1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace PhpCfdi\SatCatalogosPopulate\Importers\Cce\Injectors; |
6
|
|
|
|
7
|
|
|
use PhpCfdi\SatCatalogosPopulate\AbstractCsvInjector; |
8
|
|
|
use PhpCfdi\SatCatalogosPopulate\Database\DataFields; |
9
|
|
|
use PhpCfdi\SatCatalogosPopulate\Database\DataTable; |
10
|
|
|
use PhpCfdi\SatCatalogosPopulate\Database\DateDataField; |
11
|
|
|
use PhpCfdi\SatCatalogosPopulate\Database\PaddingDataField; |
12
|
|
|
use PhpCfdi\SatCatalogosPopulate\Database\TextDataField; |
13
|
|
|
use PhpCfdi\SatCatalogosPopulate\Utils\ArrayProcessors\RightTrim; |
14
|
|
|
use PhpCfdi\SatCatalogosPopulate\Utils\CsvFile; |
15
|
|
|
use RuntimeException; |
16
|
|
|
|
17
|
|
|
class FraccionesArancelarias extends AbstractCsvInjector |
18
|
|
|
{ |
19
|
|
|
/** @param bool $shouldRecreateTable Indicates if the injector must recreate the table */ |
20
|
6 |
|
public function __construct( |
21
|
|
|
string $sourceFile, |
22
|
|
|
private bool $shouldRecreateTable |
23
|
|
|
) { |
24
|
6 |
|
parent::__construct($sourceFile); |
25
|
6 |
|
} |
26
|
|
|
|
27
|
1 |
|
protected function createCsvFileReader(): CsvFile |
28
|
|
|
{ |
29
|
1 |
|
return new CsvFile($this->sourceFile(), new RightTrim()); |
30
|
|
|
} |
31
|
|
|
|
32
|
3 |
|
public function checkHeaders(CsvFile $csv): void |
33
|
|
|
{ |
34
|
3 |
|
$csv->move(3); |
35
|
3 |
|
$expected = [ |
36
|
|
|
'c_FraccionArancelaria', |
37
|
|
|
'Descripción', |
38
|
|
|
'Fecha de inicio de vigencia', |
39
|
|
|
'Fecha de fin de vigencia', |
40
|
|
|
'UMT', |
41
|
|
|
]; |
42
|
3 |
|
$headers = $csv->readLine(); |
43
|
|
|
|
44
|
3 |
|
if ($expected !== $headers) { |
45
|
1 |
|
throw new RuntimeException("The headers did not match on file {$this->sourceFile()}"); |
46
|
|
|
} |
47
|
|
|
|
48
|
2 |
|
$csv->next(); |
49
|
2 |
|
} |
50
|
|
|
|
51
|
2 |
|
public function dataTable(): DataTable |
52
|
|
|
{ |
53
|
2 |
|
return new DataTable('cce_fracciones_arancelarias', new DataFields([ |
54
|
2 |
|
new TextDataField('fraccion'), |
55
|
2 |
|
new TextDataField('texto'), |
56
|
2 |
|
new DateDataField('vigencia_desde'), |
57
|
2 |
|
new DateDataField('vigencia_hasta'), |
58
|
2 |
|
new PaddingDataField('unidad', '0', 2), |
59
|
|
|
])); |
60
|
|
|
} |
61
|
|
|
|
62
|
1 |
|
protected function shouldRecreateTable(): bool |
63
|
|
|
{ |
64
|
1 |
|
return $this->shouldRecreateTable; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|