<?php
    Getsecurity('reject_produksi');

    if($_REQUEST['ajax']) {
        switch($_REQUEST['code']) {
            case "transno":
                if(RetRstField("SELECT fnid FROM txreject_production_hdr WHERE ftreject_production_department_no='{$_REQUEST['fttrans_no']}'"))
                {
                    ?>
                        alert('No. Reject Produksi sudah dipakai... ');
                    <?php
                }
                else
                {
                    ?>
                        submitbutton('Simpan','','','','');
                    <?php
                }
                die("");
                break;
            case "item":
                $ssql="SELECT ftuom_code FROM txproduction_det WHERE ftitem_code='{$_REQUEST['ftitem_code']}'";
                $ftuom_code=RetRstField($ssql);
                ?>
                    document.getElementById('ftuom_codeD0<?php echo $_REQUEST['index']; ?>').value='<?php echo $ftuom_code ; ?>';
                <?php
                $ssql="select fnqty as fnqty_production from txproduction_det
                         where ftproduction_no='{$_REQUEST['ftproduction_no']}'
                            and ftitem_code='{$_REQUEST['ftitem_code']}'";
                $fnqty_avail=RetRstField($ssql);
                if(($fnqty_avail==""))
                {
                    $fnqty_avail="0";
                }
                ?>
                    document.getElementById('fnqty_productionD0<?php echo $_REQUEST['index']; ?>').value='<?php echo $fnqty_avail; ?>';
                <?php
                die("");
                break;
        }
    }

    $objAxpDB->ViewName("Daftar Reject Produksi");
    $objAxpDB->ViewSQL("SELECT a.fnid, a.ftreject_production_department_no,a.fdtrans_date,
                                a.ftdepartment_code, c.fttrans_status_name AS ftstatus ,a.ftnotes
                                FROM txreject_production_hdr a
                                LEFT JOIN tstransaction_status c ON a.fnstatus = c.fntrans_status_code AND c.fntrans_group_code = 2");
    $objAxpDB->ViewCaption("ID, No. Reject Produksi, Tgl. Transaksi, Kode Departement, Status");
    $objAxpDB->ViewPeriod(TRUE);

    $objAxpDB->FormName("Reject Produksi");
    $objAxpDB->FormSQL("SELECT  ftreject_production_department_no, ftdepartment_code, ftspk_produksi_no, ftreject_code, ftreject_type_code, fdtrans_date, ftnotes, fnstatus
                        FROM txreject_production_hdr");
    $objAxpDB->FormCaption("No. Reject Produksi, Departement,No. Spk, Kode Reject, Tipe Reject, Tgl. Reject Produksi, Catatan, Status");
    $objAxpDB->FormPosition(" TL, TL, TL, HD, HD,TR, BL, BR");

    // Deklarasi Detail
    $objAxpDB->GridSQL(0, "SELECT fnindex, ftproduction_no,ftitem_code, fnqty_production, fnqty, ftuom_code, ftdescription FROM txreject_production_det");
    $objAxpDB->GridCaption(0,"No., No. Produksi, Barang, Qty Produksi, Qty Reject, Satuan, Keterangan " );

    $objAxpDB->Lookup('fnstatus', 'SELECT fntrans_status_code, fttrans_status_name FROM tstransaction_status where  fntrans_group_code=2', 'fntrans_status_code', 'fttrans_status_name', 1,true);
    $objAxpDB->Lookup("ftspk_produksi_no", "SELECT ftspk_no, fdtrans_date, ftdepartment_code FROM txspk_hdr WHERE fnstatus =1 ORDER BY fdtrans_date ", "ftspk_no", "fdtrans_date", -1,FALSE,"' AND ftdepartment_code=\''+ document.getElementById('ftdepartment_code').value + '\''");
    $objAxpDB->Lookup("ftdepartment_code", "SELECT ftdepartment_code, ftdepartment_name FROM tldepartment_ppic", "ftdepartment_code", "ftdepartment_name", -1,true);
    $objAxpDB->Lookup("ftreject_code", "select ftreject_code, ftreject_name, ftdivision_code from tlreject_type ", "ftreject_code", "ftreject_name", -1, false, "' AND ftdivision_code=\''+ document.getElementById('ftdepartment_code').value + '\''");

    $ajaxGrid1="ajax_do_grid0('produksi.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=grid&ftdepartment_code='+ document.getElementById('ftdepartment_code').value);";

    $Clear="document.getElementById('ftspk_produksi_no').value='';";
    $Clear.="document.getElementById('hidden_ftspk_produksi_no').value='';";
    $Clear.="document.getElementById('span_ftspk_produksi_no').innerHTML='';";
    $Clear.="document.getElementById('ftreject_code').value='';";
    $Clear.="document.getElementById('hidden_ftreject_code').value='';";
    $Clear.="document.getElementById('span_ftreject_code').innerHTML='';";
    $Clear.="document.getElementById('ftreject_type_code').value='';";
    $Clear.="$ajaxGrid1";

    $objAxpDB->FormScript(1, "onChange=\"{$Clear}\"");
    $objAxpDB->FormScript(2, "onChange=\"{$ajaxGrid1}\"");
    
    $ajaxType_Reject="ajax_do('query2.php?code=reject_type&ftreject_code=' + this.value + '&objAddress=ftreject_type_code');";
    $objAxpDB->FormScript(3,"onChange=\"{$ajaxType_Reject}\"");

    $Clear1="document.getElementById('ftitem_codeD0_N_').value='';";
    $Clear1.="document.getElementById('hidden_ftitem_codeD0_N_').value='';";
    $Clear1.="document.getElementById('span_ftitem_codeD0_N_').innerHTML='';";
    $Clear1.="document.getElementById('fnqty_productionD0_N_').value='0';";
    $Clear1.="document.getElementById('fnqtyD0_N_').value='0';";
    $Clear1.="document.getElementById('ftuom_codeD0_N_').value='';";
    $objAxpDB->GridScript(0,1 , "onChange=\"{$Clear1}\"");

    $ajaxfnqty_avail="OnChange=\"ajax_do('produksi.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=item&index=_N_&ftproduction_no='+  document.getElementById('ftproduction_noD0_N_').value +'&ftitem_code='+  document.getElementById('ftitem_codeD0_N_').value +'');\"";
    $objAxpDB->GridScript(0,2,"{$ajaxfnqty_avail}");

    $objAxpDB->SetStatus("id, fnstatus");
       if(!$_REQUEST['id']) {
            $strAutoNumber1="  ajax_do('query2.php?code=2&ftmodule_code=produksi06&thbln=' + document.getElementById(\"fdtrans_date\").value + '&field_name=ftreject_production_department_no&no_trans=ftreject_production_department_no&table_name=txreject_production_hdr&ftbranch_code={$_SESSION['strbranch']}');
                             ";
            $strAutoNumber0=" function OnChangeDate_fdtrans_date() {
                                           {$strAutoNumber1}
                                     }
                                     OnChangeDate_fdtrans_date();
                                ";

            $objAxpDB->FormJS($strAutoNumber0);
     }

    if ($objAxpDB->GetStatus("id") == "")
            $objAxpDB->ButtonShow("baru, cetak_daftar, export_excel , tutup");
    elseif ($objAxpDB->GetStatus("id") == 0) {
            $objAxpDB->FormLocked("0, 0, 0,0, 1, 0, 0, 1");

            $objAxpDB->ButtonShow("reset, simpan, tutup");
            $objAxpDB->GridLocked(0, "1,0, 0, 1, 0, 1, 0, 0, 0");
            $objAxpDB->GridAllowAddNew(0, TRUE);
            $objAxpDB->GridAllowDelete(0, TRUE);
            //$objAxpDB->Lookup("ftitem_code", "SELECT a.ftitem_code, b.ftitem_name, a.ftproduction_no FROM txproduction_det a INNER JOIN vBomDetail b ON a.ftitem_code = b.ftitem_code ORDER BY a.ftitem_code ", "ftitem_code", "ftitem_name", -1, False,"' AND ftproduction_no=\''+ document.getElementById('ftproduction_noD0_N_').value + '\''");
            $objAxpDB->Lookup("ftitem_code", "SELECT a.ftitem_code, a.ftitem_name, a.ftproduction_no FROM txproduction_det a where 0=0 ", "ftitem_code", "ftitem_name", -1, False,"' AND ftproduction_no=\''+ document.getElementById('ftproduction_noD0_N_').value + '\''");
            $objAxpDB->Lookup("ftproduction_no", "SELECT a.ftproduction_no,b.fdtrans_date FROM txproduction_det a INNER JOIN txproduction_hdr b ON a.ftproduction_no = b.ftproduction_no and b.fnstatus = 1 ", "ftproduction_no", "fdtrans_date", -1,FALSE,"' AND ftspk_no=\''+ document.getElementById('ftspk_produksi_no').value + '\' AND ftdepartment_code=\''+ document.getElementById('ftdepartment_code').value + '\''");
    } elseif ($objAxpDB->GetStatus("fnstatus") == 1) {
            $objAxpDB->FormLocked("1, 1, 1, 1,1, 1, 1, 1");
            $objAxpDB->ButtonShow("cetak, batal, tutup");
            $objAxpDB->GridLocked(0, "1,1, 1, 1, 1, 1, 1, 1");
            $objAxpDB->Lookup("ftitem_code", "SELECT ftitem_code, ftitem_name FROM vBomDetail", "ftitem_code", "ftitem_name", -1,false);
            $objAxpDB->Lookup("ftproduction_no", "SELECT a.ftproduction_no,a.fdtrans_date FROM txproduction_hdr a ", "ftproduction_no", "fdtrans_date", -1,FALSE);
    } elseif ($objAxpDB->GetStatus("fnstatus") == 9) {
            $objAxpDB->FormLocked("1, 1, 1, 1,1, 1, 1, 1");
            $objAxpDB->ButtonShow("tutup");
            $objAxpDB->GridLocked(0, "1,1, 1, 1, 1, 1, 1, 1");
            $objAxpDB->Lookup("ftitem_code", "SELECT ftitem_code, ftitem_name FROM vBomDetail", "ftitem_code", "ftitem_name", -1,false);
            $objAxpDB->Lookup("ftproduction_no", "SELECT a.ftproduction_no,a.fdtrans_date FROM txproduction_hdr a ", "ftproduction_no", "fdtrans_date", -1,FALSE);
    } elseif ($objAxpDB->GetStatus("id") == 1) {
            $objAxpDB->FormLocked("1, 1, 1, 1,1, 1, 1, 1");
            $objAxpDB->ButtonShow("cetak, batal, tutup");
            $objAxpDB->GridLocked(0, "1,1, 1, 1,1, 1, 1, 1, 1");
            $objAxpDB->Lookup("ftitem_code", "SELECT ftitem_code, ftitem_name FROM vBomDetail", "ftitem_code", "ftitem_name", -1,false);
            $objAxpDB->Lookup("ftproduction_no", "SELECT a.ftproduction_no,a.fdtrans_date FROM txproduction_hdr a ", "ftproduction_no", "fdtrans_date", -1,FALSE);
   }
   if($_REQUEST['ajax']) {
           switch($_REQUEST['code']) {
           case "grid":
               ob_start();
                $_REQUEST['id']=0;
                $objAxpDB->GridSQL(0, "SELECT fnindex, ftproduction_no,ftitem_code, fnqty_production, fnqty, ftuom_code, ftdescription FROM txreject_production_det");

                $objAxpDB->Process();
                $objAxpDB->setGrid2(0);
                $html = ob_get_contents();
                ob_end_clean();
                ?>

                    div = document.getElementById('txtHint0');
                    var m='<?php echo js_esc($html); ?>';
                    m= m.replace(/^\s*|\s*$/g,"");
                    div.innerHTML =m;
                    RowBuild0();

                 <?php
                break;
           }
           die("");
           exit;
    }
    $objAxpDB->Process();
    $objAxpDB->WriteHtmlTable();
?>
