Moving 2.0 development version to main trunk.
[fa-stable.git] / inventory / includes / db / items_transfer_db.inc
1 <?php
2
3 //-------------------------------------------------------------------------------------------------------------
4
5 function add_stock_transfer($Items, $location_from, $location_to, $date_, $type, $reference, $memo_)
6 {
7         begin_transaction();
8
9         $transfer_id = get_next_trans_no(systypes::location_transfer());
10
11         foreach ($Items as $line_item)
12         {
13                 add_stock_transfer_item($transfer_id, $line_item->stock_id, $location_from,
14                         $location_to, $date_, $type, $reference, $line_item->quantity);
15         }
16
17         add_comments(systypes::location_transfer(), $transfer_id, $date_, $memo_);
18
19         references::save_last($reference, systypes::location_transfer());
20
21         commit_transaction();
22
23         return $transfer_id;
24 }
25
26 //-------------------------------------------------------------------------------------------------------------
27
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
32
33 function add_stock_transfer_item($transfer_id, $stock_id, $location_from, $location_to,
34         $date_, $type, $reference, $quantity)
35 {
36         add_stock_move(systypes::location_transfer(), $stock_id, $transfer_id, $location_from,
37         $date_, $reference, -$quantity, 0, $type);
38
39         add_stock_move(systypes::location_transfer(), $stock_id, $transfer_id, $location_to,
40                 $date_, $reference, $quantity, 0, $type);
41
42 }
43
44 //-------------------------------------------------------------------------------------------------------------
45
46 function get_stock_transfer($trans_no)
47 {
48         $result = get_stock_transfer_items($trans_no);
49         if (db_num_rows($result) < 2)
50         {
51                 display_db_error("transfer with less than 2 items : $trans_no", "");
52         }
53
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
56         // it will bomb
57         $move1 = db_fetch($result);
58         $move2 = db_fetch($result);
59
60         // return an array of (From, To)
61         if ($move1['qty'] < 0)
62                 return array($move1, $move2);
63         else
64                 return array($move2, $move1);
65 }
66
67 //-------------------------------------------------------------------------------------------------------------
68
69 function get_stock_transfer_items($trans_no)
70 {
71         $result = get_stock_moves(systypes::location_transfer(), $trans_no);
72
73         if (db_num_rows($result) == 0)
74         {
75                 return null;
76         }
77
78         return $result;
79 }
80
81 //-------------------------------------------------------------------------------------------------------------
82
83 function void_stock_transfer($type_no)
84 {
85         void_stock_move(systypes::location_transfer(), $type_no);
86 }
87
88 ?>