Compare commits
14 Commits
a7fc89ac29
...
5f69069aa0
Author | SHA1 | Date | |
---|---|---|---|
5f69069aa0 | |||
095a65a643 | |||
928d2e57be | |||
e4e952e842 | |||
2a0335f834 | |||
9ccf53fa4e | |||
8f16f33a1e | |||
ef54c36edc | |||
4aa88d5164 | |||
8ea13c3efd | |||
12e3d7ed3b | |||
d165440483 | |||
1720f6854b | |||
3e6452a44d |
@ -3,13 +3,42 @@ namespace Incoviba\Common\Define;
|
||||
|
||||
use PDO;
|
||||
use PDOStatement;
|
||||
use PDOException;
|
||||
|
||||
interface Connection
|
||||
{
|
||||
/**
|
||||
* @return Connection
|
||||
* @throws PDOException
|
||||
*/
|
||||
public function connect(): Connection;
|
||||
|
||||
/**
|
||||
* @param string $query
|
||||
* @return PDOStatement
|
||||
* @throws PDOException
|
||||
*/
|
||||
public function query(string $query): PDOStatement;
|
||||
|
||||
/**
|
||||
* @param string $query
|
||||
* @return PDOStatement
|
||||
* @throws PDOException
|
||||
*/
|
||||
public function prepare(string $query): PDOStatement;
|
||||
|
||||
/**
|
||||
* @param string $query
|
||||
* @param array|null $data
|
||||
* @return PDOStatement
|
||||
* @throws PDOException
|
||||
*/
|
||||
public function execute(string $query, ?array $data = null): PDOStatement;
|
||||
|
||||
/**
|
||||
* @return PDO
|
||||
* @throws PDOException
|
||||
*/
|
||||
public function getPDO(): PDO;
|
||||
public function getQueryBuilder(): Query\Builder;
|
||||
}
|
||||
|
@ -2,8 +2,15 @@
|
||||
namespace Incoviba\Common\Define\Money;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResponse;
|
||||
|
||||
interface Provider
|
||||
{
|
||||
/**
|
||||
* @param string $money_symbol
|
||||
* @param DateTimeInterface $dateTime
|
||||
* @return float
|
||||
* @throws EmptyResponse
|
||||
*/
|
||||
public function get(string $money_symbol, DateTimeInterface $dateTime): float;
|
||||
}
|
||||
|
@ -1,11 +1,42 @@
|
||||
<?php
|
||||
namespace Incoviba\Common\Define;
|
||||
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use PDOException;
|
||||
|
||||
interface Repository
|
||||
{
|
||||
/**
|
||||
* @param array|null $data
|
||||
* @return Model
|
||||
*/
|
||||
public function create(?array $data = null): Model;
|
||||
|
||||
/**
|
||||
* @param Model $model
|
||||
* @return Model
|
||||
* @throws PDOException
|
||||
*/
|
||||
public function save(Model $model): Model;
|
||||
|
||||
/**
|
||||
* @param array $data_row
|
||||
* @return Model
|
||||
*/
|
||||
public function load(array $data_row): Model;
|
||||
|
||||
/**
|
||||
* @param Model $model
|
||||
* @param array $new_data
|
||||
* @return Model
|
||||
* @throws EmptyResult
|
||||
*/
|
||||
public function edit(Model $model, array $new_data): Model;
|
||||
|
||||
/**
|
||||
* @param Model $model
|
||||
* @return void
|
||||
* @throws PDOException
|
||||
*/
|
||||
public function remove(Model $model): void;
|
||||
}
|
||||
|
@ -2,7 +2,9 @@
|
||||
namespace Incoviba\Common\Ideal;
|
||||
|
||||
use PDO;
|
||||
use PDOException;
|
||||
use ReflectionProperty;
|
||||
use ReflectionException;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
@ -116,9 +118,20 @@ abstract class Repository implements Define\Repository
|
||||
}
|
||||
$this->setDefault($model, $property);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Define\Model $model
|
||||
* @param string $property
|
||||
* @return void
|
||||
*/
|
||||
protected function setDefault(Define\Model &$model, string $property): void
|
||||
{
|
||||
$prop = new ReflectionProperty($model, $property);
|
||||
try {
|
||||
$prop = new ReflectionProperty($model, $property);
|
||||
} catch (ReflectionException) {
|
||||
$model->{$property} = null;
|
||||
return;
|
||||
}
|
||||
$type = $prop->getType()->getName();
|
||||
$value = match ($type) {
|
||||
'int' => 0,
|
||||
@ -128,6 +141,13 @@ abstract class Repository implements Define\Repository
|
||||
};
|
||||
$model->{$property} = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $columns
|
||||
* @param array $values
|
||||
* @return int
|
||||
* @throws PDOException
|
||||
*/
|
||||
protected function saveNew(array $columns, array $values): int
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -138,6 +158,14 @@ abstract class Repository implements Define\Repository
|
||||
$this->connection->execute($query, $values);
|
||||
return $this->connection->getPDO()->lastInsertId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Define\Model $model
|
||||
* @param array $columns
|
||||
* @param array $data
|
||||
* @return Define\Model
|
||||
* @throws EmptyResult
|
||||
*/
|
||||
protected function update(Define\Model $model, array $columns, array $data): Define\Model
|
||||
{
|
||||
$changes = [];
|
||||
@ -158,30 +186,59 @@ abstract class Repository implements Define\Repository
|
||||
->set($columns_string)
|
||||
->where("{$this->getKey()} = ?");
|
||||
$values []= $this->getIndex($model);
|
||||
$this->connection->execute($query, $values);
|
||||
try {
|
||||
$this->connection->execute($query, $values);
|
||||
} catch (PDOException $exception) {
|
||||
throw new EmptyResult($query, $exception);
|
||||
}
|
||||
return $this->fetchById($this->getIndex($model));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $query
|
||||
* @param array|null $data
|
||||
* @return Define\Model
|
||||
* @throws EmptyResult
|
||||
*/
|
||||
protected function fetchOne(string $query, ?array $data = null): Define\Model
|
||||
{
|
||||
$result = $this->connection->execute($query, $data)->fetch(PDO::FETCH_ASSOC);
|
||||
if ($result === false) {
|
||||
throw new EmptyResult($query);
|
||||
try {
|
||||
$result = $this->connection->execute($query, $data)->fetch(PDO::FETCH_ASSOC);
|
||||
} catch (PDOException $exception) {
|
||||
throw new EmptyResult($query, $exception);
|
||||
|
||||
}
|
||||
return $this->load($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $query
|
||||
* @param array|null $data
|
||||
* @return array
|
||||
* @throws EmptyResult
|
||||
*/
|
||||
protected function fetchMany(string $query, ?array $data = null): array
|
||||
{
|
||||
$results = $this->connection->execute($query, $data)->fetchAll(PDO::FETCH_ASSOC);
|
||||
if ($results === false) {
|
||||
throw new EmptyResult($query);
|
||||
try {
|
||||
$results = $this->connection->execute($query, $data)->fetchAll(PDO::FETCH_ASSOC);
|
||||
} catch (PDOException $exception) {
|
||||
throw new EmptyResult($query, $exception);
|
||||
}
|
||||
return array_map([$this, 'load'], $results);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $query
|
||||
* @param array|null $data
|
||||
* @return array
|
||||
* @throws EmptyResult
|
||||
*/
|
||||
protected function fetchAsArray(string $query, ?array $data = null): array
|
||||
{
|
||||
$results = $this->connection->execute($query, $data)->fetchAll(PDO::FETCH_ASSOC);
|
||||
if ($results === false) {
|
||||
throw new EmptyResult($query);
|
||||
try {
|
||||
$results = $this->connection->execute($query, $data)->fetchAll(PDO::FETCH_ASSOC);
|
||||
} catch (PDOException $exception) {
|
||||
throw new EmptyResult($query, $exception);
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
|
56
app/common/Ideal/Service/API.php
Normal file
56
app/common/Ideal/Service/API.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
namespace Incoviba\Common\Ideal\Service;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Exception\ServiceAction;
|
||||
|
||||
abstract class API extends Ideal\Service
|
||||
{
|
||||
public function __construct(LoggerInterface $logger)
|
||||
{
|
||||
parent::__construct($logger);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|array|null $order
|
||||
* @return array
|
||||
*/
|
||||
abstract public function getAll(null|string|array $order = null): array;
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return Define\Model
|
||||
* @throws ServiceAction\Read
|
||||
*/
|
||||
abstract public function get(int $id): Define\Model;
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @return Define\Model
|
||||
* @throws ServiceAction\Create
|
||||
*/
|
||||
abstract public function add(array $data): Define\Model;
|
||||
|
||||
/**
|
||||
* @param Define\Model $model
|
||||
* @param array $new_data
|
||||
* @return Define\Model
|
||||
* @throws ServiceAction\Update
|
||||
*/
|
||||
abstract public function edit(Define\Model $model, array $new_data): Define\Model;
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return Define\Model
|
||||
* @throws ServiceAction\Delete
|
||||
*/
|
||||
abstract public function delete(int $id): Define\Model;
|
||||
|
||||
/**
|
||||
* @param Define\Model $model
|
||||
* @return Define\Model
|
||||
*/
|
||||
abstract protected function process(Define\Model $model): Define\Model;
|
||||
}
|
@ -22,6 +22,7 @@ class Connection implements Define\Connection
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPDO(): PDO
|
||||
{
|
||||
$this->connect();
|
||||
|
@ -1,12 +1,27 @@
|
||||
<?php
|
||||
use Incoviba\Controller\API\Proyectos\Brokers;
|
||||
use Incoviba\Controller\API\Proyectos\Brokers\Contracts;
|
||||
|
||||
$app->group('/brokers', function($app) {
|
||||
$app->post('/add[/]', Brokers::class . ':add');
|
||||
$app->post('/edit[/]', Brokers::class . ':edit');
|
||||
$app->group('/contracts', function($app) {
|
||||
$app->post('/add[/]', [Contracts::class, 'add']);
|
||||
$app->get('[/]', Contracts::class);
|
||||
});
|
||||
$app->group('/contract/{contract_id}', function($app) {
|
||||
$app->post('/edit[/]', [Contracts::class, 'edit']);
|
||||
$app->post('/inactive[/]', [Contracts::class, 'inactive']);
|
||||
$app->delete('[/]', [Contracts::class, 'delete']);
|
||||
$app->get('[/]', [Contracts::class, 'get']);
|
||||
});
|
||||
$app->post('/add[/]', [Brokers::class, 'add']);
|
||||
$app->post('/edit[/]', [Brokers::class, 'edit']);
|
||||
$app->get('[/]', Brokers::class);
|
||||
});
|
||||
$app->group('/broker/{broker_rut}', function($app) {
|
||||
$app->delete('[/]', Brokers::class . ':delete');
|
||||
$app->get('[/]', Brokers::class . ':show');
|
||||
$app->group('/contracts', function($app) {
|
||||
$app->post('/add[/]', [Contracts::class, 'add']);
|
||||
$app->get('[/]', [Contracts::class, 'getByBroker']);
|
||||
});
|
||||
$app->delete('[/]', [Brokers::class, 'delete']);
|
||||
$app->get('[/]', [Brokers::class, 'get']);
|
||||
});
|
||||
|
12
app/resources/routes/api/ventas/reservations.php
Normal file
12
app/resources/routes/api/ventas/reservations.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
use Incoviba\Controller\API\Ventas\Reservations;
|
||||
|
||||
$app->group('/reservations', function($app) {
|
||||
$app->post('/add[/]', [Reservations::class, 'add']);
|
||||
$app->get('[/]', Reservations::class);
|
||||
});
|
||||
$app->group('/reservation/{reservation_id}', function($app) {
|
||||
$app->post('/edit[/]', [Reservations::class, 'edit']);
|
||||
$app->delete('[/]', [Reservations::class, 'delete']);
|
||||
$app->get('[/]', [Reservations::class, 'get']);
|
||||
});
|
@ -29,6 +29,7 @@
|
||||
}
|
||||
return response.json().then(json => {
|
||||
if (!json.edited) {
|
||||
alert('No se pudo editar la unidad.')
|
||||
return
|
||||
}
|
||||
this.props.valor = parseFloat(json.input.valor)
|
||||
@ -68,8 +69,7 @@
|
||||
return
|
||||
}
|
||||
this.update().precio(newValue).then(() => {
|
||||
facturas.venta.update().totalUnidades()
|
||||
facturas.draw().facturas()
|
||||
window.location.reload()
|
||||
})
|
||||
})
|
||||
},
|
||||
|
@ -18,8 +18,8 @@
|
||||
Firmar
|
||||
</a>
|
||||
<br />
|
||||
<a href="{{$urls->base}}/ventas/factura/{{$venta->id}}">
|
||||
Factura
|
||||
<a href="{{$urls->base}}/ventas/factura/{{$venta->id}}" class="ui icon link">
|
||||
Factura<i class="small file alternate outline icon"></i>
|
||||
</a>
|
||||
</div>
|
||||
@else
|
||||
|
@ -17,7 +17,7 @@ class Brokers
|
||||
|
||||
return $this->withJson($response, compact('brokers'));
|
||||
}
|
||||
public function show(ServerRequestInterface $request, ResponseInterface $response, Service\Proyecto\Broker $brokerService, int $broker_rut): ResponseInterface
|
||||
public function get(ServerRequestInterface $request, ResponseInterface $response, Service\Proyecto\Broker $brokerService, int $broker_rut): ResponseInterface
|
||||
{
|
||||
try {
|
||||
$broker = $brokerService->get($broker_rut);
|
||||
|
143
app/src/Controller/API/Proyectos/Brokers/Contracts.php
Normal file
143
app/src/Controller/API/Proyectos/Brokers/Contracts.php
Normal file
@ -0,0 +1,143 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\API\Proyectos\Brokers;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use DateMalformedStringException;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Controller\API\withJson;
|
||||
use Incoviba\Service;
|
||||
use Incoviba\Exception\ServiceAction;
|
||||
|
||||
class Contracts
|
||||
{
|
||||
use withJson;
|
||||
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, Service\Proyecto\Broker\Contract $contractService): ResponseInterface
|
||||
{
|
||||
$contracts = $contractService->getAll();
|
||||
|
||||
return $this->withJson($response, compact('contracts'));
|
||||
}
|
||||
public function getByBroker(ServerRequestInterface $request, ResponseInterface $response, Service\Proyecto\Broker\Contract $contractService,
|
||||
Service\Proyecto\Broker $brokerService, int $broker_rut): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'broker_rut' => $broker_rut,
|
||||
'contracts' => []
|
||||
];
|
||||
try {
|
||||
$broker = $brokerService->get($broker_rut);
|
||||
$output['contracts'] = $contractService->getByBroker($broker->rut);
|
||||
} catch (ServiceAction\Read $exception) {
|
||||
return $this->withError($response, $exception);
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function get(ServerRequestInterface $request, ResponseInterface $response, Service\Proyecto\Broker\Contract $contractService, int $contract_id): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'contract_id' => $contract_id,
|
||||
'contract' => null
|
||||
];
|
||||
try {
|
||||
$output['contract'] = $contractService->getById($contract_id);
|
||||
} catch (ServiceAction\Read $exception) {
|
||||
return $this->withError($response, $exception);
|
||||
}
|
||||
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function add(ServerRequestInterface $request, ResponseInterface $response, Service\Proyecto\Broker\Contract $contractService): ResponseInterface
|
||||
{
|
||||
$input = $request->getParsedBody();
|
||||
$output = [
|
||||
'input' => $input,
|
||||
'contracts' => [],
|
||||
'success' => false,
|
||||
'partial' => false,
|
||||
'errors' => [],
|
||||
];
|
||||
foreach ($input['contracts'] as $jsonData) {
|
||||
try {
|
||||
$contractData = json_decode($jsonData, true);
|
||||
if (is_array($jsonData)) {
|
||||
$contractData = $jsonData;
|
||||
}
|
||||
$contract = $contractService->add($contractData);
|
||||
$output['contracts'] []= [
|
||||
'contract' => $contract,
|
||||
'success' => true
|
||||
];
|
||||
$output['partial'] = true;
|
||||
} catch (ServiceAction\Create $exception) {
|
||||
$output['errors'] []= $this->parseError($exception);
|
||||
}
|
||||
}
|
||||
if (count($output['contracts']) == count($input['contracts'])) {
|
||||
$output['success'] = true;
|
||||
}
|
||||
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function edit(ServerRequestInterface $request, ResponseInterface $response, Service\Proyecto\Broker\Contract $contractService, int $contract_id): ResponseInterface
|
||||
{
|
||||
$input = $request->getParsedBody();
|
||||
$output = [
|
||||
'contract_id' => $contract_id,
|
||||
'input' => $input,
|
||||
'contract' => null,
|
||||
'success' => false
|
||||
];
|
||||
try {
|
||||
$contract = $contractService->getById($contract_id);
|
||||
$output['contract'] = $contractService->edit($contract, $input);
|
||||
$output['success'] = true;
|
||||
} catch (ServiceAction\Read | ServiceAction\Update $exception) {
|
||||
return $this->withError($response, $exception);
|
||||
}
|
||||
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function inactive(ServerRequestInterface $request, ResponseInterface $response, Service\Proyecto\Broker\Contract $contractService, int $contract_id): ResponseInterface
|
||||
{
|
||||
$input = $request->getParsedBody();
|
||||
$output = [
|
||||
'contract_id' => $contract_id,
|
||||
'input' => $input,
|
||||
'contract' => null,
|
||||
'success' => false
|
||||
];
|
||||
try {
|
||||
$contract = $contractService->getById($contract_id);
|
||||
$date = new DateTimeImmutable();
|
||||
if (!empty($input['date'])) {
|
||||
try {
|
||||
$date = new DateTimeImmutable($input['date']);
|
||||
} catch (DateMalformedStringException) {}
|
||||
}
|
||||
$output['contract'] = $contractService->inactive($contract, $date);
|
||||
$output['success'] = true;
|
||||
} catch (ServiceAction\Read | ServiceAction\Update $exception) {
|
||||
return $this->withError($response, $exception);
|
||||
}
|
||||
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function delete(ServerRequestInterface $request, ResponseInterface $response, Service\Proyecto\Broker\Contract $contractService, int $contract_id): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'contract_id' => $contract_id,
|
||||
'contract' => null,
|
||||
'success' => false
|
||||
];
|
||||
try {
|
||||
$output['contract'] = $contractService->delete($contract_id);
|
||||
$output['success'] = true;
|
||||
} catch (ServiceAction\Delete $exception) {
|
||||
return $this->withError($response, $exception);
|
||||
}
|
||||
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
103
app/src/Controller/API/Ventas/Reservations.php
Normal file
103
app/src/Controller/API/Ventas/Reservations.php
Normal file
@ -0,0 +1,103 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\API\Ventas;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Controller\API\withJson;
|
||||
use Incoviba\Exception\ServiceAction;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Reservations
|
||||
{
|
||||
use withJson;
|
||||
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Reservation $reservationService): ResponseInterface
|
||||
{
|
||||
$reservations = [];
|
||||
try {
|
||||
$reservations = $reservationService->getAll();
|
||||
} catch (ServiceAction\Read $exception) {
|
||||
return $this->withError($response, $exception);
|
||||
}
|
||||
|
||||
return $this->withJson($response, compact('reservations'));
|
||||
}
|
||||
public function get(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Reservation $reservationService, int $reservation_id): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'reservation_id' => $reservation_id,
|
||||
'reservation' => null,
|
||||
];
|
||||
|
||||
try {
|
||||
$output['reservation'] = $reservationService->get($reservation_id);
|
||||
} catch (ServiceAction\Read $exception) {
|
||||
return $this->withError($response, $exception);
|
||||
}
|
||||
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function add(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Reservation $reservationService): ResponseInterface
|
||||
{
|
||||
$input = $request->getParsedBody();
|
||||
$output = [
|
||||
'input' => $input,
|
||||
'reservations' => [],
|
||||
'success' => false,
|
||||
'partial' => false,
|
||||
'errors' => [],
|
||||
];
|
||||
|
||||
try {
|
||||
$output['reservations'] []= [
|
||||
'reservation' => $reservationService->add($input),
|
||||
'success' => true
|
||||
];
|
||||
$output['partial'] = true;
|
||||
} catch (ServiceAction\Create $exception) {
|
||||
$output['errors'] []= $this->parseError($exception);
|
||||
}
|
||||
|
||||
if (count($input['reservations']) === count($output['reservations'])) {
|
||||
$output['success'] = true;
|
||||
}
|
||||
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function edit(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Reservation $reservationService, int $reservation_id): ResponseInterface
|
||||
{
|
||||
$input = $request->getParsedBody();
|
||||
$output = [
|
||||
'input' => $input,
|
||||
'reservation_id' => $reservation_id,
|
||||
'reservations' => null,
|
||||
'success' => false,
|
||||
];
|
||||
|
||||
try {
|
||||
$reservation = $reservationService->get($reservation_id);
|
||||
$output['reservations'] = $reservationService->edit($reservation, $input);
|
||||
$output['success'] = true;
|
||||
} catch (ServiceAction\Read | ServiceAction\Update $exception) {
|
||||
return $this->withError($response, $exception);
|
||||
}
|
||||
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function delete(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Reservation $reservationService, int $reservation_id): ResponseInterface
|
||||
{
|
||||
$output = [
|
||||
'reservation_id' => $reservation_id,
|
||||
'success' => false,
|
||||
];
|
||||
|
||||
try {
|
||||
$reservationService->delete($reservation_id);
|
||||
$output['success'] = true;
|
||||
} catch (ServiceAction\Delete $exception) {
|
||||
return $this->withError($response, $exception);
|
||||
}
|
||||
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
@ -5,7 +5,7 @@ class PropiedadUnidad extends Unidad
|
||||
{
|
||||
public int $pu_id;
|
||||
public int $propiedad_id;
|
||||
public float $valor;
|
||||
public ?float $valor;
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
|
@ -65,6 +65,13 @@ class Cartola extends Ideal\Repository
|
||||
->where('cuenta_id = ?');
|
||||
return $this->fetchMany($query, [$cuenta_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $cuenta_id
|
||||
* @param DateTimeInterface $fecha
|
||||
* @return Model\Contabilidad\Cartola
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByCuentaAndFecha(int $cuenta_id, DateTimeInterface $fecha): Model\Contabilidad\Cartola
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -73,6 +80,13 @@ class Cartola extends Ideal\Repository
|
||||
->where('cuenta_id = ? AND fecha = ?');
|
||||
return $this->fetchOne($query, [$cuenta_id, $fecha->format('Y-m-d')]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $cuenta_id
|
||||
* @param DateTimeInterface $fecha
|
||||
* @return Model\Contabilidad\Cartola
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchLastByCuentaAndFecha(int $cuenta_id, DateTimeInterface $fecha): Model\Contabilidad\Cartola
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
|
@ -62,6 +62,13 @@ class Movimiento extends Ideal\Repository
|
||||
->where('cuenta_id = ?');
|
||||
return $this->fetchMany($query, [$cuenta_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $cuenta_id
|
||||
* @param DateTimeInterface $fecha
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByCuentaAndFecha(int $cuenta_id, DateTimeInterface $fecha): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -70,6 +77,17 @@ class Movimiento extends Ideal\Repository
|
||||
->where('cuenta_id = ? AND fecha = ?');
|
||||
return $this->fetchMany($query, [$cuenta_id, $fecha->format('Y-m-d')]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $cuenta_id
|
||||
* @param DateTimeInterface $fecha
|
||||
* @param string $glosa
|
||||
* @param int $cargo
|
||||
* @param int $abono
|
||||
* @param int $saldo
|
||||
* @return Model\Contabilidad\Movimiento
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByCuentaAndFechaAndGlosaAndCargoAndAbonoAndSaldo(int $cuenta_id, DateTimeInterface $fecha, string $glosa, int $cargo, int $abono, int $saldo): Model\Contabilidad\Movimiento
|
||||
{
|
||||
$len = (int) round(strlen($glosa) * .75);
|
||||
@ -99,6 +117,15 @@ class Movimiento extends Ideal\Repository
|
||||
}
|
||||
return $this->fetchMany($query, [$sociedad_rut, $mes->format('Y-m-01'), $mes->format('Y-m-t')]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $cuenta_id
|
||||
* @param DateTimeInterface $startDate
|
||||
* @param DateTimeInterface $endDate
|
||||
* @param array $idList
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchMissingInDateRange(int $cuenta_id, DateTimeInterface $startDate, DateTimeInterface $endDate, array $idList = []): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
|
@ -60,6 +60,11 @@ class Detalle extends Ideal\Repository
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $movimiento_id
|
||||
* @return Model\Contabilidad\Movimiento\Detalle
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByMovimiento(int $movimiento_id): Model\Contabilidad\Movimiento\Detalle
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
|
@ -30,16 +30,38 @@ class Direccion extends Ideal\Repository
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Define\Model $model
|
||||
* @param array $new_data
|
||||
* @return Define\Model
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['calle', 'numero', 'extra', 'comuna'], $new_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $calle
|
||||
* @param int $numero
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByCalleAndNumero(string $calle, int $numero): array
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `calle` = ? AND `numero` = ?";
|
||||
return $this->fetchMany($query, [$calle, $numero]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $calle
|
||||
* @param int $numero
|
||||
* @param string $extra
|
||||
* @param int $comuna_id
|
||||
* @return Model\Direccion
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByCalleAndNumeroAndExtraAndComuna(string $calle, int $numero, string $extra, int $comuna_id): Model\Direccion
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `calle` = ? AND `numero` = ? AND `extra` = ? AND `comuna` = ?";
|
||||
|
@ -35,11 +35,23 @@ class Proveedor extends Ideal\Repository
|
||||
]);
|
||||
return $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Define\Model $model
|
||||
* @param array $new_data
|
||||
* @return Model\Inmobiliaria\Proveedor
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function edit(Define\Model $model, array $new_data): Model\Inmobiliaria\Proveedor
|
||||
{
|
||||
return $this->update($model, ['rut', 'digito', 'nombre', 'razon', 'contacto_rut'], $new_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $nombre
|
||||
* @return Model\Inmobiliaria\Proveedor
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByNombre(string $nombre): Model\Inmobiliaria\Proveedor
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
|
@ -50,6 +50,12 @@ class Login extends Ideal\Repository
|
||||
->where('user_id = ?');
|
||||
return $this->fetchMany($query, [$user_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $user_id
|
||||
* @return Model\Login
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchActiveByUser(int $user_id): Model\Login
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
|
@ -28,6 +28,13 @@ class Persona extends Ideal\Repository
|
||||
[$model->rut, $model->digito, $model->nombres, $model->apellidoPaterno, $model->apellidoMaterno]);
|
||||
return $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Define\Model $model
|
||||
* @param array $new_data
|
||||
* @return Model\Persona
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function edit(Define\Model $model, array $new_data): Model\Persona
|
||||
{
|
||||
return $this->update($model, ['digito', 'nombres', 'apellido_paterno', 'apellido_materno'], $new_data);
|
||||
|
@ -72,6 +72,11 @@ class Datos extends Ideal\Repository
|
||||
], $new_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $persona_rut
|
||||
* @return Model\Persona\Datos
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByPersona(int $persona_rut): Model\Persona\Datos
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
|
@ -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()
|
||||
|
@ -27,11 +27,22 @@ class User extends Ideal\Repository
|
||||
return $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Define\Model $model
|
||||
* @param array $new_data
|
||||
* @return Define\Model
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['name', 'password', 'enabled'], $new_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @return Model\User
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByName(string $name): Model\User
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `name` = ?";
|
||||
|
@ -2,6 +2,7 @@
|
||||
namespace Incoviba\Repository;
|
||||
|
||||
use PDO;
|
||||
use PDOException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
@ -128,6 +129,12 @@ class Venta extends Ideal\Repository
|
||||
}
|
||||
return $this->parseData(new Model\Venta(), $data, $map);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Define\Model $model
|
||||
* @return Model\Venta
|
||||
* @throws PDOException
|
||||
*/
|
||||
public function save(Define\Model $model): Model\Venta
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
@ -142,6 +149,13 @@ class Venta extends Ideal\Repository
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Define\Model $model
|
||||
* @param array $new_data
|
||||
* @return Model\Venta
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function edit(Define\Model $model, array $new_data): Model\Venta
|
||||
{
|
||||
return $this->update($model, ['propietario', 'propiedad', 'pie', 'bono_pie', 'credito', 'escritura', 'subsidio', 'escriturado',
|
||||
@ -149,6 +163,11 @@ class Venta extends Ideal\Repository
|
||||
'relacionado', 'promocion', 'resciliacion', 'devolucion'], $new_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $proyecto_id
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByProyecto(int $proyecto_id): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -163,6 +182,12 @@ class Venta extends Ideal\Repository
|
||||
->group('a.id');
|
||||
return $this->fetchMany($query, [$proyecto_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $proyecto_id
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchIdsByProyecto(int $proyecto_id): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -177,6 +202,12 @@ class Venta extends Ideal\Repository
|
||||
->group('a.id');
|
||||
return $this->fetchIds($query, [$proyecto_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $proyecto_id
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchActivaByProyecto(int $proyecto_id): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -191,6 +222,13 @@ class Venta extends Ideal\Repository
|
||||
->group('a.id');
|
||||
return $this->fetchMany($query, [$proyecto_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $proyecto_nombre
|
||||
* @param int $unidad_descripcion
|
||||
* @return Model\Venta
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByProyectoAndUnidad(string $proyecto_nombre, int $unidad_descripcion): Model\Venta
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -205,6 +243,12 @@ class Venta extends Ideal\Repository
|
||||
->where('`proyecto`.`descripcion` = ? AND `unidad`.`descripcion` = ? AND tev.`activa`');
|
||||
return $this->fetchOne($query, [$proyecto_nombre, $unidad_descripcion]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $pie_id
|
||||
* @return Model\Venta
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByPie(int $pie_id): Model\Venta
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -213,6 +257,12 @@ class Venta extends Ideal\Repository
|
||||
->where('pie = ?');
|
||||
return $this->fetchOne($query, [$pie_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $pie_id
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchIdByPie(int $pie_id): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -221,6 +271,13 @@ class Venta extends Ideal\Repository
|
||||
->where('pie = ?');
|
||||
return $this->fetchId($query, [$pie_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $unidad
|
||||
* @param string $tipo
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByUnidad(string $unidad, string $tipo): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -233,6 +290,12 @@ class Venta extends Ideal\Repository
|
||||
->where('`unidad`.`descripcion` LIKE ? AND tu.`descripcion` = ?');
|
||||
return $this->fetchMany($query, [$unidad, $tipo]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $unidad_id
|
||||
* @return Model\Venta
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByUnidadId(int $unidad_id): Model\Venta
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -242,6 +305,13 @@ class Venta extends Ideal\Repository
|
||||
->where('pu.unidad = ?');
|
||||
return $this->fetchOne($query, [$unidad_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $unidad
|
||||
* @param string $tipo
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchIdsByUnidad(string $unidad, string $tipo): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -254,6 +324,12 @@ class Venta extends Ideal\Repository
|
||||
->where('`unidad`.`descripcion` LIKE ? AND tu.`descripcion` = ?');
|
||||
return $this->fetchIds($query, [$unidad, $tipo]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $precio
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByPrecio(string $precio): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -262,6 +338,12 @@ class Venta extends Ideal\Repository
|
||||
->where('valor_uf = ?');
|
||||
return $this->fetchMany($query, [$precio]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $precio
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchIdsByPrecio(string $precio): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -270,6 +352,13 @@ class Venta extends Ideal\Repository
|
||||
->where('valor_uf = ?');
|
||||
return $this->fetchIds($query, [$precio]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $propietario_rut
|
||||
* @param int $propiedad_id
|
||||
* @return Model\Venta
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByPropietarioAndPropiedad(int $propietario_rut, int $propiedad_id): Model\Venta
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -278,6 +367,12 @@ class Venta extends Ideal\Repository
|
||||
->where('propietario = ? AND propiedad = ?');
|
||||
return $this->fetchOne($query, [$propietario_rut, $propiedad_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $propietario
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByPropietario(string $propietario): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -289,6 +384,12 @@ class Venta extends Ideal\Repository
|
||||
OR CONCAT_WS(' ', `propietario`.`nombres`, `propietario`.`apellido_paterno`, `propietario`.`apellido_materno`) LIKE :propietario");
|
||||
return $this->fetchMany($query, [':propietario' => "%{$propietario}%"]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $propietario
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchIdsByPropietario(string $propietario): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -302,6 +403,12 @@ class Venta extends Ideal\Repository
|
||||
OR CONCAT_WS('-', rut, dv) = :rut");
|
||||
return $this->fetchIds($query, [':propietario' => "%{$propietario}%", ':rut' => $propietario]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $propietario
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByPropietarioNombreCompleto(string $propietario): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -311,6 +418,12 @@ class Venta extends Ideal\Repository
|
||||
->where("CONCAT_WS(' ', `propietario`.`nombres`, `propietario`.`apellido_paterno`, `propietario`.`apellido_materno`) LIKE ?");
|
||||
return $this->fetchMany($query, [$propietario]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $proyecto_id
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchEscriturasByProyecto(int $proyecto_id): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -325,6 +438,12 @@ class Venta extends Ideal\Repository
|
||||
->group('a.id');
|
||||
return $this->fetchMany($query, [$proyecto_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $escritura_id
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchIdByEscritura(int $escritura_id): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -333,6 +452,12 @@ class Venta extends Ideal\Repository
|
||||
->where('escritura = ?');
|
||||
return $this->fetchId($query, [$escritura_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $subsidio_id
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchIdBySubsidio(int $subsidio_id): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -341,6 +466,12 @@ class Venta extends Ideal\Repository
|
||||
->where('subsidio = ?');
|
||||
return $this->fetchId($query, [$subsidio_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $credito_id
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchIdByCredito(int $credito_id): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -349,6 +480,12 @@ class Venta extends Ideal\Repository
|
||||
->where('credito = ?');
|
||||
return $this->fetchId($query, [$credito_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $bono_id
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchIdByBono(int $bono_id): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -357,6 +494,11 @@ class Venta extends Ideal\Repository
|
||||
->where('bono_pie = ?');
|
||||
return $this->fetchId($query, [$bono_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $venta_id
|
||||
* @return array
|
||||
*/
|
||||
public function fetchByIdForSearch(int $venta_id): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -382,6 +524,11 @@ class Venta extends Ideal\Repository
|
||||
->limit(1);
|
||||
return $this->connection->execute($query, [$venta_id])->fetch(PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $venta_id
|
||||
* @return array
|
||||
*/
|
||||
public function fetchByIdForList(int $venta_id): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -404,20 +551,33 @@ class Venta extends Ideal\Repository
|
||||
return $this->connection->execute($query, [$venta_id])->fetch(PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $query
|
||||
* @param array|null $data
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
protected function fetchIds(string $query, ?array $data = null): array
|
||||
{
|
||||
$results = $this->connection->execute($query, $data)->fetchAll(PDO::FETCH_ASSOC);
|
||||
if ($results === false) {
|
||||
throw new Implement\Exception\EmptyResult($query);
|
||||
try {
|
||||
return $this->connection->execute($query, $data)->fetchAll(PDO::FETCH_ASSOC);
|
||||
} catch (PDOException $exception) {
|
||||
throw new Implement\Exception\EmptyResult($query, $exception);
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $query
|
||||
* @param array|null $data
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
protected function fetchId(string $query, ?array $data = null): array
|
||||
{
|
||||
$results = $this->connection->execute($query, $data)->fetch(PDO::FETCH_ASSOC);
|
||||
if ($results === false) {
|
||||
throw new Implement\Exception\EmptyResult($query);
|
||||
try {
|
||||
return $this->connection->execute($query, $data)->fetch(PDO::FETCH_ASSOC);
|
||||
} catch (PDOException $exception) {
|
||||
throw new Implement\Exception\EmptyResult($query, $exception);
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
}
|
||||
|
@ -31,11 +31,23 @@ class BonoPie extends Ideal\Repository
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Define\Model $model
|
||||
* @param array $new_data
|
||||
* @return Define\Model
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['valor', 'pago'], $new_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $value
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByValue(float $value): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -44,6 +56,12 @@ class BonoPie extends Ideal\Repository
|
||||
->where('valor = ?');
|
||||
return $this->fetchMany($query, [$value]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $pago_id
|
||||
* @return Model\Venta\BonoPie
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByPago(int $pago_id): Model\Venta\BonoPie
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -52,6 +70,12 @@ class BonoPie extends Ideal\Repository
|
||||
->where('pago = ?');
|
||||
return $this->fetchOne($query, [$pago_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $venta_id
|
||||
* @return Model\Venta\BonoPie
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByVenta(int $venta_id): Model\Venta\BonoPie
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
|
@ -37,6 +37,11 @@ class Credito extends Ideal\Repository
|
||||
return $this->update($model, ['banco', 'valor', 'fecha', 'uf', 'abonado', 'fecha_abono', 'pago'], $new_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $value
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByValue(int $value): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -53,6 +58,12 @@ class Credito extends Ideal\Repository
|
||||
->where('pago = ?');
|
||||
return $this->fetchOne($query, [$pago_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $venta_id
|
||||
* @return Model\Venta\Credito
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByVenta(int $venta_id): Model\Venta\Credito
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
|
@ -198,6 +198,12 @@ GROUP BY p1.`fecha`, v1.`descripcion`
|
||||
ORDER BY p1.`fecha`, v1.`descripcion`";
|
||||
return $this->fetchAsArray($query);*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $pie_id
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByPie(int $pie_id): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
|
@ -39,6 +39,11 @@ class Escritura extends Ideal\Repository
|
||||
return $this->update($model, ['valor', 'fecha', 'uf', 'abonado', 'fecha_abono', 'pago'], $new_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $value
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByValue(int $value): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -55,6 +60,12 @@ class Escritura extends Ideal\Repository
|
||||
->where('pago = ?');
|
||||
return $this->fetchOne($query, [$pago_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $venta_id
|
||||
* @return Model\Venta\Escritura
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByVenta(int $venta_id): Model\Venta\Escritura
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
|
@ -100,6 +100,12 @@ FROM (
|
||||
WHERE venta_id = ?";
|
||||
return $this->fetchMany($query, [$venta_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $value
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByValue(int $value): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -108,6 +114,12 @@ WHERE venta_id = ?";
|
||||
->where('valor = ? OR ROUND(valor/uf, 3) = ?');
|
||||
return $this->fetchMany($query, [$value, $value]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $venta_id
|
||||
* @return Model\Venta\Pago
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchDevolucionByVenta(int $venta_id): Model\Venta\Pago
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
|
@ -48,6 +48,11 @@ class Pie extends Ideal\Repository
|
||||
return $this->update($model, ['fecha', 'valor', 'uf', 'cuotas', 'asociado', 'reajuste'], $new_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $pie_id
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchAsociados(int $pie_id): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -56,6 +61,12 @@ class Pie extends Ideal\Repository
|
||||
->where('asociado = ?');
|
||||
return $this->fetchMany($query, [$pie_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $value
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByValue(float $value): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -72,6 +83,12 @@ class Pie extends Ideal\Repository
|
||||
->where('reajuste = ?');
|
||||
return $this->fetchOne($query, [$reajuste_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $venta_id
|
||||
* @return Model\Venta\Pie
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByVenta(int $venta_id): Model\Venta\Pie
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
|
@ -32,11 +32,23 @@ class Precio extends Ideal\Repository
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Define\Model $model
|
||||
* @param array $new_data
|
||||
* @return Define\Model
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['unidad', 'valor'], $new_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $proyecto_id
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByProyecto(int $proyecto_id): array
|
||||
{
|
||||
$query = "SELECT a.*
|
||||
@ -50,6 +62,12 @@ WHERE ptu.`proyecto` = ? AND tep.`descripcion` = 'vigente'
|
||||
ORDER BY tu.`orden`, ptu.`nombre`, `unidad`.`subtipo`, LPAD(`unidad`.`descripcion`, 4, '0')";
|
||||
return $this->fetchMany($query, [$proyecto_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $unidad_id
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByUnidad(int $unidad_id): array
|
||||
{
|
||||
$query = "SELECT a.*
|
||||
@ -59,6 +77,12 @@ FROM `{$this->getTable()}` a
|
||||
WHERE `unidad` = ?";
|
||||
return $this->fetchMany($query, [$unidad_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $unidad_id
|
||||
* @return Define\Model
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchVigenteByUnidad(int $unidad_id): Define\Model
|
||||
{
|
||||
$query = "SELECT a.*
|
||||
@ -68,6 +92,13 @@ FROM `{$this->getTable()}` a
|
||||
WHERE `unidad` = ? AND tep.`descripcion` = 'vigente'";
|
||||
return $this->fetchOne($query, [$unidad_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $unidad_id
|
||||
* @param string $date_time
|
||||
* @return Define\Model
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByUnidadAndDate(int $unidad_id, string $date_time): Define\Model
|
||||
{
|
||||
$query = "SELECT a.*
|
||||
|
@ -48,11 +48,23 @@ class Propiedad extends Ideal\Repository
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Define\Model $model
|
||||
* @param array $new_data
|
||||
* @return Model\Venta\Propiedad
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function edit(Define\Model $model, array $new_data): Model\Venta\Propiedad
|
||||
{
|
||||
return $this->update($model, ['unidad_principal', 'estacionamientos', 'bodegas', 'estado'], $new_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $unidad_id
|
||||
* @return Model\Venta\Propiedad
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchVigenteByUnidad(int $unidad_id): Model\Venta\Propiedad
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `unidad_principal` = ?";
|
||||
|
@ -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)) {
|
||||
|
@ -49,6 +49,12 @@ class Subsidio extends Ideal\Repository
|
||||
->where('subsidio = ? OR pago = ?');
|
||||
return $this->fetchOne($query, [$pago_id, $pago_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $venta_id
|
||||
* @return Model\Venta\Subsidio
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByVenta(int $venta_id): Model\Venta\Subsidio
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
|
@ -33,6 +33,11 @@ class TipoEstadoVenta extends Ideal\Repository
|
||||
return $this->update($model, ['descripcion', 'activa'], $new_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $descripcion
|
||||
* @return Model\Venta\TipoEstadoVenta
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByDescripcion(string $descripcion): Model\Venta\TipoEstadoVenta
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `descripcion` = ?";
|
||||
|
@ -129,6 +129,13 @@ class Unidad extends Ideal\Repository
|
||||
->where("a.`descripcion` LIKE ? AND tu.`descripcion` = ? AND (pu.`id` IS NULL OR `venta`.`id` IS NULL OR tev.`activa` = 0)");
|
||||
return $this->fetchMany($query, [$descripcion, $tipo]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $descripcion
|
||||
* @param string $tipo
|
||||
* @return array
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchDisponiblesIdsByDescripcionAndTipo(string $descripcion, string $tipo): array
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
@ -141,7 +148,11 @@ class Unidad extends Ideal\Repository
|
||||
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`
|
||||
LEFT OUTER JOIN `tipo_estado_venta` tev ON tev.`id` = ev.`estado`")
|
||||
->where("a.`descripcion` LIKE ? AND tu.`descripcion` = ? AND (pu.`id` IS NULL OR `venta`.`id` IS NULL OR tev.`activa` = 0)");
|
||||
return $this->connection->execute($query, [$descripcion, $tipo])->fetchAll(PDO::FETCH_ASSOC);
|
||||
try {
|
||||
return $this->connection->execute($query, [$descripcion, $tipo])->fetchAll(PDO::FETCH_ASSOC);
|
||||
} catch (PDOException $exception) {
|
||||
throw new Implement\Exception\EmptyResult($query, $exception);
|
||||
}
|
||||
}
|
||||
public function fetchByIdForSearch(int $unidad_id): array
|
||||
{
|
||||
|
@ -39,6 +39,11 @@ class Prorrateo extends Ideal\Repository
|
||||
return $this->update($model, ['unidad_id', 'prorrateo'], $new_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $unidad_id
|
||||
* @return Model\Venta\Unidad\Prorrateo
|
||||
* @throws Implement\Exception\EmptyResult
|
||||
*/
|
||||
public function fetchByUnidad(int $unidad_id): Model\Venta\Unidad\Prorrateo
|
||||
{
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Contabilidad;
|
||||
|
||||
use PDOException;
|
||||
use DateTimeImmutable;
|
||||
use DateTimeInterface;
|
||||
use Incoviba\Common\Define\Cartola\Banco;
|
||||
@ -273,12 +274,12 @@ class Cartola extends Service
|
||||
$data['abono'] ?? 0,
|
||||
$data['saldo']
|
||||
);
|
||||
} catch (Exception\EmptyResult $exception) {
|
||||
} catch (Exception\EmptyResult) {
|
||||
$data['cuenta_id'] = $cuenta->id;
|
||||
$movimiento = $this->movimientoRepository->create($data);
|
||||
try {
|
||||
return $this->movimientoRepository->save($movimiento);
|
||||
} catch (\PDOException $exception) {
|
||||
} catch (PDOException $exception) {
|
||||
$this->logger->critical(var_export($data,true));
|
||||
throw $exception;
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ class Mes extends Banco
|
||||
}
|
||||
try {
|
||||
$reader = PhpSpreadsheet\IOFactory::createReader('Xlsx');
|
||||
} catch (PhpSpreadsheet\Reader\Exception $exception) {
|
||||
} catch (PhpSpreadsheet\Reader\Exception) {
|
||||
return false;
|
||||
}
|
||||
$xlsx = $reader->load($filename);
|
||||
|
@ -9,7 +9,7 @@ trait isExcel
|
||||
* @throws PhpSpreadsheet\Exception
|
||||
* @throws PhpSpreadsheet\Calculation\Exception
|
||||
*/
|
||||
protected function findTitlesRow(PhpSpreadsheet\Worksheet\RowIterator &$rowIterator, string $firstTitle, int $columnOffset = 1, bool $caseInsensitive = false): ?PhpSpreadsheet\Worksheet\Row
|
||||
protected function findTitlesRow(PhpSpreadsheet\Worksheet\RowIterator $rowIterator, string $firstTitle, int $columnOffset = 1, bool $caseInsensitive = false): ?PhpSpreadsheet\Worksheet\Row
|
||||
{
|
||||
if ($caseInsensitive) {
|
||||
$firstTitle = strtolower($firstTitle);
|
||||
@ -100,11 +100,6 @@ trait isExcel
|
||||
if ($columnOffset > 1) {
|
||||
$cellIterator->seek($columnOffset);
|
||||
}
|
||||
foreach ($exitValues as $exitValue) {
|
||||
if ($cellIterator->current()->getCalculatedValue() === $exitValue) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return in_array($cellIterator->current()->getCalculatedValue(), $exitValues, true);
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,9 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Contabilidad\Cartola;
|
||||
|
||||
use Incoviba\Common\Ideal\Cartola\Banco;
|
||||
use InvalidArgumentException;
|
||||
use Psr\Http\Message\UploadedFileInterface;
|
||||
use Incoviba\Common\Ideal\Cartola\Banco;
|
||||
|
||||
trait withSubBancos
|
||||
{
|
||||
|
@ -15,8 +15,8 @@ class Semanal extends Ideal\Service
|
||||
protected Repository\Contabilidad\Deposito $depositoRepository,
|
||||
protected Service\Contabilidad\Cartola $cartolaService,
|
||||
protected Service\Contabilidad\Movimiento $movimientoService,
|
||||
protected Service\Contabilidad\Informe\Tesoreria\Excel $excelService,
|
||||
protected Service\Contabilidad\Informe\Tesoreria\PDF $pdfService)
|
||||
protected Service\Contabilidad\Informe\Tesoreria\Input\Excel $excelService,
|
||||
protected Service\Contabilidad\Informe\Tesoreria\Output\PDF $pdfService)
|
||||
{
|
||||
parent::__construct($logger);
|
||||
}
|
||||
@ -31,6 +31,6 @@ class Semanal extends Ideal\Service
|
||||
}
|
||||
return $this->anterior;
|
||||
}
|
||||
public function build(DateTimeInterface $fecha): array
|
||||
{}
|
||||
/*public function build(DateTimeInterface $fecha): array
|
||||
{}*/
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ class SaldosContables extends Ideal\Service
|
||||
'saldo' => $this->getSaldo($dataMovimiento)
|
||||
];
|
||||
try {
|
||||
$movimiento = $this->movimientoRepository->fetchByCuentaAndFechaAndCargoAndAbonoAndSaldo($cuenta->id, $dataMovimiento->fecha, $data['cargo'], $data['abono'], $data['saldo']);
|
||||
$movimiento = $this->movimientoRepository->fetchByCuentaAndFechaAndGlosaAndCargoAndAbonoAndSaldo($cuenta->id, $dataMovimiento->fecha, $data['glosa'], $data['cargo'], $data['abono'], $data['saldo']);
|
||||
} catch (Implement\Exception\EmptyResult) {
|
||||
$movimiento = $this->movimientoRepository->create($data);
|
||||
$movimiento = $this->movimientoRepository->save($movimiento);
|
||||
|
@ -1,7 +1,6 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Contabilidad\Informe\Tesoreria\Input\Excel;
|
||||
|
||||
use stdClass;
|
||||
use PhpOffice\PhpSpreadsheet;
|
||||
|
||||
class DAPyFFMM extends Sheet
|
||||
|
@ -5,6 +5,7 @@ use DateInterval;
|
||||
use DateTimeInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Exception\ServiceAction\Read;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
@ -94,7 +95,7 @@ class Output extends Ideal\Service
|
||||
$dataInmobiliaria->sociedad = $inmobiliaria;
|
||||
try {
|
||||
$cuentas = $this->cuentaService->getAllActiveByInmobiliaria($inmobiliaria->rut);
|
||||
} catch (Implement\Exception\EmptyResult) {
|
||||
} catch (Read) {
|
||||
return $dataInmobiliaria;
|
||||
}
|
||||
foreach ($cuentas as $cuenta) {
|
||||
|
@ -17,7 +17,7 @@ class Movimientos
|
||||
|
||||
const INGRESOS = 'ingresos';
|
||||
const EGRESOS = 'egresos';
|
||||
public function addDap(string $tipo, array $movimientos)
|
||||
public function addDap(string $tipo, array $movimientos): self
|
||||
{
|
||||
foreach ($movimientos as $movimiento) {
|
||||
$this->dap->{$tipo} []= $movimiento;
|
||||
@ -66,11 +66,7 @@ class Movimientos
|
||||
$date = $movimiento->fecha;
|
||||
}
|
||||
if ($movimiento->fecha !== $date) {
|
||||
if ($movimiento->cuenta->inmobiliaria->rut === $sociedad_rut) {
|
||||
$temp []= $movimiento;
|
||||
}
|
||||
$date = $movimiento->fecha;
|
||||
continue;
|
||||
}
|
||||
if ($movimiento->cuenta->inmobiliaria->rut === $sociedad_rut) {
|
||||
$temp []= $movimiento;
|
||||
|
@ -2,6 +2,7 @@
|
||||
namespace Incoviba\Service\Inmobiliaria;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Incoviba\Exception\ServiceAction\Read;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Incoviba\Common\Ideal\Service;
|
||||
use Incoviba\Common\Implement;
|
||||
@ -16,19 +17,37 @@ class Cuenta extends Service
|
||||
parent::__construct($logger);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @throws Read
|
||||
*/
|
||||
public function getAllActive(): array
|
||||
{
|
||||
$cuentas = array_map([$this, 'process'], $this->cuentaRepository->fetchAll());
|
||||
return array_values(array_filter($cuentas, function(Model\Inmobiliaria\Cuenta $cuenta) {
|
||||
return $cuenta->currentEstado()->active;
|
||||
}));
|
||||
try {
|
||||
$cuentas = array_map([$this, 'process'], $this->cuentaRepository->fetchAll());
|
||||
return array_values(array_filter($cuentas, function(Model\Inmobiliaria\Cuenta $cuenta) {
|
||||
return $cuenta->currentEstado()->active;
|
||||
}));
|
||||
} catch (Implement\Exception\EmptyResult $exception) {
|
||||
throw new Read(__CLASS__, $exception);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $inmobiliaria_rut
|
||||
* @return array
|
||||
* @throws Read
|
||||
*/
|
||||
public function getAllActiveByInmobiliaria(int $inmobiliaria_rut): array
|
||||
{
|
||||
$cuentas = array_map([$this, 'process'], $this->cuentaRepository->fetchByInmobiliaria($inmobiliaria_rut));
|
||||
return array_values(array_filter($cuentas, function(Model\Inmobiliaria\Cuenta $cuenta) {
|
||||
return $cuenta->currentEstado()->active;
|
||||
}));
|
||||
try {
|
||||
$cuentas = array_map([$this, 'process'], $this->cuentaRepository->fetchByInmobiliaria($inmobiliaria_rut));
|
||||
return array_values(array_filter($cuentas, function(Model\Inmobiliaria\Cuenta $cuenta) {
|
||||
return $cuenta->currentEstado()->active;
|
||||
}));
|
||||
} catch (Implement\Exception\EmptyResult $exception) {
|
||||
throw new Read(__CLASS__, $exception);
|
||||
}
|
||||
}
|
||||
public function add(array $data): Model\Inmobiliaria\Cuenta
|
||||
{
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Inmobiliaria;
|
||||
|
||||
use Incoviba\Exception\ServiceAction\Read;
|
||||
use PDOException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
@ -73,7 +74,7 @@ class Proveedor extends Ideal\Service
|
||||
}
|
||||
$filteredData = $this->proveedorRepository->filterData($data);
|
||||
return $this->process($this->proveedorRepository->edit($proveedor, $filteredData));
|
||||
} catch (Implement\Exception\EmptyResult) {
|
||||
} catch (Read | Implement\Exception\EmptyResult) {
|
||||
return $proveedor;
|
||||
}
|
||||
}
|
||||
@ -82,7 +83,7 @@ class Proveedor extends Ideal\Service
|
||||
try {
|
||||
$this->proveedorRepository->remove($proveedor);
|
||||
return true;
|
||||
} catch (Implement\Exception\EmptyResult | PDOException) {
|
||||
} catch (PDOException) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -192,7 +192,7 @@ class Login
|
||||
protected function cryptoJs_aes_decrypt($data, $key): string
|
||||
{
|
||||
$data = base64_decode($data);
|
||||
if (substr($data, 0, 8) != "Salted__") {
|
||||
if (!str_starts_with($data, "Salted__")) {
|
||||
return false;
|
||||
}
|
||||
$salt = substr($data, 8, 8);
|
||||
|
@ -3,6 +3,7 @@ namespace Incoviba\Service;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Exception\ServiceAction\Read;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
use Psr\Log\LoggerInterface;
|
||||
@ -17,9 +18,18 @@ class Persona extends Ideal\Service
|
||||
parent::__construct($logger);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $rut
|
||||
* @return Model\Persona
|
||||
* @throws Read
|
||||
*/
|
||||
public function getById(int $rut): Model\Persona
|
||||
{
|
||||
return $this->process($this->personaRepository->fetchById($rut));
|
||||
try {
|
||||
return $this->process($this->personaRepository->fetchById($rut));
|
||||
} catch (Implement\Exception\EmptyResult $exception) {
|
||||
throw new Read(__CLASS__, $exception);
|
||||
}
|
||||
}
|
||||
public function add(array $data): Model\Persona
|
||||
{
|
||||
|
@ -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 {
|
||||
|
133
app/src/Service/Proyecto/Broker/Contract.php
Normal file
133
app/src/Service/Proyecto/Broker/Contract.php
Normal file
@ -0,0 +1,133 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Proyecto\Broker;
|
||||
|
||||
use DateTimeInterface;
|
||||
use DateTimeImmutable;
|
||||
use DateMalformedStringException;
|
||||
use PDOException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Exception\ServiceAction;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Contract extends Ideal\Service
|
||||
{
|
||||
public function __construct(LoggerInterface $logger,
|
||||
protected Repository\Proyecto\Broker\Contract $contractRepository,
|
||||
protected Repository\Proyecto\Broker\Contract\State $stateRepository)
|
||||
{
|
||||
parent::__construct($logger);
|
||||
}
|
||||
|
||||
public function getAll(): array
|
||||
{
|
||||
try {
|
||||
return array_map([$this, 'process'], $this->contractRepository->fetchAll());
|
||||
} catch (Implement\Exception\EmptyResult) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
public function getByBroker(int $broker_rut): array
|
||||
{
|
||||
try {
|
||||
return array_map([$this, 'broker'], $this->contractRepository->fetchByBroker($broker_rut));
|
||||
} catch (Implement\Exception\EmptyResult $exception) {
|
||||
throw new ServiceAction\Read(__CLASS__, $exception);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ServiceAction\Read
|
||||
*/
|
||||
public function getById(int $id): Model\Proyecto\Broker\Contract
|
||||
{
|
||||
try {
|
||||
return $this->process($this->contractRepository->fetchById($id));
|
||||
} catch (Implement\Exception\EmptyResult $exception) {
|
||||
throw new ServiceAction\Read(__CLASS__, $exception);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ServiceAction\Create
|
||||
*/
|
||||
public function add(array $data): Model\Proyecto\Broker\Contract
|
||||
{
|
||||
try {
|
||||
return $this->process($this->contractRepository->fetchActiveByProjectAndBroker($data['proyecto_id'], $data['broker_rut']));
|
||||
} catch (Implement\Exception\EmptyResult) {}
|
||||
|
||||
try {
|
||||
$filteredData = $this->contractRepository->filterData($data);
|
||||
$contract = $this->contractRepository->create($filteredData);
|
||||
$contract = $this->contractRepository->save($contract);
|
||||
$type = Model\Proyecto\Broker\Contract\State\Type::ACTIVE;
|
||||
$date = new DateTimeImmutable();
|
||||
if (isset($data['date'])) {
|
||||
try {
|
||||
$date = new DateTimeImmutable($data['date']);
|
||||
} catch (DateMalformedStringException) {}
|
||||
}
|
||||
$state = $this->stateRepository->create(['contract_id' => $contract->id, 'date' => $date, 'type' => $type]);
|
||||
$this->stateRepository->save($state);
|
||||
return $this->process($contract);
|
||||
} catch (PDOException $exception) {
|
||||
throw new ServiceAction\Create(__CLASS__, $exception);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ServiceAction\Update
|
||||
*/
|
||||
public function edit(Model\Proyecto\Broker\Contract $contract, array $data): Model\Proyecto\Broker\Contract
|
||||
{
|
||||
try {
|
||||
$filteredData = $this->contractRepository->filterData($data);
|
||||
return $this->process($this->contractRepository->edit($contract, $filteredData));
|
||||
} catch (PDOException | Implement\Exception\EmptyResult) {
|
||||
throw new ServiceAction\Update(__CLASS__);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ServiceAction\Delete
|
||||
*/
|
||||
public function delete(int $id): Model\Proyecto\Broker\Contract
|
||||
{
|
||||
try {
|
||||
$contract = $this->contractRepository->fetchById($id);
|
||||
$this->contractRepository->remove($contract->id);
|
||||
return $contract;
|
||||
} catch (PDOException | Implement\Exception\EmptyResult $exception) {
|
||||
throw new ServiceAction\Delete(__CLASS__, $exception);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ServiceAction\Update
|
||||
*/
|
||||
public function inactive(Model\Proyecto\Broker\Contract $contract, DateTimeInterface $date = new DateTimeImmutable()): Model\Proyecto\Broker\Contract
|
||||
{
|
||||
try {
|
||||
$type = Model\Proyecto\Broker\Contract\State\Type::INACTIVE;
|
||||
$state = $this->stateRepository->create(['contract_id' => $contract->id, 'date' => $date, 'type' => $type]);
|
||||
$this->stateRepository->save($state);
|
||||
return $this->process($contract);
|
||||
} catch (PDOException $exception) {
|
||||
throw new ServiceAction\Update(__CLASS__, $exception);
|
||||
}
|
||||
}
|
||||
|
||||
protected function process(Model\Proyecto\Broker\Contract $contract): Model\Proyecto\Broker\Contract
|
||||
{
|
||||
$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;
|
||||
}
|
||||
}
|
@ -36,7 +36,7 @@ class Terreno extends Ideal\Service
|
||||
return $proyecto->terreno;
|
||||
}
|
||||
try {
|
||||
// Valor 1o Enero
|
||||
// Valor 1o enero
|
||||
return $this->getValorContable($proyecto, $lastNovember->add(new DateInterval('P1M'))->add(new DateInterval('P1D')));
|
||||
} catch (Implement\Exception\EmptyResponse) {}
|
||||
if ($proyecto->terreno->fecha === null) {
|
||||
|
@ -9,7 +9,12 @@ class Redis
|
||||
{
|
||||
public function __construct(protected ClientInterface $client) {}
|
||||
|
||||
public function get(string $name): mixed
|
||||
/**
|
||||
* @param string $name
|
||||
* @return string|null
|
||||
* @throws EmptyRedis
|
||||
*/
|
||||
public function get(string $name): ?string
|
||||
{
|
||||
try {
|
||||
if (!$this->client->exists($name)) {
|
||||
|
@ -2,7 +2,6 @@
|
||||
namespace Incoviba\Service;
|
||||
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResponse;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
@ -102,7 +101,7 @@ class Search
|
||||
{
|
||||
try {
|
||||
return $this->unidadRepository->fetchDisponiblesIdsByDescripcionAndTipo($query, $tipo);
|
||||
} catch (EmptyResponse) {
|
||||
} catch (EmptyResult) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace Incoviba\Service;
|
||||
|
||||
use PDOException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Repository;
|
||||
@ -39,7 +40,7 @@ class Sociedad extends Ideal\Service
|
||||
} catch (EmptyResult) {
|
||||
try {
|
||||
return $this->process($this->sociedadRepository->save($this->sociedadRepository->create($data)));
|
||||
} catch (EmptyResult) {
|
||||
} catch (PDOException) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ namespace Incoviba\Service;
|
||||
|
||||
use Exception;
|
||||
use DateTimeImmutable;
|
||||
use DateInterval;
|
||||
use DateMalformedStringException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Incoviba\Common\Ideal\Service;
|
||||
use Incoviba\Common\Implement;
|
||||
@ -98,7 +98,7 @@ class Venta extends Service
|
||||
public function getFacturacionById(int $venta_id): array
|
||||
{
|
||||
$venta = $this->getById($venta_id);
|
||||
$escritura = (in_array($venta->currentEstado()->tipoEstadoVenta->descripcion, ['escriturando'])) ? $venta->currentEstado()->fecha : $venta->fecha;
|
||||
$escritura = (in_array($venta->currentEstado()->tipoEstadoVenta->descripcion, ['escriturando', 'firmado por inmobiliaria'])) ? $venta->currentEstado()->fecha : $venta->fecha;
|
||||
$data = [
|
||||
'id' => $venta->id,
|
||||
'fecha' => $venta->fecha->format('Y-m-d'),
|
||||
@ -289,7 +289,7 @@ class Venta extends Service
|
||||
{
|
||||
try {
|
||||
$fecha = new DateTimeImmutable($data['fecha']);
|
||||
} catch (\DateMalformedStringException) {
|
||||
} catch (DateMalformedStringException) {
|
||||
$fecha = new DateTimeImmutable();
|
||||
}
|
||||
$estadoData = [
|
||||
@ -348,7 +348,7 @@ class Venta extends Service
|
||||
{
|
||||
try {
|
||||
$fecha = new DateTimeImmutable($data['fecha_reajuste']);
|
||||
} catch (\DateMalformedStringException) {
|
||||
} catch (DateMalformedStringException) {
|
||||
$fecha = new DateTimeImmutable();
|
||||
}
|
||||
$reajusteData = [
|
||||
@ -363,7 +363,7 @@ class Venta extends Service
|
||||
{
|
||||
try {
|
||||
$fecha = new DateTimeImmutable($data['fecha_pago']);
|
||||
} catch (\DateMalformedStringException) {
|
||||
} catch (DateMalformedStringException) {
|
||||
$fecha = new DateTimeImmutable();
|
||||
}
|
||||
$uf = $this->moneyService->getUF($fecha);
|
||||
@ -389,7 +389,7 @@ class Venta extends Service
|
||||
{
|
||||
try {
|
||||
$fecha = new DateTimeImmutable($data['fecha']);
|
||||
} catch (\DateMalformedStringException) {
|
||||
} catch (DateMalformedStringException) {
|
||||
$fecha = new DateTimeImmutable();
|
||||
}
|
||||
$uf = $this->moneyService->getUF($fecha);
|
||||
@ -399,15 +399,15 @@ class Venta extends Service
|
||||
'subsidio' => $this->valorService->clean($data['valor_subsidio']),
|
||||
'uf' => $uf
|
||||
];
|
||||
$subsidio = $this->addSubsidio($subsidioData);
|
||||
$this->ventaRepository->edit($venta, ['subsidio' => $subsidio->id]);
|
||||
$formaPago = $this->addFormaPago($subsidioData);
|
||||
$this->ventaRepository->edit($venta, ['subsidio' => $formaPago->subsidio->id]);
|
||||
}
|
||||
|
||||
protected function editCredito(Model\Venta $venta, array $data): void
|
||||
{
|
||||
try {
|
||||
$fecha = new DateTimeImmutable($data['fecha']);
|
||||
} catch (\DateMalformedStringException) {
|
||||
} catch (DateMalformedStringException) {
|
||||
$fecha = new DateTimeImmutable();
|
||||
}
|
||||
$uf = $this->moneyService->getUF($fecha);
|
||||
|
@ -2,6 +2,7 @@
|
||||
namespace Incoviba\Service\Venta;
|
||||
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Exception\ServiceAction\Read;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
use Psr\Log\LoggerInterface;
|
||||
@ -27,8 +28,18 @@ class BonoPie
|
||||
}
|
||||
return $bono;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $venta_id
|
||||
* @return Model\Venta\BonoPie
|
||||
* @throws Read
|
||||
*/
|
||||
public function getByVenta(int $venta_id): Model\Venta\BonoPie
|
||||
{
|
||||
return $this->bonoPieRepository->fetchByVenta($venta_id);
|
||||
try {
|
||||
return $this->bonoPieRepository->fetchByVenta($venta_id);
|
||||
} catch (EmptyResult $exception) {
|
||||
throw new Read(__CLASS__, $exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ class Cierre
|
||||
public function getByProyecto(int $proyecto_id): array
|
||||
{
|
||||
$cierres = $this->cierreRepository->fetchByProyecto($proyecto_id);
|
||||
foreach ($cierres as &$cierre) {
|
||||
foreach ($cierres as $cierre) {
|
||||
$cierre->estados = $this->estadoCierreRepository->fetchByCierre($cierre->id);
|
||||
$cierre->current = $this->estadoCierreRepository->fetchCurrentByCierre($cierre->id);
|
||||
$cierre->unidades = $this->unidadRepository->fetchByCierre($cierre->id);
|
||||
@ -30,7 +30,7 @@ class Cierre
|
||||
$cierre->estados = $this->estadoCierreRepository->fetchByCierre($cierre_id);
|
||||
$cierre->current = $this->estadoCierreRepository->fetchCurrentByCierre($cierre_id);
|
||||
$cierre->unidades = $this->unidadRepository->fetchByCierre($cierre_id);
|
||||
foreach ($cierre->unidades as &$unidad) {
|
||||
foreach ($cierre->unidades as $unidad) {
|
||||
$unidad->currentPrecio = $this->precioRepository->fetchByUnidadAndDate($unidad->id, $cierre->dateTime->format('Y-m-d'));
|
||||
}
|
||||
$cierre->valoresCierre = $this->valorCierreRepository->fetchByCierre($cierre_id);
|
||||
|
@ -3,6 +3,8 @@ namespace Incoviba\Service\Venta;
|
||||
|
||||
use Exception;
|
||||
use DateTimeImmutable;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Exception\ServiceAction\Read;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Repository;
|
||||
@ -24,9 +26,18 @@ class Credito extends Ideal\Service
|
||||
parent::__construct($logger);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $venta_id
|
||||
* @return Model\Venta\Credito
|
||||
* @throws Read
|
||||
*/
|
||||
public function getByVenta(int $venta_id): Model\Venta\Credito
|
||||
{
|
||||
return $this->creditoRepository->fetchByVenta($venta_id);
|
||||
try {
|
||||
return $this->creditoRepository->fetchByVenta($venta_id);
|
||||
} catch (EmptyResult $exception) {
|
||||
throw new Read(__CLASS__, $exception);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3,6 +3,7 @@ namespace Incoviba\Service\Venta;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use DateInterval;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use IntlDateFormatter;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
|
@ -3,6 +3,7 @@ namespace Incoviba\Service\Venta;
|
||||
|
||||
use Exception;
|
||||
use DateTimeImmutable;
|
||||
use DateMalformedStringException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
@ -65,7 +66,7 @@ class Escritura extends Ideal\Service
|
||||
}
|
||||
try {
|
||||
$data['fecha'] = (new DateTimeImmutable($data['fecha']))->format('Y-m-d');
|
||||
} catch (\DateMalformedStringException) {
|
||||
} catch (DateMalformedStringException) {
|
||||
unset($data['fecha']);
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,14 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Venta;
|
||||
|
||||
use Incoviba\Service\Valor;
|
||||
use Error;
|
||||
use Incoviba\Exception\ServiceAction\Read;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service\Valor;
|
||||
|
||||
class FormaPago extends Ideal\Service
|
||||
{
|
||||
@ -28,22 +30,22 @@ class FormaPago extends Ideal\Service
|
||||
$formaPago = new Model\Venta\FormaPago();
|
||||
try {
|
||||
$formaPago->pie = $this->pieService->getByVenta($venta_id);
|
||||
} catch (Implement\Exception\EmptyResult) {}
|
||||
} catch (Read) {}
|
||||
try {
|
||||
$formaPago->bonoPie = $this->bonoPieService->getByVenta($venta_id);
|
||||
} catch (Implement\Exception\EmptyResult) {}
|
||||
} catch (Read) {}
|
||||
try {
|
||||
$formaPago->credito = $this->creditoService->getByVenta($venta_id);
|
||||
} catch (Implement\Exception\EmptyResult) {}
|
||||
} catch (Read) {}
|
||||
try {
|
||||
$formaPago->escritura = $this->escrituraRepository->fetchByVenta($venta_id);
|
||||
} catch (Implement\Exception\EmptyResult) {}
|
||||
try {
|
||||
$formaPago->subsidio = $this->subsidioService->getByVenta($venta_id);
|
||||
} catch (Implement\Exception\EmptyResult) {}
|
||||
} catch (Read) {}
|
||||
try {
|
||||
$formaPago->devolucion = $this->pagoService->getDevolucionByVenta($venta_id);
|
||||
} catch (Implement\Exception\EmptyResult) {}
|
||||
} catch (Read) {}
|
||||
try {
|
||||
$formaPago->cuotasAbono = $this->cuotaRepository->fetchByVenta($venta_id);
|
||||
} catch (Implement\Exception\EmptyResult) {}
|
||||
@ -66,7 +68,7 @@ class FormaPago extends Ideal\Service
|
||||
$method = 'add' . str_replace(' ', '', ucwords(str_replace('_', ' ', $name)));
|
||||
$obj = $this->{$method}($data);
|
||||
$forma_pago->{$name} = $obj;
|
||||
} catch (\Error $error) {
|
||||
} catch (Error $error) {
|
||||
$this->logger->critical($error);
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,10 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Venta;
|
||||
|
||||
use Exception;
|
||||
use DateTimeInterface;
|
||||
use DateTimeImmutable;
|
||||
use DateMalformedStringException;
|
||||
use Incoviba\Exception\ServiceAction\Read;
|
||||
use PDOException;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Repository;
|
||||
@ -112,9 +113,19 @@ class Pago
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $venta_id
|
||||
* @return Model\Venta\Pago
|
||||
* @throws Read
|
||||
*/
|
||||
public function getDevolucionByVenta(int $venta_id): Model\Venta\Pago
|
||||
{
|
||||
return $this->process($this->pagoRepository->fetchDevolucionByVenta($venta_id));
|
||||
try {
|
||||
return $this->process($this->pagoRepository->fetchDevolucionByVenta($venta_id));
|
||||
} catch (EmptyResult $exception) {
|
||||
throw new Read(__CLASS__, $exception);
|
||||
}
|
||||
}
|
||||
|
||||
public function add(array $data): Model\Venta\Pago
|
||||
@ -122,7 +133,7 @@ class Pago
|
||||
if (!isset($data['uf'])) {
|
||||
try {
|
||||
$data['uf'] = $this->ufService->get(new DateTimeImmutable($data['fecha']));
|
||||
} catch (\DateMalformedStringException) {
|
||||
} catch (DateMalformedStringException) {
|
||||
$data['uf'] = 0;
|
||||
}
|
||||
}
|
||||
@ -147,14 +158,14 @@ class Pago
|
||||
if (array_key_exists('fecha', $data)) {
|
||||
try {
|
||||
$data['fecha'] = (new DateTimeImmutable($data['fecha']))->format('Y-m-d');
|
||||
} catch (\DateMalformedStringException) {
|
||||
} catch (DateMalformedStringException) {
|
||||
$data['fecha'] = (new DateTimeImmutable())->format('Y-m-d');
|
||||
}
|
||||
}
|
||||
if (array_key_exists('uf', $data)) {
|
||||
try {
|
||||
$data['uf'] = $this->ufService->get(new DateTimeImmutable($data['fecha']));
|
||||
} catch (\DateMalformedStringException) {
|
||||
} catch (DateMalformedStringException) {
|
||||
$data['uf'] = 0;
|
||||
}
|
||||
}
|
||||
@ -171,7 +182,7 @@ class Pago
|
||||
try {
|
||||
$this->pagoRepository->remove($pago);
|
||||
return true;
|
||||
} catch (EmptyResult|PDOException) {
|
||||
} catch (PDOException) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
namespace Incoviba\Service\Venta;
|
||||
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Common\Implement\Repository\Factory;
|
||||
use Incoviba\Exception\ServiceAction\Read;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
|
||||
@ -20,7 +20,11 @@ class Pie
|
||||
}
|
||||
public function getByVenta(int $venta_id): Model\Venta\Pie
|
||||
{
|
||||
return $this->process($this->pieRepository->fetchByVenta($venta_id));
|
||||
try {
|
||||
return $this->process($this->pieRepository->fetchByVenta($venta_id));
|
||||
} catch (EmptyResult $exception) {
|
||||
throw new Read(__CLASS__, $exception);
|
||||
}
|
||||
}
|
||||
|
||||
public function add(array $data): Model\Venta\Pie
|
||||
|
@ -1,6 +1,8 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Venta;
|
||||
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Exception\ServiceAction\Read;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
|
||||
@ -8,29 +10,58 @@ class Precio
|
||||
{
|
||||
public function __construct(protected Repository\Venta\Precio $precioRepository, protected Repository\Venta\EstadoPrecio $estadoPrecioRepository) {}
|
||||
|
||||
/**
|
||||
* @param int $proyecto_id
|
||||
* @return array
|
||||
* @throws Read
|
||||
*/
|
||||
public function getByProyecto(int $proyecto_id): array
|
||||
{
|
||||
$precios = $this->precioRepository->fetchByProyecto($proyecto_id);
|
||||
foreach ($precios as &$precio) {
|
||||
$precio->estados = $this->estadoPrecioRepository->fetchByPrecio($precio->id);
|
||||
$precio->current = $this->estadoPrecioRepository->fetchCurrentByPrecio($precio->id);
|
||||
try {
|
||||
$precios = $this->precioRepository->fetchByProyecto($proyecto_id);
|
||||
foreach ($precios as $precio) {
|
||||
$precio->estados = $this->estadoPrecioRepository->fetchByPrecio($precio->id);
|
||||
$precio->current = $this->estadoPrecioRepository->fetchCurrentByPrecio($precio->id);
|
||||
}
|
||||
return $precios;
|
||||
} catch (EmptyResult $exception) {
|
||||
throw new Read(__CLASS__, $exception);
|
||||
}
|
||||
return $precios;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $unidad_id
|
||||
* @return Model\Venta\Precio
|
||||
* @throws Read
|
||||
*/
|
||||
public function getVigenteByUnidad(int $unidad_id): Model\Venta\Precio
|
||||
{
|
||||
$precio = $this->precioRepository->fetchVigenteByUnidad($unidad_id);
|
||||
$precio->estados = $this->estadoPrecioRepository->fetchByPrecio($precio->id);
|
||||
$precio->current = $this->estadoPrecioRepository->fetchCurrentByPrecio($precio->id);
|
||||
return $precio;
|
||||
}
|
||||
public function getByUnidad(int $unidad_id): array
|
||||
{
|
||||
$precios = $this->precioRepository->fetchByUnidad($unidad_id);
|
||||
foreach ($precios as &$precio) {
|
||||
try {
|
||||
$precio = $this->precioRepository->fetchVigenteByUnidad($unidad_id);
|
||||
$precio->estados = $this->estadoPrecioRepository->fetchByPrecio($precio->id);
|
||||
$precio->current = $this->estadoPrecioRepository->fetchCurrentByPrecio($precio->id);
|
||||
return $precio;
|
||||
} catch (EmptyResult $exception) {
|
||||
throw new Read(__CLASS__, $exception);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $unidad_id
|
||||
* @return array
|
||||
* @throws Read
|
||||
*/
|
||||
public function getByUnidad(int $unidad_id): array
|
||||
{
|
||||
try {
|
||||
$precios = $this->precioRepository->fetchByUnidad($unidad_id);
|
||||
foreach ($precios as $precio) {
|
||||
$precio->estados = $this->estadoPrecioRepository->fetchByPrecio($precio->id);
|
||||
$precio->current = $this->estadoPrecioRepository->fetchCurrentByPrecio($precio->id);
|
||||
}
|
||||
return $precios;
|
||||
} catch (EmptyResult $exception) {
|
||||
throw new Read(__CLASS__, $exception);
|
||||
}
|
||||
return $precios;
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,8 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Venta;
|
||||
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Exception\ServiceAction\Read;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
use Incoviba\Model;
|
||||
|
||||
class PropiedadUnidad
|
||||
@ -51,10 +50,10 @@ class PropiedadUnidad
|
||||
try {
|
||||
$unidad->precios = $this->precioService->getByUnidad($unidad->id);
|
||||
$unidad->currentPrecio = $this->precioService->getVigenteByUnidad($unidad->id);
|
||||
if ($unidad->valor === 0 or $unidad->valor === null) {
|
||||
if ($unidad->valor === null or $unidad->valor === 0) {
|
||||
$unidad->valor = $unidad->currentPrecio->valor;
|
||||
}
|
||||
} catch (EmptyResult) {}
|
||||
} catch (Read) {}
|
||||
return $unidad;
|
||||
}
|
||||
}
|
||||
|
81
app/src/Service/Venta/Reservation.php
Normal file
81
app/src/Service/Venta/Reservation.php
Normal file
@ -0,0 +1,81 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Venta;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use DateMalformedStringException;
|
||||
use PDOException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Exception\ServiceAction;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Reservation extends Ideal\Service\API
|
||||
{
|
||||
public function __construct(LoggerInterface $logger, protected Repository\Venta\Reservation $reservationRepository)
|
||||
{
|
||||
parent::__construct($logger);
|
||||
}
|
||||
|
||||
public function getAll(null|string|array $order = null): array
|
||||
{
|
||||
try {
|
||||
return $this->reservationRepository->fetchAll($order);
|
||||
} catch (Implement\Exception\EmptyResult) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public function get(int $id): Model\Venta\Reservation
|
||||
{
|
||||
try {
|
||||
return $this->process($this->reservationRepository->fetchById($id));
|
||||
} catch (Implement\Exception\EmptyResult $exception) {
|
||||
throw new ServiceAction\Read(__CLASS__, $exception);
|
||||
}
|
||||
}
|
||||
|
||||
public function add(array $data): Model\Venta\Reservation
|
||||
{
|
||||
try {
|
||||
$date = new DateTimeImmutable();
|
||||
try {
|
||||
$date = new DateTimeImmutable($data['date']);
|
||||
} catch (DateMalformedStringException) {}
|
||||
return $this->process($this->reservationRepository->fetchByBuyerAndDate($data['buyer_rut'], $date));
|
||||
} catch (Implement\Exception\EmptyResult) {}
|
||||
|
||||
try {
|
||||
$reservationData = $this->reservationRepository->filterData($data);
|
||||
$reservation = $this->reservationRepository->create($reservationData);
|
||||
$this->reservationRepository->save($reservation);
|
||||
return $this->process($reservation);
|
||||
} catch (PDOException $exception) {
|
||||
throw new ServiceAction\Create(__CLASS__, $exception);
|
||||
}
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Model\Venta\Reservation
|
||||
{
|
||||
try {
|
||||
return $this->process($this->reservationRepository->edit($model, $new_data));
|
||||
} catch (PDOException | Implement\Exception\EmptyResult $exception) {
|
||||
throw new ServiceAction\Update(__CLASS__, $exception);
|
||||
}
|
||||
}
|
||||
public function delete(int $id): Model\Venta\Reservation
|
||||
{
|
||||
try {
|
||||
$reservation = $this->reservationRepository->fetchById($id);
|
||||
$this->reservationRepository->remove($reservation);
|
||||
return $reservation;
|
||||
} catch (PDOException | Implement\Exception\EmptyResult $exception) {
|
||||
throw new ServiceAction\Delete(__CLASS__, $exception);
|
||||
}
|
||||
}
|
||||
protected function process(Define\Model $model): Model\Venta\Reservation
|
||||
{
|
||||
return $model;
|
||||
}
|
||||
}
|
@ -1,8 +1,10 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Venta;
|
||||
|
||||
use Exception;
|
||||
use DateTimeImmutable;
|
||||
use DateMalformedStringException;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Exception\ServiceAction\Read;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Service;
|
||||
@ -19,17 +21,26 @@ class Subsidio
|
||||
protected Service\Valor $valorService
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @param int $venta_id
|
||||
* @return Model\Venta\Subsidio
|
||||
* @throws Read
|
||||
*/
|
||||
public function getByVenta(int $venta_id): Model\Venta\Subsidio
|
||||
{
|
||||
return $this->subsidioRepository->fetchByVenta($venta_id);
|
||||
try {
|
||||
return $this->subsidioRepository->fetchByVenta($venta_id);
|
||||
} catch (EmptyResult $exception) {
|
||||
throw new Read(__CLASS__, $exception);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function add(array $data): Model\Venta\Subsidio
|
||||
{
|
||||
$fecha = new DateTimeImmutable($data['fecha']);
|
||||
$fecha = new DateTimeImmutable();
|
||||
try {
|
||||
$fecha = new DateTimeImmutable($data['fecha']);
|
||||
} catch (DateMalformedStringException) {}
|
||||
$uf = $data['uf'] ?? $this->moneyService->getUF($fecha);
|
||||
$tipoPago = $this->tipoPagoRepository->fetchByDescripcion('vale vista');
|
||||
$ahorro = $this->pagoService->add(['fecha' => $fecha->format('Y-m-d'), 'valor' => $this->valorService->clean($data['ahorro']) * $uf, 'uf' => $uf, 'tipo' => $tipoPago->id]);
|
||||
|
@ -1,9 +1,10 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Venta;
|
||||
|
||||
use Incoviba\Exception\ServiceAction\Read;
|
||||
use PDOException;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Unidad
|
||||
@ -60,8 +61,7 @@ class Unidad
|
||||
try {
|
||||
$unidad->precios = $this->precioService->getByUnidad($unidad->id);
|
||||
$unidad->currentPrecio = $this->precioService->getVigenteByUnidad($unidad->id);
|
||||
} catch (EmptyResult) {
|
||||
}
|
||||
} catch (Read) {}
|
||||
return $unidad;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user