public ActionResult Filter(int id)
        {
            object viewModel = null;

            ViewBag.title = this._report[id];
            switch (id)
            {
                case 5:
                    ViewBag.type = new SortedList()
                    {
                        { 1,    "盈電工程有限公司" },
                        { 2,    "盈電機電工程有限公司" }
                    };
                    break;
                case 7:
                    ViewBag.type = new SortedList()
                    {
                        { 1,    "All Billed ACQ" },
                        { 2,    "Billed ACQ with Dummy Invoice Only" },
                        { 3,    "Billed ACQ with invoice Number" }
                    };
                    break;
                case 8:
                    ViewBag.dummy = new SortedList()
                    {
                        { 1,    "All" },
                        { 2,    "With Dummy Invoice" },
                        { 3,    "Without Dummy Invoice" }
                    };
                    break;
                case 9:
                    viewModel = new Report9Model()
                        {
                            types = new Report9ModelType[] { Report9ModelType.Maintenance, Report9ModelType.Quotation }
                        };
                    break;
                case 11:
                    ViewBag.region = this.getRegion();
                    viewModel = new Report11Model()
                    {
                        order_date = DateTime.Today.ToString("dd-MM-yyyy"),
                        //order_date_required = true
                    };
                    break;
                case 12:
                    ViewBag.engineer = this.getEngineer();
                    break;
                case 13:
                    ViewBag.type = new SortedList()
                    {
                        { 1,    "Invoice" },
                        { 2,    "Quotation" }
                    };
                    ViewBag.type2 = new SortedList()
                    {
                        { 1,    "for Maintenance Contract (ACM)" },
                        { 2,    "for Quotation (ACQ)" }
                    };
                    break;
                case 14:
                    ViewBag.type = new SortedList()
                    {
                        { 1,    "All" },
                        { 2,    "T&C Only" },
                        { 3,    "Not T&C Only" },
                        { 4,    "Without Service Date" }
                    };
                    break;
                case 15:
                    ViewBag.region = this.getRegion();
                    break;
                case 16:
                    //ViewBag.type = _bank;
                    break;
                case 17:
                    ViewBag.region = this.getRegion();
                    break;
                case 19:
                    Report19Model repot19model = new Report19Model();
                    repot19model.Modes = new Report19ModelMode[] { Report19ModelMode.By_Category, Report19ModelMode.By_Employee, Report19ModelMode.By_Sub__Contractor, Report19ModelMode.By_Supplier, Report19ModelMode.By_Minor_Work };
                    repot19model.CostCategories = this.getCosts();
                    repot19model.Suppliers = this.getSuppliers();
                    viewModel = repot19model;
                    break;
                case 20:
                    ViewBag.order_status = new SortedList()
                    {
                        { 1, "預約保養" },
                        { 2, "做保養" },
                        { 3, "完成保養" }
                    };
                    break;
                case 21:
                    //ViewBag.district = this.getDistrict();
                    var district = (from d in this._db.recsys_district
                            where d.status == 1 && (d.name == "帝琴灣" || d.name == "爵悅庭")
                            orderby d.region ascending
                            select d);
                    ViewBag.district = Common.array_conv(Common.query(district), "id", "name");
                    break;
                case 22:
                    Report22Model report22Model = new Report22Model();
                    report22Model.show_printed = false;
                    viewModel = report22Model;
                    break;
            }
            return View("Report" + id, viewModel);
        }
 public ActionResult Report11(Report11Model model)
 {
     //return Pdf("/reportsgen/report11/", this._report[11].ToString(), false);
     return new ReportsGenController().Report11(model);
 }
        public ActionResult Report11(Report11Model model)
        {
            string order_id = model.order_id;
            string order_date = model.order_date;
            string customer_code = model.customer_code;
            string customer_name = model.customer_name;
            ReportDailyECall.ReportModel reportModel = new ReportDailyECall.ReportModel();
            ArrayList where = new ArrayList();

            if (!String.IsNullOrWhiteSpace(order_id))
                where.Add("o.id = '" + order_id + "'");

            if (model.choose_region.Trim().Length > 0)
            {

                string[] chosenRegionList = model.choose_region.Split(',');

                string regionIDFilter = string.Empty;
                string regionNullFilter = " rg.id is null ";
                bool isRegionNullFilterChoose = false;
                foreach (var regionId in chosenRegionList)
                {
                    if (regionId.Equals("-1"))
                        isRegionNullFilterChoose = true;
                    else
                    {
                        regionIDFilter += regionId + ",";
                    }
                }

                if (isRegionNullFilterChoose)
                {
                    if (!string.IsNullOrEmpty(regionIDFilter))
                        where.Add("(rg.id in ( " + regionIDFilter.TrimEnd(',') + " ) or " + regionNullFilter + " )");
                    else
                        where.Add(regionNullFilter);
                }

                else
                {
                    where.Add("rg.id in ( " + regionIDFilter.TrimEnd(',') + " )");
                }
            }
            else
            {
                return Content("找不到任何紀錄。");
            }

            //if (model.order_date_required)
            //{
                if (!string.IsNullOrEmpty(model.order_date))
                {
                    where.Add(string.Format("o.repair_date >= '{0}' AND o.repair_date < DATEADD(day, 1, '{0}')", ConvertDateStringFormat(model.order_date, DATEPICKER_DATE_FORMAT, DB_DATE_FORMAT)));
                    ViewBag.date = Common.to_date("d/M/yyyy", DateTime.ParseExact(model.order_date, DATEPICKER_DATE_FORMAT, null));
                }
                else
                {
                    where.Add(string.Format("o.repair_date >= '{0}' AND o.repair_date < DATEADD(day, 1, '{0}')", DateTime.Today.ToString(DB_DATE_FORMAT)));
                    ViewBag.date = Common.to_date("d/M/yyyy", DateTime.Today);
                }
            //}
            //else
            //{
            //    where.Add(" o.repair_date is null ");
            //    ViewBag.date = "";
            //}

            if (model.MasterCustomerID.HasValue)
                where.Add("c.customer_id = " + model.MasterCustomerID.Value);

            string sql = @"
                select
                    o.id, o.repair_date, o.start_time, o.end_time, o.remark, o.fault,
                    pu.name as recipient, e1.name as technician1, e2.name as technician2, e3.name as technician3, e4.name as technician4, o.reviewer,
                    c.customer_code, c.name AS customer_name, c.address2, c.tel1,
                    c.type, c.code, c.manual_input_code, c.prefix,
                    c.contact, c.title, rg.name as region_name, rg.id as region_id,
                    c.customer_code as customer_code
                from recsys_order as o
                left outer join recsys_relate_customers as c on o.customer_id = c.id
                left outer join recsys_district as d on c.district2 = d.id
                left outer join recsys_region as rg on d.region = rg.id
                left outer join recsys_users as pu on o.call_pickup_user_id = pu.id
                left outer join recsys_users as e1 on o.engineer_id_1 = e1.id
                left outer join recsys_users as e2 on o.engineer_id_2 = e2.id
                left outer join recsys_users as e3 on o.engineer_id_3 = e3.id
                left outer join recsys_users as e4 on o.engineer_id_4 = e4.id
                where o.status = '1' AND o.order_status = '2'
                " + (where.Count > 0 ? " AND " + String.Join(" AND ", where.ToArray()) : String.Empty) + @"
                order by o.repair_date desc";
            reportModel.Records = Common.queryToObject<ReportDailyECall.RecordModel>(this._db.ExecuteStoreQuery<ReportDailyECall.RecordModel>(sql)).ToList();
            if (reportModel.Records.Count() > 0)
            {
                //ViewBag.date = Common.to_date("d/M/yyyy", DateTime.Now);
                return View("~/Views/ReportsGen/Report11.cshtml", reportModel);
            }
            else
            {
                return Content("找不到任何紀錄。");
            }
        }