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/ColegiumDtv3Import.php
<?php

namespace App\Imports;

use Exception;

class ColegiumDtv3Import extends AbstractChunksImport
{
     protected function getExpectedHeaders(): array
    {
        return [
            'apoderado',
            'run_apoderado',
            'alumno',
            'fecha_nacimiento',
            'rut',
            'nivel',
            'curso',
            'descripcion_del_cargo',
            'monto_del_cargo',
            'saldo',
            'fecha_pago',
            'estado',
            'boleta',
            'fecha_vcto_aviso'
        ];
    }

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

    protected function getSheetName()
    {
        return 0;
    }

    protected int $headingRowIndex = 2;

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

        try {
            // Validación de data
            if (!empty($row['apoderado'])) {
                $apoderado = $row['apoderado'];
            } else {
                $apoderado = null;
            }

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

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

            if (!empty($row['fecha_nacimiento'])) {
                try {
                    $fecha_nacimiento = ordenar_fechaServidor($row['fecha_nacimiento']);
                } catch (Exception $e) {
                    $validation_errors++;
                    $validation_messages .= ($validation_errors) . ': fecha_nacimiento inválida. ';
                }
            } else {
                $fecha_nacimiento = null;
            }

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

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

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

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

            if (!empty($row['monto_del_cargo'])) {
                try {
                    $monto_del_cargo = floatval($row['monto_del_cargo']);
                } catch (\Throwable $th) {
                    $validation_errors++;
                    $validation_messages .= ($validation_errors) . ': monto_del_cargo inválido. ';
                }
                
            } else {
                $monto_del_cargo = 0;
            }

            if (!empty($row['saldo'])) {
                try {
                    $saldo = floatval($row['saldo']);
                } catch (\Throwable $th) {
                    $validation_errors++;
                    $validation_messages .= ($validation_errors) . ': saldo inválido. ';
                }
                
            } else {
                $saldo = 0;
            }

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

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

            if (!empty($row['boleta'])) {
                try {
                    $boleta = intval($row['boleta']);
                } catch (\Throwable $th) {
                    $validation_errors++;
                    $validation_messages .= ($validation_errors) . ': boleta inválido. ';
                }
                
            } else {
                $boleta = 0;
            }

            
            if (!empty($row['fecha_vcto_aviso'])) {
                try {
                    $fecha_vcto_aviso = ordenar_fechaServidor($row['fecha_vcto_aviso']);
                } catch (Exception $e) {
                    $validation_errors++;
                    $validation_messages .= ($validation_errors) . ': fecha_vcto_aviso inválida. ';
                }
            } else {
                $fecha_vcto_aviso = null;
            }

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

            return [
                'parent' => $apoderado,
                'parent_rut' => $run_apoderado,
                'student' => $alumno,
                'birth_date' => $fecha_nacimiento,
                'rut' => $rut,
                'level' => $nivel,
                'class' => $curso,
                'charge_description' => $descripcion_del_cargo,
                'charge_amount' => $monto_del_cargo,
                'balance' => $saldo,
                'payment_date' => $fecha_pago,
                'status' => $estado,
                'invoice' => $boleta,
                'expiration_alert_date' => $fecha_vcto_aviso,
                '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;
        }
    }
}