public ActionResult ajxGetSerial(int id) { IPublishInvoiceService _ipiSer = IoC.Resolve <IPublishInvoiceService>(); PublishInvoice pi = _ipiSer.Getbykey(id); return(Json(pi)); }
//lay default Pattern va serial //lay pattern dau tien cua cong ty, van con hoa don trong dai private PublishInvoice DefaultPublishInvoice(int ComID) { PublishInvoice ret = null; IPublishInvoiceService _PubSrv = IoC.Resolve <IPublishInvoiceService>(); ret = _PubSrv.Query.Where(pi => pi.ComId == ComID && (pi.Status == 1 || pi.Status == 2)).First(); return(ret); }
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 string UnConfirmPaymentFkey(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.Unpaid || (inv.Status != InvoiceStatus.SignedInv && inv.Status != InvoiceStatus.AdjustedInv)); } catch (Exception ex) { log.Error("UnConfirmPaymentFkey " + ex); return("ERR:6 " + ex.Message); } if (invLst.Count == 0) { return("ERR:13"); // hoa đơn đã gạch nợ/bỏ gạch nợ rồi } if (invSrv.UnConfirmPayment(invLst)) { return("OK:"); } return("ERR:7"); //sao lai khong bo thanh toán được ? }
public string deliverInvFkey(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] } try { 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 _iInvoicSrv = InvServiceFactory.GetService(pattern, comID); invLst = (List <IInvoice>)_iInvoicSrv.GetByFkey(comID, invTokens); if (invLst.Count != invTokens.Length) { return("ERR:6"); //khong tim thay hoa don } ICompanyService _comSrv = IoC.Resolve <ICompanyService>(); Company com = _comSrv.Getbykey(comID); 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); } } catch (Exception ex) { log.Error("deliver: " + ex); } return("OK:"); }
private void getPublishInvoice(string pattern, int comID, out string invPattern, out string invSerial) { invPattern = invSerial = null; int isPattern = string.IsNullOrWhiteSpace(pattern) ? 0 : 1; IPublishInvoiceService _PubInvSrv = IoC.Resolve <IPublishInvoiceService>(); switch ((isPattern)) { case 0: PublishInvoice pubinv = _PubInvSrv.GetFirst(comID, new int[] { 1, 2 }); if (pubinv != null) { invPattern = pubinv.InvPattern; invSerial = pubinv.InvSerial; _PubInvSrv.UnbindSession(pubinv); } else { return; //tham so pattern va serial khong hop le } break; case 1: PublishInvoice pubFirst = _PubInvSrv.GetbyPattern(comID, pattern, new int[] { 1, 2 }).FirstOrDefault(); if (pubFirst == null) { return; } else { invPattern = pattern; invSerial = pubFirst.InvSerial; _PubInvSrv.UnbindSession(pubFirst); } break; } }
private string processCancelInv(string fkey, string pattern = null, string serial = null, decimal invNo = 0) { 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] } int isPattern = string.IsNullOrEmpty(pattern) ? 0 : 1; IPublishInvoiceService _PubInvSrv = IoC.Resolve <IPublishInvoiceService>(); switch ((isPattern)) { case 0: PublishInvoice pubinv = _PubInvSrv.GetFirst(comID, new int[] { 1, 2 }); if (pubinv != null) { pattern = pubinv.InvPattern; serial = pubinv.InvSerial; _PubInvSrv.UnbindSession(pubinv); } else { return("ERR:20"); //tham so pattern va serial khong hop le } break; case 1: PublishInvoice pubFirst = _PubInvSrv.GetbyPattern(comID, pattern, new int[] { 1, 2 }).FirstOrDefault(); if (pubFirst == null) { return("ERR:20"); } else { serial = !string.IsNullOrWhiteSpace(serial) ? serial : pubFirst.InvSerial; _PubInvSrv.UnbindSession(pubFirst); } break; } IInvoiceService iinvSrc = InvServiceFactory.GetService(pattern, comID); try { IInvoice currentInv = InvServiceFactory.NewInstance(pattern, comID); if (invNo > 0) { currentInv = iinvSrc.GetByNo(comID, pattern, serial, invNo); } else { currentInv = iinvSrc.GetByFkey(comID, fkey); } if (null == currentInv) { return("ERR:2"); //khong ton tai hoa don } Launcher t = Launcher.Instance; t.Cancel(new IInvoice[] { currentInv }); ILogSystemService businessLog = IoC.Resolve <ILogSystemService>(); businessLog.WriteLogCancel(comID, HttpContext.Current.User.Identity.Name, currentInv.Pattern, currentInv.Serial, currentInv.No.ToString("0000000"), currentInv.PublishDate, currentInv.Amount, currentInv.CusName, currentInv.CusAddress, currentInv.CusCode, currentInv.CusTaxCode, BusinessLogType.Cancel); businessLog.CommitChanges(); return("OK:"); } catch (Exception ex) { log.Error("cancelInv " + ex); return("ERR:6 " + ex.Message); } }
private string processReplace(string xmlData, string pattern, string fkey, string serial = null, decimal invNo = 0, int convert = 0) { if (FXContext.Current == null) { return("ERR:1"); } try { XmlSchemaValidator validator = new XmlSchemaValidator(); if (!validator.ValidXmlDoc(xmlData, "", AppDomain.CurrentDomain.BaseDirectory + @"xmlvalidate\replacevatinvoice.xsd")) { //customer xml string not valid, don't do any thing log.Info("processReplace " + validator.ValidationError); return("ERR:3 err:" + validator.ValidationError); //du lieu dau vao khong hop le } if (convert == 1) { xmlData = DataHelper.convertTCVN3ToUnicode(xmlData); } 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] } ICustomerService _cusSvr = IoC.Resolve <ICustomerService>(); string invNumList = ""; int isPattern = string.IsNullOrEmpty(pattern) ? 0 : 1; IPublishInvoiceService _PubInvSrv = IoC.Resolve <IPublishInvoiceService>(); switch ((isPattern)) { case 0: PublishInvoice pubinv = _PubInvSrv.GetFirst(comID, new int[] { 1, 2 }); if (pubinv != null) { pattern = pubinv.InvPattern; serial = pubinv.InvSerial; _PubInvSrv.UnbindSession(pubinv); } else { return("ERR:20"); //tham so pattern va serial khong hop le } break; case 1: PublishInvoice pubFirst = _PubInvSrv.GetbyPattern(comID, pattern, new int[] { 1, 2 }).FirstOrDefault(); if (pubFirst == null) { return("ERR:20"); } else { serial = !string.IsNullOrWhiteSpace(serial) ? serial : pubFirst.InvSerial; _PubInvSrv.UnbindSession(pubFirst); } break; } IInvoiceService iinvSrc = InvServiceFactory.GetService(pattern, comID); IInvoice currentInv = InvServiceFactory.NewInstance(pattern, comID); if (invNo > 0) { currentInv = iinvSrc.GetByNo(comID, pattern, serial, invNo); } else { currentInv = iinvSrc.GetByFkey(comID, fkey); } if (null == currentInv) { log.Error("Không tồn tại hóa đơn."); return("ERR:2"); //khong ton tai hoa don, hoa don da duoc thay the roi; } string invPattern = null, invSerial = null, errorMessage = ""; if (!LaunchInvoices.Instance.ExistNoInPubInv(comID, currentInv.Pattern, currentInv.Serial, out invPattern, out invSerial, out errorMessage)) { log.Error("het so hoa don trong dai."); return("ERR:6 " + fkey); //het so hoa don trong dai } IInvoice inv = (InvoiceBase)InvServiceFactory.NewInstance(invPattern, comID); try { XElement xeles = XElement.Parse(xmlData); DataHelper.DeserializeEinvFromXML(xmlData, inv); inv.No = 0; inv.Name = currentInv.Name; inv.Pattern = invPattern; inv.Serial = invSerial; inv.CreateBy = System.Web.HttpContext.Current.User.Identity.Name; var Typecus = (from c in _cusSvr.Query where c.ComID == comID && c.Code == inv.CusCode && c.CusType == 1 select c.CusType).SingleOrDefault(); if (Typecus == 0) { inv.CusSignStatus = cusSignStatus.NocusSignStatus; } else { inv.CusSignStatus = cusSignStatus.NoSignStatus; } if (currentInv.Status == InvoiceStatus.SignedInv || currentInv.Status == InvoiceStatus.AdjustedInv) { IList <ProductInv> products = new List <ProductInv>(); foreach (IProductInv ii in inv.Products) { products.Add((ProductInv)ii); } Launcher.Instance.PublishReplace(currentInv, products, (InvoiceBase)inv, ""); invNumList += inv.Fkey ?? " "; } else { return("ERR:9 " + currentInv.Status); } } catch (EInvoice.Core.Launching.NoFactory.OpenTranException ex) { log.Error(ex); return("ERR:14"); } catch (Exception ex) { log.Error("replaceInv err5: " + ex); return("ERR:5 " + ex.Message);//loi phat hanh hoa don } ILogSystemService businessLog = IoC.Resolve <ILogSystemService>(); businessLog.WriteLogReplaceAdjust(comID, currentInv.Pattern, currentInv.Serial, currentInv.No, currentInv.PublishDate, currentInv.Amount, inv.Pattern, inv.Serial, inv.No, inv.PublishDate, inv.Amount, inv.CusName, inv.CusAddress, inv.CusCode, inv.CusTaxCode, HttpContext.Current.User.Identity.Name, BusinessLogType.Replace); businessLog.CommitChanges(); //invNumList = invNumList.Remove(invNumList.Length - 1, 1); return("OK_" + invNumList); } catch (Exception ex) { log.Error("replaceInv: " + ex); return("ERR:5 " + ex.Message); } }
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 static ValidationResult checkExistPublishInvoice(String invSerial, String invPattern, int comID, out PublishInvoice objOut) { PublishInvoiceDA dABu = new PublishInvoiceDA(); objOut = dABu.checkExistByID(invSerial, invPattern, comID); if (objOut == null) { return(new ValidationResult(ConstantsMultiLanguageKey.E_PublishInvoice_NotExist)); } return(null); }
public IHttpActionResult ImportAndPublishInv(ApiPublish publish) { ILog log = LogManager.GetLogger(typeof(PublishController)); //check valiadate xml XmlSchemaValidator validator = new XmlSchemaValidator(); //xmlInvData = convertSpecialCharacter(xmlInvData); if (!validator.ValidXmlDoc(publish.xmlData, "", AppDomain.CurrentDomain.BaseDirectory + @"xmlvalidate\VATInVoice_ws.xsd")) { log.Error(publish.xmlData); log.Error("ERR:3-" + validator.ValidationError); return(Ok("ERR:3-" + validator.ValidationError)); //du lieu dau vao khong hop le } if (publish.convert == 1) { publish.xmlData = DataHelper.convertTCVN3ToUnicode(publish.xmlData); } Company _currentCompany = ((EInvoiceContext)FXContext.Current).CurrentCompany; IDeliver _DeliverService = _currentCompany.Config.ContainsKey("IDeliver") ? InvServiceFactory.GetDeliver(_currentCompany.Config["IDeliver"]) : null; int comID = _currentCompany.id; if (_currentCompany == null) { return(NotFound()); } IPublishInvoiceService _PubInvSrv = IoC.Resolve <IPublishInvoiceService>(); int patternNull = string.IsNullOrEmpty(publish.pattern) ? 0 : 1; int serialNull = string.IsNullOrEmpty(publish.serial) ? 0 : 1; string nameInvoice = ""; switch ((patternNull + serialNull)) { case 0: PublishInvoice pubinv = _PubInvSrv.GetFirst(comID, new int[] { 1, 2 }); if (pubinv != null) { IRegisterTempService regisSrv = IoC.Resolve <IRegisterTempService>(); RegisterTemp rtemp = regisSrv.Getbykey(pubinv.RegisterID); publish.pattern = pubinv.InvPattern; publish.serial = pubinv.InvSerial; nameInvoice = rtemp.NameInvoice; _PubInvSrv.UnbindSession(pubinv); regisSrv.UnbindSession(rtemp); } else { return(Ok("ERR:20")); //tham so pattern va serial khong hop le } break; case 1: PublishInvoice pubFirst = null; try { if (!string.IsNullOrWhiteSpace(publish.pattern)) { pubFirst = (from p in _PubInvSrv.Query where (p.ComId == comID) && (p.InvPattern == publish.pattern) && (p.Status == 1 || p.Status == 2) select p).FirstOrDefault(); } else { pubFirst = (from p in _PubInvSrv.Query where (p.ComId == comID) && (p.InvSerial == publish.serial) && (p.Status == 1 || p.Status == 2) select p).FirstOrDefault(); } } catch (Exception ex) { log.Error(ex); return(Ok("ERR:20")); //khong can return cung duoc } if (pubFirst == null) { return(Ok("ERR:20")); } else { IRegisterTempService regisSrv = IoC.Resolve <IRegisterTempService>(); RegisterTemp rtemp = regisSrv.Getbykey(pubFirst.RegisterID); nameInvoice = rtemp.NameInvoice; publish.pattern = pubFirst.InvPattern; publish.serial = pubFirst.InvSerial; _PubInvSrv.UnbindSession(pubFirst); regisSrv.UnbindSession(rtemp); } break; case 2: // PublishInvoice pub = _PubInvSrv.CurrentPubInv(comID, pattern, serial, 1); PublishInvoice pub = null; try { pub = (from p in _PubInvSrv.Query where (p.ComId == comID) && (p.InvPattern == publish.pattern) && (p.InvSerial == publish.serial) && (p.Status == 1 || p.Status == 2) select p).First(); } catch (Exception ex) { log.Error(ex); return(Ok("ERR:20")); //khong can return cung duoc } if (pub == null) { return(Ok("ERR:20")); } else { IRegisterTempService regisSrv = IoC.Resolve <IRegisterTempService>(); RegisterTemp rtemp = regisSrv.Getbykey(pub.RegisterID); nameInvoice = rtemp.NameInvoice; _PubInvSrv.UnbindSession(pub); regisSrv.UnbindSession(rtemp); } break; } log.Info("pattern-serial: " + publish.pattern + "-" + publish.serial); XElement elem = XElement.Parse(publish.xmlData); IList <IInvoice> lstINV = new List <IInvoice>(); string invKeyAndNumList = ""; IEnumerable <XElement> listTemp = elem.Elements("Inv"); IList <String> lstKey = new List <String>(); //check xem con du so hoa don ko if (getMaxInvNumber(comID, publish.pattern, publish.serial) < listTemp.Count()) { return(Ok("ERR:6")); //khong con du so hoa don cho lo phat hanh } //check xem lo truyen vao lon hon MaxBlockInv hay ko int maxBlockInv; string temp = System.Configuration.ConfigurationManager.AppSettings["MaxBlockInv"]; if (string.IsNullOrEmpty(temp) || !Int32.TryParse(temp, out maxBlockInv)) { maxBlockInv = 5000; } if (listTemp.Count() > maxBlockInv) { return(Ok("ERR:10")); // lo hoa don truyen vao lon hon maxBlockInv; } try { foreach (XElement e in listTemp) { XElement ele = e.Element("Invoice"); string fKey = e.Element("key").Value.Trim(); lstKey.Add(fKey); IInvoice inv = InvServiceFactory.NewInstance(publish.pattern, comID); string read = string.Concat(ele); inv.DeserializeFromXML(read); inv.Name = nameInvoice; inv.Pattern = publish.pattern; inv.Serial = publish.serial; inv.CreateBy = inv.CreateBy ?? System.Web.HttpContext.Current.User.Identity.Name; inv.Fkey = fKey; lstINV.Add(inv); } } catch (Exception ex) { log.Error(ex); return(Ok("ERR:5"));//loi phat hanh hoa don } try { Launcher.Instance.Launch(publish.pattern, publish.serial, lstINV.ToArray()); if (_DeliverService != null) { _DeliverService.PrepareDeliver(lstINV.ToArray(), _currentCompany); } for (int i = 0; i < lstINV.Count; i++) { invKeyAndNumList += lstKey[i] + "_" + lstINV[i].No + ","; } //remove the last "," character invKeyAndNumList = invKeyAndNumList.Remove(invKeyAndNumList.Length - 1, 1); return(Ok("OK:" + publish.pattern + ";" + publish.serial + "-" + invKeyAndNumList)); } catch (Exception ex) { log.Error(ex); return(Ok("ERR:13")); } }
public IHttpActionResult ImportInv(ApiPublish publish) { ILog log = LogManager.GetLogger(typeof(PublishController)); XmlSchemaValidator validator = new XmlSchemaValidator(); //xmlInvData = convertSpecialCharacter(xmlInvData); if (!validator.ValidXmlDoc(publish.xmlData, "", AppDomain.CurrentDomain.BaseDirectory + @"xmlvalidate\VATInVoice_ws.xsd")) { //customer xml string not valid, don't do any thing log.Error("ERR3: " + validator.ValidationError); return(Ok("ERR:3")); } if (publish.convert == 1) { publish.xmlData = DataHelper.convertTCVN3ToUnicode(publish.xmlData); } Company _currentCompany = ((EInvoiceContext)FXContext.Current).CurrentCompany; int comID = _currentCompany.id; IPublishInvoiceService _PubInvSrv = IoC.Resolve <IPublishInvoiceService>(); string nameInvoice = "", serial = null; int patternNull = string.IsNullOrEmpty(publish.pattern) ? 0 : 1; switch (patternNull) { case 0: PublishInvoice pubinv = _PubInvSrv.GetFirst(comID, new int[] { 1, 2 }); if (pubinv != null) { IRegisterTempService regisSrv = IoC.Resolve <IRegisterTempService>(); RegisterTemp rtemp = regisSrv.Getbykey(pubinv.RegisterID); publish.pattern = pubinv.InvPattern; nameInvoice = rtemp.NameInvoice; serial = pubinv.InvSerial; _PubInvSrv.UnbindSession(pubinv); regisSrv.UnbindSession(rtemp); } else { return(Ok("ERR:20")); //tham so pattern va serial khong hop le } break; case 1: PublishInvoice pub = null; try { pub = (from p in _PubInvSrv.Query where (p.ComId == comID) && (p.InvPattern == publish.pattern) && (p.Status == 1 || p.Status == 2) select p).FirstOrDefault(); } catch (Exception ex) { log.Error(ex); return(Ok("ERR:20")); //khong can return cung duoc } if (pub == null) { return(Ok("ERR:20")); } else { IRegisterTempService regisSrv = IoC.Resolve <IRegisterTempService>(); RegisterTemp rtemp = regisSrv.Getbykey(pub.RegisterID); nameInvoice = rtemp.NameInvoice; serial = pub.InvSerial; _PubInvSrv.UnbindSession(pub); regisSrv.UnbindSession(rtemp); } break; } XElement elem = XElement.Parse(publish.xmlData); IList <IInvoice> lstINV = new List <IInvoice>(); string invKeyAndNumList = ""; IEnumerable <XElement> listTemp = elem.Elements("Inv"); IList <String> lstKey = new List <String>(); //check xem lo truyen vao lon hon MaxBlockInv hay ko int maxBlockInv; string temp = System.Configuration.ConfigurationManager.AppSettings["MaxBlockInv"]; if (string.IsNullOrEmpty(temp) || !Int32.TryParse(temp, out maxBlockInv)) { maxBlockInv = 5000; } if (listTemp.Count() > maxBlockInv) { return(Ok("ERR:10")); // lo hoa don truyen vao lon hon maxBlockInv; } try { int cc = listTemp.Count(); foreach (XElement e in listTemp) { XElement ele = e.Element("Invoice"); string fKey = e.Element("key").Value.Trim(); lstKey.Add(fKey); IInvoice inv = InvServiceFactory.NewInstance(publish.pattern, comID); string read = string.Concat(ele); inv.DeserializeFromXML(read); inv.No = 0; inv.Name = nameInvoice; inv.Pattern = publish.pattern; inv.Serial = serial; inv.CreateBy = System.Web.HttpContext.Current.User.Identity.Name; inv.Fkey = fKey; lstINV.Add(inv); } } catch (Exception ex) { log.Error("ERR:5-", ex); return(Ok("ERR:5"));//loi phat hanh hoa don } string mess = ""; bool isImport = false; IInvoiceService t = EInvoice.Core.InvServiceFactory.GetService(publish.pattern, _currentCompany.id); t.BeginTran(); try { if (lstINV.Count > 50) { t.isStateLess = true; } isImport = t.CreateInvoice(lstINV.ToArray(), out mess); t.CommitTran(); } catch (Exception ex) { t.RolbackTran(); log.Error(ex); return(Ok("ERR:5")); } finally { t.isStateLess = false; } if (isImport) { for (int i = 0; i < lstINV.Count; i++) { invKeyAndNumList += lstKey[i] + ","; } //remove the last "," character invKeyAndNumList = invKeyAndNumList.Remove(invKeyAndNumList.Length - 1, 1); return(Ok("OK:" + publish.pattern + ";" + serial + "-" + invKeyAndNumList)); } log.Error(mess); return(Ok("ERR:5")); }
/// <summary> /// ham validate model /// </summary> /// <param name="validationContext"></param> /// <returns></returns> public IEnumerable <ValidationResult> Validate(System.ComponentModel.DataAnnotations.ValidationContext validationContext) { AdjustInvDH ctlAdj = new AdjustInvDH(); Boolean draftCancel = invoice.DraftCancel ?? false; //check hoa đơn hủy if ((invoice.Type == InvoiceType.Nomal || invoice.Type == InvoiceType.ForReplace || invoice.Type == InvoiceType.ForAdjustAccrete || invoice.Type == InvoiceType.ForAdjustReduce || invoice.Type == InvoiceType.ForAdjustInfo) && draftCancel) { List <String> validateRequestHuy = ModelBase.validateRequiredObject(new string[] { "key" , "invoice.Type", "invoice.Status", "invoice.DraftCancel", "invoice.ComtaxCode" }, new object[] { key, invoice.Type, invoice.Status, invoice.DraftCancel, invoice.ComTaxCode }); foreach (String item in validateRequestHuy) { yield return(new ValidationResult(item)); } //check invoice co ton tai hay ko PVOILInvoice objOut; yield return(ModelValidate.checkExistNoInvoice(key, out objOut)); //type=0,1,2,3,4 and status=0 and draftcancel=1 check key họ truyền lên với fkey trong bảng pvoilinvie là status=3 hoặc 5 thì k nhận báo lỗi if (objOut != null) { if (objOut.Status == Untilities.Common.Constants.InvoiceStatus.Bi_Thay_The || objOut.Status == Untilities.Common.Constants.InvoiceStatus.Xoa_Bo) { yield return(new ValidationResult(ConstantsMultiLanguageKey.E_Invoice_Status_3_5)); } // Check trong bảng [AdjustInv] nếu đã tồn tại invid của key truyền lên thì báo lỗi AdjustInv objAdj = ctlAdj.CheckExists(objOut.id); if (objAdj != null) { yield return(new ValidationResult(String.Format(ConfigMultiLanguage.getMessWithKey(ConstantsMultiLanguageKey.E_AdjustInv_Exist), key))); } } //if (invoice.Status != 1) //{ // yield return new ValidationResult(ConstantsMultiLanguageKey.E_Invoice_Status_Delete); //} } else { List <String> validateRequest = ModelBase.validateRequiredObject(new string[] { "key" , "invoice.ComtaxCode", "invoice.BusinessDepartmentID", "invoice.Type", "invoice.Status" , "invoice.PaymentMethod", "invoice.PaymentStatus", "invoice.CreateDate", "invoice.CreateBy" , "invoice.Total" , "invoice.VATRate", "invoice.VATAmount", "invoice.Amount" , "invoice.AmountInWords" , "invoice.Otherfees" , "invoice.Currency" , "invoice.ExchangeRate" }, new object[] { key , invoice.ComTaxCode, invoice.BusinessDepartmentID, invoice.Type, invoice.Status , invoice.PaymentMethod, invoice.PaymentStatus, invoice.CreateDate, invoice.CreateBy , invoice.Total , invoice.VATRate, invoice.VATAmount, invoice.Amount , invoice.AmountInWords , invoice.OtherFees , invoice.Currency , invoice.ExchangeRate }); foreach (String item in validateRequest) { yield return(new ValidationResult(item)); } //ton tai du lieu 1 trong 3 column sau CusTaxCode,CusName,CusAddress thì ca 3 column này phải có data if (String.IsNullOrEmpty(invoice.Buyer)) { List <String> validateRequestCus = ModelBase.validateRequiredObject(new string[] { "invoice.CusTaxCode", "invoice.CusName", "invoice.CusAddress" }, new object[] { invoice.CusTaxCode, invoice.CusName, invoice.CusAddress }); foreach (String item in validateRequestCus) { yield return(new ValidationResult(item)); } } if (invoice.Status != 0) { new ValidationResult(ConstantsMultiLanguageKey.E_Invoice_Status_Create); } else { if ((invoice.Type == InvoiceType.Nomal || invoice.Type == InvoiceType.ForReplace || invoice.Type == InvoiceType.ForAdjustAccrete || invoice.Type == InvoiceType.ForAdjustReduce || invoice.Type == InvoiceType.ForAdjustInfo) && invoice.DraftCancel != null) { if (!(invoice.Type == InvoiceType.Nomal && !draftCancel)) { String noCheckOk = HttpContext.Current.Request.QueryString["NoCheckOK"]; if ((!((invoice.Type == InvoiceType.ForAdjustReduce || invoice.Type == InvoiceType.ForAdjustAccrete) && !draftCancel)) || noCheckOk == null) { List <String> validateRequestCus = ModelBase.validateRequiredObject(new string[] { "invoice.originalKey" }, new object[] { invoice.originalKey }); foreach (String item in validateRequestCus) { yield return(new ValidationResult(item)); } } } //hoa don ko phai huy if (!draftCancel) { //check invoice co ton tai hay ko yield return(ModelValidate.checkExistInvoice(key)); if (invoice.Status != 0) { new ValidationResult(ConstantsMultiLanguageKey.E_Invoice_Status_Create); } PVOILInvoiceDA pvOil = new PVOILInvoiceDA(); //originalKey trong bảng pvoilinvie là status=3 hoặc 5 thì k nhận báo lỗi PVOILInvoice objInvoice = pvOil.checkExistInvoice(invoice.originalKey); if (objInvoice != null) { if (objInvoice.Status == Untilities.Common.Constants.InvoiceStatus.Bi_Thay_The || objInvoice.Status == Untilities.Common.Constants.InvoiceStatus.Xoa_Bo) { yield return(new ValidationResult(ConstantsMultiLanguageKey.E_Invoice_Status_3_5)); } } // type=1,2,3,4 check id của originalKey có trong bảng [AdjustInv] chưa?. nếu có status khác 0,1,2 báo lỗi if ((invoice.Type == InvoiceType.ForReplace || invoice.Type == InvoiceType.ForAdjustAccrete || invoice.Type == InvoiceType.ForAdjustReduce || invoice.Type == InvoiceType.ForAdjustInfo) && objInvoice != null) { AdjustInv objAdj = ctlAdj.CheckExistsAdj(Convert.ToInt64(objInvoice.id)); if (objAdj != null && (objAdj.Status != Untilities.Common.Constants.StatusAdj.Adj_0 && objAdj.Status != Untilities.Common.Constants.StatusAdj.Adj_1 && objAdj.Status != Untilities.Common.Constants.StatusAdj.Adj_2)) { yield return(new ValidationResult(String.Format(ConfigMultiLanguage.getMessWithKey(ConstantsMultiLanguageKey.E_AdjustInv_ThayThe), invoice.originalKey))); } } // type=1,2,3,4 thì bắt truyền trường ProcessInvNote => "bắt buộc nhập ProcessInvNote" if (invoice.Type == InvoiceType.ForReplace || invoice.Type == InvoiceType.ForAdjustAccrete || invoice.Type == InvoiceType.ForAdjustReduce || invoice.Type == InvoiceType.ForAdjustInfo) { List <String> validateRequestProcessInvNote = ModelBase.validateRequiredObject(new string[] { "invoice.ProcessInvNote" }, new object[] { invoice.ProcessInvNote }); foreach (String item in validateRequestProcessInvNote) { yield return(new ValidationResult(item)); } } // type=4 : check originalKey nếu tồn tại type=4 thì sẽ chỉ nhận type=4 k nhận type=1,2,3 của fkey mới if (invoice.Type == InvoiceType.ForAdjustInfo) { if (objInvoice.Type == InvoiceType.ForAdjustInfo) { yield return(new ValidationResult(String.Format(ConfigMultiLanguage.getMessWithKey(ConstantsMultiLanguageKey.E_Invoice_DaDieuChinhThongTin), invoice.originalKey))); } } } //else if (draftCancel) //{ // if (invoice.Status != 1) // { // new ValidationResult(ConstantsMultiLanguageKey.E_Invoice_Status_Delete); // } //} //check mau hoa don khong được điều chỉnh thay thế if ((invoice.Type == InvoiceType.ForReplace || invoice.Type == InvoiceType.ForAdjustAccrete || invoice.Type == InvoiceType.ForAdjustReduce || invoice.Type == InvoiceType.ForAdjustInfo) && invoice.DraftCancel != null) { yield return(ModelValidate.checkExistInvoiceTemplateTypeView(invoice.Type ?? 8)); } } else { //check invoice co ton tai hay ko yield return(ModelValidate.checkExistInvoice(key)); } } CustomerDA ctlCustomer = new CustomerDA(); Customer objCus = ctlCustomer.checkExistCustaxcode(invoice.CusTaxCode); if (objCus != null) { invoice.CusAddress = objCus.Address; invoice.CusName = objCus.Name; } WareHouseDA ctlWareHouse = new WareHouseDA(); Warehouse objWareHouse = ctlWareHouse.checkExistWarehouse(invoice.COutputWarehouseID ?? 0); if (objWareHouse != null) { invoice.COutputWarehouseCode = objWareHouse.Code; invoice.COutputWarehouse = objWareHouse.Name; } //check hàng hóa List <String> validateRequestProduct = ModelBase.validateRequiredList <ProductModel>(invoice.products, new string[] { "VATRate", "VATAmount" }); foreach (String item in validateRequestProduct) { yield return(new ValidationResult(item)); } int ComID = invoice.ComID ?? default(int); //Check company //yield return ModelValidate.checkComID(ComID); //Check buyer //yield return ModelValidate.checkExistBuyer(invoice.Buyer); yield return(ModelValidate.checkValueInArrayValue <InvoiceType>(invoice.Type, "Type", ConstantsMultiLanguageKey.E_InValid_Value)); yield return(ModelValidate.checkValueInArrayValue <PaymentMethod>(invoice.PaymentMethod, "PaymentMethod", ConstantsMultiLanguageKey.E_InValid_Value)); yield return(ModelValidate.checkValueInArrayValue <InvoiceStatus>(invoice.Status, "Status", ConstantsMultiLanguageKey.E_InValid_Value)); yield return(ModelValidate.checkValueInArrayValue <PaymentStatus>(invoice.PaymentStatus, "PaymentStatus", ConstantsMultiLanguageKey.E_InValid_Value)); yield return(ModelValidate.checkValueInArrayValue <VATRate>(invoice.VATRate, "VATRate", ConstantsMultiLanguageKey.E_InValid_Value)); yield return(ModelValidate.checkDoDaiSo(invoice.Total.ToString(), LengthNumber.DO_DAI_19, "Total", ConstantsMultiLanguageKey.E_String_Length)); yield return(ModelValidate.checkSoAm(invoice.Total, "Total", ConstantsMultiLanguageKey.E_Number_Value)); yield return(ModelValidate.checkDoDaiSo(invoice.VATAmount.ToString(), LengthNumber.DO_DAI_19, "VATAmount", ConstantsMultiLanguageKey.E_String_Length)); yield return(ModelValidate.checkSoAm(invoice.VATAmount, "VATAmount", ConstantsMultiLanguageKey.E_Number_Value)); yield return(ModelValidate.checkDoDaiSo(invoice.Amount.ToString(), LengthNumber.DO_DAI_19, "Amount", ConstantsMultiLanguageKey.E_String_Length)); yield return(ModelValidate.checkSoAm(invoice.Amount, "Amount", ConstantsMultiLanguageKey.E_Number_Value)); yield return(ModelValidate.checkDoDaiSo(invoice.AmountInWords, LengthNumber.DO_DAI_255, "AmountInWords", ConstantsMultiLanguageKey.E_String_Length)); yield return(ModelValidate.checkDoDaiSo(invoice.OtherFees.ToString(), LengthNumber.DO_DAI_19, "Otherfees", ConstantsMultiLanguageKey.E_String_Length)); yield return(ModelValidate.checkSoAm(invoice.OtherFees, "Otherfees", ConstantsMultiLanguageKey.E_Number_Value)); yield return(ModelValidate.checkDoDaiSo(invoice.ExchangeRate.ToString(), LengthNumber.DO_DAI_19, "ExchangeRate", ConstantsMultiLanguageKey.E_String_Length)); yield return(ModelValidate.checkSoAm(invoice.ExchangeRate, "ExchangeRate", ConstantsMultiLanguageKey.E_Number_Value)); yield return(ModelValidate.checkDoDaiSo(invoice.Currency, LengthNumber.DO_DAI_3, "Currency", ConstantsMultiLanguageKey.E_String_Length)); //yield return ModelValidate.checkCurrency(invoice.Currency); ///Check BusinessDepartment ID BusinessDepartment objBD = null; Business objB = null; PublishInvoice objPInvoice = null; Department objDepartment = null; userdata objuser = null; //Lấy BusinessID yield return(ModelValidate.checkExistBussinessDepartment(invoice.BusinessDepartmentID, out objBD)); if (objBD != null) { //Lấy thông tin Business yield return(ModelValidate.checkExistBussiness(objBD.BusinessID, out objB)); if (invoice.ModifiedDate == null) { invoice.ModifiedDate = DateTime.Now; } if (invoice.PublishDate == null) { invoice.PublishDate = DateTime.Now; } //check khac nhau giua tax code dang nhap va bussinessDepartment if (!invoice.ComTaxCode.Equals(objB.TaxCode)) { yield return(new ValidationResult(ConstantsMultiLanguageKey.E_TAXCODEDANGNHAP_TAXCODEBUSINESSDEPARTMENT)); } //lay tax code invoice.ComTaxCode = objB.TaxCode; if (objB != null) { invoice.Serial = objB.InvSerial; invoice.Pattern = objB.InvPattern; invoice.BusinessID = objBD.BusinessID; //lấy thông tin company CompanyDA ctlCompany = new CompanyDA(); Company company = ctlCompany.checkExistByID(objB.ComID); if (company != null) { invoice.ComName = company.Name; invoice.ComAddress = company.Address; } //Lấy thông tin Publish Invoice yield return(ModelValidate.checkExistPublishInvoice(objB.InvSerial, objB.InvPattern, objB.ComID, out objPInvoice)); if (objPInvoice != null) { invoice.Name = objPInvoice.InvCateName; } //Lấy thông tin Publish Invoice yield return(ModelValidate.checkExistDepartment(objBD.DepartmentID, out objDepartment)); if (objDepartment != null) { invoice.DepartmentID = objBD.DepartmentID; invoice.BranchCode = objDepartment.Code; invoice.BranchName = objDepartment.Name; invoice.BranchAddress = objDepartment.Address; invoice.BranchPhone = objDepartment.Phone; invoice.ComID = objDepartment.ComID; } //Lấy thông tin User yield return(ModelValidate.checkUsersByID(objBD.UserID, out objuser)); if (objuser != null) { if (HttpContext.Current.Request.Headers["Authentication"] != null) { String[] authentication = Untility.decodeBase64(HttpContext.Current.Request.Headers["Authentication"]).Split(':'); String userNameLogin = authentication[0]; //check khac nhau giua username dang nhap va bussinessDepartment if (!objuser.username.Equals(userNameLogin)) { yield return(new ValidationResult(ConstantsMultiLanguageKey.E_USERNAMEDANGNHAP_USERNAMEBUSINESSDEPARTMENT)); } } if (!objuser.IsApproved ?? !eInvoice.Untilities.Common.Constants.ActiveUser.INACTIVE) { yield return(new ValidationResult(String.Format(ConfigMultiLanguage.getMessWithKey(ConstantsMultiLanguageKey.E_User_Active), objuser.username))); } } } } } }
public string UnConfirmPaymentFkeyVNP(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.Unpaid || (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.Unpaid || (inv.Status != InvoiceStatus.SignedInv && inv.Status != InvoiceStatus.AdjustedInv)); if (invKLst.Count > 0) { invLst.AddRange(invKLst); } } catch (Exception ex) { log.Error("UnConfirmPaymentFkey " + ex); return("ERR:6 " + ex.Message); } if (invLst.Count == 0) { return("ERR:13"); // hoa đơn đã gạch nợ/bỏ gạch nợ rồi } if (invSrv.UnConfirmPayment(invLst)) { 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></Item>"); } rv.Append("</Data>"); return(rv.ToString()); } return("ERR:7"); //sao lai khong bo 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 ? }