diff --git a/ChangeLog b/ChangeLog
index 8377c3d35d3..c72f312e918 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -16,11 +16,12 @@ For users:
to automatically add timestamp and user line into editionf field when editing a note.
- New: Add button cancel into edition of notes.
- New: Improved Opensurvey module and added options to disable comments and disable
- public votes
+ public votes.
- New: The box "balance of bank accounts" show all opened accounts.
- New: Add option MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE.
- New: Add warning if supplier payment is higher that due amount.
-- New increase length of url into bookmark module.
+- New: Increase length of url into bookmark module.
+- New: Add an admin page to make a mass init of barcode values for all products.
TODO
- New: Predefined product and free product use same form.
@@ -79,6 +80,9 @@ Fix: Enable extrafields for customer order, proposal and invoice lines. This fea
fix enough quickly for 3.5.0 release.
Fix: user right on Holiday for month report nor working.
Fix: [ bug #1250 ] "Supplier Ref. product" sidebar search box does not work
+Fix: Bad space in predefined messages.
+Fix: Signature was not added for email sent from thirdparty page.
+Fix: Action event SHIPPING_VALIDATE is not implemented
***** ChangeLog for 3.5 compared to 3.4.* *****
For users:
diff --git a/htdocs/admin/mails.php b/htdocs/admin/mails.php
index ec3faca6625..e29bea1a2e6 100644
--- a/htdocs/admin/mails.php
+++ b/htdocs/admin/mails.php
@@ -132,7 +132,7 @@ if (! empty($_POST['removedfile']) || ! empty($_POST['removedfilehtml']))
if (($action == 'send' || $action == 'sendhtml') && ! GETPOST('addfile') && ! GETPOST('addfilehtml') && ! GETPOST('removedfile') && ! GETPOST('cancel'))
{
$error=0;
-
+
$email_from='';
if (! empty($_POST["fromname"])) $email_from=$_POST["fromname"].' ';
if (! empty($_POST["frommail"])) $email_from.='<'.$_POST["frommail"].'>';
@@ -144,12 +144,12 @@ if (($action == 'send' || $action == 'sendhtml') && ! GETPOST('addfile') && ! GE
$subject = $_POST['subject'];
$body = $_POST['message'];
$deliveryreceipt= $_POST["deliveryreceipt"];
-
+
//Check if we have to decode HTML
if (!empty($conf->global->FCKEDITOR_ENABLE_MAILING) && dol_textishtml(dol_html_entity_decode($body, ENT_COMPAT | ENT_HTML401))) {
$body=dol_html_entity_decode($body, ENT_COMPAT | ENT_HTML401);
}
-
+
// Create form object
include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
$formmail = new FormMail($db);
@@ -693,7 +693,7 @@ else
$formmail->clear_attached_files();
}
- $formmail->show_form(($action == 'testhtml'?'addfilehtml':'addfile'),($action == 'testhtml'?'removefilehtml':'removefile'));
+ print $formmail->get_form(($action == 'testhtml'?'addfilehtml':'addfile'),($action == 'testhtml'?'removefilehtml':'removefile'));
print ' ';
}
diff --git a/htdocs/barcode/codeinit.php b/htdocs/barcode/codeinit.php
new file mode 100644
index 00000000000..bae8d90e589
--- /dev/null
+++ b/htdocs/barcode/codeinit.php
@@ -0,0 +1,282 @@
+
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+/**
+ * \file htdocs/barcode/codeinit.php
+ * \ingroup member
+ * \brief Page to make mass init of barcode
+ */
+require '../main.inc.php';
+require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
+require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
+
+$langs->load("admin");
+$langs->load("members");
+$langs->load("errors");
+
+// Choix de l'annee d'impression ou annee courante.
+$now = dol_now();
+$year=dol_print_date($now,'%Y');
+$month=dol_print_date($now,'%m');
+$day=dol_print_date($now,'%d');
+$forbarcode=GETPOST('forbarcode');
+$fk_barcode_type=GETPOST('fk_barcode_type');
+$mode=GETPOST('mode');
+$modellabel=GETPOST("modellabel"); // Doc template to use
+$numberofsticker=GETPOST('numberofsticker','int');
+
+$mesg='';
+
+$action=GETPOST('action');
+
+$producttmp=new Product($db);
+$thirdpartytmp=new Societe($db);
+
+$modBarCodeProduct='';
+
+
+/*
+ * Actions
+ */
+
+// Define barcode template for products
+if (! empty($conf->global->BARCODE_PRODUCT_ADDON_NUM))
+{
+ $dirbarcodenum=array_merge(array('/core/modules/barcode/'),$conf->modules_parts['barcode']);
+
+ 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))
+ {
+ $file = substr($file, 0, dol_strlen($file)-4);
+
+ try {
+ dol_include_once($dirroot.$file.'.php');
+ }
+ catch(Exception $e)
+ {
+ dol_syslog($e->getMessage(), LOG_ERR);
+ }
+
+ $modBarCodeProduct = new $file();
+ break;
+ }
+ }
+ closedir($handle);
+ }
+ }
+}
+
+if ($action == 'initbarcodeproducts')
+{
+ if (! is_object($modBarCodeProduct))
+ {
+ $error++;
+ setEventMessage($langs->trans("NoBarcodeNumberingTemplateDefined"),'errors');
+ }
+
+ if (! $error)
+ {
+ $productstatic=new Product($db);
+
+ $db->begin();
+
+ $sql="SELECT rowid, ref, fk_product_type FROM ".MAIN_DB_PREFIX."product where barcode IS NULL or barcode = ''";
+ $resql=$db->query($sql);
+ if ($resql)
+ {
+ $num=$db->num_rows($resql);
+
+ $i=0; $nbok=$nbtry=0;
+ while ($i < $num)
+ {
+ $obj=$db->fetch_object($resql);
+ if ($obj)
+ {
+ $productstatic->id=$obj->rowid;
+ $productstatic->ref=$obj->ref;
+ $productstatic->type=$obj->fk_product_type;
+ $nextvalue=$modBarCodeProduct->getNextValue($productstatic,'');
+
+ print 'Set value '.$nextvalue.' to product '.$productstatic->id." ".$productstatic->ref." ".$productstatic->type." \n";
+ $result=$productstatic->setValueFrom('barcode', $nextvalue);
+
+ $nbtry++;
+ if ($result > 0) $nbok++;
+ }
+
+ $i++;
+ }
+ }
+ else
+ {
+ $error++;
+ dol_print_error($db);
+ }
+
+ if (! $error)
+ {
+ setEventMessage($langs->trans("RecordsModified",$nbok),'mesgs');
+
+ //$db->rollback();
+ $db->commit();
+ }
+ else
+ {
+ $db->rollback();
+ }
+ }
+
+ $action='';
+}
+
+
+
+/*
+ * View
+ */
+
+if (!$user->admin) accessforbidden();
+if (empty($conf->barcode->enabled)) accessforbidden();
+
+$form=new Form($db);
+
+llxHeader('',$langs->trans("MassBarcodeInit"));
+
+print_fiche_titre($langs->trans("MassBarcodeInit"));
+print ' ';
+
+print $langs->trans("MassBarcodeInitDesc").' ';
+print ' ';
+
+dol_htmloutput_errors($mesg);
+
+//print img_picto('','puce').' '.$langs->trans("PrintsheetForOneBarCode").' ';
+//print ' ';
+
+print '
';
- // TODO Trick to have param removedfile containing nb of image to delete. But this does not works without javascript
- $out.= ''."\n";
- $out.= ''."\n";
- if (count($listofpaths))
+ if (is_numeric($this->withfile))
{
- foreach($listofpaths as $key => $val)
- {
- $out.= '
';
- }
+ // TODO Trick to have param removedfile containing nb of image to delete. But this does not works without javascript
+ $out.= ''."\n";
+ $out.= ''."\n";
+ if (count($listofpaths))
+ {
+ foreach($listofpaths as $key => $val)
+ {
+ $out.= '
';
// Add to agenda
if (! empty($conf->agenda->enabled) && $user->rights->agenda->myactions->create)
@@ -761,7 +747,7 @@ function show_contacts($conf,$langs,$db,$object,$backtopage='')
}
}
else
- {
+ {
print "
";
print '
'.$langs->trans("None").'
';
print "
\n";
@@ -775,16 +761,6 @@ function show_contacts($conf,$langs,$db,$object,$backtopage='')
- function copyToClipboard (text) {
- text = text.replace(/ /g,"\n");
- var newElem = "
'.$langs->trans('HelpCopyToClipboard').'";
- $("#dialog").html(newElem);
- $( "#dialog" ).dialog();
- $("#coords").select();
- return false;
- }
- ';
return $i;
}
diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php
index b9e25aa58f1..19d2adeea93 100644
--- a/htdocs/core/lib/functions.lib.php
+++ b/htdocs/core/lib/functions.lib.php
@@ -438,7 +438,7 @@ function dol_string_nospecial($str,$newstr='_',$badchars='')
* Returns text escaped for inclusion into javascript code
*
* @param string $stringtoescape String to escape
- * @param string $mode 0=Escape also ' and " into ', 1=Escape ' but not " for usage into 'string', 2=Escape " but not ' for usage into "string"
+ * @param string $mode 0=Escape also ' and " into ', 1=Escape ' but not " for usage into 'string', 2=Escape " but not ' for usage into "string", 3=Escape ' and " with \
* @return string Escaped string. Both ' and " are escaped into ' if they are escaped.
*/
function dol_escape_js($stringtoescape, $mode=0)
@@ -449,6 +449,7 @@ function dol_escape_js($stringtoescape, $mode=0)
if (empty($mode)) { $substitjs["'"]="\\'"; $substitjs['"']="\\'"; }
else if ($mode == 1) $substitjs["'"]="\\'";
else if ($mode == 2) { $substitjs['"']='\\"'; }
+ else if ($mode == 3) { $substitjs["'"]="\\'"; $substitjs['"']="\\\""; }
return strtr($stringtoescape, $substitjs);
}
diff --git a/htdocs/core/menus/standard/auguria_menu.php b/htdocs/core/menus/standard/auguria_menu.php
index 74612aa57fd..ac84a0713f3 100644
--- a/htdocs/core/menus/standard/auguria_menu.php
+++ b/htdocs/core/menus/standard/auguria_menu.php
@@ -110,12 +110,12 @@ class MenuManager
// 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.
- if (! empty($conf->product->enabled) || ! empty($conf->service->enabled) || ! empty($conf->global->MAIN_MENU_ENABLE_MODULETOOLS))
+ 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))
{
if (empty($user->societe_id))
{
- //$newmenu->add("/admin/tools/index.php?mainmenu=home&leftmenu=modulesadmintools", $langs->trans("ModulesSystemTools"), 0, 1, '', 'home', 'modulesadmintools');
- if ($leftmenu=="modulesadmintools" && $user->admin)
+ if ((! empty($conf->product->enabled) || ! empty($conf->service->enabled)) && ($leftmenu=="modulesadmintools" && $user->admin))
{
$langs->load("products");
$array_menu_product=array(
@@ -131,9 +131,9 @@ class MenuManager
'type'=>'left',
'position'=>20
);
- array_unshift($tabMenu,$array_menu_product);
- //$newmenu->add("/product/admin/product_tools.php?mainmenu=home&leftmenu=modulesadmintools", $langs->trans("ProductVatMassChange"), 1, $user->admin);
+ array_unshift($tabMenu,$array_menu_product); // add at beginning of array
}
+ // Main menu title
$array_menu_product=array(
'url'=>"/admin/tools/index.php?mainmenu=home&leftmenu=modulesadmintools",
'titre'=>$langs->trans("ModulesSystemTools"),
@@ -146,7 +146,7 @@ class MenuManager
'type'=>'left',
'position'=>20
);
- array_unshift($tabMenu,$array_menu_product);
+ array_unshift($tabMenu,$array_menu_product); // add at beginning of array
}
}
diff --git a/htdocs/core/menus/standard/eldy.lib.php b/htdocs/core/menus/standard/eldy.lib.php
index 14de23b298f..6c7e64d118a 100644
--- a/htdocs/core/menus/standard/eldy.lib.php
+++ b/htdocs/core/menus/standard/eldy.lib.php
@@ -539,11 +539,13 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu
}
// Modules system tools
- if (! empty($conf->product->enabled) || ! empty($conf->service->enabled) || ! empty($conf->global->MAIN_MENU_ENABLE_MODULETOOLS))
+ 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.
{
if (empty($user->societe_id))
{
$newmenu->add("/admin/tools/index.php?mainmenu=home&leftmenu=modulesadmintools", $langs->trans("ModulesSystemTools"), 0, 1, '', $mainmenu, 'modulesadmintools');
+ // Special case: This entry can't be embedded into modules because we need it for both module service and products and we don't want duplicate lines.
if ((empty($leftmenu) || $leftmenu=="modulesadmintools") && $user->admin)
{
$langs->load("products");
diff --git a/htdocs/core/modules/barcode/mod_barcode_product_standard.php b/htdocs/core/modules/barcode/mod_barcode_product_standard.php
index d20c7502f4a..c7a48c80b2f 100644
--- a/htdocs/core/modules/barcode/mod_barcode_product_standard.php
+++ b/htdocs/core/modules/barcode/mod_barcode_product_standard.php
@@ -190,15 +190,29 @@ class mod_barcode_product_standard extends ModeleNumRefBarCode
}
else
{
- // Get Mask value
- $mask = empty($conf->global->BARCODE_STANDARD_PRODUCT_MASK)?'':$conf->global->BARCODE_STANDARD_PRODUCT_MASK;
- if (! $mask)
+ if ($this->verif_syntax($code) >= 0)
{
- $this->error='NotConfigured';
- return '';
+ $is_dispo = $this->verif_dispo($db, $code, $product);
+ 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);
@@ -216,8 +230,8 @@ class mod_barcode_product_standard extends ModeleNumRefBarCode
*/
function verif_dispo($db, $code, $product)
{
- $sql = "SELECT ref FROM ".MAIN_DB_PREFIX."product";
- $sql.= " WHERE ref = '".$code."'";
+ $sql = "SELECT barcode FROM ".MAIN_DB_PREFIX."product";
+ $sql.= " WHERE barcode = '".$code."'";
if ($product->id > 0) $sql.= " AND rowid <> ".$product->id;
$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;
+ }
+
}
?>
diff --git a/htdocs/core/modules/modBarcode.class.php b/htdocs/core/modules/modBarcode.class.php
index 283d62e2700..bbc16750dd6 100644
--- a/htdocs/core/modules/modBarcode.class.php
+++ b/htdocs/core/modules/modBarcode.class.php
@@ -101,14 +101,26 @@ class modBarcode extends DolibarrModules
'leftmenu'=>'barcodeprint',
'type'=>'left', // This is a Left menu entry
'titre'=>'BarCodePrintsheet',
- 'url'=>'/barcode/printsheet.php',
+ 'url'=>'/barcode/printsheet.php?mainmenu=home&leftmenu=modulesadmintools',
'langs'=>'products', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
'position'=>200,
'enabled'=>'$conf->barcode->enabled', // Define condition to show or hide menu entry. Use '$conf->mymodule->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
'perms'=>'1', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
'target'=>'',
'user'=>2); // 0=Menu for internal users, 1=external users, 2=both
- $r++;
+ $r++;
+
+ $this->menu[$r]=array( 'fk_menu'=>'fk_mainmenu=home,fk_leftmenu=modulesadmintools', // Use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
+ 'type'=>'left', // This is a Left menu entry
+ 'titre'=>'MassBarcodeInit',
+ 'url'=>'/barcode/codeinit.php?mainmenu=home&leftmenu=modulesadmintools',
+ 'langs'=>'products', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
+ 'position'=>300,
+ 'enabled'=>'$conf->barcode->enabled && $leftmenu=="modulesadmintools"', // Define condition to show or hide menu entry. Use '$conf->mymodule->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
+ 'perms'=>'1', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
+ 'target'=>'',
+ 'user'=>0); // 0=Menu for internal users, 1=external users, 2=both
+ $r++;
}
diff --git a/htdocs/core/modules/modProduct.class.php b/htdocs/core/modules/modProduct.class.php
index 43cab4f72cf..b9185624209 100644
--- a/htdocs/core/modules/modProduct.class.php
+++ b/htdocs/core/modules/modProduct.class.php
@@ -129,6 +129,20 @@ class modProduct extends DolibarrModules
$this->rights[$r][4] = 'export';
$r++;
+ /* We can't enable this here because it must be enabled in both product and service module and this create duplicate insert
+ $r=0;
+ $this->menu[$r]=array( 'fk_menu'=>'fk_mainmenu=home,fk_leftmenu=modulesadmintools', // Use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
+ 'type'=>'left', // This is a Left menu entry
+ 'titre'=>'ProductVatMassChange',
+ 'url'=>'/product/admin/product_tools.php?mainmenu=home&leftmenu=modulesadmintools',
+ 'langs'=>'products', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
+ 'position'=>300,
+ 'enabled'=>'$conf->product->enabled && $leftmenu=="modulesadmintools"', // Define condition to show or hide menu entry. Use '$conf->mymodule->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
+ 'perms'=>'1', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
+ 'target'=>'',
+ 'user'=>0); // 0=Menu for internal users, 1=external users, 2=both
+ $r++;
+ */
// Exports
//--------
diff --git a/htdocs/core/modules/modService.class.php b/htdocs/core/modules/modService.class.php
index eb472a25799..695ff596e6e 100644
--- a/htdocs/core/modules/modService.class.php
+++ b/htdocs/core/modules/modService.class.php
@@ -114,6 +114,22 @@ class modService extends DolibarrModules
$r++;
+ /* We can't enable this here because it must be enabled in both product and service module and this create duplicate insert
+ $r=0;
+ $this->menu[$r]=array( 'fk_menu'=>'fk_mainmenu=home,fk_leftmenu=modulesadmintools', // Use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
+ 'type'=>'left', // This is a Left menu entry
+ 'titre'=>'ProductVatMassChange',
+ 'url'=>'/product/admin/product_tools.php?mainmenu=home&leftmenu=modulesadmintools',
+ 'langs'=>'products', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
+ 'position'=>300,
+ 'enabled'=>'$conf->product->enabled && $leftmenu=="modulesadmintools"', // Define condition to show or hide menu entry. Use '$conf->mymodule->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
+ 'perms'=>'1', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
+ 'target'=>'',
+ 'user'=>0); // 0=Menu for internal users, 1=external users, 2=both
+ $r++;
+ */
+
+
// Exports
//--------
$r=0;
diff --git a/htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php b/htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php
index b089b5487a7..6ab80b6ad88 100644
--- a/htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php
+++ b/htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php
@@ -1,7 +1,7 @@
* Copyright (C) 2009-2011 Regis Houssin
- * Copyright (C) 2011 Juanjo Menent
+ * Copyright (C) 2011-2013 Juanjo Menent
* Copyright (C) 2013 Cedric GROSS
*
* This program is free software; you can redistribute it and/or modify
@@ -373,6 +373,25 @@ class InterfaceActionsAuto
// Parameters $object->sendotid defined by caller
//$object->sendtoid=0;
$ok=1;
+ }
+ elseif ($action == 'SHIPPING_VALIDATE')
+ {
+ dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
+ $langs->load("other");
+ $langs->load("sendings");
+ $langs->load("agenda");
+
+ $object->actiontypecode='AC_OTH_AUTO';
+ if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ShippingValidated",$object->ref);
+ if (empty($object->actionmsg))
+ {
+ $object->actionmsg=$langs->transnoentities("ShippingValidated",$object->ref);
+ $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
+ }
+
+ // Parameters $object->sendtoid defined by caller
+ //$object->sendtoid=0;
+ $ok=1;
}
elseif ($action == 'SHIPPING_SENTBYMAIL')
{
diff --git a/htdocs/expedition/fiche.php b/htdocs/expedition/fiche.php
index 0a5d3d0cfcf..c04c4966efe 100644
--- a/htdocs/expedition/fiche.php
+++ b/htdocs/expedition/fiche.php
@@ -1542,7 +1542,7 @@ else if ($id || $ref)
}
// Show form
- $formmail->show_form();
+ print $formmail->get_form();
print ' ';
}
diff --git a/htdocs/fichinter/fiche.php b/htdocs/fichinter/fiche.php
index e40d2b44daa..15e08bad604 100644
--- a/htdocs/fichinter/fiche.php
+++ b/htdocs/fichinter/fiche.php
@@ -1709,7 +1709,7 @@ else if ($id > 0 || ! empty($ref))
$formmail->add_attached_files($file,basename($file),dol_mimetype($file));
}
- $formmail->show_form();
+ print $formmail->get_form();
print ' ';
}
diff --git a/htdocs/fourn/commande/fiche.php b/htdocs/fourn/commande/fiche.php
index ffa72ecf9ac..8da53a67477 100644
--- a/htdocs/fourn/commande/fiche.php
+++ b/htdocs/fourn/commande/fiche.php
@@ -1634,13 +1634,13 @@ elseif (! empty($object->id))
}
print '
'.price($line->total_ht).'
';
-
+
if (is_object($hookmanager))
{
$parameters=array('line'=>$line,'num'=>$num,'i'=>$i);
$reshook=$hookmanager->executeHooks('printObjectLine',$parameters,$object,$action);
}
-
+
if ($object->statut == 0 && $user->rights->fournisseur->commande->creer)
{
print '
';
if ($object->statut == 0) print 'id.'&action=edit_line&etat=0&lineid='.$object->lines[$i]->rowid.'">'.img_edit().'';
else print ' ';
@@ -2370,7 +2370,7 @@ else
}
// Show form
- $formmail->show_form();
+ print $formmail->get_form();
print ' ';
}
diff --git a/htdocs/fourn/facture/impayees.php b/htdocs/fourn/facture/impayees.php
index f7d62f8692e..1d81ae01230 100644
--- a/htdocs/fourn/facture/impayees.php
+++ b/htdocs/fourn/facture/impayees.php
@@ -146,10 +146,8 @@ if ($user->rights->fournisseur->facture->lire)
$sql.= " GROUP BY s.rowid, s.nom, f.rowid, f.ref, f.ref_supplier, f.total_ht, f.total_ttc, f.datef, f.date_lim_reglement, f.paye, f.fk_statut, s.rowid, s.nom";
if (! $user->rights->societe->client->voir && ! $socid) $sql .= ", sc.fk_soc, sc.fk_user ";
- $sql.= " ORDER BY ";
- $listfield=explode(',',$sortfield);
- foreach ($listfield as $key => $value) $sql.=$listfield[$key]." ".$sortorder.",";
- $sql.= " f.ref_supplier DESC";
+ $sql.=$db->order($sortfield,$sortorder);
+ if (! in_array("f.ref_supplier",explode(',',$sortfield))) $sql.= ", f.ref_supplier DESC";
$resql = $db->query($sql);
if ($resql)
diff --git a/htdocs/langs/ca_ES/agenda.lang b/htdocs/langs/ca_ES/agenda.lang
index 238911047e3..f0612d4abe2 100644
--- a/htdocs/langs/ca_ES/agenda.lang
+++ b/htdocs/langs/ca_ES/agenda.lang
@@ -52,6 +52,7 @@ InvoiceSentByEMail=Factura a client %s enviada per e-mail
SupplierOrderSentByEMail=Comanda a proveïdor %s enviada per e-mail
SupplierInvoiceSentByEMail=Factura de proveïdor %s enviada per e-mail
ShippingSentByEMail=Expedició %s enviada per e-mail
+ShippingValidated=Expedició %s validada
InterventionSentByEMail=Intervenció %s enviada per e-mail
NewCompanyToDolibarr= Tercer creat
DateActionPlannedStart= Data d'inici prevista
diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang
index 19192574369..794d5f05c4a 100644
--- a/htdocs/langs/en_US/admin.lang
+++ b/htdocs/langs/en_US/admin.lang
@@ -345,8 +345,6 @@ SecurityTokenIsUnique=Use a unique securekey parameter for each URL
EnterRefToBuildUrl=Enter reference for object %s
GetSecuredUrl=Get calculated URL
ButtonHideUnauthorized=Hide buttons for unauthorized actions instead of showing disabled buttons
-ProductVatMassChange=Mass VAT change
-ProductVatMassChangeDesc=This page can be used to modify a VAT rate defined on products or services from a value to another. Warning, this change is done on all database.
OldVATRates=Old VAT rate
NewVATRates=New VAT rate
PriceBaseTypeToChange=Modify on prices with base reference value defined on
@@ -381,6 +379,12 @@ KeepEmptyToUseDefault=Keep empty to use default value
DefaultLink=Default link
ValueOverwrittenByUserSetup=Warning, this value may be overwritten by user specific setup (each user can set his own clicktodial url)
ExternalModule=External module - Installed into directory %s
+BarcodeInitForThirdparties=Mass barcode init for thirdparties
+BarcodeInitForProductsOrServices=Mass barcode init for products or services
+CurrentlyNWithoutBarCode=Currently, you have %s records on %s %s without barcode defined.
+InitEmptyBarCode=Init the %s barcode
+NoBarcodeNumberingTemplateDefined=No numbering barcode template enabled into barcode module setup.
+NoRecordWithoutBarcodeDefined=No record with no barcode value defined.
# Modules
Module0Name=Users & groups
diff --git a/htdocs/langs/en_US/agenda.lang b/htdocs/langs/en_US/agenda.lang
index 187f818210e..0e37d3290f7 100644
--- a/htdocs/langs/en_US/agenda.lang
+++ b/htdocs/langs/en_US/agenda.lang
@@ -52,6 +52,7 @@ InvoiceSentByEMail=Customer invoice %s sent by EMail
SupplierOrderSentByEMail=Supplier order %s sent by EMail
SupplierInvoiceSentByEMail=Supplier invoice %s sent by EMail
ShippingSentByEMail=Shipping %s sent by EMail
+ShippingValidated= Shipping %s validated
InterventionSentByEMail=Intervention %s sent by EMail
NewCompanyToDolibarr= Third party created
DateActionPlannedStart= Planned start date
diff --git a/htdocs/langs/en_US/errors.lang b/htdocs/langs/en_US/errors.lang
index 5dd292aa10b..fa0b87cc506 100644
--- a/htdocs/langs/en_US/errors.lang
+++ b/htdocs/langs/en_US/errors.lang
@@ -26,8 +26,11 @@ ErrorFromToAccountsMustDiffers=Source and targets bank accounts must be differen
ErrorBadThirdPartyName=Bad value for third party name
ErrorProdIdIsMandatory=The %s is mandatory
ErrorBadCustomerCodeSyntax=Bad syntax for customer code
+ErrorBadBarCodeSyntax=Bad syntax for bar code
ErrorCustomerCodeRequired=Customer code required
+ErrorBarCodeRequired=Bar code required
ErrorCustomerCodeAlreadyUsed=Customer code already used
+ErrorBarCodeAlreadyUsed=Bar code already used
ErrorPrefixRequired=Prefix required
ErrorUrlNotValid=The website address is incorrect
ErrorBadSupplierCodeSyntax=Bad syntax for supplier code
diff --git a/htdocs/langs/en_US/mails.lang b/htdocs/langs/en_US/mails.lang
index c16827bbdee..88d499ac7e0 100644
--- a/htdocs/langs/en_US/mails.lang
+++ b/htdocs/langs/en_US/mails.lang
@@ -79,6 +79,10 @@ MailtoEMail=Hyper link to email
ActivateCheckRead=Allow to use the "Unsubcribe" link
ActivateCheckReadKey=Key use to encrypt URL use for "Read Receipt" and "Unsubcribe" feature
EMailSentToNRecipients=EMail sent to %s recipients.
+EachInvoiceWillBeAttachedToEmail=A document using default invoice document template will be created and attached to each email.
+MailTopicSendRemindUnpaidInvoices=Remind of invoice %s (%s)
+SendRemind=Send remind by EMails
+RemindSent=%S remind(s) sent
# Libelle des modules de liste de destinataires mailing
MailingModuleDescContactCompanies=Contacts/addresses of all third parties (customer, prospect, supplier, ...)
diff --git a/htdocs/langs/en_US/other.lang b/htdocs/langs/en_US/other.lang
index c0fed3de5ef..8ad1d0b0adf 100644
--- a/htdocs/langs/en_US/other.lang
+++ b/htdocs/langs/en_US/other.lang
@@ -49,14 +49,15 @@ Miscellaneous=Miscellaneous
NbOfActiveNotifications=Number of notifications
PredefinedMailTest=This is a test mail.\nThe two lines are separated by a carriage return.\n\n__SIGNATURE__
PredefinedMailTestHtml=This is a test mail (the word test must be in bold). The two lines are separated by a carriage return.
__SIGNATURE__
-PredefinedMailContentSendInvoice=__CONTACTCIVNAME__ \n\n You will find here the invoice __FACREF__\n\n__PERSONALIZED__Sincerely\n\n__SIGNATURE__
-PredefinedMailContentSendInvoiceReminder=__CONTACTCIVNAME__ \n\n We would like to warn you that the invoice __FACREF__ seems to not being payed. So this is the invoice in attachment again, as a reminder.\n\n__PERSONALIZED__Sincerely\n\n__SIGNATURE__
-PredefinedMailContentSendProposal=__CONTACTCIVNAME__ \n\n You will find here the commercial proposal __PROPREF__\n\n__PERSONALIZED__Sincerely\n\n__SIGNATURE__
-PredefinedMailContentSendOrder=__CONTACTCIVNAME__ \n\n You will find here the order __ORDERREF__\n\n__PERSONALIZED__Sincerely\n\n__SIGNATURE__
-PredefinedMailContentSendSupplierOrder=__CONTACTCIVNAME__ \n\n You will find here our order __ORDERREF__\n\n__PERSONALIZED__Sincerely\n\n__SIGNATURE__
-PredefinedMailContentSendSupplierInvoice=__CONTACTCIVNAME__ \n\n You will find here the invoice __FACREF__\n\n__PERSONALIZED__Sincerely\n\n__SIGNATURE__
-PredefinedMailContentSendShipping=__CONTACTCIVNAME__ \n\n You will find here the shipping __SHIPPINGREF__\n\n__PERSONALIZED__Sincerely\n\n__SIGNATURE__
-PredefinedMailContentSendFichInter=__CONTACTCIVNAME__ \n\n You will find here the intervention __FICHINTERREF__\n\n__PERSONALIZED__Sincerely\n\n__SIGNATURE__
+PredefinedMailContentSendInvoice=__CONTACTCIVNAME__\n\nYou will find here the invoice __FACREF__\n\n__PERSONALIZED__Sincerely\n\n__SIGNATURE__
+PredefinedMailContentSendInvoiceReminder=__CONTACTCIVNAME__\n\nWe would like to warn you that the invoice __FACREF__ seems to not being payed. So this is the invoice in attachment again, as a reminder.\n\n__PERSONALIZED__Sincerely\n\n__SIGNATURE__
+PredefinedMailContentSendProposal=__CONTACTCIVNAME__\n\nYou will find here the commercial proposal __PROPREF__\n\n__PERSONALIZED__Sincerely\n\n__SIGNATURE__
+PredefinedMailContentSendOrder=__CONTACTCIVNAME__\n\nYou will find here the order __ORDERREF__\n\n__PERSONALIZED__Sincerely\n\n__SIGNATURE__
+PredefinedMailContentSendSupplierOrder=__CONTACTCIVNAME__\n\nYou will find here our order __ORDERREF__\n\n__PERSONALIZED__Sincerely\n\n__SIGNATURE__
+PredefinedMailContentSendSupplierInvoice=__CONTACTCIVNAME__\n\nYou will find here the invoice __FACREF__\n\n__PERSONALIZED__Sincerely\n\n__SIGNATURE__
+PredefinedMailContentSendShipping=__CONTACTCIVNAME__\n\nYou will find here the shipping __SHIPPINGREF__\n\n__PERSONALIZED__Sincerely\n\n__SIGNATURE__
+PredefinedMailContentSendFichInter=__CONTACTCIVNAME__\n\nYou will find here the intervention __FICHINTERREF__\n\n__PERSONALIZED__Sincerely\n\n__SIGNATURE__
+PredefinedMailContentThirdparty=__CONTACTCIVNAME__\n\n__PERSONALIZED__\n\n__SIGNATURE__
DemoDesc=Dolibarr is a compact ERP/CRM composed by several functional modules. A demo that includes all modules does not mean anything as this never occurs. So, several demo profiles are available.
ChooseYourDemoProfil=Choose the demo profile that match your activity...
DemoFundation=Manage members of a foundation
diff --git a/htdocs/langs/en_US/products.lang b/htdocs/langs/en_US/products.lang
index 96fdf76379b..fa3144d0475 100644
--- a/htdocs/langs/en_US/products.lang
+++ b/htdocs/langs/en_US/products.lang
@@ -13,6 +13,10 @@ NewProduct=New product
NewService=New service
ProductCode=Product code
ServiceCode=Service code
+ProductVatMassChange=Mass VAT change
+ProductVatMassChangeDesc=This page can be used to modify a VAT rate defined on products or services from a value to another. Warning, this change is done on all database.
+MassBarcodeInit=Mass barcode init
+MassBarcodeInitDesc=This page can be used to initialize a barcode on objects that does not have barcode defined. Check before that setup of module barcode is complete.
ProductAccountancyBuyCode=Accountancy code (buy)
ProductAccountancySellCode=Accountancy code (sell)
ProductOrService=Product or Service
@@ -217,4 +221,4 @@ DefinitionOfBarCodeForThirdpartyNotComplete=Definition of type or value of bar c
BarCodeDataForProduct=Barcode information of product %s :
BarCodeDataForThirdparty=Barcode information of thirdparty %s :
BarcodeStickersMask=xxx
-
+
diff --git a/htdocs/langs/es_ES/agenda.lang b/htdocs/langs/es_ES/agenda.lang
index 7abb1dd277b..d832ae6afb5 100644
--- a/htdocs/langs/es_ES/agenda.lang
+++ b/htdocs/langs/es_ES/agenda.lang
@@ -52,6 +52,7 @@ InvoiceSentByEMail=Factura a cliente %s enviada por e-mail
SupplierOrderSentByEMail=Pedido a proveedor %s enviada por e-mail
SupplierInvoiceSentByEMail=Factura de proveedor %s enviada por e-mail
ShippingSentByEMail=Expedición %s enviada por e-mail
+ShippingValidated= Expedición %s validada
InterventionSentByEMail=Intervención %s enviada por e-mail
NewCompanyToDolibarr= Tercero creado
DateActionPlannedStart= Fecha de inicio prevista
diff --git a/htdocs/langs/fr_FR/agenda.lang b/htdocs/langs/fr_FR/agenda.lang
index 190c08ad2ac..d21617fde47 100644
--- a/htdocs/langs/fr_FR/agenda.lang
+++ b/htdocs/langs/fr_FR/agenda.lang
@@ -52,6 +52,7 @@ InvoiceSentByEMail=Facture client %s envoyée par EMail
SupplierOrderSentByEMail=Commande fournisseur %s envoyée par EMail
SupplierInvoiceSentByEMail=Facture fournisseur %s envoyée par Email
ShippingSentByEMail=Bon d'expédition %s envoyé par Email
+ShippingValidated=Bon d'expédition %s validée
InterventionSentByEMail=Intervention %s envoyée par Email
NewCompanyToDolibarr= Tiers créé
DateActionPlannedStart= Date de début de réalisation prévue
diff --git a/htdocs/langs/fr_FR/other.lang b/htdocs/langs/fr_FR/other.lang
index 9814d4f3704..355dadad2ba 100644
--- a/htdocs/langs/fr_FR/other.lang
+++ b/htdocs/langs/fr_FR/other.lang
@@ -49,14 +49,15 @@ Miscellaneous=Divers
NbOfActiveNotifications=Nombre de notifications
PredefinedMailTest=Ceci est un message de test.\nLes 2 lignes sont séparées par un retour à la ligne.\n\n__SIGNATURE__
PredefinedMailTestHtml=Ceci est un message de test (le mot test doit être en gras). Les 2 lignes sont séparées par un retour à la ligne.
__SIGNATURE__
-PredefinedMailContentSendInvoice=__CONTACTCIVNAME__ \n\n Veuillez trouver ci-joint la facture __FACREF__\n\n__PERSONALIZED__Cordialement\n\n__SIGNATURE__
-PredefinedMailContentSendInvoiceReminder=__CONTACTCIVNAME__ \n\nNous voudrions porter à votre connaissance que la facture __FACREF__ ne semble pas avoir été réglée. La voici donc, pour rappel, en pièce jointe.\n\n__PERSONALIZED__Cordialement\n\n__SIGNATURE__
-PredefinedMailContentSendProposal=__CONTACTCIVNAME__ \n\n Veuillez trouver ci-joint la proposition commerciale __PROPREF__\n\n__PERSONALIZED__Cordialement\n\n__SIGNATURE__
-PredefinedMailContentSendOrder=__CONTACTCIVNAME__ \n\n Veuillez trouver ci-joint la commande __ORDERREF__\n\n__PERSONALIZED__Cordialement\n\n__SIGNATURE__
-PredefinedMailContentSendSupplierOrder=__CONTACTCIVNAME__ \n\n Veuillez trouver ci-joint notre commande __ORDERREF__\n\n__PERSONALIZED__Cordialement\n\n__SIGNATURE__
-PredefinedMailContentSendSupplierInvoice=__CONTACTCIVNAME__ \n\n Veuillez trouver ci-joint la facture __FACREF__\n\n__PERSONALIZED__Cordialement\n\n__SIGNATURE__
-PredefinedMailContentSendShipping=__CONTACTCIVNAME__ \n\n Veuillez trouver ci-joint le bon d'expédition __SHIPPINGREF__\n\n__PERSONALIZED__Cordialement\n\n__SIGNATURE__
-PredefinedMailContentSendFichInter=__CONTACTCIVNAME__ \n\n Veuillez trouver ci-joint la fiche d'intervention __FICHINTERREF__\n\n__PERSONALIZED__Cordialement\n\n__SIGNATURE__
+PredefinedMailContentSendInvoice=__CONTACTCIVNAME__\n\nVeuillez trouver ci-joint la facture __FACREF__\n\n__PERSONALIZED__Cordialement\n\n__SIGNATURE__
+PredefinedMailContentSendInvoiceReminder=__CONTACTCIVNAME__\n\nNous voudrions porter à votre connaissance que la facture __FACREF__ ne semble pas avoir été réglée. La voici donc, pour rappel, en pièce jointe.\n\n__PERSONALIZED__Cordialement\n\n__SIGNATURE__
+PredefinedMailContentSendProposal=__CONTACTCIVNAME__\n\nVeuillez trouver ci-joint la proposition commerciale __PROPREF__\n\n__PERSONALIZED__Cordialement\n\n__SIGNATURE__
+PredefinedMailContentSendOrder=__CONTACTCIVNAME__\n\nVeuillez trouver ci-joint la commande __ORDERREF__\n\n__PERSONALIZED__Cordialement\n\n__SIGNATURE__
+PredefinedMailContentSendSupplierOrder=__CONTACTCIVNAME__\n\nVeuillez trouver ci-joint notre commande __ORDERREF__\n\n__PERSONALIZED__Cordialement\n\n__SIGNATURE__
+PredefinedMailContentSendSupplierInvoice=__CONTACTCIVNAME__\n\nVeuillez trouver ci-joint la facture __FACREF__\n\n__PERSONALIZED__Cordialement\n\n__SIGNATURE__
+PredefinedMailContentSendShipping=__CONTACTCIVNAME__\n\nVeuillez trouver ci-joint le bon d'expédition __SHIPPINGREF__\n\n__PERSONALIZED__Cordialement\n\n__SIGNATURE__
+PredefinedMailContentSendFichInter=__CONTACTCIVNAME__\n\nVeuillez trouver ci-joint la fiche d'intervention __FICHINTERREF__\n\n__PERSONALIZED__Cordialement\n\n__SIGNATURE__
+PredefinedMailContentThirdparty=__CONTACTCIVNAME__\n\n__PERSONALIZED__\n\n__SIGNATURE__
DemoDesc=Dolibarr est un logiciel de gestion d'activité (professionnelle ou associative) composé de modules fonctionnels indépendants et optionnels. Une démonstration qui inclut tous ces modules n'a pas de sens car les modules ne sont jamais tous utilisés en même temps. Aussi, plusieurs profils de démonstration type sont disponibles.
ChooseYourDemoProfil=Veuillez choisir le profil de démonstration qui correspond le mieux à votre activité…
DemoFundation=Gestion des adhérents d'une association
diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php
index f5070cf3eda..42209bbcca1 100644
--- a/htdocs/product/class/product.class.php
+++ b/htdocs/product/class/product.class.php
@@ -1,6 +1,6 @@
- * Copyright (C) 2004-2013 Laurent Destailleur
+ * Copyright (C) 2004-2014 Laurent Destailleur
* Copyright (C) 2005-2013 Regis Houssin
* Copyright (C) 2006 Andre Cianfarani
* Copyright (C) 2007-2011 Jean Heimburger
@@ -202,7 +202,7 @@ class Product extends CommonObject
*
* @param User $user User making insert
* @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)
{
@@ -300,141 +300,230 @@ class Product extends CommonObject
// 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);
- $sql = "SELECT count(*) as nb";
- $sql.= " FROM ".MAIN_DB_PREFIX."product";
- $sql.= " WHERE entity IN (".getEntity('product', 1).")";
- $sql.= " AND ref = '" .$this->ref."'";
+ // Check more parameters
+ // If error, this->errors[] is filled
+ $result = $this->verify();
- $result = $this->db->query($sql);
- if ($result)
- {
- $obj = $this->db->fetch_object($result);
- if ($obj->nb == 0)
+ if ($result >= 0)
+ {
+ $sql = "SELECT count(*) as nb";
+ $sql.= " FROM ".MAIN_DB_PREFIX."product";
+ $sql.= " WHERE entity IN (".getEntity('product', 1).")";
+ $sql.= " AND ref = '" .$this->ref."'";
+
+ $result = $this->db->query($sql);
+ if ($result)
{
- // 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.= ")";
-
- dol_syslog(get_class($this)."::Create sql=".$sql);
- $result = $this->db->query($sql);
- if ( $result )
+ $obj = $this->db->fetch_object($result);
+ if ($obj->nb == 0)
{
- $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;
- $this->price = $price_ht;
- $this->price_ttc = $price_ttc;
- $this->price_min = $price_min_ht;
- $this->price_min_ttc = $price_min_ttc;
+ $id = $this->db->last_insert_id(MAIN_DB_PREFIX."product");
- $result = $this->_log_price($user);
- if ($result > 0)
+ if ($id > 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
{
$error++;
- $this->error=$this->db->lasterror();
+ $this->error='ErrorFailedToGetInsertedId';
}
}
else
{
$error++;
- $this->error='ErrorFailedToGetInsertedId';
+ $this->error=$this->db->lasterror();
}
}
else
{
+ // Product already exists with this ref
+ $langs->load("products");
$error++;
- $this->error=$this->db->lasterror();
+ $this->error = "ErrorProductAlreadyExists";
}
}
else
{
- // Product already exists with this ref
- $langs->load("products");
$error++;
- $this->error = "ErrorProductAlreadyExists";
+ $this->error=$this->db->lasterror();
}
- }
- else
- {
- $error++;
- $this->error=$this->db->lasterror();
- }
- if (! $error && ! $notrigger)
- {
- // Appel des triggers
- include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
- $interface=new Interfaces($this->db);
- $result=$interface->run_triggers('PRODUCT_CREATE',$this,$user,$langs,$conf);
- if ($result < 0) { $error++; $this->errors=$interface->errors; }
- // Fin appel triggers
- }
+ if (! $error && ! $notrigger)
+ {
+ // Appel des triggers
+ include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
+ $interface=new Interfaces($this->db);
+ $result=$interface->run_triggers('PRODUCT_CREATE',$this,$user,$langs,$conf);
+ if ($result < 0) { $error++; $this->errors=$interface->errors; }
+ // 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
*
* @param int $id Id of product
* @param User $user Object user making update
* @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
*/
function update($id, $user, $notrigger=false, $action='update')
@@ -443,9 +532,7 @@ class Product extends CommonObject
$error=0;
- $this->db->begin();
-
- // Verification parametres
+ // Check parameters
if (! $this->libelle) $this->libelle = 'MISSING LABEL';
// Clean parameters
@@ -473,135 +560,154 @@ class Product extends CommonObject
//Gencod
$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_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)."'");
- $sql.= ", fk_barcode_type = ". (empty($this->barcode_type)?"null":$this->db->escape($this->barcode_type));
+ $this->db->begin();
- $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;
+ // Check name is required and codes are ok or unique.
+ // If error, this->errors[] is filled
+ if ($action != 'add')
+ {
+ $result = $this->verify(); // We don't check when update called during a create because verify was already done
+ }
- dol_syslog(get_class($this)."update sql=".$sql);
- $resql=$this->db->query($sql);
- if ($resql)
- {
- $this->id = $id;
+ if ($result >= 0)
+ {
+ // For automatic creation
+ if ($this->barcode == -1) $this->get_barcode($this,$this->barcode_type_code);
- // Multilangs
- if (! empty($conf->global->MAIN_MULTILANGS))
+ $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)."'");
+ $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->error=$langs->trans("Error")." : ".$this->db->error()." - ".$sql;
- return -2;
- }
- }
+ $this->id = $id;
- // Actions on extra fields (by external module or standard code)
- $hookmanager->initHooks(array('productdao'));
- $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
+ // Multilangs
+ if (! empty($conf->global->MAIN_MULTILANGS))
{
- $result=$this->insertExtraFields();
- if ($result < 0)
+ if ( $this->setMultiLangs() < 0)
{
- $error++;
+ $this->error=$langs->trans("Error")." : ".$this->db->error()." - ".$sql;
+ return -2;
}
}
- }
- else if ($reshook < 0) $error++;
- if (! $error && ! $notrigger)
- {
- // Appel des triggers
- 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)
+ // Actions on extra fields (by external module or standard code)
+ $hookmanager->initHooks(array('productdao'));
+ $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))
{
- $olddir = $conf->product->dir_output . "/" . dol_sanitizeFileName($this->oldcopy->ref);
- $newdir = $conf->product->dir_output . "/" . dol_sanitizeFileName($this->ref);
- if (file_exists($olddir))
+ if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
{
- include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
- $res=@dol_move($olddir, $newdir);
- if (! $res)
+ $result=$this->insertExtraFields();
+ if ($result < 0)
{
- $this->error='ErrorFailToMoveDir';
$error++;
}
}
}
- }
+ else if ($reshook < 0) $error++;
- if (! $error)
- {
- $this->db->commit();
- return 1;
+ if (! $error && ! $notrigger)
+ {
+ // Appel des triggers
+ 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
{
- $this->db->rollback();
- return -$error;
+ if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
+ {
+ $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
- {
- if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
- {
- $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
+ {
+ $this->db->rollback();
+ dol_syslog(get_class($this)."::Update fails verify ".join(',',$this->errors), LOG_WARNING);
+ return -3;
+ }
}
/**
@@ -3156,6 +3262,8 @@ class Product extends CommonObject
$this->tobuy=1;
$this->type=0;
$this->note='This is a comment (private)';
+
+ $this->barcode=-1; // Create barcode automatically
}
}
?>
diff --git a/htdocs/product/fiche.php b/htdocs/product/fiche.php
index ca47227e1f0..6a86dbe3217 100644
--- a/htdocs/product/fiche.php
+++ b/htdocs/product/fiche.php
@@ -117,10 +117,25 @@ if (empty($reshook))
// Barcode value
if ($action == 'setbarcode' && $user->rights->barcode->creer)
{
- //Todo: ajout verification de la validite du code barre en fonction du type
- $result = $object->setValueFrom('barcode', GETPOST('barcode'));
- header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
- exit;
+ $result=$object->check_barcode(GETPOST('barcode'));
+
+ if ($result >= 0)
+ {
+ $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')
@@ -236,8 +251,9 @@ if (empty($reshook))
exit;
}
else
- {
- setEventMessage($langs->trans($object->error), 'errors');
+ {
+ if (count($object->errors)) setEventMessage($object->errors, 'errors');
+ else setEventMessage($langs->trans($object->error), 'errors');
$action = "create";
}
}
@@ -279,7 +295,11 @@ if (empty($reshook))
$object->volume_units = GETPOST('volume_units');
$object->finished = GETPOST('finished');
$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');
// Fill array 'array_options' with data from add form
@@ -292,14 +312,16 @@ if (empty($reshook))
$action = 'view';
}
else
- {
- setEventMessage($langs->trans($object->error), 'errors');
+ {
+ if (count($object->errors)) setEventMessage($object->errors, 'errors');
+ else setEventMessage($langs->trans($object->error), 'errors');
$action = 'edit';
}
}
else
- {
- setEventMessage($langs->trans("ErrorProductBadRefOrLabel"), 'errors');
+ {
+ if (count($object->errors)) setEventMessage($object->errors, 'errors');
+ else setEventMessage($langs->trans("ErrorProductBadRefOrLabel"), 'errors');
$action = 'edit';
}
}
@@ -762,8 +784,8 @@ else
print $formbarcode->select_barcode_type($fk_barcode_type, 'fk_barcode_type', 1);
print '
';
}
if ($user->rights->societe->creer)
@@ -1840,7 +1840,7 @@ else
if ($user->rights->societe->supprimer)
{
- if ($conf->use_javascript_ajax && empty($conf->dol_use_jmobile)) // We can(t use preloaded confirm form with jmobile
+ if ($conf->use_javascript_ajax && empty($conf->dol_use_jmobile)) // We can't use preloaded confirm form with jmobile
{
print '