mirror of
https://github.com/stokebob/BealeEngineering.git
synced 2026-03-19 06:37:15 +00:00
Added form to view sales invoices. Feature to match and split sales invoices to purchase orders Other minor updates/improvements to UI and database functions
225 lines
6.6 KiB
C#
225 lines
6.6 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 ReadInvoiceHeader : Connection
|
|
{
|
|
public ReadInvoiceHeader(string sqlConnectionString) : base(sqlConnectionString)
|
|
{
|
|
|
|
}
|
|
|
|
protected List<int> SalesInvoiceIdList { get; set; }
|
|
|
|
protected bool SalesInvoiceIdListListIsSet
|
|
{
|
|
get
|
|
{
|
|
if (SalesInvoiceIdList == null || !SalesInvoiceIdList.Any()) { return false; }
|
|
else { return true; }
|
|
}
|
|
}
|
|
|
|
protected List<string> SalesInvoiceNumberList { get; set; }
|
|
|
|
protected bool SalesInvoiceNumberListIsSet
|
|
{
|
|
get
|
|
{
|
|
if (SalesInvoiceNumberList == null || !SalesInvoiceNumberList.Any()) { return false; }
|
|
else { return true; }
|
|
}
|
|
}
|
|
|
|
public DateTime DateFrom { get; set; }
|
|
|
|
public bool DateFromIsSet
|
|
{
|
|
get
|
|
{
|
|
if (DateFrom == null || DateFrom == default(DateTime)) { return false; }
|
|
else { return true; }
|
|
}
|
|
}
|
|
|
|
public DateTime DateTo { get; set; }
|
|
|
|
public bool DateToIsSet
|
|
{
|
|
get
|
|
{
|
|
if (DateTo == null || DateTo == default(DateTime)) { return false; }
|
|
else { return true; }
|
|
}
|
|
}
|
|
|
|
public List<string> InvoiceNumber { get; set; }
|
|
|
|
public bool InvoiceNumberIsSet
|
|
{
|
|
get
|
|
{
|
|
if (InvoiceNumber == null || !InvoiceNumber.Any()) { return false; }
|
|
else { return true; }
|
|
}
|
|
}
|
|
|
|
public List<string> Reference { get; set; }
|
|
|
|
public bool ReferenceIsSet
|
|
{
|
|
get
|
|
{
|
|
if (Reference == null || !Reference.Any()) { return false; }
|
|
else { return true; }
|
|
}
|
|
}
|
|
|
|
public Model.Sale.InvoiceHeader BySaleInvoiceId(int invoiceId)
|
|
{
|
|
var invoiceList = new List<int> { invoiceId };
|
|
var resultList = BySaleInvoiceId(invoiceList);
|
|
|
|
if (resultList == null || !resultList.Any()) { return null; }
|
|
else { return resultList[0]; }
|
|
}
|
|
|
|
public List<Model.Sale.InvoiceHeader> BySaleInvoiceId(List<int> invoiceIdList)
|
|
{
|
|
SalesInvoiceIdList = invoiceIdList;
|
|
try
|
|
{
|
|
return Read();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
finally
|
|
{
|
|
SalesInvoiceIdList = null;
|
|
}
|
|
}
|
|
|
|
public Model.Sale.InvoiceHeader BySaleInvoiceNumber(string invoiceNumber)
|
|
{
|
|
var invoiceList = new List<string> { invoiceNumber };
|
|
var resultList = BySaleInvoiceNumber(invoiceList);
|
|
|
|
if (resultList == null || !resultList.Any()) { return null; }
|
|
else { return resultList[0]; }
|
|
}
|
|
|
|
public List<Model.Sale.InvoiceHeader> BySaleInvoiceNumber(List<string> invoiceNumberList)
|
|
{
|
|
SalesInvoiceNumberList = invoiceNumberList;
|
|
try
|
|
{
|
|
return Read();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
finally
|
|
{
|
|
SalesInvoiceNumberList = null;
|
|
}
|
|
}
|
|
|
|
protected void AddSqlWhereString(ref string sqlString, ref DynamicParameters parameters)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(sqlString))
|
|
{ throw new Exception("SQL string is empty."); }
|
|
|
|
sqlString = sqlString + @"
|
|
WHERE 1=1";
|
|
|
|
if (SalesInvoiceIdListListIsSet)
|
|
{
|
|
sqlString = sqlString + @"
|
|
AND SaleInvoice.SaleInvoiceID IN @saleInvoiceId";
|
|
|
|
parameters.Add("@saleInvoiceId", SalesInvoiceIdList);
|
|
}
|
|
else if (SalesInvoiceNumberListIsSet)
|
|
{
|
|
sqlString = sqlString + @"
|
|
AND SaleInvoice.SaleInvoiceNumber IN @salesInvoiceNumberList";
|
|
|
|
parameters.Add("@salesInvoiceNumberList", SalesInvoiceNumberList);
|
|
}
|
|
else
|
|
{
|
|
if (DateFromIsSet)
|
|
{
|
|
sqlString = sqlString + @"
|
|
AND InvoiceDate >= @dateFrom";
|
|
|
|
parameters.Add("@dateFrom", DateFrom);
|
|
}
|
|
if (DateToIsSet)
|
|
{
|
|
sqlString = sqlString + @"
|
|
AND InvoiceDate <= @dateTo";
|
|
|
|
parameters.Add("@dateTo", DateTo);
|
|
}
|
|
if (InvoiceNumberIsSet)
|
|
{
|
|
sqlString = sqlString + @"
|
|
AND SaleInvoiceNumber IN @salesInvoiceNumber";
|
|
|
|
parameters.Add("@salesInvoiceNumber", InvoiceNumber);
|
|
}
|
|
if (ReferenceIsSet)
|
|
{
|
|
sqlString = sqlString + @"
|
|
AND Reference IN @reference";
|
|
|
|
parameters.Add("@reference", Reference);
|
|
}
|
|
}
|
|
}
|
|
public List<Model.Sale.InvoiceHeader> Read()
|
|
{
|
|
// build the sql string and dapper parameters
|
|
var parameters = new DynamicParameters();
|
|
string sqlString = @"
|
|
SELECT SaleInvoice.SaleInvoiceID
|
|
,SaleInvoice.SaleInvoiceNumber
|
|
,SaleInvoice.InvoiceDate
|
|
,SaleInvoice.DateDue
|
|
,SaleInvoice.Reference
|
|
,SaleInvoice.CurrencyCode
|
|
,SaleInvoice.InvoiceTotal
|
|
,SaleInvoice.TaxTotal
|
|
,SaleInvoice.IsCreditNote
|
|
,SaleInvoice.Status
|
|
,Contact.ContactName
|
|
FROM SaleInvoice
|
|
INNER JOIN Contact ON SaleInvoice.ContactID = Contact.ContactID";
|
|
|
|
AddSqlWhereString(ref sqlString, ref parameters);
|
|
|
|
sqlString = sqlString + @"
|
|
ORDER BY SaleInvoiceID";
|
|
|
|
// make the call
|
|
using (SqlConnection conn = new SqlConnection(sqlConnectionString))
|
|
{
|
|
conn.Open();
|
|
|
|
var invoiceHeaders = conn.Query<Model.Sale.InvoiceHeader>(sqlString, parameters).ToList();
|
|
return invoiceHeaders;
|
|
}
|
|
}
|
|
}
|
|
}
|