Ejemplo n.º 1
0
        public decimal CalculatePricePerTotalWeight(PriceRequest model)
        {
            var m     = measureUnitApp.GetAll().Result;
            var pType = m.FirstOrDefault(m => m.MeasureUnitId == model.ProductMeasureUnit).MeasureUnitTypeId;
            var qType = m.FirstOrDefault(m => m.MeasureUnitId == model.QuantityMeasureUnit).MeasureUnitTypeId;

            return(pricingApp.CalculatePricePerTotalWeight(model, pType, qType));
        }
Ejemplo n.º 2
0
        private async Task CalculateItem(NewOrderItem item, MeasureUnitEnum prodMeasureUnit, MeasureUnitTypeEnum pType, MeasureUnitTypeEnum qType, int corpClientId)
        {
            item.OriginalPrice = pricingApp.CalculatePricePerTotalWeight(new PriceRequest
            {
                ProductMeasureUnit  = prodMeasureUnit,
                ProductPrice        = item.ProductPrice,
                Quantity            = item.Quantity,
                QuantityMeasureUnit = item.MeasureUnitId
            }, pType, qType);
            var prodSummary = await dataSheetService.CalculateProduction(item.ProductId, item.MeasureUnitId, item.Quantity, corpClientId);

            item.Cost   = prodSummary.ProductionItems.Any() ? prodSummary.ProductionCost : new decimal?();
            item.Profit = prodSummary.ProductionItems.Any() ? (item.PriceAfterDiscount - prodSummary.ProductionCost) : new decimal?();
        }
Ejemplo n.º 3
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
            });
        }
    }