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 { private readonly HttpClient m_http; private readonly DialogService m_dialogService; private DateTime m_currentTradeDate; private DateTime m_previousTradeDate; private IEnumerable m_branches; 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; } } }