Skip to content

Commit

Permalink
feat: generazione barcode interno
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoPistorello committed Jan 20, 2025
1 parent 02c1e72 commit 8fe7ecd
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 4 deletions.
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,16 @@
"intervention/image": "^2.3",
"jurosh/pdf-merge": "^2.1",
"league/csv": "^9.7.0",
"league/oauth2-client": "^2.6",
"league/oauth2-google": "^4.0",
"league/flysystem": "^3.0",
"league/flysystem-ftp": "^3.0",
"league/oauth2-client": "^2.6",
"league/oauth2-google": "^4.0",
"monolog/monolog": "^1.27",
"mpdf/mpdf": "^v8.0.10",
"mpociot/vat-calculator": "^2.3",
"owasp/csrf-protector-php": "^1.0",
"phpmailer/phpmailer": "^6.0",
"picqer/php-barcode-generator": "^3.2",
"respect/validation": "^2.0",
"servo/fluidxml": "^2.0",
"slim/flash": "^0.4.0",
Expand Down
17 changes: 16 additions & 1 deletion modules/articoli/actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@
if (Models\Locale::getDefault()->id == Models\Locale::getPredefined()->id) {
$articolo->name = post('descrizione');
}
$articolo->barcode = post('barcode');

if (post('genera_barcode')) {
$codice = "200".str_pad($articolo->id, 9, "0", STR_PAD_LEFT);
$barcode = (new Picqer\Barcode\Types\TypeEan13())->getBarcode($codice)->getBarcode();
}
$articolo->barcode = $barcode ?: post('barcode');
$articolo->coefficiente = post('coefficiente');
$articolo->idiva_vendita = post('idiva_vendita');
$articolo->prezzo_acquisto = post('prezzo_acquisto');
Expand Down Expand Up @@ -455,6 +460,16 @@

flash()->info(tr('Giacenza aggiornata!'));

break;

case 'generate-barcode':
$codice = "200".str_pad($id_record, 9, "0", STR_PAD_LEFT);
$barcode = (new Picqer\Barcode\Types\TypeEan13())->getBarcode($codice)->getBarcode();

echo json_encode([
'barcode' => $barcode
]);

break;
}

Expand Down
5 changes: 5 additions & 0 deletions modules/articoli/add.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
</div>

<div class="col-md-6">
<span class="pull-right tip text-muted"><input type="checkbox" id="genera_barcode" name="genera_barcode" /> <?php echo tr('Generazione automatica'); ?></span>
{[ "type": "text", "label": "<?php echo tr('Barcode'); ?>", "name": "barcode", "required": 0, "value": "<?php echo htmlentities(filter('barcode')) ?: ''; ?>", "validation": "barcode" ]}
</div>
</div>
Expand Down Expand Up @@ -223,4 +224,8 @@ function scorpora_iva_add() {
let scorporato = prezzo * 100 / (100 + percentuale);
input.val(scorporato);
}

$("#genera_barcode").click(function(){
$(".modal #barcode").attr("disabled", $(this).is(":checked")).val("");
});
</script>
25 changes: 25 additions & 0 deletions modules/articoli/bulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,20 @@

flash()->info(tr('Listino aggiornato correttamente!'));

break;

case 'generate-barcode-bulk':
foreach ($id_records as $id) {
$codice = "200".str_pad($id, 9, "0", STR_PAD_LEFT);
$barcode = (new Picqer\Barcode\Types\TypeEan13())->getBarcode($codice)->getBarcode();

$articolo = Articolo::find($id);
$articolo->barcode = $barcode;
$articolo->save();
}

flash()->info(tr('Barcode generati correttamente!'));

break;
}

Expand Down Expand Up @@ -632,4 +646,15 @@
],
];

$operations['generate-barcode-bulk'] = [
'text' => '<span><i class="fa fa-magic"></i> '.tr('Genera barcode').'</span>',
'data' => [
'title' => tr('Generare il barcode per gli articoli selezionati?'),
'msg' => 'Il barcode sarà generato in maniera random con tipologia EAN-13',
'button' => tr('Genera'),
'class' => 'btn btn-lg btn-success',
'blank' => false,
],
];

return $operations;
26 changes: 25 additions & 1 deletion modules/articoli/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
</div>

<div class="col-md-3">
{[ "type": "text", "label": "<?php echo tr('Barcode'); ?>", "name": "barcode", "value": "$barcode$" ]}
<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>
{[ "type": "text", "label": "<?php echo tr('Barcode'); ?>", "name": "barcode", "validation": "barcode", "class": "text-center", "value": "$barcode$" ]}
</div>

<div class="col-md-3">
Expand Down Expand Up @@ -359,6 +360,29 @@ function scorporaIva() {
$("#scorporaIva").click( function() {
scorporaIva();
});

function generaBarcode() {
$.ajax({
url: globals.rootdir + "/actions.php",
type: "POST",
data: {
id_module: globals.id_module,
id_record: globals.id_record,
op: "generate-barcode"
},
success: function(response) {
response = JSON.parse(response);
let input = $("#barcode");
input.val(response.barcode);
},
error: function(xhr, status, error) {
}
});
}

$("#generaBarcode").click( function() {
generaBarcode();
});
</script>


Expand Down

0 comments on commit 8fe7ecd

Please sign in to comment.