Base
This commit is contained in:
57
app/Controller/Bonos.php
Normal file
57
app/Controller/Bonos.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Definition\Controller;
|
||||
use Incoviba\old\Venta\Venta;
|
||||
use Incoviba\old\Venta\BonoPie;
|
||||
use Incoviba\old\Venta\Pago;
|
||||
|
||||
class Bonos
|
||||
{
|
||||
use Controller;
|
||||
|
||||
public static function add()
|
||||
{
|
||||
$id_venta = get('venta');
|
||||
$venta = model(Venta::class)->findOne($id_venta);
|
||||
return view('ventas.bonos.add', compact('venta'));
|
||||
}
|
||||
public static function do_add()
|
||||
{
|
||||
$id_venta = get('venta');
|
||||
$venta = model(Venta::class)->findOne($id_venta);
|
||||
if ($venta->bono_pie != 0) {
|
||||
header('Location: ' . nUrl('ventas', 'show', ['venta' => $venta->id]));
|
||||
return;
|
||||
}
|
||||
$uf = uf($venta->fecha());
|
||||
$valor = post('valor');
|
||||
$data = [
|
||||
'fecha' => $venta->fecha,
|
||||
'valor' => $valor * $uf->uf->value,
|
||||
'tipo' => 8,
|
||||
'uf' => $uf->uf->value
|
||||
];
|
||||
$pago = model(Pago::class)->create($data);
|
||||
$pago->save();
|
||||
$data = [
|
||||
'valor' => $valor,
|
||||
'pago' => $pago->id
|
||||
];
|
||||
$bono = model(BonoPie::class)->create($data);
|
||||
$bono->save();
|
||||
$venta->bono_pie = $bono->id;
|
||||
$venta->save();
|
||||
header('Location: ' . nUrl('ventas', 'show', ['venta' => $venta->id]));
|
||||
}
|
||||
public static function edit()
|
||||
{
|
||||
$id_venta = get('venta');
|
||||
$venta = model(Venta::class)->findOne($id_venta);
|
||||
return view('ventas.bonos.edit', compact('venta'));
|
||||
}
|
||||
public static function do_edit()
|
||||
{
|
||||
d(post());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user