Beispiel #1
0
        public ActionResult Edit(TemplatePrintViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (Request["Submit"] == "Save")
                {
                    var TemplatePrint = TemplatePrintRepository.GetTemplatePrintById(model.Id);
                    AutoMapper.Mapper.Map(model, TemplatePrint);
                    TemplatePrint.ModifiedUserId = WebSecurity.CurrentUserId;
                    TemplatePrint.ModifiedDate   = DateTime.Now;
                    TemplatePrintRepository.UpdateTemplatePrint(TemplatePrint);

                    TempData[Globals.SuccessMessageKey] = App_GlobalResources.Wording.UpdateSuccess;
                    return(RedirectToAction("Index"));
                }

                return(View(model));
            }

            return(View(model));

            //if (Request.UrlReferrer != null)
            //    return Redirect(Request.UrlReferrer.AbsoluteUri);
            //return RedirectToAction("Index");
        }
Beispiel #2
0
        public ActionResult Print(int Id, bool ExportExcel = false)
        {
            var model = new TemplatePrintViewModel();
            //lấy logo công ty
            var logo     = Erp.BackOffice.Helpers.Common.GetSetting("LogoCompany");
            var company  = Erp.BackOffice.Helpers.Common.GetSetting("companyName");
            var address  = Erp.BackOffice.Helpers.Common.GetSetting("addresscompany");
            var phone    = Erp.BackOffice.Helpers.Common.GetSetting("phonecompany");
            var fax      = Erp.BackOffice.Helpers.Common.GetSetting("faxcompany");
            var bankcode = Erp.BackOffice.Helpers.Common.GetSetting("bankcode");
            var bankname = Erp.BackOffice.Helpers.Common.GetSetting("bankname");
            var ImgLogo  = "<div class=\"logo\"><img src=" + logo + " height=\"73\" /></div>";
            //lấy hóa đơn.
            var aa   = WelfareProgramsRepository.GetWelfareProgramsById(Id);
            var user = userRepository.GetUserById(aa.CreatedUserId.Value);

            //lấy thông tin khách hàng
            var staff            = WelfareProgramsDetailRepository.GetAllvwWelfareProgramsDetail().Where(x => x.WelfareProgramsId == aa.Id).ToList();
            var ProvideDate      = aa.ProvideStartDate.Value.ToString("dd/MM/yyyy HH:mm") + " - " + aa.ProvideEndDate.Value.ToString("dd/MM/yyyy HH:mm");
            var RegistrationDate = aa.RegistrationStartDate.Value.ToString("dd/MM/yyyy HH:mm") + " - " + aa.RegistrationEndDate.Value.ToString("dd/MM/yyyy HH:mm");
            //lấy template phiếu xuất.
            var template = templatePrintRepository.GetAllTemplatePrint().Where(x => x.Code.Contains("WelfarePrograms")).OrderByDescending(x => x.CreatedDate).FirstOrDefault();

            //truyền dữ liệu vào template.
            model.Content = template.Content;
            model.Content = model.Content.Replace("{WelfareCode}", aa.Code);
            model.Content = model.Content.Replace("{WelfareName}", aa.Name);
            model.Content = model.Content.Replace("{ProvideDate}", ProvideDate);
            model.Content = model.Content.Replace("{RegistrationDate}", RegistrationDate);
            model.Content = model.Content.Replace("{Address}", aa.Address);
            model.Content = model.Content.Replace("{Category}", aa.Category);
            model.Content = model.Content.Replace("{StaffCreateName}", user.FullName);

            model.Content = model.Content.Replace("{DataTable}", buildHtmlDetailList(staff));
            model.Content = model.Content.Replace("{System.Logo}", ImgLogo);
            model.Content = model.Content.Replace("{System.CompanyName}", company);
            model.Content = model.Content.Replace("{System.AddressCompany}", address);
            model.Content = model.Content.Replace("{System.PhoneCompany}", phone);
            model.Content = model.Content.Replace("{System.Fax}", fax);
            model.Content = model.Content.Replace("{System.BankCodeCompany}", bankcode);
            model.Content = model.Content.Replace("{System.BankNameCompany}", bankname);
            //Tạo barcode
            //Image barcode = Code128Rendering.MakeBarcodeImage(productInvoice.Code, 1, true);
            //model.Content = model.Content.Replace("{BarcodeImgSource}", ImageToBase64(barcode, System.Drawing.Imaging.ImageFormat.Png));
            if (ExportExcel)
            {
                Response.AppendHeader("content-disposition", "attachment;filename=" + "KeHoachPhucLoi_" + aa.Code + ".xls");
                Response.Charset = "";
                Response.Cache.SetCacheability(HttpCacheability.NoCache);
                Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                Response.Write(model.Content);
                Response.End();
            }
            return(View(model));
        }
Beispiel #3
0
        public ActionResult Print(int?Id, int?TargetId, int?Month, int?Year)
        {
            var model = new TemplatePrintViewModel();
            //lấy logo công ty
            //var logo = Erp.BackOffice.Helpers.Common.GetSetting("LogoCompany");
            var company  = Erp.BackOffice.Helpers.Common.GetSetting("companyName");
            var address  = Erp.BackOffice.Helpers.Common.GetSetting("addresscompany");
            var phone    = Erp.BackOffice.Helpers.Common.GetSetting("phonecompany");
            var fax      = Erp.BackOffice.Helpers.Common.GetSetting("faxcompany");
            var bankcode = Erp.BackOffice.Helpers.Common.GetSetting("bankcode");
            var bankname = Erp.BackOffice.Helpers.Common.GetSetting("bankname");
            //var ImgLogo = "<div class=\"logo\"><img src=" + logo + " height=\"73\" /></div>";
            //lấy phiếu chi.
            vwPayment payment = new vwPayment();

            if (Id != null)
            {
                payment = paymentRepository.GetvwPaymentById(Id.Value);
            }
            else
            {
                payment = paymentRepository.GetAllvwPayment().Where(x => x.TargetId == TargetId && x.TargetName == "Staffs" && x.Name == "Chi trả lương tháng " + Month + "/" + Year).FirstOrDefault();
            }
            //lấy template phiếu xuất.
            var template = templatePrintRepository.GetAllTemplatePrint().Where(x => x.Code.Contains("Payment")).OrderByDescending(x => x.CreatedDate).FirstOrDefault();

            //truyền dữ liệu vào template.
            model.Content = template.Content;
            model.Content = model.Content.Replace("{Code}", payment.Code);
            model.Content = model.Content.Replace("{Company}", payment.ReceiverUserName);
            model.Content = model.Content.Replace("{Customer}", payment.Receiver);
            model.Content = model.Content.Replace("{Address}", payment.Address);
            model.Content = model.Content.Replace("{Reason}", payment.Name);
            model.Content = model.Content.Replace("{Money}", payment.Amount.ToCurrencyStr(null));
            model.Content = model.Content.Replace("{VoucherDate}", payment.VoucherDate != null?payment.VoucherDate.Value.ToShortDateString():"chưa có");

            model.Content = model.Content.Replace("{CreatedDate}", payment.CreatedDate.Value.ToString("dd/MM/yyyy HH:mm"));
            model.Content = model.Content.Replace("{SalerName}", payment.SalerName);
            model.Content = model.Content.Replace("{MoneyText}", Erp.BackOffice.Helpers.Common.ChuyenSoThanhChu_2(payment.Amount.ToString()));
            model.Content = model.Content.Replace("{Note}", payment.Note);

            model.Content = model.Content.Replace("{System.CompanyName}", company);
            model.Content = model.Content.Replace("{System.AddressCompany}", address);
            model.Content = model.Content.Replace("{System.PhoneCompany}", phone);
            model.Content = model.Content.Replace("{System.Fax}", fax);
            model.Content = model.Content.Replace("{System.BankCodeCompany}", bankcode);
            model.Content = model.Content.Replace("{System.BankNameCompany}", bankname);
            //Mid
            model.Content = model.Content.Replace("{DetailList}", buildHtmlDetailList(payment.Id, payment.Amount));
            return(View(model));
        }
Beispiel #4
0
        public ActionResult Create(TemplatePrintViewModel model)
        {
            if (ModelState.IsValid)
            {
                var TemplatePrint = new TemplatePrint();
                AutoMapper.Mapper.Map(model, TemplatePrint);
                TemplatePrint.IsDeleted      = false;
                TemplatePrint.CreatedUserId  = WebSecurity.CurrentUserId;
                TemplatePrint.ModifiedUserId = WebSecurity.CurrentUserId;
                TemplatePrint.AssignedUserId = WebSecurity.CurrentUserId;
                TemplatePrint.CreatedDate    = DateTime.Now;
                TemplatePrint.ModifiedDate   = DateTime.Now;
                TemplatePrint.ContentDefault = model.Content;
                TemplatePrintRepository.InsertTemplatePrint(TemplatePrint);

                TempData[Globals.SuccessMessageKey] = App_GlobalResources.Wording.InsertSuccess;
                return(RedirectToAction("Index"));
            }
            return(View(model));
        }
Beispiel #5
0
        public ActionResult Edit(int? Id)
        {
            var TemplatePrint = TemplatePrintRepository.GetTemplatePrintById(Id.Value);
            if (TemplatePrint != null && TemplatePrint.IsDeleted != true)
            {
                var model = new TemplatePrintViewModel();
                AutoMapper.Mapper.Map(TemplatePrint, model);

                //if (model.CreatedUserId != Helpers.Common.CurrentUser.Id && Helpers.Common.CurrentUser.UserTypeId != 1)
                //{
                //    TempData["FailedMessage"] = "NotOwner";
                //    return RedirectToAction("Index");
                //}

                return View(model);
            }
            if (Request.UrlReferrer != null)
                return Redirect(Request.UrlReferrer.AbsoluteUri);
            return RedirectToAction("Index");
        }
        public ActionResult Print(int Id)
        {
            var model = new TemplatePrintViewModel();
            //lấy logo công ty
            //var logo = Erp.BackOffice.Helpers.Common.GetSetting("LogoCompany");
            var company  = Erp.BackOffice.Helpers.Common.GetSetting("companyName");
            var address  = Erp.BackOffice.Helpers.Common.GetSetting("addresscompany");
            var phone    = Erp.BackOffice.Helpers.Common.GetSetting("phonecompany");
            var fax      = Erp.BackOffice.Helpers.Common.GetSetting("faxcompany");
            var bankcode = Erp.BackOffice.Helpers.Common.GetSetting("bankcode");
            var bankname = Erp.BackOffice.Helpers.Common.GetSetting("bankname");
            //var ImgLogo = "<div class=\"logo\"><img src=" + logo + " height=\"73\" /></div>";
            //lấy phiếu chi.
            var payment = paymentRepository.GetvwPaymentById(Id);

            //lấy template phiếu xuất.
            var template = templatePrintRepository.GetAllTemplatePrint().Where(x => x.Code.Contains("Payment")).OrderByDescending(x => x.CreatedDate).FirstOrDefault();

            //truyền dữ liệu vào template.
            model.Content = template.Content;
            model.Content = model.Content.Replace("{Code}", payment.Code);
            model.Content = model.Content.Replace("{Company}", payment.ReceiverUserName);
            model.Content = model.Content.Replace("{Customer}", payment.Receiver);
            model.Content = model.Content.Replace("{Address}", payment.Address);
            model.Content = model.Content.Replace("{Reason}", payment.Name);
            model.Content = model.Content.Replace("{Money}", Erp.BackOffice.Helpers.Common.PhanCachHangNgan2(payment.Amount).ToString());
            model.Content = model.Content.Replace("{VoucherDate}", payment.VoucherDate.Value.ToShortDateString());

            model.Content = model.Content.Replace("{CreatedDate}", payment.CreatedDate.Value.ToString("dd/MM/yyyy HH:mm"));
            model.Content = model.Content.Replace("{SalerName}", payment.SalerName);
            model.Content = model.Content.Replace("{MoneyText}", Erp.BackOffice.Helpers.Common.ChuyenSoThanhChu_2(Convert.ToInt32(payment.Amount.Value)));
            model.Content = model.Content.Replace("{Note}", payment.Note);

            model.Content = model.Content.Replace("{System.CompanyName}", company);
            model.Content = model.Content.Replace("{System.AddressCompany}", address);
            model.Content = model.Content.Replace("{System.PhoneCompany}", phone);
            model.Content = model.Content.Replace("{System.Fax}", fax);
            model.Content = model.Content.Replace("{System.BankCodeCompany}", bankcode);
            model.Content = model.Content.Replace("{System.BankNameCompany}", bankname);
            return(View(model));
        }
Beispiel #7
0
        public ActionResult Print(int?Id)
        {
            var PhysicalInventory = PhysicalInventoryRepository.GetAllvwPhysicalInventory()
                                    .Where(item => item.Id == Id).FirstOrDefault();

            //lấy logo công ty
            var logo     = Erp.BackOffice.Helpers.Common.GetSetting("LogoCompany");
            var company  = Erp.BackOffice.Helpers.Common.GetSetting("companyName");
            var address  = Erp.BackOffice.Helpers.Common.GetSetting("addresscompany");
            var phone    = Erp.BackOffice.Helpers.Common.GetSetting("phonecompany");
            var fax      = Erp.BackOffice.Helpers.Common.GetSetting("faxcompany");
            var bankcode = Erp.BackOffice.Helpers.Common.GetSetting("bankcode");
            var bankname = Erp.BackOffice.Helpers.Common.GetSetting("bankname");
            var ImgLogo  = "<div class=\"logo\"><img src=" + logo + " height=\"73\" /></div>";

            if (PhysicalInventory != null && PhysicalInventory.IsDeleted != true)
            {
                var model = new TemplatePrintViewModel();

                //lấy danh sách sản phẩm
                var user       = userRepository.GetUserById(PhysicalInventory.CreatedUserId.Value);
                var detailList = PhysicalInventoryRepository.GetAllvwPhysicalInventoryDetail(Id.Value).AsEnumerable()
                                 .Select(item => new PhysicalInventoryDetailViewModel
                {
                    Note                = item.Note,
                    ProductId           = item.ProductId,
                    ProductCode         = item.ProductCode,
                    ProductName         = item.ProductName,
                    PhysicalInventoryId = item.PhysicalInventoryId,
                    QuantityInInventory = item.QuantityInInventory,
                    QuantityRemaining   = item.QuantityRemaining,
                    QuantityDiff        = item.QuantityDiff,
                    CategoryCode        = item.CategoryCode
                })
                                 .OrderBy(item => item.CategoryCode)
                                 .ThenBy(item => item.ProductCode)
                                 .ToList();
                var groupList = detailList.GroupBy(x => new { x.CategoryCode }, (key, group) => new
                {
                    CategoryCode = key.CategoryCode,
                    ProductList  = group.ToList()
                });
                var ListRow = "";
                int n       = 1;
                foreach (var item in groupList)
                {
                    var Row = "<tr style=\"background:#eee\"><td colspan=\"5\"><b>" + item.CategoryCode + "</b></td></tr>";
                    foreach (var g in item.ProductList)
                    {
                        Row += "<tr>"
                               + "<td class=\"text-center\">" + n++ + "</td>"
                               + "<td class=\"text-left\">" + g.ProductCode + "-" + g.ProductName + "</td>"
                               + "<td>" + Erp.BackOffice.Helpers.Common.PhanCachHangNgan(g.QuantityInInventory) + "</td>"
                               + "<td>" + Erp.BackOffice.Helpers.Common.PhanCachHangNgan(g.QuantityRemaining) + "</td>"
                               + "<td>" + Erp.BackOffice.Helpers.Common.PhanCachHangNgan(g.QuantityDiff) + "</td></tr>";
                    }

                    ListRow += Row;
                }



                var style = "<style>.invoice-detail{ width:100%;margin-top: 10px;border-spacing: 0px;}"
                            + ".invoice-detail th{border: 1px solid #000;border-right: none;padding: 5px;}"
                            + " .invoice-detail tr th:last-child {border-right: 1px solid #000;}"
                            + " .invoice-detail td{padding: 5px 5px; border-bottom: 1px solid #000; border-left: 1px solid #000; height: 15px;font-size: 12px;}"
                            + " .invoice-detail tr td:last-child {border-right: 1px solid #000;}"
                            + ".invoice-detail tbody tr:last-child td {border-bottom: 1px solid #000;}"
                            + " .invoice-detail tfoot td{font-weight:bold;border-bottom: 1px solid #000;}"
                            + " .invoice-detail tfoot tr:first-child td{border-top: 1px solid #000;}"
                            + ".text-center{text-align:center;}"
                            + ".text-right{text-align:right;}"
                            + ".text-left{text-align:left;}"
                            + " .logo{ width: 100px;float: left; margin: 0 20px;height: 100px;line-height: 100px;}"
                            + ".logo img{ width:100%;vertical-align: middle;}"
                            + "</style>";

                var table = style + "<table class=\"invoice-detail\"><thead><tr> <th>STT</th> <th>Tên sản phẩm</th><th>SL hệ thống</th><th>SL thực tế</th><th>SL chênh lệch</th></tr></thead><tbody>"
                            + ListRow
                            + "</tbody></table>";

                //lấy template phiếu xuất.
                var template = templatePrintRepository.GetAllTemplatePrint().Where(x => x.Code.Contains("PhysicalInventory")).OrderByDescending(x => x.CreatedDate).FirstOrDefault();
                model.Content = template.Content;
                model.Content = model.Content.Replace("{Note}", PhysicalInventory.Note);
                model.Content = model.Content.Replace("{WarehouseName}", PhysicalInventory.WarehouseName);
                model.Content = model.Content.Replace("{ProductInboundCode}", PhysicalInventory.ProductInboundCode);
                model.Content = model.Content.Replace("{ProductOutboundCode}", PhysicalInventory.ProductOutboundCode);
                model.Content = model.Content.Replace("{Code}", PhysicalInventory.Code);
                model.Content = model.Content.Replace("{Day}", PhysicalInventory.CreatedDate.Value.Day.ToString());
                model.Content = model.Content.Replace("{Month}", PhysicalInventory.CreatedDate.Value.Month.ToString());
                model.Content = model.Content.Replace("{Year}", PhysicalInventory.CreatedDate.Value.Year.ToString());
                model.Content = model.Content.Replace("{DataTable}", table);
                model.Content = model.Content.Replace("{Logo}", ImgLogo);
                model.Content = model.Content.Replace("{System.CompanyName}", company);
                model.Content = model.Content.Replace("{System.AddressCompany}", address);
                model.Content = model.Content.Replace("{System.PhoneCompany}", phone);
                model.Content = model.Content.Replace("{System.Fax}", fax);
                model.Content = model.Content.Replace("{System.BankCodeCompany}", bankcode);
                model.Content = model.Content.Replace("{System.BankNameCompany}", bankname);
                return(View(model));
            }

            if (Request.UrlReferrer != null)
            {
                return(Redirect(Request.UrlReferrer.AbsoluteUri));
            }
            return(RedirectToAction("Index"));
        }
Beispiel #8
0
        public ViewResult Create()
        {
            var model = new TemplatePrintViewModel();

            return(View(model));
        }
Beispiel #9
0
        public ActionResult Print(int Id, bool ExportExcel = false)
        {
            try
            {
                var model = new TemplatePrintViewModel();
                //lấy logo công ty
                var logo     = Erp.BackOffice.Helpers.Common.GetSetting("LogoCompany");
                var company  = Erp.BackOffice.Helpers.Common.GetSetting("companyName");
                var address  = Erp.BackOffice.Helpers.Common.GetSetting("addresscompany");
                var phone    = Erp.BackOffice.Helpers.Common.GetSetting("phonecompany");
                var fax      = Erp.BackOffice.Helpers.Common.GetSetting("faxcompany");
                var bankcode = Erp.BackOffice.Helpers.Common.GetSetting("bankcode");
                var bankname = Erp.BackOffice.Helpers.Common.GetSetting("bankname");
                var ImgLogo  = "<div class=\"logo\"><img src=" + logo + " height=\"73\" /></div>";
                List <vwProductInvoiceDetail> detailList = new List <vwProductInvoiceDetail>();
                var TotalDiscountMoneyNT = TotalDiscountMoneyNTRepository.GetvwTotalDiscountMoneyNTById(Id);
                if (TotalDiscountMoneyNT != null && TotalDiscountMoneyNT.IsDeleted != true)
                {
                    detailList = productInvoiceRepository.GetAllvwInvoiceDetails()
                                 .Where(x => x.IsArchive == true && x.BranchId == TotalDiscountMoneyNT.DrugStoreId &&
                                        x.Month == TotalDiscountMoneyNT.Month && x.Year == TotalDiscountMoneyNT.Year).ToList();
                }


                //lấy template phiếu xuất.
                var template = templatePrintRepository.GetAllTemplatePrint().Where(x => x.Code.Contains("TotalDiscountMoneyNT")).OrderByDescending(x => x.CreatedDate).FirstOrDefault();
                //truyền dữ liệu vào template.
                model.Content = template.Content;
                model.Content = model.Content.Replace("{DrugStoreName}", TotalDiscountMoneyNT.DrugStoreName);
                model.Content = model.Content.Replace("{MonthYear}", TotalDiscountMoneyNT.Month + " NĂM " + TotalDiscountMoneyNT.Year);
                model.Content = model.Content.Replace("{PrintDate}", DateTime.Now.ToString("dd/MM/yyyy HH:mm"));
                model.Content = model.Content.Replace("{QuantityDay}", Erp.BackOffice.Helpers.Common.PhanCachHangNgan2(TotalDiscountMoneyNT.QuantityDay));
                model.Content = model.Content.Replace("{PercentDecrease}", Erp.BackOffice.Helpers.CommonSatic.ToCurrencyStr(TotalDiscountMoneyNT.PercentDecrease, null));
                model.Content = model.Content.Replace("{DecreaseAmount}", Erp.BackOffice.Helpers.CommonSatic.ToCurrencyStr(TotalDiscountMoneyNT.DecreaseAmount, null));
                model.Content = model.Content.Replace("{DiscountAmount}", Erp.BackOffice.Helpers.CommonSatic.ToCurrencyStr(TotalDiscountMoneyNT.DiscountAmount, null));
                model.Content = model.Content.Replace("{RemainingAmount}", Erp.BackOffice.Helpers.CommonSatic.ToCurrencyStr(TotalDiscountMoneyNT.RemainingAmount, null));

                model.Content = model.Content.Replace("{Amount}", Erp.BackOffice.Helpers.CommonSatic.ToCurrencyStr(detailList.Sum(x => x.Amount), null));
                model.Content = model.Content.Replace("{DataTable}", buildHtmlDetailList(detailList));
                model.Content = model.Content.Replace("{System.Logo}", ImgLogo);
                model.Content = model.Content.Replace("{System.CompanyName}", company);
                model.Content = model.Content.Replace("{System.AddressCompany}", address);
                model.Content = model.Content.Replace("{System.PhoneCompany}", phone);
                model.Content = model.Content.Replace("{System.Fax}", fax);
                model.Content = model.Content.Replace("{System.BankCodeCompany}", bankcode);
                model.Content = model.Content.Replace("{System.BankNameCompany}", bankname);
                model.Content = model.Content.Replace("{PrintDate}", DateTime.Now.ToString("dd/MM/yyyy HH:mm"));

                if (ExportExcel)
                {
                    Response.AppendHeader("content-disposition", "attachment;filename=" + DateTime.Now.ToString("yyyyMMdd") + "ChietKhauNhaThuoc" + ".xls");
                    Response.Charset = "";
                    Response.Cache.SetCacheability(HttpCacheability.NoCache);
                    Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                    Response.Write(model.Content);
                    Response.End();
                }
                return(View(model));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public ActionResult Print(int Id, bool ExportExcel = false)
        {
            var model = new TemplatePrintViewModel();
            //lấy logo công ty
            var logo     = Erp.BackOffice.Helpers.Common.GetSetting("LogoCompany");
            var company  = Erp.BackOffice.Helpers.Common.GetSetting("companyName");
            var address  = Erp.BackOffice.Helpers.Common.GetSetting("addresscompany");
            var phone    = Erp.BackOffice.Helpers.Common.GetSetting("phonecompany");
            var fax      = Erp.BackOffice.Helpers.Common.GetSetting("faxcompany");
            var bankcode = Erp.BackOffice.Helpers.Common.GetSetting("bankcode");
            var bankname = Erp.BackOffice.Helpers.Common.GetSetting("bankname");
            var ImgLogo  = "<div class=\"logo\"><img src=" + logo + " height=\"73\" /></div>";
            //lấy template phiếu xuất.
            var template = templatePrintRepository.GetAllTemplatePrint().Where(x => x.Code == "RePayPoints").OrderByDescending(x => x.CreatedDate).FirstOrDefault();

            if (template != null)
            {
                //lấy hóa đơn.
                var RePayPoints = vwRePayPointsService.Get(Id);
                //lấy thông tin khách hàng
                var customer = customerRepository.GetvwCustomerById(RePayPoints.CustomerId.Value);
                List <RePayPointsDetailViewModel> detailList = new List <RePayPointsDetailViewModel>();
                //lấy danh sách sản phẩm xuất kho
                detailList = vwRePayPointsDetailService.GetAllvwRePayPointsDetailByRePayPointId(Id)
                             .Select(x => new RePayPointsDetailViewModel
                {
                    Id           = x.Id,
                    Point        = x.Point,
                    GiftId       = x.GiftId,
                    GiftName     = x.GiftName,
                    GiftCode     = x.GiftCode,
                    Quantity     = x.Quantity,
                    Unit         = x.Unit,
                    TotalPoint   = x.TotalPoint,
                    CategoryCode = x.CategoryCode
                }).ToList();
                //tạo dòng của table html danh sách sản phẩm.
                var ListRow = "";
                int index   = 1;
                foreach (var item in detailList)
                {
                    var Row = "<tr>"
                              + "<td class=\"text-center\">" + index + "</td>"
                              + "<td class=\"text-left\">" + item.GiftCode + "</td>"
                              + "<td class=\"text-left\">" + item.GiftName + "</td>"
                              + "<td class=\"text-center\">" + item.Unit + "</td>"
                              + "<td class=\"text-right\">" + item.Quantity.Value + "</td>"
                              + "<td class=\"text-right\">" + Helpers.Common.PhanCachHangNgan(item.Point).Replace(".", ",") + "</td>"
                              + "<td class=\"text-right\">" + Helpers.Common.PhanCachHangNgan(item.TotalPoint).Replace(".", ",") + "</td></tr>";
                    ListRow += Row;
                    index++;
                }
                //khởi tạo table html.
                var table = "<table class=\"invoice-detail\"><thead><tr> <th style=\"width: 30px;\">STT</th><th style=\"width: 100px;\">Mã quà tặng</th><th>Tên quà tặng</th><th style=\"width: 80px;\">ĐVT</th><th style=\"width: 80px;\">Số lượng</th><th style=\"width: 100px;\">Điểm quy đổi</th><th style=\"width: 100px;\">Tổng điểm</th></tr></thead><tbody>"
                            + ListRow
                            + "</tbody><tfoot>"
                            + "</td><td colspan=\"4\" class=\"text-right\">Tổng cộng</td><td class=\"text-right\">"
                            + Erp.BackOffice.Helpers.Common.PhanCachHangNgan(detailList.Sum(x => x.Quantity)).Replace(".", ",")
                            + "</td><td></td><td class=\"text-right\">"
                            + Erp.BackOffice.Helpers.Common.PhanCachHangNgan(RePayPoints.TotalPoint).Replace(".", ",")
                            + "</td></tr>"
                            + "</tfoot></table>";

                //truyền dữ liệu vào template.
                string replacement = template.Content;
                Helpers.Common.DienDuLieu(ref replacement, RePayPoints, true, true);
                replacement   = replacement.Replace("{Day}", RePayPoints.CreatedDate.Value.Day.ToString());
                replacement   = replacement.Replace("{Month}", RePayPoints.CreatedDate.Value.Month.ToString());
                replacement   = replacement.Replace("{Year}", RePayPoints.CreatedDate.Value.Year.ToString());
                replacement   = replacement.Replace("{CustomerPhone}", customer.Phone);
                replacement   = replacement.Replace("{DataTable}", table);
                replacement   = replacement.Replace("{System.Logo}", ImgLogo);
                replacement   = replacement.Replace("{System.CompanyName}", company);
                replacement   = replacement.Replace("{System.AddressCompany}", address);
                replacement   = replacement.Replace("{System.PhoneCompany}", phone);
                replacement   = replacement.Replace("{System.Fax}", fax);
                replacement   = replacement.Replace("{System.BankCodeCompany}", bankcode);
                replacement   = replacement.Replace("{System.BankNameCompany}", bankname);
                model.Content = replacement;
                if (ExportExcel)
                {
                    Response.AppendHeader("content-disposition", "attachment;filename=" + RePayPoints.CreatedDate.Value.ToString("yyyyMMdd") + RePayPoints.Code + ".xlsx");
                    Response.Charset = "iso-8859-1";
                    Response.Cache.SetCacheability(HttpCacheability.NoCache);
                    Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                    Response.Write(model.Content);
                    Response.End();
                }
            }

            return(View(model));
        }
        public ActionResult Print(int?month, int?year, string Status, bool ExportExcel = false)
        {
            var model = new TemplatePrintViewModel();
            //lấy logo công ty
            var logo     = Erp.BackOffice.Helpers.Common.GetSetting("LogoCompany");
            var company  = Erp.BackOffice.Helpers.Common.GetSetting("companyName");
            var address  = Erp.BackOffice.Helpers.Common.GetSetting("addresscompany");
            var phone    = Erp.BackOffice.Helpers.Common.GetSetting("phonecompany");
            var fax      = Erp.BackOffice.Helpers.Common.GetSetting("faxcompany");
            var bankcode = Erp.BackOffice.Helpers.Common.GetSetting("bankcode");
            var bankname = Erp.BackOffice.Helpers.Common.GetSetting("bankname");
            var ImgLogo  = "<div class=\"logo\"><img src=" + logo + " height=\"73\" /></div>";
            List <HistoryCommissionStaffViewModel> q = HistoryCommissionStaffRepository.GetAllHistoryCommissionStaffFull()
                                                       .Select(item => new HistoryCommissionStaffViewModel
            {
                Id            = item.Id,
                CreatedUserId = item.CreatedUserId,
                //CreatedUserName = item.CreatedUserName,
                CreatedDate    = item.CreatedDate,
                ModifiedUserId = item.ModifiedUserId,
                //ModifiedUserName = item.ModifiedUserName,
                ModifiedDate      = item.ModifiedDate,
                Month             = item.Month,
                Year              = item.Year,
                AmountCommission  = item.AmountCommission,
                CommissionPercent = item.CommissionPercent,
                MinimumRevenue    = item.MinimumRevenue,
                PositionName      = item.PositionName,
                RevenueDS         = item.RevenueDS,
                StaffId           = item.StaffId,
                StaffName         = item.StaffName,
                IsDeleted         = item.IsDeleted
            }).OrderByDescending(m => m.ModifiedDate).ToList();

            if (month != null && month.Value > 0)
            {
                q = q.Where(x => x.Month == month).ToList();
            }
            else
            {
                q = q.Where(x => x.Month == DateTime.Now.Month).ToList();
            }
            if (year != null && year.Value > 0)
            {
                q = q.Where(x => x.Year == year).ToList();
            }
            else
            {
                q = q.Where(x => x.Year == DateTime.Now.Year).ToList();
            }
            if (!string.IsNullOrEmpty(Status))
            {
                if (Status == "unsuccess")
                {
                    q = q.Where(x => x.IsDeleted == null || x.IsDeleted == true).ToList();
                }
                if (Status == "success")
                {
                    q = q.Where(x => x.IsDeleted == false).ToList();
                }
            }
            if (Erp.BackOffice.Filters.SecurityFilter.IsTrinhDuocVien())
            {
                var staff = staffRepository.GetvwStaffsByUser(WebSecurity.CurrentUserId);
                if (staff != null)
                {
                    q = q.Where(x => x.StaffId == staff.Id).ToList();
                }
                else
                {
                    q = null;
                }
            }
            if (Erp.BackOffice.Filters.SecurityFilter.IsAdminSystemManager())
            {
                var staff      = staffRepository.GetvwStaffsByUser(WebSecurity.CurrentUserId);
                var item_staff = q.Where(x => x.StaffId == staff.Id).ToList();
                q = q.Where(x => x.StaffParentId != null && x.StaffParentId == staff.Id).ToList();
                q = q.Union(item_staff).OrderByDescending(x => x.ModifiedDate).ToList();
            }
            //lấy template phiếu xuất.
            var template = templatePrintRepository.GetAllTemplatePrint().Where(x => x.Code.Contains("PrintHistoryCommissionStaff")).OrderByDescending(x => x.CreatedDate).FirstOrDefault();

            //truyền dữ liệu vào template.
            model.Content = template.Content;

            model.Content = model.Content.Replace("{DataTable}", buildHtmlDetailList_PrintBCNXT(q));
            model.Content = model.Content.Replace("{System.Logo}", ImgLogo);
            model.Content = model.Content.Replace("{System.CompanyName}", company);
            model.Content = model.Content.Replace("{System.AddressCompany}", address);
            model.Content = model.Content.Replace("{System.PhoneCompany}", phone);
            model.Content = model.Content.Replace("{System.Fax}", fax);
            model.Content = model.Content.Replace("{System.BankCodeCompany}", bankcode);
            model.Content = model.Content.Replace("{System.BankNameCompany}", bankname);
            model.Content = model.Content.Replace("{PrintDate}", DateTime.Now.ToString("dd/MM/yyyy HH:mm"));
            model.Content = model.Content.Replace("{Title.month}", "Tháng " + month + " năm " + year);
            if (ExportExcel)
            {
                Response.AppendHeader("content-disposition", "attachment;filename=" + "BaoCaoHoaHongNhanVien" + DateTime.Now.ToString("yyyyMMdd") + ".xls");
                Response.Charset = "";
                Response.Cache.SetCacheability(HttpCacheability.NoCache);
                Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                Response.Write(model.Content);
                Response.End();
            }
            return(View(model));
        }