diff --git a/app/common/Define/Cartola/Banco.php b/app/common/Define/Cartola/Banco.php index 2a23f06..71f1323 100644 --- a/app/common/Define/Cartola/Banco.php +++ b/app/common/Define/Cartola/Banco.php @@ -6,4 +6,5 @@ use Psr\Http\Message\UploadedFileInterface; interface Banco { public function process(UploadedFileInterface $file): array; + } diff --git a/app/common/Ideal/Cartola/Banco.php b/app/common/Ideal/Cartola/Banco.php new file mode 100644 index 0000000..d4e10c6 --- /dev/null +++ b/app/common/Ideal/Cartola/Banco.php @@ -0,0 +1,20 @@ +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; +} diff --git a/app/resources/views/contabilidad/centros_costos/asignar.blade.php b/app/resources/views/contabilidad/centros_costos/asignar.blade.php index 2cf50c2..13340a3 100644 --- a/app/resources/views/contabilidad/centros_costos/asignar.blade.php +++ b/app/resources/views/contabilidad/centros_costos/asignar.blade.php @@ -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() diff --git a/app/setup/setups/services.php b/app/setup/setups/services.php index 8b2b709..e90b3b3 100644 --- a/app/setup/setups/services.php +++ b/app/setup/setups/services.php @@ -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); diff --git a/app/src/Service/Cartola/Itau.php b/app/src/Service/Cartola/Itau.php new file mode 100644 index 0000000..c7d842c --- /dev/null +++ b/app/src/Service/Cartola/Itau.php @@ -0,0 +1,91 @@ + '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; + } +} diff --git a/app/src/Service/Cartola/Security.php b/app/src/Service/Cartola/Security.php index d89fd6f..ae8f26b 100644 --- a/app/src/Service/Cartola/Security.php +++ b/app/src/Service/Cartola/Security.php @@ -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