manage invoice with multicompany

This commit is contained in:
atm-quentin 2018-11-07 12:11:19 +01:00
parent 0d443c434e
commit 8e51204dff
4 changed files with 54 additions and 8 deletions

View File

@ -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']);

View File

@ -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);

View File

@ -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';

View File

@ -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);