mirror of
https://github.com/stokebob/BealeEngineering.git
synced 2026-03-21 07:37:16 +00:00
115 lines
4.1 KiB
C#
115 lines
4.1 KiB
C#
using Dapper;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data.SqlClient;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace BealeEngineering.Core.Data.Database.Sale
|
|
{
|
|
public class ReadInvoice : ReadInvoiceHeader
|
|
{
|
|
public ReadInvoice(string sqlConnectionString) : base(sqlConnectionString)
|
|
{
|
|
|
|
}
|
|
public List<Model.Sale.InvoiceHeader> SaleInvoiceHeader { get; set; }
|
|
public bool SaleInvoiceHeaderIsSet
|
|
{
|
|
get
|
|
{
|
|
if (SaleInvoiceHeader == null || !SaleInvoiceHeader.Any()) { return false; }
|
|
else { return true; }
|
|
}
|
|
}
|
|
public new List<Model.Sale.Invoice> GetBySaleInvoiceId(List<int> invoiceIdList)
|
|
{
|
|
SalesInvoiceIdList = invoiceIdList;
|
|
try
|
|
{
|
|
return Read();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
finally
|
|
{
|
|
SalesInvoiceIdList = null;
|
|
}
|
|
}
|
|
public new List<Model.Sale.Invoice> Read()
|
|
{
|
|
// build the sql string and dapper parameters
|
|
var parameters = new DynamicParameters();
|
|
string sqlString = @"
|
|
SELECT SaleInvoice.SaleInvoiceID
|
|
,SaleInvoice.SaleInvoiceNumber
|
|
,SaleInvoice.InvoiceDate
|
|
,Contact.ContactName
|
|
,SaleInvoice.DateDue
|
|
,SaleInvoice.Reference
|
|
,SaleInvoice.CurrencyCode
|
|
,SaleInvoice.InvoiceTotal
|
|
,SaleInvoice.TaxTotal
|
|
,SaleInvoice.IsCreditNote
|
|
,SaleInvoice.Status
|
|
,SaleInvoiceLine.SaleInvoiceLineID
|
|
,SaleInvoiceLine.SaleInvoiceID
|
|
,SaleInvoiceLine.LineNumber
|
|
,SaleInvoiceLine.InventoryItemCode
|
|
,SaleInvoiceLine.Description
|
|
,SaleInvoiceLine.Quantity
|
|
,SaleInvoiceLine.UnitAmount
|
|
,SaleInvoiceLine.Discount
|
|
,SaleInvoiceLine.AccountCode
|
|
,SaleInvoiceLine.TaxType
|
|
,SaleInvoiceLine.TaxAmount
|
|
,SaleInvoiceLine.LineAmount
|
|
FROM SaleInvoice
|
|
INNER JOIN Contact ON SaleInvoice.ContactID = Contact.ContactID
|
|
LEFT OUTER JOIN SaleInvoiceLine ON SaleInvoice.SaleInvoiceID = SaleInvoiceLine.SaleInvoiceID";
|
|
|
|
AddSqlWhereString(ref sqlString, ref parameters);
|
|
|
|
sqlString = sqlString + @"
|
|
ORDER BY SaleInvoice.SaleInvoiceID
|
|
,SaleInvoiceLine.LineNumber
|
|
,SaleInvoiceLine.SaleInvoiceLineID";
|
|
|
|
// make the call
|
|
using (SqlConnection conn = new SqlConnection(sqlConnectionString))
|
|
{
|
|
conn.Open();
|
|
|
|
var invoiceDictionary = new Dictionary<int, Model.Sale.Invoice>();
|
|
|
|
var invoiceList = conn.Query<Model.Sale.Invoice, Model.Sale.Invoice.InvoiceLine, Model.Sale.Invoice>
|
|
(
|
|
sqlString,
|
|
(invoice, invoiceDetail) =>
|
|
{
|
|
Model.Sale.Invoice invoiceEntry;
|
|
|
|
if (!invoiceDictionary.TryGetValue(invoice.SaleInvoiceID, out invoiceEntry))
|
|
{
|
|
invoiceEntry = invoice;
|
|
invoiceEntry.InvoiceLineList = new List<Model.Sale.Invoice.InvoiceLine>();
|
|
invoiceDictionary.Add(invoiceEntry.SaleInvoiceID, invoiceEntry);
|
|
}
|
|
|
|
invoiceEntry.InvoiceLineList.Add(invoiceDetail);
|
|
return invoiceEntry;
|
|
},
|
|
parameters,
|
|
splitOn: "SaleInvoiceLineID")
|
|
.Distinct()
|
|
.ToList();
|
|
|
|
return invoiceList;
|
|
}
|
|
}
|
|
}
|
|
}
|