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

$dir="report/penjualan/report/";

$paramsx=array();

$ssql="select * from tlreport where fnid='{$_REQUEST['id']}'";
$rs=mysql_query($ssql);
$r=mysql_fetch_assoc($rs);
$code=$r['ftreport_code'];
//$code=$_REQUEST['code'];

switch ($code) {
    case "s01":        
        $paramsx[]=array("name"=>"currency_code",
                          "value"=>$_REQUEST['currency_code'],
                          "type"=>"string");
        $paramsx[]=array("name"=>"si_no",
                          "value"=>$_REQUEST['ftsi_no'],
                          "type"=>"string");
        $paramsx[]=array("name"=>"date_from",
                          "value"=>Cdate($_REQUEST['date_from'])." 00:00:00",
                          "type"=>"date");
        $paramsx[]=array("name"=>"date_end",
                          "value"=>Cdate($_REQUEST['date_end']). " 00:00:00",
                          "type"=>"date");
        $paramsx[]=array("name"=>"username",
                          "value"=>$_SESSION['username'],
                          "type"=>"string");
        show_report($dir."report01_per_faktur",$paramsx);
        break;
    
    case "s02":          
            if(strtoupper($_REQUEST['customer_code'])=="SELURUH") 
            $_REQUEST['customer_code']="";
        
            $paramsx[]=array("name"=>"customer_code",
                          "value"=>$_REQUEST['customer_code'],
                          "type"=>"string");
            $paramsx[]=array("name"=>"currency_code",
                          "value"=>$_REQUEST['currency_code'],
                          "type"=>"string");
            $paramsx[]=array("name"=>"date_from",
                          "value"=>Cdate($_REQUEST['date_from'])." 00:00:00",
                          "type"=>"date");
            $paramsx[]=array("name"=>"date_end",
                          "value"=>Cdate($_REQUEST['date_end']). " 00:00:00",
                          "type"=>"date");
            $paramsx[]=array("name"=>"username",
                          "value"=>$_SESSION['username'],
                          "type"=>"string");
            show_report($dir."report02_per_customer",$paramsx);
        break;
    
    case "s03":          
        if(strtoupper($_REQUEST['sales_code'])=="SELURUH") 
            $_REQUEST['sales_code']="";
        
        $paramsx[]=array("name"=>"sales_code",
                      "value"=>$_REQUEST['sales_code'],
                      "type"=>"string");
        $paramsx[]=array("name"=>"currency_code",
                      "value"=>$_REQUEST['currency_code'],
                      "type"=>"string");
        $paramsx[]=array("name"=>"date_from",
                      "value"=>Cdate($_REQUEST['date_from'])." 00:00:00",
                      "type"=>"date");
        $paramsx[]=array("name"=>"date_end",
                      "value"=>Cdate($_REQUEST['date_end']). " 00:00:00",
                      "type"=>"date");
        $paramsx[]=array("name"=>"username",
                      "value"=>$_SESSION['username'],
                      "type"=>"string");
        show_report($dir."report03_per_salesman",$paramsx);

        break;

    case "s04":          
        if(strtoupper($_REQUEST['sales_code'])=="SELURUH") 
            $_REQUEST['sales_code']="";
        
        if(strtoupper($_REQUEST['currency_code'])=="SELURUH") 
            $_REQUEST['currency_code']="";
        
        $paramsx[]=array("name"=>"sales_code",
                      "value"=>$_REQUEST['sales_code'],
                      "type"=>"string");
        $paramsx[]=array("name"=>"currency_code",
                      "value"=>$_REQUEST['currency_code'],
                      "type"=>"string");
        $paramsx[]=array("name"=>"date_from",
                      "value"=>Cdate($_REQUEST['date_from'])." 00:00:00",
                      "type"=>"date");
        $paramsx[]=array("name"=>"date_end",
                      "value"=>Cdate($_REQUEST['date_end']). " 00:00:00",
                      "type"=>"date");
        $paramsx[]=array("name"=>"username",
                      "value"=>$_SESSION['username'],
                      "type"=>"string");
        show_report($dir."report04_top_per_salesman",$paramsx);

        break;
    
    case "s11":
        $ftitem_code= $_REQUEST['ftitem_code'] . "%";
        
        $paramsx[]=array("name"=>"ftitem_code",
                      "value"=>$ftitem_code,
                      "type"=>"string");
        $paramsx[]=array("name"=>"username",
                      "value"=>$_SESSION['username'],
                      "type"=>"string");
        show_report($dir."report11_daftar_harga_jual",$paramsx);
        break;
        
    case "s15":
        if(strtoupper($_REQUEST['ftitem_code'])=="SELURUH") 
            $_REQUEST['ftitem_code']="";
         
        $paramsx[]=array("name"=>"currency_code",
                      "value"=>$_REQUEST['currency_code'],
                      "type"=>"string");
        $paramsx[]=array("name"=>"item_code",
                          "value"=>$_REQUEST['ftitem_code'],
                          "type"=>"string");
        $paramsx[]=array("name"=>"sales_code",
                          "value"=>$_REQUEST['sales_code'],
                          "type"=>"string");
        $paramsx[]=array("name"=>"date_from",
                      "value"=>Cdate($_REQUEST['date_from'])." 00:00:00",
                      "type"=>"date");
        $paramsx[]=array("name"=>"date_end",
                      "value"=>Cdate($_REQUEST['date_end'])." 00:00:00",
                      "type"=>"date");
        $paramsx[]=array("name"=>"username",
                      "value"=>$_SESSION['username'],
                      "type"=>"string");

        show_report($dir."report15_penjualan_detail_per_barang",$paramsx);
        break;
    
    case "s15_2":
            $paramsx[]=array("name"=>"customer_code",
                          "value"=>$_REQUEST['customer_code'],
                          "type"=>"string");
            $paramsx[]=array("name"=>"date_from",
                          "value"=>Cdate($_REQUEST['date_from'])." 00:00:00",
                          "type"=>"date");
            $paramsx[]=array("name"=>"date_end",
                          "value"=>Cdate($_REQUEST['date_end'])." 00:00:00",
                          "type"=>"date");
            $paramsx[]=array("name"=>"username",
                          "value"=>$_SESSION['username'],
                          "type"=>"string");

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

    case "s17":     
        $paramsx[]=array("name"=>"sales_code",
                          "value"=>$_REQUEST['ftsales_code'],
                          "type"=>"string");
        $paramsx[]=array("name"=>"currency_code",
                          "value"=>$_REQUEST['currency_code'],
                          "type"=>"string");
        $paramsx[]=array("name"=>"date_from",
                          "value"=>Cdate($_REQUEST['date_from'])." 00:00:00",
                          "type"=>"date");
        $paramsx[]=array("name"=>"date_end",
                          "value"=>Cdate($_REQUEST['date_end']). " 00:00:00",
                          "type"=>"date");
        $paramsx[]=array("name"=>"username",
                          "value"=>$_SESSION['username'],
                          "type"=>"string");
        show_report($dir."report17_sales_order",$paramsx);
        break;

    
    case "s24":
        if(strtoupper($_REQUEST['sales_code'])=="SELURUH") 
            $_REQUEST['sales_code']="";
        
        $paramsx[]=array("name"=>"sales_code",
                      "value"=>$_REQUEST['sales_code'],
                      "type"=>"string");
        $paramsx[]=array("name"=>"currency_code",
                      "value"=>$_REQUEST['currency_code'],
                      "type"=>"string");
        $paramsx[]=array("name"=>"date_from",
                      "value"=>Cdate($_REQUEST['date_from'])." 00:00:00",
                      "type"=>"date");
        $paramsx[]=array("name"=>"date_end",
                      "value"=>Cdate($_REQUEST['date_end']). " 00:00:00",
                      "type"=>"date");
        $paramsx[]=array("name"=>"username",
                      "value"=>$_SESSION['username'],
                      "type"=>"string");
        show_report($dir."report24_penjualan_detail_per_sales",$paramsx);
        break;
    
    case "s25":
            $paramsx[]=array("name"=>"ftitem_code",
                          "value"=>$_REQUEST['ftitem_code'],
                          "type"=>"string");
            $paramsx[]=array("name"=>"username",
                          "value"=>$_SESSION['username'],
                          "type"=>"string");

            show_report($dir."report25_harga_jual_akhir",$paramsx);
        break;
    
    case "s26":
        if(strtoupper($_REQUEST['customer_code'])=="SELURUH") 
            $_REQUEST['customer_code']="";
        
        $paramsx[]=array("name"=>"customer_code",
                          "value"=>$_REQUEST['customer_code'],
                          "type"=>"string");
        $paramsx[]=array("name"=>"sales_code",
                      "value"=>$_REQUEST['sales_code'],
                      "type"=>"string");
        $paramsx[]=array("name"=>"currency_code",
                      "value"=>$_REQUEST['currency_code'],
                      "type"=>"string");
        $paramsx[]=array("name"=>"date_from",
                      "value"=>Cdate($_REQUEST['date_from'])." 00:00:00",
                      "type"=>"date");
        $paramsx[]=array("name"=>"date_end",
                      "value"=>Cdate($_REQUEST['date_end'])." 00:00:00",
                      "type"=>"date");
        $paramsx[]=array("name"=>"username",
                      "value"=>$_SESSION['username'],
                      "type"=>"string");

        show_report($dir."report26_penjualan_detail_per_customer",$paramsx);
        break;
        
    case "s27":
        $paramsx[]=array("name"=>"currency_code",
                      "value"=>$_REQUEST['currency_code'],
                      "type"=>"string");
        $paramsx[]=array("name"=>"si_no",
                          "value"=>$_REQUEST['ftsi_no'],
                          "type"=>"string");
        $paramsx[]=array("name"=>"date_from",
                      "value"=>Cdate($_REQUEST['date_from'])." 00:00:00",
                      "type"=>"date");
        $paramsx[]=array("name"=>"date_end",
                      "value"=>Cdate($_REQUEST['date_end'])." 00:00:00",
                      "type"=>"date");
        $paramsx[]=array("name"=>"username",
                      "value"=>$_SESSION['username'],
                      "type"=>"string");

        show_report($dir."report27_penjualan_detail_per_faktur",$paramsx);
        break;    
    
    /* Tidak digunakan di abrindo
    case "s05":
        $paramsx[]=array("name"=>"date_from",
                      "value"=>Cdate($_REQUEST['date_from'])." 00:00:00",
                      "type"=>"date");
        $paramsx[]=array("name"=>"date_end",
                      "value"=>Cdate($_REQUEST['date_end']). " 00:00:00",
                      "type"=>"date");
        $paramsx[]=array("name"=>"username",
                      "value"=>$_SESSION['username'],
                      "type"=>"string");
        show_report($dir."report03_per_stock_group",$paramsx);          
        break;
    
    case "s08":          
        if(strtolower($_REQUEST['customer_code'])=="seluruh") {
                $_REQUEST['customer_code']="%";
        }

        $paramsx[]=array("name"=>"customer_code",
                      "value"=>$_REQUEST['customer_code'],
                      "type"=>"string");
        $paramsx[]=array("name"=>"currency_code",
                      "value"=>$_REQUEST['currency_code'],
                      "type"=>"string");
        $paramsx[]=array("name"=>"date_from",
                      "value"=>Cdate($_REQUEST['date_from'])." 00:00:00",
                      "type"=>"date");
        $paramsx[]=array("name"=>"date_end",
                      "value"=>Cdate($_REQUEST['date_end']). " 00:00:00",
                      "type"=>"date");
        $paramsx[]=array("name"=>"username",
                      "value"=>$_SESSION['username'],
                      "type"=>"string");
        show_report($dir."report04_per_customer_jml_pembayaran",$paramsx);
        break;
        
    case "s09":
        if(strtolower($_REQUEST['ftstock_group_code'])=="seluruh") {
                $_REQUEST['ftstock_group_code']="%";
        }

        $paramsx[]=array("name"=>"stock_group",
                      "value"=>$_REQUEST['ftstock_group_code'],
                      "type"=>"string");
        $paramsx[]=array("name"=>"date_from",
                      "value"=>Cdate($_REQUEST['date_from'])." 00:00:00",
                      "type"=>"date");
        $paramsx[]=array("name"=>"date_end",
                      "value"=>Cdate($_REQUEST['date_end']). " 00:00:00",
                      "type"=>"date");
        $paramsx[]=array("name"=>"username",
                      "value"=>$_SESSION['username'],
                      "type"=>"string");
        show_report($dir."report05_per_jenis_per_stock_detail",$paramsx);          
        break;
        
    
        
    case "s12":
        if(strtolower($_REQUEST['customer_code'])=="seluruh") {
                $_REQUEST['customer_code']="%";
        }

        $paramsx[]=array("name"=>"customer_code",
                      "value"=>$_REQUEST['customer_code'],
                      "type"=>"string");
        $paramsx[]=array("name"=>"currency_code",
                      "value"=>$_REQUEST['currency_code'],
                      "type"=>"string");
        $paramsx[]=array("name"=>"date_from",
                      "value"=>Cdate($_REQUEST['date_from'])." 00:00:00",
                      "type"=>"date");
        $paramsx[]=array("name"=>"date_end",
                      "value"=>Cdate($_REQUEST['date_end'])." 00:00:00",
                      "type"=>"date");
        $paramsx[]=array("name"=>"username",
                      "value"=>$_SESSION['username'],
                      "type"=>"string");

        show_report($dir."report08_penjualan_buat_bonus",$paramsx);
        break;
    
    case "s13":
        $paramsx[]=array("name"=>"date_from",
                      "value"=>$_REQUEST['date_from'],
                      "type"=>"string");
        $paramsx[]=array("name"=>"username",
                      "value"=>$_SESSION['username'],
                      "type"=>"string");
        show_report($dir."report12_penjualan_per_bulan",$paramsx);
        break;

    case "s14":
        $paramsx[]=array("name"=>"date_from",
                      "value"=>$_REQUEST['date_from'],
                      "type"=>"string");
        $paramsx[]=array("name"=>"username",
                      "value"=>$_SESSION['username'],
                      "type"=>"string");
        show_report($dir."report14_penjualan_barang_per_bulan",$paramsx);
        break;
    
    case "s18":
        if($_REQUEST['customer_type']=='SELURUH') {
                $customer_type="%%";
                $customer_type_name="SELURUH";
        }
        else {
                $ssql="SELECT  ftcustomer_type_name
                                FROM tlcustomer_type
                                WHERE ftcustomer_type_code='{$_REQUEST['customer_type']}'";

                $customer_type=$_REQUEST['customer_type'] ;
                $customer_type_name=RetRstField($ssql);
        }

        $paramsx[]=array("name"=>"customer_type_code",
                        "value"=>$customer_type,
                        "type"=>"string");
        $paramsx[]=array("name"=>"customer_type_name",
                        "value"=>$customer_type_name,
                        "type"=>"string");
        $paramsx[]=array("name"=>"date_from",
                        "value"=>Cdate($_REQUEST['date_from'])." 00:00:00",
                        "type"=>"date");
        $paramsx[]=array("name"=>"date_end",
                        "value"=>Cdate($_REQUEST['date_end']). " 00:00:00",
                        "type"=>"date");
        $paramsx[]=array("name"=>"username",
                        "value"=>$_SESSION['username'],
                        "type"=>"string");

        show_report($dir."report14_penjualan_omset",$paramsx);
        break;
        
    case "s19":
        $paramsx[]=array("name"=>"date_from",
            "value"=>Cdate($_REQUEST['date_from'])." 00:00:00",
            "type"=>"date");
        $paramsx[]=array("name"=>"date_end",
            "value"=>Cdate($_REQUEST['date_end']). " 00:00:00",
            "type"=>"date");
        $paramsx[]=array("name"=>"username",
            "value"=>$_SESSION['username'],
            "type"=>"string");
        
        show_report($dir."report15_dj_invoice_batal",$paramsx);
        break;
    
    case "s20":
        $paramsx[]=array("name"=>"date_from",
            "value"=>Cdate($_REQUEST['date_from'])." 00:00:00",
            "type"=>"date");
        $paramsx[]=array("name"=>"date_end",
            "value"=>Cdate($_REQUEST['date_end'])." 00:00:00",
            "type"=>"date");
        $paramsx[]=array("name"=>"username",
            "value"=>$_SESSION['username'],
            "type"=>"string");
        show_report($dir."report16_sales_return",$paramsx);
        break;
    
    case "s21":
        if(strtolower($_REQUEST['customer_code'])=="seluruh") {
                $_REQUEST['customer_code']="%";
        }
            
        $paramsx[]=array("name"=>"customer_code",
            "value"=>$_REQUEST['customer_code'],
            "type"=>"string");
        $paramsx[]=array("name"=>"date_from",
            "value"=>Cdate($_REQUEST['date_from'])." 00:00:00",
            "type"=>"date");
        $paramsx[]=array("name"=>"date_end",
            "value"=>Cdate($_REQUEST['date_end'])." 00:00:00",
            "type"=>"date");
        $paramsx[]=array("name"=>"username",
            "value"=>$_SESSION['username'],
            "type"=>"string");
        show_report($dir."report21_sales_return_per_customer",$paramsx);
        break;
        
    case "s22":
        $paramsx[]=array("name"=>"date_from",
            "value"=>Cdate($_REQUEST['date_from'])." 00:00:00",
            "type"=>"date");
        $paramsx[]=array("name"=>"date_end",
            "value"=>Cdate($_REQUEST['date_end'])." 00:00:00",
            "type"=>"date");
        $paramsx[]=array("name"=>"username",
            "value"=>$_SESSION['username'],
            "type"=>"string");
        show_report($dir."report22_sales_return_per_faktur",$paramsx);
        break;

    case "s23":
        $paramsx[]=array("name"=>"customer_code",
                      "value"=>$_REQUEST['customer_code'],
                      "type"=>"string");
        $paramsx[]=array("name"=>"ftitem_code",
                       "value"=>$_REQUEST['ftitem_code'],
                      "type"=>"string");
        $paramsx[]=array("name"=>"date_from",
                      "value"=>Cdate($_REQUEST['date_from'])." 00:00:00",
                      "type"=>"date");
        $paramsx[]=array("name"=>"date_end",
                      "value"=>Cdate($_REQUEST['date_end'])." 00:00:00",
                      "type"=>"date");
        $paramsx[]=array("name"=>"username",
                      "value"=>$_SESSION['username'],
                      "type"=>"string");

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

    */
}