Example #1
0
        public ActionResult UpdateCustomer()
        {
            try
            {
                int id = Convert.ToInt32(Request["Name"]);
                string status = Request["Status"];
                var cService = new CustomerService();
                var customer = cService.GetCustomerById(id);
                if (customer != null)
                {
                    if (status == Status.ACTIVE.ToString())
                    {
                        customer.Status = (int)Status.ACTIVE;
                        customer.ApprovedUserId = AccessFactory.CurrentUser.Id;
                        customer.LastModifiedBy = AccessFactory.CurrentUser.Id;
                        cService.UpdateCustomer(customer);
                    }
                    else if (status == Status.DELETE.ToString())
                    {
                        cService.DeleteCustomer(customer);
                    }
                }

                return Json(new { finish = true });
            }
            catch (Exception ex)
            {

                return Json(new { finish = false });
            }
        }
Example #2
0
        public ActionResult SearchExport()
        {
            try
            {
                var table = new StringBuilder();
                var datefrom = DateTime.ParseExact(Request["DateFrom"], "dd/MM/yyyy", null);
                var dateto = DateTime.ParseExact(Request["DateTo"], "dd/MM/yyyy", null);
                var eService = new ExportService();
                var oService = new OrderService();
                var tService = new StockService();
                var cService = new CustomerService();
                var exports = eService.GetExportByDate(datefrom, dateto);

                table.Append("<table id='table1' class='table1'>");
                table.Append("<thead>");
                table.Append("<tr>");
                table.Append("<th>Mã đơn hàng</th>");
                table.Append("<th>Khách hàng</th>");
                table.Append("<th>Tên kho</th>");
                table.Append("<th>Ngày xuất kho</th>");
                table.Append("</tr>");
                table.Append("</thead>");

                table.Append("<tbody>");
                foreach (var export in exports)
                {
                    var order = oService.GetOrderById(export.OrderId);
                    var customer = cService.GetCustomerById(order.CustomerId);
                    var stock = tService.GetStockById(export.StockId);
                    table.Append("<tr>");
                    table.AppendFormat("<td>{0}</td>", order.Code);
                    table.AppendFormat("<td>{0}</td>", customer.Name);
                    table.AppendFormat("<td>{0}</td>", stock.Name);
                    table.AppendFormat("<td>{0}</td>", export.CreatedDate.ToShortDateString());
                    table.Append("</tr>");
                }

                table.Append("</tbody>");
                table.Append("</table>");

                return Json(new
                {
                    finish = true,
                    data = table.ToString()
                });
            }
            catch (Exception e)
            {

                return Json(new { finish = false, data = e.ToString() });

            }
        }
Example #3
0
        public ActionResult Index(CustomerModel model)
        {
            var m = Init();
            var cService = new CustomerService();
            var customer = new Customer();
            model.cities = m.cities;
            model.customertypes = m.customertypes;
            model.Error = "";
            //valid exist data
            var valid = cService.GetAllCustomer()
               .Where(c => (!string.IsNullOrEmpty(model.Email) && c.Email == model.Email) ||
                           (!string.IsNullOrEmpty(model.Phone1) && c.PhoneNumber1 == model.Phone1) ||
                           (!string.IsNullOrEmpty(model.Phone2) && c.PhoneNumber1 == model.Phone2) ||
                           (!string.IsNullOrEmpty(model.Phone1) && c.PhoneNumber2 == model.Phone1) ||
                           (!string.IsNullOrEmpty(model.Phone2) && c.PhoneNumber2 == model.Phone2));

            if (!valid.Any())
            {
                //save data
                customer.Name = model.Name;
                customer.Code = Constant.CUSTOMER_CODE;
                customer.CustomerType = model.Type;
                customer.PhoneNumber1 = model.Phone1;
                customer.PhoneNumber2 = model.Phone2;
                customer.Email = model.Email;
                customer.FaxNumber = model.Fax;
                customer.Address = model.Address;
                customer.CityId = model.City;
                customer.Note = model.Note;
                customer.ReferUserId = AccessFactory.CurrentUser.Id;
                customer.ApprovedUserId = AccessFactory.CurrentUser.Id;
                customer.Status = (int)Status.REVIEW;
                customer.LastModifiedBy = AccessFactory.CurrentUser.Id;
                customer.LastModifiedDate = DateTime.Now;

                cService.InsertCustomer(customer);
                model.Save = true;
            }
            else
            {
                model.Error = "Khách hàng đã tồn tại";
                model.Save = false;
            }

            return View(model);
        }
Example #4
0
        private CustomerListModel initCustomerListModel(int selectedUser = Constant.ALL_VALUE, 
                                                        int seletedStatus = Constant.ALL_VALUE,
                                                        string searchKey = "")
        {
            var model = new CustomerListModel();
            var uService = new UserService();
            var cService = new CustomerService();

            var sellers = uService.GetAllUser().Where(c => c.ReferUserId == AccessFactory.CurrentUser.Id).ToList();
            sellers.Insert(0, new User() { Id = Constant.ALL_VALUE, Name = Constant.ALL });
            model.Sellers = sellers;

            var statuses = cService.GetAllCustomerStatus();
            statuses.Insert(0, new CustomerStatus() { Name = Constant.ALL, Type = Constant.ALL_VALUE });
            model.Status = statuses;

            var allcustomer = new List<Customer>();

            var sellersfilter = sellers;
            if (selectedUser != Constant.ALL_VALUE)
                sellersfilter = sellersfilter.Where(c => c.Id == selectedUser).ToList();

            searchKey = searchKey != null ? searchKey.Trim().ToLower() : "";

            foreach (var seller in sellersfilter)
            {
                allcustomer.AddRange(cService.GetAllCustomer().Where(c => c.ReferUserId == seller.Id).ToList());
            }

            if (seletedStatus != Constant.ALL_VALUE)
                allcustomer = allcustomer.Where(c => c.Status == seletedStatus).ToList();

            if (searchKey != "")
                //allcustomer = (from c in allcustomer
                //               where c.Name.ToLower().Contains(searchKey)
                //               select c).OrderBy(c => c.Name).ToList();
                allcustomer = allcustomer.Where(c => (c.Name != null && c.Name.ToLower().Contains(searchKey))
                    || (c.PhoneNumber1 != null && c.PhoneNumber1.ToLower().Contains(searchKey))
                    || (c.PhoneNumber2 != null && c.PhoneNumber2.ToLower().Contains(searchKey))
                    || (c.Email != null && c.Email.Contains(searchKey))
                                                     ).ToList();

            model.Customers = allcustomer;

            model.SelectedSeller = Constant.ALL_VALUE;
            model.SelectedCustomerStatus = Constant.ALL_VALUE;
            model.Search = "";

            return model;
        }
Example #5
0
        public ActionResult SearchPayment()
        {
            try
            {
                var table = new StringBuilder();
                var datefrom = DateTime.ParseExact(Request["DateFrom"], "dd/MM/yyyy", null);
                var dateto = DateTime.ParseExact(Request["DateTo"], "dd/MM/yyyy", null);
                var pService = new PaymentService();
                var oService = new OrderService();
                var cService = new CustomerService();
                var payments = pService.GetPaymentByDate(datefrom, dateto);
                double totalCash = 0, totalTransfer = 0;

                table.Append("<table id='table1' class='table1'>");
                table.Append("<thead>");
                table.Append("<tr>");
                table.Append("<th>Mã đơn hàng</th>");
                table.Append("<th>Khách hàng</th>");
                table.Append("<th>Hình thức thanh toán</th>");
                table.Append("<th>Tổng giá trị</th>");
                table.Append("</tr>");
                table.Append("</thead>");

                table.Append("<tbody>");
                foreach (var payment in payments)
                {
                    var total = oService.GetOrderDetailByOrderid(payment.OrderId).Sum(c => c.TotalQuantity);
                    var order = oService.GetOrderById(payment.OrderId);
                    var customer = cService.GetCustomerById(order.CustomerId);
                    if (order.IsSeen == false)
                        table.Append("<tr style='background:grey'>");
                    else
                        table.Append("<tr>");
                    table.AppendFormat("<td>{0}</td>", order.Code);
                    table.AppendFormat("<td>{0}</td>", customer.Name);
                    table.AppendFormat("<td>{0}</td>", payment.PaymentType.Name);
                    table.AppendFormat("<td>{0}</td>", Constant.ConvertCurrency(total));
                    table.Append("</tr>");

                    if (payment.PaymentType.Id == (int)PaymentType.CASH)
                        totalCash += total;
                    else
                        totalTransfer += total;
                }

                table.Append("</tbody>");
                table.Append("</table>");

                return Json(new
                {
                    finish = true,
                    data = table.ToString(),
                    totalCash = Constant.ConvertCurrency(totalCash),
                    totalTransfer = Constant.ConvertCurrency(totalTransfer)
                });
            }
            catch (Exception e)
            {

                return Json(new { finish = false, data = e.ToString() });

            }
        }
Example #6
0
        public ActionResult SearchOrder()
        {
            try
            {
                var table = new StringBuilder();
                var datefrom = DateTime.ParseExact(Request["DateFrom"], "dd/MM/yyyy", null);
                var dateto = DateTime.ParseExact(Request["DateTo"], "dd/MM/yyyy", null);
                var oService = new OrderService();
                var cService = new CustomerService();
                var orders = oService.GetOrderByDate(datefrom, dateto);
                var totalcount = orders.Count();
                var newcount = orders.Count(c => c.IsSeen == false);
                double totalsum = 0, newsum = 0;

                table.Append("<table id='table1' class='table1'>");
                table.Append("<thead>");
                table.Append("<tr>");
                table.Append("<th>Mã đơn hàng</th>");
                table.Append("<th>Giá đơn hàng</th>");
                table.Append("<th>Tỉnh/thành khách hàng</th>");
                table.Append("<th>Trạng thái đơn hàng</th>");
                table.Append("</tr>");
                table.Append("</thead>");

                table.Append("<tbody>");
                foreach (var order in orders)
                {
                    var total = oService.GetOrderDetailByOrderid(order.Id).Sum(c => c.TotalQuantity);
                    var customer = cService.GetCustomerById(order.CustomerId);
                    if (order.IsSeen == false)
                        table.Append("<tr style='background:grey'>");
                    else
                        table.Append("<tr>");
                    table.AppendFormat("<td>{0}</td>", order.Code);
                    table.AppendFormat("<td>{0}</td>", Constant.ConvertCurrency(total));
                    table.AppendFormat("<td>{0}</td>", customer.City.Name);
                    table.AppendFormat("<td>{0}</td>", AccessFactory.GetStatus(order.Status));
                    table.Append("</tr>");

                    totalsum += total;
                    if (order.IsSeen == false)
                        newsum += total;
                }

                table.Append("</tbody>");
                table.Append("</table>");
                oService.UpdateOrderInSeen(orders);

                return Json(new
                {
                    finish = true,
                    data = table.ToString(),
                    totalCount = totalcount,
                    totalSum = Constant.ConvertCurrency(totalsum),
                    newCount = newcount,
                    newSum = Constant.ConvertCurrency(newsum)
                });
            }
            catch (Exception e)
            {

                return Json(new { finish = false, data = e.ToString() });

            }
        }
Example #7
0
        public ActionResult SaveCustomer()
        {
            try
            {
                var Name = Request["Name"];
                var Phone1 = Request["Phone1"];
                var Phone2 = Request["Phone2"];
                var Email = Request["Email"];
                var Fax = Request["Fax"];
                var Address = Request["Address"];
                var Note = Request["Note"];
                var Type = Convert.ToInt32(Request["Type"]);
                var City = Convert.ToInt32(Request["City"]);

                var model = Init();
                var cService = new CustomerService();
                var customer = new Customer();
                model.Error = "";
                //valid exist data
                var valid = cService.GetAllCustomer()
                   .Where(c => (!string.IsNullOrEmpty(Email) && c.Email == Email) ||
                               (!string.IsNullOrEmpty(Phone1) && c.PhoneNumber1 == Phone1) ||
                               (!string.IsNullOrEmpty(Phone2) && c.PhoneNumber1 == Phone2) ||
                               (!string.IsNullOrEmpty(Phone1) && c.PhoneNumber2 == Phone1) ||
                               (!string.IsNullOrEmpty(Phone2) && c.PhoneNumber2 == Phone2));

                if (!valid.Any())
                {
                    //save data

                    customer.Name = Name;
                    customer.CustomerType = Type;
                    customer.PhoneNumber1 = Phone1;
                    customer.PhoneNumber2 = Phone2;
                    customer.Code = Constant.CUSTOMER_CODE;
                    customer.Email = Email;
                    customer.FaxNumber = Fax;
                    customer.Address = Address;
                    customer.CityId = City;
                    customer.Note = Note;
                    customer.ReferUserId = AccessFactory.CurrentUser.Id;
                    customer.ApprovedUserId = AccessFactory.CurrentUser.Id;
                    customer.Status = (int)Status.REVIEW;
                    customer.LastModifiedBy = AccessFactory.CurrentUser.Id;
                    customer.LastModifiedDate = DateTime.Now;

                    cService.InsertCustomer(customer);
                }
                else
                {
                    return Json(new { finish = false, data = "Khách hàng đã tồn tại" });
                }

            }
            catch (Exception e)
            {
                return Json(new { finish = false, data = e.ToString() });
            }
            return Json(new { finish = true, data = "Lưu thành công" });
        }
Example #8
0
        private CustomerModel Init()
        {
            var model = new CustomerModel();
            var ciService = new CityService();
            var cService = new CustomerService();

            model.cities = ciService.GetAllCity().ToList();
            model.customertypes = cService.GetAllCustomerType();
            model.Error = "";
            model.Save = false;
            return model;
        }