Agregar y editar abono cuotas.
This commit is contained in:
@ -36,6 +36,7 @@ $app->group('/venta/{venta_id:[0-9]+}', function($app) {
|
||||
$app->get('[/]', Ventas\Abono\Cuotas::class);
|
||||
});
|
||||
$app->get('/add[/]', [Ventas\Escrituras::class, 'add']);
|
||||
$app->get('[/]', [Ventas\Escrituras::class, 'show']);
|
||||
});
|
||||
$app->group('/credito', function($app) {
|
||||
$app->get('[/]', [Ventas\Creditos::class, 'show']);
|
||||
|
@ -35,6 +35,9 @@ $app->group('/venta/{venta_id}', function($app) {
|
||||
$app->post('/add[/]', [Ventas\Bonos::class, 'add']);
|
||||
});
|
||||
$app->group('/escritura', function($app) {
|
||||
$app->group('/cuotas', function($app) {
|
||||
$app->post('/add[/]', [Ventas\Abonos\Cuotas::class, 'add']);
|
||||
});
|
||||
$app->post('/add[/]', [Ventas\Escrituras::class, 'add']);
|
||||
});
|
||||
$app->group('/credito', function($app) {
|
||||
|
@ -14,7 +14,7 @@
|
||||
<th>UF</th>
|
||||
<th rowspan="2">Estado</th>
|
||||
<th class="right aligned">
|
||||
<button class="ui green icon button" id="add_button">
|
||||
<button class="ui tertiary green icon button" id="add_button">
|
||||
<i class="plus icon"></i>
|
||||
</button>
|
||||
</th>
|
||||
@ -50,13 +50,13 @@
|
||||
$(document).ready(function () {
|
||||
const addModal = new AddModal({
|
||||
modal: '#add_cuota_modal',
|
||||
form: '#add_cuota_form',
|
||||
form: 'add_cuota_form',
|
||||
fecha: '#add_fecha',
|
||||
})
|
||||
const editModal = new EditModal({
|
||||
table: 'cuotas',
|
||||
modal: '#edit_cuota_modal',
|
||||
form: '#edit_cuota_form',
|
||||
form: 'edit_cuota_form',
|
||||
fecha: '#edit_fecha',
|
||||
estado: '#edit_estado'
|
||||
})
|
||||
|
@ -4,7 +4,7 @@
|
||||
</div>
|
||||
<div class="content">
|
||||
<form class="ui form" id="add_cuota_form">
|
||||
<input type="hidden" name="id" />
|
||||
<input type="hidden" name="venta_id" value="{{$venta->id}}" />
|
||||
<div class="two wide field">
|
||||
<label>Número</label>
|
||||
<input type="text" name="numero" />
|
||||
|
@ -36,11 +36,11 @@
|
||||
<label>Estado</label>
|
||||
<div class="ui selection search dropdown" id="edit_estado">
|
||||
<i class="dropdown icon"></i>
|
||||
<input type="hidden" name="estado" />
|
||||
<input type="hidden" name="tipo_estado_id" />
|
||||
<div class="default text">Estado</div>
|
||||
<div class="menu">
|
||||
@foreach($estados as $estado)
|
||||
<div class="item" data-value="{{$estado->id}}">{{$estado->nombre}}</div>
|
||||
<div class="item" data-value="{{$estado->id}}">{{$estado->descripcion}}</div>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
@ -100,7 +100,7 @@
|
||||
const body = new FormData(form)
|
||||
const fecha = $(this.props.fecha).calendar('get date')
|
||||
body.set('fecha', fecha.getFullYear() + '-' + (fecha.getMonth() + 1).toString().padStart(2, '0') + '-' + fecha.getDate().toString().padStart(2, '0'))
|
||||
body.set('estado', $(this.props.estado).dropdown('get value'))
|
||||
body.set('tipo_estado_id', $(this.props.estado).dropdown('get value'))
|
||||
const url = `{{$urls->api}}/venta/{{$venta->id}}/escritura/cuota/${this.data.id}/edit`
|
||||
const method = 'post'
|
||||
APIClient.fetch(url, {method, body}).then(response => {
|
||||
|
@ -5,6 +5,13 @@
|
||||
@endsection
|
||||
|
||||
@section('venta_content')
|
||||
@if (count($venta->formaPago()->cuotasAbono) > 0)
|
||||
<a href="{{$urls->base}}/venta/{{$venta->id}}/escritura/cuotas" class="ui small green button">Ver Cuotas</a>
|
||||
<p>{{$format->pesos(array_reduce($venta->formaPago()->cuotas, function($sum, $cuota) {return $sum + $cuota->pago->valor;}, 0))}}</p>
|
||||
<p>{{$format->ufs(array_reduce($venta->formaPago()->cuotas, function($sum, $cuota) {return $sum + $cuota->pago->valor();}, 0.0))}}</p>
|
||||
@else
|
||||
<a href="{{$urls->base}}/venta/{{$venta->id}}/escritura/cuotas" class="ui small green button"><i class="plus icon"></i> Agregar Cuotas</a>
|
||||
@endif
|
||||
<form class="ui form" id="edit_form">
|
||||
<div class="three wide field">
|
||||
<label for="fecha">Fecha</label>
|
||||
@ -15,6 +22,26 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="three wide field">
|
||||
<label for="valor">Valor</label>
|
||||
<div class="ui left labeled input">
|
||||
<div class="ui basic label">$</div>
|
||||
<input type="text" name="valor" value="{{$venta->formaPago()->escritura->pago->valor}}" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="three wide field">
|
||||
<label>Estado</label>
|
||||
<div class="ui selection dropdown" id="estado">
|
||||
<input type="hidden" name="estado" />
|
||||
<div class="default text">Estado</div>
|
||||
<i class="dropdown icon"></i>
|
||||
<div class="menu">
|
||||
@foreach($estados as $estado)
|
||||
<div class="item" data-value="{{$estado->id}}">{{ucwords($estado->descripcion)}}</div>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button class="ui button">Guardar</button>
|
||||
</form>
|
||||
@endsection
|
||||
@ -27,12 +54,13 @@
|
||||
data.set('venta', {{$venta->id}})
|
||||
const fecha = $('#fecha').calendar('get date')
|
||||
data.set('fecha', fecha.toISOString())
|
||||
data.set('estado', $('#estado').dropdown('get value'))
|
||||
return fetchAPI(url, {method: 'post', body: data}).then(response => {
|
||||
if (response.ok) {
|
||||
return response.json()
|
||||
}
|
||||
}).then(json => {
|
||||
if (!json.edited) {
|
||||
if (!json.success) {
|
||||
return
|
||||
}
|
||||
window.location = '{{$urls->base}}/venta/{{$venta->id}}'
|
||||
@ -41,6 +69,8 @@
|
||||
$(document).ready(() => {
|
||||
calendar_date_options.initialDate = new Date({{$venta->currentEstado()->fecha->format('Y, m-1, j')}})
|
||||
$('#fecha').calendar(calendar_date_options)
|
||||
$('#estado').dropdown()
|
||||
$('#estado').dropdown('set selected', '{{$venta->currentEstado()->id}}')
|
||||
$('#edit_form').submit(event => {
|
||||
event.preventDefault()
|
||||
editEscritura()
|
||||
|
60
app/src/Controller/API/Ventas/Abonos/Cuotas.php
Normal file
60
app/src/Controller/API/Ventas/Abonos/Cuotas.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
namespace Incoviba\Controller\API\Ventas\Abonos;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement;
|
||||
use Incoviba\Controller\API;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Cuotas extends Ideal\Controller
|
||||
{
|
||||
use API\withJson;
|
||||
|
||||
public function add(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Service\Venta\Pago $pagoService,
|
||||
Service\UF $ufService,
|
||||
Service\Valor $valorService,
|
||||
Repository\Venta\Abono\Cuota $cuotaRepository): ResponseInterface
|
||||
{
|
||||
$input = $request->getParsedBody();
|
||||
$output = [
|
||||
'input' => $input,
|
||||
'cuota' => null,
|
||||
'success' => false,
|
||||
];
|
||||
try {
|
||||
$input['valor'] = $valorService->clean($input['valor']);
|
||||
if (isset($input['uf']) and !empty($input['uf'])) {
|
||||
$uf = $ufService->get(new DateTimeImmutable($input['fecha']));
|
||||
$input['valor'] = $uf * $valorService->clean($input['uf']);
|
||||
}
|
||||
$pagoData = array_intersect_key($input, array_flip(['fecha', 'valor']));
|
||||
$pago = $pagoService->add($pagoData);
|
||||
$cuotaData = array_intersect_key($input, array_flip(['venta_id', 'numero']));
|
||||
$cuotaData['pago_id'] = $pago->id;
|
||||
$cuota = $cuotaRepository->create($cuotaData);
|
||||
$output['cuota'] = $cuotaRepository->save($cuota);
|
||||
$output['success'] = true;
|
||||
} catch (Implement\Exception\EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function edit(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Abono\Cuota $cuotaRepository, int $cuota_id): ResponseInterface
|
||||
{
|
||||
$input = $request->getParsedBody();
|
||||
$output = [
|
||||
'input' => $input,
|
||||
'cuota' => null,
|
||||
'success' => false,
|
||||
];
|
||||
try {
|
||||
$cuota = $cuotaRepository->fetchById($cuota_id);
|
||||
$output['cuota'] = $cuotaRepository->edit($cuota, $input);
|
||||
$output['success'] = true;
|
||||
} catch (Implement\Exception\EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
@ -12,6 +12,7 @@ class Cuotas
|
||||
{
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Service\Venta $ventaService,
|
||||
Repository\Venta\TipoEstadoPago $estadoPagoRepository,
|
||||
Repository\Venta\Abono\Cuota $cuotaRepository, View $view, int $venta_id): ResponseInterface
|
||||
{
|
||||
$venta = null;
|
||||
@ -22,6 +23,10 @@ class Cuotas
|
||||
try {
|
||||
$cuotas = $cuotaRepository->fetchByVenta($venta_id);
|
||||
} catch (EmptyResult $e) {}
|
||||
return $view->render($response, 'ventas.escrituras.abono.cuotas', compact('venta', 'cuotas'));
|
||||
$estados = [];
|
||||
try {
|
||||
$estados = $estadoPagoRepository->fetchAll();
|
||||
} catch (EmptyResult $e) {}
|
||||
return $view->render($response, 'ventas.escrituras.abono.cuotas', compact('venta', 'cuotas', 'estados'));
|
||||
}
|
||||
}
|
||||
|
@ -10,10 +10,12 @@ use Psr\Http\Message\ServerRequestInterface;
|
||||
class Escrituras
|
||||
{
|
||||
public function show(ServerRequestInterface $request, ResponseInterface $response, View $view,
|
||||
Repository\Venta\TipoEstadoPago $estadoPagoRepository,
|
||||
Service\Venta $ventaService, int $venta_id): ResponseInterface
|
||||
{
|
||||
$venta = $ventaService->getById($venta_id);
|
||||
return $view->render($response, 'ventas.escrituras.show', compact('venta'));
|
||||
$estados = $estadoPagoRepository->fetchAll();
|
||||
return $view->render($response, 'ventas.escrituras.show', compact('venta', 'estados'));
|
||||
}
|
||||
public function informe(ServerRequestInterface $request, ResponseInterface $response, View $view,
|
||||
Service\Venta $ventaService, int $venta_id): ResponseInterface
|
||||
|
@ -7,11 +7,12 @@ use Incoviba\Common\Implement;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Cuota extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Repository\Venta $ventaRepository,
|
||||
protected Repository\Venta\Pago $pagoRepository)
|
||||
protected Service\Venta\Pago $pagoService)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('venta_abono_cuotas');
|
||||
@ -29,7 +30,7 @@ class Cuota extends Ideal\Repository
|
||||
->register('pago_id', (new Implement\Repository\Mapper())
|
||||
->setProperty('pago')
|
||||
->setFunction(function($data) {
|
||||
return $this->pagoRepository->fetchById($data['pago_id']);
|
||||
return $this->pagoService->getById($data['pago_id']);
|
||||
})
|
||||
);
|
||||
return $this->parseData(new Model\Venta\Abono\Cuota(), $data, $map);
|
||||
|
Reference in New Issue
Block a user