Mejoras en Facturacion

This commit is contained in:
2023-11-30 18:40:15 -03:00
parent f2efb41977
commit 04478afa2f
14 changed files with 310 additions and 24 deletions

View File

@ -2,6 +2,7 @@
namespace Incoviba\Repository\Venta;
use PDO;
use PDOException;
use Incoviba\Common\Ideal;
use Incoviba\Common\Define;
use Incoviba\Common\Implement;
@ -38,6 +39,40 @@ class Unidad extends Ideal\Repository
{
return $this->update($model, ['subtipo', 'piso', 'descripcion', 'orientacion', 'pt'], $new_data);
}
public function editProrrateo(Model\Venta\Unidad $model, array $new_data): Model\Venta\Unidad
{
try {
$query = $this->connection->getQueryBuilder()
->select('prorrateo')
->from('unidad_prorrateo')
->where('unidad_id = ?');
$result = $this->connection->execute($query, [$model->id])->fetch(PDO::FETCH_ASSOC);
if ($result === false) {
throw new Implement\Exception\EmptyResult($query);
}
if ($new_data['prorrateo'] !== $result['prorrateo']) {
$query = $this->connection->getQueryBuilder()
->update('unidad_prorrateo')
->set('prorrateo = ?')
->where('unidad_id = ?');
$this->connection->execute($query, [$new_data['prorrateo'], $model->id]);
$model->prorrateo = $new_data['prorrateo'];
}
} catch (PDOException | Implement\Exception\EmptyResult) {
$query = $this->connection->getQueryBuilder()
->insert()
->into('unidad_prorrateo')
->columns(['unidad_id', 'prorrateo'])
->values(['?', '?']);
try {
$this->connection->execute($query, [$model->id, $new_data['prorrateo']]);
$model->prorrateo = $new_data['prorrateo'];
} catch (PDOException) {
throw new Implement\Exception\EmptyResult($query);
}
}
return $model;
}
public function fetchById(int $id): Model\Venta\Unidad
{