Пример #1
0
        public ActionResult CancelInvNotReIndex(EInvoiceIndexModel model, int?page, int?Pagesize)
        {
            IPublishInvoiceService _PubIn = IoC.Resolve <IPublishInvoiceService>();
            Company        currentCom     = ((EInvoiceContext)FXContext.Current).CurrentCompany;
            IList <string> lstpattern     = _PubIn.LstByPattern(currentCom.id, 1);

            if (lstpattern.Count == 0)
            {
                Messages.AddErrorFlashMessage(Resources.Message.MInv_SMesNoPubAccess);
                return(RedirectToAction("Index", "Home"));
            }
            if (model == null)
            {
                model = new EInvoiceIndexModel();
            }
            //lay pattern
            if (string.IsNullOrEmpty(model.Pattern))
            {
                model.Pattern = lstpattern[0];
            }
            model.lstpattern = lstpattern;
            //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 = LstSerial;
            if (string.IsNullOrEmpty(model.Serial))
            {
                model.Serial = LstSerial[0];
            }
            int defautPagesize   = Pagesize.HasValue ? Convert.ToInt32(Pagesize) : 10;
            int currentPageIndex = page.HasValue ? page.Value - 1 : 0;
            int totalRecords     = 0;

            IInvoiceService  IInvSrv = InvServiceFactory.GetService(model.Pattern, currentCom.id);
            IList <IInvoice> lst;

            if (!model.InvNo.HasValue)
            {
                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);
                }
                if (DateFrom != null && DateTo != null && DateFrom > DateTo)
                {
                    Messages.AddErrorMessage("Nhập đúng dữ liệu tìm kiếm theo ngày!");
                    DateFrom = DateTo = null;
                }
                InvoiceStatus[] status = new InvoiceStatus[] { InvoiceStatus.SignedInv, InvoiceStatus.AdjustedInv, InvoiceStatus.ReplacedInv, InvoiceStatus.InUseInv };
                lst = IInvSrv.SearchByStatus(currentCom.id, model.Pattern, model.Serial, DateFrom, DateTo, model.nameCus, model.code, model.CodeTax, (InvoiceType)model.typeInvoice, currentPageIndex, defautPagesize, out totalRecords, status);
            }
            else
            {
                lst = new List <IInvoice>();
                IInvoice inv = IInvSrv.GetByNo(currentCom.id, model.Pattern, model.Serial, model.InvNo.Value);
                if (inv != null)
                {
                    lst.Add(inv);
                }
                totalRecords = lst.Count();
            }
            model.PageListINV = new PagedList <IInvoice>(lst, currentPageIndex, defautPagesize, totalRecords);
            return(View(model));
        }
Пример #2
0
        public ActionResult Index(EInvoiceIndexModel model, int?page, int?Pagesize)
        {
            IPublishInvoiceService _PubIn = IoC.Resolve <IPublishInvoiceService>();
            Company currentCom            = ((EInvoiceContext)FXContext.Current).CurrentCompany;

            try
            {
                IList <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"));
                }
                if (model == null)
                {
                    model = new EInvoiceIndexModel();
                }
                model.Pattern    = string.IsNullOrEmpty(model.Pattern) ? lstpattern[0] : model.Pattern;
                model.lstpattern = lstpattern;
                List <string> LstSerial = _PubIn.ListSerialByPattern(currentCom.id, model.Pattern, new int[] { 1, 2, 3 }).Distinct().ToList <string>();
                model.lstserial = LstSerial;
                int defautPagesize   = Pagesize.HasValue ? Convert.ToInt32(Pagesize) : 10;
                int currentPageIndex = page.HasValue ? page.Value - 1 : 0;
                int totalRecords     = 0;

                IInvoiceService  IInvSrv = InvServiceFactory.GetService(model.Pattern, currentCom.id);
                IList <IInvoice> lst;
                if (!model.InvNo.HasValue || model.InvNo == null)
                {
                    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);
                    }
                    if (DateFrom != null && DateTo != null && DateFrom > DateTo)
                    {
                        Messages.AddErrorMessage("Nhập đúng dữ liệu tìm kiếm theo ngày!");
                        DateFrom = DateTo = null;
                    }
                    lst = IInvSrv.SearchByCustomer(currentCom.id, model.Pattern, model.Serial, DateFrom, DateTo, (InvoiceStatus)model.Status, model.nameCus, model.code, model.CodeTax, (InvoiceType)model.typeInvoice, currentPageIndex, defautPagesize, out totalRecords);
                }
                else
                {
                    lst          = IInvSrv.GetListByNo(currentCom.id, model.Pattern, model.Serial, model.InvNo.Value);
                    totalRecords = lst.Count();
                }
                model.PageListINV = new PagedList <IInvoice>(lst, currentPageIndex, defautPagesize, totalRecords);
                int signPlugin = 0;
                if (currentCom.Config.Keys.Contains("SignPlugin"))
                {
                    int.TryParse(currentCom.Config["SignPlugin"], out signPlugin);
                }
                model.SignPlugin = signPlugin;
                return(View(model));
            }
            catch (UnAuthorizedException e)
            {
                log.Error(e);
                Messages.AddErrorMessage("Có lỗi xảy ra, vui lòng thực hiện lại!");
                return(RedirectToAction("Index", "Home"));
            }
            catch (ArgumentException ex)
            {
                log.Error(ex);
                return(Redirect("/Home/PotentiallyError"));
            }
            catch (HttpRequestValidationException ex)
            {
                log.Error(ex);
                return(RedirectToAction("PotentiallyError", "Home"));
            }
        }