diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 375288ce754..14f3ea7075f 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -1790,57 +1790,13 @@ if (empty($reshook)) include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php'; - /* - * Generate document - */ - if ($action == 'builddoc') // En get ou en post - { - $object->fetch($id); - $object->fetch_thirdparty(); + // Actions to build doc + $upload_dir = $conf->facture->dir_output; + $permissioncreate=$user->rights->facture->creer; + include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; + - // Save last template used to generate document - if (GETPOST('model')) - $object->setDocModel($user, GETPOST('model', 'alpha')); - if (GETPOST('fk_bank')) { // this field may come from an external module - $object->fk_bank = GETPOST('fk_bank'); - } else { - $object->fk_bank = $object->fk_account; - } - - // Define output language - $outputlangs = $langs; - $newlang = ''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang = GETPOST('lang_id'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; - if (! empty($newlang)) - { - $outputlangs = new Translate("", $conf); - $outputlangs->setDefaultLang($newlang); - } - $result = $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); - if ($result <= 0) - { - setEventMessages($object->error, $object->errors, 'errors'); - $action=''; - } - } - - // Remove file in doc form - else if ($action == 'remove_file') { - if ($object->fetch($id)) { - require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; - - $object->fetch_thirdparty(); - - $langs->load("other"); - $upload_dir = $conf->facture->dir_output; - $file = $upload_dir . '/' . GETPOST('file'); - $ret = dol_delete_file($file, 0, 0, 0, $object); - if ($ret) setEventMessages($langs->trans("FileWasRemoved", GETPOST('urlfile')), null, 'mesgs'); - else setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), null, 'errors'); - $action = ''; - } - } elseif ($action == 'update_extras') { + if ($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, GETPOST('attribute')); diff --git a/htdocs/core/actions_builddoc.inc.php b/htdocs/core/actions_builddoc.inc.php index 9502d723013..2e5d7d71252 100644 --- a/htdocs/core/actions_builddoc.inc.php +++ b/htdocs/core/actions_builddoc.inc.php @@ -51,15 +51,15 @@ if ($action == 'builddoc' && $permissioncreate) // Save last template used to generate document if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha')); - // Special case for invoices - if (property_exists($object, 'fk_bank')) - { + // Special case to force bank account + //if (property_exists($object, 'fk_bank')) + //{ if (GETPOST('fk_bank')) { // this field may come from an external module $object->fk_bank = GETPOST('fk_bank'); - } else { + } else if (! empty($object->fk_account)) { $object->fk_bank = $object->fk_account; } - } + //} $outputlangs = $langs; $newlang='';