Files
oficial/app/src/Service/Cartola/Itau.php

81 lines
2.5 KiB
PHP
Raw Normal View History

<?php
namespace Incoviba\Service\Cartola;
use DateTimeImmutable;
use Psr\Http\Message\UploadedFileInterface;
use PhpOffice\PhpSpreadsheet;
use Incoviba\Common\Ideal\Cartola\Banco;
class Itau extends Banco
{
protected function columnMap(): array
{
return [
'Fecha' => 'fecha',
'Número de operación' => 'documento',
2024-01-17 16:21:40 -03:00
'Descripción' => 'glosa',
'Depósitos o abonos' => 'abono',
2024-01-17 18:27:29 -03:00
'Giros o cargos' => 'cargo'
];
}
protected function parseFile(UploadedFileInterface $uploadedFile): array
{
$filename = '/tmp/cartola.xls';
$uploadedFile->moveTo($filename);
$reader = PhpSpreadsheet\IOFactory::createReader('Xls');
$xlsx = $reader->load($filename);
$sheet = $xlsx->getActiveSheet();
$dates = explode(' - ', $sheet->getCell('C4')->getCalculatedValue());
$date = DateTimeImmutable::createFromFormat('d/m/Y', $dates[0]);
$year = $date->format('Y');
$rowIndex = 26;
$columns = [];
$row = $sheet->getRowIterator($rowIndex)->current();
$cols = $row->getColumnIterator('A','G');
foreach ($cols as $col) {
$columns []= trim($col->getCalculatedValue());
}
$rowIndex ++;
$row = $sheet->getRowIterator($rowIndex)->current();
$cols = $row->getColumnIterator('A', 'G');
$colIndex = 0;
foreach ($cols as $col) {
$value = $col->getCalculatedValue();
if ($value !== null) {
$columns[$colIndex] .= " {$value}";
}
$colIndex ++;
}
$rowIndex ++;
$data = [];
$rows = $sheet->getRowIterator($rowIndex);
foreach ($rows as $row) {
if ($sheet->getCell("A{$rowIndex}")->getCalculatedValue() === null) {
break;
}
$cols = $row->getColumnIterator('A', 'G');
$colIndex = 0;
$rowData = [];
foreach ($cols as $col) {
$value = $col->getCalculatedValue();
$col = $columns[$colIndex];
if ($col === 'Fecha') {
list($d, $m) = explode('/', $value);
$value = "{$year}-{$m}-{$d}";
}
$rowData[$col] = $value;
$colIndex ++;
}
$data []= $rowData;
$rowIndex ++;
}
unlink($filename);
return $data;
}
}