2023-07-24 20:55:26 -04:00
|
|
|
<?php
|
|
|
|
namespace Incoviba\Repository\Venta;
|
|
|
|
|
|
|
|
use Incoviba\Common\Define;
|
|
|
|
use Incoviba\Common\Ideal;
|
2023-08-08 23:53:49 -04:00
|
|
|
use Incoviba\Common\Implement;
|
2023-07-24 20:55:26 -04:00
|
|
|
use Incoviba\Model;
|
|
|
|
use Incoviba\Repository;
|
|
|
|
|
|
|
|
class Pago extends Ideal\Repository
|
|
|
|
{
|
2023-09-13 18:51:46 -03:00
|
|
|
public function __construct(
|
|
|
|
Define\Connection $connection,
|
|
|
|
protected Repository\Banco $bancoRepository,
|
|
|
|
protected TipoPago $tipoPagoRepository
|
|
|
|
)
|
2023-07-24 20:55:26 -04:00
|
|
|
{
|
|
|
|
parent::__construct($connection);
|
|
|
|
$this->setTable('pago');
|
|
|
|
}
|
|
|
|
|
2023-09-13 18:51:46 -03:00
|
|
|
public function create(?array $data = null): Model\Venta\Pago
|
2023-07-24 20:55:26 -04:00
|
|
|
{
|
2023-08-08 23:53:49 -04:00
|
|
|
$map = (new Implement\Repository\MapperParser(['valor', 'identificador', 'uf', 'pagador']))
|
|
|
|
->register('banco', (new Implement\Repository\Mapper())
|
|
|
|
->setFunction(function($data) {
|
2023-07-24 20:55:26 -04:00
|
|
|
if ($data['banco'] === null or $data['banco'] === 0) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return $this->bancoRepository->fetchById($data['banco']);
|
2023-08-08 23:53:49 -04:00
|
|
|
}))
|
|
|
|
->register('tipo', (new Implement\Repository\Mapper())
|
|
|
|
->setProperty('tipoPago')
|
|
|
|
->setFunction(function($data) {
|
2023-07-24 20:55:26 -04:00
|
|
|
if ($data['tipo'] === null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return $this->tipoPagoRepository->fetchById($data['tipo']);
|
2023-08-08 23:53:49 -04:00
|
|
|
}))
|
|
|
|
->register('fecha', (new Implement\Repository\Mapper\DateTime('fecha'))
|
|
|
|
->setDefault(null))
|
|
|
|
->register('asociado', (new Implement\Repository\Mapper())
|
|
|
|
->setFunction(function($data) {
|
2023-07-24 20:55:26 -04:00
|
|
|
if ($data['asociado'] === null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return $this->fetchById($data['asociado']);
|
2023-08-08 23:53:49 -04:00
|
|
|
}));
|
2023-07-24 20:55:26 -04:00
|
|
|
return $this->parseData(new Model\Venta\Pago(), $data, $map);
|
|
|
|
}
|
2023-09-13 18:51:46 -03:00
|
|
|
public function save(Define\Model $model): Model\Venta\Pago
|
2023-07-24 20:55:26 -04:00
|
|
|
{
|
|
|
|
$model->id = $this->saveNew(
|
|
|
|
['valor', 'banco', 'tipo', 'identificador', 'fecha', 'uf', 'pagador', 'asociado'],
|
2023-09-13 18:51:46 -03:00
|
|
|
[$model->valor, $model->banco?->id, $model->tipoPago?->id, $model->identificador, $model->fecha?->format('Y-m-d H:i:s'), $model->uf, $model->pagador, $model->asociado?->id]
|
2023-07-24 20:55:26 -04:00
|
|
|
);
|
|
|
|
return $model;
|
|
|
|
}
|
2023-09-13 18:51:46 -03:00
|
|
|
public function edit(Define\Model $model, array $new_data): Model\Venta\Pago
|
2023-07-24 20:55:26 -04:00
|
|
|
{
|
|
|
|
return $this->update($model, ['valor', 'banco', 'tipo', 'identificador', 'fecha', 'uf', 'pagador', 'asociado'], $new_data);
|
|
|
|
}
|
|
|
|
}
|