diff --git a/htdocs/compta/facture/card-rec.php b/htdocs/compta/facture/card-rec.php index 4f754fbd173..11dec142a17 100644 --- a/htdocs/compta/facture/card-rec.php +++ b/htdocs/compta/facture/card-rec.php @@ -117,6 +117,8 @@ $usercancreatewithdrarequest = $user->rights->prelevement->bons->creer; $now = dol_now(); +$error = 0; + /* * Actions @@ -287,13 +289,21 @@ if (empty($reshook)) elseif ($action == 'setref' && $user->rights->facture->creer) { //var_dump(GETPOST('ref', 'alpha'));exit; - $result = $object->setValueFrom('titre', GETPOST('ref', 'alpha'), '', null, 'text', '', $user, 'BILLREC_MODIFY'); + $result = $object->setValueFrom('titre', $ref, '', null, 'text', '', $user, 'BILLREC_MODIFY'); if ($result > 0) { $object->titre = GETPOST('ref', 'alpha'); // deprecated $object->title = GETPOST('ref', 'alpha'); $object->ref = $object->title; - } else dol_print_error($db, $object->error, $object->errors); + } else { + $error++; + if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') { + $langs->load("errors"); + setEventMessages($langs->trans('ErrorRefAlreadyExists', $ref), null, 'errors'); + } else { + setEventMessages($object->error, $object->errors, 'errors'); + } + } } // Set bank account elseif ($action == 'setbankaccount' && $user->rights->facture->creer) { diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index def74e173a3..110db6d8166 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -4074,7 +4074,7 @@ if ($action == 'create') print $object->getLibType(); print ''; if ($object->module_source) { - print ' ('.$langs->trans("POS").' '.$object->module_source.' - '.$langs->trans("Terminal").' '.$object->pos_source.')'; + print ' ('.$langs->trans("POS").' '.ucfirst($object->module_source).' - '.$langs->trans("Terminal").' '.$object->pos_source.')'; } if ($object->type == Facture::TYPE_REPLACEMENT) { $facreplaced = new Facture($db); diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 243d4d57f7c..ec03bb66524 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -1817,7 +1817,11 @@ abstract class CommonObject return -2; } } else { - $this->error = $this->db->lasterror(); + if ($this->db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') { + $this->error = 'DB_ERROR_RECORD_ALREADY_EXISTS'; + } else { + $this->error = $this->db->lasterror(); + } $this->db->rollback(); return -1; } diff --git a/htdocs/langs/en_US/errors.lang b/htdocs/langs/en_US/errors.lang index 255bce66531..2413e6d76ba 100644 --- a/htdocs/langs/en_US/errors.lang +++ b/htdocs/langs/en_US/errors.lang @@ -8,6 +8,7 @@ ErrorBadEMail=Email %s is wrong ErrorBadMXDomain=Email %s seems wrong (domain has no valid MX record) ErrorBadUrl=Url %s is wrong ErrorBadValueForParamNotAString=Bad value for your parameter. It appends generally when translation is missing. +ErrorRefAlreadyExists=Reference %s already exists. ErrorLoginAlreadyExists=Login %s already exists. ErrorGroupAlreadyExists=Group %s already exists. ErrorRecordNotFound=Record not found. diff --git a/htdocs/langs/fr_FR/errors.lang b/htdocs/langs/fr_FR/errors.lang index 97d3e48f512..abd1c6ec9f9 100644 --- a/htdocs/langs/fr_FR/errors.lang +++ b/htdocs/langs/fr_FR/errors.lang @@ -7,6 +7,7 @@ ErrorButCommitIsDone=Erreurs trouvées mais on valide malgré tout ErrorBadEMail=email %s invalide ErrorBadUrl=Url %s invalide ErrorBadValueForParamNotAString=Mauvaise valeur de paramètre. Ceci arrive lors d'une tentative de traduction d'une clé non renseignée. +ErrorRefAlreadyExists=La référence %s existe déjà. ErrorLoginAlreadyExists=L'identifiant %s existe déjà. ErrorGroupAlreadyExists=Le groupe %s existe déjà. ErrorRecordNotFound=Enregistrement non trouvé.