<?php
 session_cache_expire(1440);
session_start();
session_name("insys");
include "include/config.php";
include "include/functions.php";
//include "class/template_class.php";
include "include/report_generator.php";

$dir="report/pembelian/print/";
$paramsx=array();

switch ($_REQUEST['form']) {
    case "purchaseorder":
    case "purchaseorderlocal":
    case "purchaseorderimport":    
        $ssql="select ftpo_no,ffvat,ffdiscount,fcdiscount from txpurchase_order_hdr where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);

        $paramsx[]=array("name"=>"trans_no",
                          "value"=>$r["ftpo_no"],
                          "type"=>"string");
         $paramsx[]=array("name"=>"username",
                          "value"=>$_SESSION['username'],
                          "type"=>"string");
        $ssql="select count(a1.fnid) as jml
                from txpurchase_order_hdr a1
                where a1.ftpo_no like '".$r["ftpo_no"]."-%'";

        $revisi=RetRstField($ssql);
        if($revisi==0) {
            $revisi_ke=" ";
        }
        else {
            $revisi_ke="Revisi Ke-{$revisi}";
        }

        $paramsx[]=array("name"=>"revisi_ke",
                          "value"=>$revisi_ke,
                          "type"=>"string");

        show_report($dir."crprint01_po_local2_pajak_discount",$paramsx);

        break;        
   
    case "penerimaanbarang":
        $ssql="select ftstock_in_no,fnpo_typelpb from txstock_in_hdr where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);
        
        $cetak_harga="0";
        
        $paramsx[]=array("name"=>"trans_no",
                          "value"=>$r["ftstock_in_no"],
                          "type"=>"string");
        $paramsx[]=array("name"=>"username",
                          "value"=>$_SESSION['username'],
                          "type"=>"string");
        $paramsx[]=array("name"=>"cetak_harga",
                          "value"=>$cetak_harga,
                          "type"=>"string");
        
        show_report($dir."crprint02_stok_masuk",$paramsx);

        break;
   
    case "purchaseinvoicelocal":
         $ssql="select ftpurchase_invoice_no from txpurchase_invoice_hdr where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);
        $paramsx[]=array("name"=>"trans_no",
                          "value"=>$r["ftpurchase_invoice_no"],
                          "type"=>"string");
         $paramsx[]=array("name"=>"username",
                          "value"=>$_SESSION['username'],
                          "type"=>"string");
        show_report($dir."crprint04_pi_local",$paramsx);
   break;
    case "purchaseinvoicelocal_cetak_non_harga":
        $ssql="select ftpurchase_invoice_no from txpurchase_invoice_hdr where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);
        $paramsx[]=array("name"=>"trans_no",
                          "value"=>$r["ftpurchase_invoice_no"],
                          "type"=>"string");
         $paramsx[]=array("name"=>"username",
                          "value"=>$_SESSION['username'],
                          "type"=>"string");
        show_report($dir."crprint04_pi_local_nonharga",$paramsx);
   break;
    case "purchaseinvoiceimport":
         $ssql="select ftpurchase_invoice_no from txpurchase_invoice_hdr where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);

        $paramsx[]=array("name"=>"trans_no",
                          "value"=>$r["ftpurchase_invoice_no"],
                          "type"=>"string");
         $paramsx[]=array("name"=>"username",
                          "value"=>$_SESSION['username'],
                          "type"=>"string");

        show_report($dir."crprint04_pi_import",$paramsx);
   break;
    case "purchaseinvoiceimport_cetak_non_harga":
        $ssql="select ftpurchase_invoice_no from txpurchase_invoice_hdr where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);

        $paramsx[]=array("name"=>"trans_no",
                          "value"=>$r["ftpurchase_invoice_no"],
                          "type"=>"string");
         $paramsx[]=array("name"=>"username",
                          "value"=>$_SESSION['username'],
                          "type"=>"string");

        show_report($dir."crprint04_pi_import_nonharga",$paramsx);
   break;
  case "purchasereturnlocal":
         $ssql="select ftpurchase_return_no from txpurchase_return_hdr where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);
        $paramsx[]=array("name"=>"trans_no",
                          "value"=>$r["ftpurchase_return_no"],
                          "type"=>"string");
         $paramsx[]=array("name"=>"username",
                          "value"=>$_SESSION['username'],
                          "type"=>"string");
        show_report($dir."crprint05_pr_local",$paramsx);
   break;
    case "purchasereturnlocal_cetak_non_harga":
         $ssql="select ftpurchase_return_no from txpurchase_return_hdr where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);
        $paramsx[]=array("name"=>"trans_no",
                          "value"=>$r["ftpurchase_return_no"],
                          "type"=>"string");
         $paramsx[]=array("name"=>"username",
                          "value"=>$_SESSION['username'],
                          "type"=>"string");
        show_report($dir."crprint05_pr_local_nonharga",$paramsx);
   break;
    case "purchasereturnimport":
         $ssql="select ftpurchase_return_no from txpurchase_return_hdr where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);
        $paramsx[]=array("name"=>"trans_no",
                          "value"=>$r["ftpurchase_return_no"],
                          "type"=>"string");
         $paramsx[]=array("name"=>"username",
                          "value"=>$_SESSION['username'],
                          "type"=>"string");
        show_report($dir."crprint05_pr_local",$paramsx);
   break;
    case "purchasereturnimport_cetak_non_harga":
         $ssql="select ftpurchase_return_no from txpurchase_return_hdr where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);
        $paramsx[]=array("name"=>"trans_no",
                          "value"=>$r["ftpurchase_return_no"],
                          "type"=>"string");
         $paramsx[]=array("name"=>"username",
                          "value"=>$_SESSION['username'],
                          "type"=>"string");
        show_report($dir."crprint05_pr_local_nonharga",$paramsx);
   break;
    case "tandaterima":
         $ssql="select fttanda_terima_no from txtanda_terima_hdr where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);
        $paramsx[]=array("name"=>"trans_no",
                          "value"=>$r["fttanda_terima_no"],
                          "type"=>"string");
         $paramsx[]=array("name"=>"username",
                          "value"=>$_SESSION['username'],
                          "type"=>"string");
        show_report($dir."crprint06_tanda_terima",$paramsx);
        break;
    case "tandaterima_cetak_tanpa_nama_company":
         $ssql="select fttanda_terima_no from txtanda_terima_hdr where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);
        $paramsx[]=array("name"=>"trans_no",
                          "value"=>$r["fttanda_terima_no"],
                          "type"=>"string");
         $paramsx[]=array("name"=>"username",
                          "value"=>$_SESSION['username'],
                          "type"=>"string");
        show_report($dir."crprint06_tanda_terima2",$paramsx);
        break;
    case "purchaserequest":
        $ssql="select ftpr_no from txpurchase_request_hdr where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);
        $paramsx[]=array("name"=>"trans_no",
                          "value"=>$r["ftpr_no"],
                          "type"=>"string");
         $paramsx[]=array("name"=>"username",
                          "value"=>$_SESSION['username'],
                          "type"=>"string");
         
        show_report($dir."crprint00_po_request",$paramsx);
        break;

    // TIdak dipakai
    /*
    case "purchaseorderlocal_cetak_non_harga":
        $ssql="select ftpo_no,ffvat,ffdiscount,fcdiscount from txpurchase_order_hdr where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);

        $paramsx[]=array("name"=>"trans_no",
                          "value"=>$r["ftpo_no"],
                          "type"=>"string");
         $paramsx[]=array("name"=>"username",
                          "value"=>$_SESSION['username'],
                          "type"=>"string");
        $ssql="select count(a1.fnid) as jml
                from txpurchase_order_hdr a1
                where a1.ftpo_no like '".$r["ftpo_no"]."-%'";

        $revisi=RetRstField($ssql);
        if($revisi==0) {
            $revisi_ke=" ";
        }
        else {
            $revisi_ke="Revisi Ke-{$revisi}";
        }

         $paramsx[]=array("name"=>"revisi_ke",
                          "value"=>$revisi_ke,
                          "type"=>"string");

          show_report($dir."crprint01_po_local2_nonharga",$paramsx);
   break;
      case "purchaseorderlocal_cetak_tanpa_nama_company":
        $ssql="select ftpo_no, ffvat, ffdiscount, fcdiscount from txpurchase_order_hdr where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);

        $paramsx[]=array("name"=>"trans_no",
                          "value"=>$r["ftpo_no"],
                          "type"=>"string");
         $paramsx[]=array("name"=>"username",
                          "value"=>$_SESSION['username'],
                          "type"=>"string");
          $ssql="select count(a1.fnid) as jml
                from txpurchase_order_hdr a1
                where a1.ftpo_no like '".$r["ftpo_no"]."-%'";

        $revisi=RetRstField($ssql);
        if($revisi==0) {
            $revisi_ke=" ";
        }
        else {
            $revisi_ke="Revisi Ke-{$revisi}";
        }

         $paramsx[]=array("name"=>"revisi_ke",
                          "value"=>$revisi_ke,
                          "type"=>"string");


       if(($r['ffvat']==0)&&($r['fcdiscount']==0)) {
            show_report($dir."crprint01_po_local_nonpajak",$paramsx);
        }
        else if(($r['ffvat']>0)&&($r['fcdiscount']>0)) {
            show_report($dir."crprint01_po_local_pajak_discount",$paramsx);
        }
        else if($r['ffvat']>0) {
            show_report($dir."crprint01_po_local_pajak",$paramsx);
        }
        else if($r['fcdiscount']>0) {
            show_report($dir."crprint01_po_local_discount",$paramsx);
        }

    break; 

    case "purchaseorderimport":
        $ssql="select ftpo_no,fcamount,ftdelivery_address,ffdiscount,fcother_cost from txpurchase_order_hdr where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);

        $paramsx[]=array("name"=>"trans_no",
                          "value"=>$r["ftpo_no"],
                          "type"=>"string");
         $paramsx[]=array("name"=>"username",
                          "value"=>$_SESSION['username'],
                          "type"=>"string");
          $paramsx[]=array("name"=>"say",
                          "value"=>terbilang_eng($r['fcamount']),
                          "type"=>"string");
             $paramsx[]=array("name"=>"ftdelivery_address",
                          "value"=>"{$r['ftdelivery_address']}",
                          "type"=>"string");

			  $ssql="select count(a1.fnid) as jml
                from txpurchase_order_hdr a1
                where a1.ftpo_no like '".$r["ftpo_no"]."-_' OR  a1.ftpo_no like '".$r["ftpo_no"]."-__'";

				$revisi=RetRstField($ssql);
				if($revisi==0) {
					$revisi_ke=" ";
				}
				else {
					$revisi_ke="Revisi Ke-{$revisi}";
				}

				 $paramsx[]=array("name"=>"revisi_ke",
								  "value"=>$revisi_ke,
								  "type"=>"string");

        show_report($dir."crprint01_po_import_subamount_discount_biayalain2",$paramsx);
        break;
    
    case "purchaseorderimport_cetak_non_harga":
        $ssql="select ftpo_no,fcamount,ftdelivery_address,ffdiscount,fcother_cost from txpurchase_order_hdr where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);

        $paramsx[]=array("name"=>"trans_no",
                          "value"=>$r["ftpo_no"],
                          "type"=>"string");
         $paramsx[]=array("name"=>"username",
                          "value"=>$_SESSION['username'],
                          "type"=>"string");
          $paramsx[]=array("name"=>"say",
                          "value"=>terbilang_eng($r['fcamount']),
                          "type"=>"string");
             $paramsx[]=array("name"=>"ftdelivery_address",
                          "value"=>"{$r['ftdelivery_address']}",
                          "type"=>"string");

			  $ssql="select count(a1.fnid) as jml
                from txpurchase_order_hdr a1
                where a1.ftpo_no like '".$r["ftpo_no"]."-_' OR  a1.ftpo_no like '".$r["ftpo_no"]."-__'";

				$revisi=RetRstField($ssql);
				if($revisi==0) {
					$revisi_ke=" ";
				}
				else {
					$revisi_ke="Revisi Ke-{$revisi}";
				}

				 $paramsx[]=array("name"=>"revisi_ke",
								  "value"=>$revisi_ke,
								  "type"=>"string");

        show_report($dir."crprint01_po_import_nonharga",$paramsx);
   break;
     case "purchaseorderimport_cetak_tanpa_nama_company":
        $ssql="select ftpo_no,fcamount from txpurchase_order_hdr where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);

        $paramsx[]=array("name"=>"trans_no",
                          "value"=>$r["ftpo_no"],
                          "type"=>"string");
         $paramsx[]=array("name"=>"username",
                          "value"=>$_SESSION['username'],
                          "type"=>"string");
          $paramsx[]=array("name"=>"say",
                          "value"=>terbilang_eng($r['fcamount']),
                          "type"=>"string");
		    $ssql="select count(a1.fnid) as jml
                from txpurchase_order_hdr a1
                where a1.ftpo_no like '".$r["ftpo_no"]."-_' OR  a1.ftpo_no like '".$r["ftpo_no"]."-__'";

				$revisi=RetRstField($ssql);
				if($revisi==0) {
					$revisi_ke=" ";
				}
				else {
					$revisi_ke="Revisi Ke-{$revisi}";
				}

				 $paramsx[]=array("name"=>"revisi_ke",
								  "value"=>$revisi_ke,
								  "type"=>"string");
        show_report($dir."crprint01_po_import2",$paramsx);
    break;

    case "trackingpo":
         $ssql="select fttrackingpo_no from txtrackingpo_hdr where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);

        $paramsx[]=array("name"=>"trans_no",
                          "value"=>$r["fttrackingpo_no"],
                          "type"=>"string");
         $paramsx[]=array("name"=>"username",
                          "value"=>$_SESSION['username'],
                          "type"=>"string");

        show_report($dir."crprint03_po_tracking",$paramsx);
   break;

    */
    
}