Cartola Diaria

This commit is contained in:
Juan Pablo Vial
2024-02-19 22:39:22 -03:00
parent 51cabee824
commit 879b612493
8 changed files with 529 additions and 249 deletions

View File

@ -17,6 +17,7 @@ class Santander extends Banco
'DESCRIPCIÓN MOVIMIENTO' => 'glosa',
'FECHA' => 'fecha',
'N° DOCUMENTO' => 'documento',
'SALDO' => 'saldo'
];
}
protected function parseFile(UploadedFileInterface $uploadedFile): array
@ -28,42 +29,47 @@ class Santander extends Banco
$xlsx = $reader->load($filename);
$sheet = $xlsx->getActiveSheet();
$rowIndex = 16;
$found = false;
$columns = [];
$row = $sheet->getRowIterator($rowIndex)->current();
$cols = $row->getColumnIterator('A', 'H');
foreach ($cols as $col) {
$columns []= $col->getCalculatedValue();
}
$rowIndex ++;
$rows = $sheet->getRowIterator($rowIndex);
$data = [];
foreach ($rows as $row) {
if ($sheet->getCell("A{$rowIndex}")->getCalculatedValue() === 'Resumen comisiones') {
foreach ($sheet->getRowIterator() as $row) {
if (!$found and $sheet->getCell("A{$row->getRowIndex()}")->getCalculatedValue() === 'MONTO') {
$found = true;
foreach ($row->getColumnIterator() as $column) {
if ($column->getValue() === null) {
break;
}
$columns[$column->getColumn()] = trim($column->getValue());
}
continue;
}
if (!$found) {
continue;
}
if ($sheet->getCell("A{$row->getRowIndex()}")->getValue() === null) {
break;
}
$cols = $row->getColumnIterator('A', 'H');
$colIndex = 0;
$rowData = [];
foreach ($cols as $col) {
$value = $col->getCalculatedValue();
$col = $columns[$colIndex];
if ($col === 'FECHA') {
list($d,$m,$Y) = explode('/', $value);
$value = "{$Y}-{$m}-{$d}";
foreach ($columns as $columnIndex => $column) {
$value = $sheet->getCell("{$columnIndex}{$row->getRowIndex()}")->getCalculatedValue();
$mapped = $this->columnMap()[$column] ?? $column;
if ($mapped === 'fecha') {
$value = implode('-', array_reverse(explode('/', $value)));
}
$rowData[$col] = $value;
$colIndex ++;
if ($column === 'MONTO') {
$value = (int) $value;
}
$rowData[$column] = $value;
}
if ($rowData['CARGO/ABONO'] === 'C') {
$rowData['cargo'] = -$rowData['MONTO'];
$rowData['MONTO'] = -$rowData['MONTO'];
$rowData['cargo'] = $rowData['MONTO'];
$rowData['abono'] = 0;
} else {
$rowData['cargo'] = 0;
$rowData['abono'] = $rowData['MONTO'];
}
$data []= $rowData;
$rowIndex ++;
}
return $data;