Files
oficial/app/src/Repository/Venta/BonoPie.php

89 lines
2.6 KiB
PHP
Raw Normal View History

2023-07-28 16:22:20 -04:00
<?php
namespace Incoviba\Repository\Venta;
use Incoviba\Common\Ideal;
use Incoviba\Common\Define;
use Incoviba\Common\Implement;
2023-07-28 16:22:20 -04:00
use Incoviba\Model;
class BonoPie extends Ideal\Repository
{
public function __construct(Define\Connection $connection, protected Pago $pagoRepository)
{
parent::__construct($connection);
$this->setTable('bono_pie');
}
public function create(?array $data = null): Define\Model
{
2024-11-18 23:25:20 -03:00
$map = (new Implement\Repository\MapperParser(['valor']))
->register('pago', (new Implement\Repository\Mapper())
->setFunction(function($data) {
2023-07-28 16:22:20 -04:00
return $this->pagoRepository->fetchById($data['pago']);
}));
2023-07-28 16:22:20 -04:00
return $this->parseData(new Model\Venta\BonoPie(), $data, $map);
}
public function save(Define\Model $model): Define\Model
{
$model->id = $this->saveNew(
['valor', 'pago'],
[$model->pago->valor, $model->pago->id]
);
return $model;
}
2025-03-03 14:57:22 -03:00
/**
* @param Define\Model $model
* @param array $new_data
* @return Define\Model
* @throws Implement\Exception\EmptyResult
*/
2023-07-28 16:22:20 -04:00
public function edit(Define\Model $model, array $new_data): Define\Model
{
return $this->update($model, ['valor', 'pago'], $new_data);
}
2024-01-08 17:33:42 -03:00
2025-03-03 14:57:22 -03:00
/**
* @param float $value
* @return array
* @throws Implement\Exception\EmptyResult
*/
2024-01-08 17:33:42 -03:00
public function fetchByValue(float $value): array
{
$query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable())
->where('valor = ?');
return $this->fetchMany($query, [$value]);
}
2025-03-03 14:57:22 -03:00
/**
* @param int $pago_id
* @return Model\Venta\BonoPie
* @throws Implement\Exception\EmptyResult
*/
2024-01-08 17:33:42 -03:00
public function fetchByPago(int $pago_id): Model\Venta\BonoPie
{
$query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable())
->where('pago = ?');
return $this->fetchOne($query, [$pago_id]);
}
2025-03-03 14:57:22 -03:00
/**
* @param int $venta_id
* @return Model\Venta\BonoPie
* @throws Implement\Exception\EmptyResult
*/
2024-03-13 14:38:44 -03:00
public function fetchByVenta(int $venta_id): Model\Venta\BonoPie
{
$query = $this->connection->getQueryBuilder()
->select('a.*')
->from("{$this->getTable()} a")
->joined('JOIN venta ON venta.bono_pie = a.id')
->where('venta.id = ?');
return $this->fetchOne($query, [$venta_id]);
}
2023-07-28 16:22:20 -04:00
}