Old ineffective sql_trail superseded by new improved db_trail logging only calls...
[fa-stable.git] / inventory / includes / db / items_locations_db.inc
index 4a12c671cc73aa60dcf45980fb8f06cb40b68399..9fd54b62bd1d1e802d94884325c61635c64288e6 100644 (file)
@@ -9,12 +9,13 @@
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
 ***********************************************************************/
-function add_item_location($loc_code, $location_name, $delivery_address, $phone, $phone2, $fax, $email, $contact)
+function add_item_location($loc_code, $location_name, $delivery_address, $phone, $phone2, $fax, $email, $contact, $fixed_asset = 0)
 {
-       $sql = "INSERT INTO ".TB_PREF."locations (loc_code, location_name, delivery_address, phone, phone2, fax, email, contact)
+       begin_transaction(__FUNCTION__, func_get_args());
+       $sql = "INSERT INTO ".TB_PREF."locations (loc_code, location_name, delivery_address, phone, phone2, fax, email, contact, fixed_asset)
                VALUES (".db_escape($loc_code).", ".db_escape($location_name).", ".db_escape($delivery_address).", "
                        .db_escape($phone).", ".db_escape($phone2).", ".db_escape($fax).", ".db_escape($email).", "
-                       .db_escape($contact).")";
+                       .db_escape($contact).", ".db_escape($fixed_asset).")";
 
        db_query($sql,"a location could not be added");
 
@@ -23,31 +24,37 @@ function add_item_location($loc_code, $location_name, $delivery_address, $phone,
                SELECT ".db_escape($loc_code).", ".TB_PREF."stock_master.stock_id, 0 FROM ".TB_PREF."stock_master";
 
        db_query($sql,"a location could not be added");
+       commit_transaction();
 }
 
 //------------------------------------------------------------------------------------
 
-function update_item_location($loc_code, $location_name, $delivery_address, $phone, $phone2, $fax, $email, $contact)
+function update_item_location($loc_code, $location_name, $delivery_address, $phone, $phone2, $fax, $email, $contact, $fixed_asset = 0)
 
 {
+       begin_transaction(__FUNCTION__, func_get_args());
     $sql = "UPDATE ".TB_PREF."locations SET location_name=".db_escape($location_name).",
        delivery_address=".db_escape($delivery_address).",
        phone=".db_escape($phone).", phone2=".db_escape($phone2).", fax=".db_escape($fax).",
-       email=".db_escape($email).", contact=".db_escape($contact)."
+       email=".db_escape($email).", contact=".db_escape($contact).",
+      fixed_asset=".db_escape($fixed_asset)."
        WHERE loc_code = ".db_escape($loc_code);
 
        db_query($sql,"a location could not be updated");
+       commit_transaction();
 }
 
 //------------------------------------------------------------------------------------
 
 function delete_item_location($item_location)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql="DELETE FROM ".TB_PREF."locations WHERE loc_code=".db_escape($item_location);
        db_query($sql,"a location could not be deleted");
 
        $sql = "DELETE FROM ".TB_PREF."loc_stock WHERE loc_code =".db_escape($item_location);
        db_query($sql,"a location could not be deleted");
+       commit_transaction();
 }
 
 //------------------------------------------------------------------------------------
@@ -63,33 +70,36 @@ function get_item_location($item_location)
 
 //------------------------------------------------------------------------------------
 
-function get_item_locations($show_inactive)
+function get_item_locations($show_inactive, $fixed_asset = 0)
 {
-       $sql = "SELECT * FROM ".TB_PREF."locations";
-       if (!$show_inactive) $sql .= " WHERE !inactive";
-       return db_query($sql, "could not query locations");;
+       $sql = "SELECT * FROM ".TB_PREF."locations WHERE fixed_asset = ".db_escape($fixed_asset);
+       if (!$show_inactive) $sql .= " AND !inactive";
+       return db_query($sql, "could not query locations");
 }
 
 //------------------------------------------------------------------------------------
 
 function set_reorder_level($stock_id, $loc_code, $reorder_level)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql = "UPDATE ".TB_PREF."loc_stock SET reorder_level = $reorder_level
                WHERE stock_id = ".db_escape($stock_id)." AND loc_code = ".db_escape($loc_code);
 
        db_query($sql,"an item reorder could not be set");
+       commit_transaction();
 }
 
 //------------------------------------------------------------------------------------
 
-function get_loc_details($stock_id)
+function get_loc_details($stock_id, $fixed_asset = 0)
 {
-       $sql = "SELECT ".TB_PREF."loc_stock.*, ".TB_PREF."locations.location_name
-               FROM ".TB_PREF."loc_stock, ".TB_PREF."locations
-               WHERE ".TB_PREF."loc_stock.loc_code=".TB_PREF."locations.loc_code
-               AND ".TB_PREF."loc_stock.stock_id = ".db_escape($stock_id) 
-               ." ORDER BY ".TB_PREF."loc_stock.loc_code";
+       $sql = "SELECT stock.loc_code, stock.location_name, "
+       .db_escape($stock_id)." as stock_id, reorders.reorder_level
+               FROM ".TB_PREF."locations stock LEFT JOIN ".TB_PREF."loc_stock reorders ON
+               reorders.loc_code=stock.loc_code
+               AND reorders.stock_id = ".db_escape($stock_id)
+           ." WHERE stock.fixed_asset = ".db_escape($fixed_asset)
+               ." ORDER BY reorders.loc_code";
        return db_query($sql,"an item reorder could not be retreived");
 }
 
-?>
\ No newline at end of file