FIX: cartola BCI
This commit is contained in:
@ -3,6 +3,7 @@ namespace Incoviba\Model;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Model\Movimiento\Detalle;
|
||||
|
||||
class Movimiento extends Ideal\Model
|
||||
@ -19,7 +20,11 @@ class Movimiento extends Ideal\Model
|
||||
public function getDetalles(): ?Detalle
|
||||
{
|
||||
if (!isset($this->detalles)) {
|
||||
try {
|
||||
$this->detalles = $this->runFactory('detalles');
|
||||
} catch (EmptyResult) {
|
||||
$this->detalles = null;
|
||||
}
|
||||
}
|
||||
return $this->detalles;
|
||||
}
|
||||
|
@ -1,9 +1,8 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Cartola;
|
||||
|
||||
use DOMDocument;
|
||||
use DOMElement;
|
||||
use Psr\Http\Message\UploadedFileInterface;
|
||||
use PhpOffice\PhpSpreadsheet;
|
||||
use Incoviba\Common\Ideal\Cartola\Banco;
|
||||
|
||||
class BCI extends Banco
|
||||
@ -11,59 +10,78 @@ class BCI extends Banco
|
||||
protected function columnMap(): array
|
||||
{
|
||||
return [
|
||||
'Fecha' => 'fecha',
|
||||
'Cargo ($)' => 'cargo',
|
||||
'Abono ($)' => 'abono',
|
||||
'Descripcin' => 'descripcion',
|
||||
'Saldo Diario' => 'saldo'
|
||||
'Fecha Transacción' => 'fecha',
|
||||
'Cargo $ (-)' => 'cargo',
|
||||
'Abono $ (+)' => 'abono',
|
||||
'Descripción' => 'descripcion',
|
||||
'Saldo' => 'saldo'
|
||||
];
|
||||
}
|
||||
protected function getFilename(UploadedFileInterface $uploadedFile): string
|
||||
{
|
||||
return '/tmp/cartola.html';
|
||||
return '/tmp/cartola.xlsx';
|
||||
}
|
||||
protected function parseFile(string $filename): array
|
||||
{
|
||||
$xlsx = @PhpSpreadsheet\IOFactory::load($filename);
|
||||
$worksheet = $xlsx->getActiveSheet();
|
||||
$rows = $worksheet->getRowIterator();
|
||||
|
||||
|
||||
$domDocument = new DOMDocument();
|
||||
$domDocument->loadHTML('<body>' . str_replace('?', '', mb_convert_encoding(file_get_contents($filename), 'windows-1252', 'utf-8')) . '</body>');
|
||||
|
||||
$tables = $domDocument->getElementsByTagName('table');
|
||||
$table = $tables->item(1);
|
||||
$data = [];
|
||||
$columns = [];
|
||||
$found = false;
|
||||
foreach ($table->getElementsByTagName('tr')->getIterator() as $row) {
|
||||
if (!$found and str_contains($row->textContent, 'Fecha')) {
|
||||
$found = true;
|
||||
$columns = $this->getRowContent($row);
|
||||
$rows->seek(3);
|
||||
$row = $rows->current();
|
||||
$columnIterator = $row->getColumnIterator();
|
||||
$saldoFinal = 0;
|
||||
foreach ($columnIterator as $column) {
|
||||
if ($column->getValue() === null) {
|
||||
continue;
|
||||
}
|
||||
if (!$found) {
|
||||
continue;
|
||||
}
|
||||
$rowData = $this->getRowContent($row);
|
||||
if (str_starts_with($rowData[0], 'Saldo Contable Final ($)')) {
|
||||
if ($column->getCalculatedValue() === 'Saldo Contable') {
|
||||
$columnIterator->next();
|
||||
$column = $columnIterator->current();
|
||||
$saldoFinal = (int) str_replace('.', '', $column->getCalculatedValue());
|
||||
break;
|
||||
}
|
||||
}
|
||||
$saldo = $saldoFinal;
|
||||
|
||||
$data = [];
|
||||
$columns = [];
|
||||
$dataFound = false;
|
||||
foreach ($rows as $row) {
|
||||
if (!$dataFound and $worksheet->getCell([1, $row->getRowIndex()])->getCalculatedValue() !== null
|
||||
and trim($worksheet->getCell([1, $row->getRowIndex()])->getCalculatedValue()) === 'Fecha Contable') {
|
||||
$dataFound = true;
|
||||
$columns = $this->getRowData($row);
|
||||
continue;
|
||||
}
|
||||
if (!$dataFound) {
|
||||
continue;
|
||||
}
|
||||
if ($worksheet->getCell([1, $row->getRowIndex()])->getValue() === null) {
|
||||
break;
|
||||
}
|
||||
$rowData = $this->getRowData($row);
|
||||
$rowData = array_combine($columns, $rowData);
|
||||
$rowData['Fecha'] = implode('-', array_reverse(explode('-', $rowData['Fecha'])));
|
||||
$rowData['Cargo ($)'] = (int) str_replace('.', '', $rowData['Cargo ($)']);
|
||||
$rowData['Abono ($)'] = (int) str_replace('.', '', $rowData['Abono ($)']);
|
||||
$rowData['Saldo Diario'] = (int) str_replace('.', '', $rowData['Saldo Diario']);
|
||||
$rowData['Fecha Transacción'] = implode('-', array_reverse(explode('/', $rowData['Fecha Transacción'])));
|
||||
$rowData['Cargo $ (-)'] = (int) str_replace('.', '', $rowData['Cargo $ (-)'] ?? 0);
|
||||
$rowData['Abono $ (+)'] = (int) str_replace('.', '', $rowData['Abono $ (+)'] ?? 0);
|
||||
$saldo = $saldo + $rowData['Cargo $ (-)'] - $rowData['Abono $ (+)'];
|
||||
$rowData['Saldo'] = $saldo;
|
||||
unset($rowData['']);
|
||||
|
||||
$data []= $rowData;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function getRowContent(DOMElement $row): array
|
||||
protected function getRowData(PhpSpreadsheet\Worksheet\Row $row): array
|
||||
{
|
||||
$content = [];
|
||||
$tdsIterator = $row->getElementsByTagName('td')->getIterator();
|
||||
foreach ($tdsIterator as $cell) {
|
||||
$content []= $cell->textContent;
|
||||
$data = [];
|
||||
$cells = $row->getColumnIterator();
|
||||
foreach ($cells as $cell) {
|
||||
$data []= $cell->getCalculatedValue();
|
||||
}
|
||||
return $content;
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user