Laravel 11, Vuexy Admin 10.3, by admin@koneko.mx
This commit is contained in:
78
modules/Admin/App/Imports/SATCodigoPostalImport.php
Normal file
78
modules/Admin/App/Imports/SATCodigoPostalImport.php
Normal file
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Imports;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Maatwebsite\Excel\Concerns\ToCollection;
|
||||
|
||||
class SATCodigoPostalImport implements ToCollection
|
||||
{
|
||||
public function collection(Collection $collection)
|
||||
{
|
||||
$batchSize = 1000;
|
||||
$batchData = [];
|
||||
$processedRows = 0;
|
||||
|
||||
foreach ($collection as $key => $row) {
|
||||
if ($key < 7 || !$row[1]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$requestArray = [
|
||||
'c_codigo_postal' => $row[0],
|
||||
'c_estado' => $row[1],
|
||||
'c_municipio' => $row[2],
|
||||
'c_localidad' => $row[3],
|
||||
'estimulo_franja_fronteriza' => $row[4],
|
||||
'fecha_inicio_de_vigencia' => $row[5] ?
|
||||
Carbon::instance(\PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($row[5])) :
|
||||
null,
|
||||
'fecha_fin_de_vigencia' => $row[6] ?
|
||||
Carbon::instance(\PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($row[6])) :
|
||||
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_codigo_postal')->upsert(
|
||||
$batchData,
|
||||
[
|
||||
'c_codigo_postal'
|
||||
],
|
||||
[
|
||||
'c_estado',
|
||||
'c_municipio',
|
||||
'c_localidad',
|
||||
'estimulo_franja_fronteriza',
|
||||
'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";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
68
modules/Admin/App/Imports/SATColoniaImport.php
Normal file
68
modules/Admin/App/Imports/SATColoniaImport.php
Normal file
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Imports;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Maatwebsite\Excel\Concerns\ToCollection;
|
||||
|
||||
class SATColoniaImport implements ToCollection
|
||||
{
|
||||
/**
|
||||
* @param Collection $collection
|
||||
*/
|
||||
public function collection(Collection $collection)
|
||||
{
|
||||
$batchSize = 1000;
|
||||
$batchData = [];
|
||||
$processedRows = 0;
|
||||
|
||||
foreach ($collection as $key => $row) {
|
||||
if ($key < 5 || !$row[1]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$requestArray = [
|
||||
'c_colonia' => $row[0],
|
||||
'c_codigo_postal' => $row[1],
|
||||
'nombre_del_asentamiento' => $row[2],
|
||||
];
|
||||
|
||||
$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_colonia')->upsert(
|
||||
$batchData,
|
||||
[
|
||||
'c_colonia',
|
||||
'c_codigo_postal',
|
||||
],
|
||||
[
|
||||
'nombre_del_asentamiento',
|
||||
]
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
echo "Error in batch: " . $e->getMessage() . "\n";
|
||||
|
||||
foreach ($batchData as $row) {
|
||||
echo "Row data: " . json_encode($row) . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
77
modules/Admin/App/Imports/SATEstadoImport.php
Normal file
77
modules/Admin/App/Imports/SATEstadoImport.php
Normal file
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Imports;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Maatwebsite\Excel\Concerns\ToCollection;
|
||||
|
||||
class SATEstadoImport implements ToCollection
|
||||
{
|
||||
/**
|
||||
* @param Collection $collection
|
||||
*/
|
||||
public function collection(Collection $collection)
|
||||
{
|
||||
$batchSize = 1000;
|
||||
$batchData = [];
|
||||
$processedRows = 0;
|
||||
|
||||
foreach ($collection as $key => $row) {
|
||||
if ($key < 5 || !$row[1]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$requestArray = [
|
||||
'c_estado' => $row[0],
|
||||
'c_pais' => $row[1],
|
||||
'nombre_del_estado' => $row[2],
|
||||
'fecha_inicio_de_vigencia' => $row[3] ?
|
||||
Carbon::instance(\PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($row[3])) :
|
||||
null,
|
||||
'fecha_fin_de_vigencia' => $row[4] ?
|
||||
Carbon::instance(\PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($row[4])) :
|
||||
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_estado')->upsert(
|
||||
$batchData,
|
||||
[
|
||||
'c_estado',
|
||||
'c_pais',
|
||||
],
|
||||
[
|
||||
'nombre_del_estado',
|
||||
'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";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
95
modules/Admin/App/Imports/SATFormaPagoImport.php
Normal file
95
modules/Admin/App/Imports/SATFormaPagoImport.php
Normal file
@ -0,0 +1,95 @@
|
||||
<?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";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
77
modules/Admin/App/Imports/SATLocalidadImport.php
Normal file
77
modules/Admin/App/Imports/SATLocalidadImport.php
Normal file
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Imports;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Maatwebsite\Excel\Concerns\ToCollection;
|
||||
|
||||
class SATLocalidadImport implements ToCollection
|
||||
{
|
||||
/**
|
||||
* @param Collection $collection
|
||||
*/
|
||||
public function collection(Collection $collection)
|
||||
{
|
||||
$batchSize = 1000;
|
||||
$batchData = [];
|
||||
$processedRows = 0;
|
||||
|
||||
foreach ($collection as $key => $row) {
|
||||
if ($key < 5 || !$row[1]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$requestArray = [
|
||||
'c_localidad' => $row[0],
|
||||
'c_estado' => $row[1],
|
||||
'descripcion' => $row[2],
|
||||
'fecha_de_inicio_de_vigencia' => $row[3] ?
|
||||
Carbon::instance(\PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($row[3])) :
|
||||
null,
|
||||
'fecha_de_fin_de_vigencia' => $row[4] ?
|
||||
Carbon::instance(\PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($row[4])) :
|
||||
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_localidad')->upsert(
|
||||
$batchData,
|
||||
[
|
||||
'c_localidad',
|
||||
'c_estado',
|
||||
],
|
||||
[
|
||||
'descripcion',
|
||||
'fecha_de_inicio_de_vigencia',
|
||||
'fecha_de_fin_de_vigencia'
|
||||
]
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
echo "Error in batch: " . $e->getMessage() . "\n";
|
||||
|
||||
foreach ($batchData as $row) {
|
||||
echo "Row data: " . json_encode($row) . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
79
modules/Admin/App/Imports/SATMonedaImport.php
Normal file
79
modules/Admin/App/Imports/SATMonedaImport.php
Normal file
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Imports;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Maatwebsite\Excel\Concerns\ToCollection;
|
||||
|
||||
class SATMonedaImport implements ToCollection
|
||||
{
|
||||
/**
|
||||
* @param Collection $collection
|
||||
*/
|
||||
public function collection(Collection $collection)
|
||||
{
|
||||
$batchSize = 1000;
|
||||
$batchData = [];
|
||||
$processedRows = 0;
|
||||
|
||||
foreach ($collection as $key => $row) {
|
||||
if ($key < 5 || !$row[1]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$requestArray = [
|
||||
'c_moneda' => $row[0],
|
||||
'descripcion' => $row[1],
|
||||
'decimales' => $row[2],
|
||||
'porcentaje_variacion' => $row[3],
|
||||
'fecha_inicio_de_vigencia' => $row[4] ?
|
||||
Carbon::instance(\PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($row[4])) :
|
||||
null,
|
||||
'fecha_fin_de_vigencia' => $row[5] ?
|
||||
Carbon::instance(\PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($row[5])) :
|
||||
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_moneda')->upsert(
|
||||
$batchData,
|
||||
[
|
||||
'c_moneda',
|
||||
],
|
||||
[
|
||||
'descripcion',
|
||||
'decimales',
|
||||
'porcentaje_variacion',
|
||||
'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";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
77
modules/Admin/App/Imports/SATMunicipioImport.php
Normal file
77
modules/Admin/App/Imports/SATMunicipioImport.php
Normal file
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Imports;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Maatwebsite\Excel\Concerns\ToCollection;
|
||||
|
||||
class SATMunicipioImport implements ToCollection
|
||||
{
|
||||
/**
|
||||
* @param Collection $collection
|
||||
*/
|
||||
public function collection(Collection $collection)
|
||||
{
|
||||
$batchSize = 1000;
|
||||
$batchData = [];
|
||||
$processedRows = 0;
|
||||
|
||||
foreach ($collection as $key => $row) {
|
||||
if ($key < 5 || !$row[1]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$requestArray = [
|
||||
'c_municipio' => $row[0],
|
||||
'c_estado' => $row[1],
|
||||
'descripcion' => $row[2],
|
||||
'fecha_de_inicio_de_vigencia' => $row[3] ?
|
||||
Carbon::instance(\PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($row[3])) :
|
||||
null,
|
||||
'fecha_de_fin_de_vigencia' => $row[4] ?
|
||||
Carbon::instance(\PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($row[4])) :
|
||||
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_municipio')->upsert(
|
||||
$batchData,
|
||||
[
|
||||
'c_municipio',
|
||||
'c_estado',
|
||||
],
|
||||
[
|
||||
'descripcion',
|
||||
'fecha_de_inicio_de_vigencia',
|
||||
'fecha_de_fin_de_vigencia'
|
||||
]
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
echo "Error in batch: " . $e->getMessage() . "\n";
|
||||
|
||||
foreach ($batchData as $row) {
|
||||
echo "Row data: " . json_encode($row) . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
74
modules/Admin/App/Imports/SATPaisImport.php
Normal file
74
modules/Admin/App/Imports/SATPaisImport.php
Normal file
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Imports;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Maatwebsite\Excel\Concerns\ToCollection;
|
||||
|
||||
class SATPaisImport implements ToCollection
|
||||
{
|
||||
/**
|
||||
* @param Collection $collection
|
||||
*/
|
||||
public function collection(Collection $collection)
|
||||
{
|
||||
$batchSize = 1000;
|
||||
$batchData = [];
|
||||
$processedRows = 0;
|
||||
|
||||
foreach ($collection as $key => $row) {
|
||||
if ($key < 5 || !$row[1]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$requestArray = [
|
||||
'c_pais' => $row[0],
|
||||
'descripcion' => $row[1],
|
||||
'formato_de_codigo_postal' => $row[2],
|
||||
'formato_de_registro_de_identidad_tributaria' => $row[3],
|
||||
'validacion_del_registro_de_identidad_tributaria' => $row[4],
|
||||
'agrupaciones' => $row[5],
|
||||
];
|
||||
|
||||
$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_pais')->upsert(
|
||||
$batchData,
|
||||
[
|
||||
'c_pais',
|
||||
],
|
||||
[
|
||||
'descripcion',
|
||||
'formato_de_codigo_postal',
|
||||
'formato_de_registro_de_identidad_tributaria',
|
||||
'validacion_del_registro_de_identidad_tributaria',
|
||||
'agrupaciones',
|
||||
]
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
echo "Error in batch: " . $e->getMessage() . "\n";
|
||||
|
||||
foreach ($batchData as $row) {
|
||||
echo "Row data: " . json_encode($row) . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
79
modules/Admin/App/Imports/SATRegimenFiscalImport.php
Normal file
79
modules/Admin/App/Imports/SATRegimenFiscalImport.php
Normal file
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Imports;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Maatwebsite\Excel\Concerns\ToCollection;
|
||||
|
||||
class SATRegimenFiscalImport 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_regimen_fiscal' => $row[0],
|
||||
'descripcion' => $row[1],
|
||||
'fisica' => $row[2],
|
||||
'moral' => $row[3],
|
||||
'fecha_de_inicio_de_vigencia' => $row[4] ?
|
||||
Carbon::instance(\PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($row[4])) :
|
||||
null,
|
||||
'fecha_de_fin_de_vigencia' => $row[5] ?
|
||||
Carbon::instance(\PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($row[5])) :
|
||||
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_regimen_fiscal')->upsert(
|
||||
$batchData,
|
||||
[
|
||||
'c_regimen_fiscal',
|
||||
],
|
||||
[
|
||||
'descripcion',
|
||||
'fisica',
|
||||
'moral',
|
||||
'fecha_de_inicio_de_vigencia',
|
||||
'fecha_de_fin_de_vigencia'
|
||||
]
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
echo "Error in batch: " . $e->getMessage() . "\n";
|
||||
|
||||
foreach ($batchData as $row) {
|
||||
echo "Row data: " . json_encode($row) . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
81
modules/Admin/App/Imports/SATUsoCFDIImport.php
Normal file
81
modules/Admin/App/Imports/SATUsoCFDIImport.php
Normal file
@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Imports;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Maatwebsite\Excel\Concerns\ToCollection;
|
||||
|
||||
class SATUsoCFDIImport 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_uso_cfdi' => $row[0],
|
||||
'descripcion' => $row[1],
|
||||
'aplica_para_tipo_persona_fisica' => $row[2],
|
||||
'aplica_para_tipo_persona_moral' => $row[3],
|
||||
'fecha_inicio_de_vigencia' => $row[4] ?
|
||||
Carbon::instance(\PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($row[4])) :
|
||||
null,
|
||||
'fecha_fin_de_vigencia' => $row[5] ?
|
||||
Carbon::instance(\PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($row[5])) :
|
||||
null,
|
||||
'regimen_fiscal_receptor' => $row[6],
|
||||
];
|
||||
|
||||
$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_uso_cfdi')->upsert(
|
||||
$batchData,
|
||||
[
|
||||
'c_uso_cfdi',
|
||||
],
|
||||
[
|
||||
'descripcion',
|
||||
'aplica_para_tipo_persona_fisica',
|
||||
'aplica_para_tipo_persona_moral',
|
||||
'fecha_inicio_de_vigencia',
|
||||
'fecha_fin_de_vigencia',
|
||||
'regimen_fiscal_receptor',
|
||||
]
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
echo "Error in batch: " . $e->getMessage() . "\n";
|
||||
|
||||
foreach ($batchData as $row) {
|
||||
echo "Row data: " . json_encode($row) . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
31
modules/Admin/App/Imports/SatCatalogsImport.php
Normal file
31
modules/Admin/App/Imports/SatCatalogsImport.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Admin\App\Imports;
|
||||
|
||||
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
|
||||
use Maatwebsite\Excel\Concerns\WithConditionalSheets;
|
||||
|
||||
|
||||
class SatCatalogsImport implements WithMultipleSheets
|
||||
{
|
||||
use WithConditionalSheets;
|
||||
|
||||
public function conditionalSheets(): array
|
||||
{
|
||||
return [
|
||||
'c_FormaPago' => new SATFormaPagoImport(),
|
||||
'c_Moneda' => new SATMonedaImport(),
|
||||
'c_CodigoPostal_Parte_1' => new SATCodigoPostalImport(),
|
||||
'c_CodigoPostal_Parte_2' => new SATCodigoPostalImport(),
|
||||
'c_RegimenFiscal' => new SATRegimenFiscalImport(),
|
||||
'c_Pais' => new SATPaisImport(),
|
||||
'c_UsoCFDI' => new SATUsoCFDIImport(),
|
||||
'C_Colonia_1' => new SATColoniaImport(),
|
||||
'C_Colonia_2' => new SATColoniaImport(),
|
||||
'C_Colonia_3' => new SATColoniaImport(),
|
||||
'c_Estado' => new SATEstadoImport(),
|
||||
'C_Localidad' => new SATLocalidadImport(),
|
||||
'C_Municipio' => new SATMunicipioImport(),
|
||||
];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user