<?php
class OrdenController extends Zend_Controller_Action{
protected $logger;
private $orden;
private $orden_n; //orden nueva
public function init(){
$this->logger = Zend_Registry::get('logger');
}
public function preDispatch(){
//Zend_Session::destroy();
}
public function indexAction(){
$this->view->titulo = 'Orden de Compras';
}
public function agregarAction(){
$this->orden = new Zend_Session_Namespace('orden');
($this->orden->cont == null)?$this->orden->cont=0:$this->orden->cont=$this->orden->cont;
$this->orden->cont = $this->orden->cont + 1;
$this->orden->id[$i] = $this->_getParam('id');
$this->orden->nombre[$i] = $this->_getParam('nombre');
$this->orden->precio[$i] = $this->_getParam('precio');
$this->orden->cantidad[$i] = $this->_getParam('cantidad');
$this->_helper->viewRenderer->setNoRender();
$this->_helper->layout->disableLayout();
}
public function quitarAction(){
$x = 1;
$this->_helper->viewRenderer->setNoRender();
$this->_helper->layout->disableLayout();
try{
Zend_Session::namespaceUnset('orden');
Zend_Session::namespaceUnset('orden_n');
}catch(Exception $e){
$this->logger->log("UNSET SESION ".$e->getMessage(),Zend_Log
::ERR); }
$this->orden = new Zend_Session_Namespace('orden');
$this->orden_n = new Zend_Session_Namespace('orden_n');
for($i=1; $i<= $this->orden->cont; $i++){
if($this->orden->id[$i] != $this->_getParam('id')){
$this->orden_n->id[$x]= $this->orden->id[$i];
$this->orden_n->nombre[$x]= $this->orden->nombre[$i];
$this->orden_n->precio[$x]= $this->orden->precio[$i];
$this->orden_n->cantidad[$x]= $this->orden->cantidad[$i];
$this->orden_n->cont= $x;
$x+=1;
}
}
$this->orden = new Zend_Session_Namespace('orden');
for($i=1; $i<= $this->orden_n->cont; $i++){
$this->orden->id[$i]= $this->orden_n->id[$i];
$this->orden->nombre[$i]= $this->orden_n->nombre[$i];
$this->orden->precio[$i]= $this->orden_n->precio[$i];
$this->orden->cantidad[$i]= $this->orden_n->cantidad[$i];
$this->orden->cont= $i;
}
}
public function preventaAction(){
$this->_helper->viewRenderer->setNoRender();
$this->_helper->layout->disableLayout();
$this->orden = new Zend_Session_Namespace('orden');
$tabla="<div style='font-family:Verdana' align='right'><a href='http://192.168.40.100/pruebajax/public/orden/reset' id='nuevaorden'>Nueva Orden</a></div>";
$tabla.="<br/><div style='font-family:Verdana;font-size:11px;' align='center'>
<table width='80%' border='1' style='border-collapse:collapse'>";
$tabla.="<thead style='background-color:#BBBBBB'><tr><th>ITEM</th><th>DESCRIPCION</th><th>CANTIDAD</th><th>PRECIO</th><th>MONTO</th><th> </th></tr></thead>";
for($i=1; $i <= $this->orden->cont; $i++){
$tabla.="<tr><td>".$i."</td>
<td>".$this->orden->nombre[$i]."</td>
<td align='center' width='8%'>
<input type='text' name='cantidad[".$i."]'
value='".$this->orden->cantidad[$i]."' size='8' style='text-align:right'/></td>
<td align='right'>".number_format($this->orden->precio[$i],2,'.',',')."</td> <td align='right'>S/. ".number_format($this->orden->precio[$i]*$this->orden->cantidad[$i],2,'.',',')."</td> <td align='center'><a href='' title='Quitar del Pedido' onclick='quitar(".$this->orden->id[$i].",event)'>
<img src='http://192.168.40.100/pruebajax/public/img/drop.gif' style='border:0px'
/></a></td>
</tr>";
$total += $this->orden->precio[$i]*$this->orden->cantidad[$i];
}
$this->orden->monto = $total;
$tabla.="<tr><td colspan='4' align='right' style='font-weight:bold;padding-right:25px'>TOTAL</td><td align='right'>S/. ".number_format($total,2,'.',',')."</td> <td align='center'>
<input type='image' title='Recalcular Orden' src='http://192.168.40.100/pruebajax/public/img/refrescar.png' style='border:0px'
onclick='recalcular()' /></td>
</tr></table><br/>
<div align='center'><a href='http://192.168.40.100/pruebajax/public/orden/grabar' style='text-decoration:none'>
<img src='http://192.168.40.100/pruebajax/public/img/icono_compras.gif' style='border:0px' />
<b style='color:#D82729'> Finalizar Compra</b></a></div>";
echo $tabla;
}
public function recalculoAction(){
$this->orden = new Zend_Session_Namespace('orden');
$cantidad = $this->_getParam('cantidad');
for($i=1;$i<= $this->orden->cont;$i++){
if($cantidad[$i] != $this->orden->cantidad[$i]){
$this->orden->cantidad[$i] = $cantidad[$i];
}
}
$this->_redirect('producto/listar');
}
public function grabarAction(){
$this->orden = new Zend_Session_Namespace('orden');
$ordenes = new Model_DbTable_Orden();
$res = $ordenes->grabar();
$this->logger->log("respuesta ".$res,Zend_Log
::INFO); //$this->_redirect('producto/listar');
}
}