public function getTypes($rest)
 {
     $accttypes = get_account_types();
     $ret = array();
     while ($type = db_fetch($accttypes)) {
         $ret[] = array('id' => $type['id'], 'name' => $type['name'], 'class_id' => $type['class_id'], 'parent' => $type['parent']);
     }
     api_success_response(json_encode($ret));
 }
//-----------------------------------------------------------------------------------
if ($Mode == 'Delete') {
    if (can_delete($selected_id)) {
        delete_account_type($selected_id);
        display_notification(_('Selected account group has been deleted'));
    }
    $Mode = 'RESET';
}
if ($Mode == 'RESET') {
    $selected_id = "";
    $_POST['id'] = $_POST['name'] = '';
    unset($_POST['parent']);
    unset($_POST['class_id']);
}
//-----------------------------------------------------------------------------------
$result = get_account_types(check_value('show_inactive'));
start_form();
start_table(TABLESTYLE);
$th = array(_("Group ID"), _("Group Name"), _("Subgroup Of"), _("Class"), "", "");
inactive_control_column($th);
table_header($th);
$k = 0;
while ($myrow = db_fetch($result)) {
    alt_table_row_color($k);
    $bs_text = get_account_class_name($myrow["class_id"]);
    if ($myrow["parent"] == '-1') {
        $parent_text = "";
    } else {
        $parent_text = get_account_type_name($myrow["parent"]);
    }
    label_cell($myrow["id"]);
function print_annual_balance_breakdown_detail()
{
    global $path_to_root, $date_system;
    $dim = get_company_pref('use_dimension');
    $dimension = $dimension2 = 0;
    if ($dim == 2) {
        $date = $_POST['PARAM_0'];
        $dimension = $_POST['PARAM_1'];
        $dimension2 = $_POST['PARAM_2'];
        $comments = $_POST['PARAM_3'];
        $destination = $_POST['PARAM_4'];
    } else {
        if ($dim == 1) {
            $date = $_POST['PARAM_0'];
            $dimension = $_POST['PARAM_1'];
            $comments = $_POST['PARAM_3'];
            $destination = $_POST['PARAM_4'];
        } else {
            $date = $_POST['PARAM_0'];
            $comments = $_POST['PARAM_3'];
            $destination = $_POST['PARAM_4'];
        }
    }
    if ($destination) {
        include_once $path_to_root . "/reporting/includes/excel_report.inc";
    } else {
        include_once $path_to_root . "/reporting/includes/pdf_report.inc";
    }
    $title = _("Annual Balance Breakdown - Detailed");
    $output_filename = "AnnualBalanceBreakDownDetail";
    $fontsize = 7;
    $page_size = user_pagesize();
    $page_orientation = 'L';
    $margins = array('top' => 30, 'bottom' => 34, 'left' => 16, 'right' => 10);
    $excelColWidthFactor = 5;
    $rep = new FrontReport($title, $output_filename, $page_size, $fontsize, $page_orientation, $margins, $excelColWidthFactor);
    $enddate = end_month($date);
    $dec = user_price_dec();
    // Lay out the columns for this report
    //$cols2 = array(0, 70, 127, 184, 232, 280, 328, 376, 424, 472, 520, 568, 616, 664, 712, 760);
    //-------------0--1---2----3----4----5----6----7----8----9----10---11---12---13---14---15-
    $cols2 = array(0 => 0, 70);
    $endline = $rep->endLine - 20;
    $wi = ($endline - $cols2[1]) / 12;
    // 12 amount columns
    for ($i = 2; $i < 15; $i++) {
        $cols2[$i] = $cols2[$i - 1] + $wi;
    }
    $cols = $cols2;
    //----------------------------------------------------------------------------------------
    $aligns2 = array('left', 'right', 'right', 'right', 'right', 'right', 'right', 'right', 'right', 'right', 'right', 'right', 'right');
    $headers2 = array();
    //$cols = array(0, 70, 127, 184, 232, 280, 328, 376, 424, 472, 520, 568, 616, 664, 712, 760);
    //-------------0--1---2----3----4----5----6----7----8----9----10---11---12---13---14---15-
    //----------------------------------------------------------------------------------------
    $aligns = array('left', 'right', 'right', 'right', 'right', 'right', 'right', 'right', 'right', 'right', 'right', 'right', 'right');
    $headers = array();
    $date = begin_month($date);
    $date = add_months($date, -11);
    list($da, $mo, $yr) = explode_date_to_dmy($date);
    if ($date_system == 1) {
        list($yr, $mo, $da) = jalali_to_gregorian($yr, $mo, $da);
    } elseif ($date_system == 2) {
        list($yr, $mo, $da) = islamic_to_gregorian($yr, $mo, $da);
    }
    $headers2[0] = 'Account';
    $headers[0] = '';
    for ($i = 0; $i < 12; $i++) {
        $header_row[$i] = $rep->DatePrettyPrint($date, 0, 1);
        // Wrap at space between month & year
        $wrap_point = strpos($header_row[$i], ' ');
        if ($wrap_point) {
            $headers2[] = substr($header_row[$i], 0, $wrap_point);
            $headers[] = substr($header_row[$i], $wrap_point + 1);
        } else {
            $headers2[] = '';
            $headers[] = $header_row[$i];
        }
        $date = add_months($date, 1);
    }
    /*
    $header_row[] = "Fiscal Year Begin";
    $header_row[] = "Fiscal YTD";
    for ($i = 12; $i < 14; $i++)
    {
       	$wrapped_header_text = $rep->TextWrapCalc($header_row[$i], $cols[$i+2] - $cols[$i+1], true);
       	$headers2[] = trim($wrapped_header_text[0]);
       	$headers[] = trim($wrapped_header_text[1]);
    }
    */
    if ($dim == 2) {
        $params = array(0 => $comments, 1 => array('text' => _("Report Period"), 'from' => '', 'to' => $rep->DatePrettyPrint($enddate)), 2 => array('text' => '', 'from' => '', 'to' => ''), 3 => array('text' => '', 'from' => '', 'to' => ''), 4 => array('text' => _("Dimension 1"), 'from' => get_dimension_string($dimension), 'to' => ''), 5 => array('text' => _("Dimension 2"), 'from' => get_dimension_string($dimension2), 'to' => ''));
    } else {
        if ($dim == 1) {
            $params = array(0 => $comments, 1 => array('text' => _("Report Period"), 'from' => '', 'to' => $rep->DatePrettyPrint($enddate)), 2 => array('text' => '', 'from' => '', 'to' => ''), 3 => array('text' => _('Dimension'), 'from' => get_dimension_string($dimension), 'to' => ''));
        } else {
            $params = array(0 => $comments, 1 => array('text' => _("Report Period"), 'from' => '', 'to' => $rep->DatePrettyPrint($enddate)));
        }
    }
    // Company logo setting
    $companylogoenable = true;
    // Footer Settings
    $footerenable = true;
    $footertext = _('For Management Purposes Only');
    $rep->Font();
    $rep->SetFillColor(240, 240, 240);
    $rep->scaleLogoWidth = true;
    $rep->lineHeight = 8;
    $rep->SetCellPadding(4);
    $rep->Info($params, $cols, $headers, $aligns, $cols2, $headers2, $aligns2, $companylogoenable, $footerenable, $footertext);
    $rep->SetHeaderType('Header3');
    $rep->NewPage();
    $rep->SetDrawColor(0, 0, 0);
    $rep->SetLineWidth(0.1);
    $sales = array(1 => 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
    $classresult = get_account_classes(false, 1);
    while ($class = db_fetch($classresult)) {
        $ctotal = array(1 => 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
        $convert = get_class_type_convert($class["ctype"]);
        //Print Class Name
        $rep->NewLine();
        $oldcMargin = $rep->GetCellPadding();
        $rep->SetCellPadding(0);
        $oldFontSize = $rep->fontSize;
        $rep->fontSize = 12;
        $rep->Font('b');
        $rep->TextCol(0, 5, $class["class_name"]);
        $rep->Font();
        $rep->fontSize = $oldFontSize;
        $rep->SetCellPadding($oldcMargin);
        $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"], $yr, $mo, $convert, $dec, $rep, $dimension, $dimension2);
            for ($i = 1; $i <= 12; $i++) {
                $ctotal[$i] += $classtotal[$i];
            }
        }
        //Print Class Summary
        $rep->row += 5;
        $rep->Line($rep->row - 3);
        $rep->NewLine();
        $rep->Font('b');
        $oldcMargin = $rep->GetCellPadding();
        $rep->SetCellPadding(0);
        $fill = 0;
        $rep->TextCol(0, 1, _('Total') . " " . $class["class_name"], 0, 4, 0, $fill, NULL, 1);
        $rep->SetCellPadding($oldcMargin);
        for ($i = 1; $i <= 12; $i++) {
            $rep->AmountCol2($i, $i + 1, $ctotal[$i] * $convert, $dec, 0, 4, 0, $fill, NULL, 1, true);
            $sales[$i] += $ctotal[$i];
        }
        $rep->Font();
        $rep->NewLine(2);
    }
    $rep->Font('bold');
    $oldcMargin = $rep->GetCellPadding();
    $rep->SetCellPadding(0);
    $rep->TextCol(0, 1, _('Net Assets (Liabilities)'), 0, 4, 0, $fill, NULL, 1);
    $rep->SetCellPadding($oldcMargin);
    for ($i = 1; $i <= 12; $i++) {
        $rep->AmountCol2($i, $i + 1, $sales[$i] * -1, $dec, 0, 4, 0, $fill, NULL, 1, true);
    }
    $rep->Font();
    $rep->NewLine();
    $rep->Line($rep->row);
    $rep->NewLine(2);
    $calc = array(1 => 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
    $total = array(1 => 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
    $classresult = get_account_classes(false, 0);
    while ($class = db_fetch($classresult)) {
        $convert = get_class_type_convert($class["ctype"]);
        //Print Class Name
        $oldcMargin = $rep->GetCellPadding();
        $rep->SetCellPadding(0);
        $rep->Font('b');
        $rep->TextCol(0, 1, _("Total ") . $class["class_name"], 0, 4, 0, $fill, NULL, 1);
        $rep->SetCellPadding($oldcMargin);
        $typeresult = get_account_types(false, $class['cid']);
        while ($accounttype = db_fetch($typeresult)) {
            $result = get_gl_accounts(null, null, $accounttype['id']);
            while ($account = db_fetch($result)) {
                $bal = getPeriods($yr, $mo, $account["account_code"], $dimension, $dimension2);
                $balance = array(1 => $bal['per01'], $bal['per02'], $bal['per03'], $bal['per04'], $bal['per05'], $bal['per06'], $bal['per07'], $bal['per08'], $bal['per09'], $bal['per10'], $bal['per11'], $bal['per12']);
                for ($i = 1; $i <= 12; $i++) {
                    $total[$i] += $balance[$i];
                }
            }
        }
        for ($i = 1; $i <= 12; $i++) {
            $rep->AmountCol2($i, $i + 1, $total[$i] * $convert, $dec, 0, 4, 0, $fill, NULL, 1, true);
            $calc[$i] += $total[$i];
            $total[$i] = 0;
        }
        $rep->NewLine(2);
    }
    $oldcMargin = $rep->GetCellPadding();
    $rep->SetCellPadding(0);
    $rep->TextCol(0, 1, _('Total Profit/Loss'), 0, 4, 0, $fill, NULL, 1);
    $rep->SetCellPadding($oldcMargin);
    for ($i = 1; $i <= 12; $i++) {
        $rep->AmountCol2($i, $i + 1, -$calc[$i], $dec, 0, 4, 0, $fill, NULL, 1, true);
        // no convert
    }
    $rep->Font();
    $rep->End();
}
Example #4
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 #5
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 #6
0
function print_trial_balance()
{
    global $path_to_root;
    global $pdeb, $pcre, $cdeb, $ccre, $tdeb, $tcre, $pbal, $cbal, $tbal;
    $dim = get_company_pref('use_dimension');
    $dimension = $dimension2 = 0;
    $from = $_POST['PARAM_0'];
    $to = $_POST['PARAM_1'];
    $zero = $_POST['PARAM_2'];
    $balances = $_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';
    $dec = user_price_dec();
    $cols2 = array(0, 50, 190, 310, 430, 530);
    //-------------0--1---2----3----4----5--
    $headers2 = array('', '', _('Brought Forward'), _('This Period'), _('Balance'));
    $aligns2 = array('left', 'left', 'left', 'left', 'left');
    $cols = array(0, 50, 150, 210, 270, 330, 390, 450, 510, 570);
    //------------0--1---2----3----4----5----6----7----8--
    $headers = array(_('Account'), _('Account Name'), _('Debit'), _('Credit'), _('Debit'), _('Credit'), _('Debit'), _('Credit'));
    $aligns = array('left', 'left', 'right', 'right', 'right', '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' => ''));
    } 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' => ''));
        } else {
            $params = array(0 => $comments, 1 => array('text' => _('Period'), 'from' => $from, 'to' => $to));
        }
    }
    $rep = new FrontReport(_('Trial Balance'), "TrialBalance", user_pagesize(), 9, $orientation);
    if ($orientation == 'L') {
        recalculate_cols($cols);
        recalculate_cols($cols2);
    }
    $rep->Font();
    $rep->Info($params, $cols, $headers, $aligns, $cols2, $headers2, $aligns2);
    $rep->NewPage();
    $classresult = get_account_classes(false);
    while ($class = db_fetch($classresult)) {
        $rep->Font('bold');
        $rep->TextCol(0, 1, $class['cid']);
        $rep->TextCol(1, 4, $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)) {
            display_type($accounttype["id"], $accounttype["name"], $dec, $rep, $from, $to, $zero, $balances, $dimension, $dimension2);
        }
        $rep->NewLine();
    }
    $rep->Line($rep->row);
    $rep->NewLine();
    $rep->Font('bold');
    if ($balances == 0) {
        $rep->TextCol(0, 2, _("Total"));
        $rep->AmountCol(2, 3, $pdeb, $dec);
        $rep->AmountCol(3, 4, $pcre, $dec);
        $rep->AmountCol(4, 5, $cdeb, $dec);
        $rep->AmountCol(5, 6, $ccre, $dec);
        $rep->AmountCol(6, 7, $tdeb, $dec);
        $rep->AmountCol(7, 8, $tcre, $dec);
        $rep->NewLine();
    }
    $rep->TextCol(0, 2, _("Ending Balance"));
    if ($pbal >= 0.0) {
        $rep->AmountCol(2, 3, $pbal, $dec);
    } else {
        $rep->AmountCol(3, 4, abs($pbal), $dec);
    }
    if ($cbal >= 0.0) {
        $rep->AmountCol(4, 5, $cbal, $dec);
    } else {
        $rep->AmountCol(5, 6, abs($cbal), $dec);
    }
    if ($tbal >= 0.0) {
        $rep->AmountCol(6, 7, $tbal, $dec);
    } else {
        $rep->AmountCol(7, 8, abs($tbal), $dec);
    }
    $rep->NewLine();
    $rep->Line($rep->row + 10);
    if (($pbal = round2($pbal, $dec)) != 0.0 && $dimension == 0 && $dimension2 == 0) {
        $rep->NewLine(2);
        $rep->Font();
        $rep->TextCol(0, 8, _("The Opening Balance is not in balance, probably due to a non closed Previous Fiscalyear."));
    }
    $rep->End();
}
Example #7
0
function print_Chart_of_Accounts()
{
    global $path_to_root;
    $showbalance = $_POST['PARAM_0'];
    $comments = $_POST['PARAM_1'];
    $orientation = $_POST['PARAM_2'];
    $destination = $_POST['PARAM_3'];
    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';
    $dec = 0;
    $cols = array(0, 50, 300, 425, 500);
    $headers = array(_('Account'), _('Account Name'), _('Account Code'), _('Balance'));
    $aligns = array('left', 'left', 'left', 'right');
    $params = array(0 => $comments);
    $rep = new FrontReport(_('Chart of Accounts'), "ChartOfAccounts", user_pagesize(), 9, $orientation);
    if ($orientation == 'L') {
        recalculate_cols($cols);
    }
    $rep->Font();
    $rep->Info($params, $cols, $headers, $aligns);
    $rep->NewPage();
    $classresult = get_account_classes(false);
    while ($class = db_fetch($classresult)) {
        $rep->Font('bold');
        $rep->TextCol(0, 1, $class['cid']);
        $rep->TextCol(1, 4, $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)) {
            display_type($accounttype["id"], $accounttype["name"], $dec, $rep, $showbalance, 0);
        }
        $rep->NewLine();
    }
    $rep->Line($rep->row + 10);
    $rep->End();
}
Example #8
0
function print_balance_sheet()
{
    global $path_to_root;
    $dim = get_company_pref('use_dimension');
    $dimension = $dimension2 = 0;
    $from = $_POST['PARAM_0'];
    $to = $_POST['PARAM_1'];
    if ($dim == 2) {
        $dimension = $_POST['PARAM_2'];
        $dimension2 = $_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 {
        if ($dim == 1) {
            $dimension = $_POST['PARAM_2'];
            $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'];
        } else {
            $tags = isset($_POST['PARAM_2']) ? $_POST['PARAM_2'] : -1;
            $decimals = $_POST['PARAM_3'];
            $graphics = $_POST['PARAM_4'];
            $comments = $_POST['PARAM_5'];
            $orientation = $_POST['PARAM_6'];
            $destination = $_POST['PARAM_7'];
        }
    }
    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();
    }
    $cols = array(0, 50, 200, 350, 425, 500);
    //------------0--1---2----3----4----5--
    $headers = array(_('Account'), _('Account Name'), _('Open Balance'), _('Period'), _('Close Balance'));
    $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' => ''));
        }
    }
    $rep = new FrontReport(_('Balance Sheet'), "BalanceSheet", user_pagesize(), 9, $orientation);
    if ($orientation == 'L') {
        recalculate_cols($cols);
    }
    $rep->Font();
    $rep->Info($params, $cols, $headers, $aligns);
    $rep->NewPage();
    $calc_open = $calc_period = 0.0;
    $equity_open = $equity_period = 0.0;
    $liability_open = $liability_period = 0.0;
    $econvert = $lconvert = 0;
    $classresult = get_account_classes(false, 1);
    while ($class = db_fetch($classresult)) {
        $class_open_total = 0;
        $class_period_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, $convert, $dec, $rep, $dimension, $dimension2, $tags, $pg, $graphics);
            $class_open_total += $classtotal[0];
            $class_period_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_open_total * $convert, $dec);
        $rep->AmountCol(3, 4, $class_period_total * $convert, $dec);
        $rep->AmountCol(4, 5, ($class_open_total + $class_period_total) * $convert, $dec);
        $rep->Font();
        $rep->NewLine(2);
        $calc_open += $class_open_total;
        $calc_period += $class_period_total;
        if ($class['ctype'] == CL_EQUITY) {
            $equity_open += $class_open_total;
            $equity_period += $class_period_total;
            $econvert = $convert;
        } elseif ($class['ctype'] == CL_LIABILITIES) {
            $liability_open += $class_open_total;
            $liability_period += $class_period_total;
            $lconvert = $convert;
        }
    }
    $rep->Font();
    $rep->TextCol(0, 2, _('Calculated Return'));
    if ($lconvert == 1) {
        $calc_open *= -1;
        $calc_period *= -1;
    }
    $rep->AmountCol(2, 3, $calc_open, $dec);
    // never convert
    $rep->AmountCol(3, 4, $calc_period, $dec);
    $rep->AmountCol(4, 5, $calc_open + $calc_period, $dec);
    $rep->NewLine(2);
    $rep->Font('bold');
    $rep->TextCol(0, 2, _('Total') . " " . _('Liabilities') . _(' and ') . _('Equities'));
    $topen = $equity_open * $econvert + $liability_open * $lconvert + $calc_open;
    $tperiod = $equity_period * $econvert + $liability_period * $lconvert + $calc_period;
    $tclose = $topen + $tperiod;
    $rep->AmountCol(2, 3, $topen, $dec);
    $rep->AmountCol(3, 4, $tperiod, $dec);
    $rep->AmountCol(4, 5, $tclose, $dec);
    $rep->Font();
    $rep->NewLine();
    $rep->Line($rep->row);
    if ($graphics) {
        $pg->x[] = _('Calculated Return');
        $pg->y[] = abs($calc_open);
        $pg->z[] = abs($calc_period);
        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();
}
Example #9
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 . ')');
    }
}
Example #10
0
function print_annual_expense_breakdown()
{
    global $path_to_root, $date_system;
    $dim = get_company_pref('use_dimension');
    $dimension = $dimension2 = 0;
    if ($dim == 2) {
        $year = $_POST['PARAM_0'];
        $dimension = $_POST['PARAM_1'];
        $dimension2 = $_POST['PARAM_2'];
        $tags = isset($_POST['PARAM_3']) ? $_POST['PARAM_3'] : -1;
        $comments = $_POST['PARAM_4'];
        $orientation = $_POST['PARAM_5'];
        $destination = $_POST['PARAM_6'];
    } else {
        if ($dim == 1) {
            $year = $_POST['PARAM_0'];
            $dimension = $_POST['PARAM_1'];
            $tags = isset($_POST['PARAM_2']) ? $_POST['PARAM_2'] : -1;
            $comments = $_POST['PARAM_3'];
            $orientation = $_POST['PARAM_4'];
            $destination = $_POST['PARAM_5'];
        } else {
            $year = $_POST['PARAM_0'];
            $tags = isset($_POST['PARAM_1']) ? $_POST['PARAM_1'] : -1;
            $comments = $_POST['PARAM_2'];
            $orientation = $_POST['PARAM_3'];
            $destination = $_POST['PARAM_4'];
        }
    }
    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';
    $dec = 1;
    //$pdec = user_percent_dec();
    $cols = array(0, 40, 150, 180, 210, 240, 270, 300, 330, 360, 390, 420, 450, 480, 510);
    //------------0--1---2----3----4----5----6----7----8----10---11---12---13---14---15-
    //$yr = date('Y');
    //$mo = date('m'):
    // from now
    $sql = "SELECT begin, end, YEAR(end) AS yr, MONTH(end) AS mo FROM " . TB_PREF . "fiscal_year WHERE id=" . db_escape($year);
    $result = db_query($sql, "could not get fiscal year");
    $row = db_fetch($result);
    $year = sql2date($row['begin']) . " - " . sql2date($row['end']);
    $yr = $row['yr'];
    $mo = $row['mo'];
    $da = 1;
    if ($date_system == 1) {
        list($yr, $mo, $da) = jalali_to_gregorian($yr, $mo, $da);
    } elseif ($date_system == 2) {
        list($yr, $mo, $da) = islamic_to_gregorian($yr, $mo, $da);
    }
    $per12 = strftime('%b', mktime(0, 0, 0, $mo, $da, $yr));
    $per11 = strftime('%b', mktime(0, 0, 0, $mo - 1, $da, $yr));
    $per10 = strftime('%b', mktime(0, 0, 0, $mo - 2, $da, $yr));
    $per09 = strftime('%b', mktime(0, 0, 0, $mo - 3, $da, $yr));
    $per08 = strftime('%b', mktime(0, 0, 0, $mo - 4, $da, $yr));
    $per07 = strftime('%b', mktime(0, 0, 0, $mo - 5, $da, $yr));
    $per06 = strftime('%b', mktime(0, 0, 0, $mo - 6, $da, $yr));
    $per05 = strftime('%b', mktime(0, 0, 0, $mo - 7, $da, $yr));
    $per04 = strftime('%b', mktime(0, 0, 0, $mo - 8, $da, $yr));
    $per03 = strftime('%b', mktime(0, 0, 0, $mo - 9, $da, $yr));
    $per02 = strftime('%b', mktime(0, 0, 0, $mo - 10, $da, $yr));
    $per01 = strftime('%b', mktime(0, 0, 0, $mo - 11, $da, $yr));
    $headers = array(_('Account'), _('Account Name'), $per01, $per02, $per03, $per04, $per05, $per06, $per07, $per08, $per09, $per10, $per11, $per12);
    $aligns = array('left', 'left', 'right', 'right', 'right', 'right', 'right', 'right', 'right', 'right', 'right', 'right', 'right', 'right');
    if ($dim == 2) {
        $params = array(0 => $comments, 1 => array('text' => _("Year"), 'from' => $year, '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' => ''), 5 => array('text' => _('Info'), 'from' => _('Amounts in thousands'), 'to' => ''));
    } else {
        if ($dim == 1) {
            $params = array(0 => $comments, 1 => array('text' => _("Year"), 'from' => $year, 'to' => ''), 2 => array('text' => _('Dimension'), 'from' => get_dimension_string($dimension), 'to' => ''), 3 => array('text' => _('Tags'), 'from' => get_tag_names($tags), 'to' => ''), 4 => array('text' => _('Info'), 'from' => _('Amounts in thousands'), 'to' => ''));
        } else {
            $params = array(0 => $comments, 1 => array('text' => _("Year"), 'from' => $year, 'to' => ''), 2 => array('text' => _('Tags'), 'from' => get_tag_names($tags), 'to' => ''), 3 => array('text' => _('Info'), 'from' => _('Amounts in thousands'), 'to' => ''));
        }
    }
    $rep = new FrontReport(_('Annual Expense Breakdown'), "AnnualBreakDown", user_pagesize(), 9, $orientation);
    if ($orientation == 'L') {
        recalculate_cols($cols);
    }
    $rep->Font();
    $rep->Info($params, $cols, $headers, $aligns);
    $rep->NewPage();
    $sales = array(1 => 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
    $classresult = get_account_classes(false, 0);
    while ($class = db_fetch($classresult)) {
        $ctotal = array(1 => 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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"], $yr, $mo, $convert, $dec, $rep, $dimension, $dimension2, $tags);
            for ($i = 1; $i <= 12; $i++) {
                $ctotal[$i] += $classtotal[$i];
            }
        }
        //Print Class Summary
        $rep->row += 6;
        $rep->Line($rep->row);
        $rep->NewLine();
        $rep->Font('bold');
        $rep->TextCol(0, 2, _('Total') . " " . $class["class_name"]);
        for ($i = 1; $i <= 12; $i++) {
            $rep->AmountCol($i + 1, $i + 2, $ctotal[$i] * $convert, $dec);
            $sales[$i] += $ctotal[$i];
        }
        $rep->Font();
        $rep->NewLine(2);
    }
    $rep->Font('bold');
    $rep->TextCol(0, 2, _("Calculated Return"));
    for ($i = 1; $i <= 12; $i++) {
        $rep->AmountCol($i + 1, $i + 2, $sales[$i] * -1, $dec);
    }
    $rep->Font();
    $rep->NewLine();
    $rep->Line($rep->row);
    $rep->NewLine(2);
    $rep->End();
}
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 . ')');
    }
}
Example #12
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();
}
Example #13
0
    $myrow = db_fetch_row($result);
    if ($myrow[0] > 0) {
        display_error(tr("Cannot delete this account group because GL account groups have been created referring to it."));
        return false;
    }
    return true;
}
//-----------------------------------------------------------------------------------
if (isset($_GET['delete'])) {
    if (can_delete($selected_id)) {
        delete_account_type($selected_id);
        meta_forward($_SERVER['PHP_SELF']);
    }
}
//-----------------------------------------------------------------------------------
$result = get_account_types();
start_table($table_style);
$th = array(tr("Name"), tr("Subgroup Of"), tr("Class Type"), "", "");
table_header($th);
$k = 0;
while ($myrow = db_fetch($result)) {
    alt_table_row_color($k);
    $bs_text = get_account_class_name($myrow["class_id"]);
    if ($myrow["parent"] == reserved_words::get_any_numeric()) {
        $parent_text = "";
    } else {
        $parent_text = get_account_type_name($myrow["parent"]);
    }
    label_cell($myrow["name"]);
    label_cell($parent_text);
    label_cell($bs_text);