<?php
     if($_REQUEST['ajax']) {
        switch($_REQUEST['code']) {
            case "transno":
              if(RetRstField("SELECT fnid FROM txspp_hdr WHERE ftspp_no='{$_REQUEST['fttrans_no']}'"))
              {
                  ?>
                     alert('No. SPP sudah dipakai... ');
                  <?php
              }
              else
              {
                  ?>
                     submitbutton('Simpan','','','','');
                  <?php
              }
              break;
              die("");
            case "item":
              $ssql=_ITEM;
              $ssql="SELECT M.ftuom_code FROM ($ssql) M WHERE ftitem_code='{$_REQUEST['ftitem_code']}'";

              $ftuom_code=RetRstField($ssql);
                  ?>
                     document.getElementById('ftuom_codeD0<?php echo $_REQUEST['index']; ?>').value='<?php echo $ftuom_code ; ?>';
                  <?php
              die("");
              break;
//            case "oum":
//              if($_REQUEST['fnitem_type']==1)
//                {
//                        $ssql="SELECT UCASE(ftuom_code) AS ftuom_code FROM tlstock_hdr_setengah_jadi WHERE ftitem_code='{$_REQUEST['ftitem_code']}'";
//                        $ftuom_code=RetRstField($ssql);
//                        #die($ftuom_code);
//                          ?>
//                              document.getElementById('ftuom_codeD0<?php echo $_REQUEST['index'];?>').value='<?php echo $ftuom_code; ?>';
//                         <?
//                }
//              else
//                {
//                        $ssql="SELECT UCASE(ftuom_code) AS ftuom_code FROM tlstock_hdr_bahan_baku WHERE ftitem_code='{$_REQUEST['ftitem_code']}'";
//                        $ftuom_code=RetRstField($ssql);
//                        # die($ftuom_code);
//                          ?>
//                              document.getElementById('ftuom_codeD0<?php echo $_REQUEST['index'];?>').value='<?php echo $ftuom_code; ?>';
//                         <?
//                }
//              die("");
//              break;
        }
    }

    $objAxpDB->ViewName("Daftar SPP");
    $objAxpDB->ViewSQL("SELECT a.fnid, a.ftspp_no,a.fdtrans_date,a.ftdepartment_code,
                                a.ftnotes, c.fttrans_status_name AS ftstatus
                                FROM txspp_hdr a
                                LEFT JOIN tstransaction_status c ON a.fnstatus = c.fntrans_status_code AND c.fntrans_group_code = 2");
    $objAxpDB->ViewCaption("ID, No. SPP, Tgl. Transaksi, Kode Departement, Keterangan, Status");
    $objAxpDB->ViewPeriod(TRUE);
       if(!$_REQUEST['id']) {
            $strAutoNumber1="  ajax_do('query2.php?code=2&ftmodule_code=ppic_01&thbln=' + document.getElementById(\"fdtrans_date\").value + '&field_name=ftspp_no&no_trans=ftspp_no&table_name=txspp_hdr');

                             ";

            $strAutoNumber0=" function OnChangeDate_fdtrans_date() {
                                           {$strAutoNumber1}

                                     }
                                     OnChangeDate_fdtrans_date();
                                ";

            $objAxpDB->FormJS($strAutoNumber0);
     }
    $objAxpDB->FormName("SPP");
    $objAxpDB->FormSQL("select  ftspp_no, ftdepartment_code, fdtrans_date,ftnotes,fnstatus from txspp_hdr");
    $objAxpDB->FormCaption("No. SPP, Departement, Tgl. SPP,Catatan, Status");

    $objAxpDB->FormPosition("TL, TL, TR, BL, BR");

     // Deklarasi Detail
    $ajaxGrid="ajax_do_grid0('ppic.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=grid&fnitem_type='+ document.getElementById('fnitem_type').value);";
    $objAxpDB->FormScript(1, "onChange=\"{$ajaxGrid}\"");

    $objAxpDB->GridSQL(0, "SELECT fnindex, ftitem_code,fnqty,ftuom_code, ftdescription FROM txspp_det");
    $objAxpDB->GridCaption(0,"No., Barang, Qty, Satuan, Keterangan" );

    //Isi Oum Code Detail
    $ajaxOUM_Code="ajax_do('ppic.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=item&ftitem_code=' + this.value + '&index=_N_');";
    $objAxpDB->GridScript(0,1," onChange=\"{$ajaxOUM_Code}\"");

    $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("ftdepartment_code", "SELECT ftprocess_code, ftprocess_name FROM tlprocess_setengah_jadi", "ftprocess_code", "ftprocess_name", -1, True);
    $objAxpDB->Lookup("fnitem_type", "SELECT fntrans_status_code, fttrans_status_name FROM tstransaction_status WHERE fntrans_status_code<>0 AND fntrans_group_code = 39", "fntrans_status_code", "fttrans_status_name", 0,true);
    $objAxpDB->Lookup("ftitem_code", "SELECT ftitem_code, ftitem_name FROM tlstock_hdr_setengah_jadi", "ftitem_code", "ftitem_name", -1,false);

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

            $objAxpDB->ButtonShow("reset, simpan, tutup");
            $objAxpDB->GridLocked(0, "1, 0, 0, 1,0");
            $objAxpDB->GridAllowAddNew(0, true);
            $objAxpDB->GridAllowDelete(0, true);

    } elseif ($objAxpDB->GetStatus("fnstatus") == 1) {
            $objAxpDB->FormLocked("1,1,1,1,1");
            $objAxpDB->ButtonShow("cetak, batal, tutup");
            $objAxpDB->GridLocked(0, "1,1,1,1,1");

    } elseif ($objAxpDB->GetStatus("fnstatus") == 9) {
            $objAxpDB->FormLocked("1,1,1,1,1");
            $objAxpDB->ButtonShow("tutup");
            $objAxpDB->GridLocked(0, "1,1,1,1,1");

    } elseif ($objAxpDB->GetStatus("id") == 1) {
            $objAxpDB->FormLocked("1,1,1,1,1");
            $objAxpDB->ButtonShow("cetak, batal, tutup");
            $objAxpDB->GridLocked(0, "1,1,1,1,1,1");	
	}

if($_REQUEST['ajax'])
{
           switch($_REQUEST['code'])
           {
           case "grid":
               ob_start();
                         if($_REQUEST['fnitem_type']=="1")
                         {
                                $objAxpDB->Lookup("ftitem_code", "SELECT ftitem_code, ftitem_name FROM tlstock_hdr_setengah_jadi $m", "ftitem_code", "ftitem_name", -1,false);
                         }
                         else
                         {
                                $objAxpDB->Lookup("ftitem_code", "SELECT ftitem_code, ftitem_name FROM tlstock_hdr_bahan_baku  $m", "ftitem_code", "ftitem_name", -1,false);
                         }
               $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();
                    RowIndex0();
               <?
               break;

           }
           die("");
           exit;
    }

    if(isset($_REQUEST['id'])&&($_REQUEST['id'])!=0)
    {
            $ssql="SELECT fnitem_type
                         FROM txdelivery_order_hdr_internal
                            WHERE fnid='{$_REQUEST['id']}'";

           $fnitem_type=RetRstField($ssql);
           if($fnitem_type=="1")
           {
                $objAxpDB->Lookup("ftitem_code", "SELECT ftitem_code, ftitem_name FROM tlstock_hdr_setengah_jadi $m", "ftitem_code", "ftitem_name", -1,false);
           }
           else
           {
                $objAxpDB->Lookup("ftitem_code", "SELECT ftitem_code, ftitem_name FROM tlstock_hdr_bahan_baku  $m", "ftitem_code", "ftitem_name", -1,false);
           }
    }

    $objAxpDB->Process();
    $objAxpDB->WriteHtmlTable();


?>
