Cleanup
This commit is contained in:
@ -36,11 +36,22 @@ class Broker extends Common\Ideal\Repository
|
||||
return $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Define\Model $model
|
||||
* @param array $new_data
|
||||
* @return Model\Proyecto\Broker
|
||||
* @throws Common\Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function edit(Common\Define\Model $model, array $new_data): Model\Proyecto\Broker
|
||||
{
|
||||
return $this->update($model, ['rut', 'digit', 'name'], $new_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @return Model\Proyecto\Broker|null
|
||||
* @throws Common\Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByName(string $name): ?Model\Proyecto\Broker
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
|
@ -42,11 +42,23 @@ class Contract extends Common\Ideal\Repository
|
||||
[$model->broker->rut, $model->proyecto->id, $model->commission]);
|
||||
return $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Common\Define\Model $model
|
||||
* @param array $new_data
|
||||
* @return Model\Proyecto\Broker\Contract
|
||||
* @throws Common\Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function edit(Common\Define\Model $model, array $new_data): Model\Proyecto\Broker\Contract
|
||||
{
|
||||
return $this->update($model, ['broker_rut', 'proyecto_id', 'commission'], $new_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $brokerRut
|
||||
* @return array
|
||||
* @throws Common\Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByBroker(int $brokerRut): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -55,6 +67,12 @@ class Contract extends Common\Ideal\Repository
|
||||
->where('broker_rut = :broker_rut');
|
||||
return $this->fetchMany($query, ['broker_rut' => $brokerRut]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $proyecto_id
|
||||
* @return array
|
||||
* @throws Common\Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByProject(int $proyecto_id): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -63,6 +81,12 @@ class Contract extends Common\Ideal\Repository
|
||||
->where('proyecto_id = :proyecto_id');
|
||||
return $this->fetchMany($query, ['proyecto_id' => $proyecto_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $brokerRut
|
||||
* @return array
|
||||
* @throws Common\Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchActiveByBroker(int $brokerRut): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -72,6 +96,12 @@ class Contract extends Common\Ideal\Repository
|
||||
->where('a.broker_rut = :broker_rut AND bcs.state = :state');
|
||||
return $this->fetchMany($query, ['broker_rut' => $brokerRut, 'state' => Model\Proyecto\Broker\Contract\Type::ACTIVE]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $proyecto_id
|
||||
* @return array
|
||||
* @throws Common\Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchActiveByProject(int $proyecto_id): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -81,6 +111,13 @@ class Contract extends Common\Ideal\Repository
|
||||
->where('a.proyecto_id = :proyecto_id AND bcs.state = :state');
|
||||
return $this->fetchMany($query, ['proyecto_id' => $proyecto_id, 'state' => Model\Proyecto\Broker\Contract\Type::ACTIVE]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $proyecto_id
|
||||
* @param int $brokerRut
|
||||
* @return Model\Proyecto\Broker\Contract
|
||||
* @throws Common\Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchActiveByProjectAndBroker(int $proyecto_id, int $brokerRut): Model\Proyecto\Broker\Contract
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
|
@ -50,11 +50,23 @@ class Data extends Common\Ideal\Repository
|
||||
[$model->broker->rut, $model->representative?->rut, $model->legalName]);
|
||||
return $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Common\Define\Model $model
|
||||
* @param array $new_data
|
||||
* @return Model\Proyecto\Broker\Data
|
||||
* @throws Common\Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function edit(Common\Define\Model $model, array $new_data): Model\Proyecto\Broker\Data
|
||||
{
|
||||
return $this->update($model, ['representative_rut', 'legal_name'], $new_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $broker_rut
|
||||
* @return Model\Proyecto\Broker\Data
|
||||
* @throws Common\Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByBroker(int $broker_rut): Model\Proyecto\Broker\Data
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
|
@ -1,7 +1,8 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use DateTimeInterface;
|
||||
use DateInterval;
|
||||
use PDO;
|
||||
use Incoviba\Common;
|
||||
use Incoviba\Model;
|
||||
@ -57,6 +58,13 @@ class Reservation extends Common\Ideal\Repository
|
||||
$this->savePromotions($model);
|
||||
return $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Common\Define\Model $model
|
||||
* @param array $new_data
|
||||
* @return Model\Venta\Reservation
|
||||
* @throws Common\Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function edit(Common\Define\Model $model, array $new_data): Model\Venta\Reservation
|
||||
{
|
||||
return $this->update($model, ['buyer_rut', 'date', 'broker_rut'], $new_data);
|
||||
@ -71,6 +79,21 @@ class Reservation extends Common\Ideal\Repository
|
||||
return $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $buyer_rut
|
||||
* @param DateTimeInterface $date
|
||||
* @return Model\Venta\Reservation
|
||||
* @throws Common\Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByBuyerAndDate(int $buyer_rut, DateTimeInterface $date): Model\Venta\Reservation
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select()
|
||||
->from('reservations')
|
||||
->where('buyer_rut = :buyer_rut AND date >= :date');
|
||||
return $this->fetchOne($query, ['buyer_rut' => $buyer_rut, 'date' => $date->sub(new DateInterval('P10D'))->format('Y-m-d')]);
|
||||
}
|
||||
|
||||
protected function saveUnits(Model\Venta\Reservation $reservation): void
|
||||
{
|
||||
if (empty($reservation->units)) {
|
||||
|
@ -34,7 +34,7 @@ class Broker extends Ideal\Service
|
||||
try {
|
||||
$broker = $this->brokerRepository->create($filteredData);
|
||||
$broker = $this->brokerRepository->save($broker);
|
||||
} catch (PDOException | EmptyResult $exception) {
|
||||
} catch (PDOException $exception) {
|
||||
throw new ServiceAction\Create(__CLASS__, $exception);
|
||||
}
|
||||
}
|
||||
@ -100,7 +100,7 @@ class Broker extends Ideal\Service
|
||||
}
|
||||
try {
|
||||
$this->brokerRepository->remove($broker);
|
||||
} catch (PDOException | EmptyResult $exception) {
|
||||
} catch (PDOException $exception) {
|
||||
throw new ServiceAction\Delete(__CLASS__, $exception);
|
||||
} finally {
|
||||
return $broker;
|
||||
@ -116,6 +116,13 @@ class Broker extends Ideal\Service
|
||||
|
||||
return $broker;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Model\Proyecto\Broker $broker
|
||||
* @param array $data
|
||||
* @return Model\Proyecto\Broker\Data
|
||||
* @throws ServiceAction\Create
|
||||
*/
|
||||
protected function addData(Model\Proyecto\Broker $broker, array $data): Model\Proyecto\Broker\Data
|
||||
{
|
||||
$data['broker_rut'] = $broker->rut;
|
||||
@ -123,7 +130,7 @@ class Broker extends Ideal\Service
|
||||
if (isset($filteredData['representative_rut'])) {
|
||||
try {
|
||||
$this->personaService->getById($filteredData['representative_rut']);
|
||||
} catch (EmptyResult) {
|
||||
} catch (ServiceAction\Read) {
|
||||
unset($filteredData['representative_rut']);
|
||||
}
|
||||
}
|
||||
@ -134,10 +141,17 @@ class Broker extends Ideal\Service
|
||||
try {
|
||||
$brokerData = $this->dataRepository->create($filteredData);
|
||||
return $this->dataRepository->save($brokerData);
|
||||
} catch (PDOException | EmptyResult $exception) {
|
||||
} catch (PDOException $exception) {
|
||||
throw new ServiceAction\Create(__CLASS__, $exception);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Model\Proyecto\Broker $broker
|
||||
* @param array $data
|
||||
* @return Model\Proyecto\Broker\Data
|
||||
* @throws ServiceAction\Update
|
||||
*/
|
||||
protected function editData(Model\Proyecto\Broker $broker, array $data): Model\Proyecto\Broker\Data
|
||||
{
|
||||
try {
|
||||
|
@ -73,7 +73,7 @@ class Contract extends Ideal\Service
|
||||
$state = $this->stateRepository->create(['contract_id' => $contract->id, 'date' => $date, 'type' => $type]);
|
||||
$this->stateRepository->save($state);
|
||||
return $this->process($contract);
|
||||
} catch (Implement\Exception\EmptyResult $exception) {
|
||||
} catch (PDOException $exception) {
|
||||
throw new ServiceAction\Create(__CLASS__, $exception);
|
||||
}
|
||||
}
|
||||
@ -115,7 +115,7 @@ class Contract extends Ideal\Service
|
||||
$state = $this->stateRepository->create(['contract_id' => $contract->id, 'date' => $date, 'type' => $type]);
|
||||
$this->stateRepository->save($state);
|
||||
return $this->process($contract);
|
||||
} catch (PDOException | Implement\Exception\EmptyResult $exception) {
|
||||
} catch (PDOException $exception) {
|
||||
throw new ServiceAction\Update(__CLASS__, $exception);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user