Add a real free numbering module for contract
This commit is contained in:
parent
eca9408c91
commit
db7478098a
@ -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.
|
||||
|
||||
@ -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.")";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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 '<form name="form_contract" action="'.$_SERVER["PHP_SELF"].'" method="post">';
|
||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||
|
||||
@ -890,7 +915,12 @@ if ($action == 'create')
|
||||
print '<table class="border" width="100%">';
|
||||
|
||||
// Ref
|
||||
print '<tr><td class="fieldrequired">'.$langs->trans('Ref').'</td><td colspan="2">'.$langs->trans("Draft").'</td></tr>';
|
||||
if (! empty($modCodeContract->code_auto)) {
|
||||
$tmpcode=$langs->trans("Draft");
|
||||
} else {
|
||||
$tmpcode='<input name="ref" size="20" maxlength="128" value="'.dol_escape_htmltag(GETPOST('ref')?GETPOST('ref'):$tmpcode).'">';
|
||||
}
|
||||
print '<tr><td class="fieldrequired">'.$langs->trans('Ref').'</td><td colspan="2">'.$tmpcode.'</td></tr>';
|
||||
|
||||
// Ref Int
|
||||
print '<tr><td>'.$langs->trans('RefCustomer').'</td>';
|
||||
@ -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 = '<a href="'.DOL_URL_ROOT.'/contrat/liste.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
|
||||
|
||||
// Ref du contrat
|
||||
print '<tr><td width="25%">'.$langs->trans("Ref").'</td><td colspan="3">';
|
||||
print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref', '');
|
||||
print "</td></tr>";
|
||||
if (!empty($modCodeContract->code_auto)) {
|
||||
print '<tr><td width="25%">'.$langs->trans("Ref").'</td><td colspan="3">';
|
||||
print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref', '');
|
||||
print "</td></tr>";
|
||||
} else {
|
||||
print '<tr>';
|
||||
print '<td width="20%">';
|
||||
print $form->editfieldkey("Ref",'ref',$object->ref,$object,$user->rights->contrat->creer);
|
||||
print '</td><td>';
|
||||
print $form->editfieldval("Ref",'ref',$object->ref,$object,$user->rights->contrat->creer);
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
}
|
||||
|
||||
print '<tr>';
|
||||
print '<td width="20%">';
|
||||
|
||||
@ -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
|
||||
|
||||
106
htdocs/core/modules/contract/mod_contract_olive.php
Normal file
106
htdocs/core/modules/contract/mod_contract_olive.php
Normal file
@ -0,0 +1,106 @@
|
||||
<?php
|
||||
/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2006-2009 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2014 Floran Henry <florian.henry@open-concept.pro>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -32,6 +32,7 @@ class mod_contract_serpis extends ModelNumRefContracts
|
||||
var $prefix='CT';
|
||||
var $error='';
|
||||
var $nom='Serpis';
|
||||
var $code_auto=1;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user