Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
        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));
        }
Ejemplo n.º 4
0
        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);
            }
        }
Ejemplo n.º 5
0
        private string processReplace(string xmlData, string pattern, string fkey, string serial = null, decimal invNo = 0, int convert = 0)
        {
            if (FXContext.Current == null)
            {
                return("ERR:1");
            }
            try
            {
                XmlSchemaValidator validator = new XmlSchemaValidator();
                if (!validator.ValidXmlDoc(xmlData, "", AppDomain.CurrentDomain.BaseDirectory + @"xmlvalidate\replacevatinvoice.xsd"))
                {
                    //customer xml string not valid, don't do any thing
                    log.Info("processReplace " + validator.ValidationError);
                    return("ERR:3 err:" + validator.ValidationError);  //du lieu dau vao khong hop le
                }

                if (convert == 1)
                {
                    xmlData = DataHelper.convertTCVN3ToUnicode(xmlData);
                }
                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]
                }
                ICustomerService _cusSvr = IoC.Resolve <ICustomerService>();

                string invNumList = "";

                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);
                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)
                {
                    log.Error("Không tồn tại hóa đơn.");
                    return("ERR:2");  //khong ton tai hoa don, hoa don da duoc thay the roi;
                }

                string invPattern = null, invSerial = null, errorMessage = "";
                if (!LaunchInvoices.Instance.ExistNoInPubInv(comID, currentInv.Pattern, currentInv.Serial, out invPattern, out invSerial, out errorMessage))
                {
                    log.Error("het so hoa don trong dai.");
                    return("ERR:6 " + fkey);   //het so hoa don trong dai
                }
                IInvoice inv = (InvoiceBase)InvServiceFactory.NewInstance(invPattern, comID);
                try
                {
                    XElement xeles = XElement.Parse(xmlData);
                    DataHelper.DeserializeEinvFromXML(xmlData, inv);
                    inv.No       = 0;
                    inv.Name     = currentInv.Name;
                    inv.Pattern  = invPattern;
                    inv.Serial   = invSerial;
                    inv.CreateBy = System.Web.HttpContext.Current.User.Identity.Name;
                    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 (currentInv.Status == InvoiceStatus.SignedInv || currentInv.Status == InvoiceStatus.AdjustedInv)
                    {
                        IList <ProductInv> products = new List <ProductInv>();
                        foreach (IProductInv ii in inv.Products)
                        {
                            products.Add((ProductInv)ii);
                        }
                        Launcher.Instance.PublishReplace(currentInv, products, (InvoiceBase)inv, "");
                        invNumList += inv.Fkey ?? " ";
                    }
                    else
                    {
                        return("ERR:9 " + currentInv.Status);
                    }
                }
                catch (EInvoice.Core.Launching.NoFactory.OpenTranException ex)
                {
                    log.Error(ex);
                    return("ERR:14");
                }
                catch (Exception ex)
                {
                    log.Error("replaceInv err5: " + ex);
                    return("ERR:5 " + ex.Message);//loi phat hanh hoa don
                }
                ILogSystemService businessLog = IoC.Resolve <ILogSystemService>();
                businessLog.WriteLogReplaceAdjust(comID, currentInv.Pattern, currentInv.Serial, currentInv.No, currentInv.PublishDate, currentInv.Amount, inv.Pattern, inv.Serial, inv.No, inv.PublishDate, inv.Amount, inv.CusName, inv.CusAddress, inv.CusCode, inv.CusTaxCode, HttpContext.Current.User.Identity.Name, BusinessLogType.Replace);
                businessLog.CommitChanges();
                //invNumList = invNumList.Remove(invNumList.Length - 1, 1);
                return("OK_" + invNumList);
            }
            catch (Exception ex)
            {
                log.Error("replaceInv: " + ex);
                return("ERR:5 " + ex.Message);
            }
        }
Ejemplo n.º 6
0
        public ActionResult CreateAdJustInv(string NewPattern, string NewSerial, string Pattern, string PubDatasource, string NoInv, string SerialNo, string type, HttpPostedFileBase FileUpload)
        {
            ICompanyService  _comSrv    = IoC.Resolve <ICompanyService>();
            Company          currentCom = _comSrv.Getbykey(((EInvoiceContext)FXContext.Current).CurrentCompany.id);
            ICustomerService _CusSvc    = IoC.Resolve <ICustomerService>();
            InvoiceBase      model      = (InvoiceBase)InvServiceFactory.NewInstance(NewPattern, currentCom.id);

            TryUpdateModelFromType(model.GetType(), model);
            model.Pattern = NewPattern;
            model.Serial  = NewSerial;
            model.ComID   = currentCom.id;
            IInvoiceService    IInvSrv = InvServiceFactory.GetService(Pattern, currentCom.id);
            IInvoice           inv     = IInvSrv.GetByNo(currentCom.id, Pattern, SerialNo, Convert.ToDecimal(NoInv));
            IList <ProductInv> lst     = (IList <ProductInv>)PubDatasource.DeserializeJSON <ProductInv>(typeof(IList <ProductInv>));

            if (lst.Count() == 0)
            {
                Messages.AddErrorFlashMessage(Resources.Message.MRequestProd);
                return(RedirectToAction("CreateAdJustInv", new { Pattern = Pattern, Serial = SerialNo, invNo = NoInv }));
            }
            try
            {
                var Typecus = (from c in _CusSvc.Query where c.Code == model.CusCode && c.CusType == 1 && c.ComID == currentCom.id select c.CusType).SingleOrDefault();
                if (Typecus == 0)
                {
                    model.CusSignStatus = cusSignStatus.NocusSignStatus;
                }
                else
                {
                    model.CusSignStatus = cusSignStatus.NoSignStatus;
                }
                if ((inv.Status == InvoiceStatus.SignedInv || inv.Status == InvoiceStatus.InUseInv || inv.Status == InvoiceStatus.AdjustedInv))// =1 hoa don dieu chinh
                {
                    if (lst != null && lst.Count > 0)
                    {
                        model.Products = (from pr in lst select pr as IProductInv).ToList();
                    }
                    string xmldata        = string.Empty;
                    string message        = string.Empty;
                    string resultLauncher = string.Empty;
                    model.Fkey = "";
                    model.id   = 0;
                    model.Type = (InvoiceType)Convert.ToInt32(type);
                    //save file and get path
                    string strPath = "";
                    if (FileUpload != null)
                    {
                        string fileext = (Path.GetExtension(FileUpload.FileName).Length > 1) ? Path.GetExtension(FileUpload.FileName).Substring(1) : "";
                        if (fileext.ToLower() == "docx" || fileext.ToLower() == "pdf" || fileext.ToLower() == "doc")
                        {
                            strPath = @"\RecordsInv\" + currentCom.id + @"\" + Pattern.Replace("/", "") + @"\" + SerialNo.Replace("/", "") + "_" + NoInv + "." + fileext;
                            string strFullPath = GetFullPathRecordsCancel(strPath);
                            FileUpload.SaveAs(strFullPath);
                        }
                    }
                    ILauncherService _launcher = IoC.Resolve(Type.GetType(currentCom.Config["LauncherType"])) as ILauncherService;
                    _launcher.PublishAdjust(inv, lst, model, strPath);
                    resultLauncher = _launcher.Message;
                    if (resultLauncher.Contains("OK:"))
                    {
                        Messages.AddFlashMessage("Điều chỉnh hóa đơn thành công.");
                    }
                    else
                    {
                        Messages.AddErrorFlashMessage(StringErrorService(resultLauncher));
                    }
                }
            }
            catch (Exception ex)
            {
                Messages.AddErrorFlashMessage("Có lỗi xảy ra, vui lòng thực hiện lại.");
                log.Error(" CreateAdJustInv -: " + ex);
            }
            return(RedirectToAction("AdjustInvIndex", new { pattern = Pattern, Serial = SerialNo }));
        }
Ejemplo n.º 7
0
        public ActionResult CreateAdJustInv(AdjustModel model)
        {
            try
            {
                ICompanyService        comSrv     = IoC.Resolve <ICompanyService>();
                Company                currentCom = comSrv.Getbykey(((EInvoiceContext)FXContext.Current).CurrentCompany.id);
                IPublishInvoiceService PubIn      = IoC.Resolve <IPublishInvoiceService>();

                IInvoiceService IInvSrv = InvServiceFactory.GetService(model.pattern, currentCom.id);
                string          ErrorMessage = "";
                string          newPattern = null, newSerial = null;

                int result = getTaxDeclaration(currentCom.id, model.pattern, model.serial, model.invNo);

                if (result > 0 && result != -2)
                {
                    log.Error("Error CreateReplaceInv! Hóa đơn này chưa chốt kê khai thuế, vì vậy không thể thực hiện điều chỉnh. Hãy thực hiện nghiệp vụ thay thế hóa đơn!");
                    Messages.AddErrorFlashMessage("Hóa đơn này chưa chốt kê khai thuế, vì vậy không thể thực hiện điều chỉnh. Hãy thực hiện nghiệp vụ thay thế hóa đơn!");
                    return(RedirectToAction("SearchAdJustInv", new { pattern = model.pattern, serial = model.serial }));
                }

                //kiểm tra số hóa đơn của giải còn hay hết
                if (!LaunchInvoices.Instance.ExistNoInPubInv(currentCom.id, model.pattern, model.serial, out newPattern, out newSerial, out ErrorMessage))
                {
                    Messages.AddErrorFlashMessage(ErrorMessage);
                    return(RedirectToAction("SearchAdJustInv", new { pattern = model.pattern, serial = model.serial }));
                }

                //Lấy ra đối tượng hóa đơn cần thay thế
                //Hóa đơn đã thay thế và kê khai thuế thì không được chỉnh sửa
                IInvoice inv = IInvSrv.GetByNo(currentCom.id, model.pattern, model.serial, Convert.ToDecimal(model.invNo));
                if (inv.Status == InvoiceStatus.ReplacedInv || inv.Status == InvoiceStatus.CanceledInv)
                {
                    Messages.AddErrorFlashMessage("Hóa đơn đã bị thay thế hoặc bị hủy!");
                    return(RedirectToAction("SearchAdJustInv"));
                }
                int type = 0;
                int.TryParse(model.type, out type);
                model.pattern          = newPattern ?? model.pattern;
                model.serial           = newSerial ?? model.serial;
                ViewData["NewPattern"] = model.pattern;
                ViewData["NewSerial"]  = model.serial;
                ViewData["Data"]       = inv;
                ViewData["company"]    = currentCom;
                ViewData["type"]       = model.type;
                //them dong chu tang hay giam
                ViewData["typeName"] = model.typeName;
                int signPlugin = 0;
                if (currentCom.Config.Keys.Contains("SignPlugin"))
                {
                    int.TryParse(currentCom.Config["SignPlugin"], out signPlugin);
                }
                ViewData["SignPlugin"] = signPlugin;
                if (inv.Pattern != model.pattern)
                {
                    IInvoice invNew = InvServiceFactory.NewInstance(model.pattern, currentCom.id);
                    invNew.ComID         = currentCom.id;
                    invNew.Name          = inv.Name;
                    invNew.CusName       = inv.CusName;
                    invNew.CusCode       = inv.CusCode;
                    invNew.CusAddress    = inv.CusAddress;
                    invNew.Buyer         = inv.Buyer;
                    invNew.No            = inv.No;
                    invNew.Serial        = inv.Serial;
                    invNew.Note          = "";
                    invNew.PaymentMethod = inv.PaymentMethod;
                    invNew.Products      = inv.Products;
                    invNew.Pattern       = inv.Pattern;
                    invNew.Type          = (InvoiceType)type;
                    invNew.Amount        = inv.Amount;
                    invNew.Total         = inv.Total;
                    invNew.VATAmount     = inv.VATAmount;
                    string adjustView = InvServiceFactory.GetView(model.pattern, currentCom.id) + "CreateAdJustInv";
                    return(View(adjustView, invNew));
                }
                inv.Note = "";
                inv.Type = (InvoiceType)type;
                string ViewName = InvServiceFactory.GetView(model.pattern, currentCom.id) + "CreateAdJustInv";
                return(View(ViewName, inv));
            }
            catch (Exception ex)
            {
                log.Error(" CreateAdJustInv -:" + ex);
                Messages.AddErrorFlashMessage("Không tồn tại hóa đơn này!");
                return(RedirectToAction("SearchAdJustInv"));
            }
        }
Ejemplo n.º 8
0
        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"));
            }
        }
Ejemplo n.º 9
0
        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"));
        }
Ejemplo n.º 10
0
        public ActionResult Create(string Pattern, string PubDatasource)
        {
            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          ErrorMessage      = "";
            IInvoice        model             = InvServiceFactory.NewInstance(Pattern, currentCom.id);
            IInvoiceService IInvSrv           = InvServiceFactory.GetService(Pattern, currentCom.id);

            try
            {
                TryUpdateModelFromType(model.GetType(), model);
                model.CusCode = !string.IsNullOrWhiteSpace(model.CusCode) ? model.CusCode : model.CusTaxCode;
                var tem = InvServiceFactory.GetInvoiceType(Pattern, currentCom.id);
                if (!String.IsNullOrEmpty(PubDatasource))
                {
                    ICustomerService _CusSvc = FX.Core.IoC.Resolve <ICustomerService>();
                    var Typecus = (from c in _CusSvc.Query where c.Code == model.CusCode && c.CusType == 1 && c.ComID == currentCom.id select c.CusType).SingleOrDefault();
                    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.CreateInvoice(lstproduct, model, out ErrorMessage) == true)
                    {
                        log.Info("Create EInvoice by: " + HttpContext.User.Identity.Name + " Info-- TenKhachHang: " + model.CusName + " MaKhachHang: " + model.CusCode + " SoTien: " + model.Amount);
                        Messages.AddFlashMessage("Tạo mới 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, dịch vụ");
                }
                List <string> ser = _PubIn.GetSerialByPatter(Pattern, currentCom.id);
                ViewData["ser"]     = ser;
                ViewData["company"] = currentCom;
                string ViewName = InvServiceFactory.GetView(Pattern, currentCom.id) + "Create";
                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 = InvServiceFactory.NewInstance(Pattern, currentCom.id);
                List <string> ser = _PubIn.GetSerialByPatter(Pattern, currentCom.id);
                ViewData["ser"]     = ser;
                ViewData["company"] = currentCom;
                string ViewName = InvServiceFactory.GetView(Pattern, currentCom.id) + "Create";
                return(View(ViewName, model));
            }
            catch (Exception ex)
            {
                log.Error(" Create - " + ex);
                Messages.AddErrorMessage("Có lỗi xảy ra, vui lòng thực hiện lại!");
                List <string> ser = _PubIn.GetSerialByPatter(Pattern, currentCom.id);
                ViewData["ser"]     = ser;
                ViewData["company"] = currentCom;
                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) + "Create";
                return(View(ViewName, model));
            }
        }
Ejemplo n.º 11
0
        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))
            });
        }
Ejemplo n.º 12
0
        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));
        }
Ejemplo n.º 13
0
        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());
        }
Ejemplo n.º 14
0
        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"));
            }
        }