Cambio base Cartola/Banco e implementacion de Itau
This commit is contained in:
@ -6,4 +6,5 @@ use Psr\Http\Message\UploadedFileInterface;
|
||||
interface Banco
|
||||
{
|
||||
public function process(UploadedFileInterface $file): array;
|
||||
|
||||
}
|
||||
|
20
app/common/Ideal/Cartola/Banco.php
Normal file
20
app/common/Ideal/Cartola/Banco.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
namespace Incoviba\Common\Ideal\Cartola;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Psr\Http\Message\UploadedFileInterface;
|
||||
|
||||
abstract class Banco implements Define\Cartola\Banco
|
||||
{
|
||||
public function process(UploadedFileInterface $file): array
|
||||
{
|
||||
$data = $this->parseFile($file);
|
||||
return array_map(function($row) {
|
||||
$columns = $this->columnMap();
|
||||
return array_combine(array_values($columns), array_values($row));
|
||||
}, $data);
|
||||
}
|
||||
|
||||
abstract protected function columnMap(): array;
|
||||
abstract protected function parseFile(UploadedFileInterface $uploadedFile): array;
|
||||
}
|
@ -206,11 +206,11 @@
|
||||
fecha.setDate(fecha.getDate() + 1)
|
||||
this.data.movimientos[idx] = {
|
||||
fecha: fecha,
|
||||
glosa: row['descripción'],
|
||||
documento: row['número de documentos'],
|
||||
cargo: row.cargos,
|
||||
abono: row.abonos,
|
||||
saldo: row.saldos
|
||||
glosa: row.descripcion,
|
||||
documento: row.documento,
|
||||
cargo: row.cargo,
|
||||
abono: row.abono,
|
||||
saldo: row.saldo
|
||||
}
|
||||
})
|
||||
this.draw().cartola()
|
||||
|
@ -34,7 +34,9 @@ return [
|
||||
return (new Incoviba\Service\Cartola(
|
||||
$container->get(Psr\Http\Message\StreamFactoryInterface::class),
|
||||
$container->get(Incoviba\Common\Define\Contabilidad\Exporter::class)
|
||||
))->register('security', $container->get(Incoviba\Service\Cartola\Security::class));
|
||||
))
|
||||
->register('security', $container->get(Incoviba\Service\Cartola\Security::class))
|
||||
->register('itau', $container->get(Incoviba\Service\Cartola\Itau::class));
|
||||
},
|
||||
Incoviba\Common\Define\Contabilidad\Exporter::class => function(ContainerInterface $container) {
|
||||
return $container->get(Incoviba\Service\Contabilidad\Exporter\Nubox::class);
|
||||
|
91
app/src/Service/Cartola/Itau.php
Normal file
91
app/src/Service/Cartola/Itau.php
Normal 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;
|
||||
}
|
||||
}
|
@ -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
|
||||
|
Reference in New Issue
Block a user