Exemplo n.º 1
0
        /// <summary>
        /// Проводка накладной
        /// </summary>
        /// <param name="waybill"></param>
        public void Accept(WriteoffWaybill waybill, User user, DateTime currentDateTime)
        {
            // регулярная проверка - не появились ли РЦ для переоценки
            articleRevaluationService.CheckAccountingPriceListWithoutCalculatedRevaluation(currentDateTime);

            CheckPossibilityToAccept(waybill, user);

            // получение текущих позиций реестров цен
            var senderPriceLists = articlePriceService.GetArticleAccountingPrices(waybill.SenderStorage.Id,
                                                                                  writeoffWaybillRepository.GetArticlesSubquery(waybill.Id), currentDateTime);

            // проводим накладную
            waybill.Accept(senderPriceLists, UseReadyToAcceptState, user, currentDateTime);

            // резервирование товаров при проводке
            var reservationInfoList = articleMovementService.AcceptArticles(waybill);

            // Пересчет показателей исходящего проведенного наличия
            articleAvailabilityService.WriteoffWaybillAccepted(waybill, reservationInfoList);
        }
Exemplo n.º 2
0
        public WriteoffWaybillMainIndicators GetMainIndicators(WriteoffWaybill waybill, User user, bool calculateReceivelessProfit = false)
        {
            var ind = new WriteoffWaybillMainIndicators();

            var allowToViewPurchaseCost = user.HasPermission(Permission.PurchaseCost_View_ForEverywhere);
            var allowToViewAccPrice     = user.HasPermissionToViewStorageAccountingPrices(waybill.SenderStorage);

            if (waybill.IsAccepted)
            {
                ind.SenderAccountingPriceSum = allowToViewAccPrice ? waybill.SenderAccountingPriceSum : (decimal?)null;

                if (calculateReceivelessProfit)
                {
                    ind.ReceivelessProfitSum     = allowToViewPurchaseCost && allowToViewAccPrice ? waybill.ReceivelessProfitSum : (decimal?)null;
                    ind.ReceivelessProfitPercent = allowToViewPurchaseCost && allowToViewAccPrice ? waybill.ReceivelessProfitPercent : (decimal?)null;
                }
            }
            else
            {
                var storage         = waybill.SenderStorage;
                var purchaseCostSum = allowToViewPurchaseCost ? waybill.PurchaseCostSum : (decimal?)null;

                ind.SenderAccountingPriceSum = allowToViewAccPrice ? (decimal?)0 : null;

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

                if (allowToViewAccPrice)
                {
                    senderAccountingPrices = articlePriceService.GetAccountingPrice(storage.Id, writeoffWaybillRepository.GetArticlesSubquery(waybill.Id));
                }

                foreach (var row in waybill.Rows)
                {
                    if (allowToViewAccPrice)
                    {
                        var senderAccountingPrice = senderAccountingPrices[row.Article.Id];

                        ind.SenderAccountingPriceSum += senderAccountingPrice.Value * row.WritingoffCount;
                    }
                }

                if (allowToViewAccPrice)
                {
                    ind.SenderAccountingPriceSum = Math.Round(ind.SenderAccountingPriceSum.Value, 2);
                }

                if (calculateReceivelessProfit)
                {
                    if (allowToViewAccPrice && allowToViewPurchaseCost)
                    {
                        ind.ReceivelessProfitSum     = ind.SenderAccountingPriceSum.Value - purchaseCostSum;
                        ind.ReceivelessProfitPercent = purchaseCostSum != 0M ? ind.ReceivelessProfitSum / purchaseCostSum * 100M : 0M;
                    }
                    else
                    {
                        ind.ReceivelessProfitPercent = null;
                        ind.ReceivelessProfitSum     = null;
                    }
                }
            }

            return(ind);
        }