示例#1
0
 private function pie($mysqli, $year)
 {
     $data = Db\AnnualApi::getYear($mysqli, $year);
     $sum = array_sum($data);
     $colors = new Util\Colors(6);
     $cdata = array(array("label" => 'Federal taxes', "color" => $colors->getNext(), "value" => $data['FEDERAL_TAXES']), array("label" => 'State taxes', "color" => $colors->getNext(), "value" => $data['STATE_TAXES']), array("label" => 'Other government fees (est)', "color" => $colors->getNext(), "value" => $data['SOCIAL_SEC']), array("label" => 'Donations', "color" => $colors->getNext(), "value" => $data['DONATIONS']), array("label" => 'Savings', "color" => $colors->getNext(), "value" => $data['SAVINGS']), array("label" => 'Remainder (expenses)', "color" => $colors->getNext(), "value" => $data['GROSS_INCOME'] * 2 - $sum));
     $options = array('tooltipTemplate' => "<%if (label){%><%=label%>: <%}%>\$<%= value.toFixed(2).replace(/(\\d)(?=(\\d{3})+\\.)/g, '\$1,') %>", 'legendTemplate' => "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<segments.length; i++){%><li><span style=\"border-color:<%=segments[i].fillColor%>\"></span><%if(segments[i].label){%><%=segments[i].label%><%}%></li><%}%></ul>", 'responsive' => true);
     $current_year = date("Y");
     $extra = array('headerText' => $year . ' &mdash; $' . number_format($data['GROSS_INCOME'], 2) . ($year >= $current_year ? ' (est)' : ''));
     echo json_encode(array("Pie", $cdata, $options, $extra));
 }
示例#2
0
 public function yearReport($mysqli, $year)
 {
     echo '<h1>' . $year . ' Annual Report</h1>';
     $data = Db\AnnualApi::getYear($mysqli, $year);
     echo '<h2>Income</h2>';
     echo '<table border=1 style="border-collapse: collapse;"><tr><th>Key</th><th>Value</th></tr>';
     foreach ($data as $key => $value) {
         printf('<tr><td>%s</td><td>%s</td>', $key, $value);
     }
     echo '</table>';
     $this->renderAnnualPie($year);
     $categories = Db\InvestmentsApi::getCategories($mysqli);
     $data = Db\InvestmentsApi::getInvestments($mysqli, $year, $year);
     echo '<h2>Investments</h2>';
     echo '<table border=1 style="border-collapse: collapse;"><tr><th>Month</th>';
     foreach ($categories as $i) {
         printf('<th>%s</th>', $i->name);
     }
     echo '<th>Total</th></tr>';
     for ($i = 1; $i <= 12; $i++) {
         if (empty($data[$year][$i])) {
             continue;
         }
         echo '<tr><td>' . date("F", mktime(0, 0, 0, $i, 1, $year)) . '</td>';
         foreach ($categories as $category) {
             if (isset($data[$year][$i][$category->key])) {
                 $value = $data[$year][$i][$category->key];
             } else {
                 $value = '';
             }
             printf('<td>%s</td>', $value);
         }
         printf('<td>%s</td>', array_sum($data[$year][$i]));
         echo '</tr>';
     }
     echo '</table>';
     $id = 'canvaschart' . uniqid();
     echo '<div class="canvascontainer line"><canvas data-src="/data/investments/year/' . $year . '" id="' . $id . '"></div>';
 }