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.

221 lines
8.3 KiB

  1. using Newtonsoft.Json;
  2. using Swift.API.Common;
  3. using Swift.API.ThirdPartyApiServices;
  4. using Swift.DAL.BL.Remit.Transaction;
  5. using Swift.DAL.Remittance.CustomerDeposits;
  6. using Swift.DAL.SwiftDAL;
  7. using Swift.web.Library;
  8. using System;
  9. using System.Data;
  10. using System.Threading.Tasks;
  11. namespace Swift.web.Remit.Transaction.ApproveTxn
  12. {
  13. public partial class Manage : System.Web.UI.Page
  14. {
  15. private const string ViewFunctionId = "20122800";
  16. private readonly StaticDataDdl _sdd = new StaticDataDdl();
  17. private readonly ApproveTransactionDao atd = new ApproveTransactionDao();
  18. private readonly CustomerDepositDao _dao = new CustomerDepositDao();
  19. protected void Page_Load(object sender, EventArgs e)
  20. {
  21. Authenticate();
  22. // GetStatic.AttachConfirmMsg(ref btnApprove, "Are you sure to APPROVE this transaction?");
  23. if (!IsPostBack)
  24. {
  25. }
  26. LoadTransaction();
  27. if (GetRequest() == "v")
  28. {
  29. btnApprove.Text = "Verify";
  30. GetStatic.AttachConfirmMsg(ref btnApprove, "Are you sure to verify this transaction?");
  31. }
  32. else
  33. {
  34. GetStatic.AttachConfirmMsg(ref btnApprove, "Are you sure to approve this transaction?");
  35. }
  36. }
  37. private void Authenticate()
  38. {
  39. _sdd.CheckAuthentication(ViewFunctionId);
  40. }
  41. private void LoadTransaction()
  42. {
  43. string tranNo = GetTranNo();
  44. ucTran.SearchData(tranNo, "", "", "", "APPROVE", "ADMIN: VIEW TXN TO APPROVE");
  45. ucTran.isFromApproveTxn = "Y";
  46. divTranDetails.Visible = ucTran.TranFound;
  47. if (!ucTran.TranFound)
  48. {
  49. divControlno.InnerHtml = "<h2>No Transaction Found</h2>";
  50. return;
  51. }
  52. }
  53. protected string GetTranNo()
  54. {
  55. return GetStatic.ReadQueryString("id", "");
  56. }
  57. protected string GetRequest()
  58. {
  59. return GetStatic.ReadQueryString("requestFrom", "");
  60. }
  61. private void Approve()
  62. {
  63. DbResult _dbRes = atd.GetTxnApproveDataIMEPay(GetStatic.GetUser(), GetTranNo());
  64. if (_dbRes.ErrorCode != "0")
  65. {
  66. GetStatic.PrintMessage(Page, _dbRes);
  67. return;
  68. }
  69. if (_dbRes.Extra2 == "True")//is realtime
  70. {
  71. SendTransactionServices _tpSend = new SendTransactionServices();
  72. string ProcessId = Guid.NewGuid().ToString().Replace("-", "") + ":" + _dbRes.Extra1 + ":releaseTxn";
  73. var result = _tpSend.ReleaseTransaction(new TFReleaseTxnRequest()
  74. {
  75. TfPin = _dbRes.Id,
  76. TxnId = _dbRes.Extra,
  77. RequestBy = GetStatic.GetUser(),
  78. ProviderId = _dbRes.Extra1,
  79. ProcessId = ProcessId.Substring(ProcessId.Length - 40, 40)
  80. });
  81. _dbRes.ErrorCode = result.ResponseCode;
  82. _dbRes.Msg = result.Msg;
  83. _dbRes.Id = "";
  84. if (_dbRes.ErrorCode != "0")
  85. {
  86. GetStatic.AlertMessage(Page, _dbRes.ErrorCode + " " + _dbRes.Msg);
  87. GetStatic.CallJSFunction(Page, "window.returnValue = true; window.close();");
  88. LoadTransaction();
  89. return;
  90. }
  91. else
  92. {
  93. var dr = atd.ApproveHoldedTXN(GetStatic.GetUser(), GetTranNo());
  94. GetStatic.AlertMessage(Page, dr.Msg);
  95. if (dr.ErrorCode.Equals("0"))
  96. {
  97. GetStatic.CallJSFunction(Page, "window.returnValue = true; window.close();");
  98. LoadTransaction();
  99. return;
  100. }
  101. }
  102. }
  103. else
  104. {
  105. var dr = atd.ApproveHoldedTXN(GetStatic.GetUser(), GetTranNo());
  106. // SendApprovalMailToCustomers();
  107. GetStatic.AlertMessage(Page, dr.Msg);
  108. if (dr.ErrorCode.Equals("0"))
  109. {
  110. //GetStatic.CallJSFunction(Page, "window.returnValue = true; window.close();");
  111. Response.Redirect("/Remit/Transaction/ApproveTxn/holdTxnListMobile.aspx");
  112. LoadTransaction();
  113. return;
  114. }
  115. }
  116. }
  117. private void Verify()
  118. {
  119. var tranId = GetTranNo();
  120. DbResult _res = new DbResult();
  121. if (!string.IsNullOrEmpty(tranId))
  122. {
  123. _res = _dao.VerifyCashCollect(GetStatic.GetUser(), tranId);
  124. }
  125. else
  126. {
  127. GetStatic.AlertMessage(this, "Please choose at least on record!");
  128. }
  129. GetStatic.AlertMessage(Page, _res.Msg);
  130. if (_res.ErrorCode.Equals("0"))
  131. {
  132. GetStatic.CallJSFunction(Page, "window.returnValue = true; window.close();");
  133. LoadTransaction();
  134. }
  135. }
  136. private void SendApprovalMailToCustomers()
  137. {
  138. Task.Factory.StartNew(() => { SendEmail(); });
  139. }
  140. private void SendEmail()
  141. {
  142. DataTable mailDetails = atd.GetMailDetails("system");
  143. if (mailDetails.Rows.Count == 0 || mailDetails == null)
  144. {
  145. return;
  146. }
  147. foreach (DataRow item in mailDetails.Rows)
  148. {
  149. string res = SendEmailNotification(item);
  150. if (res != "Mail Send")
  151. {
  152. atd.ErrorEmail("system", item["rowId"].ToString());
  153. }
  154. }
  155. }
  156. private string SendEmailNotification(DataRow item)
  157. {
  158. string msgSubject = "JME Control No.: " + item["controlNoDec"].ToString();
  159. string toEmailId = item["createdBy"].ToString();
  160. string msgBody = "Dear " + item["SenderName"];
  161. msgBody += "<br/><br/>This is to acknowledge that you have successfully completed your transaction through JME Online Remit System.";
  162. msgBody += "<br/><br/>Kindly take a note of the following transaction details for your record.";
  163. msgBody += "<br/><br/>JME Number: " + item["controlNoDec"].ToString();
  164. msgBody += "<br/>Amount sent: " + item["collCurr"].ToString() + " " + GetStatic.ShowDecimal(item["tAmt"].ToString());
  165. msgBody += "<br/>Payment method: " + item["paymentMethod"].ToString();
  166. msgBody += "<br/>Pay-out country: " + item["pcountry"].ToString();
  167. msgBody += "<br/>Account holding bank Name: " + item["payountBankOrAgent"].ToString();
  168. msgBody += "<br/>Account number: " + item["accNo"].ToString();
  169. msgBody += "<br/>Account holder’s name: " + item["receiverName"].ToString();
  170. msgBody += "<br/>Payout Amount: " + item["payoutCurr"].ToString() + " " + GetStatic.ShowDecimal(item["pAmt"].ToString());
  171. msgBody += "<br/><br/>You can keep track of your payment status by https://online.gmeremit.com/.";
  172. msgBody +=
  173. "<br><br>If you need further assistance kindly email us at support@jme.com.np or call us at 03-5475-3913. or visit our website <a href=\"http://japanremit.com/\">japanremit.com</a>";
  174. msgBody +=
  175. "<br><br><br>We look forward to provide you excellent service.";
  176. msgBody +=
  177. "<br><br>Thank You.";
  178. msgBody +=
  179. "<br><br><br>Regards,";
  180. msgBody +=
  181. "<br>JME Online Team";
  182. msgBody +=
  183. "<br>Tokyo, Japan ";
  184. msgBody +=
  185. "<br>Phone number 15886864 ";
  186. SmtpMailSetting mail = new SmtpMailSetting
  187. {
  188. MsgBody = msgBody,
  189. MsgSubject = msgSubject,
  190. ToEmails = toEmailId
  191. };
  192. return mail.SendSmtpMail(mail);
  193. }
  194. protected void btnApprove_Click(object sender, EventArgs e)
  195. {
  196. if (GetRequest() == "v")
  197. {
  198. Verify();
  199. }
  200. else
  201. {
  202. Approve();
  203. }
  204. }
  205. }
  206. }