1
|
|
|
<?php |
2
|
|
|
namespace MrPrompt\Celesc\Shipment\Partial; |
3
|
|
|
|
4
|
|
|
use DateTime; |
5
|
|
|
use MrPrompt\ShipmentCommon\Base\Dealership; |
6
|
|
|
use MrPrompt\ShipmentCommon\Base\Customer; |
7
|
|
|
use MrPrompt\ShipmentCommon\Base\Sequence; |
8
|
|
|
use MrPrompt\ShipmentCommon\Type\Numeric; |
9
|
|
|
use MrPrompt\ShipmentCommon\Type\Alphanumeric; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* File header |
13
|
|
|
* |
14
|
|
|
* @author Thiago Paes <[email protected]> |
15
|
|
|
*/ |
16
|
|
|
class Header |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* Type of register |
20
|
|
|
* |
21
|
|
|
* @const string |
22
|
|
|
*/ |
23
|
|
|
const TYPE = '1'; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Sequencial line |
27
|
|
|
* |
28
|
|
|
* @const int |
29
|
|
|
*/ |
30
|
|
|
const LINE = 1; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Sent code |
34
|
|
|
* |
35
|
|
|
* @const int |
36
|
|
|
*/ |
37
|
|
|
const CODE = 1; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Currency |
41
|
|
|
* |
42
|
|
|
* @const string |
43
|
|
|
*/ |
44
|
|
|
const CURRENCY = 'R$'; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Customer Code |
48
|
|
|
* |
49
|
|
|
* @var Customer |
50
|
|
|
*/ |
51
|
|
|
private $customer; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Dealership |
55
|
|
|
* |
56
|
|
|
* @var Dealership |
57
|
|
|
*/ |
58
|
|
|
private $dealership; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* File date creation |
62
|
|
|
* |
63
|
|
|
* @var DateTime |
64
|
|
|
*/ |
65
|
|
|
private $created; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Sequencial number of file |
69
|
|
|
* |
70
|
|
|
* @var Sequence |
71
|
|
|
*/ |
72
|
|
|
private $sequence; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Constructor |
76
|
|
|
* |
77
|
|
|
* @param Customer $customer |
78
|
|
|
* @param Dealership $dealership |
79
|
|
|
* @param Sequence $sequence |
80
|
|
|
* @param DateTime $created |
81
|
|
|
*/ |
82
|
7 |
|
public function __construct(Customer $customer, Dealership $dealership, Sequence $sequence, DateTime $created) |
83
|
|
|
{ |
84
|
7 |
|
$this->customer = $customer; |
85
|
7 |
|
$this->dealership = $dealership; |
86
|
7 |
|
$this->sequence = $sequence; |
87
|
7 |
|
$this->created = $created; |
88
|
7 |
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return Customer |
92
|
|
|
*/ |
93
|
1 |
|
public function getCustomer() |
94
|
|
|
{ |
95
|
1 |
|
return $this->customer; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @param Customer $customer |
100
|
|
|
*/ |
101
|
1 |
|
public function setCustomer(Customer $customer) |
102
|
|
|
{ |
103
|
1 |
|
$this->customer = $customer; |
104
|
1 |
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @return Dealership |
108
|
|
|
*/ |
109
|
|
|
public function getDealership() |
110
|
|
|
{ |
111
|
|
|
return $this->dealership; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @param Dealership $dealership |
116
|
|
|
*/ |
117
|
|
|
public function setDealership(Dealership $dealership) |
118
|
|
|
{ |
119
|
|
|
$this->dealership = $dealership; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @return DateTime |
124
|
|
|
*/ |
125
|
1 |
|
public function getCreated() |
126
|
|
|
{ |
127
|
1 |
|
return $this->created; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @param DateTime $created |
132
|
|
|
*/ |
133
|
1 |
|
public function setCreated(DateTime $created) |
134
|
|
|
{ |
135
|
1 |
|
$this->created = $created; |
136
|
1 |
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @return Sequence |
140
|
|
|
*/ |
141
|
1 |
|
public function getSequence() |
142
|
|
|
{ |
143
|
1 |
|
return $this->sequence; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @param Sequence $sequence |
148
|
|
|
*/ |
149
|
1 |
|
public function setSequence(Sequence $sequence) |
150
|
|
|
{ |
151
|
1 |
|
$this->sequence = $sequence; |
152
|
1 |
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Render header line |
156
|
|
|
* |
157
|
|
|
* @return string |
158
|
|
|
*/ |
159
|
1 |
|
public function render() |
160
|
|
|
{ |
161
|
|
|
// register type |
162
|
1 |
|
$line = self::TYPE; |
163
|
|
|
|
164
|
|
|
// customer code |
165
|
1 |
|
$line .= str_pad($this->customer->getCode(), 56, Alphanumeric::FILL, Alphanumeric::ALIGN); |
166
|
|
|
|
167
|
|
|
// dealership code |
168
|
1 |
|
$line .= str_pad($this->dealership->getCode(), 4, Alphanumeric::FILL, Alphanumeric::ALIGN); |
169
|
|
|
|
170
|
|
|
// date from file |
171
|
1 |
|
$line .= $this->created->format('dmY'); |
172
|
|
|
|
173
|
|
|
// Currency |
174
|
1 |
|
$line .= str_pad(self::CURRENCY, 6, Alphanumeric::FILL, Alphanumeric::ALIGN); |
175
|
|
|
|
176
|
|
|
// sequence file |
177
|
1 |
|
$line .= str_pad($this->sequence->getValue(), 6, Numeric::FILL, Numeric::ALIGN); |
178
|
|
|
|
179
|
|
|
// Result code |
180
|
1 |
|
$line .= str_pad(' ', 2, Alphanumeric::FILL, Alphanumeric::ALIGN); |
181
|
|
|
|
182
|
|
|
// Company name |
183
|
1 |
|
$line .= str_pad($this->customer->getName(), 20, Alphanumeric::FILL, Alphanumeric::ALIGN); |
184
|
|
|
|
185
|
|
|
// Spaces only |
186
|
1 |
|
$line .= str_pad(' ', 40, Alphanumeric::FILL, Alphanumeric::ALIGN); |
187
|
|
|
|
188
|
|
|
// sent code |
189
|
1 |
|
$line .= self::CODE; |
190
|
|
|
|
191
|
|
|
// sequence line |
192
|
1 |
|
$line .= str_pad(self::LINE, 6, Numeric::FILL, Numeric::ALIGN); |
193
|
|
|
|
194
|
|
|
// resulting... |
195
|
1 |
|
return $line; |
196
|
|
|
} |
197
|
|
|
} |
198
|
|
|
|