Example #1
0
 $fyear = db_fetch($result);
 $begin = sql2date($fyear['begin']);
 $end = sql2date($fyear['end']);
 hidden('begin', $begin);
 hidden('end', $end);
 $total = $btotal = $ltotal = 0;
 for ($i = 0, $date_ = $begin; date1_greater_date2($end, $date_); $i++) {
     start_row();
     $_POST['amount' . $i] = number_format2(get_only_budget_trans_from_to($date_, $date_, $_POST['account'], $_POST['dim1'], $_POST['dim2']), 0);
     label_cell($date_);
     if (!isset($_POST['amount' . $i])) {
         $_POST['amount' . $i] = '0';
     }
     amount_cells(null, 'amount' . $i, null, 15, null, 0);
     if ($showdims) {
         $d = get_budget_trans_from_to($date_, $date_, $_POST['account'], $_POST['dim1'], $_POST['dim2']);
         label_cell(number_format2($d, 0), "nowrap align=right");
         $btotal += $d;
     }
     $lamount = get_gl_trans_from_to(add_years($date_, -1), add_years(end_month($date_), -1), $_POST['account'], $_POST['dim1'], $_POST['dim2']);
     $total += input_num('amount' . $i);
     $ltotal += $lamount;
     label_cell(number_format2($lamount, 0), "nowrap align=right");
     $date_ = add_months($date_, 1);
     end_row();
 }
 start_row();
 label_cell("<b>" . tr("Total") . "</b>");
 label_cell("<b>" . number_format2($total, 0) . "</b>", 'align=right');
 if ($showdims) {
     label_cell("<b>" . number_format2($btotal, 0) . "</b>", "nowrap align=right");
Example #2
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 #3
0
function display_type($type, $typename, $from, $to, $begin, $end, $compare, $convert, &$dec, &$pdec, &$rep, $dimension = 0, $dimension2 = 0, $drilldown, $path_to_root)
{
    global $levelptr, $k;
    $code_per_balance = 0;
    $code_acc_balance = 0;
    $per_balance_total = 0;
    $acc_balance_total = 0;
    unset($totals_arr);
    $totals_arr = array();
    //Get Accounts directly under this group/type
    $result = get_gl_accounts(null, null, $type);
    while ($account = db_fetch($result)) {
        $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 ($drilldown && $levelptr == 0) {
            $url = "<a href='{$path_to_root}/gl/inquiry/gl_account_inquiry.php?TransFromDate=" . $from . "&TransToDate=" . $to . "&Dimension=" . $dimension . "&Dimension2=" . $dimension2 . "&account=" . $account['account_code'] . "'>" . $account['account_code'] . " " . $account['account_name'] . "</a>";
            start_row("class='stockmankobg'");
            label_cell($url);
            amount_cell($per_balance * $convert);
            amount_cell($acc_balance * $convert);
            amount_cell(Achieve($per_balance, $acc_balance));
            end_row();
        }
        $code_per_balance += $per_balance;
        $code_acc_balance += $acc_balance;
    }
    $levelptr = 1;
    //Get Account groups/types under this group/type
    $result = get_account_types(false, false, $type);
    while ($accounttype = db_fetch($result)) {
        $totals_arr = display_type($accounttype["id"], $accounttype["name"], $from, $to, $begin, $end, $compare, $convert, $dec, $pdec, $rep, $dimension, $dimension2, $drilldown, $path_to_root);
        $per_balance_total += $totals_arr[0];
        $acc_balance_total += $totals_arr[1];
    }
    //Display Type Summary if total is != 0
    if ($code_per_balance + $per_balance_total + $code_acc_balance + $acc_balance_total != 0) {
        if ($drilldown && $type == $_POST["AccGrp"]) {
            start_row("class='inquirybg' style='font-weight:bold'");
            label_cell(_('Total') . " " . $typename);
            amount_cell(($code_per_balance + $per_balance_total) * $convert);
            amount_cell(($code_acc_balance + $acc_balance_total) * $convert);
            amount_cell(Achieve($code_per_balance + $per_balance_total, $code_acc_balance + $acc_balance_total));
            end_row();
        }
        //START Patch#1 : Display  only direct child types
        $acctype1 = get_account_type($type);
        $parent1 = $acctype1["parent"];
        if ($drilldown && $parent1 == $_POST["AccGrp"]) {
            $url = "<a href='{$path_to_root}/gl/inquiry/profit_loss.php?TransFromDate=" . $from . "&TransToDate=" . $to . "&Compare=" . $compare . "&Dimension=" . $dimension . "&Dimension2=" . $dimension2 . "&AccGrp=" . $type . "'>" . $type . " " . $typename . "</a>";
            alt_table_row_color($k);
            label_cell($url);
            amount_cell(($code_per_balance + $per_balance_total) * $convert);
            amount_cell(($code_acc_balance + $acc_balance_total) * $convert);
            amount_cell(Achieve($code_per_balance + $per_balance_total, $code_acc_balance + $acc_balance_total));
            end_row();
        }
    }
    $totals_arr[0] = $code_per_balance + $per_balance_total;
    $totals_arr[1] = $code_acc_balance + $acc_balance_total;
    return $totals_arr;
}
Example #4
0
function display_type($type, $typename, $from, $to, $begin, $end, $compare, $convert, &$dec, &$pdec, &$rep, $dimension, $dimension2, $tags, &$pg, $graphics)
{
    $code_per_balance = 0;
    $code_acc_balance = 0;
    $per_balance_total = 0;
    $acc_balance_total = 0;
    $totals_arr = array();
    $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)) {
        if ($tags != -1 && is_array($tags) && $tags[0] != false) {
            if (!is_record_in_tags($tags, TAG_ACCOUNT, $account['account_code'])) {
                continue;
            }
        }
        $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;
        }
        //Print Type Title if it has atleast one non-zero account
        if (!$printtitle) {
            $printtitle = 1;
            $rep->row -= 4;
            $rep->TextCol(0, 5, $typename);
            $rep->row -= 4;
            $rep->Line($rep->row);
            $rep->NewLine();
        }
        $rep->TextCol(0, 1, $account['account_code']);
        $rep->TextCol(1, 2, $account['account_name']);
        $rep->AmountCol(2, 3, $per_balance * $convert, $dec);
        $rep->AmountCol(3, 4, $acc_balance * $convert, $dec);
        $rep->AmountCol(4, 5, Achieve($per_balance, $acc_balance), $pdec);
        $rep->NewLine();
        if ($rep->row < $rep->bottomMargin + 3 * $rep->lineHeight) {
            $rep->Line($rep->row - 2);
            $rep->NewPage();
        }
        $code_per_balance += $per_balance;
        $code_acc_balance += $acc_balance;
    }
    //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, 5, $typename);
            $rep->row -= 4;
            $rep->Line($rep->row);
            $rep->NewLine();
        }
        $totals_arr = display_type($accounttype["id"], $accounttype["name"], $from, $to, $begin, $end, $compare, $convert, $dec, $pdec, $rep, $dimension, $dimension2, $tags, $pg, $graphics);
        $per_balance_total += $totals_arr[0];
        $acc_balance_total += $totals_arr[1];
    }
    //Display Type Summary if total is != 0 OR head is printed (Needed in case of unused hierarchical COA)
    if ($code_per_balance + $per_balance_total + $code_acc_balance + $acc_balance_total != 0 || $printtitle) {
        $rep->row += 6;
        $rep->Line($rep->row);
        $rep->NewLine();
        $rep->TextCol(0, 2, _('Total') . " " . $typename);
        $rep->AmountCol(2, 3, ($code_per_balance + $per_balance_total) * $convert, $dec);
        $rep->AmountCol(3, 4, ($code_acc_balance + $acc_balance_total) * $convert, $dec);
        $rep->AmountCol(4, 5, Achieve($code_per_balance + $per_balance_total, $code_acc_balance + $acc_balance_total), $pdec);
        if ($graphics) {
            $pg->x[] = $typename;
            $pg->y[] = abs($code_per_balance + $per_balance_total);
            $pg->z[] = abs($code_acc_balance + $acc_balance_total);
        }
        $rep->NewLine();
    }
    $totals_arr[0] = $code_per_balance + $per_balance_total;
    $totals_arr[1] = $code_acc_balance + $acc_balance_total;
    return $totals_arr;
}