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(); }
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(); }
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(); }
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(); }
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 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(); }