public ActionResult CancelInvApprove(string[] cbeinv, string hdPattern, string Serial) { Company currentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany; IInvoiceService IInvSrv = InvServiceFactory.GetService(hdPattern, currentCom.id); try { int[] invIds = (from s in cbeinv select Convert.ToInt32(s)).ToArray(); if (invIds.Length < 0) { Messages.AddErrorMessage("Bạn chưa chọn hóa đơn để hủy."); return(RedirectToAction("CancelInvNotReIndex", new { Pattern = hdPattern, Serial = Serial })); } ILogSystemService businessLog = IoC.Resolve <ILogSystemService>(); IList <IInvoice> invLst = IInvSrv.GetByID(currentCom.id, invIds); int succCount = 0; IInvSrv.BeginTran(); var context = (EInvoiceContext)FXContext.Current; foreach (var item in invIds) { IInvoice Oinvoice = IInvSrv.GetByID(currentCom.id, hdPattern, item); if (Oinvoice.Status == InvoiceStatus.CanceledInv || Oinvoice.Status == InvoiceStatus.ReplacedInv || Oinvoice.Status == InvoiceStatus.AdjustedInv) { continue; } succCount++; Oinvoice.Status = InvoiceStatus.CanceledInv; Oinvoice.Note += " || Thực hiện hủy Hóa đơn (Không thay thế): Người hủy:" + context.CurrentUser.username + " Ngày hủy:" + DateTime.Now.ToString(); IInvSrv.Update(Oinvoice); log.Info("INVCANCEL_" + context.CurrentUser.username + "_" + hdPattern + "_" + Oinvoice.Serial + "_" + Oinvoice.No + "_" + DateTime.Now); businessLog.WriteLogCancel(currentCom.id, context.CurrentUser.username, Oinvoice.Pattern, Oinvoice.Serial, Oinvoice.No.ToString("0000000"), Oinvoice.ArisingDate, Oinvoice.Amount, Oinvoice.CusName, Oinvoice.CusAddress, Oinvoice.CusCode, Oinvoice.CusTaxCode, BusinessLogType.Cancel); } if (succCount == 0) { Messages.AddErrorFlashMessage("Kiểm tra lại hóa đơn hủy, có thể đã được thanh toán hoặc sửa đổi."); } else { IInvSrv.CommitTran(); Messages.AddFlashMessage("Tổng số hóa đơn hủy là:" + succCount); } return(RedirectToAction("CancelInvNotReIndex", new { Pattern = hdPattern, Serial = Serial })); } catch (Exception ex) { Messages.AddErrorFlashMessage("Có lỗi trong quá trình xử lý, vui lòng thực hiện lại!"); log.Error(" CancelInvApprove -" + ex.Message); IInvSrv.RolbackTran(); return(RedirectToAction("CancelInvNotReIndex", new { Pattern = hdPattern, Serial = Serial })); } }
public IHttpActionResult RemoteCancel(RemoteInvoice data) { try { Company currentCompany = ((EInvoiceContext)FXContext.Current).CurrentCompany; XElement elem = XElement.Parse(data.InvData); IEnumerable <XElement> listTemp = elem.Elements("key"); IDictionary <string, byte[]> dictInv = new Dictionary <string, byte[]>(); IInvoiceService IInvSrv = InvServiceFactory.GetService(data.InvPattern, currentCompany.id); var context = (EInvoiceContext)FXContext.Current; ILogSystemService businessLog = IoC.Resolve <ILogSystemService>(); int succCount = 0; foreach (var item in listTemp) { IInvoice Oinvoice = IInvSrv.GetByFkey(currentCompany.id, item.Value); if (Oinvoice == null || Oinvoice.Status == InvoiceStatus.CanceledInv || Oinvoice.Status == InvoiceStatus.ReplacedInv || Oinvoice.Status == InvoiceStatus.AdjustedInv) { continue; } succCount++; Oinvoice.Status = InvoiceStatus.CanceledInv; Oinvoice.Note += " || Thực hiện hủy Hóa đơn (Không thay thế): Người hủy:" + context.CurrentUser.username + " Ngày hủy:" + DateTime.Now.ToString(); IInvSrv.Update(Oinvoice); businessLog.WriteLogCancel(currentCompany.id, context.CurrentUser.username, Oinvoice.Pattern, Oinvoice.Serial, Oinvoice.No.ToString("0000000"), Oinvoice.ArisingDate, Oinvoice.Amount, Oinvoice.CusName, Oinvoice.CusAddress, Oinvoice.CusCode, Oinvoice.CusTaxCode, BusinessLogType.Cancel); } if (succCount == 0) { return(Ok <string>("ERROR:Kiểm tra lại hóa đơn hủy, có thể đã được thanh toán hoặc sửa đổi.")); } else { IInvSrv.CommitTran(); return(Ok <string>("OK:Tổng số hóa đơn hủy là:" + succCount)); } } catch (Exception ex) { return(Ok("ERROR")); } }
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); } }