public function diezproductosmenosvendidosrepoAction()
    {
        $from = $this->_getParam('from');
        $to = $this->_getParam('to');
        $model = new Application_Model_DbTable_RelCartaVentas();
        $posts = $model->reporte_diez_productos_menos_vendidos($from, $to);
        $this->getHelper('layout')->disableLayout();
        $this->getHelper('ViewRenderer')->setNoRender();
        $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;
        }
        $tipo_reporte = '10 Productos Menos Vendidos';
        $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/>';
        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 . '  <div>
                                                            <table cellspacing="10%" cellpadding="10%" width=100%>
                                                                <tr align = center  BGCOLOR="ccff66">
                                                                    <td width="2%"><font><u>Id Producto</u></font></td>
                                                                <td width="2%"><font><u>Nombre</u></font></td>
                                                                <td width="2%"><font><u>Total de veces Vendido</u></font></td>

                                                                </tr>';
        if (count($posts)) {
            foreach ($posts as $tipo) {
                $content = $content . '<tr align="center" bgcolor="ffff99">';
                if ($tipo) {
                    $content = $content . '<td>' . $tipo->id_producto . '</td>';
                    $content = $content . '<td>' . $tipo->nombre . '</td>';
                    $content = $content . '<td>' . $tipo->cantidad . '</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 10 Productos Menos Vendidos.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);
                }
            }
        }
    }
 public function confirmarventaAction()
 {
     $form = new Application_Form_Buscarcliente();
     //recibe la lista de productos
     $listaproductos = $this->_getParam("products_selected");
     $model = new Application_Model_DbTable_CartaProductos();
     $puntos1 = $form->getValue('puntos');
     $productosbase = $model->getproductos();
     if ($this->getRequest()->isPost()) {
         //Calculo subtotal
         if ($form->isValid($this->_getAllParams())) {
             $sub_total = 0;
             $puntosventa = 0;
             foreach ($productosbase as $base) {
                 foreach ($listaproductos as $product) {
                     $chunks = explode('|', $product);
                     $product_id = $chunks[0];
                     if ($base->id_producto == $product_id) {
                         $product_qty = $chunks[1];
                         $product_price = $base->precio;
                         $puntosventa = $puntosventa + $base->puntos_producto * $product_qty;
                         $product_amount = $product_price * $product_qty;
                         $sub_total = $sub_total + $product_amount;
                     }
                 }
             }
             $fecha = new Zend_Db_Expr('NOW()');
             $id_usuario = $form->getvalue('cliente');
             $observacion = $form->getvalue('observacion');
             $mesa = $form->getvalue('mesa');
             $puntoscliente = $form->getvalue('puntos');
             $descuento = $form->getvalue('descuento');
             if ($puntoscliente >= 1000 && $descuento <= $puntoscliente && $sub_total >= $descuento) {
                 $descuento = $descuento;
                 //Descuento de puntos y venta
                 $sub_total = $sub_total - $descuento;
                 $puntoscliente = $puntoscliente - $descuento;
                 $puntosclientefinal = $puntoscliente + $puntosventa;
                 $modeluser = new Application_Model_DbTable_Usuarios();
                 $modeluser->editarpuntosacumulados($puntosclientefinal, $id_usuario);
             } else {
                 $descuento = 0;
                 $sub_total = $sub_total;
                 $puntosclientefinal = $puntoscliente + $puntosventa;
                 $modeluser = new Application_Model_DbTable_Usuarios();
                 $modeluser->editarpuntosacumulados($puntosclientefinal, $id_usuario);
             }
             $model = new Application_Model_DbTable_Ventas();
             //Agrego venta * validar
             $idventa = $model->crearventa($sub_total, $mesa, $fecha, $puntosventa, $descuento, $observacion, $id_usuario);
             //Integracion de productos a la tabla relacional ventas-productos
             foreach ($productosbase as $base) {
                 foreach ($listaproductos as $product) {
                     $chunks = explode('|', $product);
                     $product_id = $chunks[0];
                     if ($base->id_producto == $product_id) {
                         $product_qty = $chunks[1];
                         $modelorelacion = new Application_Model_DbTable_RelCartaVentas();
                         $modelorelacion->agregarProductosVenta($idventa, $product_id, $product_qty);
                     }
                 }
             }
             return $this->_redirect('/administrador');
         }
     }
     $this->view->element = $form;
     $this->view->punto = $puntos1;
     $this->view->productobase = $productosbase;
     $this->view->listaventa = $listaproductos;
 }