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.
 
 
 

346 righe
11 KiB

<?php
require_once ROOT . "lib/classes/IDataClass.php";
class RichiestaIntegrazione extends DataClass {
const TABLE_NAME = "RICHIESTA_INTEGRAZIONE";
const SEQ_NAME = 'RICHIESTA_INTEGRAZIONE_ID_SEQ';
public $ID = 0;
public $ID_DOMANDA_SCONTI = 0;
public $DATA_RICHIESTA = null;
public $DESCRIZIONE_RICHIESTA = "";
public $NUMERO_PROTOCOLLO = "";
public $PROTOCOLLO_JSON = null;
public $DATA_PROTOCOLLO = null;
public $FILEPATH_PDF_PROTOCOLLATO = "";
public $DATA_INVIO_NOTIFICA = null;
public $SCADENZA = null;
public $FILEPATH_RISPOSTA = "";
public $DATA_CARICAMENTO = null;
public $STATO = "";
public $NOTE_OPERATORE = "";
public $NOTE_UTENTE = "";
public $DATA_VALIDAZIONE = null;
public $OPERATORE_VALIDAZIONE = "";
public $OPERATORE_RICHIESTA = 0;
public function __construct($src = null) {
global $con;
if ($src == null) {
return;
}
$stripSlashes = 0;
if (is_array($src)) {
if (isset($src['ID']) && $src['ID'] > 0) {
$this->_loadAndFillObject($src['ID'], self::TABLE_NAME, $src);
} else {
$this->_loadByRow($src, $stripSlashes);
}
} elseif (intval($src)) {
$sql = "SELECT * FROM " . self::TABLE_NAME . " WHERE ID = :id";
$query = $con->prepare($sql);
$query->bindParam(":id", $src);
try {
$query->execute();
$it = $query->fetchAll(PDO::FETCH_ASSOC);
Utils::FillObjectFromRow($this, $it[0]);
} catch (Exception $exc) {
$exc->getMessage();
}
}
}
public static function Count($filter = null) {
return parent::_count(self::TABLE_NAME, $filter);
}
public static function LoadDataTable($searchQuery = "", $searchArray = array(), $columnName = array(), $columnSortOrder = array(), $start = 0, $offset = 0) {
return parent::_loadDataTable(self::TABLE_NAME, $searchQuery, $searchArray, $columnName, $columnSortOrder, $start, $offset);
}
public static function load($id = 0, $stato = "") {
global $con, $LoggedAccount;
$rows = array();
if (intval($id) > 0) {
if (!empty($stato)) {
$filter = "AND STATO = :stato ";
} else {
$filter = "";
}
$sql = "SELECT * FROM " . self::TABLE_NAME . " WHERE ID=:id " . $filter . " ORDER BY ID ASC ";
$query = $con->prepare($sql);
$query->bindParam(":id", $id);
if (!empty($stato)) {
$query->bindParam(":stato", $stato);
}
try {
$query->execute();
$rows = $query->fetchAll(PDO::FETCH_ASSOC);
} catch (Exception $exc) {
$exc->getMessage();
}
}
return $rows;
}
public static function loadFromDomanda($id_domanda = 0, $stato = "") {
global $con, $LoggedAccount;
$rows = array();
if (intval($id_domanda) > 0) {
if (!empty($stato)) {
$filter = "AND STATO = :stato ";
} else {
$filter = "";
}
$sql = "SELECT * FROM " . self::TABLE_NAME . " WHERE ID_DOMANDA_SCONTI=:id " . $filter . " ORDER BY ID ASC ";
$query = $con->prepare($sql);
$query->bindParam(":id", $id_domanda);
if (!empty($stato)) {
$query->bindParam(":stato", $stato);
}
try {
$query->execute();
$rows = $query->fetchAll(PDO::FETCH_ASSOC);
} catch (Exception $exc) {
$exc->getMessage();
}
}
return $rows;
}
public function Save() {
global $con, $LoggedAccount;
$vars = get_object_vars($this);
unset($vars["DATA_RICHIESTA"]);
$sql = Utils::prepareQuery(self::TABLE_NAME, $vars);
/* Utils::print_array($sql);
Utils::print_array($vars); */
$queryabi = $con->prepare($sql);
foreach ($vars as $k => $v) {
if ($k == "ID" && $v == 0) {
continue;
}
$queryabi->bindValue(":" . $k, $v);
}
try {
$it = parent::_Save($queryabi);
if (trim($it['erroreCode']) == 'HY000') {
$it['erroreDescrizione'] = '<b>Richiesta già inserita!</b><br/> Non è possibile inviare una richiesta di integrazione per la stessa domanda di sconto.';
}
} catch (Exception $exc) {
$it['erroreDescrizione'] = $exc->getMessage();
}
return $it;
}
public function Parse(&$record, $campo = "") {
array_push($record, array("Campo" => $campo, "Valore" => $this->$campo));
}
public function calcolaScadenzaDaInvio(): void {
if (!empty($this->DATA_INVIO_NOTIFICA)) {
try {
$dataInvio = new DateTime($this->DATA_INVIO_NOTIFICA);
$dataInvio->modify('+30 days');
$this->SCADENZA = $dataInvio->format('d-M-y');
$this->DATA_INVIO_NOTIFICA = Date::dateOracleDate($this->DATA_INVIO_NOTIFICA, 'd-M-y');
} catch (Exception $e) {
// Gestione errore se la data è malformata
error_log("Errore nel calcolo della scadenza: " . $e->getMessage());
$this->SCADENZA = null;
}
} else {
// Nessuna data di invio => nessuna scadenza calcolabile
$this->SCADENZA = null;
}
}
public static function checkVerificaDatiPreSalvataggio() {
global $LoggedAccount;
$_POST['ID_INTEGRAZIONE'] = intval(Utils::get_filter_int_POST('ID_INTEGRAZIONE'));
$_POST['ID_DOMANDA_SCONTI'] = intval(Utils::get_filter_int_POST('ID_DOMANDA_SCONTI'));
$_POST['NOTE_UTENTE'] = Utils::get_filter_string_POST('NOTE_UTENTE');
}
public function checkDatiPreSave() {
global $LoggedAccount;
$response = array();
$controllValidita = true;
$dati_mancanti = '';
if (trim($this->NOTE_UTENTE) == '') {
$controllValidita = false;
$dati_mancanti .= " <br><b>Campo Note</b><br> ";
}
if (!Date::verifyMinorDate(DateTime::createFromFormat('d-M-y', $this->DATA_CARICAMENTO), DateTime::createFromFormat('d-M-y', $this->SCADENZA))) {
$controllValidita = false;
$dati_mancanti .= " <br><b>I termini per il caricamento dell'integrazione sono scaduti.</b><br> ";
}
$response['checkDati'] = $controllValidita;
$response['txt_dati_mancanti'] = $dati_mancanti;
return $response;
}
}
class IntegrazioniEmailQueue extends DataClass {
const TABLE_NAME = "INTEGRAZIONI_EMAIL_QUEUE";
const SEQ_NAME = 'SEQ_EMAIL_QUEUE';
public $ID = 0;
public $ID_RICHIESTA = 0;
public $DESTINATARIO = "";
public $OGGETTO = "";
public $CORPO = "";
public $STATO = 0; //-- 1 = INVIATA, 99 = ERRORE
public $TENTATIVI = 0;
public $ERRORE_MESSAGGIO = "";
public $DATA_INSERIMENTO = null;
public $DATA_INVIO = null;
public function __construct($src = null) {
global $con;
if ($src == null) {
return;
}
$stripSlashes = 0;
if (is_array($src)) {
if (isset($src['ID']) && $src['ID'] > 0) {
$this->_loadAndFillObject($src['ID'], self::TABLE_NAME, $src);
} else {
$this->_loadByRow($src, $stripSlashes);
}
} elseif (intval($src)) {
$sql = "SELECT * FROM " . self::TABLE_NAME . " WHERE ID = :id";
$query = $con->prepare($sql);
$query->bindParam(":id", $src);
try {
$query->execute();
$it = $query->fetchAll(PDO::FETCH_ASSOC);
Utils::FillObjectFromRow($this, $it[0]);
} catch (Exception $exc) {
$exc->getMessage();
}
}
}
public static function load($id = 0, $stato = "") {
global $con, $LoggedAccount;
$rows = array();
if (intval($id) > 0) {
if (!empty($stato)) {
$filter = "AND STATO = :stato ";
} else {
$filter = "";
}
$sql = "SELECT * FROM " . self::TABLE_NAME . " WHERE ID=:id " . $filter . " ORDER BY ID ASC ";
$query = $con->prepare($sql);
$query->bindParam(":id", $id);
if (!empty($stato)) {
$query->bindParam(":stato", $stato);
}
try {
$query->execute();
$rows = $query->fetchAll(PDO::FETCH_ASSOC);
} catch (Exception $exc) {
$exc->getMessage();
}
}
return $rows;
}
public static function loadQueue($stato = 0) {
global $con, $LoggedAccount;
$rows = array();
if (!empty($stato)) {
$filter = "AND STATO = :stato ";
} else {
$filter = "";
}
$sql = "SELECT * FROM " . self::TABLE_NAME . " WHERE ID > 0 " . $filter . " ORDER BY DATA_INSERIMENTO ASC ";
$query = $con->prepare($sql);
if (!empty($stato)) {
$query->bindParam(":stato", $stato);
}
try {
$query->execute();
$rows = $query->fetchAll(PDO::FETCH_ASSOC);
} catch (Exception $exc) {
$exc->getMessage();
}
return $rows;
}
public static function Count($filter = null) {
return parent::_count(self::TABLE_NAME, $filter);
}
public function Save() {
global $con, $LoggedAccount;
$vars = get_object_vars($this);
unset($vars["DATA_INSERIMENTO"]);
$sql = Utils::prepareQuery(self::TABLE_NAME, $vars);
/* Utils::print_array($sql);
Utils::print_array($vars); */
$queryabi = $con->prepare($sql);
foreach ($vars as $k => $v) {
if ($k == "ID" && $v == 0) {
continue;
}
$queryabi->bindValue(":" . $k, $v);
}
try {
$it = parent::_Save($queryabi);
if (trim($it['erroreCode']) == 'HY000') {
$it['erroreDescrizione'] = '<b>Richiesta già inserita!</b><br/> Non è possibile inviare una richiesta di integrazione per la stessa domanda di sconto.';
}
} catch (Exception $exc) {
$it['erroreDescrizione'] = $exc->getMessage();
}
return $it;
}
public function Parse(&$record, $campo = "") {
array_push($record, array("Campo" => $campo, "Valore" => $this->$campo));
}
public function processaCodaEmail() {
global $con, $LoggedAccount;
$rows = $this->loadQueue(0); // Stato 0 = In attesa di invio
foreach ($rows as $row) {
$emailQueue = new IntegrazioniEmailQueue($row['ID']);
$emailQueue->STATO = 1; // Imposta lo stato a "Inviata"
$emailQueue->DATA_INVIO = date(FORMAT_TIMESTAMP_ORACLE);
// Invia l'email (logica di invio email non implementata qui)
// ...
// Salva lo stato aggiornato
$emailQueue->Save();
}
}
}