From 3c7e4b9ef4fb402068edfbc51a1e72825b135125 Mon Sep 17 00:00:00 2001 From: Juan Pablo Vial Date: Fri, 5 Apr 2024 17:13:21 -0300 Subject: [PATCH] Orden sociedades --- .../Contabilidad/Informe/Tesoreria/Excel.php | 125 ++++++++++++++++-- 1 file changed, 111 insertions(+), 14 deletions(-) diff --git a/app/src/Service/Contabilidad/Informe/Tesoreria/Excel.php b/app/src/Service/Contabilidad/Informe/Tesoreria/Excel.php index a38605f..6c9f813 100644 --- a/app/src/Service/Contabilidad/Informe/Tesoreria/Excel.php +++ b/app/src/Service/Contabilidad/Informe/Tesoreria/Excel.php @@ -12,6 +12,17 @@ use Incoviba\Service; class Excel extends Ideal\Service { 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) { @@ -154,7 +165,7 @@ class Excel extends Ideal\Service 'Saldo empresa', 'Total Cuentas', 'Total FFMM', 'Total DAP', 'Caja Total']; $styles = [ 'alignment' => [ - 'horizontal' => PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER + 'horizontal' => PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER, ], 'borders' => [ 'outline' => [ @@ -176,11 +187,20 @@ class Excel extends Ideal\Service $this->fillColumns($sheet, $columns, $styles, $startRow); $rowIndex = $startRow + 1; - foreach ($data['inmobiliarias'] as $dataInmobiliaria) { - $rowIndex += $this->fillInmobiliaria($sheet, $dataInmobiliaria, $rowIndex); + $sociedades = []; + 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; + $sheet->getStyle("B8:B{$finalRow}")->getAlignment()->setVertical(PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER); $sheet->getStyle("B7:N{$finalRow}")->getBorders()->getAllBorders() ->setBorderStyle(PhpSpreadsheet\Style\Border::BORDER_THIN) ->getColor()->setARGB('FFD9D9D9'); @@ -279,6 +299,82 @@ class Excel extends Ideal\Service $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 = [ 'fill' => [ 'fillType' => PhpSpreadsheet\Style\Fill::FILL_SOLID, @@ -292,7 +388,7 @@ class Excel extends Ideal\Service ]; $rowIngreso = null; $rowEgreso = null; - foreach ($data['movimientos'] as $tipo => $movimientos) { + foreach ($dataMovimientos as $tipo => $movimientos) { if ($tipo === 'capital dap') { $sheet->getCell("B{$rowIndex}")->setValue('CAPITAL 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->getStyle("C{$start}:D{$end}")->getNumberFormat()->setFormatCode(self::CURRENCY_CODE); + $rowIndex ++; continue; } $sheet->getCell("B{$rowIndex}")->setValue(strtoupper($tipo)); @@ -453,27 +550,27 @@ class Excel extends Ideal\Service } $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; - $sheet->getCell("B{$rowIndex}")->setValue($dataInmobiliaria->inmobiliaria->razon); - foreach ($dataInmobiliaria->cuentas as $cuentaRowIndex => $cuenta) { + $sheet->getCell("B{$rowIndex}")->setValue($dataSociedad->inmobiliaria->razon); + foreach ($dataSociedad->cuentas as $cuentaRowIndex => $cuenta) { $this->fillCuenta($sheet, $cuenta, 3, $baseRowIndex + $cuentaRowIndex); } - $sheet->getCell("K{$rowIndex}")->setValue($dataInmobiliaria->total()); - $sheet->getCell("L{$rowIndex}")->setValue($dataInmobiliaria->ffmm()); - $sheet->getCell("M{$rowIndex}")->setValue($dataInmobiliaria->deposito()); - $sheet->getCell("N{$rowIndex}")->setValue($dataInmobiliaria->caja()); + $sheet->getCell("K{$rowIndex}")->setValue($dataSociedad->total()); + $sheet->getCell("L{$rowIndex}")->setValue($dataSociedad->ffmm()); + $sheet->getCell("M{$rowIndex}")->setValue($dataSociedad->deposito()); + $sheet->getCell("N{$rowIndex}")->setValue($dataSociedad->caja()); - if (count($dataInmobiliaria->cuentas) > 1) { - $finalRow = $rowIndex + count($dataInmobiliaria->cuentas) - 1; + if (count($dataSociedad->cuentas) > 1) { + $finalRow = $rowIndex + count($dataSociedad->cuentas) - 1; $sheet->mergeCells("B{$rowIndex}:B{$finalRow}"); $sheet->mergeCells("K{$rowIndex}:K{$finalRow}"); $sheet->mergeCells("L{$rowIndex}:L{$finalRow}"); $sheet->mergeCells("M{$rowIndex}:M{$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 {