Exemple #1
0
 public function sum($type, $date_from, $date_to)
 {
     //$date_from = "01-01-$yaer 00:00:00";
     //$date_to = "31-12-$yaer 23:59:59";
     $query = new \yii\db\Query();
     $query->select("sum(`leadsum`) AS lead,{{%transactions}}.type,{{%transactions}}.valuedate")->from('{{%transactions}}');
     $query->join = [['LEFT JOIN', '{{%accounts}}', '{{%accounts}}.id=account_id']];
     $query->groupBy = "{{%accounts}}.type";
     $query->where("{{%accounts}}.type = :type");
     $query->andWhere("valuedate>=:date_from");
     $query->andWhere("valuedate<=:date_to");
     $query->params([':date_from' => $date_from, ':date_to' => $date_to, ':type' => $type]);
     $command = $query->createCommand();
     return $command->queryScalar();
 }