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.
995 righe
39 KiB
995 righe
39 KiB
<? |
|
class stipula { |
|
|
|
public $info; |
|
protected $db; |
|
public $object; |
|
public $codice_gestore; |
|
public $managerRichieste; |
|
|
|
private function __construct() { |
|
global $pdo; |
|
$this->db = $pdo; |
|
$this->codice_gestore = $_SESSION["ente"]->codice; |
|
} |
|
|
|
public static function getIdFromExternal(String $id) { |
|
global $pdo; |
|
return $pdo->go("SELECT b_contratti.codice FROM b_contratti WHERE riferimento_esterno = :id",[":id"=>$id])->fetch(PDO::FETCH_COLUMN); |
|
} |
|
|
|
public static function getIdDerivazionePrincipale(string $modulo,string $elemento) { |
|
global $pdo; |
|
$relazione = null; |
|
switch($modulo) { |
|
case "pcp": |
|
$relazione = $pdo->go("SELECT codice_pcp FROM b_pcp_round WHERE codice = :codice",[":codice"=>$elemento])->fetch(PDO::FETCH_COLUMN); |
|
break; |
|
case "gare": |
|
$relazione = $pdo->go("SELECT codice_gara FROM b_gare_lotti WHERE codice = :codice",[":codice"=>$elemento])->fetch(PDO::FETCH_COLUMN); |
|
break; |
|
} |
|
return $relazione; |
|
} |
|
|
|
public function getBreadcrumb($breadcrumb = []) { |
|
if (!empty($this->info["modulo_origine"]) && !empty(!empty($this->info["codice_elemento"]))) { |
|
$relazione = self::getIdDerivazionePrincipale($this->info["modulo_origine"],$this->info["codice_elemento"]); |
|
if (!empty($relazione) && ($_SESSION["utente"]->permission($this->info["modulo_origine"],$relazione))) { |
|
global $beRoot; |
|
if (file_exists("{$beRoot}/{$this->info["modulo_origine"]}/panel.php")) { |
|
$infoModulo = Modulo::getInfo($this->info["modulo_origine"]); |
|
$breadcrumb["/{$this->info["modulo_origine"]}/panel.php?codice={$relazione}"] = __($infoModulo["titolo"]) . " - " . __("Pannello"); |
|
} |
|
} |
|
} |
|
return $breadcrumb; |
|
} |
|
|
|
public static function getContrattiFromModulo($modulo,$elemento) { |
|
global $pdo; |
|
$bind = [":modulo"=>$modulo,":elemento"=>$elemento,":gestore"=>$_SESSION["ente"]->codice]; |
|
$sql = "SELECT b_contratti.codice, b_contratti.importo_totale, b_contratti.id,b_contratti.stato,b_contratti.oggetto,b_contratti.data_stipula,b_contratti.data_inizio,b_contratti.data_fine, |
|
GROUP_CONCAT(b_contraenti.codice_operatore, \":\" , b_contraenti.denominazione SEPARATOR \"-_-\") AS operatori |
|
FROM b_contratti |
|
LEFT JOIN r_contraenti ON b_contratti.codice = r_contraenti.codice_contratto |
|
LEFT JOIN b_contraenti ON r_contraenti.codice_contraente = b_contraenti.codice AND b_contraenti.tipologia = 'oe' |
|
WHERE b_contratti.modulo_origine = :modulo AND b_contratti.codice_elemento = :elemento AND b_contratti.codice_gestore = :gestore |
|
GROUP BY b_contratti.codice "; |
|
$return = $pdo->go($sql,$bind)->fetchAll(PDO::FETCH_ASSOC); |
|
return $return; |
|
} |
|
|
|
public function updateStato(int $stato,bool $force = false) { |
|
if ($this->info["stato"] < $stato || $force) { |
|
$this->db->go("UPDATE b_contratti SET stato = :stato WHERE codice = :codice",[":stato"=>$stato,":codice"=>$this->info["codice"]]); |
|
} |
|
if (isset($_SESSION["ente"])) { |
|
$_SESSION["ente"]->manageUpdates("stipula",$this->info["codice"],$this); |
|
$_SESSION["ente"]->checkConservazione("stipula", $this->info["codice"], $this->info["stato"], $this->info["codice_ente"]); |
|
} |
|
} |
|
|
|
public function getAllegati() : array { |
|
return $this->db->go("SELECT * FROM b_fileManager WHERE sourceID = :codice AND sourceType = 'contratti-public'", [":codice" => $this->info['codice']])->fetchAll(PDO::FETCH_ASSOC); |
|
} |
|
|
|
public static function saveContratto($data,$codici_operatore = []) { |
|
global $pdo; |
|
$entiAbilitati = $_SESSION["utente"]->getEntiBeneficiari(); |
|
if ($_SESSION["ente"]->checkLimite("contratti") || $data["codice"] > 0) { |
|
$checkEnte = false; |
|
$return = false; |
|
foreach($entiAbilitati AS $ente) { |
|
if ($data["codice_ente"] == $ente["codice"]) { |
|
$checkEnte = true; |
|
break; |
|
} |
|
} |
|
if ($checkEnte) { |
|
$operazione = empty($data["codice"]) ? "INSERT" : "UPDATE"; |
|
if ($operazione == "INSERT") { |
|
$data["id"] = 1; |
|
$sql = "SELECT id FROM b_contratti WHERE codice_gestore = :codice_gestore ORDER BY id DESC LIMIT 0,1 "; |
|
$ris = $pdo->go($sql,array(":codice_gestore"=>$_SESSION["ente"]->codice)); |
|
if ($ris->rowCount() === 1) { |
|
$rec = $ris->fetch(PDO::FETCH_ASSOC); |
|
$data["id"] = $rec["id"] + 1; |
|
} |
|
$data["codice_gestore"] = $_SESSION["ente"]->codice; |
|
} |
|
|
|
$salva = new salva(); |
|
$salva->debug = false; |
|
|
|
$salva->nome_tabella = "b_contratti"; |
|
$salva->operazione = $operazione; |
|
$salva->oggetto = $data; |
|
$codice = $salva->save(); |
|
if ($codice !== false) { |
|
if (!$_SESSION["ente"]->checkLimite("contratti") && empty($data["codice"])) { |
|
$_SESSION["ente"]->sendAlertLimite("contratti"); |
|
} |
|
$return = $codice; |
|
if (!empty($data["cig"])) { |
|
if (isset($data["data_inizio"])) { anac::updateDati190($data["cig"],"190data_inizio",$data["data_inizio"],$_SESSION["ente"]->codice); } |
|
if (isset($data["data_fine"])) { anac::updateDati190($data["cig"],"190data_fine",$data["data_fine"],$_SESSION["ente"]->codice); } |
|
} |
|
if ($_SESSION["utente"]->gerarchia > 15) { |
|
$utenti = [$_SESSION["utente"]->codice]; |
|
} |
|
if (!empty($utenti)) { |
|
foreach($utenti AS $utente) { |
|
$permesso = []; |
|
$permesso["sezione"] = "contratti"; |
|
$permesso["codice_elemento"] = $codice; |
|
$permesso["codice_gestore"] = $_SESSION["ente"]->codice; |
|
$permesso["funzione"] = "0"; |
|
$permesso["codice_utente"] = $utente; |
|
$salva = new salva(); |
|
$salva->debug = false; |
|
|
|
$salva->nome_tabella = "r_permessi"; |
|
$salva->operazione = "INSERT"; |
|
$salva->oggetto = $permesso; |
|
$salva->save(); |
|
} |
|
} |
|
$contratto = self::init($return); |
|
if (!empty($contratto)) { |
|
if (!empty($codici_operatore)) { |
|
foreach($codici_operatore AS $oe) { |
|
if (!empty($oe)) { $contratto->createContraenteFromOE($oe); } |
|
} |
|
} |
|
$_SESSION["ente"]->manageUpdates("stipula",$contratto->info["codice"],$contratto); |
|
} |
|
} |
|
} |
|
} |
|
return $return; |
|
} |
|
|
|
public function saveExtraInfo($chiave,$valore) { |
|
$extraInfo = $this->getExtraInfo(); |
|
$extraInfo[$chiave] = $valore; |
|
$this->info["extraInfo"] = $extraInfo = json_encode($extraInfo); |
|
$salva = new salva(); |
|
$salva->debug = false; |
|
|
|
$salva->nome_tabella = "b_contratti"; |
|
$salva->operazione = "UPDATE"; |
|
$salva->oggetto = ["codice"=>$this->info["codice"],"extraInfo"=>$extraInfo]; |
|
if (!empty($salva->save())) { return true; } |
|
return false; |
|
} |
|
|
|
public function saveUnimodData(string $json) : bool{ |
|
$salva = new salva(); |
|
$salva->debug = false; |
|
|
|
$salva->nome_tabella = "b_contratti"; |
|
$salva->operazione = "UPDATE"; |
|
$salva->oggetto = [ |
|
"codice" => $this->info["codice"], |
|
"unimod_data" => $json |
|
]; |
|
if (!empty($salva->save())) { return true; } |
|
return false; |
|
} |
|
|
|
public function saveUnimodXML(string $xml) : bool { |
|
$salva = new salva(); |
|
$salva->debug = false; |
|
|
|
$salva->nome_tabella = "b_contratti"; |
|
$salva->operazione = "UPDATE"; |
|
$salva->oggetto = [ |
|
"codice" => $this->info["codice"], |
|
"unimod_xml" => $xml |
|
]; |
|
if (!empty($salva->save())) { return true; } |
|
return false; |
|
} |
|
|
|
public function getExtraInfo() { |
|
if (!empty($this->info["extraInfo"])) { |
|
return json_decode($this->info["extraInfo"],true); |
|
} |
|
return false; |
|
} |
|
|
|
public static function getStati() { |
|
global $beRoot; |
|
return jsonToArray($beRoot."/contratti/stati.json"); |
|
} |
|
|
|
public function getContraenti($type, $codice=null, $codice_oe = null) { |
|
if ($type == "oe" || $type=="ore" || $type=="uff") { |
|
$bind = [":codice_contratto"=>$this->info["codice"],":type"=>$type]; |
|
$sql = "SELECT b_contraenti.*, r_contraenti.codice AS codice_relazione, r_contraenti.extraInfo AS infoRelazione FROM b_contraenti JOIN r_contraenti ON b_contraenti.codice = r_contraenti.codice_contraente |
|
WHERE b_contraenti.tipologia = :type AND r_contraenti.codice_contratto = :codice_contratto "; |
|
if (!empty($codice)) { |
|
$bind[":codice"]=$codice; |
|
$sql .= " AND b_contraenti.codice = :codice "; |
|
} |
|
|
|
if(!empty($codice_oe)){ |
|
$bind[":codice_operatore"] = $codice_oe; |
|
$sql .= " AND b_contraenti.codice_operatore = :codice_operatore "; |
|
} |
|
|
|
$tmpContraenti = $this->db->go($sql,$bind)->fetchAll(PDO::FETCH_ASSOC); |
|
if (!empty($tmpContraenti)) { |
|
$contraenti = []; |
|
foreach($tmpContraenti AS $contraente) { |
|
$contraente["extraInfo"] = json_decode($contraente["extraInfo"],true); |
|
$contraenti[] = $contraente; |
|
} |
|
return $contraenti; |
|
} |
|
} |
|
return false; |
|
} |
|
|
|
public static function ruoliEsponentiSA() { |
|
$ruoli = []; |
|
$ruoli["dirigente"] = "Dirigente"; |
|
$ruoli["segretario-generale"] = "Segretario Generale"; |
|
$ruoli["rettore"] = "Rettore"; |
|
$ruoli["pro-Rettore"] = "Pro-Rettore"; |
|
$ruoli["direttore-Generale"] = "Direttore Generale"; |
|
$ruoli["amministratore-delegato"] = "Amministratore Delegato"; |
|
$ruoli["responsabile-funzione"] = "Responsabile Funzione"; |
|
$ruoli["altro"] = "Altro"; |
|
return $ruoli; |
|
} |
|
|
|
public static function ruoliUfficiali() { |
|
$ruoli = []; |
|
$ruoli["segretario generale"] = "Segretario generale"; |
|
$ruoli["notaio"] = "Notaio"; |
|
$ruoli["ufficiale rogante"] = "Ufficiale rogante"; |
|
$ruoli["altro"] = "Altro ruolo"; |
|
return $ruoli; |
|
} |
|
|
|
public function getEsponentiSA($codice = NULL) { |
|
$bind = [":codice_ente"=>$this->codice_gestore]; |
|
$sql = ""; |
|
if (!empty($codice)) { |
|
$bind[":codice"] = $codice; |
|
$sql = " AND codice = :codice "; |
|
} |
|
$return = []; |
|
$tmp = $this->db->go("SELECT * FROM b_contraenti WHERE codice_gestore = :codice_ente AND tipologia = 'ore' {$sql}",$bind)->fetchAll(PDO::FETCH_ASSOC); |
|
if (!empty($tmp)) { |
|
foreach($tmp AS $esponente) { |
|
$esponente["extraInfo"] = json_decode($esponente["extraInfo"],true); |
|
$return[] = $esponente; |
|
} |
|
} |
|
return $return; |
|
} |
|
|
|
public function getUfficialiRoganti($codice = NULL) { |
|
$bind = [":codice_ente"=>$this->codice_gestore]; |
|
$sql = ""; |
|
if (!empty($codice)) { |
|
$bind[":codice"] = $codice; |
|
$sql = " AND codice = :codice "; |
|
} |
|
$return = []; |
|
$tmp = $this->db->go("SELECT * FROM b_contraenti WHERE codice_gestore = :codice_ente AND tipologia = 'uff' {$sql}",$bind)->fetchAll(PDO::FETCH_ASSOC); |
|
if (!empty($tmp)) { |
|
foreach($tmp AS $esponente) { |
|
$esponente["extraInfo"] = json_decode($esponente["extraInfo"],true); |
|
$return[] = $esponente; |
|
} |
|
} |
|
return $return; |
|
} |
|
|
|
public function getOOEE() { |
|
return $this->db->go("SELECT b_contraenti.codice_operatore FROM b_contraenti JOIN r_contraenti ON b_contraenti.codice = r_contraenti.codice_contraente |
|
WHERE b_contraenti.codice_operatore > 0 AND r_contraenti.codice_contratto = :codice_contratto ", |
|
[":codice_contratto"=>$this->info["codice"]])->fetchAll(PDO::FETCH_ASSOC); |
|
} |
|
|
|
public function createContraenteFromOE($codice_operatore) { |
|
global $root; |
|
if (!empty($codice_operatore)) { |
|
$oe = oeManager::getOE($codice_operatore); |
|
if (!empty($oe)) { |
|
$contraenti = $this->getContraenti("oe"); |
|
$found = false; |
|
if (!empty($contraenti)) { |
|
foreach($contraenti AS $check) { |
|
if ($check["codice_operatore"] == $oe["codice"]) { |
|
$found = true; |
|
break; |
|
} |
|
} |
|
} |
|
if (!$found) { |
|
$contraente["codice_operatore"] = $oe["codice"]; |
|
$contraente["cf"] = $oe["codice_fiscale_impresa"]; |
|
$contraente["denominazione"] = $oe["ragione_sociale"]; |
|
$contraente["extraInfo"]["pec"] = $oe["pec"]; |
|
$contraente["ruolo"] = ""; |
|
$formInfo = FormManager::getInfoFromID("organizzazione-oe",$this->codice_gestore); |
|
if (!empty($formInfo)) { |
|
$formManager = new FormManager; |
|
$formManager->init($formInfo["codice"],"oe",$oe["codice"]); |
|
$data = $formManager->getValues(); |
|
if (!empty($data)) { |
|
$rappresentante = reset($data); |
|
foreach($rappresentante AS $data) { |
|
$infoRappresentante = $formManager->getInputInfo($data["codice"]); |
|
switch($infoRappresentante["input"]["id"]) { |
|
case "soggetto-nome": |
|
$contraente["extraInfo"]["nome"] = $data["value"]; |
|
break; |
|
case "soggetto-cognome": |
|
$contraente["extraInfo"]["cognome"] = $data["value"]; |
|
break; |
|
case "soggetto-codiceFiscale": |
|
$contraente["extraInfo"]["codiceFiscale"] = $data["value"]; |
|
break; |
|
case "soggetto-ruolo": |
|
$infoRappresentante["input"]["opzioni"] = json_decode($infoRappresentante["input"]["opzioni"],true); |
|
if (in_array("tipologieRappresentantiLegali.json",$infoRappresentante["input"]["opzioni"]) !== false) { |
|
$opzioni = jsonToArray($root."/backend/form/json/tipologieRappresentantiLegali.json"); |
|
$data["value"] = $opzioni[$data["value"]]["IT"] ?? $data["value"]; |
|
} |
|
$contraente["ruolo"] = $data["value"]; |
|
break; |
|
case "soggetto-nascita": |
|
$contraente["extraInfo"]["dataNascita"] = $data["value"]; |
|
break; |
|
case "soggetto-indirizzo": |
|
$indirizzo = json_decode($data["value"],true); |
|
$contraente["extraInfo"]["indirizzo"] = $indirizzo["indirizzo"]; |
|
$contraente["extraInfo"]["stato"] = $indirizzo["stato"]; |
|
$contraente["extraInfo"]["regione"] = $indirizzo["regione"]; |
|
$contraente["extraInfo"]["provincia"] = $indirizzo["provincia"]; |
|
$contraente["extraInfo"]["citta"] = $indirizzo["citta"]; |
|
$contraente["extraInfo"]["cap"] = $indirizzo["cap"]; |
|
break; |
|
default: |
|
break; |
|
} |
|
} |
|
} |
|
} |
|
$contraente["codice"] = $this->saveOE($contraente); |
|
if (!empty($contraente["codice"])) { |
|
return $contraente; |
|
} |
|
} |
|
} |
|
} |
|
} |
|
|
|
public function saveContraente($contraente,$tipo) { |
|
$contraente["extraInfo"] = json_encode($contraente["extraInfo"]); |
|
$contraente["tipologia"] = $tipo; |
|
$contraente["codice_gestore"] = $this->codice_gestore; |
|
$salva = new salva(); |
|
$salva->debug = false; |
|
|
|
$salva->nome_tabella = "b_contraenti"; |
|
$salva->operazione = (empty($contraente["codice"])) ? "INSERT" : "UPDATE"; |
|
$salva->oggetto = $contraente; |
|
$return = $salva->save(); |
|
if (!empty($return)) { |
|
$this->updateStato("10"); |
|
$check = $this->db->go("SELECT codice FROM r_contraenti WHERE codice_contratto = :contratto AND codice_contraente = :contraente",[":contratto"=>$this->info["codice"],":contraente"=>$return]); |
|
if ($check->rowCount() == 0) { |
|
$salva = new salva(); |
|
$salva->debug = false; |
|
|
|
$salva->nome_tabella = "r_contraenti"; |
|
$salva->operazione = "INSERT"; |
|
$salva->oggetto = ["codice_contratto"=>$this->info["codice"],"codice_contraente"=>$return]; |
|
$salva->save(); |
|
} |
|
return $return; |
|
} |
|
return false; |
|
} |
|
|
|
public function saveOE($contraente) { |
|
$contraente["codice_operatore"] = 0; |
|
if (!empty($contraente["extraInfo"]["pec"])) { |
|
$check = $this->db->go("SELECT codice FROM b_operatori_economici WHERE pec = :pec",[":pec"=>$contraente["extraInfo"]["pec"]]); |
|
if ($check->rowCount() === 1) { |
|
$contraente["codice_operatore"] = $check->fetch(PDO::FETCH_ASSOC)["codice"]; |
|
if (empty($contraente["codice"])) { |
|
$check = $this->db->go("SELECT codice FROM b_contraenti WHERE codice_operatore = :codice_operatore AND codice_gestore = :gestore", |
|
[":codice_operatore"=>$contraente["codice_operatore"],":gestore"=>$this->codice_gestore]); |
|
if ($check->rowCount() === 1) { $contraente["codice"] = $check->fetch(PDO::FETCH_ASSOC)["codice"]; } |
|
} |
|
} |
|
} |
|
return $this->saveContraente($contraente,"oe"); |
|
} |
|
|
|
public function getDestinatari() { |
|
$destinatari = $this->getOOEE() ?? []; |
|
$return = []; |
|
foreach($destinatari AS $tmp) { |
|
$return[] = $tmp["codice_operatore"]; |
|
} |
|
return $return; |
|
} |
|
|
|
public static function init($codice) { |
|
if (!empty($codice) && !empty($_SESSION["utente"]) && !empty($_SESSION["ente"])) { |
|
global $pdo; |
|
$bind = [":codice"=>$codice,":codice_gestore"=>$_SESSION["ente"]->codice]; |
|
$sql = "SELECT * FROM b_contratti WHERE codice = :codice AND codice_gestore = :codice_gestore"; |
|
if (!$_SESSION["utente"]->fromHere()) { |
|
$sql .= " AND codice_ente = :codice_ente"; |
|
$bind[":codice_ente"] = $_SESSION["utente"]->codice_ente; |
|
} |
|
$contratto = $pdo->go($sql,$bind)->fetch(PDO::FETCH_ASSOC); |
|
if (!empty($contratto)) { |
|
$continua = true; |
|
if ($_SESSION["utente"]->codice_ente != $contratto["codice_gestore"] && $_SESSION["utente"]->codice_ente != $contratto["codice_ente"] && $_SESSION["utente"]->gerarchia > 9) { |
|
$continua = false; |
|
} |
|
if ($continua) { |
|
$instance = new stipula(); |
|
$instance->info = $contratto; |
|
return $instance; |
|
} |
|
} |
|
} |
|
return false; |
|
} |
|
|
|
private static function defaultAutenticationLevel() { |
|
return $_SESSION["ente"]->defaultAutenticationLevel(); |
|
} |
|
|
|
public function checkLock($id_cmd) { |
|
$return = true; |
|
$stato = $this->info["stato"]; |
|
if ($_SESSION["utente"]->readOnly) { |
|
return true; |
|
} else { |
|
if ($_SESSION["utente"]->hasSuperPowers()) { |
|
$return = false; |
|
} else { |
|
if (($stato >= 0) && !empty($id_cmd) && $_SESSION["utente"]->unlockSupporto()) { |
|
$cmd = self::getInfoModulo($id_cmd); |
|
if ($cmd !== false) { |
|
$loa = $cmd["authenticationLevel"] ?? self::defaultAutenticationLevel(); |
|
if ($_SESSION["utente"]->authenticationLevel < $loa) { |
|
return true; |
|
} |
|
if (($stato >= $cmd["stato_minimo"] || $cmd["stato_minimo"] == null) && ($stato <= $cmd["stato_massimo"] || $cmd["stato_massimo"] === null)) { $return = false; } |
|
} |
|
} |
|
} |
|
} |
|
return $return; |
|
} |
|
|
|
public function getManagerRichieste() { |
|
$managerRichieste = new richiesteOE("contratti",$this->info["codice"]); |
|
if (!empty($managerRichieste)) { |
|
$this->managerRichieste = $managerRichieste; |
|
} |
|
return $this->managerRichieste; |
|
} |
|
|
|
public function getPartecipanti($codice = "",$ammessi = NULL) { |
|
$bind = [":codice_contratto"=>$this->info["codice"]]; |
|
$sql = "SELECT * FROM r_contraentii WHERE codice_contratto = :codice_contratto "; |
|
if (!empty($codice)) { |
|
$sql .= " AND codice = :codice_partecipante "; |
|
$bind[":codice_partecipante"] = $codice; |
|
} |
|
if ($ammessi === TRUE) { |
|
$sql .= " AND conferma = 'S' AND escluso = 'N' "; |
|
} else if ($ammessi != "ALL") { |
|
$sql .= " AND conferma = 'S' "; |
|
} |
|
return $this->db->go($sql,$bind)->fetchAll(PDO::FETCH_ASSOC); |
|
} |
|
|
|
static function getTipologie($filters=null) { |
|
$moduli = self::getModuli($filters); |
|
$tmp = []; |
|
foreach($moduli AS $modulo) { $tmp[] = $modulo["tipo"]; } |
|
$tmp = array_unique($tmp); |
|
if (!empty($tmp)) { |
|
$tipologie = []; |
|
global $config; |
|
$conf = jsonToArray($config["jsonFolder"]."/contratti-tipologie.json"); |
|
foreach($tmp AS $tipo) { |
|
$tipologie[$tipo] = $conf[$tipo]; |
|
} |
|
return $tipologie; |
|
} else { |
|
return false; |
|
} |
|
|
|
} |
|
|
|
public function getContrattoSottoscritto($content = false, $codice_firmatario = NULL, $first = false) { |
|
global $config; |
|
$select = "codice,codice_firmatario,extraInfo,name,mime,md5,sha1,sha256,utente_creazione,timestamp_creazione,utente_modifica,timestamp"; |
|
$where = ""; |
|
if ($content) { $select = "*"; } |
|
$bind = [":contratto"=>$this->info["codice"]]; |
|
if ($codice_firmatario !== NULL) { |
|
$where = " AND codice_firmatario = :firmatario "; |
|
$bind[":firmatario"] = $codice_firmatario; |
|
} |
|
$limit = ""; |
|
if ($first) { $limit = "LIMIT 0,1"; } |
|
|
|
$tmp = $this->db->go("SELECT {$select} FROM b_contratti_sottoscritti WHERE codice_contratto = :contratto {$where} ORDER BY codice {$limit}",$bind); |
|
$return = []; |
|
if ($tmp->rowCount() > 0) { |
|
while($con = $tmp->fetch(PDO::FETCH_ASSOC)) { |
|
if(! empty($con["content"])) { |
|
$path = "{$config["mediaFolder"]}/{$_SESSION["ente"]->codice}/contratti-signed/{$this->info["codice"]}/" . md5($con["content"]) . $con["sha1"]; |
|
if(file_exists($path)) { |
|
$content = file_get_contents($path); |
|
$content = @simple_decrypt($content, $con["content"]); |
|
if(! empty($content)) { |
|
$con["content"] = $content; |
|
$content = null; |
|
unset($content); |
|
gc_collect_cycles(); |
|
} |
|
} |
|
} |
|
$return[$con["codice_firmatario"]] = $con; |
|
} |
|
} |
|
if ($codice_firmatario !== NULL) { |
|
if (!empty($return[$codice_firmatario])) { |
|
$return = $return[$codice_firmatario]; |
|
} else { |
|
$return = []; |
|
} |
|
} |
|
return $return; |
|
} |
|
|
|
public function getCostiSegreteria() : array { |
|
if ($this->info["modalita"] == "atto_pubblico") return []; |
|
$dati = []; |
|
switch($this->info["riferimento_normativo"]) { |
|
case "2023-36": |
|
$totale = ((float) $this->info["importo_totale"]); |
|
$dati["imposta di bollo"] = 1000; |
|
if ($totale < 25000000) { |
|
$dati["imposta di bollo"] = 500; |
|
} |
|
if ($totale < 5000000) { |
|
$dati["imposta di bollo"] = 250; |
|
} |
|
if ($totale < 1000000) { |
|
$dati["imposta di bollo"] = 120; |
|
} |
|
if ($totale < 150000) { |
|
$dati["imposta di bollo"] = 40; |
|
} |
|
if ($totale < 40000) { |
|
$dati["imposta di bollo"] = 0; |
|
} |
|
$dati["imposta di registro"] = 200.00; |
|
$dati["totale"] = $dati["imposta di bollo"] + $dati["imposta di registro"]; |
|
break; |
|
case "2016-50": |
|
if (!empty($this->info["facciate"])) { |
|
$dati = [ |
|
"imposta di bollo" => 45.00, |
|
"imposta di registro" => 200.00, |
|
"costi aggiuntivi facciate in allegato" => 0.00, |
|
"totale" => 0.00 |
|
]; |
|
if (!empty($this->info["facciate"])) { |
|
$clamp = round_to_nearest_multiple((int) $this->info["facciate"] - 1 ,4) / 4; |
|
$dati["costi aggiuntivi facciate in allegato"] = (float) (($clamp + 1) * 16); |
|
} |
|
$totale = 0.00; |
|
foreach($dati as $titolo => $somma) { |
|
$totale += $somma; |
|
} |
|
$dati["totale"] = $totale; |
|
} |
|
|
|
break; |
|
} |
|
return $dati; |
|
} |
|
|
|
public function getFirstContratto($content=false) { |
|
return $this->getContrattoSottoscritto($content,0,true); |
|
} |
|
|
|
public function getLastContratto($content=false) { |
|
$bind = [":contratto"=>$this->info["codice"]]; |
|
$tmp = $this->db->go("SELECT codice_firmatario FROM b_contratti_sottoscritti WHERE codice_contratto = :contratto ORDER BY timestamp DESC LIMIT 0,1",$bind); |
|
if ($tmp->rowCount() === 1) { |
|
return $this->getContrattoSottoscritto($content,$tmp->fetch(PDO::FETCH_ASSOC)["codice_firmatario"]); |
|
} |
|
} |
|
|
|
public function getContrattoFinale($content=false) { |
|
if ($this->info["stato"] >= 30) { |
|
if (!empty($this->getExtraInfo()["sottoscritto"])) { |
|
return $this->getLastContratto($content); |
|
} |
|
} |
|
return false; |
|
} |
|
|
|
static function getModuli($filters=null,$stato = null) { |
|
global $config; |
|
$moduli = jsonToArray($config["jsonFolder"]."/contratti-panel.json"); |
|
|
|
if (isset($_SESSION["ente"]->erpConnector) && method_exists($_SESSION["ente"]->erpConnector,"extendStipula")) { |
|
$adds = $_SESSION["ente"]->erpConnector->extendStipula(); |
|
if (!empty($adds)) { |
|
foreach($adds AS $key => $info) { |
|
$moduli[$key] = $info; |
|
} |
|
} |
|
} |
|
$tmp = []; |
|
foreach($moduli AS $id_modulo => $modulo) { |
|
|
|
if (!empty($modulo['attivabile'])) { |
|
if (!$_SESSION['ente']->hasModulo($modulo['attivabile']['nome_modulo'])) { |
|
continue; |
|
} |
|
} |
|
|
|
$insert = true; |
|
if (is_array($filters) && !empty($filters)) { |
|
foreach($filters AS $key => $value) { |
|
if ($modulo[$key] !== $value) { $insert = false; } |
|
} |
|
} |
|
if ($insert && $stato !== null) { |
|
if ($modulo["stato_minimo"] > $stato) { $insert = false; } |
|
} |
|
if (is_array($modulo["stati_esclusi"]) && in_array($stato,$modulo["stati_esclusi"]) !== false) { $insert = false; } |
|
if ($insert) { $tmp[$id_modulo] = $modulo; } |
|
$moduli = $tmp; |
|
} |
|
return $moduli; |
|
} |
|
|
|
static function getInfoModulo($radice) { |
|
$return = false; |
|
if (!empty($radice)) { |
|
$moduli = self::getModuli(false); |
|
if (!empty($moduli[$radice])) { |
|
$return = $moduli[$radice]; |
|
$return["id"] = $radice; |
|
$return["titolo"] = __($return["titolo"]); |
|
$return["descrizione"] = __($return["descrizione"]); |
|
} |
|
} |
|
return $return; |
|
} |
|
|
|
static function getModalita() { |
|
$modalita = []; |
|
$modalita["atto_pubblico"] = ["titolo"=>"Atto pubblico notarile","invio_remoto"=>true,"ufficiale_rogante"=>true,"attivo"=>true]; |
|
$modalita["scrittura_pubblica"] = ["titolo"=>"Scrittura pubblica amministrativa","invio_remoto"=>false,"ufficiale_rogante"=>true,"attivo"=>true]; |
|
$modalita["scrittura_privata"] = ["titolo"=>"Scrittura privata","invio_remoto"=>true,"ufficiale_rogante"=>false,"attivo"=>true]; |
|
return $modalita; |
|
} |
|
|
|
protected function queryGetDocumentali() |
|
{ |
|
$bind = []; |
|
$sql = "SELECT b_contratti_richiesta_documentale.codice, |
|
b_contratti_richiesta_documentale.codice_classe_documentale, |
|
b_contratti_richiesta_documentale.codice_oe, |
|
b_contratti_richiesta_documentale.descrizione, |
|
b_contratti_richiesta_documentale.timestamp_creazione, |
|
b_contratti_richiesta_documentale.bozza, |
|
b_contratti_richiesta_documentale.soft_delete, |
|
r_contratto_richiesta.codice_contratto, |
|
r_contratto_richiesta.codice_richiesta, |
|
r_contratto_richiesta.bloccante |
|
FROM b_contratti_richiesta_documentale |
|
JOIN r_contratto_richiesta ON b_contratti_richiesta_documentale.codice = r_contratto_richiesta.codice_richiesta |
|
WHERE r_contratto_richiesta.codice_contratto = :codice_contratto |
|
AND b_contratti_richiesta_documentale.soft_delete = 'N' "; |
|
|
|
return $sql; |
|
} |
|
|
|
public function getDocumentali($filters = []) |
|
{ |
|
global $pdo; |
|
|
|
$bind = array(':codice_contratto' => $this->info['codice']); |
|
|
|
$sql = self::queryGetDocumentali($filters); |
|
|
|
if(!empty($filters['bozza'])){ |
|
$sql .= " AND b_contratti_richiesta_documentale.bozza = :bozza "; |
|
$bind[':bozza'] = $filters['bozza']; |
|
} |
|
|
|
|
|
if(!empty($_SESSION["utente"]->oe['codice'])){ |
|
$sql .= " AND b_contratti_richiesta_documentale.codice_oe = :codice_oe "; |
|
$bind[':codice_oe'] = $_SESSION["utente"]->oe['codice']; |
|
|
|
} |
|
|
|
return $pdo->go($sql, $bind); |
|
|
|
} |
|
|
|
// INSERIRE QUESTA FUNZIONE IN AGGIUNTA RISPOSTA DOCUMENTALE PER LE PER RISPOSTE IN ATTESA DI valutazione |
|
// E NEL CROWN JOB PER I DOCUMENTI SCADUTI |
|
public static function updateBadges($codice_contratto) |
|
{ |
|
global $pdo; |
|
|
|
if(!empty($codice_contratto)){ |
|
|
|
$badge = 0; |
|
|
|
$contratto = $pdo->prepare("SELECT b_contratti.codice, b_contratti.stato FROM b_contratti WHERE b_contratti.codice = :codice_contratto"); |
|
$contratto->bindValue(":codice_contratto", $codice_contratto); |
|
$contratto->execute(); |
|
$contratto = $contratto->fetch(PDO::FETCH_ASSOC); |
|
|
|
if(!empty($contratto)){ |
|
|
|
if ($contratto['stato'] === '25') { |
|
$badge = 1; |
|
} |
|
|
|
if ($_SESSION['ente']->hasModulo('contratti.documentale')) { |
|
$richieste = RichiestaDocumentale::getRichieste(['codice_contratto' => $codice_contratto]); |
|
|
|
$codiciClassiDocumentali = pluck('codice_classe_documentale', $richieste); |
|
|
|
$classiDocumentali = ContrattoDocumentale::getAllDocumentali(['codici' => $codiciClassiDocumentali]); |
|
|
|
foreach ($classiDocumentali as $key => $classeDocumentale) { |
|
if ($classeDocumentale['soggetto'] != '5') { |
|
$classiDocumentali[$key]['ruoli'] = ContrattoDocumentale::getRuoli($classeDocumentale['codice']); |
|
} |
|
} |
|
|
|
foreach ($richieste as $key => $richiesta) { |
|
foreach ($classiDocumentali as $key2 => $classeDocumentale) { |
|
if ($richiesta['codice_classe_documentale'] == $classeDocumentale['codice']) { |
|
$richieste[$key]['classe_documentale'] = $classeDocumentale; |
|
} |
|
} |
|
} |
|
|
|
foreach ($richieste as $key => $richiesta) { |
|
if ($richiesta['classe_documentale']['soggetto'] == '5') { |
|
|
|
$risposte = $pdo->prepare("SELECT codice, codice_richiesta, stato |
|
FROM b_contratti_risposta_documentale |
|
WHERE codice_richiesta = :codice_richiesta |
|
AND (stato = 10 OR stato = 30) |
|
AND b_contratti_risposta_documentale.codice IN ( |
|
SELECT MAX(codice) as codice |
|
FROM b_contratti_risposta_documentale |
|
GROUP BY codice_richiesta, codice_soggetto_oe |
|
)"); |
|
|
|
$risposte->bindValue(':codice_richiesta', $richiesta['codice']); |
|
|
|
$risposte->execute(); |
|
|
|
$badge += $risposte->rowCount() ?? null; |
|
|
|
}else{ |
|
|
|
|
|
$codiciRuoli = pluck('codice', $richiesta['classe_documentale']['ruoli']); |
|
$codiciRuoli = arrayIsNumeric($codiciRuoli); |
|
$codiciRuoli = implode(",", $codiciRuoli); |
|
|
|
if (!empty($codiciRuoli)) { |
|
$soggettiRuoli = $pdo->prepare("SELECT r_contratto_b_soggetto_oe.codice_soggetto_oe |
|
FROM r_contratto_b_soggetto_oe |
|
JOIN r_contratto_b_soggetto_oe_ruolo ON r_contratto_b_soggetto_oe.codice = r_contratto_b_soggetto_oe_ruolo.codice_r_contratto_b_soggetti_oe |
|
AND r_contratto_b_soggetto_oe.codice_contratto = :codice_contratto |
|
AND r_contratto_b_soggetto_oe_ruolo.codice_ruolo IN ($codiciRuoli) "); |
|
|
|
|
|
$soggettiRuoli->bindValue(':codice_contratto', $codice_contratto); |
|
$soggettiRuoli->execute(); |
|
$soggettiRuoli = $soggettiRuoli->fetchAll(PDO::FETCH_COLUMN); |
|
|
|
|
|
if(!empty($soggettiRuoli)){ |
|
|
|
$soggettiRuoli = implode(',', array_unique($soggettiRuoli)); |
|
|
|
$risposte = $pdo->prepare("SELECT codice, codice_richiesta, stato, codice_soggetto_oe |
|
FROM b_contratti_risposta_documentale |
|
WHERE codice_richiesta = :codice_richiesta |
|
AND codice_soggetto_oe IN ($soggettiRuoli) |
|
AND (b_contratti_risposta_documentale.stato = 10 OR b_contratti_risposta_documentale.stato = 30) |
|
AND b_contratti_risposta_documentale.codice IN ( |
|
SELECT MAX(codice) as codice |
|
FROM b_contratti_risposta_documentale |
|
GROUP BY codice_richiesta, codice_soggetto_oe |
|
)"); |
|
|
|
|
|
$risposte->bindValue(':codice_richiesta', $richiesta['codice']); |
|
$risposte->execute(); |
|
|
|
$badge += $risposte->rowCount(); |
|
} |
|
} |
|
} |
|
} |
|
} |
|
|
|
$pdo->go("UPDATE b_contratti set badge = :badge WHERE codice = :codice_contratto", [':badge' => $badge, "codice_contratto" => $codice_contratto]); |
|
} |
|
} |
|
} |
|
|
|
public static function getCountBadge() |
|
{ |
|
global $pdo; |
|
|
|
$badge = 0; |
|
|
|
$bind_bad = []; |
|
|
|
$sql_bad = "SELECT SUM(b_contratti.badge) AS totale |
|
FROM b_contratti |
|
WHERE b_contratti.codice_gestore = :codice_gestore "; |
|
$bind_bad[":codice_gestore"] = $_SESSION['ente']->codice; |
|
|
|
|
|
if ($_SESSION["utente"]->gerarchia > 10) { |
|
$ids = Utente::getPermissionsInModulo($_SESSION["ente"]->codice,$_SESSION["utente"]->codice,"contratti"); |
|
$ids = implode(",",$ids); |
|
$sql_bad .= " AND b_contratti.codice IN ({$ids}) "; |
|
} |
|
|
|
if (!$_SESSION["utente"]->fromHere()) { |
|
$sql_bad .= " AND codice_ente = :codice_ente"; |
|
$bind_bad[":codice_ente"] = $_SESSION["utente"]->codice_ente; |
|
} |
|
|
|
$ris_badge = $pdo->go($sql_bad, $bind_bad); |
|
$badge += $ris_badge->fetch(PDO::FETCH_COLUMN); |
|
|
|
return $badge; |
|
} |
|
|
|
public function getSoggetti($soggetto = null, $ruoli = [], $codice_oe = null, $filters = []) |
|
{ |
|
|
|
global $pdo; |
|
|
|
if (!empty($soggetto)) { |
|
|
|
$bind[':codice_contratto'] = $this->info['codice']; |
|
|
|
$sql = "SELECT r_contratto_b_soggetto_oe.*, r_contratto_b_soggetto_oe_ruolo.codice_ruolo |
|
FROM r_contratto_b_soggetto_oe |
|
JOIN r_contratto_b_soggetto_oe_ruolo ON r_contratto_b_soggetto_oe.codice = r_contratto_b_soggetto_oe_ruolo.codice_r_contratto_b_soggetti_oe |
|
WHERE r_contratto_b_soggetto_oe.codice_contratto = :codice_contratto "; |
|
|
|
if (!empty($_SESSION["utente"]->oe['codice'])) { |
|
$bind[':codice_oe'] = $_SESSION["utente"]->oe['codice']; |
|
$sql .= " AND r_contratto_b_soggetto_oe.codice_oe = :codice_oe "; |
|
}elseif(!empty($codice_oe)){ |
|
$sql .= " AND r_contratto_b_soggetto_oe.codice_oe = :codice_oe "; |
|
$bind[':codice_oe'] = $codice_oe; |
|
} |
|
|
|
if(!empty($ruoli)){ |
|
$ruoli = implode(",", array_unique(pluck('codice', $ruoli))) ?? []; |
|
$sql .= " AND r_contratto_b_soggetto_oe_ruolo.codice_ruolo IN ($ruoli)"; |
|
} |
|
|
|
$ris = $pdo->go($sql, $bind); |
|
|
|
if ($ris->rowCount() > 0) { |
|
$relazioni = $ris->fetchAll(PDO::FETCH_ASSOC); |
|
|
|
$codici_soggetti_oe = implode(",", array_unique(pluck('codice_soggetto_oe', $relazioni))) ?? []; |
|
|
|
// GET SOGGETTI |
|
$bind[':soggetto'] = $soggetto; |
|
$sql = "SELECT * |
|
FROM b_soggetti_oe |
|
WHERE codice IN ($codici_soggetti_oe) |
|
AND soggetto = :soggetto |
|
AND soft_delete = 'N' "; |
|
|
|
$ris = $pdo->go($sql, $bind); |
|
$soggetti_oe = $ris->fetchAll(PDO::FETCH_ASSOC) ?? []; |
|
|
|
// GET RUOLI |
|
$codici_ruolo = implode(",", array_unique(pluck('codice_ruolo', $relazioni))) ?? []; |
|
$sql = "SELECT * |
|
FROM b_ruoli_documentale |
|
WHERE codice IN ($codici_ruolo) |
|
AND soft_delete = 'N' "; |
|
|
|
|
|
$ris = $pdo->go($sql); |
|
$ruoli = $ris->fetchAll(PDO::FETCH_ASSOC); |
|
|
|
if (!empty($soggetti_oe)) { |
|
// CREAZIONE MATRICE CONTENENTE I CODICI DEI RUOLI PER OGNI SOGGETTO_OE |
|
foreach ($soggetti_oe as $key => $soggetto) { |
|
foreach ($relazioni as $relazione) { |
|
if ($soggetto['codice'] == $relazione['codice_soggetto_oe']) { |
|
$soggetti_oe[$key]['ruoli'][] = $relazione['codice_ruolo']; |
|
} |
|
} |
|
} |
|
|
|
// ASSOCIAZIONE DEI RUOLI AI SOGGETTI |
|
if (!empty($ruoli)) { |
|
foreach ($soggetti_oe as $key => $soggetto) { |
|
if (!empty($soggetto['ruoli'])) { |
|
foreach ($soggetto['ruoli'] as $key2 => $keyRuolo) { |
|
foreach ($ruoli as $ruolo) { |
|
if ($keyRuolo == $ruolo['codice']) { |
|
$soggetti_oe[$key]['ruoli'][$key2] = $ruolo['ruolo']; |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
|
|
return $soggetti_oe; |
|
} |
|
} |
|
} |
|
return []; |
|
} |
|
|
|
/** |
|
* Questa funzione può essere utilizzata per avere i dati di una richiesta |
|
*/ |
|
public function getRichiesta($codice_richiesta) |
|
{ |
|
global $pdo; |
|
|
|
if (!empty($codice_richiesta)) { |
|
$bind = [ |
|
':codice' => $codice_richiesta, |
|
':codice_contratto' => $this->info['codice'], |
|
]; |
|
|
|
$sql = self::queryGetDocumentali(); |
|
$sql.= " AND b_contratti_richiesta_documentale.codice = :codice"; |
|
$ris = $pdo->go($sql, $bind); |
|
|
|
if ($ris->rowCount() > 0) { |
|
$result = $ris->fetch(PDO::FETCH_ASSOC); |
|
return $result; |
|
} |
|
} |
|
|
|
return []; |
|
} |
|
}
|
|
|