OfficeBanking usando isExcel y correccion en procesamiento de valores.
This commit is contained in:
@ -4,9 +4,12 @@ namespace Incoviba\Service\Contabilidad\Cartola\Santander;
|
||||
use Psr\Http\Message\UploadedFileInterface;
|
||||
use PhpOffice\PhpSpreadsheet;
|
||||
use Incoviba\Common\Ideal\Cartola\Banco;
|
||||
use Incoviba\Service\Contabilidad\Cartola\isExcel;
|
||||
|
||||
class OfficeBanking extends Banco
|
||||
{
|
||||
use isExcel;
|
||||
|
||||
public function is(string $filename): bool
|
||||
{
|
||||
if (!str_ends_with($filename, 'xlsx')) {
|
||||
@ -14,17 +17,17 @@ class OfficeBanking extends Banco
|
||||
}
|
||||
try {
|
||||
$reader = PhpSpreadsheet\IOFactory::createReader('Xlsx');
|
||||
} catch (PhpSpreadsheet\Reader\Exception $exception) {
|
||||
} catch (PhpSpreadsheet\Reader\Exception) {
|
||||
return false;
|
||||
}
|
||||
$xlsx = $reader->load($filename);
|
||||
$sheet = $xlsx->getActiveSheet();
|
||||
$subtitle = $sheet->getCell('A1')->getCalculatedValue();
|
||||
if ($subtitle === 'Consulta de movimientos de Cuentas Corrientes') {
|
||||
if ($subtitle !== null and trim($subtitle) === 'Cartolas históricas de Cuentas Corrientes') {
|
||||
return true;
|
||||
}
|
||||
$subtitle = $sheet->getCell('A2')->getCalculatedValue();
|
||||
return $subtitle === 'Consulta de movimientos de Cuentas Corrientes';
|
||||
return $subtitle !== null and trim($subtitle) === 'Cartolas históricas de Cuentas Corrientes';
|
||||
}
|
||||
|
||||
protected function columnMap(): array
|
||||
@ -47,6 +50,7 @@ class OfficeBanking extends Banco
|
||||
'Factura Boleta' => 'identificador',
|
||||
'RUT' => 'rut',
|
||||
'Nombres' => 'nombres',
|
||||
'Depto' => 'identificador'
|
||||
];
|
||||
}
|
||||
protected function getFilename(UploadedFileInterface $uploadedFile): string
|
||||
@ -79,44 +83,44 @@ class OfficeBanking extends Banco
|
||||
$found = false;
|
||||
$columns = [];
|
||||
$data = [];
|
||||
foreach ($sheet->getRowIterator() as $row) {
|
||||
if (!$found and $sheet->getCell("A{$row->getRowIndex()}")->getCalculatedValue() === 'MONTO') {
|
||||
$titleValueMap = [
|
||||
'MONTO' => 'int'
|
||||
];
|
||||
$rowIterator = $sheet->getRowIterator();
|
||||
while ($rowIterator->valid()) {
|
||||
$row = $rowIterator->current();
|
||||
$first = $sheet->getCell("A{$row->getRowIndex()}")->getCalculatedValue();
|
||||
if ($first !== null) {
|
||||
$first = trim($first);
|
||||
}
|
||||
if (!$found and $first === 'MONTO') {
|
||||
$found = true;
|
||||
foreach ($row->getColumnIterator() as $column) {
|
||||
if ($column->getValue() === null) {
|
||||
break;
|
||||
}
|
||||
$columns[$column->getColumn()] = trim($column->getValue());
|
||||
}
|
||||
$columns = $this->grabTitlesRow($row);
|
||||
$rowIterator->next();
|
||||
continue;
|
||||
}
|
||||
if (!$found) {
|
||||
$rowIterator->next();
|
||||
continue;
|
||||
}
|
||||
if ($sheet->getCell("A{$row->getRowIndex()}")->getValue() === null) {
|
||||
if ($first === 'Resumen comisiones' or $first === null) {
|
||||
break;
|
||||
}
|
||||
$rowData = [];
|
||||
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)));
|
||||
}
|
||||
if ($column === 'MONTO' or $column === 'SALDO') {
|
||||
$value = (int) $value;
|
||||
}
|
||||
$rowData[$column] = $value;
|
||||
}
|
||||
if ($rowData['CARGO/ABONO'] === 'C') {
|
||||
$rowData['MONTO'] = -$rowData['MONTO'];
|
||||
$rowData['cargo'] = $rowData['MONTO'];
|
||||
$rowData = $this->grabRow($row, $columns, process: true, titleValueMap: $titleValueMap);
|
||||
$fecha = explode('/', $rowData['FECHA']);
|
||||
$rowData['FECHA'] = $fecha[2] . '-' . $fecha[1] . '-' . $fecha[0];
|
||||
switch ($rowData['CARGO/ABONO']) {
|
||||
case 'C':
|
||||
$rowData['abono'] = 0;
|
||||
} else {
|
||||
$rowData['cargo'] = 0;
|
||||
$rowData['cargo'] = -$rowData['MONTO'];
|
||||
break;
|
||||
default:
|
||||
$rowData['abono'] = $rowData['MONTO'];
|
||||
$rowData['cargo'] = 0;
|
||||
break;
|
||||
}
|
||||
$data []= $rowData;
|
||||
$data[] = $rowData;
|
||||
$rowIterator->next();
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
Reference in New Issue
Block a user