1<?php 2 3include ('includes/session.php'); 4$Title = _('Stock Movements'); 5/* webERP manual links before header.php */ 6$ViewTopic = 'Inventory'; 7$BookMark = 'InventoryMovement'; 8include ('includes/header.php'); 9 10if (isset($_GET['StockID'])) { 11 $StockID = trim(mb_strtoupper($_GET['StockID'])); 12} elseif (isset($_POST['StockID'])) { 13 $StockID = trim(mb_strtoupper($_POST['StockID'])); 14} else { 15 $StockID = ''; 16} 17 18$StockInfo = ''; 19if ('' != $StockID) { 20 $Result = DB_query("SELECT description, units FROM stockmaster WHERE stockid='" . $StockID . "'"); 21 $MyRow = DB_fetch_row($Result); 22 23 $StockInfo = '<br /><b>' . $StockID . ' - ' . $MyRow['0'] . ' : ' . _('in units of') . ' : ' . $MyRow[1] . '</b>'; 24} 25 26echo '<p class="page_title_text"> 27 <img src="', $RootPath, '/css/', $_SESSION['Theme'], '/images/inventory.png" title="', _('Inventory'), '" alt="" /> ', $Title, $StockInfo, '</p>'; 28 29echo '<form action="', htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8'), '" method="post"> 30 <div> 31 <input type="hidden" name="FormID" value="', $_SESSION['FormID'], '" />'; 32 33if (!isset($_POST['BeforeDate']) or !Is_date($_POST['BeforeDate'])) { 34 $_POST['BeforeDate'] = Date($_SESSION['DefaultDateFormat']); 35} 36if (!isset($_POST['AfterDate']) or !Is_date($_POST['AfterDate'])) { 37 $_POST['AfterDate'] = Date($_SESSION['DefaultDateFormat'], Mktime(0, 0, 0, Date('m') - 3, Date('d'), Date('y'))); 38} 39 40echo '<br /> 41 <table class="selection"> 42 <tr> 43 <th colspan="12">', _('Stock Code'), ':<input type="text" name="StockID" size="21" value="', $StockID, '" required="required" maxlength="20" />'; 44 45echo ' ', _('From Stock Location'), ':<select required="required" name="StockLocation"> '; 46 47$SQL = "SELECT locations.loccode, 48 locationname 49 FROM locations 50 INNER JOIN locationusers 51 ON locationusers.loccode=locations.loccode 52 AND locationusers.userid='" . $_SESSION['UserID'] . "' 53 AND locationusers.canview=1 54 ORDER BY locationname"; 55 56$ResultStkLocs = DB_query($SQL); 57 58while ($MyRow = DB_fetch_array($ResultStkLocs)) { 59 if (isset($_POST['StockLocation']) and $_POST['StockLocation'] != 'All') { 60 if ($MyRow['loccode'] == $_POST['StockLocation']) { 61 echo '<option selected="selected" value="' . $MyRow['loccode'] . '">' . $MyRow['locationname'] . '</option>'; 62 } else { 63 echo '<option value="' . $MyRow['loccode'] . '">' . $MyRow['locationname'] . '</option>'; 64 } 65 } elseif ($MyRow['loccode'] == $_SESSION['UserStockLocation']) { 66 echo '<option selected="selected" value="' . $MyRow['loccode'] . '">' . $MyRow['locationname'] . '</option>'; 67 $_POST['StockLocation'] = $MyRow['loccode']; 68 } else { 69 echo '<option value="' . $MyRow['loccode'] . '">' . $MyRow['locationname'] . '</option>'; 70 } 71} 72 73echo '</select></th> 74 </tr>'; 75echo '<tr> 76 <th colspan="12">', _('Show Movements between'), ': 77 <input type="text" name="AfterDate" class="date" size="11" required="required" maxlength="10" value="', $_POST['AfterDate'], '" /> ' . _('and') . ': 78 <input type="text" name="BeforeDate" class="date" size="11" required="required" maxlength="10" value="', $_POST['BeforeDate'], '" /> 79 <input type="submit" name="ShowMoves" value="', _('Show Stock Movements'), '" /> 80 </th> 81 </tr>'; 82 83$SQLBeforeDate = FormatDateForSQL($_POST['BeforeDate']); 84$SQLAfterDate = FormatDateForSQL($_POST['AfterDate']); 85 86$SQL = "SELECT stockmoves.stockid, 87 systypes.typename, 88 stockmoves.stkmoveno, 89 stockmoves.type, 90 stockmoves.transno, 91 stockmoves.trandate, 92 stockmoves.userid, 93 stockmoves.debtorno, 94 stockmoves.branchcode, 95 custbranch.brname, 96 stockmoves.qty, 97 stockmoves.reference, 98 stockmoves.price, 99 stockmoves.discountpercent, 100 stockmoves.newqoh, 101 stockmoves.narrative, 102 stockmaster.decimalplaces, 103 stockmaster.controlled, 104 stockmaster.serialised 105 FROM stockmoves 106 INNER JOIN systypes 107 ON stockmoves.type=systypes.typeid 108 INNER JOIN stockmaster 109 ON stockmoves.stockid=stockmaster.stockid 110 LEFT JOIN custbranch 111 ON stockmoves.debtorno=custbranch.debtorno 112 AND stockmoves.branchcode = custbranch.branchcode 113 WHERE stockmoves.loccode='" . $_POST['StockLocation'] . "' 114 AND stockmoves.trandate >= '" . $SQLAfterDate . "' 115 AND stockmoves.stockid = '" . $StockID . "' 116 AND stockmoves.trandate <= '" . $SQLBeforeDate . "' 117 AND hidemovt=0 118 ORDER BY stkmoveno DESC"; 119 120$ErrMsg = _('The stock movements for the selected criteria could not be retrieved because') . ' - '; 121$DbgMsg = _('The SQL that failed was') . ' '; 122 123$MovtsResult = DB_query($SQL, $ErrMsg, $DbgMsg); 124 125if (DB_num_rows($MovtsResult) > 0) { 126 $MyRow = DB_fetch_array($MovtsResult); 127 128 echo '<tr> 129 <th>', _('Type'), '</th> 130 <th>', _('Number'), '</th> 131 <th>', _('Date'), '</th> 132 <th>', _('User ID'), '</th> 133 <th>', _('Customer'), '</th> 134 <th>', _('Branch'), '</th> 135 <th>', _('Quantity'), '</th> 136 <th>', _('Reference'), '</th> 137 <th>', _('Price'), '</th> 138 <th>', _('Discount'), '</th> 139 <th>', _('New Qty'), '</th> 140 <th>', _('Narrative'), '</th>'; 141 if ($MyRow['controlled'] == 1) { 142 echo '<th>', _('Serial No.'), '</th>'; 143 } 144 echo '</tr>'; 145 146 DB_data_seek($MovtsResult, 0); 147 148 while ($MyRow = DB_fetch_array($MovtsResult)) { 149 150 $DisplayTranDate = ConvertSQLDate($MyRow['trandate']); 151 152 $SerialSQL = "SELECT serialno, moveqty FROM stockserialmoves WHERE stockmoveno='" . $MyRow['stkmoveno'] . "'"; 153 $SerialResult = DB_query($SerialSQL); 154 155 $SerialText = ''; 156 while ($SerialRow = DB_fetch_array($SerialResult)) { 157 if ($MyRow['serialised'] == 1) { 158 $SerialText.= $SerialRow['serialno'] . '<br />'; 159 } else { 160 $SerialText.= $SerialRow['serialno'] . ' Qty- ' . $SerialRow['moveqty'] . '<br />'; 161 } 162 } 163 164 if ($MyRow['type'] == 10) { 165 /*its a sales invoice allow link to show invoice it was sold on*/ 166 167 echo '<tr class="striped_row"> 168 <td><a target="_blank" href="', $RootPath, '/PrintCustTrans.php?FromTransNo=', urlencode($MyRow['transno']), '&InvOrCredit=Invoice">', $MyRow['typename'], '</a></td> 169 <td>', $MyRow['transno'], '</td> 170 <td>', $DisplayTranDate, '</td> 171 <td>', $MyRow['userid'], '</td> 172 <td>', $MyRow['debtorno'], '</td> 173 <td>', $MyRow['branchcode'], ' - ', $MyRow['brname'], '</td> 174 <td class="number">', locale_number_format($MyRow['qty'], $MyRow['decimalplaces']), '</td> 175 <td>', $MyRow['reference'], '</td> 176 <td class="number">', locale_number_format($MyRow['price'], $_SESSION['CompanyRecord']['decimalplaces']), '</td> 177 <td class="number">', locale_number_format($MyRow['discountpercent'] * 100, 2), '%%</td> 178 <td class="number">', locale_number_format($MyRow['newqoh'], $MyRow['decimalplaces']), '</td> 179 <td>', $MyRow['narrative'], '</td>'; 180 if ($MyRow['controlled'] == 1) { 181 echo '<td>', $SerialText, '</td>'; 182 } 183 echo '</tr>'; 184 185 } elseif ($MyRow['type'] == 11) { 186 187 echo '<tr class="striped_row"> 188 <td><a target="_blank" href="', $RootPath, '/PrintCustTrans.php?FromTransNo=', urlencode($MyRow['transno']), '&InvOrCredit=Credit">', $MyRow['typename'], '</a></td> 189 <td>', $MyRow['transno'], '</td> 190 <td>', $DisplayTranDate, '</td> 191 <td>', $MyRow['userid'], '</td> 192 <td>', $MyRow['debtorno'], '</td> 193 <td>', $MyRow['branchcode'], '</td> 194 <td class="number">', locale_number_format($MyRow['qty'], $MyRow['decimalplaces']), '</td> 195 <td>', $MyRow['reference'], '</td> 196 <td class="number">', locale_number_format($MyRow['price'], $_SESSION['CompanyRecord']['decimalplaces']), '</td> 197 <td class="number">', locale_number_format($MyRow['discountpercent'] * 100, 2), '%%</td> 198 <td class="number">', locale_number_format($MyRow['newqoh'], $MyRow['decimalplaces']), '</td> 199 <td>', $MyRow['narrative'], '</td>'; 200 if ($MyRow['controlled'] == 1) { 201 echo '<td>', $SerialText, '</td>'; 202 } 203 echo '</tr>'; 204 205 } else { 206 207 echo '<tr class="striped_row"> 208 <td>', $MyRow['typename'], '</td> 209 <td>', $MyRow['transno'], '</td> 210 <td>', $DisplayTranDate, '</td> 211 <td>', $MyRow['userid'], '</td> 212 <td>', $MyRow['debtorno'], '</td> 213 <td>', $MyRow['branchcode'], '</td> 214 <td class="number">', locale_number_format($MyRow['qty'], $MyRow['decimalplaces']), '</td> 215 <td>', $MyRow['reference'], '</td> 216 <td class="number">', locale_number_format($MyRow['price'], $_SESSION['CompanyRecord']['decimalplaces']), '</td> 217 <td class="number">', locale_number_format($MyRow['discountpercent'] * 100, 2), '%</td> 218 <td class="number">', locale_number_format($MyRow['newqoh'], $MyRow['decimalplaces']), '</td> 219 <td>', $MyRow['narrative'], '</td>'; 220 if ($MyRow['controlled'] == 1) { 221 echo '<td>', $SerialText, '</td>'; 222 } 223 echo '</tr>'; 224 225 } 226 //end of page full new headings if 227 228 } 229 //end of while loop 230 231} 232 233echo '</table> 234 <div class="centre"> 235 <br /><a href="', $RootPath, '/StockStatus.php?StockID=', urlencode($StockID), '">', _('Show Stock Status'), '</a> 236 <br /><a href="', $RootPath, '/StockUsage.php?StockID=', urlencode($StockID), '&StockLocation=', urlencode($_POST['StockLocation']), '">', _('Show Stock Usage'), '</a> 237 <br /><a href="', $RootPath, '/SelectSalesOrder.php?SelectedStockItem=', urlencode($StockID), '&StockLocation=', urlencode($_POST['StockLocation']), '">', _('Search Outstanding Sales Orders'), '</a> 238 <br /><a href="', $RootPath, '/SelectCompletedOrder.php?SelectedStockItem=', urlencode($StockID), '">', _('Search Completed Sales Orders'), '</a> 239 </div> 240 </div> 241 </form>'; 242 243include ('includes/footer.php'); 244 245?>