function display_bank_trans($yr, $mo, &$dec, &$rep, $dimension, $dimension2, $date)
{
    global $bank_account_types;
    $total = array(1 => 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
    $fill = 0;
    //Get Accounts directly under this group/type
    $result = get_bank_accounts();
    while ($account = db_fetch($result)) {
        $ctotal = array(1 => 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
        $bal = getPeriods($yr, $mo, $account["id"], $dimension, $dimension2, true);
        $per = getPeriods($yr, $mo, $account["id"], $dimension, $dimension2);
        //_vd($bal);
        $is_home = is_company_currency($account['bank_curr_code']);
        $rep->row += 4;
        $rep->NewLine();
        $oldcMargin = $rep->GetCellPadding();
        $rep->SetCellPadding(0);
        $rep->SetCellPadding($oldcMargin);
        $rep->row += 1;
        $rep->Line($rep->row - 4);
        $rep->NewLine();
        $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'], $bal['ytd'], $bal['mon12']);
        $period = array(1 => $per['per01'], $per['per02'], $per['per03'], $per['per04'], $per['per05'], $per['per06'], $per['per07'], $per['per08'], $per['per09'], $per['per10'], $per['per11'], $per['per12'], $per['ytd'], $per['mon12']);
        $rep->Font('b');
        $rep->TextCol(0, 3, $account['bank_account_name'] . " - " . $bank_account_types[$account['account_type']], 0, 4, 0, $fill, NULL, 1);
        $rep->Font();
        $rep->NewLine(2);
        $rep->TextCol(0, 1, _("Opening Balance"), 0, 4, 0, $fill, NULL, 1);
        for ($i = 1; $i <= 14; $i++) {
            if (!$is_home) {
                $balance[$i] = to_home_currency($balance[$i], $account['bank_curr_code'], $date);
            }
            $rep->AmountCol2($i, $i + 1, $balance[$i], $dec, 0, 4, 0, $fill, NULL, 1, true);
            $ctotal[$i] += $balance[$i];
        }
        $rep->NewLine(2);
        $rep->TextCol(0, 1, _("Net Cash Value"), 0, 4, 0, $fill, NULL, 1);
        for ($i = 1; $i <= 14; $i++) {
            if (!$is_home) {
                $period[$i] = to_home_currency($period[$i], $account['bank_curr_code'], $date);
            }
            $rep->AmountCol2($i, $i + 1, $period[$i], $dec, 0, 4, 0, $fill, NULL, 1, true);
            $ctotal[$i] += $period[$i];
        }
        $fill = !$fill;
        $rep->NewLine(2);
        $rep->TextCol(0, 1, _("Closing Balance"), 0, 4, 0, $fill, NULL, 1);
        for ($i = 1; $i <= 14; $i++) {
            $rep->AmountCol2($i, $i + 1, $ctotal[$i], $dec, 0, 4, 0, $fill, NULL, 1, true);
            $total[$i] += $ctotal[$i];
        }
    }
    $rep->Line($rep->row - 8);
    $rep->NewLine(2);
    $rep->TextCol(0, 1, _("Total Bank Accounts"), 0, 4, 0, $fill, NULL, 1);
    for ($i = 1; $i <= 14; $i++) {
        $rep->AmountCol2($i, $i + 1, $total[$i], $dec, 0, 4, 0, $fill, NULL, 1, true);
    }
}
Example #2
0
function print_inventory_planning()
{
    global $path_to_root;
    $category = $_POST['PARAM_0'];
    $location = $_POST['PARAM_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';
    if ($category == ALL_NUMERIC) {
        $category = 0;
    }
    if ($category == 0) {
        $cat = _('All');
    } else {
        $cat = get_category_name($category);
    }
    if ($location == ALL_TEXT) {
        $location = 'all';
    }
    if ($location == 'all') {
        $loc = _('All');
    } else {
        $loc = get_location_name($location);
    }
    $cols = array(0, 50, 150, 180, 210, 240, 270, 300, 330, 390, 435, 480, 525);
    $per0 = strftime('%b', mktime(0, 0, 0, date('m'), 1, date('Y')));
    $per1 = strftime('%b', mktime(0, 0, 0, date('m') - 1, 1, date('Y')));
    $per2 = strftime('%b', mktime(0, 0, 0, date('m') - 2, 1, date('Y')));
    $per3 = strftime('%b', mktime(0, 0, 0, date('m') - 3, 1, date('Y')));
    $per4 = strftime('%b', mktime(0, 0, 0, date('m') - 4, 1, date('Y')));
    $headers = array(_('Category'), '', $per4, $per3, $per2, $per1, $per0, '3*M', _('QOH'), _('Cust Ord'), _('Supp Ord'), _('Sugg Ord'));
    $aligns = array('left', 'left', 'right', 'right', 'right', 'right', 'right', 'right', 'right', 'right', 'right', 'right');
    $params = array(0 => $comments, 1 => array('text' => _('Category'), 'from' => $cat, 'to' => ''), 2 => array('text' => _('Location'), 'from' => $loc, 'to' => ''));
    $rep = new FrontReport(_('Inventory Planning Report'), "InventoryPlanning", user_pagesize(), 9, $orientation);
    if ($orientation == 'L') {
        recalculate_cols($cols);
    }
    $rep->Font();
    $rep->Info($params, $cols, $headers, $aligns);
    $rep->NewPage();
    $res = getTransactions($category, $location);
    $catt = '';
    while ($trans = db_fetch($res)) {
        if ($catt != $trans['cat_description']) {
            if ($catt != '') {
                $rep->Line($rep->row - 2);
                $rep->NewLine(2, 3);
            }
            $rep->TextCol(0, 1, $trans['category_id']);
            $rep->TextCol(1, 2, $trans['cat_description']);
            $catt = $trans['cat_description'];
            $rep->NewLine();
        }
        if ($location == 'all') {
            $loc_code = "";
        } else {
            $loc_code = $location;
        }
        $custqty = get_demand_qty($trans['stock_id'], $loc_code);
        $custqty += get_demand_asm_qty($trans['stock_id'], $loc_code);
        $suppqty = get_on_porder_qty($trans['stock_id'], $loc_code);
        $suppqty += get_on_worder_qty($trans['stock_id'], $loc_code);
        $period = getPeriods($trans['stock_id'], $trans['loc_code']);
        $rep->NewLine();
        $dec = get_qty_dec($trans['stock_id']);
        $rep->TextCol(0, 1, $trans['stock_id']);
        $rep->TextCol(1, 2, $trans['description'] . ($trans['inactive'] == 1 ? " (" . _("Inactive") . ")" : ""), -1);
        $rep->AmountCol(2, 3, $period['prd0'], $dec);
        $rep->AmountCol(3, 4, $period['prd1'], $dec);
        $rep->AmountCol(4, 5, $period['prd2'], $dec);
        $rep->AmountCol(5, 6, $period['prd3'], $dec);
        $rep->AmountCol(6, 7, $period['prd4'], $dec);
        $MaxMthSales = Max($period['prd0'], $period['prd1'], $period['prd2'], $period['prd3']);
        $IdealStockHolding = $MaxMthSales * 3;
        $rep->AmountCol(7, 8, $IdealStockHolding, $dec);
        $rep->AmountCol(8, 9, $trans['qty_on_hand'], $dec);
        $rep->AmountCol(9, 10, $custqty, $dec);
        $rep->AmountCol(10, 11, $suppqty, $dec);
        $SuggestedTopUpOrder = $IdealStockHolding - $trans['qty_on_hand'] + $custqty - $suppqty;
        if ($SuggestedTopUpOrder < 0.0) {
            $SuggestedTopUpOrder = 0.0;
        }
        $rep->AmountCol(11, 12, $SuggestedTopUpOrder, $dec);
    }
    $rep->Line($rep->row - 4);
    $rep->NewLine();
    $rep->End();
}
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 print_inventory_planning()
{
    global $path_to_root;
    include_once $path_to_root . "reporting/includes/pdf_report.inc";
    $category = $_REQUEST['PARAM_0'];
    $location = $_REQUEST['PARAM_1'];
    $comments = $_REQUEST['PARAM_2'];
    $dec = user_qty_dec();
    if ($category == reserved_words::get_all_numeric()) {
        $category = 0;
    }
    if ($category == 0) {
        $cat = tr('All');
    } else {
        $cat = get_category_name($category);
    }
    if ($location == reserved_words::get_all()) {
        $location = 'all';
    }
    if ($location == 'all') {
        $loc = tr('All');
    } else {
        $loc = $location;
    }
    $cols = array(0, 50, 150, 180, 210, 240, 270, 300, 330, 390, 435, 480, 525);
    $per0 = strftime('%b', mktime(0, 0, 0, date('m'), date('d'), date('Y')));
    $per1 = strftime('%b', mktime(0, 0, 0, date('m') - 1, date('d'), date('Y')));
    $per2 = strftime('%b', mktime(0, 0, 0, date('m') - 2, date('d'), date('Y')));
    $per3 = strftime('%b', mktime(0, 0, 0, date('m') - 3, date('d'), date('Y')));
    $per4 = strftime('%b', mktime(0, 0, 0, date('m') - 4, date('d'), date('Y')));
    $headers = array(tr('Category'), '', $per4, $per3, $per2, $per1, $per0, '3*M', tr('QOH'), tr('Cust Ord'), tr('Supp Ord'), tr('Sugg Ord'));
    $aligns = array('left', 'left', 'right', 'right', 'right', 'right', 'right', 'right', 'right', 'right', 'right', 'right');
    $params = array(0 => $comments, 1 => array('text' => tr('Category'), 'from' => $cat, 'to' => ''), 2 => array('text' => tr('Location'), 'from' => $loc, 'to' => ''));
    $rep = new FrontReport(tr('Inventory Planning Report'), "InventoryPlanning.pdf", user_pagesize());
    $rep->Font();
    $rep->Info($params, $cols, $headers, $aligns);
    $rep->Header();
    $res = getTransactions($category, $location);
    $catt = '';
    while ($trans = db_fetch($res)) {
        if ($catt != $trans['cat_description']) {
            if ($catt != '') {
                $rep->Line($rep->row - 2);
                $rep->NewLine(2, 3);
            }
            $rep->TextCol(0, 1, $trans['category_id']);
            $rep->TextCol(1, 2, $trans['cat_description']);
            $catt = $trans['cat_description'];
            $rep->NewLine();
        }
        $custqty = getCustQty($trans['stock_id'], $trans['loc_code']);
        $custqty += getCustAsmQty($trans['stock_id'], $trans['loc_code']);
        $suppqty = getSuppQty($trans['stock_id'], $trans['loc_code']);
        $period = getPeriods($trans['stock_id'], $trans['loc_code']);
        $rep->NewLine();
        $rep->TextCol(0, 1, $trans['stock_id']);
        $rep->TextCol(1, 2, $trans['description']);
        $rep->TextCol(2, 3, number_format2($period['prd0'], $dec));
        $rep->TextCol(3, 4, number_format2($period['prd1'], $dec));
        $rep->TextCol(4, 5, number_format2($period['prd2'], $dec));
        $rep->TextCol(5, 6, number_format2($period['prd3'], $dec));
        $rep->TextCol(6, 7, number_format2($period['prd4'], $dec));
        $MaxMthSales = Max($period['prd0'], $period['prd1'], $period['prd2'], $period['prd3']);
        $IdealStockHolding = $MaxMthSales * 3;
        $rep->TextCol(7, 8, number_format2($IdealStockHolding, $dec));
        $rep->TextCol(8, 9, number_format2($trans['qty_on_hand'], $dec));
        $rep->TextCol(9, 10, number_format2($custqty, $dec));
        $rep->TextCol(10, 11, number_format2($suppqty, $dec));
        $SuggestedTopUpOrder = $IdealStockHolding - $trans['qty_on_hand'] + $custqty - $suppqty;
        if ($SuggestedTopUpOrder < 0.0) {
            $SuggestedTopUpOrder = 0.0;
        }
        $rep->TextCol(11, 12, number_format2($SuggestedTopUpOrder, $dec));
    }
    $rep->Line($rep->row - 4);
    $rep->End();
}
Example #5
0
//
define("NO_AUTH", 1);
require_once "overall.php";
// By default recalc only 1 period back.
if (!isset($_GET['back'])) {
    $_GET['back'] = 1;
}
list($to, $back, $period) = parseToBackPeriod($_GET, true);
if (is_numeric(@$_SERVER['argv'][2])) {
    $back = $_SERVER['argv'][2];
}
$fromId = intval(@$_GET['fromid']);
if (!$fromId) {
    $fromId = 0;
}
$periods = getPeriods();
$onlyPeriod = @$_SERVER['argv'][1];
if (!isset($periods[$onlyPeriod])) {
    $onlyPeriod = null;
}
if (isCgi()) {
    echo "<body>";
}
writeLogLine(($fromId ? "Continuing" : "Starting") . " recalculation.\n");
$items = $DB->select("SELECT * FROM item WHERE id > ? ORDER BY id", $fromId);
// ORDER BY id is IMPORTANT!
writeLogLine(sprintf("We have %d items left to process.\n\n", count($items)));
$hasError = false;
$t0 = microtime(true);
foreach ($items as $item) {
    foreach ($periods as $period => $periodName) {
Example #6
0
require_once "overall.php";
$params = $_POST + $_GET;
try {
    $apikey = @$params['apikey'];
    $allowedKeys = preg_split('/\\s+/s', trim(getSetting("apikeys", "")));
    if (!$apikey || !in_array($apikey, $allowedKeys)) {
        throw new Exception('Invalid "apikey" parameter');
    }
    $itemIds = trim(@$params['item_ids']);
    if (!$itemIds) {
        throw new Exception('Parameter "item_ids" must be specified and not empty');
    }
    $dataNames = trim(@$params['data_names']);
    $dataNames = $dataNames ? explode(TAGS_SEP, $dataNames) : array();
    $onlyPeriods = trim(@$params['periods']);
    $onlyPeriods = $onlyPeriods ? explode(TAGS_SEP, $onlyPeriods) : array();
    list($to, $back) = parseToBackPeriod($params);
    $result = array();
    foreach (getPeriods() as $period => $periodName) {
        if ($onlyPeriods && !in_array($period, $onlyPeriods)) {
            continue;
        }
        $result[$period] = generateTableData($to, $back, $period, $itemIds, $dataNames);
    }
    //	print_r($result);
    header("Content-Type: application/json");
    echo json_encode($result);
} catch (Exception $e) {
    header("Content-Type: text/plain");
    echo $e->getMessage();
}
Example #7
0
            } else {
                $_POST['item']['sql'] = "SELECT COUNT(*)\nFROM some_table\nWHERE created BETWEEN \$FROM AND \$TO\n";
            }
        }
    }
}
$SELECT_DSNS = array();
foreach ($DB->select("SELECT id, name FROM dsn ORDER BY name") as $row) {
    $SELECT_DSNS[$row['id']] = $row['name'];
}
$SELECT_ITEMS = array();
$seenArchived = 0;
foreach ($DB->select("SELECT id, name, archived FROM item ORDER BY archived, name") as $row) {
    if (!$seenArchived && $row['archived']) {
        $SELECT_ITEMS[0] = "";
    }
    $SELECT_ITEMS[$row['id']] = $row['name'];
}
$SELECT_PERIODS = getPeriods();
if (!$tables && $id) {
    $to = $DB->selectCell("SELECT MAX(created) FROM data WHERE item_id=?", $id);
    if (!$to) {
        $to = time();
    }
    foreach ($SELECT_PERIODS as $period => $periodName) {
        $data = generateTableData($to, $PREVIEW_TABLES_COLS, $period, $id);
        $tables[$periodName] = generateHtmlTableFromData($data, true);
    }
}
$title = $id ? 'Edit item <a href="' . htmlspecialchars($_SERVER['REQUEST_URI']) . '">' . htmlspecialchars($_POST['item']['name']) . '</a>' . '&nbsp;<a href="item.php?clone=' . htmlspecialchars($id) . '" title="Clone this item"><img src="static/clone.gif" width="10" height="10" border="0" /></a>' : "Add a new item";
template("item", array("titleHtml" => $title, "title" => strip_tags($title), "tables" => $tables, "canAjaxTestSql" => canAjaxTestSql()));
Example #8
0
function display_type($type, $typename, $yr, $mo, $convert, &$dec, &$rep, $dimension, $dimension2, $tags)
{
    $ctotal = array(1 => 0, 0, 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, 0, 0);
    $totals_arr = array();
    $printtitle = 0;
    //Flag for printing type name
    //Get Accounts directly under this group/type
    $result = get_gl_accounts(null, null, $type);
    while ($account = db_fetch($result)) {
        if ($tags != -1 && is_array($tags) && $tags[0] != false) {
            if (!is_record_in_tags($tags, TAG_ACCOUNT, $account['account_code'])) {
                continue;
            }
        }
        $bal = getPeriods($yr, $mo, $account["account_code"], $dimension, $dimension2);
        if (!$bal['per01'] && !$bal['per02'] && !$bal['per03'] && !$bal['per04'] && !$bal['per05'] && !$bal['per06'] && !$bal['per07'] && !$bal['per08'] && !$bal['per09'] && !$bal['per10'] && !$bal['per11'] && !$bal['per12']) {
            continue;
        }
        //Print Type Title if it has atleast one non-zero account
        if (!$printtitle) {
            $printtitle = 1;
            $rep->row -= 4;
            $rep->TextCol(0, 5, $typename);
            $rep->row -= 4;
            $rep->Line($rep->row);
            $rep->NewLine();
        }
        $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']);
        $rep->TextCol(0, 1, $account['account_code']);
        $rep->TextCol(1, 2, $account['account_name']);
        for ($i = 1; $i <= 12; $i++) {
            $rep->AmountCol($i + 1, $i + 2, $balance[$i] * $convert, $dec);
            $ctotal[$i] += $balance[$i];
        }
        $rep->NewLine();
    }
    //Get Account groups/types under this group/type
    $result = get_account_types(false, false, $type);
    while ($accounttype = db_fetch($result)) {
        //Print Type Title if has sub types and not previously printed
        if (!$printtitle) {
            $printtitle = 1;
            $rep->row -= 4;
            $rep->TextCol(0, 5, $typename);
            $rep->row -= 4;
            $rep->Line($rep->row);
            $rep->NewLine();
        }
        $totals_arr = display_type($accounttype["id"], $accounttype["name"], $yr, $mo, $convert, $dec, $rep, $dimension, $dimension2, $tags);
        for ($i = 1; $i <= 12; $i++) {
            $total[$i] += $totals_arr[$i];
        }
    }
    //Display Type Summary if total is != 0 OR head is printed (Needed in case of unused hierarchical COA)
    if ($printtitle) {
        $rep->row += 6;
        $rep->Line($rep->row);
        $rep->NewLine();
        $rep->TextCol(0, 2, _('Total') . " " . $typename);
        for ($i = 1; $i <= 12; $i++) {
            $rep->AmountCol($i + 1, $i + 2, ($total[$i] + $ctotal[$i]) * $convert, $dec);
        }
        $rep->NewLine();
    }
    for ($i = 1; $i <= 12; $i++) {
        $totals_arr[$i] = $total[$i] + $ctotal[$i];
    }
    return $totals_arr;
}
Example #9
0
function print_annual_expense_breakdown()
{
    global $path_to_root, $date_system;
    include_once $path_to_root . "reporting/includes/pdf_report.inc";
    $dim = get_company_pref('use_dimension');
    $dimension = $dimension2 = 0;
    if ($dim == 2) {
        $year = $_REQUEST['PARAM_0'];
        $dimension = $_REQUEST['PARAM_1'];
        $dimension2 = $_REQUEST['PARAM_2'];
        $comments = $_REQUEST['PARAM_3'];
    } else {
        if ($dim == 1) {
            $year = $_REQUEST['PARAM_0'];
            $dimension = $_REQUEST['PARAM_1'];
            $comments = $_REQUEST['PARAM_2'];
        } else {
            $year = $_REQUEST['PARAM_0'];
            $comments = $_REQUEST['PARAM_1'];
        }
    }
    $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
    $yr = $year;
    $mo = 12;
    $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(tr('Account'), tr('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' => tr("Year"), 'from' => $year, 'to' => ''), 2 => array('text' => tr("Dimension") . " 1", 'from' => get_dimension_string($dimension), 'to' => ''), 3 => array('text' => tr("Dimension") . " 2", 'from' => get_dimension_string($dimension2), 'to' => ''), 4 => array('text' => tr('Info'), 'from' => tr('Amounts in thousands'), 'to' => ''));
    } else {
        if ($dim == 1) {
            $params = array(0 => $comments, 1 => array('text' => tr("Year"), 'from' => $year, 'to' => ''), 2 => array('text' => tr('Dimension'), 'from' => get_dimension_string($dimension), 'to' => ''), 3 => array('text' => tr('Info'), 'from' => tr('Amounts in thousands'), 'to' => ''));
        } else {
            $params = array(0 => $comments, 1 => array('text' => tr("Year"), 'from' => $year, 'to' => ''), 2 => array('text' => tr('Info'), 'from' => tr('Amounts in thousands'), 'to' => ''));
        }
    }
    $rep = new FrontReport(tr('Annual Expense Breakdown'), "AnnualBreakDown.pdf", user_pagesize());
    $rep->Font();
    $rep->Info($params, $cols, $headers, $aligns);
    $rep->Header();
    $classname = '';
    $group = '';
    $total = array(1 => 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
    $total2 = array(1 => 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
    $sales = array(1 => 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
    $calc = array(1 => 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
    $accounts = get_gl_accounts_all(0);
    while ($account = db_fetch($accounts)) {
        $bal = getPeriods($year, $account["account_code"], $dimension, $dimension2);
        if (!$bal['per01'] && !$bal['per02'] && !$bal['per03'] && !$bal['per04'] && !$bal['per05'] && !$bal['per06'] && !$bal['per07'] && !$bal['per08'] && !$bal['per09'] && !$bal['per10'] && !$bal['per11'] && !$bal['per12']) {
            continue;
        }
        $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']);
        if ($account['AccountClassName'] != $classname) {
            if ($classname != '') {
                $closeclass = true;
            }
        }
        if ($account['AccountTypeName'] != $group) {
            if ($group != '') {
                $rep->Line($rep->row + 6);
                $rep->row -= 6;
                $rep->TextCol(0, 2, tr('Total') . " " . $group);
                for ($i = 1; $i <= 12; $i++) {
                    $rep->TextCol($i + 1, $i + 2, number_format2($total[$i], $dec));
                }
                $total = array(1 => 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
                $rep->row -= $rep->lineHeight + 4;
                if ($closeclass) {
                    $rep->Line($rep->row + 6);
                    $rep->row -= 6;
                    $rep->Font('bold');
                    $rep->TextCol(0, 2, tr('Total') . " " . $classname);
                    for ($i = 1; $i <= 12; $i++) {
                        $rep->TextCol($i + 1, $i + 2, number_format2($total2[$i], $dec));
                        $sales[$i] += $total2[$i];
                    }
                    $rep->Font();
                    $total2 = array(1 => 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
                    $rep->NewLine(3);
                    $closeclass = false;
                }
            }
            if ($account['AccountClassName'] != $classname) {
                $rep->Font('bold');
                $rep->TextCol(0, 5, $account['AccountClassName']);
                $rep->Font();
                $rep->row -= $rep->lineHeight + 4;
            }
            $group = $account['AccountTypeName'];
            $rep->TextCol(0, 5, $account['AccountTypeName']);
            $rep->Line($rep->row - 4);
            $rep->row -= $rep->lineHeight + 4;
        }
        $classname = $account['AccountClassName'];
        $rep->TextCol(0, 1, $account['account_code']);
        $rep->TextCol(1, 2, $account['account_name']);
        for ($i = 1; $i <= 12; $i++) {
            $rep->TextCol($i + 1, $i + 2, number_format2($balance[$i], $dec));
            $total[$i] += $balance[$i];
            $total2[$i] += $balance[$i];
        }
        $rep->NewLine();
        if ($rep->row < $rep->bottomMargin + 3 * $rep->lineHeight) {
            $rep->Line($rep->row - 2);
            $rep->Header();
        }
    }
    if ($account['AccountClassName'] != $classname) {
        if ($classname != '') {
            $closeclass = true;
        }
    }
    if ($account['AccountTypeName'] != $group) {
        if ($group != '') {
            $rep->Line($rep->row + 6);
            $rep->row -= 6;
            $rep->TextCol(0, 2, tr('Total') . " " . $group);
            for ($i = 1; $i <= 12; $i++) {
                $rep->TextCol($i + 1, $i + 2, number_format2($total[$i], $dec));
            }
            $rep->row -= $rep->lineHeight + 4;
            if ($closeclass) {
                $rep->Line($rep->row + 6);
                $rep->row -= 6;
                $rep->Font('bold');
                $rep->TextCol(0, 2, tr('Total') . " " . $classname);
                for ($i = 1; $i <= 12; $i++) {
                    $rep->TextCol($i + 1, $i + 2, number_format2($total2[$i], $dec));
                    $calc[$i] = $sales[$i] + $total2[$i];
                }
                $rep->row -= $rep->lineHeight + 8;
                $rep->TextCol(0, 2, tr('Calculated Return'));
                for ($i = 1; $i <= 12; $i++) {
                    $rep->TextCol($i + 1, $i + 2, number_format2($calc[$i], $dec));
                }
                $rep->Font();
                $rep->NewLine();
            }
        }
    }
    $rep->Line($rep->row);
    $rep->End();
}
Example #10
0
{
    $main = $_POST['cls'][0];
    $clsmain = explode(':',$main);
    $cldet = $clsmain[0];
    $subid = $clsmain[1];
    $batid = substr($cldet,0,1);
    $sec = substr($cldet,-1);
    $fid = $_POST['fid'];
    $date = $_POST['date'];
    echo "<form action='#' method='post'>";
    echo "<input type='hidden' name='fid' value='".$fid."' />";
    echo "<input type='hidden' name='date' value='".$date."' />";
    echo "<input type='hidden' name='batid' value='".$batid."' />";
    echo "<input type='hidden' name='sec' value='".$sec."' />";
    echo "<input type='hidden' name='subid' value='".$subid."' />";
    echo "<fieldset style='width: 300px'><legend>Select Periods:</legend>".getPeriods($batid,$sec,$date)."</fieldset><br />";
    echo "<input type='submit' name='phase2' /></form>";
   //echo "batid: ".$batid." sec:".$sec." subid:".$subid." fid:".$fid." ".$date;
    
}
elseif(isset($_POST['phase2']))
{
    
    
    $batid = $_POST['batid'];
    $batsec = $_POST['sec'];
    $subid = $_POST['subid'];
    $date = $_POST['date'];
    $fid = $_POST['fid'];
    $per=$_POST['per'];
    if(count($per)<=0)
Example #11
0
function getIndexUrl($tag)
{
    $periods = getPeriods();
    $params = array();
    if (strlen($tag)) {
        $params['tag'] = $tag;
    }
    if (strlen(@$_GET['period'])) {
        $params['period'] = $_GET['period'];
    }
    if (strlen(@$_GET['to'])) {
        $params['to'] = $_GET['to'];
    }
    $params = http_build_query($params);
    $url = "index.php" . (strlen($params) ? "?" . $params : "");
    return $url;
}