Editar credito
This commit is contained in:
31
app/src/Controller/API/Ventas/Creditos.php
Normal file
31
app/src/Controller/API/Ventas/Creditos.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\API\Ventas;
|
||||
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Ideal\Controller;
|
||||
use Incoviba\Controller\API\withJson;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Creditos extends Controller
|
||||
{
|
||||
use withJson;
|
||||
|
||||
public function edit(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService,
|
||||
Service\Venta\Credito $creditoService, int $venta_id): ResponseInterface
|
||||
{
|
||||
$body = $request->getParsedBody();
|
||||
$output = [
|
||||
'input' => $body,
|
||||
'credito' => null,
|
||||
'status' => false
|
||||
];
|
||||
try {
|
||||
$venta = $ventaService->getById($venta_id);
|
||||
$output['credito'] = $creditoService->edit($venta->formaPago()->credito, $body);
|
||||
$output['status'] = true;
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
20
app/src/Controller/Ventas/Creditos.php
Normal file
20
app/src/Controller/Ventas/Creditos.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\Ventas;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Incoviba\Common\Alias\View;
|
||||
use Incoviba\Common\Ideal\Controller;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Creditos extends Controller
|
||||
{
|
||||
public function show(ServerRequestInterface $request, ResponseInterface $response, View $view,
|
||||
Repository\Venta $ventaRepository, Repository\Banco $bancoRepository,
|
||||
int $venta_id): ResponseInterface
|
||||
{
|
||||
$venta = $ventaRepository->fetchById($venta_id);
|
||||
$bancos = $bancoRepository->fetchAll('nombre');
|
||||
return $view->render($response, 'ventas.creditos', compact('venta', 'bancos'));
|
||||
}
|
||||
}
|
@ -14,7 +14,7 @@ class Pie extends Model
|
||||
public ?Pie $asociado;
|
||||
public ?Pago $reajuste;
|
||||
|
||||
public array $cuotasArray;
|
||||
public array $cuotasArray = [];
|
||||
public function cuotas(bool $pagadas = false, bool $vigentes = false): array
|
||||
{
|
||||
if ($this->asociado !== null) {
|
||||
|
@ -159,15 +159,6 @@ class Venta extends Ideal\Repository
|
||||
->joined('JOIN tipo_estado_venta tev ON tev.id = ev.estado')
|
||||
->where('ptu.proyecto = ? AND tev.activa')
|
||||
->group('a.id');
|
||||
/*$query = "SELECT a.*
|
||||
FROM `{$this->getTable()}` a
|
||||
JOIN `propiedad_unidad` pu ON pu.`propiedad` = a.`propiedad`
|
||||
JOIN `unidad` ON `unidad`.`id` = pu.`unidad` AND pu.`principal` = 1
|
||||
JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = `unidad`.`pt`
|
||||
JOIN (SELECT e1.* FROM `estado_venta` e1 JOIN (SELECT MAX(`id`) AS 'id', `venta` FROM `estado_venta` GROUP BY `venta`) e0 ON e0.`id` = e1.`id`) ev ON ev.`venta` = a.`id`
|
||||
JOIN `tipo_estado_venta` tev ON tev.`id` = ev.`estado`
|
||||
WHERE ptu.`proyecto` = ? AND tev.`activa`
|
||||
GROUP BY a.`id`";*/
|
||||
return $this->fetchMany($query, [$proyecto_id]);
|
||||
}
|
||||
public function fetchIdsByProyecto(int $proyecto_id): array
|
||||
|
@ -17,7 +17,7 @@ class Credito extends Ideal\Repository
|
||||
|
||||
public function create(?array $data = null): Model\Venta\Credito
|
||||
{
|
||||
$map = (new Implement\Repository\MapperParser())
|
||||
$map = (new Implement\Repository\MapperParser(['valor']))
|
||||
->register('pago', (new Implement\Repository\Mapper())
|
||||
->setFunction(function($data) {
|
||||
return $this->pagoService->getById($data['pago']);
|
||||
|
@ -209,8 +209,8 @@ class Tesoreria extends Ideal\Service
|
||||
'cuenta' => $deposito->cuenta,
|
||||
'fecha' => $deposito->termino,
|
||||
'cargo' => 0,
|
||||
'abono' => $deposito->futuro,
|
||||
'saldo' => $deposito->futuro,
|
||||
'abono' => $deposito->capital,
|
||||
'saldo' => $deposito->capital,
|
||||
'glosa' => 'RESCATE DAP'
|
||||
]]);
|
||||
}
|
||||
|
@ -2,20 +2,25 @@
|
||||
namespace Incoviba\Service\Venta;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Incoviba\Common\Ideal\Service;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Service\Money;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class Credito
|
||||
class Credito extends Service
|
||||
{
|
||||
public function __construct(
|
||||
LoggerInterface $logger,
|
||||
protected Repository\Venta\Credito $creditoRepository,
|
||||
protected Repository\Venta\Pago $pagoRepository,
|
||||
protected Repository\Venta\TipoPago $tipoPagoRepository,
|
||||
protected Repository\Venta\EstadoPago $estadoPagoRepository,
|
||||
protected Repository\Venta\TipoEstadoPago $tipoEstadoPagoRepository,
|
||||
protected Money $moneyService
|
||||
) {}
|
||||
) {
|
||||
parent::__construct($logger);
|
||||
}
|
||||
|
||||
public function add(array $data): Model\Venta\Credito
|
||||
{
|
||||
@ -30,6 +35,27 @@ class Credito
|
||||
]);
|
||||
return $this->creditoRepository->save($credito);
|
||||
}
|
||||
public function edit(Model\Venta\Credito $credito, array $data): Model\Venta\Credito
|
||||
{
|
||||
$uf = $this->moneyService->getUF($credito->pago->fecha);
|
||||
if (array_key_exists('fecha', $data)) {
|
||||
$fecha = new DateTimeImmutable($data['fecha']);
|
||||
$data['fecha'] = $fecha->format('Y-m-d');
|
||||
$uf = $this->moneyService->getUF($fecha);
|
||||
$data['uf'] = $uf;
|
||||
}
|
||||
if (array_key_exists('valor', $data)) {
|
||||
$data['valor'] = round(((float) $data['valor']) * $uf);
|
||||
}
|
||||
$filteredData = array_intersect_key($data, array_fill_keys([
|
||||
'fecha',
|
||||
'uf',
|
||||
'valor',
|
||||
'banco'
|
||||
], 0));
|
||||
$credito->pago = $this->pagoRepository->edit($credito->pago, $filteredData);
|
||||
return $this->creditoRepository->edit($credito, $filteredData);
|
||||
}
|
||||
protected function addPago(array $data): Model\Venta\Pago
|
||||
{
|
||||
$pago = $this->pagoRepository->create($data);
|
||||
|
Reference in New Issue
Block a user