Пример #1
0
        /// <summary>
        /// Erstelle zu der jeweiligen Rechnung ein neues Erlöskonto
        /// </summary>
        /// <param name="dbContext">DB Kontext</param>
        /// <param name="inv">Rechnungsobjekt</param>
        public static void CreateAccounts(DataClasses1DataContext dbContext, Invoice inv)
        {
            List<_Accounts> acc = null;
             acc = Accounts.generateAccountNumber(dbContext,inv.Id).ToList();

             if (acc != null && acc.Count() == inv.InvoiceItem.Count)
             {
                 foreach (var thisItems in acc)
                 {
                     var myAccount = new InvoiceItemAccountItem
                     {
                         InvoiceItemId = thisItems.InvoiceItemId,
                         RevenueAccountText = thisItems.AccountNumber
                     };
                     var contains = dbContext.InvoiceItemAccountItem.FirstOrDefault(q => q.InvoiceItemId ==
                         thisItems.InvoiceItemId && q.RevenueAccountText == thisItems.AccountNumber.Trim());
                     if (contains != null)
                     {
                         contains.RevenueAccountText = thisItems.AccountNumber.Trim();
                     }
                     else
                     {
                         dbContext.InvoiceItemAccountItem.InsertOnSubmit(myAccount);
                     }
                     dbContext.SubmitChanges();
                 }
             }
             else
             {
                 throw new Exception("Die Rechnung konnte nicht gedruckt werden, da nicht alle Dienstleistungen ein Erlöskonto haben! Sie können die Erlöskonten im Reiter 'Rechnung erstellen' zuweisen und die Rechnung erneut drucken.");
             }
        }
Пример #2
0
        /// <summary>
        /// Erstellt eine Verknuepfung zwischen einem Auftrag und einer Rechnung.
        /// </summary>
        /// <param name="OrderNumber">Id des Auftrags.</param>
        /// <param name="invoiceId">Id der Rechnung.</param>
        /// <param name="dbContext">Datenbankkontext für die Transaktion.</param>
        /// <returns>Die neue Verknüpfung.</returns>
        public static OrderInvoice CreateOrderInvoice(Order order, Invoice invoice, DataClasses1DataContext dbContext)
        {
            OrderInvoice item = new OrderInvoice()
            {
                Order = order,
                Invoice = invoice
            };

            dbContext.OrderInvoice.InsertOnSubmit(item);
            ///  var invoiceNumber = dbContext.Invoice.Where(q => q.Id == invoiceId).Select(q => q.InvoiceNumber).Single();
            var orderNumber = dbContext.Order.Where(q => q.OrderNumber == order.OrderNumber).Select(q => q.OrderNumber).Single();
            dbContext.WriteLogItem("Rechnung wurde mit Auftrag " + orderNumber + " verknüpft.", LogTypes.INSERT, order.OrderNumber, "OrderInvoice", invoice.Id);
            return item;
        }
Пример #3
0
        /// <summary>
        /// Standardkonstruktort fuer die Klasse InvoicePDF
        /// </summary>
        /// <param name="dbContext">DB Kontext</param>
        /// <param name="invoice">Rechnungsobjekt</param>
        /// <param name="logoFilePath">Pfad zum Logo</param>
        public InvoicePDF(DataClasses1DataContext dbContext, Invoice invoice, string logoFilePath)
            : base(dbContext, logoFilePath, true)
        {
            _dbContext = dbContext;
            this.Invoice = invoice;

            this.Letterhead = new LetterHead(dbContext);
            this.Letterhead.Lines = new List<string>();
            if (invoice.Customer.LargeCustomer != null)
            {
                this.Letterhead.Lines.Add(invoice.Customer.Name);
            }
            if (invoice.InvoiceRecipient != string.Empty)
            {
                this.Letterhead.Lines.Add(invoice.InvoiceRecipient);
            }
            else
            {
                if (this.Invoice.Customer != null && this.Invoice.Customer.SmallCustomer != null && this.Invoice.Customer.SmallCustomer.Person != null)
                {
                    this.Letterhead.Lines.Add(this.Invoice.Customer.SmallCustomer.Person.Name+ " " + this.Invoice.Customer.SmallCustomer.Person.FirstName);
                }
                if (this.Invoice.Customer != null && this.Invoice.Customer.LargeCustomer != null && this.Invoice.Customer.LargeCustomer.Person != null)
                {
                    this.Letterhead.Lines.Add(this.Invoice.Customer.LargeCustomer.Person.Name);
                }
            }
            if (invoice.Adress != null)
            {
                    if(invoice.Adress.Street != string.Empty || invoice.Adress.StreetNumber != string.Empty)
                    this.Letterhead.Lines.Add(invoice.Adress.Street + " " + invoice.Adress.StreetNumber);
                    if (invoice.Adress.Zipcode != string.Empty || invoice.Adress.City != string.Empty)
                    this.Letterhead.Lines.Add(invoice.Adress.Zipcode + " " + invoice.Adress.City);
                    if (invoice.Adress.Country != string.Empty)
                    this.Letterhead.Lines.Add(invoice.Adress.Country);
             }

            this.Headline = "Rechnung";
        }
 protected void Print(Invoice newInvoice,  DataClasses1DataContext dbContext)
 {
     using (MemoryStream memS = new MemoryStream())
     {
         InvoiceHelper.CreateAccounts(dbContext, newInvoice);
         newInvoice.Print(dbContext, memS, "");
         dbContext.SubmitChanges();
         string fileName = "Rechnung_" +newInvoice.InvoiceNumber.Number+ "_"+ newInvoice.CreateDate.Day + "_" + newInvoice.CreateDate.Month + "_" + newInvoice.CreateDate.Year + ".pdf";
         string serverPath = ConfigurationManager.AppSettings["DataPath"] + "\\UserData";
         if (!Directory.Exists(serverPath)) Directory.CreateDirectory(serverPath);
         if (!Directory.Exists(serverPath + "\\" + Session["CurrentUserId"].ToString())) Directory.CreateDirectory(serverPath + "\\" + Session["CurrentUserId"].ToString());
         serverPath = serverPath + "\\" + Session["CurrentUserId"].ToString();
         File.WriteAllBytes(serverPath + "\\" + fileName, memS.ToArray());
         OpenPrintfile(fileName);
         dbContext.SubmitChanges();
     }
 }
Пример #5
0
 protected void Print(Invoice newInvoice, DataClasses1DataContext dbContext)
 {
     using (MemoryStream memS = new MemoryStream())
     {
         string serverPath = ConfigurationManager.AppSettings["DataPath"] + "\\UserData";
         InvoiceHelper.CreateAccounts(dbContext, newInvoice);
         newInvoice.Print(dbContext, memS, "");
         string fileName = "Rechnung_" + newInvoice.InvoiceNumber.Number + "_" + newInvoice.CreateDate.Day + "_" + newInvoice.CreateDate.Month + "_" + newInvoice.CreateDate.Year + ".pdf";
         if (!Directory.Exists(serverPath)) Directory.CreateDirectory(serverPath);
         if (!Directory.Exists(serverPath + "\\" + Session["CurrentUserId"].ToString())) Directory.CreateDirectory(serverPath + "\\" + Session["CurrentUserId"].ToString());
         serverPath = serverPath + "\\" + Session["CurrentUserId"].ToString();
         File.WriteAllBytes(serverPath + "\\" + fileName, memS.ToArray());
         string url = ConfigurationManager.AppSettings["BaseUrl"];
         string path = url + "UserData/" + Session["CurrentUserId"].ToString() + "/" + fileName;
         ScriptManager.RegisterStartupScript(this, this.GetType(), "Invoice", "<script>openFile('" + path + "');</script>", false);
         dbContext.SubmitChanges();
     }
 }
Пример #6
0
		private void detach_Invoice(Invoice entity)
		{
			this.SendPropertyChanging();
			entity.Document = null;
		}
Пример #7
0
		private void attach_Invoice(Invoice entity)
		{
			this.SendPropertyChanging();
			entity.Document = this;
		}
Пример #8
0
		private void attach_Invoice(Invoice entity)
		{
			this.SendPropertyChanging();
			entity.Adress = this;
		}
Пример #9
0
		private void detach_Invoice(Invoice entity)
		{
			this.SendPropertyChanging();
			entity.Customer = null;
		}
Пример #10
0
		private void attach_Invoice(Invoice entity)
		{
			this.SendPropertyChanging();
			entity.Customer = this;
		}
Пример #11
0
		private void detach_Invoice(Invoice entity)
		{
			this.SendPropertyChanging();
			entity.InvoiceTypes = null;
		}
Пример #12
0
 partial void DeleteInvoice(Invoice instance);
Пример #13
0
 partial void UpdateInvoice(Invoice instance);
Пример #14
0
 partial void InsertInvoice(Invoice instance);
Пример #15
0
        /// <summary>
        /// Erstellt eine neue Rechnung.
        /// </summary>
        /// <param name="dbContext">Datenbankkontext für die Transaktion.</param>
        /// <param name="userId">Id des Benutzers.</param>
        /// <param name="invoiceRecipient">Rechnungsempfänger.</param>
        /// <param name="invoiceRecipientAdressId">Adresse des Rechnungsempfängers.</param>
        /// <param name="customerId">Id des Kunden.</param>
        /// <returns>Die neue Rechnung.</returns>
        public static Invoice CreateInvoice(DataClasses1DataContext dbContext, int userId, string invoiceRecipient, Adress invoiceRecipientAdress, int customerId, double? discount, string invTypeId)
        {
            //if (string.IsNullOrEmpty(invoiceRecipient))
            //{
            //    throw new ArgumentNullException("Der Rechnungsempfänger darf nicht leer sein.");
            //}

            decimal? helper = null;
            Invoice invoice = new Invoice()
            {
                CreateDate = DateTime.Now,
                IsPrinted = false,
                UserId = userId,
                InvoiceRecipient = invoiceRecipient,
                Adress = invoiceRecipientAdress,
                CustomerId = customerId,
                discount = ((discount.HasValue) ? decimal.Parse(discount.Value.ToString()) : helper),
                InvoiceType = GetInvoiceTypeId(dbContext, invTypeId)
            };

            dbContext.Invoice.InsertOnSubmit(invoice);
            dbContext.SubmitChanges();
            dbContext.WriteLogItem("Rechnung wurde angelegt.", LogTypes.INSERT, invoice.Id, "Invoice");
            return invoice;
        }