|
|
@ -14,7 +14,7 @@ namespace Cloud_Manager.Services |
|
|
|
public class SalesService : ISalesInterface |
|
|
|
{ |
|
|
|
private readonly BiskAcdbContext m_context; |
|
|
|
private readonly ITokenService m_tokenService; |
|
|
|
private readonly IKeyService m_tokenService; |
|
|
|
private readonly HttpContext m_httpContext; |
|
|
|
private readonly IHubContext<SalesHub, ISalesHub> m_salesHub; |
|
|
|
|
|
|
@ -22,7 +22,7 @@ namespace Cloud_Manager.Services |
|
|
|
public event EventHandler FetchComplete; |
|
|
|
public event EventHandler FetchStart; |
|
|
|
|
|
|
|
public SalesService(BiskAcdbContext a_context, ITokenService a_tokenService, |
|
|
|
public SalesService(BiskAcdbContext a_context, IKeyService a_tokenService, |
|
|
|
IHttpContextAccessor a_httpContextAccessor, IHubContext<SalesHub, ISalesHub> a_salesHub) |
|
|
|
{ |
|
|
|
m_context = a_context; |
|
|
@ -31,151 +31,11 @@ namespace Cloud_Manager.Services |
|
|
|
m_salesHub = a_salesHub; |
|
|
|
} |
|
|
|
|
|
|
|
public Task FetchRecentTransaction(int a_limit) |
|
|
|
{ |
|
|
|
throw new NotImplementedException(); |
|
|
|
} |
|
|
|
|
|
|
|
public IEnumerable<SaleItem> GetRecentTransaction() |
|
|
|
{ |
|
|
|
throw new NotImplementedException(); |
|
|
|
} |
|
|
|
|
|
|
|
public IEnumerable<SaleItem> GetTransactions(DateTime a_start, DateTime a_end) |
|
|
|
{ |
|
|
|
string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; |
|
|
|
|
|
|
|
if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) |
|
|
|
{ |
|
|
|
IEnumerable<string> accessiblebranches = m_tokenService.BranchIds(token); |
|
|
|
|
|
|
|
using (var command = m_context.Database.GetDbConnection().CreateCommand()) |
|
|
|
{ |
|
|
|
command.CommandText = "CALL GetTransactionsByDate(@p0,@p1,@p2)"; |
|
|
|
command.Parameters.Add(new MySqlParameter("@p0", a_start.ToString("yyyy-MM-dd"))); |
|
|
|
command.Parameters.Add(new MySqlParameter("@p1", a_end.ToString("yyyy-MM-dd"))); |
|
|
|
command.Parameters.Add(new MySqlParameter("@p2", string.Join(", ", accessiblebranches.ToArray()))); |
|
|
|
|
|
|
|
m_context.Database.OpenConnection(); |
|
|
|
|
|
|
|
using (var reader = command.ExecuteReader()) |
|
|
|
{ |
|
|
|
while (reader.Read()) |
|
|
|
{ |
|
|
|
yield return new SaleItem |
|
|
|
{ |
|
|
|
Transno = reader.GetString(0), |
|
|
|
Total = (decimal)reader.GetDouble(1), |
|
|
|
Date = reader.GetDateTime(2), |
|
|
|
Cashier = reader.GetString(3), |
|
|
|
BranchId = reader.GetString(4), |
|
|
|
Customer = reader.GetString(5), |
|
|
|
Status = reader.GetString(6), |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public Task FetchTransaction(DateTime a_start, DateTime a_end) |
|
|
|
{ |
|
|
|
throw new NotImplementedException(); |
|
|
|
} |
|
|
|
|
|
|
|
public Task FetchReceipt(string a_receiptId) |
|
|
|
{ |
|
|
|
throw new NotImplementedException(); |
|
|
|
} |
|
|
|
|
|
|
|
public IEnumerable<SaleItem> GetReceipt(string a_receiptId) |
|
|
|
{ |
|
|
|
string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; |
|
|
|
|
|
|
|
if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) |
|
|
|
{ |
|
|
|
IEnumerable<string> accessiblebranches = m_tokenService.BranchIds(token); |
|
|
|
|
|
|
|
using (var command = m_context.Database.GetDbConnection().CreateCommand()) |
|
|
|
{ |
|
|
|
command.CommandText = "CALL GetTransactionsById(@p0,@p1)"; |
|
|
|
command.Parameters.Add(new MySqlParameter("@p0", a_receiptId)); |
|
|
|
command.Parameters.Add(new MySqlParameter("@p1", string.Join(", ", accessiblebranches.ToArray()))); |
|
|
|
|
|
|
|
m_context.Database.OpenConnection(); |
|
|
|
|
|
|
|
using (var reader = command.ExecuteReader()) |
|
|
|
{ |
|
|
|
while (reader.Read()) |
|
|
|
{ |
|
|
|
yield return new SaleItem |
|
|
|
{ |
|
|
|
Transno = reader.GetString(0), |
|
|
|
Total = (decimal)reader.GetDouble(1), |
|
|
|
Date = reader.GetDateTime(2), |
|
|
|
Cashier = reader.GetString(3), |
|
|
|
BranchId = reader.GetString(4), |
|
|
|
Customer = reader.GetString(5), |
|
|
|
Status = reader.GetString(6), |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
// Close the connection explicitly
|
|
|
|
m_context.Database.CloseConnection(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public Task<IEnumerable<Tblcart>> GetReceiptDetail(string a_receiptId) |
|
|
|
{ |
|
|
|
List<Tblcart> details = new List<Tblcart>(); |
|
|
|
string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; |
|
|
|
|
|
|
|
if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) |
|
|
|
{ |
|
|
|
IEnumerable<string> accessiblebranches = m_tokenService.BranchIds(token); |
|
|
|
|
|
|
|
using (var command = m_context.Database.GetDbConnection().CreateCommand()) |
|
|
|
{ |
|
|
|
command.CommandText = "CALL GetReceiptDetails(@p0,@p1)"; |
|
|
|
command.Parameters.Add(new MySqlParameter("@p0", a_receiptId)); |
|
|
|
command.Parameters.Add(new MySqlParameter("@p1", string.Join(", ", accessiblebranches.ToArray()))); |
|
|
|
|
|
|
|
m_context.Database.OpenConnection(); |
|
|
|
|
|
|
|
using (var reader = command.ExecuteReader()) |
|
|
|
{ |
|
|
|
while (reader.Read()) |
|
|
|
{ |
|
|
|
details.Add(new Tblcart |
|
|
|
{ |
|
|
|
Transno = a_receiptId, |
|
|
|
Id = reader.GetString(0), |
|
|
|
Quantity = reader.GetInt32(1), |
|
|
|
Date = reader.GetDateTime(2), |
|
|
|
Price = reader.GetDecimal(3), |
|
|
|
Cashier = reader.GetString(4), |
|
|
|
Status = reader.GetString(5), |
|
|
|
Total = (decimal)reader.GetDouble(6), |
|
|
|
Unit = reader.GetString(7), |
|
|
|
Costprice = reader.GetDecimal(8), |
|
|
|
BranchId = reader.GetString(9), |
|
|
|
CountId = reader.GetString(10), |
|
|
|
Tendered = reader.GetDecimal(11), |
|
|
|
Balance = reader.GetDecimal(12), |
|
|
|
ValueAddTax = reader.GetDecimal(13) |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return Task.FromResult(details.AsEnumerable()); |
|
|
|
} |
|
|
|
|
|
|
|
public async Task SyncCart(List<Tblcart> a_item) |
|
|
|
{ |
|
|
|
string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; |
|
|
|
if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) |
|
|
|
string apiKey = m_httpContext.Request.Headers["BISK-API-KEY"]!; |
|
|
|
if (AuthEnums.Valid == m_tokenService.ValidateKey(apiKey)) |
|
|
|
{ |
|
|
|
string jsonString = JsonSerializer.Serialize(a_item); |
|
|
|
using (var command = m_context.Database.GetDbConnection().CreateCommand()) |
|
|
@ -191,10 +51,10 @@ namespace Cloud_Manager.Services |
|
|
|
|
|
|
|
public DateTime GetLastSyncDate(string a_tablename) |
|
|
|
{ |
|
|
|
string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; |
|
|
|
if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) |
|
|
|
string apiKey = m_httpContext.Request.Headers["BISK-API-KEY"]!; |
|
|
|
if (AuthEnums.Valid == m_tokenService.ValidateKey(apiKey)) |
|
|
|
{ |
|
|
|
string activeBranch = m_tokenService.GetBaseBranch(token)!; |
|
|
|
string activeBranch = m_tokenService.GetBaseBranch(apiKey)!; |
|
|
|
DateTime? lastSync = m_context.Tblsyncinfos.FirstOrDefault(p => p.TableName == a_tablename && p.BranchId == activeBranch!)?.LastSyncDate; |
|
|
|
|
|
|
|
if (lastSync != null) |
|
|
@ -207,10 +67,10 @@ namespace Cloud_Manager.Services |
|
|
|
|
|
|
|
public void SetLastSyncDate(string a_tableName, DateTime a_timestamp) |
|
|
|
{ |
|
|
|
string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; |
|
|
|
if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) |
|
|
|
string apiKey = m_httpContext.Request.Headers["BISK-API-KEY"]!; |
|
|
|
if (AuthEnums.Valid == m_tokenService.ValidateKey(apiKey)) |
|
|
|
{ |
|
|
|
string activeBranch = m_tokenService.GetBaseBranch(token)!; |
|
|
|
string activeBranch = m_tokenService.GetBaseBranch(apiKey)!; |
|
|
|
using (var command = m_context.Database.GetDbConnection().CreateCommand()) |
|
|
|
{ |
|
|
|
m_context.Database.OpenConnection(); |
|
|
@ -227,8 +87,8 @@ namespace Cloud_Manager.Services |
|
|
|
|
|
|
|
public async Task SyncCancelledTransaction(List<Tblcancelledtransaction> a_item) |
|
|
|
{ |
|
|
|
string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; |
|
|
|
if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) |
|
|
|
string apiKey = m_httpContext.Request.Headers["BISK-API-KEY"]!; |
|
|
|
if (AuthEnums.Valid == m_tokenService.ValidateKey(apiKey)) |
|
|
|
{ |
|
|
|
string jsonString = JsonSerializer.Serialize(a_item); |
|
|
|
using (var command = m_context.Database.GetDbConnection().CreateCommand()) |
|
|
@ -244,8 +104,8 @@ namespace Cloud_Manager.Services |
|
|
|
|
|
|
|
public async Task SyncCreditPurchase(List<Creditpurchase> a_item) |
|
|
|
{ |
|
|
|
string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; |
|
|
|
if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) |
|
|
|
string apiKey = m_httpContext.Request.Headers["BISK-API-KEY"]!; |
|
|
|
if (AuthEnums.Valid == m_tokenService.ValidateKey(apiKey)) |
|
|
|
{ |
|
|
|
string jsonString = JsonSerializer.Serialize(a_item); |
|
|
|
using (var command = m_context.Database.GetDbConnection().CreateCommand()) |
|
|
@ -261,8 +121,8 @@ namespace Cloud_Manager.Services |
|
|
|
|
|
|
|
public async Task SyncCustomerAccount(List<Customeraccount> a_customerAccounts) |
|
|
|
{ |
|
|
|
string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; |
|
|
|
if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) |
|
|
|
string apiKey = m_httpContext.Request.Headers["BISK-API-KEY"]!; |
|
|
|
if (AuthEnums.Valid == m_tokenService.ValidateKey(apiKey)) |
|
|
|
{ |
|
|
|
string jsonString = JsonSerializer.Serialize(a_customerAccounts); |
|
|
|
using (var command = m_context.Database.GetDbConnection().CreateCommand()) |
|
|
@ -278,8 +138,8 @@ namespace Cloud_Manager.Services |
|
|
|
|
|
|
|
public async Task SyncCustomerPurchase(List<Tblcustomerpurchase> a_customerPurchase) |
|
|
|
{ |
|
|
|
string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; |
|
|
|
if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) |
|
|
|
string apiKey = m_httpContext.Request.Headers["BISK-API-KEY"]!; |
|
|
|
if (AuthEnums.Valid == m_tokenService.ValidateKey(apiKey)) |
|
|
|
{ |
|
|
|
string jsonString = JsonSerializer.Serialize(a_customerPurchase); |
|
|
|
using (var command = m_context.Database.GetDbConnection().CreateCommand()) |
|
|
@ -295,8 +155,8 @@ namespace Cloud_Manager.Services |
|
|
|
|
|
|
|
public async Task SyncDiscountLogs(List<Tbldiscountlog> a_discountLog) |
|
|
|
{ |
|
|
|
string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; |
|
|
|
if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) |
|
|
|
string apiKey = m_httpContext.Request.Headers["BISK-API-KEY"]!; |
|
|
|
if (AuthEnums.Valid == m_tokenService.ValidateKey(apiKey)) |
|
|
|
{ |
|
|
|
string jsonString = JsonSerializer.Serialize(a_discountLog); |
|
|
|
using (var command = m_context.Database.GetDbConnection().CreateCommand()) |
|
|
@ -312,8 +172,8 @@ namespace Cloud_Manager.Services |
|
|
|
|
|
|
|
public async Task SyncDeliveryDetails(List<Tbldeliverydetail> a_details) |
|
|
|
{ |
|
|
|
string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; |
|
|
|
if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) |
|
|
|
string apiKey = m_httpContext.Request.Headers["BISK-API-KEY"]!; |
|
|
|
if (AuthEnums.Valid == m_tokenService.ValidateKey(apiKey)) |
|
|
|
{ |
|
|
|
string jsonString = JsonSerializer.Serialize(a_details); |
|
|
|
using (var command = m_context.Database.GetDbConnection().CreateCommand()) |
|
|
@ -329,8 +189,8 @@ namespace Cloud_Manager.Services |
|
|
|
|
|
|
|
public async Task SyncDeliveryHead(List<Tbldeliveryhead> a_heads) |
|
|
|
{ |
|
|
|
string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; |
|
|
|
if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) |
|
|
|
string apiKey = m_httpContext.Request.Headers["BISK-API-KEY"]!; |
|
|
|
if (AuthEnums.Valid == m_tokenService.ValidateKey(apiKey)) |
|
|
|
{ |
|
|
|
string jsonString = JsonSerializer.Serialize(a_heads); |
|
|
|
using (var command = m_context.Database.GetDbConnection().CreateCommand()) |
|
|
@ -346,8 +206,8 @@ namespace Cloud_Manager.Services |
|
|
|
|
|
|
|
public async Task SyncDeliveryRecipients(List<Tbldeliveryrecipient> a_recipients) |
|
|
|
{ |
|
|
|
string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; |
|
|
|
if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) |
|
|
|
string apiKey = m_httpContext.Request.Headers["BISK-API-KEY"]!; |
|
|
|
if (AuthEnums.Valid == m_tokenService.ValidateKey(apiKey)) |
|
|
|
{ |
|
|
|
string jsonString = JsonSerializer.Serialize(a_recipients); |
|
|
|
using (var command = m_context.Database.GetDbConnection().CreateCommand()) |
|
|
@ -363,8 +223,8 @@ namespace Cloud_Manager.Services |
|
|
|
|
|
|
|
public async Task SyncInvoice(List<Tblinvoice> a_invoice) |
|
|
|
{ |
|
|
|
string token = m_httpContext.Request.Headers[HeaderNames.Authorization]!; |
|
|
|
if (AuthEnums.Valid == m_tokenService.ValidateToken(token)) |
|
|
|
string apiKey = m_httpContext.Request.Headers["BISK-API-KEY"]!; |
|
|
|
if (AuthEnums.Valid == m_tokenService.ValidateKey(apiKey)) |
|
|
|
{ |
|
|
|
string jsonString = JsonSerializer.Serialize(a_invoice); |
|
|
|
using (var command = m_context.Database.GetDbConnection().CreateCommand()) |
|
|
@ -377,5 +237,42 @@ namespace Cloud_Manager.Services |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#region NotImplemented
|
|
|
|
public Task FetchRecentTransaction(int a_limit) |
|
|
|
{ |
|
|
|
throw new NotImplementedException(); |
|
|
|
} |
|
|
|
|
|
|
|
public Task FetchTransaction(DateTime a_start, DateTime a_end) |
|
|
|
{ |
|
|
|
throw new NotImplementedException(); |
|
|
|
} |
|
|
|
|
|
|
|
public IEnumerable<SaleItem> GetTransactions(DateTime a_start, DateTime a_end) |
|
|
|
{ |
|
|
|
throw new NotImplementedException(); |
|
|
|
} |
|
|
|
|
|
|
|
public IEnumerable<SaleItem> GetRecentTransaction() |
|
|
|
{ |
|
|
|
throw new NotImplementedException(); |
|
|
|
} |
|
|
|
|
|
|
|
public Task FetchReceipt(string a_receiptId) |
|
|
|
{ |
|
|
|
throw new NotImplementedException(); |
|
|
|
} |
|
|
|
|
|
|
|
public IEnumerable<SaleItem> GetReceipt(string a_receiptId) |
|
|
|
{ |
|
|
|
throw new NotImplementedException(); |
|
|
|
} |
|
|
|
|
|
|
|
public Task<IEnumerable<Tblcart>> GetReceiptDetail(string a_receiptId) |
|
|
|
{ |
|
|
|
throw new NotImplementedException(); |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
} |
|
|
|
} |
|
|
|