public void Init() { storage = new Storage("Тестовое место хранения", StorageType.DistributionCenter) { Id = 1 }; user = new User(new Employee("Иван", "Иванов", "Иванович", new EmployeePost("Менеджер"), null), "Иванов Иван", "ivanov", "pa$$w0rd", new Team("Тестовая команда", null), null); economicAgent = new PhysicalPerson(new LegalForm("Легал форм", EconomicAgentType.PhysicalPerson)); accountOrganization = new AccountOrganization("Орг1 кор имя", "орг1 длин имя", economicAgent) { Id = 1 }; clientOrganization = new ClientOrganization("client org", "cllll", economicAgent) { Id = 3 }; storage.AddAccountOrganization(accountOrganization); deal = new Deal("Тестовая сделка", user) { Id = 2 }; client = new Client("клиент1", new ClientType("основной тип клиента"), ClientLoyalty.Follower, new ClientServiceProgram("программа 1"), new ClientRegion("Регион 1"), 10); deal.Contract = new ClientContract(accountOrganization, clientOrganization, "Договор 1", "1", DateTime.Now, DateTime.Now); client.AddDeal(deal); quota = new DealQuota("Тестовая квота", 20, 14, 20000.0M) { Id = 3 }; deal.AddQuota(quota); team = new Mock <Team>(); expenditureWaybill = new ExpenditureWaybill("123", DateTime.Today, storage, deal, team.Object, quota, false, user, DeliveryAddressType.ClientAddress, "", DateTime.Today, user); }
/// <summary> /// Расчет неоплаченного остатка по накладной /// </summary> public decimal CalculateDebtRemainder(ExpenditureWaybill waybill) { var salesCost = CalculateSalePriceSum(waybill) - GetTotalReturnedSumForSaleWaybill(waybill); //Стоимость реализации с учетом возвратов var paymentForSale = CalculatePaymentSum(waybill); // Оплата по накладной с учетом возвращенных по возвратам оплат return(salesCost - paymentForSale); // Долг по реализации }
private void UpdateIndicatorsForExpenditureWaybill(ExpenditureWaybill waybill, short sign) { articleMovementFactualFinancialIndicatorService.Update(waybill.ShippingDate.Value, waybill.Sender.Id, waybill.SenderStorage.Id, null, null, ArticleMovementOperationType.Expenditure, waybill.Id, sign * waybill.PurchaseCostSum, sign * waybill.SenderAccountingPriceSum, sign * waybill.SalePriceSum); }
/// <summary> /// Расчет неоплаченного остатка по накладной реализации /// </summary> /// <param name="saleWaybill">Накладная реализации</param> /// <returns>Неоплаченный остаток</returns> public decimal CalculateDebtRemainder(SaleWaybill saleWaybill) { if (saleWaybill.Is <ExpenditureWaybill>()) { ExpenditureWaybill expenditureWaybill = saleWaybill.As <ExpenditureWaybill>(); return(expenditureWaybillIndicatorService.CalculateDebtRemainder(expenditureWaybill)); } throw new Exception("Неизвестный тип накладной реализации."); }
/// <summary> /// Общая сумма всех возвратов по накладной реализации /// </summary> /// <param name="saleWaybill">Накладная реализации</param> /// <returns>Сумма</returns> public decimal GetTotalReservedByReturnSumForSaleWaybill(SaleWaybill saleWaybill) { if (saleWaybill.Is <ExpenditureWaybill>()) { ExpenditureWaybill expenditureWaybill = saleWaybill.As <ExpenditureWaybill>(); return(expenditureWaybillIndicatorService.GetTotalReservedByReturnSumForSaleWaybill(expenditureWaybill)); } throw new Exception("Неизвестный тип накладной реализации."); }
public void ExpenditureWaybill_Must_Throw_Exception_If_Curator_Is_Null() { try { waybill = new ExpenditureWaybill("123", currentDate, storage, deal.Object, team.Object, quota, false, null, DeliveryAddressType.CustomAddress, "qwerty", creationDate, createdBy.Object); Assert.Fail("Исключение не вызвано."); } catch (Exception ex) { Assert.AreEqual("Не указан куратор.", ex.Message); } }
public void ExpenditureWaybill_Initial_Params_Must_Be_Set() { waybill = new ExpenditureWaybill("123", currentDate, storage, deal.Object, team.Object, quota, false, user.Object, DeliveryAddressType.CustomAddress, "qwerty", creationDate, createdBy.Object); Assert.AreEqual("123", waybill.Number); Assert.AreEqual(currentDate.SetHoursMinutesAndSeconds(0, 0, 0), waybill.Date); Assert.AreEqual(storage, waybill.SenderStorage); Assert.AreEqual(deal.Object.Id, waybill.Deal.Id); Assert.AreEqual(team.Object.Id, waybill.Team.Id); Assert.AreEqual(quota, waybill.Quota); Assert.AreEqual(false, waybill.IsPrepayment); Assert.AreEqual(user.Object.Id, waybill.Curator.Id); Assert.AreEqual(DeliveryAddressType.CustomAddress, waybill.DeliveryAddressType); Assert.AreEqual("qwerty", waybill.DeliveryAddress); Assert.AreEqual(createdBy.Object.Id, waybill.CreatedBy.Id); Assert.AreEqual(creationDate, waybill.CreationDate); }
private void UpdateShippedIndicators(ExpenditureWaybill waybill, short sign) { var shippedIndicators = new List <ShippedSaleIndicator>(); ValidationUtils.Assert(!waybill.Rows.Any(x => !x.Is <ExpenditureWaybillRow>()), "Расчет показателя для данного типа накладной реализации еще не реализован."); foreach (var item in waybill.Rows.Where(x => x.Is <ExpenditureWaybillRow>())) { var row = item.As <ExpenditureWaybillRow>(); // обновление показателя отгруженных накладных реализации var shippedIndicator = CreateShippedSaleIndicator(waybill.ShippingDate.Value, row, waybill.Team.Id, sign); shippedIndicators.Add(shippedIndicator); } shippedSaleIndicatorService.Update(waybill.ShippingDate.Value, waybill.Curator.Id, waybill.SenderStorage.Id, waybill.Deal.Id, waybill.Team.Id, expenditureWaybillRepository.GetArticleBatchesSubquery(waybill.Id), shippedIndicators); }
public void Init() { creationDate = DateTime.Now; currentDate = DateTime.Now; storage = new Storage("qwe", StorageType.ExtraStorage); deal = new Mock <Deal>(); quota = new DealQuota("asd", 10, 45, 15000); user = new Mock <User>(); createdBy = new Mock <User>(); team = new Mock <Team>(); contract = new Mock <ClientContract>(); accountOrganization = new Mock <AccountOrganization>(); valueAddedTax = new ValueAddedTax("18%", 18); ag = new ArticleGroup("Группа товаров", "Группа товаров"); art1 = new Article("Товар 1", ag, new MeasureUnit("шт.", "штуки", "123", 1), false); art2 = new Article("Товар 2", ag, new MeasureUnit("шт.", "штуки", "123", 1), false); art3 = new Article("Товар 3", ag, new MeasureUnit("шт.", "штуки", "123", 1), false); prices = new List <ArticleAccountingPrice>(); prices.Add(new ArticleAccountingPrice(art1, 10M)); prices.Add(new ArticleAccountingPrice(art2, 13M)); prices.Add(new ArticleAccountingPrice(art3, 15M)); receiptWaybillRow = new ReceiptWaybillRow(art1, 150, valueAddedTax, 75); user.Setup(x => x.Id).Returns(43); createdBy.Setup(x => x.Id).Returns(1); team.Setup(x => x.Id).Returns(1); deal.Setup(x => x.IsActive).Returns(true); deal.Setup(x => x.IsClosed).Returns(false); deal.Setup(x => x.Quotas).Returns(new List <DealQuota> { quota }); deal.Setup(x => x.Contract).Returns(contract.Object); deal.Setup(x => x.Id).Returns(2); accountOrganization.Setup(x => x.Storages).Returns(new List <Storage> { storage }); contract.Setup(x => x.AccountOrganization).Returns(accountOrganization.Object); waybill = new ExpenditureWaybill("123", currentDate, storage, deal.Object, team.Object, quota, false, user.Object, DeliveryAddressType.CustomAddress, "qwerty", creationDate, createdBy.Object); waybillRow = new ExpenditureWaybillRow(receiptWaybillRow, 10, valueAddedTax); waybill.AddRow(waybillRow); }
private void UpdateAcceptedIndicators(ExpenditureWaybill waybill, short sign) { ValidationUtils.Assert(sign == 1 || sign == -1, "Значение множителя может быть только 1 или -1."); var acceptedIndicators = new List <AcceptedSaleIndicator>(); ValidationUtils.Assert(!waybill.Rows.Any(x => !x.Is <ExpenditureWaybillRow>()), "Расчет показателя для данного типа накладной реализации еще не реализован."); foreach (var item in waybill.Rows.Where(x => x.Is <ExpenditureWaybillRow>())) { var row = item.As <ExpenditureWaybillRow>(); // обновление показателя проведенных накладных реализации var acceptedIndicator = CreateAcceptedSaleIndicator(waybill.AcceptanceDate.Value, row, waybill.Team.Id, sign); acceptedIndicators.Add(acceptedIndicator); } acceptedSaleIndicatorService.Update(waybill.AcceptanceDate.Value, waybill.Curator.Id, waybill.SenderStorage.Id, waybill.Deal.Id, waybill.Team.Id, expenditureWaybillRepository.GetArticleBatchesSubquery(waybill.Id), acceptedIndicators); }
/// <summary> /// Разнести неразнесенные части платежных документов на накладную реализации. /// После разнесения у накладной реализации может оставаться неоплаченный остаток. /// Если до разнесения накладная реализации не имеет положительного неоплаченного остатка, разнесение платежного документа не будет создано. /// При полной оплате накладной реализации происходит установка признака того, что накладная реализации полностью оплачена. /// </summary> /// <param name="dealPaymentUndistributedPartsInfo">Список неразнесенных частей платежных документов</param> /// <param name="saleWaybill">Накладная реализации (единственная), на которую выполняется разнесение платежных документов</param> /// <param name="debtRemainder">Текущий неоплаченный остаток по накладной</param> /// <param name="sumToDistribute">Сумма к разнесению</param> /// <param name="currentDate">Дата операции</param> private void PaySaleWaybill(List <DealPaymentUndistributedPartInfo> dealPaymentUndistributedPartsInfo, SaleWaybill saleWaybill, decimal debtRemainder, decimal sumToDistribute, DateTime currentDate) { // разносим неразнесенные части оплат foreach (var distributionPartInfo in dealPaymentUndistributedPartsInfo.OrderBy(x => x.AppearenceDate)) { var dealPaymentDocument = distributionPartInfo.DealPaymentDocument; // cумма создаваемого разнесения платежного документа decimal sum = Math.Min(distributionPartInfo.Sum, sumToDistribute); // вычитаем разносимую сумму distributionPartInfo.Sum -= sum; sumToDistribute -= sum; // дата создаваемого разнесения var distributionDate = DateTimeUtils.GetMaxDate(distributionPartInfo.AppearenceDate, saleWaybill.AcceptanceDate.Value); ValidationUtils.Assert(dealPaymentDocument.Is <DealPaymentFromClient>() || dealPaymentDocument.Is <DealCreditInitialBalanceCorrection>(), "Платежный документ имеет недопустимый тип."); ValidationUtils.Assert(sum > 0, "Сумма для разнесения должна быть положительной."); if (saleWaybill.Is <ExpenditureWaybill>()) // Если появятся еще типы накладных реализации, вместо "накладная реализации товаров" выводить их названия { ExpenditureWaybill expenditureWaybill = saleWaybill.As <ExpenditureWaybill>(); ValidationUtils.Assert(expenditureWaybill.IsAccepted, String.Format("Невозможно разнести платежный документ на накладную реализации товаров {0} со статусом «{1}».", expenditureWaybill.Name, expenditureWaybill.State.GetDisplayName())); ValidationUtils.Assert(sum <= debtRemainder, String.Format("Сумма для разнесения ({0} р.) превышает неоплаченный остаток накладной реализации товаров {1} ({2} р.)", sum.ForDisplay(ValueDisplayType.Money), expenditureWaybill.Name, debtRemainder.ForDisplay(ValueDisplayType.Money))); ValidationUtils.Assert(dealPaymentDocument.Team == saleWaybill.Team, String.Format("Невозможно оплатить накладную реализации «{0}», т.к. она относится к другой команде.", saleWaybill.Name)); // формируем разнесение var dealPaymentDocumentDistributionToSaleWaybill = new DealPaymentDocumentDistributionToSaleWaybill(dealPaymentDocument, expenditureWaybill, sum, distributionDate, currentDate) { SourceDistributionToReturnFromClientWaybill = distributionPartInfo.DealPaymentDocumentDistributionToReturnFromClientWaybill }; dealPaymentDocument.AddDealPaymentDocumentDistribution(dealPaymentDocumentDistributionToSaleWaybill); debtRemainder -= sum; // Если накладная реализации товаров полностью оплачена, ставим ей признак полной оплаты expenditureWaybill.IsFullyPaid = debtRemainder <= 0M; } // и выходим if (saleWaybill.IsFullyPaid) { break; } } // удаляем полностью разнесенные части var undistributedPartsToDelete = dealPaymentUndistributedPartsInfo.Where(x => x.Sum == 0).ToList(); foreach (var item in undistributedPartsToDelete) { dealPaymentUndistributedPartsInfo.Remove(item); } }
/// <summary> /// Пересчет показателей реализации при отмене проводки накладной реализации товаров /// </summary> public void ExpenditureWaybillAcceptanceCancelled(ExpenditureWaybill waybill) { UpdateAcceptedIndicators(waybill, -1); }
/// <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); }
/// <summary> /// Расчет суммы итоговой оплаты реализации, с учетом возвратов товаров /// </summary> /// <param name="waybill">Накладная реализации</param> /// <returns></returns> public decimal CalculatePaymentSum(ExpenditureWaybill waybill) { return(saleWaybillRepository.CalculatePaymentSum(waybill.Id)); }
/// <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); }
public IDictionary <Guid, ExpenditureWaybillRowMainIndicators> CalculateRowsMainIndicators(ExpenditureWaybill waybill, bool allowToViewAccPrices = true, bool calculateSalePrice = false, bool calculateValueAddedTaxSum = false) { return(GetMainIndicatorsForRowList(waybill, waybill.Rows.Select(x => x.As <ExpenditureWaybillRow>()), expenditureWaybillRepository.GetArticlesSubquery(waybill.Id), allowToViewAccPrices: allowToViewAccPrices, calculateSalePrice: calculateSalePrice, calculateValueAddedTaxSum: calculateValueAddedTaxSum)); }
/// <summary> /// Расчет суммы отпускных цен для накладной /// </summary> /// <param name="waybill"></param> /// <returns></returns> public decimal CalculateSalePriceSum(ExpenditureWaybill waybill) { return(CalculateMainIndicators(waybill, calculateSalePriceSum: true).SalePriceSum); }
public void WaybillFinalizationCancelled(ExpenditureWaybill waybill) { articleMovementOperationCountIndicatorService.DecrementIndicator(waybill.ShippingDate.Value, ArticleMovementOperationType.Expenditure, waybill.SenderStorage.Id); }
public void Init() { // инициализация IoC IoCInitializer.Init(); setting = new Setting() { UseReadyToAcceptStateForExpenditureWaybill = false }; settingRepository = Mock.Get(IoCContainer.Resolve <ISettingRepository>()); settingRepository.Setup(x => x.Get()).Returns(setting); storage = new Storage("qwe", StorageType.ExtraStorage) { Id = 42 }; accOrgSender = new Mock <AccountOrganization>(); accOrgSender.Setup(x => x.Id).Returns(1); accOrgRecipient = new Mock <AccountOrganization>(); accOrgRecipient.Setup(x => x.Id).Returns(2); valueAddedTax = new ValueAddedTax(); user = new Mock <User>(); user.Setup(x => x.GetPermissionDistributionType(It.IsAny <Permission>())).Returns(PermissionDistributionType.All); createdBy = new Mock <User>(); createdBy.Setup(x => x.GetPermissionDistributionType(It.IsAny <Permission>())).Returns(PermissionDistributionType.All); acceptedBy = new Mock <User>(); acceptedBy.Setup(x => x.GetPermissionDistributionType(It.IsAny <Permission>())).Returns(PermissionDistributionType.All); var articleGroup = new ArticleGroup("Тестовая группа", "Тестовая группа"); var measureUnit = new MeasureUnit("шт.", "Штука", "123", 0) { Id = 1 }; articleA = new Article("Тестовый товар A", articleGroup, measureUnit, true) { Id = 1 }; receiptWaybillRow = new Mock <ReceiptWaybillRow>(); receiptWaybillRow.Setup(x => x.Article).Returns(articleA); articleAccountingPrice = new List <ArticleAccountingPrice>() { new ArticleAccountingPrice(articleA, 100) }; expenditureWaybillRepository = Mock.Get(IoCContainer.Resolve <IExpenditureWaybillRepository>()); articleRepository = Mock.Get(IoCContainer.Resolve <IArticleRepository>()); articlePriceService = Mock.Get(IoCContainer.Resolve <IArticlePriceService>()); articlePriceService.Setup(x => x.GetArticleAccountingPrices(It.Is <short>(y => y == storage.Id), It.IsAny <IEnumerable <int> >())).Returns(articleAccountingPrice); articlePriceService.Setup(x => x.GetArticleAccountingPrices(It.Is <short>(y => y == storage.Id), It.IsAny <ISubQuery>(), It.IsAny <DateTime>())).Returns(articleAccountingPrice); articleAvailabilityService = Mock.Get(IoCContainer.Resolve <IArticleAvailabilityService>()); articleMovementService = Mock.Get(IoCContainer.Resolve <IArticleMovementService>()); receiptWaybillService = Mock.Get(IoCContainer.Resolve <IReceiptWaybillService>()); articleRevaluationService = Mock.Get(IoCContainer.Resolve <IArticleRevaluationService>()); factualFinancialArticleMovementService = new Mock <IFactualFinancialArticleMovementService>(); articleMovementOperationCountService = new Mock <IArticleMovementOperationCountService>(); teamRepository = Mock.Get(IoCContainer.Resolve <ITeamRepository>()); dealRepository = Mock.Get(IoCContainer.Resolve <IDealRepository>()); expenditureWaybillIndicatorService = Mock.Get(IoCContainer.Resolve <IExpenditureWaybillIndicatorService>()); dealPaymentDocumentDistributionService = Mock.Get(IoCContainer.Resolve <IDealPaymentDocumentDistributionService>()); blockingService = Mock.Get(IoCContainer.Resolve <IBlockingService>()); articleSaleService = Mock.Get(IoCContainer.Resolve <IArticleSaleService>()); teamService = Mock.Get(IoCContainer.Resolve <ITeamService>()); dealService = Mock.Get(IoCContainer.Resolve <IDealService>()); dealIndicatorService = Mock.Get(IoCContainer.Resolve <IDealIndicatorService>()); clientContractIndicatorService = Mock.Get(IoCContainer.Resolve <IClientContractIndicatorService>()); returnFromClientWaybillRepository = new Mock <IReturnFromClientWaybillRepository>(); expenditureWaybillService = new ExpenditureWaybillService(settingRepository.Object, expenditureWaybillRepository.Object, teamRepository.Object, Mock.Get(IoCContainer.Resolve <IStorageRepository>()).Object, Mock.Get(IoCContainer.Resolve <IUserRepository>()).Object, dealRepository.Object, articlePriceService.Object, expenditureWaybillIndicatorService.Object, articleMovementService.Object, dealPaymentDocumentDistributionService.Object, blockingService.Object, articleSaleService.Object, factualFinancialArticleMovementService.Object, articleMovementOperationCountService.Object, teamService.Object, dealService.Object, dealIndicatorService.Object, clientContractIndicatorService.Object, articleAvailabilityService.Object, receiptWaybillService.Object, articleRevaluationService.Object, returnFromClientWaybillRepository.Object); deal = new Mock <Deal>(); quota = new DealQuota("asd", 10, 45, 15000); team = new Mock <Team>(); contract = new Mock <ClientContract>(); accountOrganization = new Mock <AccountOrganization>(); deal.Setup(x => x.IsActive).Returns(true); deal.Setup(x => x.IsClosed).Returns(false); deal.Setup(x => x.Quotas).Returns(new List <DealQuota> { quota }); deal.Setup(x => x.Contract).Returns(contract.Object); accountOrganization.Setup(x => x.Storages).Returns(new List <Storage> { storage }); contract.Setup(x => x.AccountOrganization).Returns(accountOrganization.Object); waybill = new ExpenditureWaybill("123", DateTime.Now, storage, deal.Object, team.Object, quota, false, user.Object, DeliveryAddressType.CustomAddress, "qwe", DateTime.Now, createdBy.Object); var row = new ExpenditureWaybillRow(receiptWaybillRow.Object, 10, valueAddedTax); waybill.AddRow(row); articleMovementService.Setup(x => x.CancelArticleAcceptance(It.IsAny <ExpenditureWaybill>())) .Returns(new List <OutgoingWaybillRowSourceReservationInfo>() { new OutgoingWaybillRowSourceReservationInfo(row.Id, 1, 1) }); articleMovementService.Setup(x => x.AcceptArticles(It.IsAny <ExpenditureWaybill>())) .Returns(new List <OutgoingWaybillRowSourceReservationInfo>() { new OutgoingWaybillRowSourceReservationInfo(row.Id, 1, 1) }); }
public void Init() { employee1 = new Employee("Работник 1 имя", "Работник 1 фамилия", "Работник 1 отчество", new EmployeePost("Работник 1 пост"), null); curator = new User(employee1, "Куратор", "log", "pas", new Team("Тестовая команда", null), null); team = new Team("123", curator); economicAgent = new PhysicalPerson(new LegalForm("Легал форм", EconomicAgentType.PhysicalPerson)); accountOrganization = new AccountOrganization("Орг1 кор имя", "орг1 длин имя", economicAgent) { Id = 1 }; accountOrganizationAnother = new AccountOrganization("Орг2 кор имя", "орг2 длин имя", economicAgent) { Id = 2 }; clientOrganization = new ClientOrganization("client org", "cllll", economicAgent) { Id = 3 }; client = new Client("клиент1", new ClientType("основной тип клиента"), ClientLoyalty.Follower, new ClientServiceProgram("программа 1"), new ClientRegion("Регион 1"), 10); deal = new Deal("Тестовая сделка", curator); client.AddDeal(deal); storage = new Storage("Склад 1", StorageType.ExtraStorage); storage.AddAccountOrganization(accountOrganization); storage.AddAccountOrganization(accountOrganizationAnother); storage2 = new Storage("Склад 2", StorageType.ExtraStorage); returnFromClientReason = new ReturnFromClientReason("Брак"); returnFromClientWaybill = new ReturnFromClientWaybill("142", DateTime.Today, accountOrganization, deal, team, storage, returnFromClientReason, curator, curator, DateTime.Now); valueAddedTax = new ValueAddedTax("18%", 18); ag = new ArticleGroup("Группа товаров", "Группа товаров"); art1 = new Article("Товар 1", ag, new MeasureUnit("шт.", "штуки", "123", 1), false); art2 = new Article("Товар 2", ag, new MeasureUnit("шт.", "штуки", "123", 1), false); art3 = new Article("Товар 3", ag, new MeasureUnit("шт.", "штуки", "123", 1), false); Prices = new List <ArticleAccountingPrice>(); Prices.Add(new ArticleAccountingPrice(art1, 10M)); Prices.Add(new ArticleAccountingPrice(art2, 13M)); Prices.Add(new ArticleAccountingPrice(art3, 15M)); deal1 = new Deal("Deal1", curator); deal2 = new Deal("Deal2", curator); quota1 = new DealQuota("qq", 1); quota2 = new DealQuota("qq", 2); deal1.AddQuota(quota1); deal2.AddQuota(quota2); deal1.Contract = new ClientContract(accountOrganization, clientOrganization, "Договор", "1", DateTime.Now, DateTime.Now); deal2.Contract = new ClientContract(accountOrganizationAnother, clientOrganization, "kk", "22", DateTime.Today, DateTime.Now); recRow1 = new ReceiptWaybillRow(art1, 5, 50, new ValueAddedTax("18%", 18)) { Id = Guid.NewGuid() }; recRow1_1 = new ReceiptWaybillRow(art1, 2, 30, new ValueAddedTax("18%", 18)) { Id = Guid.NewGuid() }; recRow2 = new ReceiptWaybillRow(art2, 7, 35, new ValueAddedTax("18%", 18)) { Id = Guid.NewGuid() }; recRow3 = new ReceiptWaybillRow(art3, 9, 90, new ValueAddedTax("18%", 18)) { Id = Guid.NewGuid() }; recRow1.PurchaseCost = 50 / 5; recRow1.PurchaseCost = 35 / 7; recRow1.PurchaseCost = 90 / 9; saleRow1 = new ExpenditureWaybillRow(recRow1, 3, valueAddedTax) { Id = Guid.NewGuid() }; saleRow1_1 = new ExpenditureWaybillRow(recRow1_1, 1, valueAddedTax) { Id = Guid.NewGuid() }; saleRow2 = new ExpenditureWaybillRow(recRow2, 4, valueAddedTax) { Id = Guid.NewGuid() }; saleRow3 = new ExpenditureWaybillRow(recRow3, 5, valueAddedTax) { Id = Guid.NewGuid() }; saleRowAnother1 = new ExpenditureWaybillRow(recRow1, 3, valueAddedTax) { Id = Guid.NewGuid() }; saleRowAnother2 = new ExpenditureWaybillRow(recRow2, 4, valueAddedTax) { Id = Guid.NewGuid() }; saleRowAnother3 = new ExpenditureWaybillRow(recRow3, 5, valueAddedTax) { Id = Guid.NewGuid() }; sale = new ExpenditureWaybill("1", DateTime.Today, storage, deal1, team, quota1, true, curator, DeliveryAddressType.ClientAddress, "", DateTime.Now, curator) { Id = Guid.NewGuid() }; saleAnother = new ExpenditureWaybill("1", DateTime.Today, storage, deal2, team, quota2, true, curator, DeliveryAddressType.ClientAddress, "", DateTime.Now, curator) { Id = Guid.NewGuid() }; sale.As <ExpenditureWaybill>().AddRow((ExpenditureWaybillRow)saleRow1); sale.As <ExpenditureWaybill>().AddRow((ExpenditureWaybillRow)saleRow2); sale.As <ExpenditureWaybill>().AddRow((ExpenditureWaybillRow)saleRow3); saleAnother.As <ExpenditureWaybill>().AddRow((ExpenditureWaybillRow)saleRowAnother1); saleAnother.As <ExpenditureWaybill>().AddRow((ExpenditureWaybillRow)saleRowAnother2); saleAnother.As <ExpenditureWaybill>().AddRow((ExpenditureWaybillRow)saleRowAnother3); sale.As <ExpenditureWaybill>().Accept(Prices, false, curator, DateTime.Now); saleAnother.As <ExpenditureWaybill>().Accept(Prices, false, curator, DateTime.Now); }
/// <summary> /// Пересчет финансовых показателей после отгрузки товара по накладной реализации /// </summary> /// <param name="waybill">Накладная реализации товаров</param> public void ExpenditureWaybillShipped(ExpenditureWaybill waybill) { UpdateIndicatorsForExpenditureWaybill(waybill, 1); }
/// <summary> /// Пересчет финансовых показателей после отмены отгрузки товара по накладной реализации /// </summary> /// <param name="waybill">Накладная реализации товаров</param> public void ExpenditureWaybillShippingCancelled(ExpenditureWaybill waybill) { UpdateIndicatorsForExpenditureWaybill(waybill, -1); }