de03445e99e883f6cb882001038dbce99b6d34b6
[fa-stable.git] / includes / db / manufacturing_db.inc
1 <?php
2 /**********************************************************************
3     Copyright (C) FrontAccounting, LLC.
4         Released under the terms of the GNU Affero General Public License,
5         AGPL, as published by the Free Software Foundation, either version 
6         3 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/agpl-3.0.html>.
11 ***********************************************************************/
12 function get_mb_flag($stock_id)
13 {
14         $sql = "SELECT mb_flag FROM ".TB_PREF."stock_master WHERE stock_id = '" . $stock_id . "'";
15         $result = db_query($sql, "retreive mb_flag from item");
16         
17         if (db_num_rows($result) == 0)
18                 return -1;
19
20         $myrow = db_fetch_row($result);
21         return $myrow[0];
22 }
23
24 //--------------------------------------------------------------------------------------
25
26 function get_bom($item)
27 {
28         $sql = "SELECT ".TB_PREF."bom.*, ".TB_PREF."locations.location_name, ".TB_PREF."workcentres.name AS WorkCentreDescription, 
29         ".TB_PREF."stock_master.description, ".TB_PREF."stock_master.mb_flag AS ResourceType, 
30         ".TB_PREF."stock_master.material_cost+ ".TB_PREF."stock_master.labour_cost+".TB_PREF."stock_master.overhead_cost AS standard_cost, units, 
31         ".TB_PREF."bom.quantity * (".TB_PREF."stock_master.material_cost+ ".TB_PREF."stock_master.labour_cost+ ".TB_PREF."stock_master.overhead_cost) AS ComponentCost 
32         FROM (".TB_PREF."workcentres, ".TB_PREF."locations, ".TB_PREF."bom) INNER JOIN ".TB_PREF."stock_master ON ".TB_PREF."bom.component = ".TB_PREF."stock_master.stock_id 
33         WHERE ".TB_PREF."bom.parent = '" . $item . "'
34                 AND ".TB_PREF."workcentres.id=".TB_PREF."bom.workcentre_added
35                 AND ".TB_PREF."bom.loc_code = ".TB_PREF."locations.loc_code ORDER BY ".TB_PREF."bom.id";
36         
37         return db_query($sql, "The bill of material could not be retrieved");
38 }
39
40 //--------------------------------------------------------------------------------------
41
42 function has_bom($item)
43 {
44     $result = get_bom($item);
45     
46     return (db_num_rows($result) != 0);
47 }
48
49 //--------------------------------------------------------------------------------------
50
51 ?>