function ValFilterBarang() {
      if(document.getElementById("ftbom_type").value=='') {
           alert('Jenis barang harus diisi...');
           document.getElementById("ftbom_type").focus();
           return false;
      }
      else if(document.getElementById("ftitem_code").value=='') {
            alert('Kode / Nama barang harus disi...');
           document.getElementById("ftitem_code").focus();
           return false;
      }
    return true;
}
function BOMInputQty() {
    var m="";
    var i=document.getElementsByName('fnindexD0[]').length;
    for(var j=1;j<i;j++) {
        if (document.getElementsByName('hidden_ftitemdetail_codeD0[]')[j].value=='') {
              alert('Kode Barang Belum Valid ...');
              document.getElementsByName('ftitemdetail_codeD0[]')[j].focus();
              return false;

        }
        else if (document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1<=0) {
              alert('Qty harus di isi ...');
              document.getElementsByName('fnqtyD0[]')[j].focus();
              return false;

        }
         
        
    }
    return true;
}
function BOMQtyMulti(index) {
    var m="";
    var i=document.getElementsByName('fnindexD0[]').length;
    for(var j=1;j<i;j++) {
	    fnqtyD=document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1;
        fnqty_1D=document.getElementsByName('fnqty_1D0[]')[j].value.replace(/,/g,'')*1;
		fnqty_3D=(fnqtyD/fnqty_1D);
        document.getElementsByName('fnqty_3D0[]')[j].value=fnqty_3D;
    }
    return true;
}
function BOMQtyMulti1(index) {
    var m="";
    var i=document.getElementsByName('fnindexD0[]').length;
    for(var j=1;j<i;j++) {
		var gContainer=window.opener;       
		gContainer.document.getElementById('fnqtyD0'+gContainer.document.getElementById('fnindex_grid0').value).value=document.getElementsByName('fnqty_3D0[]')[j].value;
    }
	window.close();
    return true;
}
function BOMCalculation(index) {
    var m="";
    var i=document.getElementsByName('fnindexD0[]').length;
    for(var j=1;j<i;j++) {
		var gContainer=window.opener;       
	    document.getElementsByName('ftoumdetail_codeD0[]')[j].value='khkh';
    }
    return true;
}

function ValBOM() {
  // document.getElementById("fttype").value='BOM';
  if(document.getElementById("ftbom_type").value=='') {
      alert('Tipe Bom Harus Diisi...');
      document.getElementById("ftbom_type").focus();
      return false;
  }
  else if(document.getElementById("hidden_ftitem_code").value=='') {
      alert('Kode yang anda masukan salah...');
      document.getElementById("ftitem_code").focus();
      return false;
  }
  else if(document.getElementById("ftdepartment_code").value=='') {
      alert('Department harus disi...');
      document.getElementById("ftdepartment_code").focus();
      return false;
  } 
  else if(document.getElementById("ffnetto").value=='') {
      alert('Netto harus disi...');
      document.getElementById("fnnetto").focus();
      return false;
  } 
    else if(document.getElementById("ffbruto").value=='') {
      alert('Bruto harus disi...');
      document.getElementById("fnbruto").focus();
      return false;
  } 
  else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }
  
  else if (BOMInputQty()==false) {
       return false;
  }
    ajax_do(str_url + '&ajax=1&code=transno&ftitem_code=' + document.getElementById('ftitem_code').value);
  return false;
}

function SPPInputQty() {
    var m="";

    
    var i=document.getElementsByName('fnindexD0[]').length;
    for(var j=1;j<i;j++) {
        if (document.getElementsByName('hidden_ftitem_codeD0[]')[j].value=='') {
              alert('Kode Barang Belum Valid ...');
              document.getElementsByName('hidden_ftitem_codeD0[]')[j].focus();
              return false;

        }
        else if (document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1<=0) {
              alert('Qty harus di isi ...');
              document.getElementsByName('fnqtyD0[]')[j].focus();
              return false;

        }

    }
    return true;
}

function ValSPP() {
 
  if(document.getElementById("ftspp_no").value=='') {
      alert('No. SPP Harus Diisi...');
      document.getElementById("ftspp_no").focus();
      return false;
  }
  else if(document.getElementById("ftdepartment_code").value=='') {
       alert('Departement Harus Diisi...');
      document.getElementById("ftdepartment_code").focus();
      return false;
  }
   else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }
  
   else if (SPPInputQty()==false) {
	  return false;
  }
    ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftspp_no').value);

      return false;
}

// SPK Proses
function ValSPKProses0() {

  if(document.getElementById("ftspk_no").value=='') {
      alert('No. SPK Harus Diisi...');
      document.getElementById("ftspk_no").focus();
      return false;
  }
  else if(document.getElementById("ftpor_no").value=='') {
       alert('No. POR Harus Diisi...');
      document.getElementById("ftpor_no").focus();
      return false;
  }
  else if(document.getElementById("ftestimation_no").value=='') {
       alert('N0. Estimasi Harus Diisi...');
      document.getElementById("ftestimation_no").focus();
      return false;
  }  
   else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }
  
  else if (SPKProsesInputQty0()==false) {
	  return false;
  }

  ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftspk_no').value);

  return false;
}
function SPKProsesInputQty0() {
    var m="";
    
    var i=document.getElementsByName('fnindexD0[]').length;
    for(var j=1;j<i;j++) {
        if (document.getElementsByName('ftitemdetail_codeD0[]')[j].value=='') {
              alert('Kode Barang Belum Valid ...');
              document.getElementsByName('ftitemdetail_codeD0[]')[j].focus();
              return false;
        }
        else if (document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1<=0) {
              alert('Qty harus di isi ...');
              document.getElementsByName('fnqtyD0[]')[j].focus();
              return false;

        }

    }
    return true;
}

function ValSPKCovering() {
 
  if(ValSPKProses0()==false) {
      return false;
  }
  else if (SPKProsesInputQty0()==false) {
	  return false;
  }

  ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftspk_no').value);

  return false;
}

function ValSPKWarping() {

  if(ValSPKProses0()==false) {
      return false;
  }
  else if (SPKProsesInputQty0()==false) {
	  return false;
  }

  ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftspk_no').value);

  return false;
}

function ValSPKWeaving() {

  if(ValSPKProses0()==false) {
      return false;
  }
  else if (SPKProsesInputQty0()==false) {
	  return false;
  }

  ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftspk_no').value);

  return false;
}

function ValSPKFinishing() {

  if(ValSPKProses0()==false) {
      return false;
  }
  else if (SPKProsesInputQty0()==false) {
	  return false;
  }

  ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftspk_no').value);

  return false;
}

function ValSPKPacking() {

  if(ValSPKProses0()==false) {
      return false;
  }
  else if (SPKProsesInputQty0()==false) {
	  return false;
  }

  ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftspk_no').value);

  return false;
}

function ValSPKSparepart() {

  if(ValSPKProses0()==false) {
      return false;
  }
  else if (SPKProsesInputQty0()==false) {
	  return false;
  }

  ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftspk_no').value);

  return false;
}

// Estimasi

function EstimasiInputQty0() {
    var m="";
    var i=document.getElementsByName('fnindexD0[]').length;
    for(var j=1;j<i;j++) {
        if ((document.getElementsByName('hidden_ftitem_codeD0[]')[j].value=='')&&(document.getElementsByName('chk_includeD0[]')[j].checked == true)) {
              alert('Kode Barang Belum Valid ...');
              document.getElementsByName('hidden_ftitem_codeD0[]')[j].focus();
              return false;
        }
    }
    return true;
}

function EstimasiInputQty() {
    var m="";
    var i=document.getElementsByName('fnindexD1[]').length;
    for(var j=1;j<i;j++) {
        if (document.getElementsByName('hidden_ftitem_codeD1[]')[j].value=='') {
              alert('Kode Barang Belum Valid ...');
              document.getElementsByName('hidden_ftitem_codeD1[]')[j].focus();
              return false;
        }
        else if (document.getElementsByName('fnformulaD1[]')[j].value.replace(/,/g,'')*1<=0) {
              alert('Formula harus di isi ...');
              document.getElementsByName('fnformulaD1[]')[j].focus();
              return false;

        }
    }
    return true;
}
function ValSPKSewing() {
 
  if(document.getElementById("ftspk_no").value=='') {
      alert('No. SPK Harus Diisi...');
      document.getElementById("ftspk_no").focus();
      return false;
  }
  else if(document.getElementById("ftdepartment_code").value=='') {
       alert('Departement Harus Diisi...');
      document.getElementById("ftdepartment_code").focus();
      return false;
  }  
  else if(document.getElementById("ftpos_no").value=='') {
       alert('No. POS Harus Diisi...');
      document.getElementById("ftpos_no").focus();
      return false;
  }
  else if(document.getElementById("ftestimation_no").value=='') {
       alert('N0. Estimasi Harus Diisi...');
      document.getElementById("ftestimation_no").focus();
      return false;
  }  
   else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }
  
   else if (SPKSewingInputQty()==false) {
	  return false;
  }
    ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftspk_no').value);

      return false;
}
function SPKSewingInputQty() {
    var m="";

    
    var i=document.getElementsByName('fnindexD0[]').length;
    for(var j=1;j<i;j++) {
        if (document.getElementsByName('hidden_ftitemdetail_codeD0[]')[j].value=='') {
              alert('Kode Barang Belum Valid ...');
              document.getElementsByName('hidden_ftitemdetail_codeD0[]')[j].focus();
              return false;

        }
        else if (document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1<=0) {
              alert('Qty harus di isi ...');
              document.getElementsByName('fnqtyD0[]')[j].focus();
              return false;

        }

    }
    return true;
}
function ValSPKInjection() {
 
  if(document.getElementById("ftspk_no").value=='') {
      alert('No. SPK Harus Diisi...');
      document.getElementById("ftspk_no").focus();
      return false;
  }
  else if(document.getElementById("ftdepartment_code").value=='') {
       alert('Departement Harus Diisi...');
      document.getElementById("ftdepartment_code").focus();
      return false;
  }  
  else if(document.getElementById("ftpos_no").value=='') {
       alert('No. POS Harus Diisi...');
      document.getElementById("ftpos_no").focus();
      return false;
  }
  else if(document.getElementById("ftestimation_no").value=='') {
       alert('N0. Estimasi Harus Diisi...');
      document.getElementById("ftestimation_no").focus();
      return false;
  }  
   else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }
  
   else if (SPKInjectionInputQty()==false) {
	  return false;
  }
    ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftspk_no').value);

      return false;
}
function SPKInjectionInputQty() {
    var m="";

    
    var i=document.getElementsByName('fnindexD0[]').length;
    for(var j=1;j<i;j++) {
        if (document.getElementsByName('hidden_ftitemdetail_codeD0[]')[j].value=='') {
              alert('Kode Barang Belum Valid ...');
              document.getElementsByName('hidden_ftitemdetail_codeD0[]')[j].focus();
              return false;

        }
        else if (document.getElementsByName('hidden_ftmachine_codeD0[]')[j].value=='') {
              alert('Kode Mesin Belum Valid ...');
              document.getElementsByName('ftmachine_codeD0[]')[j].focus();
              return false;

        }		
        else if (document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1<=0) {
              alert('Qty harus di isi ...');
              document.getElementsByName('fnqtyD0[]')[j].focus();
              return false;

        }

    }
    return true;
}

function ValRekapSPK() {
  if(document.getElementById("ftrekap_spk_no").value=='') {
      alert('No. Transaksi harus disi...');
      document.getElementById("ftrekap_spk_no").focus();
      return false;
  }
  else  if(document.getElementById("ftdepartment_code").value=='') {
      alert('Department belum valid ...');
      document.getElementById("ftdepartment_code").focus();
      return false;
  }
  else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }
  else if (RekapSPKInputQty()==false) {
       return false;
  }

    ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftrekap_spk_no').value);

  return false;
}

// Detail Rekap Delivery Order
function RekapSPKInputQty() {
    var i=document.getElementsByName('fnindexD0[]').length;

	for(var j=1;j<i;j++) {
    if (document.getElementsByName('ftspk_noD0[]')[j].value=='') {
		 alert('No. SPK belum valid..');
		document.getElementsByName('ftspk_noD0[]')[j].focus();
		 return false;
    }
    else if (document.getElementsByName('ftpos_noD0[]')[j].value=='') {
		 alert('No. POS belum valid..');
		document.getElementsByName('ftpos_noD0[]')[j].focus();
		 return false;
    }
	else if (document.getElementsByName('ftestimation_noD0[]')[j].value=='') {
		alert('No. Estimasi belum valid..');
		document.getElementsByName('ftestimation_noD0[]')[j].focus();
		return false;
    }
}
    return true;
}

function EstimasiInputQty() {
    var m=""; 
    var i=document.getElementsByName('fnindexD1[]').length;
    for(var j=1;j<i;j++) {
        if (document.getElementsByName('hidden_ftitem_codeD1[]')[j].value=='') {
              alert('Kode Barang Belum Valid ...');
              document.getElementsByName('hidden_ftitem_codeD1[]')[j].focus();
              return false; 
        }
        else if (document.getElementsByName('fnformulaD1[]')[j].value.replace(/,/g,'')*1<=0) {
              alert('Formula harus di isi ...');
              document.getElementsByName('fnformulaD1[]')[j].focus();
              return false;

        } 
    }
    return true;
}

function EstimasiRecalInputQty() {
     var i=document.getElementsByName('fnindexD1[]').length;
    for(var j=1;j<i;j++) {
       document.getElementsByName('fnqtyD1[]')[j].value=(document.getElementsByName('fnformulaD1[]')[j].value.replace(/,/g,'')*1)*(document.getElementById('fnqty_hdrD1'+j).value.replace(/,/g,'')*1);
       document.getElementById('fnqty_outstandingD1'+j).value=(document.getElementById('fnqty_availD1'+j).value.replace(/,/g,'')*1)-(document.getElementById('fnqtyD1'+j).value.replace(/,/g,'')*1);

    }    
    return true;
}

function EstimasiRecalInputQtyIndex(index) {   
   document.getElementById('fnqtyD1'+index).value=(document.getElementById('fnformulaD1'+index).value.replace(/,/g,'')*1)*(document.getElementById('fnqty_hdrD1'+j).value.replace(/,/g,'')*1);
   document.getElementById('fnqty_outstandingD1'+index).value=(document.getElementById('fnqty_availD1'+index).value.replace(/,/g,'')*1)-(document.getElementById('fnqtyD1'+index).value.replace(/,/g,'')*1);
   return true;
} 

function ValEstimasi() {

  if(document.getElementById("ftestimation_no").value=='') {
      alert('No. Estimasi Harus Diisi...');
      document.getElementById("ftestimation_no").focus();
      return false;
  }
  
   else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail 1 transaksi belum di input ...');
      return false;
  }
  
 else if(document.getElementsByName('fnindexD1[]').length==1) {
      alert('Detail 2 transaksi belum di input ...');
      return false;
  }

   else if (EstimasiInputQty0()==false) {
       return false;
  }
 else if (EstimasiInputQty()==false) {
       return false;
  }
    ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftestimation_no').value);


  return false;
}

function Generate_Estimasi() {
	 var i=document.getElementsByName('fnindexD0[]').length;
	 var str='';
    for(var j=1;j<i;j++) { 
		 if(document.getElementsByName('chk_includeD0[]')[j].checked == true) {
			if(str=='') {
				str=document.getElementsByName('ftitem_codeD0[]')[j].value
			}
			else {
				str=str+'|'+document.getElementsByName('ftitem_codeD0[]')[j].value
			}
		 }		
    }  
	
	//alert(str);
	 ajax_do_grid1('ppic.php?form=estimasi&mode=edit&id=0&ajax=1&code=grid1&ftitem_codex='+ str +'&ftpos_no='+ document.getElementById('ftpos_no').value);
   
	return true;
}
function SetIncludeEstimasi(index) {
	if(document.getElementById('chk_includeD0'+index).checked == true)  {
		document.getElementById('hd_includeD0'+index).value='1';
     } else {
		document.getElementById('hd_includeD0'+index).value='0';
     } 
 
}


 

