Agregar Bono Pie

This commit is contained in:
Juan Pablo Vial
2024-11-18 23:25:20 -03:00
parent 1e1994264e
commit cb2edb1543
9 changed files with 156 additions and 4 deletions

View File

@ -1,18 +1,31 @@
<?php
namespace Incoviba\Service\Venta;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Repository;
use Incoviba\Model;
use Psr\Log\LoggerInterface;
class BonoPie
{
public function __construct(protected Repository\Venta\BonoPie $bonoPieRepository) {}
public function __construct(protected Repository\Venta\BonoPie $bonoPieRepository,
protected LoggerInterface $logger,
protected Pago $pagoService) {}
public function add(array $data): Model\Venta\BonoPie
{
$filteredData = $this->bonoPieRepository->filterData($data);
$bono = $this->bonoPieRepository->create($filteredData);
return $this->bonoPieRepository->save($bono);
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;
}
public function getByVenta(int $venta_id): Model\Venta\BonoPie
{