You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

250 lines
8.0 KiB

$(document).ready(function () {
$("#" + mId + "pCountry").on("change", function () {
ClearCalculatedAmount();
PcountryOnChange('c', "");
});
$("#btnCalculate").on("click", function () {
CalculateTxn();
});
$("#" + mId + "bySendAmt").on("click", function () {
$("#" + mId + "txtCollAmt").prop("disabled", false);
$("#" + mId + "txtPayAmt").prop("disabled", true);
$("#" + mId + "txtPayAmt").val('');
});
$("#" + mId + "byPayOutAmt").on("click", function () {
$("#" + mId + "txtPayAmt").prop("disabled", false);
$("#" + mId + "txtCollAmt").prop("disabled", true);
$("#" + mId + "txtCollAmt").val('');
});
$("#" + mId + "pMode").on("change", function () {
ClearCalculatedAmount();
});
});
function CalculateTxn(amt, obj, isManualSc) {
var collAmt = parseFloat($("#" + mId + "txtCollAmt").val().replace(',', '').replace(',', '').replace(',', ''));
if (isManualSc === '' || isManualSc === undefined) {
isManualSc = 'N';
}
if (isManualSc === 'N') {
if (obj === '' || obj === null || obj == undefined) {
if (document.getElementById(mId + "txtPayAmt").disabled) {
obj = 'cAmt';
amt = GetValue(mId + "txtCollAmt");
}
else {
obj = 'pAmt';
amt = GetValue(mId + "txtPayAmt");
}
}
}
else {
obj = $("#" + mId + "hddCalcBy").val();
if (obj === 'cAmt') {
amt = GetValue(mId + "txtCollAmt");
}
else {
amt = GetValue(mId + "txtPayAmt");
}
}
var pCountry = GetValue(mId + "pCountry");
var pCountrytxt = $("#" + mId + "pCountry option:selected").text();
var pMode = GetValue(mId + "pMode");
var pModetxt = $("#" + mId + "pMode option:selected").text();
if (pCountry === "" || pCountry === null || pCountry === undefined) {
alert("Please choose payout country");
GetElement(mId + "pCountry").focus();
return false;
}
if (pMode === "" || pMode === null || pMode === undefined) {
alert("Please choose payment mode");
GetElement(mId + "pMode").focus();
return false;
}
collAmt = GetValue(mId + "txtCollAmt");
if (obj === "cAmt") {
collAmt = amt;
payAmt = 0;
}
if (obj === "pAmt") {
payAmt = amt;
collAmt = 0;
}
var payCurr = $("#" + mId + "pCurrDdl").val();
var collCurr = 'JPY';
var sc = $("#" + mId + "lblServiceChargeAmt").val();
if (pCountry === "203" && payCurr === "USD") {
if ((pMode === "1" && pAgent !== 2091) || (pMode !== "12" && pAgent !== 2091)) {
alert('USD receiving is only allow for Door to Door');
ClearCalculatedAmount();
return false;
}
}
var collectAmount = Number($("#" + mId + "txtCollAmt").val());
var payoutAmount = Number($("#" + mId + "txtPayAmt").val());
var payoutPartner = $("#" + mId + "hddPayoutPartner").val();
var IsExrateFromPartner = $("#" + mId + "hddFetchExrateFromPartner").val();
var PCountryCode = $("#" + mId + "hddPCountryCode").val();
if (collectAmount <= 0 && payoutAmount <= 0) {
return;
}
$("#" + mId + "hddCalcBy").val(obj);
var dataToSend = {
MethodName: 'CalculateTxn', pCountry: pCountry, pCountrytxt: pCountrytxt, pMode: pMode,
collAmt: collAmt, payAmt: payAmt, payCurr: payCurr, collCurr: collCurr
, pModetxt: pModetxt, isManualSc: isManualSc
, sc: sc, payoutPartner: payoutPartner, IsExrateFromPartner: IsExrateFromPartner, PCountryCode: PCountryCode
};
var options =
{
url: '',
data: dataToSend,
dataType: 'JSON',
type: 'POST',
async: true,
success: function (response) {
ParseCalculateData(response, obj);
}
};
$.ajax(options);
$("#DivLoad").hide();
return true;
}
function PcountryOnChange(obj, pmode, pAgentSelected = "") {
var pCountry = $("#" + mId + "pCountry").val();
if (pCountry === "" || pCountry === null)
return;
var method = "";
if (obj === 'c') {
method = "PaymentModePcountry";
}
if (obj === 'pcurr') {
method = "PCurrPcountry";
}
var country = $("#" + mId + "pCountry option:selected ").text();
var dataToSend = { MethodName: method, pCountry: pCountry };
var options =
{
url: '',
data: dataToSend,
dataType: 'JSON',
type: 'POST',
async: true,
success: function (response) {
if (obj === 'c') {
LoadPayMode(response, document.getElementById(mId + "pMode"), 'pcurr', "", pmode);
}
else if (obj === 'pcurr') {
if (response === "")
return false;
$("#" + mId + "lblPayCurr").text(response[0].currencyCode);
$("#" + mId + "lblExCurr").text(response[0].currencyCode);
return true;
}
return true;
},
error: function (result) {
alert("Due to unexpected errors we were unable to load data");
}
};
$.ajax(options);
}
function LoadPayMode(response, myDDL, recall, selectField, obj) {
var data = response;
$(myDDL).empty();
var option;
if (selectField !== "" && selectField !== undefined) {
option = document.createElement("option");
option.text = selectField;
option.value = "";
myDDL.options.add(option);
}
for (var i = 0; i < data.length; i++) {
option = document.createElement("option");
option.text = data[i].typeTitle;
option.value = data[i].serviceTypeId;
try {
myDDL.options.add(option);
}
catch (e) {
alert(e);
}
}
if (recall === 'pcurr') {
SetDDLTextSelected(mId + "pMode", obj);
}
}
function SetDDLTextSelected(ddl, selectText) {
$("#" + ddl + " option").each(function () {
if ($(this).text() === $.trim(selectText)) {
$(this).prop('selected', true);
return;
}
});
}
function ParseCalculateData(response, amtType) {
debugger
var data = response;
if (data[0].ErrCode === '1') {
alert(data[0].Msg);
ClearCalculatedAmount();
return;
}
$("#" + mId + "lblSendAmt").text(parseFloat(Number(data[0].sAmt).toFixed(3))); //
$("#" + mId + "lblExRate").text(roundNumber(data[0].exRate, 8));
$("#" + mId + "lblPayCurr").text(data[0].pCurr);
$("#" + mId + "lblExCurr").text(data[0].pCurr);
$("#" + mId + "txtPayAmt").val(data[0].pAmt);
$("#" + mId + "lblServiceChargeAmt").text(parseFloat(data[0].scCharge).toFixed(0));
SetValueById(mId + "txtCollAmt", parseFloat(Number(data[0].collAmt).toFixed(3)), ""); //
SetValueById(mId + "lblSendAmt", parseFloat(Number(data[0].sAmt).toFixed(3)), ""); //
}
function ClearCalculatedAmount() {
$("#" + mId + "txtCollAmt").val('');
$("#" + mId + "txtPayAmt").val('');
$("#" + mId + "lblExCurr").text('');
$("#" + mId + "lblSendAmt").text('0.00');
$("#" + mId + "lblServiceChargeAmt").text('0.00');
$("#" + mId + "lblExRate").text('0.00');
$("#" + mId + "lblPayCurr").text('');
}
function ClearTxnData() {
ClearCalculatedAmount();
$("#" + mId + "pCountry").val('');
$("#" + mId + "pMode").val('');
}
function roundNumber(rnum, rlength) { // Arguments: number to round, number of decimal places
var newnumber = Math.round(rnum * Math.pow(10, rlength)) / Math.pow(10, rlength);
return parseFloat(newnumber); // Output the result to the form field (change for your purposes)
}