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.
96 lines
4.2 KiB
96 lines
4.2 KiB
using Biskilog_Accounting.Server.POSModels;
|
|
using Biskilog_Accounting.Server.Services;
|
|
using Biskilog_Accounting.Shared.CustomModels;
|
|
using Biskilog_Accounting.Shared.Interfaces;
|
|
using Biskilog_Accounting.Shared.POSModels;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
|
using Microsoft.Net.Http.Headers;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Data.Entity;
|
|
|
|
namespace Biskilog_Accounting.Server.Controllers
|
|
{
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
public class AnalyticsController : ControllerBase
|
|
{
|
|
private readonly IConnectionService m_connection;
|
|
private readonly ITokenService m_tokenService;
|
|
public AnalyticsController(ITokenService tokenService, IConnectionService connection)
|
|
{
|
|
m_tokenService = tokenService;
|
|
m_connection = connection;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Endpoint to return analysis on CancelledSales within a specified period
|
|
/// </summary>
|
|
/// <param name="a_start"></param>
|
|
/// <param name="a_end"></param>
|
|
[Authorize]
|
|
[HttpGet, Route("cancelledsales/{a_start}/{a_end}")]
|
|
public IEnumerable<CancelledSales> GetCancelledSalesAsync(DateTime a_start, DateTime a_end)
|
|
{
|
|
string token = Request.Headers[HeaderNames.Authorization]!;
|
|
int? databaseId = m_tokenService.GetDatabaseIdFromToken(token);
|
|
string connectionString = m_connection.GetClientConnectionString(databaseId!.Value);
|
|
bool? comparisonMode = m_tokenService.GetComparison(token);
|
|
string? currentBranch = m_tokenService.GetBaseBranch(token);
|
|
|
|
//Creates a new db context
|
|
BiskAcdbContext newContext = (BiskAcdbContext)m_connection.PrepareDBContext(connectionString);
|
|
|
|
AnalyticalService analysis = new(newContext, comparisonMode!.Value, currentBranch!);
|
|
var result = analysis.GetCancelledSales(a_start, a_end);
|
|
|
|
return result;
|
|
}
|
|
/// <summary>
|
|
/// Endpoint to return analysis on Sales within a specified period
|
|
/// </summary>
|
|
/// <param name="a_start"></param>
|
|
/// <param name="a_end"></param>
|
|
[Authorize]
|
|
[HttpGet, Route("sales/{a_start}/{a_end}")]
|
|
public IEnumerable<Tblcart> GetSalesAsync(DateTime a_start, DateTime a_end)
|
|
{
|
|
string token = Request.Headers[HeaderNames.Authorization]!;
|
|
int? databaseId = m_tokenService.GetDatabaseIdFromToken(token);
|
|
string connectionString = m_connection.GetClientConnectionString(databaseId!.Value);
|
|
bool? comparisonMode = m_tokenService.GetComparison(token);
|
|
string? currentBranch = m_tokenService.GetBaseBranch(token);
|
|
|
|
//Creates a new db context
|
|
BiskAcdbContext newContext = (BiskAcdbContext)m_connection.PrepareDBContext(connectionString);
|
|
|
|
AnalyticalService analysis = new(newContext, comparisonMode!.Value, currentBranch!);
|
|
return analysis.GetSalesTransaction(a_start, a_end);
|
|
}
|
|
/// <summary>
|
|
/// Endpoint to return analysis on in-debt customers
|
|
/// </summary>
|
|
/// <param name="a_start"></param>
|
|
/// <param name="a_end"></param>
|
|
[Authorize]
|
|
[HttpGet, Route("debtors")]
|
|
public IEnumerable<InDebtCustomers> GetInDebtCustomers()
|
|
{
|
|
string token = Request.Headers[HeaderNames.Authorization]!;
|
|
int? databaseId = m_tokenService.GetDatabaseIdFromToken(token);
|
|
string connectionString = m_connection.GetClientConnectionString(databaseId!.Value);
|
|
bool? comparisonMode = m_tokenService.GetComparison(token);
|
|
string? currentBranch = m_tokenService.GetBaseBranch(token);
|
|
|
|
//Creates a new db context
|
|
BiskAcdbContext newContext = (BiskAcdbContext)m_connection.PrepareDBContext(connectionString);
|
|
|
|
AnalyticalService analysis = new(newContext, comparisonMode!.Value, currentBranch!);
|
|
return analysis.GetInDebtCustomers();
|
|
}
|
|
|
|
}
|
|
}
|
|
|