Listado de Precios para Contrato Broker

This commit is contained in:
Juan Pablo Vial
2025-03-13 12:18:08 -03:00
parent 346001db8e
commit 68aebdb4fe
18 changed files with 826 additions and 14 deletions

View File

@ -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;
}
}

View File

@ -0,0 +1,85 @@
<?php
namespace Incoviba\Service\Venta;
use Psr\Log\LoggerInterface;
use Incoviba\Common\Ideal;
use Incoviba\Common\Implement;
use Incoviba\Exception;
use Incoviba\Model;
use Incoviba\Repository;
use Incoviba\Service;
class Promotion extends Ideal\Service
{
public function __construct(LoggerInterface $logger,
protected Repository\Venta\Promotion $promotionRepository,
protected Repository\Proyecto\Broker\Contract $contractRepository)
{
parent::__construct($logger);
}
public function getAll(null|string|array $order = null): array
{
try {
return array_map([$this, 'process'], $this->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;
}
}

View File

@ -1,9 +1,10 @@
<?php
namespace Incoviba\Service\Venta;
use Incoviba\Exception\ServiceAction\Read;
use PDOException;
use Incoviba\Common\Implement\Repository\Factory;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Exception\ServiceAction\Read;
use Incoviba\Repository;
use Incoviba\Model;
@ -31,6 +32,10 @@ class Unidad
{
return array_map([$this, 'process'], $this->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;
}
}