public IWarehouseCatalog BuildEntity(WarehouseCatalogDto dto) { var entity = new WarehouseCatalog(dto.WarehouseKey) { Key = dto.Key, Name = dto.Name, Description = dto.Description, UpdateDate = dto.UpdateDate, CreateDate = dto.CreateDate }; entity.ResetDirtyProperties(); return(entity); }
/// <summary> /// Creates warehouse catalog and persists it to the database. /// </summary> /// <param name="warehouseKey"> /// The warehouse key. /// </param> /// <param name="name"> /// The name. /// </param> /// <param name="description"> /// The description. /// </param> /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param> /// <returns> /// The <see cref="IWarehouseCatalog"/>. /// </returns> public IWarehouseCatalog CreateWarehouseCatalogWithKey( Guid warehouseKey, string name, string description = "", bool raiseEvents = true) { Mandate.ParameterCondition(!warehouseKey.Equals(Guid.Empty), "warehouseKey"); var catalog = new WarehouseCatalog(warehouseKey) { Name = name, Description = description }; if (raiseEvents) { if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs <IWarehouseCatalog>(catalog), this)) { catalog.WasCancelled = true; return(catalog); } } using (new WriteLock(Locker)) { var uow = UowProvider.GetUnitOfWork(); using (var repository = RepositoryFactory.CreateWarehouseCatalogRepository(uow)) { repository.AddOrUpdate(catalog); uow.Commit(); } } if (raiseEvents) { Created.RaiseEvent(new Events.NewEventArgs <IWarehouseCatalog>(catalog), this); } return(catalog); }
public void Can_Add_A_Catalog_To_The_Default_Warehouse() { //// Arrange var warehouse = _warehouseService.GetDefaultWarehouse(); //// Act var catalog = new WarehouseCatalog(warehouse.Key) { Name = "2nd Catalog" }; _warehouseService.Save(catalog); var catalogs = _warehouseService.GetAllWarehouseCatalogs(); warehouse = _warehouseService.GetDefaultWarehouse(); //// Assert Assert.IsTrue(catalog.HasIdentity, "catalog does not have an identity"); Assert.NotNull(catalogs, "Catalogs was null"); Assert.IsTrue(catalogs.Any(), "Catalogs collection was empty"); Assert.IsTrue(warehouse.WarehouseCatalogs.Count() > 1); }
/// <summary> /// Creates warehouse catalog and persists it to the database. /// </summary> /// <param name="warehouseKey"> /// The warehouse key. /// </param> /// <param name="name"> /// The name. /// </param> /// <param name="description"> /// The description. /// </param> /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param> /// <returns> /// The <see cref="IWarehouseCatalog"/>. /// </returns> public IWarehouseCatalog CreateWarehouseCatalogWithKey( Guid warehouseKey, string name, string description = "", bool raiseEvents = true) { Mandate.ParameterCondition(!warehouseKey.Equals(Guid.Empty), "warehouseKey"); var catalog = new WarehouseCatalog(warehouseKey) { Name = name, Description = description }; if (raiseEvents) if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs<IWarehouseCatalog>(catalog), this)) { catalog.WasCancelled = true; return catalog; } using (new WriteLock(Locker)) { var uow = UowProvider.GetUnitOfWork(); using (var repository = RepositoryFactory.CreateWarehouseCatalogRepository(uow)) { repository.AddOrUpdate(catalog); uow.Commit(); } } if (raiseEvents) Created.RaiseEvent(new Events.NewEventArgs<IWarehouseCatalog>(catalog), this); return catalog; }
public SalesDocumentNode CreateSalesDocument(Order order) { var exportSaleDocument = new SalesDocumentNode { Id = ++objectCounter }; exportSaleDocument.Reference = new ReferenceNode(exportSaleDocument.Id, new PropertyNode("Номер", Common1cTypes.String, ExportMode == Export1cMode.IPForTinkoff ? order.OnlineOrder.Value : order.Id), new PropertyNode("Дата", Common1cTypes.Date, order.DeliveryDate.Value.ToString("s")) ); var exportGoodsTable = new TableNode { Name = "Товары", }; var exportServicesTable = new TableNode { Name = "Услуги", }; foreach (var orderItem in order.OrderItems) { var record = CreateRecord(orderItem); if (Nomenclature.GetCategoriesForGoods().Contains(orderItem.Nomenclature.Category)) { exportGoodsTable.Records.Add(record); exportSaleDocument.Comission.Comissions.Add(0); } else { exportServicesTable.Records.Add(record); } } exportSaleDocument.Properties.Add( new PropertyNode("Организация", Common1cTypes.ReferenceOrganization, OrganizationCatalog.CreateReferenceTo(order.Contract.Organization) ) ); exportSaleDocument.Properties.Add( new PropertyNode("Комментарий", Common1cTypes.String, order.Comment ) ); exportSaleDocument.Properties.Add( new PropertyNode("Склад", Common1cTypes.ReferenceWarehouse, WarehouseCatalog.CreateReferenceTo(Warehouse1c.Default) ) ); exportSaleDocument.Properties.Add( new PropertyNode("Контрагент", Common1cTypes.ReferenceCounterparty, CounterpartyCatalog.CreateReferenceTo(order.Client) ) ); exportSaleDocument.Properties.Add( new PropertyNode("ДоговорКонтрагента", Common1cTypes.ReferenceContract, ContractCatalog.CreateReferenceToContract(order) ) ); exportSaleDocument.Properties.Add( new PropertyNode("ВалютаДокумента", Common1cTypes.ReferenceCurrency, CurrencyCatalog.CreateReferenceTo(OldExportTo1c.Currency.Default) ) ); exportSaleDocument.Properties.Add( new PropertyNode("УчитыватьНДС", Common1cTypes.Boolean, "true" ) ); exportSaleDocument.Properties.Add( new PropertyNode("СуммаВключаетНДС", Common1cTypes.Boolean, "true" ) ); exportSaleDocument.Properties.Add( new PropertyNode("ВидОперации", "ПеречислениеСсылка.ВидыОперацийРеализацияТоваров", "ПродажаКомиссия" ) ); exportSaleDocument.Properties.Add( new PropertyNode("КурсВзаиморасчетов", Common1cTypes.Numeric, 1 ) ); exportSaleDocument.Properties.Add( new PropertyNode("КратностьВзаиморасчетов", Common1cTypes.Numeric, 1 ) ); exportSaleDocument.Tables.Add(exportGoodsTable); exportSaleDocument.Tables.Add(exportServicesTable); return(exportSaleDocument); }
public void CreateRetailDocument(Order order) { if (!order.DeliveryDate.HasValue) { throw new ArgumentNullException(nameof(order.DeliveryDate)); } if (!RetailDocumentsList.TryGetValue(order.DeliveryDate.Value.Date, out RetailDocumentNode exportRetailDocument)) { exportRetailDocument = new RetailDocumentNode { Id = ++objectCounter }; exportRetailDocument.Reference = new ReferenceNode( exportRetailDocument.Id, new PropertyNode( "Номер", Common1cTypes.String, ExportMode == Export1cMode.IPForTinkoff ? (order.OnlineOrder ?? throw new ArgumentNullException(nameof(order.OnlineOrder), $@"(OrderId: {order.Id})")) : order.Id), new PropertyNode( "Дата", Common1cTypes.Date, order.DeliveryDate.Value.Date.ToString("s")) ); var exportGoodsTable = new TableNode { Name = "Товары", }; var exportRefundGoodsTable = new TableNode { Name = "Возвраты", }; var exportTerminalTable = new TableNode { Name = "Оплата", }; var exportRefundTerminalTable = new TableNode { Name = "ВозвратОплаты", }; exportRetailDocument.Properties.Add( new PropertyNode("Организация", Common1cTypes.ReferenceOrganization, OrganizationCatalog.CreateReferenceTo(order.Contract.Organization)) ); exportRetailDocument.Properties.Add( new PropertyNode("Комментарий", Common1cTypes.String, order.Comment ) ); exportRetailDocument.Properties.Add( new PropertyNode("Склад", Common1cTypes.ReferenceWarehouse, WarehouseCatalog.CreateReferenceTo(Warehouse1c.Default) ) ); exportRetailDocument.Properties.Add( new PropertyNode("ВалютаДокумента", Common1cTypes.ReferenceCurrency, CurrencyCatalog.CreateReferenceTo(ExportTo1c.Currency.Default) ) ); exportRetailDocument.Properties.Add( new PropertyNode("СуммаВключаетНДС", Common1cTypes.Boolean, "true" ) ); exportRetailDocument.Properties.Add( new PropertyNode("ВидОперации", "ПеречислениеСсылка.ВидыОперацийОтчетОРозничныхПродажах", "ОтчетККМОПродажах" ) ); exportRetailDocument.Tables.Add(exportGoodsTable); exportRetailDocument.Tables.Add(exportTerminalTable); exportRetailDocument.Tables.Add(exportRefundGoodsTable); exportRetailDocument.Tables.Add(exportRefundTerminalTable); } bool isTerminalPaid = (order.PaymentType == PaymentType.ByCard || order.PaymentType == PaymentType.Terminal); bool isRefund = false; foreach (var orderItem in order.OrderItems) { isRefund = (orderItem.ActualSum < 0); if (orderItem.ActualSum != 0) { var record = CreateRetailRecord(orderItem); exportRetailDocument.Tables[0].Records.Add(record); //Товары if (isRefund) { exportRetailDocument.Tables[2].Records.Add(record); } if (isTerminalPaid) { var recordPayment = new TableRecordNode(); recordPayment.Properties.Add( new PropertyNode("СуммаОплаты", Common1cTypes.Numeric, orderItem.ActualSum ) ); //оплаты безналом exportRetailDocument.Tables[1].Records.Add(recordPayment); if (isRefund) { exportRetailDocument.Tables[3].Records.Add(recordPayment); } } } } if (!RetailDocumentsList.ContainsKey(order.DeliveryDate.Value.Date)) { RetailDocumentsList.Add(order.DeliveryDate.Value.Date, exportRetailDocument); } }