|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* SaaS Link plugin for Craft CMS 3.x |
|
4
|
|
|
* |
|
5
|
|
|
* @link https://workingconcept.com |
|
6
|
|
|
* @copyright Copyright (c) 2018 Working Concept Inc. |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace workingconcept\saaslink\models\harvest; |
|
10
|
|
|
|
|
11
|
|
|
use craft\base\Model; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Harvest Invoice Model |
|
15
|
|
|
* https://help.getharvest.com/api-v2/invoices-api/invoices/invoices/ |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
class HarvestInvoice extends Model |
|
19
|
|
|
{ |
|
20
|
|
|
// Properties |
|
21
|
|
|
// ========================================================================= |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var int Unique ID for the expense. |
|
25
|
|
|
*/ |
|
26
|
|
|
public $id; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var object An object containing invoice’s client id and name. |
|
30
|
|
|
*/ |
|
31
|
|
|
private $_client; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var array Array of invoice line items. |
|
35
|
|
|
*/ |
|
36
|
|
|
public $line_items; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @var object An object containing the associated estimate’s id. |
|
40
|
|
|
*/ |
|
41
|
|
|
private $_estimate; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @var object An object containing the associated retainer’s id. |
|
45
|
|
|
*/ |
|
46
|
|
|
private $_retainer; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @var object An object containing the id and name of the person that created the invoice. |
|
50
|
|
|
*/ |
|
51
|
|
|
private $_creator; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @var string Used to build a URL to the public web invoice for your client: |
|
55
|
|
|
* `https://{ACCOUNT_SUBDOMAIN}.harvestapp.com/client/invoices/abc123456` |
|
56
|
|
|
*/ |
|
57
|
|
|
public $client_key; |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @var string If no value is set, the number will be automatically generated. |
|
61
|
|
|
*/ |
|
62
|
|
|
public $number; |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @var string The purchase order number. |
|
66
|
|
|
*/ |
|
67
|
|
|
public $purchase_order; |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @var float The total amount for the invoice, including any discounts and taxes. |
|
71
|
|
|
*/ |
|
72
|
|
|
public $amount; |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @var float The total amount due at this time for this invoice. |
|
76
|
|
|
*/ |
|
77
|
|
|
public $due_amount; |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @var float This percentage is applied to the subtotal, including line items and discounts. |
|
81
|
|
|
*/ |
|
82
|
|
|
public $tax; |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @var float The first amount of tax included, calculated from tax. If no tax is defined, this value will be null. |
|
86
|
|
|
*/ |
|
87
|
|
|
public $tax_amount; |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @var float This percentage is applied to the subtotal, including line items and discounts. |
|
91
|
|
|
*/ |
|
92
|
|
|
public $tax2; |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @var float The amount calculated from tax2. |
|
96
|
|
|
*/ |
|
97
|
|
|
public $tax2_amount; |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @var float This percentage is subtracted from the subtotal. |
|
101
|
|
|
*/ |
|
102
|
|
|
public $discount; |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @var float The amount calcuated from discount. |
|
106
|
|
|
*/ |
|
107
|
|
|
public $discount_amount; |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* @var string The invoice subject. |
|
111
|
|
|
*/ |
|
112
|
|
|
public $subject; |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @var string Any additional notes included on the invoice. |
|
116
|
|
|
*/ |
|
117
|
|
|
public $notes; |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* @var string The currency code associated with this invoice. |
|
121
|
|
|
*/ |
|
122
|
|
|
public $currency; |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* @var string The current state of the invoice: draft, open, paid, or closed. |
|
126
|
|
|
*/ |
|
127
|
|
|
public $state; |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* @var string Start of the period during which time entries were added to this invoice. |
|
131
|
|
|
*/ |
|
132
|
|
|
public $period_start; |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* @var string End of the period during which time entries were added to this invoice. |
|
136
|
|
|
*/ |
|
137
|
|
|
public $period_end; |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* @var string Date the invoice was issued. |
|
141
|
|
|
*/ |
|
142
|
|
|
public $issue_date; |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* @var string Date the invoice is due. |
|
146
|
|
|
*/ |
|
147
|
|
|
public $due_date; |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* @var string The timeframe in which the invoice should be paid. Options: upon receipt, net 15, net 30, net 45, net 60, or custom. |
|
151
|
|
|
*/ |
|
152
|
|
|
public $payment_term; |
|
153
|
|
|
|
|
154
|
|
|
/** |
|
155
|
|
|
* @var string Date and time the invoice was sent. |
|
156
|
|
|
*/ |
|
157
|
|
|
public $sent_at; |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* @var string Date and time the invoice was paid. |
|
161
|
|
|
*/ |
|
162
|
|
|
public $paid_at; |
|
163
|
|
|
|
|
164
|
|
|
/** |
|
165
|
|
|
* @var string Date the invoice was paid. |
|
166
|
|
|
*/ |
|
167
|
|
|
public $paid_date; |
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* @var string Date and time the invoice was closed. |
|
171
|
|
|
*/ |
|
172
|
|
|
public $closed_at; |
|
173
|
|
|
|
|
174
|
|
|
/** |
|
175
|
|
|
* @var string Date and time the invoice was created. |
|
176
|
|
|
*/ |
|
177
|
|
|
public $created_at; |
|
178
|
|
|
|
|
179
|
|
|
/** |
|
180
|
|
|
* @var string Date and time the invoice was last updated. |
|
181
|
|
|
*/ |
|
182
|
|
|
public $updated_at; |
|
183
|
|
|
|
|
184
|
|
|
|
|
185
|
|
|
// Public Methods |
|
186
|
|
|
// ========================================================================= |
|
187
|
|
|
|
|
188
|
|
|
public function getClient() |
|
189
|
|
|
{ |
|
190
|
|
|
return $this->_client; |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
public function setClient($client) |
|
194
|
|
|
{ |
|
195
|
|
|
return $this->_client = $client; |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
public function getEstimate() |
|
199
|
|
|
{ |
|
200
|
|
|
return $this->_estimate; |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
public function setEstimate($estimate) |
|
204
|
|
|
{ |
|
205
|
|
|
return $this->_estimate = $estimate; |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
public function getRetainer() |
|
209
|
|
|
{ |
|
210
|
|
|
return $this->_retainer; |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
public function setRetainer($retainer) |
|
214
|
|
|
{ |
|
215
|
|
|
return $this->_retainer = $retainer; |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
public function getCreator() |
|
219
|
|
|
{ |
|
220
|
|
|
return $this->_creator; |
|
221
|
|
|
} |
|
222
|
|
|
|
|
223
|
|
|
public function setCreator($creator) |
|
224
|
|
|
{ |
|
225
|
|
|
return $this->_creator = $creator; |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
public function rules() |
|
229
|
|
|
{ |
|
230
|
|
|
return [ |
|
231
|
|
|
[[ |
|
232
|
|
|
'id', |
|
233
|
|
|
], 'number', 'integerOnly' => true], |
|
234
|
|
|
[['id'], 'required'], |
|
235
|
|
|
[[ |
|
236
|
|
|
'amount', |
|
237
|
|
|
'due_amount', |
|
238
|
|
|
'tax', |
|
239
|
|
|
'tax_amount', |
|
240
|
|
|
'tax2', |
|
241
|
|
|
'tax2_amount', |
|
242
|
|
|
'discount', |
|
243
|
|
|
'discount_amount', |
|
244
|
|
|
], 'number', 'integerOnly' => false], |
|
245
|
|
|
[[ |
|
246
|
|
|
'client_key', |
|
247
|
|
|
'number', |
|
248
|
|
|
'purchase_order', |
|
249
|
|
|
'subject', |
|
250
|
|
|
'notes', |
|
251
|
|
|
'currency', |
|
252
|
|
|
'state', |
|
253
|
|
|
'period_start', |
|
254
|
|
|
'period_end', |
|
255
|
|
|
'issue_date', |
|
256
|
|
|
'due_date', |
|
257
|
|
|
'payment_term', |
|
258
|
|
|
'sent_at', |
|
259
|
|
|
'paid_at', |
|
260
|
|
|
'paid_date', |
|
261
|
|
|
'closed_at', |
|
262
|
|
|
'created_at', |
|
263
|
|
|
'updated_at', |
|
264
|
|
|
], 'string'], |
|
265
|
|
|
]; |
|
266
|
|
|
} |
|
267
|
|
|
|
|
268
|
|
|
} |
|
269
|
|
|
|