Non puoi selezionare più di 25 argomenti
Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
194 righe
9.9 KiB
194 righe
9.9 KiB
<?php |
|
class reportGare extends reportModulo { |
|
|
|
public static function getReportSettings() { |
|
return include(__DIR__ . "/config.php"); |
|
} |
|
|
|
public static function getReportData(string $from = null, string $to = null, array $filters = null) { |
|
if (!empty($_SESSION["utente"])) { |
|
global $pdo; |
|
$data = []; |
|
$bind = []; |
|
$enti = array_column($_SESSION["utente"]->getEntiBeneficiari(),"codice"); |
|
$sql = "SELECT b_gare.codice FROM b_gare JOIN b_gare_round ON b_gare.codice = b_gare_round.codice_gara WHERE b_gare.codice_ente IN (".implode(",",$enti).") "; |
|
if (!empty($from)) { |
|
$bind[":from"] = $from; |
|
$sql .= " AND DATE(b_gare_round.pubblicazione) >= :from "; |
|
} |
|
if (!empty($to)) { |
|
$bind[":to"] = $to; |
|
$sql .= " AND DATE(b_gare_round.pubblicazione) <= :to "; |
|
} |
|
$settings = self::getReportSettings(); |
|
$where = []; |
|
if (!empty($filters)) { |
|
foreach($filters AS $key => $value) { |
|
if (isset($settings["filters"][$key]) && in_array($value,array_keys($settings["filters"][$key]["values"]),true) !== false) { |
|
$bind[":{$key}_filter"] = $value; |
|
$where[] = " $key = :{$key}_filter "; |
|
} |
|
} |
|
} |
|
if (!empty($where)) { |
|
$where = implode (" AND ", $where); |
|
$sql .= " AND {$where}"; |
|
} |
|
$sql .= " GROUP BY b_gare.codice"; |
|
$tmp = $pdo->go($sql,$bind); |
|
$stati = gara::getStati(); |
|
if ($tmp->rowCount() > 0) { |
|
$risGara = $pdo->prepare("SELECT * FROM b_gare WHERE codice = :codice"); |
|
$risLotti = $pdo->prepare("SELECT * FROM b_gare_lotti WHERE codice_gara = :codice"); |
|
$risRound = $pdo->prepare("SELECT * FROM b_gare_round WHERE codice_gara = :codice"); |
|
$risPartecipanti = $pdo->prepare("SELECT codice, codice_fiscale, ragione_sociale,aggiudicatario FROM r_partecipanti_gare WHERE codice_round = :codice_round AND codice_lotto = :codice_lotto AND conferma = 'S'"); |
|
$risInviti = $pdo->prepare("SELECT id FROM r_inviti_gare WHERE codice_round = :codice_round AND codice_lotto = :codice_lotto"); |
|
$tempInviti = $pdo->prepare("SELECT codice FROM temp_inviti WHERE attivo = 'S' AND contesto = 'gare' AND codice_elemento = :codice_round AND sub_elemento = :codice_lotto"); |
|
$oggettoElenco = $pdo->prepare("SELECT oggetto FROM b_bandi_albo WHERE codice = :codice AND tipologia <> 'I' "); |
|
while($codiceGara = $tmp->fetch(PDO::FETCH_COLUMN)) { |
|
$row = []; |
|
$risGara->execute([":codice"=>$codiceGara]); |
|
$datiGara = $risGara->fetch(PDO::FETCH_ASSOC); |
|
$extraInfoGara = json_decode($datiGara["extraInfo"],true); |
|
$risRound->execute([":codice"=>$codiceGara]); |
|
$datiRound = $risRound->fetchAll(PDO::FETCH_ASSOC); |
|
$risLotti->execute([":codice"=>$codiceGara]); |
|
$datiLotti = $risLotti->fetchAll(PDO::FETCH_ASSOC); |
|
$row["id"] = $datiGara["id"]; |
|
$row["oggetto"] = $datiGara["oggetto"]; |
|
$row["beneficiario"] = ente::getInfoFromID($datiGara["codice_ente"])[0]["denominazione"]; |
|
$row["rup"] = ""; |
|
$row["cf"] = ""; |
|
$rup = incarichi::getIncaricatiFromElement('gare',$codiceGara,14); |
|
if (!empty($rup[0])) { |
|
$rup = $rup[0]; |
|
$row["rup"] = $rup["extraInfo"]["cognome"] . " " . $rup["extraInfo"]["nome"]; |
|
$row["cf"] = $rup["codice_fiscale"]; |
|
} |
|
$row["cig"] = null; |
|
$row["criterio"] = null; |
|
if (!empty($datiLotti)) { |
|
$row["cig"] = trim(implode("/",array_column($datiLotti,"cig")),"/"); |
|
$cpv = array_column($datiLotti,"cpv"); |
|
$cpv = cpvManager::getInfo($cpv); |
|
$row["cpv"] = trim(implode("/",array_column($cpv,"codice_completo")),"/"); |
|
$tmpCriteri = array_unique(array_filter(array_column($datiLotti,"criterio"))); |
|
if (!empty($tmpCriteri)) { |
|
sort($tmpCriteri); |
|
$criteri = []; |
|
foreach($tmpCriteri AS $criterio) { |
|
$criteri[] = getCriteri(false)[$criterio]["titolo"]; |
|
} |
|
$row["criterio"] = implode("/",$criteri); |
|
} |
|
} |
|
$row["tipologia"] = getTipologieAffidamento(false)[$datiGara["tipologia"]]["titolo"]; |
|
$row["procedura"] = getProcedure(false)[$datiGara["procedura"]]["titolo"]; |
|
$pubblicazioni = array_filter(array_column($datiRound,"pubblicazione")); |
|
$scadenze = array_filter(array_column($datiRound,"scadenza")); |
|
$row["pubblicazione"] = (!empty($pubblicazioni)) ? min($pubblicazioni) : null; |
|
$row["scadenza"] = (!empty($scadenze)) ? max($scadenze) : null; |
|
$row["stato"] = $stati[$datiGara["stato"]]["titolo"]; |
|
$row["importo"] = $datiGara["prezzoRiferimento"]; |
|
$row["aggiudicato"] = 0; |
|
$row["ribasso"] = null; |
|
$row["elenco"] = null; |
|
$inviti = 0; |
|
$partecipanti = 0; |
|
foreach($datiRound AS $round) { |
|
$checkInvitiLotto = true; |
|
$extraInfoRound = json_decode($round["extraInfo"],true); |
|
if (!empty($extraInfoRound["tipo_elenco_invito"]) && !empty($extraInfoRound["codice_elenco_invito"]) && $extraInfoRound["tipo_elenco_invito"] == "b_bandi_albo") { |
|
$oggettoElenco->bindValue(":codice", $extraInfoRound["codice_elenco_invito"]); |
|
$oggettoElenco->execute(); |
|
if ($oggettoElenco->rowCount() === 1) { |
|
$row["elenco"] = $oggettoElenco->fetch(PDO::FETCH_COLUMN); |
|
} |
|
} |
|
$risInviti->bindValue(":codice_round",$round["codice"]); |
|
$risPartecipanti->bindValue(":codice_round",$round["codice"]); |
|
$tempInviti->bindValue(":codice_round",$round["codice"]); |
|
$risInviti->bindValue(":codice_lotto",0); |
|
$risInviti->execute(); |
|
if($risInviti->rowCount() > 0) { |
|
$checkInvitiLotto = false; |
|
$inviti += $risInviti->rowCount(); |
|
} |
|
$tempInviti->bindValue(":codice_lotto",0); |
|
$tempInviti->execute(); |
|
if($tempInviti->rowCount() > 0) { |
|
$checkInvitiLotto = false; |
|
$inviti += $tempInviti->rowCount(); |
|
} |
|
$attiAggiudicazione = []; |
|
$dateAttiAggiudicazione = []; |
|
$aggiudicatari = []; |
|
foreach($datiLotti AS $lotto) { |
|
$extraInfoLotto = json_decode($lotto["extraInfo"],true); |
|
$aggiudicazione = trim($extraInfoLotto["estremi_definitiva"] ?? null); |
|
if (!empty($aggiudicazione)) { |
|
$atto = $aggiudicazione; |
|
$attiAggiudicazione[] = $atto; |
|
$re = '/([0-9]{2}\/[0-9]{2}\/[0-9]{4})/m'; |
|
preg_match_all($re, $atto, $matches, PREG_SET_ORDER, 0); |
|
if (!empty($matches[0][0])) { |
|
$dataAtto = date2mysql($matches[0][0]); |
|
if (!empty($dataAtto)) { |
|
$dateAttiAggiudicazione[] = $dataAtto; |
|
} |
|
} |
|
} |
|
$row["aggiudicato"] += $lotto["importoAggiudicazione"]; |
|
$risPartecipanti->bindValue(":codice_lotto",$lotto["codice"]); |
|
$risPartecipanti->execute(); |
|
if($risPartecipanti->rowCount() > 0) { |
|
$partecipanti += $risPartecipanti->rowCount(); |
|
while($partecipante = $risPartecipanti->fetch(PDO::FETCH_ASSOC)) { |
|
if ($partecipante["aggiudicatario"] == "S") { |
|
$aggiudicatari[] = $partecipante["codice_fiscale"] . "-" . $partecipante["ragione_sociale"]; |
|
} |
|
} |
|
} |
|
if ($checkInvitiLotto) { |
|
$risInviti->bindValue(":codice_lotto",$lotto["codice"]); |
|
$risInviti->execute(); |
|
if($risInviti->rowCount() > 0) { |
|
$inviti += $risInviti->rowCount(); |
|
} |
|
$tempInviti->bindValue(":codice_lotto",$lotto["codice"]); |
|
$tempInviti->execute(); |
|
if($tempInviti->rowCount() > 0) { |
|
$inviti += $tempInviti->rowCount(); |
|
} |
|
} |
|
} |
|
} |
|
if (empty($row["aggiudicato"])) { |
|
$row["aggiudicato"] = null; |
|
} else if ($row["aggiudicato"] < $row["importo"]) { |
|
$differenza = $row["importo"] - $row["aggiudicato"]; |
|
$row["ribasso"] = ($differenza * 100) / $row["importo"]; |
|
} |
|
$row["inviti"] = $inviti; |
|
$row["partecipanti"] = $partecipanti; |
|
$row["contributo"] = $datiGara["contributoSUA"]; |
|
$row["incassato"] = $datiGara["contributoSUAVersato"]; |
|
$row["utente"] = null; |
|
if ($datiGara["utente_creazione"] > 0) { |
|
$infoUtente = Utente::getInfoFromID($datiGara["utente_creazione"]); |
|
$row["utente"] = "{$infoUtente["cognome"]} {$infoUtente["nome"]}"; |
|
} |
|
$row["soggettoApprovatore"] = $extraInfoGara["soggettoApprovatore"] ?? ""; |
|
$row["responsabileStruttura"] = $extraInfoGara["responsabileStruttura"] ?? ""; |
|
$row["provvedimentoIndizione"] = $extraInfoGara["provvedimentoIndizione"] ?? ""; |
|
$row["dataProvvedimentoIndizione"] = $extraInfoGara["dataProvvedimentoIndizione"] ?? ""; |
|
$row["provvedimentoAggiudicazione"] = implode("/",$attiAggiudicazione); |
|
$row["dataProvvedimentoAggiudicazione"] = implode("|",$dateAttiAggiudicazione); |
|
$row["aggiudicatario"] = implode("/",$aggiudicatari); |
|
$data[] = $row; |
|
} |
|
} |
|
return $data; |
|
} |
|
} |
|
}
|
|
|