Index: contrat.class.php =================================================================== RCS file: /cvsroot/dolibarr/dolibarr/htdocs/contrat/contrat.class.php,v retrieving revision 1.58 diff -u -r1.58 contrat.class.php --- contrat.class.php 26 Oct 2005 19:00:46 -0000 1.58 +++ contrat.class.php 5 Nov 2005 22:28:37 -0000 @@ -49,7 +49,9 @@ var $user_cloture; var $date_creation; var $date_validation; + var $date_contrat; var $date_cloture; + var $date_fin_validite; var $commercial_signature_id; var $commercial_suivi_id; @@ -89,6 +91,7 @@ function active_line($user, $line_id, $date, $dateend='') { global $langs; + global $conf; // statut actif : 4 @@ -127,6 +130,7 @@ function close_line($user, $line_id, $dateend) { global $langs; + global $conf; // statut actif : 4 @@ -186,6 +190,37 @@ return -1; } } + /** + * \brief Repasse un contrat en brouillon + * Utile pour saisir des avenants. + * \param user Objet User qui annule + * \param langs Environnement langue de l'utilisateur + * \param conf Environnement de configuration lors de l'opération + */ + function brouillon($user,$langs='',$conf='') + { + $sql = "UPDATE ".MAIN_DB_PREFIX."contrat SET statut = 0"; + $sql .= " WHERE rowid = ".$this->id . " AND statut = 1"; // uniquement les valides + + $resql = $this->db->query($sql) ; + if ($resql) + { + $this->use_webcal=($conf->global->PHPWEBCALENDAR_CONTRACTSTATUS=='always'?1:0); + + // Appel des triggers + include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('CONTRACT_UPDATE',$this,$user,$langs,$conf); + // Fin appel triggers + + return 1; + } + else + { + $this->error=$this->db->error(); + return -1; + } + } /** * \brief Valide un contrat @@ -261,7 +296,9 @@ $sql.= " fk_user_mise_en_service, ".$this->db->pdate("date_contrat")." as datecontrat,"; $sql.= " fk_user_author,"; $sql.= " fk_projet,"; - $sql.= " fk_commercial_signature, fk_commercial_suivi "; + $sql.= " fk_commercial_signature, fk_commercial_suivi ,"; + $sql .= $this->db->pdate("fin_validite") . "as datefin,"; + $sql .= $this->db->pdate("date_cloture") . " as datecloture "; $sql.= " FROM ".MAIN_DB_PREFIX."contrat WHERE rowid = $id"; $resql = $this->db->query($sql) ; @@ -279,6 +316,7 @@ $this->facturedetid = $result["fk_facturedet"]; $this->mise_en_service = $result["datemise"]; $this->date_fin_validite = $result["datefin"]; + $this->date_cloture = $result["datecloture"]; $this->date_contrat = $result["datecontrat"]; $this->user_author_id = $result["fk_user_author"]; @@ -294,7 +332,8 @@ $this->societe->fetch($result["fk_soc"]); $this->db->free($resql); - + + $this->brouillon = ($this->statut == 0 ) ? 1 : 0; return $this->id; } else @@ -318,9 +357,11 @@ */ function fetch_lignes() { + + require_once(DOL_DOCUMENT_ROOT."/propal.class.php"); dolibarr_syslog("Contrat.class.php::fetch_lignes"); $this->lignes = array(); - + // Selectionne les lignes contrats liées à un produit $sql = "SELECT p.rowid, p.label, p.description as product_desc, p.ref,"; $sql.= " d.description, d.price_ht, d.tva_tx, d.qty, d.remise_percent, d.subprice,"; @@ -452,12 +493,14 @@ // Insère contrat $sql = "INSERT INTO ".MAIN_DB_PREFIX."contrat (datec, fk_soc, fk_user_author, date_contrat"; // $sql.= ", fk_commercial_signature, fk_commercial_suivi"; - $sql.= " , ref)"; + // $sql.= " , ref)"; + $sql.= " , ref, fin_validite )"; $sql.= " VALUES (now(),".$this->soc_id.",".$user->id; $sql.= ",".$this->db->idate($this->date_contrat); // $sql.= ",".($this->commercial_signature_id>=0?$this->commercial_signature_id:"null"); // $sql.= ",".($this->commercial_suivi_id>=0?$this->commercial_suivi_id:"null"); $sql .= ", " . (strlen($this->ref)<=0 ? "null" : "'".$this->ref."'"); + $sql.= ",".(strlen($this->date_fin_validite) <=0) ? "null" :$this->db->idate($this->date_fin_validite); $sql.= ")"; $resql=$this->db->query($sql); if ($resql) @@ -813,6 +856,29 @@ } } + /** + * \brief Modifie la date de fin de validite du contrat + * \param date_fin La date de fin + */ + function set_date_fin_validite($date_fin) + { + $this->date_fin_validite = $date_fin; + $sql = "UPDATE ".MAIN_DB_PREFIX."contrat"; + $sql.= " SET fin_validite = "; + $sql.= (is_null($date_fin)) ? "null" :$this->db->idate($this->date_fin_validite); + + $sql.= " WHERE rowid = ".$this->id." ;"; + + if ($this->db->query($sql)) + { + return 1; + } + else + { + dolibarr_print_error($this->db); + return -1; + } + } /** * \brief Retourne le libellé du statut du contrat Index: fiche.php =================================================================== RCS file: /cvsroot/dolibarr/dolibarr/htdocs/contrat/fiche.php,v retrieving revision 1.69 diff -u -r1.69 fiche.php --- fiche.php 26 Oct 2005 19:00:46 -0000 1.69 +++ fiche.php 5 Nov 2005 22:28:37 -0000 @@ -52,6 +52,13 @@ { $date_end=mktime(12, 0 , 0, $_POST["date_endmonth"], $_POST["date_endday"], $_POST["date_endyear"]); } + +$datefinvalid = null; +if ($_POST["fin_validitemonth"] && $_POST["fin_validiteday"] && $_POST["fin_validiteyear"]) +{ + $datefinvalid=mktime(12, 0 , 0, $_POST["fin_validitemonth"], $_POST["fin_validiteday"], $_POST["fin_validiteyear"]); +} + // Param si updateligne $date_start_update=''; $date_end_update=''; @@ -93,7 +100,7 @@ $contrat->soc_id = $_POST["soc_id"]; $contrat->date_contrat = $datecontrat; - + $contrat->date_fin_validite = $datefinvalid; $contrat->commercial_suivi_id = $_POST["commercial_suivi_id"]; $contrat->commercial_signature_id = $_POST["commercial_signature_id"]; @@ -124,6 +131,14 @@ $contrat->classin($_POST["projetid"]); } + +if ($_POST["action"] == 'update') +{ + $contrat = new Contrat($db); + $contrat->fetch($_GET["id"]); + $contrat->set_date_fin_validite($datefinvalid); +} + if ($_POST["action"] == 'addligne' && $user->rights->contrat->creer) { if ($_POST["pqty"] && (($_POST["pu"] && $_POST["desc"]) || $_POST["p_idprod"])) @@ -233,8 +248,17 @@ return; } } - - +if ($_POST["action"] == 'confirm_avenant' && $_POST["confirm"] == 'yes') +{ + if ($user->rights->contrat->creer ) + { + $contrat = new Contrat($db); + $contrat->id = $_GET["id"]; + $contrat->brouillon($user,$langs,$conf); + Header("Location: index.php"); + return; + } +} llxHeader('',$langs->trans("ContractCard"),"Contrat"); @@ -338,6 +362,10 @@ print '