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 req.*, item.description, item.mb_flag, loc.location_name,
15 center.name AS WorkCentreDescription,
16 item.material_cost as ComponentCost,
17 item.inventory_account,
19 FROM (".TB_PREF."wo_requirements req,"
20 .TB_PREF."locations loc,"
21 .TB_PREF."workcentres center)
22 INNER JOIN ".TB_PREF."stock_master item ON req.stock_id=item.stock_id
23 WHERE workorder_id=".db_escape($woid)."
24 AND loc.loc_code = req.loc_code
25 AND center.id=workcentre";
27 return db_query($sql, "The work order requirements could not be retrieved");
30 function get_requirements_costs($woid)
32 $sql = "SELECT SUM(units_req*unit_cost) cost
33 FROM ".TB_PREF."wo_requirements
34 WHERE workorder_id=".db_escape($woid);
36 $result = db_query($sql, "The work order requirements costs could not be retrieved");
37 $costs = db_fetch($result);
39 return $costs['cost'] ? $costs['cost'] : 0;
42 //--------------------------------------------------------------------------------------
44 function create_wo_requirements($woid, $stock_id)
46 begin_transaction(__FUNCTION__, func_get_args());
47 $sql = "INSERT INTO ".TB_PREF."wo_requirements (workorder_id, stock_id, workcentre, units_req, loc_code)
48 SELECT ".db_escape($woid).", component, workcentre_added, quantity, loc_code
49 FROM ".TB_PREF."bom WHERE parent=".db_escape($stock_id);
51 db_query($sql, "The work order requirements could not be added");
55 //--------------------------------------------------------------------------------------
57 function delete_wo_requirements($woid)
59 begin_transaction(__FUNCTION__, func_get_args());
60 $sql="DELETE FROM ".TB_PREF."wo_requirements WHERE workorder_id=".db_escape($woid);
61 db_query($sql,"The work order requirements could not be deleted");
66 //--------------------------------------------------------------------------------------
68 Update total component units issued and average component cost
70 function update_wo_requirement_issued($id, $quantity, $cost)
72 begin_transaction(__FUNCTION__, func_get_args());
73 $sql = "UPDATE ".TB_PREF."wo_requirements SET
74 unit_cost = (units_issued*unit_cost+".$quantity*$cost.")/(units_issued+".$quantity."),
75 units_issued = units_issued + ".db_escape($quantity)."
76 WHERE id = ".db_escape($id);
78 db_query($sql, "The work requirements issued quantity couldn't be updated");
82 //--------------------------------------------------------------------------------------
84 function void_wo_requirements($woid)
86 begin_transaction(__FUNCTION__, func_get_args());
87 $sql = "UPDATE ".TB_PREF."wo_requirements SET units_issued = 0
88 WHERE workorder_id = ".db_escape($woid);
90 db_query($sql, "The work requirements issued quantity couldn't be voided");