Base
This commit is contained in:
126
app/Controller/Unidades.php
Normal file
126
app/Controller/Unidades.php
Normal file
@ -0,0 +1,126 @@
|
||||
<?php
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Definition\Controller;
|
||||
use Incoviba\old\Proyecto\Proyecto;
|
||||
use Incoviba\old\Venta\TipoUnidad;
|
||||
use Incoviba\old\Proyecto\ProyectoTipoUnidad;
|
||||
use Incoviba\old\Venta\Unidad;
|
||||
|
||||
class Unidades
|
||||
{
|
||||
use Controller;
|
||||
|
||||
public static function agregar()
|
||||
{
|
||||
$id = get('tipo');
|
||||
$tipo = model(ProyectoTipoUnidad::class)->findOne($id);
|
||||
$len = strlen(post('total'));
|
||||
|
||||
$unis = json_decode(post('unidades'));
|
||||
$data = [];
|
||||
foreach ($unis as $n_unidad) {
|
||||
if ($tipo->tipo()->descripcion == 'departamento') {
|
||||
$ini = post('piso_ini' . $n_unidad);
|
||||
$end = post('piso_end' . $n_unidad);
|
||||
$subtipo = post('linea' . $n_unidad);
|
||||
$orientacion = post('orientacion' . $n_unidad);
|
||||
for ($piso = $ini; $piso <= $end; $piso ++) {
|
||||
$descripcion = $piso . str_pad(post('linea' . $n_unidad), $len, '0', \STR_PAD_LEFT);
|
||||
|
||||
$data []= [
|
||||
'proyecto' => $tipo->proyecto()->id,
|
||||
'tipo' => $tipo->tipo()->id,
|
||||
'subtipo' => $subtipo,
|
||||
'piso' => $piso,
|
||||
'descripcion' => $descripcion,
|
||||
'abreviacion' => $tipo->abreviacion,
|
||||
'm2' => $tipo->m2,
|
||||
'terraza' => $tipo->terraza,
|
||||
'logia' => $tipo->logia,
|
||||
'orientacion' => $orientacion,
|
||||
'pt' => $tipo->id
|
||||
];
|
||||
}
|
||||
} else {
|
||||
$descripcion = post('descripcion' . $n_unidad);
|
||||
$piso = post('piso' . $n_unidad);
|
||||
$data []= [
|
||||
'proyecto' => $tipo->proyecto()->id,
|
||||
'tipo' => $tipo->tipo()->id,
|
||||
'piso' => $piso,
|
||||
'descripcion' => $descripcion,
|
||||
'abreviacion' => $tipo->abreviacion,
|
||||
'm2' => $tipo->m2,
|
||||
'terraza' => $tipo->terraza,
|
||||
'logia' => $tipo->logia,
|
||||
'pt' => $tipo->id
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($data as $uni) {
|
||||
$unidad = model(Unidad::class)
|
||||
->where('descripcion', $uni['descripcion'])
|
||||
->where('proyecto', $uni['proyecto'])
|
||||
->where('tipo', $uni['tipo'])
|
||||
->findOne();
|
||||
if ($unidad) {
|
||||
continue;
|
||||
}
|
||||
$unidad = model(Unidad::class)->create($uni);
|
||||
$unidad->save();
|
||||
}
|
||||
header('Location: ' . url('', ['p' => 'proyectos', 'a' => 'list_unidades', 'proyecto' => $tipo->proyecto()->id]));
|
||||
}
|
||||
public static function edit()
|
||||
{
|
||||
$id = get('unidad');
|
||||
$unidad = model(Unidad::class)->findOne($id);
|
||||
$tipos = model(ProyectoTipoUnidad::class)->where('proyecto', $unidad->proyecto()->id)->findMany();
|
||||
$abreviaciones = ['N', 'NE', 'E', 'SE', 'S', 'SO', 'O', 'NO'];
|
||||
$descripciones = ['Norte', 'Noreste', 'Este', 'Sureste', 'Sur', 'Suroeste', 'Oeste', 'Noroeste'];
|
||||
$orientaciones = [];
|
||||
foreach ($abreviaciones as $i => $ab) {
|
||||
$orientaciones []= (object) ['abreviacion' => $ab, 'descripcion' => $descripciones[$i]];
|
||||
}
|
||||
|
||||
return view('proyectos.unidades.edit', compact('unidad', 'tipos', 'orientaciones'));
|
||||
}
|
||||
public static function editar()
|
||||
{
|
||||
$id = get('unidad');
|
||||
$unidad = model(Unidad::class)->findOne($id);
|
||||
|
||||
$change = false;
|
||||
$fields = ['descripcion', 'tipo', 'piso', 'linea', 'orientacion'];
|
||||
foreach ($fields as $field) {
|
||||
$f = $field;
|
||||
if ($f == 'tipo') {
|
||||
$f = 'pt';
|
||||
}
|
||||
if ($f == 'linea') {
|
||||
$f = 'subtipo';
|
||||
}
|
||||
if ($unidad->{$f} != post($field)) {
|
||||
$unidad->{$f} = post($field);
|
||||
$change = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($change) {
|
||||
$unidad->save();
|
||||
}
|
||||
header('Location: ' . nUrl('proyectos', 'list_unidades', ['proyecto' => $unidad->proyecto()->id]));
|
||||
}
|
||||
public static function remove()
|
||||
{
|
||||
$id = get('unidad');
|
||||
$unidad = model(Unidad::class)->findOne($id);
|
||||
$unidad->delete();
|
||||
|
||||
$id = get('proyecto');
|
||||
header('Location: ' . nUrl('proyectos', 'list_unidades', ['proyecto' => $id]));
|
||||
}
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user