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

4 years ago
  1. $(document).ready(function () {
  2. $("#" + mId + "pCountry").on("change", function () {
  3. ClearCalculatedAmount();
  4. PcountryOnChange('c', "");
  5. });
  6. $("#btnCalculate").on("click", function () {
  7. CalculateTxn();
  8. });
  9. $("#" + mId + "bySendAmt").on("click", function () {
  10. $("#" + mId + "txtCollAmt").prop("disabled", false);
  11. $("#" + mId + "txtPayAmt").prop("disabled", true);
  12. $("#" + mId + "txtPayAmt").val('');
  13. });
  14. $("#" + mId + "byPayOutAmt").on("click", function () {
  15. $("#" + mId + "txtPayAmt").prop("disabled", false);
  16. $("#" + mId + "txtCollAmt").prop("disabled", true);
  17. $("#" + mId + "txtCollAmt").val('');
  18. });
  19. $("#" + mId + "pMode").on("change", function () {
  20. ClearCalculatedAmount();
  21. });
  22. });
  23. function CalculateTxn(amt, obj, isManualSc) {
  24. var collAmt = parseFloat($("#" + mId + "txtCollAmt").val().replace(',', '').replace(',', '').replace(',', ''));
  25. if (isManualSc === '' || isManualSc === undefined) {
  26. isManualSc = 'N';
  27. }
  28. if (isManualSc === 'N') {
  29. if (obj === '' || obj === null || obj == undefined) {
  30. if (document.getElementById(mId + "txtPayAmt").disabled) {
  31. obj = 'cAmt';
  32. amt = GetValue(mId + "txtCollAmt");
  33. }
  34. else {
  35. obj = 'pAmt';
  36. amt = GetValue(mId + "txtPayAmt");
  37. }
  38. }
  39. }
  40. else {
  41. obj = $("#" + mId + "hddCalcBy").val();
  42. if (obj === 'cAmt') {
  43. amt = GetValue(mId + "txtCollAmt");
  44. }
  45. else {
  46. amt = GetValue(mId + "txtPayAmt");
  47. }
  48. }
  49. var pCountry = GetValue(mId + "pCountry");
  50. var pCountrytxt = $("#" + mId + "pCountry option:selected").text();
  51. var pMode = GetValue(mId + "pMode");
  52. var pModetxt = $("#" + mId + "pMode option:selected").text();
  53. if (pCountry === "" || pCountry === null || pCountry === undefined) {
  54. alert("Please choose payout country");
  55. GetElement(mId + "pCountry").focus();
  56. return false;
  57. }
  58. if (pMode === "" || pMode === null || pMode === undefined) {
  59. alert("Please choose payment mode");
  60. GetElement(mId + "pMode").focus();
  61. return false;
  62. }
  63. collAmt = GetValue(mId + "txtCollAmt");
  64. if (obj === "cAmt") {
  65. collAmt = amt;
  66. payAmt = 0;
  67. }
  68. if (obj === "pAmt") {
  69. payAmt = amt;
  70. collAmt = 0;
  71. }
  72. var payCurr = $("#" + mId + "pCurrDdl").val();
  73. var collCurr = 'JPY';
  74. var sc = $("#" + mId + "lblServiceChargeAmt").val();
  75. if (pCountry === "203" && payCurr === "USD") {
  76. if ((pMode === "1" && pAgent !== 2091) || (pMode !== "12" && pAgent !== 2091)) {
  77. alert('USD receiving is only allow for Door to Door');
  78. ClearCalculatedAmount();
  79. return false;
  80. }
  81. }
  82. var collectAmount = Number($("#" + mId + "txtCollAmt").val());
  83. var payoutAmount = Number($("#" + mId + "txtPayAmt").val());
  84. var payoutPartner = $("#" + mId + "hddPayoutPartner").val();
  85. var IsExrateFromPartner = $("#" + mId + "hddFetchExrateFromPartner").val();
  86. var PCountryCode = $("#" + mId + "hddPCountryCode").val();
  87. if (collectAmount <= 0 && payoutAmount <= 0) {
  88. return;
  89. }
  90. $("#" + mId + "hddCalcBy").val(obj);
  91. var dataToSend = {
  92. MethodName: 'CalculateTxn', pCountry: pCountry, pCountrytxt: pCountrytxt, pMode: pMode,
  93. collAmt: collAmt, payAmt: payAmt, payCurr: payCurr, collCurr: collCurr
  94. , pModetxt: pModetxt, isManualSc: isManualSc
  95. , sc: sc, payoutPartner: payoutPartner, IsExrateFromPartner: IsExrateFromPartner, PCountryCode: PCountryCode
  96. };
  97. var options =
  98. {
  99. url: '',
  100. data: dataToSend,
  101. dataType: 'JSON',
  102. type: 'POST',
  103. async: true,
  104. success: function (response) {
  105. ParseCalculateData(response, obj);
  106. }
  107. };
  108. $.ajax(options);
  109. $("#DivLoad").hide();
  110. return true;
  111. }
  112. function PcountryOnChange(obj, pmode, pAgentSelected = "") {
  113. var pCountry = $("#" + mId + "pCountry").val();
  114. if (pCountry === "" || pCountry === null)
  115. return;
  116. var method = "";
  117. if (obj === 'c') {
  118. method = "PaymentModePcountry";
  119. }
  120. if (obj === 'pcurr') {
  121. method = "PCurrPcountry";
  122. }
  123. var country = $("#" + mId + "pCountry option:selected ").text();
  124. var dataToSend = { MethodName: method, pCountry: pCountry };
  125. var options =
  126. {
  127. url: '',
  128. data: dataToSend,
  129. dataType: 'JSON',
  130. type: 'POST',
  131. async: true,
  132. success: function (response) {
  133. if (obj === 'c') {
  134. LoadPayMode(response, document.getElementById(mId + "pMode"), 'pcurr', "", pmode);
  135. }
  136. else if (obj === 'pcurr') {
  137. if (response === "")
  138. return false;
  139. $("#" + mId + "lblPayCurr").text(response[0].currencyCode);
  140. $("#" + mId + "lblExCurr").text(response[0].currencyCode);
  141. return true;
  142. }
  143. return true;
  144. },
  145. error: function (result) {
  146. alert("Due to unexpected errors we were unable to load data");
  147. }
  148. };
  149. $.ajax(options);
  150. }
  151. function LoadPayMode(response, myDDL, recall, selectField, obj) {
  152. var data = response;
  153. $(myDDL).empty();
  154. var option;
  155. if (selectField !== "" && selectField !== undefined) {
  156. option = document.createElement("option");
  157. option.text = selectField;
  158. option.value = "";
  159. myDDL.options.add(option);
  160. }
  161. for (var i = 0; i < data.length; i++) {
  162. option = document.createElement("option");
  163. option.text = data[i].typeTitle;
  164. option.value = data[i].serviceTypeId;
  165. try {
  166. myDDL.options.add(option);
  167. }
  168. catch (e) {
  169. alert(e);
  170. }
  171. }
  172. if (recall === 'pcurr') {
  173. SetDDLTextSelected(mId + "pMode", obj);
  174. }
  175. }
  176. function SetDDLTextSelected(ddl, selectText) {
  177. $("#" + ddl + " option").each(function () {
  178. if ($(this).text() === $.trim(selectText)) {
  179. $(this).prop('selected', true);
  180. return;
  181. }
  182. });
  183. }
  184. function ParseCalculateData(response, amtType) {
  185. debugger
  186. var data = response;
  187. if (data[0].ErrCode === '1') {
  188. alert(data[0].Msg);
  189. ClearCalculatedAmount();
  190. return;
  191. }
  192. $("#" + mId + "lblSendAmt").text(parseFloat(Number(data[0].sAmt).toFixed(3))); //
  193. $("#" + mId + "lblExRate").text(roundNumber(data[0].exRate, 8));
  194. $("#" + mId + "lblPayCurr").text(data[0].pCurr);
  195. $("#" + mId + "lblExCurr").text(data[0].pCurr);
  196. $("#" + mId + "txtPayAmt").val(data[0].pAmt);
  197. $("#" + mId + "lblServiceChargeAmt").text(parseFloat(data[0].scCharge).toFixed(0));
  198. SetValueById(mId + "txtCollAmt", parseFloat(Number(data[0].collAmt).toFixed(3)), ""); //
  199. SetValueById(mId + "lblSendAmt", parseFloat(Number(data[0].sAmt).toFixed(3)), ""); //
  200. }
  201. function ClearCalculatedAmount() {
  202. $("#" + mId + "txtCollAmt").val('');
  203. $("#" + mId + "txtPayAmt").val('');
  204. $("#" + mId + "lblExCurr").text('');
  205. $("#" + mId + "lblSendAmt").text('0.00');
  206. $("#" + mId + "lblServiceChargeAmt").text('0.00');
  207. $("#" + mId + "lblExRate").text('0.00');
  208. $("#" + mId + "lblPayCurr").text('');
  209. }
  210. function ClearTxnData() {
  211. ClearCalculatedAmount();
  212. $("#" + mId + "pCountry").val('');
  213. $("#" + mId + "pMode").val('');
  214. }
  215. function roundNumber(rnum, rlength) { // Arguments: number to round, number of decimal places
  216. var newnumber = Math.round(rnum * Math.pow(10, rlength)) / Math.pow(10, rlength);
  217. return parseFloat(newnumber); // Output the result to the form field (change for your purposes)
  218. }