function render($id, $title)
 {
     global $path_to_root;
     include_once $path_to_root . "/includes/ui.inc";
     include_once $path_to_root . "/reporting/includes/class.graphic.inc";
     if (!defined('FLOAT_COMP_DELTA')) {
         define('FLOAT_COMP_DELTA', 0.004);
     }
     if (!isset($this->top)) {
         $this->top = 10;
     }
     $begin = begin_fiscalyear();
     $today = Today();
     $begin1 = date2sql($begin);
     $today1 = date2sql($today);
     $sql = "SELECT SUM((trans.ov_amount + trans.ov_discount) * rate) AS total, s.supplier_id, s.supp_name FROM\n            " . TB_PREF . "supp_trans AS trans, " . TB_PREF . "suppliers AS s WHERE trans.supplier_id=s.supplier_id\n            AND (trans.type = " . ST_SUPPINVOICE . " OR trans.type = " . ST_SUPPCREDIT . ")\n            AND tran_date >= '{$begin1}' AND tran_date <= '{$today1}' ";
     if ($this->data_filter != '') {
         $sql .= ' AND ' . $this->data_filter;
     }
     $sql .= "GROUP by s.supplier_id ORDER BY total DESC, s.supplier_id " . " LIMIT " . $this->top;
     $result = db_query($sql);
     if ($this->graph_type == 'Table') {
         $th = array(_("Supplier"), _("Amount"));
         start_table(TABLESTYLE, "width=98%");
         table_header($th);
         $k = 0;
         //row colour counter
         while ($myrow = db_fetch($result)) {
             alt_table_row_color($k);
             $name = $myrow["supplier_id"] . " " . $myrow["supp_name"];
             label_cell($name);
             amount_cell($myrow['total']);
             end_row();
         }
         end_table(1);
     } else {
         $pg = new graph();
         $i = 0;
         while ($myrow = db_fetch($result)) {
             $name = $myrow["supplier_id"] . " " . $myrow["supp_name"];
             $pg->x[$i] = $name;
             $pg->y[$i] = $myrow['total'];
             $i++;
         }
         $pg->title = $title;
         $pg->axis_x = _("Supplier");
         $pg->axis_y = _("Amount");
         $pg->graphic_1 = $today;
         $pg->type = 2;
         $pg->skin = 1;
         $pg->built_in = false;
         $filename = company_path() . "/pdf_files/" . uniqid("") . ".png";
         $pg->display($filename, true);
         echo "<img src='{$filename}' border='0' alt='{$title}' style='max-width:100%'>";
     }
 }
Esempio n. 2
0
 function render($id, $title)
 {
     global $path_to_root;
     include_once $path_to_root . "/reporting/includes/class.graphic.inc";
     if (!defined('FLOAT_COMP_DELTA')) {
         define('FLOAT_COMP_DELTA', 0.004);
     }
     if (!isset($this->top)) {
         $this->top = 10;
     }
     $begin = begin_fiscalyear();
     $today = Today();
     $begin1 = date2sql($begin);
     $today1 = date2sql($today);
     $sql = "SELECT SUM((ov_amount + ov_discount) * rate * IF(trans.type = " . ST_CUSTCREDIT . ", -1, 1)) AS total,d.debtor_no, d.name" . " FROM " . TB_PREF . "debtor_trans AS trans, " . TB_PREF . "debtors_master AS d" . " WHERE trans.debtor_no=d.debtor_no" . " AND (trans.type = " . ST_SALESINVOICE . " OR trans.type = " . ST_CUSTCREDIT . ")" . " AND tran_date >= '{$begin1}' AND tran_date <= '{$today1}'";
     if ($this->data_filter != '') {
         $sql .= ' AND ' . $this->data_filter;
     }
     $sql .= " GROUP by d.debtor_no ORDER BY total DESC, d.debtor_no " . " LIMIT " . $this->top;
     $result = db_query($sql);
     if ($this->graph_type == 'Table') {
         $th = array(null, _("Customer"), _("Amount"));
         start_table(TABLESTYLE, "width=98%");
         table_header($th);
         $k = 0;
         //row colour counter
         $i = 0;
         while ($myrow = db_fetch($result)) {
             alt_table_row_color($k);
             label_cell(viewer_link($myrow["debtor_no"], 'sales/inquiry/customer_inquiry.php?customer_id=' . $myrow["debtor_no"]));
             label_cell(viewer_link($myrow["name"], 'sales/inquiry/customer_inquiry.php?customer_id=' . $myrow["debtor_no"]));
             amount_cell($myrow['total']);
             end_row();
         }
         end_table(1);
     } else {
         $pg = new graph();
         $i = 0;
         while ($myrow = db_fetch($result)) {
             $pg->x[$i] = $myrow["debtor_no"] . " " . $myrow["name"];
             $pg->y[$i] = $myrow['total'];
             $i++;
         }
         $pg->title = $title;
         $pg->axis_x = _("Customer");
         $pg->axis_y = _("Amount");
         $pg->graphic_1 = $today;
         $pg->type = 2;
         $pg->skin = 1;
         $pg->built_in = false;
         $filename = company_path() . "/pdf_files/" . uniqid("") . ".png";
         $pg->display($filename, true);
         echo "<img src='{$filename}' border='0' alt='{$title}' style='max-width:100%'>";
     }
 }
Esempio n. 3
0
 function render($id, $title)
 {
     global $path_to_root;
     include_once $path_to_root . "/reporting/includes/class.graphic.inc";
     $begin = begin_fiscalyear();
     $today = Today();
     $begin1 = date2sql($begin);
     $today1 = date2sql($today);
     $sql = "SELECT SUM(amount) AS total, c.class_name, c.ctype FROM\n            " . TB_PREF . "gl_trans," . TB_PREF . "chart_master AS a, " . TB_PREF . "chart_types AS t,\n            " . TB_PREF . "chart_class AS c WHERE\n            account = a.account_code AND a.account_type = t.id AND t.class_id = c.cid\n            AND IF(c.ctype > 3, tran_date >= '{$begin1}', tran_date >= '0000-00-00')\n            AND tran_date <= '{$today1}' ";
     if ($this->data_filter != '') {
         $sql .= ' AND ' . $this->data_filter;
     }
     $sql .= " GROUP BY c.cid ORDER BY c.cid";
     $result = db_query($sql, "Transactions could not be calculated");
     $calculated = _("Calculated Return");
     if ($this->graph_type == 'Table') {
         start_table(TABLESTYLE2, "width=98%");
         $total = 0;
         while ($myrow = db_fetch($result)) {
             if ($myrow['ctype'] > 3) {
                 $total += $myrow['total'];
                 $myrow['total'] = -$myrow['total'];
             }
             label_row($myrow['class_name'], number_format2($myrow['total'], user_price_dec()), "class='label' style='font-weight:bold;'", "style='font-weight:bold;' align=right");
         }
         label_row("&nbsp;", "");
         label_row($calculated, number_format2(-$total, user_price_dec()), "class='label' style='font-weight:bold;'", "style='font-weight:bold;' align=right");
         end_table(1);
     } else {
         $pg = new graph();
         $i = 0;
         $total = 0;
         while ($myrow = db_fetch($result)) {
             if ($myrow['ctype'] > 3) {
                 $total += $myrow['total'];
                 $myrow['total'] = -$myrow['total'];
                 $pg->x[$i] = $myrow['class_name'];
                 $pg->y[$i] = abs($myrow['total']);
                 $i++;
             }
         }
         $pg->x[$i] = $calculated;
         $pg->y[$i] = -$total;
         $pg->title = $title;
         $pg->axis_x = _("Class");
         $pg->axis_y = _("Amount");
         $pg->graphic_1 = $today;
         $pg->type = 5;
         $pg->skin = 1;
         $pg->built_in = false;
         $filename = company_path() . "/pdf_files/" . uniqid("") . ".png";
         $pg->display($filename, true);
         echo "<img src='{$filename}' border='0' alt='{$title}' style='max-width:100%'>";
     }
 }
Esempio n. 4
0
 function render($id, $title)
 {
     global $path_to_root;
     if (!isset($this->top)) {
         $this->top = 10;
     }
     global $path_to_root;
     $pg = new graph();
     $begin = begin_fiscalyear();
     $today = Today();
     $begin1 = date2sql($begin);
     $today1 = date2sql($today);
     $sql = "SELECT SUM(-t.amount) AS total, d.reference, d.name FROM\n            " . TB_PREF . "gl_trans AS t," . TB_PREF . "dimensions AS d WHERE\n            (t.dimension_id = d.id OR t.dimension2_id = d.id) AND\n            t.tran_date >= '{$begin1}' AND t.tran_date <= '{$today1}' ";
     if ($this->data_filter != '') {
         $sql .= ' AND ' . $this->data_filter;
     }
     $sql .= "GROUP BY d.id ORDER BY total DESC LIMIT " . $this->top;
     $result = db_query($sql, "Transactions could not be calculated");
     if ($this->graph_type == 'Table') {
         $title = _("Top 10 Dimensions in fiscal year");
         br(2);
         display_heading($title);
         br();
         $th = array(_("Dimension"), _("Amount"));
         start_table(TABLESTYLE, "width=98%");
         table_header($th);
         $k = 0;
         //row colour counter
         while ($myrow = db_fetch($result)) {
             alt_table_row_color($k);
             label_cell($myrow['reference'] . " " . $myrow["name"]);
             amount_cell($myrow['total']);
             end_row();
         }
         end_table(2);
     } else {
         $pg = new graph();
         $i = 0;
         while ($myrow = db_fetch($result)) {
             $pg->x[$i] = $myrow['reference'] . " " . $myrow["name"];
             $pg->y[$i] = abs($myrow['total']);
             $i++;
         }
         $pg->title = $title;
         $pg->axis_x = _("Dimension");
         $pg->axis_y = _("Amount");
         $pg->graphic_1 = $today;
         $pg->type = 5;
         $pg->skin = 1;
         $pg->built_in = false;
         $filename = company_path() . "/pdf_files/" . uniqid("") . ".png";
         $pg->display($filename, true);
         echo "<img src='{$filename}' border='0' alt='{$title}' style='max-width:100%'>";
     }
 }
Esempio n. 5
0
function print_profit_and_loss_statement()
{
    global $comp_path, $path_to_root;
    include_once $path_to_root . "reporting/includes/pdf_report.inc";
    $dim = get_company_pref('use_dimension');
    $dimension = $dimension2 = 0;
    $from = $_REQUEST['PARAM_0'];
    $to = $_REQUEST['PARAM_1'];
    $compare = $_REQUEST['PARAM_2'];
    if ($dim == 2) {
        $dimension = $_REQUEST['PARAM_3'];
        $dimension2 = $_REQUEST['PARAM_4'];
        $graphics = $_REQUEST['PARAM_5'];
        $comments = $_REQUEST['PARAM_6'];
    } else {
        if ($dim == 1) {
            $dimension = $_REQUEST['PARAM_3'];
            $graphics = $_REQUEST['PARAM_4'];
            $comments = $_REQUEST['PARAM_5'];
        } else {
            $graphics = $_REQUEST['PARAM_3'];
            $comments = $_REQUEST['PARAM_4'];
        }
    }
    if ($graphics) {
        include_once $path_to_root . "reporting/includes/class.graphic.inc";
        $pg = new graph();
    }
    $dec = 0;
    $pdec = user_percent_dec();
    $cols = array(0, 50, 200, 350, 425, 500);
    //------------0--1---2----3----4----5--
    $headers = array(tr('Account'), tr('Account Name'), tr('Period'), tr('Accumulated'), tr('Achieved %'));
    $aligns = array('left', 'left', 'right', 'right', 'right');
    if ($dim == 2) {
        $params = array(0 => $comments, 1 => array('text' => tr('Period'), 'from' => $from, 'to' => $to), 2 => array('text' => tr('Dimension') . " 1", 'from' => get_dimension_string($dimension), 'to' => ''), 3 => array('text' => tr('Dimension') . " 2", 'from' => get_dimension_string($dimension2), 'to' => ''));
    } else {
        if ($dim == 1) {
            $params = array(0 => $comments, 1 => array('text' => tr('Period'), 'from' => $from, 'to' => $to), 2 => array('text' => tr('Dimension'), 'from' => get_dimension_string($dimension), 'to' => ''));
        } else {
            $params = array(0 => $comments, 1 => array('text' => tr('Period'), 'from' => $from, 'to' => $to));
        }
    }
    if ($compare == 0 || $compare == 2) {
        $end = $to;
        if ($compare == 2) {
            $begin = $from;
            $headers[3] = tr('Budget');
        } else {
            $begin = begin_fiscalyear();
        }
    } elseif ($compare == 1) {
        $begin = add_months($from, -12);
        $end = add_months($to, -12);
        $headers[3] = tr('Period Y-1');
    }
    $rep = new FrontReport(tr('Profit and Loss Statement'), "ProfitAndLoss.pdf", user_pagesize());
    $rep->Font();
    $rep->Info($params, $cols, $headers, $aligns);
    $rep->Header();
    $classname = '';
    $group = '';
    $totalper = 0.0;
    $totalacc = 0.0;
    $classper = 0.0;
    $classacc = 0.0;
    $salesper = 0.0;
    $salesacc = 0.0;
    $accounts = get_gl_accounts_all(0);
    while ($account = db_fetch($accounts)) {
        $per_balance = get_gl_trans_from_to($from, $to, $account["account_code"], $dimension, $dimension2);
        if ($compare == 2) {
            $acc_balance = get_budget_trans_from_to($begin, $end, $account["account_code"], $dimension, $dimension2);
        } else {
            $acc_balance = get_gl_trans_from_to($begin, $end, $account["account_code"], $dimension, $dimension2);
        }
        if (!$per_balance && !$acc_balance) {
            continue;
        }
        if ($account['AccountClassName'] != $classname) {
            if ($classname != '') {
                $closeclass = true;
            }
        }
        if ($account['AccountTypeName'] != $group) {
            if ($group != '') {
                $rep->Line($rep->row + 6);
                $rep->row -= 6;
                $rep->TextCol(0, 2, tr('Total') . " " . $group);
                $rep->TextCol(2, 3, number_format2($totalper, $dec));
                $rep->TextCol(3, 4, number_format2($totalacc, $dec));
                $rep->TextCol(4, 5, number_format2(Achieve($totalper, $totalacc), $pdec));
                if ($graphics) {
                    $pg->x[] = $group;
                    $pg->y[] = abs($totalper);
                    $pg->z[] = abs($totalacc);
                }
                $totalper = $totalacc = 0.0;
                $rep->row -= $rep->lineHeight + 4;
                if ($closeclass) {
                    $rep->Line($rep->row + 6);
                    $rep->row -= 6;
                    $rep->Font('bold');
                    $rep->TextCol(0, 2, tr('Total') . " " . $classname);
                    $rep->TextCol(2, 3, number_format2($classper, $dec));
                    $rep->TextCol(3, 4, number_format2($classacc, $dec));
                    $rep->TextCol(4, 5, number_format2(Achieve($classper, $classacc), $pdec));
                    $rep->Font();
                    $salesper += $classper;
                    $salesacc += $classacc;
                    $classper = $classacc = 0.0;
                    $rep->NewLine(3);
                    $closeclass = false;
                }
            }
            if ($account['AccountClassName'] != $classname) {
                $rep->Font('bold');
                $rep->TextCol(0, 5, $account['AccountClassName']);
                $rep->Font();
                $rep->row -= $rep->lineHeight + 4;
            }
            $group = $account['AccountTypeName'];
            $rep->TextCol(0, 5, $account['AccountTypeName']);
            $rep->Line($rep->row - 4);
            $rep->row -= $rep->lineHeight + 4;
        }
        $classname = $account['AccountClassName'];
        $per_balance *= -1;
        $acc_balance *= -1;
        $totalper += $per_balance;
        $totalacc += $acc_balance;
        $classper += $per_balance;
        $classacc += $acc_balance;
        $rep->TextCol(0, 1, $account['account_code']);
        $rep->TextCol(1, 2, $account['account_name']);
        $rep->TextCol(2, 3, number_format2($per_balance, $dec));
        $rep->TextCol(3, 4, number_format2($acc_balance, $dec));
        $rep->TextCol(4, 5, number_format2(Achieve($per_balance, $acc_balance), $pdec));
        $rep->NewLine();
        if ($rep->row < $rep->bottomMargin + 3 * $rep->lineHeight) {
            $rep->Line($rep->row - 2);
            $rep->Header();
        }
    }
    if ($account['AccountClassName'] != $classname) {
        if ($classname != '') {
            $closeclass = true;
        }
    }
    if ($account['AccountTypeName'] != $group) {
        if ($group != '') {
            $rep->Line($rep->row + 6);
            $rep->row -= 6;
            $rep->TextCol(0, 2, tr('Total') . " " . $group);
            $rep->TextCol(2, 3, number_format2($totalper, $dec));
            $rep->TextCol(3, 4, number_format2($totalacc, $dec));
            $rep->TextCol(4, 5, number_format2(Achieve($totalper, $totalacc), $pdec));
            if ($graphics) {
                $pg->x[] = $group;
                $pg->y[] = abs($totalper);
                $pg->z[] = abs($totalacc);
            }
            $rep->row -= $rep->lineHeight + 4;
            if ($closeclass) {
                $rep->Line($rep->row + 6);
                $calculateper = $salesper + $classper;
                $calculateacc = $salesacc + $classacc;
                $rep->row -= 6;
                $rep->Font('bold');
                $rep->TextCol(0, 2, tr('Total') . " " . $classname);
                $rep->TextCol(2, 3, number_format2($classper, $dec));
                $rep->TextCol(3, 4, number_format2($classacc, $dec));
                $rep->TextCol(4, 5, number_format2(Achieve($classper, $classacc), $pdec));
                $rep->row -= $rep->lineHeight + 8;
                $rep->TextCol(0, 2, tr('Calculated Return'));
                $rep->TextCol(2, 3, number_format2($calculateper, $dec));
                $rep->TextCol(3, 4, number_format2($calculateacc, $dec));
                $rep->TextCol(4, 5, number_format2(Achieve($calculateper, $calculateacc), $pdec));
                if ($graphics) {
                    $pg->x[] = tr('Calculated Return');
                    $pg->y[] = abs($calculateper);
                    $pg->z[] = abs($calculateacc);
                }
                $rep->Font();
                $rep->NewLine();
            }
        }
    }
    $rep->Line($rep->row);
    if ($graphics) {
        global $decseps, $graph_skin;
        $pg->title = $rep->title;
        $pg->axis_x = tr("Group");
        $pg->axis_y = tr("Amount");
        $pg->graphic_1 = $headers[2];
        $pg->graphic_2 = $headers[3];
        $pg->type = $graphics;
        $pg->skin = $graph_skin;
        $pg->built_in = false;
        $pg->fontfile = $path_to_root . "reporting/fonts/Vera.ttf";
        $pg->latin_notation = $decseps[$_SESSION["wa_current_user"]->prefs->dec_sep()] != ".";
        $filename = $comp_path . '/' . user_company() . "/pdf_files/test.png";
        $pg->display($filename, true);
        $w = $pg->width / 1.5;
        $h = $pg->height / 1.5;
        $x = ($rep->pageWidth - $w) / 2;
        $rep->NewLine(2);
        if ($rep->row - $h < $rep->bottomMargin) {
            $rep->Header();
        }
        $rep->AddImage($filename, $x, $rep->row - $h, $w, $h);
    }
    $rep->End();
}
Esempio n. 6
0
function display_gl_info()
{
    global $path_to_root;
    $pg = new graph();
    $begin = begin_fiscalyear();
    $today = Today();
    $begin1 = date2sql($begin);
    $today1 = date2sql($today);
    $sql = "SELECT SUM(amount) AS total, c.class_name, c.ctype FROM\n\t\t\t" . TB_PREF . "gl_trans," . TB_PREF . "chart_master AS a, " . TB_PREF . "chart_types AS t, \n\t\t\t" . TB_PREF . "chart_class AS c WHERE\n\t\t\taccount = a.account_code AND a.account_type = t.id AND t.class_id = c.cid\n\t\t\tAND IF(c.ctype > 3, tran_date >= '{$begin1}', tran_date >= '0000-00-00') \n\t\t\tAND tran_date <= '{$today1}' GROUP BY c.cid ORDER BY c.cid";
    $result = db_query($sql, "Transactions could not be calculated");
    $title = _("Class Balances");
    br(2);
    display_heading($title);
    br();
    start_table(TABLESTYLE2, "width=30%");
    $i = 0;
    $total = 0;
    while ($myrow = db_fetch($result)) {
        if ($myrow['ctype'] > 3) {
            $total += $myrow['total'];
            $myrow['total'] = -$myrow['total'];
            $pg->x[$i] = $myrow['class_name'];
            $pg->y[$i] = abs($myrow['total']);
            $i++;
        }
        label_row($myrow['class_name'], number_format2($myrow['total'], user_price_dec()), "class='label' style='font-weight:bold;'", "style='font-weight:bold;' align=right");
    }
    $calculated = _("Calculated Return");
    label_row("&nbsp;", "");
    label_row($calculated, number_format2(-$total, user_price_dec()), "class='label' style='font-weight:bold;'", "style='font-weight:bold;' align=right");
    $pg->x[$i] = $calculated;
    $pg->y[$i] = -$total;
    end_table(2);
    $pg->title = $title;
    $pg->axis_x = _("Class");
    $pg->axis_y = _("Amount");
    $pg->graphic_1 = $today;
    $pg->type = 5;
    $pg->skin = 1;
    $pg->built_in = false;
    $filename = company_path() . "/pdf_files/" . uniqid("") . ".png";
    $pg->display($filename, true);
    start_table(TABLESTYLE);
    start_row();
    echo "<td>";
    echo "<img src='{$filename}' border='0' alt='{$title}'>";
    echo "</td>";
    end_row();
    end_table(1);
}
Esempio n. 7
0
function print_aged_supplier_analysis()
{
    global $path_to_root, $systypes_array;
    $to = $_POST['PARAM_0'];
    $fromsupp = $_POST['PARAM_1'];
    $currency = $_POST['PARAM_2'];
    $show_all = $_POST['PARAM_3'];
    $summaryOnly = $_POST['PARAM_4'];
    $no_zeros = $_POST['PARAM_5'];
    $graphics = $_POST['PARAM_6'];
    $comments = $_POST['PARAM_7'];
    $orientation = $_POST['PARAM_8'];
    $destination = $_POST['PARAM_9'];
    if ($destination) {
        include_once $path_to_root . "/reporting/includes/excel_report.inc";
    } else {
        include_once $path_to_root . "/reporting/includes/pdf_report.inc";
    }
    $orientation = $orientation ? 'L' : 'P';
    if ($graphics) {
        include_once $path_to_root . "/reporting/includes/class.graphic.inc";
        $pg = new graph();
    }
    if ($fromsupp == ALL_TEXT) {
        $from = _('All');
    } else {
        $from = get_supplier_name($fromsupp);
    }
    $dec = user_price_dec();
    if ($summaryOnly == 1) {
        $summary = _('Summary Only');
    } else {
        $summary = _('Detailed Report');
    }
    if ($currency == ALL_TEXT) {
        $convert = true;
        $currency = _('Balances in Home Currency');
    } else {
        $convert = false;
    }
    if ($no_zeros) {
        $nozeros = _('Yes');
    } else {
        $nozeros = _('No');
    }
    if ($show_all) {
        $show = _('Yes');
    } else {
        $show = _('No');
    }
    $PastDueDays1 = get_company_pref('past_due_days');
    $PastDueDays2 = 2 * $PastDueDays1;
    $nowdue = "1-" . $PastDueDays1 . " " . _('Days');
    $pastdue1 = $PastDueDays1 + 1 . "-" . $PastDueDays2 . " " . _('Days');
    $pastdue2 = _('Over') . " " . $PastDueDays2 . " " . _('Days');
    $cols = array(0, 100, 130, 190, 250, 320, 385, 450, 515);
    $headers = array(_('Supplier'), '', '', _('Current'), $nowdue, $pastdue1, $pastdue2, _('Total Balance'));
    $aligns = array('left', 'left', 'left', 'right', 'right', 'right', 'right', 'right');
    $params = array(0 => $comments, 1 => array('text' => _('End Date'), 'from' => $to, 'to' => ''), 2 => array('text' => _('Supplier'), 'from' => $from, 'to' => ''), 3 => array('text' => _('Currency'), 'from' => $currency, 'to' => ''), 4 => array('text' => _('Type'), 'from' => $summary, 'to' => ''), 5 => array('text' => _('Show Also Allocated'), 'from' => $show, 'to' => ''), 6 => array('text' => _('Suppress Zeros'), 'from' => $nozeros, 'to' => ''));
    if ($convert) {
        $headers[2] = _('currency');
    }
    $rep = new FrontReport(_('Aged Supplier Analysis'), "AgedSupplierAnalysis", user_pagesize(), 9, $orientation);
    if ($orientation == 'L') {
        recalculate_cols($cols);
    }
    $rep->Font();
    $rep->Info($params, $cols, $headers, $aligns);
    $rep->NewPage();
    $total = array();
    $total[0] = $total[1] = $total[2] = $total[3] = $total[4] = 0.0;
    $PastDueDays1 = get_company_pref('past_due_days');
    $PastDueDays2 = 2 * $PastDueDays1;
    $nowdue = "1-" . $PastDueDays1 . " " . _('Days');
    $pastdue1 = $PastDueDays1 + 1 . "-" . $PastDueDays2 . " " . _('Days');
    $pastdue2 = _('Over') . " " . $PastDueDays2 . " " . _('Days');
    $sql = "SELECT supplier_id, supp_name AS name, curr_code FROM " . TB_PREF . "suppliers";
    if ($fromsupp != ALL_TEXT) {
        $sql .= " WHERE supplier_id=" . db_escape($fromsupp);
    }
    $sql .= " ORDER BY supp_name";
    $result = db_query($sql, "The suppliers could not be retrieved");
    while ($myrow = db_fetch($result)) {
        if (!$convert && $currency != $myrow['curr_code']) {
            continue;
        }
        if ($convert) {
            $rate = get_exchange_rate_from_home_currency($myrow['curr_code'], $to);
        } else {
            $rate = 1.0;
        }
        $supprec = get_supplier_details($myrow['supplier_id'], $to, $show_all);
        if (!$supprec) {
            continue;
        }
        $supprec['Balance'] *= $rate;
        $supprec['Due'] *= $rate;
        $supprec['Overdue1'] *= $rate;
        $supprec['Overdue2'] *= $rate;
        $str = array($supprec["Balance"] - $supprec["Due"], $supprec["Due"] - $supprec["Overdue1"], $supprec["Overdue1"] - $supprec["Overdue2"], $supprec["Overdue2"], $supprec["Balance"]);
        if ($no_zeros && floatcmp(array_sum($str), 0) == 0) {
            continue;
        }
        $rep->fontSize += 2;
        $rep->TextCol(0, 2, $myrow['name']);
        if ($convert) {
            $rep->TextCol(2, 3, $myrow['curr_code']);
        }
        $rep->fontSize -= 2;
        $total[0] += $supprec["Balance"] - $supprec["Due"];
        $total[1] += $supprec["Due"] - $supprec["Overdue1"];
        $total[2] += $supprec["Overdue1"] - $supprec["Overdue2"];
        $total[3] += $supprec["Overdue2"];
        $total[4] += $supprec["Balance"];
        for ($i = 0; $i < count($str); $i++) {
            $rep->AmountCol($i + 3, $i + 4, $str[$i], $dec);
        }
        $rep->NewLine(1, 2);
        if (!$summaryOnly) {
            $res = get_invoices($myrow['supplier_id'], $to, $show_all);
            if (db_num_rows($res) == 0) {
                continue;
            }
            $rep->Line($rep->row + 4);
            while ($trans = db_fetch($res)) {
                $rep->NewLine(1, 2);
                $rep->TextCol(0, 1, $systypes_array[$trans['type']], -2);
                $rep->TextCol(1, 2, $trans['reference'], -2);
                $rep->TextCol(2, 3, sql2date($trans['tran_date']), -2);
                foreach ($trans as $i => $value) {
                    $trans[$i] *= $rate;
                }
                $str = array($trans["Balance"] - $trans["Due"], $trans["Due"] - $trans["Overdue1"], $trans["Overdue1"] - $trans["Overdue2"], $trans["Overdue2"], $trans["Balance"]);
                for ($i = 0; $i < count($str); $i++) {
                    $rep->AmountCol($i + 3, $i + 4, $str[$i], $dec);
                }
            }
            $rep->Line($rep->row - 8);
            $rep->NewLine(2);
        }
    }
    if ($summaryOnly) {
        $rep->Line($rep->row + 4);
        $rep->NewLine();
    }
    $rep->fontSize += 2;
    $rep->TextCol(0, 3, _('Grand Total'));
    $rep->fontSize -= 2;
    for ($i = 0; $i < count($total); $i++) {
        $rep->AmountCol($i + 3, $i + 4, $total[$i], $dec);
        if ($graphics && $i < count($total) - 1) {
            $pg->y[$i] = abs($total[$i]);
        }
    }
    $rep->Line($rep->row - 8);
    $rep->NewLine();
    if ($graphics) {
        global $decseps, $graph_skin;
        $pg->x = array(_('Current'), $nowdue, $pastdue1, $pastdue2);
        $pg->title = $rep->title;
        $pg->axis_x = _("Days");
        $pg->axis_y = _("Amount");
        $pg->graphic_1 = $to;
        $pg->type = $graphics;
        $pg->skin = $graph_skin;
        $pg->built_in = false;
        $pg->latin_notation = $decseps[$_SESSION["wa_current_user"]->prefs->dec_sep()] != ".";
        $filename = company_path() . "/pdf_files/" . uniqid("") . ".png";
        $pg->display($filename, true);
        $w = $pg->width / 1.5;
        $h = $pg->height / 1.5;
        $x = ($rep->pageWidth - $w) / 2;
        $rep->NewLine(2);
        if ($rep->row - $h < $rep->bottomMargin) {
            $rep->NewPage();
        }
        $rep->AddImage($filename, $x, $rep->row - $h, $w, $h);
    }
    $rep->End();
}
 function render($id, $title)
 {
     global $path_to_root;
     if (!isset($this->top)) {
         $this->top = 10;
     }
     $begin = begin_fiscalyear();
     $today = Today();
     $begin1 = date2sql($begin);
     $today1 = date2sql($today);
     $sql = "SELECT SUM((trans.unit_price * trans.quantity) * d.rate) AS total, s.stock_id, s.description,\n            SUM(trans.quantity) AS qty FROM\n            " . TB_PREF . "debtor_trans_details AS trans, " . TB_PREF . "stock_master AS s, " . TB_PREF . "debtor_trans AS d\n            WHERE trans.stock_id=s.stock_id AND trans.debtor_trans_type=d.type AND trans.debtor_trans_no=d.trans_no\n            AND (d.type = " . ST_SALESINVOICE . " OR d.type = " . ST_CUSTCREDIT . ") ";
     if ($this->item_type == 'manuf') {
         $sql .= "AND s.mb_flag='M' ";
     }
     if ($this->data_filter != '') {
         $sql .= ' AND ' . $this->data_filter;
     }
     $sql .= "AND d.tran_date >= '{$begin1}' AND d.tran_date <= '{$today1}' GROUP by s.stock_id ORDER BY total DESC, s.stock_id " . " LIMIT " . $this->top;
     $result = db_query($sql);
     if ($this->graph_type == 'Table') {
         if ($this->item_type == 'manuf') {
             $title = _("Top 10 Manufactured Items in fiscal year");
         } else {
             $title = _("Top 10 Sold Items in fiscal year");
         }
         display_heading($title);
         br();
         $th = array(_("Item"), _("Amount"), _("Quantity"));
         start_table(TABLESTYLE, "width=98%");
         table_header($th);
         $k = 0;
         //row colour counter
         while ($myrow = db_fetch($result)) {
             alt_table_row_color($k);
             $name = $myrow["description"];
             label_cell($name);
             amount_cell($myrow['total']);
             qty_cell($myrow['qty']);
             end_row();
         }
         end_table(1);
     } else {
         $pg = new graph();
         $i = 0;
         while ($myrow = db_fetch($result)) {
             $pg->x[$i] = $myrow["description"];
             $pg->y[$i] = $myrow['total'];
             $i++;
         }
         $pg->title = $title;
         $pg->axis_x = _("Item");
         $pg->axis_y = _("Amount");
         $pg->graphic_1 = $today;
         $pg->type = 2;
         $pg->skin = 1;
         $pg->built_in = false;
         $filename = company_path() . "/pdf_files/" . uniqid("") . ".png";
         $pg->display($filename, true);
         echo "<img src='{$filename}' border='0' alt='{$title}' style='max-width:100%'>";
     }
 }
Esempio n. 9
0
function print_aged_supplier_analysis()
{
    global $comp_path, $path_to_root;
    include_once $path_to_root . "reporting/includes/pdf_report.inc";
    $to = $_REQUEST['PARAM_0'];
    $fromsupp = $_REQUEST['PARAM_1'];
    $currency = $_REQUEST['PARAM_2'];
    $summaryOnly = $_REQUEST['PARAM_3'];
    $graphics = $_REQUEST['PARAM_4'];
    $comments = $_REQUEST['PARAM_5'];
    if ($graphics) {
        include_once $path_to_root . "reporting/includes/class.graphic.inc";
        $pg = new graph();
    }
    if ($fromsupp == reserved_words::get_all_numeric()) {
        $from = tr('All');
    } else {
        $from = get_supplier_name($fromsupp);
    }
    $dec = user_price_dec();
    if ($summaryOnly == 1) {
        $summary = tr('Summary Only');
    } else {
        $summary = tr('Detailed Report');
    }
    if ($currency == reserved_words::get_all()) {
        $convert = true;
        $currency = tr('Balances in Home Currency');
    } else {
        $convert = false;
    }
    $PastDueDays1 = get_company_pref('past_due_days');
    $PastDueDays2 = 2 * $PastDueDays1;
    $nowdue = "1-" . $PastDueDays1 . " " . tr('Days');
    $pastdue1 = $PastDueDays1 + 1 . "-" . $PastDueDays2 . " " . tr('Days');
    $pastdue2 = tr('Over') . " " . $PastDueDays2 . " " . tr('Days');
    $cols = array(0, 100, 130, 190, 250, 320, 385, 450, 515);
    $headers = array(tr('Supplier'), '', '', tr('Current'), $nowdue, $pastdue1, $pastdue2, tr('Total Balance'));
    $aligns = array('left', 'left', 'left', 'right', 'right', 'right', 'right', 'right');
    $params = array(0 => $comments, 1 => array('text' => tr('End Date'), 'from' => $to, 'to' => ''), 2 => array('text' => tr('Supplier'), 'from' => $from, 'to' => ''), 3 => array('text' => tr('Currency'), 'from' => $currency, 'to' => ''), 4 => array('text' => tr('Type'), 'from' => $summary, 'to' => ''));
    if ($convert) {
        $headers[2] = tr('currency');
    }
    $rep = new FrontReport(tr('Aged Supplier Analysis'), "AgedSupplierAnalysis.pdf", user_pagesize());
    $rep->Font();
    $rep->Info($params, $cols, $headers, $aligns);
    $rep->Header();
    $total = array();
    $total[0] = $total[1] = $total[2] = $total[3] = $total[4] = 0.0;
    $PastDueDays1 = get_company_pref('past_due_days');
    $PastDueDays2 = 2 * $PastDueDays1;
    $nowdue = "1-" . $PastDueDays1 . " " . tr('Days');
    $pastdue1 = $PastDueDays1 + 1 . "-" . $PastDueDays2 . " " . tr('Days');
    $pastdue2 = tr('Over') . " " . $PastDueDays2 . " " . tr('Days');
    $sql = "SELECT supplier_id, supp_name AS name, curr_code FROM suppliers ";
    if ($fromsupp != reserved_words::get_all_numeric()) {
        $sql .= "WHERE supplier_id={$fromsupp} ";
    }
    $sql .= "ORDER BY supp_name";
    $result = db_query($sql, "The suppliers could not be retrieved");
    while ($myrow = db_fetch($result)) {
        if (!$convert && $currency != $myrow['curr_code']) {
            continue;
        }
        $rep->fontSize += 2;
        $rep->TextCol(0, 3, $myrow['name']);
        if ($convert) {
            $rate = get_exchange_rate_from_home_currency($myrow['curr_code'], $to);
            $rep->TextCol(2, 4, $myrow['curr_code']);
        } else {
            $rate = 1.0;
        }
        $rep->fontSize -= 2;
        $supprec = get_supplier_details($myrow['supplier_id'], $to);
        foreach ($supprec as $i => $value) {
            $supprec[$i] *= $rate;
        }
        $total[0] += $supprec["Balance"] - $supprec["Due"];
        $total[1] += $supprec["Due"] - $supprec["Overdue1"];
        $total[2] += $supprec["Overdue1"] - $supprec["Overdue2"];
        $total[3] += $supprec["Overdue2"];
        $total[4] += $supprec["Balance"];
        $str = array(number_format2($supprec["Balance"] - $supprec["Due"], $dec), number_format2($supprec["Due"] - $supprec["Overdue1"], $dec), number_format2($supprec["Overdue1"] - $supprec["Overdue2"], $dec), number_format2($supprec["Overdue2"], $dec), number_format2($supprec["Balance"], $dec));
        for ($i = 0; $i < count($str); $i++) {
            $rep->TextCol($i + 3, $i + 4, $str[$i]);
        }
        $rep->NewLine(1, 2);
        if (!$summaryOnly) {
            $res = get_invoices($myrow['supplier_id'], $to);
            if (db_num_rows($res) == 0) {
                continue;
            }
            $rep->Line($rep->row + 4);
            while ($trans = db_fetch($res)) {
                $rep->NewLine(1, 2);
                $rep->TextCol(0, 1, $trans['type_name'], -2);
                $rep->TextCol(1, 2, $trans['reference'], -2);
                $rep->TextCol(2, 3, sql2date($trans['tran_date']), -2);
                foreach ($trans as $i => $value) {
                    $trans[$i] *= $rate;
                }
                $str = array(number_format2($trans["Balance"] - $trans["Due"], $dec), number_format2($trans["Due"] - $trans["Overdue1"], $dec), number_format2($trans["Overdue1"] - $trans["Overdue2"], $dec), number_format2($trans["Overdue2"], $dec), number_format2($trans["Balance"], $dec));
                for ($i = 0; $i < count($str); $i++) {
                    $rep->TextCol($i + 3, $i + 4, $str[$i]);
                }
            }
            $rep->Line($rep->row - 8);
            $rep->NewLine(2);
        }
    }
    if ($summaryOnly) {
        $rep->Line($rep->row + 4);
        $rep->NewLine();
    }
    $rep->fontSize += 2;
    $rep->TextCol(0, 3, tr('Grand Total'));
    $rep->fontSize -= 2;
    for ($i = 0; $i < count($total); $i++) {
        $rep->TextCol($i + 3, $i + 4, number_format2($total[$i], $dec));
        if ($graphics && $i < count($total) - 1) {
            $pg->y[$i] = abs($total[$i]);
        }
    }
    $rep->Line($rep->row - 8);
    if ($graphics) {
        global $decseps, $graph_skin;
        $pg->x = array(tr('Current'), $nowdue, $pastdue1, $pastdue2);
        $pg->title = $rep->title;
        $pg->axis_x = tr("Days");
        $pg->axis_y = tr("Amount");
        $pg->graphic_1 = $to;
        $pg->type = $graphics;
        $pg->skin = $graph_skin;
        $pg->built_in = false;
        $pg->fontfile = $path_to_root . "reporting/fonts/Vera.ttf";
        $pg->latin_notation = $decseps[$_SESSION["wa_current_user"]->prefs->dec_sep()] != ".";
        $filename = $comp_path . '/' . user_company() . "/pdf_files/test.png";
        $pg->display($filename, true);
        $w = $pg->width / 1.5;
        $h = $pg->height / 1.5;
        $x = ($rep->pageWidth - $w) / 2;
        $rep->NewLine(2);
        if ($rep->row - $h < $rep->bottomMargin) {
            $rep->Header();
        }
        $rep->AddImage($filename, $x, $rep->row - $h, $w, $h);
    }
    $rep->End();
}
Esempio n. 10
0
function print_balance_sheet()
{
    global $comp_path, $path_to_root;
    include_once $path_to_root . "reporting/includes/pdf_report.inc";
    $dim = get_company_pref('use_dimension');
    $dimension = $dimension2 = 0;
    $from = $_REQUEST['PARAM_0'];
    $to = $_REQUEST['PARAM_1'];
    if ($dim == 2) {
        $dimension = $_REQUEST['PARAM_2'];
        $dimension2 = $_REQUEST['PARAM_3'];
        $graphics = $_REQUEST['PARAM_4'];
        $comments = $_REQUEST['PARAM_5'];
    } else {
        if ($dim == 1) {
            $dimension = $_REQUEST['PARAM_2'];
            $graphics = $_REQUEST['PARAM_3'];
            $comments = $_REQUEST['PARAM_4'];
        } else {
            $graphics = $_REQUEST['PARAM_2'];
            $comments = $_REQUEST['PARAM_3'];
        }
    }
    if ($graphics) {
        include_once $path_to_root . "reporting/includes/class.graphic.inc";
        $pg = new graph();
    }
    $dec = 0;
    $cols = array(0, 50, 200, 350, 425, 500);
    //------------0--1---2----3----4----5--
    $headers = array(tr('Account'), tr('Account Name'), tr('Open Balance'), tr('Period'), tr('Close Balance'));
    $aligns = array('left', 'left', 'right', 'right', 'right');
    if ($dim == 2) {
        $params = array(0 => $comments, 1 => array('text' => tr('Period'), 'from' => $from, 'to' => $to), 2 => array('text' => tr('Dimension') . " 1", 'from' => get_dimension_string($dimension), 'to' => ''), 3 => array('text' => tr('Dimension') . " 2", 'from' => get_dimension_string($dimension2), 'to' => ''));
    } else {
        if ($dim == 1) {
            $params = array(0 => $comments, 1 => array('text' => tr('Period'), 'from' => $from, 'to' => $to), 2 => array('text' => tr('Dimension'), 'from' => get_dimension_string($dimension), 'to' => ''));
        } else {
            $params = array(0 => $comments, 1 => array('text' => tr('Period'), 'from' => $from, 'to' => $to));
        }
    }
    $rep = new FrontReport(tr('Balance Sheet'), "BalanceSheet.pdf", user_pagesize());
    $rep->Font();
    $rep->Info($params, $cols, $headers, $aligns);
    $rep->Header();
    $classname = '';
    $group = '';
    $totalopen = 0.0;
    $totalperiod = 0.0;
    $totalclose = 0.0;
    $classopen = 0.0;
    $classperiod = 0.0;
    $classclose = 0.0;
    $assetsopen = 0.0;
    $assetsperiod = 0.0;
    $assetsclose = 0.0;
    $closeclass = false;
    $accounts = get_gl_accounts_all(1);
    while ($account = db_fetch($accounts)) {
        $prev_balance = get_gl_balance_from_to("", $from, $account["account_code"], $dimension, $dimension2);
        $curr_balance = get_gl_trans_from_to($from, $to, $account["account_code"], $dimension, $dimension2);
        if (!$prev_balance && !$curr_balance) {
            continue;
        }
        if ($account['AccountClassName'] != $classname) {
            if ($classname != '') {
                $closeclass = true;
            }
        }
        if ($account['AccountTypeName'] != $group) {
            if ($group != '') {
                $rep->Line($rep->row + 6);
                $rep->row -= 6;
                $rep->TextCol(0, 2, tr('Total') . " " . $group);
                $rep->TextCol(2, 3, number_format2($totalopen, $dec));
                $rep->TextCol(3, 4, number_format2($totalperiod, $dec));
                $rep->TextCol(4, 5, number_format2($totalclose, $dec));
                if ($graphics) {
                    $pg->x[] = $group;
                    $pg->y[] = abs($totalclose);
                }
                $totalopen = $totalperiod = $totalclose = 0.0;
                $rep->row -= $rep->lineHeight + 4;
                if ($closeclass) {
                    $rep->Line($rep->row + 6);
                    $rep->row -= 6;
                    $rep->Font('bold');
                    $rep->TextCol(0, 2, tr('Total') . " " . $classname);
                    $rep->TextCol(2, 3, number_format2($classopen, $dec));
                    $rep->TextCol(3, 4, number_format2($classperiod, $dec));
                    $rep->TextCol(4, 5, number_format2($classclose, $dec));
                    $rep->Font();
                    $assetsopen += $classopen;
                    $assetsperiod += $classperiod;
                    $assetsclose += $classclose;
                    $classopen = $classperiod = $classclose = 0.0;
                    $rep->NewLine(3);
                    $closeclass = false;
                }
            }
            if ($account['AccountClassName'] != $classname) {
                $rep->Font('bold');
                $rep->TextCol(0, 5, $account['AccountClassName']);
                $rep->Font();
                $rep->row -= $rep->lineHeight + 4;
            }
            $group = $account['AccountTypeName'];
            $rep->TextCol(0, 5, $account['AccountTypeName']);
            $rep->Line($rep->row - 4);
            $rep->row -= $rep->lineHeight + 4;
        }
        $classname = $account['AccountClassName'];
        $totalopen += $prev_balance;
        $totalperiod += $curr_balance;
        $totalclose = $totalopen + $totalperiod;
        $classopen += $prev_balance;
        $classperiod += $curr_balance;
        $classclose = $classopen + $classperiod;
        $rep->TextCol(0, 1, $account['account_code']);
        $rep->TextCol(1, 2, $account['account_name']);
        $rep->TextCol(2, 3, number_format2($prev_balance, $dec));
        $rep->TextCol(3, 4, number_format2($curr_balance, $dec));
        $rep->TextCol(4, 5, number_format2($curr_balance + $prev_balance, $dec));
        $rep->NewLine();
        if ($rep->row < $rep->bottomMargin + 3 * $rep->lineHeight) {
            $rep->Line($rep->row - 2);
            $rep->Header();
        }
    }
    if ($account['AccountClassName'] != $classname) {
        if ($classname != '') {
            $closeclass = true;
        }
    }
    if ($account['AccountTypeName'] != $group) {
        if ($group != '') {
            $rep->Line($rep->row + 6);
            $rep->row -= 6;
            $rep->TextCol(0, 2, tr('Total') . " " . $group);
            $rep->TextCol(2, 3, number_format2($totalopen, $dec));
            $rep->TextCol(3, 4, number_format2($totalperiod, $dec));
            $rep->TextCol(4, 5, number_format2($totalclose, $dec));
            if ($graphics) {
                $pg->x[] = $group;
                $pg->y[] = abs($totalclose);
            }
            $rep->row -= $rep->lineHeight + 4;
            if ($closeclass) {
                $rep->Line($rep->row + 6);
                $calculateopen = -$assetsopen - $classopen;
                $calculateperiod = -$assetsperiod - $classperiod;
                $calculateclose = -$assetsclose - $classclose;
                $rep->row -= 6;
                $rep->TextCol(0, 2, tr('Calculated Return'));
                $rep->TextCol(2, 3, number_format2($calculateopen, $dec));
                $rep->TextCol(3, 4, number_format2($calculateperiod, $dec));
                $rep->TextCol(4, 5, number_format2($calculateclose, $dec));
                if ($graphics) {
                    $pg->x[] = tr('Calculated Return');
                    $pg->y[] = abs($calculateclose);
                }
                $rep->row -= $rep->lineHeight + 4;
                $rep->Font('bold');
                $rep->TextCol(0, 2, tr('Total') . " " . $classname);
                $rep->TextCol(2, 3, number_format2(-$assetsopen, $dec));
                $rep->TextCol(3, 4, number_format2(-$assetsperiod, $dec));
                $rep->TextCol(4, 5, number_format2(-$assetsclose, $dec));
                $rep->Font();
                $rep->NewLine();
            }
        }
    }
    $rep->Line($rep->row);
    if ($graphics) {
        global $decseps, $graph_skin;
        $pg->title = $rep->title;
        $pg->axis_x = tr("Group");
        $pg->axis_y = tr("Amount");
        $pg->graphic_1 = $to;
        $pg->type = $graphics;
        $pg->skin = $graph_skin;
        $pg->built_in = false;
        $pg->fontfile = $path_to_root . "reporting/fonts/Vera.ttf";
        $pg->latin_notation = $decseps[$_SESSION["wa_current_user"]->prefs->dec_sep()] != ".";
        $filename = $comp_path . '/' . user_company() . "/pdf_files/test.png";
        $pg->display($filename, true);
        $w = $pg->width / 1.5;
        $h = $pg->height / 1.5;
        $x = ($rep->pageWidth - $w) / 2;
        $rep->NewLine(2);
        if ($rep->row - $h < $rep->bottomMargin) {
            $rep->Header();
        }
        $rep->AddImage($filename, $x, $rep->row - $h, $w, $h);
    }
    $rep->End();
}