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.
186 righe
7.3 KiB
186 righe
7.3 KiB
<? |
|
$configPath = substr(__DIR__,0,strpos(__DIR__,"/public_html"))."/config.php"; |
|
include_once($configPath); |
|
|
|
if (!empty($_SESSION["utente"]) && $_SESSION["utente"]->permission($radice)) { |
|
if (isset($_GET["draw"])) { |
|
|
|
$return = array(); |
|
$return["draw"] = (int)$_GET["draw"]; |
|
$return["recordsTotal"] = (int)0; |
|
$return["recordsFiltered"] = (int)0; |
|
|
|
$bind = array(":codice_gestore"=>$_SESSION["ente"]->codice); |
|
$sql = "SELECT b_contratti.codice, b_contratti.id, |
|
b_contratti.stato, |
|
b_contratti.importo_totale, |
|
b_contratti.oggetto, |
|
b_contratti.badge, |
|
b_contratti.data_stipula, |
|
b_contratti.data_inizio, |
|
b_contratti.data_fine |
|
|
|
FROM b_contratti |
|
WHERE b_contratti.codice_gestore = :codice_gestore "; |
|
|
|
if ($_SESSION["utente"]->gerarchia > 10) { |
|
$ids = Utente::getPermissionsInModulo($_SESSION["ente"]->codice,$_SESSION["utente"]->codice,"contratti"); |
|
$ids = implode(",",$ids); |
|
$sql .= " AND b_contratti.codice IN ({$ids}) "; |
|
} |
|
|
|
if (!$_SESSION["utente"]->fromHere()) { |
|
$sql .= " AND codice_ente = :codice_ente"; |
|
$bind[":codice_ente"] = $_SESSION["utente"]->codice_ente; |
|
} |
|
|
|
$risultati = $pdo->go($sql,$bind); |
|
if ($risultati->rowCount() > 0) { |
|
$return["recordsTotal"] = (int)$risultati->rowCount(); |
|
$filterApplied = false; |
|
if (!empty($_GET["search"]["value"])) { |
|
$filterApplied = true; |
|
$sql .= " AND ( "; |
|
|
|
$suddivisione = suddivisione_pdo($_GET["search"]["value"],"id"); |
|
$sql .= "(" . $suddivisione["sql"] . ") OR "; |
|
$bind = array_merge($bind,$suddivisione["bind"]); |
|
|
|
$suddivisione = suddivisione_pdo($_GET["search"]["value"],"oggetto"); |
|
$sql .= "(" . $suddivisione["sql"] . ") "; |
|
$bind = array_merge($bind,$suddivisione["bind"]); |
|
|
|
$sql .= ") "; |
|
} |
|
|
|
if (isset($_GET["stato"]) && $_GET["stato"]!=="") { |
|
$filterApplied = true; |
|
$bind[":status"] = $_GET["stato"]; |
|
$sql .= " AND b_contratti.stato = :status "; |
|
} |
|
|
|
$order = "b_contratti.id "; |
|
switch($_GET["order"][0]["column"]) { |
|
// case "2": $order = "b_contratti.badge "; break; |
|
case "3": $order = "b_contratti.id "; break; |
|
case "4": $order = "b_contratti.oggetto "; break; |
|
case "5": $order = "b_contratti.importo_totale "; break; |
|
case "6": $order = "b_contratti.data_stipula "; break; |
|
case "7": $order = "b_contratti.data_inizio "; break; |
|
case "8": $order = "b_contratti.data_fine "; break; |
|
} |
|
if ($_GET["order"][0]["dir"] == "desc") { |
|
$order.= "DESC "; |
|
} else { |
|
$order.= "ASC "; |
|
} |
|
|
|
if ($_SESSION['ente']->hasModulo('contratti.documentale') && !empty($_GET['badge']) && $_GET['badge'] == 'on'){ |
|
$filterApplied = true; |
|
$sql .= " AND b_contratti.badge > 0"; |
|
} |
|
|
|
$sql .= " ORDER BY " . $order . ", b_contratti.codice DESC "; |
|
$risultatiBeforLimit = $pdo->go($sql,$bind); |
|
if ($_GET["length"] !== "-1") { |
|
$sql.= "LIMIT ". (int)$_GET["start"] .", " . (int)$_GET["length"]; |
|
} |
|
|
|
$risultati = $pdo->go($sql,$bind); |
|
if ($risultati->rowCount() > 0) { |
|
if ($filterApplied) { |
|
$return["recordsFiltered"] = (int)$risultatiBeforLimit->rowCount(); |
|
} else { |
|
$return["recordsFiltered"] = $return["recordsTotal"]; |
|
} |
|
$return["data"] = array(); |
|
|
|
$stati = stipula::getStati(); |
|
$contratti = $risultati->fetchAll(PDO::FETCH_ASSOC); |
|
|
|
if ($_SESSION['ente']->hasModulo('contratti.documentale')){ |
|
$ids = pluck('codice', $contratti) ?? []; |
|
$richieste = RichiestaDocumentale::getRichieste(['codici_contratti' => $ids]); |
|
|
|
if (!empty($richieste)) { |
|
$tmpContratti = $contratti; |
|
$contratti = null; |
|
foreach ( $tmpContratti as $key => $tmpContratto) { |
|
$contratti[$key] = $tmpContratto; |
|
foreach ($richieste as $key2 => $richiesta) { |
|
if ($tmpContratto['codice'] == $richiesta['codice_contratto'] ) { |
|
$contratti[$key]['richieste'][$key2] = $richiesta; |
|
} |
|
} |
|
} |
|
} |
|
|
|
} |
|
|
|
foreach($contratti as $record) { |
|
|
|
$stato = $stati[$record["stato"]] ?? ['titolo' => __('Stato Non Definito'), 'color' => '#CC0000']; |
|
$statusERP = ""; |
|
if (!empty($_SESSION["ente"]->erpConnector) && method_exists($_SESSION["ente"]->erpConnector,"getStatusStipula")) { |
|
$statusERP = $_SESSION["ente"]->erpConnector->getStatusStipula($record["codice"]); |
|
if (!empty($statusERP)) { |
|
$statusERP = "<span class='badge badge-{$statusERP["color"]}'>{$statusERP["label"]}</span>"; |
|
} |
|
} |
|
$row = array(); |
|
|
|
$panelHref = "/backend/contratti/panel.php?codice={$record["codice"]}"; |
|
|
|
$row[] = '<div id="flag_'.$record["codice"].'" class="status_flag" style="background-color:'.$stato["color"].'"></div>'; |
|
$row[] = __($stato["titolo"]) . "{$statusERP}"; |
|
$row[] = $record["id"]; |
|
|
|
// Badge contratto |
|
if ($record["badge"] > 0) { |
|
$row[] = '<span class="badge badge-danger" style="font-size:1em">' . $record['badge'] ?? null . '</span>'; |
|
}else{ |
|
$row[] = null; |
|
} |
|
|
|
$row[] = "<strong><a href='{$panelHref}' title='".__("gestisci")."'>" . $record["oggetto"] . "</a></strong>"; |
|
$row[] = number_format($record["importo_totale"],2,",","."); |
|
$row[] = mysql2date($record["data_stipula"]); |
|
$row[] = mysql2date($record["data_inizio"]); |
|
$row[] = mysql2date($record["data_fine"]); |
|
|
|
// badge richieste |
|
if ($_SESSION['ente']->hasModulo('contratti.documentale')) { |
|
|
|
$badges = rispostaDocumentale::getGroupBadge($record['codice'], $record['richieste'] ?? [], 'sa'); |
|
if ( !empty($badges)) { |
|
ob_start(); |
|
foreach ($badges as $stat => $badge) { |
|
?> |
|
<a href="javascript:void(0)" class="text-decoration-none" title='<?= $badge['titolo'] ?>'> |
|
<span class="mr-1 badge badge-<?= $badge['class']?> " style="font-size:1em"> <?= (!empty($badge['contatori'])) ? $badge['contatori'] : 0 ?></span> |
|
</a> |
|
<? |
|
} |
|
$row[] = ob_get_clean(); |
|
}else{ |
|
$row[] = __('Nessuna richiesta in corso'); |
|
} |
|
|
|
}else{ |
|
$row[] = ''; |
|
} |
|
|
|
$row[] = "<a href='{$panelHref}' title='".__("gestisci")."' class='btn-info btn-sm'><span class='fa fa-th'></span></a>"; |
|
$return["data"][] = $row; |
|
} |
|
} else { |
|
$return["data"] = array(); |
|
} |
|
} else { |
|
$return["data"] = array(); |
|
} |
|
|
|
echo json_encode($return); |
|
} |
|
} |
|
?>
|
|
|