Integracion Toku a flujo
This commit is contained in:
@ -6,6 +6,7 @@ use Psr\Http\Message\ServerRequestInterface;
|
|||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
use Incoviba\Common\Alias\View;
|
use Incoviba\Common\Alias\View;
|
||||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||||
|
use Incoviba\Exception\ServiceAction\Create;
|
||||||
use Incoviba\Model;
|
use Incoviba\Model;
|
||||||
use Incoviba\Repository;
|
use Incoviba\Repository;
|
||||||
use Incoviba\Service;
|
use Incoviba\Service;
|
||||||
@ -84,13 +85,15 @@ class Cuotas
|
|||||||
return $view->render($response, 'ventas.pies.cuotas.add', compact('pie', 'venta', 'bancos'));
|
return $view->render($response, 'ventas.pies.cuotas.add', compact('pie', 'venta', 'bancos'));
|
||||||
}
|
}
|
||||||
public function doAdd(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pie $pieService,
|
public function doAdd(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pie $pieService,
|
||||||
Repository\Venta $ventaRepository, Service\Valor $valorService, int $pie_id): ResponseInterface
|
Repository\Venta $ventaRepository, Service\Valor $valorService,
|
||||||
|
Service\Queue $queueService, int $pie_id): ResponseInterface
|
||||||
{
|
{
|
||||||
$body = $request->getParsedBody();
|
$body = $request->getParsedBody();
|
||||||
$pie = $pieService->getById($pie_id);
|
$pie = $pieService->getById($pie_id);
|
||||||
$venta = $ventaRepository->fetchByPie($pie_id);
|
$venta = $ventaRepository->fetchByPie($pie_id);
|
||||||
$start = count($pie->cuotas(vigentes: true));
|
$start = count($pie->cuotas(vigentes: true));
|
||||||
$total = $pie->cuotas;
|
$total = $pie->cuotas;
|
||||||
|
$cuotas = [];
|
||||||
for ($i = $start; $i < $total; $i ++) {
|
for ($i = $start; $i < $total; $i ++) {
|
||||||
if ($body["banco{$i}"] === '') {
|
if ($body["banco{$i}"] === '') {
|
||||||
continue;
|
continue;
|
||||||
@ -103,7 +106,17 @@ class Cuotas
|
|||||||
'valor' => $valorService->clean(str_replace('.', '', $body["valor{$i}"])),
|
'valor' => $valorService->clean(str_replace('.', '', $body["valor{$i}"])),
|
||||||
'numero' => $i + 1,
|
'numero' => $i + 1,
|
||||||
];
|
];
|
||||||
$pieService->addCuota($data);
|
try {
|
||||||
|
$cuotas []= $pieService->addCuota($data)->id;
|
||||||
|
} catch (Create) {}
|
||||||
|
}
|
||||||
|
if (count($cuotas) > 0) {
|
||||||
|
$data = [
|
||||||
|
'type' => 'request',
|
||||||
|
'action' => "/api/external/toku/cuotas/{$venta->id}",
|
||||||
|
'body' => compact('cuotas')
|
||||||
|
];
|
||||||
|
$queueService->enqueue($data);
|
||||||
}
|
}
|
||||||
return $response->withHeader('Location', "/venta/{$venta->id}");
|
return $response->withHeader('Location', "/venta/{$venta->id}");
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,11 @@ class TipoPago extends Ideal\Repository
|
|||||||
return $this->update($model, ['descripcion'], $new_data);
|
return $this->update($model, ['descripcion'], $new_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $descripcion
|
||||||
|
* @return Model\Venta\TipoPago
|
||||||
|
* @throws Implement\Exception\EmptyResult
|
||||||
|
*/
|
||||||
public function fetchByDescripcion(string $descripcion): Model\Venta\TipoPago
|
public function fetchByDescripcion(string $descripcion): Model\Venta\TipoPago
|
||||||
{
|
{
|
||||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `descripcion` = ?";
|
$query = "SELECT * FROM `{$this->getTable()}` WHERE `descripcion` = ?";
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Incoviba\Service\Venta;
|
namespace Incoviba\Service\Venta;
|
||||||
|
|
||||||
|
use PDOException;
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
use DateInterval;
|
use DateInterval;
|
||||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
|
||||||
use IntlDateFormatter;
|
use IntlDateFormatter;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Incoviba\Common\Ideal;
|
use Incoviba\Common\Ideal;
|
||||||
|
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||||
|
use Incoviba\Exception\ServiceAction\Create;
|
||||||
use Incoviba\Repository;
|
use Incoviba\Repository;
|
||||||
use Incoviba\Model;
|
use Incoviba\Model;
|
||||||
|
|
||||||
@ -92,9 +94,18 @@ class Cuota extends Ideal\Service
|
|||||||
return $this->cuotaRepository->fetchVigenteByPie($pie_id);
|
return $this->cuotaRepository->fetchVigenteByPie($pie_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $data
|
||||||
|
* @return Model\Venta\Cuota
|
||||||
|
* @throws Create
|
||||||
|
*/
|
||||||
public function add(array $data): Model\Venta\Cuota
|
public function add(array $data): Model\Venta\Cuota
|
||||||
{
|
{
|
||||||
$tipoPago = $this->tipoPagoRepository->fetchByDescripcion('cheque');
|
try {
|
||||||
|
$tipoPago = $this->tipoPagoRepository->fetchByDescripcion('cheque');
|
||||||
|
} catch (EmptyResult $exception) {
|
||||||
|
throw new Create(__CLASS__, $exception);
|
||||||
|
}
|
||||||
$fields = array_flip([
|
$fields = array_flip([
|
||||||
'fecha',
|
'fecha',
|
||||||
'banco',
|
'banco',
|
||||||
@ -112,8 +123,11 @@ class Cuota extends Ideal\Service
|
|||||||
$mapped_data = $filtered_data;
|
$mapped_data = $filtered_data;
|
||||||
$mapped_data['valor_$'] = $mapped_data['valor'];
|
$mapped_data['valor_$'] = $mapped_data['valor'];
|
||||||
unset($mapped_data['valor']);
|
unset($mapped_data['valor']);
|
||||||
$cuota = $this->cuotaRepository->create($mapped_data);
|
try {
|
||||||
$this->cuotaRepository->save($cuota);
|
$cuota = $this->cuotaRepository->create($mapped_data);
|
||||||
return $cuota;
|
return $this->cuotaRepository->save($cuota);
|
||||||
|
} catch (PDOException $exception) {
|
||||||
|
throw new Create(__CLASS__, $exception);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ namespace Incoviba\Service\Venta;
|
|||||||
use DateTimeInterface;
|
use DateTimeInterface;
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
use DateMalformedStringException;
|
use DateMalformedStringException;
|
||||||
|
use Incoviba\Exception\ServiceAction\Create;
|
||||||
use Incoviba\Exception\ServiceAction\Read;
|
use Incoviba\Exception\ServiceAction\Read;
|
||||||
use Incoviba\Exception\ServiceAction\Update;
|
use Incoviba\Exception\ServiceAction\Update;
|
||||||
use PDOException;
|
use PDOException;
|
||||||
@ -129,6 +130,11 @@ class Pago
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $data
|
||||||
|
* @return Model\Venta\Pago
|
||||||
|
* @throws Create
|
||||||
|
*/
|
||||||
public function add(array $data): Model\Venta\Pago
|
public function add(array $data): Model\Venta\Pago
|
||||||
{
|
{
|
||||||
if (array_key_exists('fecha', $data)) {
|
if (array_key_exists('fecha', $data)) {
|
||||||
@ -146,16 +152,24 @@ class Pago
|
|||||||
|
|
||||||
$filtered_data = $this->pagoRepository->filterData($data);
|
$filtered_data = $this->pagoRepository->filterData($data);
|
||||||
|
|
||||||
$pago = $this->pagoRepository->create($filtered_data);
|
try {
|
||||||
$pago = $this->pagoRepository->save($pago);
|
$pago = $this->pagoRepository->create($filtered_data);
|
||||||
|
$pago = $this->pagoRepository->save($pago);
|
||||||
|
} catch (PDOException $exception) {
|
||||||
|
throw new Create(__CLASS__, $exception);
|
||||||
|
}
|
||||||
|
|
||||||
$tipoEstado = $this->tipoEstadoPagoRepository->fetchByDescripcion('no pagado');
|
$tipoEstado = $this->tipoEstadoPagoRepository->fetchByDescripcion('no pagado');
|
||||||
$estado = $this->estadoPagoRepository->create([
|
try {
|
||||||
'pago' => $pago->id,
|
$estado = $this->estadoPagoRepository->create([
|
||||||
'fecha' => $pago->fecha->format('Y-m-d'),
|
'pago' => $pago->id,
|
||||||
'estado' => $tipoEstado->id
|
'fecha' => $pago->fecha->format('Y-m-d'),
|
||||||
]);
|
'estado' => $tipoEstado->id
|
||||||
$estado = $this->estadoPagoRepository->save($estado);
|
]);
|
||||||
|
$estado = $this->estadoPagoRepository->save($estado);
|
||||||
|
} catch (PDOException $exception) {
|
||||||
|
throw new Create(__CLASS__, $exception);
|
||||||
|
}
|
||||||
$pago->currentEstado = $estado;
|
$pago->currentEstado = $estado;
|
||||||
return $pago;
|
return $pago;
|
||||||
}
|
}
|
||||||
|
@ -53,6 +53,12 @@ class Pie
|
|||||||
throw new Create(__CLASS__, $exception);
|
throw new Create(__CLASS__, $exception);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $data
|
||||||
|
* @return Model\Venta\Cuota
|
||||||
|
* @throws Create
|
||||||
|
*/
|
||||||
public function addCuota(array $data): Model\Venta\Cuota
|
public function addCuota(array $data): Model\Venta\Cuota
|
||||||
{
|
{
|
||||||
return $this->cuotaService->add($data);
|
return $this->cuotaService->add($data);
|
||||||
|
Reference in New Issue
Block a user