<?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/keuangan/print/";
$dir_sub=_REPORT_PATH."/report/keuangan/print/";
$paramsx=array();

switch ($_REQUEST['form']) { 
    case "supplier":
        show_report($dir."cr13_supplier",$paramsx,"");
       
        break;
  
    case "pembayaranhutang":
        $ssql="select ftcvs_no from txrecap_bank_voucher_hdr where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);

        $paramsx[]=array("name"=>"trans_no",
                      "value"=>$r["ftcvs_no"],
                      "type"=>"string");
        $paramsx[]=array("name"=>"SUBREPORT_DIR",
                      "value"=>$dir_sub,
                      "type"=>"string");
        $paramsx[]=array("name"=>"username",
                        "value"=>$_SESSION['username'],
                        "type"=>"string");
        show_report($dir."cr12_ap_portrait_half",$paramsx,"border:0px solid");
        break;
    
    case "pembayaranhutangimport":
        $ssql="select ftcvs_no from txrecap_bank_voucher_hdr where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);

        $paramsx[]=array("name"=>"trans_no",
                      "value"=>$r["ftcvs_no"],
                      "type"=>"string");
        $paramsx[]=array("name"=>"SUBREPORT_DIR",
                      "value"=>$dir_sub,
                      "type"=>"string");
        $paramsx[]=array("name"=>"username",
                        "value"=>$_SESSION['username'],
                        "type"=>"string");
        show_report($dir."cr12_ap_import",$paramsx," table {border:	0px solid;}");
        break;

    case "penerimaanpiutang":
        $ssql="select ftar_no from txar_hdr where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);
        
        $paramsx[]=array("name"=>"trans_no",
                          "value"=>$r["ftar_no"],
                          "type"=>"string");
        $paramsx[]=array("name"=>"SUBREPORT_DIR",
                          "value"=>$dir_sub,
                          "type"=>"string");
        $paramsx[]=array("name"=>"username",
                          "value"=>$_SESSION['username'],
                          "type"=>"string");
        // landscape version
        // show_report($dir."cr11_ar",$paramsx,"border: 0px solid");
        // portrait version (regular priter)
        // show_report($dir."cr11_ar_portrait",$paramsx,"border: 0px solid");
        show_report($dir."cr11_ar_portrait_half",$paramsx,"border: 0px solid");
        break;
    
    case "PenerimaanPiutangBank":
        $ssql="select ftar_no from txar_hdr where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);
       
        $paramsx[]=array("name"=>"trans_no",
                          "value"=>$r["ftar_no"],
                          "type"=>"string");
        $paramsx[]=array("name"=>"SUBREPORT_DIR",
                          "value"=>$dir_sub,
                          "type"=>"string");
        $paramsx[]=array("name"=>"username",
                          "value"=>$_SESSION['username'],
                          "type"=>"string");

        show_report($dir."cr11_ar_bank",$paramsx," table {border:	0px solid;}");
        break;

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

        $paramsx[]=array("name"=>"trans_no",
                          "value"=>$r["ftar_no"],
                          "type"=>"string");
        $paramsx[]=array("name"=>"SUBREPORT_DIR",
                          "value"=>$dir_sub,
                          "type"=>"string");
        $paramsx[]=array("name"=>"username",
                          "value"=>$_SESSION['username'],
                          "type"=>"string");
        show_report($dir."cr11_ar",$paramsx,"");
        break;
    
    
    case "debitmemo":
        $ssql="select ftdm_no from txdebit_memo_hdr where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);
        
        $paramsx[]=array("name"=>"trans_no",
                          "value"=>$r["ftdm_no"],
                          "type"=>"string");
        $ssql="select fntrans_type
                from txdebit_memo_hdr
                where fnid='{$_REQUEST['id']}'";
                    
        if((RetRstField($ssql))>2) {
             show_report($dir."cr08_debit_memo_um",$paramsx);
        }
        else {
            show_report($dir."cr08_debit_memo",$paramsx);
        }
        
        break;
        
    case "creditmemo":
        $ssql="select ftcm_no from txcredit_memo_hdr where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);
        
        $paramsx[]=array("name"=>"trans_no",
                          "value"=>$r["ftcm_no"],
                          "type"=>"string");

    
        show_report($dir."cr07_credit_memo",$paramsx);
        break;
    
    case "giromundurhutang":
        $paramsx[]=array("name"=>"id",
                          "value"=>$_REQUEST['id'],
                          "type"=>"long");

        show_report($dir."cr06_giro_hutang",$paramsx);
        break;
   
    case "giromundurpiutang":
        $paramsx[]=array("name"=>"id",
                          "value"=>$_REQUEST['id'],
                          "type"=>"long");

        show_report($dir."cr05_giro_piutang",$paramsx);
        break;
    
    case "kasmasuk":
        $ssql="select ftcashrcp_no,fcamount from txcashrcp_hdr where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);
        
        $paramsx[]=array("name"=>"trans_no",
                          "value"=>$r["ftcashrcp_no"],
                          "type"=>"string");
        $temp=terbilang($r["fcamount"]);
        $paramsx[]=array("name"=>"say",
                          "value"=>$temp,
                          "type"=>"string");
        $paramsx[]=array("name"=>"username",
                          "value"=>$_SESSION['username'],
                          "type"=>"string");
        //show_report($dir."cr01_kas_masuk",$paramsx," table {border: 0px solid;}");
        show_report($dir."cr01_kas_masuk_halfA4",$paramsx," table {border: 0px solid;}");
        break;
    
    case "kaskeluar":   

        $ssql="select ftcashpym_no,fcamount from txcashpym_hdr where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);
        
        $paramsx[]=array("name"=>"trans_no",
                          "value"=>$r["ftcashpym_no"],
                          "type"=>"string");
        $temp=terbilang($r["fcamount"]);
        $paramsx[]=array("name"=>"say",
                          "value"=>$temp,
                          "type"=>"string");
        $paramsx[]=array("name"=>"username",
                          "value"=>$_SESSION['username'],
                          "type"=>"string");
        //show_report($dir."cr02_kas_keluar",$paramsx," table {border:	0px solid;}");
        show_report($dir."cr02_kas_keluar_halfA4",$paramsx," table {border:	0px solid;}");
        break;
    
    case "bankmasuk":   
        $ssql="select ftbankrcp_no,fcamount from txbankrcp_hdr where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);
        
        $paramsx[]=array("name"=>"trans_no",
                          "value"=>$r["ftbankrcp_no"],
                          "type"=>"string");
        $temp=terbilang($r["fcamount"]);
        $paramsx[]=array("name"=>"say",
                          "value"=>$temp,
                          "type"=>"string");
        $paramsx[]=array("name"=>"username",
                        "value"=>$_SESSION['username'],
                        "type"=>"string");
        // show_report($dir."cr03_bank_masuk",$paramsx," table {border:	0px solid;}");
        show_report($dir."cr03_bank_masuk_halfA4",$paramsx," table {border:0px solid;}");
        break;

    case "bankkeluar":   
        $ssql="select ftbankpym_no,fcamount from txbankpym_hdr where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);
		
        $ssql1="select fnprint_status from txbankpym_hdr where fnid='{$_REQUEST['id']}'";
        $rs1=mysql_query($ssql1);
        $r1=mysql_fetch_assoc($rs1);

        if($r1["fnprint_status"]=='0'){
                $ssql2="UPDATE txbankpym_hdr SET fnprint_status=1 where fnid='{$_REQUEST['id']}'";
                $rs2=mysql_query($ssql2);
        }
        else{
                $ssql3="UPDATE txbankpym_hdr SET ftprint_counter=ftprint_counter+1 where fnid='{$_REQUEST['id']}'";
                $rs3=mysql_query($ssql3);
        }
		
        $paramsx[]=array("name"=>"trans_no",
                          "value"=>$r["ftbankpym_no"],
                          "type"=>"string");
        $temp=terbilang($r["fcamount"]);
        $paramsx[]=array("name"=>"say",
                          "value"=>$temp,
                          "type"=>"string");
        $paramsx[]=array("name"=>"username",
                          "value"=>$_SESSION['username'],
                          "type"=>"string");
        // show_report($dir."cr04_bank_keluar",$paramsx," table {border:	0px solid;}");
        show_report($dir."cr04_bank_keluar_halfA4",$paramsx," table {border:	0px solid;}");
        break;

    case "uangmukapenjualan":
        $ssql="select fttrans_no,fcamount from txadvanced_receive where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);
        $paramsx[]=array("name"=>"trans_no",
                          "value"=>$r["fttrans_no"],
                          "type"=>"string");
        $temp=terbilang($r["fcamount"]);
        $paramsx[]=array("name"=>"say",
                          "value"=>$temp,
                          "type"=>"string");
        $paramsx[]=array("name"=>"username",
                          "value"=>$_SESSION['username'],
                          "type"=>"string");
        $paramsx[]=array("name"=>"REPORT_DIR",
                        "value"=>"images/",
                        "type"=>"string");
        show_report($dir."cr14_uang_muka_penjualan",$paramsx," table {border: 0px solid;}");
        break;
    
    case "uangmukapembelian":
        $ssql="select fttrans_no,fcamount from txadvanced_payment where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);
        $paramsx[]=array("name"=>"trans_no",
                          "value"=>$r["fttrans_no"],
                          "type"=>"string");
        $temp=terbilang($r["fcamount"]);
        $paramsx[]=array("name"=>"say",
                          "value"=>$temp,
                          "type"=>"string");
        $paramsx[]=array("name"=>"username",
                          "value"=>$_SESSION['username'],
                          "type"=>"string");
        $paramsx[]=array("name"=>"REPORT_DIR",
                        "value"=>"images/",
                        "type"=>"string");
        show_report($dir."cr15_uang_muka_pembelian",$paramsx," table {border: 0px solid;}");
        break;
    
    /* Tidak digunakan
    case "bankmasuksementara":
        $ssql="select ftbankrcp_no,fcamount from txbankrcp_hdr where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);

        $paramsx[]=array("name"=>"trans_no",
                          "value"=>$r["ftbankrcp_no"],
                          "type"=>"string");
        $temp=terbilang($r["fcamount"]);
        $paramsx[]=array("name"=>"say",
                          "value"=>$temp,
                          "type"=>"string");
        $paramsx[]=array("name"=>"username",
                        "value"=>$_SESSION['username'],
                        "type"=>"string");
        show_report($dir."cr03_bank_masuk_sementara",$paramsx," table {border:	0px solid;}");
	break;
     
    case "bankkeluarsementara":
        $ssql="select ftbankpym_no,fcamount from txbankpym_hdr where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);

        $paramsx[]=array("name"=>"trans_no",
                          "value"=>$r["ftbankpym_no"],
                          "type"=>"string");
        $temp=terbilang($r["fcamount"]);
        $paramsx[]=array("name"=>"say",
                          "value"=>$temp,
                          "type"=>"string");
        $paramsx[]=array("name"=>"username",
                          "value"=>$_SESSION['username'],
                          "type"=>"string");
        show_report($dir."cr04_bank_keluar_sementara",$paramsx," table {border:	0px solid;}");
        break;
    
    case "pembayaranhutangimportsementara":
        $ssql="select ftcvs_no from txrecap_bank_voucher_hdr where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);

        $paramsx[]=array("name"=>"trans_no",
                          "value"=>$r["ftcvs_no"],
                          "type"=>"string");
          $paramsx[]=array("name"=>"SUBREPORT_DIR",
                          "value"=>$dir_sub,
                          "type"=>"string");
           $paramsx[]=array("name"=>"username",
                          "value"=>$_SESSION['username'],
                          "type"=>"string");
        
         show_report($dir."cr12_ap_import_sementara",$paramsx," table {border:	0px solid;}");
        break; 
     
    case "pembayaranhutangsementara":
      $ssql="select ftcvs_no from txrecap_bank_voucher_hdr where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);

        $paramsx[]=array("name"=>"trans_no",
                      "value"=>$r["ftcvs_no"],
                      "type"=>"string");
        $paramsx[]=array("name"=>"SUBREPORT_DIR",
                      "value"=>$dir_sub,
                      "type"=>"string");
        $paramsx[]=array("name"=>"username",
                    "value"=>$_SESSION['username'],
                    "type"=>"string");
        //show_report($dir."cr12_ap_sementara",$paramsx,"border:	1px solid");
        show_report($dir."cr12_ap_sementara",$paramsx,"border:	0px solid");
        break;
    
    case "proyeksibiaya":
         $ssql="select ftcp_no from txcashflow_projection_hdr where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);
        
        $paramsx[]=array("name"=>"trans_no",
                          "value"=>$r["ftcp_no"],
                          "type"=>"string");

        show_report($dir."cr10_proyeksi_biaya",$paramsx);
        break;
      
    case "proyeksipembayaran":
            $ssql="select ftpp_no from txpayment_projection_hdr where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);
        
        $paramsx[]=array("name"=>"trans_no",
                          "value"=>$r["ftpp_no"],
                          "type"=>"string");

    
        show_report($dir."cr09_proyeksi_pembayaran",$paramsx);
        break; 
    * 
    */
}