using Biskilog_Accounting.Shared.CustomModels; using Biskilog_Accounting.Shared.Interfaces; using Biskilog_Accounting.Shared.POSModels; using System.Text.Json; namespace Biskilog_Accounting.Client.Repos { public class SalesRepository : ISalesInterface { private IEnumerable m_transactions; private IEnumerable m_recentTransactions; private readonly HttpClient m_http; public event EventHandler TransactionsChanged; public event EventHandler FetchComplete; public event EventHandler FetchStart; public SalesRepository(HttpClient a_http) { m_recentTransactions = m_transactions = new List(); m_http = a_http; } public async Task FetchRecentTransaction(int a_limit) { FetchStart?.Invoke(this, EventArgs.Empty); var response = await m_http.GetAsync($"api/analytics/sales/recent/{a_limit}"); if (response.IsSuccessStatusCode) { var jsonContent = await response.Content.ReadAsStringAsync(); var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true }; var recent = JsonSerializer.Deserialize>(jsonContent, options); m_recentTransactions = recent; } FetchComplete?.Invoke(this, EventArgs.Empty); } public async Task FetchTransaction(DateTime a_start, DateTime a_end) { FetchStart?.Invoke(this, EventArgs.Empty); string start = a_start.ToString("yyyy-MM-dd"); string end = a_end.ToString("yyyy-MM-dd"); var response = await m_http.GetAsync($"api/sales/transactions/{start}/{end}"); if (response.IsSuccessStatusCode) { var jsonContent = await response.Content.ReadAsStringAsync(); var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true }; var recent = JsonSerializer.Deserialize>(jsonContent, options); m_transactions = recent; TransactionsChanged?.Invoke(this, new EventArgs()); } FetchComplete?.Invoke(this, EventArgs.Empty); } public IEnumerable GetTransactions(DateTime a_start, DateTime a_end) { return m_transactions; } public IEnumerable GetRecentTransaction() { return m_recentTransactions; } public async Task FetchReceipt(string a_receiptId) { FetchStart?.Invoke(this, EventArgs.Empty); var response = await m_http.GetAsync($"api/sales/transactions/lookup/{a_receiptId}"); if (response.IsSuccessStatusCode) { var jsonContent = await response.Content.ReadAsStringAsync(); var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true }; var recent = JsonSerializer.Deserialize>(jsonContent, options); m_transactions = recent; TransactionsChanged?.Invoke(this, new EventArgs()); } FetchComplete?.Invoke(this, EventArgs.Empty); } public async Task> GetReceiptDetail(string a_receiptId) { var response = await m_http.GetAsync($"api/sales/receipt/lookup/{a_receiptId}"); if (response.IsSuccessStatusCode) { var jsonContent = await response.Content.ReadAsStringAsync(); var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true }; var recent = JsonSerializer.Deserialize>(jsonContent, options); return recent; } 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 } }