Orden sociedades

This commit is contained in:
Juan Pablo Vial
2024-04-05 17:13:21 -03:00
parent 20045c9a64
commit 3c7e4b9ef4

View File

@ -12,6 +12,17 @@ use Incoviba\Service;
class Excel extends Ideal\Service class Excel extends Ideal\Service
{ {
protected const CURRENCY_CODE = '_ $* #,##0_ ;_ $* -#,##0_ ;_ $* "-"_ ;_ @_ '; protected const CURRENCY_CODE = '_ $* #,##0_ ;_ $* -#,##0_ ;_ $* "-"_ ;_ @_ ';
protected const ORDEN_SOCIEDADES = [
99543380,
78017310,
76837020,
76743916,
76519798,
76309587,
77023196,
77023201,
76309592,
];
public function __construct(LoggerInterface $logger, protected string $folder, protected Service\UF $ufService, protected Service\USD $usdService) public function __construct(LoggerInterface $logger, protected string $folder, protected Service\UF $ufService, protected Service\USD $usdService)
{ {
@ -154,7 +165,7 @@ class Excel extends Ideal\Service
'Saldo empresa', 'Total Cuentas', 'Total FFMM', 'Total DAP', 'Caja Total']; 'Saldo empresa', 'Total Cuentas', 'Total FFMM', 'Total DAP', 'Caja Total'];
$styles = [ $styles = [
'alignment' => [ 'alignment' => [
'horizontal' => PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER 'horizontal' => PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER,
], ],
'borders' => [ 'borders' => [
'outline' => [ 'outline' => [
@ -176,11 +187,20 @@ class Excel extends Ideal\Service
$this->fillColumns($sheet, $columns, $styles, $startRow); $this->fillColumns($sheet, $columns, $styles, $startRow);
$rowIndex = $startRow + 1; $rowIndex = $startRow + 1;
foreach ($data['inmobiliarias'] as $dataInmobiliaria) { $sociedades = [];
$rowIndex += $this->fillInmobiliaria($sheet, $dataInmobiliaria, $rowIndex); foreach (self::ORDEN_SOCIEDADES as $sociedad_rut) {
foreach ($data['inmobiliarias'] as $dataSociedad) {
if ($dataSociedad->inmobiliaria->rut === $sociedad_rut) {
$sociedades []= $dataSociedad;
}
}
}
foreach ($sociedades as $dataSociedad) {
$rowIndex += $this->fillSociedad($sheet, $dataSociedad, $rowIndex);
} }
$finalRow = $rowIndex; $finalRow = $rowIndex;
$sheet->getStyle("B8:B{$finalRow}")->getAlignment()->setVertical(PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER);
$sheet->getStyle("B7:N{$finalRow}")->getBorders()->getAllBorders() $sheet->getStyle("B7:N{$finalRow}")->getBorders()->getAllBorders()
->setBorderStyle(PhpSpreadsheet\Style\Border::BORDER_THIN) ->setBorderStyle(PhpSpreadsheet\Style\Border::BORDER_THIN)
->getColor()->setARGB('FFD9D9D9'); ->getColor()->setARGB('FFD9D9D9');
@ -279,6 +299,82 @@ class Excel extends Ideal\Service
$conditional = $this->getConditional(); $conditional = $this->getConditional();
$dataMovimientos = [
'capital dap' => [
'ingresos' => [],
'egresos' => []
],
'ingresos' => [],
'egresos' => []
];
foreach (self::ORDEN_SOCIEDADES as $sociedad_rut) {
$date = null;
foreach ($data['movimientos']['capital dap']['ingresos'] as $movimiento) {
if ($date === null) {
$date = $movimiento->fecha;
}
if ($movimiento->fecha !== $date) {
if ($movimiento->cuenta->inmobiliaria->rut === $sociedad_rut) {
$dataMovimientos['movimientos']['capital dap']['ingresos'] [] = $movimiento;
}
$date = $movimiento->fecha;
continue;
}
if ($movimiento->cuenta->inmobiliaria->rut === $sociedad_rut) {
$dataMovimientos['movimientos']['capital dap']['ingresos'] []= $movimiento;
}
}
$date = null;
foreach ($data['movimientos']['capital dap']['egresos'] as $movimiento) {
if ($date === null) {
$date = $movimiento->fecha;
}
if ($movimiento->fecha !== $date) {
if ($movimiento->cuenta->inmobiliaria->rut === $sociedad_rut) {
$dataMovimientos['movimientos']['capital dap']['egresos'] [] = $movimiento;
}
$date = $movimiento->fecha;
continue;
}
if ($movimiento->cuenta->inmobiliaria->rut === $sociedad_rut) {
$dataMovimientos['movimientos']['capital dap']['egresos'] []= $movimiento;
}
}
$date = null;
foreach ($data['movimientos']['ingresos'] as $movimiento) {
if ($date === null) {
$date = $movimiento->fecha;
}
if ($movimiento->fecha !== $date) {
if ($movimiento->cuenta->inmobiliaria->rut === $sociedad_rut) {
$dataMovimientos['ingresos'] [] = $movimiento;
}
$date = $movimiento->fecha;
continue;
}
if ($movimiento->cuenta->inmobiliaria->rut === $sociedad_rut) {
$dataMovimientos['ingresos'] []= $movimiento;
}
}
$date = null;
foreach ($data['movimientos']['egresos'] as $movimiento) {
if ($date === null) {
$date = $movimiento->fecha;
}
if ($movimiento->fecha !== $date) {
if ($movimiento->cuenta->inmobiliaria->rut === $sociedad_rut) {
$dataMovimientos['egresos'] [] = $movimiento;
}
$date = $movimiento->fecha;
continue;
}
if ($movimiento->cuenta->inmobiliaria->rut === $sociedad_rut) {
$dataMovimientos['egresos'] []= $movimiento;
}
}
}
$styles = [ $styles = [
'fill' => [ 'fill' => [
'fillType' => PhpSpreadsheet\Style\Fill::FILL_SOLID, 'fillType' => PhpSpreadsheet\Style\Fill::FILL_SOLID,
@ -292,7 +388,7 @@ class Excel extends Ideal\Service
]; ];
$rowIngreso = null; $rowIngreso = null;
$rowEgreso = null; $rowEgreso = null;
foreach ($data['movimientos'] as $tipo => $movimientos) { foreach ($dataMovimientos as $tipo => $movimientos) {
if ($tipo === 'capital dap') { if ($tipo === 'capital dap') {
$sheet->getCell("B{$rowIndex}")->setValue('CAPITAL DAP'); $sheet->getCell("B{$rowIndex}")->setValue('CAPITAL DAP');
$sheet->getCell("T{$rowIndex}")->setValue('SUMA DAP'); $sheet->getCell("T{$rowIndex}")->setValue('SUMA DAP');
@ -324,6 +420,7 @@ class Excel extends Ideal\Service
$sheet->getCell("V{$totalRow}")->setValue("=SUM(C{$start}:D{$end})"); $sheet->getCell("V{$totalRow}")->setValue("=SUM(C{$start}:D{$end})");
$sheet->getStyle("C{$start}:D{$end}")->getNumberFormat()->setFormatCode(self::CURRENCY_CODE); $sheet->getStyle("C{$start}:D{$end}")->getNumberFormat()->setFormatCode(self::CURRENCY_CODE);
$rowIndex ++;
continue; continue;
} }
$sheet->getCell("B{$rowIndex}")->setValue(strtoupper($tipo)); $sheet->getCell("B{$rowIndex}")->setValue(strtoupper($tipo));
@ -453,27 +550,27 @@ class Excel extends Ideal\Service
} }
$sheet->getStyle([2, $rowIndex, $columnIndex, $rowIndex])->applyFromArray($styles); $sheet->getStyle([2, $rowIndex, $columnIndex, $rowIndex])->applyFromArray($styles);
} }
protected function fillInmobiliaria(PhpSpreadsheet\Worksheet\Worksheet $sheet, object $dataInmobiliaria, int $baseRowIndex): int protected function fillSociedad(PhpSpreadsheet\Worksheet\Worksheet $sheet, object $dataSociedad, int $baseRowIndex): int
{ {
$rowIndex = $baseRowIndex; $rowIndex = $baseRowIndex;
$sheet->getCell("B{$rowIndex}")->setValue($dataInmobiliaria->inmobiliaria->razon); $sheet->getCell("B{$rowIndex}")->setValue($dataSociedad->inmobiliaria->razon);
foreach ($dataInmobiliaria->cuentas as $cuentaRowIndex => $cuenta) { foreach ($dataSociedad->cuentas as $cuentaRowIndex => $cuenta) {
$this->fillCuenta($sheet, $cuenta, 3, $baseRowIndex + $cuentaRowIndex); $this->fillCuenta($sheet, $cuenta, 3, $baseRowIndex + $cuentaRowIndex);
} }
$sheet->getCell("K{$rowIndex}")->setValue($dataInmobiliaria->total()); $sheet->getCell("K{$rowIndex}")->setValue($dataSociedad->total());
$sheet->getCell("L{$rowIndex}")->setValue($dataInmobiliaria->ffmm()); $sheet->getCell("L{$rowIndex}")->setValue($dataSociedad->ffmm());
$sheet->getCell("M{$rowIndex}")->setValue($dataInmobiliaria->deposito()); $sheet->getCell("M{$rowIndex}")->setValue($dataSociedad->deposito());
$sheet->getCell("N{$rowIndex}")->setValue($dataInmobiliaria->caja()); $sheet->getCell("N{$rowIndex}")->setValue($dataSociedad->caja());
if (count($dataInmobiliaria->cuentas) > 1) { if (count($dataSociedad->cuentas) > 1) {
$finalRow = $rowIndex + count($dataInmobiliaria->cuentas) - 1; $finalRow = $rowIndex + count($dataSociedad->cuentas) - 1;
$sheet->mergeCells("B{$rowIndex}:B{$finalRow}"); $sheet->mergeCells("B{$rowIndex}:B{$finalRow}");
$sheet->mergeCells("K{$rowIndex}:K{$finalRow}"); $sheet->mergeCells("K{$rowIndex}:K{$finalRow}");
$sheet->mergeCells("L{$rowIndex}:L{$finalRow}"); $sheet->mergeCells("L{$rowIndex}:L{$finalRow}");
$sheet->mergeCells("M{$rowIndex}:M{$finalRow}"); $sheet->mergeCells("M{$rowIndex}:M{$finalRow}");
$sheet->mergeCells("N{$rowIndex}:N{$finalRow}"); $sheet->mergeCells("N{$rowIndex}:N{$finalRow}");
} }
return count($dataInmobiliaria->cuentas); return count($dataSociedad->cuentas);
} }
protected function fillCuenta(PhpSpreadsheet\Worksheet\Worksheet $sheet, object $cuenta, int $startColumnIndex, int $rowIndex): void protected function fillCuenta(PhpSpreadsheet\Worksheet\Worksheet $sheet, object $cuenta, int $startColumnIndex, int $rowIndex): void
{ {