c7c8c5d92b1c1abdf830d21a3152be6d5347a5d5
[fa-stable.git] / includes / db / manufacturing_db.inc
1 <?php
2
3 function get_mb_flag($stock_id)
4 {
5         $sql = "SELECT mb_flag FROM ".TB_PREF."stock_master WHERE stock_id = '" . $stock_id . "'";
6         $result = db_query($sql, "retreive mb_flag from item");
7         
8         if (db_num_rows($result) == 0)
9                 return -1;
10
11         $myrow = db_fetch_row($result);
12         return $myrow[0];
13 }
14
15 //--------------------------------------------------------------------------------------
16
17 function get_bom($item)
18 {
19         $sql = "SELECT ".TB_PREF."bom.*, ".TB_PREF."locations.location_name, ".TB_PREF."workcentres.name AS WorkCentreDescription, 
20         ".TB_PREF."stock_master.description, ".TB_PREF."stock_master.mb_flag AS ResourceType, 
21         ".TB_PREF."stock_master.material_cost+ ".TB_PREF."stock_master.labour_cost+".TB_PREF."stock_master.overhead_cost AS standard_cost, units, 
22         ".TB_PREF."bom.quantity * (".TB_PREF."stock_master.material_cost+ ".TB_PREF."stock_master.labour_cost+ ".TB_PREF."stock_master.overhead_cost) AS ComponentCost 
23         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 
24         WHERE ".TB_PREF."bom.parent = '" . $item . "'
25                 AND ".TB_PREF."workcentres.id=".TB_PREF."bom.workcentre_added
26                 AND ".TB_PREF."bom.loc_code = ".TB_PREF."locations.loc_code ORDER BY ".TB_PREF."bom.id";
27         
28         return db_query($sql, "The bill of material could not be retrieved");
29 }
30
31 //--------------------------------------------------------------------------------------
32
33 function has_bom($item)
34 {
35     $result = get_bom($item);
36     
37     return (db_num_rows($result) != 0);
38 }
39
40 //--------------------------------------------------------------------------------------
41
42 ?>