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 add_movement_type($name)
14 $sql = "INSERT INTO ".TB_PREF."movement_types (name)
15 VALUES (".db_escape($name).")";
17 db_query($sql, "could not add item movement type");
20 function update_movement_type($type_id, $name)
22 $sql = "UPDATE ".TB_PREF."movement_types SET name=".db_escape($name)."
23 WHERE id=".db_escape($type_id);
25 db_query($sql, "could not update item movement type");
28 function get_all_movement_type($all=false)
30 $sql = "SELECT * FROM ".TB_PREF."movement_types";
31 if (!$all) $sql .= " WHERE !inactive";
33 return db_query($sql, "could not get all item movement type");
36 function get_movement_type($type_id)
38 $sql = "SELECT * FROM ".TB_PREF."movement_types WHERE id=".db_escape($type_id);
40 $result = db_query($sql, "could not get item movement type");
42 return db_fetch($result);
45 function delete_movement_type($type_id)
47 $sql="DELETE FROM ".TB_PREF."movement_types WHERE id=".db_escape($type_id);
49 db_query($sql, "could not delete item movement type");
52 function get_stock_movements($stock_id, $StockLocation, $BeforeDate, $AfterDate)
54 $before_date = date2sql($BeforeDate);
55 $after_date = date2sql($AfterDate);
56 $sql = "SELECT type, trans_no, tran_date, person_id, qty, reference";
61 $sql.= " FROM ".TB_PREF."stock_moves
65 $sql.= " loc_code=".db_escape($StockLocation)." AND";
68 $sql.= " tran_date >= '". $after_date . "'
69 AND tran_date <= '" . $before_date . "'
70 AND stock_id = ".db_escape($stock_id) . " ORDER BY tran_date,trans_id";
72 return db_query($sql, "could not query stock moves");
75 function get_stock_movements_before($stock_id, $StockLocation, $AfterDate)
77 $after_date = date2sql($AfterDate);
78 $sql = "SELECT SUM(qty) FROM ".TB_PREF."stock_moves WHERE stock_id=".db_escape($stock_id);
80 $sql .= " AND loc_code=".db_escape( $StockLocation);
81 $sql .= " AND tran_date < '" . $after_date . "'";
82 $before_qty = db_query($sql, "The starting quantity on hand could not be calculated");
84 $before_qty_row = db_fetch_row($before_qty);
85 return $before_qty_row[0];
88 function movement_types_in_stock_moves($selected_id)
90 $sql= "SELECT COUNT(*) FROM ".TB_PREF."stock_moves
91 WHERE type=" . ST_INVADJUST. " AND person_id=".db_escape($selected_id);
93 $result = db_query($sql, "could not query stock moves");
94 $myrow = db_fetch_row($result);
95 return ($myrow[0] > 0);