コード例 #1
0
        public async Task UpdateOrderItem(UpdateOrderItem model, int corpClientId)
        {
            var item = await orderItemApp.Get(model.OrderItemId, corpClientId);

            var prod = await productApp.Get(corpClientId, model.ProductId);

            model.ProductPrice = item.ProductPrice;
            var units = await measureUnitApp.GetAll();

            var pType = units.FirstOrDefault(u => u.MeasureUnitId == prod.MeasureUnitId).MeasureUnitTypeId;
            var qType = units.FirstOrDefault(u => u.MeasureUnitId == model.MeasureUnitId).MeasureUnitTypeId;

            if (model.OrderItemStatusId == OrderItemStatusEnum.Cancelado)
            {
                model.Cost   = null;
                model.Profit = null;
            }
            else
            {
                await CalculateItem(model, prod.MeasureUnitId, pType, qType, corpClientId);
            }

            await orderItemApp.Update(model, corpClientId);

            var nextStatus = await GetNextOrderStatus(item.Order.OrderNumber, corpClientId);

            await orderApp.ChangeStatus(new UpdateOrderStatus
            {
                OrderNumber   = item.Order.OrderNumber,
                OrderStatusId = nextStatus
            }, corpClientId);
        }
コード例 #2
0
        public async Task <ProductionSummary> CalculateProduction(long productId, MeasureUnitEnum measureId, decimal quantity, int corpClientId)
        {
            var items     = new List <ProductionItem>();
            var dataSheet = await dataSheetApp.Get(productId, corpClientId);

            var units = await measureUnitApp.GetAll();

            var sourceUnit = units.FirstOrDefault(u => u.MeasureUnitId == measureId);
            var p          = await productApp.Get(corpClientId, productId);

            var pType = units.FirstOrDefault(u => u.MeasureUnitId == p.MeasureUnitId).MeasureUnitTypeId;
            var price = pricingApp.CalculatePricePerTotalWeight(new PriceRequest
            {
                ProductMeasureUnit  = p.MeasureUnitId,
                ProductPrice        = p.Price,
                Quantity            = quantity,
                QuantityMeasureUnit = measureId,
                ResultPrecision     = 2
            }, pType, sourceUnit.MeasureUnitTypeId);

            if (dataSheet == null)
            {
                return new ProductionSummary
                       {
                           SalePrice       = price,
                           ProductionItems = items
                       }
            }
            ;
            var q = Convert.ToDecimal(UnitConverter.ToBaseUnit(measureId, quantity, sourceUnit.MeasureUnitTypeId));

            foreach (var di in dataSheet.DataSheetItems)
            {
                var item = new ProductionItem
                {
                    AdditionalInfo  = di.AdditionalInfo,
                    DataSheetId     = di.DataSheetId,
                    DataSheetItemId = di.DataSheetItemId,
                    IsBaseItem      = di.IsBaseItem,
                    RawMaterial     = di.RawMaterial,
                    Percentage      = di.Percentage,
                    RawMaterialId   = di.RawMaterialId
                };

                if (dataSheet.IncreaseWeight)
                {
                    item.Quantity = q / (1 + (dataSheet.WeightVariationPercentage / 100)) * item.Percentage / 100;
                }
                else
                {
                    item.Quantity = q / (1 - (dataSheet.WeightVariationPercentage / 100)) * item.Percentage / 100;
                }

                var rmSourceUnit = units.FirstOrDefault(u => u.MeasureUnitId == di.RawMaterial.MeasureUnitId);
                var rmQuantity   = Convert.ToDecimal(UnitConverter.ToBaseUnit(rmSourceUnit.MeasureUnitId, 1, rmSourceUnit.MeasureUnitTypeId));
                var rmPrice      = di.RawMaterial.Price / rmQuantity;
                item.Cost = rmPrice * item.Quantity;

                switch (rmSourceUnit.MeasureUnitTypeId)
                {
                case MeasureUnitTypeEnum.Mass:
                    item.MeasureUnit = units.FirstOrDefault(u => u.MeasureUnitId == MeasureUnitEnum.Grama);
                    break;

                case MeasureUnitTypeEnum.Volume:
                    item.MeasureUnit = units.FirstOrDefault(u => u.MeasureUnitId == MeasureUnitEnum.Mililitro);
                    break;

                case MeasureUnitTypeEnum.Lenght:
                    break;

                default:
                    break;
                }
                items.Add(item);
            }
            return(new ProductionSummary
            {
                SalePrice = price,
                ProductionItems = items
            });
        }
    }
コード例 #3
0
 public IActionResult Get(string objectId = "59fbc96d5b407021f04f805e")
 {
     return(new ObjectResult(_service.Get(objectId)));
 }
コード例 #4
0
 public async Task <Product> Get(int corpClientId, int id)
 {
     return(await productApp.Get(corpClientId, id));
 }