FIX: escriturar
This commit is contained in:
@ -86,7 +86,7 @@
|
|||||||
<div class="ui calendar" id="fecha_pago">
|
<div class="ui calendar" id="fecha_pago">
|
||||||
<div class="ui left icon input">
|
<div class="ui left icon input">
|
||||||
<i class="calendar icon"></i>
|
<i class="calendar icon"></i>
|
||||||
<input type="text" class="fecha_pago" />
|
<input type="text" name="fecha_pago" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -160,13 +160,13 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
@if (isset($venta->formaPago()->credito) and $venta->formaPago()->credito->pago->banco === null)
|
@if (!isset($venta->formaPago()->credito) or $venta->formaPago()->credito->pago->banco === null)
|
||||||
<h4 class="ui header">Crédito</h4>
|
<h4 class="ui header">Crédito</h4>
|
||||||
<div class="fields">
|
<div class="fields">
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label for="valor_credito">Valor [UF]</label>
|
<label for="valor_credito">Valor [UF]</label>
|
||||||
<div class="ui right labeled disabled input">
|
<div class="ui right labeled input">
|
||||||
<input type="text" value="{{$format->number($venta->formaPago()->credito->pago->valor(), 2)}}" />
|
<input type="text" id="valor_credito" name="valor_credito" value="{{$venta->formaPago()->credito?->pago->valor() ?? ''}}" />
|
||||||
<div class="ui basic label">UF</div>
|
<div class="ui basic label">UF</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -254,9 +254,15 @@
|
|||||||
$('#escriturar_form').submit(event => {
|
$('#escriturar_form').submit(event => {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
const url = '{{$urls->api}}/venta/{{$venta->id}}/escriturar'
|
const url = '{{$urls->api}}/venta/{{$venta->id}}/escriturar'
|
||||||
const data = new FormData(event.currentTarget)
|
const body = new FormData(event.currentTarget)
|
||||||
data.set('fecha', $('#fecha').calendar('get date').toISOString())
|
body.set('fecha', $('#fecha').calendar('get date').toISOString())
|
||||||
fetchAPI(url, {method: 'post', body: data}).then(response => {
|
if (body.get('fecha_pago') !== '') {
|
||||||
|
body.set('fecha_pago', $('#fecha_pago').calendar('get date').toISOString())
|
||||||
|
}
|
||||||
|
if (body.get('fecha_reajuste') !== '') {
|
||||||
|
body.set('fecha_reajuste', $('#fecha_reajuste').calendar('get date').toISOString())
|
||||||
|
}
|
||||||
|
fetchAPI(url, {method: 'post', body}).then(response => {
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
return response.json()
|
return response.json()
|
||||||
}
|
}
|
||||||
@ -267,6 +273,8 @@
|
|||||||
})
|
})
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
|
$('#fecha_pago').calendar(calendar_date_options)
|
||||||
|
$('#fecha_reajuste').calendar(calendar_date_options)
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
@endpush
|
@endpush
|
||||||
|
@ -5,6 +5,7 @@ use DateTimeImmutable;
|
|||||||
use Incoviba\Common\Implement;
|
use Incoviba\Common\Implement;
|
||||||
use Incoviba\Repository;
|
use Incoviba\Repository;
|
||||||
use Incoviba\Model;
|
use Incoviba\Model;
|
||||||
|
use PhpParser\Node\Expr\AssignOp\Mod;
|
||||||
|
|
||||||
class Venta
|
class Venta
|
||||||
{
|
{
|
||||||
@ -14,6 +15,8 @@ class Venta
|
|||||||
protected Repository\Venta\TipoEstadoVenta $tipoEstadoVentaRepository,
|
protected Repository\Venta\TipoEstadoVenta $tipoEstadoVentaRepository,
|
||||||
protected Repository\Venta\Credito $creditoRepository,
|
protected Repository\Venta\Credito $creditoRepository,
|
||||||
protected Repository\Venta\Escritura $escrituraRepository,
|
protected Repository\Venta\Escritura $escrituraRepository,
|
||||||
|
protected Repository\Venta\Pago $pagoRepository,
|
||||||
|
protected Repository\Venta\EstadoPago $estadoPagoRepository,
|
||||||
protected Venta\Propietario $propietarioService,
|
protected Venta\Propietario $propietarioService,
|
||||||
protected Venta\Propiedad $propiedadService,
|
protected Venta\Propiedad $propiedadService,
|
||||||
protected Venta\Pie $pieService,
|
protected Venta\Pie $pieService,
|
||||||
@ -312,8 +315,8 @@ class Venta
|
|||||||
if ($this->validarData($data, ['fecha_pago'], ['valor_pago_pesos', 'valor_pago_ufs'])) {
|
if ($this->validarData($data, ['fecha_pago'], ['valor_pago_pesos', 'valor_pago_ufs'])) {
|
||||||
$this->abonoEscritura($venta, $data);
|
$this->abonoEscritura($venta, $data);
|
||||||
}
|
}
|
||||||
if ($this->validarData($data, ['banco_credito'])) {
|
if ($this->validarData($data, ['banco_credito'], ['valor_credito'])) {
|
||||||
$this->creditoRepository->edit($venta->formaPago()->credito, ['banco' => $data['banco_credito']]);
|
$this->editCredito($venta, $data);
|
||||||
}
|
}
|
||||||
if ($this->validarData($data, ['valor_subsidio', 'valor_ahorro', 'fecha'])) {
|
if ($this->validarData($data, ['valor_subsidio', 'valor_ahorro', 'fecha'])) {
|
||||||
$this->subsidioEscritura($venta, $data);
|
$this->subsidioEscritura($venta, $data);
|
||||||
@ -357,11 +360,18 @@ class Venta
|
|||||||
$fecha = new DateTimeImmutable($data['fecha_pago']);
|
$fecha = new DateTimeImmutable($data['fecha_pago']);
|
||||||
$uf = $this->moneyService->getUF($fecha);
|
$uf = $this->moneyService->getUF($fecha);
|
||||||
$valor = $data['valor_pago_ufs'] !== '' ? $data['valor_pago_ufs'] * $uf : $data['valor_pago_pesos'];
|
$valor = $data['valor_pago_ufs'] !== '' ? $data['valor_pago_ufs'] * $uf : $data['valor_pago_pesos'];
|
||||||
$escrituraData = [
|
$pagoData = [
|
||||||
'valor' => $valor,
|
'valor' => $valor,
|
||||||
'fecha' => $fecha->format('Y-m-d'),
|
'fecha' => $fecha->format('Y-m-d'),
|
||||||
'uf' => $uf
|
'uf' => $uf
|
||||||
];
|
];
|
||||||
|
$pago = $this->pagoService->add($pagoData);
|
||||||
|
$escrituraData = [
|
||||||
|
'valor' => $valor,
|
||||||
|
'fecha' => $fecha->format('Y-m-d'),
|
||||||
|
'uf' => $uf,
|
||||||
|
'pago' => $pago->id
|
||||||
|
];
|
||||||
$escritura = $this->escrituraRepository->create($escrituraData);
|
$escritura = $this->escrituraRepository->create($escrituraData);
|
||||||
$escritura = $this->escrituraRepository->save($escritura);
|
$escritura = $this->escrituraRepository->save($escritura);
|
||||||
$this->ventaRepository->edit($venta, ['escritura' => $escritura->id]);
|
$this->ventaRepository->edit($venta, ['escritura' => $escritura->id]);
|
||||||
@ -379,6 +389,42 @@ class Venta
|
|||||||
$subsidio = $this->addSubsidio($subsidioData);
|
$subsidio = $this->addSubsidio($subsidioData);
|
||||||
$this->ventaRepository->edit($venta, ['subsidio' => $subsidio->id]);
|
$this->ventaRepository->edit($venta, ['subsidio' => $subsidio->id]);
|
||||||
}
|
}
|
||||||
|
protected function editCredito(Model\Venta $venta, array $data): void
|
||||||
|
{
|
||||||
|
$fecha = new DateTimeImmutable($data['fecha']);
|
||||||
|
$uf = $this->moneyService->getUF($fecha);
|
||||||
|
$valor = $data['valor_credito'] * $uf;
|
||||||
|
if ($venta->formaPago()->credito === null) {
|
||||||
|
$pagoData = [
|
||||||
|
'valor' => $valor,
|
||||||
|
'fecha' => $fecha->format('Y-m-d'),
|
||||||
|
'uf' => $uf
|
||||||
|
];
|
||||||
|
$pago = $this->pagoService->add($pagoData);
|
||||||
|
$creditoData = [
|
||||||
|
'banco' => $data['banco_credito'],
|
||||||
|
'valor' => $valor,
|
||||||
|
'pago' => $pago->id
|
||||||
|
];
|
||||||
|
$credito = $this->creditoRepository->create($creditoData);
|
||||||
|
$credito = $this->creditoRepository->save($credito);
|
||||||
|
$this->ventaRepository->edit($venta, ['credito' => $credito->id]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$this->pagoRepository->edit($venta->formaPago()->credito->pago, [
|
||||||
|
'valor' => $valor,
|
||||||
|
'banco' => $data['banco_credito'],
|
||||||
|
'uf' => $uf
|
||||||
|
]);
|
||||||
|
$this->estadoPagoRepository->edit($venta->formaPago()->credito->pago->currentEstado, [
|
||||||
|
'fecha' => $fecha->format('Y-m-d')
|
||||||
|
]);
|
||||||
|
$this->creditoRepository->edit($venta->formaPago()->credito, [
|
||||||
|
'valor' => $valor,
|
||||||
|
'fecha' => $fecha->format('Y-m-d'),
|
||||||
|
'uf' => $uf
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
public function desistir(Model\Venta $venta, array $data): bool
|
public function desistir(Model\Venta $venta, array $data): bool
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user