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 references::save_last($reference, systypes::location_transfer());
26 //-------------------------------------------------------------------------------------------------------------
28 // add 2 stock_moves entries for a stock transfer
29 // $date_ is display date (not sql)
30 // std_cost is in HOME currency
31 // it seems the standard_cost field is not used at all
33 function add_stock_transfer_item($transfer_id, $stock_id, $location_from, $location_to,
34 $date_, $type, $reference, $quantity)
36 add_stock_move(systypes::location_transfer(), $stock_id, $transfer_id, $location_from,
37 $date_, $reference, -$quantity, 0, $type);
39 add_stock_move(systypes::location_transfer(), $stock_id, $transfer_id, $location_to,
40 $date_, $reference, $quantity, 0, $type);
44 //-------------------------------------------------------------------------------------------------------------
46 function get_stock_transfer($trans_no)
48 $result = get_stock_transfer_items($trans_no);
49 if (db_num_rows($result) < 2)
51 display_db_error("transfer with less than 2 items : $trans_no", "");
54 // this function is very bad that it assumes that 1st record and 2nd record contain the
55 // from and to locations - if get_stock_moves uses a different ordering than trans_no then
57 $move1 = db_fetch($result);
58 $move2 = db_fetch($result);
60 // return an array of (From, To)
61 if ($move1['qty'] < 0)
62 return array($move1, $move2);
64 return array($move2, $move1);
67 //-------------------------------------------------------------------------------------------------------------
69 function get_stock_transfer_items($trans_no)
71 $result = get_stock_moves(systypes::location_transfer(), $trans_no);
73 if (db_num_rows($result) == 0)
81 //-------------------------------------------------------------------------------------------------------------
83 function void_stock_transfer($type_no)
85 void_stock_move(systypes::location_transfer(), $type_no);