From 7260e139dfac0c5f42b868e0605587dec11ed360 Mon Sep 17 00:00:00 2001 From: jfefe Date: Wed, 6 Mar 2013 04:17:14 +0100 Subject: [PATCH] Add extrafields support when create a customer invoice --- htdocs/compta/facture.php | 13 ++++++++++++ htdocs/compta/facture/class/facture.class.php | 20 ++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 7766cfeb862..26673dbd937 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -7,6 +7,7 @@ * Copyright (C) 2006 Andre Cianfarani * Copyright (C) 2010-2013 Juanjo Menent * Copyright (C) 2012 Christophe Battarel + * Copyright (C) 2013 Jean-Francois FERRY * * 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 @@ -38,6 +39,7 @@ require DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php'; require DOL_DOCUMENT_ROOT . '/core/lib/invoice.lib.php'; require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php'; require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php'; +require DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php'; if (! empty($conf->commande->enabled)) { require DOL_DOCUMENT_ROOT . '/commande/class/commande.class.php'; @@ -87,6 +89,7 @@ $NBLINES=4; $usehm=(! empty($conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE)?$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE:0); $object=new Facture($db); +$extrafields = new ExtraFields($db); // Load object if ($id > 0 || ! empty($ref)) @@ -613,6 +616,15 @@ else if ($action == 'add' && $user->rights->facture->creer) $db->begin(); $error=0; + + // Get extra fields + foreach($_POST as $key => $value) + { + if (preg_match("/^options_/",$key)) + { + $object->array_options[$key]=GETPOST($key); + } + } // Replacement invoice if ($_POST['type'] == 1) @@ -1743,6 +1755,7 @@ $now=dol_now(); if ($action == 'create') { $facturestatic=new Facture($db); + $extralabels=$extrafields->fetch_name_optionals_label('facture'); print_fiche_titre($langs->trans('NewBill')); diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index fd3bb85a69b..31e45d40807 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -135,7 +135,7 @@ class Facture extends CommonInvoice */ function create($user,$notrigger=0,$forceduedate=0) { - global $langs,$conf,$mysoc; + global $langs,$conf,$mysoc,$hookmanager; $error=0; // Clean parameters @@ -437,6 +437,24 @@ class Facture extends CommonInvoice $result=$this->update_price(1); if ($result > 0) { + // 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('invoiceid'=>$this->id); + $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$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=$this->insertExtraFields(); + if ($result < 0) + { + $error++; + } + } + } + else if ($reshook < 0) $error++; + // Appel des triggers include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $interface=new Interfaces($this->db);