Пример #1
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);
        }
Пример #2
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);
        }
Пример #3
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);
        }
Пример #4
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);
        }
Пример #5
0
        public ResultInfo UpdateOrderProduct()
        {
            var log = new MongoHistoryAPI()
            {
                APIUrl     = "/api/c1order/updateorderproduct",
                CreateTime = DateTime.Now,
                Sucess     = 1
            };

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

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

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

                var c1Info = db.C1Info.Where(p => p.CInfoCommon.UserLogin == paser.user).FirstOrDefault();

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

                var orderProduct = db.OrderProducts.Where(p => p.ProductId == paser.productId && p.OrderId == paser.orderId).FirstOrDefault();
                if (orderProduct == null)
                {
                    throw new Exception("Sai thong tin");
                }

                if (orderProduct.HaiOrder.OrderStatus != "process")
                {
                    throw new Exception("Đơn hàng không thể cập nhật");
                }

                // check quantity
                int?quantityRemain = orderProduct.Quantity - orderProduct.QuantityFinish;

                if (quantityRemain < paser.quantity)
                {
                    throw new Exception("Số lượng giao vượt quá");
                }

                orderProduct.QuantityFinish = orderProduct.QuantityFinish + paser.quantity;

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

                // save history

                var history = new OrderProductHistory()
                {
                    Id         = Guid.NewGuid().ToString(),
                    CreateDate = DateTime.Now,
                    Notes      = "Đại lý " + c1Info.StoreName + "(" + c1Info.Code + ") đã cập nhật",
                    OrderId    = orderProduct.OrderId,
                    ProductId  = orderProduct.ProductId,
                    Quantity   = paser.quantity
                };

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

                // gui thong bao
                var order = db.HaiOrders.Find(paser.orderId);
                if (order != null)
                {
                    var staff = order.OrderStaffs.Where(p => p.ProcessId == "create").FirstOrDefault();
                    // nhan vien
                    if (staff != null)
                    {
                        HaiUtil.SendNotifi("Đơn hàng " + order.Code, "Cửa hàng " + c1Info.StoreName + " vừa giao hàng", staff.HaiStaff.UserLogin, db, mongoHelper);
                    }

                    // c2
                    HaiUtil.SendNotifi("Đơn hàng " + order.Code, "Cửa hàng " + c1Info.StoreName + " vừa giao hàng", order.CInfoCommon.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);
        }
Пример #6
0
        public ActionResult UpdateDelivery(string orderId, string productId, int?can, int?box)
        {
            if (can == null || box == null)
            {
                return(Json(new { id = 0 }, JsonRequestBehavior.AllowGet));
            }

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

            if (orderProduct == null)
            {
                return(Json(new { id = 0 }, JsonRequestBehavior.AllowGet));
            }

            var quantity = box + orderProduct.ProductInfo.Quantity * can;

            orderProduct.QuantityFinish = quantity;

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

            string stt = "";

            if (quantity == 0)
            {
                stt = "Chưa giao";
            }
            else if (quantity == orderProduct.Quantity)
            {
                stt = "Giao đủ";
            }
            else if (quantity > orderProduct.Quantity)
            {
                stt = "Giao nhiều hơn";
            }
            else if (quantity < orderProduct.Quantity)
            {
                stt = "Giao ít hơn";
            }

            var    order       = orderProduct.HaiOrder;
            string deliveryStt = GetDeliveryStatus(order);

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

            // save history
            var haiStaff = db.HaiStaffs.Where(p => p.UserLogin == User.Identity.Name).FirstOrDefault();
            var history  = new OrderProductHistory()
            {
                Id         = Guid.NewGuid().ToString(),
                CreateDate = DateTime.Now,
                Notes      = "Quan ly cong ty cap nhat",
                OrderId    = orderProduct.OrderId,
                ProductId  = orderProduct.ProductId,
                Quantity   = quantity,
                StaffId    = haiStaff.Id
            };

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


            Utitl.Send("Đơn hàng " + orderProduct.HaiOrder.Code, "Đã cập nhật số lượng giao " + HaiUtil.ConvertProductQuantityText(orderProduct.ProductInfo.Quantity, quantity, orderProduct.ProductInfo.Unit) +
                       "\nCho sản phẩm " + orderProduct.ProductInfo.PName, haiStaff.UserLogin, db, mongoHelp);

            return(Json(new { id = 1, money = (quantity * orderProduct.PerPrice).Value.ToString("C", Util.Cultures.VietNam), stt = stt }, JsonRequestBehavior.AllowGet));
        }