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 //-------------------------------------------------------------------------------------------------------------
14 function add_stock_adjustment($items, $location, $date_, $type, $increase, $reference, $memo_)
19 $args = func_get_args();
20 $args = (object)array_combine(array('items', 'location', 'date_', 'type', 'increase',
21 'reference', 'memo_'), $args);
23 hook_db_prewrite($args, ST_INVADJUST);
25 $adj_id = get_next_trans_no(ST_INVADJUST);
27 foreach ($items as $line_item)
31 $line_item->quantity = -$line_item->quantity;
33 add_stock_adjustment_item($adj_id, $line_item->stock_id, $location, $date_, $type, $reference,
34 $line_item->quantity, $line_item->standard_cost, $memo_);
37 add_comments(ST_INVADJUST, $adj_id, $date_, $memo_);
39 $Refs->save(ST_INVADJUST, $adj_id, $reference);
40 add_audit_trail(ST_INVADJUST, $adj_id, $date_);
42 $args->trans_no = $adj_id;
43 hook_db_postwrite($args, ST_INVADJUST);
49 //-------------------------------------------------------------------------------------------------------------
51 function void_stock_adjustment($type_no)
53 hook_db_prevoid(ST_INVADJUST, $type_no);
55 //Average the cost while voiding
56 $adjustment_items = get_stock_adjustment_items($type_no);
57 while ($adjustment = db_fetch($adjustment_items))
59 update_average_material_cost(0, $adjustment['stock_id'],
60 $adjustment['standard_cost'], -$adjustment['qty'], sql2date($adjustment['tran_date']));
62 void_gl_trans(ST_INVADJUST, $type_no);
63 void_stock_move(ST_INVADJUST, $type_no);
66 //-------------------------------------------------------------------------------------------------------------
68 function get_stock_adjustment_items($trans_no)
70 $result = get_stock_moves(ST_INVADJUST, $trans_no);
72 if (db_num_rows($result) == 0)
80 //--------------------------------------------------------------------------------------------------
82 function add_stock_adjustment_item($adj_id, $stock_id, $location, $date_, $type, $reference,
83 $quantity, $standard_cost, $memo_)
85 $mb_flag = get_mb_flag($stock_id);
87 if (is_service($mb_flag))
89 display_db_error("Cannot do inventory adjustment for Service item : $stock_id", "");
92 update_average_material_cost(null, $stock_id, $standard_cost, $quantity, $date_);
94 add_stock_move(ST_INVADJUST, $stock_id, $adj_id, $location,
95 $date_, $reference, $quantity, $standard_cost, $type);
97 if ($standard_cost > 0)
100 $stock_gl_codes = get_stock_gl_code($stock_id);
102 add_gl_trans_std_cost(ST_INVADJUST, $adj_id, $date_,
103 $stock_gl_codes['adjustment_account'], $stock_gl_codes['dimension_id'], $stock_gl_codes['dimension2_id'], $memo_, ($standard_cost * -($quantity)));
105 add_gl_trans_std_cost(ST_INVADJUST, $adj_id, $date_, $stock_gl_codes['inventory_account'], 0, 0, $memo_, ($standard_cost * $quantity));
109 //-------------------------------------------------------------------------------------------------------------