Itau funcionando para ByV y Vialcorp

This commit is contained in:
Juan Pablo Vial
2024-09-12 16:41:57 -03:00
parent 74b15add36
commit 5defd2b564

View File

@ -8,6 +8,8 @@ use Psr\Http\Message\UploadedFileInterface;
class Itau extends Banco
{
use isExcel;
const CUENTA_CORRIENTE = 0;
const ULTIMOS_MOVIMIENTOS = 1;
@ -24,6 +26,7 @@ class Itau extends Banco
'Descripción' => 'glosa',
'Depósitos o abonos' => 'abono',
'Giros o cargos' => 'cargo',
'Saldo diario' => 'saldo',
'Documentos' => 'documento',
'Movimientos' => 'glosa',
'Saldos' => 'saldo',
@ -65,54 +68,46 @@ class Itau extends Banco
}
protected function parseCuentaCorriente(PhpSpreadsheet\Worksheet\Worksheet $sheet): array
{
$titleValueMap = [
'Giros o cargos' => 'int',
'Depósitos o abonos' => 'int',
'Saldos' => 'int',
'Saldo diario' => 'int',
];
$found = false;
$year = 0;
$columns = [];
$data = [];
foreach ($sheet->getRowIterator() as $row) {
if (!$found and $sheet->getCell("A{$row->getRowIndex()}")->getCalculatedValue() === 'Cartola Histórica') {
$columnIndex = 'A';
foreach ($row->getColumnIterator() as $column) {
if ($column->getValue() !== 'Periodo') {
continue;
}
$columnIndex = $column->getColumn();
break;
}
$dates = explode(' - ', $sheet->getCell("{$columnIndex}{$row->getRowIndex()}")->getCalculatedValue());
$date = DateTimeImmutable::createFromFormat('d/m/Y', $dates[0]);
$year = $date->format('Y');
$rowIterator = $sheet->getRowIterator();
while ($rowIterator->valid()) {
$row = $rowIterator->current();
if ($sheet->getCell("A{$row->getRowIndex()}")->getCalculatedValue() === 'Cartola Histórica') {
$range = $this->getDateRange($row);
$year = $range[0]->format('Y');
$rowIterator->next();
continue;
}
if (!$found and $sheet->getCell("A{$row->getRowIndex()}")->getCalculatedValue() === 'Movimientos') {
if ($sheet->getCell("A{$row->getRowIndex()}")->getCalculatedValue() === 'Movimientos') {
$found = true;
foreach ($row->getColumnIterator() as $column) {
if ($column->getValue() === null) {
break;
}
$columns[$column->getColumn()] = trim($column->getValue());
}
$rowIterator->next();
$row = $rowIterator->current();
$columns = $this->grabTitlesRow($row);
$rowIterator->next();
continue;
}
if (!$found) {
$rowIterator->next();
continue;
}
if ($sheet->getCell("A{$row->getRowIndex()}")->getValue() === null) {
break;
}
$rowData = [];
foreach ($columns as $columnIndex => $column) {
$value = $sheet->getCell("{$columnIndex}{$row->getRowIndex()}")->getCalculatedValue();
$mapped = $this->columnMap()[$column];
if ($mapped === 'fecha') {
list($d, $m) = explode('/', $value);
$value = "{$year}-{$m}-{$d}";
}
if (in_array($mapped, ['cargo', 'abono', 'saldo'])) {
$value = (int) $value;
}
$rowData[$column] = $value;
}
$rowData = $this->grabRow($row, $columns, process: true, titleValueMap: $titleValueMap);
$fecha = explode('/', $rowData['Fecha']);
$rowData['Fecha'] = "{$year}-{$fecha[1]}-{$fecha[0]}";
$data []= $rowData;
$rowIterator->next();
}
return $data;
@ -184,4 +179,22 @@ class Itau extends Banco
}
throw new PhpSpreadsheet\Exception();
}
protected function getDateRange(PhpSpreadsheet\Worksheet\Row $row): array
{
$columnIndex = 'A';
$columnIterator = $row->getColumnIterator();
while ($columnIterator->valid()) {
$column = $columnIterator->current();
if (str_contains($column->getValue(), '-')) {
$columnIndex = $column->getColumn();
break;
}
$columnIterator->next();
}
$value = $row->getWorksheet()->getCell("{$columnIndex}{$row->getRowIndex()}")->getCalculatedValue();
$dates = explode(' - ', $value);
return array_map(function($date) {
return DateTimeImmutable::createFromFormat('d/m/Y', $date);
}, $dates);
}
}