Added 'Item Like' parameter to Stock Sheet Report allowing SQL LIKE or regexp filteri...
[fa-stable.git] / reporting / rep303.php
index 9c2a493bdf9831300e726c8a88d6605997358003..2f3e7a35404478d7eb9e6b0475a788293c37aab2 100644 (file)
@@ -29,7 +29,7 @@ include_once($path_to_root . "/includes/db/manufacturing_db.inc");
 
 print_stock_check();
 
-function getTransactions($category, $location)
+function getTransactions($category, $location, $item_like)
 {
        $sql = "SELECT ".TB_PREF."stock_master.category_id,
                        ".TB_PREF."stock_category.description AS cat_description,
@@ -48,6 +48,15 @@ function getTransactions($category, $location)
                $sql .= " AND ".TB_PREF."stock_master.category_id = ".db_escape($category);
        if ($location != 'all')
                $sql .= " AND IF(".TB_PREF."stock_moves.stock_id IS NULL, '1=1',".TB_PREF."stock_moves.loc_code = ".db_escape($location).")";
+  if($item_like)
+  {
+    $regexp = null;
+
+    if(sscanf($item_like, "/%s", &$regexp)==1)
+      $sql .= " AND ".TB_PREF."stock_master.stock_id RLIKE ".db_escape($regexp);
+    else
+      $sql .= " AND ".TB_PREF."stock_master.stock_id LIKE ".db_escape($item_like);
+  }
        $sql .= " GROUP BY ".TB_PREF."stock_master.category_id,
                ".TB_PREF."stock_category.description,
                ".TB_PREF."stock_master.stock_id,
@@ -70,9 +79,10 @@ function print_stock_check()
        $check    = $_POST['PARAM_3'];
        $shortage = $_POST['PARAM_4'];
        $no_zeros = $_POST['PARAM_5'];
-       $comments = $_POST['PARAM_6'];
-               $orientation = $_POST['PARAM_7'];
-               $destination = $_POST['PARAM_8'];
+       $like     = $_POST['PARAM_6']; 
+       $comments = $_POST['PARAM_7'];
+       $orientation = $_POST['PARAM_8'];
+       $destination = $_POST['PARAM_9'];
 
        if ($destination)
                include_once($path_to_root . "/reporting/includes/excel_report.inc");
@@ -138,7 +148,7 @@ function print_stock_check()
     $rep->Info($params, $cols, $headers, $aligns);
     $rep->NewPage();
 
-       $res = getTransactions($category, $location);
+       $res = getTransactions($category, $location, $like);
        $catt = '';
        while ($trans=db_fetch($res))
        {