function ValGroupMesin() {
  if(document.getElementById("fnlevel").value=='') {
       document.getElementById("fnlevel").value=0;
  }

  if(document.getElementById("ftmachine_group_code").value=='') {
       alert('Kode Group Mesin harus diisi...');
       document.getElementById("ftmachine_group_code").focus();
       return false;
  }
  else if(document.getElementById("ftmachine_group_name").value=='') {
       alert('Nama Group Mesin harus diisi...');
       document.getElementById("ftmachine_group_name").focus();
       return false;
  }

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

  return false;
}

function ValMesin() {
  
  if(document.getElementById("ftmachine_code").value=='') {
      alert('Kode Mesin Harus Diisi...');
      document.getElementById("ftmachine_code").focus();
      return false;
  }
  else if(document.getElementById("ftmachine_name").value=='') {
       alert('Mesin Harus Diisi...');
      document.getElementById("ftmachine_name").focus();
      return false;
  }
  else if(document.getElementById("ftmachine_group_code").value=='') {
       alert('Kode Group Mesin harus diisi...');
       document.getElementById("ftmachine_group_code").focus();
       return false;
  }
  else if (MesinInputSparepart()==false) {
        return false;
  }

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

  return false;
}


function UpdateMesin() {
  
  if(document.getElementById("ftmachine_name").value=='') {
       alert('Mesin Harus Diisi...');
      document.getElementById("ftmachine_name").focus();
      return false;
  }
  else if(document.getElementById("ftmachine_group_code").value=='') {
       alert('Kode Group Mesin harus diisi...');
       document.getElementById("ftmachine_group_code").focus();
       return false;
  }
  else if (MesinInputSparepart()==false) {
       return false;
  }

  return true;
}

function MesinInputSparepart() {
    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('ftitem_codeD0[]')[j].focus();
             return false;
        }
    }

    return true;
}

function ValOperator() {

  if(document.getElementById("ftoperator_code").value=='') {
      alert('Kode Operator Harus Diisi...');
      document.getElementById("ftoperator_code").focus();
      return false;
  }
  else if(document.getElementById("ftemployee_name").value=='') {
       alert('Nama Operator Harus Diisi...');
      document.getElementById("ftemployee_name").focus();
      return false;
  }
//  alert(str_url);
    ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftoperator_code').value);

  return false;
}

function ValLine() {

  if(document.getElementById("ftline_code").value=='') {
      alert('Kode Line Harus Diisi...');
      document.getElementById("ftline_code").focus();
      return false;
  }
  else if(document.getElementById("ftline_name").value=='') {
       alert('Nama Line Harus Diisi...');
      document.getElementById("ftline_name").focus();
      return false;
  }
//  alert(str_url);
    ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftline_code').value);

  return false;
}

// Hasil Produksi 
function HasilProduksiSame() {
    var m="";


    var i=document.getElementsByName('fnindexD0[]').length;
    for(var j=1;j<i;j++)
    {
        for(var k=1;k<i;k++)
        {
            if (j!=k)
                {
                    if ((document.getElementsByName('ftmachine_codeD0[]')[j].value==document.getElementsByName('ftmachine_codeD0[]')[k].value)&&(document.getElementsByName('ftoperator_codeD0[]')[j].value==document.getElementsByName('ftoperator_codeD0[]')[k].value)&&(document.getElementsByName('ftspk_noD0[]')[j].value==document.getElementsByName('ftspk_noD0[]')[k].value)&&(document.getElementsByName('ftwarehouse_codeD0[]')[j].value==document.getElementsByName('ftwarehouse_codeD0[]')[k].value)&&(document.getElementsByName('ftlocation_codeD0[]')[j].value==document.getElementsByName('ftlocation_codeD0[]')[k].value)&&(document.getElementsByName('hidden_ftitem_codeD0[]')[j].value==document.getElementsByName('hidden_ftitem_codeD0[]')[k].value))
                    {
                          alert('Detail Transaksi Tidak Boleh Sama');
                          document.getElementsByName('hidden_ftitem_codeD0[]')[j].focus();
                          return false;
                    }
                }
            
        }
    }
    return true;
}

function HasilProduksiInputQty() {
    var m="";

    var i=document.getElementsByName('fnindexD0[]').length;
    for(var j=1;j<i;j++) {
        if (document.getElementsByName('ftmachine_codeD0[]')[j].value=='') {
              alert('No. Mesin Harus Diisi ...');
              document.getElementsByName('ftmachine_codeD0[]')[j].focus();
              return false;
		}
        else if (document.getElementsByName('ftoperator_codeD0[]')[j].value=='') {
              alert('Kode Operator Harus Diisi ...');
              document.getElementsByName('ftoperator_codeD0[]')[j].focus();
              return false;
        }				
        else if (document.getElementsByName('ftspk_noD0[]')[j].value=='') {
              alert('No. Spk Harus Diisi ...');
              document.getElementsByName('ftspk_noD0[]')[j].focus();
              return false;
        }		
        else if (document.getElementsByName('ftitem_codeD0[]')[j].value=='') {
              alert('Kode Barang Belum Valid ...');
              document.getElementsByName('ftitem_codeD0[]')[j].focus();
              return false;
        }
        else 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 ValHasilProduksi() {

  if(document.getElementById("ftproduction_no").value=='') {
      alert('No. Produksi Harus Diisi...');
      document.getElementById("ftproduction_no").focus();
      return false;
  }

  else if(document.getElementById("ftshift_code").value=='') {
      alert('Kode Shift harus disi...');
      document.getElementById("ftshift_code").focus();
      return false;
  }
   else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }

   else if (HasilProduksiInputQty()==false) {
       return false;
  }
   else if (HasilProduksiSame()==false) {
       return false;
  }

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

  return false;
  }

// produksi end here 

function ValStockInHasilProduksiInputQty() {
    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('Gudang Belum Valid ...');
              document.getElementsByName('ftwarehouse_codeD0[]')[j].focus();
              return false;

        }
        else if (document.getElementsByName('ftlocation_codeD0[]')[j].value=='') {
              alert('Lokasi Belum Valid ...');
              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 ValStockInHasilProduksi() {

  if(document.getElementById("ftstock_in_no").value=='') {
      alert('No. Stock Masuk Harus Diisi...');
      document.getElementById("ftstock_in_no").focus();
      return false;
  }
  /*
  else if(document.getElementById("ftline_code").value=='') {
      alert('Line Harus Diisi...');
      document.getElementById("ftline_code").focus();
      return false;
  }
    */
  else if(document.getElementById("ftreff_no").value=='') {
       alert('No. Reff Harus Diisi...');
      document.getElementById("ftreff_no").focus();
      return false;
  }
   else if(document.getElementById("hidden_ftoperator_code").value=='') {
      alert('Operator harus disi...');
      document.getElementById("ftoperator_code").focus();
      return false;
  }
    else if(document.getElementById("hidden_ftoperator_code").value=='') {
      alert('Operator harus disi...');
      document.getElementById("ftoperator_code").focus();
      return false;
  }
    else if(document.getElementById("ftmachine_code").value=='') {
      alert('Mesin harus disi...');
      document.getElementById("ftmachine_code").focus();
      return false;
  }
   else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }

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


  return false;
}

//Start Val Reject Production Department
function RejectProduksiSame() {
    var m="";


    var i=document.getElementsByName('fnindexD0[]').length;
    for(var j=1;j<i;j++)
    {
        for(var k=1;k<i;k++)
        {
            if (j!=k)
                {
                    if ((document.getElementsByName('ftproduction_noD0[]')[j].value==document.getElementsByName('ftproduction_noD0[]')[k].value)&&(document.getElementsByName('hidden_ftitem_codeD0[]')[j].value==document.getElementsByName('hidden_ftitem_codeD0[]')[k].value))
                    {
                          alert('Detail Transaksi Tidak Boleh Sama');
                          document.getElementsByName('ftitem_codeD0[]')[j].focus();
                          return false;
                    }
                }

        }
    }
    return true;
}
function RejectProduksiInputQty() {
    var m="";


    var i=document.getElementsByName('fnindexD0[]').length;
    for(var j=1;j<i;j++) {
        ffqty1=document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1;
        ffqty2=document.getElementsByName('fnqty_productionD0[]')[j].value.replace(/,/g,'')*1;
        
        if (document.getElementsByName('ftproduction_noD0[]')[j].value=='') {
              alert('No. Produksi Harus Diisi ...');
              document.getElementsByName('ftproduction_noD0[]')[j].focus();
              return false;
		}
        else if (document.getElementsByName('ftitem_codeD0[]')[j].value=='') {
              alert('Kode Barang Belum Valid ...');
              document.getElementsByName('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;
        }
        else if(ffqty1>ffqty2 ) {
            alert('Qty Reject lebih besar dari Qty Produksi...');
            document.getElementsByName('fnqtyD0[]')[j].focus();
            return false;
        }


    }
    return true;
}

function ValRejectProduksi() {

  if(document.getElementById("ftreject_production_department_no").value=='') {
      alert('No. Reject Produksi Harus Diisi...');
      document.getElementById("ftreject_production_department_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("ftspk_produksi_no").value=='') {
      alert('No. Spk harus disi...');
      document.getElementById("ftspk_produksi_no").focus();
      return false;
  }
  else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }

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


  return false;
  }
//End Val Reject Production Department

function ValQCInputQty() {
    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 ValQC() {

  if(document.getElementById("ftqc_no").value=='') {
      alert('No. Transaksi Harus Diisi...');
      document.getElementById("ftqc_no").focus();
      return false;
  }
  else if(document.getElementById("hidden_ftstock_in_no").value=='') {
       alert('No. Stock In Harus Diisi...');
      document.getElementById("ftstock_in_no").focus();
      return false;
  }
  
   else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }

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


  return false;
}
function SPKInputQty() {
    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 SPBInputQty() {
    var m="";


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

        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;

        }
                else if(ffqty1>ffqty2 ) {
            alert('Qty SPB lebih besar dari Qty Outstanding...');
            document.getElementsByName('fnqtyD0[]')[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 ValSPB() {

  if(document.getElementById("ftspb_no").value=='') {
      alert('No. SPB Harus Diisi...');
      document.getElementById("ftspb_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('No Estimation 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 (SPBInputQty()==false) {
       return false;
  }
    ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftspb_no').value);


  return false;
}

function GilingSame() {
    var m="";


    var i=document.getElementsByName('fnindexD0[]').length;
    for(var j=1;j<i;j++)
    {
        for(var k=1;k<i;k++)
        {
            if (j!=k)
                {
                    if ((document.getElementsByName('ftreject_production_department_noD0[]')[j].value==document.getElementsByName('ftreject_production_department_noD0[]')[k].value)&&(document.getElementsByName('ftproduction_noD0[]')[j].value==document.getElementsByName('ftproduction_noD0[]')[k].value)&&(document.getElementsByName('hidden_ftitem_codeD0[]')[j].value==document.getElementsByName('hidden_ftitem_codeD0[]')[k].value))
                    {
                          alert('Detail Transaksi Tidak Boleh Sama');
                          document.getElementsByName('hidden_ftitem_codeD0[]')[j].focus();
                          return false;
                    }
                }

        }
    }
    return true;
}
function ValGilingInputQty() {
//    var m="";


    var i=document.getElementsByName('fnindexD0[]').length;
    for(var j=1;j<i;j++) {
        ffqty1=document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1;
        ffqty2=document.getElementsByName('fnqty_rejectD0[]')[j].value.replace(/,/g,'')*1;
        if (document.getElementsByName('ftreject_production_department_noD0[]')[j].value=='')
        {
              alert('No. Reject Harus Diisi ...');
              document.getElementsByName('ftreject_production_department_noD0[]')[j].focus();
              return false;
	}
        else if (document.getElementsByName('ftproduction_noD0[]')[j].value=='')
        {
              alert('No. Produksi Harus Diisi ...');
              document.getElementsByName('ftproduction_noD0[]')[j].focus();
              return false;
	}
        else if (document.getElementsByName('hidden_ftitem_codeD0[]')[j].value=='')
        {
              alert('Kode Barang Belum Valid ...');
              document.getElementsByName('hidden_ftitem_codeD0[]')[j].focus();
              return false;
        }
        else if(ffqty1>ffqty2 )
        {
            alert('Qty Giling lebih besar dari Qty Reject...');
            document.getElementsByName('fnqtyD0[]')[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 ValGiling() {

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

  else if(document.getElementById("hidden_ftspk_no").value=='') {
       alert('No. Spk Harus Diisi...');
      document.getElementById("ftspk_no").focus();
      return false;
  }
  else if(document.getElementById("ftgiling_type").value=='') {
       alert('Tipe Giling Harus Diisi...');
      document.getElementById("ftgiling_type").focus();
      return false;
  }
   else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }

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


  return false;
}

function ValHasilGilingInputQty() {
    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 ValHasilGiling() {

  if(document.getElementById("ftgiling_result_no").value=='') {
      alert('No. Transaksi Harus Diisi...');
      document.getElementById("ftgiling_result_no").focus();
      return false;
  }
  else if(document.getElementById("hidden_ftgiling_no").value=='') {
       alert('No. Reject Harus Diisi...');
      document.getElementById("ftqc_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('ftgiling_result_no').value);


  return false;
}



