Пример #1
0
 public bool DeleteDelivery(Delivery delivery)
 {
     if (delivery == null) return false;
     _unitOfWork.DeliveryRepository.Delete(delivery);
     _unitOfWork.Save();
     return true;
 }
Пример #2
0
 public bool EditDelivery(Delivery delivery)
 {
     _unitOfWork.DeliveryRepository.Edit(delivery);
     _unitOfWork.Save();
     return true;
 }
Пример #3
0
 public bool AddDelivery(Delivery delivery)
 {
     _unitOfWork.DeliveryRepository.Add(delivery);
     _unitOfWork.Save();
     return true;
 }
Пример #4
0
        private DeliveryViewModel EditGoodsReceivingNote(Delivery delivery)
        {
            if (delivery == null) return new DeliveryViewModel();
            var dispatch = _dispatchService.Get(t => t.DispatchID == delivery.DispatchID, null,
               "FDP,FDP.AdminUnit,FDP.AdminUnit.AdminUnit2,FDP.AdminUnit.AdminUnit2.AdminUnit2,Transporter,Hub").FirstOrDefault();

            var deliveryViewModel = new DeliveryViewModel();

            deliveryViewModel.DispatchID = delivery.DispatchID;
            deliveryViewModel.DeliveryDate = delivery.DeliveryDate;
            deliveryViewModel.DocumentReceivedBy = delivery.DocumentReceivedBy;
            deliveryViewModel.DocumentReceivedDate = delivery.DocumentReceivedDate;
            deliveryViewModel.DeliveryID = delivery.DeliveryID;
            //distribution.DonorID=dispatch.
            deliveryViewModel.DriverName = delivery.DriverName;
            deliveryViewModel.FDPID = delivery.FDPID;
            deliveryViewModel.HubID = delivery.HubID;
            deliveryViewModel.TransporterID = delivery.TransporterID;
            deliveryViewModel.InvoiceNo = delivery.InvoiceNo;
            deliveryViewModel.PlateNoPrimary = delivery.PlateNoPrimary;
            deliveryViewModel.PlateNoTrailler = delivery.PlateNoTrailler;
            deliveryViewModel.RequisitionNo = delivery.RequisitionNo;
            deliveryViewModel.FDP = dispatch.FDP.Name;
            deliveryViewModel.Region = dispatch.FDP.AdminUnit.AdminUnit2.AdminUnit2.Name;
            deliveryViewModel.Zone = dispatch.FDP.AdminUnit.AdminUnit2.Name;
            deliveryViewModel.Woreda = dispatch.FDP.AdminUnit.Name;
            deliveryViewModel.Hub = dispatch.Hub.Name;
            deliveryViewModel.DeliveryBy = delivery.DeliveryBy;
            deliveryViewModel.ReceivedBy = delivery.ReceivedBy;
            deliveryViewModel.ReceivedDate = delivery.ReceivedDate;
            deliveryViewModel.ReceivingNumber = delivery.ReceivingNumber;
            deliveryViewModel.InvoiceNo = delivery.InvoiceNo;
            deliveryViewModel.WayBillNo = delivery.WayBillNo;
            deliveryViewModel.RequisitionNo = delivery.RequisitionNo;
            deliveryViewModel.Transporter = dispatch.Transporter.Name;
            deliveryViewModel.Status = delivery.Status;
            deliveryViewModel.ActionTypeRemark = delivery.ActionTypeRemark;
            var pref = UserAccountHelper.UserCalendarPreference();
            deliveryViewModel.DeliveryDatePref = delivery.DeliveryDate.HasValue
                                                         ? delivery.DeliveryDate.Value.ToCTSPreferedDateFormat(pref)
                                                         : "";
            deliveryViewModel.ReceivedDatePref = delivery.ReceivedDate.HasValue
                                                         ? delivery.ReceivedDate.Value.ToCTSPreferedDateFormat(pref)
                                                         : "";
            deliveryViewModel.DocumentReceivedDatePref = delivery.DocumentReceivedDate.HasValue
                                                                 ? delivery.DocumentReceivedDate.Value.
                                                                       ToCTSPreferedDateFormat(pref)
                                                                 : "";

            deliveryViewModel.ContainsDiscripancy =
                delivery.DeliveryDetails.Any(t => t.ReceivedQuantity < t.SentQuantity);
            //foreach (var dispatchDetail in dispatch.DispatchDetails)
            //{
            //    var deliveryDetail = new DistributionDetail();
            //    deliveryDetail.DistributionID = distribution.DistributionID;
            //    deliveryDetail.DistributionDetailID = Guid.NewGuid();
            //    deliveryDetail.CommodityID = dispatchDetail.CommodityID;
            //    deliveryDetail.ReceivedQuantity = 0;
            //    deliveryDetail.SentQuantity = dispatchDetail.RequestedQuantityInMT;
            //    deliveryDetail.UnitID = dispatchDetail.UnitID;

            //}
            return deliveryViewModel;
        }
Пример #5
0
 private GRNViewModel BindDeliveryViewModel(Delivery delivery)
 {
     var datePref = _userAccountService.GetUserInfo(HttpContext.User.Identity.Name).DatePreference;
     var firstOrDefault = _dispatchService.FindBy(t => t.DispatchID == delivery.DispatchID).FirstOrDefault();
     var deliveryViewModel = new GRNViewModel();
     if (firstOrDefault != null)
     {
         deliveryViewModel = new GRNViewModel
         {
             DeliveryID = delivery.DeliveryID,
             InvoiceNo = delivery.InvoiceNo,
             Program = firstOrDefault.DispatchAllocation.Program.Name,
             BidNumber = firstOrDefault.BidNumber,
             DispatchDatePref = firstOrDefault.DispatchDate.ToShortDateString(),
             CreatedDatePref = firstOrDefault.DispatchDate.ToString(),
             ReceivingNumber = delivery.ReceivingNumber,
             WayBillNo = delivery.WayBillNo,
             ReceivedBy = delivery.ReceivedBy,
             ReceivedDate = delivery.ReceivedDate != null ? delivery.ReceivedDate.Value.ToShortDateString() : "",
             DeliveryBy = delivery.DeliveryBy,
             DeliveryDate = delivery.DeliveryDate != null ? delivery.DeliveryDate.Value.ToShortDateString() : "",
             DocumentReceivedDate = delivery.DocumentReceivedDate != null ? delivery.DocumentReceivedDate.Value.ToShortDateString() : "",
             RequisitionNo = delivery.RequisitionNo,
             Zone=delivery.FDP.AdminUnit.AdminUnit2.Name,
             Woreda = delivery.FDP.AdminUnit.Name,
             FDP = delivery.FDP.Name,
             PlateNoPrimary = delivery.PlateNoPrimary,
             PlateNoTrailler = delivery.PlateNoTrailler,
             DriverName = delivery.DriverName,
             DispatchID = delivery.DispatchID,
             RefNo = _transporterPaymentRequestService.FindBy(r=>r.GIN==delivery.InvoiceNo).Select(t=>t.ReferenceNo).FirstOrDefault()
         };
     }
     return deliveryViewModel;
 }
Пример #6
0
        public ActionResult ReceiveGRN(DeliveryViewModel deliveryViewModel)
        {
            if (ModelState.IsValid)
            {
                int transportOrderId = 0;

                var dispatch = _dispatchService.Get(t => t.DispatchID == deliveryViewModel.DispatchID, null,
                    "DispatchDetails,DispatchAllocation").FirstOrDefault();

                var delivery = new Delivery();
                delivery.DeliveryBy = deliveryViewModel.DeliveryBy;
                delivery.DeliveryDate = deliveryViewModel.DeliveryDate;
                delivery.DispatchID = deliveryViewModel.DispatchID;
                delivery.DeliveryID = deliveryViewModel.DeliveryID;
                delivery.DocumentReceivedBy = deliveryViewModel.DocumentReceivedBy;
                delivery.DocumentReceivedDate = deliveryViewModel.DocumentReceivedDate;
                delivery.DonorID = deliveryViewModel.DonorID;
                delivery.DriverName = deliveryViewModel.DriverName;
                delivery.FDPID = deliveryViewModel.FDPID;
                delivery.HubID = deliveryViewModel.HubID;
                delivery.InvoiceNo = deliveryViewModel.InvoiceNo;
                delivery.PlateNoPrimary = deliveryViewModel.PlateNoPrimary;
                delivery.PlateNoTrailler = deliveryViewModel.PlateNoTrailler;
                delivery.ReceivedBy = deliveryViewModel.ReceivedBy;
                delivery.ReceivedDate = deliveryViewModel.ReceivedDate;
                delivery.ReceivingNumber = deliveryViewModel.ReceivingNumber;
                delivery.RequisitionNo = deliveryViewModel.RequisitionNo;
                delivery.TransporterID = deliveryViewModel.TransporterID;
                delivery.WayBillNo = deliveryViewModel.WayBillNo;
                if (dispatch != null)
                {

                    foreach (var dispatchDetail in dispatch.DispatchDetails)
                    {
                        var deliveryDetail = new DeliveryDetail();
                        deliveryDetail.DeliveryID = delivery.DeliveryID;
                        deliveryDetail.DeliveryDetailID = Guid.NewGuid();
                        deliveryDetail.CommodityID = dispatchDetail.CommodityID;
                        deliveryDetail.ReceivedQuantity = 0;
                        deliveryDetail.SentQuantity = dispatchDetail.RequestedQuantityInMT;
                        deliveryDetail.UnitID = dispatchDetail.UnitID;
                        delivery.DeliveryDetails.Add(deliveryDetail);

                    }

                    _deliveryService.AddDelivery(delivery);

                    var dispatchAllocation = dispatch.DispatchAllocation;
                    if (dispatchAllocation != null)
                    {
                        transportOrderId = dispatchAllocation.TransportOrderID.HasValue ? dispatchAllocation.TransportOrderID.Value : 0;
                    }
                }
                return RedirectToAction("EditGRN", "Delivery", new { Area = "Logistics", id = delivery.DeliveryID });
            }

            return View(deliveryViewModel);
        }
Пример #7
0
        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);
        }
Пример #8
0
        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();
                if (newdelivery != null)
                {
                    newdelivery.DispatchID = delivery.DispatchID;
                    newdelivery.ReceivingNumber = delivery.ReceivingNumber;
                    newdelivery.WayBillNo = delivery.WayBillNo;
                    newdelivery.ReceivedBy = delivery.ReceivedBy;
                    newdelivery.ReceivedDate = DateTime.Parse(delivery.ReceivedDate);
                    newdelivery.DeliveryBy = delivery.DeliveryBy;
                    newdelivery.DeliveryDate = DateTime.Parse(delivery.DeliveryDate);
                    newdelivery.DocumentReceivedDate = DateTime.Parse(delivery.DocumentReceivedDate);
                    _deliveryService.EditDelivery(newdelivery);

                    deliveryDetail =
                        _deliveryDetailService.Get(t => t.DeliveryID == newdelivery.DeliveryID, null,
                                                       "Commodity,Unit").FirstOrDefault();
                    if (deliveryDetail != null)
                    {
                        deliveryDetail.ReceivedQuantity = delivery.ReceivedQuantity;
                        _deliveryDetailService.EditDeliveryDetail(deliveryDetail);
                    }
                }
            }
            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 = DateTime.Parse(delivery.ReceivedDate);
                newdelivery.DeliveryBy = delivery.DeliveryBy;
                newdelivery.DeliveryDate = DateTime.Parse(delivery.DeliveryDate);
                newdelivery.DocumentReceivedDate = DateTime.Parse(delivery.DocumentReceivedDate);
                if (dispatch != null)
                {
                    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;
                deliveryDetail.ReceivedQuantity = delivery.ReceivedQuantity;
                //deliveryDetail.Commodity = _commodityService.FindById(delivery.CommodityID);
                //deliveryDetail.Unit = _unitService.FindById(delivery.UnitID);
                newdelivery.DeliveryDetails = new List<DeliveryDetail> { deliveryDetail };
                _deliveryService.AddDelivery(newdelivery);
                //_deliveryService.AddDelivery(newdelivery);
            }
            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;
                }
                _transactionService.PostDeliveryReceipt(newdelivery.DeliveryID);
            }

            return Json(deliveryViewModel, JsonRequestBehavior.AllowGet);
            //return View("Dispatches", distributionViewModel);
        }