1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace PhpCfdi\SatCatalogosPopulate\Importers; |
6
|
|
|
|
7
|
|
|
use PhpCfdi\SatCatalogosPopulate\Database\Repository; |
8
|
|
|
use PhpCfdi\SatCatalogosPopulate\ImporterInterface; |
9
|
|
|
use Psr\Log\LoggerInterface; |
10
|
|
|
use RuntimeException; |
11
|
|
|
|
12
|
|
|
class SourcesImporter implements ImporterInterface |
13
|
|
|
{ |
14
|
1 |
|
public function import(string $source, Repository $repository, LoggerInterface $logger): void |
15
|
|
|
{ |
16
|
1 |
|
$importers = [ |
17
|
1 |
|
'CFDI 3.3' => ['source' => $source . '/catCFDI.xls', 'importer' => new CfdiCatalogs()], |
18
|
1 |
|
'CFDI 4.0' => ['source' => $source . '/cfdi_40.xls', 'importer' => new Cfdi40Catalogs()], |
19
|
1 |
|
'Nóminas' => ['source' => $source . '/catNomina.xls', 'importer' => new NominaCatalogs()], |
20
|
|
|
'Nóminas - Estados' => [ |
21
|
1 |
|
'source' => $source . '/nominas_estados.xls', |
22
|
1 |
|
'importer' => new NominaEstadosCatalogs(), |
23
|
|
|
], |
24
|
1 |
|
'CCE' => ['source' => $source, 'importer' => new CceCatalogs()], |
25
|
1 |
|
'Pagos' => ['source' => $source . '/catPagos.xls', 'importer' => new RepCatalogs()], |
26
|
1 |
|
'CCP 2.0' => ['source' => $source . '/CatalogosCartaPorte20.xls', 'importer' => new Ccp20Catalogs()], |
27
|
|
|
]; |
28
|
|
|
|
29
|
1 |
|
foreach ($importers as $name => $info) { |
30
|
1 |
|
$sourceFile = $info['source']; |
31
|
1 |
|
if (! file_exists($sourceFile)) { |
32
|
|
|
throw new RuntimeException("Se esperaba encontrar $sourceFile pero no existe"); |
33
|
|
|
} |
34
|
|
|
} |
35
|
|
|
|
36
|
1 |
|
foreach ($importers as $name => $info) { |
37
|
|
|
/** @var ImporterInterface $importer */ |
38
|
1 |
|
$sourceFile = $info['source']; |
39
|
1 |
|
$importer = $info['importer']; |
40
|
1 |
|
$logger->info("Importando $name desde $sourceFile..."); |
41
|
1 |
|
$importer->import($sourceFile, $repository, $logger); |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|