[0005214] Stock Check Sheet: changed option name to less confusing for shortages...
[fa-stable.git] / includes / dashboard.inc
index af8219a9cb49c4e7e162a911c36c6e09eb96ca53..9a5a9f4b5ce57e024ebc5292ffecdcfde36c7e31 100644 (file)
@@ -15,7 +15,7 @@ function dashboard($sel_app)
        $selected_app = $sel_app;
 
 
-       if (!$_SESSION["wa_current_user"]->check_application_access($selected_app))
+       if (is_object($sel_app) && !$_SESSION["wa_current_user"]->check_application_access($selected_app))
                return;
        // first have a look through the directory, 
        // and remove old temporary pdfs and pngs
@@ -157,12 +157,15 @@ function display_all()
        table_one();
        $title = customer_top($today, 3, 66, $pg);
        source_graphic($today, $title, _("Customer"), $pg, _("Sales"));
+       $pg = new graph();
        $title = supplier_top($today, 3, 66, $pg);
        source_graphic($today, $title, _("Supplier"), $pg, _("Purchases"));
+       $pg = new graph();
        $title = stock_top($today, 3, 66, 0, $pg);
        source_graphic($today, $title, _("Items"), $pg, _("Sales"), _("Costs"));
        table_two();
        dimension_top($today, 3, 66);
+       $pg = new graph();
        $title = gl_top($today, 66, $pg);
        source_graphic($today, $title, _("Class"), $pg, _("Amount"), null, 5);
        stock_top($today, 3, 66, 2);
@@ -192,7 +195,7 @@ function customer_top($today, $limit=10, $width="33", &$pg=null)
        while ($myrow = db_fetch($result))
        {
                alt_table_row_color($k);
-               $name = $myrow["debtor_no"]." ".$myrow["name"];
+               $name = $myrow["debtor_no"]." ".htmlspecialchars_decode($myrow["name"]);
                label_cell($name);
                amount_cell($myrow['total']);
                if ($pg != null)
@@ -229,7 +232,7 @@ function supplier_top($today, $limit=10, $width="33", &$pg=null)
        while ($myrow = db_fetch($result))
        {
                alt_table_row_color($k);
-               $name = $myrow["supplier_id"]." ".$myrow["supp_name"];
+               $name = $myrow["supplier_id"]." ".htmlspecialchars_decode($myrow["supp_name"]);
                label_cell($name);
                amount_cell($myrow['total']);
                if ($pg != null)
@@ -269,7 +272,7 @@ function stock_top($today, $limit=10, $width="33", $type=0, &$pg=null)
                        SUM(qty) AS qty FROM ".TB_PREF."stock_master AS s, ".TB_PREF."stock_moves AS m 
                        WHERE s.stock_id=m.stock_id ";
                if ($type == 1)
-                       $sql .= "AND s.mb_flag='M' ";
+                       $sql .= "AND s.mb_flag='M' AND m.type <> ".ST_CUSTDELIVERY." AND m.type <> ".ST_CUSTCREDIT." ";
                elseif ($type == 2)     
                        $sql .= "AND s.mb_flag='F' ";
        }
@@ -403,20 +406,22 @@ function gl_top($today, $width="33", &$pg=null)
 
 function gl_performance($today, $width="33", $weeks=5)
 {
+       global $SysPrefs;
        $pg = new graph();
 
        $begin = begin_fiscalyear();
        $begin1 = date2sql($begin);
        $today1 = date2sql($today);
+       $sep = $SysPrefs->dateseps[user_date_sep()];
        $sql = "SELECT week_name, sales, costs 
-               FROM(SELECT DATE_FORMAT(tran_date, '%Y-%u') AS week_name, 
+               FROM(SELECT DATE_FORMAT(tran_date, '%Y{$sep}%u') AS week_name, 
                        SUM(IF(c.ctype = 4, amount * -1, 0)) AS sales, 
                        SUM(IF(c.ctype = 6, amount, 0)) AS costs FROM 
                        ".TB_PREF."gl_trans, ".TB_PREF."chart_master AS a, ".TB_PREF."chart_types AS t, 
                        ".TB_PREF."chart_class AS c WHERE(c.ctype = 4 OR c.ctype = 6) 
                        AND account = a.account_code AND a.account_type = t.id AND t.class_id = c.cid 
                        AND tran_date >= '$begin1' AND tran_date <= '$today1' 
-                       GROUP BY week_name ORDER BY week_name DESC      LIMIT 0, 5) b 
+                       GROUP BY week_name ORDER BY week_name DESC LIMIT 0, $weeks) b 
                GROUP BY week_name ORDER BY week_name ASC";
        $result = db_query($sql, "Transactions could not be calculated");
        $title = _("Last $weeks weeks Performance");