var str_url=location.href.replace(/#/g,'');

function ValCompanyProfile() {
  if(document.getElementById("ftcompany_code").value=='') {
       alert('Kode Company harus diisi...');
       document.getElementById("ftcompany_code").focus();
       return false;
  }
  else if(document.getElementById("ftcompany_name").value.length=='') {
       alert('Nama Company harus diisi...');
       document.getElementById("ftcompany_name").focus();
       return false;
  }


  ajax_do(str_url+'&ajax=1&code=transno&fttrans_no='+document.getElementById('ftcompany_code').value);
   document.getElementById("ftcompany_code").focus();
  return false;
}

function ValTipeDocument() {
  if(document.getElementById("ftdocument_type_code").value=='') {
       alert('Kode Tipe Document harus diisi...');
       document.getElementById("ftdocument_type_code").focus();
       return false;
  }
  else if(document.getElementById("ftdocument_type_name").value.length=='') {
       alert('Nama Tipe Document harus diisi...');
       document.getElementById("ftdocument_type_name").focus();
       return false;
  }


  ajax_do(str_url+'&ajax=1&code=transno&fttrans_no='+document.getElementById('ftdocument_type_code').value);
   document.getElementById("ftdocument_type_code").focus();
  return false;
}

function ValDocument() {
  if(document.getElementById("ftdocument_code").value=='') {
       alert('Kode Tipe Document harus diisi...');
       document.getElementById("ftdocument_type_code").focus();
       return false;
  }
  else if(document.getElementById("ftdocument_name").value=='') {
       alert('Nama  Document harus diisi...');
       document.getElementById("ftdocument_name").focus();
       return false;
  }
  else if(document.getElementById("ftdocument_no").value.length=='') {
       alert('No. Document harus diisi...');
       document.getElementById("ftdocument_no").focus();
       return false;
  }
 
  ajax_do(str_url+'&ajax=1&code=transno&fttrans_no='+document.getElementById('ftdocument_code').value);
   document.getElementById("ftdocument_code").focus();
  return false;
}

/*
function ValDocument() {
  if(document.getElementById("ftdocument_code").value=='') {
       alert('Kode Tipe Document harus diisi...');
       document.getElementById("ftdocument_type_code").focus();
       return false;
  }
  else if(document.getElementById("ftdocument_code").value=='') {
       alert('Kode  Document harus diisi...');
       document.getElementById("ftdocument_code").focus();
       return false;
  }
  else if(document.getElementById("ftrev_no").value.length=='') {
       alert('No. Rev harus diisi...');
       document.getElementById("ftrev_no").focus();
       return false;
  }
  else if(document.getElementById("fttitle").value.length=='') {
       alert('Judul harus diisi...');
       document.getElementById("fttitle").focus();
       return false;
  }

  ajax_do(str_url+'&ajax=1&code=transno&fttrans_no='+document.getElementById('ftdocument_code').value);
   document.getElementById("ftdocument_code").focus();
  return false;
}

*/
function ValKurs() {

  if(document.getElementById("ftsimbol").value=='') {
       alert('Kode mata uang harus diisi...');
       document.getElementById("ftsimbol").focus();
       return false;
  }
  else if(document.getElementById("ftdescription").value.length=='') {
       alert('Nama mata uang harus diisi...');
       document.getElementById("ftdescription").focus();
       return false;
  }


  ajax_do(str_url+'&ajax=1&code=transno&fttrans_no='+document.getElementById('ftsimbol').value);
   document.getElementById("ftsimbol").focus();
  return false;
}

function ValKacaHelm() {

  if(document.getElementById("ftkaca_helm_code").value=='') {
       alert('Kode kaca helm harus diisi...');
       document.getElementById("ftkaca_helm_code").focus();
       return false;
  }
  else if(document.getElementById("ftkaca_helm_code").value.length!=3) {
       alert('Kode kaca helm harus 3 karakter...');
       document.getElementById("ftkaca_helm_code").focus();
       return false;
  }
  else if(document.getElementById("ftkaca_helm_name").value=='') {
       alert('Nama kaca helm harus di isi...');
       document.getElementById("ftkaca_helm_name").focus();
       return false;
  }


  ajax_do(str_url+'&ajax=1&code=transno&fttrans_no='+document.getElementById('ftkaca_helm_code').value);
   document.getElementById("ftkaca_helm_code").focus();
  return false;
}

function ValSubgroupBarang() {

  if(document.getElementById("ftstock_subgroup_code").value=='') {
       alert('Kode Subgroup harus diisi...');
       document.getElementById("ftstock_subgroup_code").focus();
       return false;
  }
  else if(document.getElementById("ftstock_subgroup_code").value.length!=3) {
       alert('Kode Subgroup harus 3 karakter...');
       document.getElementById("ftstock_subgroup_code").focus();
       return false;
  }
  else if(document.getElementById("ftstock_subgroup_name").value=='') {
       alert('Nama Subgroup harus di isi...');
       document.getElementById("ftstock_subgroup_name").focus();
       return false;
  }
  else if(document.getElementById("hidden_ftstock_group_code").value=='') {
       alert('Kode Stock group belum valid...');
       document.getElementById("ftstock_group_code").focus();
       return false;
  }

  ajax_do(str_url+'&ajax=1&code=transno&fttrans_no='+document.getElementById('ftstock_subgroup_code').value);
   document.getElementById("ftstock_subgroup_code").focus();
  return false;
}

function ValKas() {

  if(document.getElementById("ftcode").value=='') {
       alert('Kode Kas harus diisi...');
       document.getElementById("ftcode").focus();
       return false;
  }
  else if(document.getElementById("ftdescription").value=='') {
       alert('Keterangan harus diisi...');
       document.getElementById("ftdescription").focus();
       return false;
  }
     ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftcode').value);

  return false;
}

function ValBank() {

  if(document.getElementById("ftcode").value=='') {
       alert('Kode Bank harus diisi...');
       document.getElementById("ftcode").focus();
       return false;
  }
  else if(document.getElementById("ftdescription").value=='') {
       alert('Keterangan harus diisi...');
       document.getElementById("ftdescription").focus();
       return false;
  }
     ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftcode').value);

  return false;
}


function ValSupplier() {

  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=='') {
      alert('Kode Supplier harus diisi...');
      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;
  }
   //else if(document.getElementById("ftzip_code_1").value=='') {
   //    alert('Kode Pos 1  harus diisi...');
  //     document.getElementById("ftzip_code_1").focus();
  //     return false;
 // }
  //  else if(document.getElementById("ftstate_1").value=='') {
  //     alert('Propinsi 1  harus diisi...');
  //     document.getElementById("ftstate_1").focus();
  //     return false;
 // }
   // else if(document.getElementById("ftcountry").value=='') {
   //    alert('Negara  harus diisi...');
   //    document.getElementById("ftcountry").focus();
  //     return false;
 // }
 // else if(document.getElementById("ftnpwp").value=='') {
 //      alert('NPWP  harus diisi...');
 //      document.getElementById("ftnpwp").focus();
 //      return false;
 // }
 // else if(document.getElementById("ftnpwp").value=='') {
  //     alert('NPWP  harus diisi...');
  //     document.getElementById("ftnpwp").focus();
 //      return false;
 // }
     ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftsupplier_code').value);

  return false;
}

function ValCustomer() {
  if(document.getElementById("ftcustomer_code").value=='') {
       alert('Nomor Tracking harus diisi...');
       document.getElementById("ftcustomer_code").focus();
       return false;
  }

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

  return false;

}


function ValTipeCustomer() {

  if(document.getElementById("ftcustomer_type_code").value=='') {
       alert('Kode Tipe Customer harus diisi...');
       document.getElementById("ftcustomer_type_code").focus();
       return false;
  }
  else if(document.getElementById("ftcustomer_type_name").value=='') {
       alert('Nama Tipe Customer harus diisi...');
       document.getElementById("ftcustomer_type_name").focus();
       return false;
  }
   ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftcustomer_type_code').value);

  return false;
}

function ValBarangBebas() {
  if(document.getElementById("ftitem_code").value=='') {
       alert('Kode Barang Bebas harus diisi...');
       document.getElementById("ftitem_code").focus();
       return false;
  }

  else if(document.getElementById("ftitem_name").value=='') {
       alert('Nama Barang Bebas harus diisi...');
       document.getElementById("ftitem_name").focus();
       return false;
  }
  else if(document.getElementById("ftuom_code").value=='') {
       alert('Satuan harus diisi...');
       document.getElementById("ftuom_code").focus();
       return false;
  }
  ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftitem_code').value);
   document.getElementById("ftitem_code").focus();
    return false;
}


function ValSize() {

  if(document.getElementById("ftsize_code").value=='') {
       alert('Kode Ukuran harus diisi...');
       document.getElementById("ftsize_code").focus();
       return false;
  }
     else if(document.getElementById("ftsize_code").value.length!=1) {
       alert('Kode Size harus 1 karakter...');
       document.getElementById("ftsize_code").focus();
       return false;
  }
  else if(document.getElementById("ftsize_name").value=='') {
       alert('Nama Ukuran harus diisi...');
       document.getElementById("ftsize_name").focus();
       return false;
  }
   ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftsize_code').value);
   document.getElementById("ftitem_code").focus();
    return false;
}
/*
function Setftitem_code() {
    if( document.getElementById("ftstock_category_code").value=='inv') {
         document.getElementById("ftitem_code").value=document.getElementById("ftstock_group_code").value+document.getElementById("ftstock_subgroup_code").value+document.getElementById("ftdecal_code").value+ document.getElementById("ftcolor_code").value+document.getElementById("ftsize_code").value+document.getElementById("ftyesno").value+document.getElementById("ftkaca_helm_code").value;

         document.getElementById("ftitem_name").value=document.getElementById("hidden_ftstock_group_code").value;
		 document.getElementById("ftprint_name").value=document.getElementById("hidden_ftstock_group_code").value;

         document.getElementById("ftitem_name").value+=' '+document.getElementById("hidden_ftstock_subgroup_code").value;
		  document.getElementById("ftprint_name").value+=' '+document.getElementById("hidden_ftstock_subgroup_code").value;

         document.getElementById("ftitem_name").value+=' '+document.getElementById("hidden_ftdecal_code").value;
		 document.getElementById("ftprint_name").value+=' '+document.getElementById("hidden_ftdecal_code").value;

         document.getElementById("ftitem_name").value+='-'+document.getElementById("hidden_ftcolor_code").value;
		  document.getElementById("ftprint_name").value+='-'+document.getElementById("hidden_ftcolor_code").value;

         if(document.getElementById("ftsize_code").value!='0') {

             document.getElementById("ftitem_name").value+='-"'+document.getElementById("hidden_ftsize_code").value+'"';
			  document.getElementById("ftprint_name").value+='-"'+document.getElementById("hidden_ftsize_code").value+'"';
         }
         document.getElementById("ftitem_name").value+='-'+document.getElementById("hidden_ftkaca_helm_code").value;
		  document.getElementById("ftprint_name").value+='-'+document.getElementById("hidden_ftkaca_helm_code").value;
          if(document.getElementById("ftyesno").value=='1') {

                document.getElementById("ftitem_name").value+='(2 in 1)';
                document.getElementById("ftprint_name").value+='(2 in 1)';
          }

    }
    else if (document.getElementById("ftstock_category_code").value=='kca-helm') {
         document.getElementById("ftitem_code").value=document.getElementById("ftstock_group_code").value+document.getElementById("ftstock_subgroup_code").value+document.getElementById("ftdecal_code").value+ document.getElementById("ftcolor_code").value+document.getElementById("ftsize_code").value+document.getElementById("ftyesno").value+'1';

    }

}
*/

function ValBarang() {

    if(document.getElementById("ftitem_code").value=='') {
        alert('Kode Barang harus diisi...');
        document.getElementById("ftitem_code").focus();
        return false;
    }
    else if(document.getElementById("ftitem_code").value.indexOf('&') != -1) {
       alert('Kode Barang Tidak boleh menggunakan Karakter & ...');
       document.getElementById("ftitem_code").focus();
       return false;
    } 
    else if(document.getElementById("ftitem_name").value=='') {
        alert('Nama Barang harus diisi...');
        document.getElementById("ftitem_name").focus();
        return false;
    }
    else if(document.getElementById("ftprint_name").value=='') {
        alert('Nama Cetak harus diisi...');
        document.getElementById("ftprint_name").focus();
        return false;
    }
    else if(document.getElementById("ftuom_code").value=='') {
        alert('Satuan harus diisi...');
        document.getElementById("ftuom_code").focus();
        return false;
    }
    else if(document.getElementById("ftstock_category_code").value=='') {
        alert('Kategory harus diisi...');
        document.getElementById("ftstock_category_code").focus();
        return false;
    }

    else if(document.getElementById("hidden_ftstock_group_code").value=='') {
        alert('Group belum valid...');
        document.getElementById("ftstock_group_code").focus();
        return false;
    }
    else if(document.getElementById("ftgl_inv_acc").value=='' && document.getElementById("ftstock_category_code").value=='inv') {
        alert('No Perkiraan Persediaan harus diisi...');
        document.getElementById("ftgl_inv_acc").focus();
        return false;
    }
    else if(document.getElementById("ftgl_cogs_acc").value=='') {
        alert('No Perkiraan HPP harus diisi...');
        document.getElementById("ftgl_cogs_acc").focus();
        return false;
    }
    else if(document.getElementById("ftgl_sales_acc").value=='' && document.getElementById("ftstock_category_code").value=='inv') {
        alert('No Perkiraan Penjualan harus diisi...');
        document.getElementById("ftgl_sales_acc").focus();
        return false;
    }
    else if(document.getElementById("ftgl_sales_ret_acc").value=='' && document.getElementById("ftstock_category_code").value=='inv') {
        alert('No Perkiraan Retur Penjualan harus diisi...');
        document.getElementById("ftgl_sales_ret_acc").focus();
        return false;
    }
    else if(document.getElementById("ftgl_sales_disc_acc").value=='' && document.getElementById("ftstock_category_code").value=='inv') {
        alert('No Perkiraan Discount Penjualan harus diisi...');
        document.getElementById("ftgl_sales_disc_acc").focus();
        return false;
    }
    else if(ValBarang1()==false) {
        return false;
    }

    ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftitem_code').value);
    document.getElementById("ftitem_code").focus();
    return false;
}

function ValBarang1() {
    var i=document.getElementsByName('ftuom_code_multiD1[]').length;
    for(var j=1;j<i;j++) {

        if  (document.getElementsByName('ftuom_code_multiD1[]')[j].value==document.getElementById('ftuom_code').value) {
            alert('Kode satuan sudah digunakan ');
            document.getElementsByName('ftuom_code_multiD1[]')[j].focus();
            return false;
        } else  if  (document.getElementsByName('ftuom_code_multiD1[]')[j].value=='') {
            alert('Kode Multi Satuan harus diisi ');
            document.getElementsByName('ftuom_code_multiD1[]')[j].focus();
            return false;
        } else  if  (document.getElementsByName('ffformulaD1[]')[j].value.replace(/,/g,'')*1 <= 0) {
            alert('Nominal Formula harus lebih besar dari 0 ');
            document.getElementsByName('ffformulaD1[]')[j].focus();
            return false;
        }

        for(var k=1;k<j;k++) {
            if  (document.getElementsByName('ftuom_code_multiD1[]')[k].value==document.getElementsByName('ftuom_code_multiD1[]')[j].value) {
                alert('Kode satuan sudah digunakan ');
                document.getElementsByName('ftuom_code_multiD1[]')[k].focus();
                return false;
            }
        }
    }

    return true;
}

function UpdateBarang() {
    if(document.getElementById("ftitem_code").value=='') {
       alert('Kode Barang harus diisi...');
       document.getElementById("ftitem_code").focus();
       return false;
  }
  else if(document.getElementById("ftitem_name").value=='') {
       alert('Nama Barang harus diisi...');
       document.getElementById("ftitem_name").focus();
       return false;
  }
  else if(document.getElementById("ftprint_name").value=='') {
       alert('Nama Cetak harus diisi...');
       document.getElementById("ftprint_name").focus();
       return false;
  }
    else if(document.getElementById("ftuom_code").value=='') {
       alert('Satuan harus diisi...');
       document.getElementById("ftuom_code").focus();
       return false;
  }

    else if(document.getElementById("ftstock_category_code").value=='') {
       alert('Kategory harus diisi...');
       document.getElementById("ftstock_category_code").focus();
       return false;
    }
    else if(document.getElementById("hidden_ftstock_group_code").value=='') {
        alert('Group belum valid...');
        document.getElementById("ftstock_group_code").focus();
        return false;
    }
    else if(document.getElementById("ftgl_inv_acc").value=='' && document.getElementById("ftstock_category_code").value=='inv') {
        alert('No Perkiraan Persediaan harus diisi...');
        document.getElementById("ftgl_inv_acc").focus();
        return false;
    }
    else if(document.getElementById("ftgl_cogs_acc").value=='') {
        alert('No Perkiraan HPP harus diisi...');
        document.getElementById("ftgl_cogs_acc").focus();
        return false;
    }
    else if(document.getElementById("ftgl_sales_acc").value=='' && document.getElementById("ftstock_category_code").value=='inv') {
        alert('No Perkiraan Penjualan harus diisi...');
        document.getElementById("ftgl_sales_acc").focus();
        return false;
    }
    else if(document.getElementById("ftgl_sales_ret_acc").value=='' && document.getElementById("ftstock_category_code").value=='inv') {
        alert('No Perkiraan Retur Penjualan harus diisi...');
        document.getElementById("ftgl_sales_ret_acc").focus();
        return false;
    }
    else if(document.getElementById("ftgl_sales_disc_acc").value=='' && document.getElementById("ftstock_category_code").value=='inv') {
        alert('No Perkiraan Discount Penjualan harus diisi...');
        document.getElementById("ftgl_sales_disc_acc").focus();
        return false;
    }
    else if(ValBarang1()==false) {
        return false;
    }

    return true;
}

function ValLokasi() {

  if(document.getElementById("ftlocation_code").value=='') {
       alert('Kode Lokasi harus diisi...');
       document.getElementById("ftlocation_code").focus();
       return false;
  }
  else if(document.getElementById("ftlocation_name").value=='') {
       alert('Nama Lokasi harus diisi...');
       document.getElementById("ftlocation_name").focus();
       return false;
  }
  else if(document.getElementById("ftwarehouse_code").value=='') {
       alert('Kode Gudang harus diisi...');
       document.getElementById("ftwarehouse_code").focus();
       return false;
  }

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

  document.getElementById("ftitem_code").focus();
  return false;
}

function ValGudang() {

  if(document.getElementById("ftwarehouse_code").value=='') {
       alert('Kode Gudang harus diisi...');
       document.getElementById("ftwarehouse_code").focus();
       return false;
  }
  else if(document.getElementById("ftwarehouse_name").value=='') {
       alert('Nama Gudang harus diisi...');
       document.getElementById("ftwarehouse_name").focus();
       return false;
  }

  ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftwarehouse_code').value);
  document.getElementById("ftitem_code").focus();

  return false;
}

function ValSatuan() {

  if(document.getElementById("ftuom_code").value=='') {
       alert('Kode Satuan harus diisi...');
       document.getElementById("ftuom_code").focus();
       return false;
  }
  else if(document.getElementById("ftuom_name").value=='') {
       alert('Nama Satuan harus diisi...');
       document.getElementById("ftuom_name").focus();
       return false;
  }

  ajax_do(str_url+'&ajax=1&code=transno&fttrans_no='+document.getElementById('ftuom_code').value);
  document.getElementById("ftitem_code").focus();
  return false;
}

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

  if(document.getElementById("ftstock_group_code").value=='') {
       alert('Kode Group Barang harus diisi...');
       document.getElementById("ftstock_group_code").focus();
       return false;
  }
  else if(document.getElementById("ftstock_group_name").value=='') {
       alert('Nama Group Barang harus diisi...');
       document.getElementById("ftstock_group_name").focus();
       return false;
  }

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

  return false;
}
//Ganti Password
function ValGantiPassword() {

  if(document.getElementById("ftusername").value=='') {
       alert('UserName harus diisi...');
       document.getElementById("ftusername").focus();
       return false;
  }
  else if(document.getElementById("password_confirm1").value!=document.getElementById("password_confirm2").value) {
       alert('Passwod Confirm tidak sama ...');
       document.getElementById("ftusername").focus();
       return false;
  }
  return true;

}

//User
function ValUser() {

  if(document.getElementById("ftusername").value=='') {
       alert('UserName harus diisi...');
       document.getElementById("ftusername").focus();
       return false;
  }
  else if(document.getElementById("ftpassword").value!=document.getElementById("password_confirm").value) {
       alert('Password Confirm tidak sama...');
       document.getElementById("password_confirm").focus();
       return false;
  }
  else if(document.getElementById("ftuser_group_code").value=='') {
       alert('Kode group user diisi harus diisi...');
       document.getElementById("ftuser_group_code").focus();
       return false;
  }
   else if(document.getElementById("ftfirst_name").value=='') {
       alert('Nama depan harus diisi harus diisi...');
       document.getElementById("ftfirst_name").focus();
       return false;
  }
  else if(document.getElementById("ftmiddle_name").value=='') {
       alert('Nama tengah harus diisi...');
       document.getElementById("ftmiddle_name").focus();
       return false;
  }
   else if(document.getElementById("ftlast_name").value=='') {
       alert('Nama belakang harus diisi...');
       document.getElementById("ftlast_name").focus();
       return false;
  }
  else if(document.getElementById("ftlast_name").value=='') {
       alert('Nama belakang harus diisi...');
       document.getElementById("ftlast_name").focus();
       return false;
  }

     ajax_do(str_url+'&ajax=1&code=transno&fttrans_no='+document.getElementById('ftusername').value);
  document.getElementById("ftusername").focus();
  return false;

}

function ValUserGroup() {

    if(document.getElementById("ftuser_group_code").value=='') {
       alert('Kode Group User harus disi...');
       document.getElementById("ftuser_group_code").focus();
       return false;
    }
     else if(document.getElementById("ftuser_group_name").value=='') {
       alert('Nama Group User harus disi...');
       document.getElementById("ftuser_group_name").focus();
       return false;
  }

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

    return false;
}

////Innitial stock
//-------------------------------------------------------------------
function ValSaldoAwalStock() {
  if(document.getElementById("ftstock_in_no").value=='') {
       alert('No. transaksi harus disi...');
       document.getElementById("ftstock_in_no").focus();
       return false;
  }
//  else if(document.getElementById("ftcategory_code").value=='') {
//       alert('Kategori harus disi...');
//       document.getElementById("ftcategory_code").focus();
//       return false;
//  }
//    else if((document.getElementById("ftcategory_code").value!=0)&&(document.getElementById("ftstock_in_company").value=='')) {
//       alert('Supplier/Customer harus disi...');
//       document.getElementById("ftstock_in_company").focus();
//       return false;
//  }
//   else if(document.getElementById("ftdocument_no").value=='') {
//       alert('No. Document harus disi...');
//       document.getElementById("ftdocument_no").focus();
//       return false;
//  }
//  else if(document.getElementById("ftdelivery_no").value=='') {
//       alert('No. Surat Jalan harus disi...');
//       document.getElementById("ftdelivery_no").focus();
//       return false;
//  }
//  else if(document.getElementById("ftchecked_user").value=='') {
//       alert('Nama Pengecek barang harus diisi...');
//        document.getElementById("ftchecked_user").focus();
//       return false;
//  }
   else if (SaldoAwalStockInputQty()==false) {
       return false;
  }

  ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftstock_in_no').value);
   document.getElementById("ftstock_in_no").focus();
    return false;


}

function SaldoAwalStockRecalQty() {

    var i=document.getElementsByName('fnindexD0[]').length;

    var ffqty=0;
    var fcprice=0;
    var ffTotal=0;

    for(var j=1;j<i;j++) {
        ffqty=document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1;
        //fcprice=document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1;
       // ffTotal=ffTotal+(ffqty*fcprice);
       ffTotal=ffTotal+ffqty;

    }

    document.getElementById('fntotal_qty').value=ffTotal;

}

function SaldoAwalStockInputQty() {
    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;
        }
        else if (document.getElementsByName('ftwarehouse_codeD0[]')[j].value=='') {
             alert('Gudang harus diisi..');
             document.getElementsByName('ftwarehouse_codeD0[]')[j].focus();
             return false;
        }
        else if (document.getElementsByName('ftlocation_codeD0[]')[j].value=='') {
             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 masuk harus diisi..');
//              document.getElementsByName('fnqtyD0[]')[j].focus();
//             return false;
//        }

//        else if (document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1<=0) {
//             alert('Harga masuk harus diisi..');
//              document.getElementsByName('fcpriceD0[]')[j].focus();
//             return false;
//        }

    }

    return true;
}


////Stock In
//-------------------------------------------------------------------


function ValStockMasukSetengahJadi() {
  if(document.getElementById("ftstock_in_no").value=='') {
       alert('No. transaksi harus disi...');
       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((document.getElementById("ftcategory_code").value!=5)&&(document.getElementById("ftcategory_code").value!=8)&&(document.getElementById("hidden_ftstock_in_company").value=='')) {
       alert('Supplier/Customer belum valid...');
       document.getElementById("ftstock_in_company").focus();
       return false;
  }
  else if (StockMasukInputQty()==false) {
       return false;
  }
  if (accessExpDate()==false) {
       return false;
  }

  ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftstock_in_no').value);
   document.getElementById("ftstock_in_no").focus();
    return false;


}

function ValStockMasukSparepart() {
  if(document.getElementById("ftstock_in_no").value=='') {
       alert('No. transaksi harus disi...');
       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 (StockMasukInputQty()==false) {
       return false;
  }
  if (accessExpDate()==false) {
       return false;
  }

  ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftstock_in_no').value);
   document.getElementById("ftstock_in_no").focus();
    return false;


}
function accessExpDate() {
    var i=document.getElementsByName('fnindexD0[]').length;
    for(var j=1;j<i;j++) {
        var ftitem_code=document.getElementsByName('ftitem_codeD0[]')[j].value;

        if (document.getElementById('fbaccessD11').value=='aktif') {
            if(document.getElementsByName('fdexp_dateD0[]')[j].value==''){ 
                if(document.getElementsByName('ftactiveD0[]')[j].value==1){
                alert('Exp. Date Item '+ ftitem_code +' Harus Diisi ...');
                document.getElementsByName('fdexp_dateD0[]')[j].focus();
                return false;
                }
            }
        }

    }

    return true;
}

function ValStockMasuk() {
    if(document.getElementById("ftstock_in_no").value=='') {
       alert('No. transaksi harus disi...');
       document.getElementById("ftstock_in_no").focus();
       return false;
    }
    else if(document.getElementById("ftcategory_code").value=='') {
       alert('Kategori harus disi...');
       document.getElementById("ftcategory_code").focus();
       return false;
    }
    else if(document.getElementsByName('fnindexD0[]').length==1) {
       alert('Detail transaksi belum di input ...');
       return false;
    }
    else if (StockMasukInputQty()==false) {
       return false;
    }
    
    var cattype=document.getElementById("ftcategory_code").value;
    if ((cattype=='1') || (cattype=='2') || (cattype=='3')|| (cattype=='5') || (cattype=='6') || (cattype=='7')) {
        if(document.getElementById("hidden_ftstock_in_company").value=='') {
           alert('Pemberi belum valid...');
           document.getElementById("ftstock_in_company").focus();
           return false;
        }
    }
    
    if ((cattype=='2') || (cattype=='3') || (cattype=='6') || (cattype=='7') || (cattype=='8') || (cattype=='9') || (cattype=='12')) {
        if(document.getElementById("ftdocument_no").value=='') {
           alert('No. Document harus disi...');
           document.getElementById("ftdocument_no").focus();
           return false;
        }
    }
    
    if (accessExpDate()==false) {
       return false;
    }

    ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftstock_in_no').value);
    document.getElementById("ftstock_in_no").focus();
    return false;
  
}


function RevisiStockMasuk() {
    if(document.getElementById("ftstock_in_no").value=='') {
         alert('No. transaksi harus disi...');
         document.getElementById("ftstock_in_no").focus();
         return false;
    }
    else if(document.getElementById("ftcategory_code").value=='') {
         alert('Kategori harus disi...');
         document.getElementById("ftcategory_code").focus();
         return false;
    }
    /*
    else if((document.getElementById("ftcategory_code").value!=5)&&(document.getElementById("ftcategory_code").value!=8)&&(document.getElementById("hidden_ftstock_in_company").value=='')) {
         alert('Supplier/Customer belum valid...');
         document.getElementById("ftstock_in_company").focus();
         return false;
    }*/
    else if(document.getElementsByName('fnindexD0[]').length==1) {
        alert('Detail transaksi belum di input ...');
        return false;
    }
    else if (StockMasukInputQty()==false) {
         return false;
    }

    return true;
  
}

function StockMasukRecalQty() {

    var i=document.getElementsByName('fnindexD0[]').length;
    
    var ffqty=0;
    var fcprice=0;
    var ffTotal=0;

    for(var j=1;j<i;j++) {
        ffqty=document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1;
        ffTotal=ffTotal+ffqty;
    }

    document.getElementById('fntotal_qty').value=ffTotal;
}

function StockMasukInputQty() {
    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;
        } 
        else if (document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1<=0) {
            alert('Qty tidak boleh 0..');
            document.getElementsByName('fnqtyD0[]')[j].focus();
            return false;
        }

        if (document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1>0) {
            if (document.getElementsByName('ftwarehouse_codeD0[]')[j].value=='') {
                alert('Gudang harus diisi..');
                document.getElementsByName('ftwarehouse_codeD0[]')[j].focus();
                return false;
            }
            else if (document.getElementsByName('ftlocation_codeD0[]')[j].value=='') {
                alert('Lokasi harus diisi..');
                document.getElementsByName('ftlocation_codeD0[]')[j].focus();
                return false;
            } 
            else if (document.getElementsByName('fnqty_baseD0[]')[j].value.replace(/,/g,'')*1<=0) {
                alert('Qty Base tidak boleh 0..');
                document.getElementsByName('fnqty_baseD0[]')[j].focus();
                return false;
            }
            else if (document.getElementsByName('ftuom_codeD0[]')[j].value=="") {
                alert('Satuan diisi ...');
                document.getElementsByName('ftuom_codeD0[]')[j].focus();
                return false;
            } 
        } 

    }

    return true;
}

// Stock Keluar
//--------------------------------------------------------------------
function ValStockKeluar() {
    if(document.getElementById("ftstock_out_no").value=='') {
         alert('No. transaksi harus disi...');
         document.getElementById("ftstock_out_no").focus();
         return false;
    }
    else if(document.getElementById("ftcategory_code").value=='') {
         alert('Kategori harus disi...');
         document.getElementById("ftcategory_code").focus();
         return false;
    }
    else if(document.getElementsByName('fnindexD0[]').length==1) {
        alert('Detail transaksi belum di input ...');
        return false;
    }
    else if (StockKeluarInputQty()==false) {
         return false;
    }
    
    var cattype=document.getElementById("ftcategory_code").value;
    if ((cattype=='1') || (cattype=='2') || (cattype=='3')|| (cattype=='5') || (cattype=='6') || (cattype=='9')) {
        if(document.getElementById("hidden_ftstock_out_company").value=='') {
           alert('Penerima belum valid...');
           document.getElementById("ftstock_out_company").focus();
           return false;
        }
        // tukar barang perlu no document
        else if((document.getElementById("ftdocument_no").value=='') && (cattype=='5'))  {
           alert('No. Document harus disi...');
           document.getElementById("ftdocument_no").focus();
           return false;
        }
    }
    
    if (accessExpDate()==false) {
         return false;
    }
    
    ajax_do(str_url+'&ajax=1&code=transno&fttrans_no='+document.getElementById('ftstock_out_no').value);
    document.getElementById("ftstock_out_no").focus();
    return false;
}

function RevisiStockKeluar() {
    if(document.getElementById("ftstock_out_no").value=='') {
         alert('No. transaksi harus disi...');
         document.getElementById("ftstock_out_no").focus();
         return false;
    }
     else if(document.getElementById("ftcategory_code").value=='') {
         alert('Kategori harus disi...');
         document.getElementById("ftcategory_code").focus();
         return false;
    }
    else if(document.getElementsByName('fnindexD0[]').length==1) {
        alert('Detail transaksi belum di input ...');
        return false;
    }
    else if (StockKeluarInputQty()==false) {
         return false;
    }
   
    var cattype=document.getElementById("ftcategory_code").value;
    if ((cattype=='1') || (cattype=='2') || (cattype=='3')|| (cattype=='5') || (cattype=='6') || (cattype=='9')) {
        if(document.getElementById("hidden_ftstock_out_company").value=='') {
           alert('Penerima belum valid...');
           document.getElementById("ftstock_out_company").focus();
           return false;
        }
        // tukar barang perlu no document
        else if((document.getElementById("ftdocument_no").value=='') && (cattype=='6'))  {
           alert('No. Document harus disi...');
           document.getElementById("ftdocument_no").focus();
           return false;
        }
    }
    
    return true;
}

function ValStockKeluarSetengahJadi() {
  if(document.getElementById("ftstock_out_no").value=='') {
       alert('No. transaksi harus disi...');
       document.getElementById("ftstock_out_no").focus();
       return false;
  }
   else if(document.getElementById("ftcategory_code").value=='') {
       alert('Kategori harus disi...');
       document.getElementById("ftcategory_code").focus();
       return false;
  }
  /*else if(document.getElementById("ftdocument_no").value=='') {
       alert('No. Document harus disi...');
       document.getElementById("ftdocument_no").focus();
       return false;
  } */
  else if((document.getElementById("ftcategory_code").value!=4)&&(document.getElementById("ftcategory_code").value!=5)&&(document.getElementById("hidden_ftstock_out_company").value=='')) {
       alert('Supplier/Customer belum valid...');
       document.getElementById("ftstock_out_company").focus();
       return false;
  }
  else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }

  else if (StockKeluarInputQty()==false) {
       return false;
  }
  if (accessExpDate()==false) {
       return false;
  }
  ajax_do(str_url+'&ajax=1&code=transno&fttrans_no='+document.getElementById('ftstock_out_no').value);
  document.getElementById("ftstock_out_no").focus();
  return false;
}


function ValStockKeluarSparepart() {
  if(document.getElementById("ftstock_out_no").value=='') {
       alert('No. transaksi harus disi...');
       document.getElementById("ftstock_out_no").focus();
       return false;
  }
   else if(document.getElementById("ftcategory_code").value=='') {
       alert('Kategori harus disi...');
       document.getElementById("ftcategory_code").focus();
       return false;
  }
  /* else if(document.getElementById("ftdocument_no").value=='') {
       alert('No. Document harus disi...');
       document.getElementById("ftdocument_no").focus();
       return false;
  } */
  else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }
  else if (StockKeluarInputQty()==false) {
       return false;
  }
  if (accessExpDate()==false) {
       return false;
  }
  ajax_do(str_url+'&ajax=1&code=transno&fttrans_no='+document.getElementById('ftstock_out_no').value);
  document.getElementById("ftstock_out_no").focus();
  return false;
}

function StockKeluarRecalQty() {

    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,'')*1;
        ffTotal=ffTotal+(ffqty);
    }

    document.getElementById('fntotal_qty').value=ffTotal;

}
function StockKeluarInputQty() {
    var i=document.getElementsByName('fnindexD0[]').length;
    var ffqty1=0;
    var ffqty2=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('ftitem_codeD0[]')[j].focus();
             return false;
        }
        else if (document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1>0) {
            if (document.getElementsByName('ftwarehouse_codeD0[]')[j].value=='') {
                alert('Gudang harus diisi..');
                document.getElementsByName('ftwarehouse_codeD0[]')[j].focus();
                return false; 
            } else if (document.getElementsByName('ftlocation_codeD0[]')[j].value=='') {
                alert('Lokasi harus diisi..');
                document.getElementsByName('ftlocation_codeD0[]')[j].focus();
                return false;
            } else if (document.getElementsByName('fnqty_baseD0[]')[j].value.replace(/,/g,'')*1<=0) {
                alert('Qty Base tidak boleh 0..');
                document.getElementsByName('fnqty_baseD0[]')[j].focus();
                return false;
            } else if (document.getElementsByName('ftuom_codeD0[]')[j].value=="") {
                alert('Satuan diisi ...');
                document.getElementsByName('ftuom_codeD0[]')[j].focus();
                return false;
            } else if(ffqty1>ffqty2 ) {
                alert('Qty keluar lebih besar dari Qty Available ...');
                document.getElementsByName('fnqtyD0[]')[j].focus();
                return false;
            }
        }
        // Kategori Tukar Barang bisa kirim barang secara partial atau sebagian
        else if(document.getElementById('ftcategory_code').value!='5') {
            if (document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1<=0) {
                document.getElementsByName('fnqtyD0[]')[j].focus();
                alert('Qty keluar harus diisi..');
                return false;
            }
            // MENYUSUL : coding untuk cek tidak boleh lebih dari qty stock masuk tukar barang 
            /*else if((document.getElementsByName('fnqty_sisaD0[]')[j].value.replace(/,/g,'')*1<document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1)) {
                    alert('Qty keluar lebih besar dari Qty Sisa return Penjualan...');
                    document.getElementsByName('fnqtyD0[]')[j].focus();
                    return false;
            }*/
        }
        
        // coding ini digunakan untuk apa yah ? tidak terpakai kah ?
        /* else if(document.getElementById('ftcategory_code').value=='0') {
            if((document.getElementsByName('fnqty_sisaD0[]')[j].value.replace(/,/g,'')*1<document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1)) {
                    alert('Qty keluar lebih besar dari Qty Sisa return Penjualan...');
                    document.getElementsByName('fnqtyD0[]')[j].focus();
                    return false;
            }
        }*/
    }

    return true;
}

function FinalStockKeluarSetengahJadi() {

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

  else if(document.getElementById("ftcategory_code").value=='') {
       alert('Kategori harus disi...');
       document.getElementById("ftcategory_code").focus();
       return false;
  }

  else if(document.getElementById("ftdocument_no").value=='') {
       alert('No. Document harus disi...');
       document.getElementById("ftdocument_no").focus();
       return false;
  }

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

  else if (StockKeluarInputQty()==false) {
       return false;
  }

  return true;
}

// Mutasi Barang
function ValMutasiBarang() {
    if(document.getElementById("ftstock_mutation_no").value=='') {
         alert('No. transaksi harus disi...');
         document.getElementById("ftstock_mutation_no").focus();
         return false;
    }
     else if(document.getElementsByName('fnindexD0[]').length==1) {
        alert('Detail transaksi belum di input ...');
        return false;
    }
    else if (StockMutasiInputQty()==false) {
         return false;
    }
    if (accessExpDate()==false) {
         return false;
    }

    ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftstock_mutation_no').value);
    document.getElementById("ftstock_mutation_no").focus();
    return false;
}

function RevisiMutasiBarang() {
    if(document.getElementById("ftstock_mutation_no").value=='') {
         alert('No. transaksi harus disi...');
         document.getElementById("ftstock_mutation_no").focus();
         return false;
    }
     else if(document.getElementsByName('fnindexD0[]').length==1) {
        alert('Detail transaksi belum di input ...');
        return false;
    }
    else if (StockMutasiInputQty()==false) {
         return false;
    }
    
    return true;
}

function ValMutasiBarangSparepart() {
  if(document.getElementById("ftstock_mutation_no").value=='') {
       alert('No. transaksi harus disi...');
       document.getElementById("ftstock_mutation_no").focus();
       return false;
  }
   else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }
  else if (StockMutasiInputQty()==false) {
       return false;
  }
  if (accessExpDate()==false) {
       return false;
  }

   ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftstock_mutation_no').value);
   document.getElementById("ftstock_mutation_no").focus();
    return false;
}

function StockMutasiInputQty() {
    var i=document.getElementsByName('fnindexD0[]').length;
    var ffqty1=0;
    var ffqty2=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('ftitem_codeD0[]')[j].focus();
            return false;
        }
        else if  (document.getElementsByName('ftwarehouse_fromD0[]')[j].value=='') {
            alert('Gudang Asal harus diisi...');
             document.getElementsByName('ftwarehouse_fromD0[]')[j].focus();
            return false;
        }
        else if  (document.getElementsByName('ftlocation_fromD0[]')[j].value=='') {
            alert('Lokasi Asal harus diisi...');
             document.getElementsByName('ftlocation_fromD0[]')[j].focus();
            return false;
        }
        else if  (document.getElementsByName('ftwarehouse_toD0[]')[j].value=='') {
            alert('Gudang Tujuan harus diisi...');
             document.getElementsByName('ftwarehouse_toD0[]')[j].focus();
            return false;
        }
        else if  (document.getElementsByName('ftlocation_toD0[]')[j].value=='') {
            alert('Lokasi Tujuan harus diisi...');
             document.getElementsByName('ftlocation_toD0[]')[j].focus();
            return false;
        }
        // else if ( (document.getElementsByName('ftwarehouse_fromD0[]')[j].value==document.getElementsByName('ftwarehouse_fromD0[]')[j].value)&&(document.getElementsByName('ftlocation_fromD0[]')[j].value==document.getElementsByName('ftlocation_toD0[]')[j].value)) {
        else if (document.getElementsByName('ftlocation_fromD0[]')[j].value==document.getElementsByName('ftlocation_toD0[]')[j].value) {
            document.getElementsByName('ftlocation_toD0[]')[j].focus();
            alert('Gudang dan lokasi asal tidak boleh sama dengan gudang dan lokasi tujuan ...');
            return false;
        }
        else if (ffqty2 <= 0) {
             document.getElementsByName('ftitem_codeD0[]')[j].focus();
             alert('Qty Avail barang tidak mencukupi..');
             return false;
        } 
        else if (ffqty1 <= 0) {
             document.getElementsByName('fnqtyD0[]')[j].focus();
             alert('Qty mutasi harus diisi..');
             return false;
        }
        else if(ffqty1>ffqty2 ) {
            alert('Qty mutasi lebih besar dari Qty Avail...');
            document.getElementsByName('fnqtyD0[]')[j].focus();
            return false;
        } 
        else if (document.getElementsByName('fnqty_baseD0[]')[j].value.replace(/,/g,'')*1<=0) {
            alert('Qty Base tidak boleh 0..');
            document.getElementsByName('fnqty_baseD0[]')[j].focus();
            return false;
        }

        for(var k=j+1;k<i;k++) {
            if ((document.getElementsByName('ftitem_codeD0[]')[j].value==document.getElementsByName('ftitem_codeD0[]')[k].value) &&
                (document.getElementsByName('ftwarehouse_fromD0[]')[j].value==document.getElementsByName('ftwarehouse_fromD0[]')[k].value) &&
                (document.getElementsByName('ftwarehouse_toD0[]')[j].value==document.getElementsByName('ftwarehouse_toD0[]')[k].value) &&
                (document.getElementsByName('ftlocation_fromD0[]')[j].value==document.getElementsByName('ftlocation_fromD0[]')[k].value) &&
                (document.getElementsByName('ftlocation_toD0[]')[j].value==document.getElementsByName('ftlocation_toD0[]')[k].value)) {
                    alert('Kode Barang yang sama tidak bisa ke gudang dan lokasi yang sama ');
                    document.getElementsByName('ftitem_codeD0[]')[j].focus();
                    return false;
                }
        }

    }

    return true;
}

function FinalPenyesuaianBarang() {
    if(document.getElementById("ftstock_adjustment_no").value=='') {
        alert('No. transaksi harus disi...');
        document.getElementById("ftstock_adjustment_no").focus();
        return false;
    }
    else if(document.getElementsByName('fnindexD0[]').length==1) {
        alert('Detail transaksi belum di input ...');
        return false;
    }
    else if (StockPenyesuaianInputQty()==false) {
        return false;
    }

    return true;
}

//Penyesuaian Barang
function ValPenyesuaianBarang() {
  if(document.getElementById("ftstock_adjustment_no").value=='') {
       alert('No. transaksi harus disi...');
       document.getElementById("ftstock_adjustment_no").focus();
       return false;
  }
   else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }
  else if (StockPenyesuaianInputQty()==false) {
       return false;
  }
  if (accessExpDate()==false) {
       return false;
  }

    ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftstock_adjustment_no').value);
    document.getElementById("ftstock_adjustment_no").focus();
    return false;
}

function ValPenyesuaianBarangSparepart() {
  if(document.getElementById("ftstock_adjustment_no").value=='') {
       alert('No. transaksi harus disi...');
       document.getElementById("ftstock_adjustment_no").focus();
       return false;
  }
   else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }
  else if (StockPenyesuaianInputQty()==false) {
       return false;
  }
  if (accessExpDate()==false) {
       return false;
  }

    ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftstock_adjustment_no').value);
   document.getElementById("ftstock_adjustment_no").focus();
    return false;
}

function FinalPenyesuaianBarangSparepart() {
    if(document.getElementById("ftstock_adjustment_no").value=='') {
        alert('No. transaksi harus disi...');
        document.getElementById("ftstock_adjustment_no").focus();
        return false;
    }
    else if(document.getElementsByName('fnindexD0[]').length==1) {
        alert('Detail transaksi belum di input ...');
        return false;
    }
    else if (StockPenyesuaianInputQty()==false) {
        return false;
    }

    return true;
}

function StockPenyesuaianRecalQty() {

    var i=document.getElementsByName('fnindexD0[]').length;
    var ffAvail=0;
    var ffqty=0;
    var ffOpname=0;
    for(var j=1;j<i;j++) {
        if(document.getElementsByName('fnqty_opnameD0[]')[j].value.replace(/,/g,'')*1<0) {
            document.getElementsByName('fnqtyD0[]')[j].value='0';
        }
        else {
              ffAvail=document.getElementsByName('fnqty_availableD0[]')[j].value.replace(/,/g,'')*1
              ffOpname=document.getElementsByName('fnqty_opnameD0[]')[j].value.replace(/,/g,'')*1;
              document.getElementsByName('fnqtyD0[]')[j].value= ffOpname-ffAvail;
        }
    }

}

function StockPenyesuaianRecalQty1(j) {
        var ffAvail=0;
        var ffqty=0;
        var ffOpname=0;
        ffAvail=document.getElementById('fnqty_availableD0'+j).value.replace(/,/g,'')*1;
        ffOpname=document.getElementById('fnqty_opnameD0'+j).value.replace(/,/g,'')*1 ;
        document.getElementById('fnqtyD0'+j).value= ffOpname-ffAvail;

    }



function StockPenyesuaianInputQty() {
    var i=document.getElementsByName('fnindexD0[]').length;
    for(var j=1;j<i;j++) {
        if (document.getElementsByName('hidden_ftitem_codeD0[]')[j].value=='') {
             document.getElementsByName('ftitem_codeD0[]')[j].focus();
             alert('Kode Barang belum valid..');
             return false;
        }
        else if (document.getElementsByName('ftwarehouse_codeD0[]')[j].value=='') {
             document.getElementsByName('ftwarehouse_codeD0[]')[j].focus();
             alert('Gudang harus diisi..');
             return false;
        }
        else if (document.getElementsByName('ftlocation_codeD0[]')[j].value=='') {
             document.getElementsByName('ftlocation_codeD0[]')[j].focus();
             alert('Lokasi harus diisi..');
             return false;
        }
        else if (document.getElementsByName('fnqty_opnameD0[]')[j].value.replace(/,/g,'')*1<0) {
             document.getElementsByName('fnqty_opnameD0[]')[j].focus();
             alert('QtyOpname harus diisi..');
             return false;
        }
        /*
        else if (document.getElementsByName('fnqty_availableD0[]')[j].value.replace(/,/g,'')*1<0) {
             document.getElementsByName('fnqty_availableD0[]')[j].focus();
             alert('Tidak bisa penyesuaian stock minus. ');
             return false;
        }
        */
        for(var k=j+1;k<i;k++) {
            if ((document.getElementsByName('ftitem_codeD0[]')[j].value==document.getElementsByName('ftitem_codeD0[]')[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)) {
                    alert('Kode Barang yang sama tidak bisa ke gudang dan lokasi yang sama ');
                    document.getElementsByName('ftitem_codeD0[]')[j].focus();
                    return false;
                }
        }
    }
    return true;

}

// Delivery Order
function ValDeliveryOrder() {
    if(document.getElementById("ftdo_no").value=='') {
        alert('No. transaksi harus disi...');
        document.getElementById("ftdo_no").focus();
        return false;
    }
    else  if(document.getElementById("ftdo_type").value=='') {
        alert('Tipe DO harus di pilih ...');
        document.getElementById("ftdo_type").focus();
        return false;
    }
    else if(document.getElementById("hidden_ftcustomer_code").value=='') {
        alert('Customer belum valid ...');
        document.getElementById("ftcustomer_code").focus();
        return false;
    }
    else  if(document.getElementById("ftdelivery_method").value=='') {
        alert('Metode Pengiriman harus di pilih ...');
        document.getElementById("ftdelivery_method").focus();
        return false;
    }
    else if(document.getElementsByName('fnindexD0[]').length==1) {
        alert('Detail transaksi belum di input ...');
        return false;
    }
    else if (DeliveryOrderInputQty()==false) {
        return false;
    }

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

    return false;
}

function FinalDeliveryOrder() {
  if(document.getElementById("ftdo_no").value=='') {
      alert('No. transaksi harus disi...');
      document.getElementById("ftdo_no").focus();
      return false;
  }
  else  if(document.getElementById("hidden_ftcustomer_code").value=='') {
      alert('Customer belum valid ...');
      document.getElementById("ftcustomer_code").focus();
      return false;
  }
    else  if(document.getElementById("ftdelivery_method").value=='') {
      alert('Metode Pengiriman harus di pilih ...');
      document.getElementById("ftdelivery_method").focus();
      return false;
  }
   else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }
  else if (DeliveryOrderInputQty()==false) {
       return false;
  }
  return true;
}

function DeliveryOrderRecalQtyBase() {
    var i=document.getElementsByName('fnindexD0[]').length;
    var ffqty=0;
    for(var j=1;j<i;j++) {
		fnqtyD= document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1;
		ffformulaD=document.getElementsByName('ffformulaD0[]')[j].value.replace(/,/g,'')*1;
		fnqty_baseD=(fnqtyD*ffformulaD);
		document.getElementsByName('fnqty_baseD0[]')[j].value=fnqty_baseD;
    }
	// document.getElementById('fftotal_qty_base').value=fnqty_baseD;
}
function DeliveryOrderRecalQty() {

    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,'')*1;
        ffTotal=ffTotal+(ffqty*1);
    }
    document.getElementById('fftotal_qty').value=ffTotal;

}
function DeliveryOrderInputQty() {
    var i=document.getElementsByName('fnindexD0[]').length;
    var ffqty1=0;
    var ffqty2=0;
    var m=0;
    ffqty1=ffqty1*1;
    ffqty2=ffqty2*1;

    DeliveryOrderRecalQty();
    DeliveryOrderRecalQtyBase();

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

    if(m==1) {
        alert('Qty Barang tidak boleh lebih besar dari Qty Tersedia');
        return false;
    }

    return true;
}

// Rekap Delivery Order
function ValRekapDeliveryOrder() {
  if(document.getElementById("ftrekap_do_no").value=='') {
      alert('No. Transaksi harus disi...');
      document.getElementById("ftrekap_do_no").focus();
      return false;
  }
  else  if(document.getElementById("hidden_ftcustomer_code").value=='') {
      alert('Customer belum valid ...');
      document.getElementById("ftcustomer_code").focus();
      return false;
  }
  else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }
  else if (RekapDeliveryOrderInputQty()==false) {
       return false;
  }

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

  return false;
}

// Detail Rekap Delivery Order
function RekapDeliveryOrderInputQty() {
    var i=document.getElementsByName('fnindexD0[]').length;
    /*var ffqty1=0;
    var ffqty2=0;
    var m=0;
    ffqty1=ffqty1*1;
    ffqty2=ffqty2*1;
    
        ffqty1=document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1;
        ffqty2=document.getElementsByName('fnqty_availableD0[]')[j].value.replace(/,/g,'')*1*/
	for(var j=1;j<i;j++) {
    if (document.getElementsByName('ftdo_noD0[]')[j].value=='') {
		 alert('No. Do belum valid..');
		document.getElementsByName('ftdo_noD0[]')[j].focus();
		 return false;
    }
    else if (document.getElementsByName('ftdo_typeD0[]')[j].value=='') {
		 alert('Tipe Surat Jalan belum valid..');
		document.getElementsByName('ftdo_typeD0[]')[j].focus();
		 return false;
    }
}
    return true;
}


//saldo awal hutang
function ValSaldoAwalHutang() {
    document.getElementById("fnsaldo_awal").value='1';

    if(document.getElementById("ftpurchase_invoice_no").value=='') {
        alert('No. transaksi harus disi...');
        document.getElementById("ftpurchase_invoice_no").focus();
        return false;
    }
    /*else if(document.getElementById("hidden_ftsupplier_code").value=='') {
        alert('No. Supplier belum valid...');
        document.getElementById("ftsupplier_code").focus();
        return false;
    }*/
    else if(document.getElementById("ftsupplier_code").value=='') {
        alert('No. Supplier belum valid...');
        document.getElementById("ftsupplier_code").focus();
        return false;
    }
     else if(document.getElementById('fcamount').value.replace(/,/g,'')*1<=0) {
        alert('Jumlah Hutang harus disi...');
        document.getElementById("fcamount").focus();
        return false;
    }
      ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftpurchase_invoice_no').value);

  return false;
}

function ValSaldoAwalHutang1() {

    document.getElementById('fcoutstanding_amount').value= document.getElementById('fcamount').value;
    ElementCurrencyALL();
}


function ValSaldoAwalPiutang() {
    document.getElementById("fnsaldo_awal").value='1';

    if(document.getElementById("ftsales_invoice_no").value=='') {
        alert('No. Invoice harus disi...');
        document.getElementById("ftsales_invoice_no").focus();
        return false;
    }
    else if(document.getElementById("ftcustomer_code").value=='') {
        alert('No. Customer belum valid...');
        document.getElementById("ftcustomer_code").focus();
        return false;
    }
     else if(document.getElementById('fcamount').value.replace(/,/g,'')*1<=0) {
        alert('Jumlah Piutang harus disi...');
        document.getElementById("fcamount").focus();
        return false;
    }
      ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftsales_invoice_no').value);

  return false;
}


function ValSaldoAwalPiutang1() {

    document.getElementById('fcoutstanding_amount').value= document.getElementById('fcamount').value;
      ElementCurrencyALL();
}

function ValSalesOrder() {

    if(document.getElementById("ftso_no").value=='') {
        alert('No. transaksi harus diisi...');
        document.getElementById("ftso_no").focus();
        return false;
    }
    else if(document.getElementById("hidden_ftcustomer_code").value=='') {
        alert('Customer belum valid ...');
        document.getElementById("ftcustomer_code").focus();
        return false;
    }
    else if(document.getElementById("ftsales_code").value=='') {
        alert('Salesman belum valid ...');
        document.getElementById("ftsales_code").focus();
        return false;
    }
    /* else if(document.getElementById("ftdelivery_method").value=='') {
        alert('Metode pengiriman harus diisi ...');
        document.getElementById("ftdelivery_method").focus();
        return false;
    } */
    else if(document.getElementById("ftcurrency_code").value=='') {
        alert('Mata uang harus diisi ...');
        document.getElementById("ftcurrency_code").focus();
        return false;
    }
    else if(document.getElementById("fcrate").value=='') {
        alert('Kurs harus diisi ...');
        document.getElementById("fcrate").focus();
        return false;
    }
    else if(document.getElementById("fntax_code").value=='') {
        alert('Kode pajak harus diisi ...');
        document.getElementById("fntax_code").focus();
        return false;
    }
    else if(document.getElementById("fnpayment_status").value=='') {
        alert('Status pembayaran harus diisi ...');
        document.getElementById("fnpayment_status").focus();
        return false;
    }
    else if(document.getElementById("fntax_code").value=='') {
        alert('Kode Pajak harus disi...');
        document.getElementById("fntax_code").focus();
        return false;
    }
    else if(document.getElementById('ffdiscount').value.replace(/,/g,'')*1 > 100) {
        alert('Discount tidak boleh lebih dari 100 ...');
        document.getElementById('ffdiscount').focus();
        return false;
    }
    else if(document.getElementsByName('fnindexD0[]').length<1) {
        alert('Detail transaksi harus disi...');
        return false;
    }
    else if (SalesOrderInputQty()==false) {
         return false;
    }

    if(document.getElementById('fcamount').value.replace(/,/g,'')*1 == 0) {
        if(!confirm('Total Harga sebesar 0 Rupiah. ANDA YAKIN ?')) {
            document.getElementById('fcamount').focus();
            return false;
        }
    }
    
    ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftso_no').value + '&ftcustomer_code=' + document.getElementById('ftcustomer_code').value + '&fcamount=' + document.getElementById('fcamount').value + '&fdtrans_date=' + document.getElementById('fdtrans_date').value);

  return false;

}

function SalesOrderRecalQty() {

    var i=document.getElementsByName('fnindexD0[]').length;
    var fnqtyD=0;
    var fcpriceD=0;
    var fcpricetempD=0;
    var ffdiscountD=0;
    var fcdiscountD=0;
    var fcamountD=0;

    var fcpayment_amount=0;
    var fcoutstanding_amount=0;
    var fcsub_amount=0;
    var fcsub_amounttemp=0;
    var ffdiscount=0;
    var fcdiscount=0;
    var fcother_cost=0;
    var ffvat=0;
    var fcvat=0;
    var fcamount=0;

    
    for(var j=0;j<i;j++) {
        fnqtyD=document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1;
        fcpriceD=document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1;
        fcpricetempD=document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1;
        ffdiscountD=document.getElementsByName('ffdiscountD0[]')[j].value;
        //ffdiscountD=document.getElementsByName('ffdiscountD0[]')[j].value.replace(/,/g,'')*1;var str_ffdiscountD = ffdiscountD + '';
        var str_ffdiscountD = ffdiscountD + '';
        str_ffdiscountD = str_ffdiscountD.split('+');
 
        for(var i = 0; i < str_ffdiscountD.length; i++) {
            // Trim the excess whitespace.
            str_ffdiscountD[i] = str_ffdiscountD[i].replace(/^\s*/, "").replace(/\s*$/, "");
            fcpricetempD = fcpricetempD - (fcpricetempD * (str_ffdiscountD[i]/100));
        } 
        fcdiscountD = (fnqtyD * fcpricetempD);
   
        //fcdiscountD=(fnqtyD*fcpriceD)*(ffdiscountD/100);
        //fcdiscountD=Math.round(fcdiscountD*100)/100;
        //fcamountD=Math.round((fnqtyD*fcpriceD)*100/100);
        fcamountD=(fnqtyD*fcpriceD);
        fcamountD=fcamountD-fcdiscountD;
        //fcamountD=Math.round((fcamountD)*100/100);
        fcsub_amount+=fcamountD;
        document.getElementsByName('fcdiscountD0[]')[j].value=fcdiscountD;
        document.getElementsByName('fcamountD0[]')[j].value=fcamountD;
    }
    document.getElementById('fcsub_amount').value=fcsub_amount;
    
    ffdiscount=document.getElementById('ffdiscount').value;
    // ffdiscount=document.getElementById('ffdiscount').value.replace(/,/g,'')*1;
    
    // tier discount 
    var str_ffdiscount = ffdiscount + '';
    str_ffdiscount = str_ffdiscount.split('+');
 
    for(var i = 0; i < str_ffdiscount.length; i++) {
        // Trim the excess whitespace.
        str_ffdiscount[i] = str_ffdiscount[i].replace(/^\s*/, "").replace(/\s*$/, "");
        fcdiscount = fcdiscount + (fcsub_amounttemp * (str_ffdiscountD[i]/100));
        fcsub_amounttemp = fcsub_amounttemp - (fcsub_amounttemp * (str_ffdiscount[i]/100));
    } 
    
    //fcdiscount=fcsub_amount*ffdiscount/100;
    //fcdiscount=Math.round((fcdiscount)*100/100);

    ffvat= document.getElementById('ffvat').value*1;
    fcvat=fcsub_amount*ffvat/100;
    //fcvat=Math.round((fcvat)*100/100);

    fcother_cost=document.getElementById('fcother_cost').value.replace(/,/g,'')*1;
    //fcother_cost=Math.round((fcother_cost)*100/100);

    fcamount=(fcsub_amount-fcdiscount)+fcvat+fcother_cost;
    fcamount=Math.round((fcamount)*100/100);
    fcoutstanding_amount=fcamount;
    fcpayment_amount=0;

    document.getElementById('fcdiscount').value=fcdiscount;
    document.getElementById('fcvat').value=fcvat;
    document.getElementById('fcamount').value=fcamount;
    document.getElementById('fcoutstanding_amount').value=fcoutstanding_amount;
    document.getElementById('fcpayment_amount').value=fcpayment_amount;

    ElementCurrencyALL();

    return true;
}

function SalesOrderRecalPrice() {
    SalesOrderRecalQty0();

}

function SalesOrderRecalDiscPercent() {
    var fcsub_amount=document.getElementById('fcsub_amount').value.replace(/,/g,'')*1;
    var ffdiscount=document.getElementById('ffdiscount').value;
    //var ffdiscount=document.getElementById('ffdiscount').value.replace(/,/g,'')*1;
    var fcdiscount=0;
    //var fcdiscount=fcsub_amount*ffdiscount/100;
    //fcdiscount=Math.round((fcdiscount)*100/100);
    
    // tier discount 
    var str_ffdiscount = ffdiscount + '';
    var str_ffdiscount = str_ffdiscount.split('+');
    
    for(var i = 0; i < str_ffdiscount.length; i++) {
        // Trim the excess whitespace.
        str_ffdiscount[i] = str_ffdiscount[i].replace(/^\s*/, "").replace(/\s*$/, "");
        fcdiscount = fcdiscount + (fcsub_amount * (str_ffdiscount[i]/100));
        fcsub_amount = fcsub_amount - (fcsub_amount * (str_ffdiscount[i]/100));
    }
    
    document.getElementById('fcdiscount').value=fcdiscount;
 
    ElementCurrencyOnBlur(document.getElementById('fcdiscount'));
    SalesOrderRecalQty0();
}

function SalesOrderRecalDiscRp() {
      var fcsub_amount=document.getElementById('fcsub_amount').value.replace(/,/g,'')*1;
      var fcdiscount=document.getElementById('fcdiscount').value.replace(/,/g,'')*1;
      var ffdiscount=(fcdiscount/(fcsub_amount))*100;

       //ffdiscount=Math.round((ffdiscount)*100/100);
      document.getElementById('ffdiscount').value=ffdiscount;
      //ElementCurrencyOnBlur(document.getElementById('ffdiscount'));
      SalesOrderRecalQty0();

}

function SalesOrderRecalDiscDetailPercent(index) {
    var fnqtyD=0;
    fnqtyD=document.getElementById('fnqtyD0'+index).value.replace(/,/g,'')*1;
    var fcpriceD=document.getElementById('fcpriceD0'+index).value.replace(/,/g,'')*1;
    var ffdiscountD=document.getElementById('ffdiscountD0'+index).value;
    //var ffdiscountD=document.getElementById('ffdiscountD0'+index).value.replace(/,/g,'')*1;
    var fcdiscountD=0;
    //var fcdiscountD=(fnqtyD*fcpriceD)*(ffdiscountD/100);
    //fcdiscountD=Math.round((fcdiscountD)*100/100);

    // tier discount 
    var str_ffdiscountD = ffdiscountD + '';
    var str_ffdiscountD = str_ffdiscountD.split('+');
 
    for(var i = 0; i < str_ffdiscountD.length; i++) {
        // Trim the excess whitespace.
        str_ffdiscountD[i] = str_ffdiscountD[i].replace(/^\s*/, "").replace(/\s*$/, "");
        fcdiscountD = fcdiscountD + (fcpriceD * (str_ffdiscountD[i]/100));
        fcpriceD = fcpriceD - (fcpriceD * (str_ffdiscountD[i]/100));
    }
    fcdiscountD = (fnqtyD * fcdiscountD);
   
    document.getElementById('fcdiscountD0'+index).value=fcdiscountD;      
    SalesOrderRecalQty0();

}

function SalesOrderRecalDiscDetailRp(index) {
       var fnqtyD=0;
       fnqtyD=document.getElementById('fnqtyD0'+index).value.replace(/,/g,'')*1;
       var fcpriceD=document.getElementById('fcpriceD0'+index).value.replace(/,/g,'')*1;
       var fcdiscountD= document.getElementById('fcdiscountD0'+index).value.replace(/,/g,'')*1;
       var ffdiscountD=(fcdiscountD/(fnqtyD*fcpriceD))*100;
       //ffdiscountD=Math.round((ffdiscountD)*100/100);
       document.getElementById('ffdiscountD0'+index).value=ffdiscountD;      
       SalesOrderRecalQty0();

}

function SalesOrderRecalQty0() {
    
    var i=document.getElementsByName('fnindexD0[]').length;
    
    var fnqtyD=0;
    var fcpriceD=0;
    var fcpricetempD=0;
    var ffdiscountD=0;
    var fcdiscountD=0;
    var fcamountD=0;

    var fcpayment_amount=0;
    var fcoutstanding_amount=0;
    var fftotal_qty=0;
    var fcsub_amount=0;
    var fcsub_amounttemp=0;
    var ffdiscount=0;
    var fcdiscount=0;
    var fcother_cost=0;
    var ffvat=0;
    var fcvat=0;
    var fcamount=0;

    for(var j=0;j<i;j++) {
        fnqtyD=document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1;
        fcpriceD=document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1;
        fcdiscountD=document.getElementsByName('fcdiscountD0[]')[j].value.replace(/,/g,'')*1;
         
        //fcamountD=Math.round(((fnqtyD*fcpriceD )-fcdiscountD)*100/100);
        fcamountD=(fnqtyD*fcpriceD )-fcdiscountD;
        document.getElementsByName('fcamountD0[]')[j].value=fcamountD;
        fftotal_qty+= document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1;
        fcsub_amount+= document.getElementsByName('fcamountD0[]')[j].value.replace(/,/g,'')*1;
    }
    document.getElementById('fftotal_qty').value=fftotal_qty;
    document.getElementById('fcsub_amount').value=fcsub_amount;
   
    fcdiscount=document.getElementById('fcdiscount').value.replace(/,/g,'')*1;

    fcother_cost=document.getElementById('fcother_cost').value.replace(/,/g,'')*1;
    //fcother_cost=Math.round((fcother_cost)*100/100);

    fcamount=(fcsub_amount-fcdiscount)+fcother_cost;

    ffvat= document.getElementById('ffvat').value.replace(/,/g,'')*1;
    fcvat=fcamount*ffvat/100;
    //fcvat=Math.round((fcvat)*100/100);

    fcamount=fcamount+fcvat;
    //fcamount=Math.round((fcamount)*100/100);

    fcoutstanding_amount=fcamount;
    fcpayment_amount=0;

    document.getElementById('fcvat').value=fcvat;
    document.getElementById('fcamount').value=fcamount;
    document.getElementById('fcoutstanding_amount').value=fcoutstanding_amount;
    //document.getElementById('fcpayment_amount').value=fcpayment_amount;
    
    ElementCurrencyALL();
    return true;
}

function SalesOrderInputQty() {
    var m="";
    var n="";
        
    // validasi untuk gudang,lokasi,qty available ada di modules_process tergantung system setting

    var i=document.getElementsByName('fnindexD0[]').length;
    for(var j=1;j<i;j++) {
        if (document.getElementsByName('ftitem_codeD0[]')[j].value=="") {
              alert('Kode barang harus diisi ...');
              document.getElementsByName('ftitem_codeD0[]')[j].focus();
              return false;
        }
        else if (document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1 == 0) {
              alert('Qty harus diisi ...');
              document.getElementsByName('fnqtyD0[]')[j].focus();
              return false;
        }
        else if (document.getElementsByName('fnqty_baseD0[]')[j].value.replace(/,/g,'')*1 == 0) {
              document.getElementsByName('fnqtyD0[]')[j].value = 0;
              alert('Perhitungan formula tidak cocok. Harap input qty kembali ...');
              document.getElementsByName('fnqtyD0[]')[j].focus();
              return false;
        }
        else if (document.getElementsByName('ftuom_codeD0[]')[j].value=="") {
              alert('Satuan diisi ...');
              document.getElementsByName('ftuom_codeD0[]')[j].focus();
              return false;
        }
        /* else if (document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1<=0) {
              alert('Harga harus diisi ...');
              document.getElementsByName('fcpriceD0[]')[j].focus();
              return false;
        } 
        else if (document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1 < document.getElementsByName('fcold_priceD0[]')[j].value.replace(/,/g,'')*1) {
              alert('Harga barang tidak boleh lebih kecil dari harga jual sebelumnya ...');
              document.getElementsByName('fcpriceD0[]')[j].focus();
              return false;
        } */
        else if (document.getElementsByName('ffdiscountD0[]')[j].value.replace(/,/g,'')*1>100) {
              alert('Discount tidak boleh lebih dari 100 ...');
              document.getElementsByName('ffdiscountD0[]')[j].focus();
              return false;
        }
        else if (document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1==0) {
            n=n+ document.getElementsByName('ftitem_codeD0[]')[j].value +'\n';
        }
    }

    if(n!="") {
           if(confirm('Harga barang berikut GRATIS :\n------------------------------------ \n '+n+'-------------------------------\n Apakah transaksi akan diteruskan??')) {
                    return true;
            }
            else {
                  return false;
            }
    }
    else if(m!="") {
           if(confirm('Harga barang berikut lebih kecil dari harga jual :\n------------------------------------ \n '+m+'-------------------------------\n Apakah transaksi akan diteruskan??')) {
                    return true;
            }
            else {
                  return false;
            }
    }
    return true;
}

function FinalSalesOrder() {
    if(document.getElementById("ftso_no").value=='') {
        alert('No. transaksi harus disi...');
        document.getElementById("ftso_no").focus();
        return false;
    }
    else if(document.getElementsByName('fntax_code').value=='') {
        alert('Kode Pajak harus disi...');
        return false;
    }
    else if(document.getElementsByName('fnindexD0[]').length<1) {
        alert('Detail transaksi harus disi...');
        return false;
    }
    else if (SalesOrderInputQty()==false) {
         return false;
    }

    ajax_do(str_url + '&ajax=1&code=creditlimit&fttrans_no=' + document.getElementById('ftso_no').value + '&ftcustomer_code=' + document.getElementById('ftcustomer_code').value + '&fcamount=' + document.getElementById('fcamount').value);

  return false;
}

function RevisiSalesOrder() {

    if(document.getElementById("ftso_no").value=='') {
        alert('No. transaksi harus diisi...');
        document.getElementById("ftso_no").focus();
        return false;
    }
    else if(document.getElementById("hidden_ftcustomer_code").value=='') {
        alert('Customer belum valid ...');
        document.getElementById("ftcustomer_code").focus();
        return false;
    }
    else if(document.getElementById("ftsales_code").value=='') {
        alert('Salesman belum valid ...');
        document.getElementById("ftsales_code").focus();
        return false;
    }
    /* else if(document.getElementById("ftdelivery_method").value=='') {
        alert('Metode pengiriman harus diisi ...');
        document.getElementById("ftdelivery_method").focus();
        return false;
    } */
    else if(document.getElementById("ftcurrency_code").value=='') {
        alert('Mata uang harus diisi ...');
        document.getElementById("ftcurrency_code").focus();
        return false;
    }
    else if(document.getElementById("fcrate").value=='') {
        alert('Kurs harus diisi ...');
        document.getElementById("fcrate").focus();
        return false;
    }
    else if(document.getElementById("fntax_code").value=='') {
        alert('Kode pajak harus diisi ...');
        document.getElementById("fntax_code").focus();
        return false;
    }
    else if(document.getElementById("fnpayment_status").value=='') {
        alert('Status pembayaran harus diisi ...');
        document.getElementById("fnpayment_status").focus();
        return false;
    }
    else if(document.getElementById("fntax_code").value=='') {
        alert('Kode Pajak harus disi...');
        document.getElementById("fntax_code").focus();
        return false;
    }
    else if(document.getElementById('ffdiscount').value.replace(/,/g,'')*1 > 100) {
        alert('Discount tidak boleh lebih dari 100 ...');
        document.getElementById('ffdiscount').focus();
        return false;
    }
    else if(document.getElementsByName('fnindexD0[]').length<1) {
        alert('Detail transaksi harus disi...');
        return false;
    }
    else if (SalesOrderInputQty()==false) {
         return false;
    }

    if(document.getElementById('fcamount').value.replace(/,/g,'')*1 == 0) {
        if(!confirm('Total Harga sebesar 0 Rupiah. ANDA YAKIN ?')) {
            document.getElementById('fcamount').focus();
            return false;
        }
    }
    
    return true;
}

//--------------------------------------------
//Sales Invoice

function ValSalesInvoice() {

    if(document.getElementById("ftsales_invoice_no").value=='') {
        alert('No. transaksi harus disi...');
        document.getElementById("ftsales_invoice_no").focus();
        return false;
    }
    // else if(document.getElementById("fntax_code").value!='1') {
    //    if(document.getElementById("ftvat_no").value=='') {
    //        alert('No. faktur pajak harus disi...');
    //        document.getElementById("ftvat_no").focus();
    //        return false;
    //    }
    //}  
    else if(document.getElementById("hidden_ftcustomer_code").value=='') {
      alert('Customer belum valid ...');
      document.getElementById("ftcustomer_code").focus();
      return false;
    }
    else if(document.getElementsByName('fnindexD0[]').length<1) {
        alert('Detail transaksi harus disi...');
        return false;
    }
    else if (SalesInvoiceInputQty()==false) {
         return false;
    }

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

  return false;

}

function SalesInvoiceRecalQty() {

    var i=document.getElementsByName('fnindexD0[]').length;
    var fnqtyD=0;
    var fcpriceD=0;
    var ffdiscountD=0;
    var fcdiscountD=0;
    var fcamountD=0;

    var fcpayment_amount=0;
    var fcoutstanding_amount=0;
    var fcsub_amount=0;
    var ffdiscount=0;
    var fcdiscount=0;
    var fcother_cost=0;
    var ffvat=0;
    var fcvat=0;
    var fcamount=0;

    for(var j=0;j<i;j++) {

//        if(document.getElementsByName('ftstock_category_codeD[]')[j].value=='inv') {
              fnqtyD=document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1;
//        }
//        else {
//            fnqtyD=1;
//        }
        fcpriceD=document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1;
        ffdiscountD=document.getElementsByName('ffdiscountD0[]')[j].value.replace(/,/g,'')*1;
        fcdiscountD=(fnqtyD*fcpriceD)*(ffdiscountD/100);
        //fcdiscountD=Math.round(fcdiscountD*100)/100;
        fcamountD=fnqtyD*fcpriceD;
        fcamountD=fcamountD-fcdiscountD;
        //fcamountD=Math.round((fcamountD)*100/100);
        fcsub_amount+=fcamountD;
        document.getElementsByName('fcdiscountD0[]')[j].value=fcdiscountD;
        document.getElementsByName('fcamountD0[]')[j].value=fcamountD;
       
    }
    document.getElementById('fcsub_amount').value=fcsub_amount;
    ffdiscount=document.getElementById('ffdiscount').value.replace(/,/g,'')*1;
    fcdiscount=fcsub_amount*ffdiscount/100;
    //fcdiscount=Math.round((fcdiscount)*100/100);

    ffvat= document.getElementById('ffvat').value*1;
    fcvat=fcsub_amount*ffvat/100;
    //fcvat=Math.round((fcvat)*100/100);

    fcother_cost=document.getElementById('fcother_cost').value.replace(/,/g,'')*1;
    //fcother_cost=Math.round((fcother_cost)*100/100);

    fcamount=(fcsub_amount-fcdiscount)+fcvat+fcother_cost;
    //fcamount=Math.round((fcamount)*100/100);
    fcoutstanding_amount=fcamount;
    fcpayment_amount=0;

    document.getElementById('fcdiscount').value=fcdiscount;
    document.getElementById('fcvat').value=fcvat;
    document.getElementById('fcamount').value=fcamount;
    document.getElementById('fcoutstanding_amount').value=fcoutstanding_amount;
    document.getElementById('fcpayment_amount').value=fcpayment_amount;

    return true;
}

function SalesInvoiceRecalPrice() {
    SalesInvoiceRecalQty0();

}

function SalesInvoiceRecalDiscPercent() {
    var fcsub_amount=document.getElementById('fcsub_amount').value.replace(/,/g,'')*1;
    var ffdiscount=document.getElementById('ffdiscount').value;
    //var ffdiscount=document.getElementById('ffdiscount').value*1;
    var fcdiscount=0;
    //var fcdiscount=fcsub_amount*ffdiscount/100;
    //fcdiscount=Math.round((fcdiscount)*100/100);
    
    // tier discount 
    var str_ffdiscount = ffdiscount + '';
    var str_ffdiscount = str_ffdiscount.split('+');
    
    for(var i = 0; i < str_ffdiscount.length; i++) {
        // Trim the excess whitespace.
        str_ffdiscount[i] = str_ffdiscount[i].replace(/^\s*/, "").replace(/\s*$/, "");
        fcdiscount = fcdiscount + (fcsub_amount * (str_ffdiscount[i]/100));
        fcsub_amount = fcsub_amount - (fcsub_amount * (str_ffdiscount[i]/100));
    }
    
    document.getElementById('fcdiscount').value=fcdiscount;
    SalesInvoiceRecalQty0();

}

function SalesInvoiceRecalDiscRp() {
      var fcsub_amount=document.getElementById('fcsub_amount').value.replace(/,/g,'')*1;
      var fcdiscount=document.getElementById('fcdiscount').value.replace(/,/g,'')*1;
      var ffdiscount=(fcdiscount/(fcsub_amount))*100;

      // ffdiscount=Math.round((ffdiscount)*100/100);
      document.getElementById('ffdiscount').value=ffdiscount;
      SalesInvoiceRecalQty0();

}

function SalesInvoiceRecalDiscDetailPercent(index) {
    var fnqtyD=0;
    //if(document.getElementById('ftstock_category_codeD0'+index).value=='inv') {
    fnqtyD=document.getElementById('fnqtyD0'+index).value.replace(/,/g,'')*1;
    //}
    // else {
    //    fnqtyD=1;
    // }
    var fcpriceD=document.getElementById('fcpriceD0'+index).value.replace(/,/g,'')*1;
    var ffdiscountD=document.getElementById('ffdiscountD0'+index).value;
    //var ffdiscountD=document.getElementById('ffdiscountD0'+index).value.replace(/,/g,'')*1;
    var fcdiscountD=0;
    
    // tier discount 
    var str_ffdiscountD = ffdiscountD + '';
    var str_ffdiscountD = str_ffdiscountD.split('+');
 
    for(var i = 0; i < str_ffdiscountD.length; i++) {
        // Trim the excess whitespace.
        str_ffdiscountD[i] = str_ffdiscountD[i].replace(/^\s*/, "").replace(/\s*$/, "");
        fcdiscountD = fcdiscountD + (fcpriceD * (str_ffdiscountD[i]/100));
        fcpriceD = fcpriceD - (fcpriceD * (str_ffdiscountD[i]/100));
    }
    fcdiscountD = (fnqtyD * fcdiscountD);
   
    //var fcdiscountD=(fnqtyD*fcpriceD)*(ffdiscountD/100);
    //fcdiscountD=Math.round((fcdiscountD)*100/100);

    document.getElementById('fcdiscountD0'+index).value=fcdiscountD;
    SalesInvoiceRecalQty0();

}

function SalesInvoiceRecalDiscDetailRp(index) {
    var fnqtyD=0;
//     if(document.getElementById('ftstock_category_codeD'+index).value=='inv') {
    fnqtyD=document.getElementById('fnqtyD0'+index).value.replace(/,/g,'')*1;
//      }
//      else {
//          fnqtyD=1;
//      }
    var fcpriceD=document.getElementById('fcpriceD0'+index).value.replace(/,/g,'')*1;
    var fcdiscountD= document.getElementById('fcdiscountD0'+index).value.replace(/,/g,'')*1;
    var ffdiscountD=(fcdiscountD/(fnqtyD*fcpriceD))*100;
    // ffdiscountD=Math.round((ffdiscountD)*100/100);
    document.getElementById('ffdiscountD0'+index).value=ffdiscountD;
    SalesInvoiceRecalQty0();

}

function SalesInvoiceRecalQty0() {

    var i=document.getElementsByName('fnindexD0[]').length;
    var fnqtyD=0;
    var fntotal_qty=0;
    var fcpriceD=0;
    var fcpricetempD=0;
    var ffdiscountD=0;
    var fcdiscountD=0;
    var fcamountD=0;

    var fcpayment_amount=0;
    var fcoutstanding_amount=0;
    var fcsub_amount=0;
    var fcsub_amounttemp=0;
    var ffdiscount=0;
    var fcdiscount=0;
    var fcother_cost=0;
    var ffvat=0;
    var fcvat=0;
    var fcamount=0;


    for(var j=0;j<i;j++) {

        //if(document.getElementsByName('ftstock_category_codeD0[]')[j].value=='inv') {
        fnqtyD=document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1;
        //}
        // else {
        //    fnqtyD=1;
        // }
        // fcdiscountD=document.getElementsByName('fcdiscountD[]')[j].value.replace(/,/g,'')*1;
        fntotal_qty+= document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1;     
        fcpriceD=document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1;
        //ffdiscountD=document.getElementsByName('ffdiscountD0[]')[j].value.replace(/,/g,'')*1;
        //fcdiscountD=(fnqtyD*fcpriceD)*(ffdiscountD/100);
        //document.getElementsByName('fcdiscountD0[]')[j].value = fcdiscountD;
        fcdiscountD=document.getElementsByName('fcdiscountD0[]')[j].value.replace(/,/g,'')*1;
         
        fcamountD=(fnqtyD*fcpriceD )-fcdiscountD;
        document.getElementsByName('fcamountD0[]')[j].value=fcamountD;
        fcsub_amount+= document.getElementsByName('fcamountD0[]')[j].value.replace(/,/g,'')*1;
    }
    document.getElementById('fcsub_amount').value=fcsub_amount;
    document.getElementById('fntotal_qty').value=fntotal_qty;
    /*fcdiscount=document.getElementById('fcdiscount').value.replace(/,/g,'')*1;

    fcother_cost=document.getElementById('fcother_cost').value.replace(/,/g,'')*1;
    fcother_cost=Math.round((fcother_cost)*100/100);

    ffvat= document.getElementById('ffvat').value.replace(/,/g,'')*1;
    fcvat=(fcsub_amount-fcdiscount)*ffvat/100;
    fcvat=Math.round((fcvat)*100/100);

    fcamount=(fcsub_amount-fcdiscount)+fcvat+fcother_cost;
    fcamount=Math.round((fcamount)*100/100);
    fcoutstanding_amount=fcamount;
    fcpayment_amount=0;*/
    fcdiscount=document.getElementById('fcdiscount').value.replace(/,/g,'')*1;

    fcother_cost=document.getElementById('fcother_cost').value.replace(/,/g,'')*1;
    //fcother_cost=Math.round((fcother_cost)*100/100);

    fcamount=(fcsub_amount-fcdiscount)+fcother_cost;

    ffvat= document.getElementById('ffvat').value.replace(/,/g,'')*1;
    fcvat=fcamount*ffvat/100;
    //fcvat=Math.round((fcvat)*100/100);

    fcamount=fcamount+fcvat;

    //fcamount=Math.round((fcamount)*100/100);
    fcoutstanding_amount=fcamount;
    fcpayment_amount=0;

    document.getElementById('fcvat').value=fcvat;
    document.getElementById('fcamount').value=fcamount;
    document.getElementById('fcoutstanding_amount').value=fcoutstanding_amount;
    document.getElementById('fcpayment_amount').value=fcpayment_amount;
    ElementCurrencyALL();
    return true;
}

function SalesInvoiceInputQty() {
     var m="";
     var n="";

    var i=document.getElementsByName('fnindexD0[]').length;
    // Kalau Load dari grid , index mulai dari 1, kalau input dari baru , index mulai dari 0.. belom dibenerin bugs nya 
    for(var j=1;j<i;j++) {
        if ((document.getElementById('ftso_no').value != "") && document.getElementsByName('fnqty_baseD0[]')[j].value.replace(/,/g,'')*1>document.getElementsByName('fnqty_so_outstanding_baseD0[]')[j].value.replace(/,/g,'')*1)  {
            alert('Qty tidak boleh melebihi sisa SO ...');
            document.getElementsByName('fnqtyD0[]')[j].focus();
            return false;
        }
        else if (document.getElementsByName('ftitem_codeD0[]')[j].value=="") {
            alert('Kode barang harus diisi ...');
            document.getElementsByName('ftitem_codeD0[]')[j].focus();
            return false;
        }
        else if (document.getElementsByName('ftuom_codeD0[]')[j].value=="") {
              alert('Satuan diisi ...');
              document.getElementsByName('ftuom_codeD0[]')[j].focus();
              return false;
        } 
        else if (document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1<0) {
              alert('Harga harus di isi ...');
              document.getElementsByName('fcpriceD0[]')[j].focus();
              return false;
        }
        else if (document.getElementsByName('ffdiscountD0[]')[j].value.replace(/,/g,'')*1>100) {
              alert('Discount tidak boleh lebih dari 100 ...');
              document.getElementsByName('ffdiscountD0[]')[j].focus();
              return false;
        }
        else if (document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1==0) {
            n=n+ document.getElementsByName('ftitem_codeD0[]')[j].value +'\n';
        }
        //else if (document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1<document.getElementsByName('fcpriceListD0[]')[j].value.replace(/,/g,'')*1) {
        //    m=m+ document.getElementsByName('ftitem_codeD0[]')[j].value +'\n';
        //}
    }
    if(n!="") {
           if(confirm('Harga barang berikut GRATIS :\n------------------------------------ \n '+n+'-------------------------------\n Apakah transaksi akan diteruskan??')) {
                    return true;
            }
            else {
                  return false;
            }
    }
    else if(m!="") {
           if(confirm('Harga barang berikut lebih kecil dari harga jual :\n------------------------------------ \n '+m+'-------------------------------\n Apakah transaksi akan diteruskan??')) {
                    return true;
            }
            else {
                  return false;
            }
    }
    return true;
}
function SalesInvoiceInputQtyX() {
    var m="";


    var i=document.getElementsByName('fnindexD0[]').length;
    for(var j=0;j<i;j++) {
//        if (document.getElementsByName('fnqtyD[]')[j].value.replace(/,/g,'')*1<0)  {
//             alert('Qty harus di isi ...');
//            document.getElementsByName('fnqtyD[]')[j].focus();
//             return false;
//        }
//       else
       //alert('x');
        if (document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1<=0) {
              alert('Harga harus di isi ...');
              document.getElementsByName('fcpriceD0[]')[j].focus();
              return false;

        }
        else if (document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1<document.getElementsByName('fcpriceListD0[]')[j].value.replace(/,/g,'')*1) {
            m=m+ document.getElementsByName('ftitem_codeD0[]')[j].value +'\n';
        }
    }
    if(m!="") {
           if(confirm('Harga barang berikut lebih kecil dari harga jual :\n------------------------------------ \n '+m+'-------------------------------\n Apakah transaksi akan diteruskan??')) {
                    return true;
            }
            else {
                  return false;
            }
    }
    return true;
}


function ValSalesInvoiceAdjustment() {

    if(document.getElementById("ftsales_invoice_no").value=='') {
        alert('No. transaksi harus disi...');
        document.getElementById("ftsales_invoice_no").focus();
        return false;
    }
    else  if(document.getElementById("hidden_ftcustomer_code").value=='') {
      alert('Customer belum valid ...');
      document.getElementById("ftcustomer_code").focus();
      return false;
    }
    else if(document.getElementsByName('fnindexD0[]').length<1) {
        alert('Detail transaksi harus disi...');
        return false;
    }  
    else if(document.getElementById('fcamount').value==0) {
        alert('Nilai Jumlah Total tidak boleh 0');
        return false;
    }  
    else if(document.getElementById('ftsales_code').value=='') {
        alert('Salesman belum harus diisi');
        return false;
    } 
    
    /*else if (SalesInvoiceInputQty()==false) {
         return false;
    }
    
    var j=document.getElementsByName('fnindexD0[]').length;
    for(var k=1;k<j;k++) {
        if  ((document.getElementsByName('fcamountD0[]')[k].value=='') || (document.getElementsByName('fcamountD0[]')[k].value==0)) {
            alert('Nilai Jumlah total harus diisi dan tidak boleh 0');
            document.getElementsByName('fcamountD0[]')[k].focus();
            return false;
        }
    } */

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

  return false;

}

function SalesInvoiceAdjustmentRecalQty() {

    var i=document.getElementsByName('fnindexD0[]').length;
   
    var fcsub_amount=0;
    var fcamount=0;

    for(var j=0;j<i;j++) {
        fcamount=document.getElementsByName('fcamountD0[]')[j].value.replace(/,/g,'')*1;
        fcsub_amount+=fcamount;      
    }
    
    document.getElementById('fcsub_amount').value=fcsub_amount;
    
    ffvat= document.getElementById('ffvat').value.replace(/,/g,'')*1;
    fcvat=fcamount*ffvat/100;

    fcamount=fcsub_amount+fcvat;

    document.getElementById('fcvat').value=fcvat;
    document.getElementById('fcamount').value=fcamount;
    document.getElementById('fcoutstanding_amount').value=fcamount;
    document.getElementById('fcpayment_amount').value=0;

    ElementCurrencyALL();
    
    return true;
}


function RevisiSalesInvoiceAdjustment() {

    if(document.getElementById("ftsales_invoice_no").value=='') {
        alert('No. transaksi harus disi...');
        document.getElementById("ftsales_invoice_no").focus();
        return false;
    }
    else  if(document.getElementById("hidden_ftcustomer_code").value=='') {
      alert('Customer belum valid ...');
      document.getElementById("ftcustomer_code").focus();
      return false;
    }
    else if(document.getElementsByName('fnindexD0[]').length<1) {
        alert('Detail transaksi harus disi...');
        return false;
    }  
    else if(document.getElementById('fcamount').value==0) {
        alert('Nilai Jumlah Total tidak boleh 0');
        return false;
    }  
    
  return true;

}

//--------------------------------------------
//Kas Masuk

function ValKasMasuk() {
  if(document.getElementById("ftcashrcp_no").value=='') {
       alert('No. transaksi harus disi...');
       document.getElementById("ftcashrcp_no").focus();
       return false;
  }
  /*else if(document.getElementById("ftjournal_no").value=='') {
       alert('No. Jurnal harus disi...');
       document.getElementById("ftjournal_no").focus();
       return false;
  }*/
  else if(document.getElementById("ftacc_no1").value=='') {
       alert('No. Perkiraan harus diisi...');
       document.getElementById("ftacc_no1").focus();
       return false;
  }
  else if(document.getElementById("fccomparison_amount").value.replace(/,/g,'')*1<=0) {
      alert('Jumlah total tidak boleh kosong ...');
      document.getElementById("fccomparison_amount").focus();
      return false;
  }
   else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }
   else if (KasMasukInputQty()==false) {
       return false;
  }
  else if(document.getElementById("fccomparison_amount").value.replace(/,/g,'')*1!=document.getElementById("fcamount").value.replace(/,/g,'')*1) {
       alert('transaksi belum balance ...');
        document.getElementById("fccomparison_amount").focus();
        return false;
  }

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

  return false;
}


function FinalKasMasuk() {
  if(document.getElementById("ftcashrcp_no").value=='') {
       alert('No. transaksi harus disi...');
       document.getElementById("ftcashrcp_no").focus();
       return false;
  }
  /*else if(document.getElementById("ftjournal_no").value=='') {
       alert('No. Jurnal harus disi...');
       document.getElementById("ftjournal_no").focus();
       return false;
  }*/
  else if(document.getElementById("ftacc_no1").value=='') {
       alert('No. Perkiraan harus diisi...');
       document.getElementById("ftacc_no1").focus();
       return false;
  }
  else if(document.getElementById("fccomparison_amount").value.replace(/,/g,'')*1<=0) {
      alert('Jumlah total tidak boleh kosong ...');
      document.getElementById("fccomparison_amount").focus();
      return false;
  }
   else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }
   else if (KasMasukInputQty()==false) {
       return false;
  }
  else if(document.getElementById("fccomparison_amount").value.replace(/,/g,'')*1!=document.getElementById("fcamount").value.replace(/,/g,'')*1) {
       alert('transaksi belum balance ...');
        document.getElementById("fccomparison_amount").focus();
        return false;
  }
 ajax_do(str_url + '&ajax=1&code=transno2&fttrans_no=' + document.getElementById('ftcashrcp_no').value);


  return false;
}



function KasMasukInputQty() {
    var i=document.getElementsByName('fnindexD0[]').length;
    for(var j=1;j<i;j++) {
        if(document.getElementsByName('ftcoa_codeD0[]')[j].value=='') {
            alert('No. Perkiraan detail harus di isi ...');
            document.getElementsByName('ftcoa_codeD0[]')[j].focus();
            return false;
        }
        else if(document.getElementsByName('hidden_ftcoa_codeD0[]')[j].value=='') {
              alert('No. Perkiraan detail harus di isi ...');
              document.getElementsByName('hidden_ftcoa_codeD0[]')[j].focus();
              return false;
        }    
        else if(document.getElementsByName('ftdescriptionD0[]')[j].value=='') {
            alert("Keterangan harus diisi...")
            document.getElementsByName('ftdescriptionD0[]')[j].focus();
             return false;
        }
        else if(document.getElementsByName('fcamountD0[]')[j].value.replace(/,/g,'')*1==0) {
            alert('Jumlah total di detail tidak boleh kosong ...');
            document.getElementsByName('fcamountD0[]')[j].focus();
            return false;
        }
    }
    return true;
}

function KasMasukRecalQty() {

    var i=document.getElementsByName('fnindexD0[]').length;
    var fcamount=0;
    for(var j=1;j<i;j++) {
        fcamount+=document.getElementsByName('fcamountD0[]')[j].value.replace(/,/g,'')*1;
    }
     document.getElementById("fcamount").value=fcamount;
     ElementCurrencyALL();
}


function RevisiKasMasuk() {

    if(document.getElementById("ftacc_no1").value=='') {
       alert('No. Perkiraan harus diisi...');
       document.getElementById("ftacc_no1").focus();
       return false;
    }
    else if(document.getElementById("fccomparison_amount").value.replace(/,/g,'')*1<=0) {
        alert('Jumlah total tidak boleh kosong ...');
        document.getElementById("fccomparison_amount").focus();
        return false;
    }
    else if(document.getElementsByName('fnindexD0[]').length==1) {
        alert('Detail transaksi belum di input ...');
        return false;
    }
    else if (KasMasukInputQty()==false) {
        return false;
    }
    else if(document.getElementById("fccomparison_amount").value.replace(/,/g,'')*1!=document.getElementById("fcamount").value.replace(/,/g,'')*1) {
        alert('transaksi belum balance ...');
        document.getElementById("fccomparison_amount").focus();
        return false;
  }

  return true;

}



////--------------------------------------------
//Kas Keluar

function ValKasKeluar() {
  if(document.getElementById("ftcashpym_no").value=='') {
       alert('No. transaksi harus disi...');
       document.getElementById("ftcashpym_no").focus();
       return false;
  }
  /*else if(document.getElementById("ftjournal_no").value=='') {
       alert('No. Jurnal harus disi...');
       document.getElementById("ftjournal_no").focus();
       return false;
  }*/
    else if(document.getElementById("ftacc_no1").value=='') {
       alert('No. Perkiraan harus diisi...');
       document.getElementById("ftacc_no1").focus();
       return false;
  }
  else if(document.getElementById("fccomparison_amount").value.replace(/,/g,'')*1<=0) {
      alert('Jumlah total tidak boleh kosong ...');
      document.getElementById("fccomparison_amount").focus();
      return false;
  }
  else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }
  else if (KasKeluarInputQty()==false) {
       return false;
  }
  else if(document.getElementById("fccomparison_amount").value.replace(/,/g,'')*1!=document.getElementById("fcamount").value.replace(/,/g,'')*1) {
       alert('transaksi belum balance ...');
        document.getElementById("fccomparison_amount").focus();
        return false;
  }
  ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftcashpym_no').value);

  return false;
}

function FinalKasKeluar() {
  if(document.getElementById("ftcashpym_no").value=='') {
       alert('No. transaksi harus disi...');
       document.getElementById("ftcashpym_no").focus();
       return false;
  }
  /*else if(document.getElementById("ftjournal_no").value=='') {
       alert('No. Jurnal harus disi...');
       document.getElementById("ftjournal_no").focus();
       return false;
  }*/
    else if(document.getElementById("ftacc_no1").value=='') {
       alert('No. Perkiraan harus diisi...');
       document.getElementById("ftacc_no1").focus();
       return false;
  }
  else if(document.getElementById("fccomparison_amount").value.replace(/,/g,'')*1<=0) {
      alert('Jumlah total tidak boleh kosong ...');
      document.getElementById("fccomparison_amount").focus();
      return false;
  }
  else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }
  else if (KasKeluarInputQty()==false) {
       return false;
  }
   else if(document.getElementById("fccomparison_amount").value.replace(/,/g,'')*1!=document.getElementById("fcamount").value.replace(/,/g,'')*1) {
       alert('transaksi belum balance ...');
        document.getElementById("fccomparison_amount").focus();
        return false;
  }
  ajax_do(str_url + '&ajax=1&code=transno2&fttrans_no=' + document.getElementById('ftcashpym_no').value);

  return false;
}


function KasKeluarInputQty() {
    var i=document.getElementsByName('fnindexD0[]').length;
    for(var j=1;j<i;j++) {
        if(document.getElementsByName('ftcoa_codeD0[]')[j].value=='') {
            alert('No. Perkiraan detail harus di isi ...');
            document.getElementsByName('ftcoa_codeD0[]')[j].focus();
            return false;
        }
        else if(document.getElementsByName('hidden_ftcoa_codeD0[]')[j].value=='') {
              alert('No. Perkiraan detail harus di isi ...');
              document.getElementsByName('hidden_ftcoa_codeD0[]')[j].focus();
              return false;
        }    
        else if(document.getElementsByName('ftdescriptionD0[]')[j].value=='') {
              alert('Keterangan detail harus di isi ...');
              document.getElementsByName('ftdescriptionD0[]')[j].focus();
              return false;
        }
        else if(document.getElementsByName('fcamountD0[]')[j].value.replace(/,/g,'')*1==0) {
            alert('Jumlah total di detail tidak boleh kosong ...');
            document.getElementsByName('fcamountD0[]')[j].focus();
            return false;
        }
    }
    return true;
}

function KasKeluarRecalQty() {
    var i=document.getElementsByName('fnindexD0[]').length;
    var fcamount=0;
    
    for(var j=1;j<i;j++) {
        fcamount+=document.getElementsByName('fcamountD0[]')[j].value.replace(/,/g,'')*1;
    }
    
     document.getElementById("fcamount").value=fcamount;
      ElementCurrencyALL();
}


function RevisiKasKeluar() {
  if(document.getElementById("ftcashpym_no").value=='') {
       alert('No. transaksi harus disi...');
       document.getElementById("ftcashpym_no").focus();
       return false;
  }
  else if(document.getElementById("ftacc_no1").value=='') {
       alert('No. Perkiraan harus diisi...');
       document.getElementById("ftacc_no1").focus();
       return false;
  }
  else if(document.getElementById("fccomparison_amount").value.replace(/,/g,'')*1<=0) {
      alert('Jumlah total tidak boleh kosong ...');
      document.getElementById("fccomparison_amount").focus();
      return false;
  }
  else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }
  else if (KasKeluarInputQty()==false) {
       return false;
  }
  else if(document.getElementById("fccomparison_amount").value.replace(/,/g,'')*1!=document.getElementById("fcamount").value.replace(/,/g,'')*1) {
       alert('transaksi belum balance ...');
        document.getElementById("fccomparison_amount").focus();
        return false;
  }

  return true;
}

////--------------------------------------------
//Bank Masuk

function ValBankMasuk() {
  if(document.getElementById("ftbankrcp_no").value=='') {
       alert('No. transaksi harus disi...');
       document.getElementById("ftbankrcp_no").focus();
       return false;
  }
  else if(document.getElementById("ftacc_no1").value=='') {
       alert('No. Perkiraan harus diisi...');
       document.getElementById("ftacc_no1").focus();
       return false;
  }

  else if(document.getElementById("fccomparison_amount").value.replace(/,/g,'')*1<=0) {
      alert('Jumlah total tidak boleh kosong ...');
      document.getElementById("fccomparison_amount").focus();
      return false;
  }
  else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }
  else if (BankMasukInputQty()==false) {
       return false;
  }
  else if(document.getElementById("fccomparison_amount").value.replace(/,/g,'')*1!=document.getElementById("fcamount").value.replace(/,/g,'')*1) {
       alert('transaksi belum balance ...');
        document.getElementById("fccomparison_amount").focus();
        return false;
  }

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

  return false;
}

function FinalBankMasuk() {
  if(document.getElementById("ftbankrcp_no").value=='') {
       alert('No. transaksi harus disi...');
       document.getElementById("ftbankrcp_no").focus();
       return false;
  }
  /*else if(document.getElementById("ftjournal_no").value=='') {
       alert('No. Jurnal harus disi...');
       document.getElementById("ftjournal_no").focus();
       return false;
  }*/
    else if(document.getElementById("ftacc_no1").value=='') {
       alert('No. Perkiraan harus diisi...');
       document.getElementById("ftacc_no1").focus();
       return false;
  }

  else if(document.getElementById("fccomparison_amount").value.replace(/,/g,'')*1<=0) {
      alert('Jumlah total tidak boleh kosong ...');
      document.getElementById("fccomparison_amount").focus();
      return false;
  }
   else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }
  else if (BankMasukInputQty()==false) {
       return false;
  }
  else if(document.getElementById("fccomparison_amount").value.replace(/,/g,'')*1!=document.getElementById("fcamount").value.replace(/,/g,'')*1) {
       alert('transaksi belum balance ...');
        document.getElementById("fccomparison_amount").focus();
        return false;
  }

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

  return false;
}

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

        if(document.getElementsByName('ftcoa_codeD0[]')[j].value=='') {
            alert('No. Perkiraan detail harus di isi ...');
            document.getElementsByName('ftcoa_codeD0[]')[j].focus();
            return false;
        }
        else if(document.getElementsByName('hidden_ftcoa_codeD0[]')[j].value=='') {
              alert('No. Perkiraan detail harus di isi ...');
              document.getElementsByName('hidden_ftcoa_codeD0[]')[j].focus();
              return false;
        }    
        else if(document.getElementsByName('fnpayment_methodD0[]')[j].value=='') {
            alert('Metode Pembayaran detail harus di isi ...');
            document.getElementsByName('fnpayment_methodD0[]')[j].focus();
            return false;
        }
        else if (((document.getElementsByName('fnpayment_methodD0[]')[j].value*1==0)||(document.getElementsByName('fnpayment_methodD0[]')[j].value*1==1))&&(document.getElementsByName('ftgiro_noD0[]')[j].value=='') ) {
            alert('No. Cek Atau giro belum di isi ...');
            document.getElementsByName('ftgiro_noD0[]')[j].focus();
            return false;
        }
        else if(document.getElementsByName('ftdescriptionD0[]')[j].value=='') {
            alert('Keterangan harus diisi ...');
            document.getElementsByName('ftdescriptionD0[]')[j].focus();
            return false;
        }
        else if(document.getElementsByName('fcamountD0[]')[j].value.replace(/,/g,'')*1==0) {
            alert('Jumlah total di detail tidak boleh kosong ...');
            document.getElementsByName('fcamountD0[]')[j].focus();
            return false;
        }
        else if(document.getElementsByName('fdgiro_cliring_dateD0[]')[j].value < document.getElementsByName('fdgiro_dateD0[]')[j].value) {
            alert('Tgl Cair Giro tidak boleh lebih kecil dari Tgl Giro...');
            document.getElementsByName('fdgiro_cliring_date[]')[j].focus();
            return false;
        }

    }
    return true;
}

function BankMasukRecalQty() {
    var i=document.getElementsByName('fnindexD0[]').length;
    var fcamount=0;
    for(var j=1;j<i;j++) {
        fcamount+=document.getElementsByName('fcamountD0[]')[j].value.replace(/,/g,'')*1;
    }
     document.getElementById("fcamount").value=fcamount;
      ElementCurrencyALL();
}

function RevisiBankMasuk() {
      if(document.getElementById("ftbankrcp_no").value=='') {
           alert('No. transaksi harus disi...');
           document.getElementById("ftbankrcp_no").focus();
           return false;
      }
      else if(document.getElementById("ftacc_no1").value=='') {
           alert('No. Perkiraan harus diisi...');
           document.getElementById("ftacc_no1").focus();
           return false;
      }

      else if(document.getElementById("fccomparison_amount").value.replace(/,/g,'')*1<=0) {
          alert('Jumlah total tidak boleh kosong ...');
          document.getElementById("fccomparison_amount").focus();
          return false;
      }
      else if(document.getElementsByName('fnindexD0[]').length==1) {
          alert('Detail transaksi belum di input ...');
          return false;
      }
      else if (BankMasukInputQty()==false) {
           return false;
      }
      else if(document.getElementById("fccomparison_amount").value.replace(/,/g,'')*1!=document.getElementById("fcamount").value.replace(/,/g,'')*1) {
           alert('transaksi belum balance ...');
            document.getElementById("fccomparison_amount").focus();
            return false;
      }

    return true;
}

////--------------------------------------------
//Bank Keluar

function ValBankKeluar() {
  if(document.getElementById("ftbankpym_no").value=='') {
       alert('No. transaksi harus disi...');
       document.getElementById("ftbankpym_no").focus();
       return false;
  }
  else if(document.getElementById("ftacc_no1").value=='') {
       alert('No. Perkiraan harus diisi...');
       document.getElementById("ftacc_no1").focus();
       return false;
  }
  else if(document.getElementById("fccomparison_amount").value.replace(/,/g,'')*1<=0) {
      alert('Jumlah total tidak boleh kosong ...');
      document.getElementById("fccomparison_amount").focus();
      return false;
  }
  else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }
  else if (BankKeluarInputQty()==false) {
       return false;
  }
  else if(document.getElementById("fccomparison_amount").value.replace(/,/g,'')*1!=document.getElementById("fcamount").value.replace(/,/g,'')*1) {
       alert('transaksi belum balance ...');
        document.getElementById("fccomparison_amount").focus();
        return false;
  }

  if(document.getElementById("fnstatus").value=='0') {
      ajax_do(str_url + '&ajax=1&code=transno3&fttrans_no=' + document.getElementById('ftbankpym_no').value);
  }
  else {
      ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftbankpym_no').value);
  }
  
  return false;
}

function FinalBankKeluar() {
  if(document.getElementById("ftbankpym_no").value=='') {
       alert('No. transaksi harus disi...');
       document.getElementById("ftbankpym_no").focus();
       return false;
  }
  /*else if(document.getElementById("ftjournal_no").value=='') {
       alert('No. Jurnal harus disi...');
       document.getElementById("ftjournal_no").focus();
       return false;
  }*/
  else if(document.getElementById("ftacc_no1").value=='') {
       alert('No. Perkiraan harus diisi...');
       document.getElementById("ftacc_no1").focus();
       return false;
  }
  else if(document.getElementById("fccomparison_amount").value.replace(/,/g,'')*1<=0) {
      alert('Jumlah total tidak boleh kosong ...');
      document.getElementById("fccomparison_amount").focus();
      return false;
  }
   else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }

   else if (BankKeluarInputQty()==false) {
       return false;
  }
  else if(document.getElementById("fccomparison_amount").value.replace(/,/g,'')*1!=document.getElementById("fcamount").value.replace(/,/g,'')*1) {
       alert('transaksi belum balance ...');
        document.getElementById("fccomparison_amount").focus();
        return false;
  }

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

  return false;
}

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

        if(document.getElementsByName('ftcoa_codeD0[]')[j].value=='') {
            alert('No. Perkiraan detail harus di isi ...');
            document.getElementsByName('ftcoa_codeD0[]')[j].focus();
            return false;
        }
        else if(document.getElementsByName('hidden_ftcoa_codeD0[]')[j].value=='') {
              alert('No. Perkiraan detail harus di isi ...');
              document.getElementsByName('hidden_ftcoa_codeD0[]')[j].focus();
              return false;
        }    
        else if(document.getElementsByName('fnpayment_methodD0[]')[j].value=='') {
            alert('Metode Pembayaran detail harus di isi ...');
            document.getElementsByName('fnpayment_methodD0[]')[j].focus();
            return false;
        }
        else if (((document.getElementsByName('fnpayment_methodD0[]')[j].value*1==0)||(document.getElementsByName('fnpayment_methodD0[]')[j].value*1==1))&&(document.getElementsByName('ftgiro_noD0[]')[j].value=='') ) {
            alert('No. Cek Atau giro belum di isi ...');
            document.getElementsByName('ftgiro_noD0[]')[j].focus();
            return false;
        }
        else if(document.getElementsByName('ftdescriptionD0[]')[j].value=='') {
            alert('Keterangan harus diisi ...');
            document.getElementsByName('ftdescriptionD0[]')[j].focus();
            return false;
        }
        else if(document.getElementsByName('fcamountD0[]')[j].value.replace(/,/g,'')*1==0) {
            alert('Jumlah total di detail tidak boleh kosong ...');
            document.getElementsByName('fcamountD0[]')[j].focus();
            return false;
        }
        else if(document.getElementsByName('fdgiro_cliring_dateD0[]')[j].value < document.getElementsByName('fdgiro_dateD0[]')[j].value) {
            alert('Tgl Cair Giro tidak boleh lebih kecil dari Tgl Giro...');
            document.getElementsByName('fdgiro_cliring_date[]')[j].focus();
            return false;
        }

    }
    return true;
}

function BankKeluarRecalQty() {
    var i=document.getElementsByName('fnindexD0[]').length;
    var fcamount=0;
    
    for(var j=1;j<i;j++) {
        fcamount+=document.getElementsByName('fcamountD0[]')[j].value.replace(/,/g,'')*1;
    }

    document.getElementById("fcamount").value=fcamount;

    ElementCurrencyALL();
}

function RevisiBankKeluar() {
  if(document.getElementById("ftbankpym_no").value=='') {
       alert('No. transaksi harus disi...');
       document.getElementById("ftbankpym_no").focus();
       return false;
  }
  else if(document.getElementById("ftacc_no1").value=='') {
       alert('No. Perkiraan harus diisi...');
       document.getElementById("ftacc_no1").focus();
       return false;
  }
  else if(document.getElementById("fccomparison_amount").value.replace(/,/g,'')*1<=0) {
      alert('Jumlah total tidak boleh kosong ...');
      document.getElementById("fccomparison_amount").focus();
      return false;
  }
  else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }
  else if (BankKeluarInputQty()==false) {
       return false;
  }
  else if(document.getElementById("fccomparison_amount").value.replace(/,/g,'')*1!=document.getElementById("fcamount").value.replace(/,/g,'')*1) {
       alert('transaksi belum balance ...');
        document.getElementById("fccomparison_amount").focus();
        return false;
  }

    return true;
}


////--------------------------------------------
//Menu Outstanding Mingguan
function ValOutstandingMingguan() {
  if(document.getElementById("ftpow_no").value=='') {
       alert('No. transaksi harus disi...');
       document.getElementById("ftpow_no").focus();
       return false;
  }
 else if(document.getElementById("hidden_ftcustomer_code").value=='') {
       alert('Customer belum valid...');
       document.getElementById("ftcustomer_code").focus();
       return false;
  }
   else if(document.getElementById("fntrans_type").value=='') {
       alert('Cara Kirim harus disi...');
       document.getElementById("fntrans_type").focus();
       return false;
  }
   else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }
  else if (OutstandingMingguanInputQty()==false) {
       return false;
  }
    ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftpow_no').value);

  return false;
}

function OutstandingMingguanInputQty() {
    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;
        }
        else if(document.getElementsByName('ffqtyD0[]')[j].value.replace(/,/g,'')*1==0) {
            alert('Qty di detail tidak boleh kosong ...');
            document.getElementsByName('ffqtyD0[]')[j].focus();
            return false;
        }
    }
    return true;
}

function OutstandingMingguanRecalQty() {
    var i=document.getElementsByName('fnindexD0[]').length;
    var fcamount=0;
    for(var j=1;j<i;j++) {
       /// document.getElementsByName('ffqtyD0[]')[j].value= document.getElementsByName('ffqty_luarkotaD0[]')[j].value.replace(/,/g,'')*1+ document.getElementsByName('ffqty_conntainerD0[]')[j].value.replace(/,/g,'')*1+ document.getElementsByName('ffqty_jakartaD0[]')[j].value.replace(/,/g,'')*1
        fcamount+=document.getElementsByName('ffqtyD0[]')[j].value.replace(/,/g,'')*1;
    }
     document.getElementById("fftotal_qty").value=fcamount;
}


// Production Order Request
function FinalProductionOrderRequest() {

  return true;
}

// Production Order Request Custom
function ValProductionOrderRequestCustom() {
  if(document.getElementById("ftpor_no").value=='') {
       alert('No. transaksi harus disi...');
       document.getElementById("ftpor_no").focus();
       return false;
  }
  else if (ProductionOrderRequestCustomInputQty()==false) {
       return false;
  }
    ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftpor_no').value);

  return false;
}

function ProductionOrderRequestCustomInputQty() {
    var i=document.getElementsByName('fnindexD0[]').length;
    for(var j=1;j<i;j++) {
        if(document.getElementsByName('ftitem_codeD0[]')[j].value=='') {
            alert('Item belum valid ...');
            document.getElementsByName('ftitem_codeD0[]')[j].focus();
            return false;
        }
        /*else if(document.getElementsByName('ffqtyD0[]')[j].value.replace(/,/g,'')*1==0) {
            alert('Qty di detail tidak boleh kosong ...');
            document.getElementsByName('ffqtyD0[]')[j].focus();
            return false;
        }*/
    }
    return true;
}

function FinalProductionOrderRequestCustom() {

  return true;
}


//Piutang Giro Mundur
function ValGiroMundurPiutang() {
    var m1=document.getElementById("fdgiro_date").value.split("/");
    var m2=document.getElementById("fdgiro_cliring_date").value.split("/");
    var date_giro=m1[2]+m1[1]+m1[0];
    var date_cliring=m2[2]+m2[1]+m2[0];
    if(date_cliring<date_giro) {
        if(confirm("Tgl cair tidak boleh lebih kecil dari tgl giro ...\n Apakah trnsaksi akan diteruskan ??")) {
            return true;
        }
    } else if (document.getElementById("fnstatus_giro").value == 0) {
        alert('Status Giro harus di isi terima atau tolak ...');
        document.getElementById("fnstatus_giro").focus();
        return false;
    } else if (document.getElementById("ftacc_no").value == "") {
        alert('No Perkiraan harus diisi.');
        document.getElementById("ftacc_no").focus();
        return false;
    }

    return true;
}

//Hutanf Giro Mundur
function ValGiroMundurHutang() {
    //
    var m1=document.getElementById("fdgiro_date").value.split("/");
    var m2=document.getElementById("fdgiro_cliring_date").value.split("/");
    var date_giro=m1[2]+m1[1]+m1[0];
    var date_cliring=m2[2]+m2[1]+m2[0];
    if(date_cliring<date_giro) {
        if(confirm("Tgl cair tidak boleh lebih kecil dari tgl giro ...\n Apakah trnsaksi akan diteruskan ??")) {
            return true;
        }
        return false;
    } else if (document.getElementById("fnstatus_giro").value == 0) {
        alert('Status Giro harus di isi terima atau tolak ...');
        document.getElementById("fnstatus_giro").focus();
        return false;
    } else if (document.getElementById("ftacc_no").value == "") {
        alert('No Perkiraan harus diisi.');
        document.getElementById("ftacc_no").focus();
        return false;
    }
    
    return true;
}

function ValPenerimaanPiutangBank() {
  PenerimaanPiutangRecalQty0();
  PenerimaanPiutangRecalQty1();

  var sub_total=document.getElementById("fcsub_amount").value.replace(/,/g,'')*1;
  var pembulatan=document.getElementById("fcother_cost").value.replace(/,/g,'')*1;
  var total_invoice=document.getElementById("fcinvoice_amount").value.replace(/,/g,'')*1;
  
  if(document.getElementById("ftar_no").value=='') {
       alert('No. transaksi harus di isi...');
       document.getElementById("ftar_no").focus();
       return false;
  }
  if(document.getElementById("hidden_ftcustomer_code").value=='') {
       alert('Customer belum valid...');
       document.getElementById("ftcustomer_code").focus();
       return false;
  }
  else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }
  else if (PenerimaanPiutangInputQty0()==false) {
       return false;
  }
  else if (total_invoice > 0) {
    if (sub_total + pembulatan != total_invoice) {
      alert('Transaksi belum balance');
      return false;
    }
  }

  var j=document.getElementsByName('fnindexD0[]').length;
  var method="";
  var nogiro="";
  for(i=1; i < j; i++){
    if(method!="") method+="___";
    if(nogiro!="") nogiro+="___";
    method+=document.getElementsByName('fnpayment_methodD0[]')[i].value;
    nogiro+=document.getElementsByName('ftgiro_noD0[]')[i].value;
  }
  
  ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftar_no').value + '&method=' + method + '&nogiro=' + nogiro);
  // ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftbankrcp_no').value+'&fttrans_no1=' + document.getElementById('ftjournal_no').value);

  return false;
}

function PenerimaanPiutangRecalQty0Bank() {
    var i=document.getElementsByName('fnindexD0[]').length;
    var fcamountxx=0;
    for(var j=1;j<i;j++) {
        document.getElementsByName('fctotalD0[]')[j].value=document.getElementsByName('fcamountD0[]')[j].value.replace(/,/g,'')*1+document.getElementsByName('fcother_costD0[]')[j].value.replace(/,/g,'')*1;
        fcamountxx+=document.getElementsByName('fcamountD0[]')[j].value.replace(/,/g,'')*1;
    }
        document.getElementById('fcsub_amount').value=fcamountxx;
        document.getElementById('fcamount').value=fcamountxx+document.getElementById('fcother_cost').value.replace(/,/g,'')*1+document.getElementById('fcother_cost2').value.replace(/,/g,'')*1;



        ElementCurrencyOnBlur(document.getElementById('fcamount'));
        ElementCurrencyOnBlur(document.getElementById('fcother_cost'));
         ElementCurrencyOnBlur(document.getElementById('fcother_cost2'));
         ElementCurrencyOnBlur(document.getElementById('fcsub_amount'));
     ElementCurrencyALL();
}
function ValPenerimaanPiutangPenerimaan() {
  PenerimaanPiutangRecalQty0();
  PenerimaanPiutangRecalQty1();
  if(document.getElementById("ftar_no").value=='') {
       alert('No. transaksi harus di isi...');
       document.getElementById("ftar_no").focus();
       return false;
  }
  if(document.getElementById("hidden_ftcustomer_code").value=='') {
       alert('Customer belum valid...');
       document.getElementById("ftcustomer_code").focus();
       return false;
  }
   else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }
  else if (PenerimaanPiutangInputQty0()==false) {
       return false;
  }
   else if (PenerimaanPiutangInputQty1()==false) {
       return false;
  }
  else if(PenerimaanPiutangInputQty0Penerimaan()==false) {
       return false;
  }
  else if ( (document.getElementById('fccm_min').value.replace(/,/g,'')*(1)+document.getElementById('fccm_add').value.replace(/,/g,'')*(-1))+document.getElementById('fcamountxx').value.replace(/,/g,'')*1!=document.getElementById('fcinvoice_amount').value.replace(/,/g,'')*1) {
      alert('transaksi belum balance...');
        return false;
  }


  return true;
}

function PenerimaanPiutangInputQty0Penerimaan() {
    var i=document.getElementsByName('fnindexD0[]').length;
    for(var j=1;j<i;j++) {
        if(document.getElementsByName('fnstatus_giroD0[]')[j].value=='draft') {
            alert('Giro belum dicairkan...');
            return false;
        }
    }
    return true;
}

//AR
function ValPenerimaanPiutang() {  
  
  PenerimaanPiutangRecalQty0();
  PenerimaanPiutangRecalQty1();

  if(document.getElementById("ftar_no").value=='') {
       alert('No. transaksi harus di isi...');
       document.getElementById("ftar_no").focus();
       return false;
  }
  if(document.getElementById("hidden_ftcustomer_code").value=='') {
       alert('Customer belum valid...');
       document.getElementById("ftcustomer_code").focus();
       return false;
  }
   else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }
  else if (PenerimaanPiutangInputQty0()==false) {
       return false;  
  }
  else if (PenerimaanPiutangInputQty2()==false) {
       return false;  
  }
  else if (document.getElementById("ftcurrency_code").value=='IDR') {
        j=document.getElementsByName('fnindexD1[]').length;
        var valamount = true;

        for(i=0; i < j; i++){
            if ((document.getElementsByName('ftcurrency_codeD1[]')[i].value!='IDR') && (document.getElementsByName('fcpayment_amountD1[]')[i].value.replace(/,/g,'')*1 > 0 )) {
                valamount = false;
                break;
            }
        }

        if (valamount) {
            if ( (document.getElementById('fcsub_amount').value.replace(/,/g,'')*1) != ((document.getElementById('fcamount').value.replace(/,/g,'')*1) + (document.getElementById('fcother_cost').value.replace(/,/g,'')*1))) {
                alert('Nominal pembayaran dan piutang belum balance');
                return false;
            }
        } else {
            retvalue = confirm ("Anda yakin transaksi tetap disimpan ? Ada Selisih Kurs sebesar" + document.getElementById("fcrate_adjustment").value);
            if (retvalue == false) return false;
        }
  }
  else if (document.getElementById("ftcurrency_code").value!='IDR') {
        if ( (document.getElementById('fcsub_amount').value.replace(/,/g,'')*1) != ((document.getElementById('fcamount').value.replace(/,/g,'')*1) + (document.getElementById('fcother_cost').value.replace(/,/g,'')*1))) {
            alert('Nominal pembayaran dan hutang belum balance');
            return false;
        }

        retvalue = confirm ("Anda yakin transaksi tetap disimpan ? Ada Selisih Kurs sebesar" + document.getElementById("fcrate_adjustment").value);
        if (retvalue == false) return false;
  }
  
  var j=document.getElementsByName('fnindexD0[]').length;
  var method="";
  var nogiro="";
  for(i=1; i < j; i++){
    if(method!="") method+="___";
    if(nogiro!="") nogiro+="___";
    method+=document.getElementsByName('fnpayment_methodD0[]')[i].value;
    nogiro+=document.getElementsByName('ftgiro_noD0[]')[i].value;
  }
    
  ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftar_no').value + '&method=' + method + '&nogiro=' + nogiro);
  // ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftbankrcp_no').value+'&fttrans_no1=' + document.getElementById('ftjournal_no').value);

  return false;
}
function PenerimaanPiutangBalance(){
  var i=document.getElementsByName('fnindexD0[]').length;
  var j=document.getElementsByName('fnindexD1[]').length;
  var k=document.getElementsByName('fnindexD2[]').length;

  numD0=0;numD1=0;numD2=0;

  for(var N=0; N<i; N++) {
     ttlD0=document.getElementsByName('fcamountD0[]')[N].value.replace(/,/g,'')*1;
     numD0+=ttlD0;
  }

  for(var N=0; N<j; N++) {
     ttlD1=document.getElementsByName('fcpayment_amountD1[]')[N].value.replace(/,/g,'')*1;
     numD1+=ttlD1;
  }

  for(var N=0; N<k; N++) {
     ttlD2=document.getElementsByName('fccm_paymentD2[]')[N].value.replace(/,/g,'')*1;
     numD2+=ttlD2;
  }

  ttlCredit=numD0 + numD2;
  ttlDebit=numD1;

  if(ttlCredit != ttlDebit){return false;}else{return true;}
}

function PenerimaanPiutangInputQty0() {
    var i=document.getElementsByName('fnindexD0[]').length;
    for(var j=1;j<i;j++) {
      $fnpayment_method=document.getElementsByName('fnpayment_methodD0[]')[j].value*1;
      $ftgiro_no=document.getElementsByName('ftgiro_noD0[]')[j].value;

         if(document.getElementsByName('ftacc_noD0[]')[j].value=='') {
            alert('No. perkiraan harus di isi...');
            document.getElementsByName('ftacc_noD0[]')[j].focus();
            return false;
        }
        else if(document.getElementsByName('fnpayment_methodD0[]')[j].value=='') {
            alert('Metode Pembayaran harus di isi...');
            document.getElementsByName('fnpayment_methodD0[]')[j].focus();
            return false;
        }
        else if (($fnpayment_method==0 || $fnpayment_method==1)&&($ftgiro_no=='') ) {
            alert('No. Cek Atau giro belum di isi ...');
            document.getElementsByName('ftgiro_noD0[]')[j].focus();
            return false;
        }
        else if (($fnpayment_method==9) && ($ftgiro_no=='') ) {
            alert('No. Transaksi Uang Muka belum di isi ...');
            document.getElementsByName('ftgiro_noD0[]')[j].focus();
            return false;
        }
        else if(document.getElementsByName('fctotalD0[]')[j].value.replace(/,/g,'')*1==0) {
            alert('Pembayaran harus di isi...');
            document.getElementsByName('fcamountD0[]')[j].focus();
            return false;
        }
        else if ((document.getElementsByName('fcother_costD0[]')[j].value.replace(/,/g,'')*1 != 0)&&(document.getElementsByName('ftother_coa_codeD0[]')[j].value=='')) {
            alert('No. Perkiraan Biaya belum diisi ...');
            document.getElementsByName('ftother_coa_codeD0[]')[j].focus();
            return false;
        }

    }
    return true;
}
function PenerimaanPiutangInputQty1() {
    var i=document.getElementsByName('fnindexD1[]').length;
    for(var j=0;j<i;j++) {
        if(  document.getElementsByName('fcpayment_amountD[]')[j].value.replace(/,/g,'')*1> document.getElementsByName('fcoutstanding_amountD[]')[j].value.replace(/,/g,'')*1) {
            alert('Jumlah pembayaran melebihi jml Invoice ...');
            document.getElementsByName('fcpayment_amountD[]')[j].focus();
            return false;
        }
    }
    return true;
}

function PenerimaanPiutangInputQty2() {
    // Grid Other Cost
    var i=document.getElementsByName('fnindexD3[]').length;
    for(var j=0;j<i;j++) {
        if ((document.getElementsByName('fcamountD3[]')[j].value.replace(/,/g,'')*1 != 0)&&(document.getElementsByName('ftcoa_codeD3[]')[j].value=='')) {
            alert('No. Perkiraan Biaya Lain belum diisi ...');
            document.getElementsByName('ftcoa_codeD3[]')[j].focus();
            return false;
        }
    }
    return true;
}

function PenerimaanPiutangRecalQty0() {
    var i=document.getElementsByName('fnindexD0[]').length;
    var h=document.getElementsByName('fnindexD2[]').length;

    var fcamountxx=0;
    var fccm_amount=0;
    // alert(document.getElementsByName('fnindexD0[]').length);
   
    for(var j=1;j<i;j++) {
        //alert(document.getElementsByName('fcamountD0[]')[j].value.replace(/,/g,'')*1);
        var fctotal=document.getElementsByName('fcamountD0[]')[j].value.replace(/,/g,'')*1+document.getElementsByName('fcother_costD0[]')[j].value.replace(/,/g,'')*1;
        document.getElementsByName('fctotalD0[]')[j].value=fctotal;
        document.getElementsByName('fctotal_baseD0[]')[j].value=fctotal * (document.getElementById('fcrate').value.replace(/,/g,'')*1);
        ElementCurrencyOnBlur(document.getElementsByName('fctotalD0[]')[j]);
        ElementCurrencyOnBlur(document.getElementsByName('fctotal_baseD0[]')[j]);
        fcamountxx+=document.getElementsByName('fctotalD0[]')[j].value.replace(/,/g,'')*1; 
    }

    // for(var j=0;j<h;j++) {
    //     fccm_amount+=document.getElementsByName('fccm_paymentD2[]')[j].value.replace(/,/g,'')*1;
    // }

    PenerimaanPiutangRecalQty1();
    PenerimaanPiutangRecalOtherCost();

    document.getElementById('fcsub_amount').value= document.getElementById('fcinvoice_amount').value;
    // document.getElementById('fcamount').value=fcamountxx + (document.getElementById('fcother_cost').value.replace(/,/g,'')*1);
    document.getElementById('fcamount').value=fcamountxx;

    document.getElementById('fcsub_amount_base').value=(document.getElementById('fcsub_amount_base').value.replace(/,/g,'')*1);
    document.getElementById('fcamount_base').value=(document.getElementById('fcamount').value.replace(/,/g,'')*1) * (document.getElementById('fcrate').value.replace(/,/g,'')*1);
    document.getElementById('fcrate_adjustment').value=(document.getElementById('fcsub_amount_base').value.replace(/,/g,'')*1) - ((document.getElementById('fcamount_base').value.replace(/,/g,'')*1) + (document.getElementById('fcother_cost').value.replace(/,/g,'')*1));

    // document.getElementById('fcamountxx').value=document.getElementById('fcamount').value;

    ElementCurrencyALL();
}

function PenerimaanPiutangRecalQty1() {
    var i=document.getElementsByName('fnindexD1[]').length;
    var fcinvoice_amount=0;
    var fcinvoice_amount_base=0;

    for(var j=0;j<i;j++) {
        fcinvoice_amount+=document.getElementsByName('fcpayment_amountD1[]')[j].value.replace(/,/g,'')*1;
        document.getElementsByName('fcpayment_amount_baseD1[]')[j].value=(document.getElementsByName('fcpayment_amountD1[]')[j].value.replace(/,/g,'')*1) * (document.getElementsByName('fcrate_invoiceD1[]')[j].value.replace(/,/g,'')*1);
        fcinvoice_amount_base+=document.getElementsByName('fcpayment_amount_baseD1[]')[j].value.replace(/,/g,'')*1;
        ElementCurrencyOnBlur(document.getElementsByName('fcpayment_amount_baseD1[]')[j]);
    }

    document.getElementById('fcinvoice_amount').value=fcinvoice_amount;
    document.getElementById('fcsub_amount_base').value=fcinvoice_amount_base;

    ElementCurrencyALL();
}

function PenerimaanPiutangRecalQty2() {
    var i=document.getElementsByName('fnindexD2[]').length;
    var fccm_amount=0;
    var fcinvoice_amount=document.getElementById('fcinvoice_amount').value.replace(/,/g,'')*1;
    var fcsub_amount=document.getElementById('fcsub_amount').value.replace(/,/g,'')*1;
    // for(var j=0;j<i;j++) {
    //    fccm_amount+=document.getElementsByName('fccm_paymentD2[]')[j].value.replace(/,/g,'')*1;
    // }

    // document.getElementById('fcsub_amount').value=fccm_amount + fcsub_amount;

    // if(fcinvoice_amount != 0){
    //   document.getElementById('fcother_cost').value=fcinvoice_amount - fccm_amount;
    // }else{
    //   document.getElementById('fcother_cost').value=0;
    // }

    ElementCurrencyALL();
}

function PenerimaanPiutangRecalOtherCost() {
  var i=document.getElementsByName('fnindexD3[]').length;
  var fcamount=0;

  for(var j=0;j<i;j++) {
    fcamount+=document.getElementsByName('fcamountD3[]')[j].value.replace(/,/g,'')*1;
  }

  document.getElementById('fcother_cost').value=fcamount;

}


function PenerimaanPiutangCheckCurrency() {
    var i=document.getElementsByName('fnindexD1[]').length;

    var ftcurrency_code = '';

    for(var j=0;j<i;j++) {
        if (document.getElementsByName('fcpayment_amountD1[]')[j].value.replace(/,/g,'') > 0) {
            if (ftcurrency_code != '') {
                if (ftcurrency_code != document.getElementsByName('ftcurrency_codeD1[]')[j].value.replace(/,/g,'')) {
                    alert('Invoice yang dipilih harus dari kode currency yang sama. ');
                    return false;
                }
            }
            ftcurrency_code = document.getElementsByName('ftcurrency_codeD1[]')[j].value.replace(/,/g,'');

            if (document.getElementById('ftcurrency_code').value.replace(/,/g,'') != 'IDR') {
                if (ftcurrency_code != document.getElementById('ftcurrency_code').value.replace(/,/g,'')) {
                    alert('Mata uang pembayaran harus IDR atau dari kode currency yang sama. ');
                    return false;
                }
            }

        }
    }

    return true;
}

function RevisiPenerimaanPiutang() {
      PenerimaanPiutangRecalQty0();
      PenerimaanPiutangRecalQty1();

      if(document.getElementById("ftar_no").value=='') {
           alert('No. transaksi harus di isi...');
           document.getElementById("ftar_no").focus();
           return false;
      }
      if(document.getElementById("hidden_ftcustomer_code").value=='') {
           alert('Customer belum valid...');
           document.getElementById("ftcustomer_code").focus();
           return false;
      }
       else if(document.getElementsByName('fnindexD0[]').length==1) {
          alert('Detail transaksi belum di input ...');
          return false;
      }
      else if (PenerimaanPiutangInputQty0()==false) {
           return false;
      }
      else if (document.getElementById("ftcurrency_code").value=='IDR') {
            j=document.getElementsByName('fnindexD1[]').length;
            var valamount = true;

            for(i=0; i < j; i++){
                if (document.getElementsByName('ftcurrency_codeD1[]')[i].value!='IDR' && document.getElementsByName('fcpayment_amountD1[]')[i].value > 0 ) {
                    valamount = false;
                    break;
                }
            }

            if (valamount) {
                // if ( (document.getElementById('fcsub_amount').value.replace(/,/g,'')*1) != document.getElementById('fcamount').value.replace(/,/g,'')*1) {
                if ( (document.getElementById('fcsub_amount').value.replace(/,/g,'')*1) != ((document.getElementById('fcamount').value.replace(/,/g,'')*1) + (document.getElementById('fcother_cost').value.replace(/,/g,'')*1))) {
                    alert('Nominal pembayaran dan piutang belum balance');
                    return false;
                }
            } else {
                retvalue = confirm ("Anda yakin transaksi tetap disimpan ? Ada Selisih Kurs sebesar" + document.getElementById("fcrate_adjustment").value);
                if (retvalue == false) return false;
            }
      }
      else if (document.getElementById("ftcurrency_code").value!='IDR') {
            // if ( (document.getElementById('fcsub_amount').value.replace(/,/g,'')*1) != document.getElementById('fcamount').value.replace(/,/g,'')*1) {
            if ( (document.getElementById('fcsub_amount').value.replace(/,/g,'')*1) != ((document.getElementById('fcamount').value.replace(/,/g,'')*1) + (document.getElementById('fcother_cost').value.replace(/,/g,'')*1))) {
                
                alert('Nominal pembayaran dan hutang belum balance');
                return false;
            }

            retvalue = confirm ("Anda yakin transaksi tetap disimpan ? Ada Selisih Kurs sebesar" + document.getElementById("fcrate_adjustment").value);
            if (retvalue == false) return false;
      }
      
      var j=document.getElementsByName('fnindexD0[]').length;
      var method="";
      var nogiro="";
      for(i=1; i < j; i++){
        if(method!="") method+="___";
        if(nogiro!="") nogiro+="___";
        method+=document.getElementsByName('fnpayment_methodD0[]')[i].value;
        nogiro+=document.getElementsByName('ftgiro_noD0[]')[i].value;
      }

    return true;
}

//Credit Memo

function Hitungcm() {
    var i=document.getElementsByName('fnindexD2[]').length;
    var fcinvoice_amount=0;
    for(var j=0;j<i;j++) {
        fcinvoice_amount+=document.getElementsByName('fccm_paymentD2[]')[j].value.replace(/,/g,'')*1;
    }
    document.getElementById('fccm_min').value=fcinvoice_amount;
    ElementCurrencyALL();
}

function ValCreditMemo() {
  CreditMemoRecalQty();
  if(document.getElementById("ftcm_no").value=='') {
       alert('No. transaksi harus di isi...');
       document.getElementById("ftcm_no").focus();
       return false;
  }
 else if(document.getElementById("hidden_ftcustomer_code").value=='') {
       alert('Customer belum valid...');
       document.getElementById("ftcustomer_code").focus();
       return false;
  }
 else if(document.getElementById("fntrans_type").value=='') {
       alert('Jenis credit memo harus di isi...');
       document.getElementById("fntrans_type").focus();
       return false;
  }
   else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }
  else if (CreditMemoInputQty()==false) {
       return false;
  }
  else if(document.getElementById('fcinvoice_amount').value.replace(/,/g,'')*1<=0) {
      alert('Jml. Credit memo belum di isi ...');
      return false;
  }

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

  return false;
}

function CreditMemoInputQty() {
    var i=document.getElementsByName('fnindexD0[]').length;

    for(var j=1;j<i;j++) {
        if(document.getElementById("fntrans_type").value!=3) {
            if(document.getElementsByName('ftsales_invoice_noD0[]')[j].value=='') {
                alert('No. Sales Invoice harus di isi ..');
                document.getElementsByName('ftsales_invoice_noD0[]')[j].focus();
                return false;
            }
            else if(document.getElementsByName('fccredit_amountD0[]')[j].value.replace(/,/g,'')*1<=0) {
                alert('Jml. Credit memo harus lebih besar 0 ..');
                 document.getElementsByName('fccredit_amountD0[]')[j].focus();
                 return false;
            }
            else if(document.getElementsByName('fcoutstanding_credit_memoD0[]')[j].value.replace(/,/g,'')*1<document.getElementsByName('fccredit_amountD0[]')[j].value.replace(/,/g,'')*1) {
                alert('Jml. Credit memo tidak boleh melebihi jml credit memo yg sudah dipakai untuk invoice tersebut ...');
                  document.getElementsByName('fccredit_amountD0[]')[j].focus();
                 return false;
            }

            else if(document.getElementsByName('fcinvoice_amountD0[]')[j].value.replace(/,/g,'')*1<document.getElementsByName('fccredit_amountD0[]')[j].value.replace(/,/g,'')*1) {
                alert('Jml. Credit memo tidak boleh melebihi jml invoice ..');
                  document.getElementsByName('fccredit_amountD0[]')[j].focus();
                 return false;
            }

        }
        else {
             if(document.getElementsByName('fccredit_amountD0[]')[j].value.replace(/,/g,'')*1<=0) {
                alert('Jml. Credit memo harus lebih besar 0 ..');
                  document.getElementsByName('fccredit_amountD0[]')[j].focus();
                 return false;
            }
        }
    }

    return true;
}

function CreditMemoRecalQty() {

    var i=document.getElementsByName('fnindexD0[]').length;
    var fccredit_amount=0;
    for(var j=1;j<i;j++) {
        fccredit_amount+=document.getElementsByName('fccredit_amountD0[]')[j].value.replace(/,/g,'')*1;
    }

    document.getElementById('fcinvoice_amount').value=fccredit_amount;
    document.getElementById('fcoutstanding_amount').value=fccredit_amount;
    document.getElementById('fccredit_amount').value=0;
}


//Proyeksi Pembayaran
function ValProyeksiPembayaran() {

  if(document.getElementById("ftpp_no").value=='') {
       alert('No. transaksi harus di isi...');
       document.getElementById("ftpp_no").focus();
       return false;
  }
  else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }
  else if(ProyeksiPembayaranInputQty0()==false) {
      return false;
  }

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

  return false;
}
function ProyeksiPembayaranInputQty0() {
    var i=document.getElementsByName('fnindexD0[]').length;
    for(var j=1;j<i;j++) {
        if(document.getElementsByName('hidden_ftsupplier_codeD0[]')[j].value=='') {
            alert('Supplier belum valid...');
            document.getElementsByName('ftsupplier_codeD0[]')[j].focus();
            return false;
        }
        else if(document.getElementsByName('ftpo_noD0[]')[j].value=='') {
            alert('PO tidak boleh kosong ...');
            document.getElementsByName('ftpo_noD0[]')[j].focus();
            return false;
        }

        else if ((document.getElementsByName('fcamountD0[]')[j].value*1<=0 )&&(document.getElementsByName('fcamountUSDD0[]')[j].value*1<=0 )) {
            alert('Jumlah belum di isi ...');
            document.getElementsByName('fcamountD0[]')[j].focus();
            return false;
        }
//          else if(document.getElementsByName('ftcv_noD0[]')[j].value.replace(/,/g,'')*1==0) {
//            alert('No. CV tidak boleh kosong ...');
//            document.getElementsByName('ftcv_noD0[]')[j].focus();
//            return false;
//        }
          else if(document.getElementsByName('ftreceipt_noD0[]')[j].value.replace(/,/g,'')*1==0) {
            alert('No. Tanda Terima tidak boleh kosong ...');
            document.getElementsByName('ftreceipt_noD0[]')[j].focus();
            return false;
        }
          else if(document.getElementsByName('ftacc_noD0[]')[j].value.replace(/,/g,'')*1==0) {
            alert('No. Perkiraan/Bank harus diisi ...');
            document.getElementsByName('ftacc_noD0[]')[j].focus();
            return false;
        }

    }
    return true;
}


function ValPembayaranHutang() {
  var retvalue;
  var j = 0;
  
  RekapBankVoucherRecalQty0();

  if(document.getElementById("ftcvs_no").value=='') {
       alert('No. transaksi harus di isi...');
       document.getElementById("ftcvs_no").focus();
       return false;
  }
  else if(document.getElementById("hidden_ftsupplier_code").value=='') {
       alert('supplier belum valid...');
       document.getElementById("ftsupplier_code").focus();
       return false;
  }
  else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }
  else if (RekapBankVoucherInputQty0()==false) {
       return false;
  }
  else if (RekapBankVoucherInputQty1()==false) {
       return false;
  }
  else if (RekapBankVoucherInputQty2()==false) {
       return false;
  }
  else if (document.getElementById("ftcurrency_code").value=='IDR') {
        j=document.getElementsByName('fnindexD1[]').length;
        var valamount = true;

        for(i=0; i < j; i++){
            if (document.getElementsByName('ftcurrency_codeD1[]')[i].value!='IDR' && document.getElementsByName('fcpayment_amountUSDD1[]')[i].value.replace(/,/g,'')*1 > 0 ) {
                valamount = false;
                break;
            }
        }

        if (valamount) {
            if ( ((document.getElementById('fcsub_amount').value.replace(/,/g,'')*1) + (document.getElementById('fcother_cost').value.replace(/,/g,'')*1)) != document.getElementById('fcamount').value.replace(/,/g,'')*1) {
                alert('Nominal pembayaran dan hutang belum balance');
                return false;
            }
        } else {
            retvalue = confirm ("Anda yakin transaksi tetap disimpan ? Ada Selisih Kurs sebesar" + document.getElementById("fcrate_adjustment").value);
            if (retvalue == false) return false;
        }
  }
  else if (document.getElementById("ftcurrency_code").value!='IDR') {
        
        retvalue = confirm ("Anda yakin transaksi tetap disimpan ? Ada Selisih Kurs sebesar" + document.getElementById("fcrate_adjustment").value);
        if (retvalue == false) return false;
  }
  
  j=document.getElementsByName('fnindexD0[]').length;
  var method="";
  var nogiro="";
  for(i=1; i < j; i++){
    if(method!="") method+="___";
    if(nogiro!="") nogiro+="___";
    method+=document.getElementsByName('fnpayment_methodD0[]')[i].value;
    nogiro+=document.getElementsByName('ftgiro_noD0[]')[i].value;
  }

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

  return false;
}

function RevisiPembayaranHutang() {
      var retvalue;
      var j = 0;

      RekapBankVoucherRecalQty0();

      if(document.getElementById("ftcvs_no").value=='') {
           alert('No. transaksi harus di isi...');
           document.getElementById("ftcvs_no").focus();
           return false;
      }
      else if(document.getElementById("hidden_ftsupplier_code").value=='') {
           alert('supplier belum valid...');
           document.getElementById("ftsupplier_code").focus();
           return false;
      }
      else if(document.getElementsByName('fnindexD0[]').length==1) {
          alert('Detail transaksi belum di input ...');
          return false;
      }
      else if (RekapBankVoucherInputQty0()==false) {
           return false;
      }
      else if (RekapBankVoucherInputQty1()==false) {
           return false;
      }
      else if (RekapBankVoucherInputQty2()==false) {
           return false;
      }
      else if (document.getElementById("ftcurrency_code").value=='IDR') {
            j=document.getElementsByName('fnindexD1[]').length;
            var valamount = true;

            for(i=0; i < j; i++){
                if (document.getElementsByName('ftcurrency_codeD1[]')[i].value!='IDR' && document.getElementsByName('fcpayment_amountUSDD1[]')[i].value.replace(/,/g,'')*1 > 0 ) {
                    valamount = false;
                    break;
                }
            }

            if (valamount) {
                if ( ((document.getElementById('fcsub_amount').value.replace(/,/g,'')*1) + (document.getElementById('fcother_cost').value.replace(/,/g,'')*1)) != document.getElementById('fcamount').value.replace(/,/g,'')*1) {
                    alert('Nominal pembayaran dan hutang belum balance');
                    return false;
                }
            } else {
                retvalue = confirm ("Anda yakin transaksi tetap disimpan ? Ada Selisih Kurs sebesar" + document.getElementById("fcrate_adjustment").value);
                if (retvalue == false) return false;
            }
      }
      else if (document.getElementById("ftcurrency_code").value!='IDR') {
            if ( ((document.getElementById('fcsub_amountUSD').value.replace(/,/g,'')*1) + (document.getElementById('fcother_costUSD').value.replace(/,/g,'')*1)) != document.getElementById('fcamountUSD').value.replace(/,/g,'')*1) {
                alert('Nominal pembayaran dan hutang belum balance');
                return false;
            }

            retvalue = confirm ("Anda yakin transaksi tetap disimpan ? Ada Selisih Kurs sebesar" + document.getElementById("fcrate_adjustment").value);
            if (retvalue == false) return false;
      }

      j=document.getElementsByName('fnindexD0[]').length;
      var method="";
      var nogiro="";
      for(i=1; i < j; i++){
        if(method!="") method+="___";
        if(nogiro!="") nogiro+="___";
        method+=document.getElementsByName('fnpayment_methodD0[]')[i].value;
        nogiro+=document.getElementsByName('ftgiro_noD0[]')[i].value;
      }

    return true;
}

function FinalPembayaranHutang() {
  RekapBankVoucherRecalQty0();
  
  if(document.getElementById("ftcvs_no").value=='') {
       alert('No. transaksi harus di isi...');
       document.getElementById("ftcvs_no").focus();
       return false;
  }
  else if(document.getElementById("hidden_ftsupplier_code").value=='') {
       alert('supplier belum valid...');
       document.getElementById("ftsupplier_code").focus();
       return false;
  }
  else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }
  else if (RekapBankVoucherInputQty0()==false) {
       return false;
  }
  else if (RekapBankVoucherInputQty1()==false) {
       return false;
  }
  else if (RekapBankVoucherInputQty2()==false) {
       return false;
  }

  /*else if ( document.getElementById('fcamount').value.replace(/,/g,'')*1!=document.getElementById('fcsub_amount').value.replace(/,/g,'')*1) {
       alert('transaksi belum balance...');
        return false;
  }*/

  ajax_do(str_url + '&ajax=1&code=transno2&fttrans_no=' + document.getElementById('ftcvs_no').value);
  
  return false;
}


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

        if(document.getElementsByName('ftacc_noD0[]')[j].value=='') {
            alert('No. Perkiraan tidak boleh kosong ...');
            document.getElementsByName('ftacc_noD0[]')[j].focus();
            return false;
        }
        else if(document.getElementsByName('fnpayment_methodD0[]')[j].value=='') {
            alert('Metode Pembayaran tidak boleh kosong ...');
            document.getElementsByName('fnpayment_methodD0[]')[j].focus();
            return false;
        }
        else if (((document.getElementsByName('fnpayment_methodD0[]')[j].value*1==0)||(document.getElementsByName('fnpayment_methodD0[]')[j].value*1==1))&&(document.getElementsByName('ftgiro_noD0[]')[j].value=='') ) {
            alert('No. Cek Atau giro belum di isi ...');
            document.getElementsByName('ftgiro_noD0[]')[j].focus();
            return false;
        }
        else if ((document.getElementsByName('fnpayment_methodD0[]')[j].value*1==9)&&(document.getElementsByName('ftgiro_noD0[]')[j].value=='') ) {
            alert('No. Transaksi Uang Muka belum di isi ...');
            document.getElementsByName('ftgiro_noD0[]')[j].focus();
            return false;
        }
        else if(document.getElementsByName('fctotalD0[]')[j].value.replace(/,/g,'')*1==0) {
            alert('Pembayaran tidak boleh kosong ...');
            document.getElementsByName('fcamountD0[]')[j].focus();
            return false;
        }
        else if ((document.getElementsByName('fcother_costUSDD0[]')[j].value.replace(/,/g,'')*1 != 0)&&(document.getElementsByName('ftother_coa_codeD0[]')[j].value=='')) {
            alert('No. Perkiraan Biaya belum diisi ...');
            document.getElementsByName('ftother_coa_codeD0[]')[j].focus();
            return false;
        }

    }
    return true;
}
function RekapBankVoucherInputQty1() {
    /*var i=document.getElementsByName('fnindexD1[]').length;
    for(var j=0;j<i;j++) {
        if(  document.getElementsByName('fcpayment_amountD[]')[j].value.replace(/,/g,'')*1> document.getElementsByName('fcoutstanding_amountD[]')[j].value.replace(/,/g,'')*1) {
            alert('Jumlah pembayaran IDR melebihi jml Tagihan ...');
            document.getElementsByName('fcpayment_amountD[]')[j].focus();
            return false;
        }
        if(  document.getElementsByName('fcpayment_amountUSDD[]')[j].value.replace(/,/g,'')*1> document.getElementsByName('fcoutstanding_amountUSDD[]')[j].value.replace(/,/g,'')*1) {
            alert('Jumlah pembayaran USD melebihi jml Tagihan ...');
            document.getElementsByName('fcpayment_amountUSDD[]')[j].focus();
            return false;
        }
    }*/
    return true;
}

function RekapBankVoucherInputQty2() {
    // Grid Other Cost
    var i=document.getElementsByName('fnindexD2[]').length;
    for(var j=0;j<i;j++) {
        if ((document.getElementsByName('fcamountD2[]')[j].value.replace(/,/g,'')*1 != 0)&&(document.getElementsByName('ftcoa_codeD2[]')[j].value=='')) {
            alert('No. Perkiraan Biaya Lain belum diisi ...');
            document.getElementsByName('ftcoa_codeD2[]')[j].focus();
            return false;
        }
    }
    return true;
}

function RekapBankVoucherRecalQty0() {
  var i=document.getElementsByName('fnindexD0[]').length;
  var fcamountxx=0;
  var fcamountxx2=0;
  var fcamountxx3=0;
  var fcamountxx4=0;

  for(var j=1;j<i;j++) {
    document.getElementsByName('fcamountD0[]')[j].value=document.getElementsByName('fcamountUSDD0[]')[j].value.replace(/,/g,'') * document.getElementById('fckurs').value.replace(/,/g,'');
    document.getElementsByName('fcother_costD0[]')[j].value=document.getElementsByName('fcother_costUSDD0[]')[j].value.replace(/,/g,'') * document.getElementById('fckurs').value.replace(/,/g,'');
    document.getElementsByName('fctotalUSDD0[]')[j].value=(document.getElementsByName('fcother_costUSDD0[]')[j].value.replace(/,/g,'')*1) + (document.getElementsByName('fcamountUSDD0[]')[j].value.replace(/,/g,'') * 1);
    document.getElementsByName('fctotalD0[]')[j].value=document.getElementsByName('fctotalUSDD0[]')[j].value.replace(/,/g,'') * document.getElementById('fckurs').value.replace(/,/g,'');

    fcamountxx+=document.getElementsByName('fctotalUSDD0[]')[j].value.replace(/,/g,'')*1;
    fcamountxx2+=document.getElementsByName('fctotalD0[]')[j].value.replace(/,/g,'')*1;
  }

  document.getElementById('fcamountUSD').value=fcamountxx;
  document.getElementById('fcamount').value=fcamountxx2;

  RekapBankVoucherRecalOtherCost();
  RekapBankVoucherRecalQty1();

}

function RekapBankVoucherRecalQty1() {
    var i=document.getElementsByName('fnindexD1[]').length;
    var fcinvoice_amount=0;
    var fcinvoice_amountUSD=0;
    var fckurs = 1;
    var ftcurrency=document.getElementById('ftcurrency_code').value;
    var ftcurrency2='IDR';

    for(var j=0;j<i;j++) {
        fckurs = document.getElementsByName('fckursD1[]')[j].value.replace(/,/g,'') * 1;
        document.getElementsByName('fcamountD1[]')[j].value=document.getElementsByName('fcamountUSDD1[]')[j].value.replace(/,/g,'') * fckurs;
        document.getElementsByName('fcoutstanding_amountD1[]')[j].value=(document.getElementsByName('fcoutstanding_amountUSDD1[]')[j].value.replace(/,/g,'')*1) * fckurs;

        document.getElementsByName('fcpayment_amountD1[]')[j].value=document.getElementsByName('fcpayment_amountUSDD1[]')[j].value.replace(/,/g,'') * fckurs;

        fcinvoice_amountUSD+=document.getElementsByName('fcpayment_amountUSDD1[]')[j].value.replace(/,/g,'') * 1;
        fcinvoice_amount+=document.getElementsByName('fcpayment_amountD1[]')[j].value.replace(/,/g,'') * 1;
        
        if ((document.getElementsByName('ftcurrency_codeD1[]')[j].value != "IDR") && (document.getElementsByName('fcpayment_amountD1[]')[j].value != 0)) {
            ftcurrency2 = document.getElementsByName('ftcurrency_codeD1[]')[j].value;
        }
    }

    document.getElementById('fcother_cost').value = (document.getElementById('fcother_costUSD').value.replace(/,/g,'')*1) * (document.getElementById('fckurs').value.replace(/,/g,'')*1);

    document.getElementById('fcinvoice_amount').value=fcinvoice_amount;
    document.getElementById('fcsub_amount').value = (document.getElementById('fcinvoice_amount').value.replace(/,/g,'')*1);
    // document.getElementById('fcamount').value = (document.getElementById('fcamount').value.replace(/,/g,'')*1) + ((document.getElementById('fcother_costUSD').value.replace(/,/g,'')*1) * (document.getElementById('fckurs').value.replace(/,/g,'')*1));
    document.getElementById('fcamount').value = (document.getElementById('fcamount').value.replace(/,/g,'')*1);

    document.getElementById('fcinvoice_amountUSD').value=fcinvoice_amountUSD;
    document.getElementById('fcsub_amountUSD').value = (document.getElementById('fcinvoice_amountUSD').value.replace(/,/g,'')*1);
    // document.getElementById('fcamountUSD').value = (document.getElementById('fcamountUSD').value.replace(/,/g,'')*1) + (document.getElementById('fcother_costUSD').value.replace(/,/g,'')*1) ;
    document.getElementById('fcamountUSD').value = (document.getElementById('fcamountUSD').value.replace(/,/g,'')*1);

    if (ftcurrency2 == "IDR") {
        document.getElementById('fcrate_adjustment').value=0;
    } else {
        document.getElementById('fcrate_adjustment').value=(document.getElementById('fcsub_amount').value.replace(/,/g,'')*1) - (document.getElementById('fcamount').value.replace(/,/g,'')*1) + ((document.getElementById('fcother_costUSD').value.replace(/,/g,'')*1) * (document.getElementById('fckurs').value.replace(/,/g,'')*1));
    }   
    
    ElementCurrencyALL();
    
}

function RekapBankVoucherRecalQty2(index) {
   var i=document.getElementsByName('fnindexD1[]').length;

   if(document.getElementById('chk_includeD1'+index).checked == true) {
       document.getElementById('fcpayment_amountUSDD1'+index).value=document.getElementById('fcoutstanding_amountUSDD1'+index).value;
       document.getElementById('fcpayment_amountD1'+index).value=document.getElementById('fcpayment_amountUSDD1'+index).value.replace(/,/g,'')*document.getElementById('fckurs').value.replace(/,/g,'');
       document.getElementById('hd_includeD1'+index).value=1;
   }
   else {
        document.getElementById('hd_includeD1'+index).value=0;
   }

   RekapBankVoucherRecalQty1();
}


function RekapBankVoucherRecalOtherCost() {
  var i=document.getElementsByName('fnindexD2[]').length;
  var fcamount=0;
  
  for(var j=0;j<i;j++) {
    fcamount+=document.getElementsByName('fcamountD2[]')[j].value.replace(/,/g,'')*1;
  }
  
  document.getElementById('fcother_costUSD').value=fcamount;
  document.getElementById('fcother_cost').value =fcamount * document.getElementById('fckurs').value;
  
}

function ValPembayaranHutangImport() {
  var retvalue;
  var j = 0;

  RekapBankVoucherRecalQtyImport0();

  if(document.getElementById("ftcvs_no").value=='') {
       alert('No. transaksi harus di isi...');
       document.getElementById("ftcvs_no").focus();
       return false;
  }
  else if(document.getElementById("hidden_ftsupplier_code").value=='') {
       alert('supplier belum valid...');
       document.getElementById("ftsupplier_code").focus();
       return false;
  }
  else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }
  else if (RekapBankVoucherInputQtyImport0()==false) {
       return false;
  }
  else if (RekapBankVoucherInputQtyImport1()==false) {
       return false;
  }
  else if (RekapBankVoucherInputQtyImport2()==false) {
       return false;
  }
  else if (document.getElementById("ftcurrency_code").value=='IDR') {
        j=document.getElementsByName('fnindexD1[]').length;
        var valamount = true;
        
        for(i=0; i < j; i++) {
            if (document.getElementsByName('ftcurrency_codeD1[]')[i].value!='IDR' && document.getElementsByName('fcpayment_amountUSDD1[]')[i].value.replace(/,/g,'')*1 > 0 ) {
                valamount = false;
                break;
            }
        }

        if (valamount) {
            if ( ((document.getElementById('fcsub_amount').value.replace(/,/g,'')*1) + (document.getElementById('fcother_cost').value.replace(/,/g,'')*1)) != document.getElementById('fcamount').value.replace(/,/g,'')*1) {
                alert('Nominal pembayaran dan hutang belum balance');
                return false;
            }
        } else {
            retvalue = confirm ("Anda yakin transaksi tetap disimpan ? Ada Selisih Kurs sebesar" + document.getElementById("fcrate_adjustment").value);
            if (retvalue == false) return false;
        }
  }
  else if (document.getElementById("ftcurrency_code").value!='IDR') {
        
        retvalue = confirm ("Anda yakin transaksi tetap disimpan ? Ada Selisih Kurs sebesar" + document.getElementById("fcrate_adjustment").value);
        if (retvalue == false) return false;
  }
  
    j=document.getElementsByName('fnindexD0[]').length;
  var method="";
  var nogiro="";
  for(i=1; i < j; i++){
    if(method!="") method+="___";
    if(nogiro!="") nogiro+="___";
    method+=document.getElementsByName('fnpayment_methodD0[]')[i].value;
    nogiro+=document.getElementsByName('ftgiro_noD0[]')[i].value;
  }
  
  ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftcvs_no').value + '&method=' + method + '&nogiro=' + nogiro);

  return false;
}

function FinalPembayaranHutangImport() {
  RekapBankVoucherRecalQtyImport0();
  if(document.getElementById("ftcvs_no").value=='') {
       alert('No. transaksi harus di isi...');
       document.getElementById("ftcvs_no").focus();
       return false;
  }
  else if(document.getElementById("hidden_ftsupplier_code").value=='') {
       alert('supplier belum valid...');
       document.getElementById("ftsupplier_code").focus();
       return false;
  }
  else if(document.getElementById("ftcurrency_code").value=='') {
       alert('Mata uang belum dipilih...');
       document.getElementById("ftcurrency_code").focus();
       return false;
  }
   else if((document.getElementById("ftcurrency_code").value=='IDR')&&(document.getElementById("fckurs").value.replace(/,/g,'')*1!=1)) {
       alert('Kurs IDR harus "1"...');
        document.getElementById("fckurs").value=1;
       document.getElementById("fckurs").focus();
       return false;
  }
  else if(document.getElementById("fckurs").value.replace(/,/g,'')*1<1) {
       alert('Kurs mata uang harus lebih besar 0...');
       document.getElementById("fckurs").focus();
       return false;
  }
  else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }
  else if (RekapBankVoucherInputQtyImport0()==false) {
       return false;
  }
   else if (RekapBankVoucherInputQtyImport1()==false) {
       return false;
  }
  else if (RekapBankVoucherInputQtyImport2()==false) {
       return false;
  }

   // else if ( (document.getElementById('fcamount').value.replace(/,/g,'')*1)-(document.getElementById('fcother_costIDR').value.replace(/,/g,'')*1)+(document.getElementById('fcother_costIDRx').value.replace(/,/g,'')*1)!=document.getElementById('fcsub_amount').value.replace(/,/g,'')*1) {
   /*else if ( (document.getElementById('fcamount').value.replace(/,/g,'')*1)-(document.getElementById('fcother_costIDR').value.replace(/,/g,'')*1)+(document.getElementById('fcother_costUSDx').value.replace(/,/g,'')*1)+(document.getElementById('fcother_costIDRx').value.replace(/,/g,'')*1)!=document.getElementById('fcsub_amount').value.replace(/,/g,'')*1) {
  
   alert('transaksi belum balance...');
        return false;
  }*/

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

  return false;
}

function RevisiPembayaranHutangImport() {
      var retvalue;
      var j = 0;

      RekapBankVoucherRecalQtyImport0();

      if(document.getElementById("ftcvs_no").value=='') {
           alert('No. transaksi harus di isi...');
           document.getElementById("ftcvs_no").focus();
           return false;
      }
      else if(document.getElementById("hidden_ftsupplier_code").value=='') {
           alert('supplier belum valid...');
           document.getElementById("ftsupplier_code").focus();
           return false;
      }
      else if(document.getElementsByName('fnindexD0[]').length==1) {
          alert('Detail transaksi belum di input ...');
          return false;
      }
      else if (RekapBankVoucherInputQtyImport0()==false) {
           return false;
      }
      else if (RekapBankVoucherInputQtyImport1()==false) {
           return false;
      }
      else if (RekapBankVoucherInputQtyImport2()==false) {
           return false;
      }
      else if (document.getElementById("ftcurrency_code").value=='IDR') {
            j=document.getElementsByName('fnindexD1[]').length;
            var valamount = true;

            for(i=0; i < j; i++){
                if (document.getElementsByName('ftcurrency_codeD1[]')[i].value!='IDR' && document.getElementsByName('fcpayment_amountUSDD1[]')[i].value.replace(/,/g,'')*1 > 0 ) {
                    valamount = false;
                    break;
                }
            }

            if (valamount) {
                if ( ((document.getElementById('fcsub_amount').value.replace(/,/g,'')*1) + (document.getElementById('fcother_cost').value.replace(/,/g,'')*1)) != document.getElementById('fcamount').value.replace(/,/g,'')*1) {
                    alert('Nominal pembayaran dan hutang belum balance');
                    return false;
                }
            } else {
                retvalue = confirm ("Anda yakin transaksi tetap disimpan ? Ada Selisih Kurs sebesar" + document.getElementById("fcrate_adjustment").value);
                if (retvalue == false) return false;
            }
      }
      else if (document.getElementById("ftcurrency_code").value!='IDR') {
            if ( ((document.getElementById('fcsub_amountUSD').value.replace(/,/g,'')*1) + (document.getElementById('fcother_costUSD').value.replace(/,/g,'')*1)) != document.getElementById('fcamountUSD').value.replace(/,/g,'')*1) {
                alert('Nominal pembayaran dan hutang belum balance');
                return false;
            }

            retvalue = confirm ("Anda yakin transaksi tetap disimpan ? Ada Selisih Kurs sebesar" + document.getElementById("fcrate_adjustment").value);
            if (retvalue == false) return false;
      }

      j=document.getElementsByName('fnindexD0[]').length;
      var method="";
      var nogiro="";
      for(i=1; i < j; i++){
        if(method!="") method+="___";
        if(nogiro!="") nogiro+="___";
        method+=document.getElementsByName('fnpayment_methodD0[]')[i].value;
        nogiro+=document.getElementsByName('ftgiro_noD0[]')[i].value;
      }

    return true;
}

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

        if(document.getElementsByName('ftacc_noD0[]')[j].value=='') {
            alert('No. Perkiraan tidak boleh kosong ...');
            document.getElementsByName('ftacc_noD0[]')[j].focus();
            return false;
        }
        else if(document.getElementsByName('fnpayment_methodD0[]')[j].value=='') {
            alert('Metode Pembayaran tidak boleh kosong ...');
            document.getElementsByName('fnpayment_methodD0[]')[j].focus();
            return false;
        }
        else if (((document.getElementsByName('fnpayment_methodD0[]')[j].value*1==0)||(document.getElementsByName('fnpayment_methodD0[]')[j].value*1==1))&&(document.getElementsByName('ftgiro_noD0[]')[j].value=='') ) {
            alert('No. Cek Atau giro belum di isi ...');
            document.getElementsByName('ftgiro_noD0[]')[j].focus();
            return false;
        }
        else if ((document.getElementsByName('fnpayment_methodD0[]')[j].value*1==9)&&(document.getElementsByName('ftgiro_noD0[]')[j].value=='') ) {
            alert('No. Transaksi Uang Muka belum di isi ...');
            document.getElementsByName('ftgiro_noD0[]')[j].focus();
            return false;
        }
        else if(document.getElementsByName('fctotalD0[]')[j].value.replace(/,/g,'')*1==0) {
            alert('Pembayaran tidak boleh kosong ...');
            document.getElementsByName('fcamountD0[]')[j].focus();
            return false;
        }
        else if ((document.getElementsByName('fcother_costUSDD0[]')[j].value.replace(/,/g,'')*1 != 0)&&(document.getElementsByName('ftother_coa_codeD0[]')[j].value=='')) {
            alert('No. Perkiraan Biaya belum diisi ...');
            document.getElementsByName('ftother_coa_codeD0[]')[j].focus();
            return false;
        }

    }
    return true;
}
function RekapBankVoucherInputQtyImport1() {
    var i=document.getElementsByName('fnindexD1[]').length;
    for(var j=0;j<i;j++) {
        if(  document.getElementsByName('fcpayment_amountUSDD1[]')[j].value.replace(/,/g,'')*1> document.getElementsByName('fcoutstanding_amountUSDD1[]')[j].value.replace(/,/g,'')*1) {
            alert('Jumlah pembayaran IDR melebihi jml Tagihan ...');
            document.getElementsByName('fcpayment_amountUSDD1[]')[j].focus();
            return false;
        }
      
    }
    return true;
}

function RekapBankVoucherInputQtyImport2() {
    // Grid Other Cost
    var i=document.getElementsByName('fnindexD2[]').length;
    for(var j=0;j<i;j++) {
        if ((document.getElementsByName('fcamountD2[]')[j].value.replace(/,/g,'')*1 != 0)&&(document.getElementsByName('ftcoa_codeD2[]')[j].value=='')) {
            alert('No. Perkiraan Biaya Lain belum diisi ...');
            document.getElementsByName('ftcoa_codeD2[]')[j].focus();
            return false;
        }
    }
    return true;
}

function RekapBankVoucherRecalQtyImport0() {
  var i=document.getElementsByName('fnindexD0[]').length;
  var fcamountxx=0;
  var fcamountxx2=0;
  var fcamountxx3=0;
  var fcamountxx4=0;

  for(var j=1;j<i;j++) {
    document.getElementsByName('fcamountD0[]')[j].value=document.getElementsByName('fcamountUSDD0[]')[j].value.replace(/,/g,'') * document.getElementById('fckurs').value.replace(/,/g,'');
    document.getElementsByName('fcother_costD0[]')[j].value=document.getElementsByName('fcother_costUSDD0[]')[j].value.replace(/,/g,'') * document.getElementById('fckurs').value.replace(/,/g,'');
    document.getElementsByName('fctotalUSDD0[]')[j].value=(document.getElementsByName('fcother_costUSDD0[]')[j].value.replace(/,/g,'')*1) + (document.getElementsByName('fcamountUSDD0[]')[j].value.replace(/,/g,'') * 1);
    document.getElementsByName('fctotalD0[]')[j].value=document.getElementsByName('fctotalUSDD0[]')[j].value.replace(/,/g,'') * document.getElementById('fckurs').value.replace(/,/g,'');

    fcamountxx+=document.getElementsByName('fctotalUSDD0[]')[j].value.replace(/,/g,'')*1;
    fcamountxx2+=document.getElementsByName('fctotalD0[]')[j].value.replace(/,/g,'')*1;
  }

  document.getElementById('fcamountUSD').value=fcamountxx;
  document.getElementById('fcamount').value=fcamountxx2;

  RekapBankVoucherRecalOtherCost();
  RekapBankVoucherRecalQtyImport1();
}

function RekapBankVoucherRecalQtyImport1() {

    var i=document.getElementsByName('fnindexD1[]').length;
    var fcinvoice_amount=0;
    var fcinvoice_amountUSD=0;
    var fckurs = 1;
    var ftcurrency=document.getElementById('ftcurrency_code').value;
    var ftcurrency2="IDR";
    
    for(var j=0;j<i;j++) {
        fckurs = document.getElementsByName('fckursD1[]')[j].value.replace(/,/g,'') * 1;
        document.getElementsByName('fcamountD1[]')[j].value=document.getElementsByName('fcamountUSDD1[]')[j].value.replace(/,/g,'') * fckurs;
        document.getElementsByName('fcoutstanding_amountD1[]')[j].value=(document.getElementsByName('fcoutstanding_amountUSDD1[]')[j].value.replace(/,/g,'')*1) * fckurs;

        document.getElementsByName('fcpayment_amountD1[]')[j].value=document.getElementsByName('fcpayment_amountUSDD1[]')[j].value.replace(/,/g,'') * fckurs;

        fcinvoice_amountUSD+=document.getElementsByName('fcpayment_amountUSDD1[]')[j].value.replace(/,/g,'') * 1;
        fcinvoice_amount+=document.getElementsByName('fcpayment_amountD1[]')[j].value.replace(/,/g,'') * 1;

        if ((document.getElementsByName('ftcurrency_codeD1[]')[j].value != "IDR") && (document.getElementsByName('fcpayment_amountD1[]')[j].value != 0)) {
            ftcurrency2 = document.getElementsByName('ftcurrency_codeD1[]')[j].value;
        }
    }

    document.getElementById('fcother_cost').value = (document.getElementById('fcother_costUSD').value.replace(/,/g,'')*1) * (document.getElementById('fckurs').value.replace(/,/g,'')*1);

    document.getElementById('fcinvoice_amount').value=fcinvoice_amount;
    document.getElementById('fcsub_amount').value = (document.getElementById('fcinvoice_amount').value.replace(/,/g,'')*1);
    document.getElementById('fcamount').value = (document.getElementById('fcamount').value.replace(/,/g,'')*1);

    document.getElementById('fcinvoice_amountUSD').value=fcinvoice_amountUSD;
    document.getElementById('fcsub_amountUSD').value = (document.getElementById('fcinvoice_amountUSD').value.replace(/,/g,'')*1);
    document.getElementById('fcamountUSD').value = (document.getElementById('fcamountUSD').value.replace(/,/g,'')*1);

    if (ftcurrency2 == "IDR") {
        document.getElementById('fcrate_adjustment').value=0;
    } else { 
        document.getElementById('fcrate_adjustment').value=(document.getElementById('fcsub_amount').value.replace(/,/g,'')*1) - (document.getElementById('fcamount').value.replace(/,/g,'')*1) + (document.getElementById('fcother_cost').value.replace(/,/g,'')*1);
    }
    
    ElementCurrencyALL();

}

function RekapBankVoucherRecalQtyImport2(index) {
   var i=document.getElementsByName('fnindexD1[]').length;

   if(document.getElementById('chk_includeD1'+index).checked == true) {
       document.getElementById('fcpayment_amountUSDD1'+index).value=document.getElementById('fcoutstanding_amountUSDD1'+index).value;
       document.getElementById('fcpayment_amountD1'+index).value=document.getElementById('fcpayment_amountUSDD1'+index).value.replace(/,/g,'')*document.getElementById('fckurs').value.replace(/,/g,'');
       document.getElementById('hd_includeD1'+index).value=1;
   }
   else {
        document.getElementById('hd_includeD1'+index).value=0;
   }

   RekapBankVoucherRecalQtyImport1();

}

function RekapBankVoucherCheckCurrency() {
    var i=document.getElementsByName('fnindexD1[]').length;

    var ftcurrency_code = '';

    for(var j=0;j<i;j++) {
        if (document.getElementsByName('fcpayment_amountUSDD1[]')[j].value.replace(/,/g,'') > 0) {
            if (ftcurrency_code != '') {
                if (ftcurrency_code != document.getElementsByName('ftcurrency_codeD1[]')[j].value.replace(/,/g,'')) {
                    alert('Invoice yang dipilih harus dari kode currency yang sama. ');
                    return false;
                }
            }
            ftcurrency_code = document.getElementsByName('ftcurrency_codeD1[]')[j].value.replace(/,/g,'');

            if (document.getElementById('ftcurrency_code').value.replace(/,/g,'') != 'IDR') {
                if (ftcurrency_code != document.getElementById('ftcurrency_code').value.replace(/,/g,'')) {
                    alert('Mata uang pembayaran harus IDR atau dari kode currency yang sama. ');
                    return false;
                }
            }

        }
    }

    return true;
}


function valInclude(index) {
   var i=document.getElementsByName('fnindexD0[]').length;

   if(document.getElementById('chk_includeD0'+index).checked == true) {
                document.getElementById('hd_includeD0'+index).value=1;
                document.getElementById('ftrekap_statusD0'+index).value=1;
   }
   else {
                document.getElementById('hd_includeD0'+index).value=0;
                document.getElementById('ftrekap_statusD0'+index).value=0;

   }

}

//debit memo
function ValDebitMemo() {
  DebitMemoRecalQty();
  if(document.getElementById("ftdm_no").value=='') {
       alert('No. transaksi harus di isi...');
       document.getElementById("ftdm_no").focus();
       return false;
  }
  else if(document.getElementById("hidden_ftsupplier_code").value=='') {
       alert('Supplier belum valid...');
       document.getElementById("ftsupplier_code").focus();
       return false;
  }
 else if(document.getElementById("fntrans_type").value=='') {
       alert('Jenis debit memo harus di isi...');
       document.getElementById("fntrans_type").focus();
       return false;
  }
   else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }
  else if (DebitMemoInputQty()==false) {
       return false;
  }
  else if(document.getElementById('fcinvoice_amount').value.replace(/,/g,'')*1<=0) {
      alert('Jml. Debit memo belum di isi ...');
      return false;
  }
             ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftdm_no').value);

  return false;
}

function DebitMemoInputQty() {
        var i=document.getElementsByName('fnindexD0[]').length;

    for(var j=1;j<i;j++) {
        if(document.getElementById("fntrans_type").value.replace(/,/g,'')*1<3) {
            if(document.getElementsByName('ftcv_noD0[]')[j].value=='') {
                alert('No. Purchase Invoice harus di isi ..');
                document.getElementsByName('ftcv_noD0[]')[j].focus();
                return false;
            }
            else if(document.getElementsByName('fcdebit_amountD0[]')[j].value.replace(/,/g,'')*1<=0) {
                alert('Jml. Debit memo harus lebih besar 0 ..');
                 document.getElementsByName('fcdebit_amountD0[]')[j].focus();
                 return false;
            } /*
            else if(document.getElementsByName('fcoutstanding_debit_memoD0[]')[j].value.replace(/,/g,'')*1<document.getElementsByName('fcdebit_amountD0[]')[j].value.replace(/,/g,'')*1) {
                alert('Jml. Debit memo tidak boleh melebihi jml Debit memo yg sudah dipakai untuk po tersebut ...');
                  document.getElementsByName('fccredit_amountD0[]')[j].focus();
                 return false;
            }
            else if(document.getElementsByName('fcinvoice_amountD0[]')[j].value.replace(/,/g,'')*1<document.getElementsByName('fcdebit_amountD0[]')[j].value.replace(/,/g,'')*1) {
                alert('Jml. Debit memo tidak boleh melebihi jml CV ..');
                  document.getElementsByName('fcdebit_amountD0[]')[j].focus();
                 return false;
            }*/

        }
        else {
             if(document.getElementsByName('fcdebit_amountD0[]')[j].value.replace(/,/g,'')*1<=0) {
                alert('Jml. Debit memo harus lebih besar 0 ..');
                  document.getElementsByName('fcdebit_amountD0[]')[j].focus();
                 return false;
            }
        }
    }

    return true;
}

function DebitMemoRecalQty() {

    var i=document.getElementsByName('fnindexD0[]').length;
    var fcdebit_amount=0;

    for(var j=1;j<i;j++) {
        fcdebit_amount+=document.getElementsByName('fcdebit_amountD0[]')[j].value.replace(/,/g,'')*1;
    }

    document.getElementById('fcinvoice_amount').value=fcdebit_amount;
    document.getElementById('fcoutstanding_amount').value=fcdebit_amount;
    document.getElementById('fcdebit_amount').value =0;

}


// Uang Muka Pembelian
function ValUangMukaPembelian() {
  if(document.getElementById("fttrans_no").value=='') {
       alert('No. transaksi harus disi...');
       document.getElementById("fttrans_no").focus();
       return false;
  }
  else if(document.getElementById("ftsupplier_code").value=='') {
       alert('Supplier harus diisi...');
       document.getElementById("ftsupplier_code").focus();
       return false;
  }
  else  if(document.getElementById("hidden_ftsupplier_code").value=='') {
      alert('Supplier belum valid ...');
      document.getElementById("ftsupplier_code").focus();
      return false;
  }
  else if((document.getElementById("fcamount").value=='') || (document.getElementById("fcamount").value.replace(/,/g,'')*1<=0 )) {
       alert('Jumlah harus diisi dan tidak boleh 0 ...');
       document.getElementById("fcamount").focus();
       return false;
  }
  else if(document.getElementById("fnpayment_method").value!='') {
        if (document.getElementById("fnpayment_method").value=='0' || document.getElementById("fnpayment_method").value=='1') {
            if (document.getElementById("ftgiro_no").value=='') {
                alert('No Giro harus diisi ...');
                document.getElementById("ftgiro_no").focus();
                return false;
            }
        }
        
        if (document.getElementById("ftacc_no").value=='') {
            alert('No Perkiraan harus diisi ...');
            document.getElementById("ftacc_no").focus();
            return false;
        }
  }

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

  return false;
}

function UpdateUangMukaPembelian() {
  if(document.getElementById("fttrans_no").value=='') {
       alert('No. transaksi harus disi...');
       document.getElementById("fttrans_no").focus();
       return false;
  }
  else if(document.getElementById("ftsupplier_code").value=='') {
       alert('Supplier harus diisi...');
       document.getElementById("ftsupplier_code").focus();
       return false;
  }
  else if((document.getElementById("fcamount").value=='') || (document.getElementById("fcamount").value.replace(/,/g,'')*1<=0 )) {
       alert('Jumlah harus diisi dan tidak boleh 0 ...');
       document.getElementById("fcamount").focus();
       return false;
  }
  else if(document.getElementById("fnpayment_method").value!='') {
        if (document.getElementById("fnpayment_method").value=='0' || document.getElementById("fnpayment_method").value=='1') {
            if (document.getElementById("ftgiro_no").value=='') {
                alert('No Giro harus diisi ...');
                document.getElementById("ftgiro_no").focus();
                return false;
            }
        }

        if (document.getElementById("ftacc_no").value=='') {
            alert('No Perkiraan harus diisi ...');
            document.getElementById("ftacc_no").focus();
            return false;
        }
  }
  return true;
}

function RevisiUangMukaPembelian() {
  if(document.getElementById("fttrans_no").value=='') {
       alert('No. transaksi harus disi...');
       document.getElementById("fttrans_no").focus();
       return false;
  }
  else if(document.getElementById("ftsupplier_code").value=='') {
       alert('Supplier harus diisi...');
       document.getElementById("ftsupplier_code").focus();
       return false;
  }
  else  if(document.getElementById("hidden_ftsupplier_code").value=='') {
      alert('Supplier belum valid ...');
      document.getElementById("ftsupplier_code").focus();
      return false;
  }
  else if((document.getElementById("fcamount").value=='') || (document.getElementById("fcamount").value.replace(/,/g,'')*1<=0 )) {
       alert('Jumlah harus diisi dan tidak boleh 0 ...');
       document.getElementById("fcamount").focus();
       return false;
  }
  else if(document.getElementById("fnpayment_method").value!='') {
        if (document.getElementById("fnpayment_method").value=='0' || document.getElementById("fnpayment_method").value=='1') {
            if (document.getElementById("ftgiro_no").value=='') {
                alert('No Giro harus diisi ...');
                document.getElementById("ftgiro_no").focus();
                return false;
            }
        }

        if (document.getElementById("ftacc_no").value=='') {
            alert('No Perkiraan harus diisi ...');
            document.getElementById("ftacc_no").focus();
            return false;
        }
  }

  return true;
}

// Uang Muka Penjualan
function ValUangMukaPenjualan() {
  if(document.getElementById("fttrans_no").value=='') {
       alert('No. transaksi harus disi...');
       document.getElementById("fttrans_no").focus();
       return false;
  }
  else if(document.getElementById("ftcustomer_code").value=='') {
       alert('Customer harus diisi...');
       document.getElementById("ftcustomer_code").focus();
       return false;
  }
  else  if(document.getElementById("hidden_ftcustomer_code").value=='') {
      alert('Customer belum valid ...');
      document.getElementById("ftcustomer_code").focus();
      return false;
  }
  else if((document.getElementById("fcamount").value=='') || (document.getElementById("fcamount").value.replace(/,/g,'')*1<=0 )) {
       alert('Jumlah harus diisi dan tidak boleh 0 ...');
       document.getElementById("fcamount").focus();
       return false;
  }
  else if(document.getElementById("fnpayment_method").value!='') {
        if (document.getElementById("fnpayment_method").value=='0' || document.getElementById("fnpayment_method").value=='1') {
            if (document.getElementById("ftgiro_no").value=='') {
                alert('No Giro harus diisi ...');
                document.getElementById("ftgiro_no").focus();
                return false;
            }
        }

        if (document.getElementById("ftacc_no").value=='') {
            alert('No Perkiraan harus diisi ...');
            document.getElementById("ftacc_no").focus();
            return false;
        }
  }

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

  return false;
}

function UpdateUangMukaPenjualan() {
  if(document.getElementById("fttrans_no").value=='') {
       alert('No. transaksi harus disi...');
       document.getElementById("fttrans_no").focus();
       return false;
  }
  else if(document.getElementById("ftcustomer_code").value=='') {
       alert('Customer harus diisi...');
       document.getElementById("ftcustomer_code").focus();
       return false;
  }
  else if((document.getElementById("fcamount").value=='') || (document.getElementById("fcamount").value.replace(/,/g,'')*1<=0 )) {
       alert('Jumlah harus diisi dan tidak boleh 0 ...');
       document.getElementById("fcamount").focus();
       return false;
  }
  else if(document.getElementById("fnpayment_method").value!='') {
        if (document.getElementById("fnpayment_method").value=='0' || document.getElementById("fnpayment_method").value=='1') {
            if (document.getElementById("ftgiro_no").value=='') {
                alert('No Giro harus diisi ...');
                document.getElementById("ftgiro_no").focus();
                return false;
            }
        }

        if (document.getElementById("ftacc_no").value=='') {
            alert('No Perkiraan harus diisi ...');
            document.getElementById("ftacc_no").focus();
            return false;
        }
  }
  return true;
}

function RevisiUangMukaPenjualan() {
  if(document.getElementById("fttrans_no").value=='') {
       alert('No. transaksi harus disi...');
       document.getElementById("fttrans_no").focus();
       return false;
  }
  else if(document.getElementById("ftcustomer_code").value=='') {
       alert('Customer harus diisi...');
       document.getElementById("ftcustomer_code").focus();
       return false;
  }
  else  if(document.getElementById("hidden_ftcustomer_code").value=='') {
      alert('Customer belum valid ...');
      document.getElementById("ftcustomer_code").focus();
      return false;
  }
  else if((document.getElementById("fcamount").value=='') || (document.getElementById("fcamount").value.replace(/,/g,'')*1<=0 )) {
       alert('Jumlah harus diisi dan tidak boleh 0 ...');
       document.getElementById("fcamount").focus();
       return false;
  }
  else if(document.getElementById("fnpayment_method").value!='') {
        if (document.getElementById("fnpayment_method").value=='0' || document.getElementById("fnpayment_method").value=='1') {
            if (document.getElementById("ftgiro_no").value=='') {
                alert('No Giro harus diisi ...');
                document.getElementById("ftgiro_no").focus();
                return false;
            }
        }

        if (document.getElementById("ftacc_no").value=='') {
            alert('No Perkiraan harus diisi ...');
            document.getElementById("ftacc_no").focus();
            return false;
        }
  }

  return true;
}


function ValCalOrderRequest() {
var i=document.getElementsByName('fnindexD0[]').length;
var fttype_barang_code='';
var fttype_barang_name='';
var ftcolor_code='';
var m;

    for(var j=1;j<i;j++) {
        fttype_barang_code = document.getElementsByName('fttype_barang_codeD0[]')[j].value;
        ftcolor_code= document.getElementsByName('ftcolor_codeD0[]')[j].value;

        if(( document.getElementsByName('fttype_barang_codeD0[]')[j-1].value== document.getElementsByName('fttype_barang_codeD0[]')[j].value) && ( document.getElementsByName('ftcolor_codeD0[]')[j-1].value== document.getElementsByName('ftcolor_codeD0[]')[j].value)) {
     }
        else {
             document.getElementsByName('ffqtyD0[]')[j].value=document.getElementsByName('ffqty_mporD0[]')[j].value;

        }


    }
}
function ValPOS() {
    var i=document.getElementsByName('fnindexD0[]').length;
    var total=0 ;
    for(var j=1;j<i;j++) {
        total= total+document.getElementsByName('ffqtyD0[]')[j].value.replace(/,/g,'')*1;
    }
     document.getElementById('fftotal_qty').value=total;
}




//========================================
//          BAHAN BAKU
//========================================
function ValGroupBarangBahanBaku() {

  if(document.getElementById("ftstock_group_code").value=='') {
       alert('Kode Group Barang harus diisi...');
       document.getElementById("ftstock_group_code").focus();
       return false;
  }
  else if(document.getElementById("ftstock_group_name").value=='') {
       alert('Nama Group Barang harus diisi...');
       document.getElementById("ftstock_group_name").focus();
       return false;
  }


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

  return false;
}

function ValBarangBahanBaku() {

  if(document.getElementById("ftitem_code").value=='') {
       alert('Kode Barang harus diisi...');
       document.getElementById("ftitem_code").focus();
       return false;
  }
  else if(document.getElementById("ftitem_code").value.length==0) {
       alert('Kode Barang harus diisi...');
       document.getElementById("ftitem_code").focus();
       return false;
  }
  else if(document.getElementById("ftitem_code").value.indexOf('&') != -1) {
       alert('Kode Barang Tidak boleh menggunakan Karakter & ...');
       document.getElementById("ftitem_code").focus();
       return false;
  }  
  else if(document.getElementById("ftitem_name").value=='') {
       alert('Nama Barang harus diisi...');
       document.getElementById("ftitem_name").focus();
       return false;
  }
  else if(document.getElementById("ftprint_name").value=='') {
       alert('Nama Cetak harus diisi...');
       document.getElementById("ftprint_name").focus();
       return false;
  }
  else if(document.getElementById("ftstock_category_code").value=='') {
       alert('Kategory harus diisi...');
       document.getElementById("ftstock_category_code").focus();
       return false;
  }
   else if(document.getElementById("hidden_ftstock_group_code").value=='') {
       alert('Group belum valid...');
       document.getElementById("ftstock_group_code").focus();
       return false;
  }
  /*
  else if(document.getElementById("ftweight_code").value=='') {
       alert('Kode berat harus diisi...');
       document.getElementById("ftweight_code").focus();
       return false;
  } */
  else if(document.getElementById("ftuom_code").value=='') {
       alert('Kode satuan harus diisi...');
       document.getElementById("ftuom_code").focus();
       return false;
  }
  else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Kode Supplier belum di input ...');
      return false;
  }
    else if(document.getElementById("ftgl_inv_acc").value=='') {
        alert('No Perkiraan Persediaan harus diisi...');
        document.getElementById("ftgl_inv_acc").focus();
        return false;
    }
    else if(document.getElementById("ftgl_cogs_acc").value=='') {
        alert('No Perkiraan HPP harus diisi...');
        document.getElementById("ftgl_cogs_acc").focus();
        return false;
    }
    else if(document.getElementById("ftgl_sales_acc").value=='') {
        alert('No Perkiraan Penjualan harus diisi...');
        document.getElementById("ftgl_sales_acc").focus();
        return false;
    }
    else if(document.getElementById("ftgl_sales_ret_acc").value=='') {
        alert('No Perkiraan Retur Penjualan harus diisi...');
        document.getElementById("ftgl_sales_ret_acc").focus();
        return false;
    }
    else if(document.getElementById("ftgl_sales_disc_acc").value=='') {
        alert('No Perkiraan Discount Penjualan harus diisi...');
        document.getElementById("ftgl_sales_disc_acc").focus();
        return false;
    }

     if(ValBarangBahanBaku1()==false) {
         return false;
     }

     ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftitem_code').value+'&fttrans_no1='+ ValBarangBahanBaku2());
     document.getElementById("ftitem_code").focus();
     return false;
}

function ValBarangBahanBaku1() {
    var i=document.getElementsByName('fnindexD1[]').length;
    for(var j=1;j<i;j++) {
        if  (document.getElementsByName('ftuom_code_multiD1[]')[j].value==document.getElementById('ftuom_code').value) {
            alert('Kode satuan sudah digunakan ');
            document.getElementsByName('ftuom_code_multiD1[]')[j].focus();
            return false;
        } else  if  (document.getElementsByName('ftuom_code_multiD1[]')[j].value=='') {
            alert('Kode Multi Satuan harus diisi ');
            document.getElementsByName('ftuom_code_multiD1[]')[j].focus();
            return false;
        } else  if  (document.getElementsByName('ffformulaD1[]')[j].value.replace(/,/g,'')*1 <= 0) {
            alert('Nominal Formula harus lebih besar dari 0 ');
            document.getElementsByName('ffformulaD1[]')[j].focus();
            return false;
        }

        for(var k=1;k<j;k++) {
            if  (document.getElementsByName('ftuom_code_multiD1[]')[k].value==document.getElementsByName('ftuom_code_multiD1[]')[j].value) {
                alert('Kode satuan sudah digunakan ');
                document.getElementsByName('ftuom_code_multiD1[]')[k].focus();
                return false;
            }
        }
    }

    
    return true;
}

function ValBarangBahanBaku2() {
    var i=document.getElementsByName('fnindexD0[]').length;
    var ftsupplier_code='';
    for(var j=1;j<i;j++) {
        if(ftsupplier_code=='') {
            ftsupplier_code=document.getElementsByName('ftsupplier_codeD0[]')[j].value;
        }
        else {
             ftsupplier_code=ftsupplier_code+'|'+document.getElementsByName('ftsupplier_codeD0[]')[j].value;
        }
    }

    return ftsupplier_code;
}

function UpdateBarangBahanBaku() {
    if(document.getElementById("ftitem_code").value=='') {
       alert('Kode Barang harus diisi...');
       document.getElementById("ftitem_code").focus();
       return false;
  }
  else if(document.getElementById("ftitem_name").value=='') {
       alert('Nama Barang harus diisi...');
       document.getElementById("ftitem_name").focus();
       return false;
  }
  else if(document.getElementById("ftprint_name").value=='') {
       alert('Nama Cetak harus diisi...');
       document.getElementById("ftprint_name").focus();
       return false;
  }
 else if(document.getElementById("ftuom_code").value=='') {
       alert('Satuan harus diisi...');
       document.getElementById("ftuom_code").focus();
       return false;
  }

 else if(document.getElementById("ftstock_category_code").value=='') {
       alert('Kategory harus diisi...');
       document.getElementById("ftstock_category_code").focus();
       return false;
  }
    else if(document.getElementById("ftgl_inv_acc").value=='') {
        alert('No Perkiraan Persediaan harus diisi...');
        document.getElementById("ftgl_inv_acc").focus();
        return false;
    }
    else if(document.getElementById("ftgl_cogs_acc").value=='') {
        alert('No Perkiraan HPP harus diisi...');
        document.getElementById("ftgl_cogs_acc").focus();
        return false;
    }
    else if(document.getElementById("ftgl_sales_acc").value=='') {
        alert('No Perkiraan Penjualan harus diisi...');
        document.getElementById("ftgl_sales_acc").focus();
        return false;
    }
    else if(document.getElementById("ftgl_sales_ret_acc").value=='') {
        alert('No Perkiraan Retur Penjualan harus diisi...');
        document.getElementById("ftgl_sales_ret_acc").focus();
        return false;
    }
    else if(document.getElementById("ftgl_sales_disc_acc").value=='') {
        alert('No Perkiraan Discount Penjualan harus diisi...');
        document.getElementById("ftgl_sales_disc_acc").focus();
        return false;
    }
    else if(ValBarangBahanBaku1()==false) {
       return false;
    }

    return true;
}


////function Setftitem_code_bahan_baku() {
   //document.getElementById("ftitem_code").value=document.getElementById("ftstock_group_code").value+document.getElementById("ftstock_group_code1").value+document.getElementById("ftstock_group_code2").value+ document.getElementById("ftstock_group_code3").value+ document.getElementById("ftstock_group_code4").value+ document.getElementById("ftstock_group_code5").value+'.'+document.getElementById("ftsupplier_code").value;
    //document.getElementById("ftitem_code").value=document.getElementById("ftstock_group_code").value+document.getElementById("ftstock_group_code1").value+document.getElementById("ftstock_group_code2").value+ document.getElementById("ftstock_group_code3").value+ document.getElementById("ftstock_group_code4").value+ document.getElementById("ftstock_group_code5").value;
//}
//function Setftitem_code_bahan_baku_eps() {
   //document.getElementById("ftitem_code").value=document.getElementById("ftstock_group_code").value+document.getElementById("ftstock_group_code1").value+document.getElementById("ftstock_group_code2").value+ document.getElementById("ftstock_group_code3").value+ document.getElementById("ftstock_group_code4").value+ document.getElementById("ftstock_group_code5").value+'.'+document.getElementById("ftsupplier_code").value;
   // document.getElementById("ftitem_code").value=document.getElementById("ftstock_group_code").value+document.getElementById("ftstock_group_code1").value+document.getElementById("ftstock_group_code6").value+document.getElementById("ftstock_group_code2").value+document.getElementById("ftstock_group_code4").value+ document.getElementById("ftstock_group_code5").value;
//}/
//function Setftitem_code_bahan_baku_decal() {
   //document.getElementById("ftitem_code").value=document.getElementById("ftstock_group_code").value+document.getElementById("ftstock_group_code1").value+document.getElementById("ftstock_group_code2").value+ document.getElementById("ftstock_group_code3").value+ document.getElementById("ftstock_group_code4").value+ document.getElementById("ftstock_group_code5").value+'.'+document.getElementById("ftsupplier_code").value;
    //document.getElementById("ftitem_code").value=document.getElementById("ftstock_group_code").value+document.getElementById("ftstock_group_code1").value+document.getElementById("ftstock_group_code6").value+document.getElementById("ftstock_group_code2").value+document.getElementById("ftstock_group_code4").value+ document.getElementById("ftstock_group_code3").value;
//}


function ValSaldoAwalStockBahanBaku() {
  if(document.getElementById("ftstock_in_no").value=='') {
       alert('No. transaksi harus disi...');
       document.getElementById("ftstock_in_no").focus();
       return false;
  }
//  else if(document.getElementById("ftcategory_code").value=='') {
//       alert('Kategori harus disi...');
//       document.getElementById("ftcategory_code").focus();
//       return false;
//  }
//    else if((document.getElementById("ftcategory_code").value!=0)&&(document.getElementById("ftstock_in_company").value=='')) {
//       alert('Supplier/Customer harus disi...');
//       document.getElementById("ftstock_in_company").focus();
//       return false;
//  }
//   else if(document.getElementById("ftdocument_no").value=='') {
//       alert('No. Document harus disi...');
//       document.getElementById("ftdocument_no").focus();
//       return false;
//  }
//  else if(document.getElementById("ftdelivery_no").value=='') {
//       alert('No. Surat Jalan harus disi...');
//       document.getElementById("ftdelivery_no").focus();
//       return false;
//  }
//  else if(document.getElementById("ftchecked_user").value=='') {
//       alert('Nama Pengecek barang harus diisi...');
//        document.getElementById("ftchecked_user").focus();
//       return false;
//  }
   else if (SaldoAwalStockInputQtyBahanBaku()==false) {
       return false;
  }

  ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftstock_in_no').value);
   document.getElementById("ftstock_in_no").focus();
    return false;


}

function SaldoAwalStockRecalQtyBahanBaku() {

    var i=document.getElementsByName('fnindexD0[]').length;

    var ffqty=0;
    var fcprice=0;
    var ffTotal=0;

    for(var j=1;j<i;j++) {
        ffqty=document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1;
        //fcprice=document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1;
       // ffTotal=ffTotal+(ffqty*fcprice);
       ffTotal=ffTotal+ffqty;

    }

    document.getElementById('fntotal_qty').value=ffTotal;

}

function SaldoAwalStockInputQtyBahanBaku() {
    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;
        }
        else if (document.getElementsByName('ftwarehouse_codeD0[]')[j].value=='') {
             alert('Gudang harus diisi..');
             document.getElementsByName('ftwarehouse_codeD0[]')[j].focus();
             return false;
        }
        else if (document.getElementsByName('ftlocation_codeD0[]')[j].value=='') {
             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 masuk harus diisi..');
//              document.getElementsByName('fnqtyD0[]')[j].focus();
//             return false;
//        }

//        else if (document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1<=0) {
//             alert('Harga masuk harus diisi..');
//              document.getElementsByName('fcpriceD0[]')[j].focus();
//             return false;
//        }

    }

    return true;
}

function ValSaldoAwalStockSetengahJadi() {
  if(document.getElementById("ftstock_in_no").value=='') {
       alert('No. transaksi harus disi...');
       document.getElementById("ftstock_in_no").focus();
       return false;
  }
//  else if(document.getElementById("ftcategory_code").value=='') {
//       alert('Kategori harus disi...');
//       document.getElementById("ftcategory_code").focus();
//       return false;
//  }
//    else if((document.getElementById("ftcategory_code").value!=0)&&(document.getElementById("ftstock_in_company").value=='')) {
//       alert('Supplier/Customer harus disi...');
//       document.getElementById("ftstock_in_company").focus();
//       return false;
//  }
//   else if(document.getElementById("ftdocument_no").value=='') {
//       alert('No. Document harus disi...');
//       document.getElementById("ftdocument_no").focus();
//       return false;
//  }
//  else if(document.getElementById("ftdelivery_no").value=='') {
//       alert('No. Surat Jalan harus disi...');
//       document.getElementById("ftdelivery_no").focus();
//       return false;
//  }
//  else if(document.getElementById("ftchecked_user").value=='') {
//       alert('Nama Pengecek barang harus diisi...');
//        document.getElementById("ftchecked_user").focus();
//       return false;
//  }
   else if (SaldoAwalStockInputQtySetengahJadi()==false) {
       return false;
  }

  ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftstock_in_no').value);
   document.getElementById("ftstock_in_no").focus();
    return false;


}

function SaldoAwalStockRecalQtySetengahJadi() {

    var i=document.getElementsByName('fnindexD0[]').length;

    var ffqty=0;
    var fcprice=0;
    var ffTotal=0;

    for(var j=1;j<i;j++) {
        ffqty=document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1;
        //fcprice=document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1;
       // ffTotal=ffTotal+(ffqty*fcprice);
       ffTotal=ffTotal+ffqty;

    }

    document.getElementById('fntotal_qty').value=ffTotal;

}

function SaldoAwalStockInputQtySetengahJadi() {
    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;
        }
        else if (document.getElementsByName('ftwarehouse_codeD0[]')[j].value=='') {
             alert('Gudang harus diisi..');
             document.getElementsByName('ftwarehouse_codeD0[]')[j].focus();
             return false;
        }
        else if (document.getElementsByName('ftlocation_codeD0[]')[j].value=='') {
             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 masuk harus diisi..');
//              document.getElementsByName('fnqtyD0[]')[j].focus();
//             return false;
//        }

//        else if (document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1<=0) {
//             alert('Harga masuk harus diisi..');
//              document.getElementsByName('fcpriceD0[]')[j].focus();
//             return false;
//        }

    }

    return true;
}

function ValSaldoAwalStockSparepart() {
  if(document.getElementById("ftstock_in_no").value=='') {
       alert('No. transaksi harus disi...');
       document.getElementById("ftstock_in_no").focus();
       return false;
  }
//  else if(document.getElementById("ftcategory_code").value=='') {
//       alert('Kategori harus disi...');
//       document.getElementById("ftcategory_code").focus();
//       return false;
//  }
//    else if((document.getElementById("ftcategory_code").value!=0)&&(document.getElementById("ftstock_in_company").value=='')) {
//       alert('Supplier/Customer harus disi...');
//       document.getElementById("ftstock_in_company").focus();
//       return false;
//  }
//   else if(document.getElementById("ftdocument_no").value=='') {
//       alert('No. Document harus disi...');
//       document.getElementById("ftdocument_no").focus();
//       return false;
//  }
//  else if(document.getElementById("ftdelivery_no").value=='') {
//       alert('No. Surat Jalan harus disi...');
//       document.getElementById("ftdelivery_no").focus();
//       return false;
//  }
//  else if(document.getElementById("ftchecked_user").value=='') {
//       alert('Nama Pengecek barang harus diisi...');
//        document.getElementById("ftchecked_user").focus();
//       return false;
//  }
   else if (SaldoAwalStockInputQtySparepart()==false) {
       return false;
  }

  ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftstock_in_no').value);
   document.getElementById("ftstock_in_no").focus();
    return false;


}

function SaldoAwalStockRecalQtySparepart() {

    var i=document.getElementsByName('fnindexD0[]').length;

    var ffqty=0;
    var fcprice=0;
    var ffTotal=0;

    for(var j=1;j<i;j++) {
        ffqty=document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1;
        //fcprice=document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1;
       // ffTotal=ffTotal+(ffqty*fcprice);
       ffTotal=ffTotal+ffqty;

    }

    document.getElementById('fntotal_qty').value=ffTotal;

}

function SaldoAwalStockInputQtySparepart() {
    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;
        }
        else if (document.getElementsByName('ftwarehouse_codeD0[]')[j].value=='') {
             alert('Gudang harus diisi..');
             document.getElementsByName('ftwarehouse_codeD0[]')[j].focus();
             return false;
        }
        else if (document.getElementsByName('ftlocation_codeD0[]')[j].value=='') {
             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 masuk harus diisi..');
//              document.getElementsByName('fnqtyD0[]')[j].focus();
//             return false;
//        }

//        else if (document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1<=0) {
//             alert('Harga masuk harus diisi..');
//              document.getElementsByName('fcpriceD0[]')[j].focus();
//             return false;
//        }

    }

    return true;
}

    //--------------------------------------------------------------------
function ValStockKeluarBahanBaku() {

  if(document.getElementById("ftstock_out_no").value=='') {
       alert('No. transaksi harus disi...');
       document.getElementById("ftstock_out_no").focus();
       return false;
  }
   else if(document.getElementById("ftcategory_code").value=='') {
       alert('Kategori harus disi...');
       document.getElementById("ftcategory_code").focus();
       return false;
  }
  /*else if(document.getElementById("ftdocument_no").value=='') {
       alert('No. Document harus disi...');
       document.getElementById("ftdocument_no").focus();
       return false;
  } */
//   else if(document.getElementById("hidden_ftstock_out_company").value=='') {
//       alert('Supplier/Customer belum valid...');
//       document.getElementById("ftstock_out_company").focus();
//       return false;
//  }
  else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }

  else if (StockKeluarInputQtyBahanBaku()==false) {
       return false;
  }
  if (accessExpDate()==false) {
       return false;
  }
  ajax_do(str_url+'&ajax=1&code=transno&fttrans_no='+document.getElementById('ftstock_out_no').value);
  document.getElementById("ftstock_out_no").focus();
  return false;
}


function FinalStockKeluarBahanBaku() {

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

  else if(document.getElementById("ftcategory_code").value=='') {
       alert('Kategori harus disi...');
       document.getElementById("ftcategory_code").focus();
       return false;
  }
  
  else if(document.getElementById("ftdocument_no").value=='') {
       alert('No. Document harus disi...');
       document.getElementById("ftdocument_no").focus();
       return false;
  }

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

  else if (StockKeluarInputQtyBahanBaku()==false) {
       return false;
  }
  
  return true;
}

function StockKeluarRecalQtyBahanBaku() {

    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,'')*1;
        ffTotal=ffTotal+(ffqty);
    }

    document.getElementById('fntotal_qty').value=ffTotal;

}
function StockKeluarInputQtyBahanBaku() {
    var i=document.getElementsByName('fnindexD0[]').length;
    var ffqty1=0;
    var ffqty2=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('ftitem_codeD0[]')[j].focus();
             return false;
        }
        else if (document.getElementsByName('ftwarehouse_codeD0[]')[j].value=='') {
             alert('Gudang harus diisi..');
              document.getElementsByName('ftwarehouse_codeD0[]')[j].focus();
             return false;
        }
        else if (document.getElementsByName('ftlocation_codeD0[]')[j].value=='') {
             alert('Lokasi harus diisi..');
             document.getElementsByName('ftlocation_codeD0[]')[j].focus();
             return false;
        }
        else if (document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1<=0) {
             document.getElementsByName('fnqtyD0[]')[j].focus();
             alert('Qty keluar harus diisi..');
             return false;
        }
        else if (document.getElementsByName('fnqty_baseD0[]')[j].value.replace(/,/g,'')*1<=0) {
            alert('Qty Base tidak boleh 0..');
            document.getElementsByName('fnqty_baseD0[]')[j].focus();
            return false;
        }
        else if(ffqty1>ffqty2 ) {
            alert('Qty keluar lebih besar dari Qty Avail...');
            document.getElementsByName('fnqtyD0[]')[j].focus();
            return false;
        }
//        else if(document.getElementById('ftcategory_code').value=='1') {
//            if((document.getElementsByName('fnqty_sisaD0[]')[j].value.replace(/,/g,'')*1<document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1)) {
//                    alert('Qty keluar lebih besar dari Qty Sisa return Penjualan...');
//                    document.getElementsByName('fnqtyD0[]')[j].focus();
//                    return false;
//            }
//        }
    }

    return true;
}

function ValMutasiBarangBahanBaku() {
  if(document.getElementById("ftstock_mutation_no").value=='') {
       alert('No. transaksi harus disi...');
       document.getElementById("ftstock_mutation_no").focus();
       return false;
  }
   else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }
  else if (StockMutasiInputQtyBahanBaku()==false) {
       return false;
  }
  if (accessExpDate()==false) {
       return false;
  }

   ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftstock_mutation_no').value);
   document.getElementById("ftstock_mutation_no").focus();
    return false;
}


function StockMutasiInputQtyBahanBaku() {
    var i=document.getElementsByName('fnindexD0[]').length;
    var ffqty1=0;
    var ffqty2=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('ftitem_codeD0[]')[j].focus();
            return false;
        }
        else if  (document.getElementsByName('ftwarehouse_fromD0[]')[j].value=='') {
            alert('Gudang Asal harus diisi...');
             document.getElementsByName('ftwarehouse_fromD0[]')[j].focus();
            return false;
        }
        else if  (document.getElementsByName('ftlocation_fromD0[]')[j].value=='') {
            alert('Lokasi Asal harus diisi...');
             document.getElementsByName('ftlocation_fromD0[]')[j].focus();
            return false;
        }
        else if  (document.getElementsByName('ftwarehouse_toD0[]')[j].value=='') {
            alert('Gudang Tujuan harus diisi...');
             document.getElementsByName('ftwarehouse_toD0[]')[j].focus();
            return false;
        }
        else if  (document.getElementsByName('ftlocation_toD0[]')[j].value=='') {
            alert('Lokasi Tujuan harus diisi...');
             document.getElementsByName('ftlocation_toD0[]')[j].focus();
            return false;
        }
        else if ( (document.getElementsByName('ftwarehouse_fromD0[]')[j].value==document.getElementsByName('ftwarehouse_fromD0[]')[j].value)&&(document.getElementsByName('ftlocation_fromD0[]')[j].value==document.getElementsByName('ftlocation_toD0[]')[j].value)) {
            document.getElementsByName('ftlocation_toD0[]')[j].focus();
            alert('Gudang dan lokasi asal tidak boleh sama dengan gudang dan lokasi tujuan ...');
            return false;
        }
        else if (ffqty2 <= 0) {
             document.getElementsByName('ftitem_codeD0[]')[j].focus();
             alert('Qty Avail barang tidak mencukupi..');
             return false;
        }
        else if (ffqty1 <= 0) {
             document.getElementsByName('fnqtyD0[]')[j].focus();
             alert('Qty mutasi harus diisi..');
             return false;
        }
        else if(ffqty1>ffqty2 ) {
            alert('Qty mutasi lebih besar dari Qty Avail...');
            document.getElementsByName('fnqtyD0[]')[j].focus();
            return false;
        }
        else if (document.getElementsByName('fnqty_baseD0[]')[j].value.replace(/,/g,'')*1<=0) {
            alert('Qty Base tidak boleh 0..');
            document.getElementsByName('fnqty_baseD0[]')[j].focus();
            return false;
        }

        for(var k=j+1;k<i;k++) {
            if ((document.getElementsByName('ftitem_codeD0[]')[j].value==document.getElementsByName('ftitem_codeD0[]')[k].value) &&
                (document.getElementsByName('ftwarehouse_fromD0[]')[j].value==document.getElementsByName('ftwarehouse_fromD0[]')[k].value) &&
                (document.getElementsByName('ftwarehouse_toD0[]')[j].value==document.getElementsByName('ftwarehouse_toD0[]')[k].value) &&
                (document.getElementsByName('ftlocation_fromD0[]')[j].value==document.getElementsByName('ftlocation_fromD0[]')[k].value) &&
                (document.getElementsByName('ftlocation_toD0[]')[j].value==document.getElementsByName('ftlocation_toD0[]')[k].value)) {
                    alert('Kode Barang yang sama tidak bisa ke gudang dan lokasi yang sama ');
                    document.getElementsByName('ftitem_codeD0[]')[j].focus();
                    return false;
                }
        }

    }

    return true;
}

// Mutasi bahan baku ke barang jadi
function ValMutasiBarangJadi() {
  if(document.getElementById("ftstock_mutation_no").value=='') {
       alert('No. transaksi harus disi...');
       document.getElementById("ftstock_mutation_no").focus();
       return false;
  }
   else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }
  else if (StockMutasiInputQtyBBToJadi()==false) {
       return false;
  }
  if (accessExpDate()==false) {
       return false;
  }

   ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftstock_mutation_no').value);
   document.getElementById("ftstock_mutation_no").focus();
    return false;
}


function StockMutasiInputQtyBBToJadi() {
    var i=document.getElementsByName('fnindexD0[]').length;
    var ffqty1=0;
    var ffqty2=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('ftitem_codeD0[]')[j].focus();
            return false;
        }
        else if  (document.getElementsByName('ftwarehouse_fromD0[]')[j].value=='') {
            alert('Gudang Asal harus diisi...');
             document.getElementsByName('ftwarehouse_fromD0[]')[j].focus();
            return false;
        }
        else if  (document.getElementsByName('ftlocation_fromD0[]')[j].value=='') {
            alert('Lokasi Asal harus diisi...');
             document.getElementsByName('ftlocation_fromD0[]')[j].focus();
            return false;
        }
        else if  (document.getElementsByName('ftwarehouse_toD0[]')[j].value=='') {
            alert('Gudang Tujuan harus diisi...');
             document.getElementsByName('ftwarehouse_toD0[]')[j].focus();
            return false;
        }
        else if  (document.getElementsByName('ftlocation_toD0[]')[j].value=='') {
            alert('Lokasi Tujuan harus diisi...');
             document.getElementsByName('ftlocation_toD0[]')[j].focus();
            return false;
        }
        else if ( (document.getElementsByName('ftwarehouse_fromD0[]')[j].value==document.getElementsByName('ftwarehouse_fromD0[]')[j].value)&&(document.getElementsByName('ftlocation_fromD0[]')[j].value==document.getElementsByName('ftlocation_toD0[]')[j].value)) {
            document.getElementsByName('ftlocation_toD0[]')[j].focus();
            alert('Gudang dan lokasi asal tidak boleh sama dengan gudang dan lokasi tujuan ...');
            return false;
        }
        else if (ffqty2 <= 0) {
             document.getElementsByName('ftitem_codeD0[]')[j].focus();
             alert('Qty Avail barang tidak mencukupi..');
             return false;
        }
        else if (ffqty1 <= 0) {
             document.getElementsByName('fnqtyD0[]')[j].focus();
             alert('Qty mutasi harus diisi..');
             return false;
        }
        else if(ffqty1>ffqty2 ) {
            alert('Qty mutasi lebih besar dari Qty Avail...');
            document.getElementsByName('fnqtyD0[]')[j].focus();
            return false;
        }
        else if (document.getElementsByName('fnqty_baseD0[]')[j].value.replace(/,/g,'')*1<=0) {
            alert('Qty Base tidak boleh 0..');
            document.getElementsByName('fnqty_baseD0[]')[j].focus();
            return false;
        }

        for(var k=j+1;k<i;k++) {
            if ((document.getElementsByName('ftitem_codeD0[]')[j].value==document.getElementsByName('ftitem_codeD0[]')[k].value) &&
                (document.getElementsByName('ftwarehouse_fromD0[]')[j].value==document.getElementsByName('ftwarehouse_fromD0[]')[k].value) &&
                (document.getElementsByName('ftwarehouse_toD0[]')[j].value==document.getElementsByName('ftwarehouse_toD0[]')[k].value) &&
                (document.getElementsByName('ftlocation_fromD0[]')[j].value==document.getElementsByName('ftlocation_fromD0[]')[k].value) &&
                (document.getElementsByName('ftlocation_toD0[]')[j].value==document.getElementsByName('ftlocation_toD0[]')[k].value)) {
                    alert('Kode Barang yang sama tidak bisa ke gudang dan lokasi yang sama ');
                    document.getElementsByName('ftitem_codeD0[]')[j].focus();
                    return false;
                }
        }

    }

    return true;
}

function FinalPenyesuaianBarangBahanBaku() {
    if(document.getElementById("ftstock_adjustment_no").value=='') {
        alert('No. transaksi harus disi...');
        document.getElementById("ftstock_adjustment_no").focus();
        return false;
    }
    else if(document.getElementsByName('fnindexD0[]').length==1) {
        alert('Detail transaksi belum di input ...');
        return false;
    }
    else if (StockPenyesuaianInputQtyBahanBaku()==false) {
        return false;
    }

    return true;
}

function ValPenyesuaianBarangBahanBaku() {
  if(document.getElementById("ftstock_adjustment_no").value=='') {
       alert('No. transaksi harus disi...');
       document.getElementById("ftstock_adjustment_no").focus();
       return false;
  }
   else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }
  else if (StockPenyesuaianInputQtyBahanBaku()==false) {
       return false;
  }
  if (accessExpDate()==false) {
       return false;
  }

    ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftstock_adjustment_no').value);
    document.getElementById("ftstock_adjustment_no").focus();
    return false;
}

function FinalPenyesuaianBarangSetengahJadi() {
    if(document.getElementById("ftstock_adjustment_no").value=='') {
        alert('No. transaksi harus disi...');
        document.getElementById("ftstock_adjustment_no").focus();
        return false;
    }
    else if(document.getElementsByName('fnindexD0[]').length==1) {
        alert('Detail transaksi belum di input ...');
        return false;
    }
    else if (StockPenyesuaianInputQtyBahanBaku()==false) {
        return false;
    }
    return true;
}

function ValPenyesuaianBarangSetengahJadi() {
  if(document.getElementById("ftstock_adjustment_no").value=='') {
       alert('No. transaksi harus disi...');
       document.getElementById("ftstock_adjustment_no").focus();
       return false;
  }
   else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }
  else if (StockPenyesuaianInputQtyBahanBaku()==false) {
       return false;
  }
  if (accessExpDate()==false) {
       return false;
  }

    ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftstock_adjustment_no').value);
   document.getElementById("ftstock_adjustment_no").focus();
    return false;
}


function StockPenyesuaianRecalQtyBahanBaku() {

    var i=document.getElementsByName('fnindexD0[]').length;
    var ffAvail=0;
    var ffqty=0;
    var ffOpname=0;
    for(var j=1;j<i;j++) {
        if(document.getElementsByName('fnqty_opnameD0[]')[j].value.replace(/,/g,'')*1<0) {
            document.getElementsByName('fnqtyD0[]')[j].value='0';
        }
        else {
              ffAvail=document.getElementsByName('fnqty_availableD0[]')[j].value.replace(/,/g,'')*1
              ffOpname=document.getElementsByName('fnqty_opnameD0[]')[j].value.replace(/,/g,'')*1;
              document.getElementsByName('fnqtyD0[]')[j].value= ffOpname-ffAvail;
        }
        
    }

}

function StockPenyesuaianRecalQty1BahanBaku(j) {
        var ffAvail=0;
        var ffqty=0;
        var ffOpname=0;
        ffAvail=document.getElementById('fnqty_availableD0'+j).value.replace(/,/g,'')*1;
        ffOpname=document.getElementById('fnqty_opnameD0'+j).value.replace(/,/g,'')*1 ;
        document.getElementById('fnqtyD0'+j).value= ffOpname-ffAvail;
        ElementCurrencyALL();
    }



function StockPenyesuaianInputQtyBahanBaku() {
    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('ftitem_codeD0[]')[j].focus();
             alert('Kode Barang belum valid..');
             return false;
        }
        else if (document.getElementsByName('ftwarehouse_codeD0[]')[j].value=='') {
             document.getElementsByName('ftwarehouse_codeD0[]')[j].focus();
             alert('Gudang harus diisi..');
             return false;
        }
        else if (document.getElementsByName('ftlocation_codeD0[]')[j].value=='') {
             document.getElementsByName('ftlocation_codeD0[]')[j].focus();
             alert('Lokasi harus diisi..');
             return false;
        }
        else if (document.getElementsByName('fnqty_opnameD0[]')[j].value.replace(/,/g,'')*1<0) {
             document.getElementsByName('fnqty_opnameD0[]')[j].focus();
             alert('Qty Opname harus diisi..');
             return false;
        }
        /*
        else if (document.getElementsByName('fnqty_availableD0[]')[j].value.replace(/,/g,'')*1<0) {
             document.getElementsByName('fnqty_availableD0[]')[j].focus();
             alert('Tidak bisa penyesuaian stock minus. ');
             return false;
        }
        */
        for(var k=j+1;k<i;k++) {
            if ((document.getElementsByName('ftitem_codeD0[]')[j].value==document.getElementsByName('ftitem_codeD0[]')[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)) {
                    alert('Kode Barang yang sama tidak bisa ke gudang dan lokasi yang sama ');
                    document.getElementsByName('ftitem_codeD0[]')[j].focus();
                    return false;
                }
        }
        
        if (document.getElementsByName('fnqty_opnameD0[]')[j].value.replace(/,/g,'')*1==0) {
            m='1';
        }
    }

    if (m==1) {
        if(confirm('Qty Opname ada yang 0, apakah transaksi akan diterus kan ???')) {
             return true;
        }
        else {
             return false;
        }
    }

    return true;

}

// Module Pembelian

// Master Ekspedisi
function ValEkspedisi() {

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

  }
  else if(document.getElementById("ftexpedition_name").value=='') {
       alert('Nama Ekspedisi harus diisi...');
       document.getElementById("ftexpedition_name").focus();
       return false;
  }

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

  return false;
}

// Purchase Request - Start

function ValPurchaseRequest() {
    if(document.getElementById("ftpr_no").value=='') {
        alert('No. transaksi harus disi...');
        document.getElementById("ftpr_no").focus();
        return false;
    }
    else if(document.getElementsByName('fnindexD0[]').length<1) {
        alert('Detail transaksi harus disi...');
        return false;
    }
    else if (PurchaseRequestInputQty()==false) {
        return false;
    }

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

  return false;

}

function PurchaseRequestInputQty() {
    var m="";

    var i=document.getElementsByName('fnindexD0[]').length;
    for(var j=1;j<i;j++) {
        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 (document.getElementsByName('fnqty_baseD0[]')[j].value.replace(/,/g,'')*1<=0) {
            alert('Qty Base tidak boleh 0..');
            document.getElementsByName('fnqty_baseD0[]')[j].focus();
            return false;
        }
        else if (document.getElementsByName('ftuom_codeD0[]')[j].value == '') {
              alert('Satuan harus di isi ...');
              document.getElementsByName('ftuom_codeD0[]')[j].focus();
              return false;
        }
    }
    return true;
}


function RevisiPurchaseRequest() {

    if(document.getElementById("ftpr_no").value=='') {
        alert('No. transaksi harus disi...');
        document.getElementById("ftpr_no").focus();
        return false;
    }else if(document.getElementsByName('fnindexD0[]').length<1) {
        alert('Detail transaksi harus disi...');
        return false;
    }
    else if (PurchaseRequestInputQty()==false) {
         return false;
    }

  return true;

}

function FinalPurchaseRequest() {
    if(document.getElementById("ftpr_no").value=='') {
        alert('No. transaksi harus disi...');
        document.getElementById("ftpr_no").focus();
        return false;
    }else if(document.getElementsByName('fnindexD0[]').length<1) {
        alert('Detail transaksi harus disi...');
        return false;
    }
    else if (PurchaseRequestInputQty()==false) {
         return false;
    }

  return true;

}

// Purchase Order Local - Start

//function ValPurchaseOrderLocal() {
function ValPurchaseOrder() {
   
//    PurchaseOrderLocalRecalQty();
//    PurchaseOrderRecalQty();
    if(document.getElementById("ftpo_no").value=='') {
        alert('No. transaksi harus disi...');
        document.getElementById("ftpo_no").focus();
        return false;
    }
    else if(document.getElementById("fnpo_type").value=='') {
        alert('Jenis PO harus disi...');
        document.getElementById("fnpo_type").focus();
        return false;
    }
    else if(document.getElementById("hidden_ftsupplier_code").value=='') {
        alert('Kode supplier belum valid...');
        document.getElementById("ftsupplier_code").focus();
        return false;
    }
    else if(document.getElementById("ftterm_payment").value=='') {
        alert('Syarat pembayaran belum diisi...');
        document.getElementById("ftterm_payment").focus();
        return false;
    }
    else if(document.getElementById("ftcurrency_code").value=='') {
        alert('Mata uang belum di isi...');
        document.getElementById("ftcurrency_code").focus();
        return false;
    }
    else if(document.getElementById('fcrate').value.replace(/,/g,'')*1<=0) {
        alert('Kurs Belum valid...');
        document.getElementById("fcrate").focus();
        return false;
    }
    
    else if(document.getElementById("fntax_code").value=='') {
        alert('Kode pajak belum diisi...');
        document.getElementById("fntax_code").focus();
        return false;
    }
    else if (document.getElementById('ffdiscount').value.replace(/,/g,'')*1 > 100) {
        alert('Discount tidak boleh lebih dari 100 ...');
        document.getElementById('ffdiscount').focus();
        return false;
    }
    else if (document.getElementById('ffvat').value.replace(/,/g,'')*1 > 100) {
        alert('Pajak tidak boleh lebih dari 100%. Harap cek kembali dan perhatikan mata uang nya.');
        document.getElementById('ffvat').focus();
        return false;
    }
    else if(document.getElementsByName('fnindexD0[]').length<1) {
        alert('Detail transaksi harus disi...');
        return false;
    }
    //else if (PurchaseOrderItem()==false) {
    //    alert('Item code tidak boleh sama pada daftar barang.');
    //     return false;
    //}
//    else if (PurchaseOrderLocalInputQty()==false) {
    else if (PurchaseOrderInputQty()==false) {
         return false;
    }

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

  return false;

}

function PurchaseOrderItem(){
  var i=document.getElementsByName('fnindexD0[]').length;
  var arr=new Array();
  var bool=true;

  for(var j=1; j < i; j++){
    arr[j]=document.getElementsByName('ftitem_codeD0[]')[j].value;
  }

  arr.sort();
  var arrlast=arr[0];
  for(j=1; j < arr.length; j++){
    if(arr[j]==arrlast){
      bool=false;
      break;
    }else{
      arrlast=arr[j];
    }
  }
  
  return bool;
}

//function PurchaseOrderLocalRecalQty() {
function PurchaseOrderRecalQty() {

    var i=document.getElementsByName('fnindexD0[]').length;
    var fnqtyD=0;
    var fcpriceD=0;
    var ffdiscountD=0;
    var fcdiscountD=0;
    var fcamountD=0;

    var fcpayment_amount=0;
    var fcoutstanding_amount=0;
    var fcsub_amount=0;
    var ffdiscount=0;
    var fcdiscount=0;
    var fcother_cost=0;
    var ffvat=0;
    var fcvat=0;
    var fcamount=0;


    for(var j=1;j<i;j++) {

//        if(document.getElementsByName('ftstock_category_codeD[]')[j].value=='inv') {
              fnqtyD=document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1;
//        }
//        else {
//            fnqtyD=1;
//        }
        fcpriceD=document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1;
        ffdiscountD=document.getElementsByName('ffdiscountD0[]')[j].value.replace(/,/g,'')*1;
        fcdiscountD=(fnqtyD*fcpriceD)*(ffdiscountD/100);
        fcdiscountD=Math.round(fcdiscountD*100)/100;
        fcamountD=Math.round((fnqtyD*fcpriceD)*100/100);
        fcamountD=fcamountD-fcdiscountD;
        fcamountD=Math.round((fcamountD)*100/100);
        fcsub_amount+=fcamountD;
        document.getElementsByName('fcdiscountD0[]')[j].value=fcdiscountD;
        document.getElementsByName('fcamountD0[]')[j].value=fcamountD;
    }
    document.getElementById('fcsub_amount').value=fcsub_amount;
    ffdiscount=document.getElementById('ffdiscount').value.replace(/,/g,'')*1;
    fcdiscount=fcsub_amount*ffdiscount/100;
    fcdiscount=Math.round((fcdiscount)*100/100);
    

    fcother_cost=document.getElementById('fcother_cost').value.replace(/,/g,'')*1;
    fcother_cost=Math.round((fcother_cost)*100/100);

    ffvat= document.getElementById('ffvat').value.replace(/,/g,'')*1;
    fcvat=(fcsub_amount-fcdiscount+fcother_cost)*ffvat/100;
    fcvat=Math.round((fcvat)*100/100);
    
    fcamount=(fcsub_amount-fcdiscount)+fcvat+fcother_cost;
    fcamount=Math.round((fcamount)*100/100);
    fcoutstanding_amount=fcamount;
    fcpayment_amount=0;

    document.getElementById('fcdiscount').value=fcdiscount;
    document.getElementById('fcvat').value=fcvat;
    document.getElementById('fcamount').value=fcamount;
//    document.getElementById('fcoutstanding_amount').value=fcoutstanding_amount;
//    document.getElementById('fcpayment_amount').value=fcpayment_amount;

    return true;
}

//function PurchaseOrderLocalRecalPrice() {
function PurchaseOrderRecalPrice() {
//    PurchaseOrderLocalRecalQty0();
    PurchaseOrderRecalQty0();
}

//function PurchaseOrderLocalRecalDiscPercent() {
function PurchaseOrderRecalDiscPercent() {
      var fcsub_amount=document.getElementById('fcsub_amount').value.replace(/,/g,'')*1;
      var ffdiscount=document.getElementById('ffdiscount').value*1;  
      var fcdiscount=fcsub_amount*ffdiscount/100;
      
      //fcdiscount=Math.round((fcdiscount)*100/100);
      document.getElementById('fcdiscount').value=fcdiscount;
      ElementCurrencyOnBlur(document.getElementById('fcdiscount'));
//      PurchaseOrderLocalRecalQty0();
      PurchaseOrderRecalQty0();
}

//function PurchaseOrderLocalRecalDiscRp() {
function PurchaseOrderRecalDiscRp() {
      var fcsub_amount=document.getElementById('fcsub_amount').value.replace(/,/g,'')*1;
      var fcdiscount=document.getElementById('fcdiscount').value.replace(/,/g,'')*1;
      var ffdiscount=(fcdiscount/(fcsub_amount))*100;

      // ffdiscount=Math.round((ffdiscount)*100/100);
      document.getElementById('ffdiscount').value=ffdiscount;
      ElementCurrencyOnBlur(document.getElementById('ffdiscount'));
//      PurchaseOrderLocalRecalQty0();
      PurchaseOrderRecalQty0();
}

//function PurchaseOrderLocalRecalDiscDetailPercent(index) {
function PurchaseOrderRecalDiscDetailPercentOld(index) {
    var fnqtyD=0;
//     if(document.getElementById('ftstock_category_codeD'+index).value=='inv') {
              fnqtyD=document.getElementById('fnqtyD0'+index).value.replace(/,/g,'')*1;
//      }
//      else {
//          fnqtyD=1;
//      }
       var fcpriceD=document.getElementById('fcpriceD0'+index).value.replace(/,/g,'')*1;
       var ffdiscountD=document.getElementById('ffdiscountD0'+index).value.replace(/,/g,'')*1;
       var fcdiscountD=(fnqtyD*fcpriceD)*(ffdiscountD/100);
       //fcdiscountD=Math.round((fcdiscountD)*100/100);

       document.getElementById('fcdiscountD0'+index).value=fcdiscountD;
//      PurchaseOrderLocalRecalQty0();
      PurchaseOrderRecalQty0();

      ElementCurrencyALL();
}

function PurchaseOrderRecalDiscDetailPercent(index) {
    var fnqtyD=0;
    fnqtyD=document.getElementById('fnqtyD0'+index).value.replace(/,/g,'')*1;
    var fcpriceD=document.getElementById('fcpriceD0'+index).value.replace(/,/g,'')*1;
    var ffdiscountD=document.getElementById('ffdiscountD0'+index).value;
    //var ffdiscountD=document.getElementById('ffdiscountD0'+index).value.replace(/,/g,'')*1;
    var fcdiscountD=0;
    //var fcdiscountD=(fnqtyD*fcpriceD)*(ffdiscountD/100);
    //fcdiscountD=Math.round((fcdiscountD)*100/100);

    // tier discount 
    var str_ffdiscountD = ffdiscountD + '';
    var str_ffdiscountD = str_ffdiscountD.split('+');
 
    for(var i = 0; i < str_ffdiscountD.length; i++) {
        // Trim the excess whitespace.
        str_ffdiscountD[i] = str_ffdiscountD[i].replace(/^\s*/, "").replace(/\s*$/, "");
        fcdiscountD = fcdiscountD + (fcpriceD * (str_ffdiscountD[i]/100));
        fcpriceD = fcpriceD - (fcpriceD * (str_ffdiscountD[i]/100));
    }
    fcdiscountD = (fnqtyD * fcdiscountD);
   
    document.getElementById('fcdiscountD0'+index).value=fcdiscountD;      
    PurchaseOrderRecalQty0();
    //ElementCurrencyALL();

}

//function PurchaseOrderLocalRecalDiscDetailRp(index) {
function PurchaseOrderRecalDiscDetailRp(index) {
     var fnqtyD=0;
//     if(document.getElementById('ftstock_category_codeD'+index).value=='inv') {
              fnqtyD=document.getElementById('fnqtyD0'+index).value.replace(/,/g,'')*1;
//      }
//      else {
//          fnqtyD=1;
//      }
       var fcpriceD=document.getElementById('fcpriceD0'+index).value.replace(/,/g,'')*1;
       var fcdiscountD= document.getElementById('fcdiscountD0'+index).value.replace(/,/g,'')*1;
       var ffdiscountD=(fcdiscountD/(fnqtyD*fcpriceD))*100;
        //ffdiscountD=Math.round((ffdiscountD)*100/100);
       document.getElementById('ffdiscountD0'+index).value=ffdiscountD;
       ElementCurrencyOnBlur(document.getElementById('ffdiscountD0'+index));
//       PurchaseOrderLocalRecalQty0();
       PurchaseOrderRecalQty0();
}

//function PurchaseOrderLocalRecalQty0() {
function PurchaseOrderRecalQty0() {

    var i=document.getElementsByName('fnindexD0[]').length;
    var fnqtyD=0;
    var fcpriceD=0;
    var ffdiscountD=0;
    var fcdiscountD=0;
    var fcamountD=0;

    var fcpayment_amount=0;
    var fcoutstanding_amount=0;
    var fcsub_amount=0;
    var ffdiscount=0;
    var fcdiscount=0;
    var fcother_cost=0;
    var ffvat=0;
    var fcvat=0;
    var fcamount=0;


    for(var j=1;j<i;j++) {
        fnqtyD=document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1;
        ffformulaD=document.getElementsByName('ffformulaD0[]')[j].value.replace(/,/g,'')*1;
        fcpriceD=document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1;
        fcdiscountD=document.getElementsByName('fcdiscountD0[]')[j].value.replace(/,/g,'')*1;

        fcamountD=(fnqtyD*fcpriceD )-fcdiscountD;//#
        document.getElementsByName('fcamountD0[]')[j].value=fcamountD;

        fchppD=fcamountD/fnqtyD;
        document.getElementsByName('fchppD0[]')[j].value=fchppD;

        if(document.getElementsByName('fnstatusD0[]')[j].value!='9') {
            fcsub_amount+= document.getElementsByName('fcamountD0[]')[j].value.replace(/,/g,'')*1;
        }
        
	fnqty_baseD=(fnqtyD*ffformulaD);
        document.getElementsByName('fnqty_baseD0[]')[j].value=fnqty_baseD;	
        document.getElementsByName('fnqty_limitD0[]')[j].value=fnqty_baseD;		

    }
    document.getElementById('fcsub_amount').value=fcsub_amount;
    fcdiscount=document.getElementById('fcdiscount').value.replace(/,/g,'')*1;
//    fcdiscount=Math.round((fcdiscount)*100/100);
  

    fcother_cost=document.getElementById('fcother_cost').value.replace(/,/g,'')*1;
//    fcother_cost=Math.round((fcother_cost)*100/100);

    ffvat= document.getElementById('ffvat').value.replace(/,/g,'')*1;
    if (ffvat != 0) { 
        fcvat=(fcsub_amount-fcdiscount+fcother_cost)*ffvat/100;
    } else {    
        fcvat= document.getElementById('fcvat').value.replace(/,/g,'')*1;
        ffvat= (fcvat / (fcsub_amount-fcdiscount+fcother_cost)) * 100 ;
        document.getElementById('ffvat').value = ffvat;
    }    
    //    fcvat=Math.round((fcvat)*100/100);
    // calculate hpp (include tax)
    for(var j=1;j<i;j++) {
        fchppD=document.getElementsByName('fchppD0[]')[j].value.replace(/,/g,'')*1;
        fchppD=fchppD + ((fchppD*ffvat)/100);
        document.getElementsByName('fchppD0[]')[j].value=fchppD;
    } 

    fcamount=(fcsub_amount-fcdiscount)+fcvat+fcother_cost;
//    fcamount=Math.round((fcamount)*100/100);
    fcoutstanding_amount=fcamount;
    fcpayment_amount=0;


    document.getElementById('fcdiscount').value=fcdiscount;
    document.getElementById('fcvat').value=fcvat;
    document.getElementById('fcamount').value=fcamount;
//    document.getElementById('fcoutstanding_amount').value=fcoutstanding_amount;
//    document.getElementById('fcpayment_amount').value=fcpayment_amount;
      ElementCurrencyALL();
    return true;
}

//function PurchaseOrderLocalInputQty() {
function PurchaseOrderInputQty() {
    var m="";

    var i=document.getElementsByName('fnindexD0[]').length;
    for(var j=1;j<i;j++) {
        if (document.getElementsByName('ftitem_codeD0[]')[j].value=='')  {
            alert('Kode barang belum valid ...');
            document.getElementsByName('ftitem_codeD0[]')[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 (document.getElementsByName('ftlocation_codeD0[]')[j].value=='') {
              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 harus di isi ...');
              document.getElementsByName('fnqtyD0[]')[j].focus();
              return false;
        }
        else if (document.getElementsByName('fnqty_baseD0[]')[j].value.replace(/,/g,'')*1<=0) {
            alert('Qty Base tidak boleh 0..');
            document.getElementsByName('fnqty_baseD0[]')[j].focus();
            return false;
        }
        else if (document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1<=0) {
              // alert('Harga harus di isi ...');
              // document.getElementsByName('fcpriceD0[]')[j].focus();
              m = 1;
              // return false;
        } /*
        else if (document.getElementsByName('fcselling_priceD0[]')[j].value.replace(/,/g,'')*1<=0) {
              alert('Harga Jual harus di isi ...');
              document.getElementsByName('fcselling_priceD0[]')[j].focus();
              return false;
        } */
        else if (document.getElementsByName('ffdiscountD0[]')[j].value.replace(/,/g,'')*1>100) {
            alert('Discount tidak boleh lebih dari 100 ...');
            document.getElementsByName('ffdiscountD0[]')[j].focus();
            return false;
        }
        else if (document.getElementsByName('ftuom_codeD0[]')[j].value=="") {
            alert('Satuan diisi ...');
            document.getElementsByName('ftuom_codeD0[]')[j].focus();
            return false;
        }

        
    }
    
    if(m == 1) {
        if(!confirm('Harga barang ada yang sebesar 0 Rupiah. ANDA YAKIN ?')) {
            return false;
        }
    }

    return true;
}

//function PurchaseOrderLocalInputQtyX() {
function PurchaseOrderInputQtyX() {
    var m="";


    var i=document.getElementsByName('fnindexD0[]').length;
    for(var j=1;j<i;j++) {
//        if (document.getElementsByName('fnqtyD[]')[j].value.replace(/,/g,'')*1<0)  {
//             alert('Qty harus di isi ...');
//            document.getElementsByName('fnqtyD[]')[j].focus();
//             return false;
//        }
//       else
       //alert('x');
        if (document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1<=0) {
              alert('Harga harus di isi ...');
              document.getElementsByName('fcpriceD0[]')[j].focus();
              return false;

        }
//        else if (document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1<document.getElementsByName('fcpriceListD[]')[j].value.replace(/,/g,'')*1) {
//            m=m+ document.getElementsByName('ftitem_codeD0[]')[j].value +'\n';
//        }
    }
//    if(m!="") {
//           if(confirm('Harga barang berikut lebih kecil dari harga jual :\n------------------------------------ \n '+m+'-------------------------------\n Apakah transaksi akan diteruskan??')) {
//                    return true;
//            }
//            else {
//                  return false;
//            }
//    }
    return true;
}

//function FinalPurchaseOrderLocal() {
function FinalPurchaseOrder() {

//    PurchaseOrderLocalRecalQty();
//    PurchaseOrderRecalQty();
    if(document.getElementById("ftpo_no").value=='') {
        alert('No. transaksi harus disi...');
        document.getElementById("ftpo_no").focus();
        return false;
    }
    else if(document.getElementById("hidden_ftsupplier_code").value=='') {
        alert('Kode supplier belum valid...');
        document.getElementById("ftsupplier_code").focus();
        return false;
    }
     else if(document.getElementById("ftterm_payment").value=='') {
        alert('Syarat pembayaran belum diisi...');
        document.getElementById("ftterm_payment").focus();
        return false;
    }
    else if(document.getElementById("ftcurrency_code").value=='') {
        alert('Mata uang belum di isi...');
        document.getElementById("ftcurrency_code").focus();
        return false;
    }
    else if(document.getElementById('fcrate').value.replace(/,/g,'')*1<=0) {
        alert('Kurs Belum valid...');
        document.getElementById("fcrate").focus();
        return false;
    }
    
    else if(document.getElementById("fntax_code").value=='') {
        alert('Kode pajak belum diisi...');
        document.getElementById("fntax_code").focus();
        return false;
    }
    else if(document.getElementsByName('fnindexD0[]').length<1) {
        alert('Detail transaksi harus disi...');
        return false;
    }
    else if (PurchaseOrderItem()==false) {
        alert('Item code tidak boleh sama pada daftar barang.');
         return false;
    }
//    else if (PurchaseOrderLocalInputQty()==false) {
    else if (PurchaseOrderInputQty()==false) {
         return false;
    }
    
    return true;

}
//function RevisiPurchaseOrderLocal() {
function RevisiPurchaseOrder() {

    if(document.getElementById("ftpo_no").value=='') {
        alert('No. transaksi harus disi...');
        document.getElementById("ftpo_no").focus();
        return false;
    }
    else if(document.getElementById("hidden_ftsupplier_code").value=='') {
        alert('Kode supplier belum valid...');
        document.getElementById("ftsupplier_code").focus();
        return false;
    }
     else if(document.getElementById("ftterm_payment").value=='') {
        alert('Syarat pembayaran belum diisi...');
        document.getElementById("ftterm_payment").focus();
        return false;
    }
    else if(document.getElementById("ftcurrency_code").value=='') {
        alert('Mata uang belum di isi...');
        document.getElementById("ftcurrency_code").focus();
        return false;
    }
    else if(document.getElementById('fcrate').value.replace(/,/g,'')*1<=0) {
        alert('Kurs Belum valid...');
        document.getElementById("fcrate").focus();
        return false;
    }

    else if(document.getElementById("fntax_code").value=='') {
        alert('Kode pajak belum diisi...');
        document.getElementById("fntax_code").focus();
        return false;
    }

//    else if(document.getElementById("ftvat_no").value=='') {
//        alert('No. faktur pajak harus disi...');
//        document.getElementById("ftvat_no").focus();
//        return false;
//    }
    else if(document.getElementsByName('fnindexD0[]').length<1) {
        alert('Detail transaksi harus disi...');
        return false;
    }
//    else if (PurchaseOrderLocalInputQty()==false) {
    else if (PurchaseOrderInputQty()==false) {
         return false;
    }

    
  return true;

}

function ValPurchaseOrderImport() {

//    PurchaseOrderImportRecalQty();
    if(document.getElementById("ftpo_no").value=='') {
        alert('No. transaksi harus disi...');
        document.getElementById("ftpo_no").focus();
        return false;
    }
    else if(document.getElementById("hidden_ftsupplier_code").value=='') {
        alert('Kode supplier belum valid...');
        document.getElementById("ftsupplier_code").focus();
        return false;
    }
     else if(document.getElementById("ftterm_payment").value=='') {
        alert('Syarat pembayaran belum diisi...');
        document.getElementById("ftterm_payment").focus();
        return false;
    }
    else if(document.getElementById("ftcurrency_code").value=='') {
        alert('Mata uang belum di isi...');
        document.getElementById("ftcurrency_code").focus();
        return false;
    }
    else if(document.getElementById('fcrate').value.replace(/,/g,'')*1<=0) {
        alert('Kurs Belum valid...');
        document.getElementById("fcrate").focus();
        return false;
    }
    else if(document.getElementById("fntax_code").value=='') {
        alert('Kode pajak belum diisi...');
        document.getElementById("fntax_code").focus();
        return false;
    }
    else if (document.getElementById('ffdiscount').value.replace(/,/g,'')*1 > 100) {
        alert('Discount tidak boleh lebih dari 100 ...');
        document.getElementById('ffdiscount').focus();
        return false;
    }
    else if(document.getElementsByName('fnindexD0[]').length<1) {
        alert('Detail transaksi harus disi...');
        return false;
    }
    else if (PurchaseOrderItem()==false) {
        alert('Item code tidak boleh sama pada daftar barang.');
         return false;
    }
    else if (PurchaseOrderImportInputQty()==false) {
         return false;
    }

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

  return false;

}

function PurchaseOrderImportRecalQty() {

    var i=document.getElementsByName('fnindexD0[]').length;
    var fnqtyD=0;
    var fcpriceD=0;
    var ffdiscountD=0;
    var fcdiscountD=0;
    var fcamountD=0;

    var fcpayment_amount=0;
    var fcoutstanding_amount=0;
    var fcsub_amount=0;
    var ffdiscount=0;
    var fcdiscount=0;
    var fcother_cost=0;
    var ffvat=0;
    var fcvat=0;
    var fcamount=0;


    for(var j=1;j<i;j++) {

//        if(document.getElementsByName('ftstock_category_codeD[]')[j].value=='inv') {
              fnqtyD=document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1;
//        }
//        else {
//            fnqtyD=1;
//        }
        fcpriceD=document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1;
        ffdiscountD=document.getElementsByName('ffdiscountD0[]')[j].value.replace(/,/g,'')*1;
        fcdiscountD=(fnqtyD*fcpriceD)*(ffdiscountD/100);
//        fcdiscountD=Math.round(fcdiscountD*100)/100;
//        fcamountD=Math.round((fnqtyD*fcpriceD)*100/100);
        fcamountD=fnqtyD*fcpriceD;
        fcamountD=fcamountD-fcdiscountD;
//        fcamountD=Math.round((fcamountD)*100/100);
        fcsub_amount+=fcamountD;
        document.getElementsByName('fcdiscountD0[]')[j].value=fcdiscountD;
        document.getElementsByName('fcamountD0[]')[j].value=fcamountD;
    }
    document.getElementById('fcsub_amount').value=fcsub_amount;
    ffdiscount=document.getElementById('ffdiscount').value.replace(/,/g,'')*1;
    fcdiscount=fcsub_amount*ffdiscount/100;
//    fcdiscount=Math.round((fcdiscount)*100/100);
//     fcdiscount=Math.round((fcdiscount)*100/100);
  

    fcother_cost=document.getElementById('fcother_cost').value.replace(/,/g,'')*1;
//    fcother_cost=Math.round((fcother_cost)*100/100);

    ffvat= document.getElementById('ffvat').value.replace(/,/g,'')*1;
    fcvat=(fcsub_amount-fcdiscount+fcother_cost)*ffvat/100;
//    fcvat=Math.round((fcvat)*100/100);
    
    fcamount=(fcsub_amount-fcdiscount)+fcvat+fcother_cost;
//    fcamount=Math.round((fcamount)*100/100);
    fcoutstanding_amount=fcamount;
    fcpayment_amount=0;

    document.getElementById('fcdiscount').value=fcdiscount;
    document.getElementById('fcvat').value=fcvat;
    document.getElementById('fcamount').value=fcamount;

//    document.getElementById('fcoutstanding_amount').value=fcoutstanding_amount;
//    document.getElementById('fcpayment_amount').value=fcpayment_amount;

    return true;
}

function PurchaseOrderImportRecalPrice() {
    PurchaseOrderImportRecalQty0();

}

function PurchaseOrderImportRecalDiscPercent() {
      var fcsub_amount=document.getElementById('fcsub_amount').value.replace(/,/g,'')*1;
      var ffdiscount=document.getElementById('ffdiscount').value.replace(/,/g,'')*1;
      var  fcdiscount=fcsub_amount*ffdiscount/100;
//       fcdiscount=Math.round((fcdiscount)*100/100);

      document.getElementById('fcdiscount').value=fcdiscount;
      ElementCurrencyOnBlur(document.getElementById('fcdiscount'));
      PurchaseOrderImportRecalQty0();
}

function PurchaseOrderImportRecalDiscRp() {
      var fcsub_amount=document.getElementById('fcsub_amount').value.replace(/,/g,'')*1;
      var fcdiscount=document.getElementById('fcdiscount').value.replace(/,/g,'')*1;
      var ffdiscount=(fcdiscount/(fcsub_amount))*100;

//       ffdiscount=Math.round((ffdiscount)*100/100);
      document.getElementById('ffdiscount').value=ffdiscount;
      ElementCurrencyOnBlur(document.getElementById('ffdiscount'));
      PurchaseOrderImportRecalQty0();
}

function PurchaseOrderImportRecalDiscDetailPercent(index) {
    var fnqtyD=0;
//     if(document.getElementById('ftstock_category_codeD'+index).value=='inv') {
              fnqtyD=document.getElementById('fnqtyD0'+index).value.replace(/,/g,'')*1;
//      }
//      else {
//          fnqtyD=1;
//      }
       var fcpriceD=document.getElementById('fcpriceD0'+index).value.replace(/,/g,'')*1;
       var ffdiscountD=document.getElementById('ffdiscountD0'+index).value.replace(/,/g,'')*1;
       var fcdiscountD=(fnqtyD*fcpriceD)*(ffdiscountD/100);
//       fcdiscountD=Math.round((fcdiscountD)*100/100);

       document.getElementById('fcdiscountD0'+index).value=fcdiscountD;
      ElementCurrencyOnBlur(document.getElementById('ffdiscount'));
      PurchaseOrderImportRecalQty0();
}

function PurchaseOrderImportRecalDiscDetailRp(index) {
     var fnqtyD = 0;
//     if(document.getElementById('ftstock_category_codeD'+index).value=='inv') {
              fnqtyD=document.getElementById('fnqtyD0'+index).value.replace(/,/g,'')*1;
//      }
//      else {
//          fnqtyD=1;
//      }
       var fcpriceD=document.getElementById('fcpriceD0'+index).value.replace(/,/g,'')*1;
       var fcdiscountD= document.getElementById('fcdiscountD0'+index).value.replace(/,/g,'')*1;
       var ffdiscountD=(fcdiscountD/(fnqtyD*fcpriceD))*100;
//        ffdiscountD=Math.round((ffdiscountD)*100/100);
       document.getElementById('ffdiscountD0'+index).value=ffdiscountD;
       ElementCurrencyOnBlur(document.getElementById('ffdiscountD0'+index));
       PurchaseOrderImportRecalQty0();
}

function PurchaseOrderImportRecalQty0() {

    var i=document.getElementsByName('fnindexD0[]').length;
    var fnqtyD=0;
    var fcpriceD=0;
    var ffdiscountD=0;
    var fcdiscountD=0;
    var fcamountD=0;

    var fcpayment_amount=0;
    var fcoutstanding_amount=0;
    var fcsub_amount=0;
    var ffdiscount=0;
    var fcdiscount=0;
    var fcother_cost=0;
    var ffvat=0;
    var fcvat=0;
    var fcamount=0;


    for(var j=1;j<i;j++) {

//        if(document.getElementsByName('ftstock_category_codeD[]')[j].value=='inv') {
              fnqtyD=document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1;
			  ffformulaD=document.getElementsByName('ffformulaD0[]')[j].value.replace(/,/g,'')*1;			  

//        }
//        else {
//            fnqtyD=1;
//        }
        fcpriceD=document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1;
        fcdiscountD=document.getElementsByName('fcdiscountD0[]')[j].value.replace(/,/g,'')*1;

//        fcamountD=Math.round(((fnqtyD*fcpriceD )-fcdiscountD)*100/100);
        fcamountD=(fnqtyD*fcpriceD )-fcdiscountD;
        
        document.getElementsByName('fcamountD0[]')[j].value=fcamountD;
        fcsub_amount+= document.getElementsByName('fcamountD0[]')[j].value.replace(/,/g,'')*1;
		
		fnqty_baseD=(fnqtyD*ffformulaD);
        document.getElementsByName('fnqty_baseD0[]')[j].value=fnqty_baseD;	
    }
    document.getElementById('fcsub_amount').value=fcsub_amount;
    fcdiscount=document.getElementById('fcdiscount').value.replace(/,/g,'')*1;  

    fcother_cost=document.getElementById('fcother_cost').value.replace(/,/g,'')*1;
//    fcother_cost=Math.round((fcother_cost)*100/100);

    ffvat= document.getElementById('ffvat').value.replace(/,/g,'')*1;
    fcvat=(fcsub_amount-fcdiscount+fcother_cost)*ffvat/100;
//    fcvat=Math.round((fcvat)*100/100);
    
    fcamount=(fcsub_amount-fcdiscount)+fcvat+fcother_cost;
//    fcamount=Math.round((fcamount)*100/100);
    fcoutstanding_amount=fcamount;
    fcpayment_amount=0;


    document.getElementById('fcdiscount').value=fcdiscount;
    document.getElementById('fcvat').value=fcvat;
    document.getElementById('fcamount').value=fcamount;
    //document.getElementById('fcoutstanding_amount').value=fcoutstanding_amount;
    //document.getElementById('fcpayment_amount').value=fcpayment_amount;
      ElementCurrencyALL();
    return true;
}

function PurchaseOrderImportInputQty() {
    var m="";


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

        if (document.getElementsByName('ftitem_codeD0[]')[j].value=='')  {
             alert('Kode barang belum valid ...');
            document.getElementsByName('ftitem_codeD0[]')[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 (document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1<=0) {
            alert('Qty tidak boleh 0..');
            document.getElementsByName('fnqtyD0[]')[j].focus();
            return false;
        }
        else if (document.getElementsByName('fnqty_baseD0[]')[j].value.replace(/,/g,'')*1<=0) {
            alert('Qty Base tidak boleh 0..');
            document.getElementsByName('fnqty_baseD0[]')[j].focus();
            return false;
        }
        else if (document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1<=0) {
              alert('Harga harus di isi ...');
              document.getElementsByName('fcpriceD0[]')[j].focus();
              return false;
        }
        else if (document.getElementsByName('ffdiscountD0[]')[j].value.replace(/,/g,'')*1>100) {
              alert('Discount tidak boleh lebih dari 100 ...');
              document.getElementsByName('ffdiscountD0[]')[j].focus();
              return false;
        } 
        else if (document.getElementsByName('ftuom_codeD0[]')[j].value=="") {
                alert('Satuan diisi ...');
                document.getElementsByName('ftuom_codeD0[]')[j].focus();
                return false;
        }

    }

    return true;
}

function PurchaseOrderImportInputQtyX() {
    var m="";


    var i=document.getElementsByName('fnindexD0[]').length;
    for(var j=1;j<i;j++) {
//        if (document.getElementsByName('fnqtyD[]')[j].value.replace(/,/g,'')*1<0)  {
//             alert('Qty harus di isi ...');
//            document.getElementsByName('fnqtyD[]')[j].focus();
//             return false;
//        }
//       else
       //alert('x');
        if (document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1<=0) {
              alert('Harga harus di isi ...');
              document.getElementsByName('fcpriceD0[]')[j].focus();
              return false;

        }
//        else if (document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1<document.getElementsByName('fcpriceListD[]')[j].value.replace(/,/g,'')*1) {
//            m=m+ document.getElementsByName('ftitem_codeD0[]')[j].value +'\n';
//        }
    }
//    if(m!="") {
//           if(confirm('Harga barang berikut lebih kecil dari harga jual :\n------------------------------------ \n '+m+'-------------------------------\n Apakah transaksi akan diteruskan??')) {
//                    return true;
//            }
//            else {
//                  return false;
//            }
//    }
    return true;
}

function FinalPurchaseOrderImport() {
    
    if(document.getElementById("ftpo_no").value=='') {
        alert('No. transaksi harus disi...');
        document.getElementById("ftpo_no").focus();
        return false;
    }
    else if(document.getElementById("hidden_ftsupplier_code").value=='') {
        alert('Kode supplier belum valid...');
        document.getElementById("ftsupplier_code").focus();
        return false;
    }
    else if(document.getElementById("ftterm_payment").value=='') {
        alert('Syarat pembayaran belum diisi...');
        document.getElementById("ftterm_payment").focus();
        return false;
    }
    else if(document.getElementById("ftcurrency_code").value=='') {
        alert('Mata uang belum di isi...');
        document.getElementById("ftcurrency_code").focus();
        return false;
    }
    else if(document.getElementById('fcrate').value.replace(/,/g,'')*1<=0) {
        alert('Kurs Belum valid...');
        document.getElementById("fcrate").focus();
        return false;
    }
    else if(document.getElementById("fntax_code").value=='') {
        alert('Kode pajak belum diisi...');
        document.getElementById("fntax_code").focus();
        return false;
    }
    else if(document.getElementsByName('fnindexD0[]').length<1) {
        alert('Detail transaksi harus disi...');
        return false;
    }
    else if (PurchaseOrderItem()==false) {
        alert('Item code tidak boleh sama pada daftar barang.');
         return false;
    }
    else if (PurchaseOrderImportInputQty()==false) {
         return false;
    }
    
    return true;
}

function RevisiPurchaseOrderImport() {

//    PurchaseOrderImportRecalQty();
    if(document.getElementById("ftpo_no").value=='') {
        alert('No. transaksi harus disi...');
        document.getElementById("ftpo_no").focus();
        return false;
    }
//    else if(document.getElementById("ftvat_no").value=='') {
//        alert('No. faktur pajak harus disi...');
//        document.getElementById("ftvat_no").focus();
//        return false;
//    }
    else if(document.getElementsByName('fnindexD0[]').length<1) {
        alert('Detail transaksi harus disi...');
        return false;
    }
    else if (PurchaseOrderImportInputQty()==false) {
         return false;
    }

     return true;

}

function ValPenerimaanBarang() {
  StockMasukRecalQtyPembelian();
  if(document.getElementById("ftstock_in_no").value=='') {
       alert('No. transaksi harus disi...');
       document.getElementById("ftstock_in_no").focus();
       return false;
  }
  else if(document.getElementById("ftstock_type_code").value=='') {
       alert('Tipe Stock harus disi...');
       document.getElementById("ftstock_type_code").focus();
       return false;
  }
  else if(document.getElementById("ftcategory_code").value=='') {
       alert('Kategori harus disi...');
       document.getElementById("ftcategory_code").focus();
       return false;
  }
  /* else if(document.getElementById("hidden_ftstock_in_company").value=='') {
       alert('Supplier harus disi...');
       document.getElementById("ftstock_in_company").focus();
       return false;
  } 
  else if(document.getElementById("hidden_ftdocument_no").value=='') {
       alert('No.PO harus disi...');
       document.getElementById("ftdocument_no").focus();
       return false;
  } */

  else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }
   else if( document.getElementById('fntotal_qty').value.replace(/,/g,'')*1<=0) {
       alert('Detail transaksi belum di input ...');
      return false;
  }
//   else if(document.getElementById("ftdocument_no").value=='') {
//       alert('No. Document harus disi...');
//       document.getElementById("ftdocument_no").focus();
//       return false;
//  }
//  else if(document.getElementById("ftdelivery_no").value=='') {
//       alert('No. Surat Jalan harus disi...');
//       document.getElementById("ftdelivery_no").focus();
//       return false;
//  }
//  else if(document.getElementById("ftchecked_user").value=='') {
//       alert('Nama Pengecek barang harus diisi...');
//        document.getElementById("ftchecked_user").focus();
//       return false;
//  }
   else if (StockMasukInputQtyPembelian()==false) {
       return false;
  }
   
 ajax_do(str_url + '&ajax=1&code=transno&ftdocument_no=' + document.getElementById('ftdocument_no').value +'&fttrans_no=' + document.getElementById('ftstock_in_no').value);
   document.getElementById("ftstock_in_no").focus();
    return false;
}

function RevisiPenerimaanBarang() {

    if(document.getElementById("ftstock_in_no").value=='') {
        alert('No. transaksi harus disi...');
        document.getElementById("ftstock_in_no").focus();
        return false;
    }
    else if(document.getElementById("ftstock_type_code").value=='') {
       alert('Tipe Stock harus disi...');
       document.getElementById("ftstock_type_code").focus();
       return false;
    }
    else if(document.getElementsByName('fnindexD0[]').length<1) {
        alert('Detail transaksi harus disi...');
        return false;
    }
    else if (StockMasukInputQtyPembelian()==false) {
       return false;
    
	}
   
    return true;
}

function ValPenerimaanBarangImport() {
  StockMasukRecalQtyPembelian();
  if(document.getElementById("ftstock_in_no").value=='') {
       alert('No. transaksi harus disi...');
       document.getElementById("ftstock_in_no").focus();
       return false;
  }
  else if(document.getElementById("ftstock_type_code").value=='') {
       alert('Tipe Stock harus disi...');
       document.getElementById("ftstock_type_code").focus();
       return false;
  }
  else if(document.getElementById("ftcategory_code").value=='') {
       alert('Kategori harus disi...');
       document.getElementById("ftcategory_code").focus();
       return false;
  }
  else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }
   else if( document.getElementById('fntotal_qty').value.replace(/,/g,'')*1<=0) {
       alert('Detail transaksi belum di input ...');
      return false;
  }
   else if (StockMasukInputQtyPembelian()==false) {
       return false;
  }
   
 ajax_do(str_url + '&ajax=1&code=transno&ftdocument_no=' + document.getElementById('ftdocument_no').value +'&fttrans_no=' + document.getElementById('ftstock_in_no').value);
   document.getElementById("ftstock_in_no").focus();
    return false;
}

function RevisiPenerimaanBarangImport() {

    if(document.getElementById("ftstock_in_no").value=='') {
        alert('No. transaksi harus disi...');
        document.getElementById("ftstock_in_no").focus();
        return false;
    }
    else if(document.getElementById("ftstock_type_code").value=='') {
       alert('Tipe Stock harus disi...');
       document.getElementById("ftstock_type_code").focus();
       return false;
    }
    else if(document.getElementsByName('fnindexD0[]').length<1) {
        alert('Detail transaksi harus disi...');
        return false;
    }
    else if (StockMasukInputQtyPembelian()==false) {
       return false;
    
	}
   
    return true;
}

function ValStockMasukPembelian() {
  StockMasukRecalQtyPembelian();

  if(document.getElementById("ftstock_in_no").value=='') {
       alert('No. transaksi harus disi...');
       document.getElementById("ftstock_in_no").focus();
       return false;
  }
  else if(document.getElementById("ftcategory_code").value=='') {
       alert('Kategori harus disi...');
       document.getElementById("ftcategory_code").focus();
       return false;
  }
  else if(document.getElementById("hidden_ftstock_in_company").value=='') {
       alert('Supplier harus disi...');
       document.getElementById("ftstock_in_company").focus();
       return false;
  }
  else if(document.getElementById("hidden_ftdocument_no").value=='') {
       alert('No.PO harus disi...');
       document.getElementById("ftdocument_no").focus();
       return false;
  }
  else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }
  else if( document.getElementById('fntotal_qty').value.replace(/,/g,'')*1<=0) {
       alert('Detail transaksi belum di input ...');
      return false;
  }
  else if (StockMasukInputQtyPembelian()==false) {
       return false;
  }

  ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftstock_in_no').value);
   document.getElementById("ftstock_in_no").focus();
    return false;

}

function StockMasukRecalQtyPembelian() {

    var i=document.getElementsByName('fnindexD0[]').length;

    var ffqty=0;
    var fcprice=0;
    var ffTotal=0;
	
    for(var j=1;j<i;j++) {
        ffqty=document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1;
        ffTotal=ffTotal+ffqty;
    }
   
    document.getElementById('fntotal_qty').value=ffTotal;

}

function StockMasukRecalQtyPembelianMulti() {
    var i=document.getElementsByName('fnindexD0[]').length;
    var fnqty_poD=0;
    var ffformulaD=1;
    var fnqty_baseD=0;
    for(var j=1;j<i;j++) {		
        fnqtyD=document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1;
        ffformulaD=document.getElementsByName('ffformulaD0[]')[j].value.replace(/,/g,'')*1;
        fnqty_baseD=(fnqtyD*ffformulaD);
        document.getElementsByName('fnqty_baseD0[]')[j].value=fnqty_baseD;
    }

    ElementCurrencyALL();

    return true;
}

function StockMasukInputQtyPembelian() {
    var i=document.getElementsByName('fnindexD0[]').length;
    var m='';
    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;
        }
        else if (document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1>0) {
             if (document.getElementsByName('ftwarehouse_codeD0[]')[j].value=='') {
                 alert('Gudang harus diisi..');
                 document.getElementsByName('ftwarehouse_codeD0[]')[j].focus();
                 return false;
             }
             else if (document.getElementsByName('ftlocation_codeD0[]')[j].value=='') {
                 alert('Lokasi harus diisi..');
                 document.getElementsByName('ftlocation_codeD0[]')[j].focus();
                 return false;
             }
             else if (document.getElementsByName('fnqty_baseD0[]')[j].value.replace(/,/g,'')*1<=0) {
                alert('Qty Base tidak boleh 0..');
                document.getElementsByName('fnqty_baseD0[]')[j].focus();
                return false;
            }
        }
    }
    
    if(document.getElementById("ftcategory_code").value="0"){
        for(var j=1;j<i;j++) {
            // if(document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1  > ((document.getElementsByName('fnqtysisapoD0[]')[j].value.replace(/,/g,'')*1) + (document.getElementsByName('fnqtypoD0[]')[j].value.replace(/,/g,'')*1)*0.03) ) {
            if(document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1  > ((document.getElementsByName('fnqtysisapoD0[]')[j].value.replace(/,/g,'')*1)) ) {
                // alert('Qty Terima tidak boleh melebihi batas 3%');
                alert('Qty Terima tidak boleh melebihi qty PO');
                document.getElementsByName('fnqtyD0[]')[j].focus();
                return false;
            }
            else if(document.getElementsByName('fnqtysisapoD0[]')[j].value.replace(/,/g,'')*1<document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1) {
                m='1';
            }
        }
    }
	
    if(m!='') {
         if (!confirm('"Qty Masuk" ada yang melebihi "Qty PO", apakah transaksi akan diteruskan')) {
              return false;
         }
    }
    return true;
}

/*function StockMasukRecalQtyPembelian1(index) {

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

    }
     return true;


}*/


//function ValPurchaseInvoiceLocal() {
function ValPurchaseInvoice() {

//    PurchaseInvoiceLocalRecalQty();
    if(document.getElementById("ftpurchase_invoice_no").value=='') {
        alert('No. transaksi harus disi...');
        document.getElementById("ftpurchase_invoice_no").focus();
        return false;
    }
    else if(document.getElementById("fnpo_type").value=='') {
        alert('Jenis PO harus disi...');
        document.getElementById("fnpo_type").focus();
        return false;
    }
      else if(document.getElementById("hidden_ftstock_in_no").value=='') {
        alert('No. Terima belum valid...');
        document.getElementById("ftstock_in_no").focus();
        return false;
    }
  else  if(document.getElementById("hidden_ftsupplier_code").value=='') {
      alert('Supplier belum valid ...');
      document.getElementById("ftsupplier_code").focus();
      return false;
  }
  else if((document.getElementById("fcexpedition_cost").value.replace(/,/g,'')*1 > 0) && (document.getElementById("ftexpedition_code").value == '')) {
      alert('Kode Ekspedisi harap diisi ...');
      document.getElementById("ftexpedition_code").focus();
      return false;
  }
//    else if(document.getElementById("hidden_ftstock_in_no").value=='') {
//        alert('No. Stock Masuk belum valid...');
//        document.getElementById("ftstock_in_no").focus();
//        return false;
//    }
//     else if(document.getElementById("ftterm_payment").value=='') {
//        alert('Syarat pembayaran belum diisi...');
//        document.getElementById("ftterm_payment").focus();
//        return false;
//    }
//    else if(document.getElementById("ftcurrency_code").value=='') {
//        alert('Mata uang belum di isi...');
//        document.getElementById("ftcurrency_code").focus();
//        return false;
//    }
//    else if(document.getElementById('fcrate').value.replace(/,/g,'')*1<=0) {
//        alert('Kurs Belum valid...');
//        document.getElementById("fcrate").focus();
//        return false;
//    }
//
//    else if(document.getElementById("fntax_code").value=='') {
//        alert('Kode pajak belum diisi...');
//        document.getElementById("fntax_code").focus();
//        return false;
//    }

//    else if(document.getElementById("ftvat_no").value=='') {
//        alert('No. faktur pajak harus disi...');
//        document.getElementById("ftvat_no").focus();
//        return false;
//    }
    else if(document.getElementById('ffvat').value.replace(/,/g,'')*1 > 100) {
        alert('Pajak tidak boleh lebih dari 100%.');
        document.getElementById('ffvat').focus();
        return false;
    }
    else if(document.getElementsByName('fnindexD0[]').length<1) {
        alert('Detail transaksi harus disi...');
        return false;
    }
//    else if (PurchaseInvoiceLocalInputQty()==false) {
    else if (PurchaseInvoiceInputQty()==false) {
         return false;
    }

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

  return false;

}

function RevisiPurchaseInvoice() {

    if(document.getElementById("ftpurchase_invoice_no").value=='') {
        alert('No. transaksi harus disi...');
        document.getElementById("ftpurchase_invoice_no").focus();
        return false;
    }
    else if(document.getElementById("hidden_ftsupplier_code").value=='') {
        alert('Supplier belum valid ...');
        document.getElementById("ftsupplier_code").focus();
        return false;
    }
    else if((document.getElementById("fcexpedition_cost").value.replace(/,/g,'')*1 > 0) && (document.getElementById("ftexpedition_code").value == '')) {
        alert('Kode Ekspedisi harap diisi ...');
        document.getElementById("ftexpedition_code").focus();
        return false;
    }
    else if(document.getElementsByName('fnindexD0[]').length<1) {
        alert('Detail transaksi harus disi...');
        return false;
    }
    else if (PurchaseInvoiceImportInputQty()==false) {
         return false;
    }
     return true;

}

//function PurchaseInvoiceLocalRecalQty() {
function PurchaseInvoiceRecalQty() {

    var i=document.getElementsByName('fnindexD0[]').length;
    var fnqtyD=0;
    var fcpriceD=0;
    var ffdiscountD=0;
    var fcdiscountD=0;
    var fcamountD=0;

    var fcpayment_amount=0;
    var fcoutstanding_amount=0;
    var fcsub_amount=0;
    var ffdiscount=0;
    var fcdiscount=0;
    var fcother_cost=0;
    var ffvat=0;
    var fcvat=0;
    var fcamount=0;


    for(var j=1;j<i;j++) {

//        if(document.getElementsByName('ftstock_category_codeD[]')[j].value=='inv') {
              fnqtyD=document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1;
//        }
//        else {
//            fnqtyD=1;
//        }
        fcpriceD=document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1;
        ffdiscountD=document.getElementsByName('ffdiscountD0[]')[j].value.replace(/,/g,'')*1;
        fcdiscountD=(fnqtyD*fcpriceD)*(ffdiscountD/100);
//        fcdiscountD=Math.round(fcdiscountD*100)/100;
//        fcamountD=Math.round((fnqtyD*fcpriceD)*100/100);
        fcamountD=fnqtyD*fcpriceD;
        fcamountD=fcamountD-fcdiscountD;
//        fcamountD=Math.round((fcamountD)*100/100);
        fcsub_amount+=fcamountD;
        document.getElementsByName('fcdiscountD0[]')[j].value=fcdiscountD;
        document.getElementsByName('fcamountD0[]')[j].value=fcamountD;
    }
    document.getElementById('fcsub_amount').value=fcsub_amount;
    ffdiscount=document.getElementById('ffdiscount').value.replace(/,/g,'')*1;
    fcdiscount=fcsub_amount*ffdiscount/100;
//    fcdiscount=Math.round((fcdiscount)*100/100);

   

    fcother_cost=document.getElementById('fcother_cost').value.replace(/,/g,'')*1;
//    fcother_cost=Math.round((fcother_cost)*100/100);

    ffvat= document.getElementById('ffvat').value.replace(/,/g,'')*1;
    fcvat=(fcsub_amount-fcdiscount+fcother_cost)*ffvat/100;
//    fcvat=Math.round((fcvat)*100/100);

    fcamount=(fcsub_amount-fcdiscount)+fcvat+fcother_cost;
//    fcamount=Math.round((fcamount)*100/100);
    fcoutstanding_amount=fcamount;
    fcpayment_amount=0;

    document.getElementById('fcdiscount').value=fcdiscount;
    document.getElementById('fcvat').value=fcvat;
    document.getElementById('fcamount').value=fcamount;
//    document.getElementById('fcoutstanding_amount').value=fcoutstanding_amount;
//    document.getElementById('fcpayment_amount').value=fcpayment_amount;

    return true;
}

//function PurchaseInvoiceLocalRecalPrice() {
function PurchaseInvoiceRecalPrice() {
//    PurchaseInvoiceLocalRecalQty0();
    PurchaseInvoiceRecalQty0();
}

//function PurchaseInvoiceLocalRecalDiscPercent() {
function PurchaseInvoiceRecalDiscPercent() {
      var fcsub_amount=document.getElementById('fcsub_amount').value.replace(/,/g,'')*1;
      var ffdiscount=document.getElementById('ffdiscount').value*1;
      var  fcdiscount=fcsub_amount*ffdiscount/100;
//       fcdiscount=Math.round((fcdiscount)*100/100);
      document.getElementById('fcdiscount').value=fcdiscount;
//      PurchaseInvoiceLocalRecalQty0();
      PurchaseInvoiceRecalQty0();

}

//function PurchaseInvoiceLocalRecalDiscRp() {
function PurchaseInvoiceRecalDiscRp() {
      var fcsub_amount=document.getElementById('fcsub_amount').value.replace(/,/g,'')*1;
      var fcdiscount=document.getElementById('fcdiscount').value.replace(/,/g,'')*1;
      var ffdiscount=(fcdiscount/(fcsub_amount))*100;

//       ffdiscount=Math.round((ffdiscount)*100/100);
      document.getElementById('ffdiscount').value=ffdiscount;
//      PurchaseInvoiceLocalRecalQty0();
      PurchaseInvoiceRecalQty0();

}

//function PurchaseInvoiceLocalRecalDiscDetailPercent(index) {
function PurchaseInvoiceRecalDiscDetailPercent(index) {
    var fnqtyD=0;
//     if(document.getElementById('ftstock_category_codeD'+index).value=='inv') {
              fnqtyD=document.getElementById('fnqtyD0'+index).value.replace(/,/g,'')*1;
//      }
//      else {
//          fnqtyD=1;
//      }
       var fcpriceD=document.getElementById('fcpriceD0'+index).value.replace(/,/g,'')*1;
       var ffdiscountD=document.getElementById('ffdiscountD0'+index).value.replace(/,/g,'')*1;
       var fcdiscountD=(fnqtyD*fcpriceD)*(ffdiscountD/100);
//       fcdiscountD=Math.round((fcdiscountD)*100/100);

       document.getElementById('fcdiscountD0'+index).value=fcdiscountD;
//      PurchaseInvoiceLocalRecalQty0();
       PurchaseInvoiceRecalQty0();

}

//function PurchaseInvoiceLocalRecalDiscDetailRp(index) {
function PurchaseInvoiceRecalDiscDetailRp(index) {
     var fnqtyD=0;
//     if(document.getElementById('ftstock_category_codeD'+index).value=='inv') {
              fnqtyD=document.getElementById('fnqtyD0'+index).value.replace(/,/g,'')*1;
//      }
//      else {
//          fnqtyD=1;
//      }
       var fcpriceD=document.getElementById('fcpriceD0'+index).value.replace(/,/g,'')*1;
       var fcdiscountD= document.getElementById('fcdiscountD0'+index).value.replace(/,/g,'')*1;
       var ffdiscountD=(fcdiscountD/(fnqtyD*fcpriceD))*100;
//        ffdiscountD=Math.round((ffdiscountD)*100/100);
       document.getElementById('ffdiscountD0'+index).value=ffdiscountD;
//       PurchaseInvoiceLocalRecalQty0();
       PurchaseInvoiceRecalQty0();

}

//function PurchaseInvoiceLocalRecalQty0() {
function PurchaseInvoiceRecalQty0() {

    var i=document.getElementsByName('fnindexD0[]').length;
    var fnqtyD=0;
    var fcpriceD=0;
    var ffdiscountD=0;
    var fcdiscountD=0;
    var fcamountD=0;

    var fcpayment_amount=0;
    var fcoutstanding_amount=0;
    var fcsub_amount=0;
    var ffdiscount=0;
    var fcdiscount=0;
    var fcother_cost=0;
    var ffvat=0;
    var fcvat=0;
    var fcamount=0;

    var fcprice_cogs = 0;
    var fcamount_cogs = 0;

    for(var j=1;j<i;j++) {

//        if(document.getElementsByName('ftstock_category_codeD[]')[j].value=='inv') {
              fnqtyD=document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1;
//        }
//        else {
//            fnqtyD=1;
//        }
        fcpriceD=document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1;
        fcdiscountD=document.getElementsByName('fcdiscountD0[]')[j].value.replace(/,/g,'')*1;

//        fcamountD=Math.round(((fnqtyD*fcpriceD )-fcdiscountD)*100/100);
        fcamountD=(fnqtyD*fcpriceD )-fcdiscountD;
        document.getElementsByName('fcamountD0[]')[j].value=fcamountD;
        fcsub_amount+= document.getElementsByName('fcamountD0[]')[j].value.replace(/,/g,'')*1;

    }
    document.getElementById('fcsub_amount').value=fcsub_amount;

    ffdiscount=document.getElementById('ffdiscount').value.replace(/,/g,'')*1;
    fcdiscount=(fcsub_amount*ffdiscount)/100;

    fcother_cost=document.getElementById('fcother_cost').value.replace(/,/g,'')*1;

    ffvat= document.getElementById('ffvat').value.replace(/,/g,'')*1;
    fcvat=(fcsub_amount-fcdiscount+fcother_cost)*ffvat/100;
    
    fcamount=(fcsub_amount-fcdiscount)+fcvat+fcother_cost;

    fcoutstanding_amount=fcamount;
    fcpayment_amount=0;

    document.getElementById('fcvat').value=fcvat;
    document.getElementById('fcdiscount').value=fcdiscount;
    document.getElementById('fcamount').value=fcamount;
    document.getElementById('fcoutstanding_amount').value=fcoutstanding_amount;
//    document.getElementById('fcpayment_amount').value=fcpayment_amount;

    // Calculate price cogs
    for(j=1;j<i;j++) {
        fcamount_cogs = ((document.getElementsByName('fcamountD0[]')[j].value.replace(/,/g,'')*1) / (document.getElementById('fcsub_amount').value.replace(/,/g,'')*1));
        
        if ((fcamount - (document.getElementById('fcsub_amount').value.replace(/,/g,'')*1)) != 0) {
            fcamount_cogs = fcamount_cogs * (fcamount - (document.getElementById('fcsub_amount').value.replace(/,/g,'')*1));
            fcamount_cogs = (document.getElementsByName('fcamountD0[]')[j].value.replace(/,/g,'')*1) + fcamount_cogs;
        } else {
            fcamount_cogs = (document.getElementsByName('fcamountD0[]')[j].value.replace(/,/g,'')*1);
        }

        fcamount_cogs = fcamount_cogs / (document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1);
        document.getElementsByName('fcprice_cogsD0[]')[j].value = fcamount_cogs;

        if((document.getElementById('fcexpedition_cost').value.replace(/,/g,'')*1) > 0) {
            fcprice_cogs = (document.getElementsByName('fcamountD0[]')[j].value.replace(/,/g,'')*1) / (document.getElementById('fcsub_amount').value.replace(/,/g,'')*1);
            fcprice_cogs = (fcprice_cogs * (document.getElementById('fcexpedition_cost').value.replace(/,/g,'')*1)) / (document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1);

            document.getElementsByName('fcprice_cogsD0[]')[j].value = (document.getElementsByName('fcprice_cogsD0[]')[j].value.replace(/,/g,'')*1) + fcprice_cogs;
            //alert(fcprice_cogs);
        }
    }

    ElementCurrencyALL();

    return true;
}

//function PurchaseInvoiceLocalInputQty() {
function PurchaseInvoiceInputQty() {
    var m="";


    var i=document.getElementsByName('fnindexD0[]').length;
    for(var j=1;j<i;j++) {
//        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 (document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1<=0) {
//              alert('PO yang anda pilih belum ada harga, Silahkan masukan harga terlebih dahulu');
//              document.getElementsByName('fcpriceD0[]')[j].focus();
//              return false;

//        } else
        if (document.getElementsByName('ffdiscountD0[]')[j].value.replace(/,/g,'')*1>100) {
              alert('Discount tidak boleh lebih dari 100 ...');
              document.getElementsByName('ffdiscountD0[]')[j].focus();
              return false;
        }
//        else if (document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1<document.getElementsByName('fcpriceListD0[]')[j].value.replace(/,/g,'')*1) {
//            m=m+ document.getElementsByName('ftitem_codeD0[]')[j].value +'\n';
//        }
    }
//    if(m!="") {
//           if(confirm('Harga barang berikut lebih kecil dari harga jual :\n------------------------------------ \n '+m+'-------------------------------\n Apakah transaksi akan diteruskan??')) {
//                    return true;
//            }
//            else {
//                  return false;
//            }
//    }
    return true;
}
//function PurchaseInvoiceLocalInputQtyX() {
function PurchaseInvoiceInputQtyX() {
    var m="";


    var i=document.getElementsByName('fnindexD0[]').length;
    for(var j=1;j<i;j++) {
//        if (document.getElementsByName('fnqtyD[]')[j].value.replace(/,/g,'')*1<0)  {
//             alert('Qty harus di isi ...');
//            document.getElementsByName('fnqtyD[]')[j].focus();
//             return false;
//        }
//       else
       //alert('x');
        if (document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1<=0) {
              alert('Harga harus di isi ...');
              document.getElementsByName('fcpriceD0[]')[j].focus();
              return false;

        }
//        else if (document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1<document.getElementsByName('fcpriceListD[]')[j].value.replace(/,/g,'')*1) {
//            m=m+ document.getElementsByName('ftitem_codeD0[]')[j].value +'\n';
//        }
    }
//    if(m!="") {
//           if(confirm('Harga barang berikut lebih kecil dari harga jual :\n------------------------------------ \n '+m+'-------------------------------\n Apakah transaksi akan diteruskan??')) {
//                    return true;
//            }
//            else {
//                  return false;
//            }
//    }
    return true;
}

//function FinalPurchaseInvoiceLocal() {
function FinalPurchaseInvoice() {
  return true;

}


function ValPurchaseInvoiceImport() {

//    PurchaseInvoiceImportRecalQty();
    if(document.getElementById("ftpurchase_invoice_no").value=='') {
        alert('No. transaksi harus disi...');
        document.getElementById("ftpurchase_invoice_no").focus();
        return false;
    }
    /* else if(document.getElementById("hidden_ftstock_in_no").value=='') {
        alert('No. Terima belum valid...');
        document.getElementById("ftstock_in_no").focus();
        return false;
    } 
    else if(document.getElementById("hidden_ftpo_no").value=='') {
        alert('No. PO belum valid...');
        document.getElementById("ftpo_no").focus();
        return false;
    } */
    else if(document.getElementById("hidden_ftsupplier_code").value=='') {
        alert('Supplier belum valid ...');
        document.getElementById("ftsupplier_code").focus();
        return false;
    }
    else if((document.getElementById("fcexpedition_cost").value.replace(/,/g,'')*1 > 0) && (document.getElementById("ftexpedition_code").value == '')) {
        alert('Kode Ekspedisi harap diisi ...');
        document.getElementById("ftexpedition_code").focus();
        return false;
    }
//     else if(document.getElementById("ftterm_payment").value=='') {
//        alert('Syarat pembayaran belum diisi...');
//        document.getElementById("ftterm_payment").focus();
//        return false;
//    }
//    else if(document.getElementById("ftcurrency_code").value=='') {
//        alert('Mata uang belum di isi...');
//        document.getElementById("ftcurrency_code").focus();
//        return false;
//    }
//    else if(document.getElementById('fcrate').value.replace(/,/g,'')*1<=0) {
//        alert('Kurs Belum valid...');
//        document.getElementById("fcrate").focus();
//        return false;
//    }
//
//    else if(document.getElementById("fntax_code").value=='') {
//        alert('Kode pajak belum diisi...');
//        document.getElementById("fntax_code").focus();
//        return false;
//    }

//    else if(document.getElementById("ftvat_no").value=='') {
//        alert('No. faktur pajak harus disi...');
//        document.getElementById("ftvat_no").focus();
//        return false;
//    }
    else if(document.getElementsByName('fnindexD0[]').length<1) {
        alert('Detail transaksi harus disi...');
        return false;
    }
    else if (PurchaseInvoiceImportInputQty()==false) {
         return false;
    }

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

  return false;

}

function RevisiPurchaseInvoiceImport() {

    if(document.getElementById("ftpurchase_invoice_no").value=='') {
        alert('No. transaksi harus disi...');
        document.getElementById("ftpurchase_invoice_no").focus();
        return false;
    }
    else if(document.getElementById("hidden_ftsupplier_code").value=='') {
        alert('Supplier belum valid ...');
        document.getElementById("ftsupplier_code").focus();
        return false;
    }
    else if((document.getElementById("fcexpedition_cost").value.replace(/,/g,'')*1 > 0) && (document.getElementById("ftexpedition_code").value == '')) {
        alert('Kode Ekspedisi harap diisi ...');
        document.getElementById("ftexpedition_code").focus();
        return false;
    }
    else if(document.getElementsByName('fnindexD0[]').length<1) {
        alert('Detail transaksi harus disi...');
        return false;
    }
    else if (PurchaseInvoiceImportInputQty()==false) {
         return false;
    }
     return true;

}

function PurchaseInvoiceImportRecalQty() {

    var i=document.getElementsByName('fnindexD0[]').length;
    var fnqtyD=0;
    var fcpriceD=0;
    var ffdiscountD=0;
    var fcdiscountD=0;
    var fcamountD=0;

    var fcpayment_amount=0;
    var fcoutstanding_amount=0;
    var fcsub_amount=0;
    var ffdiscount=0;
    var fcdiscount=0;
    var fcother_cost=0;
    var ffvat=0;
    var fcvat=0;
    var fcamount=0;


    for(var j=1;j<i;j++) {

//        if(document.getElementsByName('ftstock_category_codeD[]')[j].value=='inv') {
              fnqtyD=document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1;
//        }
//        else {
//            fnqtyD=1;
//        }
        fcpriceD=document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1;
        ffdiscountD=document.getElementsByName('ffdiscountD0[]')[j].value.replace(/,/g,'')*1;
        fcdiscountD=(fnqtyD*fcpriceD)*(ffdiscountD/100);
//        fcdiscountD=Math.round(fcdiscountD*100)/100;
//        fcamountD=Math.round((fnqtyD*fcpriceD)*100/100);
        fcamountD=fnqtyD*fcpriceD;
        fcamountD=fcamountD-fcdiscountD;
//        fcamountD=Math.round((fcamountD)*100/100);
        fcsub_amount+=fcamountD;
        document.getElementsByName('fcdiscountD0[]')[j].value=fcdiscountD;
        document.getElementsByName('fcamountD0[]')[j].value=fcamountD;
    }
    document.getElementById('fcsub_amount').value=fcsub_amount;
    ffdiscount=document.getElementById('ffdiscount').value.replace(/,/g,'')*1;
    fcdiscount=fcsub_amount*ffdiscount/100;
//    fcdiscount=Math.round((fcdiscount)*100/100);

    fcother_cost=document.getElementById('fcother_cost').value.replace(/,/g,'')*1;
//    fcother_cost=Math.round((fcother_cost)*100/100);

    ffvat= document.getElementById('ffvat').value.replace(/,/g,'')*1;
    fcvat=(fcsub_amount-fcdiscount+fcother_cost)*ffvat/100;
//    fcvat=Math.round((fcvat)*100/100);

    fcamount=(fcsub_amount-fcdiscount)+fcvat+fcother_cost;
//    fcamount=Math.round((fcamount)*100/100);
    fcoutstanding_amount=fcamount;
    fcpayment_amount=0;

    document.getElementById('fcdiscount').value=fcdiscount;
    document.getElementById('fcvat').value=fcvat;
    document.getElementById('fcamount').value=fcamount;
//    document.getElementById('fcoutstanding_amount').value=fcoutstanding_amount;
//    document.getElementById('fcpayment_amount').value=fcpayment_amount;

    return true;
}

function PurchaseInvoiceImportRecalPrice() {
    PurchaseInvoiceImportRecalQty0();

}

function PurchaseInvoiceImportRecalDiscPercent() {
      var fcsub_amount=document.getElementById('fcsub_amount').value.replace(/,/g,'')*1;
      var ffdiscount=document.getElementById('ffdiscount').value*1;
      var  fcdiscount=fcsub_amount*ffdiscount/100;
//       fcdiscount=Math.round((fcdiscount)*100/100);
      document.getElementById('fcdiscount').value=fcdiscount;
      PurchaseInvoiceImportRecalQty0();

}

function PurchaseInvoiceImportRecalDiscRp() {
      var fcsub_amount=document.getElementById('fcsub_amount').value.replace(/,/g,'')*1;
      var fcdiscount=document.getElementById('fcdiscount').value.replace(/,/g,'')*1;
      var ffdiscount=(fcdiscount/(fcsub_amount))*100;

//       ffdiscount=Math.round((ffdiscount)*100/100);
      document.getElementById('ffdiscount').value=ffdiscount;
      PurchaseInvoiceImportRecalQty0();

}

function PurchaseInvoiceImportRecalDiscDetailPercent(index) {
    var fnqtyD=document.getElementById('fnqtyD0'+index).value.replace(/,/g,'')*1;
    var fcpriceD=document.getElementById('fcpriceD0'+index).value.replace(/,/g,'')*1;
    var ffdiscountD=document.getElementById('ffdiscountD0'+index).value.replace(/,/g,'')*1;
    var fcdiscountD=(fnqtyD*fcpriceD)*(ffdiscountD/100);
    // fcdiscountD=Math.round((fcdiscountD)*100/100);

    document.getElementById('fcdiscountD0'+index).value=fcdiscountD;
    PurchaseInvoiceImportRecalQty0();
}

function PurchaseInvoiceImportRecalDiscDetailRp(index) {
    var fnqtyD=document.getElementById('fnqtyD0'+index).value.replace(/,/g,'')*1;

    var fcpriceD=document.getElementById('fcpriceD0'+index).value.replace(/,/g,'')*1;
    var fcdiscountD= document.getElementById('fcdiscountD0'+index).value.replace(/,/g,'')*1;
    var ffdiscountD=(fcdiscountD/(fnqtyD*fcpriceD))*100;
    // ffdiscountD=Math.round((ffdiscountD)*100/100);
    document.getElementById('ffdiscountD0'+index).value=ffdiscountD;
    PurchaseInvoiceImportRecalQty0();
}

function PurchaseInvoiceImportRecalQty0() {

    var i=document.getElementsByName('fnindexD0[]').length;
    var fnqtyD=0;
    var fcpriceD=0;
    var ffdiscountD=0;
    var fcdiscountD=0;
    var fcamountD=0;

    var fcpayment_amount=0;
    var fcoutstanding_amount=0;
    var fcsub_amount=0;
    var ffdiscount=0;
    var fcdiscount=0;
    var fcother_cost=0;
    var ffvat=0;
    var fcvat=0;
    var fcamount=0;

    var fcprice_cogs = 0;
    var fcamount_cogs = 0;

    for(var j=1;j<i;j++) {

        fnqtyD=document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1;
        fcpriceD=document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1;
        fcdiscountD=document.getElementsByName('fcdiscountD0[]')[j].value.replace(/,/g,'')*1;

//        fcamountD=Math.round(((fnqtyD*fcpriceD )-fcdiscountD)*100/100);
        fcamountD=(fnqtyD*fcpriceD )-fcdiscountD;
        document.getElementsByName('fcamountD0[]')[j].value=fcamountD;
        fcsub_amount+= document.getElementsByName('fcamountD0[]')[j].value.replace(/,/g,'')*1;
    }
    document.getElementById('fcsub_amount').value=fcsub_amount;

    ffdiscount=document.getElementById('ffdiscount').value.replace(/,/g,'')*1;
    fcdiscount=(fcsub_amount*ffdiscount)/100;
  
    fcother_cost=document.getElementById('fcother_cost').value.replace(/,/g,'')*1;

    ffvat= document.getElementById('ffvat').value.replace(/,/g,'')*1;
    fcvat=(fcsub_amount-fcdiscount+fcother_cost)*ffvat/100;

    fcamount=(fcsub_amount-fcdiscount)+fcvat+fcother_cost;

    fcoutstanding_amount=fcamount;
    fcpayment_amount=0;

    document.getElementById('fcdiscount').value=fcdiscount;
    document.getElementById('fcvat').value=fcvat;
    document.getElementById('fcamount').value=fcamount;
    document.getElementById('fcoutstanding_amount').value=fcoutstanding_amount;
    document.getElementById('fcpayment_amount').value=fcpayment_amount;

    // Calculate price cogs
    for(j=1;j<i;j++) {
        fcamount_cogs = ((document.getElementsByName('fcamountD0[]')[j].value.replace(/,/g,'')*1) / (document.getElementById('fcsub_amount').value.replace(/,/g,'')*1));
        
        if ((fcamount - (document.getElementById('fcsub_amount').value.replace(/,/g,'')*1)) != 0) {
            fcamount_cogs = fcamount_cogs * (fcamount - (document.getElementById('fcsub_amount').value.replace(/,/g,'')*1));
            fcamount_cogs = (document.getElementsByName('fcamountD0[]')[j].value.replace(/,/g,'')*1) + fcamount_cogs;
        } else {
            fcamount_cogs = (document.getElementsByName('fcamountD0[]')[j].value.replace(/,/g,'')*1);
        }

        fcamount_cogs = fcamount_cogs / (document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1);
        document.getElementsByName('fcprice_cogsD0[]')[j].value = fcamount_cogs;

        if((document.getElementById('fcexpedition_cost').value.replace(/,/g,'')*1) > 0) {
            fcprice_cogs = (document.getElementsByName('fcamountD0[]')[j].value.replace(/,/g,'')*1) / (document.getElementById('fcsub_amount').value.replace(/,/g,'')*1);
            fcprice_cogs = (fcprice_cogs * (document.getElementById('fcexpedition_cost').value.replace(/,/g,'')*1)) / (document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1);

            document.getElementsByName('fcprice_cogsD0[]')[j].value = (document.getElementsByName('fcprice_cogsD0[]')[j].value.replace(/,/g,'')*1) + fcprice_cogs;
            //alert(fcprice_cogs);
        }
    }
    
    ElementCurrencyALL();
    return true;
}

function PurchaseInvoiceImportInputQty() {
    var m="";


    var i=document.getElementsByName('fnindexD0[]').length;
    for(var j=1;j<i;j++) {
//        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 (document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1<=0) {
              alert('Harga harus di isi ...');
              document.getElementsByName('fcpriceD0[]')[j].focus();
              return false;

        }
        else if (document.getElementsByName('ffdiscountD0[]')[j].value.replace(/,/g,'')*1>100) {
              alert('Discount tidak boleh lebih dari 100 ...');
              document.getElementsByName('ffdiscountD0[]')[j].focus();
              return false;
        }
//        else if (document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1<document.getElementsByName('fcpriceListD0[]')[j].value.replace(/,/g,'')*1) {
//            m=m+ document.getElementsByName('ftitem_codeD0[]')[j].value +'\n';
//        }
    }
//    if(m!="") {
//           if(confirm('Harga barang berikut lebih kecil dari harga jual :\n------------------------------------ \n '+m+'-------------------------------\n Apakah transaksi akan diteruskan??')) {
//                    return true;
//            }
//            else {
//                  return false;
//            }
//    }
    return true;
}
function PurchaseInvoiceImportInputQtyX() {
    var m="";


    var i=document.getElementsByName('fnindexD0[]').length;
    for(var j=1;j<i;j++) {
//        if (document.getElementsByName('fnqtyD[]')[j].value.replace(/,/g,'')*1<0)  {
//             alert('Qty harus di isi ...');
//            document.getElementsByName('fnqtyD[]')[j].focus();
//             return false;
//        }
//       else
       //alert('x');
        if (document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1<=0) {
              alert('Harga harus di isi ...');
              document.getElementsByName('fcpriceD0[]')[j].focus();
              return false;

        }
//        else if (document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1<document.getElementsByName('fcpriceListD[]')[j].value.replace(/,/g,'')*1) {
//            m=m+ document.getElementsByName('ftitem_codeD0[]')[j].value +'\n';
//        }
    }
//    if(m!="") {
//           if(confirm('Harga barang berikut lebih kecil dari harga jual :\n------------------------------------ \n '+m+'-------------------------------\n Apakah transaksi akan diteruskan??')) {
//                    return true;
//            }
//            else {
//                  return false;
//            }
//    }
    return true;
}

function FinalPurchaseInvoiceImport() {
  return true;

}



function ValPurchaseReturn() {

    if(document.getElementById("ftpurchase_return_no").value=='') {
        alert('No. transaksi harus disi...');
        document.getElementById("ftpurchase_return_no").focus();
        return false;
    }
    else if(document.getElementById("hidden_ftpurchase_invoice_no").value=='') {
        alert('No. PI belum valid...');
        document.getElementById("ftpurchase_invoice_no").focus();
        return false;
    }
  else  if(document.getElementById("hidden_ftsupplier_code").value=='') {
      alert('Supplier belum valid ...');
      document.getElementById("ftsupplier_code").focus();
      return false;
  }
//     else if(document.getElementById("ftterm_payment").value=='') {
//        alert('Syarat pembayaran belum diisi...');
//        document.getElementById("ftterm_payment").focus();
//        return false;
//    }
//    else if(document.getElementById("ftcurrency_code").value=='') {
//        alert('Mata uang belum di isi...');
//        document.getElementById("ftcurrency_code").focus();
//        return false;
//    }
//    else if(document.getElementById('fcrate').value.replace(/,/g,'')*1<=0) {
//        alert('Kurs Belum valid...');
//        document.getElementById("fcrate").focus();
//        return false;
//    }
//
//    else if(document.getElementById("fntax_code").value=='') {
//        alert('Kode pajak belum diisi...');
//        document.getElementById("fntax_code").focus();
//        return false;
//    }

//    else if(document.getElementById("ftvat_no").value=='') {
//        alert('No. faktur pajak harus disi...');
//        document.getElementById("ftvat_no").focus();
//        return false;
//    }
    else if(document.getElementsByName('fnindexD0[]').length<1) {
        alert('Detail transaksi harus disi...');
        return false;
    }
    else if (PurchaseReturnLocalInputQty()==false) {
         return false;
    }

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

  return false;

}

function PurchaseReturnLocalRecalQty() {

    var i=document.getElementsByName('fnindexD0[]').length;
    var fnqtyD=0;
    var fcpriceD=0;
    var ffdiscountD=0;
    var fcdiscountD=0;
    var fcamountD=0;

    var fcpayment_amount=0;
    var fcoutstanding_amount=0;
    var fcsub_amount=0;
    var ffdiscount=0;
    var fcdiscount=0;
    var fcother_cost=0;
    var ffvat=0;
    var fcvat=0;
    var fcamount=0;


    for(var j=1;j<i;j++) {

//        if(document.getElementsByName('ftstock_category_codeD[]')[j].value=='inv') {
              fnqtyD=document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1;
//        }
//        else {
//            fnqtyD=1;
//        }
        fcpriceD=document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1;
        ffdiscountD=document.getElementsByName('ffdiscountD0[]')[j].value.replace(/,/g,'')*1;
        fcdiscountD=(fnqtyD*fcpriceD)*(ffdiscountD/100);
        //fcdiscountD=Math.round(fcdiscountD*100)/100;
        //fcamountD=Math.round((fnqtyD*fcpriceD)*100/100);
        fcamountD=fcamountD-fcdiscountD;
        //fcamountD=Math.round((fcamountD)*100/100);
        fcsub_amount+=fcamountD;
        document.getElementsByName('fcdiscountD0[]')[j].value=fcdiscountD;
        document.getElementsByName('fcamountD0[]')[j].value=fcamountD;
    }
    document.getElementById('fcsub_amount').value=fcsub_amount;
    fcdiscount=document.getElementById('fcdiscount').value.replace(/,/g,'')*1;
    //fcdiscount=fcsub_amount*ffdiscount/100;
    //fcdiscount=Math.round((fcdiscount)*100/100);

   
    fcother_cost=document.getElementById('fcother_cost').value.replace(/,/g,'')*1;
    //fcother_cost=Math.round((fcother_cost)*100/100);

    ffvat= document.getElementById('ffvat').value.replace(/,/g,'')*1;
    fcvat=(fcsub_amount-fcdiscount+fcother_cost)*ffvat/100;
    //fcvat=Math.round((fcvat)*100/100);
    
    fcamount=(fcsub_amount-fcdiscount)+fcvat+fcother_cost;
    //fcamount=Math.round((fcamount)*100/100);
    fcoutstanding_amount=fcamount;
    fcpayment_amount=0;

    document.getElementById('fcdiscount').value=fcdiscount;
    document.getElementById('fcvat').value=fcvat;
    document.getElementById('fcamount').value=fcamount;
//    document.getElementById('fcoutstanding_amount').value=fcoutstanding_amount;
//    document.getElementById('fcpayment_amount').value=fcpayment_amount;

    return true;
}

function PurchaseReturnLocalRecalPrice() {
    PurchaseReturnLocalRecalQty0();

}

function PurchaseReturnLocalRecalDiscPercent() {
      var fcsub_amount=document.getElementById('fcsub_amount').value.replace(/,/g,'')*1;
      var ffdiscount=document.getElementById('ffdiscount').value*1;
      var  fcdiscount=fcsub_amount*ffdiscount/100;
      //fcdiscount=Math.round((fcdiscount)*100/100);
      document.getElementById('fcdiscount').value=fcdiscount;
      ElementCurrencyOnBlur(document.getElementById('fcdiscount'));
      PurchaseReturnLocalRecalQty0();

}

function PurchaseReturnLocalRecalDiscRp() {
      var fcsub_amount=document.getElementById('fcsub_amount').value.replace(/,/g,'')*1;
      var fcdiscount=document.getElementById('fcdiscount').value.replace(/,/g,'')*1;
      var ffdiscount=(fcdiscount/(fcsub_amount))*100;

      //ffdiscount=Math.round((ffdiscount)*100/100);
      document.getElementById('ffdiscount').value=ffdiscount;
      ElementCurrencyOnBlur(document.getElementById('ffdiscount'));
      PurchaseReturnLocalRecalQty0();
}

function PurchaseReturnLocalRecalDiscDetailPercent(index) {
    var fnqtyD=0;
//     if(document.getElementById('ftstock_category_codeD'+index).value=='inv') {
              fnqtyD=document.getElementById('fnqtyD0'+index).value.replace(/,/g,'')*1;
//      }
//      else {
//          fnqtyD=1;
//      }
       var fcpriceD=document.getElementById('fcpriceD0'+index).value.replace(/,/g,'')*1;
       var ffdiscountD=document.getElementById('ffdiscountD0'+index).value.replace(/,/g,'')*1;
       var fcdiscountD=(fnqtyD*fcpriceD)*(ffdiscountD/100);
       //fcdiscountD=Math.round((fcdiscountD)*100/100);

      document.getElementById('fcdiscountD0'+index).value=fcdiscountD;
      PurchaseReturnLocalRecalQty0();
}

function PurchaseReturnLocalRecalDiscDetailRp(index) {
     var fnqtyD=0;
//     if(document.getElementById('ftstock_category_codeD'+index).value=='inv') {
              fnqtyD=document.getElementById('fnqtyD0'+index).value.replace(/,/g,'')*1;
//      }
//      else {
//          fnqtyD=1;
//      }
       var fcpriceD=document.getElementById('fcpriceD0'+index).value.replace(/,/g,'')*1;
       var fcdiscountD= document.getElementById('fcdiscountD0'+index).value.replace(/,/g,'')*1;
       var ffdiscountD=(fcdiscountD/(fnqtyD*fcpriceD))*100;
       //ffdiscountD=Math.round((ffdiscountD)*100/100);
       document.getElementById('ffdiscountD0'+index).value=ffdiscountD;
       PurchaseReturnLocalRecalQty0();
}

function PurchaseReturnLocalRecalQty0() {

    var i=document.getElementsByName('fnindexD0[]').length;
    var fnqtyD=0;
    var fcpriceD=0;
    var ffdiscountD=0;
    var fcdiscountD=0;
    var fcamountD=0;

    var fcpayment_amount=0;
    var fcoutstanding_amount=0;
    var fcsub_amount=0;
    var ffdiscount=0;
    var fcdiscount=0;
    var fcother_cost=0;
    var ffvat=0;
    var fcvat=0;
    var fcamount=0;


    for(var j=1;j<i;j++) {

//        if(document.getElementsByName('ftstock_category_codeD[]')[j].value=='inv') {
              fnqtyD=document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1;
//        }
//        else {
//            fnqtyD=1;
//        }
        fcpriceD=document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1;
        fcdiscountD=document.getElementsByName('fcdiscountD0[]')[j].value.replace(/,/g,'')*1;

        fcamountD=(fnqtyD*fcpriceD)-fcdiscountD;
        document.getElementsByName('fcamountD0[]')[j].value=fcamountD;
        fcsub_amount+= document.getElementsByName('fcamountD0[]')[j].value.replace(/,/g,'')*1;
    }
    document.getElementById('fcsub_amount').value=fcsub_amount;
    fcdiscount=document.getElementById('fcdiscount').value.replace(/,/g,'')*1;
    //fcdiscount=Math.round((fcdiscount)*100/100);   

    fcother_cost=document.getElementById('fcother_cost').value.replace(/,/g,'')*1;
    //fcother_cost=Math.round((fcother_cost)*100/100);

    ffvat= document.getElementById('ffvat').value.replace(/,/g,'')*1;
    fcvat=(fcsub_amount-fcdiscount+fcother_cost)*ffvat/100;
    //fcvat=Math.round((fcvat)*100/100);

    fcamount=(fcsub_amount-fcdiscount)+fcvat+fcother_cost;
    //fcamount=Math.round((fcamount)*100/100);
    fcoutstanding_amount=fcamount;
    fcpayment_amount=0;


    document.getElementById('fcvat').value=fcvat;
    document.getElementById('fcamount').value=fcamount;
//    document.getElementById('fcoutstanding_amount').value=fcoutstanding_amount;
//    document.getElementById('fcpayment_amount').value=fcpayment_amount;
    ElementCurrencyALL();
    return true;
}

function PurchaseReturnLocalInputQty() {
    var m="";


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

       if (document.getElementsByName('fnqty_outstanding_piD0[]')[j].value.replace(/,/g,'')*1<document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1) {
              alert('Qty tidak boleh melebihi jumlah Sisa PI yang belum direturn ...');
              document.getElementsByName('fnqtyD0[]')[j].focus();
              return false;
       }
       else if (document.getElementsByName('fnqty_availableD0[]')[j].value.replace(/,/g,'')*1<document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1) {
              alert('Qty tidak boleh melebihi jumlah Avail yang belum direturn ...');
              document.getElementsByName('fnqtyD0[]')[j].focus();
              return false;
       }
       else if (document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1<=0) {
            alert('Harga harus di isi ...');
            document.getElementsByName('fcpriceD0[]')[j].focus();
            return false;
       }

        if (document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1>0) {
            m='1';

            if (document.getElementsByName('fnqty_baseD0[]')[j].value.replace(/,/g,'')*1<=0) {
               alert('Qty Base tidak boleh 0..');
               document.getElementsByName('fnqty_baseD0[]')[j].focus();
               return false;
            }

        }
    }
    if(m=='') {
          alert('Detail transaksi belum diinput...');
          return false;
    }
    return true;
}

function PurchaseReturnLocalInputQtyX() {
    var m="";


    var i=document.getElementsByName('fnindexD0[]').length;
    for(var j=1;j<i;j++) {
//        if (document.getElementsByName('fnqtyD[]')[j].value.replace(/,/g,'')*1<0)  {
//             alert('Qty harus di isi ...');
//            document.getElementsByName('fnqtyD[]')[j].focus();
//             return false;
//        }
//       else
       //alert('x');
        if (document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1<=0) {
              alert('Harga harus di isi ...');
              document.getElementsByName('fcpriceD0[]')[j].focus();
              return false;

        }
//        else if (document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1<document.getElementsByName('fcpriceListD[]')[j].value.replace(/,/g,'')*1) {
//            m=m+ document.getElementsByName('ftitem_codeD0[]')[j].value +'\n';
//        }
    }
//    if(m!="") {
//           if(confirm('Harga barang berikut lebih kecil dari harga jual :\n------------------------------------ \n '+m+'-------------------------------\n Apakah transaksi akan diteruskan??')) {
//                    return true;
//            }
//            else {
//                  return false;
//            }
//    }
    return true;
}

function FinalPurchaseReturn() {
  return true;

}

function ValPurchaseReturnImport() {

//    PurchaseReturnImportRecalQty();
    if(document.getElementById("ftpurchase_return_no").value=='') {
        alert('No. transaksi harus disi...');
        document.getElementById("ftpurchase_return_no").focus();
        return false;
    }
    else if(document.getElementById("hidden_ftpurchase_invoice_no").value=='') {
        alert('No. PI belum valid...');
        document.getElementById("ftpurchase_invoice_no").focus();
        return false;
    }
  else  if(document.getElementById("hidden_ftsupplier_code").value=='') {
      alert('Supplier belum valid ...');
      document.getElementById("ftsupplier_code").focus();
      return false;
  }
//     else if(document.getElementById("ftterm_payment").value=='') {
//        alert('Syarat pembayaran belum diisi...');
//        document.getElementById("ftterm_payment").focus();
//        return false;
//    }
//    else if(document.getElementById("ftcurrency_code").value=='') {
//        alert('Mata uang belum di isi...');
//        document.getElementById("ftcurrency_code").focus();
//        return false;
//    }
//    else if(document.getElementById('fcrate').value.replace(/,/g,'')*1<=0) {
//        alert('Kurs Belum valid...');
//        document.getElementById("fcrate").focus();
//        return false;
//    }
//
//    else if(document.getElementById("fntax_code").value=='') {
//        alert('Kode pajak belum diisi...');
//        document.getElementById("fntax_code").focus();
//        return false;
//    }

//    else if(document.getElementById("ftvat_no").value=='') {
//        alert('No. faktur pajak harus disi...');
//        document.getElementById("ftvat_no").focus();
//        return false;
//    }
    else if(document.getElementsByName('fnindexD0[]').length<1) {
        alert('Detail transaksi harus disi...');
        return false;
    }
    else if (PurchaseReturnImportInputQty()==false) {
         return false;
    }

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

  return false;

}

function PurchaseReturnImportRecalQty() {

    var i=document.getElementsByName('fnindexD0[]').length;
    var fnqtyD=0;
    var fcpriceD=0;
    var ffdiscountD=0;
    var fcdiscountD=0;
    var fcamountD=0;

    var fcpayment_amount=0;
    var fcoutstanding_amount=0;
    var fcsub_amount=0;
    var ffdiscount=0;
    var fcdiscount=0;
    var fcother_cost=0;
    var ffvat=0;
    var fcvat=0;
    var fcamount=0;


    for(var j=1;j<i;j++) {

//        if(document.getElementsByName('ftstock_category_codeD[]')[j].value=='inv') {
              fnqtyD=document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1;
//        }
//        else {
//            fnqtyD=1;
//        }
        fcpriceD=document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1;
        ffdiscountD=document.getElementsByName('ffdiscountD0[]')[j].value.replace(/,/g,'')*1;
        fcdiscountD=(fnqtyD*fcpriceD)*(ffdiscountD/100);
        //fcdiscountD=Math.round(fcdiscountD*100)/100;
        //fcamountD=Math.round((fnqtyD*fcpriceD)*100/100);
        fcamountD=fcamountD-fcdiscountD;

        //fcamountD=Math.round((fcamountD)*100/100);
        fcsub_amount+=fcamountD;
        document.getElementsByName('fcdiscountD0[]')[j].value=fcdiscountD;
        document.getElementsByName('fcamountD0[]')[j].value=fcamountD;
    }
    document.getElementById('fcsub_amount').value=fcsub_amount;
    ffdiscount=document.getElementById('ffdiscount').value.replace(/,/g,'')*1;
    fcdiscount=fcsub_amount*ffdiscount/100;
    //fcdiscount=Math.round((fcdiscount)*100/100);

   

    fcother_cost=document.getElementById('fcother_cost').value.replace(/,/g,'')*1;
    fcother_cost=Math.round((fcother_cost)*100/100);

     ffvat= document.getElementById('ffvat').value.replace(/,/g,'')*1;
    fcvat=(fcsub_amount-fcdiscount+fcother_cost)*ffvat/100;
    //fcvat=Math.round((fcvat)*100/100);
    
    fcamount=(fcsub_amount-fcdiscount)+fcvat+fcother_cost;
    //fcamount=Math.round((fcamount)*100/100);
    fcoutstanding_amount=fcamount;
    fcpayment_amount=0;

    document.getElementById('fcdiscount').value=fcdiscount;
    document.getElementById('fcvat').value=fcvat;
    document.getElementById('fcamount').value=fcamount;
//    document.getElementById('fcoutstanding_amount').value=fcoutstanding_amount;
//    document.getElementById('fcpayment_amount').value=fcpayment_amount;

    return true;
}

function PurchaseReturnImportRecalPrice() {
    PurchaseReturnImportRecalQty0();

}

function PurchaseReturnImportRecalDiscPercent() {
      var fcsub_amount=document.getElementById('fcsub_amount').value.replace(/,/g,'')*1;
      var ffdiscount=document.getElementById('ffdiscount').value*1;
      var  fcdiscount=fcsub_amount*ffdiscount/100;
      //fcdiscount=Math.round((fcdiscount)*100/100);
      document.getElementById('fcdiscount').value=fcdiscount;
      ElementCurrencyOnBlur(document.getElementById('fcdiscount'));
      PurchaseReturnImportRecalQty0();
}

function PurchaseReturnImportRecalDiscRp() {
      var fcsub_amount=document.getElementById('fcsub_amount').value.replace(/,/g,'')*1;
      var fcdiscount=document.getElementById('fcdiscount').value.replace(/,/g,'')*1;
      var ffdiscount=(fcdiscount/(fcsub_amount))*100;
      //ffdiscount=Math.round((ffdiscount)*100/100);
      document.getElementById('ffdiscount').value=ffdiscount;
      ElementCurrencyOnBlur(document.getElementById('ffdiscount'));
      PurchaseReturnImportRecalQty0();

}

function PurchaseReturnImportRecalDiscDetailPercent(index) {
    var fnqtyD=0;
//     if(document.getElementById('ftstock_category_codeD'+index).value=='inv') {
              fnqtyD=document.getElementById('fnqtyD0'+index).value.replace(/,/g,'')*1;
//      }
//      else {
//          fnqtyD=1;
//      }
       var fcpriceD=document.getElementById('fcpriceD0'+index).value.replace(/,/g,'')*1;
       var ffdiscountD=document.getElementById('ffdiscountD0'+index).value.replace(/,/g,'')*1;
       var fcdiscountD=(fnqtyD*fcpriceD)*(ffdiscountD/100);
       //fcdiscountD=Math.round((fcdiscountD)*100/100);

      document.getElementById('fcdiscountD0'+index).value=fcdiscountD;
      PurchaseReturnImportRecalQty0();
}

function PurchaseReturnImportRecalDiscDetailRp(index) {
     var fnqtyD=0;
//     if(document.getElementById('ftstock_category_codeD'+index).value=='inv') {
              fnqtyD=document.getElementById('fnqtyD0'+index).value.replace(/,/g,'')*1;
//      }
//      else {
//          fnqtyD=1;
//      }
       var fcpriceD=document.getElementById('fcpriceD0'+index).value.replace(/,/g,'')*1;
       var fcdiscountD= document.getElementById('fcdiscountD0'+index).value.replace(/,/g,'')*1;
       var ffdiscountD=(fcdiscountD/(fnqtyD*fcpriceD))*100;
       //ffdiscountD=Math.round((ffdiscountD)*100/100);
       document.getElementById('ffdiscountD0'+index).value=ffdiscountD;
       PurchaseReturnImportRecalQty0();
}

function PurchaseReturnImportRecalQty0() {

    var i=document.getElementsByName('fnindexD0[]').length;
    var fnqtyD=0;
    var fcpriceD=0;
    var ffdiscountD=0;
    var fcdiscountD=0;
    var fcamountD=0;

    var fcpayment_amount=0;
    var fcoutstanding_amount=0;
    var fcsub_amount=0;
    var ffdiscount=0;
    var fcdiscount=0;
    var fcother_cost=0;
    var ffvat=0;
    var fcvat=0;
    var fcamount=0;

    for(var j=1;j<i;j++) {

//        if(document.getElementsByName('ftstock_category_codeD[]')[j].value=='inv') {
              fnqtyD=document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1;
//        }
//        else {
//            fnqtyD=1;
//        }
        fcpriceD=document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1;

        fcdiscountD=document.getElementsByName('fcdiscountD0[]')[j].value.replace(/,/g,'')*1;

        fcamountD=(fnqtyD*fcpriceD )-fcdiscountD;
        document.getElementsByName('fcamountD0[]')[j].value=fcamountD;
        fcsub_amount+= document.getElementsByName('fcamountD0[]')[j].value.replace(/,/g,'')*1;
    }
    document.getElementById('fcsub_amount').value=fcsub_amount;
    fcdiscount=document.getElementById('fcdiscount').value.replace(/,/g,'')*1;
    //fcdiscount=Math.round((fcdiscount)*100/100);
  
    fcother_cost=document.getElementById('fcother_cost').value.replace(/,/g,'')*1;
    //fcother_cost=Math.round((fcother_cost)*100/100);

    ffvat= document.getElementById('ffvat').value.replace(/,/g,'')*1;
    fcvat=(fcsub_amount-fcdiscount+fcother_cost)*ffvat/100;
    //fcvat=Math.round((fcvat)*100/100);
    
    fcamount=(fcsub_amount-fcdiscount)+fcvat+fcother_cost;
    //fcamount=Math.round((fcamount)*100/100);
    fcoutstanding_amount=fcamount;
    fcpayment_amount=0;


    document.getElementById('fcvat').value=fcvat;
    document.getElementById('fcamount').value=fcamount;
//    document.getElementById('fcoutstanding_amount').value=fcoutstanding_amount;
//    document.getElementById('fcpayment_amount').value=fcpayment_amount;
      ElementCurrencyALL();
    return true;
}

function PurchaseReturnImportInputQty() {
    var m="";
    var i=document.getElementsByName('fnindexD0[]').length;
    for(var j=1;j<i;j++) {

           if (document.getElementsByName('fnqty_outstanding_piD0[]')[j].value.replace(/,/g,'')*1<document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1) {
              alert('Qty tidak boleh melebihi jumlah Sisa PI yang belum direturn ...');
              document.getElementsByName('fnqtyD0[]')[j].focus();
              return false;
       }
       else if (document.getElementsByName('fnqty_availableD0[]')[j].value.replace(/,/g,'')*1<document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1) {
              alert('Qty tidak boleh melebihi jumlah Avail yang belum direturn ...');
              document.getElementsByName('fnqtyD0[]')[j].focus();
              return false;
       }
       else if (document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1<=0) {
              alert('Harga harus di isi ...');
              document.getElementsByName('fcpriceD0[]')[j].focus();
              return false;

       }

        if (document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1>0) {
            m='1';

            if (document.getElementsByName('fnqty_baseD0[]')[j].value.replace(/,/g,'')*1<=0) {
                alert('Qty Base tidak boleh 0..');
                document.getElementsByName('fnqty_baseD0[]')[j].focus();
                return false;
            }
        }
    }
    if(m=='') {
          alert('Detail transaksi belum diinput...');
          return false;
    }
    return true;
}

function PurchaseReturnImportInputQtyX() {
    var m="";


    var i=document.getElementsByName('fnindexD0[]').length;
    for(var j=1;j<i;j++) {
//        if (document.getElementsByName('fnqtyD[]')[j].value.replace(/,/g,'')*1<0)  {
//             alert('Qty harus di isi ...');
//            document.getElementsByName('fnqtyD[]')[j].focus();
//             return false;
//        }
//       else
       //alert('x');
        if (document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1<=0) {
              alert('Harga harus di isi ...');
              document.getElementsByName('fcpriceD0[]')[j].focus();
              return false;

        }
//        else if (document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1<document.getElementsByName('fcpriceListD[]')[j].value.replace(/,/g,'')*1) {
//            m=m+ document.getElementsByName('ftitem_codeD0[]')[j].value +'\n';
//        }
    }
//    if(m!="") {
//           if(confirm('Harga barang berikut lebih kecil dari harga jual :\n------------------------------------ \n '+m+'-------------------------------\n Apakah transaksi akan diteruskan??')) {
//                    return true;
//            }
//            else {
//                  return false;
//            }
//    }
    return true;
}

function FinalPurchaseReturnImport() {
  return true;

}



function ValTrackingPO() {
    //alert('suhut');
   if(document.getElementById("fttrackingpo_no").value=='') {
        alert('No. transaksi harus disi...');
        document.getElementById("fttrackingpo_no").focus();
        return false;
    }

     else if(document.getElementById("ftmarking_no").value=='') {
        alert('No Marking belum diisi...');
        document.getElementById("ftmarking_no").focus();
        return false;
    }
    else if(document.getElementsByName('fnindexD0[]').length<1) {
        alert('Detail transaksi harus disi...');
        return false;
    }
    else if(ValTrackingPO1==false)  {
        return false;
    }

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

  return false;

}

function ValTrackingPO1() {
      var i=document.getElementsByName('fnindexD0[]').length;
    for(var j=1;j<i;j++) {
        if(document.getElementById("hidden_ftsupplier_codeD0[]")[j].value=='') {
            alert('Supplier harus disi...');
            document.getElementsByName('ftsupplier_codeD0[]')[j].focus();
            return false;
        }
        else if(document.getElementById("hidden_ftpo_noD0[]")[j].value=='') {
            alert('No. PO harus disi...');
            document.getElementsByName('ftpo_noD0[]')[j].focus();
            return false;
        }
         else if(document.getElementById("hidden_ftitem_codeD0[]")[j].value=='') {
            alert('Kode Barang harus disi...');
            document.getElementsByName('ftitem_codeD0[]')[j].focus();
            return false;
        }
         else if(document.getElementById("fnqtyD0[]")[j].replace(/,/g,'')*1<=0) {
            alert('Qty harus disi...');
            document.getElementsByName('fnqtyD0[]')[j].focus();
            return false;
        }
    }
    return true;
}



function ValTandaTerima() {
    if(document.getElementById("fttanda_terima_no").value=='') {
        alert('No. transaksi harus disi...');
        document.getElementById("fttanda_terima_no").focus();
        return false;
    }
    else if(document.getElementById("hidden_ftsupplier_code").value=='') {
        alert('Kode Supplier belum valid...');
        document.getElementById("ftsupplier_code").focus();
        return false;
    }
     /*else if(document.getElementById("ftacc_no").value=='') {
        alert('Bank belum diisi...');
        document.getElementById("ftacc_no").focus();
        return false;
    }*/
    else if(document.getElementsByName('fnindexD0[]').length<1) {
        alert('Detail transaksi harus disi...');
        return false;
    }
   
    else if ((document.getElementById('fcamount').value.replace(/,/g,'')*1<=0)&&(document.getElementById('fcamountUSD').value.replace(/,/g,'')*1<=0)) {
           alert('Detail transaksi harus disi...');
         return false;
    }

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

  return false;

}

function RevisiTandaTerima() {
    if(document.getElementById("fttanda_terima_no").value=='') {
        alert('No. transaksi harus disi...');
        document.getElementById("fttanda_terima_no").focus();
        return false;
    }
    else if(document.getElementById("hidden_ftsupplier_code").value=='') {
        alert('Kode Supplier belum valid...');
        document.getElementById("ftsupplier_code").focus();
        return false;
    }
     /*else if(document.getElementById("ftacc_no").value=='') {
        alert('Bank belum diisi...');
        document.getElementById("ftacc_no").focus();
        return false;
    }*/
    else if(document.getElementsByName('fnindexD0[]').length<1) {
        alert('Detail transaksi harus disi...');
        return false;
    }

    else if ((document.getElementById('fcamount').value.replace(/,/g,'')*1<=0)&&(document.getElementById('fcamountUSD').value.replace(/,/g,'')*1<=0)) {
           alert('Detail transaksi harus disi...');
         return false;
    }

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

  return true;

}



function ValTandaTerima1(index) {
        var fcamountD0=document.getElementById('fcamountD0'+index).value.replace(/,/g,'')*1;
        var fcamountUSDD0=document.getElementById('fcamountUSDD0'+index).value.replace(/,/g,'')*1;
        var fcamount=document.getElementById('fcamount').value.replace(/,/g,'')*1;
        var fcamountUSD=document.getElementById('fcamountUSD').value.replace(/,/g,'')*1;
	if(document.getElementById('chk_includeD0'+index).checked == true) {
		document.getElementById('fcamount').value=fcamount+fcamountD0;
                document.getElementById('fcamountUSD').value=fcamountUSD+fcamountUSDD0;
		document.getElementById('hd_includeD0'+index).value='1';
	}
	else {
		document.getElementById('fcamount').value=fcamount-fcamountD0;
                document.getElementById('fcamountUSD').value=fcamountUSD-fcamountUSDD0;
		document.getElementById('hd_includeD0'+index).value='0';
	}
	ValTandaTerima2();
}

function ValTandaTerima2() {
   document.getElementById('fcpayment_amount').value=0;
   document.getElementById('fcoutstanding_amount').value=document.getElementById('fcamount').value;
   document.getElementById('fcpayment_amountUSD').value=0;
   document.getElementById('fcoutstanding_amountUSD').value=document.getElementById('fcamountUSD').value;
}
function ValTandaTerima3() {

    var i=document.getElementsByName('fnindexD0[]').length;
    var fcamountUSD=0;
    var fcamount=0;
    var fcrate = document.getElementById('fcrate').value;
    
    for(var j=1;j<i;j++) {
         document.getElementsByName('fcamountD0[]')[j].value = document.getElementsByName('fcamountUSDD0[]')[j].value * fcrate;
         fcamountUSD=fcamountUSD+ document.getElementsByName('fcamountUSDD0[]')[j].value.replace(/,/g,'')*1;
         fcamount=fcamount+ document.getElementsByName('fcamountD0[]')[j].value.replace(/,/g,'')*1;

      }

    document.getElementById('fcamountUSD').value=fcamountUSD;
    document.getElementById('fcamount').value=fcamount;

	ValTandaTerima2();
    return true;
}



function ValPendidikan() {
  if(document.getElementById("fteducation_code").value=='') {
       alert('Kode Pendidikan harus disi...');
       document.getElementById("fteducation_code").focus();
       return false;
  }
  else if(document.getElementById("fteducation_name").value=='') {
       alert('Nama Pendidikan harus disi...');
       document.getElementById("fteducation_name").focus();
       return false;
  }
  
   ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('fteducation_code').value);
   document.getElementById("fteducation_code").focus();
    return false;
}

function ValJabatan() {
  if(document.getElementById("ftposition_code").value=='') {
       alert('Kode Jabatan harus disi...');
       document.getElementById("ftposition_code").focus();
       return false;
  }
  else if(document.getElementById("ftposition_name").value=='') {
       alert(' Nama Jabatan harus disi...');
       document.getElementById("ftposition_name").focus();
       return false;
  }

   ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftposition_code').value);
   document.getElementById("ftposition_code").focus();
    return false;
}

function ValDivisi() {
  if(document.getElementById("ftdivision_code").value=='') {
       alert('Kode Divisi harus disi...');
       document.getElementById("ftdivision_code").focus();
       return false;
  }
  else if(document.getElementById("ftdivision_name").value=='') {
       alert('Nama Divisi harus disi...');
       document.getElementById("ftdivision_name").focus();
       return false;
  }

   ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftdivision_code').value);
   document.getElementById("ftdivision_code").focus();
    return false;
}

function ValDepartemen() {
  if(document.getElementById("ftdepartment_code").value=='') {
       alert('Kode Departemen harus disi...');
       document.getElementById("ftdepartment_code").focus();
       return false;
  }
  else if(document.getElementById("ftdepartment_name").value=='') {
       alert('Nama Departemen harus disi...');
       document.getElementById("ftdepartment_name").focus();
       return false;
  }

   ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftdepartment_code').value);
   document.getElementById("ftdepartment_code").focus();
    return false;
}

function ValPPH21() {
  if(document.getElementById("ftpph21_code").value=='') {
       alert(' Kode PPH21 harus disi...');
       document.getElementById("ftpph21_code").focus();
       return false;
  }
  else if(document.getElementById("ftpph21_name").value=='') {
       alert(' Nama PPH21 harus disi...');
       document.getElementById("ftpph21_name").focus();
       return false;
  }

   ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftpph21_code').value);
   document.getElementById("ftpph21_code").focus();
    return false;
}


function ValTipeShift() {
    
  if(document.getElementById("ftshift_code").value=='') {
       alert('Kode Tipe Shift harus disi...');
       document.getElementById("ftshift_code").focus();
       return false;
  }
  else if(document.getElementById("ftshift_name").value=='') {
       alert('Nama Tipe Shift harus disi...');
       document.getElementById("ftshift_name").focus();
       return false;
  }
  else if(TipeShift_Grid()==false) {
      return false;
  }
   ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftshift_code').value);
   document.getElementById("ftshift_code").focus();
    return false;
}

function UpdateTipeShift() {
  
  if(document.getElementById("ftshift_code").value=='') {
       alert('Kode Tipe Shift harus disi...');
       document.getElementById("ftshift_code").focus();
       return false;
  }
  else if(document.getElementById("ftshift_name").value=='') {
       alert('Nama Tipe Shift harus disi...');
       document.getElementById("ftshift_name").focus();
       return false;
  }
  else if(TipeShift_Grid()==false) {
      return false;
  }
 
    return true;
}

function TipeShift_Grid() {
    var i=document.getElementsByName('fnindexD0[]').length;
    for(var j=1;j<i;j++) {
         if (ValTime(document.getElementsByName('fdshift_inD0[]')[j].value)==false) {
             alert('Jam masuk belum valid..');
            document.getElementsByName('fdshift_inD0[]')[j].focus();
             return false;
        }
        else if (ValTime(document.getElementsByName('fdshift_outD0[]')[j].value)==false) {
             alert('Jam keluar belum valid..');
            document.getElementsByName('fdshift_outD0[]')[j].focus();
             return false;
        }
      }
    return true;
}

function ValTipeCatatan() {
  if(document.getElementById("ftnotes_type_code").value=='') {
       alert('Kode Tipe Catatan harus disi...');
       document.getElementById("ftnotes_type_code").focus();
       return false;
  }
  else if(document.getElementById("ftnotes_type_name").value=='') {
       alert('Nama Tipe Catatan harus disi...');
       document.getElementById("ftnotes_type_name").focus();
       return false;
  }

   ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftnotes_type_code').value);
   document.getElementById("ftnotes_type_code").focus();
    return false;
}
function ValGroupPenggajian() {
  if(document.getElementById("ftgroup_pengajian_code").value=='') {
       alert('Kode Group Penggajian harus disi...');
       document.getElementById("ftgroup_pengajian_code").focus();
       return false;
  }
  else if(document.getElementById("ftgroup_pengajian_name").value=='') {
       alert('Group Penggajian harus disi...');
       document.getElementById("ftgroup_pengajian_name").focus();
       return false;
  }

   ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftgroup_pengajian_code').value);
   document.getElementById("ftgroup_pengajian_code").focus();
    return false;
}




function ValPegawai1() {
  if(document.getElementById("ftemployee_code").value=='') {
       alert(' Kode Pegawai harus disi...');
       document.getElementById("ftemployee_code").focus();
       return false;
  }
  else if(document.getElementById("ftemployee_name").value=='') {
       alert(' Nama Pegawai harus disi...');
       document.getElementById("ftemployee_name").focus();
       return false;
  }
    else if(document.getElementById("ftbirth_place").value=='') {
       alert(' Tempat lahir harus disi...');
       document.getElementById("ftbirth_place").focus();
       return false;
  }
  
    else if(document.getElementById("ftreligion").value=='') {
       alert('Agama harus disi...');
       document.getElementById("ftreligion").focus();
       return false;
  }
  else if(document.getElementById("fnsex").value=='') {
       alert('Jenis Kelamin harus disi...');
       document.getElementById("fnsex").focus();
       return false;
  }
   else if(document.getElementById("ftktp_no").value=='') {
       alert('No. KTP harus disi...');
       document.getElementById("ftktp_no").focus();
       return false;
  }
  
    else if(document.getElementById("fteducation_code").value=='') {
       alert('Pendidikan harus disi...');
       document.getElementById("fteducation_code").focus();
       return false;
  }
   else if(document.getElementById("ftposition_code").value=='') {
       alert('Jabatan harus disi...');
       document.getElementById("ftposition_code").focus();
       return false;
  }
   else if(document.getElementById("ftdepartment_code").value=='') {
       alert('Departement harus disi...');
       document.getElementById("ftdepartment_code").focus();
       return false;
  }
    else if(document.getElementById("fnstatus").value=='') {
       alert('Status harus disi...');
       document.getElementById("fnstatus").focus();
       return false;
  }
  
   else if(document.getElementById("ftpph21_code").value=='') {
       alert('PPH 21 harus disi...');
       document.getElementById("ftpph21_code").focus();
       return false;
  }
    else if(document.getElementById("fnmarried_status").value=='') {
       alert('Status menikah harus disi...');
       document.getElementById("fnmarried_status").focus();
       return false;
  }
   else if(document.getElementById("fnmarried_status").value=='') {
       alert('Status menikah harus disi...');
       document.getElementById("fnmarried_status").focus();
       return false;
  }
   /*else if(document.getElementById("ftpayroll_type_code").value=='') {
       alert('Tipe gaji harus disi...');
       document.getElementById("ftpayroll_type_code").focus();
       return false;
  }*/
   else if(document.getElementById("ftshift_code").value=='') {
       alert('Shift harus disi...');
       document.getElementById("ftshift_code").focus();
       return false;
  }
    else if(document.getElementById("fnpayment_status_code").value=='') {
       alert('Metode pembayaran harus disi...');
       document.getElementById("fnpayment_status_code").focus();
       return false;
  }
  
    else if (ValPegawai_Tanggungan()==false) {
       return false;
  }
    else if (ValPegawai_Catatan()==false) {
       return false;
  }
  else if (ValPegawai_Pendapatan()==false) {
       return false;
  }
   else if (ValPegawai_Potongan()==false) {
       return false;
  }
  
  return true;
  }
  
function ValPegawai() {
   if(ValPegawai1()==true) {
	   ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftemployee_code').value);
	   document.getElementById("ftemployee_code").focus();
	   return false;
	}
	 return false;
   
}

function UpdatePegawai() {   
	 return ValPegawai1();   
}

function ValPegawai_Tanggungan() {
    var i=document.getElementsByName('fnindexD0[]').length;  
    for(var j=1;j<i;j++) { 
         if (document.getElementsByName('ftload_nameD0[]')[j].value=='') {
             alert('Nama tanggungan harus diisi..');
            document.getElementsByName('ftload_nameD0[]')[j].focus();
             return false;
        }
        else if (document.getElementsByName('ftload_statusD0[]')[j].value=='') {
             alert('Status tanggungan harus diisi..');
            document.getElementsByName('ftload_statusD0[]')[j].focus();
             return false;
        }
      }
    return true;
}

function ValPegawai_Catatan() {
    var i=document.getElementsByName('fnindexD1[]').length;
    for(var j=1;j<i;j++) {
         if (document.getElementsByName('ftnotes_type_codeD1[]')[j].value=='') {
             alert('Tipe catatan harus diisi..');
            document.getElementsByName('ftnotes_type_codeD1[]')[j].focus();
             return false;
        }
        else if (document.getElementsByName('ftnotes_contentD1[]')[j].value=='') {
             alert('Isi catatan harus diisi..');
            document.getElementsByName('ftnotes_contentD1[]')[j].focus();
             return false;
        }
      }
    return true;
}

function ValPegawai_Pendapatan() {
    var i=document.getElementsByName('fnindexD2[]').length;
    for(var j=1;j<i;j++) {
         if (document.getElementsByName('hidden_ftsalary_codeD2[]')[j].value=='') {
             alert('Kode Gaji belum valid ...');
            document.getElementsByName('ftsalary_codeD2[]')[j].focus();
             return false;
        }
       else if (document.getElementsByName('fnsalary_periodD2[]')[j].value=='') {
             alert('Periode harus diisi ...');
            document.getElementsByName('fnsalary_periodD2[]')[j].focus();
             return false;
        }
         else if (document.getElementsByName('fnpayroll_slipD2[]')[j].value=='') {
             alert('Pengajian harus diisi ...');
            document.getElementsByName('fnpayroll_slipD2[]')[j].focus();
             return false;
        }
      }
    return true;
}
function ValPegawai_Potongan() {
    var i=document.getElementsByName('fnindexD3[]').length;
    for(var j=1;j<i;j++) {
         if (document.getElementsByName('hidden_ftsalary_codeD3[]')[j].value=='') {
             alert('Kode Gaji belum valid ...');
            document.getElementsByName('ftsalary_codeD3[]')[j].focus();
             return false;
        }
       else if (document.getElementsByName('fnsalary_periodD3[]')[j].value=='') {
             alert('Periode harus diisi ...');
            document.getElementsByName('fnsalary_periodD3[]')[j].focus();
             return false;
        }
         else if (document.getElementsByName('fnpayroll_slipD3[]')[j].value=='') {
             alert('Pengajian harus diisi ...');
            document.getElementsByName('fnpayroll_slipD3[]')[j].focus();
             return false;
        }
      }
    return true;
}


function ValLembur() {
  if(document.getElementById("ftovertime_code").value=='') {
       alert('Kode Lembur harus disi...');
       document.getElementById("ftovertime_code").focus();
       return false;
  }
  else if(ValTime(document.getElementById("fdovertime_from").value)==false) {
       alert('Periode lembur awal belum valid...');
       document.getElementById("fdovertime_from").focus();
       return false;
  }
   else if(ValTime(document.getElementById("fdovertime_to").value)==false) {
       alert('Periode lembur akhir belum valid...');
       document.getElementById("fdovertime_to").focus();
       return false;
  }
   ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftovertime_code').value);
   document.getElementById("ftovertime_code").focus();
   return false;

}

function ValTipeCuti() {
  if(document.getElementById("ftleave_type_code").value=='') {
       alert('Kode Tipe cuti harus disi...');
       document.getElementById("ftleave_type_code").focus();
       return false;
  }
  else if(document.getElementById("ftleave_type_name").value=='') {
       alert('Nama tipe cuti harus disi...');
       document.getElementById("ftleave_type_name").focus();
       return false;
  }
   
   ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftleave_type_code').value);
   document.getElementById("ftleave_type_code").focus();
   return false;

}
function ValCuti() {
  if(document.getElementById("ftleave_no").value=='') {
       alert('No transaksi harus disi...');
       document.getElementById("ftleave_no").focus();
       return false;
  }
  else if(document.getElementById("hidden_ftemployee_code").value=='') {
       alert('Kode pegawai belum valid harus disi...');
       document.getElementById("ftemployee_code").focus();
       return false;
  }
   else if(document.getElementById("ftleave_type_code").value=='') {
       alert('Tipe cuti harus disi...');
       document.getElementById("ftleave_type_code").focus();
       return false;
  }
 else if(document.getElementById("fnleave_days").value*1<=0) {
       alert('Jumlah cuti harus lebih besar 0 disi...');
       document.getElementById("fnleave_days").focus();
       return false;
  }

   ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftleave_no').value);
   document.getElementById("ftleave_no").focus();
   return false;

}



function ValHariLibur() {
  if(document.getElementById("ftholiday_code").value=='') {
       alert('Kode hari libur harus disi...');
       document.getElementById("ftholiday_code").focus();
       return false;
  }
  else if(document.getElementById("ftholiday_name").value=='') {
       alert('Nama hari libur harus disi...');
       document.getElementById("ftholiday_name").focus();
       return false;
  }
   ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftholiday_code').value);
   document.getElementById("ftholiday_code").focus();
   return false;

}
function ValTerlambat() {
  if(document.getElementById("ftlate_code").value=='') {
       alert('Kode terlambat harus disi...');
       document.getElementById("ftlate_code").focus();
       return false;
  }
  else if(ValTime(document.getElementById("fdlate_from").value)==false) {
       alert('Periode terlamat awal belum valid...');
       document.getElementById("fdlate_from").focus();
       return false;
  }
   else if(ValTime(document.getElementById("fdlate_to").value)==false) {
       alert('Periode terlambat akhir belum valid...');
       document.getElementById("fdlate_to").focus();
       return false;
  }
   ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftlate_code').value);
   document.getElementById("ftlate_code").focus();
   return false;

}
function ValPengajian1() {
  if(document.getElementById("ftsalary_code").value=='') {
       alert('Kode Pengajian harus disi...');
       document.getElementById("ftsalary_code").focus();
       return false;
  }
  else  if(document.getElementById("ftsalary_name").value=='') {
       alert('Nama pengajian harus disi...');
       document.getElementById("ftsalary_name").focus();
       return false;
  }
  else  if(document.getElementById("ftsalary_category_code").value=='') {
       alert('Kategori harus disi...');
       document.getElementById("ftsalary_category_code").focus();
       return false;
  }
  
  else  if(document.getElementById("fnsalary_type").value=='') {
       alert('Type pengajian harus disi...');
       document.getElementById("fnsalary_type").focus();
       return false;
  }
   else  if(document.getElementById("fnsalary_period").value=='') {
       alert('Periode harus disi...');
       document.getElementById("fnsalary_period").focus();
       return false;
  }
   else  if(document.getElementById("fnpayroll_slip").value=='') {
       alert('"Di Bayar Dipengajian" harus di isi...');
       document.getElementById("fnpayroll_slip").focus();
       return false;
  }
   else  if(document.getElementById("fnstatus").value=='') {
       alert('status harus di isi...');
       document.getElementById("fnstatus").focus();
       return false;
  }
 return true;
 
 }
 function ValPengajian() {
   if(ValPengajian1()==true) {
	   ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftsalary_code').value);
	   document.getElementById("ftsalary_code").focus();
	   return false;
	}
	return false;
}

 function UpdatePengajian() {
	return ValPengajian1();
 }


function ValAbsensi() {
  if(document.getElementById("ftattendance_no").value=='') {
       alert('No. Transaksi harus disi...');
       document.getElementById("ftattendance_no").focus();
       return false;
  }
  else if(document.getElementsByName('fnindexD0[]').length<2) {
      alert('Detail transaksi belum diisi...');
      return false;
  }
 
  else if(ValAbsensi1()==false) {
      return false;
  }
  if(document.getElementById('ftdesciption').value=='Hari Libur') {
       if (!confirm('Hari tersebut hari libur, apakah mau diteruskan...')) {
             return false;
       }
  }
  // ajax_do(str_url + '&ajax=1&code=transno&ftposition_code=' + document.getElementById('ftposition_code').value +'&ftshift_code=' + document.getElementById('ftshift_code').value +'&fdattendance_date=' + document.getElementById('fdattendance_date').value +'&fttrans_no=' + document.getElementById('ftattendance_no').value);
  ajax_do(str_url + '&ajax=1&code=transno&ftdivision_code=' + document.getElementById('ftdivision_code').value +'&ftdepartment_code=' + document.getElementById('ftdepartment_code').value +'&ftposition_code=' + document.getElementById('ftposition_code').value +'&ftshift_code=' + document.getElementById('ftshift_code').value +'&fdattendance_date=' + document.getElementById('fdattendance_date').value +'&fttrans_no=' + document.getElementById('ftattendance_no').value);
   
   document.getElementById("ftattendance_no").focus();
   return false;

}

function ValAbsensi1() {
     var i=document.getElementsByName('fnindexD0[]').length;
     var str1='';
     var str2='';
    for(var j=1;j<i;j++) {
         if ((document.getElementsByName('hidden_ftemployee_codeD0[]')[j].value=='')) {
             alert('Grid belum di isi ...');
            document.getElementsByName('ftemployee_codeD0[]')[j].focus();
             return false;
        }
        else if(document.getElementsByName('fnemployee_statusD0[]')[j].value=='') {
            alert('Status kehadiran harus diisi...');
            document.getElementsByName('fnemployee_statusD0[]')[j].focus();
             return false;
        }
        else if((document.getElementsByName('fnemployee_statusD0[]')[j].value=='0')&&(!( (document.getElementsByName('ftabsen_codeD0[]')[j].value=='')||(document.getElementsByName('ftabsen_codeD0[]')[j].value=='T')))){
             alert('Keterlambatan untuk status kehadiran tidak valid...');
             document.getElementsByName('fnemployee_statusD0[]')[j].focus();
             return false;
             
        }
        else if(ValTime(document.getElementsByName('fdworking_enter_timeD0[]')[j].value)==false){
              alert('Jam masuk belum valid...');
             document.getElementsByName('fdworking_enter_timeD0[]')[j].focus();
             return false;
        }
        else if(ValTime(document.getElementsByName('fdworking_exit_timeD0[]')[j].value)==false){
              alert('Jam keluar belum valid...');
             document.getElementsByName('fdworking_exit_timeD0[]')[j].focus();
             return false;
        }

        str1=CDate(document.getElementById("fdattendance_date").value).replace(/-/g,'')+document.getElementsByName('fdworking_enter_timeD0[]')[j].value.replace(/:/g,'');
        str2=CDate(document.getElementsByName('fdworking_exit_dateD0[]')[j].value).replace(/-/g,'')+document.getElementsByName('fdworking_exit_timeD0[]')[j].value.replace(/:/g,'');
       // alert(str1);
       // alert(str2);
        if(str2<str1) {
             alert('Jam keluar tidak boleh melebihi jam masuk ...');
             document.getElementsByName('fdworking_exit_timeD0[]')[j].focus();
             return false;
        }
    
        if(document.getElementsByName('ftabsen_codeD0[]')[j].value=='T'){
            if(document.getElementsByName('fdworking_enter_timeD0[]')[j].value.replace(/:/g,'')*1<=document.getElementById('ftworking_enter_time').value.replace(/:/g,'')*1){
                 alert('Karna keterlambatan : Jam masuk tidak boleh melebihi jam masuk...');
                 document.getElementsByName('fdworking_exit_timeD0[]')[j].focus();
                 return false;
            }
        }
        
        
      }
      return true;
}

function FinalAbsensi() {
   return true;

}

function ValPerhitunganLembur() {
  if(document.getElementById("ftovertime_no").value=='') {
       alert('No. Transaksi harus disi...');
       document.getElementById("ftovertime_no").focus();
       return false;
  }
  else if(document.getElementsByName('fnindexD0[]').length<2) {
     alert('Detail transaksi belum diisi...');
  }
   if(document.getElementById('ftdesciption').value=='Hari Libur') {
       if (!confirm('Hari tersebut hari libur, apakah mau diteruskan...')) {
             return false;
       }
  }
  if(ValPerhitunganLembur1()==false) {
      return false;
  }
   ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftovertime_no').value);
   document.getElementById("ftovertime_no").focus();
   return false;

}

function ValPerhitunganLembur1() {
     var i=document.getElementsByName('fnindexD0[]').length;
     var str1='';
     var str2='';
    for(var j=1;j<i;j++) {
         if ((document.getElementsByName('hidden_ftemployee_codeD0[]')[j].value=='')) {
             alert('Grid belum di isi ...');
            document.getElementsByName('ftemployee_codeD0[]')[j].focus();
             return false;
        }
       
        else if(ValTime(document.getElementsByName('fdovertime_enter_timeD0[]')[j].value)==false){
              alert('Jam masuk lembur belum valid...');
             document.getElementsByName('fdovertime_enter_timeD0[]')[j].focus();
             return false;
        }
        else if(ValTime(document.getElementsByName('fdovertime_exit_timeD0[]')[j].value)==false){
              alert('Jam keluar lembur belum valid...');
             document.getElementsByName('fdovertime_exit_timeD0[]')[j].focus();
             return false;
        }

        str1=CDate(document.getElementById("fdovertime_date").value).replace(/-/g,'')+document.getElementsByName('fdovertime_enter_timeD0[]')[j].value.replace(/:/g,'');
        str2=CDate(document.getElementsByName('fdovertime_exit_dateD0[]')[j].value).replace(/-/g,'')+document.getElementsByName('fdovertime_exit_timeD0[]')[j].value.replace(/:/g,'');
       // alert(str1);
       // alert(str2);
        if(str2<str1) {
             alert('Jam keluar lembur tidak boleh melebihi jam masuk lembur...');
             document.getElementsByName('fdovertime_exit_timeD0[]')[j].focus();
             return false;
        }

      }
      return true;
}

function FinalPerhitunganLembur() {
 return true;
}

function ValPembayaranUangLembur() {
  if(document.getElementById("ftovertime_money_no").value=='') {
       alert('No. Transaksi harus disi...');
       document.getElementById("ftovertime_money_no").focus();
       return false;
  }
  else if(document.getElementsByName('fnindexD0[]').length<2) {
       alert('Detail transaksi belum diisi...');
       return false;
  }
  else if(ValPembayaranUangLembur1()==false) {
       return false;
  }
  
   ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftovertime_money_no').value);
   document.getElementById("ftovertime_money_no").focus();
   return false;

}

function ValPembayaranUangLembur1() {
     var i=document.getElementsByName('fnindexD0[]').length;
     var str1='';
     var str2='';
    for(var j=1;j<i;j++) {
         if ((document.getElementsByName('hidden_ftemployee_codeD0[]')[j].value=='')) {
            alert('Detail transaksi belum diisi...');
            document.getElementsByName('ftemployee_codeD0[]')[j].focus();
             return false;
        }
      }
      return true;
}



function ValTHR() {
  if(document.getElementById("ftthr_no").value=='') {
       alert('No. Transaksi harus disi...');
       document.getElementById("ftthr_no").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("ftdivision_code").value=='') {
       alert('Divisi harus disi...');
       document.getElementById("ftdivision_code").focus();
       return false;
  }
  else if(document.getElementById("ftgroup_pengajian_code").value=='') {
       alert('Group Penggajian harus disi...');
       document.getElementById("ftgroup_pengajian_code").focus();
       return false;
  }  
  else if(document.getElementById("ftreligion").value=='') {
       alert('Agama harus disi...');
       document.getElementById("ftreligion").focus();
       return false;
  }    
  else if(document.getElementsByName('fnindexD0[]').length<2) {
     alert('Detail transaksi belum diisi...');
      return false;
  }
   else if(ValTHR1()==false) {
       return false;
  }
   ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftthr_no').value);
   document.getElementById("ftthr_no").focus();
   return false;

}

function ValTHR1() {
     var i=document.getElementsByName('fnindexD0[]').length;
     var str1='';
     var str2='';
    for(var j=1;j<i;j++) {
         if ((document.getElementsByName('hidden_ftemployee_codeD0[]')[j].value=='')) {
            alert('Detail transaksi belum diisi...');
            document.getElementsByName('ftemployee_codeD0[]')[j].focus();
             return false;
        }
      }
      return true;
}


function ValPinjaman() {
  if(document.getElementById("ftloan_no").value=='') {
       alert('No. Transaksi harus disi...');
       document.getElementById("ftloan_no").focus();
       return false;
  }
  else if(document.getElementById("hidden_ftemployee_code").value=='') {
       alert('Kode pegawai belum valid harus disi...');
       document.getElementById("ftemployee_code").focus();
       return false;
  }
  else if(document.getElementById("ftloan_type_code").value=='') {
       alert('Jenis pinjaman harus disi...');
       document.getElementById("ftloan_type_code").focus();
       return false;
  }
   else if(document.getElementById("fnpayroll_slip").value=='') {
       alert('Potongan di pengajian harus disi...');
       document.getElementById("fnpayroll_slip").focus();
       return false;
  }
  else if(document.getElementById('fcloan_balance').value.replace(/,/g,'')*1<=0) {
	   alert('Jumlah pinjaman harus disi...');
       document.getElementById("fcloan_balance").focus();
       return false;
  }
//  else if(document.getElementById('fcloan_max').value.replace(/,/g,'')*1< (document.getElementById('fcloan_balance').value.replace(/,/g,'')*1+document.getElementById('fcloan_amount').value.replace(/,/g,'')*1  )) {
//	   alert('Jumlah pinjaman tidak boleh melebihi maxsimum jml pinjaman...');
//       document.getElementById("fcloan_balance").focus();
//       return false;
//  }
  
   else if(document.getElementById("ftbankpym_no").value=='') {
       alert('No. Bank Keluar Harus Diisi...');
       document.getElementById("ftbankpym_no").focus();
       return false;
  }
    else if(document.getElementById("ftjournal_no").value=='') {
       alert('No. Jurnal Harus Diisi...');
       document.getElementById("ftjournal_no").focus();
       return false;
  }
    else if(document.getElementById("ftacc_no").value=='') {
       alert('Bank Harus Diisi...');
       document.getElementById("ftacc_no").focus();
       return false;
  }
    else if(document.getElementById("fnpayment_method").value=='') {
       alert('Metode pembayaran Harus Diisi...');
       document.getElementById("fnpayment_method").focus();
       return false;
  }

   ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftloan_no').value+'&ftbankpym_no=' + document.getElementById('ftbankpym_no').value+'&ftjournal_no=' + document.getElementById('ftjournal_no').value);
   document.getElementById("ftloan_no").focus();
   return false;

}

function ValPinjaman1() {
  if(document.getElementById("ftloan_no").value=='') {
       alert('No. Transaksi harus disi...');
       document.getElementById("ftloan_no").focus();
       return false;
  }
  else if(document.getElementById("hidden_ftemployee_code").value=='') {
       alert('Kode pegawai belum valid harus disi...');
       document.getElementById("ftemployee_code").focus();
       return false;
  }
  else if(document.getElementById("ftloan_type_code").value=='') {
       alert('Jenis pinjaman harus disi...');
       document.getElementById("ftloan_type_code").focus();
       return false;
  }
   else if(document.getElementById("fnpayroll_slip").value=='') {
       alert('Potongan di pengajian harus disi...');
       document.getElementById("fnpayroll_slip").focus();
       return false;
  }
  else if(document.getElementById('fcloan_balance').value.replace(/,/g,'')*1<=0) {
	   alert('Jumlah pinjaman harus disi...');
       document.getElementById("fcloan_balance").focus();
       return false;
  }
//  else if(document.getElementById('fcloan_max').value.replace(/,/g,'')*1< (document.getElementById('fcloan_balance').value.replace(/,/g,'')*1+document.getElementById('fcloan_amount').value.replace(/,/g,'')*1  )) {
//	   alert('Jumlah pinjaman tidak boleh melebihi maxsimum jml pinjaman...');
//       document.getElementById("fcloan_balance").focus();
//       return false;
//  }

   else if(document.getElementById("ftbankpym_no").value=='') {
       alert('No. Bank Keluar Harus Diisi...');
       document.getElementById("ftbankpym_no").focus();
       return false;
  }
    else if(document.getElementById("ftjournal_no").value=='') {
       alert('No. Jurnal Harus Diisi...');
       document.getElementById("ftjournal_no").focus();
       return false;
  }
    else if(document.getElementById("ftacc_no").value=='') {
       alert('Bank Harus Diisi...');
       document.getElementById("ftacc_no").focus();
       return false;
  }
    else if(document.getElementById("fnpayment_method").value=='') {
       alert('Metode pembayaran Harus Diisi...');
       document.getElementById("fnpayment_method").focus();
       return false;
  }

   ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftloan_no').value+'&ftbankpym_no=' + document.getElementById('ftbankpym_no').value+'&ftjournal_no=' + document.getElementById('ftjournal_no').value);
   document.getElementById("ftloan_no").focus();
   return false;

}

function FinalPinjaman() {
  if(document.getElementById("ftloan_no").value=='') {
       alert('No. Transaksi harus disi...');
       document.getElementById("ftloan_no").focus();
       return false;
  }
  else if(document.getElementById("hidden_ftemployee_code").value=='') {
       alert('Kode pegawai belum valid harus disi...');
       document.getElementById("ftemployee_code").focus();
       return false;
  }
  else if(document.getElementById("ftloan_type_code").value=='') {
       alert('Jenis pinjaman harus disi...');
       document.getElementById("ftloan_type_code").focus();
       return false;
  }
   else if(document.getElementById("fnpayroll_slip").value=='') {
       alert('Potongan di pengajian harus disi...');
       document.getElementById("fnpayroll_slip").focus();
       return false;
  }
  else if(document.getElementById('fcloan_balance').value.replace(/,/g,'')*1<=0) {
	   alert('Jumlah pinjaman harus disi...');
       document.getElementById("fcloan_balance").focus();
       return false;
  }
//  else if(document.getElementById('fcloan_max').value.replace(/,/g,'')*1< (document.getElementById('fcloan_balance').value.replace(/,/g,'')*1+document.getElementById('fcloan_amount').value.replace(/,/g,'')*1  )) {
//	   alert('Jumlah pinjaman tidak boleh melebihi maxsimum jml pinjaman...');
//       document.getElementById("fcloan_balance").focus();
//       return false;
//  }

   else if(document.getElementById("ftbankpym_no").value=='') {
       alert('No. Bank Keluar Harus Diisi...');
       document.getElementById("ftbankpym_no").focus();
       return false;
  }
    else if(document.getElementById("ftjournal_no").value=='') {
       alert('No. Jurnal Harus Diisi...');
       document.getElementById("ftjournal_no").focus();
       return false;
  }
    else if(document.getElementById("ftacc_no").value=='') {
       alert('Bank Harus Diisi...');
       document.getElementById("ftacc_no").focus();
       return false;
  }
    else if(document.getElementById("fnpayment_method").value=='') {
       alert('Metode pembayaran Harus Diisi...');
       document.getElementById("fnpayment_method").focus();
       return false;
  }

  return true;

}

function FinalPinjaman1() {
  if(document.getElementById("ftloan_no").value=='') {
       alert('No. Transaksi harus disi...');
       document.getElementById("ftloan_no").focus();
       return false;
  }
  else if(document.getElementById("hidden_ftemployee_code").value=='') {
       alert('Kode pegawai belum valid harus disi...');
       document.getElementById("ftemployee_code").focus();
       return false;
  }
  else if(document.getElementById("ftloan_type_code").value=='') {
       alert('Jenis pinjaman harus disi...');
       document.getElementById("ftloan_type_code").focus();
       return false;
  }
   else if(document.getElementById("fnpayroll_slip").value=='') {
       alert('Potongan di pengajian harus disi...');
       document.getElementById("fnpayroll_slip").focus();
       return false;
  }
  else if(document.getElementById('fcloan_balance').value.replace(/,/g,'')*1<=0) {
	   alert('Jumlah pinjaman harus disi...');
       document.getElementById("fcloan_balance").focus();
       return false;
  }
//  else if(document.getElementById('fcloan_max').value.replace(/,/g,'')*1< (document.getElementById('fcloan_balance').value.replace(/,/g,'')*1+document.getElementById('fcloan_amount').value.replace(/,/g,'')*1  )) {
//	   alert('Jumlah pinjaman tidak boleh melebihi maxsimum jml pinjaman...');
//       document.getElementById("fcloan_balance").focus();
//       return false;
//  }

   else if(document.getElementById("ftbankpym_no").value=='') {
       alert('No. Bank Keluar Harus Diisi...');
       document.getElementById("ftbankpym_no").focus();
       return false;
  }
    else if(document.getElementById("ftjournal_no").value=='') {
       alert('No. Jurnal Harus Diisi...');
       document.getElementById("ftjournal_no").focus();
       return false;
  }
    else if(document.getElementById("ftacc_no").value=='') {
       alert('Bank Harus Diisi...');
       document.getElementById("ftacc_no").focus();
       return false;
  }
    else if(document.getElementById("fnpayment_method").value=='') {
       alert('Metode pembayaran Harus Diisi...');
       document.getElementById("fnpayment_method").focus();
       return false;
  }

  return true;

}


function ValPembayaranPinjaman() {
  if(document.getElementById("ftloan_payment_no").value=='') {
       alert('No. Transaksi harus disi...');
       document.getElementById("ftloan_payment_no").focus();
       return false;
  }
  else if(document.getElementById("hidden_ftemployee_code").value=='') {
       alert('Kode Pegawai belum lengkap...');
       document.getElementById("ftemployee_code").focus();
       return false;
  }
  else if(document.getElementsByName('fnindexD0[]').length<2) {
     alert('Detail transaksi belum diisi...');
	 return false;
  }
  else if(ValPembayaranPinjaman2()==false) {
	return false;
  }
  else if(document.getElementById("ftbankrcp_no").value=='') {
       alert('No. Bank Masuk Harus Diisi...');
       document.getElementById("ftbankrcp_no").focus();
       return false;
  }
    else if(document.getElementById("ftjournal_no").value=='') {
       alert('No. Jurnal Harus Diisi...');
       document.getElementById("ftjournal_no").focus();
       return false;
  }
    else if(document.getElementById("ftacc_no").value=='') {
       alert('Bank Harus Diisi...');
       document.getElementById("ftacc_no").focus();
       return false;
  }
    else if(document.getElementById("fnpayment_method").value=='') {
       alert('Metode pembayaran Harus Diisi...');
       document.getElementById("fnpayment_method").focus();
       return false;
  }

   ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftloan_payment_no').value+'&ftbankrcp_no=' + document.getElementById('ftbankrcp_no').value+'&ftjournal_no=' + document.getElementById('ftjournal_no').value);
   document.getElementById("ftloan_payment_no").focus();
   return false;
   

}

function FinalPembayaranPinjaman() {
  if(document.getElementById("ftloan_payment_no").value=='') {
       alert('No. Transaksi harus disi...');
       document.getElementById("ftloan_payment_no").focus();
       return false;
  }
  else if(document.getElementById("hidden_ftemployee_code").value=='') {
       alert('Kode Pegawai belum lengkap...');
       document.getElementById("ftemployee_code").focus();
       return false;
  }
  else if(document.getElementsByName('fnindexD0[]').length<2) {
     alert('Detail transaksi belum diisi...');
	 return false;
  }
  else if(ValPembayaranPinjaman2()==false) {
	return false;
  }


    else if(document.getElementById("ftbankrcp_no").value=='') {
       alert('No. Bank Masuk Harus Diisi...');
       document.getElementById("ftbankrcp_no").focus();
       return false;
  }
    else if(document.getElementById("ftjournal_no").value=='') {
       alert('No. Jurnal Harus Diisi...');
       document.getElementById("ftjournal_no").focus();
       return false;
  }
    else if(document.getElementById("ftacc_no").value=='') {
       alert('Bank Harus Diisi...');
       document.getElementById("ftacc_no").focus();
       return false;
  }
    else if(document.getElementById("fnpayment_method").value=='') {
       alert('Metode pembayaran Harus Diisi...');
       document.getElementById("fnpayment_method").focus();
       return false;
  }

//   ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftloan_payment_no').value+'&ftbankrcp_no=' + document.getElementById('ftbankrcp_no').value+'&ftjournal_no=' + document.getElementById('ftjournal_no').value);
//   document.getElementById("ftloan_payment_no").focus();
   return true;


}

function ValPembayaranPinjaman1() {

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

      
        fcamountxx+=document.getElementsByName('fcloan_paymentD0[]')[j].value.replace(/,/g,'')*1;
    }
         document.getElementById('fcloan_payment_amount').value=fcamountxx;

    ElementCurrencyALL();
}



function ValPembayaranPinjaman2() {
     var m=0;
    var i=document.getElementsByName('fnindexD0[]').length;    
    for(var j=1;j<i;j++) {
		 if(document.getElementsByName('fcloan_paymentD0[]')[j].value.replace(/,/g,'')*1>document.getElementsByName('fcloan_balanceD0[]')[j].value.replace(/,/g,'')*1) {
			alert("Jumlah pembayaran tidak boleh melebihi sisa peminjaman ....");
			document.getElementsByName('fcloan_paymentD0[]')[j].focus();
			return false;
		}
        else if(document.getElementsByName('fcloan_paymentD0[]')[j].value.replace(/,/g,'')*1>0) {
            m=1;
		} 
		
    }

     if(m==0) {
           if(!confirm('Jumlah pembayaran harus ada yang diisi...')) {
                return false;
          }
     } 

    return true;
}





//====================================
//		SLIP GAJI
//====================================

function ValDaftarPegawai() {
      if(document.getElementById("ftpayroll_slip_no").value=='') {
           alert('No. Transaksi harus disi...');
           document.getElementById("ftpayroll_slip_no").focus();
           return false;
      }
      else if(document.getElementById("ftpayroll_type_code").value=='') {
            alert('Type gaji harus disi...');
           document.getElementById("ftpayroll_type_code").focus();
           return false;
      }
//       else if(document.getElementById("fdstart_date").value>document.getElementById("fdend_date").value) {
//            alert('Periode 2 tidak boleh melebihi periode 1...');
//           document.getElementById("fdend_date").focus();
//           return false;
//      }
  
    return true;
}
function ValSlipGajiTipe1() {
    if(document.getElementById("ftpayroll_slip_no").value=='') {
       alert('No. Transaksi harus disi...');
       document.getElementById("ftpayroll_slip_no").focus();
       return false;
  }
    return true;

}
function ValSlipGajiTipe2() {
    if(document.getElementById("ftpayroll_slip_no").value=='') {
       alert('No. Transaksi harus disi...');
       document.getElementById("ftpayroll_slip_no").focus();
       return false;
  }
    return true;

}
function ValSlipGajiTipe3() {
    if(document.getElementById("ftpayroll_slip_no").value=='') {
       alert('No. Transaksi harus disi...');
       document.getElementById("ftpayroll_slip_no").focus();
       return false;
  }
    return true;

}

function FinalSlipGajiTipe1() {
    if(document.getElementById("ftpayroll_slip_no").value=='') {
       alert('No. Transaksi harus disi...');
       document.getElementById("ftpayroll_slip_no").focus();
       return false;
  }
    return true;

}
function FinalSlipGajiTipe2() {
    if(document.getElementById("ftpayroll_slip_no").value=='') {
       alert('No. Transaksi harus disi...');
       document.getElementById("ftpayroll_slip_no").focus();
       return false;
  }
    return true;

}
function FinalSlipGajiTipe3() {
    if(document.getElementById("ftpayroll_slip_no").value=='') {
       alert('No. Transaksi harus disi...');
       document.getElementById("ftpayroll_slip_no").focus();
       return false;
  }
    return true;

}

function ValSlipGajiIncome() {
    var i=document.getElementsByName('fnindexD1[]').length;
	var ffTotal=0;
    for(var j=1;j<i;j++) {
        ffTotal=ffTotal+document.getElementsByName('fcamountD1[]')[j].value.replace(/,/g,'')*1;
    }
	var index=document.getElementById('fnindex_grid1').value;
    document.getElementById('fcincome_amountD0'+index).value=ffTotal;
	document.getElementById('fcamountD0'+index).value=document.getElementById('fcincome_amountD0'+index).value.replace(/,/g,'')*1-document.getElementById('fcdeduction_amountD0'+index).value.replace(/,/g,'')*1;
}
function ValSlipGajiDeduction() {
    var i=document.getElementsByName('fnindexD2[]').length;
	var ffTotal=0;
    for(var j=1;j<i;j++) {
        ffTotal=ffTotal+document.getElementsByName('fcamountD2[]')[j].value.replace(/,/g,'')*1;
    }
	var index=document.getElementById('fnindex_grid1').value;
    document.getElementById('fcdeduction_amountD0'+index).value=ffTotal;
	document.getElementById('fcamountD0'+index).value=document.getElementById('fcincome_amountD0'+index).value.replace(/,/g,'')*1-document.getElementById('fcdeduction_amountD0'+index).value.replace(/,/g,'')*1;

}
function ValStrSlipGajiUrlHdr() {
	var strReturn="";
	strReturn+='&ftpayroll_slip_nox='+base64_encode(document.getElementById('ftpayroll_slip_no').value);
	strReturn+='&ftpayroll_type_codex='+base64_encode(document.getElementById('ftpayroll_type_code').value);
	strReturn+='&fdtrans_datex='+base64_encode(document.getElementById('fdtrans_date').value);
	strReturn+='&fdstart_datex='+base64_encode(document.getElementById('fdstart_date').value);
	strReturn+='&fdend_datex='+base64_encode(document.getElementById('fdend_date').value);
	strReturn+='&ftnotesx='+(document.getElementById('ftnotes').value);
	strReturn+='&fcgrand_income_amountx='+base64_encode(document.getElementById('fcgrand_income_amount').value);
	strReturn+='&fcgrand_deduction_amountx='+base64_encode(document.getElementById('fcgrand_deduction_amount').value);
	strReturn+='&fcgrand_totalx='+base64_encode(document.getElementById('fcgrand_total').value);
	strReturn+='&fnstatusx='+base64_encode(document.getElementById('fnstatus').value);
	return  strReturn;
}
function ValStrSlipGajiUrlEmployee() {
        var grid1="";
        var i=document.getElementsByName('fnindexD1[]').length;      
        for(var j=1;j<i;j++) {
           grid1+=document.getElementsByName('fnindexD1[]')[j].value+"|"+document.getElementsByName('ftsalary_codeD1[]')[j].value+"|"+document.getElementsByName('fcamountD1[]')[j].value.replace(/,/g,'')*1+"*";
        }
        var grid2="";
        i=document.getElementsByName('fnindexD2[]').length;      
        for(j=1;j<i;j++) {
           grid2+=document.getElementsByName('fnindexD2[]')[j].value+"|"+document.getElementsByName('ftsalary_codeD2[]')[j].value+"|"+document.getElementsByName('fcamountD2[]')[j].value.replace(/,/g,'')*1+"*";
        }
        //alert('&strgrid1='+base64_encode(grid1)+'&strgrid2='+base64_encode(grid2));
        return '&strgrid1='+base64_encode(grid1)+'&strgrid2='+base64_encode(grid2);
       
}



function SetDisableObject(ObjId) {
	
    Obj=document.getElementById(ObjId);
	
    if(Obj.type == "checkbox") {

    }
    else if(Obj.type == "text") {
			 
            Obj.readOnly = true;
            Obj.style.backgroundColor='rgb(224, 224, 224)';
			
			

    }
    else if(Obj.type == "radio") {

    }
    else if(Obj.type == "button") {
         Obj.disabled=true;

    }
    else if(Obj.type == "textarea") {
         Obj.readOnly = true;
            Obj.style.backgroundColor='rgb(224, 224, 224)';

    }
      else if(Obj.type == "select-one") {         
           Obj.disabled=true;
           Obj.onChange='this.selectedIndex = this.initialSelect';
           Obj.onFocus= 'this.initialSelect = this.selectedIndex';	
			Obj.readOnly = true;
            Obj.style.backgroundColor='rgb(224, 224, 224)';

    }
    else if(Obj.type == "submit") {

    }
    else if(Obj.type == "radio") {

    }
}

function ValShiftPegawaiKolektif() {
    if(document.getElementById("fttrans_no").value=='') {
      alert('No. transaksi harus disi...');
      document.getElementById("fttrans_no").focus();
      return false;
    }
    else if (ValShiftPegawaiKolektif1()==false) {
       return false;
  }

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

  return false;
}

function ValShiftPegawaiKolektif1() {
    var i=document.getElementsByName('fnindexD0[]').length;
   
    for(var j=1;j<i;j++) {
      
         if (document.getElementsByName('hidden_ftdivision_codeD0[]')[j].value=='') {
             alert('Kode Divisi belum valid..');
            document.getElementsByName('ftdivision_codeD0[]')[j].focus();
             return false;
        }
        else if (document.getElementsByName('hidden_ftdepartment_codeD0[]')[j].value=='') {
             alert('Kode Departement belum valid..');
            document.getElementsByName('ftdepartment_codeD0[]')[j].focus();
             return false;
        }
        else if (document.getElementsByName('hidden_ftposition_codeD0[]')[j].value=='') {
             alert('Kode Jabatan belum valid..');
            document.getElementsByName('ftposition_codeD0[]')[j].focus();
             return false;
        }
       
         else if (document.getElementsByName('ftshift_code_fromD0[]')[j].value=='') {
             alert('Shift Asal belum valid..');
            document.getElementsByName('ftshift_code_fromD0[]')[j].focus();
             return false;
        }
          else if (document.getElementsByName('ftshift_code_toD0[]')[j].value=='') {
             alert('Shift Tujuan belum valid..');
            document.getElementsByName('ftshift_code_toD0[]')[j].focus();
             return false;
        }
       
    }

    return true;
}

// ======================================================
//=== BARANG SETENGAH JADI===============================
//=======================================================
function ValGroupBarangSetengahJadi() {

  if(document.getElementById("ftstock_group_code").value=='') {
       alert('Kode Group Barang harus diisi...');
       document.getElementById("ftstock_group_code").focus();
       return false;
  }
  else if(document.getElementById("ftstock_group_name").value=='') {
       alert('Nama Group Barang harus diisi...');
       document.getElementById("ftstock_group_name").focus();
       return false;
  }


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

  return false;
}

function ValBarangSetengahJadi() {

  if(document.getElementById("ftitem_code").value=='') {
       alert('Kode Barang harus diisi...');
       document.getElementById("ftitem_code").focus();
       return false;
  }
  else if(document.getElementById("ftitem_code").value.length==0) {
       alert('Kode Barang harus diisi...');
       document.getElementById("ftitem_code").focus();
       return false;
  }
  else if(document.getElementById("ftitem_code").value.indexOf('&') != -1) {
       alert('Kode Barang Tidak boleh menggunakan Karakter & ...');
       document.getElementById("ftitem_code").focus();
       return false;
  } 
  else if(document.getElementById("ftitem_name").value=='') {
       alert('Nama Barang harus diisi...');
       document.getElementById("ftitem_name").focus();
       return false;
  }
  else if(document.getElementById("ftprint_name").value=='') {
       alert('Nama Cetak harus diisi...');
       document.getElementById("ftprint_name").focus();
       return false;
  }

 else if(document.getElementById("ftstock_category_code").value=='') {
       alert('Kategory harus diisi...');
       document.getElementById("ftstock_category_code").focus();
       return false;
  }
   else if(document.getElementById("hidden_ftstock_group_code").value=='') {
       alert('Group belum valid...');
       document.getElementById("ftstock_group_code").focus();
       return false;
  }
  /*
  else if(document.getElementById("ftweight_code").value=='') {
       alert('Kode berat harus diisi...');
       document.getElementById("ftweight_code").focus();
       return false;
  } */
  else if(document.getElementById("ftuom_code").value=='') {
       alert('Kode satuan harus diisi...');
       document.getElementById("ftuom_code").focus();
       return false;
  }
    else if(document.getElementById("ftgl_inv_acc").value=='') {
        alert('No Perkiraan Persediaan harus diisi...');
        document.getElementById("ftgl_inv_acc").focus();
        return false;
    }
    else if(document.getElementById("ftgl_cogs_acc").value=='') {
        alert('No Perkiraan HPP harus diisi...');
        document.getElementById("ftgl_cogs_acc").focus();
        return false;
    }
    else if(document.getElementById("ftgl_sales_acc").value=='') {
        alert('No Perkiraan Penjualan harus diisi...');
        document.getElementById("ftgl_sales_acc").focus();
        return false;
    }
    else if(document.getElementById("ftgl_sales_ret_acc").value=='') {
        alert('No Perkiraan Retur Penjualan harus diisi...');
        document.getElementById("ftgl_sales_ret_acc").focus();
        return false;
    }
    else if(document.getElementById("ftgl_sales_disc_acc").value=='') {
        alert('No Perkiraan Discount Penjualan harus diisi...');
        document.getElementById("ftgl_sales_disc_acc").focus();
        return false;
    }

  else if(ValBarangSetengahJadi1()==false) {
       return false;
  }

  ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftitem_code').value);
  document.getElementById("ftitem_code").focus();
  return false;
}

function ValBarangSetengahJadi1() {
    var i=document.getElementsByName('ftuom_code_multiD1[]').length;
    for(var j=1;j<i;j++) {
        if  (document.getElementsByName('ftuom_code_multiD1[]')[j].value==document.getElementById('ftuom_code').value) {
            alert('Kode satuan sudah digunakan ');
            document.getElementsByName('ftuom_code_multiD1[]')[j].focus();
            return false;
        } else  if  (document.getElementsByName('ftuom_code_multiD1[]')[j].value=='') {
            alert('Kode Multi Satuan harus diisi ');
            document.getElementsByName('ftuom_code_multiD1[]')[j].focus();
            return false;
        } else  if  (document.getElementsByName('ffformulaD1[]')[j].value.replace(/,/g,'')*1 <= 0) {
            alert('Nominal Formula harus lebih besar dari 0 ');
            document.getElementsByName('ffformulaD1[]')[j].focus();
            return false;
        }

        for(var k=1;k<j;k++) {
            if  (document.getElementsByName('ftuom_code_multiD1[]')[k].value==document.getElementsByName('ftuom_code_multiD1[]')[j].value) {
                alert('Kode satuan sudah digunakan ');
                document.getElementsByName('ftuom_code_multiD1[]')[k].focus();
                return false;
            }
        }
    }

    return true;
}

function UpdateBarangSetengahJadi() {
    if(document.getElementById("ftitem_code").value=='') {
       alert('Kode Barang harus diisi...');
       document.getElementById("ftitem_code").focus();
       return false;
  }
  else if(document.getElementById("ftitem_name").value=='') {
       alert('Nama Barang harus diisi...');
       document.getElementById("ftitem_name").focus();
       return false;
  }
  else if(document.getElementById("ftprint_name").value=='') {
       alert('Nama Cetak harus diisi...');
       document.getElementById("ftprint_name").focus();
       return false;
  }
 else if(document.getElementById("ftuom_code").value=='') {
       alert('Satuan harus diisi...');
       document.getElementById("ftuom_code").focus();
       return false;
  }

 else if(document.getElementById("ftstock_category_code").value=='') {
       alert('Kategory harus diisi...');
       document.getElementById("ftstock_category_code").focus();
       return false;
  }
    else if(document.getElementById("ftgl_inv_acc").value=='') {
        alert('No Perkiraan Persediaan harus diisi...');
        document.getElementById("ftgl_inv_acc").focus();
        return false;
    }
    else if(document.getElementById("ftgl_cogs_acc").value=='') {
        alert('No Perkiraan HPP harus diisi...');
        document.getElementById("ftgl_cogs_acc").focus();
        return false;
    }
    else if(document.getElementById("ftgl_sales_acc").value=='') {
        alert('No Perkiraan Penjualan harus diisi...');
        document.getElementById("ftgl_sales_acc").focus();
        return false;
    }
    else if(document.getElementById("ftgl_sales_ret_acc").value=='') {
        alert('No Perkiraan Retur Penjualan harus diisi...');
        document.getElementById("ftgl_sales_ret_acc").focus();
        return false;
    }
    else if(document.getElementById("ftgl_sales_disc_acc").value=='') {
        alert('No Perkiraan Discount Penjualan harus diisi...');
        document.getElementById("ftgl_sales_disc_acc").focus();
        return false;
    }
    else if(ValBarangSetengahJadi1()==false) {
       return false;
    }

    return true;
}

//BAHAN BAKU
function ValTipeBarangBahanBaku() {

  if(document.getElementById("ftstock_group_code").value=='') {
       alert('Kode Tipe Barang harus diisi...');
       document.getElementById("ftstock_group_code").focus();
       return false;
  }
   else if(document.getElementById("ftstock_group_code").value.length!=3) {
       alert('Kode Tipe Barang 3 karakter...');
       document.getElementById("ftstock_group_code").focus();
       return false;
  }
  else if(document.getElementById("ftstock_group_name").value=='') {
       alert('Nama Tipe Barang harus diisi...');
       document.getElementById("ftstock_group_name").focus();
       return false;
  }

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

  return false;
}



function ValNamaBarangBahanBaku() {

  if(document.getElementById("ftstock_group_code").value=='') {
       alert('Kode Nama Barang harus diisi...');
       document.getElementById("ftstock_group_code").focus();
       return false;
  }
   else if(document.getElementById("ftstock_group_code").value.length!=5) {
       alert('Kode Nama Barang 5 karakter...');
       document.getElementById("ftstock_group_code").focus();
       return false;
  }
  else if(document.getElementById("ftstock_group_name").value=='') {
       alert('Nama Barang harus diisi...');
       document.getElementById("ftstock_group_name").focus();
       return false;
  }

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

  return false;
}


// Barang sparepart

function ValGroupBarangSparepart() {

  if(document.getElementById("ftstock_group_code").value=='') {
       alert('Kode Group Barang harus diisi...');
       document.getElementById("ftstock_group_code").focus();
       return false;
  }
  else if(document.getElementById("ftstock_group_name").value=='') {
       alert('Nama Group Barang harus diisi...');
       document.getElementById("ftstock_group_name").focus();
       return false;
  }


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

  return false;
}

function ValBarangSparepart() {

  if(document.getElementById("ftitem_code").value=='') {
       alert('Kode Barang harus diisi...');
       document.getElementById("ftitem_code").focus();
       return false;
  }
  else if(document.getElementById("ftitem_code").value.length==0) {
       alert('Kode Barang harus diisi...');
       document.getElementById("ftitem_code").focus();
       return false;
  }
  else if(document.getElementById("ftitem_code").value.indexOf('&') != -1) {
       alert('Kode Barang Tidak boleh menggunakan Karakter & ...');
       document.getElementById("ftitem_code").focus();
       return false;
  } 
  else if(document.getElementById("ftitem_name").value=='') {
       alert('Nama Barang harus diisi...');
       document.getElementById("ftitem_name").focus();
       return false;
  }
  else if(document.getElementById("ftprint_name").value=='') {
       alert('Nama Cetak harus diisi...');
       document.getElementById("ftprint_name").focus();
       return false;
  }

 else if(document.getElementById("ftstock_category_code").value=='') {
       alert('Kategory harus diisi...');
       document.getElementById("ftstock_category_code").focus();
       return false;
  }
   else if(document.getElementById("hidden_ftstock_group_code").value=='') {
       alert('Group belum valid...');
       document.getElementById("ftstock_group_code").focus();
       return false;
  }
  /*
  else if(document.getElementById("ftweight_code").value=='') {
       alert('Kode berat harus diisi...');
       document.getElementById("ftweight_code").focus();
       return false;
  } */
  else if(document.getElementById("ftuom_code").value=='') {
       alert('Kode satuan harus diisi...');
       document.getElementById("ftuom_code").focus();
       return false;
  }
    else if(document.getElementById("ftgl_inv_acc").value=='') {
        alert('No Perkiraan Persediaan harus diisi...');
        document.getElementById("ftgl_inv_acc").focus();
        return false;
    }
    else if(document.getElementById("ftgl_cogs_acc").value=='') {
        alert('No Perkiraan HPP harus diisi...');
        document.getElementById("ftgl_cogs_acc").focus();
        return false;
    }
    else if(document.getElementById("ftgl_sales_acc").value=='') {
        alert('No Perkiraan Penjualan harus diisi...');
        document.getElementById("ftgl_sales_acc").focus();
        return false;
    }
    else if(document.getElementById("ftgl_sales_ret_acc").value=='') {
        alert('No Perkiraan Retur Penjualan harus diisi...');
        document.getElementById("ftgl_sales_ret_acc").focus();
        return false;
    }
    else if(document.getElementById("ftgl_sales_disc_acc").value=='') {
        alert('No Perkiraan Discount Penjualan harus diisi...');
        document.getElementById("ftgl_sales_disc_acc").focus();
        return false;
    }

  else if(ValBarangSparepart1()==false) {
       return false;
  }

  ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftitem_code').value);
  document.getElementById("ftitem_code").focus();
  return false;
}

function ValBarangSparepart1() {
    var i=document.getElementsByName('ftuom_code_multiD1[]').length;
    for(var j=1;j<i;j++) {

        if  (document.getElementsByName('ftuom_code_multiD1[]')[j].value==document.getElementById('ftuom_code').value) {
            alert('Kode satuan sudah digunakan ');
            document.getElementsByName('ftuom_code_multiD1[]')[j].focus();
            return false;
        } else  if  (document.getElementsByName('ftuom_code_multiD1[]')[j].value=='') {
            alert('Kode Multi Satuan harus diisi ');
            document.getElementsByName('ftuom_code_multiD1[]')[j].focus();
            return false;
        } else  if  (document.getElementsByName('ffformulaD1[]')[j].value.replace(/,/g,'')*1 <= 0) {
            alert('Nominal Formula harus lebih besar dari 0 ');
            document.getElementsByName('ffformulaD1[]')[j].focus();
            return false;
        }

        for(var k=1;k<j;k++) {
            if  (document.getElementsByName('ftuom_code_multiD1[]')[k].value==document.getElementsByName('ftuom_code_multiD1[]')[j].value) {
                alert('Kode satuan sudah digunakan ');
                document.getElementsByName('ftuom_code_multiD1[]')[k].focus();
                return false;
            }
        }
    }

    return true;
}

function UpdateBarangSparepart() {
    if(document.getElementById("ftitem_code").value=='') {
       alert('Kode Barang harus diisi...');
       document.getElementById("ftitem_code").focus();
       return false;
  }
  else if(document.getElementById("ftitem_name").value=='') {
       alert('Nama Barang harus diisi...');
       document.getElementById("ftitem_name").focus();
       return false;
  }
  else if(document.getElementById("ftprint_name").value=='') {
       alert('Nama Cetak harus diisi...');
       document.getElementById("ftprint_name").focus();
       return false;
  }
 else if(document.getElementById("ftuom_code").value=='') {
       alert('Satuan harus diisi...');
       document.getElementById("ftuom_code").focus();
       return false;
  }

 else if(document.getElementById("ftstock_category_code").value=='') {
       alert('Kategory harus diisi...');
       document.getElementById("ftstock_category_code").focus();
       return false;
  }
    else if(document.getElementById("ftgl_inv_acc").value=='') {
        alert('No Perkiraan Persediaan harus diisi...');
        document.getElementById("ftgl_inv_acc").focus();
        return false;
    }
    else if(document.getElementById("ftgl_cogs_acc").value=='') {
        alert('No Perkiraan HPP harus diisi...');
        document.getElementById("ftgl_cogs_acc").focus();
        return false;
    }
    else if(document.getElementById("ftgl_sales_acc").value=='') {
        alert('No Perkiraan Penjualan harus diisi...');
        document.getElementById("ftgl_sales_acc").focus();
        return false;
    }
    else if(document.getElementById("ftgl_sales_ret_acc").value=='') {
        alert('No Perkiraan Retur Penjualan harus diisi...');
        document.getElementById("ftgl_sales_ret_acc").focus();
        return false;
    }
    else if(document.getElementById("ftgl_sales_disc_acc").value=='') {
        alert('No Perkiraan Discount Penjualan harus diisi...');
        document.getElementById("ftgl_sales_disc_acc").focus();
        return false;
    }
    else if(ValBarangSparepart1()==false) {
       return false;
    }

    return true;
}

// Stock Masuk Return
function ValStockMasukService() {
  if(document.getElementById("ftstock_in_return_no").value=='') {
      alert('No. transaksi harus disi...');
      document.getElementById("ftstock_in_return_no").focus();
      return false;
  }

  else  if(document.getElementById("hidden_ftreturn_no").value=='') {
      alert('Customer belum valid ...');
      document.getElementById("ftreturn_no").focus();
      return false;
  }

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

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

  return false;
}

function RevisiStockMasukService() {
 if(document.getElementById("ftstock_in_return_no").value=='') {
      alert('No. transaksi harus disi...');
      document.getElementById("ftstock_in_return_no").focus();
      return false;
  }
 else  if(document.getElementById("hidden_ftsupplier_code").value=='') {
      alert('Supplier belum valid ...');
      document.getElementById("ftsupplier_code").focus();
      return false;
  }
 else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }

  return true;
}

function ValStockMasukReturn() {
  if(document.getElementById("ftstock_in_return_no").value=='') {
      alert('No. transaksi harus disi...');
      document.getElementById("ftstock_in_return_no").focus();
      return false;
  }
 
  else  if(document.getElementById("hidden_ftreturn_no").value=='') {
      alert('Customer belum valid ...');
      document.getElementById("ftreturn_no").focus();
      return false;
  }
 
   else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }
  else if (StockMasukReturnInputQty()==false) {
       return false;
  }

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

  return false;
}

function RevisiStockMasukReturn() {
 if(document.getElementById("ftstock_in_return_no").value=='') {
      alert('No. transaksi harus disi...');
      document.getElementById("ftstock_in_return_no").focus();
      return false;
  }
 else  if(document.getElementById("hidden_ftsupplier_code").value=='') {
      alert('Supplier belum valid ...');
      document.getElementById("ftsupplier_code").focus();
      return false;
  }
 else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }

  return true;
}

function StockMasukReturnInputQty() {
    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++) {
     
          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 (document.getElementsByName('fnqty_baseD0[]')[j].value.replace(/,/g,'')*1<=0) {
               alert('Qty Base tidak boleh 0..');
               document.getElementsByName('fnqty_baseD0[]')[j].focus();
               return false;
          }
        
        }


    return true;
}

function ValHistoryPendingDeliverySchedule() {
  if(document.getElementById("fthistory_pending_delivery_schedule_no").value=='') {
      alert('No. transaksi harus disi...');
      document.getElementById("fthistory_pending_delivery_schedule_no").focus();
      return false;
  }
  else if(document.getElementById("hidden_ftpo_no").value=='') {
      alert('No. PO harus disi...');
      document.getElementById("ftpo_no").focus();
      return false;
  }
  else if(document.getElementById("ftmemo_no").value=='') {
      alert('No. Memo harus disi...');
      document.getElementById("ftmemo_no").focus();
      return false;
  }
   else if(document.getElementById("ftnotes").value=='') {
      alert('Catatan harus disi...');
      document.getElementById("ftnotes").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('fthistory_pending_delivery_schedule_no').value);

  return false;
}


function ValJenisBahan() {

  if(document.getElementById("ftmaterial_type_code").value=='') {
       alert('Kode Bahan harus diisi...');
       document.getElementById("ftmaterial_type_code").focus();
       return false;
  }
  else if(document.getElementById("ftmaterial_type_name").value=='') {
       alert('Nama Bahan harus diisi...');
       document.getElementById("ftmaterial_type_name").focus();
       return false;
  }

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

  return false;
}

//PENGEMBALIAN BARANG
function ValPengembalianBarang() {
  if(document.getElementById("ftfpb_no").value=='') {
      alert('No. transaksi harus disi...');
      document.getElementById("ftfpb_no").focus();
      return false;
  }
   else if(document.getElementById("ftpos_no").value=='') {
      alert('No. POS harus disi...');
      document.getElementById("ftpos_no").focus();
      return false;
  }
   else if(document.getElementById("ftspk_no").value=='') {
      alert('No. SPK harus disi...');
      document.getElementById("ftspk_no").focus();
      return false;
  } 
   else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }
  else if (PengembalianBarangInputQty() ==false) {
       return false;
  }

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

  return false;
}


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

   else if(document.getElementById("ftpos_no").value=='') {
      alert('No. POS harus disi...');
      document.getElementById("ftpos_no").focus();
      return false;
  }
   else if(document.getElementById("ftspk_no").value=='') {
      alert('No. SPK harus disi...');
      document.getElementById("ftspk_no").focus();
      return false;
  } 
   else if(document.getElementsByName('fnindexD0[]').length==1) {
      alert('Detail transaksi belum di input ...');
      return false;
  }
  else if (PengembalianBarangInputQty()==false) {
       return false;
  }


  return true;
}


function PengembalianBarangInputQty() {
    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++) {
        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 harus diisi..');
               document.getElementsByName('fnqtyD0[]')[j].focus();
               return false;
          }
          else if (document.getElementsByName('fnqty_baseD0[]')[j].value.replace(/,/g,'')*1<=0) {
               alert('Qty Base tidak boleh 0..');
               document.getElementsByName('fnqty_baseD0[]')[j].focus();
               return false;
          }
    }

    return true;
}

function ValReturPenjualan()
{

    if(document.getElementById("ftsales_return_no").value=="")
    {
        alert("No transaksi harus diisi...");
        document.getElementById("ftsales_return_no").focus();
        return false;
    }
//        else if(document.getElementById("hidden_ftsales_invoice_no").value=="")
//            {
//                alert("No SI Belum Valid..");
//                document.getElementById('ftsales_invoice_no').focus();
//                return false;
//            }
    else if(document.getElementById("hidden_ftcustomer_code").value=='') {
        alert('Customer belum valid ...');
        document.getElementById("ftcustomer_code").focus();
        return false;
    }
    else if(document.getElementById("ftsales_code").value=='') {
        alert('Sales harus diisi.');
        document.getElementById("ftsales_code").focus();
        return false;
    }
    else if(document.getElementById("fnreturn_type").value=='') {
        alert('Jenis Retur harus diisi.');
        document.getElementById("fnreturn_type").focus();
        return false;
    }
    else if(document.getElementById("ftnotes").value=='') {
        alert('Catatan / Alasan Retur harus diisi.');
        document.getElementById("ftnotes").focus();
        return false;
    }
    else if(SalesReturnInputQty()==false)
    {
        return false;
    }
    
    ajax_do(str_url+'&ajax=1&code=transno&fttrans_no='+document.getElementById("ftsales_return_no").value);
    return false;
}


function RevisiReturPenjualan() {
    if(document.getElementById("ftsales_return_no").value=="")
    {
        alert("No transaksi harus diisi...");
        document.getElementById("ftsales_return_no").focus();
        return false;
    }
    else if(document.getElementById("hidden_ftcustomer_code").value=='') {
        alert('Customer belum valid ...');
        document.getElementById("ftcustomer_code").focus();
        return false;
    }
    else if(document.getElementById("ftsales_code").value=='') {
        alert('Sales harus diisi.');
        document.getElementById("ftsales_code").focus();
        return false;
    }
    else if(document.getElementById("fnreturn_type").value=='') {
        alert('Jenis Retur harus diisi.');
        document.getElementById("fnreturn_type").focus();
        return false;
    }
    else if(document.getElementById("ftnotes").value=='') {
        alert('Catatan / Alasan Retur harus diisi.');
        document.getElementById("ftnotes").focus();
        return false;
    }
    else if(SalesReturnInputQty()==false)
    {
        return false;
    }
    
    return true;
}


function SalesReturnRecalPrice() {
    SalesReturnRecalQty0();

}

function SalesReturnRecalDiscPercent() {
    var fcdiscount=0;
    var fcsub_amount=document.getElementById('fcsub_amount').value.replace(/,/g,'')*1;
    var ffdiscount=document.getElementById('ffdiscount').value;
    //var  fcdiscount=fcsub_amount*ffdiscount/100;
    //fcdiscount=Math.round((fcdiscount)*100/100);
    
    // tier discount 
    var str_ffdiscount = ffdiscount + '';
    var str_ffdiscount = str_ffdiscount.split('+');
    
    for(var i = 0; i < str_ffdiscount.length; i++) {
        // Trim the excess whitespace.
        str_ffdiscount[i] = str_ffdiscount[i].replace(/^\s*/, "").replace(/\s*$/, "");
        fcdiscount = fcdiscount + (fcsub_amount * (str_ffdiscount[i]/100));
        fcsub_amount = fcsub_amount - (fcsub_amount * (str_ffdiscount[i]/100));
    }
   
    document.getElementById('fcdiscount').value=fcdiscount;
    SalesReturnRecalQty0();

}

function SalesReturnRecalDiscRp() {
    var fcsub_amount=document.getElementById('fcsub_amount').value.replace(/,/g,'')*1;
    var fcdiscount=document.getElementById('fcdiscount').value.replace(/,/g,'')*1;
    var ffdiscount=(fcdiscount/(fcsub_amount))*100;
    // ffdiscount=Math.round((ffdiscount)*100/100);
    document.getElementById('ffdiscount').value=ffdiscount;
    SalesReturnRecalQty0();

}

function SalesReturnDiscDetailPercent(index) {
    var fnqtyD=0;
    var fcdiscountD=0;
    
    fnqtyD=document.getElementById('fnqtyD0'+index).value.replace(/,/g,'')*1;

    var fcpriceD=document.getElementById('fcpriceD0'+index).value.replace(/,/g,'')*1;
    var ffdiscountD=document.getElementById('ffdiscountD0'+index).value;
    // var fcdiscountD=(fnqtyD*fcpriceD)*(ffdiscountD/100);
    // fcdiscountD=Math.round((fcdiscountD)*100/100);

    // tier discount 
    var str_ffdiscountD = ffdiscountD + '';
    var str_ffdiscountD = str_ffdiscountD.split('+');

    for(var i = 0; i < str_ffdiscountD.length; i++) {
        // Trim the excess whitespace. 
        str_ffdiscountD[i] = str_ffdiscountD[i].replace(/^\s*/, "").replace(/\s*$/, "");
        fcdiscountD = fcdiscountD + (fcpriceD * (str_ffdiscountD[i]/100));
        fcpriceD = fcpriceD - (fcpriceD * (str_ffdiscountD[i]/100));
      
    }
    fcdiscountD = (fnqtyD * fcdiscountD);

    document.getElementById('fcdiscountD0'+index).value=fcdiscountD;
    SalesReturnRecalQty0();

}

function SalesReturnRecalDiscDetailRp(index) {
    var fnqtyD=0;
    fnqtyD=document.getElementById('fnqtyD0'+index).value.replace(/,/g,'')*1;

    var fcpriceD=document.getElementById('fcpriceD0'+index).value.replace(/,/g,'')*1;
    var fcdiscountD= document.getElementById('fcdiscountD0'+index).value.replace(/,/g,'')*1;
    var ffdiscountD=(fcdiscountD/(fnqtyD*fcpriceD))*100;
    // ffdiscountD=Math.round((ffdiscountD)*100/100);
    document.getElementById('ffdiscountD0'+index).value=ffdiscountD;
    SalesReturnRecalQty0();

}

function SalesReturnRecalQty0() {

    var i=document.getElementsByName('fnindexD0[]').length;
    var fnqtyD=0;
    var fcpriceD=0;
    var ffdiscountD=0;
    var fcdiscountD=0;
    var fcamountD=0;

    var fcpayment_amount=0;
    var fcoutstanding_amount=0;
    var fcsub_amount=0;
    var ffdiscount=0;
    var fcdiscount=0;
    var fcother_cost=0;
    var ffvat=0;
    var fcvat=0;
    var fcamount=0;

    for(var j=1;j<i;j++) {

        fnqtyD=document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1;
          
        fcpriceD=document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1;
        fcdiscountD=document.getElementsByName('fcdiscountD0[]')[j].value.replace(/,/g,'')*1;

        // fcamountD=Math.round(((fnqtyD*fcpriceD )-fcdiscountD)*100/100);
        fcamountD=((fnqtyD*fcpriceD )-fcdiscountD);
        document.getElementsByName('fcamountD0[]')[j].value=fcamountD;
        fcsub_amount+= document.getElementsByName('fcamountD0[]')[j].value.replace(/,/g,'')*1;
        
    }
    
    document.getElementById('fcsub_amount').value=fcsub_amount;
    fcdiscount=document.getElementById('fcdiscount').value.replace(/,/g,'')*1;
    // fcdiscount=Math.round((fcdiscount)*100/100);

    fcother_cost=document.getElementById('fcother_cost').value.replace(/,/g,'')*1;
    // fcother_cost=Math.round((fcother_cost)*100/100);

    ffvat= document.getElementById('ffvat').value.replace(/,/g,'')*1;
    fcvat=(fcsub_amount-fcdiscount+fcother_cost)*ffvat/100;
    // fcvat=Math.round((fcvat)*100/100);

    fcamount=(fcsub_amount-fcdiscount)+fcvat+fcother_cost;
    // fcamount=Math.round((fcamount)*100/100);

    document.getElementById('fcvat').value=fcvat;
    document.getElementById('fcamount').value=fcamount;

    ElementCurrencyALL();
    
    return true;
}

function SalesReturnInputQty() {
    var m="";


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

        if (document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1>0) {
            if ((document.getElementsByName('fnqty_outstanding_siD0[]')[j].value.replace(/,/g,'')*1<document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1) 
                            && (document.getElementById('ftso_no').value != ''))  {
                alert('Qty tidak boleh melebihi jumlah Sisa SO yang belum direturn ...');
                document.getElementsByName('fnqtyD0[]')[j].focus();
                return false;
            }
            else if (document.getElementsByName('ftwarehouse_codeD0[]')[j].value=='') {
                 alert('Gudang harus diisi..');
                 document.getElementsByName('ftwarehouse_codeD0[]')[j].focus();
                 return false;
             }
             else if (document.getElementsByName('ftlocation_codeD0[]')[j].value=='') {
                 alert('Lokasi harus diisi..');
                 document.getElementsByName('ftlocation_codeD0[]')[j].focus();
                 return false;
             }
             else if (document.getElementsByName('ftuom_codeD0[]')[j].value=='') {
                 alert('Satuan harus diisi..');
                 document.getElementsByName('ftftuom_codeD0[]')[j].focus();
                 return false;
             }
             else if (document.getElementsByName('fnqty_baseD0[]')[j].value.replace(/,/g,'')*1<=0) {
                 alert('Qty Base tidak boleh 0..');
                 document.getElementsByName('fnqty_baseD0[]')[j].focus();
                 return false;
             }

             m=1;
        }
    }

    if(m=='') {
          alert('Detail transaksi belum diinput...');
          return false;
    }
    
    return true;
}

function SalesInputQtyX() {
    var m="";


    var i=document.getElementsByName('fnindexD0[]').length;
    for(var j=1;j<i;j++) {
        if (document.getElementsByName('fcpriceD0[]')[j].value.replace(/,/g,'')*1<=0) {
              alert('Harga harus di isi ...');
              document.getElementsByName('fcpriceD0[]')[j].focus();
              return false;

        }
    }

    return true;
}

function FinalSalesReturn() {
  return true;

}

// Module Accounting

// No Perkiraan
function ValNoPerkiraan() {
    var formatcoa = document.getElementById("ftCOA_Code").value;
    formatcoa=formatcoa.substr(4, 1);
    //alert(formatcoa);

    if(document.getElementById("ftCOA_Code").value=='') {
        alert('Kode Perkiraan harus disi...');
        document.getElementById("ftCOA_Code").focus();
        return false;
    } 
    else if(document.getElementById('ftCOA_Name').value=='') {
        alert('Nama Perkiraan harus disi...');
        return false;
    }
    else if(document.getElementById('ftCOA_SubGroup_Code').value=='') { 
        alert('Group Perkiraan harus disi...');
        return false;
    }
    else if (document.getElementById("ftCOA_Code").length == 9) {
        alert('Kode Perkiraan harus 8 digit dengan format XXXX.XXXX');
        return false;
    }
    else if (formatcoa != '.') {
        alert('Kode Perkiraan harus 8 digit dengan format XXXX.XXXX');
        return false;
    }

    ajax_do(str_url + '&ajax=1&code=kodeperkiraan&ftcoa_code=' + document.getElementById('ftCOA_Code').value);
    return false;

}

function ValAsset(){
    if(document.getElementById("ftasset_code").value=='') {
        alert('Kode Asset harus disi...');
        document.getElementById("ftasset_code").focus();
        return false;
    }
    else if(document.getElementsByName('ftasset_name').value=='') {
        alert('Nama Asset harus disi...');
        return false;
    }

  ajax_do(str_url + '&ajax=1&code=kodeasset&ftasset_code=' + document.getElementById('ftasset_code').value);
  return false;
}

function ValKategoriAsset(){
    if(document.getElementById("ftcategory_code").value=='') {
        alert('Kode Kategori harus disi...');
        document.getElementById("ftcategory_code").focus();
        return false;
    }
    else if(document.getElementsByName('ftcategory_name').value=='') {
        alert('Nama Kategori harus disi...');
        return false;
    }

  ajax_do(str_url + '&ajax=1&code=kodekategori&ftcategory_code=' + document.getElementById('ftcategory_code').value);
  return false;
}

function ValPenyusutanAsset(){
  if(document.getElementById("fttrans_code").value=='') {
        alert('Kode Transaksi harus disi...');
        document.getElementById("fttrans_code").focus();
        return false;
  }else if(checkAsset() == false){
    return false;
  }

  ajax_do(str_url + '&ajax=1&code=penyusutan&fttrans_code=' + document.getElementById('fttrans_code').value + '&fdtrans_date=' + document.getElementById('fdtrans_date').value);
  return false;
}


function ValPenyusutanAsset(){
  if(document.getElementById("fttrans_code").value=='') {
        alert('Kode Transaksi harus disi...');
        document.getElementById("fttrans_code").focus();
        return false;
  }else if(checkAsset() == false){
    return false;
  }

  ajax_do(str_url + '&ajax=1&code=penyusutan&fttrans_code=' + document.getElementById('fttrans_code').value + '&fdtrans_date=' + document.getElementById('fdtrans_date').value);
  return false;
}

function checkAsset(){
  var h=-1;
  var i=document.getElementsByName('fnindexD0[]').length - 1;
  var fnd=0;
  var arrAsset=new Array();

  for(j=0; j < i; j++){
    var str=document.getElementsByName('ftasset_codeD0[]')[j].value;    

    if(str == "") h++;
  }

  if(h == i){
    alert('Tidak ada data list yang terpilih.');
    
    return false;
  }
}

function ValSaldoAwalPerkiraan(){
  ajax_do(str_url + '&ajax=1&code=periode&periode=' + document.getElementById('fdperiodesaldo').value);
  return false;
}

function SaldoAwalPerkiraanRecall(){
  var i=document.getElementsByName('fnindexD0[]').length;
  var TotDebit=0;
  var TotKredit=0;

  for(j=0; j < i; j++){
    TotDebit+=document.getElementsByName('fcdebitD0[]')[j].value.replace(/,/g,'')*1;
    TotKredit+=document.getElementsByName('fccreditD0[]')[j].value.replace(/,/g,'')*1;
  }

  document.getElementById('fcdebit_tot').value=TotDebit;
  document.getElementById('fccredit_tot').value=TotKredit;

  ElementCurrencyALL();
}

function ValJurnalUmum(){
  JurnalUmumRecalGrid();
  if(document.getElementById("ftjournal_no").value=='') {
        alert('No. Jurnal harus disi...');
        document.getElementById("ftjournal_no").focus();
        return false;
  }else if(document.getElementById("ftdocument_no").value=='') {
        alert('No. Bukti harus disi...');
        document.getElementById("ftdocument_no").focus();
        return false;
  }else if(document.getElementById('fcdebit').value.replace(/,/g,'')*1 != document.getElementById('fccredit').value.replace(/,/g,'')*1){
        alert('Transaksi belum balance...');
        return false;
  }else if(JurnalUmumGrid() == false){
        alert('Transaksi tidak ada...');
        return false;
  }
  
  ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftjournal_no').value);
  return false;
}

function JurnalUmumRecalGrid(){
  var i=document.getElementsByName('fnindexD0[]').length;
  var TotDebit=0;
  var TotKredit=0;

  for(j=0; j < i; j++){
    TotDebit+=document.getElementsByName('fcdebitD0[]')[j].value.replace(/,/g,'')*1;
    TotKredit+=document.getElementsByName('fccreditD0[]')[j].value.replace(/,/g,'')*1;
  }

  document.getElementById('fcdebit').value=TotDebit;
  document.getElementById('fccredit').value=TotKredit;

  ElementCurrencyALL();
}

function JurnalUmumGrid(){
  var i=document.getElementsByName('fnindexD0[]').length;
  var valgrid=true;

  if(i=0) valgrid=false;
  
  for(j=0; j < i; j++){
    if(document.getElementsByName('ftcoa_codeD0[]')[j].value){
      valgrid=false;
      j=i;
    }
  }

  return valgrid;
}

function RevisiJurnalUmum() {
      JurnalUmumRecalGrid();
      if(document.getElementById("ftjournal_no").value=='') {
            alert('No. Jurnal harus disi...');
            document.getElementById("ftjournal_no").focus();
            return false;
      }else if(document.getElementById("ftdocument_no").value=='') {
            alert('No. Bukti harus disi...');
            document.getElementById("ftdocument_no").focus();
            return false;
      }else if(document.getElementById('fcdebit').value.replace(/,/g,'')*1 != document.getElementById('fccredit').value.replace(/,/g,'')*1){
            alert('Transaksi belum balance...');
            return false;
      }else if(JurnalUmumGrid() == false){
            alert('Transaksi tidak ada...');
            return false;
      }

      return true;
}


function ValTutupBuku(){
    if(document.getElementsByName('fdstart_month_periodD1[]')[1].value=='') {
        alert('Tgl Periode Awal harus ada.');
        document.getElementsByName('fdstart_month_periodD1[]')[1].focus();
        return false;
    } 

  ajax_do(str_url + '&ajax=1&code=transno&fdstart_month_period=' + document.getElementsByName('fdstart_month_periodD1[]')[1]);
  return false;
}


function ValSupport() {
  if(document.getElementById("ftsupport_code").value=='') {
       alert('Kode Support harus diisi...');
       document.getElementById("ftsupport_code").focus();
       return false;
  }
  else if(document.getElementById("ftsupport_name").value=='') {
       alert('Nama Support harus diisi...');
       document.getElementById("ftsupport_name").focus();
       return false;
  }

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

  return false;

}



function ValTrackingReport() {
/*   if(document.getElementById("fttracking_no").value=='') {
       alert('Tracking no harus diisi...');
       document.getElementById("fttracking_no").focus();
       return false;
  }
  else if(document.getElementById("ftsupport_code").value=='') {
       alert('Nama Support harus diisi...');
       document.getElementById("ftsupport_code").focus();
       return false;
  }
   */
    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('fttracking_no').value);
  //ajax_do(str_url + '&ajax=1&code=transno&fttrans_no=' + document.getElementById('ftdo_no').value);
  return false;

}

function ValProjectTracking() {
  if(document.getElementById("fttracking_code").value=='') {
       alert('Nomor Tracking harus diisi...');
       document.getElementById("fttracking_code").focus();
       return false;
  }
    else if(document.getElementById("ftproject_code").value=='') {
       alert('Project harus di pilih...');
       document.getElementById("ftproject_code").focus();
       return false;
    }

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

  return false;	
}

function FinalApproveTracking() {
 if(document.getElementById("fttracking_code").value=='') {
       alert('Project harus di pilih...');
       document.getElementById("fttracking_code").focus();
       return false;
    }
return true;
}


function FinalTracking() {
 if(document.getElementById("fttracking_code").value=='') {
       alert('Project harus di pilih...');
       document.getElementById("fttracking_code").focus();
       return false;
    }
return true;
}

//project tracking
function ValProject() {

    if(document.getElementById("ftproject_code").value=='') {
       alert('Kode Project harus diisi...');
       document.getElementById("ftproject_code").focus();
       return false;
    }
    else if(document.getElementById("ftproject_name").value=='') {
       alert('Nama Project harus diisi...');
       document.getElementById("ftproject_name").focus();
       return false;
    }
    else if(document.getElementById("fnstatus").value=='') {
       alert('status harus di pilih...');
       document.getElementById("fnstatus").focus();
       return false;
	}	
    else if(document.getElementById("fttype_form").value=='') {
       alert('Type Input harus di pilih...');
       document.getElementById("fttype_form").focus();
       return false;
	}
	
    var i=document.getElementsByName('fnindexD0[]').length;
    for(var j=1;j<i;j++) {

       if (document.getElementsByName('ftuser_projectD0[]')[j].value=='') {
             alert('User Name Belum di isi..');
             document.getElementsByName('ftuser_projectD0[]')[j].focus();
             return false;
		}
	}	
	
	
    ajax_do(str_url + '&ajax=1&code=transno&ftproject_code=' + document.getElementById('ftproject_code').value);
    document.getElementById("ftproject_code").focus();
    
  return false;
}

function ValProjectCategory() {

    if(document.getElementById("ftproject_code").value=='') {
       alert('Kode Project harus diisi...');
       document.getElementById("ftproject_code").focus();
       return false;
    }

    ajax_do(str_url + '&ajax=1&code=transno&ftproject_code=' + document.getElementById('ftproject_code').value);
    document.getElementById("ftproject_code").focus();
    
  return false;
}

function Valjenis_aktivitas() {

    if(document.getElementById("ftjenis_aktivitas_code").value=='') {
       alert('Kode jenis aktivitas harus diisi...');
       document.getElementById("ftjenis_aktivitas_code").focus();
       return false;
    }
    else if(document.getElementById("ftpilihan").value=='') {
       alert('pilihan harus diisi...');
       document.getElementById("ftpilihan").focus();
       return false;
    }

    ajax_do(str_url + '&ajax=1&code=transno&ftjenis_aktivitas_code=' + document.getElementById('ftjenis_aktivitas_code').value);
    document.getElementById("ftjenis_aktivitas_code").focus();
    
  return false;
}

function ValAssembly() {
    if(document.getElementById("ftassembly_no").value=='') {
       alert('Nomor assembly harus diisi...');
       document.getElementById("ftassembly_no").focus();
       return false;
    }
    else if(document.getElementById("ftitem_code").value=='') {
       alert('Kode Barang harus diisi...');
       document.getElementById("ftitem_code").focus();
       return false;
    }
    else if(document.getElementById("hidden_ftitem_code").value=='') {
      alert('Kode Barang belum valid ...');
      document.getElementById("ftitem_code").focus();
      return false;
    }
    else if(document.getElementById("fnqty").value==0) {
       alert('Qty harus diisi...');
       document.getElementById("fnqty").focus();
       return false;
    }
    else if(document.getElementById("ftwarehouse_code").value==0) {
       alert('Gudang harus diisi...');
       document.getElementById("ftwarehouse_code").focus();
       return false;
    }
    else if(document.getElementById("ftlocation_code").value==0) {
       alert('Lokasi harus diisi...');
       document.getElementById("ftlocation_code").focus();
       return false;
    }
    
    var i = document.getElementsByName('fnindexD0[]').length;
    var fnqtyD=0;
    for(var j = 1; j < i; j++) {
        fnqtyD=document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1;
        fnqtyAvail=document.getElementsByName('fnqty_availableD0[]')[j].value.replace(/,/g,'')*1;
        
        if (document.getElementsByName('ftitem_codeD0[]')[j].value=='') {
            alert('Kode Barang harus di isi ...');
            document.getElementsByName('ftitem_codeD0[]')[j].focus();
            return false;
        } 
        else if(document.getElementsByName("hidden_ftitem_codeD0[]")[j].value=='') {
            alert('Kode Barang belum valid ...');
            document.getElementsByName("ftitem_codeD0[]")[j].focus();
            return false;
        }
        else if (fnqtyD==0) {
            alert('Qty harus di isi ...');
            document.getElementsByName('fnqtyD0[]')[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 (fnqtyD>fnqtyAvail) {
            alert('Qty tidak boleh lebih besar dari Qty Tersedia ...');
            document.getElementsByName('fnqtyD0[]')[j].focus();
            return false;
        }
    }

    ajax_do(str_url + '&ajax=1&code=transno&ftassembly_no=' + document.getElementById('ftassembly_no').value);
    document.getElementById("ftassembly_no").focus();
    
  return false;
}

function RevisiAssembly() {
    if(document.getElementById("ftassembly_no").value=='') {
       alert('Nomor assembly harus diisi...');
       document.getElementById("ftassembly_no").focus();
       return false;
    }
    else if(document.getElementById("ftitem_code").value=='') {
       alert('Kode Barang harus diisi...');
       document.getElementById("ftitem_code").focus();
       return false;
    }
    else if(document.getElementById("hidden_ftitem_code").value=='') {
      alert('Kode Barang belum valid ...');
      document.getElementById("ftitem_code").focus();
      return false;
    }
    else if(document.getElementById("fnqty").value==0) {
       alert('Qty harus diisi...');
       document.getElementById("fnqty").focus();
       return false;
    }
    else if(document.getElementById("ftwarehouse_code").value==0) {
       alert('Gudang harus diisi...');
       document.getElementById("ftwarehouse_code").focus();
       return false;
    }
    else if(document.getElementById("ftlocation_code").value==0) {
       alert('Lokasi harus diisi...');
       document.getElementById("ftlocation_code").focus();
       return false;
    }
    
    var i = document.getElementsByName('fnindexD0[]').length;
    var fnqtyD=0;
    for(var j = 1; j < i; j++) {
        fnqtyD=document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1;
        
        if (document.getElementsByName('ftitem_codeD0[]')[j].value=='') {
            alert('Kode Barang harus di isi ...');
            document.getElementsByName('ftitem_codeD0[]')[j].focus();
            return false;
        } 
        else if(document.getElementsByName("hidden_ftitem_codeD0[]")[j].value=='') {
            alert('Kode Barang belum valid ...');
            document.getElementsByName("ftitem_codeD0[]")[j].focus();
            return false;
        }
        else if (fnqtyD==0) {
            alert('Qty harus di isi ...');
            document.getElementsByName('fnqtyD0[]')[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;
        }
    }

    return true;
}


function AssemblyRecalQty() {

    if (document.getElementById('fnupdate_price').value == '1') { 
            
        var i=document.getElementsByName('fnindexD0[]').length;

        var fnqtyD=0;
        var fcpriceD=0;
        var fcamountD=0;
        var fctotal=0;

        for(var j=0; j < i; j++) {
            fnqtyD = document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1;
            fcpriceD=document.getElementsByName('fcnet_priceD0[]')[j].value.replace(/,/g,'')*1;
            fcamountD=(fnqtyD*fcpriceD);
            document.getElementsByName('fctotal_priceD0[]')[j].value = fcamountD; 
            fctotal = fctotal + fcamountD;
        }

        //fctotal = parseFloat((fctotal + document.getElementById('fcother_cost').value.replace(/,/g,'')*1).toFixed(2));
        
        document.getElementById('fcnet_price').value = parseFloat(((fctotal / document.getElementById('fnqty').value)+document.getElementById('fcother_cost').value.replace(/,/g,'')*1).toFixed(2));
        ElementCurrencyALL();
    }    
}


function ValDisassembly() {
    fnqty=document.getElementById("fnqty").value.replace(/,/g,'')*1; 
    fnqtyAvail=document.getElementById("fnqty_available").value.replace(/,/g,'')*1; 
        
    if(document.getElementById("ftdisassembly_no").value=='') {
       alert('Nomor disassembly harus diisi...');
       document.getElementById("ftdisassembly_no").focus();
       return false;
    }
    else if(document.getElementById("ftitem_code").value=='') {
       alert('Kode Barang harus diisi...');
       document.getElementById("ftitem_code").focus();
       return false;
    }
    else if(document.getElementById("hidden_ftitem_code").value=='') {
        alert('Kode Barang belum valid ...');
        document.getElementById("ftitem_code").focus();
        return false;
    }
    else if(document.getElementById("fnqty").value==0) {
       alert('Qty harus diisi...');
       document.getElementById("fnqty").focus();
       return false;
    }
    else if(document.getElementById("ftwarehouse_code").value==0) {
       alert('Gudang harus diisi...');
       document.getElementById("ftwarehouse_code").focus();
       return false;
    }
    else if(document.getElementById("ftlocation_code").value==0) {
       alert('Lokasi harus diisi...');
       document.getElementById("ftlocation_code").focus();
       return false;
    } 
    else if (fnqty>fnqtyAvail) {
        alert('Qty tidak boleh lebih besar dari Qty Tersedia ...');
        document.getElementById("fnqty").focus();
        return false;
    }
    
    var i = document.getElementsByName('fnindexD0[]').length;
    var fnqtyD=0;
    for(var j = 1; j < i; j++) {
        fnqtyD=document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1;
                
        if (document.getElementsByName('ftitem_codeD0[]')[j].value=='') {
            alert('Kode Barang harus di isi ...');
            document.getElementsByName('ftitem_codeD0[]')[j].focus();
            return false;
        }
        else if(document.getElementsByName("hidden_ftitem_codeD0[]")[j].value=='') {
            alert('Kode Barang belum valid ...');
            document.getElementsByName("ftitem_codeD0[]")[j].focus();
            return false;
        }
        else if (fnqtyD==0) {
            alert('Qty harus di isi ...');
            document.getElementsByName('fnqtyD0[]')[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;
        }
    }

    ajax_do(str_url + '&ajax=1&code=transno&ftdisassembly_no=' + document.getElementById('ftdisassembly_no').value);
    document.getElementById("ftdisassembly_no").focus();
    
  return false;
}


function RevisiDisassembly() {
    if(document.getElementById("ftdisassembly_no").value=='') {
       alert('Nomor disassembly harus diisi...');
       document.getElementById("ftdisassembly_no").focus();
       return false;
    }
    else if(document.getElementById("ftitem_code").value=='') {
       alert('Kode Barang harus diisi...');
       document.getElementById("ftitem_code").focus();
       return false;
    }
    else if(document.getElementById("hidden_ftitem_code").value=='') {
        alert('Kode Barang belum valid ...');
        document.getElementById("ftitem_code").focus();
        return false;
    }
    else if(document.getElementById("fnqty").value==0) {
       alert('Qty harus diisi...');
       document.getElementById("fnqty").focus();
       return false;
    }
    else if(document.getElementById("ftwarehouse_code").value==0) {
       alert('Gudang harus diisi...');
       document.getElementById("ftwarehouse_code").focus();
       return false;
    }
    else if(document.getElementById("ftlocation_code").value==0) {
       alert('Lokasi harus diisi...');
       document.getElementById("ftlocation_code").focus();
       return false;
    }
    
    var i = document.getElementsByName('fnindexD0[]').length;
    var fnqtyD=0;
    for(var j = 1; j < i; j++) {
        fnqtyD=document.getElementsByName('fnqtyD0[]')[j].value.replace(/,/g,'')*1;
        
        if (document.getElementsByName('ftitem_codeD0[]')[j].value=='') {
            alert('Kode Barang harus di isi ...');
            document.getElementsByName('ftitem_codeD0[]')[j].focus();
            return false;
        }
        else if(document.getElementsByName("hidden_ftitem_codeD0[]")[j].value=='') {
            alert('Kode Barang belum valid ...');
            document.getElementsByName("ftitem_codeD0[]")[j].focus();
            return false;
        }
        else if (fnqtyD==0) {
            alert('Qty harus di isi ...');
            document.getElementsByName('fnqtyD0[]')[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;
        }
    }

    return true;
}


function ValMerk() {

  if(document.getElementById("ftbrand_code").value=='') {
       alert('Kode merk harus diisi...');
       document.getElementById("ftbrand_code").focus();
       return false;
  }
  else if(document.getElementById("ftbrand_name").value=='') {
       alert('Nama merk harus diisi...');
       document.getElementById("ftbrand_name").focus();
       return false;
  }

  ajax_do(str_url+'&ajax=1&code=transno&fttrans_no='+document.getElementById('ftbrand_code').value);
  document.getElementById("ftbrand_code").focus();
  return false;
}

function ValMobil() {

  if(document.getElementById("ftcar_code").value=='') {
       alert('Kode mobil harus diisi...');
       document.getElementById("ftcar_code").focus();
       return false;
  }
  else if(document.getElementById("ftcar_name").value=='') {
       alert('Nama mobil harus diisi...');
       document.getElementById("ftcar_name").focus();
       return false;
  }
  else if(document.getElementById("ftbrand_code").value=='') {
       alert('Kode merk harus diisi...');
       document.getElementById("ftbrand_code").focus();
       return false;
  }

  ajax_do(str_url+'&ajax=1&code=transno&fttrans_no='+document.getElementById('ftcar_code').value);
  document.getElementById("ftcar_code").focus();
  return false;
}

function ValSalesman() {

    if(document.getElementById("ftsales_code").value=='') {
         alert('Kode salesman harus diisi...');
         document.getElementById("ftsales_code").focus();
         return false;
    }
    else if(document.getElementById("ftsales_name").value=='') {
         alert('Nama salesman harus diisi...');
         document.getElementById("ftsales_name").focus();
         return false;
    }
    /* else if(document.getElementById("ffcommission").value==0) {
         alert('Komisi harus diisi...');
         document.getElementById("ffcommission").focus();
         return false;
    } */
    else if(document.getElementById("fnstatus").value=='') {
         alert('Status harus dipilih...');
         document.getElementById("fnstatus").focus();
         return false;
    }

    ajax_do(str_url+'&ajax=1&code=transno&fttrans_no='+document.getElementById('ftsales_code').value);
    document.getElementById("ftsales_code").focus();
    return false;
}