diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 227ae42b266..7c8a02ba693 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -947,7 +947,7 @@ class Facture extends CommonInvoice */ function createFromClone($socid=0) { - global $user,$hookmanager; + global $user,$hookmanager, $conf; $error=0; @@ -996,6 +996,7 @@ class Facture extends CommonInvoice $this->close_code = ''; $this->close_note = ''; $this->products = $this->lines; // Tant que products encore utilise + $this->entity = $conf->entity; // Loop on each line of new invoice foreach($this->lines as $i => $line) @@ -3348,7 +3349,16 @@ class Facture extends CommonInvoice $mybool=false; $file = $conf->global->FACTURE_ADDON.".php"; - $classname = $conf->global->FACTURE_ADDON; + + $constant = 'FACTURE_ADDON_'.$this->entity; + + if (! empty($conf->global->$constant)) { + $classname = $conf->global->$constant; // for multicompany proposal sharing + } else { + $classname = $conf->global->FACTURE_ADDON; + } + + // Include file with class $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); diff --git a/htdocs/core/modules/facture/mod_facture_mars.php b/htdocs/core/modules/facture/mod_facture_mars.php index 19161ae1325..d9ff514d42d 100644 --- a/htdocs/core/modules/facture/mod_facture_mars.php +++ b/htdocs/core/modules/facture/mod_facture_mars.php @@ -151,7 +151,7 @@ class mod_facture_mars extends ModeleNumRefFactures */ function getNextValue($objsoc, $invoice, $mode='next') { - global $db; + global $db, $conf; $prefix=$this->prefixinvoice; @@ -160,12 +160,14 @@ class mod_facture_mars extends ModeleNumRefFactures else if ($invoice->type == 3) $prefix=$this->prefixdeposit; else $prefix=$this->prefixinvoice; + $entity = ((isset($$invoice->entity) && is_numeric($$invoice->entity)) ? $$invoice->entity : $conf->entity); + // D'abord on recupere la valeur max $posindice=8; $sql = "SELECT MAX(CAST(SUBSTRING(facnumber FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL $sql.= " FROM ".MAIN_DB_PREFIX."facture"; $sql.= " WHERE facnumber LIKE '".$prefix."____-%'"; - $sql.= " AND entity IN (".getEntity('invoicenumber', 1, $invoice).")"; + $sql.= " AND entity = $entity"; $resql=$db->query($sql); dol_syslog(get_class($this)."::getNextValue", LOG_DEBUG); diff --git a/htdocs/core/modules/facture/mod_facture_mercure.php b/htdocs/core/modules/facture/mod_facture_mercure.php index 88217172c76..032112af70d 100644 --- a/htdocs/core/modules/facture/mod_facture_mercure.php +++ b/htdocs/core/modules/facture/mod_facture_mercure.php @@ -145,15 +145,46 @@ class mod_facture_mercure extends ModeleNumRefFactures $mask = ''; if (is_object($invoice) && $invoice->type == 1) { + $constant = 'FACTURE_MERCURE_MASK_REPLACEMENT_'.$invoice->entity; + if (! empty($conf->global->$constant)) { + $mask = $conf->global->$constant; // for multicompany proposal sharing + } else { $mask=$conf->global->FACTURE_MERCURE_MASK_REPLACEMENT; + } if (! $mask) { + $constant = 'FACTURE_MERCURE_MASK_INVOICE_'.$invoice->entity; + if (! empty($conf->global->$constant)) { + $mask = $conf->global->$constant; // for multicompany proposal sharing + } else { $mask=$conf->global->FACTURE_MERCURE_MASK_INVOICE; } } - else if (is_object($invoice) && $invoice->type == 2) $mask=$conf->global->FACTURE_MERCURE_MASK_CREDIT; - else if (is_object($invoice) && $invoice->type == 3) $mask=$conf->global->FACTURE_MERCURE_MASK_DEPOSIT; - else $mask=$conf->global->FACTURE_MERCURE_MASK_INVOICE; + } + else if (is_object($invoice) && $invoice->type == 2){ + $constant = 'FACTURE_MERCURE_MASK_CREDIT_'.$invoice->entity; + if (! empty($conf->global->$constant)) { + $mask = $conf->global->$constant; // for multicompany proposal sharing + } else { + $mask=$conf->global->FACTURE_MERCURE_MASK_CREDIT; + } + } + else if (is_object($invoice) && $invoice->type == 3){ + $constant = 'FACTURE_MERCURE_MASK_DEPOSIT_'.$invoice->entity; + if (! empty($conf->global->$constant)) { + $mask = $conf->global->$constant; // for multicompany proposal sharing + } else { + $mask=$conf->global->FACTURE_MERCURE_MASK_DEPOSIT; + } + } + else { + $constant = 'FACTURE_MERCURE_MASK_INVOICE_'.$invoice->entity; + if (! empty($conf->global->$constant)) { + $mask = $conf->global->$constant; // for multicompany proposal sharing + } else { + $mask=$conf->global->FACTURE_MERCURE_MASK_INVOICE; + } + } if (! $mask) { $this->error='NotConfigured'; diff --git a/htdocs/core/modules/facture/mod_facture_terre.php b/htdocs/core/modules/facture/mod_facture_terre.php index 1c19d564486..697827ceb6f 100644 --- a/htdocs/core/modules/facture/mod_facture_terre.php +++ b/htdocs/core/modules/facture/mod_facture_terre.php @@ -175,12 +175,15 @@ class mod_facture_terre extends ModeleNumRefFactures else if ($invoice->type == 3) $prefix=$this->prefixdeposit; else $prefix=$this->prefixinvoice; + // D'abord on recupere la valeur max + $entity = ((isset($invoice->entity) && is_numeric($invoice->entity)) ? $invoice->entity : $conf->entity); + // D'abord on recupere la valeur max $posindice=8; $sql = "SELECT MAX(CAST(SUBSTRING(facnumber FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL $sql.= " FROM ".MAIN_DB_PREFIX."facture"; $sql.= " WHERE facnumber LIKE '".$prefix."____-%'"; - $sql.= " AND entity IN (".getEntity('invoicenumber', 1, $invoice).")"; + $sql.= " AND entity = $entity"; $resql=$db->query($sql); dol_syslog(get_class($this)."::getNextValue", LOG_DEBUG);