74 lines
2.5 KiB
PHP
74 lines
2.5 KiB
PHP
![]() |
<?php
|
||
|
namespace Incoviba\Repository\Venta;
|
||
|
|
||
|
use DateTimeImmutable;
|
||
|
use Incoviba\Common\Define;
|
||
|
use Incoviba\Common\Ideal;
|
||
|
use Incoviba\Model;
|
||
|
use Incoviba\Repository;
|
||
|
|
||
|
class Pago extends Ideal\Repository
|
||
|
{
|
||
|
public function __construct(Define\Connection $connection, protected Repository\Banco $bancoRepository, protected TipoPago $tipoPagoRepository)
|
||
|
{
|
||
|
parent::__construct($connection);
|
||
|
$this->setTable('pago');
|
||
|
}
|
||
|
|
||
|
public function create(?array $data = null): Define\Model
|
||
|
{
|
||
|
$map = [
|
||
|
'valor' => [],
|
||
|
'banco' => [
|
||
|
'function' => function($data) {
|
||
|
if ($data['banco'] === null or $data['banco'] === 0) {
|
||
|
return null;
|
||
|
}
|
||
|
return $this->bancoRepository->fetchById($data['banco']);
|
||
|
}
|
||
|
],
|
||
|
'tipo' => [
|
||
|
'property' => 'tipoPago',
|
||
|
'function' => function($data) {
|
||
|
if ($data['tipo'] === null) {
|
||
|
return null;
|
||
|
}
|
||
|
return $this->tipoPagoRepository->fetchById($data['tipo']);
|
||
|
}
|
||
|
],
|
||
|
'identificador' => [],
|
||
|
'fecha' => [
|
||
|
'function' => function($data) {
|
||
|
if ($data['fecha'] === null) {
|
||
|
return null;
|
||
|
}
|
||
|
return new DateTimeImmutable($data['fecha']);
|
||
|
}
|
||
|
],
|
||
|
'uf' => [],
|
||
|
'pagador' => [],
|
||
|
'asociado' => [
|
||
|
'function' => function($data) {
|
||
|
if ($data['asociado'] === null) {
|
||
|
return null;
|
||
|
}
|
||
|
return $this->fetchById($data['asociado']);
|
||
|
}
|
||
|
]
|
||
|
];
|
||
|
return $this->parseData(new Model\Venta\Pago(), $data, $map);
|
||
|
}
|
||
|
public function save(Define\Model $model): Define\Model
|
||
|
{
|
||
|
$model->id = $this->saveNew(
|
||
|
['valor', 'banco', 'tipo', 'identificador', 'fecha', 'uf', 'pagador', 'asociado'],
|
||
|
[$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]
|
||
|
);
|
||
|
return $model;
|
||
|
}
|
||
|
public function edit(Define\Model $model, array $new_data): Define\Model
|
||
|
{
|
||
|
return $this->update($model, ['valor', 'banco', 'tipo', 'identificador', 'fecha', 'uf', 'pagador', 'asociado'], $new_data);
|
||
|
}
|
||
|
}
|