Fixed a couple of bugs in stock list and account list search.
[fa-stable.git] / manufacturing / includes / db / work_order_requirements_db.inc
index a96af69ebe9bd973adacc683a142177f5364b3f3..9422961f7c69ff8275ebcdcf35200181c4ca0e57 100644 (file)
@@ -1,25 +1,25 @@
 <?php
 /**********************************************************************
     Copyright (C) FrontAccounting, LLC.
-       Released under the terms of the GNU Affero General Public License,
-       AGPL, as published by the Free Software Foundation, either version 
-       of the License, or (at your option) any later version.
+       Released under the terms of the GNU General Public License, GPL, 
+       as published by the Free Software Foundation, either version 3 
+       of the License, or (at your option) any later version.
     This program is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
-    See the License here <http://www.gnu.org/licenses/agpl-3.0.html>.
+    See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
 ***********************************************************************/
 function get_wo_requirements($woid)
 {
-       $sql = "SELECT ".TB_PREF."wo_requirements.*, ".TB_PREF."stock_master.description,
-               ".TB_PREF."stock_master.mb_flag, 
-               ".TB_PREF."locations.location_name, 
-               ".TB_PREF."workcentres.name AS WorkCentreDescription FROM 
-               (".TB_PREF."wo_requirements, ".TB_PREF."locations, ".TB_PREF."workcentres) INNER JOIN ".TB_PREF."stock_master ON 
-               ".TB_PREF."wo_requirements.stock_id = ".TB_PREF."stock_master.stock_id 
-               WHERE workorder_id=$woid
-               AND ".TB_PREF."locations.loc_code = ".TB_PREF."wo_requirements.loc_code
-               AND ".TB_PREF."workcentres.id=workcentre";
+       $sql = "SELECT req.*, item.description, item.mb_flag, loc.location_name, 
+                       center.name AS WorkCentreDescription
+               FROM (".TB_PREF."wo_requirements req,"
+                       .TB_PREF."locations loc,"
+                       .TB_PREF."workcentres center)
+                       INNER JOIN ".TB_PREF."stock_master item ON req.stock_id=item.stock_id 
+               WHERE workorder_id=".db_escape($woid)."
+               AND loc.loc_code = req.loc_code
+               AND center.id=workcentre";
 
        return db_query($sql, "The work order requirements could not be retrieved");    
 }
@@ -29,38 +29,38 @@ function get_wo_requirements($woid)
 function create_wo_requirements($woid, $stock_id)
 {
        // create Work Order Requirements based on the bom
-       $result = get_bom($stock_id);   
-       
+       $result = get_bom($stock_id);
+
        while ($myrow = db_fetch($result)) 
        {
-               
+
                $sql = "INSERT INTO ".TB_PREF."wo_requirements (workorder_id, stock_id, workcentre, units_req, loc_code)
-                       VALUES ($woid, '" .
+                       VALUES (".db_escape($woid).", '" .
                        $myrow["component"] . "', '"    .
                        $myrow["workcentre_added"] . "', '"     .
                        $myrow["quantity"] . "', '"     .
                        $myrow["loc_code"] . "')";
-                       
+
         db_query($sql, "The work order requirements could not be added");
-       }               
+       }
 }
 
 //--------------------------------------------------------------------------------------
 
 function delete_wo_requirements($woid)
 {
-       $sql="DELETE FROM ".TB_PREF."wo_requirements WHERE workorder_id=$woid";
+       $sql="DELETE FROM ".TB_PREF."wo_requirements WHERE workorder_id=".db_escape($woid);
        db_query($sql,"The work order requirements could not be deleted");      
 }
 
 
 //--------------------------------------------------------------------------------------
 
-function update_wo_requirement_issued($woReqID, $quantity)
+function update_wo_requirement_issued($woid, $stock_id, $quantity)
 {
-       $sql = "UPDATE ".TB_PREF."wo_requirements SET units_issued = units_issued + $quantity
-               WHERE id = '$woReqID'";
-                               
+       $sql = "UPDATE ".TB_PREF."wo_requirements SET units_issued = units_issued + ".db_escape($quantity)."
+               WHERE workorder_id = ".db_escape($woid)." AND stock_id = ".db_escape($stock_id);
+
        db_query($sql, "The work requirements issued quantity couldn't be updated");
 }
 
@@ -68,11 +68,9 @@ function update_wo_requirement_issued($woReqID, $quantity)
 
 function void_wo_requirements($woid)
 {
-       $sql = "UPDATE ".TB_PREF."wo_requirements SET units_issued = 0 WHERE workorder_id = $woid";
-                               
+       $sql = "UPDATE ".TB_PREF."wo_requirements SET units_issued = 0 WHERE workorder_id = "
+       .db_escape($woid);
+
        db_query($sql, "The work requirements issued quantity couldn't be voided");     
 }
 
-//--------------------------------------------------------------------------------------
-
-?>
\ No newline at end of file