1<?php
2/* Shows the customers account transactions with balances outstanding, links available to drill down to invoice/credit note or email invoices/credit notes. */
3
4include('includes/session.php');
5$Title = _('Customer Inquiry');// Screen identification.
6$ViewTopic = 'ARInquiries';// Filename's id in ManualContents.php's TOC.
7$BookMark = 'CustomerInquiry';// Anchor's id in the manual's html document.
8include('includes/header.php');
9
10// always figure out the SQL required from the inputs available
11
12if (!isset($_GET['CustomerID']) and !isset($_SESSION['CustomerID'])) {
13	prnMsg(_('To display the enquiry a customer must first be selected from the customer selection screen'), 'info');
14	echo '<br /><div class="centre"><a href="', $RootPath, '/SelectCustomer.php">', _('Select a Customer to Inquire On'), '</a></div>';
15	include('includes/footer.php');
16	exit;
17} else {
18	if (isset($_GET['CustomerID'])) {
19		$_SESSION['CustomerID'] = stripslashes($_GET['CustomerID']);
20	}
21	$CustomerID = $_SESSION['CustomerID'];
22}
23//Check if the users have proper authority
24if ($_SESSION['SalesmanLogin'] != '') {
25	$ViewAllowed = false;
26	$sql = "SELECT salesman FROM custbranch WHERE debtorno = '" . $CustomerID . "'";
27	$ErrMsg = _('Failed to retrieve sales data');
28	$result = DB_query($sql,$ErrMsg);
29	if(DB_num_rows($result)>0) {
30		while($myrow = DB_fetch_array($result)) {
31			if ($_SESSION['SalesmanLogin'] == $myrow['salesman']){
32				$ViewAllowed = true;
33			}
34		}
35	} else {
36		prnMsg(_('There is no salesman data set for this debtor'),'error');
37		include('includes/footer.php');
38		exit;
39	}
40	if (!$ViewAllowed){
41		prnMsg(_('You have no authority to review this data'),'error');
42		include('includes/footer.php');
43		exit;
44	}
45}
46
47
48if (isset($_GET['Status'])) {
49	if (is_numeric($_GET['Status'])) {
50		$_POST['Status'] = $_GET['Status'];
51	}
52} elseif (isset($_POST['Status'])) {
53	if($_POST['Status'] == '' or $_POST['Status'] == 1 or $_POST['Status'] == 0) {
54		$Status = $_POST['Status'];
55	} else {
56		prnMsg(_('The balance status should be all or zero balance or not zero balance'), 'error');
57		exit;
58	}
59} else {
60	$_POST['Status'] = '';
61}
62
63if (!isset($_POST['TransAfterDate'])) {
64	$_POST['TransAfterDate'] = Date($_SESSION['DefaultDateFormat'], Mktime(0, 0, 0, Date('m') - $_SESSION['NumberOfMonthMustBeShown'], Date('d'), Date('Y')));
65}
66
67$SQL = "SELECT debtorsmaster.name,
68		currencies.currency,
69		currencies.decimalplaces,
70		paymentterms.terms,
71		debtorsmaster.creditlimit,
72		holdreasons.dissallowinvoices,
73		holdreasons.reasondescription,
74		SUM(debtortrans.ovamount + debtortrans.ovgst + debtortrans.ovfreight + debtortrans.ovdiscount - debtortrans.alloc) AS balance,
75		SUM(CASE WHEN (paymentterms.daysbeforedue > 0) THEN
76			CASE WHEN (TO_DAYS(Now()) - TO_DAYS(debtortrans.trandate)) >= paymentterms.daysbeforedue
77			THEN debtortrans.ovamount + debtortrans.ovgst + debtortrans.ovfreight + debtortrans.ovdiscount - debtortrans.alloc ELSE 0 END
78		ELSE
79			CASE WHEN TO_DAYS(Now()) - TO_DAYS(ADDDATE(last_day(debtortrans.trandate),paymentterms.dayinfollowingmonth)) >= 0 THEN debtortrans.ovamount + debtortrans.ovgst + debtortrans.ovfreight + debtortrans.ovdiscount - debtortrans.alloc ELSE 0 END
80		END) AS due,
81		SUM(CASE WHEN (paymentterms.daysbeforedue > 0) THEN
82			CASE WHEN TO_DAYS(Now()) - TO_DAYS(debtortrans.trandate) > paymentterms.daysbeforedue
83			AND TO_DAYS(Now()) - TO_DAYS(debtortrans.trandate) >= (paymentterms.daysbeforedue + " . $_SESSION['PastDueDays1'] . ")
84			THEN debtortrans.ovamount + debtortrans.ovgst + debtortrans.ovfreight + debtortrans.ovdiscount - debtortrans.alloc ELSE 0 END
85		ELSE
86			CASE WHEN TO_DAYS(Now()) - TO_DAYS(ADDDATE(last_day(debtortrans.trandate),paymentterms.dayinfollowingmonth)) >= " . $_SESSION['PastDueDays1'] . "
87			THEN debtortrans.ovamount + debtortrans.ovgst + debtortrans.ovfreight + debtortrans.ovdiscount
88			- debtortrans.alloc ELSE 0 END
89		END) AS overdue1,
90		SUM(CASE WHEN (paymentterms.daysbeforedue > 0) THEN
91			CASE WHEN TO_DAYS(Now()) - TO_DAYS(debtortrans.trandate) > paymentterms.daysbeforedue
92			AND TO_DAYS(Now()) - TO_DAYS(debtortrans.trandate) >= (paymentterms.daysbeforedue + " . $_SESSION['PastDueDays2'] . ") THEN debtortrans.ovamount + debtortrans.ovgst + debtortrans.ovfreight + debtortrans.ovdiscount - debtortrans.alloc ELSE 0 END
93		ELSE
94			CASE WHEN TO_DAYS(Now()) - TO_DAYS(ADDDATE(last_day(debtortrans.trandate),paymentterms.dayinfollowingmonth)) >= " . $_SESSION['PastDueDays2'] . " THEN debtortrans.ovamount + debtortrans.ovgst + debtortrans.ovfreight + debtortrans.ovdiscount - debtortrans.alloc ELSE 0 END
95		END) AS overdue2
96		FROM debtorsmaster,
97	 			paymentterms,
98	 			holdreasons,
99	 			currencies,
100	 			debtortrans
101		WHERE  debtorsmaster.paymentterms = paymentterms.termsindicator
102	 		AND debtorsmaster.currcode = currencies.currabrev
103	 		AND debtorsmaster.holdreason = holdreasons.reasoncode
104	 		AND debtorsmaster.debtorno = '" . $CustomerID . "'
105	 		AND debtorsmaster.debtorno = debtortrans.debtorno
106			GROUP BY debtorsmaster.name,
107			currencies.currency,
108			paymentterms.terms,
109			paymentterms.daysbeforedue,
110			paymentterms.dayinfollowingmonth,
111			debtorsmaster.creditlimit,
112			holdreasons.dissallowinvoices,
113			holdreasons.reasondescription";
114
115$ErrMsg = _('The customer details could not be retrieved by the SQL because');
116$CustomerResult = DB_query($SQL, $ErrMsg);
117
118if (DB_num_rows($CustomerResult) == 0) {
119
120	/*Because there is no balance - so just retrieve the header information about the customer - the choice is do one query to get the balance and transactions for those customers who have a balance and two queries for those who don't have a balance OR always do two queries - I opted for the former */
121
122	$NIL_BALANCE = True;
123
124	$SQL = "SELECT debtorsmaster.name,
125					debtorsmaster.currcode,
126					currencies.currency,
127					currencies.decimalplaces,
128					paymentterms.terms,
129					debtorsmaster.creditlimit,
130					holdreasons.dissallowinvoices,
131					holdreasons.reasondescription
132			FROM debtorsmaster INNER JOIN paymentterms
133			ON debtorsmaster.paymentterms = paymentterms.termsindicator
134			INNER JOIN currencies
135			ON debtorsmaster.currcode = currencies.currabrev
136			INNER JOIN holdreasons
137			ON debtorsmaster.holdreason = holdreasons.reasoncode
138			WHERE debtorsmaster.debtorno = '" . $CustomerID . "'";
139
140	$ErrMsg = _('The customer details could not be retrieved by the SQL because');
141	$CustomerResult = DB_query($SQL, $ErrMsg);
142
143} else {
144	$NIL_BALANCE = False;
145}
146
147$CustomerRecord = DB_fetch_array($CustomerResult);
148
149if ($NIL_BALANCE == True) {
150	$CustomerRecord['balance'] = 0;
151	$CustomerRecord['due'] = 0;
152	$CustomerRecord['overdue1'] = 0;
153	$CustomerRecord['overdue2'] = 0;
154}
155
156echo '<div class="noprint centre">
157		<a href="', $RootPath, '/SelectCustomer.php">', _('Back to Customer Screen'), '</a>
158	</div>';
159
160echo '<p class="page_title_text">
161		<img src="', $RootPath, '/css/', $Theme, '/images/customer.png" title="', _('Customer'), '" alt="" />', _('Customer'), ': ', stripslashes($CustomerID), ' - ', $CustomerRecord['name'], '<br />', _('All amounts stated in'), ': ', $CustomerRecord['currency'], '<br />', _('Terms'), ': ', $CustomerRecord['terms'], '<br />', _('Credit Limit'), ': ', locale_number_format($CustomerRecord['creditlimit'], 0), '<br />', _('Credit Status'), ': ', $CustomerRecord['reasondescription'], '
162	</p>';
163
164if ($CustomerRecord['dissallowinvoices'] != 0) {
165	echo '<br /><font color="red" size="4"><b>', _('ACCOUNT ON HOLD'), '</font></b><br />';
166}
167
168echo '<table class="selection" width="70%">
169	<tr>
170		<th style="width:20%">', _('Total Balance'), '</th>
171		<th style="width:20%">', _('Current'), '</th>
172		<th style="width:20%">', _('Now Due'), '</th>
173		<th style="width:20%">', $_SESSION['PastDueDays1'], '-', $_SESSION['PastDueDays2'], ' ' . _('Days Overdue'), '</th>
174		<th style="width:20%">', _('Over'), ' ', $_SESSION['PastDueDays2'], ' ', _('Days Overdue'), '</th>
175	</tr>';
176
177echo '<tr>
178		<td class="number">', locale_number_format($CustomerRecord['balance'], $CustomerRecord['decimalplaces']), '</td>
179		<td class="number">', locale_number_format(($CustomerRecord['balance'] - $CustomerRecord['due']), $CustomerRecord['decimalplaces']), '</td>
180		<td class="number">', locale_number_format(($CustomerRecord['due'] - $CustomerRecord['overdue1']), $CustomerRecord['decimalplaces']), '</td>
181		<td class="number">', locale_number_format(($CustomerRecord['overdue1'] - $CustomerRecord['overdue2']), $CustomerRecord['decimalplaces']), '</td>
182		<td class="number">', locale_number_format($CustomerRecord['overdue2'], $CustomerRecord['decimalplaces']), '</td>
183	</tr>
184</table>';
185
186echo '<div class="centre"><form onSubmit="return VerifyForm(this);" action="', htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8'), '" method="post" class="noPrint">
187		<input type="hidden" name="FormID" value="', $_SESSION['FormID'], '" />';
188echo _('Show all transactions after'), ':<input type="text" required="required" class="date" name="TransAfterDate" value="', $_POST['TransAfterDate'], '" maxlength="10" size="11" />';
189
190echo '<select name="Status">';
191if ($_POST['Status'] == '') {
192	echo '<option value="" selected="selected">', _('All'), '</option>';
193	echo '<option value="1">', _('Invoices not fully allocated'), '</option>';
194	echo '<option value="0">', _('Invoices fully allocated'), '</option>';
195} else {
196	if ($_POST['Status'] == 0) {
197		echo '<option value="">', _('All'), '</option>';
198		echo '<option value="1">', _('Invoices not fully allocated'), '</option>';
199		echo '<option selected="selected" value="0">', _('Invoices fully allocated'), '</option>';
200	} elseif ($_POST['Status'] == 1) {
201		echo '<option value="" selected="selected">', _('All'), '</option>';
202		echo '<option selected="selected" value="1">', _('Invoices not fully allocated'), '</option>';
203		echo '<option value="0">', _('Invoices fully allocated'), '</option>';
204	}
205}
206
207echo '</select>';
208echo '<input class="noprint" name="Refresh Inquiry" type="submit" value="', _('Refresh Inquiry'), '" />
209	</form></div>';
210
211$DateAfterCriteria = FormatDateForSQL($_POST['TransAfterDate']);
212
213$SQL = "SELECT systypes.typename,
214				debtortrans.id,
215				debtortrans.type,
216				debtortrans.transno,
217				debtortrans.branchcode,
218				debtortrans.trandate,
219				debtortrans.reference,
220				debtortrans.invtext,
221				debtortrans.order_,
222				salesorders.customerref,
223				debtortrans.rate,
224				(debtortrans.ovamount + debtortrans.ovgst + debtortrans.ovfreight + debtortrans.ovdiscount) AS totalamount,
225				debtortrans.alloc AS allocated
226			FROM debtortrans
227			INNER JOIN systypes
228				ON debtortrans.type = systypes.typeid
229			LEFT JOIN salesorders
230				ON salesorders.orderno=debtortrans.order_
231			WHERE debtortrans.debtorno = '" . $CustomerID . "'
232				AND debtortrans.trandate >= '" . $DateAfterCriteria . "'
233				ORDER BY debtortrans.trandate,
234					debtortrans.id";
235
236$ErrMsg = _('No transactions were returned by the SQL because');
237$TransResult = DB_query($SQL, $ErrMsg);
238
239if (DB_num_rows($TransResult) == 0) {
240	echo '<div class="centre">', _('There are no transactions to display since'), ' ', $_POST['TransAfterDate'], '</div>';
241	include('includes/footer.php');
242	exit;
243}
244
245/* Show a table of the invoices returned by the SQL. */
246
247echo '<table class="selection"><thead>
248	<tr>
249		<th class="ascending">', _('Type'), '</th>
250		<th class="ascending">', _('Number'), '</th>
251		<th class="ascending">', _('Date'), '</th>
252		<th>', _('Branch'), '</th>
253		<th class="ascending">', _('Reference'), '</th>
254		<th>', _('Comments'), '</th>
255		<th>', _('Order'), '</th>
256		<th>', _('Total'), '</th>
257		<th>', _('Allocated'), '</th>
258		<th>', _('Balance'), '</th>
259		<th class="noprint">', _('More Info'), '</th>
260		<th class="noprint">', _('More Info'), '</th>
261		<th class="noprint">', _('More Info'), '</th>
262		<th class="noprint">', _('More Info'), '</th>
263		<th class="noprint">', _('More Info'), '</th>
264	</tr>
265	</thead><tbody>';
266
267while ($MyRow = DB_fetch_array($TransResult)) {
268
269	$FormatedTranDate = ConvertSQLDate($MyRow['trandate']);
270
271	if ($_SESSION['InvoicePortraitFormat'] == 1) { //Invoice/credits in portrait
272		$PrintCustomerTransactionScript = 'PrintCustTransPortrait.php';
273	} else { //produce pdfs in landscape
274		$PrintCustomerTransactionScript = 'PrintCustTrans.php';
275	}
276
277	/* if the user is allowed to create credits for invoices */
278	if (in_array($_SESSION['PageSecurityArray']['Credit_Invoice.php'], $_SESSION['AllowedPageSecurityTokens']) and $MyRow['type'] == 10) {
279		if ($_SESSION['CompanyRecord']['gllink_debtors'] == 1 and in_array($_SESSION['PageSecurityArray']['GLTransInquiry.php'], $_SESSION['AllowedPageSecurityTokens'])) {
280			/* Show transactions where:
281			 * - Is invoice
282			 * - User can raise credits
283			 * - User can view GL transactions
284			 */
285			echo '<tr class="striped_row">
286					<td>', _($MyRow['typename']), '</td>
287					<td><a href="' . $RootPath . '/CustWhereAlloc.php?TransType=' . $MyRow['type'] . '&TransNo=' . $MyRow['transno'] . '" target="_blank">' . $MyRow['transno'] . '</a></td>
288					<td>', ConvertSQLDate($MyRow['trandate']), '</td>
289					<td>', $MyRow['branchcode'], '</td>
290					<td>', $MyRow['reference'], '</td>
291					<td style="width:200px">', $MyRow['invtext'], '</td>
292					<td>', $MyRow['order_'], '</td>
293					<td class="number">', locale_number_format($MyRow['totalamount'], $CustomerRecord['decimalplaces']), '</td>
294					<td class="number">', locale_number_format($MyRow['allocated'], $CustomerRecord['decimalplaces']), '</td>
295					<td class="number">', locale_number_format($MyRow['totalamount'] - $MyRow['allocated'], $CustomerRecord['decimalplaces']), '</td>
296					<td class="noprint">
297						<a href="', $RootPath, '/Credit_Invoice.php?InvoiceNumber=', $MyRow['transno'], '" title="', _('Click to credit the invoice'), '">
298							<img alt="" src="', $RootPath, '/css/', $Theme, '/images/credit.png" /> ',
299							_('Credit'), '
300						</a>
301					</td>
302					<td class="noprint">
303						<a href="', $RootPath, '/PrintCustTrans.php?FromTransNo=', $MyRow['transno'], '&amp;InvOrCredit=Invoice" title="', _('Click to preview the invoice'), '">
304							<img alt="" src="', $RootPath, '/css/', $Theme, '/images/preview.png" /> ',
305							_('HTML'), '
306						</a>
307					</td>
308					<td class="noprint">
309						<a href="', $RootPath, '/', $PrintCustomerTransactionScript, '?FromTransNo=', $MyRow['transno'], '&amp;InvOrCredit=Invoice&amp;PrintPDF=True" title="', _('Click for PDF'), '">
310							<img alt="" src="', $RootPath, '/css/', $Theme, '/images/pdf.png" /> ',
311							_('PDF'), '
312						</a>
313					</td>
314					<td class="noprint">
315						<a href="', $RootPath, '/EmailCustTrans.php?FromTransNo=', $MyRow['transno'], '&amp;InvOrCredit=Invoice" title="', _('Click to email the invoice'), '">
316							<img alt="" src="', $RootPath, '/css/', $Theme, '/images/email.png" /> ', _('Email'), '
317						</a>
318					</td>
319					<td class="noprint">
320						<a href="', $RootPath, '/GLTransInquiry.php?TypeID=', $MyRow['type'], '&amp;TransNo=', $MyRow['transno'], '" title="', _('Click to view the GL entries'), '">
321							<img alt="" src="', $RootPath, '/css/', $Theme, '/images/gl.png" /> ',
322							_('GL Entries'), '
323						</a>
324					</td>
325				</tr>';
326		} else {
327			/* Show transactions where:
328			 * - Is invoice
329			 * - User can raise credits
330			 * - User cannot view GL transactions
331			 */
332			echo '<tr class="striped_row">
333					<td>', _($MyRow['typename']), '</td>
334					<td><a href="' . $RootPath . '/CustWhereAlloc.php?TransType=' . $MyRow['type'] . '&TransNo=' . $MyRow['transno'] . '">' . $MyRow['transno'] . '</a></td>
335					<td>', ConvertSQLDate($MyRow['trandate']), '</td>
336					<td>', $MyRow['branchcode'], '</td>
337					<td>', $MyRow['reference'], '</td>
338					<td style="width:200px">', $MyRow['invtext'], '</td>
339					<td>', $MyRow['order_'], '</td>
340					<td class="number">', locale_number_format($MyRow['totalamount'], $CustomerRecord['decimalplaces']), '</td>
341					<td class="number">', locale_number_format($MyRow['allocated'], $CustomerRecord['decimalplaces']), '</td>
342					<td class="number">', locale_number_format($MyRow['totalamount'] - $MyRow['allocated'], $CustomerRecord['decimalplaces']), '</td>
343					<td class="noprint">
344						<a href="', $RootPath, '/Credit_Invoice.php?InvoiceNumber=', $MyRow['transno'], '" title="', _('Click to credit the invoice'), '">
345							<img alt="" src="', $RootPath, '/css/', $Theme, '/images/credit.png" /> ',
346							_('Credit'), '
347						</a>
348					</td>
349					<td class="noprint">
350						<a href="', $RootPath, '/PrintCustTrans.php?FromTransNo=', $MyRow['transno'], '&amp;InvOrCredit=Invoice" title="', _('Click to preview the invoice'), '">
351							<img alt="" src="', $RootPath, '/css/', $Theme, '/images/preview.png" /> ',
352							_('HTML'), '
353						</a>
354					</td>
355					<td class="noprint">
356						<a href="', $RootPath, '/', $PrintCustomerTransactionScript, '?FromTransNo=', $MyRow['transno'], '&amp;InvOrCredit=Invoice&amp;PrintPDF=True" title="', _('Click for PDF'), '">
357							<img alt="" src="', $RootPath, '/css/', $Theme, '/images/pdf.png" /> ',
358							_('PDF'), '
359						</a>
360					</td>
361					<td class="noprint">
362						<a href="', $RootPath, '/EmailCustTrans.php?FromTransNo=', $MyRow['transno'], '&amp;InvOrCredit=Invoice" title="', _('Click to email the invoice'), '">
363							<img alt="" src="', $RootPath, '/css/', $Theme, '/images/email.png" /> ', _('Email'), '
364						</a>
365					</td>
366					<td class="noprint">&nbsp;</td>
367				</tr>';
368
369		}
370
371	} elseif ($MyRow['type'] == 10) {
372		/* Show transactions where:
373		 * - Is invoice
374		 * - User cannot raise credits
375		 * - User cannot view GL transactions
376		 */
377		echo '<tr class="striped_row">
378				<td>', _($MyRow['typename']), '</td>
379				<td>', $MyRow['transno'], '</td>
380				<td>', ConvertSQLDate($MyRow['trandate']), '</td>
381				<td>', $MyRow['branchcode'], '</td>
382				<td>', $MyRow['reference'], '</td>
383				<td style="width:200px">', $MyRow['invtext'], '</td>
384				<td>', $MyRow['order_'], '</td>
385				<td class="number">', locale_number_format($MyRow['totalamount'], $CustomerRecord['decimalplaces']), '</td>
386				<td class="number">', locale_number_format($MyRow['allocated'], $CustomerRecord['decimalplaces']), '</td>
387				<td class="number">', locale_number_format($MyRow['totalamount'] - $MyRow['allocated'], $CustomerRecord['decimalplaces']), '</td>
388				<td class="noprint">&nbsp;</td>
389				<td class="noprint">
390					<a href="', $RootPath, '/PrintCustTrans.php?FromTransNo=', $MyRow['transno'], '&amp;InvOrCredit=Invoice" title="', _('Click to preview the invoice'), '">
391						<img alt="" src="', $RootPath, '/css/', $Theme, '/images/preview.png" /> ',
392						_('HTML'), '
393					</a>
394				</td>
395				<td class="noprint">
396					<a href="', $RootPath, '/', $PrintCustomerTransactionScript, '?FromTransNo=', $MyRow['transno'], '&amp;InvOrCredit=Invoice&amp;PrintPDF=True" title="', _('Click for PDF'), '">
397						<img alt="" src="', $RootPath, '/css/', $Theme, '/images/pdf.png" /> ',
398						_('PDF'), '
399					</a>
400				</td>
401				<td class="noprint">
402					<a href="', $RootPath, '/EmailCustTrans.php?FromTransNo=', $MyRow['transno'], '&amp;InvOrCredit=Invoice" title="', _('Click to email the invoice'), '">
403						<img alt="" src="', $RootPath, '/css/', $Theme, '/images/email.png" /> ', _('Email'), '
404					</a>
405				</td>
406				<td class="noprint">&nbsp;</td>
407			</tr>';
408
409	} elseif ($MyRow['type'] == 11) {
410		/* Show transactions where:
411		 * - Is credit note
412		 * - User can view GL transactions
413		 */
414		if ($_SESSION['CompanyRecord']['gllink_debtors'] == 1 and in_array($_SESSION['PageSecurityArray']['GLTransInquiry.php'], $_SESSION['AllowedPageSecurityTokens'])) {
415			echo '<tr class="striped_row">
416					<td>', _($MyRow['typename']), '</td>
417					<td><a href="' . $RootPath . '/CustWhereAlloc.php?TransType=' . $MyRow['type'] . '&TransNo=' . $MyRow['transno'] . '">' . $MyRow['transno'] . '</a></td>
418					<td>', ConvertSQLDate($MyRow['trandate']), '</td>
419					<td>', $MyRow['branchcode'], '</td>
420					<td>', $MyRow['reference'], '</td>
421					<td style="width:200px">', $MyRow['invtext'], '</td>
422					<td>', $MyRow['order_'], '</td>
423					<td class="number">', locale_number_format($MyRow['totalamount'], $CustomerRecord['decimalplaces']), '</td>
424					<td class="number">', locale_number_format($MyRow['allocated'], $CustomerRecord['decimalplaces']), '</td>
425					<td class="number">', locale_number_format($MyRow['totalamount'] - $MyRow['allocated'], $CustomerRecord['decimalplaces']), '</td>
426					<td class="noprint">
427						<a href="', $RootPath, '/PrintCustTrans.php?FromTransNo=', $MyRow['transno'], '&amp;InvOrCredit=Credit" title="', _('Click to preview the credit note'), '">
428							<img alt="" src="', $RootPath, '/css/', $Theme, '/images/preview.png" /> ',
429							_('HTML'), '
430						</a>
431					</td>
432					<td class="noprint">
433						<a href="', $RootPath, '/', $PrintCustomerTransactionScript, '?FromTransNo=', $MyRow['transno'], '&amp;InvOrCredit=Credit&amp;PrintPDF=True" title="', _('Click for PDF'), '">
434							<img alt="" src="', $RootPath, '/css/', $Theme, '/images/pdf.png" /> ',
435							_('PDF'), '
436						</a>
437					</td>
438					<td class="noprint">
439						<a href="', $RootPath, '/EmailCustTrans.php?FromTransNo=', $MyRow['transno'], '&amp;InvOrCredit=Credit">', _('Email'), '
440							<img src="', $RootPath, '/css/', $Theme, '/images/email.png" title="', _('Click to email the credit note'), '" alt="" />
441						</a>
442					</td>
443					<td class="noprint">
444						<a href="', $RootPath, '/CustomerAllocations.php?AllocTrans=', $MyRow['id'], '" title="', _('Click to allocate funds'), '">
445							<img alt="" src="', $RootPath, '/css/', $Theme, '/images/allocation.png" /> ',
446							_('Allocation'), '
447						</a>
448					</td>
449					<td class="noprint">
450						<a href="', $RootPath, '/GLTransInquiry.php?TypeID=', $MyRow['type'], '&amp;TransNo=', $MyRow['transno'], '" title="', _('Click to view the GL entries'), '">
451							<img alt="" src="', $RootPath, '/css/', $Theme, '/images/gl.png" /> ',
452							_('GL Entries'), '
453						</a>
454					</td>
455				</tr>';
456
457		} else {
458			/* Show transactions where:
459			* - Is credit note
460			* - User cannot view GL transactions
461			*/
462			echo '<tr class="striped_row">
463					<td>', _($MyRow['typename']), '</td>
464					<td><a href="' . $RootPath . '/CustWhereAlloc.php?TransType=' . $MyRow['type'] . '&TransNo=' . $MyRow['transno'] . '">' . $MyRow['transno'] . '</a></td>
465					<td>', ConvertSQLDate($MyRow['trandate']), '</td>
466					<td>', $MyRow['branchcode'], '</td>
467					<td>', $MyRow['reference'], '</td>
468					<td style="width:200px">', $MyRow['invtext'], '</td>
469					<td>', $MyRow['order_'], '</td>
470					<td class="number">', locale_number_format($MyRow['totalamount'], $CustomerRecord['decimalplaces']), '</td>
471					<td class="number">', locale_number_format($MyRow['allocated'], $CustomerRecord['decimalplaces']), '</td>
472					<td class="number">', locale_number_format($MyRow['totalamount'] - $MyRow['allocated'], $CustomerRecord['decimalplaces']), '</td>
473					<td class="noprint">
474						<a href="', $RootPath, '/PrintCustTrans.php?FromTransNo=', $MyRow['transno'], '&amp;InvOrCredit=Credit" title="', _('Click to preview the credit note'), '">
475							<img alt="" src="', $RootPath, '/css/', $Theme, '/images/preview.png" /> ',
476							_('HTML'), '
477						</a>
478					</td>
479					<td class="noprint">
480						<a href="', $RootPath, '/', $PrintCustomerTransactionScript, '?FromTransNo=', $MyRow['transno'], '&amp;InvOrCredit=Credit&amp;PrintPDF=True" title="', _('Click for PDF'), '">
481							<img alt="" src="', $RootPath, '/css/', $Theme, '/images/pdf.png" /> ',
482							_('PDF'), '
483						</a>
484					</td>
485					<td class="noprint">
486						<a href="', $RootPath, '/EmailCustTrans.php?FromTransNo=', $MyRow['transno'], '&amp;InvOrCredit=Credit">', _('Email'), '
487							<img src="', $RootPath, '/css/', $Theme, '/images/email.png" title="', _('Click to email the credit note'), '" alt="" />
488						</a>
489					</td>
490					<td class="noprint">
491						<a href="', $RootPath, '/CustomerAllocations.php?AllocTrans=', $MyRow['id'], '" title="', _('Click to allocate funds'), '">
492							<img alt="" src="', $RootPath, '/css/', $Theme, '/images/allocation.png" /> ',
493							_('Allocation'), '
494						</a>
495					</td>
496					<td class="noprint">&nbsp;</td>
497				</tr>';
498
499		}
500	} elseif ($MyRow['type'] == 12 and $MyRow['totalamount'] < 0) {
501		/* Show transactions where:
502		 * - Is receipt
503		 * - User can view GL transactions
504		 */
505		if ($_SESSION['CompanyRecord']['gllink_debtors'] == 1 and in_array($_SESSION['PageSecurityArray']['GLTransInquiry.php'], $_SESSION['AllowedPageSecurityTokens'])) {
506			echo '<tr class="striped_row">
507					<td>', _($MyRow['typename']), '</td>
508					<td><a href="' . $RootPath . '/CustWhereAlloc.php?TransType=' . $MyRow['type'] . '&TransNo=' . $MyRow['transno'] . '">' . $MyRow['transno'] . '</a></td>
509					<td>', ConvertSQLDate($MyRow['trandate']), '</td>
510					<td>', $MyRow['branchcode'], '</td>
511					<td>', $MyRow['reference'], '</td>
512					<td style="width:200px">', $MyRow['invtext'], '</td>
513					<td>', $MyRow['order_'], '</td>
514					<td class="number">', locale_number_format($MyRow['totalamount'], $CustomerRecord['decimalplaces']), '</td>
515					<td class="number">', locale_number_format($MyRow['allocated'], $CustomerRecord['decimalplaces']), '</td>
516					<td class="number">', locale_number_format($MyRow['totalamount'] - $MyRow['allocated'], $CustomerRecord['decimalplaces']), '</td>
517					<td class="noprint">
518						<a href="', $RootPath, '/CustomerAllocations.php?AllocTrans=', $MyRow['id'], '" title="', _('Click to allocate funds'), '">
519							<img alt="" src="', $RootPath, '/css/', $Theme, '/images/allocation.png" /> ',
520							_('Allocation'), '
521						</a>
522					</td>
523					<td class="noprint">&nbsp;</td>
524					<td class="noprint">&nbsp;</td>
525					<td class="noprint">&nbsp;</td>
526					<td class="noprint">
527						<a href="', $RootPath, '/GLTransInquiry.php?TypeID=', $MyRow['type'], '&amp;TransNo=', $MyRow['transno'], '" title="', _('Click to view the GL entries'), '">
528							<img alt="" src="', $RootPath, '/css/', $Theme, '/images/gl.png" /> ',
529							_('GL Entries'), '
530						</a>
531					</td>
532				</tr>';
533
534		} else { //no permission for GLTrans Inquiries
535		/* Show transactions where:
536		 * - Is credit note
537		 * - User cannot view GL transactions
538		 */
539			echo '<tr class="striped_row">
540					<td>', _($MyRow['typename']), '</td>
541					<td>', $MyRow['transno'], '</td>
542					<td>', ConvertSQLDate($MyRow['trandate']), '</td>
543					<td>', $MyRow['branchcode'], '</td>
544					<td>', $MyRow['reference'], '</td>
545					<td style="width:200px">', $MyRow['invtext'], '</td>
546					<td>', $MyRow['order_'], '</td>
547					<td class="number">', locale_number_format($MyRow['totalamount'], $CustomerRecord['decimalplaces']), '</td>
548					<td class="number">', locale_number_format($MyRow['allocated'], $CustomerRecord['decimalplaces']), '</td>
549					<td class="number">', locale_number_format($MyRow['totalamount'] - $MyRow['allocated'], $CustomerRecord['decimalplaces']), '</td>
550					<td class="noprint">
551						<a href="', $RootPath, '/CustomerAllocations.php?AllocTrans=', $MyRow['id'], '" title="', _('Click to allocate funds'), '">
552							<img alt="" src="', $RootPath, '/css/', $Theme, '/images/allocation.png" /> ',
553							_('Allocation'), '
554						</a>
555					</td>
556					<td class="noprint">&nbsp;</td>
557					<td class="noprint">&nbsp;</td>
558					<td class="noprint">&nbsp;</td>
559					<td class="noprint">&nbsp;</td>
560				</tr>';
561
562		}
563	} elseif ($MyRow['type'] == 12 and $MyRow['totalamount'] > 0) {
564		if ($_SESSION['CompanyRecord']['gllink_debtors'] == 1 and in_array($_SESSION['PageSecurityArray']['GLTransInquiry.php'], $_SESSION['AllowedPageSecurityTokens'])) {
565			/* Show transactions where:
566			* - Is a negative receipt
567			* - User can view GL transactions
568			*/
569			echo '<tr class="striped_row">
570					<td>', _($MyRow['typename']), '</td>
571					<td>', $MyRow['transno'], '</td>
572					<td>', ConvertSQLDate($MyRow['trandate']), '</td>
573					<td>', $MyRow['branchcode'], '</td>
574					<td>', $MyRow['reference'], '</td>
575					<td style="width:200px">', $MyRow['invtext'], '</td>
576					<td>', $MyRow['order_'], '</td>
577					<td class="number">', locale_number_format($MyRow['totalamount'], $CustomerRecord['decimalplaces']), '</td>
578					<td class="number">', locale_number_format($MyRow['allocated'], $CustomerRecord['decimalplaces']), '</td>
579					<td class="number">', locale_number_format($MyRow['totalamount'] - $MyRow['allocated'], $CustomerRecord['decimalplaces']), '</td>
580					<td class="noprint">&nbsp;</td>
581					<td class="noprint">&nbsp;</td>
582					<td class="noprint">&nbsp;</td>
583					<td class="noprint">&nbsp;</td>
584					<td class="noprint">
585						<a href="', $RootPath, '/GLTransInquiry.php?TypeID=', $MyRow['type'], '&amp;TransNo=', $MyRow['transno'], '" title="', _('Click to view the GL entries'), '">
586							<img alt="" src="', $RootPath, '/css/', $Theme, '/images/gl.png" /> ',
587							_('GL Entries'), '
588						</a>
589					</td>
590				</tr>';
591
592		} else {
593			/* Show transactions where:
594			* - Is a negative receipt
595			* - User cannot view GL transactions
596			*/
597			echo '<tr class="striped_row">
598					<td>', _($MyRow['typename']), '</td>
599					<td>', $MyRow['transno'], '</td>
600					<td>', ConvertSQLDate($MyRow['trandate']), '</td>
601					<td>', $MyRow['branchcode'], '</td>
602					<td>', $MyRow['reference'], '</td>
603					<td style="width:200px">', $MyRow['invtext'], '</td>
604					<td>', $MyRow['order_'], '</td>
605					<td class="number">', locale_number_format($MyRow['totalamount'], $CustomerRecord['decimalplaces']), '</td>
606					<td class="number">', locale_number_format($MyRow['allocated'], $CustomerRecord['decimalplaces']), '</td>
607					<td class="number">', locale_number_format($MyRow['totalamount'] - $MyRow['allocated'], $CustomerRecord['decimalplaces']), '</td>
608					<td class="noprint">&nbsp;</td>
609					<td class="noprint">&nbsp;</td>
610					<td class="noprint">&nbsp;</td>
611					<td class="noprint">&nbsp;</td>
612					<td class="noprint">&nbsp;</td>
613				</tr>';
614		}
615	} else {
616		if ($_SESSION['CompanyRecord']['gllink_debtors'] == 1 and in_array($_SESSION['PageSecurityArray']['GLTransInquiry.php'], $_SESSION['AllowedPageSecurityTokens'])) {
617			/* Show transactions where:
618			* - Is a misc transaction
619			* - User can view GL transactions
620			*/
621			echo '<tr class="striped_row">
622					<td>', _($MyRow['typename']), '</td>
623					<td>', $MyRow['transno'], '</td>
624					<td>', ConvertSQLDate($MyRow['trandate']), '</td>
625					<td>', $MyRow['branchcode'], '</td>
626					<td>', $MyRow['reference'], '</td>
627					<td style="width:200px">', $MyRow['invtext'], '</td>
628					<td>', $MyRow['order_'], '</td>
629					<td class="number">', locale_number_format($MyRow['totalamount'], $CustomerRecord['decimalplaces']), '</td>
630					<td class="number">', locale_number_format($MyRow['allocated'], $CustomerRecord['decimalplaces']), '</td>
631					<td class="number">', locale_number_format($MyRow['totalamount'] - $MyRow['allocated'], $CustomerRecord['decimalplaces']), '</td>
632					<td class="noprint">&nbsp;</td>
633					<td class="noprint">&nbsp;</td>
634					<td class="noprint">&nbsp;</td>
635					<td class="noprint">&nbsp;</td>
636					<td class="noprint">
637						<a href="', $RootPath, '/GLTransInquiry.php?TypeID=', $MyRow['type'], '&amp;TransNo=', $MyRow['transno'], '" title="', _('Click to view the GL entries'), '">
638							<img alt="" src="', $RootPath, '/css/', $Theme, '/images/gl.png" /> ',
639							_('GL Entries'), '
640						</a>
641					</td>
642				</tr>';
643
644		} else {
645			/* Show transactions where:
646			* - Is a misc transaction
647			* - User cannot view GL transactions
648			*/
649			echo '<tr class="striped_row">
650					<td>', $MyRow['typename'], '</td>
651					<td>', $MyRow['transno'], '</td>
652					<td>', ConvertSQLDate($MyRow['trandate']), '</td>
653					<td>', $MyRow['branchcode'], '</td>
654					<td>', $MyRow['reference'], '</td>
655					<td style="width:200px">', $MyRow['invtext'], '</td>
656					<td>', $MyRow['order_'], '</td>
657					<td class="number">', locale_number_format($MyRow['totalamount'], $CustomerRecord['decimalplaces']), '</td>
658					<td class="number">', locale_number_format($MyRow['allocated'], $CustomerRecord['decimalplaces']), '</td>
659					<td class="number">', locale_number_format($MyRow['totalamount'] - $MyRow['allocated'], $CustomerRecord['decimalplaces']), '</td>
660					<td class="noprint">&nbsp;</td>
661					<td class="noprint">&nbsp;</td>
662					<td class="noprint">&nbsp;</td>
663					<td class="noprint">&nbsp;</td>
664					<td class="noprint">&nbsp;</td>
665				</tr>';
666		}
667	}
668
669}
670//end of while loop
671
672echo '</tbody></table>';
673include('includes/footer.php');
674?>
675