Ejemplo n.º 1
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.º 2
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.º 3
0
        public ActionResult Create(string Pattern)
        {
            ICompanyService        comSrv     = IoC.Resolve <ICompanyService>();
            Company                currentCom = comSrv.Getbykey(((EInvoiceContext)FXContext.Current).CurrentCompany.id);
            IPublishInvoiceService _PubIn     = IoC.Resolve <IPublishInvoiceService>();
            IRegisterTempService   _ReTemSvc  = IoC.Resolve <IRegisterTempService>();
            string   ViewName = InvServiceFactory.GetView(Pattern, currentCom.id) + "Create";
            IInvoice model    = InvServiceFactory.NewInstance(Pattern, currentCom.id);

            model.Pattern = Pattern;
            model.ComID   = currentCom.id;
            model.Name    = _ReTemSvc.SeachNameInv(Pattern, currentCom.id);
            List <string> ser = _PubIn.GetSerialByPatter(Pattern, currentCom.id);

            if (ser.Count == 0)
            {
                Messages.AddErrorFlashMessage("Dải số đã hết hoặc đã bị hủy.");
                return(RedirectToAction("Index", new { Pattern = Pattern }));
            }
            ViewData["ser"]     = ser;
            ViewData["company"] = currentCom;
            return(View(ViewName, model));
        }
Ejemplo n.º 4
0
        public ActionResult CreateAdJustInv(AdjustModel model)
        {
            try
            {
                ICompanyService        comSrv     = IoC.Resolve <ICompanyService>();
                Company                currentCom = comSrv.Getbykey(((EInvoiceContext)FXContext.Current).CurrentCompany.id);
                IPublishInvoiceService PubIn      = IoC.Resolve <IPublishInvoiceService>();

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

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

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

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

                //Lấy ra đối tượng hóa đơn cần thay thế
                //Hóa đơn đã thay thế và kê khai thuế thì không được chỉnh sửa
                IInvoice inv = IInvSrv.GetByNo(currentCom.id, model.pattern, model.serial, Convert.ToDecimal(model.invNo));
                if (inv.Status == InvoiceStatus.ReplacedInv || inv.Status == InvoiceStatus.CanceledInv)
                {
                    Messages.AddErrorFlashMessage("Hóa đơn đã bị thay thế hoặc bị hủy!");
                    return(RedirectToAction("SearchAdJustInv"));
                }
                int type = 0;
                int.TryParse(model.type, out type);
                model.pattern          = newPattern ?? model.pattern;
                model.serial           = newSerial ?? model.serial;
                ViewData["NewPattern"] = model.pattern;
                ViewData["NewSerial"]  = model.serial;
                ViewData["Data"]       = inv;
                ViewData["company"]    = currentCom;
                ViewData["type"]       = model.type;
                //them dong chu tang hay giam
                ViewData["typeName"] = model.typeName;
                int signPlugin = 0;
                if (currentCom.Config.Keys.Contains("SignPlugin"))
                {
                    int.TryParse(currentCom.Config["SignPlugin"], out signPlugin);
                }
                ViewData["SignPlugin"] = signPlugin;
                if (inv.Pattern != model.pattern)
                {
                    IInvoice invNew = InvServiceFactory.NewInstance(model.pattern, currentCom.id);
                    invNew.ComID         = currentCom.id;
                    invNew.Name          = inv.Name;
                    invNew.CusName       = inv.CusName;
                    invNew.CusCode       = inv.CusCode;
                    invNew.CusAddress    = inv.CusAddress;
                    invNew.Buyer         = inv.Buyer;
                    invNew.No            = inv.No;
                    invNew.Serial        = inv.Serial;
                    invNew.Note          = "";
                    invNew.PaymentMethod = inv.PaymentMethod;
                    invNew.Products      = inv.Products;
                    invNew.Pattern       = inv.Pattern;
                    invNew.Type          = (InvoiceType)type;
                    invNew.Amount        = inv.Amount;
                    invNew.Total         = inv.Total;
                    invNew.VATAmount     = inv.VATAmount;
                    string adjustView = InvServiceFactory.GetView(model.pattern, currentCom.id) + "CreateAdJustInv";
                    return(View(adjustView, invNew));
                }
                inv.Note = "";
                inv.Type = (InvoiceType)type;
                string ViewName = InvServiceFactory.GetView(model.pattern, currentCom.id) + "CreateAdJustInv";
                return(View(ViewName, inv));
            }
            catch (Exception ex)
            {
                log.Error(" CreateAdJustInv -:" + ex);
                Messages.AddErrorFlashMessage("Không tồn tại hóa đơn này!");
                return(RedirectToAction("SearchAdJustInv"));
            }
        }
Ejemplo n.º 5
0
        public ActionResult Edit(string Pattern, int id, string PubDatasource)
        {
            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
            {
                string ErrorMessage = "";
                TryUpdateModelFromType(model.GetType(), model);
                model.CusCode = !string.IsNullOrWhiteSpace(model.CusCode) ? model.CusCode : model.CusTaxCode;
                model.Note    = NoteOrder + " || " + model.Note;
                if (!String.IsNullOrEmpty(PubDatasource) && PubDatasource != "[]")
                {
                    ICustomerService _CusSvc = FX.Core.IoC.Resolve <ICustomerService>();
                    var Typecus = (from c in _CusSvc.Query where c.Code == model.CusCode && c.CusType == 1 select c.CusType).FirstOrDefault();
                    if (Typecus == 0)
                    {
                        model.CusSignStatus = cusSignStatus.NocusSignStatus;
                    }
                    else
                    {
                        model.CusSignStatus = cusSignStatus.NoSignStatus;
                    }
                    IList <ProductInv> lstproduct = (IList <ProductInv>)PubDatasource.DeserializeJSON <ProductInv>(typeof(IList <ProductInv>));

                    if (IInvSrv.UpdateInvoice(lstproduct, model, out ErrorMessage) == true)
                    {
                        log.Info("Edit EInvoice by: " + HttpContext.User.Identity.Name + " Info-- TenKhachHang: " + model.CusName + " MaKhachHang: " + model.CusCode + " SoTien: " + model.Amount);
                        Messages.AddFlashMessage("Cập nhật hóa đơn thành công.");
                        return(RedirectToAction("Index", new { Pattern = Pattern, Serial = model.Serial }));
                    }
                    else
                    {
                        Messages.AddErrorMessage(ErrorMessage);
                    }
                    model.Products = (from pr in lstproduct select pr as IProductInv).ToList();
                }
                else
                {
                    Messages.AddErrorMessage("Chưa nhập thông tin sản phẩm");
                }
                model.Name = _ReTemSvc.SeachNameInv(Pattern, currentCom.id);
                List <string> ser = _PubIn.GetSerialByPatter(model.Pattern, currentCom.id);
                ViewData["ser"]     = ser;
                ViewData["company"] = currentCom;
                string ViewName = InvServiceFactory.GetView(Pattern, currentCom.id) + "Edit";
                return(View(ViewName, model));
            }
            catch (HttpRequestValidationException ex)
            {
                log.Error("ArgumentException: " + ex);
                Messages.AddErrorMessage("Dữ liệu không hợp lệ hoặc có chứa mã gây nguy hiểm tiềm tàng cho hệ thống!");
                model = 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");
                if (!String.IsNullOrEmpty(PubDatasource))
                {
                    IList <ProductInv> lstproduct = (IList <ProductInv>)PubDatasource.DeserializeJSON <ProductInv>(typeof(IList <ProductInv>));
                    model.Products = (from pr in lstproduct select pr as IProductInv).ToList();
                }
                string ViewName = InvServiceFactory.GetView(Pattern, currentCom.id) + "Edit";
                return(View(ViewName, model));
            }
        }