From b790a7b6421c36a2a769492ef24327ef2023f719 Mon Sep 17 00:00:00 2001 From: Bobbie Hodgetts Date: Thu, 9 May 2024 16:42:32 +0100 Subject: [PATCH 01/15] wip --- bnhtrade.gui/Form1.Designer.cs | 149 ++++++++++++++++++ bnhtrade.gui/Form1.cs | 33 ++++ bnhtrade.gui/Form1.resx | 120 ++++++++++++++ bnhtrade.gui/Program.cs | 17 ++ bnhtrade.gui/bnhtrade.gui.csproj | 11 ++ bnhtrade.sln | 6 + .../Database/Purchase/PurchaseLineStatus.cs | 54 +++++++ .../Logic/Purchase/PurchaseLineStatus.cs | 16 ++ .../Model/Purchase/PurchaseLineStatus.cs | 18 +++ src/bnhtrade.Core/bnhtrade.Core.csproj | 3 + 10 files changed, 427 insertions(+) create mode 100644 bnhtrade.gui/Form1.Designer.cs create mode 100644 bnhtrade.gui/Form1.cs create mode 100644 bnhtrade.gui/Form1.resx create mode 100644 bnhtrade.gui/Program.cs create mode 100644 bnhtrade.gui/bnhtrade.gui.csproj create mode 100644 src/bnhtrade.Core/Data/Database/Purchase/PurchaseLineStatus.cs create mode 100644 src/bnhtrade.Core/Logic/Purchase/PurchaseLineStatus.cs create mode 100644 src/bnhtrade.Core/Model/Purchase/PurchaseLineStatus.cs diff --git a/bnhtrade.gui/Form1.Designer.cs b/bnhtrade.gui/Form1.Designer.cs new file mode 100644 index 0000000..843036f --- /dev/null +++ b/bnhtrade.gui/Form1.Designer.cs @@ -0,0 +1,149 @@ +namespace bnhtrade.gui +{ + partial class Form1 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + tabControl1 = new TabControl(); + tabPage1 = new TabPage(); + tabPage3 = new TabPage(); + comboBox1 = new ComboBox(); + dtTmOrderSearch = new DateTimePicker(); + label1 = new Label(); + txtbxOrderSearch = new TextBox(); + tabPage2 = new TabPage(); + tabControl1.SuspendLayout(); + tabPage3.SuspendLayout(); + SuspendLayout(); + // + // tabControl1 + // + tabControl1.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + tabControl1.Controls.Add(tabPage1); + tabControl1.Controls.Add(tabPage3); + tabControl1.Controls.Add(tabPage2); + tabControl1.Location = new Point(12, 12); + tabControl1.Name = "tabControl1"; + tabControl1.SelectedIndex = 0; + tabControl1.Size = new Size(1010, 533); + tabControl1.TabIndex = 0; + tabControl1.SelectedIndexChanged += tabControl1_SelectedIndexChanged; + // + // tabPage1 + // + tabPage1.Location = new Point(4, 24); + tabPage1.Name = "tabPage1"; + tabPage1.Padding = new Padding(3); + tabPage1.Size = new Size(1002, 505); + tabPage1.TabIndex = 0; + tabPage1.Text = "Home"; + tabPage1.UseVisualStyleBackColor = true; + // + // tabPage3 + // + 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; + // + // comboBox1 + // + comboBox1.FormattingEnabled = true; + comboBox1.Location = new Point(580, 46); + comboBox1.Name = "comboBox1"; + comboBox1.Size = new Size(214, 23); + comboBox1.TabIndex = 3; + // + // dtTmOrderSearch + // + dtTmOrderSearch.Location = new Point(356, 46); + dtTmOrderSearch.Name = "dtTmOrderSearch"; + dtTmOrderSearch.Size = new Size(157, 23); + dtTmOrderSearch.TabIndex = 2; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(31, 28); + label1.Name = "label1"; + label1.Size = new Size(75, 15); + label1.TabIndex = 1; + label1.Text = "Order Search"; + // + // txtbxOrderSearch + // + txtbxOrderSearch.Location = new Point(31, 46); + txtbxOrderSearch.Name = "txtbxOrderSearch"; + 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; + // + // Form1 + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1034, 557); + Controls.Add(tabControl1); + Name = "Form1"; + Text = "Form1"; + Load += Form1_Load; + tabControl1.ResumeLayout(false); + tabPage3.ResumeLayout(false); + tabPage3.PerformLayout(); + ResumeLayout(false); + } + + #endregion + + private TabControl tabControl1; + private TabPage tabPage1; + private TabPage tabPage2; + private TabPage tabPage3; + private TextBox txtbxOrderSearch; + private Label label1; + private DateTimePicker dtTmOrderSearch; + private ComboBox comboBox1; + } +} diff --git a/bnhtrade.gui/Form1.cs b/bnhtrade.gui/Form1.cs new file mode 100644 index 0000000..61818d0 --- /dev/null +++ b/bnhtrade.gui/Form1.cs @@ -0,0 +1,33 @@ +namespace bnhtrade.gui +{ + public partial class Form1 : Form + { + + bool loadedTabIndex1 = false; + + public Form1() + { + InitializeComponent(); + } + + private void Form1_Load(object sender, EventArgs e) + { + + } + + private void tabPage3_Click(object sender, EventArgs e) + { + + } + + private void tabControl1_SelectedIndexChanged(object sender, EventArgs e) + { + int index = (sender as TabControl).SelectedIndex; + + if (index == 1) + { + + } + } + } +} diff --git a/bnhtrade.gui/Form1.resx b/bnhtrade.gui/Form1.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/bnhtrade.gui/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/bnhtrade.gui/Program.cs b/bnhtrade.gui/Program.cs new file mode 100644 index 0000000..51d9543 --- /dev/null +++ b/bnhtrade.gui/Program.cs @@ -0,0 +1,17 @@ +namespace bnhtrade.gui +{ + internal static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + // To customize application configuration such as set high DPI settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + Application.Run(new Form1()); + } + } +} \ No newline at end of file diff --git a/bnhtrade.gui/bnhtrade.gui.csproj b/bnhtrade.gui/bnhtrade.gui.csproj new file mode 100644 index 0000000..663fdb8 --- /dev/null +++ b/bnhtrade.gui/bnhtrade.gui.csproj @@ -0,0 +1,11 @@ + + + + WinExe + net8.0-windows + enable + true + enable + + + \ No newline at end of file diff --git a/bnhtrade.sln b/bnhtrade.sln index 3031671..6a56ea9 100644 --- a/bnhtrade.sln +++ b/bnhtrade.sln @@ -13,6 +13,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "bnhtrade.ComTypeLib", "src\ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "lib", "lib", "{3D90C0F5-02E7-44E5-A89D-F5E217C6602F}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "bnhtrade.gui", "bnhtrade.gui\bnhtrade.gui.csproj", "{9FC75037-D13C-46F2-A3F4-5C13F0A8850E}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -31,6 +33,10 @@ Global {C3405E9D-B47A-4569-B6A3-BC9E7AA71EE5}.Debug|Any CPU.Build.0 = Debug|Any CPU {C3405E9D-B47A-4569-B6A3-BC9E7AA71EE5}.Release|Any CPU.ActiveCfg = Release|Any CPU {C3405E9D-B47A-4569-B6A3-BC9E7AA71EE5}.Release|Any CPU.Build.0 = Release|Any CPU + {9FC75037-D13C-46F2-A3F4-5C13F0A8850E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9FC75037-D13C-46F2-A3F4-5C13F0A8850E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9FC75037-D13C-46F2-A3F4-5C13F0A8850E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9FC75037-D13C-46F2-A3F4-5C13F0A8850E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/bnhtrade.Core/Data/Database/Purchase/PurchaseLineStatus.cs b/src/bnhtrade.Core/Data/Database/Purchase/PurchaseLineStatus.cs new file mode 100644 index 0000000..b58618d --- /dev/null +++ b/src/bnhtrade.Core/Data/Database/Purchase/PurchaseLineStatus.cs @@ -0,0 +1,54 @@ +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.Purchase +{ + internal class PurchaseLineStatus : Connection + { + public List Read() + { + var returnList = new List(); + + using (SqlConnection conn = new SqlConnection(SqlConnectionString)) + { + conn.Open(); + + using (SqlCommand cmd = new SqlCommand(@" + SELECT [PurchaseLineStatusID] + ,[PurchaseLineStatus] + ,[ListSort] + ,[TimeStamp] + FROM [e2A].[dbo].[tblPurchaseLineStatus] + ORDER BY [ListSort] + ", conn)) + { + + using (SqlDataReader reader = cmd.ExecuteReader()) + { + if (!reader.HasRows) + { + // do something + } + else + { + while (reader.Read()) + { + int id = reader.GetInt32(0); + string name = reader.GetString(1); + int lineSort = reader.GetInt32(2); + + var returnItem = new Model.Purchase.PurchaseLineStatus(id, name,lineSort); + returnList.Add( returnItem ); + } + } + } + } + } + return returnList; + } + } +} diff --git a/src/bnhtrade.Core/Logic/Purchase/PurchaseLineStatus.cs b/src/bnhtrade.Core/Logic/Purchase/PurchaseLineStatus.cs new file mode 100644 index 0000000..4ddccc1 --- /dev/null +++ b/src/bnhtrade.Core/Logic/Purchase/PurchaseLineStatus.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.Purchase +{ + public class PurchaseLineStatus + { + public List ReadAll() + { + return new Data.Database.Purchase.PurchaseLineStatus().Read(); + } + } +} diff --git a/src/bnhtrade.Core/Model/Purchase/PurchaseLineStatus.cs b/src/bnhtrade.Core/Model/Purchase/PurchaseLineStatus.cs new file mode 100644 index 0000000..f7bae9f --- /dev/null +++ b/src/bnhtrade.Core/Model/Purchase/PurchaseLineStatus.cs @@ -0,0 +1,18 @@ +namespace bnhtrade.Core.Model.Purchase +{ + public class PurchaseLineStatus + { + public PurchaseLineStatus(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;} + } +} diff --git a/src/bnhtrade.Core/bnhtrade.Core.csproj b/src/bnhtrade.Core/bnhtrade.Core.csproj index 506a48a..7e43728 100644 --- a/src/bnhtrade.Core/bnhtrade.Core.csproj +++ b/src/bnhtrade.Core/bnhtrade.Core.csproj @@ -177,6 +177,7 @@ + @@ -236,6 +237,7 @@ + @@ -294,6 +296,7 @@ + From 97fff18e7ee4472966e9ff591f1cd60731d368d9 Mon Sep 17 00:00:00 2001 From: Bobbie Hodgetts Date: Thu, 9 May 2024 21:27:51 +0100 Subject: [PATCH 02/15] wip --- bnhtrade.gui/Form1.Designer.cs | 14 +++ bnhtrade.gui/Form1.cs | 11 ++ bnhtrade.gui/Form1.resx | 3 + ...gic.Purchase.PurchaseLineStatus.datasource | 10 ++ ...del.Purchase.PurchaseLineStatus.datasource | 10 ++ bnhtrade.gui/Properties/Resources.Designer.cs | 63 +++++++++++ bnhtrade.gui/Properties/Resources.resx | 101 ++++++++++++++++++ bnhtrade.gui/bnhtrade.gui.csproj | 19 ++++ src/bnhtrade.ComTypeLib/app.config | 64 +++++++++++ src/bnhtrade.Core/App.config | 64 +++++++++++ .../Database/Account/CreateInvoiceLineItem.cs | 3 +- .../Data/Database/Account/ReadAccountCode.cs | 2 +- .../Database/Account/ReadInvoiceLineItem.cs | 2 +- .../Data/Database/Account/ReadTaxCode.cs | 2 +- .../Data/Database/Amazon/FeeEstimate.cs | 2 +- .../Database/AmazonFba/ReadShipmentInfo.cs | 2 +- .../AmazonFba/ReadShipmentPrimaryKey.cs | 2 +- .../Database/AmazonFba/SetShipmentInfo.cs | 2 +- src/bnhtrade.Core/Data/Database/Connection.cs | 2 +- .../Consistency/ImportAmazonSettlement.cs | 2 +- .../Export/CreateAmazonFeedSubmission.cs | 2 +- .../Database/Export/CreateSalesInvoice.cs | 2 +- .../Export/ReadAmazonFeedSubmission.cs | 2 +- .../Export/UpdateAmazonFeedSubmission.cs | 2 +- .../Import/AmazonFbaCustomerReturn.cs | 2 +- .../Import/AmazonFbaInventoryAdjustment.cs | 2 +- .../Import/AmazonFbaInventoryAgeData.cs | 2 +- .../Import/AmazonFbaInventoryAgeRead.cs | 2 +- .../Database/Import/AmazonFbaInventoryData.cs | 2 +- .../Import/AmazonFbaInventoryLedgerDetail.cs | 2 +- .../Import/AmazonFbaInventoryReceipt.cs | 2 +- .../Database/Import/AmazonFbaReimbursement.cs | 2 +- .../Database/Import/AmazonFbaRemovalOrder.cs | 2 +- .../Database/Import/AmazonFbaSaleShipment.cs | 2 +- .../Import/AmazonSettlementHeaderRead.cs | 2 +- .../Database/Import/AmazonSettlementInsert.cs | 2 +- .../Database/Import/AmazonSettlementRead.cs | 2 +- .../Database/Import/AmazonSettlementUpdate.cs | 2 +- .../Data/Database/Log/DateTimeLog.cs | 2 +- .../Data/Database/Log/LogEvent.cs | 2 +- .../Product/CreateCompetitivePrice.cs | 2 +- .../Database/Product/ReadCompetitivePrice.cs | 2 +- .../Data/Database/Product/ReadProduct.cs | 2 +- .../Data/Database/Product/ReadProductId.cs | 2 +- .../Data/Database/Programmability/Sequence.cs | 2 +- .../Database/Purchase/PurchaseLineStatus.cs | 4 +- .../Data/Database/ReadRandomData.cs | 2 +- .../Data/Database/SKU/GetSKUId.cs | 2 +- .../Data/Database/SKU/InsertSku.cs | 2 +- .../Database/SKU/Price/CreatePricingDetail.cs | 2 +- .../Data/Database/SKU/Price/ReadParameter.cs | 2 +- .../Database/SKU/Price/ReadPricingDetail.cs | 2 +- .../Data/Database/SKU/ReadSku.cs | 2 +- .../Data/Database/SKU/ReadSkuConditionInfo.cs | 2 +- .../Data/Database/SqlWhereBuilder.cs | 2 +- .../Database/Stock/DeleteSkuTransaction.cs | 2 +- .../Database/Stock/InsertSkuTransaction.cs | 2 +- .../Stock/InsertSkuTransactionType.cs | 2 +- .../Data/Database/Stock/JournalCrud.cs | 2 +- .../Data/Database/Stock/ReadSkuTransaction.cs | 2 +- .../Database/Stock/ReadSkuTransactionType.cs | 2 +- .../Data/Database/Stock/ReadStatusBalance.cs | 2 +- .../Database/Stock/ReadStatusTransaction.cs | 2 +- .../Database/Stock/ReadStatusTypeBalance.cs | 2 +- .../Data/Database/Stock/ReadStockId.cs | 2 +- .../Data/Database/Stock/Status.cs | 2 +- .../Data/Database/Stock/StatusType.cs | 2 +- .../Database/Stock/UpdateSkuTransaction.cs | 2 +- .../Logic/Export/AmazonSettlement.cs | 2 +- src/bnhtrade.Core/Logic/Sku/GetSkuId.cs | 2 +- .../Logic/Sku/Price/FbaPricing.cs | 2 +- .../Logic/Sku/Price/UpdateRepricingValues.cs | 2 +- .../Logic/Stock/SkuTransactionCrud.cs | 2 +- .../Logic/Stock/SkuTransactionImport.cs | 2 +- .../Logic/Stock/SkuTransactionTypeCrud.cs | 2 +- .../Model/Purchase/PurchaseLineStatus.cs | 8 +- src/bnhtrade.Core/Program.cs | 2 +- src/bnhtrade.Core/Test/SQLLoop.cs | 2 +- src/bnhtrade.Core/Test/_BoilerPlate/Sql.cs | 2 +- src/bnhtrade.Core/bnhtrade.Core.csproj | 79 ++++++++++++++ src/bnhtrade.Core/packages.config | 24 +++++ src/bnhtrade.ScheduledTasks/App.config | 64 +++++++++++ 82 files changed, 603 insertions(+), 70 deletions(-) create mode 100644 bnhtrade.gui/Properties/DataSources/bnhtrade.Core.Logic.Purchase.PurchaseLineStatus.datasource create mode 100644 bnhtrade.gui/Properties/DataSources/bnhtrade.Core.Model.Purchase.PurchaseLineStatus.datasource create mode 100644 bnhtrade.gui/Properties/Resources.Designer.cs create mode 100644 bnhtrade.gui/Properties/Resources.resx diff --git a/bnhtrade.gui/Form1.Designer.cs b/bnhtrade.gui/Form1.Designer.cs index 843036f..2ba8c6c 100644 --- a/bnhtrade.gui/Form1.Designer.cs +++ b/bnhtrade.gui/Form1.Designer.cs @@ -28,6 +28,7 @@ /// private void InitializeComponent() { + components = new System.ComponentModel.Container(); tabControl1 = new TabControl(); tabPage1 = new TabPage(); tabPage3 = new TabPage(); @@ -36,8 +37,10 @@ label1 = new Label(); txtbxOrderSearch = new TextBox(); tabPage2 = new TabPage(); + purchaseLineStatusBindingSource = new BindingSource(components); tabControl1.SuspendLayout(); tabPage3.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)purchaseLineStatusBindingSource).BeginInit(); SuspendLayout(); // // tabControl1 @@ -80,11 +83,15 @@ // // comboBox1 // + comboBox1.DataSource = purchaseLineStatusBindingSource; + comboBox1.DisplayMember = "PurchaseLineStatusName"; comboBox1.FormattingEnabled = true; comboBox1.Location = new Point(580, 46); comboBox1.Name = "comboBox1"; comboBox1.Size = new Size(214, 23); comboBox1.TabIndex = 3; + comboBox1.ValueMember = "PurchaseLineStatusId"; + comboBox1.SelectedIndexChanged += comboBox1_SelectedIndexChanged; // // dtTmOrderSearch // @@ -120,6 +127,11 @@ 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); @@ -132,6 +144,7 @@ tabControl1.ResumeLayout(false); tabPage3.ResumeLayout(false); tabPage3.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)purchaseLineStatusBindingSource).EndInit(); ResumeLayout(false); } @@ -145,5 +158,6 @@ private Label label1; private DateTimePicker dtTmOrderSearch; private ComboBox comboBox1; + private BindingSource purchaseLineStatusBindingSource; } } diff --git a/bnhtrade.gui/Form1.cs b/bnhtrade.gui/Form1.cs index 61818d0..578eaf2 100644 --- a/bnhtrade.gui/Form1.cs +++ b/bnhtrade.gui/Form1.cs @@ -8,6 +8,7 @@ namespace bnhtrade.gui public Form1() { InitializeComponent(); + purchaseLineStatusBindingSource.DataSource = new Core.Logic.Purchase.PurchaseLineStatus().ReadAll(); } private void Form1_Load(object sender, EventArgs e) @@ -29,5 +30,15 @@ namespace bnhtrade.gui } } + + private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) + { + + } + + private void purchaseLineStatusBindingSource_CurrentChanged(object sender, EventArgs e) + { + + } } } diff --git a/bnhtrade.gui/Form1.resx b/bnhtrade.gui/Form1.resx index af32865..fbfcf25 100644 --- a/bnhtrade.gui/Form1.resx +++ b/bnhtrade.gui/Form1.resx @@ -117,4 +117,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + \ No newline at end of file diff --git a/bnhtrade.gui/Properties/DataSources/bnhtrade.Core.Logic.Purchase.PurchaseLineStatus.datasource b/bnhtrade.gui/Properties/DataSources/bnhtrade.Core.Logic.Purchase.PurchaseLineStatus.datasource new file mode 100644 index 0000000..c951b2f --- /dev/null +++ b/bnhtrade.gui/Properties/DataSources/bnhtrade.Core.Logic.Purchase.PurchaseLineStatus.datasource @@ -0,0 +1,10 @@ + + + + bnhtrade.Core.Logic.Purchase.PurchaseLineStatus, bnhtrade.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + \ No newline at end of file diff --git a/bnhtrade.gui/Properties/DataSources/bnhtrade.Core.Model.Purchase.PurchaseLineStatus.datasource b/bnhtrade.gui/Properties/DataSources/bnhtrade.Core.Model.Purchase.PurchaseLineStatus.datasource new file mode 100644 index 0000000..c289362 --- /dev/null +++ b/bnhtrade.gui/Properties/DataSources/bnhtrade.Core.Model.Purchase.PurchaseLineStatus.datasource @@ -0,0 +1,10 @@ + + + + bnhtrade.Core.Model.Purchase.PurchaseLineStatus, bnhtrade.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + \ No newline at end of file diff --git a/bnhtrade.gui/Properties/Resources.Designer.cs b/bnhtrade.gui/Properties/Resources.Designer.cs new file mode 100644 index 0000000..93c0772 --- /dev/null +++ b/bnhtrade.gui/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace bnhtrade.gui.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("bnhtrade.gui.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/bnhtrade.gui/Properties/Resources.resx b/bnhtrade.gui/Properties/Resources.resx new file mode 100644 index 0000000..4fdb1b6 --- /dev/null +++ b/bnhtrade.gui/Properties/Resources.resx @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/bnhtrade.gui/bnhtrade.gui.csproj b/bnhtrade.gui/bnhtrade.gui.csproj index 663fdb8..c896b8a 100644 --- a/bnhtrade.gui/bnhtrade.gui.csproj +++ b/bnhtrade.gui/bnhtrade.gui.csproj @@ -8,4 +8,23 @@ enable + + + + + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + \ No newline at end of file diff --git a/src/bnhtrade.ComTypeLib/app.config b/src/bnhtrade.ComTypeLib/app.config index 258fe8a..5d28cbc 100644 --- a/src/bnhtrade.ComTypeLib/app.config +++ b/src/bnhtrade.ComTypeLib/app.config @@ -34,6 +34,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/bnhtrade.Core/App.config b/src/bnhtrade.Core/App.config index d276c2b..7160e97 100644 --- a/src/bnhtrade.Core/App.config +++ b/src/bnhtrade.Core/App.config @@ -42,6 +42,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/bnhtrade.Core/Data/Database/Account/CreateInvoiceLineItem.cs b/src/bnhtrade.Core/Data/Database/Account/CreateInvoiceLineItem.cs index 455d39c..efd8b90 100644 --- a/src/bnhtrade.Core/Data/Database/Account/CreateInvoiceLineItem.cs +++ b/src/bnhtrade.Core/Data/Database/Account/CreateInvoiceLineItem.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; -using System.Data.SqlClient; +//using Microsoft.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/src/bnhtrade.Core/Data/Database/Account/ReadAccountCode.cs b/src/bnhtrade.Core/Data/Database/Account/ReadAccountCode.cs index 814d552..efcac16 100644 --- a/src/bnhtrade.Core/Data/Database/Account/ReadAccountCode.cs +++ b/src/bnhtrade.Core/Data/Database/Account/ReadAccountCode.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/src/bnhtrade.Core/Data/Database/Account/ReadInvoiceLineItem.cs b/src/bnhtrade.Core/Data/Database/Account/ReadInvoiceLineItem.cs index 07482f0..612ef3c 100644 --- a/src/bnhtrade.Core/Data/Database/Account/ReadInvoiceLineItem.cs +++ b/src/bnhtrade.Core/Data/Database/Account/ReadInvoiceLineItem.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/src/bnhtrade.Core/Data/Database/Account/ReadTaxCode.cs b/src/bnhtrade.Core/Data/Database/Account/ReadTaxCode.cs index dd285c2..0991fbf 100644 --- a/src/bnhtrade.Core/Data/Database/Account/ReadTaxCode.cs +++ b/src/bnhtrade.Core/Data/Database/Account/ReadTaxCode.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/src/bnhtrade.Core/Data/Database/Amazon/FeeEstimate.cs b/src/bnhtrade.Core/Data/Database/Amazon/FeeEstimate.cs index 64331c7..d7b30d9 100644 --- a/src/bnhtrade.Core/Data/Database/Amazon/FeeEstimate.cs +++ b/src/bnhtrade.Core/Data/Database/Amazon/FeeEstimate.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/src/bnhtrade.Core/Data/Database/AmazonFba/ReadShipmentInfo.cs b/src/bnhtrade.Core/Data/Database/AmazonFba/ReadShipmentInfo.cs index 718ae05..25709c5 100644 --- a/src/bnhtrade.Core/Data/Database/AmazonFba/ReadShipmentInfo.cs +++ b/src/bnhtrade.Core/Data/Database/AmazonFba/ReadShipmentInfo.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/src/bnhtrade.Core/Data/Database/AmazonFba/ReadShipmentPrimaryKey.cs b/src/bnhtrade.Core/Data/Database/AmazonFba/ReadShipmentPrimaryKey.cs index 166267a..167e01a 100644 --- a/src/bnhtrade.Core/Data/Database/AmazonFba/ReadShipmentPrimaryKey.cs +++ b/src/bnhtrade.Core/Data/Database/AmazonFba/ReadShipmentPrimaryKey.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/src/bnhtrade.Core/Data/Database/AmazonFba/SetShipmentInfo.cs b/src/bnhtrade.Core/Data/Database/AmazonFba/SetShipmentInfo.cs index 9cefbff..c0b5aaf 100644 --- a/src/bnhtrade.Core/Data/Database/AmazonFba/SetShipmentInfo.cs +++ b/src/bnhtrade.Core/Data/Database/AmazonFba/SetShipmentInfo.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/src/bnhtrade.Core/Data/Database/Connection.cs b/src/bnhtrade.Core/Data/Database/Connection.cs index 53f29d9..eb5c8d4 100644 --- a/src/bnhtrade.Core/Data/Database/Connection.cs +++ b/src/bnhtrade.Core/Data/Database/Connection.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Configuration; namespace bnhtrade.Core.Data.Database diff --git a/src/bnhtrade.Core/Data/Database/Consistency/ImportAmazonSettlement.cs b/src/bnhtrade.Core/Data/Database/Consistency/ImportAmazonSettlement.cs index ece367b..0389d31 100644 --- a/src/bnhtrade.Core/Data/Database/Consistency/ImportAmazonSettlement.cs +++ b/src/bnhtrade.Core/Data/Database/Consistency/ImportAmazonSettlement.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/src/bnhtrade.Core/Data/Database/Export/CreateAmazonFeedSubmission.cs b/src/bnhtrade.Core/Data/Database/Export/CreateAmazonFeedSubmission.cs index 4145fb3..483ec83 100644 --- a/src/bnhtrade.Core/Data/Database/Export/CreateAmazonFeedSubmission.cs +++ b/src/bnhtrade.Core/Data/Database/Export/CreateAmazonFeedSubmission.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.IO; using System.Linq; using System.Text; diff --git a/src/bnhtrade.Core/Data/Database/Export/CreateSalesInvoice.cs b/src/bnhtrade.Core/Data/Database/Export/CreateSalesInvoice.cs index 1714f09..582e1ee 100644 --- a/src/bnhtrade.Core/Data/Database/Export/CreateSalesInvoice.cs +++ b/src/bnhtrade.Core/Data/Database/Export/CreateSalesInvoice.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/src/bnhtrade.Core/Data/Database/Export/ReadAmazonFeedSubmission.cs b/src/bnhtrade.Core/Data/Database/Export/ReadAmazonFeedSubmission.cs index d5768bf..611a053 100644 --- a/src/bnhtrade.Core/Data/Database/Export/ReadAmazonFeedSubmission.cs +++ b/src/bnhtrade.Core/Data/Database/Export/ReadAmazonFeedSubmission.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/src/bnhtrade.Core/Data/Database/Export/UpdateAmazonFeedSubmission.cs b/src/bnhtrade.Core/Data/Database/Export/UpdateAmazonFeedSubmission.cs index acd001e..b44f766 100644 --- a/src/bnhtrade.Core/Data/Database/Export/UpdateAmazonFeedSubmission.cs +++ b/src/bnhtrade.Core/Data/Database/Export/UpdateAmazonFeedSubmission.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/src/bnhtrade.Core/Data/Database/Import/AmazonFbaCustomerReturn.cs b/src/bnhtrade.Core/Data/Database/Import/AmazonFbaCustomerReturn.cs index c58c5f1..4d37221 100644 --- a/src/bnhtrade.Core/Data/Database/Import/AmazonFbaCustomerReturn.cs +++ b/src/bnhtrade.Core/Data/Database/Import/AmazonFbaCustomerReturn.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.IO; using System.Linq; using System.Text; diff --git a/src/bnhtrade.Core/Data/Database/Import/AmazonFbaInventoryAdjustment.cs b/src/bnhtrade.Core/Data/Database/Import/AmazonFbaInventoryAdjustment.cs index a0d7ef6..b85a82c 100644 --- a/src/bnhtrade.Core/Data/Database/Import/AmazonFbaInventoryAdjustment.cs +++ b/src/bnhtrade.Core/Data/Database/Import/AmazonFbaInventoryAdjustment.cs @@ -1,5 +1,5 @@ using System; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.IO; namespace bnhtrade.Core.Data.Database.Import diff --git a/src/bnhtrade.Core/Data/Database/Import/AmazonFbaInventoryAgeData.cs b/src/bnhtrade.Core/Data/Database/Import/AmazonFbaInventoryAgeData.cs index 5cd5284..6eb13ef 100644 --- a/src/bnhtrade.Core/Data/Database/Import/AmazonFbaInventoryAgeData.cs +++ b/src/bnhtrade.Core/Data/Database/Import/AmazonFbaInventoryAgeData.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.IO; using System.Linq; using System.Text; diff --git a/src/bnhtrade.Core/Data/Database/Import/AmazonFbaInventoryAgeRead.cs b/src/bnhtrade.Core/Data/Database/Import/AmazonFbaInventoryAgeRead.cs index 4efb77b..34d07fc 100644 --- a/src/bnhtrade.Core/Data/Database/Import/AmazonFbaInventoryAgeRead.cs +++ b/src/bnhtrade.Core/Data/Database/Import/AmazonFbaInventoryAgeRead.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/src/bnhtrade.Core/Data/Database/Import/AmazonFbaInventoryData.cs b/src/bnhtrade.Core/Data/Database/Import/AmazonFbaInventoryData.cs index cc9bd19..04f6ffa 100644 --- a/src/bnhtrade.Core/Data/Database/Import/AmazonFbaInventoryData.cs +++ b/src/bnhtrade.Core/Data/Database/Import/AmazonFbaInventoryData.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.IO; using System.Linq; using System.Text; diff --git a/src/bnhtrade.Core/Data/Database/Import/AmazonFbaInventoryLedgerDetail.cs b/src/bnhtrade.Core/Data/Database/Import/AmazonFbaInventoryLedgerDetail.cs index 88f1464..0815e28 100644 --- a/src/bnhtrade.Core/Data/Database/Import/AmazonFbaInventoryLedgerDetail.cs +++ b/src/bnhtrade.Core/Data/Database/Import/AmazonFbaInventoryLedgerDetail.cs @@ -2,7 +2,7 @@ using bnhtrade.Core.Logic.Amazon.Fba; using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Diagnostics; using System.Diagnostics.Eventing.Reader; using System.IO; diff --git a/src/bnhtrade.Core/Data/Database/Import/AmazonFbaInventoryReceipt.cs b/src/bnhtrade.Core/Data/Database/Import/AmazonFbaInventoryReceipt.cs index 2216877..f991ef5 100644 --- a/src/bnhtrade.Core/Data/Database/Import/AmazonFbaInventoryReceipt.cs +++ b/src/bnhtrade.Core/Data/Database/Import/AmazonFbaInventoryReceipt.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Globalization; using System.IO; using System.Linq; diff --git a/src/bnhtrade.Core/Data/Database/Import/AmazonFbaReimbursement.cs b/src/bnhtrade.Core/Data/Database/Import/AmazonFbaReimbursement.cs index 4b732d2..714fcc4 100644 --- a/src/bnhtrade.Core/Data/Database/Import/AmazonFbaReimbursement.cs +++ b/src/bnhtrade.Core/Data/Database/Import/AmazonFbaReimbursement.cs @@ -4,7 +4,7 @@ using NUnit.Framework.Constraints; using System; using System.Collections.Generic; using System.Data; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.IO; using System.Linq; using System.Runtime.ConstrainedExecution; diff --git a/src/bnhtrade.Core/Data/Database/Import/AmazonFbaRemovalOrder.cs b/src/bnhtrade.Core/Data/Database/Import/AmazonFbaRemovalOrder.cs index a7ffdf4..ba4f69b 100644 --- a/src/bnhtrade.Core/Data/Database/Import/AmazonFbaRemovalOrder.cs +++ b/src/bnhtrade.Core/Data/Database/Import/AmazonFbaRemovalOrder.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.IO; using System.Linq; using System.Text; diff --git a/src/bnhtrade.Core/Data/Database/Import/AmazonFbaSaleShipment.cs b/src/bnhtrade.Core/Data/Database/Import/AmazonFbaSaleShipment.cs index 5397d2e..51443b4 100644 --- a/src/bnhtrade.Core/Data/Database/Import/AmazonFbaSaleShipment.cs +++ b/src/bnhtrade.Core/Data/Database/Import/AmazonFbaSaleShipment.cs @@ -1,7 +1,7 @@ using Dapper; using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.IO; using System.Linq; using System.Text; diff --git a/src/bnhtrade.Core/Data/Database/Import/AmazonSettlementHeaderRead.cs b/src/bnhtrade.Core/Data/Database/Import/AmazonSettlementHeaderRead.cs index 02f1f23..35c29a2 100644 --- a/src/bnhtrade.Core/Data/Database/Import/AmazonSettlementHeaderRead.cs +++ b/src/bnhtrade.Core/Data/Database/Import/AmazonSettlementHeaderRead.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; namespace bnhtrade.Core.Data.Database.Import { diff --git a/src/bnhtrade.Core/Data/Database/Import/AmazonSettlementInsert.cs b/src/bnhtrade.Core/Data/Database/Import/AmazonSettlementInsert.cs index 4719cb9..8a7bec5 100644 --- a/src/bnhtrade.Core/Data/Database/Import/AmazonSettlementInsert.cs +++ b/src/bnhtrade.Core/Data/Database/Import/AmazonSettlementInsert.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.IO; using System.Linq; using System.Text; diff --git a/src/bnhtrade.Core/Data/Database/Import/AmazonSettlementRead.cs b/src/bnhtrade.Core/Data/Database/Import/AmazonSettlementRead.cs index 4e46a34..5d31d13 100644 --- a/src/bnhtrade.Core/Data/Database/Import/AmazonSettlementRead.cs +++ b/src/bnhtrade.Core/Data/Database/Import/AmazonSettlementRead.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; namespace bnhtrade.Core.Data.Database.Import { diff --git a/src/bnhtrade.Core/Data/Database/Import/AmazonSettlementUpdate.cs b/src/bnhtrade.Core/Data/Database/Import/AmazonSettlementUpdate.cs index 41a4c7b..8169d8f 100644 --- a/src/bnhtrade.Core/Data/Database/Import/AmazonSettlementUpdate.cs +++ b/src/bnhtrade.Core/Data/Database/Import/AmazonSettlementUpdate.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/src/bnhtrade.Core/Data/Database/Log/DateTimeLog.cs b/src/bnhtrade.Core/Data/Database/Log/DateTimeLog.cs index a367350..b32832d 100644 --- a/src/bnhtrade.Core/Data/Database/Log/DateTimeLog.cs +++ b/src/bnhtrade.Core/Data/Database/Log/DateTimeLog.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/src/bnhtrade.Core/Data/Database/Log/LogEvent.cs b/src/bnhtrade.Core/Data/Database/Log/LogEvent.cs index b3cc8f0..e074f90 100644 --- a/src/bnhtrade.Core/Data/Database/Log/LogEvent.cs +++ b/src/bnhtrade.Core/Data/Database/Log/LogEvent.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/src/bnhtrade.Core/Data/Database/Product/CreateCompetitivePrice.cs b/src/bnhtrade.Core/Data/Database/Product/CreateCompetitivePrice.cs index df84a34..ad1823f 100644 --- a/src/bnhtrade.Core/Data/Database/Product/CreateCompetitivePrice.cs +++ b/src/bnhtrade.Core/Data/Database/Product/CreateCompetitivePrice.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/src/bnhtrade.Core/Data/Database/Product/ReadCompetitivePrice.cs b/src/bnhtrade.Core/Data/Database/Product/ReadCompetitivePrice.cs index ef8a2aa..d68132f 100644 --- a/src/bnhtrade.Core/Data/Database/Product/ReadCompetitivePrice.cs +++ b/src/bnhtrade.Core/Data/Database/Product/ReadCompetitivePrice.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/src/bnhtrade.Core/Data/Database/Product/ReadProduct.cs b/src/bnhtrade.Core/Data/Database/Product/ReadProduct.cs index ad436bc..f55de04 100644 --- a/src/bnhtrade.Core/Data/Database/Product/ReadProduct.cs +++ b/src/bnhtrade.Core/Data/Database/Product/ReadProduct.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/src/bnhtrade.Core/Data/Database/Product/ReadProductId.cs b/src/bnhtrade.Core/Data/Database/Product/ReadProductId.cs index 21b561c..45c9cda 100644 --- a/src/bnhtrade.Core/Data/Database/Product/ReadProductId.cs +++ b/src/bnhtrade.Core/Data/Database/Product/ReadProductId.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/src/bnhtrade.Core/Data/Database/Programmability/Sequence.cs b/src/bnhtrade.Core/Data/Database/Programmability/Sequence.cs index 58045a9..434a89a 100644 --- a/src/bnhtrade.Core/Data/Database/Programmability/Sequence.cs +++ b/src/bnhtrade.Core/Data/Database/Programmability/Sequence.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/src/bnhtrade.Core/Data/Database/Purchase/PurchaseLineStatus.cs b/src/bnhtrade.Core/Data/Database/Purchase/PurchaseLineStatus.cs index b58618d..7aa4ecf 100644 --- a/src/bnhtrade.Core/Data/Database/Purchase/PurchaseLineStatus.cs +++ b/src/bnhtrade.Core/Data/Database/Purchase/PurchaseLineStatus.cs @@ -1,13 +1,13 @@ using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; namespace bnhtrade.Core.Data.Database.Purchase { - internal class PurchaseLineStatus : Connection + public class PurchaseLineStatus : Connection { public List Read() { diff --git a/src/bnhtrade.Core/Data/Database/ReadRandomData.cs b/src/bnhtrade.Core/Data/Database/ReadRandomData.cs index 38a5c90..9fac6e6 100644 --- a/src/bnhtrade.Core/Data/Database/ReadRandomData.cs +++ b/src/bnhtrade.Core/Data/Database/ReadRandomData.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/src/bnhtrade.Core/Data/Database/SKU/GetSKUId.cs b/src/bnhtrade.Core/Data/Database/SKU/GetSKUId.cs index d397527..0738acb 100644 --- a/src/bnhtrade.Core/Data/Database/SKU/GetSKUId.cs +++ b/src/bnhtrade.Core/Data/Database/SKU/GetSKUId.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; namespace bnhtrade.Core.Data.Database.Sku { diff --git a/src/bnhtrade.Core/Data/Database/SKU/InsertSku.cs b/src/bnhtrade.Core/Data/Database/SKU/InsertSku.cs index 7af1d05..6e5664a 100644 --- a/src/bnhtrade.Core/Data/Database/SKU/InsertSku.cs +++ b/src/bnhtrade.Core/Data/Database/SKU/InsertSku.cs @@ -1,7 +1,7 @@ using FikaAmazonAPI.AmazonSpApiSDK.Models.ProductPricing; using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/src/bnhtrade.Core/Data/Database/SKU/Price/CreatePricingDetail.cs b/src/bnhtrade.Core/Data/Database/SKU/Price/CreatePricingDetail.cs index 06d0e6e..106ef82 100644 --- a/src/bnhtrade.Core/Data/Database/SKU/Price/CreatePricingDetail.cs +++ b/src/bnhtrade.Core/Data/Database/SKU/Price/CreatePricingDetail.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Transactions; namespace bnhtrade.Core.Data.Database.Sku.Price diff --git a/src/bnhtrade.Core/Data/Database/SKU/Price/ReadParameter.cs b/src/bnhtrade.Core/Data/Database/SKU/Price/ReadParameter.cs index 4b5d028..7839832 100644 --- a/src/bnhtrade.Core/Data/Database/SKU/Price/ReadParameter.cs +++ b/src/bnhtrade.Core/Data/Database/SKU/Price/ReadParameter.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/src/bnhtrade.Core/Data/Database/SKU/Price/ReadPricingDetail.cs b/src/bnhtrade.Core/Data/Database/SKU/Price/ReadPricingDetail.cs index dd03317..16f64e1 100644 --- a/src/bnhtrade.Core/Data/Database/SKU/Price/ReadPricingDetail.cs +++ b/src/bnhtrade.Core/Data/Database/SKU/Price/ReadPricingDetail.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/src/bnhtrade.Core/Data/Database/SKU/ReadSku.cs b/src/bnhtrade.Core/Data/Database/SKU/ReadSku.cs index c800dab..bd3f43b 100644 --- a/src/bnhtrade.Core/Data/Database/SKU/ReadSku.cs +++ b/src/bnhtrade.Core/Data/Database/SKU/ReadSku.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/src/bnhtrade.Core/Data/Database/SKU/ReadSkuConditionInfo.cs b/src/bnhtrade.Core/Data/Database/SKU/ReadSkuConditionInfo.cs index cd0edc9..f1fe400 100644 --- a/src/bnhtrade.Core/Data/Database/SKU/ReadSkuConditionInfo.cs +++ b/src/bnhtrade.Core/Data/Database/SKU/ReadSkuConditionInfo.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/src/bnhtrade.Core/Data/Database/SqlWhereBuilder.cs b/src/bnhtrade.Core/Data/Database/SqlWhereBuilder.cs index 48009fb..d21e0d7 100644 --- a/src/bnhtrade.Core/Data/Database/SqlWhereBuilder.cs +++ b/src/bnhtrade.Core/Data/Database/SqlWhereBuilder.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/src/bnhtrade.Core/Data/Database/Stock/DeleteSkuTransaction.cs b/src/bnhtrade.Core/Data/Database/Stock/DeleteSkuTransaction.cs index b6d320d..0b87dbd 100644 --- a/src/bnhtrade.Core/Data/Database/Stock/DeleteSkuTransaction.cs +++ b/src/bnhtrade.Core/Data/Database/Stock/DeleteSkuTransaction.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/src/bnhtrade.Core/Data/Database/Stock/InsertSkuTransaction.cs b/src/bnhtrade.Core/Data/Database/Stock/InsertSkuTransaction.cs index c3e9023..781d8ff 100644 --- a/src/bnhtrade.Core/Data/Database/Stock/InsertSkuTransaction.cs +++ b/src/bnhtrade.Core/Data/Database/Stock/InsertSkuTransaction.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/src/bnhtrade.Core/Data/Database/Stock/InsertSkuTransactionType.cs b/src/bnhtrade.Core/Data/Database/Stock/InsertSkuTransactionType.cs index 83d483d..f80c831 100644 --- a/src/bnhtrade.Core/Data/Database/Stock/InsertSkuTransactionType.cs +++ b/src/bnhtrade.Core/Data/Database/Stock/InsertSkuTransactionType.cs @@ -1,5 +1,5 @@ using System; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Transactions; namespace bnhtrade.Core.Data.Database.Stock diff --git a/src/bnhtrade.Core/Data/Database/Stock/JournalCrud.cs b/src/bnhtrade.Core/Data/Database/Stock/JournalCrud.cs index 65b0dfe..06785a7 100644 --- a/src/bnhtrade.Core/Data/Database/Stock/JournalCrud.cs +++ b/src/bnhtrade.Core/Data/Database/Stock/JournalCrud.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/src/bnhtrade.Core/Data/Database/Stock/ReadSkuTransaction.cs b/src/bnhtrade.Core/Data/Database/Stock/ReadSkuTransaction.cs index 39a2a22..75f0563 100644 --- a/src/bnhtrade.Core/Data/Database/Stock/ReadSkuTransaction.cs +++ b/src/bnhtrade.Core/Data/Database/Stock/ReadSkuTransaction.cs @@ -1,7 +1,7 @@ using NUnit.Framework.Internal; using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/src/bnhtrade.Core/Data/Database/Stock/ReadSkuTransactionType.cs b/src/bnhtrade.Core/Data/Database/Stock/ReadSkuTransactionType.cs index 8f4cedd..c792717 100644 --- a/src/bnhtrade.Core/Data/Database/Stock/ReadSkuTransactionType.cs +++ b/src/bnhtrade.Core/Data/Database/Stock/ReadSkuTransactionType.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/src/bnhtrade.Core/Data/Database/Stock/ReadStatusBalance.cs b/src/bnhtrade.Core/Data/Database/Stock/ReadStatusBalance.cs index 93ae836..e65ab1c 100644 --- a/src/bnhtrade.Core/Data/Database/Stock/ReadStatusBalance.cs +++ b/src/bnhtrade.Core/Data/Database/Stock/ReadStatusBalance.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/src/bnhtrade.Core/Data/Database/Stock/ReadStatusTransaction.cs b/src/bnhtrade.Core/Data/Database/Stock/ReadStatusTransaction.cs index b078322..3bec5de 100644 --- a/src/bnhtrade.Core/Data/Database/Stock/ReadStatusTransaction.cs +++ b/src/bnhtrade.Core/Data/Database/Stock/ReadStatusTransaction.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/src/bnhtrade.Core/Data/Database/Stock/ReadStatusTypeBalance.cs b/src/bnhtrade.Core/Data/Database/Stock/ReadStatusTypeBalance.cs index 69c9463..6789bd9 100644 --- a/src/bnhtrade.Core/Data/Database/Stock/ReadStatusTypeBalance.cs +++ b/src/bnhtrade.Core/Data/Database/Stock/ReadStatusTypeBalance.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/src/bnhtrade.Core/Data/Database/Stock/ReadStockId.cs b/src/bnhtrade.Core/Data/Database/Stock/ReadStockId.cs index a17e60f..0854aa2 100644 --- a/src/bnhtrade.Core/Data/Database/Stock/ReadStockId.cs +++ b/src/bnhtrade.Core/Data/Database/Stock/ReadStockId.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/src/bnhtrade.Core/Data/Database/Stock/Status.cs b/src/bnhtrade.Core/Data/Database/Stock/Status.cs index 77243ce..54325e7 100644 --- a/src/bnhtrade.Core/Data/Database/Stock/Status.cs +++ b/src/bnhtrade.Core/Data/Database/Stock/Status.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/src/bnhtrade.Core/Data/Database/Stock/StatusType.cs b/src/bnhtrade.Core/Data/Database/Stock/StatusType.cs index 1b394e1..23e89a3 100644 --- a/src/bnhtrade.Core/Data/Database/Stock/StatusType.cs +++ b/src/bnhtrade.Core/Data/Database/Stock/StatusType.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/src/bnhtrade.Core/Data/Database/Stock/UpdateSkuTransaction.cs b/src/bnhtrade.Core/Data/Database/Stock/UpdateSkuTransaction.cs index 09f835a..06d765d 100644 --- a/src/bnhtrade.Core/Data/Database/Stock/UpdateSkuTransaction.cs +++ b/src/bnhtrade.Core/Data/Database/Stock/UpdateSkuTransaction.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/src/bnhtrade.Core/Logic/Export/AmazonSettlement.cs b/src/bnhtrade.Core/Logic/Export/AmazonSettlement.cs index 9f4db85..21cc170 100644 --- a/src/bnhtrade.Core/Logic/Export/AmazonSettlement.cs +++ b/src/bnhtrade.Core/Logic/Export/AmazonSettlement.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/src/bnhtrade.Core/Logic/Sku/GetSkuId.cs b/src/bnhtrade.Core/Logic/Sku/GetSkuId.cs index 9224dd0..af717f6 100644 --- a/src/bnhtrade.Core/Logic/Sku/GetSkuId.cs +++ b/src/bnhtrade.Core/Logic/Sku/GetSkuId.cs @@ -1,5 +1,5 @@ using System; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Transactions; namespace bnhtrade.Core.Logic.Sku diff --git a/src/bnhtrade.Core/Logic/Sku/Price/FbaPricing.cs b/src/bnhtrade.Core/Logic/Sku/Price/FbaPricing.cs index 18e25ec..c131872 100644 --- a/src/bnhtrade.Core/Logic/Sku/Price/FbaPricing.cs +++ b/src/bnhtrade.Core/Logic/Sku/Price/FbaPricing.cs @@ -1,7 +1,7 @@ using CsvHelper; using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Globalization; using System.IO; using System.Linq; diff --git a/src/bnhtrade.Core/Logic/Sku/Price/UpdateRepricingValues.cs b/src/bnhtrade.Core/Logic/Sku/Price/UpdateRepricingValues.cs index 5ea3010..6f63b2e 100644 --- a/src/bnhtrade.Core/Logic/Sku/Price/UpdateRepricingValues.cs +++ b/src/bnhtrade.Core/Logic/Sku/Price/UpdateRepricingValues.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Transactions; namespace bnhtrade.Core.Logic.Sku.Price diff --git a/src/bnhtrade.Core/Logic/Stock/SkuTransactionCrud.cs b/src/bnhtrade.Core/Logic/Stock/SkuTransactionCrud.cs index 1bf36d8..d727132 100644 --- a/src/bnhtrade.Core/Logic/Stock/SkuTransactionCrud.cs +++ b/src/bnhtrade.Core/Logic/Stock/SkuTransactionCrud.cs @@ -1,7 +1,7 @@ using bnhtrade.Core.Data.Database; using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Linq; using System.Text; using System.Threading; diff --git a/src/bnhtrade.Core/Logic/Stock/SkuTransactionImport.cs b/src/bnhtrade.Core/Logic/Stock/SkuTransactionImport.cs index 27618d6..10afa97 100644 --- a/src/bnhtrade.Core/Logic/Stock/SkuTransactionImport.cs +++ b/src/bnhtrade.Core/Logic/Stock/SkuTransactionImport.cs @@ -3,7 +3,7 @@ using bnhtrade.Core.Model.Stock; using FikaAmazonAPI.AmazonSpApiSDK.Models.Restrictions; using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/src/bnhtrade.Core/Logic/Stock/SkuTransactionTypeCrud.cs b/src/bnhtrade.Core/Logic/Stock/SkuTransactionTypeCrud.cs index 7192928..3aabfda 100644 --- a/src/bnhtrade.Core/Logic/Stock/SkuTransactionTypeCrud.cs +++ b/src/bnhtrade.Core/Logic/Stock/SkuTransactionTypeCrud.cs @@ -1,7 +1,7 @@ using bnhtrade.Core.Data.Database; using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/src/bnhtrade.Core/Model/Purchase/PurchaseLineStatus.cs b/src/bnhtrade.Core/Model/Purchase/PurchaseLineStatus.cs index f7bae9f..b7b6b74 100644 --- a/src/bnhtrade.Core/Model/Purchase/PurchaseLineStatus.cs +++ b/src/bnhtrade.Core/Model/Purchase/PurchaseLineStatus.cs @@ -1,4 +1,10 @@ -namespace bnhtrade.Core.Model.Purchase +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace bnhtrade.Core.Model.Purchase { public class PurchaseLineStatus { diff --git a/src/bnhtrade.Core/Program.cs b/src/bnhtrade.Core/Program.cs index d3549e3..38065c2 100644 --- a/src/bnhtrade.Core/Program.cs +++ b/src/bnhtrade.Core/Program.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.IO; using System.Linq; using System.Transactions; diff --git a/src/bnhtrade.Core/Test/SQLLoop.cs b/src/bnhtrade.Core/Test/SQLLoop.cs index 74f68db..b2b2eba 100644 --- a/src/bnhtrade.Core/Test/SQLLoop.cs +++ b/src/bnhtrade.Core/Test/SQLLoop.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/src/bnhtrade.Core/Test/_BoilerPlate/Sql.cs b/src/bnhtrade.Core/Test/_BoilerPlate/Sql.cs index cdf2d36..5e0d900 100644 --- a/src/bnhtrade.Core/Test/_BoilerPlate/Sql.cs +++ b/src/bnhtrade.Core/Test/_BoilerPlate/Sql.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/src/bnhtrade.Core/bnhtrade.Core.csproj b/src/bnhtrade.Core/bnhtrade.Core.csproj index 7e43728..3d80c65 100644 --- a/src/bnhtrade.Core/bnhtrade.Core.csproj +++ b/src/bnhtrade.Core/bnhtrade.Core.csproj @@ -49,6 +49,12 @@ ..\..\packages\AWSSDK.SQS.3.7.300.75\lib\net45\AWSSDK.SQS.dll + + ..\..\packages\Azure.Core.1.39.0\lib\net472\Azure.Core.dll + + + ..\..\packages\Azure.Identity.1.11.3\lib\netstandard2.0\Azure.Identity.dll + ..\..\packages\CsvHelper.31.0.4\lib\net47\CsvHelper.dll @@ -67,6 +73,33 @@ ..\..\packages\Microsoft.Bcl.HashCode.1.1.1\lib\net461\Microsoft.Bcl.HashCode.dll + + ..\..\packages\Microsoft.Data.SqlClient.5.2.0\lib\net462\Microsoft.Data.SqlClient.dll + + + ..\..\packages\Microsoft.Identity.Client.4.60.3\lib\net462\Microsoft.Identity.Client.dll + + + ..\..\packages\Microsoft.Identity.Client.Extensions.Msal.4.60.3\lib\netstandard2.0\Microsoft.Identity.Client.Extensions.Msal.dll + + + ..\..\packages\Microsoft.IdentityModel.Abstractions.7.5.1\lib\net472\Microsoft.IdentityModel.Abstractions.dll + + + ..\..\packages\Microsoft.IdentityModel.JsonWebTokens.7.5.1\lib\net472\Microsoft.IdentityModel.JsonWebTokens.dll + + + ..\..\packages\Microsoft.IdentityModel.Logging.7.5.1\lib\net472\Microsoft.IdentityModel.Logging.dll + + + ..\..\packages\Microsoft.IdentityModel.Protocols.7.5.1\lib\net472\Microsoft.IdentityModel.Protocols.dll + + + ..\..\packages\Microsoft.IdentityModel.Protocols.OpenIdConnect.7.5.1\lib\net472\Microsoft.IdentityModel.Protocols.OpenIdConnect.dll + + + ..\..\packages\Microsoft.IdentityModel.Tokens.7.5.1\lib\net472\Microsoft.IdentityModel.Tokens.dll + ..\..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll @@ -89,16 +122,39 @@ ..\..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll + + ..\..\packages\System.ClientModel.1.0.0\lib\netstandard2.0\System.ClientModel.dll + ..\..\packages\System.ComponentModel.Annotations.5.0.0\lib\net461\System.ComponentModel.Annotations.dll + + ..\..\packages\System.Configuration.ConfigurationManager.8.0.0\lib\net462\System.Configuration.ConfigurationManager.dll + + + + ..\..\packages\System.Diagnostics.DiagnosticSource.8.0.1\lib\net462\System.Diagnostics.DiagnosticSource.dll + + + + + + ..\..\packages\System.IdentityModel.Tokens.Jwt.7.5.1\lib\net472\System.IdentityModel.Tokens.Jwt.dll + + + ..\..\packages\System.IO.FileSystem.AccessControl.5.0.0\lib\net461\System.IO.FileSystem.AccessControl.dll + ..\..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll + + ..\..\packages\System.Memory.Data.8.0.0\lib\net462\System.Memory.Data.dll + + ..\..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll @@ -111,7 +167,26 @@ ..\..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll + + ..\..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll + True + True + + + + ..\..\packages\System.Security.AccessControl.6.0.1\lib\net461\System.Security.AccessControl.dll + + + ..\..\packages\System.Security.Cryptography.ProtectedData.8.0.0\lib\net462\System.Security.Cryptography.ProtectedData.dll + + + ..\..\packages\System.Security.Permissions.8.0.0\lib\net462\System.Security.Permissions.dll + + + ..\..\packages\System.Security.Principal.Windows.5.0.0\lib\net461\System.Security.Principal.Windows.dll + + ..\..\packages\System.Text.Encodings.Web.8.0.0\lib\net462\System.Text.Encodings.Web.dll @@ -126,12 +201,14 @@ ..\..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll + + @@ -370,7 +447,9 @@ This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + true + + + + + + true + + + + + + + + + \ No newline at end of file diff --git a/src/bnhtrade.Core/packages.config b/src/bnhtrade.Core/packages.config deleted file mode 100644 index 0c0571d..0000000 --- a/src/bnhtrade.Core/packages.config +++ /dev/null @@ -1,53 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/bnhtrade.ScheduledTasks/Properties/AssemblyInfo.cs b/src/bnhtrade.ScheduledTasks/Properties/AssemblyInfo.cs index 791fba4..fe48fd8 100644 --- a/src/bnhtrade.ScheduledTasks/Properties/AssemblyInfo.cs +++ b/src/bnhtrade.ScheduledTasks/Properties/AssemblyInfo.cs @@ -1,16 +1,6 @@ using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("bnhtrade Scheduled Tasks")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("bnhtrade Scheduled Tasks")] -[assembly: AssemblyCopyright("Copyright © 2018")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -21,16 +11,3 @@ using System.Runtime.InteropServices; // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("5d6e1d66-3901-4340-95c6-ee65051ab623")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/bnhtrade.ScheduledTasks/bnhtrade.ScheduledTasks.csproj b/src/bnhtrade.ScheduledTasks/bnhtrade.ScheduledTasks.csproj index 799bedb..72b1ef4 100644 --- a/src/bnhtrade.ScheduledTasks/bnhtrade.ScheduledTasks.csproj +++ b/src/bnhtrade.ScheduledTasks/bnhtrade.ScheduledTasks.csproj @@ -1,16 +1,9 @@ - - - + - Debug - AnyCPU - {5D6E1D66-3901-4340-95C6-EE65051AB623} + net8.0-windows Exe bnhtrade_Scheduled_Tasks bnhtradeScheduledTasks - v4.7.2 - 512 - true publish\ true Disk @@ -26,56 +19,30 @@ false false true - - - + false + + + false - AnyCPU - true - full - false - ..\..\bin\Debug\console\ - DEBUG;TRACE - prompt - 4 + ..\..\bin\$(AssemblyName)\Debug\ - AnyCPU none - true - ..\..\bin\Release\console\ - TRACE - prompt - 4 + ..\..\bin\$(AssemblyName)\Release\ bnhtradeScheduledTasks.Program - - - - - - - - - - - - - - - + True True Settings.settings - - + SettingsSingleFileGenerator Settings.Designer.cs @@ -93,13 +60,19 @@ - - {339d7413-3da7-46ea-a55c-255a9a6b95eb} - bnhtrade.Core - + + + + + + - xcopy /E /Y "$(TargetDir)" "C:\Users\Bobbie\Dropbox\Apps\bnhtrade" + bnhtrade Scheduled Tasks + bnhtrade Scheduled Tasks + Copyright © 2018 + 1.0.0.0 + 1.0.0.0 \ No newline at end of file diff --git a/bnhtrade.gui/Form1.Designer.cs b/src/bnhtrade.gui/Form1.Designer.cs similarity index 100% rename from bnhtrade.gui/Form1.Designer.cs rename to src/bnhtrade.gui/Form1.Designer.cs diff --git a/bnhtrade.gui/Form1.cs b/src/bnhtrade.gui/Form1.cs similarity index 100% rename from bnhtrade.gui/Form1.cs rename to src/bnhtrade.gui/Form1.cs diff --git a/bnhtrade.gui/Form1.resx b/src/bnhtrade.gui/Form1.resx similarity index 100% rename from bnhtrade.gui/Form1.resx rename to src/bnhtrade.gui/Form1.resx diff --git a/bnhtrade.gui/Program.cs b/src/bnhtrade.gui/Program.cs similarity index 100% rename from bnhtrade.gui/Program.cs rename to src/bnhtrade.gui/Program.cs diff --git a/bnhtrade.gui/Properties/DataSources/bnhtrade.Core.Logic.Purchase.PurchaseLineStatus.datasource b/src/bnhtrade.gui/Properties/DataSources/bnhtrade.Core.Logic.Purchase.PurchaseLineStatus.datasource similarity index 100% rename from bnhtrade.gui/Properties/DataSources/bnhtrade.Core.Logic.Purchase.PurchaseLineStatus.datasource rename to src/bnhtrade.gui/Properties/DataSources/bnhtrade.Core.Logic.Purchase.PurchaseLineStatus.datasource diff --git a/bnhtrade.gui/Properties/DataSources/bnhtrade.Core.Model.Purchase.PurchaseLineStatus.datasource b/src/bnhtrade.gui/Properties/DataSources/bnhtrade.Core.Model.Purchase.PurchaseLineStatus.datasource similarity index 100% rename from bnhtrade.gui/Properties/DataSources/bnhtrade.Core.Model.Purchase.PurchaseLineStatus.datasource rename to src/bnhtrade.gui/Properties/DataSources/bnhtrade.Core.Model.Purchase.PurchaseLineStatus.datasource diff --git a/bnhtrade.gui/Properties/Resources.Designer.cs b/src/bnhtrade.gui/Properties/Resources.Designer.cs similarity index 100% rename from bnhtrade.gui/Properties/Resources.Designer.cs rename to src/bnhtrade.gui/Properties/Resources.Designer.cs diff --git a/bnhtrade.gui/Properties/Resources.resx b/src/bnhtrade.gui/Properties/Resources.resx similarity index 100% rename from bnhtrade.gui/Properties/Resources.resx rename to src/bnhtrade.gui/Properties/Resources.resx diff --git a/bnhtrade.gui/bnhtrade.gui.csproj b/src/bnhtrade.gui/bnhtrade.gui.csproj similarity index 55% rename from bnhtrade.gui/bnhtrade.gui.csproj rename to src/bnhtrade.gui/bnhtrade.gui.csproj index c896b8a..d44d9b5 100644 --- a/bnhtrade.gui/bnhtrade.gui.csproj +++ b/src/bnhtrade.gui/bnhtrade.gui.csproj @@ -6,10 +6,19 @@ enable true enable + C:\Users\Bobbie\source\repos\stokebob\bnhtrade\bin + + + false + + + ..\..\bin\$(AssemblyName)\Debug\ + + + ..\..\bin\$(AssemblyName)\Release\ - - + From c2082acf8e583d4c83ba4beb9c0f50edd1169d11 Mon Sep 17 00:00:00 2001 From: Bobbie Hodgetts Date: Fri, 10 May 2024 18:30:45 +0100 Subject: [PATCH 04/15] 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 From 960579b0b28b25b57f112f7f374efccb94bb7964 Mon Sep 17 00:00:00 2001 From: Bobbie Hodgetts Date: Fri, 10 May 2024 22:42:14 +0100 Subject: [PATCH 05/15] the reciving search box is oworking --- .../Account/PurchaseInvoiceLineSummary.cs | 91 +++++++++++++ .../Logic/Account/PurchaseInvoice.cs | 5 + .../Account/PurchaseInvoiceLineSummary.cs | 18 +++ src/bnhtrade.gui/Form1.Designer.cs | 122 +++++++++++++++--- src/bnhtrade.gui/Form1.cs | 17 ++- src/bnhtrade.gui/Form1.resx | 4 +- ...e.Model.Account.PurchaseInvoice.datasource | 10 ++ ...ount.PurchaseInvoiceLineSummary.datasource | 10 ++ src/bnhtrade.gui/bnhtrade.gui.csproj | 4 + 9 files changed, 260 insertions(+), 21 deletions(-) create mode 100644 src/bnhtrade.Core/Data/Database/Account/PurchaseInvoiceLineSummary.cs create mode 100644 src/bnhtrade.Core/Model/Account/PurchaseInvoiceLineSummary.cs create mode 100644 src/bnhtrade.gui/Properties/DataSources/bnhtrade.Core.Model.Account.PurchaseInvoice.datasource create mode 100644 src/bnhtrade.gui/Properties/DataSources/bnhtrade.Core.Model.Account.PurchaseInvoiceLineSummary.datasource diff --git a/src/bnhtrade.Core/Data/Database/Account/PurchaseInvoiceLineSummary.cs b/src/bnhtrade.Core/Data/Database/Account/PurchaseInvoiceLineSummary.cs new file mode 100644 index 0000000..4c17f9b --- /dev/null +++ b/src/bnhtrade.Core/Data/Database/Account/PurchaseInvoiceLineSummary.cs @@ -0,0 +1,91 @@ +using FikaAmazonAPI.AmazonSpApiSDK.Models.ProductFees; +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 PurchaseInvoiceLineSummary : Connection + { + public List Read(DateTime periodTo, string lineStatus, List descriptionSearch) + { + var returnList = new List(); + var sqlBuilder = new bnhtrade.Core.Data.Database.SqlWhereBuilder(); + + //build sql query + string sql = @" + SELECT tblPurchase.PurchaseDate + ,tblPurchase.PurchaseID + ,tblPurchase.PurchaseNumber + ,tblPurchaseLine.PurchaseLineID + ,tblPurchaseLine.ItemDescription + ,tblPurchaseLineStatus.PurchaseLineStatus + FROM tblPurchase + INNER JOIN tblPurchaseLine ON tblPurchase.PurchaseID = tblPurchaseLine.PurchaseID + INNER JOIN tblPurchaseLineStatus ON tblPurchaseLine.PurchaseLineStatusID = tblPurchaseLineStatus.PurchaseLineStatusID + WHERE tblPurchase.PurchaseDate <= @purchaseDate + "; + + if (lineStatus != null) + { + sql = sql + " AND PurchaseLineStatus = @purchaseLineStatus "; + } + + // build the where statments + if (descriptionSearch.Any()) + { + sqlBuilder.LikeAnd("ItemDescription", descriptionSearch, "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)) + { + cmd.Parameters.AddWithValue("@purchaseDate", periodTo); + if (descriptionSearch.Any()) + { + cmd.Parameters.AddWithValue("@purchaseLineStatus", lineStatus); + } + + sqlBuilder.AddParametersToSqlCommand(cmd); + + using (SqlDataReader reader = cmd.ExecuteReader()) + { + while (reader.Read()) + { + DateTime purchaseDate = DateTime.SpecifyKind(reader.GetDateTime(0), DateTimeKind.Utc); + int purchaseID = reader.GetInt32(1); + int purchaseNumber = reader.GetInt32(2); + int purchaseLineID = reader.GetInt32(3); + string itemDescription = reader.GetString(4); + string purchaseLineStatus = reader.GetString(5); + + var item = new Model.Account.PurchaseInvoiceLineSummary(); + item.PurchaseDate = purchaseDate; + item.PurchaseId = purchaseID; + item.PurchaseNumber = purchaseNumber; + item.PurchaseLineId = purchaseLineID; + item.ItemDescription = itemDescription; + item.LineStatus = purchaseLineStatus; + + returnList.Add(item); + } + } + } + } + return returnList; + } + } +} diff --git a/src/bnhtrade.Core/Logic/Account/PurchaseInvoice.cs b/src/bnhtrade.Core/Logic/Account/PurchaseInvoice.cs index 2f8e014..c9b1e13 100644 --- a/src/bnhtrade.Core/Logic/Account/PurchaseInvoice.cs +++ b/src/bnhtrade.Core/Logic/Account/PurchaseInvoice.cs @@ -12,5 +12,10 @@ namespace bnhtrade.Core.Logic.Account { return new Data.Database.Account.PurchaseInvoiceLineStatus().Read().Values.ToList(); } + + public List GetLineSummary(DateTime maxDate, string lineStatus, List wordSearchList) + { + return new Data.Database.Account.PurchaseInvoiceLineSummary().Read(maxDate,lineStatus, wordSearchList); + } } } diff --git a/src/bnhtrade.Core/Model/Account/PurchaseInvoiceLineSummary.cs b/src/bnhtrade.Core/Model/Account/PurchaseInvoiceLineSummary.cs new file mode 100644 index 0000000..b85fbf7 --- /dev/null +++ b/src/bnhtrade.Core/Model/Account/PurchaseInvoiceLineSummary.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace bnhtrade.Core.Model.Account +{ + public class PurchaseInvoiceLineSummary + { + public int PurchaseId { get; set; } + public int PurchaseNumber { get; set; } + public int PurchaseLineId { get; set; } + public DateTime PurchaseDate { get; set; } + public string ItemDescription { get; set; } + public string LineStatus { get; set; } + } +} diff --git a/src/bnhtrade.gui/Form1.Designer.cs b/src/bnhtrade.gui/Form1.Designer.cs index 099a324..f18f498 100644 --- a/src/bnhtrade.gui/Form1.Designer.cs +++ b/src/bnhtrade.gui/Form1.Designer.cs @@ -33,13 +33,24 @@ tabPage1 = new TabPage(); tabPage2 = new TabPage(); Receiving = new TabPage(); + dataGridView1 = new DataGridView(); + bindingSource1 = new BindingSource(components); + buttonSearch = new Button(); comboBox1 = new ComboBox(); purchaseLineStatusBindingSource = new BindingSource(components); - dtTmOrderSearch = new DateTimePicker(); + dateTimeOrderSearch = new DateTimePicker(); label1 = new Label(); - txtbxOrderSearch = new TextBox(); + textboxOrderSearch = new TextBox(); + purchaseNumberDataGridViewTextBoxColumn = new DataGridViewTextBoxColumn(); + purchaseDateDataGridViewTextBoxColumn = new DataGridViewTextBoxColumn(); + itemDescriptionDataGridViewTextBoxColumn = new DataGridViewTextBoxColumn(); + purchaseLineIdDataGridViewTextBoxColumn = new DataGridViewTextBoxColumn(); + lineStatusDataGridViewTextBoxColumn = new DataGridViewTextBoxColumn(); + purchaseIdDataGridViewTextBoxColumn = new DataGridViewTextBoxColumn(); tabControl1.SuspendLayout(); Receiving.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit(); + ((System.ComponentModel.ISupportInitialize)bindingSource1).BeginInit(); ((System.ComponentModel.ISupportInitialize)purchaseLineStatusBindingSource).BeginInit(); SuspendLayout(); // @@ -79,10 +90,12 @@ // // Receiving // + Receiving.Controls.Add(dataGridView1); + Receiving.Controls.Add(buttonSearch); Receiving.Controls.Add(comboBox1); - Receiving.Controls.Add(dtTmOrderSearch); + Receiving.Controls.Add(dateTimeOrderSearch); Receiving.Controls.Add(label1); - Receiving.Controls.Add(txtbxOrderSearch); + Receiving.Controls.Add(textboxOrderSearch); Receiving.Location = new Point(4, 24); Receiving.Name = "Receiving"; Receiving.Padding = new Padding(3); @@ -92,14 +105,39 @@ Receiving.UseVisualStyleBackColor = true; Receiving.Click += tabPage3_Click; // + // dataGridView1 + // + dataGridView1.AutoGenerateColumns = false; + dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView1.Columns.AddRange(new DataGridViewColumn[] { purchaseNumberDataGridViewTextBoxColumn, purchaseDateDataGridViewTextBoxColumn, itemDescriptionDataGridViewTextBoxColumn, purchaseLineIdDataGridViewTextBoxColumn, lineStatusDataGridViewTextBoxColumn, purchaseIdDataGridViewTextBoxColumn }); + dataGridView1.DataSource = bindingSource1; + dataGridView1.Location = new Point(31, 94); + dataGridView1.Name = "dataGridView1"; + dataGridView1.Size = new Size(925, 396); + dataGridView1.TabIndex = 5; + // + // bindingSource1 + // + bindingSource1.DataSource = typeof(Core.Model.Account.PurchaseInvoiceLineSummary); + // + // buttonSearch + // + buttonSearch.Location = new Point(847, 46); + buttonSearch.Name = "buttonSearch"; + buttonSearch.Size = new Size(109, 25); + buttonSearch.TabIndex = 4; + buttonSearch.Text = "Search"; + buttonSearch.UseVisualStyleBackColor = true; + buttonSearch.Click += buttonSearch_Click; + // // comboBox1 // comboBox1.DataSource = purchaseLineStatusBindingSource; comboBox1.DisplayMember = "PurchaseLineStatusName"; comboBox1.FormattingEnabled = true; - comboBox1.Location = new Point(580, 46); + comboBox1.Location = new Point(195, 46); comboBox1.Name = "comboBox1"; - comboBox1.Size = new Size(214, 23); + comboBox1.Size = new Size(189, 23); comboBox1.TabIndex = 3; comboBox1.ValueMember = "PurchaseLineStatusId"; comboBox1.SelectedIndexChanged += comboBox1_SelectedIndexChanged; @@ -109,12 +147,12 @@ purchaseLineStatusBindingSource.DataSource = typeof(Core.Model.Purchase.PurchaseLineStatus); purchaseLineStatusBindingSource.CurrentChanged += purchaseLineStatusBindingSource_CurrentChanged; // - // dtTmOrderSearch + // dateTimeOrderSearch // - dtTmOrderSearch.Location = new Point(356, 46); - dtTmOrderSearch.Name = "dtTmOrderSearch"; - dtTmOrderSearch.Size = new Size(157, 23); - dtTmOrderSearch.TabIndex = 2; + dateTimeOrderSearch.Location = new Point(31, 46); + dateTimeOrderSearch.Name = "dateTimeOrderSearch"; + dateTimeOrderSearch.Size = new Size(131, 23); + dateTimeOrderSearch.TabIndex = 2; // // label1 // @@ -125,12 +163,49 @@ label1.TabIndex = 1; label1.Text = "Order Search"; // - // txtbxOrderSearch + // textboxOrderSearch // - txtbxOrderSearch.Location = new Point(31, 46); - txtbxOrderSearch.Name = "txtbxOrderSearch"; - txtbxOrderSearch.Size = new Size(268, 23); - txtbxOrderSearch.TabIndex = 0; + textboxOrderSearch.Location = new Point(417, 46); + textboxOrderSearch.Name = "textboxOrderSearch"; + textboxOrderSearch.Size = new Size(415, 23); + textboxOrderSearch.TabIndex = 0; + // + // purchaseNumberDataGridViewTextBoxColumn + // + purchaseNumberDataGridViewTextBoxColumn.DataPropertyName = "PurchaseNumber"; + purchaseNumberDataGridViewTextBoxColumn.HeaderText = "PurchaseNumber"; + purchaseNumberDataGridViewTextBoxColumn.Name = "purchaseNumberDataGridViewTextBoxColumn"; + // + // purchaseDateDataGridViewTextBoxColumn + // + purchaseDateDataGridViewTextBoxColumn.DataPropertyName = "PurchaseDate"; + purchaseDateDataGridViewTextBoxColumn.HeaderText = "PurchaseDate"; + purchaseDateDataGridViewTextBoxColumn.Name = "purchaseDateDataGridViewTextBoxColumn"; + // + // itemDescriptionDataGridViewTextBoxColumn + // + itemDescriptionDataGridViewTextBoxColumn.DataPropertyName = "ItemDescription"; + itemDescriptionDataGridViewTextBoxColumn.HeaderText = "ItemDescription"; + itemDescriptionDataGridViewTextBoxColumn.Name = "itemDescriptionDataGridViewTextBoxColumn"; + itemDescriptionDataGridViewTextBoxColumn.Width = 500; + // + // purchaseLineIdDataGridViewTextBoxColumn + // + purchaseLineIdDataGridViewTextBoxColumn.DataPropertyName = "PurchaseLineId"; + purchaseLineIdDataGridViewTextBoxColumn.HeaderText = "PurchaseLineId"; + purchaseLineIdDataGridViewTextBoxColumn.Name = "purchaseLineIdDataGridViewTextBoxColumn"; + // + // lineStatusDataGridViewTextBoxColumn + // + lineStatusDataGridViewTextBoxColumn.DataPropertyName = "LineStatus"; + lineStatusDataGridViewTextBoxColumn.HeaderText = "LineStatus"; + lineStatusDataGridViewTextBoxColumn.Name = "lineStatusDataGridViewTextBoxColumn"; + // + // purchaseIdDataGridViewTextBoxColumn + // + purchaseIdDataGridViewTextBoxColumn.DataPropertyName = "PurchaseId"; + purchaseIdDataGridViewTextBoxColumn.HeaderText = "PurchaseId"; + purchaseIdDataGridViewTextBoxColumn.Name = "purchaseIdDataGridViewTextBoxColumn"; // // Form1 // @@ -144,6 +219,8 @@ tabControl1.ResumeLayout(false); Receiving.ResumeLayout(false); Receiving.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit(); + ((System.ComponentModel.ISupportInitialize)bindingSource1).EndInit(); ((System.ComponentModel.ISupportInitialize)purchaseLineStatusBindingSource).EndInit(); ResumeLayout(false); } @@ -154,10 +231,19 @@ private TabPage tabPage1; private TabPage tabPage2; private TabPage Receiving; - private TextBox txtbxOrderSearch; + private TextBox textboxOrderSearch; private Label label1; - private DateTimePicker dtTmOrderSearch; + private DateTimePicker dateTimeOrderSearch; private ComboBox comboBox1; private BindingSource purchaseLineStatusBindingSource; + private Button buttonSearch; + private DataGridView dataGridView1; + private BindingSource bindingSource1; + private DataGridViewTextBoxColumn purchaseNumberDataGridViewTextBoxColumn; + private DataGridViewTextBoxColumn purchaseDateDataGridViewTextBoxColumn; + private DataGridViewTextBoxColumn itemDescriptionDataGridViewTextBoxColumn; + private DataGridViewTextBoxColumn purchaseLineIdDataGridViewTextBoxColumn; + private DataGridViewTextBoxColumn lineStatusDataGridViewTextBoxColumn; + private DataGridViewTextBoxColumn purchaseIdDataGridViewTextBoxColumn; } } diff --git a/src/bnhtrade.gui/Form1.cs b/src/bnhtrade.gui/Form1.cs index 75d3ee7..2bb0e5b 100644 --- a/src/bnhtrade.gui/Form1.cs +++ b/src/bnhtrade.gui/Form1.cs @@ -34,8 +34,8 @@ namespace bnhtrade.gui private void InitialiseTabReceiving() { purchaseLineStatusBindingSource.DataSource = new Core.Logic.Account.PurchaseInvoice().ReadLineStatusToList(); + comboBox1.SelectedIndex = 3; initTabReceiving = true; - MessageBox.Show("ldsakjfl;s"); } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) @@ -48,5 +48,20 @@ namespace bnhtrade.gui } + private void buttonSearch_Click(object sender, EventArgs e) + { + char[] separator = { ' ' }; + var searchList = textboxOrderSearch.Text.Split(separator).ToList(); + + bindingSource1.DataSource = new Core.Logic.Account.PurchaseInvoice().GetLineSummary( + dateTimeOrderSearch.Value + , comboBox1.Text + , searchList); + } + + private void bindingSource1_CurrentChanged(object sender, EventArgs e) + { + + } } } diff --git a/src/bnhtrade.gui/Form1.resx b/src/bnhtrade.gui/Form1.resx index 6a9ea6f..3431ac8 100644 --- a/src/bnhtrade.gui/Form1.resx +++ b/src/bnhtrade.gui/Form1.resx @@ -117,8 +117,8 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 17, 17 + + 250, 17 17, 17 diff --git a/src/bnhtrade.gui/Properties/DataSources/bnhtrade.Core.Model.Account.PurchaseInvoice.datasource b/src/bnhtrade.gui/Properties/DataSources/bnhtrade.Core.Model.Account.PurchaseInvoice.datasource new file mode 100644 index 0000000..a5a5f96 --- /dev/null +++ b/src/bnhtrade.gui/Properties/DataSources/bnhtrade.Core.Model.Account.PurchaseInvoice.datasource @@ -0,0 +1,10 @@ + + + + bnhtrade.Core.Model.Account.PurchaseInvoice, bnhtrade.Core, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + \ No newline at end of file diff --git a/src/bnhtrade.gui/Properties/DataSources/bnhtrade.Core.Model.Account.PurchaseInvoiceLineSummary.datasource b/src/bnhtrade.gui/Properties/DataSources/bnhtrade.Core.Model.Account.PurchaseInvoiceLineSummary.datasource new file mode 100644 index 0000000..495bd9f --- /dev/null +++ b/src/bnhtrade.gui/Properties/DataSources/bnhtrade.Core.Model.Account.PurchaseInvoiceLineSummary.datasource @@ -0,0 +1,10 @@ + + + + bnhtrade.Core.Model.Account.PurchaseInvoiceLineSummary, bnhtrade.Core, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + \ No newline at end of file diff --git a/src/bnhtrade.gui/bnhtrade.gui.csproj b/src/bnhtrade.gui/bnhtrade.gui.csproj index d44d9b5..f49ccfd 100644 --- a/src/bnhtrade.gui/bnhtrade.gui.csproj +++ b/src/bnhtrade.gui/bnhtrade.gui.csproj @@ -36,4 +36,8 @@ + + + + \ No newline at end of file From a56a97031aa78b2f16d89b74f401843bd06d087e Mon Sep 17 00:00:00 2001 From: Bobbie Hodgetts Date: Sat, 11 May 2024 09:46:47 +0100 Subject: [PATCH 06/15] wip --- .../Account/PurchaseInvoiceLineSummary.cs | 2 +- .../Model/Credentials/bnhtradeDB.cs | 17 ++- src/bnhtrade.gui/Form1.Designer.cs | 140 ++++++++++-------- src/bnhtrade.gui/Form1.cs | 36 ++++- 4 files changed, 128 insertions(+), 67 deletions(-) diff --git a/src/bnhtrade.Core/Data/Database/Account/PurchaseInvoiceLineSummary.cs b/src/bnhtrade.Core/Data/Database/Account/PurchaseInvoiceLineSummary.cs index 4c17f9b..1b4e20f 100644 --- a/src/bnhtrade.Core/Data/Database/Account/PurchaseInvoiceLineSummary.cs +++ b/src/bnhtrade.Core/Data/Database/Account/PurchaseInvoiceLineSummary.cs @@ -54,7 +54,7 @@ namespace bnhtrade.Core.Data.Database.Account using (SqlCommand cmd = new SqlCommand(sql, conn)) { cmd.Parameters.AddWithValue("@purchaseDate", periodTo); - if (descriptionSearch.Any()) + if (lineStatus != null) { cmd.Parameters.AddWithValue("@purchaseLineStatus", lineStatus); } diff --git a/src/bnhtrade.Core/Model/Credentials/bnhtradeDB.cs b/src/bnhtrade.Core/Model/Credentials/bnhtradeDB.cs index 2155c85..6071447 100644 --- a/src/bnhtrade.Core/Model/Credentials/bnhtradeDB.cs +++ b/src/bnhtrade.Core/Model/Credentials/bnhtradeDB.cs @@ -9,24 +9,35 @@ namespace bnhtrade.Core.Model.Credentials public class bnhtradeDB { public string DataSource { get; private set; } + public string UserId { get; private set; } + public string UserPassword { get; private set; } + public string InitialCatalog { get; private set; } = "e2A"; + public bool PersistSecurityInfo { get; private set; } = true; + public bool MultipleActiveResultSets { get; private set; } = true; + + public uint ConnectionTimeout { get; private set; } + public string ConnectionString - { get + { + get { return "Data Source=" + DataSource + ";Initial Catalog=" + InitialCatalog + ";Persist Security Info=" + PersistSecurityInfo.ToString() - + ";User ID=" + UserId + ";Password=" + UserPassword + ";MultipleActiveResultSets=" + MultipleActiveResultSets.ToString(); + + ";User ID=" + UserId + ";Password=" + UserPassword + ";MultipleActiveResultSets=" + MultipleActiveResultSets.ToString() + + ";Connect Timeout=" + ConnectionTimeout; } } - public bnhtradeDB (string source, string userId, string userPassword) + public bnhtradeDB (string source, string userId, string userPassword, uint connectionTimeout = 30) { this.DataSource = source; this.UserId = userId; this.UserPassword = userPassword; + this.ConnectionTimeout = connectionTimeout; } } } diff --git a/src/bnhtrade.gui/Form1.Designer.cs b/src/bnhtrade.gui/Form1.Designer.cs index f18f498..1ad7482 100644 --- a/src/bnhtrade.gui/Form1.Designer.cs +++ b/src/bnhtrade.gui/Form1.Designer.cs @@ -33,7 +33,14 @@ tabPage1 = new TabPage(); tabPage2 = new TabPage(); Receiving = new TabPage(); + labelDataGridCount = new Label(); dataGridView1 = new DataGridView(); + purchaseNumberDataGridViewTextBoxColumn = new DataGridViewTextBoxColumn(); + purchaseDateDataGridViewTextBoxColumn = new DataGridViewTextBoxColumn(); + itemDescriptionDataGridViewTextBoxColumn = new DataGridViewTextBoxColumn(); + purchaseLineIdDataGridViewTextBoxColumn = new DataGridViewTextBoxColumn(); + lineStatusDataGridViewTextBoxColumn = new DataGridViewTextBoxColumn(); + purchaseIdDataGridViewTextBoxColumn = new DataGridViewTextBoxColumn(); bindingSource1 = new BindingSource(components); buttonSearch = new Button(); comboBox1 = new ComboBox(); @@ -41,12 +48,6 @@ dateTimeOrderSearch = new DateTimePicker(); label1 = new Label(); textboxOrderSearch = new TextBox(); - purchaseNumberDataGridViewTextBoxColumn = new DataGridViewTextBoxColumn(); - purchaseDateDataGridViewTextBoxColumn = new DataGridViewTextBoxColumn(); - itemDescriptionDataGridViewTextBoxColumn = new DataGridViewTextBoxColumn(); - purchaseLineIdDataGridViewTextBoxColumn = new DataGridViewTextBoxColumn(); - lineStatusDataGridViewTextBoxColumn = new DataGridViewTextBoxColumn(); - purchaseIdDataGridViewTextBoxColumn = new DataGridViewTextBoxColumn(); tabControl1.SuspendLayout(); Receiving.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit(); @@ -90,6 +91,7 @@ // // Receiving // + Receiving.Controls.Add(labelDataGridCount); Receiving.Controls.Add(dataGridView1); Receiving.Controls.Add(buttonSearch); Receiving.Controls.Add(comboBox1); @@ -105,71 +107,30 @@ Receiving.UseVisualStyleBackColor = true; Receiving.Click += tabPage3_Click; // + // labelDataGridCount + // + labelDataGridCount.Anchor = AnchorStyles.Right; + labelDataGridCount.ImageAlign = ContentAlignment.MiddleRight; + labelDataGridCount.Location = new Point(845, 70); + labelDataGridCount.Name = "labelDataGridCount"; + labelDataGridCount.RightToLeft = RightToLeft.Yes; + labelDataGridCount.Size = new Size(129, 21); + labelDataGridCount.TabIndex = 6; + labelDataGridCount.Text = "labelListCount"; + labelDataGridCount.TextAlign = ContentAlignment.MiddleLeft; + // // dataGridView1 // + dataGridView1.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; dataGridView1.AutoGenerateColumns = false; dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridView1.Columns.AddRange(new DataGridViewColumn[] { purchaseNumberDataGridViewTextBoxColumn, purchaseDateDataGridViewTextBoxColumn, itemDescriptionDataGridViewTextBoxColumn, purchaseLineIdDataGridViewTextBoxColumn, lineStatusDataGridViewTextBoxColumn, purchaseIdDataGridViewTextBoxColumn }); dataGridView1.DataSource = bindingSource1; dataGridView1.Location = new Point(31, 94); dataGridView1.Name = "dataGridView1"; - dataGridView1.Size = new Size(925, 396); + dataGridView1.Size = new Size(943, 396); dataGridView1.TabIndex = 5; // - // bindingSource1 - // - bindingSource1.DataSource = typeof(Core.Model.Account.PurchaseInvoiceLineSummary); - // - // buttonSearch - // - buttonSearch.Location = new Point(847, 46); - buttonSearch.Name = "buttonSearch"; - buttonSearch.Size = new Size(109, 25); - buttonSearch.TabIndex = 4; - buttonSearch.Text = "Search"; - buttonSearch.UseVisualStyleBackColor = true; - buttonSearch.Click += buttonSearch_Click; - // - // comboBox1 - // - comboBox1.DataSource = purchaseLineStatusBindingSource; - comboBox1.DisplayMember = "PurchaseLineStatusName"; - comboBox1.FormattingEnabled = true; - comboBox1.Location = new Point(195, 46); - comboBox1.Name = "comboBox1"; - comboBox1.Size = new Size(189, 23); - comboBox1.TabIndex = 3; - comboBox1.ValueMember = "PurchaseLineStatusId"; - comboBox1.SelectedIndexChanged += comboBox1_SelectedIndexChanged; - // - // purchaseLineStatusBindingSource - // - purchaseLineStatusBindingSource.DataSource = typeof(Core.Model.Purchase.PurchaseLineStatus); - purchaseLineStatusBindingSource.CurrentChanged += purchaseLineStatusBindingSource_CurrentChanged; - // - // dateTimeOrderSearch - // - dateTimeOrderSearch.Location = new Point(31, 46); - dateTimeOrderSearch.Name = "dateTimeOrderSearch"; - dateTimeOrderSearch.Size = new Size(131, 23); - dateTimeOrderSearch.TabIndex = 2; - // - // label1 - // - label1.AutoSize = true; - label1.Location = new Point(31, 28); - label1.Name = "label1"; - label1.Size = new Size(75, 15); - label1.TabIndex = 1; - label1.Text = "Order Search"; - // - // textboxOrderSearch - // - textboxOrderSearch.Location = new Point(417, 46); - textboxOrderSearch.Name = "textboxOrderSearch"; - textboxOrderSearch.Size = new Size(415, 23); - textboxOrderSearch.TabIndex = 0; - // // purchaseNumberDataGridViewTextBoxColumn // purchaseNumberDataGridViewTextBoxColumn.DataPropertyName = "PurchaseNumber"; @@ -207,6 +168,62 @@ purchaseIdDataGridViewTextBoxColumn.HeaderText = "PurchaseId"; purchaseIdDataGridViewTextBoxColumn.Name = "purchaseIdDataGridViewTextBoxColumn"; // + // bindingSource1 + // + bindingSource1.DataSource = typeof(Core.Model.Account.PurchaseInvoiceLineSummary); + // + // buttonSearch + // + buttonSearch.Location = new Point(865, 37); + buttonSearch.Name = "buttonSearch"; + buttonSearch.Size = new Size(109, 25); + buttonSearch.TabIndex = 4; + buttonSearch.Text = "Search"; + buttonSearch.UseVisualStyleBackColor = true; + buttonSearch.Click += buttonSearch_Click; + // + // comboBox1 + // + comboBox1.DataSource = purchaseLineStatusBindingSource; + comboBox1.DisplayMember = "PurchaseLineStatusName"; + comboBox1.FormattingEnabled = true; + comboBox1.Location = new Point(195, 39); + comboBox1.Name = "comboBox1"; + comboBox1.Size = new Size(189, 23); + comboBox1.TabIndex = 3; + comboBox1.ValueMember = "PurchaseLineStatusId"; + comboBox1.SelectedIndexChanged += comboBox1_SelectedIndexChanged; + // + // purchaseLineStatusBindingSource + // + purchaseLineStatusBindingSource.DataSource = typeof(Core.Model.Purchase.PurchaseLineStatus); + purchaseLineStatusBindingSource.CurrentChanged += purchaseLineStatusBindingSource_CurrentChanged; + // + // dateTimeOrderSearch + // + dateTimeOrderSearch.Location = new Point(31, 39); + dateTimeOrderSearch.Name = "dateTimeOrderSearch"; + dateTimeOrderSearch.Size = new Size(131, 23); + dateTimeOrderSearch.TabIndex = 2; + dateTimeOrderSearch.ValueChanged += dateTimeOrderSearch_ValueChanged; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(31, 21); + label1.Name = "label1"; + label1.Size = new Size(75, 15); + label1.TabIndex = 1; + label1.Text = "Order Search"; + // + // textboxOrderSearch + // + textboxOrderSearch.Location = new Point(417, 39); + textboxOrderSearch.Name = "textboxOrderSearch"; + textboxOrderSearch.Size = new Size(415, 23); + textboxOrderSearch.TabIndex = 0; + textboxOrderSearch.KeyPress += textboxOrderSearch_KeyPress; + // // Form1 // AutoScaleDimensions = new SizeF(7F, 15F); @@ -245,5 +262,6 @@ private DataGridViewTextBoxColumn purchaseLineIdDataGridViewTextBoxColumn; private DataGridViewTextBoxColumn lineStatusDataGridViewTextBoxColumn; private DataGridViewTextBoxColumn purchaseIdDataGridViewTextBoxColumn; + private Label labelDataGridCount; } } diff --git a/src/bnhtrade.gui/Form1.cs b/src/bnhtrade.gui/Form1.cs index 2bb0e5b..201889c 100644 --- a/src/bnhtrade.gui/Form1.cs +++ b/src/bnhtrade.gui/Form1.cs @@ -33,14 +33,18 @@ namespace bnhtrade.gui private void InitialiseTabReceiving() { + Cursor.Current = Cursors.WaitCursor; purchaseLineStatusBindingSource.DataSource = new Core.Logic.Account.PurchaseInvoice().ReadLineStatusToList(); comboBox1.SelectedIndex = 3; + ListBoxQuery(); initTabReceiving = true; + Cursor.Current = Cursors.Default; } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { - + ListBoxQuery(); + textboxOrderSearch.Select(); } private void purchaseLineStatusBindingSource_CurrentChanged(object sender, EventArgs e) @@ -49,19 +53,47 @@ namespace bnhtrade.gui } private void buttonSearch_Click(object sender, EventArgs e) + { + ListBoxQuery(); + } + + private void textboxOrderSearch_KeyPress(object sender, KeyPressEventArgs e) + { + if (e.KeyChar == Convert.ToChar(Keys.Enter)) + { + ListBoxQuery(); + e.Handled = true; + } + } + + private void ListBoxQuery() { char[] separator = { ' ' }; var searchList = textboxOrderSearch.Text.Split(separator).ToList(); + string comboBox = null; + if (comboBox1.Text != "All") + { + comboBox = comboBox1.Text; + } + bindingSource1.DataSource = new Core.Logic.Account.PurchaseInvoice().GetLineSummary( dateTimeOrderSearch.Value - , comboBox1.Text + , comboBox , searchList); + + labelDataGridCount.Text = bindingSource1.Count.ToString(); } private void bindingSource1_CurrentChanged(object sender, EventArgs e) { } + + private void dateTimeOrderSearch_ValueChanged(object sender, EventArgs e) + { + ListBoxQuery(); + textboxOrderSearch.Select(); + } } } From fb058fc22fcf00f238bcf89c4b001faf9101c724 Mon Sep 17 00:00:00 2001 From: Bobbie Hodgetts Date: Sun, 12 May 2024 00:07:24 +0100 Subject: [PATCH 07/15] wip --- .../Data/Database/Account/PurchaseInvoice.cs | 2 +- .../Database/Account/PurchaseInvoiceLine.cs | 27 +- .../Logic/Account/PurchaseInvoice.cs | 11 +- .../Logic/Account/PurchaseInvoiceMisc.cs | 21 + .../Model/Account/PurchaseInvoice.cs | 124 ++++- .../Model/Account/TaxCodeInfo.cs | 4 +- .../Forms/Account/PurchaseInvoice.Designer.cs | 514 ++++++++++++++++++ .../Forms/Account/PurchaseInvoice.cs | 31 ++ .../Forms/Account/PurchaseInvoice.resx | 150 +++++ .../{Form1.Designer.cs => Home.Designer.cs} | 37 +- src/bnhtrade.gui/{Form1.cs => Home.cs} | 25 +- src/bnhtrade.gui/{Form1.resx => Home.resx} | 2 +- src/bnhtrade.gui/Program.cs | 2 +- ...rade.Core.Model.Account.Contact.datasource | 10 + 14 files changed, 920 insertions(+), 40 deletions(-) create mode 100644 src/bnhtrade.Core/Logic/Account/PurchaseInvoiceMisc.cs create mode 100644 src/bnhtrade.gui/Forms/Account/PurchaseInvoice.Designer.cs create mode 100644 src/bnhtrade.gui/Forms/Account/PurchaseInvoice.cs create mode 100644 src/bnhtrade.gui/Forms/Account/PurchaseInvoice.resx rename src/bnhtrade.gui/{Form1.Designer.cs => Home.Designer.cs} (91%) rename src/bnhtrade.gui/{Form1.cs => Home.cs} (70%) rename src/bnhtrade.gui/{Form1.resx => Home.resx} (97%) create mode 100644 src/bnhtrade.gui/Properties/DataSources/bnhtrade.Core.Model.Account.Contact.datasource diff --git a/src/bnhtrade.Core/Data/Database/Account/PurchaseInvoice.cs b/src/bnhtrade.Core/Data/Database/Account/PurchaseInvoice.cs index 17574b0..9b0fe1e 100644 --- a/src/bnhtrade.Core/Data/Database/Account/PurchaseInvoice.cs +++ b/src/bnhtrade.Core/Data/Database/Account/PurchaseInvoice.cs @@ -8,7 +8,7 @@ using static System.ComponentModel.Design.ObjectSelectorEditor; namespace bnhtrade.Core.Data.Database.Account { - internal class PurchaseInvoice : Connection + public class PurchaseInvoice : Connection { private bnhtrade.Core.Data.Database.SqlWhereBuilder sqlBuilder; diff --git a/src/bnhtrade.Core/Data/Database/Account/PurchaseInvoiceLine.cs b/src/bnhtrade.Core/Data/Database/Account/PurchaseInvoiceLine.cs index 4e7ee2f..d282818 100644 --- a/src/bnhtrade.Core/Data/Database/Account/PurchaseInvoiceLine.cs +++ b/src/bnhtrade.Core/Data/Database/Account/PurchaseInvoiceLine.cs @@ -44,6 +44,7 @@ namespace bnhtrade.Core.Data.Database.Account InvoiceIdList = new List(); InvoiceLineIdList = new List(); StatusList = new List(); + ItemDescription = new List(); } public Dictionary Read() @@ -104,6 +105,9 @@ namespace bnhtrade.Core.Data.Database.Account sql = sql + sqlBuilder.SqlWhereString; } + // catch taxcode to add in after db read + var lineTaxCodeDict = new Dictionary(); + using (SqlConnection conn = new SqlConnection(SqlConnectionString)) { conn.Open(); @@ -173,14 +177,35 @@ namespace bnhtrade.Core.Data.Database.Account line.RecordModified = recordModified; line.RecordCreated = recordCreated; line.IsActive = isActive; - line.AccountTaxCode = accountTaxCode; returnList.Add(purchaseLineID, line); + + lineTaxCodeDict.Add(purchaseLineID, accountTaxCode); } } } } } + // read tax codes form db and add to return object + var taxcodeList = new Data.Database.Account.ReadTaxCode().GetByTaxCode(lineTaxCodeDict.Values.ToList()); + + foreach (var line in returnList.Values) + { + foreach(var taxcode in taxcodeList) + { + if (taxcode.TaxCode == lineTaxCodeDict[line.PurchaseLineId]) + { + line.AccountTaxCode = taxcode; + break; + } + } + if (line.AccountTaxCode == null) + { + throw new Exception("Fail safe, this really shouodn't happen"); + } + } + + // all done return returnList; } } diff --git a/src/bnhtrade.Core/Logic/Account/PurchaseInvoice.cs b/src/bnhtrade.Core/Logic/Account/PurchaseInvoice.cs index c9b1e13..13c3936 100644 --- a/src/bnhtrade.Core/Logic/Account/PurchaseInvoice.cs +++ b/src/bnhtrade.Core/Logic/Account/PurchaseInvoice.cs @@ -6,16 +6,7 @@ using System.Threading.Tasks; namespace bnhtrade.Core.Logic.Account { - public class PurchaseInvoice + public class PurchaseInvoice : Core.Data.Database.Account.PurchaseInvoice { - public List ReadLineStatusToList() - { - return new Data.Database.Account.PurchaseInvoiceLineStatus().Read().Values.ToList(); - } - - public List GetLineSummary(DateTime maxDate, string lineStatus, List wordSearchList) - { - return new Data.Database.Account.PurchaseInvoiceLineSummary().Read(maxDate,lineStatus, wordSearchList); - } } } diff --git a/src/bnhtrade.Core/Logic/Account/PurchaseInvoiceMisc.cs b/src/bnhtrade.Core/Logic/Account/PurchaseInvoiceMisc.cs new file mode 100644 index 0000000..02330bb --- /dev/null +++ b/src/bnhtrade.Core/Logic/Account/PurchaseInvoiceMisc.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace bnhtrade.Core.Logic.Account +{ + public class PurchaseInvoiceMisc + { + public List ReadLineStatusToList() + { + return new Data.Database.Account.PurchaseInvoiceLineStatus().Read().Values.ToList(); + } + + public List GetLineSummary(DateTime maxDate, string lineStatus, List wordSearchList) + { + return new Data.Database.Account.PurchaseInvoiceLineSummary().Read(maxDate,lineStatus, wordSearchList); + } + } +} diff --git a/src/bnhtrade.Core/Model/Account/PurchaseInvoice.cs b/src/bnhtrade.Core/Model/Account/PurchaseInvoice.cs index b6e3250..6fe3a0f 100644 --- a/src/bnhtrade.Core/Model/Account/PurchaseInvoice.cs +++ b/src/bnhtrade.Core/Model/Account/PurchaseInvoice.cs @@ -9,18 +9,71 @@ 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 decimal InvoiceNetAmount + { + get + { + return InvoiceGrossAmount - InvoiceTaxAmount; + } + } + + public decimal InvoiceTaxAmount + { + get + { + decimal amount = 0; + foreach (var item in InvoiceLines) + { + amount = amount + item.LineTotalTax; + } + return amount; + } + } + + public decimal InvoiceGrossAmount + { + get + { + decimal amount = 0; + foreach (var item in InvoiceLines) + { + amount = amount + item.LineTotalGross; + } + return amount; + } + } + + /// + /// Value stored in database to check invoice lines against + /// + public decimal InvoiceGrossAmountCheck { get; set; } + + /// + /// Don't know what this is for, all the amounts in the db are gross, so this is always true + /// 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; } @@ -28,24 +81,91 @@ namespace bnhtrade.Core.Model.Account 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 ItemNet + { + get + { + return ItemGross - ItemTax; + } + } + public decimal ItemGross { get; set; } + public decimal ItemTax { get; set; } + + public decimal ShippingNet + { + get + { + return ShippingGross - ShippingTax; + } + } + public decimal ShippingGross { get; set; } + public decimal ShippingTax { get; set; } + + public decimal OtherNet + { + get + { + return OtherGross - OtherTax; + } + } + public decimal OtherGross { get; set; } + public decimal OtherTax { get; set; } - public string AccountTaxCode { get; set; } + + public decimal LineTotalNet + { + get + { + return (ItemGross + ShippingGross + OtherGross) - (ItemTax + ShippingTax + OtherTax); + } + } + + public decimal LineTotalTax + { + get + { + return ItemTax + ShippingTax + OtherTax; + } + } + + public decimal LineTotalGross + { + get + { + return ItemGross + ShippingGross + OtherGross; + } + } + + public bnhtrade.Core.Model.Account.TaxCodeInfo 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/TaxCodeInfo.cs b/src/bnhtrade.Core/Model/Account/TaxCodeInfo.cs index fe57a95..4e3d067 100644 --- a/src/bnhtrade.Core/Model/Account/TaxCodeInfo.cs +++ b/src/bnhtrade.Core/Model/Account/TaxCodeInfo.cs @@ -9,7 +9,7 @@ namespace bnhtrade.Core.Model.Account { public class TaxCodeInfo : IValidatableObject { - public TaxCodeInfo(string taxCodeId, string title, string description, decimal taxRatePercent, bool isMarginSchemeRate, + public TaxCodeInfo(string taxCode, string title, string description, decimal taxRatePercent, bool isMarginSchemeRate, bool isValidOnExpense, bool isValidOnIncome, string taxType, bool isActive) { if (TaxRate < 0) @@ -24,7 +24,7 @@ namespace bnhtrade.Core.Model.Account throw new Exception("Tax rate is >= 100%"); } - TaxCode = taxCodeId; + TaxCode = taxCode; TaxCodeDescription = description; TaxRate = taxRatePercent; IsMarginScheme = isMarginSchemeRate; diff --git a/src/bnhtrade.gui/Forms/Account/PurchaseInvoice.Designer.cs b/src/bnhtrade.gui/Forms/Account/PurchaseInvoice.Designer.cs new file mode 100644 index 0000000..f307d5e --- /dev/null +++ b/src/bnhtrade.gui/Forms/Account/PurchaseInvoice.Designer.cs @@ -0,0 +1,514 @@ +namespace bnhtrade.gui.Forms.Account +{ + partial class PurchaseInvoice + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + bsInvoice = new BindingSource(components); + textBoxEbayUsername = new TextBox(); + bsContact = new BindingSource(components); + label1 = new Label(); + label2 = new Label(); + textBoxEbayEmail = new TextBox(); + label3 = new Label(); + textBoxPaypalUsername = new TextBox(); + label4 = new Label(); + textBoxPaypalEmail = new TextBox(); + label5 = new Label(); + textBoxUsername = new TextBox(); + labelPurchaseInvoiceNumber = new Label(); + labelSupplierRef = new Label(); + textBox1 = new TextBox(); + dateTimeOrderDate = new DateTimePicker(); + textBoxTotalAmount = new TextBox(); + textBoxTaxAmount = new TextBox(); + textBoxNetAmount = new TextBox(); + label6 = new Label(); + label7 = new Label(); + label8 = new Label(); + label = new Label(); + label11 = new Label(); + dataGridView1 = new DataGridView(); + itemDescriptionDataGridViewTextBoxColumn = new DataGridViewTextBoxColumn(); + statusDataGridViewTextBoxColumn = new DataGridViewTextBoxColumn(); + itemQuantityDataGridViewTextBoxColumn = new DataGridViewTextBoxColumn(); + PurchaseId = new DataGridViewTextBoxColumn(); + PurchaseLineId = new DataGridViewTextBoxColumn(); + ItemNet = new DataGridViewTextBoxColumn(); + ShippingNet = new DataGridViewTextBoxColumn(); + OtherNet = new DataGridViewTextBoxColumn(); + LineTotalTax = new DataGridViewTextBoxColumn(); + LineTotalGross = new DataGridViewTextBoxColumn(); + bsInvoiceLines = new BindingSource(components); + textBoxOrderChannel = new TextBox(); + tabControl1 = new TabControl(); + tabPageAccountTransactions = new TabPage(); + tabPageNotes = new TabPage(); + ((System.ComponentModel.ISupportInitialize)bsInvoice).BeginInit(); + ((System.ComponentModel.ISupportInitialize)bsContact).BeginInit(); + ((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit(); + ((System.ComponentModel.ISupportInitialize)bsInvoiceLines).BeginInit(); + tabControl1.SuspendLayout(); + SuspendLayout(); + // + // bsInvoice + // + bsInvoice.DataSource = typeof(Core.Model.Account.PurchaseInvoice); + // + // textBoxEbayUsername + // + textBoxEbayUsername.DataBindings.Add(new Binding("Text", bsContact, "ContactEbayName", true)); + textBoxEbayUsername.Location = new Point(118, 83); + textBoxEbayUsername.Name = "textBoxEbayUsername"; + textBoxEbayUsername.Size = new Size(215, 23); + textBoxEbayUsername.TabIndex = 0; + // + // bsContact + // + bsContact.DataSource = typeof(Core.Model.Account.Contact); + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(16, 86); + label1.Name = "label1"; + label1.Size = new Size(87, 15); + label1.TabIndex = 1; + label1.Text = "ebay username"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(16, 115); + label2.Name = "label2"; + label2.Size = new Size(64, 15); + label2.TabIndex = 3; + label2.Text = "ebay email"; + // + // textBoxEbayEmail + // + textBoxEbayEmail.DataBindings.Add(new Binding("Text", bsContact, "ContactEbayEmail", true)); + textBoxEbayEmail.Location = new Point(118, 112); + textBoxEbayEmail.Name = "textBoxEbayEmail"; + textBoxEbayEmail.Size = new Size(215, 23); + textBoxEbayEmail.TabIndex = 2; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(16, 144); + label3.Name = "label3"; + label3.Size = new Size(97, 15); + label3.TabIndex = 5; + label3.Text = "paypal username"; + // + // textBoxPaypalUsername + // + textBoxPaypalUsername.DataBindings.Add(new Binding("Text", bsContact, "ContactPaypalName", true)); + textBoxPaypalUsername.Location = new Point(118, 141); + textBoxPaypalUsername.Name = "textBoxPaypalUsername"; + textBoxPaypalUsername.Size = new Size(215, 23); + textBoxPaypalUsername.TabIndex = 4; + // + // label4 + // + label4.AutoSize = true; + label4.Location = new Point(16, 173); + label4.Name = "label4"; + label4.Size = new Size(74, 15); + label4.TabIndex = 7; + label4.Text = "paypal email"; + // + // textBoxPaypalEmail + // + textBoxPaypalEmail.DataBindings.Add(new Binding("Text", bsContact, "ContactPaypalEmail", true)); + textBoxPaypalEmail.Location = new Point(118, 170); + textBoxPaypalEmail.Name = "textBoxPaypalEmail"; + textBoxPaypalEmail.Size = new Size(215, 23); + textBoxPaypalEmail.TabIndex = 6; + // + // label5 + // + label5.AutoSize = true; + label5.Location = new Point(16, 57); + label5.Name = "label5"; + label5.Size = new Size(39, 15); + label5.TabIndex = 9; + label5.Text = "Name"; + // + // textBoxUsername + // + textBoxUsername.DataBindings.Add(new Binding("Text", bsContact, "ContantName", true)); + textBoxUsername.Location = new Point(118, 54); + textBoxUsername.Name = "textBoxUsername"; + textBoxUsername.Size = new Size(215, 23); + textBoxUsername.TabIndex = 8; + // + // labelPurchaseInvoiceNumber + // + labelPurchaseInvoiceNumber.AutoSize = true; + labelPurchaseInvoiceNumber.Font = new Font("Segoe UI", 18F, FontStyle.Regular, GraphicsUnit.Point, 0); + labelPurchaseInvoiceNumber.Location = new Point(12, 9); + labelPurchaseInvoiceNumber.Name = "labelPurchaseInvoiceNumber"; + labelPurchaseInvoiceNumber.Size = new Size(213, 32); + labelPurchaseInvoiceNumber.TabIndex = 10; + labelPurchaseInvoiceNumber.Text = "Purchase Invoice #"; + // + // labelSupplierRef + // + labelSupplierRef.AutoSize = true; + labelSupplierRef.Location = new Point(16, 202); + labelSupplierRef.Name = "labelSupplierRef"; + labelSupplierRef.Size = new Size(73, 15); + labelSupplierRef.TabIndex = 12; + labelSupplierRef.Text = "Supplier Ref."; + // + // textBox1 + // + textBox1.DataBindings.Add(new Binding("Text", bsInvoice, "SupplierRef", true)); + textBox1.Location = new Point(118, 199); + textBox1.Name = "textBox1"; + textBox1.Size = new Size(215, 23); + textBox1.TabIndex = 11; + // + // dateTimeOrderDate + // + dateTimeOrderDate.Anchor = AnchorStyles.Top | AnchorStyles.Right; + dateTimeOrderDate.DataBindings.Add(new Binding("Value", bsInvoice, "PurchaseDate", true, DataSourceUpdateMode.Never)); + dateTimeOrderDate.Location = new Point(915, 51); + dateTimeOrderDate.Name = "dateTimeOrderDate"; + dateTimeOrderDate.Size = new Size(143, 23); + dateTimeOrderDate.TabIndex = 14; + // + // textBoxTotalAmount + // + textBoxTotalAmount.Anchor = AnchorStyles.Top | AnchorStyles.Right; + textBoxTotalAmount.DataBindings.Add(new Binding("Text", bsInvoice, "InvoiceGrossAmount", true)); + textBoxTotalAmount.Location = new Point(915, 167); + textBoxTotalAmount.Name = "textBoxTotalAmount"; + textBoxTotalAmount.Size = new Size(143, 23); + textBoxTotalAmount.TabIndex = 18; + // + // textBoxTaxAmount + // + textBoxTaxAmount.Anchor = AnchorStyles.Top | AnchorStyles.Right; + textBoxTaxAmount.DataBindings.Add(new Binding("Text", bsInvoice, "InvoiceTaxAmount", true)); + textBoxTaxAmount.Location = new Point(915, 138); + textBoxTaxAmount.Name = "textBoxTaxAmount"; + textBoxTaxAmount.Size = new Size(143, 23); + textBoxTaxAmount.TabIndex = 17; + // + // textBoxNetAmount + // + textBoxNetAmount.Anchor = AnchorStyles.Top | AnchorStyles.Right; + textBoxNetAmount.DataBindings.Add(new Binding("Text", bsInvoice, "InvoiceNetAmount", true)); + textBoxNetAmount.Location = new Point(915, 109); + textBoxNetAmount.Name = "textBoxNetAmount"; + textBoxNetAmount.Size = new Size(143, 23); + textBoxNetAmount.TabIndex = 16; + // + // label6 + // + label6.Anchor = AnchorStyles.Top | AnchorStyles.Right; + label6.AutoSize = true; + label6.Location = new Point(824, 83); + label6.Name = "label6"; + label6.Size = new Size(84, 15); + label6.TabIndex = 19; + label6.Text = "Order Channel"; + // + // label7 + // + label7.Anchor = AnchorStyles.Top | AnchorStyles.Right; + label7.AutoSize = true; + label7.Location = new Point(824, 141); + label7.Name = "label7"; + label7.Size = new Size(69, 15); + label7.TabIndex = 20; + label7.Text = "Tax amount"; + // + // label8 + // + label8.Anchor = AnchorStyles.Top | AnchorStyles.Right; + label8.AutoSize = true; + label8.Location = new Point(824, 112); + label8.Name = "label8"; + label8.Size = new Size(71, 15); + label8.TabIndex = 21; + label8.Text = "Net amount"; + // + // label + // + label.Anchor = AnchorStyles.Top | AnchorStyles.Right; + label.AutoSize = true; + label.Location = new Point(824, 57); + label.Name = "label"; + label.Size = new Size(64, 15); + label.TabIndex = 23; + label.Text = "Order Date"; + // + // label11 + // + label11.Anchor = AnchorStyles.Top | AnchorStyles.Right; + label11.AutoSize = true; + label11.Location = new Point(824, 170); + label11.Name = "label11"; + label11.Size = new Size(79, 15); + label11.TabIndex = 24; + label11.Text = "Total Amount"; + // + // dataGridView1 + // + dataGridView1.AllowUserToDeleteRows = false; + dataGridView1.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + dataGridView1.AutoGenerateColumns = false; + dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView1.Columns.AddRange(new DataGridViewColumn[] { itemDescriptionDataGridViewTextBoxColumn, statusDataGridViewTextBoxColumn, itemQuantityDataGridViewTextBoxColumn, PurchaseId, PurchaseLineId, ItemNet, ShippingNet, OtherNet, LineTotalTax, LineTotalGross }); + dataGridView1.DataSource = bsInvoiceLines; + dataGridView1.Location = new Point(16, 259); + dataGridView1.Name = "dataGridView1"; + dataGridView1.ReadOnly = true; + dataGridView1.RowTemplate.Height = 30; + dataGridView1.Size = new Size(1042, 264); + dataGridView1.TabIndex = 25; + // + // itemDescriptionDataGridViewTextBoxColumn + // + itemDescriptionDataGridViewTextBoxColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + itemDescriptionDataGridViewTextBoxColumn.DataPropertyName = "ItemDescription"; + itemDescriptionDataGridViewTextBoxColumn.HeaderText = "Description"; + itemDescriptionDataGridViewTextBoxColumn.Name = "itemDescriptionDataGridViewTextBoxColumn"; + itemDescriptionDataGridViewTextBoxColumn.ReadOnly = true; + // + // statusDataGridViewTextBoxColumn + // + statusDataGridViewTextBoxColumn.DataPropertyName = "Status"; + statusDataGridViewTextBoxColumn.HeaderText = "Status"; + statusDataGridViewTextBoxColumn.Name = "statusDataGridViewTextBoxColumn"; + statusDataGridViewTextBoxColumn.ReadOnly = true; + // + // itemQuantityDataGridViewTextBoxColumn + // + itemQuantityDataGridViewTextBoxColumn.DataPropertyName = "ItemQuantity"; + itemQuantityDataGridViewTextBoxColumn.HeaderText = "Qty."; + itemQuantityDataGridViewTextBoxColumn.MinimumWidth = 50; + itemQuantityDataGridViewTextBoxColumn.Name = "itemQuantityDataGridViewTextBoxColumn"; + itemQuantityDataGridViewTextBoxColumn.ReadOnly = true; + itemQuantityDataGridViewTextBoxColumn.Width = 50; + // + // PurchaseId + // + PurchaseId.DataPropertyName = "PurchaseId"; + PurchaseId.HeaderText = "PurchaseId"; + PurchaseId.Name = "PurchaseId"; + PurchaseId.ReadOnly = true; + PurchaseId.Visible = false; + // + // PurchaseLineId + // + PurchaseLineId.DataPropertyName = "PurchaseLineId"; + PurchaseLineId.HeaderText = "PurchaseLineId"; + PurchaseLineId.Name = "PurchaseLineId"; + PurchaseLineId.ReadOnly = true; + PurchaseLineId.Visible = false; + // + // ItemNet + // + ItemNet.DataPropertyName = "ItemNet"; + ItemNet.HeaderText = "Item"; + ItemNet.MinimumWidth = 60; + ItemNet.Name = "ItemNet"; + ItemNet.ReadOnly = true; + ItemNet.Width = 60; + // + // ShippingNet + // + ShippingNet.DataPropertyName = "ShippingNet"; + ShippingNet.HeaderText = "Ship"; + ShippingNet.MinimumWidth = 60; + ShippingNet.Name = "ShippingNet"; + ShippingNet.ReadOnly = true; + ShippingNet.Width = 60; + // + // OtherNet + // + OtherNet.DataPropertyName = "OtherNet"; + OtherNet.HeaderText = "Adjust"; + OtherNet.MinimumWidth = 60; + OtherNet.Name = "OtherNet"; + OtherNet.ReadOnly = true; + OtherNet.Width = 60; + // + // LineTotalTax + // + LineTotalTax.DataPropertyName = "LineTotalTax"; + LineTotalTax.HeaderText = "Tax"; + LineTotalTax.MinimumWidth = 60; + LineTotalTax.Name = "LineTotalTax"; + LineTotalTax.ReadOnly = true; + LineTotalTax.Width = 60; + // + // LineTotalGross + // + LineTotalGross.DataPropertyName = "LineTotalGross"; + LineTotalGross.HeaderText = "Total"; + LineTotalGross.MinimumWidth = 60; + LineTotalGross.Name = "LineTotalGross"; + LineTotalGross.ReadOnly = true; + LineTotalGross.Width = 60; + // + // bsInvoiceLines + // + bsInvoiceLines.DataMember = "InvoiceLines"; + bsInvoiceLines.DataSource = bsInvoice; + // + // textBoxOrderChannel + // + textBoxOrderChannel.Anchor = AnchorStyles.Top | AnchorStyles.Right; + textBoxOrderChannel.DataBindings.Add(new Binding("Text", bsInvoice, "PurchaseChannel", true)); + textBoxOrderChannel.Location = new Point(915, 80); + textBoxOrderChannel.Name = "textBoxOrderChannel"; + textBoxOrderChannel.Size = new Size(143, 23); + textBoxOrderChannel.TabIndex = 26; + // + // tabControl1 + // + tabControl1.Controls.Add(tabPageAccountTransactions); + tabControl1.Controls.Add(tabPageNotes); + tabControl1.Location = new Point(16, 541); + tabControl1.Name = "tabControl1"; + tabControl1.SelectedIndex = 0; + tabControl1.Size = new Size(1042, 197); + tabControl1.TabIndex = 27; + // + // tabPageAccountTransactions + // + tabPageAccountTransactions.Location = new Point(4, 24); + tabPageAccountTransactions.Name = "tabPageAccountTransactions"; + tabPageAccountTransactions.Padding = new Padding(3); + tabPageAccountTransactions.Size = new Size(1034, 169); + tabPageAccountTransactions.TabIndex = 0; + tabPageAccountTransactions.Text = "Account Transactions"; + tabPageAccountTransactions.UseVisualStyleBackColor = true; + // + // tabPageNotes + // + tabPageNotes.Location = new Point(4, 24); + tabPageNotes.Name = "tabPageNotes"; + tabPageNotes.Padding = new Padding(3); + tabPageNotes.Size = new Size(1034, 169); + tabPageNotes.TabIndex = 1; + tabPageNotes.Text = "Notes"; + tabPageNotes.UseVisualStyleBackColor = true; + // + // PurchaseInvoice + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1070, 750); + Controls.Add(tabControl1); + Controls.Add(textBoxOrderChannel); + Controls.Add(dataGridView1); + Controls.Add(label11); + Controls.Add(label); + Controls.Add(label8); + Controls.Add(label7); + Controls.Add(label6); + Controls.Add(textBoxTotalAmount); + Controls.Add(textBoxTaxAmount); + Controls.Add(textBoxNetAmount); + Controls.Add(dateTimeOrderDate); + Controls.Add(labelSupplierRef); + Controls.Add(textBox1); + Controls.Add(labelPurchaseInvoiceNumber); + Controls.Add(label5); + Controls.Add(textBoxUsername); + Controls.Add(label4); + Controls.Add(textBoxPaypalEmail); + Controls.Add(label3); + Controls.Add(textBoxPaypalUsername); + Controls.Add(label2); + Controls.Add(textBoxEbayEmail); + Controls.Add(label1); + Controls.Add(textBoxEbayUsername); + Name = "PurchaseInvoice"; + Text = "PurchaseInvoice"; + Load += PurchaseInvoice_Load; + ((System.ComponentModel.ISupportInitialize)bsInvoice).EndInit(); + ((System.ComponentModel.ISupportInitialize)bsContact).EndInit(); + ((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit(); + ((System.ComponentModel.ISupportInitialize)bsInvoiceLines).EndInit(); + tabControl1.ResumeLayout(false); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private BindingSource bsInvoice; + private TextBox textBoxEbayUsername; + private Label label1; + private Label label2; + private TextBox textBoxEbayEmail; + private Label label3; + private TextBox textBoxPaypalUsername; + private Label label4; + private TextBox textBoxPaypalEmail; + private Label label5; + private TextBox textBoxUsername; + private Label labelPurchaseInvoiceNumber; + private Label labelSupplierRef; + private TextBox textBox1; + private DateTimePicker dateTimeOrderDate; + private TextBox textBoxTotalAmount; + private TextBox textBoxTaxAmount; + private TextBox textBoxNetAmount; + private Label label6; + private Label label7; + private Label label8; + private Label label; + private Label label11; + private DataGridView dataGridView1; + private BindingSource bsContact; + private BindingSource bsInvoiceLines; + private DataGridViewTextBoxColumn itemDescriptionDataGridViewTextBoxColumn; + private DataGridViewTextBoxColumn statusDataGridViewTextBoxColumn; + private DataGridViewTextBoxColumn itemQuantityDataGridViewTextBoxColumn; + private DataGridViewTextBoxColumn PurchaseId; + private DataGridViewTextBoxColumn PurchaseLineId; + private DataGridViewTextBoxColumn ItemNet; + private DataGridViewTextBoxColumn ShippingNet; + private DataGridViewTextBoxColumn OtherNet; + private DataGridViewTextBoxColumn LineTotalTax; + private DataGridViewTextBoxColumn LineTotalGross; + private TextBox textBoxOrderChannel; + public TabControl tabControl1; + private TabPage tabPageAccountTransactions; + private TabPage tabPageNotes; + } +} \ No newline at end of file diff --git a/src/bnhtrade.gui/Forms/Account/PurchaseInvoice.cs b/src/bnhtrade.gui/Forms/Account/PurchaseInvoice.cs new file mode 100644 index 0000000..e034bb4 --- /dev/null +++ b/src/bnhtrade.gui/Forms/Account/PurchaseInvoice.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace bnhtrade.gui.Forms.Account +{ + public partial class PurchaseInvoice : Form + { + Core.Model.Account.PurchaseInvoice purchaseInvoice; + + public PurchaseInvoice(Core.Model.Account.PurchaseInvoice purchaseInvoice) + { + InitializeComponent(); + this.purchaseInvoice = purchaseInvoice; + } + + private void PurchaseInvoice_Load(object sender, EventArgs e) + { + bsInvoiceLines.DataSource = purchaseInvoice; + bsContact.DataSource = purchaseInvoice.Contact; + bsInvoice.DataSource = purchaseInvoice; + labelPurchaseInvoiceNumber.Text += purchaseInvoice.PurchaseNumber.ToString("D6"); + } + } +} diff --git a/src/bnhtrade.gui/Forms/Account/PurchaseInvoice.resx b/src/bnhtrade.gui/Forms/Account/PurchaseInvoice.resx new file mode 100644 index 0000000..371a720 --- /dev/null +++ b/src/bnhtrade.gui/Forms/Account/PurchaseInvoice.resx @@ -0,0 +1,150 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + + 149, 21 + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + 257, 21 + + \ No newline at end of file diff --git a/src/bnhtrade.gui/Form1.Designer.cs b/src/bnhtrade.gui/Home.Designer.cs similarity index 91% rename from src/bnhtrade.gui/Form1.Designer.cs rename to src/bnhtrade.gui/Home.Designer.cs index 1ad7482..ed278d1 100644 --- a/src/bnhtrade.gui/Form1.Designer.cs +++ b/src/bnhtrade.gui/Home.Designer.cs @@ -1,6 +1,6 @@ namespace bnhtrade.gui { - partial class Form1 + partial class Home { /// /// Required designer variable. @@ -41,7 +41,7 @@ purchaseLineIdDataGridViewTextBoxColumn = new DataGridViewTextBoxColumn(); lineStatusDataGridViewTextBoxColumn = new DataGridViewTextBoxColumn(); purchaseIdDataGridViewTextBoxColumn = new DataGridViewTextBoxColumn(); - bindingSource1 = new BindingSource(components); + bsReceivingLines = new BindingSource(components); buttonSearch = new Button(); comboBox1 = new ComboBox(); purchaseLineStatusBindingSource = new BindingSource(components); @@ -51,7 +51,7 @@ tabControl1.SuspendLayout(); Receiving.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit(); - ((System.ComponentModel.ISupportInitialize)bindingSource1).BeginInit(); + ((System.ComponentModel.ISupportInitialize)bsReceivingLines).BeginInit(); ((System.ComponentModel.ISupportInitialize)purchaseLineStatusBindingSource).BeginInit(); SuspendLayout(); // @@ -64,7 +64,7 @@ tabControl1.Location = new Point(12, 12); tabControl1.Name = "tabControl1"; tabControl1.SelectedIndex = 0; - tabControl1.Size = new Size(1010, 533); + tabControl1.Size = new Size(1022, 533); tabControl1.TabIndex = 0; tabControl1.SelectedIndexChanged += tabControl1_SelectedIndexChanged; // @@ -73,7 +73,7 @@ tabPage1.Location = new Point(4, 24); tabPage1.Name = "tabPage1"; tabPage1.Padding = new Padding(3); - tabPage1.Size = new Size(1002, 505); + tabPage1.Size = new Size(1014, 505); tabPage1.TabIndex = 0; tabPage1.Text = "Home"; tabPage1.UseVisualStyleBackColor = true; @@ -84,7 +84,7 @@ tabPage2.Location = new Point(4, 24); tabPage2.Name = "tabPage2"; tabPage2.Padding = new Padding(3); - tabPage2.Size = new Size(1002, 505); + tabPage2.Size = new Size(1014, 505); tabPage2.TabIndex = 1; tabPage2.Text = "FBA Shipments"; tabPage2.UseVisualStyleBackColor = true; @@ -101,7 +101,7 @@ Receiving.Location = new Point(4, 24); Receiving.Name = "Receiving"; Receiving.Padding = new Padding(3); - Receiving.Size = new Size(1002, 505); + Receiving.Size = new Size(1014, 505); Receiving.TabIndex = 2; Receiving.Text = "Receiving"; Receiving.UseVisualStyleBackColor = true; @@ -111,7 +111,7 @@ // labelDataGridCount.Anchor = AnchorStyles.Right; labelDataGridCount.ImageAlign = ContentAlignment.MiddleRight; - labelDataGridCount.Location = new Point(845, 70); + labelDataGridCount.Location = new Point(857, 70); labelDataGridCount.Name = "labelDataGridCount"; labelDataGridCount.RightToLeft = RightToLeft.Yes; labelDataGridCount.Size = new Size(129, 21); @@ -125,11 +125,14 @@ dataGridView1.AutoGenerateColumns = false; dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridView1.Columns.AddRange(new DataGridViewColumn[] { purchaseNumberDataGridViewTextBoxColumn, purchaseDateDataGridViewTextBoxColumn, itemDescriptionDataGridViewTextBoxColumn, purchaseLineIdDataGridViewTextBoxColumn, lineStatusDataGridViewTextBoxColumn, purchaseIdDataGridViewTextBoxColumn }); - dataGridView1.DataSource = bindingSource1; + dataGridView1.DataSource = bsReceivingLines; dataGridView1.Location = new Point(31, 94); + dataGridView1.MultiSelect = false; dataGridView1.Name = "dataGridView1"; - dataGridView1.Size = new Size(943, 396); + dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView1.Size = new Size(955, 396); dataGridView1.TabIndex = 5; + dataGridView1.DoubleClick += dataGridView1_DoubleClick; // // purchaseNumberDataGridViewTextBoxColumn // @@ -168,9 +171,9 @@ purchaseIdDataGridViewTextBoxColumn.HeaderText = "PurchaseId"; purchaseIdDataGridViewTextBoxColumn.Name = "purchaseIdDataGridViewTextBoxColumn"; // - // bindingSource1 + // bsReceivingLines // - bindingSource1.DataSource = typeof(Core.Model.Account.PurchaseInvoiceLineSummary); + bsReceivingLines.DataSource = typeof(Core.Model.Account.PurchaseInvoiceLineSummary); // // buttonSearch // @@ -224,20 +227,20 @@ textboxOrderSearch.TabIndex = 0; textboxOrderSearch.KeyPress += textboxOrderSearch_KeyPress; // - // Form1 + // Home // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1034, 557); + ClientSize = new Size(1046, 557); Controls.Add(tabControl1); - Name = "Form1"; + Name = "Home"; Text = "Form1"; Load += Form1_Load; tabControl1.ResumeLayout(false); Receiving.ResumeLayout(false); Receiving.PerformLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit(); - ((System.ComponentModel.ISupportInitialize)bindingSource1).EndInit(); + ((System.ComponentModel.ISupportInitialize)bsReceivingLines).EndInit(); ((System.ComponentModel.ISupportInitialize)purchaseLineStatusBindingSource).EndInit(); ResumeLayout(false); } @@ -255,7 +258,7 @@ private BindingSource purchaseLineStatusBindingSource; private Button buttonSearch; private DataGridView dataGridView1; - private BindingSource bindingSource1; + private BindingSource bsReceivingLines; private DataGridViewTextBoxColumn purchaseNumberDataGridViewTextBoxColumn; private DataGridViewTextBoxColumn purchaseDateDataGridViewTextBoxColumn; private DataGridViewTextBoxColumn itemDescriptionDataGridViewTextBoxColumn; diff --git a/src/bnhtrade.gui/Form1.cs b/src/bnhtrade.gui/Home.cs similarity index 70% rename from src/bnhtrade.gui/Form1.cs rename to src/bnhtrade.gui/Home.cs index 201889c..39117f8 100644 --- a/src/bnhtrade.gui/Form1.cs +++ b/src/bnhtrade.gui/Home.cs @@ -1,11 +1,13 @@ +using bnhtrade.gui.Forms.Account; + namespace bnhtrade.gui { - public partial class Form1 : Form + public partial class Home : Form { bool initTabReceiving = false; - public Form1() + public Home() { InitializeComponent(); } @@ -34,7 +36,7 @@ namespace bnhtrade.gui private void InitialiseTabReceiving() { Cursor.Current = Cursors.WaitCursor; - purchaseLineStatusBindingSource.DataSource = new Core.Logic.Account.PurchaseInvoice().ReadLineStatusToList(); + purchaseLineStatusBindingSource.DataSource = new Core.Logic.Account.PurchaseInvoiceMisc().ReadLineStatusToList(); comboBox1.SelectedIndex = 3; ListBoxQuery(); initTabReceiving = true; @@ -77,12 +79,12 @@ namespace bnhtrade.gui comboBox = comboBox1.Text; } - bindingSource1.DataSource = new Core.Logic.Account.PurchaseInvoice().GetLineSummary( + bsReceivingLines.DataSource = new Core.Logic.Account.PurchaseInvoiceMisc().GetLineSummary( dateTimeOrderSearch.Value , comboBox , searchList); - labelDataGridCount.Text = bindingSource1.Count.ToString(); + labelDataGridCount.Text = bsReceivingLines.Count.ToString(); } private void bindingSource1_CurrentChanged(object sender, EventArgs e) @@ -95,5 +97,18 @@ namespace bnhtrade.gui ListBoxQuery(); textboxOrderSearch.Select(); } + + private void dataGridView1_DoubleClick(object sender, EventArgs e) + { + var row = dataGridView1.CurrentCell.RowIndex; + var lineSummary = (bnhtrade.Core.Model.Account.PurchaseInvoiceLineSummary)bsReceivingLines[row]; + int purchaseId = lineSummary.PurchaseId; + var dbRead = new Core.Logic.Account.PurchaseInvoice(); + dbRead.PurchaseInvoiceIdList = new List { purchaseId }; + var dbresult = dbRead.Read(); + var purchaseInvoice = dbresult[purchaseId]; + var form = new PurchaseInvoice(purchaseInvoice); + form.Show(); + } } } diff --git a/src/bnhtrade.gui/Form1.resx b/src/bnhtrade.gui/Home.resx similarity index 97% rename from src/bnhtrade.gui/Form1.resx rename to src/bnhtrade.gui/Home.resx index 3431ac8..70d97fa 100644 --- a/src/bnhtrade.gui/Form1.resx +++ b/src/bnhtrade.gui/Home.resx @@ -117,7 +117,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + 250, 17 diff --git a/src/bnhtrade.gui/Program.cs b/src/bnhtrade.gui/Program.cs index 51d9543..ebc23e5 100644 --- a/src/bnhtrade.gui/Program.cs +++ b/src/bnhtrade.gui/Program.cs @@ -11,7 +11,7 @@ namespace bnhtrade.gui // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + Application.Run(new Home()); } } } \ No newline at end of file diff --git a/src/bnhtrade.gui/Properties/DataSources/bnhtrade.Core.Model.Account.Contact.datasource b/src/bnhtrade.gui/Properties/DataSources/bnhtrade.Core.Model.Account.Contact.datasource new file mode 100644 index 0000000..f0dd868 --- /dev/null +++ b/src/bnhtrade.gui/Properties/DataSources/bnhtrade.Core.Model.Account.Contact.datasource @@ -0,0 +1,10 @@ + + + + bnhtrade.Core.Model.Account.Contact, bnhtrade.Core, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + \ No newline at end of file From 0fb45b8090fc877c4cab7f71718a9f6a3a82e27c Mon Sep 17 00:00:00 2001 From: Bobbie Hodgetts Date: Sun, 12 May 2024 15:10:24 +0100 Subject: [PATCH 08/15] reading account journal complete --- .../Data/Database/Account/Journal.cs | 208 ++++++++++++++++++ .../Data/Database/Account/JournalType.cs | 144 ++++++++++++ .../Data/Database/Account/ReadAccountCode.cs | 36 ++- .../Data/Database/SqlWhereBuilder.cs | 21 ++ .../Logic/Account/GetAccountCodeInfo.cs | 2 +- src/bnhtrade.Core/Model/Account/Journal.cs | 65 ++++++ .../Model/Account/JournalType.cs | 43 ++++ src/bnhtrade.Core/Program.cs | 7 + src/bnhtrade.Core/Test/Account/Account.cs | 9 +- .../Test/_BoilerPlate/sql_Read.cs | 94 ++++++++ .../Forms/Account/PurchaseInvoice.Designer.cs | 10 +- .../Forms/Account/PurchaseInvoice.resx | 3 + 12 files changed, 626 insertions(+), 16 deletions(-) create mode 100644 src/bnhtrade.Core/Data/Database/Account/Journal.cs create mode 100644 src/bnhtrade.Core/Data/Database/Account/JournalType.cs create mode 100644 src/bnhtrade.Core/Model/Account/Journal.cs create mode 100644 src/bnhtrade.Core/Model/Account/JournalType.cs create mode 100644 src/bnhtrade.Core/Test/_BoilerPlate/sql_Read.cs diff --git a/src/bnhtrade.Core/Data/Database/Account/Journal.cs b/src/bnhtrade.Core/Data/Database/Account/Journal.cs new file mode 100644 index 0000000..26a5a94 --- /dev/null +++ b/src/bnhtrade.Core/Data/Database/Account/Journal.cs @@ -0,0 +1,208 @@ +using FikaAmazonAPI.AmazonSpApiSDK.Models.CatalogItems; +using System; +using System.Collections.Generic; +using System.Data.SqlClient; +using System.Linq; +using System.Runtime.InteropServices.Marshalling; +using System.Text; +using System.Threading.Tasks; +using static System.ComponentModel.Design.ObjectSelectorEditor; + +namespace bnhtrade.Core.Data.Database.Account +{ + internal class Journal : Connection + { + private bnhtrade.Core.Data.Database.SqlWhereBuilder sqlBuilder; + + /// + /// Results filter + /// + public List AccountJournalId { get; set; } + + public Journal() + { + Init(); + } + + public void Init() + { + sqlBuilder = new SqlWhereBuilder(); + AccountJournalId = new List(); + } + + /// + /// + /// + /// Dictionary were key is the table primary key + public Dictionary Read() + { + sqlBuilder.Init(); + + //build sql query + string sql = @" + SELECT tblAccountJournal.AccountJournalID + ,tblAccountJournal.AccountJournalTypeID + ,tblAccountJournal.EntryDate + ,tblAccountJournal.PostDate + ,tblAccountJournal.LastModified + ,tblAccountJournal.IsLocked + ,tblAccountJournalPost.AccountJournalPostID + ,tblAccountJournalPost.AccountChartOfID + ,tblAccountJournalPost.AmountGbp + FROM tblAccountJournal + INNER JOIN tblAccountJournalPost ON tblAccountJournal.AccountJournalID = tblAccountJournalPost.AccountJournalID + WHERE 1 = 1 "; + + // build the where statments + if (AccountJournalId.Any()) + { + sqlBuilder.In("tblAccountJournal.AccountJournalID", AccountJournalId, "AND"); + } + + // append where string to the sql + if (sqlBuilder.IsSetSqlWhereString) + { + sql = sql + sqlBuilder.SqlWhereString; + } + + // build tuple list + var dbJournalList = new List<( + uint AccountJournalId + , uint AccountJournalTypeId + , DateTime EntryDate + , DateTime PostDate + , DateTime LastModified + , bool IsLocked + )>(); + + var dbJournalPostList = new List<( + uint AccountJournalId + , uint AccountJournalPostId + , uint AccountChartOfId + , decimal AmountGbp + )>(); + + + bool hasRows = false; + + 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) + { + hasRows = true; + uint lastJournalId = 0; + while (reader.Read()) + { + // read journal header + uint journalId = (uint)reader.GetInt32(0); + if (journalId != lastJournalId) + { + lastJournalId = journalId; + + (uint AccountJournalId + , uint AccountJournalTypeId + , DateTime EntryDate + , DateTime PostDate + , DateTime LastModified + , bool IsLocked + ) + journal = + ( journalId + , (uint)reader.GetInt32(1) + , DateTime.SpecifyKind(reader.GetDateTime(2), DateTimeKind.Utc) + , DateTime.SpecifyKind(reader.GetDateTime(3), DateTimeKind.Utc) + , DateTime.SpecifyKind(reader.GetDateTime(4), DateTimeKind.Utc) + , reader.GetBoolean(5) + ); + + dbJournalList.Add(journal); + } + + // read journal posts + (uint AccountJournalId + , uint AccountJournalPostId + , uint AccountChartOfId + , decimal AmountGbp + ) + journalPost = + ( journalId + , (uint)reader.GetInt32(6) + , (uint)reader.GetInt32(7) + , reader.GetDecimal(8) + ); + + dbJournalPostList.Add(journalPost); + } + } + } + } + } + + var returnList = new Dictionary(); + if (hasRows) + { + // build lists to filter db results by + var journalTypeIdList = new List(); + var accountIdList = new List(); + foreach (var item in dbJournalList) + { + journalTypeIdList.Add(item.AccountJournalTypeId); + } + foreach (var item in dbJournalPostList) + { + accountIdList.Add(item.AccountChartOfId); + } + + // get journalTypes from db + var dbJournalType = new Data.Database.Account.JournalType(); + dbJournalType.IdList = journalTypeIdList; + var journalTypeDict = dbJournalType.Read(); + + // get accounts from db + var dbAccount = new Data.Database.Account.ReadAccountCode(); + var accountDict = dbAccount.ByAccountId(accountIdList); + + // build final return dictionary + foreach (var dbJournal in dbJournalList) + { + // build posts + var newPosts = new List(); + foreach (var dbJournalPost in dbJournalPostList) + { + if (dbJournalPost.AccountJournalId == dbJournal.AccountJournalId) + { + var newPost = new Core.Model.Account.Journal.Post( + dbJournalPost.AccountJournalPostId + , accountDict[dbJournalPost.AccountChartOfId] + , dbJournalPost.AmountGbp); + + newPosts.Add(newPost); + } + } + + // create the journal + var newJournal = new Core.Model.Account.Journal( + dbJournal.AccountJournalId + , journalTypeDict[dbJournal.AccountJournalTypeId] + , newPosts + , dbJournal.EntryDate + , dbJournal.PostDate + , dbJournal.LastModified + , dbJournal.IsLocked); + + returnList.Add(dbJournal.AccountJournalId, newJournal); + } + } + // all done, return the list herevar + return returnList; + } + } +} diff --git a/src/bnhtrade.Core/Data/Database/Account/JournalType.cs b/src/bnhtrade.Core/Data/Database/Account/JournalType.cs new file mode 100644 index 0000000..a39ad80 --- /dev/null +++ b/src/bnhtrade.Core/Data/Database/Account/JournalType.cs @@ -0,0 +1,144 @@ +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 JournalType : Connection + { + private bnhtrade.Core.Data.Database.SqlWhereBuilder sqlBuilder; + + /// + /// Results filter + /// + public List IdList { get; set; } + + /// + /// Searches for the specificed phases within the item description. Uses the LIKE AND sql function + /// + public List TitleList { get; set; } + + public JournalType() + { + Init(); + } + + public void Init() + { + sqlBuilder = new SqlWhereBuilder(); + IdList = new List(); + TitleList = new List(); + } + + /// + /// + /// + /// Dictionary where key is the table primary key + public Dictionary Read() + { + // create the return (emptyP list) here + var returnList = new Dictionary(); + sqlBuilder.Init(); + + //build sql query + string sql = @" + SELECT [AccountJournalTypeID] + ,[TypeTitle] + ,[ChartOfAccountID_Debit] + ,[ChartOfAccountID_Credit] + FROM [e2A].[dbo].[tblAccountJournalType] + WHERE 1 = 1 "; + + // build the where statments + if (IdList.Any()) + { + sqlBuilder.In("AccountJournalTypeID", IdList, "AND"); + } + if (TitleList.Any()) + { + sqlBuilder.In("TypeTitle", TitleList, "AND"); + } + + // append where string to the sql + if (sqlBuilder.IsSetSqlWhereString) + { + sql = sql + sqlBuilder.SqlWhereString; + } + + // create dictionary to add credit/debit accounts on after db read + var creditDict = new Dictionary(); + var debitDict = new Dictionary(); + + 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()) + { + // read from db and create object + uint journalTypeId = (uint)reader.GetInt32(0); + string title = reader.GetString(1); + int? debitAccountId = null; + if (!reader.IsDBNull(2)) { debitAccountId = reader.GetInt32(2); } + int? creditAccountId = null; + if (!reader.IsDBNull(3)) { creditAccountId = reader.GetInt32(3); } + + // build return list + var item = new Model.Account.JournalType(journalTypeId, title); + returnList.Add(journalTypeId, item); + + // build dictionaries + if (debitAccountId != null) + { + debitDict.Add(journalTypeId, (uint)debitAccountId); + } + if (creditAccountId != null) + { + creditDict.Add(journalTypeId, (uint)creditAccountId); + } + } + } + } + } + } + // get account objects from db + var accountIdList = debitDict.Values.ToList(); + accountIdList.AddRange(creditDict.Values.ToList()); + var dbaccount = new Data.Database.Account.ReadAccountCode(); + var dbDict = dbaccount.ByAccountId(accountIdList); + + // add to the returnlist + foreach (var account in returnList.Values) + { + Model.Account.Account debitAccount = null; + if (debitDict.ContainsKey(account.JournalTypeId)) + { + debitAccount = dbDict[debitDict[account.JournalTypeId]]; + } + + Model.Account.Account creditAccount = null; + if (creditDict.ContainsKey(account.JournalTypeId)) + { + creditAccount = dbDict[creditDict[account.JournalTypeId]]; // key of 59 needed + } + + account.AddDefaultAccounts(creditAccount, debitAccount); + } + + // all done, return the list here + return returnList; + } + } +} + diff --git a/src/bnhtrade.Core/Data/Database/Account/ReadAccountCode.cs b/src/bnhtrade.Core/Data/Database/Account/ReadAccountCode.cs index 814d552..ba238a7 100644 --- a/src/bnhtrade.Core/Data/Database/Account/ReadAccountCode.cs +++ b/src/bnhtrade.Core/Data/Database/Account/ReadAccountCode.cs @@ -10,7 +10,6 @@ namespace bnhtrade.Core.Data.Database.Account public class ReadAccountCode : Connection { private Data.Database.SqlWhereBuilder sqlWhere = new SqlWhereBuilder(); - private List resultList; public ReadAccountCode() { @@ -27,26 +26,45 @@ namespace bnhtrade.Core.Data.Database.Account var dictionary = new Dictionary(); foreach (var item in list) { - dictionary.Add(item.Id, item); + dictionary.Add(item.Value.Id, item.Value); } return dictionary; } - public List ByAccountCode(List accountCodeList) + public Dictionary ByAccountId(List accountIdList) { Innit(); + var resultDict = new Dictionary(); + + if (accountIdList == null || !accountIdList.Any()) + { + return resultDict; + } + + sqlWhere.In("tblAccountChartOf.AccountChartOfID", accountIdList, " WHERE "); + resultDict = Execute(sqlWhere.SqlWhereString, sqlWhere.ParameterList); + return resultDict; + } + + public Dictionary ByAccountCode(List accountCodeList) + { + Innit(); + var resultDict = new Dictionary(); if (accountCodeList == null || !accountCodeList.Any()) { - return resultList; + return resultDict; } sqlWhere.In("tblAccountChartOf.AccountCode", accountCodeList, " WHERE "); - return Execute(sqlWhere.SqlWhereString, sqlWhere.ParameterList); + resultDict = Execute(sqlWhere.SqlWhereString, sqlWhere.ParameterList); + return resultDict; } - private List Execute(string sqlWhere, Dictionary parameters) + private Dictionary Execute(string sqlWhere, Dictionary parameters) { + var resultDict = new Dictionary(); + //build sql query string sqlString = @" SELECT tblAccountChartOf.AccountChartOfID @@ -91,18 +109,18 @@ namespace bnhtrade.Core.Data.Database.Account int multiplier = reader.GetInt32(6); var result = new Model.Account.Account(tablePk, accountCode, title, description, type, basicType, multiplier); - resultList.Add(result); + resultDict.Add(tablePk, result); } } - return resultList; } } } + return resultDict; } private void Innit() { - resultList = new List(); + sqlWhere.Init(); } } } diff --git a/src/bnhtrade.Core/Data/Database/SqlWhereBuilder.cs b/src/bnhtrade.Core/Data/Database/SqlWhereBuilder.cs index c75213c..812e4a7 100644 --- a/src/bnhtrade.Core/Data/Database/SqlWhereBuilder.cs +++ b/src/bnhtrade.Core/Data/Database/SqlWhereBuilder.cs @@ -209,5 +209,26 @@ namespace bnhtrade.Core.Data.Database In(columnReference, stringList, wherePrefix); } + + /// + /// Append an 'In' statement and parameter list to the class properties + /// + /// Name of the column to used to for the condition statement + /// List of values to test in condition statement + /// Optional prefix that gets added to the sql string result + public void In(string columnReference, List orValueList, string wherePrefix = null) + { + var stringList = new List(); + + if (orValueList != null || !orValueList.Any()) + { + foreach (uint value in orValueList) + { + stringList.Add(value.ToString()); + } + } + + In(columnReference, stringList, wherePrefix); + } } } diff --git a/src/bnhtrade.Core/Logic/Account/GetAccountCodeInfo.cs b/src/bnhtrade.Core/Logic/Account/GetAccountCodeInfo.cs index 9e08fac..d2019f4 100644 --- a/src/bnhtrade.Core/Logic/Account/GetAccountCodeInfo.cs +++ b/src/bnhtrade.Core/Logic/Account/GetAccountCodeInfo.cs @@ -35,7 +35,7 @@ namespace bnhtrade.Core.Logic.Account public List ByAccountCode(List accountCodeList) { - return readAccountCode.ByAccountCode(accountCodeList); + return readAccountCode.ByAccountCode(accountCodeList).Values.ToList(); } public Dictionary ConvertToDictionary(List accountCodeList) diff --git a/src/bnhtrade.Core/Model/Account/Journal.cs b/src/bnhtrade.Core/Model/Account/Journal.cs new file mode 100644 index 0000000..3ddbdb2 --- /dev/null +++ b/src/bnhtrade.Core/Model/Account/Journal.cs @@ -0,0 +1,65 @@ +using Microsoft.VisualBasic; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace bnhtrade.Core.Model.Account +{ + public class Journal : IValidatableObject + { + internal Journal(uint journalId, Core.Model.Account.JournalType type, List posts, DateTime entryDate, DateTime postDate, DateTime lastModifed, bool isLocked) + { + JournalId = journalId; + Type = type; + Posts = posts; + EntryDate = entryDate; + PostDate = postDate; + LastModified = lastModifed; + IsLocked = isLocked; + } + + public uint JournalId { get; private set; } + public Core.Model.Account.JournalType Type { get; private set; } + public List Posts { get; private set; } = new List(); + public DateTime EntryDate { get; private set; } + public DateTime PostDate { get; private set; } + public DateTime LastModified { get;private set; } + public bool IsLocked { get; private set; } + + public class Post + { + internal Post(uint postId, Core.Model.Account.Account account, decimal amountGbp) + { + PostId = postId; + Account = account; + AmountGbp = amountGbp; + } + + public uint PostId { get; private set; } + public Core.Model.Account.Account Account { get; private set; } + public decimal AmountGbp { get; private set; } + } + + public IEnumerable Validate(ValidationContext validationContext) + { + var result = new List(); + + // get total of posts + decimal postTotal = 0; + foreach (var post in Posts) + { + postTotal = postTotal + post.AmountGbp; + } + if (postTotal != 0) + { + result.Add(new ValidationResult("Account journal posts do not equal zero")); + } + + throw new NotImplementedException(); + return result; + } + } +} diff --git a/src/bnhtrade.Core/Model/Account/JournalType.cs b/src/bnhtrade.Core/Model/Account/JournalType.cs new file mode 100644 index 0000000..e31c717 --- /dev/null +++ b/src/bnhtrade.Core/Model/Account/JournalType.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace bnhtrade.Core.Model.Account +{ + public class JournalType + { + internal JournalType(uint journalTypeId, string title, Model.Account.Account defaultCreditAccount = null, Model.Account.Account defaultDebitAccount = null) + { + JournalTypeId = journalTypeId; + Title = title; + DefaultCreditAccount = defaultCreditAccount; + DefaultDebitAccount = defaultDebitAccount; + } + + internal void AddDefaultAccounts(Model.Account.Account defaultCreditAccount = null, Model.Account.Account defaultDebitAccount = null) + { + DefaultCreditAccount = defaultCreditAccount; + DefaultDebitAccount = defaultDebitAccount; + } + + public uint JournalTypeId { get ; private set; } + + public string Title { get; private set; } + + public Model.Account.Account DefaultDebitAccount { get; private set; } + + public bool IsSetDefaultDebitAccount + { + get { return DefaultDebitAccount != null; } + } + + public Model.Account.Account DefaultCreditAccount { get; private set; } + + public bool IsSetDefaultCreditAccount + { + get { return DefaultCreditAccount != null; } + } + } +} diff --git a/src/bnhtrade.Core/Program.cs b/src/bnhtrade.Core/Program.cs index d3549e3..41d77ea 100644 --- a/src/bnhtrade.Core/Program.cs +++ b/src/bnhtrade.Core/Program.cs @@ -233,6 +233,7 @@ namespace bnhtrade.Core { public class AccountQuery { + // externally called & internal public static decimal CurrencyConvertToGbp(string sqlConnectionString, string currencyCode, decimal amount, DateTime conversionDate) { if (currencyCode == "GBP" || amount == 0M) @@ -288,6 +289,7 @@ namespace bnhtrade.Core } } + // externally called public static int CurrencyExchangeRateInsert(string sqlConnectionString, int exchangeRateSource, string currencyCode, decimal currencyUnitsPerGbp, DateTime periodStart, DateTime periodEnd, bool checkOverride = false) { @@ -420,6 +422,7 @@ namespace bnhtrade.Core } } + // internally called public static bool AccountJournalEntryIsLocked(string sqlConnectionString, int journalId) { using (SqlConnection conn = new SqlConnection(sqlConnectionString)) @@ -449,6 +452,7 @@ namespace bnhtrade.Core } } + // externally called public static int AccountJournalInsert(string sqlConnectionString, int journalTypeId, DateTime entryDate, string currencyCode, decimal amount, int debitAccountId = 0, int creditAccountId = 0, bool lockEntry = false) { @@ -492,6 +496,7 @@ namespace bnhtrade.Core } } + // externally called // return false on locked journal entry public static bool AccountJournalDelete(string sqlConnectionString, int accountJournalId) { @@ -540,6 +545,7 @@ namespace bnhtrade.Core } } + // internally called private static bool AccountJournalPostInsert(string sqlConnectionString, int journalId, DateTime entryDate, string currencyCode, decimal amount, int debitAccountId = 0, int creditAccountId = 0) { @@ -685,6 +691,7 @@ namespace bnhtrade.Core } } + // externally called public static bool AccountJournalPostUpdate(string sqlConnectionString, int journalId, string currencyCode, decimal amount, int debitAccountId = 0, int creditAccountId = 0) { diff --git a/src/bnhtrade.Core/Test/Account/Account.cs b/src/bnhtrade.Core/Test/Account/Account.cs index b1a2459..10d15cc 100644 --- a/src/bnhtrade.Core/Test/Account/Account.cs +++ b/src/bnhtrade.Core/Test/Account/Account.cs @@ -11,7 +11,7 @@ namespace bnhtrade.Core.Test.Account { public Account() { - PurchaseInvoiceLine(); + Journal(); } public void PurchaseInvoice() @@ -27,5 +27,12 @@ namespace bnhtrade.Core.Test.Account read.ItemDescription = new List { "xbox", "kill" }; var result = read.Read(); } + + public void Journal() + { + var read = new Data.Database.Account.Journal(); + read.AccountJournalId = new List { 123, 300, 324, 5678, 22 }; + var result = read.Read(); + } } } diff --git a/src/bnhtrade.Core/Test/_BoilerPlate/sql_Read.cs b/src/bnhtrade.Core/Test/_BoilerPlate/sql_Read.cs new file mode 100644 index 0000000..7121986 --- /dev/null +++ b/src/bnhtrade.Core/Test/_BoilerPlate/sql_Read.cs @@ -0,0 +1,94 @@ +using bnhtrade.Core.Data.Database; +using System; +using System.Collections.Generic; +using System.Data.SqlClient; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace bnhtrade.Core.Test._BoilerPlate +{ + internal class xxxxxxxYourClassNameHerexxxxxxxx : Connection + { + private bnhtrade.Core.Data.Database.SqlWhereBuilder sqlBuilder; + + /// + /// Results filter + /// + public List ColumnTitle1List { get; set; } + + /// + /// Searches for the specificed phases within the item description. Uses the LIKE AND sql function + /// + public List ColumnTitle2List { get; set; } + + public xxxxxxxYourClassNameHerexxxxxxxx() + { + Init(); + } + + public void Init() + { + sqlBuilder = new SqlWhereBuilder(); + ColumnTitle1List = new List(); + ColumnTitle2List = new List(); + } + + /// + /// + /// + /// Dictionary were key is the table primary key + public Dictionary Read() + { + // create the return (emptyP list) here + var returnList = new Dictionary(); + sqlBuilder.Init(); + + //build sql query + string sql = @" + SELECT item1, item2, item3 + FROM tblPurchaseLine + WHERE 1 = 1 "; + + // build the where statments + if (ColumnTitle1List.Any()) + { + sqlBuilder.In("xxxxxxxxxxxxxxColumnTitle1xxxxxxxxxxxxxxxxxx", ColumnTitle1List, "AND"); + } + if (ColumnTitle2List.Any()) + { + sqlBuilder.In("xxxxxxxxxxxxxxColumnTitle2xxxxxxxxxxxxxxxxxx", ColumnTitle2List, "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()) + { + // read from db and create object + // and add to return list + } + } + } + } + } + // all done, return the list here + return returnList; + } + } +} diff --git a/src/bnhtrade.gui/Forms/Account/PurchaseInvoice.Designer.cs b/src/bnhtrade.gui/Forms/Account/PurchaseInvoice.Designer.cs index f307d5e..987f6a2 100644 --- a/src/bnhtrade.gui/Forms/Account/PurchaseInvoice.Designer.cs +++ b/src/bnhtrade.gui/Forms/Account/PurchaseInvoice.Designer.cs @@ -294,7 +294,7 @@ dataGridView1.Name = "dataGridView1"; dataGridView1.ReadOnly = true; dataGridView1.RowTemplate.Height = 30; - dataGridView1.Size = new Size(1042, 264); + dataGridView1.Size = new Size(1042, 280); dataGridView1.TabIndex = 25; // // itemDescriptionDataGridViewTextBoxColumn @@ -400,10 +400,10 @@ // tabControl1.Controls.Add(tabPageAccountTransactions); tabControl1.Controls.Add(tabPageNotes); - tabControl1.Location = new Point(16, 541); + tabControl1.Location = new Point(16, 561); tabControl1.Name = "tabControl1"; tabControl1.SelectedIndex = 0; - tabControl1.Size = new Size(1042, 197); + tabControl1.Size = new Size(1042, 232); tabControl1.TabIndex = 27; // // tabPageAccountTransactions @@ -411,7 +411,7 @@ tabPageAccountTransactions.Location = new Point(4, 24); tabPageAccountTransactions.Name = "tabPageAccountTransactions"; tabPageAccountTransactions.Padding = new Padding(3); - tabPageAccountTransactions.Size = new Size(1034, 169); + tabPageAccountTransactions.Size = new Size(1034, 204); tabPageAccountTransactions.TabIndex = 0; tabPageAccountTransactions.Text = "Account Transactions"; tabPageAccountTransactions.UseVisualStyleBackColor = true; @@ -430,7 +430,7 @@ // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1070, 750); + ClientSize = new Size(1070, 805); Controls.Add(tabControl1); Controls.Add(textBoxOrderChannel); Controls.Add(dataGridView1); diff --git a/src/bnhtrade.gui/Forms/Account/PurchaseInvoice.resx b/src/bnhtrade.gui/Forms/Account/PurchaseInvoice.resx index 371a720..856c4dd 100644 --- a/src/bnhtrade.gui/Forms/Account/PurchaseInvoice.resx +++ b/src/bnhtrade.gui/Forms/Account/PurchaseInvoice.resx @@ -123,6 +123,9 @@ 149, 21 + + 149, 21 + True From 1c7ed5da9360ef253e058fb9ee21c7d18d2880c5 Mon Sep 17 00:00:00 2001 From: Bobbie Hodgetts Date: Sun, 12 May 2024 16:22:53 +0100 Subject: [PATCH 09/15] wip --- src/bnhtrade.ComTypeLib/Account/Account.cs | 8 +- .../Data/Database/Account/CreateJournal.cs | 208 +++++++ .../Data/Database/Account/Currency.cs | 199 +++++++ .../Data/Database/Account/DeleteJournal.cs | 64 +++ .../Account/{Contact.cs => ReadContact.cs} | 4 +- .../Account/{Journal.cs => ReadJournal.cs} | 42 +- .../{JournalType.cs => ReadJournalType.cs} | 4 +- ...chaseInvoice.cs => ReadPurchaseInvoice.cs} | 8 +- ...oiceLine.cs => ReadPurchaseInvoiceLine.cs} | 4 +- ...us.cs => ReadPurchaseInvoiceLineStatus.cs} | 2 +- ...y.cs => ReadPurchaseInvoiceLineSummary.cs} | 2 +- .../Data/Database/Account/UpdateJournal.cs | 75 +++ src/bnhtrade.Core/Logic/Account/Currency.cs | 23 + src/bnhtrade.Core/Logic/Account/Journal.cs | 25 + .../Logic/Account/PurchaseInvoice.cs | 2 +- .../Logic/Account/PurchaseInvoiceMisc.cs | 4 +- src/bnhtrade.Core/Program.cs | 539 +----------------- src/bnhtrade.Core/Test/Account/Account.cs | 6 +- 18 files changed, 660 insertions(+), 559 deletions(-) create mode 100644 src/bnhtrade.Core/Data/Database/Account/CreateJournal.cs create mode 100644 src/bnhtrade.Core/Data/Database/Account/Currency.cs create mode 100644 src/bnhtrade.Core/Data/Database/Account/DeleteJournal.cs rename src/bnhtrade.Core/Data/Database/Account/{Contact.cs => ReadContact.cs} (98%) rename src/bnhtrade.Core/Data/Database/Account/{Journal.cs => ReadJournal.cs} (84%) rename src/bnhtrade.Core/Data/Database/Account/{JournalType.cs => ReadJournalType.cs} (98%) rename src/bnhtrade.Core/Data/Database/Account/{PurchaseInvoice.cs => ReadPurchaseInvoice.cs} (96%) rename src/bnhtrade.Core/Data/Database/Account/{PurchaseInvoiceLine.cs => ReadPurchaseInvoiceLine.cs} (98%) rename src/bnhtrade.Core/Data/Database/Account/{PurchaseInvoiceLineStatus.cs => ReadPurchaseInvoiceLineStatus.cs} (96%) rename src/bnhtrade.Core/Data/Database/Account/{PurchaseInvoiceLineSummary.cs => ReadPurchaseInvoiceLineSummary.cs} (98%) create mode 100644 src/bnhtrade.Core/Data/Database/Account/UpdateJournal.cs create mode 100644 src/bnhtrade.Core/Logic/Account/Currency.cs create mode 100644 src/bnhtrade.Core/Logic/Account/Journal.cs diff --git a/src/bnhtrade.ComTypeLib/Account/Account.cs b/src/bnhtrade.ComTypeLib/Account/Account.cs index 3fd7a77..7d42ea3 100644 --- a/src/bnhtrade.ComTypeLib/Account/Account.cs +++ b/src/bnhtrade.ComTypeLib/Account/Account.cs @@ -35,26 +35,26 @@ namespace bnhtrade.ComTypeLib public int AccountJournalInsert(ConnectionCredential sqlConnCred, int journalTypeId, DateTime entryDate, string currencyCode, [MarshalAs(UnmanagedType.Currency)] decimal amount, int debitAccountId = 0, int creditAccountId = 0, bool lockEntry = false) { - return Core.Account.AccountQuery.AccountJournalInsert(sqlConnCred.ConnectionString, journalTypeId, entryDate, + return new Core.Logic.Account.Journal().AccountJournalInsert(journalTypeId, entryDate, currencyCode, amount, debitAccountId, creditAccountId, lockEntry); } public bool AccountJournalDelete(ConnectionCredential sqlConnCred, int accountJournalId) { - return Core.Account.AccountQuery.AccountJournalDelete(sqlConnCred.ConnectionString, accountJournalId); + return new Core.Logic.Account.Journal().AccountJournalDelete(accountJournalId); } [return: MarshalAs(UnmanagedType.Currency)] public decimal CurrencyConvertToGbp(ConnectionCredential sqlConnCred, string currencyCode, [MarshalAs(UnmanagedType.Currency)] decimal amount, DateTime conversionDate) { - return Core.Account.AccountQuery.CurrencyConvertToGbp(sqlConnCred.ConnectionString, currencyCode, amount, conversionDate); + return new Core.Logic.Account.Currency().CurrencyConvertToGbp(currencyCode, amount, conversionDate); } public int CurrencyExchangeRateInsert(ConnectionCredential sqlConnCred, int exchangeRateSource, string currencyCode, [MarshalAs(UnmanagedType.Currency)] decimal currencyUnitsPerGbp, DateTime periodStart, DateTime periodEnd, bool checkOverride = false) { - return Core.Account.AccountQuery.CurrencyExchangeRateInsert(sqlConnCred.ConnectionString, exchangeRateSource, currencyCode, + return new Core.Logic.Account.Currency().CurrencyExchangeRateInsert(exchangeRateSource, currencyCode, currencyUnitsPerGbp, periodStart, periodEnd, checkOverride); } } diff --git a/src/bnhtrade.Core/Data/Database/Account/CreateJournal.cs b/src/bnhtrade.Core/Data/Database/Account/CreateJournal.cs new file mode 100644 index 0000000..01a4f04 --- /dev/null +++ b/src/bnhtrade.Core/Data/Database/Account/CreateJournal.cs @@ -0,0 +1,208 @@ +using System; +using System.Collections.Generic; +using System.Data.SqlClient; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Transactions; + +namespace bnhtrade.Core.Data.Database.Account +{ + internal class CreateJournal : Connection + { + /// + /// Old code needs sorting + /// + public int AccountJournalInsert(int journalTypeId, DateTime entryDate, string currencyCode, + decimal amount, int debitAccountId = 0, int creditAccountId = 0, bool lockEntry = false) + { + int defaultDebit = 0; + int defaultCredit = 0; + + // ensure date is UTC + entryDate = DateTime.SpecifyKind(entryDate, DateTimeKind.Utc); + + // debit and credit locks are checked in journal post method + using (TransactionScope scope = new TransactionScope()) + using (SqlConnection conn = new SqlConnection(SqlConnectionString)) + { + conn.Open(); + + // insert the journal entry + int journalId; + + using (SqlCommand cmd = new SqlCommand(@" + INSERT INTO tblAccountJournal + (AccountJournalTypeID, EntryDate, IsLocked) + OUTPUT INSERTED.AccountJournalID + VALUES + (@journalTypeId, @entryDate, @lockEntry) + ", conn)) + { + // add parameters + cmd.Parameters.AddWithValue("@journalTypeId", journalTypeId); + cmd.Parameters.AddWithValue("@entryDate", entryDate.ToUniversalTime()); + cmd.Parameters.AddWithValue("@lockEntry", lockEntry); + + //execute + journalId = (int)cmd.ExecuteScalar(); + } + + // insert journal entries + //bool postResult = AccountJournalPostInsert(sqlConnectionString, journalId, entryDate, currencyCode, amount, debitAccountId, creditAccountId); + bool postResult = AccountJournalPostInsert(journalId, entryDate, currencyCode, amount, debitAccountId, creditAccountId); + + scope.Complete(); + return journalId; + } + } + + /// + /// Old code needs sorting + /// + internal bool AccountJournalPostInsert(int journalId, DateTime entryDate, + string currencyCode, decimal amount, int debitAccountId = 0, int creditAccountId = 0) + { + int defaultDebit; + int defaultCredit; + entryDate = DateTime.SpecifyKind(entryDate, DateTimeKind.Utc); + + using (TransactionScope scope = new TransactionScope()) + using (SqlConnection conn = new SqlConnection(SqlConnectionString)) + { + conn.Open(); + + // ensure their are no other entries + using (SqlCommand cmd = new SqlCommand(@" + SELECT + Count(tblAccountJournalPost.AccountJournalPostID) AS CountOfAccountJournalPostID + FROM + tblAccountJournalPost + WHERE + (((tblAccountJournalPost.AccountJournalID)=@AccountJournalID)); + ", conn)) + { + cmd.Parameters.AddWithValue("@AccountJournalID", journalId); + + int count = (int)cmd.ExecuteScalar(); + + if (count > 0) + { + throw new Exception("Unable the insert journal posts, post already present AccountJournalID=" + journalId); + } + } + + //checks + using (SqlCommand cmd = new SqlCommand(@" + SELECT + tblAccountJournalType.ChartOfAccountID_Debit, tblAccountJournalType.ChartOfAccountID_Credit + FROM + tblAccountJournal + INNER JOIN tblAccountJournalType + ON tblAccountJournal.AccountJournalTypeID = tblAccountJournalType.AccountJournalTypeID + WHERE + (((tblAccountJournal.AccountJournalID)=@journalId)); + ", conn)) + { + cmd.Parameters.AddWithValue("@journalId", journalId); + + using (SqlDataReader reader = cmd.ExecuteReader()) + { + if (reader.Read()) + { + // debit check + if (reader.IsDBNull(0)) + { + if (debitAccountId == 0) + { + throw new Exception("Debit Account ID required, default not set for journal type"); + } + } + else + { + defaultDebit = reader.GetInt32(0); + if (debitAccountId == 0) + { + debitAccountId = defaultDebit; + } + else if (debitAccountId != defaultDebit) + { + throw new Exception("Debit Account ID supplied does not match default set for journal type"); + } + + } + // credit check + if (reader.IsDBNull(1)) + { + if (creditAccountId == 0) + { + throw new Exception("Credit Account ID required, default not set for journal type"); + } + } + else + { + defaultCredit = reader.GetInt32(1); + if (creditAccountId == 0) + { + creditAccountId = defaultCredit; + } + else if (creditAccountId != defaultCredit) + { + throw new Exception("Credit Account ID supplied does not match default set for journal type"); + } + } + } + else + { + throw new Exception("AccountJournalID '" + journalId + "' does not exist."); + } + } + } + + // currency conversion + if (currencyCode != "GBP") + { + amount = new Data.Database.Account.Currency().CurrencyConvertToGbp(currencyCode, amount, entryDate); + } + + // ensure decimal is rounded + amount = Math.Round(amount, 2); + + // insert debit post + using (SqlCommand cmd = new SqlCommand(@" + INSERT INTO tblAccountJournalPost + (AccountJournalID, AccountChartOfID, AmountGbp) + VALUES + (@AccountJournalId, @AccountChartOfId, @AmountGbp) + ", conn)) + { + // add parameters + cmd.Parameters.AddWithValue("@AccountJournalId", journalId); + cmd.Parameters.AddWithValue("@AccountChartOfId", debitAccountId); + cmd.Parameters.AddWithValue("@AmountGbp", amount); + + cmd.ExecuteNonQuery(); + } + + // insert credit post + using (SqlCommand cmd = new SqlCommand(@" + INSERT INTO tblAccountJournalPost + (AccountJournalID, AccountChartOfID, AmountGbp) + VALUES + (@AccountJournalId, @AccountChartOfId, @AmountGbp) + ", conn)) + { + // add parameters + cmd.Parameters.AddWithValue("@AccountJournalId", journalId); + cmd.Parameters.AddWithValue("@AccountChartOfId", creditAccountId); + cmd.Parameters.AddWithValue("@AmountGbp", (amount * -1)); + + cmd.ExecuteNonQuery(); + } + + scope.Complete(); + return true; + } + } + } +} diff --git a/src/bnhtrade.Core/Data/Database/Account/Currency.cs b/src/bnhtrade.Core/Data/Database/Account/Currency.cs new file mode 100644 index 0000000..da36093 --- /dev/null +++ b/src/bnhtrade.Core/Data/Database/Account/Currency.cs @@ -0,0 +1,199 @@ +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 Currency : Connection + { + public decimal CurrencyConvertToGbp(string currencyCode, decimal amount, DateTime conversionDate) + { + if (currencyCode == "GBP" || amount == 0M) + { + return amount; + } + + if (currencyCode.Length != 3) + { + throw new Exception("Invalid currency code '" + currencyCode + "'"); + } + + using (SqlConnection sqlConn = new SqlConnection(SqlConnectionString)) + { + sqlConn.Open(); + + using (SqlCommand cmd = new SqlCommand(@" + SELECT CurrencyUnitsPerGBP + FROM tblAccountExchangeRate + WHERE CurrencyCode=@currencyCode AND StartDate<=@conversionDate AND EndDate>@conversionDate + ", sqlConn)) + { + cmd.Parameters.AddWithValue("@currencyCode", currencyCode); + cmd.Parameters.AddWithValue("@conversionDate", conversionDate); + + object result = cmd.ExecuteScalar(); + if (result != null) + { + return amount / Convert.ToDecimal(result); + } + } + + // return reason for no record found + using (SqlCommand cmd = new SqlCommand(@" + SELECT CurrencyUnitsPerGBP + FROM tblAccountExchangeRate + WHERE CurrencyCode=@currencyCode + ", sqlConn)) + { + cmd.Parameters.AddWithValue("@currencyCode", currencyCode); + + object result = cmd.ExecuteScalar(); + if (result == null) + { + throw new Exception("Currency code '" + currencyCode + "' does not exist in Exchange Rate table"); + } + else + { + throw new Exception("Date range for " + currencyCode + " " + conversionDate.ToShortDateString() + " " + + conversionDate.ToLongTimeString() + "' does not exist in Exchange Rate table"); + } + } + } + } + + public int CurrencyExchangeRateInsert(int exchangeRateSource, string currencyCode, + decimal currencyUnitsPerGbp, DateTime periodStart, DateTime periodEnd, bool checkOverride = false) + { + currencyUnitsPerGbp = decimal.Round(currencyUnitsPerGbp, 4); + periodStart = DateTime.SpecifyKind(periodStart, DateTimeKind.Utc); + periodEnd = DateTime.SpecifyKind(periodEnd, DateTimeKind.Utc); + + // CHECKS + // HMRC source only + if (exchangeRateSource != 1) + { + throw new Exception("Function does not currently accept exchange rates from sources other than HMRC"); + } + // currency code upper case only + currencyCode = currencyCode.ToUpper(); + if (currencyCode.Length != 3) + { + throw new Exception("Invalid currency code '" + currencyCode + "'"); + } + + if (periodEnd <= periodStart) + { + throw new Exception("Invalid date period."); + } + + if (checkOverride == false && (periodEnd - periodStart).Days > 31) + { + throw new Exception("Date period is greater than 31 days."); + } + + // retirve previous data + DateTime? periodEndLast = null; + using (SqlConnection sqlConn = new SqlConnection(SqlConnectionString)) + { + sqlConn.Open(); + + using (SqlCommand cmd = new SqlCommand(@" + SELECT Max(tblAccountExchangeRate.EndDate) AS MaxOfEndDate + FROM tblAccountExchangeRate + WHERE (((tblAccountExchangeRate.CurrencyCode) = @currencyCode)) + ", sqlConn)) + { + cmd.Parameters.AddWithValue("@currencyCode", currencyCode); + + object obj = cmd.ExecuteScalar(); + + // currency code not existing + if (obj == DBNull.Value && checkOverride == false) + { + throw new Exception("Currency code '" + currencyCode + "' does not exist in table"); + } + // currency code exists + else + { + periodEndLast = DateTime.SpecifyKind(Convert.ToDateTime(obj), DateTimeKind.Utc); + + if (periodStart != periodEndLast) + { + throw new Exception("Invalid period start date -- must equal previous period end-date."); + } + } + } + + // retrive previous exchange rate and check + decimal currencyUnitsPerGbpLast = 0; + if (periodEndLast != null) + { + using (SqlCommand cmd = new SqlCommand(@" + SELECT tblAccountExchangeRate.AccountExchangeRateID, tblAccountExchangeRate.CurrencyUnitsPerGBP + FROM tblAccountExchangeRate + WHERE (tblAccountExchangeRate.EndDate = @periodEndLast) + AND (CurrencyCode = @currencyCode); + ", sqlConn)) + { + cmd.Parameters.AddWithValue("@periodEndLast", periodEndLast); + cmd.Parameters.AddWithValue("@currencyCode", currencyCode); + + using (var reader = cmd.ExecuteReader()) + { + if (reader.Read()) + { + currencyUnitsPerGbpLast = reader.GetDecimal(1); + } + else + { + throw new Exception("Error that shouldn't happen! Check code @ 5129f3e6-2f7e-4883-bc73-b317d8fa4050"); + } + // error if >1 line + if (reader.Read()) + { + string errText = "Multiple lines in currency exchange table for '" + currencyCode + "' where [EndDate]=" + periodEndLast.ToString(); + new Logic.Log.LogEvent().LogError(errText); + throw new Exception(errText); + } + } + } + } + + // check difference between current and previous exchange rates isn't too great + if (checkOverride == false && + (currencyUnitsPerGbpLast > (currencyUnitsPerGbp * 1.05m) || currencyUnitsPerGbpLast < (currencyUnitsPerGbp * 0.95m)) + ) + { + throw new Exception("Difference between supplied and previous exchange rates is greater than 5%"); + } + + // MAKE THE INSERT + int recordId = 0; + using (SqlCommand cmd = new SqlCommand(@" + INSERT INTO tblAccountExchangeRate (ExchangeRateSource, CurrencyCode, CurrencyUnitsPerGBP, StartDate, EndDate) + OUTPUT INSERTED.AccountExchangeRateID + VALUES (@exchangeRateSource, @currencyCode, @currencyUnitsPerGbp, @periodStart, @periodEnd); + ", sqlConn)) + { + cmd.Parameters.AddWithValue("@exchangeRateSource", exchangeRateSource); + cmd.Parameters.AddWithValue("@currencyCode", currencyCode); + cmd.Parameters.AddWithValue("@currencyUnitsPerGbp", currencyUnitsPerGbp); + cmd.Parameters.AddWithValue("@periodStart", periodStart); + cmd.Parameters.AddWithValue("@periodEnd", periodEnd); + + recordId = (int)cmd.ExecuteScalar(); + + if (recordId < 1) + { + throw new Exception("Error inserting record, did not retrive new record ID."); + } + } + + return recordId; + } + } + } +} diff --git a/src/bnhtrade.Core/Data/Database/Account/DeleteJournal.cs b/src/bnhtrade.Core/Data/Database/Account/DeleteJournal.cs new file mode 100644 index 0000000..ce03164 --- /dev/null +++ b/src/bnhtrade.Core/Data/Database/Account/DeleteJournal.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using System.Data.SqlClient; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Transactions; + +namespace bnhtrade.Core.Data.Database.Account +{ + internal class DeleteJournal : Connection + { + /// + /// Old code needs sorting + /// + public bool AccountJournalDelete(int accountJournalId) + { + // check if journal entry is locked + using (TransactionScope scope = new TransactionScope()) + { + bool IsLocked = new Data.Database.Account.ReadJournal().EntryIsLocked(accountJournalId); + if (IsLocked == true) + { + return false; + } + + using (SqlConnection conn = new SqlConnection(SqlConnectionString)) + { + conn.Open(); + + // make the delete + using (SqlCommand cmd = new SqlCommand(@" + DELETE FROM tblAccountJournalPost + WHERE AccountJournalID=@accountJournalId; + ", conn)) + { + cmd.Parameters.AddWithValue("@accountJournalId", accountJournalId); + + int rows = cmd.ExecuteNonQuery(); + + if (rows == 0) + { + throw new Exception("Journal entry and/or entry posts do not exist for AccountJournalId=" + accountJournalId); + } + } + + using (SqlCommand cmd = new SqlCommand(@" + DELETE FROM tblAccountJournal + WHERE AccountJournalID=@accountJournalId; + ", conn)) + { + cmd.Parameters.AddWithValue("@accountJournalId", accountJournalId); + + cmd.ExecuteNonQuery(); + } + + scope.Complete(); + return true; + } + } + } + + } +} diff --git a/src/bnhtrade.Core/Data/Database/Account/Contact.cs b/src/bnhtrade.Core/Data/Database/Account/ReadContact.cs similarity index 98% rename from src/bnhtrade.Core/Data/Database/Account/Contact.cs rename to src/bnhtrade.Core/Data/Database/Account/ReadContact.cs index 1a75568..489adad 100644 --- a/src/bnhtrade.Core/Data/Database/Account/Contact.cs +++ b/src/bnhtrade.Core/Data/Database/Account/ReadContact.cs @@ -7,13 +7,13 @@ using System.Threading.Tasks; namespace bnhtrade.Core.Data.Database.Account { - internal class Contact : Connection + internal class ReadContact : Connection { private bnhtrade.Core.Data.Database.SqlWhereBuilder sqlBuilder; public List ContactIdList { get; set; } - public Contact() + public ReadContact() { Init(); } diff --git a/src/bnhtrade.Core/Data/Database/Account/Journal.cs b/src/bnhtrade.Core/Data/Database/Account/ReadJournal.cs similarity index 84% rename from src/bnhtrade.Core/Data/Database/Account/Journal.cs rename to src/bnhtrade.Core/Data/Database/Account/ReadJournal.cs index 26a5a94..a91897d 100644 --- a/src/bnhtrade.Core/Data/Database/Account/Journal.cs +++ b/src/bnhtrade.Core/Data/Database/Account/ReadJournal.cs @@ -10,16 +10,16 @@ using static System.ComponentModel.Design.ObjectSelectorEditor; namespace bnhtrade.Core.Data.Database.Account { - internal class Journal : Connection + internal class ReadJournal : Connection { private bnhtrade.Core.Data.Database.SqlWhereBuilder sqlBuilder; /// - /// Results filter + /// Filter the read results /// public List AccountJournalId { get; set; } - public Journal() + public ReadJournal() { Init(); } @@ -162,7 +162,7 @@ namespace bnhtrade.Core.Data.Database.Account } // get journalTypes from db - var dbJournalType = new Data.Database.Account.JournalType(); + var dbJournalType = new Data.Database.Account.ReadJournalType(); dbJournalType.IdList = journalTypeIdList; var journalTypeDict = dbJournalType.Read(); @@ -204,5 +204,39 @@ namespace bnhtrade.Core.Data.Database.Account // all done, return the list herevar return returnList; } + + /// + /// Test for locked journal entry + /// + /// False on locked journal entry + public bool EntryIsLocked(int journalId) + { + using (SqlConnection conn = new SqlConnection(SqlConnectionString)) + { + conn.Open(); + using (SqlCommand cmd = new SqlCommand(@" + SELECT + tblAccountJournal.IsLocked + FROM + tblAccountJournal + WHERE + tblAccountJournal.AccountJournalID=@accountJournalId; + ", conn)) + { + cmd.Parameters.AddWithValue("@accountJournalId", journalId); + + object obj = cmd.ExecuteScalar(); + if (obj == null) + { + throw new Exception("Journal entry not found for AccountJournalID=" + journalId); + } + else + { + return (bool)obj; + } + } + } + } + } } diff --git a/src/bnhtrade.Core/Data/Database/Account/JournalType.cs b/src/bnhtrade.Core/Data/Database/Account/ReadJournalType.cs similarity index 98% rename from src/bnhtrade.Core/Data/Database/Account/JournalType.cs rename to src/bnhtrade.Core/Data/Database/Account/ReadJournalType.cs index a39ad80..3835422 100644 --- a/src/bnhtrade.Core/Data/Database/Account/JournalType.cs +++ b/src/bnhtrade.Core/Data/Database/Account/ReadJournalType.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace bnhtrade.Core.Data.Database.Account { - internal class JournalType : Connection + internal class ReadJournalType : Connection { private bnhtrade.Core.Data.Database.SqlWhereBuilder sqlBuilder; @@ -21,7 +21,7 @@ namespace bnhtrade.Core.Data.Database.Account /// public List TitleList { get; set; } - public JournalType() + public ReadJournalType() { Init(); } diff --git a/src/bnhtrade.Core/Data/Database/Account/PurchaseInvoice.cs b/src/bnhtrade.Core/Data/Database/Account/ReadPurchaseInvoice.cs similarity index 96% rename from src/bnhtrade.Core/Data/Database/Account/PurchaseInvoice.cs rename to src/bnhtrade.Core/Data/Database/Account/ReadPurchaseInvoice.cs index 9b0fe1e..f9442ff 100644 --- a/src/bnhtrade.Core/Data/Database/Account/PurchaseInvoice.cs +++ b/src/bnhtrade.Core/Data/Database/Account/ReadPurchaseInvoice.cs @@ -8,13 +8,13 @@ using static System.ComponentModel.Design.ObjectSelectorEditor; namespace bnhtrade.Core.Data.Database.Account { - public class PurchaseInvoice : Connection + public class ReadPurchaseInvoice : Connection { private bnhtrade.Core.Data.Database.SqlWhereBuilder sqlBuilder; public List PurchaseInvoiceIdList { get; set; } - public PurchaseInvoice() + public ReadPurchaseInvoice() { Init(); } @@ -136,7 +136,7 @@ namespace bnhtrade.Core.Data.Database.Account // add contact info if (invoiceContactDict.Any()) { - var readContact = new Data.Database.Account.Contact(); + var readContact = new Data.Database.Account.ReadContact(); readContact.ContactIdList = invoiceContactDict.Values.ToList(); var contactDict = readContact.Read(); @@ -154,7 +154,7 @@ namespace bnhtrade.Core.Data.Database.Account } // add invoice lines - var readLines = new Data.Database.Account.PurchaseInvoiceLine(); + var readLines = new Data.Database.Account.ReadPurchaseInvoiceLine(); readLines.InvoiceIdList = purchaseIdList; var lines = readLines.Read(); foreach(var invoice in returnList.Values) diff --git a/src/bnhtrade.Core/Data/Database/Account/PurchaseInvoiceLine.cs b/src/bnhtrade.Core/Data/Database/Account/ReadPurchaseInvoiceLine.cs similarity index 98% rename from src/bnhtrade.Core/Data/Database/Account/PurchaseInvoiceLine.cs rename to src/bnhtrade.Core/Data/Database/Account/ReadPurchaseInvoiceLine.cs index d282818..4642f28 100644 --- a/src/bnhtrade.Core/Data/Database/Account/PurchaseInvoiceLine.cs +++ b/src/bnhtrade.Core/Data/Database/Account/ReadPurchaseInvoiceLine.cs @@ -9,7 +9,7 @@ using static System.ComponentModel.Design.ObjectSelectorEditor; namespace bnhtrade.Core.Data.Database.Account { - internal class PurchaseInvoiceLine : Connection + internal class ReadPurchaseInvoiceLine : Connection { private bnhtrade.Core.Data.Database.SqlWhereBuilder sqlBuilder; @@ -33,7 +33,7 @@ namespace bnhtrade.Core.Data.Database.Account /// public List ItemDescription { get; set; } - public PurchaseInvoiceLine() + public ReadPurchaseInvoiceLine() { Init(); } diff --git a/src/bnhtrade.Core/Data/Database/Account/PurchaseInvoiceLineStatus.cs b/src/bnhtrade.Core/Data/Database/Account/ReadPurchaseInvoiceLineStatus.cs similarity index 96% rename from src/bnhtrade.Core/Data/Database/Account/PurchaseInvoiceLineStatus.cs rename to src/bnhtrade.Core/Data/Database/Account/ReadPurchaseInvoiceLineStatus.cs index ded5807..d15e0c9 100644 --- a/src/bnhtrade.Core/Data/Database/Account/PurchaseInvoiceLineStatus.cs +++ b/src/bnhtrade.Core/Data/Database/Account/ReadPurchaseInvoiceLineStatus.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace bnhtrade.Core.Data.Database.Account { - internal class PurchaseInvoiceLineStatus : Connection + internal class ReadPurchaseInvoiceLineStatus : Connection { public Dictionary Read() { diff --git a/src/bnhtrade.Core/Data/Database/Account/PurchaseInvoiceLineSummary.cs b/src/bnhtrade.Core/Data/Database/Account/ReadPurchaseInvoiceLineSummary.cs similarity index 98% rename from src/bnhtrade.Core/Data/Database/Account/PurchaseInvoiceLineSummary.cs rename to src/bnhtrade.Core/Data/Database/Account/ReadPurchaseInvoiceLineSummary.cs index 1b4e20f..da2bc15 100644 --- a/src/bnhtrade.Core/Data/Database/Account/PurchaseInvoiceLineSummary.cs +++ b/src/bnhtrade.Core/Data/Database/Account/ReadPurchaseInvoiceLineSummary.cs @@ -9,7 +9,7 @@ using static System.ComponentModel.Design.ObjectSelectorEditor; namespace bnhtrade.Core.Data.Database.Account { - internal class PurchaseInvoiceLineSummary : Connection + internal class ReadPurchaseInvoiceLineSummary : Connection { public List Read(DateTime periodTo, string lineStatus, List descriptionSearch) { diff --git a/src/bnhtrade.Core/Data/Database/Account/UpdateJournal.cs b/src/bnhtrade.Core/Data/Database/Account/UpdateJournal.cs new file mode 100644 index 0000000..c7de34a --- /dev/null +++ b/src/bnhtrade.Core/Data/Database/Account/UpdateJournal.cs @@ -0,0 +1,75 @@ +using System; +using System.Collections.Generic; +using System.Data.SqlClient; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Transactions; + +namespace bnhtrade.Core.Data.Database.Account +{ + internal class UpdateJournal : Connection + { + public bool AccountJournalPostUpdate(int journalId, string currencyCode, decimal amount, int debitAccountId = 0, int creditAccountId = 0) + { + using (TransactionScope scope = new TransactionScope()) + using (SqlConnection conn = new SqlConnection(SqlConnectionString)) + { + conn.Open(); + + // retrive journal entry date + DateTime entryDate; + using (SqlCommand cmd = new SqlCommand(@" + SELECT + tblAccountJournal.EntryDate + FROM + tblAccountJournal + WHERE + (((tblAccountJournal.AccountJournalID)=@accountJournalId)); + ", conn)) + { + cmd.Parameters.AddWithValue("@accountJournalId", journalId); + + entryDate = DateTime.SpecifyKind((DateTime)cmd.ExecuteScalar(), DateTimeKind.Utc); + } + + // delete the original posts + using (SqlCommand cmd = new SqlCommand(@" + DELETE FROM + tblAccountJournalPost + WHERE + (((tblAccountJournalPost.AccountJournalID)=@accountJournalId)); + ", conn)) + { + cmd.Parameters.AddWithValue("@accountJournalId", journalId); + + cmd.ExecuteNonQuery(); + } + + //insert new posts + //bool postResult = AccountJournalPostInsert(sqlConnectionString, journalId, entryDate, currencyCode, amount, debitAccountId, creditAccountId); + bool postResult = new Data.Database.Account.CreateJournal().AccountJournalPostInsert(journalId, entryDate, currencyCode, amount, debitAccountId, creditAccountId); + + // update modified date on journal + using (SqlCommand cmd = new SqlCommand(@" + UPDATE + tblAccountJournal + SET + tblAccountJournal.LastModified=@utcNow + WHERE + (((tblAccountJournal.AccountJournalID)=@accountJournalId)); + ", conn)) + { + cmd.Parameters.AddWithValue("@accountJournalId", journalId); + cmd.Parameters.AddWithValue("@utcNow", DateTime.UtcNow); + + cmd.ExecuteNonQuery(); + } + + scope.Complete(); + } + return true; + } + + } +} diff --git a/src/bnhtrade.Core/Logic/Account/Currency.cs b/src/bnhtrade.Core/Logic/Account/Currency.cs new file mode 100644 index 0000000..0aa682d --- /dev/null +++ b/src/bnhtrade.Core/Logic/Account/Currency.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace bnhtrade.Core.Logic.Account +{ + public class Currency + { + public decimal CurrencyConvertToGbp(string currencyCode, decimal amount, DateTime conversionDate) + { + return new Data.Database.Account.Currency().CurrencyConvertToGbp(currencyCode, amount, conversionDate); + } + + public int CurrencyExchangeRateInsert(int exchangeRateSource, string currencyCode, + decimal currencyUnitsPerGbp, DateTime periodStart, DateTime periodEnd, bool checkOverride = false) + { + return new Data.Database.Account.Currency().CurrencyExchangeRateInsert(exchangeRateSource, currencyCode, + currencyUnitsPerGbp, periodStart, periodEnd, checkOverride); + } + } +} diff --git a/src/bnhtrade.Core/Logic/Account/Journal.cs b/src/bnhtrade.Core/Logic/Account/Journal.cs new file mode 100644 index 0000000..690c85f --- /dev/null +++ b/src/bnhtrade.Core/Logic/Account/Journal.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Data.SqlClient; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Transactions; + +namespace bnhtrade.Core.Logic.Account +{ + public class Journal + { + public int AccountJournalInsert(int journalTypeId, DateTime entryDate, string currencyCode, + decimal amount, int debitAccountId = 0, int creditAccountId = 0, bool lockEntry = false) + { + return new Data.Database.Account.CreateJournal().AccountJournalInsert(journalTypeId, entryDate, currencyCode, + amount, debitAccountId, creditAccountId, lockEntry); + } + + public bool AccountJournalDelete(int accountJournalId) + { + return new Data.Database.Account.DeleteJournal().AccountJournalDelete(accountJournalId); + } + } +} diff --git a/src/bnhtrade.Core/Logic/Account/PurchaseInvoice.cs b/src/bnhtrade.Core/Logic/Account/PurchaseInvoice.cs index 13c3936..7866744 100644 --- a/src/bnhtrade.Core/Logic/Account/PurchaseInvoice.cs +++ b/src/bnhtrade.Core/Logic/Account/PurchaseInvoice.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace bnhtrade.Core.Logic.Account { - public class PurchaseInvoice : Core.Data.Database.Account.PurchaseInvoice + public class PurchaseInvoice : Core.Data.Database.Account.ReadPurchaseInvoice { } } diff --git a/src/bnhtrade.Core/Logic/Account/PurchaseInvoiceMisc.cs b/src/bnhtrade.Core/Logic/Account/PurchaseInvoiceMisc.cs index 02330bb..10eeb98 100644 --- a/src/bnhtrade.Core/Logic/Account/PurchaseInvoiceMisc.cs +++ b/src/bnhtrade.Core/Logic/Account/PurchaseInvoiceMisc.cs @@ -10,12 +10,12 @@ namespace bnhtrade.Core.Logic.Account { public List ReadLineStatusToList() { - return new Data.Database.Account.PurchaseInvoiceLineStatus().Read().Values.ToList(); + return new Data.Database.Account.ReadPurchaseInvoiceLineStatus().Read().Values.ToList(); } public List GetLineSummary(DateTime maxDate, string lineStatus, List wordSearchList) { - return new Data.Database.Account.PurchaseInvoiceLineSummary().Read(maxDate,lineStatus, wordSearchList); + return new Data.Database.Account.ReadPurchaseInvoiceLineSummary().Read(maxDate,lineStatus, wordSearchList); } } } diff --git a/src/bnhtrade.Core/Program.cs b/src/bnhtrade.Core/Program.cs index 41d77ea..c6ae64c 100644 --- a/src/bnhtrade.Core/Program.cs +++ b/src/bnhtrade.Core/Program.cs @@ -229,532 +229,6 @@ namespace bnhtrade.Core } } - namespace Account - { - public class AccountQuery - { - // externally called & internal - public static decimal CurrencyConvertToGbp(string sqlConnectionString, string currencyCode, decimal amount, DateTime conversionDate) - { - if (currencyCode == "GBP" || amount == 0M) - { - return amount; - } - - if (currencyCode.Length != 3) - { - throw new Exception("Invalid currency code '" + currencyCode + "'"); - } - - using (SqlConnection sqlConn = new SqlConnection(sqlConnectionString)) - { - sqlConn.Open(); - - using (SqlCommand cmd = new SqlCommand(@" - SELECT CurrencyUnitsPerGBP - FROM tblAccountExchangeRate - WHERE CurrencyCode=@currencyCode AND StartDate<=@conversionDate AND EndDate>@conversionDate - ", sqlConn)) - { - cmd.Parameters.AddWithValue("@currencyCode", currencyCode); - cmd.Parameters.AddWithValue("@conversionDate", conversionDate); - - object result = cmd.ExecuteScalar(); - if (result != null) - { - return amount / Convert.ToDecimal(result); - } - } - - // return reason for no record found - using (SqlCommand cmd = new SqlCommand(@" - SELECT CurrencyUnitsPerGBP - FROM tblAccountExchangeRate - WHERE CurrencyCode=@currencyCode - ", sqlConn)) - { - cmd.Parameters.AddWithValue("@currencyCode", currencyCode); - - object result = cmd.ExecuteScalar(); - if (result == null) - { - throw new Exception("Currency code '" + currencyCode + "' does not exist in Exchange Rate table"); - } - else - { - throw new Exception("Date range for " + currencyCode + " " + conversionDate.ToShortDateString() + " " + - conversionDate.ToLongTimeString() + "' does not exist in Exchange Rate table"); - } - } - } - } - - // externally called - public static int CurrencyExchangeRateInsert(string sqlConnectionString, int exchangeRateSource, string currencyCode, - decimal currencyUnitsPerGbp, DateTime periodStart, DateTime periodEnd, bool checkOverride = false) - { - currencyUnitsPerGbp = decimal.Round(currencyUnitsPerGbp, 4); - periodStart = DateTime.SpecifyKind(periodStart, DateTimeKind.Utc); - periodEnd = DateTime.SpecifyKind(periodEnd, DateTimeKind.Utc); - - // CHECKS - // HMRC source only - if (exchangeRateSource != 1) - { - throw new Exception("Function does not currently accept exchange rates from sources other than HMRC"); - } - // currency code upper case only - currencyCode = currencyCode.ToUpper(); - if (currencyCode.Length != 3) - { - throw new Exception("Invalid currency code '" + currencyCode +"'"); - } - - if (periodEnd <= periodStart) - { - throw new Exception("Invalid date period."); - } - - if (checkOverride == false && (periodEnd - periodStart).Days > 31) - { - throw new Exception("Date period is greater than 31 days."); - } - - // retirve previous data - DateTime? periodEndLast = null; - using (SqlConnection sqlConn = new SqlConnection(sqlConnectionString)) - { - sqlConn.Open(); - - using (SqlCommand cmd = new SqlCommand(@" - SELECT Max(tblAccountExchangeRate.EndDate) AS MaxOfEndDate - FROM tblAccountExchangeRate - WHERE (((tblAccountExchangeRate.CurrencyCode) = @currencyCode)) - ", sqlConn)) - { - cmd.Parameters.AddWithValue("@currencyCode", currencyCode); - - object obj = cmd.ExecuteScalar(); - - // currency code not existing - if (obj == DBNull.Value && checkOverride == false) - { - throw new Exception("Currency code '" + currencyCode + "' does not exist in table"); - } - // currency code exists - else - { - periodEndLast = DateTime.SpecifyKind(Convert.ToDateTime(obj), DateTimeKind.Utc); - - if (periodStart != periodEndLast) - { - throw new Exception("Invalid period start date -- must equal previous period end-date."); - } - } - } - - // retrive previous exchange rate and check - decimal currencyUnitsPerGbpLast = 0; - if (periodEndLast != null) - { - using (SqlCommand cmd = new SqlCommand(@" - SELECT tblAccountExchangeRate.AccountExchangeRateID, tblAccountExchangeRate.CurrencyUnitsPerGBP - FROM tblAccountExchangeRate - WHERE (tblAccountExchangeRate.EndDate = @periodEndLast) - AND (CurrencyCode = @currencyCode); - ", sqlConn)) - { - cmd.Parameters.AddWithValue("@periodEndLast", periodEndLast); - cmd.Parameters.AddWithValue("@currencyCode", currencyCode); - - using (var reader = cmd.ExecuteReader()) - { - if (reader.Read()) - { - currencyUnitsPerGbpLast = reader.GetDecimal(1); - } - else - { - throw new Exception("Error that shouldn't happen! Check code @ 5129f3e6-2f7e-4883-bc73-b317d8fa4050"); - } - // error if >1 line - if (reader.Read()) - { - string errText = "Multiple lines in currency exchange table for '" + currencyCode + "' where [EndDate]=" + periodEndLast.ToString(); - new Logic.Log.LogEvent().LogError(errText); - throw new Exception(errText); - } - } - } - } - - // check difference between current and previous exchange rates isn't too great - if (checkOverride == false && - (currencyUnitsPerGbpLast > (currencyUnitsPerGbp * 1.05m) || currencyUnitsPerGbpLast < (currencyUnitsPerGbp * 0.95m)) - ) - { - throw new Exception("Difference between supplied and previous exchange rates is greater than 5%"); - } - - // MAKE THE INSERT - int recordId = 0; - using (SqlCommand cmd = new SqlCommand(@" - INSERT INTO tblAccountExchangeRate (ExchangeRateSource, CurrencyCode, CurrencyUnitsPerGBP, StartDate, EndDate) - OUTPUT INSERTED.AccountExchangeRateID - VALUES (@exchangeRateSource, @currencyCode, @currencyUnitsPerGbp, @periodStart, @periodEnd); - ", sqlConn)) - { - cmd.Parameters.AddWithValue("@exchangeRateSource", exchangeRateSource); - cmd.Parameters.AddWithValue("@currencyCode", currencyCode); - cmd.Parameters.AddWithValue("@currencyUnitsPerGbp", currencyUnitsPerGbp); - cmd.Parameters.AddWithValue("@periodStart", periodStart); - cmd.Parameters.AddWithValue("@periodEnd", periodEnd); - - recordId = (int)cmd.ExecuteScalar(); - - if (recordId < 1) - { - throw new Exception("Error inserting record, did not retrive new record ID."); - } - } - - return recordId; - } - } - - // internally called - public static bool AccountJournalEntryIsLocked(string sqlConnectionString, int journalId) - { - using (SqlConnection conn = new SqlConnection(sqlConnectionString)) - { - conn.Open(); - using (SqlCommand cmd = new SqlCommand(@" - SELECT - tblAccountJournal.IsLocked - FROM - tblAccountJournal - WHERE - tblAccountJournal.AccountJournalID=@accountJournalId; - ", conn)) - { - cmd.Parameters.AddWithValue("@accountJournalId", journalId); - - object obj = cmd.ExecuteScalar(); - if (obj == null) - { - throw new Exception("Journal entry not found for AccountJournalID=" + journalId); - } - else - { - return (bool)obj; - } - } - } - } - - // externally called - public static int AccountJournalInsert(string sqlConnectionString, int journalTypeId, DateTime entryDate, string currencyCode, - decimal amount, int debitAccountId = 0, int creditAccountId = 0, bool lockEntry = false) - { - int defaultDebit = 0; - int defaultCredit = 0; - - // ensure date is UTC - entryDate = DateTime.SpecifyKind(entryDate, DateTimeKind.Utc); - - // debit and credit locks are checked in journal post method - using (TransactionScope scope = new TransactionScope()) - using (SqlConnection conn = new SqlConnection(sqlConnectionString)) - { - conn.Open(); - - // insert the journal entry - int journalId; - - using (SqlCommand cmd = new SqlCommand(@" - INSERT INTO tblAccountJournal - (AccountJournalTypeID, EntryDate, IsLocked) - OUTPUT INSERTED.AccountJournalID - VALUES - (@journalTypeId, @entryDate, @lockEntry) - ", conn)) - { - // add parameters - cmd.Parameters.AddWithValue("@journalTypeId", journalTypeId); - cmd.Parameters.AddWithValue("@entryDate", entryDate.ToUniversalTime()); - cmd.Parameters.AddWithValue("@lockEntry", lockEntry); - - //execute - journalId = (int)cmd.ExecuteScalar(); - } - - // insert journal entries - bool postResult = AccountJournalPostInsert(sqlConnectionString, journalId, entryDate, currencyCode, amount, debitAccountId, creditAccountId); - - scope.Complete(); - return journalId; - } - } - - // externally called - // return false on locked journal entry - public static bool AccountJournalDelete(string sqlConnectionString, int accountJournalId) - { - // check if journal entry is locked - using (TransactionScope scope = new TransactionScope()) - { - bool IsLocked = Account.AccountQuery.AccountJournalEntryIsLocked(sqlConnectionString, accountJournalId); - if (IsLocked == true) - { - return false; - } - - using (SqlConnection conn = new SqlConnection(sqlConnectionString)) - { - conn.Open(); - - // make the delete - using (SqlCommand cmd = new SqlCommand(@" - DELETE FROM tblAccountJournalPost - WHERE AccountJournalID=@accountJournalId; - ", conn)) - { - cmd.Parameters.AddWithValue("@accountJournalId", accountJournalId); - - int rows = cmd.ExecuteNonQuery(); - - if (rows == 0) - { - throw new Exception("Journal entry and/or entry posts do not exist for AccountJournalId=" + accountJournalId); - } - } - - using (SqlCommand cmd = new SqlCommand(@" - DELETE FROM tblAccountJournal - WHERE AccountJournalID=@accountJournalId; - ", conn)) - { - cmd.Parameters.AddWithValue("@accountJournalId", accountJournalId); - - cmd.ExecuteNonQuery(); - } - - scope.Complete(); - return true; - } - } - } - - // internally called - private static bool AccountJournalPostInsert(string sqlConnectionString, int journalId, DateTime entryDate, - string currencyCode, decimal amount, int debitAccountId = 0, int creditAccountId = 0) - { - int defaultDebit; - int defaultCredit; - entryDate = DateTime.SpecifyKind(entryDate, DateTimeKind.Utc); - - using (TransactionScope scope = new TransactionScope()) - using (SqlConnection conn = new SqlConnection(sqlConnectionString)) - { - conn.Open(); - - // ensure their are no other entries - using (SqlCommand cmd = new SqlCommand(@" - SELECT - Count(tblAccountJournalPost.AccountJournalPostID) AS CountOfAccountJournalPostID - FROM - tblAccountJournalPost - WHERE - (((tblAccountJournalPost.AccountJournalID)=@AccountJournalID)); - ", conn)) - { - cmd.Parameters.AddWithValue("@AccountJournalID", journalId); - - int count = (int)cmd.ExecuteScalar(); - - if (count > 0) - { - throw new Exception("Unable the insert journal posts, post already present AccountJournalID=" + journalId); - } - } - - //checks - using (SqlCommand cmd = new SqlCommand(@" - SELECT - tblAccountJournalType.ChartOfAccountID_Debit, tblAccountJournalType.ChartOfAccountID_Credit - FROM - tblAccountJournal - INNER JOIN tblAccountJournalType - ON tblAccountJournal.AccountJournalTypeID = tblAccountJournalType.AccountJournalTypeID - WHERE - (((tblAccountJournal.AccountJournalID)=@journalId)); - ", conn)) - { - cmd.Parameters.AddWithValue("@journalId", journalId); - - using (SqlDataReader reader = cmd.ExecuteReader()) - { - if (reader.Read()) - { - // debit check - if (reader.IsDBNull(0)) - { - if (debitAccountId == 0) - { - throw new Exception("Debit Account ID required, default not set for journal type"); - } - } - else - { - defaultDebit = reader.GetInt32(0); - if (debitAccountId == 0) - { - debitAccountId = defaultDebit; - } - else if (debitAccountId != defaultDebit) - { - throw new Exception("Debit Account ID supplied does not match default set for journal type"); - } - - } - // credit check - if (reader.IsDBNull(1)) - { - if (creditAccountId == 0) - { - throw new Exception("Credit Account ID required, default not set for journal type"); - } - } - else - { - defaultCredit = reader.GetInt32(1); - if (creditAccountId == 0) - { - creditAccountId = defaultCredit; - } - else if (creditAccountId != defaultCredit) - { - throw new Exception("Credit Account ID supplied does not match default set for journal type"); - } - } - } - else - { - throw new Exception("AccountJournalID '" + journalId + "' does not exist."); - } - } - } - - // currency conversion - if (currencyCode != "GBP") - { - amount = Core.Account.AccountQuery.CurrencyConvertToGbp(sqlConnectionString, currencyCode, amount, entryDate); - } - - // ensure decimal is rounded - amount = Math.Round(amount, 2); - - // insert debit post - using (SqlCommand cmd = new SqlCommand(@" - INSERT INTO tblAccountJournalPost - (AccountJournalID, AccountChartOfID, AmountGbp) - VALUES - (@AccountJournalId, @AccountChartOfId, @AmountGbp) - ", conn)) - { - // add parameters - cmd.Parameters.AddWithValue("@AccountJournalId", journalId); - cmd.Parameters.AddWithValue("@AccountChartOfId", debitAccountId); - cmd.Parameters.AddWithValue("@AmountGbp", amount); - - cmd.ExecuteNonQuery(); - } - - // insert credit post - using (SqlCommand cmd = new SqlCommand(@" - INSERT INTO tblAccountJournalPost - (AccountJournalID, AccountChartOfID, AmountGbp) - VALUES - (@AccountJournalId, @AccountChartOfId, @AmountGbp) - ", conn)) - { - // add parameters - cmd.Parameters.AddWithValue("@AccountJournalId", journalId); - cmd.Parameters.AddWithValue("@AccountChartOfId", creditAccountId); - cmd.Parameters.AddWithValue("@AmountGbp", (amount * -1)); - - cmd.ExecuteNonQuery(); - } - - scope.Complete(); - return true; - } - } - - // externally called - public static bool AccountJournalPostUpdate(string sqlConnectionString, int journalId, string currencyCode, decimal amount, - int debitAccountId = 0, int creditAccountId = 0) - { - using (TransactionScope scope = new TransactionScope()) - using (SqlConnection conn = new SqlConnection(sqlConnectionString)) - { - conn.Open(); - - // retrive journal entry date - DateTime entryDate; - using (SqlCommand cmd = new SqlCommand(@" - SELECT - tblAccountJournal.EntryDate - FROM - tblAccountJournal - WHERE - (((tblAccountJournal.AccountJournalID)=@accountJournalId)); - ", conn)) - { - cmd.Parameters.AddWithValue("@accountJournalId", journalId); - - entryDate = DateTime.SpecifyKind((DateTime)cmd.ExecuteScalar(), DateTimeKind.Utc); - } - - // delete the original posts - using (SqlCommand cmd = new SqlCommand(@" - DELETE FROM - tblAccountJournalPost - WHERE - (((tblAccountJournalPost.AccountJournalID)=@accountJournalId)); - ", conn)) - { - cmd.Parameters.AddWithValue("@accountJournalId", journalId); - - cmd.ExecuteNonQuery(); - } - - //insert new posts - bool postResult = AccountJournalPostInsert(sqlConnectionString, journalId, entryDate, currencyCode, amount, debitAccountId, creditAccountId); - - // update modified date on journal - using (SqlCommand cmd = new SqlCommand(@" - UPDATE - tblAccountJournal - SET - tblAccountJournal.LastModified=@utcNow - WHERE - (((tblAccountJournal.AccountJournalID)=@accountJournalId)); - ", conn)) - { - cmd.Parameters.AddWithValue("@accountJournalId", journalId); - cmd.Parameters.AddWithValue("@utcNow", DateTime.UtcNow); - - cmd.ExecuteNonQuery(); - } - - scope.Complete(); - } - return true; - } - } - } - namespace Sku { public class Sku @@ -885,7 +359,7 @@ namespace bnhtrade.Core conn.Open(); // add account journal entry - int accountJournalId = Account.AccountQuery.AccountJournalInsert(sqlConnectionString, accountJournalType, entryDate, currencyCode, amount); + int accountJournalId = new Logic.Account.Journal().AccountJournalInsert(accountJournalType, entryDate, currencyCode, amount); // make the stock insert int stockId = WIP_StockInsertSub(sqlConnectionString, productId, conditionId, accountTaxCodeId, @@ -1255,7 +729,7 @@ namespace bnhtrade.Core } // delete account journal entry - Account.AccountQuery.AccountJournalDelete(sqlConnectionString, accountJournalId); + new Data.Database.Account.DeleteJournal().AccountJournalDelete(accountJournalId); scope.Complete(); } @@ -1986,8 +1460,8 @@ namespace bnhtrade.Core conn.Open(); // create account journal entry - int journalId = Account.AccountQuery.AccountJournalInsert( - sqlConnectionString, accountJournalTypeIdNet, entryDate, currencyCode, amountNet, debitAccountId); + int journalId = new Data.Database.Account.CreateJournal().AccountJournalInsert( + accountJournalTypeIdNet, entryDate, currencyCode, amountNet, debitAccountId); // add transaction to purchase line transaction table using (SqlCommand cmd = new SqlCommand(@" @@ -2049,8 +1523,7 @@ namespace bnhtrade.Core } // make the update - bool result = Core.Account.AccountQuery.AccountJournalPostUpdate(sqlConnectionString, - accountJouranlId, currencyCode, amountNet, debitAccountId, creditAccountId); + bool result = new Data.Database.Account.UpdateJournal().AccountJournalPostUpdate(accountJouranlId, currencyCode, amountNet, debitAccountId, creditAccountId); scope.Complete(); } @@ -2147,7 +1620,7 @@ namespace bnhtrade.Core } // delete account journal entry - Account.AccountQuery.AccountJournalDelete(sqlConnectionString, accountJournalId); + new Data.Database.Account.DeleteJournal().AccountJournalDelete(accountJournalId); scope.Complete(); } diff --git a/src/bnhtrade.Core/Test/Account/Account.cs b/src/bnhtrade.Core/Test/Account/Account.cs index 10d15cc..cbd55e2 100644 --- a/src/bnhtrade.Core/Test/Account/Account.cs +++ b/src/bnhtrade.Core/Test/Account/Account.cs @@ -16,21 +16,21 @@ namespace bnhtrade.Core.Test.Account public void PurchaseInvoice() { - var read = new Data.Database.Account.PurchaseInvoice(); + var read = new Data.Database.Account.ReadPurchaseInvoice(); 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(); + var read = new Data.Database.Account.ReadPurchaseInvoiceLine(); read.ItemDescription = new List { "xbox", "kill" }; var result = read.Read(); } public void Journal() { - var read = new Data.Database.Account.Journal(); + var read = new Data.Database.Account.ReadJournal(); read.AccountJournalId = new List { 123, 300, 324, 5678, 22 }; var result = read.Read(); } From a865abb788bd36d68727339efd038b3d388e05d4 Mon Sep 17 00:00:00 2001 From: Bobbie Hodgetts Date: Tue, 6 Aug 2024 12:07:18 +0100 Subject: [PATCH 10/15] wip --- .../Data/Database/SKU/InsertSku.cs | 2 +- src/bnhtrade.Core/Logic/Sku/GetSkuId.cs | 6 +- src/bnhtrade.Core/Program.cs | 122 +----------------- 3 files changed, 8 insertions(+), 122 deletions(-) diff --git a/src/bnhtrade.Core/Data/Database/SKU/InsertSku.cs b/src/bnhtrade.Core/Data/Database/SKU/InsertSku.cs index 7af1d05..68cb69a 100644 --- a/src/bnhtrade.Core/Data/Database/SKU/InsertSku.cs +++ b/src/bnhtrade.Core/Data/Database/SKU/InsertSku.cs @@ -9,7 +9,7 @@ using System.Transactions; namespace bnhtrade.Core.Data.Database.Sku { - public class InsertSku : Connection + internal class InsertSku : Connection { public int InsertNew(int productId, int conditionId, int accountTaxCodeId) { diff --git a/src/bnhtrade.Core/Logic/Sku/GetSkuId.cs b/src/bnhtrade.Core/Logic/Sku/GetSkuId.cs index 9224dd0..230c608 100644 --- a/src/bnhtrade.Core/Logic/Sku/GetSkuId.cs +++ b/src/bnhtrade.Core/Logic/Sku/GetSkuId.cs @@ -28,8 +28,10 @@ namespace bnhtrade.Core.Logic.Sku { return 0; } - - return new Data.Database.Sku.InsertSku().InsertNew(productId, conditionId, accountTaxCodeId); + else + { + return new Data.Database.Sku.InsertSku().InsertNew(productId, conditionId, accountTaxCodeId); + } } } } diff --git a/src/bnhtrade.Core/Program.cs b/src/bnhtrade.Core/Program.cs index c6ae64c..c21cb8c 100644 --- a/src/bnhtrade.Core/Program.cs +++ b/src/bnhtrade.Core/Program.cs @@ -60,7 +60,7 @@ namespace bnhtrade.Core ) { // first off, check if listing-item already exists, return id if it does - int listingItemId = EbayListingItemGet(sqlConnectionString, itemNumber, listingEnd); + int listingItemId = EbayListingItemGet(sqlConnectionString, itemNumber, listingEnd); if (listingItemId > 0) { return (listingItemId, false, false); } @@ -228,123 +228,6 @@ namespace bnhtrade.Core } } } - - namespace Sku - { - public class Sku - { - public static int GetSkuIdByType(string sqlConnectionString, int productId, int conditionId, int accountTaxCodeId, bool noMatchInsertNew) - { - using (TransactionScope scope = new TransactionScope()) - using (SqlConnection conn = new SqlConnection(sqlConnectionString)) - { - conn.Open(); - - // look for existing entry - using (SqlCommand cmd = new SqlCommand(@" - SELECT - tblSku.skuSkuID - FROM - tblSku - WHERE - (((tblSku.skuProductID)=@productId) AND ((tblSku.skuSkuConditionID)=@conditionId) AND ((tblSku.AccountTaxCodeID)=@accountTaxCodeId)); - ", conn)) - { - cmd.Parameters.AddWithValue("@productId", productId); - cmd.Parameters.AddWithValue("@conditionId", conditionId); - cmd.Parameters.AddWithValue("@accountTaxCodeId", accountTaxCodeId); - - object obj = cmd.ExecuteScalar(); - if (obj != null) - { - return (int)obj; - } - } - - // value check insert bool - if (noMatchInsertNew == false) - { - return 0; - } - else - { - // get this far, check tax code id is a valid for SKU - using (SqlCommand cmd = new SqlCommand(@" - SELECT tblAccountTaxCode.InvoiceSales - FROM tblAccountTaxCode - WHERE (((tblAccountTaxCode.AccountTaxCodeID)=@accountTaxCodeId)); - ", conn)) - { - cmd.Parameters.AddWithValue("@accountTaxCodeId", accountTaxCodeId); - - object obj = cmd.ExecuteScalar(); - - if (obj == null) - { - throw new Exception("AccountTaxCodeID=" + accountTaxCodeId + " doesn't exist!"); - } - else - { - bool result = (bool)obj; - if (result == false) - { - throw new Exception("AccountTaxCodeID=" + accountTaxCodeId + " is not a valid type for an SKU."); - } - } - } - - // get info to create sku number - int skuCount; - int skuSuffix; - using (SqlCommand cmd = new SqlCommand("SELECT NEXT VALUE FOR SkuCountSequence;", conn)) - { - skuCount = (int)cmd.ExecuteScalar(); - } - using (SqlCommand cmd = new SqlCommand(@" - SELECT tblSkuCondition.scnSkuNumberSuffix - FROM tblSkuCondition - WHERE (((tblSkuCondition.scnSkuConditionID)=@conditionId)); - ", conn)) - { - cmd.Parameters.AddWithValue("@conditionId", conditionId); - - try - { - skuSuffix = (int)cmd.ExecuteScalar(); - } - catch (Exception ex) - { - throw new Exception("Error retriving SKU number suffix for SkuConditionID=" + conditionId + "." + - System.Environment.NewLine + "Error Message: " + ex.Message); - } - } - string skuNumber = skuCount.ToString("D6") + "-" + skuSuffix.ToString("D2"); - - // insert new sku - int skuId; - using (SqlCommand cmd = new SqlCommand(@" - INSERT INTO tblSku - (skuSkuNumber, skuProductID, skuSkuConditionID, AccountTaxCodeID) - OUTPUT INSERTED.skuSkuID - VALUES - (@skuNumber, @productId, @conditionId, @accountTaxCodeId) - ", conn)) - { - cmd.Parameters.AddWithValue("@skuNumber", skuNumber); - cmd.Parameters.AddWithValue("@productId", productId); - cmd.Parameters.AddWithValue("@conditionId", conditionId); - cmd.Parameters.AddWithValue("@accountTaxCodeId", accountTaxCodeId); - - skuId = (int)cmd.ExecuteScalar(); - } - - scope.Complete(); - return skuId; - } - } - } - } - } namespace Stock { @@ -549,7 +432,7 @@ namespace bnhtrade.Core } else { - throw new Exception("Manual delete of this stock type is not supported, use the moethod that created it!"); + throw new Exception("Manual delete of this stock type is not supported, use the method that created it!"); } // check there is only one stock journal entry for stock item @@ -879,6 +762,7 @@ namespace bnhtrade.Core } // insert journal posts into database + //new Data.Database.Stock Core.Stock.StockJournal.StockJournalPostInsert(conn, stockId, stockJournalId, journalPosts, isNewStock); // consistency check From a0c669f1d42e88f8d3d76286579e112d4e7da1cb Mon Sep 17 00:00:00 2001 From: Bobbie Hodgetts Date: Wed, 6 Nov 2024 17:12:34 +0000 Subject: [PATCH 11/15] wip --- .../Data/Amazon/Report/ReportLogic.cs | 44 ++++++++++++++++++- .../Data/Amazon/Report/SettlementReport.cs | 29 +++++------- .../Database/Export/CreateSalesInvoice.cs | 2 +- .../Logic/Import/AmazonSettlement.cs | 10 +++-- 4 files changed, 61 insertions(+), 24 deletions(-) diff --git a/src/bnhtrade.Core/Data/Amazon/Report/ReportLogic.cs b/src/bnhtrade.Core/Data/Amazon/Report/ReportLogic.cs index b8a6c57..37582ca 100644 --- a/src/bnhtrade.Core/Data/Amazon/Report/ReportLogic.cs +++ b/src/bnhtrade.Core/Data/Amazon/Report/ReportLogic.cs @@ -86,6 +86,25 @@ namespace bnhtrade.Core.Data.Amazon.Report ReportProcessingStatus = ProcessingStatus.NULL; } + + + + + + /// + /// Return a list of report that are currently available filtered parameters set in class + /// + /// report list + protected IList ListAvailableReports() + { + var parameters = new ParameterReportList(); + parameters.reportTypes = new List() { reportType }; + parameters.marketplaceIds.Add(amznConn.GetCurrentMarketplace.ID); + + // request from amazon + return amznConn.Reports.GetReports(parameters); + } + /// /// For reports that require a start and end period to report over. /// @@ -169,6 +188,22 @@ namespace bnhtrade.Core.Data.Amazon.Report } } + DownloadReport(reportId); + } + + protected void DownloadByReportId(string reportId) + { + Init(); + DownloadReport(reportId); + } + + private void DownloadReport(string reportId) + { + if (report == null) + { + WaitWhileProcessing(reportId); + } + // test for processing status if (report.ProcessingStatus == FikaAmazonAPI.AmazonSpApiSDK.Models.Reports.Report.ProcessingStatusEnum.DONE) { @@ -246,12 +281,19 @@ namespace bnhtrade.Core.Data.Amazon.Report } // save to file - string reportFilePath = Config.GetTempFileDirectoryPath() + @"\SP-API-Reports\ " + report.ReportType.ToString() + " reportId_" + reportId + ".txt"; + string dirPath = Config.GetTempFileDirectoryPath() + @"\SP-API-Reports\"; + System.IO.Directory.CreateDirectory(dirPath); + string reportFilePath = dirPath + report.ReportType.ToString() + " reportId_" + reportId + ".txt"; System.IO.File.WriteAllText(reportFilePath, reportString); log.LogInformation("Amazon report #" + reportId + " sucessfully saved to disk."); this.ReportFilePath = reportFilePath; } + + + + + /// /// If a duplicate report has been recently requested, Amazon may return 'FATAL'. This method tests for, and attempts to retrive the duplicate report that is causing the error. /// diff --git a/src/bnhtrade.Core/Data/Amazon/Report/SettlementReport.cs b/src/bnhtrade.Core/Data/Amazon/Report/SettlementReport.cs index aa5a684..5fc4edb 100644 --- a/src/bnhtrade.Core/Data/Amazon/Report/SettlementReport.cs +++ b/src/bnhtrade.Core/Data/Amazon/Report/SettlementReport.cs @@ -1,6 +1,7 @@ using bnhtrade.Core.Data.Amazon.SellingPartnerAPI; using FikaAmazonAPI; using FikaAmazonAPI.Parameter.Report; +using FikaAmazonAPI.Utils; using System; using System.Collections.Generic; using System.Linq; @@ -10,11 +11,9 @@ using static FikaAmazonAPI.Utils.Constants; namespace bnhtrade.Core.Data.Amazon.Report { - public class SettlementReport + public class SettlementReport : ReportLogic { - private AmazonConnection amznConn = new SpApiConnection().Connection; - - public SettlementReport () + public SettlementReport () : base(ReportTypes.GET_V2_SETTLEMENT_REPORT_DATA_FLAT_FILE_V2) { } @@ -25,28 +24,22 @@ namespace bnhtrade.Core.Data.Amazon.Report public List ListAvaliableReports() { UI.Console.WriteLine("Requesting list of avaliable settlement reports form Amazon SP-API"); + var reportList = ListAvailableReports(); - // set parameters - var parameters = new ParameterReportList(); - parameters.reportTypes = new List() { ReportTypes.GET_V2_SETTLEMENT_REPORT_DATA_FLAT_FILE_V2}; - parameters.marketplaceIds.Add(amznConn.GetCurrentMarketplace.ID); - - // request from amazon - var result = amznConn.Reports.GetReports(parameters); - - var returnList = new List(); - foreach (var report in result) + var reportIdList = new List(); + foreach (var report in reportList) { - returnList.Add(report.ReportId); + reportIdList.Add(report.ReportId); } UI.Console.WriteLine("{0} Settlement reports avaible on Amazon SP-API"); - return returnList; + return reportIdList; } - public string GetFile(string reportId) + public string GetReportFile(string reportId) { - return amznConn.Reports.GetReportFile(reportId); + DownloadByReportId(reportId); + return ReportFilePath; } } } diff --git a/src/bnhtrade.Core/Data/Database/Export/CreateSalesInvoice.cs b/src/bnhtrade.Core/Data/Database/Export/CreateSalesInvoice.cs index 1714f09..38354b7 100644 --- a/src/bnhtrade.Core/Data/Database/Export/CreateSalesInvoice.cs +++ b/src/bnhtrade.Core/Data/Database/Export/CreateSalesInvoice.cs @@ -104,7 +104,7 @@ namespace bnhtrade.Core.Data.Database.Export cmd.Parameters.AddWithValue("@invoiceID", invoiceId); cmd.Parameters.AddWithValue("@itemCode", invoiceList[i].InvoiceLineList[j].ItemCode); cmd.Parameters.AddWithValue("@netAmount", invoiceList[i].InvoiceLineList[j].UnitAmount); - cmd.Parameters.AddWithValue("@accountCode", invoiceList[i].InvoiceLineList[j].AccountCode.AccountCode); + cmd.Parameters.AddWithValue("@accountCode", (int)invoiceList[i].InvoiceLineList[j].AccountCode.AccountCode); cmd.Parameters.AddWithValue("@taxAmount", invoiceList[i].InvoiceLineList[j].TaxAmount); cmd.Parameters.AddWithValue("@taxCode", invoiceList[i].InvoiceLineList[j].TaxCode.TaxCode); diff --git a/src/bnhtrade.Core/Logic/Import/AmazonSettlement.cs b/src/bnhtrade.Core/Logic/Import/AmazonSettlement.cs index 8cea48d..8530c81 100644 --- a/src/bnhtrade.Core/Logic/Import/AmazonSettlement.cs +++ b/src/bnhtrade.Core/Logic/Import/AmazonSettlement.cs @@ -1,4 +1,5 @@ -using System.Linq; +using bnhtrade.Core.Data.Amazon.Report; +using System.Linq; namespace bnhtrade.Core.Logic.Import { @@ -10,6 +11,7 @@ namespace bnhtrade.Core.Logic.Import public AmazonSettlement() { + amazonReport = new Data.Amazon.Report.SettlementReport(); } public void SyncDatabase() @@ -53,12 +55,12 @@ namespace bnhtrade.Core.Logic.Import } // import into database - var dbImport = new Data.Database.Import.AmazonSettlementInsert(); + var dbInsert = new Data.Database.Import.AmazonSettlementInsert(); for (int i = 0; i < spapiReportIdList.Count(); i++) { UI.Console.WriteLine("Importing settlement report " + (i + 1) + " of " + spapiReportIdList.Count() + " (ReportID:" + spapiReportIdList[i] + ")."); - var filePath = amazonReport.GetFile(spapiReportIdList[i]); - bool ack = dbImport.ByFlatFile(filePath, spapiReportIdList[i]); + var filePath = amazonReport.GetReportFile(spapiReportIdList[i]); + bool ack = dbInsert.ByFlatFile(filePath, spapiReportIdList[i]); log.LogInformation("Settlment Report imported (ReportID:" + spapiReportIdList[i] + ")."); } From 30174290cf8a6d5f8a64ff196b935622ee7dfe40 Mon Sep 17 00:00:00 2001 From: Bobbie Hodgetts Date: Mon, 9 Jun 2025 21:23:42 +0100 Subject: [PATCH 12/15] pull master into branch * Migrated projects to dotnet8 migrated all projects over to .net8 incomplete feature for gui shipments * Amazon inventory ledger testing and implementation Tested what I can until more data for the Amazon Ledger Detail table comes in * amazon settlement amounts now set to tax inclusive when exporting to invoice * Some updates to the COM lib to attempt to get it to work on .net 8. Unfinished, porting all Access functions over to vs instead * feature exchange rate update automation Automated downloading exchange rates from HMRC and updating the database. Added function call to the console and form applications. Also added a form to show the console output in form application. --- src/bnhtrade.ComTypeLib/Account/Account.cs | 3 +- .../ILRepack.Config.props.old2 | 6 + src/bnhtrade.ComTypeLib/ILRepack.targets | 12 +- src/bnhtrade.ComTypeLib/README.md | 11 + .../bnhtrade.ComTypeLib.csproj | 20 +- .../Data/Database/Account/CreateJournal.cs | 2 +- .../Data/Database/Account/Currency.cs | 310 +++++++++++------- src/bnhtrade.Core/Data/Database/Constants.cs | 14 +- .../Database/Import/AmazonFbaReimbursement.cs | 4 +- .../Database/Import/AmazonSettlementInsert.cs | 10 +- .../Data/Database/SqlWhereBuilder.cs | 15 +- .../Stock/InsertSkuTransactionType.cs | 38 +-- .../Database/Stock/ReadSkuTransactionType.cs | 99 ++---- src/bnhtrade.Core/Logic/Account/Currency.cs | 189 ++++++++++- .../Logic/Import/AmazonFbaCustomerReturn.cs | 2 +- .../Logic/Stock/SkuTransactionCrud.cs | 3 - .../Logic/Stock/SkuTransactionImport.cs | 129 ++++---- .../Logic/Stock/SkuTransactionTypeCrud.cs | 14 +- src/bnhtrade.Core/Logic/Utilities/DateTime.cs | 51 +++ .../Logic/Utilities/DateTimeCheck.cs | 8 +- .../Logic/Utilities/DateTimeParse.cs | 23 -- .../Logic/Utilities/ListFunction.cs | 59 ++++ .../Logic/Utilities/NightlyRoutine.cs | 2 + src/bnhtrade.Core/Logic/Validate/Format.cs | 17 +- .../Model/Account/CurrencyCode.cs | 191 +++++++++++ .../Model/Account/CurrencyExchangeRate.cs | 71 ++++ src/bnhtrade.Core/Model/Account/Invoice.cs | 2 +- .../Model/Credentials/bnhtradeDB.cs | 2 +- .../Model/Stock/SkuTransactionCreate.cs | 4 +- .../Properties/Settings.Designer.cs | 2 +- src/bnhtrade.Core/Test/Account/Account.cs | 13 +- src/bnhtrade.Core/bnhtrade.Core.csproj | 40 ++- src/bnhtrade.ScheduledTasks/Program.cs | 37 ++- .../bnhtrade.ScheduledTasks.csproj | 3 +- src/bnhtrade.gui/FormConsole.Designer.cs | 72 ++++ src/bnhtrade.gui/FormConsole.cs | 44 +++ src/bnhtrade.gui/FormConsole.resx | 120 +++++++ src/bnhtrade.gui/Home.Designer.cs | 104 ++++-- src/bnhtrade.gui/Home.cs | 7 + src/bnhtrade.gui/Home.resx | 4 +- src/bnhtrade.gui/TextBoxStreamWriter.cs | 28 ++ 41 files changed, 1370 insertions(+), 415 deletions(-) create mode 100644 src/bnhtrade.ComTypeLib/ILRepack.Config.props.old2 create mode 100644 src/bnhtrade.ComTypeLib/README.md create mode 100644 src/bnhtrade.Core/Logic/Utilities/DateTime.cs delete mode 100644 src/bnhtrade.Core/Logic/Utilities/DateTimeParse.cs create mode 100644 src/bnhtrade.Core/Logic/Utilities/ListFunction.cs create mode 100644 src/bnhtrade.Core/Model/Account/CurrencyCode.cs create mode 100644 src/bnhtrade.Core/Model/Account/CurrencyExchangeRate.cs create mode 100644 src/bnhtrade.gui/FormConsole.Designer.cs create mode 100644 src/bnhtrade.gui/FormConsole.cs create mode 100644 src/bnhtrade.gui/FormConsole.resx create mode 100644 src/bnhtrade.gui/TextBoxStreamWriter.cs diff --git a/src/bnhtrade.ComTypeLib/Account/Account.cs b/src/bnhtrade.ComTypeLib/Account/Account.cs index 7d42ea3..491ac29 100644 --- a/src/bnhtrade.ComTypeLib/Account/Account.cs +++ b/src/bnhtrade.ComTypeLib/Account/Account.cs @@ -54,8 +54,7 @@ namespace bnhtrade.ComTypeLib public int CurrencyExchangeRateInsert(ConnectionCredential sqlConnCred, int exchangeRateSource, string currencyCode, [MarshalAs(UnmanagedType.Currency)] decimal currencyUnitsPerGbp, DateTime periodStart, DateTime periodEnd, bool checkOverride = false) { - return new Core.Logic.Account.Currency().CurrencyExchangeRateInsert(exchangeRateSource, currencyCode, - currencyUnitsPerGbp, periodStart, periodEnd, checkOverride); + throw new Exception("This function has been retired, now handled by nightly routines"); } } diff --git a/src/bnhtrade.ComTypeLib/ILRepack.Config.props.old2 b/src/bnhtrade.ComTypeLib/ILRepack.Config.props.old2 new file mode 100644 index 0000000..35e9ad5 --- /dev/null +++ b/src/bnhtrade.ComTypeLib/ILRepack.Config.props.old2 @@ -0,0 +1,6 @@ + + + + True + + \ No newline at end of file diff --git a/src/bnhtrade.ComTypeLib/ILRepack.targets b/src/bnhtrade.ComTypeLib/ILRepack.targets index 8bf0115..24ac6c2 100644 --- a/src/bnhtrade.ComTypeLib/ILRepack.targets +++ b/src/bnhtrade.ComTypeLib/ILRepack.targets @@ -1,8 +1,12 @@ + - + + + + + LibraryPath="$(OutputPath)" + /> - \ No newline at end of file + + \ No newline at end of file diff --git a/src/bnhtrade.ComTypeLib/README.md b/src/bnhtrade.ComTypeLib/README.md new file mode 100644 index 0000000..d78c968 --- /dev/null +++ b/src/bnhtrade.ComTypeLib/README.md @@ -0,0 +1,11 @@ +To setup on new computer: + +1. Add the app.local.config to the users ..\AppData\Local\bnhtrade\ folder (create the bnhtrade folder) + +2. CLone bnhtrade solution from the repo + +3. Build bnhtradeCOM project + +4. Register the COM host for COM. With an elevated prompt, navigate to the build directory and run "regsvr32 bnhtradeCOM.comhost.dll" + +5. \ No newline at end of file diff --git a/src/bnhtrade.ComTypeLib/bnhtrade.ComTypeLib.csproj b/src/bnhtrade.ComTypeLib/bnhtrade.ComTypeLib.csproj index 263137a..599052e 100644 --- a/src/bnhtrade.ComTypeLib/bnhtrade.ComTypeLib.csproj +++ b/src/bnhtrade.ComTypeLib/bnhtrade.ComTypeLib.csproj @@ -4,8 +4,17 @@ Library bnhtradeCOM false + + - + + + true + + + + + false @@ -24,15 +33,11 @@ - + - - copy "$(ProjectDir)_RegAsmInstall.bat" "$(TargetDir)" -copy "$(ProjectDir)_RegAsmRefresh.bat" "$(TargetDir)" -copy "$(ProjectDir)_RegAsmUninstall.bat" "$(TargetDir)" bnhtrade COM Type Library bnhtrade bnhtradeCOMAsm @@ -40,4 +45,7 @@ copy "$(ProjectDir)_RegAsmUninstall.bat" "$(TargetDir)" 1.0.0.0 1.0.0.0 + + + \ No newline at end of file diff --git a/src/bnhtrade.Core/Data/Database/Account/CreateJournal.cs b/src/bnhtrade.Core/Data/Database/Account/CreateJournal.cs index 01a4f04..a149dbf 100644 --- a/src/bnhtrade.Core/Data/Database/Account/CreateJournal.cs +++ b/src/bnhtrade.Core/Data/Database/Account/CreateJournal.cs @@ -162,7 +162,7 @@ namespace bnhtrade.Core.Data.Database.Account // currency conversion if (currencyCode != "GBP") { - amount = new Data.Database.Account.Currency().CurrencyConvertToGbp(currencyCode, amount, entryDate); + amount = new Logic.Account.Currency().CurrencyConvertToGbp(currencyCode, amount, entryDate); } // ensure decimal is rounded diff --git a/src/bnhtrade.Core/Data/Database/Account/Currency.cs b/src/bnhtrade.Core/Data/Database/Account/Currency.cs index da36093..5172f47 100644 --- a/src/bnhtrade.Core/Data/Database/Account/Currency.cs +++ b/src/bnhtrade.Core/Data/Database/Account/Currency.cs @@ -1,26 +1,25 @@ using System; using System.Collections.Generic; -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Collections; +using FikaAmazonAPI.AmazonSpApiSDK.Models.FulfillmentOutbound; +using System.Data; namespace bnhtrade.Core.Data.Database.Account { internal class Currency : Connection { - public decimal CurrencyConvertToGbp(string currencyCode, decimal amount, DateTime conversionDate) + /// + /// Returns excahnge rate, in decimal format, for a given currency and datetime + /// + /// currency code + /// dat and time + /// + public decimal? ReadExchangeRate(string currencyCode, DateTime date) { - if (currencyCode == "GBP" || amount == 0M) - { - return amount; - } - - if (currencyCode.Length != 3) - { - throw new Exception("Invalid currency code '" + currencyCode + "'"); - } - using (SqlConnection sqlConn = new SqlConnection(SqlConnectionString)) { sqlConn.Open(); @@ -32,145 +31,210 @@ namespace bnhtrade.Core.Data.Database.Account ", sqlConn)) { cmd.Parameters.AddWithValue("@currencyCode", currencyCode); - cmd.Parameters.AddWithValue("@conversionDate", conversionDate); + cmd.Parameters.AddWithValue("@conversionDate", date); object result = cmd.ExecuteScalar(); if (result != null) { - return amount / Convert.ToDecimal(result); - } - } - - // return reason for no record found - using (SqlCommand cmd = new SqlCommand(@" - SELECT CurrencyUnitsPerGBP - FROM tblAccountExchangeRate - WHERE CurrencyCode=@currencyCode - ", sqlConn)) - { - cmd.Parameters.AddWithValue("@currencyCode", currencyCode); - - object result = cmd.ExecuteScalar(); - if (result == null) - { - throw new Exception("Currency code '" + currencyCode + "' does not exist in Exchange Rate table"); + return Convert.ToDecimal(result); } else { - throw new Exception("Date range for " + currencyCode + " " + conversionDate.ToShortDateString() + " " + - conversionDate.ToLongTimeString() + "' does not exist in Exchange Rate table"); + return null; } } } } - public int CurrencyExchangeRateInsert(int exchangeRateSource, string currencyCode, - decimal currencyUnitsPerGbp, DateTime periodStart, DateTime periodEnd, bool checkOverride = false) + public List ReadExchangeRate(List currencyCodeList = null, DateTime date = default(DateTime)) { + throw new NotImplementedException("Complete, but untested"); + + var returnList = new List(); + + string sql = @" + SELECT AccountEchangeRateID, ExchangeRateSource, CurrencyCode, CurrencyUnitsPerGBP, StartDate, EndDate + FROM tblAccountExchangeRate + WHERE 1=1 "; + + if (date != default(DateTime)) + { + sql = sql + " AND (@dateTime >= StartDate AND @dateTime < endDate) "; + } + + var sqlWhere = new Data.Database.SqlWhereBuilder(); + + // create string list + List stringList = new List(); + if (currencyCodeList != null) + { + stringList = currencyCodeList.ConvertAll(f => f.ToString()); + if (stringList.Any()) + { + sqlWhere.In("CurrencyCode", stringList, "AND"); + } + } + + sql = sql + sqlWhere.SqlWhereString; + + using (SqlConnection sqlConn = new SqlConnection(SqlConnectionString)) + { + sqlConn.Open(); + + using (SqlCommand cmd = new SqlCommand(sql)) + { + if (date != default(DateTime)) + { + cmd.Parameters.AddWithValue("@dateTime", date); + } + if (stringList.Any()) + { + sqlWhere.AddParametersToSqlCommand(cmd); + } + + using (var reader = cmd.ExecuteReader()) + { + while (reader.Read()) + { + int id = reader.GetInt32(0); + int exchangeRateSource = reader.GetInt32(1); + string currencyCodeString = reader.GetString(2); + decimal currencyUnitsPerGBP = reader.GetDecimal(3); + DateTime startDate = DateTime.SpecifyKind( reader.GetDateTime(4), DateTimeKind.Utc); + DateTime endDate = DateTime.SpecifyKind(reader.GetDateTime(5), DateTimeKind.Utc); + + + // convert string to enum + if (Enum.TryParse(currencyCodeString, out Model.Account.CurrencyCode currencyCode) == false) + { + throw new Exception("Failed converting database string to enum"); + } + + var item = new Model.Account.CurrencyExchangeRate( + currencyCode + , exchangeRateSource + , startDate + , endDate + ); + + returnList.Add(item); + } + } + } + } + return returnList; + } + + public List ReadExchangeRateLatest(List currencyCodeList = null) + { + var returnList = new List(); + + string sql = @" + SELECT t1.AccountExchangeRateID, t1.ExchangeRateSource, t1.CurrencyCode, t1.CurrencyUnitsPerGBP, t1.StartDate, t1.EndDate, + t2.maxdate + FROM tblAccountExchangeRate AS t1 + INNER JOIN + (SELECT max(StartDate) AS maxdate, + CurrencyCode + FROM tblAccountExchangeRate + GROUP BY CurrencyCode + "; + + // add any filters + var sqlWhere = new Data.Database.SqlWhereBuilder(); + var codeStringList = new List(); + if (currencyCodeList != null && currencyCodeList.Any() == true) + { + // convert to string list + foreach ( var currencyCode in currencyCodeList) + { + codeStringList.Add(currencyCode.ToString()); + } + + // add to where statement + sqlWhere.In("CurrencyCode", codeStringList, "HAVING"); + sql = sql + sqlWhere.SqlWhereString; + } + + sql = sql + @" ) AS t2 + ON t1.CurrencyCode = t2.CurrencyCode + AND t1.StartDate = t2.maxdate + ORDER BY t1.CurrencyCode;"; + + //query db + using (SqlConnection sqlConn = new SqlConnection(SqlConnectionString)) + { + sqlConn.Open(); + + using (SqlCommand cmd = new SqlCommand(sql, sqlConn)) + { + if (codeStringList.Any()) + { + sqlWhere.AddParametersToSqlCommand(cmd); + } + + using (var reader = cmd.ExecuteReader()) + { + while (reader.Read()) + { + int id = reader.GetInt32(0); + int exchangeRateSource = reader.GetInt32(1); + string currencyCodeString = reader.GetString(2); + decimal currencyUnitsPerGBP = reader.GetDecimal(3); + DateTime startDate = DateTime.SpecifyKind(reader.GetDateTime(4), DateTimeKind.Utc); + DateTime endDate = DateTime.SpecifyKind(reader.GetDateTime(5), DateTimeKind.Utc); + + + // convert string to enum + if (Enum.TryParse(currencyCodeString, out Model.Account.CurrencyCode currencyCode) == false) + { + throw new Exception("Failed converting database string to enum"); + } + + var item = new Model.Account.CurrencyExchangeRate( + currencyCode + , exchangeRateSource + , startDate + , endDate + ); + + returnList.Add(item); + } + } + } + } + return returnList; + } + + public int InsertExchangeRate(int exchangeRateSource, Model.Account.CurrencyCode currencyCode, + decimal currencyUnitsPerGbp, DateTime periodStartUtc, DateTime periodEnd, bool checkOverride = false) + { + // checks + if (periodStartUtc.Kind != DateTimeKind.Utc || periodEnd.Kind != DateTimeKind.Utc) + { + throw new FormatException("Currency date time kind must be UTC"); + } + currencyUnitsPerGbp = decimal.Round(currencyUnitsPerGbp, 4); - periodStart = DateTime.SpecifyKind(periodStart, DateTimeKind.Utc); - periodEnd = DateTime.SpecifyKind(periodEnd, DateTimeKind.Utc); // CHECKS - // HMRC source only - if (exchangeRateSource != 1) - { - throw new Exception("Function does not currently accept exchange rates from sources other than HMRC"); - } - // currency code upper case only - currencyCode = currencyCode.ToUpper(); - if (currencyCode.Length != 3) - { - throw new Exception("Invalid currency code '" + currencyCode + "'"); - } - - if (periodEnd <= periodStart) + if (periodEnd <= periodStartUtc) { throw new Exception("Invalid date period."); } - if (checkOverride == false && (periodEnd - periodStart).Days > 31) + if (checkOverride == false && (periodEnd - periodStartUtc).Days > 31) { throw new Exception("Date period is greater than 31 days."); } - // retirve previous data + // make the insert DateTime? periodEndLast = null; using (SqlConnection sqlConn = new SqlConnection(SqlConnectionString)) { sqlConn.Open(); - using (SqlCommand cmd = new SqlCommand(@" - SELECT Max(tblAccountExchangeRate.EndDate) AS MaxOfEndDate - FROM tblAccountExchangeRate - WHERE (((tblAccountExchangeRate.CurrencyCode) = @currencyCode)) - ", sqlConn)) - { - cmd.Parameters.AddWithValue("@currencyCode", currencyCode); - object obj = cmd.ExecuteScalar(); - - // currency code not existing - if (obj == DBNull.Value && checkOverride == false) - { - throw new Exception("Currency code '" + currencyCode + "' does not exist in table"); - } - // currency code exists - else - { - periodEndLast = DateTime.SpecifyKind(Convert.ToDateTime(obj), DateTimeKind.Utc); - - if (periodStart != periodEndLast) - { - throw new Exception("Invalid period start date -- must equal previous period end-date."); - } - } - } - - // retrive previous exchange rate and check - decimal currencyUnitsPerGbpLast = 0; - if (periodEndLast != null) - { - using (SqlCommand cmd = new SqlCommand(@" - SELECT tblAccountExchangeRate.AccountExchangeRateID, tblAccountExchangeRate.CurrencyUnitsPerGBP - FROM tblAccountExchangeRate - WHERE (tblAccountExchangeRate.EndDate = @periodEndLast) - AND (CurrencyCode = @currencyCode); - ", sqlConn)) - { - cmd.Parameters.AddWithValue("@periodEndLast", periodEndLast); - cmd.Parameters.AddWithValue("@currencyCode", currencyCode); - - using (var reader = cmd.ExecuteReader()) - { - if (reader.Read()) - { - currencyUnitsPerGbpLast = reader.GetDecimal(1); - } - else - { - throw new Exception("Error that shouldn't happen! Check code @ 5129f3e6-2f7e-4883-bc73-b317d8fa4050"); - } - // error if >1 line - if (reader.Read()) - { - string errText = "Multiple lines in currency exchange table for '" + currencyCode + "' where [EndDate]=" + periodEndLast.ToString(); - new Logic.Log.LogEvent().LogError(errText); - throw new Exception(errText); - } - } - } - } - - // check difference between current and previous exchange rates isn't too great - if (checkOverride == false && - (currencyUnitsPerGbpLast > (currencyUnitsPerGbp * 1.05m) || currencyUnitsPerGbpLast < (currencyUnitsPerGbp * 0.95m)) - ) - { - throw new Exception("Difference between supplied and previous exchange rates is greater than 5%"); - } - - // MAKE THE INSERT int recordId = 0; using (SqlCommand cmd = new SqlCommand(@" INSERT INTO tblAccountExchangeRate (ExchangeRateSource, CurrencyCode, CurrencyUnitsPerGBP, StartDate, EndDate) @@ -179,9 +243,9 @@ namespace bnhtrade.Core.Data.Database.Account ", sqlConn)) { cmd.Parameters.AddWithValue("@exchangeRateSource", exchangeRateSource); - cmd.Parameters.AddWithValue("@currencyCode", currencyCode); + cmd.Parameters.AddWithValue("@currencyCode", currencyCode.ToString()); cmd.Parameters.AddWithValue("@currencyUnitsPerGbp", currencyUnitsPerGbp); - cmd.Parameters.AddWithValue("@periodStart", periodStart); + cmd.Parameters.AddWithValue("@periodStart", periodStartUtc); cmd.Parameters.AddWithValue("@periodEnd", periodEnd); recordId = (int)cmd.ExecuteScalar(); diff --git a/src/bnhtrade.Core/Data/Database/Constants.cs b/src/bnhtrade.Core/Data/Database/Constants.cs index 8fae4df..6795e36 100644 --- a/src/bnhtrade.Core/Data/Database/Constants.cs +++ b/src/bnhtrade.Core/Data/Database/Constants.cs @@ -8,14 +8,22 @@ namespace bnhtrade.Core.Data.Database { public static class Constants { + /// + /// Gets the date bnhtrade started trading, UK time (datetime kind unspecified). + /// + /// The UK date and time the business started (datetime kind unspecified) + public static DateTime GetBusinessStartUk() + { + return new Logic.Utilities.DateTime().ConvertUtcToUk(GetBusinessStartUtc()); + } /// - /// Gets the date bnhtrade started trading. + /// Gets the date bnhtrade started trading, as UTC time /// - /// Date and time + /// The UTC date and time the business started (datetime kind UTC) public static DateTime GetBusinessStartUtc() { - DateTime businessStart = new DateTime(2014, 09, 01); + DateTime businessStart = new DateTime(2014, 08, 31, 23, 00, 00); // 2014-09-01 uk date time return DateTime.SpecifyKind(businessStart, DateTimeKind.Utc); } diff --git a/src/bnhtrade.Core/Data/Database/Import/AmazonFbaReimbursement.cs b/src/bnhtrade.Core/Data/Database/Import/AmazonFbaReimbursement.cs index acb78ce..77f2c54 100644 --- a/src/bnhtrade.Core/Data/Database/Import/AmazonFbaReimbursement.cs +++ b/src/bnhtrade.Core/Data/Database/Import/AmazonFbaReimbursement.cs @@ -354,8 +354,8 @@ namespace bnhtrade.Core.Data.Database.Import item.Asin = reader.GetString(8); item.Condition = reader.GetString(9); item.CurrencyUnit = reader.GetString(10); - item.AmountPerUnit = reader.GetInt32(11); - item.AmountTotal = reader.GetInt32(12); + item.AmountPerUnit = reader.GetDecimal(11); + item.AmountTotal = reader.GetDecimal(12); item.QuantityReimbursedCash = reader.GetInt32(13); item.QuantityReimbursedInventory = reader.GetInt32(14); item.QuantityReimbursedTotal = reader.GetInt32(15); diff --git a/src/bnhtrade.Core/Data/Database/Import/AmazonSettlementInsert.cs b/src/bnhtrade.Core/Data/Database/Import/AmazonSettlementInsert.cs index 4719cb9..778368b 100644 --- a/src/bnhtrade.Core/Data/Database/Import/AmazonSettlementInsert.cs +++ b/src/bnhtrade.Core/Data/Database/Import/AmazonSettlementInsert.cs @@ -146,16 +146,16 @@ namespace bnhtrade.Core.Data.Database.Import sqlCommand.Parameters.AddWithValue("@settlementId", settlementRef); } - var parseDateTime = new Core.Logic.Utilities.DateTimeParse(); + var parseDateTime = new Core.Logic.Utilities.DateTime(); if (indexSettlementStartDate == -1 || items[indexSettlementStartDate].Length == 0) { sqlCommand.Parameters.AddWithValue("@settlementStartDate", DBNull.Value); } - else { sqlCommand.Parameters.AddWithValue("@settlementStartDate", parseDateTime.ParseMwsReportDateTime(items[indexSettlementStartDate])); } + else { sqlCommand.Parameters.AddWithValue("@settlementStartDate", parseDateTime.ParseIsoDateTimeString(items[indexSettlementStartDate])); } if (indexSettlementEndDate == -1 || items[indexSettlementEndDate].Length == 0) { sqlCommand.Parameters.AddWithValue("@settlementEndDate", DBNull.Value); } - else { sqlCommand.Parameters.AddWithValue("@settlementEndDate", parseDateTime.ParseMwsReportDateTime(items[indexSettlementEndDate])); } + else { sqlCommand.Parameters.AddWithValue("@settlementEndDate", parseDateTime.ParseIsoDateTimeString(items[indexSettlementEndDate])); } if (indexDepositDate == -1 || items[indexDepositDate].Length == 0) { sqlCommand.Parameters.AddWithValue("@depositDate", DBNull.Value); } - else { sqlCommand.Parameters.AddWithValue("@depositDate", parseDateTime.ParseMwsReportDateTime(items[indexDepositDate])); } + else { sqlCommand.Parameters.AddWithValue("@depositDate", parseDateTime.ParseIsoDateTimeString(items[indexDepositDate])); } if (indexTotalAmount == -1 || items[indexTotalAmount].Length == 0) { sqlCommand.Parameters.AddWithValue("@totalAmount", DBNull.Value); } else { sqlCommand.Parameters.AddWithValue("@settlementotalAmounttId", settlementAmount); } @@ -245,7 +245,7 @@ namespace bnhtrade.Core.Data.Database.Import else { sqlCommand.Parameters.AddWithValue("@FulfillmentRef", items[indexFulfillmentId]); } if (indexPostedDateTime == -1 || items[indexPostedDateTime].Length == 0) { sqlCommand.Parameters.AddWithValue("@PostedDateTimeUTC", DBNull.Value); } - else { sqlCommand.Parameters.AddWithValue("@PostedDateTimeUTC", new Logic.Utilities.DateTimeParse().ParseMwsReportDateTime(items[indexPostedDateTime])); } + else { sqlCommand.Parameters.AddWithValue("@PostedDateTimeUTC", new Logic.Utilities.DateTime().ParseIsoDateTimeString(items[indexPostedDateTime])); } if (indexOrderItemCode == -1 || items[indexOrderItemCode].Length == 0) { sqlCommand.Parameters.AddWithValue("@OrderItemCode", DBNull.Value); } else { sqlCommand.Parameters.AddWithValue("@OrderItemCode", long.Parse(items[indexOrderItemCode])); } diff --git a/src/bnhtrade.Core/Data/Database/SqlWhereBuilder.cs b/src/bnhtrade.Core/Data/Database/SqlWhereBuilder.cs index 812e4a7..73687f1 100644 --- a/src/bnhtrade.Core/Data/Database/SqlWhereBuilder.cs +++ b/src/bnhtrade.Core/Data/Database/SqlWhereBuilder.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Data.SqlClient; +using Microsoft.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -53,7 +54,19 @@ namespace bnhtrade.Core.Data.Database ParameterList = new Dictionary(); } - public void AddParametersToSqlCommand(SqlCommand cmd) + // delete this once all references use the new Microsoft.Data.SqlClient + public void AddParametersToSqlCommand(System.Data.SqlClient.SqlCommand cmd) + { + if (ParameterList != null) + { + foreach (var item in ParameterList) + { + cmd.Parameters.AddWithValue(item.Key, item.Value); + } + } + } + + public void AddParametersToSqlCommand(Microsoft.Data.SqlClient.SqlCommand cmd) { if (ParameterList != null) { diff --git a/src/bnhtrade.Core/Data/Database/Stock/InsertSkuTransactionType.cs b/src/bnhtrade.Core/Data/Database/Stock/InsertSkuTransactionType.cs index 83d483d..4a6236f 100644 --- a/src/bnhtrade.Core/Data/Database/Stock/InsertSkuTransactionType.cs +++ b/src/bnhtrade.Core/Data/Database/Stock/InsertSkuTransactionType.cs @@ -6,23 +6,19 @@ namespace bnhtrade.Core.Data.Database.Stock { public class InsertSkuTransactionType : Connection { - /// - /// The insert command will not participate in any amibent transaction scope. Default is true. - /// - public bool SuppressTransactionScope { get; set; } = true; - /// /// Creates a new SKU Transaction Type /// /// /// + /// The insert command will not participate in any amibent transaction scope /// ID of the created record /// - public int Create(string skuTransactionCode, int stockJournalTypeId) + public int Create(string skuTransactionCode, int stockJournalTypeId, bool transactionScopeSuppress = false) { int id; var scopeOption = new TransactionScopeOption(); - if (SuppressTransactionScope) + if (transactionScopeSuppress) { scopeOption = TransactionScopeOption.Suppress; } @@ -32,12 +28,13 @@ namespace bnhtrade.Core.Data.Database.Stock } using (TransactionScope scope = new TransactionScope(scopeOption)) - using (SqlConnection conn = new SqlConnection(SqlConnectionString)) { - conn.Open(); + using (SqlConnection conn = new SqlConnection(SqlConnectionString)) + { + conn.Open(); - // insert new and retrive new value - using (SqlCommand cmd = new SqlCommand(@" + // insert new and retrive new value + using (SqlCommand cmd = new SqlCommand(@" INSERT INTO tblStockSkuTransactionType ( TypeName, StockJournalTypeID, TypeCode ) OUTPUT @@ -45,19 +42,20 @@ namespace bnhtrade.Core.Data.Database.Stock VALUES ( @typeName, @stockJournalTypeId, @typeCode ); ", conn)) - { - cmd.Parameters.AddWithValue("@typeName", skuTransactionCode); - cmd.Parameters.AddWithValue("@typeCode", skuTransactionCode); - cmd.Parameters.AddWithValue("@stockJournalTypeId", stockJournalTypeId); + { + cmd.Parameters.AddWithValue("@typeName", skuTransactionCode); + cmd.Parameters.AddWithValue("@stockJournalTypeId", stockJournalTypeId); + cmd.Parameters.AddWithValue("@typeCode", skuTransactionCode); - object obj = cmd.ExecuteScalar(); + object obj = cmd.ExecuteScalar(); - if (obj == null || obj == DBNull.Value) - throw new Exception("tblStockSkuTransactionType insert operation returned null"); + if (obj == null || obj == DBNull.Value) + throw new Exception("tblStockSkuTransactionType insert operation returned null"); - id = (int)obj; + id = (int)obj; + } + scope.Complete(); } - scope.Complete(); } return id; } diff --git a/src/bnhtrade.Core/Data/Database/Stock/ReadSkuTransactionType.cs b/src/bnhtrade.Core/Data/Database/Stock/ReadSkuTransactionType.cs index 8f4cedd..df2d71d 100644 --- a/src/bnhtrade.Core/Data/Database/Stock/ReadSkuTransactionType.cs +++ b/src/bnhtrade.Core/Data/Database/Stock/ReadSkuTransactionType.cs @@ -4,7 +4,9 @@ using System.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Transactions; using Dapper; +using static System.Formats.Asn1.AsnWriter; namespace bnhtrade.Core.Data.Database.Stock { @@ -14,81 +16,10 @@ namespace bnhtrade.Core.Data.Database.Stock { } - /// - /// Depriciated, delete when not required by other code - /// - /// - /// - /// - public int GetTypeId(string typeCode) + private List Execute(string sqlWhere, DynamicParameters param, bool transactionScopeSuppress = false) { - /* GetStockTransactionTypeId return meanings - * >0 use as the TypeId when inserting transaction - * 0 Skip transpose, type doesn't exist or is new (not reviewed yet) - * -1 Type import/transpose is disabled, IsProcessed=TRUE StockTransactionID=NULL */ + var returnList = new List(); - // old optional parameters - // , bool onNewReturnId = false, bool onNewDisableInsert = false - - if (typeCode.Length == 0) - { - throw new Exception("Empty match string passed to method"); - } - using (SqlConnection sqlConn = new SqlConnection(SqlConnectionString)) - { - sqlConn.Open(); - using (SqlCommand cmd = new SqlCommand(@" - SELECT - StockSkuTransactionTypeID, - IsNewReviewRequired, - TransactionImportEnabled - FROM - tblStockSkuTransactionType - WHERE - TypeCode=@typeCode; - ", sqlConn)) - { - cmd.Parameters.AddWithValue("@typeCode", typeCode); - - using (SqlDataReader reader = cmd.ExecuteReader()) - { - if (reader.Read()) - { - int transactionTypeId = reader.GetInt32(0); - bool isNew = reader.GetBoolean(1); - bool importEnabled = reader.GetBoolean(2); - - if (isNew == true) - { - // return 0 and 'skip' item - return 0; - } - else if (importEnabled == false) - { - // mark IsProcessed=true and leave transactionId=null - return -1; - } - else if (transactionTypeId > 0) - { - - return transactionTypeId; - } - else - { - throw new Exception("Sku TransactionTypeId lookup method failed, is one of the 'enabled' boolean on table set to null?"); - } - } - else - { - return 0; - } - } - } - } - } - - private List Execute(string sqlWhere, DynamicParameters param) - { string sql = @" SELECT tblStockSkuTransactionType.StockSkuTransactionTypeID AS TypeId ,tblStockSkuTransactionType.TypeName @@ -117,13 +48,25 @@ namespace bnhtrade.Core.Data.Database.Stock using (SqlConnection conn = new SqlConnection(SqlConnectionString)) { - conn.Open(); - - return conn.Query(sql, param).ToList(); + if (transactionScopeSuppress) + { + using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Suppress)) + { + conn.Open(); + returnList = conn.Query(sql, param).ToList(); + } + } + else + { + conn.Open(); + returnList = conn.Query(sql, param).ToList(); + } } + + return returnList; } - public List ByTypeCode(List typeCodeList) + public List ByTypeCode(List typeCodeList, bool transactionScopeSuppress = false) { typeCodeList.RemoveAll(string.IsNullOrWhiteSpace); @@ -138,7 +81,7 @@ namespace bnhtrade.Core.Data.Database.Stock return Execute(sqlWhere, param); } - public List ByTypeName(List typeName) + public List ByTypeName(List typeName, bool transactionScopeSuppress = false) { typeName.RemoveAll(string.IsNullOrWhiteSpace); diff --git a/src/bnhtrade.Core/Logic/Account/Currency.cs b/src/bnhtrade.Core/Logic/Account/Currency.cs index 0aa682d..49ced0b 100644 --- a/src/bnhtrade.Core/Logic/Account/Currency.cs +++ b/src/bnhtrade.Core/Logic/Account/Currency.cs @@ -1,23 +1,200 @@ -using System; +using FikaAmazonAPI.ConstructFeed.Messages; +using System; using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Data.SqlClient; +using System.Globalization; using System.Linq; using System.Text; +using System.Threading; using System.Threading.Tasks; +using System.Xml.Linq; namespace bnhtrade.Core.Logic.Account { public class Currency { + Log.LogEvent log = new Log.LogEvent(); + public decimal CurrencyConvertToGbp(string currencyCode, decimal amount, DateTime conversionDate) { - return new Data.Database.Account.Currency().CurrencyConvertToGbp(currencyCode, amount, conversionDate); + if (currencyCode == "GBP" || amount == 0M) + { + return amount; + } + + if (currencyCode.Length != 3) + { + throw new Exception("Invalid currency code '" + currencyCode + "'"); + } + + var db = new Data.Database.Account.Currency(); + var exchageRate = db.ReadExchangeRate(currencyCode, conversionDate); + + if (exchageRate != null) + { + return amount / Convert.ToDecimal(exchageRate); + } + else + { + throw new Exception("Currency code '" + currencyCode + "' or date " + conversionDate.ToShortDateString() + " " + conversionDate.ToLongTimeString() + "' does not exist in the Exchange Rate table"); + } + } - public int CurrencyExchangeRateInsert(int exchangeRateSource, string currencyCode, - decimal currencyUnitsPerGbp, DateTime periodStart, DateTime periodEnd, bool checkOverride = false) + private DateTime GetHmrcMaxPeriodAvaible() { - return new Data.Database.Account.Currency().CurrencyExchangeRateInsert(exchangeRateSource, currencyCode, - currencyUnitsPerGbp, periodStart, periodEnd, checkOverride); + // HMRC monthly sxchange rates are published on the penultimate Thursday of the month before + // For some leeway we'll use the penultimate Friday + + // find penultimate Friday for current month + var ukTimeNow = new Logic.Utilities.DateTime().ConvertUtcToUk(DateTime.UtcNow); + var monthDayCount = DateTime.DaysInMonth(ukTimeNow.Year, ukTimeNow.Month); + var thisMonthPenultimateFriday = DateTime.SpecifyKind(new DateTime(ukTimeNow.Year, ukTimeNow.Month, monthDayCount), DateTimeKind.Unspecified); + int count = 0; + int fridayCount = 0; + while (count != 15) + { + if (thisMonthPenultimateFriday.DayOfWeek == DayOfWeek.Friday) + { + fridayCount++; + if (fridayCount == 2) + { + break; + } + } + thisMonthPenultimateFriday = thisMonthPenultimateFriday.AddDays(-1); + count++; + } + + if (count == 15) + { + throw new Exception("Something went wrong here ErrorID:ef7f5d8f-0f7b-4014-aa65-421ecd5d7367"); + } + + var mostRecentPeriodAvaible = DateTime.SpecifyKind(new DateTime(ukTimeNow.Year, ukTimeNow.Month, 1), DateTimeKind.Unspecified); ; + if (ukTimeNow >= thisMonthPenultimateFriday) + { + mostRecentPeriodAvaible = mostRecentPeriodAvaible.AddMonths(1); + } + + return mostRecentPeriodAvaible; + } + + public void UpdateHmrcExchageRates() + { + log.LogInformation("Starting update database HMRC exchange rates"); + + int exchangeRateSourceId = 1; // id for hmrc + + // retrive most recent data from db + var db = new Data.Database.Account.Currency(); + var dbLatestRates = db.ReadExchangeRateLatest(); + + // sanity check, make sure there are no duplicates + int count = 0; + foreach (var exchageRate in dbLatestRates) + { + count = 0; + var currency = exchageRate.CurrencyCode; + foreach (var subExchageRate in dbLatestRates) + { + if (exchageRate.CurrencyCode == subExchageRate.CurrencyCode) + { + count = 1; + } + } + if (count > 1) + { + throw new FormatException("Datebase returned duplicate information"); + } + } + + // test for no data (first time running) + var hmrcMonthToRetrive = new DateTime(); + if (dbLatestRates.Any() == false) + { + hmrcMonthToRetrive = Data.Database.Constants.GetBusinessStartUk(); + } + + // set first/earliest month to retrive from hmrc website + foreach (var exchageRate in dbLatestRates) + { + var dbEndDateTime = exchageRate.DateTimeEndUk; + + if (hmrcMonthToRetrive == default(DateTime)) + { + hmrcMonthToRetrive = dbEndDateTime; + } + else + { + if (dbEndDateTime < hmrcMonthToRetrive) + { + hmrcMonthToRetrive = dbEndDateTime; + } + } + } + + // check - more coding required to retrive periods before 2021-01-01 + if (hmrcMonthToRetrive < DateTime.SpecifyKind(new DateTime(2021, 1, 1), DateTimeKind.Unspecified)) + { + throw new Exception("This function does not currently retirve exchange rates from HMRC for dates before 2021-01-01"); + } + + // check if retrival from hmrc is required + var hmrcMaxMonthAvaible = GetHmrcMaxPeriodAvaible(); + if (hmrcMonthToRetrive.Year == hmrcMaxMonthAvaible.Year && hmrcMonthToRetrive.Month > hmrcMaxMonthAvaible.Month) + { + // nothing to retrive + log.LogInformation("Exchange rates curretly up to date, exiting."); + return; + } + + // get info from hmrc and insert data in db + while (hmrcMonthToRetrive <= hmrcMaxMonthAvaible) + { + count = 0; + + var url = new string( + "https://www.trade-tariff.service.gov.uk/api/v2/exchange_rates/files/monthly_xml_" + + hmrcMonthToRetrive.Year.ToString() + + "-" + + hmrcMonthToRetrive.Month.ToString() + + ".xml" + ); + var xd = new XDocument(); + xd = XDocument.Load(url); + + foreach (var exchageRate in dbLatestRates) + { + if (exchageRate.DateTimeStartUtc < hmrcMonthToRetrive) + { + //retrive exchange rate from xml + XElement node = xd.Root.Elements("exchangeRate").Where(e => e.Element("currencyCode").Value == exchageRate.CurrencyCode.ToString()).FirstOrDefault(); + decimal rate = decimal.Parse(node.Element("rateNew").Value); + rate = decimal.Round(rate, 4); + + // insert into db + new Data.Database.Account.Currency().InsertExchangeRate( + exchangeRateSourceId + , exchageRate.CurrencyCode + , rate + , new Utilities.DateTime().ConvertUkToUtc(hmrcMonthToRetrive) + , new Utilities.DateTime().ConvertUkToUtc(hmrcMonthToRetrive.AddMonths(1)) + ); + + count++; + } + } + + log.LogInformation( + count + " new exchange rate(s) added to database for " + hmrcMonthToRetrive.ToString("MMMM") + " " + hmrcMonthToRetrive.Year.ToString() + ); + + hmrcMonthToRetrive = hmrcMonthToRetrive.AddMonths(1); + } + + log.LogInformation("Updating database currency exchange rates complete."); } } } diff --git a/src/bnhtrade.Core/Logic/Import/AmazonFbaCustomerReturn.cs b/src/bnhtrade.Core/Logic/Import/AmazonFbaCustomerReturn.cs index 206fd87..193db10 100644 --- a/src/bnhtrade.Core/Logic/Import/AmazonFbaCustomerReturn.cs +++ b/src/bnhtrade.Core/Logic/Import/AmazonFbaCustomerReturn.cs @@ -45,7 +45,7 @@ namespace bnhtrade.Core.Logic.Import dateLog.SetDateTimeUtc(reportName, utcEndDate); scope.Complete(); } - log.LogInformation("Amazon report '" + reportName + "' sync with database comlpete."); + log.LogInformation("Amazon report '" + reportName + "' sync with database complete."); } } } diff --git a/src/bnhtrade.Core/Logic/Stock/SkuTransactionCrud.cs b/src/bnhtrade.Core/Logic/Stock/SkuTransactionCrud.cs index 1bf36d8..4e8637d 100644 --- a/src/bnhtrade.Core/Logic/Stock/SkuTransactionCrud.cs +++ b/src/bnhtrade.Core/Logic/Stock/SkuTransactionCrud.cs @@ -126,9 +126,6 @@ namespace bnhtrade.Core.Logic.Stock /// public int Create(Model.Stock.SkuTransactionCreate skuTransaction) { - // need to add function to check if transaction type exists, if not, create a new one. - throw new NotImplementedException(); - if (skuTransaction == null) { throw new Exception(err + "Object was null"); diff --git a/src/bnhtrade.Core/Logic/Stock/SkuTransactionImport.cs b/src/bnhtrade.Core/Logic/Stock/SkuTransactionImport.cs index 27618d6..1b1faef 100644 --- a/src/bnhtrade.Core/Logic/Stock/SkuTransactionImport.cs +++ b/src/bnhtrade.Core/Logic/Stock/SkuTransactionImport.cs @@ -39,10 +39,10 @@ namespace bnhtrade.Core.Logic.Stock private string ConstructTransactionTypeCode(Model.Import.AmazonFbaInventoryLedgerDetail record) { - if (string.IsNullOrEmpty(record.Reason)) - { - return null; - } + //if (string.IsNullOrEmpty(record.Reason)) + //{ + // return null; + //} string transactionCode = "<" + record.EventType + ">"; @@ -66,33 +66,26 @@ namespace bnhtrade.Core.Logic.Stock } /// - /// Imports/Transaposes all data required for reconcilation, into the sku transaction table. + /// Imports/Transaposes all required data into sku transaction table for reconcilation. /// public void ImportAll() { - bool inventoryLedgerDetail = false; - bool reimbursement = false; + string methodName = "'Import all' data to 'Stock SKU Transactions'"; - while (true) + log.LogInformation(methodName + " started..."); + + try { - try - { - if (true) - { - if (inventoryLedgerDetail == false) { inventoryLedgerDetail = true; ImportAmazonFbaLedgerDetail(); } - if (reimbursement == false) { reimbursement = true; ImportAmazonFbaReimbursement(); } - } - - break; - } - catch (Exception ex) - { - log.LogError( - "Exception caught running Importing amazon reports in the SKU transaction table, see for further details", - ex.ToString() - ); - } + ImportAmazonFbaLedgerDetail(); + ImportAmazonFbaReimbursement(); } + catch + { + log.LogError(methodName + " did not complete."); + throw; + } + + log.LogInformation(methodName + " complete."); } /// @@ -101,7 +94,9 @@ namespace bnhtrade.Core.Logic.Stock /// public void ImportAmazonFbaReimbursement() { - throw new NotImplementedException("Needs testing"); + string methodName = "Import 'Amazon FBA Reimbursement' into 'Stock SKU Transactions'"; + + //throw new NotImplementedException("Needs testing"); /* * Not to be used for stock reconciliation! A single stock item can have multiple reimburesements aginst it. @@ -112,9 +107,9 @@ namespace bnhtrade.Core.Logic.Stock * and also the 'Cost of goods' amounts moved to the appropreate account id */ - log.LogInformation("Starting TransposeFbaRemovalOrderReport()"); - int transposeCount = 0; - int transposeSkip = 0; + log.LogInformation(methodName + " started..."); + int importedCount = 0; + int processedCount = 0; var dbAmznReport = new Data.Database.Import.AmazonFbaReimbursement(); var dbTransType = new Logic.Stock.SkuTransactionTypeCrud(); @@ -128,6 +123,8 @@ namespace bnhtrade.Core.Logic.Stock var transTypeCodeList = new List(); foreach (var item in importList) { + processedCount++; + transTypeCodeList.Add(ConstructTransactionTypeCode(item, false)); // any that reimburse inventory, will have two entries if(item.QuantityReimbursedInventory > 0) @@ -170,7 +167,7 @@ namespace bnhtrade.Core.Logic.Stock // don't go any further until the transaction-type has been reviewed/setup if (foundNewType) { - log.LogWarning("Cannot complete ImportAmazonFbaReimbursement, new 'Stock Trnasaction Type' found. Review required/"); + log.LogWarning(methodName + " unable to complete. New 'Stock Trnasaction Type' found. Review required/"); return; } @@ -189,7 +186,7 @@ namespace bnhtrade.Core.Logic.Stock if (transType.IsNewReviewRequired) { - throw new Exception("Fail safe: Buggy code, should not get here!"); + throw new Exception(methodName + " fail safe: Buggy code, should not get here!"); } else if (transType.TransactionImportEnabled) { @@ -214,7 +211,7 @@ namespace bnhtrade.Core.Logic.Stock if (transType.IsNewReviewRequired) { - throw new Exception("Fail safe: Buggy code, should not get here!"); + throw new Exception(methodName + " fail safe: Buggy code, should not get here!"); } else if (transType.TransactionImportEnabled) { @@ -233,20 +230,26 @@ namespace bnhtrade.Core.Logic.Stock } // update the amazon report table dbAmznReport.UpdateIsProcessed(item.FbaReimbursementReportID, true, transId); - transposeCount = transposeCount + 1; + importedCount++; } // drop out of loop scope.Complete(); } Console.Write("\r"); - log.LogInformation("ProcessFbaReimbursementData() complete, " + transposeCount + " total records transposed, " + transposeSkip + " records skipped."); + + log.LogInformation( + methodName + " complete. Records transferred/processed " + importedCount + "/" + processedCount + ); } catch (Exception ex) { - log.LogError("Exception catch, aborting ProcessFbaReimbursementData(), see detailed info. " - + transposeCount + " total records completed, " + transposeSkip + " records skipped.", ex.ToString()); - } + log.LogError( + methodName + " aborted due an exception, no records where modified." + , ex.ToString() + ); + throw; + } } /// @@ -255,12 +258,11 @@ namespace bnhtrade.Core.Logic.Stock /// public void ImportAmazonFbaLedgerDetail() { - // Done but needs testing!! - throw new NotImplementedException("Done but needs testing!!"); + string methodName = "Import 'Amazon FBA Ledger Detail' into 'Stock SKU Transactions'"; - log.LogInformation("Starting TransposeFbaAdustmentReport()"); - int transposeCount = 0; - int transposeSkip = 0; + log.LogInformation(methodName + " started"); + int transferredCount = 0; + int processedCount = 0; using (var scope = new TransactionScope()) { @@ -275,6 +277,8 @@ namespace bnhtrade.Core.Logic.Stock var transCodeToJournalTypeId = new Dictionary(); foreach (var item in reportDict) { + processedCount++; + // test for internal Amazon stuff that we don't care about and mark as processed if (item.Value.EventType == "WhseTransfers") { @@ -340,21 +344,25 @@ namespace bnhtrade.Core.Logic.Stock } } - // check for any new types codes, and add them if ther are - var dbTransType = new Logic.Stock.SkuTransactionTypeCrud(); - var transTypeList = dbTransType.GetByTypeCode(transCodeToJournalTypeId.Keys.ToList()); - - foreach ( var transType in transTypeList) + // check for any new types codes, remove existing from list and add remaing to db + using (TransactionScope scope2 = new TransactionScope(TransactionScopeOption.Suppress)) { - if (transCodeToJournalTypeId.ContainsKey(transType.Key)) + var dbTransType = new Logic.Stock.SkuTransactionTypeCrud(); + + var transTypeList = dbTransType.GetByTypeCode(transCodeToJournalTypeId.Keys.ToList()); + + foreach (var transType in transTypeList) { - transCodeToJournalTypeId.Remove(transType.Key); + if (transCodeToJournalTypeId.ContainsKey(transType.Key)) + { + transCodeToJournalTypeId.Remove(transType.Key); + } } - } - foreach (var newItem in transCodeToJournalTypeId) - { - dbTransType.Create(newItem.Key, newItem.Value); + foreach (var newItem in transCodeToJournalTypeId) + { + dbTransType.Create(newItem.Key, newItem.Value); + } } // finally, add the transction list to the table @@ -363,33 +371,28 @@ namespace bnhtrade.Core.Logic.Stock { int id = dbTransaction.Create(item); dbImport.UpdateIsProcessed((int)item.ForeignKey, id); + transferredCount++; } scope.Complete(); log.LogInformation( - "TransposeFbaAdustmentReport() complete, " + transposeCount + " total records transposed, " + transposeSkip + " records skipped." + methodName + " complete. Records transferred/processed " + transferredCount + "/" + processedCount ); - if (transposeSkip > 0) - { - log.LogInformation( - transposeSkip + " number records skipped during TransposeFbaAdustmentReport() operation." - ); - } } catch (Exception ex) { scope.Dispose(); log.LogError( - "Exception catch, aborting TransposeFbaAdustmentReport(), see detailed info. " - + transposeCount + " total records completed, " + transposeSkip + " records skipped." + methodName + " aborted, no records modified. See additional info exception details." , ex.ToString() ); + + throw; } } - return; } } } diff --git a/src/bnhtrade.Core/Logic/Stock/SkuTransactionTypeCrud.cs b/src/bnhtrade.Core/Logic/Stock/SkuTransactionTypeCrud.cs index 7192928..62e9352 100644 --- a/src/bnhtrade.Core/Logic/Stock/SkuTransactionTypeCrud.cs +++ b/src/bnhtrade.Core/Logic/Stock/SkuTransactionTypeCrud.cs @@ -25,15 +25,15 @@ namespace bnhtrade.Core.Logic.Stock /// /// Id for new record entry /// Transaction type code already exists - public int Create(string skuTransactionTypeCode, int stockJournalTypeId) + public int Create(string skuTransactionTypeCode, int stockJournalTypeId, bool transactionScopeSuppress = false) { //check to see if type already exists - var result = dbRead.ByTypeCode(new List { skuTransactionTypeCode }); + var result = dbRead.ByTypeCode(new List { skuTransactionTypeCode }, transactionScopeSuppress); if (result.Any()) throw new InvalidOperationException("Create SKU Transaction Type failed, typecode already exists failed"); // okay to proceed - int id = new Data.Database.Stock.InsertSkuTransactionType().Create(skuTransactionTypeCode, stockJournalTypeId); + int id = new Data.Database.Stock.InsertSkuTransactionType().Create(skuTransactionTypeCode, stockJournalTypeId, transactionScopeSuppress); return id; } @@ -42,14 +42,14 @@ namespace bnhtrade.Core.Logic.Stock /// /// /// The object, or null - public Model.Stock.SkuTransactionType GetByTypeCode(string typeCode) + public Model.Stock.SkuTransactionType GetByTypeCode(string typeCode, bool transactionScopeSuppress = false) { if (string.IsNullOrWhiteSpace(typeCode)) { return null; } - var result = dbRead.ByTypeCode(new List { typeCode }); + var result = dbRead.ByTypeCode(new List { typeCode }, transactionScopeSuppress); if (result.Any()) { @@ -66,7 +66,7 @@ namespace bnhtrade.Core.Logic.Stock /// /// list of transaction type codes /// DIctionary key=transactionTypeCode, value=transactionType object - public Dictionary GetByTypeCode(List typeCodeList) + public Dictionary GetByTypeCode(List typeCodeList, bool transactionScopeSuppress = false) { var returnDict = new Dictionary(); if (!typeCodeList.Any()) @@ -74,7 +74,7 @@ namespace bnhtrade.Core.Logic.Stock return returnDict; } - var dbResult = dbRead.ByTypeCode(typeCodeList); + var dbResult = dbRead.ByTypeCode(typeCodeList, transactionScopeSuppress); foreach(var item in dbResult) { diff --git a/src/bnhtrade.Core/Logic/Utilities/DateTime.cs b/src/bnhtrade.Core/Logic/Utilities/DateTime.cs new file mode 100644 index 0000000..efb1e45 --- /dev/null +++ b/src/bnhtrade.Core/Logic/Utilities/DateTime.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace bnhtrade.Core.Logic.Utilities +{ + public class DateTime + { + public System.DateTime ConvertUkToUtc(System.DateTime ukDateTime) + { + if (ukDateTime.Kind == DateTimeKind.Local && TimeZoneInfo.Local.Id != "GMT Standard Time") + { + throw new System.ArgumentException("DateTime kind set to local, local is not set to 'GMT Standard Time'"); + } + else if (ukDateTime.Kind == DateTimeKind.Utc) + { + throw new System.ArgumentException("DateTime kind is UTC"); + } + + TimeZoneInfo ukZone = TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time"); + System.DateTime ukTime = TimeZoneInfo.ConvertTimeToUtc(ukDateTime, ukZone); + return ukTime; // is returned as DateTimeKind 'unspecified' + } + + public System.DateTime ConvertUtcToUk(System.DateTime utcDateTime) + { + if (utcDateTime.Kind != DateTimeKind.Utc) + { + throw new System.ArgumentException("DateTime kind is not UTC"); + } + + TimeZoneInfo ukZone = TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time"); + System.DateTime ukTime = TimeZoneInfo.ConvertTimeFromUtc(utcDateTime, ukZone); + return ukTime; // is returned as DateTimeKind 'unspecified' + } + + public System.DateTime ParseIsoDateTimeString(string reportDateTime) + { + string isoDateTime = + reportDateTime.Substring(6, 4) + "-" + + reportDateTime.Substring(3, 2) + "-" + + reportDateTime.Substring(0, 2) + "T" + + reportDateTime.Substring(11, 2) + ":" + + reportDateTime.Substring(14, 2) + ":" + + reportDateTime.Substring(17, 2) + "Z"; + return System.DateTime.Parse(isoDateTime); + } + } +} diff --git a/src/bnhtrade.Core/Logic/Utilities/DateTimeCheck.cs b/src/bnhtrade.Core/Logic/Utilities/DateTimeCheck.cs index dacc3fe..a1a2d2f 100644 --- a/src/bnhtrade.Core/Logic/Utilities/DateTimeCheck.cs +++ b/src/bnhtrade.Core/Logic/Utilities/DateTimeCheck.cs @@ -8,9 +8,9 @@ namespace bnhtrade.Core.Logic.Utilities { public class DateTimeCheck : Validate.Validate { - public bool IsUtc(DateTime dateTimeToCheck) + public bool IsUtc(System.DateTime dateTimeToCheck) { - if (dateTimeToCheck == default(DateTime)) + if (dateTimeToCheck == default(System.DateTime)) { ValidationResultAdd( "DateTime value set to default."); return false; @@ -22,9 +22,9 @@ namespace bnhtrade.Core.Logic.Utilities } return true; } - public bool IsLocal(DateTime dateTimeToCheck) + public bool IsLocal(System.DateTime dateTimeToCheck) { - if (dateTimeToCheck == default(DateTime)) + if (dateTimeToCheck == default(System.DateTime)) { ValidationResultAdd("DateTime value set to default."); return false; diff --git a/src/bnhtrade.Core/Logic/Utilities/DateTimeParse.cs b/src/bnhtrade.Core/Logic/Utilities/DateTimeParse.cs deleted file mode 100644 index 970a387..0000000 --- a/src/bnhtrade.Core/Logic/Utilities/DateTimeParse.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace bnhtrade.Core.Logic.Utilities -{ - public class DateTimeParse - { - public DateTime ParseMwsReportDateTime(string reportDateTime) - { - string isoDateTime = - reportDateTime.Substring(6, 4) + "-" + - reportDateTime.Substring(3, 2) + "-" + - reportDateTime.Substring(0, 2) + "T" + - reportDateTime.Substring(11, 2) + ":" + - reportDateTime.Substring(14, 2) + ":" + - reportDateTime.Substring(17, 2) + "Z"; - return DateTime.Parse(isoDateTime); - } - } -} diff --git a/src/bnhtrade.Core/Logic/Utilities/ListFunction.cs b/src/bnhtrade.Core/Logic/Utilities/ListFunction.cs new file mode 100644 index 0000000..5712e89 --- /dev/null +++ b/src/bnhtrade.Core/Logic/Utilities/ListFunction.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace bnhtrade.Core.Logic.Utilities +{ + public class ListFunction + { + public ListFunction() { } + + /// + /// Outputs a unique list from an input list + /// + /// + /// + /// Unique list + public List UniqueList(List inputList, bool removeNullorWhitespace = true) + { + List outputList = new List(); + + foreach (string input in inputList) + { + if (string.IsNullOrWhiteSpace(input) && removeNullorWhitespace) + { + break; + } + + bool stringExists = false; + foreach (string output in outputList) + { + if (output == input) + { + stringExists = true; + break; + } + } + + if (stringExists == false) + { + outputList.Add(input); + } + } + + return outputList; + } + + public List UniqueList(List inputList, bool removeNullorWhitespace = true) + { + List stringList = new List(); + foreach (Enum input in inputList) + { + stringList.Add(input.ToString()); + } + return UniqueList(stringList, removeNullorWhitespace); + } + } +} diff --git a/src/bnhtrade.Core/Logic/Utilities/NightlyRoutine.cs b/src/bnhtrade.Core/Logic/Utilities/NightlyRoutine.cs index 586f2f3..153b206 100644 --- a/src/bnhtrade.Core/Logic/Utilities/NightlyRoutine.cs +++ b/src/bnhtrade.Core/Logic/Utilities/NightlyRoutine.cs @@ -21,6 +21,7 @@ namespace bnhtrade.Core.Logic.Utilities var export = new bnhtrade.Core.Logic.Export.AmazonSettlement(); bool stockUpdate = false; + bool exchangeRate = false; bool accountProcess = false; while (true) @@ -28,6 +29,7 @@ namespace bnhtrade.Core.Logic.Utilities try { if (stockUpdate == false) { stockUpdate = true; new bnhtrade.Core.Logic.Import.Amazon().SyncAllWithDatabase(); ; } + if (exchangeRate == false) { exchangeRate = true; new Logic.Account.Currency().UpdateHmrcExchageRates(); } if (accountProcess == false) { accountProcess = true; export.ToInvoice(); } // if (stockProcess == false) { stockProcess = true; stock.ProcessFbaStockImportData(); } diff --git a/src/bnhtrade.Core/Logic/Validate/Format.cs b/src/bnhtrade.Core/Logic/Validate/Format.cs index 08c35cf..989b485 100644 --- a/src/bnhtrade.Core/Logic/Validate/Format.cs +++ b/src/bnhtrade.Core/Logic/Validate/Format.cs @@ -15,7 +15,10 @@ namespace bnhtrade.Core.Logic.Validate /// public static bool SkuNumber(string skuNumber) { - if (string.IsNullOrEmpty(skuNumber)) { return false;} + if (string.IsNullOrEmpty(skuNumber)) + { + return false; + } int count = 0; foreach (char c in skuNumber) @@ -50,11 +53,17 @@ namespace bnhtrade.Core.Logic.Validate public static bool DateTime(DateTime dateTime) { if (dateTime == default(DateTime)) - { return false; } + { + return false; + } else if (dateTime.Kind != DateTimeKind.Utc) - { return false; } + { + return false; + } else - { return true; } + { + return true; + } } } } diff --git a/src/bnhtrade.Core/Model/Account/CurrencyCode.cs b/src/bnhtrade.Core/Model/Account/CurrencyCode.cs new file mode 100644 index 0000000..f6629e2 --- /dev/null +++ b/src/bnhtrade.Core/Model/Account/CurrencyCode.cs @@ -0,0 +1,191 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace bnhtrade.Core.Model.Account +{ + public enum CurrencyCode + { + AED, + AFN, + ALL, + AMD, + ANG, + AOA, + ARS, + AUD, + AWG, + AZN, + BAM, + BBD, + BDT, + BGN, + BHD, + BIF, + BMD, + BND, + BOB, + BOV, + BRL, + BSD, + BTN, + BWP, + BYN, + BYR, + BZD, + CAD, + CDF, + CHE, + CHF, + CHW, + CLF, + CLP, + CNY, + COP, + COU, + CRC, + CUC, + CUP, + CVE, + CZK, + DJF, + DKK, + DOP, + DZD, + EGP, + ERN, + ETB, + EUR, + FJD, + FKP, + GBP, + GEL, + GHS, + GIP, + GMD, + GNF, + GTQ, + GYD, + HKD, + HNL, + HRK, + HTG, + HUF, + IDR, + ILS, + INR, + IQD, + IRR, + ISK, + JMD, + JOD, + JPY, + KES, + KGS, + KHR, + KMF, + KPW, + KRW, + KWD, + KYD, + KZT, + LAK, + LBP, + LKR, + LRD, + LSL, + LYD, + MAD, + MDL, + MGA, + MKD, + MMK, + MNT, + MOP, + MRO, + MUR, + MVR, + MWK, + MXN, + MXV, + MYR, + MZN, + NAD, + NGN, + NIO, + NOK, + NPR, + NZD, + OMR, + PAB, + PEN, + PGK, + PHP, + PKR, + PLN, + PYG, + QAR, + RON, + RSD, + RUB, + RWF, + SAR, + SBD, + SCR, + SDG, + SEK, + SGD, + SHP, + SLL, + SOS, + SRD, + SSP, + STD, + SVC, + SYP, + SZL, + THB, + TJS, + TMT, + TND, + TOP, + TRY, + TTD, + TWD, + TZS, + UAH, + UGX, + USD, + USN, + UYI, + UYU, + UZS, + VEF, + VND, + VUV, + WST, + XAF, + XAG, + XAU, + XBA, + XBB, + XBC, + XBD, + XCD, + XDR, + XOF, + XPD, + XPF, + XPT, + XSU, + XTS, + XUA, + XXX, + YER, + ZAR, + ZMW, + ZWL + } +} diff --git a/src/bnhtrade.Core/Model/Account/CurrencyExchangeRate.cs b/src/bnhtrade.Core/Model/Account/CurrencyExchangeRate.cs new file mode 100644 index 0000000..5558f78 --- /dev/null +++ b/src/bnhtrade.Core/Model/Account/CurrencyExchangeRate.cs @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace bnhtrade.Core.Model.Account +{ + public class CurrencyExchangeRate + { + public CurrencyExchangeRate(CurrencyCode currencyCode, int exchangeRateSource, DateTime dateTimeStartUtc, DateTime dateTimeEndUtc) + { + this.CurrencyCode = currencyCode; + this.ExchangeRateSource = exchangeRateSource; + + if (dateTimeEndUtc > dateTimeStartUtc) + { + this.DateTimeStartUtc = dateTimeStartUtc; + this.DateTimeEndUtc = dateTimeEndUtc; + } + else + { + throw new ArgumentException("Incorrect start and/or end date value(s)"); + } + } + + public CurrencyCode CurrencyCode { get; private set; } + + public int ExchangeRateSource { get; private set; } + + public decimal CurrencyUnitsPerGbp { get; private set; } + + public DateTime DateTimeStartUk + { + get + { + return new Logic.Utilities.DateTime().ConvertUtcToUk(DateTimeStartUtc); + } + } + + public DateTime DateTimeStartUtc { get; private set; } + + public DateTime DateTimeEndUk + { + get + { + return new Logic.Utilities.DateTime().ConvertUtcToUk(DateTimeEndUtc); + } + } + + public DateTime DateTimeEndUtc { get; private set; } + + + /// + /// Checks whether a given datetime falls within the the exchange rate period + /// + /// The date and time to check + /// True or false + public bool DateTimeWithinPeriodCheck(DateTime dateTimeToCheck) + { + if (dateTimeToCheck >= DateTimeStartUtc && dateTimeToCheck < DateTimeEndUtc) + { + return true; + } + else + { + return false; + } + } + } +} diff --git a/src/bnhtrade.Core/Model/Account/Invoice.cs b/src/bnhtrade.Core/Model/Account/Invoice.cs index c908775..aae6d67 100644 --- a/src/bnhtrade.Core/Model/Account/Invoice.cs +++ b/src/bnhtrade.Core/Model/Account/Invoice.cs @@ -42,7 +42,7 @@ namespace bnhtrade.Core.Model.Account public abstract class Invoice : InvoiceHeader, IInvoice { - private bool unitAmountIsTaxExclusive = true; + private bool unitAmountIsTaxExclusive = false; public decimal InvoiceNetAmount { get; } diff --git a/src/bnhtrade.Core/Model/Credentials/bnhtradeDB.cs b/src/bnhtrade.Core/Model/Credentials/bnhtradeDB.cs index 6071447..c8140ab 100644 --- a/src/bnhtrade.Core/Model/Credentials/bnhtradeDB.cs +++ b/src/bnhtrade.Core/Model/Credentials/bnhtradeDB.cs @@ -28,7 +28,7 @@ namespace bnhtrade.Core.Model.Credentials { return "Data Source=" + DataSource + ";Initial Catalog=" + InitialCatalog + ";Persist Security Info=" + PersistSecurityInfo.ToString() + ";User ID=" + UserId + ";Password=" + UserPassword + ";MultipleActiveResultSets=" + MultipleActiveResultSets.ToString() - + ";Connect Timeout=" + ConnectionTimeout; + + ";Connect Timeout=" + ConnectionTimeout + ";Encrypt=True;TrustServerCertificate=True"; } } diff --git a/src/bnhtrade.Core/Model/Stock/SkuTransactionCreate.cs b/src/bnhtrade.Core/Model/Stock/SkuTransactionCreate.cs index f959e12..03c00e1 100644 --- a/src/bnhtrade.Core/Model/Stock/SkuTransactionCreate.cs +++ b/src/bnhtrade.Core/Model/Stock/SkuTransactionCreate.cs @@ -54,7 +54,7 @@ namespace bnhtrade.Core.Model.Stock { var result = new List(); - if (Logic.Validate.Format.DateTime(TransactionDate)) + if (Logic.Validate.Format.DateTime(TransactionDate) == false) { result.Add(new ValidationResult("Invalid transaction date")); } @@ -62,7 +62,7 @@ namespace bnhtrade.Core.Model.Stock { result.Add(new ValidationResult("Invalid transaction type code")); } - if (Logic.Validate.Format.SkuNumber(SkuNumber)) + if (Logic.Validate.Format.SkuNumber(SkuNumber) == false) { result.Add(new ValidationResult("Invalid SKU number")); } diff --git a/src/bnhtrade.Core/Properties/Settings.Designer.cs b/src/bnhtrade.Core/Properties/Settings.Designer.cs index a3552dd..54f8522 100644 --- a/src/bnhtrade.Core/Properties/Settings.Designer.cs +++ b/src/bnhtrade.Core/Properties/Settings.Designer.cs @@ -12,7 +12,7 @@ namespace bnhtrade.Core.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.9.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.13.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); diff --git a/src/bnhtrade.Core/Test/Account/Account.cs b/src/bnhtrade.Core/Test/Account/Account.cs index cbd55e2..04c9ded 100644 --- a/src/bnhtrade.Core/Test/Account/Account.cs +++ b/src/bnhtrade.Core/Test/Account/Account.cs @@ -1,9 +1,12 @@ -using System; +using bnhtrade.Core.Data.Database.Account; +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms.Design; +using System.Xml; +using System.Xml.Linq; namespace bnhtrade.Core.Test.Account { @@ -11,7 +14,13 @@ namespace bnhtrade.Core.Test.Account { public Account() { - Journal(); + UpdateHmrcExchageRates(); + } + + public void UpdateHmrcExchageRates() + { + var logic = new bnhtrade.Core.Logic.Account.Currency(); + logic.UpdateHmrcExchageRates(); } public void PurchaseInvoice() diff --git a/src/bnhtrade.Core/bnhtrade.Core.csproj b/src/bnhtrade.Core/bnhtrade.Core.csproj index 55a9e13..924196e 100644 --- a/src/bnhtrade.Core/bnhtrade.Core.csproj +++ b/src/bnhtrade.Core/bnhtrade.Core.csproj @@ -5,6 +5,8 @@ false true true + + false @@ -30,28 +32,30 @@ - - - - - - - - - true - + - - - - true - - - - + + + + + + + + + True + True + Settings.settings + + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + \ No newline at end of file diff --git a/src/bnhtrade.ScheduledTasks/Program.cs b/src/bnhtrade.ScheduledTasks/Program.cs index 3e4af66..f797450 100644 --- a/src/bnhtrade.ScheduledTasks/Program.cs +++ b/src/bnhtrade.ScheduledTasks/Program.cs @@ -25,6 +25,7 @@ namespace bnhtradeScheduledTasks Console.WriteLine(); Console.WriteLine("<1> Amazon reports"); Console.WriteLine("<2> Stock functions"); + Console.WriteLine("<3> Account functions"); Console.WriteLine(""); Console.WriteLine("<8> Start scheduled nightly tasks"); Console.WriteLine("<9> Dev functions"); @@ -50,12 +51,12 @@ namespace bnhtradeScheduledTasks Console.WriteLine("<1> Start nightly tasks"); Console.WriteLine(); Console.WriteLine("<2> Update FBA Inventory Data"); - Console.WriteLine("<3> Update FBA Inventory Age Data"); + Console.WriteLine("<3> Update FBA Inventory Ledger Data (new)"); Console.WriteLine("<4> Update Amazon Settlement Data"); - Console.WriteLine("<5> Update Fba Inventory Receipt Data"); + Console.WriteLine("<5> (depreciated) Update Fba Inventory Receipt Data"); Console.WriteLine("<6> Update Fba Sale Shipment Data"); Console.WriteLine("<7> Update Fba Return Data"); - Console.WriteLine("<8> Update Fba Adustment Data"); + Console.WriteLine("<8> (depreciated) Update Fba Adustment Data"); Console.WriteLine("<9> Update Fba Removal Order Data"); Console.WriteLine(); Console.WriteLine("<0> Back"); @@ -84,7 +85,7 @@ namespace bnhtradeScheduledTasks else if (input == "3") { Console.Clear(); - new bnhtrade.Core.Logic.Import.AmazonFbaInventoryAge().SyncDatabaseWithAmazon(); + new bnhtrade.Core.Logic.Import.AmazonFbaInventoryLedgerDetail().SyncDatabaseWithAmazon(); Console.WriteLine("Complete, press any key to continue..."); Console.ReadKey(); } @@ -242,6 +243,34 @@ namespace bnhtradeScheduledTasks } while (true); } + else if (input == "3") + { + do + { + Console.Clear(); + Console.WriteLine(consoleHeader); + Console.WriteLine("Main Menu > Account"); + Console.WriteLine(); + Console.WriteLine("<1> Update HMRC Exchange Rates"); + Console.WriteLine(); + Console.WriteLine("<0> Back"); + Console.WriteLine(""); + Console.Write("Enter an option >"); + input = Console.ReadLine(); + + if (input == "0") + { + break; + } + else if (input == "1") + { + Console.Clear(); + new bnhtrade.Core.Logic.Account.Currency().UpdateHmrcExchageRates(); + Console.WriteLine("Complete, press any key to continue..."); + Console.ReadKey(); + } + } while (true); + } else if (input == "8") { Console.Clear(); diff --git a/src/bnhtrade.ScheduledTasks/bnhtrade.ScheduledTasks.csproj b/src/bnhtrade.ScheduledTasks/bnhtrade.ScheduledTasks.csproj index 4b3c2a2..29c1d33 100644 --- a/src/bnhtrade.ScheduledTasks/bnhtrade.ScheduledTasks.csproj +++ b/src/bnhtrade.ScheduledTasks/bnhtrade.ScheduledTasks.csproj @@ -64,8 +64,7 @@ - - + bnhtrade Scheduled Tasks diff --git a/src/bnhtrade.gui/FormConsole.Designer.cs b/src/bnhtrade.gui/FormConsole.Designer.cs new file mode 100644 index 0000000..1f77957 --- /dev/null +++ b/src/bnhtrade.gui/FormConsole.Designer.cs @@ -0,0 +1,72 @@ +namespace bnhtrade.gui +{ + partial class FormConsole + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + button1 = new Button(); + txtConsole = new TextBox(); + SuspendLayout(); + // + // button1 + // + button1.Location = new Point(610, 389); + button1.Name = "button1"; + button1.Size = new Size(152, 49); + button1.TabIndex = 2; + button1.Text = "Close"; + button1.UseVisualStyleBackColor = true; + button1.Click += button1_Click; + // + // txtConsole + // + txtConsole.Location = new Point(53, 41); + txtConsole.Multiline = true; + txtConsole.Name = "txtConsole"; + txtConsole.Size = new Size(709, 337); + txtConsole.TabIndex = 3; + // + // FormConsole + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(txtConsole); + Controls.Add(button1); + Name = "FormConsole"; + Text = "Form1"; + Load += FormConsole_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Button button1; + private TextBox txtConsole; + } +} \ No newline at end of file diff --git a/src/bnhtrade.gui/FormConsole.cs b/src/bnhtrade.gui/FormConsole.cs new file mode 100644 index 0000000..a5314c4 --- /dev/null +++ b/src/bnhtrade.gui/FormConsole.cs @@ -0,0 +1,44 @@ +using ConsoleRedirection; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace bnhtrade.gui +{ + public partial class FormConsole : Form + { + // That's our custom TextWriter class + TextWriter _writer = null; + + public FormConsole() + { + InitializeComponent(); + } + + private void FormConsole_Load(object sender, EventArgs e) + { + // Instantiate the writer + _writer = new TextBoxStreamWriter(txtConsole); + // Redirect the out Console stream + Console.SetOut(_writer); + } + + // This is called when the "Say Hello" button is clicked + private void txtSayHello_Click(object sender, EventArgs e) + { + // Writing to the Console now causes the text to be displayed in the text box. + Console.WriteLine("Hello world"); + } + + private void button1_Click(object sender, EventArgs e) + { + this.Close(); + } + } +} diff --git a/src/bnhtrade.gui/FormConsole.resx b/src/bnhtrade.gui/FormConsole.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/src/bnhtrade.gui/FormConsole.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/src/bnhtrade.gui/Home.Designer.cs b/src/bnhtrade.gui/Home.Designer.cs index ed278d1..43c956d 100644 --- a/src/bnhtrade.gui/Home.Designer.cs +++ b/src/bnhtrade.gui/Home.Designer.cs @@ -48,11 +48,14 @@ dateTimeOrderSearch = new DateTimePicker(); label1 = new Label(); textboxOrderSearch = new TextBox(); + tabAccounts = new TabPage(); + btnExchangeRate = new Button(); tabControl1.SuspendLayout(); Receiving.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit(); ((System.ComponentModel.ISupportInitialize)bsReceivingLines).BeginInit(); ((System.ComponentModel.ISupportInitialize)purchaseLineStatusBindingSource).BeginInit(); + tabAccounts.SuspendLayout(); SuspendLayout(); // // tabControl1 @@ -61,19 +64,22 @@ tabControl1.Controls.Add(tabPage1); tabControl1.Controls.Add(tabPage2); tabControl1.Controls.Add(Receiving); - tabControl1.Location = new Point(12, 12); + tabControl1.Controls.Add(tabAccounts); + tabControl1.Location = new Point(14, 16); + tabControl1.Margin = new Padding(3, 4, 3, 4); tabControl1.Name = "tabControl1"; tabControl1.SelectedIndex = 0; - tabControl1.Size = new Size(1022, 533); + tabControl1.Size = new Size(1168, 711); tabControl1.TabIndex = 0; tabControl1.SelectedIndexChanged += tabControl1_SelectedIndexChanged; // // tabPage1 // - tabPage1.Location = new Point(4, 24); + tabPage1.Location = new Point(4, 29); + tabPage1.Margin = new Padding(3, 4, 3, 4); tabPage1.Name = "tabPage1"; - tabPage1.Padding = new Padding(3); - tabPage1.Size = new Size(1014, 505); + tabPage1.Padding = new Padding(3, 4, 3, 4); + tabPage1.Size = new Size(1160, 678); tabPage1.TabIndex = 0; tabPage1.Text = "Home"; tabPage1.UseVisualStyleBackColor = true; @@ -81,10 +87,11 @@ // tabPage2 // tabPage2.AccessibleName = ""; - tabPage2.Location = new Point(4, 24); + tabPage2.Location = new Point(4, 29); + tabPage2.Margin = new Padding(3, 4, 3, 4); tabPage2.Name = "tabPage2"; - tabPage2.Padding = new Padding(3); - tabPage2.Size = new Size(1014, 505); + tabPage2.Padding = new Padding(3, 4, 3, 4); + tabPage2.Size = new Size(1160, 678); tabPage2.TabIndex = 1; tabPage2.Text = "FBA Shipments"; tabPage2.UseVisualStyleBackColor = true; @@ -98,10 +105,11 @@ Receiving.Controls.Add(dateTimeOrderSearch); Receiving.Controls.Add(label1); Receiving.Controls.Add(textboxOrderSearch); - Receiving.Location = new Point(4, 24); + Receiving.Location = new Point(4, 29); + Receiving.Margin = new Padding(3, 4, 3, 4); Receiving.Name = "Receiving"; - Receiving.Padding = new Padding(3); - Receiving.Size = new Size(1014, 505); + Receiving.Padding = new Padding(3, 4, 3, 4); + Receiving.Size = new Size(1160, 678); Receiving.TabIndex = 2; Receiving.Text = "Receiving"; Receiving.UseVisualStyleBackColor = true; @@ -111,10 +119,10 @@ // labelDataGridCount.Anchor = AnchorStyles.Right; labelDataGridCount.ImageAlign = ContentAlignment.MiddleRight; - labelDataGridCount.Location = new Point(857, 70); + labelDataGridCount.Location = new Point(979, 93); labelDataGridCount.Name = "labelDataGridCount"; labelDataGridCount.RightToLeft = RightToLeft.Yes; - labelDataGridCount.Size = new Size(129, 21); + labelDataGridCount.Size = new Size(147, 28); labelDataGridCount.TabIndex = 6; labelDataGridCount.Text = "labelListCount"; labelDataGridCount.TextAlign = ContentAlignment.MiddleLeft; @@ -126,11 +134,13 @@ dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridView1.Columns.AddRange(new DataGridViewColumn[] { purchaseNumberDataGridViewTextBoxColumn, purchaseDateDataGridViewTextBoxColumn, itemDescriptionDataGridViewTextBoxColumn, purchaseLineIdDataGridViewTextBoxColumn, lineStatusDataGridViewTextBoxColumn, purchaseIdDataGridViewTextBoxColumn }); dataGridView1.DataSource = bsReceivingLines; - dataGridView1.Location = new Point(31, 94); + dataGridView1.Location = new Point(35, 125); + dataGridView1.Margin = new Padding(3, 4, 3, 4); dataGridView1.MultiSelect = false; dataGridView1.Name = "dataGridView1"; + dataGridView1.RowHeadersWidth = 51; dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect; - dataGridView1.Size = new Size(955, 396); + dataGridView1.Size = new Size(1091, 528); dataGridView1.TabIndex = 5; dataGridView1.DoubleClick += dataGridView1_DoubleClick; // @@ -138,18 +148,23 @@ // purchaseNumberDataGridViewTextBoxColumn.DataPropertyName = "PurchaseNumber"; purchaseNumberDataGridViewTextBoxColumn.HeaderText = "PurchaseNumber"; + purchaseNumberDataGridViewTextBoxColumn.MinimumWidth = 6; purchaseNumberDataGridViewTextBoxColumn.Name = "purchaseNumberDataGridViewTextBoxColumn"; + purchaseNumberDataGridViewTextBoxColumn.Width = 125; // // purchaseDateDataGridViewTextBoxColumn // purchaseDateDataGridViewTextBoxColumn.DataPropertyName = "PurchaseDate"; purchaseDateDataGridViewTextBoxColumn.HeaderText = "PurchaseDate"; + purchaseDateDataGridViewTextBoxColumn.MinimumWidth = 6; purchaseDateDataGridViewTextBoxColumn.Name = "purchaseDateDataGridViewTextBoxColumn"; + purchaseDateDataGridViewTextBoxColumn.Width = 125; // // itemDescriptionDataGridViewTextBoxColumn // itemDescriptionDataGridViewTextBoxColumn.DataPropertyName = "ItemDescription"; itemDescriptionDataGridViewTextBoxColumn.HeaderText = "ItemDescription"; + itemDescriptionDataGridViewTextBoxColumn.MinimumWidth = 6; itemDescriptionDataGridViewTextBoxColumn.Name = "itemDescriptionDataGridViewTextBoxColumn"; itemDescriptionDataGridViewTextBoxColumn.Width = 500; // @@ -157,19 +172,25 @@ // purchaseLineIdDataGridViewTextBoxColumn.DataPropertyName = "PurchaseLineId"; purchaseLineIdDataGridViewTextBoxColumn.HeaderText = "PurchaseLineId"; + purchaseLineIdDataGridViewTextBoxColumn.MinimumWidth = 6; purchaseLineIdDataGridViewTextBoxColumn.Name = "purchaseLineIdDataGridViewTextBoxColumn"; + purchaseLineIdDataGridViewTextBoxColumn.Width = 125; // // lineStatusDataGridViewTextBoxColumn // lineStatusDataGridViewTextBoxColumn.DataPropertyName = "LineStatus"; lineStatusDataGridViewTextBoxColumn.HeaderText = "LineStatus"; + lineStatusDataGridViewTextBoxColumn.MinimumWidth = 6; lineStatusDataGridViewTextBoxColumn.Name = "lineStatusDataGridViewTextBoxColumn"; + lineStatusDataGridViewTextBoxColumn.Width = 125; // // purchaseIdDataGridViewTextBoxColumn // purchaseIdDataGridViewTextBoxColumn.DataPropertyName = "PurchaseId"; purchaseIdDataGridViewTextBoxColumn.HeaderText = "PurchaseId"; + purchaseIdDataGridViewTextBoxColumn.MinimumWidth = 6; purchaseIdDataGridViewTextBoxColumn.Name = "purchaseIdDataGridViewTextBoxColumn"; + purchaseIdDataGridViewTextBoxColumn.Width = 125; // // bsReceivingLines // @@ -177,9 +198,10 @@ // // buttonSearch // - buttonSearch.Location = new Point(865, 37); + buttonSearch.Location = new Point(989, 49); + buttonSearch.Margin = new Padding(3, 4, 3, 4); buttonSearch.Name = "buttonSearch"; - buttonSearch.Size = new Size(109, 25); + buttonSearch.Size = new Size(125, 33); buttonSearch.TabIndex = 4; buttonSearch.Text = "Search"; buttonSearch.UseVisualStyleBackColor = true; @@ -190,9 +212,10 @@ comboBox1.DataSource = purchaseLineStatusBindingSource; comboBox1.DisplayMember = "PurchaseLineStatusName"; comboBox1.FormattingEnabled = true; - comboBox1.Location = new Point(195, 39); + comboBox1.Location = new Point(223, 52); + comboBox1.Margin = new Padding(3, 4, 3, 4); comboBox1.Name = "comboBox1"; - comboBox1.Size = new Size(189, 23); + comboBox1.Size = new Size(215, 28); comboBox1.TabIndex = 3; comboBox1.ValueMember = "PurchaseLineStatusId"; comboBox1.SelectedIndexChanged += comboBox1_SelectedIndexChanged; @@ -204,35 +227,59 @@ // // dateTimeOrderSearch // - dateTimeOrderSearch.Location = new Point(31, 39); + dateTimeOrderSearch.Location = new Point(35, 52); + dateTimeOrderSearch.Margin = new Padding(3, 4, 3, 4); dateTimeOrderSearch.Name = "dateTimeOrderSearch"; - dateTimeOrderSearch.Size = new Size(131, 23); + dateTimeOrderSearch.Size = new Size(149, 27); dateTimeOrderSearch.TabIndex = 2; dateTimeOrderSearch.ValueChanged += dateTimeOrderSearch_ValueChanged; // // label1 // label1.AutoSize = true; - label1.Location = new Point(31, 21); + label1.Location = new Point(35, 28); label1.Name = "label1"; - label1.Size = new Size(75, 15); + label1.Size = new Size(95, 20); label1.TabIndex = 1; label1.Text = "Order Search"; // // textboxOrderSearch // - textboxOrderSearch.Location = new Point(417, 39); + textboxOrderSearch.Location = new Point(477, 52); + textboxOrderSearch.Margin = new Padding(3, 4, 3, 4); textboxOrderSearch.Name = "textboxOrderSearch"; - textboxOrderSearch.Size = new Size(415, 23); + textboxOrderSearch.Size = new Size(474, 27); textboxOrderSearch.TabIndex = 0; textboxOrderSearch.KeyPress += textboxOrderSearch_KeyPress; // + // tabAccounts + // + tabAccounts.Controls.Add(btnExchangeRate); + tabAccounts.Location = new Point(4, 29); + tabAccounts.Name = "tabAccounts"; + tabAccounts.Padding = new Padding(3); + tabAccounts.Size = new Size(1160, 678); + tabAccounts.TabIndex = 3; + tabAccounts.Text = "Accounts"; + tabAccounts.UseVisualStyleBackColor = true; + // + // btnExchangeRate + // + btnExchangeRate.Location = new Point(48, 50); + btnExchangeRate.Name = "btnExchangeRate"; + btnExchangeRate.Size = new Size(237, 50); + btnExchangeRate.TabIndex = 0; + btnExchangeRate.Text = "Update exchange rates"; + btnExchangeRate.UseVisualStyleBackColor = true; + btnExchangeRate.Click += btnExchangeRate_Click; + // // Home // - AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1046, 557); + ClientSize = new Size(1195, 743); Controls.Add(tabControl1); + Margin = new Padding(3, 4, 3, 4); Name = "Home"; Text = "Form1"; Load += Form1_Load; @@ -242,6 +289,7 @@ ((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit(); ((System.ComponentModel.ISupportInitialize)bsReceivingLines).EndInit(); ((System.ComponentModel.ISupportInitialize)purchaseLineStatusBindingSource).EndInit(); + tabAccounts.ResumeLayout(false); ResumeLayout(false); } @@ -266,5 +314,7 @@ private DataGridViewTextBoxColumn lineStatusDataGridViewTextBoxColumn; private DataGridViewTextBoxColumn purchaseIdDataGridViewTextBoxColumn; private Label labelDataGridCount; + private TabPage tabAccounts; + private Button btnExchangeRate; } } diff --git a/src/bnhtrade.gui/Home.cs b/src/bnhtrade.gui/Home.cs index 39117f8..b4ce227 100644 --- a/src/bnhtrade.gui/Home.cs +++ b/src/bnhtrade.gui/Home.cs @@ -110,5 +110,12 @@ namespace bnhtrade.gui var form = new PurchaseInvoice(purchaseInvoice); form.Show(); } + + private void btnExchangeRate_Click(object sender, EventArgs e) + { + var myForm = new FormConsole(); + myForm.Show(); + new bnhtrade.Core.Logic.Account.Currency().UpdateHmrcExchageRates(); + } } } diff --git a/src/bnhtrade.gui/Home.resx b/src/bnhtrade.gui/Home.resx index 70d97fa..a298a7f 100644 --- a/src/bnhtrade.gui/Home.resx +++ b/src/bnhtrade.gui/Home.resx @@ -1,7 +1,7 @@