mirror of
https://github.com/stokebob/BealeEngineering.git
synced 2026-03-21 15:47:15 +00:00
Added feature to auto allocate sales invoices to client purchase orders.
This commit is contained in:
@@ -0,0 +1,160 @@
|
||||
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 InvoiceHeaderGet : Connection
|
||||
{
|
||||
public InvoiceHeaderGet(string sqlConnectionString) : base(sqlConnectionString)
|
||||
{
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Setting this will override he other filters, within the sql statement.
|
||||
/// </summary>
|
||||
protected List<int> SalesInvoiceIdList { get; set; }
|
||||
private bool SalesInvoiceIdListListIsSet
|
||||
{
|
||||
get
|
||||
{
|
||||
if (SalesInvoiceIdList == null || !SalesInvoiceIdList.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 List<Model.Sale.InvoiceHeader> GetBySaleInvoiceId(List<int> orderIdList)
|
||||
{
|
||||
SalesInvoiceIdList = orderIdList;
|
||||
try
|
||||
{
|
||||
return GetByFilters();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
finally
|
||||
{
|
||||
SalesInvoiceIdList = 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 (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> GetByFilters()
|
||||
{
|
||||
// build the sql string and dapper parameters
|
||||
var parameters = new DynamicParameters();
|
||||
string sqlString = @"
|
||||
SELECT SaleInvoiceID
|
||||
,ContactID
|
||||
,SaleInvoiceNumber
|
||||
,InvoiceDate
|
||||
,DateDue
|
||||
,Reference
|
||||
,CurrencyCode
|
||||
,InvoiceTotal
|
||||
,TaxTotal
|
||||
,IsCreditNote
|
||||
FROM SaleInvoice";
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user