<?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";
//foreach ($_REQUEST as $key1 => $value1) {
//  $_REQUEST[$key1]=str_replace('_|_','/',$_REQUEST[$key1]);
//}

$dir="report/akunting/report/";
$dir_sub=_REPORT_PATH."/report/akunting/report/";
$paramsx=array();

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

// innitialize parameters
if(strtoupper($_REQUEST['ftitem_code'])=="") 
    $_REQUEST['ftitem_code']="SELURUH";

if(strtoupper($_REQUEST['ftstock_group'])=="") 
    $_REQUEST['ftstock_group']="SELURUH";

if(strtoupper($_REQUEST['ftwarehouse'])=="") 
    $_REQUEST['ftwarehouse']="SELURUH";

if(strtoupper($_REQUEST['ftlocation'])=="") 
    $_REQUEST['ftlocation']="SELURUH"; 

if(strtoupper($_REQUEST['ftcoa_code_from'])=="") 
    $_REQUEST['ftcoa_code_from']="SELURUH"; 

if(strtoupper($_REQUEST['ftcoa_code_end'])=="") 
    $_REQUEST['ftcoa_code_end']="SELURUH"; 


switch ($code) {
    case "acc00":
        if($_REQUEST['fnstatus']=="SELURUH") {
            $fnstatus="";
        }
        else {
            $fnstatus=$_REQUEST['fnstatus'];
        }
        
        $paramsx[]=array("name"=>"pfnstatus",
                          "value"=>$fnstatus,
                          "type"=>"string");
        $paramsx[]=array("name"=>"username",
                          "value"=>$_SESSION['username'],
                          "type"=>"string");
        show_report($dir."report00_no_perkiraan",$paramsx);
        break;

    case "acc01":
        
        $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']). " 12:59:59",
                          "type"=>"date");
        $paramsx[]=array("name"=>"username",
                          "value"=>$_SESSION['username'],
                          "type"=>"string");

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

    // testing report baru
    /* case "acc02":

       if ($_REQUEST['type'] == 'pdf') {
           require_once 'report_new/laporan_buku_besar.php';
           require_once 'report_new/jspdf/pdfFromHTML.php';
          // require_once 'report_new/laporan_buku_besar_pdf.php';
          }else if($_REQUEST['type'] == 'excel'){
            require_once "report_new/excel/setting.php";
            require_once 'report_new/laporan_buku_besar.php';
          }else{
            require_once 'report_new/laporan_buku_besar.php';
        }

    break; */
    
    case "acc02":     
      
        $fdperiodesaldo = RetRstField("SELECT DISTINCT CONCAT(YEAR(fdperiodesaldo),'-01-01') FROM thsaldoperkiraan ORDER BY fdperiodesaldo DESC LIMIT 1");
        if ($fdperiodesaldo == "") {
            $fdperiodesaldo = RetRstField("SELECT CONCAT(YEAR(fdstart_period),'-01-01') FROM tscompany_info ");
        }
        
        $paramsx[]=array("name"=>"coa_code_from",
                          "value"=>$_REQUEST['ftcoa_code_from'],
                          "type"=>"string");
        $paramsx[]=array("name"=>"coa_code_end",
                          "value"=>$_REQUEST['ftcoa_code_end'],
                          "type"=>"string");
        $paramsx[]=array("name"=>"date_last_saldo",
                          "value"=>$fdperiodesaldo." 00:00:00",
                          "type"=>"date");
        $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']). " 12:59:59",
                          "type"=>"date");
        $paramsx[]=array("name"=>"username",
                          "value"=>$_SESSION['username'],
                          "type"=>"string");

        if ($_SESSION["sys_multi_currency"]) {
            show_report($dir."report02_buku_besar_curr",$paramsx);
        } else {
            show_report($dir."report02_buku_besar",$paramsx);
        }
        
        break;
       
    case "acc03":

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

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

    case "acc04":

        $fdperiodesaldo = RetRstField("SELECT DISTINCT CONCAT(YEAR(fdperiodesaldo),'-01-01') FROM thsaldoperkiraan ORDER BY fdperiodesaldo DESC LIMIT 1");

        $paramsx[]=array("name"=>"pdate_end",
                          "value"=>Cdate($_REQUEST['date_end']). " 12:59:59",
                          "type"=>"date");
        $paramsx[]=array("name"=>"pdate_last_saldo",
                          "value"=>$fdperiodesaldo." 00:00:00",
                          "type"=>"date");
        $paramsx[]=array("name"=>"username",
                          "value"=>$_SESSION['username'],
                          "type"=>"string");

        show_report($dir."report04_neraca_periode",$paramsx);
       break;
   
    case "acc05":

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

        show_report($dir."report03_neraca_percobaan",$paramsx);
        break;
   
    case "acc06":

        $fdperiodesaldo = RetRstField("SELECT DISTINCT CONCAT(YEAR(fdperiodesaldo),'-01-01') FROM thsaldoperkiraan ORDER BY fdperiodesaldo DESC LIMIT 1");

        $paramsx[]=array("name"=>"pdate_end",
                          "value"=>Cdate($_REQUEST['date_end']). " 12:59:59",
                          "type"=>"date");
        $paramsx[]=array("name"=>"pdate_last_saldo",
                          "value"=>$fdperiodesaldo." 00:00:00",
                          "type"=>"date");
        $paramsx[]=array("name"=>"username",
                          "value"=>$_SESSION['username'],
                          "type"=>"string");

        show_report($dir."report05_neraca_percobaan",$paramsx);
       break;   
   
    case "acc07":   
        /* if($_REQUEST['ftlocation']=="SELURUH") {
            $location="%%";
        }
        else {
            $location=$_REQUEST['location'];
        }

        if($_REQUEST['ftitem_code']=="SELURUH") {
            $ftitem_code="%%";
        }
        else {
            $ftitem_code=$_REQUEST['ftitem_code'];
        } */

        $paramsx[]=array("name"=>"fnwarehouse_type",
                         "value"=>$_REQUEST['fnwarehouse_type'],
                         "type"=>"string");
        $paramsx[]=array("name"=>"ftwarehouse",
                         "value"=>$_REQUEST['ftwarehouse'],
                         "type"=>"string");
        $paramsx[]=array("name"=>"ftlocation",
                         "value"=>$_REQUEST['ftlocation'],
                         "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."report05_per_lokasi",$paramsx);
        break;
    
    case "acc08":
        $paramsx[]=array("name"=>"date_from",
                          "value"=>Cdate($_REQUEST['date_from']). " 00:00:01",
                          "type"=>"date");
        $paramsx[]=array("name"=>"date_end",
                          "value"=>Cdate($_REQUEST['date_end']). " 12:59:59",
                          "type"=>"date");
        $paramsx[]=array("name"=>"username",
                          "value"=>$_SESSION['username'],
                          "type"=>"string");

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

     case "acc09":

        $fdperiodesaldo = RetRstField("SELECT DISTINCT CONCAT(YEAR(fdperiodesaldo),'-01-01') FROM thsaldoperkiraan ORDER BY fdperiodesaldo DESC LIMIT 1");

        $paramsx[]=array("name"=>"pdate_end",
                          "value"=>Cdate($_REQUEST['date_end']). " 12:59:59",
                          "type"=>"date");
        $paramsx[]=array("name"=>"pdate_last_saldo",
                          "value"=>$fdperiodesaldo." 00:00:00",
                          "type"=>"date");
        $paramsx[]=array("name"=>"username",
                          "value"=>$_SESSION['username'],
                          "type"=>"string");

        show_report($dir."report09_neraca_perincian",$paramsx);
       break;
   
    case "acc14":   
        $paramsx[]=array("name"=>"fnwarehouse_type",
                         "value"=>$_REQUEST['fnwarehouse_type'],
                         "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."report14_inventory_per_barang",$paramsx);
        break;
    
    case "acc15":   
        $paramsx[]=array("name"=>"fnwarehouse_type",
                         "value"=>$_REQUEST['fnwarehouse_type'],
                         "type"=>"string");
        $paramsx[]=array("name"=>"ftwarehouse",
                         "value"=>$_REQUEST['ftwarehouse'],
                         "type"=>"string");
        $paramsx[]=array("name"=>"ftlocation",
                         "value"=>$_REQUEST['ftlocation'],
                         "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."report15_inventory_per_lokasi",$paramsx);
        break;
    
    case "acc16":         
        $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_inventory_penyesuaian",$paramsx);
        break;
           
    
    case "acc17":   
        $paramsx[]=array("name"=>"fnwarehouse_type",
                         "value"=>$_REQUEST['fnwarehouse_type'],
                         "type"=>"string");
        $paramsx[]=array("name"=>"ftwarehouse",
                         "value"=>$_REQUEST['ftwarehouse'],
                         "type"=>"string");
        $paramsx[]=array("name"=>"ftlocation",
                         "value"=>$_REQUEST['ftlocation'],
                         "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."report17_inventory_per_jenis",$paramsx);
        break;
    
    case "acc18":
        $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."report18_margin_penjualan",$paramsx);
        break;   
    
     case "acc19":          
            $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."report19_inventory_per_group",$paramsx);
        break;
    
    case "acc20":   
        $paramsx[]=array("name"=>"fnwarehouse_type",
                         "value"=>$_REQUEST['fnwarehouse_type'],
                         "type"=>"string");
        $paramsx[]=array("name"=>"ftwarehouse",
                         "value"=>$_REQUEST['ftwarehouse'],
                         "type"=>"string");
        $paramsx[]=array("name"=>"ftlocation",
                         "value"=>$_REQUEST['ftlocation'],
                         "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."report20_inventory_per_gudang",$paramsx);
        break;
    
    case "acc21":

        //date from
        list($dt, $mn, $yr)=split("-", $_REQUEST['date_from']);

        //date end
        list($dt1, $mn1, $yr1)=split("/", $_REQUEST['date_end']);

        if ($mn != $mn1) {
            $datefrom = $yr1 . '-' . $mn1 . '-' . $yr;
        }else{
            $datefrom = $_REQUEST['date_from'];
        }

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

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

        break;
}