84 lines
2.4 KiB
PHP
84 lines
2.4 KiB
PHP
<?php
|
|
namespace App\Controller;
|
|
|
|
use Carbon\Carbon;
|
|
use App\Definition\Controller;
|
|
use Incoviba\old\Proyecto\Proyecto;
|
|
use Incoviba\old\Proyecto\ProyectoAgente;
|
|
use Incoviba\old\Venta\Unidad;
|
|
use Incoviba\old\Venta\UnidadBloqueada;
|
|
|
|
class UnidadesBloqueadas
|
|
{
|
|
use Controller;
|
|
|
|
public static function list()
|
|
{
|
|
$proyectos = model(Proyecto::class)->findMany();
|
|
echo view('ventas.operadores.unidades.list', compact('proyectos'));
|
|
}
|
|
public static function add()
|
|
{
|
|
$proyectos = model(Proyecto::class)->findMany();
|
|
echo view('ventas.operadores.unidades.add', compact('proyectos'));
|
|
}
|
|
public static function bloquear()
|
|
{
|
|
$operador = model(ProyectoAgente::class)->findOne(get('operador'));
|
|
echo view('ventas.operadores.unidades.bloquear', compact('operador'));
|
|
}
|
|
public static function do_bloquear()
|
|
{
|
|
$operador = model(ProyectoAgente::class)->findOne(get('operador'));
|
|
$fecha = Carbon::createFromDate(post('year'), post('month'), post('day'), config('app.timezone'));
|
|
$unidades = self::getUnidades([], 'departamentos', 1);
|
|
$unidades = self::getUnidades($unidades, 'estacionamientos', 2);
|
|
$unidades = self::getUnidades($unidades, 'bodegas', 3);
|
|
if (post('unidad') != null) {
|
|
foreach (post('unidad') as $u) {
|
|
$unidad = model(Unidad::class)->findOne($u);
|
|
if (array_search($unidad, $unidades) === false) {
|
|
$unidades []= $unidad;
|
|
}
|
|
}
|
|
}
|
|
|
|
foreach ($unidades as $unidad) {
|
|
$data = [
|
|
'agente' => $operador->id,
|
|
'unidad' => $unidad->id
|
|
];
|
|
$ub = model(UnidadBloqueada::class)->create($data);
|
|
$ub->new($fecha);
|
|
}
|
|
header('Location: ' . nUrl('unidades_bloqueadas', 'list'));
|
|
}
|
|
protected static function getUnidades(array $unidades, string $name, int $tipo): array
|
|
{
|
|
if (trim(post($name)) == '') {
|
|
return $unidades;
|
|
}
|
|
$unis = [];
|
|
$separators = [PHP_EOL, ';', ',', '-'];
|
|
foreach ($separators as $separator) {
|
|
if (strpos(post($name), $separator) !== false) {
|
|
$unis = explode($separator, post($name));
|
|
break;
|
|
}
|
|
}
|
|
if (count($unis) == 0) {
|
|
return $unidades;
|
|
}
|
|
array_walk($unis, function(&$item) {
|
|
$item = trim($item);
|
|
$item = model(Unidad::class)->where('descripcion', $item)->where('tipo', 1)->findOne();
|
|
});
|
|
foreach ($unis as $uni) {
|
|
if (array_search($uni, $unidades) === false) {
|
|
$unidades []= $uni;
|
|
}
|
|
}
|
|
return $unidades;
|
|
}
|
|
}
|