public JsonResult JsonAdjustDocReturnTable(string DepartmentId, string SectionId, string YearId, string MonthId, string MatNameId)
        {
            ViewBag.DepartmentId = DepartmentId;
            ViewBag.SectionId    = SectionId;
            ViewBag.MatNameId    = MatNameId;
            ViewBag.YearId       = YearId;
            ViewBag.MonthId      = MonthId;

            // add IEnumerable<AdjustAcceptedViewModels>
            List <AdjustDocReturnedViewModels> viewModel = new List <AdjustDocReturnedViewModels>();

            //filter department
            var q = from d in objBs.docReturnDelayBs.GetByFilter(DepartmentId, SectionId, Convert.ToInt32(MonthId), Convert.ToInt32(YearId))
                    select d;

            //filter matname
            if (!String.IsNullOrEmpty(MatNameId))
            {
                q = q.Where(x => x.MATFRIGRP == MatNameId);
            }

            int c = q.Count();

            foreach (var item in q)
            {
                AdjustDocReturnedViewModels model = new AdjustDocReturnedViewModels();
                model.Shipment        = item.SHPMNTNO;
                model.DeliveryNote    = item.DELVNO;
                model.CarrierId       = item.CARRIER_ID;
                model.RegionId        = item.REGION_ID;
                model.RegionName      = item.REGION_NAME_TH;
                model.Soldto          = item.SOLDTO;
                model.SoldtoName      = item.SOLDTO_NAME;
                model.Shipto          = item.SHIPTO;
                model.ShiptoName      = item.TO_SHPG_LOC_NAME;
                model.ShippingPoint   = item.SHPPOINT;
                model.TruckType       = item.TRUCK_TYPE;
                model.PlanDocReturn   = item.PLNDOCRETDATE_SCGL.Value.ToString("dd/MM/yyyy HH:mm", new CultureInfo("th-TH"));
                model.ActualDocReturn = item.DOCRETDATE_SCGL.Value.ToString("dd/MM/yyyy HH:mm", new CultureInfo("th-TH"));
                model.ActualGI        = item.ACTGIDATE.Value.ToString("dd/MM/yyyy HH:mm", new CultureInfo("th-TH"));
                viewModel.Add(model);
            }

            var ddlReason = (from r in objBs.reasonDocReturnBs.GetAll()
                             select new
            {
                Id = r.Id,
                Name = r.Name
            }).Distinct().OrderBy(x => x.Name);

            ViewBag.ReasonId = new SelectList(ddlReason.ToList(), "Id", "Name");

            var jsonResult = Json(viewModel, JsonRequestBehavior.AllowGet);

            jsonResult.MaxJsonLength = int.MaxValue;
            return(jsonResult);
        }
        public ActionResult ExportExcel(string DepartmentId, string SectionId, string YearId, string MonthId, string MatNameId)
        {
            try
            {
                DataTable templateData = new DataTable();
                // add IEnumerable<AdjustAcceptedViewModels>
                List <AdjustDocReturnedViewModels> viewModel = new List <AdjustDocReturnedViewModels>();

                //filter department
                var q = from d in objBs.docReturnDelayBs.GetByFilter(DepartmentId, SectionId, Convert.ToInt32(MonthId), Convert.ToInt32(YearId))
                        select d;

                //filter matname
                if (!String.IsNullOrEmpty(MatNameId))
                {
                    q = q.Where(x => x.MATFRIGRP == MatNameId);
                }

                int c = q.Count();

                //int c = q.Count();

                foreach (var item in q)
                {
                    AdjustDocReturnedViewModels model = new AdjustDocReturnedViewModels();
                    model.Shipment        = item.SHPMNTNO;
                    model.DeliveryNote    = item.DELVNO;
                    model.CarrierId       = item.CARRIER_ID;
                    model.RegionId        = item.REGION_ID;
                    model.RegionName      = item.REGION_NAME_TH;
                    model.Soldto          = item.SOLDTO;
                    model.SoldtoName      = item.SOLDTO_NAME;
                    model.Shipto          = item.SHIPTO;
                    model.ShiptoName      = item.TO_SHPG_LOC_NAME;
                    model.ShippingPoint   = item.SHPPOINT;
                    model.TruckType       = item.TRUCK_TYPE;
                    model.PlanDocReturn   = item.PLNDOCRETDATE_SCGL.Value.ToString("dd/MM/yyyy HH:mm", new CultureInfo("th-TH"));
                    model.ActualDocReturn = item.DOCRETDATE_SCGL.Value.ToString("dd/MM/yyyy HH:mm", new CultureInfo("th-TH"));
                    model.ActualGI        = item.ACTGIDATE.Value.ToString("dd/MM/yyyy HH:mm", new CultureInfo("th-TH"));
                    viewModel.Add(model);
                }
                templateData.Merge(ExcelModels.ToDataTable(viewModel));
                templateData.Columns.Add("Remark", typeof(string));

                ExcelModels ex = new ExcelModels();
                ex.DumpExcel(templateData, "ExportedAdjustDocReturn_" + DateTime.Now.ToString("yyyyMMddHHmm", new CultureInfo("th-TH")));//dump

                return(View());
            }
            catch (Exception e)
            {
                TempData["Msg"] = "Error" + e.ToString();
                return(View());
            }
        }