Initial commit: Horux Backend API
- API REST para gestion de facturas electronicas mexicanas (CFDI) - Laravel 9 con autenticacion OAuth 2.0 (Passport) - Integracion con Syntage, Clerk y Facturama - 30 modelos Eloquent, 39 controladores - Documentacion completa en /docs Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
44
app/Imports/UnitCodesImport.php
Normal file
44
app/Imports/UnitCodesImport.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Imports;
|
||||
|
||||
use App\Models\UnitCode;
|
||||
use Carbon\Carbon;
|
||||
use Maatwebsite\Excel\Concerns\ToModel;
|
||||
use Maatwebsite\Excel\Concerns\WithChunkReading;
|
||||
use Maatwebsite\Excel\Concerns\WithStartRow;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadingRow;
|
||||
|
||||
class UnitCodesImport implements ToModel, WithChunkReading, WithHeadingRow, WithStartRow
|
||||
{
|
||||
|
||||
/**
|
||||
* Método para indicar desde qué fila comenzar a leer.
|
||||
*/
|
||||
public function startRow(): int
|
||||
{
|
||||
return 2; // Si tienes encabezados, comienza en la fila 2
|
||||
}
|
||||
|
||||
public function model(array $row)
|
||||
{
|
||||
|
||||
return UnitCode::updateOrCreate(
|
||||
['id' => $row['id']],
|
||||
['description' => $this->emptyToNull($row['description'])]
|
||||
);
|
||||
}
|
||||
|
||||
private function emptyToNull($value)
|
||||
{
|
||||
return $value === '' ? null : $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Devuelve el tamaño del chunk (en filas) a leer.
|
||||
*/
|
||||
public function chunkSize(): int
|
||||
{
|
||||
return 5000; // Ajusta el tamaño según tus necesidades
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user