<?php
defined('_JEXECGS') or die ('ACCESO RESTRINGIDO');
ini_set('display_errors','On');
	session_start();
?>
<SCRIPT language="javascript">

          function addDetalle(tableID, valor1, valor2, valor3, valor4, valor5) {
			  //valor1-->codigo
			  //valor2-->nombre
			  //valor3-->cantidad
			  //valor4-->precio
			  //valor5-->total
			  
              if(valor2.length>0){
               var table = document.getElementById(tableID);
               var rowCount = table.rows.length;
               var row = table.insertRow(rowCount);
               var cell1 = row.insertCell(0);

               var element1 = document.createElement("input");
               element1.type = "text";
               if(valor1.length>0){
                   element1.setAttribute("value",valor1);
               }
               element1.setAttribute("class","map-ctrl-input");
               element1.setAttribute("size","12");
               element1.setAttribute("readonly","readonly");
               cell1.appendChild(element1);
              

               var cell2 = row.insertCell(1);
                
               var element2   = document.createElement("input");;
               element2.type = "text";
               if(valor2.length>0){
                   element2.setAttribute("value",valor2);
               }
               element2.setAttribute("class","map-ctrl-input");
               element2.setAttribute("size","46");
               element2.setAttribute("readonly","readonly");
               cell2.appendChild(element2);
               
               
               var cell3 = row.insertCell(2);

               var element3    = document.createElement("input");
                
               element3.type = "text";
               if(valor3>0){
                    element3.setAttribute("value",valor3);
               }
               element3.setAttribute("class","map-ctrl-input");
               element3.setAttribute("size","12");
              // element3.setAttribute("readonly","readonly");
               cell3.appendChild(element3);
               
               var cell4 = row.insertCell(3);
                
               var element4   = document.createElement("input");;
               element4.type = "text";
                if(valor4>0){
                   element4.setAttribute("value",valor4);
               }
                element4.setAttribute("class","map-ctrl-input");
                element4.setAttribute("size","12");
                element4.setAttribute("readonly","readonly");
                cell4.appendChild(element4);  

		var cell5 = row.insertCell(4);
                
               var element5   = document.createElement("input");;
               element5.type = "text";
                if(valor5>0){
                   element5.setAttribute("value",valor5);
               }
                element5.setAttribute("class","map-ctrl-input");
                element5.setAttribute("size","12");
                element5.setAttribute("readonly","readonly");
                cell5.appendChild(element5);  


                

              }
          }

function MET_anadir(){//valor1-->codigo
			  //valor2-->nombre
			  //valor3-->cantidad
			  //valor4-->precio
			  //valor5-->total
	var codigo = document.getElementById('txtCodItem').value;
	var nombre = document.getElementById('txtNomItem').value;
	var cantidad = parseFloat(document.getElementById('txtCantidad').value);
	var precio = parseFloat(document.getElementById('txtPrecio').value);
	var total = (parseFloat(precio) * parseFloat(cantidad));
	if(total>0){
		addDetalle("tblDetDetConKardex", codigo, nombre, cantidad, precio, total);
	}else{
		alert("Debe seleccionar un producto");
	}
}
		  
</script>
<form method="post" name="frm" id="frm" autocomplete="off">
<table>
<h2>Gestor de pedidos</h2>
<table>
<tr>
<td>
<p>C&oacute;digo</p>
</td>
<td>
<input name="txtCodigo" type="text" class="txt_textbox" disabled="disabled" id="txtCodigo" size="25" title="No usar espacios en blanco" value="<?php echo (isset($reg))?$reg['cod_pedido']:''; ?>" />
</td>
</tr>

<tr>
<td>
<p>Fecha</p>
</td>
<td>
<input name="txtFecha" type="text" class="txt_textbox" disabled="disabled" id="txtFecha" size="25" title="No usar espacios en blanco" value="<?php echo (isset($reg))?$reg['fec_pedido']:''; ?>"  />
</td>
</tr>

<tr>
<td>
<p>Observaci&oacute;n</p>
</td>
<td>
 <textarea rows="4" cols="26" name="txtObservacion" id="txtObservacion">
<?php echo (isset($reg))?$reg['obs_pedido']:''; ?>
</textarea> 
</td>
</tr>

<tr>
<td>
<p>Total</p>
</td>
<td>
<input name="txtTotal" type="text" class="txt_textbox" id="txtTotal" disabled="disabled" size="25" title="No usar espacios en blanco" value="<?php echo (isset($reg))?$reg['val_total']:''; ?>"  />
</td>
</tr>

<tr>
<td>
<p><h3>Adicionar productos</h3></p>
</td>
</tr>

<tr>
<td colspan="2">
<input name="txtCodItem" type="text" class="txt_textbox" id="txtCodItem" disabled="disabled" size="10" title="No usar espacios en blanco" value="48090"  />
<input name="txtNomItem" type="text" class="txt_textbox" id="txtNomItem" disabled="disabled" size="50" title="No usar espacios en blanco" value="ZAPATO NEGRO S/N"  />
<input name="txtPrecio" type="text" class="txt_textbox" id="txtPrecio" disabled="disabled" size="10" title="No usar espacios en blanco" value="12.25"  />
<input name="txtCantidad" type="text" class="txt_textbox" id="txtCantidad" disabled="disabled" size="10" title="No usar espacios en blanco" value="2"/>
<img width="16px" height="16px" src="/shine/images/add.png" onclick="MET_anadir();">
</td>
</tr>


<table id="tblCabDetalle" height="20px"  border="0">
	<tr>
		<th bgcolor="#f0f0f0" width="100px">Codigo</th>
		<th bgcolor="#f0f0f0" width="300px">Nombre</th>
		<th bgcolor="#f0f0f0" width="100px">Cantidad</th>
		<th bgcolor="#f0f0f0" width="100px">Precio</th>
		<th bgcolor="#f0f0f0" width="100px">Total</th>
	</tr>
</table>
<table name="tblDetDetConKardex" id="tblDetDetConKardex" height="20px" width="50%" border="0"></table>
<input type="text" value="texto">
<table>
<tr>
<td colspan="2" style="text-align:right;">
<input name="btn_ingresar" type="button" class="txt_textbox" id="btn_ingresar" value="Grabar" style="width:70px" onClick="MET_grabar();" />
</td>
</tr>
</table>



</table>


</table>
</form>

<SCRIPT language="javascript">
function MET_grabar(){
	var ruta = 'controller/ctrlPedido.php?opt=grabar';	
		document.frm.action = ruta;
		document.frm.submit();
}
</script>