2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU General Public License, GPL,
5 as published by the Free Software Foundation, either version 3
6 of the License, or (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 function get_wo_requirements($woid)
14 $sql = "SELECT ".TB_PREF."wo_requirements.*, ".TB_PREF."stock_master.description,
15 ".TB_PREF."stock_master.mb_flag,
16 ".TB_PREF."locations.location_name,
17 ".TB_PREF."workcentres.name AS WorkCentreDescription FROM
18 (".TB_PREF."wo_requirements, ".TB_PREF."locations, "
19 .TB_PREF."workcentres) INNER JOIN ".TB_PREF."stock_master ON
20 ".TB_PREF."wo_requirements.stock_id = ".TB_PREF."stock_master.stock_id
21 WHERE workorder_id=".db_escape($woid)."
22 AND ".TB_PREF."locations.loc_code = ".TB_PREF."wo_requirements.loc_code
23 AND ".TB_PREF."workcentres.id=workcentre";
25 return db_query($sql, "The work order requirements could not be retrieved");
28 //--------------------------------------------------------------------------------------
30 function create_wo_requirements($woid, $stock_id)
32 // create Work Order Requirements based on the bom
33 $result = get_bom($stock_id);
35 while ($myrow = db_fetch($result))
38 $sql = "INSERT INTO ".TB_PREF."wo_requirements (workorder_id, stock_id, workcentre, units_req, loc_code)
39 VALUES (".db_escape($woid).", '" .
40 $myrow["component"] . "', '" .
41 $myrow["workcentre_added"] . "', '" .
42 $myrow["quantity"] . "', '" .
43 $myrow["loc_code"] . "')";
45 db_query($sql, "The work order requirements could not be added");
49 //--------------------------------------------------------------------------------------
51 function delete_wo_requirements($woid)
53 $sql="DELETE FROM ".TB_PREF."wo_requirements WHERE workorder_id=".db_escape($woid);
54 db_query($sql,"The work order requirements could not be deleted");
58 //--------------------------------------------------------------------------------------
60 function update_wo_requirement_issued($woid, $stock_id, $quantity)
62 $sql = "UPDATE ".TB_PREF."wo_requirements SET units_issued = units_issued + ".db_escape($quantity)."
63 WHERE workorder_id = ".db_escape($woid)." AND stock_id = ".db_escape($stock_id);
65 db_query($sql, "The work requirements issued quantity couldn't be updated");
68 //--------------------------------------------------------------------------------------
70 function void_wo_requirements($woid)
72 $sql = "UPDATE ".TB_PREF."wo_requirements SET units_issued = 0 WHERE workorder_id = "
75 db_query($sql, "The work requirements issued quantity couldn't be voided");
78 //--------------------------------------------------------------------------------------