diff --git a/bnhtrade.sln b/bnhtrade.sln index 3031671..9f182a9 100644 --- a/bnhtrade.sln +++ b/bnhtrade.sln @@ -1,18 +1,19 @@ - Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.9.34728.123 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{CF330C30-8231-4D54-B60C-FF0644713502}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "bnhtrade.ScheduledTasks", "src\bnhtrade.ScheduledTasks\bnhtrade.ScheduledTasks.csproj", "{5D6E1D66-3901-4340-95C6-EE65051AB623}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "bnhtrade.ScheduledTasks", "src\bnhtrade.ScheduledTasks\bnhtrade.ScheduledTasks.csproj", "{5D6E1D66-3901-4340-95C6-EE65051AB623}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "bnhtrade.Core", "src\bnhtrade.Core\bnhtrade.Core.csproj", "{339D7413-3DA7-46EA-A55C-255A9A6B95EB}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "bnhtrade.Core", "src\bnhtrade.Core\bnhtrade.Core.csproj", "{339D7413-3DA7-46EA-A55C-255A9A6B95EB}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "bnhtrade.ComTypeLib", "src\bnhtrade.ComTypeLib\bnhtrade.ComTypeLib.csproj", "{C3405E9D-B47A-4569-B6A3-BC9E7AA71EE5}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "bnhtrade.ComTypeLib", "src\bnhtrade.ComTypeLib\bnhtrade.ComTypeLib.csproj", "{C3405E9D-B47A-4569-B6A3-BC9E7AA71EE5}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "lib", "lib", "{3D90C0F5-02E7-44E5-A89D-F5E217C6602F}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "bnhtrade.gui", "src\bnhtrade.gui\bnhtrade.gui.csproj", "{92788EE6-6B75-45BE-A0F3-9E4F51CDEB3F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -31,6 +32,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 + {92788EE6-6B75-45BE-A0F3-9E4F51CDEB3F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {92788EE6-6B75-45BE-A0F3-9E4F51CDEB3F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {92788EE6-6B75-45BE-A0F3-9E4F51CDEB3F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {92788EE6-6B75-45BE-A0F3-9E4F51CDEB3F}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/build/README.md b/build/README.md deleted file mode 100644 index 31ac55a..0000000 --- a/build/README.md +++ /dev/null @@ -1 +0,0 @@ -Build customizations (custom msbuild files/psake/fake/albacore/etc) scripts \ No newline at end of file diff --git a/build/bnhtrade.ComTypeLib.RegAsmInstall.bat b/build/bnhtrade.ComTypeLib.RegAsmInstall.bat deleted file mode 100644 index 7f7457e..0000000 --- a/build/bnhtrade.ComTypeLib.RegAsmInstall.bat +++ /dev/null @@ -1,19 +0,0 @@ -@set batchpath=%~dp0 -@set dllpath=%batchpath% -::bnhtrade Database Client\bin\Release\ - -@copy "%dllpath%bnhtradeCOM.dll" "%SYSTEMROOT%\SysWOW64\bnhtradeCOM.dll" -@copy "%dllpath%bnhtradeCOM.dll" "%SYSTEMROOT%\System32\bnhtradeCOM.dll" - -@c: -@cd\Windows\Microsoft.NET\Framework\v4.* -regasm.exe /codebase /tlb "bnhtradeCOM.dll" - -@cd\Windows\Microsoft.NET\Framework64\v4.* -regasm.exe /codebase /tlb "bnhtradeCOM.dll" - -@echo. -@echo Finished running regasm install script. -@echo. -@rem if no arguments passed, pause -@IF "%~1"=="" @pause \ No newline at end of file diff --git a/build/bnhtrade.ComTypeLib.RegAsmRefresh.bat b/build/bnhtrade.ComTypeLib.RegAsmRefresh.bat deleted file mode 100644 index 5079927..0000000 --- a/build/bnhtrade.ComTypeLib.RegAsmRefresh.bat +++ /dev/null @@ -1,7 +0,0 @@ -@set mypath=%~dp0 - -call "%mypath%bnhtrade.ComTypeLib.RegAsmUninstall.bat" nopause -call "%mypath%bnhtrade.ComTypeLib.RegAsmInstall.bat" nopause -@echo Completed regasm refresh -@echo. -@pause diff --git a/build/bnhtrade.ComTypeLib.RegAsmUninstall.bat b/build/bnhtrade.ComTypeLib.RegAsmUninstall.bat deleted file mode 100644 index f92943a..0000000 --- a/build/bnhtrade.ComTypeLib.RegAsmUninstall.bat +++ /dev/null @@ -1,17 +0,0 @@ -@c: -@cd\Windows\Microsoft.NET\Framework\v4.* -regasm.exe /u "%SYSTEMROOT%\System32\bnhtradeCOM.dll" -@cd\Windows\Microsoft.NET\Framework64\v4.* -regasm.exe /u "%SYSTEMROOT%\SysWOW64\bnhtradeCOM.dll" -cd -@del /q "%SYSTEMROOT%\SysWOW64\bnhtradeCOM.dll" -@del /q "%SYSTEMROOT%\SysWOW64\bnhtradeCOM.tlb" - -@del /q "%SYSTEMROOT%\System32\bnhtradeCOM.dll" -@del /q "%SYSTEMROOT%\System32\bnhtradeCOM.tlb" - -@echo. -@echo Finished running regasm uninstall script. -@rem if no arguments passed, pause -@echo. -@IF "%~1"=="" @pause \ No newline at end of file diff --git a/docs/README.md b/docs/README.md deleted file mode 100644 index cbf6f4f..0000000 --- a/docs/README.md +++ /dev/null @@ -1 +0,0 @@ -Documentation stuff, markdown files, help files etc. \ No newline at end of file diff --git a/lib/README.md b/lib/README.md deleted file mode 100644 index 7cd8419..0000000 --- a/lib/README.md +++ /dev/null @@ -1 +0,0 @@ -Things that can NEVER exist in a nuget package \ No newline at end of file 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.ComTypeLib/Properties/AssemblyInfo.cs b/src/bnhtrade.ComTypeLib/Properties/AssemblyInfo.cs index 29bbd44..5021801 100644 --- a/src/bnhtrade.ComTypeLib/Properties/AssemblyInfo.cs +++ b/src/bnhtrade.ComTypeLib/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 COM Type Library")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("bnhtrade")] -[assembly: AssemblyProduct("bnhtradeCOMAsm")] -[assembly: AssemblyCopyright("Copyright © 2019")] [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("c3405e9d-b47a-4569-b6a3-bc9e7aa71ee5")] - -// 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.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.ComTypeLib/bnhtrade.ComTypeLib.csproj b/src/bnhtrade.ComTypeLib/bnhtrade.ComTypeLib.csproj index 29ee72f..263137a 100644 --- a/src/bnhtrade.ComTypeLib/bnhtrade.ComTypeLib.csproj +++ b/src/bnhtrade.ComTypeLib/bnhtrade.ComTypeLib.csproj @@ -1,38 +1,19 @@ - - - + - Debug - AnyCPU - {C3405E9D-B47A-4569-B6A3-BC9E7AA71EE5} + net8.0-windows Library - Properties - bnhtrade.ComTypeLib bnhtradeCOM - v4.7.2 - 512 - true - - - + false + + + false - true - full - false - ..\..\bin\Debug\com\ - DEBUG;TRACE - prompt - 4 + ..\..\bin\$(AssemblyName)\Debug\ SecurityRules.ruleset - pdbonly - true - ..\..\bin\Release\com\ - TRACE - prompt - 4 + ..\..\bin\$(AssemblyName)\Release\ true false @@ -40,54 +21,23 @@ Always - - - - - - - - + - - - - - - - - + + + - - - - - - - - - - - {339d7413-3da7-46ea-a55c-255a9a6b95eb} - bnhtrade.Core - - - - - - - + copy "$(ProjectDir)_RegAsmInstall.bat" "$(TargetDir)" copy "$(ProjectDir)_RegAsmRefresh.bat" "$(TargetDir)" copy "$(ProjectDir)_RegAsmUninstall.bat" "$(TargetDir)" + bnhtrade COM Type Library + bnhtrade + bnhtradeCOMAsm + Copyright © 2019 + 1.0.0.0 + 1.0.0.0 - - - - 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}. - - - \ No newline at end of file diff --git a/src/bnhtrade.ComTypeLib/packages.config b/src/bnhtrade.ComTypeLib/packages.config deleted file mode 100644 index 9e214cc..0000000 --- a/src/bnhtrade.ComTypeLib/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file 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/Amazon/Report/FbaInventoryLedgerDetailed.cs b/src/bnhtrade.Core/Data/Amazon/Report/FbaInventoryLedgerDetailed.cs index ce16503..2f2f16a 100644 --- a/src/bnhtrade.Core/Data/Amazon/Report/FbaInventoryLedgerDetailed.cs +++ b/src/bnhtrade.Core/Data/Amazon/Report/FbaInventoryLedgerDetailed.cs @@ -7,7 +7,6 @@ using System.IO; using static FikaAmazonAPI.Utils.Constants; using System.Linq; using CsvHelper.Configuration; -using NUnit.Framework.Interfaces; namespace bnhtrade.Core.Data.Amazon.Report { 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/Account/CreateInvoiceLineItem.cs b/src/bnhtrade.Core/Data/Database/Account/CreateInvoiceLineItem.cs index 455d39c..67eb118 100644 --- a/src/bnhtrade.Core/Data/Database/Account/CreateInvoiceLineItem.cs +++ b/src/bnhtrade.Core/Data/Database/Account/CreateInvoiceLineItem.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +//using System.Data.SqlClient; using System.Data.SqlClient; using System.Linq; using System.Text; 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/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/Account/ReadContact.cs b/src/bnhtrade.Core/Data/Database/Account/ReadContact.cs new file mode 100644 index 0000000..489adad --- /dev/null +++ b/src/bnhtrade.Core/Data/Database/Account/ReadContact.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 ReadContact : Connection + { + private bnhtrade.Core.Data.Database.SqlWhereBuilder sqlBuilder; + + public List ContactIdList { get; set; } + + public ReadContact() + { + 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/ReadJournal.cs b/src/bnhtrade.Core/Data/Database/Account/ReadJournal.cs new file mode 100644 index 0000000..a91897d --- /dev/null +++ b/src/bnhtrade.Core/Data/Database/Account/ReadJournal.cs @@ -0,0 +1,242 @@ +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 ReadJournal : Connection + { + private bnhtrade.Core.Data.Database.SqlWhereBuilder sqlBuilder; + + /// + /// Filter the read results + /// + public List AccountJournalId { get; set; } + + public ReadJournal() + { + 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.ReadJournalType(); + 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; + } + + /// + /// 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/ReadJournalType.cs b/src/bnhtrade.Core/Data/Database/Account/ReadJournalType.cs new file mode 100644 index 0000000..3835422 --- /dev/null +++ b/src/bnhtrade.Core/Data/Database/Account/ReadJournalType.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 ReadJournalType : 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 ReadJournalType() + { + 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/ReadPurchaseInvoice.cs b/src/bnhtrade.Core/Data/Database/Account/ReadPurchaseInvoice.cs new file mode 100644 index 0000000..f9442ff --- /dev/null +++ b/src/bnhtrade.Core/Data/Database/Account/ReadPurchaseInvoice.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 +{ + public class ReadPurchaseInvoice : Connection + { + private bnhtrade.Core.Data.Database.SqlWhereBuilder sqlBuilder; + + public List PurchaseInvoiceIdList { get; set; } + + public ReadPurchaseInvoice() + { + 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.ReadContact(); + 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.ReadPurchaseInvoiceLine(); + 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/ReadPurchaseInvoiceLine.cs b/src/bnhtrade.Core/Data/Database/Account/ReadPurchaseInvoiceLine.cs new file mode 100644 index 0000000..4642f28 --- /dev/null +++ b/src/bnhtrade.Core/Data/Database/Account/ReadPurchaseInvoiceLine.cs @@ -0,0 +1,212 @@ +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 ReadPurchaseInvoiceLine : 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 ReadPurchaseInvoiceLine() + { + Init(); + } + + public void Init() + { + sqlBuilder = new SqlWhereBuilder(); + InvoiceIdList = new List(); + InvoiceLineIdList = new List(); + StatusList = new List(); + ItemDescription = 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; + } + + // catch taxcode to add in after db read + var lineTaxCodeDict = 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()) + { + 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; + + 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/Data/Database/Account/ReadPurchaseInvoiceLineStatus.cs b/src/bnhtrade.Core/Data/Database/Account/ReadPurchaseInvoiceLineStatus.cs new file mode 100644 index 0000000..d15e0c9 --- /dev/null +++ b/src/bnhtrade.Core/Data/Database/Account/ReadPurchaseInvoiceLineStatus.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.Account +{ + internal class ReadPurchaseInvoiceLineStatus : Connection + { + public Dictionary Read() + { + var returnList = new Dictionary(); + + 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.Account.PurchaseInvoiceLineStatus(id, name,lineSort); + returnList.Add(id, returnItem ); + } + } + } + } + } + return returnList; + } + } +} diff --git a/src/bnhtrade.Core/Data/Database/Account/ReadPurchaseInvoiceLineSummary.cs b/src/bnhtrade.Core/Data/Database/Account/ReadPurchaseInvoiceLineSummary.cs new file mode 100644 index 0000000..da2bc15 --- /dev/null +++ b/src/bnhtrade.Core/Data/Database/Account/ReadPurchaseInvoiceLineSummary.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 ReadPurchaseInvoiceLineSummary : 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 (lineStatus != null) + { + 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/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/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/Data/Database/Import/AmazonFbaReimbursement.cs b/src/bnhtrade.Core/Data/Database/Import/AmazonFbaReimbursement.cs index 4b732d2..acb78ce 100644 --- a/src/bnhtrade.Core/Data/Database/Import/AmazonFbaReimbursement.cs +++ b/src/bnhtrade.Core/Data/Database/Import/AmazonFbaReimbursement.cs @@ -1,6 +1,5 @@ using FikaAmazonAPI.AmazonSpApiSDK.Models.Finances; using FikaAmazonAPI.ConstructFeed.Messages; -using NUnit.Framework.Constraints; using System; using System.Collections.Generic; using System.Data; @@ -11,7 +10,7 @@ using System.Runtime.ConstrainedExecution; using System.Security.Policy; using System.Text; using System.Threading.Tasks; -using System.Web.UI.WebControls; +//using System.Web.UI.WebControls; namespace bnhtrade.Core.Data.Database.Import { 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/Data/Database/SqlWhereBuilder.cs b/src/bnhtrade.Core/Data/Database/SqlWhereBuilder.cs index 48009fb..812e4a7 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 /// @@ -126,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/Data/Database/Stock/ReadSkuTransaction.cs b/src/bnhtrade.Core/Data/Database/Stock/ReadSkuTransaction.cs index 39a2a22..ec62928 100644 --- a/src/bnhtrade.Core/Data/Database/Stock/ReadSkuTransaction.cs +++ b/src/bnhtrade.Core/Data/Database/Stock/ReadSkuTransaction.cs @@ -1,5 +1,4 @@ -using NUnit.Framework.Internal; -using System; +using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Linq; 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/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/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 new file mode 100644 index 0000000..7866744 --- /dev/null +++ b/src/bnhtrade.Core/Logic/Account/PurchaseInvoice.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace bnhtrade.Core.Logic.Account +{ + 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 new file mode 100644 index 0000000..10eeb98 --- /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.ReadPurchaseInvoiceLineStatus().Read().Values.ToList(); + } + + public List GetLineSummary(DateTime maxDate, string lineStatus, List wordSearchList) + { + return new Data.Database.Account.ReadPurchaseInvoiceLineSummary().Read(maxDate,lineStatus, wordSearchList); + } + } +} 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] + ")."); } 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/Logic/Stock/SkuTransactionReconcile.cs b/src/bnhtrade.Core/Logic/Stock/SkuTransactionReconcile.cs index fe7b7c1..90be9c6 100644 --- a/src/bnhtrade.Core/Logic/Stock/SkuTransactionReconcile.cs +++ b/src/bnhtrade.Core/Logic/Stock/SkuTransactionReconcile.cs @@ -5,7 +5,6 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Transactions; -using System.Web.UI; namespace bnhtrade.Core.Logic.Stock { diff --git a/src/bnhtrade.Core/Model/Account/Account.cs b/src/bnhtrade.Core/Model/Account/Account.cs index d5fccf9..985b4e2 100644 --- a/src/bnhtrade.Core/Model/Account/Account.cs +++ b/src/bnhtrade.Core/Model/Account/Account.cs @@ -4,7 +4,6 @@ using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; -using System.Web.UI.WebControls; namespace bnhtrade.Core.Model.Account { 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/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/Model/Account/PurchaseInvoice.cs b/src/bnhtrade.Core/Model/Account/PurchaseInvoice.cs new file mode 100644 index 0000000..6fe3a0f --- /dev/null +++ b/src/bnhtrade.Core/Model/Account/PurchaseInvoice.cs @@ -0,0 +1,172 @@ +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 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; } + + 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 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/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/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.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.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.Core/Model/Import/AmazonFbaInventoryLedgerDetail.cs b/src/bnhtrade.Core/Model/Import/AmazonFbaInventoryLedgerDetail.cs index 9f42ef1..646a709 100644 --- a/src/bnhtrade.Core/Model/Import/AmazonFbaInventoryLedgerDetail.cs +++ b/src/bnhtrade.Core/Model/Import/AmazonFbaInventoryLedgerDetail.cs @@ -1,5 +1,4 @@ using CsvHelper.Configuration.Attributes; -using NUnit.Framework.Interfaces; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; diff --git a/src/bnhtrade.Core/Model/Import/AmazonFbaReimbursement.cs b/src/bnhtrade.Core/Model/Import/AmazonFbaReimbursement.cs index 4f903d5..ddc3e8b 100644 --- a/src/bnhtrade.Core/Model/Import/AmazonFbaReimbursement.cs +++ b/src/bnhtrade.Core/Model/Import/AmazonFbaReimbursement.cs @@ -7,7 +7,6 @@ using System.Runtime.ConstrainedExecution; using System.Security.Policy; using System.Text; using System.Threading.Tasks; -using System.Web.UI.WebControls; namespace bnhtrade.Core.Model.Import { diff --git a/src/bnhtrade.Core/Model/Purchase/PurchaseLineStatus.cs b/src/bnhtrade.Core/Model/Purchase/PurchaseLineStatus.cs new file mode 100644 index 0000000..b7b6b74 --- /dev/null +++ b/src/bnhtrade.Core/Model/Purchase/PurchaseLineStatus.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.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/Program.cs b/src/bnhtrade.Core/Program.cs index d3549e3..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,642 +228,6 @@ namespace bnhtrade.Core } } } - - namespace Account - { - public class AccountQuery - { - 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"); - } - } - } - } - - 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; - } - } - - 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; - } - } - } - } - - 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; - } - } - - // 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; - } - } - } - - 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; - } - } - - 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 - { - 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 { @@ -878,7 +242,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, @@ -1068,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 @@ -1248,7 +612,7 @@ namespace bnhtrade.Core } // delete account journal entry - Account.AccountQuery.AccountJournalDelete(sqlConnectionString, accountJournalId); + new Data.Database.Account.DeleteJournal().AccountJournalDelete(accountJournalId); scope.Complete(); } @@ -1398,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 @@ -1979,8 +1344,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(@" @@ -2042,8 +1407,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(); } @@ -2140,7 +1504,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/Properties/AssemblyInfo.cs b/src/bnhtrade.Core/Properties/AssemblyInfo.cs deleted file mode 100644 index 0ee464f..0000000 --- a/src/bnhtrade.Core/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -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 Database Client")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("bnhtrade Database Client")] -[assembly: AssemblyCopyright("Copyright © 2017")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("339d7413-3da7-46ea-a55c-255a9a6b95eb")] - -// 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.Core/Test/Account/Account.cs b/src/bnhtrade.Core/Test/Account/Account.cs index b6386be..cbd55e2 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,28 @@ namespace bnhtrade.Core.Test.Account { public Account() { - //var inst = new Data.Database.Account.GetTaxCode(sqlConnectionString); - //inst. + Journal(); + } - //var taxInfo = inst.GetAll(); + public void 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.ReadPurchaseInvoiceLine(); + read.ItemDescription = new List { "xbox", "kill" }; + var result = read.Read(); + } + + public void Journal() + { + var read = new Data.Database.Account.ReadJournal(); + 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.Core/bnhtrade.Core.csproj b/src/bnhtrade.Core/bnhtrade.Core.csproj index 506a48a..55a9e13 100644 --- a/src/bnhtrade.Core/bnhtrade.Core.csproj +++ b/src/bnhtrade.Core/bnhtrade.Core.csproj @@ -1,356 +1,30 @@ - - - - + - Debug - AnyCPU - {339D7413-3DA7-46EA-A55C-255A9A6B95EB} + net8.0-windows Library - Properties - bnhtrade.Core - bnhtrade.Core - v4.7.2 - 512 - true - - - + false + true + true + + + false - AnyCPU - true - full - false - ..\..\bin\Debug\core\ - DEBUG;TRACE - prompt - 4 + ..\..\bin\$(AssemblyName)\Debug\ - AnyCPU none - true - ..\..\bin\Release\core\ - TRACE - prompt - 4 + ..\..\bin\$(AssemblyName)\Release\ - - ..\..\packages\AWSSDK.Core.3.7.303.15\lib\net45\AWSSDK.Core.dll - - - ..\..\packages\AWSSDK.SecurityToken.3.7.300.76\lib\net45\AWSSDK.SecurityToken.dll - - - ..\..\packages\AWSSDK.SQS.3.7.300.75\lib\net45\AWSSDK.SQS.dll - - - ..\..\packages\CsvHelper.31.0.4\lib\net47\CsvHelper.dll - - - ..\..\packages\Dapper.2.1.35\lib\net461\Dapper.dll - - - ..\..\packages\Dapper.Contrib.2.0.78\lib\net461\Dapper.Contrib.dll - - - ..\..\packages\CSharpAmazonSpAPI.1.7.17\lib\netstandard2.0\FikaAmazonAPI.dll - - - ..\..\packages\Microsoft.Bcl.AsyncInterfaces.8.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll - - - ..\..\packages\Microsoft.Bcl.HashCode.1.1.1\lib\net461\Microsoft.Bcl.HashCode.dll - - - ..\..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll - - - ..\..\packages\NUnit.4.1.0\lib\net462\nunit.framework.dll - - - ..\..\packages\NUnit.4.1.0\lib\net462\nunit.framework.legacy.dll - - - ..\..\packages\RestSharp.110.2.0\lib\net471\RestSharp.dll - - - ..\..\packages\RestSharp.Serializers.NewtonsoftJson.110.2.0\lib\net471\RestSharp.Serializers.NewtonsoftJson.dll - - - ..\..\packages\StandardSocketsHttpHandler.2.2.0.8\lib\netstandard2.0\StandardSocketsHttpHandler.dll - - - - ..\..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll - - - ..\..\packages\System.ComponentModel.Annotations.5.0.0\lib\net461\System.ComponentModel.Annotations.dll - - - - - - - ..\..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll - - - - ..\..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll - - - ..\..\packages\System.Reflection.4.3.0\lib\net462\System.Reflection.dll - True - True - - - ..\..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll - - - - ..\..\packages\System.Text.Encodings.Web.8.0.0\lib\net462\System.Text.Encodings.Web.dll - - - ..\..\packages\System.Text.Json.8.0.3\lib\net462\System.Text.Json.dll - - - ..\..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll - - - - ..\..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll - - - - - - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - True - True - Settings.settings - - - - - - - - - - SettingsSingleFileGenerator - Settings.Designer.cs - - - - @@ -361,18 +35,23 @@ - - - - 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 7cea662..0000000 --- a/src/bnhtrade.Core/packages.config +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/bnhtrade.ScheduledTasks/App.config b/src/bnhtrade.ScheduledTasks/App.config index e845686..752d9c5 100644 --- a/src/bnhtrade.ScheduledTasks/App.config +++ b/src/bnhtrade.ScheduledTasks/App.config @@ -39,6 +39,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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..4b3c2a2 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,18 @@ - - {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/src/bnhtrade.gui/Forms/Account/PurchaseInvoice.Designer.cs b/src/bnhtrade.gui/Forms/Account/PurchaseInvoice.Designer.cs new file mode 100644 index 0000000..987f6a2 --- /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, 280); + 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, 561); + tabControl1.Name = "tabControl1"; + tabControl1.SelectedIndex = 0; + tabControl1.Size = new Size(1042, 232); + tabControl1.TabIndex = 27; + // + // tabPageAccountTransactions + // + tabPageAccountTransactions.Location = new Point(4, 24); + tabPageAccountTransactions.Name = "tabPageAccountTransactions"; + tabPageAccountTransactions.Padding = new Padding(3); + tabPageAccountTransactions.Size = new Size(1034, 204); + 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, 805); + 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..856c4dd --- /dev/null +++ b/src/bnhtrade.gui/Forms/Account/PurchaseInvoice.resx @@ -0,0 +1,153 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + 149, 21 + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + 257, 21 + + \ No newline at end of file diff --git a/src/bnhtrade.gui/Home.Designer.cs b/src/bnhtrade.gui/Home.Designer.cs new file mode 100644 index 0000000..ed278d1 --- /dev/null +++ b/src/bnhtrade.gui/Home.Designer.cs @@ -0,0 +1,270 @@ +namespace bnhtrade.gui +{ + partial class Home + { + /// + /// 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(); + tabControl1 = new TabControl(); + 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(); + bsReceivingLines = new BindingSource(components); + buttonSearch = new Button(); + comboBox1 = new ComboBox(); + purchaseLineStatusBindingSource = new BindingSource(components); + dateTimeOrderSearch = new DateTimePicker(); + label1 = new Label(); + textboxOrderSearch = new TextBox(); + tabControl1.SuspendLayout(); + Receiving.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit(); + ((System.ComponentModel.ISupportInitialize)bsReceivingLines).BeginInit(); + ((System.ComponentModel.ISupportInitialize)purchaseLineStatusBindingSource).BeginInit(); + SuspendLayout(); + // + // tabControl1 + // + tabControl1.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + tabControl1.Controls.Add(tabPage1); + tabControl1.Controls.Add(tabPage2); + tabControl1.Controls.Add(Receiving); + tabControl1.Location = new Point(12, 12); + tabControl1.Name = "tabControl1"; + tabControl1.SelectedIndex = 0; + tabControl1.Size = new Size(1022, 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(1014, 505); + tabPage1.TabIndex = 0; + tabPage1.Text = "Home"; + tabPage1.UseVisualStyleBackColor = true; + // + // tabPage2 + // + tabPage2.AccessibleName = ""; + tabPage2.Location = new Point(4, 24); + tabPage2.Name = "tabPage2"; + tabPage2.Padding = new Padding(3); + tabPage2.Size = new Size(1014, 505); + tabPage2.TabIndex = 1; + tabPage2.Text = "FBA Shipments"; + tabPage2.UseVisualStyleBackColor = true; + // + // Receiving + // + Receiving.Controls.Add(labelDataGridCount); + Receiving.Controls.Add(dataGridView1); + Receiving.Controls.Add(buttonSearch); + Receiving.Controls.Add(comboBox1); + Receiving.Controls.Add(dateTimeOrderSearch); + Receiving.Controls.Add(label1); + Receiving.Controls.Add(textboxOrderSearch); + Receiving.Location = new Point(4, 24); + Receiving.Name = "Receiving"; + Receiving.Padding = new Padding(3); + Receiving.Size = new Size(1014, 505); + Receiving.TabIndex = 2; + Receiving.Text = "Receiving"; + Receiving.UseVisualStyleBackColor = true; + Receiving.Click += tabPage3_Click; + // + // labelDataGridCount + // + labelDataGridCount.Anchor = AnchorStyles.Right; + labelDataGridCount.ImageAlign = ContentAlignment.MiddleRight; + labelDataGridCount.Location = new Point(857, 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 = bsReceivingLines; + dataGridView1.Location = new Point(31, 94); + dataGridView1.MultiSelect = false; + dataGridView1.Name = "dataGridView1"; + dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView1.Size = new Size(955, 396); + dataGridView1.TabIndex = 5; + dataGridView1.DoubleClick += dataGridView1_DoubleClick; + // + // 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"; + // + // bsReceivingLines + // + bsReceivingLines.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; + // + // Home + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1046, 557); + Controls.Add(tabControl1); + Name = "Home"; + Text = "Form1"; + Load += Form1_Load; + tabControl1.ResumeLayout(false); + Receiving.ResumeLayout(false); + Receiving.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit(); + ((System.ComponentModel.ISupportInitialize)bsReceivingLines).EndInit(); + ((System.ComponentModel.ISupportInitialize)purchaseLineStatusBindingSource).EndInit(); + ResumeLayout(false); + } + + #endregion + + private TabControl tabControl1; + private TabPage tabPage1; + private TabPage tabPage2; + private TabPage Receiving; + private TextBox textboxOrderSearch; + private Label label1; + private DateTimePicker dateTimeOrderSearch; + private ComboBox comboBox1; + private BindingSource purchaseLineStatusBindingSource; + private Button buttonSearch; + private DataGridView dataGridView1; + private BindingSource bsReceivingLines; + private DataGridViewTextBoxColumn purchaseNumberDataGridViewTextBoxColumn; + private DataGridViewTextBoxColumn purchaseDateDataGridViewTextBoxColumn; + private DataGridViewTextBoxColumn itemDescriptionDataGridViewTextBoxColumn; + private DataGridViewTextBoxColumn purchaseLineIdDataGridViewTextBoxColumn; + private DataGridViewTextBoxColumn lineStatusDataGridViewTextBoxColumn; + private DataGridViewTextBoxColumn purchaseIdDataGridViewTextBoxColumn; + private Label labelDataGridCount; + } +} diff --git a/src/bnhtrade.gui/Home.cs b/src/bnhtrade.gui/Home.cs new file mode 100644 index 0000000..39117f8 --- /dev/null +++ b/src/bnhtrade.gui/Home.cs @@ -0,0 +1,114 @@ +using bnhtrade.gui.Forms.Account; + +namespace bnhtrade.gui +{ + public partial class Home : Form + { + + bool initTabReceiving = false; + + public Home() + { + 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; + string name = tabControl1.SelectedTab.Name; + + if (name == "Receiving" && initTabReceiving == false) + { + InitialiseTabReceiving(); + } + } + + private void InitialiseTabReceiving() + { + Cursor.Current = Cursors.WaitCursor; + purchaseLineStatusBindingSource.DataSource = new Core.Logic.Account.PurchaseInvoiceMisc().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) + { + + } + + 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; + } + + bsReceivingLines.DataSource = new Core.Logic.Account.PurchaseInvoiceMisc().GetLineSummary( + dateTimeOrderSearch.Value + , comboBox + , searchList); + + labelDataGridCount.Text = bsReceivingLines.Count.ToString(); + } + + private void bindingSource1_CurrentChanged(object sender, EventArgs e) + { + + } + + private void dateTimeOrderSearch_ValueChanged(object sender, EventArgs e) + { + 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/Home.resx b/src/bnhtrade.gui/Home.resx new file mode 100644 index 0000000..70d97fa --- /dev/null +++ b/src/bnhtrade.gui/Home.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + 250, 17 + + + 17, 17 + + \ No newline at end of file diff --git a/src/bnhtrade.gui/Program.cs b/src/bnhtrade.gui/Program.cs new file mode 100644 index 0000000..ebc23e5 --- /dev/null +++ b/src/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 Home()); + } + } +} \ No newline at end of file diff --git a/src/bnhtrade.gui/Properties/DataSources/bnhtrade.Core.Logic.Purchase.PurchaseLineStatus.datasource b/src/bnhtrade.gui/Properties/DataSources/bnhtrade.Core.Logic.Purchase.PurchaseLineStatus.datasource new file mode 100644 index 0000000..c951b2f --- /dev/null +++ b/src/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/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 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/Properties/DataSources/bnhtrade.Core.Model.Purchase.PurchaseLineStatus.datasource b/src/bnhtrade.gui/Properties/DataSources/bnhtrade.Core.Model.Purchase.PurchaseLineStatus.datasource new file mode 100644 index 0000000..c289362 --- /dev/null +++ b/src/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/src/bnhtrade.gui/Properties/Resources.Designer.cs b/src/bnhtrade.gui/Properties/Resources.Designer.cs new file mode 100644 index 0000000..93c0772 --- /dev/null +++ b/src/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/src/bnhtrade.gui/Properties/Resources.resx b/src/bnhtrade.gui/Properties/Resources.resx new file mode 100644 index 0000000..4fdb1b6 --- /dev/null +++ b/src/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/src/bnhtrade.gui/bnhtrade.gui.csproj b/src/bnhtrade.gui/bnhtrade.gui.csproj new file mode 100644 index 0000000..f49ccfd --- /dev/null +++ b/src/bnhtrade.gui/bnhtrade.gui.csproj @@ -0,0 +1,43 @@ + + + + WinExe + net8.0-windows + enable + true + enable + C:\Users\Bobbie\source\repos\stokebob\bnhtrade\bin + + + false + + + ..\..\bin\$(AssemblyName)\Debug\ + + + ..\..\bin\$(AssemblyName)\Release\ + + + + + + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + + + + + \ No newline at end of file