This commit is contained in:
Juan Pablo Vial
2022-03-07 23:49:26 -03:00
parent 7d3e75c316
commit b8babf2906
2 changed files with 1 additions and 109 deletions

View File

@ -561,108 +561,7 @@ class Informes
$service = new Resumen();
$service->build($id, new \DateTimeImmutable($fecha));
return;
$proyecto = model(Proyecto::class)->findOne($id);
$mes = null;
if ($fecha != null) {
$mes = Carbon::parse($fecha)->addMonths(1)->subDays(1);
}
$ventas = $proyecto->ventas();
usort($ventas, function($a, $b) {
return $a->fecha()->timestamp - $b->fecha()->timestamp;
});
$name = 'Contabilidad';
$hoy = Carbon::now(config('app.timezone'));
$filename = str_replace('ñ', 'n', $name . ' - ' . $proyecto->descripcion . ' - ' . $hoy->format('Y-m-d') . '.xls');
$informe = new PHPExcel($name, $filename);
$columnas = [
'Propietario',
['name' => 'Departamento', 'style' => 'general_number'],
['name' => 'Estacionamientos', 'style' => 'number'],
['name' => 'Bodegas', 'style' => 'number'],
'Fecha Venta',
['name' => 'Mes', 'style' => 'mes'],
'Tipo',
['name' => 'm² Ponderados', 'style' => 'amount'],
['name' => 'Valor Promesa', 'style' => 'amount'],
['name' => 'Pie [UF]', 'style' => 'amount'],
['name' => 'Pie [$]', 'style' => 'amount'],
['name' => 'Abono Escritura', 'style' => 'amount'],
['name' => 'Crédito', 'style' => 'amount'],
['name' => 'Cuotas', 'style' => 'number'],
['name' => 'Cuotas Pagadas', 'style' => 'number'],
['name' => 'Pie Pagado [UF]', 'style' => 'amount'],
['name' => 'Pie Pagado [$]', 'style' => 'amount']
];
$informe->addColumns($columnas);
$data = [];
foreach ($ventas as $venta) {
$info = [];
$info['Propietario'] = mb_strtoupper($venta->propietario()->nombreCompleto());
$info['Departamento'] = $venta->unidad()->descripcion;
$ests = [];
if ($venta->propiedad()->estacionamientos != '') {
$es = $venta->propiedad()->estacionamientos();
foreach ($es as $e) {
$ests []= $e->descripcion;
}
}
$info['Estacionamientos'] = implode(', ', $ests);
$bods = [];
if ($venta->propiedad()->bodegas != '') {
$bs = $venta->propiedad()->bodegas();
foreach ($bs as $b) {
$bods []= $b->descripcion;
}
}
$info['Bodegas'] = implode(', ', $bods);
$info['Fecha Venta'] = $venta->fecha()->format('d.m.Y');
$info['Mes'] = $venta->fecha()->format('M-y');
$info['Tipo'] = $venta->unidad()->abreviacion;
$info['m² Ponderados'] = $venta->unidad()->m2('vendible');
$info['Valor Promesa'] = $venta->valor_uf;
$info['Pie [UF]'] = 0;
$info['Pie [$]'] = 0;
$info['Abono Escritura'] = 0;
$info['Crédito'] = 0;
$info['Cuotas'] = 0;
$info['Cuotas Pagadas'] = 0;
$info['Pie Pagado [UF]'] = 0;
$info['Pie Pagado [$]'] = 0;
if ($venta->pie()) {
$info['Pie [UF]'] = $venta->pie()->valor;
$info['Pie [$]'] = $venta->pie()->valorPesos();
$info['Abono Escritura'] = ($venta->escritura != 0) ? $venta->escritura()->valor('ufs') : ($venta->valor_uf - $venta->pie()->valor - (($venta->credito != 0) ? $venta->credito()->pago()->valor('ufs') : 0));
$info['Crédito'] = ($venta->credito != 0) ? $venta->credito()->pago()->valor('ufs') : 0;
$info['Cuotas'] = $venta->pie()->cuotas;
$info['Cuotas Pagadas'] = count($venta->pie()->pagadas($mes));
$info['Pie Pagado [UF]'] = $venta->pie()->valorPagado('uf', $mes);
$info['Pie Pagado [$]'] = $venta->pie()->valorPagado('pesos', $mes);
}
$data []= $info;
}
$informe->addData($data);
$totals = [
'Departamento' => 'count',
'Estacionamientos' => 'count',
'Bodegas' => 'count',
'm² Ponderados' => 'sum',
'Valor Promesa' => 'sum',
'Pie' => 'sum',
'Pie Pagado' => 'sum'
];
$informe->addTotals($totals);
return $informe->informe();
return '';
} else {
$proyectos = model(Proyecto::class)->order_by_asc('descripcion')->find_many();
return view('informes.resumen_contabilidad', compact('proyectos'));

View File

@ -170,12 +170,5 @@ class Resumen
->formatColumn('C')
->formatColumn('D')
->send($filename);
return;
header("Content-Type: text/csv; charset=utf-8");
header('Content-Disposition: attachment; filename="' . $filename . '"');
header('Cache-Control: max-age=0');
file_put_contents('php://output', implode(PHP_EOL, $output));
}
}