4 Commits

Author SHA1 Message Date
b9c2972fe9 Cuando existen cuotas asociadas a algun pie distintas al pie asociado 2024-10-01 17:35:23 -03:00
37015f7e95 PHP 8 2024-10-01 17:34:43 -03:00
c3b36dcdf7 Optimizacion 2024-10-01 17:34:27 -03:00
c68b773cbb FIX: Banco vacio 2024-10-01 17:33:29 -03:00
4 changed files with 24 additions and 14 deletions

View File

@ -16,7 +16,7 @@
<a href="{{$urls->base}}/venta/{{$venta->id}}/pie/cuotas"> <a href="{{$urls->base}}/venta/{{$venta->id}}/pie/cuotas">
<span data-tooltip="Pagadas">{{count($pie->cuotas(true))}}</span>/{{$pie->cuotas}} <span data-tooltip="Pagadas">{{count($pie->cuotas(true))}}</span>/{{$pie->cuotas}}
</a> </a>
@if (count($pie->cuotas(false, true)) < $pie->cuotas) @if (count($pie->cuotas(vigentes: true)) < $pie->cuotas)
<a href="{{$urls->base}}/ventas/pie/{{$pie->id}}/cuotas/add"> <a href="{{$urls->base}}/ventas/pie/{{$pie->id}}/cuotas/add">
<i class="plus icon"></i> <i class="plus icon"></i>
</a> </a>

View File

@ -84,7 +84,7 @@ 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, int $pie_id): ResponseInterface Repository\Venta $ventaRepository, Service\Valor $valorService, int $pie_id): ResponseInterface
{ {
$body = $request->getParsedBody(); $body = $request->getParsedBody();
$pie = $pieService->getById($pie_id); $pie = $pieService->getById($pie_id);
@ -92,12 +92,15 @@ class Cuotas
$start = count($pie->cuotas(vigentes: true)); $start = count($pie->cuotas(vigentes: true));
$total = $pie->cuotas; $total = $pie->cuotas;
for ($i = $start; $i < $total; $i ++) { for ($i = $start; $i < $total; $i ++) {
if ($body["banco{$i}"] === '') {
continue;
}
$data = [ $data = [
'pie' => $pie->id, 'pie' => $pie->id,
'fecha' => $body["fecha{$i}"], 'fecha' => $body["fecha{$i}"],
'banco' => $body["banco{$i}"], 'banco' => (int) $body["banco{$i}"],
'identificador' => $body["identificador{$i}"], 'identificador' => $body["identificador{$i}"],
'valor' => str_replace(['.', ','], ['', ''], $body["valor{$i}"]), 'valor' => $valorService->clean($body["valor{$i}"]),
'numero' => $i + 1, 'numero' => $i + 1,
]; ];
$pieService->addCuota($data); $pieService->addCuota($data);

View File

@ -18,7 +18,8 @@ class Pie extends Model
public function cuotas(bool $pagadas = false, bool $vigentes = false): array public function cuotas(bool $pagadas = false, bool $vigentes = false): array
{ {
if ($this->asociado !== null) { if ($this->asociado !== null) {
return $this->asociado->cuotas($pagadas, $vigentes); $cuotas = $this->asociado->cuotas($pagadas, $vigentes);
$this->cuotasArray = array_merge($this->cuotasArray, $cuotas);
} }
if (!$pagadas and !$vigentes) { if (!$pagadas and !$vigentes) {
return $this->cuotasArray; return $this->cuotasArray;

View File

@ -4,16 +4,21 @@ namespace Incoviba\Service\Venta;
use DateTimeImmutable; use DateTimeImmutable;
use DateInterval; use DateInterval;
use IntlDateFormatter; use IntlDateFormatter;
use Psr\Log\LoggerInterface;
use Incoviba\Common\Ideal;
use Incoviba\Repository; use Incoviba\Repository;
use Incoviba\Model; use Incoviba\Model;
class Cuota class Cuota extends Ideal\Service
{ {
public function __construct( public function __construct(
LoggerInterface $logger,
protected Repository\Venta\Cuota $cuotaRepository, protected Repository\Venta\Cuota $cuotaRepository,
protected Pago $pagoService, protected Pago $pagoService,
protected Repository\Venta\TipoPago $tipoPagoRepository protected Repository\Venta\TipoPago $tipoPagoRepository
) {} ) {
parent::__construct($logger);
}
public function pendientes(): array public function pendientes(): array
{ {
@ -75,11 +80,11 @@ class Cuota
} }
public function getByPie(int $pie_id): array public function getByPie(int $pie_id): array
{ {
try { try {
return $this->cuotaRepository->fetchByPie($pie_id); return $this->cuotaRepository->fetchByPie($pie_id);
} catch (EmptyResult) { } catch (EmptyResult) {
return []; return [];
} }
} }
public function getVigenteByPie(int $pie_id): array public function getVigenteByPie(int $pie_id): array
{ {
@ -89,13 +94,14 @@ class Cuota
public function add(array $data): Model\Venta\Cuota public function add(array $data): Model\Venta\Cuota
{ {
$tipoPago = $this->tipoPagoRepository->fetchByDescripcion('cheque'); $tipoPago = $this->tipoPagoRepository->fetchByDescripcion('cheque');
$fields = array_fill_keys([ $fields = array_flip([
'fecha', 'fecha',
'banco', 'banco',
'valor', 'valor',
'identificador' 'identificador'
], 0); ]);
$filtered_data = array_intersect_key($data, $fields); $filtered_data = array_intersect_key($data, $fields);
$pago_data = array_merge($filtered_data, ['tipo' => $tipoPago->id]); $pago_data = array_merge($filtered_data, ['tipo' => $tipoPago->id]);
$pago = $this->pagoService->add($pago_data); $pago = $this->pagoService->add($pago_data);