|
1
|
|
|
<?php |
|
2
|
|
|
require_once 'Intraface/functions.php'; |
|
3
|
|
|
require_once 'Intraface/modules/procurement/Procurement.php'; |
|
4
|
|
|
require_once 'DB/Sql.php'; |
|
5
|
|
|
|
|
6
|
|
|
class ProcurementTest extends PHPUnit_Framework_TestCase |
|
7
|
|
|
{ |
|
8
|
|
|
private $kernel; |
|
|
|
|
|
|
9
|
|
|
|
|
10
|
|
View Code Duplication |
function setUp() |
|
|
|
|
|
|
11
|
|
|
{ |
|
12
|
|
|
$db = MDB2::singleton(DB_DSN); |
|
13
|
|
|
$db->exec('TRUNCATE procurement'); |
|
14
|
|
|
$db->exec('TRUNCATE procurement_item'); |
|
15
|
|
|
$db->exec('TRUNCATE accounting_account'); |
|
16
|
|
|
$db->exec('TRUNCATE accounting_post'); |
|
17
|
|
|
$db->exec('TRUNCATE accounting_year'); |
|
18
|
|
|
$db->exec('TRUNCATE accounting_voucher'); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
function createKernel() |
|
22
|
|
|
{ |
|
23
|
|
|
$kernel = new Stub_Kernel; |
|
24
|
|
|
$kernel->setting->set('user', 'accounting.active_year', '1'); |
|
25
|
|
|
$kernel->setting->set('intranet', 'vatpercent', 25); |
|
26
|
|
|
$kernel->setting->set('intranet', 'accounting.vat_out_account_id', 46); |
|
27
|
|
|
$kernel->setting->set('intranet', 'accounting.vat_in_account_id', 44); |
|
28
|
|
|
|
|
29
|
|
|
return $kernel; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
View Code Duplication |
function createAccountingYear() |
|
|
|
|
|
|
33
|
|
|
{ |
|
34
|
|
|
require_once 'Intraface/modules/accounting/Year.php'; |
|
35
|
|
|
$year = new Year($this->createKernel()); |
|
36
|
|
|
$year->save(array('from_date' => date('Y').'-01-01', 'to_date' => date('Y').'-12-31', 'label' => 'test', 'locked' => 0, 'vat' => 1)); |
|
37
|
|
|
$year->createAccounts('standard'); |
|
38
|
|
|
return $year; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
function testConstruct() |
|
42
|
|
|
{ |
|
43
|
|
|
$procurement = new Procurement($this->createKernel()); |
|
44
|
|
|
$this->assertEquals('Procurement', get_class($procurement)); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
function testUpdateWithEmptyArray() |
|
48
|
|
|
{ |
|
49
|
|
|
$procurement = new Procurement($this->createKernel()); |
|
50
|
|
|
|
|
51
|
|
|
$this->assertFalse($procurement->update(array())); |
|
52
|
|
|
$this->assertEquals(3, $procurement->error->count(), $procurement->error->view()); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
function testUpdateWithValidInput() |
|
56
|
|
|
{ |
|
57
|
|
|
$procurement = new Procurement($this->createKernel()); |
|
58
|
|
|
$this->assertTrue($procurement->update(array('dk_invoice_date' => '01-01-2007', 'delivery_date' => '02-01-2007', 'dk_payment_date' => '03-01-2007', 'number' => 1, 'description' => 'test', 'dk_price_items' => '100,00', 'dk_price_shipment_etc' => '40,00', 'dk_vat' => '25,00'))); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
function testLoad() |
|
62
|
|
|
{ |
|
63
|
|
|
$kernel = $this->createKernel(); |
|
64
|
|
|
$procurement = new Procurement($kernel); |
|
65
|
|
|
$procurement->update(array('dk_invoice_date' => '01-01-2007', 'delivery_date' => '02-01-2007', 'dk_payment_date' => '03-01-2007', 'number' => 1, 'description' => 'test', 'dk_price_items' => '100,00', 'dk_price_shipment_etc' => '40,00', 'dk_vat' => '25,00')); |
|
66
|
|
|
|
|
67
|
|
|
$procurement = new Procurement($kernel, 1); |
|
68
|
|
|
$expected = array( |
|
69
|
|
|
'id' => 1, |
|
70
|
|
|
'invoice_date' => '2007-01-01', |
|
71
|
|
|
'dk_invoice_date' => '01-01-2007', |
|
72
|
|
|
'delivery_date' => '2007-01-01', |
|
73
|
|
|
'dk_delivery_date' => '01-01-2007', |
|
74
|
|
|
'payment_date' => '2007-01-03', |
|
75
|
|
|
'dk_payment_date' => '03-01-2007', |
|
76
|
|
|
'date_recieved' => '0000-00-00 00:00:00', |
|
77
|
|
|
'dk_date_recieved' => '00-00-0000', |
|
78
|
|
|
'date_canceled' => '0000-00-00 00:00:00', |
|
79
|
|
|
'dk_date_canceled' => '00-00-0000', |
|
80
|
|
|
'date_stated' => '00-00-0000', |
|
81
|
|
|
'dk_date_stated' => '00-00-0000', |
|
82
|
|
|
'paid_date' => '0000-00-00', |
|
83
|
|
|
'this_date' => '0000-00-00', |
|
84
|
|
|
'dk_paid_date' => '00-00-0000', |
|
85
|
|
|
'number' => 1, |
|
86
|
|
|
'contact_id' => 0, |
|
87
|
|
|
'vendor' => '', |
|
88
|
|
|
'description' => 'test', |
|
89
|
|
|
'from_region_key' => 0, |
|
90
|
|
|
'from_region' => 'denmark', |
|
91
|
|
|
'price_items' => '100.00', |
|
92
|
|
|
'dk_price_items' => '100,00', |
|
93
|
|
|
'price_shipment_etc' => '40.00', |
|
94
|
|
|
'dk_price_shipment_etc' => '40,00', |
|
95
|
|
|
'vat' => '25.00', |
|
96
|
|
|
'dk_vat' => '25,00', |
|
97
|
|
|
'total_price' => 165, |
|
98
|
|
|
'dk_total_price' => '165,00', |
|
99
|
|
|
'status_key' => 0, |
|
100
|
|
|
'status' => 'ordered', |
|
101
|
|
|
'state_account_id' => 0, |
|
102
|
|
|
'voucher_id' => 0 |
|
103
|
|
|
); |
|
104
|
|
|
|
|
105
|
|
|
$this->assertEquals($expected, $procurement->get()); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
function testReadyForStateBeforeSaved() |
|
109
|
|
|
{ |
|
110
|
|
|
$procurement = new Procurement($this->createKernel()); |
|
111
|
|
|
$this->assertFalse($procurement->readyForState($this->createAccountingYear())); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
function testReadyForStateWhenReady() |
|
115
|
|
|
{ |
|
116
|
|
|
$procurement = new Procurement($this->createKernel()); |
|
117
|
|
|
$procurement->update(array('dk_invoice_date' => '01-01-'.date('Y'), 'delivery_date' => '02-01-'.date('Y'), 'dk_payment_date' => '03-01-'.date('Y'), 'number' => 1, 'description' => 'test', 'dk_price_items' => '100,00', 'dk_price_shipment_etc' => '40,00', 'dk_vat' => '25,00')); |
|
118
|
|
|
$procurement->setPaid('04-01-'.date('Y')); |
|
119
|
|
|
$this->assertTrue($procurement->readyForState($this->createAccountingYear())); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
function testIsStateBeforeStated() |
|
123
|
|
|
{ |
|
124
|
|
|
$procurement = new Procurement($this->createKernel()); |
|
125
|
|
|
$this->assertFalse($procurement->isStated()); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
function testState() |
|
129
|
|
|
{ |
|
130
|
|
|
$procurement = new Procurement($this->createKernel()); |
|
131
|
|
|
$procurement->update(array('dk_invoice_date' => '01-01-'.date('Y'), 'delivery_date' => '02-01-'.date('Y'), 'dk_payment_date' => '03-01-'.date('Y'), 'number' => 1, 'description' => 'test', 'dk_price_items' => '100,00', 'dk_price_shipment_etc' => '40,00', 'dk_vat' => '25,00')); |
|
132
|
|
|
$year = $this->createAccountingYear(); |
|
133
|
|
|
$procurement->setPaid('04-01-'.date('Y')); |
|
134
|
|
|
|
|
135
|
|
|
$state = array( |
|
136
|
|
|
0 => array('text' => '', 'amount' => '100,00', 'state_account_id' => 7000), |
|
137
|
|
|
1 => array('text' => 'shipment_etc', 'amount' => '40,00', 'state_account_id' => 7200) |
|
138
|
|
|
|
|
139
|
|
|
); |
|
140
|
|
|
|
|
141
|
|
|
$this->assertTrue($procurement->state($year, 1, '05-01-'.date('Y'), $state, 58000, new Stub_Translation), $procurement->error->view()); |
|
142
|
|
|
|
|
143
|
|
|
$voucher = Voucher::factory($year, 1); |
|
|
|
|
|
|
144
|
|
|
$expected = array( |
|
145
|
|
|
0 => array( |
|
146
|
|
|
'id' => 1, |
|
147
|
|
|
'date_dk' => '05-01-' . date('Y'), |
|
148
|
|
|
'date' => date('Y') . '-01-05', |
|
149
|
|
|
'text' => 'procurement# 1: test - købsmoms', |
|
150
|
|
|
'debet' => '25.00', |
|
151
|
|
|
'credit' => '0.00', |
|
152
|
|
|
'voucher_number' => 1, |
|
153
|
|
|
'reference' => '', |
|
154
|
|
|
'voucher_id' => 1, |
|
155
|
|
|
'account_id' => 44, |
|
156
|
|
|
'stated' => 1, |
|
157
|
|
|
'account_number' => '66100', |
|
158
|
|
|
'account_name' => 'Moms, indgående, køb' |
|
159
|
|
|
), |
|
160
|
|
|
1 => array( |
|
161
|
|
|
'id' => 2, |
|
162
|
|
|
'date_dk' => '05-01-' . date('Y'), |
|
163
|
|
|
'date' => date('Y') . '-01-05', |
|
164
|
|
|
'text' => 'procurement# 1: test', |
|
165
|
|
|
'debet' => '100.00', |
|
166
|
|
|
'credit' => '0.00', |
|
167
|
|
|
'voucher_number' => 1, |
|
168
|
|
|
'reference' => '', |
|
169
|
|
|
'voucher_id' => 1, |
|
170
|
|
|
'account_id' => 10, |
|
171
|
|
|
'stated' => 1, |
|
172
|
|
|
'account_number' => '7000', |
|
173
|
|
|
'account_name' => 'Kontorartikler' |
|
174
|
|
|
), |
|
175
|
|
|
2 => array( |
|
176
|
|
|
'id' => 3, |
|
177
|
|
|
'date_dk' => '05-01-' . date('Y'), |
|
178
|
|
|
'date' => date('Y') . '-01-05', |
|
179
|
|
|
'text' => 'procurement# 1: test', |
|
180
|
|
|
'debet' => '0.00', |
|
181
|
|
|
'credit' => '125.00', |
|
182
|
|
|
'voucher_number' => 1, |
|
183
|
|
|
'reference' => '', |
|
184
|
|
|
'voucher_id' => 1, |
|
185
|
|
|
'account_id' => 33, |
|
186
|
|
|
'stated' => 1, |
|
187
|
|
|
'account_number' => '58000', |
|
188
|
|
|
'account_name' => 'Bank, folio' |
|
189
|
|
|
), |
|
190
|
|
|
3 => array( |
|
191
|
|
|
'id' => 4, |
|
192
|
|
|
'date_dk' => '05-01-' . date('Y'), |
|
193
|
|
|
'date' => date('Y') . '-01-05', |
|
194
|
|
|
'text' => 'procurement# 1: test - shipment_etc', |
|
195
|
|
|
'debet' => '40.00', |
|
196
|
|
|
'credit' => '0.00', |
|
197
|
|
|
'voucher_number' => 1, |
|
198
|
|
|
'reference' => '', |
|
199
|
|
|
'voucher_id' => 1, |
|
200
|
|
|
'account_id' => 11, |
|
201
|
|
|
'stated' => 1, |
|
202
|
|
|
'account_number' => '7200', |
|
203
|
|
|
'account_name' => 'Porto' |
|
204
|
|
|
), |
|
205
|
|
|
4 => array( |
|
206
|
|
|
'id' => 5, |
|
207
|
|
|
'date_dk' => '05-01-' . date('Y'), |
|
208
|
|
|
'date' => date('Y') . '-01-05', |
|
209
|
|
|
'text' => 'procurement# 1: test - shipment_etc', |
|
210
|
|
|
'debet' => '0.00', |
|
211
|
|
|
'credit' => '40.00', |
|
212
|
|
|
'voucher_number' => 1, |
|
213
|
|
|
'reference' => '', |
|
214
|
|
|
'voucher_id' => 1, |
|
215
|
|
|
'account_id' => 33, |
|
216
|
|
|
'stated' => 1, |
|
217
|
|
|
'account_number' => '58000', |
|
218
|
|
|
'account_name' => 'Bank, folio' |
|
219
|
|
|
) |
|
220
|
|
|
); |
|
221
|
|
|
|
|
222
|
|
|
$this->assertEquals($expected, $voucher->getPosts()); |
|
223
|
|
|
|
|
224
|
|
|
$this->assertTrue($procurement->isStated()); |
|
225
|
|
|
$this->assertFalse($procurement->readyForState($year)); |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
function testStateWithNoShipment() |
|
229
|
|
|
{ |
|
230
|
|
|
$procurement = new Procurement($this->createKernel()); |
|
231
|
|
|
$procurement->update(array('dk_invoice_date' => '01-01-'.date('Y'), 'delivery_date' => '02-01-'.date('Y'), 'dk_payment_date' => '03-01-'.date('Y'), 'number' => 1, 'description' => 'test', 'dk_price_items' => '135,96', 'dk_price_shipment_etc' => '0', 'dk_vat' => '33,99')); |
|
232
|
|
|
$year = $this->createAccountingYear(); |
|
233
|
|
|
$procurement->setPaid('04-01-'.date('Y')); |
|
234
|
|
|
|
|
235
|
|
|
$state = array( |
|
236
|
|
|
0 => array('text' => '', 'amount' => '135,96', 'state_account_id' => 7000), |
|
237
|
|
|
|
|
238
|
|
|
); |
|
239
|
|
|
|
|
240
|
|
|
|
|
241
|
|
|
$this->assertTrue($procurement->state($year, 1, '05-01-'.date('Y'), $state, 58000, new Stub_Translation), $procurement->error->view()); |
|
242
|
|
|
} |
|
243
|
|
|
} |
|
244
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.