96 lines
3.1 KiB
PHP
96 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace Modules\Admin\App\Imports;
|
|
|
|
use Carbon\Carbon;
|
|
use Illuminate\Support\Collection;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Maatwebsite\Excel\Concerns\ToCollection;
|
|
|
|
class SATFormaPagoImport implements ToCollection
|
|
{
|
|
/**
|
|
* @param Collection $collection
|
|
*/
|
|
public function collection(Collection $collection)
|
|
{
|
|
$batchSize = 1000;
|
|
$batchData = [];
|
|
$processedRows = 0;
|
|
|
|
foreach ($collection as $key => $row) {
|
|
if ($key < 6 || !$row[1]) {
|
|
continue;
|
|
}
|
|
|
|
$requestArray = [
|
|
'c_forma_pago' => $row[0],
|
|
'descripcion' => $row[1],
|
|
'bancarizado' => $row[2],
|
|
'numero_de_operacion' => $row[3],
|
|
'rfc_del_emisor_de_la_cuenta_ordenante' => $row[4],
|
|
'cuenta_ordenante' => $row[5],
|
|
'patron_para_cuenta_ordenante' => $row[6],
|
|
'rfc_del_emisor_cuenta_de_beneficiario' => $row[7],
|
|
'cuenta_de_benenficiario' => $row[8],
|
|
'patron_para_cuenta_beneficiaria' => $row[9],
|
|
'tipo_cadena_pago' => $row[10],
|
|
'banco_emisor_de_la_cuenta_ordenante' => $row[11],
|
|
'fecha_inicio_de_vigencia' => $row[12] ?
|
|
Carbon::instance(\PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($row[12])) :
|
|
null,
|
|
'fecha_fin_de_vigencia' => $row[13] ?
|
|
Carbon::instance(\PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($row[13])) :
|
|
null,
|
|
];
|
|
|
|
$batchData[] = $requestArray;
|
|
$processedRows++;
|
|
|
|
if (count($batchData) >= $batchSize) {
|
|
$this->insertBatch($batchData);
|
|
$batchData = [];
|
|
}
|
|
}
|
|
|
|
if (!empty($batchData)) {
|
|
$this->insertBatch($batchData);
|
|
}
|
|
|
|
echo "\n\033[32mImport completed: Processed $processedRows rows.\033[0m\n";
|
|
}
|
|
|
|
private function insertBatch(array $batchData)
|
|
{
|
|
try {
|
|
DB::table('sat_forma_pago')->upsert(
|
|
$batchData,
|
|
[
|
|
'c_forma_pago',
|
|
],
|
|
[
|
|
'descripcion',
|
|
'bancarizado',
|
|
'numero_de_operacion',
|
|
'rfc_del_emisor_de_la_cuenta_ordenante',
|
|
'cuenta_ordenante',
|
|
'patron_para_cuenta_ordenante',
|
|
'rfc_del_emisor_cuenta_de_beneficiario',
|
|
'cuenta_de_benenficiario',
|
|
'patron_para_cuenta_beneficiaria',
|
|
'tipo_cadena_pago',
|
|
'banco_emisor_de_la_cuenta_ordenante',
|
|
'fecha_inicio_de_vigencia',
|
|
'fecha_fin_de_vigencia',
|
|
]
|
|
);
|
|
} catch (\Exception $e) {
|
|
echo "Error in batch: " . $e->getMessage() . "\n";
|
|
|
|
foreach ($batchData as $row) {
|
|
echo "Row data: " . json_encode($row) . "\n";
|
|
}
|
|
}
|
|
}
|
|
}
|