"); $log = true ; if ($log) $handle = fopen('log_LoadControllaProvvAg.txt', 'a+') ; $posStart = $_GET['posStart'] ; $count = $_GET['count'] ; if ($log) { fwrite($handle, "posStart = " . $posStart . "\n") ; fwrite($handle, "count = " . $count . "\n") ; } /*************************************************************************** * where-list ***************************************************************************/ $dataDal = $_GET["dataDal"] ; $dataAl = $_GET["dataAl"] ; $idAgente = $_GET["idAgente"] ; $totAuto = $_GET["totAuto"] ; $tipo = $_GET["tipo"] ; $fattSald = $_GET["fattSald"] ; $fattAgSald = $_GET["fattAgSald"] ; $ordinaper = $_GET["ordinaper"] ; $direction = $_GET["direction"] ; $where = "1=1" ; /************************* * filtro Fattura Saldata **************************/ if (isset($fattSald) and ($fattSald != 'tutti') and ($fattSald != '')) $where .= " and O.SaldoFattura = $fattSald" ; /************************************ * filtro Provvigione Agenzia Saldata ************************************/ if (isset($fattAgSald) and ($fattAgSald != 'tutti') and ($fattAgSald != '')) $where .= " and O.SaldoProvvigione = $fattAgSald" ; /*************************************** * controllo la colonna da ordinare ***************************************/ switch($ordinaper) { case 0: // Numero Ordine $orderBy = "O.IdOrdini $direction" ; break ; case 1: // Numero Fattura $orderBy = "O.NumFattura $direction, O.IdOrdini ASC" ; break ; case 2: // Fattura Saldata $orderBy = "O.SaldoFattura $direction, O.IdOrdini ASC" ; break ; case 3: // Nome Cliente $orderBy = "C.Nome $direction, O.IdOrdini ASC" ; break ; case 4: // Data Fatturazione $orderBy = "O.DataSpedFattura $direction, O.IdOrdini ASC" ; break ; case 5: // Importo Ordine (Base Provvigionale) $orderBy = "AVO.BaseProvvigionale $direction, O.IdOrdini ASC" ; break ; case 6: // Percentuale Agente $orderBy = "AFP.Percentuale $direction, O.IdOrdini ASC" ; break ; case 7: // Importo Provvigione Agente $orderBy = "AVO.AmmontareProvvAgente $direction, O.IdOrdini ASC" ; break ; case 8: // Provvigione Agente Saldata $orderBy = "O.SaldoProvvigione $direction, O.IdOrdini ASC" ; break ; case 9: // provincia $orderBy = "C.provincia $direction, O.IdOrdini ASC" ; break ; case 10: // telefono $orderBy = "C.telefono $direction, O.IdOrdini ASC" ; break ; case 11: // fax $orderBy = "C.fax $direction, O.IdOrdini ASC" ; break ; case 12: // email $orderBy = "C.email $direction, O.IdOrdini ASC" ; break ; case 13: // consegna $orderBy = "C.consegna $direction, O.IdOrdini ASC" ; break ; case 14: // note $orderBy = "C.note $direction, O.IdOrdini ASC" ; break ; default: // Numero Ordine $orderBy = "O.IdOrdini $direction" ; break ; } if ($totAuto == 1) $flagCalcola = 1 ; else $flagCalcola = 0 ; if ($tipo == "nonpagate") { // Ordini con provvigioni NON PAGATE $query = " select *, AFP.percentuale as PercentualeAgente, A.Percentuale as PercentualeDefault, C.Nome as NomeCliente from $tordini O inner join $tclienti C on C.IdClienti = O.IdCliente inner join $tpagamenti P on P.IdPagamenti = O.IdPagamento inner join $tageforper AFP on AFP.IdAgente = O.IdAgente and AFP.IdFornitore = O.IdFornitore inner join $tagenti A on A.IdAgenti = O.IdAgente 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 = $idAgente and $where order by $orderBy " ; } else { $flag_chk = 0 ; // Ordini con provvigioni PAGATE $query = " select *, AFP.percentuale as PercentualeAgente, A.Percentuale as PercentualeDefault, C.Nome as NomeCliente from $tordini O inner join $tclienti C on C.IdClienti = O.IdCliente inner join $tpagamenti P on P.IdPagamenti = O.IdPagamento inner join $tageforper AFP on AFP.IdAgente = O.IdAgente and AFP.IdFornitore = O.IdFornitore inner join $tagenti A on A.IdAgenti = O.IdAgente 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 = $idAgente and $where order by $orderBy " ; } debug(0, $query) ; if ($log) fwrite($handle, "$query \n") ; list($nrowsdati, $dati) = $db->RecuperaDati($query) ; if ($log) fwrite($handle, "\n") ; print("") ; list($n, $d) = $db->RecuperaDati($query) ; // print_r($d) ; for ($i=0; $i<$n; $i++) { $idOrdine = $d['IdOrdini'][$i] ; $numFattura = $d['NumFattura'][$i] ; if ($d['PercentualeAgente'][$i] != 0) $per = nfp($d['PercentualeAgente'][$i]) ; else $per = nfp($d['PercentualeDefault'][$i]) ; $saldFattura = SiNo($d['SaldoFattura'][$i]) ; $cliente = htmlspecialchars($d['NomeCliente'][$i]) ; $dataSpedFattura = ItaDate($d['DataSpedFattura'][$i]) ; $totOrd = nfe($d['BaseProvvigionale'][$i]) ; $ammProvvAgente = nfe($d['AmmontareProvvAgente'][$i]) ; $provvAgSaldata = SiNo($d['SaldoProvvigione'][$i]) ; $str .= "$flag_chk" ; $str .= "" ; if ($log) fwrite($handle, "$cliente$agente$categoria$piva$codfis$indirizzo$cap$citta$prov$telefono$fax$email$consegna$note\n") ; print ("$idOrdine$numFattura$saldFattura$cliente$dataSpedFattura$totOrd$per$ammProvvAgente$provvAgSaldata$flagCalcola") ; } print ("") ; if ($log) fclose($handle) ; ?>