summaryrefslogtreecommitdiff
path: root/app/Controller/Budget.php
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2015-03-12 23:03:51 -0400
committerFrederic Guillot <fred@kanboard.net>2015-03-12 23:03:51 -0400
commit4700139a86d1ef44eabe43edb5a4abff9c645811 (patch)
treea4bf846ff610a59d91fa6d0405b0460dbd2d9e31 /app/Controller/Budget.php
parent925ede9b48bef67739d26f0d0a394342f2d8edf0 (diff)
Start to develop the budget module
Diffstat (limited to 'app/Controller/Budget.php')
-rw-r--r--app/Controller/Budget.php111
1 files changed, 111 insertions, 0 deletions
diff --git a/app/Controller/Budget.php b/app/Controller/Budget.php
new file mode 100644
index 00000000..01090550
--- /dev/null
+++ b/app/Controller/Budget.php
@@ -0,0 +1,111 @@
+<?php
+
+namespace Controller;
+
+/**
+ * Budget
+ *
+ * @package controller
+ * @author Frederic Guillot
+ */
+class Budget extends Base
+{
+ /**
+ * Budget index page
+ *
+ * @access public
+ */
+ public function index()
+ {
+ $project = $this->getProject();
+
+ $this->response->html($this->projectLayout('budget/index', array(
+ 'total' => $this->budget->getTotal($project['id']),
+ 'project' => $project,
+ 'title' => t('Budget')
+ )));
+ }
+
+ /**
+ * Create budget lines
+ *
+ * @access public
+ */
+ public function create(array $values = array(), array $errors = array())
+ {
+ $project = $this->getProject();
+
+ if (empty($values)) {
+ $values['date'] = date('Y-m-d');
+ }
+
+ $this->response->html($this->projectLayout('budget/create', array(
+ 'lines' => $this->budget->getAll($project['id']),
+ 'values' => $values + array('project_id' => $project['id']),
+ 'errors' => $errors,
+ 'project' => $project,
+ 'title' => t('Budget')
+ )));
+ }
+
+ /**
+ * Validate and save a new budget
+ *
+ * @access public
+ */
+ public function save()
+ {
+ $project = $this->getProject();
+
+ $values = $this->request->getValues();
+ list($valid, $errors) = $this->budget->validateCreation($values);
+
+ if ($valid) {
+
+ if ($this->budget->create($values['project_id'], $values['amount'], $values['comment'], $values['date'])) {
+ $this->session->flash(t('The budget line have been created successfully.'));
+ $this->response->redirect($this->helper->url('budget', 'create', array('project_id' => $project['id'])));
+ }
+ else {
+ $this->session->flashError(t('Unable to create the budget line.'));
+ }
+ }
+
+ $this->create($values, $errors);
+ }
+
+ /**
+ * Confirmation dialog before removing a budget
+ *
+ * @access public
+ */
+ public function confirm()
+ {
+ $project = $this->getProject();
+
+ $this->response->html($this->projectLayout('budget/remove', array(
+ 'project' => $project,
+ 'budget_id' => $this->request->getIntegerParam('budget_id'),
+ 'title' => t('Remove a budget line'),
+ )));
+ }
+
+ /**
+ * Remove a budget
+ *
+ * @access public
+ */
+ public function remove()
+ {
+ $this->checkCSRFParam();
+ $project = $this->getProject();
+
+ if ($this->budget->remove($this->request->getIntegerParam('budget_id'))) {
+ $this->session->flash(t('Budget line removed successfully.'));
+ } else {
+ $this->session->flashError(t('Unable to remove this budget line.'));
+ }
+
+ $this->response->redirect($this->helper->url('budget', 'create', array('project_id' => $project['id'])));
+ }
+}