|
1
|
|
|
<?php |
|
2
|
|
|
namespace CbCaio\Boletos\Models\BoletoInfo; |
|
3
|
|
|
|
|
4
|
|
|
use Carbon\Carbon; |
|
5
|
|
|
use CbCaio\Boletos\Calculators\Calculator; |
|
6
|
|
|
use CbCaio\Boletos\Models\BoletoInfo\Base\Boleto; |
|
7
|
|
|
|
|
8
|
|
|
class BoletoInfo extends Boleto |
|
9
|
|
|
{ |
|
10
|
|
|
protected $date_format = 'Y-m-d'; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @param bool|FALSE $formatado10digitos |
|
14
|
|
|
* @param bool|FALSE $inteiro |
|
15
|
|
|
* @return int|null|string |
|
16
|
|
|
*/ |
|
17
|
|
|
public function getValorFinal($formatado10digitos = false, $inteiro = false) |
|
18
|
|
|
{ |
|
19
|
|
|
$data_processamento = $this->getDataProcessamento(); |
|
20
|
|
|
$data_vencimento = $this->getDataVencimentoRecebida(); |
|
21
|
|
|
$vencido = ($data_processamento->toDateString() > $data_vencimento->toDateString()); |
|
22
|
|
|
|
|
23
|
|
|
$valor_cobrado = $this->getValorBase(); |
|
24
|
|
|
if ($vencido) { |
|
25
|
|
|
$diferenca_dias = $data_processamento->diffInDays($data_vencimento); |
|
26
|
|
|
$valor_cobrado += $this->getValorTaxa(true) * $diferenca_dias + $this->getValorMulta(true); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
if ($formatado10digitos === true) { |
|
30
|
|
|
return Calculator::formataNumero($valor_cobrado, 10, 0); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
if ($inteiro === true) { |
|
34
|
|
|
return $valor_cobrado; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
return Calculator::formataValor($valor_cobrado); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @return Carbon |
|
42
|
|
|
*/ |
|
43
|
|
|
public function getDataVencimentoCalculada() |
|
44
|
|
|
{ |
|
45
|
|
|
$data_hoje = Carbon::now()->setTime(0, 0, 0); |
|
46
|
|
|
if ($data_hoje->timestamp > $this->getDataVencimentoRecebida()->timestamp) { |
|
47
|
|
|
$dias_para_pagar = $this->getDiasParaPagar(); |
|
48
|
|
|
if ($dias_para_pagar == null) { |
|
|
|
|
|
|
49
|
|
|
return $data_hoje; |
|
50
|
|
|
} else { |
|
51
|
|
|
$data_vencimento = $data_hoje->addDay($dias_para_pagar); |
|
52
|
|
|
|
|
53
|
|
|
return $data_vencimento; |
|
54
|
|
|
} |
|
55
|
|
|
} else { |
|
56
|
|
|
return $this->getDataVencimentoRecebida(); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @param bool|FALSE $valor_inteiro |
|
62
|
|
|
* @return int|string |
|
63
|
|
|
*/ |
|
64
|
|
View Code Duplication |
public function getValorTaxa($valor_inteiro = false) |
|
|
|
|
|
|
65
|
|
|
{ |
|
66
|
|
|
$valor_taxa = intval(($this->getTaxaPercentual() / 3000) * $this->getValorBase()); |
|
67
|
|
|
|
|
68
|
|
|
if ($valor_inteiro) { |
|
69
|
|
|
return $valor_taxa; |
|
70
|
|
|
} else { |
|
71
|
|
|
return Calculator::formataValor($valor_taxa); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @param bool|FALSE $valor_inteiro |
|
77
|
|
|
* @return int|string |
|
78
|
|
|
*/ |
|
79
|
|
View Code Duplication |
public function getValorMulta($valor_inteiro = false) |
|
|
|
|
|
|
80
|
|
|
{ |
|
81
|
|
|
$valor_multa = intval(($this->getMultaPercentual() / 100) * $this->getValorBase()); |
|
82
|
|
|
|
|
83
|
|
|
if ($valor_inteiro) { |
|
84
|
|
|
return $valor_multa; |
|
85
|
|
|
} else { |
|
86
|
|
|
return Calculator::formataValor($valor_multa); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @return Carbon |
|
92
|
|
|
*/ |
|
93
|
|
View Code Duplication |
public function getDataVencimentoRecebida() |
|
|
|
|
|
|
94
|
|
|
{ |
|
95
|
|
|
if ($this->attributes['data_vencimento'] instanceof Carbon) { |
|
96
|
|
|
return $this->attributes['data_vencimento']->setTime(0, 0, 0); |
|
97
|
|
|
} else { |
|
98
|
|
|
return Carbon::createFromFormat($this->date_format, $this->attributes['data_vencimento']) |
|
99
|
|
|
->setTime(0, 0, 0); |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @return Carbon |
|
105
|
|
|
*/ |
|
106
|
|
View Code Duplication |
public function getDataDocumento() |
|
|
|
|
|
|
107
|
|
|
{ |
|
108
|
|
|
if ($this->attributes['data_documento'] instanceof Carbon) { |
|
109
|
|
|
return $this->attributes['data_documento']->setTime(0, 0, 0); |
|
110
|
|
|
} else { |
|
111
|
|
|
return Carbon::createFromFormat( |
|
112
|
|
|
$this->date_format, $this->attributes['data_documento'])->setTime(0, 0, 0); |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* @return Carbon |
|
118
|
|
|
*/ |
|
119
|
|
|
public function getDataProcessamento() |
|
120
|
|
|
{ |
|
121
|
|
|
if (isset($this->attributes['data_processamento'])) { |
|
122
|
|
|
$data_processamento = $this->attributes['data_processamento']; |
|
123
|
|
|
|
|
124
|
|
|
if (!($data_processamento instanceof Carbon)) { |
|
125
|
|
|
$data_processamento = Carbon::createFromFormat('Y-m-d', $data_processamento); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
if (!$data_processamento->isPast()) { |
|
129
|
|
|
return $data_processamento->setTime(0, 0, 0); |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
return Carbon::now()->setTime(0, 0, 0); |
|
134
|
|
|
} |
|
135
|
|
|
} |