From 51cabee8244379e2af9dc5a3548815ab718dcf4b Mon Sep 17 00:00:00 2001 From: Juan Pablo Vial Date: Thu, 15 Feb 2024 18:57:56 -0300 Subject: [PATCH] Editar credito --- app/resources/routes/04_ventas.php | 3 + app/resources/routes/api/ventas.php | 3 + app/resources/views/ventas/creditos.blade.php | 294 ++++++++++++++++++ app/src/Controller/API/Ventas/Creditos.php | 31 ++ app/src/Controller/Ventas/Creditos.php | 20 ++ app/src/Model/Venta/Pie.php | 2 +- app/src/Repository/Venta.php | 9 - app/src/Repository/Venta/Credito.php | 2 +- .../Contabilidad/Informe/Tesoreria.php | 4 +- app/src/Service/Venta/Credito.php | 30 +- 10 files changed, 383 insertions(+), 15 deletions(-) create mode 100644 app/resources/views/ventas/creditos.blade.php create mode 100644 app/src/Controller/API/Ventas/Creditos.php create mode 100644 app/src/Controller/Ventas/Creditos.php diff --git a/app/resources/routes/04_ventas.php b/app/resources/routes/04_ventas.php index 003d2af..e094508 100644 --- a/app/resources/routes/04_ventas.php +++ b/app/resources/routes/04_ventas.php @@ -31,6 +31,9 @@ $app->group('/venta/{venta_id:[0-9]+}', function($app) { $app->group('/escritura', function($app) { $app->get('/add[/]', [Ventas\Escrituras::class, 'add']); }); + $app->group('/credito', function($app) { + $app->get('[/]', [Ventas\Creditos::class, 'show']); + }); $app->get('/escriturar[/]', [Ventas::class, 'escriturar']); $app->get('/desistir[/]', [Ventas::class, 'desistir']); $app->get('/desistida[/]', [Ventas::class, 'desistida']); diff --git a/app/resources/routes/api/ventas.php b/app/resources/routes/api/ventas.php index d3e2c7a..1c23c8b 100644 --- a/app/resources/routes/api/ventas.php +++ b/app/resources/routes/api/ventas.php @@ -30,6 +30,9 @@ $app->group('/venta/{venta_id}', function($app) { $app->group('/escritura', function($app) { $app->post('/add[/]', [Ventas\Escrituras::class, 'add']); }); + $app->group('/credito', function($app) { + $app->post('[/]', [Ventas\Creditos::class, 'edit']); + }); $app->post('/escriturar[/]', [Ventas::class, 'escriturar']); $app->group('/desistir', function($app) { $app->get('/eliminar[/]', [Ventas::class, 'insistir']); diff --git a/app/resources/views/ventas/creditos.blade.php b/app/resources/views/ventas/creditos.blade.php new file mode 100644 index 0000000..b62c3fc --- /dev/null +++ b/app/resources/views/ventas/creditos.blade.php @@ -0,0 +1,294 @@ +@extends('ventas.base') + +@section('venta_subtitle') + Crédito +@endsection + +@section('venta_content') + @php($credito = $venta->formaPago()->credito) +
+
+
Fecha
+
+ + {{$credito->pago->fecha->format('d-m-Y')}} + + + + + +
+
+
+
Banco
+
+ + @if (isset($credito->pago->banco)) + {{$credito->pago->banco->nombre}} + @else + No definido + @endif + + + + + +
+
+
+
Valor
+
+ + {{$format->ufs($credito->pago->valor())}} + + + + + +
+
+
+@endsection + +@push('page_styles') + +@endpush +@push('page_scripts') + +@endpush diff --git a/app/src/Controller/API/Ventas/Creditos.php b/app/src/Controller/API/Ventas/Creditos.php new file mode 100644 index 0000000..6ba25c3 --- /dev/null +++ b/app/src/Controller/API/Ventas/Creditos.php @@ -0,0 +1,31 @@ +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); + } +} diff --git a/app/src/Controller/Ventas/Creditos.php b/app/src/Controller/Ventas/Creditos.php new file mode 100644 index 0000000..e04f9b1 --- /dev/null +++ b/app/src/Controller/Ventas/Creditos.php @@ -0,0 +1,20 @@ +fetchById($venta_id); + $bancos = $bancoRepository->fetchAll('nombre'); + return $view->render($response, 'ventas.creditos', compact('venta', 'bancos')); + } +} diff --git a/app/src/Model/Venta/Pie.php b/app/src/Model/Venta/Pie.php index cdae691..96d023f 100644 --- a/app/src/Model/Venta/Pie.php +++ b/app/src/Model/Venta/Pie.php @@ -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) { diff --git a/app/src/Repository/Venta.php b/app/src/Repository/Venta.php index 6d6a54a..089e0d5 100644 --- a/app/src/Repository/Venta.php +++ b/app/src/Repository/Venta.php @@ -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 diff --git a/app/src/Repository/Venta/Credito.php b/app/src/Repository/Venta/Credito.php index bef27bd..b36ec8d 100644 --- a/app/src/Repository/Venta/Credito.php +++ b/app/src/Repository/Venta/Credito.php @@ -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']); diff --git a/app/src/Service/Contabilidad/Informe/Tesoreria.php b/app/src/Service/Contabilidad/Informe/Tesoreria.php index ebdee8f..cb8b39e 100644 --- a/app/src/Service/Contabilidad/Informe/Tesoreria.php +++ b/app/src/Service/Contabilidad/Informe/Tesoreria.php @@ -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' ]]); } diff --git a/app/src/Service/Venta/Credito.php b/app/src/Service/Venta/Credito.php index 1e35b2c..d7ff3fa 100644 --- a/app/src/Service/Venta/Credito.php +++ b/app/src/Service/Venta/Credito.php @@ -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);