New source control repo for Biskilog POS - secure hub to store & manage source code. Streamlines dev process, tracks changes, & improves collaboration. Ensures reliable software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

98 lines
3.3 KiB

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<Tblbranch> 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<ReceiptDialog>("Receipt",
new Dictionary<string, object>() { { "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<Tblbranch> FetchBranches()
{
return m_branches;
}
public async Task<Tblcompanydetail> 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<Tblcompanydetail>(jsonContent, options);
m_info = recent;
return recent;
}
return null;
}
public async Task<IEnumerable<Tblbranch>> 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<IEnumerable<Tblbranch>>(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;
}
}
}