using Marco.Pms.Model.Dtos.PurchaseInvoice;
using Marco.Pms.Services.Service.ServiceInterfaces;
using MarcoBMS.Services.Helpers;
using Microsoft.AspNetCore.Mvc;
namespace Marco.Pms.Services.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class PurchaseInvoiceController : ControllerBase
{
private readonly UserHelper _userHelper;
private readonly IPurchaseInvoiceService _purchaseInvoiceService;
private readonly Guid tenantId;
public PurchaseInvoiceController(UserHelper userHelper, IPurchaseInvoiceService purchaseInvoiceService)
{
_userHelper = userHelper;
_purchaseInvoiceService = purchaseInvoiceService;
tenantId = _userHelper.GetTenantId();
}
///
/// Creates a purchase invoice.
///
/// The purchase invoice model.
/// The cancellation token.
/// The HTTP response with the purchase invoice status and data.
[HttpPost("create")]
public async Task CreatePurchaseInvoice([FromBody] PurchaseInvoiceDto model, CancellationToken ct)
{
// Get the currently logged-in employee
var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
// Create a purchase invoice using the purchase invoice service
var response = await _purchaseInvoiceService.CreatePurchaseInvoiceAsync(model, loggedInEmployee, tenantId, ct);
// Return the HTTP response with the purchase invoice status and data
return StatusCode(response.StatusCode, response);
}
}
}