Update 2022-03-07
This commit is contained in:
@ -410,6 +410,8 @@ class Informes
|
||||
public static function ventas()
|
||||
{
|
||||
if (get('proyecto')) {
|
||||
ini_set('memory_limit', "1G");
|
||||
ini_set('max_execution_time', '3600');
|
||||
$id = get('proyecto');
|
||||
$proyecto = model(Proyecto::class)->findOne($id);
|
||||
$ventas = $proyecto->ventas();
|
||||
@ -434,7 +436,7 @@ class Informes
|
||||
|
||||
$columnas = [
|
||||
'Propietario',
|
||||
['name' => 'Departamento', 'style' => 'number'],
|
||||
'Departamento',
|
||||
['name' => 'Estacionamientos', 'style' => 'number'],
|
||||
['name' => 'Bodegas', 'style' => 'number'],
|
||||
'Fecha Venta',
|
||||
@ -457,7 +459,8 @@ class Informes
|
||||
['name' => 'Valor Neto', 'style' => 'amount'],
|
||||
['name' => 'UF/m²*', 'style' => 'amount'],
|
||||
['name' => 'Comision', 'style' => 'amount'],
|
||||
['name' => 'Venta s/Comision', 'style' => 'amount']
|
||||
['name' => 'Venta s/Comision', 'style' => 'amount'].
|
||||
['name' => 'Precio', 'style' => 'Amount']
|
||||
];
|
||||
//$informe->addColumns($columnas);
|
||||
|
||||
@ -465,28 +468,14 @@ class Informes
|
||||
foreach ($ventas as $venta) {
|
||||
$info = [];
|
||||
$info['Propietario'] = mb_strtoupper($venta->propietario()->nombreCompleto());
|
||||
$info['Departamento'] = trim(array_reduce($venta->propiedad()->departamentos(), function($carry, $item) {
|
||||
return implode(' - ', [$carry, $item->descripcion]);
|
||||
}), ' -');
|
||||
//$ests = [];
|
||||
$info['Departamento'] = implode(' - ', array_map(function($item) {
|
||||
return $item->descripcion;
|
||||
}, $venta->propiedad()->departamentos()));
|
||||
$es = $venta->propiedad()->estacionamientos();
|
||||
/*if (count($es) > 0) {
|
||||
foreach ($es as $e) {
|
||||
$ests []= $e->descripcion;
|
||||
}
|
||||
}
|
||||
$info['Estacionamientos'] = implode(', ', $ests);*/
|
||||
$info['Estacionamientos'] = implode(', ', array_map(function($item) {
|
||||
return $item->descripcion;
|
||||
}, $es));
|
||||
//$bods = [];
|
||||
$bs = $venta->propiedad()->bodegas();
|
||||
/*if (count($bs) > 0) {
|
||||
foreach ($bs as $b) {
|
||||
$bods []= $b->descripcion;
|
||||
}
|
||||
}
|
||||
$info['Bodegas'] = implode(', ', $bods);*/
|
||||
$info['Bodegas'] = implode(', ', array_map(function($item) {
|
||||
return $item->descripcion;
|
||||
}, $bs));
|
||||
@ -495,7 +484,7 @@ class Informes
|
||||
$info['Tipo'] = $venta->unidad()->abreviacion;
|
||||
$info['m² Ponderados'] = $venta->unidad()->m2('vendible');
|
||||
$info['Valor Promesa'] = $venta->valor_uf;
|
||||
$info['Pie'] = $venta->pie()->valor;
|
||||
$info['Pie'] = $venta->pie()->valor;
|
||||
$info['Pie Pagado'] = 0;
|
||||
$info['% Pie Pagado'] = 0;
|
||||
if ($venta->pie()) {
|
||||
@ -508,12 +497,6 @@ class Informes
|
||||
$info['Valor Operador'] = $venta->valorComision();
|
||||
//$promos = 0;
|
||||
$ps = $venta->promociones();
|
||||
/*if (count($ps) > 0) {
|
||||
foreach ($ps as $promo) {
|
||||
$promos += $promo->valor;
|
||||
}
|
||||
}
|
||||
$info['Premios'] = $promos;*/
|
||||
$info['Premios'] = array_reduce($ps, function($sum, $item) {
|
||||
return $sum + $item->valor;
|
||||
});
|
||||
@ -536,31 +519,17 @@ class Informes
|
||||
$info['UF/m²*'] = $venta->uf_m2();
|
||||
$info['Comision'] = $venta->valorFinal() * $comision;
|
||||
$info['Venta s/Comision'] = $venta->valorFinal() - $info['Comision'];
|
||||
$fecha = $venta->fecha();
|
||||
$info['Precio'] = 0;
|
||||
try {
|
||||
$info['Precio'] = array_reduce($venta->propiedad()->departamentos(), function($sum, $item) use ($fecha) {
|
||||
return $sum + $item->precio($fecha)->valor;
|
||||
});
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
|
||||
$data []= $info;
|
||||
}
|
||||
/*$informe->addData($data);
|
||||
|
||||
$totals = [
|
||||
'Propietario' => 'TOTAL',
|
||||
'Departamento' => 'count',
|
||||
'Estacionamientos' => 'count',
|
||||
'Bodegas' => 'count',
|
||||
'm² Ponderados' => 'sum',
|
||||
'Valor Promesa' => 'sum',
|
||||
'Bono Pie' => 'sum',
|
||||
'Subsidio' => 'sum',
|
||||
'Ahorro' => 'sum',
|
||||
'Credito' => 'sum',
|
||||
'Valor Operador' => 'sum',
|
||||
'Premios' => 'sum',
|
||||
'Valor Ests & Bods' => 'sum',
|
||||
'Valor Neto' => 'sum',
|
||||
'Comision' => 'sum'
|
||||
];
|
||||
$informe->addTotals($totals);
|
||||
|
||||
return $informe->informe();*/
|
||||
|
||||
$body = [
|
||||
"Proyecto" => $proyecto->descripcion,
|
||||
|
@ -163,53 +163,25 @@ class Ventas
|
||||
$unis = json_decode(post('unidades'));
|
||||
$id_principal = array_shift($unis);
|
||||
$principal = model(Unidad::class)->findOne(post('unidad' . $id_principal));
|
||||
$propiedad = model(Propiedad::class)
|
||||
->select('propiedad.*')
|
||||
->join('unidad', ['unidad.id', '=', 'propiedad.unidad_principal'])
|
||||
->where('propiedad.unidad_principal', $principal->id)
|
||||
->where('unidad.proyecto', post('proyecto'))
|
||||
->orderByDesc('propiedad.id')
|
||||
->findOne();
|
||||
// Revisar si existe la propiedad y si está vigente.
|
||||
if (!$propiedad or ($propiedad->venta() and $propiedad->venta()->estado() and $propiedad->venta()->estado()->tipo()->descripcion != 'vigente')) {
|
||||
if (!$propiedad) {
|
||||
$propiedad = model(Propiedad::class)->create();
|
||||
}
|
||||
$propiedad->unidad_principal = $principal->id;
|
||||
$propiedad->save();
|
||||
$propiedad = model(Propiedad::class)->create();
|
||||
$propiedad->unidad_principal = $principal->id;
|
||||
$propiedad->save();
|
||||
$data = [
|
||||
'propiedad' => $propiedad->id,
|
||||
'unidad' => $principal->id,
|
||||
'principal' => 1
|
||||
];
|
||||
$pu = model(PropiedadUnidad::class)->create($data);
|
||||
$pu->save();
|
||||
foreach ($unis as $id_unidad) {
|
||||
$data = [
|
||||
'propiedad' => $propiedad->id,
|
||||
'unidad' => $principal->id,
|
||||
'principal' => 1
|
||||
'unidad' => post('unidad' . $id_unidad),
|
||||
'principal' => 0
|
||||
];
|
||||
$pu = model(PropiedadUnidad::class)->create($data);
|
||||
$pu->save();
|
||||
foreach ($unis as $id_unidad) {
|
||||
$data = [
|
||||
'propiedad' => $propiedad->id,
|
||||
'unidad' => post('unidad' . $id_unidad),
|
||||
'principal' => 0
|
||||
];
|
||||
$pu = model(PropiedadUnidad::class)->create($data);
|
||||
$pu->save();
|
||||
}
|
||||
/*$ests = [];
|
||||
$bods = [];
|
||||
foreach ($unis as $id_unidad) {
|
||||
$unidad = model(Unidad::class)->findOne(post('unidad' . $id_unidad));
|
||||
if ($unidad->tipo == 2) {
|
||||
$ests []= $unidad->id;
|
||||
}
|
||||
if ($unidad->tipo == 3) {
|
||||
$bods []= $unidad->id;
|
||||
}
|
||||
}
|
||||
$propiedad->estacionamientos = implode(';', $ests);
|
||||
$propiedad->bodegas = implode(';', $bods);
|
||||
$propiedad->save();*/
|
||||
} elseif ($propiedad->venta() and $propiedad->venta()->estado()->tipo()->descripcion == 'vigente') {
|
||||
// Existe la propiedad en este proyecto y está vigente. Error, no se debiese vender si está vigente.
|
||||
throw new \Exception('Existe la propiedad en este proyecto y está vigente. Error, no se debiese vender si está vigente.');
|
||||
}
|
||||
|
||||
$venta = model(Venta::class)->create();
|
||||
|
Reference in New Issue
Block a user