Exemplo n.º 1
0
        public ActionResult ConfirmDeliveyMailer(MailerDeliveryConfirmInfo detail)
        {
            var findDetail = db.MM_MailerDeliveryDetail.Where(p => p.Id == detail.DetailId).FirstOrDefault();

            if (findDetail != null)
            {
                var mailerInfo = db.MM_Mailers.Find(findDetail.MailerID);

                var findDocument = db.MM_MailerDelivery.Where(p => p.DocumentID == detail.DocumentID).FirstOrDefault();

                if (findDocument == null)
                {
                    return(Json(new ResultInfo()
                    {
                        error = 1,
                        msg = "Sai thông tin"
                    }, JsonRequestBehavior.AllowGet));
                }

                findDetail.DeliveryStatus  = detail.DeliveryStatus;
                mailerInfo.CurrentStatusID = detail.DeliveryStatus;

                var deliveryDate = DateTime.ParseExact(detail.DeliveryDate + " " + detail.DeliveryTime, "dd/M/yyyy HH:mm", null);

                if (deliveryDate == null)
                {
                    deliveryDate = DateTime.Now;
                }

                if (detail.DeliveryStatus == 5)
                {
                    findDetail.DeliveryTo     = "";
                    findDetail.DeliveryNotes  = detail.DeliveryNotes;
                    findDetail.ReturnReasonID = detail.ReturnReasonID;
                    findDetail.DeliveryDate   = deliveryDate;


                    mailerInfo.DeliveryTo    = "";
                    mailerInfo.DeliveryDate  = deliveryDate;
                    mailerInfo.DeliveryNotes = detail.DeliveryNotes;
                    mailerInfo.IsReturn      = true;

                    HandleHistory.AddTracking(5, detail.MailerID, mailerInfo.CurrentPostOfficeID, "Trả lại hàng, vì lý do " + detail.DeliveryNotes);
                }
                else if (detail.DeliveryStatus == 6)
                {
                    findDetail.DeliveryTo    = "";
                    findDetail.DeliveryNotes = detail.DeliveryNotes;
                    findDetail.DeliveryDate  = deliveryDate;

                    mailerInfo.DeliveryTo    = "";
                    mailerInfo.DeliveryDate  = deliveryDate;
                    mailerInfo.DeliveryNotes = detail.DeliveryNotes;

                    HandleHistory.AddTracking(6, detail.MailerID, mailerInfo.CurrentPostOfficeID, "Chưa phát được vì " + detail.DeliveryNotes);
                }
                else if (detail.DeliveryStatus == 4)
                {
                    findDetail.DeliveryTo     = detail.DeliveryTo;
                    findDetail.ReturnReasonID = null;
                    findDetail.DeliveryNotes  = "Đã phát";
                    findDetail.DeliveryDate   = deliveryDate;

                    mailerInfo.DeliveryTo      = detail.DeliveryTo;
                    mailerInfo.DeliveryDate    = deliveryDate;
                    mailerInfo.DeliveryNotes   = "Đã phát";
                    mailerInfo.CurrentStatusID = 4;
                    if (mailerInfo.IsReturn == true)
                    {
                        findDetail.DeliveryNotes = "Đã hoàn - Người gửi thanh toán cước";
                        mailerInfo.DeliveryNotes = "Đã hoàn - Người gửi thanh toán cước";

                        findDetail.DeliveryStatus  = 11;
                        mailerInfo.CurrentStatusID = 11;
                        mailerInfo.PaymentMethodID = "NGTT";

                        HandleHistory.AddTracking(11, detail.MailerID, mailerInfo.CurrentPostOfficeID, "Ngày hoàn " + deliveryDate.ToString("dd/MM/yyyy") + " lúc " + deliveryDate.ToString("HH:mm") + ", người nhận: " + detail.DeliveryTo);
                    }
                    else
                    {
                        HandleHistory.AddTracking(4, detail.MailerID, mailerInfo.CurrentPostOfficeID, "Ngày phát " + deliveryDate.ToString("dd/MM/yyyy") + " lúc " + deliveryDate.ToString("HH:mm") + ", người nhận: " + detail.DeliveryTo);
                        // save nhung don co thu tien COD
                        if (mailerInfo.PaymentMethodID == "NNTT")
                        {
                            var saveCoDDebit = new EmpployeeDebitCOD()
                            {
                                Id = Guid.NewGuid().ToString(),
                                AccountantConfirm = 0,
                                COD         = Convert.ToDouble(mailerInfo.COD) + Convert.ToDouble(mailerInfo.Amount),
                                Describe    = "Thu: Cước + COD",
                                ConfirmDate = DateTime.Now,
                                CreateDate  = DateTime.Now,
                                DocumentID  = detail.DocumentID,
                                EmployeeID  = findDocument.EmployeeID,
                                MailerID    = mailerInfo.MailerID
                            };

                            db.EmpployeeDebitCODs.Add(saveCoDDebit);
                        }
                        else
                        {
                            if (mailerInfo.COD > 0)
                            {
                                var saveCoDDebit = new EmpployeeDebitCOD()
                                {
                                    Id = Guid.NewGuid().ToString(),
                                    AccountantConfirm = 0,
                                    Describe          = "Thu: COD",
                                    COD         = Convert.ToDouble(mailerInfo.COD),
                                    ConfirmDate = DateTime.Now,
                                    CreateDate  = DateTime.Now,
                                    DocumentID  = detail.DocumentID,
                                    EmployeeID  = findDocument.EmployeeID,
                                    MailerID    = mailerInfo.MailerID
                                };

                                db.EmpployeeDebitCODs.Add(saveCoDDebit);
                            }
                        }
                    }
                }
                mailerInfo.IsPostAccept    = false;
                db.Entry(mailerInfo).State = System.Data.Entity.EntityState.Modified;
                db.Entry(findDetail).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();

                return(Json(new ResultInfo()
                {
                    error = 0,
                    msg = ""
                }, JsonRequestBehavior.AllowGet));
            }

            return(Json(new ResultInfo()
            {
                error = 1,
                msg = "Sai thông tin"
            }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 2
0
        // cap nhat mailer
        public ResultInfo UpdateDelivery(UpdateDeliveryReceive info, string user)
        {
            var result = new ResultInfo()
            {
                error = 0,
                msg   = "success"
            };

            try
            {
                var checkUser = db.BS_Employees.Where(p => p.UserLogin == user).FirstOrDefault();

                if (checkUser == null)
                {
                    throw new Exception("Sai thông tin");
                }

                // check Document of employee
                var document = db.MM_MailerDelivery.Where(p => p.DocumentID == info.DocumentID && p.EmployeeID == checkUser.EmployeeID).FirstOrDefault();

                if (document == null)
                {
                    throw new Exception("Đơn này không được phân cho bạn phát");
                }

                // find detail
                var findDetail = db.MM_MailerDeliveryDetail.Where(p => p.DocumentID == info.DocumentID && p.MailerID == info.MailerID && p.DeliveryStatus == 3).FirstOrDefault();

                if (findDetail == null)
                {
                    throw new Exception("Sai thông tin");
                }


                DateTime deliverDate = DateTime.ParseExact(info.DeliveryDate, "dd/M/yyyy HH:mm", null);

                if (deliverDate == null)
                {
                    deliverDate = DateTime.Now;
                }

                //
                var mailerInfo = db.MM_Mailers.Find(findDetail.MailerID);

                if (mailerInfo == null)
                {
                    throw new Exception("Vận đơn sai");
                }
                mailerInfo.IsPostAccept    = false;
                findDetail.DeliveryStatus  = info.StatusID;
                mailerInfo.CurrentStatusID = info.StatusID;

                if (info.StatusID == 5)
                {
                    //  var findReason = db.BS_ReturnReasons.Where(p => p.ReasonID == info.ReturnReasonID).FirstOrDefault();

                    findDetail.DeliveryTo     = "";
                    findDetail.DeliveryNotes  = info.Note;
                    findDetail.ReturnReasonID = info.ReturnReasonID;
                    findDetail.DeliveryDate   = deliverDate;


                    mailerInfo.DeliveryTo    = "";
                    mailerInfo.DeliveryDate  = deliverDate;
                    mailerInfo.DeliveryNotes = info.Note;
                    mailerInfo.IsReturn      = true;
                    HandleHistory.AddTracking(5, info.MailerID, mailerInfo.CurrentPostOfficeID, "Trả lại hàng, vì lý do " + info.Note);
                }
                else if (info.StatusID == 6)
                {
                    findDetail.DeliveryTo    = "";
                    findDetail.DeliveryDate  = deliverDate;
                    findDetail.DeliveryNotes = info.Note;

                    mailerInfo.DeliveryTo    = "";
                    mailerInfo.DeliveryDate  = deliverDate;
                    mailerInfo.DeliveryNotes = info.Note;

                    HandleHistory.AddTracking(6, info.MailerID, mailerInfo.CurrentPostOfficeID, "Chưa phát được vì " + info.Note);
                }
                else if (info.StatusID == 4)
                {
                    findDetail.DeliveryTo     = info.Reciever;
                    findDetail.ReturnReasonID = null;
                    findDetail.DeliveryNotes  = "Đã phát";
                    findDetail.DeliveryDate   = deliverDate;

                    mailerInfo.DeliveryTo      = info.Reciever;
                    mailerInfo.DeliveryDate    = deliverDate;
                    mailerInfo.DeliveryNotes   = "Đã phát";
                    mailerInfo.CurrentStatusID = 4;

                    if (mailerInfo.IsReturn == true)
                    {
                        findDetail.DeliveryNotes = "Đã hoàn - Người gửi thanh toán cước";
                        mailerInfo.DeliveryNotes = "Đã hoàn - Người gửi thanh toán cước";

                        findDetail.DeliveryStatus  = 11;
                        mailerInfo.CurrentStatusID = 11;
                        mailerInfo.PaymentMethodID = "NGTT";

                        HandleHistory.AddTracking(11, info.MailerID, mailerInfo.CurrentPostOfficeID, "Ngày hoàn " + deliverDate.ToString("dd/MM/yyyy") + " lúc " + deliverDate.ToString("HH:mm") + ", người nhận: " + info.Reciever);
                    }
                    else
                    {
                        HandleHistory.AddTracking(4, info.MailerID, mailerInfo.CurrentPostOfficeID, "Ngày phát " + deliverDate.ToString("dd/MM/yyyy") + " lúc " + deliverDate.ToString("HH:mm") + ", người nhận: " + info.Reciever);

                        if (mailerInfo.PaymentMethodID == "NNTT")
                        {
                            var saveCoDDebit = new EmpployeeDebitCOD()
                            {
                                Id = Guid.NewGuid().ToString(),
                                AccountantConfirm = 0,
                                COD         = Convert.ToDouble(mailerInfo.COD) + Convert.ToDouble(mailerInfo.Amount),
                                Describe    = "Thu: Cước + COD",
                                ConfirmDate = DateTime.Now,
                                CreateDate  = DateTime.Now,
                                DocumentID  = findDetail.DocumentID,
                                EmployeeID  = document.EmployeeID,
                                MailerID    = mailerInfo.MailerID
                            };

                            db.EmpployeeDebitCODs.Add(saveCoDDebit);
                        }
                        else
                        {
                            if (mailerInfo.COD > 0)
                            {
                                var saveCoDDebit = new EmpployeeDebitCOD()
                                {
                                    Id = Guid.NewGuid().ToString(),
                                    AccountantConfirm = 0,
                                    Describe          = "Thu: COD",
                                    COD         = Convert.ToDouble(mailerInfo.COD),
                                    ConfirmDate = DateTime.Now,
                                    CreateDate  = DateTime.Now,
                                    DocumentID  = findDetail.DocumentID,
                                    EmployeeID  = document.EmployeeID,
                                    MailerID    = mailerInfo.MailerID
                                };

                                db.EmpployeeDebitCODs.Add(saveCoDDebit);
                            }
                        }
                    }
                }

                if (info.images != null)
                {
                    foreach (var image in info.images)
                    {
                        var saveImage = new MailerImage()
                        {
                            Id         = Guid.NewGuid().ToString(),
                            CreateTime = DateTime.Now,
                            MailerID   = info.MailerID,
                            PathImage  = image,
                            UserSend   = user
                        };

                        db.MailerImages.Add(saveImage);
                    }
                    db.SaveChanges();
                }

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

                UpdateDeliveryStatus(document.DocumentID);
            }
            catch (Exception e)
            {
                result.msg   = e.Message;
                result.error = 1;
            }

            return(result);
        }