2
0
forked from Wavyzz/dolibarr

code syntax

This commit is contained in:
Frédéric FRANCE
2021-02-22 19:05:32 +01:00
parent 5199e3da5b
commit bb276566c6
2 changed files with 90 additions and 115 deletions

View File

@@ -52,27 +52,21 @@ $maxperinit = 1000;
*/
// Define barcode template for products
if (!empty($conf->global->BARCODE_PRODUCT_ADDON_NUM))
{
if (!empty($conf->global->BARCODE_PRODUCT_ADDON_NUM)) {
$dirbarcodenum = array_merge(array('/core/modules/barcode/'), $conf->modules_parts['barcode']);
foreach ($dirbarcodenum as $dirroot)
{
foreach ($dirbarcodenum as $dirroot) {
$dir = dol_buildpath($dirroot, 0);
$handle = @opendir($dir);
if (is_resource($handle))
{
while (($file = readdir($handle)) !== false)
{
if (preg_match('/^mod_barcode_product_.*php$/', $file))
{
if (is_resource($handle)) {
while (($file = readdir($handle)) !== false) {
if (preg_match('/^mod_barcode_product_.*php$/', $file)) {
$file = substr($file, 0, dol_strlen($file) - 4);
try {
dol_include_once($dirroot.$file.'.php');
} catch (Exception $e)
{
} catch (Exception $e) {
dol_syslog($e->getMessage(), LOG_ERR);
}
@@ -85,28 +79,23 @@ if (!empty($conf->global->BARCODE_PRODUCT_ADDON_NUM))
}
}
if ($action == 'initbarcodeproducts')
{
if (!is_object($modBarCodeProduct))
{
if ($action == 'initbarcodeproducts') {
if (!is_object($modBarCodeProduct)) {
$error++;
setEventMessages($langs->trans("NoBarcodeNumberingTemplateDefined"), null, 'errors');
}
if (!$error)
{
if (!$error) {
$productstatic = new Product($db);
$db->begin();
$nbok = 0;
if (!empty($eraseallbarcode))
{
if (!empty($eraseallbarcode)) {
$sql = "UPDATE ".MAIN_DB_PREFIX."product";
$sql .= " SET barcode = NULL";
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
setEventMessages($langs->trans("AllBarcodeReset"), null, 'mesgs');
} else {
$error++;
@@ -121,16 +110,13 @@ if ($action == 'initbarcodeproducts')
dol_syslog("codeinit", LOG_DEBUG);
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
$i = 0; $nbok = $nbtry = 0;
while ($i < min($num, $maxperinit))
{
while ($i < min($num, $maxperinit)) {
$obj = $db->fetch_object($resql);
if ($obj)
{
if ($obj) {
$productstatic->id = $obj->rowid;
$productstatic->ref = $obj->ref;
$productstatic->type = $obj->fk_product_type;
@@ -140,7 +126,9 @@ if ($action == 'initbarcodeproducts')
$result = $productstatic->setValueFrom('barcode', $nextvalue, '', '', 'text', '', $user, 'PRODUCT_MODIFY');
$nbtry++;
if ($result > 0) $nbok++;
if ($result > 0) {
$nbok++;
}
}
$i++;
@@ -150,14 +138,12 @@ if ($action == 'initbarcodeproducts')
dol_print_error($db);
}
if (!$error)
{
if (!$error) {
setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
}
}
if (!$error)
{
if (!$error) {
//$db->rollback();
$db->commit();
} else {
@@ -174,8 +160,12 @@ if ($action == 'initbarcodeproducts')
* View
*/
if (!$user->admin) accessforbidden();
if (empty($conf->barcode->enabled)) accessforbidden();
if (!$user->admin) {
accessforbidden();
}
if (empty($conf->barcode->enabled)) {
accessforbidden();
}
$form = new Form($db);
@@ -198,8 +188,7 @@ print '<input type="hidden" name="token" value="'.newToken().'">';
print '<br>';
// For thirdparty
if ($conf->societe->enabled)
{
if ($conf->societe->enabled) {
$nbno = $nbtotal = 0;
print load_fiche_titre($langs->trans("BarcodeInitForThirdparties"), '', 'company');
@@ -207,19 +196,21 @@ if ($conf->societe->enabled)
print '<br>'."\n";
$sql = "SELECT count(rowid) as nb FROM ".MAIN_DB_PREFIX."societe where barcode IS NULL or barcode = ''";
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$obj = $db->fetch_object($resql);
$nbno = $obj->nb;
} else dol_print_error($db);
} else {
dol_print_error($db);
}
$sql = "SELECT count(rowid) as nb FROM ".MAIN_DB_PREFIX."societe";
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$obj = $db->fetch_object($resql);
$nbtotal = $obj->nb;
} else dol_print_error($db);
} else {
dol_print_error($db);
}
print $langs->trans("CurrentlyNWithoutBarCode", $nbno, $nbtotal, $langs->transnoentitiesnoconv("ThirdParties")).'<br>'."\n";
@@ -231,8 +222,7 @@ if ($conf->societe->enabled)
// For products
if ($conf->product->enabled || $conf->product->service)
{
if ($conf->product->enabled || $conf->product->service) {
// Example 1 : Adding jquery code
print '<script type="text/javascript" language="javascript">
function confirm_erase() {
@@ -251,32 +241,32 @@ if ($conf->product->enabled || $conf->product->service)
$sql .= " GROUP BY fk_product_type, datec";
$sql .= " ORDER BY datec";
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
while ($i < $num)
{
while ($i < $num) {
$obj = $db->fetch_object($resql);
$nbno += $obj->nb;
$i++;
}
} else dol_print_error($db);
} else {
dol_print_error($db);
}
$sql = "SELECT count(rowid) as nb FROM ".MAIN_DB_PREFIX."product";
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$obj = $db->fetch_object($resql);
$nbtotal = $obj->nb;
} else dol_print_error($db);
} else {
dol_print_error($db);
}
print $langs->trans("CurrentlyNWithoutBarCode", $nbno, $nbtotal, $langs->transnoentitiesnoconv("ProductsOrServices")).'<br>'."\n";
if (is_object($modBarCodeProduct))
{
if (is_object($modBarCodeProduct)) {
print $langs->trans("BarCodeNumberManager").": ";
$objproduct = new Product($db);
print '<b>'.(isset($modBarCodeProduct->name) ? $modBarCodeProduct->name : $modBarCodeProduct->nom).'</b> - '.$langs->trans("NextValue").': <b>'.$modBarCodeProduct->getNextValue($objproduct).'</b><br>';
@@ -286,8 +276,7 @@ if ($conf->product->enabled || $conf->product->service)
$titleno = $langs->trans("NoBarcodeNumberingTemplateDefined");
print '<font class="warning">'.$langs->trans("NoBarcodeNumberingTemplateDefined").'</font> (<a href="'.DOL_URL_ROOT.'/admin/barcode.php">'.$langs->trans("ToGenerateCodeDefineAutomaticRuleFirst").'</a>)<br>';
}
if (empty($nbno))
{
if (empty($nbno)) {
$disabled1 = 1;
}