mirror of
https://github.com/stokebob/bnhtrade.git
synced 2026-03-19 14:37:16 +00:00
* complete read invoices from db * wip * wip * wip * wip * wip * wip * wip * wip * updated nuget package spapi * WIP * wip, now test * wip, jut need to fix tax inclusive line amounts not supported * wip * wip, before I f everything up * no, it complies now, this is the one before I f everything up * wip * wip * wip, logic ready for testing * wip it builds!!!! * wip tested, working, need to complete the gui section * wip * wip * wip - created export invoice data delete, time for testing * wip testing phase * wip - delete function fully tested and working * wip on to sorting out the issue with settlement invoices not tallying * wip * wip * wip * wip * wip before I complete change the ReadInvoiceLineItem sections * that appears to have worked, on with the main quest * no it's doesn't work, saving before i remove the confusing cache system (just use a dictionary!!) * wipping picadilli * wip * wip * implemented uow on inovice export, now for testing * wip * wip all tested do invoice currency convertion fearure * wip * pretty much done so long as xero accepts the exported invoices * Complete!
127 lines
4.5 KiB
C#
127 lines
4.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Microsoft.Data.SqlClient;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace bnhtrade.Core.Data.Database.Account
|
|
{
|
|
public class ReadAccountCode : Connection
|
|
{
|
|
private Data.Database.SqlWhereBuilder sqlWhere = new SqlWhereBuilder();
|
|
|
|
public ReadAccountCode()
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the full chart of accounts
|
|
/// </summary>
|
|
/// <returns>Dictionary where the database record id is the key</returns>
|
|
public Dictionary<uint, Model.Account.Account> All()
|
|
{
|
|
Innit();
|
|
var list = Execute(null, null);
|
|
var dictionary = new Dictionary<uint, Model.Account.Account>();
|
|
foreach (var item in list)
|
|
{
|
|
dictionary.Add(item.Value.Id, item.Value);
|
|
}
|
|
return dictionary;
|
|
}
|
|
|
|
public Dictionary<uint, Model.Account.Account> ByAccountId(List<uint> accountIdList)
|
|
{
|
|
Innit();
|
|
var resultDict = new Dictionary<uint, Model.Account.Account>();
|
|
|
|
if (accountIdList == null || !accountIdList.Any())
|
|
{
|
|
return resultDict;
|
|
}
|
|
|
|
sqlWhere.In("tblAccountChartOf.AccountChartOfID", accountIdList, " WHERE ");
|
|
resultDict = Execute(sqlWhere.SqlWhereString, sqlWhere.ParameterList);
|
|
return resultDict;
|
|
}
|
|
|
|
public Dictionary<uint, Model.Account.Account> ByAccountCode(List<int> accountCodeList)
|
|
{
|
|
Innit();
|
|
var resultDict = new Dictionary<uint, Model.Account.Account>();
|
|
|
|
if (accountCodeList == null || !accountCodeList.Any())
|
|
{
|
|
return resultDict;
|
|
}
|
|
|
|
sqlWhere.In("tblAccountChartOf.AccountCode", accountCodeList, " WHERE ");
|
|
resultDict = Execute(sqlWhere.SqlWhereString, sqlWhere.ParameterList);
|
|
return resultDict;
|
|
}
|
|
|
|
private Dictionary<uint, Model.Account.Account> Execute(string sqlWhere, Dictionary<string, object> parameters)
|
|
{
|
|
var resultDict = new Dictionary<uint, Model.Account.Account>();
|
|
|
|
//build sql query
|
|
string sqlString = @"
|
|
SELECT tblAccountChartOf.AccountChartOfID
|
|
,tblAccountChartOf.AccountCode
|
|
,tblAccountChartOf.AccountName
|
|
,tblAccountChartOf.Description
|
|
,tblAccountChartOfType.AccountChartOfType
|
|
,tblAccountChartOfType.BasicType
|
|
,tblAccountChartOfType.Multiplier
|
|
FROM tblAccountChartOf
|
|
INNER JOIN tblAccountChartOfType ON tblAccountChartOf.AccountChartOfTypeID = tblAccountChartOfType.AccountChartOfTypeID
|
|
" + sqlWhere;
|
|
|
|
using (SqlConnection conn = new SqlConnection(SqlConnectionString))
|
|
{
|
|
conn.Open();
|
|
|
|
using (SqlCommand cmd = new SqlCommand(sqlString, conn))
|
|
{
|
|
if (parameters != null)
|
|
{
|
|
foreach (var parameter in parameters)
|
|
{
|
|
cmd.Parameters.AddWithValue(parameter.Key, parameter.Value);
|
|
}
|
|
}
|
|
|
|
using (SqlDataReader reader = cmd.ExecuteReader())
|
|
{
|
|
if (reader.HasRows)
|
|
{
|
|
while (reader.Read())
|
|
{
|
|
|
|
uint tablePk = (uint)reader.GetInt32(0);
|
|
uint accountCode = (uint)reader.GetInt32(1);
|
|
string title = reader.GetString(2);
|
|
string description = null;
|
|
if (!reader.IsDBNull(3)) { description = reader.GetString(3); }
|
|
string type = reader.GetString(4);
|
|
string basicType = reader.GetString(5);
|
|
int multiplier = reader.GetInt32(6);
|
|
|
|
var result = new Model.Account.Account(tablePk, accountCode, title, description, type, basicType, multiplier);
|
|
resultDict.Add(tablePk, result);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return resultDict;
|
|
}
|
|
|
|
private void Innit()
|
|
{
|
|
sqlWhere.Init();
|
|
}
|
|
}
|
|
}
|