Skip to content

Commit

Permalink
modifiche in amministrazione tipi di movimenti contabili. closes #288
Browse files Browse the repository at this point in the history
  • Loading branch information
madbob committed Sep 14, 2024
1 parent 1e344d0 commit ecf3802
Show file tree
Hide file tree
Showing 12 changed files with 217 additions and 117 deletions.
92 changes: 54 additions & 38 deletions code/app/Helpers/Components.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,58 @@ function formatInnerLastUpdater($component, $params)
return $params;
}

function appendSaveNotifier($params)
{
$params['appendNodes'] = $params['appendNodes'] ?? [];

/*
Questo aggiunge al form la barra di notifica che viene attivata
quando si modifica un qualche parametro ed è richiesto il
salvataggio
*/
$params['appendNodes'][] = sprintf('<div class="fixed-bottom bg-danger p-2 bottom-helper" hidden>
<div class="row justify-content-end align-items-center">
<div class="col-auto text-white">%s</div>
<div class="col-auto">
<button class="btn btn-success" type="submit">%s</button>
</div>
</div>
</div>', _i('Ricorda di cliccare il tasto "Salva" quando hai finito!'), _i('Salva'));

return $params;
}

function mainFormButtons($params)
{
$buttons = $params['attributes']['other_buttons'] ?? [];

$buttons = formatUpdater($buttons, $params);
$obj = $params['obj'];

$nodelete = filter_var($params['attributes']['nodelete'] ?? false, FILTER_VALIDATE_BOOLEAN);
if (!$nodelete) {
$buttons[] = [
'color' => 'danger',
'classes' => ['delete-button'],
'label' => $obj && $obj->deleted_at != null ? _i('Elimina Definitivamente') : _i('Elimina'),
];
}

$nosave = filter_var($params['attributes']['nosave'] ?? false, FILTER_VALIDATE_BOOLEAN);
if (!$nosave) {
$buttons[] = [
'color' => 'success',
'classes' => ['save-button'],
'label' => _i('Salva'),
'attributes' => ['type' => 'submit'],
];
}

$params['buttons'] = $buttons;

return $params;
}

function formatMainFormButtons($component, $params)
{
/*
Expand All @@ -211,44 +263,8 @@ function formatMainFormButtons($component, $params)
}
else {
$params['main_form_managed'] = 'ongoing';
$buttons = $params['attributes']['other_buttons'] ?? [];

$buttons = formatUpdater($buttons, $params);
$obj = $params['obj'];

$nodelete = filter_var($params['attributes']['nodelete'] ?? false, FILTER_VALIDATE_BOOLEAN);
if (!$nodelete) {
$buttons[] = [
'color' => 'danger',
'classes' => ['delete-button'],
'label' => $obj && $obj->deleted_at != null ? _i('Elimina Definitivamente') : _i('Elimina'),
];
}

$nosave = filter_var($params['attributes']['nosave'] ?? false, FILTER_VALIDATE_BOOLEAN);
if (!$nosave) {
$buttons[] = [
'color' => 'success',
'classes' => ['save-button'],
'label' => _i('Salva'),
'attributes' => ['type' => 'submit'],
];
}

$params['buttons'] = $buttons;

if (isset($params['appendNodes']) == false) {
$params['appendNodes'] = [];
}

$params['appendNodes'][] = sprintf('<div class="fixed-bottom bg-danger p-2 bottom-helper" hidden>
<div class="row justify-content-end align-items-center">
<div class="col-auto text-white">%s</div>
<div class="col-auto">
<button class="btn btn-success" type="submit">%s</button>
</div>
</div>
</div>', _i('Ricorda di cliccare il tasto "Salva" quando hai finito!'), _i('Salva'));
$params = mainFormButtons($params);
$params = appendSaveNotifier($params);
}

unset($params['attributes']['other_buttons'], $params['attributes']['nodelete'], $params['attributes']['nosave']);
Expand Down
8 changes: 8 additions & 0 deletions code/app/Models/Concerns/TracksUpdater.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
<?php

/*
Usato dai modelli che tracciano data e operatore dell'ultima modifica
effettuata.
I form primari di gestione delle istanze delle classi che usano questo trait
sono processati con la funzione formatUpdater() per generare la nota "Ultima
Modifica" che appare al fondo di essi
*/

namespace App\Models\Concerns;

use Illuminate\Database\Eloquent\Relations\BelongsTo;
Expand Down
36 changes: 11 additions & 25 deletions code/app/Services/MovementTypesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use DB;

use App\Gas;
use App\Movement;
use App\MovementType;

Expand Down Expand Up @@ -57,15 +58,12 @@ private function newFunction($pay_id, $request, &$data)
private function parseRules(&$data, $role, $classname, $request)
{
$payments = paymentTypes();
$valid_payments = array_intersect_key($request, $payments);
$fields = (new $classname())->balanceFields();

foreach(array_keys($fields) as $f) {
foreach(array_keys($payments) as $pay_id) {
if (isset($request[$pay_id]) == false) {
continue;
}

$conf = $request[$classname . '-' . $f . '-' . $pay_id] ?? 'ignore';
foreach(array_keys($valid_payments) as $pay_id) {
$conf = $request[$role . '-' . $classname . '-' . $f . '-' . $pay_id] ?? 'ignore';
if ($conf != 'ignore') {
$cell = null;

Expand All @@ -92,12 +90,9 @@ private function parseRules(&$data, $role, $classname, $request)
private function fixVoidMethods(&$data, $request)
{
$payments = paymentTypes();
$valid_payments = array_intersect_key($request, $payments);

foreach(array_keys($payments) as $pay_id) {
if (isset($request[$pay_id]) == false) {
continue;
}

foreach(array_keys($valid_payments) as $pay_id) {
$exists = array_filter($data, function($d) use ($pay_id) {
return $d->method == $pay_id;
});
Expand All @@ -120,17 +115,8 @@ public function update($id, array $request)
$this->setIfSet($type, $request, 'default_notes');

if ($type->system == false) {
$sender_type = $request['sender_type'];
if (!empty($sender_type))
$type->sender_type = $sender_type;
else
$type->sender_type = null;

$target_type = $request['target_type'];
if (!empty($target_type))
$type->target_type = $target_type;
else
$type->target_type = null;
$type->sender_type = empty($request['sender_type']) ? null : $request['sender_type'];
$type->target_type = empty($request['target_type']) ? null : $request['target_type'];
}

$data = [];
Expand All @@ -139,12 +125,12 @@ public function update($id, array $request)
$this->parseRules($data, 'sender', $type->sender_type, $request);
}

if ($type->target_type != null && $type->target_type != $type->sender_type) {
if ($type->target_type != null) {
$this->parseRules($data, 'target', $type->target_type, $request);
}

if ($type->sender_type != 'App\Gas' && $type->target_type != 'App\Gas') {
$this->parseRules($data, 'master', 'App\Gas', $request);
if ($type->sender_type != Gas::class && $type->target_type != Gas::class) {
$this->parseRules($data, 'master', Gas::class, $request);
}

/*
Expand Down
7 changes: 7 additions & 0 deletions code/config/larastrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,20 @@
],
],
],

/*
mform viene usato per le entità rappresentate dentro una
loadablelist: al salvataggio, lo slot in cui si trova il form stesso
viene chiuso ed il relativo header viene aggiornato
*/
'mform' => [
'extends' => 'form',
'params' => [
'classes' => ['main-form'],
'reviewCallback' => 'formatMainFormButtons',
],
],

'iform' => [
'extends' => 'form',
'params' => [
Expand Down
2 changes: 1 addition & 1 deletion code/public/js/gasdotto.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion code/public/js/gasdotto.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion code/public/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"/js/gasdotto.js": "/js/gasdotto.js?id=8343ed592713ef47b7f1d616470b4a37",
"/js/gasdotto.js": "/js/gasdotto.js?id=c019a69811eb328888b7b886111bb64d",
"/css/gasdotto.css": "/css/gasdotto.css?id=944fde138a68e0877df0d9da8e03d933"
}
5 changes: 5 additions & 0 deletions code/resources/assets/js/callables.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ class Callables {
}
}

static filterOutUnusedRules(form)
{
form.find('table tbody tr[hidden]').remove();
}

/* post-saved-function ****************************************************/

static closeAllModals()
Expand Down
53 changes: 32 additions & 21 deletions code/resources/assets/js/gasdotto.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,31 @@ function miscInnerCallbacks(form, data) {
return true;
}

function preSaveForm(form) {
var proceed = true;

var test = form.find('input[name^=pre-saved-function]');
if (test.length != 0) {
test.each(function() {
var fn = Callables[$(this).val()];
if (typeof fn === 'function') {
/*
Se una pre-saved-function solleva una eccezione, il form
non viene effettivamente eseguito
*/
try {
fn(form);
}
catch(error) {
proceed = false;
}
}
});
}

return proceed;
}

function miscInnerModalCallbacks(modal) {
var test = modal.find('input[name=reload-portion]');
if (test.length != 0) {
Expand Down Expand Up @@ -487,6 +512,12 @@ $(document).ready(function() {
event.preventDefault();

var form = $(this);

var proceed = preSaveForm(form);
if (proceed == false) {
return;
}

form.find('button[type=submit]').prop('disabled', true);

utils.postAjax({
Expand Down Expand Up @@ -536,27 +567,7 @@ $(document).ready(function() {
event.preventDefault();
var form = $(this);

var proceed = true;

var test = form.find('input[name^=pre-saved-function]');
if (test.length != 0) {
test.each(function() {
var fn = Callables[$(this).val()];
if (typeof fn === 'function') {
/*
Se una pre-saved-function solleva una eccezione, il form
non viene effettivamente eseguito
*/
try {
fn(form);
}
catch(error) {
proceed = false;
}
}
});
}

var proceed = preSaveForm(form);
if (proceed == false) {
return;
}
Expand Down
14 changes: 11 additions & 3 deletions code/resources/assets/js/movements.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class Movements {
var sender = editor.find('select[name=sender_type] option:selected').val();
var target = editor.find('select[name=target_type] option:selected').val();
var table = editor.find('table');
var manages_gas = (sender == 'App\\Gas' || target == 'App\\Gas');

table.find('tbody tr').each(function() {
var type = $(this).attr('data-target-class');
Expand All @@ -63,15 +64,22 @@ class Movements {
molti tipi di movimento vanno ad incidere sui saldi globali
anche quando il GAS non è direttamente coinvolto
*/
$(this).toggleClass('hidden', (type != 'App\\Gas' && type != sender && type != target));
if (type == 'master-App\\Gas') {
$(this).prop('hidden', manages_gas);
}
else {
$(this).prop('hidden', type != 'sender-' + sender && type != 'target-' + target);
}
});

table.find('thead input[data-active-for]').each(function() {
var type = $(this).attr('data-active-for');
if(type != '' && type != sender && type != target)
if(type != '' && type != sender && type != target) {
$(this).prop('checked', false).prop('disabled', true).change();
else
}
else {
$(this).prop('disabled', false);
}
});
});

Expand Down
2 changes: 1 addition & 1 deletion code/resources/views/app.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</form>
@endif

<div class="container-fluid">
<div class="container-fluid mb-5">
<div class="row">
<div class="col-md-12" id="main-contents">
@include('commons.flashing')
Expand Down
Loading

0 comments on commit ecf3802

Please sign in to comment.