Cleanup in inventory transfer view.
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Wed, 8 Apr 2015 22:42:47 +0000 (00:42 +0200)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Wed, 8 Apr 2015 22:42:47 +0000 (00:42 +0200)
inventory/includes/db/items_transfer_db.inc
inventory/view/view_transfer.php

index e4a452fe3ed12e00c63b4f67f6703d4657e448e2..c9a845f9b3e6613d28f2c23b21687896acbe7811 100644 (file)
@@ -75,26 +75,29 @@ function add_stock_transfer_item($transfer_id, $stock_id, $location_from, $locat
 }
 
 //-------------------------------------------------------------------------------------------------------------
-
+//
+//     Get inventory transfer common data (currently this is still stored in stock_moves table).
+//
 function get_stock_transfer($trans_no)
 {
-       $result = get_stock_transfer_items($trans_no);
-       if (db_num_rows($result) < 2)
-       {
-               display_db_error("transfer with less than 2 items : $trans_no", "");
-       }
+       // retrieve common data from any two from/to move records
+       $sql = "SELECT loc_from.*, loc_to.*
+               FROM
+                       (SELECT trans_no, type, tran_date, reference, move.loc_code as from_loc, loc.location_name as from_name
+                       FROM ".TB_PREF."stock_moves move
+                               LEFT JOIN ".TB_PREF."locations loc ON loc.loc_code=move.loc_code
+                       WHERE type=".ST_LOCTRANSFER." AND trans_no=".db_escape($trans_no). " AND qty<0 LIMIT 1) loc_from,
+
+                       (SELECT move.loc_code as to_loc, loc.location_name as to_name
+                       FROM ".TB_PREF."stock_moves move
+                               LEFT JOIN ".TB_PREF."locations loc ON loc.loc_code=move.loc_code
+                       WHERE type=".ST_LOCTRANSFER." AND trans_no=".db_escape($trans_no). " AND qty>0 LIMIT 1) loc_to";
+
+       $result = db_query($sql, "Could not get transfer common data");
+
+       $data = db_fetch($result);
 
-       // 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);
-       else
-               return array($move2, $move1);
+       return $data;
 }
 
 //-------------------------------------------------------------------------------------------------------------
index ce17ce75eccdc3ca3e49b96b158ac0c0a76e3228..ec35033328ec8d13587b8dc6d4ce1bcb71e29eb2 100644 (file)
@@ -25,10 +25,7 @@ if (isset($_GET["trans_no"]))
        $trans_no = $_GET["trans_no"];
 }
 
-$transfer_items = get_stock_transfer($trans_no);
-
-$from_trans = $transfer_items[0];
-$to_trans = $transfer_items[1];
+$trans = get_stock_transfer($trans_no);
 
 display_heading($systypes_array[ST_LOCTRANSFER] . " #$trans_no");
 
@@ -36,13 +33,12 @@ echo "<br>";
 start_table(TABLESTYLE2, "width='90%'");
 
 start_row();
-label_cells(_("Item"), $from_trans['stock_id'] . " - " . $from_trans['description'], "class='tableheader2'");
-label_cells(_("From Location"), $from_trans['location_name'], "class='tableheader2'");
-label_cells(_("To Location"), $to_trans['location_name'], "class='tableheader2'");
+label_cells(_("Reference"), $trans['reference'], "class='tableheader2'");
+label_cells(_("Date"), sql2date($trans['tran_date']), "class='tableheader2'");
 end_row();
 start_row();
-label_cells(_("Reference"), $from_trans['reference'], "class='tableheader2'");
-label_cells(_("Date"), sql2date($from_trans['tran_date']), "class='tableheader2'");
+label_cells(_("From Location"), $trans['from_name'], "class='tableheader2'");
+label_cells(_("To Location"), $trans['to_name'], "class='tableheader2'");
 end_row();
 
 comments_display_row(ST_LOCTRANSFER, $trans_no);
@@ -57,7 +53,7 @@ $transfer_items = get_stock_moves(ST_LOCTRANSFER, $trans_no);
 $k = 0;
 while ($item = db_fetch($transfer_items))
 {
-       if ($item['loc_code'] == $to_trans['loc_code'])
+       if ($item['loc_code'] == $trans['to_loc'])
        {
         alt_table_row_color($k);