public function ventasclienterepoAction() { $id_cliente = $this->_getParam('id'); $from = $this->_getParam('from'); $to = $this->_getParam('to'); $idUsuario = Zend_Registry::get('id_usuario'); $modelUser = new Application_Model_DbTable_Usuarios(); $datosAdmin = $modelUser->traerdatosclienteID($idUsuario); foreach ($datosAdmin as $admin) { $nombreAdmin = $admin->nombre; $apellidoAdmin = $admin->apellido; } $model = new Application_Model_DbTable_Ventas(); $posts = $model->reporte_venta_cliente($id_cliente, $from, $to); $this->getHelper('layout')->disableLayout(); $this->getHelper('ViewRenderer')->setNoRender(); $tipo_reporte = 'Reporte Ventas por Usuario'; $content = '<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Reportes - Capicua Restobar.</title> </head> <body>' . '<img width=100% height=50px src="images/top_footer.jpg"/> <br/><br/> <h3><center>' . $tipo_reporte . '</center></h3>' . '<br/> <strong><u>Administrador : </u></strong>' . ' ' . $nombreAdmin . ' ' . $apellidoAdmin . '<br/> <strong><u>Fecha : </u></strong>' . ' ' . date("d/m/Y H:i") . '<br/> <div>'; if ($from || $to) { $content = $content . ' <hr> <li> <p>Desde: ' . $from . '</p> </li> <li> <p>Hasta: ' . $to . '</p> </li>'; } else { $content = $content . ' <h3> Reporte Historico</h3>'; } $content = $content . '<table cellspacing="10%" cellpadding="10%" width=100%> <tr align = center BGCOLOR="ccff66"> <td width="2%"><font><u>Nombre</u></font></td> <td width="2%"><font><u>Fecha</u></font></td> <td width="2%"><font><u>Descuento Hecho</u></font></td> <td width="2%"><font><u>Puntos Venta</u></font></td> <td width="2%"><font><u>Total Venta</u></font></td> <td width="2%"><font><u>Cantidad</u></font></td> <td width="2%"><font><u>Producto</u></font></td> <td width="2%"><font><u>Precio Unitario</u></font></td> </tr>'; $id_prueba = 0; $fecha = 0; $total = 0; if (count($posts)) { foreach ($posts as $post) { $content = $content . '<tr align="center" bgcolor="ffff99">'; if ($post->id_usuario != $id_prueba) { $id_prueba = $post->id_usuario; $content = $content . '<td>' . $post->cliente . ' ' . $post->apellido . '</td>'; } else { $content = $content . '<td></td>'; } if ($post->fecha != $fecha) { $date = $post->fecha; $dia = explode("-", $date, 3); $year = $dia[0]; $month = (string) (int) $dia[1]; $month2 = str_pad((int) $month, 2, "0", STR_PAD_LEFT); $day = (string) (int) $dia[2]; $day2 = str_pad((int) $day, 2, "0", STR_PAD_LEFT); $time = explode(":", $date, 3); $hora = explode(" ", $time[0], 2); $min = (string) (int) $time[1]; $min2 = str_pad((int) $min, 2, "0", STR_PAD_LEFT); $fecha = $post->fecha; // Verificacion de no Repeticion $content = $content . '<td>' . $day2 . " -" . $month2 . " - " . $year . " " . "/" . " " . $hora[1] . ":" . $min2 . '</td>'; } else { $content = $content . '<td></td>'; } if ($post->total != $total) { $total = $post->total; $content = $content . '<td>' . $post->descuento . '</td>'; $content = $content . '<td>' . $post->puntos_venta . '</td>'; $content = $content . '<td>' . $post->total . '</td>'; } else { $content = $content . '<td></td>'; $content = $content . '<td></td>'; $content = $content . '<td></td>'; } $content = $content . '<td>' . $post->cantidad_producto . '</td>'; $content = $content . '<td>' . $post->nombre . '</td>'; $content = $content . '<td>' . $post->precio . '</td>'; $content = $content . '</tr>'; } } else { $content = $content . ' <tr> <td colspan="3">No hay datos</td> </tr>'; } $content = $content . '</table><div></body></html>'; if ($content != '') { //Añadimos la extensión del archivo. Si está vacío el nombre lo creamos $path = 'Reporte-Ventas_' . date("d/m/Y H:i") . '.pdf'; //Las opciones del papel del PDF. Si no existen se asignan las siguientes:[*] $paper_1 = 'a4'; $paper_2 = 'portrait'; $dompdf = new DOMPDF(); $dompdf->set_paper($paper_1, $paper_2); $dompdf->load_html(utf8_encode($content)); //ini_set("memory_limit","32M"); //opcional $dompdf->render(); $mode = false; //Creamos el pdf if ($mode == false) { $dompdf->stream($path); } //Lo guardamos en un directorio y lo mostramos if ($mode == true) { if (file_put_contents($path, $dompdf->output())) { header('Location: ' . $path); } } } }