diff --git a/app/resources/views/ventas/pies/cuotas.blade.php b/app/resources/views/ventas/pies/cuotas.blade.php index 64ebb57..d912fea 100644 --- a/app/resources/views/ventas/pies/cuotas.blade.php +++ b/app/resources/views/ventas/pies/cuotas.blade.php @@ -5,6 +5,29 @@ @endsection @section('venta_content') + @if (count($asociadas) > 0) +
+
Asociados
+
+ {!! implode(' - ', array_map(function(Incoviba\Model\Venta $venta) use ($urls) { + return "base}/venta/{$venta->id}\">{$venta->propiedad()->departamentos()[0]->descripcion}"; + }, $asociadas)) !!} +
+
+ @endif +
+
Valor
+
+ {{$format->ufs($venta->formaPago()->pie->valor)}} + @if (count($asociadas) > 0) + [{{$format->ufs($venta->formaPago()->pie->valor + array_reduce($asociadas, function(float $sum, Incoviba\Model\Venta $venta) { + return $sum + $venta->formaPago()->pie->valor; + }, 0.0))}}] + @endif +
+
Cuotas
+
{{$venta->formaPago()->pie->cuotas}}
+
@@ -37,8 +60,10 @@ @@ -128,7 +153,7 @@ {{$format->ufs($total - $pagado)}} diff --git a/app/src/Controller/Ventas.php b/app/src/Controller/Ventas.php index 38e665e..3361c67 100644 --- a/app/src/Controller/Ventas.php +++ b/app/src/Controller/Ventas.php @@ -98,10 +98,21 @@ class Ventas return $view->render($response, 'ventas.add', compact('regiones', 'proyectos')); } public function cuotas(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService, + Repository\Venta $ventaRepository, View $view, int $venta_id): ResponseInterface { $venta = $ventaService->getById($venta_id); - return $view->render($response, 'ventas.pies.cuotas', compact('venta')); + $asociadas = []; + if (isset($venta->formaPago()->pie->asociado)) { + $asociadas []= $ventaService->getByPie($venta->formaPago()->pie->asociado->id); + foreach ($venta->formaPago()->pie->asociado->asociados() as $asociado) { + if ($venta->formaPago()->pie->id === $asociado->id) { + continue; + } + $asociadas []= $ventaService->getByPie($asociado->id); + } + } + return $view->render($response, 'ventas.pies.cuotas', compact('venta', 'asociadas')); } public function escriturar(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService, Repository\Contabilidad\Banco $bancoRepository, View $view, int $venta_id): ResponseInterface diff --git a/app/src/Controller/Ventas/Pies.php b/app/src/Controller/Ventas/Pies.php index 648b342..dacb0f5 100644 --- a/app/src/Controller/Ventas/Pies.php +++ b/app/src/Controller/Ventas/Pies.php @@ -10,7 +10,9 @@ use Psr\Http\Message\ServerRequestInterface; class Pies { - public function cuotas(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pie $pieService, Repository\Venta $ventaRepository, Repository\Contabilidad\Banco $bancoRepository, View $view, int $pie_id): ResponseInterface + public function cuotas(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pie $pieService, + Repository\Venta $ventaRepository, Repository\Contabilidad\Banco $bancoRepository, + View $view, int $pie_id): ResponseInterface { $pie = $pieService->getById($pie_id); $venta = $ventaRepository->fetchByPie($pie_id); @@ -18,6 +20,6 @@ class Pies usort($bancos, function(Model\Contabilidad\Banco $a, Model\Contabilidad\Banco $b) { return strcmp($a->nombre, $b->nombre); }); - return $view->render($response, 'ventas.pies.cuotas', compact('pie', 'venta', 'bancos')); + return $view->render($response, 'ventas.pies.cuotas', compact('pie', 'venta', 'bancos', 'ventaRepository')); } } diff --git a/app/src/Service/Venta.php b/app/src/Service/Venta.php index ec8500b..f9ebf44 100644 --- a/app/src/Service/Venta.php +++ b/app/src/Service/Venta.php @@ -83,6 +83,10 @@ class Venta extends Service { return $this->ventaRepository->fetchByIdForList($venta_id); } + public function getByPie(int $pie_id): Model\Venta + { + return $this->process($this->ventaRepository->fetchByPie($pie_id)); + } protected function process(Model\Venta $venta): Model\Venta { diff --git a/app/src/Service/Venta/Pago.php b/app/src/Service/Venta/Pago.php index fe8c8b1..45663e8 100644 --- a/app/src/Service/Venta/Pago.php +++ b/app/src/Service/Venta/Pago.php @@ -30,6 +30,7 @@ class Pago try { $estado = $this->estadoPagoRepository->create($data); $this->estadoPagoRepository->save($estado); + $this->getUF($pago); return true; } catch (PDOException) { return false; @@ -162,7 +163,7 @@ class Pago protected function getUF(Model\Venta\Pago $pago): ?float { if (($pago->uf === null or $pago->uf === 0.0) - and $pago->currentEstado->tipoEstadoPago->descripcion === 'abonado' + and in_array($pago->currentEstado->tipoEstadoPago->descripcion, ['depositado', 'abonado']) and $pago->currentEstado->fecha <= new DateTimeImmutable()) { $uf = $this->moneyService->getUF($pago->currentEstado->fecha); if ($uf !== 0.0) { diff --git a/app/src/Service/Venta/Pie.php b/app/src/Service/Venta/Pie.php index dfeda57..872c637 100644 --- a/app/src/Service/Venta/Pie.php +++ b/app/src/Service/Venta/Pie.php @@ -2,6 +2,7 @@ namespace Incoviba\Service\Venta; use Incoviba\Common\Implement\Exception\EmptyResult; +use Incoviba\Common\Implement\Repository\Factory; use Incoviba\Repository; use Incoviba\Model; @@ -47,6 +48,9 @@ class Pie try { $pie->asociados = $this->pieRepository->fetchAsociados($pie->id); } catch (EmptyResult) {} + if (isset($pie->asociado)) { + $pie->asociado = $this->getById($pie->asociado->id); + } return $pie; } } diff --git a/docker-compose.yml b/docker-compose.yml index 22b04ab..ed5dd78 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -91,7 +91,7 @@ services: service: web volumes: - ./logs/test:/logs - command: [ '/code/vendor/bin/phpunit-watcher', 'watch' ] + command: [ '/code/bin/phpunit-watcher', 'watch' ] volumes: dbdata: {}
{{$cuota->pago->identificador}} {{$format->pesos($cuota->pago->valor)}} - @if ($cuota->pago->currentEstado->tipoEstadoPago->descripcion === 'abonado' and $cuota->pago->currentEstado->fecha <= $now) + @if (in_array($cuota->pago->currentEstado->tipoEstadoPago->descripcion, ['depositado', 'abonado']) and $cuota->pago->currentEstado->fecha <= $now) {{$format->ufs($cuota->pago->valor())}} + @else + ~{{$format->ufs($cuota->pago->valor / $uf_venta)}} @endif - {{$format->number($pagado / $total * 100, 2)}}% + {{$format->number(($total > 0) ? $pagado / $total * 100 : 0, 2)}}%
- {{$format->number(($total - $pagado) / $total * 100, 2)}}% + {{$format->number(($total > 0) ? ($total - $pagado) / $total * 100 : 0, 2)}}%