Skip to content
Snippets Groups Projects
Commit 7e08ee94 authored by Laurent Destailleur's avatar Laurent Destailleur
Browse files

Merge pull request #1351 from atm-geoffrey/3.5

add extrafields support in supplier orders
parents 1dca56c2 dce354ad
No related branches found
No related tags found
No related merge requests found
......@@ -75,6 +75,10 @@ $result = restrictedArea($user, 'fournisseur', $id, '', 'commande');
$hookmanager->initHooks(array('ordersuppliercard'));
$object = new CommandeFournisseur($db);
$extrafields = new ExtraFields($db);
// fetch optionals attributes and labels
$extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
// Load object
if ($id > 0 || ! empty($ref))
......@@ -692,6 +696,40 @@ else if ($action == 'remove_file' && $object->id > 0 && $user->rights->fournisse
else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
}
elseif ($action == 'update_extras')
{
// Fill array 'array_options' with data from add form
$extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
if($ret < 0)
$error++;
if(!$error) {
// Actions on extra fields (by external module or standard code)
// FIXME le hook fait double emploi avec le trigger !!
$hookmanager->initHooks(array('supplierorderdao'));
$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++;
}
else
{
$action = 'edit_extras';
}
}
/*
* Create an order
*/
......@@ -717,7 +755,10 @@ else if ($action == 'add' && $user->rights->fournisseur->commande->creer)
$object->mode_reglement_id = GETPOST('mode_reglement_id');
$object->note_private = GETPOST('note_private');
$object->note_public = GETPOST('note_public');
// Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
$id = $object->create($user);
if ($id < 0)
{
......@@ -1072,7 +1113,12 @@ if ($action=="create")
// Other options
$parameters=array();
$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))
{
print $object->showOptionals($extrafields,'edit');
}
// Bouton "Create Draft"
print "</table>\n";
......@@ -1089,7 +1135,9 @@ elseif (! empty($object->id))
$title=$langs->trans("SupplierOrder");
dol_fiche_head($head, 'card', $title, 0, 'order');
$res=$object->fetch_optionals($object->id,$extralabels);
/*
* Confirmation de la suppression de la commande
*/
......@@ -1354,7 +1402,70 @@ elseif (! empty($object->id))
// Other attributes
$parameters=array('socid'=>$socid, 'colspan' => ' colspan="3"');
$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 ($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)
{
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->fournisseur->commande->creer)
{
print $extrafields->showInputField($key,$value);
}
else
{
print $extrafields->showOutputField($key,$value);
}
print '</td></tr>'."\n";
}
}
if(count($extrafields->attribute_label) > 0) {
if ($action == 'edit_extras' && $user->rights->fournisseur->commande->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->fournisseur->commande->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>';
}
}
}
}
// Ligne de 3 colonnes
print '<tr><td>'.$langs->trans("AmountHT").'</td>';
print '<td align="right"><b>'.price($object->total_ht).'</b></td>';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment