Skip to content

Commit

Permalink
Added dashboard widget for unpaid purchase invoices.
Browse files Browse the repository at this point in the history
  • Loading branch information
notrinos committed Aug 20, 2022
1 parent 0362778 commit 84c959c
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 8 deletions.
17 changes: 9 additions & 8 deletions admin/dashboard.php
Expand Up @@ -13,10 +13,10 @@
$page_security = 'SA_SETUPDISPLAY';
$path_to_root = '..';

include_once($path_to_root . '/includes/session.inc');
include_once($path_to_root . '/includes/ui.inc');
include_once($path_to_root . '/reporting/includes/class.graphic.inc');
include_once($path_to_root . '/dashboard/includes/dashboard_classes.inc');
include_once($path_to_root.'/includes/session.inc');
include_once($path_to_root.'/includes/ui.inc');
include_once($path_to_root.'/reporting/includes/class.graphic.inc');
include_once($path_to_root.'/dashboard/includes/dashboard_classes.inc');

$js = '';
if ($SysPrefs->use_popup_windows)
Expand All @@ -35,7 +35,8 @@

if ($d = @opendir($dir)) {
while (($file = readdir($d)) !== false) {
if (!is_file($dir.'/'.$file) || $file == 'index.php') continue;
if (!is_file($dir.'/'.$file) || $file == 'index.php')
continue;
$ftime = filemtime($dir.'/'.$file);

if (time()-$ftime > 180)
Expand All @@ -56,6 +57,7 @@
$dashboard->addWidget(DA_SUPPLIER, 201, WIDGET_HALF);
$dashboard->addWidget(DA_SUPPLIER, 202, WIDGET_HALF);
$dashboard->addWidget(DA_SUPPLIER, 203, WIDGET_HALF);
$dashboard->addWidget(DA_SUPPLIER, 204, WIDGET_HALF);

$dashboard->addDashboard(_('Inventory'), DA_INVENTORY);
$dashboard->addWidget(DA_INVENTORY, 301, WIDGET_HALF);
Expand Down Expand Up @@ -97,8 +99,7 @@

echo $dashboard->display();
}
else {
else
display_error(_('Mising context data'));
}

end_page();
end_page();
7 changes: 7 additions & 0 deletions dashboard/includes/dashboard_classes.inc
Expand Up @@ -267,3 +267,10 @@ function supplier_trans($today) {

return $result;
}

function supplier_unpaid_invoices($today) {
$today = date2sql($today);
$sql = "SELECT trans.trans_no, trans.reference, trans.tran_date, trans.due_date, s.supplier_id, s.supp_name, s.curr_code, (trans.ov_amount + trans.ov_gst + trans.ov_discount) AS total, (trans.ov_amount + trans.ov_gst + trans.ov_discount - trans.alloc) AS remainder, DATEDIFF(trans.due_date, '$today') AS days 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 ASC";

return db_query($sql, 'could not get supplier transactions');
}
47 changes: 47 additions & 0 deletions dashboard/widget204.php
@@ -0,0 +1,47 @@
<?php
/**********************************************************************
Copyright (C) NotrinosERP.
Released under the terms of the GNU General Public License, GPL,
as published by the Free Software Foundation, either version 3
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
***********************************************************************/

$today = Today();
$result = supplier_unpaid_invoices($today);
$num = db_num_rows($result);
$title = sprintf(_("%s unpaid Purchase Invoices"), $num);

$widget = new Widget();
$widget->setTitle($title);
$widget->Start();

$th = array('#', _('Ref.'), _('Date'), _('Due Date'), _('Supplier'), _('Currency'), _('Total'), _('Remainder'), _('Days'));

if($widget->checkSecurity('SA_SUPPTRANSVIEW')) {

start_table(TABLESTYLE, "width='100%'");
table_header($th);
$k = 0;
while ($myrow = db_fetch($result)) {
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']));
label_cell(sql2date($myrow['due_date']));
$name = $myrow['supplier_id'].' '.$myrow['supp_name'];
label_cell($name);
label_cell($myrow['curr_code']);
amount_cell($myrow['total']);
amount_cell($myrow['remainder']);
label_cell($myrow['days'], "align='right'");
end_row();
}
end_table();
}

$widget->End();

0 comments on commit 84c959c

Please sign in to comment.