I am trying to make a query in yii2, I am new and I have not yet become familiar with the query topic, the query is as follows:
I need to bring this data:
->select('ingreso.idingreso', 'ingreso.fecha_hora', 'persona.nombre', 'ingreso.tipo_comprobante', 'ingreso.serie_comprobante', 'ingreso.num_comprobante', 'ingreso.impuesto', 'ingreso.estado', 'SUM("ingreso.cantidad*precio_cantidad") AS total')
This is what I tried but it did not work, and try several types of join:
$table = Ingreso::find()
->leftJoin('persona', 'ingreso.idingreso = persona.idpersona')
->leftJoin('detalle_ingreso', 'ingreso.idingreso = detalle_ingreso.idingreso')
->select('ingreso.idingreso', 'ingreso.fecha_hora', 'persona.nombre', 'ingreso.tipo_comprobante', 'ingreso.serie_comprobante', 'ingreso.num_comprobante', 'ingreso.impuesto', 'ingreso.estado', 'SUM("ingreso.cantidad*precio_cantidad") AS total')
->Where(["estado" => 'A'])
->orderBy(['ingreso.idingreso' => SORT_DESC])
->groupBy(['ingreso.idingreso', 'ingreso.fecha_hora', 'persona.nombre', 'ingreso.tipo_comprobante', 'ingreso.serie_comprobante', 'ingreso.num_comprobante', 'ingreso.impuesto', 'ingreso.estado']);
$pages = new Pagination([
"pageSize" => 4,
"totalCount" => $table->count()
]);
$model = $table
->limit($pages->limit)
->all();
Apart from that I throw a mistake with the page in this part:
"totalCount" => $table->count()
I appreciate your help.