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