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

namespace App\Imports;

class TreasuryPacImport extends AbstractChunksImport
{
     protected function getExpectedHeaders(): array
    {
        return [
            'banco',
            'ctacte',
            'monto',
            'rut_afinanciero',
            'rut_alumno',
            'estado',
            'mes_cobro',
            'fecha',
            'forma_de_pago'
        ];
    }

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

    protected function getSheetName()
    {
        return 0;
    }

    protected int $headingRowIndex = 2;

    protected function normalizeRow(array $row, int $numRow): ?array
    {
        // 👇 OMITIR FILAS DE TOTALES
        if (empty($row['orden_de_compra']) && stripos($row['pagador'] ?? '', 'total') !== false) {
            return null;
        }

        $validation_errors = 0;
        $validation_messages = '';

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

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

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

            if (!empty($row['rut_afinanciero']) && $row['rut_afinanciero'] !== 'Sin Información') {
                if (!validateRut(trim($row['rut_afinanciero']))) {
                    $validation_errors++;
                    $validation_messages .= ($validation_errors) . ': rut_afinanciero ' . '"' . $row['rut_afinanciero'] . '"' . ' inválido. ';
                } else {
                    $rut_afinanciero = formateaRut($row['rut_afinanciero']);
                }
            } else {
                $rut_afinanciero = null;
            }

            if (!empty($row['rut_alumno']) && $row['rut_alumno'] !== 'Sin Información') {
                if (!validateRut(trim($row['rut_alumno']))) {
                    $validation_errors++;
                    $validation_messages .= ($validation_errors) . ': rut_alumno ' . '"' . $row['rut_alumno'] . '"' . ' inválido. ';
                } else {
                    $rut_alumno = formateaRut($row['rut_alumno']);
                }
            } else {
                $rut_alumno = null;
            }

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

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

            if (!empty($row['fecha'])) {
                if (validateDate($row['fecha'], 'd/m/Y')) {
                    $validation_errors++;
                    $validation_messages .= ($validation_errors) . ': fecha inválida. ';
                } else {
                    $fecha = ordenar_fechaSlashServidor($row['fecha']);
                }
            } else {
                $fecha = null;
            }
            
            if (!empty($row['forma_de_pago'])) {
                $forma_de_pago = $row['forma_de_pago'];
            } else {
                $forma_de_pago = 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 [
                'bank' => $banco,
                'account' => $ctacte,
                'amount' => $monto,
                'financial_parent_rut' => $rut_afinanciero,
                'student_rut' => $rut_alumno,
                'status' => $estado,
                'billing_month' => $mes_cobro,
                'date' => $fecha,
                'payment_method' => $forma_de_pago,
                '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;
        }
    }
}