Example #1
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;
        }
Example #2
0
 partial void UpdateOrderItem(OrderItem instance);
Example #3
0
 partial void DeleteOrderItem(OrderItem instance);
Example #4
0
 partial void InsertOrderItem(OrderItem instance);
Example #5
0
		private void detach_OrderItem(OrderItem entity)
		{
			this.SendPropertyChanging();
			entity.OrderItemStatus = null;
		}
Example #6
0
		private void detach_OrderItem(OrderItem entity)
		{
			this.SendPropertyChanging();
			entity.CostCenter = null;
		}
Example #7
0
		private void attach_OrderItem(OrderItem entity)
		{
			this.SendPropertyChanging();
			entity.Product = this;
		}
Example #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;
        }