forked from timschofield/webERP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZ_CheckDebtorsControl.php
158 lines (123 loc) · 5.65 KB
/
Z_CheckDebtorsControl.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
<?php
include('includes/session.php');
$Title=_('Debtors Control Integrity');
$ViewTopic = 'SpecialUtilities';
$BookMark = basename(__FILE__, '.php'); ;
include('includes/header.php');
//
//========[ SHOW OUR FORM ]===========
//
// Context Navigation and Title
echo '<a href="'. $RootPath . '/index.php?&Application=AR">' . _('Back to Customers') . '</a>';
echo '<div class="centre"><h3>' . $Title . '</h3></div>';
// Page Border
echo '<form method="post" action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '">';
echo '<div class="centre">';
echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
echo '<table class="selection">';
$DefaultFromPeriod = ( !isset($_POST['FromPeriod']) OR $_POST['FromPeriod']=='' ) ? 1 : $_POST['FromPeriod'];
if ( !isset($_POST['ToPeriod']) OR $_POST['ToPeriod']=='' )
{
$SQL = "SELECT Max(periodno) FROM periods";
$prdResult = DB_query($SQL);
$MaxPrdrow = DB_fetch_row($prdResult);
DB_free_result($prdResult);
$DefaultToPeriod = $MaxPrdrow[0];
} else {
$DefaultToPeriod = $_POST['ToPeriod'];
}
echo '<tr>
<td>' . _('Start Period:') . '</td>
<td><select name="FromPeriod">';
$ToSelect = '<tr><td>' . _('End Period:') . '</td>
<td><select name="ToPeriod">';
$SQL = "SELECT periodno, lastdate_in_period FROM periods ORDER BY periodno";
$perResult = DB_query($SQL);
while ( $perRow=DB_fetch_array($perResult) ) {
$FromSelected = ( $perRow['periodno'] == $DefaultFromPeriod ) ? 'selected="selected"' : '';
echo '<option ' . $FromSelected . ' value="' . $perRow['periodno'] . '">' .MonthAndYearFromSQLDate($perRow['lastdate_in_period']) . '</option>';
$ToSelected = ( $perRow['periodno'] == $DefaultToPeriod ) ? 'selected="selected"' : '';
$ToSelect .= '<option ' . $ToSelected . ' value="' . $perRow['periodno'] . '">' . MonthAndYearFromSQLDate($perRow['lastdate_in_period']) . '</option>';
}
DB_free_result($perResult);
echo '</select></td></tr>';
echo $ToSelect . '</select></td></tr>';
echo '</table>';
echo '<br /><input type="submit" name="Show" value="'._('Accept').'" />';
echo '<input type="submit" value="' . _('Cancel') .'" />';
if ( isset($_POST['Show']) ) {
//
//========[ SHOW SYNOPSYS ]===========
//
echo '<br /><table border="1">';
echo '<tr>
<th>' . _('Period') . '</th>
<th>' . _('Bal B/F in GL') . '</th>
<th>' . _('Invoices') . '</th>
<th>' . _('Receipts') . '</th>
<th>' . _('Bal C/F in GL') . '</th>
<th>' . _('Calculated') . '</th>
<th>' . _('Difference') . '</th>
</tr>';
$CurPeriod = $_POST['FromPeriod'];
$GLOpening = $invTotal = $RecTotal = $GLClosing = $CalcTotal = $DiffTotal = 0;
while ( $CurPeriod <= $_POST['ToPeriod'] ) {
$SQL = "SELECT bfwd,
actual
FROM chartdetails
WHERE period = " . $CurPeriod . "
AND accountcode=" . $_SESSION['CompanyRecord']['debtorsact'];
$dtResult = DB_query($SQL);
$dtRow = DB_fetch_array($dtResult);
DB_free_result($dtResult);
$GLOpening += $dtRow['bfwd'];
$glMovement = $dtRow['bfwd'] + $dtRow['actual'];
echo '<tr class="striped_row">
<td>' . $CurPeriod . '</td>
<td class="number">' . locale_number_format($dtRow['bfwd'],2) . '</td>';
$SQL = "SELECT SUM((ovamount+ovgst+ovfreight+ovdiscount)/rate) AS totinvnetcrds
FROM debtortrans
WHERE prd = '" . $CurPeriod . "'
AND (type=10 OR type=11)";
$invResult = DB_query($SQL);
$invRow = DB_fetch_array($invResult);
DB_free_result($invResult);
$invTotal += $invRow['totinvnetcrds'];
echo '<td class="number">' . locale_number_format($invRow['totinvnetcrds'],2) . '</td>';
$SQL = "SELECT SUM((ovamount+ovgst+ovfreight+ovdiscount)/rate) AS totreceipts
FROM debtortrans
WHERE prd = '" . $CurPeriod . "'
AND type=12";
$recResult = DB_query($SQL);
$recRow = DB_fetch_array($recResult);
DB_free_result($recResult);
$RecTotal += $recRow['totreceipts'];
$CalcMovement = $dtRow['bfwd'] + $invRow['totinvnetcrds'] + $recRow['totreceipts'];
echo '<td class="number">' . locale_number_format($recRow['totreceipts'],2) . '</td>';
$GLClosing += $glMovement;
$CalcTotal += $CalcMovement;
$DiffTotal += $diff;
$diff = ( $dtRow['bfwd'] == 0 ) ? 0 : round($glMovement,2) - round($CalcMovement,2);
$color = ( $diff == 0 OR $dtRow['bfwd'] == 0 ) ? 'green' : 'red';
echo '<td class="number">' . locale_number_format($glMovement,$_SESSION['CompanyRecord']['decimalplaces']) . '</td>
<td class="number">' . locale_number_format(($CalcMovement),$_SESSION['CompanyRecord']['decimalplaces']) . '</td>
<td class="number" style="background-color:white;color:' . $color . '">' . locale_number_format($diff,$_SESSION['CompanyRecord']['decimalplaces']) . '</td>
</tr>';
$CurPeriod++;
}
$difColor = ( $DiffTotal == 0 ) ? 'green' : 'red';
echo '<tr style="bgcolor:white">
<td>' . _('Total') . '</td>
<td class="number">' . locale_number_format($GLOpening,$_SESSION['CompanyRecord']['decimalplaces']) . '</td>
<td class="number">' . locale_number_format($invTotal,$_SESSION['CompanyRecord']['decimalplaces']) . '</td>
<td class="number">' . locale_number_format($RecTotal,$_SESSION['CompanyRecord']['decimalplaces']) . '</td>
<td class="number">' . locale_number_format($GLClosing,$_SESSION['CompanyRecord']['decimalplaces']) . '</td>
<td class="number">' . locale_number_format($CalcTotal,$_SESSION['CompanyRecord']['decimalplaces']) . '</td>
<td class="number" style="color=' . $difColor . '">' . locale_number_format($DiffTotal,$_SESSION['CompanyRecord']['decimalplaces']) . '</td>
</tr>';
echo '</table>';
}
echo '</div>
</form>';
include('includes/footer.php');
?>