public JsonpResult verify(int invNo, string pattern, string serial, int ck) { IInvSrv = InvServiceFactory.GetService(pattern, currentCom.id); iGen = InvServiceFactory.GetGenerator(pattern, currentCom.id); IInvoice inv = IInvSrv.GetByNo(currentCom.id, pattern, serial, invNo); byte[] data = iRepo.GetData(inv); XmlDocument xd = new XmlDocument(); xd.PreserveWhitespace = true; xd.LoadXml(System.Text.Encoding.UTF8.GetString(data)); int k = iGen.VerifyInvoice(Encoding.UTF8.GetBytes(xd.OuterXml)); bool c = false; if (k == 0 || k == 1 || (k == 2 && ck == 0)) { c = true; } return(new JsonpResult { Data = c, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); }
public ActionResult ConvertForStore(int id, string patt) { if (id <= 0) { throw new HttpRequestValidationException(); } Company currentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany; user currentUser = ((EInvoiceContext)FXContext.Current).CurrentUser; string err; IInvoiceService InvSrv = InvServiceFactory.GetService(patt, currentCom.id); IInvoice inv = InvSrv.GetByID(currentCom.id, patt, id); if (inv.Status == InvoiceStatus.CanceledInv || inv.Status == InvoiceStatus.ReplacedInv) { return(Json("nosuccess")); } IStaffService _staSrv = IoC.Resolve <IStaffService>(); Staff staff = _staSrv.SearchByAccountName(currentUser.username, currentCom.id); string name = ""; if (null != staff) { name = staff.FullName; } string HtmlRet = InvSrv.ConvertForStore(inv, name, out err); if (err == string.Empty) { log.Info("Convert Invoice (Luu tru) By : " + HttpContext.User.Identity.Name + " Info-- Pattern: " + inv.Pattern + " Serial: " + inv.Serial + " No: " + inv.No); return(Json(HtmlRet)); } return(Json("nosuccess")); }
public IHttpActionResult RemoteReplacePublish(RemoteAdjustInvoice data) { try { Company currentCompany = ((EInvoiceContext)FXContext.Current).CurrentCompany; XElement elem = XElement.Parse(data.InvData); IEnumerable <XElement> listTemp = elem.Elements("Data"); IDictionary <string, byte[]> dictInv = new Dictionary <string, byte[]>(); foreach (XElement e in listTemp) { string id = e.Element("id").Value; string Signed = e.Element("Signed").Value; dictInv.Add(id, Convert.FromBase64String(Signed)); } IInvoiceService invSrv = InvServiceFactory.GetService(data.OriPattern, currentCompany.id); IInvoice OriInv = invSrv.GetByNo(currentCompany.id, data.OriPattern, data.OriSerial, data.OriNo); IInvoice p = EInvoice.Core.Launching.Launcher.Instance.ReplaceRemote(OriInv, data.OriPattern, data.OriSerial, dictInv); return(Ok(new DataUpdate() { Data = p.Data, No = p.No, Serial = p.Serial })); } catch (Exception ex) { return(Ok("ERROR")); } }
public ActionResult ReportLaunch(ReportsLaunchModel model) { try { Company currentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany; IPublishInvoiceService PubInvSrv = IoC.Resolve <IPublishInvoiceService>(); IList <string> lstPattern = PubInvSrv.LstByPattern(currentCom.id, 2); if (lstPattern.Count == 0) { Messages.AddErrorFlashMessage("Thông báo phát hành chưa được chấp nhận hoặc chưa có hóa đơn."); return(Redirect("/")); } if (lstPattern.Count > 0) { if (string.IsNullOrEmpty(model.Pattern)) { model.Pattern = lstPattern[0]; IInvoiceService IInvSrv = InvServiceFactory.GetService(model.Pattern, currentCom.id); } } List <string> lstSerial = (from p in PubInvSrv.Query where (p.ComId == currentCom.id) && (p.InvPattern == model.Pattern) && (p.Status > 1) select p.InvSerial).Distinct().ToList <string>(); model.lstPattern = new SelectList(lstPattern); model.lstSerial = new SelectList(lstSerial); return(View(model)); } catch (Exception ex) { Messages.AddErrorFlashMessage(ex.Message); return(RedirectToAction("Index", "Home")); } }
public ActionResult Edit(string Pattern, int id) { ICompanyService comSrv = IoC.Resolve <ICompanyService>(); Company currentCom = comSrv.Getbykey(((EInvoiceContext)FXContext.Current).CurrentCompany.id); IPublishInvoiceService _PubIn = IoC.Resolve <IPublishInvoiceService>(); IRegisterTempService _ReTemSvc = IoC.Resolve <IRegisterTempService>(); string ViewName = InvServiceFactory.GetView(Pattern, currentCom.id) + "Edit"; //khoi tao service IInvoiceService IInvSrv = InvServiceFactory.GetService(Pattern, currentCom.id); //lay ve mot ban ghi hoa don IInvoice model = IInvSrv.Getbykey <IInvoice>(id); if (model.Status != InvoiceStatus.NewInv) { Messages.AddErrorFlashMessage("Không thể sửa hóa đơn này."); return(RedirectToAction("Index", new { Pattern = Pattern, Serial = model.Serial })); } //lay va doi danh sach cac san pham thanh doi tuong json //nếu Unit=null thì mặc định hiển thị "" foreach (var item in model.Products) { if (item.Unit == null) { item.Unit = ""; } } //lay ra danh sach cac serial List <string> ser = _PubIn.GetSerialByPatter(model.Pattern, currentCom.id); ViewData["ser"] = ser; //lay thong tin ve don vi ban hang ViewData["company"] = currentCom; model.Note = ""; return(View(ViewName, model)); }
public ActionResult Delete(string Pattern, int id) { if (id <= 0) { throw new HttpRequestValidationException(); } log.Debug("Access - Delete"); Company currentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany; IInvoiceService IInvSrv = InvServiceFactory.GetService(Pattern, currentCom.id); IInvoice model = IInvSrv.Getbykey <IInvoice>(id); try { string ErrorMessage = ""; if (IInvSrv.DeleteInvoice(model, out ErrorMessage) == true) { log.Info("Delete EInvoice by: " + HttpContext.User.Identity.Name + " Info-- ID: " + model.id + "Pattern: " + model.Pattern + " Serial: " + model.Serial + " SoHoaDon: " + model.No.ToString() + " TenKhachHang: " + model.CusName + " MaKhachHang: " + model.CusCode + " SoTien: " + model.Amount); Messages.AddFlashMessage("Xóa hóa đơn thành công."); log.Info("Delete successfull id =" + id); } else { Messages.AddErrorFlashMessage(ErrorMessage); } } catch (Exception ex) { log.Error(" Delete-" + ex.Message); } return(RedirectToAction("Index", new { Pattern = Pattern, Serial = model.Serial })); }
/// <summary> /// Doi trang thai hoa don /// status=2 den status=4 /// </summary> /// <param name="pat"></param> /// <param name="seri"></param> /// <param name="invNo"></param> /// <returns></returns> public ActionResult adInv(string pat, string seri, string invNo) { Company currentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany; IInvoiceService IInvSrv = InvServiceFactory.GetService(pat, currentCom.id); try { //sua lai decimal No; decimal.TryParse(invNo, out No); if (No == 0) { No = -1; } IInvoice inv = IInvSrv.GetByNo(currentCom.id, pat, seri, Convert.ToDecimal(No)); if (inv.Status == InvoiceStatus.SignedInv) { return(Json(new { inv.Pattern, inv.Serial })); } else { return(Json("")); } } catch (Exception ex) { log.Error(" adInv -:" + ex.Message); Messages.AddErrorFlashMessage(Resources.Message.AdjReInv_MInvalidInv); return(RedirectToAction("SearchInvAdjust")); } }
public ActionResult GetXSLTbyPattern(string pattern) { Company currentComp = ((EInvoiceContext)FX.Context.FXContext.Current).CurrentCompany; RegisterTemp temp = InvServiceFactory.GetRegister(pattern, currentComp.id); InvTemplate invTemp = InvServiceFactory.GetTemplateByPattern(pattern, currentComp.id); string xslt = invTemp.XsltFile; string tmp = "<style type=\"text/css\">"; StringBuilder sb = new StringBuilder(); if (!xslt.Contains(tmp)) { tmp = "<style type=\"text/css\" rel=\"stylesheet\">"; } if (xslt.Contains(tmp)) { string head = xslt.Substring(0, xslt.IndexOf(tmp) + tmp.Length); string foot = xslt.Substring(xslt.IndexOf("</style>")); if (!string.IsNullOrWhiteSpace(temp.CssData)) { sb.AppendFormat("{0}{1}{2}{3}{4}", head, temp.CssData, temp.CssLogo, temp.CssBackgr, foot); } else { sb.AppendFormat("{0}{1}{2}{3}{4}", head, invTemp.CssData, invTemp.CssLogo, invTemp.CssBackgr, foot); } } //InvTemplate temp = src.GetByName(tempname); byte[] xsltData = System.Text.Encoding.UTF8.GetBytes(sb.ToString()); return(File(xsltData, "text/xsl")); }
public ActionResult ajxPreview(int idInvoice, string pattern) { try { Company currentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany; IInvoiceService IInvSrv = InvServiceFactory.GetService(pattern, currentCom.id); logtest.Info("call: " + idInvoice + " pattern: " + pattern + " company: " + currentCom.id); IInvoice oInvoice = IInvSrv.Getbykey <IInvoice>(idInvoice); //IViewer _iViewerSrv = IoC.Resolve<IViewer>(); IViewer _iViewerSrv = InvServiceFactory.GetViewer(pattern, currentCom.id); if (oInvoice.Status != InvoiceStatus.NewInv) { IRepositoryINV _iRepoSrv = IoC.Resolve <IRepositoryINV>(); byte[] data = _iRepoSrv.GetData(oInvoice); return(Json(new { invData = _iViewerSrv.GetHtml(data), status = oInvoice.Status })); } else { return(Json(new { invData = _iViewerSrv.GetHtml(System.Text.Encoding.UTF8.GetBytes(oInvoice.GetXMLData())), status = 0 })); } } catch (Exception ex) { logtest.Error(ex); return(Json(new { invData = "Có lỗi xảy ra, vui lòng thực hiện lại.", status = 0 })); } }
public ActionResult getXSLTbyTempName(string tempname) { IInvTemplateService src = IoC.Resolve <IInvTemplateService>(); InvTemplate temp = InvServiceFactory.GetTemplateByName(tempname); byte[] xsltData = System.Text.Encoding.UTF8.GetBytes(temp.XsltFile); return(File(xsltData, "text/xsl")); }
private bool uploadfile(HttpPostedFileBase FileUpload, string idInv, string Pattern, string SerialNo, string NoInv, Company currentCom, string resultLauncher, out string mess) { try { if (FileUpload != null) { bool check = false; //get adjustid string[] listResultLaunchera = resultLauncher.Split(';'); string[] listResultLauncherb = listResultLaunchera[2].ToString().Split('_'); IInvoiceService IInvSrv = InvServiceFactory.GetService(Pattern, currentCom.id); IInvoice invoiceNew = IInvSrv.GetByNo(currentCom.id, Pattern, listResultLaunchera[1].ToString(), Convert.ToDecimal(Convert.ToInt32(listResultLauncherb[1].ToString().Replace(',', ' ')))); int idadjust = (from a in IoC.Resolve <IAdjustInvService>().Query where a.InvId == Convert.ToInt32(idInv) && a.AdjustInvId == invoiceNew.id select a.id).SingleOrDefault(); //end RecordsInv tbRecordsInv = IoC.Resolve <IRecordsInvService>().Query.Where(idAdjust => idAdjust.id == Convert.ToInt32(idadjust)).FirstOrDefault(); IRecordsInvService _SvcRecordsInv = IoC.Resolve <IRecordsInvService>(); string strPath = ""; string strFullPath = ""; string fileext = (Path.GetExtension(FileUpload.FileName).Length > 1) ? Path.GetExtension(FileUpload.FileName).Substring(1) : ""; if (fileext.ToLower() != "docx" && fileext.ToLower() != "pdf" && fileext.ToLower() != "doc") { mess = "File biên bản hủy đính kèm không đúng định dạng !"; return(check); } strPath = @"\RecordsInv\" + currentCom.id + @"\" + Pattern.Replace("/", "") + @"\" + SerialNo.Replace("/", "") + "_" + NoInv + "." + fileext; strFullPath = GetFullPathRecordsCancel(strPath); if (!string.IsNullOrEmpty(strFullPath)) { tbRecordsInv.InvPattern = Pattern; tbRecordsInv.Path = strPath; } _SvcRecordsInv.Update(tbRecordsInv); _SvcRecordsInv.CommitTran(); if (!string.IsNullOrEmpty(strFullPath)) { FileUpload.SaveAs(strFullPath); mess = "Upload biên bản thành công"; } else { mess = "Không upload biên bản thành công!"; } return(true); } else { mess = "Không tồn tại file update!"; return(false); } } catch (Exception ex) { mess = string.Format("Attach file RecordCancel: Pattern={0}, Serial={1}, NoInv={2}, Exception:{3}", Pattern, SerialNo, NoInv, ex.ToString()); return(false); } }
public bool LaunchCollectInvoice(string FromDate, string ToDate, string pattern, string serial) { DateTime?DateFrom = null; DateTime?DateTo = null; if (!string.IsNullOrWhiteSpace(FromDate)) { DateFrom = DateTime.ParseExact(FromDate, "dd/MM/yyyy", null); } if (!string.IsNullOrWhiteSpace(ToDate)) { DateTo = DateTime.ParseExact(ToDate, "dd/MM/yyyy", null); } try { Company currentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany; IInvoiceService IInvSrv = InvServiceFactory.GetService(pattern, currentCom.id); // chỉ tìm NewInv int totalRecords = 0; IList <IInvoice> listInvoice = IInvSrv.SearchInvoice(currentCom.id, pattern, serial, DateFrom, DateTo, 0, 0, out totalRecords, InvoiceStatus.NewInv); if (listInvoice.Count > 0) { //edit phat hanh hoa don 03/07/2014 int[] ids = listInvoice.Select(c => c.id).ToArray(); string resultMessage = ""; LaunchInvoices.Instance.Launch(ids, pattern, serial, out resultMessage); log.Info("Publish EInvoice by: " + HttpContext.User.Identity.Name + " Info-- Pattern: " + pattern + " Serial: " + serial + " SoLuongPhatHanh: " + listInvoice.Count.ToString()); if (resultMessage.Contains("OK")) { Messages.AddFlashMessage(resultMessage); } else if (resultMessage.Contains("ERR:14")) { Messages.AddErrorFlashMessage("Có lô hóa đơn khác đang được phát hành, xin vui lòng thực hiện lại."); } else { Messages.AddErrorFlashMessage(resultMessage); } log.Info("Launch Result: " + resultMessage); } else { Messages.AddErrorFlashMessage("Không có hóa đơn mới tạo."); return(false); } return(true); } catch (Exception ex) { Messages.AddErrorFlashMessage("Có lỗi xảy ra, vui lòng thực hiện lại."); log.Error(" LaunchCollectInvoice -:" + ex); return(false); } }
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 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 GetXSLT(string pattern) { Company currentComp = ((EInvoiceContext)FX.Context.FXContext.Current).CurrentCompany; byte[] xsltData; InvTemplate temp = new InvTemplate(); temp = InvServiceFactory.GetTemplateByPattern(pattern, currentComp.id); xsltData = System.Text.Encoding.UTF8.GetBytes(temp.XsltFile); return(File(xsltData, "text/xsl")); }
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 ActionResult LaunchChoiceByPlugin(string cbid, string Pattern, string Serial, string certificate) { try { string[] idsStr = cbid.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); int[] ids = (from s in idsStr select Convert.ToInt32(s)).ToArray(); if (ids.Length < 0) { return(Json("ERROR:1")); } Company currentCompany = ((EInvoiceContext)FXContext.Current).CurrentCompany; byte[] raw = Convert.FromBase64String(certificate); X509Certificate2 x509Cert = new X509Certificate2(raw); KeyStores _keyStore = KeyStoresManagement.GetKeyStore(currentCompany.id); if (_keyStore == null) { log.Error("keyStores invalid"); return(Json("ERROR:2")); } string serial4Keystore = _keyStore.SerialCert.TrimEnd().ToUpper(); string serial4X509Cert = x509Cert.GetSerialNumberString().TrimEnd().ToUpper(); if (serial4Keystore.CompareTo(serial4X509Cert) != 0) { log.Error("1|" + _keyStore.SerialCert.ToUpper()); log.Error("2|" + x509Cert.GetSerialNumberString().ToUpper()); return(Json("ERROR:2")); } if (DateTime.Parse(x509Cert.GetExpirationDateString()) < DateTime.Today) { return(Json("ERROR:3")); } IInvoiceService IInvSrv = InvServiceFactory.GetService(Pattern, currentCompany.id); IInvoice[] invoicesByIds = IInvSrv.GetByID(currentCompany.id, ids).OrderBy(p => p.id).ToArray(); IList <InvoiceForPlugin> data = new List <InvoiceForPlugin>(); IDictionary <string, string> dictHash = EInvoice.Core.Launching.Launcher.Instance.GetDigestForRemote(Pattern, Serial, invoicesByIds, x509Cert); foreach (KeyValuePair <string, string> pair in dictHash) { data.Add(new InvoiceForPlugin() { Key = pair.Key, Hash = pair.Value }); } IInvSrv.UnbindSession(); return(Json(new { hashdata = data })); } catch (Exception ex) { log.Error(ex); return(Json("ERROR:4")); } }
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 string CertifyReplace(string pattern, IList <IInvoice> invoices, Company currentCompany, bool resend = false) { string ErrorMessages = ""; RegisterTemp temp = InvServiceFactory.GetRegister(pattern, currentCompany.id); ICertifyProvider _CertifyProvider = IoC.Resolve(Type.GetType(temp.ICertifyProvider)) as ICertifyProvider; /// Xac thuc hoa don string errCertify = _CertifyProvider.CertifyReplace(pattern, invoices, currentCompany); if (!string.IsNullOrWhiteSpace(errCertify)) { ErrorMessages = errCertify; } return("value"); }
public ActionResult ResetTem() { try { InvServiceFactory.Initial(); ViewData["MessageResetTem"] = "Reset mau thanh cong."; return(View()); } catch (Exception ex) { log.Error(ex); ViewData["MessageResetTem"] = "Reset mau khong thanh cong."; return(View()); } }
//private void UpdateNode(IInvoice invoiceVat, IInvoiceService IInvSrv, int style) //{ // if (style == 0) // { // invoiceVat.Note += "|| Hóa đơn bị điều chỉnh: bởi: " + HttpContext.User.Identity.Name + " Thời gian điều chỉnh:" + DateTime.Now.ToString(); // } // else // { // invoiceVat.Note += "|| Hóa đơn bị thay thế: bởi: " + HttpContext.User.Identity.Name + " Thời gian thay thế: " + DateTime.Now.ToString(); // } // IInvSrv.Update(invoiceVat); // IInvSrv.CommitChanges(); //} private void UpdateNode(int comid, string pattern, string serial, string no, int style) { IInvoiceService _IInvService = InvServiceFactory.GetService(pattern, comid); IInvoice Oriinv = _IInvService.GetByNo(comid, pattern, serial, Convert.ToDecimal(no)); if (style == 0) { Oriinv.Note += "|| Hóa đơn bị điều chỉnh: bởi: " + HttpContext.User.Identity.Name + " Thời gian điều chỉnh:" + DateTime.Now.ToString(); } else { Oriinv.Note += "|| Hóa đơn bị thay thế: bởi: " + HttpContext.User.Identity.Name + " Thời gian thay thế: " + DateTime.Now.ToString(); } _IInvService.Update(Oriinv); _IInvService.CommitChanges(); }
public ActionResult UpdateCoupon(string Pattern, int id) { if (id <= 0) { throw new HttpRequestValidationException(); } ICompanyService comSrv = IoC.Resolve <ICompanyService>(); Company currentCom = comSrv.Getbykey(((EInvoiceContext)FXContext.Current).CurrentCompany.id); IPublishInvoiceService _PubIn = IoC.Resolve <IPublishInvoiceService>(); IRegisterTempService _ReTemSvc = IoC.Resolve <IRegisterTempService>(); IInvoiceService IInvSrv = InvServiceFactory.GetService(Pattern, currentCom.id); IInvoice model = IInvSrv.Getbykey <IInvoice>(id); string NoteOrder = model.Note; try { TryUpdateModelFromType(model.GetType(), model); model.Note = NoteOrder + " || " + model.Note; IInvSrv.Update(model); IInvSrv.CommitChanges(); log.Info("Edit EInvoice by: " + HttpContext.User.Identity.Name + " Info-- TenKhachHang: " + model.CusName + " MaKhachHang: " + model.CusCode + " SoTien: " + model.Amount); Messages.AddFlashMessage("Sửa phiếu thu thành công."); return(RedirectToAction("Index", new { Pattern = Pattern, Serial = model.Serial })); } catch (HttpRequestValidationException ex) { log.Error("ArgumentException: " + ex); Messages.AddErrorMessage("Dữ liệu không hợp lệ hoặc có chứa mã gây nguy hiểm tiềm tàng cho hệ thống!"); model = IInvSrv.Getbykey <IInvoice>(id); List <string> ser = _PubIn.GetSerialByPatter(Pattern, currentCom.id); ViewData["ser"] = ser; ViewData["company"] = currentCom; string ViewName = InvServiceFactory.GetView(Pattern, currentCom.id) + "Edit"; return(View(ViewName, model)); } catch (Exception ex) { log.Error("Edit -", ex); model.Name = _ReTemSvc.SeachNameInv(Pattern, currentCom.id); List <string> ser = _PubIn.GetSerialByPatter(model.Pattern, currentCom.id); ViewData["ser"] = ser; ViewData["company"] = currentCom; Messages.AddErrorMessage("Có lỗi xảy ra, vui lòng thực hiện lại."); string ViewName = InvServiceFactory.GetView(Pattern, currentCom.id) + "Edit"; return(View(ViewName, model)); } }
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 IHttpActionResult convertForVerify(DataAPI portal) { Company _currentCompany = ((EInvoiceContext)FXContext.Current).CurrentCompany; int comID = _currentCompany.id; if (_currentCompany == null) { return(Unauthorized()); //username khong phu hop - ko tim thay company phu hop voi [username] } string invPattern = null, invSerial = null; getPublishInvoice(portal.pattern, _currentCompany.id, out invPattern, out invSerial); if (string.IsNullOrWhiteSpace(invPattern)) { return(Ok("ERR:20")); } IInvoiceService _iInvoicSrv = InvServiceFactory.GetService(invPattern, comID); IInvoice oInvoiceBase = InvServiceFactory.NewInstance(invPattern, comID); if (portal.invNo > 0) { oInvoiceBase = _iInvoicSrv.GetByNo(comID, invPattern, invSerial, portal.invNo); } else { oInvoiceBase = _iInvoicSrv.GetByFkey(comID, portal.fkey); } if (null == oInvoiceBase) { return(Ok <string>("ERR:6")); //không tìm thấy hóa đơn } //lay html IRepositoryINV _repository = IoC.Resolve <IRepositoryINV>(); byte[] invdata = _repository.GetData(oInvoiceBase); string err = ""; string rv = _iInvoicSrv.ConvertForVerify(oInvoiceBase, "", out err); if (string.IsNullOrEmpty(rv) && !string.IsNullOrEmpty(err)) { return(Ok <string>("ERR:8")); //hóa đơn đã convert rồi } return(Ok <string>(rv)); }
public void Launch(int[] invIds, string pattern, string Serial, out string Messages) { Company currentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany; IInvoiceService IInvSrv = InvServiceFactory.GetService(pattern, currentCom.id); Messages = ""; if (!LockTable.Contains(String.Format("{0}${1}", pattern, currentCom.id))) { object lockobj = new object(); LockTable.Add(String.Format("{0}${1}", pattern, currentCom.id), lockobj); } lock (LockTable[String.Format("{0}${1}", pattern, currentCom.id)]) { IList <IInvoice> lst = IInvSrv.GetByID(currentCom.id, invIds).OrderBy(p => p.ArisingDate).ToList(); ILauncherService _launcher = IoC.Resolve(Type.GetType(currentCom.Config["LauncherType"])) as ILauncherService; _launcher.PublishInv(pattern, Serial, lst.ToArray(), HttpContext.Current.User.Identity.Name); Messages = _launcher.Message; } }
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:"); }
public ActionResult WrapReplaceInvoices(string key, string signed, string pattern, string serial, string no) { try { Company currentCompany = ((EInvoiceContext)FXContext.Current).CurrentCompany; IDictionary <string, byte[]> dictInv = new Dictionary <string, byte[]>(); dictInv.Add(key, Convert.FromBase64String(signed)); IInvoiceService invSrv = InvServiceFactory.GetService(pattern, currentCompany.id); IInvoice OriInv = invSrv.GetByNo(currentCompany.id, pattern, serial, decimal.Parse(no)); IInvoice p = EInvoice.Core.Launching.Launcher.Instance.ReplaceRemote(OriInv, pattern, serial, dictInv); return(Json("OK")); } catch (Exception ex) { log.Error(ex); return(Json("Lỗi: Chưa thay thế được hóa đơn, vui lòng thực hiện lại.")); } }
public ActionResult previewTemplate(int tempId) { InvTemplate it = new InvTemplate(); IInvTemplateService _invTempSrc = IoC.Resolve <IInvTemplateService>(); it = _invTempSrc.Getbykey(tempId); XmlDocument xdoc = new XmlDocument(); xdoc.PreserveWhitespace = true; xdoc.LoadXml(it.XmlFile); XmlProcessingInstruction newPI; String PItext = "type='text/xsl' href='" + FX.Utils.UrlUtil.GetSiteUrl() + "/InvoiceTemplate/GetXSLTbyTempName?tempname=" + it.TemplateName + "'"; newPI = xdoc.CreateProcessingInstruction("xml-stylesheet", PItext); xdoc.InsertBefore(newPI, xdoc.DocumentElement); IViewer _iViewerSrv = InvServiceFactory.GetViewer(it.TemplateName); return(Json(_iViewerSrv.GetHtml(System.Text.Encoding.UTF8.GetBytes(xdoc.OuterXml)))); }
public ActionResult WriteNote(string Pattern, int id, string TypeView) { Company currentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany; IInvoiceService IInvSrv = InvServiceFactory.GetService(Pattern, currentCom.id); IInvoice Einv = IInvSrv.Getbykey <IInvoice>(id); //thong tin view model WriteNoteModel model = new WriteNoteModel(); model.id = id; model.pattern = Pattern; model.TypeView = TypeView; if (string.IsNullOrEmpty(Einv.Note)) { model.Note = ""; } else { model.Note = Einv.Note; } return(View(model)); }
public IHttpActionResult convertForStore(DataAPI portal) { Company _currentCompany = ((EInvoiceContext)FXContext.Current).CurrentCompany; int comID = _currentCompany.id; if (_currentCompany == null) { return(Unauthorized()); //username khong phu hop - ko tim thay company phu hop voi [username] } string invPattern = null, invSerial = null; getPublishInvoice(portal.pattern, _currentCompany.id, out invPattern, out invSerial); if (string.IsNullOrWhiteSpace(invPattern)) { return(Ok("ERR:20")); } IInvoiceService _iInvoicSrv = InvServiceFactory.GetService(invPattern, comID); IInvoice currentInv = InvServiceFactory.NewInstance(invPattern, comID); if (portal.invNo > 0) { currentInv = _iInvoicSrv.GetByNo(comID, invPattern, invSerial, portal.invNo); } else { currentInv = _iInvoicSrv.GetByFkey(comID, portal.fkey); } if (null == currentInv) { return(NotFound()); } //lay html IRepositoryINV _repository = IoC.Resolve <IRepositoryINV>(); byte[] invdata = _repository.GetData(currentInv); string err = ""; string rv = _iInvoicSrv.ConvertForStore(currentInv, "", out err); return(Ok <string>(rv)); }