﻿<?xml version="1.0" encoding="utf-16"?>
<JiwaDocument xmlns:jiwa="http://www.jiwa.com.au/xml/schemas" Type="JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin">
  <RecID>82999ffa-2d4b-43f6-9768-2eccf9443db2</RecID>
  <Name>REST API Export Invoice and Statement</Name>
  <Description>Extends the REST API by allowing for the exporting of invoices and statements to pdf and other formats.&amp;#13;&amp;#10;&amp;#13;&amp;#10;Note you need to set the system settings and restart the web api first.</Description>
  <IsEnabled>true</IsEnabled>
  <IsIsolatedToOwnAppDomain>false</IsIsolatedToOwnAppDomain>
  <ExecutionOrder>0</ExecutionOrder>
  <Author>Stuart Barnes</Author>
  <Version>7.2.1.0</Version>
  <Code>using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using JiwaFinancials.Jiwa;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Drawing;
using ServiceStack;
using ServiceStack.DataAnnotations;
using ServiceStack.Model;
using JiwaFinancials.Jiwa.JiwaServiceModel.Tables;
using ServiceStack.Auth;
using System.Linq;
using ServiceStack.OrmLite;
using System.Data;
using System.Data.Common;
using ServiceStack.DataAnnotations;
using System.Runtime.Serialization;


#region "SystemSettingPlugin"
public class SystemSettingPlugin : System.MarshalByRefObject, JiwaFinancials.Jiwa.JiwaApplication.IJiwaSystemSettingPlugin
{
    public override object InitializeLifetimeService()
    {
        // returning null here will prevent the lease manager
        // from deleting the Object.
        return null;
    }

    public void FormatCell(JiwaFinancials.Jiwa.JiwaApplication.IJiwaBusinessLogic BusinessLogicHost, JiwaFinancials.Jiwa.JiwaApplication.Controls.JiwaGrid GridObject, JiwaFinancials.Jiwa.JiwaApplication.IJiwaForm FormObject, int Col, int Row, JiwaFinancials.Jiwa.JiwaApplication.SystemSettings.Setting SystemSetting)
    {
    }

    public void ReadData(JiwaFinancials.Jiwa.JiwaApplication.IJiwaBusinessLogic BusinessLogicHost, JiwaFinancials.Jiwa.JiwaApplication.Controls.JiwaGrid GridObject, JiwaFinancials.Jiwa.JiwaApplication.IJiwaForm FormObject, int Row, JiwaFinancials.Jiwa.JiwaApplication.SystemSettings.Setting SystemSetting)
    {
		
		System.Data.SqlClient.SqlParameter SQLParam = null;
		System.Data.SqlClient.SqlDataReader SQLReader = null;
		if (SystemSetting.IDKey == "SRep" || SystemSetting.IDKey == "SRep" ||  SystemSetting.IDKey == "IRep") {			
				if (SystemSetting.Contents.Trim().Length &gt; 0) 
				{
				string SQL = "";

				var db = BusinessLogicHost.Manager.Database;
				try 
				{
					SQL = @"SELECT SY_ReportSection.Name+' \ ' + SY_Report.FileName as DisplayName FROM SY_Report JOIN SY_ReportSection ON SY_Report.SY_ReportSection_RecID = SY_ReportSection.RecID
	                        where SY_Report.RecID = @RecID ";			
					
					
					using (SqlCommand SQLCmd = new SqlCommand(SQL, db.SQLConnection, db.SQLTransaction)) 
					{
						SQLParam = new SqlParameter("@RecID", System.Data.SqlDbType.Char);
						SQLParam.Value = SystemSetting.Contents;
						SQLCmd.Parameters.Add(SQLParam);

						SQLReader = db.ExecuteReader(SQLCmd);

						if (SQLReader.Read() == true) 
						{
							SystemSetting.DisplayContents = string.Format("{0}", db.Sanitise(SQLReader, "DisplayName"));
						}
					}

					SQLReader.Close();
				} finally {
					if ((SQLReader != null)) 
					{
						SQLReader.Close();
					}
				}				
			}
				
				
				

		if (SystemSetting.IDKey == "SProc" || SystemSetting.IDKey == "IProc") {			
				if (SystemSetting.Contents.Trim().Length &gt; 0) 
				{
				string SQL = "";

				var db = BusinessLogicHost.Manager.Database;
				try 
				{
					SQL = @"Select [NAME] from sysobjects where type = 'P' and category = 0 and [NAME]
	                        = @RecID ";			
					
					
					using (SqlCommand SQLCmd = new SqlCommand(SQL, db.SQLConnection, db.SQLTransaction)) 
					{
						SQLParam = new SqlParameter("@RecID", System.Data.SqlDbType.Char);
						SQLParam.Value = SystemSetting.Contents;
						SQLCmd.Parameters.Add(SQLParam);

						SQLReader = db.ExecuteReader(SQLCmd);

						if (SQLReader.Read() == true) 
						{
							SystemSetting.DisplayContents = string.Format("{0}", db.Sanitise(SQLReader, "NAME"));
						}
					}

					SQLReader.Close();
				} finally {
					if ((SQLReader != null)) 
					{
						SQLReader.Close();
					}
				}				
			}
		}				
				
			
			
				
		}		
		
		
    }

    public void ButtonClicked(JiwaFinancials.Jiwa.JiwaApplication.IJiwaBusinessLogic BusinessLogicHost, JiwaFinancials.Jiwa.JiwaApplication.Controls.JiwaGrid GridObject, JiwaFinancials.Jiwa.JiwaApplication.IJiwaForm FormObject, int Col, int Row, JiwaFinancials.Jiwa.JiwaApplication.SystemSettings.Setting SystemSetting)
    {
		System.Data.SqlClient.SqlParameter SQLParam = null;
		System.Data.SqlClient.SqlDataReader SQLReader = null;
		if (SystemSetting.IDKey == "SRep" || SystemSetting.IDKey == "SRep" ||  SystemSetting.IDKey == "IRep" ) 
		{

			var search = BusinessLogicHost.Manager.Search;
			
			search.Clear();
			search.CurrentOption = 1;
			JiwaFinancials.Jiwa.JiwaApplication.JiwaSearch.clsSearch.SearchModes searchMode = JiwaFinancials.Jiwa.JiwaApplication.JiwaSearch.clsSearch.SearchModes.jswReports;
			search.SetDefaultSearch(ref searchMode);
			search.UsePinBoard = false;
			
			if (search.Show(FormObject.Form) == System.Windows.Forms.DialogResult.OK) 
			{
				if (search.Results.Count &gt; 0) 
				{						
					var idField = (JiwaFinancials.Jiwa.JiwaApplication.JiwaSearch.Field)search.get_Fields(1);
					SystemSetting.Contents = idField.FieldValue.ToString();
					
					var TitleField = (JiwaFinancials.Jiwa.JiwaApplication.JiwaSearch.Field)search.get_Fields(2);
					var FileNameField = (JiwaFinancials.Jiwa.JiwaApplication.JiwaSearch.Field)search.get_Fields(3);
					
					SystemSetting.DisplayContents = String.Format("{0} / {1}", TitleField.FieldValue.ToString(), FileNameField.FieldValue.ToString());
				} 
				else 
				{
					throw new JiwaFinancials.Jiwa.JiwaApplication.Exceptions.ClientCancelledException();
				}
			} 
			else 
			{
				throw new JiwaFinancials.Jiwa.JiwaApplication.Exceptions.ClientCancelledException();
			}		
		}
		
		
		
		
		if (SystemSetting.IDKey == "IProc" || SystemSetting.IDKey == "SProc") 
		{

			var search = BusinessLogicHost.Manager.Search;
			
			search.Clear();
			search.CurrentOption = 1;
			JiwaFinancials.Jiwa.JiwaApplication.JiwaSearch.clsSearch.SearchModes searchMode = JiwaFinancials.Jiwa.JiwaApplication.JiwaSearch.clsSearch.SearchModes.jswStoredProcedures;
			search.SetDefaultSearch(ref searchMode);
			search.UsePinBoard = false;
			
			if (search.Show(FormObject.Form) == System.Windows.Forms.DialogResult.OK) 
			{
				if (search.Results.Count &gt; 0) 
				{						
					var idField = (JiwaFinancials.Jiwa.JiwaApplication.JiwaSearch.Field)search.get_Fields(1);
					SystemSetting.Contents = idField.FieldValue.ToString();
					
//					var TitleField = (JiwaFinancials.Jiwa.JiwaApplication.JiwaSearch.Field)search.get_Fields(2);
//					var FileNameField = (JiwaFinancials.Jiwa.JiwaApplication.JiwaSearch.Field)search.get_Fields(3);
//					
					SystemSetting.DisplayContents = idField.FieldValue.ToString();
				} 
				else 
				{
					throw new JiwaFinancials.Jiwa.JiwaApplication.Exceptions.ClientCancelledException();
				}
			} 
			else 
			{
				throw new JiwaFinancials.Jiwa.JiwaApplication.Exceptions.ClientCancelledException();
			}		
		}			
		
		
		
		
		
    }
}
#endregion





namespace JiwaFinancials.Jiwa.JiwaServiceModel
{
	public class RESTAPIPlugin : System.MarshalByRefObject, JiwaFinancials.Jiwa.JiwaApplication.IJiwaRESTAPIPlugin
	{
		public static string PluginName;
		public static string StatementReportID;
		public static string InvoiceReportID;
		public static string StatementProc;
		public static string InvoiceProc;		
		
		public void Configure(JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin Plugin, ServiceStack.ServiceStackHost  AppHost, Funq.Container Container, JiwaApplication.Manager JiwaApplicationManager)
		{
			Plugin.PluginReferenceCollection.Read();
			AppDomain.CurrentDomain.AssemblyResolve += delegate(object sender, System.ResolveEventArgs args) { return AssemblyResolve(sender, args, Plugin); };
			System.Reflection.AssemblyName aName = new  System.Reflection.AssemblyName(System.Reflection.Assembly.GetExecutingAssembly().GetName().FullName);
			PluginName =  aName.Name;
			StatementReportID = JiwaApplicationManager.Database.ReadSysData(PluginName, "SRep", "0").ToString();
			InvoiceReportID = JiwaApplicationManager.Database.ReadSysData(PluginName, "IRep", "0").ToString();
			StatementProc = JiwaApplicationManager.Database.ReadSysData(PluginName, "SProc", "0").ToString();
			InvoiceProc = JiwaApplicationManager.Database.ReadSysData(PluginName, "IProc", "0").ToString();	
			bool PDFExport = bool.Parse(JiwaApplicationManager.Database.ReadSysData(PluginName, "PDFExport", "0").ToString());
			bool GExport = bool.Parse(JiwaApplicationManager.Database.ReadSysData(PluginName, "GExport", "0").ToString());
			bool SExport = bool.Parse(JiwaApplicationManager.Database.ReadSysData(PluginName, "SExport", "0").ToString());
			bool IExport = bool.Parse(JiwaApplicationManager.Database.ReadSysData(PluginName, "IExport", "0").ToString());
			
	        AppHost.RegisterService&lt;ExporterService&gt;(); 
			if(SExport &amp;&amp; GExport)
			{
				AppHost.Routes.Add(typeof(StatementGetRequest), "/Export/Statement", "GET", "Get the debtor statement as raw data", "");
			}
	        if(SExport &amp;&amp; PDFExport)
			{
				AppHost.Routes.Add(typeof(StatementPDFGetRequest), "/ExportPDF/StatementPDF", "GET", "Get the debtor statement as pdf", "");
			}
			if(IExport &amp;&amp; GExport)
			{
				AppHost.Routes.Add(typeof(InvoiceGetRequest), "/Export/Invoice", "GET", "Get the debtor invoice as raw data", "");
			}
			
			if(IExport &amp;&amp; PDFExport)
			{
				AppHost.Routes.Add(typeof(InvoicePDFGetRequest), "/ExportPDF/InvoicePDF", "GET", "Get the debtor invoice as pdf", "");
			}
			
			
		}
		
		
		
		public System.Reflection.Assembly AssemblyResolve(object sender, System.ResolveEventArgs args, JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin Plugin)
		{
			// If the requested assembly is a reference to another plugin, then we need to attempt to resolve the assembly ourselves					
			foreach(JiwaApplication.Plugin.PluginReference pluginReference in Plugin.PluginReferenceCollection)
			{
				if (String.Format("{0}, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", pluginReference.Name) == args.Name)
					return System.Reflection.Assembly.LoadFile(pluginReference.Plugin.RuntimeFileName);
			}
			
			return null;
		}
	}

	#region "Requests"
		[Serializable()]
		[ApiResponse(200, "Statement read OK")]
		[ApiResponse(401, "Not authenticated")]
		[ApiResponse(404, "No Statement was found")]
		public class StatementGetRequest : IReturn&lt;StatementGetResponse&gt;
		{
		}
		
	
		[Serializable()]
		[ApiResponse(200, "Statement read OK")]
		[ApiResponse(401, "Not authenticated")]
		[ApiResponse(404, "No Statement was found")]
		public class StatementPDFGetRequest  : IReturn&lt;ServiceStack.Web.IHttpResult&gt;
		{
		}		
		
		
		
			[Serializable()]
		[ApiResponse(200, "Statement read OK")]
		[ApiResponse(401, "Not authenticated")]
		[ApiResponse(404, "No Statement was found")]
		public class InvoiceGetRequest : IReturn&lt;InvoiceGetResponse&gt;
		{
			public string InvoiceNo  { get; set; }
			public int HistoryNo  { get; set; }
		}	
		
			[Serializable()]
		[ApiResponse(200, "Statement read OK")]
		[ApiResponse(401, "Not authenticated")]
		[ApiResponse(404, "No Statement was found")]
		public class InvoicePDFGetRequest  : IReturn&lt;ServiceStack.Web.IHttpResult&gt;
		{
			public string InvoiceNo  { get; set; }
			public int HistoryNo  { get; set; }
		}	
		
		
	#endregion
		
	#region "Responses"
		[Serializable()]
		[DataContract]
		public class StatementGetResponse
		{
			 [DataMember]
			public string DebtorID  { get; set; }
			 [DataMember]
			public string DebtorAccountNo  { get; set; }
			 [DataMember]
			public string DebtorName  { get; set; }
			 [DataMember]
			public string Address1 { get; set; }
			 [DataMember]
			public string Address2  { get; set; }
			 [DataMember]
			public string Address3  { get; set; }
			 [DataMember]
			public string Address4  { get; set; }
			 [DataMember]
			public string PostCode  { get; set; }
			 [DataMember]
			public string ABN  { get; set; }
			 [DataMember]
			public decimal CurrentBalance  { get; set; }
			 [DataMember]
			public decimal Period1Balance  { get; set; }
			 [DataMember]
			public decimal Period2Balance  { get; set; }
			 [DataMember]
			public decimal Period3Balance  { get; set; }
			 [DataMember]
			public decimal TotalBalance  { get; set; }
			 [DataMember]
			public string PeriodType  { get; set; }
			 [DataMember]
			public bool Parent  { get; set; }
			 [DataMember]
			public string TransID  { get; set; }
			 [DataMember]
			public string InvRemitNo { get; set; }
			 [DataMember]
			public DateTime TransactionDate { get; set; }
			 [DataMember]
			public string Reference { get; set; }
			 [DataMember]
			public string Remark  { get; set; }
			 [DataMember]
			public string TransactionType { get; set; }
			 [DataMember]
			public decimal Amount { get; set; }
			 [DataMember]
			public decimal DebitAmount { get; set; }
			 [DataMember]
			public decimal CreditAmount { get; set; }
			 [DataMember]
			public decimal AllocatedAmount { get; set; }
			 [DataMember]
			public bool DebitCredit { get; set; }
			 [DataMember]
			public decimal TransactionBalance { get; set; }
			 [DataMember]
			public int PeriodNo { get; set; }
			 [DataMember]
			public int MoneyDecimalPlaces  { get; set; }		
		}
		
		
		[Serializable()]
		[DataContract]
		public class InvoiceGetResponse
		{
			 [DataMember]
		    public string InvoiceLineID { get; set; }
			[DataMember]
		    public short? LineNum { get; set; }
			[DataMember]
		    public string LineType { get; set; }
			[DataMember]
		    public string PartNo { get; set; }
			[DataMember]
		    public decimal? QuantityThisDelivery { get; set; }
			[DataMember]
		    public string StyleCode { get; set; }
			[DataMember]
		    public string StyleID { get; set; }
			[DataMember]
		    public string Comment { get; set; }
			[DataMember]
		    public string PartDescription { get; set; }
			[DataMember]
		    public decimal? AvgPriceEachExGST { get; set; }
			[DataMember]
		    public decimal? AvgPriceEachIncGST { get; set; }
			[DataMember]
		    public decimal? PriceTotalExGST { get; set; }
			[DataMember]
		    public decimal? PriceTotalIncGST { get; set; }
			[DataMember]
		    public string StyleDescription { get; set; }
			[DataMember]
		    public string InvoiceNo { get; set; }
			[DataMember]
		    public short? HistoryNo { get; set; }
			[DataMember]
		    public string CompanyName { get; set; }
			[DataMember]
		    public string CompanyABN { get; set; }
			[DataMember]
		    public string CompanyAddress1 { get; set; }
			[DataMember]
		    public string CompanyAddress2 { get; set; }
			[DataMember]
		    public string CompanyAddress3 { get; set; }
			[DataMember]
		    public string CompanyAddress4 { get; set; }
			[DataMember]
		    public string CompanyPhone { get; set; }
			[DataMember]
		    public string CompanyFax { get; set; }
			[DataMember]
		    public string CompanyEmail { get; set; }
			[DataMember]
		    public string CompanyWebsite { get; set; }
			[DataMember]
		    public string CustomerName { get; set; }
			[DataMember]
		    public string CustomerAddress1 { get; set; }
			[DataMember]
		    public string CustomerAddress2 { get; set; }
			[DataMember]
		    public string CustomerAddress3 { get; set; }
			[DataMember]
		    public string CustomerAddress4 { get; set; }
			[DataMember]
		    public string CustomerPostCode { get; set; }
			[DataMember]
		    public string CustomerABN { get; set; }
			[DataMember]
		    public string OrderNo { get; set; }
			[DataMember]
		    public string AccountNo { get; set; }
			[DataMember]
		    public string TaxExemptNo { get; set; }
			[DataMember]
		    public string CourierDetails { get; set; }
			[DataMember]
		    public string SOReference { get; set; }
			[DataMember]
		    public string SalesPerson { get; set; }
			[DataMember]
		    public DateTime? RecordDate { get; set; }
			[DataMember]
		    public string DelContactName { get; set; }
			[DataMember]
		    public string DeliveryAddress1 { get; set; }
			[DataMember]
		    public string DeliveryAddress2 { get; set; }
			[DataMember]
		    public string DeliveryAddress3 { get; set; }
			[DataMember]
		    public string DeliveryAddress4 { get; set; }
			[DataMember]
		    public string DeliveryPostCode { get; set; }
			[DataMember]
		    public string DeliveryAddressCountry { get; set; }
			[DataMember]
		    public decimal? SubTotalIncGST { get; set; }
			[DataMember]
		    public decimal? Cart1IncGST { get; set; }
			[DataMember]
		    public decimal? Cart2IncGST { get; set; }
			[DataMember]
		    public decimal? Cart3IncGST { get; set; }
			[DataMember]
		    public decimal? InvoiceTotalIncGST { get; set; }
			[DataMember]
		    public string Notes { get; set; }
			[DataMember]
		    public bool? CreditNote { get; set; }
			[DataMember]
		    public short? QuantityDecimalPlaces { get; set; }
			[DataMember]
		    public byte? MoneyDecimalPlaces { get; set; }
			[DataMember]
		    public decimal? SubTotalExGST { get; set; }
			[DataMember]
		    public decimal? Cart1ExGST { get; set; }
			[DataMember]
		    public decimal? Cart2ExGST { get; set; }
			[DataMember]
		    public decimal? Cart3ExGST { get; set; }
			[DataMember]
		    public decimal? InvoiceTotalExGST { get; set; }
			[DataMember]
		    public decimal? LineGSTAmount { get; set; }
			[DataMember]
		    public decimal? SubTotalGST { get; set; }
			[DataMember]
		    public decimal? Cart1GST { get; set; }
			[DataMember]
		    public decimal? Cart2GST { get; set; }
			[DataMember]
		    public decimal? Cart3GST { get; set; }
			[DataMember]
		    public decimal? InvoiceTotalGST { get; set; }
			[DataMember]
		    public byte? KitHeader { get; set; }
			[DataMember]
		    public byte? KitComponent { get; set; }
			[DataMember]
		    public decimal? ItemTaxToCharge { get; set; }
			[DataMember]
		    public decimal? QuantityOrdered { get; set; }
			[DataMember]
		    public decimal? QuantityOnBackOrder { get; set; }
			[DataMember]
		    public string Units { get; set; }
			[DataMember]
		    public string KitLineID { get; set; }
			[DataMember]
		    public decimal? QuantityPreviousDelivery { get; set; }
			[DataMember]
		    public bool? UseSerialNo { get; set; }
			[DataMember]
		    public decimal? TotalAmountPaid { get; set; }
			[DataMember]
		    public decimal? TotalAmountTendered { get; set; }
			[DataMember]
		    public string InvoiceID { get; set; }
			[DataMember]
		    public string CashSaleName { get; set; }
			[DataMember]
		    public string CashSaleCompany { get; set; }
			[DataMember]
		    public string CashSaleAddress1 { get; set; }
			[DataMember]
		    public string CashSaleAddress2 { get; set; }
			[DataMember]
		    public string CashSaleAddress3 { get; set; }
			[DataMember]
		    public string CashSaleAddress4 { get; set; }
			[DataMember]
		    public string CashSalePostcode { get; set; }
			[DataMember]
		    public string CashSalePhone { get; set; }
			[DataMember]
		    public string CashSaleFax { get; set; }
			[DataMember]
		    public string CashSaleContactName { get; set; }
			[DataMember]
		    public decimal? OrderedPriceTotalExGST { get; set; }
			[DataMember]
		    public decimal? OrderedPriceTotalIncGST { get; set; }
			[DataMember]
		    public decimal? SubTotalOrderedIncGST { get; set; }
			[DataMember]
		    public decimal? OrderedInvoiceTotalIncGST { get; set; }
			[DataMember]
		    public decimal? LineOrderedGSTAmount { get; set; }
			[DataMember]
		    public decimal? SubTotalOrderedGST { get; set; }
			[DataMember]
		    public short? PeriodType { get; set; }
			[DataMember]
		    public short? TermsDays { get; set; }
			[DataMember]
		    public short? TermsType { get; set; }
			[DataMember]
		    public decimal? QtyThisDelUom { get; set; }
			[DataMember]
		    public string UomName { get; set; }
			[DataMember]
		    public string UomPartNo { get; set; }
			[DataMember]
		    public decimal? QtyOrderedUom { get; set; }
			[DataMember]
		    public decimal? QtyBackOrdUom { get; set; }
			[DataMember]
		    public decimal? ItemPriceUom { get; set; }
			[DataMember]
		    public decimal? ItemPriceIncGSTUom { get; set; }
			[DataMember]
		    public DateTime? ExpectedDeliveryDate { get; set; }
			[DataMember]
		    public decimal? SubTotalOrderedExGST { get; set; }
			[DataMember]
		    public decimal? OrderedInvoiceTotalExGST { get; set; }
			[DataMember]
		    public decimal? OrderedInvoiceTotalGST { get; set; }
			[DataMember]
		    public string AltAccountNo { get; set; }
			[DataMember]
		    public DateTime? ForwardOrderDate { get; set; }
			[DataMember]
		    public DateTime? ScheduledDate { get; set; }
			[DataMember]
			public decimal? OrderedCartage1ExTax { get; set; }
			[DataMember]
			public decimal? OrderedCartage2ExTax { get; set; }
			[DataMember]
			public decimal? OrderedCartage3ExTax { get; set; }
			[DataMember]
			public decimal? OrderedCartage1Tax { get; set; }
			[DataMember]
			public decimal? OrderedCartage2Tax { get; set; }
			[DataMember]
			public decimal? OrderedCartage3Tax { get; set; }
			[DataMember]
			public decimal? OrderedCartage1IncTax { get; set; }
			[DataMember]
			public decimal? OrderedCartage2IncTax { get; set; }
			[DataMember]
			public decimal? OrderedCartage3IncTax { get; set; }			
		}

	#endregion
		
	#region "Services"	
		public class ExporterService : Service
		{
			
			
			private JiwaServiceModel.Tables.v_APIKey GetApiKey(string apiKey)
	        {
				
	            return this.Db.Single(this.Db.From&lt;JiwaServiceModel.Tables.v_APIKey&gt;().Where(x =&gt; x.KeyValue == apiKey));
	        }			
			
			private JiwaServiceModel.Tables.DB_Main GetDBMain(string DebtorID)
	        {
				
	            return this.Db.Single(this.Db.From&lt;JiwaServiceModel.Tables.DB_Main&gt;().Where(x =&gt; x.DebtorID == DebtorID));
	        }
			
			

			private JiwaServiceModel.Tables.SO_History GetSOHist(string DebtorID, string InvNo, int HistoryNo)
	        {
				
	            //return this.Db.Single(this.Db.From&lt;JiwaServiceModel.Tables.DB_Main&gt;().Where(x =&gt; x.DebtorID == DebtorID));
			 var query = Db.From&lt;SO_History&gt;()
                .Join&lt;SO_History, SO_Main&gt;((History, Main) =&gt;( History.InvoiceID == Main.InvoiceID) &amp;&amp; (Main.DebtorID == DebtorID &amp;&amp; History.HistoryNo == HistoryNo) &amp;&amp; (Main.InvoiceNo == InvNo) );	
				List&lt;JiwaFinancials.Jiwa.JiwaServiceModel.Tables.SO_History&gt; result =  (Db.Select&lt;JiwaFinancials.Jiwa.JiwaServiceModel.Tables.SO_History&gt;(query));
				if(result == null || result.Count == 0)
				{
					return null;
				}
				return result.FirstOrDefault();
	        }
						
			
			
		
			
			
			[Authenticate]
		    public List&lt;InvoiceGetResponse&gt; Get(InvoiceGetRequest request)
			{
				//System.Diagnostics.Debugger.Launch();
				JiwaApplication.Manager manager = this.SessionAs&lt;JiwaAuthUserSession&gt;().Manager;
				string DebtorID = "";
				string DebtorAcc = "";
				string HistoryID = "";
				if(manager.Database.APIKey_Type == "Debtor" )
				{

					JiwaServiceModel.Tables.v_APIKey vapikey = GetApiKey(manager.Database.APIKey_KeyValue);
					if(vapikey == null || vapikey.Name == "")
					{
						throw new Exception("API Key is not for debtor."); 
					}
					JiwaServiceModel.Tables.DB_Main dbMain = GetDBMain(vapikey.PrincipalID);
					if(dbMain == null)
					{
						throw new Exception("No debtor found."); 
					}
					DebtorID = dbMain.DebtorID;
					
					
	                JiwaServiceModel.Tables.SO_History hist = GetSOHist(DebtorID, request.InvoiceNo, request.HistoryNo);
					if(hist == null)
					{
						throw new Exception("No invoice found for debtor."); 
					}
					HistoryID = hist.InvoiceHistoryID;
					Db.SetCommandTimeout(600);
					return  StoredProcedures.SPList.usp_Jiwa_Invoices_Invoice(Db, HistoryID).ConvertToList&lt;InvoiceGetResponse&gt;();
				}
				else
				{
					throw new Exception("API Key is not for a debtor."); 
				}
				return new List&lt;InvoiceGetResponse&gt;();				
			}
			
			
			[Authenticate]
		    public ServiceStack.Web.IHttpResult Get(InvoicePDFGetRequest request)
			{
				//System.Diagnostics.Debugger.Launch();
				JiwaApplication.Manager manager = this.SessionAs&lt;JiwaAuthUserSession&gt;().Manager;
				string DebtorID = "";
				string DebtorAcc = "";
				string HistoryID = "";
				if(manager.Database.APIKey_Type == "Debtor" )
				{

					JiwaServiceModel.Tables.v_APIKey vapikey = GetApiKey(manager.Database.APIKey_KeyValue);
					if(vapikey == null || vapikey.Name == "")
					{
						throw new Exception("API Key is not for debtor."); 
					}
					JiwaServiceModel.Tables.DB_Main dbMain = GetDBMain(vapikey.PrincipalID);
					if(dbMain == null)
					{
						throw new Exception("No debtor found."); 
					}
					DebtorID = dbMain.DebtorID;
					
					
	                JiwaServiceModel.Tables.SO_History hist = GetSOHist(DebtorID, request.InvoiceNo, request.HistoryNo);
					if(hist == null)
					{
						throw new Exception("No invoice found for debtor."); 
					}
					HistoryID = hist.InvoiceHistoryID;
					//Db.SetCommandTimeout(600);
					//return  StoredProcedures.SPList.usp_Jiwa_Invoices_Invoice(Db, HistoryID).ConvertToList&lt;InvoiceGetResponse&gt;();
					using (ReportsServices rs = base.ResolveService&lt;ReportsServices&gt;())
					{
						ReportsPDFGETRequest pdfreq = new ReportsPDFGETRequest();
						pdfreq.ReportID = RESTAPIPlugin.InvoiceReportID;
						pdfreq.ReportParameters = new List&lt;ReportParameter&gt;();
						pdfreq.AsAttachment = true;
						pdfreq.ReportParameters.Add(new ReportParameter(){Name = "Pass_SP_InvoiceHistoryID", Value = HistoryID});
						return  rs.Get(pdfreq);					
					}					
				}
				else
				{
					throw new Exception("API Key is not for a debtor."); 
				}
				return new HttpResult("Failed wrong api key type", System.Net.HttpStatusCode.BadRequest);			
			}
						
			
			
			
			[Authenticate]
		    public List&lt;StatementGetResponse&gt; Get(StatementGetRequest request)
			{				                             

				
				//System.Diagnostics.Debugger.Launch();
				JiwaApplication.Manager manager = this.SessionAs&lt;JiwaAuthUserSession&gt;().Manager;
				string DebtorID = "";
				string DebtorAcc = "";
				if(manager.Database.APIKey_Type == "Debtor" )
				{

					JiwaServiceModel.Tables.v_APIKey vapikey = GetApiKey(manager.Database.APIKey_KeyValue);
					if(vapikey == null || vapikey.Name == "")
					{
						throw new Exception("API Key is not for debtor."); 
					}
					JiwaServiceModel.Tables.DB_Main dbMain = GetDBMain(vapikey.PrincipalID);
					if(dbMain == null)
					{
						throw new Exception("No debtor found."); 
					}
					DebtorID = dbMain.DebtorID;
					DebtorAcc = dbMain.AccountNo;
					Db.SetCommandTimeout(600);
					return  StoredProcedures.SPList.usp_JIWA_Debtors_StatementsAsAt(Db, DebtorAcc,DebtorAcc, DateTime.Now).ConvertToList&lt;StatementGetResponse&gt;();
				}
				else
				{
					throw new Exception("API Key is not for a debtor."); 
				}
				return new List&lt;StatementGetResponse&gt;();
				
				
				
			}
			
			
			
			
			[Authenticate]
		    public ServiceStack.Web.IHttpResult Get(StatementPDFGetRequest request)
			{				                             

				
				//System.Diagnostics.Debugger.Launch();
				JiwaApplication.Manager manager = this.SessionAs&lt;JiwaAuthUserSession&gt;().Manager;
				string DebtorID = "";
				string DebtorAcc = "";
				if(manager.Database.APIKey_Type == "Debtor" )
				{

					JiwaServiceModel.Tables.v_APIKey vapikey = GetApiKey(manager.Database.APIKey_KeyValue);
					if(vapikey == null || vapikey.Name == "")
					{
						throw new Exception("API Key is not for debtor."); 
					}
					JiwaServiceModel.Tables.DB_Main dbMain = GetDBMain(vapikey.PrincipalID);
					if(dbMain == null)
					{
						throw new Exception("No debtor found."); 
					}
					DebtorID = dbMain.DebtorID;
					DebtorAcc = dbMain.AccountNo;
					//Db.SetCommandTimeout(600);
					//return  StoredProcedures.SPList.usp_JIWA_Debtors_StatementsAsAt(Db, DebtorAcc,DebtorAcc, DateTime.Now).ConvertToList&lt;StatementGetResponse&gt;();
					using (ReportsServices rs = base.ResolveService&lt;ReportsServices&gt;())
					{
						ReportsPDFGETRequest pdfreq = new ReportsPDFGETRequest();
						pdfreq.ReportID = RESTAPIPlugin.StatementReportID;
						pdfreq.ReportParameters = new List&lt;ReportParameter&gt;();
						pdfreq.AsAttachment = true;
						pdfreq.ReportParameters.Add(new ReportParameter(){Name = "Pass_SP_StartingDebtorAccountNo", Value = DebtorAcc});
						pdfreq.ReportParameters.Add(new ReportParameter(){Name = "Pass_SP_EndingDebtorAccountNo", Value = DebtorAcc});
						pdfreq.ReportParameters.Add(new ReportParameter(){Name = "Pass_SP_AsAtDate", Value = DateTime.Now.ToString()});
						return  rs.Get(pdfreq);					
					}
					
					
				}
				else
				{
					throw new Exception("API Key is not for a debtor."); 
				}
				return new HttpResult("Failed wrong api key type", System.Net.HttpStatusCode.BadRequest);
				
				
				
			}
						
			
			
			
			
			
			
			

		}
	#endregion
}




namespace JiwaFinancials.Jiwa.JiwaServiceModel.StoredProcedures
{
	public  static partial class SPList 
	{
		
		private static DbParameter CreateNewParameter(DbCommand dbCommand, string paramName, object paramValue, ParameterDirection paramDirection, DbType paramType)
		{
			DbParameter param = dbCommand.CreateParameter();
			param.Direction = paramDirection;
			param.DbType = paramType;
			param.ParameterName = paramName;
			param.Value = paramValue ?? DBNull.Value;
			return param;
		}		
		
	  public static OrmLiteSPStatement usp_JIWA_Debtors_StatementsAsAt(this IDbConnection db, string @sP_StartingDebtorAccountNo = null, string @sP_EndingDebtorAccountNo = null, DateTime? @sP_AsAtDate = null)
      {
         var dbCmd = (DbCommand)OrmLiteConfig.ExecFilter.CreateCommand(db).ToDbCommand();
        // dbCmd.CommandText = "usp_JIWA_Debtors_StatementsAsAt";
		dbCmd.CommandText = RESTAPIPlugin.StatementProc;
		
         dbCmd.CommandType = CommandType.StoredProcedure;
         dbCmd.Parameters.Add(CreateNewParameter(dbCmd,"SP_StartingDebtorAccountNo",@sP_StartingDebtorAccountNo,ParameterDirection.Input,DbType.AnsiString));
         dbCmd.Parameters.Add(CreateNewParameter(dbCmd,"SP_EndingDebtorAccountNo",@sP_EndingDebtorAccountNo,ParameterDirection.Input,DbType.AnsiString));
         dbCmd.Parameters.Add(CreateNewParameter(dbCmd,"SP_AsAtDate",@sP_AsAtDate,ParameterDirection.Input,DbType.DateTime));
          dbCmd.Parameters.Add(CreateNewParameter(dbCmd,"__ReturnValue",0,ParameterDirection.ReturnValue,DbType.Int32));
         return new OrmLiteSPStatement(db, dbCmd);
      }
	
		public static OrmLiteSPStatement usp_Jiwa_Invoices_Invoice(this IDbConnection db, string @sP_InvoiceHistoryID = null)
		{
			var dbCmd = (DbCommand)OrmLiteConfig.ExecFilter.CreateCommand(db).ToDbCommand();
			//dbCmd.CommandText = "usp_Jiwa_Invoices_Invoice";
			dbCmd.CommandText = RESTAPIPlugin.InvoiceProc;
			dbCmd.CommandType = CommandType.StoredProcedure;
			dbCmd.Parameters.Add(CreateNewParameter(dbCmd,"SP_InvoiceHistoryID",@sP_InvoiceHistoryID,ParameterDirection.Input,DbType.String));
			dbCmd.Parameters.Add(CreateNewParameter(dbCmd,"__ReturnValue",0,ParameterDirection.ReturnValue,DbType.Int32));
			return new OrmLiteSPStatement(db, dbCmd);
		}
		
		
	}
}</Code>
  <ExceptionPolicy>Report</ExceptionPolicy>
  <Language>CSharp</Language>
  <ReferenceCollection>
    <Reference>
      <RecID>503e2764-c816-4af3-b684-89acc7b42b7f</RecID>
      <AssemblyFullName>JiwaApplication, Version=7.2.1.0, Culture=neutral, PublicKeyToken=e30ce81e37f29c8c</AssemblyFullName>
      <AssemblyName>JiwaApplication.dll</AssemblyName>
      <AssemblyLocation>E:\Program Files (x86)\Jiwa Financials\Jiwa 7\JiwaApplication.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>77532399-32e4-430a-96b8-c490be8f3670</RecID>
      <AssemblyFullName>mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</AssemblyFullName>
      <AssemblyName>mscorlib.dll</AssemblyName>
      <AssemblyLocation>C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>d1029685-430f-4ac7-b054-44fcebb3db6e</RecID>
      <AssemblyFullName>System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</AssemblyFullName>
      <AssemblyName>System.dll</AssemblyName>
      <AssemblyLocation>C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>80411a13-c06b-47d2-85ab-d777f04580b8</RecID>
      <AssemblyFullName>Microsoft.VisualBasic, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</AssemblyFullName>
      <AssemblyName>Microsoft.VisualBasic.dll</AssemblyName>
      <AssemblyLocation>C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Microsoft.VisualBasic\v4.0_10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualBasic.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>73ea5bb9-0b18-4580-9dd5-5f0dc7bd5f79</RecID>
      <AssemblyFullName>System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</AssemblyFullName>
      <AssemblyName>System.Drawing.dll</AssemblyName>
      <AssemblyLocation>C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>36b45e8e-a940-41d1-b83f-b3c607941186</RecID>
      <AssemblyFullName>JiwaODBC, Version=7.2.1.0, Culture=neutral, PublicKeyToken=e30ce81e37f29c8c</AssemblyFullName>
      <AssemblyName>JiwaODBC.dll</AssemblyName>
      <AssemblyLocation>E:\Program Files (x86)\Jiwa Financials\Jiwa 7\JiwaODBC.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>4bd67c06-4ce9-4ef3-9568-801018dcacc6</RecID>
      <AssemblyFullName>System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</AssemblyFullName>
      <AssemblyName>System.Data.dll</AssemblyName>
      <AssemblyLocation>C:\WINDOWS\Microsoft.Net\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>6e8bbb9c-de8c-4228-99cc-d951dc063812</RecID>
      <AssemblyFullName>System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</AssemblyFullName>
      <AssemblyName>System.Xml.dll</AssemblyName>
      <AssemblyLocation>C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>87b4d77c-a9e5-4405-b09f-a826590d11cd</RecID>
      <AssemblyFullName>System.Runtime.Serialization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</AssemblyFullName>
      <AssemblyName>System.Runtime.Serialization.dll</AssemblyName>
      <AssemblyLocation>C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.Serialization\v4.0_4.0.0.0__b77a5c561934e089\System.Runtime.Serialization.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>e4bcf4e2-afc9-4f92-9eec-048b5d8b8a07</RecID>
      <AssemblyFullName>Microsoft.SqlServer.Smo, Version=14.100.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91</AssemblyFullName>
      <AssemblyName>Microsoft.SqlServer.Smo.dll</AssemblyName>
      <AssemblyLocation>E:\Program Files (x86)\Jiwa Financials\Jiwa 7\Microsoft.SqlServer.Smo.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>a6ed9539-a0c6-4d4f-a03b-9c1ad8b3a694</RecID>
      <AssemblyFullName>Microsoft.SqlServer.ConnectionInfo, Version=14.100.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91</AssemblyFullName>
      <AssemblyName>Microsoft.SqlServer.ConnectionInfo.dll</AssemblyName>
      <AssemblyLocation>E:\Program Files (x86)\Jiwa Financials\Jiwa 7\Microsoft.SqlServer.ConnectionInfo.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>a5ca4d7c-32e6-4515-825a-0bca47bd6dd2</RecID>
      <AssemblyFullName>System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</AssemblyFullName>
      <AssemblyName>System.Windows.Forms.dll</AssemblyName>
      <AssemblyLocation>C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>491a08c1-565b-4486-8480-6d88caa53af1</RecID>
      <AssemblyFullName>Infragistics4.Win.v13.1, Version=13.1.20131.2060, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb</AssemblyFullName>
      <AssemblyName>Infragistics4.Win.v13.1.dll</AssemblyName>
      <AssemblyLocation>C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Infragistics4.Win.v13.1\v4.0_13.1.20131.2060__7dd5c3163f2cd0cb\Infragistics4.Win.v13.1.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>7ea07c57-4ad3-4320-a72b-342d9c1a54c4</RecID>
      <AssemblyFullName>Infragistics4.Win.Misc.v13.1, Version=13.1.20131.2060, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb</AssemblyFullName>
      <AssemblyName>Infragistics4.Win.Misc.v13.1.dll</AssemblyName>
      <AssemblyLocation>C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Infragistics4.Win.Misc.v13.1\v4.0_13.1.20131.2060__7dd5c3163f2cd0cb\Infragistics4.Win.Misc.v13.1.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>56b0af21-e3e0-4a53-b352-479ecd18269f</RecID>
      <AssemblyFullName>Infragistics4.Win.UltraWinEditors.v13.1, Version=13.1.20131.2060, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb</AssemblyFullName>
      <AssemblyName>Infragistics4.Win.UltraWinEditors.v13.1.dll</AssemblyName>
      <AssemblyLocation>C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Infragistics4.Win.UltraWinEditors.v13.1\v4.0_13.1.20131.2060__7dd5c3163f2cd0cb\Infragistics4.Win.UltraWinEditors.v13.1.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>5304e270-a6ff-4755-839f-d95c28d5b8e7</RecID>
      <AssemblyFullName>Infragistics4.Win.UltraWinExplorerBar.v13.1, Version=13.1.20131.2060, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb</AssemblyFullName>
      <AssemblyName>Infragistics4.Win.UltraWinExplorerBar.v13.1.dll</AssemblyName>
      <AssemblyLocation>C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Infragistics4.Win.UltraWinExplorerBar.v13.1\v4.0_13.1.20131.2060__7dd5c3163f2cd0cb\Infragistics4.Win.UltraWinExplorerBar.v13.1.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>ab07dc87-aa3a-4759-becb-c1d6c3516d7c</RecID>
      <AssemblyFullName>Infragistics4.Win.UltraWinTree.v13.1, Version=13.1.20131.2060, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb</AssemblyFullName>
      <AssemblyName>Infragistics4.Win.UltraWinTree.v13.1.dll</AssemblyName>
      <AssemblyLocation>C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Infragistics4.Win.UltraWinTree.v13.1\v4.0_13.1.20131.2060__7dd5c3163f2cd0cb\Infragistics4.Win.UltraWinTree.v13.1.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>8721b0a0-ba4d-4a95-b83a-60fdb4c01ae6</RecID>
      <AssemblyFullName>FarPoint.Win.Spread, Version=8.35.20151.0, Culture=neutral, PublicKeyToken=327c3516b1b18457</AssemblyFullName>
      <AssemblyName>FarPoint.Win.Spread.dll</AssemblyName>
      <AssemblyLocation>C:\WINDOWS\assembly\GAC_MSIL\FarPoint.Win.Spread\8.35.20151.0__327c3516b1b18457\FarPoint.Win.Spread.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>d8a086de-6d76-4b06-93a0-25dae964273a</RecID>
      <AssemblyFullName>Infragistics4.Win.UltraWinTabControl.v13.1, Version=13.1.20131.2060, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb</AssemblyFullName>
      <AssemblyName>Infragistics4.Win.UltraWinTabControl.v13.1.dll</AssemblyName>
      <AssemblyLocation>C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Infragistics4.Win.UltraWinTabControl.v13.1\v4.0_13.1.20131.2060__7dd5c3163f2cd0cb\Infragistics4.Win.UltraWinTabControl.v13.1.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>6a3c2838-a19f-4ca1-a0e2-ab6f10026941</RecID>
      <AssemblyFullName>Infragistics4.Shared.v13.1, Version=13.1.20131.2060, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb</AssemblyFullName>
      <AssemblyName>Infragistics4.Shared.v13.1.dll</AssemblyName>
      <AssemblyLocation>C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Infragistics4.Shared.v13.1\v4.0_13.1.20131.2060__7dd5c3163f2cd0cb\Infragistics4.Shared.v13.1.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>35122810-e831-406a-a143-45576879881a</RecID>
      <AssemblyFullName>Infragistics4.Win.UltraWinToolbars.v13.1, Version=13.1.20131.2060, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb</AssemblyFullName>
      <AssemblyName>Infragistics4.Win.UltraWinToolbars.v13.1.dll</AssemblyName>
      <AssemblyLocation>C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Infragistics4.Win.UltraWinToolbars.v13.1\v4.0_13.1.20131.2060__7dd5c3163f2cd0cb\Infragistics4.Win.UltraWinToolbars.v13.1.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>296a043d-0825-47e1-961f-2e7c5eb4674e</RecID>
      <AssemblyFullName>Infragistics4.Win.UltraWinStatusBar.v13.1, Version=13.1.20131.2060, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb</AssemblyFullName>
      <AssemblyName>Infragistics4.Win.UltraWinStatusBar.v13.1.dll</AssemblyName>
      <AssemblyLocation>C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Infragistics4.Win.UltraWinStatusBar.v13.1\v4.0_13.1.20131.2060__7dd5c3163f2cd0cb\Infragistics4.Win.UltraWinStatusBar.v13.1.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>14567ac0-9dbd-4124-a763-12bb34ee9d34</RecID>
      <AssemblyFullName>Infragistics4.Win.UltraWinSchedule.v13.1, Version=13.1.20131.2060, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb</AssemblyFullName>
      <AssemblyName>Infragistics4.Win.UltraWinSchedule.v13.1.dll</AssemblyName>
      <AssemblyLocation>C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Infragistics4.Win.UltraWinSchedule.v13.1\v4.0_13.1.20131.2060__7dd5c3163f2cd0cb\Infragistics4.Win.UltraWinSchedule.v13.1.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>15d80987-877a-4afc-89cd-1618e2f725b1</RecID>
      <AssemblyFullName>Infragistics4.Win.UltraWinListView.v13.1, Version=13.1.20131.2060, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb</AssemblyFullName>
      <AssemblyName>Infragistics4.Win.UltraWinListView.v13.1.dll</AssemblyName>
      <AssemblyLocation>C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Infragistics4.Win.UltraWinListView.v13.1\v4.0_13.1.20131.2060__7dd5c3163f2cd0cb\Infragistics4.Win.UltraWinListView.v13.1.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>7bf671c8-15de-41d8-8189-1744d18a5e65</RecID>
      <AssemblyFullName>ServiceStack, Version=5.0.0.0, Culture=neutral, PublicKeyToken=02c12cbda47e6587</AssemblyFullName>
      <AssemblyName>ServiceStack.dll</AssemblyName>
      <AssemblyLocation>E:\Program Files (x86)\Jiwa Financials\Jiwa 7\ServiceStack.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>66d90239-533d-43dd-8e05-aa6cbdd6d65c</RecID>
      <AssemblyFullName>ActiproSoftware.SyntaxEditor.WinForms, Version=16.1.330.0, Culture=neutral, PublicKeyToken=c27e062d3c1a4763</AssemblyFullName>
      <AssemblyName>ActiproSoftware.SyntaxEditor.WinForms.dll</AssemblyName>
      <AssemblyLocation>E:\Program Files (x86)\Jiwa Financials\Jiwa 7\ActiproSoftware.SyntaxEditor.WinForms.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>11fd375b-1c6b-4e83-b3c1-8bccffa6a35d</RecID>
      <AssemblyFullName>ZetaHtmlEditControl, Version=1.1.0.3, Culture=neutral, PublicKeyToken=2e2e5ba5da72b6c0</AssemblyFullName>
      <AssemblyName>ZetaHtmlEditControl.dll</AssemblyName>
      <AssemblyLocation>E:\Program Files (x86)\Jiwa Financials\Jiwa 7\ZetaHtmlEditControl.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>4d7920fe-0498-4921-991e-0b6a15cb5f26</RecID>
      <AssemblyFullName>ActiproSoftware.SyntaxEditor.Addons.DotNet.WinForms, Version=16.1.330.0, Culture=neutral, PublicKeyToken=c27e062d3c1a4763</AssemblyFullName>
      <AssemblyName>ActiproSoftware.SyntaxEditor.Addons.DotNet.WinForms.dll</AssemblyName>
      <AssemblyLocation>E:\Program Files (x86)\Jiwa Financials\Jiwa 7\ActiproSoftware.SyntaxEditor.Addons.DotNet.WinForms.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>cf91e7e0-67c4-44bb-84dd-828ffd00fc01</RecID>
      <AssemblyFullName>System.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</AssemblyFullName>
      <AssemblyName>System.Security.dll</AssemblyName>
      <AssemblyLocation>C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Security\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Security.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>e211ad4a-569e-492f-b67a-a8be3bb78d9e</RecID>
      <AssemblyFullName>JiwaEncryption, Version=7.2.1.0, Culture=neutral, PublicKeyToken=e30ce81e37f29c8c</AssemblyFullName>
      <AssemblyName>JiwaEncryption.dll</AssemblyName>
      <AssemblyLocation>E:\Program Files (x86)\Jiwa Financials\Jiwa 7\JiwaEncryption.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>b9c3643d-5861-45cf-9fce-f60fd0ccb93b</RecID>
      <AssemblyFullName>Microsoft.SqlServer.Dac, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</AssemblyFullName>
      <AssemblyName>Microsoft.SqlServer.Dac.dll</AssemblyName>
      <AssemblyLocation>E:\Program Files (x86)\Jiwa Financials\Jiwa 7\Microsoft.SqlServer.Dac.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>408ce911-ed44-4a9b-8c71-310ec9fa91ae</RecID>
      <AssemblyFullName>CrystalDecisions.CrystalReports.Engine, Version=13.0.3500.0, Culture=neutral, PublicKeyToken=692fbea5521e1304</AssemblyFullName>
      <AssemblyName>CrystalDecisions.CrystalReports.Engine.dll</AssemblyName>
      <AssemblyLocation>C:\WINDOWS\assembly\GAC_MSIL\CrystalDecisions.CrystalReports.Engine\13.0.3500.0__692fbea5521e1304\CrystalDecisions.CrystalReports.Engine.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>7cb501ac-d1cc-4f72-8b2d-0ca70a5e9608</RecID>
      <AssemblyFullName>CrystalDecisions.Shared, Version=13.0.3500.0, Culture=neutral, PublicKeyToken=692fbea5521e1304</AssemblyFullName>
      <AssemblyName>CrystalDecisions.Shared.dll</AssemblyName>
      <AssemblyLocation>C:\WINDOWS\assembly\GAC_MSIL\CrystalDecisions.Shared\13.0.3500.0__692fbea5521e1304\CrystalDecisions.Shared.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>4b853dc5-8d35-4e8f-8e7a-268d435edc45</RecID>
      <AssemblyFullName>CrystalDecisions.ReportAppServer.ClientDoc, Version=13.0.3500.0, Culture=neutral, PublicKeyToken=692fbea5521e1304</AssemblyFullName>
      <AssemblyName>CrystalDecisions.ReportAppServer.ClientDoc.dll</AssemblyName>
      <AssemblyLocation>C:\WINDOWS\assembly\GAC_MSIL\CrystalDecisions.ReportAppServer.ClientDoc\13.0.3500.0__692fbea5521e1304\CrystalDecisions.ReportAppServer.ClientDoc.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>80f8e919-86ad-4e91-99ba-d1945ebf28b2</RecID>
      <AssemblyFullName>CrystalDecisions.ReportAppServer.Controllers, Version=13.0.3500.0, Culture=neutral, PublicKeyToken=692fbea5521e1304</AssemblyFullName>
      <AssemblyName>CrystalDecisions.ReportAppServer.Controllers.dll</AssemblyName>
      <AssemblyLocation>C:\WINDOWS\assembly\GAC_MSIL\CrystalDecisions.ReportAppServer.Controllers\13.0.3500.0__692fbea5521e1304\CrystalDecisions.ReportAppServer.Controllers.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>67668a0a-c405-4dc6-be16-ad18f0499b11</RecID>
      <AssemblyFullName>System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</AssemblyFullName>
      <AssemblyName>System.Core.dll</AssemblyName>
      <AssemblyLocation>C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>d793257a-5267-4c60-bd6a-43546f79863c</RecID>
      <AssemblyFullName>Infragistics4.Win.AppStylistSupport.v13.1, Version=13.1.20131.2060, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb</AssemblyFullName>
      <AssemblyName>Infragistics4.Win.AppStylistSupport.v13.1.dll</AssemblyName>
      <AssemblyLocation>C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Infragistics4.Win.AppStylistSupport.v13.1\v4.0_13.1.20131.2060__7dd5c3163f2cd0cb\Infragistics4.Win.AppStylistSupport.v13.1.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>d2f3cdad-1371-45be-b33f-b19e7825527c</RecID>
      <AssemblyFullName>JiwaLib, Version=7.2.1.0, Culture=neutral, PublicKeyToken=e30ce81e37f29c8c</AssemblyFullName>
      <AssemblyName>JiwaLib.dll</AssemblyName>
      <AssemblyLocation>E:\Program Files (x86)\Jiwa Financials\Jiwa 7\JiwaLib.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>21951da5-f4fc-4cfb-921f-fc97e3e948b3</RecID>
      <AssemblyFullName>Microsoft.ApplicationInsights, Version=2.4.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35</AssemblyFullName>
      <AssemblyName>Microsoft.ApplicationInsights.dll</AssemblyName>
      <AssemblyLocation>E:\Program Files (x86)\Jiwa Financials\Jiwa 7\Microsoft.ApplicationInsights.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>bed5b8b8-f9c8-4e1c-8614-b89d6d47cd59</RecID>
      <AssemblyFullName>CrystalDecisions.Windows.Forms, Version=13.0.3500.0, Culture=neutral, PublicKeyToken=692fbea5521e1304</AssemblyFullName>
      <AssemblyName>CrystalDecisions.Windows.Forms.dll</AssemblyName>
      <AssemblyLocation>C:\WINDOWS\assembly\GAC_MSIL\CrystalDecisions.Windows.Forms\13.0.3500.0__692fbea5521e1304\CrystalDecisions.Windows.Forms.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>46d72c64-69e0-4c49-8279-43dc222d5930</RecID>
      <AssemblyFullName>Infragistics4.Win.UltraWinGrid.v13.1, Version=13.1.20131.2060, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb</AssemblyFullName>
      <AssemblyName>Infragistics4.Win.UltraWinGrid.v13.1.dll</AssemblyName>
      <AssemblyLocation>C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Infragistics4.Win.UltraWinGrid.v13.1\v4.0_13.1.20131.2060__7dd5c3163f2cd0cb\Infragistics4.Win.UltraWinGrid.v13.1.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>34da9199-42dd-41c3-83ee-56ceaac13cf2</RecID>
      <AssemblyFullName>ActiproSoftware.Shared.WinForms, Version=16.1.330.0, Culture=neutral, PublicKeyToken=c27e062d3c1a4763</AssemblyFullName>
      <AssemblyName>ActiproSoftware.Shared.WinForms.dll</AssemblyName>
      <AssemblyLocation>E:\Program Files (x86)\Jiwa Financials\Jiwa 7\ActiproSoftware.Shared.WinForms.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>c290c0b2-b1d8-42bd-b710-f357c34d524f</RecID>
      <AssemblyFullName>FarPoint.Win, Version=8.35.20151.0, Culture=neutral, PublicKeyToken=327c3516b1b18457</AssemblyFullName>
      <AssemblyName>FarPoint.Win.dll</AssemblyName>
      <AssemblyLocation>C:\WINDOWS\assembly\GAC_MSIL\FarPoint.Win\8.35.20151.0__327c3516b1b18457\FarPoint.Win.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>a3f6c11c-4f2f-47ca-a57c-0710d98a538c</RecID>
      <AssemblyFullName>CrystalDecisions.ReportAppServer.ReportDefModel, Version=13.0.3500.0, Culture=neutral, PublicKeyToken=692fbea5521e1304</AssemblyFullName>
      <AssemblyName>CrystalDecisions.ReportAppServer.ReportDefModel.dll</AssemblyName>
      <AssemblyLocation>C:\WINDOWS\assembly\GAC_MSIL\CrystalDecisions.ReportAppServer.ReportDefModel\13.0.3500.0__692fbea5521e1304\CrystalDecisions.ReportAppServer.ReportDefModel.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>081bc8f2-f221-4022-a0ac-c25e3cb9b7d7</RecID>
      <AssemblyFullName>ServiceStack.Interfaces, Version=5.0.0.0, Culture=neutral, PublicKeyToken=02c12cbda47e6587</AssemblyFullName>
      <AssemblyName>ServiceStack.Interfaces.dll</AssemblyName>
      <AssemblyLocation>E:\Program Files (x86)\Jiwa Financials\Jiwa 7\ServiceStack.Interfaces.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>58505eef-3fd9-4c59-a427-37f74db035df</RecID>
      <AssemblyFullName>ServiceStack.Server, Version=5.0.0.0, Culture=neutral, PublicKeyToken=02c12cbda47e6587</AssemblyFullName>
      <AssemblyName>ServiceStack.Server.dll</AssemblyName>
      <AssemblyLocation>E:\Program Files (x86)\Jiwa Financials\Jiwa 7\ServiceStack.Server.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>e1f39e59-3dee-49df-bdd6-dddb8547f948</RecID>
      <AssemblyFullName>ServiceStack.OrmLite, Version=5.0.0.0, Culture=neutral, PublicKeyToken=02c12cbda47e6587</AssemblyFullName>
      <AssemblyName>ServiceStack.OrmLite.dll</AssemblyName>
      <AssemblyLocation>E:\Program Files (x86)\Jiwa Financials\Jiwa 7\ServiceStack.OrmLite.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>643f3260-f9d5-4ade-a022-2e9a223c56bd</RecID>
      <AssemblyFullName>ServiceStack.OrmLite.SqlServer, Version=5.0.0.0, Culture=neutral, PublicKeyToken=02c12cbda47e6587</AssemblyFullName>
      <AssemblyName>ServiceStack.OrmLite.SqlServer.dll</AssemblyName>
      <AssemblyLocation>E:\Program Files (x86)\Jiwa Financials\Jiwa 7\ServiceStack.OrmLite.SqlServer.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>67902a2c-e442-4bfc-9198-cd865dbe01d3</RecID>
      <AssemblyFullName>ServiceStack.Text, Version=5.0.0.0, Culture=neutral, PublicKeyToken=02c12cbda47e6587</AssemblyFullName>
      <AssemblyName>ServiceStack.Text.dll</AssemblyName>
      <AssemblyLocation>E:\Program Files (x86)\Jiwa Financials\Jiwa 7\ServiceStack.Text.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>0c6d8245-c571-403b-a1cf-44876e1a620f</RecID>
      <AssemblyFullName>System.Net, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</AssemblyFullName>
      <AssemblyName>System.Net.dll</AssemblyName>
      <AssemblyLocation>C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Net\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Net.dll</AssemblyLocation>
    </Reference>
    <Reference>
      <RecID>7f173096-0dec-40e5-99a9-03780eec6250</RecID>
      <AssemblyFullName>JiwaServiceModel, Version=7.2.1.0, Culture=neutral, PublicKeyToken=e30ce81e37f29c8c</AssemblyFullName>
      <AssemblyName>JiwaServiceModel.dll</AssemblyName>
      <AssemblyLocation>E:\Program Files (x86)\Jiwa Financials\Jiwa 7\JiwaServiceModel.dll</AssemblyLocation>
    </Reference>
  </ReferenceCollection>
  <SystemSettingCollection>
    <SystemSetting>
      <RecID>1283637b60734084bb4d</RecID>
      <IDKey>IProc</IDKey>
      <Description>Stored Procedure for Invoices</Description>
      <DisplayOrder>1</DisplayOrder>
      <CellType>Lookup</CellType>
      <Contents>usp_Jiwa_Invoices_Invoice</Contents>
      <DisplayContents>usp_Jiwa_Invoices_Invoice</DisplayContents>
    </SystemSetting>
    <SystemSetting>
      <RecID>e276f9023ce24b04ab26</RecID>
      <IDKey>IRep</IDKey>
      <Description>Invoice Report</Description>
      <DisplayOrder>2</DisplayOrder>
      <CellType>Lookup</CellType>
      <Contents>8ce38d28-d320-4b82-9038-8cf2b1880ca4</Contents>
      <DisplayContents>8ce38d28-d320-4b82-9038-8cf2b1880ca4</DisplayContents>
    </SystemSetting>
    <SystemSetting>
      <RecID>95dc21897dc54dc7b78f</RecID>
      <IDKey>SProc</IDKey>
      <Description>Stored Procedure for Statements</Description>
      <DisplayOrder>3</DisplayOrder>
      <CellType>Lookup</CellType>
      <Contents>usp_JIWA_Debtors_StatementsAsAt</Contents>
      <DisplayContents>usp_JIWA_Debtors_StatementsAsAt</DisplayContents>
    </SystemSetting>
    <SystemSetting>
      <RecID>332edf7b38664b709575</RecID>
      <IDKey>SRep</IDKey>
      <Description>Statement Report</Description>
      <DisplayOrder>4</DisplayOrder>
      <CellType>Lookup</CellType>
      <Contents>843535cf-9d8f-4950-beb0-70d6ed44a527</Contents>
      <DisplayContents>843535cf-9d8f-4950-beb0-70d6ed44a527</DisplayContents>
    </SystemSetting>
    <SystemSetting>
      <RecID>1f038460621f40e09fbf</RecID>
      <IDKey>PDFExport</IDKey>
      <Description>Allow PDF Export</Description>
      <DisplayOrder>5</DisplayOrder>
      <CellType>Checkbox</CellType>
      <Contents>True</Contents>
      <DisplayContents>True</DisplayContents>
    </SystemSetting>
    <SystemSetting>
      <RecID>57a6153ad7504cdba2dc</RecID>
      <IDKey>GExport</IDKey>
      <Description>Allow General Export to csv and XML</Description>
      <DisplayOrder>6</DisplayOrder>
      <CellType>Checkbox</CellType>
      <Contents>True</Contents>
      <DisplayContents>True</DisplayContents>
    </SystemSetting>
    <SystemSetting>
      <RecID>8c364281fae445dcaf90</RecID>
      <IDKey>SExport</IDKey>
      <Description>Allow Statement Export</Description>
      <DisplayOrder>7</DisplayOrder>
      <CellType>Checkbox</CellType>
      <Contents>True</Contents>
      <DisplayContents>True</DisplayContents>
    </SystemSetting>
    <SystemSetting>
      <RecID>9a8e83bd21e04068b870</RecID>
      <IDKey>IExport</IDKey>
      <Description>Allow Invoice Export</Description>
      <DisplayOrder>8</DisplayOrder>
      <CellType>Checkbox</CellType>
      <Contents>True</Contents>
      <DisplayContents>True</DisplayContents>
    </SystemSetting>
  </SystemSettingCollection>
  <PluginReferenceCollection>
    <PluginReference>
      <RecID>cfd292a8-b28a-46de-a9b1-299a0fce4805</RecID>
      <Plugin>
        <RecID xmlns="Entities.Plugin">7ddc7010-5098-4aaf-b518-9f93c64065af</RecID>
        <Name xmlns="Entities.Plugin">REST API</Name>
        <Description xmlns="Entities.Plugin">Provides a REST HTTP endpoint with some routes.</Description>
        <Author xmlns="Entities.Plugin">Jiwa Financials</Author>
        <IsEnabled xmlns="Entities.Plugin">false</IsEnabled>
        <ExecutionOrder xmlns="Entities.Plugin">0</ExecutionOrder>
      </Plugin>
    </PluginReference>
  </PluginReferenceCollection>
</JiwaDocument>