Ejemplo n.º 1
0
        public bool ExistNoInPubInv(int ComID, string pattern, string serial, out string newPattern, out string newSerial, out string ErrorMessage)
        {
            newPattern   = pattern;
            newSerial    = serial;
            ErrorMessage = "";
            IPublishInvoiceService _pubSrv = IoC.Resolve <IPublishInvoiceService>();
            var pubInv = _pubSrv.Query.Where(pub => pub.ComId == ComID && pub.InvPattern == pattern && pub.InvSerial == serial && (pub.Status == 2 || pub.Status == 1)).ToList();

            if (pubInv != null && pubInv.Count > 0)
            {
                decimal MaxNo     = pubInv.Max(p => p.ToNo);
                decimal CurrentNo = pubInv.Max(p => p.CurrentNo);
                if (MaxNo > CurrentNo)
                {
                    return(true);
                }
            }

            IList <PublishInvoice> publishInvoices = _pubSrv.Query.Where(p => p.ComId == ComID && (p.Status == 2 || p.Status == 1)).OrderBy(p => p.StartDate).ToList();

            if (publishInvoices.Count == 0)
            {
                ErrorMessage = "Giải đã hết hóa đơn để cấp số xin vui lòng đăng ký giải mới.";
                return(false);
            }
            var pInv = publishInvoices.Where(p => p.InvPattern == pattern).FirstOrDefault();

            newPattern = pInv != null ? pInv.InvPattern : publishInvoices.First().InvPattern;
            newSerial  = pInv != null ? pInv.InvSerial : publishInvoices.First().InvSerial;
            return(true);
        }
Ejemplo n.º 2
0
        public ActionResult Edit(int id)
        {
            Company currentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany;
            IRegisterTempService   registerTempSrv = IoC.Resolve <IRegisterTempService>();
            IPublishInvoiceService publishInvSrv   = IoC.Resolve <IPublishInvoiceService>();

            if (publishInvSrv.GetPubOfReg(id, currentCom.id).Count > 0)
            {
                Messages.AddErrorFlashMessage("Không được sửa mẫu hóa đơn đang sử dụng.");
                return(RedirectToAction("Index"));
            }
            string             logoKey      = string.Format("{0}_{1}", currentCom.id, "logo");
            string             backgroudKey = string.Format("{0}_{1}", currentCom.id, "backgroud");
            RegisterTemp       registerTemp = registerTempSrv.Getbykey(id);
            RegisterTempModels model        = new RegisterTempModels();

            model.tempId     = registerTemp.InvoiceTemp.Id;
            model.CurrentCom = currentCom;
            model.logoFile   = model.imgFile = registerTemp.Name;
            model.RegisTemp  = registerTemp;
            if (!string.IsNullOrWhiteSpace(registerTemp.CssLogo))
            {
                setCacheContext(logoKey, registerTemp.CssLogo);
            }
            if (!string.IsNullOrWhiteSpace(registerTemp.CssBackgr))
            {
                setCacheContext(backgroudKey, registerTemp.CssBackgr);
            }
            return(View(model));
        }
Ejemplo n.º 3
0
        public ActionResult Delete(int id)
        {
            Company currentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany;
            IRegisterTempService   registerTempSrv = IoC.Resolve <IRegisterTempService>();
            IPublishInvoiceService publishInvSrv   = IoC.Resolve <IPublishInvoiceService>();

            try
            {
                if (publishInvSrv.GetPubOfReg(id, currentCom.id).Count > 0)
                {
                    Messages.AddErrorFlashMessage("Không được xóa mẫu hóa đơn đang sử dụng.");
                    return(RedirectToAction("Index"));
                }
                RegisterTemp model = registerTempSrv.Getbykey(id);
                registerTempSrv.Delete(model);
                registerTempSrv.CommitChanges();
                Messages.AddFlashMessage("Xóa mẫu hóa đơn thành công.");
            }
            catch (Exception ex)
            {
                log.Error(ex);
                Messages.AddErrorFlashMessage("Có lỗi xảy ra, vui lòng thực hiện lại.");
            }
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 4
0
        public ActionResult ajxGetSerial(int id)
        {
            IPublishInvoiceService _ipiSer = IoC.Resolve <IPublishInvoiceService>();
            PublishInvoice         pi      = _ipiSer.Getbykey(id);

            return(Json(pi));
        }
Ejemplo n.º 5
0
        public ActionResult Edit(string Pattern, int id)
        {
            ICompanyService        comSrv     = IoC.Resolve <ICompanyService>();
            Company                currentCom = comSrv.Getbykey(((EInvoiceContext)FXContext.Current).CurrentCompany.id);
            IPublishInvoiceService _PubIn     = IoC.Resolve <IPublishInvoiceService>();
            IRegisterTempService   _ReTemSvc  = IoC.Resolve <IRegisterTempService>();
            string ViewName = InvServiceFactory.GetView(Pattern, currentCom.id) + "Edit";
            //khoi tao service
            IInvoiceService IInvSrv = InvServiceFactory.GetService(Pattern, currentCom.id);
            //lay ve mot ban ghi hoa don
            IInvoice model = IInvSrv.Getbykey <IInvoice>(id);

            if (model.Status != InvoiceStatus.NewInv)
            {
                Messages.AddErrorFlashMessage("Không thể sửa hóa đơn này.");
                return(RedirectToAction("Index", new { Pattern = Pattern, Serial = model.Serial }));
            }
            //lay va doi danh sach cac san pham thanh doi tuong json
            //nếu Unit=null thì mặc định hiển thị ""
            foreach (var item in model.Products)
            {
                if (item.Unit == null)
                {
                    item.Unit = "";
                }
            }
            //lay ra danh sach cac serial
            List <string> ser = _PubIn.GetSerialByPatter(model.Pattern, currentCom.id);

            ViewData["ser"] = ser;
            //lay thong tin ve don vi ban hang
            ViewData["company"] = currentCom;
            model.Note          = "";
            return(View(ViewName, model));
        }
Ejemplo n.º 6
0
        public ActionResult Launch()
        {
            IPublishInvoiceService _PubIn = IoC.Resolve <IPublishInvoiceService>();
            Company     currentCom        = ((EInvoiceContext)FXContext.Current).CurrentCompany;
            LaunchModel model             = new LaunchModel();

            try
            {
                //lstpattern
                List <string> lstpattern = _PubIn.LstByPattern(currentCom.id, 1);
                if (lstpattern.Count == 0)
                {
                    Messages.AddErrorFlashMessage("Cần tạo thông báo phát hành.");
                    return(RedirectToAction("Index", "Publish"));
                }
                model.Listpattern = new SelectList(lstpattern);
                //lstserial
                List <string> oserial = (from s in _PubIn.Query where ((s.ComId == currentCom.id) && (s.Status == 1 || s.Status == 2)) select s.InvSerial).ToList <string>();
                model.Listserial = new SelectList(oserial);
            }
            catch (Exception ex)
            {
                Messages.AddErrorFlashMessage("Có lỗi xảy ra, vui lòng thực hiện lại.");
                log.Error(" Launch -" + ex.Message);
                return(RedirectToAction("Index", "Home"));
            }
            return(View(model));
        }
Ejemplo n.º 7
0
        public ActionResult Quickreport(ReportsDetailModel model)
        {
            Company currentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany;
            IPublishInvoiceService PubInvSrv = IoC.Resolve <IPublishInvoiceService>();
            //if (model == null) model = new ReportsDetailModel();
            IList <string> lstPattern = PubInvSrv.LstByPattern(currentCom.id, 2);

            if (lstPattern.Count == 0)
            {
                Messages.AddErrorFlashMessage("Thông báo phát hành chưa được chấp nhận hoặc chưa có hóa đơn.");
                return(Redirect("/"));
            }
            if (lstPattern.Count > 0)
            {
                if (String.IsNullOrEmpty(model.Pattern))
                {
                    model.Pattern = lstPattern[0];
                }
            }
            List <string> lstSerial = (from p in PubInvSrv.Query where p.ComId == currentCom.id && p.InvPattern == model.Pattern && (p.Status > 1) select p.InvSerial).Distinct().ToList <string>();

            model.lstPattern = new SelectList(lstPattern);
            model.lstSerial  = new SelectList(lstSerial);
            return(View(model));
        }
Ejemplo n.º 8
0
 public ActionResult ReportLaunch(ReportsLaunchModel model)
 {
     try
     {
         Company currentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany;
         IPublishInvoiceService PubInvSrv  = IoC.Resolve <IPublishInvoiceService>();
         IList <string>         lstPattern = PubInvSrv.LstByPattern(currentCom.id, 2);
         if (lstPattern.Count == 0)
         {
             Messages.AddErrorFlashMessage("Thông báo phát hành chưa được chấp nhận hoặc chưa có hóa đơn.");
             return(Redirect("/"));
         }
         if (lstPattern.Count > 0)
         {
             if (string.IsNullOrEmpty(model.Pattern))
             {
                 model.Pattern = lstPattern[0];
                 IInvoiceService IInvSrv = InvServiceFactory.GetService(model.Pattern, currentCom.id);
             }
         }
         List <string> lstSerial = (from p in PubInvSrv.Query where (p.ComId == currentCom.id) && (p.InvPattern == model.Pattern) && (p.Status > 1) select p.InvSerial).Distinct().ToList <string>();
         model.lstPattern = new SelectList(lstPattern);
         model.lstSerial  = new SelectList(lstSerial);
         return(View(model));
     }
     catch (Exception ex)
     {
         Messages.AddErrorFlashMessage(ex.Message);
         return(RedirectToAction("Index", "Home"));
     }
 }
Ejemplo n.º 9
0
        //lay default Pattern va serial
        //lay pattern dau tien cua cong ty, van con hoa don trong dai
        private PublishInvoice DefaultPublishInvoice(int ComID)
        {
            PublishInvoice         ret     = null;
            IPublishInvoiceService _PubSrv = IoC.Resolve <IPublishInvoiceService>();

            ret = _PubSrv.Query.Where(pi => pi.ComId == ComID && (pi.Status == 1 || pi.Status == 2)).First();
            return(ret);
        }
Ejemplo n.º 10
0
        public ActionResult getserial(string pattern)
        {
            Company currentCom           = ((EInvoiceContext)FXContext.Current).CurrentCompany;
            IPublishInvoiceService PubIn = IoC.Resolve <IPublishInvoiceService>();
            var q = (from p in PubIn.Query where (p.ComId == currentCom.id) && (p.Status == 2 || p.Status == 1 || p.Status == 3) && (p.InvPattern == pattern) select p.InvSerial).Distinct();

            return(Json(new { q }));
        }
Ejemplo n.º 11
0
        public IHttpActionResult GetPublishInvoice()
        {
            Company comp = ((EInvoiceContext)FX.Context.FXContext.Current).CurrentCompany;
            IPublishInvoiceService pubInvSrv = IoC.Resolve <IPublishInvoiceService>();
            IList <PublishInvoice> list      = pubInvSrv.Query.Where(p => p.ComId == comp.id && p.Status >= 1).ToList();

            return(Ok(list));
        }
Ejemplo n.º 12
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 ?
        }
Ejemplo n.º 13
0
        //lấy danh sách các serial từ pattern
        //status=1,status=2
        public ActionResult GetSerialByPatter(string opattern)
        {
            Company currentCom            = ((EInvoiceContext)FXContext.Current).CurrentCompany;
            IPublishInvoiceService _PubIn = IoC.Resolve <IPublishInvoiceService>();
            var pu = (from c in _PubIn.Query where (c.InvPattern == opattern) && c.ComId == currentCom.id && (c.Status == 1 || c.Status == 2) select c.InvSerial).Distinct().ToList();

            return(Json(new
            {
                pu
            }));
        }
Ejemplo n.º 14
0
        public ActionResult GetSerialPayments(string Pattern)
        {
            IPublishInvoiceService _PubIn = IoC.Resolve <IPublishInvoiceService>();
            Company currentCom            = ((EInvoiceContext)FXContext.Current).CurrentCompany;
            var     pu = _PubIn.LstBySerial(currentCom.id, Pattern, 1);

            return(Json(new
            {
                pu
            }));
        }
Ejemplo n.º 15
0
        private bool checkInvNumber(int ComID, string pattern, string serial)
        {
            IPublishInvoiceService _pubSrv = IoC.Resolve <IPublishInvoiceService>();
            decimal MaxNo     = (from pub in _pubSrv.Query where (pub.ComId == ComID && pub.InvPattern == pattern && pub.InvSerial == serial && (pub.Status == 1 || pub.Status == 2)) select pub.ToNo).Max();
            decimal CurrentNo = (from opub in _pubSrv.Query where (opub.ComId == ComID && opub.InvPattern == pattern && opub.InvSerial == serial && (opub.Status == 1 || opub.Status == 2)) select opub.CurrentNo).Max();

            if (MaxNo > CurrentNo)
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 16
0
        public ActionResult AdjustInvIndex(AdjustInvoiceModel model, int?page)
        {
            IPublishInvoiceService PubIn = IoC.Resolve <IPublishInvoiceService>();
            Company       currentCom     = ((EInvoiceContext)FXContext.Current).CurrentCompany;
            List <string> lstpattern     = PubIn.LstByPattern(currentCom.id, 2);

            if (lstpattern.Count == 0)
            {
                Messages.AddErrorFlashMessage(Resources.Message.MInv_SMesNoPubAccess);
                return(Redirect("/"));
            }
            model.lstPattern = new SelectList(lstpattern);
            if (string.IsNullOrEmpty(model.pattern) && lstpattern.Count > 0)
            {
                model.pattern = lstpattern[0];
            }
            //lay serial
            List <string> LstSerial = (from p in PubIn.Query where p.Status != 0 && p.InvPattern == model.pattern && p.ComId == currentCom.id select p.InvSerial).Distinct().ToList <string>();

            model.lstSerial = new SelectList(LstSerial);
            if (string.IsNullOrEmpty(model.Serial))
            {
                model.Serial = LstSerial[0];
            }
            // call service
            model.ComId = currentCom.id;
            //phân trang
            int      defautPagesize   = 10;
            int      currentPageIndex = page.HasValue ? page.Value - 1 : 0;
            int      totalcount;
            decimal  InvNo    = model.InvNo.HasValue ? model.InvNo.Value : 0;
            DateTime?DateFrom = null;
            DateTime?DateTo   = null;

            if (!string.IsNullOrWhiteSpace(model.FromDate))
            {
                DateFrom = DateTime.ParseExact(model.FromDate, "dd/MM/yyyy", null);
            }
            if (!string.IsNullOrWhiteSpace(model.ToDate))
            {
                DateTo = DateTime.ParseExact(model.ToDate, "dd/MM/yyyy", null);
            }
            //IList<AdjustInv> lst = _adjustInvSrv.GetAdjustInv(model.ComId, model.pattern, model.Serial, DateFrom, DateTo, InvNo, ProcessingStatus.AdjustedInv, model.nameCus, model.code, model.CodeTax);
            IList <AjustSearchModel> lst = _adjustInvSrv.SearchAdjust(model.ComId, model.pattern, model.Serial, DateFrom, DateTo, InvNo, ProcessingStatus.AdjustedInv, model.nameCus, model.code, model.CodeTax, currentPageIndex, defautPagesize, out totalcount);

            model.PageListAdjustSearch = new PagedList <AjustSearchModel>(lst, currentPageIndex, defautPagesize, totalcount);
            ViewData["Title1"]         = "Hóa đơn bị điều chỉnh";
            ViewData["Title2"]         = "Hóa đơn điều chỉnh";
            ViewData["TypeView"]       = 2;
            return(View(model));
        }
Ejemplo n.º 17
0
        public ActionResult DetailRPublish(int id)
        {
            if (id <= 0)
            {
                throw new HttpRequestValidationException();
            }
            IPublishService        pubSrc    = IoC.Resolve <IPublishService>();
            Publish                model     = pubSrc.Getbykey(id);
            IPublishInvoiceService pubinvSrc = IoC.Resolve <IPublishInvoiceService>();
            var qr = (from pi in pubinvSrc.Query where pi.PublishID == model.id select pi);
            IList <PublishInvoice> lstpubinv = qr.ToList();

            ViewData["lstpubinv"] = lstpubinv;
            return(View(model));
        }
Ejemplo n.º 18
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 ?
        }
Ejemplo n.º 19
0
        public ActionResult UpdateCoupon(string Pattern, int id)
        {
            if (id <= 0)
            {
                throw new HttpRequestValidationException();
            }
            ICompanyService        comSrv     = IoC.Resolve <ICompanyService>();
            Company                currentCom = comSrv.Getbykey(((EInvoiceContext)FXContext.Current).CurrentCompany.id);
            IPublishInvoiceService _PubIn     = IoC.Resolve <IPublishInvoiceService>();
            IRegisterTempService   _ReTemSvc  = IoC.Resolve <IRegisterTempService>();
            IInvoiceService        IInvSrv    = InvServiceFactory.GetService(Pattern, currentCom.id);
            IInvoice               model      = IInvSrv.Getbykey <IInvoice>(id);
            string NoteOrder = model.Note;

            try
            {
                TryUpdateModelFromType(model.GetType(), model);
                model.Note = NoteOrder + " || " + model.Note;
                IInvSrv.Update(model);
                IInvSrv.CommitChanges();
                log.Info("Edit EInvoice by: " + HttpContext.User.Identity.Name + " Info-- TenKhachHang: " + model.CusName + " MaKhachHang: " + model.CusCode + " SoTien: " + model.Amount);
                Messages.AddFlashMessage("Sửa phiếu thu thành công.");
                return(RedirectToAction("Index", new { Pattern = Pattern, Serial = model.Serial }));
            }
            catch (HttpRequestValidationException ex)
            {
                log.Error("ArgumentException: " + ex);
                Messages.AddErrorMessage("Dữ liệu không hợp lệ hoặc có chứa mã gây nguy hiểm tiềm tàng cho hệ thống!");
                model = IInvSrv.Getbykey <IInvoice>(id);
                List <string> ser = _PubIn.GetSerialByPatter(Pattern, currentCom.id);
                ViewData["ser"]     = ser;
                ViewData["company"] = currentCom;
                string ViewName = InvServiceFactory.GetView(Pattern, currentCom.id) + "Edit";
                return(View(ViewName, model));
            }
            catch (Exception ex)
            {
                log.Error("Edit -", ex);
                model.Name = _ReTemSvc.SeachNameInv(Pattern, currentCom.id);
                List <string> ser = _PubIn.GetSerialByPatter(model.Pattern, currentCom.id);
                ViewData["ser"]     = ser;
                ViewData["company"] = currentCom;
                Messages.AddErrorMessage("Có lỗi xảy ra, vui lòng thực hiện lại.");
                string ViewName = InvServiceFactory.GetView(Pattern, currentCom.id) + "Edit";
                return(View(ViewName, model));
            }
        }
Ejemplo n.º 20
0
        //Tự động thay đổi ToNo khi nhập Invserialprefix và InvSerialSuffix
        public ActionResult ajx(int Id, string InvSerialPrefix, string InvSerialSuffix)
        {
            Company _currentcompany          = ((EInvoiceContext)FXContext.Current).CurrentCompany;
            IPublishInvoiceService pubinvSrc = IoC.Resolve <IPublishInvoiceService>();
            var qr = from p in pubinvSrc.Query
                     where
                     (p.RegisterID == Id) && (p.InvSerialPrefix == InvSerialPrefix) &&
                     (p.InvSerialSuffix == InvSerialSuffix) && (p.Status == 0 || p.Status == 1 || p.Status == 2 || p.Status == 3) && (p.ComId == _currentcompany.id)
                     select p.ToNo;
            decimal ic = qr.Count() == 0 ? 0 : qr.Max();

            return(Json(new
            {
                ic
            }
                        ));
        }
Ejemplo n.º 21
0
        private int getTaxDeclaration(int comId, string pattern, string serial, string invNo)
        {
            int result = -2;
            IPublishInvoiceService PubIn = IoC.Resolve <IPublishInvoiceService>();

            string latestTaxDeclarationDate = PubIn.GetLatestTaxDeclarationDate();

            if (latestTaxDeclarationDate != null)
            {
                string   createDateByFKey             = PubIn.GetArisingDateByinvNo(comId, pattern, serial, invNo);
                DateTime latestTaxDeclarationDateTime = System.Convert.ToDateTime(latestTaxDeclarationDate);
                DateTime createDateFKey = System.Convert.ToDateTime(createDateByFKey);

                result = DateTime.Compare(createDateFKey, latestTaxDeclarationDateTime);
            }

            return(result);
        }
Ejemplo n.º 22
0
        public ActionResult ajxGetPattern(int id)
        {
            IPublishInvoiceService _ipiSer = IoC.Resolve <IPublishInvoiceService>();
            Company _currentCom            = ((EInvoiceContext)FXContext.Current).CurrentCompany;
            IList <PublishInvoice> listPI  = _ipiSer.GetPublishedPub(id, _currentCom.id);
            List <pubInfo>         pList   = new List <pubInfo>();

            foreach (PublishInvoice pi in listPI)
            {
                pubInfo p = new pubInfo();
                p.InvPattern = pi.InvPattern;
                p.PubInvId   = pi.id;
                p.InvSerial  = pi.InvSerial;
                p.CurrentNo  = pi.CurrentNo;
                p.ToNo       = pi.ToNo;
                pList.Add(p);
            }
            return(Json(pList));
        }
Ejemplo n.º 23
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:");
        }
Ejemplo n.º 24
0
 public ActionResult SearchAdJustInv()
 {
     try
     {
         AdjustModel            model = new AdjustModel();
         IPublishInvoiceService PubIn = IoC.Resolve <IPublishInvoiceService>();
         Company        currentCom    = ((EInvoiceContext)FXContext.Current).CurrentCompany;
         IList <string> lstpattern    = PubIn.LstByPattern(currentCom.id, 2);
         model.lstpattern = new SelectList(lstpattern);
         model.lstserial  = new SelectList("");
         model.currentcom = currentCom;
         return(View(model));
     }
     catch (Exception ex)
     {
         log.Error(" SearchAdJustInv -:" + ex);
         Messages.AddErrorFlashMessage("Có lỗi xảy ra, vui lòng thực hiện lại!");
         return(RedirectToAction("Index", "Home"));
     }
 }
Ejemplo n.º 25
0
        private int getMaxInvNumber(int comID, string pattern, string serial)
        {
            int rv = 0;
            IPublishInvoiceService _srv          = IoC.Resolve <IPublishInvoiceService>();
            IList <PublishInvoice> LstPubInvoice = _srv.GetbyPattern(comID, pattern, 1, 2).Where(item => item.InvSerial == serial).ToList();

            if (LstPubInvoice == null || LstPubInvoice.Count == 0)
            {
                throw new Exception("No publishInvoice for Notransaction.");
            }
            foreach (PublishInvoice p in LstPubInvoice)
            {
                rv += (int)(p.ToNo - p.CurrentNo);
                if (p.CurrentNo == 0)
                {
                    rv = rv - 1;
                }
                _srv.UnbindSession(p);
            }
            return(rv);
        }
Ejemplo n.º 26
0
        public ActionResult Index(CertInvModel model, int?page)
        {
            int                    pageIndex  = page.HasValue ? page.Value - 1 : 0;
            int                    pageSize   = 20;
            int                    total      = 0;
            Company                currentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany;
            IInvCertifyService     invcertSrv = IoC.Resolve <IInvCertifyService>();
            IPublishInvoiceService _PubIn     = IoC.Resolve <IPublishInvoiceService>();
            IList <string>         lstpattern = _PubIn.LstByPattern(currentCom.id, 1);

            if (lstpattern.Count == 0)
            {
                Messages.AddErrorFlashMessage(Resources.Message.MInv_SMesNoPubAccess);
                return(RedirectToAction("/"));
            }
            model.pattern  = string.IsNullOrEmpty(model.pattern) ? lstpattern[0] : model.pattern;
            model.Patterns = lstpattern;
            var lst = invcertSrv.GetCertify(currentCom.id, model.pattern, model.status, model.type, pageIndex, pageSize, out total);

            model.PagedListInvCert = new PagedList <InvCertify>(lst, pageIndex, pageSize, total);
            return(View(model));
        }
Ejemplo n.º 27
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.º 28
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;
            }
        }
Ejemplo n.º 29
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.º 30
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);
            }
        }