From d44a0bfed5191da74732c86023e444fdb9f4079b Mon Sep 17 00:00:00 2001 From: barhen Date: Fri, 15 Dec 2023 22:11:02 -0500 Subject: [PATCH] I forgot commit --- Client/Repos/MainInterfaceService.cs | 66 ++++++ Client/Repos/ProductRepository.cs | 60 +++++ Client/Repos/SalesRepository.cs | 70 +++++- Server/BiskAcdbContext.cs | 20 +- Server/CloudHubs/SalesHub.cs | 18 ++ Server/Program.cs | 1 + Server/Services/CompanyService.cs | 176 +++++++++++++- Server/Services/CustomerService.cs | 20 +- Server/Services/ProductRepo.cs | 210 +++++++++++++++++ Server/Services/SalesService.cs | 219 +++++++++++++++++- Server/Services/UserService.cs | 18 ++ .../SyncCompanyInfoController.cs | 151 ++++++++++++ .../SyncControllers/SyncProductsController.cs | 145 ++++++++++++ Server/SyncControllers/SyncSalesController.cs | 145 ++++++++++++ Server/appsettings.json | 4 +- Shared/CustomModels/SyncTimestamp.cs | 14 ++ Shared/Interfaces/ICompanyInfo.cs | 10 + Shared/Interfaces/ICustomer.cs | 1 + Shared/Interfaces/IProducts.cs | 12 + Shared/Interfaces/ISalesHub.cs | 10 + Shared/Interfaces/ISalesInterface.cs | 12 + Shared/Interfaces/IUser.cs | 1 + Shared/POSModels/Systemuserrole.cs | 8 +- Shared/POSModels/Tblsyncinfo.cs | 13 ++ Shared/POSModels/Tbluser.cs | 16 +- Shared/POSModels/Tbstock.cs | 6 +- 26 files changed, 1396 insertions(+), 30 deletions(-) create mode 100644 Server/CloudHubs/SalesHub.cs create mode 100644 Server/SyncControllers/SyncCompanyInfoController.cs create mode 100644 Server/SyncControllers/SyncProductsController.cs create mode 100644 Server/SyncControllers/SyncSalesController.cs create mode 100644 Shared/CustomModels/SyncTimestamp.cs create mode 100644 Shared/Interfaces/ISalesHub.cs create mode 100644 Shared/POSModels/Tblsyncinfo.cs diff --git a/Client/Repos/MainInterfaceService.cs b/Client/Repos/MainInterfaceService.cs index bd037bd..6e1b14e 100644 --- a/Client/Repos/MainInterfaceService.cs +++ b/Client/Repos/MainInterfaceService.cs @@ -134,5 +134,71 @@ namespace Biskilog_Accounting.Client.Repos } return null; } + #region Unimplemented + public Task SyncBranches(List a_branches) + { + throw new NotImplementedException(); + } + + public Task SyncCompanyDetails(List a_details) + { + throw new NotImplementedException(); + } + + public Task SyncDriverDetails(List a_details) + { + throw new NotImplementedException(); + } + + public Task SyncSustemRoles(List a_roles) + { + throw new NotImplementedException(); + } + + public Task SyncTrucks(List a_trucks) + { + throw new NotImplementedException(); + } + + public Task SyncTruckAssignments(List a_assignments) + { + throw new NotImplementedException(); + } + + public Task SyncTruckMappings(List a_mapping) + { + throw new NotImplementedException(); + } + + public Task SyncTruckInventory(List a_inventories) + { + throw new NotImplementedException(); + } + + public DateTime GetLastSyncDate(string a_tablename) + { + throw new NotImplementedException(); + } + + public void SetLastSyncDate(string a_tableName, DateTime a_timestamp) + { + throw new NotImplementedException(); + } + + public Task SyncUserAsync(List a_users) + { + throw new NotImplementedException(); + } + + public Task SyncCustomers(List a_details) + { + throw new NotImplementedException(); + } + + public Task SyncSystemRoles(List a_roles) + { + throw new NotImplementedException(); + } + #endregion } } diff --git a/Client/Repos/ProductRepository.cs b/Client/Repos/ProductRepository.cs index e50f213..a2796c2 100644 --- a/Client/Repos/ProductRepository.cs +++ b/Client/Repos/ProductRepository.cs @@ -139,5 +139,65 @@ namespace Biskilog_Accounting.Client.Repos { throw new NotImplementedException(); } + + public Task SyncProducts(List a_item) + { + throw new NotImplementedException(); + } + + public Task SyncInventory(List a_item) + { + throw new NotImplementedException(); + } + + public Task SyncInventoryEntries(List a_item) + { + throw new NotImplementedException(); + } + + public Task SyncPriceChanges(List a_items) + { + throw new NotImplementedException(); + } + + public Task SyncProductAltUnit(List a_items) + { + throw new NotImplementedException(); + } + + public Task SyncRestockAsync(List a_items) + { + throw new NotImplementedException(); + } + + public Task SyncUnitOfMeasureAsync(List a_items) + { + throw new NotImplementedException(); + } + + public Task SyncStockAsync(List a_items) + { + throw new NotImplementedException(); + } + + public Task SyncBrandsAsync(List a_items) + { + throw new NotImplementedException(); + } + + public Task SyncCategoriesAsync(List a_items) + { + throw new NotImplementedException(); + } + + public DateTime GetLastSyncDate(string a_tablename) + { + throw new NotImplementedException(); + } + + public void SetLastSyncDate(string a_tableName, DateTime a_timestamp) + { + throw new NotImplementedException(); + } } } diff --git a/Client/Repos/SalesRepository.cs b/Client/Repos/SalesRepository.cs index b9e4521..29c43c4 100644 --- a/Client/Repos/SalesRepository.cs +++ b/Client/Repos/SalesRepository.cs @@ -77,11 +77,6 @@ namespace Biskilog_Accounting.Client.Repos FetchComplete?.Invoke(this, EventArgs.Empty); } - public IEnumerable GetReceipt(string a_receiptId) - { - throw new NotImplementedException(); - } - public async Task> GetReceiptDetail(string a_receiptId) { var response = await m_http.GetAsync($"api/sales/receipt/lookup/{a_receiptId}"); @@ -94,5 +89,70 @@ namespace Biskilog_Accounting.Client.Repos } return null; } + #region Unimplemented + public IEnumerable GetReceipt(string a_receiptId) + { + throw new NotImplementedException(); + } + public Task SyncCart(List a_item) + { + throw new NotImplementedException(); + } + + public DateTime GetLastSyncDate(string a_tablename) + { + throw new NotImplementedException(); + } + + public void SetLastSyncDate(string a_tableName, DateTime a_timestamp) + { + throw new NotImplementedException(); + } + + public Task SyncCancelledTransaction(List a_item) + { + throw new NotImplementedException(); + } + + public Task SyncCreditPurchase(List a_item) + { + throw new NotImplementedException(); + } + + public Task SyncCustomerAccount(List a_customerAccounts) + { + throw new NotImplementedException(); + } + + public Task SyncCustomerPurchase(List a_customerPurchase) + { + throw new NotImplementedException(); + } + + public Task SyncDiscountLogs(List a_discountLog) + { + throw new NotImplementedException(); + } + + public Task SyncDeliveryDetails(List a_details) + { + throw new NotImplementedException(); + } + + public Task SyncDeliveryHead(List a_heads) + { + throw new NotImplementedException(); + } + + public Task SyncDeliveryRecipients(List a_recipients) + { + throw new NotImplementedException(); + } + + public Task SyncInvoice(List a_invoice) + { + throw new NotImplementedException(); + } + #endregion } } diff --git a/Server/BiskAcdbContext.cs b/Server/BiskAcdbContext.cs index 3cc7530..347b360 100644 --- a/Server/BiskAcdbContext.cs +++ b/Server/BiskAcdbContext.cs @@ -1,10 +1,8 @@ -using Azure.Core; -using Biskilog_Accounting.Shared.Enums; +using Biskilog_Accounting.Shared.Enums; using Biskilog_Accounting.Shared.Interfaces; using Biskilog_Accounting.Shared.POSModels; using Microsoft.EntityFrameworkCore; using Microsoft.Net.Http.Headers; -using System.Security.Claims; namespace Biskilog_Accounting.Server.POSModels; @@ -86,7 +84,7 @@ public partial class BiskAcdbContext : DbContext public virtual DbSet Tblpricechanges { get; set; } public virtual DbSet Tblproducts { get; set; } - + public virtual DbSet Tblsyncinfos { get; set; } public virtual DbSet Tbltrucks { get; set; } public virtual DbSet TbltruckDrivermappings { get; set; } @@ -1074,7 +1072,21 @@ public partial class BiskAcdbContext : DbContext .UseCollation("utf8mb4_general_ci") .HasCharSet("utf8mb4"); }); + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.TableName).HasName("PRIMARY"); + entity.ToTable("tblsyncinfo"); + + entity.Property(e => e.TableName) + .HasMaxLength(150) + .HasColumnName("tableName"); + entity.Property(e => e.BranchId) + .HasMaxLength(50) + .IsFixedLength() + .HasColumnName("branchId"); + entity.Property(e => e.LastSyncDate).HasColumnType("timestamp"); + }); modelBuilder.Entity(entity => { entity.HasKey(e => new { e.TruckId, e.BranchId }) diff --git a/Server/CloudHubs/SalesHub.cs b/Server/CloudHubs/SalesHub.cs new file mode 100644 index 0000000..05c6934 --- /dev/null +++ b/Server/CloudHubs/SalesHub.cs @@ -0,0 +1,18 @@ +using Biskilog_Accounting.Shared.CustomModels; +using Biskilog_Accounting.Shared.Interfaces; +using Microsoft.AspNetCore.SignalR; + +namespace Biskilog_Accounting.Server.CloudHubs +{ + public class SalesHub : Hub + { + public async Task JoinCompanyGroup(string a_companyId) + { + await Groups.AddToGroupAsync(Context.ConnectionId, a_companyId); + } + public async Task AddTransaction(string a_companyId, SaleItem a_sale) + { + await Clients.OthersInGroup(a_companyId).TransactionMade(a_sale); + } + } +} diff --git a/Server/Program.cs b/Server/Program.cs index 6137f46..5814888 100644 --- a/Server/Program.cs +++ b/Server/Program.cs @@ -13,6 +13,7 @@ using Biskilog_Accounting.Server.POSModels; var builder = WebApplication.CreateBuilder(args); // Add services to the container. +builder.Services.AddSignalR(); builder.Services.AddControllers().AddJsonOptions(x => x.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles); builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); builder.Logging.ClearProviders(); diff --git a/Server/Services/CompanyService.cs b/Server/Services/CompanyService.cs index eb6bae9..12939aa 100644 --- a/Server/Services/CompanyService.cs +++ b/Server/Services/CompanyService.cs @@ -1,6 +1,11 @@ using Biskilog_Accounting.Server.POSModels; +using Biskilog_Accounting.Shared.Enums; using Biskilog_Accounting.Shared.Interfaces; using Biskilog_Accounting.Shared.POSModels; +using Microsoft.EntityFrameworkCore; +using Microsoft.Net.Http.Headers; +using MySqlConnector; +using System.Text.Json; namespace Biskilog_Accounting.Server.Services { @@ -41,7 +46,7 @@ namespace Biskilog_Accounting.Server.Services public Task GetCompanyInfoAsync() { - m_companyInfo = m_context.Tblcompanydetails.First(); + m_companyInfo = m_context.Tblcompanydetails.FirstOrDefault(); return Task.FromResult(m_companyInfo); } @@ -49,5 +54,174 @@ namespace Biskilog_Accounting.Server.Services { return m_companyInfo.CompanyName; } + public async Task SyncBranches(List a_items) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_items); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL BranchSync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + public DateTime GetLastSyncDate(string a_tablename) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string activeBranch = m_tokenService.GetBaseBranch(token)!; + DateTime? lastSync = m_context.Tblsyncinfos.FirstOrDefault(p => p.TableName == a_tablename && p.BranchId == activeBranch!)?.LastSyncDate; + + if (lastSync != null) + { + return (DateTime)lastSync!; + } + } + return new DateTime(2000, 01, 01); + } + + public void SetLastSyncDate(string a_tableName, DateTime a_timestamp) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string activeBranch = m_tokenService.GetBaseBranch(token)!; + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL SetTableLastSync(@p0,@p1,@p2)"; + command.Parameters.Add(new MySqlParameter("@p0", a_tableName)); + command.Parameters.Add(new MySqlParameter("@p1", activeBranch)); + command.Parameters.Add(new MySqlParameter("@p2", a_timestamp)); + command.ExecuteNonQuery(); + } + } + + } + + public async Task SyncSystemRoles(List a_roles) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_roles); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL SystemUserRolesSync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + public async Task SyncCompanyDetails(List a_details) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_details); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL CompanyDetailSync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + + public async Task SyncDriverDetails(List a_details) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_details); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL DriverSync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + + public async Task SyncTrucks(List a_trucks) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_trucks); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL TruckSync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + + public async Task SyncTruckAssignments(List a_assignments) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_assignments); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL TruckAssignmentSync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + + public async Task SyncTruckMappings(List a_mapping) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_mapping); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL TruckDriverMappingSync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + + public async Task SyncTruckInventory(List a_inventories) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_inventories); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL TruckInventorySync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } } } diff --git a/Server/Services/CustomerService.cs b/Server/Services/CustomerService.cs index a2c9763..489bc75 100644 --- a/Server/Services/CustomerService.cs +++ b/Server/Services/CustomerService.cs @@ -2,10 +2,11 @@ using Biskilog_Accounting.Shared.CustomModels; using Biskilog_Accounting.Shared.Enums; using Biskilog_Accounting.Shared.Interfaces; +using Biskilog_Accounting.Shared.POSModels; using Microsoft.EntityFrameworkCore; using Microsoft.Net.Http.Headers; using MySqlConnector; -using System.Drawing.Drawing2D; +using System.Text.Json; namespace Biskilog_Accounting.Server.Services { @@ -67,5 +68,22 @@ namespace Biskilog_Accounting.Server.Services { throw new NotImplementedException(); } + + public async Task SyncCustomers(List a_details) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_details); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL CustomerSync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } } } diff --git a/Server/Services/ProductRepo.cs b/Server/Services/ProductRepo.cs index 0e4c916..1d07ec8 100644 --- a/Server/Services/ProductRepo.cs +++ b/Server/Services/ProductRepo.cs @@ -8,6 +8,7 @@ using Microsoft.Net.Http.Headers; using MySqlConnector; using System.Data; using System.Data.Common; +using System.Text.Json; namespace Biskilog_Accounting.Server.Services { @@ -146,7 +147,216 @@ namespace Biskilog_Accounting.Server.Services } return new List(); } + public async Task SyncProducts(List a_item) + { + try + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_item); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL ProductSync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + }catch (Exception ex) + { + throw new Exception(ex.Message, ex); + } + } + + public async Task SyncInventory(List a_item) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_item); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL InventorySync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + + public async Task SyncInventoryEntries(List a_item) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_item); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL InventoryEntriesSync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + + public async Task SyncPriceChanges(List a_items) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_items); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL PriceChangeSync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + + public async Task SyncProductAltUnit(List a_items) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_items); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL ProductAltUnitSync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + + public async Task SyncRestockAsync(List a_items) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_items); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL RestockLevelsSync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + public async Task SyncUnitOfMeasureAsync(List a_items) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_items); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL UnitOfMeasureSync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + + public async Task SyncStockAsync(List a_items) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_items); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL StockSync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + + public async Task SyncBrandsAsync(List a_items) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_items); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL BrandSync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + + public async Task SyncCategoriesAsync(List a_items) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_items); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL CategorySync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + public DateTime GetLastSyncDate(string a_tablename) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string activeBranch = m_tokenService.GetBaseBranch(token)!; + DateTime? lastSync = m_context.Tblsyncinfos.FirstOrDefault(p => p.TableName == a_tablename && p.BranchId == activeBranch!)?.LastSyncDate; + + if (lastSync != null) + { + return (DateTime)lastSync!; + } + } + return new DateTime(2000, 01, 01); + } + + public void SetLastSyncDate(string a_tableName, DateTime a_timestamp) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string activeBranch = m_tokenService.GetBaseBranch(token)!; + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL SetTableLastSync(@p0,@p1,@p2)"; + command.Parameters.Add(new MySqlParameter("@p0", a_tableName)); + command.Parameters.Add(new MySqlParameter("@p1", activeBranch)); + command.Parameters.Add(new MySqlParameter("@p2", a_timestamp)); + command.ExecuteNonQuery(); + } + } + + } #region Only Need to implement in the client Side public Task FetchUnits() { diff --git a/Server/Services/SalesService.cs b/Server/Services/SalesService.cs index 0ba0722..3693a8e 100644 --- a/Server/Services/SalesService.cs +++ b/Server/Services/SalesService.cs @@ -1,12 +1,14 @@ -using Biskilog_Accounting.Server.POSModels; +using Biskilog_Accounting.Server.CloudHubs; +using Biskilog_Accounting.Server.POSModels; using Biskilog_Accounting.Shared.CustomModels; using Biskilog_Accounting.Shared.Enums; using Biskilog_Accounting.Shared.Interfaces; using Biskilog_Accounting.Shared.POSModels; +using Microsoft.AspNetCore.SignalR; using Microsoft.EntityFrameworkCore; using Microsoft.Net.Http.Headers; using MySqlConnector; -using System.Drawing.Drawing2D; +using System.Text.Json; namespace Biskilog_Accounting.Server.Services { @@ -15,16 +17,19 @@ namespace Biskilog_Accounting.Server.Services private readonly BiskAcdbContext m_context; private readonly ITokenService m_tokenService; private readonly HttpContext m_httpContext; + private readonly IHubContext m_salesHub; public event EventHandler TransactionsChanged; public event EventHandler FetchComplete; public event EventHandler FetchStart; - public SalesService(BiskAcdbContext a_context, ITokenService a_tokenService, IHttpContextAccessor a_httpContextAccessor) + public SalesService(BiskAcdbContext a_context, ITokenService a_tokenService, + IHttpContextAccessor a_httpContextAccessor, IHubContext a_salesHub) { m_context = a_context; m_tokenService = a_tokenService; m_httpContext = a_httpContextAccessor?.HttpContext; + m_salesHub = a_salesHub; } public Task FetchRecentTransaction(int a_limit) @@ -116,6 +121,8 @@ namespace Biskilog_Accounting.Server.Services }; } } + // Close the connection explicitly + m_context.Database.CloseConnection(); } } } @@ -165,5 +172,211 @@ namespace Biskilog_Accounting.Server.Services } return Task.FromResult(details.AsEnumerable()); } + + public async Task SyncCart(List a_item) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_item); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL SaleSyncUpstream(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + + public DateTime GetLastSyncDate(string a_tablename) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string activeBranch = m_tokenService.GetBaseBranch(token)!; + DateTime? lastSync = m_context.Tblsyncinfos.FirstOrDefault(p => p.TableName == a_tablename && p.BranchId == activeBranch!)?.LastSyncDate; + + if (lastSync != null) + { + return (DateTime)lastSync!; + } + } + return new DateTime(2000,01,01); + } + + public void SetLastSyncDate(string a_tableName, DateTime a_timestamp) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string activeBranch = m_tokenService.GetBaseBranch(token)!; + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL SetTableLastSync(@p0,@p1,@p2)"; + command.Parameters.Add(new MySqlParameter("@p0", a_tableName)); + command.Parameters.Add(new MySqlParameter("@p1", activeBranch)); + command.Parameters.Add(new MySqlParameter("@p2", a_timestamp)); + command.ExecuteNonQuery(); + } + } + + } + + public async Task SyncCancelledTransaction(List a_item) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_item); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL CancelledSaleSync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + + public async Task SyncCreditPurchase(List a_item) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_item); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL CreditPurchaseSync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + + public async Task SyncCustomerAccount(List a_customerAccounts) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_customerAccounts); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL CustomerAccountSync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + + public async Task SyncCustomerPurchase(List a_customerPurchase) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_customerPurchase); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL CustomerPurchasesSync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + + public async Task SyncDiscountLogs(List a_discountLog) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_discountLog); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL DiscountLogsSync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + + public async Task SyncDeliveryDetails(List a_details) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_details); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL DeliveryDetailsSync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + + public async Task SyncDeliveryHead(List a_heads) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_heads); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL DeliveryheadSync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + + public async Task SyncDeliveryRecipients(List a_recipients) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_recipients); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL DeliveryRecipientSync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } + + public async Task SyncInvoice(List a_invoice) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_invoice); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL InvoiceSync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } } } diff --git a/Server/Services/UserService.cs b/Server/Services/UserService.cs index 43ac2e3..0033787 100644 --- a/Server/Services/UserService.cs +++ b/Server/Services/UserService.cs @@ -7,6 +7,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Net.Http.Headers; using MySqlConnector; using System.Drawing.Drawing2D; +using System.Text.Json; namespace Biskilog_Accounting.Server.Services { @@ -39,5 +40,22 @@ namespace Biskilog_Accounting.Server.Services { throw new NotImplementedException(); } + + public async Task SyncUserAsync(List a_users) + { + string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; + if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) + { + string jsonString = JsonSerializer.Serialize(a_users); + using (var command = m_context.Database.GetDbConnection().CreateCommand()) + { + m_context.Database.OpenConnection(); + + command.CommandText = "CALL UsersSync(@p0)"; + command.Parameters.Add(new MySqlParameter("@p0", jsonString)); + command.ExecuteNonQuery(); + } + } + } } } diff --git a/Server/SyncControllers/SyncCompanyInfoController.cs b/Server/SyncControllers/SyncCompanyInfoController.cs new file mode 100644 index 0000000..1abcc12 --- /dev/null +++ b/Server/SyncControllers/SyncCompanyInfoController.cs @@ -0,0 +1,151 @@ +using Biskilog_Accounting.Shared.CustomModels; +using Biskilog_Accounting.Shared.Interfaces; +using Biskilog_Accounting.Shared.POSModels; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using System.Runtime.InteropServices; + +namespace Biskilog_Accounting.Server.SyncControllers +{ + [Route("api/[controller]")] + [ApiController] + public class SyncCompanyInfoController : ControllerBase + { + private readonly ISalesInterface m_salesService; + private readonly ICustomer m_customer; + private readonly IUser m_users; + private readonly ICompanyInfo m_companyInfo; + public SyncCompanyInfoController(ISalesInterface a_salesService, ICustomer customer, IUser users,ICompanyInfo a_companyInfo) + { + m_salesService = a_salesService; + m_customer = customer; + m_users = users; + m_companyInfo = a_companyInfo; + } + // GET: api/ + [Authorize] + [HttpGet, Route("lastsyncdate/{a_tableName}")] + public DateTime GetLastSyncDate(string a_tableName) + { + return m_salesService.GetLastSyncDate(a_tableName); + } + // Post: api/ + [Authorize] + [HttpPost, Route("setsyncdate")] + public void SetLastSyncDate(SyncTimestamp a_timestamp) + { + m_salesService.SetLastSyncDate(a_timestamp.TableName, a_timestamp.Timestamp); + } + // POST api/ + /// + /// Endpoint to publish a collection of SystemUserRoles rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/SystemRoles")] + public async Task SyncSyatemRolesAsync(List a_item) + { + await m_companyInfo.SyncSystemRoles(a_item); + } + // POST api/ + /// + /// Endpoint to publish a collection of TblDriver rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/tblDriver")] + public async Task SyncDriversAsync(List a_item) + { + await m_companyInfo.SyncDriverDetails(a_item); + } + // POST api/ + /// + /// Endpoint to publish a collection of CompanyDetails rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/tblcompanydetails")] + public async Task SyncCompanyAsync(List a_item) + { + await m_companyInfo.SyncCompanyDetails(a_item); + } + // POST api/ + /// + /// Endpoint to publish a collection of TblUsers rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/tblusers")] + public async Task SyncUsersAsync(List a_item) + { + await m_users.SyncUserAsync(a_item); + } + // POST api/ + /// + /// Endpoint to publish a collection of Trucks rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/tbltrucks")] + public async Task SyncTrucksAsync(List a_item) + { + await m_companyInfo.SyncTrucks(a_item); + } + // POST api/ + /// + /// Endpoint to publish a collection of TblBranch rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/tblbranch")] + public async Task SyncBranchAsync(List a_item) + { + await m_companyInfo.SyncBranches(a_item); + } + // POST api/ + /// + /// Endpoint to publish a collection of TblCustomers rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/tblcustomers")] + public async Task SyncCustomersAsync(List a_item) + { + await m_customer.SyncCustomers(a_item); + } + // POST api/ + /// + /// Endpoint to publish a collection of TblTruck Inventory rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/tbltruckinventory")] + public async Task SyncTruckInventoryAsync(List a_item) + { + await m_companyInfo.SyncTruckInventory(a_item); + } + // POST api/ + /// + /// Endpoint to publish a collection of TblTruckAssignment rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/tblTruckAssignment")] + public async Task SyncTruckAssignmentSync(List a_item) + { + await m_companyInfo.SyncTruckAssignments(a_item); + } + // POST api/ + /// + /// Endpoint to publish a collection of TblDriverMapping rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/tbldrivermappings")] + public async Task SyncTruckDriverMappingSync(List a_item) + { + await m_companyInfo.SyncTruckMappings(a_item); + } + } +} diff --git a/Server/SyncControllers/SyncProductsController.cs b/Server/SyncControllers/SyncProductsController.cs new file mode 100644 index 0000000..b91f3cb --- /dev/null +++ b/Server/SyncControllers/SyncProductsController.cs @@ -0,0 +1,145 @@ +using Biskilog_Accounting.Server.Services; +using Biskilog_Accounting.Shared.CustomModels; +using Biskilog_Accounting.Shared.Interfaces; +using Biskilog_Accounting.Shared.POSModels; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +namespace Biskilog_Accounting.Server.SyncControllers +{ + [Route("api/[controller]")] + [ApiController] + public class SyncProductsController : ControllerBase + { + private readonly IProduct m_productService; + public SyncProductsController(IProduct a_productService) + { + m_productService = a_productService; + } + // GET: api/ + [Authorize] + [HttpGet, Route("lastsyncdate/{a_tableName}")] + public DateTime GetLastSyncDate(string a_tableName) + { + return m_productService.GetLastSyncDate(a_tableName); + } + // Post: api/ + [Authorize] + [HttpPost, Route("setsyncdate")] + public void SetLastSyncDate(SyncTimestamp a_timestamp) + { + m_productService.SetLastSyncDate(a_timestamp.TableName, a_timestamp.Timestamp); + } + // POST api/ + /// + /// Endpoint to publish a collection of TblProduct rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/tblProducts")] + public async Task SyncProductsAsync(List a_item) + { + await m_productService.SyncProducts(a_item); + } + // POST api/ + /// + /// Endpoint to publish a collection of TblInventory rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/tblInventory")] + public async Task SyncInventoryAsync(List a_item) + { + await m_productService.SyncInventory(a_item); + } + // POST api/ + /// + /// Endpoint to publish a collection of Restock rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/tblRestock")] + public async Task SyncRestockAsync(List a_item) + { + await m_productService.SyncRestockAsync(a_item); + } + // POST api/ + /// + /// Endpoint to publish a collection of TblInventoryEntries rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/tblInventoryentry")] + public async Task SyncInventoryEntriesAsync(List a_item) + { + await m_productService.SyncInventoryEntries(a_item); + } + // POST api/ + /// + /// Endpoint to publish a collection of PriceChanges rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/tlpricechanges")] + public async Task SyncPriceChangesAsync(List a_item) + { + await m_productService.SyncPriceChanges(a_item); + } + // POST api/ + /// + /// Endpoint to publish a collection of ProductAltUnit rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/tblProductAltUnit")] + public async Task SyncProductAltUnitAsync(List a_item) + { + await m_productService.SyncProductAltUnit(a_item); + } + // POST api/ + /// + /// Endpoint to publish a collection of TbStock rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/tblStock")] + public async Task SyncStockAsync(List a_item) + { + await m_productService.SyncStockAsync(a_item); + } + // POST api/ + /// + /// Endpoint to publish a collection of TblBrands rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/tblbrands")] + public async Task SyncBrandsAsync(List a_item) + { + await m_productService.SyncBrandsAsync(a_item); + } + // POST api/ + /// + /// Endpoint to publish a collection of TblCategory rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/tblCategories")] + public async Task SyncCategoriesAsync(List a_item) + { + await m_productService.SyncCategoriesAsync(a_item); + } + // POST api/ + /// + /// Endpoint to publish a collection of UnitOfMeasure rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/tblunitofmeasure")] + public async Task SyncUnitMeasureAsync(List a_item) + { + await m_productService.SyncUnitOfMeasureAsync(a_item); + } + } +} diff --git a/Server/SyncControllers/SyncSalesController.cs b/Server/SyncControllers/SyncSalesController.cs new file mode 100644 index 0000000..437da37 --- /dev/null +++ b/Server/SyncControllers/SyncSalesController.cs @@ -0,0 +1,145 @@ +using Biskilog_Accounting.Shared.CustomModels; +using Biskilog_Accounting.Shared.Interfaces; +using Biskilog_Accounting.Shared.POSModels; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; + +// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 + +namespace Biskilog_Accounting.Server.SyncControllers +{ + [Route("api/[controller]")] + [ApiController] + public class SyncSalesController : ControllerBase + { + private readonly ISalesInterface m_salesService; + public SyncSalesController(ISalesInterface a_salesService) + { + m_salesService = a_salesService; + } + // GET: api/ + [Authorize] + [HttpGet, Route("lastsyncdate/{a_tableName}")] + public DateTime GetLastSyncDate(string a_tableName) + { + return m_salesService.GetLastSyncDate(a_tableName); + } + // Post: api/ + [Authorize] + [HttpPost, Route("setsyncdate")] + public void SetLastSyncDate(SyncTimestamp a_timestamp) + { + m_salesService.SetLastSyncDate(a_timestamp.TableName, a_timestamp.Timestamp); + } + // POST api/ + /// + /// Endpoint to publish a collection of TblCart rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/tblCart")] + public async Task SyncSalesAsync(List a_item) + { + await m_salesService.SyncCart(a_item); + } + // POST api/ + /// + /// Endpoint to publish a collection of TblCancelledTransation rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/tblcancelledtransaction")] + public async Task SyncCancelledTransactionAsync(List a_item) + { + await m_salesService.SyncCancelledTransaction(a_item); + } + // POST api/ + /// + /// Endpoint to publish a collection of TblInvoice rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/tblinvoice")] + public async Task SyncInvoiceAsync(List a_item) + { + await m_salesService.SyncInvoice(a_item); + } + // POST api/ + /// + /// Endpoint to publish a collection of CreditPurchase rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/tblCreditpurchase")] + public async Task SyncCreditPurchaseAsync(List a_item) + { + await m_salesService.SyncCreditPurchase(a_item); + } + // POST api/ + /// + /// Endpoint to publish a collection of Customer Account rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/tblCustomerAccount")] + public async Task SyncCustomerAccountAsync(List a_item) + { + await m_salesService.SyncCustomerAccount(a_item); + } + // POST api/ + /// + /// Endpoint to publish a collection of Customer Purchase rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/CustomerPurchase")] + public async Task SyncCustomerPurchaseAsync(List a_item) + { + await m_salesService.SyncCustomerPurchase(a_item); + } + // POST api/ + /// + /// Endpoint to publish a collection of Discount logs rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/DiscountLogs")] + public async Task SyncDiscountLogsAsync(List a_item) + { + await m_salesService.SyncDiscountLogs(a_item); + } + // POST api/ + /// + /// Endpoint to publish a collection of Delivery Head rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/tblDeliveryhead")] + public async Task SyncDeliveryHeadAsync(List a_item) + { + await m_salesService.SyncDeliveryHead(a_item); + } + // POST api/ + /// + /// Endpoint to publish a collection of Delivery Details rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/tblDeliverydetails")] + public async Task SyncDeliveryDetailsAsync(List a_item) + { + await m_salesService.SyncDeliveryDetails(a_item); + } + // POST api/ + /// + /// Endpoint to publish a collection of Delivery Recipient rows to the cloud + /// + /// + [Authorize] + [HttpPost, Route("publish/tblDeliveryrecipient")] + public async Task SyncDeliveryRecipientAsync(List a_item) + { + await m_salesService.SyncDeliveryRecipients(a_item); + } + } +} diff --git a/Server/appsettings.json b/Server/appsettings.json index 984fb06..5331a5f 100644 --- a/Server/appsettings.json +++ b/Server/appsettings.json @@ -6,8 +6,8 @@ } }, "ConnectionStrings": { - "Connection": "server=54.37.19.162;database=dev_biskilogclients;user=biskilog;password=mefbuk-6niFsu-fytrew", - "PrivateConnection": "server={0};database={1};user=biskilog;password=mefbuk-6niFsu-fytrew;default command timeout=0;" + "Connection": "server=54.37.19.162;database=dev_biskilogclients;user=biskilog;password=mefbuk-6niFsu-fytrew;AllowZeroDateTime=True;", + "PrivateConnection": "server={0};database={1};user=biskilog;password=mefbuk-6niFsu-fytrew;default command timeout=0;AllowZeroDateTime=True;" }, "AllowedHosts": "*", "JWT": { diff --git a/Shared/CustomModels/SyncTimestamp.cs b/Shared/CustomModels/SyncTimestamp.cs new file mode 100644 index 0000000..5fe78c5 --- /dev/null +++ b/Shared/CustomModels/SyncTimestamp.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Biskilog_Accounting.Shared.CustomModels +{ + public class SyncTimestamp + { + public string TableName { get; set; } + public DateTime Timestamp { get; set; } + } +} diff --git a/Shared/Interfaces/ICompanyInfo.cs b/Shared/Interfaces/ICompanyInfo.cs index 66fb19b..450ff39 100644 --- a/Shared/Interfaces/ICompanyInfo.cs +++ b/Shared/Interfaces/ICompanyInfo.cs @@ -14,5 +14,15 @@ namespace Biskilog_Accounting.Shared.Interfaces Task> GetBranches(); string GetCompanyName(); string GetBranchName(string a_branchId); + Task SyncBranches(List a_branches); + Task SyncCompanyDetails(List a_details); + Task SyncDriverDetails(List a_details); + Task SyncSystemRoles(List a_roles); + Task SyncTrucks(List a_trucks); + Task SyncTruckAssignments(List a_assignments); + Task SyncTruckMappings(List a_mapping); + Task SyncTruckInventory(List a_inventories); + DateTime GetLastSyncDate(string a_tablename); + void SetLastSyncDate(string a_tableName, DateTime a_timestamp); } } diff --git a/Shared/Interfaces/ICustomer.cs b/Shared/Interfaces/ICustomer.cs index 4039c2d..0c5ab90 100644 --- a/Shared/Interfaces/ICustomer.cs +++ b/Shared/Interfaces/ICustomer.cs @@ -7,5 +7,6 @@ namespace Biskilog_Accounting.Shared.Interfaces { IEnumerable FetchCustomers(); Task> GetCustomers(); + Task SyncCustomers(List a_details); } } diff --git a/Shared/Interfaces/IProducts.cs b/Shared/Interfaces/IProducts.cs index b5f5aa7..871ba67 100644 --- a/Shared/Interfaces/IProducts.cs +++ b/Shared/Interfaces/IProducts.cs @@ -28,5 +28,17 @@ namespace Biskilog_Accounting.Shared.Interfaces event EventHandler UnitsChanged; event EventHandler BrandsChanged; event EventHandler CategoriesChanged; + Task SyncProducts(List a_item); + Task SyncInventory(List a_item); + Task SyncInventoryEntries(List a_item); + Task SyncPriceChanges(List a_items); + Task SyncProductAltUnit(List a_items); + Task SyncRestockAsync(List a_items); + Task SyncUnitOfMeasureAsync(List a_items); + Task SyncStockAsync(List a_items); + Task SyncBrandsAsync(List a_items); + Task SyncCategoriesAsync(List a_items); + DateTime GetLastSyncDate(string a_tablename); + void SetLastSyncDate(string a_tableName, DateTime a_timestamp); } } diff --git a/Shared/Interfaces/ISalesHub.cs b/Shared/Interfaces/ISalesHub.cs new file mode 100644 index 0000000..bb704e3 --- /dev/null +++ b/Shared/Interfaces/ISalesHub.cs @@ -0,0 +1,10 @@ +using Biskilog_Accounting.Shared.CustomModels; + +namespace Biskilog_Accounting.Shared.Interfaces +{ + public interface ISalesHub + { + Task TransactionMade(SaleItem a_transaction); + Task JoinCompanyGroup(); + } +} diff --git a/Shared/Interfaces/ISalesInterface.cs b/Shared/Interfaces/ISalesInterface.cs index 03801c4..72dc9e5 100644 --- a/Shared/Interfaces/ISalesInterface.cs +++ b/Shared/Interfaces/ISalesInterface.cs @@ -17,6 +17,18 @@ namespace Biskilog_Accounting.Shared.Interfaces Task FetchReceipt(string a_receiptId); IEnumerable GetReceipt(string a_receiptId); Task> GetReceiptDetail(string a_receiptId); + Task SyncCart(List a_item); + Task SyncCancelledTransaction(List a_item); + Task SyncCreditPurchase(List a_item); + Task SyncCustomerAccount(List a_customerAccounts); + Task SyncCustomerPurchase(List a_customerPurchase); + Task SyncDiscountLogs(List a_discountLog); + Task SyncDeliveryDetails(List a_details); + Task SyncDeliveryHead(List a_heads); + Task SyncDeliveryRecipients(List a_recipients); + Task SyncInvoice(List a_invoice); + DateTime GetLastSyncDate(string a_tablename); + void SetLastSyncDate(string a_tableName, DateTime a_timestamp); event EventHandler TransactionsChanged; event EventHandler FetchComplete; event EventHandler FetchStart; diff --git a/Shared/Interfaces/IUser.cs b/Shared/Interfaces/IUser.cs index 1318c18..8b1b712 100644 --- a/Shared/Interfaces/IUser.cs +++ b/Shared/Interfaces/IUser.cs @@ -11,5 +11,6 @@ namespace Biskilog_Accounting.Shared.Interfaces { IEnumerable FetchUsers(); Task> GetUsers(); + Task SyncUserAsync(List a_users); } } diff --git a/Shared/POSModels/Systemuserrole.cs b/Shared/POSModels/Systemuserrole.cs index 08f478d..b62b51f 100644 --- a/Shared/POSModels/Systemuserrole.cs +++ b/Shared/POSModels/Systemuserrole.cs @@ -7,13 +7,13 @@ public partial class Systemuserrole { public string? Roles { get; set; } - public sbyte? Owner { get; set; } + public bool? Owner { get; set; } - public sbyte? Manager { get; set; } + public bool? Manager { get; set; } - public sbyte? Assist { get; set; } + public bool? Assist { get; set; } - public sbyte? Cashier { get; set; } + public bool? Cashier { get; set; } public int Id { get; set; } } diff --git a/Shared/POSModels/Tblsyncinfo.cs b/Shared/POSModels/Tblsyncinfo.cs new file mode 100644 index 0000000..59f8194 --- /dev/null +++ b/Shared/POSModels/Tblsyncinfo.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; + +namespace Biskilog_Accounting.Server.POSModels; + +public partial class Tblsyncinfo +{ + public string TableName { get; set; } = null!; + + public DateTime? LastSyncDate { get; set; } = DateTime.MinValue; + + public string? BranchId { get; set; } +} diff --git a/Shared/POSModels/Tbluser.cs b/Shared/POSModels/Tbluser.cs index bc03592..ce46d7d 100644 --- a/Shared/POSModels/Tbluser.cs +++ b/Shared/POSModels/Tbluser.cs @@ -9,21 +9,21 @@ public partial class Tbluser public string BranchId { get; set; } = null!; - public string? Password { get; set; } + public string? Password { get; set; } = string.Empty; - public string? Firstname { get; set; } + public string? Firstname { get; set; } = string.Empty; - public string? Surname { get; set; } + public string? Surname { get; set; } = string.Empty; - public string? StreetAddress1 { get; set; } + public string? StreetAddress1 { get; set; } = string.Empty; - public string? StreetAddress2 { get; set; } + public string? StreetAddress2 { get; set; } = string.Empty; - public string? City { get; set; } + public string? City { get; set; } = string.Empty; - public string? StateOrProvince { get; set; } + public string? StateOrProvince { get; set; } = string.Empty; - public string? Telephone { get; set; } + public string? Telephone { get; set; } = string.Empty; public string? Email { get; set; } diff --git a/Shared/POSModels/Tbstock.cs b/Shared/POSModels/Tbstock.cs index 82684db..7c826b1 100644 --- a/Shared/POSModels/Tbstock.cs +++ b/Shared/POSModels/Tbstock.cs @@ -11,11 +11,13 @@ public partial class Tbstock public int? Qty { get; set; } - public DateOnly? Sdate { get; set; } + public DateTime? Sdate { get; set; } public string? Stockinby { get; set; } - public string BranchId { get; set; } = null!; + public string? BranchId { get; set; } public string CountId { get; set; } = null!; + + public DateTime LastModified { get; set; } }