3 function get_qoh_on_date($stock_id, $location=null, $date_=null)
8 $date = date2sql($date_);
10 $sql = "SELECT SUM(qty) FROM ".TB_PREF."stock_moves
11 WHERE stock_id='$stock_id'
12 AND tran_date <= '$date'";
14 if ($location != null)
15 $sql .= " AND loc_code = '$location'";
17 $result = db_query($sql, "QOH calulcation failed");
19 $myrow = db_fetch_row($result);
24 //--------------------------------------------------------------------------------------
26 function get_item_edit_info($stock_id)
28 $sql = "SELECT material_cost + labour_cost + overhead_cost AS standard_cost, units
29 FROM ".TB_PREF."stock_master WHERE stock_id='$stock_id'";
30 $result = db_query($sql, "The standard cost cannot be retrieved");
32 return db_fetch($result);
35 //--------------------------------------------------------------------------------------
37 function get_standard_cost($stock_id)
39 $sql = "SELECT material_cost + labour_cost + overhead_cost AS std_cost
40 FROM ".TB_PREF."stock_master WHERE stock_id='$stock_id'";
41 $result = db_query($sql, "The standard cost cannot be retrieved");
43 $myrow = db_fetch_row($result);
48 //--------------------------------------------------------------------------------------
50 function is_inventory_item($stock_id)
52 $sql = "SELECT stock_id FROM ".TB_PREF."stock_master
53 WHERE stock_id='$stock_id' AND mb_flag <> 'D'";
54 $result = db_query($sql, "Cannot query is inventory item or not");
56 return db_num_rows($result) > 0;
59 //-------------------------------------------------------------------
61 Function get_stock_gl_code($stock_id)
63 /*Gets the GL Codes relevant to the item account */
65 $sql = "SELECT inventory_account, cogs_account,
66 adjustment_account, sales_account, assembly_account, dimension_id, dimension2_id FROM
67 ".TB_PREF."stock_master WHERE stock_id = '$stock_id'";
69 $get = db_query($sql,"retreive stock gl code");
70 return db_fetch($get);
73 //--------------------------------------------------------------------------------------
75 // $date_ - display / non-sql date
76 // $std_cost - in HOME currency
77 // $show_or_hide - wil this move be visible in reports, etc
78 // $price - in $person_id's currency
80 function add_stock_move($type, $stock_id, $trans_no, $location,
81 $date_, $reference, $quantity, $std_cost, $person_id=null, $show_or_hide=1,
82 $price=0, $discount_percent=0, $error_msg="")
84 // do not add a stock move if it's a non-inventory item
85 if (!is_inventory_item($stock_id))
88 $date = date2sql($date_);
90 $sql = "INSERT INTO ".TB_PREF."stock_moves (stock_id, trans_no, type, loc_code,
91 tran_date, person_id, reference, qty, standard_cost, visible, price,
92 discount_percent) VALUES ('$stock_id', $trans_no, $type,
93 '$location', '$date', '$person_id', '$reference', $quantity, $std_cost,
94 $show_or_hide, $price, $discount_percent)";
97 $error_msg = "The stock movement record cannot be inserted";
99 db_query($sql, $error_msg);
101 return db_insert_id();
104 //--------------------------------------------------------------------------------------------------
106 function get_stock_moves($type, $type_no, $visible=false)
108 $sql = "SELECT ".TB_PREF."stock_moves.*, ".TB_PREF."stock_master.description, ".TB_PREF."stock_master.units,
109 ".TB_PREF."locations.location_name,
110 ".TB_PREF."stock_master.material_cost + ".TB_PREF."stock_master.labour_cost + ".TB_PREF."stock_master.overhead_cost AS FixedStandardCost
111 FROM ".TB_PREF."stock_moves,".TB_PREF."locations,".TB_PREF."stock_master
112 WHERE ".TB_PREF."stock_moves.stock_id = ".TB_PREF."stock_master.stock_id
113 AND ".TB_PREF."locations.loc_code=".TB_PREF."stock_moves.loc_code
114 AND type=$type AND trans_no=$type_no ORDER BY trans_id";
116 $sql .= " AND ".TB_PREF."stock_moves.visible=1";
118 return db_query($sql, "Could not get stock moves");
121 //--------------------------------------------------------------------------------------------------
123 function void_stock_move($type, $type_no)
125 $sql = "UPDATE ".TB_PREF."stock_moves SET qty=0, price=0, discount_percent=0,
126 standard_cost=0 WHERE type=$type AND trans_no=$type_no";
128 db_query($sql, "Could not void stock moves");
131 //--------------------------------------------------------------------------------------------------
133 function get_location_name($loc_code)
135 $sql = "SELECT location_name FROM ".TB_PREF."locations WHERE loc_code='$loc_code'";
137 $result = db_query($sql, "could not retreive the location name for $loc_code");
139 if (db_num_rows($result) == 1)
141 $row = db_fetch_row($result);
145 display_db_error("could not retreive the location name for $loc_code", $sql, true);
148 //--------------------------------------------------------------------------------------------------