コード例 #1
0
        public ChangeOwnerWaybillMainIndicators GetMainIndicators(ChangeOwnerWaybill waybill, User user, bool calculateValueAddedTaxes = false)
        {
            var indicators = new ChangeOwnerWaybillMainIndicators();

            var allowToViewAccPrices = user.HasPermissionToViewStorageAccountingPrices(waybill.Storage);

            if (!allowToViewAccPrices)
            {
                indicators.AccountingPriceSum = null;

                if (calculateValueAddedTaxes)
                {
                    var emptyLookup = new Dictionary <decimal, decimal>().ToLookup(x => x.Value, x => x.Value);
                    indicators.VatInfoList = emptyLookup;
                }
            }
            else
            {
                if (waybill.IsAccepted)
                {
                    indicators.AccountingPriceSum = waybill.AccountingPriceSum;

                    if (calculateValueAddedTaxes)
                    {
                        indicators.VatInfoList = waybill.Rows.ToLookup(x => x.ValueAddedTax.Value, x => x.ValueAddedTaxSum);
                    }
                }
                else
                {
                    var articleSubQuery  = changeOwnerWaybillRepository.GetArticlesSubquery(waybill.Id);
                    var accountingPrices = articlePriceService.GetAccountingPrice(waybill.Storage.Id, articleSubQuery);

                    var valueAddedTaxList = new Dictionary <ChangeOwnerWaybillRow, decimal>();
                    indicators.AccountingPriceSum = 0M;

                    foreach (var row in waybill.Rows)
                    {
                        var accountingPrice = accountingPrices[row.Article.Id];

                        if (accountingPrice.HasValue)
                        {
                            var accountingPricePartialSum = accountingPrice.Value * row.MovingCount;
                            indicators.AccountingPriceSum += accountingPricePartialSum;

                            if (calculateValueAddedTaxes)
                            {
                                valueAddedTaxList.Add(row, VatUtils.CalculateVatSum(accountingPricePartialSum, row.ValueAddedTax.Value));
                            }
                        }
                    }

                    if (calculateValueAddedTaxes)
                    {
                        indicators.VatInfoList = valueAddedTaxList.ToLookup(x => x.Key.ValueAddedTax.Value, x => x.Value);
                    }
                }
            }

            return(indicators);
        }
コード例 #2
0
        private IDictionary <Guid, ChangeOwnerWaybillRowMainIndicators> GetMainIndicatorsForRowList(ChangeOwnerWaybill waybill, IEnumerable <ChangeOwnerWaybillRow> rowsToGetIndicators,
                                                                                                    ISubQuery rowsToGetIndicatorsArticleSubquery, User user, bool calculateValueAddedTaxSum)
        {
            var result = new Dictionary <Guid, ChangeOwnerWaybillRowMainIndicators>();

            var allowToViewAccPrice = user.HasPermissionToViewStorageAccountingPrices(waybill.Storage);

            var accountingPrices = new DynamicDictionary <int, decimal?>();

            if (allowToViewAccPrice && !waybill.IsAccepted)
            {
                accountingPrices = articlePriceService.GetAccountingPrice(waybill.Storage.Id, rowsToGetIndicatorsArticleSubquery);
            }

            foreach (var row in rowsToGetIndicators)
            {
                var ind = new ChangeOwnerWaybillRowMainIndicators();

                if (allowToViewAccPrice)
                {
                    if (waybill.IsAccepted)
                    {
                        ind.AccountingPrice = row.ArticleAccountingPrice.AccountingPrice;

                        if (calculateValueAddedTaxSum)
                        {
                            ind.ValueAddedTaxSum = row.ValueAddedTaxSum;
                        }
                    }
                    else
                    {
                        ind.AccountingPrice = accountingPrices[row.Article.Id];

                        if (calculateValueAddedTaxSum)
                        {
                            ind.ValueAddedTaxSum = VatUtils.CalculateVatSum(ind.AccountingPrice * row.MovingCount, row.ValueAddedTax.Value);
                        }
                    }
                }
                else
                {
                    ind.AccountingPrice  = (decimal?)null;
                    ind.ValueAddedTaxSum = (decimal?)null;
                }

                result.Add(row.Id, ind);
            }

            return(result);
        }
コード例 #3
0
        /// <summary>
        /// Расчет основных показателей накладной
        /// </summary>
        public ExpenditureWaybillMainIndicators CalculateMainIndicators(ExpenditureWaybill waybill, bool calculateSenderAccountingPriceSum = false,
                                                                        bool calculateSalePriceSum     = false, bool calculatePaymentSum    = false, bool calculatePaymentPercent = false, bool calculateDebtRemainder = false,
                                                                        bool calculateVatInfoList      = false, bool calculateTotalDiscount = false, bool calculateProfit         = false, bool calculateLostProfit    = false,
                                                                        bool calculateTotalReturnedSum = false, bool calculateTotalReservedByReturnSum = false)
        {
            var result = new ExpenditureWaybillMainIndicators();

            decimal senderAccountingPriceSum = 0M, salePriceSum = 0M;

            if (!waybill.IsAccepted)
            {
                var valueAddedTaxList = new Dictionary <ExpenditureWaybillRow, decimal>();
                var accountingPrices  = new DynamicDictionary <int, decimal?>();

                if (calculateSenderAccountingPriceSum || calculateSalePriceSum || calculateProfit || calculatePaymentPercent || calculateTotalDiscount || calculateVatInfoList)
                {
                    if (calculateSenderAccountingPriceSum || calculateSalePriceSum || calculateProfit || calculatePaymentPercent || calculateTotalDiscount)
                    {
                        var articleSubQuery = expenditureWaybillRepository.GetArticlesSubquery(waybill.Id);
                        accountingPrices = articlePriceService.GetAccountingPrice(waybill.SenderStorage.Id, articleSubQuery);
                    }

                    foreach (var row in waybill.Rows)
                    {
                        var expenditureWaybillRow = row.As <ExpenditureWaybillRow>();

                        var accountingPrice = (accountingPrices[expenditureWaybillRow.Article.Id] ?? 0);
                        senderAccountingPriceSum += Math.Round(accountingPrice * row.SellingCount, 2);

                        var rowSalePriceSum = expenditureWaybillRow.CalculateSalePrice(accountingPrice) * row.SellingCount;
                        salePriceSum += rowSalePriceSum;

                        if (calculateVatInfoList)
                        {
                            var rowValueAddedTaxSum = VatUtils.CalculateVatSum(rowSalePriceSum, row.ValueAddedTax.Value);
                            valueAddedTaxList.Add(expenditureWaybillRow, Math.Round(rowValueAddedTaxSum, 2));
                        }
                    }

                    if (calculateSenderAccountingPriceSum)
                    {
                        result.SenderAccountingPriceSum = senderAccountingPriceSum;
                    }

                    if (calculateSalePriceSum || calculateProfit || calculatePaymentPercent)
                    {
                        result.SalePriceSum = salePriceSum;
                    }

                    if (calculateTotalDiscount)
                    {
                        result.TotalDiscountPercent = senderAccountingPriceSum == 0 ? 0 : Math.Round(((senderAccountingPriceSum - salePriceSum) / senderAccountingPriceSum) * 100, 2);
                        result.TotalDiscountSum     = senderAccountingPriceSum - salePriceSum;
                    }

                    if (calculateVatInfoList)
                    {
                        result.VatInfoList = valueAddedTaxList.ToLookup(x => x.Key.ValueAddedTax.Value, x => x.Value);
                    }
                }
            }
            else
            {
                if (calculateSenderAccountingPriceSum)
                {
                    result.SenderAccountingPriceSum = senderAccountingPriceSum = waybill.SenderAccountingPriceSum;
                }

                if (calculateSalePriceSum || calculateProfit || calculatePaymentPercent)
                {
                    result.SalePriceSum = salePriceSum = waybill.SalePriceSum;
                }

                if (calculateTotalDiscount)
                {
                    result.TotalDiscountPercent = waybill.TotalDiscountPercent;
                    result.TotalDiscountSum     = waybill.TotalDiscountSum;
                }

                if (calculateVatInfoList)
                {
                    result.VatInfoList = waybill.Rows.ToLookup(x => x.ValueAddedTax.Value, x => x.ValueAddedTaxSum);
                }
            }

            if (calculateProfit)
            {
                var purchaseCostSum = waybill.PurchaseCostSum;
                result.ProfitPercent = (purchaseCostSum != 0M ? Math.Round((salePriceSum - purchaseCostSum) / purchaseCostSum * 100M, 2) : 0M);
                result.ProfitSum     = salePriceSum - purchaseCostSum;
            }

            if (calculateDebtRemainder)
            {
                result.DebtRemainder = CalculateDebtRemainder(waybill);
            }

            if (calculatePaymentSum || calculatePaymentPercent)
            {
                var paymentSum = CalculatePaymentSum(waybill);

                if (calculatePaymentSum)
                {
                    result.PaymentSum = paymentSum;
                }

                if (calculatePaymentPercent)
                {
                    var calcWaybillCost = salePriceSum - GetTotalReturnedSumForSaleWaybill(waybill);    // Расчет общей суммы необходимой оплаты по накладной
                    // Проверяем ее на ноль, т.к. идет деление на эту величину.
                    result.PaymentPercent = (salePriceSum != 0M && calcWaybillCost != 0M) ? Math.Round(paymentSum / calcWaybillCost * 100M, 2) : 0M;
                }
            }

            if (calculateLostProfit)
            {
                var reservedByReturnLostProfitSum = waybill.Rows.Select(x => (x.SalePrice - x.PurchaseCost) * x.ReservedByReturnCount).Sum() ?? 0;
                var returnLostProfitSum           = waybill.Rows.Select(x => (x.SalePrice - x.PurchaseCost) * x.ReceiptedReturnCount).Sum() ?? 0;

                result.ReturnLostProfitSum           = returnLostProfitSum;
                result.ReservedByReturnLostProfitSum = reservedByReturnLostProfitSum;
            }

            if (calculateTotalReturnedSum)
            {
                result.TotalReturnedSum = GetTotalReturnedSumForSaleWaybill(waybill);
            }

            if (calculateTotalReservedByReturnSum)
            {
                result.TotalReservedByReturnSum = GetTotalReservedByReturnSumForSaleWaybill(waybill);
            }

            return(result);
        }
コード例 #4
0
        /// <summary>
        /// Расчет основных показателей для позиции накладной
        /// </summary>
        private IDictionary <Guid, ExpenditureWaybillRowMainIndicators> GetMainIndicatorsForRowList(ExpenditureWaybill waybill, IEnumerable <ExpenditureWaybillRow> rowsToGetIndicators,
                                                                                                    ISubQuery rowsToGetIndicatorsArticleSubquery, bool allowToViewAccPrices = true, bool calculateSalePrice = false, bool calculateValueAddedTaxSum = false)
        {
            var result = new Dictionary <Guid, ExpenditureWaybillRowMainIndicators>();

            var accountingPrices = new DynamicDictionary <int, decimal?>();

            if (!waybill.IsAccepted)
            {
                accountingPrices = articlePriceService.GetAccountingPrice(waybill.SenderStorage.Id, rowsToGetIndicatorsArticleSubquery);
            }

            foreach (var row in rowsToGetIndicators)
            {
                var ind = new ExpenditureWaybillRowMainIndicators();

                if (waybill.IsAccepted)
                {
                    ind.SenderAccountingPrice = allowToViewAccPrices ? row.SenderArticleAccountingPrice.AccountingPrice : (decimal?)null;

                    if (calculateSalePrice)
                    {
                        ind.SalePrice = row.SalePrice.Value;
                    }

                    if (calculateValueAddedTaxSum)
                    {
                        ind.ValueAddedTaxSum = row.ValueAddedTaxSum;
                    }
                }
                else
                {
                    var senderAccountingPrice = accountingPrices[row.Article.Id];

                    if (senderAccountingPrice != null)
                    {
                        senderAccountingPrice = Math.Round(senderAccountingPrice.Value, 2);

                        ind.SenderAccountingPrice = allowToViewAccPrices ? senderAccountingPrice : (decimal?)null;

                        if (calculateSalePrice || calculateValueAddedTaxSum)
                        {
                            var salePrice = row.CalculateSalePrice(senderAccountingPrice.Value);

                            if (calculateSalePrice)
                            {
                                ind.SalePrice = salePrice;
                            }

                            if (calculateValueAddedTaxSum)
                            {
                                ind.ValueAddedTaxSum = VatUtils.CalculateVatSum(salePrice * row.SellingCount, row.ValueAddedTax.Value);
                            }
                        }
                    }
                    else
                    {
                        ind.SenderAccountingPrice = null;

                        if (calculateSalePrice)
                        {
                            ind.SalePrice = null;
                        }

                        if (calculateValueAddedTaxSum)
                        {
                            ind.ValueAddedTaxSum = null;
                        }
                    }
                }

                result.Add(row.Id, ind);
            }

            return(result);
        }
コード例 #5
0
        public MovementWaybillMainIndicators GetMainIndicators(MovementWaybill waybill, User user, bool calculateMarkups = false, bool calculateValueAddedTaxSums = false)
        {
            var ind = new MovementWaybillMainIndicators();

            var allowToViewRecipientAccPrices = user.HasPermissionToViewStorageAccountingPrices(waybill.RecipientStorage);
            var allowToViewSenderAccPrices    = user.HasPermissionToViewStorageAccountingPrices(waybill.SenderStorage);
            var allowToViewBothAccPrices      = allowToViewRecipientAccPrices && allowToViewSenderAccPrices;

            var emptyLookup = new Dictionary <decimal, decimal>().ToLookup(x => x.Value, x => x.Value);

            if (waybill.IsAccepted)
            {
                ind.SenderAccountingPriceSum    = allowToViewSenderAccPrices ? (decimal?)waybill.SenderAccountingPriceSum.Value : null;
                ind.RecipientAccountingPriceSum = allowToViewRecipientAccPrices ? (decimal?)waybill.RecipientAccountingPriceSum.Value : null;

                if (calculateMarkups)
                {
                    ind.MovementMarkupPercent = allowToViewBothAccPrices ? (decimal?)waybill.MovementMarkupPercent : null;
                    ind.MovementMarkupSum     = allowToViewBothAccPrices ? (decimal?)waybill.MovementMarkupSum : null;
                }

                if (calculateValueAddedTaxSums)
                {
                    ind.SenderVatInfoList    = allowToViewSenderAccPrices ? waybill.Rows.ToLookup(x => x.ValueAddedTax.Value, x => x.SenderValueAddedTaxSum) : emptyLookup;
                    ind.RecipientVatInfoList = allowToViewRecipientAccPrices ? waybill.Rows.ToLookup(x => x.ValueAddedTax.Value, x => x.RecipientValueAddedTaxSum) : emptyLookup;
                }
            }
            else
            {
                var storageList = new List <short>();

                if (allowToViewRecipientAccPrices)
                {
                    storageList.Add(waybill.RecipientStorage.Id);
                }
                if (allowToViewSenderAccPrices)
                {
                    storageList.Add(waybill.SenderStorage.Id);
                }

                if (storageList.Count == 0)
                {
                    storageList.Add(0);
                }

                var articleSubQuery = movementWaybillRepository.GetArticlesSubquery(waybill.Id);

                var accountingPrices = articlePriceService.GetAccountingPrice(storageList, articleSubQuery);

                ind.SenderAccountingPriceSum    = allowToViewSenderAccPrices ? (decimal?)0 : null;
                ind.RecipientAccountingPriceSum = allowToViewRecipientAccPrices ? (decimal?)0 : null;
                var senderValueAddedTaxList    = new Dictionary <MovementWaybillRow, decimal>();
                var recipientValueAddedTaxList = new Dictionary <MovementWaybillRow, decimal>();

                foreach (var row in waybill.Rows)
                {
                    if (allowToViewSenderAccPrices)
                    {
                        var senderAccountingPrice = (accountingPrices[waybill.SenderStorage.Id][row.Article.Id] ?? 0);

                        ind.SenderAccountingPriceSum += senderAccountingPrice * row.MovingCount;

                        senderValueAddedTaxList.Add(row, VatUtils.CalculateVatSum(senderAccountingPrice * row.MovingCount, row.ValueAddedTax.Value));
                    }

                    if (allowToViewRecipientAccPrices)
                    {
                        var recipientAccountingPrice = (accountingPrices[waybill.RecipientStorage.Id][row.Article.Id] ?? 0);

                        ind.RecipientAccountingPriceSum += recipientAccountingPrice * row.MovingCount;

                        recipientValueAddedTaxList.Add(row, VatUtils.CalculateVatSum(recipientAccountingPrice * row.MovingCount, row.ValueAddedTax.Value));
                    }
                }

                if (calculateMarkups)
                {
                    ind.MovementMarkupPercent = allowToViewBothAccPrices && ind.SenderAccountingPriceSum != 0M ?
                                                Math.Round((ind.RecipientAccountingPriceSum.Value - ind.SenderAccountingPriceSum.Value) / ind.SenderAccountingPriceSum.Value * 100M, 2) : (decimal?)null;

                    ind.MovementMarkupSum = allowToViewBothAccPrices ? ind.RecipientAccountingPriceSum - ind.SenderAccountingPriceSum : (decimal?)null;
                }

                if (calculateValueAddedTaxSums)
                {
                    ind.SenderVatInfoList    = senderValueAddedTaxList.ToLookup(x => x.Key.ValueAddedTax.Value, x => x.Value);
                    ind.RecipientVatInfoList = recipientValueAddedTaxList.ToLookup(x => x.Key.ValueAddedTax.Value, x => x.Value);
                }
            }

            return(ind);
        }
コード例 #6
0
        /// <summary>
        /// Расчет основных показателей для коллекции позиций накладной перемещения
        /// </summary>
        /// <param name="rowsToGetIndicators">Список позиций накладной, для которых необходимо расчитать показатели</param>
        /// <param name="rowsToGetIndicatorsArticleSubquery">Подзапрос для товаров из позиций накладной, для которых необходимо расчитать показатели</param>
        private IDictionary <Guid, MovementWaybillRowMainIndicators> GetMainIndicatorsForRowList(MovementWaybill waybill, IEnumerable <MovementWaybillRow> rowsToGetIndicators,
                                                                                                 ISubQuery rowsToGetIndicatorsArticleSubquery, User user, bool calculateValueAddedTaxSums, bool calculateMarkups)
        {
            var result = new Dictionary <Guid, MovementWaybillRowMainIndicators>();

            var allowToViewRecipientAccPrices = user.HasPermissionToViewStorageAccountingPrices(waybill.RecipientStorage);
            var allowToViewSenderAccPrices    = user.HasPermissionToViewStorageAccountingPrices(waybill.SenderStorage);

            // список УЦ для переданных позиций
            var accountingPrices = new DynamicDictionary <short, DynamicDictionary <int, decimal?> >();

            if (!waybill.IsAccepted)
            {
                // формируем список МХ, с которых можно просматривать УЦ
                var storageList = new List <short>();

                if (allowToViewRecipientAccPrices)
                {
                    storageList.Add(waybill.RecipientStorage.Id);
                }
                if (allowToViewSenderAccPrices)
                {
                    storageList.Add(waybill.SenderStorage.Id);
                }
                if (storageList.Count == 0)
                {
                    storageList.Add(0);
                }

                // получаем список УЦ для указанных позиций
                accountingPrices = articlePriceService.GetAccountingPrice(storageList, rowsToGetIndicatorsArticleSubquery);
            }

            foreach (var row in rowsToGetIndicators)
            {
                var ind = new MovementWaybillRowMainIndicators();

                if (waybill.IsAccepted)
                {
                    ind.SenderAccountingPrice    = allowToViewSenderAccPrices ? row.SenderArticleAccountingPrice.AccountingPrice : (decimal?)null;
                    ind.RecipientAccountingPrice = allowToViewRecipientAccPrices ? row.RecipientArticleAccountingPrice.AccountingPrice : (decimal?)null;

                    if (calculateValueAddedTaxSums)
                    {
                        ind.SenderValueAddedTaxSum    = allowToViewSenderAccPrices ? row.SenderValueAddedTaxSum : (decimal?)null;
                        ind.RecipientValueAddedTaxSum = allowToViewRecipientAccPrices ? row.RecipientValueAddedTaxSum : (decimal?)null;
                    }
                }
                else
                {
                    ind.SenderAccountingPrice    = allowToViewSenderAccPrices ? accountingPrices[waybill.SenderStorage.Id][row.Article.Id] : (decimal?)null;
                    ind.RecipientAccountingPrice = allowToViewRecipientAccPrices ? accountingPrices[waybill.RecipientStorage.Id][row.Article.Id] : (decimal?)null;

                    if (calculateValueAddedTaxSums)
                    {
                        ind.SenderValueAddedTaxSum = allowToViewSenderAccPrices ?
                                                     VatUtils.CalculateVatSum(ind.SenderAccountingPrice * row.MovingCount, row.ValueAddedTax.Value) : (decimal?)null;
                        ind.RecipientValueAddedTaxSum = allowToViewRecipientAccPrices ?
                                                        VatUtils.CalculateVatSum(ind.RecipientAccountingPrice * row.MovingCount, row.ValueAddedTax.Value) : (decimal?)null;
                    }
                }

                if (calculateMarkups)
                {
                    decimal purchaseCost = row.ReceiptWaybillRow.PurchaseCost;

                    ind.MovementMarkupSum = ind.SenderAccountingPrice.HasValue && ind.RecipientAccountingPrice.HasValue ?
                                            Math.Round(ind.RecipientAccountingPrice.Value - ind.SenderAccountingPrice.Value, 2) : (decimal?)null;
                    ind.MovementMarkupPercent = ind.MovementMarkupSum.HasValue && ind.SenderAccountingPrice.HasValue && ind.SenderAccountingPrice != 0M ?
                                                Math.Round(ind.MovementMarkupSum.Value / ind.SenderAccountingPrice.Value * 100M, 2) : (decimal?)null;

                    ind.PurchaseMarkupSum     = ind.RecipientAccountingPrice.HasValue ? Math.Round(ind.RecipientAccountingPrice.Value - purchaseCost, 2) : (decimal?)null;
                    ind.PurchaseMarkupPercent = ind.PurchaseMarkupSum.HasValue && purchaseCost != 0M ?
                                                Math.Round(ind.PurchaseMarkupSum.Value / purchaseCost * 100M, 2) : (decimal?)null;
                }

                result.Add(row.Id, ind);
            }

            return(result);
        }