$showPocketMoney2 = 0;
 }
 if (count($errors) != 0) {
     echo '<errors>';
     foreach ($errors as $error) {
         echo "<error>{$error}</error>";
     }
     echo '</errors>';
 }
 //create the chart
 $insertChart = InsertChart(BADGER_ROOT . "/includes/charts/charts.swf", BADGER_ROOT . "/includes/charts/charts_library", BADGER_ROOT . "/modules/forecast/forecastChart.php?endDate={$endDate}&account={$account}&savingTarget={$savingTarget}&pocketMoney1={$pocketMoney1}&pocketMoney2={$pocketMoney2}&showLowerLimit={$showLowerLimit}&showUpperLimit={$showUpperLimit}&showPlannedTransactions={$showPlannedTransactions}&showSavingTarget={$showSavingTarget}&showPocketMoney1={$showPocketMoney1}&showPocketMoney2={$showPocketMoney2}", 800, 400, "ECE9D8", true);
 $am = new AccountManager($badgerDb);
 $totals = array();
 $currentAccount = $am->getAccountById($account);
 $startDate = new Date();
 $currentBalances = getDailyAmount($currentAccount, $startDate, $selectedDate);
 $accountCurrency = $currentAccount->getCurrency()->getSymbol();
 foreach ($currentBalances as $balanceKey => $balanceVal) {
     if (isset($totals[$balanceKey])) {
         $totals[$balanceKey]->add($balanceVal);
     } else {
         $totals[$balanceKey] = $balanceVal;
     }
 }
 //calculate spending money, if saving target should be reached
 $countDay = count($totals) - 1;
 //get numbers of days between today & endDate
 $laststanding = new Amount($totals[$selectedDate->getDate()]);
 $endDateBalance = $laststanding;
 //get balance of end date
 $freeMoney = new Amount($endDateBalance->sub($savingTarget));
function showTrendData()
{
    global $badgerDb;
    global $logger;
    $logger->log('statistics::showTrendData: REQUEST_URI: ' . $_SERVER['REQUEST_URI']);
    if (!isset($_GET['accounts']) || !isset($_GET['startDate']) || !isset($_GET['endDate'])) {
        throw new BadgerException('statistics', 'missingParameter');
    }
    $accountIds = explode(';', $_GET['accounts']);
    foreach ($accountIds as $key => $val) {
        settype($accountIds[$key], 'integer');
    }
    $startDate = new Date($_GET['startDate']);
    $endDate = new Date($_GET['endDate']);
    $now = new Date();
    $now->setHour(0);
    $now->setMinute(0);
    $now->setSecond(0);
    if ($endDate->after($now)) {
        $endDate = $now;
    }
    $accountManager = new AccountManager($badgerDb);
    $totals = array();
    $accounts = array();
    $currentAccountIndex = 0;
    foreach ($accountIds as $currentAccountId) {
        $currentAccount = $accountManager->getAccountById($currentAccountId);
        $accounts[$currentAccountIndex][0] = $currentAccount->getTitle();
        $currentBalances = getDailyAmount($currentAccount, $startDate, $endDate);
        foreach ($currentBalances as $balanceKey => $balanceVal) {
            if (isset($totals[$balanceKey])) {
                $totals[$balanceKey]->add($balanceVal);
            } else {
                $totals[$balanceKey] = $balanceVal;
            }
            $accounts[$currentAccountIndex][] = $balanceVal->get();
        }
        $currentAccountIndex++;
    }
    $numDates = count($totals);
    $chart = array();
    //for documentation for the following code see: http://www.maani.us/charts/index.php?menu=Reference
    $chart['chart_type'] = "line";
    $chart['axis_category'] = array('skip' => $numDates / 12, 'font' => "Arial", 'bold' => false, 'size' => 10, 'color' => "000000", 'alpha' => 100, 'orientation' => "horizontal");
    $chart['axis_ticks'] = array('value_ticks' => true, 'category_ticks' => true, 'position' => "centered", 'major_thickness' => 2, 'major_color' => "000000", 'minor_thickness' => 1, 'minor_color' => "000000", 'minor_count' => 4);
    $chart['axis_value'] = array('min' => 0, 'max' => 0, 'steps' => 10, 'prefix' => "", 'suffix' => "", 'decimals' => 0, 'decimal_char' => ".", 'separator' => "", 'show_min' => true, 'font' => "Arial", 'bold' => false, 'size' => 10, 'color' => "000000", 'alpha' => 75, 'orientation' => "horizontal");
    $chart['chart_border'] = array('top_thickness' => 1, 'bottom_thickness' => 1, 'left_thickness' => 1, 'right_thickness' => 1, 'color' => "000000");
    $chart['chart_pref'] = array('line_thickness' => 1, 'point_shape' => "none", 'fill_shape' => false);
    $chart['chart_grid_h'] = array('thickness' => 1, 'color' => "000000", 'alpha' => 15, 'type' => "solid");
    $chart['chart_grid_v'] = array('thickness' => 1, 'color' => "000000", 'alpha' => 5, 'type' => "dashed");
    $chart['chart_rect'] = array('x' => 50, 'y' => 50, 'width' => 700, 'height' => 300, 'positive_color' => "ffffff", 'negative_color' => "000000", 'positive_alpha' => 100, 'negative_alpha' => 10);
    $chart['chart_value'] = array('prefix' => "", 'suffix' => "", 'decimals' => 0, 'decimal_char' => ".", 'separator' => "", 'position' => "cursor", 'hide_zero' => true, 'as_percentage' => false, 'font' => "Arial", 'bold' => false, 'size' => 10, 'color' => "000000", 'alpha' => 90);
    $chart['chart_transition'] = array('type' => "none", 'delay' => 1, 'duration' => 1, 'order' => "all");
    $chart['legend_rect'] = array('x' => 50, 'y' => 5, 'width' => 700, 'height' => 5, 'margin' => 5, 'fill_color' => "FFFFFF", 'fill_alpha' => 100, 'line_color' => "000000", 'line_alpha' => 100, 'line_thickness' => 1);
    $chart['legend_label'] = array('layout' => "horizontal", 'bullet' => "circle", 'font' => "Arial", 'bold' => false, 'size' => 11, 'color' => "000000", 'alpha' => 90);
    $chart['legend_transition'] = array('type' => "none", 'delay' => 1, 'duration' => 1);
    $chart['series_color'] = array("FF0000", "00FF00", "0000FF", "FF8000", "404040", "800040");
    $chart['chart_data'] = array();
    $chart['chart_data'][0][0] = '';
    if (count($accounts) > 1) {
        $chart['chart_data'][1][0] = getBadgerTranslation2('statistics', 'trendTotal');
    } else {
        $chart['chart_data'][1][0] = utf8_encode($accounts[0][0]);
    }
    foreach ($totals as $key => $val) {
        $tmp = new Date($key);
        $chart['chart_data'][0][] = $tmp->getFormatted();
        $chart['chart_data'][1][] = $val->get();
    }
    if (count($accounts) > 1) {
        foreach ($accounts as $val) {
            $chart['chart_data'][] = $val;
        }
    }
    SendChartData($chart);
}
Example #3
0
$totals = array();
$values = array();
$valueTargets = array();
$valueNames = array();
//echo '<pre>'; print_r($displayStartDate); echo "x"; print_r($displayEndDate); echo '</pre>';
if (is_null($displayStartDate) || is_null($displayEndDate)) {
    echo getBadgerTranslation2('statistics2Graph', 'noMatchingTransactions');
    require_once BADGER_ROOT . "/includes/fileFooter.php";
    exit;
}
foreach ($accountIds as $currentAccountId) {
    $currentAccount = $accountManager->getAccountById($currentAccountId);
    $filter = getDataGridFilter($currentAccount);
    //echo "<pre>"; print_r($filter); echo "</pre>";
    $currentAccount->setFilter($filter);
    $currentBalances = getDailyAmount($currentAccount, $displayStartDate, $displayEndDate, false, $startWithBalance, true);
    $previousAmount = null;
    //echo "currentAccountId: $currentAccountId<br />";
    //echo "<pre>"; print_r($currentBalances); echo "</pre>";
    foreach ($currentBalances as $balanceKey => $balanceVal) {
        if (isset($totals[$balanceKey])) {
            $totals[$balanceKey]->add($balanceVal);
        } else {
            $totals[$balanceKey] = $balanceVal;
        }
        $values[$currentAccount->getId()][] = is_null($previousAmount) || $balanceVal->compare($previousAmount) != 0 || $balanceKey == $displayEndDate->getTime() ? $balanceVal->get() : '-';
        //$values[$currentAccount->getId()][] = ($balanceVal->compare($previousAmount) != 0) ? $balanceVal->get() : '-';
        if ($showTickMarks) {
            $date = new Date($balanceKey);
            $valueTargets[$currentAccount->getId()][] = "javascript:reachThroughTrend('" . $date->getFormatted() . "', '{$currentAccountId}');";
            $valueNames[$currentAccount->getId()][] = $date->getFormatted() . ': ' . $balanceVal->getFormatted();