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.
523 righe
17 KiB
523 righe
17 KiB
<?php |
|
|
|
require_once ROOT . "lib/classes/IDataClass.php"; |
|
|
|
/** |
|
* Description of UTENTI |
|
* @author Gigi |
|
*/ |
|
class Domanda extends DataClass { |
|
|
|
const TABLE_NAME = "DOMANDA"; |
|
const SEQ_NAME = "DOMANDA_ID_SEQ"; |
|
|
|
public $ID = 0; |
|
public $ID_ACCOUNT = 0; |
|
public $DATA_REGISTRAZIONE = null; |
|
public $IBAN = ''; |
|
public $ISTITUTO_CREDITO = ''; |
|
public $FILIALE_CREDITO = ''; |
|
public $ISEE = 0; |
|
public $DATA_RILASCIO_ISEE = null; |
|
public $STATO = 0; |
|
public $NOTE = ''; |
|
public $dichiarazioni = array(); |
|
public $allegati = array(); |
|
public $richieste_sconti = array(); |
|
// public $richieste_sconti_erogati = array(); |
|
|
|
public function __construct($src = null) { |
|
global $con; |
|
if ($src == null) { |
|
return; |
|
} |
|
$stripSlashes = false; |
|
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(); |
|
} |
|
} |
|
$this->loadDati(); |
|
} |
|
|
|
public static function Count($filter = null) { |
|
return parent::_count(self::TABLE_NAME, $filter); |
|
} |
|
|
|
/* protocollo locale */ |
|
|
|
public function generaProtocollo() { |
|
return date('Ym') . str_pad($this->ID, 6, '0', STR_PAD_LEFT); |
|
} |
|
|
|
/* identificativo locale */ |
|
|
|
public function generaIdentificativo() { |
|
return "D" . Date::dateOracleTimeStamp($this->DATA_REGISTRAZIONE, 'Ym') . str_pad($this->ID, 6, '0', STR_PAD_LEFT); |
|
} |
|
|
|
public function loadDati() { |
|
$this->dichiarazioni = DomandaDichiarazioni::AllFromDomanda($this->ID); |
|
$this->allegati = Allegati::ListByDomanda($this->ID); |
|
$this->richieste_sconti = DomandaSconti::load($this->ID, 999); |
|
// $this->richieste_sconti_erogati = DomandaSconti::load($this->ID, RS_PRESA_IN_CARICO); |
|
} |
|
|
|
/* OBBLIGA LA GENERAZIONE DEL PDF IN CASO DI MODIFICA */ |
|
|
|
public function ResetPdfGenerato() { |
|
if ($this->ID > 0 && $this->STATO == STATO_DOMANDA_IN_PREPARAZIONE) { |
|
$this->ALLEGATO_GENERATO = null; |
|
$this->DATA_ALLEGATO = null; |
|
} |
|
} |
|
|
|
/* |
|
* Verifica completamento domanda per generazione pdf |
|
*/ |
|
|
|
public function CanGenPdf() { |
|
return Allegati::checkDocumentiObbligatoriCompletati(); |
|
} |
|
|
|
public function CountDocObbligatori() { |
|
return Allegati::checkDocumentiObbligatoriCompletati(false, true); |
|
} |
|
|
|
public function CountDocObbligatoriAllegati() { |
|
return Allegati::checkDocumentiObbligatoriCompletati(false, false, true); |
|
} |
|
|
|
/* |
|
* Verifica completamento domanda |
|
*/ |
|
|
|
public function CheckCompletata() { |
|
return Allegati::checkAllegatiObbligatoriCompletatiPreInvio(); |
|
} |
|
|
|
public function AllegatoGenerato() { |
|
return ( $this->ALLEGATO_GENERATO != null && $this->ALLEGATO_GENERATO != '' ? true : false); |
|
} |
|
|
|
/** |
|
* Load Domanda From CF Account with all dependencies |
|
* @params => $codiceFiscale |
|
* @return => Domanda (Object) |
|
*/ |
|
public static function loadDomandaFromAccount() { |
|
global $con, $LoggedAccount; |
|
$domanda = new Domanda(); |
|
$sql = "SELECT * FROM DOMANDA WHERE ID_ACCOUNT = :id_account"; |
|
$query = $con->prepare($sql); |
|
$query->bindParam(":id_account", $LoggedAccount->ID); |
|
try { |
|
$query->execute(); |
|
$row = $query->fetch(PDO::FETCH_ASSOC); |
|
if (isset($row['ID']) && $row['ID'] > 0) { |
|
$domanda->_loadByRow($row); |
|
$domanda->loadDati(); |
|
} |
|
} catch (Exception $exc) { |
|
$exc->getMessage(); |
|
} |
|
|
|
return $domanda; |
|
} |
|
|
|
public static function selectFromAccount() { |
|
global $con, $LoggedAccount; |
|
$return = array(); |
|
if ($LoggedAccount->ID > 0) { |
|
$verify = $con->prepare("SELECT * FROM " . self::TABLE_NAME . " WHERE ID_ACCOUNT=:id_account AND STATO < 6 ORDER BY ID ASC"); |
|
$verify->bindParam(":id_account", $LoggedAccount->ID); |
|
try { |
|
$verify->execute(); |
|
$return = $verify->fetchAll(PDO::FETCH_ASSOC); |
|
} catch (Exception $exc) { |
|
$return['esito'] = -999; |
|
$return['erroreDescrizione'] = $exc->getMessage(); |
|
} |
|
} |
|
return $return; |
|
} |
|
|
|
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); |
|
} |
|
|
|
/** |
|
* Funzione di verifica dei dati POST prima del salvataggio |
|
*/ |
|
public static function checkVerificaDatiPreSalvataggio() { |
|
global $LoggedAccount; |
|
|
|
$_POST['ID_ACCOUNT'] = $LoggedAccount->ID; |
|
$_POST['ISTITUTO_CREDITO'] = Utils::get_filter_string_POST('ISTITUTO_CREDITO'); |
|
$_POST['FILIALE_CREDITO'] = Utils::get_filter_string_POST('FILIALE_CREDITO'); |
|
$_POST['IBAN'] = Utils::get_filter_string_POST('IBAN'); |
|
$_POST['RIPETI_IBAN'] = Utils::get_filter_string_POST('RIPETI_IBAN'); |
|
$_POST["DATA_REGISTRAZIONE"] = date('d-M-Y h.i.s.u A'); |
|
// $_POST["ISEE"] = (strtolower($_POST['ISEE']) == 'on' ? 1 : 0); |
|
// $_POST['DATA_RILASCIO_ISEE'] = Utils::get_filter_string_POST('DATA_RILASCIO_ISEE'); |
|
} |
|
|
|
public function checkDatiPreSave() { |
|
global $LoggedAccount; |
|
$response = array(); |
|
|
|
$controllValidita = true; |
|
$dati_mancanti = ''; |
|
|
|
/* CONTROLLO I DATI OBBLIGATORI DELLE DICHIARAZIONI */ |
|
$anag_dic = AnagraficaDichiarazioni::getObblGruopByCodice(); |
|
$arrayDicDb = array(); |
|
foreach ($anag_dic as $k => $v) { |
|
$arrayDicDb[$k] = 0; |
|
} |
|
|
|
$count_dic_da_salvare = AnagraficaDichiarazioni::Count(' OBBLIGO = 1 GROUP BY CODICE'); |
|
|
|
$count_dic_salvate = 0; |
|
foreach ($this->dichiarazioni as $k => $s) { |
|
$arrayDicDb[$s] = 1; |
|
$count_dic_salvate++; |
|
} |
|
|
|
if ($count_dic_da_salvare > $count_dic_salvate) { |
|
|
|
$txtpunti = ""; |
|
$i = 0; |
|
foreach ($arrayDicDb as $k => $v) { |
|
if ($v == 0) { |
|
$i++; |
|
$txtpunti .= ( $i > 1 ? ', ' . $k : $k); |
|
} |
|
} |
|
$controllValidita = false; |
|
$dati_mancanti .= "Selezionare i seguenti punti: <b>$txtpunti</b> "; |
|
} |
|
if ($this->ISTITUTO_CREDITO == "") { |
|
$controllValidita = false; |
|
$dati_mancanti .= " <br><b>L'istituto di credito</b> "; |
|
} |
|
if ($this->FILIALE_CREDITO == "") { |
|
$controllValidita = false; |
|
$dati_mancanti .= " <br><b>La filiale dell'istituto di credito</b> "; |
|
} |
|
if ($this->IBAN == "") { |
|
$controllValidita = false; |
|
$dati_mancanti .= " <br><b>Il codice IBAN</b> "; |
|
} |
|
|
|
if (!Utils::inizia_con($this->IBAN, 'IT') && SOLO_IBAN_ITALIANI) { |
|
$controllValidita = false; |
|
$dati_mancanti .= " <br><b>Si accettano solo IBAN di banche italiane</b>"; |
|
} |
|
|
|
// if (strlen($this->IBAN) > LUNGHEZZA_IBAN) { |
|
// $controllValidita = false; |
|
// $dati_mancanti .= " <br><b>La lunghezza del codice IBAN deve essere di massimo (".LUNGHEZZA_IBAN.") caratteri</b> "; |
|
// } |
|
// if (strlen($this->IBAN) < LUNGHEZZA_IBAN) { |
|
// $controllValidita = false; |
|
// $dati_mancanti .= " <br><b>La lunghezza del codice IBAN deve essere di minimo (".LUNGHEZZA_IBAN.") caratteri</b> "; |
|
// } |
|
|
|
if (isset($_POST['RIPETI_IBAN']) && ($_POST['RIPETI_IBAN'] == "" || ($_POST['RIPETI_IBAN'] != $this->IBAN))) { |
|
$controllValidita = false; |
|
$dati_mancanti .= " <br><b>Campo Iban errato o non corrispondente</b>"; |
|
} |
|
|
|
// if (SOLO_IBAN_ITALIANI && !Utils::checkIban($this->IBAN)) { |
|
// $controllValidita = false; |
|
// $dati_mancanti .= " <br><b>Il codice IBAN non è valido</b>"; |
|
// } |
|
if (!Utils::isValidIBAN($this->IBAN)) { |
|
$controllValidita = false; |
|
$dati_mancanti .= " <br><b>Il codice IBAN non è valido</b>"; |
|
} |
|
$this->IBAN = strtoupper(str_replace(' ', '', $this->IBAN)); |
|
|
|
// if($this->DATA_RILASCIO_ISEE == ''){ |
|
// $controllValidita = false; |
|
// $dati_mancanti .= " <br><b>La data del rilascio ISEE</b>"; |
|
// }else { |
|
// $this->DATA_RILASCIO_ISEE = Date::dateOracleDate($this->DATA_RILASCIO_ISEE, 'd-m-Y') ; |
|
// $checkRilascio = Date::checkSaveDate(MIN_DATA_RILASCIO_ISEE_PHP, $this->DATA_RILASCIO_ISEE, "", true); |
|
// if ($checkRilascio['esito'] != 1) { |
|
// $controllValidita = false; |
|
// $dati_mancanti .= " <br><b>Data rilascio ISEE</b>"; |
|
// } |
|
// } |
|
// $this->DATA_RILASCIO_ISEE = (trim($this->DATA_RILASCIO_ISEE) != '' ? Date::dateOracleDate($this->DATA_RILASCIO_ISEE, 'd-M-y') : '') ; |
|
$response['checkDati'] = $controllValidita; |
|
$response['txt_dati_mancanti'] = $dati_mancanti; |
|
|
|
return $response; |
|
} |
|
|
|
public function presentaDomanda() { |
|
global $LoggedAccount; |
|
$response = Utils::initDefaultResponse(); |
|
if ($LoggedAccount->ID == $this->ID_ACCOUNT && $this->STATO == INPREPARAZIONE) { |
|
$this->STATO = PREPARATA; |
|
$this->DATA_PRESENTAZIONE = date(FORMAT_TIMESTAMP_ORACLE); |
|
$response = $this->Save(); |
|
} |
|
return $response; |
|
} |
|
|
|
public function riapriDomanda() { |
|
global $LoggedAccount; |
|
$response = Utils::initDefaultResponse(); |
|
if ($LoggedAccount->ID == $this->ID_ACCOUNT && $this->STATO == PREPARATA) { |
|
$this->STATO = INPREPARAZIONE; |
|
$this->DATA_PRESENTAZIONE = null; |
|
$response = $this->Save(); |
|
} |
|
return $response; |
|
} |
|
|
|
/* |
|
* Modificare ogni qual volta si fa un update o insert |
|
*/ |
|
|
|
public function Save() { |
|
global $con, $LoggedAccount; |
|
$vars = get_object_vars($this); |
|
unset($vars['dichiarazioni']); |
|
unset($vars['allegati']); |
|
unset($vars['documenti']); |
|
unset($vars['richieste_sconti']); |
|
// unset($vars['richieste_sconti_erogati']); |
|
unset($vars['DATA_REGISTRAZIONE']); |
|
$sql = Utils::prepareQuery(self::TABLE_NAME, $vars); |
|
//echo $sql; |
|
$queryabi = $con->prepare($sql); |
|
foreach ($vars as $k => $v) { |
|
if ($k == "ID" && $v == 0) { |
|
continue; |
|
} |
|
// echo "<br>:" . $k. " => ". $v; |
|
$queryabi->bindValue(":" . $k, $v); |
|
} |
|
try { |
|
$it = parent::_Save($queryabi); |
|
} catch (Exception $exc) { |
|
$it['erroreDescrizione'] = $exc->getMessage(); |
|
} |
|
return $it; |
|
} |
|
|
|
public function statoDomandaCompletata() { |
|
global $con, $LoggedAccount; |
|
$risultato = array(); |
|
$sql = "SELECT * FROM " . self::TABLE_NAME . " WHERE ID_ACCOUNT=:id AND STATO=1"; |
|
$query = $con->prepare($sql); |
|
$query->bindParam(":id", $LoggedAccount->ID); |
|
try { |
|
$query->execute(); |
|
$it = $query->fetchAll(PDO::FETCH_ASSOC); |
|
$risultato['esito'] = 1; |
|
$risultato['dati'] = $it; |
|
} catch (Exception $exc) { |
|
$risultato['esito'] = -999; |
|
$risultato['erroreDescrizione'] = $exc->getMessage(); |
|
} |
|
return $risultato; |
|
} |
|
|
|
/** |
|
* Setta lo stato della domanda a chiusa |
|
* @global type $con |
|
* @return type |
|
*/ |
|
public function setDomandaChiusa() { |
|
global $con; |
|
$risultato = array(); |
|
$sql = "UPDATE " . self::TABLE_NAME . " SET STATO=5 WHERE ID=:id"; |
|
$query = $con->prepare($sql); |
|
$query->bindParam(":id", $this->ID); |
|
try { |
|
$query->execute(); |
|
$risultato['esito'] = 1; |
|
} catch (Exception $exc) { |
|
$risultato['esito'] = -999; |
|
$risultato['erroreDescrizione'] = $exc->getMessage(); |
|
} |
|
return $risultato; |
|
} |
|
|
|
public function Delete() { |
|
return parent::_Delete(self::TABLE_NAME, "ID = " . $this->ID); |
|
} |
|
|
|
/** |
|
* Funzione per la visualizzazione dei logs |
|
* @param type $record |
|
* @param type $campo |
|
*/ |
|
public function Parse(&$record, $campo = "") { |
|
array_push($record, array("Campo" => $campo, "Valore" => $this->$campo)); |
|
} |
|
|
|
public function generateDirForUpload($basePath = ROOT_UPLOAD, $destinationPath = '') { |
|
$path = ''; |
|
if ($basePath != "") { |
|
//$path = $basePath . $this->ID_ACCOUNT; |
|
$path = File::getFolderFromDomanda($this, ROOT_UPLOAD_PRESENTAZIONE); |
|
File::createPath($path); |
|
if (is_dir($path) && !empty($destinationPath)) { |
|
$path .= "/" . $destinationPath; |
|
File::createPath($path); |
|
} else { |
|
$path = ''; |
|
} |
|
if (!is_dir($path)) { |
|
$path = ''; |
|
} |
|
} |
|
return $path; |
|
} |
|
} |
|
|
|
class DomandaDichiarazioni extends DataClass { |
|
|
|
const TABLE_NAME = "DOMANDA_DICHIARAZIONI"; |
|
const SP_ = "SPDICHIARAZIONISAVE"; |
|
|
|
public $ID_DOMANDA = 0; //FK |
|
public $ID_ANAG_DICHIARAZIONI = 0; |
|
|
|
public function __construct($src = null) { |
|
global $con; |
|
if ($src == null) |
|
return; |
|
if (is_array($src)) { |
|
$this->_loadByRow($src, $stripSlashes); |
|
} elseif (intval($src)) { |
|
$this->_loadById($src, self::TABLE_NAME, true); |
|
} |
|
} |
|
|
|
public static function Count($filter = null) { |
|
return parent::_count(self::TABLE_NAME, $filter); |
|
} |
|
|
|
/** |
|
* Load titoli di studio |
|
* |
|
* * return |
|
* For $id => array of DomandaTitoliStudio, for other array of array of DomandaTitoliStudio |
|
* |
|
* * params: |
|
* $id (int): load single rows from id |
|
* $id_anag_titolo (int): filter from id_anag_titolo |
|
*/ |
|
public static function load($id_domanda = 0, $id_anag_dichiarazione = 0) { |
|
global $con; |
|
|
|
if ($id_domanda <= 0) { |
|
return array(); |
|
} |
|
|
|
$rows = array(); |
|
|
|
$select = ($onlyCount ? " COUNT(ID_DOMANDA) AS TOT " : " * "); |
|
$filter = ""; |
|
|
|
if (!empty($id_domanda)) { |
|
$filter .= ($filter != "" ? " AND " : "") . " ID_DOMANDA = :id_domanda "; |
|
} |
|
if (!empty($id_anag_dichiarazione)) { |
|
$filter .= ($filter != "" ? " AND " : "") . " ID_ANAG_DICHIARAZIONE = :id_anag_dichiarazione "; |
|
} |
|
|
|
$filter = ($filter != "" ? " WHERE " : "") . $filter; |
|
$sql = "SELECT " . $select . " FROM " . self::TABLE_NAME . $filter; |
|
$query = $con->prepare($sql); |
|
|
|
if (!empty($id_domanda)) { |
|
$query->bindParam(":id_domanda", $id_domanda); |
|
} |
|
if (!empty($id_anag_dichiarazione)) { |
|
$query->bindParam(":id_anag_dichiarazione", $id_anag_dichiarazione); |
|
} |
|
|
|
try { |
|
$query->execute(); |
|
$rows = $query->fetchAll(PDO::FETCH_ASSOC); |
|
} catch (Exception $exc) { |
|
echo $exc->getMessage(); |
|
} |
|
return $rows; |
|
} |
|
|
|
public static function AllFromDomanda($id_domanda = 0, $onlyDomanda = false) { |
|
global $con; |
|
$rows = array(); |
|
$filter = " T.CANCELLATO = 0 "; |
|
$order = " ORDER BY T.POSIZIONE, T.CODICE"; |
|
|
|
if (!empty($id_domanda) && $onlyDomanda) { |
|
$filter .= ($filter != "" ? " AND " : "") . " D.ID_DOMANDA = :id_domanda "; |
|
} |
|
|
|
$filter = ($filter != "" ? " WHERE " : "") . $filter; |
|
|
|
$sql = "SELECT T.ID AS ID_DICHIARAZIONE, T.DESCRIZIONE, T.CODICE, T.OBBLIGO, D.ID_DOMANDA, D.ID_ANAG_DICHIARAZIONI " |
|
. "FROM " . AnagraficaDichiarazioni::TABLE_NAME . " T LEFT JOIN " . self::TABLE_NAME . " D on D.ID_ANAG_DICHIARAZIONI = T.ID AND D.ID_DOMANDA = :id_domanda " |
|
. $filter . $order; |
|
|
|
$query = $con->prepare($sql); |
|
if (!empty($id_domanda)) { |
|
$query->bindParam(":id_domanda", $id_domanda); |
|
} |
|
|
|
try { |
|
$query->execute(); |
|
$rows = $query->fetchAll(PDO::FETCH_ASSOC); |
|
} catch (Exception $exc) { |
|
echo $exc->getMessage(); |
|
} |
|
return $rows; |
|
} |
|
|
|
public function Delete() { |
|
return parent::_Delete(self::TABLE_NAME, "ID_DOMANDA = " . $this->ID_DOMANDA); |
|
} |
|
|
|
public function Save() { |
|
global $con, $LoggedAccount; |
|
|
|
$sql = "CALL " . self::SP_ . " (?,?)"; |
|
|
|
$query = $con->prepare($sql); |
|
|
|
$query->bindParam(1, $this->ID_DOMANDA); |
|
$query->bindParam(2, $this->ID_ANAG_DICHIARAZIONI); |
|
try { |
|
if ($query->execute()) { |
|
$it['esito'] = 1; |
|
} |
|
} catch (Exception $exc) { |
|
$it['descrizioneErrore'] = $exc->getMessage(); |
|
} |
|
return $it; |
|
} |
|
}
|
|
|