public ActionResult AcceptAll(string documentId) { var document = db.MM_PackingList.Where(p => p.DocumentID == documentId).FirstOrDefault(); if (document == null) { return(Json(new { error = 1, msg = "Sai thông tin" }, JsonRequestBehavior.AllowGet)); } if (document.StatusID != 2) { return(Json(new { error = 1, msg = "Bảng kê chưa xác nhận" }, JsonRequestBehavior.AllowGet)); } var listMailer = db.MM_PackingListDetail.Where(p => p.DocumentID == documentId).ToList(); foreach (var item in listMailer) { var mailer = db.MM_Mailers.Find(item.MailerID); if (mailer.CurrentStatusID != 1) { continue; } if (item.StatusID == 1) { item.StatusID = 2; // da nhan item.AcceptDate = DateTime.Now; db.Entry(item).State = System.Data.Entity.EntityState.Modified; mailer.CurrentStatusID = 2; mailer.LastUpdateDate = DateTime.Now; mailer.CurrentPostOfficeID = document.PostOfficeIDAccept; db.Entry(mailer).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); HandleHistory.AddTracking(2, mailer.MailerID, mailer.CurrentPostOfficeID, "Hàng đã được tiếp nhận tại bưu cục"); } } return(Json(new { error = 0 }, JsonRequestBehavior.AllowGet)); }
// 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); }
public ActionResult AddListMailer(List <string> mailers, string documentId) { var document = db.MM_PackingList.Where(p => p.DocumentID == documentId).FirstOrDefault(); if (document.StatusID != 0) { return(Json(new { error = 1, msg = "Bảng kê không thể thêm" }, JsonRequestBehavior.AllowGet)); } foreach (var item in mailers) { var mailer = db.MM_Mailers.Find(item); if (mailer == null) { continue; } if (mailer.CurrentStatusID != 2 && mailer.CurrentStatusID != 5) { continue; } if (document.PostOfficeID != mailer.CurrentPostOfficeID) { continue; } var checkDetail = db.MM_PackingListDetail.Where(p => p.DocumentID == document.DocumentID && p.MailerID == item).FirstOrDefault(); if (checkDetail != null) { continue; } var checkDetailOther = db.MM_PackingListDetail.Where(p => p.MailerID == item && p.StatusID == 12).FirstOrDefault(); if (checkDetailOther != null) { continue; } var ins = new MM_PackingListDetail() { CreationDate = DateTime.Now, DocumentID = document.DocumentID, MailerID = mailer.MailerID, StatusID = 12, Notes = "" }; db.MM_PackingListDetail.Add(ins); db.SaveChanges(); mailer.CurrentStatusID = 12; mailer.LastUpdateDate = DateTime.Now; db.Entry(mailer).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); HandleHistory.AddTracking(12, item, mailer.CurrentPostOfficeID, "Hàng đang được đóng giói chuẩn bị vận chuyển"); } return(Json(new { error = 0 }, JsonRequestBehavior.AllowGet)); }