using Biskilog_Accounting.Client.Pages.Transactions.Elements; using Biskilog_Accounting.Shared.CustomModels; using Biskilog_Accounting.Shared.Interfaces; using Biskilog_Accounting.Shared.POSModels; using Radzen; using System.Text.Json; namespace Biskilog_Accounting.Client.Repos { public class MainInterfaceService : IMainInterface, ICompanyInfo, IUser, ICustomer { private readonly HttpClient m_http; private readonly DialogService m_dialogService; private DateTime m_currentTradeDate; private DateTime m_previousTradeDate; private IEnumerable m_branches { get; set; } = new List(); private IEnumerable m_users { get; set; } = new List(); private IEnumerable m_customers { get; set; } = new List(); private Tblcompanydetail m_info; public MainInterfaceService(DialogService a_dialogService, HttpClient http) { m_dialogService = a_dialogService; m_currentTradeDate = new DateTime(2023, 05, 01); m_previousTradeDate = new DateTime(2023, 04, 01); m_http = http; } async Task OpenReceiptDialog(string a_receiptId) { await m_dialogService.OpenSideAsync("Receipt", new Dictionary() { { "ReceiptId", a_receiptId } }, options: new SideDialogOptions { CloseDialogOnOverlayClick = true, Position = DialogPosition.Right, ShowMask = true, ShowTitle = false, }); } public void ShowReceipt(string a_receiptId) { OpenReceiptDialog(a_receiptId); } public DateOnly CurrentTradeDate() { return DateOnly.FromDateTime(m_currentTradeDate); } public DateOnly PreviousTradeDate() { return DateOnly.FromDateTime(m_previousTradeDate); } public IEnumerable FetchBranches() { return m_branches; } public async Task GetCompanyInfoAsync() { var response = await m_http.GetAsync($"api/companyinfo/info"); if (response.IsSuccessStatusCode) { var jsonContent = await response.Content.ReadAsStringAsync(); var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true }; var recent = JsonSerializer.Deserialize(jsonContent, options); m_info = recent; return recent; } return null; } public async Task> GetBranches() { var response = await m_http.GetAsync($"api/companyinfo/branches"); if (response.IsSuccessStatusCode) { var jsonContent = await response.Content.ReadAsStringAsync(); var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true }; var recent = JsonSerializer.Deserialize>(jsonContent, options); m_branches = recent; return recent; } return null; } public string GetCompanyName() { return m_info.CompanyName; } public string GetBranchName(string a_branchId) { return m_branches.First(b => b.BranchId == a_branchId).BranchName; } public IEnumerable FetchUsers() { return m_users; } public async Task> GetUsers() { var response = await m_http.GetAsync($"api/users/accounts"); if (response.IsSuccessStatusCode) { var jsonContent = await response.Content.ReadAsStringAsync(); var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true }; var recent = JsonSerializer.Deserialize>(jsonContent, options); m_users = recent; return recent; } return null; } public IEnumerable FetchCustomers() { return m_customers; } public async Task> GetCustomers() { var response = await m_http.GetAsync($"api/customer/accounts"); if (response.IsSuccessStatusCode) { var jsonContent = await response.Content.ReadAsStringAsync(); var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true }; var recent = JsonSerializer.Deserialize>(jsonContent, options); m_customers = recent; return recent; } 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 } }