FIX: Fechas revisadas.
This commit is contained in:
@ -251,12 +251,21 @@
|
||||
event.preventDefault()
|
||||
const url = '{{$urls->api}}/venta/{{$venta->id}}/escriturar'
|
||||
const body = new FormData(event.currentTarget)
|
||||
body.set('fecha', $('#fecha').calendar('get date').toISOString())
|
||||
if (body.get('fecha_pago') !== '') {
|
||||
body.set('fecha_pago', $('#fecha_pago').calendar('get date').toISOString())
|
||||
const fecha = $('#fecha').calendar('get date')
|
||||
body.set('fecha', [fecha.getFullYear(), fecha.getMonth()+1, fecha.getDate()].join('-'))
|
||||
const $fechaPago = $('#fecha_pago')
|
||||
if ($fechaPago.length > 0) {
|
||||
const fechaPago = $fechaPago.calendar('get date')
|
||||
if (fechaPago !== null) {
|
||||
body.set('fecha_pago', [fechaPago.getFullYear(), fechaPago.getMonth()+1, fechaPago.getDate()].join('-'))
|
||||
}
|
||||
}
|
||||
const $fechaReajuste = $('#fecha_reajuste')
|
||||
if ($fechaReajuste.length > 0) {
|
||||
const fechaReajuste = $fechaReajuste.calendar('get date')
|
||||
if (fechaReajuste !== null) {
|
||||
body.set('fecha_reajuste', [fechaReajuste.getFullYear(), fechaReajuste.getMonth()+1, fechaReajuste.getDate()].join('-'))
|
||||
}
|
||||
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) {
|
||||
|
@ -285,12 +285,13 @@ class Venta extends Service
|
||||
return $this->formaPagoService->add($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function addEstado(Model\Venta $venta, Model\Venta\TipoEstadoVenta $tipoEstadoVenta, array $data): void
|
||||
{
|
||||
try {
|
||||
$fecha = new DateTimeImmutable($data['fecha']);
|
||||
} catch (\DateMalformedStringException) {
|
||||
$fecha = new DateTimeImmutable();
|
||||
}
|
||||
$estadoData = [
|
||||
'venta' => $venta->id,
|
||||
'estado' => $tipoEstadoVenta->id,
|
||||
@ -343,12 +344,13 @@ class Venta extends Service
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function reajustarEscritura(Model\Venta $venta, array $data): void
|
||||
{
|
||||
try {
|
||||
$fecha = new DateTimeImmutable($data['fecha_reajuste']);
|
||||
} catch (\DateMalformedStringException) {
|
||||
$fecha = new DateTimeImmutable();
|
||||
}
|
||||
$reajusteData = [
|
||||
'valor' => $this->valorService->clean($data['valor_reajuste']),
|
||||
'fecha' => $fecha->format('Y-m-d')
|
||||
@ -357,12 +359,13 @@ class Venta extends Service
|
||||
$this->pieService->reajustar($pie, $reajusteData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function abonoEscritura(Model\Venta $venta, array $data): void
|
||||
{
|
||||
try {
|
||||
$fecha = new DateTimeImmutable($data['fecha_pago']);
|
||||
} catch (\DateMalformedStringException) {
|
||||
$fecha = new DateTimeImmutable();
|
||||
}
|
||||
$uf = $this->moneyService->getUF($fecha);
|
||||
$valor = $data['valor_pago_ufs'] !== '' ? $this->valorService->clean($data['valor_pago_ufs']) * $uf : $this->valorService->clean($data['valor_pago_pesos']);
|
||||
$pagoData = [
|
||||
@ -382,12 +385,13 @@ class Venta extends Service
|
||||
$this->ventaRepository->edit($venta, ['escritura' => $escritura->id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function subsidioEscritura(Model\Venta $venta, array $data): void
|
||||
{
|
||||
try {
|
||||
$fecha = new DateTimeImmutable($data['fecha']);
|
||||
} catch (\DateMalformedStringException) {
|
||||
$fecha = new DateTimeImmutable();
|
||||
}
|
||||
$uf = $this->moneyService->getUF($fecha);
|
||||
$subsidioData = [
|
||||
'fecha_venta' => $fecha->format('Y-m-d'),
|
||||
@ -399,15 +403,19 @@ class Venta extends Service
|
||||
$this->ventaRepository->edit($venta, ['subsidio' => $subsidio->id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function editCredito(Model\Venta $venta, array $data): void
|
||||
{
|
||||
try {
|
||||
$fecha = new DateTimeImmutable($data['fecha']);
|
||||
} catch (\DateMalformedStringException) {
|
||||
$fecha = new DateTimeImmutable();
|
||||
}
|
||||
$uf = $this->moneyService->getUF($fecha);
|
||||
$valor = $this->valorService->clean($data['valor_credito']) * $uf;
|
||||
if ($venta->formaPago()->credito === null) {
|
||||
if ($data['valor_credito'] === 0) {
|
||||
return;
|
||||
}
|
||||
$pagoData = [
|
||||
'valor' => $valor,
|
||||
'fecha' => $fecha->format('Y-m-d'),
|
||||
@ -424,6 +432,12 @@ class Venta extends Service
|
||||
$this->ventaRepository->edit($venta, ['credito' => $credito->id]);
|
||||
return;
|
||||
}
|
||||
if ($data['valor_credito'] === 0) {
|
||||
$this->pagoRepository->remove($venta->formaPago()->credito->pago);
|
||||
$this->creditoRepository->remove($venta->formaPago()->credito);
|
||||
$this->ventaRepository->edit($venta, ['credito' => null]);
|
||||
return;
|
||||
}
|
||||
$this->pagoRepository->edit($venta->formaPago()->credito->pago, [
|
||||
'valor' => $valor,
|
||||
'banco' => $data['banco_credito'],
|
||||
|
@ -117,13 +117,14 @@ class Pago
|
||||
return $this->process($this->pagoRepository->fetchDevolucionByVenta($venta_id));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function add(array $data): Model\Venta\Pago
|
||||
{
|
||||
if (!isset($data['uf'])) {
|
||||
try {
|
||||
$data['uf'] = $this->ufService->get(new DateTimeImmutable($data['fecha']));
|
||||
} catch (\DateMalformedStringException) {
|
||||
$data['uf'] = 0;
|
||||
}
|
||||
}
|
||||
$filtered_data = $this->pagoRepository->filterData($data);
|
||||
$filtered_data['valor'] = round($this->valorService->clean($filtered_data['valor']));
|
||||
@ -141,16 +142,21 @@ class Pago
|
||||
return $pago;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function edit(Model\Venta\Pago $pago, array $data): Model\Venta\Pago
|
||||
{
|
||||
if (array_key_exists('fecha', $data)) {
|
||||
try {
|
||||
$data['fecha'] = (new DateTimeImmutable($data['fecha']))->format('Y-m-d');
|
||||
} catch (\DateMalformedStringException) {
|
||||
$data['fecha'] = (new DateTimeImmutable())->format('Y-m-d');
|
||||
}
|
||||
}
|
||||
if (array_key_exists('uf', $data)) {
|
||||
try {
|
||||
$data['uf'] = $this->ufService->get(new DateTimeImmutable($data['fecha']));
|
||||
} catch (\DateMalformedStringException) {
|
||||
$data['uf'] = 0;
|
||||
}
|
||||
}
|
||||
$filteredData = $this->pagoRepository->filterData($data);
|
||||
if (array_key_exists('valor', $filteredData)) {
|
||||
|
Reference in New Issue
Block a user