<?php
    $objAxpDB->ViewName("Daftar laporan inventory");
    $objAxpDB->ViewTable("vIPLaporan");
    $objAxpDB->ViewSQL("SELECT fnid,ftreport_code,  ftreport_name FROM tlreport WHERE ftreport_group = 'inventory_setengah_jadi' order by ftreport_code");
    $objAxpDB->ViewCaption("ID,ftreport_code, Nama laporan");

    $objAxpDB->FormName(" laporan inventory setengah jadi");
    $objAxpDB->FormSQL("SELECT ftreport_name
                      FROM tlreport");
    $objAxpDB->FormCaption("Nama laporan");
    $objAxpDB->FormPosition("TL");
     $objAxpDB->LookupMagicQuotes(true);
     $objAxpDB->lengt_object=false;
    if($_REQUEST['id']) {
        $ssql="select * from tlreport where fnid='{$_REQUEST['id']}'";
        $rs=mysql_query($ssql);
        $r=mysql_fetch_assoc($rs);
        $code=$r['ftreport_code'];
        $report_name=" :: ".$r['ftreport_name'];
        switch ($code) {

           case "sji00":
                $objAxpDB->Lookup("ftitem_code", "SELECT 'SELURUH' as ftitem_code,'SELURUH' AS ftitem_name UNION ALL   SELECT ftitem_code, ftitem_name FROM tlstock_hdr_setengah_jadi", "ftitem_code", "ftitem_name", -1,false);

             $objAxpDB->FormSQL("SELECT '' as ftitem_code
                      FROM tlreport");
              $objAxpDB->FormCaption("Kode Barang");
            $objAxpDB->FormPosition("TL");
          break;
          case "sji00_1":
             $objAxpDB->FormSQL("SELECT
                            CONVERT(null,date) as date_from,
                            CONVERT(null,date) as date_end
                            FROM tlreport");
            $objAxpDB->FormCaption("Date From, Date End");
            $objAxpDB->FormPosition("TR,TR");
          break;
          case "sji01":
             $objAxpDB->Lookup("ftstock_group_code", "SELECT 'SELURUH' as ftstock_group_code,'SELURUH' AS ftstock_group_name UNION ALL   SELECT ftstock_group_code, ftstock_group_name FROM tlstock_group_setengah_jadi", "ftstock_group_code", "ftstock_group_name", -1,false);
             $objAxpDB->FormSQL("SELECT  '' as ftstock_group_code,
                            CONVERT(null,date) as date_from,
                            CONVERT(null,date) as date_end
                            FROM tlreport");
            $objAxpDB->FormCaption("Stock Group, Date From,Date End");
            $objAxpDB->FormPosition("TL, TR,TR");
          break;

          case "sji03":
             $objAxpDB->Lookup("stock", "SELECT 'SELURUH' as ftitem_code,'SELURUH' AS ftitem_name UNION ALL SELECT ftitem_code, ftitem_name FROM tlstock_hdr_setengah_jadi", "ftitem_code", "ftitem_name", -1,false);
             $objAxpDB->FormSQL("SELECT '' as stock,
                            CONVERT(null,date) as date_from,
                            CONVERT(null,date) as date_end
                            FROM tlreport");
            $objAxpDB->FormCaption("Barang, Date From,Date End");
            $objAxpDB->FormPosition("TL, TR,TR");
          break;
            case "sji05":
                $objAxpDB->Lookup("warehouse", "SELECT 'SELURUH' as ftwarehouse_code,'SELURUH' AS ftwarehouse_name UNION ALL   SELECT ftwarehouse_code, ftwarehouse_name FROM tlwarehouse", "ftwarehouse_code", "ftwarehouse_name", -1,true);
                $objAxpDB->Lookup("location", "SELECT 'SELURUH' as ftlocation_code,'SELURUH' AS ftlocation_name UNION ALL SELECT ftlocation_code, ftlocation_name FROM tllocation", "ftlocation_code", "ftlocation_name", -1,true);  
                $objAxpDB->Lookup("item", "SELECT 'SELURUH' as ftitem_code,'SELURUH' AS ftitem_name UNION ALL SELECT ftitem_code, ftitem_name FROM tlstock_hdr_setengah_jadi", "ftitem_code", "ftitem_name", -1,false);

                $objAxpDB->FormSQL("SELECT '' as warehouse,'' as location,'' as item, 
                            CONVERT(null,date) as date_from, 
                            CONVERT(null,date) as date_end 
                            FROM tlreport");
                $objAxpDB->FormCaption("Gudang,Lokasi,Barang,Date From,Date End");
                $objAxpDB->FormPosition("TL,TL,TL,TR,TR");
            break;
         case "sji06":
            $objAxpDB->Lookup("ftlocation_from", "SELECT 'SELURUH' as ftlocation_code,'SELURUH' AS ftlocation_name UNION ALL   SELECT ftlocation_code, ftlocation_name FROM tllocation", "ftlocation_code", "ftlocation_name", -1,true);
            $objAxpDB->Lookup("ftlocation_to", "SELECT 'SELURUH' as ftlocation_code,'SELURUH' AS ftlocation_name UNION ALL   SELECT ftlocation_code, ftlocation_name FROM tllocation", "ftlocation_code", "ftlocation_name", -1,true);
            
            $objAxpDB->FormSQL("SELECT 
                            CONVERT(null,date) as date_from, 
                            CONVERT(null,date) as date_end,
                            'SELURUH' as ftlocation_from, 'SELURUH' as ftlocation_to
                            FROM tlreport");
            $objAxpDB->FormCaption("Date From,Date End, Location From, Location To");
            $objAxpDB->FormPosition("TL, TL, TR, TR");   
            
            break;
        case "sji07":
            $objAxpDB->FormSQL("SELECT
                            CONVERT(null,date) as date_from,
                            CONVERT(null,date) as date_end
                            FROM tlreport");
            $objAxpDB->FormCaption(" Date From,Date End");
            $objAxpDB->FormPosition("TL, TL");
          break;
          case "sji08":
             $objAxpDB->Lookup("warehouse", "SELECT 'SELURUH' as ftwarehouse_code,'SELURUH' AS ftwarehouse_name UNION ALL   SELECT ftwarehouse_code, ftwarehouse_name FROM tlwarehouse", "ftwarehouse_code", "ftwarehouse_name", -1,true);
             $objAxpDB->FormSQL("SELECT '' as warehouse,
                            CONVERT(null,date) as date_from,
                            CONVERT(null,date) as date_end
                            FROM tlreport");
            $objAxpDB->FormCaption("Gudang, Date From,Date End");
            $objAxpDB->FormPosition("TL, TR,TR");
          break;
          case "sji09":
            $objAxpDB->Lookup("location", "SELECT 'SELURUH' as ftlocation_code,'SELURUH' AS ftlocation_name UNION ALL   SELECT ftlocation_code, ftlocation_name FROM tllocation", "ftlocation_code", "ftlocation_name", -1,true);
            $objAxpDB->Lookup("ftitem_code", "SELECT 'SELURUH' as ftitem_code,'SELURUH' AS ftitem_name UNION ALL SELECT ftitem_code, ftitem_name FROM tlstock_hdr_setengah_jadi", "ftitem_code", "ftitem_name", -1,false);
            $objAxpDB->FormSQL("SELECT '' as location,
                            '' as ftitem_code,
                            CONVERT(null,date) as date_from,
                            CONVERT(null,date) as date_end
                            FROM tlreport");
            $objAxpDB->FormCaption("Lokasi,Kode Barang, Date From,Date End");
            $objAxpDB->FormPosition("TL,TL,TR,TR");
          break;
          case "sji10":
             $objAxpDB->Lookup("stock", "SELECT 'SELURUH' as ftitem_code,'SELURUH' AS ftitem_name UNION ALL   SELECT ftitem_code, ftitem_name FROM tlstock_hdr_setengah_jadi where ftstock_category_code='inv'", "ftitem_code", "ftitem_name", -1,false);
             $objAxpDB->FormSQL("SELECT '' as stock
                              FROM tlreport");
            $objAxpDB->FormCaption("Barang");
            $objAxpDB->FormPosition("TL");
          break;
        case "sji11":
            $objAxpDB->Lookup("ftcategory_code", "SELECT 'SELURUH' as ftcategory_code,'SELURUH' AS ftcategory_name UNION ALL SELECT fntrans_status_code AS ftcategory_code, fttrans_status_name AS ftcategory_name FROM tstransaction_status WHERE fntrans_group_code = 4 AND fnactive_status=1 ", "ftcategory_code", "ftcategory_name", -1,true);
            $objAxpDB->Lookup("ftitem_code", "SELECT 'SELURUH' as ftitem_code,'SELURUH' AS ftitem_name UNION ALL   SELECT ftitem_code, ftitem_name FROM tlstock_hdr_setengah_jadi where ftstock_category_code='invsj' ", "ftitem_code", "ftitem_name", -1,false);
            $objAxpDB->Lookup("ftlocation_code", "SELECT 'SELURUH' as ftlocation_code,'SELURUH' AS ftlocation_name  UNION ALL   SELECT ftlocation_code, ftlocation_code FROM tllocation", "ftlocation_code", "ftlocation_name", -1,false);

            $objAxpDB->FormSQL("SELECT
                                '' as ftcategory_code,
                                '' as ftitem_code,
                                '' as ftlocation_code,
                                CONVERT(null,date) as date_from,
                                CONVERT(null,date) as date_end
                                FROM tlreport");

            $objAxpDB->FormCaption("Kategori, Barang, Lokasi,Date From,Date End");
            $objAxpDB->FormPosition("TL,TL,TL, TR,TR");
        break;
        case "sji12":
            $objAxpDB->Lookup("ftcategory_code", "SELECT 'SELURUH' as ftcategory_code,'SELURUH' AS ftcategory_name UNION ALL SELECT fntrans_status_code AS ftcategory_code, fttrans_status_name AS ftcategory_name FROM tstransaction_status WHERE fntrans_group_code = 3 AND fnactive_status=1 ", "ftcategory_code", "ftcategory_name", -1,true);
            $objAxpDB->Lookup("ftitem_code", "SELECT 'SELURUH' as ftitem_code,'SELURUH' AS ftitem_name UNION ALL   SELECT ftitem_code, ftitem_name FROM tlstock_hdr_setengah_jadi where ftstock_category_code='invsj'", "ftitem_code", "ftitem_name", -1,false);
            $objAxpDB->Lookup("ftlocation_code", "SELECT 'SELURUH' as ftlocation_code,'SELURUH' AS ftlocation_name  UNION ALL   SELECT ftlocation_code, ftlocation_code FROM tllocation", "ftlocation_code", "ftlocation_name", -1,false);

            $objAxpDB->FormSQL("SELECT
                                '' as ftcategory_code,
                                '' as ftitem_code,
                                '' as ftlocation_code,
                                CONVERT(null,date) as date_from,
                                CONVERT(null,date) as date_end
                                FROM tlreport");

            $objAxpDB->FormCaption("Kategori, Barang, Lokasi,Date From,Date End");
            $objAxpDB->FormPosition("TL,TL,TL,TR,TR");
        break;
            case "sji13":

            $objAxpDB->FormSQL("SELECT
                                CONVERT(null,date) as date_from,
                                CONVERT(null,date) as date_end
                                FROM tlreport");

            $objAxpDB->FormCaption("Date From,Date End");
            $objAxpDB->FormPosition("TL,TL");
              break;
                case "sji14":
            $objAxpDB->Lookup("area_code", "SELECT 'SELURUH' as ftarea_code,'SELURUH' AS ftarea_name UNION ALL   SELECT ftarea_code, ftarea_name FROM tlarea", "ftarea_code", "ftarea_name", -1,true);
            $objAxpDB->FormSQL("SELECT
                                '' as area_code,
                                CONVERT(null,date) as date_from,
                                CONVERT(null,date) as date_end
                                FROM tlreport");

            $objAxpDB->FormCaption("Wilayah,Date From,Date End");
            $objAxpDB->FormPosition("TL,TR, TR");
              break;
           case "sji15":
                $objAxpDB->Lookup("subgroup_code", "SELECT 'SELURUH' as ftstock_subgroup_code,'SELURUH' AS ftstock_subgroup_name UNION ALL   SELECT ftstock_subgroup_code, ftstock_subgroup_name FROM tlstock_subgroup", "ftstock_subgroup_code", "ftstock_subgroup_name", -1,false);

                $objAxpDB->Lookup("customer_code", "SELECT 'SELURUH' as ftcustomer_code,'SELURUH' AS ftcustomer_name UNION ALL   SELECT ftcustomer_code, ftcustomer_name FROM tlcustomer", "ftcustomer_code", "ftcustomer_name", -1,false);
                $objAxpDB->FormSQL("SELECT
                                    '' as customer_code, '' as subgroup_code,
                                    CONVERT(null,date) as date_from,
                                    CONVERT(null,date) as date_end
                                    FROM tlreport");

                $objAxpDB->FormCaption("Customer,Subgroup,Date From,Date End");
                $objAxpDB->FormPosition("TL,TL,TR, TR");
              break;
             case "sji16":

               $objAxpDB->FormSQL("SELECT
                                    CONVERT(null,date) as date_from,
                                    CONVERT(null,date) as date_end
                                    FROM tlreport");

                $objAxpDB->FormCaption("Subgroup,Date From,Date End");
                $objAxpDB->FormPosition("TL,TR, TR");
              break;
        }
    }



    $objAxpDB->Process();
    if(!$_REQUEST['id']) {
        $objAxpDB->WriteHtmlTable();
    }
    else {
         $objAxpDB->FormName("laporan inventory setengah jadi".$report_name);
         $objAxpDB->ButtonShow("generate_report,print_report,export_excel_report,export_pdf_report");
        $objAxpDB->reportData();
    }