/// <summary> /// Listen to carrier and direct to another person /// </summary> /// <param name="sender">previous hero</param> /// <param name="args">order params</param> public void ListenRequest(object sender, OrderEventArgs args) { IDeliver carrier = args.Carrier; this.ReceiveOrderBack += carrier.DeliverOrder; Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine("- Держи, {0}.", args.Carrier); Console.ResetColor(); this.ReceiveOrderBack += ((Farmer)sender).ReceiveFairyObject; if (NeededObject == null) { throw new HeroException(); } else if (ReceiveOrderBack != null) { ReceiveOrderBack(this, new OrderEventArgs(carrier, this, ProducedObject)); } else { throw new HeroException(); } }
public void PublishInv(string pattern, string serial, IInvoice[] mInvoiceList, string username = null) { try { Company currentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany; IDeliver _DeliverService = currentCom.Config.ContainsKey("IDeliver") ? InvServiceFactory.GetDeliver(currentCom.Config["IDeliver"]) : null; if (mInvoiceList.Length <= 50) { Launcher.Instance.Launch(pattern, serial, mInvoiceList); Message = "OK"; } else { for (int i = 0; i < mInvoiceList.Length / 50; i++) { Launcher.Instance.Launch(pattern, serial, mInvoiceList.Skip(i * 50).Take(50).ToArray()); } Message = "OK"; } if (_DeliverService != null) { _DeliverService.PrepareDeliver(mInvoiceList, currentCom); } } catch (Exception ex) { Message = ex.Message; } }
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 deliverInv(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>(); //List<decimal> invNos = new List<decimal>(); Dictionary <string, List <decimal> > patternAndNo = new Dictionary <string, List <decimal> >(); string[] invTokens = lsInv.lstInvToken.Split('_'); foreach (string invToken in invTokens) { string pattern; string serial; decimal invNo; string rv = DataHelper.parseInvToken(invToken, out pattern, out serial, out invNo); if (!rv.Equals("OK")) { return(rv); } if (!patternAndNo.ContainsKey(pattern + ";" + serial)) { patternAndNo[pattern + ";" + serial] = new List <decimal>(); } patternAndNo[pattern + ";" + serial].Add(invNo); } foreach (KeyValuePair <string, List <decimal> > i in patternAndNo) { string[] key = i.Key.Split(';'); IInvoiceService _iInvoicSrv = InvServiceFactory.GetService(key[0], comID); invLst.AddRange(_iInvoicSrv.GetByNo(comID, key[0], key[1], i.Value.ToArray())); } 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:"); }
public string publishInv(ApiPublish publish) { Company currentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany; ILog log = LogManager.GetLogger(typeof(PublishController)); if (!LockTable.Contains(String.Format("{0}${1}", publish.pattern, currentCom.id))) { object lockobj = new object(); LockTable.Add(String.Format("{0}${1}", publish.pattern, currentCom.id), lockobj); } lock (LockTable[String.Format("{0}${1}", publish.pattern, currentCom.id)]) { IDeliver _DeliverService = currentCom.Config.ContainsKey("IDeliver") ? InvServiceFactory.GetDeliver(currentCom.Config["IDeliver"]) : null; IInvoiceService IInvSrv = InvServiceFactory.GetService(publish.pattern, currentCom.id); IList <IInvoice> lst = IInvSrv.GetByID(currentCom.id, publish.invIDs).OrderBy(p => p.CreateDate).ToList(); try { if (lst.Count() <= 50) { Launcher.Instance.Launch(publish.pattern, publish.serial, lst.ToArray()); } else { for (int i = 0; i < lst.Count() / 50; i++) { Launcher.Instance.Launch(publish.pattern, publish.serial, lst.Skip(i * 50).Take(50).ToArray()); } } try { if (_DeliverService != null) { _DeliverService.PrepareDeliver(lst.ToArray(), currentCom); } } catch (Exception ex) { log.Error(ex); } return("OK"); } catch (EInvoice.Core.Launching.NoFactory.OpenTranException ex) { log.Error(ex); return("ERR:14"); } catch (Exception ex) { log.Error(ex); return("ERR:5 " + ex.Message);//loi phat hanh hoa don } } }
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:"); }
/// <summary> /// Listen to carrier and direct to another person /// </summary> /// <param name="sender">previous hero</param> /// <param name="args">order params</param> public void ListenRequest(object sender, OrderEventArgs args) { IDeliver carrier = args.Carrier; this.OrderFairyObject += carrier.ReceiveOrder; this.ReceiveOrderBack += carrier.DeliverOrder; // Create next hero, which can give needed component Farmer farmer = new Farmer("Фермер", Sex.Male, Profession.Farmer); this.OrderFairyObject += farmer.ListenRequest; this.ReceiveOrderBack += ((Farmwife)sender).ReceiveFairyObject; // Couple of words to describe situation Console.ForegroundColor = ConsoleColor.DarkYellow; Console.Write("- {0} меня уже сутки не кормил! Принеси мне поесть {1} и я дам тебе {2}.", farmer, farmer.ProducedObject, this.ProducedObject); Console.ResetColor(); // no needed object - no answer if (NeededObject == null) { if (OrderFairyObject != null) { OrderFairyObject(this, new OrderEventArgs(carrier, farmer, farmer.ProducedObject)); } else { throw new HeroException(); } } else if (ReceiveOrderBack != null) { ReceiveOrderBack(this, new OrderEventArgs(carrier, this, ProducedObject)); } else { throw new HeroException(); } }
/// <summary> /// Listen to carrier and direct to another person /// </summary> /// <param name="sender">previous hero</param> /// <param name="args">order params</param> public void ListenRequest(object sender, OrderEventArgs args) { IDeliver carrier = args.Carrier; this.OrderFairyObject += carrier.ReceiveOrder; this.ReceiveOrderBack += carrier.DeliverOrder; IronForger ironForger = new IronForger("Кузнец", Sex.Male, Profession.IronForger); this.OrderFairyObject += ironForger.ListenRequest; this.ReceiveOrderBack += ((Cow)sender).ReceiveFairyObject; Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine("- Знаешь где живёт {0}? Возьми у него {1}, принеси и нею я скошу тебе {2}", ironForger, ironForger.ProducedObject, this.ProducedObject, this); Console.ResetColor(); if (NeededObject == null) { if (OrderFairyObject != null) { OrderFairyObject(this, new OrderEventArgs(carrier, ironForger, ironForger.ProducedObject)); } else { throw new HeroException(); } } else if (ReceiveOrderBack != null) { ReceiveOrderBack(this, new OrderEventArgs(carrier, this, ProducedObject)); } else { throw new HeroException(); } }
/// <summary> /// Listen to carrier and direct to another person /// </summary> /// <param name="sender">previous hero</param> /// <param name="args">order params</param> public void ListenRequest(object sender, OrderEventArgs args) { IDeliver carrier = args.Carrier; this.ReceiveOrder += carrier.ReceiveOrder; Cow cow = new Cow("Корова"); this.ReceiveOrder += cow.ListenRequest; this.DeliverOrder += ((Hen)sender).HeplHusband; Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine("- Ой, а у меня закончилось {2}! Возле дома в хлеву стоит {0}. Попроси у неё {1}, из него сделаю тебе {2}.", cow, cow.ProducedObject, this.ProducedObject); Console.ResetColor(); if (NeededObject == null) { if (ReceiveOrder != null) { ReceiveOrder(this, new OrderEventArgs(carrier, cow, cow.ProducedObject)); } else { throw new HeroException(); } } else if (DeliverOrder != null) { DeliverOrder(this, new OrderEventArgs(carrier, this, ProducedObject)); } else { throw new HeroException(); } }
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 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 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 ? }
public DeliveryPerson(string name, IDeliver strategy) { this.Name = name; this.Strategy = strategy; }
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 OrderEventArgs(IDeliver carrier, FairyHero supplier, FairyObject fairyObject) { Carrier = carrier; Supplier = supplier; FairyObject = fairyObject; }
public DeliveryPerson(string name, IDeliver strategy) { this.Name = name; this.Strategy = strategy; }
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 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 ? }