Beispiel #1
0
        /// <summary>
        /// Fügt dem Grosskunden eine neue Kostenstelle hinzu,
        /// </summary>
        /// <param name="name">Name der Kostenstelle.</param>
        /// <param name="costcenterNumber">Kostenstellennummer.</param>
        /// <param name="dbContext">Datenbankkontext für die Transaktion.</param>
        /// <returns>Die neue Kostenstelle.</returns>
        public CostCenter AddNewCostCenter(string name, string costcenterNumber, DataClasses1DataContext dbContext)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("Der Name der Kostenstelle darf nicht leer sein.");
            }

            if (string.IsNullOrEmpty(costcenterNumber))
            {
                throw new ArgumentNullException("Die Kostenstellennummer darf nicht leer sein.");
            }

            if (this.CostCenter.Any(q => q.Name == name))
            {
                throw new Exception("Der Kunde " + this.Customer.Name + " besitzt bereits eine Kostenstelle mit Namen " + name + ".");
            }

            CostCenter costcenter = new CostCenter()
            {
                Name = name,
                CostcenterNumber = costcenterNumber
            };
            costcenter._dbContext = dbContext;
            this.CostCenter.Add(costcenter);
            dbContext.SubmitChanges();
            dbContext.WriteLogItem("Neue Kostenstelle " + name + " angelegt.", LogTypes.INSERT, this.CustomerId, "Customer", costcenter.Id);
            return costcenter;
        }
		private void detach_CostCenter(CostCenter entity)
		{
			this.SendPropertyChanging();
			entity.BankAccount = null;
		}
Beispiel #3
0
        /// <summary>
        /// Fügt dem Auftrag eine neue Position hinzu.
        /// </summary>
        /// <param name="productId">Id des Produkts.</param>
        /// <param name="priceAmount">Preis für die Position.</param>
        /// <param name="count">Anzahl für die Position.</param>
        /// <param name="costCenterId">Id der Kostenstelle, falls benötigt.</param>
        /// <param name="superOrderItemId">Id der übergeordneten Auftragsposition, falls benoetigt.</param>
        /// <param name="isAuthorativeCharge">Gibt an, ob es sich um eine behoerdliche Gebühr handelt oder nicht.</param>
        /// <param name="dbContext">Datenbankkontext für die Transaktion.</param>
        /// <returns>Die neue Auftragsposition.</returns>
        public OrderItem AddOrderItem(int productId, decimal priceAmount, int count, CostCenter costCenter, int? superOrderItemId, bool isAuthorativeCharge, DataClasses1DataContext dbContext)
        {
            var product = dbContext.Product.Where(q => q.Id == productId).Single();
            OrderItem item = new OrderItem()
            {
                Amount = priceAmount,
                CostCenter = costCenter,
                ProductId = productId,
                Status = (int)OrderItemStatusTypes.Open,
                ProductName = product.Name,
                SuperOrderItemId = superOrderItemId,
                Count = count,
                IsAuthorativeCharge = isAuthorativeCharge,
                NeedsVAT = isAuthorativeCharge ? false : product.NeedsVAT
            };

            this.OrderItem.Add(item);
            dbContext.SubmitChanges();
            dbContext.WriteLogItem("Auftragsposition " + product.Name + " für Auftrag " + this.OrderNumber + " angelegt.", LogTypes.INSERT, item.Id, "OrderItem");
            return item;
        }
 partial void DeleteCostCenter(CostCenter instance);
 partial void UpdateCostCenter(CostCenter instance);
 partial void InsertCostCenter(CostCenter instance);
		private void detach_CostCenter(CostCenter entity)
		{
			this.SendPropertyChanging();
			entity.LargeCustomer = null;
		}
Beispiel #8
0
        /// <summary>
        /// Fügt der Rechnung eine neue Rechnungsposition hinzu.
        /// </summary>
        /// <param name="name">Bezeichnung für die Rechnungsposition.</param>
        /// <param name="amount">Betrag der Rechnungsposition.</param>
        /// <param name="count">Anzahl für die Position.</param>
        /// <param name="orderItemId">Id der Auftragsposition, falls vorhande.</param>
        /// <param name="costCenterId">Id der Kostenstelle, falls benötigt.</param>
        /// <param name="dbContext">Datenbankkontext für die Transaktion.</param>
        /// <returns>Die neue Rechnungsposition.</returns>
        public InvoiceItem AddInvoiceItem(string name, decimal amount, int count, OrderItem orderItem, CostCenter costCenter, DataClasses1DataContext dbContext)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new Exception("Die Bezeichnung der Rechnungsposition darf nicht leer sein.");
            }

            if (this.IsPrinted)
            {
                throw new Exception("Die Rechnungsposition kann nicht hinzugefügt werden: Die Rechnung ist bereits gedruckt.");
            }

            Customer customer = dbContext.Customer.Single(q => q.Id == this.CustomerId);
            InvoiceItem item = new InvoiceItem()
            {
                Amount = amount,
                Count = count,
                Name = name,
                OrderItem = orderItem,
                CostCenter = costCenter
            };

            this.InvoiceItem.Add(item);
            dbContext.SubmitChanges();
            dbContext.WriteLogItem("Rechnungsposition " + name + " zur Rechnung hinzugefügt.", LogTypes.INSERT, this.Id, "InvoiceItem", item.Id);
            if (orderItem != null)
            {
                if (orderItem.Status == (int)OrderItemStatusTypes.Payed)
                {
                    throw new Exception("Die Auftragsposition ist bereits abgerechnet.");
                }

                if (orderItem.Status != (int)OrderItemStatusTypes.Closed)
                {
                    throw new Exception("Die Auftragsposition ist nicht abgeschlossen.");
                }

                if (orderItem.Order.LocationId.HasValue && this.OrderInvoice.Any(q => q.Order.LocationId != orderItem.Order.LocationId))
                {
                    throw new Exception("Die Auftragsposition kann nicht zur Rechnung hinzugefügt werden, da der Standort des Auftrags nicht mit dem Standort der bisherigen Aufträge in der Rechnung übereinstimmt.");
                }

                if (orderItem.NeedsVAT)
                {
                    if (orderItem.Order.Location != null && orderItem.Order.Location.VAT.HasValue) //Großkunde
                    {
                        item.VAT = orderItem.Order.Location.VAT.Value;
                    }
                    else //SofortKunde
                    {
                        item.VAT = customer.VAT;
                    }
                }

                orderItem.LogDBContext = dbContext;
                orderItem.Status = (int)OrderItemStatusTypes.Payed;
                var order = orderItem.Order;
                if (!dbContext.OrderInvoice.Any(q => q.OrderNumber == order.OrderNumber && q.InvoiceId == this.Id))
                {
                    Database.OrderInvoice.CreateOrderInvoice(order, this, dbContext);
                }
            }
            else
            {
                item.VAT = customer.VAT;
            }

            return item;
        }