<?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="SELECT ftuom_code FROM vBomTypeDetail WHERE ftitem_code='{$_REQUEST['ftitemdetail_code']}' ";
				  $ftuom_code=RetRstField($ssql); 
                  ?> 
					  document.getElementById('ftoumdetail_codeD0<?php echo $_REQUEST['index']; ?>').value='<?php echo $ftuom_code ; ?>';
   				  <?php
				die("");
			break;
              case "uom":
                  $ssql="SELECT UPPER(ftuom_code) as ftuom_code FROM vBomTypeHeader WHERE ftitem_code='{$_REQUEST['ftitem_code']}' ";
                  $uom_code=RetRstField($ssql);
                  ?>
                      document.getElementById('ftuom_code').value='<?php echo ($uom_code); ?>';
                  <?php
                 
                  die("");
              break;
        }
        die("");
    }
	//$objAxpDB->LookupMagicQuotes(True);
    $objAxpDB->ViewName("Daftar BOM");
    $objAxpDB->ViewSQL("SELECT a.fnid, a.ftitem_code, b.ftitem_name, a.ftuom_code,c.ftdepartment_name,
						  CASE WHEN fnstatus=0 THEN 'tidak aktif' 
						  ELSE 'aktif' 
						  END AS STATUS
						FROM tlbom_header a
							INNER JOIN vBomTypeHeader b ON a.ftitem_code=b.ftitem_code
							INNER JOIN tldepartment_ppic c ON a.ftdepartment_code=c.ftdepartment_code
						ORDER BY c.ftdepartment_name");
    $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,ffnetto,ffbruto,fnstatus
                        from tlbom_header");
    $objAxpDB->FormCaption("Type Bom, Kode Barang,Nama Barang, Satuan, Department,Keterangan,Berat Bersih, Berat Kotor, Status");
    $objAxpDB->FormPosition("TL,TL,HD,TL,TR, BL, BR,BR,BR,HD");
    // Deklarasi Detail
    $objAxpDB->GridSQL(0, "SELECT fnindex,ftitem_type, ftitemdetail_code,fnqty,ftoumdetail_code ,ftuomdetail_multi_code FROM tlbom_detail");
    $objAxpDB->GridCaption(0,"No.,Type Barang, Kode Barang, Qty, Satuan, Satuan Multi" );

    $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);
    $objAxpDB->Lookup('ftitem_type', "SELECT 0 AS A,'Barang Bahan Baku' AS B UNION ALL SELECT 1 AS A,'Barang Bahan Proses' AS B", "A", "B", -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('ftuomdetail_multi_code', 'SELECT ftuom_code, ftuom_name FROM vi_uom_code_multi', 'ftuom_code', 'ftuom_name', -1,true);
	$objAxpDB->Lookup("ftdepartment_code", "SELECT ftdepartment_code, ftdepartment_name FROM tldepartment_ppic", "ftdepartment_code", "ftdepartment_name", -1, True);

    $ajaxItem="ajax_do('ppic.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=uom&ftitem_code='+ this.value);";
	$objAxpDB->FormScript(1," onChange=\"{$ajaxItem}\"");
	$x="document.getElementById('ftitem_code').value='';";
    $x.="document.getElementById('hidden_ftitem_code').value='';";
    $x.="document.getElementById('span_ftitem_code').innerHTML='';";
	$x.="document.getElementById('ftuom_code').value='';";
	$objAxpDB->FormScript(0," onChange=\"{$x}\"");
	
	$xD="document.getElementById('ftitemdetail_codeD0_N_').value='';";
    $xD.="document.getElementById('hidden_ftitemdetail_codeD0_N_').value='';";
    $xD.="document.getElementById('span_ftitemdetail_codeD0_N_').innerHTML='';";
	$xD.="document.getElementById('ftoumdetail_codeD0_N_').value='';";
	$objAxpDB->GridScript(0,1," onChange=\"{$xD}\"");
	
    $ajaxItemDetail="ajax_do('ppic.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=item&ftitemdetail_code=' + this.value + '&index=_N_');";
	$objAxpDB->GridScript(0,2," onChange=\"{$ajaxItemDetail}\"");

	$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, 0,0,0,0,0 ");
            $objAxpDB->ButtonShow("reset, simpan, tutup");
            $objAxpDB->GridLocked(0, "1, 0, 0,0, 1");
            $objAxpDB->GridAllowAddNew(0, TRUE);
            $objAxpDB->GridAllowDelete(0, TRUE);
			
			$objAxpDB->Lookup("ftitem_code", "SELECT ftitem_code, ftitem_name,ftuom_code,ftitem_type FROM vBomTypeHeader ", "ftitem_name", "ftitem_code",-1,false,"' AND ftitem_type =\''+ document.getElementById('ftbom_type').value + '\''");
			$objAxpDB->Lookup("ftitemdetail_code", "SELECT ftitem_code, ftitem_name,ftuom_code,ftitem_type FROM vBomTypeDetail ", "ftitem_name", "ftitem_code",-1,false,"' AND ftitem_type =\''+ document.getElementById('ftitem_typeD0_N_').value + '\''");

			/*
			$ajax1="&ftbom_type='+ document.getElementById('ftbom_type').value";
			$ajax1="open('?form=filter_Item&mode=edit&id=0{$ajax1},'mywindow','width=900,height=800,resizable=yes,scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no,screenX=100,screenY=2')";
			$ajax1=" OnClick=\"{$ajax1}\"";
			$objAxpDB->FormLayout(1,"&nbsp;<input type='button' id='cmd_grid_list' name='cmd_grid_list' value='...' {$ajax1}>");
			*/
    } elseif ($objAxpDB->GetStatus("id") != 0) {
	
			$objAxpDB->Lookup("ftitem_code", "SELECT ftitem_code, ftitem_name,ftuom_code,ftitem_type FROM vBomTypeHeader ", "ftitem_code", "ftitem_name",-1,false,"' AND ftitem_type =\''+ document.getElementById('ftbom_type').value + '\''");
			$objAxpDB->Lookup("ftitemdetail_code", "SELECT ftitem_code, ftitem_name,ftuom_code,ftitem_type FROM vBomTypeDetail ", "ftitem_code", "ftitem_name",-1,false,"' AND ftitem_type =\''+ document.getElementById('ftitem_typeD0_N_').value + '\''");
            $objAxpDB->FormLocked("1, 1, 1,1, 1,0,0,0,0 ");
			$objAxpDB->ButtonShow("baru, update, cetak, hapus, tutup");
            $objAxpDB->GridLocked(0, "1, 0,0, 0,1");
			            $objAxpDB->GridAllowAddNew(0, TRUE);
            $objAxpDB->GridAllowDelete(0, TRUE);
    }
			$objAxpDB->Process();
			$objAxpDB->WriteHtmlTable();

?>