From dce354adc33960de4d08a0512074c05348b19217 Mon Sep 17 00:00:00 2001 From: Geoffrey Date: Mon, 16 Dec 2013 11:13:39 +0100 Subject: [PATCH] add extrafields support in supplier orders. managed in configuration but not in view mode --- htdocs/fourn/commande/fiche.php | 117 +++++++++++++++++++++++++++++++- 1 file changed, 114 insertions(+), 3 deletions(-) diff --git a/htdocs/fourn/commande/fiche.php b/htdocs/fourn/commande/fiche.php index 8c87e754bc4ba..cdb8b4f93a6a4 100644 --- a/htdocs/fourn/commande/fiche.php +++ b/htdocs/fourn/commande/fiche.php @@ -75,6 +75,10 @@ $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 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 @@ $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 @@ // 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 "\n"; @@ -1089,7 +1135,9 @@ $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 @@ // 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 '
'; + print ''; + print ''; + print ''; + } + 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 'attribute_required[$key])) print ' class="fieldrequired"'; + print '>'.$label.''; + // 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 ''."\n"; + } + } + + if(count($extrafields->attribute_label) > 0) { + + if ($action == 'edit_extras' && $user->rights->fournisseur->commande->creer) + { + print ''; + print ''; + print ''; + print ''; + + } + else { + if ($object->statut == 0 && $user->rights->fournisseur->commande->creer) + { + print ''.img_picto('','edit').' '.$langs->trans('Modify').''; + } + } + } + } + // Ligne de 3 colonnes print ''.$langs->trans("AmountHT").''; print ''.price($object->total_ht).'';