コード例 #1
0
        protected List <AgencyInfo> GetListC1(HaiStaff staff)
        {
            List <AgencyInfo> agencyResult = new List <AgencyInfo>();

            List <C1Info> c1List = new List <C1Info>();

            var roleCheck = CheckRoleShowInfo(staff.UserLogin);

            if (roleCheck == 1)
            {
                c1List = db.C1Info.Where(p => p.IsActive == 1).ToList();
            }
            else
            {
                c1List = db.C1Info.Where(p => p.IsActive == 1 && p.CInfoCommon.BranchCode == staff.HaiBranch.Code).ToList();
            }


            foreach (var item in c1List)
            {
                agencyResult.Add(new AgencyInfo()
                {
                    code   = item.Code,
                    name   = item.StoreName,
                    type   = "CI",
                    deputy = item.Deputy
                });
            }

            return(agencyResult);
        }
コード例 #2
0
        protected List <AgencyInfoC2Result> getListAgency(HaiStaff staff)
        {
            List <AgencyInfoC2Result> agencyResult = new List <AgencyInfoC2Result>();
            List <C2Info>             c2List       = new List <C2Info>();

            c2List = staff.C2Info.Where(p => p.IsActive == 1).ToList();
            foreach (var item in c2List)
            {
                agencyResult.Add(new AgencyInfoC2Result()
                {
                    code            = item.Code,
                    name            = item.StoreName,
                    type            = "CII",
                    deputy          = item.Deputy,
                    address         = item.CInfoCommon.AddressInfo,
                    lat             = item.CInfoCommon.Lat == null ? 0 : item.CInfoCommon.Lat,
                    lng             = item.CInfoCommon.Lng == null ? 0 : item.CInfoCommon.Lng,
                    phone           = item.CInfoCommon.Phone,
                    id              = item.Id,
                    identityCard    = item.CInfoCommon.IdentityCard,
                    businessLicense = item.CInfoCommon.BusinessLicense,
                    province        = item.CInfoCommon.ProvinceName,
                    district        = item.CInfoCommon.DistrictName,
                    taxCode         = item.CInfoCommon.TaxCode,
                    c1Id            = item.C1Info.Code
                });
            }

            return(agencyResult);
        }
コード例 #3
0
        public ActionResult ModifyStaff(HaiStaff staff, string birthday, HttpPostedFileBase avatar, HttpPostedFileBase signature)
        {
            if (!Utitl.CheckUser(db, User.Identity.Name, "ManageStaff", 1))
            {
                return(RedirectToAction("relogin", "home"));
            }
            var staffCheck = db.HaiStaffs.Find(staff.Id);

            if (staffCheck != null)
            {
                if (birthday != "" && birthday != null)
                {
                    DateTime dt = DateTime.ParseExact(birthday, "MM/dd/yyyy HH:mm", null);
                    staffCheck.BirthDay = dt;
                }

                staffCheck.FullName = staff.FullName;
                // staffCheck.Code = staff.Code;
                staffCheck.BranchId     = staff.BranchId;
                staffCheck.DepartmentId = staff.DepartmentId;
                staffCheck.PositionId   = staff.PositionId;
                staffCheck.Notes        = staff.Notes;
                staffCheck.Phone        = staff.Phone;
                staffCheck.Email        = staff.Email;

                staffCheck.PlaceOfBirth = staff.PlaceOfBirth;

                if (avatar != null)
                {
                    staffCheck.AvatarUrl = UploadImage(avatar, "/staff/avatar", ".jpg", staff.Code);
                }

                if (signature != null)
                {
                    staffCheck.SignatureUrl = UploadImage(signature, "/staff/signature", ".png", staff.Code);
                }


                db.Entry(staffCheck).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
                ViewBag.TabActive = "1";

                return(RedirectToAction("modifystaff", "haistaff", new { Id = staffCheck.Id }));
            }
            else
            {
                return(RedirectToAction("error", "home"));
            }
        }
コード例 #4
0
        private void DeleteAgencyC1(HaiStaff staff, string AgencyId, HttpPostedFileBase files)
        {
            if (files != null && files.ContentLength > 0)
            {
                string extension = System.IO.Path.GetExtension(files.FileName);
                if (extension.Equals(".xlsx"))
                {
                    string fileSave = "staffci_" + DateTime.Now.ToString("ddMMyyyyhhmmss") + extension;
                    string path     = Server.MapPath("~/temp/" + fileSave);
                    if (System.IO.File.Exists(path))
                    {
                        System.IO.File.Delete(path);
                    }

                    files.SaveAs(path);
                    FileInfo       newFile = new FileInfo(path);
                    var            package = new ExcelPackage(newFile);
                    ExcelWorksheet sheet   = package.Workbook.Worksheets[1];

                    int totalRows = sheet.Dimension.End.Row;
                    int totalCols = sheet.Dimension.End.Column;

                    for (int i = 2; i <= totalRows; i++)
                    {
                        string code    = Convert.ToString(sheet.Cells[i, 1].Value);
                        var    checkC2 = staff.C1Info.Where(p => p.Code == code).FirstOrDefault();
                        if (checkC2 != null)
                        {
                            staff.C1Info.Remove(checkC2);
                            db.SaveChanges();
                        }
                    }
                }
            }
            else
            {
                var checkC1 = staff.C1Info.Where(p => p.Code == AgencyId).FirstOrDefault();

                if (checkC1 != null)
                {
                    staff.C1Info.Remove(checkC1);
                    db.SaveChanges();
                }
            }

            // db.Entry(staff).State = System.Data.Entity.EntityState.Modified;
            //  db.SaveChanges();
        }
コード例 #5
0
        protected List <AgencyInfo> GetStaffC1(HaiStaff staff)
        {
            List <AgencyInfo> agencyResult = new List <AgencyInfo>();

            List <C1Info> c1List = new List <C1Info>();

            int permit = HaiUtil.CheckRoleShowInfo(db, User.Identity.Name);

            if (permit == 2)
            {
                // get list cn
                var branchPermit = db.UserBranchPermisses.Where(p => p.UserName == User.Identity.Name).Select(p => p.BranchCode).ToList();
                c1List = db.C1Info.Where(p => branchPermit.Contains(p.CInfoCommon.BranchCode)).ToList();
            }
            else
            {
                c1List = staff.C1Info.Where(p => p.IsActive == 1).OrderBy(p => p.CInfoCommon.BranchCode).ToList();
            }

            foreach (var item in c1List)
            {
                agencyResult.Add(new AgencyInfo()
                {
                    code            = item.Code,
                    name            = item.StoreName,
                    type            = "CI",
                    deputy          = item.Deputy,
                    address         = item.CInfoCommon.AddressInfo,
                    lat             = item.CInfoCommon.Lat == null ? 0 : item.CInfoCommon.Lat,
                    lng             = item.CInfoCommon.Lng == null ? 0 : item.CInfoCommon.Lng,
                    phone           = item.CInfoCommon.Phone,
                    id              = item.CInfoCommon.Id,
                    rank            = item.CInfoCommon.CRank,
                    group           = "CI",
                    identityCard    = item.CInfoCommon.IdentityCard,
                    businessLicense = item.CInfoCommon.BusinessLicense,
                    province        = item.CInfoCommon.ProvinceName,
                    district        = item.CInfoCommon.DistrictName,
                    taxCode         = item.CInfoCommon.TaxCode,
                    haibranch       = item.CInfoCommon.BranchCode,
                    subOwner        = new List <SubOwner>()
                });
            }

            return(agencyResult);
        }
コード例 #6
0
        protected List <AgencyInfo> getListAgencyC1(HaiStaff staff)
        {
            List <AgencyInfo> agencyResult = new List <AgencyInfo>();

            List <C1Info> c1List = new List <C1Info>();

            c1List = db.C1Info.Where(p => p.IsActive == 1 && p.HaiBrandId == staff.BranchId).ToList();
            foreach (var item in c1List)
            {
                agencyResult.Add(new AgencyInfo()
                {
                    code   = item.Code,
                    name   = item.StoreName,
                    type   = "CI",
                    deputy = item.Deputy
                });
            }

            return(agencyResult);
        }
コード例 #7
0
        public ActionResult CreateStaff(HaiStaff staff, string birthday, HttpPostedFileBase avatar, HttpPostedFileBase signature)
        {
            if (!Utitl.CheckUser(db, User.Identity.Name, "ManageStaff", 1))
            {
                return(RedirectToAction("relogin", "home"));
            }

            staff.CreateDate = DateTime.Now;
            staff.IsLock     = 0;

            try
            {
                DateTime dt           = DateTime.ParseExact(birthday, "MM/dd/yyyy HH:mm", null);
                string   urlAvatar    = UploadImage(avatar, "/staff/avatar", ".jpg", staff.Code);
                string   urlSignature = UploadImage(signature, "/staff/signature", ".png", staff.Code);

                staff.AvatarUrl    = urlAvatar;
                staff.SignatureUrl = urlSignature;
                staff.Id           = Guid.NewGuid().ToString();
                staff.IsLock       = 0;
                staff.Code         = generalCode();

                db.HaiStaffs.Add(staff);
                db.SaveChanges();

                var findStoreId = db.StoreStaffIds.Find(staff.Code);
                findStoreId.IsUser          = 1;
                db.Entry(findStoreId).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
            }
            catch
            {
            }

            return(RedirectToAction("modifystaff", "haistaff", new { id = staff.Id }));
        }
コード例 #8
0
        public ResultInfo StaffComplete()
        {
            var log = new MongoHistoryAPI()
            {
                APIUrl     = "/api/order/staffcomplete",
                CreateTime = DateTime.Now,
                Sucess     = 1
            };

            var result = new ResultInfo()
            {
                id  = "1",
                msg = "success"
            };

            try
            {
                var requestContent = Request.Content.ReadAsStringAsync().Result;
                var jsonserializer = new JavaScriptSerializer();
                var paser          = jsonserializer.Deserialize <OrderInfoRequest>(requestContent);
                log.Content = new JavaScriptSerializer().Serialize(paser);

                if (!mongoHelper.checkLoginSession(paser.user, paser.token))
                {
                    throw new Exception("Wrong token and user login!");
                }

                DateTime dateSuggest = DateTime.ParseExact(paser.timeSuggest, "d/M/yyyy", null);

                CInfoCommon cinfo = db.CInfoCommons.Where(p => p.CCode == paser.code).FirstOrDefault();

                HaiStaff staff = db.HaiStaffs.Where(p => p.UserLogin == paser.user).FirstOrDefault();
                if (staff == null)
                {
                    throw new Exception("Sai thong tin nguoi dat");
                }


                string orderType = "order";
                if (paser.inCheckIn == 1)
                {
                    orderType = "checkinorder";
                }
                else if (paser.inCheckIn == 0)
                {
                    orderType = "order";
                }

                if (String.IsNullOrEmpty(orderType))
                {
                    throw new Exception("Sai thong tin dat hang");
                }

                //
                if (paser.product == null || paser.product.Count() == 0)
                {
                    throw new Exception("Thieu thong tin san pham");
                }

                if (cinfo == null)
                {
                    throw new Exception("Sai thong tin khach hang");
                }

                // create code
                int?   number = GetOrderNumber(cinfo.BranchCode);
                string code   = cinfo.BranchCode + (100000 + number);


                // tạo đơn hàng
                var order = new HaiOrder()
                {
                    Id             = Guid.NewGuid().ToString(),
                    OrderType      = orderType,
                    ShipType       = paser.shipType,
                    PayType        = paser.payType,
                    Agency         = cinfo.Id,
                    CreateDate     = DateTime.Now,
                    OrderStatus    = "process",
                    ReceiveAddress = paser.address,
                    Notes          = paser.notes,
                    ExpectDate     = dateSuggest,
                    BrachCode      = cinfo.BranchCode,
                    Code           = code,
                    OrderNumber    = number,
                    ReceivePhone1  = paser.phone,
                    UserCreate     = paser.user,
                    DateCode       = DateTime.Now.Date.ToString("ddMMyyyy"),
                    DebtTimeLine   = paser.debtTime,
                    DStatus        = "incomplete",
                    C1Code         = "",
                    C1Id           = "",
                    C1Name         = ""
                };

                if (paser.c1 == "000")
                {
                    order.SalePlace = "B";
                }
                else
                {
                    order.SalePlace = "CI";

                    var checkC1 = db.C1Info.Where(p => p.Code == paser.c1).FirstOrDefault();

                    if (checkC1 == null)
                    {
                        throw new Exception("Sai thông tin nơi lấy hàng");
                    }

                    order.C1Code = checkC1.Code;
                    order.C1Id   = checkC1.Id;
                    order.C1Name = checkC1.StoreName;
                }

                db.HaiOrders.Add(order);
                db.SaveChanges();

                // danh sach san pham mua
                double?priceTotal = 0;
                foreach (var item in paser.product)
                {
                    // kiem tra san pham
                    var checkProduct = db.ProductInfoes.Find(item.code);
                    if (checkProduct != null && item.quantity > 0)
                    {
                        double?perPrice     = checkProduct.Price != null ? checkProduct.Price : 0;
                        double?price        = perPrice * item.quantity;
                        var    productOrder = new OrderProduct()
                        {
                            OrderId        = order.Id,
                            ModifyDate     = DateTime.Now,
                            PerPrice       = checkProduct.Price,
                            Quantity       = item.quantity,
                            ProductId      = checkProduct.Id,
                            PriceTotal     = price,
                            QuantityFinish = 0,
                            HasBill        = item.hasBill
                        };
                        db.OrderProducts.Add(productOrder);
                        db.SaveChanges();
                        priceTotal += price;
                    }
                }

                if (priceTotal == 0)
                {
                    db.HaiOrders.Remove(order);
                    db.SaveChanges();
                    throw new Exception("Sai thong tin san pham (ma san pham) hoac so luong");
                }
                else
                {
                    order.PriceTotal      = priceTotal;
                    db.Entry(order).State = EntityState.Modified;
                    db.SaveChanges();
                }


                // update process: nhan vien khoi tao
                OrderStaff orderStaff = new OrderStaff()
                {
                    Id         = Guid.NewGuid().ToString(),
                    CreateTime = DateTime.Now,
                    OrderId    = order.Id,
                    Notes      = "Khoi tao",
                    ProcessId  = "create",
                    StaffId    = staff.Id
                };

                db.OrderStaffs.Add(orderStaff);
                db.SaveChanges();

                // gui thong bao
                // nhan vien
                HaiUtil.SendNotifi("Đơn hàng " + order.Code, "Bạn vừa tạo đơn hàng cho " + cinfo.CName, staff.UserLogin, db, mongoHelper);

                // c2
                // HaiUtil.SendNotifi("Đơn hàng " + order.Code, "Bạn có 1 đơn hàng được tạo bởi nhân viên Công ty H.A.I " + staff.FullName + "(" + staff.Code + ")", cinfo.UserLogin, db, mongoHelper);
            }
            catch (Exception e)
            {
                result.id  = "0";
                result.msg = e.Message;
                log.Sucess = 0;
            }

            log.ReturnInfo = new JavaScriptSerializer().Serialize(result);

            mongoHelper.createHistoryAPI(log);

            return(result);
        }
コード例 #9
0
        public ActionResult Decor(HttpPostedFileBase image, string extension, string user, string token, string checkInId, string group)
        {
            if (mongoHelp.checkLoginSession(user, token))
            {
                HaiStaff staff = db.HaiStaffs.Where(p => p.UserLogin == user).FirstOrDefault();
                if (staff == null)
                {
                    return(Json(new { id = "0", msg = "Sai thong tin" }, JsonRequestBehavior.AllowGet));
                }

                var cWork = db.CalendarWorks.Find(checkInId);

                if (cWork == null)
                {
                    return(Json(new { id = "0", msg = "Sai thong tin" }, JsonRequestBehavior.AllowGet));
                }


                string dfolder = user + "/" + group + "/" + DateTime.Now.Date.ToString("dd-MM-yyyy");

                string fsave = "~/uploadfolder/" + dfolder;

                bool exists = System.IO.Directory.Exists(Server.MapPath(fsave));

                if (!exists)
                {
                    System.IO.Directory.CreateDirectory(Server.MapPath(fsave));
                }


                string urlThumbnail = "";
                try
                {
                    MemoryStream target = new MemoryStream();
                    image.InputStream.CopyTo(target);
                    byte[] data = target.ToArray();

                    ImageUpload imageUpload = new ImageUpload
                    {
                        Width      = 3000,
                        isSacle    = false,
                        UploadPath = fsave,
                        user       = cWork.AgencyCode
                    };

                    ImageResult imageResult = imageUpload.RenameUploadFile(data, extension);

                    if (imageResult.Success)
                    {
                        urlThumbnail = "/uploadfolder/" + dfolder + "/" + imageResult.ImageName;
                    }


                    // save inffo
                    var decor = new DecorImage()
                    {
                        Id             = Guid.NewGuid().ToString(),
                        CreateTime     = DateTime.Now.TimeOfDay,
                        DecorGroup     = group,
                        ImageUrl       = urlThumbnail,
                        CalendarWorkID = checkInId
                    };

                    db.DecorImages.Add(decor);
                    db.SaveChanges();
                }
                catch
                {
                    return(Json(new { id = "0", msg = "Image upload to fail" }, JsonRequestBehavior.AllowGet));
                }

                return(Json(new { id = "1", msg = urlThumbnail }, JsonRequestBehavior.AllowGet));
            }

            return(Json(new { id = "0", msg = "Faile token user" }, JsonRequestBehavior.AllowGet));
        }
コード例 #10
0
        protected List <AgencyInfo> GetStaffC2(HaiStaff staff)
        {
            List <AgencyInfo> agencyResult = new List <AgencyInfo>();

            List <C2Info> c2List = new List <C2Info>();

            int permit = HaiUtil.CheckRoleShowInfo(db, User.Identity.Name);

            if (permit == 2)
            {
                // get list cn
                var branchPermit = db.UserBranchPermisses.Where(p => p.UserName == User.Identity.Name).Select(p => p.BranchCode).ToList();
                c2List = db.C2Info.Where(p => branchPermit.Contains(p.CInfoCommon.BranchCode) && p.OldData == 0).ToList();
            }
            else
            {
                c2List = staff.StaffWithC2.Where(p => p.C2Info.IsActive == 1).OrderByDescending(p => p.GroupChoose).Select(p => p.C2Info).ToList();
            }

            foreach (var item in c2List)
            {
                var staffC2 = staff.StaffWithC2.Where(p => p.C2Id == item.Id).FirstOrDefault();
                int?group   = 0;
                if (staffC2 != null)
                {
                    group = staffC2.GroupChoose;
                }

                // danh sach c1
                var             c2c1       = db.C2C1.Where(p => p.C2Code == item.Code).ToList();
                List <SubOwner> agencyC2C1 = new List <SubOwner>();

                foreach (var item2 in c2c1)
                {
                    var checkC1 = db.C1Info.Where(p => p.Code == item2.C1Code).FirstOrDefault();
                    if (checkC1 != null)
                    {
                        agencyC2C1.Add(new SubOwner()
                        {
                            code     = checkC1.Code,
                            name     = checkC1.Deputy,
                            store    = checkC1.StoreName,
                            priority = item2.Priority
                        });
                    }
                }

                agencyResult.Add(new AgencyInfo()
                {
                    code            = item.Code,
                    name            = item.StoreName,
                    type            = "CII",
                    smsCode         = item.SMSCode,
                    deputy          = item.Deputy,
                    address         = item.CInfoCommon.AddressInfo,
                    lat             = item.CInfoCommon.Lat == null ? 0 : item.CInfoCommon.Lat,
                    lng             = item.CInfoCommon.Lng == null ? 0 : item.CInfoCommon.Lng,
                    phone           = item.CInfoCommon.Phone,
                    id              = item.CInfoCommon.Id,
                    rank            = item.CInfoCommon.CRank,
                    group           = Convert.ToString(group),
                    identityCard    = item.CInfoCommon.IdentityCard,
                    businessLicense = item.CInfoCommon.BusinessLicense,
                    province        = item.CInfoCommon.ProvinceName,
                    district        = item.CInfoCommon.DistrictName,
                    taxCode         = item.CInfoCommon.TaxCode,
                    haibranch       = item.CInfoCommon.BranchCode,
                    subOwner        = agencyC2C1
                });
            }

            return(agencyResult);
        }
コード例 #11
0
        public UpdateDeliveryResult UpdateDelivery(string productId, string orderId, int quantity, string user, string token)
        {
            var log = new MongoHistoryAPI()
            {
                APIUrl     = "/api/manageorder/updatedelivery",
                CreateTime = DateTime.Now,
                Sucess     = 1
            };

            var result = new UpdateDeliveryResult()
            {
                id  = "1",
                msg = "success"
            };

            try
            {
                if (!mongoHelper.checkLoginSession(user, token))
                {
                    throw new Exception("Wrong token and user login!");
                }

                HaiStaff staff = db.HaiStaffs.Where(p => p.UserLogin == user).FirstOrDefault();
                if (staff == null)
                {
                    throw new Exception("Sai thong tin nguoi dat");
                }


                var checkOrderProduct = db.OrderProducts.Where(p => p.OrderId == orderId && p.ProductId == productId).FirstOrDefault();

                if (checkOrderProduct == null)
                {
                    throw new Exception("Sai thong tin");
                }


                checkOrderProduct.QuantityFinish = quantity;

                checkOrderProduct.ModifyDate = DateTime.Now;

                db.Entry(checkOrderProduct).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();


                //
                var    order       = checkOrderProduct.HaiOrder;
                string deliveryStt = GetDeliveryStatus(order);
                var    status      = db.DeliveryStatus.Find(deliveryStt);
                order.DStatus = deliveryStt;

                result.deliveryStatus     = status.Name;
                result.deliveryStatusCode = status.Id;
                result.finish             = quantity;

                db.Entry(order).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();


                //
                // update process: nhan vien khoi tao
                var history = new OrderProductHistory()
                {
                    Id         = Guid.NewGuid().ToString(),
                    CreateDate = DateTime.Now,
                    Notes      = "Nhan vien cong ty cap nhat",
                    OrderId    = checkOrderProduct.OrderId,
                    ProductId  = checkOrderProduct.ProductId,
                    Quantity   = quantity,
                    StaffId    = staff.Id
                };

                db.OrderProductHistories.Add(history);
                db.SaveChanges();

                HaiUtil.SendNotifi("Đơn hàng " + order.Code, "Đã cập nhật số lượng giao " + HaiUtil.ConvertProductQuantityText(checkOrderProduct.ProductInfo.Quantity, quantity, checkOrderProduct.ProductInfo.Unit) +
                                   "\nCho sản phẩm " + checkOrderProduct.ProductInfo.PName, staff.UserLogin, db, mongoHelper);
            }
            catch (Exception e)
            {
                result.id  = "0";
                result.msg = e.Message;
                log.Sucess = 0;
            }

            log.ReturnInfo = new JavaScriptSerializer().Serialize(result);

            mongoHelper.createHistoryAPI(log);

            return(result);
        }
コード例 #12
0
        public ActionResult ExcelPlanReport(int month, int year, string staffId)
        {
            if (!Utitl.CheckUser(db, User.Identity.Name, "CheckIn", 0))
            {
                return(RedirectToAction("relogin", "home"));
            }
            int days = DateTime.DaysInMonth(year, month);

            HaiStaff staff = db.HaiStaffs.Find(staffId);

            if (staff == null)
            {
                return(RedirectToAction("error", "home"));
            }

            string name   = "report" + DateTime.Now.ToString("ddMMyyyyHHmmss") + ".xlsx";
            string pathTo = Server.MapPath("~/temp/" + name);



            try
            {
                FileInfo newFile = new FileInfo(pathTo);
                if (newFile.Exists)
                {
                    newFile.Delete(); // ensures we create a new workbook
                    newFile = new FileInfo(pathTo);
                }
                var maxday = new SqlParameter("@maxday", SqlDbType.Int);

                maxday.Value = days;
                var monthParams = new SqlParameter("@month", SqlDbType.VarChar);
                monthParams.Value = month;
                var yearParams  = new SqlParameter("@year", year);
                var staffParams = new SqlParameter("@staffId", staffId);
                var data        = db.Database.SqlQuery <checkin_report_plan_result>("checkin_report_plan @maxday,@month,@year,@staffId", maxday, monthParams, yearParams, staffParams).ToList();
                var sumary      = db.checkin_calendartype_group(month, year, staffId).ToList();
                using (ExcelPackage package = new ExcelPackage(newFile))
                {
                    ExcelWorksheet worksheet = package.Workbook.Worksheets.Add(staff.FullName);

                    worksheet.Cells[1, 2].Value           = "KẾ HOẠCH CHĂM SÓC KHÁCH HÀNG";
                    worksheet.Cells[1, 2].Style.Font.Bold = true;
                    worksheet.Cells[3, 2].Value           = "Chi nhánh: " + staff.HaiBranch.Code;
                    worksheet.Cells[4, 2].Value           = "Tên NV: " + staff.FullName;
                    worksheet.Cells[5, 2].Value           = "Mã Nv: " + staff.Code;
                    worksheet.Cells[6, 2].Value           = "Khu vực: " + staff.HaiBranch.HaiArea.Name;


                    for (var i = 0; i < sumary.Count(); i++)
                    {
                        worksheet.Cells[i + 1, 9].Value = sumary[i].Name + ": " + sumary[i].countday;
                    }


                    var tableIndex = 6;
                    if (tableIndex < sumary.Count)
                    {
                        tableIndex = sumary.Count;
                    }

                    tableIndex += 2;

                    //
                    worksheet.Cells[tableIndex, 1].Value            = "STT";
                    worksheet.Cells[tableIndex, 1].Style.Font.Bold  = true;
                    worksheet.Cells[tableIndex, 2].Value            = "CỤM";
                    worksheet.Cells[tableIndex, 2].Style.Font.Bold  = true;
                    worksheet.Cells[tableIndex, 3].Value            = "MÃ KH";
                    worksheet.Cells[tableIndex, 3].Style.Font.Bold  = true;
                    worksheet.Cells[tableIndex, 4].Value            = "TÊN KH";
                    worksheet.Cells[tableIndex, 4].Style.Font.Bold  = true;
                    worksheet.Cells[tableIndex, 5].Value            = "TÊN CỬA HÀNG";
                    worksheet.Cells[tableIndex, 5].Style.Font.Bold  = true;
                    worksheet.Cells[tableIndex, 6].Value            = "CN";
                    worksheet.Cells[tableIndex, 6].Style.Font.Bold  = true;
                    worksheet.Cells[tableIndex, 7].Value            = "ĐỊA CHỈ";
                    worksheet.Cells[tableIndex, 7].Style.Font.Bold  = true;
                    worksheet.Cells[tableIndex, 8].Value            = "HUYỆN";
                    worksheet.Cells[tableIndex, 8].Style.Font.Bold  = true;
                    worksheet.Cells[tableIndex, 9].Value            = "TỈNH";
                    worksheet.Cells[tableIndex, 9].Style.Font.Bold  = true;
                    worksheet.Cells[tableIndex, 10].Value           = "CẤP 1";
                    worksheet.Cells[tableIndex, 10].Style.Font.Bold = true;
                    worksheet.Cells[tableIndex, 11].Value           = "MIÊU TẢ";
                    worksheet.Cells[tableIndex, 11].Style.Font.Bold = true;

                    for (int i = 0; i < days; i++)
                    {
                        worksheet.Cells[tableIndex, i + 12].Value           = i + 1;
                        worksheet.Cells[tableIndex, i + 12].Style.Font.Bold = true;
                    }

                    // general data
                    tableIndex++;
                    var agency      = "";
                    var agencyCount = 1;
                    for (int i = 0; i < data.Count(); i++)
                    {
                        if (agency != data[i].AgencyCode)
                        {
                            agency = data[i].AgencyCode;

                            var c2 = db.C2Info.Where(p => p.Code == agency).FirstOrDefault();

                            if (c2 != null)
                            {
                                worksheet.Cells[tableIndex, 1].Value = agencyCount;
                                agencyCount++;
                                worksheet.Cells[tableIndex, 2].Value = "";
                                worksheet.Cells[tableIndex, 3].Value = agency;
                                worksheet.Cells[tableIndex, 4].Value = c2.Deputy;
                                worksheet.Cells[tableIndex, 5].Value = c2.StoreName;
                                worksheet.Cells[tableIndex, 6].Value = c2.CInfoCommon.BranchCode;
                                worksheet.Cells[tableIndex, 7].Value = c2.CInfoCommon.AddressInfo;
                                worksheet.Cells[tableIndex, 8].Value = c2.CInfoCommon.DistrictName;
                                worksheet.Cells[tableIndex, 9].Value = c2.CInfoCommon.ProvinceName;
                            }
                        }
                        worksheet.Cells[tableIndex, 11].Value = data[i].CType;

                        for (int j = 0; j < days; j++)
                        {
                            worksheet.Cells[tableIndex, j + 12].Value = data[i].getValue(j + 1);
                        }


                        tableIndex++;
                    }

                    package.Save();
                }
            }
            catch
            {
                return(RedirectToAction("error", "home"));
            }


            return(File(pathTo, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", string.Format("report-ke-hoach-" + DateTime.Now.ToString("ddMMyyyyhhmmss") + ".{0}", "xlsx")));
        }