Difference between revisions of "Module Codes Barre (développeur)"
Jump to navigation
Jump to search
PolyglotBot (talk | contribs) m (Updating interlang links (links to translated versions of this page in other languages) triggered by origin English page "Module_Barcode_(developer)" update.) |
m (→Code PHP) Tag: 2017 source edit |
||
Line 37: | Line 37: | ||
= Code PHP = | = Code PHP = | ||
− | Pour générer une image d'un code | + | Pour générer une image d'un bar code ou d'un QR code, vous pouvez utiliser la portion de code suivant: |
<syntaxhighlight lang="php"> | <syntaxhighlight lang="php"> | ||
− | + | $code = 'string_to_convert_into_qrcode'; | |
+ | $generator = 'tcpdfbarcode'; // Can be 'phpbarcode' or a value provided by an external module | ||
+ | $encoding = 'QRCODE'; | ||
+ | |||
+ | $dirbarcode = array_merge(array("/core/modules/barcode/doc/"), $conf->modules_parts['barcode']); | ||
+ | |||
+ | $result = 0; | ||
+ | foreach ($dirbarcode as $reldir) { | ||
+ | $dir = dol_buildpath($reldir, 0); | ||
+ | $newdir = dol_osencode($dir); | ||
+ | |||
+ | // Check if directory exists (we do not use dol_is_dir to avoid loading files.lib.php) | ||
+ | if (!is_dir($newdir)) { | ||
+ | continue; | ||
+ | } | ||
+ | |||
+ | $result = @include_once $newdir.$generator.'.modules.php'; | ||
+ | if ($result) { | ||
+ | break; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // Load barcode class | ||
+ | $classname = "mod".ucfirst($generator); | ||
+ | $module = new $classname($db); | ||
+ | if ($module->encodingIsSupported($encoding)) { | ||
+ | $result = $module->writeBarCode($code, $encoding, $readable); | ||
+ | } | ||
+ | // image is into file $conf->barcode->dir_temp . '/barcode_' . $code . '_' . $encoding . '.png'; | ||
</syntaxhighlight> | </syntaxhighlight> |
Revision as of 20:41, 31 March 2024
Barcode | |
---|---|
Numéro/ID du module | 55 |
Doc utilisateur du module | Module Codes Barre |
Doc développeur du module | Cette page |
Fonction
Gestion des codes barre. Ce module permet d'ajouter la possibilité de saisir une valeur de code barre sur les produits ou les tiers.
Permissions
- ->barcode->lire
- ->barcode->creer
- ->barcode->supprimer
Tables SQL
Aucune. Le code barre est en général un code stocké au niveau de la propriété (dans la table Produit par exemple)
Code PHP
Pour générer une image d'un bar code ou d'un QR code, vous pouvez utiliser la portion de code suivant:
$code = 'string_to_convert_into_qrcode';
$generator = 'tcpdfbarcode'; // Can be 'phpbarcode' or a value provided by an external module
$encoding = 'QRCODE';
$dirbarcode = array_merge(array("/core/modules/barcode/doc/"), $conf->modules_parts['barcode']);
$result = 0;
foreach ($dirbarcode as $reldir) {
$dir = dol_buildpath($reldir, 0);
$newdir = dol_osencode($dir);
// Check if directory exists (we do not use dol_is_dir to avoid loading files.lib.php)
if (!is_dir($newdir)) {
continue;
}
$result = @include_once $newdir.$generator.'.modules.php';
if ($result) {
break;
}
}
// Load barcode class
$classname = "mod".ucfirst($generator);
$module = new $classname($db);
if ($module->encodingIsSupported($encoding)) {
$result = $module->writeBarCode($code, $encoding, $readable);
}
// image is into file $conf->barcode->dir_temp . '/barcode_' . $code . '_' . $encoding . '.png';