function ValTipeOutsource() {
  
  if(document.getElementById("ftoutsource_type_code").value=='') {
      alert('Kode Outsource Harus Diisi...');
      document.getElementById("ftoutsource_type_code").focus();
      return false;
  }
  else if(document.getElementById("ftoutsource_type_name").value=='') {
       alert('Outsource Harus Diisi...');
      document.getElementById("ftoutsource_type_name").focus();
      return false;
  }
//  alert(str_url);
    ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftoutsource_type_code').value);

  return false;
}

function ValTipeReject() {

  if(document.getElementById("ftreject_type_code").value=='') {
       alert('Kode Tipe Reject Harus Diisi...');
      document.getElementById("ftreject_type_code").focus();
      return false;
  } 
  else if(document.getElementById("ftreject_type_name").value=='') {
       alert('Tipe Reject Harus Diisi...');
      document.getElementById("ftreject_type_name").focus();
      return false;
  } 
   else if(document.getElementById("ftdivision_code").value=='') {
       alert('Divisi Harus Diisi...');
      document.getElementById("ftdivision_code").focus();
      return false;
  }
//  alert(str_url);
    ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftreject_type_code').value);
        //+'&fttrans_no2=' + document.getElementById('ftdivision_code').value);

      return false;
  }
function ValOutsource() {
  
  if(document.getElementById("ftsupplier_code").value=='') {
      alert('Kode Outsource Harus Diisi...');
      document.getElementById("ftsupplier_code").focus();
      return false;
  }
  else if(document.getElementById("ftsupplier_name").value=='') {
       alert('Nama Outsource Harus Diisi...');
      document.getElementById("ftsupplier_name").focus();
      return false;
  }
  else if(document.getElementById("ftcontact_supplier_name").value=='') {
       alert('Nama Kontak DMI Ke Outsource Harus Diisi...');
      document.getElementById("ftcontact_supplier_name").focus();
      return false;
  }  
  else if(document.getElementById("ftsupplier_type").value=='') {
       alert('Tipe Outsource Harus Diisi...');
      document.getElementById("ftsupplier_type").focus();
      return false;
  }  
//  alert(str_url);
    ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftsupplier_code').value);

  return false;
}
function UpdateNamaKaryawanOperator() {
 
//  alert(str_url);
    ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftoperator_code').value+'&fttrans_no2=' + document.getElementById('ftemployee_code').value);

  return false;
}

function DeliveryOrderRecalQtyOutSource() {

    var i=document.getElementsByName('fnindexD0[]').length;
    var ffqty=0;
    var ffTotal=0;
    for(var j=1;j<i;j++) {


         ffqty=document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'');
        ffTotal=ffTotal+(ffqty*1);
    }
    document.getElementById('fftotal_qty').value=ffTotal;

}
function DeliveryOrderInputQtyOutSource() {
    var i=document.getElementsByName('fnindexD0[]').length;
    var ffqty1=0;
    var ffqty2=0;
    var m=0;
    ffqty1=ffqty1*1;
    ffqty2=ffqty2*1;
    for(var j=1;j<i;j++) {
        ffqty1=document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1;
        ffqty2=document.getElementsByName('fnqty_availableD0[]')[j].value.replace(/,/g,'')*1

         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('ftwarehouse_codeD0[]')[j].value.replace(/,/g,'')*1<=0) {
               alert('Gudang harus diisi..');
                document.getElementsByName('ftwarehouse_codeD0[]')[j].focus();
               return false;
          }
           else if (document.getElementsByName('ftlocation_codeD0[]')[j].value.replace(/,/g,'')*1<=0) {
               alert('Lokasi harus diisi..');
                document.getElementsByName('ftlocation_codeD0[]')[j].focus();
               return false;
          }
          else if (document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1<=0) {
               alert('Qty DO harus diisi..');
               document.getElementsByName('fnqtyD0[]')[j].focus();
               return false;
          }
          else if(ffqty1>ffqty2 ) {

             m=1;
          }
    }
      if(m==1) {
           if(!confirm('Qty Barang ada yang lebih besar dari Qty Avail..\n Apakah transaksi akan dilanjutkan ...?')) {
                return false;
          }
    }

    return true;
}
//validasi surat jalan outsource 
function SuratJalanOutsourceInputQty() {
    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('ftwarehouse_codeD0[]')[j].value=='') {
              alert('Kode gudang harus di isi ...');
              document.getElementsByName('ftwarehouse_codeD0[]')[j].focus();
              return false;
        }
        else if (document.getElementsByName('ftlocation_codeD0[]')[j].value=='') {
              alert('Kode lokasi harus di isi ...');
              document.getElementsByName('ftlocation_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 ValSuratJalanOutsource() {

  if(document.getElementById("ftdo_no").value=='') {
      alert('No. DO Harus Diisi...');
      document.getElementById("ftdo_no").focus();
      return false;
  }
  else if(document.getElementById("ftsupplier_type").value=='') {
       alert('Tipe Outsource Harus Diisi...');
      document.getElementById("ftsupplier_type").focus();
      return false;
  }
  else if(document.getElementById("ftsupplier_code").value=='') {
      alert('Outsource harus disi...');
      document.getElementById("ftsupplier_code").focus();
      return false;
  }

  else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }

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


  return false;
}
//validasi surat jalan outsource

/*
function ValSuratJalanOutsource() {
  if(document.getElementById("ftdo_no").value=='') {
      alert('No. transaksi harus disi...');
      document.getElementById("ftdo_no").focus();
      return false;
  }

   else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }
  else if (DeliveryOrderInputQtyOutSource()==false) {
       return false;
  }

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

  return false;
}*/

function RevisiSuratJalanOutsource() {
  if(document.getElementById("ftdo_no").value=='') {
      alert('No. transaksi harus disi...');
      document.getElementById("ftdo_no").focus();
      return false;
  }

   else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }
  else if (DeliveryOrderInputQtyOutSource()==false) {
       return false;
  }

    
  return true;
}

function ValSupplierOutsource() {

  if(document.getElementById("ftsupplier_code").value=='') {
       alert('Kode Supplier harus diisi...');
       document.getElementById("ftsupplier_code").focus();
       return false;

  }
  else if(document.getElementById("ftsupplier_code").value.length!=4) {
      alert('Kode Supplier harus 4 karakter...');
      document.getElementById("ftsupplier_code").focus();
      return false;
  }
  else if(document.getElementById("ftsupplier_name").value=='') {
       alert('Nama Supplier harus diisi...');
       document.getElementById("ftsupplier_name").focus();
       return false;
  }
    else if(document.getElementById("ftaddress1").value=='') {
       alert('Alamat 1 harus diisi...');
       document.getElementById("ftaddress1").focus();
       return false;
  }
    else if(document.getElementById("ftcity_1").value=='') {
       alert('Kota 1  harus diisi...');
       document.getElementById("ftcity_1").focus();
       return false;
  }


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

  return false;
}


function ValStockMasukOutsourceInputQty() {
    var m="";


    var i=document.getElementsByName('fnindexD0[]').length;
    for(var j=1;j<i;j++) {
        if ( (document.getElementsByName('ftwarehouse_codeD0[]')[j].value=='')&&(document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1>0) ) {
              alert('Gudang Belum Valid ...');
              document.getElementsByName('ftwarehouse_codeD0[]')[j].focus();
              return false;

        }
        else if ( (document.getElementsByName('ftlocation_codeD0[]')[j].value=='')&&(document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1>0) ) {
            alert('Lokasi Belum Valid ...');
              document.getElementsByName('ftlocation_codeD0[]')[j].focus();
              return false;

        }

        if (document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1>0) {
            m="1";
        }
    }
    if(m=='') {
          alert('Qty di detail belum ada yang terisi ...');
            return false;
    }
    return true;
}

function ValStockMasukOutsource() {

  if(document.getElementById("ftstock_in_return_no").value=='') {
      alert('No. Transaksi Harus Diisi...');
      document.getElementById("ftstock_in_return_no").focus();
      return false;
  }
  else if(document.getElementById("fntype_reff").value=='') {
      alert('Type Reff Harus Diisi...');
      document.getElementById("fntype_reff").focus();
      return false;
  }
  else if((document.getElementById("fntype_reff").value=='1')&&(document.getElementById("hidden_ftreturn_no").value=='')) {
       alert('No. Return Harus Diisi...');
      document.getElementById("ftreturn_no").focus();
      return false;
  }
  else if((document.getElementById("fntype_reff").value=='0')&&(document.getElementById("hidden_ftdo_no").value=='')) {
     alert('No. DO Harus Diisi...');
      document.getElementById("ftdo_no").focus();
      return false;
  }

   else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }

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


  return false;
}


function ValSuratJalanServiceOutsourceInputQty() {
    var m="";


    var i=document.getElementsByName('fnindexD0[]').length;
    for(var j=1;j<i;j++) {
        if ( (document.getElementsByName('ftwarehouse_codeD0[]')[j].value=='')&&(document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1>0) ) {
              alert('Gudang Belum Valid ...');
              document.getElementsByName('ftwarehouse_codeD0[]')[j].focus();
              return false;

        }
        else if ( (document.getElementsByName('ftlocation_codeD0[]')[j].value=='')&&(document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1>0) ) {
            alert('Lokasi Belum Valid ...');
              document.getElementsByName('ftlocation_codeD0[]')[j].focus();
              return false;

        }

        if (document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1>0) {
            m="1";
        }
    }
    if(m=='') {
          alert('Qty di detail belum ada yang terisi ...');
            return false;
    }
    return true;
}

function ValSuratJalanServiceOutsource() {

  if(document.getElementById("ftservice_no").value=='') {
      alert('No. Transaksi Harus Diisi...');
      document.getElementById("ftservice_no").focus();
      return false;
  }
  else if(document.getElementById("ftstock_in_return_no").value=='') {
     alert('No. Stock In Outsource Harus Diisi...');
      document.getElementById("ftstock_in_return_no").focus();
      return false;
  }
 

   else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }

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


  return false;
}

function PerhitunganInsentiveSubcontraktorInputQty() {
      var i=document.getElementsByName('fnindexD0[]').length;
      var fcservice_amount=0;
      var fcdedution_amount=0;
      var fcamount=0;
        var tfcservice_amount=0;
      var tfcdedution_amount=0;
      var tfcamount=0;
    for(var j=1;j<i;j++) {
            fcservice_amount=(document.getElementsByName('fnqty_outD0[]')[j].value.replace(/,/g,'')*1)*(document.getElementById('fcpriceD0'+j).value.replace(/,/g,'')*1);
            fcdedution_amount=(document.getElementsByName('fnqty_deductionD0[]')[j].value.replace(/,/g,'')*1)*(document.getElementById('fcpriceD0'+j).value.replace(/,/g,'')*1);
            fcamount=(document.getElementsByName('fnqty_inD0[]')[j].value.replace(/,/g,'')*1)*(document.getElementById('fcpriceD0'+j).value.replace(/,/g,'')*1);
            document.getElementById('fcservice_amountD0'+j).value=fcservice_amount;
            document.getElementById('fcdedution_amountD0'+j).value=fcdedution_amount;
            document.getElementById('fcamountD0'+j).value=fcamount;
            tfcservice_amount=tfcservice_amount+fcservice_amount;
            tfcdedution_amount=tfcdedution_amount+fcdedution_amount;
            tfcamount=tfcamount+fcamount;
    }

    document.getElementById('fcsub_amount').value=tfcservice_amount;
    document.getElementById('fcdeduction_amount').value=tfcdedution_amount;
    document.getElementById('fcamount').value=tfcamount;
    return true;
}

function ValPerhitunganInsentiveSubcontraktor() {
     if(document.getElementById("ftfaktur_no").value=='') {
      alert('No. Transaksi Harus Diisi...');
      document.getElementById("ftfaktur_no").focus();
      return false;
  }
    

   else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }

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


  return false;
}

function FinalPerhitunganInsentiveSubcontraktor() {
     if(document.getElementById("ftfaktur_no").value=='') {
      alert('No. Transaksi Harus Diisi...');
      document.getElementById("ftfaktur_no").focus();
      return false;
  }


   else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }


  
  return true;
}

function UpdatePerhitunganInsentiveSubcontraktor() {
     if(document.getElementById("ftfaktur_no").value=='') {
      alert('No. Transaksi Harus Diisi...');
      document.getElementById("ftfaktur_no").focus();
      return false;
  }


   else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }

  return true;
}

