1<?php
2
3
4include('includes/session.php');
5
6$Title = _('Authorise Internal Stock Requests');
7$ViewTopic = 'Inventory';
8$BookMark = 'AuthoriseRequest';
9
10include('includes/header.php');
11
12echo '<p class="page_title_text"><img src="'.$RootPath.'/css/'.$Theme.'/images/transactions.png" title="' . $Title . '" alt="" />' . ' ' . $Title . '</p>';
13
14if (isset($_POST['UpdateAll'])) {
15	foreach ($_POST as $POSTVariableName => $POSTValue) {
16		if (mb_substr($POSTVariableName,0,6)=='status') {
17			$RequestNo=mb_substr($POSTVariableName,6);
18			$sql="UPDATE stockrequest
19					SET authorised='1'
20					WHERE dispatchid='" . $RequestNo . "'";
21			$result=DB_query($sql);
22		}
23		if (strpos($POSTVariableName, 'cancel')) {
24 			$CancelItems = explode('cancel', $POSTVariableName);
25 			$sql = "UPDATE stockrequestitems
26 						SET completed=1
27 						WHERE dispatchid='" . $CancelItems[0] . "'
28 						AND dispatchitemsid='" . $CancelItems[1] . "'";
29 			$result = DB_query($sql);
30 			$result = DB_query("SELECT stockid FROM stockrequestitems WHERE completed=0 AND dispatchid='" . $CancelItems[0] . "'");
31 			if (DB_num_rows($result) ==0){
32				$result = DB_query("UPDATE stockrequest
33									SET authorised='1'
34									WHERE dispatchid='" . $CancelItems[0] . "'");
35			}
36
37 		}
38	}
39}
40
41/* Retrieve the requisition header information
42 */
43$sql="SELECT stockrequest.dispatchid,
44			locations.locationname,
45			stockrequest.despatchdate,
46			stockrequest.narrative,
47			departments.description,
48			www_users.realname,
49			www_users.email
50		FROM stockrequest INNER JOIN departments
51			ON stockrequest.departmentid=departments.departmentid
52		INNER JOIN locations
53			ON stockrequest.loccode=locations.loccode
54		INNER JOIN locationusers ON locationusers.loccode=locations.loccode AND locationusers.userid='" .  $_SESSION['UserID'] . "' AND locationusers.canupd=1
55		INNER JOIN www_users
56			ON www_users.userid=departments.authoriser
57		WHERE stockrequest.authorised=0
58		AND stockrequest.closed=0
59		AND www_users.userid='".$_SESSION['UserID']."'";
60$result=DB_query($sql);
61
62echo '<form method="post" action="' . htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '">';
63echo '<div>';
64echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
65echo '<table class="selection">
66	<tr>
67		<th>' . _('Request Number') . '</th>
68		<th>' . _('Department') . '</th>
69		<th>' . _('Location Of Stock') . '</th>
70		<th>' . _('Requested Date') . '</th>
71		<th>' . _('Narrative') . '</th>
72		<th>' . _('Authorise') . '</th>
73	</tr>';
74
75while ($myrow=DB_fetch_array($result)) {
76
77	echo '<tr>
78			<td>' . $myrow['dispatchid'] . '</td>
79			<td>' . $myrow['description'] . '</td>
80			<td>' . $myrow['locationname'] . '</td>
81			<td>' . ConvertSQLDate($myrow['despatchdate']) . '</td>
82			<td>' . $myrow['narrative'] . '</td>
83			<td><input type="checkbox" name="status'.$myrow['dispatchid'].'" /></td>
84		</tr>';
85	$LinesSQL="SELECT stockrequestitems.dispatchitemsid,
86						stockrequestitems.stockid,
87						stockrequestitems.decimalplaces,
88						stockrequestitems.uom,
89						stockmaster.description,
90						stockrequestitems.quantity
91				FROM stockrequestitems
92				INNER JOIN stockmaster
93				ON stockmaster.stockid=stockrequestitems.stockid
94			WHERE dispatchid='".$myrow['dispatchid'] . "'
95			AND completed=0";
96	$LineResult=DB_query($LinesSQL);
97
98	echo '<tr>
99			<td></td>
100			<td colspan="5" align="left">
101				<table class="selection" align="left">
102				<tr>
103					<th>' . _('Product') . '</th>
104					<th>' . _('Quantity Required') . '</th>
105					<th>' . _('Units') . '</th>
106					<th>' . _('Cancel Line') . '</th>
107				</tr>';
108
109	while ($LineRow=DB_fetch_array($LineResult)) {
110		echo '<tr>
111				<td>' . $LineRow['description'] . '</td>
112				<td class="number">' . locale_number_format($LineRow['quantity'],$LineRow['decimalplaces']) . '</td>
113				<td>' . $LineRow['uom'] . '</td>
114				<td><input type="checkbox" name="' . $myrow['dispatchid'] . 'cancel' . $LineRow['dispatchitemsid'] . '" /></td
115			</tr>';
116	} // end while order line detail
117	echo '</table>
118			</td>
119		</tr>';
120} //end while header loop
121echo '</table>';
122echo '<br /><div class="centre"><input type="submit" name="UpdateAll" value="' . _('Update'). '" /></div>
123      </div>
124      </form>';
125
126include('includes/footer.php');
127?>