<?php  
    $objAxpDB->ViewName("Daftar laporan akunting");
    $objAxpDB->ViewSQL("SELECT fnid, ftreport_code,  ftreport_name FROM tlreport WHERE ftreport_group = 'akunting' order by ftreport_code");
    $objAxpDB->ViewCaption("ID,Kode Laporan, Nama laporan");
    
    $objAxpDB->FormName("laporan akunting");
    $objAxpDB->FormSQL("SELECT ftreport_name FROM tlreport WHERe fnstatus = 1");
    $objAxpDB->FormCaption("Nama laporan");
    $objAxpDB->FormPosition("TL");
    $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 "acc00":
                $objAxpDB->Lookup("fnstatus", "SELECT 'SELURUH' as fnstatus, 'SELURUH' AS fnstatus_name UNION ALL  SELECT fnTrans_Status_Code as fnstatus, ftTrans_Status_Name as fnstatus_name FROM tstransaction_status WHERE fnTrans_Group_Code = 9 AND fnTrans_Status_Code != 2 ", "fnstatus", "fnstatus_name", -1,true);
                
                $objAxpDB->FormSQL("SELECT 'SELURUH' as fnstatus FROM tlreport");
                $objAxpDB->FormCaption("Status");
                $objAxpDB->FormPosition("TL");
                break;

            case "acc01":
                $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 "acc02":
                $objAxpDB->Lookup("ftcoa_code_from", "SELECT 'SELURUH' as ftcoa_code, 'SELURUH' AS ftcoa_name UNION ALL  SELECT ftcoa_code, ftcoa_name FROM tlcoa WHERE fnstatus = 1 ", "ftcoa_code", "ftcoa_name", -1,false);
                $objAxpDB->Lookup("ftcoa_code_end", "SELECT 'SELURUH' as ftcoa_code, 'SELURUH' AS ftcoa_name UNION ALL  SELECT ftcoa_code, ftcoa_name FROM tlcoa WHERE fnstatus = 1 ", "ftcoa_code", "ftcoa_name", -1,false);
                
                $objAxpDB->FormSQL("SELECT '' as ftcoa_code_from, '' as ftcoa_code_end,
                                CONVERT(null,date) as date_from,
                                CONVERT(null,date) as date_end
                                FROM tlreport");
                $objAxpDB->FormCaption("No Perkiraan From,No Perkiraan End,Date From,Date End");
                $objAxpDB->FormPosition("TL, TL, TR, TR");
                break;

            case "acc03":
                $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 "acc04":
                $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 "acc05":
                $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 "acc08":
                $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 "acc09":
                $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 "acc14":
                $objAxpDB->Lookup("fnwarehouse_type", "SELECT 'SELURUH' as fntrans_status_code,'SELURUH' AS fttrans_status_name UNION ALL  SELECT fntrans_status_code, fttrans_status_name FROM tstransaction_status WHERE fntrans_group_code = 55 and fnactive_status = 1 ", "fntrans_status_code", "fttrans_status_name", -1,true);  
                $objAxpDB->Lookup("ftitem_code", "SELECT 'SELURUH' as ftitem_code,'SELURUH' AS ftitem_name UNION ALL SELECT ftitem_code, CONCAT(TRIM(ftitem_name),CASE WHEN TRIM(ftpart_no) != '' THEN ' PART NO: ' ELSE '' END,ftpart_no) AS ftitem_name FROM tlstock_hdr WHERE fnstatus=1 ORDER BY ftitem_name ", "ftitem_code", "ftitem_name",-1,false);
                $objAxpDB->FormSQL("SELECT '' AS fnwarehouse_type, '' as ftitem_code,
                                            CONVERT(null,date) as date_from,
                                            CONVERT(null,date) as date_end
                                    FROM tlreport");
                $objAxpDB->FormCaption("Tipe Gudang, Kode Barang, Date From,Date End");
                $objAxpDB->FormPosition("TL,TL,TR,TR");
                break; 
            
            case "acc15":
                $objAxpDB->Lookup("fnwarehouse_type", "SELECT 'SELURUH' as fntrans_status_code,'SELURUH' AS fttrans_status_name UNION ALL  SELECT fntrans_status_code, fttrans_status_name FROM tstransaction_status WHERE fntrans_group_code = 55 and fnactive_status = 1 ", "fntrans_status_code", "fttrans_status_name", -1,true);  
                $objAxpDB->Lookup("ftwarehouse", "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("ftlocation", "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, CONCAT(TRIM(ftitem_name),CASE WHEN TRIM(ftpart_no) != '' THEN ' PART NO: ' ELSE '' END,ftpart_no) AS ftitem_name FROM tlstock_hdr WHERE fnstatus=1 ORDER BY ftitem_name ", "ftitem_code", "ftitem_name",-1,false);
                $objAxpDB->FormSQL("SELECT '' AS fnwarehouse_type, '' as ftwarehouse, '' as ftlocation, '' as ftitem_code,
                                            CONVERT(null,date) as date_from,
                                            CONVERT(null,date) as date_end
                                    FROM tlreport");
                $objAxpDB->FormCaption("Tipe Gudang, Gudang, Lokasi,Kode Barang, Date From,Date End");
                $objAxpDB->FormPosition("TL, TL,TL,TL,TR,TR");
                break; 
            
            case "acc16":
                $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 "acc17":
                $objAxpDB->Lookup("fnwarehouse_type", "SELECT 'SELURUH' as fntrans_status_code,'SELURUH' AS fttrans_status_name UNION ALL  SELECT fntrans_status_code, fttrans_status_name FROM tstransaction_status WHERE fntrans_group_code = 55 and fnactive_status = 1 ", "fntrans_status_code", "fttrans_status_name", -1,true);  
                $objAxpDB->Lookup("ftwarehouse", "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("ftlocation", "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, CONCAT(TRIM(ftitem_name),CASE WHEN TRIM(ftpart_no) != '' THEN ' PART NO: ' ELSE '' END,ftpart_no) AS ftitem_name FROM tlstock_hdr WHERE fnstatus=1 ORDER BY ftitem_name ", "ftitem_code", "ftitem_name",-1,false);
                $objAxpDB->FormSQL("SELECT '' AS fnwarehouse_type, '' as ftwarehouse, '' as ftlocation, '' as ftitem_code,
                                            CONVERT(null,date) as date_from,
                                            CONVERT(null,date) as date_end
                                    FROM tlreport");
                $objAxpDB->FormCaption("Tipe Gudang, Gudang, Lokasi,Kode Barang, Date From,Date End");
                $objAxpDB->FormPosition("TL, TL,TL,TL,TR,TR");
                break; 
            
            case "acc18":
                $objAxpDB->FormSQL("SELECT '' as currency_code,'' AS ftsi_no,
                                        CONVERT(null,date) as date_from,
                                        CONVERT(null,date) as date_end                                        
                                    FROM tlreport");
                $objAxpDB->FormCaption("Mata Uang, No Invoice, Date From, Date End");
                $objAxpDB->FormPosition("HD,TL,TR,TR");
                break;
        
            case "acc19":
                $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 "acc20":
                $objAxpDB->Lookup("fnwarehouse_type", "SELECT 'SELURUH' as fntrans_status_code,'SELURUH' AS fttrans_status_name UNION ALL  SELECT fntrans_status_code, fttrans_status_name FROM tstransaction_status WHERE fntrans_group_code = 55 and fnactive_status = 1 ", "fntrans_status_code", "fttrans_status_name", -1,true);  
                $objAxpDB->Lookup("ftwarehouse", "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("ftlocation", "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, CONCAT(TRIM(ftitem_name),CASE WHEN TRIM(ftpart_no) != '' THEN ' PART NO: ' ELSE '' END,ftpart_no) AS ftitem_name FROM tlstock_hdr WHERE fnstatus=1 ORDER BY ftitem_name ", "ftitem_code", "ftitem_name",-1,false);
                $objAxpDB->FormSQL("SELECT '' AS fnwarehouse_type, '' as ftwarehouse, '' as ftlocation, '' as ftitem_code,
                                            CONVERT(null,date) as date_from,
                                            CONVERT(null,date) as date_end
                                    FROM tlreport");
                $objAxpDB->FormCaption("Tipe Gudang, Gudang, Lokasi,Kode Barang, Date From,Date End");
                $objAxpDB->FormPosition("TL, TL,HD,TL,TR,TR");
                break; 
            
            case "acc21":

                $fdtrans_date1 = date('d/m/Y');
                $fdtrans_date = date('d/n/Y');
                list($dt, $mn, $yr)=split("/", $fdtrans_date);

                //$tglAkhir=tglAkhirBulan($yr,$mn);

                $objAxpDB->FormSQL("SELECT CONVERT('{$yr}/{$mn}/01',date) as date_from,
                                            CONVERT('{$yr}/{$mn}/{$tglAkhir}',date) as date_end
                                    FROM tlreport");

                $objAxpDB->FormCaption("Date From,Date End");
                $objAxpDB->FormPosition("HD,TL");

                break;

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