Example #1
0
function display_trial_balance()
{
    global $table_style, $path_to_root;
    start_table($table_style);
    $tableheader = "<tr>\n        <td rowspan=2 class='tableheader'>" . tr("Account") . "</td>\n        <td rowspan=2 class='tableheader'>" . tr("Account Name") . "</td>\n\t\t<td colspan=2 class='tableheader'>" . tr("Brought Forward") . "</td>\n\t\t<td colspan=2 class='tableheader'>" . tr("This Period") . "</td>\n\t\t<td colspan=2 class='tableheader'>" . tr("Balance") . "</td>\n\t\t</tr><tr>\n\t\t<td class='tableheader'>" . tr("Debit") . "</td>\n        <td class='tableheader'>" . tr("Credit") . "</td>\n\t\t<td class='tableheader'>" . tr("Debit") . "</td>\n\t\t<td class='tableheader'>" . tr("Credit") . "</td>\n        <td class='tableheader'>" . tr("Debit") . "</td>\n        <td class='tableheader'>" . tr("Credit") . "</td>\n        </tr>";
    echo $tableheader;
    $k = 0;
    $accounts = get_gl_accounts();
    while ($account = db_fetch($accounts)) {
        if (is_account_balancesheet($account["account_code"])) {
            $begin = null;
        } else {
            $begin = begin_fiscalyear();
            if ($_POST['TransFromDate'] < $begin) {
                $begin = $_POST['TransFromDate'];
            }
            $begin = add_days($begin, -1);
        }
        $prev_balance = get_balance($account["account_code"], $begin, $_POST['TransFromDate'], false, false);
        $curr_balance = get_balance($account["account_code"], $_POST['TransFromDate'], $_POST['TransToDate']);
        if (check_value("NoZero") && !$prev_balance && !$curr_balance) {
            continue;
        }
        alt_table_row_color($k);
        $url = "<a href='{$path_to_root}/gl/inquiry/gl_account_inquiry.php?" . SID . "TransFromDate=" . $_POST["TransFromDate"] . "&TransToDate=" . $_POST["TransToDate"] . "&account=" . $account["account_code"] . "'>" . $account["account_code"] . "</a>";
        label_cell($url);
        label_cell($account["account_name"]);
        display_debit_or_credit_cells($prev_balance);
        display_debit_or_credit_cells($curr_balance);
        display_debit_or_credit_cells($prev_balance + $curr_balance);
        end_row();
    }
    end_table(1);
}
function getPeriods($yr, $mo, $id, $dimension, $dimension2, $balance = false)
{
    $begin = date2sql(begin_fiscalyear());
    $date13 = date('Y-m-d', mktime(0, 0, 0, $mo + 12, 1, $yr));
    $date12 = date('Y-m-d', mktime(0, 0, 0, $mo + 11, 1, $yr));
    $date11 = date('Y-m-d', mktime(0, 0, 0, $mo + 10, 1, $yr));
    $date10 = date('Y-m-d', mktime(0, 0, 0, $mo + 9, 1, $yr));
    $date09 = date('Y-m-d', mktime(0, 0, 0, $mo + 8, 1, $yr));
    $date08 = date('Y-m-d', mktime(0, 0, 0, $mo + 7, 1, $yr));
    $date07 = date('Y-m-d', mktime(0, 0, 0, $mo + 6, 1, $yr));
    $date06 = date('Y-m-d', mktime(0, 0, 0, $mo + 5, 1, $yr));
    $date05 = date('Y-m-d', mktime(0, 0, 0, $mo + 4, 1, $yr));
    $date04 = date('Y-m-d', mktime(0, 0, 0, $mo + 3, 1, $yr));
    $date03 = date('Y-m-d', mktime(0, 0, 0, $mo + 2, 1, $yr));
    $date02 = date('Y-m-d', mktime(0, 0, 0, $mo + 1, 1, $yr));
    $date01 = date('Y-m-d', mktime(0, 0, 0, $mo, 1, $yr));
    if (!$balance) {
        $sql = "SELECT SUM(CASE WHEN trans_date >= '{$date01}' AND trans_date < '{$date02}' THEN amount ELSE 0 END) AS per01,\n\t\t   \t\tSUM(CASE WHEN trans_date >= '{$date02}' AND trans_date < '{$date03}' THEN amount ELSE 0 END) AS per02,\n\t\t   \t\tSUM(CASE WHEN trans_date >= '{$date03}' AND trans_date < '{$date04}' THEN amount ELSE 0 END) AS per03,\n\t\t   \t\tSUM(CASE WHEN trans_date >= '{$date04}' AND trans_date < '{$date05}' THEN amount ELSE 0 END) AS per04,\n\t\t   \t\tSUM(CASE WHEN trans_date >= '{$date05}' AND trans_date < '{$date06}' THEN amount ELSE 0 END) AS per05,\n\t\t   \t\tSUM(CASE WHEN trans_date >= '{$date06}' AND trans_date < '{$date07}' THEN amount ELSE 0 END) AS per06,\n\t\t   \t\tSUM(CASE WHEN trans_date >= '{$date07}' AND trans_date < '{$date08}' THEN amount ELSE 0 END) AS per07,\n\t\t   \t\tSUM(CASE WHEN trans_date >= '{$date08}' AND trans_date < '{$date09}' THEN amount ELSE 0 END) AS per08,\n\t\t   \t\tSUM(CASE WHEN trans_date >= '{$date09}' AND trans_date < '{$date10}' THEN amount ELSE 0 END) AS per09,\n\t\t   \t\tSUM(CASE WHEN trans_date >= '{$date10}' AND trans_date < '{$date11}' THEN amount ELSE 0 END) AS per10,\n\t\t   \t\tSUM(CASE WHEN trans_date >= '{$date11}' AND trans_date < '{$date12}' THEN amount ELSE 0 END) AS per11,\n\t\t   \t\tSUM(CASE WHEN trans_date >= '{$date12}' AND trans_date < '{$date13}' THEN amount ELSE 0 END) AS per12,\n\t\t   \t\tSUM(CASE WHEN trans_date >= '{$begin}' AND trans_date < '{$date13}' THEN amount ELSE 0 END) AS ytd,\n\t\t   \t\tSUM(CASE WHEN trans_date >= '{$date01}' AND trans_date < '{$date13}' THEN amount ELSE 0 END) AS mon12\n    \t\t\tFROM " . TB_PREF . "bank_trans\n\t\t\t\tWHERE bank_act='{$id}'";
    } else {
        $sql = "SELECT SUM(CASE WHEN trans_date < '{$date01}' THEN amount ELSE 0 END) AS per01,\n\t\t   \t\tSUM(CASE WHEN trans_date < '{$date02}' THEN amount ELSE 0 END) AS per02,\n\t\t   \t\tSUM(CASE WHEN trans_date < '{$date03}' THEN amount ELSE 0 END) AS per03,\n\t\t   \t\tSUM(CASE WHEN trans_date < '{$date04}' THEN amount ELSE 0 END) AS per04,\n\t\t   \t\tSUM(CASE WHEN trans_date < '{$date05}' THEN amount ELSE 0 END) AS per05,\n\t\t   \t\tSUM(CASE WHEN trans_date < '{$date06}' THEN amount ELSE 0 END) AS per06,\n\t\t   \t\tSUM(CASE WHEN trans_date < '{$date07}' THEN amount ELSE 0 END) AS per07,\n\t\t   \t\tSUM(CASE WHEN trans_date < '{$date08}' THEN amount ELSE 0 END) AS per08,\n\t\t   \t\tSUM(CASE WHEN trans_date < '{$date09}' THEN amount ELSE 0 END) AS per09,\n\t\t   \t\tSUM(CASE WHEN trans_date < '{$date10}' THEN amount ELSE 0 END) AS per10,\n\t\t   \t\tSUM(CASE WHEN trans_date < '{$date11}' THEN amount ELSE 0 END) AS per11,\n\t\t   \t\tSUM(CASE WHEN trans_date < '{$date12}' THEN amount ELSE 0 END) AS per12,\n\t\t   \t\tSUM(CASE WHEN trans_date < '{$begin}' THEN amount ELSE 0 END) AS ytd,\n\t\t   \t\tSUM(CASE WHEN trans_date < '{$date01}' THEN amount ELSE 0 END) AS mon12\n    \t\t\tFROM " . TB_PREF . "bank_trans\n\t\t\t\tWHERE bank_act='{$id}'";
    }
    if ($dimension != 0) {
        $sql .= " AND dimension_id = " . ($dimension < 0 ? 0 : db_escape($dimension));
    }
    if ($dimension2 != 0) {
        $sql .= " AND dimension2_id = " . ($dimension2 < 0 ? 0 : db_escape($dimension2));
    }
    $result = db_query($sql, "Transactions for bank account {$id} could not be calculated");
    return db_fetch($result);
}
Example #3
0
function print_Chart_of_Accounts()
{
    global $path_to_root;
    include_once $path_to_root . "reporting/includes/pdf_report.inc";
    $showbalance = $_REQUEST['PARAM_0'];
    $comments = $_REQUEST['PARAM_1'];
    $dec = 0;
    $cols = array(0, 50, 300, 425, 500);
    $headers = array(tr('Account'), tr('Account Name'), tr('Account Code'), tr('Balance'));
    $aligns = array('left', 'left', 'left', 'right');
    $params = array(0 => $comments);
    $rep = new FrontReport(tr('Chart of Accounts'), "ChartOfAccounts.pdf", user_pagesize());
    $rep->Font();
    $rep->Info($params, $cols, $headers, $aligns);
    $rep->Header();
    $classname = '';
    $group = '';
    $accounts = get_gl_accounts_all();
    while ($account = db_fetch($accounts)) {
        if ($showbalance == 1) {
            $begin = begin_fiscalyear();
            if (is_account_balancesheet($account["account_code"])) {
                $begin = "";
            }
            $balance = get_gl_trans_from_to($begin, ToDay(), $account["account_code"], 0);
        }
        if ($account['AccountTypeName'] != $group) {
            if ($classname != '') {
                $rep->row -= 4;
            }
            if ($account['AccountClassName'] != $classname) {
                $rep->Font('bold');
                $rep->TextCol(0, 4, $account['AccountClassName']);
                $rep->Font();
                $rep->row -= $rep->lineHeight + 4;
            }
            $group = $account['AccountTypeName'];
            $rep->TextCol(0, 4, $account['AccountTypeName']);
            //$rep->Line($rep->row - 4);
            $rep->row -= $rep->lineHeight + 4;
        }
        $classname = $account['AccountClassName'];
        $rep->TextCol(0, 1, $account['account_code']);
        $rep->TextCol(1, 2, $account['account_name']);
        $rep->TextCol(2, 3, $account['account_code2']);
        if ($showbalance == 1) {
            $rep->TextCol(3, 4, number_format2($balance, $dec));
        }
        $rep->NewLine();
        if ($rep->row < $rep->bottomMargin + 3 * $rep->lineHeight) {
            $rep->Line($rep->row - 2);
            $rep->Header();
        }
    }
    $rep->Line($rep->row);
    $rep->End();
}
 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%'>";
     }
 }
Example #5
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%'>";
     }
 }
Example #6
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%'>";
     }
 }
Example #7
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%'>";
     }
 }
Example #8
0
function display_type($type, $typename, &$dec, &$rep, $showbalance, $level)
{
    $printtitle = 0;
    //Flag for printing type name
    //Get Accounts directly under this group/type
    $result = get_gl_accounts(null, null, $type);
    while ($account = db_fetch($result)) {
        //Print Type Title if it has atleast one non-zero account
        if (!$printtitle) {
            $prefix = '';
            for ($sp = 1; $sp <= $level; $sp++) {
                $prefix .= '         ';
            }
            $printtitle = 1;
            $rep->row -= 4;
            $rep->TextCol(0, 1, $type);
            $rep->TextCol(1, 4, $prefix . $typename);
            $rep->row -= 4;
            $rep->Line($rep->row);
            $rep->NewLine();
        }
        if ($showbalance == 1) {
            $begin = begin_fiscalyear();
            if (is_account_balancesheet($account["account_code"])) {
                $begin = "";
            }
            $balance = get_gl_trans_from_to($begin, ToDay(), $account["account_code"], 0);
        }
        $rep->TextCol(0, 1, $account['account_code']);
        $rep->TextCol(1, 2, $prefix . $account['account_name']);
        $rep->TextCol(2, 3, $account['account_code2']);
        if ($showbalance == 1) {
            $rep->AmountCol(3, 4, $balance, $dec);
        }
        $rep->NewLine();
    }
    //Get Account groups/types under this group/type
    $result = get_account_types(false, false, $type);
    while ($accounttype = db_fetch($result)) {
        //Print Type Title if has sub types and not previously printed
        if (!$printtitle) {
            $printtitle = 1;
            $rep->row -= 4;
            $rep->TextCol(0, 1, $type);
            $rep->TextCol(1, 4, $typename);
            $rep->row -= 4;
            $rep->Line($rep->row);
            $rep->NewLine();
        }
        $nextlevel = $level + 1;
        display_type($accounttype["id"], $accounttype["name"] . ' (' . $typename . ')', $dec, $rep, $showbalance, $nextlevel);
    }
}
Example #9
0
function getYTD($dim)
{
    $date = Today();
    $date = begin_fiscalyear($date);
    date2sql($date);
    $sql = "SELECT SUM(amount) AS Balance\n\t\tFROM\n\t\t\t" . TB_PREF . "gl_trans\n\t\tWHERE (dimension_id = '{$dim}' OR dimension2_id = '{$dim}')\n\t\tAND tran_date >= '{$date}'";
    $TransResult = db_query($sql, "No transactions were returned");
    if (db_num_rows($TransResult) == 1) {
        $DemandRow = db_fetch_row($TransResult);
        $balance = $DemandRow[0];
    } else {
        $balance = 0.0;
    }
    return $balance;
}
Example #10
0
function display_balance_sheet()
{
    global $path_to_root;
    $from = begin_fiscalyear();
    $to = $_POST['TransToDate'];
    if (!isset($_POST['Dimension'])) {
        $_POST['Dimension'] = 0;
    }
    if (!isset($_POST['Dimension2'])) {
        $_POST['Dimension2'] = 0;
    }
    $dimension = $_POST['Dimension'];
    $dimension2 = $_POST['Dimension2'];
    $lconvert = $econvert = 1;
    if (isset($_POST["AccGrp"]) && strlen($_POST['AccGrp']) > 0) {
        $drilldown = 1;
    } else {
        $drilldown = 0;
    }
    // Root level
    div_start('balance_tbl');
    start_table(TABLESTYLE, "width='30%'");
    if (!$drilldown) {
        $equityclose = 0.0;
        $lclose = 0.0;
        $calculateclose = 0.0;
        $parent = -1;
        //Get classes for BS
        $classresult = get_account_classes(false, 1);
        while ($class = db_fetch($classresult)) {
            $classclose = 0.0;
            $convert = get_class_type_convert($class["ctype"]);
            $ctype = $class["ctype"];
            $classname = $class["class_name"];
            //Print Class Name
            table_section_title($class["class_name"]);
            //Get Account groups/types under this group/type
            $typeresult = get_account_types(false, $class['cid'], -1);
            while ($accounttype = db_fetch($typeresult)) {
                $TypeTotal = display_type($accounttype["id"], $accounttype["name"], $from, $to, $convert, $dimension, $dimension2, $drilldown, $path_to_root);
                //Print Summary
                if ($TypeTotal != 0) {
                    $url = "<a href='{$path_to_root}/gl/inquiry/balance_sheet.php?TransFromDate=" . $from . "&TransToDate=" . $to . "&Dimension=" . $dimension . "&Dimension2=" . $dimension2 . "&AccGrp=" . $accounttype['id'] . "'>" . $accounttype['id'] . " " . $accounttype['name'] . "</a>";
                    alt_table_row_color($k);
                    label_cell($url);
                    amount_cell($TypeTotal * $convert);
                    end_row();
                }
                $classclose += $TypeTotal;
            }
            //Print Class Summary
            start_row("class='inquirybg' style='font-weight:bold'");
            label_cell(_('Total') . " " . $class["class_name"]);
            amount_cell($classclose * $convert);
            end_row();
            if ($ctype == CL_EQUITY) {
                $equityclose += $classclose;
                $econvert = $convert;
            }
            if ($ctype == CL_LIABILITIES) {
                $lclose += $classclose;
                $lconvert = $convert;
            }
            $calculateclose += $classclose;
        }
        if ($lconvert == 1) {
            $calculateclose *= -1;
        }
        //Final Report Summary
        $url = "<a href='{$path_to_root}/gl/inquiry/profit_loss.php?TransFromDate=" . $from . "&TransToDate=" . $to . "&Dimension=" . $dimension . "&Dimension2=" . $dimension2 . "&Compare=0'>" . _('Calculated Return') . "</a>";
        start_row("class='inquirybg' style='font-weight:bold'");
        label_cell($url);
        amount_cell($calculateclose);
        end_row();
        start_row("class='inquirybg' style='font-weight:bold'");
        label_cell(_('Total') . " " . _('Liabilities') . _(' and ') . _('Equities'));
        amount_cell($lclose * $lconvert + $equityclose * $econvert + $calculateclose);
        end_row();
    } else {
        //Level Pointer : Global variable defined in order to control display of root
        global $levelptr;
        $levelptr = 0;
        $accounttype = get_account_type($_POST["AccGrp"]);
        $classid = $accounttype["class_id"];
        $class = get_account_class($classid);
        $convert = get_class_type_convert($class["ctype"]);
        //Print Class Name
        table_section_title($_POST["AccGrp"] . " " . get_account_type_name($_POST["AccGrp"]));
        $classclose = display_type($accounttype["id"], $accounttype["name"], $from, $to, $convert, $dimension, $dimension2, $drilldown, $path_to_root);
    }
    end_table(1);
    // outer table
    div_end();
}
Example #11
0
function print_trial_balance()
{
    global $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'];
    $zero = $_REQUEST['PARAM_2'];
    if ($dim == 2) {
        $dimension = $_REQUEST['PARAM_3'];
        $dimension2 = $_REQUEST['PARAM_4'];
        $comments = $_REQUEST['PARAM_5'];
    } else {
        if ($dim == 1) {
            $dimension = $_REQUEST['PARAM_3'];
            $comments = $_REQUEST['PARAM_4'];
        } else {
            $comments = $_REQUEST['PARAM_3'];
        }
    }
    $dec = user_price_dec();
    $cols2 = array(0, 50, 230, 330, 430, 530);
    //-------------0--1---2----3----4----5--
    $headers2 = array('', '', tr('Brought Forward'), tr('This Period'), tr('Balance'));
    $aligns2 = array('left', 'left', 'left', 'left', 'left');
    $cols = array(0, 50, 200, 250, 300, 350, 400, 450, 500, 550);
    //------------0--1---2----3----4----5----6----7----8----9--
    $headers = array(tr('Account'), tr('Account Name'), tr('Debit'), tr('Credit'), tr('Debit'), tr('Credit'), tr('Debit'), tr('Credit'));
    $aligns = array('left', 'left', 'right', 'right', 'right', '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('Trial Balance'), "TrialBalance.pdf", user_pagesize());
    $rep->Font();
    $rep->Info($params, $cols, $headers, $aligns, $cols2, $headers2, $aligns2);
    $rep->Header();
    $accounts = get_gl_accounts();
    while ($account = db_fetch($accounts)) {
        if (is_account_balancesheet($account["account_code"])) {
            $begin = "";
        } else {
            if ($from < $begin) {
                $begin = add_days($from, -1);
            } else {
                $begin = add_days(begin_fiscalyear(), -1);
            }
        }
        $prev_balance = get_gl_balance_from_to($begin, $from, $account["account_code"], $dimension, $dimension2);
        $curr_balance = get_gl_trans_from_to($from, $to, $account["account_code"], $dimension, $dimension2);
        if ($zero == 0 && !$prev_balance && !$curr_balance) {
            continue;
        }
        $rep->TextCol(0, 1, $account['account_code']);
        $rep->TextCol(1, 2, $account['account_name']);
        if ($prev_balance > 0.0) {
            $rep->TextCol(2, 3, number_format2(abs($prev_balance), $dec));
        } else {
            $rep->TextCol(3, 4, number_format2(abs($prev_balance), $dec));
        }
        if ($curr_balance > 0.0) {
            $rep->TextCol(4, 5, number_format2(abs($curr_balance), $dec));
        } else {
            $rep->TextCol(5, 6, number_format2(abs($curr_balance), $dec));
        }
        if ($curr_balance + $prev_balance > 0.0) {
            $rep->TextCol(6, 7, number_format2(abs($curr_balance + $prev_balance), $dec));
        } else {
            $rep->TextCol(7, 8, number_format2(abs($curr_balance + $prev_balance), $dec));
        }
        $rep->NewLine();
        if ($rep->row < $rep->bottomMargin + $rep->lineHeight) {
            $rep->Line($rep->row - 2);
            $rep->Header();
        }
    }
    $rep->Line($rep->row);
    $rep->End();
}
Example #12
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);
}
 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%'>";
     }
 }
Example #14
0
function show_results()
{
    global $path_to_root, $table_style;
    if (!isset($_POST["account"]) || $_POST["account"] == "") {
        return;
    }
    $act_name = get_gl_account_name($_POST["account"]);
    $dim = get_company_pref('use_dimension');
    /*Now get the transactions  */
    if (!isset($_POST['Dimension'])) {
        $_POST['Dimension'] = 0;
    }
    if (!isset($_POST['Dimension2'])) {
        $_POST['Dimension2'] = 0;
    }
    $result = get_gl_transactions($_POST['TransFromDate'], $_POST['TransToDate'], -1, $_POST["account"], $_POST['Dimension'], $_POST['Dimension2']);
    $colspan = $dim == 2 ? "6" : ($dim == 1 ? "5" : "4");
    //echo "\nDimension =". $_POST['Dimension'];
    display_heading($_POST["account"] . "&nbsp;&nbsp;&nbsp;" . $act_name);
    start_table($table_style);
    if ($dim == 2) {
        $th = array(tr("Type"), tr("#"), tr("Date"), tr("Dimension") . " 1", tr("Dimension") . " 2", tr("Person/Item"), tr("Debit"), tr("Credit"), tr("Balance"), tr("Memo"));
    } else {
        if ($dim == 1) {
            $th = array(tr("Type"), tr("#"), tr("Date"), tr("Dimension"), tr("Person/Item"), tr("Debit"), tr("Credit"), tr("Balance"), tr("Memo"));
        } else {
            $th = array(tr("Type"), tr("#"), tr("Date"), tr("Person/Item"), tr("Debit"), tr("Credit"), tr("Balance"), tr("Memo"));
        }
    }
    table_header($th);
    if (is_account_balancesheet($_POST["account"])) {
        $begin = "";
    } else {
        $begin = begin_fiscalyear();
        if ($_POST['TransFromDate'] < $begin) {
            $begin = $_POST['TransFromDate'];
        }
        $begin = add_days($begin, -1);
    }
    $bfw = get_gl_balance_from_to($begin, $_POST['TransFromDate'], $_POST["account"], $_POST['Dimension'], $_POST['Dimension2']);
    start_row("class='inquirybg'");
    label_cell("<b>" . tr("Opening Balance") . " - " . $_POST['TransFromDate'] . "</b>", "colspan={$colspan}");
    display_debit_or_credit_cells($bfw);
    label_cell("");
    end_row();
    //$running_total =0;
    $running_total = $bfw;
    $j = 1;
    $k = 0;
    //row colour counter
    while ($myrow = db_fetch($result)) {
        alt_table_row_color($k);
        $running_total += $myrow["amount"];
        $trandate = sql2date($myrow["tran_date"]);
        label_cell(systypes::name($myrow["type"]));
        label_cell(get_gl_view_str($myrow["type"], $myrow["type_no"], $myrow["type_no"], true));
        label_cell($trandate);
        if ($dim >= 1) {
            label_cell(get_dimension_string($myrow['dimension_id'], true));
        }
        if ($dim > 1) {
            label_cell(get_dimension_string($myrow['dimension2_id'], true));
        }
        label_cell(payment_person_types::person_name($myrow["person_type_id"], $myrow["person_id"]));
        display_debit_or_credit_cells($myrow["amount"]);
        amount_cell($running_total);
        label_cell($myrow['memo_']);
        end_row();
        $j++;
        if ($j == 12) {
            $j = 1;
            table_header($th);
        }
    }
    //end of while loop
    start_row("class='inquirybg'");
    label_cell("<b>" . tr("Ending Balance") . " - " . $_POST['TransToDate'] . "</b>", "colspan={$colspan}");
    display_debit_or_credit_cells($running_total);
    label_cell("");
    end_row();
    end_table(2);
    if (db_num_rows($result) == 0) {
        display_note(tr("No general ledger transactions have been created for this account on the selected dates."), 0, 1);
    }
}
Example #15
0
function print_GL_transactions()
{
    global $path_to_root;
    include_once $path_to_root . "reporting/includes/pdf_report.inc";
    $rep = new FrontReport(tr('GL Account Transactions'), "GLAccountTransactions.pdf", user_pagesize());
    $dim = get_company_pref('use_dimension');
    $dimension = $dimension2 = 0;
    $from = $_REQUEST['PARAM_0'];
    $to = $_REQUEST['PARAM_1'];
    $fromacc = $_REQUEST['PARAM_2'];
    $toacc = $_REQUEST['PARAM_3'];
    if ($dim == 2) {
        $dimension = $_REQUEST['PARAM_4'];
        $dimension2 = $_REQUEST['PARAM_5'];
        $comments = $_REQUEST['PARAM_6'];
    } else {
        if ($dim == 1) {
            $dimension = $_REQUEST['PARAM_4'];
            $comments = $_REQUEST['PARAM_5'];
        } else {
            $comments = $_REQUEST['PARAM_4'];
        }
    }
    $dec = user_price_dec();
    $cols = array(0, 70, 90, 140, 210, 280, 340, 400, 450, 510, 570);
    //------------0--1---2---3----4----5----6----7----8----9----10-------
    //-----------------------dim1-dim2-----------------------------------
    //-----------------------dim1----------------------------------------
    //-------------------------------------------------------------------
    $aligns = array('left', 'left', 'left', 'left', 'left', 'left', 'right', 'right', 'right');
    if ($dim == 2) {
        $headers = array(tr('Type'), tr('#'), tr('Date'), tr('Dimension') . " 1", tr('Dimension') . " 2", tr('Person/Item'), tr('Debit'), tr('Credit'), tr('Balance'));
    } else {
        if ($dim == 1) {
            $headers = array(tr('Type'), tr('#'), tr('Date'), tr('Dimension'), "", tr('Person/Item'), tr('Debit'), tr('Credit'), tr('Balance'));
        } else {
            $headers = array(tr('Type'), tr('#'), tr('Date'), "", "", tr('Person/Item'), tr('Debit'), tr('Credit'), tr('Balance'));
        }
    }
    if ($dim == 2) {
        $params = array(0 => $comments, 1 => array('text' => tr('Period'), 'from' => $from, 'to' => $to), 2 => array('text' => tr('Accounts'), 'from' => $fromacc, 'to' => $toacc), 3 => array('text' => tr('Dimension') . " 1", 'from' => get_dimension_string($dimension), 'to' => ''), 4 => 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('Accounts'), 'from' => $fromacc, 'to' => $toacc), 3 => array('text' => tr('Dimension'), 'from' => get_dimension_string($dimension), 'to' => ''));
        } else {
            $params = array(0 => $comments, 1 => array('text' => tr('Period'), 'from' => $from, 'to' => $to), 2 => array('text' => tr('Accounts'), 'from' => $fromacc, 'to' => $toacc));
        }
    }
    $rep->Font();
    $rep->Info($params, $cols, $headers, $aligns);
    $rep->Header();
    $accounts = get_gl_accounts($fromacc, $toacc);
    while ($account = db_fetch($accounts)) {
        if (is_account_balancesheet($account["account_code"])) {
            $begin = "";
        } else {
            if ($from < $begin) {
                $begin = add_days($from, -1);
            } else {
                $begin = add_days(begin_fiscalyear(), -1);
            }
        }
        $prev_balance = get_gl_balance_from_to($begin, $from, $account["account_code"], $dimension, $dimension2);
        $trans = get_gl_transactions($from, $to, -1, $account['account_code'], $dimension, $dimension2);
        $rows = db_num_rows($trans);
        if ($prev_balance == 0.0 && $rows == 0) {
            continue;
        }
        $rep->Font('bold');
        $rep->TextCol(0, 3, $account['account_code'] . " " . $account['account_name']);
        $rep->TextCol(3, 5, tr('Opening Balance'));
        if ($prev_balance > 0.0) {
            $rep->TextCol(6, 7, number_format2(abs($prev_balance), $dec));
        } else {
            $rep->TextCol(7, 8, number_format2(abs($prev_balance), $dec));
        }
        $rep->Font();
        $total = $prev_balance;
        $rep->NewLine(2);
        if ($rows > 0) {
            while ($myrow = db_fetch($trans)) {
                $total += $myrow['amount'];
                $rep->TextCol(0, 1, systypes::name($myrow["type"]));
                $rep->TextCol(1, 2, $myrow['type_no']);
                $rep->TextCol(2, 3, sql2date($myrow["tran_date"]));
                if ($dim >= 1) {
                    $rep->TextCol(3, 4, get_dimension_string($myrow['dimension_id']));
                }
                if ($dim > 1) {
                    $rep->TextCol(4, 5, get_dimension_string($myrow['dimension2_id']));
                }
                $rep->TextCol(5, 6, payment_person_types::person_name($myrow["person_type_id"], $myrow["person_id"], false));
                if ($myrow['amount'] > 0.0) {
                    $rep->TextCol(6, 7, number_format2(abs($myrow['amount']), $dec));
                } else {
                    $rep->TextCol(7, 8, number_format2(abs($myrow['amount']), $dec));
                }
                $rep->TextCol(8, 9, number_format2($total, $dec));
                $rep->NewLine();
                if ($rep->row < $rep->bottomMargin + $rep->lineHeight) {
                    $rep->Line($rep->row - 2);
                    $rep->Header();
                }
            }
            $rep->NewLine();
        }
        $rep->Font('bold');
        $rep->TextCol(3, 5, tr("Ending Balance"));
        if ($total > 0.0) {
            $rep->TextCol(6, 7, number_format2(abs($total), $dec));
        } else {
            $rep->TextCol(7, 8, number_format2(abs($total), $dec));
        }
        $rep->Font();
        $rep->Line($rep->row - $rep->lineHeight + 4);
        $rep->NewLine(2, 1);
    }
    $rep->End();
}
Example #16
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();
}
Example #17
0
label_cell($myrow["id"]);
label_cell($myrow["reference"]);
label_cell($myrow["name"]);
label_cell($myrow["type_"]);
label_cell(sql2date($myrow["date_"]));
label_cell(sql2date($myrow["due_date"]));
end_row();
comments_display_row(ST_DIMENSION, $id);
end_table();
if ($myrow["closed"] == true) {
    display_note(_("This dimension is closed."));
}
start_form();
start_table(TABLESTYLE_NOBORDER);
start_row();
if (!isset($_POST['TransFromDate'])) {
    $_POST['TransFromDate'] = begin_fiscalyear();
}
if (!isset($_POST['TransToDate'])) {
    $_POST['TransToDate'] = Today();
}
date_cells(_("from:"), 'TransFromDate');
date_cells(_("to:"), 'TransToDate');
submit_cells('Show', _("Show"), '', false);
end_row();
end_table();
hidden('trans_no', $id);
end_form();
display_dimension_balance($id, $_POST['TransFromDate'], $_POST['TransToDate']);
br(1);
end_page(true, false, false, ST_DIMENSION, $id);
Example #18
0
function display_profit_and_loss()
{
    global $path_to_root, $sel;
    if (!isset($_POST['Dimension'])) {
        $_POST['Dimension'] = 0;
    }
    if (!isset($_POST['Dimension2'])) {
        $_POST['Dimension2'] = 0;
    }
    $dimension = $_POST['Dimension'];
    $dimension2 = $_POST['Dimension2'];
    $from = $_POST['TransFromDate'];
    $to = $_POST['TransToDate'];
    $compare = $_POST['Compare'];
    if (isset($_POST["AccGrp"]) && strlen($_POST['AccGrp']) > 0) {
        $drilldown = 1;
    } else {
        $drilldown = 0;
    }
    // Root level
    $dec = 0;
    $pdec = user_percent_dec();
    if ($compare == 0 || $compare == 2) {
        $end = $to;
        if ($compare == 2) {
            $begin = $from;
        } else {
            $begin = begin_fiscalyear();
        }
    } elseif ($compare == 1) {
        $begin = add_months($from, -12);
        $end = add_months($to, -12);
    }
    div_start('pl_tbl');
    start_table(TABLESTYLE, "width=50%");
    $tableheader = "<tr>\n        <td class='tableheader'>" . _("Group/Account Name") . "</td>\n        <td class='tableheader'>" . _("Period") . "</td>\n\t\t<td class='tableheader'>" . $sel[$compare] . "</td>\n\t\t<td class='tableheader'>" . _("Achieved %") . "</td>\n        </tr>";
    if (!$drilldown) {
        $parent = -1;
        $classper = 0.0;
        $classacc = 0.0;
        $salesper = 0.0;
        $salesacc = 0.0;
        //Get classes for PL
        $classresult = get_account_classes(false, 0);
        while ($class = db_fetch($classresult)) {
            $class_per_total = 0;
            $class_acc_total = 0;
            $convert = get_class_type_convert($class["ctype"]);
            //Print Class Name
            table_section_title($class["class_name"], 4);
            echo $tableheader;
            //Get Account groups/types under this group/type
            $typeresult = get_account_types(false, $class['cid'], -1);
            while ($accounttype = db_fetch($typeresult)) {
                $TypeTotal = display_type($accounttype["id"], $accounttype["name"], $from, $to, $begin, $end, $compare, $convert, $dec, $pdec, $rep, $dimension, $dimension2, $drilldown, $path_to_root);
                $class_per_total += $TypeTotal[0];
                $class_acc_total += $TypeTotal[1];
                if ($TypeTotal[0] != 0 || $TypeTotal[1] != 0) {
                    $url = "<a href='{$path_to_root}/gl/inquiry/profit_loss.php?TransFromDate=" . $from . "&TransToDate=" . $to . "&Compare=" . $compare . "&Dimension=" . $dimension . "&Dimension2=" . $dimension2 . "&AccGrp=" . $accounttype['id'] . "'>" . $accounttype['id'] . " " . $accounttype['name'] . "</a>";
                    alt_table_row_color($k);
                    label_cell($url);
                    amount_cell($TypeTotal[0] * $convert);
                    amount_cell($TypeTotal[1] * $convert);
                    amount_cell(Achieve($TypeTotal[0], $TypeTotal[1]));
                    end_row();
                }
            }
            //Print Class Summary
            start_row("class='inquirybg' style='font-weight:bold'");
            label_cell(_('Total') . " " . $class["class_name"]);
            amount_cell($class_per_total * $convert);
            amount_cell($class_acc_total * $convert);
            amount_cell(Achieve($class_per_total, $class_acc_total));
            end_row();
            $salesper += $class_per_total;
            $salesacc += $class_acc_total;
        }
        start_row("class='inquirybg' style='font-weight:bold'");
        label_cell(_('Calculated Return'));
        amount_cell($salesper * -1);
        amount_cell($salesacc * -1);
        amount_cell(achieve($salesper, $salesacc));
        end_row();
    } else {
        //Level Pointer : Global variable defined in order to control display of root
        global $levelptr;
        $levelptr = 0;
        $accounttype = get_account_type($_POST["AccGrp"]);
        $classid = $accounttype["class_id"];
        $class = get_account_class($classid);
        $convert = get_class_type_convert($class["ctype"]);
        //Print Class Name
        table_section_title($_POST["AccGrp"] . " " . get_account_type_name($_POST["AccGrp"]), 4);
        echo $tableheader;
        $classtotal = display_type($accounttype["id"], $accounttype["name"], $from, $to, $begin, $end, $compare, $convert, $dec, $pdec, $rep, $dimension, $dimension2, $drilldown, $path_to_root);
    }
    end_table(1);
    // outer table
    div_end();
}
Example #19
0
function print_profit_and_loss_statement()
{
    global $path_to_root;
    $dim = get_company_pref('use_dimension');
    $dimension = $dimension2 = 0;
    $from = $_POST['PARAM_0'];
    $to = $_POST['PARAM_1'];
    $compare = $_POST['PARAM_2'];
    if ($dim == 2) {
        $dimension = $_POST['PARAM_3'];
        $dimension2 = $_POST['PARAM_4'];
        $tags = isset($_POST['PARAM_5']) ? $_POST['PARAM_5'] : -1;
        $decimals = $_POST['PARAM_6'];
        $graphics = $_POST['PARAM_7'];
        $comments = $_POST['PARAM_8'];
        $orientation = $_POST['PARAM_9'];
        $destination = $_POST['PARAM_10'];
    } else {
        if ($dim == 1) {
            $dimension = $_POST['PARAM_3'];
            $tags = isset($_POST['PARAM_4']) ? $_POST['PARAM_4'] : -1;
            $decimals = $_POST['PARAM_5'];
            $graphics = $_POST['PARAM_6'];
            $comments = $_POST['PARAM_7'];
            $orientation = $_POST['PARAM_8'];
            $destination = $_POST['PARAM_9'];
        } else {
            $tags = isset($_POST['PARAM_3']) ? $_POST['PARAM_3'] : -1;
            $decimals = $_POST['PARAM_4'];
            $graphics = $_POST['PARAM_5'];
            $comments = $_POST['PARAM_6'];
            $orientation = $_POST['PARAM_7'];
            $destination = $_POST['PARAM_8'];
        }
    }
    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 (!$decimals) {
        $dec = 0;
    } else {
        $dec = user_price_dec();
    }
    $pdec = user_percent_dec();
    $cols = array(0, 50, 200, 350, 425, 500);
    //------------0--1---2----3----4----5--
    $headers = array(_('Account'), _('Account Name'), _('Period'), _('Accumulated'), _('Achieved %'));
    $aligns = array('left', 'left', 'right', 'right', 'right');
    if ($dim == 2) {
        $params = array(0 => $comments, 1 => array('text' => _('Period'), 'from' => $from, 'to' => $to), 2 => array('text' => _('Dimension') . " 1", 'from' => get_dimension_string($dimension), 'to' => ''), 3 => array('text' => _('Dimension') . " 2", 'from' => get_dimension_string($dimension2), 'to' => ''), 4 => array('text' => _('Tags'), 'from' => get_tag_names($tags), 'to' => ''));
    } else {
        if ($dim == 1) {
            $params = array(0 => $comments, 1 => array('text' => _('Period'), 'from' => $from, 'to' => $to), 2 => array('text' => _('Dimension'), 'from' => get_dimension_string($dimension), 'to' => ''), 3 => array('text' => _('Tags'), 'from' => get_tag_names($tags), 'to' => ''));
        } else {
            $params = array(0 => $comments, 1 => array('text' => _('Period'), 'from' => $from, 'to' => $to), 2 => array('text' => _('Tags'), 'from' => get_tag_names($tags), 'to' => ''));
        }
    }
    if ($compare == 0 || $compare == 2) {
        $end = $to;
        if ($compare == 2) {
            $begin = $from;
            $headers[3] = _('Budget');
        } else {
            $begin = begin_fiscalyear();
        }
    } elseif ($compare == 1) {
        $begin = add_months($from, -12);
        $end = add_months($to, -12);
        $headers[3] = _('Period Y-1');
    }
    $rep = new FrontReport(_('Profit and Loss Statement'), "ProfitAndLoss", user_pagesize(), 9, $orientation);
    if ($orientation == 'L') {
        recalculate_cols($cols);
    }
    $rep->Font();
    $rep->Info($params, $cols, $headers, $aligns);
    $rep->NewPage();
    $salesper = 0.0;
    $salesacc = 0.0;
    $classresult = get_account_classes(false, 0);
    while ($class = db_fetch($classresult)) {
        $class_per_total = 0;
        $class_acc_total = 0;
        $convert = get_class_type_convert($class["ctype"]);
        //Print Class Name
        $rep->Font('bold');
        $rep->TextCol(0, 5, $class["class_name"]);
        $rep->Font();
        $rep->NewLine();
        //Get Account groups/types under this group/type with no parents
        $typeresult = get_account_types(false, $class['cid'], -1);
        while ($accounttype = db_fetch($typeresult)) {
            $classtotal = display_type($accounttype["id"], $accounttype["name"], $from, $to, $begin, $end, $compare, $convert, $dec, $pdec, $rep, $dimension, $dimension2, $tags, $pg, $graphics);
            $class_per_total += $classtotal[0];
            $class_acc_total += $classtotal[1];
        }
        //Print Class Summary
        $rep->row += 6;
        $rep->Line($rep->row);
        $rep->NewLine();
        $rep->Font('bold');
        $rep->TextCol(0, 2, _('Total') . " " . $class["class_name"]);
        $rep->AmountCol(2, 3, $class_per_total * $convert, $dec);
        $rep->AmountCol(3, 4, $class_acc_total * $convert, $dec);
        $rep->AmountCol(4, 5, Achieve($class_per_total, $class_acc_total), $pdec);
        $rep->Font();
        $rep->NewLine(2);
        $salesper += $class_per_total;
        $salesacc += $class_acc_total;
    }
    $rep->Font('bold');
    $rep->TextCol(0, 2, _('Calculated Return'));
    $rep->AmountCol(2, 3, $salesper * -1, $dec);
    // always convert
    $rep->AmountCol(3, 4, $salesacc * -1, $dec);
    $rep->AmountCol(4, 5, Achieve($salesper, $salesacc), $pdec);
    if ($graphics) {
        $pg->x[] = _('Calculated Return');
        $pg->y[] = abs($salesper);
        $pg->z[] = abs($salesacc);
    }
    $rep->Font();
    $rep->NewLine();
    $rep->Line($rep->row);
    if ($graphics) {
        global $decseps, $graph_skin;
        $pg->title = $rep->title;
        $pg->axis_x = _("Group");
        $pg->axis_y = _("Amount");
        $pg->graphic_1 = $headers[2];
        $pg->graphic_2 = $headers[3];
        $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();
}