using Biskilog_Cloud.Shared.CustomModels; using Biskilog_Cloud.Shared.Interfaces; using Biskilog_Cloud.Shared.Models; using Dapper; using Microsoft.EntityFrameworkCore; using System.Data; using System.Data.SqlClient; namespace ServerManager.ServiceRepo { public class SalesService : ISalesInterface { private readonly BiskPosContext m_context; private readonly string m_connection; public SalesService(BiskPosContext a_context, IConfiguration configuration) { m_context = a_context; m_connection = configuration.GetConnectionString("connection")!.ToString(); } public event EventHandler TransactionsChanged; public event EventHandler FetchComplete; public event EventHandler FetchStart; public async Task> FetchCancelledTransaction(DateTime a_lastSync, string a_branch) { using (IDbConnection dbConnection = new SqlConnection(m_connection)) { dbConnection.Open(); // Using Dapper to call a stored procedure with parameters var parameters = new { a_tableName = "tblcancelledtransaction", a_branchId = a_branch, lastModified = a_lastSync }; List result = (await dbConnection.QueryAsync( "FetchTableRows", parameters, commandType: CommandType.StoredProcedure)).AsList(); return result; } } public async Task> FetchCartTbl(DateTime a_lastSync,string a_branch) { using (IDbConnection dbConnection = new SqlConnection(m_connection)) { dbConnection.Open(); // Using Dapper to call a stored procedure with parameters var parameters = new { a_tableName = "tblcart", a_branchId = a_branch, lastModified = a_lastSync }; List result = (await dbConnection.QueryAsync( "FetchTableRows", parameters, commandType: CommandType.StoredProcedure)).AsList(); return result; } } public async Task> FetchCreditPurchase(DateTime a_lastSync, string a_branch) { using (IDbConnection dbConnection = new SqlConnection(m_connection)) { dbConnection.Open(); // Using Dapper to call a stored procedure with parameters var parameters = new { a_tableName = "CreditPurchases", a_branchId = a_branch, lastModified = a_lastSync }; List result = (await dbConnection.QueryAsync( "FetchTableRows", parameters, commandType: CommandType.StoredProcedure)).AsList(); return result; } } public async Task> FetchCustomerAccount(DateTime a_lastSync, string a_branch) { using (IDbConnection dbConnection = new SqlConnection(m_connection)) { dbConnection.Open(); // Using Dapper to call a stored procedure with parameters var parameters = new { a_tableName = "customeraccounts", a_branchId = a_branch, lastModified = a_lastSync }; List result = (await dbConnection.QueryAsync( "FetchTableRows", parameters, commandType: CommandType.StoredProcedure)).AsList(); return result; } } public async Task> FetchCustomerPurchase(DateTime a_lastSync, string a_branch) { using (IDbConnection dbConnection = new SqlConnection(m_connection)) { dbConnection.Open(); // Using Dapper to call a stored procedure with parameters var parameters = new { a_tableName = "tblcustomerpurchases", a_branchId = a_branch, lastModified = a_lastSync }; List result = (await dbConnection.QueryAsync( "FetchTableRows", parameters, commandType: CommandType.StoredProcedure)).AsList(); return result; } } public async Task> FetchDeliveryDetails(DateTime a_lastSync, string a_branch) { using (IDbConnection dbConnection = new SqlConnection(m_connection)) { dbConnection.Open(); // Using Dapper to call a stored procedure with parameters var parameters = new { a_tableName = "tbldeliverydetails", a_branchId = a_branch, lastModified = a_lastSync }; List result = (await dbConnection.QueryAsync( "FetchTableRows", parameters, commandType: CommandType.StoredProcedure)).AsList(); return result; } } public async Task> FetchDeliveryHead(DateTime a_lastSync, string a_branch) { using (IDbConnection dbConnection = new SqlConnection(m_connection)) { dbConnection.Open(); // Using Dapper to call a stored procedure with parameters var parameters = new { a_tableName = "TblDeliveryHeads", a_branchId = a_branch, lastModified = a_lastSync }; List result = (await dbConnection.QueryAsync( "FetchTableRows", parameters, commandType: CommandType.StoredProcedure)).AsList(); return result; } } public async Task> FetchDeliveryRecipients(DateTime a_lastSync, string a_branch) { using (IDbConnection dbConnection = new SqlConnection(m_connection)) { dbConnection.Open(); // Using Dapper to call a stored procedure with parameters var parameters = new { a_tableName = "TblDeliveryRecipients", a_branchId = a_branch, lastModified = a_lastSync }; List result = (await dbConnection.QueryAsync( "FetchTableRows", parameters, commandType: CommandType.StoredProcedure)).AsList(); return result; } } public async Task> FetchDiscountLogs(DateTime a_lastSync, string a_branch) { using (IDbConnection dbConnection = new SqlConnection(m_connection)) { dbConnection.Open(); // Using Dapper to call a stored procedure with parameters var parameters = new { a_tableName = "TblDiscountLogs", a_branchId = a_branch, lastModified = a_lastSync }; List result = (await dbConnection.QueryAsync( "FetchTableRows", parameters, commandType: CommandType.StoredProcedure)).AsList(); return result; } } public async Task> FetchInvoice(DateTime a_lastSync, string a_branch) { using (IDbConnection dbConnection = new SqlConnection(m_connection)) { dbConnection.Open(); // Using Dapper to call a stored procedure with parameters var parameters = new { a_tableName = "TblInvoices", a_branchId = a_branch, lastModified = a_lastSync }; List result = (await dbConnection.QueryAsync( "FetchTableRows", parameters, commandType: CommandType.StoredProcedure)).AsList(); return result; } } public Task FetchReceipt(string a_receiptId) { throw new NotImplementedException(); } public Task FetchRecentTransaction(int a_limit) { throw new NotImplementedException(); } public Task FetchTransaction(DateTime a_start, DateTime a_end) { throw new NotImplementedException(); } public IEnumerable GetReceipt(string a_receiptId) { throw new NotImplementedException(); } public Task> GetReceiptDetail(string a_receiptId) { throw new NotImplementedException(); } public IEnumerable GetRecentTransaction() { throw new NotImplementedException(); } public IEnumerable GetTransactions(DateTime a_start, DateTime a_end) { throw new NotImplementedException(); } } }