forked from timschofield/webERP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSalesCommissionStatements.php
251 lines (219 loc) · 8.68 KB
/
SalesCommissionStatements.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
<?php
include ('includes/session.php');
$Title = _('Sales Commission Statements');
/* Manual links before header.php */
$ViewTopic = 'SalesCommission';
$BookMark = 'Reports';
include ('includes/header.php');
echo '<p class="page_title_text">
<img src="', $RootPath, '/css/', $_SESSION['Theme'], '/images/reports.png" title="', _('Search'), '" alt="" />', ' ', $Title, '
</p>';
if (isset($_POST['Submit'])) {
if ($_POST['Period'] != '') {
$_POST['FromPeriod'] = ReportPeriod($_POST['Period'], 'From');
$_POST['ToPeriod'] = ReportPeriod($_POST['Period'], 'To');
}
$SQL = "SELECT salescommissions.commissionno,
salescommissions.type,
salescommissions.transno,
salescommissions.stkmoveno,
salescommissions.salespersoncode,
salescommissions.paid,
salescommissions.amount,
salesman.salesmanname,
MONTHNAME(periods.lastdate_in_period) AS month,
YEAR(periods.lastdate_in_period) AS year,
salescommissions.currency,
salescommissions.exrate,
stockmoves.debtorno,
stockmoves.type AS invcredit,
stockmoves.transno AS invcredno,
debtorsmaster.name,
currencies.decimalplaces
FROM salescommissions
INNER JOIN gltrans
ON salescommissions.commissionno=gltrans.typeno
AND gltrans.type=39
INNER JOIN salesman
ON salescommissions.salespersoncode=salesman.salesmancode
INNER JOIN periods
ON periods.periodno=gltrans.periodno
INNER JOIN stockmoves
ON salescommissions.stkmoveno=stockmoves.stkmoveno
INNER JOIN debtorsmaster
ON stockmoves.debtorno=debtorsmaster.debtorno
INNER JOIN currencies
ON salescommissions.currency=currencies.currabrev
WHERE salescommissions.salespersoncode LIKE '" . $_POST['SalesPerson'] . "'
AND salescommissions.currency LIKE '" . $_POST['Currency'] . "'
AND salescommissions.paid LIKE '" . $_POST['PaidUnpaid'] . "'
AND gltrans.periodno>='" . $_POST['FromPeriod'] . "'
AND gltrans.periodno<='" . $_POST['ToPeriod'] . "'
AND gltrans.account='" . $_SESSION['CompanyRecord']['commissionsact'] . "'
ORDER BY salescommissions.commissionno";
$Result = DB_query($SQL);
if (DB_num_rows($Result) > 0) {
echo '<table>
<thead>
<tr>
<th class="SortedColumn">', _('Commission ID'), '</th>
<th class="SortedColumn">', _('Sales Person'), '</th>
<th class="SortedColumn">', _('Period'), '</th>
<th class="SortedColumn">', _('Customer'), '</th>
<th class="SortedColumn">', _('Invoice/Credit'), '</th>
<th class="SortedColumn">', _('Amount'), '</th>
<th class="SortedColumn">', _('Paid?'), '</th>
</tr>
</thead>';
echo '<tbody>';
while ($MyRow = DB_fetch_array($Result)) {
if ($MyRow['invcredit'] == 10) {
$Type = _('Invoice');
} else {
$Type = _('Credit');
}
if ($MyRow['paid'] == 0) {
$Paid = _('No');
} else {
$Paid = _('Yes');
}
echo '<tr class="striped_row">
<td>', $MyRow['commissionno'], '</td>
<td>', $MyRow['salesmanname'], '</td>
<td>', $MyRow['month'], ' ', $MyRow['year'], '</td>
<td>', $MyRow['debtorno'], ' - ', $MyRow['name'], '</td>
<td>', $Type, ' no ', $MyRow['invcredno'], '</td>
<td class="number">', locale_number_format($MyRow['amount'], $MyRow['decimalplaces']), '</td>
<td>', $Paid, '</td>
</tr>';
}
echo '</tbody>
</table>';
} else {
prnMsg(_('There are no commissions meeting this criteria. Please select different criteria and run the report again.'), 'info');
}
echo '<a class="noPrint" href="', htmlspecialchars(basename(__FILE__), ENT_QUOTES, 'UTF-8'), '">', _('Select different report criteria'), '</a><br />';
include ('includes/footer.php');
exit;
} else {
if (!isset($_POST['SalesPerson'])) {
$_POST['SalesPerson'] = '%%';
}
if (!isset($_POST['Currency'])) {
$_POST['Currency'] = '%%';
}
if (!isset($_POST['PaidUnpaid'])) {
$_POST['PaidUnpaid'] = '%%';
}
if (!isset($_POST['FromPeriod'])) {
$_POST['FromPeriod'] = GetPeriod(date($_SESSION['DefaultDateFormat']));
}
if (!isset($_POST['ToPeriod'])) {
$_POST['ToPeriod'] = GetPeriod(date($_SESSION['DefaultDateFormat']));
}
echo '<form method="post" action="', htmlspecialchars(basename(__FILE__), ENT_QUOTES, 'UTF-8'), '">';
echo '<input type="hidden" name="FormID" value="', $_SESSION['FormID'], '" />';
echo '<fieldset>
<legend>', _('Report Criteria'), '</legend>
<field>
<label for="SalesPerson">', _('Sales Person'), '</label>
<select name="SalesPerson" autofocus="autofocus">';
$SQL = "SELECT salesmancode,
salesmanname
FROM salesman";
$Result = DB_query($SQL);
echo '<option value="%%">', _('All Sales People'), '</option>';
while ($MyRow = DB_fetch_array($Result)) {
echo '<option value="', $MyRow['salesmancode'], '">', $MyRow['salesmanname'], '</option>';
}
echo '</select>
<fieldhelp>', _('Select the sales person to report on.'), '</fieldhelp>
</field>';
$SQL = "SELECT currabrev, currency FROM currencies";
$Result = DB_query($SQL);
echo '<field>
<label for="Currency">', _('Currency'), '</label>
<select name="Currency" required="required">';
echo '<option value="%%">', _('All Currencies'), '</option>';
while ($MyRow = DB_fetch_array($Result)) {
if ($MyRow['currabrev'] == $_POST['Currency']) {
echo '<option selected="selected" value="', $MyRow['currabrev'], '">', $MyRow['currency'], ' (', $MyRow['currabrev'], ')</option>';
} else {
echo '<option value="', $MyRow['currabrev'], '">', $MyRow['currency'], ' (', $MyRow['currabrev'], ')</option>';
}
}
echo '</select>
<fieldhelp>', _('Select the currency of the transactions to report on.'), '</fieldhelp>
</field>';
echo '<field>
<label for="PaidUnpaid">', _('Show Paid or Unpaid Commissions'), '</label>
<select name="PaidUnpaid">
<option value="%%">', _('All Commissions'), '</option>
<option value="0">', _('Only Unpaid Commissions'), '</option>
<option value="1">', _('Only Paid Commissions'), '</option>
</select>
<fieldhelp>', _('Filter commissions by whether they are paid or unpaid'), '</fieldhelp>
</field>';
echo ' <field>
<label for="FromPeriod">', _('Select Period From'), ':</label>
<select name="FromPeriod" autofocus="autofocus">';
$NextYear = date('Y-m-d', strtotime('+1 Year'));
$SQL = "SELECT periodno,
lastdate_in_period
FROM periods
WHERE lastdate_in_period < '" . $NextYear . "'
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>
<fieldhelp>', _('Select the starting period for this report'), '</fieldhelp>
</field>';
if (!isset($_POST['ToPeriod']) or $_POST['ToPeriod'] == '') {
$DefaultToPeriod = GetPeriod(date($_SESSION['DefaultDateFormat'], mktime(0, 0, 0, Date('m') + 1, 0, Date('Y'))));
} else {
$DefaultToPeriod = $_POST['ToPeriod'];
}
echo '<field>
<label for="ToPeriod">', _('Select Period To'), ':</label>
<select name="ToPeriod">';
$RetResult = DB_data_seek($Periods, 0);
while ($MyRow = DB_fetch_array($Periods)) {
if ($MyRow['periodno'] == $DefaultToPeriod) {
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>
<fieldhelp>', _('Select the end period for this report'), '</fieldhelp>
</field>';
if (!isset($_POST['Period'])) {
$_POST['Period'] = '';
}
echo '<field>
<label for="Period">','<b>' . _('OR') . ' </b>' . _('Select Period'), ':</label>
', ReportPeriodList($_POST['Period'], array('l', 't')), '
<fieldhelp>', _('Select a predefined period from this list. If a selection is made here it will override anything selected in the From and To options above.'), '</fieldhelp>
</field>';
echo '</fieldset>';
echo '<div class="centre">
<input type="submit" name="Submit" value="', _('View Report'), '" />
</div>';
echo '</form>';
}
include ('includes/footer.php');
?>