Esempio n. 1
0
        public void MovementWaybill_If_Date_Is_Today_Hours_Minutes_Seconds_Must_Not_Be_0()
        {
            var movementWaybill = new MovementWaybill("123", DateTime.Today, storageA, senderOrganizationA, storageB, senderOrganizationB, valueAddedTax, user, user, DateTime.Now)
            {
                Id = Guid.NewGuid()
            };

            Assert.AreEqual(0.ToString(), (movementWaybill.Date.Hour + movementWaybill.Date.Minute + movementWaybill.Date.Hour).ToString());
        }
Esempio n. 2
0
        //[TestMethod]
        //public void MovementWaybill_If_OutcomingWaybill_Exist_Row_Cannot_Be_Deleted()
        //{
        //    var accPriceA_sender = new ArticleAccountingPrice(articleA, 50);
        //    var accPriceB_sender = new ArticleAccountingPrice(articleB, 60);
        //    var accPriceB_recipient = new ArticleAccountingPrice(articleB, 70);
        //    var accPriceC_recipient = new ArticleAccountingPrice(articleC, 80);

        //    var senderPriceLists = new List<ArticleAccountingPrice> { accPriceA_sender, accPriceB_sender };
        //    var recipientPriceLists = new List<ArticleAccountingPrice> { accPriceB_recipient, accPriceC_recipient };

        //    var movementWaybill = new MovementWaybill("123", DateTime.Now, storageA, senderOrganizationA, storageB, senderOrganizationB);
        //    movementWaybill.AddRow(rowA1_1);

        //    Provider provider;
        //    provider = new Provider("Тестовый поставщик", new ProviderType("Тестовый тип поставщика"), ProviderReliability.Medium);
        //    provider.AddOrganization(senderOrganizationA.Organization);

        //    var receiptWaybill = new ReceiptWaybill("321", DateTime.Now, storageA, senderOrganizationA, provider, 5000, new ValueAddedTax("10%", 10));
        //    receiptWaybill.AddRow(rowA1_1.ReceiptWaybillRow);
        //    rowA1_1.ReceiptWaybillRow.PendingSum = 5000;
        //    receiptWaybill.Receipt(5000, 500, new List<ArticleAccountingPrice>());

        //    movementWaybill.DeleteRow(rowA1_1);

        //    movementWaybill.AddRow(rowB);
        //    movementWaybill.AddRow(rowC);

        //    movementWaybill.SetAsReadyToShip();
        //    movementWaybill.Ship(100M, 100M, 100M, senderPriceLists, recipientPriceLists);
        //    movementWaybill.CancelShipping();

        //    Assert.IsNull(rowA1_1.SenderArticleAccountingPrice);
        //    Assert.IsNull(rowB.SenderArticleAccountingPrice);
        //    Assert.IsNull(rowC.SenderArticleAccountingPrice);

        //    Assert.IsNull(rowA1_1.RecipientArticleAccountingPrice);
        //    Assert.IsNull(rowB.RecipientArticleAccountingPrice);
        //    Assert.IsNull(rowC.RecipientArticleAccountingPrice);

        //}

        private MovementWaybill InitMovementWaybill()
        {
            MovementWaybill waybill = new MovementWaybill(numberA, DateTime.Now, storageA, senderOrganizationA,
                                                          storageB, receiverOrganizationC, valueAddedTax, user, user, DateTime.Now);
            var receiptWaybillRow = new ReceiptWaybillRow(articleA, 300, 3000, valueAddedTax);
            var row = new MovementWaybillRow(receiptWaybillRow, 10, valueAddedTax);

            waybill.AddRow(row);

            return(waybill);
        }
Esempio n. 3
0
 public void MovementWaybill_Creation_Must_Throw_Exception_If_SenderStorage_Equals_RecipientStorage()
 {
     try
     {
         var waybill = new MovementWaybill("123", DateTime.Now, storageA, senderOrganizationA, storageA, senderOrganizationB, valueAddedTax, user, user, DateTime.Now);
         Assert.Fail("Исключение не вызвано.");
     }
     catch (Exception ex)
     {
         Assert.AreEqual("Места хранения отправителя и получателя не могут совпадать.", ex.Message);
     }
 }
Esempio n. 4
0
        public void MovementWaybill_PrepareToAccept_Must_Throw_Exception()
        {
            try
            {
                MovementWaybill waybill = new MovementWaybill(numberA, DateTime.Now, storageA, senderOrganizationA,
                                                              storageB, receiverOrganizationC, valueAddedTax, user, user, DateTime.Now);

                waybill.PrepareToAccept();
            }
            catch (Exception ex)
            {
                Assert.AreEqual("Невозможно подготовить к проводке накладную, не содержащую ни одной позиции.", ex.Message);
            }
        }
Esempio n. 5
0
        public void MovementWaybill_Must_Throw_Exception_On_Setting_RecipientStorage_To_Null()
        {
            var waybill = new MovementWaybill("123", DateTime.Now, storageA, senderOrganizationA, storageB, senderOrganizationB, valueAddedTax, user, user, DateTime.Now);

            try
            {
                waybill.RecipientStorage = null;
                Assert.Fail("Исключение не вызвано.");
            }
            catch (Exception ex)
            {
                Assert.AreEqual("Место хранения-получатель не указано.", ex.Message);
            }
        }
Esempio n. 6
0
        private void UpdateIndicatorsForMovementWaybill(MovementWaybill waybill, short sign)
        {
            // пересчет показателя для входящего перемещения
            articleMovementFactualFinancialIndicatorService.Update(waybill.ReceiptDate.Value, waybill.Sender.Id, waybill.SenderStorage.Id,
                                                                   waybill.Recipient.Id, waybill.RecipientStorage.Id, ArticleMovementOperationType.IncomingMovement, waybill.Id,
                                                                   sign * waybill.PurchaseCostSum,
                                                                   sign * (waybill.RecipientAccountingPriceSum ?? 0),
                                                                   0);

            // пересчет показателя для исходящего перемещения
            articleMovementFactualFinancialIndicatorService.Update(waybill.ReceiptDate.Value, waybill.Sender.Id, waybill.SenderStorage.Id,
                                                                   waybill.Recipient.Id, waybill.RecipientStorage.Id, ArticleMovementOperationType.OutgoingMovement, waybill.Id,
                                                                   sign * waybill.PurchaseCostSum,
                                                                   sign * (waybill.SenderAccountingPriceSum ?? 0),
                                                                   0);
        }
Esempio n. 7
0
        public void MovementWaybill_Must_Throw_Exception_If_Curator_Is_Null()
        {
            try
            {
                var date = DateTime.Now;

                MovementWaybill waybill = new MovementWaybill(numberA, date, storageA, senderOrganizationA,
                                                              storageB, receiverOrganizationC, valueAddedTax, null, user, DateTime.Now);

                Assert.Fail("Исключение не вызвано.");
            }
            catch (Exception ex)
            {
                Assert.AreEqual("Не указан куратор.", ex.Message);
            }
        }
Esempio n. 8
0
        public void MovementWaybill_IndicatorsMustRecalculateOk()
        {
            MovementWaybill waybill = new MovementWaybill(numberA, DateTime.Today, storageA, senderOrganizationA,
                                                          storageB, receiverOrganizationC, valueAddedTax, user, user, DateTime.Now);

            //waybill.SetIndicators(1100M, 2234M, 2678.85M);

            //Assert.AreEqual(1100M, waybill.PurchaseCostSum);
            //Assert.AreEqual(2234M, waybill.SenderAccountingPriceSum);
            //Assert.AreEqual(2678.85M, waybill.RecipientAccountingPriceSum);
            //Assert.AreEqual(2678.85M - 2234M, waybill.MovementMarkupSum);
            //Assert.AreEqual(Math.Round((2678.85M - 2234M) / 2234M, 2), waybill.MovementMarkupPercent);

            //waybill.SetIndicators(1106M, 2289M, 3678.85M);

            //Assert.AreEqual(1106M, waybill.PurchaseCostSum);
            //Assert.AreEqual(2289M, waybill.SenderAccountingPriceSum);
            //Assert.AreEqual(3678.85M, waybill.RecipientAccountingPriceSum);
            //Assert.AreEqual(3678.85M - 2289M, waybill.MovementMarkupSum);
            //Assert.AreEqual(Math.Round((3678.85M - 2289M) / 2289M, 2), waybill.MovementMarkupPercent);
        }
Esempio n. 9
0
        /// <summary>
        /// Расчет процента отгрузки по накладной
        /// </summary>
        /// <param name="waybill"></param>
        /// <returns></returns>
        public decimal CalculateShippingPercent(MovementWaybill waybill)
        {
            var     accountingPrices = articlePriceService.GetAccountingPrice(waybill.RecipientStorage.Id, movementWaybillRepository.GetArticlesSubquery(waybill.Id));
            decimal totalIn = 0, totalOut = 0;

            decimal?price = 0M;

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

                if (price == null || price == 0)
                {
                    price = 0.0000000001M;
                }

                totalIn  += item.MovingCount * price.Value;
                totalOut += item.TotallyReservedCount * price.Value;
            }

            return(totalIn != 0 ? (totalOut / totalIn) * 100 : 0);
        }
Esempio n. 10
0
        public void MovementWaybill_InitialParameters_MustBeSet()
        {
            var date = DateTime.Now;

            MovementWaybill waybill = new MovementWaybill(numberA, date, storageA, senderOrganizationA,
                                                          storageB, receiverOrganizationC, valueAddedTax, user, user, date);

            Assert.AreEqual(0, waybill.Date.Hour + waybill.Date.Minute + waybill.Date.Second);
            Assert.AreEqual(numberA, waybill.Number);
            Assert.AreEqual(storageA.Name, waybill.SenderStorage.Name);
            Assert.AreEqual(senderOrganizationA.ShortName, waybill.Sender.ShortName);
            Assert.AreEqual(storageB.Name, waybill.RecipientStorage.Name);
            Assert.AreEqual(receiverOrganizationC.ShortName, waybill.Recipient.ShortName);
            Assert.AreEqual(user, waybill.Curator);

            Assert.IsNull(waybill.DeletionDate);
            Assert.IsNotNull(waybill.CreationDate);
            Assert.IsNotNull(waybill.Rows);
            Assert.AreEqual(0, waybill.RowCount);
            Assert.AreEqual(MovementWaybillState.Draft, waybill.State);
            Assert.AreEqual(String.Empty, waybill.Comment);
        }
Esempio n. 11
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);
        }
Esempio n. 12
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);
        }
Esempio n. 13
0
 /// <summary>
 /// Расчет основных показателей для всех позиций накладной перемещения
 /// </summary>
 public IDictionary <Guid, MovementWaybillRowMainIndicators> GetMainRowIndicators(MovementWaybill waybill, User user, bool calculateValueAddedTaxSums = false,
                                                                                  bool calculateMarkups = false)
 {
     return(GetMainIndicatorsForRowList(waybill, waybill.Rows, movementWaybillRepository.GetArticlesSubquery(waybill.Id), user,
                                        calculateValueAddedTaxSums, calculateMarkups));
 }
 public void WaybillFinalizationCancelled(MovementWaybill waybill)
 {
     articleMovementOperationCountIndicatorService.DecrementIndicator(waybill.ReceiptDate.Value, ArticleMovementOperationType.IncomingMovement, waybill.RecipientStorage.Id);
     articleMovementOperationCountIndicatorService.DecrementIndicator(waybill.ReceiptDate.Value, ArticleMovementOperationType.OutgoingMovement, waybill.SenderStorage.Id);
 }
Esempio n. 15
0
 /// <summary>
 /// Пересчет финансовых показателей после отмены приемки накладной перемещения
 /// </summary>
 /// <param name="waybill">Накладная перемещения</param>
 public void MovementWaybillReceiptCancelled(MovementWaybill waybill)
 {
     UpdateIndicatorsForMovementWaybill(waybill, -1);
 }
Esempio n. 16
0
        public void MovementWaybill_If_Date_Is_Earlier_Than_Today_Hours_Minutes_Seconds_Must_0()
        {
            var movementWaybill = new MovementWaybill("123", DateTime.Today.AddDays(-5), storageA, senderOrganizationA, storageB, senderOrganizationB, valueAddedTax, user, user, DateTime.Now);

            Assert.AreEqual(0, movementWaybill.Date.Hour + movementWaybill.Date.Minute + movementWaybill.Date.Hour);
        }