|
1
|
|
|
<?php |
|
2
|
|
|
namespace MrPrompt\Celesc\Shipment\Partial; |
|
3
|
|
|
|
|
4
|
|
|
use MrPrompt\ShipmentCommon\Base\Authorization; |
|
5
|
|
|
use MrPrompt\ShipmentCommon\Base\ConsumerUnity; |
|
6
|
|
|
use MrPrompt\ShipmentCommon\Base\Parcels; |
|
7
|
|
|
use MrPrompt\ShipmentCommon\Base\Purchaser; |
|
8
|
|
|
use MrPrompt\ShipmentCommon\Base\Seller; |
|
9
|
|
|
use MrPrompt\ShipmentCommon\Base\Sequence; |
|
10
|
|
|
use MrPrompt\ShipmentCommon\Type\Alphanumeric; |
|
11
|
|
|
use MrPrompt\ShipmentCommon\Type\Numeric; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* File detail |
|
15
|
|
|
* |
|
16
|
|
|
* @author Thiago Paes <[email protected]> |
|
17
|
|
|
*/ |
|
18
|
|
|
class Detail extends \stdClass |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* Type of register |
|
22
|
|
|
* |
|
23
|
|
|
* @var int |
|
24
|
|
|
*/ |
|
25
|
|
|
const TYPE = 2; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Sent code |
|
29
|
|
|
* |
|
30
|
|
|
* @const int |
|
31
|
|
|
*/ |
|
32
|
|
|
const CODE = '00'; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Date Format |
|
36
|
|
|
* |
|
37
|
|
|
* @var string |
|
38
|
|
|
*/ |
|
39
|
|
|
const DATE_FORMAT = 'dmY'; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Consumer Unity |
|
43
|
|
|
* |
|
44
|
|
|
* @var ConsumerUnity |
|
45
|
|
|
*/ |
|
46
|
|
|
private $consumerUnity; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Seller |
|
50
|
|
|
* |
|
51
|
|
|
* @var Seller |
|
52
|
|
|
*/ |
|
53
|
|
|
private $seller; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Purchaser |
|
57
|
|
|
* |
|
58
|
|
|
* @var Purchaser |
|
59
|
|
|
*/ |
|
60
|
|
|
private $purchaser; |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Parcels |
|
64
|
|
|
* |
|
65
|
|
|
* @var Parcels |
|
66
|
|
|
*/ |
|
67
|
|
|
private $parcels; |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Authorization |
|
71
|
|
|
* |
|
72
|
|
|
* @var Authorization |
|
73
|
|
|
*/ |
|
74
|
|
|
private $authorization; |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Sequence |
|
78
|
|
|
* |
|
79
|
|
|
* @var Sequence |
|
80
|
|
|
*/ |
|
81
|
|
|
private $sequence; |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Constructor |
|
85
|
|
|
* |
|
86
|
|
|
* @param Seller $seller |
|
87
|
|
|
* @param Purchaser $purchaser |
|
88
|
|
|
* @param Parcels $parcels |
|
89
|
|
|
* @param Authorization $authorization |
|
90
|
|
|
* @param ConsumerUnity $consumerUnity |
|
91
|
|
|
* @param Sequence $sequence |
|
92
|
|
|
*/ |
|
93
|
13 |
|
public function __construct( |
|
94
|
|
|
Seller $seller, |
|
95
|
|
|
Purchaser $purchaser, |
|
96
|
|
|
Parcels $parcels, |
|
97
|
|
|
Authorization $authorization, |
|
98
|
|
|
ConsumerUnity $consumerUnity, |
|
99
|
|
|
Sequence $sequence |
|
100
|
|
|
) { |
|
101
|
13 |
|
$this->seller = $seller; |
|
102
|
13 |
|
$this->purchaser = $purchaser; |
|
103
|
13 |
|
$this->parcels = $parcels; |
|
104
|
13 |
|
$this->authorization = $authorization; |
|
105
|
13 |
|
$this->consumerUnity = $consumerUnity; |
|
106
|
13 |
|
$this->sequence = $sequence; |
|
107
|
13 |
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* @return ConsumerUnity |
|
111
|
|
|
*/ |
|
112
|
1 |
|
public function getConsumerUnity() |
|
113
|
|
|
{ |
|
114
|
1 |
|
return $this->consumerUnity; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* @param ConsumerUnity $consumerUnity |
|
119
|
|
|
*/ |
|
120
|
1 |
|
public function setConsumerUnity(ConsumerUnity $consumerUnity) |
|
121
|
|
|
{ |
|
122
|
1 |
|
$this->consumerUnity = $consumerUnity; |
|
123
|
1 |
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* @return Seller |
|
127
|
|
|
*/ |
|
128
|
1 |
|
public function getSeller() |
|
129
|
|
|
{ |
|
130
|
1 |
|
return $this->seller; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* @param Seller $seller |
|
135
|
|
|
*/ |
|
136
|
1 |
|
public function setSeller(Seller $seller) |
|
137
|
|
|
{ |
|
138
|
1 |
|
$this->seller = $seller; |
|
139
|
1 |
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* @return Purchaser |
|
143
|
|
|
*/ |
|
144
|
1 |
|
public function getPurchaser() |
|
145
|
|
|
{ |
|
146
|
1 |
|
return $this->purchaser; |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* @param Purchaser $purchaser |
|
151
|
|
|
*/ |
|
152
|
1 |
|
public function setPurchaser(Purchaser $purchaser) |
|
153
|
|
|
{ |
|
154
|
1 |
|
$this->purchaser = $purchaser; |
|
155
|
1 |
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* @return Parcels |
|
159
|
|
|
*/ |
|
160
|
1 |
|
public function getParcels() |
|
161
|
|
|
{ |
|
162
|
1 |
|
return $this->parcels; |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
/** |
|
166
|
|
|
* @param Parcels $parcels |
|
167
|
|
|
*/ |
|
168
|
1 |
|
public function setParcels(Parcels $parcels) |
|
169
|
|
|
{ |
|
170
|
1 |
|
$this->parcels = $parcels; |
|
171
|
1 |
|
} |
|
172
|
|
|
|
|
173
|
|
|
/** |
|
174
|
|
|
* @return Authorization |
|
175
|
|
|
*/ |
|
176
|
1 |
|
public function getAuthorization() |
|
177
|
|
|
{ |
|
178
|
1 |
|
return $this->authorization; |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
/** |
|
182
|
|
|
* @param Authorization $authorization |
|
183
|
|
|
*/ |
|
184
|
1 |
|
public function setAuthorization(Authorization $authorization) |
|
185
|
|
|
{ |
|
186
|
1 |
|
$this->authorization = $authorization; |
|
187
|
1 |
|
} |
|
188
|
|
|
|
|
189
|
|
|
/** |
|
190
|
|
|
* @return Sequence |
|
191
|
|
|
*/ |
|
192
|
1 |
|
public function getSequence() |
|
193
|
|
|
{ |
|
194
|
1 |
|
return $this->sequence; |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
/** |
|
198
|
|
|
* @param Sequence $sequence |
|
199
|
|
|
*/ |
|
200
|
1 |
|
public function setSequence(Sequence $sequence) |
|
201
|
|
|
{ |
|
202
|
1 |
|
$this->sequence = $sequence; |
|
203
|
1 |
|
} |
|
204
|
|
|
|
|
205
|
|
|
/** |
|
206
|
|
|
* Render detail registry line |
|
207
|
|
|
* |
|
208
|
|
|
* @return string |
|
209
|
|
|
*/ |
|
210
|
1 |
|
public function render() |
|
211
|
|
|
{ |
|
212
|
|
|
// Register code |
|
213
|
1 |
|
$result = str_pad(self::TYPE, 1, Alphanumeric::FILL, Alphanumeric::ALIGN); |
|
214
|
|
|
|
|
215
|
|
|
// Consumer Unity from client |
|
216
|
1 |
|
$result .= str_pad($this->consumerUnity->getNumber(), 13, Numeric::FILL, Numeric::ALIGN); |
|
217
|
|
|
|
|
218
|
|
|
// Value |
|
219
|
1 |
|
$result .= str_pad(preg_replace('/[^0-9]+/', '', $this->getPrice()->getPrice()), 9, Numeric::FILL, Numeric::ALIGN); |
|
220
|
|
|
|
|
221
|
|
|
// Maturity |
|
222
|
1 |
|
$result .= $this->getPrice()->getMaturity()->format(self::DATE_FORMAT); |
|
223
|
|
|
|
|
224
|
|
|
// Sent Status |
|
225
|
1 |
|
$result .= self::CODE; |
|
226
|
|
|
|
|
227
|
|
|
// accounting account code |
|
228
|
1 |
|
$result .= str_pad('11307O63', 8, Alphanumeric::FILL, Alphanumeric::ALIGN); |
|
229
|
|
|
|
|
230
|
|
|
// internal control |
|
231
|
1 |
|
$result .= str_pad($this->authorization->getNumber(), 60, Alphanumeric::FILL, Alphanumeric::ALIGN); |
|
232
|
|
|
|
|
233
|
|
|
// computed date |
|
234
|
1 |
|
$result .= str_pad(' ', 8, Alphanumeric::FILL, Alphanumeric::ALIGN); |
|
235
|
|
|
|
|
236
|
|
|
// client document |
|
237
|
1 |
|
$result .= str_pad(preg_replace('/[^0-9]+/', '', $this->purchaser->getDocument()->getNumber()), 11, Alphanumeric::FILL, Alphanumeric::ALIGN); |
|
238
|
|
|
|
|
239
|
|
|
// administrative unity |
|
240
|
1 |
|
$result .= str_pad(' ', 10, Alphanumeric::FILL, Alphanumeric::ALIGN); |
|
241
|
|
|
|
|
242
|
|
|
// CNPJ complement (?!?) |
|
243
|
1 |
|
$result .= str_pad(' ', 3, Alphanumeric::FILL, Alphanumeric::ALIGN); |
|
244
|
|
|
|
|
245
|
|
|
// spaces only |
|
246
|
1 |
|
$result .= str_pad(' ', 11, Alphanumeric::FILL, Alphanumeric::ALIGN); |
|
247
|
|
|
|
|
248
|
|
|
// sequence number from line |
|
249
|
1 |
|
$result .= str_pad($this->sequence->getValue(), 6, Numeric::FILL, Numeric::ALIGN); |
|
250
|
|
|
|
|
251
|
|
|
// resulting.... |
|
252
|
1 |
|
return $result; |
|
253
|
|
|
} |
|
254
|
|
|
|
|
255
|
|
|
/** |
|
256
|
|
|
* @return mixed |
|
257
|
|
|
*/ |
|
258
|
|
|
private function getPrice() |
|
259
|
|
|
{ |
|
260
|
|
|
$parcel = $this->parcels->offsetGet(0); |
|
261
|
|
|
|
|
262
|
|
|
return $parcel; |
|
263
|
|
|
} |
|
264
|
|
|
} |
|
265
|
|
|
|