From db7478098a42219b5c52a05dcbf3b17b3e1b7d96 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Tue, 12 Aug 2014 13:26:06 +0200 Subject: [PATCH] Add a real free numbering module for contract --- ChangeLog | 1 + htdocs/contrat/class/contrat.class.php | 25 ++++- htdocs/contrat/fiche.php | 56 +++++++-- .../modules/contract/mod_contract_magre.php | 1 + .../modules/contract/mod_contract_olive.php | 106 ++++++++++++++++++ .../modules/contract/mod_contract_serpis.php | 1 + 6 files changed, 177 insertions(+), 13 deletions(-) create mode 100644 htdocs/core/modules/contract/mod_contract_olive.php diff --git a/ChangeLog b/ChangeLog index 5145e6505e3..681455af224 100644 --- a/ChangeLog +++ b/ChangeLog @@ -56,6 +56,7 @@ For users: - Fix: [ bug #1469 ] Triggers CONTACT_MODIFY and CONTACT_DELETE duplicates error message - Fix: [ bug #1537 ] Difference between societe.nom and adherent.societe. - New: [ task #1204 ] add a External reference to contract +- New: [ task #1204 ] add Numering contrat module free (like leopard in product module) For translators: - Update language files. diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index e6a26a8b9d4..709888dffed 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -743,13 +743,28 @@ class Contrat extends CommonObject $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."contrat"); - // Mise a jour ref - $sql = 'UPDATE '.MAIN_DB_PREFIX."contrat SET ref='(PROV".$this->id.")' WHERE rowid=".$this->id; - if ($this->db->query($sql)) + + // Load object modContract + $module=(! empty($conf->global->CONTRACT_ADDON)?$conf->global->CONTRACT_ADDON:'mod_contract_olive'); + if (substr($module, 0, 13) == 'mod_contract_' && substr($module, -3) == 'php') { - if ($this->id) + $module = substr($module, 0, dol_strlen($module)-4); + } + $result=dol_include_once('/core/modules/contract/'.$module.'.php'); + if ($result > 0) + { + $modCodeContract = new $module(); + } + + if (!empty($modCodeContract->code_auto)) { + // Mise a jour ref + $sql = 'UPDATE '.MAIN_DB_PREFIX."contrat SET ref='(PROV".$this->id.")' WHERE rowid=".$this->id; + if ($this->db->query($sql)) { - $this->ref="(PROV".$this->id.")"; + if ($this->id) + { + $this->ref="(PROV".$this->id.")"; + } } } diff --git a/htdocs/contrat/fiche.php b/htdocs/contrat/fiche.php index de97b870c08..38f4ba9a8c4 100644 --- a/htdocs/contrat/fiche.php +++ b/htdocs/contrat/fiche.php @@ -342,7 +342,7 @@ if ($action == 'add' && $user->rights->contrat->creer) // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels, $object); - + $result = $object->create($user); if ($result > 0) { @@ -744,6 +744,21 @@ else if ($action == 'confirm_move' && $confirm == 'yes' && $user->rights->contra header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); exit; } +} elseif ($action=='setref') { + $result = $object->fetch($id); + if ($result < 0) { + setEventMessage($object->errors,'errors'); + } + $object->ref=GETPOST('ref','alpha'); + + $result = $object->update($user); + if ($result < 0) { + setEventMessage($object->errors,'errors'); + $action='editref'; + } else { + header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); + exit; + } } if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->contrat->creer) @@ -818,6 +833,18 @@ $form = new Form($db); $objectlignestatic=new ContratLigne($db); +// Load object modContract +$module=(! empty($conf->global->CONTRACT_ADDON)?$conf->global->CONTRACT_ADDON:'mod_contract_olive'); +if (substr($module, 0, 13) == 'mod_contract_' && substr($module, -3) == 'php') +{ + $module = substr($module, 0, dol_strlen($module)-4); +} +$result=dol_include_once('/core/modules/contract/'.$module.'.php'); +if ($result > 0) +{ + $modCodeContract = new $module(); +} + /********************************************************************* * @@ -878,8 +905,6 @@ if ($action == 'create') $object->date_contrat = dol_now(); - $numct = $object->getNextNumRef($soc); - print '
'; print ''; @@ -890,7 +915,12 @@ if ($action == 'create') print ''; // Ref - print ''; + if (! empty($modCodeContract->code_auto)) { + $tmpcode=$langs->trans("Draft"); + } else { + $tmpcode=''; + } + print ''; // Ref Int print ''; @@ -1040,7 +1070,7 @@ else if ($action == 'valid') { $ref = substr($object->ref, 1, 4); - if ($ref == 'PROV') + if ($ref == 'PROV' && !empty($modCodeContract->code_auto)) { $numref = $object->getNextNumRef($soc); } @@ -1079,9 +1109,19 @@ else $linkback = ''.$langs->trans("BackToList").''; // Ref du contrat - print '"; + if (!empty($modCodeContract->code_auto)) { + print '"; + } else { + print ''; + print ''; + print ''; + } print ''; print '
'.$langs->trans('Ref').''.$langs->trans("Draft").'
'.$langs->trans('Ref').''.$tmpcode.'
'.$langs->trans('RefCustomer').'
'.$langs->trans("Ref").''; - print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref', ''); - print "
'.$langs->trans("Ref").''; + print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref', ''); + print "
'; + print $form->editfieldkey("Ref",'ref',$object->ref,$object,$user->rights->contrat->creer); + print ''; + print $form->editfieldval("Ref",'ref',$object->ref,$object,$user->rights->contrat->creer); + print '
'; diff --git a/htdocs/core/modules/contract/mod_contract_magre.php b/htdocs/core/modules/contract/mod_contract_magre.php index 8281552b459..289b474de5e 100644 --- a/htdocs/core/modules/contract/mod_contract_magre.php +++ b/htdocs/core/modules/contract/mod_contract_magre.php @@ -32,6 +32,7 @@ class mod_contract_magre extends ModelNumRefContracts var $version='dolibarr'; var $error = ''; var $nom = 'Magre'; + var $code_auto=1; /** * Return default description of numbering model diff --git a/htdocs/core/modules/contract/mod_contract_olive.php b/htdocs/core/modules/contract/mod_contract_olive.php new file mode 100644 index 00000000000..f2439bb431e --- /dev/null +++ b/htdocs/core/modules/contract/mod_contract_olive.php @@ -0,0 +1,106 @@ + + * Copyright (C) 2006-2009 Laurent Destailleur + * Copyright (C) 2014 Floran Henry + * + * 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 . + * or see http://www.gnu.org/ + */ + +/** + * \file htdocs/core/modules/contract/mod_contract_olive.php + * \ingroup contract + * \brief File of class to manage contract numbering rules Olive + */ + +require_once DOL_DOCUMENT_ROOT .'/core/modules/contract/modules_contract.php'; + + +/** + * Class to manage contract numbering rules Olive + */ +class mod_contract_olive extends ModelNumRefContracts +{ + + + var $nom='Olive'; // Nom du modele + var $code_modifiable = 1; // Code modifiable + var $code_modifiable_invalide = 1; // Code modifiable si il est invalide + var $code_modifiable_null = 1; // Code modifiables si il est null + var $code_null = 1; // Code facultatif + var $version='dolibarr'; // 'development', 'experimental', 'dolibarr' + var $code_auto = 0; // Numerotation automatique + + + /** Return description of module + * + * @param Translate $langs Object langs + * @return string Description of module + */ + function info() + { + global $langs; + + $langs->load("companies"); + return $langs->trans("LeopardNumRefModelDesc"); + } + + /** + * Return an example of result returned by getNextValue + * + * @param product $objproduct Object product + * @param int $type Type of third party (1:customer, 2:supplier, -1:autodetect) + * @return string Return next value + */ + function getNextValue($objsoc,$contract) + { + global $langs; + return ''; + } + + + /** + * Check validity of code according to its rules + * + * @param DoliDB $db Database handler + * @param string &$code Code to check/correct + * @param Product $product Object product + * @param int $type 0 = product , 1 = service + * @return int 0 if OK + * -1 ErrorBadProductCodeSyntax + * -2 ErrorProductCodeRequired + * -3 ErrorProductCodeAlreadyUsed + * -4 ErrorPrefixRequired + */ + function verif($db, &$code, $product, $type) + { + global $conf; + + $result=0; + $code = strtoupper(trim($code)); + + if (empty($code) && $this->code_null && empty($conf->global->MAIN_CONTARCT_CODE_ALWAYS_REQUIRED)) + { + $result=0; + } + else if (empty($code) && (! $this->code_null || ! empty($conf->global->MAIN_CONTARCT_CODE_ALWAYS_REQUIRED)) ) + { + $result=-2; + } + + dol_syslog("mod_contract_olive::verif type=".$type." result=".$result); + return $result; + } +} + diff --git a/htdocs/core/modules/contract/mod_contract_serpis.php b/htdocs/core/modules/contract/mod_contract_serpis.php index 61ca01ae419..b909b762541 100644 --- a/htdocs/core/modules/contract/mod_contract_serpis.php +++ b/htdocs/core/modules/contract/mod_contract_serpis.php @@ -32,6 +32,7 @@ class mod_contract_serpis extends ModelNumRefContracts var $prefix='CT'; var $error=''; var $nom='Serpis'; + var $code_auto=1; /**