Maxi debug of barcode feature.

New: Barcode format and mandatory requirement is checked.
New: Start to add new page for barcode init.
This commit is contained in:
Laurent Destailleur 2014-02-19 01:51:19 +01:00
parent 03d056319c
commit 2e67bbc382
8 changed files with 506 additions and 324 deletions

View File

@ -110,12 +110,12 @@ class MenuManager
// Modules system tools // Modules system tools
// TODO Find a way to add parent menu only if child menu exists. For the moment, no other method than hard coded methods. // TODO Find a way to add parent menu only if child menu exists. For the moment, no other method than hard coded methods.
if (! empty($conf->product->enabled) || ! empty($conf->service->enabled) || ! empty($conf->barcode->enabled) // TODO We should enabled module system tools entry without hardcoded test on some modules if (! empty($conf->product->enabled) || ! empty($conf->service->enabled) || ! empty($conf->barcode->enabled) // TODO We should enabled module system tools entry without hardcoded test, but when at least one modules bringing such entries are on
|| ! empty($conf->global->MAIN_MENU_ENABLE_MODULETOOLS)) || ! empty($conf->global->MAIN_MENU_ENABLE_MODULETOOLS))
{ {
if (empty($user->societe_id)) if (empty($user->societe_id))
{ {
if ($leftmenu=="modulesadmintools" && $user->admin) if ((! empty($conf->product->enabled) || ! empty($conf->service->enabled)) && ($leftmenu=="modulesadmintools" && $user->admin))
{ {
$langs->load("products"); $langs->load("products");
$array_menu_product=array( $array_menu_product=array(
@ -133,24 +133,6 @@ class MenuManager
); );
array_unshift($tabMenu,$array_menu_product); // add at beginning of array array_unshift($tabMenu,$array_menu_product); // add at beginning of array
} }
if ($leftmenu=="modulesadmintools" && $user->admin)
{
$langs->load("admin");
$array_menu_product=array(
'url'=>"/barcode/codeinit.php?mainmenu=home&leftmenu=modulesadmintools",
'titre'=>$langs->trans("MassBarcodeInit"),
'enabled'=>($user->admin?true:false),
'perms'=>($user->admin?true:false),
'fk_mainmenu'=>'home',
'fk_leftmenu'=>'modulesadmintools',
'fk_menu'=>-1,
'mainmenu'=>'home',
'leftmenu'=>'modulesadmintools_massbarcode',
'type'=>'left',
'position'=>21
);
array_unshift($tabMenu,$array_menu_product); // add at beginning of array
}
// Main menu title // Main menu title
$array_menu_product=array( $array_menu_product=array(
'url'=>"/admin/tools/index.php?mainmenu=home&leftmenu=modulesadmintools", 'url'=>"/admin/tools/index.php?mainmenu=home&leftmenu=modulesadmintools",

View File

@ -539,7 +539,7 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu
} }
// Modules system tools // Modules system tools
if (! empty($conf->product->enabled) || ! empty($conf->service->enabled) || ! empty($conf->barcode->enabled) // TODO We should enabled module system tools entry without hardcoded test on some modules if (! empty($conf->product->enabled) || ! empty($conf->service->enabled) || ! empty($conf->barcode->enabled) // TODO We should enabled module system tools entry without hardcoded test, but when at least one modules bringing such entries are on
|| ! empty($conf->global->MAIN_MENU_ENABLE_MODULETOOLS)) // Some external modules may need to force to have this entry on. || ! empty($conf->global->MAIN_MENU_ENABLE_MODULETOOLS)) // Some external modules may need to force to have this entry on.
{ {
if (empty($user->societe_id)) if (empty($user->societe_id))

View File

@ -190,15 +190,29 @@ class mod_barcode_product_standard extends ModeleNumRefBarCode
} }
else else
{ {
// Get Mask value if ($this->verif_syntax($code) >= 0)
$mask = empty($conf->global->BARCODE_STANDARD_PRODUCT_MASK)?'':$conf->global->BARCODE_STANDARD_PRODUCT_MASK;
if (! $mask)
{ {
$this->error='NotConfigured'; $is_dispo = $this->verif_dispo($db, $code, $product);
return ''; if ($is_dispo <> 0)
{
$result=-3;
}
else
{
$result=0;
}
}
else
{
if (dol_strlen($code) == 0)
{
$result=-2;
}
else
{
$result=-1;
}
} }
$result=check_value($mask,$code);
} }
dol_syslog(get_class($this)."::verif type=".$type." result=".$result); dol_syslog(get_class($this)."::verif type=".$type." result=".$result);
@ -216,8 +230,8 @@ class mod_barcode_product_standard extends ModeleNumRefBarCode
*/ */
function verif_dispo($db, $code, $product) function verif_dispo($db, $code, $product)
{ {
$sql = "SELECT ref FROM ".MAIN_DB_PREFIX."product"; $sql = "SELECT barcode FROM ".MAIN_DB_PREFIX."product";
$sql.= " WHERE ref = '".$code."'"; $sql.= " WHERE barcode = '".$code."'";
if ($product->id > 0) $sql.= " AND rowid <> ".$product->id; if ($product->id > 0) $sql.= " AND rowid <> ".$product->id;
$resql=$db->query($sql); $resql=$db->query($sql);
@ -239,6 +253,31 @@ class mod_barcode_product_standard extends ModeleNumRefBarCode
} }
/**
* Renvoi si un code respecte la syntaxe
*
* @param string $code Code a verifier
* @return int 0 if OK, <0 if KO
*/
function verif_syntax($code)
{
global $conf;
$res = 0;
// Get Mask value
$mask = empty($conf->global->BARCODE_STANDARD_PRODUCT_MASK)?'':$conf->global->BARCODE_STANDARD_PRODUCT_MASK;
if (! $mask)
{
$this->error='NotConfigured';
return '';
}
$result=check_value($mask,$code);
return $result;
}
} }
?> ?>

View File

@ -26,8 +26,11 @@ ErrorFromToAccountsMustDiffers=Source and targets bank accounts must be differen
ErrorBadThirdPartyName=Bad value for third party name ErrorBadThirdPartyName=Bad value for third party name
ErrorProdIdIsMandatory=The %s is mandatory ErrorProdIdIsMandatory=The %s is mandatory
ErrorBadCustomerCodeSyntax=Bad syntax for customer code ErrorBadCustomerCodeSyntax=Bad syntax for customer code
ErrorBadBarCodeSyntax=Bad syntax for bar code
ErrorCustomerCodeRequired=Customer code required ErrorCustomerCodeRequired=Customer code required
ErrorBarCodeRequired=Bar code required
ErrorCustomerCodeAlreadyUsed=Customer code already used ErrorCustomerCodeAlreadyUsed=Customer code already used
ErrorBarCodeAlreadyUsed=Bar code already used
ErrorPrefixRequired=Prefix required ErrorPrefixRequired=Prefix required
ErrorUrlNotValid=The website address is incorrect ErrorUrlNotValid=The website address is incorrect
ErrorBadSupplierCodeSyntax=Bad syntax for supplier code ErrorBadSupplierCodeSyntax=Bad syntax for supplier code

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2013 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2013 Regis Houssin <regis.houssin@capnetworks.com> * Copyright (C) 2005-2013 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr> * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
* Copyright (C) 2007-2011 Jean Heimburger <jean@tiaris.info> * Copyright (C) 2007-2011 Jean Heimburger <jean@tiaris.info>
@ -202,7 +202,7 @@ class Product extends CommonObject
* *
* @param User $user User making insert * @param User $user User making insert
* @param int $notrigger Disable triggers * @param int $notrigger Disable triggers
* @return int Id of product/service if OK or number of error < 0 * @return int Id of product/service if OK, < 0 if KO
*/ */
function create($user,$notrigger=0) function create($user,$notrigger=0)
{ {
@ -300,141 +300,230 @@ class Product extends CommonObject
// For automatic creation during create action (not used by Dolibarr GUI, can be used by scripts) // For automatic creation during create action (not used by Dolibarr GUI, can be used by scripts)
if ($this->barcode == -1) $this->get_barcode($this,$this->barcode_type_code); if ($this->barcode == -1) $this->get_barcode($this,$this->barcode_type_code);
$sql = "SELECT count(*) as nb"; // Check more parameters
$sql.= " FROM ".MAIN_DB_PREFIX."product"; // If error, this->errors[] is filled
$sql.= " WHERE entity IN (".getEntity('product', 1).")"; $result = $this->verify();
$sql.= " AND ref = '" .$this->ref."'";
$result = $this->db->query($sql); if ($result >= 0)
if ($result) {
{ $sql = "SELECT count(*) as nb";
$obj = $this->db->fetch_object($result); $sql.= " FROM ".MAIN_DB_PREFIX."product";
if ($obj->nb == 0) $sql.= " WHERE entity IN (".getEntity('product', 1).")";
$sql.= " AND ref = '" .$this->ref."'";
$result = $this->db->query($sql);
if ($result)
{ {
// Produit non deja existant $obj = $this->db->fetch_object($result);
$sql = "INSERT INTO ".MAIN_DB_PREFIX."product ("; if ($obj->nb == 0)
$sql.= "datec";
$sql.= ", entity";
$sql.= ", ref";
$sql.= ", ref_ext";
$sql.= ", price_min";
$sql.= ", price_min_ttc";
$sql.= ", label";
$sql.= ", fk_user_author";
$sql.= ", fk_product_type";
$sql.= ", price";
$sql.= ", price_ttc";
$sql.= ", price_base_type";
$sql.= ", tobuy";
$sql.= ", tosell";
$sql.= ", accountancy_code_buy";
$sql.= ", accountancy_code_sell";
$sql.= ", canvas";
$sql.= ", finished";
$sql.= ") VALUES (";
$sql.= "'".$this->db->idate($now)."'";
$sql.= ", ".$conf->entity;
$sql.= ", '".$this->db->escape($this->ref)."'";
$sql.= ", ".(! empty($this->ref_ext)?"'".$this->db->escape($this->ref_ext)."'":"null");
$sql.= ", ".price2num($price_min_ht);
$sql.= ", ".price2num($price_min_ttc);
$sql.= ", ".(! empty($this->libelle)?"'".$this->db->escape($this->libelle)."'":"null");
$sql.= ", ".$user->id;
$sql.= ", ".$this->type;
$sql.= ", ".price2num($price_ht);
$sql.= ", ".price2num($price_ttc);
$sql.= ", '".$this->price_base_type."'";
$sql.= ", ".$this->status;
$sql.= ", ".$this->status_buy;
$sql.= ", '".$this->accountancy_code_buy."'";
$sql.= ", '".$this->accountancy_code_sell."'";
$sql.= ", '".$this->canvas."'";
$sql.= ", ".((! isset($this->finished) || $this->finished < 0 || $this->finished == '') ? 'null' : $this->finished);
$sql.= ")";
dol_syslog(get_class($this)."::Create sql=".$sql);
$result = $this->db->query($sql);
if ( $result )
{ {
$id = $this->db->last_insert_id(MAIN_DB_PREFIX."product"); // Produit non deja existant
$sql = "INSERT INTO ".MAIN_DB_PREFIX."product (";
$sql.= "datec";
$sql.= ", entity";
$sql.= ", ref";
$sql.= ", ref_ext";
$sql.= ", price_min";
$sql.= ", price_min_ttc";
$sql.= ", label";
$sql.= ", fk_user_author";
$sql.= ", fk_product_type";
$sql.= ", price";
$sql.= ", price_ttc";
$sql.= ", price_base_type";
$sql.= ", tobuy";
$sql.= ", tosell";
$sql.= ", accountancy_code_buy";
$sql.= ", accountancy_code_sell";
$sql.= ", canvas";
$sql.= ", finished";
$sql.= ") VALUES (";
$sql.= "'".$this->db->idate($now)."'";
$sql.= ", ".$conf->entity;
$sql.= ", '".$this->db->escape($this->ref)."'";
$sql.= ", ".(! empty($this->ref_ext)?"'".$this->db->escape($this->ref_ext)."'":"null");
$sql.= ", ".price2num($price_min_ht);
$sql.= ", ".price2num($price_min_ttc);
$sql.= ", ".(! empty($this->libelle)?"'".$this->db->escape($this->libelle)."'":"null");
$sql.= ", ".$user->id;
$sql.= ", ".$this->type;
$sql.= ", ".price2num($price_ht);
$sql.= ", ".price2num($price_ttc);
$sql.= ", '".$this->price_base_type."'";
$sql.= ", ".$this->status;
$sql.= ", ".$this->status_buy;
$sql.= ", '".$this->accountancy_code_buy."'";
$sql.= ", '".$this->accountancy_code_sell."'";
$sql.= ", '".$this->canvas."'";
$sql.= ", ".((! isset($this->finished) || $this->finished < 0 || $this->finished == '') ? 'null' : $this->finished);
$sql.= ")";
if ($id > 0) dol_syslog(get_class($this)."::Create sql=".$sql);
$result = $this->db->query($sql);
if ( $result )
{ {
$this->id = $id; $id = $this->db->last_insert_id(MAIN_DB_PREFIX."product");
$this->price = $price_ht;
$this->price_ttc = $price_ttc;
$this->price_min = $price_min_ht;
$this->price_min_ttc = $price_min_ttc;
$result = $this->_log_price($user); if ($id > 0)
if ($result > 0)
{ {
if ($this->update($id, $user, true, 'add') <= 0) $this->id = $id;
$this->price = $price_ht;
$this->price_ttc = $price_ttc;
$this->price_min = $price_min_ht;
$this->price_min_ttc = $price_min_ttc;
$result = $this->_log_price($user);
if ($result > 0)
{ {
$error++; if ($this->update($id, $user, true, 'add') <= 0)
{
$error++;
}
}
else
{
$error++;
$this->error=$this->db->lasterror();
} }
} }
else else
{ {
$error++; $error++;
$this->error=$this->db->lasterror(); $this->error='ErrorFailedToGetInsertedId';
} }
} }
else else
{ {
$error++; $error++;
$this->error='ErrorFailedToGetInsertedId'; $this->error=$this->db->lasterror();
} }
} }
else else
{ {
// Product already exists with this ref
$langs->load("products");
$error++; $error++;
$this->error=$this->db->lasterror(); $this->error = "ErrorProductAlreadyExists";
} }
} }
else else
{ {
// Product already exists with this ref
$langs->load("products");
$error++; $error++;
$this->error = "ErrorProductAlreadyExists"; $this->error=$this->db->lasterror();
} }
}
else
{
$error++;
$this->error=$this->db->lasterror();
}
if (! $error && ! $notrigger) if (! $error && ! $notrigger)
{ {
// Appel des triggers // Appel des triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
$interface=new Interfaces($this->db); $interface=new Interfaces($this->db);
$result=$interface->run_triggers('PRODUCT_CREATE',$this,$user,$langs,$conf); $result=$interface->run_triggers('PRODUCT_CREATE',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; } if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers // Fin appel triggers
} }
if (! $error)
{
$this->db->commit();
return $this->id;
}
else
{
$this->db->rollback();
return -$error;
}
}
else
{
$this->db->rollback();
dol_syslog(get_class($this)."::Create fails verify ".join(',',$this->errors), LOG_WARNING);
return -3;
}
if (! $error)
{
$this->db->commit();
return $this->id;
}
else
{
$this->db->rollback();
return -$error;
}
} }
/**
* Check properties of product are ok (like name, barcode, ...)
*
* @return int 0 if OK, <0 if KO
*/
function verify()
{
$this->errors=array();
$result = 0;
$this->ref = trim($this->ref);
if (! $this->ref)
{
$this->errors[] = 'ErrorBadRef';
$result = -2;
}
$rescode = $this->check_barcode($this->barcode);
if ($rescode <> 0)
{
if ($rescode == -1)
{
$this->errors[] = 'ErrorBadBarCodeSyntax';
}
if ($rescode == -2)
{
$this->errors[] = 'ErrorBarCodeRequired';
}
if ($rescode == -3)
{
$this->errors[] = 'ErrorBarCodeAlreadyUsed';
}
$result = -3;
}
return $result;
}
/**
* Check customer code
*
* @param string $valuetotest Value to test
* @return int 0 if OK
* -1 ErrorBadBarCodeSyntax
* -2 ErrorBarCodeRequired
* -3 ErrorBarCodeAlreadyUsed
*/
function check_barcode($valuetotest)
{
global $conf;
if (! empty($conf->barcode->enabled) && ! empty($conf->global->BARCODE_PRODUCT_ADDON_NUM))
{
$module=strtolower($conf->global->BARCODE_PRODUCT_ADDON_NUM);
$dirsociete=array_merge(array('/core/modules/barcode/'),$conf->modules_parts['barcode']);
foreach ($dirsociete as $dirroot)
{
$res=dol_include_once($dirroot.$module.'.php');
if ($res) break;
}
$mod = new $module();
dol_syslog(get_class($this)."::check_barcode barcode=".$valuetotest." module=".$module);
$result = $mod->verif($this->db, $valuetotest, $this, 0);
return $result;
}
else
{
return 0;
}
}
/** /**
* Update a record into database * Update a record into database
* *
* @param int $id Id of product * @param int $id Id of product
* @param User $user Object user making update * @param User $user Object user making update
* @param int $notrigger Disable triggers * @param int $notrigger Disable triggers
* @param string $action Current action for hookmanager * @param string $action Current action for hookmanager ('add' or 'update')
* @return int 1 if OK, -1 if ref already exists, -2 if other error * @return int 1 if OK, -1 if ref already exists, -2 if other error
*/ */
function update($id, $user, $notrigger=false, $action='update') function update($id, $user, $notrigger=false, $action='update')
@ -443,9 +532,7 @@ class Product extends CommonObject
$error=0; $error=0;
$this->db->begin(); // Check parameters
// Verification parametres
if (! $this->libelle) $this->libelle = 'MISSING LABEL'; if (! $this->libelle) $this->libelle = 'MISSING LABEL';
// Clean parameters // Clean parameters
@ -473,135 +560,154 @@ class Product extends CommonObject
//Gencod //Gencod
$this->barcode=trim($this->barcode); $this->barcode=trim($this->barcode);
// For automatic creation
if ($this->barcode == -1) $this->get_barcode($this,$this->barcode_type_code);
$this->accountancy_code_buy = trim($this->accountancy_code_buy); $this->accountancy_code_buy = trim($this->accountancy_code_buy);
$this->accountancy_code_sell= trim($this->accountancy_code_sell); $this->accountancy_code_sell= trim($this->accountancy_code_sell);
$sql = "UPDATE ".MAIN_DB_PREFIX."product";
$sql.= " SET label = '" . $this->db->escape($this->libelle) ."'";
$sql.= ", ref = '" . $this->ref ."'";
$sql.= ", ref_ext = ".(! empty($this->ref_ext)?"'".$this->db->escape($this->ref_ext)."'":"null");
$sql.= ", tva_tx = " . $this->tva_tx;
$sql.= ", recuperableonly = " . $this->tva_npr;
$sql.= ", localtax1_tx = " . $this->localtax1_tx;
$sql.= ", localtax2_tx = " . $this->localtax2_tx;
$sql.= ", barcode = ". (empty($this->barcode)?"null":"'".$this->db->escape($this->barcode)."'"); $this->db->begin();
$sql.= ", fk_barcode_type = ". (empty($this->barcode_type)?"null":$this->db->escape($this->barcode_type));
$sql.= ", tosell = " . $this->status; // Check name is required and codes are ok or unique.
$sql.= ", tobuy = " . $this->status_buy; // If error, this->errors[] is filled
$sql.= ", finished = " . ((! isset($this->finished) || $this->finished < 0) ? "null" : $this->finished); if ($action != 'add')
$sql.= ", weight = " . ($this->weight!='' ? "'".$this->weight."'" : 'null'); {
$sql.= ", weight_units = " . ($this->weight_units!='' ? "'".$this->weight_units."'": 'null'); $result = $this->verify(); // We don't check when update called during a create because verify was already done
$sql.= ", length = " . ($this->length!='' ? "'".$this->length."'" : 'null'); }
$sql.= ", length_units = " . ($this->length_units!='' ? "'".$this->length_units."'" : 'null');
$sql.= ", surface = " . ($this->surface!='' ? "'".$this->surface."'" : 'null');
$sql.= ", surface_units = " . ($this->surface_units!='' ? "'".$this->surface_units."'" : 'null');
$sql.= ", volume = " . ($this->volume!='' ? "'".$this->volume."'" : 'null');
$sql.= ", volume_units = " . ($this->volume_units!='' ? "'".$this->volume_units."'" : 'null');
$sql.= ", seuil_stock_alerte = " . ((isset($this->seuil_stock_alerte) && $this->seuil_stock_alerte != '') ? "'".$this->seuil_stock_alerte."'" : "null");
$sql.= ", description = '" . $this->db->escape($this->description) ."'";
$sql.= ", customcode = '" . $this->db->escape($this->customcode) ."'";
$sql.= ", fk_country = " . ($this->country_id > 0 ? $this->country_id : 'null');
$sql.= ", note = '" . $this->db->escape($this->note) ."'";
$sql.= ", duration = '" . $this->duration_value . $this->duration_unit ."'";
$sql.= ", accountancy_code_buy = '" . $this->accountancy_code_buy."'";
$sql.= ", accountancy_code_sell= '" . $this->accountancy_code_sell."'";
$sql.= ", desiredstock = " . ((isset($this->desiredstock) && $this->desiredstock != '') ? $this->desiredstock : "null");
$sql.= " WHERE rowid = " . $id;
dol_syslog(get_class($this)."update sql=".$sql); if ($result >= 0)
$resql=$this->db->query($sql); {
if ($resql) // For automatic creation
{ if ($this->barcode == -1) $this->get_barcode($this,$this->barcode_type_code);
$this->id = $id;
// Multilangs $sql = "UPDATE ".MAIN_DB_PREFIX."product";
if (! empty($conf->global->MAIN_MULTILANGS)) $sql.= " SET label = '" . $this->db->escape($this->libelle) ."'";
$sql.= ", ref = '" . $this->ref ."'";
$sql.= ", ref_ext = ".(! empty($this->ref_ext)?"'".$this->db->escape($this->ref_ext)."'":"null");
$sql.= ", tva_tx = " . $this->tva_tx;
$sql.= ", recuperableonly = " . $this->tva_npr;
$sql.= ", localtax1_tx = " . $this->localtax1_tx;
$sql.= ", localtax2_tx = " . $this->localtax2_tx;
$sql.= ", barcode = ". (empty($this->barcode)?"null":"'".$this->db->escape($this->barcode)."'");
$sql.= ", fk_barcode_type = ". (empty($this->barcode_type)?"null":$this->db->escape($this->barcode_type));
$sql.= ", tosell = " . $this->status;
$sql.= ", tobuy = " . $this->status_buy;
$sql.= ", finished = " . ((! isset($this->finished) || $this->finished < 0) ? "null" : $this->finished);
$sql.= ", weight = " . ($this->weight!='' ? "'".$this->weight."'" : 'null');
$sql.= ", weight_units = " . ($this->weight_units!='' ? "'".$this->weight_units."'": 'null');
$sql.= ", length = " . ($this->length!='' ? "'".$this->length."'" : 'null');
$sql.= ", length_units = " . ($this->length_units!='' ? "'".$this->length_units."'" : 'null');
$sql.= ", surface = " . ($this->surface!='' ? "'".$this->surface."'" : 'null');
$sql.= ", surface_units = " . ($this->surface_units!='' ? "'".$this->surface_units."'" : 'null');
$sql.= ", volume = " . ($this->volume!='' ? "'".$this->volume."'" : 'null');
$sql.= ", volume_units = " . ($this->volume_units!='' ? "'".$this->volume_units."'" : 'null');
$sql.= ", seuil_stock_alerte = " . ((isset($this->seuil_stock_alerte) && $this->seuil_stock_alerte != '') ? "'".$this->seuil_stock_alerte."'" : "null");
$sql.= ", description = '" . $this->db->escape($this->description) ."'";
$sql.= ", customcode = '" . $this->db->escape($this->customcode) ."'";
$sql.= ", fk_country = " . ($this->country_id > 0 ? $this->country_id : 'null');
$sql.= ", note = '" . $this->db->escape($this->note) ."'";
$sql.= ", duration = '" . $this->duration_value . $this->duration_unit ."'";
$sql.= ", accountancy_code_buy = '" . $this->accountancy_code_buy."'";
$sql.= ", accountancy_code_sell= '" . $this->accountancy_code_sell."'";
$sql.= ", desiredstock = " . ((isset($this->desiredstock) && $this->desiredstock != '') ? $this->desiredstock : "null");
$sql.= " WHERE rowid = " . $id;
dol_syslog(get_class($this)."update sql=".$sql);
$resql=$this->db->query($sql);
if ($resql)
{ {
if ( $this->setMultiLangs() < 0) $this->id = $id;
{
$this->error=$langs->trans("Error")." : ".$this->db->error()." - ".$sql;
return -2;
}
}
// Actions on extra fields (by external module or standard code) // Multilangs
$hookmanager->initHooks(array('productdao')); if (! empty($conf->global->MAIN_MULTILANGS))
$parameters=array('id'=>$this->id);
$reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
if (empty($reshook))
{
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
{ {
$result=$this->insertExtraFields(); if ( $this->setMultiLangs() < 0)
if ($result < 0)
{ {
$error++; $this->error=$langs->trans("Error")." : ".$this->db->error()." - ".$sql;
return -2;
} }
} }
}
else if ($reshook < 0) $error++;
if (! $error && ! $notrigger) // Actions on extra fields (by external module or standard code)
{ $hookmanager->initHooks(array('productdao'));
// Appel des triggers $parameters=array('id'=>$this->id);
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
$interface=new Interfaces($this->db); if (empty($reshook))
$result=$interface->run_triggers('PRODUCT_MODIFY',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers
}
if (! $error && (is_object($this->oldcopy) && $this->oldcopy->ref != $this->ref))
{
// We remove directory
if ($conf->product->dir_output)
{ {
$olddir = $conf->product->dir_output . "/" . dol_sanitizeFileName($this->oldcopy->ref); if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
$newdir = $conf->product->dir_output . "/" . dol_sanitizeFileName($this->ref);
if (file_exists($olddir))
{ {
include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; $result=$this->insertExtraFields();
$res=@dol_move($olddir, $newdir); if ($result < 0)
if (! $res)
{ {
$this->error='ErrorFailToMoveDir';
$error++; $error++;
} }
} }
} }
} else if ($reshook < 0) $error++;
if (! $error) if (! $error && ! $notrigger)
{ {
$this->db->commit(); // Appel des triggers
return 1; include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('PRODUCT_MODIFY',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers
}
if (! $error && (is_object($this->oldcopy) && $this->oldcopy->ref != $this->ref))
{
// We remove directory
if ($conf->product->dir_output)
{
$olddir = $conf->product->dir_output . "/" . dol_sanitizeFileName($this->oldcopy->ref);
$newdir = $conf->product->dir_output . "/" . dol_sanitizeFileName($this->ref);
if (file_exists($olddir))
{
include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
$res=@dol_move($olddir, $newdir);
if (! $res)
{
$this->error='ErrorFailToMoveDir';
$error++;
}
}
}
}
if (! $error)
{
$this->db->commit();
return 1;
}
else
{
$this->db->rollback();
return -$error;
}
} }
else else
{ {
$this->db->rollback(); if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
return -$error; {
$this->error=$langs->trans("Error")." : ".$langs->trans("ErrorProductAlreadyExists",$this->ref);
$this->db->rollback();
return -1;
}
else
{
$this->error=$langs->trans("Error")." : ".$this->db->error()." - ".$sql;
$this->db->rollback();
return -2;
}
} }
} }
else else
{ {
if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') $this->db->rollback();
{ dol_syslog(get_class($this)."::Update fails verify ".join(',',$this->errors), LOG_WARNING);
$this->error=$langs->trans("Error")." : ".$langs->trans("ErrorProductAlreadyExists",$this->ref); return -3;
$this->db->rollback(); }
return -1;
}
else
{
$this->error=$langs->trans("Error")." : ".$this->db->error()." - ".$sql;
$this->db->rollback();
return -2;
}
}
} }
/** /**
@ -3156,6 +3262,8 @@ class Product extends CommonObject
$this->tobuy=1; $this->tobuy=1;
$this->type=0; $this->type=0;
$this->note='This is a comment (private)'; $this->note='This is a comment (private)';
$this->barcode=-1; // Create barcode automatically
} }
} }
?> ?>

View File

@ -117,10 +117,25 @@ if (empty($reshook))
// Barcode value // Barcode value
if ($action == 'setbarcode' && $user->rights->barcode->creer) if ($action == 'setbarcode' && $user->rights->barcode->creer)
{ {
//Todo: ajout verification de la validite du code barre en fonction du type $result=$object->check_barcode(GETPOST('barcode'));
$result = $object->setValueFrom('barcode', GETPOST('barcode'));
header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); if ($result >= 0)
exit; {
$result = $object->setValueFrom('barcode', GETPOST('barcode'));
header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
exit;
}
else
{
$langs->load("errors");
if ($result == -1) $errors[] = 'ErrorBadBarCodeSyntax';
else if ($result == -2) $errors[] = 'ErrorBarCodeRequired';
else if ($result == -3) $errors[] = 'ErrorBarCodeAlreadyUsed';
else $errors[] = 'FailedToValidateBarCode';
$error++;
setEventMessage($errors,'errors');
}
} }
if ($action == 'setaccountancy_code_buy') if ($action == 'setaccountancy_code_buy')
@ -236,8 +251,9 @@ if (empty($reshook))
exit; exit;
} }
else else
{ {
setEventMessage($langs->trans($object->error), 'errors'); if (count($object->errors)) setEventMessage($object->errors, 'errors');
else setEventMessage($langs->trans($object->error), 'errors');
$action = "create"; $action = "create";
} }
} }
@ -279,7 +295,11 @@ if (empty($reshook))
$object->volume_units = GETPOST('volume_units'); $object->volume_units = GETPOST('volume_units');
$object->finished = GETPOST('finished'); $object->finished = GETPOST('finished');
$object->hidden = GETPOST('hidden')=='yes'?1:0; $object->hidden = GETPOST('hidden')=='yes'?1:0;
$object->accountancy_code_sell = GETPOST('accountancy_code_sell');
$object->barcode_type = GETPOST('fk_barcode_type');
$object->barcode = GETPOST('barcode');
$object->accountancy_code_sell = GETPOST('accountancy_code_sell');
$object->accountancy_code_buy = GETPOST('accountancy_code_buy'); $object->accountancy_code_buy = GETPOST('accountancy_code_buy');
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
@ -292,14 +312,16 @@ if (empty($reshook))
$action = 'view'; $action = 'view';
} }
else else
{ {
setEventMessage($langs->trans($object->error), 'errors'); if (count($object->errors)) setEventMessage($object->errors, 'errors');
else setEventMessage($langs->trans($object->error), 'errors');
$action = 'edit'; $action = 'edit';
} }
} }
else else
{ {
setEventMessage($langs->trans("ErrorProductBadRefOrLabel"), 'errors'); if (count($object->errors)) setEventMessage($object->errors, 'errors');
else setEventMessage($langs->trans("ErrorProductBadRefOrLabel"), 'errors');
$action = 'edit'; $action = 'edit';
} }
} }
@ -762,8 +784,8 @@ else
print $formbarcode->select_barcode_type($fk_barcode_type, 'fk_barcode_type', 1); print $formbarcode->select_barcode_type($fk_barcode_type, 'fk_barcode_type', 1);
print '</td><td>'.$langs->trans("BarcodeValue").'</td><td>'; print '</td><td>'.$langs->trans("BarcodeValue").'</td><td>';
$tmpcode=isset($_POST['barcode'])?GETPOST('barcode'):$object->barcode; $tmpcode=isset($_POST['barcode'])?GETPOST('barcode'):$object->barcode;
if (! empty($modBarCodeProduct->code_auto)) $tmpcode=$modBarCodeProduct->getNextValue($object,$type); if (empty($tmpcode) && ! empty($modBarCodeProduct->code_auto)) $tmpcode=$modBarCodeProduct->getNextValue($object,$type);
print '<input size="40" type="text" name="barcode" value="'.$tmpcode.'">'; print '<input size="40" type="text" name="barcode" value="'.dol_escape_htmltag($tmpcode).'">';
print '</td></tr>'; print '</td></tr>';
} }
@ -871,7 +893,7 @@ else
// We must set them on prices tab. // We must set them on prices tab.
} }
else else
{ {
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
// PRIX // PRIX
@ -955,7 +977,7 @@ else
// Label // Label
print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td colspan="3"><input name="libelle" size="40" maxlength="255" value="'.$object->libelle.'"></td></tr>'; print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td colspan="3"><input name="libelle" size="40" maxlength="255" value="'.$object->libelle.'"></td></tr>';
// Status // Status To sell
print '<tr><td class="fieldrequired">'.$langs->trans("Status").' ('.$langs->trans("Sell").')</td><td colspan="3">'; print '<tr><td class="fieldrequired">'.$langs->trans("Status").' ('.$langs->trans("Sell").')</td><td colspan="3">';
print '<select class="flat" name="statut">'; print '<select class="flat" name="statut">';
if ($object->status) if ($object->status)
@ -971,7 +993,7 @@ else
print '</select>'; print '</select>';
print '</td></tr>'; print '</td></tr>';
// To Buy // Status To Buy
print '<tr><td class="fieldrequired">'.$langs->trans("Status").' ('.$langs->trans("Buy").')</td><td colspan="3">'; print '<tr><td class="fieldrequired">'.$langs->trans("Status").' ('.$langs->trans("Buy").')</td><td colspan="3">';
print '<select class="flat" name="statut_buy">'; print '<select class="flat" name="statut_buy">';
if ($object->status_buy) if ($object->status_buy)
@ -987,6 +1009,30 @@ else
print '</select>'; print '</select>';
print '</td></tr>'; print '</td></tr>';
// Barcode
$showbarcode=(! empty($conf->barcode->enabled) && $user->rights->barcode->lire);
if ($showbarcode)
{
print '<tr><td>'.$langs->trans('BarcodeType').'</td><td>';
if (isset($_POST['fk_barcode_type']))
{
$fk_barcode_type=GETPOST('fk_barcode_type');
}
else
{
if (empty($fk_barcode_type) && ! empty($conf->global->PRODUIT_DEFAULT_BARCODE_TYPE)) $fk_barcode_type = $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE;
}
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formbarcode.class.php';
$formbarcode = new FormBarCode($db);
print $formbarcode->select_barcode_type($fk_barcode_type, 'fk_barcode_type', 1);
print '</td><td>'.$langs->trans("BarcodeValue").'</td><td>';
$tmpcode=isset($_POST['barcode'])?GETPOST('barcode'):$object->barcode;
if (empty($tmpcode) && ! empty($modBarCodeProduct->code_auto)) $tmpcode=$modBarCodeProduct->getNextValue($object,$type);
print '<input size="40" type="text" name="barcode" value="'.dol_escape_htmltag($tmpcode).'">';
print '</td></tr>';
}
// Description (used in invoice, propal...) // Description (used in invoice, propal...)
print '<tr><td valign="top">'.$langs->trans("Description").'</td><td colspan="3">'; print '<tr><td valign="top">'.$langs->trans("Description").'</td><td colspan="3">';
@ -1100,7 +1146,7 @@ else
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
// Accountancy_code_sell // Accountancy_code_sell
print '<tr><td>'.$langs->trans("ProductAccountancySellCode").'</td>'; print '<tr><td width="20%">'.$langs->trans("ProductAccountancySellCode").'</td>';
print '<td><input name="accountancy_code_sell" size="16" value="'.$object->accountancy_code_sell.'">'; print '<td><input name="accountancy_code_sell" size="16" value="'.$object->accountancy_code_sell.'">';
print '</td></tr>'; print '</td></tr>';
@ -1121,7 +1167,7 @@ else
} }
// Fiche en mode visu // Fiche en mode visu
else else
{ {
$head=product_prepare_head($object, $user); $head=product_prepare_head($object, $user);
$titre=$langs->trans("CardProduct".$object->type); $titre=$langs->trans("CardProduct".$object->type);
$picto=($object->type==1?'service':'product'); $picto=($object->type==1?'service':'product');

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2002-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2002-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com> * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2003 Brian Fraval <brian@fraval.org> * Copyright (C) 2003 Brian Fraval <brian@fraval.org>
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr> * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
@ -208,8 +208,8 @@ class Societe extends CommonObject
$this->db->begin(); $this->db->begin();
// For automatic creation during create action (not used by Dolibarr GUI, can be used by scripts) // For automatic creation during create action (not used by Dolibarr GUI, can be used by scripts)
if ($this->code_client == -1) $this->get_codeclient($this->prefix_comm,0); if ($this->code_client == -1) $this->get_codeclient($this,0);
if ($this->code_fournisseur == -1) $this->get_codefournisseur($this->prefix_comm,1); if ($this->code_fournisseur == -1) $this->get_codefournisseur($this,1);
// Check more parameters // Check more parameters
// If error, this->errors[] is filled // If error, this->errors[] is filled
@ -290,14 +290,21 @@ class Societe extends CommonObject
} }
else else
{ {
$this->db->rollback(); $this->db->rollback();
dol_syslog(get_class($this)."::Create fails verify ".join(',',$this->errors), LOG_WARNING); dol_syslog(get_class($this)."::Create fails verify ".join(',',$this->errors), LOG_WARNING);
return -3; return -3;
} }
} }
function create_individual($user) { /**
* Create a contact/address from thirdparty
*
* @param User $user Object user
* @return int <0 if KO, >0 if OK
*/
function create_individual($user)
{
require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
$contact=new Contact($this->db); $contact=new Contact($this->db);
@ -313,11 +320,13 @@ class Societe extends CommonObject
$contact->zip = $this->zip; $contact->zip = $this->zip;
$contact->town = $this->town; $contact->town = $this->town;
$contact->phone_pro = $this->phone; $contact->phone_pro = $this->phone;
$result = $contact->create($user); $result = $contact->create($user);
if ($result < 0) { if ($result < 0)
{
$this->error = $contact->error; $this->error = $contact->error;
$this->errors = $contact->errors; $this->errors = $contact->errors;
dol_syslog("Societe::create_individual ERROR:" . $this->error, LOG_ERR); dol_syslog(get_class($this)."::create_individual ERROR:" . $this->error, LOG_ERR);
} }
return $result; return $result;
@ -325,6 +334,7 @@ class Societe extends CommonObject
/** /**
* Check properties of third party are ok (like name, third party codes, ...) * Check properties of third party are ok (like name, third party codes, ...)
* Used before an add or update.
* *
* @return int 0 if OK, <0 if KO * @return int 0 if OK, <0 if KO
*/ */
@ -342,10 +352,8 @@ class Societe extends CommonObject
$result = -2; $result = -2;
} }
if ($this->client && $this->codeclient_modifiable()) if ($this->client)
{ {
// On ne verifie le code client que si la societe est un client / prospect et que le code est modifiable
// Si il n'est pas modifiable il n'est pas mis a jour lors de l'update
$rescode = $this->check_codeclient(); $rescode = $this->check_codeclient();
if ($rescode <> 0) if ($rescode <> 0)
{ {
@ -369,10 +377,8 @@ class Societe extends CommonObject
} }
} }
if ($this->fournisseur && $this->codefournisseur_modifiable()) if ($this->fournisseur)
{ {
// On ne verifie le code fournisseur que si la societe est un fournisseur et que le code est modifiable
// Si il n'est pas modifiable il n'est pas mis a jour lors de l'update
$rescode = $this->check_codefournisseur(); $rescode = $this->check_codefournisseur();
if ($rescode <> 0) if ($rescode <> 0)
{ {
@ -407,7 +413,7 @@ class Societe extends CommonObject
* @param int $call_trigger 0=non, 1=oui * @param int $call_trigger 0=non, 1=oui
* @param int $allowmodcodeclient Inclut modif code client et code compta * @param int $allowmodcodeclient Inclut modif code client et code compta
* @param int $allowmodcodefournisseur Inclut modif code fournisseur et code compta fournisseur * @param int $allowmodcodefournisseur Inclut modif code fournisseur et code compta fournisseur
* @param string $action 'create' or 'update' * @param string $action 'add' or 'update'
* @param int $nosyncmember Do not synchronize info of linked member * @param int $nosyncmember Do not synchronize info of linked member
* @return int <0 if KO, >=0 if OK * @return int <0 if KO, >=0 if OK
*/ */
@ -467,8 +473,8 @@ class Societe extends CommonObject
$this->barcode=trim($this->barcode); $this->barcode=trim($this->barcode);
// For automatic creation // For automatic creation
if ($this->code_client == -1) $this->get_codeclient($this->prefix_comm,0); if ($this->code_client == -1) $this->get_codeclient($this,0);
if ($this->code_fournisseur == -1) $this->get_codefournisseur($this->prefix_comm,1); if ($this->code_fournisseur == -1) $this->get_codefournisseur($this,1);
$this->code_compta=trim($this->code_compta); $this->code_compta=trim($this->code_compta);
$this->code_compta_fournisseur=trim($this->code_compta_fournisseur); $this->code_compta_fournisseur=trim($this->code_compta_fournisseur);
@ -517,7 +523,7 @@ class Societe extends CommonObject
// Check name is required and codes are ok or unique. // Check name is required and codes are ok or unique.
// If error, this->errors[] is filled // If error, this->errors[] is filled
$result = $this->verify(); if ($action != 'add') $result = $this->verify(); // We don't check when update called during a create because verify was already done
if ($result >= 0) if ($result >= 0)
{ {
@ -574,16 +580,12 @@ class Societe extends CommonObject
if ($customer) if ($customer)
{ {
//$this->check_codeclient();
$sql .= ", code_client = ".(! empty($this->code_client)?"'".$this->db->escape($this->code_client)."'":"null"); $sql .= ", code_client = ".(! empty($this->code_client)?"'".$this->db->escape($this->code_client)."'":"null");
$sql .= ", code_compta = ".(! empty($this->code_compta)?"'".$this->db->escape($this->code_compta)."'":"null"); $sql .= ", code_compta = ".(! empty($this->code_compta)?"'".$this->db->escape($this->code_compta)."'":"null");
} }
if ($supplier) if ($supplier)
{ {
//$this->check_codefournisseur();
$sql .= ", code_fournisseur = ".(! empty($this->code_fournisseur)?"'".$this->db->escape($this->code_fournisseur)."'":"null"); $sql .= ", code_fournisseur = ".(! empty($this->code_fournisseur)?"'".$this->db->escape($this->code_fournisseur)."'":"null");
$sql .= ", code_compta_fournisseur = ".(! empty($this->code_compta_fournisseur)?"'".$this->db->escape($this->code_compta_fournisseur)."'":"null"); $sql .= ", code_compta_fournisseur = ".(! empty($this->code_compta_fournisseur)?"'".$this->db->escape($this->code_compta_fournisseur)."'":"null");
} }
@ -621,7 +623,7 @@ class Societe extends CommonObject
//$lmember->lastname=$this->lastname?$this->lastname:$lmember->lastname; // We keep firstname and lastname of member unchanged //$lmember->lastname=$this->lastname?$this->lastname:$lmember->lastname; // We keep firstname and lastname of member unchanged
$lmember->address=$this->address; $lmember->address=$this->address;
$lmember->email=$this->email; $lmember->email=$this->email;
$lmember->skype=$this->skype; $lmember->skype=$this->skype;
$lmember->phone=$this->phone; $lmember->phone=$this->phone;
$result=$lmember->update($user,0,1,1,1); // Use nosync to 1 to avoid cyclic updates $result=$lmember->update($user,0,1,1,1); // Use nosync to 1 to avoid cyclic updates
@ -700,7 +702,7 @@ class Societe extends CommonObject
} }
} }
else else
{ {
$this->db->rollback(); $this->db->rollback();
dol_syslog(get_class($this)."::Update fails verify ".join(',',$this->errors), LOG_WARNING); dol_syslog(get_class($this)."::Update fails verify ".join(',',$this->errors), LOG_WARNING);
return -3; return -3;
@ -1815,19 +1817,20 @@ class Societe extends CommonObject
global $conf; global $conf;
if (! empty($conf->global->SOCIETE_CODECLIENT_ADDON)) if (! empty($conf->global->SOCIETE_CODECLIENT_ADDON))
{ {
$module=$conf->global->SOCIETE_CODECLIENT_ADDON;
$dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']); $dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
foreach ($dirsociete as $dirroot) foreach ($dirsociete as $dirroot)
{ {
$res=dol_include_once($dirroot.$conf->global->SOCIETE_CODECLIENT_ADDON.'.php'); $res=dol_include_once($dirroot.$module.'.php');
if ($res) break; if ($res) break;
} }
$var = $conf->global->SOCIETE_CODECLIENT_ADDON; $mod = new $module();
$mod = new $var;
$this->code_client = $mod->getNextValue($objsoc,$type); $this->code_client = $mod->getNextValue($objsoc,$type);
$this->prefixCustomerIsRequired = $mod->prefixIsRequired; $this->prefixCustomerIsRequired = $mod->prefixIsRequired;
dol_syslog(get_class($this)."::get_codeclient code_client=".$this->code_client." module=".$var); dol_syslog(get_class($this)."::get_codeclient code_client=".$this->code_client." module=".$module);
} }
} }
@ -1844,18 +1847,19 @@ class Societe extends CommonObject
global $conf; global $conf;
if (! empty($conf->global->SOCIETE_CODECLIENT_ADDON)) if (! empty($conf->global->SOCIETE_CODECLIENT_ADDON))
{ {
$module=$conf->global->SOCIETE_CODECLIENT_ADDON;
$dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']); $dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
foreach ($dirsociete as $dirroot) foreach ($dirsociete as $dirroot)
{ {
$res=dol_include_once($dirroot.$conf->global->SOCIETE_CODECLIENT_ADDON.'.php'); $res=dol_include_once($dirroot.$module.'.php');
if ($res) break; if ($res) break;
} }
$var = $conf->global->SOCIETE_CODECLIENT_ADDON; $mod = new $module();
$mod = new $var;
$this->code_fournisseur = $mod->getNextValue($objsoc,$type); $this->code_fournisseur = $mod->getNextValue($objsoc,$type);
dol_syslog(get_class($this)."::get_codefournisseur code_fournisseur=".$this->code_fournisseur." module=".$var); dol_syslog(get_class($this)."::get_codefournisseur code_fournisseur=".$this->code_fournisseur." module=".$module);
} }
} }
@ -1863,25 +1867,25 @@ class Societe extends CommonObject
* Verifie si un code client est modifiable en fonction des parametres * Verifie si un code client est modifiable en fonction des parametres
* du module de controle des codes. * du module de controle des codes.
* *
* @return int 0=Non, 1=Oui * @return int 0=No, 1=Yes
*/ */
function codeclient_modifiable() function codeclient_modifiable()
{ {
global $conf; global $conf;
if (! empty($conf->global->SOCIETE_CODECLIENT_ADDON)) if (! empty($conf->global->SOCIETE_CODECLIENT_ADDON))
{ {
$module=$conf->global->SOCIETE_CODECLIENT_ADDON;
$dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']); $dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
foreach ($dirsociete as $dirroot) foreach ($dirsociete as $dirroot)
{ {
$res=dol_include_once($dirroot.$conf->global->SOCIETE_CODECLIENT_ADDON.'.php'); $res=dol_include_once($dirroot.$module.'.php');
if ($res) break; if ($res) break;
} }
$var = $conf->global->SOCIETE_CODECLIENT_ADDON; $mod = new $module();
$mod = new $var; dol_syslog(get_class($this)."::codeclient_modifiable code_client=".$this->code_client." module=".$module);
dol_syslog(get_class($this)."::codeclient_modifiable code_client=".$this->code_client." module=".$var);
if ($mod->code_modifiable_null && ! $this->code_client) return 1; if ($mod->code_modifiable_null && ! $this->code_client) return 1;
if ($mod->code_modifiable_invalide && $this->check_codeclient() < 0) return 1; if ($mod->code_modifiable_invalide && $this->check_codeclient() < 0) return 1;
if ($mod->code_modifiable) return 1; // A mettre en dernier if ($mod->code_modifiable) return 1; // A mettre en dernier
@ -1897,25 +1901,25 @@ class Societe extends CommonObject
/** /**
* Verifie si un code fournisseur est modifiable dans configuration du module de controle des codes * Verifie si un code fournisseur est modifiable dans configuration du module de controle des codes
* *
* @return int 0=Non, 1=Oui * @return int 0=No, 1=Yes
*/ */
function codefournisseur_modifiable() function codefournisseur_modifiable()
{ {
global $conf; global $conf;
if (! empty($conf->global->SOCIETE_CODECLIENT_ADDON)) if (! empty($conf->global->SOCIETE_CODECLIENT_ADDON))
{ {
$module=$conf->global->SOCIETE_CODECLIENT_ADDON;
$dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']); $dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
foreach ($dirsociete as $dirroot) foreach ($dirsociete as $dirroot)
{ {
$res=dol_include_once($dirroot.$conf->global->SOCIETE_CODECLIENT_ADDON.'.php'); $res=dol_include_once($dirroot.$module.'.php');
if ($res) break; if ($res) break;
} }
$var = $conf->global->SOCIETE_CODECLIENT_ADDON; $mod = new $module();
$mod = new $var; dol_syslog(get_class($this)."::codefournisseur_modifiable code_founisseur=".$this->code_fournisseur." module=".$module);
dol_syslog(get_class($this)."::codefournisseur_modifiable code_founisseur=".$this->code_fournisseur." module=".$var);
if ($mod->code_modifiable_null && ! $this->code_fournisseur) return 1; if ($mod->code_modifiable_null && ! $this->code_fournisseur) return 1;
if ($mod->code_modifiable_invalide && $this->check_codefournisseur() < 0) return 1; if ($mod->code_modifiable_invalide && $this->check_codefournisseur() < 0) return 1;
if ($mod->code_modifiable) return 1; // A mettre en dernier if ($mod->code_modifiable) return 1; // A mettre en dernier
@ -1929,36 +1933,36 @@ class Societe extends CommonObject
/** /**
* Check customer code * Check customer code
* *
* @return int 0 if OK * @return int 0 if OK
* -1 ErrorBadCustomerCodeSyntax * -1 ErrorBadCustomerCodeSyntax
* -2 ErrorCustomerCodeRequired * -2 ErrorCustomerCodeRequired
* -3 ErrorCustomerCodeAlreadyUsed * -3 ErrorCustomerCodeAlreadyUsed
* -4 ErrorPrefixRequired * -4 ErrorPrefixRequired
*/ */
function check_codeclient() function check_codeclient()
{ {
global $conf; global $conf;
if (! empty($conf->global->SOCIETE_CODECLIENT_ADDON)) if (! empty($conf->global->SOCIETE_CODECLIENT_ADDON))
{ {
$dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']); $module=$conf->global->SOCIETE_CODECLIENT_ADDON;
$dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
foreach ($dirsociete as $dirroot) foreach ($dirsociete as $dirroot)
{ {
$res=dol_include_once($dirroot.$conf->global->SOCIETE_CODECLIENT_ADDON.'.php'); $res=dol_include_once($dirroot.$module.'.php');
if ($res) break; if ($res) break;
} }
$var = $conf->global->SOCIETE_CODECLIENT_ADDON; $mod = new $module();
$mod = new $var; dol_syslog(get_class($this)."::check_codeclient code_client=".$this->code_client." module=".$module);
$result = $mod->verif($this->db, $this->code_client, $this, 0);
dol_syslog(get_class($this)."::check_codeclient code_client=".$this->code_client." module=".$var);
$result = $mod->verif($this->db, $this->code_client, $this, 0);
return $result; return $result;
} }
else else
{ {
return 0; return 0;
} }
} }
@ -1977,23 +1981,23 @@ class Societe extends CommonObject
global $conf; global $conf;
if (! empty($conf->global->SOCIETE_CODECLIENT_ADDON)) if (! empty($conf->global->SOCIETE_CODECLIENT_ADDON))
{ {
$dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']); $module=$conf->global->SOCIETE_CODECLIENT_ADDON;
$dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
foreach ($dirsociete as $dirroot) foreach ($dirsociete as $dirroot)
{ {
$res=dol_include_once($dirroot.$conf->global->SOCIETE_CODECLIENT_ADDON.'.php'); $res=dol_include_once($dirroot.$module.'.php');
if ($res) break; if ($res) break;
} }
$var = $conf->global->SOCIETE_CODECLIENT_ADDON; $mod = new $module();
$mod = new $var; dol_syslog(get_class($this)."::check_codefournisseur code_fournisseur=".$this->code_fournisseur." module=".$module);
dol_syslog(get_class($this)."::check_codefournisseur code_fournisseur=".$this->code_fournisseur." module=".$var);
$result = $mod->verif($this->db, $this->code_fournisseur, $this, 1); $result = $mod->verif($this->db, $this->code_fournisseur, $this, 1);
return $result; return $result;
} }
else else
{ {
return 0; return 0;
} }
} }

View File

@ -789,8 +789,8 @@ else
print '<td width="25%">'.$langs->trans('CustomerCode').'</td><td width="25%">'; print '<td width="25%">'.$langs->trans('CustomerCode').'</td><td width="25%">';
print '<table class="nobordernopadding"><tr><td>'; print '<table class="nobordernopadding"><tr><td>';
$tmpcode=$object->code_client; $tmpcode=$object->code_client;
if ($modCodeClient->code_auto) $tmpcode=$modCodeClient->getNextValue($object,0); if (empty($tmpcode) && ! empty($modCodeClient->code_auto)) $tmpcode=$modCodeClient->getNextValue($object,0);
print '<input type="text" name="code_client" size="16" value="'.$tmpcode.'" maxlength="15">'; print '<input type="text" name="code_client" size="16" value="'.dol_escape_htmltag($tmpcode).'" maxlength="15">';
print '</td><td>'; print '</td><td>';
$s=$modCodeClient->getToolTip($langs,$object,0); $s=$modCodeClient->getToolTip($langs,$object,0);
print $form->textwithpicto('',$s,1); print $form->textwithpicto('',$s,1);
@ -807,8 +807,8 @@ else
print '<td>'.$langs->trans('SupplierCode').'</td><td>'; print '<td>'.$langs->trans('SupplierCode').'</td><td>';
print '<table class="nobordernopadding"><tr><td>'; print '<table class="nobordernopadding"><tr><td>';
$tmpcode=$object->code_fournisseur; $tmpcode=$object->code_fournisseur;
if ($modCodeFournisseur->code_auto) $tmpcode=$modCodeFournisseur->getNextValue($object,1); if (empty($tmpcode) && ! empty($modCodeFournisseur->code_auto)) $tmpcode=$modCodeFournisseur->getNextValue($object,1);
print '<input type="text" name="code_fournisseur" size="16" value="'.$tmpcode.'" maxlength="15">'; print '<input type="text" name="code_fournisseur" size="16" value="'.dol_escape_htmltag($tmpcode).'" maxlength="15">';
print '</td><td>'; print '</td><td>';
$s=$modCodeFournisseur->getToolTip($langs,$object,1); $s=$modCodeFournisseur->getToolTip($langs,$object,1);
print $form->textwithpicto('',$s,1); print $form->textwithpicto('',$s,1);
@ -1189,8 +1189,8 @@ else
if ((!$object->code_client || $object->code_client == -1) && $modCodeClient->code_auto) if ((!$object->code_client || $object->code_client == -1) && $modCodeClient->code_auto)
{ {
$tmpcode=$object->code_client; $tmpcode=$object->code_client;
if (empty($tmpcode) && $modCodeClient->code_auto) $tmpcode=$modCodeClient->getNextValue($object,0); if (empty($tmpcode) && ! empty($modCodeClient->code_auto)) $tmpcode=$modCodeClient->getNextValue($object,0);
print '<input type="text" name="code_client" size="16" value="'.$tmpcode.'" maxlength="15">'; print '<input type="text" name="code_client" size="16" value="'.dol_escape_htmltag($tmpcode).'" maxlength="15">';
} }
else if ($object->codeclient_modifiable()) else if ($object->codeclient_modifiable())
{ {
@ -1221,8 +1221,8 @@ else
if ((!$object->code_fournisseur || $object->code_fournisseur == -1) && $modCodeFournisseur->code_auto) if ((!$object->code_fournisseur || $object->code_fournisseur == -1) && $modCodeFournisseur->code_auto)
{ {
$tmpcode=$object->code_fournisseur; $tmpcode=$object->code_fournisseur;
if (empty($tmpcode) && $modCodeFournisseur->code_auto) $tmpcode=$modCodeFournisseur->getNextValue($object,1); if (empty($tmpcode) && ! empty($modCodeFournisseur->code_auto)) $tmpcode=$modCodeFournisseur->getNextValue($object,1);
print '<input type="text" name="code_fournisseur" size="16" value="'.$tmpcode.'" maxlength="15">'; print '<input type="text" name="code_fournisseur" size="16" value="'.dol_escape_htmltag($tmpcode).'" maxlength="15">';
} }
else if ($object->codefournisseur_modifiable()) else if ($object->codefournisseur_modifiable())
{ {