Removed redundant global wip_act preference, fixed invalid account used for service...
[fa-stable.git] / includes / dashboard.inc
index 4b552cfb33d0677649c01e2a12264fdfe4695c6d..962152b24f816a8826ec0164b24c6c3176a014f2 100644 (file)
@@ -53,9 +53,12 @@ function dashboard($sel_app)
                display_all();
 }
 
-function display_title($title, $colspan=2)
+function display_title($title)
 {
-       echo "<tr><td colspan=$colspan class='headingtext' style='text-align:center;border:0;height:40px;'>$title</td></tr>\n";
+       br();
+       display_heading($title);
+       br();
+       //echo "<tr><td colspan=$colspan class='headingtext' style='background-color:#fff;text-align:center;border:0;height:40px;'>$title</td></tr>\n";
 }      
 
 function table_one()
@@ -115,7 +118,8 @@ function display_stock_topten($type=0)
                $source = _("Manufacturing");
        else    
                $source = _("Items");
-       source_graphic($today, $title, $source, $pg, ($type == 0 ? _("Sales") : _("Value")));
+       source_graphic($today, $title, $source, $pg, ($type == 0 ? _("Sales") : _("Amount")), 
+               ($type == 0 ? _("Costs") : null));
        table_end();
 }
 
@@ -156,7 +160,7 @@ function display_all()
        $title = supplier_top($today, 3, 66, $pg);
        source_graphic($today, $title, _("Supplier"), $pg, _("Purchases"));
        $title = stock_top($today, 3, 66, 0, $pg);
-       source_graphic($today, $title, _("Stock"), $pg, _("Sales"));
+       source_graphic($today, $title, _("Items"), $pg, _("Sales"), _("Costs"));
        table_two();
        dimension_top($today, 3, 66);
        $title = gl_top($today, 66, $pg);
@@ -178,9 +182,9 @@ function customer_top($today, $limit=10, $width="33", &$pg=null)
                LIMIT $limit";
        $result = db_query($sql);
        $title = _("Top $limit customers in fiscal year");
+       display_title($title);
        $th = array(_("Customer"), _("Amount"));
        start_table(TABLESTYLE, "width='$width%'");
-       display_title($title, count($th));
        table_header($th);
        check_page_security('SA_SALESTRANSVIEW');
        $k = 0; //row colour counter
@@ -215,9 +219,9 @@ function supplier_top($today, $limit=10, $width="33", &$pg=null)
                LIMIT $limit";
        $result = db_query($sql);
        $title = _("Top $limit suppliers in fiscal year");
+       display_title($title);
        $th = array(_("Supplier"), _("Amount"));
        start_table(TABLESTYLE, "width='$width%'");
-       display_title($title, count($th));
        table_header($th);
        check_page_security('SA_SUPPTRANSVIEW');
        $k = 0; //row colour counter
@@ -254,7 +258,7 @@ function stock_top($today, $limit=10, $width="33", $type=0, &$pg=null)
        if ($type == 0)
        {
                $sql = "SELECT SUM((trans.unit_price * trans.quantity) * d.rate) AS total, s.stock_id, s.description, 
-                       SUM(trans.quantity) AS qty FROM
+                       SUM(trans.quantity) AS qty, SUM((s.material_cost + s.overhead_cost + s.labour_cost) * trans.quantity) AS costs FROM
                        ".TB_PREF."debtor_trans_details AS trans, ".TB_PREF."stock_master AS s, ".TB_PREF."debtor_trans AS d 
                        WHERE trans.stock_id=s.stock_id AND trans.debtor_trans_type=d.type AND trans.debtor_trans_no=d.trans_no
                        AND (d.type = ".ST_SALESINVOICE." OR d.type = ".ST_CUSTCREDIT.") ";
@@ -269,18 +273,23 @@ function stock_top($today, $limit=10, $width="33", $type=0, &$pg=null)
                elseif ($type == 2)     
                        $sql .= "AND s.mb_flag='F' ";
        }
-       $sql .= "AND tran_date >= '$begin1' AND tran_date <= '$today1' GROUP by s.stock_id ORDER BY total DESC, s.stock_id 
+       if ($type != 2)
+               $sql .= "AND tran_date >= '$begin1' ";
+       $sql .= "AND tran_date <= '$today1' GROUP by s.stock_id ORDER BY total DESC, s.stock_id 
                LIMIT $limit";
        $result = db_query($sql);
        if ($type == 1)
                $title = _("Top $limit Manufactured Items in fiscal year");
        elseif ($type == 2)
-               $title = _("Top $limit Fixed Assets in fiscal year");
+               $title = _("Top $limit Fixed Assets");
        else    
                $title = _("Top $limit Sold Items in fiscal year");
-       $th = array(_("Item"), _("Amount"), _("Quantity"));
+       display_title($title);  
+       if ($type == 0) 
+               $th = array(_("Item"), _("Sales"), _("Costs"), _("Quantity"));
+       else    
+               $th = array(_("Item"), _("Amount"), _("Quantity"));
        start_table(TABLESTYLE, "width='$width%'");
-       display_title($title, count($th));      
        table_header($th);
        check_page_security($sec);
        $k = 0; //row colour counter
@@ -291,11 +300,15 @@ function stock_top($today, $limit=10, $width="33", $type=0, &$pg=null)
                $name = $myrow["description"];
                label_cell($name);
                amount_cell($myrow['total']);
+               if ($type == 0)
+                       amount_cell($myrow['costs']);
                qty_cell($myrow['qty']);
                if ($pg != NULL)
                {
                        $pg->x[$i] = $name; 
                        $pg->y[$i] = $myrow['total'];
+                       if ($type == 0)
+                               $pg->z[$i] = $myrow['costs'];
                }       
                $i++;
                end_row();
@@ -316,9 +329,9 @@ function dimension_top($today, $limit=10, $width="33", &$pg=null)
                t.tran_date >= '$begin1' AND t.tran_date <= '$today1' GROUP BY d.id ORDER BY total DESC LIMIT $limit";
        $result = db_query($sql, "Transactions could not be calculated");
        $title = _("Top $limit Dimensions in fiscal year");
+       display_title($title);
        $th = array(_("Dimension"), _("Amount"));
        start_table(TABLESTYLE, "width='$width%'");
-       display_title($title, count($th));
        table_header($th);
        check_page_security('SA_DIMTRANSVIEW');
        $k = 0; //row colour counter
@@ -354,8 +367,8 @@ function gl_top($today, $width="33", &$pg=null)
                AND tran_date <= '$today1' GROUP BY c.cid ORDER BY c.cid"; 
        $result = db_query($sql, "Transactions could not be calculated");
        $title = _("Class Balances");
-       start_table(TABLESTYLE2, "width='$width%'");
        display_title($title);
+       start_table(TABLESTYLE2, "width='$width%'");
        check_page_security('SA_GLANALYTIC');
        $i = 0;
        $total = 0;
@@ -413,8 +426,8 @@ function gl_performance($today, $width="33", $weeks=5)
        while ($myrow = db_fetch($result))
        {
                $pg->x[$i] = $myrow['week_name']; 
-               $pg->y[$i] = abs($myrow['sales']);
-               $pg->z[$i] = abs($myrow['costs']);
+               $pg->y[$i] = $myrow['sales'];
+               $pg->z[$i] = $myrow['costs'];
                $i++;
        }       
        $pg->x = array_reverse($pg->x);
@@ -426,7 +439,10 @@ function gl_performance($today, $width="33", $weeks=5)
 
 function source_graphic($today, $title, $x_axis, $pg, $graphic1, $graphic2=null, $type=2)
 {
-       $pg->title     = $title . " - " . $today;
+       if (count($pg->y) ==0 || (count($pg->y) == 1 && $pg->y[0] == 0))
+               return;
+       display_title("$title ($today)");       
+       //$pg->title     = $title . " - " . $today;
        $pg->axis_x    = $x_axis;
        $pg->axis_y    = _("Amount");
        $pg->graphic_1 = $graphic1;
@@ -465,14 +481,12 @@ function customer_trans($today)
                        AND DATEDIFF('$today', trans.due_date) > 0 ORDER BY days DESC";
        $result = db_query($sql);
        $title = db_num_rows($result) . _(" overdue Sales Invoices");
-       br(1);
-       display_heading($title);
-       br();
+       display_title($title);
        $th = array("#", _("Ref."), _("Date"), _("Due Date"), _("Customer"), _("Branch"), _("Currency"), 
                _("Total"), _("Remainder"),     _("Days"));
        start_table(TABLESTYLE);
        table_header($th);
-       $k = 0; //row colour counter
+       $k = 0; //row colour counter
        while ($myrow = db_fetch($result))
        {
                alt_table_row_color($k);
@@ -507,12 +521,10 @@ function customer_recurrent_invoices($today)
 {
        $result = get_recurrent_invoices($today);
        $title = _("Overdue Recurrent Invoices");
-       br(1);
-       display_heading($title);
-       br();
+       display_title($title);
        $th = array(_("Description"), _("Template No"),_("Customer"),_("Branch")."/"._("Group"),_("Next invoice"));
        start_table(TABLESTYLE, "width=70%");
-       table_header($th);
+       table_header($th);
        $k = 0;
        while ($myrow = db_fetch($result)) 
        {
@@ -554,9 +566,7 @@ function supplier_trans($today)
                        AND DATEDIFF('$today', trans.due_date) > 0 ORDER BY days DESC";
        $result = db_query($sql);
        $title = db_num_rows($result) . _(" overdue Purchase Invoices");
-       br(1);
-       display_heading($title);
-       br();
+       display_title($title);
        $th = array("#", _("Ref."), _("Date"), _("Due Date"), _("Supplier"), _("Currency"), _("Total"), 
                _("Remainder"), _("Days"));
        start_table(TABLESTYLE);
@@ -583,7 +593,7 @@ function supplier_trans($today)
 function bank_balance($today, $width)
 {
        $today = date2sql($today);
-       $sql = "SELECT bank_act, bank_account_name, SUM(amount) balance FROM ".TB_PREF."bank_trans bt 
+       $sql = "SELECT bank_act, bank_account_name, bank_curr_code, SUM(amount) balance FROM ".TB_PREF."bank_trans bt 
                    INNER JOIN ".TB_PREF."bank_accounts ba ON bt.bank_act = ba.id
                    WHERE trans_date <= '$today'
                    AND inactive <> 1
@@ -591,10 +601,8 @@ function bank_balance($today, $width)
                                ORDER BY bank_account_name";
        $result = db_query($sql);
        $title = _("Bank Account Balances");
-       br(1);
-       display_heading($title);
-       br();
-       $th = array(_("Account"), _("Balance"));
+       display_title($title);
+       $th = array(_("Account"), _("Currency"), _("Balance"));
        start_table(TABLESTYLE, "width='$width%'");
        table_header($th);
        $k = 0; //row colour counter
@@ -602,6 +610,7 @@ function bank_balance($today, $width)
        {
                alt_table_row_color($k);
                label_cell(viewer_link($myrow["bank_account_name"], 'gl/inquiry/bank_inquiry.php?bank_account='.$myrow["bank_act"]));
+               label_cell($myrow["bank_curr_code"]);
                amount_cell($myrow['balance']);
                end_row();
        }