105 lines
2.8 KiB
PHP
105 lines
2.8 KiB
PHP
<?php
|
|
namespace App\Controller;
|
|
|
|
use App\Definition\Controller;
|
|
use Incoviba\old\Venta\Pie;
|
|
use Incoviba\old\Venta\Venta;
|
|
use Incoviba\old\Venta\Pago;
|
|
use Carbon\Carbon;
|
|
|
|
class Pies
|
|
{
|
|
use Controller;
|
|
|
|
protected static function setDefault()
|
|
{
|
|
self::$default = self::list();
|
|
}
|
|
public static function list()
|
|
{
|
|
$proyecto = get('proyecto');
|
|
if ($proyecto == null) {
|
|
return self::listProyectos();
|
|
}
|
|
$proyecto = \Model::factory(Proyecto::class)->findOne($proyecto);
|
|
$ventas = $proyecto->ventas();
|
|
self::sort($ventas);
|
|
return view('ventas.list', compact('proyecto', 'ventas'));
|
|
}
|
|
public static function listProyectos()
|
|
{
|
|
$proyectos = \Model::factory(Proyecto::class)
|
|
->select('proyecto.*')
|
|
->join('estado_proyecto', ['estado.proyecto', '=', 'proyecto.id'], 'estado')
|
|
->join('tipo_estado_proyecto', ['tipo.id', '=', 'estado.estado'], 'tipo')
|
|
->join('etapa_proyecto', ['etapa.id', '=', 'tipo.etapa'], 'etapa')
|
|
->whereGte('etapa.orden', 4)
|
|
->groupBy('proyecto.id')
|
|
->findMany();
|
|
echo view('ventas.proyectos', compact('proyectos'));
|
|
}
|
|
public static function resumen()
|
|
{
|
|
$id = get('pie');
|
|
$pie = \Model::factory(\Incoviba\old\Venta\Pie::class)->findOne($id);
|
|
$venta = $pie->venta();
|
|
return view('ventas.pies.resumen', compact('venta'));
|
|
}
|
|
public static function reajustar()
|
|
{
|
|
$id = get('venta');
|
|
$venta = \Model::factory(Venta::class)->findOne($id);
|
|
return view('ventas.pies.reajustar', compact('venta'));
|
|
}
|
|
public static function reajuste()
|
|
{
|
|
$id = get('venta');
|
|
$venta = \Model::factory(Venta::class)->findOne($id);
|
|
|
|
$f = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone'));
|
|
$pago = \Model::factory(Pago::class)->create();
|
|
$pago->fecha = $f->format('Y-m-d');
|
|
$pago->uf = (float) uf($f)->uf->value;
|
|
$pago->valor = str_replace('.', '', post('valor'));
|
|
|
|
$pago->new();
|
|
|
|
$pie = $venta->pie();
|
|
$pie->reajuste = $pago->id;
|
|
$pie->save();
|
|
header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id]));
|
|
}
|
|
public static function edit()
|
|
{
|
|
$id = get('venta');
|
|
$venta = \Model::factory(Venta::class)->findOne($id);
|
|
return view('ventas.pies.edit', compact('venta'));
|
|
}
|
|
public static function editar()
|
|
{
|
|
$id = get('venta');
|
|
$venta = \Model::factory(Venta::class)->findOne($id);
|
|
$pie = $venta->pie();
|
|
$valor = correctNumber(post('valor'));
|
|
if ($pie->valor != $valor) {
|
|
$pie->valor = $valor;
|
|
}
|
|
if ($pie->cuotas != post('cuotas')) {
|
|
$pie->cuotas = post('cuotas');
|
|
}
|
|
|
|
$pie->save();
|
|
header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $venta->id]));
|
|
}
|
|
public static function asociar()
|
|
{
|
|
$id = get('pie');
|
|
$pie = \Model::factory(Pie::class)->findOne($id);
|
|
$pie->asociado = post('asociado');
|
|
|
|
$pie->save();
|
|
header('Location: ' . url('', ['p' => 'ventas', 'a' => 'show', 'venta' => $pie->venta()->id]));
|
|
}
|
|
}
|
|
?>
|