Base
This commit is contained in:
77
app/Controller/ProyectoTipoUnidades.php
Normal file
77
app/Controller/ProyectoTipoUnidades.php
Normal file
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Definition\Controller;
|
||||
use Incoviba\old\Proyecto\Proyecto;
|
||||
use Incoviba\old\Proyecto\ProyectoTipoUnidad;
|
||||
use Incoviba\old\Venta\Unidad;
|
||||
use Incoviba\old\Venta\TipoUnidad;
|
||||
|
||||
class ProyectoTipoUnidades
|
||||
{
|
||||
use Controller;
|
||||
|
||||
protected static function setDefault()
|
||||
{
|
||||
self::$default = self::list();
|
||||
}
|
||||
public static function list()
|
||||
{
|
||||
d(get());
|
||||
}
|
||||
public static function edit()
|
||||
{
|
||||
$id = get('tipo_unidad');
|
||||
$tipo = model(ProyectoTipoUnidad::class)->findOne($id);
|
||||
$tipos = model(TipoUnidad::class)->findMany();
|
||||
|
||||
return view('proyectos.tipo_unidades.edit', compact('tipo', 'tipos'));
|
||||
}
|
||||
public static function editar()
|
||||
{
|
||||
$id = get('tipo_unidad');
|
||||
$tipo = model(ProyectoTipoUnidad::class)->findOne($id);
|
||||
|
||||
$changed = false;
|
||||
foreach (post() as $field => $value) {
|
||||
if ($tipo->{$field} != $value) {
|
||||
$tipo->{$field} = $value;
|
||||
$changed = true;
|
||||
}
|
||||
}
|
||||
if ($changed) {
|
||||
$tipo->save();
|
||||
}
|
||||
header('Location: ' . nUrl('proyectos', 'list_unidades', ['proyecto' => $tipo->proyecto()->id]));
|
||||
}
|
||||
public static function add_unidad()
|
||||
{
|
||||
$id = get('tipo_unidad');
|
||||
$tipo = model(ProyectoTipoUnidad::class)->findOne($id);
|
||||
if ($tipo->tipo()->descripcion == 'departamento') {
|
||||
return view('proyectos.unidades.add', compact('tipo'));
|
||||
}
|
||||
return view('proyectos.unidades.add2', compact('tipo'));
|
||||
}
|
||||
public static function assign()
|
||||
{
|
||||
$id = get('proyecto');
|
||||
$proyecto = model(Proyecto::class)->findOne($id);
|
||||
$tipos = model(ProyectoTipoUnidad::class)->where('proyecto', $proyecto->id)->findMany();
|
||||
$libres = model(Unidad::class)->where('proyecto', $proyecto->id)->where('pt', 0)->findMany();
|
||||
|
||||
return view('proyectos.unidades.assign', compact('proyecto', 'tipos', 'libres'));
|
||||
}
|
||||
public static function asignar()
|
||||
{
|
||||
$id = get('proyecto');
|
||||
$proyecto = model(Proyecto::class)->findOne($id);
|
||||
|
||||
$libres = model(Unidad::class)->where('proyecto', $proyecto->id)->where('pt', 0)->findMany();
|
||||
foreach ($libres as $unidad) {
|
||||
$unidad->pt = post('tipo' . $unidad->id);
|
||||
$unidad->save();
|
||||
}
|
||||
header('Location: ' . nUrl('proyectos', 'list_unidades', ['proyecto' => $proyecto->id]));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user