Skip to content

Commit 5543b80

Browse files
committed
Ulteriori modifiche modulo Ubicazioni
1 parent 449b2d2 commit 5543b80

File tree

14 files changed

+380
-167
lines changed

14 files changed

+380
-167
lines changed

modules/articoli/actions.php

Lines changed: 16 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@
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');
6570
$articolo->coefficiente = post('coefficiente');
6671
$articolo->idiva_vendita = post('idiva_vendita');
6772
$articolo->prezzo_acquisto = post('prezzo_acquisto');
@@ -71,7 +76,7 @@
7176
$articolo->idconto_vendita = post('idconto_vendita');
7277
$articolo->idconto_acquisto = post('idconto_acquisto');
7378
$articolo->abilita_serial = post('abilita_serial_add');
74-
79+
$articolo->ubicazione = post('ubicazione');
7580
$articolo->um = post('um');
7681
$articolo->um_secondaria = post('um_secondaria');
7782
$articolo->fattore_um_secondaria = post('fattore_um_secondaria');
@@ -92,53 +97,6 @@
9297
$id_record = $articolo->id;
9398
$iva = post('idiva_vendita') ? Aliquota::find(post('idiva_vendita')) : null;
9499

95-
if (post('genera_barcode')) {
96-
// Genera un barcode unico controllando sia la tabella mg_articoli che mg_articoli_barcode
97-
// per evitare conflitti con barcode esistenti sia principali che aggiuntivi
98-
$tentativi = 0;
99-
$max_tentativi = 1000; // Limite massimo di tentativi per evitare loop infiniti
100-
101-
do {
102-
// Genera il codice EAN-13 basato sull'ID dell'articolo più il numero di tentativi
103-
$codice = '200'.str_pad((string) ($articolo->id + $tentativi), 9, '0', STR_PAD_LEFT);
104-
$barcode = (new Picqer\Barcode\Types\TypeEan13())->getBarcode($codice)->getBarcode();
105-
106-
// Controlla se il barcode è già presente nella tabella mg_articoli (barcode principali)
107-
$esistente_articoli = Articolo::where('barcode', $barcode)->count() > 0;
108-
109-
// Controlla se il barcode è già presente nella tabella mg_articoli_barcode (barcode aggiuntivi)
110-
$esistente_barcode = $dbo->table('mg_articoli_barcode')
111-
->where('barcode', $barcode)
112-
->count() > 0;
113-
114-
// Controlla se il barcode coincide con un codice articolo esistente
115-
// per evitare conflitti tra barcode e codici articolo
116-
$coincide_codice = Articolo::where([
117-
['codice', $barcode],
118-
['barcode', '=', '']
119-
])->count() > 0;
120-
121-
$tentativi++;
122-
123-
} while (($esistente_articoli || $esistente_barcode || $coincide_codice) && $tentativi < $max_tentativi);
124-
125-
// Se dopo tutti i tentativi non è stato trovato un barcode unico, non genera il barcode
126-
if ($tentativi >= $max_tentativi) {
127-
$barcode = null;
128-
flash()->warning(tr('Impossibile generare un barcode unico dopo _NUM_ tentativi', [
129-
'_NUM_' => $max_tentativi
130-
]));
131-
}
132-
}
133-
134-
$barcode = ($barcode ? $barcode : post('barcode'));
135-
if (!empty($barcode)) {
136-
$dbo->insert('mg_articoli_barcode', [
137-
'idarticolo' => $id_record,
138-
'barcode' => $barcode,
139-
]);
140-
}
141-
142100
if (isAjaxRequest()) {
143101
echo json_encode([
144102
'id' => $id_record,
@@ -181,9 +139,10 @@
181139
}
182140

183141
$articolo->codice = post('codice', true);
142+
$articolo->barcode = post('barcode');
184143
$articolo->um = post('um');
185-
$articolo->id_categoria = post('categoria_edit') ?: post('categoria');
186-
$articolo->id_sottocategoria = post('subcategoria_edit') ?: post('subcategoria');
144+
$articolo->id_categoria = post('categoria');
145+
$articolo->id_sottocategoria = post('subcategoria');
187146
$articolo->abilita_serial = post('abilita_serial');
188147
$articolo->ubicazione = post('ubicazione');
189148
$articolo->coefficiente = post('coefficiente');
@@ -196,8 +155,8 @@
196155
$articolo->servizio = post('servizio');
197156
$articolo->volume = post('volume');
198157
$articolo->peso_lordo = post('peso_lordo');
199-
$articolo->id_marca = post('id_marca_edit') ?: post('id_marca');
200-
$articolo->id_modello = post('id_modello_edit') ?: post('id_modello');
158+
$articolo->id_marca = post('id_marca');
159+
$articolo->id_modello = post('id_modello');
201160

202161
$articolo->um_secondaria = post('um_secondaria');
203162
$articolo->fattore_um_secondaria = post('fattore_um_secondaria');
@@ -506,48 +465,12 @@
506465
break;
507466

508467
case 'generate-barcode':
509-
// Genera un barcode unico controllando sia la tabella mg_articoli che mg_articoli_barcode
510-
// per garantire l'unicità anche considerando i barcode aggiuntivi degli articoli
511-
$tentativi = 0;
512-
$max_tentativi = 1000; // Limite massimo di tentativi per evitare loop infiniti
513-
514-
do {
515-
// Genera il codice EAN-13 basato sull'ID dell'articolo più il numero di tentativi
516-
$codice = '200'.str_pad((string) ($id_record + $tentativi), 9, '0', STR_PAD_LEFT);
517-
$barcode = (new Picqer\Barcode\Types\TypeEan13())->getBarcode($codice)->getBarcode();
518-
519-
// Controlla se il barcode è già presente nella tabella mg_articoli (barcode principali)
520-
$esistente_articoli = Articolo::where('barcode', $barcode)->count() > 0;
521-
522-
// Controlla se il barcode è già presente nella tabella mg_articoli_barcode (barcode aggiuntivi)
523-
$esistente_barcode = $dbo->table('mg_articoli_barcode')
524-
->where('barcode', $barcode)
525-
->count() > 0;
526-
527-
// Controlla se il barcode coincide con un codice articolo esistente
528-
// per evitare conflitti tra barcode e codici articolo
529-
$coincide_codice = Articolo::where([
530-
['codice', $barcode],
531-
['barcode', '=', '']
532-
])->count() > 0;
468+
$codice = '200'.str_pad((string) $id_record, 9, '0', STR_PAD_LEFT);
469+
$barcode = (new Picqer\Barcode\Types\TypeEan13())->getBarcode($codice)->getBarcode();
533470

534-
$tentativi++;
535-
536-
} while (($esistente_articoli || $esistente_barcode || $coincide_codice) && $tentativi < $max_tentativi);
537-
538-
// Se dopo tutti i tentativi non è stato trovato un barcode unico, restituisce un errore
539-
if ($tentativi >= $max_tentativi) {
540-
echo json_encode([
541-
'error' => tr('Impossibile generare un barcode unico dopo _NUM_ tentativi', [
542-
'_NUM_' => $max_tentativi
543-
])
544-
]);
545-
} else {
546-
// Restituisce il barcode generato con successo
547-
echo json_encode([
548-
'barcode' => $barcode,
549-
]);
550-
}
471+
echo json_encode([
472+
'barcode' => $barcode,
473+
]);
551474

552475
break;
553476
}

modules/articoli/add.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797

9898
<div class="row">
9999
<div class="col-md-4">
100-
{[ "type": "number", "label": "<?php echo tr('Quantità iniziale'); ?>", "name": "qta", "decimals": "qta", "value": "<?php echo htmlentities(filter('qta')) ?: ''; ?>" ]}
100+
{[ "type": "number", "label": "<?php echo tr('Quantità iniziale'); ?>", "name": "qta", "decimals": "qta" ]}
101101
</div>
102102

103103
<div class="col-md-4">
@@ -111,7 +111,7 @@
111111

112112
<div class="row">
113113
<div class="col-md-4">
114-
{[ "type": "select", "label": "<?php echo tr('Unità di misura'); ?>", "name": "um", "value": "<?php echo htmlentities(filter('um')) ?: ''; ?>", "ajax-source": "misure", "icon-after": "add|<?php echo Module::where('name', 'Unità di misura')->first()->id; ?>" ]}
114+
{[ "type": "select", "label": "<?php echo tr('Unità di misura'); ?>", "name": "um", "value": "", "ajax-source": "misure", "icon-after": "add|<?php echo Module::where('name', 'Unità di misura')->first()->id; ?>" ]}
115115
</div>
116116
<div class="col-md-4">
117117
{[ "type": "select", "label": "<?php echo tr('U.m. secondaria'); ?>", "name": "um_secondaria", "value": "", "ajax-source": "misure", "help": "<?php echo tr("Unità di misura da utilizzare nelle stampe di Ordini fornitori in relazione all'articolo"); ?>" ]}
@@ -137,10 +137,11 @@
137137
<input type="hidden" name="aliquota_predefinita" value="<?php echo $aliquota_predefinita; ?>">
138138
</div>
139139
</div>
140-
<!--aggiungo scelta dell'Ubicazione in fase di creazione Nuovo Articolo di Magazzino-->
140+
141+
<!--Aggiungo form inserimento ubicazione-->
141142
<div class="row">
142143
<div class="col-md-4">
143-
{[ "type": "select", "label": "<?php echo tr('Ubicazione'); ?>", "name": "ubicazione", "value": "$ubicazione$", "ajax-source": "ubicaz", "icon-after": "add|<?php echo Module::where('name', 'ubicazioni')->first()->id; ?>" ]}
144+
{[ "type": "select", "label": "<?php echo tr('Ubicazione'); ?>", "name": "ubicazione", "value": "", "ajax-source": "ubicaz" ]}
144145
</div>
145146
</div>
146147
</div>
@@ -262,11 +263,4 @@ function scorpora_iva_add() {
262263
$("#genera_barcode").click(function(){
263264
$(".modal #barcode").attr("disabled", $(this).is(":checked")).val("");
264265
});
265-
266-
// Espandi automaticamente la sezione "Informazioni aggiuntive" se sono precompilati dati dall'ImportFE
267-
$(document).ready(function() {
268-
if (input("prezzo_acquisto").get() > 0 || input("qta").get() > 0 || input("um").get()) {
269-
$(".card.collapsed-card .card-tools button[data-card-widget='collapse']").click();
270-
}
271-
});
272266
</script>

modules/ubicazioni/add.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,8 @@
2727
<div class="col-md-3">
2828
{[ "type": "text", "label": "<?php echo tr('Etichetta'); ?>", "name": "u_label", "required": 1, "value": "$u_label$" ]}
2929
</div>
30-
<!--<div class="col-md-4">
31-
{[ "type": "text", "label": "<?php echo tr('Descrizione'); ?>", "name": "u_label_info", "value": "$u_label_info$" ]}
32-
</div>
33-
<div class="col-md-8">
34-
{[ "type": "text", "label": "<?php echo tr('Note'); ?>", "name": "u_notes", "value": "$u_notes$" ]}
35-
</div>-->
3630
<div class="col-md-4">
37-
{[ "type": "text", "label": "<?php echo tr('Descrizione'); ?>", "name": "title", "value": "$title$" ]}
31+
{[ "type": "text", "label": "<?php echo tr('Descrizione'); ?>", "name": "title", "required": 1, "value": "$title$" ]}
3832
</div>
3933
<div class="col-md-8">
4034
{[ "type": "text", "label": "<?php echo tr('Note'); ?>", "name": "notes", "value": "$notes$" ]}
@@ -68,4 +62,4 @@
6862

6963
$('#modals > div #colore_').parent().find('.square').css('background', $('#modals > div #colore_').val());
7064
});
71-
</script>
65+
</script>

modules/ubicazioni/edit.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,8 @@
3939
<div class="col-md-3">
4040
{[ "type": "text", "label": "<?php echo tr('Etichetta'); ?>", "name": "u_label", "required": 1, "value": "$u_label$" ]}
4141
</div>
42-
<!--<div class="col-md-4">
43-
{[ "type": "text", "label": "<?php echo tr('Descrizione'); ?>", "name": "u_label_info", "value": "$u_label_info$" ]}
44-
</div>
45-
<div class="col-md-8">
46-
{[ "type": "text", "label": "<?php echo tr('Note'); ?>", "name": "u_notes", "value": "$u_notes$" ]}
47-
</div>-->
4842
<div class="col-md-4">
49-
{[ "type": "text", "label": "<?php echo tr('Descrizione'); ?>", "name": "title", "value": "$title$" ]}
43+
{[ "type": "text", "label": "<?php echo tr('Descrizione'); ?>", "name": "title", "required": 1, "value": "$title$" ]}
5044
</div>
5145
<div class="col-md-8">
5246
{[ "type": "text", "label": "<?php echo tr('Note'); ?>", "name": "notes", "value": "$notes$" ]}

templates/ubicazione/body.php

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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+
//use Database;
21+
//use Modules\Ubicazioni;
22+
23+
include_once __DIR__.'/../../core.php';
24+
25+
echo '<style>
26+
.barcode {
27+
padding: 0;
28+
margin: 0;
29+
vertical-align: top;
30+
}
31+
.barcode-cell {
32+
text-align: center;
33+
vertical-align: middle;
34+
}
35+
</style>';
36+
37+
if (!empty($_SESSION['superselect']['id_ubicazione_barcode'])) {
38+
//$records = Ubicazioni::whereIn('id', $_SESSION['superselect']['id_ubicazione_barcode'])->get();
39+
//unset($_SESSION['superselect']['id_ubicazione_barcode']);
40+
} else {
41+
$records = $dbo->fetchOne('SELECT id FROM `mg_ubicazioni` WHERE id='.prepare($id_record));
42+
}
43+
44+
$pages = count($records);
45+
$page = 0;
46+
//$prezzi_ivati = setting('Utilizza prezzi di vendita comprensivi di IVA');
47+
48+
foreach ($records as $record) {
49+
//$row = $dbo->fetchOne('SELECT * FROM `mg_ubicazioni` WHERE id='.prepare($id_record));
50+
//adeguamento a mg_ubicazioni_lang
51+
$row = $dbo->fetchOne('SELECT `mg_ubicazioni`.*, `mg_ubicazioni_lang`.`title` AS title, `mg_ubicazioni_lang`.`notes` FROM `mg_ubicazioni` LEFT JOIN `mg_ubicazioni_lang` ON (`mg_ubicazioni`.`id`=`mg_ubicazioni_lang`.`id_record` AND `mg_ubicazioni_lang`.`id_lang`='.prepare(parameter: Models\Locale::getDefault()->id).') WHERE `mg_ubicazioni`.`id`='.prepare($id_record));
52+
$u_label = $row['u_label'];
53+
$u_title = $row['title'];
54+
if ($u_title == NULL) {
55+
$u_title = "--";
56+
}
57+
//$barcode = strtolower(trim($row['u_label']).trim($u_label_info));
58+
59+
echo '
60+
<div class="barcode-cell">
61+
<p style="font-size:30pt;"><b>'.$u_label.'</b></p>
62+
<p style="font-size:25pt;">'.$u_title.'</p><br>
63+
<!--<p style="font-size:15pt;"><b>'.moneyFormat($prezzi_ivati ? $articolo->prezzo_vendita_ivato : $articolo->prezzo_vendita).'</b></p>-->
64+
<!--<barcode code="'.$barcode.'" type="C39" height="2" size="0.65" class="barcode" />-->
65+
<!--<p><b>'.$barcode.'</b></p>-->
66+
</div>';
67+
68+
++$page;
69+
70+
if ($page < $pages) {
71+
echo '<pagebreak>';
72+
}
73+
}
74+

templates/ubicazione/footer.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
echo '
21+
';

templates/ubicazione/header.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
echo '
21+
';

templates/ubicazione/init.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
//use Modules\Articoli\Articolo;
23+
24+
//$record_modulo_ubicazione = Articolo::find($id_record);
25+
/*
26+
if (!empty($id_record)) {
27+
$record = $dbo->fetchOne('SELECT * FROM `mg_ubicazioni` WHERE id='.prepare($id_record));
28+
}
29+
*/

0 commit comments

Comments
 (0)