Ver Mensaje Individual
  #3 (permalink)  
Antiguo 01/02/2011, 23:06
Avatar de anacona16
anacona16
 
Fecha de Ingreso: marzo-2010
Ubicación: Bogota DC
Mensajes: 610
Antigüedad: 14 años, 1 mes
Puntos: 52
Respuesta: Ayuda para llenar factura

Grcias solrakmnk por tu sugerencia y consejo, espero sigas ayudandome, esto es lo que tengo hecho:

http://jamak.jjsystem.net.co/php/vis...cturar_new.php

Este es el codigo:

Código PHP:
Ver original
  1. <?php
  2.     session_start();
  3.     include'../include/funciones.php';
  4.     include'../session/validar.php';
  5.    
  6.     //validar('../../index.php');
  7.    
  8.     include'../include/sql.php';
  9.     include'../include/page_bottom.php';
  10.    
  11.     $sql = new MySQL();
  12.    
  13.     $lineas = 23;
  14.    
  15.     //Fecha actual
  16.     $hoy = date("Y-m-d");
  17.    
  18.     //Fecha vencimiento
  19.     $vencimiento = date('Y-m-d', strtotime('+1 month'.$hoy));
  20.    
  21.     //Consulto datos del proveedor para mostrar en el combo
  22.     $cliente = $sql->consulta("SELECT * FROM tb_clientes");
  23.    
  24.     ///Consulto el ultimo codigo de la factura
  25.     $consulta_cod_factura = $sql->consulta("SELECT MAX(codifact) AS codifact FROM tb_facturas");
  26.     //Le sumo + 1 por ejemplo la factura 083 + 1 da 084 y esa seria la factura actual
  27.     $resultado_cod_factura = $sql->fetch_array($consulta_cod_factura);
  28.     $codfactura = $resultado_cod_factura['codifact'] + 1;
  29. ?>
  30. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  31. <html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/index.dwt.php" codeOutsideHTMLIsLocked="false" -->
  32. <head>
  33. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  34. <!-- InstanceBeginEditable name="doctitle" -->
  35. <title>Johana 0.1 - Factura de Venta</title>
  36. <!-- InstanceEndEditable -->
  37. <link href="../../css/sytle.css" rel="stylesheet" type="text/css" />
  38. <link rel="shortcut icon" href="../../img/icono.ico" />
  39. <script type="text/javascript" src="../../scripts/history.js"></script>
  40. <!-- InstanceBeginEditable name="head" -->
  41. <link href="../../css/grilla.css" rel="stylesheet" type="text/css" />
  42. <link href="../../css/validate.css" rel="stylesheet" type="text/css" />
  43. <link rel="stylesheet" type="text/css" href="../../css/tiger/theme.css"/>
  44. <link rel="stylesheet" type="text/css" href="../../css/jquery-ui-1.8.9.custom.css"/>
  45.  
  46. <script type="text/javascript" src="../../scripts/jquery/jquery-1.4.4.min.js"></script>
  47. <script type="text/javascript" src="../../scripts/jquery/jquery-ui-1.8.9.custom.min.js"></script>
  48. <script type="text/javascript" src="../../scripts/calendario/calendar.js"></script>
  49. <script type="text/javascript" src="../../scripts/calendario/calendar-es.js"></script>
  50. <script type="text/javascript" src="../../scripts/calendario/calendar-setup.js"></script>
  51.  
  52. <script type="text/javascript">
  53.    
  54.     $(function(){
  55.         $('#referencia').autocomplete({
  56.             source : '../modelos/sugerencias_productos.php',
  57.             select: function(event, ui) {
  58.                 $("#descripcion").val(ui.item.descripcion);
  59.                 $("#valor").val(ui.item.valor);
  60.             },
  61.         });
  62.     });
  63.    
  64.     window.onload = function() {
  65.         Calendar.setup({inputField: "fecha", ifFormat: "%Y-%m-%d",button: "selector"});
  66.         Calendar.setup({inputField: "vencimiento", ifFormat: "%Y-%m-%d",button: "selector2"});
  67.     }
  68.    
  69.     function change_fecha(){
  70.       if(document.form.cmbfpago.selectedIndex == 1){
  71.           document.form.vencimiento.value = '<?php echo $hoy ?>';
  72.       }
  73.       else{
  74.           document.form.vencimiento.value = '<?php echo $vencimiento ?>';
  75.       }
  76.     }
  77.    
  78.     function agregar()
  79.     {        
  80.         if(document.form.referencia.value != "" && document.form.cantidad.value != "" && document.form.descripcion.value != "" && document.form.valor.value != "" &&document.form.descuento.value != ""){
  81.            
  82.             <?php $indice = 0 ?>
  83.            
  84.             document.form.cant<?php echo $indice ?>.style.visibility = 'visible';
  85.             document.form.refeprod<?php echo $indice ?>.style.visibility = 'visible';
  86.             document.form.desc<?php echo $indice ?>.style.visibility = 'visible';
  87.             document.form.valor<?php echo $indice ?>.style.visibility = 'visible';
  88.             document.form.valortotal<?php echo $indice ?>.style.visibility = 'visible';
  89.        
  90.             document.form.cant<?php echo $indice ?>.value = document.form.cantidad.value;
  91.             document.form.refeprod<?php echo $indice ?>.value = document.form.referencia.value;
  92.             document.form.desc<?php echo $indice ?>.value = document.form.descripcion.value;
  93.             document.form.valor<?php echo $indice ?>.value = document.form.valor.value;
  94.            
  95.            
  96.             cantidad = document.form.cantidad.value;
  97.             descuento = (document.form.descuento.value/100);
  98.             valor = document.form.valor.value;
  99.             porcentaje = valor * descuento;
  100.             valor_parcial = valor - porcentaje;
  101.             valor_final = cantidad * valor_parcial;    
  102.            
  103.             document.form.valortotal<?php echo $indice ?>.value = valor_final;
  104.            
  105.             <?php echo $indice++ ?>
  106.            
  107.             document.form.cantidad.value = "";
  108.             document.form.referencia.value = "";
  109.             document.form.descripcion.value = "";
  110.             document.form.valor.value = "";
  111.             document.form.descuento.value = "";        
  112.         }else{
  113.             alert('Complete todos los campos antes de agregar el producto a la factura');
  114.         }
  115.     }
  116.    
  117. </script>
  118.  
  119. <!-- InstanceEndEditable -->
  120. </head>
  121.  
  122. <body>
  123. <div id="header">Empresa</div>
  124. <div id="boton_atras"><a href="panel.php"><img src="http://www.forosdelweb.com/img/home.png" width="16" height="16" alt="Inicio" /></a>&nbsp;<img src="http://www.forosdelweb.com/img/back.png" width="16" height="16" alt="Atras" onclick="nav(-1)" style="cursor:pointer" /></div>
  125. <div id="datos_login">
  126.     Bienvenido <strong><?php echo $_SESSION['descusua'] ?></strong> | <strong><?php echo $_SESSION['rollusua'] ?></strong> <a href="#" title="Opciones de Cuenta"><img src="http://www.forosdelweb.com/img/opciones.png" width="16" height="16" alt="Opciones de Cuenta" /></a>&nbsp;<a href="http://www.forosdelweb.com/f18/session/logout.php" title="Cerrar Sesi&oacute;n"><img src="http://www.forosdelweb.com/img/salir.png" width="16" height="16" alt="Cerrar Sesi&oacute;n" /></a>
  127. </div>
  128. <div class="cleaner"></div>
  129. <!-- InstanceBeginEditable name="Contenido" -->
  130. <fieldset>
  131.   <legend>Factura de venta<!--../modelos/generar_comprobante.php-->  </legend>
  132.   <form action="../modelos/generar_comprobante.php" method="post" enctype="multipart/form-data" name="form" id="form">
  133.     <br />
  134.     <br />
  135.     <table width="90%" border="0" align="center" class="table">
  136.       <tr align="center" class="td_bg">
  137.         <td height="30"><strong>Codigo/Referencia</strong></td>
  138.         <td><strong>Cantidad</strong></td>
  139.         <td><strong>Descripci&oacute;n/Aplicaci&oacute;n</strong></td>
  140.         <td><strong>Valor UNIT.</strong></td>
  141.         <td><strong>Descuento</strong></td>
  142.         <td>&nbsp;</td>
  143.       </tr>
  144.       <tr align="center">
  145.         <td><input name="referencia" type="text" class="valid_field" id="referencia" autocomplete="off" /></td>
  146.         <td><input name="cantidad" type="text" class="valid_field" id="cantidad" size="2" autocomplete="off" /></td>
  147.         <td><input name="descripcion" type="text" class="valid_field" id="descripcion" size="70" autocomplete="off" /></td>
  148.         <td><input name="valor" type="text" class="valid_field" id="valor" size="20" autocomplete="off" /></td>
  149.         <td><input name="descuento" type="text" class="valid_field" id="descuento" size="3" autocomplete="off" />%</td>
  150.        
  151.        
  152.        
  153.         <td><img src="http://www.forosdelweb.com/img/grilla/add.png" width="16" height="16" alt="A&ntilde;adir producto" onclick="agregar()" /></td>
  154.       </tr>
  155.     </table>
  156.     <br />
  157.     <br />
  158.     <table width="90%" border="0" align="center" class="table">
  159.     <tr align="center" valign="middle" class="td_bg">
  160.         <td height="30"><strong>Cant</strong></td>
  161.         <td><strong>Codigo/Referencia</strong></td>
  162.         <td><strong>Descripci&oacute;n/Aplicaci&oacute;n</strong></td>
  163.         <td><strong>Valor UNIT.</strong></td>
  164.         <td><strong>Valor TOTAL</strong></td>
  165.       </tr>
  166.     <?php for ($i = 0; $i < $lineas; $i++): ?>
  167.       <tr align="center">
  168.         <td><input name="cant<?php echo $i ?>" type="text" class="field_factura" id="cant<?php echo $i ?>" style="visibility:hidden" size="2" readonly="readonly" /></td>
  169.         <td><input name="refeprod<?php echo $i ?>" type="text" class="field_factura" id="refeprod<?php echo $i ?>" style="visibility:hidden" readonly="readonly" /></td>
  170.         <td><input name="desc<?php echo $i ?>" type="text" class="field_factura" id="desc<?php echo $i ?>" style="visibility:hidden" size="70" readonly="readonly" /></td>
  171.         <td><input name="valor<?php echo $i ?>" type="text" class="field_factura" id="valor<?php echo $i ?>" style="visibility:hidden" size="20" readonly="readonly" /></td>
  172.         <td><input name="valortotal<?php echo $i ?>" type="text" class="field_factura" id="valortotal<?php echo $i ?>" style="visibility:hidden" size="20" readonly="readonly" /></td>
  173.       </tr>
  174.     <?php endfor; ?>
  175.     </table>
  176.   </form>
  177. </fieldset>
  178. <!-- InstanceEndEditable -->
  179. <div class="cleaner"></div>
  180. <div id="content_bottom">
  181.     <?php bottom_page(); ?>
  182. </div>
  183. <!-- InstanceBeginEditable name="Paginacion" -->
  184. <!-- InstanceEndEditable -->
  185. </body>
  186. <!-- InstanceEnd -->
  187. </html>

Si miran el ejemplo en el link que les pase, se daran cuenta que el primer producto lo agrega, pero para el segundo ya remplaza el primero.

Yo imprimo en un for los campos donde van los poductos, que estan ocultos con un estilo y sin borde.

Espero me entiendan y puedan ayudarme, gracias.

Última edición por GatorV; 22/03/2011 a las 15:58