Skip to content

Commit 45f169b

Browse files
committed
Tim (PaulT commit): StockMovements.php, StockLocMovements.php: Correct stock movements that have more than one serial number as part of it, then the item will appear multiple times in the movements script with the total quantity in each line. For example, if I enter a quantity adjustment for a controlled item, and assign 3 serial numbers to this movement and then run the inquiries, there will be 3 separate lines with a quantity of 3 against each one.
Signed-off-by: Paul Thursby <pthursby2@gmail.com>
1 parent bd8ae37 commit 45f169b

File tree

3 files changed

+226
-213
lines changed

3 files changed

+226
-213
lines changed

StockLocMovements.php

Lines changed: 99 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -7,59 +7,75 @@
77

88
include('includes/header.php');
99

10-
echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '" method="post">';
11-
echo '<div>';
12-
echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
13-
14-
echo '<p class="page_title_text"><img src="' . $RootPath . '/css/' . $Theme . '/images/magnifier.png" title="' . _('Search') .
15-
'" alt="" />' . ' ' . $Title . '</p>';
16-
17-
echo '<table class="selection">
18-
<tr>
19-
<td> ' . _('From Stock Location') . ':<select name="StockLocation"> ';
10+
echo '<p class="page_title_text">
11+
<img src="', $RootPath, '/css/', $_SESSION['Theme'], '/images/magnifier.png" title="', _('Search'), '" alt="" />', ' ', $Title, '
12+
</p>';
13+
14+
echo '<form action="', htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8'), '" method="post">
15+
<input type="hidden" name="FormID" value="', $_SESSION['FormID'], '" />
16+
<table>
17+
<tr>
18+
<td>', _('From Stock Location'), ':<select required="required" name="StockLocation">';
19+
20+
$SQL = "SELECT locationname,
21+
locations.loccode
22+
FROM locations
23+
INNER JOIN locationusers
24+
ON locationusers.loccode=locations.loccode
25+
AND locationusers.userid='" . $_SESSION['UserID'] . "'
26+
AND locationusers.canview=1
27+
ORDER BY locationname";
28+
29+
echo '<option selected="selected" value="All">', _('All Locations'), '</option>';
30+
31+
if (!isset($_POST['StockLocation'])) {
32+
$_POST['StockLocation'] = 'All';
33+
}
2034

21-
$sql = "SELECT locations.loccode, locationname FROM locations
22-
INNER JOIN locationusers ON locationusers.loccode=locations.loccode AND locationusers.userid='" . $_SESSION['UserID'] . "' AND locationusers.canview=1";
2335
$resultStkLocs = DB_query($sql);
24-
while ($myrow=DB_fetch_array($resultStkLocs)){
25-
if (isset($_POST['StockLocation']) AND $_POST['StockLocation']!='All'){
26-
if ($myrow['loccode'] == $_POST['StockLocation']){
27-
echo '<option selected="selected" value="' . $myrow['loccode'] . '">' . $myrow['locationname'] . '</option>';
36+
37+
while ($MyRow = DB_fetch_array($ResultStkLocs)) {
38+
if (isset($_POST['StockLocation']) and $_POST['StockLocation'] != 'All') {
39+
if ($MyRow['loccode'] == $_POST['StockLocation']) {
40+
echo '<option selected="selected" value="', $MyRow['loccode'], '">', $MyRow['locationname'], '</option>';
2841
} else {
29-
echo '<option value="' . $myrow['loccode'] . '">' . $myrow['locationname'] . '</option>';
42+
echo '<option value="', $MyRow['loccode'], '">', $MyRow['locationname'], '</option>';
3043
}
31-
} elseif ($myrow['loccode']==$_SESSION['UserStockLocation']){
44+
} elseif ($MyRow['loccode'] == $_SESSION['UserStockLocation']) {
3245
echo '<option selected="selected" value="' . $myrow['loccode'] . '">' . $myrow['locationname'] . '</option>';
3346
$_POST['StockLocation']=$myrow['loccode'];
3447
} else {
35-
echo '<option value="' . $myrow['loccode'] . '">' . $myrow['locationname'] . '</option>';
48+
echo '<option value="', $MyRow['loccode'], '">', $MyRow['locationname'], '</option>';
3649
}
3750
}
3851

3952
echo '</select>';
4053

41-
if (!isset($_POST['BeforeDate']) OR !Is_Date($_POST['BeforeDate'])){
54+
if (!isset($_POST['BeforeDate']) or !Is_date($_POST['BeforeDate'])) {
4255
$_POST['BeforeDate'] = Date($_SESSION['DefaultDateFormat']);
4356
}
44-
if (!isset($_POST['AfterDate']) OR !Is_Date($_POST['AfterDate'])){
45-
$_POST['AfterDate'] = Date($_SESSION['DefaultDateFormat'], Mktime(0,0,0,Date('m')-1,Date('d'),Date('y')));
57+
if (!isset($_POST['AfterDate']) or !Is_date($_POST['AfterDate'])) {
58+
$_POST['AfterDate'] = Date($_SESSION['DefaultDateFormat'], Mktime(0, 0, 0, Date('m') - 1, Date('d'), Date('y')));
4659
}
47-
echo ' ' . _('Show Movements before') . ': <input type="text" name="BeforeDate" size="12" maxlength="12" value="' . $_POST['BeforeDate'] . '" />';
48-
echo ' ' . _('But after') . ': <input type="text" name="AfterDate" size="12" maxlength="12" value="' . $_POST['AfterDate'] . '" />';
49-
echo '</td>
60+
echo ' ', _('Show Movements before'), ': <input type="text" class="date" alt="', $_SESSION['DefaultDateFormat'], '" name="BeforeDate" size="12" required="required" maxlength="12" value="', $_POST['BeforeDate'], '" />',
61+
' ', _('But after'), ': <input type="text" class="date" alt="', $_SESSION['DefaultDateFormat'], '" name="AfterDate" size="12" required="required" maxlength="12" value="', $_POST['AfterDate'], '" />',
62+
'</td>
5063
</tr>
5164
</table>
52-
<br />';
53-
echo '<div class="centre">
54-
<input type="submit" name="ShowMoves" value="' . _('Show Stock Movements') . '" />
65+
<div class="centre">
66+
<input type="submit" name="ShowMoves" value="', _('Show Stock Movements'), '" />
5567
</div>
5668
<br />';
5769

70+
if ($_POST['StockLocation'] == 'All') {
71+
$_POST['StockLocation'] = '%%';
72+
}
5873

5974
$SQLBeforeDate = FormatDateForSQL($_POST['BeforeDate']);
6075
$SQLAfterDate = FormatDateForSQL($_POST['AfterDate']);
6176

6277
$sql = "SELECT stockmoves.stockid,
78+
stockmoves.stkmoveno,
6379
systypes.typename,
6480
stockmoves.type,
6581
stockmoves.transno,
@@ -71,82 +87,73 @@
7187
stockmoves.price,
7288
stockmoves.discountpercent,
7389
stockmoves.newqoh,
74-
stockmaster.decimalplaces,
75-
stockserialmoves.serialno
90+
stockmaster.controlled,
91+
stockmaster.serialised,
92+
stockmaster.decimalplaces
7693
FROM stockmoves
77-
INNER JOIN systypes ON stockmoves.type=systypes.typeid
78-
INNER JOIN stockmaster ON stockmoves.stockid=stockmaster.stockid
79-
LEFT JOIN stockserialmoves ON stockmoves.stkmoveno=stockserialmoves.stockmoveno
80-
WHERE stockmoves.loccode='" . $_POST['StockLocation'] . "'
81-
AND stockmoves.trandate >= '". $SQLAfterDate . "'
94+
INNER JOIN systypes
95+
ON stockmoves.type=systypes.typeid
96+
INNER JOIN stockmaster
97+
ON stockmoves.stockid=stockmaster.stockid
98+
WHERE stockmoves.loccode " . LIKE . " '" . $_POST['StockLocation'] . "'
99+
AND stockmoves.trandate >= '" . $SQLAfterDate . "'
82100
AND stockmoves.trandate <= '" . $SQLBeforeDate . "'
83101
AND hidemovt=0
84102
ORDER BY stkmoveno DESC";
85-
86103
$ErrMsg = _('The stock movements for the selected criteria could not be retrieved because');
87-
$MovtsResult = DB_query($sql,$ErrMsg);
88-
89-
echo '<table cellpadding="5" cellspacing="4 "class="selection">';
90-
$tableheader = '<tr>
91-
<th>' . _('Item Code') . '</th>
92-
<th>' . _('Type') . '</th>
93-
<th>' . _('Trans No') . '</th>
94-
<th>' . _('Date') . '</th>
95-
<th>' . _('Customer') . '</th>
96-
<th>' . _('Quantity') . '</th>
97-
<th>' . _('Reference') . '</th>
98-
<th>' . _('Price') . '</th>
99-
<th>' . _('Discount') . '</th>
100-
<th>' . _('Quantity on Hand') . '</th>
101-
<th>' . _('Serial No.') . '</th>
104+
$MovtsResult = DB_query($SQL, $ErrMsg);
105+
106+
if (DB_num_rows($MovtsResult) > 0) {
107+
echo '<table cellpadding="5" cellspacing="4" class="selection">
108+
<tr>
109+
<th>', _('Item Code'), '</th>
110+
<th>', _('Type'), '</th>
111+
<th>', _('Trans No'), '</th>
112+
<th>', _('Date'), '</th>
113+
<th>', _('Customer'), '</th>
114+
<th>', _('Quantity'), '</th>
115+
<th>', _('Reference'), '</th>
116+
<th>', _('Price'), '</th>
117+
<th>', _('Discount'), '</th>
118+
<th>', _('Quantity on Hand'), '</th>
119+
<th>', _('Serial No.'), '</th>
102120
</tr>';
103-
echo $tableheader;
104-
105-
$j = 1;
106121

107-
while ($myrow=DB_fetch_array($MovtsResult)) {
122+
while ($MyRow = DB_fetch_array($MovtsResult)) {
108123

109124
$DisplayTranDate = ConvertSQLDate($myrow['trandate']);
110125

111-
printf('<tr class="striped_row">
112-
<td><a target="_blank" href="' . $RootPath . '/StockStatus.php?StockID=%s">%s</a></td>
113-
<td>%s</td>
114-
<td>%s</td>
115-
<td>%s</td>
116-
<td>%s</td>
117-
<td class="number">%s</td>
118-
<td>%s</td>
119-
<td class="number">%s</td>
120-
<td class="number">%s</td>
121-
<td class="number">%s</td>
122-
<td class="number">%s</td>
123-
</tr>',
124-
mb_strtoupper($myrow['stockid']),
125-
mb_strtoupper($myrow['stockid']),
126-
$myrow['typename'],
127-
$myrow['transno'],
128-
$DisplayTranDate,
129-
$myrow['debtorno'],
130-
locale_number_format($myrow['qty'],
131-
$myrow['decimalplaces']),
132-
$myrow['reference'],
133-
locale_number_format($myrow['price'],$_SESSION['CompanyRecord']['decimalplaces']),
134-
locale_number_format($myrow['discountpercent']*100,2),
135-
locale_number_format($myrow['newqoh'],$myrow['decimalplaces']),
136-
$myrow['serialno']);
137-
$j++;
138-
If ($j == 16){
139-
$j=1;
140-
echo $tableheader;
126+
$SerialSQL = "SELECT serialno, moveqty FROM stockserialmoves WHERE stockmoveno='" . $MyRow['stkmoveno'] . "'";
127+
$SerialResult = DB_query($SerialSQL);
128+
129+
$SerialText = '';
130+
while ($SerialRow = DB_fetch_array($SerialResult)) {
131+
if ($MyRow['serialised'] == 1) {
132+
$SerialText .= $SerialRow['serialno'] . '<br />';
133+
} else {
134+
$SerialText .= $SerialRow['serialno'] . ' Qty- ' . $SerialRow['moveqty'] . '<br />';
135+
}
141136
}
142-
//end of page full new headings if
143-
}
144-
//end of while loop
145137

146-
echo '</table>';
147-
echo '</div>
148-
</form>';
138+
echo '<tr class="striped_row">
139+
<td><a target="_blank" href="', $RootPath, '/StockStatus.php?StockID=', mb_strtoupper(urlencode($MyRow['stockid'])), '">', mb_strtoupper($MyRow['stockid']), '</a></td>
140+
<td>', $MyRow['typename'], '</td>
141+
<td>', $MyRow['transno'], '</td>
142+
<td>', $DisplayTranDate, '</td>
143+
<td>', $MyRow['debtorno'], '</td>
144+
<td class="number">', locale_number_format($MyRow['qty'], $MyRow['decimalplaces']), '</td>
145+
<td>', $MyRow['reference'], '</td>
146+
<td class="number">', locale_number_format($MyRow['price'], $_SESSION['CompanyRecord']['decimalplaces']), '</td>
147+
<td class="number">', locale_number_format($MyRow['discountpercent'] * 100, 2), '%</td>
148+
<td class="number">', locale_number_format($MyRow['newqoh'], $MyRow['decimalplaces']), '</td>
149+
<td>', $SerialText, '</td>
150+
</tr>';
151+
}
152+
//end of while loop
153+
echo '</table>';
154+
}
155+
echo '</form>';
149156

150-
include('includes/footer.php');
157+
include ('includes/footer.php');
151158

152159
?>

0 commit comments

Comments
 (0)