Merge pull request #1848 from atm-alexis/develop_feature_intervention_lines_extrafields

Feature  : Add extrafields on intervention's lines
This commit is contained in:
Laurent Destailleur 2014-08-28 12:00:43 +02:00
commit a1e92b464f
6 changed files with 298 additions and 8 deletions

View File

@ -26,7 +26,7 @@
* Parent class for class inheritance lines of business objects
* This class is useless for the moment so no inherit are done on it
*/
abstract class CommonObjectLine
abstract class CommonObjectLine extends CommonObject
{
/**
* Call trigger based on this instance

View File

@ -126,6 +126,11 @@ function fichinter_admin_prepare_head()
$head[$h][2] = 'attributes';
$h++;
$head[$h][0] = DOL_URL_ROOT.'/fichinter/admin/fichinterdet_extrafields.php';
$head[$h][1] = $langs->trans("ExtraFields");
$head[$h][2] = 'attributesdet';
$h++;
complete_head_from_modules($conf,$langs,null,$head,$h,'fichinter_admin','remove');

View File

@ -0,0 +1,159 @@
<?php
/* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2003 Jean-Louis Bergamo <jlb@j1b.org>
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2013 Florian 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/>.
*/
/**
* \file htdocs/fichinter/admin/fichinter_extrafields.php
* \ingroup fichinter
* \brief Page to setup extra fields of ficheinter
*/
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/fichinter.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
$langs->load("companies");
$langs->load("admin");
$langs->load("members");
$langs->load('interventions');
$extrafields = new ExtraFields($db);
$form = new Form($db);
// List of supported format
$tmptype2label=ExtraFields::$type2label;
$type2label=array('');
foreach ($tmptype2label as $key => $val) $type2label[$key]=$langs->trans($val);
$action=GETPOST('action', 'alpha');
$attrname=GETPOST('attrname', 'alpha');
$elementtype='fichinterdet'; //Must be the $element of the class that manage extrafield
if (!$user->admin) accessforbidden();
/*
* Actions
*/
require DOL_DOCUMENT_ROOT.'/core/actions_extrafields.inc.php';
/*
* View
*/
llxHeader();
$textobject=$langs->transnoentitiesnoconv("Interventions");
$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
print_fiche_titre($langs->trans("InterventionsSetup"),$linkback,'setup');
$head=fichinter_admin_prepare_head();
dol_fiche_head($head, 'attributesdet', $langs->trans("Interventions"), 0, 'intervention');
print $langs->trans("DefineHereComplementaryAttributes",$textobject).'<br>'."\n";
print '<br>';
// Load attribute_label
$extrafields->fetch_name_optionals_label($elementtype);
print "<table summary=\"listofattributes\" class=\"noborder\" width=\"100%\">";
print '<tr class="liste_titre">';
print '<td align="center">'.$langs->trans("Position").'</td>';
print '<td>'.$langs->trans("Label").'</td>';
print '<td>'.$langs->trans("AttributeCode").'</td>';
print '<td>'.$langs->trans("Type").'</td>';
print '<td align="right">'.$langs->trans("Size").'</td>';
print '<td align="center">'.$langs->trans("Unique").'</td>';
print '<td align="center">'.$langs->trans("Required").'</td>';
print '<td width="80">&nbsp;</td>';
print "</tr>\n";
$var=True;
foreach($extrafields->attribute_type as $key => $value)
{
$var=!$var;
print "<tr ".$bc[$var].">";
print "<td>".$extrafields->attribute_pos[$key]."</td>\n";
print "<td>".$extrafields->attribute_label[$key]."</td>\n";
print "<td>".$key."</td>\n";
print "<td>".$type2label[$extrafields->attribute_type[$key]]."</td>\n";
print '<td align="right">'.$extrafields->attribute_size[$key]."</td>\n";
print '<td align="center">'.yn($extrafields->attribute_unique[$key])."</td>\n";
print '<td align="center">'.yn($extrafields->attribute_required[$key])."</td>\n";
print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=edit&attrname='.$key.'">'.img_edit().'</a>';
print "&nbsp; <a href=\"".$_SERVER["PHP_SELF"]."?action=delete&attrname=$key\">".img_delete()."</a></td>\n";
print "</tr>";
// $i++;
}
print "</table>";
dol_fiche_end();
// Buttons
if ($action != 'create' && $action != 'edit')
{
print '<div class="tabsAction">';
print "<a class=\"butAction\" href=\"".$_SERVER["PHP_SELF"]."?action=create\">".$langs->trans("NewAttribute")."</a>";
print "</div>";
}
/* ************************************************************************** */
/* */
/* Creation d'un champ optionnel
/* */
/* ************************************************************************** */
if ($action == 'create')
{
print "<br>";
print_titre($langs->trans('NewAttribute'));
require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_add.tpl.php';
}
/* ************************************************************************** */
/* */
/* Edition d'un champ optionnel */
/* */
/* ************************************************************************** */
if ($action == 'edit' && ! empty($attrname))
{
print "<br>";
print_titre($langs->trans("FieldEdition", $attrname));
require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_edit.tpl.php';
}
llxFooter();
$db->close();

View File

@ -167,6 +167,17 @@ class Fichinter extends CommonObject
$resql=$this->db->query($sql);
if (! $resql) $error++;
}
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
{
$result=$this->insertExtraFields();
if ($result < 0)
{
$error++;
}
}
// Add linked object
if (! $error && $this->origin && $this->origin_id)
{
@ -855,7 +866,7 @@ class Fichinter extends CommonObject
* @param int $duration Intervention duration
* @return int >0 if ok, <0 if ko
*/
function addline($user,$fichinterid, $desc, $date_intervention, $duration)
function addline($user,$fichinterid, $desc, $date_intervention, $duration, $array_option=0)
{
dol_syslog("Fichinter::Addline $fichinterid, $desc, $date_intervention, $duration");
@ -871,14 +882,20 @@ class Fichinter extends CommonObject
$line->datei = $date_intervention;
$line->duration = $duration;
if (is_array($array_option) && count($array_option)>0) {
$line->array_options=$array_option;
}
$result=$line->insert($user);
if ($result > 0)
if ($result >= 0)
{
$this->db->commit();
return 1;
}
else
{
{
$this->error=$this->db->error();
$this->db->rollback();
return -1;
@ -987,7 +1004,10 @@ class FichinterLigne extends CommonObjectLine
var $duration; // Duree de l'intervention
var $rang = 0;
public $element='fichinterdet';
public $table_element='fichinterdet';
public $fk_element='fk_fichinter';
/**
* Constructor
*
@ -1017,6 +1037,7 @@ class FichinterLigne extends CommonObjectLine
{
$objp = $this->db->fetch_object($result);
$this->rowid = $objp->rowid;
$this->id = $objp->rowid;
$this->fk_fichinter = $objp->fk_fichinter;
$this->datei = $this->db->jdate($objp->datei);
$this->desc = $objp->description;
@ -1082,7 +1103,21 @@ class FichinterLigne extends CommonObjectLine
$resql=$this->db->query($sql);
if ($resql)
{
$this->rowid=$this->db->last_insert_id(MAIN_DB_PREFIX.'fichinterdet');
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
{
$this->id=$this->rowid;
$result=$this->insertExtraFields();
if ($result < 0)
{
$error++;
}
}
$result=$this->update_total();
if ($result > 0)
{
$this->rang=$rangToUse;
@ -1140,6 +1175,17 @@ class FichinterLigne extends CommonObjectLine
$resql=$this->db->query($sql);
if ($resql)
{
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
{
$this->id=$this->rowid;
$result=$this->insertExtraFields();
if ($result < 0)
{
$error++;
}
}
$result=$this->update_total();
if ($result > 0)
{

View File

@ -196,6 +196,13 @@ else if ($action == 'add' && $user->rights->ficheinter->creer)
$object->linked_objects = array_merge($object->linked_objects, $_POST['other_linked_objects']);
}
// Extrafields
$extrafields = new ExtraFields($db);
$extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
$array_option = $extrafields->getOptionalsFromPost($extralabels);
$object->array_options = $array_option;
$id = $object->create($user);
if ($id > 0)
@ -266,12 +273,20 @@ else if ($action == 'add' && $user->rights->ficheinter->creer)
$duration = 0;
}
$predef = '';
// Extrafields
$extrafieldsline = new ExtraFields($db);
$extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line);
$array_option = $extrafieldsline->getOptionalsFromPost($extralabelsline, $predef);
$result = $object->addline(
$user,
$id,
$desc,
$date_intervention,
$duration
$duration,
$array_option
);
if ($result < 0)
@ -298,6 +313,13 @@ else if ($action == 'add' && $user->rights->ficheinter->creer)
}
else
{
// Extrafields
$extrafields = new ExtraFields($db);
$extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
$array_option = $extrafields->getOptionalsFromPost($extralabels);
$object->array_options = $array_option;
$result = $object->create($user);
if ($result > 0)
{
@ -433,12 +455,19 @@ else if ($action == "addline" && $user->rights->ficheinter->creer)
$date_intervention = dol_mktime(GETPOST('dihour','int'), GETPOST('dimin','int'), 0, GETPOST('dimonth','int'), GETPOST('diday','int'), GETPOST('diyear','int'));
$duration = convertTime2Seconds(GETPOST('durationhour','int'), GETPOST('durationmin','int'));
// Extrafields
$extrafieldsline = new ExtraFields($db);
$extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line);
$array_option = $extrafieldsline->getOptionalsFromPost($extralabelsline);
$result=$object->addline(
$user,
$id,
$desc,
$date_intervention,
$duration
$duration,
$array_option
);
// Define output language
@ -524,6 +553,13 @@ else if ($action == 'updateline' && $user->rights->ficheinter->creer && GETPOST(
$objectline->datei = $date_inter;
$objectline->desc = $desc;
$objectline->duration = $duration;
// Extrafields
$extrafieldsline = new ExtraFields($db);
$extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line);
$array_option = $extrafieldsline->getOptionalsFromPost($extralabelsline);
$objectline->array_options = $array_option;
$result = $objectline->update($user);
if ($result < 0)
{
@ -1433,6 +1469,18 @@ else if ($id > 0 || ! empty($ref))
}
print '</tr>';
$line = new FichinterLigne($db);
$line->fetch($objp->rowid);
$extrafieldsline = new ExtraFields($db);
$extralabelslines=$extrafieldsline->fetch_name_optionals_label($line->table_element);
$line->fetch_optionals($line->rowid, $extralabelslines);
print $line->showOptionals($extrafieldsline, 'view', array('style'=>$bc[$var], 'colspan'=>5));
}
// Line in update mode
@ -1461,6 +1509,17 @@ else if ($id > 0 || ! empty($ref))
print '<td align="center" colspan="5" valign="center"><input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
print '<br><input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'"></td>';
print '</tr>' . "\n";
$line = new FichinterLigne($db);
$line->fetch($objp->rowid);
$extrafieldsline = new ExtraFields($db);
$extralabelslines=$extrafieldsline->fetch_name_optionals_label($line->table_element);
$line->fetch_optionals($line->rowid, $extralabelslines);
print $line->showOptionals($extrafieldsline, 'edit', array('style'=>$bc[$var], 'colspan'=>5));
}
$i++;
@ -1511,7 +1570,16 @@ else if ($id > 0 || ! empty($ref))
print '<td align="center" valign="middle" colspan="4"><input type="submit" class="button" value="'.$langs->trans('Add').'" name="addline"></td>';
print '</tr>';
//Line extrafield
$lineadd = new FichinterLigne($db);
$extrafieldsline = new ExtraFields($db);
$extralabelslines=$extrafieldsline->fetch_name_optionals_label($lineadd->table_element);
print $lineadd->showOptionals($extrafieldsline, 'edit', array('style'=>$bc[$var], 'colspan'=>5));
if (! $num) print '</table>';
}

View File

@ -992,3 +992,15 @@ ALTER TABLE llx_actioncomm ADD INDEX idx_actioncomm_fk_element (fk_element);
ALTER TABLE llx_projet_task_time ADD INDEX idx_projet_task_time_task (fk_task);
ALTER TABLE llx_projet_task_time ADD INDEX idx_projet_task_time_date (task_date);
ALTER TABLE llx_projet_task_time ADD INDEX idx_projet_task_time_datehour (task_datehour);
-- add extrafield on ficheinter lines
CREATE TABLE IF NOT EXISTS `llx_fichinterdet_extrafields` (
`rowid` int(11) NOT NULL AUTO_INCREMENT,
`tms` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`fk_object` int(11) NOT NULL,
`import_key` varchar(14) DEFAULT NULL,
PRIMARY KEY (`rowid`),
KEY `idx_ficheinter_extrafields` (`fk_object`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;