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