Browse Source

I forgot commit

pull/14/head
Benjamin Arhen 1 year ago
parent
commit
d44a0bfed5
  1. 66
      Client/Repos/MainInterfaceService.cs
  2. 60
      Client/Repos/ProductRepository.cs
  3. 70
      Client/Repos/SalesRepository.cs
  4. 20
      Server/BiskAcdbContext.cs
  5. 18
      Server/CloudHubs/SalesHub.cs
  6. 1
      Server/Program.cs
  7. 176
      Server/Services/CompanyService.cs
  8. 20
      Server/Services/CustomerService.cs
  9. 210
      Server/Services/ProductRepo.cs
  10. 219
      Server/Services/SalesService.cs
  11. 18
      Server/Services/UserService.cs
  12. 151
      Server/SyncControllers/SyncCompanyInfoController.cs
  13. 145
      Server/SyncControllers/SyncProductsController.cs
  14. 145
      Server/SyncControllers/SyncSalesController.cs
  15. 4
      Server/appsettings.json
  16. 14
      Shared/CustomModels/SyncTimestamp.cs
  17. 10
      Shared/Interfaces/ICompanyInfo.cs
  18. 1
      Shared/Interfaces/ICustomer.cs
  19. 12
      Shared/Interfaces/IProducts.cs
  20. 10
      Shared/Interfaces/ISalesHub.cs
  21. 12
      Shared/Interfaces/ISalesInterface.cs
  22. 1
      Shared/Interfaces/IUser.cs
  23. 8
      Shared/POSModels/Systemuserrole.cs
  24. 13
      Shared/POSModels/Tblsyncinfo.cs
  25. 16
      Shared/POSModels/Tbluser.cs
  26. 6
      Shared/POSModels/Tbstock.cs

66
Client/Repos/MainInterfaceService.cs

@ -134,5 +134,71 @@ namespace Biskilog_Accounting.Client.Repos
} }
return null; return null;
} }
#region Unimplemented
public Task SyncBranches(List<Tblbranch> a_branches)
{
throw new NotImplementedException();
}
public Task SyncCompanyDetails(List<Tblcompanydetail> a_details)
{
throw new NotImplementedException();
}
public Task SyncDriverDetails(List<Tbldriver> a_details)
{
throw new NotImplementedException();
}
public Task SyncSustemRoles(List<Systemuserrole> a_roles)
{
throw new NotImplementedException();
}
public Task SyncTrucks(List<Tbltruck> a_trucks)
{
throw new NotImplementedException();
}
public Task SyncTruckAssignments(List<Tbltruckassignment> a_assignments)
{
throw new NotImplementedException();
}
public Task SyncTruckMappings(List<TbltruckDrivermapping> a_mapping)
{
throw new NotImplementedException();
}
public Task SyncTruckInventory(List<Tbltruckinventory> 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<Tbluser> a_users)
{
throw new NotImplementedException();
}
public Task SyncCustomers(List<Tblcustomer> a_details)
{
throw new NotImplementedException();
}
public Task SyncSystemRoles(List<Systemuserrole> a_roles)
{
throw new NotImplementedException();
}
#endregion
} }
} }

60
Client/Repos/ProductRepository.cs

@ -139,5 +139,65 @@ namespace Biskilog_Accounting.Client.Repos
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task SyncProducts(List<Tblproduct> a_item)
{
throw new NotImplementedException();
}
public Task SyncInventory(List<Tblinventory> a_item)
{
throw new NotImplementedException();
}
public Task SyncInventoryEntries(List<Tblinventoryentry> a_item)
{
throw new NotImplementedException();
}
public Task SyncPriceChanges(List<Tblpricechange> a_items)
{
throw new NotImplementedException();
}
public Task SyncProductAltUnit(List<Productaltunit> a_items)
{
throw new NotImplementedException();
}
public Task SyncRestockAsync(List<Restocklevel> a_items)
{
throw new NotImplementedException();
}
public Task SyncUnitOfMeasureAsync(List<Unitofmeasure> a_items)
{
throw new NotImplementedException();
}
public Task SyncStockAsync(List<Tbstock> a_items)
{
throw new NotImplementedException();
}
public Task SyncBrandsAsync(List<Tblbrand> a_items)
{
throw new NotImplementedException();
}
public Task SyncCategoriesAsync(List<Tblcategory> 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();
}
} }
} }

70
Client/Repos/SalesRepository.cs

@ -77,11 +77,6 @@ namespace Biskilog_Accounting.Client.Repos
FetchComplete?.Invoke(this, EventArgs.Empty); FetchComplete?.Invoke(this, EventArgs.Empty);
} }
public IEnumerable<SaleItem> GetReceipt(string a_receiptId)
{
throw new NotImplementedException();
}
public async Task<IEnumerable<Tblcart>> GetReceiptDetail(string a_receiptId) public async Task<IEnumerable<Tblcart>> GetReceiptDetail(string a_receiptId)
{ {
var response = await m_http.GetAsync($"api/sales/receipt/lookup/{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; return null;
} }
#region Unimplemented
public IEnumerable<SaleItem> GetReceipt(string a_receiptId)
{
throw new NotImplementedException();
}
public Task SyncCart(List<Tblcart> 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<Tblcancelledtransaction> a_item)
{
throw new NotImplementedException();
}
public Task SyncCreditPurchase(List<Creditpurchase> a_item)
{
throw new NotImplementedException();
}
public Task SyncCustomerAccount(List<Customeraccount> a_customerAccounts)
{
throw new NotImplementedException();
}
public Task SyncCustomerPurchase(List<Tblcustomerpurchase> a_customerPurchase)
{
throw new NotImplementedException();
}
public Task SyncDiscountLogs(List<Tbldiscountlog> a_discountLog)
{
throw new NotImplementedException();
}
public Task SyncDeliveryDetails(List<Tbldeliverydetail> a_details)
{
throw new NotImplementedException();
}
public Task SyncDeliveryHead(List<Tbldeliveryhead> a_heads)
{
throw new NotImplementedException();
}
public Task SyncDeliveryRecipients(List<Tbldeliveryrecipient> a_recipients)
{
throw new NotImplementedException();
}
public Task SyncInvoice(List<Tblinvoice> a_invoice)
{
throw new NotImplementedException();
}
#endregion
} }
} }

20
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.Interfaces;
using Biskilog_Accounting.Shared.POSModels; using Biskilog_Accounting.Shared.POSModels;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Net.Http.Headers; using Microsoft.Net.Http.Headers;
using System.Security.Claims;
namespace Biskilog_Accounting.Server.POSModels; namespace Biskilog_Accounting.Server.POSModels;
@ -86,7 +84,7 @@ public partial class BiskAcdbContext : DbContext
public virtual DbSet<Tblpricechange> Tblpricechanges { get; set; } public virtual DbSet<Tblpricechange> Tblpricechanges { get; set; }
public virtual DbSet<Tblproduct> Tblproducts { get; set; } public virtual DbSet<Tblproduct> Tblproducts { get; set; }
public virtual DbSet<Tblsyncinfo> Tblsyncinfos { get; set; }
public virtual DbSet<Tbltruck> Tbltrucks { get; set; } public virtual DbSet<Tbltruck> Tbltrucks { get; set; }
public virtual DbSet<TbltruckDrivermapping> TbltruckDrivermappings { get; set; } public virtual DbSet<TbltruckDrivermapping> TbltruckDrivermappings { get; set; }
@ -1074,7 +1072,21 @@ public partial class BiskAcdbContext : DbContext
.UseCollation("utf8mb4_general_ci") .UseCollation("utf8mb4_general_ci")
.HasCharSet("utf8mb4"); .HasCharSet("utf8mb4");
}); });
modelBuilder.Entity<Tblsyncinfo>(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<Tbltruck>(entity => modelBuilder.Entity<Tbltruck>(entity =>
{ {
entity.HasKey(e => new { e.TruckId, e.BranchId }) entity.HasKey(e => new { e.TruckId, e.BranchId })

18
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<ISalesHub>
{
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);
}
}
}

1
Server/Program.cs

@ -13,6 +13,7 @@ using Biskilog_Accounting.Server.POSModels;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
// Add services to the container. // Add services to the container.
builder.Services.AddSignalR();
builder.Services.AddControllers().AddJsonOptions(x => x.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles); builder.Services.AddControllers().AddJsonOptions(x => x.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles);
builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
builder.Logging.ClearProviders(); builder.Logging.ClearProviders();

176
Server/Services/CompanyService.cs

@ -1,6 +1,11 @@
using Biskilog_Accounting.Server.POSModels; using Biskilog_Accounting.Server.POSModels;
using Biskilog_Accounting.Shared.Enums;
using Biskilog_Accounting.Shared.Interfaces; using Biskilog_Accounting.Shared.Interfaces;
using Biskilog_Accounting.Shared.POSModels; using Biskilog_Accounting.Shared.POSModels;
using Microsoft.EntityFrameworkCore;
using Microsoft.Net.Http.Headers;
using MySqlConnector;
using System.Text.Json;
namespace Biskilog_Accounting.Server.Services namespace Biskilog_Accounting.Server.Services
{ {
@ -41,7 +46,7 @@ namespace Biskilog_Accounting.Server.Services
public Task<Tblcompanydetail> GetCompanyInfoAsync() public Task<Tblcompanydetail> GetCompanyInfoAsync()
{ {
m_companyInfo = m_context.Tblcompanydetails.First(); m_companyInfo = m_context.Tblcompanydetails.FirstOrDefault();
return Task.FromResult(m_companyInfo); return Task.FromResult(m_companyInfo);
} }
@ -49,5 +54,174 @@ namespace Biskilog_Accounting.Server.Services
{ {
return m_companyInfo.CompanyName; return m_companyInfo.CompanyName;
} }
public async Task SyncBranches(List<Tblbranch> 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<Systemuserrole> 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<Tblcompanydetail> 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<Tbldriver> 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<Tbltruck> 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<Tbltruckassignment> 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<TbltruckDrivermapping> 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<Tbltruckinventory> 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();
}
}
}
} }
} }

20
Server/Services/CustomerService.cs

@ -2,10 +2,11 @@
using Biskilog_Accounting.Shared.CustomModels; using Biskilog_Accounting.Shared.CustomModels;
using Biskilog_Accounting.Shared.Enums; using Biskilog_Accounting.Shared.Enums;
using Biskilog_Accounting.Shared.Interfaces; using Biskilog_Accounting.Shared.Interfaces;
using Biskilog_Accounting.Shared.POSModels;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Net.Http.Headers; using Microsoft.Net.Http.Headers;
using MySqlConnector; using MySqlConnector;
using System.Drawing.Drawing2D; using System.Text.Json;
namespace Biskilog_Accounting.Server.Services namespace Biskilog_Accounting.Server.Services
{ {
@ -67,5 +68,22 @@ namespace Biskilog_Accounting.Server.Services
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public async Task SyncCustomers(List<Tblcustomer> 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();
}
}
}
} }
} }

210
Server/Services/ProductRepo.cs

@ -8,6 +8,7 @@ using Microsoft.Net.Http.Headers;
using MySqlConnector; using MySqlConnector;
using System.Data; using System.Data;
using System.Data.Common; using System.Data.Common;
using System.Text.Json;
namespace Biskilog_Accounting.Server.Services namespace Biskilog_Accounting.Server.Services
{ {
@ -146,7 +147,216 @@ namespace Biskilog_Accounting.Server.Services
} }
return new List<Tblcategory>(); return new List<Tblcategory>();
} }
public async Task SyncProducts(List<Tblproduct> 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<Tblinventory> 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<Tblinventoryentry> 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<Tblpricechange> 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<Productaltunit> 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<Restocklevel> 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<Unitofmeasure> 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<Tbstock> 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<Tblbrand> 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<Tblcategory> 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 #region Only Need to implement in the client Side
public Task FetchUnits() public Task FetchUnits()
{ {

219
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.CustomModels;
using Biskilog_Accounting.Shared.Enums; using Biskilog_Accounting.Shared.Enums;
using Biskilog_Accounting.Shared.Interfaces; using Biskilog_Accounting.Shared.Interfaces;
using Biskilog_Accounting.Shared.POSModels; using Biskilog_Accounting.Shared.POSModels;
using Microsoft.AspNetCore.SignalR;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Net.Http.Headers; using Microsoft.Net.Http.Headers;
using MySqlConnector; using MySqlConnector;
using System.Drawing.Drawing2D; using System.Text.Json;
namespace Biskilog_Accounting.Server.Services namespace Biskilog_Accounting.Server.Services
{ {
@ -15,16 +17,19 @@ namespace Biskilog_Accounting.Server.Services
private readonly BiskAcdbContext m_context; private readonly BiskAcdbContext m_context;
private readonly ITokenService m_tokenService; private readonly ITokenService m_tokenService;
private readonly HttpContext m_httpContext; private readonly HttpContext m_httpContext;
private readonly IHubContext<SalesHub, ISalesHub> m_salesHub;
public event EventHandler TransactionsChanged; public event EventHandler TransactionsChanged;
public event EventHandler FetchComplete; public event EventHandler FetchComplete;
public event EventHandler FetchStart; 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<SalesHub, ISalesHub> a_salesHub)
{ {
m_context = a_context; m_context = a_context;
m_tokenService = a_tokenService; m_tokenService = a_tokenService;
m_httpContext = a_httpContextAccessor?.HttpContext; m_httpContext = a_httpContextAccessor?.HttpContext;
m_salesHub = a_salesHub;
} }
public Task FetchRecentTransaction(int a_limit) 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()); return Task.FromResult(details.AsEnumerable());
} }
public async Task SyncCart(List<Tblcart> 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<Tblcancelledtransaction> 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<Creditpurchase> 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<Customeraccount> 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<Tblcustomerpurchase> 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<Tbldiscountlog> 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<Tbldeliverydetail> 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<Tbldeliveryhead> 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<Tbldeliveryrecipient> 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<Tblinvoice> 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();
}
}
}
} }
} }

18
Server/Services/UserService.cs

@ -7,6 +7,7 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.Net.Http.Headers; using Microsoft.Net.Http.Headers;
using MySqlConnector; using MySqlConnector;
using System.Drawing.Drawing2D; using System.Drawing.Drawing2D;
using System.Text.Json;
namespace Biskilog_Accounting.Server.Services namespace Biskilog_Accounting.Server.Services
{ {
@ -39,5 +40,22 @@ namespace Biskilog_Accounting.Server.Services
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public async Task SyncUserAsync(List<Tbluser> 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();
}
}
}
} }
} }

151
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/<SyncCompanyInfoController>
[Authorize]
[HttpGet, Route("lastsyncdate/{a_tableName}")]
public DateTime GetLastSyncDate(string a_tableName)
{
return m_salesService.GetLastSyncDate(a_tableName);
}
// Post: api/<SyncCompanyInfoController>
[Authorize]
[HttpPost, Route("setsyncdate")]
public void SetLastSyncDate(SyncTimestamp a_timestamp)
{
m_salesService.SetLastSyncDate(a_timestamp.TableName, a_timestamp.Timestamp);
}
// POST api/<SyncCompanyInfoController>
/// <summary>
/// Endpoint to publish a collection of SystemUserRoles rows to the cloud
/// </summary>
/// <param name="a_item"></param>
[Authorize]
[HttpPost, Route("publish/SystemRoles")]
public async Task SyncSyatemRolesAsync(List<Systemuserrole> a_item)
{
await m_companyInfo.SyncSystemRoles(a_item);
}
// POST api/<SyncCompanyInfoController>
/// <summary>
/// Endpoint to publish a collection of TblDriver rows to the cloud
/// </summary>
/// <param name="a_item"></param>
[Authorize]
[HttpPost, Route("publish/tblDriver")]
public async Task SyncDriversAsync(List<Tbldriver> a_item)
{
await m_companyInfo.SyncDriverDetails(a_item);
}
// POST api/<SyncCompanyInfoController>
/// <summary>
/// Endpoint to publish a collection of CompanyDetails rows to the cloud
/// </summary>
/// <param name="a_item"></param>
[Authorize]
[HttpPost, Route("publish/tblcompanydetails")]
public async Task SyncCompanyAsync(List<Tblcompanydetail> a_item)
{
await m_companyInfo.SyncCompanyDetails(a_item);
}
// POST api/<SyncCompanyInfoController>
/// <summary>
/// Endpoint to publish a collection of TblUsers rows to the cloud
/// </summary>
/// <param name="a_item"></param>
[Authorize]
[HttpPost, Route("publish/tblusers")]
public async Task SyncUsersAsync(List<Tbluser> a_item)
{
await m_users.SyncUserAsync(a_item);
}
// POST api/<SyncCompanyInfoController>
/// <summary>
/// Endpoint to publish a collection of Trucks rows to the cloud
/// </summary>
/// <param name="a_item"></param>
[Authorize]
[HttpPost, Route("publish/tbltrucks")]
public async Task SyncTrucksAsync(List<Tbltruck> a_item)
{
await m_companyInfo.SyncTrucks(a_item);
}
// POST api/<SyncCompanyInfoController>
/// <summary>
/// Endpoint to publish a collection of TblBranch rows to the cloud
/// </summary>
/// <param name="a_item"></param>
[Authorize]
[HttpPost, Route("publish/tblbranch")]
public async Task SyncBranchAsync(List<Tblbranch> a_item)
{
await m_companyInfo.SyncBranches(a_item);
}
// POST api/<SyncCompanyInfoController>
/// <summary>
/// Endpoint to publish a collection of TblCustomers rows to the cloud
/// </summary>
/// <param name="a_item"></param>
[Authorize]
[HttpPost, Route("publish/tblcustomers")]
public async Task SyncCustomersAsync(List<Tblcustomer> a_item)
{
await m_customer.SyncCustomers(a_item);
}
// POST api/<SyncCompanyInfoController>
/// <summary>
/// Endpoint to publish a collection of TblTruck Inventory rows to the cloud
/// </summary>
/// <param name="a_item"></param>
[Authorize]
[HttpPost, Route("publish/tbltruckinventory")]
public async Task SyncTruckInventoryAsync(List<Tbltruckinventory> a_item)
{
await m_companyInfo.SyncTruckInventory(a_item);
}
// POST api/<SyncCompanyInfoController>
/// <summary>
/// Endpoint to publish a collection of TblTruckAssignment rows to the cloud
/// </summary>
/// <param name="a_item"></param>
[Authorize]
[HttpPost, Route("publish/tblTruckAssignment")]
public async Task SyncTruckAssignmentSync(List<Tbltruckassignment> a_item)
{
await m_companyInfo.SyncTruckAssignments(a_item);
}
// POST api/<SyncCompanyInfoController>
/// <summary>
/// Endpoint to publish a collection of TblDriverMapping rows to the cloud
/// </summary>
/// <param name="a_item"></param>
[Authorize]
[HttpPost, Route("publish/tbldrivermappings")]
public async Task SyncTruckDriverMappingSync(List<TbltruckDrivermapping> a_item)
{
await m_companyInfo.SyncTruckMappings(a_item);
}
}
}

145
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/<SyncProductsController>
[Authorize]
[HttpGet, Route("lastsyncdate/{a_tableName}")]
public DateTime GetLastSyncDate(string a_tableName)
{
return m_productService.GetLastSyncDate(a_tableName);
}
// Post: api/<SyncProductsController>
[Authorize]
[HttpPost, Route("setsyncdate")]
public void SetLastSyncDate(SyncTimestamp a_timestamp)
{
m_productService.SetLastSyncDate(a_timestamp.TableName, a_timestamp.Timestamp);
}
// POST api/<SyncProductsController>
/// <summary>
/// Endpoint to publish a collection of TblProduct rows to the cloud
/// </summary>
/// <param name="a_item"></param>
[Authorize]
[HttpPost, Route("publish/tblProducts")]
public async Task SyncProductsAsync(List<Tblproduct> a_item)
{
await m_productService.SyncProducts(a_item);
}
// POST api/<SyncProductsController>
/// <summary>
/// Endpoint to publish a collection of TblInventory rows to the cloud
/// </summary>
/// <param name="a_item"></param>
[Authorize]
[HttpPost, Route("publish/tblInventory")]
public async Task SyncInventoryAsync(List<Tblinventory> a_item)
{
await m_productService.SyncInventory(a_item);
}
// POST api/<SyncProductsController>
/// <summary>
/// Endpoint to publish a collection of Restock rows to the cloud
/// </summary>
/// <param name="a_item"></param>
[Authorize]
[HttpPost, Route("publish/tblRestock")]
public async Task SyncRestockAsync(List<Restocklevel> a_item)
{
await m_productService.SyncRestockAsync(a_item);
}
// POST api/<SyncProductsController>
/// <summary>
/// Endpoint to publish a collection of TblInventoryEntries rows to the cloud
/// </summary>
/// <param name="a_item"></param>
[Authorize]
[HttpPost, Route("publish/tblInventoryentry")]
public async Task SyncInventoryEntriesAsync(List<Tblinventoryentry> a_item)
{
await m_productService.SyncInventoryEntries(a_item);
}
// POST api/<SyncProductsController>
/// <summary>
/// Endpoint to publish a collection of PriceChanges rows to the cloud
/// </summary>
/// <param name="a_item"></param>
[Authorize]
[HttpPost, Route("publish/tlpricechanges")]
public async Task SyncPriceChangesAsync(List<Tblpricechange> a_item)
{
await m_productService.SyncPriceChanges(a_item);
}
// POST api/<SyncProductsController>
/// <summary>
/// Endpoint to publish a collection of ProductAltUnit rows to the cloud
/// </summary>
/// <param name="a_item"></param>
[Authorize]
[HttpPost, Route("publish/tblProductAltUnit")]
public async Task SyncProductAltUnitAsync(List<Productaltunit> a_item)
{
await m_productService.SyncProductAltUnit(a_item);
}
// POST api/<SyncProductsController>
/// <summary>
/// Endpoint to publish a collection of TbStock rows to the cloud
/// </summary>
/// <param name="a_item"></param>
[Authorize]
[HttpPost, Route("publish/tblStock")]
public async Task SyncStockAsync(List<Tbstock> a_item)
{
await m_productService.SyncStockAsync(a_item);
}
// POST api/<SyncProductsController>
/// <summary>
/// Endpoint to publish a collection of TblBrands rows to the cloud
/// </summary>
/// <param name="a_item"></param>
[Authorize]
[HttpPost, Route("publish/tblbrands")]
public async Task SyncBrandsAsync(List<Tblbrand> a_item)
{
await m_productService.SyncBrandsAsync(a_item);
}
// POST api/<SyncProductsController>
/// <summary>
/// Endpoint to publish a collection of TblCategory rows to the cloud
/// </summary>
/// <param name="a_item"></param>
[Authorize]
[HttpPost, Route("publish/tblCategories")]
public async Task SyncCategoriesAsync(List<Tblcategory> a_item)
{
await m_productService.SyncCategoriesAsync(a_item);
}
// POST api/<SyncProductsController>
/// <summary>
/// Endpoint to publish a collection of UnitOfMeasure rows to the cloud
/// </summary>
/// <param name="a_item"></param>
[Authorize]
[HttpPost, Route("publish/tblunitofmeasure")]
public async Task SyncUnitMeasureAsync(List<Unitofmeasure> a_item)
{
await m_productService.SyncUnitOfMeasureAsync(a_item);
}
}
}

145
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/<SyncSalesController>
[Authorize]
[HttpGet, Route("lastsyncdate/{a_tableName}")]
public DateTime GetLastSyncDate(string a_tableName)
{
return m_salesService.GetLastSyncDate(a_tableName);
}
// Post: api/<SyncSalesController>
[Authorize]
[HttpPost, Route("setsyncdate")]
public void SetLastSyncDate(SyncTimestamp a_timestamp)
{
m_salesService.SetLastSyncDate(a_timestamp.TableName, a_timestamp.Timestamp);
}
// POST api/<SyncSalesController>
/// <summary>
/// Endpoint to publish a collection of TblCart rows to the cloud
/// </summary>
/// <param name="a_item"></param>
[Authorize]
[HttpPost, Route("publish/tblCart")]
public async Task SyncSalesAsync(List<Tblcart> a_item)
{
await m_salesService.SyncCart(a_item);
}
// POST api/<SyncSalesController>
/// <summary>
/// Endpoint to publish a collection of TblCancelledTransation rows to the cloud
/// </summary>
/// <param name="a_item"></param>
[Authorize]
[HttpPost, Route("publish/tblcancelledtransaction")]
public async Task SyncCancelledTransactionAsync(List<Tblcancelledtransaction> a_item)
{
await m_salesService.SyncCancelledTransaction(a_item);
}
// POST api/<SyncSalesController>
/// <summary>
/// Endpoint to publish a collection of TblInvoice rows to the cloud
/// </summary>
/// <param name="a_item"></param>
[Authorize]
[HttpPost, Route("publish/tblinvoice")]
public async Task SyncInvoiceAsync(List<Tblinvoice> a_item)
{
await m_salesService.SyncInvoice(a_item);
}
// POST api/<SyncSalesController>
/// <summary>
/// Endpoint to publish a collection of CreditPurchase rows to the cloud
/// </summary>
/// <param name="a_item"></param>
[Authorize]
[HttpPost, Route("publish/tblCreditpurchase")]
public async Task SyncCreditPurchaseAsync(List<Creditpurchase> a_item)
{
await m_salesService.SyncCreditPurchase(a_item);
}
// POST api/<SyncSalesController>
/// <summary>
/// Endpoint to publish a collection of Customer Account rows to the cloud
/// </summary>
/// <param name="a_item"></param>
[Authorize]
[HttpPost, Route("publish/tblCustomerAccount")]
public async Task SyncCustomerAccountAsync(List<Customeraccount> a_item)
{
await m_salesService.SyncCustomerAccount(a_item);
}
// POST api/<SyncSalesController>
/// <summary>
/// Endpoint to publish a collection of Customer Purchase rows to the cloud
/// </summary>
/// <param name="a_item"></param>
[Authorize]
[HttpPost, Route("publish/CustomerPurchase")]
public async Task SyncCustomerPurchaseAsync(List<Tblcustomerpurchase> a_item)
{
await m_salesService.SyncCustomerPurchase(a_item);
}
// POST api/<SyncSalesController>
/// <summary>
/// Endpoint to publish a collection of Discount logs rows to the cloud
/// </summary>
/// <param name="a_item"></param>
[Authorize]
[HttpPost, Route("publish/DiscountLogs")]
public async Task SyncDiscountLogsAsync(List<Tbldiscountlog> a_item)
{
await m_salesService.SyncDiscountLogs(a_item);
}
// POST api/<SyncSalesController>
/// <summary>
/// Endpoint to publish a collection of Delivery Head rows to the cloud
/// </summary>
/// <param name="a_item"></param>
[Authorize]
[HttpPost, Route("publish/tblDeliveryhead")]
public async Task SyncDeliveryHeadAsync(List<Tbldeliveryhead> a_item)
{
await m_salesService.SyncDeliveryHead(a_item);
}
// POST api/<SyncSalesController>
/// <summary>
/// Endpoint to publish a collection of Delivery Details rows to the cloud
/// </summary>
/// <param name="a_item"></param>
[Authorize]
[HttpPost, Route("publish/tblDeliverydetails")]
public async Task SyncDeliveryDetailsAsync(List<Tbldeliverydetail> a_item)
{
await m_salesService.SyncDeliveryDetails(a_item);
}
// POST api/<SyncSalesController>
/// <summary>
/// Endpoint to publish a collection of Delivery Recipient rows to the cloud
/// </summary>
/// <param name="a_item"></param>
[Authorize]
[HttpPost, Route("publish/tblDeliveryrecipient")]
public async Task SyncDeliveryRecipientAsync(List<Tbldeliveryrecipient> a_item)
{
await m_salesService.SyncDeliveryRecipients(a_item);
}
}
}

4
Server/appsettings.json

@ -6,8 +6,8 @@
} }
}, },
"ConnectionStrings": { "ConnectionStrings": {
"Connection": "server=54.37.19.162;database=dev_biskilogclients;user=biskilog;password=mefbuk-6niFsu-fytrew", "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;" "PrivateConnection": "server={0};database={1};user=biskilog;password=mefbuk-6niFsu-fytrew;default command timeout=0;AllowZeroDateTime=True;"
}, },
"AllowedHosts": "*", "AllowedHosts": "*",
"JWT": { "JWT": {

14
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; }
}
}

10
Shared/Interfaces/ICompanyInfo.cs

@ -14,5 +14,15 @@ namespace Biskilog_Accounting.Shared.Interfaces
Task<IEnumerable<Tblbranch>> GetBranches(); Task<IEnumerable<Tblbranch>> GetBranches();
string GetCompanyName(); string GetCompanyName();
string GetBranchName(string a_branchId); string GetBranchName(string a_branchId);
Task SyncBranches(List<Tblbranch> a_branches);
Task SyncCompanyDetails(List<Tblcompanydetail> a_details);
Task SyncDriverDetails(List<Tbldriver> a_details);
Task SyncSystemRoles(List<Systemuserrole> a_roles);
Task SyncTrucks(List<Tbltruck> a_trucks);
Task SyncTruckAssignments(List<Tbltruckassignment> a_assignments);
Task SyncTruckMappings(List<TbltruckDrivermapping> a_mapping);
Task SyncTruckInventory(List<Tbltruckinventory> a_inventories);
DateTime GetLastSyncDate(string a_tablename);
void SetLastSyncDate(string a_tableName, DateTime a_timestamp);
} }
} }

1
Shared/Interfaces/ICustomer.cs

@ -7,5 +7,6 @@ namespace Biskilog_Accounting.Shared.Interfaces
{ {
IEnumerable<CustomerAccounts> FetchCustomers(); IEnumerable<CustomerAccounts> FetchCustomers();
Task<IEnumerable<CustomerAccounts>> GetCustomers(); Task<IEnumerable<CustomerAccounts>> GetCustomers();
Task SyncCustomers(List<Tblcustomer> a_details);
} }
} }

12
Shared/Interfaces/IProducts.cs

@ -28,5 +28,17 @@ namespace Biskilog_Accounting.Shared.Interfaces
event EventHandler UnitsChanged; event EventHandler UnitsChanged;
event EventHandler BrandsChanged; event EventHandler BrandsChanged;
event EventHandler CategoriesChanged; event EventHandler CategoriesChanged;
Task SyncProducts(List<Tblproduct> a_item);
Task SyncInventory(List<Tblinventory> a_item);
Task SyncInventoryEntries(List<Tblinventoryentry> a_item);
Task SyncPriceChanges(List<Tblpricechange> a_items);
Task SyncProductAltUnit(List<Productaltunit> a_items);
Task SyncRestockAsync(List<Restocklevel> a_items);
Task SyncUnitOfMeasureAsync(List<Unitofmeasure> a_items);
Task SyncStockAsync(List<Tbstock> a_items);
Task SyncBrandsAsync(List<Tblbrand> a_items);
Task SyncCategoriesAsync(List<Tblcategory> a_items);
DateTime GetLastSyncDate(string a_tablename);
void SetLastSyncDate(string a_tableName, DateTime a_timestamp);
} }
} }

10
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();
}
}

12
Shared/Interfaces/ISalesInterface.cs

@ -17,6 +17,18 @@ namespace Biskilog_Accounting.Shared.Interfaces
Task FetchReceipt(string a_receiptId); Task FetchReceipt(string a_receiptId);
IEnumerable<SaleItem> GetReceipt(string a_receiptId); IEnumerable<SaleItem> GetReceipt(string a_receiptId);
Task<IEnumerable<Tblcart>> GetReceiptDetail(string a_receiptId); Task<IEnumerable<Tblcart>> GetReceiptDetail(string a_receiptId);
Task SyncCart(List<Tblcart> a_item);
Task SyncCancelledTransaction(List<Tblcancelledtransaction> a_item);
Task SyncCreditPurchase(List<Creditpurchase> a_item);
Task SyncCustomerAccount(List<Customeraccount> a_customerAccounts);
Task SyncCustomerPurchase(List<Tblcustomerpurchase> a_customerPurchase);
Task SyncDiscountLogs(List<Tbldiscountlog> a_discountLog);
Task SyncDeliveryDetails(List<Tbldeliverydetail> a_details);
Task SyncDeliveryHead(List<Tbldeliveryhead> a_heads);
Task SyncDeliveryRecipients(List<Tbldeliveryrecipient> a_recipients);
Task SyncInvoice(List<Tblinvoice> a_invoice);
DateTime GetLastSyncDate(string a_tablename);
void SetLastSyncDate(string a_tableName, DateTime a_timestamp);
event EventHandler TransactionsChanged; event EventHandler TransactionsChanged;
event EventHandler FetchComplete; event EventHandler FetchComplete;
event EventHandler FetchStart; event EventHandler FetchStart;

1
Shared/Interfaces/IUser.cs

@ -11,5 +11,6 @@ namespace Biskilog_Accounting.Shared.Interfaces
{ {
IEnumerable<Tbluser> FetchUsers(); IEnumerable<Tbluser> FetchUsers();
Task<IEnumerable<Tbluser>> GetUsers(); Task<IEnumerable<Tbluser>> GetUsers();
Task SyncUserAsync(List<Tbluser> a_users);
} }
} }

8
Shared/POSModels/Systemuserrole.cs

@ -7,13 +7,13 @@ public partial class Systemuserrole
{ {
public string? Roles { get; set; } 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; } public int Id { get; set; }
} }

13
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; }
}

16
Shared/POSModels/Tbluser.cs

@ -9,21 +9,21 @@ public partial class Tbluser
public string BranchId { get; set; } = null!; 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; } public string? Email { get; set; }

6
Shared/POSModels/Tbstock.cs

@ -11,11 +11,13 @@ public partial class Tbstock
public int? Qty { get; set; } public int? Qty { get; set; }
public DateOnly? Sdate { get; set; } public DateTime? Sdate { get; set; }
public string? Stockinby { 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 string CountId { get; set; } = null!;
public DateTime LastModified { get; set; }
} }

Loading…
Cancel
Save