Agregar Bono Pie
This commit is contained in:
@ -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
|
||||
{
|
||||
|
Reference in New Issue
Block a user