diff --git a/app/Config/Routes.php b/app/Config/Routes.php index ee71b28..2869f44 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -29,6 +29,9 @@ $routes->get('syncScheduled', 'Home::syncScheduled'); $routes->get('viewAccounts', 'Home::viewAccountsTree'); $routes->get('viewActivities', 'Home::viewAccountActivities'); $routes->get('viewScheduled', 'Home::viewScheduled'); +$routes->get('viewBill/(:any)', 'Home::viewBill/$1'); +$routes->get('viewChart', 'Charts::getData/0'); +$routes->get('viewChart/(:num)', 'Charts::getData/$1'); service('auth')->routes($routes); diff --git a/app/Config/Routing.php b/app/Config/Routing.php index 7abadc7..c196f75 100644 --- a/app/Config/Routing.php +++ b/app/Config/Routing.php @@ -111,7 +111,7 @@ class Routing extends BaseRouting * * Default: false */ - public bool $multipleSegmentsOneParam = false; + public bool $multipleSegmentsOneParam = true; /** * For Auto Routing (Improved). diff --git a/app/Controllers/Charts.php b/app/Controllers/Charts.php new file mode 100644 index 0000000..84737ba --- /dev/null +++ b/app/Controllers/Charts.php @@ -0,0 +1,131 @@ +db = \Config\Database::connect(); + } + + public function getData($id){ + if ($id == 0) + return $this->getAllData(); + else + return $this->getDetailData($id); + } + + private function getDetailData($id){ + $jetzt = date('Y-m-01'); + $query = <<= '$jetzt' + AND (datum < '$jetzt'::date + interval '1 month') + AND budget_bills.id = bill_id + AND account_id = finanzen.budget_accounts.id + AND (account_id IN ( + WITH RECURSIVE subordinates AS ( + SELECT + id, + parent_id, + description + FROM + finanzen.budget_accounts + WHERE + id = $id + UNION + SELECT + e.id, + e.parent_id, + e.description + FROM + finanzen.budget_accounts e + INNER JOIN subordinates s ON s.id = e.parent_id) + SELECT + id + FROM + subordinates + )) + GROUP BY description, account_id + EOD; + $data = array(); + $result = $this->db->query($query); + foreach ($result->getResult() as $row) { + $werte[] = $row->amount; + $ids[] = $row->id; + $labels[] = $row->description; + } + $data['data'] = json_encode($werte); + $data['labels'] = json_encode($labels); + $data['ids'] = json_encode($ids); + $data['title'] = "Kategorieübersicht > ".$jetzt; + return view("charts/monthly", $data); +} + private function getAllData(){ + $jetzt = date('Y-m-01'); + $query = <<= '$jetzt' + AND budget_bills.id = bill_id + AND (account_id IN + ( + WITH RECURSIVE subordinates AS ( + SELECT + id, + parent_id, + description + FROM + finanzen.budget_accounts + WHERE + id = w.id + UNION + SELECT + e.id, + e.parent_id, + e.description + FROM + finanzen.budget_accounts e + INNER JOIN subordinates s ON s.id = e.parent_id) + SELECT + id + FROM + subordinates + )) + ) AS x GROUP BY description, id) as i WHERE summe is not null; + EOD; + $data = array(); + $result = $this->db->query($query); + foreach ($result->getResult() as $row) { + $werte[] = $row->summe; + $ids[] = $row->id; + $labels[] = $row->description; + } + $data['data'] = json_encode($werte); + $data['labels'] = json_encode($labels); + $data['ids'] = json_encode($ids); + $data['title'] = "Monatsübersicht > ".$jetzt; + return view("charts/monthly", $data); + +// SELECT description,amount FROM (SELECT id,description from finanzen.budget_accounts WHERE parent_id=0 AND type='output' AND LKZ is null) as w, +// LATERAL +// (SELECT subamount as amount +// FROM finanzen.budget_billdetails, finanzen.budget_bills +// WHERE datum >= DATE_TRUNC('month',current_date) +// AND budget_bills.id = bill_id +// AND (account_id IN +// (SELECT id from finanzen.budget_accounts WHERE (id = w.id OR parent_id = w.id)) +// ) +// ) AS x + } +} \ No newline at end of file diff --git a/app/Views/charts/monthly.php b/app/Views/charts/monthly.php new file mode 100644 index 0000000..2be7308 --- /dev/null +++ b/app/Views/charts/monthly.php @@ -0,0 +1,68 @@ +extend('layout'); ?> +section('menu'); ?> + include('sidebar') ?> +endSection(); ?> +section('css'); ?> + + +endSection(); ?> +section('content'); ?> +
+
+ +
+
+endSection(); ?> +section('scripts'); ?> + + + + + + +endSection(); ?> \ No newline at end of file diff --git a/app/Views/layout.php b/app/Views/layout.php index d24762d..cc9c00c 100644 --- a/app/Views/layout.php +++ b/app/Views/layout.php @@ -64,6 +64,22 @@ +
@@ -41,7 +41,15 @@ >
-
+
+ + + + + + +
+
@@ -50,8 +58,8 @@
- - + +
@@ -130,36 +138,10 @@ endSection(); ?> section('scripts'); ?> - - - endSection(); ?> \ No newline at end of file diff --git a/app/Views/sidebar.php b/app/Views/sidebar.php index fa49e95..7a8f0fe 100644 --- a/app/Views/sidebar.php +++ b/app/Views/sidebar.php @@ -54,7 +54,7 @@