FIX compatibility with invoice sharing and invoice number sharing

This commit is contained in:
Regis Houssin 2018-11-14 15:24:22 +01:00
parent 3294fada3d
commit 9ff4b31843
3 changed files with 78 additions and 44 deletions

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2005-2008 Laurent Destailleur <eldy@users.sourceforge.net> /* Copyright (C) 2005-2008 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2015 Regis Houssin <regis.houssin@inodbox.com> * Copyright (C) 2005-2018 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es> * Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -145,19 +145,19 @@ class mod_facture_mars extends ModeleNumRefFactures
* Return next value not used or last value used * Return next value not used or last value used
* *
* @param Societe $objsoc Object third party * @param Societe $objsoc Object third party
* @param Facture $facture Object invoice * @param Facture $invoice Object invoice
* @param string $mode 'next' for next value or 'last' for last value * @param string $mode 'next' for next value or 'last' for last value
* @return string Value * @return string Value
*/ */
function getNextValue($objsoc,$facture,$mode='next') function getNextValue($objsoc, $invoice, $mode='next')
{ {
global $db; global $db;
$prefix=$this->prefixinvoice; $prefix=$this->prefixinvoice;
if ($facture->type == 1) $prefix=$this->prefixreplacement; if ($invoice->type == 1) $prefix=$this->prefixreplacement;
else if ($facture->type == 2) $prefix=$this->prefixcreditnote; else if ($invoice->type == 2) $prefix=$this->prefixcreditnote;
else if ($facture->type == 3) $prefix=$this->prefixdeposit; else if ($invoice->type == 3) $prefix=$this->prefixdeposit;
else $prefix=$this->prefixinvoice; else $prefix=$this->prefixinvoice;
// D'abord on recupere la valeur max // D'abord on recupere la valeur max
@ -165,7 +165,7 @@ class mod_facture_mars extends ModeleNumRefFactures
$sql = "SELECT MAX(CAST(SUBSTRING(facnumber FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL $sql = "SELECT MAX(CAST(SUBSTRING(facnumber FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL
$sql.= " FROM ".MAIN_DB_PREFIX."facture"; $sql.= " FROM ".MAIN_DB_PREFIX."facture";
$sql.= " WHERE facnumber LIKE '".$prefix."____-%'"; $sql.= " WHERE facnumber LIKE '".$prefix."____-%'";
$sql.= " AND entity IN (".getEntity('invoicenumber').")"; $sql.= " AND entity IN (".getEntity('invoicenumber', 1, $invoice).")";
$resql=$db->query($sql); $resql=$db->query($sql);
dol_syslog(get_class($this)."::getNextValue", LOG_DEBUG); dol_syslog(get_class($this)."::getNextValue", LOG_DEBUG);
@ -189,7 +189,7 @@ class mod_facture_mars extends ModeleNumRefFactures
$sql = "SELECT facnumber as ref"; $sql = "SELECT facnumber as ref";
$sql.= " FROM ".MAIN_DB_PREFIX."facture"; $sql.= " FROM ".MAIN_DB_PREFIX."facture";
$sql.= " WHERE facnumber LIKE '".$prefix."____-".$num."'"; $sql.= " WHERE facnumber LIKE '".$prefix."____-".$num."'";
$sql.= " AND entity IN (".getEntity('invoicenumber').")"; $sql.= " AND entity IN (".getEntity('invoicenumber', 1, $invoice).")";
dol_syslog(get_class($this)."::getNextValue", LOG_DEBUG); dol_syslog(get_class($this)."::getNextValue", LOG_DEBUG);
$resql=$db->query($sql); $resql=$db->query($sql);
@ -204,7 +204,7 @@ class mod_facture_mars extends ModeleNumRefFactures
} }
else if ($mode == 'next') else if ($mode == 'next')
{ {
$date=$facture->date; // This is invoice date (not creation date) $date=$invoice->date; // This is invoice date (not creation date)
$yymm = strftime("%y%m",$date); $yymm = strftime("%y%m",$date);
if ($max >= (pow(10, 4) - 1)) $num=$max+1; // If counter > 9999, we do not format on 4 chars, we take number as it is if ($max >= (pow(10, 4) - 1)) $num=$max+1; // If counter > 9999, we do not format on 4 chars, we take number as it is

View File

@ -131,43 +131,77 @@ class mod_facture_mercure extends ModeleNumRefFactures
* Return next value * Return next value
* *
* @param Societe $objsoc Object third party * @param Societe $objsoc Object third party
* @param Facture $facture Object invoice * @param Facture $invoice Object invoice
* @param string $mode 'next' for next value or 'last' for last value * @param string $mode 'next' for next value or 'last' for last value
* @return string Value if OK, 0 if KO * @return string Value if OK, 0 if KO
*/ */
function getNextValue($objsoc,$facture,$mode='next') function getNextValue($objsoc, $invoice, $mode='next')
{ {
global $db,$conf; global $db,$conf;
require_once DOL_DOCUMENT_ROOT .'/core/lib/functions2.lib.php'; require_once DOL_DOCUMENT_ROOT .'/core/lib/functions2.lib.php';
// Get Mask value // Get Mask value
$mask = ''; $mask = '';
if (is_object($facture) && $facture->type == 1) if (is_object($invoice) && $invoice->type == 1)
{ {
$mask=$conf->global->FACTURE_MERCURE_MASK_REPLACEMENT; $constant = 'FACTURE_MERCURE_MASK_REPLACEMENT_'.$invoice->entity;
if (! $mask) if (! empty($conf->global->$constant)) {
{ $mask = $conf->global->$constant; // for multicompany proposal sharing
$mask=$conf->global->FACTURE_MERCURE_MASK_INVOICE; } else {
} $mask=$conf->global->FACTURE_MERCURE_MASK_REPLACEMENT;
} }
else if (is_object($facture) && $facture->type == 2) $mask=$conf->global->FACTURE_MERCURE_MASK_CREDIT; if (! $mask)
else if (is_object($facture) && $facture->type == 3) $mask=$conf->global->FACTURE_MERCURE_MASK_DEPOSIT; {
else $mask=$conf->global->FACTURE_MERCURE_MASK_INVOICE; $constant = 'FACTURE_MERCURE_MASK_INVOICE_'.$invoice->entity;
if (! $mask) if (! empty($conf->global->$constant)) {
{ $mask = $conf->global->$constant; // for multicompany proposal sharing
$this->error='NotConfigured'; } else {
return 0; $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';
return 0;
}
$where=''; $where='';
//if ($facture->type == 2) $where.= " AND type = 2"; //if ($facture->type == 2) $where.= " AND type = 2";
//else $where.=" AND type != 2"; //else $where.=" AND type != 2";
$numFinal=get_next_value($db,$mask,'facture','facnumber',$where,$objsoc,$facture->date,$mode); // Get entities
if (! preg_match('/([0-9])+/',$numFinal)) $this->error = $numFinal; $entity = getEntity('invoicenumber', 1, $invoice);
return $numFinal; $numFinal=get_next_value($db,$mask,'facture','facnumber',$where,$objsoc,$facture->date,$mode,false,null,$entity);
if (! preg_match('/([0-9])+/',$numFinal)) $this->error = $numFinal;
return $numFinal;
} }

View File

@ -163,16 +163,16 @@ class mod_facture_terre extends ModeleNumRefFactures
* Return next value not used or last value used * Return next value not used or last value used
* *
* @param Societe $objsoc Object third party * @param Societe $objsoc Object third party
* @param Facture $facture Object invoice * @param Facture $invoice Object invoice
* @param string $mode 'next' for next value or 'last' for last value * @param string $mode 'next' for next value or 'last' for last value
* @return string Value * @return string Value
*/ */
function getNextValue($objsoc,$facture,$mode='next') function getNextValue($objsoc, $invoice, $mode='next')
{ {
global $db; global $db;
if ($facture->type == 2) $prefix=$this->prefixcreditnote; if ($invoice->type == 2) $prefix=$this->prefixcreditnote;
else if ($facture->type == 3) $prefix=$this->prefixdeposit; else if ($invoice->type == 3) $prefix=$this->prefixdeposit;
else $prefix=$this->prefixinvoice; else $prefix=$this->prefixinvoice;
// D'abord on recupere la valeur max // D'abord on recupere la valeur max
@ -180,7 +180,7 @@ class mod_facture_terre extends ModeleNumRefFactures
$sql = "SELECT MAX(CAST(SUBSTRING(facnumber FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL $sql = "SELECT MAX(CAST(SUBSTRING(facnumber FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL
$sql.= " FROM ".MAIN_DB_PREFIX."facture"; $sql.= " FROM ".MAIN_DB_PREFIX."facture";
$sql.= " WHERE facnumber LIKE '".$prefix."____-%'"; $sql.= " WHERE facnumber LIKE '".$prefix."____-%'";
$sql.= " AND entity IN (".getEntity('invoicenumber').")"; $sql.= " AND entity IN (".getEntity('invoicenumber', 1, $invoice).")";
$resql=$db->query($sql); $resql=$db->query($sql);
dol_syslog(get_class($this)."::getNextValue", LOG_DEBUG); dol_syslog(get_class($this)."::getNextValue", LOG_DEBUG);
@ -204,7 +204,7 @@ class mod_facture_terre extends ModeleNumRefFactures
$sql = "SELECT facnumber as ref"; $sql = "SELECT facnumber as ref";
$sql.= " FROM ".MAIN_DB_PREFIX."facture"; $sql.= " FROM ".MAIN_DB_PREFIX."facture";
$sql.= " WHERE facnumber LIKE '".$prefix."____-".$num."'"; $sql.= " WHERE facnumber LIKE '".$prefix."____-".$num."'";
$sql.= " AND entity IN (".getEntity('invoicenumber').")"; $sql.= " AND entity IN (".getEntity('invoicenumber', 1, $invoice).")";
dol_syslog(get_class($this)."::getNextValue", LOG_DEBUG); dol_syslog(get_class($this)."::getNextValue", LOG_DEBUG);
$resql=$db->query($sql); $resql=$db->query($sql);
@ -219,7 +219,7 @@ class mod_facture_terre extends ModeleNumRefFactures
} }
else if ($mode == 'next') else if ($mode == 'next')
{ {
$date=$facture->date; // This is invoice date (not creation date) $date=$invoice->date; // This is invoice date (not creation date)
$yymm = strftime("%y%m",$date); $yymm = strftime("%y%m",$date);
if ($max >= (pow(10, 4) - 1)) $num=$max+1; // If counter > 9999, we do not format on 4 chars, we take number as it is if ($max >= (pow(10, 4) - 1)) $num=$max+1; // If counter > 9999, we do not format on 4 chars, we take number as it is