From: <tim...@us...> - 2010-06-24 19:31:15
|
Revision: 3520 http://web-erp.svn.sourceforge.net/web-erp/?rev=3520&view=rev Author: tim_schofield Date: 2010-06-24 19:31:09 +0000 (Thu, 24 Jun 2010) Log Message: ----------- sql string must be unset before it can become an array Modified Paths: -------------- trunk/WorkOrderEntry.php trunk/doc/Change.log.html Modified: trunk/WorkOrderEntry.php =================================================================== --- trunk/WorkOrderEntry.php 2010-06-24 16:42:16 UTC (rev 3519) +++ trunk/WorkOrderEntry.php 2010-06-24 19:31:09 UTC (rev 3520) @@ -9,33 +9,37 @@ include('includes/header.inc'); include('includes/SQL_CommonFunctions.inc'); +echo '<p class="page_title_text"><img src="'.$rootpath.'/css/'.$theme.'/images/transactions.png" title="' . _('Search') . + '" alt="">' . ' ' . $title.'</p>'; -echo '<p class="page_title_text"><img src="'.$rootpath.'/css/'.$theme.'/images/transactions.png" title="' . _('Search') . '" alt="">' . ' ' . $title; - if (isset($_GET['ReqDate'])){ $ReqDate = $_GET['ReqDate']; +} else { + $ReqDate=Date('Y-m-d'); } if (isset($_GET['loccode'])){ $LocCode = $_GET['loccode']; +} else { + $LocCode=$_SESSION['UserStockLocation']; } // check for new or modify condition if (isset($_REQUEST['WO']) and $_REQUEST['WO']!=''){ // modify $_POST['WO'] = $_REQUEST['WO']; - $EditingExisting = true; + $EditingExisting = true; } else { // new - $_POST['WO'] = GetNextTransNo(40,$db); - $sql = "INSERT INTO workorders (wo, + $_POST['WO'] = GetNextTransNo(40,$db); + $sql = "INSERT INTO workorders (wo, loccode, requiredby, startdate) VALUES (" . $_POST['WO'] . ", - '" . (($LocCode) ? $LocCode : $_SESSION['UserStockLocation']) . "', - '" . (($ReqDate) ? $ReqDate : Date('Y-m-d')) . "', + '" . $LocCode . "', + '" . $ReqDate . "', '" . Date('Y-m-d'). "')"; - $InsWOResult = DB_query($sql,$db); + $InsWOResult = DB_query($sql,$db); } @@ -63,7 +67,7 @@ //insert wildcard characters in spaces $_POST['Keywords'] = strtoupper($_POST['Keywords']); $SearchString = '%' . str_replace(' ', '%', $_POST['Keywords']) . '%'; - + if ($_POST['StockCat']=='All'){ $SQL = "SELECT stockmaster.stockid, stockmaster.description, @@ -166,7 +170,8 @@ } //end of if search if (isset($NewItem) AND isset($_POST['WO'])){ - $InputError=false; + + $InputError=false; $CheckItemResult = DB_query("SELECT mbflag, eoq, controlled @@ -178,7 +183,10 @@ if ($CheckItemRow['controlled']==1 AND $_SESSION['DefineControlledOnWOEntry']==1){ //need to add serial nos or batches to determine quantity $EOQ = 0; } else { - $EOQ = ($ReqQty) ? $ReqQty : $CheckItemRow['eoq']; + if (!isset($ReqQty)) { + $ReqQty=$CheckItemRow['eoq']; + } + $EOQ = $ReqQty; } if ($CheckItemRow['mbflag']!='M'){ prnMsg(_('The item selected cannot be added to a work order because it is not a manufactured item'),'warn'); @@ -201,12 +209,12 @@ if ($InputError==false){ $CostResult = DB_query("SELECT SUM((materialcost+labourcost+overheadcost)*bom.quantity) AS cost - FROM stockmaster INNER JOIN bom - ON stockmaster.stockid=bom.component - WHERE bom.parent='" . $NewItem . "' - AND bom.loccode='" . $_POST['StockLocation'] . "'", - $db); - $CostRow = DB_fetch_row($CostResult); + FROM stockmaster INNER JOIN bom + ON stockmaster.stockid=bom.component + WHERE bom.parent='" . $NewItem . "' + AND bom.loccode='" . $_POST['StockLocation'] . "'", + $db); + $CostRow = DB_fetch_row($CostResult); if (is_null($CostRow[0]) OR $CostRow[0]==0){ $Cost =0; prnMsg(_('The cost of this item as accumulated from the sum of the component costs is nil. This could be because there is no bill of material set up ... you may wish to double check this'),'warn'); @@ -217,25 +225,25 @@ $EOQ=1; } - $Result = DB_Txn_Begin($db); + $Result = DB_Txn_Begin($db); // insert parent item info $sql = "INSERT INTO woitems (wo, - stockid, - qtyreqd, - stdcost) - VALUES ( " . $_POST['WO'] . ", - '" . $NewItem . "', - " . $EOQ . ", - " . $Cost . " - )"; + stockid, + qtyreqd, + stdcost) + VALUES ( " . $_POST['WO'] . ", + '" . $NewItem . "', + " . $EOQ . ", + " . $Cost . " + )"; $ErrMsg = _('The work order item could not be added'); $result = DB_query($sql,$db,$ErrMsg); //Recursively insert real component requirements - see includes/SQL_CommonFunctions.in for function WoRealRequirements WoRealRequirements($db, $_POST['WO'], $_POST['StockLocation'], $NewItem); - $result = DB_Txn_Commit($db); + $result = DB_Txn_Commit($db); unset($NewItem); } //end if there were no input errors @@ -244,20 +252,24 @@ if (isset($_POST['submit'])) { //The update button has been clicked + echo '<a href="' . $_SERVER['PHP_SELF'] . '?' . SID . "'>" . _('Enter a new work order') . '</a>'; + echo '<br><a href="' . $rootpath . '/SelectWorkOrder.php?' . SID . '">' . _('Select an existing work order') . '</a>'; + echo '<br><a href="'. $rootpath . '/WorkOrderCosting.php?' . SID . '&WO=' . $_REQUEST['WO'] . '">' . _('Go to Costing'). '</a>'; + $Input_Error = false; //hope for the best - for ($i=1;$i<=$_POST['NumberOfOutputs'];$i++){ - if (!is_numeric($_POST['OutputQty'.$i])){ - prnMsg(_('The quantity entered must be numeric'),'error'); - $Input_Error = true; - } elseif ($_POST['OutputQty'.$i]<=0){ - prnMsg(_('The quantity entered must be a positive number greater than zero'),'error'); - $Input_Error = true; - } - } - if (!Is_Date($_POST['RequiredBy'])){ - prnMsg(_('The required by date entered is in an invalid format'),'error'); - $Input_Error = true; + for ($i=1;$i<=$_POST['NumberOfOutputs'];$i++){ + if (!is_numeric($_POST['OutputQty'.$i])){ + prnMsg(_('The quantity entered must be numeric'),'error'); + $Input_Error = true; + } elseif ($_POST['OutputQty'.$i]<=0){ + prnMsg(_('The quantity entered must be a positive number greater than zero'),'error'); + $Input_Error = true; + } } + if (!Is_Date($_POST['RequiredBy'])){ + prnMsg(_('The required by date entered is in an invalid format'),'error'); + $Input_Error = true; + } if ($Input_Error == false) { @@ -267,32 +279,34 @@ for ($i=1;$i<=$_POST['NumberOfOutputs'];$i++){ $QtyRecd+=$_POST['RecdQty'.$i]; } + unset($sql); if ($QtyRecd==0){ //can only change factory location if Qty Recd is 0 $sql[] = "UPDATE workorders SET requiredby='" . $SQL_ReqDate . "', loccode='" . $_POST['StockLocation'] . "' - WHERE wo=" . $_POST['WO']; + WHERE wo=" . $_POST['WO']; } else { prnMsg(_('The factory where this work order is made can only be updated if the quantity received on all output items is 0'),'warn'); $sql[] = "UPDATE workorders SET requiredby='" . $SQL_ReqDate . "' WHERE wo=" . $_POST['WO']; } - for ($i=1;$i<=$_POST['NumberOfOutputs'];$i++){ - if (!isset($_POST['NextLotSNRef'.$i])) { - $_POST['NextLotSNRef'.$i]=''; - } - if (isset($_POST['QtyRecd'.$i]) and $_POST['QtyRecd'.$i]>$_POST['OutputQty'.$i]){ - $_POST['OutputQty'.$i]=$_POST['QtyRecd'.$i]; //OutputQty must be >= Qty already reced - } - if ($_POST['RecdQty'.$i]==0 AND $_POST['HasWOSerialNos'.$i]==false){ // can only change location cost if QtyRecd=0 - $CostResult = DB_query("SELECT SUM((materialcost+labourcost+overheadcost)*bom.quantity) AS cost - FROM stockmaster INNER JOIN bom - ON stockmaster.stockid=bom.component - WHERE bom.parent='" . $_POST['OutputItem'.$i] . "' - AND bom.loccode='" . $_POST['StockLocation'] . "'", - $db); - $CostRow = DB_fetch_row($CostResult); + for ($i=1;$i<=$_POST['NumberOfOutputs'];$i++){ + if (!isset($_POST['NextLotSNRef'.$i])) { + $_POST['NextLotSNRef'.$i]=''; + } + if (isset($_POST['QtyRecd'.$i]) and $_POST['QtyRecd'.$i]>$_POST['OutputQty'.$i]){ + $_POST['OutputQty'.$i]=$_POST['QtyRecd'.$i]; //OutputQty must be >= Qty already reced + } + if ($_POST['RecdQty'.$i]==0 AND $_POST['HasWOSerialNos'.$i]==false){ + /* can only change location cost if QtyRecd=0 */ + $CostResult = DB_query("SELECT SUM((materialcost+labourcost+overheadcost)*bom.quantity) AS cost + FROM stockmaster INNER JOIN bom + ON stockmaster.stockid=bom.component + WHERE bom.parent='" . $_POST['OutputItem'.$i] . "' + AND bom.loccode='" . $_POST['StockLocation'] . "'", + $db); + $CostRow = DB_fetch_row($CostResult); if (is_null($CostRow[0])){ $Cost =0; prnMsg(_('The cost of this item as accumulated from the sum of the component costs is nil. This could be because there is no bill of material set up ... you may wish to double check this'),'warn'); @@ -300,39 +314,35 @@ $Cost = $CostRow[0]; } $sql[] = "UPDATE woitems SET qtyreqd = ". $_POST['OutputQty' . $i] . ", - nextlotsnref = '". $_POST['NextLotSNRef'.$i] ."', - stdcost =" . $Cost . " - WHERE wo=" . $_POST['WO'] . " - AND stockid='" . $_POST['OutputItem'.$i] . "'"; - } elseif ($_POST['HasWOSerialNos'.$i]==false) { - $sql[] = "UPDATE woitems SET qtyreqd = ". $_POST['OutputQty' . $i] . ", - nextlotsnref = '". $_POST['NextLotSNRef'.$i] ."' - WHERE wo=" . $_POST['WO'] . " - AND stockid='" . $_POST['OutputItem'.$i] . "'"; - } - } + nextlotsnref = '". $_POST['NextLotSNRef'.$i] ."', + stdcost =" . $Cost . " + WHERE wo=" . $_POST['WO'] . " + AND stockid='" . $_POST['OutputItem'.$i] . "'"; + } elseif (isset($_POST['HasWOSerialNos'.$i]) and $_POST['HasWOSerialNos'.$i]==false) { + $sql[] = "UPDATE woitems SET qtyreqd = ". $_POST['OutputQty' . $i] . ", + nextlotsnref = '". $_POST['NextLotSNRef'.$i] ."' + WHERE wo=" . $_POST['WO'] . " + AND stockid='" . $_POST['OutputItem'.$i] . "'"; + } + } //run the SQL from either of the above possibilites - $ErrMsg = _('The work order could not be added/updated'); - foreach ($sql as $sql_stmt){ - // echo '<br>' . $sql_stmt; - $result = DB_query($sql_stmt,$db,$ErrMsg); + $ErrMsg = _('The work order could not be added/updated'); + foreach ($sql as $sql_stmt){ + // echo '<br>' . $sql_stmt; + $result = DB_query($sql_stmt,$db,$ErrMsg); - } + } - prnMsg(_('The work order has been updated'),'success'); + prnMsg(_('The work order has been updated'),'success'); - for ($i=1;$i<=$_POST['NumberOfOutputs'];$i++){ - unset($_POST['OutputItem'.$i]); - unset($_POST['OutputQty'.$i]); - unset($_POST['QtyRecd'.$i]); - unset($_POST['NetLotSNRef'.$i]); - unset($_POST['HasWOSerialNos'.$i]); - } - echo '<br><a href="' . $_SERVER['PHP_SELF'] . '?' . SID . "'>" . _('Enter a new work order') . '</a>'; - echo '<br><a href="' . $rootpath . '/SelectWorkOrder.php?' . SID . '">' . _('Select an existing work order') . '</a>'; - echo '<br><a href="'. $rootpath . '/WorkOrderCosting.php?' . SID . '&WO=' . $_REQUEST['WO'] . '">' . _('Go to Costing'). '</a>'; - echo '<br><br>'; + for ($i=1;$i<=$_POST['NumberOfOutputs'];$i++){ + unset($_POST['OutputItem'.$i]); + unset($_POST['OutputQty'.$i]); + unset($_POST['QtyRecd'.$i]); + unset($_POST['NetLotSNRef'.$i]); + unset($_POST['HasWOSerialNos'.$i]); + } } } elseif (isset($_POST['delete'])) { //the link to delete a selected record was clicked instead of the submit button @@ -341,8 +351,8 @@ // can't delete it there are open work issues $HasTransResult = DB_query("SELECT * FROM stockmoves - WHERE (stockmoves.type= 26 OR stockmoves.type=28) - AND reference LIKE '%" . $_POST['WO'] . "%'",$db); + WHERE (stockmoves.type= 26 OR stockmoves.type=28) + AND reference LIKE '%" . $_POST['WO'] . "%'",$db); if (DB_num_rows($HasTransResult)>0){ prnMsg(_('This work order cannot be deleted because it has issues or receipts related to it'),'error'); $CancelDelete=true; @@ -352,50 +362,49 @@ DB_Txn_Begin($db); //delete the worequirements $sql = "DELETE FROM worequirements WHERE wo=" . $_POST['WO']; - $result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true); + $result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true); //delete the items on the work order $sql = "DELETE FROM woitems WHERE wo=" . $_POST['WO']; - $result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true); - //delete the controlled items defined in wip + $result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true); + //delete the controlled items defined in wip $sql="DELETE FROM woserialnos WHERE wo=" . $_POST['WO']; - $ErrMsg=_('The work order serial numbers could not be deleted'); + $ErrMsg=_('The work order serial numbers could not be deleted'); $result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true); // delete the actual work order $sql="DELETE FROM workorders WHERE wo=" . $_POST['WO']; - $ErrMsg=_('The work order could not be deleted'); + $ErrMsg=_('The work order could not be deleted'); $result = DB_query($sql,$db,$ErrMsg,$DbgMsg,true); DB_Txn_Commit($db); - prnMsg(_('The work order has been deleted'),'success'); + prnMsg(_('The work order has been deleted'),'success'); echo "<p><a href='" . $rootpath . "/SelectWorkOrder.php?" . SID . "'>" . _('Select an existing outstanding work order') . "</a>"; unset($_POST['WO']); for ($i=1;$i<=$_POST['NumberOfOutputs'];$i++){ - unset($_POST['OutputItem'.$i]); - unset($_POST['OutputQty'.$i]); - unset($_POST['QtyRecd'.$i]); - unset($_POST['NetLotSNRef'.$i]); - unset($_POST['HasWOSerialNos'.$i]); - } - include('includes/footer.inc'); - exit; - } + unset($_POST['OutputItem'.$i]); + unset($_POST['OutputQty'.$i]); + unset($_POST['QtyRecd'.$i]); + unset($_POST['NetLotSNRef'.$i]); + unset($_POST['HasWOSerialNos'.$i]); + } + include('includes/footer.inc'); + exit; + } } echo '<form method="post" action="' . $_SERVER['PHP_SELF'] . '" name="form">'; -echo '<table>'; +echo '<br><table class=selection>'; - $sql="SELECT workorders.loccode, - requiredby, - startdate, - costissued, - closed - FROM workorders INNER JOIN locations - ON workorders.loccode=locations.loccode - WHERE workorders.wo=" . $_POST['WO']; + requiredby, + startdate, + costissued, + closed + FROM workorders INNER JOIN locations + ON workorders.loccode=locations.loccode + WHERE workorders.wo=" . $_POST['WO']; $WOResult = DB_query($sql,$db); if (DB_num_rows($WOResult)==1){ @@ -429,16 +438,16 @@ if ($WOItem['serialised']==1 AND $WOItem['nextserialno']>0){ $_POST['NextLotSNRef' .$i]=$WOItem['nextserialno']; } else { - $_POST['NextLotSNRef' .$i]=$WOItem['nextlotserialno']; - } + $_POST['NextLotSNRef' .$i]=$WOItem['nextlotsnref']; + } $_POST['Controlled'.$i] =$WOItem['controlled']; $_POST['Serialised'.$i] =$WOItem['serialised']; $HasWOSerialNosResult = DB_query('SELECT * FROM woserialnos WHERE wo=' . $_POST['WO'],$db); if (DB_num_rows($HasWOSerialNosResult)>0){ $_POST['HasWOSerialNos']=true; } else { - $_POST['HasWOSerialNos']=false; - } + $_POST['HasWOSerialNos']=false; + } $i++; } } @@ -469,11 +478,12 @@ } echo '<tr><td class="label">' . _('Required By') . ':</td> - <td><input type="textbox" name="RequiredBy" size=12 maxlength=12 value="' . $_POST['RequiredBy'] . '" onChange="return isDate(this, this.value, '."'".$_SESSION['DefaultDateFormat']."'".')'.'"'.'></td></tr>'; + <td><input type="textbox" name="RequiredBy" size=12 maxlength=12 value="' . $_POST['RequiredBy'] . + '" class="date" alt="'.$_SESSION['DefaultDateFormat'].'"></td></tr>'; if (isset($WOResult)){ echo '<tr><td class="label">' . _('Accumulated Costs') . ':</td> - <td>' . number_format($myrow['costissued'],2) . '</td></tr>'; + <td class=number>' . number_format($myrow['costissued'],2) . '</td></tr>'; } echo '</table> <p><table>'; @@ -483,22 +493,30 @@ <th>' . _('Balance Remaining') . '</th> <th>' . _('Next Lot/SN Ref') . '</th> </tr>'; +$j=0; - if (isset($NumberOfOutputs)){ for ($i=1;$i<=$NumberOfOutputs;$i++){ - echo '<tr><td><input type="hidden" name="OutputItem' . $i . '" value="' . $_POST['OutputItem' .$i] . '">' . $_POST['OutputItem' . $i] . ' - ' . $_POST['OutputItemDesc' .$i] . '</td>'; + if ($j==1) { + echo '<tr class="OddTableRows">'; + $j=0; + } else { + echo '<tr class="EvenTableRows">'; + $j++; + } + echo '<td><input type="hidden" name="OutputItem' . $i . '" value="' . $_POST['OutputItem' .$i] . '">' . + $_POST['OutputItem' . $i] . ' - ' . $_POST['OutputItemDesc' .$i] . '</td>'; if ($_POST['Controlled'.$i]==1 AND $_SESSION['DefineControlledOnWOEntry']==1){ echo '<td style="text-align: right">' . $_POST['OutputQty' . $i] . '</td>'; echo '<input type="hidden" name="OutputQty' . $i .'" value=' . $_POST['OutputQty' . $i] . '>'; } else { echo'<td><input type="text" class="number" name="OutputQty' . $i . '" value=' . $_POST['OutputQty' . $i] . ' size=10 maxlength=10></td>'; } - echo '<td><input type="hidden" name="RecdQty' . $i . '" value=' . $_POST['RecdQty' .$i] . '>' . $_POST['RecdQty' .$i] .'</td> - <td align="right">' . ($_POST['OutputQty' . $i] - $_POST['RecdQty' .$i]) . '</td>'; + echo '<td class=number><input type="hidden" name="RecdQty' . $i . '" value=' . $_POST['RecdQty' .$i] . '>' . $_POST['RecdQty' .$i] .'</td> + <td class=number>' . ($_POST['OutputQty' . $i] - $_POST['RecdQty' .$i]) . '</td>'; if ($_POST['Controlled'.$i]==1){ echo '<td><input type="text" name="NextLotSNRef' .$i . '" value="' . $_POST['NextLotSNRef'.$i] . '"></td>'; - if ($_SESSION['DefineControlledOnWOEntry']==1){ + if ($_SESSION['DefineControlledOnWOEntry']==1){ if ($_POST['Serialised' . $i]==1){ $LotOrSN = _('S/Ns'); } else { @@ -511,9 +529,15 @@ wikiLink('WorkOrder', $_POST['WO'] . $_POST['OutputItem' .$i]); echo '</td>'; echo '</tr>'; - echo '<input type="hidden" name="Controlled' . $i .'" value="' . $_POST['Controlled' . $i] . '">'; - echo '<input type="hidden" name="Serialised' . $i .'" value="' . $_POST['Serialised' . $i] . '">'; - echo '<input type="hidden" name="HasWOSerialNos' . $i .'" value="' . $_POST['HasWOSerialNos' . $i] . '">'; + if (isset($_POST['Controlled' . $i])) { + echo '<input type="hidden" name="Controlled' . $i .'" value="' . $_POST['Controlled' . $i] . '">'; + } + if (isset( $_POST['Serialised' . $i])) { + echo '<input type="hidden" name="Serialised' . $i .'" value="' . $_POST['Serialised' . $i] . '">'; + } + if (isset($_POST['HasWOSerialNos' . $i])) { + echo '<input type="hidden" name="HasWOSerialNos' . $i .'" value="' . $_POST['HasWOSerialNos' . $i] . '">'; + } } echo '<input type=hidden name="NumberOfOutputs" value=' . ($i -1).'>'; } @@ -556,7 +580,7 @@ <td><input type="Text" name="Keywords" size=20 maxlength=25 VALUE="<?php if (isset($_POST['Keywords'])) echo $_POST['Keywords']; ?>"></td></tr> <tr><td></td> <td><font SIZE 3><b><?php echo _('OR'); ?> </b></font><font size=2><?php echo _('Enter extract of the'); ?> <b><?php echo _('Stock Code'); ?></b>:</font></td> - <td><input type="Text" name="StockCode" size=15 maxlength=18 VALUE="<?php if (isset($_POST['StockCode'])) echo $_POST['StockCode']; ?>"></td> + <td><input type="Text" name="StockCode" size=15 maxlength=18 VALUE="<?php if (isset($_POST['StockCode'])) echo $_POST['StockCode']; ?>"></td> </tr> </table> <div class="centre"><input type=submit name="Search" VALUE="<?php echo _('Search Now'); ?>"> @@ -571,8 +595,8 @@ echo '<table cellpadding=2 colspan=7 BORDER=1>'; $TableHeader = '<tr><th>' . _('Code') . '</th> - <th>' . _('Description') . '</th> - <th>' . _('Units') . '</th></tr>'; + <th>' . _('Description') . '</th> + <th>' . _('Units') . '</th></tr>'; echo $TableHeader; $j = 1; $k=0; //row colour counter Modified: trunk/doc/Change.log.html =================================================================== --- trunk/doc/Change.log.html 2010-06-24 16:42:16 UTC (rev 3519) +++ trunk/doc/Change.log.html 2010-06-24 19:31:09 UTC (rev 3520) @@ -1,5 +1,6 @@ <p><font SIZE=4 COLOR=BLUE><b>webERP Change Log</b></font></p> <p></p> +<p>24/06/10 Tim: WorkOrderEntry.php - sql string must be unset before it can become an array</p> <p>24/06/10 Tim: upgrade3.11.1-3.12.sql - Add fields in salesorderfdetails table to enable new salesman commission program</p> <p>24/06/10 Phil: WOCosting.php fix to variances calculation were based on total quantity of the work order items required not the actual quantity of the work order items received as finished!!! Was correct when first released but has been wrong for several years</p> <p>24/06/10 Tim: Update SMTP server details from the UI rather than hard code into the scripts.</p> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |