private void detach_InvoiceItem(InvoiceItem entity) { this.SendPropertyChanging(); entity.Invoice = null; }
private void attach_InvoiceItem(InvoiceItem entity) { this.SendPropertyChanging(); entity.Invoice = this; }
partial void DeleteInvoiceItem(InvoiceItem instance);
partial void UpdateInvoiceItem(InvoiceItem instance);
partial void InsertInvoiceItem(InvoiceItem instance);
/// <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; }