forked from victorkagimu/KwaMoja
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Z_RePostGLFromPeriod.php
72 lines (59 loc) · 2.51 KB
/
Z_RePostGLFromPeriod.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
<?php
include ('includes/session.php');
$Title = _('Recalculation of GL Balances in Chart Details Table');
include ('includes/header.php');
echo '<form method="post" action="' . htmlspecialchars(basename(__FILE__), ENT_QUOTES, 'UTF-8') . '">';
echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
if (!isset($_POST['FromPeriod'])) {
/*Show a form to allow input of criteria for TB to show */
echo '<table>
<tr>
<td>' . _('Select Period From') . ':</td>
<td><select name="FromPeriod">';
$SQL = "SELECT periodno,
lastdate_in_period
FROM periods ORDER BY periodno";
$Periods = DB_query($SQL);
while ($MyRow = DB_fetch_array($Periods)) {
echo '<option value="' . $MyRow['periodno'] . '">' . MonthAndYearFromSQLDate($MyRow['lastdate_in_period']) . '</option>';
}
echo '</select></td>
</tr>
</table>';
echo '<div class="centre"><input type="submit" name="recalc" value="' . _('Do the Recalculation') . '" onclick="return MakeConfirm(\'' . _('Are you sure you wish to re-post all general ledger transactions since the selected period this can take some time?') . '\');" /></div>
</form>';
} else {
/* Zeroise the whole table */
$SQL = "UPDATE chartdetails SET actual=0, bfwd=0";
$Result = DB_query($SQL);
/* Then get the list of all GL codes */
$SQL = "SELECT accountcode FROM chartmaster";
$GLCodesResult = DB_query($SQL);
/* and cycle through each code */
while ($GLCodes = DB_fetch_array($GLCodesResult)) {
/* Fetch the periods */
$SQL = "SELECT period
FROM chartdetails
WHERE accountcode='" . $GLCodes['accountcode'] . "'
ORDER BY period";
$PeriodResult = DB_query($SQL);
$BalanceBroughtForward = 0;
while ($Periods = DB_fetch_array($PeriodResult)) {
/* Get the actual period amount */
$SQL = "SELECT SUM(amount) AS actual FROM gltrans WHERE account='" . $GLCodes['accountcode'] . "' AND periodno='" . $Periods['period'] . "'";
$Result = DB_query($SQL);
$MyRow = DB_fetch_array($Result);
/* Update the chartdetails table */
$SQL = "UPDATE chartdetails SET actual='" . $MyRow['actual'] . "',
bfwd=" . $BalanceBroughtForward . "
WHERE accountcode='" . $GLCodes['accountcode'] . "'
AND period='" . $Periods['period'] . "'";
$Result = DB_query($SQL);
/* Calculate the balance carried forward */
$BalanceBroughtForward+= $MyRow['actual'];
}
}
prnMsg(_('All general ledger postings have been reposted from period') . ' ' . $_POST['FromPeriod'], 'success');
}
include ('includes/footer.php');
?>