Implemented repository mapper, and venta show
This commit is contained in:
@ -1,13 +1,16 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Escritura extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Pago $pagoRepository)
|
||||
public function __construct(Define\Connection $connection, protected Service\Venta\Pago $pagoService)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('escritura');
|
||||
@ -15,20 +18,19 @@ class Escritura extends Ideal\Repository
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'pago' => [
|
||||
'function' => function($data) {
|
||||
return $this->pagoRepository->fetchById($data['pago']);
|
||||
}
|
||||
]
|
||||
];
|
||||
$map = (new Implement\Repository\MapperParser())
|
||||
->register('pago', (new Implement\Repository\Mapper())
|
||||
->setFunction(function($data) {
|
||||
return $this->pagoService->getById($data['pago']);
|
||||
}))
|
||||
->register('fecha', new Implement\Repository\Mapper\DateTime('fecha'));
|
||||
return $this->parseData(new Model\Venta\Escritura(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['valor', 'fecha', 'uf', 'abonado', 'fecha_abono', 'pago'],
|
||||
[$model->pago->valor, $model->pago->fecha->format('Y-m-d'), $model->pago->uf, null, null, $model->pago->id]
|
||||
[$model->pago->valor, $model->fecha->format('Y-m-d'), $model->pago->uf, null, null, $model->pago->id]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
|
Reference in New Issue
Block a user