Auth, Login, Home, Venta->Listados->Precios
This commit is contained in:
67
app/src/Repository/Venta/EstadoPago.php
Normal file
67
app/src/Repository/Venta/EstadoPago.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class EstadoPago extends Ideal\Repository
|
||||
{
|
||||
public function __construct(protected Define\Connection $connection,
|
||||
protected Repository\Venta\Pago $pagoRepository,
|
||||
protected Repository\Venta\TipoEstadoPago $tipoEstadoPagoRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('estado_pago');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'pago' => [
|
||||
'function' => function($data) {
|
||||
return $this->pagoRepository->fetchById($data['pago']);
|
||||
}
|
||||
],
|
||||
'estado' => [
|
||||
'property' => 'tipoEstadoPago',
|
||||
'function' => function($data) {
|
||||
return $this->tipoEstadoPagoRepository->fetchById($data['estado']);
|
||||
}
|
||||
],
|
||||
'fecha' => [
|
||||
'function' => function($data) {
|
||||
return new DateTimeImmutable($data['fecha']);
|
||||
}
|
||||
]
|
||||
];
|
||||
return $this->parseData(new Model\Venta\EstadoPago(), $data, $map);
|
||||
}
|
||||
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['pago', 'estado', 'fecha'],
|
||||
[$model->pago->id, $model->tipoEstadoPago->id, $model->fecha->format('Y-m-d')]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['pago', 'estado', 'fecha'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByPago(int $pago_id): array
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `pago` = ?";
|
||||
return $this->fetchMany($query, [$pago_id]);
|
||||
}
|
||||
public function fetchByPagoAndEstado(int $pago_id, int $estado_id): Define\Model
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `pago` = ? AND `estado` = ?";
|
||||
return $this->fetchOne($query, [$pago_id, $estado_id]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user