diff --git a/ChangeLog b/ChangeLog index e63d2f537b0..dd57b6137b3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -8,6 +8,7 @@ For users: - Look enhancements for graphics (add transparency). - Added statistics report for supplier invoices - Added average amount in invoices statistics reports. +- Can move a contract line to another contract of same third party. For translators: - The errors language file contains only error or warning messages with diff --git a/htdocs/contrat/contrat.class.php b/htdocs/contrat/contrat.class.php index 6290f6265c1..92e7752c6b8 100644 --- a/htdocs/contrat/contrat.class.php +++ b/htdocs/contrat/contrat.class.php @@ -1117,11 +1117,10 @@ class Contrat extends CommonObject } } - - /** - * \brief R�cup�re les lignes de detail du contrat - * \param statut Statut des lignes detail � r�cup�rer - * \return array Tableau des lignes de details + /** + * \brief Return list of line rowid + * \param statut Status of lines to get + * \return array Array of line's rowid */ function array_detail($statut=-1) { @@ -1132,6 +1131,7 @@ class Contrat extends CommonObject $sql.= " WHERE fk_contrat =".$this->id; if ($statut >= 0) $sql.= " AND statut = '$statut'"; + dolibarr_syslog("Contrat::array_detail() sql=".$sql,LOG_DEBUG); $resql=$this->db->query($sql); if ($resql) { @@ -1151,12 +1151,49 @@ class Contrat extends CommonObject return -1; } } + + /** + * \brief Return list of other contracts for same company than current contract + * \param option 'all' or 'others' + * \return array Array of contracts id + */ + function getListOfContracts($option='all') + { + $tab=array(); + + $sql = "SELECT c.rowid, c.ref"; + $sql.= " FROM ".MAIN_DB_PREFIX."contrat as c"; + $sql.= " WHERE fk_soc =".$this->socid; + if ($option == 'others') $sql.= " AND c.rowid != ".$this->id; + + dolibarr_syslog("Contrat::getOtherContracts() sql=".$sql,LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) + { + $num=$this->db->num_rows($resql); + $i=0; + while ($i < $num) + { + $obj = $this->db->fetch_object($resql); + $contrat=new Contrat($this->db); + $contrat->fetch($obj->rowid); + $tab[]=$contrat; + $i++; + } + return $tab; + } + else + { + $this->error=$this->db->error(); + return -1; + } + } /** * \brief Charge indicateurs this->nbtodo et this->nbtodolate de tableau de bord * \param user Objet user - * \param mode "inactive" pour services � activer, "expired" pour services expir�s + * \param mode "inactive" pour services a activer, "expired" pour services expires * \return int <0 si ko, >0 si ok */ function load_board($user,$mode) @@ -1275,7 +1312,7 @@ class ContratLigne /** * \brief Constructeur d'objets ligne de contrat - * \param DB handler d'acc�s base de donn�e + * \param DB Database access handler */ function ContratLigne($DB) { diff --git a/htdocs/contrat/fiche.php b/htdocs/contrat/fiche.php index 952f10fcc37..da17170cc77 100644 --- a/htdocs/contrat/fiche.php +++ b/htdocs/contrat/fiche.php @@ -131,10 +131,6 @@ if ($_POST["date_end_real_updatemonth"] && $_POST["date_end_real_updateday"] && $date_end_real_update=dolibarr_mktime(12, 0 , 0, $_POST["date_end_real_updatemonth"], $_POST["date_end_real_updateday"], $_POST["date_end_real_updateyear"]); } - -/* - * Actions - */ if ($_POST["action"] == 'add') { $datecontrat = dolibarr_mktime(12, 0 , 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); @@ -391,6 +387,32 @@ if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == 'yes') } } +if ($_POST["action"] == 'confirm_move' && $_POST["confirm"] == 'yes') +{ + if ($user->rights->contrat->creer) + { + if ($_POST['newcid'] > 0) + { + $contractline = new ContratLigne($db); + $result=$contractline->fetch($_GET["lineid"]); + $contractline->fk_contrat = $_POST["newcid"]; + $result=$contractline->update($user,1); + if ($result >= 0) + { + Header("Location: ".$_SERVER['PHP_SELF'].'?id='.$_GET['id']); + return; + } + else + { + $mesg='
'.$contrat->error.'
'; + } + } + else + { + $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("RefNewContract")).'
'; + } + } +} /* @@ -716,7 +738,9 @@ else $servicepos=(isset($_REQUEST["servicepos"])?$_REQUEST["servicepos"]:1); $colorb='333333'; - /* + $arrayothercontracts=$contrat->getListOfContracts('others'); + + /* * Lignes de contrats */ @@ -734,7 +758,7 @@ else // Area with common detail of line print ''; - $sql = "SELECT cd.statut, cd.label as label_det, cd.fk_product, cd.description, cd.price_ht, cd.qty, cd.rowid,"; + $sql = "SELECT cd.rowid, cd.statut, cd.label as label_det, cd.fk_product, cd.description, cd.price_ht, cd.qty,"; $sql.= " cd.tva_tx, cd.remise_percent, cd.info_bits, cd.subprice,"; $sql.= " ".$db->pdate("cd.date_ouverture_prevue")." as date_debut, ".$db->pdate("cd.date_ouverture")." as date_debut_reelle,"; $sql.= " ".$db->pdate("cd.date_fin_validite")." as date_fin, ".$db->pdate("cd.date_cloture")." as date_fin_reelle,"; @@ -795,8 +819,17 @@ else { print ''; } - // Icon update et delete (statut contrat 0=brouillon,1=valid�,2=ferm�) + // Icon move, update et delete (statut contrat 0=brouillon,1=valid�,2=ferm�) print ''; print '
 '; + if (sizeof($arrayothercontracts) && $contrat->statut != 2 && $user->rights->contrat->creer) + { + print ''; + print img_picto($langs->trans("MoveToAnotherContract"),'uparrow'); + print ''; + } + else { + print ' '; + } if ($contrat->statut != 2 && $user->rights->contrat->creer) { print ''; @@ -824,11 +857,11 @@ else print '
'; - // Date pr�vues + // Date planned print $langs->trans("DateStartPlanned").': '; if ($objp->date_debut) { print dolibarr_print_date($objp->date_debut); - // Warning si date prevu pass�e et pas en service + // Warning si date prevu passee et pas en service if ($objp->statut == 0 && $objp->date_debut < time() - $conf->contrat->warning_delay) { print " ".img_warning($langs->trans("Late")); } } else print $langs->trans("Unknown"); @@ -904,6 +937,27 @@ else print "
"; + /* + * Confirmation to move service toward another contract + */ + if ($_REQUEST["action"] == 'move' && ! $_REQUEST["cancel"] && $user->rights->contrat->creer && $contrat->lignes[$cursorline-1]->id == $_GET["rowid"]) + { + //print '
'; + $arraycontractid=array(); + foreach($arrayothercontracts as $contractcursor) + { + $arraycontractid[$contractcursor->id]=$contractcursor->ref; + } + //var_dump($arraycontractid); + // Crée un tableau formulaire + $formquestion=array( + 'text' => $langs->trans("ConfirmMoveToAnotherContractQuestion"), + array('type' => 'select', 'name' => 'newcid', 'values' => $arraycontractid)); + + $html->form_confirm($_SERVER["PHP_SELF"]."?id=".$contrat->id."&lineid=".$_GET["rowid"],$langs->trans("MoveToAnotherContract"),$langs->trans("ConfirmMoveToAnotherContract"),"confirm_move",$formquestion); + print '
'; + } + /* * Confirmation de la validation activation */ diff --git a/htdocs/html.form.class.php b/htdocs/html.form.class.php index f26301b4c57..384627e61bc 100644 --- a/htdocs/html.form.class.php +++ b/htdocs/html.form.class.php @@ -1960,7 +1960,6 @@ class Form * \param action action * \param formquestion an array with forms complementary inputs */ - function form_confirm($page, $title, $question, $action, $formquestion='') { global $langs; @@ -1987,7 +1986,9 @@ class Form } if ($input['type'] == 'select') { - + print ''; + print $this->select_array($input['name'],$input['values'],'',1); + print ''; } if ($input['type'] == 'checkbox') { @@ -2910,6 +2911,7 @@ class Form function select_array($htmlname, $array, $id='', $show_empty=0, $key_in_label=0, $value_as_key=0, $optionType=0, $option='', $translate=0) { global $langs; + // \TODO Simplify optionType and option (only one should be necessary) if ($optionType == 1 && $option != '') { print '