forked from webERP-team/webERP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnalysisHorizontalIncome.php
542 lines (497 loc) · 26.5 KB
/
AnalysisHorizontalIncome.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
<?php
/* Shows the horizontal analysis of the statement of comprehensive income. */
// BEGIN: Functions division ---------------------------------------------------
function RelativeChange($selected_period, $previous_period) {
// Calculates the relative change between selected and previous periods. Uses percent with locale number format.
if($previous_period<>0) {
return locale_number_format(($selected_period-$previous_period)*100/$previous_period, $_SESSION['CompanyRecord']['decimalplaces']) . '%';
} else {
return _('N/A');
}
}
// END: Functions division -----------------------------------------------------
// BEGIN: Procedure division ---------------------------------------------------
include ('includes/session.php');
$Title = _('Horizontal Analysis of Statement of Comprehensive Income');
$ViewTopic= 'GeneralLedger';
$BookMark = 'AnalysisHorizontalIncome';
include('includes/SQL_CommonFunctions.inc');
include('includes/AccountSectionsDef.php');// This loads the $Sections variable.
if(isset($_POST['FromPeriod']) and ($_POST['FromPeriod'] > $_POST['ToPeriod'])) {
prnMsg(_('The selected period from is actually after the period to') . '! ' . _('Please reselect the reporting period'),'error');
$_POST['SelectADifferentPeriod']='Select A Different Period';
}
if ($_POST['Period'] != '') {
$_POST['FromPeriod'] = ReportPeriod($_POST['Period'], 'From');
$_POST['ToPeriod'] = ReportPeriod($_POST['Period'], 'To');
}
include('includes/header.php');
if((!isset($_POST['FromPeriod']) AND !isset($_POST['ToPeriod'])) OR isset($_POST['SelectADifferentPeriod'])) {
echo '<p class="page_title_text"><img alt="" src="', $RootPath, '/css/', $Theme,
'/images/printer.png" title="', // Icon image.
_('Print Horizontal Analysis of Statement of Comprehensive Income'), '" /> ', // Icon title.
_('Horizontal Analysis of Statement of Comprehensive Income'), '</p>';// Page title.
echo '<div class="page_help_text">',
_('Horizontal analysis (also known as trend analysis) is a financial statement analysis technique that shows changes in the amounts of corresponding financial statement items over a period of time. It is a useful tool to evaluate trend situations.'), '<br />',
_('The statements for two periods are used in horizontal analysis. The earliest period is used as the base period. The items on the later statement are compared with items on the statement of the base period. The changes are shown both in currency (actual change) and percentage (relative change).'), '<br />',
_('webERP is an "accrual" based system (not a "cash based" system). Accrual systems include items when they are invoiced to the customer, and when expenses are owed based on the supplier invoice date.'), '</div>',
// Show a form to allow input of criteria for the report to show:
'<form method="post" action="', htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8'), '">',
'<input type="hidden" name="FormID" value="', $_SESSION['FormID'], '" />',
'<br />',
'<table class="selection">
<tr>
<td>', _('Select period from'), ':</td>
<td><select name="FromPeriod">';
if(Date('m') > $_SESSION['YearEnd']) {
/*Dates in SQL format */
$DefaultFromDate = Date ('Y-m-d', Mktime(0,0,0,$_SESSION['YearEnd'] + 2,0,Date('Y')));
$FromDate = Date($_SESSION['DefaultDateFormat'], Mktime(0,0,0,$_SESSION['YearEnd'] + 2,0,Date('Y')));
} else {
$DefaultFromDate = Date ('Y-m-d', Mktime(0,0,0,$_SESSION['YearEnd'] + 2,0,Date('Y')-1));
$FromDate = Date($_SESSION['DefaultDateFormat'], Mktime(0,0,0,$_SESSION['YearEnd'] + 2,0,Date('Y')-1));
}
$sql = "SELECT periodno, lastdate_in_period
FROM periods
ORDER BY periodno DESC";
$Periods = DB_query($sql);
while($myrow=DB_fetch_array($Periods)) {
if(isset($_POST['FromPeriod']) AND $_POST['FromPeriod']!='') {
if( $_POST['FromPeriod']== $myrow['periodno']) {
echo '<option selected="selected" value="' . $myrow['periodno'] . '">' .MonthAndYearFromSQLDate($myrow['lastdate_in_period']) . '</option>';
} else {
echo '<option value="' . $myrow['periodno'] . '">' . MonthAndYearFromSQLDate($myrow['lastdate_in_period']) . '</option>';
}
} else {
if($myrow['lastdate_in_period']==$DefaultFromDate) {
echo '<option selected="selected" value="' . $myrow['periodno'] . '">' . MonthAndYearFromSQLDate($myrow['lastdate_in_period']) . '</option>';
} else {
echo '<option value="' . $myrow['periodno'] . '">' . MonthAndYearFromSQLDate($myrow['lastdate_in_period']) . '</option>';
}
}
}
echo '</select></td>
</tr>
<tr>
<td>', _('Select period to'), ':</td>
<td><select required="required" name="ToPeriod">';
if(!isset($_POST['ToPeriod']) OR $_POST['ToPeriod']=='') {
$LastDate = date('Y-m-d',mktime(0,0,0,Date('m')+1,0,Date('Y')));
$sql = "SELECT periodno FROM periods where lastdate_in_period = '" . $LastDate . "'";
$MaxPrd = DB_query($sql);
$MaxPrdrow = DB_fetch_row($MaxPrd);
$DefaultToPeriod = (int) ($MaxPrdrow[0]);
} else {
$DefaultToPeriod = $_POST['ToPeriod'];
}
$RetResult = DB_data_seek($Periods,0);
while($myrow=DB_fetch_array($Periods)) {
echo '<option';
if($myrow['periodno']==$DefaultToPeriod) {
echo ' selected="selected"';
}
echo ' value="', $myrow['periodno'], '">', MonthAndYearFromSQLDate($myrow['lastdate_in_period']), '</option>';
}
echo '</select></td>
</tr>
<tr>
<td>
<h3>', _('OR'), '</h3>
</td>
</tr>';
if (!isset($_POST['Period'])) {
$_POST['Period'] = '';
}
echo '<tr>
<td>', _('Select Period'), ':</td>
<td>', ReportPeriodList($_POST['Period'], array('l', 't')), '</td>
</tr>
<tr>
<td>', _('Detail or summary'), ':</td>
<td><select name="Detail" required="required" title="', _('Selecting Summary will show on the totals at the account group level'), '" >
<option value="Summary">', _('Summary'), '</option>
<option selected="selected" value="Detailed">', _('All Accounts'), '</option>
</select></td>
</tr>
<tr>
<td>', _('Show all accounts including zero balances'), '</td>
<td><input name="ShowZeroBalances" title="', _('Check this box to display all accounts including those accounts with no balance'), '" type="checkbox" /></td>
</tr>
</table>
<br />', // Form buttons:
'<div class="centre noprint">',
'<button name="ShowPL" type="submit" value="', _('Show on Screen (HTML)'), '"><img alt="" src="', $RootPath, '/css/', $Theme,
'/images/gl.png" /> ', _('Show on Screen (HTML)'), '</button> ', // "Show on Screen (HTML)" button.
'<button onclick="window.location=\'index.php?Application=GL\'" type="button"><img alt="" src="', $RootPath, '/css/', $Theme,
'/images/return.svg" /> ', _('Return'), '</button>', // "Return" button.
'</div>';
// Now do the posting while the user is thinking about the period to select:
include ('includes/GLPostings.inc');
} else {
$NumberOfMonths = $_POST['ToPeriod'] - $_POST['FromPeriod'] + 1;
if($NumberOfMonths >12) {
echo '<br />';
prnMsg(_('A period up to 12 months in duration can be specified') . ' - ' . _('the system automatically shows a comparative for the same period from the previous year') . ' - ' . _('it cannot do this if a period of more than 12 months is specified') . '. ' . _('Please select an alternative period range'),'error');
include('includes/footer.php');
exit;
}
$sql = "SELECT lastdate_in_period FROM periods WHERE periodno='" . $_POST['ToPeriod'] . "'";
$PrdResult = DB_query($sql);
$myrow = DB_fetch_row($PrdResult);
$PeriodToDate = MonthAndYearFromSQLDate($myrow[0]);
// Page title as IAS 1, numerals 10 and 51:
include_once('includes/CurrenciesArray.php');// Array to retrieve currency name.
echo '<div id="Report">', // Division to identify the report block.
'<p class="page_title_text"><img alt="" src="', $RootPath, '/css/', $Theme,
'/images/gl.png" title="', // Icon image.
_('Horizontal Analysis of Statement of Comprehensive Income'), '" /> ', // Icon title.
_('Horizontal Analysis of Statement of Comprehensive Income'), '<br />', // Page title, reporting statement.
stripslashes($_SESSION['CompanyRecord']['coyname']), '<br />', // Page title, reporting entity.
_('For'), ' ', $NumberOfMonths, ' ', _('months to'), ' ', $PeriodToDate, '<br />', // Page title, reporting period.
_('All amounts stated in'), ': ', _($CurrencyName[$_SESSION['CompanyRecord']['currencydefault']]), '</p>';// Page title, reporting presentation currency and level of rounding used.
echo '<table class="scrollable">
<thead>
<tr>';
if($_POST['Detail']=='Detailed') {// Detailed report:
echo '<th class="text">', _('Account'), '</th>
<th class="text">', _('Account Name'), '</th>';
} else {// Summary report:
echo '<th class="text" colspan="2">', _('Summary'), '</th>';
}
echo '<th class="number">', _('Current period'), '</th>
<th class="number">', _('Last period'), '</th>
<th class="number">', _('Actual change'), '</th>
<th class="number">', _('Relative change'), '</th>
</tr>
</thead>
<tfoot>
<tr>
<td class="text" colspan="6">',// Prints an explanation of signs in actual and relative changes:
'<br /><b>', _('Notes'), ':</b><br />',
_('Actual change signs: a positive number indicates a variation that increases the net profit; a negative number indicates a variation that decreases the net profit.'), '<br />',
_('Relative change signs: a positive number indicates an increase in the amount of that account; a negative number indicates a decrease in the amount of that account.'), '<br />',
'</td>
</tr>
</tfoot>
<tbody>';// thead and tfoot used in conjunction with tbody enable scrolling of the table body independently of the header and footer. Also, when printing a large table that spans multiple pages, these elements can enable the table header to be printed at the top of each page.
$SQL = "SELECT accountgroups.sectioninaccounts,
accountgroups.parentgroupname,
accountgroups.groupname,
chartdetails.accountcode,
chartmaster.accountname,
SUM(CASE WHEN chartdetails.period='" . $_POST['FromPeriod'] . "' THEN chartdetails.bfwd ELSE 0 END) AS firstprdbfwd,
SUM(CASE WHEN chartdetails.period='" . $_POST['ToPeriod'] . "' THEN chartdetails.bfwd + chartdetails.actual ELSE 0 END) AS lastprdcfwd,
SUM(CASE WHEN chartdetails.period='" . ($_POST['FromPeriod'] - 12) . "' THEN chartdetails.bfwd ELSE 0 END) AS firstprdbfwdly,
SUM(CASE WHEN chartdetails.period='" . ($_POST['ToPeriod']-12) . "' THEN chartdetails.bfwd + chartdetails.actual ELSE 0 END) AS lastprdcfwdly
FROM chartmaster
INNER JOIN accountgroups ON chartmaster.group_ = accountgroups.groupname
INNER JOIN chartdetails ON chartmaster.accountcode= chartdetails.accountcode
INNER JOIN glaccountusers ON glaccountusers.accountcode=chartmaster.accountcode AND glaccountusers.userid='" . $_SESSION['UserID'] . "' AND glaccountusers.canview=1
WHERE accountgroups.pandl=1
GROUP BY accountgroups.sectioninaccounts,
accountgroups.parentgroupname,
accountgroups.groupname,
chartdetails.accountcode,
chartmaster.accountname
ORDER BY accountgroups.sectioninaccounts,
accountgroups.sequenceintb,
accountgroups.groupname,
chartdetails.accountcode";
$AccountsResult = DB_query($SQL,_('No general ledger accounts were returned by the SQL because'),_('The SQL that failed was'));
$PeriodTotal=0;
$PeriodTotalLY=0;
$Section='';
$SectionTotal=0;
$SectionTotalLY=0;
$ActGrp='';
$GrpTotal=array(0);
$GrpTotalLY=array(0);
$Level=0;
$ParentGroups=array();
$ParentGroups[$Level]='';
$DrawTotalLine = '<tr>
<td colspan="2"> </td>
<td><hr /></td>
<td><hr /></td>
<td><hr /></td>
<td><hr /></td>
</tr>';
while($myrow=DB_fetch_array($AccountsResult)) {
if($myrow['groupname']!= $ActGrp) {
if($myrow['parentgroupname']!=$ActGrp AND $ActGrp!='') {
while($myrow['groupname']!=$ParentGroups[$Level] AND $Level>0) {
if($_POST['Detail']=='Detailed') {
echo $DrawTotalLine;
$ActGrpLabel = str_repeat('___',$Level) . $ParentGroups[$Level] . ' *' . _('total');
} else {
$ActGrpLabel = str_repeat('___',$Level) . $ParentGroups[$Level];
}
echo '<tr>
<td class="text" colspan="2">', $ActGrpLabel, '</td>
<td class="number">', locale_number_format(-$GrpTotal[$Level],$_SESSION['CompanyRecord']['decimalplaces']), '</td>
<td class="number">', locale_number_format(-$GrpTotalLY[$Level],$_SESSION['CompanyRecord']['decimalplaces']), '</td>
<td class="number">', locale_number_format(-$GrpTotal[$Level]+$GrpTotalLY[$Level],$_SESSION['CompanyRecord']['decimalplaces']), '</td>
<td class="number">', RelativeChange(-$GrpTotal[$Level],-$GrpTotalLY[$Level]), '</td>
</tr>';
$GrpTotal[$Level]=0;
$GrpTotalLY[$Level]=0;
$ParentGroups[$Level]='';
$Level--;
}// End while.
//still need to print out the old group totals
if($_POST['Detail']=='Detailed') {
echo $DrawTotalLine;
$ActGrpLabel = str_repeat('___',$Level) . $ParentGroups[$Level] . ' ' . _('total');
} else {
$ActGrpLabel = str_repeat('___',$Level) . $ParentGroups[$Level];
}
// --->
if($Section ==1) {// Income
echo '<tr>
<td class="text" colspan="2">', $ActGrpLabel, '</td>
<td class="number">', locale_number_format(-$GrpTotal[$Level],$_SESSION['CompanyRecord']['decimalplaces']), '</td>
<td class="number">', locale_number_format(-$GrpTotalLY[$Level],$_SESSION['CompanyRecord']['decimalplaces']), '</td>
<td class="number">', locale_number_format(-$GrpTotal[$Level]+$GrpTotalLY[$Level],$_SESSION['CompanyRecord']['decimalplaces']), '</td>
<td class="number">', RelativeChange(-$GrpTotal[$Level],-$GrpTotalLY[$Level]), '</td>
</tr>';
} else {// Costs
// <---
echo '<tr>
<td class="text" colspan="2">', $ActGrpLabel, '</td>
<td class="number">', locale_number_format(-$GrpTotal[$Level],$_SESSION['CompanyRecord']['decimalplaces']), '</td>
<td class="number">', locale_number_format(-$GrpTotalLY[$Level],$_SESSION['CompanyRecord']['decimalplaces']), '</td>
<td class="number">', locale_number_format(-$GrpTotal[$Level]+$GrpTotalLY[$Level],$_SESSION['CompanyRecord']['decimalplaces']), '</td>
<td class="number">', RelativeChange(-$GrpTotal[$Level],-$GrpTotalLY[$Level]), '</td>
</tr>';
// --->
}
// <---
$GrpTotalLY[$Level]=0;
$GrpTotal[$Level]=0;
$ParentGroups[$Level]='';
}
}
if($myrow['sectioninaccounts']!= $Section) {
if($SectionTotal+$SectionTotalLY !=0) {
if($Section==1) {// Income.
echo $DrawTotalLine;
echo '<tr>
<td class="text" colspan="2"><h2>', $Sections[$Section], '</h2></td>
<td class="number"><h2>', locale_number_format(-$SectionTotal,$_SESSION['CompanyRecord']['decimalplaces']), '</h2></td>
<td class="number"><h2>', locale_number_format(-$SectionTotalLY,$_SESSION['CompanyRecord']['decimalplaces']), '</h2></td>
<td class="number"><h2>', locale_number_format(-$SectionTotal+$SectionTotalLY,$_SESSION['CompanyRecord']['decimalplaces']), '</h2></td>
<td class="number"><h2>', RelativeChange(-$SectionTotal,-$SectionTotalLY), '</h2></td>
</tr>';
$GPIncome = $SectionTotal;
$GPIncomeLY = $SectionTotalLY;
} else {
echo '<tr>
<td class="text" colspan="2"><h2>', $Sections[$Section], '</h2></td>
<td class="number"><h2>', locale_number_format(-$SectionTotal,$_SESSION['CompanyRecord']['decimalplaces']), '</h2></td>
<td class="number"><h2>', locale_number_format(-$SectionTotalLY,$_SESSION['CompanyRecord']['decimalplaces']), '</h2></td>
<td class="number"><h2>', locale_number_format(-$SectionTotal+$SectionTotalLY,$_SESSION['CompanyRecord']['decimalplaces']), '</h2></td>
<td class="number"><h2>', RelativeChange(-$SectionTotal,-$SectionTotalLY), '</h2></td>
</tr>';
}
if($Section==2) {// Cost of Sales - need sub total for Gross Profit.
echo $DrawTotalLine;
echo '<tr>
<td class="text" colspan="2"><h2>', _('Gross Profit'), '</h2></td>
<td class="number"><h2>', locale_number_format(-($GPIncome+$SectionTotal),$_SESSION['CompanyRecord']['decimalplaces']), '</h2></td>
<td class="number"><h2>', locale_number_format(-($GPIncomeLY+$SectionTotalLY),$_SESSION['CompanyRecord']['decimalplaces']), '</h2></td>
<td class="number"><h2>', locale_number_format(-($GPIncome+$SectionTotal)+($GPIncomeLY+$SectionTotalLY),$_SESSION['CompanyRecord']['decimalplaces']), '</h2></td>
<td class="number"><h2>', RelativeChange(-($GPIncome+$SectionTotal),-($GPIncomeLY+$SectionTotalLY)), '</h2></td>
</tr>';
}
if(($Section!=1) AND ($Section!=2)) {
echo $DrawTotalLine;
echo '<tr>
<td class="text" colspan="2"><h2>', _('Earnings after'), ' ', $Sections[$Section], '</h2></td>
<td class="number"><h2>', locale_number_format(-$PeriodTotal,$_SESSION['CompanyRecord']['decimalplaces']), '</h2></td>
<td class="number"><h2>', locale_number_format(-$PeriodTotalLY,$_SESSION['CompanyRecord']['decimalplaces']), '</h2></td>
<td class="number"><h2>', locale_number_format(-$PeriodTotal+$PeriodTotalLY,$_SESSION['CompanyRecord']['decimalplaces']), '</h2></td>
<td class="number"><h2>', RelativeChange(-$PeriodTotal,-$PeriodTotalLY), '</h2></td>
</tr>';
echo $DrawTotalLine;
}
}
$Section = $myrow['sectioninaccounts'];
$SectionTotal=0;
$SectionTotalLY=0;
if($_POST['Detail']=='Detailed') {
echo '<tr>
<td colspan="6"><h2>', $Sections[$myrow['sectioninaccounts']], '</h2></td>
</tr>';
}
}
if($myrow['groupname']!= $ActGrp) {
if($myrow['parentgroupname']==$ActGrp AND $ActGrp !='') {// Adding another level of nesting
$Level++;
}
$ActGrp = $myrow['groupname'];
$ParentGroups[$Level] = $myrow['groupname'];
if($_POST['Detail']=='Detailed') {
echo '<tr>
<td colspan="6"><h2>', $myrow['groupname'], '</h2></td>
</tr>';
}
}
// Set totals for account, groups, section and period:
$AccountTotal = $myrow['lastprdcfwd'] - $myrow['firstprdbfwd'];
$AccountTotalLY = $myrow['lastprdcfwdly'] - $myrow['firstprdbfwdly'];
for ($i=0;$i<=$Level;$i++) {
if(!isset($GrpTotalLY[$i])) {$GrpTotalLY[$i]=0;}
$GrpTotalLY[$i] += $AccountTotalLY;
if(!isset($GrpTotal[$i])) {$GrpTotal[$i]=0;}
$GrpTotal[$i] += $AccountTotal;
}
$SectionTotal += $AccountTotal;
$SectionTotalLY += $AccountTotalLY;
$PeriodTotal += $AccountTotal;
$PeriodTotalLY += $AccountTotalLY;
if($_POST['Detail']=='Detailed') {
if(isset($_POST['ShowZeroBalances']) OR (!isset($_POST['ShowZeroBalances']) AND ($AccountTotal <> 0 OR $AccountTotalLY <> 0))) {
echo '<tr class="striped_row">
<td class="text"><a href="', $RootPath, '/GLAccountInquiry.php?FromPeriod=', urlencode($_POST['FromPeriod']), '&ToPeriod=', urlencode($_POST['ToPeriod']), '&Account=', urlencode($myrow['accountcode']), '&Show=Yes">', $myrow['accountcode'], '</a></td>';
// --->
if($Section ==1) {
echo ' <td class="text">', htmlspecialchars($myrow['accountname'],ENT_QUOTES,'UTF-8',false), '</td>
<td class="number">', locale_number_format(-$AccountTotal,$_SESSION['CompanyRecord']['decimalplaces']), '</td>
<td class="number">', locale_number_format(-$AccountTotalLY,$_SESSION['CompanyRecord']['decimalplaces']), '</td>
<td class="number">', locale_number_format(-$AccountTotal+$AccountTotalLY,$_SESSION['CompanyRecord']['decimalplaces']), '</td>
<td class="number">', RelativeChange(-$AccountTotal,-$AccountTotalLY), '</td>
</tr>';
} else {
// <---
echo ' <td class="text">', htmlspecialchars($myrow['accountname'],ENT_QUOTES,'UTF-8',false), '</td>
<td class="number">', locale_number_format(-$AccountTotal,$_SESSION['CompanyRecord']['decimalplaces']), '</td>
<td class="number">', locale_number_format(-$AccountTotalLY,$_SESSION['CompanyRecord']['decimalplaces']), '</td>
<td class="number">', locale_number_format(-$AccountTotal+$AccountTotalLY,$_SESSION['CompanyRecord']['decimalplaces']), '</td>
<td class="number">', RelativeChange(-$AccountTotal,-$AccountTotalLY), '</td>
</tr>';
}
}
}
}// End of loop.
if($myrow['groupname']!= $ActGrp) {
if($myrow['parentgroupname']!=$ActGrp AND $ActGrp!='') {
while($myrow['groupname']!=$ParentGroups[$Level] AND $Level>0) {
if($_POST['Detail']=='Detailed') {
echo $DrawTotalLine;
$ActGrpLabel = str_repeat('___',$Level) . $ParentGroups[$Level] . ' ' . _('total');
} else {
$ActGrpLabel = str_repeat('___',$Level) . $ParentGroups[$Level];
}
// --->
if($Section ==1) {// Income.
echo '<tr>
<td colspan="2"><h3>', $ActGrpLabel, '</h3></td>
<td class="number">', locale_number_format(-$GrpTotal[$Level],$_SESSION['CompanyRecord']['decimalplaces']), '</td>
<td class="number">', locale_number_format(-$GrpTotalLY[$Level],$_SESSION['CompanyRecord']['decimalplaces']), '</td>
<td class="number">', locale_number_format(-$GrpTotal[$Level]+$GrpTotalLY[$Level],$_SESSION['CompanyRecord']['decimalplaces']), '</td>
<td class="number">', RelativeChange(-$GrpTotal[$Level],-$GrpTotalLY[$Level]), '</td>
</tr>';
} else {// Costs.
// <---
echo '<tr>
<td colspan="2"><h3>', $ActGrpLabel, '</h3></td>
<td class="number">', locale_number_format(-$GrpTotal[$Level],$_SESSION['CompanyRecord']['decimalplaces']), '</td>
<td class="number">', locale_number_format(-$GrpTotalLY[$Level],$_SESSION['CompanyRecord']['decimalplaces']), '</td>
<td class="number">', locale_number_format(-$GrpTotal[$Level]+$GrpTotalLY[$Level],$_SESSION['CompanyRecord']['decimalplaces']), '</td>
<td class="number">', RelativeChange(-$GrpTotal[$Level],-$GrpTotalLY[$Level]), '</td>
</tr>';
}
$GrpTotal[$Level]=0;
$GrpTotalLY[$Level]=0;
$ParentGroups[$Level]='';
$Level--;
}// End while.
//still need to print out the old group totals
if($_POST['Detail']=='Detailed') {
echo $DrawTotalLine;
$ActGrpLabel = str_repeat('___',$Level) . $ParentGroups[$Level] . ' ' . _('total');
} else {
$ActGrpLabel = str_repeat('___',$Level) . $ParentGroups[$Level];
}
echo '<tr>
<td colspan="2"><h3>', $ActGrpLabel, '</h3></td>
<td class="number">', locale_number_format(-$GrpTotal[$Level],$_SESSION['CompanyRecord']['decimalplaces']), '</td>
<td class="number">', locale_number_format(-$GrpTotalLY[$Level],$_SESSION['CompanyRecord']['decimalplaces']), '</td>
<td class="number">', locale_number_format(-$GrpTotal[$Level]+$GrpTotalLY[$Level],$_SESSION['CompanyRecord']['decimalplaces']), '</td>
<td class="number">', RelativeChange(-$GrpTotal[$Level],-$GrpTotalLY[$Level]), '</td>
</tr>';
$GrpTotal[$Level]=0;
$GrpTotalLY[$Level]=0;
$ParentGroups[$Level]='';
}
}
if($myrow['sectioninaccounts']!= $Section) {
if($Section==1) {// Income.
echo $DrawTotalLine,
'<tr>
<td colspan="2"><h2>', $Sections[$Section], '</h2></td>
<td class="number"><h2>', locale_number_format(-$SectionTotal,$_SESSION['CompanyRecord']['decimalplaces']), '</h2></td>
<td class="number"><h2>', locale_number_format(-$SectionTotalLY,$_SESSION['CompanyRecord']['decimalplaces']), '</h2></td>
<td class="number"><h2>', locale_number_format(-$SectionTotal+$SectionTotalLY,$_SESSION['CompanyRecord']['decimalplaces']), '</h2></td>
<td class="number"><h2>', RelativeChange(-$SectionTotal,-$SectionTotalLY), '</h2></td>
</tr>';
$GPIncome = $SectionTotal;
$GPIncomeLY = $SectionTotalLY;
} else {
echo $DrawTotalLine,
'<tr>
<td colspan="2"><h2>', $Sections[$Section], '</h2></td>
<td class="number"><h2>', locale_number_format(-$SectionTotal,$_SESSION['CompanyRecord']['decimalplaces']), '</h2></td>
<td class="number"><h2>', locale_number_format(-$SectionTotalLY,$_SESSION['CompanyRecord']['decimalplaces']), '</h2></td>
<td class="number"><h2>', locale_number_format(-$SectionTotal+$SectionTotalLY,$_SESSION['CompanyRecord']['decimalplaces']), '</h2></td>
<td class="number"><h2>', RelativeChange(-$SectionTotal,-$SectionTotalLY), '</h2></td>
</tr>';
}
if($Section==2) {// Cost of Sales - need sub total for Gross Profit.
echo $DrawTotalLine,
'<tr>
<td colspan="2"><h2>', _('Gross Profit'), '</h2></td>
<td class="number"><h2>', locale_number_format(-($GPIncome+$SectionTotal),$_SESSION['CompanyRecord']['decimalplaces']), '</h2></td>
<td class="number"><h2>', locale_number_format(-($GPIncomeLY+$SectionTotalLY),$_SESSION['CompanyRecord']['decimalplaces']), '</h2></td>
<td class="number"><h2>', locale_number_format(-($GPIncome+$SectionTotal)+($GPIncomeLY+$SectionTotalLY),$_SESSION['CompanyRecord']['decimalplaces']), '</h2></td>
<td class="number"><h2>', RelativeChange(-($GPIncome+$SectionTotal),-($GPIncomeLY+$SectionTotalLY)), '</h2></td>
</tr>';
}
$Section = $myrow['sectioninaccounts'];
$SectionTotal=0;
$SectionTotalLY=0;
if($_POST['Detail']=='Detailed' and isset($Sections[$myrow['sectioninaccounts']])) {
echo '<tr>
<td colspan="6"><h2>', $Sections[$myrow['sectioninaccounts']], '</h2></td>
</tr>';
}
}
echo $DrawTotalLine;
echo '<tr>
<td colspan="2"><h2>', _('Net Profit'), '</h2></td>
<td class="number"><h2>', locale_number_format(-$PeriodTotal,$_SESSION['CompanyRecord']['decimalplaces']), '</h2></td>
<td class="number"><h2>', locale_number_format(-$PeriodTotalLY,$_SESSION['CompanyRecord']['decimalplaces']), '</h2></td>
<td class="number"><h2>', locale_number_format(-$PeriodTotal+$PeriodTotalLY,$_SESSION['CompanyRecord']['decimalplaces']), '</h2></td>
<td class="number"><h2>', RelativeChange(-$PeriodTotal,-$PeriodTotalLY), '</h2></td>
</tr>';
echo $DrawTotalLine;
echo '</tbody>', // See comment at the begin of the table.
'</table>
</div>';// End div id="Report".
echo '<br />',
'<form method="post" action="', htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8'), '">',
'<input type="hidden" name="FormID" value="', $_SESSION['FormID'], '" />',
'<input type="hidden" name="FromPeriod" value="', $_POST['FromPeriod'], '" />',
'<input type="hidden" name="ToPeriod" value="', $_POST['ToPeriod'], '" />',
'<div class="centre noprint">', // Form buttons:
'<button onclick="javascript:window.print()" type="button"><img alt="" src="', $RootPath, '/css/', $Theme,
'/images/printer.png" /> ', _('Print'), '</button>', // "Print" button.
'<button name="SelectADifferentPeriod" type="submit" value="', _('Select A Different Period'), '"><img alt="" src="', $RootPath, '/css/', $Theme,
'/images/gl.png" /> ', _('Select A Different Period'), '</button> ', // "Select A Different Period" button.
'<button onclick="window.location=\'index.php?Application=GL\'" type="button"><img alt="" src="', $RootPath, '/css/', $Theme,
'/images/return.svg" /> ', _('Return'), '</button>', // "Return" button.
'</div>';
}
echo '</form>';
include('includes/footer.php');
?>