3 //-------------------------------------------------------------------------------------------------------------
5 function add_stock_transfer($Items, $location_from, $location_to, $date_, $type, $reference, $memo_)
9 $transfer_id = get_next_trans_no(systypes::location_transfer());
11 foreach ($Items as $line_item)
13 add_stock_transfer_item($transfer_id, $line_item->stock_id, $location_from,
14 $location_to, $date_, $type, $reference, $line_item->quantity);
17 add_comments(systypes::location_transfer(), $transfer_id, $date_, $memo_);
19 add_forms_for_sys_type(systypes::location_transfer(), $transfer_id, $location_from, $location_to);
21 references::save_last($reference, systypes::location_transfer());
28 //-------------------------------------------------------------------------------------------------------------
30 // add 2 stock_moves entries for a stock transfer
31 // $date_ is display date (not sql)
32 // std_cost is in HOME currency
33 // it seems the standard_cost field is not used at all
35 function add_stock_transfer_item($transfer_id, $stock_id, $location_from, $location_to,
36 $date_, $type, $reference, $quantity)
38 add_stock_move(systypes::location_transfer(), $stock_id, $transfer_id, $location_from,
39 $date_, $reference, -$quantity, 0, $type);
41 add_stock_move(systypes::location_transfer(), $stock_id, $transfer_id, $location_to,
42 $date_, $reference, $quantity, 0, $type);
46 //-------------------------------------------------------------------------------------------------------------
48 function get_stock_transfer($trans_no)
50 $result = get_stock_transfer_items($trans_no);
51 if (db_num_rows($result) < 2)
53 display_db_error("transfer with less than 2 items : $trans_no", "");
56 // this function is very bad that it assumes that 1st record and 2nd record contain the
57 // from and to locations - if get_stock_moves uses a different ordering than trans_no then
59 $move1 = db_fetch($result);
60 $move2 = db_fetch($result);
62 // return an array of (From, To)
63 if ($move1['qty'] < 0)
64 return array($move1, $move2);
66 return array($move2, $move1);
69 //-------------------------------------------------------------------------------------------------------------
71 function get_stock_transfer_items($trans_no)
73 $result = get_stock_moves(systypes::location_transfer(), $trans_no);
75 if (db_num_rows($result) == 0)
83 //-------------------------------------------------------------------------------------------------------------
85 function void_stock_transfer($type_no)
87 void_stock_move(systypes::location_transfer(), $type_no);