Cuota abono a escritura
This commit is contained in:
19
app/src/Model/Venta/Abono/Cuota.php
Normal file
19
app/src/Model/Venta/Abono/Cuota.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
namespace Incoviba\Model\Venta\Abono;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Cuota extends Ideal\Model
|
||||
{
|
||||
public Model\Venta $venta;
|
||||
public Model\Venta\Pago $pago;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return array_merge(parent::jsonSerialize(), [
|
||||
'venta_id' => $this->venta->id,
|
||||
'pago' => $this->pago
|
||||
]);
|
||||
}
|
||||
}
|
59
app/src/Repository/Venta/Abono/Cuota.php
Normal file
59
app/src/Repository/Venta/Abono/Cuota.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta\Abono;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Cuota extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Repository\Venta $ventaRepository,
|
||||
protected Repository\Venta\Pago $pagoRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Model\Venta\Abono\Cuota
|
||||
{
|
||||
$map = (new Implement\Repository\MapperParser())
|
||||
->register('venta_id', (new Implement\Repository\Mapper())
|
||||
->setProperty('venta')
|
||||
->setFunction(function($data) {
|
||||
return $this->ventaRepository->fetchById($data['venta_id']);
|
||||
})
|
||||
)
|
||||
->register('pago_id', (new Implement\Repository\Mapper())
|
||||
->setProperty('pago')
|
||||
->setFunction(function($data) {
|
||||
return $this->pagoRepository->fetchById($data['pago_id']);
|
||||
})
|
||||
);
|
||||
return $this->parseData(new Model\Venta\Abono\Cuota(), $data, $map);
|
||||
}
|
||||
|
||||
public function save(Define\Model $model): Model\Venta\Abono\Cuota
|
||||
{
|
||||
$model->id = $this->saveNew(['venta_id', 'pago_id'], [$model->venta->id, $model->pago->id]);
|
||||
return $model;
|
||||
}
|
||||
|
||||
public function edit(Define\Model $model, array $new_data): Model\Venta\Abono\Cuota
|
||||
{
|
||||
return $this->update($model, ['venta_id', 'pago_id'], $new_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws EmptyResult
|
||||
*/
|
||||
public function fetchByVenta(int $venta_id): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select()
|
||||
->from($this->getTable())
|
||||
->where('venta_id = ?');
|
||||
return $this->fetchMany($query, [$venta_id]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user