I need to ask a question for a portfolio module in accounting, I have a sales table where I am bringing all the data and I group them for each client and add up the total of each client, I need you to bring me a list grouped by client and below from each client show me the sales that have been made and add them to me.
Here's an example:
Global Marketing Farmacéuticos S...
20016 2016/09/26 2016/10/11 FC 662.457 | 0 |
--------- --------- | |
TotalCliente ===> 662.457 | | 662.457
HummaLab S.A. Tel 4445246-0 - Días Co... | |
19463 2016/07/28 2016/08/12 FC 1.328.707 | 59 |
19615 2016/08/12 2016/08/27 FC 2.895.306 | 44 |
19743 2016/08/26 2016/09/10 FC 1.592.052 | 31 |
19925 2016/09/15 2016/09/30 FC 2.688.481 | 11 |
20038 2016/09/28 2016/10/13 FC 1.926.619 | -2 |
--------- --------- | |
TotalCliente ===> 1.926.619 8.504.546 | | 10.431.165
Importaciones Unica S.A.S. Tel:44860... | |
19747 2016/08/26 2016/09/25 FC 4.266.980 | 16 |
19884 2016/09/12 2016/10/12 FC 4.760.795 | -1 |
20032 2016/09/27 2016/10/27 FC 4.117.654 |-16 |
--------- --------- | |
TotalCliente ===> 8.878.449 4.266.980 | | 13.145.429
I made this query but it only groups me the clients and adds the data but it does not bring me the corresponding sales of each client:
$ventas = $this->Venta->find('all',array(
'fields'=>array('Venta.nombreClien','Venta.documentoClien','Venta.telefonoClien','Venta.telefono2Clien','Venta.emailClien','Venta.direccionClien','SUM(Venta.valor_total)'),
'group' => array('Venta.nombreClien'),
'conditions' => array('Venta.fecha BETWEEN ? and ?' => array($desde, $hasta),'Venta.relacionfactura_id' => null)));
How can I do so that it brings me the corresponding sales of each client?