1
0
mirror of https://github.com/devcode-it/openstamanager.git synced 2025-02-01 16:36:45 +01:00

Impostazione "Totali delle tabelle ristretti alla selezione"

This commit is contained in:
Thomas Zilio 2020-07-16 17:31:30 +02:00
parent c35b641bd8
commit 3e5b3e2fa6
5 changed files with 62 additions and 9 deletions

View File

@ -140,5 +140,15 @@ switch (filter('op')) {
echo json_encode($response);
break;
case 'summable-results':
$ids = post('ids') ?: [];
$results = Util\Query::getSums($structure, [
'id' => $ids,
]);
echo json_encode($results);
break;
}

View File

@ -350,7 +350,7 @@ function getTable(selector) {
var selected = new Map();
var selected_ids = table.data('selected') ? table.data('selected').split(';') : [];
selected_ids.forEach(function(item, index) {
selected_ids.forEach(function (item, index) {
selected.set(item, true);
});
@ -360,7 +360,7 @@ function getTable(selector) {
id_module: table.data('idmodule'),
id_plugin: table.data('idplugin'),
initDatatable: function() {
initDatatable: function () {
if (table.hasClass('datatables')) {
start_local_datatables();
} else {
@ -395,10 +395,15 @@ function getTable(selector) {
bulk_container.addClass('disabled').attr('disabled', true);
btn_container.addClass('disabled').attr('disabled', true);
}
// Aggiornamento del footer nel caso sia richiesto
if (globals.restrict_summables_to_selected){
this.updateSelectedFooter();
}
},
addSelectedRows: function (row_ids) {
row_ids = Array.isArray(row_ids) ? row_ids : [row_ids];
row_ids.forEach(function(item, index) {
row_ids.forEach(function (item, index) {
selected.set(item, true);
});
@ -406,7 +411,7 @@ function getTable(selector) {
},
removeSelectedRows: function (row_ids) {
row_ids = Array.isArray(row_ids) ? row_ids : [row_ids];
row_ids.forEach(function(item, index) {
row_ids.forEach(function (item, index) {
selected.delete(item);
});
@ -416,5 +421,32 @@ function getTable(selector) {
selected.clear();
this.saveSelectedRows();
},
// Aggiornamento dei campi summable
updateSelectedFooter: function () {
let datatable = this.datatable;
let ids = this.getSelectedRows();
$.ajax({
url: globals.rootdir + "/ajax.php",
type: "POST",
dataType: "json",
data: {
id_module: this.id_module,
id_plugin: this.id_plugin,
op: "summable-results",
ids: ids,
},
success: function (response) {
for (let [column, value] of Object.entries(response)) {
let index = parseInt(column) + 1;
let sel = datatable.column(index).footer();
$(sel).addClass("text-right")
.attr("id", "summable")
.html(value);
}
}
});
},
};
}

View File

@ -174,6 +174,7 @@ if (Auth::check()) {
order_manager_id: "'.($dbo->isInstalled() ? Modules::get('Stato dei servizi')['id'] : '').'",
dataload_page_buffer: '.setting('Lunghezza in pagine del buffer Datatables').',
tempo_attesa_ricerche: '.setting('Tempo di attesa ricerche in secondi').',
restrict_summables_to_selected: '.setting('Totali delle tabelle ristretti alla selezione').',
};
</script>';
} else {

View File

@ -140,11 +140,11 @@ class Query
return '';
}
// Filtri di ricerica
// Filtri di ricerca
$search_filters = [];
foreach ($search as $field => $value) {
foreach ($search as $field => $original_value) {
$pos = array_search($field, $total['fields']);
$value = trim($value);
$value = trim($original_value);
if (isset($value) && $pos !== false) {
$search_query = $total['search_inside'][$pos];
@ -201,7 +201,14 @@ class Query
// Campo id: ricerca tramite comparazione
elseif ($field == 'id') {
$search_filters[] = $field.' = '.prepare($value);
// Filtro per una serie di ID
if (is_array($original_value)) {
if (!empty($original_value)) {
$search_filters[] = $field.' IN ('.implode(', ', $original_value).')';
}
} else {
$search_filters[] = $field.' = '.prepare($value);
}
}
// Ricerca
@ -264,7 +271,7 @@ class Query
*/
public static function getSums($structure, $search = [])
{
$total = self::readQuery($structure, $search);
$total = self::readQuery($structure);
// Calcolo di eventuali somme
if (empty($total['summable'])) {

View File

@ -122,3 +122,6 @@ UPDATE `em_accounts` SET `connected_at` = NOW();
-- Aggiunta del flag is_importabile sulle causali per permettere/bloccare l'importazione dei DDT
ALTER TABLE `dt_causalet` ADD `is_importabile` BOOLEAN DEFAULT TRUE AFTER `descrizione`;
-- Impostazione "Totali delle tabelle ristretti alla selezione"
INSERT INTO `zz_settings` (`id`, `nome`, `valore`, `tipo`, `editable`, `sezione`, `order`) VALUES (NULL, 'Totali delle tabelle ristretti alla selezione', '0', 'boolean', '1', 'Generali', 119);