1<?php
2
3
4/**
5If the User has selected Keyed Entry, show them this special select list...
6it is just in the way if they are doing file imports
7it also would not be applicable in a PO and possible other situations...
8**/
9if ($_POST['EntryType'] == 'KEYED'){
10	/*Also a multi select box for adding bundles to the dispatch without keying */
11
12	$sql = "SELECT serialno,
13				quantity,
14			(SELECT SUM(moveqty)
15				FROM pickserialdetails
16				INNER JOIN pickreqdetails on pickreqdetails.detailno=pickserialdetails.detailno
17				INNER JOIN pickreq on pickreq.prid=pickreqdetails.prid
18				AND pickreq.closed=0
19				WHERE pickserialdetails.serialno=stockserialitems.serialno
20				AND pickserialdetails.stockid=stockserialitems.stockid) as qtypickedtotal,
21			(SELECT SUM(moveqty)
22				FROM pickserialdetails
23				INNER JOIN pickreqdetails on pickreqdetails.detailno=pickserialdetails.detailno
24				INNER JOIN pickreq on pickreq.prid=pickreqdetails.prid
25				AND pickreq.orderno='" . $OrderstoPick . "'
26				AND pickreq.closed=0
27				WHERE pickserialdetails.serialno=stockserialitems.serialno
28				AND pickserialdetails.stockid=stockserialitems.stockid) as qtypickedthisorder
29			FROM stockserialitems
30			INNER JOIN locationusers
31				ON locationusers.loccode=stockserialitems.loccode
32				AND locationusers.userid='" .  $_SESSION['UserID'] . "'
33				AND locationusers.canupd=1
34			WHERE stockid='" . $StockID . "'
35				AND stockserialitems.loccode ='" . $LocationOut."'
36				AND quantity > 0
37			ORDER BY createdate, quantity";
38	$ErrMsg = '<br />' .  _('Could not retrieve the items for'). ' ' . $StockID;
39	$Bundles = DB_query($sql, $ErrMsg );
40	echo '<table class="selection"><tr>';
41	if (DB_num_rows($Bundles)>0){
42		$AllSerials=array();
43
44		foreach ($LineItem->SerialItems as $Itm){
45			$AllSerials[$Itm->BundleRef] = $Itm->BundleQty;
46		}
47
48		echo '<td valign="top"><b>' .  _('Select Existing Items'). '</b><br />';
49
50		echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '?identifier=' . urlencode($identifier) . '" method="post">';
51		echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
52		echo '<input type="hidden" name="LineNo" value="' . $LineNo . '">
53			<input type="hidden" name="StockID" value="' . $StockID . '">
54			<input type="hidden" name="EntryType" value="KEYED">
55			<input type="hidden" name="identifier" value="' . $identifier . '">
56			<input type="hidden" name="EditControlled" value="true">
57			<select name=Bundles[] multiple="multiple">';
58
59		$id=0;
60		$ItemsAvailable=0;
61		while ($myrow=DB_fetch_array($Bundles)){
62			if (is_null($MyRow['qtypickedtotal'])) {
63				$MyRow['qtypickedtotal'] = 0;
64			}
65			if (is_null($MyRow['qtypickedthisorder'])) {
66				$MyRow['qtypickedthisorder'] = 0;
67			}
68			if ($LineItem->Serialised==1){
69				if ( !array_key_exists($myrow['serialno'], $AllSerials) ){
70					echo '<option value="' . $myrow['serialno'] . '">' . $myrow['serialno'] . '</option>';
71					$ItemsAvailable++;
72				}
73			} else {
74
75				if ( !array_key_exists($myrow['serialno'], $AllSerials)  OR
76					($myrow['quantity'] - $AllSerials[$myrow['serialno']] >= 0) ) {
77
78					//Use the $InOutModifier to ajust the negative or postive direction of the quantity. Otherwise the calculated quantity is wrong.
79					if (isset($AllSerials[$MyRow['serialno']])) {
80						$RecvQty = $myrow['quantity'] - $InOutModifier * $AllSerials[$myrow['serialno']];
81					} else {
82						$RecvQty = $myrow['quantity'];
83					}
84					echo '<option value="' . $myrow['serialno'] . '/|/'. $RecvQty .'">' . $myrow['serialno'].' - ' . _('Qty left'). ': ' . $RecvQty . '</option>';
85					$ItemsAvailable += $RecvQty;
86				}
87			}
88		}
89		echo '</select>
90			<br />';
91		echo '<br /><div class="centre"><input type="submit" name="AddBatches" value="'. _('Enter'). '"></div>
92			<br />';
93		echo '</form>';
94		echo $ItemsAvailable . ' ' . _('items available');
95		echo '</td>';
96	} else {
97		echo '<td>' .  prnMsg( _('There does not appear to be any of') . ' ' . $StockID . ' ' . _('left in'). ' '. $LocationOut , 'warn') . '</td>';
98	}
99	echo '</tr></table>';
100}
101