Merge pull request #1760 from FHenry/develop

Remane contract ref_ext to ref_supplier
This commit is contained in:
Laurent Destailleur 2014-08-13 23:54:19 +02:00
commit e424ae5b86
11 changed files with 221 additions and 35 deletions

View File

@ -56,6 +56,8 @@ 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)
- New: Enable supplier price log table
For translators:
- Update language files.

View File

@ -593,6 +593,8 @@ class Facture extends CommonInvoice
// Load source object
$objFrom = dol_clone($this);
// Change socid if needed
if (! empty($socid) && $socid != $this->socid)
@ -635,10 +637,22 @@ class Facture extends CommonInvoice
unset($this->products[$i]); // Tant que products encore utilise
}
}
// Create clone
$result=$this->create($user);
if ($result < 0) $error++;
else {
// copy internal contacts
if ($this->copy_linked_contact($objFrom, 'internal') < 0)
$error++;
// copy external contacts if same company
elseif ($objFrom->socid == $this->socid)
{
if ($this->copy_linked_contact($objFrom, 'external') < 0)
$error++;
}
}
if (! $error)
{

View File

@ -45,6 +45,7 @@ class Contrat extends CommonObject
var $id;
var $ref;
var $ref_ext;
var $ref_customer;
var $socid;
var $societe; // Objet societe
var $statut=0; // 0=Draft,
@ -400,6 +401,7 @@ class Contrat extends CommonObject
$sql.= " fk_projet,";
$sql.= " fk_commercial_signature, fk_commercial_suivi,";
$sql.= " note_private, note_public, extraparams";
$sql.= " ,ref_customer";
$sql.= " ,ref_ext";
$sql.= " FROM ".MAIN_DB_PREFIX."contrat";
if ($ref)
@ -419,6 +421,7 @@ class Contrat extends CommonObject
{
$this->id = $result["rowid"];
$this->ref = (!isset($result["ref"]) || !$result["ref"]) ? $result["rowid"] : $result["ref"];
$this->ref_customer = $result["ref_customer"];
$this->ref_ext = $result["ref_ext"];
$this->statut = $result["statut"];
$this->mise_en_service = $this->db->jdate($result["datemise"]);
@ -720,7 +723,7 @@ class Contrat extends CommonObject
// Insert contract
$sql = "INSERT INTO ".MAIN_DB_PREFIX."contrat (datec, fk_soc, fk_user_author, date_contrat,";
$sql.= " fk_commercial_signature, fk_commercial_suivi, fk_projet,";
$sql.= " ref, entity, note_private, note_public, ref_ext)";
$sql.= " ref, entity, note_private, note_public, ref_customer, ref_ext)";
$sql.= " VALUES ('".$this->db->idate($now)."',".$this->socid.",".$user->id;
$sql.= ", '".$this->db->idate($this->date_contrat)."'";
$sql.= ",".($this->commercial_signature_id>0?$this->commercial_signature_id:"NULL");
@ -730,6 +733,7 @@ class Contrat extends CommonObject
$sql.= ", ".$conf->entity;
$sql.= ", ".(!empty($this->note_private)?("'".$this->db->escape($this->note_private)."'"):"NULL");
$sql.= ", ".(!empty($this->note_public)?("'".$this->db->escape($this->note_public)."'"):"NULL");
$sql.= ", ".(!empty($this->ref_customer)?("'".$this->db->escape($this->ref_customer)."'"):"NULL");
$sql.= ", ".(!empty($this->ref_ext)?("'".$this->db->escape($this->ref_ext)."'"):"NULL");
$sql.= ")";
$resql=$this->db->query($sql);
@ -739,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.")";
}
}
}
@ -965,6 +984,7 @@ class Contrat extends CommonObject
// Clean parameters
if (isset($this->ref)) $this->ref=trim($this->ref);
if (isset($this->ref_customer)) $this->ref_customer=trim($this->ref_customer);
if (isset($this->ref_ext)) $this->ref_ext=trim($this->ref_ext);
if (isset($this->entity)) $this->entity=trim($this->entity);
if (isset($this->statut)) $this->statut=trim($this->statut);
@ -988,6 +1008,7 @@ class Contrat extends CommonObject
$sql = "UPDATE ".MAIN_DB_PREFIX."contrat SET";
$sql.= " ref=".(isset($this->ref)?"'".$this->db->escape($this->ref)."'":"null").",";
$sql.= " ref_customer=".(isset($this->ref_customer)?"'".$this->db->escape($this->ref_customer)."'":"null").",";
$sql.= " ref_ext=".(isset($this->ref_ext)?"'".$this->db->escape($this->ref_ext)."'":"null").",";
$sql.= " entity=".$conf->entity.",";
$sql.= " date_contrat=".(dol_strlen($this->date_contrat)!=0 ? "'".$this->db->idate($this->date_contrat)."'" : 'null').",";

View File

@ -207,7 +207,7 @@ if ($action == 'add' && $user->rights->contrat->creer)
$object->fk_project = GETPOST('projectid','int');
$object->remise_percent = GETPOST('remise_percent','alpha');
$object->ref = GETPOST('ref','alpha');
$object->ref_ext = GETPOST('ref_ext','alpha');
$object->ref_customer = GETPOST('ref_customer','alpha');
// If creation from another object of another module (Example: origin=propal, originid=1)
if ($_POST['origin'] && $_POST['originid'])
@ -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)
{
@ -729,17 +729,32 @@ else if ($action == 'confirm_move' && $confirm == 'yes' && $user->rights->contra
$action = 'edit_extras';
setEventMessage($object->error,'errors');
}
} elseif ($action=='setref_ext') {
} elseif ($action=='setref_customer') {
$result = $object->fetch($id);
if ($result < 0) {
setEventMessage($object->errors,'errors');
}
$object->ref_ext=GETPOST('ref_ext','alpha');
$object->ref_customer=GETPOST('ref_customer','alpha');
$result = $object->update($user);
if ($result < 0) {
setEventMessage($object->errors,'errors');
$action='editref_ext';
$action='editref_customer';
} else {
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;
@ -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,11 +915,16 @@ 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>';
print '<td colspan="2"><input type="text" siez="5" name="ref_ext" id="ref_ext" value="'.GETPOST('ref_ext','alpha').'"></td></tr>';
print '<td colspan="2"><input type="text" siez="5" name="ref_customer" id="ref_customer" value="'.GETPOST('ref_customer','alpha').'"></td></tr>';
// Customer
print '<tr>';
@ -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,15 +1109,25 @@ 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%">';
print $form->editfieldkey("RefCustomer",'ref_ext',$object->ref_ext,$object,$user->rights->contrat->creer);
print $form->editfieldkey("RefCustomer",'ref_customer',$object->ref_customer,$object,$user->rights->contrat->creer);
print '</td><td>';
print $form->editfieldval("RefCustomer",'ref_ext',$object->ref_ext,$object,$user->rights->contrat->creer);
print $form->editfieldval("RefCustomer",'ref_customer',$object->ref_customer,$object,$user->rights->contrat->creer);
print '</td>';
print '</tr>';

View File

@ -42,7 +42,7 @@ $offset = $limit * $page ;
$search_nom=GETPOST('search_nom');
$search_contract=GETPOST('search_contract');
$search_ref_ext=GETPOST('search_ref_ext','alpha');
$search_ref_customer=GETPOST('search_ref_customer','alpha');
$sall=GETPOST('sall');
$statut=GETPOST('statut')?GETPOST('statut'):1;
$socid=GETPOST('socid');
@ -75,7 +75,7 @@ $sql.= ' SUM('.$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NOT NULL AND
$sql.= ' SUM('.$db->ifsql("cd.statut=5",1,0).') as nb_closed,';
$sql.= " c.rowid as cid, c.ref, c.datec, c.date_contrat, c.statut,";
$sql.= " s.nom, s.rowid as socid";
$sql.= " ,c.ref_ext";
$sql.= " ,c.ref_customer";
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= ", ".MAIN_DB_PREFIX."contrat as c";
@ -90,8 +90,8 @@ if ($search_nom) {
if ($search_contract) {
$sql .= natural_search(array('c.rowid', 'c.ref'), $search_contract);
}
if (!empty($search_ref_ext)) {
$sql .= natural_search(array('c.ref_ext'), $search_ref_ext);
if (!empty($search_ref_customer)) {
$sql .= natural_search(array('c.ref_customer'), $search_ref_customer);
}
if ($sall) {
$sql .= natural_search(array('s.nom', 'cd.label', 'cd.description'), $sall);
@ -114,9 +114,9 @@ if ($resql)
print '<tr class="liste_titre">';
$param='&amp;search_contract='.$search_contract;
$param.='&amp;search_nom='.$search_nom;
$param.='&amp;search_ref_ext='.$search_ref_ext;
$param.='&amp;search_ref_customer='.$search_ref_customer;
print_liste_field_titre($langs->trans("Ref"), $_SERVER["PHP_SELF"], "c.rowid","","$param",'',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("RefCustomer"), $_SERVER["PHP_SELF"], "c.ref_ext","","$param",'',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("RefCustomer"), $_SERVER["PHP_SELF"], "c.ref_customer","","$param",'',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Company"), $_SERVER["PHP_SELF"], "s.nom","","$param",'',$sortfield,$sortorder);
//print_liste_field_titre($langs->trans("DateCreation"), $_SERVER["PHP_SELF"], "c.datec","","$param",'align="center"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("DateContract"), $_SERVER["PHP_SELF"], "c.date_contrat","","$param",'align="center"',$sortfield,$sortorder);
@ -134,7 +134,7 @@ if ($resql)
print '<input type="text" class="flat" size="3" name="search_contract" value="'.$search_contract.'">';
print '</td>';
print '<td class="liste_titre">';
print '<input type="text" class="flat" size="7" name="search_ref_ext" value="'.$search_ref_ext.'">';
print '<input type="text" class="flat" size="7" name="search_ref_customer value="'.$search_ref_customer.'">';
print '</td>';
print '<td class="liste_titre">';
print '<input type="text" class="flat" size="24" name="search_nom" value="'.$search_nom.'">';
@ -156,7 +156,7 @@ if ($resql)
print img_object($langs->trans("ShowContract"),"contract").' '.(isset($obj->ref) ? $obj->ref : $obj->cid) .'</a>';
if ($obj->nb_late) print img_warning($langs->trans("Late"));
print '</td>';
print '<td>'.$obj->ref_ext.'</td>';
print '<td>'.$obj->ref_customer.'</td>';
print '<td><a href="../comm/fiche.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.$obj->nom.'</a></td>';
//print '<td align="center">'.dol_print_date($obj->datec).'</td>';
print '<td align="center">'.dol_print_date($db->jdate($obj->date_contrat)).'</td>';

View File

@ -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

View 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
*
* @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 Societe $objsoc Object thirdparty
* @param Contrat $contract Object contract
* @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;
}
}

View File

@ -32,6 +32,7 @@ class mod_contract_serpis extends ModelNumRefContracts
var $prefix='CT';
var $error='';
var $nom='Serpis';
var $code_auto=1;
/**

View File

@ -263,9 +263,9 @@ class ProductFournisseur extends Product
$error++;
}
/*if (! $error)
if (! $error && !empty($cong->global->PRODUCT_PRICE_SUPPLIER_NO_LOG))
{
// Ajoute modif dans table log
// Add record into log table
$sql = "INSERT INTO ".MAIN_DB_PREFIX."product_fournisseur_price_log(";
$sql.= "datec, fk_product_fournisseur,fk_user,price,quantity)";
$sql.= "values('".$this->db->idate($now)."',";
@ -281,7 +281,7 @@ class ProductFournisseur extends Product
$error++;
}
}
*/
if (! $error)
{

View File

@ -125,6 +125,7 @@ create table llx_accounting_fiscalyear
)ENGINE=innodb;
ALTER TABLE llx_contrat ADD COLUMN ref_ext varchar(30) after ref;
ALTER TABLE llx_contrat ADD COLUMN ref_customer varchar(30) after ref_ext;
ALTER TABLE llx_propal ADD COLUMN fk_shipping_method integer AFTER date_livraison;
ALTER TABLE llx_commande ADD COLUMN fk_shipping_method integer AFTER date_livraison;
@ -942,7 +943,7 @@ create table llx_c_email_templates
)ENGINE=innodb;
UPDATE llx_c_regions SET rowid = 0 where rowid = 1;
UPDATE llx_c_regions SET rowid = 0 where rowid = 1;
DELETE FROM llx_c_departements WHERE fk_region NOT IN (select rowid from llx_c_regions) AND fk_region IS NOT NULL AND fk_region <> 0;
ALTER TABLE llx_c_departements ADD CONSTRAINT fk_departements_fk_region FOREIGN KEY (fk_region) REFERENCES llx_c_regions (rowid);

View File

@ -22,7 +22,7 @@ create table llx_contrat
(
rowid integer AUTO_INCREMENT PRIMARY KEY,
ref varchar(30), -- contrat reference
ref_ext varchar(30), -- external contract ref
ref_supplier varchar(30), -- suplier contract ref
entity integer DEFAULT 1 NOT NULL, -- multi company id
tms timestamp,
datec datetime, -- creation date