2023-07-28 16:22:20 -04:00
|
|
|
<?php
|
|
|
|
namespace Incoviba\Repository\Venta;
|
|
|
|
|
|
|
|
use Incoviba\Common\Ideal;
|
|
|
|
use Incoviba\Common\Define;
|
2023-08-08 23:53:49 -04:00
|
|
|
use Incoviba\Common\Implement;
|
2023-07-28 16:22:20 -04:00
|
|
|
use Incoviba\Model;
|
|
|
|
|
|
|
|
class BonoPie extends Ideal\Repository
|
|
|
|
{
|
|
|
|
public function __construct(Define\Connection $connection, protected Pago $pagoRepository)
|
|
|
|
{
|
|
|
|
parent::__construct($connection);
|
|
|
|
$this->setTable('bono_pie');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function create(?array $data = null): Define\Model
|
|
|
|
{
|
2023-08-08 23:53:49 -04:00
|
|
|
$map = (new Implement\Repository\MapperParser())
|
|
|
|
->register('pago', (new Implement\Repository\Mapper())
|
|
|
|
->setFunction(function($data) {
|
2023-07-28 16:22:20 -04:00
|
|
|
return $this->pagoRepository->fetchById($data['pago']);
|
2023-08-08 23:53:49 -04:00
|
|
|
}));
|
2023-07-28 16:22:20 -04:00
|
|
|
return $this->parseData(new Model\Venta\BonoPie(), $data, $map);
|
|
|
|
}
|
|
|
|
public function save(Define\Model $model): Define\Model
|
|
|
|
{
|
|
|
|
$model->id = $this->saveNew(
|
|
|
|
['valor', 'pago'],
|
|
|
|
[$model->pago->valor, $model->pago->id]
|
|
|
|
);
|
|
|
|
return $model;
|
|
|
|
}
|
|
|
|
public function edit(Define\Model $model, array $new_data): Define\Model
|
|
|
|
{
|
|
|
|
return $this->update($model, ['valor', 'pago'], $new_data);
|
|
|
|
}
|
|
|
|
}
|