<?php
     if($_REQUEST['ajax']) {
        switch($_REQUEST['code']) {

            case "transno":
              if(RetRstField("SELECT fnid FROM tlbom_header WHERE ftitem_code='{$_REQUEST['ftitem_code']}'")) {

				  ?>

                  alert('Kode barang sudah dipakai... ');
            <?php
              }
              else {
                    ?>

                  submitbutton('Simpan','','','','');

            <?php
              }
            break;
              case "item":
                  $ssql=_ITEM;
                  $ssql="SELECT M.ftuom_code FROM ($ssql) M WHERE ftitem_code='{$_REQUEST['ftitem_code']}'";

                  $ftuom_code=RetRstField($ssql);
                    ?>
                      document.getElementById('ftoumdetail_codeD0<?php echo $_REQUEST['index']; ?>').value='<?php echo $ftuom_code ; ?>';
                   <?php

                       die("");
              break;
              case "item1":
                  #$ssql=_ITEM;
                  $ssql="SELECT ftuom_code FROM vbomdetail WHERE ftitem_code='{$_REQUEST['ftitem_code']}'";

                  $ftuom_code=RetRstField($ssql);
                    ?>
                      document.getElementById('ftuom_code<?php echo $_REQUEST['index']; ?>').value='<?php echo $ftuom_code ; ?>';
                   <?php

                       die("");
              break;			  

        }
        die("");
    }
    //$objAxpDB->LookupMagicQuotes(True);
    $objAxpDB->ViewName("Daftar BOM");
    $objAxpDB->ViewSQL("SELECT fnid, ftitem_code,ftitem_name,ftuom_code,
                          case when fnstatus=0 then 'tidak aktif' else 'aktif' end as Status
                                FROM tlbom_header");
    $objAxpDB->ViewCaption("ID, Kode BOM, Nama Bom, Satuan, Status");
    $objAxpDB->FormName("BOM");
    $objAxpDB->FormSQL("select ftbom_type,ftitem_code,ftitem_name,ftuom_code,ftdepartment_code,ftdescription,fnstatus,fttype
                        from tlbom_header");
    $objAxpDB->FormCaption("Type Bom, Kode Barang, Nama Barang, Satuan, Department, Keterangan, Status");
    $objAxpDB->FormPosition("TL,TL, HD, TL,TR, BL, BR, HD");
    // Deklarasi Detail
    $objAxpDB->GridSQL(0, "SELECT fnindex, ftitemdetail_code,fnqty,ftoumdetail_code FROM tlbom_detail");
    $objAxpDB->GridCaption(0,"No., Barang, Qty, Satuan" );

	$objAxpDB->Lookup("ftdepartment_code", "SELECT ftprocess_code, ftprocess_name FROM tlprocess_setengah_jadi", "ftprocess_code", "ftprocess_name", -1, True);
	$objAxpDB->Lookup('fnstatus', 'SELECT fntrans_status_code, fttrans_status_name FROM tstransaction_status where fntrans_status_code<>2 and fntrans_group_code=9', 'fntrans_status_code', 'fttrans_status_name', 1,true);
	$objAxpDB->Lookup('ftitem_code','SELECT ftitem_code , ftitem_name FROM vbomheader', "ftitem_code", "ftitem_name", -1,false); 
	$objAxpDB->Lookup('ftitemdetail_code','SELECT ftitem_code , ftitem_name FROM vbomdetail', "ftitem_code", "ftitem_name", -1,false); 
    $objAxpDB->Lookup('ftbom_type', "SELECT 0 AS A,'Barang Bahan Proses' AS B UNION ALL SELECT 1 AS A,'Barang Bahan Jadi' AS B", "A", "B", -1, true);

    $ajaxuom="ajax_do('query2.php?code=bb1&ftitem_code=' + this.value + '&obj2=ftuom_code');";	

    $ajaxItem="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=\"{$ajaxItem}\"");
    $objAxpDB->SetStatus("id, fnStatus");
	$ajaxUOM_1="ajax_do('query2.php?code=1d&ftitem_code=' + this.value + '&obj1=ftuom_code');"; 
	$objAxpDB->FormScript(0, "onChange=\"{$ajaxuom}\"");	
    if ($objAxpDB->GetStatus("id") == "")
            $objAxpDB->ButtonShow("baru, cetak_daftar, export_excel , tutup");
    elseif ($objAxpDB->GetStatus("id") == 0) {
            $objAxpDB->FormLocked("0,0, 0, 1, 0, 0,1 ");
            $objAxpDB->ButtonShow("reset, simpan, tutup");
            $objAxpDB->GridLocked(0, "1, 0, 0, 1");
            $objAxpDB->GridAllowAddNew(0, TRUE);
            $objAxpDB->GridAllowDelete(0, TRUE);

    } elseif ($objAxpDB->GetStatus("id") != 0) {
			$objAxpDB->FormLocked("1,1, 1, 1, 1, 0,1");
            $objAxpDB->ButtonShow("update, cetak, hapus, tutup");
            $objAxpDB->GridLocked(0, "1, 0,0, 1");
            $objAxpDB->GridAllowAddNew(0, TRUE);
            $objAxpDB->GridAllowDelete(0, TRUE);
    }
			$objAxpDB->Process();
			$objAxpDB->WriteHtmlTable();

?>
