getLotti($codice_lotto)[0] ?? NULL; } if (!empty($lotto["codice"])) { $continua = true; if ($this->info["smart_cig"] == "S") { $smart = true; $simogMethod = "consultaComunicazione"; } else { $smart = false; $simogMethod = "consultaGara"; } } else if ($operation == "create" && !empty($codice_ente) && !empty($anno) && isset($smart)) { $continua = true; if ($smart) { $simogMethod = ($smart) ? "consultaComunicazione" : "consultaGara"; } } if ($operation == "get") { $return = []; $return["method"] = $simogMethod; $return["data"] = []; $return["data"]["CIG"] = $lotto["cig"]; if (!$smart) { $return["data"]["schede"] = $this->version; } } else if (($operation == "put" || $operation == "create") && !empty($response)) { $availableDati = []; if (!$smart) { if ($operation != "create") { $response = $response->return; } if (!empty($response->success)) { if (!empty($lotto["codice"])) { $this->updateSimogLog($simogMethod,1,"",$lotto["codice"]); } $datiGara = $response->GaraXML->DatiGara; $datiScheda = $response->GaraXML->DatiScheda ?? NULL; $gara = $this->info; $gara["smart_cig"] = "N"; $gara["dati"] = json_decode(json_encode($datiGara->Gara),true); $gara["dati"]["importo"] = $gara["dati"]["IMPORTO_GARA"] ?? ""; $gara["oggetto"] = $datiGara->Gara->OGGETTO; if (!empty($datiScheda)) { if (!empty($datiScheda->DatiComuni)) { $gara["dati"]["cf_sua"] = $datiScheda->DatiComuni->CF_SA ?? ""; $gara["dati"]["denominazione_sua"] = $datiScheda->DatiComuni->DEN_SA ?? ""; } } } else if (!empty($response->error)) { $errors = $response->error; } else { $errors = __("Errore nella risposta"); } } else { $gara = []; $gara["smart_cig"] = "S"; $gara["lotto"] = []; $gara["lotto"]["cig"] = $response->cig; $gara["oggetto"] = $response->oggetto; $gara["cup"] = $response->cup; $gara["dati"] = json_decode(json_encode($response),true); $gara["dati"]["categorie_merc"] = $gara["dati"]["categorie_merc"]["categoria"]; if (!is_array($gara["dati"]["categorie_merc"])) { $gara["dati"]["categorie_merc"] = [$gara["dati"]["categorie_merc"]]; } $gara["lotto"]["importo"] = $response->importo; } if (!empty($gara)) { if ($operation == "create") { $gara["codice_gestore"] = $_SESSION["ente"]->codice; $gara["codice_ente"] = $codice_ente; $gara["anno_riferimento"] = $anno; } if (!empty($this->info["codice"])) { $gara["codice"] = $this->info["codice"]; } $esito = $this->saveGara($gara); $this->updateStato(10); if (!empty($datiGara->Gara->DATA_PERFEZIONAMENTO_BANDO)) { $this->updateStato(20); } if (!empty($esito["codice"])) { $updateInfo = []; $updateInfo["codice"] = $esito["codice"]; if (!$smart) { $updateInfo["cf_utente"] = $datiGara->Gara->CF_UTENTE; $updateInfo["id_gara"] = $datiGara->Gara->ID_GARA; $updateInfo["id_stazione_appaltante"] = $datiGara->Gara->ID_STAZIONE_APPALTANTE; } if (empty($this->info["data_invio_simog"])) { $updateInfo["data_invio_simog"] = date("d/m/Y H:i:s"); } $salva = new salva(); $salva->debug = false; $salva->nome_tabella = "b_simog"; $salva->operazione = "UPDATE"; $salva->oggetto = $updateInfo; $salva->save(); if (!$smart) { $datiLotto = $datiGara->Lotto; $lotti = $this->getLotti(); $updateLotto = []; $updateLotto["data_invio_simog"] = date("d/m/Y H:i:s"); foreach($lotti AS $tmp) { if ($tmp["cig"] == $datiLotto->CIG) { $updateLotto["codice"] = $tmp["codice"]; $updateLotto["data_invio_simog"] = mysql2datetime($tmp["data_invio_simog"]); } } $updateLotto["codice_simog"] = $this->info["codice"]; $updateLotto["cig"] = $datiLotto->CIG; if (!empty($datiLotto->CUPLOTTO->CODICICUP->CUP)) { $updateLotto["cup"] = $datiLotto->CUPLOTTO->CODICICUP->CUP; } $updateLotto["id_scelta_contraente"] = $datiLotto->ID_SCELTA_CONTRAENTE; $updateLotto["oggetto"] = $datiLotto->OGGETTO; $updateLotto["importo"] = $datiLotto->IMPORTO_LOTTO; $cpv = explode("-",$datiLotto->CPV); $cpv = rtrim($cpv[0],"0"); $updateLotto["cpv"][] = $cpv; $updateLotto["dati"] = json_decode(json_encode($datiLotto),true); $updateLotto["importo_attuazione_sicurezza"] = $datiLotto->IMPORTO_SA; $esitoLotto = $this->saveLotto($updateLotto,true); if (!empty($esitoLotto["codice"])) { $salva = new salva(); $salva->debug = false; $salva->nome_tabella = "b_simog_lotti"; $salva->operazione = "UPDATE"; $salva->oggetto = ["codice"=>$esitoLotto["codice"],"richiesto_simog"=>"S","data_invio_simog" => $updateLotto["data_invio_simog"]]; $salva->save(); if (!empty($datiGara->Requisito)) { $updateInfo = []; $updateInfo["codice"] = $this->info["codice"]; $updateInfo["dati"] = $this->getDati(); $updateInfo["dati"]["requisiti"] = []; $updateInfo["dati"] = json_encode($updateInfo["dati"]); $salva = new salva(); $salva->debug = false; $salva->nome_tabella = "b_simog"; $salva->operazione = "UPDATE"; $salva->oggetto = $updateInfo; $salva->save(); $requisiti = $datiGara->Requisito; if (!is_array($requisiti)) { $requisiti = [$requisiti]; } foreach($requisiti AS $requisito) { $requisito = json_decode(json_encode($requisito),true); $this->saveRequisito($requisito); } } if (!empty($datiScheda)) { if (!empty($datiScheda->Pubblicazione)) { $pubblicazione["codice"] = $this->info["codice"]; $pubblicazione["dati"] = json_decode(json_encode($datiScheda->Pubblicazione),true); $pubblicazione["dati"] = convertDate_FROMSIMOG($pubblicazione["dati"]); $pubblicazione["dati"]["dataPubblicazione"] = mysql2date(substr($datiLotto->DATA_PUBBLICAZIONE,0,10)); $this->savePubblica($pubblicazione); } if (!empty($datiScheda->SchedaCompleta)) { $cui = $this->getLastCUI($esitoLotto["codice"],true); $cuiUpdate = $datiScheda->SchedaCompleta->CUI; if ($cui != $cuiUpdate) { $this->saveCUI($esitoLotto["codice"],$cuiUpdate); } $cui = explode("-",$cui); $tipologieSchede = $this->listSchede(); $comuni = json_decode(json_encode($datiScheda->DatiComuni),true); $this->db->go("UPDATE b_simog_schede SET stato = 99 WHERE tipologia = 'comuni' AND codice_lotto = :lotto",[":lotto"=>$esitoLotto["codice"],":cui"=>$cui[1]]); $this->saveSchede($esitoLotto["codice"],[["json"=>$comuni]],"comuni",3); $appaltoType = anac::getAppaloType($updateLotto); $idSchedaAppalto = "appalto-".strtolower($appaltoType); $listaSchedeComplete = []; $listaSchedeComplete[$appaltoType] = $idSchedaAppalto; $listaSchedeComplete["DatiInizio"] = "inizio"; $listaSchedeComplete["DatiStipula"] = "stipula"; $listaSchedeComplete["DatiAvanzamenti"] = "avanzamenti"; $listaSchedeComplete["DatiConclusione"] = "conclusione"; $listaSchedeComplete["DatiCollaudo"] = "collaudo"; $listaSchedeComplete["DatiRitardi"] = "ritardi"; $listaSchedeComplete["DatiAccordi"] = "accordi"; $listaSchedeComplete["DatiSospensioni"] = "sospensione"; $listaSchedeComplete["DatiVarianti"] = "varianti"; $listaSchedeComplete["DatiSubappalti"] = "subappalti"; $correlate = []; $correlate[$appaltoType]["requisiti"] = "Requisiti"; $correlate[$appaltoType]["finanziamenti"] = "Finanziamenti"; $correlate[$appaltoType]["ausiliarie"] = "Ausiliarie"; $correlate[$appaltoType]["aggiudicatari"] = "Aggiudicatari"; $correlate[$appaltoType]["responsabili"] = "Incaricati"; $correlate["DatiInizio"]["pubblicita_esito"] = "PubblicazioneEsito"; $correlate["DatiInizio"]["responsabili"] = "Incaricati"; $correlate["DatiStipula"]["pubblicita_esito_adesione"] = "PubblicazioneEsito"; $correlate["DatiCollaudo"]["responsabili"] = "Incaricati"; $insert = []; foreach($listaSchedeComplete AS $idXML => $tipologia) { if (!empty($datiScheda->SchedaCompleta->$idXML)) { $schede = []; $nodo = $datiScheda->SchedaCompleta->$idXML; if (!empty($tipologieSchede[$tipologia]["XMLelement"])) { $xmlElement = $tipologieSchede[$tipologia]["XMLelement"]; $schede = $nodo->$xmlElement; } else { $schede = $nodo; } if (!empty($schede)) { $insert[$tipologia][] = $schede; } if (!empty($correlate[$idXML])) { foreach($correlate[$idXML] AS $subTipologia => $subXML) { if (!empty($nodo->$subXML)) { $schede = $nodo->$subXML ?? false; if (!empty($schede)) { $insert[$subTipologia][] = $schede; } } } } } } if (!empty($insert)) { foreach($insert AS $tipologia => $schede) { $this->db->go("UPDATE b_simog_schede SET stato = 99 WHERE tipologia = :tipologia AND codice_lotto = :lotto",[":tipologia"=>$tipologia,":lotto"=>$esitoLotto["codice"],":cui"=>$cui[1]]); if (!is_array($schede)) { $schede = [$schede]; } foreach($schede AS $tmpScheda) { if (!is_array($tmpScheda)) { $tmpScheda = [$tmpScheda]; } foreach($tmpScheda AS $scheda) { $scheda = json_decode(json_encode($scheda),true); $this->saveSchede($esitoLotto["codice"],[["json"=>convertDate_FROMSIMOG($scheda)]],$tipologia,3); } } } } } } } else if (!empty($esitoLotto["errori"])) { $errors = $esitoLotto["errori"]; } } } else if (!empty($esito["errori"])) { $errors = $esito["errori"]; } } if (!empty($errors)) { if (!empty($lotto["codice"])) { if (is_array($errors)) { $errors = implode("
",$errors); } $this->updateSimogLog($simogMethod,2,$errors,$lotto["codice"]); alertManager::printAlertBox($errors); } $return = ["errori"=>$errors]; } else { if (!empty($lotto["codice"])) { alertManager::printSuccessBox(__("Operazione effettuata con successo")); } $return = ["codice"=>$this->info["codice"]]; } } } ?>