Files
oficial/app/src/Service/Venta/BonoPie.php

46 lines
1.4 KiB
PHP
Raw Normal View History

2023-09-13 18:51:46 -03:00
<?php
namespace Incoviba\Service\Venta;
2024-11-18 23:25:20 -03:00
use Incoviba\Common\Implement\Exception\EmptyResult;
2025-03-03 14:57:22 -03:00
use Incoviba\Exception\ServiceAction\Read;
2023-09-13 18:51:46 -03:00
use Incoviba\Repository;
use Incoviba\Model;
2024-11-18 23:25:20 -03:00
use Psr\Log\LoggerInterface;
2023-09-13 18:51:46 -03:00
class BonoPie
{
2024-11-18 23:25:20 -03:00
public function __construct(protected Repository\Venta\BonoPie $bonoPieRepository,
protected LoggerInterface $logger,
protected Pago $pagoService) {}
2023-09-13 18:51:46 -03:00
public function add(array $data): Model\Venta\BonoPie
{
$filteredData = $this->bonoPieRepository->filterData($data);
2024-11-18 23:25:20 -03:00
if (!key_exists('pago', $filteredData)) {
$pago = $this->pagoService->add($filteredData);
$filteredData['pago'] = $pago->id;
}
try {
$bono = $this->bonoPieRepository->fetchByPago($filteredData['pago']);
} catch (EmptyResult) {
$bono = $this->bonoPieRepository->create($filteredData);
$bono = $this->bonoPieRepository->save($bono);
}
return $bono;
2023-09-13 18:51:46 -03:00
}
2025-03-03 14:57:22 -03:00
/**
* @param int $venta_id
* @return Model\Venta\BonoPie
* @throws Read
*/
2024-03-13 14:38:44 -03:00
public function getByVenta(int $venta_id): Model\Venta\BonoPie
{
2025-03-03 14:57:22 -03:00
try {
return $this->bonoPieRepository->fetchByVenta($venta_id);
} catch (EmptyResult $exception) {
throw new Read(__CLASS__, $exception);
}
2024-03-13 14:38:44 -03:00
}
2023-09-13 18:51:46 -03:00
}