Ventas
This commit is contained in:
@ -22,7 +22,7 @@ class Inmobiliaria extends Ideal\Repository
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = (new Implement\Repository\MapperParser(['db', 'razon', 'abreviacion', 'cuenta']))
|
||||
$map = (new Implement\Repository\MapperParser(['dv', 'razon', 'abreviacion', 'cuenta']))
|
||||
->register('banco', (new Implement\Repository\Mapper())
|
||||
->setFunction(function($data) {
|
||||
return $this->bancoRepository->fetchById($data['banco']);
|
||||
|
62
app/src/Repository/Menu.php
Normal file
62
app/src/Repository/Menu.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Menu extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('menus');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = (new Implement\Repository\MapperParser(['title']))
|
||||
->register('url', (new Implement\Repository\Mapper())
|
||||
->setDefault(''));
|
||||
$model = $this->parseData(new Model\Menu(), $data, $map);
|
||||
$model->children = $this->fetchChildren($model->id);
|
||||
return $model;
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['title', 'url'],
|
||||
[$model->title, $model->url]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['title', 'url'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByUser(int $user_id): array
|
||||
{
|
||||
$query = "SELECT a.*
|
||||
FROM `{$this->getTable()}` a
|
||||
JOIN `menu_permissions` mp ON mp.`menu_id` = a.`id`
|
||||
JOIN `permissions` ON `permissions`.`id` = mp.`permission_id`
|
||||
LEFT JOIN `users` u1 ON u1.`id` = `permissions`.`'ext_id` AND `permissions`.`type` = 2
|
||||
LEFT JOIN (SELECT u2.* FROM `roles` ON `roles`.`id` = `permissions`.`ext_id` AND `permissions`.`type` = 1
|
||||
JOIN `user_roles` ur ON ur.`role` = `role`.`id`
|
||||
JOIN `users` u2 ON u2.`id` = ur.`user`) us
|
||||
LEFT JOIN `menu_relations` mr ON mr.`child_id` = a.`id`
|
||||
WHERE u1.`id` = ? OR us.`id` = ? AND mr.`id` IS NULL";
|
||||
return $this->fetchMany($query, [$user_id, $user_id]);
|
||||
}
|
||||
public function fetchChildren(int $menu_id): array
|
||||
{
|
||||
$query = "SELECT sm.* FROM `menu_relations` mr WHERE mr.`parent_id` = ?";
|
||||
try {
|
||||
return $this->fetchMany($query, [$menu_id]);
|
||||
} catch (Implement\Exception\EmptyResult) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
15
app/src/Repository/Permission.php
Normal file
15
app/src/Repository/Permission.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Permission extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('permissions');
|
||||
}
|
||||
}
|
@ -23,8 +23,8 @@ class Proyecto extends Ideal\Repository
|
||||
->setArgs([$data['inmobiliaria']])))
|
||||
->register('direccion', (new Implement\Repository\Mapper())
|
||||
->setFactory((new Implement\Repository\Factory())
|
||||
->setCallable([$this->inmobiliariaRepository, 'fetchById'])
|
||||
->setArgs([$data['inmobiliaria']])))
|
||||
->setCallable([$this->direccionRepository, 'fetchById'])
|
||||
->setArgs([$data['direccion']])))
|
||||
->register('superficie_terreno', (new Implement\Repository\Mapper())
|
||||
->setProperty('terreno')
|
||||
->setFunction(function($data) {
|
||||
|
@ -106,6 +106,30 @@ FROM `{$this->getTable()}` a
|
||||
JOIN `banco` ON `banco`.`id` = `pago`.`banco`
|
||||
WHERE tep.`descripcion` = 'no pagado' AND `pago`.`fecha` < CURDATE()
|
||||
AND tev.`descripcion` IN ('vigente', 'escriturando', 'firmado por inmobiliaria')
|
||||
ORDER BY `pago`.`fecha` DESC";
|
||||
return $this->fetchAsArray($query);
|
||||
}
|
||||
public function fetchDepositadas(): array
|
||||
{
|
||||
$query = "SELECT a.`id` AS 'cuota_id', `venta`.`id` AS 'venta_id', `proyecto`.`descripcion` AS 'Proyecto', `unidad`.`descripcion` AS 'Departamento',
|
||||
`pago`.`valor` AS 'Valor', `pago`.`fecha`, CONCAT_WS(' - ', a.`numero`, `pie`.`cuotas`) AS 'Numero', `banco`.`nombre` AS 'Banco', ep.`fecha` AS 'Fecha Depositada',
|
||||
CONCAT_WS(' ', `propietario`.`nombres`, `propietario`.`apellido_paterno`, `propietario`.`apellido_materno`) AS 'Propietario'
|
||||
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`
|
||||
JOIN `pie` ON `pie`.`id` = a.`pie`
|
||||
JOIN `venta` ON `venta`.`pie` = a.`pie`
|
||||
JOIN (SELECT ev1.* FROM `estado_venta` ev1 JOIN (SELECT MAX(`id`) AS 'id', `venta` FROM `estado_venta` GROUP BY `venta`) ev0 ON ev0.`id` = ev1.`id`) ev ON ev.`venta` = `venta`.`id`
|
||||
JOIN `tipo_estado_venta` tev ON tev.`id` = ev.`estado`
|
||||
JOIN `propietario` ON `propietario`.`rut` = `venta`.`propietario`
|
||||
JOIN `propiedad_unidad` pu ON pu.`propiedad` = `venta`.`propiedad`
|
||||
JOIN `unidad` ON `unidad`.`id` = pu.`unidad` AND pu.`principal` = 1
|
||||
JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = `unidad`.`pt`
|
||||
JOIN `proyecto` ON `proyecto`.`id` = ptu.`proyecto`
|
||||
JOIN `banco` ON `banco`.`id` = `pago`.`banco`
|
||||
WHERE tep.`descripcion` = 'depositado' AND `pago`.`fecha` < CURDATE()
|
||||
AND tev.`descripcion` IN ('vigente', 'escriturando', 'firmado por inmobiliaria')
|
||||
ORDER BY `pago`.`fecha` DESC";
|
||||
return $this->fetchAsArray($query);
|
||||
}
|
||||
|
Reference in New Issue
Block a user