public JsonResult RecentDispatchAllocation() { var currentUser = UserAccountHelper.GetUser(HttpContext.User.Identity.Name); if (currentUser.DefaultHub != null) { var result = _dispatchAllocationService.FindBy(m => m.HubID == currentUser.DefaultHub).OrderByDescending(m => m.DispatchAllocationID); var dispached = GetDispatchAllocation(result); return(Json(dispached, JsonRequestBehavior.AllowGet)); } return(Json(null, JsonRequestBehavior.AllowGet)); }
public ActionResult EditGRN(GRNViewModel delivery) { var originaldelivery = _deliveryService.Get(t => t.DispatchID == delivery.DispatchID, null, "FDP,FDP.AdminUnit,FDP.AdminUnit.AdminUnit2,FDP.AdminUnit.AdminUnit2.AdminUnit2,Hub").FirstOrDefault(); var newdelivery = new Delivery(); var deliveryDetail = new DeliveryDetail(); if (originaldelivery != null) { newdelivery = _deliveryService.FindBy(t => t.DeliveryID == originaldelivery.DeliveryID).FirstOrDefault(); TransporterPaymentRequest newTransportPaymentRequest = null; newTransportPaymentRequest = _transporterPaymentRequestService.FindBy(t => t.GIN == delivery.InvoiceNo).FirstOrDefault(); if (newdelivery != null) { newdelivery.DispatchID = delivery.DispatchID; newdelivery.ReceivingNumber = delivery.ReceivingNumber; newdelivery.WayBillNo = delivery.WayBillNo; newdelivery.ReceivedBy = delivery.ReceivedBy; newdelivery.ReceivedDate = delivery.ReceivedDate != null?DateTime.Parse(delivery.ReceivedDate) : DateTime.Now; newdelivery.DeliveryBy = delivery.DeliveryBy; newdelivery.DeliveryDate = delivery.DeliveryDate != null?DateTime.Parse(delivery.DeliveryDate) : DateTime.Now; newdelivery.DocumentReceivedDate = delivery.DocumentReceivedDate != null?DateTime.Parse(delivery.DocumentReceivedDate) : DateTime.Now; _deliveryService.EditDelivery(newdelivery); deliveryDetail = _deliveryDetailService.Get(t => t.DeliveryID == newdelivery.DeliveryID, null, "Commodity,Unit").FirstOrDefault(); if (deliveryDetail != null) { deliveryDetail.ReceivedQuantity = delivery.ReceivedQuantity.ToMetricTone(); //save it using MT _deliveryDetailService.EditDeliveryDetail(deliveryDetail); } if (newTransportPaymentRequest != null) { newTransportPaymentRequest.ReferenceNo = delivery.RefNo; _transporterPaymentRequestService.EditTransporterPaymentRequest(newTransportPaymentRequest); } } } else { var dispatch = _dispatchService.FindBy(t => t.DispatchID == delivery.DispatchID).FirstOrDefault(); //newDelivery = new Delivery(); newdelivery.DeliveryID = Guid.NewGuid(); newdelivery.DispatchID = delivery.DispatchID; newdelivery.ReceivingNumber = delivery.ReceivingNumber; newdelivery.WayBillNo = delivery.WayBillNo; newdelivery.ReceivedBy = delivery.ReceivedBy; newdelivery.ReceivedDate = delivery.ReceivedDate != null?DateTime.Parse(delivery.ReceivedDate) : DateTime.Now; newdelivery.DeliveryBy = delivery.DeliveryBy; newdelivery.DeliveryDate = delivery.DeliveryDate != null?DateTime.Parse(delivery.DeliveryDate) : DateTime.Now; newdelivery.DocumentReceivedDate = delivery.DocumentReceivedDate != null?DateTime.Parse(delivery.DocumentReceivedDate) : DateTime.Now; if (dispatch != null) { var dispatchAllocation = _dispatchAllocationService.FindBy(m => m.DispatchAllocationID == dispatch.DispatchAllocationID). FirstOrDefault(); //if (dispatchAllocation != null && dispatchAllocation.ShippingInstructionID!=null) //{ // newdelivery.DonorID = _deliveryService.GetDonorID(dispatchAllocation.ShippingInstruction.Value); //} if (dispatch.DriverName != null) { newdelivery.DriverName = dispatch.DriverName; } //newDistribution.FDP = dispatch.FDP; if (dispatch.FDPID != null) { newdelivery.FDPID = int.Parse(dispatch.FDPID.ToString()); } //newDistribution.Hub = dispatch.Hub; newdelivery.HubID = dispatch.HubID; newdelivery.InvoiceNo = dispatch.GIN; newdelivery.PlateNoPrimary = dispatch.PlateNo_Prime; newdelivery.PlateNoTrailler = dispatch.PlateNo_Trailer; newdelivery.RequisitionNo = dispatch.RequisitionNo; newdelivery.TransporterID = dispatch.TransporterID; } //_deliveryService.AddDelivery(newdelivery); deliveryDetail.DeliveryDetailID = Guid.NewGuid(); deliveryDetail.CommodityID = delivery.CommodityID; deliveryDetail.UnitID = delivery.UnitID; deliveryDetail.SentQuantity = delivery.SentQuantity.ToMetricTone(); //save it using MT deliveryDetail.ReceivedQuantity = delivery.ReceivedQuantity.ToMetricTone(); //save it using MT //deliveryDetail.Delivery.DeliveryBy = _commodityService.FindById(delivery.CommodityID); //deliveryDetail.Unit = _unitService.FindById(delivery.UnitID); newdelivery.DeliveryDetails = new List <DeliveryDetail> { deliveryDetail }; _deliveryService.AddDelivery(newdelivery); var transporterPaymentRequest = new TransporterPaymentRequest(); transporterPaymentRequest.ReferenceNo = delivery.RefNo; transporterPaymentRequest.GIN = delivery.InvoiceNo; //var firstOrDefault = _transportOrderService.Get(t => t.TransporterID == newdelivery.TransporterID && t.StatusID >= 3).FirstOrDefault(); var transportOrderId = delivery.TransportOrderID; if (transportOrderId != null) { transporterPaymentRequest.TransportOrderID = transportOrderId; } transporterPaymentRequest.DeliveryID = newdelivery.DeliveryID; transporterPaymentRequest.ShortageBirr = (decimal)0.00; int BP_PR = _applicationSettingService.getPaymentRequestWorkflow(); if (BP_PR != 0) { BusinessProcessState createdstate = new BusinessProcessState { DatePerformed = DateTime.Now, PerformedBy = "System", Comment = "Created workflow for Payment Request" }; //_PaymentRequestservice.Create(request); BusinessProcess bp = _businessProcessService.CreateBusinessProcess(BP_PR, transporterPaymentRequest.TransporterPaymentRequestID, "PaymentRequest", createdstate); transporterPaymentRequest.BusinessProcessID = bp.BusinessProcessID; transporterPaymentRequest.RequestedDate = DateTime.Now; _transporterPaymentRequestService.AddTransporterPaymentRequest(transporterPaymentRequest); } ViewBag.ErrorMessage1 = "The workflow assosiated with Payment Request doesnot exist."; ViewBag.ErrorMessage2 = "Please make sure the workflow is created and configured."; } var deliveryViewModel = new GRNViewModel(); if (newdelivery != null && deliveryDetail != null) { var deliveryWithFDP = _deliveryService.Get(t => t.DeliveryID == newdelivery.DeliveryID, null, "FDP").FirstOrDefault(); deliveryViewModel = BindDeliveryViewModel(deliveryWithFDP); var deliveryDetailWithComodityUnit = _deliveryDetailService.Get(t => t.DeliveryDetailID == deliveryDetail.DeliveryDetailID, null, "Commodity,Unit").FirstOrDefault(); if (deliveryDetailWithComodityUnit != null) { deliveryViewModel.DeliveryID = deliveryDetailWithComodityUnit.DeliveryID; deliveryViewModel.CommodityID = deliveryDetailWithComodityUnit.CommodityID; deliveryViewModel.UnitID = deliveryDetailWithComodityUnit.UnitID; deliveryViewModel.SentQuantity = deliveryDetailWithComodityUnit.SentQuantity; deliveryViewModel.ReceivedQuantity = deliveryDetailWithComodityUnit.ReceivedQuantity; deliveryViewModel.Commodity = deliveryDetailWithComodityUnit.Commodity.Name; deliveryViewModel.Unit = deliveryDetailWithComodityUnit.Unit.Name; } } return(Json(deliveryViewModel, JsonRequestBehavior.AllowGet)); //return View("Dispatches", distributionViewModel); }