change search method by user and property

Hello,

Can you help me please.

I have two tables :




CREATE TABLE `expenses` (

  `id` int(11) NOT NULL,

  `user_id` int(11) DEFAULT NULL,

  `value` decimal(10,2) DEFAULT NULL,

  `mission_id` int(11) DEFAULT NULL

) ENGINE=InnoDB DEFAULT CHARSET=utf8;


CREATE TABLE `costs ` (

  `id` int(11) NOT NULL,

  `user_id` int(11) DEFAULT NULL,

  `value` decimal(10,2) DEFAULT NULL,

  `mission_id` int(11) DEFAULT NULL

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

How I can change the method searching to get for each user the mission_id with the sum of costs (value) and expenses (value)

Thank’s

What code do you have so far? What do you want to change?

Thank you

my code is :


public function search($params)

    {

        $query = Costs::find();


        $dataProvider = new ActiveDataProvider([

            'query' => $query,

        ]);


        $this->load($params);


        if (!$this->validate()) {

            return $dataProvider;

        }


        // grid filtering conditions

        $query->andFilterWhere([

            'id' => $this->id,

            'user_id' => $this->user_id,

            'value' => $this->value,

            'mission_id' => $this->mission_id,

        ]);


        return $dataProvider;

    }