<?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/penjualan/print/";
    
$paramsx=array();

switch ($_REQUEST['form']) {
    
    case "salesorder":
        
        $ssql="select ftso_no, fcamount, fntax_code from txsales_order_hdr where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_array($rs);
        $temp=terbilang($r['1']);
        $fntax_code = $r["fntax_code"];
                
        // update print counter
        $ftprint_counter = 1;
        $ssql2="UPDATE txsales_invoice_hdr SET ftprint_counter={$ftprint_counter}, ftmodified_user = '{$_SESSION['username']}', fdmodified_date = now() where ftso_no='{$r[0]}' AND fnstatus !=3 AND fnstatus !=9 ";
        $rs2=mysql_query($ssql2);
   
        $paramsx[]=array("name"=>"trans_no",
                          "value"=>$r[0],
                          "type"=>"string");
        $paramsx[]=array("name"=>"say",
                        "value"=>$temp,
                        "type"=>"string");
        
        // show print number
        if($ftprint_counter==1) {
            $print_count=" ";
        }
        else {
            $print_count = "D" . ($ftprint_counter - 1) . "";
        }
        
        $paramsx[]=array("name"=>"print_count",
                          "value"=>$print_count,
                          "type"=>"string");
        
        // cetak tipe pajak
        if ($fntax_code == 0) {
            show_report($dir."crprint01_sales_order_vat",$paramsx);
        // cetak tipe normal   
        } else {
            show_report($dir."crprint01_sales_order",$paramsx);
        }
        
        break;

    case "salesorder_cetak_do":
        $ssql="select ftso_no from txsales_order_hdr where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_array($rs);
        
        $sql = "SELECT ftdo_no FROM txdelivery_order_hdr WHERE ftso_no='{$r['ftso_no']}'";
        $rd = mysql_query($sql);
        $d = mysql_fetch_array($rd);
        
        $paramsx[]=array("name"=>"trans_no",
                          "value"=>$d["ftdo_no"],
                          "type"=>"string");
        
        /*$paramsx[]=array("name"=>"trans_no",
                          "value"=>$d["ftdo_no"],
                          "type"=>"string");
        $paramsx[]=array("name"=>"username",
                          "value"=>strtoupper($_SESSION['username']),
                          "type"=>"string");
        $paramsx[]=array("name"=>"REPORT_DIR",
                        "value"=>"images/",
                        "type"=>"string"); 
        
        $ssql="select count(a1.fnid) as jml
                from txdelivery_order_hdr a1
                where a1.ftdo_no like '".$d["ftdo_no"]."-%'";
        
        $revisi=RetRstField($sql);
        if($revisi==0) {
            $revisi_ke=" ";
        }
        else {
            $revisi_ke="Revisi Ke-{$revisi}";
        }

        $paramsx[]=array("name"=>"revisi_ke",
                          "value"=>$revisi_ke,
                          "type"=>"string");
        
        // show print number
        if($ftprint_counter==1) {
            $print_count=" ";
        }
        else {
            $print_count = "(D" . ($ftprint_counter - 1) . ")";
        }
        
        $paramsx[]=array("name"=>"print_count",
                          "value"=>$print_count,
                          "type"=>"string");
        */
        //show_report($dir."crprint02_sj1_new",$paramsx);
        show_report($dir."print_salesorder_do",$paramsx);
        break;
    
    case "salesorderkonsinyasi":

        $ssql="select ftso_no, fcamount, fntax_code from txsales_order_hdr where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_array($rs);
        $temp=terbilang($r['1']);
        $fntax_code = $r["fntax_code"];

        // update print counter
        $ftprint_counter = 1;
        $ssql2="UPDATE txsales_invoice_hdr SET ftprint_counter={$ftprint_counter}, ftmodified_user = '{$_SESSION['username']}', fdmodified_date = now() where ftso_no='{$r[0]}' AND fnstatus !=3 AND fnstatus !=9 ";
        $rs2=mysql_query($ssql2);

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

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

        // show print number
        if($ftprint_counter==1) {
            $print_count=" ";
        }
        else {
            $print_count = "D" . ($ftprint_counter - 1) . "";
        }

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

        // cetak tipe pajak
        
        // NGACO !!! jangan timpa cetakan so yg normal
        if ($fntax_code == 0) {
            show_report($dir."crprint01_sales_order_vat",$paramsx);
        // cetak tipe normal
        } else {
            show_report($dir."crprint01_sales_order",$paramsx);
        }

        break;
          
    case "salesinvoice":
        $ssql="select ftsales_invoice_no, fcamount, IFNULL(ftprint_counter,0) as ftprint_counter, fntax_code from txsales_invoice_hdr where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_array($rs);
        $temp=terbilang($r['1']);
        $fntax_code = $r["fntax_code"];
                
        // update print counter
        $ftprint_counter = $r["ftprint_counter"] + 1;
        $ssql2="UPDATE txsales_invoice_hdr SET ftprint_counter={$ftprint_counter}, ftmodified_user = '{$_SESSION['username']}', fdmodified_date = now() where fnid='{$_REQUEST['id']}'";
        $rs2=mysql_query($ssql2);
        
        $paramsx[]=array("name"=>"trans_no",
                          "value"=>$r[0],
                          "type"=>"string");
        $paramsx[]=array("name"=>"say",
                        "value"=>$temp,
                        "type"=>"string");
        
        // show print number
        if($ftprint_counter==1) {
            $print_count=" ";
        }
        else {
            $print_count = "D" . ($ftprint_counter - 1) . "";
        }
        
        $paramsx[]=array("name"=>"print_count",
                          "value"=>$print_count,
                          "type"=>"string");
        
        // cetak tipe pajak
        if ($fntax_code == 0) {
            show_report($dir."crprint03_invoice_vat",$paramsx);
        // cetak tipe normal   
        } else {
            show_report($dir."crprint03_invoice",$paramsx);
        }
      
        break;
    
    case "salesinvoicepameran":
        $ssql="select ftsales_invoice_no, fcamount, IFNULL(ftprint_counter,0) as ftprint_counter, fntax_code from txsales_invoice_hdr where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_array($rs);
        $temp=terbilang($r['1']);
        $fntax_code = $r["fntax_code"];

        // update print counter
        $ftprint_counter = $r["ftprint_counter"] + 1;

        $ssql2="UPDATE txsales_invoice_hdr SET ftprint_counter={$ftprint_counter}, ftmodified_user = '{$_SESSION['username']}', fdmodified_date = now() where fnid='{$_REQUEST['id']}'";

        $rs2=mysql_query($ssql2);

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

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

        // show print number
        if($ftprint_counter==1) {
            $print_count=" ";
        }
        else {
            $print_count = "D" . ($ftprint_counter - 1) . "";
        }

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

        // cetak tipe pajak
        if ($fntax_code == 0) {
            show_report($dir."crprint01_sales_invoice_pameran",$paramsx);
        // cetak tipe normal
        } else {
            show_report($dir."crprint01_sales_invoice_pameran",$paramsx);
        }

        break;

    case "salesinvoicekonsinyasi":


        $ssql="select ftsales_invoice_no, fcamount, IFNULL(ftprint_counter,0) as ftprint_counter, fntax_code from txsales_invoice_hdr where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_array($rs);
        $temp=terbilang($r['1']);
        $fntax_code = $r["fntax_code"];
        //

        // update print counter
        $ftprint_counter = $r["ftprint_counter"] + 1;

        $ssql2="UPDATE txsales_invoice_hdr SET ftprint_counter={$ftprint_counter}, ftmodified_user = '{$_SESSION['username']}', fdmodified_date = now() where fnid='{$_REQUEST['id']}'";

        $rs2=mysql_query($ssql2);

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

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

        // show print number
        if($ftprint_counter==1) {
            $print_count=" ";
        }
        else {
            $print_count = "D" . ($ftprint_counter - 1) . "";
        }

        $paramsx[]=array("name"=>"print_count",
                          "value"=>$print_count,
                          "type"=>"string");
       // print_r($paramsx);
       // die;
        // cetak tipe pajak
        // NGACO SALES INVOICE JANGAN TIMPA YG VERSI NORMAL !!!
        if ($fntax_code == 0) {
            show_report($dir."crprint01_sales_invoice",$paramsx);
        // cetak tipe normal
        } else {
            show_report($dir."crprint01_sales_invoice",$paramsx);
        }

        break;
        
    case "deliveryorder":
        
        $sql = "SELECT a.ftdo_no, IFNULL(a.ftprint_counter,0) as ftprint_counter, b.fntax_code FROM txdelivery_order_hdr a 
                INNER JOIN txsales_invoice_hdr b ON a.ftdo_no = b.ftdo_no WHERE a.fnid='{$_REQUEST['id']}'";
        $rd = mysql_query($sql);
        $d = mysql_fetch_array($rd);
        
        $fntax_code = $d["fntax_code"];
                
        // update print counter
        $ftprint_counter = $d["ftprint_counter"] + 1;
        $ssql2="UPDATE txdelivery_order_hdr SET ftprint_counter={$ftprint_counter}, ftmodified_user = '{$_SESSION['username']}', fdmodified_date = now() where fnid='{$_REQUEST['id']}'";
        $rs2=mysql_query($ssql2);
        
        $paramsx[]=array("name"=>"trans_no",
                          "value"=>$d["ftdo_no"],
                          "type"=>"string");
        $paramsx[]=array("name"=>"username",
                          "value"=>strtoupper($_SESSION['username']),
                          "type"=>"string");
        $paramsx[]=array("name"=>"REPORT_DIR",
                        "value"=>"images/",
                        "type"=>"string");
        
        $ssql="SELECT count(a1.fnid) as jml FROM txdelivery_order_hdr a1
                WHERE a1.ftdo_no like '".$d["ftdo_no"]."-%'";
        
        $revisi=RetRstField($sql);
        if($revisi==0) {
            $revisi_ke=" ";
        }
        else {
            $revisi_ke="Revisi Ke-{$revisi}";
        }

        $paramsx[]=array("name"=>"revisi_ke",
                          "value"=>$revisi_ke,
                          "type"=>"string");
        
        // show print number
        if($ftprint_counter==1) {
            $print_count=" ";
        }
        else {
            $print_count = "(D" . ($ftprint_counter - 1) . ")";
        }
        
        $paramsx[]=array("name"=>"print_count",
                          "value"=>$print_count,
                          "type"=>"string");
        
        // cetak tipe pajak
        if ($fntax_code == 0) {
            show_report($dir."crprint02_sj1_vat",$paramsx);
        // cetak tipe normal   
        } else {
            show_report($dir."crprint02_sj1_new",$paramsx);
        }
      
        
        break;
        
    // new report html
    case "deliveryorder_html":
        
        $sql = "SELECT a.ftdo_no, IFNULL(a.ftprint_counter,0) as ftprint_counter, b.fntax_code FROM txdelivery_order_hdr a 
                INNER JOIN txsales_invoice_hdr b ON a.ftdo_no = b.ftdo_no WHERE a.fnid='{$_REQUEST['id']}'";
        $rd = mysql_query($sql);
        $d = mysql_fetch_array($rd);
        
        //$fntax_code = $d["fntax_code"];
                
        // update print counter
        //$ftprint_counter = $d["ftprint_counter"] + 1;
        //$ssql2="UPDATE txdelivery_order_hdr SET ftprint_counter={$ftprint_counter}, ftmodified_user = '{$_SESSION['username']}', fdmodified_date = now() where fnid='{$_REQUEST['id']}'";
        //$rs2=mysql_query($ssql2);
        
        $paramsx[]=array("name"=>"trans_no",
                          "value"=>$d["ftdo_no"],
                          "type"=>"string");
        /* $paramsx[]=array("name"=>"username",
                          "value"=>strtoupper($_SESSION['username']),
                          "type"=>"string");
        $paramsx[]=array("name"=>"REPORT_DIR",
                        "value"=>"images/",
                        "type"=>"string");
        
        $ssql="SELECT count(a1.fnid) as jml FROM txdelivery_order_hdr a1
                WHERE a1.ftdo_no like '".$d["ftdo_no"]."-%'";
        
        $revisi=RetRstField($sql);
        if($revisi==0) {
            $revisi_ke=" ";
        }
        else {
            $revisi_ke="Revisi Ke-{$revisi}";
        }

        $paramsx[]=array("name"=>"revisi_ke",
                          "value"=>$revisi_ke,
                          "type"=>"string");
        
        // show print number
        if($ftprint_counter==1) {
            $print_count=" ";
        }
        else {
            $print_count = "(D" . ($ftprint_counter - 1) . ")";
        }
        
        $paramsx[]=array("name"=>"print_count",
                          "value"=>$print_count,
                          "type"=>"string");
        
        // cetak tipe pajak
        if ($fntax_code == 0) {
            show_report($dir."crprint02_sj1_vat",$paramsx);
        // cetak tipe normal   
        } else {
            show_report($dir."crprint02_sj1_new",$paramsx);
        }
        */
        show_report($dir."print_do",$paramsx);
        
        break;
    
    case "deliveryorder_cetak_do":
        $sql = "SELECT a.ftdo_no, IFNULL(a.ftprint_counter,0) as ftprint_counter, b.fntax_code FROM txdelivery_order_hdr a 
                INNER JOIN txsales_invoice_hdr b ON a.ftdo_no = b.ftdo_no WHERE a.fnid='{$_REQUEST['id']}'";
        $rd = mysql_query($sql);
        $d = mysql_fetch_array($rd);
        
        $fntax_code = $d["fntax_code"]; 
                
        // update print counter
        //$ftprint_counter = 1;
        //$ssql2="UPDATE txsales_invoice_hdr SET ftprint_counter={$ftprint_counter}, ftmodified_user = '{$_SESSION['username']}', fdmodified_date = now() where ftso_no='{$r[0]}' AND fnstatus !=3 AND fnstatus !=9 ";
        //$rs2=mysql_query($ssql2);
   
        $paramsx[]=array("name"=>"trans_no",
                          "value"=>$d["ftdo_no"],
                          "type"=>"string");
        
        // show print number
        if($ftprint_counter==1) {
            $print_count=" ";
        }
        else {
            $print_count = "D" . ($ftprint_counter - 1) . "";
        }
        
        $paramsx[]=array("name"=>"print_count",
                          "value"=>$print_count,
                          "type"=>"string");
        
        // cetak tipe pajak
        if ($fntax_code == 0) {
            show_report($dir."crprint02_delivery_order_vat",$paramsx);
        // cetak tipe normal   
        } else {
            show_report($dir."crprint02_delivery_order",$paramsx);
        }
        
        break;    
        
    case "deliveryordermonitor":
        
        //$sql = "SELECT ftdo_no, IFNULL(ftprint_counter,0) as ftprint_counter FROM txdelivery_order_hdr WHERE fnid='{$_REQUEST['id']}'";
        //$rd = mysql_query($sql);
        //$d = mysql_fetch_array($rd);
        // filter warehouse code based on login user
        $ftwarehouse_code = RetRstField("Select ifnull(ftwarehouse_code,'') FROM tluser WHERE ftusername = '{$_SESSION['username']}' ");
        if ($ftwarehouse_code != "") { 
            $str_warehouse = explode(",", $ftwarehouse_code);
            $sql_where = "''";

            foreach($str_warehouse as $item) {
                $sql_where = $sql_where . ",'{$item}'";
            }
            $sql_where = " AND d.ftwarehouse_code IN ({$sql_where})";
        }

        $ssql="SELECT a.ftdo_no, IFNULL(a.ftprint_counter,0) as ftprint_counter FROM txdelivery_order_hdr a INNER JOIN txdelivery_order_det d ON a.ftdo_no = d.ftdo_no  
                    WHERE (IFNULL(a.ftprint_counter,0) = 0) AND a.fnstatus !=3 AND a.fnstatus != 9 {$sql_where}  GROUP BY a.ftdo_no, d.ftwarehouse_code  ORDER BY a.ftdo_no ";
        $rd=mysql_query($ssql);
        
        while($d=mysql_fetch_assoc($rd)) {
            
            // update print counter
            $ftprint_counter = $d["ftprint_counter"] + 1;
            //$ssql2="UPDATE txdelivery_order_hdr SET ftprint_counter={$ftprint_counter} where fnid='{$_REQUEST['id']}'";
            $ssql2="UPDATE txdelivery_order_hdr SET ftprint_counter={$ftprint_counter}, ftmodified_user = '{$_SESSION['username']}', fdmodified_date = now() where ftdo_no='{$d["ftdo_no"]}'";
            $rs2=mysql_query($ssql2);

            $paramsx[]=array("name"=>"trans_no",
                              "value"=>$d["ftdo_no"],
                              "type"=>"string");
            $paramsx[]=array("name"=>"username",
                              "value"=>strtoupper($_SESSION['username']),
                              "type"=>"string");
            $paramsx[]=array("name"=>"REPORT_DIR",
                            "value"=>"images/",
                            "type"=>"string");


            $ssql3="SELECT count(a1.fnid) as jml FROM txdelivery_order_hdr a1
                    WHERE a1.ftdo_no like '".$d["ftdo_no"]."-%'";

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

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

            // show print number
            if($ftprint_counter==1) {
                $print_count=" ";
            }
            else {
                $print_count = "(D" . ($ftprint_counter - 1) . ")";
            }

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

            $fntax_code = RetRstField("Select fntax_code FROM txsales_invoice_hdr WHERE ftdo_no = '{$d["ftdo_no"]}' ");
    
            // cetak tipe pajak
            if ($fntax_code == 0) {
                show_report($dir."crprint02_sj1_vat",$paramsx);
            // cetak tipe normal   
            } else {
                show_report($dir."crprint02_sj1_new",$paramsx);
            }

            echo "<script language='JavaScript' type='text/javascript'>
                     window.onload = function() { window.print();  }
                  </script>  "; 
                        
        }
        
        /*            
        echo "<script language='JavaScript' type='text/javascript'>
                     setTimeout(function(){parent.window.location.href = 'http://closekiosk';}, 10000)
                  </script>  "; 
        */
        
        break;
    
    case "deliveryorderpameran":

        $sql = "SELECT a.ftdo_no, IFNULL(a.ftprint_counter,0) AS ftprint_counter, b.fntax_code FROM txdelivery_order_hdr a
                INNER JOIN txsales_invoice_hdr b ON a.ftso_no = b.ftsales_invoice_no WHERE a.fnid='{$_REQUEST['id']}'";

        $rd = mysql_query($sql);
        $d = mysql_fetch_array($rd);

        $fntax_code = $d["fntax_code"];

        // print_r($d["ftdo_no"]);
        // die;
        // update print counter
        //$ftprint_counter = 1;
        //$ssql2="UPDATE txsales_invoice_hdr SET ftprint_counter={$ftprint_counter}, ftmodified_user = '{$_SESSION['username']}', fdmodified_date = now() where ftso_no='{$r[0]}' AND fnstatus !=3 AND fnstatus !=9 ";
        //$rs2=mysql_query($ssql2);

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

        // show print number
        if($ftprint_counter==1) {
            $print_count=" ";
        }
        else {
            $print_count = "D" . ($ftprint_counter - 1) . "";
        }

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

        // cetak tipe pajak
        if ($fntax_code == 0) {
            show_report($dir."crprint02_delivery_order_pameran_vat",$paramsx);
        // cetak tipe normal
        } else {
            show_report($dir."crprint02_delivery_order_pameran_vat",$paramsx);
        }


        break;

    case "deliveryorderkonsinyasi":

            // $sql = "SELECT a.ftdo_no, IFNULL(a.ftprint_counter,0) as ftprint_counter, b.fntax_code FROM txdelivery_order_hdr a
            //         INNER JOIN txsales_invoice_hdr b ON a.ftdo_no = b.ftdo_no WHERE a.fnid='{$_REQUEST['id']}'";

            $sql = "SELECT a.ftdo_no, IFNULL(a.ftprint_counter,0) AS ftprint_counter, b.fntax_code FROM txdelivery_order_hdr a
                    INNER JOIN txsales_invoice_hdr b ON a.ftso_no = b.ftsales_invoice_no WHERE a.fnid='{$_REQUEST['id']}'";

            $rd = mysql_query($sql);
            $d = mysql_fetch_array($rd);

            $fntax_code = $d["fntax_code"];

            // print_r($d["ftdo_no"]);
            // die;
            // update print counter
            //$ftprint_counter = 1;
            //$ssql2="UPDATE txsales_invoice_hdr SET ftprint_counter={$ftprint_counter}, ftmodified_user = '{$_SESSION['username']}', fdmodified_date = now() where ftso_no='{$r[0]}' AND fnstatus !=3 AND fnstatus !=9 ";
            //$rs2=mysql_query($ssql2);

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

            // show print number
            if($ftprint_counter==1) {
                $print_count=" ";
            }
            else {
                $print_count = "D" . ($ftprint_counter - 1) . "";
            }

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

            // cetak tipe pajak
            if ($fntax_code == 0) {
                show_report($dir."crprint02_delivery_order_konsinyasi_vat",$paramsx);
            // cetak tipe normal
            } else {
                show_report($dir."crprint02_delivery_order_konsinyasi_vat",$paramsx);
            }

            break;

            
    case "salesinvoicemonitor":
        
        $ftwarehouse_code = RetRstField("Select ifnull(ftwarehouse_code,'') FROM tluser WHERE ftusername = '{$_SESSION['username']}' ");
        if ($ftwarehouse_code != "") { 
            $str_warehouse = explode(",", $ftwarehouse_code);
            $sql_where = "''";

            foreach($str_warehouse as $item) {
                $sql_where = $sql_where . ",'{$item}'";
            }
            $sql_where = " AND d.ftwarehouse_code IN ({$sql_where})";
        }

        $ssql="SELECT a.ftso_no, a.ftsales_invoice_no, IFNULL(a.ftprint_counter,0) as ftprint_counter, fntax_code FROM txsales_invoice_hdr a INNER JOIN txsales_invoice_det d ON a.ftsales_invoice_no = d.ftsales_invoice_no  
                    WHERE (IFNULL(a.ftprint_counter,0) = 0) AND a.fnstatus !=3 AND a.fnstatus != 9 {$sql_where}  GROUP BY a.ftsales_invoice_no, d.ftwarehouse_code  ORDER BY a.ftsales_invoice_no ";
        $rd=mysql_query($ssql);
        
        while($d=mysql_fetch_assoc($rd)) {
            // update print counter
            $ftprint_counter = $d["ftprint_counter"] + 1;
            $fntax_code = $d['fntax_code'];
            
            //$ssql2="UPDATE txdelivery_order_hdr SET ftprint_counter={$ftprint_counter} where fnid='{$_REQUEST['id']}'";
            $ssql2="UPDATE txsales_invoice_hdr SET ftprint_counter={$ftprint_counter}, ftmodified_user = '{$_SESSION['username']}', fdmodified_date = now() where ftsales_invoice_no='{$d["ftsales_invoice_no"]}' ";
            $rs2=mysql_query($ssql2);
    
            $ssql="select ftso_no, fcamount from txsales_invoice_hdr where fnid='{$_REQUEST['id']}'";
            $rs=mysql_query($ssql);
            $r=mysql_fetch_array($rs);
            $temp=terbilang($r['fcamount']);
                    
            $paramsx[]=array("name"=>"trans_no",
                              "value"=>$d["ftso_no"],
                              "type"=>"string");
            $paramsx[]=array("name"=>"say",
                            "value"=>$temp,
                            "type"=>"string");
            
            // show print number
            if($ftprint_counter==1) {
                $print_count=" ";
            }
            else {
                $print_count = "D" . ($ftprint_counter - 1) . "";
            }

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

            
            $fntax_code = RetRstField("Select fntax_code FROM txsales_invoice_hdr WHERE ftdo_no = '{$d["ftdo_no"]}' ");
    
            // cetak tipe pajak
            if ($fntax_code == 0) {
                show_report($dir."crprint01_sales_order_vat",$paramsx);
            // cetak tipe normal   
            } else {
                show_report($dir."crprint01_sales_order",$paramsx);
            }
            
        /*  $paramsx[]=array("name"=>"trans_no",
                              "value"=>$d["ftso_no"],
                              "type"=>"string");
            $paramsx[]=array("name"=>"username",
                              "value"=>strtoupper($_SESSION['username']),
                              "type"=>"string");
            $paramsx[]=array("name"=>"REPORT_DIR",
                            "value"=>"images/",
                            "type"=>"string");

            $ssql3="SELECT count(a1.fnid) as jml FROM txsales_invoice_hdr a1
                    WHERE a1.ftsales_invoice_no like '".$d["ftsales_invoice_no"]."-%'";

            $revisi=RetRstField($ssql3);
            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_sales_order",$paramsx); */

            echo "<script language='JavaScript' type='text/javascript'>
                     window.onload = function() { window.print();  }
                  </script>  ";

        }
        /*
        echo "<script language='JavaScript' type='text/javascript'>
                setTimeout(function(){parent.window.location.href = 'http://closekiosk';}, 10000)
              </script>  "; 
        */
        
        break;
        
        
    case "returpenjualan":
        $ssql="select ftsales_return_no, fcamount from txsales_return_hdr where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_array($rs);
        $temp=terbilang($r['1']);
        $paramsx[]=array("name"=>"trans_no",
                          "value"=>$r[0],
                          "type"=>"string");
        $paramsx[]=array("name"=>"say",
                        "value"=>$temp,
                        "type"=>"string");
        show_report($dir."crprint05_sales_return",$paramsx);
        break;
    
    case "salesinvoiceadjustment":
        $ssql="select ftsales_invoice_no, fcamount from txsales_invoice_adjustment_hdr where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_array($rs);
        $temp=terbilang($r['1']);
        $paramsx[]=array("name"=>"trans_no",
                          "value"=>$r[0],
                          "type"=>"string");
        $paramsx[]=array("name"=>"say",
                        "value"=>$temp,
                        "type"=>"string");
        show_report($dir."crprint06_sales_invoice_adjustment",$paramsx);
        
        break;

    /*
    case "salesorder_cetak_si":
        $sql="select ftso_no from txsales_order_hdr where fnid='{$_REQUEST['id']}'";
        $ds=mysql_query($sql);
        $d=mysql_fetch_array($ds);
        
        $ssql="select ftsales_invoice_no,fcamount from txsales_invoice_hdr where ftso_no='{$d['ftso_no']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);

        $ssql="select count(a1.fnid) as jml
                from txsales_invoice_hdr a1
                where a1.ftsales_invoice_no like '".$r["ftsales_invoice_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");
            
        $paramsx[]=array("name"=>"trans_no",
                          "value"=>$r["ftsales_invoice_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."crprint01_invoice_new",$paramsx);
          
        break;

    case "salesinvoicevat":
         $ssql="select ftsales_invoice_no,fcamount from txsales_invoice_hdr where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);
        

        $ssql="select count(a1.fnid) as jml
                from txsales_invoice_hdr a1
                where a1.ftsales_invoice_no like '".$r["ftsales_invoice_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");
            
        $paramsx[]=array("name"=>"trans_no",
                          "value"=>$r["ftsales_invoice_no"],
                          "type"=>"string");
        $temp=terbilang($r["fcamount"]);
         $paramsx[]=array("name"=>"say",
                          "value"=>$temp,
                          "type"=>"string");

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

        break;
    
    case "salesinvoicevatstandar":
        $ssql="update txsales_invoice_hdr set fdvat_date='".CDate($_REQUEST['fdvat_date'])."' where fnid='{$_REQUEST['id']}'";
        mysql_query($ssql);
       # echo $ssql;
        $ssql="select ftsales_invoice_no,fcamount,ftcustomer_code from txsales_invoice_hdr where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);
        $parent_code=RetRstField("select ifnull(ftparent_code,'') from tlcustomer where ftcustomer_code='".$r['ftcustomer_code']."'");
        if($parent_code) {
            $address=RetRstField("select CONCAT(IFNULL(b.ftaddress_3,''),' ',IFNULL(b.ftcity,''),' ',IFNULL(b.ftstate,'')) AS hdr_ftship_address from tlcustomer b where ftcustomer_code='".$parent_code."'");
        }
        else {
            $address=RetRstField("select CONCAT(IFNULL(b.ftaddress_3,''),' ',IFNULL(b.ftcity,''),' ',IFNULL(b.ftstate,'')) AS hdr_ftship_address from tlcustomer b where ftcustomer_code='".$r['ftcustomer_code']."'");
        }

          $ssql="select count(a1.fnid) as jml
                from txsales_invoice_hdr a1
                where a1.ftsales_invoice_no like '".$r["ftsales_invoice_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");
                
        $paramsx[]=array("name"=>"trans_no",
                          "value"=>$r["ftsales_invoice_no"],
                          "type"=>"string");
        $temp=terbilang($r["fcamount"]);
            $paramsx[]=array("name"=>"say",
                          "value"=>$temp,
                          "type"=>"string");
            $paramsx[]=array("name"=>"address",
                          "value"=>$address,
                          "type"=>"string");

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


        break;
    
    case "salesinvoicenonpt":
        $ssql="select ftsales_invoice_no,fcamount,ftcustomer_code from txsales_invoice_hdr where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);
        $parent_code=RetRstField("select ifnull(ftparent_code,'') from tlcustomer where ftcustomer_code='".$r['ftcustomer_code']."'");
        if($parent_code) {
            $address=RetRstField("select CONCAT(IFNULL(b.ftaddress_3,''),' ',IFNULL(b.ftcity,''),' ',IFNULL(b.ftstate,'')) AS hdr_ftship_address from tlcustomer b where ftcustomer_code='".$parent_code."'");
        }
        else {
            $address=RetRstField("select CONCAT(IFNULL(b.ftaddress_3,''),' ',IFNULL(b.ftcity,''),' ',IFNULL(b.ftstate,'')) AS hdr_ftship_address from tlcustomer b where ftcustomer_code='".$r['ftcustomer_code']."'");
        }

        $ssql="select count(a1.fnid) as jml
                from txsales_invoice_hdr a1
                where a1.ftsales_invoice_no like '".$r["ftsales_invoice_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");
                
        $paramsx[]=array("name"=>"trans_no",
                          "value"=>$r["ftsales_invoice_no"],
                          "type"=>"string");
        $temp=terbilang($r["fcamount"]);
        $paramsx[]=array("name"=>"say",
                      "value"=>$temp,
                      "type"=>"string");
        $paramsx[]=array("name"=>"address",
                      "value"=>$address,
                      "type"=>"string");

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

        break;
        
    
    case "deliveryorder_cetak_non_pt":
        $ssql="select ftdo_no from txdelivery_order_hdr where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);
        
        $paramsx[]=array("name"=>"trans_no",
                          "value"=>$r["ftdo_no"],
                          "type"=>"string");
         $paramsx[]=array("name"=>"username",
                          "value"=>$_SESSION['username'],
                          "type"=>"string");
        $paramsx[]=array("name"=>"REPORT_DIR",
                        "value"=>"images/",
                        "type"=>"string");
        
        $ssql="select count(a1.fnid) as jml
                from txdelivery_order_hdr a1
                where a1.ftdo_no like '".$r["ftdo_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."crprint02_sj1_non_pt",$paramsx);
        
    break;
    
    case "deliveryorder_cetak_non_pt2":
        $ssql="select ftdo_no from txdelivery_order_hdr where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);
        
        $paramsx[]=array("name"=>"trans_no",
                          "value"=>$r["ftdo_no"],
                          "type"=>"string");
         $paramsx[]=array("name"=>"username",
                          "value"=>$_SESSION['username'],
                          "type"=>"string");
        $paramsx[]=array("name"=>"REPORT_DIR",
                        "value"=>"images/",
                        "type"=>"string");
        
        $ssql="select count(a1.fnid) as jml
                from txdelivery_order_hdr a1
                where a1.ftdo_no like '".$r["ftdo_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."crprint02_sj1_non_pt2",$paramsx);
        
        break;
     
    case "rekapdeliveryorder":
        $ssql="select ftrekap_do_no from txrekap_delivery_order_hdr where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);
        
        $paramsx[]=array("name"=>"trans_no",
                          "value"=>$r["ftrekap_do_no"],
                          "type"=>"string");
        $paramsx[]=array("name"=>"username",
                          "value"=>$_SESSION['username'],
                          "type"=>"string");
        
        if($_SESSION['username']=="admin") {
             show_report($dir."crprint04_rekap_DO",$paramsx);
        }
        else {
             show_report($dir."crprint04_rekap_DO",$paramsx);
        }
       
        break;	

    case "returpenjualan_cetak_non_pt":
        $ssql="select ftsales_return_no, fcamount from txsales_return_hdr where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_array($rs);
        $temp=terbilang($r['1']);
        $paramsx[]=array("name"=>"trans_no",
                          "value"=>$r[0],
                          "type"=>"string");
        $paramsx[]=array("name"=>"say",
                        "value"=>$temp,
                        "type"=>"string");
        show_report($dir."crprint05_sales_return_non_pt",$paramsx);
        break;    

   
        */
}
