Currency selection in Price Listing Report
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Wed, 30 Jul 2008 22:24:11 +0000 (22:24 +0000)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Wed, 30 Jul 2008 22:24:11 +0000 (22:24 +0000)
CHANGELOG.txt
reporting/rep104.php
reporting/reports_main.php

index 9db7e0d48c7363318fb6f6412934685f4762f60d..6c3d6525ca2982283ac8053348ca098a5734008f 100644 (file)
@@ -19,6 +19,11 @@ Legend:
 ! -> Note
 $ -> Affected files
 
+30-Jul-2008 Joe Hunt
+! Currency selection in Price Listing Report
+$ /reporting/rep104.php
+  /reporting/reports_main.php
+  
 28-Jul-2008 Janusz Dobrowolski
 # Fixed control buttons reset after record deletion.
 $ /admin/fiscalyears.php
index d78b79c63dfe833e5d41401b291829dc1348823a..556603319738544e69ff4ae793586d86cb7ccffe 100644 (file)
@@ -11,6 +11,7 @@ $path_to_root="../";
 
 include_once($path_to_root . "includes/session.inc");
 include_once($path_to_root . "includes/date_functions.inc");
+include_once($path_to_root . "includes/ui/ui_input.inc");
 include_once($path_to_root . "includes/data_checks.inc");
 include_once($path_to_root . "gl/includes/gl_db.inc");
 include_once($path_to_root . "sales/includes/db/sales_types_db.inc");
@@ -21,35 +22,22 @@ include_once($path_to_root . "inventory/includes/db/items_category_db.inc");
 // trial_inquiry_controls();
 print_price_listing();
 
-function fetch_prices($category=0, $salestype=0)
+function fetch_items($category=0)
 {
-               $sql = "SELECT ".TB_PREF."prices.sales_type_id,
-                               ".TB_PREF."prices.stock_id,
-                               ".TB_PREF."stock_master.description AS name,
-                               ".TB_PREF."prices.curr_abrev,
-                               ".TB_PREF."prices.price,
-                               ".TB_PREF."sales_types.sales_type,
+               $sql = "SELECT ".TB_PREF."stock_master.stock_id, ".TB_PREF."stock_master.description AS name,
                                ".TB_PREF."stock_master.material_cost+".TB_PREF."stock_master.labour_cost+".TB_PREF."stock_master.overhead_cost AS Standardcost,
                                ".TB_PREF."stock_master.category_id,
                                ".TB_PREF."stock_category.description
                        FROM ".TB_PREF."stock_master,
-                               ".TB_PREF."stock_category,
-                               ".TB_PREF."sales_types,
-                               ".TB_PREF."prices
-                       WHERE ".TB_PREF."stock_master.stock_id=".TB_PREF."prices.stock_id
-                               AND ".TB_PREF."prices.sales_type_id=".TB_PREF."sales_types.id
-                               AND ".TB_PREF."stock_master.category_id=".TB_PREF."stock_category.category_id";
-               if ($salestype != 0)
-                       $sql .= " AND ".TB_PREF."sales_types.id = '$salestype'";
+                               ".TB_PREF."stock_category
+                       WHERE ".TB_PREF."stock_master.category_id=".TB_PREF."stock_category.category_id";
                if ($category != 0)
                        $sql .= " AND ".TB_PREF."stock_category.category_id = '$category'";
-               $sql .= " ORDER BY ".TB_PREF."prices.curr_abrev,
-                               ".TB_PREF."stock_master.category_id,
+               $sql .= " ORDER BY ".TB_PREF."stock_master.category_id,
                                ".TB_PREF."stock_master.stock_id";
 
     return db_query($sql,"No transactions were returned");
 }
-
 //----------------------------------------------------------------------------------------------------
 
 function print_price_listing()
@@ -58,14 +46,20 @@ function print_price_listing()
 
     include_once($path_to_root . "reporting/includes/pdf_report.inc");
 
-    $category = $_POST['PARAM_0'];
-    $salestype = $_POST['PARAM_1'];
-    $pictures = $_POST['PARAM_2'];
-    $showGP = $_POST['PARAM_3'];
-    $comments = $_POST['PARAM_4'];
+    $currency = $_POST['PARAM_0'];
+    $category = $_POST['PARAM_1'];
+    $salestype = $_POST['PARAM_2'];
+    $pictures = $_POST['PARAM_3'];
+    $showGP = $_POST['PARAM_4'];
+    $comments = $_POST['PARAM_5'];
 
     $dec = user_price_dec();
 
+       $home_curr = get_company_pref('curr_default');
+       if ($currency == reserved_words::get_all())
+               $currency = $home_curr;
+       $curr = get_currency($currency);
+       $curr_sel = $currency . " - " . $curr['currency'];
        if ($category == reserved_words::get_all_numeric())
                $category = 0;
        if ($salestype == reserved_words::get_all_numeric())
@@ -90,9 +84,10 @@ function print_price_listing()
        $aligns = array('left', 'left', 'right', 'right');
 
     $params =   array(         0 => $comments,
-                                   1 => array('text' => _('Category'), 'from' => $cat, 'to' => ''),
-                                   2 => array('text' => _('Sales Type'), 'from' => $stype, 'to' => ''),
-                                   3 => array(  'text' => _('Show GP %'),'from' => $GP,'to' => ''));
+                                   1 => array('text' => _('Currency'), 'from' => $curr_sel, 'to' => ''),
+                                   2 => array('text' => _('Category'), 'from' => $cat, 'to' => ''),
+                                   3 => array('text' => _('Sales Type'), 'from' => $stype, 'to' => ''),
+                                   4 => array(  'text' => _('Show GP %'),'from' => $GP,'to' => ''));
 
        if ($pictures)
                $user_comp = user_company();
@@ -105,22 +100,12 @@ function print_price_listing()
     $rep->Info($params, $cols, $headers, $aligns);
     $rep->Header();
 
-       $result = fetch_prices($category, $salestype);
+       $result = fetch_items($category);
 
-       $currcode = '';
        $catgor = '';
-
+       $_POST['sales_type_id'] = $salestype;
        while ($myrow=db_fetch($result))
        {
-               if ($currcode != $myrow['curr_abrev'])
-               {
-                       $rep->NewLine(2);
-                       $rep->fontSize += 2;
-                       $rep->TextCol(0, 3,     $myrow['curr_abrev'] . " " . _('Prices'));
-                       $currcode = $myrow['curr_abrev'];
-                       $rep->fontSize -= 2;
-                       $rep->NewLine();
-               }
                if ($catgor != $myrow['description'])
                {
                        $rep->Line($rep->row  - $rep->lineHeight);
@@ -134,11 +119,13 @@ function print_price_listing()
                $rep->NewLine();
                $rep->TextCol(0, 1,     $myrow['stock_id']);
                $rep->TextCol(1, 2, $myrow['name']);
-               $rep->TextCol(2, 3,     number_format2($myrow['price'], $dec));
+               $price = get_price($myrow['stock_id'], $currency, $salestype);
+               $rep->TextCol(2, 3,     number_format2($price, $dec));
                if ($showGP)
                {
-                       if ($myrow['price'] != 0.0)
-                               $disp = ($myrow['price'] - $myrow['Standardcost']) * 100 / $myrow['price'];
+                       $price2 = get_price($myrow['stock_id'], $home_curr, $salestype);
+                       if ($price2 != 0.0)
+                               $disp = ($price2 - $myrow['Standardcost']) * 100 / $price2;
                        else
                                $disp = 0.0;
                        $rep->TextCol(3, 4,     number_format2($disp, user_percent_dec()) . " %");
index 494a09f84353e41cd126235a4ba3815de56d72de..b5dcc128a1e4f2911485e55b86fedfe52d1d3de2 100644 (file)
@@ -35,7 +35,8 @@ $reports->addReport(_('Customer'),103,_('Customer Detail Listing'),
                        new ReportParam(_('Sales Areas'),'AREAS'),
                        new ReportParam(_('Sales Folk'),'SALESMEN'), new ReportParam(_('Activity Greater Than'),'TEXT'), new ReportParam(_('Activity Less Than'),'TEXT'), new ReportParam(_('Comments'),'TEXTBOX')));
 $reports->addReport(_('Customer'),104,_('Price Listing'),
-       array(  new ReportParam(_('Inventory Category'),'CATEGORIES'),
+       array(  new ReportParam(_('Currency Filter'),'CURRENCY'),
+                       new ReportParam(_('Inventory Category'),'CATEGORIES'),
                        new ReportParam(_('Sales Types'),'SALESTYPES'),
                        new ReportParam(_('Show Pictures'),'YES_NO'),
                        new ReportParam(_('Show GP %'),'YES_NO'),