Editar Brokers y sus contratos

This commit is contained in:
Juan Pablo Vial
2025-03-11 17:41:11 -03:00
parent 510e05e5ca
commit 7c7c8315e2
13 changed files with 491 additions and 60 deletions

View File

@ -1,23 +1,46 @@
<?php
namespace Incoviba\Controller\Proyectos;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Exception\ServiceAction\Read;
use Psr\Log\LoggerInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
use Incoviba\Common\Alias\View;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Exception\ServiceAction\Read;
use Incoviba\Repository;
use Incoviba\Service;
use Psr\Log\LoggerInterface;
class Brokers
{
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, LoggerInterface $logger, Service\Proyecto\Broker $brokerService, View $view): ResponseInterface
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, LoggerInterface $logger,
Service\Proyecto\Broker $brokerService, Repository\Proyecto $proyectoRepository,
View $view): ResponseInterface
{
$brokers = [];
$projects = [];
try {
$brokers = $brokerService->getAll();
} catch (Read) {}
return $view->render($response, 'proyectos.brokers', compact('brokers'));
$projects = $proyectoRepository->fetchAll('descripcion');
} catch (EmptyResult $exception) {
$logger->error($exception);
}
$brokers = $brokerService->getAll();
return $view->render($response, 'proyectos.brokers', compact('brokers', 'projects'));
}
public function show(ServerRequestInterface $request, ResponseInterface $response, LoggerInterface $logger,
Service\Proyecto\Broker $brokerService, Repository\Proyecto $proyectoRepository,
View $view, int $broker_rut): ResponseInterface
{
$broker = null;
try {
$broker = $brokerService->get($broker_rut);
} catch (Read $exception) {
$logger->error($exception);
}
$projects = [];
try {
$projects = $proyectoRepository->fetchAll('descripcion');
} catch (EmptyResult $exception) {
$logger->error($exception);
}
return $view->render($response, 'proyectos.brokers.show', compact('broker', 'projects'));
}
}

View File

@ -9,9 +9,9 @@ class Contract extends Common\Ideal\Model
public Model\Proyecto $project;
public Model\Proyecto\Broker $broker;
public float $commission;
protected array $states = [];
protected ?array $states;
public function states(): array
public function states(): ?array
{
if (!isset($this->states) or count($this->states) === 0) {
$this->states = $this->runFactory('states');
@ -20,7 +20,7 @@ class Contract extends Common\Ideal\Model
}
protected ?Contract\State $current;
public function currentState(): ?Contract\State
public function current(): ?Contract\State
{
if (!isset($this->current)) {
try {
@ -39,7 +39,7 @@ class Contract extends Common\Ideal\Model
'broker_rut' => $this->broker->rut,
'commission' => $this->commission,
'states' => $this->states(),
'current' => $this->currentState(),
'current' => $this->current(),
];
}
}

View File

@ -6,12 +6,12 @@ use IntlDateFormatter;
class Format
{
public function localDate(string $valor, string $format, bool $print = false): string
public function localDate(string $valor, ?string $format = null, bool $print = false): string
{
$date = new DateTimeImmutable($valor);
$formatter = new IntlDateFormatter('es_ES');
if ($format == null) {
$format = 'DD [de] MMMM [de] YYYY';
$format = "dd 'de' MMMM 'de' YYYY";
}
$formatter->setPattern($format);
return $formatter->format($date);

View File

@ -17,7 +17,8 @@ class Broker extends Ideal\Service
protected Repository\Proyecto\Broker $brokerRepository,
protected Repository\Proyecto\Broker\Data $dataRepository,
protected Repository\Proyecto\Broker\Contact $contactRepository,
protected Repository\Proyecto\Broker\Contract $contractRepository)
protected Repository\Proyecto\Broker\Contract $contractRepository,
protected Service\Proyecto\Broker\Contract $contractService)
{
parent::__construct($logger);
}
@ -115,8 +116,8 @@ class Broker extends Ideal\Service
->setArgs(['broker_rut' => $broker->rut])
->setCallable([$this->dataRepository, 'fetchByBroker']))
->addFactory('contracts', (new Factory())
->setArgs(['brokerRut' => $broker->rut])
->setCallable([$this->contractRepository, 'fetchByBroker']));
->setArgs(['broker_rut' => $broker->rut])
->setCallable([$this->contractService, 'getByBroker']));
return $broker;
}

View File

@ -118,7 +118,7 @@ class Contract extends Ideal\Service
{
try {
$contract = $this->contractRepository->fetchById($id);
$this->contractRepository->remove($contract->id);
$this->contractRepository->remove($contract);
return $contract;
} catch (PDOException | Implement\Exception\EmptyResult $exception) {
throw new ServiceAction\Delete(__CLASS__, $exception);
@ -145,9 +145,6 @@ class Contract extends Ideal\Service
$contract->addFactory('states', (new Implement\Repository\Factory())
->setCallable([$this->stateRepository, 'fetchByContract'])
->setArgs(['contract_id' => $contract->id]));
/*$contract->addFactory('currentState', (new Implement\Repository\Factory())
->setCallable([$this->stateRepository, 'fetchActiveByContract'])
->setArgs(['contract_id' => $contract->id]));*/
return $contract;
}
}