<?php
namespace Incoviba\Service\Contabilidad\Informe\Tesoreria\Input\Excel;

use PhpOffice\PhpSpreadsheet;

class DAPyFFMM extends Sheet
{
    public function load(PhpSpreadsheet\Spreadsheet $excel): array
    {
        if (!$excel->sheetNameExists('DAP y FFMM')) {
            return [];
        }
        $sheet = $excel->getSheetByName('DAP y FFMM');
        $data = [];

        $rowIndex = 1;
        while ($sheet->getCell("B{$rowIndex}")->getValue() !== 'EMPRESA') {
            $rowIndex ++;
        }
        $titleRow = $rowIndex;
        $columnOffset = 2;
        $titles = $this->getTableTitles($sheet, $titleRow, $columnOffset, 20, 'UF', ['(']);

        $rowIndex ++;
        while ($sheet->getCell("B{$rowIndex}")->getValue() !== 'TOTAL') {
            if ($sheet->getCell("B{$rowIndex}")->getValue() !== null) {
                $data []= $this->getRow($sheet, $titles, $titleRow, $rowIndex, $columnOffset);
                /*
                $dap = [];
                $columnIndex = 0;
                $dap[$titles[$columnIndex ++]] = $sheet->getCell("B{$rowIndex}")->getValue();
                $dap[$titles[$columnIndex ++]] = $sheet->getCell("D{$rowIndex}")->getValue();
                $dap[$titles[$columnIndex ++]] = $sheet->getCell("F{$rowIndex}")->getValue();
                $dap[$titles[$columnIndex ++]] = $this->getCalculatedValue($sheet, 'H', $rowIndex);
                $dap[$titles[$columnIndex ++]] = $this->getCalculatedValue($sheet, 'I', $rowIndex);
                $dap[$titles[$columnIndex ++]] = $this->getCalculatedValue($sheet, 'J', $rowIndex);
                $dap[$titles[$columnIndex ++]] = $this->getCalculatedValue($sheet, 'K', $rowIndex);
                $dap[$titles[$columnIndex ++]] = PhpSpreadsheet\Shared\Date::excelToDateTimeObject($this->getCalculatedValue($sheet, 'L', $rowIndex));
                $dap[$titles[$columnIndex ++]] = PhpSpreadsheet\Shared\Date::excelToDateTimeObject($this->getCalculatedValue($sheet, 'M', $rowIndex));
                $dap[$titles[$columnIndex ++]] = $this->getCalculatedValue($sheet, 'N', $rowIndex);
                $dap[$titles[$columnIndex]] = $this->getCalculatedValue($sheet, 'O', $rowIndex);

                $data []= (object) $dap;*/
            }
            $rowIndex ++;
        }

        return $data;
    }
}
