Skip to content

Commit bac4ef2

Browse files
committed
Feat: Plugin per gestione barcode multipli su articoli
1 parent 1e385a4 commit bac4ef2

11 files changed

Lines changed: 415 additions & 102 deletions

File tree

modules/articoli/actions.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,6 @@
6262
$articolo->name = post('descrizione');
6363
}
6464

65-
if (post('genera_barcode')) {
66-
$codice = '200'.str_pad((string) $articolo->id, 9, '0', STR_PAD_LEFT);
67-
$barcode = (new Picqer\Barcode\Types\TypeEan13())->getBarcode($codice)->getBarcode();
68-
}
69-
$articolo->barcode = $barcode ?: post('barcode');
7065
$articolo->coefficiente = post('coefficiente');
7166
$articolo->idiva_vendita = post('idiva_vendita');
7267
$articolo->prezzo_acquisto = post('prezzo_acquisto');
@@ -97,6 +92,19 @@
9792
$id_record = $articolo->id;
9893
$iva = post('idiva_vendita') ? Aliquota::find(post('idiva_vendita')) : null;
9994

95+
if (post('genera_barcode')) {
96+
$codice = '200'.str_pad((string) $articolo->id, 9, '0', STR_PAD_LEFT);
97+
$barcode = (new Picqer\Barcode\Types\TypeEan13())->getBarcode($codice)->getBarcode();
98+
}
99+
100+
$barcode = ($barcode ? $barcode : post('barcode'));
101+
if (!empty($barcode)) {
102+
$dbo->insert('mg_articoli_barcode', [
103+
'idarticolo' => $id_record,
104+
'barcode' => $barcode,
105+
]);
106+
}
107+
100108
if (isAjaxRequest()) {
101109
echo json_encode([
102110
'id' => $id_record,
@@ -139,7 +147,6 @@
139147
}
140148

141149
$articolo->codice = post('codice', true);
142-
$articolo->barcode = post('barcode');
143150
$articolo->um = post('um');
144151
$articolo->id_categoria = post('categoria');
145152
$articolo->id_sottocategoria = post('subcategoria');

modules/articoli/edit.php

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,14 @@
4545

4646
<div class="col-md-9">
4747
<div class="row">
48-
<div class="col-md-3">
48+
<div class="col-md-4">
4949
{[ "type": "text", "label": "<?php echo tr('Codice'); ?>", "name": "codice", "required": 1, "value": "$codice$", "validation": "codice" ]}
5050
</div>
5151

52-
<div class="col-md-3">
53-
<button type="button" class="btn btn-default btn-xs tip pull-right" id="generaBarcode"><i class="fa fa-refresh"></i> <?php echo tr('Genera'); ?></button>
54-
{[ "type": "text", "label": "<?php echo tr('Barcode'); ?>", "name": "barcode", "validation": "barcode", "class": "text-center", "value": "$barcode$" ]}
55-
</div>
56-
57-
<div class="col-md-3">
52+
<div class="col-md-4">
5853
{[ "type": "checkbox", "label": "<?php echo tr('Questo articolo è un servizio'); ?>", "name": "servizio", "value": "$servizio$", "help": "<?php echo tr('Le quantità non saranno considerate.'); ?>", "placeholder": "<?php echo tr('Servizio'); ?>" ]}
5954
</div>
60-
<div class="col-md-3">
55+
<div class="col-md-4">
6156
{[ "type": "checkbox", "label": "<?php echo tr('Attivo'); ?>", "name": "attivo", "help": "<?php echo tr('Seleziona per rendere attivo l\'articolo'); ?>", "value": "$attivo$", "placeholder": "<?php echo tr('Articolo attivo'); ?>" ]}
6257
</div>
6358
</div>
@@ -383,28 +378,6 @@ function scorporaIva() {
383378
scorporaIva();
384379
});
385380

386-
function generaBarcode() {
387-
$.ajax({
388-
url: globals.rootdir + "/actions.php",
389-
type: "POST",
390-
data: {
391-
id_module: globals.id_module,
392-
id_record: globals.id_record,
393-
op: "generate-barcode"
394-
},
395-
success: function(response) {
396-
response = JSON.parse(response);
397-
let input = $("#barcode");
398-
input.val(response.barcode);
399-
},
400-
error: function(xhr, status, error) {
401-
}
402-
});
403-
}
404-
405-
$("#generaBarcode").click( function() {
406-
generaBarcode();
407-
});
408381
</script>
409382

410383

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
/*
3+
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
4+
* Copyright (C) DevCode s.r.l.
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
20+
include_once __DIR__.'/../../core.php';
21+
22+
$operazione = filter('op');
23+
24+
switch ($operazione) {
25+
case 'addbarcode':
26+
if (!empty(post('barcode'))) {
27+
$dbo->insert('mg_articoli_barcode', [
28+
'idarticolo' => $id_parent,
29+
'barcode' => post('barcode'),
30+
]);
31+
$id_record = $dbo->lastInsertedID();
32+
33+
flash()->info(tr('Aggiunto un nuovo barcode!'));
34+
} else {
35+
flash()->warning(tr('Errore durante aggiunta del barcode'));
36+
}
37+
38+
break;
39+
40+
case 'updatebarcode':
41+
$dbo->update('mg_articoli_barcode', [
42+
'barcode' => post('barcode'),
43+
], ['id' => $id_record]);
44+
45+
flash()->info(tr('Salvataggio completato!'));
46+
47+
break;
48+
49+
case 'deletebarcode':
50+
$id = filter('id');
51+
$dbo->query('DELETE FROM `mg_articoli_barcode` WHERE `id` = '.prepare($id).'');
52+
53+
flash()->info(tr('Barcode eliminato!'));
54+
55+
break;
56+
57+
case 'manage-btn':
58+
59+
$btnid = post('btnid');
60+
61+
if( empty($btnid) ){
62+
$dbo->insert('mg_btn_articoli', [
63+
'colore' => post('colore'),
64+
'descrizione' => post('descrizione_pulsante'),
65+
'usa_immagine' => post('usa_immagine'),
66+
'idarticolo' => post('idarticolo'),
67+
]);
68+
69+
$btnid = $dbo->lastInsertedID();
70+
flash()->info(tr('Pulsante aggiornato!'));
71+
}else{
72+
if( empty(post('colore')) && empty(post('descrizione_pulsante')) && empty(post('usa_immagine')) ){
73+
$dbo->query("DELETE FROM mg_btn_articoli WHERE id=".prepare($btnid));
74+
flash()->info(tr('Pulsante rimosso!'));
75+
}else{
76+
$dbo->update('mg_btn_articoli', [
77+
'colore' => post('colore'),
78+
'descrizione' => post('descrizione_pulsante'),
79+
'usa_immagine' => post('usa_immagine'),
80+
], ['id' => $btnid]);
81+
flash()->info(tr('Pulsante aggiornato!'));
82+
}
83+
}
84+
85+
$dbo->query("DELETE FROM mg_btn_magazzini WHERE btn_id=".prepare($btnid));
86+
foreach(post('idmagazzini') as $idmagazzino){
87+
$dbo->insert('mg_btn_magazzini', [
88+
'btn_id' => $btnid,
89+
'idmagazzino' => $idmagazzino,
90+
]);
91+
}
92+
93+
break;
94+
}

plugins/barcode_articoli/add.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
/*
3+
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
4+
* Copyright (C) DevCode s.r.l.
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
20+
include_once __DIR__.'/../../core.php';
21+
22+
echo '
23+
<form action="" method="post" role="form">
24+
<input type="hidden" name="id_parent" value="'.$id_parent.'">
25+
<input type="hidden" name="backto" value="record-edit">
26+
<input type="hidden" name="op" value="addbarcode">
27+
28+
<!-- Fix creazione da Articolo -->
29+
<input type="hidden" name="id_record" value="0">
30+
31+
<div class="row">
32+
<div class="col-md-12">
33+
<button type="button" class="btn btn-default btn-xs tip pull-right" id="generaBarcode"><i class="fa fa-refresh"></i> '.tr('Genera').'</button>
34+
{[ "type": "text", "label": "'.tr('Barcode').'", "name": "barcode", "validation": "barcode", "class": "text-center", "value": "" ]}
35+
</div>
36+
</div>
37+
38+
<!-- PULSANTI -->
39+
<div class="row">
40+
<div class="col-md-12 text-right">
41+
<button type="submit" class="btn btn-primary"><i class="fa fa-plus"></i> '.tr('Aggiungi').'</button>
42+
</div>
43+
</div>
44+
</form>';
45+
46+
echo '
47+
<script>
48+
function generaBarcode() {
49+
$.ajax({
50+
url: globals.rootdir + "/actions.php",
51+
type: "POST",
52+
data: {
53+
id_module: globals.id_module,
54+
id_record: globals.id_record,
55+
op: "generate-barcode"
56+
},
57+
success: function(response) {
58+
response = JSON.parse(response);
59+
let input = $("#barcode");
60+
input.val(response.barcode);
61+
},
62+
error: function(xhr, status, error) {
63+
}
64+
});
65+
}
66+
67+
$("#generaBarcode").click( function() {
68+
generaBarcode();
69+
});
70+
</script>';

plugins/barcode_articoli/edit.php

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
/*
3+
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
4+
* Copyright (C) DevCode s.r.l.
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
20+
include_once __DIR__.'/../../core.php';
21+
22+
$id_record = get('id_record');
23+
$id_parent = get('id_parent');
24+
$id_plugin = get('id_plugin');
25+
$id_module = get('id_module');
26+
27+
$barcode = $dbo->table('mg_articoli_barcode')->where('id',$id_record)->first();
28+
29+
echo '
30+
<form action="" method="post" role="form" id="form_sedi">
31+
<input type="hidden" name="id_plugin" value="'.$id_plugin.'">
32+
<input type="hidden" name="id_parent" value="'.$id_parent.'">
33+
<input type="hidden" name="id_record" value="'.$id_record.'">
34+
<input type="hidden" name="backto" value="record-edit">
35+
<input type="hidden" name="op" value="updatebarcode">
36+
37+
<div class="row">
38+
<div class="col-md-12">
39+
<button type="button" class="btn btn-default btn-xs tip pull-right" id="generaBarcode"><i class="fa fa-refresh"></i> '.tr('Genera').'</button>
40+
{[ "type": "text", "label": "'.tr('Barcode').'", "name": "barcode", "required": 1, "value": "'.$barcode->barcode.'" ]}
41+
</div>
42+
</div>
43+
44+
<!-- PULSANTI -->
45+
<div class="row">
46+
<div class="col-md-12">
47+
<button type="button" class="btn btn-danger '.$disabled.'" onclick="rimuoviBarcode(this)">
48+
<i class="fa fa-trash"></i> '.tr('Elimina').'
49+
</button>
50+
51+
<a type="button" class="btn btn-info" href="'.$rootdir.'/pdfgen.php?id_print='.Prints::getPrints()['Barcode'].'&id_record='.$id_parent.'&idbarcode='.$id_record.'" target="_blank"><i class="fa fa-print"></i> '.tr('Stampa barcode').'</a>
52+
<button type="submit" class="btn btn-primary pull-right"><i class="fa fa-edit"></i> '.tr('Modifica').'</button>
53+
</div>
54+
</div>
55+
</form>';
56+
57+
echo '
58+
<script>
59+
function rimuoviBarcode(button) {
60+
let hash = window.location.href.split("#")[1];
61+
62+
confirmDelete(button).then(function () {
63+
redirect(globals.rootdir + "/editor.php", {
64+
backto: "record-edit",
65+
hash: hash,
66+
op: "deletebarcode",
67+
id: "'.$id_record.'",
68+
id_plugin: "'.$id_plugin.'",
69+
id_module: "'.$id_module.'",
70+
id_parent: "'.$id_parent.'",
71+
});
72+
}).catch(swal.noop);
73+
}
74+
75+
function generaBarcode() {
76+
$.ajax({
77+
url: globals.rootdir + "/actions.php",
78+
type: "POST",
79+
data: {
80+
id_module: globals.id_module,
81+
id_record: globals.id_record,
82+
op: "generate-barcode"
83+
},
84+
success: function(response) {
85+
response = JSON.parse(response);
86+
let input = $("#barcode");
87+
input.val(response.barcode);
88+
},
89+
error: function(xhr, status, error) {
90+
}
91+
});
92+
}
93+
94+
$("#generaBarcode").click( function() {
95+
generaBarcode();
96+
});
97+
</script>';

0 commit comments

Comments
 (0)