Пример #1
0
function show_results()
{
    global $path_to_root, $systypes_array;
    if (!isset($_POST["account"])) {
        $_POST["account"] = null;
    }
    $act_name = $_POST["account"] ? 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'], null, input_num('amount_min'), input_num('amount_max'));
    $colspan = $dim == 2 ? "6" : ($dim == 1 ? "5" : "4");
    if ($_POST["account"] != null) {
        display_heading($_POST["account"] . "   " . $act_name);
    }
    // Only show balances if an account is specified AND we're not filtering by amounts
    $show_balances = $_POST["account"] != null && input_num("amount_min") == 0 && input_num("amount_max") == 0;
    start_table(TABLESTYLE);
    $first_cols = array(_("Type"), _("#"), _("Date"));
    if ($_POST["account"] == null) {
        $account_col = array(_("Account"));
    } else {
        $account_col = array();
    }
    if ($dim == 2) {
        $dim_cols = array(_("Dimension") . " 1", _("Dimension") . " 2");
    } else {
        if ($dim == 1) {
            $dim_cols = array(_("Dimension"));
        } else {
            $dim_cols = array();
        }
    }
    if ($show_balances) {
        $remaining_cols = array(_("Person/Item"), _("Debit"), _("Credit"), _("Balance"), _("Memo"));
    } else {
        $remaining_cols = array(_("Person/Item"), _("Debit"), _("Credit"), _("Memo"));
    }
    $th = array_merge($first_cols, $account_col, $dim_cols, $remaining_cols);
    table_header($th);
    if ($_POST["account"] != null && is_account_balancesheet($_POST["account"])) {
        $begin = "";
    } else {
        $begin = get_fiscalyear_begin_for_date($_POST['TransFromDate']);
        if (date1_greater_date2($begin, $_POST['TransFromDate'])) {
            $begin = $_POST['TransFromDate'];
        }
        $begin = add_days($begin, -1);
    }
    $bfw = 0;
    if ($show_balances) {
        $bfw = get_gl_balance_from_to($begin, $_POST['TransFromDate'], $_POST["account"], $_POST['Dimension'], $_POST['Dimension2']);
        start_row("class='inquirybg'");
        label_cell("<b>" . _("Opening Balance") . " - " . $_POST['TransFromDate'] . "</b>", "colspan={$colspan}");
        display_debit_or_credit_cells($bfw, true);
        label_cell("");
        label_cell("");
        end_row();
    }
    $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_array[$myrow["type"]]);
        label_cell(get_gl_view_str($myrow["type"], $myrow["type_no"], $myrow["type_no"], true));
        label_cell($trandate);
        if ($_POST["account"] == null) {
            label_cell($myrow["account"] . ' ' . get_gl_account_name($myrow["account"]));
        }
        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_name($myrow["person_type_id"], $myrow["person_id"]));
        display_debit_or_credit_cells($myrow["amount"]);
        if ($show_balances) {
            amount_cell($running_total);
        }
        if ($myrow['memo_'] == "") {
            $myrow['memo_'] = get_comments_string($myrow['type'], $myrow['type_no']);
        }
        label_cell($myrow['memo_']);
        end_row();
        $j++;
        if ($j == 12) {
            $j = 1;
            table_header($th);
        }
    }
    //end of while loop
    if ($show_balances) {
        start_row("class='inquirybg'");
        label_cell("<b>" . _("Ending Balance") . " - " . $_POST['TransToDate'] . "</b>", "colspan={$colspan}");
        display_debit_or_credit_cells($running_total, true);
        label_cell("");
        label_cell("");
        end_row();
    }
    end_table(2);
    if (db_num_rows($result) == 0) {
        display_note(_("No general ledger transactions have been created for the specified criteria."), 0, 1);
    }
}
Пример #2
0
function print_GL_transactions()
{
    global $path_to_root, $systypes_array;
    $dim = get_company_pref('use_dimension');
    $dimension = $dimension2 = 0;
    $from = $_POST['PARAM_0'];
    $to = $_POST['PARAM_1'];
    $fromacc = $_POST['PARAM_2'];
    $toacc = $_POST['PARAM_3'];
    if ($dim == 2) {
        $dimension = $_POST['PARAM_4'];
        $dimension2 = $_POST['PARAM_5'];
        $comments = $_POST['PARAM_6'];
        $orientation = $_POST['PARAM_7'];
        $destination = $_POST['PARAM_8'];
    } else {
        if ($dim == 1) {
            $dimension = $_POST['PARAM_4'];
            $comments = $_POST['PARAM_5'];
            $orientation = $_POST['PARAM_6'];
            $destination = $_POST['PARAM_7'];
        } else {
            $comments = $_POST['PARAM_4'];
            $orientation = $_POST['PARAM_5'];
            $destination = $_POST['PARAM_6'];
        }
    }
    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';
    $rep = new FrontReport(_('GL Account Transactions'), "GLAccountTransactions", user_pagesize(), 9, $orientation);
    $dec = 2;
    //$cols = array(0, 80, 100, 150, 210, 280, 340, 400, 450, 510, 570);
    $cols = array(0, 65, 105, 125, 175, 230, 290, 345, 405, 465, 525);
    //------------0--1---2---3----4----5----6----7----8----9----10-------
    //-----------------------dim1-dim2-----------------------------------
    //-----------------------dim1----------------------------------------
    //-------------------------------------------------------------------
    $aligns = array('left', 'left', 'left', 'left', 'left', 'left', 'left', 'right', 'right', 'right');
    if ($dim == 2) {
        $headers = array(_('Type'), _('Ref'), _('#'), _('Date'), _('Dimension') . " 1", _('Dimension') . " 2", _('Person/Item'), _('Debit'), _('Credit'), _('Balance'));
    } elseif ($dim == 1) {
        $headers = array(_('Type'), _('Ref'), _('#'), _('Date'), _('Dimension'), "", _('Person/Item'), _('Debit'), _('Credit'), _('Balance'));
    } else {
        $headers = array(_('Type'), _('Ref'), _('#'), _('Date'), "", "", _('Person/Item'), _('Debit'), _('Credit'), _('Balance'));
    }
    if ($dim == 2) {
        $params = array(0 => $comments, 1 => array('text' => _('Period'), 'from' => $from, 'to' => $to), 2 => array('text' => _('Accounts'), 'from' => $fromacc, 'to' => $toacc), 3 => array('text' => _('Dimension') . " 1", 'from' => get_dimension_string($dimension), 'to' => ''), 4 => array('text' => _('Dimension') . " 2", 'from' => get_dimension_string($dimension2), 'to' => ''));
    } else {
        if ($dim == 1) {
            $params = array(0 => $comments, 1 => array('text' => _('Period'), 'from' => $from, 'to' => $to), 2 => array('text' => _('Accounts'), 'from' => $fromacc, 'to' => $toacc), 3 => array('text' => _('Dimension'), 'from' => get_dimension_string($dimension), 'to' => ''));
        } else {
            $params = array(0 => $comments, 1 => array('text' => _('Period'), 'from' => $from, 'to' => $to), 2 => array('text' => _('Accounts'), 'from' => $fromacc, 'to' => $toacc));
        }
    }
    if ($orientation == 'L') {
        recalculate_cols($cols);
    }
    $rep->Font();
    $rep->Info($params, $cols, $headers, $aligns);
    $rep->NewPage();
    $accounts = get_gl_accounts($fromacc, $toacc);
    while ($account = db_fetch($accounts)) {
        if (is_account_balancesheet($account["account_code"])) {
            $begin = "";
        } else {
            $begin = get_fiscalyear_begin_for_date($from);
            if (date1_greater_date2($begin, $from)) {
                $begin = $from;
            }
            $begin = add_days($begin, -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, 4, $account['account_code'] . " " . $account['account_name'], -2);
        $rep->TextCol(4, 6, _('Opening Balance'));
        if ($prev_balance > 0.0) {
            $rep->AmountCol(7, 8, abs($prev_balance), $dec);
        } else {
            $rep->AmountCol(8, 9, abs($prev_balance), $dec);
        }
        $rep->Font();
        $total = $prev_balance;
        $rep->NewLine(2);
        if ($rows > 0) {
            while ($myrow = db_fetch($trans)) {
                $total += $myrow['amount'];
                $type_name = $systypes_array[$myrow["type"]];
                if ($type_name == "Customer Payment") {
                    $rep->TextCol(0, 1, "CRB", -2);
                }
                if ($type_name == "Cash Disbursement/Check Voucher") {
                    $rep->TextCol(0, 1, "CDB", -2);
                }
                if ($type_name == "Journal Entry") {
                    $rep->TextCol(0, 1, "JB", -2);
                }
                if ($type_name == "Customer Credit Note") {
                    $type_name = "Credit Memo";
                }
                if ($type_name == "Sales Invoice") {
                    $type_name = "Invoice";
                } else {
                    if ($type_name != "Customer Payment" && $type_name != "Cash Disbursement/Check Voucher" && $type_name != "Journal Entry") {
                        $rep->TextCol(0, 1, $type_name, -2);
                    }
                }
                $reference = get_reference($myrow["type"], $myrow["type_no"]);
                $rep->TextCol(1, 2, $reference);
                $rep->TextCol(2, 3, $myrow['type_no'], -2);
                $rep->DateCol(3, 4, $myrow["tran_date"], true);
                if ($dim >= 1) {
                    $rep->TextCol(4, 5, get_dimension_string($myrow['dimension_id']));
                }
                if ($dim > 1) {
                    $rep->TextCol(5, 6, get_dimension_string($myrow['dimension2_id']));
                }
                $txt = payment_person_name($myrow["person_type_id"], $myrow["person_id"], false);
                $memo = $myrow['memo_'];
                if ($txt != "") {
                    if ($memo != "") {
                        $txt = $txt . "/" . $memo;
                    }
                } else {
                    $txt = $memo;
                }
                $rep->TextCol(6, 7, $txt, -2);
                if ($myrow['amount'] > 0.0) {
                    $rep->AmountCol(7, 8, abs($myrow['amount']), $dec);
                } else {
                    $rep->AmountCol(8, 9, abs($myrow['amount']), $dec);
                }
                $rep->TextCol(9, 10, number_format2($total, $dec));
                $rep->NewLine();
                if ($rep->row < $rep->bottomMargin + $rep->lineHeight) {
                    $rep->Line($rep->row - 2);
                    $rep->NewPage();
                }
            }
            $rep->NewLine();
        }
        $rep->Font('bold');
        $rep->TextCol(4, 6, _("Ending Balance"));
        if ($total > 0.0) {
            $rep->AmountCol(7, 8, abs($total), $dec);
        } else {
            $rep->AmountCol(8, 9, abs($total), $dec);
        }
        $rep->Font();
        $rep->Line($rep->row - $rep->lineHeight + 4);
        $rep->NewLine(2, 1);
    }
    $rep->End();
}
Пример #3
0
function display_type($type, $typename, &$dec, &$rep, $from, $to, $zero, $balances, $dimension, $dimension2)
{
    global $pdeb, $pcre, $cdeb, $ccre, $tdeb, $tcre, $pbal, $cbal, $tbal, $clear_trial_balance_opening;
    $printtitle = 0;
    //Flag for printing type name
    //Get Accounts directly under this group/type
    $accounts = get_gl_accounts(null, null, $type);
    $begin = get_fiscalyear_begin_for_date($from);
    if (date1_greater_date2($begin, $from)) {
        $begin = $from;
    }
    $begin = add_days($begin, -1);
    while ($account = db_fetch($accounts)) {
        //Print Type Title if it has atleast one non-zero account
        if (!$printtitle) {
            $rep->row -= 4;
            $rep->TextCol(0, 8, _("Group") . " - " . $type . " - " . $typename);
            $printtitle = 1;
            $rep->row -= 4;
            $rep->Line($rep->row);
            $rep->NewLine();
        }
        // FA doesn't really clear the closed year, therefore the brought forward balance includes all the transactions from the past, even though the balance is null.
        // If we want to remove the balanced part for the past years, this option removes the common part from from the prev and tot figures.
        if (@$clear_trial_balance_opening) {
            $open = get_balance($account["account_code"], $dimension, $dimension2, $begin, $begin, false, true);
            $offset = min($open['debit'], $open['credit']);
        } else {
            $offset = 0;
        }
        $prev = get_balance($account["account_code"], $dimension, $dimension2, $begin, $from, false, false);
        $curr = get_balance($account["account_code"], $dimension, $dimension2, $from, $to, true, true);
        $tot = get_balance($account["account_code"], $dimension, $dimension2, $begin, $to, false, true);
        if ($zero == 0 && !$prev['balance'] && !$curr['balance'] && !$tot['balance']) {
            continue;
        }
        $rep->TextCol(0, 1, $account['account_code']);
        $rep->TextCol(1, 2, $account['account_name']);
        if ($balances != 0) {
            if ($prev['balance'] >= 0.0) {
                $rep->AmountCol(2, 3, $prev['balance'], $dec);
            } else {
                $rep->AmountCol(3, 4, abs($prev['balance']), $dec);
            }
            if ($curr['balance'] >= 0.0) {
                $rep->AmountCol(4, 5, $curr['balance'], $dec);
            } else {
                $rep->AmountCol(5, 6, abs($curr['balance']), $dec);
            }
            if ($tot['balance'] >= 0.0) {
                $rep->AmountCol(6, 7, $tot['balance'], $dec);
            } else {
                $rep->AmountCol(7, 8, abs($tot['balance']), $dec);
            }
        } else {
            $rep->AmountCol(2, 3, $prev['debit'] - $offset, $dec);
            $rep->AmountCol(3, 4, $prev['credit'] - $offset, $dec);
            $rep->AmountCol(4, 5, $curr['debit'], $dec);
            $rep->AmountCol(5, 6, $curr['credit'], $dec);
            $rep->AmountCol(6, 7, $tot['debit'] - $offset, $dec);
            $rep->AmountCol(7, 8, $tot['credit'] - $offset, $dec);
            $pdeb += $prev['debit'] - $offset;
            $pcre += $prev['credit'] - $offset;
            $cdeb += $curr['debit'];
            $ccre += $curr['credit'];
            $tdeb += $tot['debit'] - $offset;
            $tcre += $tot['credit'] - $offset;
        }
        $pbal += $prev['balance'];
        $cbal += $curr['balance'];
        $tbal += $tot['balance'];
        $rep->NewLine();
        if ($rep->row < $rep->bottomMargin + $rep->lineHeight) {
            $rep->Line($rep->row - 2);
            $rep->NewPage();
        }
    }
    //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) {
            $rep->row -= 4;
            $rep->TextCol(0, 8, _("Group") . " - " . $type . " - " . $typename);
            $printtitle = 1;
            $rep->row -= 4;
            $rep->Line($rep->row);
            $rep->NewLine();
        }
        display_type($accounttype["id"], $accounttype["name"] . ' (' . $typename . ')', $dec, $rep, $from, $to, $zero, $balances, $dimension, $dimension2);
    }
}
Пример #4
0
function display_trial_balance($type, $typename)
{
    global $path_to_root;
    global $k, $pdeb, $pcre, $cdeb, $ccre, $tdeb, $tcre, $pbal, $cbal, $tbal;
    $printtitle = 0;
    //Flag for printing type name
    $k = 0;
    //$accounts = get_gl_accounts();
    //Get Accounts directly under this group/type
    $accounts = get_gl_accounts(null, null, $type);
    $begin = get_fiscalyear_begin_for_date($_POST['TransFromDate']);
    //$begin = begin_fiscalyear();
    if (date1_greater_date2($begin, $_POST['TransFromDate'])) {
        $begin = $_POST['TransFromDate'];
    }
    $begin = add_days($begin, -1);
    while ($account = db_fetch($accounts)) {
        //Print Type Title if it has atleast one non-zero account
        if ($type == 3502) {
            continue;
        }
        if (!$printtitle) {
            start_row("class='inquirybg' style='font-weight:bold'");
            label_cell(_("Group") . " - " . $type . " - " . $typename, "colspan=8");
            end_row();
            $printtitle = 1;
        }
        $prev = get_balance($account["account_code"], $_POST['Dimension'], $_POST['Dimension2'], $begin, $_POST['TransFromDate'], false, false);
        $curr = get_balance($account["account_code"], $_POST['Dimension'], $_POST['Dimension2'], $_POST['TransFromDate'], $_POST['TransToDate'], true, true);
        $tot = get_balance($account["account_code"], $_POST['Dimension'], $_POST['Dimension2'], $begin, $_POST['TransToDate'], false, true);
        if (check_value("NoZero") && !$prev['balance'] && !$curr['balance'] && !$tot['balance']) {
            continue;
        }
        alt_table_row_color($k);
        $url = "<a href='{$path_to_root}/gl/inquiry/gl_account_inquiry.php?TransFromDate=" . $_POST["TransFromDate"] . "&TransToDate=" . $_POST["TransToDate"] . "&account=" . $account["account_code"] . "&Dimension=" . $_POST["Dimension"] . "&Dimension2=" . $_POST["Dimension2"] . "'>" . $account["account_code"] . "</a>";
        label_cell($url);
        label_cell($account["account_name"]);
        if (check_value('Balance')) {
            display_debit_or_credit_cells($prev['balance']);
            display_debit_or_credit_cells($curr['balance']);
            display_debit_or_credit_cells($tot['balance']);
        } else {
            amount_cell($prev['debit']);
            amount_cell($prev['credit']);
            amount_cell($curr['debit']);
            amount_cell($curr['credit']);
            amount_cell($tot['debit']);
            amount_cell($tot['credit']);
            $pdeb += $prev['debit'];
            $pcre += $prev['credit'];
            $cdeb += $curr['debit'];
            $ccre += $curr['credit'];
            $tdeb += $tot['debit'];
            $tcre += $tot['credit'];
        }
        $pbal += $prev['balance'];
        $cbal += $curr['balance'];
        $tbal += $tot['balance'];
        end_row();
    }
    //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) {
            start_row("class='inquirybg' style='font-weight:bold'");
            label_cell(_("Group") . " - " . $type . " - " . $typename, "colspan=8");
            end_row();
            $printtitle = 1;
        }
        display_trial_balance($accounttype["id"], $accounttype["name"] . ' (' . $typename . ')');
    }
}
Пример #5
0
function display_trial_balance($type, $typename)
{
    global $path_to_root, $clear_trial_balance_opening;
    global $k, $pdeb, $pcre, $cdeb, $ccre, $tdeb, $tcre, $pbal, $cbal, $tbal;
    $printtitle = 0;
    //Flag for printing type name
    $k = 0;
    //$accounts = get_gl_accounts();
    //Get Accounts directly under this group/type
    $accounts = get_gl_accounts(null, null, $type);
    $begin = get_fiscalyear_begin_for_date($_POST['TransFromDate']);
    //$begin = begin_fiscalyear();
    if (date1_greater_date2($begin, $_POST['TransFromDate'])) {
        $begin = $_POST['TransFromDate'];
    }
    $begin = add_days($begin, -1);
    while ($account = db_fetch($accounts)) {
        //Print Type Title if it has atleast one non-zero account
        if (!$printtitle) {
            start_row("class='inquirybg' style='font-weight:bold'");
            label_cell(_("Group") . " - " . $type . " - " . $typename, "colspan=8");
            end_row();
            $printtitle = 1;
        }
        // FA doesn't really clear the closed year, therefore the brought forward balance includes all the transactions from the past, even though the balance is null.
        // If we want to remove the balanced part for the past years, this option removes the common part from from the prev and tot figures.
        if (@$clear_trial_balance_opening) {
            $open = get_balance($account["account_code"], $_POST['Dimension'], $_POST['Dimension2'], $begin, $begin, false, true);
            $offset = min($open['debit'], $open['credit']);
        } else {
            $offset = 0;
        }
        $prev = get_balance($account["account_code"], $_POST['Dimension'], $_POST['Dimension2'], $begin, $_POST['TransFromDate'], false, false);
        $curr = get_balance($account["account_code"], $_POST['Dimension'], $_POST['Dimension2'], $_POST['TransFromDate'], $_POST['TransToDate'], true, true);
        $tot = get_balance($account["account_code"], $_POST['Dimension'], $_POST['Dimension2'], $begin, $_POST['TransToDate'], false, true);
        if (check_value("NoZero") && !$prev['balance'] && !$curr['balance'] && !$tot['balance']) {
            continue;
        }
        alt_table_row_color($k);
        $url = "<a href='{$path_to_root}/gl/inquiry/gl_account_inquiry.php?TransFromDate=" . $_POST["TransFromDate"] . "&TransToDate=" . $_POST["TransToDate"] . "&account=" . $account["account_code"] . "&Dimension=" . $_POST["Dimension"] . "&Dimension2=" . $_POST["Dimension2"] . "'>" . $account["account_code"] . "</a>";
        label_cell($url);
        label_cell($account["account_name"]);
        if (check_value('Balance')) {
            display_debit_or_credit_cells($prev['balance']);
            display_debit_or_credit_cells($curr['balance']);
            display_debit_or_credit_cells($tot['balance']);
        } else {
            amount_cell($prev['debit'] - $offset);
            amount_cell($prev['credit'] - $offset);
            amount_cell($curr['debit']);
            amount_cell($curr['credit']);
            amount_cell($tot['debit'] - $offset);
            amount_cell($tot['credit'] - $offset);
            $pdeb += $prev['debit'];
            $pcre += $prev['credit'];
            $cdeb += $curr['debit'];
            $ccre += $curr['credit'];
            $tdeb += $tot['debit'];
            $tcre += $tot['credit'];
        }
        $pbal += $prev['balance'];
        $cbal += $curr['balance'];
        $tbal += $tot['balance'];
        end_row();
    }
    //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) {
            start_row("class='inquirybg' style='font-weight:bold'");
            label_cell(_("Group") . " - " . $type . " - " . $typename, "colspan=8");
            end_row();
            $printtitle = 1;
        }
        display_trial_balance($accounttype["id"], $accounttype["name"] . ' (' . $typename . ')');
    }
}
Пример #6
0
function display_type($type, $typename, &$dec, &$rep, $from, $to, $zero, $balances, $dimension, $dimension2)
{
    global $pdeb, $pcre, $cdeb, $ccre, $tdeb, $tcre, $pbal, $cbal, $tbal;
    $printtitle = 0;
    //Flag for printing type name
    //Get Accounts directly under this group/type
    $accounts = get_gl_accounts(null, null, $type);
    $begin = get_fiscalyear_begin_for_date($from);
    if (date1_greater_date2($begin, $from)) {
        $begin = $from;
    }
    $begin = add_days($begin, -1);
    while ($account = db_fetch($accounts)) {
        //Print Type Title if it has atleast one non-zero account
        if (!$printtitle) {
            $rep->row -= 4;
            $rep->TextCol(0, 8, _("Group") . " - " . $type . " - " . $typename);
            $printtitle = 1;
            $rep->row -= 4;
            $rep->Line($rep->row);
            $rep->NewLine();
        }
        $prev = get_balance($account["account_code"], $dimension, $dimension2, $begin, $from, false, false);
        $curr = get_balance($account["account_code"], $dimension, $dimension2, $from, $to, true, true);
        $tot = get_balance($account["account_code"], $dimension, $dimension2, $begin, $to, false, true);
        if ($zero == 0 && !$prev['balance'] && !$curr['balance'] && !$tot['balance']) {
            continue;
        }
        $rep->TextCol(0, 1, $account['account_code']);
        $rep->TextCol(1, 2, $account['account_name']);
        if ($balances != 0) {
            if ($prev['balance'] >= 0.0) {
                $rep->AmountCol(2, 3, $prev['balance'], $dec);
            } else {
                $rep->AmountCol(3, 4, abs($prev['balance']), $dec);
            }
            if ($curr['balance'] >= 0.0) {
                $rep->AmountCol(4, 5, $curr['balance'], $dec);
            } else {
                $rep->AmountCol(5, 6, abs($curr['balance']), $dec);
            }
            if ($tot['balance'] >= 0.0) {
                $rep->AmountCol(6, 7, $tot['balance'], $dec);
            } else {
                $rep->AmountCol(7, 8, abs($tot['balance']), $dec);
            }
        } else {
            $rep->AmountCol(2, 3, $prev['debit'], $dec);
            $rep->AmountCol(3, 4, $prev['credit'], $dec);
            $rep->AmountCol(4, 5, $curr['debit'], $dec);
            $rep->AmountCol(5, 6, $curr['credit'], $dec);
            $rep->AmountCol(6, 7, $tot['debit'], $dec);
            $rep->AmountCol(7, 8, $tot['credit'], $dec);
            $pdeb += $prev['debit'];
            $pcre += $prev['credit'];
            $cdeb += $curr['debit'];
            $ccre += $curr['credit'];
            $tdeb += $tot['debit'];
            $tcre += $tot['credit'];
        }
        $pbal += $prev['balance'];
        $cbal += $curr['balance'];
        $tbal += $tot['balance'];
        $rep->NewLine();
        if ($rep->row < $rep->bottomMargin + $rep->lineHeight) {
            $rep->Line($rep->row - 2);
            $rep->NewPage();
        }
    }
    //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) {
            $rep->row -= 4;
            $rep->TextCol(0, 8, _("Group") . " - " . $type . " - " . $typename);
            $printtitle = 1;
            $rep->row -= 4;
            $rep->Line($rep->row);
            $rep->NewLine();
        }
        display_type($accounttype["id"], $accounttype["name"] . ' (' . $typename . ')', $dec, $rep, $from, $to, $zero, $balances, $dimension, $dimension2);
    }
}
Пример #7
0
function print_subsidiary_ledger()
{
    global $path_to_root, $systypes_array;
    $dim = get_company_pref('use_dimension');
    $dimension = $dimension2 = 0;
    $from = $_POST['PARAM_0'];
    $to = $_POST['PARAM_1'];
    $fromacc = $_POST['PARAM_2'];
    $comments = $_POST['PARAM_3'];
    $orientation = $_POST['PARAM_4'];
    $destination = $_POST['PARAM_5'];
    if ($destination) {
        include_once $path_to_root . "/reporting/includes/excel_report.inc";
    } else {
        include_once $path_to_root . "/reporting/includes/pdf_report2.inc";
    }
    $orientation = $orientation ? 'L' : 'P';
    $rep = new FrontReport(_('Subsidiary Ledger Report'), "SubsidiaryLedger", user_pagesize(), 9, $orientation);
    $dec = user_price_dec();
    //$headers = array(_('Type'),	_('Ref'), _('#'),	_('Date'), _('Dimension')." 1", _('Dimension')." 2",
    //		_('Person/Item'), _('Debit'),	_('Credit'), _('Balance'));
    //$cols = array(0, 80, 100, 150, 210, 280, 340, 400, 450, 510, 570);
    $cols = array(0, 65, 105, 125, 175, 230, 290, 345, 405, 465, 525);
    //------------0--1---2---3----4----5----6----7----8----9----10-------
    //-----------------------dim1-dim2-----------------------------------
    //-----------------------dim1----------------------------------------
    //-------------------------------------------------------------------
    $aligns = array('left', 'left', 'left', 'center', 'left', 'left', 'left', 'right', 'right', 'right', 'right');
    $headers = array(_('Account Name'), '', '', '', '', '', _('Debit'), _('Credit'), '', _('Balance'));
    $params = array(0 => $comments, 1 => array('text' => _('Period'), 'from' => $from, 'to' => $to), 2 => array('text' => _('Accounts'), 'from' => $fromacc, 'to' => $fromacc));
    if ($orientation == 'L') {
        recalculate_cols($cols);
    }
    $rep->SetHeaderType('Header_custom');
    $rep->Font();
    $rep->Info($params, $cols, $headers, $aligns);
    $rep->NewPage();
    $accounts = get_gl_accounts($fromacc, $fromacc);
    while ($account = db_fetch($accounts)) {
        if (is_account_balancesheet($account["account_code"])) {
            $begin = "";
        } else {
            $begin = get_fiscalyear_begin_for_date($from);
            if (date1_greater_date2($begin, $from)) {
                $begin = $from;
            }
            $begin = add_days($begin, -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, 4, $account['account_code'] . " " . $account['account_name'], -2);
        $rep->TextCol(4, 6, _('Opening Balance'));
        if ($prev_balance > 0.0) {
            $rep->AmountCol(7, 8, abs($prev_balance), $dec);
        } else {
            $rep->AmountCol(8, 9, abs($prev_balance), $dec);
        }
        $rep->Font();
        $total = $prev_balance;
        $rep->NewLine(2);
        if ($rows > 0) {
            $previous = '';
            while ($myrow = db_fetch($trans)) {
                $total += $myrow['amount'];
                $txt = payment_person_name($myrow["person_type_id"], $myrow["person_id"], false);
                $current = $txt;
                $memo = $myrow['memo_'];
                if ($txt != "") {
                    if ($previous == $current) {
                        $txt = '';
                    } else {
                        $rep->NewLine(1);
                        $rep->Line($rep->row - $rep->lineHeight + 4);
                        $rep->NewLine(2, 0);
                        $rep->TextCol(3, 8, $txt, -2);
                        $rep->Line($rep->row - $rep->lineHeight + 4);
                        $rep->NewLine(2, 1);
                        $rep->NewLine(1);
                    }
                    $previous = $current;
                }
                $rep->TextCol(0, 3, $systypes_array[$myrow["type"]], -2);
                $rep->DateCol(4, 6, $myrow["tran_date"], true);
                if ($myrow['amount'] > 0.0) {
                    $rep->AmountCol(6, 7, abs($myrow['amount']), $dec);
                } else {
                    $rep->AmountCol(7, 8, abs($myrow['amount']), $dec);
                }
                $rep->TextCol(8, 10, number_format2($total, $dec));
                $rep->NewLine();
                if ($rep->row < $rep->bottomMargin + $rep->lineHeight) {
                    $rep->Line($rep->row - 2);
                    $rep->NewPage();
                }
            }
            $rep->NewLine();
        }
        $rep->Font('bold');
        $rep->TextCol(4, 6, _("Ending Balance"));
        if ($total > 0.0) {
            $rep->AmountCol(7, 8, abs($total), $dec);
        } else {
            $rep->AmountCol(8, 9, abs($total), $dec);
        }
        $rep->Font();
    }
    $rep->End();
}