From c2082acf8e583d4c83ba4beb9c0f50edd1169d11 Mon Sep 17 00:00:00 2001 From: Bobbie Hodgetts Date: Fri, 10 May 2024 18:30:45 +0100 Subject: [PATCH] progress has been made. Beer o'clock --- .../Data/Database/Account/Contact.cs | 105 ++++++++++ .../Data/Database/Account/PurchaseInvoice.cs | 178 +++++++++++++++++ .../Database/Account/PurchaseInvoiceLine.cs | 187 ++++++++++++++++++ .../PurchaseInvoiceLineStatus.cs} | 12 +- .../Data/Database/SqlWhereBuilder.cs | 83 ++++++++ .../Logic/Account/PurchaseInvoice.cs | 16 ++ .../Logic/Purchase/PurchaseLineStatus.cs | 16 -- src/bnhtrade.Core/Model/Account/Contact.cs | 27 +++ .../Model/Account/PurchaseInvoice.cs | 52 +++++ .../Account/PurchaseInvoiceLineStatus.cs | 24 +++ src/bnhtrade.Core/Test/Account/Account.cs | 18 +- src/bnhtrade.Core/bnhtrade.Core.csproj | 6 +- .../bnhtrade.ScheduledTasks.csproj | 1 - src/bnhtrade.gui/Form1.Designer.cs | 74 +++---- src/bnhtrade.gui/Form1.cs | 16 +- src/bnhtrade.gui/Form1.resx | 3 + 16 files changed, 750 insertions(+), 68 deletions(-) create mode 100644 src/bnhtrade.Core/Data/Database/Account/Contact.cs create mode 100644 src/bnhtrade.Core/Data/Database/Account/PurchaseInvoice.cs create mode 100644 src/bnhtrade.Core/Data/Database/Account/PurchaseInvoiceLine.cs rename src/bnhtrade.Core/Data/Database/{Purchase/PurchaseLineStatus.cs => Account/PurchaseInvoiceLineStatus.cs} (75%) create mode 100644 src/bnhtrade.Core/Logic/Account/PurchaseInvoice.cs delete mode 100644 src/bnhtrade.Core/Logic/Purchase/PurchaseLineStatus.cs create mode 100644 src/bnhtrade.Core/Model/Account/Contact.cs create mode 100644 src/bnhtrade.Core/Model/Account/PurchaseInvoice.cs create mode 100644 src/bnhtrade.Core/Model/Account/PurchaseInvoiceLineStatus.cs diff --git a/src/bnhtrade.Core/Data/Database/Account/Contact.cs b/src/bnhtrade.Core/Data/Database/Account/Contact.cs new file mode 100644 index 0000000..1a75568 --- /dev/null +++ b/src/bnhtrade.Core/Data/Database/Account/Contact.cs @@ -0,0 +1,105 @@ +using System; +using System.Collections.Generic; +using System.Data.SqlClient; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace bnhtrade.Core.Data.Database.Account +{ + internal class Contact : Connection + { + private bnhtrade.Core.Data.Database.SqlWhereBuilder sqlBuilder; + + public List ContactIdList { get; set; } + + public Contact() + { + Init(); + } + + public void Init() + { + sqlBuilder = new SqlWhereBuilder(); + ContactIdList = new List(); + } + + public Dictionary Read() + { + var returnList = new Dictionary(); + sqlBuilder.Init(); + + //build sql query + string sql = @" + SELECT [ContactID] + ,[ContactName] + ,[PaypalName] + ,[PaypalEmail] + ,[EbayUsername] + ,[EbayEmail] + ,[RecordCreated] + ,[RecordModified] + FROM [e2A].[dbo].[tblContact] + WHERE 1=1 "; + + // build the where statments + if (ContactIdList.Any()) + { + sqlBuilder.In("[ContactID]", ContactIdList, "AND"); + } + + // append where string to the sql + if (sqlBuilder.IsSetSqlWhereString) + { + sql = sql + sqlBuilder.SqlWhereString; + } + + using (SqlConnection conn = new SqlConnection(SqlConnectionString)) + { + conn.Open(); + + using (SqlCommand cmd = new SqlCommand(sql, conn)) + { + sqlBuilder.AddParametersToSqlCommand(cmd); + + using (SqlDataReader reader = cmd.ExecuteReader()) + { + if (reader.HasRows) + { + while (reader.Read()) + { + int contactId = reader.GetInt32(0); + string contactName = null; + if (!reader.IsDBNull(1)) { contactName = reader.GetString(1); } + string paypalName = null; + if (!reader.IsDBNull(2)) { paypalName = reader.GetString(2); } + string paypalEmail = null; + if (!reader.IsDBNull(3)) { paypalEmail = reader.GetString(3); } + string ebayUsername = null; + if (!reader.IsDBNull(4)) { ebayUsername = reader.GetString(4); } + string ebayEmail = null; + if (!reader.IsDBNull(5)) { ebayEmail = reader.GetString(5); } + DateTime recordCreated = DateTime.SpecifyKind(reader.GetDateTime(6), DateTimeKind.Utc); + DateTime? recordModified = null; + if (!reader.IsDBNull(7)) { recordModified = DateTime.SpecifyKind(reader.GetDateTime(7), DateTimeKind.Utc); } + + var contact = new Model.Account.Contact(); + contact.ContactId = contactId; + contact.ContantName = contactName; + contact.ContactPaypalName = paypalName; + contact.ContactPaypalEmail = paypalEmail; + contact.ContactEbayName = ebayUsername; + contact.ContactEbayEmail = ebayEmail; + contact.Created = recordCreated; + contact.Modified = recordModified; + + returnList.Add(contactId, contact); + } + } + } + } + } + return returnList; + } + } +} diff --git a/src/bnhtrade.Core/Data/Database/Account/PurchaseInvoice.cs b/src/bnhtrade.Core/Data/Database/Account/PurchaseInvoice.cs new file mode 100644 index 0000000..17574b0 --- /dev/null +++ b/src/bnhtrade.Core/Data/Database/Account/PurchaseInvoice.cs @@ -0,0 +1,178 @@ +using System; +using System.Collections.Generic; +using System.Data.SqlClient; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using static System.ComponentModel.Design.ObjectSelectorEditor; + +namespace bnhtrade.Core.Data.Database.Account +{ + internal class PurchaseInvoice : Connection + { + private bnhtrade.Core.Data.Database.SqlWhereBuilder sqlBuilder; + + public List PurchaseInvoiceIdList { get; set; } + + public PurchaseInvoice() + { + Init(); + } + + public void Init() + { + sqlBuilder = new SqlWhereBuilder(); + PurchaseInvoiceIdList = new List(); + } + + public Dictionary Read() + { + var returnList = new Dictionary(); + sqlBuilder.Init(); + + //build sql query + string sql = @" + SELECT tblPurchase.PurchaseID + ,tblPurchase.PurchaseNumber + ,tblPurchase.RecordID + ,tblPurchase.PurchaseDate + ,tblPurchase.ContactID + ,tblPurchase.SupplierRef + ,tblPurchase.PurchaseTotalAmount + ,tblPurchase.VatInclusiveAmounts + ,tblPurchase.RecordCreated + ,tblPurchase.RecordModified + ,tblPurchase.IsActive + ,tblAccountCurrency.CurrencyCode + ,tblPurchaseChannel.PurchaseChannelName + ,tblPurchaseStatus.PurchaseStatus + FROM tblPurchase + LEFT OUTER JOIN tblAccountCurrency ON tblPurchase.AccountCurrencyID = tblAccountCurrency.AccountCurrencyID + LEFT OUTER JOIN tblPurchaseStatus ON tblPurchase.PurchaseStatusID = tblPurchaseStatus.PurchaseStatusID + LEFT OUTER JOIN tblPurchaseChannel ON tblPurchase.PurchaseChannelID = tblPurchaseChannel.PurchaseChannelID + WHERE 1 = 1 + "; + + // build the where statments + if (PurchaseInvoiceIdList.Any()) + { + sqlBuilder.In("[PurchaseID]", PurchaseInvoiceIdList, "AND"); + } + + // append where string to the sql + if (sqlBuilder.IsSetSqlWhereString) + { + sql = sql + sqlBuilder.SqlWhereString; + } + + // dictionary so we can fill in details afterwards + var invoiceContactDict = new Dictionary(); + var purchaseIdList = new List(); + + using (SqlConnection conn = new SqlConnection(SqlConnectionString)) + { + conn.Open(); + + using (SqlCommand cmd = new SqlCommand(sql, conn)) + { + sqlBuilder.AddParametersToSqlCommand(cmd); + + using (SqlDataReader reader = cmd.ExecuteReader()) + { + if (reader.HasRows) + { + while (reader.Read()) + { + + + int purchaseID = reader.GetInt32(0); + int purchaseNumber = reader.GetInt32(1); + int? recordID = null; + if (!reader.IsDBNull(2)) { recordID = reader.GetInt32(2); } + DateTime purchaseDate = DateTime.SpecifyKind(reader.GetDateTime(3), DateTimeKind.Utc); + int? contactID = null; + if (!reader.IsDBNull(4)) { contactID = reader.GetInt32(4);} + string supplierRef = null; + if (!reader.IsDBNull(5)) { supplierRef = reader.GetString(5);} + decimal? purchaseTotalAmount = null; + if (!reader.IsDBNull(6)) { purchaseTotalAmount = reader.GetDecimal(6);} + bool vatInclusiveAmounts = reader.GetBoolean(7); + DateTime recordCreated = DateTime.SpecifyKind(reader.GetDateTime(8), DateTimeKind.Utc); + DateTime recordModified = DateTime.SpecifyKind(reader.GetDateTime(9), DateTimeKind.Utc); + bool isActive = reader.GetBoolean(10); + string currencyCode = reader.GetString(11); + string purchaseChannelName = reader.GetString(12); + string purchaseStatus = null; + if (!reader.IsDBNull(13)) { purchaseStatus = reader.GetString(13);} + + var invoice = new Model.Account.PurchaseInvoice(); + invoice.PurchaseID = purchaseID; + invoice.PurchaseNumber = purchaseNumber; + invoice.RecordID = recordID; + invoice.PurchaseDate = purchaseDate; + invoice.SupplierRef = supplierRef; + //invoice.PurchaseTotalAmount = purchaseTotalAmount; + invoice.VatInclusiveAmounts = vatInclusiveAmounts; + invoice.RecordCreated = recordCreated; + invoice.RecordModified = recordModified; + invoice.IsActive = isActive; + invoice.CurrencyCode = currencyCode; + invoice.PurchaseChannel = purchaseChannelName; + + // is there contact info that needs to be added? + if (contactID != null) + { + invoiceContactDict.Add(purchaseID, (int)contactID); + } + + purchaseIdList.Add(purchaseID); + + returnList.Add(purchaseID, invoice); + } + } + } + } + } + // add contact info + if (invoiceContactDict.Any()) + { + var readContact = new Data.Database.Account.Contact(); + readContact.ContactIdList = invoiceContactDict.Values.ToList(); + var contactDict = readContact.Read(); + + if (contactDict.Any()) + { + foreach ( var invoice in returnList) + { + if (invoiceContactDict.ContainsKey(invoice.Value.PurchaseID)) + { + int contactId = invoiceContactDict[invoice.Value.PurchaseID]; + invoice.Value.Contact = contactDict[contactId]; + } + } + } + } + + // add invoice lines + var readLines = new Data.Database.Account.PurchaseInvoiceLine(); + readLines.InvoiceIdList = purchaseIdList; + var lines = readLines.Read(); + foreach(var invoice in returnList.Values) + { + foreach(var line in lines.Values) + { + if (line.PurchaseId == invoice.PurchaseID) + { + if (invoice.InvoiceLines == null) + { + invoice.InvoiceLines = new List(); + } + invoice.InvoiceLines.Add(line); + } + } + } + + return returnList; + } + } +} diff --git a/src/bnhtrade.Core/Data/Database/Account/PurchaseInvoiceLine.cs b/src/bnhtrade.Core/Data/Database/Account/PurchaseInvoiceLine.cs new file mode 100644 index 0000000..4e7ee2f --- /dev/null +++ b/src/bnhtrade.Core/Data/Database/Account/PurchaseInvoiceLine.cs @@ -0,0 +1,187 @@ +using Amazon.Runtime.Internal.Transform; +using System; +using System.Collections.Generic; +using System.Data.SqlClient; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using static System.ComponentModel.Design.ObjectSelectorEditor; + +namespace bnhtrade.Core.Data.Database.Account +{ + internal class PurchaseInvoiceLine : Connection + { + private bnhtrade.Core.Data.Database.SqlWhereBuilder sqlBuilder; + + /// + /// Results filter + /// + public List InvoiceIdList { get; set; } + + /// + /// Results filter + /// + public List InvoiceLineIdList { get; set; } + + /// + /// Results filter + /// + public List StatusList { get; set; } + + /// + /// Searches for the specificed phases within the item description. Uses the LIKE AND sql function + /// + public List ItemDescription { get; set; } + + public PurchaseInvoiceLine() + { + Init(); + } + + public void Init() + { + sqlBuilder = new SqlWhereBuilder(); + InvoiceIdList = new List(); + InvoiceLineIdList = new List(); + StatusList = new List(); + } + + public Dictionary Read() + { + var returnList = new Dictionary(); + sqlBuilder.Init(); + + //build sql query + string sql = @" + SELECT tblPurchaseLine.PurchaseLineID + ,tblPurchaseLine.PurchaseID + ,tblPurchaseLineStatus.PurchaseLineStatus + ,tblPurchaseLine.SupplierRef + ,tblPurchaseLine.CheckedIn + ,tblPurchaseLine.ItemDescription + ,tblPurchaseLine.ItemQuantity + ,tblPurchaseLine.ItemGross + ,tblPurchaseLine.ItemTax + ,tblPurchaseLine.ShippingGross + ,tblPurchaseLine.ShippingTax + ,tblPurchaseLine.OtherGross + ,tblPurchaseLine.OtherTax + ,tblPurchaseLine.AccountTaxCodeID + ,tblPurchaseLine.Tax_AccountTransactionID + ,tblPurchaseLine.Net_AccountChartOfID + ,tblPurchaseLine.Net_AccountTransactionID + ,tblPurchaseLine.RecordCreated + ,tblPurchaseLine.RecordModified + ,tblPurchaseLine.IsActive + ,tblAccountTaxCode.TaxCode + FROM tblPurchaseLine + INNER JOIN tblPurchaseLineStatus ON tblPurchaseLine.PurchaseLineStatusID = tblPurchaseLineStatus.PurchaseLineStatusID + LEFT OUTER JOIN tblAccountTaxCode ON tblPurchaseLine.AccountTaxCodeID = tblAccountTaxCode.AccountTaxCodeID + WHERE 1 = 1 "; + + // build the where statments + if (InvoiceIdList.Any()) + { + sqlBuilder.In("PurchaseID", InvoiceLineIdList, "AND"); + } + if (InvoiceLineIdList.Any()) + { + sqlBuilder.In("PurchaseLineID", InvoiceLineIdList, "AND"); + } + if (StatusList.Any()) + { + sqlBuilder.In("PurchaseLineStatus", InvoiceLineIdList, "AND"); + } + if (ItemDescription.Any()) + { + sqlBuilder.LikeAnd("ItemDescription", ItemDescription, "AND"); + } + + + // append where string to the sql + if (sqlBuilder.IsSetSqlWhereString) + { + sql = sql + sqlBuilder.SqlWhereString; + } + + using (SqlConnection conn = new SqlConnection(SqlConnectionString)) + { + conn.Open(); + + using (SqlCommand cmd = new SqlCommand(sql, conn)) + { + sqlBuilder.AddParametersToSqlCommand(cmd); + + using (SqlDataReader reader = cmd.ExecuteReader()) + { + if (reader.HasRows) + { + while (reader.Read()) + { + int purchaseLineID = reader.GetInt32(0); + int purchaseID = reader.GetInt32(1); + string purchaseLineStatus = reader.GetString(2); + string supplierRef = null; + if (!reader.IsDBNull(3)) { supplierRef = reader.GetString(3); } + DateTime? checkedIn = null; + if (!reader.IsDBNull(4)) { checkedIn = DateTime.SpecifyKind(reader.GetDateTime(4), DateTimeKind.Utc); } + string itemDescription = null; + if (!reader.IsDBNull(5)) { itemDescription = reader.GetString(5); } + int itemQuantity = reader.GetInt32(6); + decimal itemGross = 0; + if (!reader.IsDBNull(7)) { itemGross = reader.GetDecimal(7); } + decimal itemTax = 0; + if (!reader.IsDBNull(8)) { itemTax = reader.GetDecimal(8); } + decimal shippingGross = 0; + if (!reader.IsDBNull(9)) { shippingGross = reader.GetDecimal(9); } + decimal shippingTax = 0; + if (!reader.IsDBNull(10)) { shippingTax = reader.GetDecimal(10); } + decimal otherGross = 0; + if (!reader.IsDBNull(11)) { otherGross = reader.GetDecimal(11); } + decimal otherTax = 0; + if (!reader.IsDBNull(12)) { otherTax = reader.GetDecimal(12); } + int accountTaxCodeID = reader.GetInt32(13); + int? tax_AccountTransactionID = null; + if (!reader.IsDBNull(14)) { tax_AccountTransactionID = reader.GetInt32(14); } + int net_AccountChartOfID = reader.GetInt32(15); + int? net_AccountTransactionID = null; + if (!reader.IsDBNull(16)) { net_AccountTransactionID = reader.GetInt32(16); } + DateTime recordModified; + DateTime recordCreated = DateTime.SpecifyKind(reader.GetDateTime(17), DateTimeKind.Utc); + if (reader.IsDBNull(18)) { recordModified = recordCreated; } + else { recordModified = DateTime.SpecifyKind(reader.GetDateTime(18), DateTimeKind.Utc); } + bool isActive = reader.GetBoolean(19); + string accountTaxCode = reader.GetString(20); + + var line = new Model.Account.PurchaseInvoice.Line(); + line.PurchaseLineId = purchaseLineID; + line.PurchaseId = purchaseID; + line.Status = purchaseLineStatus; + line.SupplierRef = supplierRef; + line.CheckedIn = checkedIn; + line.ItemDescription = itemDescription; + line.ItemQuantity = itemQuantity; + line.ItemGross = itemGross; + line.ItemTax = itemTax; + line.ShippingGross = shippingGross; + line.ShippingTax = shippingTax; + line.OtherGross = otherGross; + line.OtherTax = otherTax; + line.Tax_AccountTransactionId = tax_AccountTransactionID; + line.Net_AccountChartOfId = net_AccountChartOfID; + line.Net_AccountTransactionId = net_AccountTransactionID; + line.RecordModified = recordModified; + line.RecordCreated = recordCreated; + line.IsActive = isActive; + line.AccountTaxCode = accountTaxCode; + + returnList.Add(purchaseLineID, line); + } + } + } + } + } + return returnList; + } + } +} diff --git a/src/bnhtrade.Core/Data/Database/Purchase/PurchaseLineStatus.cs b/src/bnhtrade.Core/Data/Database/Account/PurchaseInvoiceLineStatus.cs similarity index 75% rename from src/bnhtrade.Core/Data/Database/Purchase/PurchaseLineStatus.cs rename to src/bnhtrade.Core/Data/Database/Account/PurchaseInvoiceLineStatus.cs index 04c41e4..ded5807 100644 --- a/src/bnhtrade.Core/Data/Database/Purchase/PurchaseLineStatus.cs +++ b/src/bnhtrade.Core/Data/Database/Account/PurchaseInvoiceLineStatus.cs @@ -5,13 +5,13 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace bnhtrade.Core.Data.Database.Purchase +namespace bnhtrade.Core.Data.Database.Account { - public class PurchaseLineStatus : Connection + internal class PurchaseInvoiceLineStatus : Connection { - public List Read() + public Dictionary Read() { - var returnList = new List(); + var returnList = new Dictionary(); using (SqlConnection conn = new SqlConnection(SqlConnectionString)) { @@ -41,8 +41,8 @@ namespace bnhtrade.Core.Data.Database.Purchase string name = reader.GetString(1); int lineSort = reader.GetInt32(2); - var returnItem = new Model.Purchase.PurchaseLineStatus(id, name,lineSort); - returnList.Add( returnItem ); + var returnItem = new Model.Account.PurchaseInvoiceLineStatus(id, name,lineSort); + returnList.Add(id, returnItem ); } } } diff --git a/src/bnhtrade.Core/Data/Database/SqlWhereBuilder.cs b/src/bnhtrade.Core/Data/Database/SqlWhereBuilder.cs index 48009fb..c75213c 100644 --- a/src/bnhtrade.Core/Data/Database/SqlWhereBuilder.cs +++ b/src/bnhtrade.Core/Data/Database/SqlWhereBuilder.cs @@ -64,6 +64,89 @@ namespace bnhtrade.Core.Data.Database } } + /// + /// Append an 'Like' statement (with AND between each like string) and parameter list to the class properties + /// + /// Name of the column to used to for the condition statement + /// List of phrases to test in condition statement + /// Optional prefix that gets added to the sql string result + public void LikeAnd(string columnReference, List phraseList, string wherePrefix = null) + { + Like(columnReference, phraseList, true, wherePrefix); + } + + /// + /// Append an 'Like' statement (with OR between each like string) and parameter list to the class properties + /// + /// Name of the column to used to for the condition statement + /// List of phrases to test in condition statement + /// Optional prefix that gets added to the sql string result + public void LikeOr(string columnReference, List phraseList, string wherePrefix = null) + { + Like(columnReference, phraseList, false, wherePrefix); + } + + private void Like(string columnReference, List phraseList, bool isAnd, string wherePrefix = null) + { + if (phraseList == null || !phraseList.Any()) + { + return; + } + + // ensure no values are repeated + var distinctList = phraseList.ToList(); + + // clean the list + for (int i = 0; i < distinctList.Count; i++) + { + if (string.IsNullOrEmpty(distinctList[i])) + { + distinctList.RemoveAt(i); + i--; + } + } + + // check again + if (distinctList == null || !distinctList.Any()) + { + return; + } + + string sqlWhere = @" + "; + + if (wherePrefix != null) + { + sqlWhere += wherePrefix; + } + + + int listCount = distinctList.Count(); + for (int i = 0; i < listCount; i++, parameterCount++) + { + if (i > 0) + { + if (isAnd) + { + sqlWhere += " AND "; + } + else + { + sqlWhere += " OR "; + } + } + + sqlWhere += " ( " + columnReference + " LIKE '%' + "; + + string param = "@parameter" + parameterCount; + sqlWhere += param; + ParameterList.Add(param, distinctList[i]); + + sqlWhere += " + '%' ) "; + } + SqlWhereString = SqlWhereString + sqlWhere; + } + /// /// Append an 'In' statement and parameter list to the class properties /// diff --git a/src/bnhtrade.Core/Logic/Account/PurchaseInvoice.cs b/src/bnhtrade.Core/Logic/Account/PurchaseInvoice.cs new file mode 100644 index 0000000..2f8e014 --- /dev/null +++ b/src/bnhtrade.Core/Logic/Account/PurchaseInvoice.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace bnhtrade.Core.Logic.Account +{ + public class PurchaseInvoice + { + public List ReadLineStatusToList() + { + return new Data.Database.Account.PurchaseInvoiceLineStatus().Read().Values.ToList(); + } + } +} diff --git a/src/bnhtrade.Core/Logic/Purchase/PurchaseLineStatus.cs b/src/bnhtrade.Core/Logic/Purchase/PurchaseLineStatus.cs deleted file mode 100644 index 4ddccc1..0000000 --- a/src/bnhtrade.Core/Logic/Purchase/PurchaseLineStatus.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace bnhtrade.Core.Logic.Purchase -{ - public class PurchaseLineStatus - { - public List ReadAll() - { - return new Data.Database.Purchase.PurchaseLineStatus().Read(); - } - } -} diff --git a/src/bnhtrade.Core/Model/Account/Contact.cs b/src/bnhtrade.Core/Model/Account/Contact.cs new file mode 100644 index 0000000..db43313 --- /dev/null +++ b/src/bnhtrade.Core/Model/Account/Contact.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace bnhtrade.Core.Model.Account +{ + public class Contact + { + public int ContactId { get; set; } + + public string ContantName { get; set; } + + public string ContactEbayName { get; set; } + + public string ContactEbayEmail { get; set; } + + public string ContactPaypalName { get; set; } + + public string ContactPaypalEmail { get; set; } + + public DateTime Created { get; set; } + + public DateTime? Modified { get; set; } + } +} diff --git a/src/bnhtrade.Core/Model/Account/PurchaseInvoice.cs b/src/bnhtrade.Core/Model/Account/PurchaseInvoice.cs new file mode 100644 index 0000000..b6e3250 --- /dev/null +++ b/src/bnhtrade.Core/Model/Account/PurchaseInvoice.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace bnhtrade.Core.Model.Account +{ + public class PurchaseInvoice + { + public int PurchaseID { get; set; } + public int PurchaseNumber { get; set; } + public int? RecordID { get; set; } + public DateTime PurchaseDate { get; set; } + public Model.Account.Contact Contact { get; set; } + public string SupplierRef { get; set; } + public string AccountCurrency { get; set; } + public string PurchaseChannel { get; set; } + public string CurrencyCode { get; set; } + public decimal PurchaseTotalAmount { get; set; } + public bool VatInclusiveAmounts { get; set; } + public DateTime RecordCreated { get; set; } + public DateTime RecordModified { get; set; } + public bool IsActive { get; set; } + + public List InvoiceLines { get; set; } + + public class Line + { + public int PurchaseLineId { get; set; } + public int PurchaseId { get; set; } + public string Status { get; set; } + public string SupplierRef { get; set; } + public DateTime? CheckedIn { get; set; } + public string ItemDescription { get; set; } + public int ItemQuantity { get; set; } + public decimal ItemGross { get; set; } + public decimal ItemTax { get; set; } + public decimal ShippingGross { get; set; } + public decimal ShippingTax { get; set; } + public decimal OtherGross { get; set; } + public decimal OtherTax { get; set; } + public string AccountTaxCode { get; set; } + public int? Tax_AccountTransactionId { get; set; } + public int Net_AccountChartOfId { get; set; } + public int? Net_AccountTransactionId { get; set; } + public DateTime RecordCreated { get; set; } + public DateTime RecordModified { get; set; } + public bool IsActive { get; set; } + } + } +} diff --git a/src/bnhtrade.Core/Model/Account/PurchaseInvoiceLineStatus.cs b/src/bnhtrade.Core/Model/Account/PurchaseInvoiceLineStatus.cs new file mode 100644 index 0000000..81f8f00 --- /dev/null +++ b/src/bnhtrade.Core/Model/Account/PurchaseInvoiceLineStatus.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace bnhtrade.Core.Model.Account +{ + public class PurchaseInvoiceLineStatus + { + public PurchaseInvoiceLineStatus(int statusId, string statusName, int listSort) + { + PurchaseLineStatusId = statusId; + PurchaseLineStatusName = statusName; + ListSort = listSort; + } + + public int PurchaseLineStatusId { get; private set; } + + public string PurchaseLineStatusName { get; private set; } + + public int ListSort { get; private set; } + } +} \ No newline at end of file diff --git a/src/bnhtrade.Core/Test/Account/Account.cs b/src/bnhtrade.Core/Test/Account/Account.cs index b6386be..b1a2459 100644 --- a/src/bnhtrade.Core/Test/Account/Account.cs +++ b/src/bnhtrade.Core/Test/Account/Account.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows.Forms.Design; namespace bnhtrade.Core.Test.Account { @@ -10,10 +11,21 @@ namespace bnhtrade.Core.Test.Account { public Account() { - //var inst = new Data.Database.Account.GetTaxCode(sqlConnectionString); - //inst. + PurchaseInvoiceLine(); + } - //var taxInfo = inst.GetAll(); + public void PurchaseInvoice() + { + var read = new Data.Database.Account.PurchaseInvoice(); + read.PurchaseInvoiceIdList = new List { 14718, 100, 101, 102, 300, 400, 1200, 2734, 6339, 9999 }; // 10 in total + var result = read.Read(); + } + + public void PurchaseInvoiceLine() + { + var read = new Data.Database.Account.PurchaseInvoiceLine(); + read.ItemDescription = new List { "xbox", "kill" }; + var result = read.Read(); } } } diff --git a/src/bnhtrade.Core/bnhtrade.Core.csproj b/src/bnhtrade.Core/bnhtrade.Core.csproj index 1d28874..55a9e13 100644 --- a/src/bnhtrade.Core/bnhtrade.Core.csproj +++ b/src/bnhtrade.Core/bnhtrade.Core.csproj @@ -20,7 +20,11 @@ - + + + + + diff --git a/src/bnhtrade.ScheduledTasks/bnhtrade.ScheduledTasks.csproj b/src/bnhtrade.ScheduledTasks/bnhtrade.ScheduledTasks.csproj index 72b1ef4..4b3c2a2 100644 --- a/src/bnhtrade.ScheduledTasks/bnhtrade.ScheduledTasks.csproj +++ b/src/bnhtrade.ScheduledTasks/bnhtrade.ScheduledTasks.csproj @@ -68,7 +68,6 @@ - xcopy /E /Y "$(TargetDir)" "C:\Users\Bobbie\Dropbox\Apps\bnhtrade" bnhtrade Scheduled Tasks bnhtrade Scheduled Tasks Copyright © 2018 diff --git a/src/bnhtrade.gui/Form1.Designer.cs b/src/bnhtrade.gui/Form1.Designer.cs index 2ba8c6c..099a324 100644 --- a/src/bnhtrade.gui/Form1.Designer.cs +++ b/src/bnhtrade.gui/Form1.Designer.cs @@ -31,15 +31,15 @@ components = new System.ComponentModel.Container(); tabControl1 = new TabControl(); tabPage1 = new TabPage(); - tabPage3 = new TabPage(); + tabPage2 = new TabPage(); + Receiving = new TabPage(); comboBox1 = new ComboBox(); + purchaseLineStatusBindingSource = new BindingSource(components); dtTmOrderSearch = new DateTimePicker(); label1 = new Label(); txtbxOrderSearch = new TextBox(); - tabPage2 = new TabPage(); - purchaseLineStatusBindingSource = new BindingSource(components); tabControl1.SuspendLayout(); - tabPage3.SuspendLayout(); + Receiving.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)purchaseLineStatusBindingSource).BeginInit(); SuspendLayout(); // @@ -47,8 +47,8 @@ // tabControl1.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; tabControl1.Controls.Add(tabPage1); - tabControl1.Controls.Add(tabPage3); tabControl1.Controls.Add(tabPage2); + tabControl1.Controls.Add(Receiving); tabControl1.Location = new Point(12, 12); tabControl1.Name = "tabControl1"; tabControl1.SelectedIndex = 0; @@ -66,20 +66,31 @@ tabPage1.Text = "Home"; tabPage1.UseVisualStyleBackColor = true; // - // tabPage3 + // tabPage2 // - tabPage3.Controls.Add(comboBox1); - tabPage3.Controls.Add(dtTmOrderSearch); - tabPage3.Controls.Add(label1); - tabPage3.Controls.Add(txtbxOrderSearch); - tabPage3.Location = new Point(4, 24); - tabPage3.Name = "tabPage3"; - tabPage3.Padding = new Padding(3); - tabPage3.Size = new Size(1002, 505); - tabPage3.TabIndex = 2; - tabPage3.Text = "Receiving"; - tabPage3.UseVisualStyleBackColor = true; - tabPage3.Click += tabPage3_Click; + tabPage2.AccessibleName = ""; + tabPage2.Location = new Point(4, 24); + tabPage2.Name = "tabPage2"; + tabPage2.Padding = new Padding(3); + tabPage2.Size = new Size(1002, 505); + tabPage2.TabIndex = 1; + tabPage2.Text = "FBA Shipments"; + tabPage2.UseVisualStyleBackColor = true; + // + // Receiving + // + Receiving.Controls.Add(comboBox1); + Receiving.Controls.Add(dtTmOrderSearch); + Receiving.Controls.Add(label1); + Receiving.Controls.Add(txtbxOrderSearch); + Receiving.Location = new Point(4, 24); + Receiving.Name = "Receiving"; + Receiving.Padding = new Padding(3); + Receiving.Size = new Size(1002, 505); + Receiving.TabIndex = 2; + Receiving.Text = "Receiving"; + Receiving.UseVisualStyleBackColor = true; + Receiving.Click += tabPage3_Click; // // comboBox1 // @@ -93,6 +104,11 @@ comboBox1.ValueMember = "PurchaseLineStatusId"; comboBox1.SelectedIndexChanged += comboBox1_SelectedIndexChanged; // + // purchaseLineStatusBindingSource + // + purchaseLineStatusBindingSource.DataSource = typeof(Core.Model.Purchase.PurchaseLineStatus); + purchaseLineStatusBindingSource.CurrentChanged += purchaseLineStatusBindingSource_CurrentChanged; + // // dtTmOrderSearch // dtTmOrderSearch.Location = new Point(356, 46); @@ -116,22 +132,6 @@ txtbxOrderSearch.Size = new Size(268, 23); txtbxOrderSearch.TabIndex = 0; // - // tabPage2 - // - tabPage2.AccessibleName = ""; - tabPage2.Location = new Point(4, 24); - tabPage2.Name = "tabPage2"; - tabPage2.Padding = new Padding(3); - tabPage2.Size = new Size(1002, 505); - tabPage2.TabIndex = 1; - tabPage2.Text = "FBA Shipments"; - tabPage2.UseVisualStyleBackColor = true; - // - // purchaseLineStatusBindingSource - // - purchaseLineStatusBindingSource.DataSource = typeof(Core.Model.Purchase.PurchaseLineStatus); - purchaseLineStatusBindingSource.CurrentChanged += purchaseLineStatusBindingSource_CurrentChanged; - // // Form1 // AutoScaleDimensions = new SizeF(7F, 15F); @@ -142,8 +142,8 @@ Text = "Form1"; Load += Form1_Load; tabControl1.ResumeLayout(false); - tabPage3.ResumeLayout(false); - tabPage3.PerformLayout(); + Receiving.ResumeLayout(false); + Receiving.PerformLayout(); ((System.ComponentModel.ISupportInitialize)purchaseLineStatusBindingSource).EndInit(); ResumeLayout(false); } @@ -153,7 +153,7 @@ private TabControl tabControl1; private TabPage tabPage1; private TabPage tabPage2; - private TabPage tabPage3; + private TabPage Receiving; private TextBox txtbxOrderSearch; private Label label1; private DateTimePicker dtTmOrderSearch; diff --git a/src/bnhtrade.gui/Form1.cs b/src/bnhtrade.gui/Form1.cs index 578eaf2..75d3ee7 100644 --- a/src/bnhtrade.gui/Form1.cs +++ b/src/bnhtrade.gui/Form1.cs @@ -3,12 +3,11 @@ namespace bnhtrade.gui public partial class Form1 : Form { - bool loadedTabIndex1 = false; + bool initTabReceiving = false; public Form1() { InitializeComponent(); - purchaseLineStatusBindingSource.DataSource = new Core.Logic.Purchase.PurchaseLineStatus().ReadAll(); } private void Form1_Load(object sender, EventArgs e) @@ -24,13 +23,21 @@ namespace bnhtrade.gui private void tabControl1_SelectedIndexChanged(object sender, EventArgs e) { int index = (sender as TabControl).SelectedIndex; + string name = tabControl1.SelectedTab.Name; - if (index == 1) + if (name == "Receiving" && initTabReceiving == false) { - + InitialiseTabReceiving(); } } + private void InitialiseTabReceiving() + { + purchaseLineStatusBindingSource.DataSource = new Core.Logic.Account.PurchaseInvoice().ReadLineStatusToList(); + initTabReceiving = true; + MessageBox.Show("ldsakjfl;s"); + } + private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { @@ -40,5 +47,6 @@ namespace bnhtrade.gui { } + } } diff --git a/src/bnhtrade.gui/Form1.resx b/src/bnhtrade.gui/Form1.resx index fbfcf25..6a9ea6f 100644 --- a/src/bnhtrade.gui/Form1.resx +++ b/src/bnhtrade.gui/Form1.resx @@ -120,4 +120,7 @@ 17, 17 + + 17, 17 + \ No newline at end of file