include ("../common/public.php") ; // print_r($_GET + $_POST) ; // exit ; if ($tot_auto == 1) $flag_chk = 1 ; else $flag_chk = 0 ; if (isset($agente) and ($agente != 0)) { $db->query("select * from $tagenti where IdAgenti = $agente") ; while ($db->next_record()) $nome = $db->f("Nome") ; } if ($dal == "") { $datadal = MySqlDate("01/01/$anno") ; $dataal = MySqlDate("31/12/$anno") ; } else { $datadal = MySqlDate($dal) ; $dataal = MySqlDate($al) ; } /*** * devo considerare se c'è qualche filtro ***/ /************************* * filtro Fattura Saldata **************************/ if (isset($fatt_sald) and ($fatt_sald != 'tutti') and ($fatt_sald != '')) $where .= " and O.SaldoFattura = $fatt_sald" ; /************************************ * filtro Provvigione Agenzia Saldata ************************************/ if (isset($fatt_ag_sald) and ($fatt_ag_sald != 'tutti') and ($fatt_ag_sald != '')) $where .= " and O.SaldoProvvigione = $fatt_ag_sald" ; /******************************************************************************* * controllo se devo eseguire degli ordinamenti e qual è la colonna da ordinare *******************************************************************************/ if (! isset($colToSort)) $colToSort = 0 ; if (! isset($direction)) $direction = "ASC" ; $strLoadXml = "LoadControllaProvvAg.php?ordinaper=$colToSort&direction=$direction&dataDal=$datadal&dataAl=$dataal&idAgente=$agente&totAuto=$tot_auto&tipo=$tipo&fattSald=$fatt_sald&fattAgSald=$fatt_ag_sald" ; /*** * Mi calcolo qualche totale che mi serve ***/ if ($tipo == "nonpagate") { $titolo = "Ordini con provvigioni NON PAGATE all'Agente: $nome" ; $qTot = " select count(*) as TotaleOrdini, sum(Avo.BaseProvvigionale) as BaseProvvigionale, sum(AVO.AmmontareProvvAgente) as AmmontareProvvAgente from $tordini O inner join $tAmmontareVariOrdini AVO on AVO.IdOrdine = O.IdOrdini where O.NumFattura <> 0 and O.SaldoProvvigioneAgente = 0 and O.DataSpedFattura >= '$datadal' and O.DataSpedFattura <= '$dataal' and O.idagente = $agente $where " ; } else { $titolo = "Ordini con provvigioni PAGATE all'Agente: $nome" ; $qTot = " select count(*) as TotaleOrdini, sum(Avo.BaseProvvigionale) as BaseProvvigionale, sum(AVO.AmmontareProvvAgente) as AmmontareProvvAgente from $tordini O inner join $tAmmontareVariOrdini AVO on AVO.IdOrdine = O.IdOrdini where O.NumFattura <> 0 and O.SaldoProvvigioneAgente = 1 and O.DataSpedFattura >= '$datadal' and O.DataSpedFattura <= '$dataal' and O.idagente = $agente $where " ; } debug (0, $qTot) ; list($n, $d) = $db->RecuperaDati($qTot) ; $totOrdini = $d['TotaleOrdini'][0] ; $totale = $d['BaseProvvigionale'][0] ; $totaleprov = $d['AmmontareProvvAgente'][0] ; if ($tipo == "nonpagate") { if ($tot_auto == 0) $totaleprov = 0.00 ; $header = "N. ORD,N. FATT,FATT SALD?,CLIENTE,DATA FATT.,IMPORTO,% PROVV,PROVV,PROVV AG SALD?,CALCOLA" ; $footer = "TOTALE:-#cspan-#cspan-#cspan-#cspan-" . nfe($totale) . "--" . "