/// <summary> /// Generates the receive model. /// </summary> /// <param name="receive">The receive.</param> /// <param name="user">The user.</param> /// <returns></returns> public static ReceiveViewModel GenerateReceiveModel(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,List<Unit> units ) { ReceiveViewModel model = new ReceiveViewModel(); model._UserProfile = user; model.InitalizeViewModel(commodities, commodityGrades, transporters, commodityTypes, commoditySources, programs, donors, hubs, user,units); 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 =Cats.Models.Hubs.ReceiveDetailViewModel.GenerateReceiveDetailModels(receive.ReceiveDetails); return model; }
/// <summary> /// Generates the receive model. /// </summary> /// <param name="receive">The receive.</param> /// <param name="user">The user.</param> /// <returns></returns> public static ReceiveViewModel GenerateReceiveModel(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, List <Unit> units) { ReceiveViewModel model = new ReceiveViewModel(); model._UserProfile = user; model.InitalizeViewModel(commodities, commodityGrades, transporters, commodityTypes, commoditySources, programs, donors, hubs, user, units); 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 = Cats.Models.Hubs.ReceiveDetailViewModel.GenerateReceiveDetailModels(receive.ReceiveDetails); return(model); }