PHP - Ayuda codigo para crear una factura

 
Vista:
sin imagen de perfil

Ayuda codigo para crear una factura

Publicado por fdoalvarezc (3 intervenciones) el 08/01/2015 23:38:23
Amigos soy nuevo en esto, pero tengo el problema que no puedo sacar el precio y asignarlo a un textbox al seleccionar un producto.

Les dejo mi codigo:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<?php
session_start();
include "sesion.php";
?>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
 
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jquery.addfield2.js"></script>
 
 
<?php
function generaProducto()
{
   //$coneccion1=mysql_connect("localhost", "root", "") or die(mysql_error()); 
   //mysql_select_db("sergafor", $coneccion1) or die(mysql_error()); 
   $consulta1=mysql_query("SELECT * FROM productos WHERE stock>0 ORDER BY producto");
   echo "<select class='combo' name='producto[]' style='width:220px'>","<option value=''>seleccione</option>";
   while($registro1=mysql_fetch_row($consulta1))
   {
      echo "<option value='".$registro1[0]."'>".$registro1[1]." - ".$registro1[3]."</option> ";
   }
   echo "</select>";
 
}
?>
 
 
 
<?php
function generaUnidad()
{
   //$coneccion1=mysql_connect("localhost", "root", "") or die(mysql_error()); 
   //mysql_select_db("sergafor", $coneccion1) or die(mysql_error()); 
   $consulta1=mysql_query("SELECT * FROM medidas ORDER BY medidas");
   echo "<select class='combo' name='unidad[]' style='width:90px'>","<option value=''>seleccione</option>";
   while($registro1=mysql_fetch_row($consulta1))
   {
      echo "<option value='".$registro1[0]."'>".$registro1[1]."</option> ";
   }
   echo "</select>";
}
 
 
 
?>
 
<script language="javascript" type="text/javascript">
 
    function Solo_Numerico(variable){
        Numer=(variable);
        if (isNaN(variable)){
            return "";
        }
        return Numer;
    }
    function ValNumero(Control){
        Control.value=Solo_Numerico(Control.value);
    }
</script>
 
<script language="javascript">
function marcado(){
if (document.form.termin.checked) {
document.form.submit();
     }
	 else{
	 alert("Debe aceptar la venta ingresada");
	  document.form.termin.focus();
       return false;
	 }
 
}
</script>
 
 
</head>
 
<body onload="form.id.focus()" topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0" marginwidth="50" marginheight="50">
 
<?php
include "llama_menu.php";
$fecha = $_REQUEST['fecha'];
$guia = $_REQUEST['guia'];
$id = $_REQUEST['run'];
 
echo "<BR>";
echo ("</font><font face='arial' size='3' color='BLACK'> DESPACHO DE MADERAS</font>\n <br>");
 
if ($fecha == "" OR $guia == "" OR $id == "" ) {
	echo "<br>";
	echo ("<font face='arial' size='3' color='black'>Fecha:</font><font face='arial' size='3' color='green'> ". $fecha ."</font>\n <br>");
	echo ("<font face='arial' size='3' color='black'>Guia:</font><font face='arial' size=3' color='green'> ". $guia."</font>\n <br>");
	echo ("<font face='arial' size='3' color='black'>Rut:</font><font face='arial' size='3' color='green'> ". $run."</font>\n <br>");
	echo "<br>";
	echo ("<font face='arial' size='3' color='red'>Faltan datos obligatorios para continuar</font>\n <br>");
	echo "<br>";
	?>
	<a href="javascript:history.go(-1);"><font size="2" face="Arial, Helvetica, sans-serif">Volver al formulario</font></a>
    <?PHP
} else {
 
	 $cinstruccion = "select * from venta where guia='". $guia ."'";
	 $cconsulta = mysql_query ($cinstruccion, $con) or die ("Fallo en la consulta guia");
     $cresultado = mysql_fetch_array ($cconsulta);
     if ($cresultado['guia']==$guia) {
		 echo "<BR>";
	 	 ?>
		 <a href="javascript:history.go(-1);"><font size="2" face="Arial, Helvetica, sans-serif">Nº de guía ya existe, volver atrás</font></a>
		 <?PHP
	} else {
		?>
		<form id="form" name="form" method="post" action="venta.php" onsubmit="return marcado();">
		<input name="fecha" type="hidden" value="<?php echo $fecha; ?>" >
		<input name="guia" type="hidden" value="<?php echo $guia; ?>" >
		<?PHP
		echo "<BR>";
		echo ("<font face='arial' size='3' color='blue'>DATOS CLIENTE</font><br>");
		echo "<BR>";
		$instruccion = "select * from clientes where id=$id";
		$consulta = mysql_query ($instruccion, $con) or die ("Fallo en la consulta");
		$nfilas = mysql_num_rows ($consulta);
		if ($nfilas == 0) {
			?>
			  <table width="100%" border="0">
			  <tr>
				<td><font size="2" face="Arial, Helvetica, sans-serif">Fecha</font></td>
				<td><?php echo "<font face='arial' size='2' color='green'>".$fecha; ?></td>
			  </tr>
			  <tr>
				<td><font size="2" face="Arial, Helvetica, sans-serif">Nº Guía</font></td>
				<td><?php echo "<font face='arial' size='2' color='green'>".$guia; ?></td>
			  </tr>
			  <tr>
				<td><font size="2" face="Arial, Helvetica, sans-serif">Run</font></td>
				<td><input name="id" required type="text" value="<?php echo $id; ?>" size="70"></td>
			  </tr>
			  <tr>
				<td><font size="2" face="Arial, Helvetica, sans-serif">Nombre</font></td>
				<td><input name="nombre" required type="text" size="70"></td>
			  </tr>
			  <tr>
				<td><font size="2" face="Arial, Helvetica, sans-serif">Dirección</font></td>
				<td><input name="direccion" required type="text" size="70">		</td>
			  </tr>
			  <tr>
				<td><font size="2" face="Arial, Helvetica, sans-serif">Teléfono</font></td>
				<td><input name="fono" required onkeyUp="return ValNumero(this);" type="text" size="70"></td>
			  </tr>
			  <tr>
				<td><font size="2" face="Arial, Helvetica, sans-serif">Email</font></td>
				<td><input name="email" type="text" size="70"></td>
			  </tr>
			</table>
			<?PHP
		} else {
			$resultado = mysql_fetch_array ($consulta);
			?>
			  <table width="100%" border="0">
			  <tr>
				<td><font size="2" face="Arial, Helvetica, sans-serif">Fecha</font></td>
				<td><?php echo "<font face='arial' size='2' color='green'>".$fecha; ?></td>
			  </tr>
			  <tr>
				<td><font size="2" face="Arial, Helvetica, sans-serif">Nº Guía</font></td>
				<td><?php echo "<font face='arial' size='2' color='green'>".$guia; ?></td>
			  </tr>
			  <tr>
				<td><font size="2" face="Arial, Helvetica, sans-serif">Run</font></td>
				<td><?php echo "<font face='arial' size='2' color='green'>".$resultado['id']; ?>
					<input name="id" type="hidden" value="<?php echo $resultado['id']; ?>" size="70">
				</td>
			  </tr>
			  <tr>
				<td><font size="2" face="Arial, Helvetica, sans-serif">Nombre</font></td>
				<td><input name="nombre" required type="text" value="<?php echo $resultado['nombre']; ?>" size="70"></td>
			  </tr>
			  <tr>
				<td><font size="2" face="Arial, Helvetica, sans-serif">Dirección</font></td>
				<td><input name="direccion" required type="text" value="<?php echo $resultado['direccion']; ?>" size="70">		</td>
			  </tr>
			  <tr>
				<td><font size="2" face="Arial, Helvetica, sans-serif">Teléfono</font></td>
				<td><input name="fono" required type="text" onkeyUp="return ValNumero(this);" value="<?php echo $resultado['fono']; ?>" size="70"></td>
			  </tr>
			  <tr>
				<td><font size="2" face="Arial, Helvetica, sans-serif">Email</font></td>
				<td><input name="email" type="text" value="<?php echo $resultado['email']; ?>" size="70"></td>
			  </tr>
			</table>
			<?PHP
		}
		// Detalle compra
		?>
		<p><font color="#0000FF" face="Arial, Helvetica, sans-serif">DETALLE</font></p>
		<div id="div_1"> <span style="float:left;padding: 0px 0px 0px 0px;"> </span>
		<font size="2" face="Arial, Helvetica, sans-serif">Producto</font>
		<?php generaProducto(); ?>
		<font size="2" face="Arial, Helvetica, sans-serif">Cant.</font>
		<input type="text" name="cantidad[]" required onkeyup="calc()" style="width:100px;" />
		<font size="2" face="Arial, Helvetica, sans-serif">Unidad</font>
		<?php generaUnidad(); ?>
		<font size="2" face="Arial, Helvetica, sans-serif">Precio Venta</font>
		<input type="text" name="precio[]" required onkeyup="calc()" style="width:90px;" />
		<input class="bt_plus" id="1" type="button" value="+" />
		</div>
 
 
		<div id="total"></div>
		<script>
			function calc()
			{
			var form = document.form;
			document.getElementById("total").innerHTML = Number(form.cantidad[].value) * Number(form.precio[].value);
			}
		</script>
 
 
  <input type="checkbox" value="1" name="termin" id="termin" /><font size="2" face="Arial, Helvetica, sans-serif">Aceptar venta
		<font size="2" face="Arial, Helvetica, sans-serif"><button type="submit" class="boton">Enviar</button>
		</font><div class="spacer"></div>
		</form>
		<?php
	}
}
 ?>
 
</body>
</html>

Sin-titulo
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil

Ayuda codigo para crear una factura

Publicado por fernando (3 intervenciones) el 09/01/2015 00:34:56
Amigos para reducir el codigo el problema lo tengo aquí:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php
function generaProducto()
{
//$coneccion1=mysql_connect("localhost", "root", "") or die(mysql_error()); 
//mysql_select_db("sergafor", $coneccion1) or die(mysql_error()); 
$consulta1=mysql_query("SELECT * FROM productos WHERE stock>0 ORDER BY producto");
echo "<select class='combo' name='producto[]' style='width:220px'>","<option value=''>seleccione</option>";
while($registro1=mysql_fetch_row($consulta1))
{
echo "<option value='".$registro1[0]."'>".$registro1[1]." - ".$registro1[3]."</option> ";
}
echo "</select>";
 
}
?>


Como hago el onchange para que me deje el valor en el arreglo precio[], cuando le saco los corchetes funciona pero al agregar mas productos no funciona.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de xve
Val: 3.943
Oro
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

Ayuda codigo para crear una factura

Publicado por xve (6935 intervenciones) el 09/01/2015 08:19:06
Hola Fernando, no entiendo muy bien lo que quieres hacer... en principio, cuando envíes los valores del formulario, ya tendrás todos los valores, no? no hace falta copiarlos al array precio[].

No se si se muy bien que es lo que quieres hacer...
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Ayuda codigo para crear una factura

Publicado por FERNANDO ALVAREZ CONEJEROS (3 intervenciones) el 09/01/2015 12:34:30
Asignar el precio del producto seleccionado a un textbox. Lo hace solo con el primero,


<select name="producto[]" id="producto" onchange="form.precio.value=this.options[this.selectedIndex].getAttribute('precio')">
<option value="">seleccionar</option>

<?php
while ($row = mysql_fetch_assoc($result)){
?>
<option value="<?php echo $row['id'] ?>" producto="<?php echo $row['producto'] ?>" precio="<?php echo $row['precio'] ?>"> <?php echo $row['producto'] ?></option>
<?php
}
?>
</select>


<input type="text" name="precio[]" id="precio" onkeyUp="return ValNumero(this);" style="width:90px;"/>

Puedes ingresar a la siguiente pagina

www.sergafor.cl

usuario dgodoy
pass 12345

menu: movimiento - despacho - ingreso

Gracias por responder
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar