X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=includes%2Fdashboard.inc;h=bb6e6e258335fd231bd3bc75f987f302b663426e;hb=e01ce098c8862750e2f4f66f255191e83a4ce1d6;hp=f78a4cb36834d27f79833a5ea2773e922fd4986e;hpb=119094231dbc6f0f570c7dab3227d653b8b601c9;p=fa-stable.git
diff --git a/includes/dashboard.inc b/includes/dashboard.inc
index f78a4cb3..bb6e6e25 100644
--- a/includes/dashboard.inc
+++ b/includes/dashboard.inc
@@ -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
@@ -53,9 +53,12 @@ function dashboard($sel_app)
display_all();
}
-function display_title($title, $colspan=2)
+function display_title($title)
{
- echo "
$title |
\n";
+ br();
+ display_heading($title);
+ br();
+ //echo "$title |
\n";
}
function table_one()
@@ -154,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, _("Stock"), $pg, _("Sales"));
+ 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);
@@ -178,10 +184,10 @@ function customer_top($today, $limit=10, $width="33", &$pg=null)
AND tran_date >= '$begin1' AND tran_date <= '$today1' GROUP by d.debtor_no ORDER BY total DESC, d.debtor_no
LIMIT $limit";
$result = db_query($sql);
- $title = _("Top $limit customers in fiscal year");
+ $title = sprintf(_("Top %s customers in fiscal year"), $limit);
+ 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,10 +221,10 @@ function supplier_top($today, $limit=10, $width="33", &$pg=null)
AND tran_date >= '$begin1' AND tran_date <= '$today1' GROUP by s.supplier_id ORDER BY total DESC, s.supplier_id
LIMIT $limit";
$result = db_query($sql);
- $title = _("Top $limit suppliers in fiscal year");
+ $title = sprintf(_("Top %s suppliers in fiscal year"), $limit);
+ 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
@@ -266,25 +272,27 @@ 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' ";
}
- $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");
+ $title = sprintf(_("Top %s Manufactured Items in fiscal year"), $limit);
elseif ($type == 2)
- $title = _("Top $limit Fixed Assets in fiscal year");
+ $title = sprintf(_("Top %s Fixed Assets"), $limit);
else
- $title = _("Top $limit Sold Items in fiscal year");
+ $title = sprintf(_("Top %s Sold Items in fiscal year"), $limit);
+ 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
@@ -323,10 +331,10 @@ function dimension_top($today, $limit=10, $width="33", &$pg=null)
(t.dimension_id = d.id OR t.dimension2_id = d.id) AND
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");
+ $title = sprintf(_("Top %s Dimensions in fiscal year"), $limit);
+ 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
@@ -362,8 +370,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;
@@ -398,22 +406,23 @@ 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);
- $sql = "SELECT CONCAT(YEAR(tran_date), '/', WEEK(tran_date)) AS week_name,
- SUM(IF (c.ctype = 4, amount * -1, 0)) AS sales,
- SUM(IF (c.ctype = 6, amount, 0)) AS costs
- FROM
+ $sep = $SysPrefs->dateseps[user_date_sep()];
+ $sql = "SELECT week_name, sales, costs
+ 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 IF(c.ctype > 3, tran_date >= '$begin1', tran_date >= '0000-00-00')
- AND tran_date <= '$today1'
- GROUP BY week_name
- ORDER BY YEAR(tran_date) DESC, WEEK(tran_date) DESC limit 0, $weeks";
+ ".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, $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");
check_page_security('SA_GLANALYTIC');
@@ -425,9 +434,6 @@ function gl_performance($today, $width="33", $weeks=5)
$pg->z[$i] = $myrow['costs'];
$i++;
}
- $pg->x = array_reverse($pg->x);
- $pg->y = array_reverse($pg->y);
- $pg->z = array_reverse($pg->z);
source_graphic($today, $title, _("Week"), $pg, _("Sales"), _("Costs"), 1);
}
@@ -436,7 +442,8 @@ function source_graphic($today, $title, $x_axis, $pg, $graphic1, $graphic2=null,
{
if (count($pg->y) ==0 || (count($pg->y) == 1 && $pg->y[0] == 0))
return;
- $pg->title = $title . " - " . $today;
+ display_title("$title ($today)");
+ //$pg->title = $title . " - " . $today;
$pg->axis_x = $x_axis;
$pg->axis_y = _("Amount");
$pg->graphic_1 = $graphic1;
@@ -445,7 +452,7 @@ function source_graphic($today, $title, $x_axis, $pg, $graphic1, $graphic2=null,
$pg->type = $type;
$pg->skin = 1;
$pg->built_in = false;
- $filename = company_path(). "/pdf_files/". uniqid("").".png";
+ $filename = company_path(). "/pdf_files/". random_id().".png";
$pg->display($filename, true);
start_table(TABLESTYLE);
start_row();
@@ -475,14 +482,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);
@@ -517,12 +522,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))
{
@@ -564,9 +567,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);
@@ -593,7 +594,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
@@ -601,10 +602,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
@@ -612,6 +611,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();
}