diff --git a/app/src/Service/Cartola/Santander.php b/app/src/Service/Cartola/Santander.php index 016e2d9..b6af374 100644 --- a/app/src/Service/Cartola/Santander.php +++ b/app/src/Service/Cartola/Santander.php @@ -17,7 +17,12 @@ class Santander extends Banco 'DESCRIPCIÓN MOVIMIENTO' => 'glosa', 'FECHA' => 'fecha', 'N° DOCUMENTO' => 'documento', - 'SALDO' => 'saldo' + 'SALDO' => 'saldo', + 'Fecha' => 'fecha', + 'Cargo ($)' => 'cargo', + 'Abono ($)' => 'abono', + 'Descripcin' => 'glosa', + 'Saldo Diario' => 'saldo' ]; } protected function parseFile(UploadedFileInterface $uploadedFile): array @@ -26,7 +31,11 @@ class Santander extends Banco $uploadedFile->moveTo($filename); $reader = PhpSpreadsheet\IOFactory::createReader('Xlsx'); - $xlsx = $reader->load($filename); + try { + $xlsx = $reader->load($filename); + } catch (PhpSpreadsheet\Reader\Exception) { + return $this->parseHtml($filename); + } $sheet = $xlsx->getActiveSheet(); $found = false; @@ -74,4 +83,59 @@ class Santander extends Banco return $data; } + protected function parseHtml(string $filename): array + { + $data = []; + $lines = explode("\r\n", file_get_contents($filename)); + $columns = []; + $found = false; + for ($rowIndex = 0; $rowIndex < count($lines); $rowIndex ++) { + if (!$found and str_contains($lines[$rowIndex], 'Cuenta Corriente: ')) { + $found = true; + $rowIndex += 2; + $columns = $this->parseHtmlRow($lines, $rowIndex); + continue; + } + if (!$found) { + continue; + } + $row = $this->parseHtmlRow($lines, $rowIndex); + if (str_contains($row[0], 'Saldo Contable')) { + break; + } + $row = array_combine($columns, $row); + $row['Fecha'] = implode('-', array_reverse(explode('-', $row['Fecha']))); + foreach (['Cargo ($)', 'Abono ($)', 'Saldo Diario'] as $column) { + $row[$column] = (int) str_replace('.', '', $row[$column]); + } + $row['Saldo Diario'] -= ($row['Abono ($)'] - $row['Cargo ($)']); + $row['N° DOCUMENTO'] = ''; + $data []= $row; + } + return $data; + } + protected function parseHtmlRow(array $lines, int &$rowIndex): array + { + if (!str_contains($lines[$rowIndex ++], '