1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Billogram\Model\Setting; |
6
|
|
|
|
7
|
|
|
use Billogram\Model\CreatableFromArray; |
8
|
|
|
use Billogram\Model\Invoice\AutomaticReminder; |
9
|
|
|
use Billogram\Model\Invoice\ReminderCollection; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @author Ibrahim Hizeoui <[email protected]> |
13
|
|
|
*/ |
14
|
|
|
class InvoiceDefaults implements CreatableFromArray |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
private $defaultMessage; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var int |
23
|
|
|
*/ |
24
|
|
|
private $defaultInterestRate; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var int |
28
|
|
|
*/ |
29
|
|
|
private $defaultReminderFee; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var int |
33
|
|
|
*/ |
34
|
|
|
private $defaultInvoiceFee; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var AutomaticReminder |
38
|
|
|
*/ |
39
|
|
|
private $automaticReminders; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var AutomaticWriteOff |
43
|
|
|
*/ |
44
|
|
|
private $automaticWriteoff; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var ReminderCollection |
48
|
|
|
*/ |
49
|
|
|
private $reminderCollection; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return string |
53
|
|
|
*/ |
54
|
|
|
public function getDefaultMessage() |
55
|
|
|
{ |
56
|
|
|
return $this->defaultMessage; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param string $defaultMessage |
61
|
|
|
* |
62
|
|
|
* @return InvoiceDefaults |
63
|
|
|
*/ |
64
|
|
|
public function withDefaultMessage(string $defaultMessage) |
65
|
|
|
{ |
66
|
|
|
$new = clone $this; |
67
|
|
|
$new->defaultMessage = $defaultMessage; |
68
|
|
|
|
69
|
|
|
return $new; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return int |
74
|
|
|
*/ |
75
|
|
|
public function getDefaultInterestRate() |
76
|
|
|
{ |
77
|
|
|
return $this->defaultInterestRate; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @param int $defaultInterestRate |
82
|
|
|
* |
83
|
|
|
* @return InvoiceDefaults |
84
|
|
|
*/ |
85
|
|
|
public function withDefaultInterestRate(int $defaultInterestRate) |
86
|
|
|
{ |
87
|
|
|
$new = clone $this; |
88
|
|
|
$new->defaultInterestRate = $defaultInterestRate; |
89
|
|
|
|
90
|
|
|
return $new; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @return int |
95
|
|
|
*/ |
96
|
|
|
public function getDefaultReminderFee() |
97
|
|
|
{ |
98
|
|
|
return $this->defaultReminderFee; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @param int $defaultReminderFee |
103
|
|
|
* |
104
|
|
|
* @return InvoiceDefaults |
105
|
|
|
*/ |
106
|
|
|
public function withDefaultReminderFee(int $defaultReminderFee) |
107
|
|
|
{ |
108
|
|
|
$new = clone $this; |
109
|
|
|
$new->defaultReminderFee = $defaultReminderFee; |
110
|
|
|
|
111
|
|
|
return $new; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @return int |
116
|
|
|
*/ |
117
|
|
|
public function getDefaultInvoiceFee() |
118
|
|
|
{ |
119
|
|
|
return $this->defaultInvoiceFee; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @param int $defaultInvoiceFee |
124
|
|
|
* |
125
|
|
|
* @return InvoiceDefaults |
126
|
|
|
*/ |
127
|
|
|
public function withDefaultInvoiceFee(int $defaultInvoiceFee) |
128
|
|
|
{ |
129
|
|
|
$new = clone $this; |
130
|
|
|
$new->defaultInvoiceFee = $defaultInvoiceFee; |
131
|
|
|
|
132
|
|
|
return $new; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @return AutomaticReminder |
137
|
|
|
*/ |
138
|
|
|
public function getAutomaticReminders() |
139
|
|
|
{ |
140
|
|
|
return $this->automaticReminders; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @param AutomaticReminder $automaticReminders |
145
|
|
|
* |
146
|
|
|
* @return InvoiceDefaults |
147
|
|
|
*/ |
148
|
|
|
public function withAutomaticReminders(AutomaticReminder $automaticReminders) |
149
|
|
|
{ |
150
|
|
|
$new = clone $this; |
151
|
|
|
$new->automaticReminders = $automaticReminders; |
152
|
|
|
|
153
|
|
|
return $new; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* @return AutomaticWriteOff |
158
|
|
|
*/ |
159
|
|
|
public function getAutomaticReminderWriteOff() |
160
|
|
|
{ |
161
|
|
|
return $this->automaticWriteoff; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* @param AutomaticWriteOff $automaticWriteoff |
166
|
|
|
* |
167
|
|
|
* @return InvoiceDefaults |
168
|
|
|
*/ |
169
|
|
|
public function withAutomaticWriteoff(AutomaticWriteOff $automaticWriteoff) |
170
|
|
|
{ |
171
|
|
|
$new = clone $this; |
172
|
|
|
$new->automaticWriteoff = $automaticWriteoff; |
173
|
|
|
|
174
|
|
|
return $new; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @return ReminderCollection |
179
|
|
|
*/ |
180
|
|
|
public function getAutomaticReminderCollection() |
181
|
|
|
{ |
182
|
|
|
return $this->reminderCollection; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* @param ReminderCollection $automaticCollection |
187
|
|
|
* |
188
|
|
|
* @return InvoiceDefaults |
189
|
|
|
*/ |
190
|
|
|
public function withAutomaticCollection(ReminderCollection $automaticCollection) |
191
|
|
|
{ |
192
|
|
|
$new = clone $this; |
193
|
|
|
$new->reminderCollection = $automaticCollection; |
194
|
|
|
|
195
|
|
|
return $new; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* Create an API response object from the HTTP response from the API server. |
200
|
|
|
* |
201
|
|
|
* @param array $data |
202
|
|
|
* |
203
|
|
|
* @return self |
204
|
|
|
*/ |
205
|
2 |
|
public static function createFromArray(array $data) |
206
|
|
|
{ |
207
|
2 |
|
$invoiceDefault = new self(); |
208
|
2 |
|
$invoiceDefault->defaultMessage = $data['default_message'] ?? null; |
209
|
2 |
|
$invoiceDefault->defaultInterestRate = $data['default_interest_rate'] ?? null; |
210
|
2 |
|
$invoiceDefault->defaultReminderFee = $data['default_reminder_fee'] ?? null; |
211
|
2 |
|
$invoiceDefault->defaultInvoiceFee = $data['default_invoice_fee'] ?? null; |
212
|
2 |
|
$invoiceDefault->automaticReminders = AutomaticReminder::createFromArray($data['automatic_reminders']); |
213
|
2 |
|
$invoiceDefault->automaticWriteoff = AutomaticWriteOff::createFromArray($data['automatic_writeoff']); |
214
|
2 |
|
$invoiceDefault->reminderCollection = ReminderCollection::createFromArray($data['automatic_collection']); |
215
|
|
|
|
216
|
2 |
|
return $invoiceDefault; |
217
|
|
|
} |
218
|
|
|
|
219
|
1 |
|
public function toArray() |
220
|
|
|
{ |
221
|
1 |
|
$data = []; |
222
|
1 |
|
if (null !== $this->defaultMessage) { |
223
|
1 |
|
$data['default_message'] = $this->defaultMessage; |
224
|
|
|
} |
225
|
1 |
|
if (null !== $this->defaultInterestRate) { |
226
|
|
|
$data['default_interest_rate'] = $this->defaultInterestRate; |
227
|
|
|
} |
228
|
1 |
|
if (null !== $this->defaultReminderFee) { |
229
|
1 |
|
$data['default_reminder_fee'] = $this->defaultReminderFee; |
230
|
|
|
} |
231
|
1 |
|
if (null !== $this->defaultInvoiceFee) { |
232
|
1 |
|
$data['default_invoice_fee'] = $this->defaultInvoiceFee; |
233
|
|
|
} |
234
|
1 |
|
if (null !== $this->automaticReminders) { |
235
|
1 |
|
$data['automatic_reminders'] = $this->automaticReminders->toArray(); |
236
|
|
|
} |
237
|
1 |
|
if (null !== $this->automaticWriteoff) { |
238
|
1 |
|
$data['automatic_reminders'] = $this->automaticWriteoff->toArray(); |
239
|
|
|
} |
240
|
1 |
|
if (null !== $this->reminderCollection) { |
241
|
1 |
|
$data['automatic_reminders'] = $this->reminderCollection->toArray(); |
242
|
|
|
} |
243
|
|
|
|
244
|
1 |
|
return $data; |
245
|
|
|
} |
246
|
|
|
} |
247
|
|
|
|