public async Task <List <ShipmentDetail> > GetShipmentDetailBySalesOrder(ShipmentView shipmentView)
        {
            try
            {
                IList <SalesOrderDetail> query = await _unitOfWork.salesOrderDetailRepository.GetEntitiesBySalesOrderId(shipmentView.SalesOrderId ?? 0);


                List <ShipmentDetail> list = new List <ShipmentDetail>();

                foreach (var item in query)

                {
                    ItemMaster itemMaster = await _unitOfWork.itemMasterRepository.GetEntityById(item.ItemId);

                    NextNumber nnShipmentDetail = await _unitOfWork.nextNumberRepository.GetNextNumber(TypeOfShipmentDetail.ShipmentsDetailNumber.ToString());

                    ShipmentDetail shipmentDetail = new ShipmentDetail()

                    {
                        ShipmentDetailNumber = nnShipmentDetail.NextNumberValue,
                        ItemId             = item.ItemId,
                        Quantity           = item.Quantity ?? 0,
                        Amount             = item.Amount,
                        SalesOrderDetailId = item.SalesOrderDetailId,
                        QuantityShipped    = item.QuantityShipped ?? 0,
                        AmountShipped      = item.Amount,
                        ShippedDate        = shipmentView.ShipmentDate,
                        Note                = "",
                        UnitPrice           = itemMaster.UnitPrice,
                        Weight              = itemMaster.Weight ?? 0,
                        WeightUnitOfMeasure = itemMaster.WeightUnitOfMeasure,
                        Volume              = itemMaster.Volume ?? 0,
                        VolumeUnitOfMeasure = itemMaster.VolumeUnitOfMeasure
                    };

                    ItemsAdjustedQuantityShippedStruct shipmentAdjustment = shipmentView.ItemsAdjustedQuantityShipped.Where(e => e.SalesOrderDetailId == item.SalesOrderDetailId).FirstOrDefault();

                    if (shipmentAdjustment.AdjustedQuantityShipped != 0)

                    {
                        shipmentDetail.QuantityShipped = shipmentAdjustment.AdjustedQuantityShipped;
                        shipmentDetail.AmountShipped   = shipmentAdjustment.AdjustedAmountShipped;
                    }

                    list.Add(shipmentDetail);
                }

                await Task.Yield();

                return(list);
            }

            catch (Exception ex)

            {
                throw new Exception("GetShipmentDetailBySalesOrder", ex);
            }
        }
示例#2
0
        public IFluentShipmentDetail CreateShipmentsDetailBySalesOrderView(ShipmentView shipmentCreation)
        {
            try
            {
                var query = unitOfWork.salesOrderDetailRepository.GetIQueryableEntitiesBySalesOrderId(shipmentCreation.SalesOrderId ?? 0);



                List <ShipmentDetail> list = new List <ShipmentDetail>();
                foreach (var item in query)
                {
                    Task <ItemMaster> itemMasterTask       = Task.Run(async() => await unitOfWork.itemMasterRepository.GetEntityById(item.ItemId));
                    Task <NextNumber> nnShipmentDetailTask = Task.Run(async() => await unitOfWork.nextNumberRepository.GetNextNumber(TypeOfShipmentDetail.ShipmentsDetailNumber.ToString()));
                    Task.WaitAll(itemMasterTask, nnShipmentDetailTask);

                    ShipmentDetail shipmentsDetail = new ShipmentDetail()
                    {
                        ShipmentDetailNumber = nnShipmentDetailTask.Result.NextNumberValue,
                        ItemId             = item.ItemId,
                        Quantity           = item.Quantity ?? 0,
                        Amount             = item.Amount,
                        SalesOrderDetailId = item.SalesOrderDetailId,
                        QuantityShipped    = item.QuantityShipped ?? 0,
                        AmountShipped      = item.Amount,
                        ShippedDate        = shipmentCreation.ShipmentDate,
                        Note                = "",
                        UnitPrice           = itemMasterTask.Result.UnitPrice,
                        Weight              = itemMasterTask.Result.Weight ?? 0,
                        WeightUnitOfMeasure = itemMasterTask.Result.WeightUnitOfMeasure,
                        Volume              = itemMasterTask.Result.Volume ?? 0,
                        VolumeUnitOfMeasure = itemMasterTask.Result.VolumeUnitOfMeasure
                    };
                    ItemsAdjustedQuantityShippedStruct shipmentAdjustment = shipmentCreation.ItemsAdjustedQuantityShipped.Where(e => e.SalesOrderDetailId == item.SalesOrderDetailId).FirstOrDefault();
                    if (shipmentAdjustment.AdjustedQuantityShipped != 0)
                    {
                        shipmentsDetail.QuantityShipped = shipmentAdjustment.AdjustedQuantityShipped;
                        shipmentsDetail.AmountShipped   = shipmentAdjustment.AdjustedAmountShipped;
                    }
                    list.Add(shipmentsDetail);
                }
                AddShipmentDetails(list);
                return(this as IFluentShipmentDetail);
            }
            catch (Exception ex)
            {
                throw new Exception("CreateShipmentsDetailBySalesOrderView", ex);
            }
        }