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 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 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 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)); }
public HttpResponseMessage convertToHTML(DataAPI portal) { Company _currentCompany = ((EInvoiceContext)FXContext.Current).CurrentCompany; int comID = _currentCompany.id; if (_currentCompany == null) { return new HttpResponseMessage() { Content = new StringContent("ERR:1-Unauthorized") } } ; string invPattern = null, invSerial = null; getPublishInvoice(portal.pattern, _currentCompany.id, out invPattern, out invSerial); if (string.IsNullOrWhiteSpace(invPattern)) { return new HttpResponseMessage() { Content = new StringContent("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(new HttpResponseMessage() { Content = new StringContent("ERR:2") }); //khong ton tai hoa don } //lay html IRepositoryINV _repository = IoC.Resolve <IRepositoryINV>(); byte[] invdata = _repository.GetData(currentInv); string err = ""; string rv = _iInvoicSrv.ConvertForStore(currentInv, "", out err); if (!string.IsNullOrWhiteSpace(err)) { log.Error(err); return(new HttpResponseMessage() { Content = new StringContent("ERR:" + err) }); } var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(rv); return(new HttpResponseMessage() { Content = new StringContent(System.Convert.ToBase64String(plainTextBytes)) }); }