Skip to content

Commit

Permalink
Merge pull request #1711 from FHenry/3.6_contractextrafields
Browse files Browse the repository at this point in the history
3.6 contractextrafields
  • Loading branch information
eldy committed Jul 5, 2014
2 parents 2921412 + fe50d8b commit 851fdf3
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 30 deletions.
21 changes: 21 additions & 0 deletions htdocs/contrat/class/contrat.class.php
Expand Up @@ -448,6 +448,14 @@ function fetch($id,$ref='')
$this->extraparams = (array) json_decode($result["extraparams"], true);

$this->db->free($resql);

// Retreive all extrafield for thirdparty
// fetch optionals attributes and labels
require_once(DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php');
$extrafields=new ExtraFields($this->db);
$extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
$this->fetch_optionals($this->id,$extralabels);


return $this->id;
}
Expand Down Expand Up @@ -753,6 +761,19 @@ function create($user)
// Insert contacts commerciaux ('SALESREPFOLL','contrat')
$result=$this->add_contact($this->commercial_suivi_id,'SALESREPFOLL','internal');
if ($result < 0) $error++;


if (! $error)
{
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
{
$result=$this->insertExtraFields();
if ($result < 0)
{
$error++;
}
}
}

if (! $error)
{
Expand Down
127 changes: 101 additions & 26 deletions htdocs/contrat/fiche.php
Expand Up @@ -5,7 +5,7 @@
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
* Copyright (C) 2010-2013 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2013 Christophe Battarel <christophe.battarel@altairis.fr>
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2013-2014 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
Expand Down Expand Up @@ -40,6 +40,7 @@
require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
}
require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php';

$langs->load("contracts");
$langs->load("orders");
Expand All @@ -65,6 +66,10 @@
$hookmanager->initHooks(array('contractcard'));

$object = new Contrat($db);
$extrafields = new ExtraFields($db);

// fetch optionals attributes and labels
$extralabels = $extrafields->fetch_name_optionals_label($object->table_element);

$permissionnote=$user->rights->contrat->creer; // Used by the include of actions_setnotes.inc.php

Expand All @@ -86,7 +91,7 @@
exit;
}
else {
$mesg=$object->error;
setEventMessage($object->error,'errors');
}
}

Expand All @@ -107,7 +112,7 @@
exit;
}
else {
$mesg=$object->error;
setEventMessage($object->error,'errors');
}
}
}
Expand Down Expand Up @@ -176,7 +181,7 @@
if (empty($datecontrat))
{
$error++;
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Date")).'</div>';
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Date")),'errors');
$action='create';
}

Expand Down Expand Up @@ -228,7 +233,7 @@

$id = $object->create($user);
if ($id < 0) {
$mesg='<div class="error">'.$object->error.'</div>';
setEventMessage($object->error,'errors');
}

if ($id > 0)
Expand Down Expand Up @@ -319,26 +324,30 @@
}
else
{
$mesg=$srcobject->error;
setEventMessage($srcobject->error,'errors');
$error++;
}
}
else
{
$mesg=$object->error;
setEventMessage($object->error,'errors');
$error++;
}
}
else
{
$result = $object->create($user,$langs,$conf);

// Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels, $object);

$result = $object->create($user);
if ($result > 0)
{
header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
exit;
}
else {
$mesg='<div class="error">'.$object->error.'</div>';
setEventMessage($object->error,'errors');
}
$action='create';
}
Expand Down Expand Up @@ -389,7 +398,7 @@
$ret=$object->fetch($id);
if ($ret < 0)
{
dol_print_error($db,$object->error);
setEventMessage($object->error,'errors');
exit;
}
$ret=$object->fetch_thirdparty();
Expand Down Expand Up @@ -546,7 +555,7 @@
}
else
{
$mesg='<div class="error">'.$object->error.'</div>';
setEventMessage($object->error,'errors');
}
}
}
Expand Down Expand Up @@ -604,13 +613,13 @@
}
else
{
dol_print_error($db,'Failed to update contrat_det');
setEventMessage($objectline->error,'errors');
$db->rollback();
}
}
else
{
dol_print_error($db);
setEventMessage($objectline->error,'errors');
}
}

Expand All @@ -626,7 +635,7 @@
}
else
{
$mesg=$object->error;
setEventMessage($object->error,'errors');
}
}

Expand Down Expand Up @@ -655,7 +664,7 @@
}
else
{
$mesg='<div class="error">'.$object->error.'</div>';
setEventMessage($object->error,'errors');
}
}

Expand All @@ -674,12 +683,33 @@
}
else
{
$mesg='<div class="error">'.$object->error.'</div>';
setEventMessage($object->error,'errors');
}
}
else
{
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("RefNewContract")).'</div>';
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("RefNewContract")),'errors');
}
} else if ($action == 'update_extras') {
// Fill array 'array_options' with data from update form
$object->fetch($id);
$extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
$ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute'));
if ($ret < 0)
$error ++;

if (! $error) {

$result = $object->insertExtraFields();
if ($result < 0) {
$error ++;
}
} else if ($reshook < 0)
$error ++;

if ($error) {
$action = 'edit_extras';
setEventMessage($object->error,'errors');
}
}

Expand All @@ -705,11 +735,11 @@
if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
{
$langs->load("errors");
$mesg = '<div class="error">'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'</div>';
setEventMessage($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"),'errors');
}
else
{
$mesg = '<div class="error">'.$object->error.'</div>';
setEventMessage($object->error,'errors');
}
}
}
Expand All @@ -723,7 +753,7 @@
}
else
{
dol_print_error($db);
setEventMessage($object->error,'errors');
}
}

Expand All @@ -739,7 +769,7 @@
exit;
}
else {
dol_print_error($db);
setEventMessage($object->error,'errors');
}
}
}
Expand All @@ -765,8 +795,6 @@
{
print_fiche_titre($langs->trans('AddContract'));

dol_htmloutput_errors($mesg,'');

$soc = new Societe($db);
if ($socid>0) $soc->fetch($socid);

Expand Down Expand Up @@ -902,8 +930,13 @@
}

// Other attributes
$parameters=array('colspan' => ' colspan="3"');
$parameters=array('objectsrc' => $objectsrc,'colspan' => ' colspan="3"');
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook

// Other attributes
if (empty($reshook) && ! empty($extrafields->attribute_label)) {
print $object->showOptionals($extrafields, 'edit');
}

print "</table>\n";

Expand Down Expand Up @@ -937,8 +970,6 @@
$result=$object->fetch_thirdparty();
if ($result < 0) dol_print_error($db,$object->error);

dol_htmloutput_errors($mesg,'');

$nbofservices=count($object->lines);

$author = new User($db);
Expand Down Expand Up @@ -1065,6 +1096,50 @@
// Other attributes
$parameters=array('colspan' => ' colspan="3"');
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook

$res = $object->fetch_optionals($object->id, $extralabels);
if (empty($reshook) && ! empty($extrafields->attribute_label)) {
foreach ($extrafields->attribute_label as $key => $label) {
if ($action == 'edit_extras') {
$value = (isset($_POST ["options_" . $key]) ? $_POST ["options_" . $key] : $object->array_options ["options_" . $key]);
} else {
$value = $object->array_options ["options_" . $key];
}
if ($extrafields->attribute_type [$key] == 'separate') {
print $extrafields->showSeparator($key);
} else {
print '<tr><td';
if (! empty($extrafields->attribute_required [$key]))
print ' class="fieldrequired"';
print '>' . $label . '</td><td colspan="5">';
// Convert date into timestamp format
if (in_array($extrafields->attribute_type [$key], array('date','datetime'))) {
$value = isset($_POST ["options_" . $key]) ? dol_mktime($_POST ["options_" . $key . "hour"], $_POST ["options_" . $key . "min"], 0, $_POST ["options_" . $key . "month"], $_POST ["options_" . $key . "day"], $_POST ["options_" . $key . "year"]) : $db->jdate($object->array_options ['options_' . $key]);
}

if ($action == 'edit_extras' && $user->rights->commande->creer && GETPOST('attribute') == $key) {
print '<form enctype="multipart/form-data" action="' . $_SERVER["PHP_SELF"] . '" method="post" name="formcontract">';
print '<input type="hidden" name="action" value="update_extras">';
print '<input type="hidden" name="attribute" value="' . $key . '">';
print '<input type="hidden" name="token" value="' . $_SESSION ['newtoken'] . '">';
print '<input type="hidden" name="id" value="' . $object->id . '">';

print $extrafields->showInputField($key, $value);

print '<input type="submit" class="button" value="' . $langs->trans('Modify') . '">';
print '</form>';
} else {
print $extrafields->showOutputField($key, $value);
if ($object->statut == 0 && $user->rights->commande->creer)
print '<a href="' . $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&action=edit_extras&attribute=' . $key . '">' . img_picto('', 'edit') . ' ' . $langs->trans('Modify') . '</a>';
}
print '</td></tr>' . "\n";
}
}
}




print "</table>";

Expand Down
4 changes: 2 additions & 2 deletions htdocs/core/class/extrafields.class.php
Expand Up @@ -677,7 +677,7 @@ function showInputField($key,$value,$moreparam='',$keyprefix='')
if ($conf->use_javascript_ajax && $conf->global->COMPANY_USE_SEARCH_TO_SELECT && ! $forcecombo)
{
include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
$out.= ajax_combobox('options_'.$key.$keyprefix, $event, $conf->global->COMPANY_USE_SEARCH_TO_SELECT);
$out.= ajax_combobox('options_'.$key.$keyprefix, array(), $conf->global->COMPANY_USE_SEARCH_TO_SELECT);
}

$out.='<select class="flat" name="options_'.$key.$keyprefix.'" id="options_'.$key.$keyprefix.'" '.($moreparam?$moreparam:'').'>';
Expand All @@ -697,7 +697,7 @@ function showInputField($key,$value,$moreparam='',$keyprefix='')
if ($conf->use_javascript_ajax && $conf->global->COMPANY_USE_SEARCH_TO_SELECT && ! $forcecombo)
{
include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
$out.= ajax_combobox('options_'.$key.$keyprefix, $event, $conf->global->COMPANY_USE_SEARCH_TO_SELECT);
$out.= ajax_combobox('options_'.$key.$keyprefix, array(), $conf->global->COMPANY_USE_SEARCH_TO_SELECT);
}

$out.='<select class="flat" name="options_'.$key.$keyprefix.'" id="options_'.$key.$keyprefix.'" '.($moreparam?$moreparam:'').'>';
Expand Down
2 changes: 1 addition & 1 deletion htdocs/core/tpl/objectline_create.tpl.php
Expand Up @@ -31,7 +31,7 @@
$usemargins=0;
if (! empty($conf->margin->enabled) && ! empty($object->element) && in_array($object->element,array('facture','propal','commande'))) $usemargins=1;

global $dateSelector, $forceall, $senderissupplier, $inputalsopricewithtax;
global $forceall, $senderissupplier, $inputalsopricewithtax;
if (empty($dateSelector)) $dateSelector=0;
if (empty($forceall)) $forceall=0;
if (empty($senderissupplier)) $senderissupplier=0;
Expand Down
2 changes: 1 addition & 1 deletion htdocs/core/tpl/objectline_edit.tpl.php
Expand Up @@ -31,7 +31,7 @@
$usemargins=0;
if (! empty($conf->margin->enabled) && ! empty($object->element) && in_array($object->element,array('facture','propal','commande'))) $usemargins=1;

global $dateSelector, $forceall, $senderissupplier, $inputalsopricewithtax;
global $forceall, $senderissupplier, $inputalsopricewithtax;
if (empty($dateSelector)) $dateSelector=0;
if (empty($forceall)) $forceall=0;
if (empty($senderissupplier)) $senderissupplier=0;
Expand Down
8 changes: 8 additions & 0 deletions htdocs/product/class/product.class.php
Expand Up @@ -1392,6 +1392,14 @@ function fetch($id='',$ref='',$ref_ext='')
$this->entity = $obj->entity;

$this->db->free($resql);


// Retreive all extrafield for thirdparty
// fetch optionals attributes and labels
require_once(DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php');
$extrafields=new ExtraFields($this->db);
$extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
$this->fetch_optionals($this->id,$extralabels);


// multilangs
Expand Down

0 comments on commit 851fdf3

Please sign in to comment.