Index: branches/OaaS/HeuristicLab.Services.Optimization.Billing.Test/App.config
===================================================================
--- branches/OaaS/HeuristicLab.Services.Optimization.Billing.Test/App.config	(revision 9602)
+++ branches/OaaS/HeuristicLab.Services.Optimization.Billing.Test/App.config	(revision 9619)
@@ -5,4 +5,7 @@
     <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
   </configSections>
+  <appSettings>
+    <add key="BillingEngineInterval" value ="00:01:00"/>
+  </appSettings>
   <connectionStrings>
     <add name="BillingContext" connectionString="ADJUST_ME" providerName="System.Data.SqlClient" />
Index: branches/OaaS/HeuristicLab.Services.Optimization.Billing.Test/DDLScript.sql
===================================================================
--- branches/OaaS/HeuristicLab.Services.Optimization.Billing.Test/DDLScript.sql	(revision 9602)
+++ branches/OaaS/HeuristicLab.Services.Optimization.Billing.Test/DDLScript.sql	(revision 9619)
@@ -15,6 +15,9 @@
     [UserId] [bigint] not null,
     [OrderId] [bigint] not null,
+    [InvoiceDate] [datetime] not null,
     [Due] [datetime] not null,
     [StatusValue] [int] not null,
+    [Total] [float] not null,
+    [Tax] [float] not null,
     [InvoiceDocument] [nvarchar](max) null,
     primary key ([InvoiceId])
@@ -36,4 +39,6 @@
     [ActiveSince] [datetime] null,
     [ActiveUntil] [datetime] null,
+    [LastBillableDay] [datetime] null,
+    [NextBillableDay] [datetime] null,
     primary key ([OrderId])
 );
Index: branches/OaaS/HeuristicLab.Services.Optimization.Billing.Test/Program.cs
===================================================================
--- branches/OaaS/HeuristicLab.Services.Optimization.Billing.Test/Program.cs	(revision 9602)
+++ branches/OaaS/HeuristicLab.Services.Optimization.Billing.Test/Program.cs	(revision 9619)
@@ -1,5 +1,7 @@
 ﻿using System;
 using System.Data.Entity.Infrastructure;
+using System.Diagnostics;
 using System.IO;
+using System.Threading;
 using HeuristicLab.Services.Optimization.Billing.DataAccess;
 using HeuristicLab.Services.Optimization.Billing.Model;
@@ -7,4 +9,7 @@
 namespace HeuristicLab.Services.Optimization.Billing.Test {
   class Program {
+    private static BillingEngine.BillingEngine billingEngine;
+    private static Thread billingEngineThread;
+
     static void Main(string[] args) {
       string ddlScript;
@@ -25,4 +30,16 @@
       }
 
+      // Start BillingEngine Service:
+      Trace.WriteLine("Starting BillingEngine ...");
+      try {
+        billingEngine = new BillingEngine.BillingEngine();
+        billingEngineThread = new Thread(billingEngine.Run);
+        billingEngineThread.IsBackground = true; //dont keep app alive
+        billingEngineThread.Start();
+      }
+      catch (Exception e) {
+        Trace.WriteLine("Error during BillingEngine startup: " + e.Message);
+      }
+
       Console.WriteLine("Press any key to exit...");
       Console.ReadKey();
Index: branches/OaaS/HeuristicLab.Services.Optimization.Billing/App.config
===================================================================
--- branches/OaaS/HeuristicLab.Services.Optimization.Billing/App.config	(revision 9602)
+++ branches/OaaS/HeuristicLab.Services.Optimization.Billing/App.config	(revision 9619)
@@ -8,4 +8,7 @@
     <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
   </configSections>
+  <appSettings>
+    <add key="BillingEngineInterval" value ="00:01:00"/>
+  </appSettings>
   <entityFramework>
     <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
Index: branches/OaaS/HeuristicLab.Services.Optimization.Billing/BillingEngine/BillingEngine.cs
===================================================================
--- branches/OaaS/HeuristicLab.Services.Optimization.Billing/BillingEngine/BillingEngine.cs	(revision 9619)
+++ branches/OaaS/HeuristicLab.Services.Optimization.Billing/BillingEngine/BillingEngine.cs	(revision 9619)
@@ -0,0 +1,157 @@
+﻿
+using System;
+using System.Collections.Generic;
+using System.Configuration;
+using System.Diagnostics;
+using System.Linq;
+using System.Threading;
+using HeuristicLab.Services.Optimization.Billing.Business;
+using HeuristicLab.Services.Optimization.Billing.Interfaces;
+using HeuristicLab.Services.Optimization.Billing.Model;
+namespace HeuristicLab.Services.Optimization.Billing.BillingEngine {
+  public class BillingEngine {
+    private bool stop;
+    private AutoResetEvent waitHandle;
+    private TimeSpan interval;
+    private DateTime currentDate;
+
+    private IOptimizationBilling billingService;
+    public IOptimizationBilling BillingService {
+      get {
+        if (billingService == null) {
+          billingService = new BillingService();
+        }
+        return billingService;
+      }
+      set { billingService = value; }
+    }
+
+    private IInvoiceFormattingEngine invoiceFormattingEngine;
+    public IInvoiceFormattingEngine InvoiceFormattingEngine {
+      get {
+        if (invoiceFormattingEngine == null) {
+          invoiceFormattingEngine = new PlainTextInvoiceFormattingEngine();
+        }
+        return invoiceFormattingEngine;
+      }
+      set { invoiceFormattingEngine = value; }
+    }
+
+    public BillingEngine() {
+      stop = false;
+      interval = TimeSpan.Parse(ConfigurationManager.AppSettings["BillingEngineInterval"]);
+      waitHandle = new AutoResetEvent(true);
+    }
+
+    public void StopBillingEngine() {
+      stop = true;
+      waitHandle.Set();
+    }
+
+    public void Run() {
+      while (!stop) {
+        try {
+          Trace.WriteLine("[BillingEngine] Start billing cycle");
+          //currentDate = DateTime.Parse(DateTime.Now.ToShortDateString());
+          currentDate = DateTime.Now.Date;
+          Trace.WriteLine(string.Format("[BillingEngine] Current date: {0}", currentDate));
+          IList<Order> activeOrders = BillingService.GetOrdersByState(OrderState.Active);
+          Trace.WriteLine(string.Format("[BillingEngine] Processing {0} active orders.", activeOrders.Count));
+          foreach (Order order in activeOrders) {
+            if (!order.NextBillableDay.HasValue) {
+              // there has never been an invoice generated from this order 
+              order.NextBillableDay = currentDate;
+            }
+
+            if (order.NextBillableDay >= currentDate) {
+              // TODO: Embed everything in a transaction
+
+              // Collect Usage Data
+              //IList<UsageRecord> usageRecrods = BillingService.GetUsageRecords(order.User.Name, order.LastBillableDay.Value, currentDate);
+
+              // Collect Invoice Data
+              Invoice invoice = new Invoice();
+              invoice.Order = order;
+              invoice.User = order.User;
+              invoice.Due = currentDate.AddMonths(1);
+              invoice.InvoiceDate = currentDate;
+              invoice.Status = InvoiceStatus.Open;
+              invoice.InvoiceLines = new List<InvoiceLine>();
+              foreach (OrderLine orderLine in order.OrderLines) {
+                InvoiceLine invoiceLine = new InvoiceLine();
+                invoiceLine.Invoice = invoice;
+                invoiceLine.Product = orderLine.Product;
+                invoiceLine.ProductPrice = orderLine.ProductPrice;
+                invoiceLine.Quantity = invoiceLine.Quantity;
+                invoice.InvoiceLines.Add(invoiceLine);
+              }
+
+              InvoiceLine usageCharges = new InvoiceLine();
+              usageCharges.Invoice = invoice;
+              usageCharges.Product = billingService.GetProductByName("Oaas Usage Charges").First();
+              usageCharges.ProductPrice = 999.99;
+              usageCharges.Quantity = 1;
+              invoice.InvoiceLines.Add(usageCharges);
+
+              // Bill Post Processing: Apply Discounts or Promotions
+              // eg. add discounts
+              // sum up items to sub-total, calc. tax -> total current charges
+
+              // Invoice Formatting Engine: Generate Invoice 
+              invoice.InvoiceDocument = InvoiceFormattingEngine.Generate(invoice);
+
+              UpdateBillingState(order);
+              billingService.UpdateOrder(order);
+            }
+          }
+
+          Trace.WriteLine("[BillingEngine] Finished billing cycle");
+        }
+        catch (Exception e) {
+          Trace.WriteLine(string.Format("[BillingEngine] The following exception occured: {0}", e.ToString()));
+        }
+        waitHandle.WaitOne(interval);
+      }
+      waitHandle.Close();
+    }
+
+    private void UpdateBillingState(Order order) {
+      if (order.ActiveUntil != null && order.ActiveUntil == order.NextBillableDay) {
+        order.NextBillableDay = null;
+        order.State = OrderState.Finished;
+      }
+
+      DateTime nextBillingDay = CalculateNextBillingDate(order);
+
+      if (order.ActiveUntil != null && order.ActiveUntil < nextBillingDay) {
+        order.NextBillableDay = nextBillingDay;
+      }
+    }
+
+    private DateTime CalculateNextBillingDate(Order order) {
+      DateTime nextBillingDay = currentDate;
+
+      if (order.BillingPeriod == BillingPeriod.Weekly) {
+        nextBillingDay = nextBillingDay.AddDays(7);
+      } else if (order.BillingPeriod == BillingPeriod.Monthly) {
+        if (order.BillingType == BillingType.Pre) {
+          nextBillingDay = nextBillingDay.AddDays(DateTime.DaysInMonth(nextBillingDay.Year, nextBillingDay.Month) + 1);
+        } else if (order.BillingType == BillingType.Post) {
+          if (nextBillingDay.Month == 12) {
+            nextBillingDay = nextBillingDay.AddDays(DateTime.DaysInMonth(nextBillingDay.Year + 1, 1) + 1);
+          } else {
+            nextBillingDay = nextBillingDay.AddDays(DateTime.DaysInMonth(nextBillingDay.Year, nextBillingDay.Month + 1) + 1);
+          }
+        }
+      } else if (order.BillingPeriod == BillingPeriod.Yearly) {
+        if (order.BillingType == BillingType.Pre) {
+          nextBillingDay = new DateTime(DateTime.Now.Year + 1, 1, 1);
+        } else if (order.BillingType == BillingType.Post) {
+          nextBillingDay = new DateTime(DateTime.Now.Year + 1, 12, 31);
+        }
+      }
+
+      return nextBillingDay;
+    }
+  }
+}
Index: branches/OaaS/HeuristicLab.Services.Optimization.Billing/BillingEngine/InvoiceTemplate.txt
===================================================================
--- branches/OaaS/HeuristicLab.Services.Optimization.Billing/BillingEngine/InvoiceTemplate.txt	(revision 9619)
+++ branches/OaaS/HeuristicLab.Services.Optimization.Billing/BillingEngine/InvoiceTemplate.txt	(revision 9619)
@@ -0,0 +1,32 @@
+﻿OPTIMIZATION LTD.
+Softwarepark 11, 
+4232 Hagenberg/Austria
+
+Email: info@optimization.cloudapp.net
+Web:   optimization.cloudapp.net
+
+-------------------------------------------------------------------------------
+                          TAX INVOICE #{INVOICE_ID} 
+-------------------------------------------------------------------------------
+To:
+{ORGANIZATION_NAME}
+{FIRSTNAME} {LASTNAME}
+{STREET}
+{POSTAL_CODE} {CITY}
+
+Date:          {INVOICE_DATE}
+Order Number:  {ORDER_ID}
+Payment Terms: {PAYMENT_TERMS}
+Payment Due:   {PAYMENT_DUE}
+
+-------------------------------------------------------------------------------
+
+ITEM  NAME                                    QUANTITY  UNIT PRICE  LINE TOTAL
+-------------------------------------------------------------------------------
+#BEGIN {ITEM} {PRODUCT_NAME} {QUANTITY} {PRODUCT_PRICE} {PRODUCT_TOTAL} #END
+
+**---------------------------------------------------------------------------**
+SUB-TOTAL CHARGES:                                          {INVOICE_SUB_TOTAL}
+TAX:                                                              {INVOICE_TAX}
+TOTAL CHARGES:                                                  {INVOICE_TOTAL}
+===============================================================================
Index: branches/OaaS/HeuristicLab.Services.Optimization.Billing/BillingEngine/PlainTextInvoiceFormattingEngine.cs
===================================================================
--- branches/OaaS/HeuristicLab.Services.Optimization.Billing/BillingEngine/PlainTextInvoiceFormattingEngine.cs	(revision 9619)
+++ branches/OaaS/HeuristicLab.Services.Optimization.Billing/BillingEngine/PlainTextInvoiceFormattingEngine.cs	(revision 9619)
@@ -0,0 +1,90 @@
+﻿using System;
+using System.Drawing;
+using System.IO;
+using System.Linq;
+using System.Windows.Forms;
+using HeuristicLab.Services.Optimization.Billing.Interfaces;
+using HeuristicLab.Services.Optimization.Billing.Model;
+
+namespace HeuristicLab.Services.Optimization.Billing.BillingEngine {
+  class PlainTextInvoiceFormattingEngine : IInvoiceFormattingEngine {
+    private const string defaultTemplatePath = @"BillingEngine\InvoiceTemplate.txt";
+    private string template;
+    private string invoiceText;
+    private string invoiceOutputPath;
+
+    public PlainTextInvoiceFormattingEngine()
+      : this(defaultTemplatePath) {
+
+    }
+
+    public PlainTextInvoiceFormattingEngine(string templatePath) {
+      if (!File.Exists(templatePath)) {
+        throw new FileNotFoundException("Cannot find template file", templatePath);
+      }
+      template = File.ReadAllText(templatePath);
+    }
+
+    public string Generate(Model.Invoice invoice) {
+      invoiceText = string.Copy(template);
+
+      invoiceText = invoiceText.Replace("{INVOICE_ID}", invoice.InvoiceId.ToString());
+
+      // TODO: Replace ContactInformation
+
+      invoiceText = invoiceText.Replace("{INVOICE_DATE}", invoice.InvoiceDate.ToString("dd.MM.yyyy"));
+      invoiceText = invoiceText.Replace("{ORDER_ID}", invoice.OrderId.ToString());
+      invoiceText = invoiceText.Replace("{PAYMENT_TERMS}", "2% 10, net 30 days");
+      invoiceText = invoiceText.Replace("{PAYMENT_DUE}", invoice.Due.Date.ToString("dd.MM.yyyy"));
+
+      // TODO: Replace InvoiceLines
+      int itemNo = 1;
+      InvoiceLine lastInvoiceLine = invoice.InvoiceLines.Last();
+      foreach (InvoiceLine invoiceLine in invoice.InvoiceLines) {
+        // copy template text for OrderLine
+        int first = invoiceText.IndexOf("#BEGIN");
+        int last = invoiceText.LastIndexOf("#END");
+        string orderLineText = invoiceText.Substring(first, last + 6 - first);
+
+        // remove #BEGIN tag
+        invoiceText = invoiceText.Remove(first, 7);
+        invoiceText = invoiceText.Remove(last, 3);
+
+        // replace text
+        invoiceText = invoiceText.Replace("{ITEM}", (++itemNo).ToString());
+        invoiceText = invoiceText.Replace("{PRODUCT_NAME}", invoiceLine.Product.Name);
+        invoiceText = invoiceText.Replace("{QUANTITY}", invoiceLine.Quantity.ToString());
+        invoiceText = invoiceText.Replace("{PRODUCT_PRICE}", invoiceLine.ProductPrice.ToString());
+        invoiceText = invoiceText.Replace("{PRODUCT_TOTAL}", string.Format("{0}", invoiceLine.Quantity + invoiceLine.ProductPrice));
+
+        if (!invoiceLine.Equals(lastInvoiceLine)) {
+          // remove #BEGIN tag and insert template text for next OrderLine
+          invoiceText = invoiceText.Replace("#END", Environment.NewLine + orderLineText);
+        } else {
+          // remove #END tag
+          invoiceText = invoiceText.Replace("#END", "");
+        }
+      }
+
+      invoiceText = invoiceText.Replace("{INVOICE_SUB_TOTAL}", string.Format("{0}", invoice.Total - invoice.Tax));
+      invoiceText = invoiceText.Replace("{INVOICE_TAX}", invoice.Tax.ToString());
+      invoiceText = invoiceText.Replace("{INVOICE_TOTAL}", invoice.Total.ToString());
+      invoiceText = invoiceText.Replace("{INVOICE_DATE}", invoice.InvoiceDate.ToString());
+
+      invoiceOutputPath = string.Format("{0}_{1}_{2}.rtf", invoice.InvoiceId, invoice.InvoiceDate.ToString("yyyMMdd"), "{CUSTOMER}");
+      string invoiceOutputPathRTF = string.Format("{0}_{1}_{2}.rtf", invoice.InvoiceId, invoice.InvoiceDate.ToString("yyyMMdd"), "{CUSTOMER}");
+      string invoiceOutputPathTXT = string.Format("{0}_{1}_{2}.txt", invoice.InvoiceId, invoice.InvoiceDate.ToString("yyyMMdd"), "{CUSTOMER}");
+
+      RichTextBox richTextBox = new RichTextBox();
+      richTextBox.Text = invoiceText;
+      richTextBox.SelectAll();
+      richTextBox.SelectionFont = new Font("Consolas", 10, FontStyle.Regular);
+      //richTextBox.Text = invoiceText;
+      File.WriteAllText(invoiceOutputPathRTF, richTextBox.Rtf);
+
+      File.WriteAllText(invoiceOutputPathTXT, invoiceText);
+
+      return invoiceOutputPath;
+    }
+  }
+}
Index: branches/OaaS/HeuristicLab.Services.Optimization.Billing/Business/BillingService.cs
===================================================================
--- branches/OaaS/HeuristicLab.Services.Optimization.Billing/Business/BillingService.cs	(revision 9602)
+++ branches/OaaS/HeuristicLab.Services.Optimization.Billing/Business/BillingService.cs	(revision 9619)
@@ -29,4 +29,10 @@
     }
 
+    public IList<Product> GetProductByName(string productName) {
+      //TODO: Authentication
+      //TODO: Enable Transaction
+      return BillingDao.FindProdcutBy(prod => prod.Name == productName).ToList();
+    }
+
     #endregion
 
@@ -42,5 +48,5 @@
       //TODO: Authentication
       //TODO: Enable Transaction
-      return BillingDao.FindOrderBy(order => order.State == state).ToList();
+      return BillingDao.FindOrderBy(order => order.StateValue == (int)state).ToList();
     }
 
@@ -50,4 +56,8 @@
       User user = GetUser(userName);
       return BillingDao.FindOrderBy(order => order.User == user).ToList();
+    }
+
+    public void UpdateOrder(Order order) {
+      throw new System.NotImplementedException();
     }
 
@@ -79,4 +89,8 @@
     }
 
+    public IList<UsageRecord> GetUsageRecords(string username, System.DateTime from, System.DateTime to) {
+      throw new System.NotImplementedException();
+    }
+
     #endregion
 
Index: branches/OaaS/HeuristicLab.Services.Optimization.Billing/Business/MockupBillingService.cs
===================================================================
--- branches/OaaS/HeuristicLab.Services.Optimization.Billing/Business/MockupBillingService.cs	(revision 9602)
+++ branches/OaaS/HeuristicLab.Services.Optimization.Billing/Business/MockupBillingService.cs	(revision 9619)
@@ -118,4 +118,21 @@
       return null;
     }
+
+    #region IOptimizationBilling Members
+
+
+    public IList<Model.Product> GetProductByName(string productName) {
+      throw new NotImplementedException();
+    }
+
+    public void UpdateOrder(Model.Order order) {
+      throw new NotImplementedException();
+    }
+
+    public IList<Model.UsageRecord> GetUsageRecords(string username, DateTime from, DateTime to) {
+      throw new NotImplementedException();
+    }
+
+    #endregion
   }
 }
Index: branches/OaaS/HeuristicLab.Services.Optimization.Billing/DataAccess/BillingContext.cs
===================================================================
--- branches/OaaS/HeuristicLab.Services.Optimization.Billing/DataAccess/BillingContext.cs	(revision 9602)
+++ branches/OaaS/HeuristicLab.Services.Optimization.Billing/DataAccess/BillingContext.cs	(revision 9619)
@@ -28,5 +28,6 @@
     public BillingContext(string connectionString)
       : base(connectionString) {
-
+      this.Configuration.LazyLoadingEnabled = false;
+      this.Configuration.ProxyCreationEnabled = false;
     }
 
@@ -96,11 +97,27 @@
       protected override void Seed(BillingContext context) {
         Product p1 = new Product() {
-          Name = "Optimization-as-a-Service - Experiment execution",
+          Name = "OaaS BAsic Service Charge",
           Description = "Create and run your experiments within HeuristicLab Hive",
-          ProductId = 1,
-          Price = 10.0,
+          Price = 20.0,
           ProductType = "Optimization Service"
         };
+
+        Product p2 = new Product() {
+          Name = "Oaas Usage Charges",
+          Description = "Charges for OaaS based on usage data",
+          Price = 0.0,
+          ProductType = "Optimization Service"
+        };
+
+        Product p3 = new Product() {
+          Name = "Oaas Support Package",
+          Description = "Charges for OaaS based on usage data",
+          Price = 50.0,
+          ProductType = "Optimization Service"
+        };
+
         p1 = context.Products.Add(p1);
+        p2 = context.Products.Add(p2);
+        p3 = context.Products.Add(p3);
 
         User u1 = new Model.User() { Name = "spimming" };
Index: branches/OaaS/HeuristicLab.Services.Optimization.Billing/DataAccess/BillingDao.cs
===================================================================
--- branches/OaaS/HeuristicLab.Services.Optimization.Billing/DataAccess/BillingDao.cs	(revision 9602)
+++ branches/OaaS/HeuristicLab.Services.Optimization.Billing/DataAccess/BillingDao.cs	(revision 9619)
@@ -2,4 +2,5 @@
 using System;
 using System.Collections.Generic;
+using System.Data.Entity;
 using System.Linq;
 using System.Linq.Expressions;
@@ -105,5 +106,10 @@
     public IEnumerable<Order> FindOrderBy(Expression<Func<Order, bool>> predicate) {
       using (var context = CreateContext()) {
-        var orders = context.Orders.Where(predicate).ToList();
+        var orders = context.Orders
+          .Include(o => o.OrderLines)
+          .Include(o => o.User)
+          .Include(o => o.Invoices)
+          .Include(o => o.OrderLines.Select(ol => ol.Product))
+          .Where(predicate).ToList();
         return orders;
       }
Index: branches/OaaS/HeuristicLab.Services.Optimization.Billing/HeuristicLab.Services.Optimization.Billing.csproj
===================================================================
--- branches/OaaS/HeuristicLab.Services.Optimization.Billing/HeuristicLab.Services.Optimization.Billing.csproj	(revision 9602)
+++ branches/OaaS/HeuristicLab.Services.Optimization.Billing/HeuristicLab.Services.Optimization.Billing.csproj	(revision 9619)
@@ -40,5 +40,7 @@
     <Reference Include="System.Core" />
     <Reference Include="System.Data.Entity" />
+    <Reference Include="System.Drawing" />
     <Reference Include="System.ServiceModel" />
+    <Reference Include="System.Windows.Forms" />
     <Reference Include="System.Xml.Linq" />
     <Reference Include="System.Data.DataSetExtensions" />
@@ -48,4 +50,6 @@
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="BillingEngine\BillingEngine.cs" />
+    <Compile Include="BillingEngine\PlainTextInvoiceFormattingEngine.cs" />
     <Compile Include="Business\BillingService.cs" />
     <Compile Include="Business\BillingServiceProvider.cs" />
@@ -54,4 +58,5 @@
     <Compile Include="Interfaces\IEntity.cs" />
     <Compile Include="Interfaces\IGenericDao.cs" />
+    <Compile Include="Interfaces\IInvoiceFormattingEngine.cs" />
     <Compile Include="Interfaces\IOptimizationBilling.cs" />
     <Compile Include="Business\MockupBillingService.cs" />
@@ -63,5 +68,9 @@
     <None Include="packages.config" />
   </ItemGroup>
-  <ItemGroup />
+  <ItemGroup>
+    <Content Include="BillingEngine\InvoiceTemplate.txt">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </Content>
+  </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
Index: branches/OaaS/HeuristicLab.Services.Optimization.Billing/Interfaces/IInvoiceFormattingEngine.cs
===================================================================
--- branches/OaaS/HeuristicLab.Services.Optimization.Billing/Interfaces/IInvoiceFormattingEngine.cs	(revision 9619)
+++ branches/OaaS/HeuristicLab.Services.Optimization.Billing/Interfaces/IInvoiceFormattingEngine.cs	(revision 9619)
@@ -0,0 +1,7 @@
+﻿using HeuristicLab.Services.Optimization.Billing.Model;
+
+namespace HeuristicLab.Services.Optimization.Billing.Interfaces {
+  public interface IInvoiceFormattingEngine {
+    string Generate(Invoice invoice);
+  }
+}
Index: branches/OaaS/HeuristicLab.Services.Optimization.Billing/Interfaces/IOptimizationBilling.cs
===================================================================
--- branches/OaaS/HeuristicLab.Services.Optimization.Billing/Interfaces/IOptimizationBilling.cs	(revision 9602)
+++ branches/OaaS/HeuristicLab.Services.Optimization.Billing/Interfaces/IOptimizationBilling.cs	(revision 9619)
@@ -1,3 +1,4 @@
-﻿using System.Collections.Generic;
+﻿using System;
+using System.Collections.Generic;
 using System.Net.Security;
 using System.ServiceModel;
@@ -9,4 +10,5 @@
     [OperationContract]
     IList<Product> GetProducts();
+    IList<Product> GetProductByName(string productName);
 
     // payment methods via enumeration
@@ -18,4 +20,7 @@
     IList<Order> GetOrdersByState(OrderState state);
     IList<Order> GetOrders(string userName);
+    void UpdateOrder(Order order);
+
+    IList<Invoice> GetInvoices(string userName);
 
     User GetUser(string userName);
@@ -23,5 +28,6 @@
 
     IList<UsageRecord> GetUsageRecords(string userName);
-    IList<Invoice> GetInvoices(string userName);
+    IList<UsageRecord> GetUsageRecords(string username, DateTime from, DateTime to);
+
   }
 }
Index: branches/OaaS/HeuristicLab.Services.Optimization.Billing/Model/Model.cs
===================================================================
--- branches/OaaS/HeuristicLab.Services.Optimization.Billing/Model/Model.cs	(revision 9602)
+++ branches/OaaS/HeuristicLab.Services.Optimization.Billing/Model/Model.cs	(revision 9619)
@@ -92,4 +92,6 @@
     public DateTime? ActiveSince { get; set; }
     public DateTime? ActiveUntil { get; set; }
+    public DateTime? LastBillableDay { get; set; }
+    public DateTime? NextBillableDay { get; set; }
 
     public virtual User User { get; set; }
@@ -130,6 +132,9 @@
     public long UserId { get; set; }
     public long OrderId { get; set; }
+    public DateTime InvoiceDate { get; set; }
     public DateTime Due { get; set; }
     public int StatusValue { get; set; }
+    public double Total { get; set; }
+    public double Tax { get; set; }
     public string InvoiceDocument { get; set; }
 
