Cambio base Cartola/Banco e implementacion de Itau

This commit is contained in:
2024-01-17 16:19:38 -03:00
parent ecdb67a9ab
commit d1d3705a7b
6 changed files with 137 additions and 12 deletions

View File

@ -0,0 +1,91 @@
<?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',
'Sucursal' => 'sucursal',
'Descripción' => 'descripcion',
'Depósitos o abonos' => 'abono',
'Giros o cargos' => 'cargo',
'Saldo diario' => 'saldo'
];
}
protected function parseFile(UploadedFileInterface $uploadedFile): array
{
function log(mixed $elem): void
{
if (!is_string($elem)) {
$elem = var_export($elem,true);
}
error_log($elem.PHP_EOL,3,'/logs/debug');
}
$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}";
log($value);
}
$rowData[$col] = $value;
$colIndex ++;
}
$data []= $rowData;
$rowIndex ++;
}
unlink($filename);
return $data;
}
}

View File

@ -5,18 +5,29 @@ use DOMDocument;
use DateTimeImmutable;
use Psr\Http\Message\UploadedFileInterface;
use PhpOffice\PhpSpreadsheet;
use Incoviba\Common\Define\Cartola\Banco;
use Incoviba\Common\Ideal\Cartola\Banco;
class Security implements Banco
class Security extends Banco
{
public function process(UploadedFileInterface $file): array
protected function parseFile(UploadedFileInterface $uploadedFile): array
{
$stream = $file->getStream();
$stream = $uploadedFile->getStream();
$stream->seek(3);
if ($stream->read(strlen('table')) === 'table') {
return $this->processHtm($file);
return $this->processHtm($uploadedFile);
}
return $this->processXls($file);
return $this->processXls($uploadedFile);
}
protected function columnMap(): array
{
return [
'fecha' => 'fecha',
'descripción' => 'glosa',
'número de documentos' => 'documento',
'cargos' => 'cargo',
'abonos' => 'abono',
'saldos' => 'saldo'
];
}
private function processXls(UploadedFileInterface $file): array