1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Claudsonm\Pedi\Standards\PagSeguro\Records; |
4
|
|
|
|
5
|
|
|
use DateTime; |
6
|
|
|
use Claudsonm\Pedi\Standards\PagSeguro\Enums\TipoRegistro; |
7
|
|
|
use Claudsonm\Pedi\Structure\Field; |
8
|
|
|
use Claudsonm\Pedi\Structure\Record; |
9
|
|
|
use Claudsonm\Pedi\Structure\Types\Numeric; |
10
|
|
|
|
11
|
|
|
class Saldo extends Record |
12
|
|
|
{ |
13
|
|
|
private array $definitions = [ |
14
|
|
|
[ |
15
|
|
|
'size' => 1, |
16
|
|
|
'start' => 1, |
17
|
|
|
'type' => Numeric::class, |
18
|
|
|
'name' => 'TIPO_REGISTRO', |
19
|
|
|
], |
20
|
|
|
[ |
21
|
|
|
'size' => 10, |
22
|
|
|
'start' => 2, |
23
|
|
|
'type' => Numeric::class, |
24
|
|
|
'name' => 'ESTABELECIMENTO', |
25
|
|
|
], |
26
|
|
|
[ |
27
|
|
|
'size' => 8, |
28
|
|
|
'start' => 12, |
29
|
|
|
'type' => Numeric::class, |
30
|
|
|
'name' => 'DATA_MOVIMENTACAO', |
31
|
|
|
], |
32
|
|
|
[ |
33
|
|
|
'size' => 2, |
34
|
|
|
'start' => 20, |
35
|
|
|
'type' => Numeric::class, |
36
|
|
|
'name' => 'TIPO_EVENTO', |
37
|
|
|
], |
38
|
|
|
[ |
39
|
|
|
'size' => 13, |
40
|
|
|
'start' => 22, |
41
|
|
|
'type' => Numeric::class, |
42
|
|
|
'name' => 'VALOR_SALDO', |
43
|
|
|
], |
44
|
|
|
]; |
45
|
|
|
|
46
|
25 |
|
public function __construct() |
47
|
|
|
{ |
48
|
25 |
|
foreach ($this->definitions as $definition) { |
49
|
25 |
|
$field = (new Field()) |
50
|
25 |
|
->setSize($definition['size']) |
51
|
25 |
|
->setStart($definition['start']) |
52
|
25 |
|
->setType(new $definition['type']()) |
53
|
25 |
|
->setName($definition['name']); |
54
|
25 |
|
$this->add($field); |
55
|
|
|
} |
56
|
25 |
|
} |
57
|
|
|
|
58
|
23 |
|
public function matches(string $line): bool |
59
|
|
|
{ |
60
|
23 |
|
return TipoRegistro::SALDO === substr($line, 0, 1); |
61
|
|
|
} |
62
|
|
|
|
63
|
1 |
|
public function getDataMovimentacao(): DateTime |
64
|
|
|
{ |
65
|
1 |
|
return DateTime::createFromFormat('Ymd', $this->fields[2]->getContent()); |
66
|
|
|
} |
67
|
|
|
|
68
|
1 |
|
public function getValor(): float |
69
|
|
|
{ |
70
|
1 |
|
return $this->fields[4]->getContent() / 100; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|