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 '