diff --git a/app/resources/routes/04_ventas.php b/app/resources/routes/04_ventas.php
index 2ce4212..8ae9b6e 100644
--- a/app/resources/routes/04_ventas.php
+++ b/app/resources/routes/04_ventas.php
@@ -23,6 +23,7 @@ $app->group('/venta/{venta_id:[0-9]+}', function($app) {
$app->get('[/]', [Ventas::class, 'propiedad']);
});
$app->group('/pie', function($app) {
+ $app->get('/add[/]', [Ventas\Pies::class, 'add']);
$app->group('/cuotas', function($app) {
$app->get('[/]', [Ventas::class, 'cuotas']);
});
diff --git a/app/resources/routes/api/ventas.php b/app/resources/routes/api/ventas.php
index c79874b..6374a98 100644
--- a/app/resources/routes/api/ventas.php
+++ b/app/resources/routes/api/ventas.php
@@ -54,6 +54,9 @@ $app->group('/venta/{venta_id}', function($app) {
$app->group('/propietario', function($app) {
$app->put('/edit[/]', [Ventas::class, 'propietario']);
});
+ $app->group('/pie', function($app) {
+ $app->post('/add[/]', [Ventas\Pies::class, 'add']);
+ });
$app->post('[/]', [Ventas::class, 'edit']);
$app->get('[/]', [Ventas::class, 'get']);
});
diff --git a/app/resources/views/ventas/pies/add.blade.php b/app/resources/views/ventas/pies/add.blade.php
new file mode 100644
index 0000000..fb378d2
--- /dev/null
+++ b/app/resources/views/ventas/pies/add.blade.php
@@ -0,0 +1,50 @@
+@extends('ventas.base')
+
+@section('venta_subtitle')
+ Pie
+@endsection
+
+@section('venta_content')
+
+ Valor Promesa: {{ $format->ufs($venta->valor) }}
+ 10% {{ $format->ufs($venta->valor * 0.1) }}
+
+
+@endsection
+
+@push('page_scripts')
+
+@endpush
diff --git a/app/resources/views/ventas/show/forma_pago/pie.blade.php b/app/resources/views/ventas/show/forma_pago/pie.blade.php
index 6f3df32..0142a58 100644
--- a/app/resources/views/ventas/show/forma_pago/pie.blade.php
+++ b/app/resources/views/ventas/show/forma_pago/pie.blade.php
@@ -1,42 +1,52 @@
-@if ($pie !== null)
Pie
-
-
-
-
-
- |
- |
- {{$format->ufs($pie->valor)}} |
- {{$format->pesos($pie->valor * $pie->uf)}} |
- Cuotas |
-
-
- {{count($pie->cuotas(true, true))}}/{{$pie->cuotas}}
-
- @if (count($pie->cuotas(vigentes: true)) < $pie->cuotas)
-
+ @if ($pie !== null)
+
+
+
+
+
+ @else
+
@endif
|
-
-
- Pagado |
|
- {{$format->ufs($pie->pagado())}} |
- {{$format->pesos($pie->pagado('pesos'))}} |
- |
-
-@if ($pie->reajuste)
-
- Reajuste |
- |
- {{$format->ufs($pie->reajuste->valor())}} |
- {{$format->pesos($pie->reajuste->valor)}} |
- |
+ @if ($pie !== null)
+ {{$format->ufs($pie->valor)}} |
+ {{$format->pesos($pie->valor * $pie->uf)}} |
+ Cuotas |
+
+
+ {{count($pie->cuotas(true, true))}}/{{$pie->cuotas}}
+
+ @if (count($pie->cuotas(vigentes: true)) < $pie->cuotas)
+
+
+
+ @endif
+ |
+ @else
+ |
+ @endif
-@endif
+@if ($pie !== null)
+
+ Pagado |
+ |
+ {{$format->ufs($pie->pagado())}} |
+ {{$format->pesos($pie->pagado('pesos'))}} |
+ |
+
+ @if ($pie->reajuste)
+
+ Reajuste |
+ |
+ {{$format->ufs($pie->reajuste->valor())}} |
+ {{$format->pesos($pie->reajuste->valor)}} |
+ |
+
+ @endif
@endif
diff --git a/app/src/Controller/API/Ventas/Pies.php b/app/src/Controller/API/Ventas/Pies.php
index 9c90638..1d5eca1 100644
--- a/app/src/Controller/API/Ventas/Pies.php
+++ b/app/src/Controller/API/Ventas/Pies.php
@@ -5,7 +5,8 @@ use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
use Incoviba\Controller\API\{withJson, emptyBody};
use Incoviba\Controller\withRedis;
-use Incoviba\Common\Implement\Exception\{EmptyRedis, EmptyResult};
+use Incoviba\Common\Implement\Exception\EmptyResult;
+use Incoviba\Exception\ServiceAction\{Create, Read, Update};
use Incoviba\Service;
class Pies
@@ -27,4 +28,35 @@ class Pies
} catch (EmptyResult) {}
return $this->withJson($response, $output);
}
+ public function add(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService,
+ Service\Venta\Pie $pieService, int $venta_id): ResponseInterface
+ {
+ $input = $request->getParsedBody();
+ $output = [
+ 'venta_id' => $venta_id,
+ 'input' => $input,
+ 'pie' => null,
+ 'success' => false
+ ];
+ try {
+ $venta = $ventaService->getById($venta_id);
+
+ } catch (Read $exception) {
+ return $this->withError($response, $exception);
+ }
+ try {
+ $pie = $pieService->add($input);
+ } catch (Create $exception) {
+ return $this->withError($response, $exception);
+ }
+ try {
+ $ventaService->edit($venta, ['pie' => $pie->id]);
+
+ $output['pie'] = $pie;
+ $output['success'] = true;
+ } catch (Update $exception) {
+ return $this->withError($response, $exception);
+ }
+ return $this->withJson($response, $output);
+ }
}
diff --git a/app/src/Controller/Ventas/Pies.php b/app/src/Controller/Ventas/Pies.php
index 3fb9fcc..d9491fd 100644
--- a/app/src/Controller/Ventas/Pies.php
+++ b/app/src/Controller/Ventas/Pies.php
@@ -1,12 +1,12 @@
fetchAll('descripcion');
return $view->render($response, 'ventas.pies.cuotas', compact('pie', 'venta', 'bancos', 'estados', 'ventaRepository'));
}
+ public function add(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService,
+ View $view, int $venta_id): ResponseInterface
+ {
+ $venta = null;
+ try {
+ $venta = $ventaService->getById($venta_id);
+ } catch (Read) {}
+ return $view->render($response, 'ventas.pies.add', compact('venta'));
+ }
}
diff --git a/app/src/Service/Venta.php b/app/src/Service/Venta.php
index 0ed32fc..d0ead13 100644
--- a/app/src/Service/Venta.php
+++ b/app/src/Service/Venta.php
@@ -4,6 +4,7 @@ namespace Incoviba\Service;
use Exception;
use DateTimeImmutable;
use DateMalformedStringException;
+use Incoviba\Exception\ServiceAction\{Read, Update};
use Psr\Log\LoggerInterface;
use Incoviba\Common\Ideal\Service;
use Incoviba\Common\Implement;
@@ -36,9 +37,18 @@ class Venta extends Service
parent::__construct($logger);
}
+ /**
+ * @param int $venta_id
+ * @return Model\Venta
+ * @throws Read
+ */
public function getById(int $venta_id): Model\Venta
{
- return $this->process($this->ventaRepository->fetchById($venta_id));
+ try {
+ return $this->process($this->ventaRepository->fetchById($venta_id));
+ } catch (Implement\Exception\EmptyResult $exception) {
+ throw new Read(__CLASS__, $exception);
+ }
}
public function getByProyecto(int $proyecto_id): array
{
@@ -285,6 +295,22 @@ class Venta extends Service
return $this->formaPagoService->add($data);
}
+ /**
+ * @param Model\Venta $venta
+ * @param array $data
+ * @return Model\Venta
+ * @throws Update
+ */
+ public function edit(Model\Venta $venta, array $data): Model\Venta
+ {
+ try {
+ $filteredData = $this->ventaRepository->filterData($data);
+ return $this->ventaRepository->edit($venta, $filteredData);
+ } catch (Implement\Exception\EmptyResult $exception) {
+ throw new Update(__CLASS__, $exception);
+ }
+ }
+
protected function addEstado(Model\Venta $venta, Model\Venta\TipoEstadoVenta $tipoEstadoVenta, array $data): void
{
try {
diff --git a/app/src/Service/Venta/Pie.php b/app/src/Service/Venta/Pie.php
index 41ca092..0d1382f 100644
--- a/app/src/Service/Venta/Pie.php
+++ b/app/src/Service/Venta/Pie.php
@@ -1,17 +1,22 @@
pieRepository->filterData($data);
- $pie = $this->pieRepository->create($filteredData);
- return $this->pieRepository->save($pie);
+ try {
+ $filteredData = $this->pieRepository->filterData($data);
+ if (!isset($filteredData['uf'])) {
+ try {
+ $date = new DateTimeImmutable($filteredData['fecha']);
+ $filteredData['uf'] = $this->ufService->get($date);
+ } catch (DateMalformedStringException) {}
+ }
+ $pie = $this->pieRepository->create($filteredData);
+ return $this->pieRepository->save($pie);
+ } catch (PDOException $exception) {
+ throw new Create(__CLASS__, $exception);
+ }
}
public function addCuota(array $data): Model\Venta\Cuota
{