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 $sql = "INSERT INTO ".TB_PREF."wo_requirements (workorder_id, stock_id, workcentre, units_req, loc_code)
47 SELECT ".db_escape($woid).", component, workcentre_added, quantity, loc_code
48 FROM ".TB_PREF."bom WHERE parent=".db_escape($stock_id);
50 db_query($sql, "The work order requirements could not be added");
53 //--------------------------------------------------------------------------------------
55 function delete_wo_requirements($woid)
57 $sql="DELETE FROM ".TB_PREF."wo_requirements WHERE workorder_id=".db_escape($woid);
58 db_query($sql,"The work order requirements could not be deleted");
62 //--------------------------------------------------------------------------------------
64 Update total component units issued and average component cost
66 function update_wo_requirement_issued($id, $quantity, $cost)
68 $sql = "UPDATE ".TB_PREF."wo_requirements SET
69 unit_cost = (units_issued*unit_cost+".$quantity*$cost.")/(units_issued+".$quantity."),
70 units_issued = units_issued + ".db_escape($quantity)."
71 WHERE id = ".db_escape($id);
73 db_query($sql, "The work requirements issued quantity couldn't be updated");
76 //--------------------------------------------------------------------------------------
78 function void_wo_requirements($woid)
80 $sql = "UPDATE ".TB_PREF."wo_requirements SET units_issued = 0
81 WHERE workorder_id = ".db_escape($woid);
83 db_query($sql, "The work requirements issued quantity couldn't be voided");