Actualizacion de Repos
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
namespace Incoviba\Repository\Proyecto;
|
||||
|
||||
use Incoviba\Common;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
|
||||
@ -11,6 +12,14 @@ class Broker extends Common\Ideal\Repository
|
||||
{
|
||||
return 'brokers';
|
||||
}
|
||||
protected function getIndex(Define\Model $model): mixed
|
||||
{
|
||||
return $model->rut;
|
||||
}
|
||||
protected function getKey(): string
|
||||
{
|
||||
return 'rut';
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Model\Proyecto\Broker
|
||||
{
|
||||
|
@ -13,6 +13,11 @@ class Contract extends Common\Ideal\Repository
|
||||
parent::__construct($connection);
|
||||
}
|
||||
|
||||
public function getTable(): string
|
||||
{
|
||||
return 'broker_contracts';
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Model\Proyecto\Broker\Contract
|
||||
{
|
||||
$map = (new Common\Implement\Repository\MapperParser(['commission']))
|
||||
|
@ -12,6 +12,11 @@ class State extends Common\Ideal\Repository
|
||||
parent::__construct($connection);
|
||||
}
|
||||
|
||||
public function getTable(): string
|
||||
{
|
||||
return 'brokers_contract_states';
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Model\Proyecto\Broker\Contract\State
|
||||
{
|
||||
$map = (new Common\Implement\Repository\MapperParser(['type']))
|
||||
|
@ -14,6 +14,11 @@ class Data extends Common\Ideal\Repository
|
||||
parent::__construct($connection);
|
||||
}
|
||||
|
||||
public function getTable(): string
|
||||
{
|
||||
return 'broker_data';
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Model\Proyecto\Broker\Data
|
||||
{
|
||||
$map = (new Common\Implement\Repository\MapperParser())
|
||||
@ -26,13 +31,15 @@ class Data extends Common\Ideal\Repository
|
||||
->setProperty('representative')
|
||||
->setDefault(null)
|
||||
->setFunction(function($data) {
|
||||
if ($data['representative_rut'] == null) return null;
|
||||
try {
|
||||
return $this->personaRepository->fetchById($data['representative_rut']);
|
||||
} catch (Common\Implement\Exception\EmptyResult) {
|
||||
return null;
|
||||
}
|
||||
}))
|
||||
->register('legalName', (new Common\Implement\Repository\Mapper())
|
||||
->register('legal_name', (new Common\Implement\Repository\Mapper())
|
||||
->setProperty('legalName')
|
||||
->setDefault(null));
|
||||
return $this->parseData(new Model\Proyecto\Broker\Data(), $data, $map);
|
||||
}
|
||||
@ -45,15 +52,15 @@ class Data extends Common\Ideal\Repository
|
||||
}
|
||||
public function edit(Common\Define\Model $model, array $new_data): Model\Proyecto\Broker\Data
|
||||
{
|
||||
return $this->update($model, ['broker_rut', 'representative_rut', 'legal_name'], $new_data);
|
||||
return $this->update($model, ['representative_rut', 'legal_name'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByBroker(int $brokerRut): Model\Proyecto\Broker\Data
|
||||
public function fetchByBroker(int $broker_rut): Model\Proyecto\Broker\Data
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select()
|
||||
->from($this->getTable())
|
||||
->where('broker_rut = :broker_rut');
|
||||
return $this->fetchOne($query, ['broker_rut' => $brokerRut]);
|
||||
return $this->fetchOne($query, ['broker_rut' => $broker_rut]);
|
||||
}
|
||||
}
|
@ -11,6 +11,11 @@ class Promotion extends Common\Ideal\Repository
|
||||
parent::__construct($connection);
|
||||
}
|
||||
|
||||
public function getTable(): string
|
||||
{
|
||||
return 'promotions';
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Model\Venta\Promotion
|
||||
{
|
||||
$map = (new Implement\Repository\MapperParser(['amount', 'type']))
|
||||
|
@ -16,6 +16,11 @@ class Reservation extends Common\Ideal\Repository
|
||||
parent::__construct($connection);
|
||||
}
|
||||
|
||||
public function getTable(): string
|
||||
{
|
||||
return 'reservations';
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Model\Venta\Reservation
|
||||
{
|
||||
$map = (new Common\Implement\Repository\MapperParser())
|
||||
|
60
app/src/Repository/Venta/Reservation/State.php
Normal file
60
app/src/Repository/Venta/Reservation/State.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta\Reservation;
|
||||
|
||||
use Incoviba\Common;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class State extends Common\Ideal\Repository
|
||||
{
|
||||
public function __construct(Common\Define\Connection $connection, protected Repository\Venta\Reservation $reservationRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
}
|
||||
|
||||
public function getTable(): string
|
||||
{
|
||||
return 'reservation_states';
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Model\Venta\Reservation\State
|
||||
{
|
||||
$map = (new Common\Implement\Repository\MapperParser(['type']))
|
||||
->register('reservation_id', (new Common\Implement\Repository\Mapper())
|
||||
->setProperty('reservation')
|
||||
->setFunction(function($data) use ($data) {
|
||||
return $this->reservationRepository->fetchById($data['reservation_id']);
|
||||
}))
|
||||
->register('date', new Common\Implement\Repository\Mapper\DateTime('date'));
|
||||
return $this->parseData(new Model\Venta\Reservation\State(), $data, $map);
|
||||
}
|
||||
public function save(Common\Define\Model $model): Model\Venta\Reservation\State
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['reservation_id', 'date', 'type'],
|
||||
[$model->reservation->id, $model->date->format('Y-m-d'), $model->type]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Common\Define\Model $model, array $new_data): Model\Venta\Reservation\State
|
||||
{
|
||||
return $this->update($model, ['reservation_id', 'date', 'type'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByReservation(int $reservation_id): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select()
|
||||
->from($this->getTable())
|
||||
->where('reservation_id = :reservation_id');
|
||||
return $this->fetchMany($query, ['reservation_id' => $reservation_id]);
|
||||
}
|
||||
public function fetchActiveByReservation(int $reservation_id): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select()
|
||||
->from($this->getTable())
|
||||
->where('reservation_id = :reservation_id AND type = :type');
|
||||
return $this->fetchMany($query, ['reservation_id' => $reservation_id, 'type' => Model\Venta\Reservation\State\Type::ACTIVE]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user