diff --git a/app/resources/database/migrations/20250312221404_alter_promotions_add_contract_id.php b/app/resources/database/migrations/20250312221404_alter_promotions_add_contract_id.php new file mode 100644 index 0000000..d0a5cdb --- /dev/null +++ b/app/resources/database/migrations/20250312221404_alter_promotions_add_contract_id.php @@ -0,0 +1,27 @@ +table('promotions') + ->addColumn('contract_id', 'integer', ['signed' => false, 'null' => false, 'default' => 0, 'after' => 'id']) + ->addForeignKey('contract_id', 'broker_contracts', 'id', ['delete' => 'cascade', 'update' => 'cascade']) + ->update(); + } +} diff --git a/app/resources/routes/api/proyectos.php b/app/resources/routes/api/proyectos.php index 0d00dc5..15d0445 100644 --- a/app/resources/routes/api/proyectos.php +++ b/app/resources/routes/api/proyectos.php @@ -21,6 +21,8 @@ $app->group('/proyecto/{proyecto_id}', function($app) { $app->get('/vendible[/]', [Proyectos::class, 'superficies']); }); $app->group('/unidades', function($app) { + $app->post('/precios[/]', [Proyectos\Unidades::class, 'precios']); + $app->post('/estados[/]', [Proyectos\Unidades::class, 'estados']); $app->get('/disponibles[/]', [Proyectos::class, 'disponibles']); $app->get('[/]', [Proyectos::class, 'unidades']); }); diff --git a/app/resources/routes/api/proyectos/brokers.php b/app/resources/routes/api/proyectos/brokers.php index b8cb395..9df5d0f 100644 --- a/app/resources/routes/api/proyectos/brokers.php +++ b/app/resources/routes/api/proyectos/brokers.php @@ -22,6 +22,9 @@ $app->group('/broker/{broker_rut}', function($app) { $app->post('/add[/]', [Contracts::class, 'add']); $app->get('[/]', [Contracts::class, 'getByBroker']); }); + $app->group('/contract/{contract_id}', function($app) { + $app->post('/promotions[/]', [Contracts::class, 'promotions']); + }); $app->delete('[/]', [Brokers::class, 'delete']); $app->get('[/]', [Brokers::class, 'get']); }); diff --git a/app/resources/routes/proyectos/brokers.php b/app/resources/routes/proyectos/brokers.php index 718259f..448135f 100644 --- a/app/resources/routes/proyectos/brokers.php +++ b/app/resources/routes/proyectos/brokers.php @@ -5,5 +5,8 @@ $app->group('/brokers', function($app) { $app->get('[/]', Brokers::class); }); $app->group('/broker/{broker_rut}', function($app) { + $app->group('/contract/{contract_id}', function($app) { + $app->get('[/]', [Brokers\Contracts::class, 'show']); + }); $app->get('[/]', [Brokers::class, 'show']); }); diff --git a/app/resources/views/proyectos/brokers/contracts/show.blade.php b/app/resources/views/proyectos/brokers/contracts/show.blade.php new file mode 100644 index 0000000..a61db80 --- /dev/null +++ b/app/resources/views/proyectos/brokers/contracts/show.blade.php @@ -0,0 +1,391 @@ +@extends('proyectos.brokers.base') + +@section('brokers_title') + {{ $contract->broker->name }} - {{ $contract->project->descripcion }} +@endsection + +@section('brokers_header') + {{ $contract->broker->name }} - {{ $contract->project->descripcion }} +@endsection + +@section('brokers_content') +
+ Comisión: {{ $format->percent($contract->commission, 2, true) }}
+ Fecha Inicio: {{ $contract->current()->date->format('d/m/Y') }}
+
+
+ + + + + + + + + + + + + + + + + + + +
TipoCantidadPrecioPromociónAcciones
MínimoPromedioMáximoMínimaPromedioMáxima
+ + + + + + + + + + + + + + + + + + + + + + +
TipoLíneaOrientaciónTipologíaCantidadPrecioPromociónAcciones
MínimoPromedioMáximoMínimaPromedioMáxima
+
+ + + + + + + + + + + + + + + + +
TipoTipo OrderUnidadUnidad OrdenEstadoPrecioPromociónFecha InicioFecha TérminoAcciones
+
+@endsection + +@include('layout.body.scripts.datatables') +@include('layout.body.scripts.datatables.searchbuilder') + +@push('page_scripts') + +@endpush diff --git a/app/resources/views/proyectos/brokers/show.blade.php b/app/resources/views/proyectos/brokers/show.blade.php index a300150..f7aec1e 100644 --- a/app/resources/views/proyectos/brokers/show.blade.php +++ b/app/resources/views/proyectos/brokers/show.blade.php @@ -44,7 +44,11 @@ @foreach($broker->contracts() as $contract) - {{ $contract->project->descripcion }} + + + {{ $contract->project->descripcion }} + + {{ $format->percent($contract->commission, 2, true) }} {{ $contract->current()->date->format('d-m-Y') }} diff --git a/app/src/Controller/API/Proyectos.php b/app/src/Controller/API/Proyectos.php index b7216cf..e6994ec 100644 --- a/app/src/Controller/API/Proyectos.php +++ b/app/src/Controller/API/Proyectos.php @@ -187,4 +187,5 @@ class Proyectos } return $this->withJson($response, $output); } + } diff --git a/app/src/Controller/API/Proyectos/Brokers/Contracts.php b/app/src/Controller/API/Proyectos/Brokers/Contracts.php index 5e4beb3..d413a0d 100644 --- a/app/src/Controller/API/Proyectos/Brokers/Contracts.php +++ b/app/src/Controller/API/Proyectos/Brokers/Contracts.php @@ -5,9 +5,11 @@ use DateTimeImmutable; use DateMalformedStringException; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; +use Incoviba\Common\Implement; use Incoviba\Controller\API\withJson; -use Incoviba\Service; use Incoviba\Exception\ServiceAction; +use Incoviba\Repository; +use Incoviba\Service; class Contracts { @@ -140,4 +142,34 @@ class Contracts return $this->withJson($response, $output); } + + public function promotions(ServerRequestInterface $request, ResponseInterface $response, + Service\Proyecto\Broker\Contract $contractService, + Repository\Venta\Unidad $unitRepository, + Repository\Venta\Promotion $promotionRepository, + int $contract_id): ResponseInterface + { + $input = $request->getParsedBody(); + $output = [ + 'contract_id' => $contract_id, + 'input' => $input, + 'unidades' => [], + ]; + $unit_ids = $input['unidad_ids']; + if (is_string($unit_ids)) { + $unit_ids = json_decode($input['unidad_ids'], true); + } + foreach ($unit_ids as $unit_id) { + try { + $unit = $unitRepository->fetchById($unit_id); + $contractService->getById($contract_id); + $promotion = $promotionRepository->fetchByContractAndUnit($contract_id, $unit->id); + $output['unidades'] []= [ + 'id' => $unit->id, + 'promotion' => $promotion + ]; + } catch (ServiceAction\Read | Implement\Exception\EmptyResult) {} + } + return $this->withJson($response, $output); + } } diff --git a/app/src/Controller/API/Proyectos/Unidades.php b/app/src/Controller/API/Proyectos/Unidades.php new file mode 100644 index 0000000..8df3c33 --- /dev/null +++ b/app/src/Controller/API/Proyectos/Unidades.php @@ -0,0 +1,85 @@ +getParsedBody(); + $output = [ + 'proyecto_id' => $proyecto_id, + 'input' => $input, + 'precios' => [] + ]; + $unidad_ids = $input['unidad_ids']; + if (is_string($unidad_ids)) { + $unidad_ids = json_decode($input['unidad_ids'], true); + } + try { + $proyecto = $proyectoService->getById($proyecto_id); + foreach ($unidad_ids as $unidad_id) { + try { + $output['precios'][] = [ + 'id' => $unidad_id, + 'precio' => $precioRepository->fetchVigenteByUnidad((int) $unidad_id) + ]; + } catch (Implement\Exception\EmptyResult) {} + } + } catch (Implement\Exception\EmptyResult) {} + return $this->withJson($response, $output); + } + public function estados(ServerRequestInterface $request, ResponseInterface $response, + Service\Proyecto $proyectoService, + Repository\Venta\Unidad $unidadRepository, + int $proyecto_id): ResponseInterface + { + $input = $request->getParsedBody(); + $output = [ + 'proyecto_id' => $proyecto_id, + 'input' => $input, + 'estados' => [] + ]; + $unidad_ids = $input['unidad_ids']; + if (is_string($unidad_ids)) { + $unidad_ids = json_decode($input['unidad_ids'], true); + } + try { + $proyecto = $proyectoService->getById($proyecto_id); + foreach ($unidad_ids as $unidad_id) { + try { + $unidad = $unidadRepository->fetchById($unidad_id); + } catch (Implement\Exception\EmptyResult) { + try { + $output['estados'][] = [ + 'id' => $unidad_id, + 'sold' => $unidadRepository->fetchSoldByUnidad((int) $unidad_id) + ]; + } catch (Implement\Exception\EmptyResult) { + $output['estados'][] = [ + 'id' => $unidad_id, + 'sold' => false + ]; + } + } + } + } catch (Implement\Exception\EmptyResult) {} + return $this->withJson($response, $output); + } +} diff --git a/app/src/Controller/Proyectos/Brokers/Contracts.php b/app/src/Controller/Proyectos/Brokers/Contracts.php new file mode 100644 index 0000000..64baac3 --- /dev/null +++ b/app/src/Controller/Proyectos/Brokers/Contracts.php @@ -0,0 +1,24 @@ +getById($contract_id); + } catch (Exception\ServiceAction\Read) {} + + return $view->render($response, 'proyectos.brokers.contracts.show', compact('contract')); + } +} diff --git a/app/src/Model/Proyecto/Broker/Contract.php b/app/src/Model/Proyecto/Broker/Contract.php index ef8876b..89f6014 100644 --- a/app/src/Model/Proyecto/Broker/Contract.php +++ b/app/src/Model/Proyecto/Broker/Contract.php @@ -32,6 +32,15 @@ class Contract extends Common\Ideal\Model return $this->current; } + protected array $promotions = []; + public function promotions(): array + { + if (count($this->promotions) === 0) { + $this->promotions = $this->runFactory('promotions'); + } + return $this->promotions; + } + protected function jsonComplement(): array { return [ diff --git a/app/src/Model/Venta/Promotion.php b/app/src/Model/Venta/Promotion.php index d7aa8e7..7aafa3f 100644 --- a/app/src/Model/Venta/Promotion.php +++ b/app/src/Model/Venta/Promotion.php @@ -3,9 +3,11 @@ namespace Incoviba\Model\Venta; use DateTimeInterface; use Incoviba\Common; +use Incoviba\Model\Proyecto\Broker; class Promotion extends Common\Ideal\Model { + public Broker\Contract $contract; public Precio $price; public float $amount; public DateTimeInterface $startDate; @@ -13,11 +15,18 @@ class Promotion extends Common\Ideal\Model public DateTimeInterface $validUntil; public int $state; + public function price(): float + { + return $this->price->valor * $this->amount; + } + protected function jsonComplement(): array { return [ + 'contract_rut' => $this->contract->id, 'price_id' => $this->price->id, 'amount' => $this->amount, + 'price' => $this->price(), 'start_date' => $this->startDate->format('Y-m-d'), 'end_date' => $this->endDate->format('Y-m-d'), 'valid_until' => $this->validUntil->format('Y-m-d'), @@ -27,4 +36,4 @@ class Promotion extends Common\Ideal\Model ] ]; } -} \ No newline at end of file +} diff --git a/app/src/Model/Venta/Unidad.php b/app/src/Model/Venta/Unidad.php index a52cd4b..c86af9c 100644 --- a/app/src/Model/Venta/Unidad.php +++ b/app/src/Model/Venta/Unidad.php @@ -45,6 +45,18 @@ class Unidad extends Ideal\Model return $precio; } + protected bool $sold; + public function sold(): bool + { + if (!isset($this->sold)) { + $this->sold = false; + try { + $this->sold = $this->runFactory('sold') ?? false; + } catch (EmptyResult) {} + } + return $this->sold; + } + public function jsonSerialize(): mixed { $output = array_merge(parent::jsonSerialize(), [ @@ -59,6 +71,7 @@ class Unidad extends Ideal\Model $output['precios'] = $this->precios; $output['current_precio'] = $this->currentPrecio; } + $output['sold'] = $this->sold() ?? false; return $output; } } diff --git a/app/src/Repository/Venta/Promotion.php b/app/src/Repository/Venta/Promotion.php index 1621add..76ce919 100644 --- a/app/src/Repository/Venta/Promotion.php +++ b/app/src/Repository/Venta/Promotion.php @@ -3,10 +3,11 @@ namespace Incoviba\Repository\Venta; use Incoviba\Common; use Incoviba\Model; +use Incoviba\Repository\Proyecto\Broker; class Promotion extends Common\Ideal\Repository { - public function __construct(Common\Define\Connection $connection, protected Precio $precioRepository) + public function __construct(Common\Define\Connection $connection, protected Broker\Contract $contractRepository, protected Precio $precioRepository) { parent::__construct($connection); } @@ -18,31 +19,70 @@ class Promotion extends Common\Ideal\Repository public function create(?array $data = null): Model\Venta\Promotion { - $map = (new Implement\Repository\MapperParser(['amount', 'type'])) - ->register('price_id', (new Implement\Repository\Mapper()) + $map = (new Common\Implement\Repository\MapperParser(['amount', 'type'])) + ->register('contract_id', (new Common\Implement\Repository\Mapper()) + ->setProperty('contract') + ->setFunction(function($data) { + return $this->contractRepository->fetchById($data['contract_id']); + })) + ->register('price_id', (new Common\Implement\Repository\Mapper()) ->setProperty('price') ->setFunction(function($data) { return $this->precioRepository->create($data); })) - ->register('start_date', new Implement\Repository\Mapper\DateTime('start_date', 'startDate')) - ->register('end_date', new Implement\Repository\Mapper\DateTime('end_date', 'endDate')) - ->register('valid_until', new Implement\Repository\Mapper\DateTime('valid_until', 'validUntil')); + ->register('start_date', new Common\Implement\Repository\Mapper\DateTime('start_date', 'startDate')) + ->register('end_date', new Common\Implement\Repository\Mapper\DateTime('end_date', 'endDate')) + ->register('valid_until', new Common\Implement\Repository\Mapper\DateTime('valid_until', 'validUntil')); return $this->parseData(new Model\Venta\Promotion(), $data, $map); } public function save(Common\Define\Model $model): Model\Venta\Promotion { $model->id = $this->saveNew( - ['amount', 'type', 'start_date', 'end_date', 'valid_until', 'price_id'], - [$model->amount, $model->type, $model->startDate->format('Y-m-d'), $model->endDate->format('Y-m-d'), $model->validUntil->format('Y-m-d'), $model->price->id] + ['contract_id', 'amount', 'type', 'start_date', 'end_date', 'valid_until', 'price_id'], + [$model->contract->id, $model->amount, $model->type, $model->startDate->format('Y-m-d'), + $model->endDate->format('Y-m-d'), $model->validUntil->format('Y-m-d'), $model->price->id] ); return $model; } public function edit(Common\Define\Model $model, array $new_data): Model\Venta\Promotion { - return $this->update($model, ['amount', 'type', 'start_date', 'end_date', 'valid_until', 'price_id'], $new_data); + return $this->update($model, ['contract_id', 'amount', 'type', 'start_date', 'end_date', 'valid_until', 'price_id'], $new_data); } + /** + * @param int $contract_id + * @return array + * @throws Common\Implement\Exception\EmptyResult + */ + public function fetchByContract(int $contract_id): array + { + $query = $this->connection->getQueryBuilder() + ->select() + ->from($this->getTable()) + ->where('contract_id = :contract_id'); + return $this->fetchMany($query, ['contract_id' => $contract_id]); + } + + /** + * @param int $contract_id + * @return array + * @throws Common\Implement\Exception\EmptyResult + */ + public function fetchActiveByContract(int $contract_id): array + { + $query = $this->connection->getQueryBuilder() + ->select() + ->from($this->getTable()) + ->where('contract_id = :contract_id AND state = :state'); + return $this->fetchMany($query, ['contract_id' => $contract_id, 'state' => Model\Venta\Promotion\State::ACTIVE]); + } + + /** + * @param int $price_id + * @return array + * @throws Common\Implement\Exception\EmptyResult + */ public function fetchByPrice(int $price_id): array { $query = $this->connection->getQueryBuilder() @@ -51,6 +91,12 @@ class Promotion extends Common\Ideal\Repository ->where('price_id = :price_id'); return $this->fetchMany($query, ['price_id' => $price_id]); } + + /** + * @param int $price_id + * @return array + * @throws Common\Implement\Exception\EmptyResult + */ public function fetchActiveByPrice(int $price_id): array { $query = $this->connection->getQueryBuilder() @@ -59,4 +105,57 @@ class Promotion extends Common\Ideal\Repository ->where('price_id = :price_id AND state = :state'); return $this->fetchMany($query, ['price_id' => $price_id, 'state' => Model\Venta\Promotion\State::ACTIVE]); } + + /** + * @param int $project_id + * @return array + * @throws Common\Implement\Exception\EmptyResult + */ + public function fetchByProject(int $project_id): array + { + $query = $this->connection->getQueryBuilder() + ->select('a.*') + ->from("{$this->getTable()} a") + ->joined('INNER JOIN precio ON precio.id = a.price_id') + ->joined('INNER JOIN unidad ON unidad.id = precio.unidad') + ->joined('INNER JOIN proyecto_tipo_unidad ON proyecto_tipo_unidad.id = unidad.pt') + ->joined('INNER JOIN proyecto ON proyecto.id = proyecto_tipo_unidad.proyecto') + ->where('proyecto.id = :project_id'); + return $this->fetchMany($query, ['project_id' => $project_id]); + } + + /** + * @param int $project_id + * @return array + * @throws Common\Implement\Exception\EmptyResult + */ + public function fetchActiveByProject(int $project_id): array + { + $query = $this->connection->getQueryBuilder() + ->select('a.*') + ->from("{$this->getTable()} a") + ->joined('INNER JOIN precio ON precio.id = a.price_id') + ->joined('INNER JOIN unidad ON unidad.id = precio.unidad') + ->joined('INNER JOIN proyecto_tipo_unidad ON proyecto_tipo_unidad.id = unidad.pt') + ->joined('INNER JOIN proyecto ON proyecto.id = proyecto_tipo_unidad.proyecto') + ->where('proyecto.id = :project_id AND a.state = :state'); + return $this->fetchMany($query, ['project_id' => $project_id, 'state' => Model\Venta\Promotion\State::ACTIVE]); + } + + /** + * @param int $contract_id + * @param int $unit_id + * @return Model\Venta\Promotion + * @throws Common\Implement\Exception\EmptyResult + */ + public function fetchByContractAndUnit(int $contract_id, int $unit_id): Model\Venta\Promotion + { + $query = $this->connection->getQueryBuilder() + ->select('a.*') + ->from("{$this->getTable()} a") + ->joined('INNER JOIN precio ON precio.id = a.price_id') + ->joined('INNER JOIN unidad ON unidad.id = precio.unidad') + ->where('a.contract_id = :contract_id AND unidad.id = :unit_id'); + return $this->fetchOne($query, ['contract_id' => $contract_id, 'unit_id' => $unit_id]); + } } diff --git a/app/src/Repository/Venta/Unidad.php b/app/src/Repository/Venta/Unidad.php index d29bc3e..6f8477c 100644 --- a/app/src/Repository/Venta/Unidad.php +++ b/app/src/Repository/Venta/Unidad.php @@ -172,6 +172,18 @@ class Unidad extends Ideal\Repository ->group('unidad.id'); return $this->connection->execute($query, [$unidad_id])->fetch(PDO::FETCH_ASSOC); } + public function fetchSoldByUnidad(int $unidad_id): Model\Venta\Unidad + { + $query = $this->connection->getQueryBuilder() + ->select('a.*') + ->from("{$this->getTable()} a") + ->joined('INNER JOIN `propiedad_unidad` pu ON pu.`unidad` = a.`id`') + ->joined('INNER JOIN `venta` ON `venta`.`propiedad` = `pu`.`propiedad`') + ->joined('LEFT OUTER JOIN (SELECT ev1.* FROM `estado_venta` ev1 JOIN (SELECT MAX(`id`) as `id`, `venta` FROM `estado_venta`) ev0 ON ev0.`id` = ev1.`id`) ev ON ev.`venta` = `venta`.`id`') + ->joined('LEFT OUTER JOIN `tipo_estado_venta` tev ON tev.`id` = ev.`estado`') + ->where('a.id = :unidad_id AND tev.activa = 1'); + return $this->fetchOne($query, ['unidad_id' => $unidad_id]); + } protected function joinProrrateo(): string { diff --git a/app/src/Service/Proyecto/Broker/Contract.php b/app/src/Service/Proyecto/Broker/Contract.php index 40664af..8c276eb 100644 --- a/app/src/Service/Proyecto/Broker/Contract.php +++ b/app/src/Service/Proyecto/Broker/Contract.php @@ -16,7 +16,8 @@ class Contract extends Ideal\Service { public function __construct(LoggerInterface $logger, protected Repository\Proyecto\Broker\Contract $contractRepository, - protected Repository\Proyecto\Broker\Contract\State $stateRepository) + protected Repository\Proyecto\Broker\Contract\State $stateRepository, + protected Repository\Venta\Promotion $promotionRepository) { parent::__construct($logger); } @@ -145,6 +146,9 @@ class Contract extends Ideal\Service $contract->addFactory('states', (new Implement\Repository\Factory()) ->setCallable([$this->stateRepository, 'fetchByContract']) ->setArgs(['contract_id' => $contract->id])); + $contract->addFactory('promotions', (new Implement\Repository\Factory()) + ->setCallable([$this->promotionRepository, 'fetchByContract']) + ->setArgs(['contract_id' => $contract->id])); return $contract; } } diff --git a/app/src/Service/Venta/Promotion.php b/app/src/Service/Venta/Promotion.php new file mode 100644 index 0000000..5b1b781 --- /dev/null +++ b/app/src/Service/Venta/Promotion.php @@ -0,0 +1,85 @@ +promotionRepository->fetchAll($order)); + } catch (Implement\Exception\EmptyResult) { + return []; + } + } + + /** + * @param int $promotion_id + * @return Model\Venta\Promotion + * @throws Exception\ServiceAction\Read + */ + public function getById(int $promotion_id): Model\Venta\Promotion + { + try { + return $this->process($this->promotionRepository->fetchById($promotion_id)); + } catch (Implement\Exception\EmptyResult $exception) { + throw new Exception\ServiceAction\Read(__CLASS__, $exception); + } + } + + /** + * @param int $contract_id + * @return array + */ + public function getByContract(int $contract_id): array + { + try { + return array_map([$this, 'process'], $this->promotionRepository->fetchByContract($contract_id)); + } catch (Implement\Exception\EmptyResult) { + try { + $contract = $this->contractRepository->fetchById($contract_id); + return array_map([$this, 'process'], $this->promotionRepository->fetchByProject($contract->project->id)); + } catch (Implement\Exception\EmptyResult) { + return []; + } + } + } + + /** + * @param int $contract_id + * @return array + */ + public function getActiveByContract(int $contract_id): array + { + try { + return array_map([$this, 'process'], $this->promotionRepository->fetchActiveByContract($contract_id)); + } catch (Implement\Exception\EmptyResult) { + try { + $contract = $this->contractRepository->fetchById($contract_id); + return array_map([$this, 'process'], $this->promotionRepository->fetchActiveByProject($contract->project->id)); + } catch (Implement\Exception\EmptyResult) { + return []; + } + } + } + + + protected function process(Model\Venta\Promotion $model): Model\Venta\Promotion + { + return $model; + } +} diff --git a/app/src/Service/Venta/Unidad.php b/app/src/Service/Venta/Unidad.php index 414741d..39fce4e 100644 --- a/app/src/Service/Venta/Unidad.php +++ b/app/src/Service/Venta/Unidad.php @@ -1,9 +1,10 @@ unidadRepository->fetchByCierre($cierre_id)); } + public function getByProyecto(int $proyecto_id): array + { + return array_map([$this, 'process'], $this->unidadRepository->fetchByProyecto($proyecto_id)); + } public function getDisponiblesByProyecto(int $proyecto_id): array { return $this->unidadRepository->fetchDisponiblesByProyecto($proyecto_id); @@ -62,6 +67,10 @@ class Unidad $unidad->precios = $this->precioService->getByUnidad($unidad->id); $unidad->currentPrecio = $this->precioService->getVigenteByUnidad($unidad->id); } catch (Read) {} + $unidad->addFactory('sold', (new Factory()) + ->setCallable([$this->unidadRepository, 'fetchSoldByUnidad']) + ->setArgs(['unidad_id' => $unidad->id]) + ); return $unidad; } }