Ver Mensaje Individual
  #1 (permalink)  
Antiguo 18/12/2008, 13:03
Avatar de colote
colote
 
Fecha de Ingreso: julio-2008
Ubicación: Rosario - Santa Fe - Argentina
Mensajes: 729
Antigüedad: 15 años, 10 meses
Puntos: 8
Pregunta Problemas con funciones !!!

Hola gente del foro, hacia tiempo que no posteaba, ahora que intento seguir con el sistemita este, y tengo un problemita.
El tema esta en la modificacion de Datos, para modificarlos los puedo mostrar, pero hay una serie de calculos que no se aplica a las filas de datos a modificar, pero si agrego una fila nueva la funcion anda bien. la fila que agrego es la fila nro 4, yo le ingreso cant y desperd% y me calcula los subtotales, que en las 3 primeras filas aparecen vacios, lo que necesito es que cuando se me muestren los datos que tengo guardados que me muestre los subtotales tambien
Alguna mano por ahi ???
Gracias !!!

Código PHP:
<?php
//para selector Materia_Prima
$var="";
$resump=mysql_query("select * from materia_prima order by nombre",$conexion);

while (
$row1=mysql_fetch_array($resump))

$var.= '<option value="'.$row1["codigo"].'" alt="'.$row1["unidad"] .'", alt1="'.$row1["costo_mp_pesos"] .'", alt2="'.$row1["costo_mp_dolar"] .'">'.$row1["nombre"].'</option>';
}
?>

<script language='JavaScript'>
var cont=1;
function addRow()
{
cont++;
var indiceFila=1;
myNewRow = document.getElementById('tabla').insertRow(-1);
myNewRow.id=indiceFila;

myNewCell=myNewRow.insertCell(-1);
myNewCell.innerHTML='<tr><td><select name="lista_'+cont+'" onChange="listaSeleccionada(this)"><option value="option">Seleccionar</option><? echo $var ?></select></td>';
myNewCell=myNewRow.insertCell(-1);
myNewCell.innerHTML='<td><input type="text" size="4" name="code_'+cont+'"/></td>';
myNewCell=myNewRow.insertCell(-1);
myNewCell.innerHTML='<td><input type="text" size="25" name="name_'+cont+'"/><td>';
myNewCell=myNewRow.insertCell(-1);
myNewCell.innerHTML='<td><input type="text" size="8" name="unid_'+cont+'"/></td>';
myNewCell=myNewRow.insertCell(-1);
myNewCell.innerHTML='<td><input type="text" size="8" name="cant_mp_'+cont+'"/></td>';
myNewCell=myNewRow.insertCell(-1);
myNewCell.innerHTML='<td><input type="text" size="8" name="desperdicio_'+cont+'"/></td>';
myNewCell=myNewRow.insertCell(-1);
myNewCell.innerHTML='<td><input type="text" size="8" name="cos_mp_pesos_'+cont+'"/></td>';
myNewCell=myNewRow.insertCell(-1);
myNewCell.innerHTML='<td><input type="text" size="8" name="cos_mp_dolar_'+cont+'"/></td>';
myNewCell=myNewRow.insertCell(-1);
myNewCell.innerHTML='<td><input type="text" size="8" name="sub_mp_pesos_'+cont+'"/></td>';
myNewCell=myNewRow.insertCell(-1);
myNewCell.innerHTML='<td><input type="text" size="8" name="sub_mp_dolar_'+cont+'"/></td></tr>';
indiceFila++;

}

///////Borrar() TABLA MATERIA PRIMA///////////
function borrar() {
var table = document.getElementById('tabla');
if(table.rows.length > 3) 
    {
    table.deleteRow(table.rows.length-1);
cont--;
    }
}

function listaSeleccionada(lista) { 
arr=lista.name.split("_");
c1="code_"+arr[1];
c2="name_"+arr[1];
c3="unid_"+arr[1];
c4="cos_mp_pesos_"+arr[1];
c5="cos_mp_dolar_"+arr[1];

c6="sub_mp_pesos_"+arr[1];
c7="sub_mp_dolar_"+arr[1];

c8="cant_mp_"+arr[1];
c9="desperdicio_"+arr[1];

document.form[c1].value = lista.options[lista.selectedIndex].value; 
document.form[c2].value = lista.options[lista.selectedIndex].text; 
document.form[c3].value = lista.options[lista.selectedIndex].getAttribute("alt");
document.form[c4].value = lista.options[lista.selectedIndex].getAttribute("alt1");
document.form[c5].value = lista.options[lista.selectedIndex].getAttribute("alt2");
}

////////////FUNCION ASIGNA VALOR DE CONT PARA EL FOR DE MOSTRAR DATOS MP-MOD-TT////
function asigna()
{
valor=document.form.var_cont.value=cont;
valorm=document.form.var_contm.value=contm;
valort=document.form.var_contt.value=contt;
//alert('Valor Cont MP:'+valor)
//alert('Valor Cont MOD:'+valorm)
//alert('Valor Cont TT:'+valort)
}

//CALCULO PARA SUBTOTALES COSTO MATERIA PRIMA////
function calculo()
{
val_cos_pesos = parseFloat(document.form[c4].value);
val_cos_dolar = parseFloat(document.form[c5].value);
val_cant = parseFloat(document.form[c8].value);
val_desp = parseFloat(document.form[c9].value)/100;

val1= (val_cos_pesos*val_cant);
total1=(val1*val_desp)+val1;
document.form[c6].value=total1.toFixed(4);

val2= (val_cos_dolar*val_cant);
total2=(val2*val_desp)+val2;
document.form[c7].value=total2.toFixed(4);

}

///FUNCION ACUMULAR SUBTOTALES COSTO MATERIA PRIMA///
function acumula() {
sub_pesos=0;
sub_dolar=0;
for(c=1;c<=cont;c++)
      { 
     sub_pesos+=parseFloat(document.form["sub_mp_pesos_"+c].value);
     sub_dolar+=parseFloat(document.form["sub_mp_dolar_"+c].value);
      }
document.form.totcos_mp_pesos.value=sub_pesos.toFixed(4);
document.form.totcos_mp_dolar.value=sub_dolar.toFixed(4);

}

</script>

</head>
<body>
<?php

?>

<form id="form" name="form" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" onsubmit="asigna()" onKeyUp="calculo();acumula();calculoMod();acumulaMod();calculofondo();calculoT();acumulaT();acumulasub()">

<table border="1" id="tablita1" bordercolor="#FFCC33" align="center">
<tr align="left">
<td><input type="submit" name="b1" value="<" onclick="anterior()"></td>
<td><font color="red" size="1"></font>Codigo</td>
<td><input type="text" size="8" name="code" value="<?php echo $_POST['code']?>"></td>
<td><input type="submit" name="b3" value="Buscar"></td>
<td><input type="submit" name="b2" value=">" onclick="siguiente()"></td>
</tr>
</table>

<?php
$piezas 
mysql_query("SELECT * FROM piezas where codigo='$_POST[code]'",$conexion);
while (
$resu_piezas mysql_fetch_array($piezas)){ //Recorro la tabla Piezas !!!

?>

<table border="1" id="tablita" bordercolor="#FFCC33" align="center" width="65%">
<tr align="center">

</tr>

<tr> 
<td>Codigo: >>> <b><?php echo $resu_piezas['codigo'];?></b><br><td>
</tr>

<tr align="left">
<td><font color="red" size="1">COD PIEZA(Lista Precios)</font></td>
<td><font color="red" size="1">NOMBRE</font></td>
</tr>
<tr>
<td><input type="text" size=8 name="cod_piezan" value="<?php echo $resu_piezas['cod_pieza']?>"></td>
<td><input type="text" size=50 name="nombren" value="<?php echo $resu_piezas['nombre'?>"><br></td>
</tr>
</table>

<br>
<br>

<br>

<table border="1" id="tabli" bordercolor="#FFCC33" align="center">
<tr><td>Cargas Sociales:<input type="text" size="8" name="alic_carga_socn"   value="<?php echo $resu_piezas['alic_carga_soc']?>"></td></tr>
<tr><td>Gastos Fundicion:<input type="text" size="8" name="alic_gg_fundn"   value="<?php echo $resu_piezas['alic_gg_fund']?>"></td></tr>
<tr><td>Gastos Mecanizado:<input type="text" size="8" name="alic_gg_mecn"   value="<?php echo $resu_piezas['alic_gg_mec']?>"></td></tr>
<tr><td>Impuestos:<input type="text" size="8" name="alic_impn"   value="<?php echo $resu_piezas['alic_imp']?>"></td></tr>
<tr><td>Utilidad:<input type="text" size="8" name="alic_utilidadn"   value="<?php echo $resu_piezas['alic_utilidad']?>"></td></tr>
</table>
<br>

<table border="0" id="tabla" bordercolor="#FFCC33" cellspacing="1">
<tr colspan="13" align="left">
<td align="center"><font color="1166FF" size="3"><b>MATERIA PRIMA</b></font></td>

<td valign="top"><input type="button" name="b1" value="[+]" onClick="addRow()"></td>
<td valign="top"><input type="button" name="b2" value="[-]" onClick="borrar()"></td>
</tr>

<?php 

$smp 
mysql_query("select * from sub_materia_prima where cod_pieza='$resu_piezas[cod_pieza]'",$conexion);
while (
$resu_smp mysql_fetch_array($smp)){ //Recorro la tabla Sub_Materia_Primas!!!

$mp mysql_query("select * from materia_prima where codigo='$resu_smp[cod_mp]'",$conexion);
while(
$resu_mp mysql_fetch_array($mp)){ //Recorro la tabla Materia_Primas!!!

?>
<!-- /////////////////////////MATERIA PRIMA -->
<tr>
<td><select name="lista_1" onChange="listaSeleccionada(this)">
<option value="option">Seleccionar</option>
<? echo $var?></select></td>

<td><input type="text" size="4" name="code_1" value="<?php echo $resu_mp['codigo']?>"></td>
<td><input type="text" size="25" name="name_1" value="<?php echo $resu_mp['nombre']?>"/></td>
<td><input type="text" size="8" name="unid_1" value="<?php echo $resu_mp['unidad']?>"/></td>
<td><input type="text" size="8" name="cant_mp_1" value="<?php echo $resu_smp['cant_mp']?>"/></td>
<td><input type="text" size="8" name="desperdicio_1" value="<?php echo $resu_smp['desperdicio']?>"/></td>
<td><input type="text" size="8" name="cos_mp_pesos_1" value="<?php echo $resu_mp['costo_mp_pesos']?>"/></td>
<td><input type="text" size="8" name="cos_mp_dolar_1" value="<?php echo $resu_mp['costo_mp_dolar']?>"/></td>
<td><input type="text" size="8" name="sub_mp_pesos_1" /></td>
<td><input type="text" size="8" name="sub_mp_dolar_1" /></td>
<input type="hidden" name="var_cont">
<td valign="top"><input type="button" name="b1" value="[+]" onClick="addRow()"></td>
<td valign="top"><input type="button" name="b2" value="[-]" onClick="borrar()"></td>

</tr>
<?php

}
}
}

?>
</table>
<br>

<table border="1" id="tabla_fondo1" bordercolor="#6B238E" rules="none">
<tr>
<td></td>
<td align="center"><font color="#5F9F9F" size="1">Subtot $</font></td>
<td align="center"><font color="#5F9F9F" size="1">Subtot U$S</font></td>
</tr>
<tr>
<td width="765px" align="right" size="1"><font color="red" size="1">Subtotal Costo Materia Prima</font></td>
<td><input type="text" size="8" name="totcos_mp_pesos"></td> 
<td><input type="text" size="8" name="totcos_mp_dolar"></td>
</tr>
</table>




<br>
<table border="1" id="tabla_f2" bordercolor="#6B238E" align="center">
<tr>
<td><input type="submit" name="ok" id="ok" value="OK" /></td>
<td><input type="submit" value="VOLVER" onclick="self.location.href='inicio.php'"></td>
</tr>
</table>

</form>

</body>
</html>
__________________
Mail: [email protected]

Última edición por colote; 18/12/2008 a las 13:05 Razón: falta imagen