/// <summary> /// Generates the receive. /// </summary> /// <returns></returns> public BLL.Receive GenerateReceive() { BLL.Receive receive = new BLL.Receive() { CreatedDate = DateTime.Now, ReceiptDate = this.ReceiptDate, DriverName = this.DriverName, GRN = this.GRN, PlateNo_Prime = this.PlateNo_Prime, PlateNo_Trailer = this.PlateNo_Trailer, TransporterID = this.TransporterID, HubID = this.HubID, CommodityTypeID = this.CommodityTypeID, WayBillNo = this.WayBillNo, ResponsibleDonorID = this.ResponsibleDonorID, SourceDonorID = this.SourceDonorID, CommoditySourceID = this.CommoditySourceID, WeightBridgeTicketNumber = this.TicketNumber, WeightBeforeUnloading = this.WeightBeforeUnloading, WeightAfterUnloading = this.WeightAfterUnloading, ReceivedByStoreMan = this.ReceivedByStoreMan, VesselName = this.VesselName, PortName = this.PortName, PurchaseOrder = this.PurchaseOrder, SupplierName = this.SupplierName, ReceiptAllocationID = this.ReceiptAllocationID, Remark = this.Remark, }; if (this.ReceiveID.HasValue) { receive.ReceiveID = this.ReceiveID.Value; } return(receive); }
/// <summary> /// Generates the receive. /// </summary> /// <returns></returns> public BLL.Receive GenerateReceive() { BLL.Receive receive = new BLL.Receive() { CreatedDate = DateTime.Now, ReceiptDate = this.ReceiptDate, DriverName = this.DriverName, GRN = this.GRN, PlateNo_Prime = this.PlateNo_Prime, PlateNo_Trailer = this.PlateNo_Trailer, TransporterID = this.TransporterID, HubID = this.HubID, CommodityTypeID = this.CommodityTypeID, WayBillNo = this.WayBillNo, ResponsibleDonorID = this.ResponsibleDonorID, SourceDonorID = this.SourceDonorID, CommoditySourceID = this.CommoditySourceID, WeightBridgeTicketNumber = this.TicketNumber, WeightBeforeUnloading = this.WeightBeforeUnloading, WeightAfterUnloading = this.WeightAfterUnloading, ReceivedByStoreMan = this.ReceivedByStoreMan, VesselName = this.VesselName, PortName = this.PortName, PurchaseOrder = this.PurchaseOrder, SupplierName = this.SupplierName, ReceiptAllocationID = this.ReceiptAllocationID, Remark = this.Remark, }; if(this.ReceiveID.HasValue) { receive.ReceiveID = this.ReceiveID.Value; } return receive; }
/// <summary> /// Generates the receive model. /// </summary> /// <param name="receive">The receive.</param> /// <param name="user">The user.</param> /// <returns></returns> public static Models.ReceiveViewModel GenerateReceiveModel(BLL.Receive receive, List <Commodity> commodities, List <CommodityGrade> commodityGrades, List <Transporter> transporters, List <CommodityType> commodityTypes, List <CommoditySource> commoditySources, List <Program> programs, List <Donor> donors, List <Hub> hubs, UserProfile user) { ReceiveViewModel model = new ReceiveViewModel(); model._UserProfile = user; model.InitalizeViewModel(commodities, commodityGrades, transporters, commodityTypes, commoditySources, programs, donors, hubs, user); model.IsEditMode = true; model.ReceiveID = receive.ReceiveID; model.DriverName = receive.DriverName; model.GRN = receive.GRN; model.PlateNo_Prime = receive.PlateNo_Prime; model.PlateNo_Trailer = receive.PlateNo_Trailer; model.TransporterID = receive.TransporterID; model.HubID = receive.HubID; ReceiveDetail receiveDetail = receive.ReceiveDetails.FirstOrDefault();//p=>p.QuantityInMT>0); Transaction receiveDetailtransaction = null; if (receiveDetail != null) { foreach (Transaction transaction in receiveDetail.TransactionGroup.Transactions) { var negTransaction = receiveDetail.TransactionGroup.Transactions.FirstOrDefault(p => p.QuantityInMT < 0); if (negTransaction != null) { model.SourceHubID = negTransaction.Account.EntityID; } receiveDetailtransaction = transaction; break; } } if (receiveDetailtransaction != null) { model.SINumber = receiveDetailtransaction.ShippingInstruction != null ? receiveDetailtransaction.ShippingInstruction.Value : ""; model.ProjectNumber = receiveDetailtransaction.ProjectCode != null ? receiveDetailtransaction.ProjectCode.Value : ""; model.ProgramID = receiveDetailtransaction.Program != null ? receiveDetailtransaction.Program.ProgramID : default(int); model.StoreID = receiveDetailtransaction.Store != null ? receiveDetailtransaction.Store.StoreID : default(int); model.StackNumber = receiveDetailtransaction.Stack.HasValue ? receiveDetailtransaction.Stack.Value : default(int); } else { model.SINumber = ""; model.ProjectNumber = ""; model.ProgramID = default(int); model.StoreID = default(int); model.StackNumber = default(int); } model.ReceiptDate = receive.ReceiptDate; model.WayBillNo = receive.WayBillNo; model.CommodityTypeID = receive.CommodityTypeID; model.ResponsibleDonorID = receive.ResponsibleDonorID; model.SourceDonorID = receive.SourceDonorID; model.CommoditySourceID = receive.CommoditySourceID; model.TicketNumber = receive.WeightBridgeTicketNumber; model.WeightBeforeUnloading = receive.WeightBeforeUnloading; model.WeightAfterUnloading = receive.WeightAfterUnloading; model.VesselName = receive.VesselName; model.PortName = receive.PortName; model.ReceiptAllocationID = receive.ReceiptAllocationID; model.PurchaseOrder = receive.PurchaseOrder; model.SupplierName = receive.SupplierName; model.Remark = receive.Remark; model.ReceivedByStoreMan = receive.ReceivedByStoreMan; model.ReceiveDetails = DRMFSS.Web.Models.ReceiveDetailViewModel.GenerateReceiveDetailModels(receive.ReceiveDetails); return(model); }
/// <summary> /// Updates the specified inserted. /// </summary> /// <param name="inserted">The inserted.</param> /// <param name="updated">The updated.</param> /// <param name="deleted">The deleted.</param> public void Update(List <BLL.ReceiveDetail> inserted, List <BLL.ReceiveDetail> updated, List <BLL.ReceiveDetail> deleted) { CTSContext db = new CTSContext(); BLL.Receive orginal = db.Receives.SingleOrDefault(p => p.ReceiveID == this.ReceiveID); if (orginal != null) { // CreatedDate = DateTime.Now, orginal.ReceiptDate = this.ReceiptDate; // orginal.ReceiveID = this.ReceiveID; orginal.DriverName = this.DriverName; orginal.GRN = this.GRN; orginal.PlateNo_Prime = this.PlateNo_Prime; orginal.PlateNo_Trailer = this.PlateNo_Trailer; //orginal.StackNumber = this.StackNumber; orginal.TransporterID = this.TransporterID; orginal.HubID = this.HubID; // orginal.SINumber = this.SINumber; //orginal.CommodityTypeID = this.CommodityTypeID; orginal.WayBillNo = this.WayBillNo; orginal.ResponsibleDonorID = this.ResponsibleDonorID; orginal.SourceDonorID = this.SourceDonorID; //orginal.ReceivedByStoreMan = this.ReceivedByStoreMan; //orginal.CommoditySourceID = this.CommoditySourceID; orginal.WeightBeforeUnloading = this.WeightBeforeUnloading; orginal.WeightAfterUnloading = this.WeightAfterUnloading; orginal.Remark = this.Remark; orginal.VesselName = this.VesselName; orginal.PortName = this.PortName; orginal.WeightBridgeTicketNumber = this.WeightBridgeTicketNumber; foreach (BLL.ReceiveDetail insert in inserted) { //TODO THIS should be in transaction //orginal.ReceiveDetails.Add(insert); } foreach (BLL.ReceiveDetail delete in deleted) { BLL.ReceiveDetail deletedCommodity = db.ReceiveDetails.SingleOrDefault(p => p.ReceiveDetailID == delete.ReceiveDetailID); if (deletedCommodity != null) { // db.ReceiveDetails.DeleteObject(deletedCommodity); } } foreach (BLL.ReceiveDetail update in updated) { BLL.ReceiveDetail updatedCommodity = db.ReceiveDetails.SingleOrDefault(p => p.ReceiveDetailID == update.ReceiveDetailID); if (updatedCommodity != null) { //updatedCommodity.CommodityID = update.CommodityID; updatedCommodity.Description = update.Description; //updatedCommodity.ReceiveDetailID = update.ReceiveDetailID; //updatedCommodity.SentQuantityInMT = update.SentQuantityInMT; //updatedCommodity.ReceivedQuantityInMT = updatedCommodity.ReceivedQuantityInMT; //updatedCommodity.SentQuantityInUnit = update.SentQuantityInUnit; //updatedCommodity.UnitID = update.UnitID; } } db.SaveChanges(); } }