From a2cd8cd7c74a8312f4ba2a3c25830eb329953f6f Mon Sep 17 00:00:00 2001 From: barhen Date: Fri, 22 Dec 2023 12:29:16 -0500 Subject: [PATCH] Resolved productaltunit and tblcancelledtransactions sync issues --- ServerManager/ServiceRepo/ProductsService.cs | 5 +-- ServerManager/ServiceRepo/SalesService.cs | 4 +- ServerManager/SyncMethods/ProductSync.cs | 46 +++++++++++--------- ServerManager/appsettings.json | 8 +--- 4 files changed, 32 insertions(+), 31 deletions(-) diff --git a/ServerManager/ServiceRepo/ProductsService.cs b/ServerManager/ServiceRepo/ProductsService.cs index 2b3d0ab..7c3232a 100644 --- a/ServerManager/ServiceRepo/ProductsService.cs +++ b/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 result = (await dbConnection.QueryAsync( - "FetchTableRows", + "FetchProductAltUnitTableRows", parameters, commandType: CommandType.StoredProcedure)).AsList(); diff --git a/ServerManager/ServiceRepo/SalesService.cs b/ServerManager/ServiceRepo/SalesService.cs index f93a88d..3abb3eb 100644 --- a/ServerManager/ServiceRepo/SalesService.cs +++ b/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 }; diff --git a/ServerManager/SyncMethods/ProductSync.cs b/ServerManager/SyncMethods/ProductSync.cs index 14c1226..984c5c5 100644 --- a/ServerManager/SyncMethods/ProductSync.cs +++ b/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(); - IEnumerable 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(); + IEnumerable 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 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 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"); diff --git a/ServerManager/appsettings.json b/ServerManager/appsettings.json index 76d349f..b40c07c 100644 --- a/ServerManager/appsettings.json +++ b/ServerManager/appsettings.json @@ -10,10 +10,6 @@ }, "APIKEY": "AI1@h1BBmaU4d9LqU4W6UKGh7kWFNB9V", "BaseUrl": "https://localhost:7122/", - "AllowedHosts": "*", - "JWT": { - "Key": "@@BISKILOGACCOUNTING2023DEV??//##$", - "Issuer": "AUTH SERVER", - "Audience": "BISKILOG" - } + "AllowedHosts": "*" + } \ No newline at end of file