Removed many global variables from config.default.php to GL Setup, Company Setup...
[fa-stable.git] / inventory / includes / db / items_transfer_db.inc
index 4d4a438b62cd0bc181e07108c49840f3ec66cb29..8448ae8968b71a5bde2598f6c32c724952675201 100644 (file)
@@ -1,28 +1,59 @@
 <?php
-
+/**********************************************************************
+    Copyright (C) FrontAccounting, LLC.
+       Released under the terms of the GNU General Public License, GPL, 
+       as published by the Free Software Foundation, either version 3 
+       of the License, or (at your option) any later version.
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
+    See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
+***********************************************************************/
 //-------------------------------------------------------------------------------------------------------------
 
 function add_stock_transfer($Items, $location_from, $location_to, $date_, $type, $reference, $memo_)
 {
+       global $SysPrefs, $path_to_root, $Refs;
+
        begin_transaction();
-               
-       $transfer_id = get_next_trans_no(systypes::location_transfer());
-               
-       foreach ($Items as $line_item) 
+       $args = func_get_args();
+       $args = (object)array_combine(array('Items', 'location_from', 'location_to', 
+       'date_', 'type', 'reference', 'memo_'), $args);
+       $args->trans_no = 0;
+       hook_db_prewrite($args, ST_LOCTRANSFER);
+
+       $transfer_id = get_next_trans_no(ST_LOCTRANSFER);
+
+       if ($SysPrefs->loc_notification() == 1)
        {
-               add_stock_transfer_item($transfer_id, $line_item->stock_id, $location_from, 
+               include_once($path_to_root . "/inventory/includes/inventory_db.inc");
+               $st_ids = array();
+               $st_names = array();
+               $st_num = array();
+               $st_reorder = array();
+       }
+       foreach ($Items as $line_item)
+       {
+               if ($SysPrefs->loc_notification() == 1)
+                       $loc = calculate_reorder_level($location_from, $line_item, $st_ids, $st_names, $st_num, $st_reorder); 
+               add_stock_transfer_item($transfer_id, $line_item->stock_id, $location_from,
                        $location_to, $date_, $type, $reference, $line_item->quantity);
        }
-       
-       add_comments(systypes::location_transfer(), $transfer_id, $date_, $memo_);      
-       
-       add_forms_for_sys_type(systypes::location_transfer(), $transfer_id, $location_from, $location_to);
-       
-       references::save_last($reference, systypes::location_transfer());               
-       
+
+       add_comments(ST_LOCTRANSFER, $transfer_id, $date_, $memo_);
+
+       $Refs->save(ST_LOCTRANSFER, $transfer_id, $reference);
+       add_audit_trail(ST_LOCTRANSFER, $transfer_id, $date_);
+
+       $args->trans_no = $transfer_id;
+       hook_db_postwrite($args, ST_LOCTRANSFER);
+
        commit_transaction();
+       
+       if ($SysPrefs->loc_notification() == 1 && count($st_ids) > 0)
+               send_reorder_email($loc, $st_ids, $st_names, $st_num, $st_reorder);
 
-       return $transfer_id;    
+       return $transfer_id;
 }
 
 //-------------------------------------------------------------------------------------------------------------
@@ -32,15 +63,15 @@ function add_stock_transfer($Items, $location_from, $location_to, $date_, $type,
 // std_cost is in HOME currency
 // it seems the standard_cost field is not used at all
 
-function add_stock_transfer_item($transfer_id, $stock_id, $location_from, $location_to,  
+function add_stock_transfer_item($transfer_id, $stock_id, $location_from, $location_to,
        $date_, $type, $reference, $quantity)
 {
-       add_stock_move(systypes::location_transfer(), $stock_id, $transfer_id, $location_from,
-               $date_, $reference, -$quantity, 0, $type);              
-       
-       add_stock_move(systypes::location_transfer(), $stock_id, $transfer_id, $location_to,
-               $date_, $reference, $quantity, 0, $type);                       
-       
+       add_stock_move(ST_LOCTRANSFER, $stock_id, $transfer_id, $location_from,
+               $date_, $reference, -$quantity, 0);
+
+       add_stock_move(ST_LOCTRANSFER, $stock_id, $transfer_id, $location_to,
+               $date_, $reference, $quantity, 0);
+
 }
 
 //-------------------------------------------------------------------------------------------------------------
@@ -48,17 +79,17 @@ function add_stock_transfer_item($transfer_id, $stock_id, $location_from, $locat
 function get_stock_transfer($trans_no)
 {
        $result = get_stock_transfer_items($trans_no);
-       if (db_num_rows($result) < 2) 
+       if (db_num_rows($result) < 2)
        {
-               display_db_error("transfer with less than 2 items : $trans_no", ""); 
+               display_db_error("transfer with less than 2 items : $trans_no", "");
        }
-       
+
        // this function is very bad that it assumes that 1st record and 2nd record contain the
        // from and to locations - if get_stock_moves uses a different ordering than trans_no then
        // it will bomb
        $move1 = db_fetch($result);
        $move2 = db_fetch($result);
-       
+
        // return an array of (From, To)
        if ($move1['qty'] < 0)
                return array($move1, $move2);
@@ -70,13 +101,13 @@ function get_stock_transfer($trans_no)
 
 function get_stock_transfer_items($trans_no)
 {
-       $result = get_stock_moves(systypes::location_transfer(), $trans_no);
-       
-       if (db_num_rows($result) == 0) 
+       $result = get_stock_moves(ST_LOCTRANSFER, $trans_no);
+
+       if (db_num_rows($result) == 0)
        {
-               return null; 
+               return null;
        }
-       
+
        return $result;
 }
 
@@ -84,7 +115,8 @@ function get_stock_transfer_items($trans_no)
 
 function void_stock_transfer($type_no)
 {
-       void_stock_move(systypes::location_transfer(), $type_no);
+       hook_db_prevoid(ST_LOCTRANSFER, $type_no);
+       void_stock_move(ST_LOCTRANSFER, $type_no);
 }
 
 ?>
\ No newline at end of file