-1
My system reads the XML files inside a folder and puts the data ("invoice number", "product code","quantity") inside an array.
I created a new array to have the total per product, where the account is correct, and the result is what I expect.
The problem is that I get error below:
Erro na Linha: #160 :: Undefined offset: 10452
C:\xampp\htdocs\controledeentregasver209112019\Romaneio\RomaneirodeCarregamentoTeste_1.php
Erro na Linha: #160 :: Undefined offset: 10485
C:\xampp\htdocs\controledeentregasver209112019\Romaneio\RomaneirodeCarregamentoTeste_1.php
Erro na Linha: #160 :: Undefined offset: 10433
C:\xampp\htdocs\controledeentregasver209112019\Romaneio\RomaneirodeCarregamentoTeste_1.php
Erro na Linha: #160 :: Undefined offset: 3767
C:\xampp\htdocs\controledeentregasver209112019\Romaneio\RomaneirodeCarregamentoTeste_1.php
Erro na Linha: #160 :: Undefined offset: 3768
C:\xampp\htdocs\controledeentregasver209112019\Romaneio\RomaneirodeCarregamentoTeste_1.php
C:\xampp\htdocs\controledeentregasver209112019\Romaneio\RomaneirodeCarregamentoTeste_1.php:171:
array (size=5)
10452 => float 30
10485 => float 20
10433 => float 10
3767 => float 40
3768 => float 30
Follow the source code:
<?php
$notaPesoQuantidade = [];
$totalizando=[];
// ****************PEGANDO OS ARQUIVOS DA PASTA
$path = "./arquivos/";
$files = scandir($path);
foreach ($files as &$value) {
if($value=='.' ||$value=='..'):
else:
$arquivo = simplexml_load_file('./arquivos/'."$value");
foreach($arquivo->NFe as $key => $xml){
//dados DA nf
$nNF = "".$xml->infNFe->ide->nNF."" ;
}
?>
<?php
//IMPRIMINDO OS PRODUTOS DA NOTA FISCAL
echo "<br/>";
echo "<b><font color=\"#054F77\"> NF-e $nNF ($value) </font></b>";
?>
<table class="table">
<thead>
<tr>
<th scope="col" style="color:#4169E1;">COD</th>
<th scope="col"style="color:#4169E1;">Quant</th>
</tr>
</thead>
<tbody>
<?php
//PERCORRENDO OS PRODUTOS DA NOTA FISCAL
foreach ($xml->infNFe->det as $value) {
?>
<tr>
<th scope="row"><?php echo $value->prod->cProd; ?></th>
<td style="font-weight: bold"><?php echo $value->prod->qCom; ?></td>
<?php
$nNF = intval ($nNF);
$cProd = intval ($value->prod->cProd);
$qCom= floatval ($value->prod->qCom);
// $notaPesoQuantidade[$nNF]["$cProd"]=$qCom;
$notaPesoQuantidade[] = [
'nota'=>$nNF,
'produto'=>$cProd,
'quantidade'=>$qCom
];
?>
</tr>
<?php
}
?>
</tbody>
</table>
<?php
echo "<hr>";
echo "<br>";
echo "<br>";
endif;
}
echo "<b><font color=\"#054F77\"> ***************** CARREGAMENTO TOTAL ******************</font></b>";
foreach ($notaPesoQuantidade as $key => $value) :
//$key = indice do array
//$value = é o arrai, ex $value['nota']
$p = $value['produto'];
$q = $value['quantidade'];
$totalizando[$p]+=$q;
endforeach;
var_dump($totalizando);
?>