Compare commits
3 Commits
93431e41b3
...
ac52305002
Author | SHA1 | Date | |
---|---|---|---|
ac52305002 | |||
d7d17a3051 | |||
80a6bf1535 |
@ -55,7 +55,7 @@ class Mapper implements Define\Repository\Mapper
|
|||||||
if ($this->hasProperty()) {
|
if ($this->hasProperty()) {
|
||||||
$property = $this->property;
|
$property = $this->property;
|
||||||
}
|
}
|
||||||
if (isset($data[$column])) {
|
if (in_array($column, array_keys($data))) {
|
||||||
if ($this->hasFactory()) {
|
if ($this->hasFactory()) {
|
||||||
$model->addFactory($property, $this->factory);
|
$model->addFactory($property, $this->factory);
|
||||||
return true;
|
return true;
|
||||||
|
@ -29,6 +29,8 @@ $app->group('/venta/{venta_id:[0-9]+}', function($app) {
|
|||||||
$app->get('[/]', [Ventas::class, 'pie']);
|
$app->get('[/]', [Ventas::class, 'pie']);
|
||||||
});
|
});
|
||||||
$app->get('/escriturar[/]', [Ventas::class, 'escriturar']);
|
$app->get('/escriturar[/]', [Ventas::class, 'escriturar']);
|
||||||
|
$app->get('/desistir[/]', [Ventas::class, 'desistir']);
|
||||||
|
$app->get('/desistida[/]', [Ventas::class, 'desistida']);
|
||||||
$app->get('/edit[/]', [Ventas::class, 'edit']);
|
$app->get('/edit[/]', [Ventas::class, 'edit']);
|
||||||
$app->get('[/]', [Ventas::class, 'show']);
|
$app->get('[/]', [Ventas::class, 'show']);
|
||||||
})->add($app->getContainer()->get(Incoviba\Middleware\Authentication::class));
|
})->add($app->getContainer()->get(Incoviba\Middleware\Authentication::class));
|
||||||
|
@ -22,9 +22,10 @@ $app->group('/ventas', function($app) {
|
|||||||
$app->post('[/]', [Ventas::class, 'proyecto']);
|
$app->post('[/]', [Ventas::class, 'proyecto']);
|
||||||
});
|
});
|
||||||
$app->group('/venta/{venta_id}', function($app) {
|
$app->group('/venta/{venta_id}', function($app) {
|
||||||
$app->get('/unidades', [Ventas::class, 'unidades']);
|
$app->get('/unidades[/]', [Ventas::class, 'unidades']);
|
||||||
$app->get('/comentarios', [Ventas::class, 'comentarios']);
|
$app->get('/comentarios[/]', [Ventas::class, 'comentarios']);
|
||||||
$app->post('/escriturar', [Ventas::class, 'escriturar']);
|
$app->post('/escriturar[/]', [Ventas::class, 'escriturar']);
|
||||||
|
$app->post('/desistir[/]', [Ventas::class, 'desistir']);
|
||||||
$app->post('[/]', [Ventas::class, 'edit']);
|
$app->post('[/]', [Ventas::class, 'edit']);
|
||||||
$app->get('[/]', [Ventas::class, 'get']);
|
$app->get('[/]', [Ventas::class, 'get']);
|
||||||
});
|
});
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
use Incoviba\Controller\Ventas\Pagos;
|
use Incoviba\Controller\API\Ventas\Pagos;
|
||||||
|
|
||||||
$app->group('/pagos', function($app) {
|
$app->group('/pagos', function($app) {
|
||||||
$app->get('/pendientes', [Pagos::class, 'para_pendientes']);
|
$app->get('/pendientes', [Pagos::class, 'para_pendientes']);
|
||||||
@ -9,4 +9,5 @@ $app->group('/pagos', function($app) {
|
|||||||
$app->group('/pago/{pago_id:[0-9]+}', function($app) {
|
$app->group('/pago/{pago_id:[0-9]+}', function($app) {
|
||||||
$app->put('/depositar[/]', [Pagos::class, 'depositar']);
|
$app->put('/depositar[/]', [Pagos::class, 'depositar']);
|
||||||
$app->put('/abonar[/]', [Pagos::class, 'abonar']);
|
$app->put('/abonar[/]', [Pagos::class, 'abonar']);
|
||||||
|
$app->post('[/]', [Pagos::class, 'edit']);
|
||||||
});
|
});
|
||||||
|
@ -12,7 +12,14 @@
|
|||||||
if (!Object.hasOwn(options['headers'], 'Authorization')) {
|
if (!Object.hasOwn(options['headers'], 'Authorization')) {
|
||||||
options['headers']['Authorization'] = 'Bearer {{md5($API_KEY)}}'
|
options['headers']['Authorization'] = 'Bearer {{md5($API_KEY)}}'
|
||||||
}
|
}
|
||||||
return fetch(url, options)
|
return fetch(url, options).then(response => {
|
||||||
|
if (response.ok) {
|
||||||
|
return response
|
||||||
|
}
|
||||||
|
throw new Error(JSON.stringify({code: response.status, message: response.statusText, url}))
|
||||||
|
}).catch(error => {
|
||||||
|
console.error(error)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
const calendar_date_options = {
|
const calendar_date_options = {
|
||||||
type: 'date',
|
type: 'date',
|
||||||
|
78
app/resources/views/ventas/desistida.blade.php
Normal file
78
app/resources/views/ventas/desistida.blade.php
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
@extends('layout.base')
|
||||||
|
|
||||||
|
@section('page_content')
|
||||||
|
<div class="ui container">
|
||||||
|
<h1 class="ui header">
|
||||||
|
Desistida - {{$venta->proyecto()->descripcion}} -
|
||||||
|
<a href="{{$urls->base}}/venta/{{$venta->id}}">
|
||||||
|
{{$venta->propiedad()->summary()}}
|
||||||
|
</a>
|
||||||
|
</h1>
|
||||||
|
<form class="ui form" id="desistida_form">
|
||||||
|
<div class="three wide field">
|
||||||
|
<label for="fecha">Fecha</label>
|
||||||
|
<div class="ui calendar" id="fecha">
|
||||||
|
<div class="ui left icon input">
|
||||||
|
<i class="calendar icon"></i>
|
||||||
|
<input type="text" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="three wide field">
|
||||||
|
<label for="devolucion">Devolución</label>
|
||||||
|
<div class="ui left labeled input">
|
||||||
|
<div class="ui basic label">$</div>
|
||||||
|
<input type="text" id="devolucion" value="{{$venta->resciliacion()->valor}}" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
@endsection
|
||||||
|
|
||||||
|
@push('page_scripts')
|
||||||
|
<script>
|
||||||
|
function alertResponse(message, color = 'green') {
|
||||||
|
$.toast({
|
||||||
|
message,
|
||||||
|
showProgress: 'bottom',
|
||||||
|
progressUp: true,
|
||||||
|
class: color,
|
||||||
|
showIcon: 'check circle',
|
||||||
|
classProgress: 'blue'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
$(document).ready(() => {
|
||||||
|
const url = '{{$urls->api}}/ventas/pago/{{$venta->resciliacion()->id}}'
|
||||||
|
let old = new Date({{$venta->resciliacion()->fecha->format('Y')}},
|
||||||
|
{{$venta->resciliacion()->fecha->format('n')}}-1, {{$venta->resciliacion()->fecha->format('j')}})
|
||||||
|
calendar_date_options['initialDate'] = old
|
||||||
|
calendar_date_options['onChange'] = function(date, text, mode) {
|
||||||
|
if (date.getTime() === old.getTime()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const body = new FormData()
|
||||||
|
body.set('fecha', date.toISOString())
|
||||||
|
fetchAPI(url, {method: 'post', body}).then(response => {
|
||||||
|
if (!response) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
old = date
|
||||||
|
alertResponse('Fecha cambiada correctamente.')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
$('#fecha').calendar(calendar_date_options)
|
||||||
|
$('#devolucion').change(event => {
|
||||||
|
console.debug(event)
|
||||||
|
const val = $(event.currentTarget).val()
|
||||||
|
const body = new FormData()
|
||||||
|
body.set('valor', val)
|
||||||
|
fetchAPI(url, {method: 'post', body}).then(response => {
|
||||||
|
if (!response) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
alertResponse('Devolución cambiada correctamente.')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
@endpush
|
75
app/resources/views/ventas/desistir.blade.php
Normal file
75
app/resources/views/ventas/desistir.blade.php
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
@extends('layout.base')
|
||||||
|
|
||||||
|
@section('page_content')
|
||||||
|
<div class="ui container">
|
||||||
|
<h1 class="ui header">
|
||||||
|
Desistir - {{$venta->proyecto()->descripcion}} -
|
||||||
|
<a href="{{$urls->base}}/venta/{{$venta->id}}">{{$venta->propiedad()->summary()}}</a>
|
||||||
|
</h1>
|
||||||
|
<div class="ui list">
|
||||||
|
<div class="item">
|
||||||
|
<div class="header">Valor Pagado</div>
|
||||||
|
<div class="content">
|
||||||
|
{{$format->pesos($venta->formaPago()->pie->pagado('pesos'))}}
|
||||||
|
<div class="ui left pointing small label">
|
||||||
|
{{$format->number($venta->formaPago()->pie->pagado() / $venta->valor * 100)}}% de la venta
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="item">
|
||||||
|
<div class="header">
|
||||||
|
Multa Estandar
|
||||||
|
<div class="ui left pointing small label">5%</div>
|
||||||
|
</div>
|
||||||
|
<div class="content">
|
||||||
|
{{$format->pesos($venta->valor * 0.05 * $UF->get())}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<form class="ui form" id="desistir_form">
|
||||||
|
<div class="three wide field">
|
||||||
|
<label for="fecha">Fecha</label>
|
||||||
|
<div class="ui calendar" id="fecha">
|
||||||
|
<div class="ui left icon input">
|
||||||
|
<i class="calendar icon"></i>
|
||||||
|
<input type="text" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="three wide field">
|
||||||
|
<label for="devolucion">Devolución [$]</label>
|
||||||
|
<div class="ui left labeled input">
|
||||||
|
<div class="ui basic label">$</div>
|
||||||
|
<input type="text" name="devolucion" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<button class="ui button">Desistir</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
@endsection
|
||||||
|
|
||||||
|
@push('page_scripts')
|
||||||
|
<script>
|
||||||
|
$(document).ready(() => {
|
||||||
|
$('#fecha').calendar(calendar_date_options)
|
||||||
|
$('#desistir_form').submit(event => {
|
||||||
|
event.preventDefault()
|
||||||
|
const body = new FormData(event.currentTarget)
|
||||||
|
const fecha = $('#fecha').calendar('get date')
|
||||||
|
body.set('fecha', fecha.toISOString())
|
||||||
|
const url = '{{$urls->api}}/venta/{{$venta->id}}/desistir'
|
||||||
|
fetchAPI(url, {method: 'post', body}).then(response => {
|
||||||
|
if (!response) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
response.json().then(json => {
|
||||||
|
if (json.desistida) {
|
||||||
|
window.location = '{{$urls->base}}/venta/{{$venta->id}}'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
return false
|
||||||
|
})
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
@endpush
|
@ -26,6 +26,14 @@
|
|||||||
<a href="{{$urls->base}}/venta/{{$venta->id}}/ceder">
|
<a href="{{$urls->base}}/venta/{{$venta->id}}/ceder">
|
||||||
Ceder <i clasS="right chevron icon"></i>
|
Ceder <i clasS="right chevron icon"></i>
|
||||||
</a>
|
</a>
|
||||||
|
@else
|
||||||
|
<div class="ui red icon label">
|
||||||
|
<i class="ban icon"></i>
|
||||||
|
{{ucwords($venta->currentEstado()->tipoEstadoVenta->descripcion)}}
|
||||||
|
(<a href="{{$urls->base}}/venta/{{$venta->id}}/desistida">
|
||||||
|
{{$format->pesos($venta->resciliacion()->valor)}}
|
||||||
|
</a>)
|
||||||
|
</div>
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
<div class="ui segments">
|
<div class="ui segments">
|
||||||
|
@ -244,4 +244,18 @@ class Ventas
|
|||||||
} catch (EmptyResult) {}
|
} catch (EmptyResult) {}
|
||||||
return $this->withJson($response, $output);
|
return $this->withJson($response, $output);
|
||||||
}
|
}
|
||||||
|
public function desistir(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService, int $venta_id): ResponseInterface
|
||||||
|
{
|
||||||
|
$data = $request->getParsedBody();
|
||||||
|
$output = [
|
||||||
|
'input' => $data,
|
||||||
|
'venta_id' => $venta_id,
|
||||||
|
'desistida' => false
|
||||||
|
];
|
||||||
|
try {
|
||||||
|
$venta = $ventaService->getById($venta_id);
|
||||||
|
$output['desistida'] = $ventaService->desistir($venta, $data);
|
||||||
|
} catch (EmptyResult) {}
|
||||||
|
return $this->withJson($response, $output);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
85
app/src/Controller/API/Ventas/Pagos.php
Normal file
85
app/src/Controller/API/Ventas/Pagos.php
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
<?php
|
||||||
|
namespace Incoviba\Controller\API\Ventas;
|
||||||
|
|
||||||
|
use DateTimeImmutable;
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||||
|
use Incoviba\Controller\API\withJson;
|
||||||
|
use Incoviba\Repository;
|
||||||
|
use Incoviba\Service;
|
||||||
|
|
||||||
|
class Pagos
|
||||||
|
{
|
||||||
|
use withJson;
|
||||||
|
|
||||||
|
public function edit(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Pago $pagoRepository, int $pago_id): ResponseInterface
|
||||||
|
{
|
||||||
|
$body = $request->getParsedBody();
|
||||||
|
$output = [
|
||||||
|
'input' => $body,
|
||||||
|
'pago_id' => $pago_id,
|
||||||
|
'pago' => null
|
||||||
|
];
|
||||||
|
try {
|
||||||
|
$pago = $pagoRepository->fetchById($pago_id);
|
||||||
|
if (isset($body['fecha'])) {
|
||||||
|
$fecha = new DateTimeImmutable($body['fecha']);
|
||||||
|
$body['fecha'] = $fecha->format('Y-m-d');
|
||||||
|
}
|
||||||
|
$output['pago'] = $pagoRepository->edit($pago, $body);
|
||||||
|
} catch (EmptyResult) {}
|
||||||
|
return $this->withJson($response, $output);
|
||||||
|
}
|
||||||
|
// NOT IMPLEMENTED
|
||||||
|
public function depositar(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService): ResponseInterface
|
||||||
|
{
|
||||||
|
$body = $request->getBody();
|
||||||
|
$json = json_decode($body->getContents());
|
||||||
|
$date = new DateTimeImmutable($json->fecha);
|
||||||
|
$response->getBody()->write(json_encode(['fecha' => $date->format('d-m-Y'), 'message' => 'Not implemented']));
|
||||||
|
return $response->withHeader('Content-Type', 'application/json');
|
||||||
|
}
|
||||||
|
// NOT IMPLEMENTED
|
||||||
|
public function abonar(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService): ResponseInterface
|
||||||
|
{
|
||||||
|
$body = $request->getBody();
|
||||||
|
$json = json_decode($body->getContents());
|
||||||
|
$date = new DateTimeImmutable($json->fecha);
|
||||||
|
$response->getBody()->write(json_encode(['fecha' => $date->format('d-m-Y'), 'message' => 'Not implemented']));
|
||||||
|
return $response->withHeader('Content-Type', 'application/json');
|
||||||
|
}
|
||||||
|
public function para_pendientes(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService): ResponseInterface
|
||||||
|
{
|
||||||
|
$pagos = $pagoService->getPendientes();
|
||||||
|
$pagos_pendientes = [];
|
||||||
|
foreach ($pagos as $pago) {
|
||||||
|
$pagos_pendientes []= [
|
||||||
|
'id' => $pago->id
|
||||||
|
];
|
||||||
|
}
|
||||||
|
return $this->withJson($response, ['pagos' => $pagos_pendientes, 'total' => count($pagos_pendientes)]);
|
||||||
|
}
|
||||||
|
public function para_abonar(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService): ResponseInterface
|
||||||
|
{
|
||||||
|
$pagos = $pagoService->getDepositados();
|
||||||
|
$pagos_depositados = [];
|
||||||
|
foreach ($pagos as $pago) {
|
||||||
|
$pagos_depositados []= [
|
||||||
|
'id' => $pago->id
|
||||||
|
];
|
||||||
|
}
|
||||||
|
return $this->withJson($response, ['pagos' => $pagos_depositados, 'total' => count($pagos_depositados)]);
|
||||||
|
}
|
||||||
|
public function rebotes(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService): ResponseInterface
|
||||||
|
{
|
||||||
|
$pagos = $pagoService->getRebotes();
|
||||||
|
$rebotes = [];
|
||||||
|
foreach ($pagos as $pago) {
|
||||||
|
$rebotes []= [
|
||||||
|
'id' => $pago->id
|
||||||
|
];
|
||||||
|
}
|
||||||
|
return $this->withJson($response, ['pagos' => $rebotes, 'total' => count($rebotes)]);
|
||||||
|
}
|
||||||
|
}
|
@ -108,4 +108,16 @@ class Ventas
|
|||||||
});
|
});
|
||||||
return $view->render($response, 'ventas.escriturar', compact('venta', 'bancos'));
|
return $view->render($response, 'ventas.escriturar', compact('venta', 'bancos'));
|
||||||
}
|
}
|
||||||
|
public function desistir(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService,
|
||||||
|
View $view, int $venta_id): ResponseInterface
|
||||||
|
{
|
||||||
|
$venta = $ventaService->getById($venta_id);
|
||||||
|
return $view->render($response, 'ventas.desistir', compact('venta'));
|
||||||
|
}
|
||||||
|
public function desistida(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService,
|
||||||
|
View $view, int $venta_id): ResponseInterface
|
||||||
|
{
|
||||||
|
$venta = $ventaService->getById($venta_id);
|
||||||
|
return $view->render($response, 'ventas.desistida', compact('venta'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,56 +13,4 @@ class Pagos
|
|||||||
{
|
{
|
||||||
return $view->render($response, 'ventas.pagos.pendientes');
|
return $view->render($response, 'ventas.pagos.pendientes');
|
||||||
}
|
}
|
||||||
public function depositar(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService): ResponseInterface
|
|
||||||
{
|
|
||||||
$body = $request->getBody();
|
|
||||||
$json = json_decode($body->getContents());
|
|
||||||
$date = new DateTimeImmutable($json->fecha);
|
|
||||||
$response->getBody()->write(json_encode(['fecha' => $date->format('d-m-Y'), 'message' => 'Not implemented']));
|
|
||||||
return $response->withHeader('Content-Type', 'application/json');
|
|
||||||
}
|
|
||||||
public function abonar(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService): ResponseInterface
|
|
||||||
{
|
|
||||||
$body = $request->getBody();
|
|
||||||
$json = json_decode($body->getContents());
|
|
||||||
$date = new DateTimeImmutable($json->fecha);
|
|
||||||
$response->getBody()->write(json_encode(['fecha' => $date->format('d-m-Y'), 'message' => 'Not implemented']));
|
|
||||||
return $response->withHeader('Content-Type', 'application/json');
|
|
||||||
}
|
|
||||||
public function para_pendientes(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService): ResponseInterface
|
|
||||||
{
|
|
||||||
$pagos = $pagoService->getPendientes();
|
|
||||||
$pagos_pendientes = [];
|
|
||||||
foreach ($pagos as $pago) {
|
|
||||||
$pagos_pendientes []= [
|
|
||||||
'id' => $pago->id
|
|
||||||
];
|
|
||||||
}
|
|
||||||
$response->getBody()->write(json_encode(['pagos' => $pagos_pendientes, 'total' => count($pagos_pendientes)]));
|
|
||||||
return $response->withHeader('Content-Type', 'application/json');
|
|
||||||
}
|
|
||||||
public function para_abonar(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService): ResponseInterface
|
|
||||||
{
|
|
||||||
$pagos = $pagoService->getDepositados();
|
|
||||||
$pagos_depositados = [];
|
|
||||||
foreach ($pagos as $pago) {
|
|
||||||
$pagos_depositados []= [
|
|
||||||
'id' => $pago->id
|
|
||||||
];
|
|
||||||
}
|
|
||||||
$response->getBody()->write(json_encode(['pagos' => $pagos_depositados, 'total' => count($pagos_depositados)]));
|
|
||||||
return $response->withHeader('Content-Type', 'application/json');
|
|
||||||
}
|
|
||||||
public function rebotes(ServerRequestInterface $request, ResponseInterface $response, Service\Venta\Pago $pagoService): ResponseInterface
|
|
||||||
{
|
|
||||||
$pagos = $pagoService->getRebotes();
|
|
||||||
$rebotes = [];
|
|
||||||
foreach ($pagos as $pago) {
|
|
||||||
$rebotes []= [
|
|
||||||
'id' => $pago->id
|
|
||||||
];
|
|
||||||
}
|
|
||||||
$response->getBody()->write(json_encode(['pagos' => $rebotes, 'total' => count($rebotes)]));
|
|
||||||
return $response->withHeader('Content-Type', 'application/json');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ class Venta extends Ideal\Model
|
|||||||
public bool $relacionado;
|
public bool $relacionado;
|
||||||
protected ?Venta\Entrega $entrega;
|
protected ?Venta\Entrega $entrega;
|
||||||
public float $uf;
|
public float $uf;
|
||||||
|
protected ?Pago $resciliacion;
|
||||||
|
|
||||||
public array $estados;
|
public array $estados;
|
||||||
public Venta\EstadoVenta $currentEstado;
|
public Venta\EstadoVenta $currentEstado;
|
||||||
@ -49,6 +50,13 @@ class Venta extends Ideal\Model
|
|||||||
}
|
}
|
||||||
return $this->entrega;
|
return $this->entrega;
|
||||||
}
|
}
|
||||||
|
public function resciliacion(): ?Venta\Pago
|
||||||
|
{
|
||||||
|
if (!isset($this->resciliacion)) {
|
||||||
|
$this->resciliacion = $this->runFactory('resciliacion');
|
||||||
|
}
|
||||||
|
return $this->resciliacion;
|
||||||
|
}
|
||||||
|
|
||||||
public function estados(): array
|
public function estados(): array
|
||||||
{
|
{
|
||||||
|
@ -34,7 +34,7 @@ class Pago extends Model
|
|||||||
'banco' => $this->banco ?? '',
|
'banco' => $this->banco ?? '',
|
||||||
'tipo_pago' => $this->tipoPago ?? '',
|
'tipo_pago' => $this->tipoPago ?? '',
|
||||||
'identificador' => $this->identificador ?? '',
|
'identificador' => $this->identificador ?? '',
|
||||||
'fecha' => $this->fecha->format('Y-m-d H:i:S') ?? '',
|
'fecha' => $this->fecha->format('Y-m-d H:i:s') ?? '',
|
||||||
'uf' => $this->uf ?? 1,
|
'uf' => $this->uf ?? 1,
|
||||||
'pagador' => $this->pagador ?? '',
|
'pagador' => $this->pagador ?? '',
|
||||||
'asociado' => $this->asociado ?? ''
|
'asociado' => $this->asociado ?? ''
|
||||||
|
@ -115,9 +115,12 @@ class Venta extends Ideal\Repository
|
|||||||
->register('fecha_ingreso', new Implement\Repository\Mapper\DateTime('fecha_ingreso', 'fechaIngreso'))
|
->register('fecha_ingreso', new Implement\Repository\Mapper\DateTime('fecha_ingreso', 'fechaIngreso'))
|
||||||
//->register('avalchile')
|
//->register('avalchile')
|
||||||
//->register('agente')
|
//->register('agente')
|
||||||
|
->register('resciliacion', (new Implement\Repository\Mapper())
|
||||||
|
->setFactory((new Implement\Repository\Factory())
|
||||||
|
->setCallable([$this->pagoService, 'getById'])
|
||||||
|
->setArgs(['pago_id' => $data['resciliacion']])))
|
||||||
->register('relacionado', new Implement\Repository\Mapper\Boolean('relacionado'));
|
->register('relacionado', new Implement\Repository\Mapper\Boolean('relacionado'));
|
||||||
//->register('promocion')
|
//->register('promocion')
|
||||||
//->register('resciliacion')
|
|
||||||
//->register('devolucion');
|
//->register('devolucion');
|
||||||
return $this->parseData(new Model\Venta(), $data, $map);
|
return $this->parseData(new Model\Venta(), $data, $map);
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
namespace Incoviba\Service;
|
namespace Incoviba\Service;
|
||||||
|
|
||||||
use DateTimeInterface;
|
use DateTimeInterface;
|
||||||
|
use DateTimeImmutable;
|
||||||
use Incoviba\Common\Implement\Exception\EmptyRedis;
|
use Incoviba\Common\Implement\Exception\EmptyRedis;
|
||||||
|
|
||||||
class UF
|
class UF
|
||||||
@ -10,8 +11,11 @@ class UF
|
|||||||
|
|
||||||
public function __construct(protected Redis $redisService, protected Money $moneyService) {}
|
public function __construct(protected Redis $redisService, protected Money $moneyService) {}
|
||||||
|
|
||||||
public function get(DateTimeInterface $date): float
|
public function get(?DateTimeInterface $date = null): float
|
||||||
{
|
{
|
||||||
|
if ($date === null) {
|
||||||
|
$date = new DateTimeImmutable();
|
||||||
|
}
|
||||||
$ufs = [];
|
$ufs = [];
|
||||||
try {
|
try {
|
||||||
$ufs = json_decode($this->redisService->get($this->redisKey), JSON_OBJECT_AS_ARRAY);
|
$ufs = json_decode($this->redisService->get($this->redisKey), JSON_OBJECT_AS_ARRAY);
|
||||||
|
@ -20,6 +20,7 @@ class Venta
|
|||||||
protected Venta\Subsidio $subsidioService,
|
protected Venta\Subsidio $subsidioService,
|
||||||
protected Venta\Credito $creditoService,
|
protected Venta\Credito $creditoService,
|
||||||
protected Venta\BonoPie $bonoPieService,
|
protected Venta\BonoPie $bonoPieService,
|
||||||
|
protected Venta\Pago $pagoService,
|
||||||
protected Money $moneyService
|
protected Money $moneyService
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
@ -108,63 +109,6 @@ class Venta
|
|||||||
|
|
||||||
return $venta;
|
return $venta;
|
||||||
}
|
}
|
||||||
public function escriturar(Model\Venta $venta, array $data): bool
|
|
||||||
{
|
|
||||||
if (in_array($venta->currentEstado()->tipoEstadoVenta->descripcion, ['escriturando', 'firmado por inmobiliaria', 'archivado'])) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
$tipoEstado = $this->tipoEstadoVentaRepository->fetchByDescripcion('escriturando');
|
|
||||||
if (isset($data['valor_reajuste']) and $data['valor_reajuste'] !== '') {
|
|
||||||
$fecha = new DateTimeImmutable($data['fecha_reajuste']);
|
|
||||||
$reajusteData = [
|
|
||||||
'valor' => $data['valor_reajuste'],
|
|
||||||
'fecha' => $fecha->format('Y-m-d')
|
|
||||||
];
|
|
||||||
$pie = $venta->formaPago()->pie;
|
|
||||||
$this->pieService->reajustar($pie, $reajusteData);
|
|
||||||
}
|
|
||||||
if (isset($data['valor_pago_pesos']) and $data['valor_pago_pesos'] !== '') {
|
|
||||||
$fecha = new DateTimeImmutable($data['fecha_pago']);
|
|
||||||
$uf = $this->moneyService->getUF($fecha);
|
|
||||||
$valor = $data['valor_pago_ufs'] !== '' ? $data['valor_pago_ufs'] * $uf : $data['valor_pago_pesos'];
|
|
||||||
$escrituraData = [
|
|
||||||
'valor' => $valor,
|
|
||||||
'fecha' => $fecha->format('Y-m-d'),
|
|
||||||
'uf' => $uf
|
|
||||||
];
|
|
||||||
$escritura = $this->escrituraRepository->create($escrituraData);
|
|
||||||
$escritura = $this->escrituraRepository->save($escritura);
|
|
||||||
$this->ventaRepository->edit($venta, ['escritura' => $escritura->id]);
|
|
||||||
}
|
|
||||||
if (isset($data['banco_credito']) and $data['banco_credito'] !== '') {
|
|
||||||
$this->creditoRepository->edit($venta->formaPago()->credito, ['banco' => $data['banco_credito']]);
|
|
||||||
}
|
|
||||||
$fecha = new DateTimeImmutable($data['fecha']);
|
|
||||||
$uf = $this->moneyService->getUF($fecha);
|
|
||||||
if (isset($data['valor_subsidio']) and $data['valor_subsidio'] !== '') {
|
|
||||||
$subsidioData = [
|
|
||||||
'fecha_venta' => $fecha->format('Y-m-d'),
|
|
||||||
'ahorro' => $data['valor_ahorro'],
|
|
||||||
'subsidio' => $data['valor_subsidio'],
|
|
||||||
'uf' => $uf
|
|
||||||
];
|
|
||||||
$subsidio = $this->addSubsidio($subsidioData);
|
|
||||||
$this->ventaRepository->edit($venta, ['subsidio' => $subsidio->id]);
|
|
||||||
}
|
|
||||||
$estadoData = [
|
|
||||||
'venta' => $venta->id,
|
|
||||||
'estado' => $tipoEstado->id,
|
|
||||||
'fecha' => $fecha->format('Y-m-d')
|
|
||||||
];
|
|
||||||
$estado = $this->estadoVentaRepository->create($estadoData);
|
|
||||||
$this->estadoVentaRepository->save($estado);
|
|
||||||
return true;
|
|
||||||
} catch (Implement\Exception\EmptyResult) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function addPropietario(array $data): Model\Venta\Propietario
|
protected function addPropietario(array $data): Model\Venta\Propietario
|
||||||
{
|
{
|
||||||
if (isset($data['natural_uno'])) {
|
if (isset($data['natural_uno'])) {
|
||||||
@ -344,4 +288,110 @@ class Venta
|
|||||||
], $filtered_data);
|
], $filtered_data);
|
||||||
return $this->bonoPieService->add($mapped_data);
|
return $this->bonoPieService->add($mapped_data);
|
||||||
}
|
}
|
||||||
|
protected function addEstado(Model\Venta $venta, Model\Venta\TipoEstadoVenta $tipoEstadoVenta, array $data): void
|
||||||
|
{
|
||||||
|
$fecha = new DateTimeImmutable($data['fecha']);
|
||||||
|
$estadoData = [
|
||||||
|
'venta' => $venta->id,
|
||||||
|
'estado' => $tipoEstadoVenta->id,
|
||||||
|
'fecha' => $fecha->format('Y-m-d')
|
||||||
|
];
|
||||||
|
$estado = $this->estadoVentaRepository->create($estadoData);
|
||||||
|
$this->estadoVentaRepository->save($estado);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function escriturar(Model\Venta $venta, array $data): bool
|
||||||
|
{
|
||||||
|
if (in_array($venta->currentEstado()->tipoEstadoVenta->descripcion, ['escriturando', 'firmado por inmobiliaria', 'archivado'])) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if ($this->validarData($data, ['fecha_reajuste', 'valor_reajuste'])) {
|
||||||
|
$this->reajustarEscritura($venta, $data);
|
||||||
|
}
|
||||||
|
if ($this->validarData($data, ['fecha_pago'], ['valor_pago_pesos', 'valor_pago_ufs'])) {
|
||||||
|
$this->abonoEscritura($venta, $data);
|
||||||
|
}
|
||||||
|
if ($this->validarData($data, ['banco_credito'])) {
|
||||||
|
$this->creditoRepository->edit($venta->formaPago()->credito, ['banco' => $data['banco_credito']]);
|
||||||
|
}
|
||||||
|
if ($this->validarData($data, ['valor_subsidio', 'valor_ahorro', 'fecha'])) {
|
||||||
|
$this->subsidioEscritura($venta, $data);
|
||||||
|
}
|
||||||
|
$tipoEstado = $this->tipoEstadoVentaRepository->fetchByDescripcion('escriturando');
|
||||||
|
$this->addEstado($venta, $tipoEstado, ['fecha' => $data['fecha']]);
|
||||||
|
return true;
|
||||||
|
} catch (Implement\Exception\EmptyResult) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected function validarData(array $data, array $keys, array $optionals = []): bool
|
||||||
|
{
|
||||||
|
foreach ($keys as $key) {
|
||||||
|
if (!isset($data[$key])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ($data[$key] === '') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach ($optionals as $key) {
|
||||||
|
if (isset($data[$key]) and $data[$key] !== '') {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
protected function reajustarEscritura(Model\Venta $venta, array $data): void
|
||||||
|
{
|
||||||
|
$fecha = new DateTimeImmutable($data['fecha_reajuste']);
|
||||||
|
$reajusteData = [
|
||||||
|
'valor' => $data['valor_reajuste'],
|
||||||
|
'fecha' => $fecha->format('Y-m-d')
|
||||||
|
];
|
||||||
|
$pie = $venta->formaPago()->pie;
|
||||||
|
$this->pieService->reajustar($pie, $reajusteData);
|
||||||
|
}
|
||||||
|
protected function abonoEscritura(Model\Venta $venta, array $data): void
|
||||||
|
{
|
||||||
|
$fecha = new DateTimeImmutable($data['fecha_pago']);
|
||||||
|
$uf = $this->moneyService->getUF($fecha);
|
||||||
|
$valor = $data['valor_pago_ufs'] !== '' ? $data['valor_pago_ufs'] * $uf : $data['valor_pago_pesos'];
|
||||||
|
$escrituraData = [
|
||||||
|
'valor' => $valor,
|
||||||
|
'fecha' => $fecha->format('Y-m-d'),
|
||||||
|
'uf' => $uf
|
||||||
|
];
|
||||||
|
$escritura = $this->escrituraRepository->create($escrituraData);
|
||||||
|
$escritura = $this->escrituraRepository->save($escritura);
|
||||||
|
$this->ventaRepository->edit($venta, ['escritura' => $escritura->id]);
|
||||||
|
}
|
||||||
|
protected function subsidioEscritura(Model\Venta $venta, array $data): void
|
||||||
|
{
|
||||||
|
$fecha = new DateTimeImmutable($data['fecha']);
|
||||||
|
$uf = $this->moneyService->getUF($fecha);
|
||||||
|
$subsidioData = [
|
||||||
|
'fecha_venta' => $fecha->format('Y-m-d'),
|
||||||
|
'ahorro' => $data['valor_ahorro'],
|
||||||
|
'subsidio' => $data['valor_subsidio'],
|
||||||
|
'uf' => $uf
|
||||||
|
];
|
||||||
|
$subsidio = $this->addSubsidio($subsidioData);
|
||||||
|
$this->ventaRepository->edit($venta, ['subsidio' => $subsidio->id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function desistir(Model\Venta $venta, array $data): bool
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if ($this->validarData($data, ['fecha', 'devolucion'])) {
|
||||||
|
$pago = $this->pagoService->add(['fecha' => $data['fecha'], 'valor' => $data['devolucion']]);
|
||||||
|
$this->ventaRepository->edit($venta, ['resciliacion' => $pago->id]);
|
||||||
|
}
|
||||||
|
$tipoEstado = $this->tipoEstadoVentaRepository->fetchByDescripcion('desistida');
|
||||||
|
$this->addEstado($venta, $tipoEstado, ['fecha' => $data['fecha']]);
|
||||||
|
return true;
|
||||||
|
} catch (Implement\Exception\EmptyResult) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user