function count brings different amount according to the date parameters passed

0

I need to get the month and year twice: to check the expenses and calculate the amount of expenses found.

In function consultarDespesas , step to the two global variables to later access them in function quantidadeDespesas . The $this->request->data['Despesa']['ano'] e $this->request->data['Despesa']['mes'] is null . I do not know how to access anywhere in the controller Expenses this request.

So, I preferred to get the month and year soon, but even so the two global variables are null when the program arrives at function quantidadeDespesas .

I have already debugged the two global variables or attributes, already debuguei $this->request->data and $this->data , but no use, everything is null . Let's look at the codes:

class DespesasController extends AppController {

public $helpers=array('Form', 'Html');

public $ano;
public $mes;

public $uses = array('Despesa', 'Receita');

function to look for expenses:

public function consultarDespesa() {
    if ($this->request->is('post')) {
            $this->ano = $this->data['Despesa']['ano'];
            $this->mes = $this->data['Despesa']['mes'];

            $despesas = $this->Despesa->find('all',
            array(
    'conditions'=>array(
    'YEAR(data_despesa)'=>$this->request->data['Despesa']['ano'],
    'MONTH(data_despesa)'=>$this->request->data['Despesa']['mes'])));

            if ($despesas == null) {
                $this->Session->setFlash("Sua pesquisa não retornou nenhum resultado.");
            }

            else {
                $this->Session->write("Despesas", $despesas);

                $this->quantidadeDespesas();
                $this->redirect(array('action'=>'exibirDespesas'));
            } 
    }
}   

Function to count how many expenses encountered:

public function quantidadeDespesas() {
    $quantidadeDespesas = $this->Despesa->query("select count(id_despesa) as quantidadeDespesas from despesas where year(data_despesa)='$this->ano' and MONTH(data_despesa)='$this->mes'");

    return $quantidadeDespesas;
}
    
asked by anonymous 27.01.2016 / 15:55

0 answers