Estimados:
Junto con saludarles quería hacerles la siguiente consulta, lo que pasa que genere una tabla en CgridView de la siguiente forma:
Controlador
public function actionPrestacionesIngresadasMes() {
$sql = "SELECT A.asiento_id as id,
MC.medico_rut as rut,
MC.medico_nombres as nombre,
MC.medico_apellidos as apellido,
A.asiento_fecha_oficial as fecha,
P.prestacion_codigo as codigo_prestacion,
P.prestacion_nombre as nombre_prestacion,
AP.asiento_prestacion_precio as precio,
YEAR(A.asiento_fecha_oficial) AS ano
FROM ASIENTO AS A
INNER JOIN ASIENTO_PRESTACION AS AP ON (AP.asiento_prestacion_asiento_id = A.asiento_id)
INNER JOIN PRESTACION AS P ON (P.prestacion_id = AP.asiento_prestacion_prestacion_id)
INNER JOIN ASIENTO_COBRANZA AS AC ON (AC.as_cob_asiento_id = A.asiento_as_cob_asiento_id)
INNER JOIN MEDICO_COBRANZA AS MC ON (MC.medico_id = AC.as_cob_medico_id)
WHERE YEAR(A.asiento_fecha_oficial) = YEAR ( NOW() )";
$rawData = Yii::app()->db->createCommand($sql)->queryAll();
$arrayDataProvider = new CArrayDataProvider($rawData, array(
'keyField' => 'id', // PRIMARY KEY
'id' => 'PrestacionesIngresadas', // ID of the data provider itself
'sort'=> false,
'pagination' => false,
));
$this->render('prestacionesIngresadasMes', array(
'arrayDataProvider'=>$arrayDataProvider
));
}
y la vista
<?php
$this->widget('ext.groupgridview.GroupGridView', array(
'id'=>'data-grid',
'dataProvider'=>$arrayDataProvider,
'extraRowColumns' => array('ano'),
'extraRowPos' => 'below',
'extraRowTotals' => function($data, $row, &$totals) {
if(!isset($totals['suma_precio'])) $totals['suma_precio'] = 0;
$totals['suma_precio'] += $data['precio'];
$totals['sumaPrecioFormat'] = number_format($totals['suma_precio'] ,0,',', '.');
},
'extraRowExpression' => '"<table class=\"tabla-extrarow\">
<tr>
<td><span class=\"blod total\">TOTAL </span></td>
<td class=\"montos\">".$totals["sumaPrecioFormat"]."</td>
</tr></table>"',
'columns'=>array(
array(
'header'=>'RUT MÉDICOS',
'name'=>'rut',
'value'=>'$data["rut"]'
),
array(
'header'=>'NOMBRES MÉDICOS',
'name'=>'nombre',
'value'=>'$data["nombre"]'
),
array(
'header'=>'APELLIDOS MÉDICOS',
'name'=>'apellido',
'value'=>'$data["apellido"]'
),
array(
'header'=>'FECHA',
'name'=>'fecha',
'value'=>'$data["fecha"]'
),
array(
'header'=>'CODIGO PRESTACION',
'name'=>'codigo_prestacion',
'value'=>'$data["codigo_prestacion"]'
),
array(
'header'=>'NOMBRE PRESTACION',
'name'=>'nombre_prestacion',
'value'=>'$data["nombre_prestacion"]'
),
array(
'id'=>'precio_id',
'header'=>'PRECIO',
'name'=>'precio',
'value'=>'number_format($data["precio"],0,\',\', \'.\')'
),
),
));?>
Hasta ahi todo bien, pero necesito Exportarla a Excel y a PDF pero no me resulta
Para exportarla a ecxel lo tengo echo de la siguiente forma pero no me funciona
public function actionExportExcelPrestacionesIngresadasMes() {
header('Content-type: text/csv');
header('Content-Disposition: attachment; filename="Reporte-Estado-Cuenta-Cliente' . date('YmdHi') . '.csv"');
$model = new Asiento('search');
$model->unsetAttributes(); // clear any default values
if (Yii::app()->user->getState('exportModel2'))
$model = Yii::app()->user->getState('exportModel2');
$dataProvider = $arrayDataProvider;
$dataProvider->setPagination(false);
// csv header
echo Asiento::model()->getAttributeLabel("rut") . ";" .
Asiento::model()->getAttributeLabel("nombre") . ";" .
Asiento::model()->getAttributeLabel("apellido") . ";" .
Asiento::model()->getAttributeLabel("fecha") . ";" .
Asiento::model()->getAttributeLabel("codigo_prestacion") . ";" .
Asiento::model()->getAttributeLabel("nombre_prestacion") . ";" .
Asiento::model()->getAttributeLabel("precio") .
" \r\n";
// csv data
$data = $dataProvider->getData();
foreach($data as $row) {
echo $row["rut"] . ";";
echo $row["nombre"] . ";";
echo $row["apellido"] . ";";
echo $row["fecha"] . ";";
echo $row["codigo_prestacion"] . ";";
echo $row["nombre_prestacion"] . ";";
echo $row["precio"];
echo "\r\n";
}
exit;
}
SI alguien sabe cual seria la mejor forma de hacerlo ojalá me pueda ayudar se lo agradeceria demaciado
saludos de ante mano…