Show also Upcoming Purchase Invoices - in Dashboard. Fixed.
[fa-stable.git] / includes / dashboard.inc
index f666f26f9135d3fe7e9d81613c1d78e40d605b5e..57db155207a056a12c96ca085ac297548192441a 100644 (file)
@@ -737,7 +737,7 @@ function gl_week_performance($today, $width="33", $weeks=4)
        $pg->setLabels($week_names);
        $pg->addSerie(_('Sales'), $sales, 'bar');
        $pg->addSerie(_('Costs'), $costs, 'bar');
-       $pg->addSerie(_('Results'), $results, 8);
+       $pg->addSerie(_('Results'), $results, 'spline');
        source_graphic($today, $title, _("Week"), $pg, _("Weeks"), $weeks);
 }
 
@@ -776,7 +776,7 @@ function gl_month_performance($today, $width="33", $months=5)
        $pg->setLabels($month_names);
        $pg->addSerie(_('Sales'), $sales, 'bar');
        $pg->addSerie(_('Costs'), $costs, 'bar');
-       $pg->addSerie(_('Results'), $results, 8);
+       $pg->addSerie(_('Results'), $results, 'spline');
        source_graphic($today, $title, _("Month"), $pg, _("Months"), $months);
 }
 
@@ -788,10 +788,12 @@ function customer_aging($today, $width="33")
        $today1 = date2sql($today);
        $past1 = get_company_pref('past_due_days');
        $past2 = 2 * $past1;
-       // removed - debtor_trans.alloc from all summations
+
        $sign = "IF(`type` IN(".implode(',',  array(ST_CUSTCREDIT,ST_CUSTPAYMENT,ST_BANKDEPOSIT))."), -1, 1)";
-       $value = "IFNULL($sign*((trans.ov_amount + trans.ov_gst + trans.ov_freight + trans.ov_freight_tax + trans.ov_discount - 
-               trans.alloc)*trans.rate),0)";
+
+       $value = "$sign*(IF(trans.prep_amount, trans.prep_amount,
+               ABS(trans.ov_amount + trans.ov_gst + trans.ov_freight + trans.ov_freight_tax + trans.ov_discount)) - trans.alloc)*trans.rate";
+
        $due = "IF (trans.type=".ST_SALESINVOICE.", trans.due_date, trans.tran_date)";
     $sql = "SELECT Sum($value) AS Balance,
                                Sum(IF ((TO_DAYS('$today1') - TO_DAYS($due)) > 0,$value,0)) AS Due,
@@ -804,7 +806,7 @@ function customer_aging($today, $width="33")
                        WHERE
                                        debtor.payment_terms = terms.terms_indicator
                                AND debtor.credit_status = credit_status.id";
-               $sql .= " AND ABS(trans.ov_amount + trans.ov_gst + trans.ov_freight + trans.ov_freight_tax + trans.ov_discount) - trans.alloc > ".FLOAT_COMP_DELTA;
+               $sql .= " AND ABS(IF(trans.prep_amount, trans.prep_amount, ABS(trans.ov_amount) + trans.ov_gst + trans.ov_freight + trans.ov_freight_tax + trans.ov_discount) - trans.alloc) > ".FLOAT_COMP_DELTA;
     $result = db_query($sql,"The customer details could not be retrieved");
 
     $row = db_fetch($result);
@@ -1086,19 +1088,25 @@ function supplier_trans($today)
                FROM ".TB_PREF."supp_trans as trans, ".TB_PREF."suppliers as s 
                WHERE s.supplier_id = trans.supplier_id
                        AND trans.type = ".ST_SUPPINVOICE." AND (ABS(trans.ov_amount + trans.ov_gst + 
-                               trans.ov_discount) - trans.alloc) > ".FLOAT_COMP_DELTA."
-                       AND DATEDIFF('$today', trans.due_date) > 0 ORDER BY days DESC";
+                               trans.ov_discount) - trans.alloc) > ".FLOAT_COMP_DELTA." ORDER BY days DESC";
        $result = db_query($sql);
-       $title = db_num_rows($result) . _(" overdue Purchase Invoices");
+       $title = db_num_rows($result) . _(" unpaid Purchase Invoices");
        display_title($title);
        $th = array("#", _("Ref."), _("Date"), _("Due Date"), _("Supplier"), _("Currency"), _("Total"), 
                _("Remainder"), _("Days"));
        start_table(TABLESTYLE, "width=90%");
        headers($th);
        $k = 0; //row colour counter
+       $due = false;
        while ($myrow = db_fetch($result))
        {
-               alt_table_row_color($k);
+               if ($myrow['days'] > 0)
+               {
+                       start_row("class='overduebg'");
+                       $due = true;
+               }
+               else
+                       alt_table_row_color($k);
                label_cell(get_trans_view_str(ST_SUPPINVOICE, $myrow["trans_no"]));
                label_cell($myrow['reference']);
                label_cell(sql2date($myrow['tran_date']));
@@ -1111,7 +1119,10 @@ function supplier_trans($today)
                label_cell($myrow['days'], "align='right'");
                end_row();
        }
-       end_table(2);
+       end_table();
+       if ($due)
+               display_note(_("Marked items are overdue."), 1, 0, "class='overduefg'");
+       br();
 }
 
 function stock_below_reorder($today, $type)