Browse Source

Resolved productaltunit and tblcancelledtransactions sync issues

dev
Benjamin Arhen 1 year ago
parent
commit
a2cd8cd7c7
  1. 5
      ServerManager/ServiceRepo/ProductsService.cs
  2. 4
      ServerManager/ServiceRepo/SalesService.cs
  3. 46
      ServerManager/SyncMethods/ProductSync.cs
  4. 8
      ServerManager/appsettings.json

5
ServerManager/ServiceRepo/ProductsService.cs

@ -184,12 +184,11 @@ namespace ServerManager.ServiceRepo
// Using Dapper to call a stored procedure with parameters
var parameters = new
{
a_tableName = "productaltunit",
a_branchId = a_branch,
branchID = a_branch,
lastModified = a_lastSync
};
List<ProductAltUnit> result = (await dbConnection.QueryAsync<ProductAltUnit>(
"FetchTableRows",
"FetchProductAltUnitTableRows",
parameters,
commandType: CommandType.StoredProcedure)).AsList();

4
ServerManager/ServiceRepo/SalesService.cs

@ -32,7 +32,7 @@ namespace ServerManager.ServiceRepo
// Using Dapper to call a stored procedure with parameters
var parameters = new
{
a_tableName = "tblcancelledtransaction",
a_tableName = "tblcancelledtransactions",
a_branchId = a_branch,
lastModified = a_lastSync
};
@ -231,7 +231,7 @@ namespace ServerManager.ServiceRepo
// Using Dapper to call a stored procedure with parameters
var parameters = new
{
a_tableName = "TblInvoices",
a_tableName = "TblInvoice",
a_branchId = a_branch,
lastModified = a_lastSync
};

46
ServerManager/SyncMethods/ProductSync.cs

@ -181,32 +181,38 @@ namespace ServerManager.SyncMethods
}
private async Task SyncProductAltUnitAsync()
{
var responseMessage = await m_httpClient.GetAsync("/api/SyncProducts/lastsyncdate/productaltunit");
if (!responseMessage.IsSuccessStatusCode)
try
{
return;
}
var responseMessage = await m_httpClient.GetAsync("/api/SyncProducts/lastsyncdate/productaltunit");
if (!responseMessage.IsSuccessStatusCode)
{
return;
}
DateTime date = await responseMessage.Content.ReadFromJsonAsync<DateTime>();
IEnumerable<RestockLevel> modifiedCart = await m_productService.FetchRestockAsync(date, "BRID0");
SyncTimestamp syncTimestamp = new SyncTimestamp { TableName = "productaltunit", Timestamp = DateTime.Now.AddSeconds(-10) };
int batchSize = 200;
int totalItems = modifiedCart.Count();
int batches = (totalItems + batchSize - 1) / batchSize; // Calculate total batches
DateTime date = await responseMessage.Content.ReadFromJsonAsync<DateTime>();
IEnumerable<ProductAltUnit> modifiedCart = await m_productService.FetchProductAltUnit(date, "BRID0");
SyncTimestamp syncTimestamp = new SyncTimestamp { TableName = "productaltunit", Timestamp = DateTime.Now.AddSeconds(-10) };
int batchSize = 200;
int totalItems = modifiedCart.Count();
int batches = (totalItems + batchSize - 1) / batchSize; // Calculate total batches
for (int batchIndex = 0; batchIndex < batches; batchIndex++)
{
List<RestockLevel> batch = modifiedCart.Skip(batchIndex * batchSize).Take(batchSize).ToList();
var response = await m_httpClient.PostAsJsonAsync("/api/SyncProducts/publish/tblProductAltUnit", batch);
if (response.IsSuccessStatusCode)
for (int batchIndex = 0; batchIndex < batches; batchIndex++)
{
Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}");
List<ProductAltUnit> batch = modifiedCart.Skip(batchIndex * batchSize).Take(batchSize).ToList();
var response = await m_httpClient.PostAsJsonAsync("/api/SyncProducts/publish/tblProductAltUnit", batch);
if (response.IsSuccessStatusCode)
{
Console.WriteLine($"{syncTimestamp.TableName} : Sent batch {batchIndex + 1}, Count: {batch.Count}");
}
}
}
//Set last sync date
await m_httpClient.PostAsJsonAsync("/api/SyncProducts/setsyncdate", syncTimestamp);
//Set last sync date
await m_httpClient.PostAsJsonAsync("/api/SyncProducts/setsyncdate", syncTimestamp);
}catch (Exception ex)
{
}
}
private async Task SyncStockAsync()
{var responseMessage = await m_httpClient.GetAsync("/api/SyncProducts/lastsyncdate/tbstock");

8
ServerManager/appsettings.json

@ -10,10 +10,6 @@
},
"APIKEY": "AI1@h1BBmaU4d9LqU4W6UKGh7kWFNB9V",
"BaseUrl": "https://localhost:7122/",
"AllowedHosts": "*",
"JWT": {
"Key": "@@BISKILOGACCOUNTING2023DEV??//##$",
"Issuer": "AUTH SERVER",
"Audience": "BISKILOG"
}
"AllowedHosts": "*"
}
Loading…
Cancel
Save