1<?php
2/* This script is to view the items purchased by a customer. */
3
4include('includes/session.php');
5$Title = _('Customer Purchases');// Screen identificator.
6$ViewTopic = 'ARInquiries';// Filename's id in ManualContents.php's TOC.
7/* This help needs to be writing...
8$BookMark = 'CustomerPurchases';// Anchor's id in the manual's html document.*/
9include('includes/header.php');
10
11if(isset($_GET['DebtorNo'])) {
12	$DebtorNo = $_GET['DebtorNo'];// Set DebtorNo from $_GET['DebtorNo'].
13} elseif(isset($_POST['DebtorNo'])) {
14	$DebtorNo = $_POST['DebtorNo'];// Set DebtorNo from $_POST['DebtorNo'].
15} else {
16	prnMsg(_('This script must be called with a customer code.'), 'info');
17	include('includes/footer.php');
18	exit;
19}
20
21$SQL = "SELECT debtorsmaster.name,
22				custbranch.brname
23		FROM debtorsmaster
24		INNER JOIN custbranch
25			ON debtorsmaster.debtorno=custbranch.debtorno
26		WHERE debtorsmaster.debtorno = '" . $DebtorNo . "'";
27
28$ErrMsg = _('The customer details could not be retrieved by the SQL because');
29$CustomerResult = DB_query($SQL, $ErrMsg);
30$CustomerRecord = DB_fetch_array($CustomerResult);
31
32echo '<p class="page_title_text"><img alt="" src="'.$RootPath.'/css/'.$Theme.
33	'/images/customer.png" title="' .
34	_('Customer') . '" /> ' .// Icon title.
35	_('Items Purchased by Customer') . '<br />' . $DebtorNo . " - " . $CustomerRecord['name'] . '</p>';// Page title.
36
37$SQL = "SELECT stockmoves.stockid,
38			stockmaster.description,
39			stockmaster.units,
40			systypes.typename,
41			transno,
42			locations.locationname,
43			trandate,
44			stockmoves.branchcode,
45			price,
46			reference,
47			qty,
48			discountpercent,
49			narrative
50		FROM stockmoves
51		INNER JOIN stockmaster
52			ON stockmaster.stockid=stockmoves.stockid
53		INNER JOIN systypes
54			ON stockmoves.type=systypes.typeid
55		INNER JOIN locations
56			ON stockmoves.loccode=locations.loccode
57		INNER JOIN locationusers ON locationusers.loccode=locations.loccode AND locationusers.userid='" .  $_SESSION['UserID'] . "' AND locationusers.canview=1";
58
59$SQLWhere=" WHERE stockmoves.debtorno='" . $DebtorNo . "'";
60
61if ($_SESSION['SalesmanLogin'] != '') {
62	$SQL .= " INNER JOIN custbranch
63				ON stockmoves.branchcode=custbranch.branchcode";
64	$SQLWhere .= " AND custbranch.salesman='" . $_SESSION['SalesmanLogin'] . "'";
65}
66
67$SQL .= $SQLWhere . " ORDER BY trandate DESC";
68
69$ErrMsg = _('The stock movement details could not be retrieved by the SQL because');
70$StockMovesResult = DB_query($SQL, $ErrMsg);
71
72if (DB_num_rows($StockMovesResult) == 0) {
73	echo '<br />';
74	prnMsg(_('There are no items for this customer'), 'notice');
75	echo '<br />';
76} //DB_num_rows($StockMovesResult) == 0
77else {
78	echo '<table class="selection">
79			<tr>
80				<th>' . _('Transaction Date') . '</th>
81				<th>' . _('Stock ID') . '</th>
82				<th>' . _('Description') . '</th>
83				<th>' . _('Type') . '</th>
84				<th>' . _('Transaction No.') . '</th>
85				<th>' . _('From Location') . '</th>
86				<th>' . _('Branch Code') . '</th>
87				<th>' . _('Quantity') . '</th>
88				<th>' . _('Unit') . '</th>
89				<th>' . _('Price') . '</th>
90				<th>' . _('Discount') . '</th>
91				<th>' . _('Total') . '</th>
92				<th>' . _('Reference') . '</th>
93				<th>' . _('Narrative') . '</th>
94			</tr>';
95
96	while ($StockMovesRow = DB_fetch_array($StockMovesResult)) {
97		echo '<tr>
98				<td>' . ConvertSQLDate($StockMovesRow['trandate']) . '</td>
99				<td>' . $StockMovesRow['stockid'] . '</td>
100				<td>' . $StockMovesRow['description'] . '</td>
101				<td>' . _($StockMovesRow['typename']) . '</td>
102				<td class="number">' . $StockMovesRow['transno'] . '</td>
103				<td>' . $StockMovesRow['locationname'] . '</td>
104				<td>' . $StockMovesRow['branchcode'] . '</td>
105				<td class="number">' . -$StockMovesRow['qty'] . '</td>
106				<td>' . $StockMovesRow['units'] . '</td>
107				<td class="number">' . locale_number_format($StockMovesRow['price'] * (1 - $StockMovesRow['discountpercent']), $_SESSION['CompanyRecord']['decimalplaces']) . '</td>
108				<td class="number">' . locale_number_format(($StockMovesRow['discountpercent'] * 100),2) . '%' . '</td>
109				<td class="number">' . locale_number_format((-$StockMovesRow['qty'] * $StockMovesRow['price'] * (1 - $StockMovesRow['discountpercent'])), $_SESSION['CompanyRecord']['decimalplaces']) . '</td>
110				<td class="number">' . $StockMovesRow['reference'] . '</td>
111				<td>' . $StockMovesRow['narrative'] . '</td>
112			</tr>';
113
114	} //$StockMovesRow = DB_fetch_array($StockMovesResult)
115
116	echo '</table>';
117}
118
119echo '<br /><div class="centre"><a href="SelectCustomer.php">' . _('Return to customer selection screen') . '</a></div><br />';
120
121include('includes/footer.php');
122?>
123