Edit extrafields on customer invoice

This commit is contained in:
jfefe 2013-03-06 04:54:08 +01:00
parent 7260e139df
commit 3ccb0fb92c

View File

@ -1733,6 +1733,36 @@ if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->facture-
} }
} }
if ($action == 'update_extras')
{
// Get extra fields
foreach($_POST as $key => $value)
{
if (preg_match("/^options_/",$key))
{
$object->array_options[$key]=$_POST[$key];
}
}
// Actions on extra fields (by external module or standard code)
// FIXME le hook fait double emploi avec le trigger !!
$hookmanager->initHooks(array('invoicedao'));
$parameters=array('id'=>$object->id);
$reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
if (empty($reshook))
{
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
{
$result=$object->insertExtraFields();
if ($result < 0)
{
$error++;
}
}
}
else if ($reshook < 0) $error++;
}
/* /*
* View * View
@ -2233,6 +2263,10 @@ else if ($id > 0 || ! empty($ref))
*/ */
$result=$object->fetch($id,$ref); $result=$object->fetch($id,$ref);
// fetch optionals attributes and labels
$extralabels=$extrafields->fetch_name_optionals_label('facture');
if ($result > 0) if ($result > 0)
{ {
if ($user->societe_id>0 && $user->societe_id!=$object->socid) accessforbidden('',0); if ($user->societe_id>0 && $user->societe_id!=$object->socid) accessforbidden('',0);
@ -3043,19 +3077,56 @@ else if ($id > 0 || ! empty($ref))
} }
// Other attributes // Other attributes
$parameters=array('colspan' => ' colspan="3"'); $res=$object->fetch_optionals($object->id,$extralabels);
$parameters=array('colspan' => ' colspan="2"');
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
if (empty($reshook) && ! empty($extrafields->attribute_label)) if (empty($reshook) && ! empty($extrafields->attribute_label))
{ {
if ($action == 'edit_extras')
{
print '<form enctype="multipart/form-data" action="'.$_SERVER["PHP_SELF"].'" method="post" name="formsoc">';
print '<input type="hidden" name="action" value="update_extras">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="id" value="'.$object->id.'">';
}
foreach($extrafields->attribute_label as $key=>$label) foreach($extrafields->attribute_label as $key=>$label)
{ {
$value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]); $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]);
print '<tr><td'; print '<tr><td';
if (! empty($extrafields->attribute_required[$key])) print ' class="fieldrequired"'; if (! empty($extrafields->attribute_required[$key])) print ' class="fieldrequired"';
print '>'.$label.'</td><td colspan="3">'; print '>'.$label.'</td><td colspan="5">';
if ($action == 'edit_extras' && $user->rights->propal->creer)
{
print $extrafields->showInputField($key,$value); print $extrafields->showInputField($key,$value);
}
else
{
print $extrafields->showOutputField($key,$value);
}
print '</td></tr>'."\n"; print '</td></tr>'."\n";
} }
if(count($extrafields->attribute_label) > 0) {
if ($action == 'edit_extras' && $user->rights->propal->creer)
{
print '<tr><td></td><td colspan="5">';
print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
print '</form>';
print '</td></tr>';
}
else {
if ($object->statut == 0 && $user->rights->propal->creer)
{
print '<tr><td></td><td><a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=edit_extras">'.img_picto('','edit').' '.$langs->trans('Modify').'</a></td></tr>';
}
}
}
} }
print '</table><br>'; print '</table><br>';