public IHttpActionResult GetRegister(List <RegisterTempApi> data) { try { Company currentComp = ((EInvoiceContext)FX.Context.FXContext.Current).CurrentCompany; IRegisterTempService registempSrv = IoC.Resolve <IRegisterTempService>(); string[] patterns = data.Select(p => p.InvPattern).ToArray(); var temps = registempSrv.Query.Where(p => patterns.Contains(p.InvPattern) && p.ComId == currentComp.id).Select(p => new RegisterData() { Name = p.Name, InvPattern = p.InvPattern, InvoiceType = p.InvoiceTemp.InvoiceType, InvoiceView = p.InvoiceTemp.InvoiceView, NameInvoice = p.NameInvoice, TemplateName = p.InvoiceTemp.TemplateName, ServiceType = p.InvoiceTemp.ServiceType } ); return(Ok(temps)); } catch (Exception ex) { return(NotFound()); } }
public ActionResult Edit(int id) { Company currentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany; IRegisterTempService registerTempSrv = IoC.Resolve <IRegisterTempService>(); IPublishInvoiceService publishInvSrv = IoC.Resolve <IPublishInvoiceService>(); if (publishInvSrv.GetPubOfReg(id, currentCom.id).Count > 0) { Messages.AddErrorFlashMessage("Không được sửa mẫu hóa đơn đang sử dụng."); return(RedirectToAction("Index")); } string logoKey = string.Format("{0}_{1}", currentCom.id, "logo"); string backgroudKey = string.Format("{0}_{1}", currentCom.id, "backgroud"); RegisterTemp registerTemp = registerTempSrv.Getbykey(id); RegisterTempModels model = new RegisterTempModels(); model.tempId = registerTemp.InvoiceTemp.Id; model.CurrentCom = currentCom; model.logoFile = model.imgFile = registerTemp.Name; model.RegisTemp = registerTemp; if (!string.IsNullOrWhiteSpace(registerTemp.CssLogo)) { setCacheContext(logoKey, registerTemp.CssLogo); } if (!string.IsNullOrWhiteSpace(registerTemp.CssBackgr)) { setCacheContext(backgroudKey, registerTemp.CssBackgr); } return(View(model)); }
public ActionResult EditRPublish(int id) { IPublishService pubSrc = IoC.Resolve <IPublishService>(); Publish opub = pubSrc.Getbykey(id); if (opub.Status != PublishStatus.InUse) { PublishModel model = new PublishModel(); Company _currentcompany = IoC.Resolve <ICompanyService>().Getbykey(((EInvoiceContext)FXContext.Current).CurrentCompany.id); ITaxAuthorityService taxSrc = IoC.Resolve <ITaxAuthorityService>(); model.TaxList = new SelectList(from tax in taxSrc.Query select tax, "Code", "Name", opub.TaxAuthorityCode); IRegisterTempService regisSrc = IoC.Resolve <IRegisterTempService>(); model.RegTempList = new SelectList(from re in regisSrc.Query where re.ComId == _currentcompany.id select re, "Id", "Name"); model.mPublish = opub; model.PubInvoiceList = opub.PublishInvoices.SerializeJSON <PublishInvoice>(); return(View(model)); } else { Messages.AddErrorFlashMessage("Thông báo phát hành này không được phép sửa"); return(RedirectToAction("Index")); } }
public ActionResult Create(int tempid) { Company currentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany; IInvTemplateService tempSrv = IoC.Resolve <IInvTemplateService>(); IInvCategoryService cateSrv = IoC.Resolve <IInvCategoryService>(); IRegisterTempService _regSrc = IoC.Resolve <IRegisterTempService>(); if (_regSrc.Query.Where(p => p.InvoiceTemp.Id == tempid && p.ComId == currentCom.id).Count() > 0) { Messages.AddErrorFlashMessage("Mẫu hóa đơn đã được đăng ký, vui lòng chọn mẫu khác."); return(RedirectToAction("Choosetemp")); } RegisterTempModels model = new RegisterTempModels(); InvTemplate invTemp = tempSrv.Getbykey(tempid); decimal i = _regSrc.GetMaxPatternOrder(invTemp.InvCateID, currentCom.id); RegisterTemp temp = new RegisterTemp(); temp.Name = invTemp.TemplateName; temp.NameInvoice = invTemp.InvCateName; temp.InvCateID = invTemp.InvCateID; temp.InvPattern = cateSrv.Getbykey(invTemp.InvCateID).InvPattern + "0"; temp.PatternOrder = i + 1; temp.CssData = invTemp.CssData; temp.IsCertify = invTemp.IsCertify; model.RegisTemp = temp; model.CurrentCom = currentCom; model.tempId = tempid; return(View(model)); }
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(int id) { Company currentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany; IRegisterTempService registerTempSrv = IoC.Resolve <IRegisterTempService>(); IPublishInvoiceService publishInvSrv = IoC.Resolve <IPublishInvoiceService>(); try { if (publishInvSrv.GetPubOfReg(id, currentCom.id).Count > 0) { Messages.AddErrorFlashMessage("Không được xóa mẫu hóa đơn đang sử dụng."); return(RedirectToAction("Index")); } RegisterTemp model = registerTempSrv.Getbykey(id); registerTempSrv.Delete(model); registerTempSrv.CommitChanges(); Messages.AddFlashMessage("Xóa mẫu hóa đơn thành công."); } catch (Exception ex) { log.Error(ex); Messages.AddErrorFlashMessage("Có lỗi xảy ra, vui lòng thực hiện lại."); } return(RedirectToAction("Index")); }
//ten loại hóa đơn lấy từ pattern public ActionResult getInv(string pattern) { Company _currentcompany = ((EInvoiceContext)FXContext.Current).CurrentCompany; IRegisterTempService regisSrc = IoC.Resolve <IRegisterTempService>(); string invcate = (from i in regisSrc.Query where i.InvPattern == pattern && i.ComId == _currentcompany.id select i.InvoiceTemp.InvCateName).Single(); return(Json(new { invcate })); }
public ActionResult EditDecision(DecisionModels model) { if (model.id <= 0) { throw new HttpRequestValidationException(); } IDecisionService decSrc = IoC.Resolve <IDecisionService>(); try { Decision oDec = model.UpdateDecision(new Decision()); //lấy thông tin về mẫu hóa đơn IList <Pupor> lstp = (IList <Pupor>)model.DecDatasource.DeserializeJSON <Pupor>(typeof(IList <Pupor>)); string json = "<Root>"; string lstPattern = ""; foreach (Pupor p in lstp) { json += "<Purpose>" + p.Mucdich + "</Purpose>"; lstPattern += p.InvPattern + ','; } json += "</Root>"; lstPattern = lstPattern.Remove(lstPattern.Length - 1, 1); oDec.ListInvPattern = lstPattern; oDec.Purpose = json; //end //oDec.EffectiveDate = DateTime.ParseExact(Request["EffectiveDate"], "dd/MM/yyyy", null); decSrc.Save(oDec); decSrc.CommitChanges(); Messages.AddFlashMessage(Resources.Message.Dec_UMesSuccess); log.Info("EditDecision by: " + HttpContext.User.Identity.Name); return(RedirectToAction("ListDecision")); } catch (HttpRequestValidationException ex) { return(Redirect("/Home/PotentiallyError")); } catch (ArgumentException ex) { return(Redirect("/Home/PotentiallyError")); } catch (Exception ex) { ICompanyService _comSrv = IoC.Resolve <ICompanyService>(); Company _currentcompany = _comSrv.Getbykey(((EInvoiceContext)FXContext.Current).CurrentCompany.id); IRegisterTempService regisSrc = IoC.Resolve <IRegisterTempService>(); model.RegTempList = new SelectList(from re in regisSrc.Query where re.ComId == _currentcompany.id select re, "InvPattern", "InvPattern"); Messages.AddErrorMessage(Resources.Message.Dec_UMesUnsuccess); log.Error(" EditDecision -" + ex.Message); return(View(model)); } }
public ActionResult ChooseTemp() { RegisterTempChoiseModels model = new RegisterTempChoiseModels(); IInvCategoryService invCateSrv = IoC.Resolve <IInvCategoryService>(); IRegisterTempService _regSrc = IoC.Resolve <IRegisterTempService>(); model.InvCategories = invCateSrv.Query.OrderBy(p => p.id).ToList(); IInvTemplateService _invTempSrc = IoC.Resolve <IInvTemplateService>(); model.CurrentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany; return(View(model)); }
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 ActionResult DetailsDecision(int id) { if (id <= 0) { throw new HttpRequestValidationException(); } IDecisionService decSrc = IoC.Resolve <IDecisionService>(); ICompanyService _comSrv = IoC.Resolve <ICompanyService>(); Company _currentcompany = _comSrv.Getbykey(((EInvoiceContext)FXContext.Current).CurrentCompany.id); IRegisterTempService regisSrc = IoC.Resolve <IRegisterTempService>(); Decision model = decSrc.Getbykey(id); //lấy thông tin ve mẫu phát hành string arr = model.Purpose; XElement elem = XElement.Parse(arr); IEnumerable <XElement> list = (from c in elem.Elements("Purpose") select c).ToList <XElement>(); IList <Pupor> lstp = new List <Pupor>(); string pt = model.ListInvPattern; string[] str = pt.Split(','); List <RegisterTemp> qr = (from r in regisSrc.Query where str.Contains(r.InvPattern) && r.ComId == _currentcompany.id select r).ToList(); int i = 0; if (i < list.Count()) { foreach (XElement xe in list) { Pupor p = new Pupor(); p.Mucdich = xe.Value; p.InvPattern = qr[i].InvPattern; p.InvCateName = qr[i].InvoiceTemp.InvCateName; lstp.Add(p); i++; } } ViewData["Data"] = lstp; //end //string mmddyy = model.EffectiveDate.Day.ToString() + "/" + model.EffectiveDate.Month.ToString() + "/" + model.EffectiveDate.Year.ToString(); //ViewData["mmddyy"] = mmddyy; return(View(model)); }
public ActionResult CreateDecision() { DecisionModels model = new DecisionModels(); IDecisionService decSrc = IoC.Resolve <IDecisionService>(); Company _currentcompany = IoC.Resolve <ICompanyService>().Getbykey(((EInvoiceContext)FXContext.Current).CurrentCompany.id); model.ComID = _currentcompany.id; model.ComName = _currentcompany.Name; model.ParentCompany = _currentcompany.Name; model.ComAddress = _currentcompany.Address; model.TaxCode = _currentcompany.TaxCode; //model.EffectiveDate = DateTime.Now; //đưa ra danh sách các đăng ký mẫu IRegisterTempService regisSrc = IoC.Resolve <IRegisterTempService>(); model.RegTempList = new SelectList(from re in regisSrc.Query where re.ComId == _currentcompany.id select re, "InvPattern", "InvPattern"); //khởi tạo đăng ký loại hóa đơn model.DecDatasource = "[]"; return(View(model)); }
public ActionResult CreateRPublish() { Company _currentcompany = IoC.Resolve <ICompanyService>().Getbykey(((EInvoiceContext)FXContext.Current).CurrentCompany.id); PublishModel model = new PublishModel(); ITaxAuthorityService taxSrc = IoC.Resolve <ITaxAuthorityService>(); IRegisterTempService regisSrc = IoC.Resolve <IRegisterTempService>(); model.TaxList = new SelectList(from tax in taxSrc.Query select tax, "Code", "Name"); model.RegTempList = new SelectList(from re in regisSrc.Query where re.ComId == _currentcompany.id select re, "Id", "Name"); Publish mPub = new Publish(); mPub.ComID = _currentcompany.id; mPub.ComName = _currentcompany.Name; mPub.ComAddress = _currentcompany.Address; mPub.ComTaxCode = _currentcompany.TaxCode; mPub.ComPhone = _currentcompany.Phone; mPub.RepresentPerson = _currentcompany.RepresentPerson; mPub.City = "Hà Nội"; model.mPublish = mPub; model.PubInvoiceList = "[]"; return(View(model)); }
public ActionResult Create(string Pattern) { 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) + "Create"; IInvoice model = InvServiceFactory.NewInstance(Pattern, currentCom.id); model.Pattern = Pattern; model.ComID = currentCom.id; model.Name = _ReTemSvc.SeachNameInv(Pattern, currentCom.id); List <string> ser = _PubIn.GetSerialByPatter(Pattern, currentCom.id); if (ser.Count == 0) { Messages.AddErrorFlashMessage("Dải số đã hết hoặc đã bị hủy."); return(RedirectToAction("Index", new { Pattern = Pattern })); } ViewData["ser"] = ser; ViewData["company"] = currentCom; return(View(ViewName, model)); }
public ActionResult AjxPreviewPubInv(int tempid, string serialNo) { IRegisterTempService regisTempSrv = IoC.Resolve <IRegisterTempService>(); Company currCom = ((EInvoiceContext)FXContext.Current).CurrentCompany; RegisterTemp temp = regisTempSrv.Getbykey(tempid); InvTemplate it = temp.InvoiceTemp; XmlDocument xdoc = new XmlDocument(); xdoc.PreserveWhitespace = true; xdoc.LoadXml(it.XmlFile); // if (xdoc.GetElementsByTagName("ComName")[0] != null) { xdoc.GetElementsByTagName("ComName")[0].InnerText = currCom.Name; } if (xdoc.GetElementsByTagName("ParentName")[0] != null) { xdoc.GetElementsByTagName("ParentName")[0].InnerText = currCom.ParentName; } if (xdoc.GetElementsByTagName("ComAddress")[0] != null) { xdoc.GetElementsByTagName("ComAddress")[0].InnerText = currCom.Address; } if (xdoc.GetElementsByTagName("ComPhone")[0] != null) { xdoc.GetElementsByTagName("ComPhone")[0].InnerText = currCom.Phone; } if (xdoc.GetElementsByTagName("ComFax")[0] != null) { xdoc.GetElementsByTagName("ComFax")[0].InnerText = currCom.Fax; } if (xdoc.GetElementsByTagName("ComBankName")[0] != null) { xdoc.GetElementsByTagName("ComBankName")[0].InnerText = currCom.BankName; } if (xdoc.GetElementsByTagName("ComBankNo")[0] != null) { xdoc.GetElementsByTagName("ComBankNo")[0].InnerText = currCom.BankNumber; } if (xdoc.GetElementsByTagName("ComTaxCode")[0] != null) { xdoc.GetElementsByTagName("ComTaxCode")[0].InnerText = currCom.TaxCode; } if (xdoc.GetElementsByTagName("SerialNo")[0] != null) { xdoc.GetElementsByTagName("SerialNo")[0].InnerText = serialNo; } XmlProcessingInstruction newPI; string urlPub = FX.Utils.UrlUtil.GetSiteUrl(); String PItext = "type='text/xsl' href='"; if (it.CssData != null) { PItext += urlPub + "/InvoiceTemplate/GetXSLTbyPattern/1?pattern=" + temp.InvPattern + "'"; } else { PItext += urlPub + "/InvoiceTemplate/GetXSLTbyTempName?tempname=" + it.TemplateName + "'"; } newPI = xdoc.CreateProcessingInstruction("xml-stylesheet", PItext); xdoc.InsertBefore(newPI, xdoc.DocumentElement); //logtest.Info("tempName: " + tempName + " href: " + PItext); // IViewer _iViewerSrv = IoC.Resolve<IViewer>(); IViewer _iViewerSrv = InvServiceFactory.GetViewer(it.TemplateName); return(Json(_iViewerSrv.GetHtml(System.Text.Encoding.UTF8.GetBytes(xdoc.OuterXml)))); }
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")); }
public ActionResult Create(RegisterTemp temp, string actionName, int tempId) { HttpPostedFileBase logoImg = Request.Files["logoImg"]; HttpPostedFileBase bgrImg = Request.Files["bgrImg"]; string _logoFile = Request["logoFile"]; string _imgFile = Request["imgFile"]; Company currentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany; IInvTemplateService tempSrv = IoC.Resolve <IInvTemplateService>(); IRegisterTempService regisTempSrv = IoC.Resolve <IRegisterTempService>(); string registerPattern = temp.InvPattern + "/" + temp.PatternOrder.ToString("000"); if (regisTempSrv.Query.Where(p => p.InvPattern.ToUpper() == registerPattern.ToUpper() && p.ComId == temp.ComId).Count() > 0) { Messages.AddErrorMessage(string.Format("Mẫu số [{0}] đã được đăng ký cho công ty.", registerPattern)); RegisterTempModels model = new RegisterTempModels(); model.CurrentCom = currentCom; model.RegisTemp = temp; model.tempId = tempId; return(View(model)); } try { InvTemplate invTemp = tempSrv.Getbykey(tempId); temp.InvoiceTemp = invTemp; string logoKey = string.Format("{0}_{1}", currentCom.id, "logo"); string backgroudKey = string.Format("{0}_{1}", currentCom.id, "backgroud"); if (logoImg != null && logoImg.ContentLength > 0) { byte[] byteLogoImg = readContentFilePosted(logoImg); setCacheContext(logoKey, updateCss(invTemp.CssLogo, byteLogoImg)); } if (string.IsNullOrWhiteSpace(_logoFile) && !string.IsNullOrWhiteSpace(invTemp.CssLogo)) { setCacheContext(logoKey, invTemp.CssLogo); } if (bgrImg != null && bgrImg.ContentLength > 0) { byte[] bytebgrImg = readContentFilePosted(bgrImg); setCacheContext(backgroudKey, updateCss(invTemp.CssBackgr, bytebgrImg, false)); } if (string.IsNullOrWhiteSpace(_imgFile) && !string.IsNullOrWhiteSpace(invTemp.CssBackgr)) { setCacheContext(backgroudKey, invTemp.CssBackgr); } temp.CssData = !string.IsNullOrWhiteSpace(temp.CssData) ? temp.CssData : invTemp.CssData; if (actionName == "preview") { RegisterTempModels model = new RegisterTempModels(); model.CurrentCom = currentCom; model.RegisTemp = temp; model.tempId = tempId; model.imgFile = _imgFile; model.logoFile = _logoFile; StringBuilder sumSb = new StringBuilder(); sumSb.AppendFormat("{0}{1}{2}", temp.CssData, getCacheContext(logoKey), getCacheContext(backgroudKey)); XmlDocument xdoc = new XmlDocument(); xdoc.PreserveWhitespace = true; xdoc.LoadXml(invTemp.XmlFile); if (xdoc.GetElementsByTagName("ComName")[0] != null) { xdoc.GetElementsByTagName("ComName")[0].InnerText = currentCom.Name; } if (xdoc.GetElementsByTagName("ComAddress")[0] != null) { xdoc.GetElementsByTagName("ComAddress")[0].InnerText = currentCom.Address; } if (xdoc.GetElementsByTagName("ComPhone")[0] != null) { xdoc.GetElementsByTagName("ComPhone")[0].InnerText = currentCom.Phone; } if (xdoc.GetElementsByTagName("ComBankNo")[0] != null) { //xdoc.GetElementsByTagName("ComFax")[0].InnerText = comFax; xdoc.GetElementsByTagName("ComBankNo")[0].InnerText = currentCom.BankNumber; } if (xdoc.GetElementsByTagName("ComTaxCode")[0] != null) { xdoc.GetElementsByTagName("ComTaxCode")[0].InnerText = currentCom.TaxCode; } XmlNode root = xdoc.DocumentElement; //Create a new node. XmlElement elem = xdoc.CreateElement("CssData"); elem.InnerText = sumSb.ToString(); //Add the node to the document. root.AppendChild(elem); XmlProcessingInstruction newPI; String PItext = "type='text/xsl' href='" + FX.Utils.UrlUtil.GetSiteUrl() + "/RegisterTemp/getXSLTbyTempName?tempname=" + invTemp.TemplateName + "'"; newPI = xdoc.CreateProcessingInstruction("xml-stylesheet", PItext); xdoc.InsertBefore(newPI, xdoc.DocumentElement); IViewer _iViewerSrv = InvServiceFactory.GetViewer(invTemp.TemplateName); ViewData["previewContent"] = _iViewerSrv.GetHtml(System.Text.Encoding.UTF8.GetBytes(xdoc.OuterXml)); return(View(model)); } temp.ICertifyProvider = temp.IsCertify ? temp.ICertifyProvider : ""; temp.InvPattern = registerPattern; if (regisTempSrv.GetbyPattern(temp.InvPattern, currentCom.id) != null) { Messages.AddErrorFlashMessage("Mẫu số đã được đăng ký, sử dụng mẫu số khác!"); RegisterTempModels model = new RegisterTempModels(); model.CurrentCom = currentCom; model.RegisTemp = temp; model.tempId = tempId; model.imgFile = _imgFile; model.logoFile = _logoFile; return(View(model)); } temp.ComId = currentCom.id; temp.InvCateID = invTemp.InvCateID; temp.CssLogo = getCacheContext(logoKey); temp.CssBackgr = getCacheContext(backgroudKey); regisTempSrv.CreateNew(temp); regisTempSrv.CommitChanges(); Messages.AddFlashMessage("Đăng ký mẫu hóa đơn thành công!"); return(RedirectToAction("Index")); } catch (Exception ex) { log.Error(ex); Messages.AddErrorMessage("Có lỗi xảy ra, vui lòng thực hiện lại."); RegisterTempModels model = new RegisterTempModels(); model.CurrentCom = currentCom; model.RegisTemp = temp; model.tempId = tempId; model.imgFile = _imgFile; model.logoFile = _logoFile; return(View(model)); } }
public ActionResult Edit(string Pattern, int id, string PubDatasource) { 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 { string ErrorMessage = ""; TryUpdateModelFromType(model.GetType(), model); model.CusCode = !string.IsNullOrWhiteSpace(model.CusCode) ? model.CusCode : model.CusTaxCode; model.Note = NoteOrder + " || " + model.Note; if (!String.IsNullOrEmpty(PubDatasource) && PubDatasource != "[]") { ICustomerService _CusSvc = FX.Core.IoC.Resolve <ICustomerService>(); var Typecus = (from c in _CusSvc.Query where c.Code == model.CusCode && c.CusType == 1 select c.CusType).FirstOrDefault(); if (Typecus == 0) { model.CusSignStatus = cusSignStatus.NocusSignStatus; } else { model.CusSignStatus = cusSignStatus.NoSignStatus; } IList <ProductInv> lstproduct = (IList <ProductInv>)PubDatasource.DeserializeJSON <ProductInv>(typeof(IList <ProductInv>)); if (IInvSrv.UpdateInvoice(lstproduct, model, out ErrorMessage) == true) { log.Info("Edit EInvoice by: " + HttpContext.User.Identity.Name + " Info-- TenKhachHang: " + model.CusName + " MaKhachHang: " + model.CusCode + " SoTien: " + model.Amount); Messages.AddFlashMessage("Cập nhật hóa đơn thành công."); return(RedirectToAction("Index", new { Pattern = Pattern, Serial = model.Serial })); } else { Messages.AddErrorMessage(ErrorMessage); } model.Products = (from pr in lstproduct select pr as IProductInv).ToList(); } else { Messages.AddErrorMessage("Chưa nhập thông tin sản phẩm"); } model.Name = _ReTemSvc.SeachNameInv(Pattern, currentCom.id); List <string> ser = _PubIn.GetSerialByPatter(model.Pattern, currentCom.id); ViewData["ser"] = ser; ViewData["company"] = currentCom; string ViewName = InvServiceFactory.GetView(Pattern, currentCom.id) + "Edit"; return(View(ViewName, model)); } 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"); if (!String.IsNullOrEmpty(PubDatasource)) { IList <ProductInv> lstproduct = (IList <ProductInv>)PubDatasource.DeserializeJSON <ProductInv>(typeof(IList <ProductInv>)); model.Products = (from pr in lstproduct select pr as IProductInv).ToList(); } string ViewName = InvServiceFactory.GetView(Pattern, currentCom.id) + "Edit"; return(View(ViewName, model)); } }
public ActionResult CreateRPublish(Publish mPub, string PubInvoiceList) { IPublishService pubSrc = IoC.Resolve <IPublishService>(); ITaxAuthorityService taxSrv = IoC.Resolve <ITaxAuthorityService>(); ICompanyService _comSrv = IoC.Resolve <ICompanyService>(); string message = ""; try { mPub.TaxAuthorityName = (from tax in taxSrv.Query where tax.Code == mPub.TaxAuthorityCode select tax.Name).FirstOrDefault(); JavaScriptSerializer jss = new JavaScriptSerializer(); IList <PublishInvoice> lst = jss.Deserialize <IList <PublishInvoice> >(PubInvoiceList); Company _currentcompany = _comSrv.Getbykey(((EInvoiceContext)FXContext.Current).CurrentCompany.id); foreach (var it in lst) { IPublishInvoiceService pubinvSrv = IoC.Resolve <IPublishInvoiceService>(); string invSer = string.Format("{0}/{1}E", it.InvSerialPrefix, it.InvSerialSuffix); var old = pubinvSrv.Query.Where(p => p.RegisterID == it.RegisterID && p.InvSerial == invSer && p.StartDate > it.StartDate && p.ComId == _currentcompany.id).FirstOrDefault(); if (old != null) { Messages.AddErrorMessage(string.Format("Thông báo có ký hiệu {0}, phải có ngày bắt đầu sau ngày: {1}", old.InvSerial, old.StartDate.ToString("dd/MM/yyyy"))); PublishModel model = new PublishModel(); model.mPublish = mPub; ITaxAuthorityService taxSrc = IoC.Resolve <ITaxAuthorityService>(); model.TaxList = new SelectList(from tax in taxSrc.Query select tax, "Code", "Name", mPub.TaxAuthorityCode); IRegisterTempService regisSrc = IoC.Resolve <IRegisterTempService>(); model.RegTempList = new SelectList(from re in regisSrc.Query where re.ComId == _currentcompany.id select re, "Id", "Name"); model.PubInvoiceList = lst.SerializeJSON <PublishInvoice>(); return(View(mPub)); } var pub = pubinvSrv.Query.Where(p => p.RegisterID == it.RegisterID && p.InvSerial == invSer && p.FromNo == it.FromNo && p.ComId == _currentcompany.id); if (pub.Count() > 0) { Messages.AddErrorMessage(string.Format("Đã tồn tại giải hóa đơn tương ứng ký hiệu {0}", it.InvSerial)); PublishModel model = new PublishModel(); model.mPublish = mPub; ITaxAuthorityService taxSrc = IoC.Resolve <ITaxAuthorityService>(); model.TaxList = new SelectList(from tax in taxSrc.Query select tax, "Code", "Name", mPub.TaxAuthorityCode); IRegisterTempService regisSrc = IoC.Resolve <IRegisterTempService>(); model.RegTempList = new SelectList(from re in regisSrc.Query where re.ComId == _currentcompany.id select re, "Id", "Name"); model.PubInvoiceList = lst.SerializeJSON <PublishInvoice>(); return(View(mPub)); } } if (pubSrc.CreateNew(mPub, lst, out message) == true) { _currentcompany.IsUsed = true; _comSrv.Update(_currentcompany); _comSrv.CommitChanges(); StringBuilder InvInfo = new StringBuilder(); for (int i = 0; i < lst.Count; i++) { InvInfo.AppendFormat("{0};{1};{2};{3};{4}_", lst[i].RegisterID, lst[i].InvSerial, lst[i].Quantity, lst[i].FromNo, lst[i].ToNo); } log.Info("Create Publish by: " + HttpContext.User.Identity.Name + "|InvInfo:" + InvInfo.ToString()); Messages.AddFlashMessage("Tạo phát hành thành công!"); return(RedirectToAction("Index")); } else { log.Error("Create Publish:" + message); Messages.AddErrorMessage("Có lỗi xảy ra, vui lòng thực hiện lại!"); PublishModel model = new PublishModel(); model.mPublish = mPub; ITaxAuthorityService taxSrc = IoC.Resolve <ITaxAuthorityService>(); model.TaxList = new SelectList(from tax in taxSrc.Query select tax, "Code", "Name", mPub.TaxAuthorityCode); IRegisterTempService regisSrc = IoC.Resolve <IRegisterTempService>(); model.RegTempList = new SelectList(from re in regisSrc.Query where re.ComId == _currentcompany.id select re, "Id", "Name"); model.PubInvoiceList = lst.SerializeJSON <PublishInvoice>(); return(View(mPub)); } } catch (Exception ex) { JavaScriptSerializer jss = new JavaScriptSerializer(); IList <PublishInvoice> lst = jss.Deserialize <IList <PublishInvoice> >(PubInvoiceList); log.Error(" CreateRPublish -" + ex); Messages.AddErrorMessage("Có lỗi xảy ra, vui lòng thực hiện lại."); Company _currentcompany = _comSrv.Getbykey(((EInvoiceContext)FXContext.Current).CurrentCompany.id); PublishModel model = new PublishModel(); model.mPublish = mPub; ITaxAuthorityService taxSrc = IoC.Resolve <ITaxAuthorityService>(); model.TaxList = new SelectList(from tax in taxSrc.Query select tax, "Code", "Name", mPub.TaxAuthorityCode); IRegisterTempService regisSrc = IoC.Resolve <IRegisterTempService>(); model.RegTempList = new SelectList(from re in regisSrc.Query where re.ComId == _currentcompany.id select re, "Id", "Name"); model.PubInvoiceList = lst.SerializeJSON <PublishInvoice>(); return(View(mPub)); } }
public IHttpActionResult GetDigest(RemoteInvoice data) { ILog log = LogManager.GetLogger(typeof(RemoteLauncherController)); XmlSchemaValidator validator = new XmlSchemaValidator(); if (!validator.ValidXmlDoc(data.InvData, "", AppDomain.CurrentDomain.BaseDirectory + @"xmlvalidate\VATInVoice_ws.xsd")) { log.Error("ERR:3-" + validator.ValidationError); return(Ok("ERR:3-" + validator.ValidationError)); //du lieu dau vao khong hop le } Company _currentCompany = ((EInvoiceContext)FXContext.Current).CurrentCompany; int comID = _currentCompany.id; if (_currentCompany == null) { return(Ok("ERR:4")); } string nameInvoice = ""; IRegisterTempService regisSrv = IoC.Resolve <IRegisterTempService>(); IPublishInvoiceService pSrv = IoC.Resolve <IPublishInvoiceService>(); RegisterTemp rtemp = regisSrv.GetbyPattern(data.InvPattern, _currentCompany.id); nameInvoice = rtemp.NameInvoice; regisSrv.UnbindSession(rtemp); XElement elem = XElement.Parse(data.InvData); IList <IInvoice> lstINV = new List <IInvoice>(); IEnumerable <XElement> listTemp = elem.Elements("Inv"); IList <String> lstKey = new List <String>(); if (listTemp.Count() > 10) { 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(data.InvPattern, comID); string read = string.Concat(ele); inv.DeserializeFromXML(read); inv.No = 0; inv.Name = nameInvoice; inv.Pattern = data.InvPattern; inv.Serial = data.InvSerial; 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")); } byte[] raw = Convert.FromBase64String(data.CertBase64String); X509Certificate2 x509Cert = new X509Certificate2(raw); IDictionary <string, string> dict = EInvoice.Core.Launching.Launcher.Instance.GetDigestForRemote(data.InvPattern, data.InvSerial, lstINV.ToArray(), x509Cert); return(Ok(dict)); }
public IHttpActionResult GetDigestForReplace(RemoteAdjustInvoice data) { ILog log = LogManager.GetLogger(typeof(RemoteLauncherController)); XmlSchemaValidator validator = new XmlSchemaValidator(); if (!validator.ValidXmlDoc(data.InvData, "", AppDomain.CurrentDomain.BaseDirectory + @"xmlvalidate\replacevatinvoice.xsd")) { log.Error("ERR:3-" + validator.ValidationError); return(Ok("ERR:3-" + validator.ValidationError)); //du lieu dau vao khong hop le } Company _currentCompany = ((EInvoiceContext)FXContext.Current).CurrentCompany; int comID = _currentCompany.id; if (_currentCompany == null) { return(Ok("ERR:4")); } IInvoiceService invSrv = InvServiceFactory.GetService(data.OriPattern, comID); IInvoice OriInv = invSrv.GetByNo(comID, data.OriPattern, data.OriSerial, data.OriNo); if (!checkInvNumber(comID, OriInv.Pattern, OriInv.Serial)) { log.Error("het so hoa don trong dai."); return(Ok <string>("ERR:6")); //het so hoa don trong dai } IRegisterTempService regisSrv = IoC.Resolve <IRegisterTempService>(); ICustomerService _cusSvr = IoC.Resolve <ICustomerService>(); IInvoice inv = (InvoiceBase)InvServiceFactory.NewInstance(OriInv.Pattern, comID); string read = data.InvData;//string.Concat(invs.ElementAt(i)); DataHelper.DeserializeEinvFromXML(read, inv); inv.No = 0; inv.Name = OriInv.Name; inv.Pattern = OriInv.Pattern; inv.Serial = OriInv.Serial; inv.CreateBy = System.Web.HttpContext.Current.User.Identity.Name; inv.ProcessInvNote = ""; string strReplace = (_currentCompany.Config.ContainsKey("ReplaceString")) ? _currentCompany.Config["ReplaceString"] : "Hóa đơn này thay thế hóa đơn số: @InvNo, Ký hiệu: @InvSerial, Gửi ngày @InvDay Tháng @InvMonth Năm @InvYear"; strReplace = strReplace.Replace("@InvNo", OriInv.No.ToString(Utils.MAX_NO_LENGTH)).Replace("@InvSerial", OriInv.Serial).Replace("@InvDay", OriInv.ArisingDate.Day.ToString()).Replace("@InvMonth", OriInv.ArisingDate.Month.ToString()).Replace("@InvYear", OriInv.ArisingDate.Year.ToString()); inv.ProcessInvNote = strReplace; inv.Type = InvoiceType.ForReplace; 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 (OriInv.Status == InvoiceStatus.SignedInv || OriInv.Status == InvoiceStatus.AdjustedInv) { byte[] raw = Convert.FromBase64String(data.CertBase64String); X509Certificate2 x509Cert = new X509Certificate2(raw); IDictionary <string, string> dict = EInvoice.Core.Launching.Launcher.Instance.GetDigestForRemote(data.OriPattern, data.OriSerial, new IInvoice[] { inv }, x509Cert); return(Ok(dict)); } return(NotFound()); }
public ActionResult LaunchReplaceByPlugin(string invData, string NewPattern, string NewSerial, int OriNo, string OriPattern, string OriSerial, string CertBase64String) { try { Company _currentCompany = ((EInvoiceContext)FXContext.Current).CurrentCompany; int comID = _currentCompany.id; if (_currentCompany == null) { return(Json(new { error = "ERR:2" })); } byte[] raw = Convert.FromBase64String(CertBase64String); X509Certificate2 x509Cert = new X509Certificate2(raw); KeyStores _keyStore = KeyStoresManagement.GetKeyStore(_currentCompany.id); if (_keyStore.SerialCert.ToUpper().CompareTo(x509Cert.GetSerialNumberString().ToUpper()) != 0) { return(Json("ERROR:2")); } if (DateTime.Parse(x509Cert.GetExpirationDateString()) < DateTime.Today) { return(Json("ERROR:3")); } IInvoiceService invSrv = InvServiceFactory.GetService(OriPattern, comID); IInvoice OriInv = invSrv.GetByNo(comID, OriPattern, OriSerial, OriNo); IRegisterTempService regisSrv = IoC.Resolve <IRegisterTempService>(); ICustomerService _cusSvr = IoC.Resolve <ICustomerService>(); IInvoice inv = InvServiceFactory.NewInstance(NewPattern, comID); inv.DeserializeFromJSON(invData); inv.Pattern = NewPattern; inv.Serial = NewSerial; inv.Status = InvoiceStatus.NewInv; DateTime dt = OriInv.ArisingDate; string strReplace = (_currentCompany.Config.ContainsKey("ReplaceString")) ? _currentCompany.Config["ReplaceString"] : "Hóa đơn này thay thế hóa đơn số: @InvNo, Ký hiệu: @InvSerial, Gửi ngày @InvDay Tháng @InvMonth Năm @InvYear"; strReplace = strReplace.Replace("@InvNo", OriInv.No.ToString(Utils.MAX_NO_LENGTH)).Replace("@InvSerial", OriInv.Serial).Replace("@InvPattern", OriInv.Pattern).Replace("@InvDay", OriInv.ArisingDate.Day.ToString()).Replace("@InvMonth", OriInv.ArisingDate.Month.ToString()).Replace("@InvYear", OriInv.ArisingDate.Year.ToString()); inv.ProcessInvNote = strReplace; inv.Type = InvoiceType.ForReplace; 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 (OriInv.Status == InvoiceStatus.SignedInv || OriInv.Status == InvoiceStatus.AdjustedInv) { IDictionary <string, string> dict = EInvoice.Core.Launching.Launcher.Instance.GetDigestForRemote(OriPattern, OriSerial, new IInvoice[] { inv }, x509Cert); if (dict.Count == 0) { return(Json("ERROR:4")); } var dictFirst = dict.FirstOrDefault(); invSrv.UnbindSession(); return(Json(new { hashdata = dictFirst })); } return(Json("ERROR:4")); } catch (Exception ex) { log.Error(ex); return(Json("ERROR:4")); } }
public ActionResult UpdatePublish(int id, string PubInvoiceList) { if (id <= 0) { throw new HttpRequestValidationException(); } IPublishService pubSrc = IoC.Resolve <IPublishService>(); ITaxAuthorityService taxSrv = IoC.Resolve <ITaxAuthorityService>(); Publish opub = pubSrc.Getbykey(id); try { TryUpdateModel <Publish>(opub); opub.TaxAuthorityName = (from tax in taxSrv.Query where tax.Code == opub.TaxAuthorityCode select tax.Name).FirstOrDefault(); JavaScriptSerializer jss = new JavaScriptSerializer(); IList <PublishInvoice> lst = jss.Deserialize <IList <PublishInvoice> >(PubInvoiceList); foreach (var it in lst) { IPublishInvoiceService pubinvSrv = IoC.Resolve <IPublishInvoiceService>(); ICompanyService _comSrv = IoC.Resolve <ICompanyService>(); Company _currentcompany = _comSrv.Getbykey(((EInvoiceContext)FXContext.Current).CurrentCompany.id); string invSer = string.Format("{0}/{1}E", it.InvSerialPrefix, it.InvSerialSuffix); var old = pubinvSrv.Query.Where(p => p.RegisterID == it.RegisterID && p.InvSerial == invSer && p.StartDate > it.StartDate && p.FromNo < it.FromNo && p.ComId == _currentcompany.id).FirstOrDefault(); if (old != null) { Messages.AddErrorMessage(string.Format("Thông báo có ký hiệu {0}, phải có ngày bắt đầu từ ngày: {1}", old.InvSerial, old.StartDate.ToString("dd/MM/yyyy"))); PublishModel model = new PublishModel(); model.mPublish = opub; ITaxAuthorityService taxSrc = IoC.Resolve <ITaxAuthorityService>(); model.TaxList = new SelectList(from tax in taxSrc.Query select tax, "Code", "Name", opub.TaxAuthorityCode); IRegisterTempService regisSrc = IoC.Resolve <IRegisterTempService>(); model.RegTempList = new SelectList(from re in regisSrc.Query where re.ComId == _currentcompany.id select re, "Id", "Name"); model.PubInvoiceList = opub.PublishInvoices.SerializeJSON <PublishInvoice>(); return(View("EditRPublish", model)); } else { old = pubinvSrv.Query.Where(p => p.RegisterID == it.RegisterID && p.InvSerial == invSer && p.StartDate <it.StartDate && p.FromNo> it.FromNo && p.ComId == _currentcompany.id).FirstOrDefault(); if (old != null) { Messages.AddErrorMessage(string.Format("Thông báo có ký hiệu {0}, phải có ngày bắt đầu nhỏ hơn ngày: {1}", old.InvSerial, old.StartDate.ToString("dd/MM/yyyy"))); PublishModel model = new PublishModel(); model.mPublish = opub; ITaxAuthorityService taxSrc = IoC.Resolve <ITaxAuthorityService>(); model.TaxList = new SelectList(from tax in taxSrc.Query select tax, "Code", "Name", opub.TaxAuthorityCode); IRegisterTempService regisSrc = IoC.Resolve <IRegisterTempService>(); model.RegTempList = new SelectList(from re in regisSrc.Query where re.ComId == _currentcompany.id select re, "Id", "Name"); model.PubInvoiceList = opub.PublishInvoices.SerializeJSON <PublishInvoice>(); return(View("EditRPublish", model)); } } } string mess = ""; if (pubSrc.Update(opub, lst, out mess) == true) { StringBuilder InvInfo = new StringBuilder(); for (int i = 0; i < lst.Count; i++) { InvInfo.AppendFormat("{0};{1};{2};{3};{4}_", lst[i].RegisterID, lst[i].InvSerial, lst[i].Quantity, lst[i].FromNo, lst[i].ToNo); } log.Info("Edit Publish by: " + HttpContext.User.Identity.Name + "|InvInfo:" + InvInfo.ToString()); Messages.AddFlashMessage("Sửa thành công"); return(RedirectToAction("Index")); } else { log.Error("Update Publish:" + mess); ICompanyService _comSrv = IoC.Resolve <ICompanyService>(); Company _currentcompany = _comSrv.Getbykey(((EInvoiceContext)FXContext.Current).CurrentCompany.id); PublishModel model = new PublishModel(); model.mPublish = opub; ITaxAuthorityService taxSrc = IoC.Resolve <ITaxAuthorityService>(); model.TaxList = new SelectList(from tax in taxSrc.Query select tax, "Code", "Name", opub.TaxAuthorityCode); IRegisterTempService regisSrc = IoC.Resolve <IRegisterTempService>(); model.RegTempList = new SelectList(from re in regisSrc.Query where re.ComId == _currentcompany.id select re, "Id", "Name"); model.PubInvoiceList = opub.PublishInvoices.SerializeJSON <PublishInvoice>(); Messages.AddErrorMessage(mess); return(View("EditRPublish", model)); } } catch (Exception ex) { log.Error("EditRPublish -" + ex); Messages.AddErrorMessage("Có lỗi xảy ra, vui lòng thực hiện lại!"); PublishModel model = new PublishModel(); model.mPublish = opub; ICompanyService _comSrv = IoC.Resolve <ICompanyService>(); Company _currentcompany = _comSrv.Getbykey(((EInvoiceContext)FXContext.Current).CurrentCompany.id); ITaxAuthorityService taxSrc = IoC.Resolve <ITaxAuthorityService>(); model.TaxList = new SelectList(from tax in taxSrc.Query select tax, "Code", "Name", opub.TaxAuthorityCode); IRegisterTempService regisSrc = IoC.Resolve <IRegisterTempService>(); model.RegTempList = new SelectList(from re in regisSrc.Query where re.ComId == _currentcompany.id select re, "Id", "Name"); model.PubInvoiceList = opub.PublishInvoices.SerializeJSON <PublishInvoice>(); return(View("EditRPublish", model)); } }
public ActionResult EditDecision(int id) { IDecisionService decSrc = IoC.Resolve <IDecisionService>(); Company _currentcompany = IoC.Resolve <ICompanyService>().Getbykey(((EInvoiceContext)FXContext.Current).CurrentCompany.id); IRegisterTempService regisSrc = IoC.Resolve <IRegisterTempService>(); Decision oDec = decSrc.Getbykey(id); //khoi tao mot decision models DecisionModels model = new DecisionModels(); model.City = oDec.City; model.ComAddress = oDec.ComAddress; model.ComID = oDec.ComID; model.ComName = oDec.ComName; model.DecisionNo = oDec.DecisionNo; model.Director = oDec.Director; model.EffectiveDate = oDec.EffectiveDate; model.EffectDate = oDec.EffectDate; model.id = oDec.id; model.ParentCompany = oDec.ParentCompany; model.Requester = oDec.Requester; model.SystemName = oDec.SystemName; model.SoftApplication = oDec.SoftApplication; model.TechDepartment = oDec.TechDepartment; model.Workflow = oDec.Workflow; model.Responsibility = oDec.Responsibility; model.Destination = oDec.Destination; model.RegTempList = new SelectList(from re in regisSrc.Query where re.ComId == _currentcompany.id select re, "InvPattern", "InvPattern"); //lấy thông tin về mẫu hóa đơn string arr = oDec.Purpose; XElement elem = XElement.Parse(arr); IEnumerable <XElement> list = (from c in elem.Elements("Purpose") select c).ToList <XElement>(); IList <Pupor> lstp = new List <Pupor>(); string pt = oDec.ListInvPattern; string[] str = pt.Split(','); List <RegisterTemp> qr = (from r in regisSrc.Query where str.Contains(r.InvPattern) && r.ComId == _currentcompany.id select r).ToList(); int i = 0; if (i < list.Count()) { foreach (XElement xe in list) { Pupor p = new Pupor(); p.Mucdich = xe.Value; p.InvPattern = qr[i].InvPattern; p.InvCateName = qr[i].InvoiceTemp.InvCateName; lstp.Add(p); i++; } } model.DecDatasource = lstp.SerializeJSON <Pupor>(); //end if (oDec.Status != 2) { model.TaxCode = _currentcompany.TaxCode; return(View(model)); } else { return(RedirectToAction("ListDecision")); } }