HEX
Server: Apache/2.4.58 (Ubuntu)
System: Linux Bradford-Sitios 6.14.0-1017-azure #17~24.04.1-Ubuntu SMP Mon Dec 1 20:10:50 UTC 2025 x86_64
User: www-data (33)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/dtw.bradford/app/Imports/ColegiumCentralizationImport.php
<?php

namespace App\Imports;

use Exception;
use PhpOffice\PhpSpreadsheet\Shared\Date;

class ColegiumCentralizationImport extends AbstractChunksImport
{
    protected function getExpectedHeaders(): array
    {
        return [
            'fecha',
            'cuenta',
            'descripcion',
            'debe',
            'haber',
            'glosa',
            'proveedores',
        ];
    }

    protected function getTableName(): string
    {
        return 'colegium_centralization';
    }

    protected function getSheetName()
    {
        return 'Centralizacion Flexline';
    }

    protected function normalizeRow(array $row, int $numRow): ?array
    {
        try {
            $validation_errors = 0;
            $validation_messages = '';

            if (!empty($row['fecha'])) {
                try {
                    $date = Date::excelToDateTimeObject($row['fecha']);
                    $fecha = $date->format('Y-m-d');
                } catch (\Throwable $th) {
                    $validation_errors++;
                    $validation_messages .= ($validation_errors) . ': fecha inválida. ';
                }
            } else {
                $fecha = null;
            }

            if (!empty($row['cuenta'])) {
                $cuenta = $row['cuenta'];
            } else {
                $cuenta = null;
            }

            if (!empty($row['descripcion'])) {
                $descripcion = $row['descripcion'];
            } else {
                $descripcion = null;
            }

            if (!empty($row['debe'])) {
                if (!is_float(limpiaMonedaDecimal($row['debe']))) {
                    $validation_errors++;
                    $validation_messages .= ($validation_errors) . ': debe inválido. ';
                } else {
                    $debe = limpiaMonedaDecimal($row['debe']);
                }
            } else {
                $debe = 0;
            }

            if (!empty($row['haber'])) {
                if (!is_float(limpiaMonedaDecimal($row['haber']))) {
                    $validation_errors++;
                    $validation_messages .= ($validation_errors) . ': haber inválido. ';
                } else {
                    $haber = limpiaMonedaDecimal($row['haber']);
                }
            } else {
                $haber = 0;
            }

            if (!empty($row['glosa'])) {
                $glosa = $row['glosa'];
            } else {
                $glosa = null;
            }

            if (!empty($row['proveedores'])) {
                if (!validateRut(trim($row['proveedores']))) {
                    $validation_errors++;
                    $validation_messages .= ($validation_errors) . ': proveedores inválido. ';
                } else {
                    $proveedores = formateaRut($row['proveedores']);
                }
            } else {
                $proveedores = null;
            }

            if ($validation_errors > 0) {
                $this->error_data[] = [
                    'numero_de_linea' => $numRow,
                    'errores' => $validation_messages,
                    'fecha_de_carga' => date('d-m-Y H:i'),
                ];
                return null;
            }

            return [
                'date' => $fecha,
                'account' => $cuenta,
                'description' => $descripcion,
                'debit' => $debe,
                'credit' => $haber,
                'detail' => $glosa,
                'provider_rut' => $proveedores,
                'created_at' => ahoraServidor()
            ];
        } catch (\Throwable $e) {
            $this->error_data[] = [
                'numero_de_linea' => $numRow,
                'errores' => 'Excepción: ' . $e->getMessage(),
                'fecha_de_carga' => date('d-m-Y H:i'),
            ];
            return null;
        }
    }
}