public IncomingWaybillRow ConvertToIncomingWaybillRow(ReturnFromClientWaybillRow row) { return(new IncomingWaybillRow() { Batch = row.ReceiptWaybillRow, BatchDate = row.ReturnFromClientWaybill.Date, Recipient = row.ReturnFromClientWaybill.Recipient, RecipientStorage = row.ReturnFromClientWaybill.RecipientStorage, Count = row.ReturnCount, FinallyMovedCount = row.FinallyMovedCount, Id = row.Id, IsReceipted = row.ReturnFromClientWaybill.IsReceipted, AcceptanceDate = row.ReturnFromClientWaybill.AcceptanceDate.Value, FinalizationDate = row.ReturnFromClientWaybill.ReceiptDate, AcceptedCount = row.AcceptedCount, ShippedCount = row.ShippedCount, Type = WaybillType.ReturnFromClientWaybill, WaybillDate = row.ReturnFromClientWaybill.Date, WaybillId = row.ReturnFromClientWaybill.Id, WaybillNumber = row.ReturnFromClientWaybill.Number, WaybillName = row.ReturnFromClientWaybill.Name, AvailableInStorageCount = (row.ReturnFromClientWaybill.IsReceipted ? row.ReturnCount - row.FinallyMovedCount : 0), PendingCount = (!row.ReturnFromClientWaybill.IsReceipted ? row.ReturnCount - row.FinallyMovedCount : 0), DivergenceCount = 0, AvailableToReserveCount = row.AvailableToReserveCount, UsageAsManualSourceCount = row.UsageAsManualSourceCount }); }
public void ReturnFromClientWaybill_Delete_Row_Must_Work() { row1 = new ReturnFromClientWaybillRow(saleRow1, 1); returnFromClientWaybill.AddRow(row1); Assert.AreEqual(returnFromClientWaybill.RowCount, 1); returnFromClientWaybill.DeleteRow(row1); Assert.AreEqual(returnFromClientWaybill.RowCount, 0); }
public void CheckPossibilityToDeleteRow(ReturnFromClientWaybillRow row, User user) { // права CheckPermissionToPerformOperationByDeal(row.ReturnFromClientWaybill, user, Permission.ReturnFromClientWaybill_Delete_Row_Delete); // сущность row.CheckPossibilityToDelete(); }
public void DeleteRow(ReturnFromClientWaybill returnFromClientWaybill, ReturnFromClientWaybillRow returnFromClientWaybillRow, User user) { CheckPossibilityToDeleteRow(returnFromClientWaybillRow, user); returnFromClientWaybill.DeleteRow(returnFromClientWaybillRow); returnFromClientWaybillRepository.Save(returnFromClientWaybill); }
private ReturnFromClientWaybill GetWaybill() { row1 = new ReturnFromClientWaybillRow(saleRow1, 1); returnFromClientWaybill.AddRow(row1); return(returnFromClientWaybill); }
public void ReturnFromClientWaybill_AddRow_Must_Init() { row1 = new ReturnFromClientWaybillRow(saleRow1, 1); returnFromClientWaybill.AddRow(row1); Assert.AreEqual(row1.ReturnFromClientWaybill.Id, returnFromClientWaybill.Id); Assert.AreEqual(row1.ReturnFromClientWaybill, returnFromClientWaybill); Assert.AreEqual(returnFromClientWaybill.RowCount, 1); }
public void ReturnFromClientWaybillRow_Initial_Parameters_Must_Be_Set() { var row1 = new ReturnFromClientWaybillRow(saleRow1, 3); Assert.AreEqual(row1.ReturnCount, 3); Assert.IsNotNull(row1.SaleWaybillRow); Assert.AreEqual(row1.PurchaseCost, row1.SaleWaybillRow.PurchaseCost); Assert.AreEqual(row1.SalePrice, row1.SaleWaybillRow.SalePrice); }
public void ReturnFromClientWaybillService_Rows_Of_Different_Articles_MustBe_AddedOk() { var row = new ReturnFromClientWaybillRow(saleRow2.Object, 2) { Id = Guid.NewGuid() }; returnFromClientWaybill.AddRow(row); Assert.AreEqual(2, returnFromClientWaybill.RowCount); }
public bool IsPossibilityToDeleteRow(ReturnFromClientWaybillRow row, User user) { try { CheckPossibilityToDeleteRow(row, user); return(true); } catch { return(false); } }
public void ReturnFromClientWaybillRow_Must_Throw_Exception_If_SaleWaybillRow_Is_Null() { try { var row1 = new ReturnFromClientWaybillRow(null, 3); Assert.Fail("Исключение не вызвано."); } catch (Exception ex) { Assert.AreEqual("Не указана позиция накладной реализации.", ex.Message); } }
public void ReturnFromClientWaybillRow_Must_Throw_Exception_If_ReturnCount_Less_Then_Zero() { try { var row1 = new ReturnFromClientWaybillRow(saleRow1, -1); Assert.Fail("Исключение не вызвано."); } catch (Exception ex) { Assert.AreEqual("Невозможно вернуть количество товара, меньшее нуля.", ex.Message); } }
public void ReturnFromClientWaybillRow_Must_Throw_Exception_If_ReturnCount_Large_Then_Accessible() { try { var row1 = new ReturnFromClientWaybillRow(saleRow1, 6); Assert.Fail("Исключение не вызвано."); } catch (Exception ex) { Assert.AreEqual("Невозможно вернуть количество товара большее, чем реализовано.", ex.Message); } }
public void ReturnFromClientWaybill_Must_Throw_Exception_If_SaleWaybillNotInit() { try { row1 = new ReturnFromClientWaybillRow(saleRow1_1, 1); returnFromClientWaybill.AddRow(row1); Assert.Fail("Исключение не вызвано."); } catch (Exception ex) { Assert.AreEqual("Невозможно добавить позицию со ссылкой на позицию накладной реализации без указанной реализации.", ex.Message); } }
public void ReturnFromClientWaybill_Must_Throw_Exception_If_Client_And_Account_Organization_Are_Difference() { try { row1 = new ReturnFromClientWaybillRow(saleRowAnother1, 1); returnFromClientWaybill.AddRow(row1); Assert.Fail("Исключение не вызвано."); } catch (Exception ex) { Assert.AreEqual("Организация-приемщик и организация-продавец товара должны совпадать.", ex.Message); } }
public ReturnFromClientWaybillMainIndicators CalculateMainRowIndicators(ReturnFromClientWaybillRow row, User user) { var indicators = new ReturnFromClientWaybillMainIndicators(); if (row.ReturnFromClientWaybill.IsAccepted) { indicators.AccountingPrice = row.ArticleAccountingPrice.AccountingPrice; } else { indicators.AccountingPrice = articlePriceService.GetAccountingPrice(row.Article, row.ReturnFromClientWaybill.RecipientStorage); } return(indicators); }
public void ReturnFromClientWaybill_Must_Throw_Exception_If_Batch_Already_Added() { try { row1 = new ReturnFromClientWaybillRow(saleRow1, 1); row2 = new ReturnFromClientWaybillRow(saleRow1, 1); returnFromClientWaybill.AddRow(row1); returnFromClientWaybill.AddRow(row2); Assert.Fail("Исключение не вызвано."); } catch (Exception ex) { Assert.AreEqual("Позиция накладной по данной позиции накладной реализации уже добавлена.", ex.Message); } }
public void ReturnFromClientWaybillService_Rows_SameArticles_SameBatches_DifferentReturnFromClientWaybillWaybillRows_MustThrowException() { try { var row = new ReturnFromClientWaybillRow(saleRow1.Object, 2) { Id = Guid.NewGuid() }; returnFromClientWaybill.AddRow(row); Assert.Fail("Исключения не было."); } catch (Exception ex) { Assert.AreEqual("Позиция накладной по данной позиции накладной реализации уже добавлена.", ex.Message); } }
public void ReturnFromClientWaybill_Must_Throw_Exception_If_State_Is_Accepted() { try { row1 = new ReturnFromClientWaybillRow(saleRow1, 1); row2 = new ReturnFromClientWaybillRow(saleRow2, 1); returnFromClientWaybill.AddRow(row1); returnFromClientWaybill.Accept(Prices, false, curator, DateTime.Now); returnFromClientWaybill.AddRow(row2); Assert.Fail("Исключение не вызвано."); } catch (Exception ex) { Assert.AreEqual("Невозможно добавить позицию в накладную со статусом «Проведено».", ex.Message); } }
public void ReturnFromClientWaybill_Must_Throw_Exception_If_DeleteRow_From_Accepted_WaybillRow() { try { row1 = new ReturnFromClientWaybillRow(saleRow1, 1); returnFromClientWaybill.AddRow(row1); returnFromClientWaybill.Accept(Prices, false, curator, DateTime.Now); returnFromClientWaybill.DeleteRow(row1); Assert.Fail("Исключение не вызвано."); } catch (Exception ex) { if (!ex.Message.StartsWith("Невозможно удалить позицию из накладной со статусом ")) { Assert.Fail("Исключение не верно."); } } }
public void ReturnFromClientWaybill_Must_Throw_Exception_If_RecipientAccountingPriceSum_Try_Set_AfterAccept() { try { var waybill = new ReturnFromClientWaybill("142", DateTime.Today, accountOrganization, deal, team, storage, returnFromClientReason, curator, curator, DateTime.Now); var row = new ReturnFromClientWaybillRow(saleRow1, 1); waybill.AddRow(row); waybill.RecipientAccountingPriceSum = 100.5M; waybill.Accept(Prices, false, curator, DateTime.Now); waybill.RecipientAccountingPriceSum = 101.5M; Assert.Fail("Исключение не вызвано."); } catch (Exception ex) { Assert.AreEqual("Невозможно установить значение суммы в учетных ценах, т.к. накладная уже проведена.", ex.Message); } }
public void SaveRow(ReturnFromClientWaybillRow entity) { CurrentSession.SaveOrUpdate(entity); }
public void ReturnFromClientWaybillRow_SaleWaubillRow_Must_Equal() { row1 = new ReturnFromClientWaybillRow(saleRow1, 1); Assert.AreEqual(row1.SaleWaybillRow, saleRow1); Assert.AreEqual(row1.SaleWaybillRow.Id, saleRow1.Id); }
/// <summary> /// Добавление позиции в накладную /// </summary> public virtual void AddRow(ReturnFromClientWaybill waybill, ReturnFromClientWaybillRow row) { waybill.AddRow(row); returnFromClientWaybillRepository.Save(waybill); }
public void Init() { // инициализация IoC IoCInitializer.Init(); setting = new Setting() { UseReadyToAcceptStateForReturnFromClientWaybill = 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); receiptedBy = new Mock <User>(); receiptedBy.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 }; articleB = new Article("Тестовый товар Б", articleGroup, measureUnit, true) { Id = 2 }; receiptWaybillRow1 = new Mock <ReceiptWaybillRow>(); receiptWaybillRow1.Setup(x => x.Article).Returns(articleA); receiptWaybillRow2 = new Mock <ReceiptWaybillRow>(); receiptWaybillRow2.Setup(x => x.Article).Returns(articleB); articleAccountingPrice = new List <ArticleAccountingPrice>() { new ArticleAccountingPrice(articleA, 100) }; returnFromClientWaybillRepository = Mock.Get(IoCContainer.Resolve <IReturnFromClientWaybillRepository>()); 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); returnFromClientWaybillRepository = Mock.Get(IoCContainer.Resolve <IReturnFromClientWaybillRepository>()); expenditureWaybillIndicatorService = Mock.Get(IoCContainer.Resolve <IExpenditureWaybillIndicatorService>()); articleAvailabilityService = Mock.Get(IoCContainer.Resolve <IArticleAvailabilityService>()); returnFromClientWaybillService = new ReturnFromClientWaybillService( IoCContainer.Resolve <ISettingRepository>(), returnFromClientWaybillRepository.Object, IoCContainer.Resolve <ITeamRepository>(), IoCContainer.Resolve <IDealRepository>(), IoCContainer.Resolve <IStorageRepository>(), IoCContainer.Resolve <IUserRepository>(), IoCContainer.Resolve <IArticlePriceService>(), IoCContainer.Resolve <IAcceptedSaleIndicatorService>(), IoCContainer.Resolve <IReturnFromClientService>(), IoCContainer.Resolve <IFactualFinancialArticleMovementService>(), IoCContainer.Resolve <IArticleMovementOperationCountService>(), IoCContainer.Resolve <IArticleMovementService>(), IoCContainer.Resolve <IDealPaymentDocumentDistributionService>(), IoCContainer.Resolve <IDealIndicatorService>(), IoCContainer.Resolve <IArticleRevaluationService>(), expenditureWaybillIndicatorService.Object, articleAvailabilityService.Object ); deal = new Mock <Deal>(); quota = new DealQuota("asd", 10, 45, 15000); team = new Team("Тестовая команда", It.IsAny <User>()) { Id = 1 }; contract = new Mock <ClientContract>(); var economicAgent = new Mock <EconomicAgent>(); accountOrganization = new AccountOrganization("asd", "asd", economicAgent.Object); 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.AddStorage(storage); contract.Setup(x => x.AccountOrganization).Returns(accountOrganization); returnFromClientWaybill = new ReturnFromClientWaybill("123", DateTime.Now, accountOrganization, deal.Object, team, storage, new ReturnFromClientReason(), user.Object, createdBy.Object, DateTime.Now); sale = new Mock <ExpenditureWaybill>(); sale.Setup(x => x.Sender).Returns(accountOrganization); sale.Setup(x => x.Team).Returns(team); sale.Setup(x => x.Is <ExpenditureWaybill>()).Returns(true); sale.Setup(x => x.As <ExpenditureWaybill>()).Returns(sale.Object); #region Создание позиции 1 saleRow1 = new Mock <ExpenditureWaybillRow>(); saleRow1.Setup(x => x.ExpenditureWaybill).Returns(sale.Object); saleRow1.Setup(x => x.SaleWaybill).Returns(sale.Object); saleRow1.Setup(x => x.Id).Returns(Guid.NewGuid()); saleRow1.Setup(x => x.SellingCount).Returns(100); saleRow1.Setup(x => x.As <ExpenditureWaybillRow>()).Returns(saleRow1.Object); saleRow1.Setup(x => x.Is <ExpenditureWaybillRow>()).Returns(true); saleRow1.Setup(x => x.Article).Returns(articleA); saleRow1.Setup(x => x.SalePrice).Returns(128); saleRow1.Setup(x => x.ReceiptWaybillRow).Returns(receiptWaybillRow1.Object); #endregion #region Создание позиции 2 saleRow2 = new Mock <ExpenditureWaybillRow>(); saleRow2.Setup(x => x.ExpenditureWaybill).Returns(sale.Object); saleRow2.Setup(x => x.SaleWaybill).Returns(sale.Object); saleRow2.Setup(x => x.Id).Returns(Guid.NewGuid()); saleRow2.Setup(x => x.SellingCount).Returns(100); saleRow2.Setup(x => x.As <ExpenditureWaybillRow>()).Returns(saleRow2.Object); saleRow2.Setup(x => x.Is <ExpenditureWaybillRow>()).Returns(true); saleRow2.Setup(x => x.Article).Returns(articleA); saleRow2.Setup(x => x.SalePrice).Returns(128); saleRow2.Setup(x => x.ReceiptWaybillRow).Returns(receiptWaybillRow2.Object); #endregion ReturnFromClientWaybillRow row = new ReturnFromClientWaybillRow(saleRow1.Object, 1); returnFromClientWaybill.AddRow(row); articleMovementService = new Mock <IArticleMovementService>(); articleMovementService.Setup(x => x.CancelArticleAcceptance(It.IsAny <WriteoffWaybill>())) .Returns(new List <OutgoingWaybillRowSourceReservationInfo>() { new OutgoingWaybillRowSourceReservationInfo(row.Id, 1, 1) }); articleMovementService.Setup(x => x.AcceptArticles(It.IsAny <WriteoffWaybill>())) .Returns(new List <OutgoingWaybillRowSourceReservationInfo>() { new OutgoingWaybillRowSourceReservationInfo(row.Id, 1, 1) }); }
/// <summary> /// Создание показателя по возвратам на дату отгрузки накладной реализации /// </summary> private ReturnFromClientBySaleShippingDateIndicator CreateReturnFromClientBySaleShippingDateIndicator(ReturnFromClientWaybillRow row, short sign) { ValidationUtils.Assert(sign == 1 || sign == -1, "Значение множителя может быть только 1 или -1."); var saleWaybillRow = row.SaleWaybillRow.As <ExpenditureWaybillRow>(); var saleWaybill = saleWaybillRow.SaleWaybill; var teamId = row.SaleWaybillRow.SaleWaybill.Team.Id; var returnFromClientWaybillCuratorId = row.ReturnFromClientWaybill.Curator.Id; return(new ReturnFromClientBySaleShippingDateIndicator(saleWaybillRow.ExpenditureWaybill.ShippingDate.Value, row.Article.Id, saleWaybill.Curator.Id, returnFromClientWaybillCuratorId, row.ReceiptWaybillRow.ReceiptWaybill.Contractor.Id, saleWaybillRow.ExpenditureWaybill.SenderStorage.Id, /* именно МХ, с которого сделана реализация */ saleWaybill.Sender.Id, saleWaybill.Deal.Client.Id, saleWaybill.Deal.Id, saleWaybill.Deal.Contract.ContractorOrganization.Id, teamId, saleWaybill.Id, row.ReceiptWaybillRow.Id, sign * Math.Round(row.PurchaseCost * row.ReturnCount, 6), sign * Math.Round(row.ArticleAccountingPrice.AccountingPrice * row.ReturnCount, 2), sign * Math.Round((row.SalePrice ?? 0M) * row.ReturnCount, 2), sign * row.ReturnCount)); }