public ActionResult GetDeliveryMailerDetail(string employeeId, string deliveryDate, string postId)
        {
            if (!CheckPostOffice(postId))
            {
                return(Json(new ResultInfo()
                {
                    error = 0, msg = "Sai bưu cục"
                }, JsonRequestBehavior.AllowGet));
            }
            DateTime date = DateTime.Now;

            try
            {
                date = DateTime.ParseExact(deliveryDate, "dd/M/yyyy", null);
            }
            catch
            {
                date = DateTime.Now;
            }
            var checkEmployyee = db.BS_Employees.Find(employeeId);

            if (checkEmployyee == null)
            {
                return(Json(new ResultInfo()
                {
                    error = 1,
                    msg = "Sai nhân viên"
                }, JsonRequestBehavior.AllowGet));
            }

            var documentCod = postId + date.ToString("ddMMyyyy");
            //
            var findDocument = db.MM_MailerDelivery.Where(p => p.DocumentCode == documentCod && p.EmployeeID == checkEmployyee.EmployeeID).FirstOrDefault();

            if (findDocument == null)
            {
                if (DateTime.Now.ToString("dd/MM/yyyy") == deliveryDate)
                {
                    findDocument = new MM_MailerDelivery()
                    {
                        DocumentID   = Guid.NewGuid().ToString(),
                        DocumentCode = documentCod,
                        CreateDate   = date,
                        DocumentDate = date,
                        EmployeeID   = employeeId,
                        LastEditDate = DateTime.Now,
                        Notes        = "",
                        NumberPlate  = "",
                        Quantity     = 0,
                        StatusID     = 0,
                        Weight       = 0,
                        PostID       = postId
                    };

                    db.MM_MailerDelivery.Add(findDocument);

                    db.SaveChanges();
                }
                else
                {
                    return(Json(new ResultInfo()
                    {
                        error = 1,
                        msg = "Không có bảng kê nào cho ngày " + deliveryDate
                    }, JsonRequestBehavior.AllowGet));
                }
            }

            var document = db.MAILER_GET_DELIVERY_EMPLOYEE_BYDATE(date.ToString("yyyy-MM-dd"), documentCod, checkEmployyee.EmployeeID).FirstOrDefault();

            var data = db.MAILERDELIVERY_GETMAILER(document.DocumentID).ToList();

            return(Json(new ResultInfo()
            {
                data = new
                {
                    document = document,
                    details = data
                },
                error = 0
            }, JsonRequestBehavior.AllowGet));
        }
        public ActionResult CreateFromRoutes(List <EmployeeAutoRouteInfo> routes, string postId)
        {
            DateTime date = DateTime.Now;

            foreach (var item in routes)
            {
                if (item.Mailers.Count() == 0)
                {
                    continue;
                }

                var documentCod = postId + date.ToString("ddMMyyyy");
                //
                var findDocument = db.MM_MailerDelivery.Where(p => p.DocumentCode == documentCod && p.EmployeeID == item.EmployeeID).FirstOrDefault();
                var findEmployee = db.BS_Employees.Find(item.EmployeeID);
                if (findDocument == null)
                {
                    findDocument = new MM_MailerDelivery()
                    {
                        DocumentID   = Guid.NewGuid().ToString(),
                        DocumentCode = documentCod,
                        CreateDate   = date,
                        DocumentDate = date,
                        EmployeeID   = item.EmployeeID,
                        LastEditDate = DateTime.Now,
                        Notes        = "",
                        NumberPlate  = "",
                        Quantity     = 0,
                        StatusID     = 0,
                        Weight       = 0,
                        PostID       = postId
                    };

                    db.MM_MailerDelivery.Add(findDocument);

                    db.SaveChanges();
                }


                // add to detail
                foreach (var mailer in item.Mailers)
                {
                    var checkMailer = db.MM_Mailers.Where(p => p.MailerID == mailer.MailerID && (p.CurrentStatusID == 2 || p.CurrentStatusID == 6 || p.CurrentStatusID == 5)).FirstOrDefault();

                    if (checkMailer != null)
                    {
                        if (checkMailer.CurrentStatusID == 6 || checkMailer.CurrentStatusID == 5)
                        {
                            if (checkMailer.IsPostAccept == false)
                            {
                                continue;
                            }
                        }

                        // dang phat
                        var check = db.MM_MailerDeliveryDetail.Where(p => p.MailerID == mailer.MailerID && p.DocumentID == findDocument.DocumentID && p.DeliveryStatus == 3).FirstOrDefault();

                        if (check != null)
                        {
                            continue;
                        }

                        var insData = new MM_MailerDeliveryDetail()
                        {
                            Id             = Guid.NewGuid().ToString(),
                            DocumentID     = findDocument.DocumentID,
                            MailerID       = checkMailer.MailerID,
                            CreationDate   = DateTime.Now,
                            DeliveryStatus = 3,
                        };

                        db.MM_MailerDeliveryDetail.Add(insData);

                        checkMailer.CurrentStatusID = 3;
                        checkMailer.LastUpdateDate  = DateTime.Now;
                        checkMailer.IsPostAccept    = false;
                        db.Entry(checkMailer).State = System.Data.Entity.EntityState.Modified;

                        db.SaveChanges();

                        HandleHistory.AddTracking(3, checkMailer.MailerID, checkMailer.CurrentPostOfficeID, "Nhân viên " + findEmployee.EmployeeName + "(" + findEmployee.Phone + ") , đang đi phát hàng");
                    }
                }

                MailerHandle.SendNotifi("Phát hàng", "Có đơn phát mới phát", findEmployee.UserLogin);
            }

            return(Json(new { }, JsonRequestBehavior.AllowGet));
        }
Beispiel #3
0
        public ActionResult CreateFromRoutes(List <EmployeeAutoRouteInfo> routes, string postId)
        {
            DateTime date = DateTime.Now;

            foreach (var item in routes)
            {
                if (item.Mailers.Count() == 0)
                {
                    continue;
                }

                var documentCod = postId + date.ToString("ddMMyyyy");
                //
                var findDocument = db.MM_MailerDelivery.Where(p => p.DocumentCode == documentCod && p.EmployeeID == item.EmployeeID).FirstOrDefault();

                if (findDocument == null)
                {
                    findDocument = new MM_MailerDelivery()
                    {
                        DocumentID   = Guid.NewGuid().ToString(),
                        DocumentCode = documentCod,
                        CreateDate   = date,
                        DocumentDate = date,
                        EmployeeID   = item.EmployeeID,
                        LastEditDate = DateTime.Now,
                        Notes        = "",
                        NumberPlate  = "",
                        Quantity     = 0,
                        StatusID     = 0,
                        Weight       = 0,
                        PostID       = postId
                    };

                    db.MM_MailerDelivery.Add(findDocument);

                    db.SaveChanges();
                }


                // add to detail
                foreach (var mailer in item.Mailers)
                {
                    var checkMailer = db.MM_Mailers.Where(p => p.MailerID == mailer.MailerID && (p.CurrentStatusID == 2 || p.CurrentStatusID == 6 || p.CurrentStatusID == 5)).FirstOrDefault();

                    if (checkMailer != null)
                    {
                        // dang phat
                        var check = db.MM_MailerDeliveryDetail.Where(p => p.MailerID == mailer.MailerID && p.DocumentID == findDocument.DocumentID && p.DeliveryStatus == 3).FirstOrDefault();

                        if (check != null)
                        {
                            continue;
                        }

                        var insData = new MM_MailerDeliveryDetail()
                        {
                            Id             = Guid.NewGuid().ToString(),
                            DocumentID     = findDocument.DocumentID,
                            MailerID       = checkMailer.MailerID,
                            CreationDate   = DateTime.Now,
                            DeliveryStatus = 3,
                        };

                        db.MM_MailerDeliveryDetail.Add(insData);

                        checkMailer.CurrentStatusID = 3;
                        checkMailer.LastUpdateDate  = DateTime.Now;
                        db.Entry(checkMailer).State = System.Data.Entity.EntityState.Modified;

                        db.SaveChanges();
                    }
                }
            }

            return(Json(new { }, JsonRequestBehavior.AllowGet));
        }