Exemple #1
0
        public ActionResult DetailCurrent()
        {
            int _comid = ((EInvoiceContext)FXContext.Current).CurrentCompany.id;

            try
            {
                ICompanyService      _comSrv = IoC.Resolve <ICompanyService>();
                Company              model   = _comSrv.Getbykey(_comid);
                ITaxAuthorityService _taxSvc = IoC.Resolve <ITaxAuthorityService>();
                if (!string.IsNullOrWhiteSpace(model.TaxAuthorityCode))
                {
                    var tax = _taxSvc.Getbykey(model.TaxAuthorityCode);
                    ViewData["taxname"] = tax != null ? tax.Name : "";
                }
                else
                {
                    ViewData["taxname"] = "";
                }
                return(View(model));
            }
            catch (Exception ex)
            {
                log.Error(" DetailCurrent  -" + ex.Message);
                return(RedirectToAction("Index", "Home"));
            }
        }
        public ActionResult EditRPublish(int id)
        {
            IPublishService pubSrc = IoC.Resolve <IPublishService>();
            Publish         opub   = pubSrc.Getbykey(id);

            if (opub.Status != PublishStatus.InUse)
            {
                PublishModel model           = new PublishModel();
                Company      _currentcompany = IoC.Resolve <ICompanyService>().Getbykey(((EInvoiceContext)FXContext.Current).CurrentCompany.id);

                ITaxAuthorityService taxSrc = IoC.Resolve <ITaxAuthorityService>();
                model.TaxList = new SelectList(from tax in taxSrc.Query select tax, "Code", "Name", opub.TaxAuthorityCode);
                IRegisterTempService regisSrc = IoC.Resolve <IRegisterTempService>();
                model.RegTempList = new SelectList(from re in regisSrc.Query where re.ComId == _currentcompany.id select re, "Id", "Name");

                model.mPublish       = opub;
                model.PubInvoiceList = opub.PublishInvoices.SerializeJSON <PublishInvoice>();
                return(View(model));
            }
            else
            {
                Messages.AddErrorFlashMessage("Thông báo phát hành này không được phép sửa");
                return(RedirectToAction("Index"));
            }
        }
Exemple #3
0
        public ActionResult Edit()
        {
            int id = ((EInvoiceContext)FXContext.Current).CurrentCompany.id;
            ITaxAuthorityService _taxSvc = IoC.Resolve <ITaxAuthorityService>();
            IList <TaxAuthority> tax     = _taxSvc.GetAll();

            ViewData["tax"] = tax;
            ICompanyService _comSrv = IoC.Resolve <ICompanyService>();
            Company         model   = _comSrv.Getbykey(id);

            return(View(model));
        }
Exemple #4
0
        public ActionResult Update(int id)
        {
            Company _currentCompany = ((EInvoiceContext)FXContext.Current).CurrentCompany;

            if (id != _currentCompany.id)
            {
                return(Redirect("/Home/PotentiallyError"));
            }
            ICompanyService _comSrv = IoC.Resolve <ICompanyService>();
            Company         model   = _comSrv.Getbykey(_currentCompany.id);

            try
            {
                TryUpdateModel <Company>(model);
                model.TaxCode = Utils.formatTaxcode(model.TaxCode);
                _comSrv.Save(model);
                _comSrv.CommitChanges();
                Messages.AddFlashMessage(Resources.Message.Com_UMesInfSuccess);
                log.Info("Update Company: " + HttpContext.User.Identity.Name);
                return(RedirectToAction("DetailCurrent"));
            }
            catch (HttpRequestValidationException ex)
            {
                return(Redirect("/Home/PotentiallyError"));
            }
            catch (ArgumentException ex)
            {
                return(Redirect("/Home/PotentiallyError"));
            }
            catch (Exception ex)
            {
                Messages.AddErrorMessage("Có lỗi xảy ra, vui lòng thực hiện lại!");
                log.Error("Error Update-" + ex);
                ITaxAuthorityService _taxSvc = IoC.Resolve <ITaxAuthorityService>();
                IList <TaxAuthority> tax     = _taxSvc.GetAll();
                ViewData["tax"] = tax;
                return(View("Edit", model));
            }
        }
        public ActionResult CreateRPublish()
        {
            Company              _currentcompany = IoC.Resolve <ICompanyService>().Getbykey(((EInvoiceContext)FXContext.Current).CurrentCompany.id);
            PublishModel         model           = new PublishModel();
            ITaxAuthorityService taxSrc          = IoC.Resolve <ITaxAuthorityService>();
            IRegisterTempService regisSrc        = IoC.Resolve <IRegisterTempService>();

            model.TaxList     = new SelectList(from tax in taxSrc.Query select tax, "Code", "Name");
            model.RegTempList = new SelectList(from re in regisSrc.Query where re.ComId == _currentcompany.id select re, "Id", "Name");
            Publish mPub = new Publish();

            mPub.ComID           = _currentcompany.id;
            mPub.ComName         = _currentcompany.Name;
            mPub.ComAddress      = _currentcompany.Address;
            mPub.ComTaxCode      = _currentcompany.TaxCode;
            mPub.ComPhone        = _currentcompany.Phone;
            mPub.RepresentPerson = _currentcompany.RepresentPerson;
            mPub.City            = "Hà Nội";
            model.mPublish       = mPub;
            model.PubInvoiceList = "[]";
            return(View(model));
        }
        public ActionResult UpdatePublish(int id, string PubInvoiceList)
        {
            if (id <= 0)
            {
                throw new HttpRequestValidationException();
            }
            IPublishService      pubSrc = IoC.Resolve <IPublishService>();
            ITaxAuthorityService taxSrv = IoC.Resolve <ITaxAuthorityService>();
            Publish opub = pubSrc.Getbykey(id);

            try
            {
                TryUpdateModel <Publish>(opub);
                opub.TaxAuthorityName = (from tax in taxSrv.Query where tax.Code == opub.TaxAuthorityCode select tax.Name).FirstOrDefault();
                JavaScriptSerializer   jss = new JavaScriptSerializer();
                IList <PublishInvoice> lst = jss.Deserialize <IList <PublishInvoice> >(PubInvoiceList);
                foreach (var it in lst)
                {
                    IPublishInvoiceService pubinvSrv = IoC.Resolve <IPublishInvoiceService>();
                    ICompanyService        _comSrv   = IoC.Resolve <ICompanyService>();
                    Company _currentcompany          = _comSrv.Getbykey(((EInvoiceContext)FXContext.Current).CurrentCompany.id);
                    string  invSer = string.Format("{0}/{1}E", it.InvSerialPrefix, it.InvSerialSuffix);
                    var     old    = pubinvSrv.Query.Where(p => p.RegisterID == it.RegisterID && p.InvSerial == invSer && p.StartDate > it.StartDate && p.FromNo < it.FromNo && p.ComId == _currentcompany.id).FirstOrDefault();
                    if (old != null)
                    {
                        Messages.AddErrorMessage(string.Format("Thông báo có ký hiệu {0}, phải có ngày bắt đầu từ ngày: {1}", old.InvSerial, old.StartDate.ToString("dd/MM/yyyy")));
                        PublishModel model = new PublishModel();
                        model.mPublish = opub;
                        ITaxAuthorityService taxSrc = IoC.Resolve <ITaxAuthorityService>();
                        model.TaxList = new SelectList(from tax in taxSrc.Query select tax, "Code", "Name", opub.TaxAuthorityCode);
                        IRegisterTempService regisSrc = IoC.Resolve <IRegisterTempService>();
                        model.RegTempList    = new SelectList(from re in regisSrc.Query where re.ComId == _currentcompany.id select re, "Id", "Name");
                        model.PubInvoiceList = opub.PublishInvoices.SerializeJSON <PublishInvoice>();
                        return(View("EditRPublish", model));
                    }
                    else
                    {
                        old = pubinvSrv.Query.Where(p => p.RegisterID == it.RegisterID && p.InvSerial == invSer && p.StartDate <it.StartDate && p.FromNo> it.FromNo && p.ComId == _currentcompany.id).FirstOrDefault();
                        if (old != null)
                        {
                            Messages.AddErrorMessage(string.Format("Thông báo có ký hiệu {0}, phải có ngày bắt đầu nhỏ hơn ngày: {1}", old.InvSerial, old.StartDate.ToString("dd/MM/yyyy")));
                            PublishModel model = new PublishModel();
                            model.mPublish = opub;
                            ITaxAuthorityService taxSrc = IoC.Resolve <ITaxAuthorityService>();
                            model.TaxList = new SelectList(from tax in taxSrc.Query select tax, "Code", "Name", opub.TaxAuthorityCode);
                            IRegisterTempService regisSrc = IoC.Resolve <IRegisterTempService>();
                            model.RegTempList    = new SelectList(from re in regisSrc.Query where re.ComId == _currentcompany.id select re, "Id", "Name");
                            model.PubInvoiceList = opub.PublishInvoices.SerializeJSON <PublishInvoice>();
                            return(View("EditRPublish", model));
                        }
                    }
                }
                string mess = "";
                if (pubSrc.Update(opub, lst, out mess) == true)
                {
                    StringBuilder InvInfo = new StringBuilder();
                    for (int i = 0; i < lst.Count; i++)
                    {
                        InvInfo.AppendFormat("{0};{1};{2};{3};{4}_", lst[i].RegisterID, lst[i].InvSerial, lst[i].Quantity, lst[i].FromNo, lst[i].ToNo);
                    }
                    log.Info("Edit Publish by: " + HttpContext.User.Identity.Name + "|InvInfo:" + InvInfo.ToString());
                    Messages.AddFlashMessage("Sửa thành công");
                    return(RedirectToAction("Index"));
                }
                else
                {
                    log.Error("Update Publish:" + mess);
                    ICompanyService _comSrv         = IoC.Resolve <ICompanyService>();
                    Company         _currentcompany = _comSrv.Getbykey(((EInvoiceContext)FXContext.Current).CurrentCompany.id);
                    PublishModel    model           = new PublishModel();
                    model.mPublish = opub;
                    ITaxAuthorityService taxSrc = IoC.Resolve <ITaxAuthorityService>();
                    model.TaxList = new SelectList(from tax in taxSrc.Query select tax, "Code", "Name", opub.TaxAuthorityCode);
                    IRegisterTempService regisSrc = IoC.Resolve <IRegisterTempService>();
                    model.RegTempList    = new SelectList(from re in regisSrc.Query where re.ComId == _currentcompany.id select re, "Id", "Name");
                    model.PubInvoiceList = opub.PublishInvoices.SerializeJSON <PublishInvoice>();
                    Messages.AddErrorMessage(mess);
                    return(View("EditRPublish", model));
                }
            }
            catch (Exception ex)
            {
                log.Error("EditRPublish -" + ex);
                Messages.AddErrorMessage("Có lỗi xảy ra, vui lòng thực hiện lại!");
                PublishModel model = new PublishModel();
                model.mPublish = opub;
                ICompanyService      _comSrv         = IoC.Resolve <ICompanyService>();
                Company              _currentcompany = _comSrv.Getbykey(((EInvoiceContext)FXContext.Current).CurrentCompany.id);
                ITaxAuthorityService taxSrc          = IoC.Resolve <ITaxAuthorityService>();
                model.TaxList = new SelectList(from tax in taxSrc.Query select tax, "Code", "Name", opub.TaxAuthorityCode);
                IRegisterTempService regisSrc = IoC.Resolve <IRegisterTempService>();
                model.RegTempList    = new SelectList(from re in regisSrc.Query where re.ComId == _currentcompany.id select re, "Id", "Name");
                model.PubInvoiceList = opub.PublishInvoices.SerializeJSON <PublishInvoice>();
                return(View("EditRPublish", model));
            }
        }
        public ActionResult CreateRPublish(Publish mPub, string PubInvoiceList)
        {
            IPublishService      pubSrc  = IoC.Resolve <IPublishService>();
            ITaxAuthorityService taxSrv  = IoC.Resolve <ITaxAuthorityService>();
            ICompanyService      _comSrv = IoC.Resolve <ICompanyService>();
            string message = "";

            try
            {
                mPub.TaxAuthorityName = (from tax in taxSrv.Query where tax.Code == mPub.TaxAuthorityCode select tax.Name).FirstOrDefault();
                JavaScriptSerializer   jss = new JavaScriptSerializer();
                IList <PublishInvoice> lst = jss.Deserialize <IList <PublishInvoice> >(PubInvoiceList);
                Company _currentcompany    = _comSrv.Getbykey(((EInvoiceContext)FXContext.Current).CurrentCompany.id);
                foreach (var it in lst)
                {
                    IPublishInvoiceService pubinvSrv = IoC.Resolve <IPublishInvoiceService>();
                    string invSer = string.Format("{0}/{1}E", it.InvSerialPrefix, it.InvSerialSuffix);
                    var    old    = pubinvSrv.Query.Where(p => p.RegisterID == it.RegisterID && p.InvSerial == invSer && p.StartDate > it.StartDate && p.ComId == _currentcompany.id).FirstOrDefault();
                    if (old != null)
                    {
                        Messages.AddErrorMessage(string.Format("Thông báo có ký hiệu {0}, phải có ngày bắt đầu sau ngày: {1}", old.InvSerial, old.StartDate.ToString("dd/MM/yyyy")));
                        PublishModel model = new PublishModel();
                        model.mPublish = mPub;
                        ITaxAuthorityService taxSrc = IoC.Resolve <ITaxAuthorityService>();
                        model.TaxList = new SelectList(from tax in taxSrc.Query select tax, "Code", "Name", mPub.TaxAuthorityCode);
                        IRegisterTempService regisSrc = IoC.Resolve <IRegisterTempService>();
                        model.RegTempList    = new SelectList(from re in regisSrc.Query where re.ComId == _currentcompany.id select re, "Id", "Name");
                        model.PubInvoiceList = lst.SerializeJSON <PublishInvoice>();
                        return(View(mPub));
                    }

                    var pub = pubinvSrv.Query.Where(p => p.RegisterID == it.RegisterID && p.InvSerial == invSer && p.FromNo == it.FromNo && p.ComId == _currentcompany.id);
                    if (pub.Count() > 0)
                    {
                        Messages.AddErrorMessage(string.Format("Đã tồn tại giải hóa đơn tương ứng ký hiệu {0}", it.InvSerial));
                        PublishModel model = new PublishModel();
                        model.mPublish = mPub;
                        ITaxAuthorityService taxSrc = IoC.Resolve <ITaxAuthorityService>();
                        model.TaxList = new SelectList(from tax in taxSrc.Query select tax, "Code", "Name", mPub.TaxAuthorityCode);
                        IRegisterTempService regisSrc = IoC.Resolve <IRegisterTempService>();
                        model.RegTempList    = new SelectList(from re in regisSrc.Query where re.ComId == _currentcompany.id select re, "Id", "Name");
                        model.PubInvoiceList = lst.SerializeJSON <PublishInvoice>();
                        return(View(mPub));
                    }
                }

                if (pubSrc.CreateNew(mPub, lst, out message) == true)
                {
                    _currentcompany.IsUsed = true;
                    _comSrv.Update(_currentcompany);
                    _comSrv.CommitChanges();
                    StringBuilder InvInfo = new StringBuilder();
                    for (int i = 0; i < lst.Count; i++)
                    {
                        InvInfo.AppendFormat("{0};{1};{2};{3};{4}_", lst[i].RegisterID, lst[i].InvSerial, lst[i].Quantity, lst[i].FromNo, lst[i].ToNo);
                    }
                    log.Info("Create Publish by: " + HttpContext.User.Identity.Name + "|InvInfo:" + InvInfo.ToString());
                    Messages.AddFlashMessage("Tạo phát hành thành công!");
                    return(RedirectToAction("Index"));
                }
                else
                {
                    log.Error("Create Publish:" + message);
                    Messages.AddErrorMessage("Có lỗi xảy ra, vui lòng thực hiện lại!");
                    PublishModel model = new PublishModel();
                    model.mPublish = mPub;
                    ITaxAuthorityService taxSrc = IoC.Resolve <ITaxAuthorityService>();
                    model.TaxList = new SelectList(from tax in taxSrc.Query select tax, "Code", "Name", mPub.TaxAuthorityCode);
                    IRegisterTempService regisSrc = IoC.Resolve <IRegisterTempService>();
                    model.RegTempList    = new SelectList(from re in regisSrc.Query where re.ComId == _currentcompany.id select re, "Id", "Name");
                    model.PubInvoiceList = lst.SerializeJSON <PublishInvoice>();
                    return(View(mPub));
                }
            }
            catch (Exception ex)
            {
                JavaScriptSerializer   jss = new JavaScriptSerializer();
                IList <PublishInvoice> lst = jss.Deserialize <IList <PublishInvoice> >(PubInvoiceList);
                log.Error(" CreateRPublish -" + ex);
                Messages.AddErrorMessage("Có lỗi xảy ra, vui lòng thực hiện lại.");
                Company      _currentcompany = _comSrv.Getbykey(((EInvoiceContext)FXContext.Current).CurrentCompany.id);
                PublishModel model           = new PublishModel();
                model.mPublish = mPub;
                ITaxAuthorityService taxSrc = IoC.Resolve <ITaxAuthorityService>();
                model.TaxList = new SelectList(from tax in taxSrc.Query select tax, "Code", "Name", mPub.TaxAuthorityCode);
                IRegisterTempService regisSrc = IoC.Resolve <IRegisterTempService>();
                model.RegTempList    = new SelectList(from re in regisSrc.Query where re.ComId == _currentcompany.id select re, "Id", "Name");
                model.PubInvoiceList = lst.SerializeJSON <PublishInvoice>();
                return(View(mPub));
            }
        }