public void GetReferencedDocuments_WriteOffTest() { var interactive = Substitute.For <IInteractiveQuestion>(); interactive.Question(string.Empty).ReturnsForAnyArgs(true); var baseParameters = Substitute.For <BaseParameters>(); using (var uow = UnitOfWorkFactory.CreateWithoutRoot()) { var warehouse = new Warehouse(); uow.Save(warehouse); var nomenclatureType = new ItemsType { Name = "Тестовый тип номенклатуры" }; uow.Save(nomenclatureType); var nomenclature = new Nomenclature { Type = nomenclatureType }; uow.Save(nomenclature); var employee = new EmployeeCard(); uow.Save(employee); var expense = new Expense { Date = new DateTime(2021, 9, 10), Employee = employee, Operation = ExpenseOperations.Employee, Warehouse = warehouse, }; var size = new Size(); var height = new Size(); uow.Save(size); uow.Save(height); var stockPosition = new StockPosition(nomenclature, 0, size, height); var item = expense.AddItem(stockPosition, 10); expense.UpdateOperations(uow, baseParameters, interactive); uow.Save(expense); //Списываем 3 штуки var writeoff = new Writeoff() { Date = new DateTime(2021, 9, 11), }; var writeoffItem = writeoff.AddItem(item.EmployeeIssueOperation, 2); writeoff.UpdateOperations(uow); uow.Save(writeoff); uow.Commit(); var repository = new EmployeeIssueRepository(uow); var result = repository.GetReferencedDocuments(writeoffItem.EmployeeWriteoffOperation.Id); Assert.That(result.First().DocumentType, Is.EqualTo(StokDocumentType.WriteoffDoc)); Assert.That(result.First().DocumentId, Is.EqualTo(writeoff.Id)); Assert.That(result.First().ItemId, Is.EqualTo(writeoffItem.Id)); } }
public static List <SWDetailsHelper> GetListByEntity(Writeoff writeoff) { List <WriteoffDetails> writeoffDetails = WriteoffDetailsController.instance().Collection.Where(x => x.IdWriteoff == writeoff.Id).ToList(); List <SWDetailsHelper> swdHelperList = new List <SWDetailsHelper>(); for (int i = 0; i < writeoffDetails.Count; i++) { SWDetailsHelper swdHelper = new SWDetailsHelper(); swdHelper.Count = writeoffDetails[i].DetailsCount; Details detail = DetailsController.instance().getById(writeoffDetails[i].IdDetails); if (detail == null) { continue; } swdHelper.Name = detail.Name; swdHelper.VendorCode = detail.VendorCode; swdHelper.OvenName = detail.OvenName; swdHelperList.Add(swdHelper); } return(swdHelperList); }
public void UpdateOperations_EmployeeIssueOperation_CanChangeWearPercentTest() { var uow = Substitute.For <IUnitOfWork>(); var nomeclature = Substitute.For <Nomenclature>(); var employee = Substitute.For <EmployeeCard>(); var issueOperation = new EmployeeIssueOperation { OperationTime = new DateTime(2019, 1, 1), StartOfUse = new DateTime(2019, 1, 1), Issued = 10, Nomenclature = nomeclature, WearPercent = 0, ExpiryByNorm = new DateTime(2019, 1, 15), Employee = employee }; var writeoff = new Writeoff { Date = new DateTime(2019, 1, 15) }; writeoff.AddItem(issueOperation, 2); Assert.That(writeoff.Items[0].WearPercent, Is.EqualTo(1)); //Меняем значение процента износа writeoff.Items[0].WearPercent = 2; //Выполняем writeoff.UpdateOperations(uow); Assert.That(writeoff.Items[0].WearPercent, Is.EqualTo(2)); }
public void UpdateOperations_WarehouseOperation_CanChangeWearPercentTest() { var uow = Substitute.For <IUnitOfWork>(); var nomeclature = Substitute.For <Nomenclature>(); var warehouse = Substitute.For <Warehouse>(); var position = new StockPosition(nomeclature, 0.2m, new Size(), new Size()); var writeoff = new Writeoff { Date = new DateTime(2019, 1, 15) }; writeoff.AddItem(position, warehouse, 2); Assert.That(writeoff.Items[0].WearPercent, Is.EqualTo(0.2m)); //Меняем значение процента износа writeoff.Items[0].WearPercent = 2; //Выполняем writeoff.UpdateOperations(uow); Assert.That(writeoff.Items[0].WearPercent, Is.EqualTo(2)); }
protected IQueryOver <Writeoff> QueryWriteoffDoc(IUnitOfWork uow, bool isCounting) { if (Filter.StokDocumentType != null && Filter.StokDocumentType != StokDocumentType.WriteoffDoc) { return(null); } WriteoffItem writeoffItemAlias = null; Writeoff writeoffAlias = null; var writeoffQuery = uow.Session.QueryOver <Writeoff>(() => writeoffAlias); if (Filter.StartDate.HasValue) { writeoffQuery.Where(o => o.Date >= Filter.StartDate.Value); } if (Filter.EndDate.HasValue) { writeoffQuery.Where(o => o.Date < Filter.EndDate.Value.AddDays(1)); } if (Filter.Warehouse != null) { writeoffQuery.Where(() => writeoffItemAlias.Warehouse == Filter.Warehouse); } writeoffQuery.Where(GetSearchCriterion( () => writeoffAlias.Id, () => authorAlias.Name )); var concatProjection = Projections.SqlFunction( new SQLFunctionTemplate(NHibernateUtil.String, "GROUP_CONCAT(DISTINCT ?1 SEPARATOR ?2)"), NHibernateUtil.String, Projections.Property(() => warehouseExpenseAlias.Name), Projections.Constant(", ")); if (!isCounting) { writeoffQuery .JoinAlias(() => writeoffAlias.Items, () => writeoffItemAlias, NHibernate.SqlCommand.JoinType.LeftOuterJoin) .JoinAlias(() => writeoffItemAlias.Warehouse, () => warehouseExpenseAlias, NHibernate.SqlCommand.JoinType.LeftOuterJoin); } writeoffQuery .JoinAlias(() => writeoffAlias.CreatedbyUser, () => authorAlias, NHibernate.SqlCommand.JoinType.LeftOuterJoin) .SelectList(list => list .SelectGroup(() => writeoffAlias.Id).WithAlias(() => resultAlias.Id) .Select(() => writeoffAlias.Date).WithAlias(() => resultAlias.Date) .Select(() => authorAlias.Name).WithAlias(() => resultAlias.Author) .Select(concatProjection).WithAlias(() => resultAlias.ExpenseWarehouse) .Select(() => StokDocumentType.WriteoffDoc).WithAlias(() => resultAlias.DocTypeEnum) .Select(() => writeoffAlias.Comment).WithAlias(() => resultAlias.Comment) .Select(() => writeoffAlias.CreationDate).WithAlias(() => resultAlias.CreationDate) ) .OrderBy(() => writeoffAlias.Date).Desc .ThenBy(() => writeoffAlias.CreationDate).Desc .TransformUsing(Transformers.AliasToBean <StockDocumentsJournalNode>()); return(writeoffQuery); }
public WriteoffModelView Save(WriteoffModelView Writeoff) { Writeoff WriteoffDb = WriteoffViewModelToDb(Writeoff); _dataManager.Writeoffs.Save(WriteoffDb); return(WriteoffViewDbToModel(WriteoffDb)); }
private WriteoffModelView WriteoffViewDbToModel(Writeoff writeoff) { return(new WriteoffModelView { Id = writeoff.Id, Date = writeoff.Date, Comment = writeoff.Comment }); }
protected override void populate(SQLiteDataReader reader) { Writeoff writeoff = new Writeoff(); writeoff.Id = reader.GetInt32(0); writeoff.WriteoffDate = reader.GetDateTime(1); writeoff.AppNumber = reader.GetString(2); writeoff.IdRecipient = reader.GetInt32(3); add(writeoff); }
private WriteoffModelEdit WriteoffEditDbToModel(Writeoff writeoff) { return(new WriteoffModelEdit { Id = writeoff.Id, Date = writeoff.Date, Comment = writeoff.Comment, ProductCounts = writeoff.ProductCounts.Select(ProductCountDbToModel).ToList() }); }
private void WriteoffCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add && e.NewItems != null) { for (int i = 0; i < e.NewItems.Count; i++) { Writeoff writeoff = e.NewItems[i] as Writeoff; add(SWHelper.Create(writeoff)); } } }
public WriteoffModelEdit Save(WriteoffModelEdit Writeoff) { Writeoff WriteoffDb = WriteoffEditModelToDb(Writeoff); _dataManager.Writeoffs.Save(WriteoffDb); foreach (var productCount in WriteoffDb.ProductCounts) { _dataManager.ProductCounts.Save(productCount); } return(WriteoffEditDbToModel(WriteoffDb)); }
public static SWHelper Create(Writeoff writeoff) { SWHelper swHelper = new SWHelper(); swHelper.Id = writeoff.Id; swHelper.TName = writeoff.TName; swHelper.OperationDate = writeoff.WriteoffDate; swHelper.AppNumber = writeoff.AppNumber; swHelper.IdRecipient = writeoff.IdRecipient; swHelper.TWriteoff = writeoff; return(swHelper); }
public bool add <T>(T model) { try { Writeoff writeoff = model as Writeoff; _collection.Add(writeoff); return(true); } catch (Exception ex) { Log.WriteError(ex.Message); return(false); } }
public bool remove <T>(T model) { try { Writeoff writeoff = model as Writeoff; if (_collection.Contains(writeoff)) { _collection.Remove(writeoff); } return(true); } catch (Exception ex) { Log.WriteError(ex.Message); return(false); } }
public void WriteoffMainTest() { var ask = Substitute.For <IInteractiveQuestion>(); ask.Question(string.Empty).ReturnsForAnyArgs(true); var baseParameters = Substitute.For <BaseParameters>(); using (var uow = UnitOfWorkFactory.CreateWithoutRoot()) { var warehouse = new Warehouse(); uow.Save(warehouse); var nomenclatureType = new ItemsType { Name = "Тестовый тип номенклатуры" }; uow.Save(nomenclatureType); var nomenclature = new Nomenclature { Type = nomenclatureType }; uow.Save(nomenclature); var size = new Size(); var height = new Size(); uow.Save(size); uow.Save(height); var position1 = new StockPosition(nomenclature, 0, size, height); var protectionTools = new ProtectionTools { Name = "СИЗ для тестирования" }; protectionTools.AddNomeclature(nomenclature); uow.Save(protectionTools); var employee = new EmployeeCard(); uow.Save(employee); uow.Commit(); var income = new Income { Warehouse = warehouse, Date = new DateTime(2017, 1, 1), Operation = IncomeOperations.Enter }; var incomeItem1 = income.AddItem(nomenclature); incomeItem1.Amount = 10; income.UpdateOperations(uow, ask); uow.Save(income); var expense = new Expense { Operation = ExpenseOperations.Employee, Warehouse = warehouse, Employee = employee, Date = new DateTime(2018, 10, 22) }; var item = expense.AddItem(position1, 3); //Обновление операций expense.UpdateOperations(uow, baseParameters, ask); uow.Save(expense); uow.Commit(); var balance = EmployeeRepository.ItemsBalance(uow, employee, new DateTime(2018, 10, 30)); Assert.That(balance.First().Amount, Is.EqualTo(3)); //Списываем var writeoff = new Writeoff { Date = new DateTime(2018, 10, 25) }; writeoff.AddItem(item.EmployeeIssueOperation, 1); //Обновление операций writeoff.UpdateOperations(uow); uow.Save(writeoff); uow.Commit(); var balanceAfter = EmployeeRepository.ItemsBalance(uow, employee, new DateTime(2018, 10, 30)); Assert.That(balanceAfter.First().Amount, Is.EqualTo(2)); } }
private void saveWriteoff() { if (cbxRecipients.SelectedIndex == -1) { System.Windows.MessageBox.Show("Выберите получателя!"); return; } if (tbxAppNumber.Text == "") { System.Windows.MessageBox.Show("Введите номер заявки!"); return; } if (wodh_collection.Collection.Count == 0) { System.Windows.MessageBox.Show("Невозможно сохранить пустое списание!"); return; } if (System.Windows.MessageBox.Show("Подтвердите списание", "Подтвердите списание", MessageBoxButton.YesNo) != MessageBoxResult.Yes) { return; } if (!wodh_collection.isAllCorrect()) { System.Windows.MessageBox.Show("Проверьте введенные данные!\nОдна или более строк заполнены некорректно!"); return; } Writeoff writeoff = new Writeoff(); writeoff.WriteoffDate = DateTime.Now; writeoff.AppNumber = tbxAppNumber.Text; writeoff.IdRecipient = (int)cbxRecipients.SelectedValue; if (writeoff.save()) { for (int i = 0; i < wodh_collection.Collection.Count; i++) { WriteoffDetailsHelper wodh = wodh_collection.Collection[i]; if (wodh.IdDetails == 0) { continue; } WriteoffDetails writeoffDetails = new WriteoffDetails(); writeoffDetails.IdDetails = wodh.IdDetails; writeoffDetails.IdWriteoff = writeoff.Id; writeoffDetails.DetailsCount = wodh.DetailsCount; if (!writeoffDetails.save()) { System.Windows.MessageBox.Show("При сохранении элементов списания произошли ошибки."); writeoff.remove(); return; } } ///Update current count //wodh_collection.Collection.Count-1 - т.к. последняя строка пустая for (int i = 0; i < wodh_collection.Collection.Count - 1; i++) { wodh_collection.Collection[i].Detail.CurrentCount = 0; } wodh_collection.clear(); cbxRecipients.SelectedIndex = -1; tbxAppNumber.Text = ""; WriteoffDetailsHelper newWriteoffDetailsHelper = new WriteoffDetailsHelper(); wodh_collection.add(newWriteoffDetailsHelper); } else { System.Windows.MessageBox.Show("При сохранении списания произошли ошибки."); return; } }
public void add(Writeoff writeoff) { _collection.Add(SWHelper.Create(writeoff)); }