1
|
|
|
<?php |
2
|
|
|
require_once 'Intraface/modules/accounting/VatPeriod.php'; |
3
|
|
|
require_once 'Intraface/modules/accounting/Account.php'; |
4
|
|
|
require_once 'Intraface/modules/accounting/Voucher.php'; |
5
|
|
|
require_once 'Intraface/Kernel.php'; |
6
|
|
|
|
7
|
|
|
class FakeVatPeriodYear |
8
|
|
|
{ |
9
|
|
|
public $kernel; |
10
|
|
|
function __construct() |
11
|
|
|
{ |
12
|
|
|
$this->kernel = new Stub_Kernel; |
13
|
|
|
$this->kernel->setting->set('intranet', 'vatpercent', 25); |
14
|
|
|
} |
15
|
|
|
function get() |
16
|
|
|
{ |
17
|
|
|
return 1; |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
function getSetting($key = '') |
21
|
|
|
{ |
22
|
|
|
if ($key == 'vat_period') { |
23
|
|
|
return 1; |
24
|
|
|
} |
25
|
|
|
return serialize(array()); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
function isYearOpen() |
29
|
|
|
{ |
30
|
|
|
return true; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
function isDateInYear() |
34
|
|
|
{ |
35
|
|
|
return true; |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
class FakeVatPeriodAccount extends Account |
40
|
|
|
{ |
41
|
|
|
protected $id; |
42
|
|
|
|
43
|
|
|
function __construct($year, $id = 0) |
44
|
|
|
{ |
45
|
|
|
$this->id = (int)$id; |
46
|
|
|
$this->value['number'] = 1000; |
47
|
|
|
$this->value['saldo'] = 100; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
function getSaldo($type, $date_from, $date_to) |
51
|
|
|
{ |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
function getId() |
55
|
|
|
{ |
56
|
|
|
return $this->id; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
function validForState() |
60
|
|
|
{ |
61
|
|
|
return true; |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
class FakeVatPeriodVoucher extends Voucher |
66
|
|
|
{ |
67
|
|
|
function getAccount($id) |
68
|
|
|
{ |
69
|
|
|
return new FakeVatPeriodAccount(new FakeVatPeriodYear); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
class TestableVatPeriod extends VatPeriod |
74
|
|
|
{ |
75
|
|
|
function getId() |
76
|
|
|
{ |
77
|
|
|
return 1; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
function getAccount($id) |
81
|
|
|
{ |
82
|
|
|
return new FakeVatPeriodAccount(new FakeVatPeriodYear, $id); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
function getVoucher() |
86
|
|
|
{ |
87
|
|
|
return new FakeVatPeriodVoucher(new FakeVatPeriodYear); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
function loadAmounts() |
91
|
|
|
{ |
92
|
|
|
$saldo_total = 0; // integer med total saldo |
93
|
|
|
$saldo_rubrik_a = 0; |
|
|
|
|
94
|
|
|
|
95
|
|
|
$date_from = $this->get('date_start'); |
96
|
|
|
$date_to = $this->get('date_end'); |
97
|
|
|
|
98
|
|
|
// Salgsmoms - udg�ende |
99
|
|
|
$account_vat_in = $this->getAccount(1); |
100
|
|
|
$account_vat_in->getSaldo('stated', $date_from, $date_to); |
101
|
|
|
$this->value['account_vat_out'] = $account_vat_in; |
102
|
|
|
|
103
|
|
|
// ganges med -1 for at f� rigtigt fortegn til udregning |
104
|
|
|
$this->value['saldo_vat_out'] = $account_vat_in->get('saldo'); |
105
|
|
|
$saldo_total += -1 * $this->value['saldo_vat_out']; // total |
106
|
|
|
|
107
|
|
|
|
108
|
|
|
// Moms af varek�b i udlandet |
109
|
|
|
// Dette bel�b er et udregnet bel�b, som udregnes under bogf�ringen |
110
|
|
|
$account_vat_abroad = $this->getAccount(2); |
111
|
|
|
$account_vat_abroad->getSaldo('stated', $date_from, $date_to); |
112
|
|
|
$this->value['account_vat_abroad'] = $account_vat_abroad; |
113
|
|
|
|
114
|
|
|
// ganges med -1 for at f� rigtigt fortegn til udregning |
115
|
|
|
$this->value['saldo_vat_abroad'] = $account_vat_abroad->get('saldo'); |
116
|
|
|
$saldo_total += -1 * $this->value['saldo_vat_abroad']; |
117
|
|
|
|
118
|
|
|
// K�bsmoms |
119
|
|
|
// K�bsmomsen inkluderer ogs� den udregnede moms af moms af varek�b i udlandet. |
120
|
|
|
// Dette bel�b er lagt p� kontoen under bogf�ringen. |
121
|
|
|
$account_vat_out = $this->getAccount(3); |
122
|
|
|
$account_vat_out->getSaldo('stated', $date_from, $date_to); |
123
|
|
|
$this->value['account_vat_in'] = $account_vat_out; |
124
|
|
|
|
125
|
|
|
$this->value['saldo_vat_in'] = $account_vat_out->get('saldo'); |
126
|
|
|
$saldo_total -= $this->value['saldo_vat_in']; |
127
|
|
|
|
128
|
|
|
|
129
|
|
|
// Rubrik A |
130
|
|
|
// EU-erhvervelser - her samles forskellige konti og bel�bet udregnes. |
131
|
|
|
// Primosaldoen skal ikke medregnes |
132
|
|
|
$buy_eu_accounts = unserialize($this->year->getSetting('buy_eu_accounts')); |
133
|
|
|
$this->value['saldo_rubrik_a'] = 0; |
134
|
|
|
$saldo_rubrik_a = 0; |
135
|
|
|
|
136
|
|
View Code Duplication |
if (is_array($buy_eu_accounts) and count($buy_eu_accounts) > 0) { |
|
|
|
|
137
|
|
|
foreach ($buy_eu_accounts as $key => $id) { |
138
|
|
|
$account_eu_buy = new FakeVatPeriodAccount($this->year, $id); |
139
|
|
|
$primo = $account_eu_buy->getPrimoSaldo(); |
140
|
|
|
$account_eu_buy->getSaldo('stated', $date_from, $date_to); |
141
|
|
|
$saldo_rubrik_a += $account_eu_buy->get('saldo'); |
142
|
|
|
$saldo_rubrik_a -= $primo['saldo']; |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
$this->value['saldo_rubrik_a'] = $saldo_rubrik_a; |
146
|
|
|
|
147
|
|
|
// Rubrik B |
148
|
|
|
// V�rdien af varesalg uden moms til andre EU-lande (EU-leverancer). Udfyldes |
149
|
|
|
// denne rubrik, skal der indsendes en liste med varesalgene uden moms. |
150
|
|
|
|
151
|
|
|
// Vi underst�tter ikke rubrikken |
152
|
|
|
|
153
|
|
|
// Rubrik C |
154
|
|
|
// V�rdien af varesalg uden moms til andre EU-lande (EU-leverancer). Udfyldes |
155
|
|
|
// denne rubrik, skal der indsendes en liste med varesalgene uden moms. |
156
|
|
|
|
157
|
|
|
// Vi underst�tter ikke rubrikken |
158
|
|
|
|
159
|
|
|
$this->value['saldo_total'] = $saldo_total; |
160
|
|
|
|
161
|
|
|
return true; |
162
|
|
|
} |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
class VatPeriodTest extends PHPUnit_Framework_TestCase |
166
|
|
|
{ |
167
|
|
|
protected $db; |
168
|
|
|
|
169
|
|
|
function setUp() |
170
|
|
|
{ |
171
|
|
|
$this->db = MDB2::singleton(DB_DSN); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
function tearDown() |
175
|
|
|
{ |
176
|
|
|
$this->db->exec('TRUNCATE accounting_account'); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
function createPeriod() |
180
|
|
|
{ |
181
|
|
|
return new VatPeriod(new FakeVatPeriodYear); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
function createPeriodWithFakeLoadAmounts() |
185
|
|
|
{ |
186
|
|
|
return new TestableVatPeriod(new FakeVatPeriodYear); |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
function testConstruction() |
190
|
|
|
{ |
191
|
|
|
$vat = $this->createPeriod(); |
192
|
|
|
$this->assertTrue(is_object($vat)); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
function testCreatePeriods() |
196
|
|
|
{ |
197
|
|
|
$vat = $this->createPeriod(); |
198
|
|
|
$this->assertTrue($vat->createPeriods()); |
199
|
|
|
$periods = $vat->getList(); |
200
|
|
|
$this->assertTrue(count($periods) == 4); |
201
|
|
|
$this->assertTrue($periods[0]['date_start'] == '0001-01-01' && $periods[0]['date_end'] == '0001-03-31'); |
202
|
|
|
$this->assertTrue($periods[1]['date_start'] == '0001-04-01' && $periods[1]['date_end'] == '0001-06-30'); |
203
|
|
|
$this->assertTrue($periods[2]['date_start'] == '0001-07-01' && $periods[2]['date_end'] == '0001-09-30'); |
204
|
|
|
$this->assertTrue($periods[3]['date_start'] == '0001-10-01' && $periods[3]['date_end'] == '0001-12-31'); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
function testStateReturnsTrue() |
208
|
|
|
{ |
209
|
|
|
// @todo make sure that the getSetting returns some usable accounts. |
210
|
|
|
$vat = $this->createPeriodWithFakeLoadAmounts(); |
211
|
|
|
$this->assertTrue($vat->state(date('d-m-Y'), 100)); |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
function testIsBalancedReturnsTrueWhenNoAmountsHasBeenSaved() |
215
|
|
|
{ |
216
|
|
|
$vat = $this->createPeriod(); |
217
|
|
|
$this->assertTrue($vat->isBalanced()); |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
function testDeleteReturnsTrue() |
221
|
|
|
{ |
222
|
|
|
$vat = $this->createPeriod(); |
223
|
|
|
$this->assertTrue($vat->delete()); |
224
|
|
|
} |
225
|
|
|
} |
226
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.