Soma de campos com nome em array - Jquery + PHP
Boa tarde
Estou desde cedo tentando resolver este problema.
tenho o seguinte script em javascript para poder somar resultados
function soma()
{
form.campo[].value = (form.campo1[].value1) / (form.campo2[].value1)
}
</script>
porem nao consigo passar a variavel q conte o array para o script.
tenho uma aplicação que esta interpretando um xml.
nela ele puxa os dados de uma nota fisca, e coloca tudo em inputs para ser importador posteriormente.
porem preciso fracionar a quantidade quando o cliente compra caixa e vende em lata.
seu eu usar o script sem [] ele funciona, porem preciso que em cada que vir pelo FOR EACH
ele ter a opção de ser incrementado com a fração
segue codigo de exibição xml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!-- CSS BOOTSTRAP -->
<style>
html {
padding: 10px;
}
</style>
<link href="css/bootstrap.css" rel="stylesheet" media="screen">
<link rel="stylesheet" href="css/font-awesome.min.css">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Importar XML</title><!--
Francionar-->
</head>
<body>
<h1></h1>
<!-- link do arquivo xml-->
<form action="" method="GET" name="form">
<?php
try
{
// busca o arquivo xml
$object = simplexml_load_file('nfe1.xml');
// faz o loop
echo '<fieldset><legend>PRODUTOS</legend>
<table class="table table-striped">
<tr>
<td><b>Cod</b></td>
<td><b>UN</b></td>
<td><b>NCM</b></td>
<td><b>CFOP</b></td>
<td><b>Descricao</b></td>
<td><b>QTD</b></td>
<td><b>Unitario R$</b></td>
<td><b>Trotal R$</b></td>
</tr>
';
foreach($object->NFe as $key => $item)
{
$count = count($item->infNFe->det);
if(isset($item->infNFe))
{
$item1=1;
$array =0;
for($i=0; $i < $count; $i++)
{
echo '
<input type="hidden" name="NRITEM" class="input-mini" value="'.$item1++.'">
<input type="hidden" name="CODCOR" class="input-small" value="UN">
<input type="hidden" name="orig" class="input-small" value="'.$item->infNFe->det[$i]->imposto->ICMS->ICMSSN102->orig.'">
<input type="hidden" name="CSOSN" class="input-small" value="'.$item->infNFe->det[$i]->imposto->ICMS->ICMSSN102->CSOSN.'">
';
// <input type="text" name="CODCOR" class="input-small" value="UN">
// salva os codigos do produto
$cProd = $item->infNFe->det[$i]->prod->cProd;
echo '<tr>
<td>
<input type="text" name="cProd" class="input-small" value="'.$cProd.'">
</td>
';
// salva unidade comercial
$uCom = $item->infNFe->det[$i]->prod->uCom;
echo '<td>
<input type="text" name="uCom" class="input-mini" value="'.$uCom.'">
</td>
';
// salva o ncm do produto
$NCM = $item->infNFe->det[$i]->prod->NCM;
echo '<td>
<input type="text" name="NCM" class="input-small" value="'.$NCM.'">
</td>
';
// salva o CFOP
$CFOP = $item->infNFe->det[$i]->prod->CFOP;
echo '<td>
<input type="text" name="CFOP" class="input-mini" value="'.$CFOP.'" size="80">
</td>
';
// Salva o nome do produto
$xProd = $item->infNFe->det[$i]->prod->xProd;
echo '<td>
<input type="text" name="xprod" class="input-xlarge" value="'.$xProd.'" size="80">
</td>
';
// Quantidade
$qCom = $item->infNFe->det[$i]->prod->qCom;
echo '<td>
<input type="text" name="qCom[]" class="input-mini" value="'.number_format((double)$qCom, 2, '.', '').'" size="80">
</td>
';
// Salva valor unitario do produto
$vUnCom = $item->infNFe->det[$i]->prod->vUnCom;
echo '<td>
<input type="text" name="vUnCom[]" class="input-small" value="'.number_format((double)$vUnCom, 4, '.', '').'" size="80">
</td>
';
// salva valor total dos produtos
$vProd = $item->infNFe->det[$i]->prod->vProd;
echo '<td>
<input type="text" name="vProd[]" class="input-small" value="'.number_format((double)$vProd, 4, '.', '').'" size="80">
</td> ';
$array++;
}
}
}
}
catch(Exception $e)
{
echo $e->getMessage();
}
?>
</fildeset>
</tr>
</table>
</form>
</body>
</html>Discussão (5)
Carregando comentários...