public string confirmPaymentFkey(ListInvoice lsInv) { Company _currentCompany = ((EInvoiceContext)FXContext.Current).CurrentCompany; int comID = _currentCompany.id; if (_currentCompany == null) { return("ERlR:7"); //username khong phu hop - ko tim thay company phu hop voi [username] } List <IInvoice> invLst = new List <IInvoice>(); string[] invTokens = lsInv.lsFkey.Split('_'); IPublishInvoiceService _PubInvSrv = IoC.Resolve <IPublishInvoiceService>(); PublishInvoice pubinv = _PubInvSrv.GetFirst(comID, new int[] { 1, 2 }); string pattern = ""; if (pubinv != null) { pattern = pubinv.InvPattern; _PubInvSrv.UnbindSession(pubinv); } IInvoiceService invSrv = InvServiceFactory.GetService(pattern, comID); try { invLst = (List <IInvoice>)invSrv.GetByFkey(comID, invTokens); if (invTokens.Length != invLst.Count) { return("ERR:6"); } invLst.RemoveAll(inv => inv.PaymentStatus == Payment.Paid || (inv.Status != InvoiceStatus.SignedInv && inv.Status != InvoiceStatus.AdjustedInv)); } catch (Exception ex) { log.Error("confirmPaymentFkey " + ex); return("ERR:6 " + ex.Message); } if (invLst.Count == 0) { return("ERR:13"); // hoa đơn đã gạch nợ/bỏ gạch nợ rồi } string strNote = " || Thực hiện gạch nợ: Người gạch nợ: " + HttpContext.Current.User.Identity.Name + " Ngày gạch nợ: " + DateTime.Now.ToString(); if (invSrv.ConfirmPayment(invLst, strNote)) { //thuc hien deliveriy IDeliver _deliver = _currentCompany.Config.Keys.Contains("IDeliver") ? IoC.Resolve(Type.GetType(_currentCompany.Config["IDeliver"])) as IDeliver : null; if (_deliver != null) { _deliver.Deliver(invLst.ToArray(), _currentCompany); } return("OK:"); } return("ERR:7"); //sao lai khong thanh toán được ? }
public ActionResult PaymentInvoice(string[] cbid, string hdPattern) { Company currentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany; int[] IDs = (from s in cbid select Convert.ToInt32(s)).ToArray(); if (IDs.Length <= 0) { Messages.AddErrorFlashMessage("Chưa chọn hóa đơn thanh toán."); return(RedirectToAction("Index")); } IInvoiceService IInvSrv = InvServiceFactory.GetService(hdPattern, currentCom.id); string strNote = "Thực hiện gạch nợ: Người gạch nợ: " + HttpContext.User.Identity.Name + " Ngày gạch nợ: " + DateTime.Now.ToString(); IList <IInvoice> lstInvoice = IInvSrv.GetByID(currentCom.id, IDs); if (IInvSrv.ConfirmPayment(lstInvoice, strNote)) { Messages.AddFlashMessage(Resources.Message.Pay_MesSuccess); //if (currentCom.Config.Keys.Contains("PaymentToDeliver")) // if (currentCom.Config["PaymentToDeliver"] == "1") // { // //IDeliver _deliver = IoC.Resolve<IDeliver>(); // if (currentCom.Config.Keys.Contains("IDeliver")) // _deliver = InvServiceFactory.GetDeliver(currentCom.Config["IDeliver"]); // else _deliver = IoC.Resolve<IDeliver>(); // _deliver.Deliver(lstInvoice.ToArray(), currentCom); // } log.Info("Change Payment Status EInvoice by: " + HttpContext.User.Identity.Name + " Info-- ID: " + string.Join(";", IDs)); return(RedirectToAction("Index")); } else { log.Error("Change Payment Status EInvoice error: " + Resources.Message.Pay_MesUnsuccess); Messages.AddErrorFlashMessage(Resources.Message.Pay_MesUnsuccess); return(RedirectToAction("Index")); } }
private PaymentTransaction paymentViaBlock(byte[] file) { //gach no theo lo Company currentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany; PaymentTransaction mTran = new PaymentTransaction(); mTran.Data = file; mTran.ComID = currentCom.id; mTran.id = Guid.NewGuid(); mTran.AccountName = HttpContext.User.Identity.Name; mTran.Status = PaymentTransactionStatus.NewUpload; string message = ""; IPaymentExcel paymentExcelSrv = IoC.Resolve <IPaymentExcel>(); List <string> lstFkey = paymentExcelSrv.GetFkey(file, mTran.id.ToString(), out message); if (lstFkey == null) { mTran.Messages = message; mTran.Status = PaymentTransactionStatus.Failed; return(mTran); } List <IInvoice> invLst = new List <IInvoice>(); PublishInvoice pub = DefaultPublishInvoice(currentCom.id); IInvoiceService invSrv = InvServiceFactory.GetService(pub.InvPattern, currentCom.id); int count = lstFkey.Count(); log.Info("paymentViaBlock get Inv"); List <IInvoice> foundLst = new List <IInvoice>(); foundLst = (List <IInvoice>)invSrv.GetByFkey(currentCom.id, lstFkey.ToArray()); log.Info("paymentViaBlock loc ket qua"); List <string> foundFkey = foundLst.Select(inv => inv.Fkey).ToList(); //khong ton tai lstFkey.RemoveAll(inv => foundFkey.Contains(inv)); //đã gạch nợ rồi List <IInvoice> updateInv = foundLst.GetRange(0, foundLst.Count); updateInv.RemoveAll(inv => inv.PaymentStatus == Payment.Paid); //cần gạch nợ foundLst.RemoveAll(inv => inv.PaymentStatus == Payment.Unpaid); //đã gạch nợ rồi. List <string> unpaiedLst = updateInv.Select(inv => inv.Fkey).ToList(); List <string> paiedList = foundLst.Select(inv => inv.Fkey).ToList(); //ko ton tai lstFkey //da gach no paiedList //can gach no unpaiedLst //ghi file excel ket qua MemoryStream stream; ExcelWriter writer; if (lstFkey.Count > 0 || paiedList.Count > 0) { stream = new MemoryStream(); writer = new ExcelWriter(stream); writer.BeginWrite(); int i = 0; for (; i < lstFkey.Count; i++) { string s = lstFkey.ElementAt(i); writer.WriteCell(i, 0, s); writer.WriteCell(i, 1, "Khong ton tai"); } for (int j = 0; j < paiedList.Count; j++) { string s = paiedList.ElementAt(j); i++; writer.WriteCell(i, 0, s); writer.WriteCell(i, 1, "Da thanh toan tu truoc"); } writer.EndWrite(); mTran.FailResult = stream.ToArray(); stream.Close(); } //thuc hien gach no va ghi note moi int[] ids = updateInv.Select(inv => inv.id).ToArray(); string noteAppends = " || Thực hiện gạch nợ: Người gạch nợ: " + HttpContext.User.Identity.Name + " Ngày gạch nợ: " + DateTime.Now.ToString(); log.Info("paymentViaBlock gach no"); if (invSrv.ConfirmPayment(ids, noteAppends)) //if (invSrv.ConfirmPayment(updateInv)) { //thanh cong het //tao file ket qua thanh cong log.Info("paymentViaBlock ghi file thanh cong"); stream = new MemoryStream(); writer = new ExcelWriter(stream); writer.BeginWrite(); for (int j = 0; j < updateInv.Count; j++) { string s = updateInv.ElementAt(j).Fkey; writer.WriteCell(j, 0, s); } writer.EndWrite(); mTran.CompleteResult = stream.ToArray(); stream.Close(); if (lstFkey.Count == 0) { mTran.Status = PaymentTransactionStatus.Completed; } else { mTran.Status = PaymentTransactionStatus.NotComplete; } log.Info("Change Payment Status Einvoices by: " + HttpContext.User.Identity.Name + " Info-- GUID: " + mTran.id.ToString() + "Tổng số: " + (count) + ", gạch nợ thành công " + updateInv.Count + ", không tồn tại: " + lstFkey.Count + ", đã gạch nợ trước: " + paiedList.Count + " hóa đơn"); mTran.Messages = "Tổng số: " + (count) + ", gạch nợ thành công " + updateInv.Count + ", không tồn tại: " + lstFkey.Count + ", đã gạch nợ trước: " + paiedList.Count + " hóa đơn"; //thuc hien deliveriy IDeliver _deliver = IoC.Resolve <IDeliver>(); _deliver.Deliver(updateInv.ToArray(), currentCom); log.Info("paymentViaBlock end " + mTran.id); return(mTran); } mTran.Status = PaymentTransactionStatus.Failed; log.Info("Change Payment Status Einvoices by: " + HttpContext.User.Identity.Name + " Info-- GUID: " + mTran.id.ToString() + "Tổng số: " + (count) + " hóa đơn, gạch nợ fail " + updateInv.Count + ", không tồn tại: " + lstFkey.Count + ", đã gạch nợ trước: " + paiedList.Count + " hóa đơn"); if (count == 0) { mTran.Messages = "File không đúng mẫu hoặc không chứa dữ liệu"; } else { mTran.Messages = "Tổng số: " + (count) + " hóa đơn, gạch nợ fail " + updateInv.Count + ", không tồn tại: " + lstFkey.Count + ", đã gạch nợ trước: " + paiedList.Count + " hóa đơn"; } return(mTran); }
public string confirmPaymentDetail(ListInvoice inv) { Company _currentCompany = ((EInvoiceContext)FXContext.Current).CurrentCompany; int comID = _currentCompany.id; if (_currentCompany == null) { return("ERR:7"); //username khong phu hop - ko tim thay company phu hop voi [username] } List <IInvoice> invLst = new List <IInvoice>(); string[] invTokens = inv.lstInvToken.Split('_'); List <string> unPaid = new List <string>(); List <string> notFound = new List <string>(); List <string> paid = new List <string>(); string pattern; string serial; decimal invNo; string rv = ""; if (invTokens.Length < 1 || (!DataHelper.parseInvToken(invTokens[0], out pattern, out serial, out invNo).Equals("OK"))) { return(DataHelper.parseInvToken(invTokens[0], out pattern, out serial, out invNo)); } IInvoiceService _iInvoicSrv = InvServiceFactory.GetService(pattern, comID); foreach (string invToken in invTokens) { pattern = ""; serial = ""; invNo = 0; rv = DataHelper.parseInvToken(invToken, out pattern, out serial, out invNo); if (!rv.Equals("OK")) { return(rv); } IInvoice oInvoiceBase = _iInvoicSrv.GetByNo(comID, pattern, serial, invNo); if (oInvoiceBase == null) { //return "ERR:6"; //khong tim thay hoa don notFound.Add(invToken); } if (oInvoiceBase.PaymentStatus == Payment.Unpaid && (oInvoiceBase.Status == InvoiceStatus.AdjustedInv || oInvoiceBase.Status == InvoiceStatus.SignedInv)) { invLst.Add(oInvoiceBase); unPaid.Add(invToken); } else { paid.Add(invToken); } } rv = ""; StringBuilder sb = new StringBuilder("ERR:6#"); foreach (string s in notFound) { sb.AppendFormat("{0}_", s); } rv = sb.ToString(); rv = rv.Remove(rv.Length - 1, 1); sb = new StringBuilder("ERR:13#"); foreach (string s in paid) { sb.AppendFormat("{0}_", s); } rv = rv + "||" + sb.ToString(); rv = rv.Remove(rv.Length - 1, 1); if (invLst.Count == 0) { //return "ERR:13"; // hoa đơn đã gạch nợ/bỏ gạch nợ rồi return(rv); } ICompanyService _comSrv = IoC.Resolve <ICompanyService>(); Company com = _comSrv.Getbykey(comID); string strNote = "Thực hiện gạch nợ: Người gạch nợ: " + HttpContext.Current.User.Identity.Name + " Ngày gạch nợ: " + DateTime.Now.ToString(); if (_iInvoicSrv.ConfirmPayment(invLst, strNote)) { //thuc hien deliveriy IDeliver _deliver = _currentCompany.Config.Keys.Contains("IDeliver") ? IoC.Resolve(Type.GetType(_currentCompany.Config["IDeliver"])) as IDeliver : null; if (_deliver != null) { _deliver.Deliver(invLst.ToArray(), com); } //return "OK:"; sb = new StringBuilder("OK:#"); foreach (string s in unPaid) { sb.AppendFormat("{0}_", s); } rv = rv + "||" + sb.ToString(); rv = rv.Remove(rv.Length - 1, 1); return(rv); //ok } return("ERR:7"); //sao lai khong thanh toán được ? }
public string confirmPaymentFkeyVNP(ListInvoice lsInv) { Company _currentCompany = ((EInvoiceContext)FXContext.Current).CurrentCompany; int comID = _currentCompany.id; if (_currentCompany == null) { return("ERR:7"); //username khong phu hop - ko tim thay company phu hop voi [username] } List <IInvoice> invLst = new List <IInvoice>(); string[] invTokens = lsInv.lsFkey.Split(';'); IPublishInvoiceService _PubInvSrv = IoC.Resolve <IPublishInvoiceService>(); PublishInvoice pubinv = _PubInvSrv.GetFirst(comID, new int[] { 1, 2 }); string pattern = ""; if (pubinv != null) { pattern = pubinv.InvPattern; _PubInvSrv.UnbindSession(pubinv); } IInvoiceService invSrv = InvServiceFactory.GetService(pattern, comID); try { invLst = (List <IInvoice>)invSrv.GetByFkey(comID, invTokens); if (invTokens.Length != invLst.Count) { return("ERR:6"); } invLst.RemoveAll(inv => inv.PaymentStatus == Payment.Paid || (inv.Status != InvoiceStatus.SignedInv && inv.Status != InvoiceStatus.AdjustedInv)); for (int i = 0; i < invTokens.Length; i++) { invTokens[i] = invTokens[i] + "K"; } List <IInvoice> invKLst = new List <IInvoice>(); invKLst = (List <IInvoice>)invSrv.GetByFkey(comID, invTokens); invKLst.RemoveAll(inv => inv.PaymentStatus == Payment.Paid || (inv.Status != InvoiceStatus.SignedInv && inv.Status != InvoiceStatus.AdjustedInv)); if (invKLst.Count > 0) { invLst.AddRange(invKLst); } } catch (Exception ex) { log.Error("confirmPaymentFkey " + ex); return("ERR:6 " + ex.Message); } if (invLst.Count == 0) { return("ERR:13"); // hoa đơn đã gạch nợ/bỏ gạch nợ rồi } string strNote = " || Thực hiện gạch nợ: Người gạch nợ: " + HttpContext.Current.User.Identity.Name + " Ngày gạch nợ: " + DateTime.Now.ToString(); if (invSrv.ConfirmPayment(invLst, strNote)) { //thuc hien deliveriy IDeliver _deliver = _currentCompany.Config.Keys.Contains("IDeliver") ? IoC.Resolve(Type.GetType(_currentCompany.Config["IDeliver"])) as IDeliver : null; if (_deliver != null) { _deliver.Deliver(invLst.ToArray(), _currentCompany); } //lay link email String weblink = System.Configuration.ConfigurationManager.AppSettings["Portal"] + "/Email/EmailInvoiceView?token="; StringBuilder rv = new StringBuilder("OK:<Data>"); foreach (IInvoice inv in invLst) { rv.Append("<Item><index>").Append(inv.PublishDate.Month).Append("</index>"); rv.Append("<cusCode>").Append(inv.CusCode).Append("</cusCode>"); if (inv.Fkey.EndsWith("K")) { rv.Append("<month>").Append(inv.Fkey.Substring(inv.Fkey.Length - 7, 6)).Append("</month>"); } else { rv.Append("<month>").Append(inv.Fkey.Substring(inv.Fkey.Length - 6, 6)).Append("</month>"); } rv.Append("<pattern>").Append(inv.Pattern).Append("</pattern>"); rv.Append("<serial>").Append(inv.Serial).Append("</serial>"); rv.Append("<status>").Append((int)inv.Status).Append("</status>"); string stoken = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(inv.id.ToString() + "_" + inv.Pattern + "_" + _currentCompany.id.ToString())); rv.AppendFormat("<link>{0}{1}</link></Item>", weblink, stoken); } rv.Append("</Data>"); return(rv.ToString()); //} //else return "OK:"; } return("ERR:7"); //sao lai khong thanh toán được ? }
public string confirmPaymentDetailFkey(ListInvoice lsInv) { Company _currentCompany = ((EInvoiceContext)FXContext.Current).CurrentCompany; int comID = _currentCompany.id; if (_currentCompany == null) { return("ERR:7"); //username khong phu hop - ko tim thay company phu hop voi [username] } List <IInvoice> invLst = new List <IInvoice>(); string[] invTokens = lsInv.lsFkey.Split('_'); if (invTokens.Count() > 1000) { return("ERR:14"); } IPublishInvoiceService _PubInvSrv = IoC.Resolve <IPublishInvoiceService>(); PublishInvoice pubinv = _PubInvSrv.GetFirst(comID, new int[] { 1, 2 }); string pattern = ""; if (pubinv != null) { pattern = pubinv.InvPattern; _PubInvSrv.UnbindSession(pubinv); } IInvoiceService invSrv = InvServiceFactory.GetService(pattern, comID); StringBuilder sb = new StringBuilder(); List <string> unPaidFkey = new List <string>(); string rv; try { invLst = (List <IInvoice>)invSrv.GetByFkey(comID, invTokens); List <string> foundFkey = invLst.Select(inv => inv.Fkey).ToList(); List <string> notFoundFkey = invTokens.ToList().GetRange(0, invTokens.Count()); notFoundFkey.RemoveAll(inv => foundFkey.Contains(inv)); // list fkey khong ton tai invLst.RemoveAll(inv => inv.PaymentStatus == Payment.Paid || (inv.Status != InvoiceStatus.SignedInv && inv.Status != InvoiceStatus.AdjustedInv)); unPaidFkey = invLst.Select(inv => inv.Fkey).ToList(); // list fkey can gach no foundFkey.RemoveAll(inv => unPaidFkey.Contains(inv)); // list fkey da gach no roi sb = new StringBuilder("ERR:6#"); foreach (string s in notFoundFkey) { sb.AppendFormat("{0}_", s); } rv = sb.ToString(); rv = rv.Remove(rv.Length - 1, 1); sb = new StringBuilder("ERR:13#"); foreach (string s in foundFkey) { sb.AppendFormat("{0}_", s); } rv = rv + "||" + sb.ToString(); rv = rv.Remove(rv.Length - 1, 1); } catch (Exception ex) { log.Error("confirmPaymentFkey " + ex); return("ERR:6 " + ex.Message); } if (invLst.Count == 0) { //toan bo lo hoa don hoac ko tim thay, hoac da gach no roi return(rv); } string strNote = " || Thực hiện gạch nợ: Người gạch nợ: " + HttpContext.Current.User.Identity.Name + " Ngày gạch nợ: " + DateTime.Now.ToString(); if (invSrv.ConfirmPayment(invLst, strNote)) { //thuc hien deliveriy IDeliver _deliver = _currentCompany.Config.Keys.Contains("IDeliver") ? IoC.Resolve(Type.GetType(_currentCompany.Config["IDeliver"])) as IDeliver : null; if (_deliver != null) { _deliver.Deliver(invLst.ToArray(), _currentCompany); } //return "OK:"; sb = new StringBuilder("OK:#"); foreach (string s in unPaidFkey) { sb.AppendFormat("{0}_", s); } rv = rv + "||" + sb.ToString(); rv = rv.Remove(rv.Length - 1, 1); return(rv); //ok } return("ERR:7"); //sao lai khong thanh toán được ? }
public string confirmPayment(ListInvoice lsinv) { Company _currentCompany = ((EInvoiceContext)FXContext.Current).CurrentCompany; int comID = _currentCompany.id; if (_currentCompany == null) { return("ERR:7"); //username khong phu hop - ko tim thay company phu hop voi [username] } List <IInvoice> invLst = new List <IInvoice>(); string[] invTokens = lsinv.lstInvToken.Split('_'); string pattern; string serial; decimal invNo; if (invTokens.Length < 1 || (!DataHelper.parseInvToken(invTokens[0], out pattern, out serial, out invNo).Equals("OK"))) { return(DataHelper.parseInvToken(invTokens[0], out pattern, out serial, out invNo)); } IInvoiceService _iInvoicSrv = InvServiceFactory.GetService(pattern, comID); Dictionary <string, List <decimal> > serialAndNo = new Dictionary <string, List <decimal> >(); foreach (string invToken in invTokens) { pattern = ""; serial = ""; invNo = 0; string rv = DataHelper.parseInvToken(invToken, out pattern, out serial, out invNo); if (!rv.Equals("OK")) { return(rv); } if (!serialAndNo.ContainsKey(serial)) { serialAndNo[serial] = new List <decimal>(); } serialAndNo[serial].Add(invNo); } //lấy list hóa đơn theo serial foreach (KeyValuePair <string, List <decimal> > i in serialAndNo) { invLst.AddRange(_iInvoicSrv.GetByNo(comID, pattern, i.Key, i.Value.ToArray())); } invLst.RemoveAll(inv => inv.Status != InvoiceStatus.SignedInv && inv.Status != InvoiceStatus.AdjustedInv); //ktra mọi token đều tìm được hóa đơn if (invTokens.Length != invLst.Count) { return("ERR:6"); } invLst.RemoveAll(inv => inv.PaymentStatus == Payment.Paid || (inv.Status != InvoiceStatus.SignedInv && inv.Status != InvoiceStatus.AdjustedInv)); if (invLst.Count == 0) { return("ERR:13"); // hoa đơn đã gạch nợ/bỏ gạch nợ rồi } ICompanyService _comSrv = IoC.Resolve <ICompanyService>(); Company com = _comSrv.Getbykey(comID); string strNote = "Thực hiện gạch nợ: Người gạch nợ: " + HttpContext.Current.User.Identity.Name + " Ngày gạch nợ: " + DateTime.Now.ToString(); if (_iInvoicSrv.ConfirmPayment(invLst, strNote)) { //thuc hien deliveriy IDeliver _deliver = _currentCompany.Config.Keys.Contains("IDeliver") ? IoC.Resolve(Type.GetType(_currentCompany.Config["IDeliver"])) as IDeliver : null; if (_deliver != null) { _deliver.Deliver(invLst.ToArray(), com); } return("OK:"); } return("ERR:7"); //sao lai khong thanh toán được ? }