99 lines
2.4 KiB
PHP
99 lines
2.4 KiB
PHP
|
<?php
|
||
|
namespace App\Controller;
|
||
|
|
||
|
use App\Definition\Controller;
|
||
|
use Incoviba\old\Venta\Venta;
|
||
|
use Carbon\Carbon;
|
||
|
use Incoviba\old\Venta\Pie;
|
||
|
use Incoviba\old\Venta\Escritura;
|
||
|
use Incoviba\old\Venta\Pago;
|
||
|
|
||
|
class FormaPago
|
||
|
{
|
||
|
use Controller;
|
||
|
|
||
|
public static function edit()
|
||
|
{
|
||
|
$id = get('venta');
|
||
|
$venta = model(Venta::class)->findOne($id);
|
||
|
|
||
|
return view('ventas.forma_pago.edit', compact('venta'));
|
||
|
}
|
||
|
public static function editar()
|
||
|
{
|
||
|
d(post());
|
||
|
$id = get('venta');
|
||
|
$venta = model(Venta::class)->findOne($id);
|
||
|
|
||
|
$valor = correctNumber(post('valor_pie'));
|
||
|
$cuotas = post('cuotas_pie');
|
||
|
if ($venta->pie != 0) {
|
||
|
$pie = $venta->pie();
|
||
|
$changed = false;
|
||
|
if ($pie->valor != $valor) {
|
||
|
$pie->valor = $valor;
|
||
|
$changed = true;
|
||
|
}
|
||
|
if ($pie->cuotas != $cuotas) {
|
||
|
$pie->cuotas = $cuotas;
|
||
|
$changed = true;
|
||
|
}
|
||
|
if ($changed) {
|
||
|
d($pie);
|
||
|
}
|
||
|
|
||
|
$valor = correctNumber(post('valor_reajuste'));
|
||
|
$f = Carbon::createFromDate(post('year_reajuste'), post('month_reajuste'), post('day_reajuste'), config('app.timezone'));
|
||
|
$uf = uf($f);
|
||
|
$reajuste = $pie->reajuste();
|
||
|
$changed = false;
|
||
|
if ($reajuste->valor != $valor) {
|
||
|
$reajuste->valor = $valor;
|
||
|
$changed = true;
|
||
|
}
|
||
|
if ($reajuste->fecha != $f->format('Y-m-d')) {
|
||
|
$reajuste->fecha = $f->format('Y-m-d');
|
||
|
$reajuste->uf = $uf->uf->value;
|
||
|
$changed = true;
|
||
|
}
|
||
|
if ($changed) {
|
||
|
d($reajuste);
|
||
|
}
|
||
|
} elseif ($valor != '') {
|
||
|
$f = Carbon::parse($venta->fecha, config('app.timezone'));
|
||
|
$uf = uf($f);
|
||
|
$data = [
|
||
|
'valor' => $valor,
|
||
|
'cuotas' => $cuotas,
|
||
|
'uf' => $uf->uf->value,
|
||
|
'fecha' => $f->format('Y-m-d')
|
||
|
];
|
||
|
$pie = model(Pie::class)->create($data);
|
||
|
d($pie);
|
||
|
}
|
||
|
|
||
|
$valor = correctNumber(post('valor_escritura'));
|
||
|
$f = Carbon::createFromDate(post('year_escritura'), post('month_escritura'), post('day_escritura'), config('app.timezone'));
|
||
|
if ($venta->escritura != 0) {
|
||
|
$escritura = $venta->escritura();
|
||
|
d($escritura);
|
||
|
} elseif ($valor != '') {
|
||
|
$data = [
|
||
|
'valor' => $valor,
|
||
|
'fecha' => $f->format('Y-m-d'),
|
||
|
'uf' => $uf->uf->value,
|
||
|
'tipo' => 7
|
||
|
];
|
||
|
$pago = model(Pago::class)->create($data);
|
||
|
$pago->newPagado();
|
||
|
$data['pago'] = $pago->id;
|
||
|
unset($data['tipo']);
|
||
|
$escritura = model(Escritura::class)->create($data);
|
||
|
$escritura->save();
|
||
|
$venta->escritura = $escritura->id;
|
||
|
$venta->save();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
?>
|