Skip to content

Commit 2951a07

Browse files
feat: aggiunta duplicazione listino selezione anagrafiche collegate e azione di gruppo per aggiornare lo sconto
1 parent 54c9da9 commit 2951a07

7 files changed

Lines changed: 127 additions & 2 deletions

File tree

modules/listini_cliente/actions.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@
3434
$listino->note = post('note');
3535
$listino->save();
3636

37+
$id_anagrafiche = (array) post('idanagrafica');
38+
$dbo->query('UPDATE `an_anagrafiche` SET id_listino=0 WHERE id_listino='.prepare($id_record));
39+
foreach ($id_anagrafiche as $id_anagrafica) {
40+
$dbo->query('UPDATE `an_anagrafiche` SET id_listino='.prepare($id_record).' WHERE idanagrafica='.prepare($id_anagrafica));
41+
}
42+
3743
flash()->info(tr('Listino modificato correttamente!'));
3844

3945
break;
@@ -74,6 +80,30 @@
7480

7581
break;
7682

83+
case 'copy':
84+
$database->beginTransaction();
85+
$dbo->query('CREATE TEMPORARY TABLE tmp SELECT * FROM mg_listini WHERE id= '.prepare($id_record));
86+
$dbo->query('ALTER TABLE tmp DROP id');
87+
$dbo->query('INSERT INTO mg_listini SELECT NULL,tmp. * FROM tmp');
88+
$id_record_new = $dbo->lastInsertedID();
89+
$dbo->query('DROP TEMPORARY TABLE tmp');
90+
$dbo->query('UPDATE mg_listini SET nome = CONCAT (nome, " (copia)") WHERE id = '.prepare($id_record_new));
91+
92+
$articoli = Articolo::where('id_listino', $id_record)->get();
93+
foreach ($articoli as $articolo) {
94+
$dbo->query('CREATE TEMPORARY TABLE tmp SELECT * FROM mg_listini_articoli WHERE id= '.prepare($articolo->id));
95+
$dbo->query('ALTER TABLE tmp DROP id');
96+
$dbo->query('INSERT INTO mg_listini_articoli SELECT NULL,tmp. * FROM tmp');
97+
$id_riga_new = $dbo->lastInsertedID();
98+
$dbo->query('DROP TEMPORARY TABLE tmp');
99+
$dbo->query('UPDATE mg_listini_articoli SET id_listino = '.prepare($id_record_new).' WHERE id = '.prepare($id_riga_new));
100+
}
101+
102+
flash()->info(tr('Listino duplicato correttamente!'));
103+
104+
break;
105+
106+
77107
case 'delete_articolo':
78108
$id_righe = (array) post('id');
79109

modules/listini_cliente/add.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
4242
<div class="row">
4343
<div class="col-md-6">
44-
{[ "type":"checkbox", "label":"'.tr('Sempre visibile').'", "name":"is_sempre_visibile", "help": "'.tr('Se impostato il valore sarà sempre visibile sull\'articolo se il listino è attivo e la data di scadenza è ancora valida').'" ]}
44+
{[ "type":"checkbox", "label":"'.tr('Sempre visibile').'", "name":"is_sempre_visibile", "help": "'.tr('Se impostato il valore sarà sempre visibile sull\'articolo se il listino è attivo e la data di scadenza è ancora valida non è quindi necessario associare il listino alle anagrafiche').'" ]}
4545
</div>
4646
4747
<div class="col-md-6">

modules/listini_cliente/bulk.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
/*
4+
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
5+
* Copyright (C) DevCode s.r.l.
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
*/
20+
21+
include_once __DIR__.'/../../core.php';
22+
23+
use Modules\ListiniCliente\Articolo;
24+
use Modules\ListiniCliente\Listino;
25+
26+
switch (post('op')) {
27+
case 'change_prezzo':
28+
foreach ($id_records as $id) {
29+
$listino = Listino::find($id);
30+
31+
$articoli = Articolo::where('id_listino', $id)->get();
32+
foreach ($articoli as $articolo) {
33+
$articolo->sconto_percentuale = post('percentuale');
34+
$articolo->save();
35+
}
36+
}
37+
38+
flash()->info(tr('Listini aggiornati!'));
39+
40+
break;
41+
}
42+
43+
$operations['change_prezzo'] = [
44+
'text' => '<span><i class="fa fa-refresh"></i> '.tr('Aggiorna sconto percentuale').'</span>',
45+
'data' => [
46+
'title' => tr('Aggiornare lo sconto percentuale per i listini selezionati?'),
47+
'msg' => tr('Per indicare uno sconto inserire la percentuale con il segno meno, al contrario per un rincaro inserire la percentuale senza segno.').'<br><br>{[ "type": "number", "label": "'.tr('Percentuale sconto/magg.').'", "name": "percentuale", "required": 1, "icon-after": "%" ]}',
48+
'button' => tr('Procedi'),
49+
'class' => 'btn btn-lg btn-warning',
50+
'blank' => false,
51+
],
52+
];
53+
54+
return $operations;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
/*
4+
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
5+
* Copyright (C) DevCode s.r.l.
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
*/
20+
21+
include_once __DIR__.'/../../core.php';
22+
23+
// Duplica listino
24+
echo '
25+
<button type="button" class="btn btn-primary ask" data-title="'.tr('Duplicare questo listino?').'" data-msg="'.tr('Clicca su tasto duplica per procedere.').'" data-op="copy" data-button="'.tr('Duplica').'" data-class="btn btn-lg btn-primary" data-backto="record-edit">
26+
<i class="fa fa-copy"></i> '.tr('Duplica listino').'
27+
</button>';

modules/listini_cliente/edit.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,20 @@
4949
5050
<div class="row">
5151
<div class="col-md-6">
52-
{[ "type":"checkbox", "label":"'.tr('Sempre visibile').'", "name":"is_sempre_visibile", "value":"$is_sempre_visibile$", "help": "'.tr('Se impostato il valore sarà sempre visibile sull\'articolo se il listino è attivo e la data di scadenza è ancora valida').'" ]}
52+
{[ "type":"checkbox", "label":"'.tr('Sempre visibile').'", "name":"is_sempre_visibile", "value":"$is_sempre_visibile$", "help": "'.tr('Se impostato il valore sarà sempre visibile sull\'articolo se il listino è attivo e la data di scadenza è ancora valida non è quindi necessario associare il listino alle anagrafiche').'" ]}
5353
</div>
5454
5555
<div class="col-md-6">
5656
{[ "type":"checkbox", "label":"'.tr('Attivo').'", "name":"attivo", "value": "$attivo$" ]}
5757
</div>
5858
</div>
5959
60+
<div class="row">
61+
<div class="col-md-12">
62+
{[ "type":"select", "multiple": "1", "label":"'.tr('Clienti').'", "ajax-source": "clienti", "name": "idanagrafica[]", "value": "'.$anagrafiche.'" ]}
63+
</div>
64+
</div>
65+
6066
<div class="row">
6167
<div class="col-md-12">
6268
{[ "type":"textarea", "label":"'.tr('Note').'", "name":"note", "value":"$note$" ]}

modules/listini_cliente/init.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
if (!empty($id_record)) {
2626
$listino = Listino::find($id_record);
2727
$record = $dbo->fetchOne('SELECT * FROM `mg_listini` WHERE `id`='.prepare($id_record));
28+
$anagrafiche = $listino->anagrafiche->pluck('idanagrafica')->toArray();
29+
$anagrafiche = implode(',', $anagrafiche);
2830

2931
$prezzi_ivati = setting('Utilizza prezzi di vendita comprensivi di IVA');
3032
}

modules/listini_cliente/src/Listino.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
use Common\SimpleModelTrait;
2424
use Illuminate\Database\Eloquent\Model;
25+
use Modules\Anagrafiche\Anagrafica;
2526

2627
/*
2728
* Classe per la gestione delle relazioni articolo-prezzo sulla base di un range di quantità e di una specifica anagrafica.
@@ -48,4 +49,9 @@ public static function build($nome = null)
4849

4950
return $model;
5051
}
52+
53+
public function anagrafiche()
54+
{
55+
return $this->hasMany(Anagrafica::class, 'id_listino');
56+
}
5157
}

0 commit comments

Comments
 (0)