コード例 #1
0
        public string confirmPaymentFkey(ListInvoice lsInv)
        {
            Company _currentCompany = ((EInvoiceContext)FXContext.Current).CurrentCompany;
            int     comID           = _currentCompany.id;

            if (_currentCompany == null)
            {
                return("ERlR:7");                        //username khong phu hop - ko tim thay company phu hop voi [username]
            }
            List <IInvoice> invLst = new List <IInvoice>();

            string[] invTokens = lsInv.lsFkey.Split('_');
            IPublishInvoiceService _PubInvSrv = IoC.Resolve <IPublishInvoiceService>();
            PublishInvoice         pubinv     = _PubInvSrv.GetFirst(comID, new int[] { 1, 2 });
            string pattern = "";

            if (pubinv != null)
            {
                pattern = pubinv.InvPattern;
                _PubInvSrv.UnbindSession(pubinv);
            }
            IInvoiceService invSrv = InvServiceFactory.GetService(pattern, comID);

            try
            {
                invLst = (List <IInvoice>)invSrv.GetByFkey(comID, invTokens);
                if (invTokens.Length != invLst.Count)
                {
                    return("ERR:6");
                }
                invLst.RemoveAll(inv => inv.PaymentStatus == Payment.Paid || (inv.Status != InvoiceStatus.SignedInv && inv.Status != InvoiceStatus.AdjustedInv));
            }
            catch (Exception ex)
            {
                log.Error("confirmPaymentFkey " + ex);
                return("ERR:6 " + ex.Message);
            }
            if (invLst.Count == 0)
            {
                return("ERR:13");            // hoa đơn đã gạch nợ/bỏ gạch nợ rồi
            }
            string strNote = "    ||    Thực hiện gạch nợ:   Người gạch nợ: " + HttpContext.Current.User.Identity.Name + "  Ngày gạch nợ: " + DateTime.Now.ToString();

            if (invSrv.ConfirmPayment(invLst, strNote))
            {
                //thuc hien deliveriy
                IDeliver _deliver = _currentCompany.Config.Keys.Contains("IDeliver") ? IoC.Resolve(Type.GetType(_currentCompany.Config["IDeliver"])) as IDeliver : null;
                if (_deliver != null)
                {
                    _deliver.Deliver(invLst.ToArray(), _currentCompany);
                }
                return("OK:");
            }
            return("ERR:7"); //sao lai khong thanh toán được ?
        }
コード例 #2
0
        public string UnConfirmPaymentFkey(ListInvoice lsInv)
        {
            Company _currentCompany = ((EInvoiceContext)FXContext.Current).CurrentCompany;
            int     comID           = _currentCompany.id;

            if (_currentCompany == null)
            {
                return("ERR:7");                        //username khong phu hop - ko tim thay company phu hop voi [username]
            }
            List <IInvoice> invLst = new List <IInvoice>();

            string[] invTokens = lsInv.lsFkey.Split('_');
            IPublishInvoiceService _PubInvSrv = IoC.Resolve <IPublishInvoiceService>();
            PublishInvoice         pubinv     = _PubInvSrv.GetFirst(comID, new int[] { 1, 2 });
            string pattern = "";

            if (pubinv != null)
            {
                pattern = pubinv.InvPattern;
                _PubInvSrv.UnbindSession(pubinv);
            }
            IInvoiceService invSrv = InvServiceFactory.GetService(pattern, comID);

            try
            {
                invLst = (List <IInvoice>)invSrv.GetByFkey(comID, invTokens);
                if (invTokens.Length != invLst.Count)
                {
                    return("ERR:6");
                }
                invLst.RemoveAll(inv => inv.PaymentStatus == Payment.Unpaid || (inv.Status != InvoiceStatus.SignedInv && inv.Status != InvoiceStatus.AdjustedInv));
            }
            catch (Exception ex)
            {
                log.Error("UnConfirmPaymentFkey " + ex);
                return("ERR:6 " + ex.Message);
            }
            if (invLst.Count == 0)
            {
                return("ERR:13");            // hoa đơn đã gạch nợ/bỏ gạch nợ rồi
            }
            if (invSrv.UnConfirmPayment(invLst))
            {
                return("OK:");
            }
            return("ERR:7"); //sao lai khong bo thanh toán được ?
        }
コード例 #3
0
        public string deliverInvFkey(ListInvoice lsInv)
        {
            Company _currentCompany = ((EInvoiceContext)FXContext.Current).CurrentCompany;
            int     comID           = _currentCompany.id;

            if (_currentCompany == null)
            {
                return("ERR:7");                        //username khong phu hop - ko tim thay company phu hop voi [username]
            }
            try
            {
                List <IInvoice>        invLst     = new List <IInvoice>();
                string[]               invTokens  = lsInv.lsFkey.Split('_');
                IPublishInvoiceService _PubInvSrv = IoC.Resolve <IPublishInvoiceService>();
                PublishInvoice         pubinv     = _PubInvSrv.GetFirst(comID, new int[] { 1, 2 });
                string pattern = "";
                if (pubinv != null)
                {
                    pattern = pubinv.InvPattern;
                    _PubInvSrv.UnbindSession(pubinv);
                }
                IInvoiceService _iInvoicSrv = InvServiceFactory.GetService(pattern, comID);
                invLst = (List <IInvoice>)_iInvoicSrv.GetByFkey(comID, invTokens);

                if (invLst.Count != invTokens.Length)
                {
                    return("ERR:6");                                  //khong tim thay hoa don
                }
                ICompanyService _comSrv  = IoC.Resolve <ICompanyService>();
                Company         com      = _comSrv.Getbykey(comID);
                IDeliver        _deliver = _currentCompany.Config.Keys.Contains("IDeliver") ? IoC.Resolve(Type.GetType(_currentCompany.Config["IDeliver"])) as IDeliver : null;
                if (_deliver != null)
                {
                    _deliver.Deliver(invLst.ToArray(), com);
                }
            }
            catch (Exception ex)
            {
                log.Error("deliver: " + ex);
            }
            return("OK:");
        }
コード例 #4
0
        private void getPublishInvoice(string pattern, int comID, out string invPattern, out string invSerial)
        {
            invPattern = invSerial = null;
            int isPattern = string.IsNullOrWhiteSpace(pattern) ? 0 : 1;
            IPublishInvoiceService _PubInvSrv = IoC.Resolve <IPublishInvoiceService>();

            switch ((isPattern))
            {
            case 0:
                PublishInvoice pubinv = _PubInvSrv.GetFirst(comID, new int[] { 1, 2 });
                if (pubinv != null)
                {
                    invPattern = pubinv.InvPattern;
                    invSerial  = pubinv.InvSerial;
                    _PubInvSrv.UnbindSession(pubinv);
                }
                else
                {
                    return;      //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;
                }
                else
                {
                    invPattern = pattern;
                    invSerial  = pubFirst.InvSerial;
                    _PubInvSrv.UnbindSession(pubFirst);
                }
                break;
            }
        }
コード例 #5
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);
            }
        }
コード例 #6
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);
            }
        }
コード例 #7
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"));
            }
        }
コード例 #8
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"));
        }
コード例 #9
0
        public string UnConfirmPaymentFkeyVNP(ListInvoice lsInv)
        {
            Company _currentCompany = ((EInvoiceContext)FXContext.Current).CurrentCompany;
            int     comID           = _currentCompany.id;

            if (_currentCompany == null)
            {
                return("ERR:7");                        //username khong phu hop - ko tim thay company phu hop voi [username]
            }
            List <IInvoice> invLst = new List <IInvoice>();

            string[] invTokens = lsInv.lsFkey.Split('_');
            IPublishInvoiceService _PubInvSrv = IoC.Resolve <IPublishInvoiceService>();
            PublishInvoice         pubinv     = _PubInvSrv.GetFirst(comID, new int[] { 1, 2 });
            string pattern = "";

            if (pubinv != null)
            {
                pattern = pubinv.InvPattern;
                _PubInvSrv.UnbindSession(pubinv);
            }
            IInvoiceService invSrv = InvServiceFactory.GetService(pattern, comID);

            try
            {
                invLst = (List <IInvoice>)invSrv.GetByFkey(comID, invTokens);
                if (invTokens.Length != invLst.Count)
                {
                    return("ERR:6");
                }
                invLst.RemoveAll(inv => inv.PaymentStatus == Payment.Unpaid || (inv.Status != InvoiceStatus.SignedInv && inv.Status != InvoiceStatus.AdjustedInv));
                for (int i = 0; i < invTokens.Length; i++)
                {
                    invTokens[i] = invTokens[i] + "K";
                }
                List <IInvoice> invKLst = new List <IInvoice>();
                invKLst = (List <IInvoice>)invSrv.GetByFkey(comID, invTokens);
                invKLst.RemoveAll(inv => inv.PaymentStatus == Payment.Unpaid || (inv.Status != InvoiceStatus.SignedInv && inv.Status != InvoiceStatus.AdjustedInv));
                if (invKLst.Count > 0)
                {
                    invLst.AddRange(invKLst);
                }
            }
            catch (Exception ex)
            {
                log.Error("UnConfirmPaymentFkey " + ex);
                return("ERR:6 " + ex.Message);
            }
            if (invLst.Count == 0)
            {
                return("ERR:13");            // hoa đơn đã gạch nợ/bỏ gạch nợ rồi
            }
            if (invSrv.UnConfirmPayment(invLst))
            {
                StringBuilder rv = new StringBuilder("OK:<Data>");
                foreach (IInvoice inv in invLst)
                {
                    rv.Append("<Item><index>").Append(inv.PublishDate.Month).Append("</index>");
                    rv.Append("<cusCode>").Append(inv.CusCode).Append("</cusCode>");
                    if (inv.Fkey.EndsWith("K"))
                    {
                        rv.Append("<month>").Append(inv.Fkey.Substring(inv.Fkey.Length - 7, 6)).Append("</month>");
                    }
                    else
                    {
                        rv.Append("<month>").Append(inv.Fkey.Substring(inv.Fkey.Length - 6, 6)).Append("</month>");
                    }
                    rv.Append("<pattern>").Append(inv.Pattern).Append("</pattern>");
                    rv.Append("<serial>").Append(inv.Serial).Append("</serial>");
                    rv.Append("<status>").Append((int)inv.Status).Append("</status></Item>");
                }
                rv.Append("</Data>");
                return(rv.ToString());
            }
            return("ERR:7"); //sao lai khong bo thanh toán được ?
        }
コード例 #10
0
        public string confirmPaymentFkeyVNP(ListInvoice lsInv)
        {
            Company _currentCompany = ((EInvoiceContext)FXContext.Current).CurrentCompany;
            int     comID           = _currentCompany.id;

            if (_currentCompany == null)
            {
                return("ERR:7");                        //username khong phu hop - ko tim thay company phu hop voi [username]
            }
            List <IInvoice> invLst = new List <IInvoice>();

            string[] invTokens = lsInv.lsFkey.Split(';');
            IPublishInvoiceService _PubInvSrv = IoC.Resolve <IPublishInvoiceService>();
            PublishInvoice         pubinv     = _PubInvSrv.GetFirst(comID, new int[] { 1, 2 });
            string pattern = "";

            if (pubinv != null)
            {
                pattern = pubinv.InvPattern;
                _PubInvSrv.UnbindSession(pubinv);
            }
            IInvoiceService invSrv = InvServiceFactory.GetService(pattern, comID);

            try
            {
                invLst = (List <IInvoice>)invSrv.GetByFkey(comID, invTokens);
                if (invTokens.Length != invLst.Count)
                {
                    return("ERR:6");
                }
                invLst.RemoveAll(inv => inv.PaymentStatus == Payment.Paid || (inv.Status != InvoiceStatus.SignedInv && inv.Status != InvoiceStatus.AdjustedInv));
                for (int i = 0; i < invTokens.Length; i++)
                {
                    invTokens[i] = invTokens[i] + "K";
                }
                List <IInvoice> invKLst = new List <IInvoice>();
                invKLst = (List <IInvoice>)invSrv.GetByFkey(comID, invTokens);
                invKLst.RemoveAll(inv => inv.PaymentStatus == Payment.Paid || (inv.Status != InvoiceStatus.SignedInv && inv.Status != InvoiceStatus.AdjustedInv));
                if (invKLst.Count > 0)
                {
                    invLst.AddRange(invKLst);
                }
            }
            catch (Exception ex)
            {
                log.Error("confirmPaymentFkey " + ex);
                return("ERR:6 " + ex.Message);
            }
            if (invLst.Count == 0)
            {
                return("ERR:13");            // hoa đơn đã gạch nợ/bỏ gạch nợ rồi
            }
            string strNote = "    ||    Thực hiện gạch nợ:   Người gạch nợ: " + HttpContext.Current.User.Identity.Name + "  Ngày gạch nợ: " + DateTime.Now.ToString();

            if (invSrv.ConfirmPayment(invLst, strNote))
            {
                //thuc hien deliveriy
                IDeliver _deliver = _currentCompany.Config.Keys.Contains("IDeliver") ? IoC.Resolve(Type.GetType(_currentCompany.Config["IDeliver"])) as IDeliver : null;
                if (_deliver != null)
                {
                    _deliver.Deliver(invLst.ToArray(), _currentCompany);
                }

                //lay link email
                String        weblink = System.Configuration.ConfigurationManager.AppSettings["Portal"] + "/Email/EmailInvoiceView?token=";
                StringBuilder rv      = new StringBuilder("OK:<Data>");
                foreach (IInvoice inv in invLst)
                {
                    rv.Append("<Item><index>").Append(inv.PublishDate.Month).Append("</index>");
                    rv.Append("<cusCode>").Append(inv.CusCode).Append("</cusCode>");
                    if (inv.Fkey.EndsWith("K"))
                    {
                        rv.Append("<month>").Append(inv.Fkey.Substring(inv.Fkey.Length - 7, 6)).Append("</month>");
                    }
                    else
                    {
                        rv.Append("<month>").Append(inv.Fkey.Substring(inv.Fkey.Length - 6, 6)).Append("</month>");
                    }
                    rv.Append("<pattern>").Append(inv.Pattern).Append("</pattern>");
                    rv.Append("<serial>").Append(inv.Serial).Append("</serial>");
                    rv.Append("<status>").Append((int)inv.Status).Append("</status>");
                    string stoken = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(inv.id.ToString() + "_" + inv.Pattern + "_" + _currentCompany.id.ToString()));
                    rv.AppendFormat("<link>{0}{1}</link></Item>", weblink, stoken);
                }
                rv.Append("</Data>");
                return(rv.ToString());
                //}
                //else return "OK:";
            }
            return("ERR:7"); //sao lai khong thanh toán được ?
        }
コード例 #11
0
        public string confirmPaymentDetailFkey(ListInvoice lsInv)
        {
            Company _currentCompany = ((EInvoiceContext)FXContext.Current).CurrentCompany;
            int     comID           = _currentCompany.id;

            if (_currentCompany == null)
            {
                return("ERR:7");                        //username khong phu hop - ko tim thay company phu hop voi [username]
            }
            List <IInvoice> invLst = new List <IInvoice>();

            string[] invTokens = lsInv.lsFkey.Split('_');
            if (invTokens.Count() > 1000)
            {
                return("ERR:14");
            }
            IPublishInvoiceService _PubInvSrv = IoC.Resolve <IPublishInvoiceService>();
            PublishInvoice         pubinv     = _PubInvSrv.GetFirst(comID, new int[] { 1, 2 });
            string pattern = "";

            if (pubinv != null)
            {
                pattern = pubinv.InvPattern;
                _PubInvSrv.UnbindSession(pubinv);
            }
            IInvoiceService invSrv     = InvServiceFactory.GetService(pattern, comID);
            StringBuilder   sb         = new StringBuilder();
            List <string>   unPaidFkey = new List <string>();
            string          rv;

            try
            {
                invLst = (List <IInvoice>)invSrv.GetByFkey(comID, invTokens);
                List <string> foundFkey    = invLst.Select(inv => inv.Fkey).ToList();
                List <string> notFoundFkey = invTokens.ToList().GetRange(0, invTokens.Count());
                notFoundFkey.RemoveAll(inv => foundFkey.Contains(inv)); // list fkey khong ton tai
                invLst.RemoveAll(inv => inv.PaymentStatus == Payment.Paid || (inv.Status != InvoiceStatus.SignedInv && inv.Status != InvoiceStatus.AdjustedInv));
                unPaidFkey = invLst.Select(inv => inv.Fkey).ToList();   // list fkey can gach no
                foundFkey.RemoveAll(inv => unPaidFkey.Contains(inv));   // list fkey da gach no roi
                sb = new StringBuilder("ERR:6#");
                foreach (string s in notFoundFkey)
                {
                    sb.AppendFormat("{0}_", s);
                }
                rv = sb.ToString();
                rv = rv.Remove(rv.Length - 1, 1);
                sb = new StringBuilder("ERR:13#");
                foreach (string s in foundFkey)
                {
                    sb.AppendFormat("{0}_", s);
                }
                rv = rv + "||" + sb.ToString();
                rv = rv.Remove(rv.Length - 1, 1);
            }
            catch (Exception ex)
            {
                log.Error("confirmPaymentFkey " + ex);
                return("ERR:6 " + ex.Message);
            }
            if (invLst.Count == 0)
            {
                //toan bo lo hoa don hoac ko tim thay, hoac da gach no roi
                return(rv);
            }
            string strNote = "    ||    Thực hiện gạch nợ:   Người gạch nợ: " + HttpContext.Current.User.Identity.Name + "  Ngày gạch nợ: " + DateTime.Now.ToString();

            if (invSrv.ConfirmPayment(invLst, strNote))
            {
                //thuc hien deliveriy
                IDeliver _deliver = _currentCompany.Config.Keys.Contains("IDeliver") ? IoC.Resolve(Type.GetType(_currentCompany.Config["IDeliver"])) as IDeliver : null;
                if (_deliver != null)
                {
                    _deliver.Deliver(invLst.ToArray(), _currentCompany);
                }
                //return "OK:";
                sb = new StringBuilder("OK:#");
                foreach (string s in unPaidFkey)
                {
                    sb.AppendFormat("{0}_", s);
                }
                rv = rv + "||" + sb.ToString();
                rv = rv.Remove(rv.Length - 1, 1);
                return(rv);  //ok
            }
            return("ERR:7"); //sao lai khong thanh toán được ?
        }