Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
129 lines (116 sloc) 4.02 KB
<?php
namespace App\Controller;
use App\Controller\AppController;
use DateTimeImmutable;
/**
* Accounts Controller
*
* @property \App\Model\Table\AccountsTable $Accounts
*
* @method \App\Model\Entity\Account[]|\Cake\Datasource\ResultSetInterface paginate($object = null, array $settings = [])
*/
class AccountsController extends AppController
{
/**
* Index method
*
* @return \Cake\Http\Response|null
*/
public function index()
{
$this->paginate = [
'contain' => ['Categories']
];
$accounts = $this->paginate($this->Accounts);
$this->set(compact('accounts'));
}
/**
* View method
*
* @param string|null $id Account id.
* @return \Cake\Http\Response|null
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
*/
public function view($id = null)
{
$account = $this->Accounts->get($id, [
'contain' => ['Categories']
]);
$this->set('account', $account);
}
/**
* Aggregate method
*
* @return void
*/
public function aggregate()
{
$from = new DateTimeImmutable($this->request->getQuery('from'));
$to = new DateTimeImmutable($this->request->getQuery('to'));
$months = $this->Accounts->getTargetMonths($from, $to);
/** @var \App\Model\Entity\Account[] $aggregatedAccounts */
$aggregatedAccounts = $this->Accounts->find('crossAggregate', ['months' => $months])->toList();
$this->set('accounts', $aggregatedAccounts);
$this->set('months', $months);
}
/**
* Add method
*
* @return \Cake\Http\Response|null Redirects on successful add, renders view otherwise.
*/
public function add()
{
$account = $this->Accounts->newEntity();
if ($this->request->is('post')) {
$account = $this->Accounts->patchEntity($account, $this->request->getData());
if ($this->Accounts->save($account)) {
$this->Flash->success(__('The account has been saved.'));
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__('The account could not be saved. Please, try again.'));
}
$categories = $this->Accounts->Categories->find('list', ['limit' => 200]);
$this->set(compact('account', 'categories'));
}
/**
* Edit method
*
* @param string|null $id Account id.
* @return \Cake\Http\Response|null Redirects on successful edit, renders view otherwise.
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
*/
public function edit($id = null)
{
$account = $this->Accounts->get($id, [
'contain' => []
]);
if ($this->request->is(['patch', 'post', 'put'])) {
$account = $this->Accounts->patchEntity($account, $this->request->getData());
if ($this->Accounts->save($account)) {
$this->Flash->success(__('The account has been saved.'));
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__('The account could not be saved. Please, try again.'));
}
$categories = $this->Accounts->Categories->find('list', ['limit' => 200]);
$this->set(compact('account', 'categories'));
}
/**
* Delete method
*
* @param string|null $id Account id.
* @return \Cake\Http\Response|null Redirects to index.
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
*/
public function delete($id = null)
{
$this->request->allowMethod(['post', 'delete']);
$account = $this->Accounts->get($id);
if ($this->Accounts->delete($account)) {
$this->Flash->success(__('The account has been deleted.'));
} else {
$this->Flash->error(__('The account could not be deleted. Please, try again.'));
}
return $this->redirect(['action' => 'index']);
}
}
You can’t perform that action at this time.