|
From: <tim...@us...> - 2012-02-26 09:19:47
|
Revision: 4973
http://web-erp.svn.sourceforge.net/web-erp/?rev=4973&view=rev
Author: tim_schofield
Date: 2012-02-26 09:19:38 +0000 (Sun, 26 Feb 2012)
Log Message:
-----------
New functionality for internal stock requests
Modified Paths:
--------------
trunk/StockCategories.php
trunk/UpgradeDatabase.php
trunk/includes/ConnectDB.inc
trunk/includes/MainMenuLinksArray.php
trunk/includes/SQL_CommonFunctions.inc
trunk/sql/mysql/upgrade4.07-4.08.sql
Added Paths:
-----------
trunk/Departments.php
trunk/InternalStockRequest.php
trunk/InternalStockRequestAuthorisation.php
trunk/InternalStockRequestFulfill.php
trunk/includes/DefineStockRequestClass.php
Added: trunk/Departments.php
===================================================================
--- trunk/Departments.php (rev 0)
+++ trunk/Departments.php 2012-02-26 09:19:38 UTC (rev 4973)
@@ -0,0 +1,261 @@
+<?php
+/* $Id: UnitsOfMeasure.php 4567 2011-05-15 04:34:49Z daintree $*/
+
+include('includes/session.inc');
+
+$title = _('Departments');
+
+include('includes/header.inc');
+echo '<p class="page_title_text"><img src="' . $rootpath . '/css/' . $theme . '/images/magnifier.png" title="' .
+ _('Top Sales Order Search') . '" alt="" />' . ' ' . $title . '</p>';
+
+if ( isset($_GET['SelectedDepartmentID']) )
+ $SelectedDepartmentID = $_GET['SelectedDepartmentID'];
+elseif (isset($_POST['SelectedDepartmentID']))
+ $SelectedDepartmentID = $_POST['SelectedDepartmentID'];
+
+if (isset($_POST['Submit'])) {
+
+ //initialise no input errors assumed initially before we test
+
+ $InputError = 0;
+
+ /* actions to take once the user has clicked the submit button
+ ie the page has called itself with some user input */
+
+ //first off validate inputs sensible
+
+ if (strpos($_POST['DepartmentName'],'&')>0 OR strpos($_POST['DepartmentName'],"'")>0) {
+ $InputError = 1;
+ prnMsg( _('The description of the department must not contain the character') . " '&' " . _('or the character') ." '",'error');
+ }
+ if (trim($_POST['DepartmentName']) == '') {
+ $InputError = 1;
+ prnMsg( _('The Name of the Department should not be empty'), 'error');
+ }
+
+ if (isset($_POST['SelectedDepartmentID']) AND $_POST['SelectedDepartmentID']!='' AND $InputError !=1) {
+
+
+ /*SelectedDepartmentID could also exist if submit had not been clicked this code would not run in this case cos submit is false of course see the delete code below*/
+ // Check the name does not clash
+ $sql = "SELECT count(*) FROM departments
+ WHERE departmentid <> '" . $SelectedDepartmentID ."'
+ AND description ".LIKE." '" . $_POST['DepartmentName'] . "'";
+ $result = DB_query($sql,$db);
+ $myrow = DB_fetch_row($result);
+ if ( $myrow[0] > 0 ) {
+ $InputError = 1;
+ prnMsg( _('This department name already exists.'),'error');
+ } else {
+ // Get the old name and check that the record still exist neet to be very carefull here
+ // idealy this is one of those sets that should be in a stored procedure simce even the checks are
+ // relavant
+ $sql = "SELECT description FROM departments
+ WHERE departmentid = '" . $SelectedDepartmentID . "'";
+ $result = DB_query($sql,$db);
+ if ( DB_num_rows($result) != 0 ) {
+ // This is probably the safest way there is
+ $myrow = DB_fetch_row($result);
+ $OldDepartmentName = $myrow[0];
+ $sql = array();
+ $sql[] = "UPDATE departments
+ SET description='" . $_POST['DepartmentName'] . "',
+ authoriser='" . $_POST['Authoriser'] . "'
+ WHERE description ".LIKE." '".$OldDepartmentName."'";
+ } else {
+ $InputError = 1;
+ prnMsg( _('The Department does not exist.'),'error');
+ }
+ }
+ $msg = _('The department has been modified');
+ } elseif ($InputError !=1) {
+ /*SelectedDepartmentID is null cos no item selected on first time round so must be adding a record*/
+ $sql = "SELECT count(*) FROM departments
+ WHERE description " .LIKE. " '".$_POST['DepartmentName'] ."'";
+ $result = DB_query($sql,$db);
+ $myrow = DB_fetch_row($result);
+ if ( $myrow[0] > 0 ) {
+ $InputError = 1;
+ prnMsg( _('There is already a Department with the specified name.'),'error');
+ } else {
+ $sql = "INSERT INTO departments (
+ description,
+ authoriser )
+ VALUES (
+ '" . $_POST['DepartmentName'] ."',
+ '" . $_POST['Authoriser'] ."'
+ )";
+ }
+ $msg = _('The new department has been created');
+ }
+
+ if ($InputError!=1){
+ //run the SQL from either of the above possibilites
+ if (is_array($sql)) {
+ $result = DB_Txn_Begin($db);
+ $tmpErr = _('The department could not be inserted');
+ $tmpDbg = _('The sql that failed was') . ':';
+ foreach ($sql as $stmt ) {
+ $result = DB_query($stmt,$db, $tmpErr,$tmpDbg,true);
+ if(!$result) {
+ $InputError = 1;
+ break;
+ }
+ }
+ if ($InputError!=1){
+ $result = DB_Txn_Commit($db);
+ } else {
+ $result = DB_Txn_Rollback($db);
+ }
+ } else {
+ $result = DB_query($sql,$db);
+ }
+ prnMsg($msg,'success');
+ }
+ unset ($SelectedDepartmentID);
+ unset ($_POST['SelectedDepartmentID']);
+ unset ($_POST['DepartmentName']);
+
+} elseif (isset($_GET['delete'])) {
+//the link to delete a selected record was clicked instead of the submit button
+// PREVENT DELETES IF DEPENDENT RECORDS IN 'stockmaster'
+ // Get the original name of the unit of measure the ID is just a secure way to find the unit of measure
+ $sql = "SELECT description FROM departments
+ WHERE departmentid = '" . $SelectedDepartmentID . "'";
+ $result = DB_query($sql,$db);
+ if ( DB_num_rows($result) == 0 ) {
+ // This is probably the safest way there is
+ prnMsg( _('You cannot delete this Department'),'warn');
+ } else {
+ $myrow = DB_fetch_row($result);
+ $OldDepartmentName = $myrow[0];
+ $sql= "SELECT COUNT(*) FROM dispatch,departments WHERE dispatch.departmentid=departments.departmentid and description ".LIKE." '" . $OldDepartmentName . "'";
+ $result = DB_query($sql,$db);
+ $myrow = DB_fetch_row($result);
+ if ($myrow[0]>0) {
+ prnMsg( _('You cannot delete this Department'),'warn');
+ echo '<br />' . _('There are') . ' ' . $myrow[0] . ' ' . _('There are items related to this department');
+ } else {
+ $sql="DELETE FROM departments WHERE description ".LIKE."'" . $OldDepartmentName . "'";
+ $result = DB_query($sql,$db);
+ prnMsg( $OldDepartmentName . ' ' . _('The department has been removed') . '!','success');
+ }
+ } //end if account group used in GL accounts
+ unset ($SelectedDepartmentID);
+ unset ($_GET['SelectedDepartmentID']);
+ unset($_GET['delete']);
+ unset ($_POST['SelectedDepartmentID']);
+ unset ($_POST['DepartmentID']);
+ unset ($_POST['DepartmentName']);
+}
+
+ if (!isset($SelectedDepartmentID)) {
+
+/* An unit of measure could be posted when one has been edited and is being updated
+ or GOT when selected for modification
+ SelectedDepartmentID will exist because it was sent with the page in a GET .
+ If its the first time the page has been displayed with no parameters
+ then none of the above are true and the list of account groups will be displayed with
+ links to delete or edit each. These will call the same page again and allow update/input
+ or deletion of the records*/
+
+ $sql = "SELECT departmentid,
+ description,
+ authoriser
+ FROM departments
+ ORDER BY departmentid";
+
+ $ErrMsg = _('There are no departments created');
+ $result = DB_query($sql,$db,$ErrMsg);
+
+ echo '<table class="selection">
+ <tr>
+ <th>' . _('Department Name') . '</th>
+ <th>' . _('Authoriser') . '</th>
+ </tr>';
+
+ $k=0; //row colour counter
+ while ($myrow = DB_fetch_array($result)) {
+
+ if ($k==1){
+ echo '<tr class="EvenTableRows">';
+ $k=0;
+ } else {
+ echo '<tr class="OddTableRows">';
+ $k++;
+ }
+
+ echo '<td>' . $myrow['description'] . '</td>';
+ echo '<td>' . $myrow['authoriser'] . '</td>';
+ echo '<td><a href="' . htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '?SelectedDepartmentID=' . $myrow['departmentid'] . '">' . _('Edit') . '</a></td>';
+ echo '<td><a href="' . htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '?SelectedDepartmentID=' . $myrow['departmentid'] . '&delete=1">' . _('Delete') .'</a></td>';
+ echo '</tr>';
+
+ } //END WHILE LIST LOOP
+ echo '</table>';
+} //end of ifs and buts!
+
+
+if (isset($SelectedDepartmentID)) {
+ echo '<div class="centre"><a href="' . htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '">' . _('View all Departments') . '</a></div>';
+}
+
+echo '<br />';
+
+if (! isset($_GET['delete'])) {
+
+ echo '<form method="post" action="' . htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '">';
+ echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
+
+ if (isset($SelectedDepartmentID)) {
+ //editing an existing section
+
+ $sql = "SELECT departmentid,
+ description
+ FROM departments
+ WHERE departmentid='" . $SelectedDepartmentID . "'";
+
+ $result = DB_query($sql, $db);
+ if ( DB_num_rows($result) == 0 ) {
+ prnMsg( _('The selected departemnt could not be found.'),'warn');
+ unset($SelectedDepartmentID);
+ } else {
+ $myrow = DB_fetch_array($result);
+
+ $_POST['DepartmentID'] = $myrow['departmentid'];
+ $_POST['DepartmentName'] = $myrow['description'];
+
+ echo '<input type="hidden" name="SelectedDepartmentID" value="' . $_POST['DepartmentID'] . '" />';
+ echo '<table class="selection">';
+ }
+
+ } else {
+ $_POST['DepartmentName']='';
+ echo '<table class="selection">';
+ }
+ echo '<tr>
+ <td>' . _('Department Name') . ':' . '</td>
+ <td><input type="text" name="DepartmentName" size="50" maxlength="100" value="' . $_POST['DepartmentName'] . '" /></td>
+ </tr>';
+ echo '<tr><td>'._('Authoriser').'</td><td><select name="Authoriser">';
+ $usersql="SELECT userid FROM www_users";
+ $userresult=DB_query($usersql,$db);
+ while ($myrow=DB_fetch_array($userresult)) {
+ if ($myrow['userid']==$UserID) {
+ echo '<option selected="True" value="'.$myrow['userid'].'">'.$myrow['userid'].'</option>';
+ } else {
+ echo '<option value="'.$myrow['userid'].'">'.$myrow['userid'].'</option>';
+ }
+ }
+ echo '</select></td></tr>';
+ echo '</table><br />';
+
+ echo '<div class="centre"><input type="submit" name="Submit" value="' . _('Enter Information') . '" /></div>';
+
+ echo '</form>';
+
+} //end if record deleted no point displaying form to add record
+
+include('includes/footer.inc');
+?>
\ No newline at end of file
Added: trunk/InternalStockRequest.php
===================================================================
--- trunk/InternalStockRequest.php (rev 0)
+++ trunk/InternalStockRequest.php 2012-02-26 09:19:38 UTC (rev 4973)
@@ -0,0 +1,682 @@
+<?php
+
+/* $Id: StockTransfers.php 4576 2011-05-27 10:59:20Z daintree $*/
+
+include('includes/DefineStockRequestClass.php');
+
+include('includes/session.inc');
+$title = _('Create an Internal Materials Request');
+
+include('includes/header.inc');
+include('includes/SQL_CommonFunctions.inc');
+
+if (isset($_GET['New'])) {
+ unset($_SESSION['Transfer']);
+ $_SESSION['Request'] = new StockRequest();
+}
+
+if (isset($_POST['Update'])) {
+ $InputError=0;
+ if ($_POST['Department']=='') {
+ prnMsg( _('You must select a Department for the request'), 'error');
+ $InputError=1;
+ }
+ if ($_POST['Location']=='') {
+ prnMsg( _('You must select a Location to request the items from'), 'error');
+ $InputError=1;
+ }
+ if ($InputError==0) {
+ $_SESSION['Request']->Department=$_POST['Department'];
+ $_SESSION['Request']->Location=$_POST['Location'];
+ $_SESSION['Request']->DispatchDate=$_POST['DispatchDate'];
+ $_SESSION['Request']->Narrative=$_POST['Narrative'];
+ }
+}
+
+if (isset($_POST['Edit'])) {
+ $_SESSION['Request']->LineItems[$_POST['LineNumber']]->Quantity=$_POST['Quantity'];
+}
+
+if (isset($_GET['Delete'])) {
+ unset($_SESSION['Request']->LineItems[$_GET['Delete']]);
+ echo '<br />';
+ prnMsg( _('The line was successfully deleted'), 'success');
+ echo '<br />';
+}
+
+foreach ($_POST as $key => $value) {
+ if (mb_strstr($key,'StockID')) {
+ $Index=mb_substr($key, 7);
+ if (filter_number_format($_POST['Quantity'.$Index])>0) {
+ $StockID=$value;
+ $ItemDescription=$_POST['ItemDescription'.$Index];
+ $DecimalPlaces=$_POST['DecimalPlaces'.$Index];
+ $NewItem_array[$StockID] = filter_number_format($_POST['Quantity'.$Index]);
+ $_POST['Units'.$StockID]=$_POST['Units'.$Index];
+ $_SESSION['Request']->AddLine($StockID, $ItemDescription, $NewItem_array[$StockID], $_POST['Units'.$StockID], $DecimalPlaces);
+ }
+ }
+}
+
+if (isset($_POST['Submit'])) {
+ DB_Txn_Begin($db);
+ $InputError=0;
+ if ($_SESSION['Request']->Department=='') {
+ prnMsg( _('You must select a Department for the request'), 'error');
+ $InputError=1;
+ }
+ if ($_SESSION['Request']->Location=='') {
+ prnMsg( _('You must select a Location to request the items from'), 'error');
+ $InputError=1;
+ }
+ if ($InputError==0) {
+ $RequestNo = GetNextTransNo(38, $db);
+ $HeaderSQL="INSERT INTO stockrequest (dispatchid,
+ loccode,
+ departmentid,
+ despatchdate,
+ narrative)
+ VALUES(
+ '" . $RequestNo . "',
+ '" . $_SESSION['Request']->Location . "',
+ '" . $_SESSION['Request']->Department . "',
+ '" . FormatDateForSQL($_SESSION['Request']->DispatchDate) . "',
+ '" . $_SESSION['Request']->Narrative . "'
+ )";
+ $ErrMsg =_('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The request header record could not be inserted because');
+ $DbgMsg = _('The following SQL to insert the request header record was used');
+ $Result = DB_query($HeaderSQL,$db,$ErrMsg,$DbgMsg,true);
+
+ foreach ($_SESSION['Request']->LineItems as $LineItems) {
+ $LineSQL="INSERT INTO stockrequestitems (dispatchitemsid,
+ dispatchid,
+ stockid,
+ quantity,
+ decimalplaces,
+ uom)
+ VALUES(
+ '".$LineItems->LineNumber."',
+ '".$RequestNo."',
+ '".$LineItems->StockID."',
+ '".$LineItems->Quantity."',
+ '".$LineItems->DecimalPlaces."',
+ '".$LineItems->UOM."'
+ )";
+ $ErrMsg =_('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The request line record could not be inserted because');
+ $DbgMsg = _('The following SQL to insert the request header record was used');
+ $Result = DB_query($LineSQL,$db,$ErrMsg,$DbgMsg,true);
+
+ }
+
+ }
+ DB_Txn_Commit($db);
+ prnMsg( _('The internal stock request has been entered and now needs to be authorised'), 'success');
+ echo '<br /><div class="centre"><a href="'. htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '?New=Yes">' . _('Create another request') . '</a></div>';
+ include('includes/footer.inc');
+ unset($_SESSION['Request']);
+ exit;
+}
+
+echo '<p class="page_title_text"><img src="'.$rootpath.'/css/'.$theme.'/images/supplier.png" title="' . _('Dispatch') .
+ '" alt="" />' . ' ' . $title . '</p>';
+
+if (isset($_GET['Edit'])) {
+ echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '" method="post">';
+ echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
+ echo '<table class="selection">';
+ echo '<tr>
+ <th colspan="2"><font size="2" color="navy">' . _('Edit the Request Line') . '</font></th>
+ </tr>';
+ echo '<tr>
+ <td>' . _('Line number') . '</td>
+ <td>' . $_SESSION['Request']->LineItems[$_GET['Edit']]->LineNumber . '</td>
+ </tr>';
+ echo '<tr>
+ <td>' . _('Stock Code') . '</td>
+ <td>' . $_SESSION['Request']->LineItems[$_GET['Edit']]->StockID . '</td>
+ </tr>';
+ echo '<tr>
+ <td>' . _('Item Description') . '</td>
+ <td>' . $_SESSION['Request']->LineItems[$_GET['Edit']]->ItemDescription . '</td>
+ </tr>';
+ echo '<tr>
+ <td>' . _('Unit of Measure') . '</td>
+ <td>' . $_SESSION['Request']->LineItems[$_GET['Edit']]->UOM . '</td>
+ </tr>';
+ echo '<tr>
+ <td>' . _('Quantity Requested') . '</td>
+ <td><input type="text" class="number" name="Quantity" value="' . locale_number_format($_SESSION['Request']->LineItems[$_GET['Edit']]->Quantity, $_SESSION['Request']->LineItems[$_GET['Edit']]->DecimalPlaces) . '" /></td>
+ </tr>';
+ echo '<input type="hidden" name="LineNumber" value="' . $_SESSION['Request']->LineItems[$_GET['Edit']]->LineNumber . '" />';
+ echo '</table><br />';
+ echo '<div class="centre"><input type="submit" name="Edit" value="' . _('Update Line') . '" /></div></form>';
+ include('includes/footer.inc');
+ exit;
+}
+
+echo '<form action="'. htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '" method=post>';
+echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
+
+echo '<table class="selection">';
+echo '<tr>
+ <th colspan="2"><font color="navy" size="2">' . _('Internal Stock Request Details') . '</font></th>
+ </tr>';
+echo '<tr>
+ <td>' . _('Department') . ':</td>';
+
+$sql="SELECT departmentid,
+ description
+ FROM departments
+ ORDER BY description";
+
+$result=DB_query($sql, $db);
+echo '<td><select name="Department">';
+echo '<option value="">' . _('Select your department') . '</option>';
+while ($myrow=DB_fetch_array($result)){
+ if (isset($_SESSION['Request']->Department) and $_SESSION['Request']->Department==$myrow['departmentid']){
+ echo '<option selected="True" value="' . $myrow['departmentid'] . '">' . $myrow['departmentid'].' - ' .htmlentities($myrow['description'], ENT_QUOTES,'UTF-8').'</option>';
+ } else {
+ echo '<option value="' . $myrow['departmentid'] . '">' . $myrow['departmentid'].' - ' .htmlentities($myrow['description'], ENT_QUOTES,'UTF-8').'</option>';
+ }
+}
+echo '</select></td></tr>';
+
+echo '<tr>
+ <td>' . _('Location from which to request stock') . ':</td>';
+$sql="SELECT loccode,
+ locationname
+ FROM locations
+ ORDER BY locationname";
+
+$result=DB_query($sql, $db);
+echo '<td><select name="Location">';
+echo '<option value="">' . _('Select a Location') . '</option>';
+while ($myrow=DB_fetch_array($result)){
+ if (isset($_SESSION['Request']->Location) and $_SESSION['Request']->Location==$myrow['loccode']){
+ echo '<option selected="True" value="' . $myrow['loccode'] . '">' . $myrow['loccode'].' - ' .htmlentities($myrow['locationname'], ENT_QUOTES,'UTF-8').'</option>';
+ } else {
+ echo '<option value="' . $myrow['loccode'] . '">' . $myrow['loccode'].' - ' .htmlentities($myrow['locationname'], ENT_QUOTES,'UTF-8').'</option>';
+ }
+}
+echo '</select></td></tr>';
+
+echo '<tr>
+ <td>' . _('Date when required') . ':</td>';
+echo '<td><input type="text" class="date" alt="'.$_SESSION['DefaultDateFormat'].'" name="DispatchDate" maxlength="10" size="11" value="' . $_SESSION['Request']->DispatchDate . '" /></td>';
+
+echo '<tr><td>' . _('Narrative') . ':</td>';
+echo '<td><textarea name="Narrative" cols="30">'.$_SESSION['Request']->Narrative.'</textarea></td>';
+
+echo '</table><br />';
+
+echo '<div class="centre"><input type="submit" name="Update" value="' . _('Update') . '" /></div>';
+
+echo '</div></form>';
+
+if (!isset($_SESSION['Request']->Location)) {
+ include('includes/footer.inc');
+ exit;
+}
+
+//****************MUESTRO LA TABLA CON LOS REGISTROS DE LA TRANSFERENCIA*************************************
+$i = 0; //Line Item Array pointer
+echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '" method="post">';
+echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
+echo '<br /><table class="selection">';
+echo '<tr>
+ <th colspan="7"><font size="2" color="navy">' . _('Details of Items Requested') . '</font></th>
+ </tr>';
+echo '<tr>
+ <th>'. _('Line Number') . '</th>
+ <th>'. _('Item Code') . '</th>
+ <th>'. _('Item Description'). '</th>
+ <th>'. _('Quantity Required'). '</th>
+ <th>'. _('UOM'). '</th>
+ </tr>';
+
+$k=0;
+
+foreach ($_SESSION['Request']->LineItems as $LineItems) {
+
+ if ($k==1){
+ echo '<tr class="EvenTableRows">';
+ $k=0;
+ } else {
+ echo '<tr class="OddTableRows">';
+ $k++;
+ }
+ echo '<td>' . $LineItems->LineNumber . '</td>
+ <td>' . $LineItems->StockID . '</td>
+ <td>' . $LineItems->ItemDescription . '</td>
+ <td class="number">' . locale_number_format($LineItems->Quantity, $LineItems->DecimalPlaces) . '</td>
+ <td>' . $LineItems->UOM . '</td>
+ <td><a href="'. htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '?Edit='.$LineItems->LineNumber.'">' . _('Edit') . '</a></td>
+ <td><a href="'. htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '?Delete='.$LineItems->LineNumber.'">' . _('Delete') . '</a></td>
+ </tr>';
+
+}
+
+echo '</table><br />';
+echo '<div class="centre"><input type="submit" name="Submit" value="' . _('Submit') . '" /></div><br />';
+
+echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '" method="post">';
+echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
+
+echo '<p class="page_title_text"><img src="' . $rootpath . '/css/' . $theme . '/images/magnifier.png" title="' . _('Search') . '" alt="" />' . ' ' . _('Search for Inventory Items'). '</p>';
+$SQL = "SELECT categoryid,
+ categorydescription
+ FROM stockcategory
+ ORDER BY categorydescription";
+$result1 = DB_query($SQL, $db);
+if (DB_num_rows($result1) == 0) {
+ echo '<p><font size="4" color="red">' . _('Problem Report') . ':</font><br />' . _('There are no stock categories currently defined please use the link below to set them up').'</p>';
+ echo '<br /><a href="' . $rootpath . '/StockCategories.php">' . _('Define Stock Categories') . '</a>';
+ exit;
+}
+echo '<table class="selection"><tr>';
+echo '<td>' . _('In Stock Category') . ':';
+echo '<select name="StockCat">';
+if (!isset($_POST['StockCat'])) {
+ $_POST['StockCat'] = "";
+}
+if ($_POST['StockCat'] == 'All') {
+ echo '<option selected="True" value="All">' . _('All').'</option>';
+} else {
+ echo '<option value="All">' . _('All').'</option>';
+}
+while ($myrow1 = DB_fetch_array($result1)) {
+ if ($myrow1['categoryid'] == $_POST['StockCat']) {
+ echo '<option selected="True" value="' . $myrow1['categoryid'] . '">' . $myrow1['categorydescription'].'</option>';
+ } else {
+ echo '<option value="' . $myrow1['categoryid'] . '">' . $myrow1['categorydescription'].'</option>';
+ }
+}
+echo '</select></td>';
+echo '<td>' . _('Enter partial') . '<b> ' . _('Description') . '</b>:</td>';
+if (isset($_POST['Keywords'])) {
+ echo '<td><input type="text" name="Keywords" value="' . $_POST['Keywords'] . '" size="20" maxlength="25" /></td>';
+} else {
+ echo '<td><input type="text" name="Keywords" size="20" maxlength="25" /></td>';
+}
+echo '</tr>
+ <tr>
+ <td></td>';
+echo '<td><font size="3"><b>' . _('OR') . ' ' . '</b></font>' . _('Enter partial') . ' <b>' . _('Stock Code') . '</b>:</td>';
+
+if (isset($_POST['StockCode'])) {
+ echo '<td><input type="text" name="StockCode" value="' . $_POST['StockCode'] . '" size="15" maxlength="18" /></td>';
+} else {
+ echo '<td><input type="text" name="StockCode" size="15" maxlength="18" /></td>';
+}
+echo '</tr></table><br />';
+echo '<div class="centre"><input type="submit" name="Search" value="' . _('Search Now') . '" /></div><br />';
+echo '<script type="text/javascript">defaultControl(document.forms[0].StockCode);</script>';
+echo '</form>';
+
+if (isset($_POST['Search']) or isset($_POST['Next']) or isset($_POST['Prev'])){
+
+ if ($_POST['Keywords']!='' AND $_POST['StockCode']=='') {
+ prnMsg ( _('Order Item description has been used in search'), 'warn' );
+ } elseif ($_POST['StockCode']!='' AND $_POST['Keywords']=='') {
+ prnMsg ( _('Stock Code has been used in search'), 'warn' );
+ } elseif ($_POST['Keywords']=='' AND $_POST['StockCode']=='') {
+ prnMsg ( _('Stock Category has been used in search'), 'warn' );
+ }
+ if (isset($_POST['Keywords']) AND mb_strlen($_POST['Keywords'])>0) {
+ //insert wildcard characters in spaces
+ $_POST['Keywords'] = mb_strtoupper($_POST['Keywords']);
+ $SearchString = '%' . str_replace(' ', '%', $_POST['Keywords']) . '%';
+
+ if ($_POST['StockCat']=='All'){
+ $SQL = "SELECT stockmaster.stockid,
+ stockmaster.description,
+ stockmaster.units as stockunits,
+ stockmaster.decimalplaces
+ FROM stockmaster,
+ stockcategory
+ WHERE stockmaster.categoryid=stockcategory.categoryid
+ AND (stockcategory.stocktype='F' OR stockcategory.stocktype='D')
+ AND stockmaster.mbflag <>'G'
+ AND stockmaster.description " . LIKE . " '$SearchString'
+ AND stockmaster.discontinued=0
+ ORDER BY stockmaster.stockid";
+ } else {
+ $SQL = "SELECT stockmaster.stockid,
+ stockmaster.description,
+ stockmaster.units as stockunits,
+ stockmaster.decimalplaces
+ FROM stockmaster,
+ stockcategory
+ WHERE stockmaster.categoryid=stockcategory.categoryid
+ AND (stockcategory.stocktype='F' OR stockcategory.stocktype='D')
+ AND stockmaster.mbflag <>'G'
+ AND stockmaster.discontinued=0
+ AND stockmaster.description " . LIKE . " '" . $SearchString . "'
+ AND stockmaster.categoryid='" . $_POST['StockCat'] . "'
+ ORDER BY stockmaster.stockid";
+ }
+
+ } elseif (mb_strlen($_POST['StockCode'])>0){
+
+ $_POST['StockCode'] = mb_strtoupper($_POST['StockCode']);
+ $SearchString = '%' . $_POST['StockCode'] . '%';
+
+ if ($_POST['StockCat']=='All'){
+ $SQL = "SELECT stockmaster.stockid,
+ stockmaster.description,
+ stockmaster.units as stockunits,
+ stockmaster.decimalplaces
+ FROM stockmaster,
+ stockcategory
+ WHERE stockmaster.categoryid=stockcategory.categoryid
+ AND (stockcategory.stocktype='F' OR stockcategory.stocktype='D')
+ AND stockmaster.stockid " . LIKE . " '" . $SearchString . "'
+ AND stockmaster.mbflag <>'G'
+ AND stockmaster.discontinued=0
+ ORDER BY stockmaster.stockid";
+ } else {
+ $SQL = "SELECT stockmaster.stockid,
+ stockmaster.description,
+ stockmaster.units as stockunits,
+ stockmaster.decimalplaces
+ FROM stockmaster,
+ stockcategory
+ WHERE stockmaster.categoryid=stockcategory.categoryid
+ AND (stockcategory.stocktype='F' OR stockcategory.stocktype='D')
+ AND stockmaster.stockid " . LIKE . " '" . $SearchString . "'
+ AND stockmaster.mbflag <>'G'
+ AND stockmaster.discontinued=0
+ AND stockmaster.categoryid='" . $_POST['StockCat'] . "'
+ ORDER BY stockmaster.stockid";
+ }
+
+ } else {
+ if ($_POST['StockCat']=='All'){
+ $SQL = "SELECT stockmaster.stockid,
+ stockmaster.description,
+ stockmaster.units as stockunits,
+ stockmaster.decimalplaces
+ FROM stockmaster,
+ stockcategory
+ WHERE stockmaster.categoryid=stockcategory.categoryid
+ AND (stockcategory.stocktype='F' OR stockcategory.stocktype='D')
+ AND stockmaster.mbflag <>'G'
+ AND stockmaster.discontinued=0
+ ORDER BY stockmaster.stockid";
+ } else {
+ $SQL = "SELECT stockmaster.stockid,
+ stockmaster.description,
+ stockmaster.units as stockunits,
+ stockmaster.decimalplaces
+ FROM stockmaster,
+ stockcategory
+ WHERE stockmaster.categoryid=stockcategory.categoryid
+ AND (stockcategory.stocktype='F' OR stockcategory.stocktype='D')
+ AND stockmaster.mbflag <>'G'
+ AND stockmaster.discontinued=0
+ AND stockmaster.categoryid='" . $_POST['StockCat'] . "'
+ ORDER BY stockmaster.stockid";
+ }
+ }
+
+ if (isset($_POST['Next'])) {
+ $Offset = $_POST['nextlist'];
+ }
+ if (isset($_POST['Prev'])) {
+ $Offset = $_POST['previous'];
+ }
+ if (!isset($Offset) or $Offset<0) {
+ $Offset=0;
+ }
+ $SQL = $SQL . ' LIMIT ' . $_SESSION['DefaultDisplayRecordsMax'].' OFFSET '.($_SESSION['DefaultDisplayRecordsMax']*$Offset);
+
+ $ErrMsg = _('There is a problem selecting the part records to display because');
+ $DbgMsg = _('The SQL used to get the part selection was');
+ $SearchResult = DB_query($SQL,$db,$ErrMsg, $DbgMsg);
+
+ if (DB_num_rows($SearchResult)==0 ){
+ prnMsg (_('There are no products available meeting the criteria specified'),'info');
+ }
+ if (DB_num_rows($SearchResult)<$_SESSION['DisplayRecordsMax']){
+ $Offset=0;
+ }
+
+} //end of if search
+/* display list if there is more than one record */
+if (isset($searchresult) AND !isset($_POST['Select'])) {
+ echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '" method="post">';
+ echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
+ $ListCount = DB_num_rows($searchresult);
+ if ($ListCount > 0) {
+ // If the user hit the search button and there is more than one item to show
+ $ListPageMax = ceil($ListCount / $_SESSION['DisplayRecordsMax']);
+ if (isset($_POST['Next'])) {
+ if ($_POST['PageOffset'] < $ListPageMax) {
+ $_POST['PageOffset'] = $_POST['PageOffset'] + 1;
+ }
+ }
+ if (isset($_POST['Previous'])) {
+ if ($_POST['PageOffset'] > 1) {
+ $_POST['PageOffset'] = $_POST['PageOffset'] - 1;
+ }
+ }
+ if ($_POST['PageOffset'] > $ListPageMax) {
+ $_POST['PageOffset'] = $ListPageMax;
+ }
+ if ($ListPageMax > 1) {
+ echo '<div class="centre"><br /> ' . $_POST['PageOffset'] . ' ' . _('of') . ' ' . $ListPageMax . ' ' . _('pages') . '. ' . _('Go to Page') . ': ';
+ echo '<select name="PageOffset">';
+ $ListPage = 1;
+ while ($ListPage <= $ListPageMax) {
+ if ($ListPage == $_POST['PageOffset']) {
+ echo '<option value=' . $ListPage . ' selected>' . $ListPage . '</option>';
+ } else {
+ echo '<option value=' . $ListPage . '>' . $ListPage . '</option>';
+ }
+ $ListPage++;
+ }
+ echo '</select>
+ <input type="submit" name="Go" value="' . _('Go') . '" />
+ <input type="submit" name="Previous" value="' . _('Previous') . '" />
+ <input type="submit" name="Next" value="' . _('Next') . '" />';
+ echo '<input type="hidden" name=Keywords value="'.$_POST['Keywords'].'" />';
+ echo '<input type="hidden" name=StockCat value="'.$_POST['StockCat'].'" />';
+ echo '<input type="hidden" name=StockCode value="'.$_POST['StockCode'].'" />';
+// echo '<input type="hidden" name=Search value="Search" />';
+ echo '<br /></div>';
+ }
+ echo '<table cellpadding="2">';
+ echo '<tr>
+ <th>' . _('Code') . '</th>
+ <th>' . _('Description') . '</th>
+ <th>' . _('Total Qty On Hand') . '</th>
+ <th>' . _('Units') . '</th>
+ <th>' . _('Stock Status') . '</th>
+ </tr>';
+ $j = 1;
+ $k = 0; //row counter to determine background colour
+ $RowIndex = 0;
+ if (DB_num_rows($searchresult) <> 0) {
+ DB_data_seek($searchresult, ($_POST['PageOffset'] - 1) * $_SESSION['DisplayRecordsMax']);
+ }
+ while (($myrow = DB_fetch_array($searchresult)) AND ($RowIndex <> $_SESSION['DisplayRecordsMax'])) {
+ if ($k == 1) {
+ echo '<tr class="EvenTableRows">';
+ $k = 0;
+ } else {
+ echo '<tr class="OddTableRows">';
+ $k++;
+ }
+ if ($myrow['mbflag'] == 'D') {
+ $qoh = _('N/A');
+ } else {
+ $qoh = locale_number_format($myrow['qoh'], $myrow['decimalplaces']);
+ }
+ if ($myrow['discontinued']==1){
+ $ItemStatus = '<font class="bad">' . _('Obsolete') . '</font>';
+ } else {
+ $ItemStatus ='';
+ }
+
+ echo '<td><input type="submit" name="Select" value="' . $myrow['stockid'] . '" /></td>
+ <td>'.$myrow['description'].'</td>
+ <td class="number">' . $qoh . '</td>
+ <td>' . $myrow['units'] . '</td>
+ <td><a target="_blank" href="' . $rootpath . '/StockStatus.php?StockID=' . $myrow['stockid'].'">' . _('View') . '</a></td>
+ <td>' . $ItemStatus . '</td>
+ </tr>';
+ //end of page full new headings if
+ }
+ //end of while loop
+ echo '</table></form><br />';
+ }
+}
+/* end display list if there is more than one record */
+
+if (isset($SearchResult)) {
+ echo '<br />';
+ echo '<div class="page_help_text">' . _('Select an item by entering the quantity required. Click Order when ready.') . '</div>';
+ echo '<br />';
+ $j = 1;
+ echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '" method="post" name="orderform">';
+ echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
+ echo '<table class="table1">';
+ echo '<tr><td>
+ <input type="hidden" name="previous" value="'.($Offset-1).'" />
+ <input tabindex="'.($j+8).'" type="submit" name="Prev" value="'._('Prev').'" /></td>';
+ echo '<td style="text-align:center" colspan="6">
+ <input type="hidden" name="order_items" value="1" />
+ <input tabindex="'.($j+9).'" type="submit" value="'._('Add to Requisition').'" /></td>';
+ echo '<td>
+ <input type="hidden" name="nextlist" value="'.($Offset+1).'" />
+ <input tabindex="'.($j+10).'" type="submit" name="Next" value="'._('Next').'" /></td></tr>';
+ echo '<tr>
+ <th>' . _('Code') . '</th>
+ <th>' . _('Description') . '</th>
+ <th>' . _('Units') . '</th>
+ <th>' . _('On Hand') . '</th>
+ <th>' . _('On Demand') . '</th>
+ <th>' . _('On Order') . '</th>
+ <th>' . _('Available') . '</th>
+ <th>' . _('Quantity') . '</th>
+ </tr>';
+ $ImageSource = _('No Image');
+
+ $k=0; //row colour counter
+ $i=0;
+ while ($myrow=DB_fetch_array($SearchResult)) {
+ if ($myrow['decimalplaces']=='') {
+ $DecimalPlacesSQL="SELECT decimalplaces
+ FROM stockmaster
+ WHERE stockid='" .$myrow['stockid'] . "'";
+ $DecimalPlacesResult = DB_query($DecimalPlacesSQL, $db);
+ $DecimalPlacesRow = DB_fetch_array($DecimalPlacesResult);
+ $DecimalPlaces = $DecimalPlacesRow['decimalplaces'];
+ } else {
+ $DecimalPlaces=$myrow['decimalplaces'];
+ }
+
+ $QOHSQL = "SELECT sum(locstock.quantity) AS qoh
+ FROM locstock
+ WHERE locstock.stockid='" .$myrow['stockid'] . "' AND
+ loccode = '" . $_SESSION['Request']->Location . "'";
+ $QOHResult = DB_query($QOHSQL,$db);
+ $QOHRow = DB_fetch_array($QOHResult);
+ $QOH = $QOHRow['qoh'];
+
+ // Find the quantity on outstanding sales orders
+ $sql = "SELECT SUM(salesorderdetails.quantity-salesorderdetails.qtyinvoiced) AS dem
+ FROM salesorderdetails,
+ salesorders
+ WHERE salesorders.orderno = salesorderdetails.orderno AND
+ salesorders.fromstkloc='" . $_SESSION['Request']->Location . "' AND
+ salesorderdetails.completed=0 AND
+ salesorders.quotation=0 AND
+ salesorderdetails.stkcode='" . $myrow['stockid'] . "'";
+ $ErrMsg = _('The demand for this product from') . ' ' . $_SESSION['Request']->Location . ' ' . _('cannot be retrieved because');
+ $DemandResult = DB_query($sql,$db,$ErrMsg);
+
+ $DemandRow = DB_fetch_row($DemandResult);
+ if ($DemandRow[0] != null){
+ $DemandQty = $DemandRow[0];
+ } else {
+ $DemandQty = 0;
+ }
+
+ // Find the quantity on purchase orders
+ $sql = "SELECT SUM(purchorderdetails.quantityord-purchorderdetails.quantityrecd)*purchorderdetails.conversionfactor AS dem
+ FROM purchorderdetails LEFT JOIN purchorders
+ ON purchorderdetails.orderno=purchorders.orderno
+ WHERE purchorderdetails.completed=0
+ AND purchorders.status<>'Cancelled'
+ AND purchorders.status<>'Rejected'
+ AND purchorderdetails.itemcode='" . $myrow['stockid'] . "'";
+
+ $ErrMsg = _('The order details for this product cannot be retrieved because');
+ $PurchResult = DB_query($sql,$db,$ErrMsg);
+
+ $PurchRow = DB_fetch_row($PurchResult);
+ if ($PurchRow[0]!=null){
+ $PurchQty = $PurchRow[0];
+ } else {
+ $PurchQty = 0;
+ }
+
+ // Find the quantity on works orders
+ $sql = "SELECT SUM(woitems.qtyreqd - woitems.qtyrecd) AS dedm
+ FROM woitems
+ WHERE stockid='" . $myrow['stockid'] ."'";
+ $ErrMsg = _('The order details for this product cannot be retrieved because');
+ $WoResult = DB_query($sql,$db,$ErrMsg);
+
+ $WoRow = DB_fetch_row($WoResult);
+ if ($WoRow[0]!=null){
+ $WoQty = $WoRow[0];
+ } else {
+ $WoQty = 0;
+ }
+
+ if ($k==1){
+ echo '<tr class="EvenTableRows">';
+ $k=0;
+ } else {
+ echo '<tr class="OddTableRows">';
+ $k=1;
+ }
+ $OnOrder = $PurchQty + $WoQty;
+ $Available = $QOH - $DemandQty + $OnOrder;
+ echo '<td>'.$myrow['stockid'].'</font></td>
+ <td>'.$myrow['description'].'</td>
+ <td>'.$myrow['stockunits'].'</td>
+ <td class="number">'.locale_number_format($QOH,$DecimalPlaces).'</td>
+ <td class="number">'.locale_number_format($DemandQty,$DecimalPlaces).'</td>
+ <td class="number">'.locale_number_format($OnOrder, $DecimalPlaces).'</td>
+ <td class="number">'.locale_number_format($Available,$DecimalPlaces).'</td>
+ <td><font size="1"><input class="number" tabindex="'.($j+7).'" type="text" size="6" name="Quantity'.$i.'" value="0" />
+ <input type="hidden" name="StockID'.$i.'" value="'.$myrow['stockid'].'" />
+ </td>
+ </tr>';
+ echo '<input type="hidden" name="DecimalPlaces'.$i.'" value="' . $myrow['decimalplaces'] . '" />';
+ echo '<input type="hidden" name="ItemDescription'.$i.'" value="' . $myrow['description'] . '" />';
+ echo '<input type="hidden" name="Units'.$i.'" value="' . $myrow['stockunits'] . '" />';
+ if ($j==1) {
+ $jsCall = '<script type="text/javascript">if (document.SelectParts) {defaultControl(document.SelectParts.itm'.$myrow['stockid'].');}</script>';
+ }
+ $i++;
+#end of page full new headings if
+ }
+#end of while loop
+ echo '<tr><td><input type="hidden" name="previous" value="'.($Offset-1).'" />
+ <input tabindex="'.($j+7).'" type="submit" name="Prev" value="'._('Prev').'" /></td>';
+ echo '<td style="text-align:center" colspan="6"><input type="hidden" name="order_items" value="1" />
+ <input tabindex="'.($j+8).'" type="submit" value="'._('Add to Requisition').'" /></td>';
+ echo '<td><input type="hidden" name="nextlist" value="'.($Offset+1).'" />
+ <input tabindex="'.($j+9).'" type="submit" name="Next" value="'._('Next').'" /></td><tr/>';
+ echo '</table></form>';
+ echo $jsCall;
+
+}#end if SearchResults to show
+
+//*********************************************************************************************************
+include('includes/footer.inc');
+?>
\ No newline at end of file
Added: trunk/InternalStockRequestAuthorisation.php
===================================================================
--- trunk/InternalStockRequestAuthorisation.php (rev 0)
+++ trunk/InternalStockRequestAuthorisation.php 2012-02-26 09:19:38 UTC (rev 4973)
@@ -0,0 +1,111 @@
+<?php
+
+/* $Id$*/
+
+include('includes/session.inc');
+
+$title = _('Authorise Internal Stock Requests');
+
+include('includes/header.inc');
+
+echo '<p class="page_title_text"><img src="'.$rootpath.'/css/'.$theme.'/images/transactions.png" title="' . $title . '" alt="" />' . ' ' . $title . '</p>';
+
+$emailsql="SELECT email FROM www_users WHERE userid='".$_SESSION['UserID']."'";
+$emailresult=DB_query($emailsql, $db);
+$emailrow=DB_fetch_array($emailresult);
+
+if (isset($_POST['updateall'])) {
+ foreach ($_POST as $key => $value) {
+ if (mb_substr($key,0,6)=='status') {
+ $RequestNo=mb_substr($key,6);
+ $sql="UPDATE stockrequest
+ SET authorised='1'
+ WHERE dispatchid='".$RequestNo."'";
+ $result=DB_query($sql, $db);
+ }
+ }
+}
+
+/* Retrieve the requisition header information
+ */
+$sql="SELECT stockrequest.dispatchid,
+ locations.locationname,
+ stockrequest.despatchdate,
+ stockrequest.narrative,
+ departments.description,
+ www_users.realname,
+ www_users.email
+ FROM stockrequest
+ LEFT JOIN departments
+ ON stockrequest.departmentid=departments.departmentid
+ LEFT JOIN locations
+ ON stockrequest.loccode=locations.loccode
+ LEFT JOIN www_users
+ ON www_users.userid=departments.authoriser
+ WHERE stockrequest.authorised=0
+ AND stockrequest.closed=0
+ AND www_users.userid='".$_SESSION['UserID']."'";
+$result=DB_query($sql, $db);
+
+echo '<form method="post" action="' . htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '">';
+echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
+echo '<table class="selection">';
+
+/* Create the table for the purchase order header */
+echo '<tr>
+ <th>'._('Request Number').'</th>
+ <th>'._('Department').'</th>
+ <th>'._('Location Of Stock').'</th>
+ <th>'._('Requested Date').'</th>
+ <th>'._('Narrative').'</th>
+ <th>'._('Authorise').'</th>
+ </tr>';
+
+while ($myrow=DB_fetch_array($result)) {
+
+ echo '<tr>
+ <td>'.$myrow['dispatchid'].'</td>
+ <td>'.$myrow['description'].'</td>
+ <td>'.$myrow['locationname'].'</td>
+ <td>'.ConvertSQLDate($myrow['despatchdate']).'</td>
+ <td>'.$myrow['narrative'].'</td>
+ <td><input type="checkbox" name="status'.$myrow['dispatchid'].'" /></td>
+ </tr>';
+ $linesql="SELECT stockrequestitems.dispatchitemsid,
+ stockrequestitems.stockid,
+ stockrequestitems.decimalplaces,
+ stockrequestitems.uom,
+ stockmaster.description,
+ stockrequestitems.quantity
+ FROM stockrequestitems
+ LEFT JOIN stockmaster
+ ON stockmaster.stockid=stockrequestitems.stockid
+ WHERE dispatchid='".$myrow['dispatchid'] . "'";
+ $lineresult=DB_query($linesql, $db);
+
+ echo '<tr>
+ <td></td>
+ <td colspan="5" align="left">
+ <table class="selection" align="left">
+ <tr>
+ <th>'._('Product').'</th>
+ <th>'._('Quantity Required').'</th>
+ <th>'._('Units').'</th>
+ </tr>';
+
+ while ($linerow=DB_fetch_array($lineresult)) {
+ echo '<tr>
+ <td>'.$linerow['description'].'</td>
+ <td class="number">'.locale_number_format($linerow['quantity'],$linerow['decimalplaces']).'</td>
+ <td>'.$linerow['uom'].'</td>
+ </tr>';
+ } // end while order line detail
+ echo '</table>
+ </td>
+ </tr>';
+} //end while header loop
+echo '</table>';
+echo '<br /><div class="centre"><input type="submit" name="updateall" value="' . _('Update'). '" /></form>';
+
+include('includes/footer.inc');
+?>
\ No newline at end of file
Added: trunk/InternalStockRequestFulfill.php
===================================================================
--- trunk/InternalStockRequestFulfill.php (rev 0)
+++ trunk/InternalStockRequestFulfill.php 2012-02-26 09:19:38 UTC (rev 4973)
@@ -0,0 +1,343 @@
+<?php
+
+$PageSecurity=1;
+
+include('includes/session.inc');
+
+$title = _('Fulfill Stock Requests');
+
+include('includes/header.inc');
+include('includes/SQL_CommonFunctions.inc');
+
+echo '<p class="page_title_text"><img src="'.$rootpath.'/css/'.$theme.'/images/inventory.png" title="' . _('Contract') . '" alt="" />' .
+ ' ' . _('Fulfill Stock Requests') . '</p>';
+
+if (isset($_POST['UpdateAll'])) {
+ foreach ($_POST as $key => $value) {
+ if (mb_strpos($key,'Qty')) {
+ $RequestID = mb_substr($key,0, mb_strpos($key,'Qty'));
+ $LineID = mb_substr($key,mb_strpos($key,'Qty')+3);
+ $Quantity = $_POST[$RequestID.'Qty'.$LineID];
+ $StockID = $_POST[$RequestID.'StockID'.$LineID];
+ $Location = $_POST[$RequestID.'Location'.$LineID];
+ $Tag = $_POST[$RequestID.'Tag'.$LineID];
+ $RequestedQuantity = $_POST[$RequestID.'RequestedQuantity'.$LineID];
+ if (isset($_POST[$RequestID.'Completed'.$LineID])) {
+ $Completed=True;
+ } else {
+ $Completed=False;
+ }
+
+ $sql="SELECT materialcost, labourcost, overheadcost FROM stockmaster WHERE stockid='".$StockID."'";
+ $result=DB_query($sql, $db);
+ $myrow=DB_fetch_array($result);
+ $StandardCost=$myrow['materialcost']+$myrow['labourcost']+$myrow['overheadcost'];
+
+ $Narrative = _('Issue') . ' ' . $Quantity . ' ' . _('of') . ' '. $StockID . ' ' . _('to department');
+
+ $AdjustmentNumber = GetNextTransNo(17,$db);
+ $PeriodNo = GetPeriod (Date($_SESSION['DefaultDateFormat']), $db);
+ $SQLAdjustmentDate = FormatDateForSQL(Date($_SESSION['DefaultDateFormat']));
+
+ $Result = DB_Txn_Begin($db);
+
+ // Need to get the current location quantity will need it later for the stock movement
+ $SQL="SELECT locstock.quantity
+ FROM locstock
+ WHERE locstock.stockid='" . $StockID . "'
+ AND loccode= '" . $Location . "'";
+ $Result = DB_query($SQL, $db);
+ if (DB_num_rows($Result)==1){
+ $LocQtyRow = DB_fetch_row($Result);
+ $QtyOnHandPrior = $LocQtyRow[0];
+ } else {
+ // There must actually be some error this should never happen
+ $QtyOnHandPrior = 0;
+ }
+
+ if ($_SESSION['ProhibitNegativeStock']==0 or ($_SESSION['ProhibitNegativeStock']==1 and $QtyOnHandPrior>=$Quantity)) {
+
+ $SQL = "INSERT INTO stockmoves (
+ stockid,
+ type,
+ transno,
+ loccode,
+ trandate,
+ prd,
+ reference,
+ qty,
+ newqoh)
+ VALUES (
+ '" . $StockID . "',
+ 17,
+ '" . $AdjustmentNumber . "',
+ '" . $Location . "',
+ '" . $SQLAdjustmentDate . "',
+ '" . $PeriodNo . "',
+ '" . $Narrative ."',
+ '" . -$Quantity . "',
+ '" . ($QtyOnHandPrior - $Quantity) . "'
+ )";
+
+
+ $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The stock movement record cannot be inserted because');
+ $DbgMsg = _('The following SQL to insert the stock movement record was used');
+ $Result = DB_query($SQL, $db, $ErrMsg, $DbgMsg, true);
+
+
+ /*Get the ID of the StockMove... */
+ $StkMoveNo = DB_Last_Insert_ID($db,'stockmoves','stkmoveno');
+
+ $SQL="UPDATE stockrequestitems
+ SET qtydelivered=qtydelivered+".$Quantity."
+ WHERE dispatchid='".$RequestID."'
+ AND dispatchitemsid='".$LineID."'";
+
+ $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' ._('The location stock record could not be updated because');
+ $DbgMsg = _('The following SQL to update the stock record was used');
+ $Result = DB_query($SQL,$db, $ErrMsg, $DbgMsg,true);
+
+ $SQL = "UPDATE locstock SET quantity = quantity - '" . $Quantity . "'
+ WHERE stockid='" . $StockID . "'
+ AND loccode='" . $Location . "'";
+
+ $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' ._('The location stock record could not be updated because');
+ $DbgMsg = _('The following SQL to update the stock record was used');
+
+ $Result = DB_query($SQL, $db, $ErrMsg, $DbgMsg, true);
+
+ if ($_SESSION['CompanyRecord']['gllink_stock']==1 AND $StandardCost > 0){
+
+ $StockGLCodes = GetStockGLCode($StockID,$db);
+
+ $SQL = "INSERT INTO gltrans (type,
+ typeno,
+ trandate,
+ periodno,
+ account,
+ amount,
+ narrative,
+ tag)
+ VALUES (17,
+ '" .$AdjustmentNumber . "',
+ '" . $SQLAdjustmentDate . "',
+ '" . $PeriodNo . "',
+ '" . $StockGLCodes['issueglact'] . "',
+ '" . $StandardCost * -($Quantity) . "',
+ '" . $Narrative . "',
+ '" . $Tag . "'
+ )";
+
+ $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The general ledger transaction entries could not be added because');
+ $DbgMsg = _('The following SQL to insert the GL entries was used');
+ $Result = DB_query($SQL,$db, $ErrMsg, $DbgMsg, true);
+
+ $SQL = "INSERT INTO gltrans (type,
+ typeno,
+ trandate,
+ periodno,
+ account,
+ amount,
+ narrative,
+ tag)
+ VALUES (17,
+ '" . $AdjustmentNumber . "',
+ '" . $SQLAdjustmentDate . "',
+ '" . $PeriodNo . "',
+ '" . $StockGLCodes['stockact'] . "',
+ '" . $StandardCost * $Quantity . "',
+ '" . $Narrative . "',
+ '" . $Tag . "'
+ )";
+
+ $Errmsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The general ledger transaction entries could not be added because');
+ $DbgMsg = _('The following SQL to insert the GL entries was used');
+ $Result = DB_query($SQL,$db, $ErrMsg, $DbgMsg,true);
+ }
+
+ if (($Quantity>=$RequestedQuantity) or $Completed==True) {
+ $SQL="UPDATE stockrequestitems
+ SET completed=1
+ WHERE dispatchid='".$RequestID."'
+ AND dispatchitemsid='".$LineID."'";
+ $Result = DB_query($SQL,$db, $ErrMsg, $DbgMsg,true);
+ }
+
+ $Result = DB_Txn_Commit($db);
+
+ $ConfirmationText = _('A stock issue for'). ' ' . $StockID . ' ' . _('has been created from location').' ' . $Location .' '. _('for a quantity of') . ' ' . $Quantity ;
+ prnMsg( $ConfirmationText,'success');
+
+ if ($_SESSION['InventoryManagerEmail']!=''){
+ $ConfirmationText = $ConfirmationText . ' ' . _('by user') . ' ' . $_SESSION['UserID'] . ' ' . _('at') . ' ' . Date('Y-m-d H:i:s');
+ $EmailSubject = _('Stock adjustment for'). ' ' . $StockID;
+ mail($_SESSION['InventoryManagerEmail'],$EmailSubject,$ConfirmationText);
+ }
+ } else {
+ $ConfirmationText = _('A stock issue for'). ' ' . $StockID . ' ' . _('from location').' ' . $Location .' '. _('for a quantity of') . ' ' . $Quantity . ' ' . _('cannot be created as there is insufficient stock and your system is configured to not allow negative stocks');
+ prnMsg( $ConfirmationText,'warn');
+ }
+ }
+}
+
+// Check if request can be closed and close if done.
+if (isset($RequestID)) {
+ $SQL="SELECT dispatchid
+ FROM stockrequestitems
+ WHERE dispatchid='".$RequestID."'
+ AND completed=0";
+ $Result=DB_query($SQL, $db);
+ if (DB_num_rows($Result)==0) {
+ $SQL="UPDATE stockrequest
+ SET closed=1
+ WHERE dispatchid='".$RequestID."'";
+ $Result=DB_query($SQL, $db);
+ }
+}
+
+if (!isset($_POST['Location'])) {
+ echo '<form method="post" action="' . htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '">';
+ echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
+ echo '<table class="selection"><tr>';
+ echo '<td>' . _('Choose a location to issue requests from') . '</td>
+ <td><select name="Location">';
+ $sql = "SELECT loccode, locationname FROM locations";
+ $resultStkLocs = DB_query($sql,$db);
+ while ($myrow=DB_fetch_array($resultStkLocs)){
+ if (isset($_SESSION['Adjustment']->StockLocation)){
+ if ($myrow['loccode'] == $_SESSION['Adjustment']->StockLocation){
+ echo '<option selected="True" value="' . $myrow['loccode'] . '">' . $myrow['locationname'] . '</option>';
+ } else {
+ echo '<option value="' . $myrow['loccode'] . '">' . $myrow['locationname'] . '</option>';
+ }
+ } elseif ($myrow['loccode']==$_SESSION['UserStockLocation']){
+ echo '<option selected="True" value="' . $myrow['loccode'] . '">' . $myrow['locationname'] . '</option>';
+ $_POST['StockLocation']=$myrow['loccode'];
+ } else {
+ echo '<option value="' . $myrow['loccode'] . '">' . $myrow['locationname'] . '</option>';
+ }
+ }
+ echo '</select></td></tr>';
+ echo '</table><br />';
+ echo '<div class="centre"><input type="submit" name="EnterAdjustment" value="'. _('Show Requests'). '" /></div>';
+ include('includes/footer.inc');
+ exit;
+}
+
+/* Retrieve the requisition header information
+ */
+if (isset($_POST['Location'])) {
+ $sql="SELECT stockrequest.dispatchid,
+ locations.locationname,
+ stockrequest.despatchdate,
+ stockrequest.narrative,
+ departments.description,
+ www_users.realname,
+ www_users.email
+ FROM stockrequest
+ LEFT JOIN departments
+ ON stockrequest.departmentid=departments.departmentid
+ LEFT JOIN locations
+ ON stockrequest.loccode=locations.loccode
+ LEFT JOIN www_users
+ ON www_users.userid=departments.authoriser
+ WHERE stockrequest.authorised=1
+ AND stockrequest.closed=0
+ AND stockrequest.loccode='".$_POST['Location']."'";
+ $result=DB_query($sql, $db);
+
+ if (DB_num_rows($result)==0) {
+ prnMsg( _('There are no outstanding authorised requests for this location'), 'info');
+ echo '<br />';
+ echo '<div class="centre"><a href="' . $_SESSION['FormID'] . '">' . _('Select another location') . '</a></div>';
+ include('includes/footer.inc');
+ exit;
+ }
+
+ echo '<form method="post" action="' . htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '">';
+ echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
+ echo '<table class="selection"><tr>';
+
+ /* Create the table for the purchase order header */
+ echo '<th>'._('Request Number').'</th>';
+ echo '<th>'._('Department').'</th>';
+ echo '<th>'._('Location Of Stock').'</th>';
+ echo '<th>'._('Requested Date').'</th>';
+ echo '<th>'._('Narrative').'</th>';
+ echo '</tr>';
+
+ while ($myrow=DB_fetch_array($result)) {
+
+ echo '<tr>';
+ echo '<td>'.$myrow['dispatchid'].'</td>';
+ echo '<td>'.$myrow['description'].'</td>';
+ echo '<td>'.$myrow['locationname'].'</td>';
+ echo '<td>'.ConvertSQLDate($myrow['despatchdate']).'</td>';
+ echo '<td>'.$myrow['narrative'].'</td>';
+ echo '</tr>';
+ $linesql="SELECT stockrequestitems.dispatchitemsid,
+ stockrequestitems.dispatchid,
+ stockrequestitems.stockid,
+ stockrequestitems.decimalplaces,
+ stockrequestitems.uom,
+ stockmaster.description,
+ stockrequestitems.quantity,
+ stockrequestitems.qtydelivered
+ FROM stockrequestitems
+ LEFT JOIN stockmaster
+ ON stockmaster.stockid=stockrequestitems.stockid
+ WHERE dispatchid='".$myrow['dispatchid'] . "'
+ AND completed=0";
+ $lineresult=DB_query($linesql, $db);
+
+ echo '<tr><td></td><td colspan="5" align="left"><table class="selection" align="left">';
+ echo '<th>'._('Product').'</th>';
+ echo '<th>'._('Quantity') . '<br />' . _('Required').'</th>';
+ echo '<th>'._('Quantity') . '<br />' . _('Delivered').'</th>';
+ echo '<th>'._('Units').'</th>';
+ echo '<th>'._('Completed').'</th>';
+ echo '<th>'._('Tag').'</th>';
+ echo '</tr>';
+
+ while ($linerow=DB_fetch_array($lineresult)) {
+ echo '<tr>';
+ echo '<td>'.$linerow['description'].'</td>';
+ echo '<td class="number">'.locale_number_format($linerow['quantity']-$linerow['qtydelivered'],$linerow['decimalplaces']).'</td>';
+ echo '<td class="number">
+ <input type="text" class="number" name="'. $linerow['dispatchid'] . 'Qty'. $linerow['dispatchitemsid'] . '" value="'.locale_number_format($linerow['quantity']-$linerow['qtydelivered'],$linerow['decimalplaces']).'" />
+ </td>';
+ echo '<td>'.$linerow['uom'].'</td>';
+ echo '<td><input type="checkbox" name="'. $linerow['dispatchid'] . 'Completed'. $linerow['dispatchitemsid'] . '" /></td>';
+ //Select the tag
+ echo '<td><select name="'. $linerow['dispatchid'] . 'Tag'. $linerow['dispatchitemsid'] . '">';
+
+ $SQL = "SELECT tagref,
+ tagdescription
+ FROM tags
+ ORDER BY tagref";
+
+ $TagResult=DB_query($SQL,$db);
+ echo '<option value=0>0 - None</option>';
+ while ($mytagrow=DB_fetch_array($TagResult)){
+ if (isset($_SESSION['Adjustment']->tag) and $_SESSION['Adjustment']->tag==$mytagrow['tagref']){
+ echo '<option selected="True" value="' . $mytagrow['tagref'] . '">' . $mytagrow['tagref'].' - ' .$myrow['tagdescription'] . '</option>';
+ } else {
+ echo '<option value="' . $mytagrow['tagref'] . '">' . $mytagrow['tagref'].' - ' .$mytagrow['tagdescription'] . '</option>';
+ }
+ }
+ echo '</select></td>';
+// End select tag
+ echo '</tr>';
+ echo '<input type="hidden" class="number" name="'. $linerow['dispatchid'] . 'StockID'. $linerow['dispatchitemsid'] . '" value="'.$linerow['stockid'].'" />';
+ echo '<input type="hidden" class="number" name="'. $linerow['dispatchid'] . 'Location'. $linerow['dispatchitemsid'] . '" value="'.$_POST['Location'].'" />';
+ echo '<input type="hidden" class="number" name="'. $linerow['dispatchid'] . 'RequestedQuantity'. $linerow['dispatchitemsid'] . '" value="'.locale_number_format($linerow['quantity']-$linerow['qtydelivered'],$linerow['decimalplaces']).'" />';
+ } // end while order line detail
+ echo '</table></td></tr>';
+ } //end while header loop
+ echo '</table>';
+ echo '<br /><div class="centre"><input type="submit" name="UpdateAll" value="' . _('Update'). '" /></form>';
+}
+
+include('includes/footer.inc');
+
+?>
\ No newline at end of file
Modified: trunk/StockCategories.php
===================================================================
--- trunk/StockCategories.php 2012-02-25 23:23:53 UTC (rev 4972)
+++ trunk/StockCategories.php 2012-02-26 09:19:38 UTC (rev 4973)
@@ -7,9 +7,7 @@
include('includes/header.inc');
-echo '<p class="page_title_text">
- <img src="'.$rootpath.'/css/'.$theme.'/images/supplier.png" title="' . _('Inventory Adjustment') . '" alt="" />' . ' ' . $title . '
- </p>';
+echo '<p class="page_title_text"><img src="'.$rootpath.'/css/'.$theme.'/images/supplier.png" title="' . _('Inventory Adjustment') . '" alt="" />' . ' ' . $title . '</p>';
if (isset($_GET['SelectedCategory'])){
$SelectedCategory = mb_strtoupper($_GET['SelectedCategory']);
@@ -57,102 +55,110 @@
if (!is_numeric(filter_number_format($_POST['PropMinimum' .$i]))){
$InputError = 1;
prnMsg(_('The minimum value is expected to be a numeric value'),'error');
- }
- if (!is_numeric(filter_number_format($_POST['PropMaximum' .$i]))){
+ }
+ if (!is_numeric(filter_number_format($_POST['PropMaximum' .$i]))){
$InputError = 1;
prnMsg(_('The maximum value is expected to be a numeric value'),'error');
- }
+ }
}
} //check the properties are sensible
- if ($SelectedCategory AND $InputError !=1) {
+ if (isset($SelectedCategory) AND $InputError !=1) {
/*SelectedCategory could also exist if submit had not been clicked this code
would not run in this case cos submit is false of course see the
delete code below*/
$sql = "UPDATE stockcategory SET stocktype = '" . $_POST['StockType'] . "',
- categorydescription = '" . $_POST['CategoryDescription'] . "',
- stockact = " . $_POST['StockAct'] . ",
- adjglact = " . $_POST['AdjGLAct'] . ",
- purchpricevaract = " . $_POST['PurchPriceVarAct'] . ",
- materialuseagevarac = " . $_POST['MaterialUseageVarAc'] . ",
- wipact = " . $_POST['WIPAct'] . "
- WHERE
- categoryid = '$SelectedCategory'";
- $ErrMsg = _('Could not update the stock category') . $_POST['CategoryDescription'] . _('because');
- $result = DB_query($sql,$db,$ErrMsg);
+ categorydescription = '" . $_POST['CategoryDescription'] . "',
+ stockact = " . $_POST['StockAct'] . ",
+ adjglact = " . $_POST['AdjGLAct'] . ",
+ issueglact = " . $_POST['IssueGLAct'] . ",
+ purchpricevaract = " . $_POST['PurchPriceVarAct'] . ",
+ materialuseagevarac = " . $_POST['MaterialUseageVarAc'] . ",
+ wipact = " . $_POST['WIPAct'] . "
+ WHERE
+ categoryid = '$SelectedCategory'";
+ $ErrMsg = _('Could not update the stock category') . $_POST['CategoryDescription'] . _('because');
+ $result = DB_query($sql,$db,$ErrMsg);
- for ($i=0;$i<=$_POST['PropertyCounter'];$i++){
+ if ($_POST['PropertyCounter']==0 and $_POST['PropLabel0']!='') {
+ $_POST['PropertyCounter']=0;
+ }
- if (isset($_POST['PropReqSO' .$i]) and $_POST['PropReqSO' .$i] == true){
- $_POST['PropReqSO' .$i] =1;
- } else {
- $_POST['PropReqSO' .$i] =0;
- }
- if (isset($_POST['PropNumeric' .$i]) and $_POST['PropNumeric' .$i] == true){
- $_POST['PropNumeric' .$i] =1;
- } else {
- $_POST['PropNumeric' .$i] =0;
- }
- if ($_POST['PropID' .$i] =='NewProperty' AND mb_strlen($_POST['PropLabel'.$i])>0){
- $sql = "INSERT INTO stockcatproperties (categoryid,
- label,
- controltype,
- defaultvalue,
- minimumvalue,
- maximumvalue,
- numericvalue,
- reqatsalesorder)
- VALUES ('" . $SelectedCategory . "',
- '" . $_POST['PropLabel' . $i] . "',
- " . $_POST['PropControlType' . $i] . ",
- '" . $_POST['PropDefault' .$i] . "',
- '" . filter_number...
[truncated message content] |