Esempio n. 1
0
        public void PublishAdjust(IInvoice OriINV, IList <ProductInv> lst, InvoiceBase INV, string AttacheFile = "")
        {
            Company currentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany;

            try
            {
                Launcher.Instance.PublishAdjust(OriINV, lst, INV, AttacheFile);
                Message = "OK:";
                try
                {
                    ILogSystemService businessLog = IoC.Resolve <ILogSystemService>();
                    businessLog.WriteLogReplaceAdjust(currentCom.id, OriINV.Pattern, OriINV.Serial, OriINV.No, OriINV.PublishDate, OriINV.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.Adjust);
                    businessLog.CommitChanges();
                }
                catch { }
            }
            catch (Exception ex)
            {
                Message = ex.Message;
            }
        }
Esempio n. 2
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);
            }
        }