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

switch ($_REQUEST['form']) {
    case "stockmasukreturn":
        $ssql="select ftstock_in_return_no from txstock_in_return_hdr_bahan_baku where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);

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

        show_report($dir."crprint02_stok_masuk_return",$paramsx);
        break;
     case "stockmasukservice":
        $ssql="select ftstock_in_return_no from txstock_in_return_hdr_bahan_baku where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);

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

        show_report($dir."crprint02_stok_masuk_service",$paramsx);
   break;
    case "stockmasuk":
        $ssql="select ftstock_in_no, ftcategory_code from txstock_in_hdr where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);
        
        $paramsx[]=array("name"=>"trans_no",
                          "value"=>$r["ftstock_in_no"],
                          "type"=>"string");
    
        if ($r["ftcategory_code"]==9) {
            show_report($dir."spprint01_stok_masuk_tukar",$paramsx);
        } else {
            show_report($dir."spprint01_stok_masuk",$paramsx);
        }    
        break;
    break;
      case "stockkeluarbahanbaku":
        $ssql="select ftstock_out_no,ftcategory_code from txstock_out_hdr_bahan_baku where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);
        
        $paramsx[]=array("name"=>"trans_no",
                          "value"=>$r["ftstock_out_no"],
                          "type"=>"string");
        $paramsx[]=array("name"=>"username",
                          "value"=>$_SESSION['username'],
                          "type"=>"string");
      
         show_report($dir."spprint02_stok_keluar",$paramsx);
      
      
    break;
    case "mutasibarang":
        $ssql="select ftstock_mutation_no from txstock_mutation_hdr_bahan_baku where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);
        
        $paramsx[]=array("name"=>"trans_no",
                          "value"=>$r["ftstock_mutation_no"],
                          "type"=>"string");
    
        show_report($dir."spprint03_mutasi",$paramsx);
    break;
    case "mutasibarangjadi":
        $ssql="select ftstock_mutation_no from txstock_mutation_hdr_bbtobj where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);

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

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

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

         $ssql="select ftdo_no from txdelivery_order_hdr_bahan_baku 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");

        $ssql="select count(a1.fnid) as jml
                from txdelivery_order_hdr_bahan_baku 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");
        if($_SESSION['username']=="admin") {
             show_report($dir."crprint02_sj_bahan_baku",$paramsx);
        }
        else {
             show_report($dir."crprint02_sj_bahan_baku",$paramsx);
        }

     
   break;

   case "deliveryorderfree":

         $ssql="select ftdo_no from txdelivery_order_hdr_free 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");

        $ssql="select count(a1.fnid) as jml
                from txdelivery_order_hdr_free 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");
        if($_SESSION['username']=="admin") {
             show_report($dir."crprint02_sj_free",$paramsx);
        }
        else {
             show_report($dir."crprint02_sj_free",$paramsx);
        }
        break;
  
       case "deliveryordersample":

         $ssql="select ftdo_no from txdelivery_order_hdr_sample 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");

        $ssql="select count(a1.fnid) as jml
                from txdelivery_order_hdr_sample 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");
        if($_SESSION['username']=="admin") {
             show_report($dir."crprint02_sj_sample",$paramsx);
        }
        else {
             show_report($dir."crprint02_sj_sample",$paramsx);
        }
        break;
  
         case "pengembalianbarang":

         $ssql="select ftfpb_no from txpengembalian_barang_hdr where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);

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

        $ssql="select count(a1.fnid) as jml
                from txpengembalian_barang_hdr a1
                where a1.ftfpb_no like '".$r["ftfpb_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");
//           pr($paramsx);
         show_report($dir."crprint05_pengembalian_barang",$paramsx);
        break;




}