<?php
namespace App\Controller;

use App\Controller\AppController;

/**
 * WlBudgets Controller
 *
 * @property \App\Model\Table\WlBudgetsTable $WlBudgets
 *
 * @method \App\Model\Entity\WlBudget[]|\Cake\Datasource\ResultSetInterface paginate($object = null, array $settings = [])
 */
class WlBudgetsController extends AppController
{

    /**
     * Index method
     *
     * @return \Cake\Http\Response|void
     */

    public function select() {
        
        if ($this->request->is('post')) {
            //debug($this->request['data']);
            $budget_id =  $this->request['data']['wl_Budgets'];
            //debug($budget_id);

            return $this->redirect(['controller' => 'budget', 'action' => 'gettype', $budget_id]);
        }
        else {
            $wlBudget = $this->WlBudgets->newEntity();
        $wlBudgets = $this->WlBudgets->find('list', [
            'conditions' => array('schulart' => 'GY')
        ]);
        //debug($wlBudgets);
        $this->set(compact('wlBudget','wlBudgets'));
        }
    } 

    public function index()
    {
        $wlBudgets = $this->paginate($this->WlBudgets);

        $this->set(compact('wlBudgets'));
    }

    /**
     * View method
     *
     * @param string|null $id Wl Budget id.
     * @return \Cake\Http\Response|void
     * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
     */
    public function view($id = null)
    {
        $wlBudget = $this->WlBudgets->get($id, [
            'contain' => ['Budget']
        ]);

        $this->set('wlBudget', $wlBudget);
    }

    /**
     * Add method
     *
     * @return \Cake\Http\Response|null Redirects on successful add, renders view otherwise.
     */
    public function add()
    {
        $wlBudget = $this->WlBudgets->newEntity();
        if ($this->request->is('post')) {
            $wlBudget = $this->WlBudgets->patchEntity($wlBudget, $this->request->getData());
            if ($this->WlBudgets->save($wlBudget)) {
                $this->Flash->success(__('The wl budget has been saved.'));

                return $this->redirect(['action' => 'index']);
            }
            $this->Flash->error(__('The wl budget could not be saved. Please, try again.'));
        }
        $this->set(compact('wlBudget'));
    }

    /**
     * Edit method
     *
     * @param string|null $id Wl Budget id.
     * @return \Cake\Http\Response|null Redirects on successful edit, renders view otherwise.
     * @throws \Cake\Network\Exception\NotFoundException When record not found.
     */
    public function edit($id = null)
    {
        $wlBudget = $this->WlBudgets->get($id, [
            'contain' => []
        ]);
        if ($this->request->is(['patch', 'post', 'put'])) {
            $wlBudget = $this->WlBudgets->patchEntity($wlBudget, $this->request->getData());
            if ($this->WlBudgets->save($wlBudget)) {
                $this->Flash->success(__('The wl budget has been saved.'));

                return $this->redirect(['action' => 'index']);
            }
            $this->Flash->error(__('The wl budget could not be saved. Please, try again.'));
        }
        $this->set(compact('wlBudget'));
    }

    /**
     * Delete method
     *
     * @param string|null $id Wl Budget 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']);
        $wlBudget = $this->WlBudgets->get($id);
        if ($this->WlBudgets->delete($wlBudget)) {
            $this->Flash->success(__('The wl budget has been deleted.'));
        } else {
            $this->Flash->error(__('The wl budget could not be deleted. Please, try again.'));
        }

        return $this->redirect(['action' => 'index']);
    }
}
