Implemented repository mapper, and venta show
This commit is contained in:
@ -1,17 +1,23 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use PDO;
|
||||
use DateTimeImmutable;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Cuota extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Pie $pieRepository, protected Repository\Banco $bancoRepository, protected Pago $pagoRepository)
|
||||
public function __construct(
|
||||
Define\Connection $connection,
|
||||
protected Pie $pieRepository,
|
||||
protected Repository\Banco $bancoRepository,
|
||||
protected Service\Venta\Pago $pagoService
|
||||
)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('cuota');
|
||||
@ -19,68 +25,33 @@ class Cuota extends Ideal\Repository
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'pie' => [
|
||||
'function' => function($data) {
|
||||
$map = (new Implement\Repository\MapperParser(['valor', 'uf', 'numero']))
|
||||
->register('pie', (new Implement\Repository\Mapper())
|
||||
->setFunction(function($data) {
|
||||
return $this->pieRepository->fetchById($data['pie']);
|
||||
}
|
||||
],
|
||||
'fecha' => [
|
||||
'function' => function($data) {
|
||||
return new DateTimeImmutable($data['fecha']);
|
||||
}
|
||||
],
|
||||
'valor' => [],
|
||||
'estado' => [
|
||||
'function' => function($data) {
|
||||
return $data['estado'] !== 0;
|
||||
}
|
||||
],
|
||||
'banco' => [
|
||||
'function' => function($data) {
|
||||
}))
|
||||
->register('fecha', new Implement\Repository\Mapper\DateTime('fecha'))
|
||||
->register('estado', new Implement\Repository\Mapper\Boolean('estado'))
|
||||
->register('banco', (new Implement\Repository\Mapper())
|
||||
->setFunction(function($data) {
|
||||
if ($data['banco'] === null or $data['banco'] === '') {
|
||||
return null;
|
||||
}
|
||||
return $this->bancoRepository->fetchById($data['banco']);
|
||||
}
|
||||
],
|
||||
'fecha_pago' => [
|
||||
'property' => 'fechaPago',
|
||||
'function' => function($data) {
|
||||
if ($data['fecha_pago'] === null) {
|
||||
return null;
|
||||
}
|
||||
return new DateTimeImmutable($data['fecha_pago']);
|
||||
}
|
||||
],
|
||||
'abonado' => [
|
||||
'function' => function($data) {
|
||||
if ($data['abonado'] === null) {
|
||||
return null;
|
||||
}
|
||||
return $data['abonado'] !== 0;
|
||||
}
|
||||
],
|
||||
'fecha_abonado' => [
|
||||
'property' => 'fechaAbonado',
|
||||
'function' => function($data) {
|
||||
if ($data['fecha_abonado'] === null) {
|
||||
return null;
|
||||
}
|
||||
return new DateTimeImmutable($data['fecha_abonado']);
|
||||
}
|
||||
],
|
||||
'uf' => [],
|
||||
'pago' => [
|
||||
'function' => function($data) {
|
||||
}))
|
||||
->register('fecha_pago', (new Implement\Repository\Mapper\DateTime('fecha_pago', 'fechaPago'))
|
||||
->setDefault(null))
|
||||
->register('abonado', (new Implement\Repository\Mapper\Boolean('abonado'))
|
||||
->setDefault(null))
|
||||
->register('fecha_abonado', (new Implement\Repository\Mapper\DateTime('fecha_abonado', 'fechaAbonado'))
|
||||
->setDefault(null))
|
||||
->register('pago', (new Implement\Repository\Mapper())
|
||||
->setFunction(function($data) {
|
||||
if ($data['pago'] === null) {
|
||||
return null;
|
||||
}
|
||||
return $this->pagoRepository->fetchById($data['pago']);
|
||||
}
|
||||
],
|
||||
'numero' => []
|
||||
];
|
||||
return $this->pagoService->getById($data['pago']);
|
||||
}));
|
||||
return $this->parseData(new Model\Venta\Cuota(), $data, $map);
|
||||
}
|
||||
|
||||
@ -158,4 +129,14 @@ GROUP BY `pago`.`fecha`, `proyecto`.`descripcion`
|
||||
ORDER BY `pago`.`fecha`, `proyecto`.`descripcion`";
|
||||
return $this->fetchAsArray($query);
|
||||
}
|
||||
public function fetchVigenteByPie(int $pie_id): array
|
||||
{
|
||||
$query = "SELECT a.*
|
||||
FROM `{$this->getTable()}` a
|
||||
JOIN `pago` ON `pago`.`id` = a.`pago`
|
||||
JOIN (SELECT e1.* FROM `estado_pago` e1 JOIN (SELECT MAX(`id`) AS 'id', `pago` FROM `estado_pago` GROUP BY `pago`) e0 ON e0.`id` = e1.`id`) ep ON ep.`pago` = `pago`.`id`
|
||||
JOIN `tipo_estado_pago` tep ON tep.`id` = ep.`estado`
|
||||
WHERE a.`pie` = ? AND tep.`active` = 1";
|
||||
return $this->fetchMany($query, [$pie_id]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user