forked from Wavyzz/dolibarr
manage invoice with multicompany
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user