0% found this document useful (0 votes)
57 views4 pages

Código Del Documento HTML.: Factura

The document contains code for generating an invoice form with JavaScript, PHP, and HTML. The JavaScript code dynamically generates form fields and validates input. The PHP code processes the form submission and outputs the invoice details. The HTML provides the form interface and integrates the JavaScript and PHP code.

Uploaded by

Edgar Martínez
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views4 pages

Código Del Documento HTML.: Factura

The document contains code for generating an invoice form with JavaScript, PHP, and HTML. The JavaScript code dynamically generates form fields and validates input. The PHP code processes the form submission and outputs the invoice details. The HTML provides the form interface and integrates the JavaScript and PHP code.

Uploaded by

Edgar Martínez
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Factura

Código del documento html.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"


"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Facturaci&#243;n</title>
<script type="text/javascript" src="codigojava.js">
</script>
</head>
<body onload="generarFactura()">
<h1 style="text-align: center">Forma de Facturaci&#243;n</h1>
<form name="factura" method="post" id="factura">
<table width="100%">
<tr>
<td rowspan="2" width="75%">
<table align="center">
<tr>
<td>Remitido a</td>
<td><input type="text" name="nombre" id="nombre" value="" size="150"></td>
</tr>
<tr>
<td>Direcci&#243;n</td>
<td><input type="text" name="direccion" id="direccion" value=""
size="150"></td>
</tr>
<tr>
<td>RFC</td>
<td><input type="text" name="rfc" id="rfc" value="" size="150"></td>
</tr>
<tr>
<td>Lugar</td>
<td><input type="text" name="lugar" id="lugar" value="" size="150"></td>
</tr>
</table>
</td>
<td align="center" id="folio" style="color:red;font-size:23px"></td>
</tr>
<tr>
<td align="center" id="date" style="font-size:16px"></td>
</tr>
</table>
<table width="80%" border="1" id="productos" align="center">
<tr>
<td align="center" width="8%" bgcolor="#DADADA">Cantidad</td>
<td align="center" width="52%" bgcolor="#DADADA">Descripci&#243;n</td>
<td align="center" width="20%" bgcolor="#DADADA">Precio Unitario</td>
</tr>
<tr>
<td align="center" width="8%"><input type="text" name="can[]" value="0" size="7"
onblur="validarCantidad(this)"></td>
<td align="center" width="52%"><input type="text" name="dep[]" value=""
size="85"></td>
<td align="center" width="20%"><input type="text" name="pu[]" value="0" size="20"
onblur="validarPrecio(this)"></td>
</tr>
</table>
<div align="center" width="80%">
<input type="button" value="Terminar" onclick="terminar()">
<input type="button" value="Agregar item" onclick="agregar()">
<input type="hidden" name="folioVal" id="folioVal">
<input type="hidden" name="fechaVal" id="fechaVal">
</div>
</form>
</body>
</html>

Código del documento php.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"


"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Facturaci&#243;n</title>
</head>
<body>
<h1 style="text-align: center">Forma de Facturaci&#243;n</h1>
<form name="factura" method="post" id="factura">
<table width="100%">
<tr>
<td rowspan="2" width="75%">
<table align="center">
<tr>
<td>Remitido a</td>
<?php
print "<td>$_POST[nombre]</td></tr>";
print "<tr><td>Direcci&#243;n</td>";
print "<td>$_POST[direccion]</td></tr>";
print "<tr><td>RFC</td>";
print "<td>$_POST[rfc]</td></tr>";
print "<tr><td>Lugar</td>";
print "<td>$_POST[lugar]</td></tr></table></td>";
print "<td align=\"center\" style=\"color:red;font-
size:23px\">Folio<br/>$_POST[folioVal]</td></tr>";
print "<tr><td align=\"center\" style=\"font-
size:16px\">$_POST[fechaVal]</td></tr></table>";
?>
<table width="100%" border="1" id="productos">
<tr>
<td align="center" width="8%" bgcolor="#DADADA">Cantidad</td>
<td align="center" width="52%" bgcolor="#DADADA">Descripci&#243;n</td>
<td align="center" width="20%" bgcolor="#DADADA">Precio Unitario</td>
<td align="center" width="20%" bgcolor="#DADADA">Importe</td>
</tr>
<?php
$cantidad = $_POST['can'];
$descripciones = $_POST['dep'];
$precios = $_POST['pu'];
$total = 0;
$importe = 0;
for($i=0; $i<count($cantidad); $i++) {
print "<tr>";
print "<td align=\"center\" width=\"8%\">$cantidad[$i]</td>";
print "<td align=\"center\" width=\"52%\">$descripciones[$i]</td>";
print "<td align=\"center\" width=\"20%\">$precios[$i]</td>";
$importe = $cantidad[$i] * $precios[$i];
$importe = round($importe, 2);
print "<td align=\"center\" width=\"20%\">$importe</td>";
print "</tr>";
$total+=$importe;
}
$total = round($total,2);
print "<tr><td colspan=\"3\" width=\"80%\" bgcolor=\"#DADADA\"
align=\"right\">Subtotal</td>";
print "<td width=\"20%\" align=\"center\" style=\"color:blue\">$
".$total."</td></tr>";
print "<tr><td colspan=\"3\" width=\"80%\" bgcolor=\"#DADADA\"
align=\"right\">I.V.A</td>";
$importe = round($total * 0.15, 2);
print "<td width=\"20%\" align=\"center\" style=\"color:blue\">$
".$importe."</td></tr>";
print "<tr><td colspan=\"3\" width=\"80%\" bgcolor=\"#DADADA\"
align=\"right\">Total</td>";
$total+= $importe;
$total = round($total,2);
print "<td width=\"20%\" align=\"center\" style=\"color:red\">$
".$total."</td></tr></table>";
?>

</body>
</html>

Código JavaScript

function agregar() {
lista = document.getElementById('productos');
nuevaFila = document.createElement('tr');
cantidad = document.createElement('td');
cantidad.align = 'center';
cantidad.width = '8%';
concepto = document.createElement('td');
concepto.align = 'center';
concepto.width = '52%';
precioUnitario = document.createElement('td');
precioUnitario.align = 'center';
precioUnitario.width = '20%';

valor = document.createElement('input');
valor.type = 'text';
valor.name = 'can[]';
valor.value = '0';
valor.size = '7';
valor.onblur = function() {validarCantidad(this);};
cantidad.appendChild(valor);

valor = document.createElement('input');
valor.type = 'text';
valor.name = 'dep[]';
valor.value = '';
valor.size = '85';
concepto.appendChild(valor);

valor = document.createElement('input');
valor.type = 'text';
valor.name = 'pu[]';
valor.value = '0';
valor.size = '20';
valor.onblur = function() {validarPrecio(this);};
precioUnitario.appendChild(valor);

nuevaFila.appendChild(cantidad);
nuevaFila.appendChild(concepto);
nuevaFila.appendChild(precioUnitario);
lista.appendChild(nuevaFila);
}

function generarFactura() {

limitesFolio = 999999 - 100000;


aleat = Math.random() * limitesFolio;
aleat = Math.round(aleat);
folio = 100000 + aleat;
numFolio = document.getElementById('folio');
numFolio.innerHTML = 'Folio<br/>' + folio;
document.getElementById('folioVal').value = folio;

textoMeses = new Array(2);


textoMeses[0] = 'Enero';
textoMeses[1] = 'Febrero';
textoMeses[2] = 'Marzo';
textoMeses[3] = 'Abril';
textoMeses[4] = 'Mayo';
textoMeses[5] = 'Junio';
textoMeses[6] = 'Julio';
textoMeses[7] = 'Agosto';
textoMeses[8] = 'Septiembre';
textoMeses[9] = 'Octubre';
textoMeses[10] = 'Noviembre';
textoMeses[11] = 'Diciembre';
fecha = new Date();
fechaHoy = document.getElementById('date');
fechaHoy.innerHTML = 'Fecha de expedición: ' + fecha.getDate() + ' de ' +
textoMeses[fecha.getMonth()] + ' de ' + fecha.getFullYear();
document.getElementById('fechaVal').value = 'Fecha de expedición: ' +
fecha.getDate() + ' de ' + textoMeses[fecha.getMonth()] + ' de ' + fecha.getFullYear();
}
function terminar() {
num = document.getElementById('nombre');
dir = document.getElementById('direccion');
rfc = document.getElementById('nombre');
lug = document.getElementById('lugar');
if(num.value=='' || dir.value=='' || rfc.value=='' || lug.value=='') {
alert('Hay campos en la seccion de datos sin llenar. Complete.');
return;
}
document.factura.action = 'factura.php';
document.factura.submit();
}

function validar(obj) {
if(isNaN(obj.value) || obj.value=='') {
alert('Se admiten unicamente caracteres numericos.');
obj.value = '0';
return 0;
}
if(parseInt(obj.value) < 0) {
alert('Cantidades negativas no validas.');
obj.value = '0';
return 0;
}
}

function validarCantidad(obj) {
if(validar(obj) == 0) {
return;
}
obj.value = parseInt(obj.value,10);
}
function validarPrecio(obj) {
if(validar(obj) == 0) {
return;
}
obj.value = Math.floor(parseFloat(obj.value)*100)/100;
}

You might also like