diff --git a/ChangeLog b/ChangeLog index 5145e6505e3..6cecbc2b752 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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. diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 7e5af441280..9b0e236af35 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -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) { diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index 9c57ff9f570..709888dffed 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -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').","; diff --git a/htdocs/contrat/fiche.php b/htdocs/contrat/fiche.php index ef5b4efab74..38f4ba9a8c4 100644 --- a/htdocs/contrat/fiche.php +++ b/htdocs/contrat/fiche.php @@ -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 '
'; print ''; @@ -890,11 +915,16 @@ if ($action == 'create') print ''; // Ref - print ''; + if (! empty($modCodeContract->code_auto)) { + $tmpcode=$langs->trans("Draft"); + } else { + $tmpcode=''; + } + print ''; // Ref Int print ''; - print ''; + print ''; // Customer 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,15 +1109,25 @@ else $linkback = ''.$langs->trans("BackToList").''; // Ref du contrat - print '"; + if (!empty($modCodeContract->code_auto)) { + print '"; + } else { + print ''; + print ''; + print ''; + } print ''; print ''; print ''; diff --git a/htdocs/contrat/liste.php b/htdocs/contrat/liste.php index 16586b9dd4c..6bd9e249bc7 100644 --- a/htdocs/contrat/liste.php +++ b/htdocs/contrat/liste.php @@ -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 ''; $param='&search_contract='.$search_contract; $param.='&search_nom='.$search_nom; - $param.='&search_ref_ext='.$search_ref_ext; + $param.='&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 ''; print ''; print ''; print ''; - print ''; + print ''; print ''; //print ''; 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..2b10d520b25 --- /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 + * + * @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; + } +} + 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; /** diff --git a/htdocs/fourn/class/fournisseur.product.class.php b/htdocs/fourn/class/fournisseur.product.class.php index b9cd7f40163..367ba5b972e 100644 --- a/htdocs/fourn/class/fournisseur.product.class.php +++ b/htdocs/fourn/class/fournisseur.product.class.php @@ -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) { diff --git a/htdocs/install/mysql/migration/3.6.0-3.7.0.sql b/htdocs/install/mysql/migration/3.6.0-3.7.0.sql index 54aea6de52d..8f79fbcf980 100644 --- a/htdocs/install/mysql/migration/3.6.0-3.7.0.sql +++ b/htdocs/install/mysql/migration/3.6.0-3.7.0.sql @@ -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); diff --git a/htdocs/install/mysql/tables/llx_contrat.sql b/htdocs/install/mysql/tables/llx_contrat.sql index 9cef8fddb42..496ecd4c97d 100644 --- a/htdocs/install/mysql/tables/llx_contrat.sql +++ b/htdocs/install/mysql/tables/llx_contrat.sql @@ -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
'.$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 '
'; - 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 ''; - 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 '
'; - print ''; + print ''; print ''; print ''; @@ -156,7 +156,7 @@ if ($resql) print img_object($langs->trans("ShowContract"),"contract").' '.(isset($obj->ref) ? $obj->ref : $obj->cid) .''; if ($obj->nb_late) print img_warning($langs->trans("Late")); print ''.$obj->ref_ext.''.$obj->ref_customer.''.img_object($langs->trans("ShowCompany"),"company").' '.$obj->nom.''.dol_print_date($obj->datec).''.dol_print_date($db->jdate($obj->date_contrat)).'