$giorno $mese per Tutti gli agenti
verso il fornitore " . stripslashes($nome_forni) . "" ; debug (0, "AGENTE = $nome_agente ; HCONFRONTI = $hconfronti ; CLIENTE = $nome_cliente ; FORNITORE = $nome_forni") ; /***************************************************************************** * Devo calcolare qui quanti sono gli agenti perchè mi servono per il calcolo * della grandezza di alcune righe ******************************************************************************/ for ($an = ($anno - 1) ; $an <= $anno; $an ++) { /************************************** * Mi ricavo gli id di tutti gli agenti ***************************************/ $db->query(" select * from agenti_$an order by nome ") ; while ($db->next_record()) $ag[$db->f('IdAgenti')] = $db->f('Nome') ; } $col = count($ag) ; ?> <? echo TITLE ?>
2002) { ?> $nome_agente) { /********************* * Numero Ordini *********************/ $dataordine = MySqlDate("$gime/$an") ; debug (0, "NOME_AGENTE = $nome_agente") ; $query = " select count(*) as tot from ordini_$an where dataordine <= '$dataordine' and idagente = $id_agente and idfornitore = $id_forni " ; debug (0, $query) ; $db->query($query) ; while ($db->next_record()) { $tot = $db->f("tot") ; $nordini[] = $tot ; ${"tot_$an"} = $tot ; ${"wid_$an"} = ($tot * 748) / 4000 ; debug (0, "TOT $an = $tot -- wid = $wid") ; $valori['NUMORDINI'][$an][$id_agente]['NOME'] = $nome_agente ; $valori['NUMORDINI'][$an][$id_agente]['TOTALE'] = $tot ; } } } @reset($ag) ; ?> $nome_agente) print ("") ; ?> $arr_numord) while ( list(, $arr_numord) = each($valori) ) { while( list($my_anno, $arr_dati) = each($arr_numord) ) { $annop = $my_anno - 1 ; @reset($ag) ; print(" \n") ; while( list($id_agente, $nome_agente) = each($ag) ) { $tot = $arr_dati[$id_agente]['TOTALE'] ; debug (0, "ANNOP = $annop ; VAL ANNO PRIMA = " . $valori['NUMORDINI'][$annop][$id_agente]['TOTALE']) ; $diff[$id_agente]['VAL'] = $tot - $valori['NUMORDINI'][$annop][$id_agente]['TOTALE'] ; $diff[$id_agente]['PER'] = @(($tot - $valori['NUMORDINI'][$annop][$id_agente]['TOTALE']) / $valori['NUMORDINI'][$annop][$id_agente]['TOTALE'] * 100) ; print(" \n") ; } ?> %s
(%s)\n", nflno($diff[$id_agente]['VAL']), nfp($diff[$id_agente]['PER']) . "%") ; } flush() ; ?> query("select * from fornitori_$an where idfornitori = $id_forni") ; while ($db->next_record()) { $totforn = 0 ; $totproforn = 0 ; $nomefornitore = $db->f("Nome") ; $idfor = $db->f("IdFornitori") ; $provvigione = $db->f("Provvigione") ; $qord = " select * from ordini_$an where idfornitore = $idfor and dataordine <= '$dataordine' and idagente = $id_agente " ; debug (0, $qord) ; $dbord->query($qord) ; while ($dbord->next_record()) { $totordine = 0 ; $sco1 = $dbord->f("Sconto1") ; $sco2 = $dbord->f("Sconto2") ; $sco3 = $dbord->f("Sconto3") ; $idordine = $dbord->f("IdOrdini") ; $importoNC = $dbord->f("ImportoNC") ; if ($importoNC > 0) $valNC = ($importoNC / 1.2) ; else $valNC = 0 ; if ($idfor != $idsarzi) $query = "select * from dettagli_$an, prodotti_$an where dettagli_$an.idordine = $idordine and prodotti_$an.idprodotti = dettagli_$an.idprodotto " ; else $query = "select * from dettagli_$an, sarzi_$an where dettagli_$an.idordine = $idordine and dettagli_$an.idprodotto = CONCAT('SA', idprodotti)" ; $dbt->query($query) ; while ($dbt->next_record()) { $impparz = $dbt->f("NumCartoni") * $dbt->f("ConfezioniDa") * $dbt->f("PrezzoUnitario") ; if ($dbt->f("ScontoPrd") != "") $impparz = CalcolaScontoProdotto($impparz, $dbt->f("ScontoPrd")) ; $totordine += $impparz ; } $sconto1 = ($totordine * $sco1 / 100) ; $ammpro1 = $totordine - $sconto1 ; $sconto2 = ($ammpro1 * $sco2 / 100) ; $ammpro2 = $ammpro1 - $sconto2 - $valNC; /*********************************************************** * Calcolo a questo punto l'ammontare delle provvigioni per * questo ordine dopo aver sottratto dall'imponibile gli * eventuali 2 sconti forniti dal fornitore e l'eventuale * ammontare della nota di credito. Idem per il * fatturato *************************************************************/ $totproordine = ($ammpro2 * $provvigione / 100) ; $sconto = $sconto1 + $sconto2 ; $totordine = $totordine - $sconto - $valNC; $totforn += $totordine ; $totproforn += $totproordine ; debug (0, "ORDINE = $idordine -- TOTORDINE = $totordine") ; } $valori['VENDUTO'][$an][$id_agente]['TOTALE'] += $totforn ; } } } @reset($ag) ; @reset($valori) ; while ( list(, $arr_numord) = each($valori) ) { while( list($my_anno, $arr_dati) = each($arr_numord) ) { $annop = $my_anno - 1 ; @reset($ag) ; print(" \n") ; while( list($id_agente, $nome_agente) = each($ag) ) { $tot = $arr_dati[$id_agente]['TOTALE'] ; $diff[$id_agente]['VAL'] = $tot - $valori['VENDUTO'][$annop][$id_agente]['TOTALE'] ; $diff[$id_agente]['PER'] = @(($tot - $valori['VENDUTO'][$annop][$id_agente]['TOTALE']) / $valori['VENDUTO'][$annop][$id_agente]['TOTALE'] * 100) ; printf(" \n", nfe($tot)) ; } ?> %s
(%s)\n", nfe($diff[$id_agente]['VAL']), nfp($diff[$id_agente]['PER']) . "%") ; } flush() ; ?> query("select * from fornitori_$an where idfornitori = $id_forni") ; while ($db->next_record()) { $totforn = 0 ; $totproforn = 0 ; $nomefornitore = $db->f("Nome") ; $idfor = $db->f("IdFornitori") ; $provvigione = $db->f("Provvigione") ; $qord = " select * from ordini_$an where idfornitore = $idfor and ordini_$an.importofattura > 0 and dataspedfattura <= '$dataordine' and idagente = $id_agente " ; debug (0, $qord) ; $dbord->query($qord) ; while ($dbord->next_record()) { $totordine = 0 ; $sco1 = $dbord->f("Sconto1") ; $sco2 = $dbord->f("Sconto2") ; $sco3 = $dbord->f("Sconto3") ; $idordine = $dbord->f("IdOrdini") ; $importoNC = $dbord->f("ImportoNC") ; if ($importoNC > 0) $valNC = ($importoNC / 1.2) ; else $valNC = 0 ; if ($idfor != $idsarzi) $query = "select * from dettagli_$an, prodotti_$an where dettagli_$an.idordine = $idordine and prodotti_$an.idprodotti = dettagli_$an.idprodotto " ; else $query = "select * from dettagli_$an, sarzi_$an where dettagli_$an.idordine = $idordine and dettagli_$an.idprodotto = CONCAT('SA', idprodotti)" ; $dbt->query($query) ; while ($dbt->next_record()) { $impparz = $dbt->f("NumCartoni") * $dbt->f("ConfezioniDa") * $dbt->f("PrezzoUnitario") ; if ($dbt->f("ScontoPrd") != "") $impparz = CalcolaScontoProdotto($impparz, $dbt->f("ScontoPrd")) ; $totordine += $impparz ; } $sconto1 = ($totordine * $sco1 / 100) ; $ammpro1 = $totordine - $sconto1 ; $sconto2 = ($ammpro1 * $sco2 / 100) ; $ammpro2 = $ammpro1 - $sconto2 - $valNC; /*********************************************************** * Calcolo a questo punto l'ammontare delle provvigioni per * questo ordine dopo aver sottratto dall'imponibile gli * eventuali 2 sconti forniti dal fornitore e l'eventuale * ammontare della nota di credito. Idem per il * fatturato *************************************************************/ $totproordine = ($ammpro2 * $provvigione / 100) ; $sconto = $sconto1 + $sconto2 ; $totordine = $totordine - $sconto - $valNC; $totforn += $totordine ; $totproforn += $totproordine ; debug (0, "ORDINE = $idordine -- TOTORDINE = $totordine") ; } $valori['FATTURATO'][$an][$id_agente]['TOTALE'] += $totforn ; } } } @reset($ag) ; @reset($valori) ; while ( list(, $arr_numord) = each($valori) ) { while( list($my_anno, $arr_dati) = each($arr_numord) ) { $annop = $my_anno - 1 ; @reset($ag) ; print(" \n") ; while( list($id_agente, $nome_agente) = each($ag) ) { $tot = $arr_dati[$id_agente]['TOTALE'] ; $diff[$id_agente]['VAL'] = $tot - $valori['FATTURATO'][$annop][$id_agente]['TOTALE'] ; $diff[$id_agente]['PER'] = @(($tot - $valori['FATTURATO'][$annop][$id_agente]['TOTALE']) / $valori['FATTURATO'][$annop][$id_agente]['TOTALE'] * 100) ; printf(" \n", nfe($tot)) ; } ?> %s
(%s)\n", nfe($diff[$id_agente]['VAL']), nfp($diff[$id_agente]['PER']) . "%") ; } ?>
  Numero Ordini  
  $nome_agente
$my_anno$tot
Differenza
  Venduto  
$my_anno%s
Differenza
  Fatturato  
$my_anno%s
Differenza


Il confronto fra due anni può essere effettuato solo a partire dal 2003.