> Totali >> Da Agente/i al Cliente/i - Anno" ; list($id, $nome_agente) = explode("^", $agente) ; $strIdCli = substr($hidcli, 0, -1) ; $arrIdCli = explode(",", $strIdCli) ; $strNomeCli = substr($hnomecli, 0, -1) ; $strNomeCli = str_replace(",", " / ", $strNomeCli) ; if (in_array(0, $arrIdCli)) $where_cli = "1" ; else $where_cli = "C.idclienti IN ($strIdCli)" ; if ($id == 0) { $single_agente = false ; if ($strNomeCli == "Tutti") $titolo = "Totali di Tutti gli agenti verso Tutti i clienti" ; else $titolo = "Totali di Tutti gli agenti verso il cliente $strNomeCli" ; $where_age = "1" ; } else { $single_agente = true ; if ($strNomeCli == "Tutti") $titolo = "Totali dell'agente $nome_agente verso Tutti i clienti" ; else $titolo = "Totali dell'agente $nome_agente verso il cliente $strNomeCli" ; $where_age = " O.idagente = $id " ; } } elseif ($from == "totali_for") { list($id, $nome_agente) = explode("^", $agente) ; $strIdFor = substr($hidfor, 0, -1) ; $arrIdFor = explode(",", $strIdFor) ; $strNomeFor = substr($hnomefor, 0, -1) ; $strNomeFor = str_replace(",", " / ", $strNomeFor) ; if (in_array(0, $arrIdFor)) $where_for = "1" ; else $where_for = "F.idfornitori IN ($strIdFor)" ; if ($id == 0) { $single_agente = false ; if ($strNomeCli == "Tutti") $titolo = "Totali di Tutti gli agenti verso Tutti i fornitori" ; else $titolo = "Totali di Tutti gli agenti verso il fornitore $strNomeFor" ; $where_age = "1" ; } else { $single_agente = true ; if ($strNomeFor == "Tutti") $titolo = "Totali dell'agente $nome_agente verso Tutti i fornitori" ; else $titolo = "Totali dell'agente $nome_agente verso il fornitore $strNomeFor" ; $where_age = " O.idagente = $id " ; } } elseif ($from == "ordini_per_cliente_per_mese") { $single_agente = false ; $meseToVis = $arrMesi[$mese] ; $titolo = "Totali dell'agente $nome_agente per il mese di $meseToVis" ; $where_cli = "month(O.dataordine) = $mese" ; $where_for = "1" ; } /*** * cerco di calcolare qualche totale * 1. Numero degli ordini e totali sul venduto ***/ $query = " select count(*) as TotaleOrdini, sum(AVO.AmmontareOrdineSenzaIva) as TotaleAmmontareOrdini, sum(AVO.BaseProvvigionale) as TotaleVenduto, sum(AVO.AmmontareProvvAgente) as TotaleProvvigioniVenduto from ordini O inner join agenti A on A.idagenti = O.idagente inner join clienti C on C.idclienti = O.idcliente inner join fornitori F on F.idfornitori = O.idfornitore inner join AmmontareVariOrdini AVO on AVO.idordine = O.idordini and AVO.Anno = $anno where O.Anno = $anno and $where_age and $where_cli and $where_for " ; list($n, $d) = $db->RecuperaDati($query) ; $totOrdini = $d['TotaleOrdini'][0] ; $totAmmOrd = $d['TotaleAmmontareOrdini'][0] ; $totVen = $d['TotaleVenduto'][0] ; $totProvvVen = $d['TotaleProvvigioniVenduto'][0] ; /*** * 1. Numero degli ordini con Fattura ***/ $query = " select count(*) as TotaleOrdiniConFattura, sum(AVO.AmmontareOrdineSenzaIva) as TotaleAmmontareOrdini, sum(AVO.BaseProvvigionale) as TotaleFatturato, sum(AVO.AmmontareProvvAgente) as TotaleProvvigioniFatturato from ordini O inner join agenti A on A.idagenti = O.idagente inner join clienti C on C.idclienti = O.idcliente inner join fornitori F on F.idfornitori = O.idfornitore inner join AmmontareVariOrdini AVO on AVO.idordine = O.idordini and AVO.Anno = $anno where O.Anno = $anno and O.ImportoFattura > 0 and $where_age and $where_cli and $where_for " ; list($n, $d) = $db->RecuperaDati($query) ; $totOrdiniConFattura = $d['TotaleOrdiniConFattura'][0] ; $totAmmOrdConFattura = $d['TotaleAmmontareOrdini'][0] ; $totFat = $d['TotaleFatturato'][0] ; $totProvvFat = $d['TotaleProvvigioniFatturato'][0] ; /*************************************** * controllo la colonna da ordinare ***************************************/ switch($colToSort) { case 0: // numero ordine $order_by = "O.IdOrdini $direction" ; break ; case 1: // numero fattura $order_by = "O.NumFattura $direction" ; break ; case 2: // nome agente $order_by = "A.Nome $direction, O.IdOrdini ASC" ; break ; case 3: // nome cliente $order_by = "C.Nome $direction, O.IdOrdini ASC" ; break ; case 4: // nome fornitore $order_by = "F.Nome $direction, O.IdOrdini ASC" ; break ; case 5: // ammontare ordine senza iva $order_by = "AVO.AmmontareOrdineSenzaIva $direction, O.IdOrdini ASC" ; break ; case 6: // imponibile provvigionale $order_by = "AVO.BaseProvvigionale $direction, O.IdOrdini ASC" ; break ; case 7: // data ordine $order_by = "O.DataOrdine $direction, O.IdOrdini ASC" ; break ; case 8: // data fattura $order_by = "O.DataSpedFattura $direction, O.IdOrdini ASC" ; break ; case 9: // percentuale provvigione agente $order_by = "AVO.PercentualeProvvAgente $direction, O.IdOrdini ASC" ; break ; case 10: // ammontare provvigione agente $order_by = "AVO.AmmontareProvvAgente $direction, O.IdOrdini ASC" ; break ; default: // mesi $order_by = "O.IdOrdini ASC" ; break ; } $query = " select O.IdOrdini, O.NumFattura, O.ImportoFattura, O.DataOrdine, O.DataSpedFattura, A.Nome as NomeAgente, C.Nome as NomeCliente, F.Nome as NomeFornitore, AVO.* from $tordini O inner join $tagenti A on A.idagenti = O.idagente inner join $tclienti C on C.idclienti = O.idcliente inner join $tfornitori F on F.idfornitori = O.idfornitore inner join $tAmmontareVariOrdini AVO on AVO.idordine = O.idordini where $where_age and $where_cli and $where_for order by $order_by " ; list($n, $d) = $db->RecuperaDati($query) ; // print_r($d) ; exit ; $arrParGen = array() ; $arrParGen = RecuperaParametriGenerali($arrParGen, $tparametri) ; $nome = $arrParGen['NomeAgenzia'] ; $sede = "Sede operativa: " . $arrParGen['IndirizzoAgenzia'] ; $datisede = "Telefono: " . $arrParGen['TelefonoAgenzia'] . " Fax: " . $arrParGen['FaxAgenzia'] . " -- P.I. " . $arrParGen['PartitaIvaAgenzia'] ; $emailsede = "Email: " . $arrParGen['MailAgenzia'] ; $titolo .= " $anno" ; ?> <? echo TITLE ?>




al
Num.Ordine Num.Fattura Agente Cliente Fornitore Imp.Ordine Imp.Provv Data Ordine Data Fattura %Provv Provvigione
Totale Venduto        
Totale Fatturato