--- /tmp/dsg/dolibarr/htdocs/core/modules/facture/github_19.0.3_mod_facture_mars.php +++ /tmp/dsg/dolibarr/htdocs/core/modules/facture/client_mod_facture_mars.php @@ -34,3 +34,3 @@ - * Dolibarr version of the loaded document - * @var string - */ + * Dolibarr version of the loaded document + * @var string + */ @@ -58,10 +58,2 @@ - global $conf, $mysoc; - - if ((float) $conf->global->MAIN_VERSION_LAST_INSTALL >= 16.0 && $mysoc->country_code != 'FR') { - $this->prefixinvoice = 'IN'; // We use correct standard code "IN = Invoice" - $this->prefixreplacement = 'IR'; - $this->prefixdeposit = 'ID'; - $this->prefixcreditnote = 'IC'; - } - - if (getDolGlobalString('INVOICE_NUMBERING_MARS_FORCE_PREFIX')) { + if (!empty($conf->global->INVOICE_NUMBERING_MARS_FORCE_PREFIX)) + { @@ -75,4 +67,3 @@ - * @param Translate $langs Lang object to use for output - * @return string Descriptive text - */ - public function info($langs) + * @return string Texte descripif + */ + public function info() @@ -99,4 +90,3 @@ - * @param Object $object Object we need next value for - * @return boolean false if conflict, true if ok - */ - public function canBeActivated($object) + * @return boolean false if conflict, true if ok + */ + public function canBeActivated() @@ -109,2 +99 @@ - $fayymm = ''; - $max = ''; + $fayymm = ''; $max = ''; @@ -119 +108,2 @@ - if ($resql) { + if ($resql) + { @@ -121,6 +111,4 @@ - if ($row) { - $fayymm = substr($row[0], 0, 6); - $max = $row[0]; - } - } - if ($fayymm && !preg_match('/'.$this->prefixinvoice.'[0-9][0-9][0-9][0-9]/i', $fayymm)) { + if ($row) { $fayymm = substr($row[0], 0, 6); $max = $row[0]; } + } + if ($fayymm && !preg_match('/'.$this->prefixinvoice.'[0-9][0-9][0-9][0-9]/i', $fayymm)) + { @@ -142 +130,2 @@ - if ($resql) { + if ($resql) + { @@ -144,6 +133,4 @@ - if ($row) { - $fayymm = substr($row[0], 0, 6); - $max = $row[0]; - } - } - if ($fayymm && !preg_match('/'.$this->prefixcreditnote.'[0-9][0-9][0-9][0-9]/i', $fayymm)) { + if ($row) { $fayymm = substr($row[0], 0, 6); $max = $row[0]; } + } + if ($fayymm && !preg_match('/'.$this->prefixcreditnote.'[0-9][0-9][0-9][0-9]/i', $fayymm)) + { @@ -162,2 +149,2 @@ - * @param string $mode 'next' for next value or 'last' for last value - * @return string|int Value if OK, 0 if KO + * @param string $mode 'next' for next value or 'last' for last value + * @return string Value @@ -170,7 +157,3 @@ - if ($invoice->type == 1) { - $prefix = $this->prefixreplacement; - } elseif ($invoice->type == 2) { - $prefix = $this->prefixcreditnote; - } elseif ($invoice->type == 3) { - $prefix = $this->prefixdeposit; - } + if ($invoice->type == 1) $prefix = $this->prefixreplacement; + elseif ($invoice->type == 2) $prefix = $this->prefixcreditnote; + elseif ($invoice->type == 3) $prefix = $this->prefixdeposit; @@ -182 +165 @@ - $sql .= " WHERE ref LIKE '".$db->escape($prefix)."____-%'"; + $sql .= " WHERE ref LIKE '".$prefix."____-%'"; @@ -187 +170,2 @@ - if ($resql) { + if ($resql) + { @@ -189,6 +173,5 @@ - if ($obj) { - $max = intval($obj->max); - } else { - $max = 0; - } - } else { + if ($obj) $max = intval($obj->max); + else $max = 0; + } + else + { @@ -198,27 +181,25 @@ - if ($mode == 'last') { - if ($max >= (pow(10, 4) - 1)) { - $num = $max; // If counter > 9999, we do not format on 4 chars, we take number as it is - } else { - $num = sprintf("%04s", $max); - } - - $ref = ''; - $sql = "SELECT ref as ref"; - $sql .= " FROM ".MAIN_DB_PREFIX."facture"; - $sql .= " WHERE ref LIKE '".$db->escape($prefix)."____-".$num."'"; - $sql .= " AND entity IN (".getEntity('invoicenumber', 1, $invoice).")"; - $sql .= " ORDER BY ref DESC"; - - dol_syslog(get_class($this)."::getNextValue", LOG_DEBUG); - $resql = $db->query($sql); - if ($resql) { - $obj = $db->fetch_object($resql); - if ($obj) { - $ref = $obj->ref; - } - } else { - dol_print_error($db); - } - - return $ref; - } elseif ($mode == 'next') { + if ($mode == 'last') + { + if ($max >= (pow(10, 4) - 1)) $num = $max; // If counter > 9999, we do not format on 4 chars, we take number as it is + else $num = sprintf("%04s", $max); + + $ref = ''; + $sql = "SELECT ref as ref"; + $sql .= " FROM ".MAIN_DB_PREFIX."facture"; + $sql .= " WHERE ref LIKE '".$prefix."____-".$num."'"; + $sql .= " AND entity IN (".getEntity('invoicenumber', 1, $invoice).")"; + $sql .= " ORDER BY ref DESC"; + + dol_syslog(get_class($this)."::getNextValue", LOG_DEBUG); + $resql = $db->query($sql); + if ($resql) + { + $obj = $db->fetch_object($resql); + if ($obj) $ref = $obj->ref; + } + else dol_print_error($db); + + return $ref; + } + elseif ($mode == 'next') + { @@ -226,28 +207,23 @@ - $yymm = dol_print_date($date, "%y%m"); - - 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 - } else { - $num = sprintf("%04s", $max + 1); - } - - dol_syslog(get_class($this)."::getNextValue return ".$prefix.$yymm."-".$num); - return $prefix.$yymm."-".$num; - } else { - dol_print_error('', 'Bad parameter for getNextValue'); - return -1; - } - } - - /** - * Return next free value - * - * @param Societe $objsoc Object third party - * @param string $objforref Object for number to search - * @param string $mode 'next' for next value or 'last' for last value - * @return string Next free value - */ - public function getNumRef($objsoc, $objforref, $mode = 'next') - { - return $this->getNextValue($objsoc, $objforref, $mode); - } + $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 + else $num = sprintf("%04s", $max + 1); + + dol_syslog(get_class($this)."::getNextValue return ".$prefix.$yymm."-".$num); + return $prefix.$yymm."-".$num; + } + else dol_print_error('', 'Bad parameter for getNextValue'); + } + + /** + * Return next free value + * + * @param Societe $objsoc Object third party + * @param string $objforref Object for number to search + * @param string $mode 'next' for next value or 'last' for last value + * @return string Next free value + */ + public function getNumRef($objsoc, $objforref, $mode = 'next') + { + return $this->getNextValue($objsoc, $objforref, $mode); + } --- /tmp/dsg/dolibarr/htdocs/core/modules/facture/github_19.0.3_mod_facture_mercure.php +++ /tmp/dsg/dolibarr/htdocs/core/modules/facture/client_mod_facture_mercure.php @@ -2,6 +2,5 @@ -/* Copyright (C) 2003-2007 Rodolphe Quiedeville - * Copyright (C) 2004-2011 Laurent Destailleur - * Copyright (C) 2005-2007 Regis Houssin - * Copyright (C) 2008 Raphael Bertrand (Resultic) - * Copyright (C) 2013 uanjo Menent - * Copyright (C) 2022 Anthony Berton +/* Copyright (C) 2003-2007 Rodolphe Quiedeville + * Copyright (C) 2004-2011 Laurent Destailleur + * Copyright (C) 2005-2007 Regis Houssin + * Copyright (C) 2008 Raphael Bertrand (Resultic) + * Copyright (C) 2013 Juanjo Menent @@ -37,4 +36,4 @@ - /** - * Dolibarr version of the loaded document - * @var string - */ + /** + * Dolibarr version of the loaded document + * @var string + */ @@ -43 +42 @@ - /** + /** @@ -49,9 +48,8 @@ - /** - * Returns the description of the numbering model - * - * @param Translate $langs Lang object to use for output - * @return string Descriptive text - */ - public function info($langs) - { - global $db, $langs; + /** + * Returns the description of the numbering model + * + * @return string Texte descripif + */ + public function info() + { + global $db, $conf, $langs; @@ -59 +57 @@ - $langs->load("bills"); + $langs->load("bills"); @@ -61 +59 @@ - $form = new Form($db); + $form = new Form($db); @@ -63,7 +61,7 @@ - $texte = $langs->trans('GenericNumRefModelDesc')."
\n"; - $texte .= '
'; - $texte .= ''; - $texte .= ''; - $texte .= ''; - $texte .= ''; - $texte .= ''; + $texte = $langs->trans('GenericNumRefModelDesc')."
\n"; + $texte .= ''; + $texte .= ''; + $texte .= ''; + $texte .= ''; + $texte .= ''; + $texte .= ''; @@ -71 +69 @@ - $texte .= ''; + $texte .= '
'; @@ -73,5 +71,5 @@ - $tooltip = $langs->trans("GenericMaskCodes", $langs->transnoentities("Invoice"), $langs->transnoentities("Invoice")); - $tooltip .= $langs->trans("GenericMaskCodes2"); - $tooltip .= $langs->trans("GenericMaskCodes3"); - $tooltip .= $langs->trans("GenericMaskCodes4a", $langs->transnoentities("Invoice"), $langs->transnoentities("Invoice")); - $tooltip .= $langs->trans("GenericMaskCodes5"); + $tooltip = $langs->trans("GenericMaskCodes", $langs->transnoentities("Invoice"), $langs->transnoentities("Invoice")); + $tooltip .= $langs->trans("GenericMaskCodes2"); + $tooltip .= $langs->trans("GenericMaskCodes3"); + $tooltip .= $langs->trans("GenericMaskCodes4a", $langs->transnoentities("Invoice"), $langs->transnoentities("Invoice")); + $tooltip .= $langs->trans("GenericMaskCodes5"); @@ -79,3 +77,3 @@ - // Setting the prefix - $texte .= ''; - $texte .= ''; + // Setting the prefix + $texte .= ''; + $texte .= ''; @@ -83 +81 @@ - $texte .= ''; + $texte .= ''; @@ -85 +83 @@ - $texte .= ''; + $texte .= ''; @@ -87,4 +85,4 @@ - // Prefix setting of replacement invoices - $texte .= ''; - $texte .= ''; - $texte .= ''; + // Prefix setting of replacement invoices + $texte .= ''; + $texte .= ''; + $texte .= ''; @@ -92,4 +90,4 @@ - // Prefix setting of credit note - $texte .= ''; - $texte .= ''; - $texte .= ''; + // Prefix setting of credit note + $texte .= ''; + $texte .= ''; + $texte .= ''; @@ -97,4 +95,4 @@ - // Prefix setting of deposit - $texte .= ''; - $texte .= ''; - $texte .= ''; + // Prefix setting of deposit + $texte .= ''; + $texte .= ''; + $texte .= ''; @@ -102,2 +100,2 @@ - $texte .= '
'.$langs->trans("Mask").' ('.$langs->trans("InvoiceStandard").'):'.$form->textwithpicto('', $tooltip, 1, 1).'
'.$langs->trans("Mask").' ('.$langs->trans("InvoiceStandard").'):'.$form->textwithpicto('', $tooltip, 1, 1).'   
'.$langs->trans("Mask").' ('.$langs->trans("InvoiceReplacement").'):'.$form->textwithpicto('', $tooltip, 1, 1).'
'.$langs->trans("Mask").' ('.$langs->trans("InvoiceReplacement").'):'.$form->textwithpicto('', $tooltip, 1, 1).'
'.$langs->trans("Mask").' ('.$langs->trans("InvoiceAvoir").'):'.$form->textwithpicto('', $tooltip, 1, 1).'
'.$langs->trans("Mask").' ('.$langs->trans("InvoiceAvoir").'):'.$form->textwithpicto('', $tooltip, 1, 1).'
'.$langs->trans("Mask").' ('.$langs->trans("InvoiceDeposit").'):'.$form->textwithpicto('', $tooltip, 1, 1).'
'.$langs->trans("Mask").' ('.$langs->trans("InvoiceDeposit").'):'.$form->textwithpicto('', $tooltip, 1, 1).'
'; - $texte .= '
'; + $texte .= ''; + $texte .= ''; @@ -105,2 +103,2 @@ - return $texte; - } + return $texte; + } @@ -108,8 +106,8 @@ - /** - * Return an example of number value - * - * @return string Example - */ - public function getExample() - { - global $mysoc; + /** + * Return an example of number value + * + * @return string Example + */ + public function getExample() + { + global $conf, $langs, $mysoc; @@ -117,7 +115,7 @@ - $old_code_client = $mysoc->code_client; - $old_code_type = $mysoc->typent_code; - $mysoc->code_client = 'CCCCCCCCCC'; - $mysoc->typent_code = 'TTTTTTTTTT'; - $numExample = $this->getNextValue($mysoc, ''); - $mysoc->code_client = $old_code_client; - $mysoc->typent_code = $old_code_type; + $old_code_client = $mysoc->code_client; + $old_code_type = $mysoc->typent_code; + $mysoc->code_client = 'CCCCCCCCCC'; + $mysoc->typent_code = 'TTTTTTTTTT'; + $numExample = $this->getNextValue($mysoc, ''); + $mysoc->code_client = $old_code_client; + $mysoc->typent_code = $old_code_type; @@ -125,5 +123,6 @@ - if (!$numExample) { - $numExample = 'NotConfigured'; - } - return $numExample; - } + if (!$numExample) + { + $numExample = 'NotConfigured'; + } + return $numExample; + } @@ -131,11 +130,11 @@ - /** - * Return next value - * - * @param Societe $objsoc Object third party - * @param Facture $invoice Object invoice - * @param string $mode 'next' for next value or 'last' for last value - * @return string Value if OK, 0 if KO - */ - public function getNextValue($objsoc, $invoice, $mode = 'next') - { - global $db; + /** + * Return next value + * + * @param Societe $objsoc Object third party + * @param Facture $invoice Object invoice + * @param string $mode 'next' for next value or 'last' for last value + * @return string Value if OK, 0 if KO + */ + public function getNextValue($objsoc, $invoice, $mode = 'next') + { + global $db, $conf; @@ -143 +142 @@ - require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; + require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; @@ -145,15 +144,18 @@ - // Get Mask value - $mask = ''; - if (is_object($invoice) && $invoice->type == 1) { - $mask = getDolGlobalString('FACTURE_MERCURE_MASK_REPLACEMENT', getDolGlobalString('FACTURE_MERCURE_MASK_INVOICE')); - } elseif (is_object($invoice) && $invoice->type == 2) { - $mask = getDolGlobalString('FACTURE_MERCURE_MASK_CREDIT'); - } elseif (is_object($invoice) && $invoice->type == 3) { - $mask = getDolGlobalString('FACTURE_MERCURE_MASK_DEPOSIT'); - } else { - $mask = getDolGlobalString('FACTURE_MERCURE_MASK_INVOICE'); - } - if (!$mask) { - $this->error = 'NotConfigured'; - return 0; - } + // Get Mask value + $mask = ''; + if (is_object($invoice) && $invoice->type == 1) + { + $mask = $conf->global->FACTURE_MERCURE_MASK_REPLACEMENT; + if (!$mask) + { + $mask = $conf->global->FACTURE_MERCURE_MASK_INVOICE; + } + } + elseif (is_object($invoice) && $invoice->type == 2) $mask = $conf->global->FACTURE_MERCURE_MASK_CREDIT; + elseif (is_object($invoice) && $invoice->type == 3) $mask = $conf->global->FACTURE_MERCURE_MASK_DEPOSIT; + else $mask = $conf->global->FACTURE_MERCURE_MASK_INVOICE; + if (!$mask) + { + $this->error = 'NotConfigured'; + return 0; + } @@ -161,3 +163,3 @@ - $where = ''; - //if ($facture->type == 2) $where.= " AND type = 2"; - //else $where.=" AND type != 2"; + $where = ''; + //if ($facture->type == 2) $where.= " AND type = 2"; + //else $where.=" AND type != 2"; @@ -165,2 +167,2 @@ - // Get entities - $entity = getEntity('invoicenumber', 1, $invoice); + // Get entities + $entity = getEntity('invoicenumber', 1, $invoice); @@ -168,4 +170,2 @@ - $numFinal = get_next_value($db, $mask, 'facture', 'ref', $where, $objsoc, $invoice->date, $mode, false, null, $entity); - if (!preg_match('/([0-9])+/', $numFinal)) { - $this->error = $numFinal; - } + $numFinal = get_next_value($db, $mask, 'facture', 'ref', $where, $objsoc, $invoice->date, $mode, false, null, $entity); + if (!preg_match('/([0-9])+/', $numFinal)) $this->error = $numFinal; @@ -173,2 +173,2 @@ - return $numFinal; - } + return $numFinal; + } @@ -177,12 +177,12 @@ - /** - * Return next free value - * - * @param Societe $objsoc Object third party - * @param string $objforref Object for number to search - * @param string $mode 'next' for next value or 'last' for last value - * @return string Next free value - */ - public function getNumRef($objsoc, $objforref, $mode = 'next') - { - return $this->getNextValue($objsoc, $objforref, $mode); - } + /** + * Return next free value + * + * @param Societe $objsoc Object third party + * @param string $objforref Object for number to search + * @param string $mode 'next' for next value or 'last' for last value + * @return string Next free value + */ + public function getNumRef($objsoc, $objforref, $mode = 'next') + { + return $this->getNextValue($objsoc, $objforref, $mode); + } --- /tmp/dsg/dolibarr/htdocs/core/modules/facture/github_19.0.3_mod_facture_terre.php +++ /tmp/dsg/dolibarr/htdocs/core/modules/facture/client_mod_facture_terre.php @@ -33,34 +33,28 @@ - /** - * Dolibarr version of the loaded document 'development', 'experimental', 'dolibarr' - * @var string - */ - public $version = 'dolibarr'; - - /** - * Prefix for invoices - * @var string - */ - public $prefixinvoice = 'FA'; - - /** - * Prefix for replacement invoices - * @var string - */ - public $prefixreplacement = 'FA'; - - /** - * Prefix for credit note - * @var string - */ - public $prefixcreditnote = 'AV'; - - /** - * Prefix for deposit - * @var string - */ - public $prefixdeposit = 'AC'; - - /** - * @var string Error code (or message) - */ - public $error = ''; + /** + * Dolibarr version of the loaded document 'development', 'experimental', 'dolibarr' + * @var string + */ + public $version = 'dolibarr'; + + /** + * Prefix for invoices + * @var string + */ + public $prefixinvoice = 'FA'; + + /** + * Prefix for credit note + * @var string + */ + public $prefixcreditnote = 'AV'; + + /** + * Prefix for deposit + * @var string + */ + public $prefixdeposit = 'AC'; + + /** + * @var string Error code (or message) + */ + public $error = ''; @@ -74,10 +68,2 @@ - global $conf, $mysoc; - - if (((float) getDolGlobalString('MAIN_VERSION_LAST_INSTALL')) >= 16.0 && $mysoc->country_code != 'FR') { - $this->prefixinvoice = 'IN'; // We use correct standard code "IN = Invoice" - $this->prefixreplacement = 'IR'; - $this->prefixdeposit = 'ID'; - $this->prefixcreditnote = 'IC'; - } - - if (getDolGlobalString('INVOICE_NUMBERING_TERRE_FORCE_PREFIX')) { + if (!empty($conf->global->INVOICE_NUMBERING_TERRE_FORCE_PREFIX)) + { @@ -91,4 +77,3 @@ - * @param Translate $langs Lang object to use for output - * @return string Descriptive text - */ - public function info($langs) + * @return string Texte descripif + */ + public function info() @@ -115,4 +100,3 @@ - * @param Object $object Object we need next value for - * @return boolean false if conflict, true if ok - */ - public function canBeActivated($object) + * @return boolean false if conflict, true if ok + */ + public function canBeActivated() @@ -125,2 +109 @@ - $fayymm = ''; - $max = ''; + $fayymm = ''; $max = ''; @@ -135 +118,2 @@ - if ($resql) { + if ($resql) + { @@ -137,6 +121,4 @@ - if ($row) { - $fayymm = substr($row[0], 0, 6); - $max = $row[0]; - } - } - if ($fayymm && !preg_match('/'.$this->prefixinvoice.'[0-9][0-9][0-9][0-9]/i', $fayymm)) { + if ($row) { $fayymm = substr($row[0], 0, 6); $max = $row[0]; } + } + if ($fayymm && !preg_match('/'.$this->prefixinvoice.'[0-9][0-9][0-9][0-9]/i', $fayymm)) + { @@ -158 +140,2 @@ - if ($resql) { + if ($resql) + { @@ -160,6 +143,4 @@ - if ($row) { - $fayymm = substr($row[0], 0, 6); - $max = $row[0]; - } - } - if ($fayymm && !preg_match('/'.$this->prefixcreditnote.'[0-9][0-9][0-9][0-9]/i', $fayymm)) { + if ($row) { $fayymm = substr($row[0], 0, 6); $max = $row[0]; } + } + if ($fayymm && !preg_match('/'.$this->prefixcreditnote.'[0-9][0-9][0-9][0-9]/i', $fayymm)) + { @@ -180 +161,2 @@ - if ($resql) { + if ($resql) + { @@ -182,6 +164,4 @@ - if ($row) { - $fayymm = substr($row[0], 0, 6); - $max = $row[0]; - } - } - if ($fayymm && !preg_match('/'.$this->prefixdeposit.'[0-9][0-9][0-9][0-9]/i', $fayymm)) { + if ($row) { $fayymm = substr($row[0], 0, 6); $max = $row[0]; } + } + if ($fayymm && !preg_match('/'.$this->prefixdeposit.'[0-9][0-9][0-9][0-9]/i', $fayymm)) + { @@ -196,4 +176 @@ - * Return next value not used or last value used. - * Note to increase perf of this numbering engine, you can create a calculated column and modify request to use this field instead for select: - * ALTER TABLE llx_facture ADD COLUMN calculated_numrefonly INTEGER AS (CASE SUBSTRING(ref FROM 1 FOR 2) WHEN 'FA' THEN CAST(SUBSTRING(ref FROM 10) AS SIGNED) ELSE 0 END) PERSISTENT; - * ALTER TABLE llx_facture ADD INDEX calculated_numrefonly_idx (calculated_numrefonly); + * Return next value not used or last value used @@ -203,2 +180,2 @@ - * @param string $mode 'next' for next value or 'last' for last value - * @return string Next ref value or last ref if $mode is 'last', <= 0 if KO + * @param string $mode 'next' for next value or 'last' for last value + * @return string Value @@ -213,5 +190,2 @@ - if ($invoice->type == 2) { - $prefix = $this->prefixcreditnote; - } elseif ($invoice->type == 3) { - $prefix = $this->prefixdeposit; - } + if ($invoice->type == 2) $prefix = $this->prefixcreditnote; + elseif ($invoice->type == 3) $prefix = $this->prefixdeposit; @@ -223 +197 @@ - $sql .= " WHERE ref LIKE '".$db->escape($prefix)."____-%'"; + $sql .= " WHERE ref LIKE '".$prefix."____-%'"; @@ -227 +201,2 @@ - if ($resql) { + if ($resql) + { @@ -229,6 +204,5 @@ - if ($obj) { - $max = intval($obj->max); - } else { - $max = 0; - } - } else { + if ($obj) $max = intval($obj->max); + else $max = 0; + } + else + { @@ -238,26 +212,24 @@ - if ($mode == 'last') { - if ($max >= (pow(10, 4) - 1)) { - $num = $max; // If counter > 9999, we do not format on 4 chars, we take number as it is - } else { - $num = sprintf("%04s", $max); - } - - $ref = ''; - $sql = "SELECT ref as ref"; - $sql .= " FROM ".MAIN_DB_PREFIX."facture"; - $sql .= " WHERE ref LIKE '".$db->escape($prefix)."____-".$num."'"; - $sql .= " AND entity IN (".getEntity('invoicenumber', 1, $invoice).")"; - $sql .= " ORDER BY ref DESC"; - - $resql = $db->query($sql); - if ($resql) { - $obj = $db->fetch_object($resql); - if ($obj) { - $ref = $obj->ref; - } - } else { - dol_print_error($db); - } - - return $ref; - } elseif ($mode == 'next') { + if ($mode == 'last') + { + if ($max >= (pow(10, 4) - 1)) $num = $max; // If counter > 9999, we do not format on 4 chars, we take number as it is + else $num = sprintf("%04s", $max); + + $ref = ''; + $sql = "SELECT ref as ref"; + $sql .= " FROM ".MAIN_DB_PREFIX."facture"; + $sql .= " WHERE ref LIKE '".$prefix."____-".$num."'"; + $sql .= " AND entity IN (".getEntity('invoicenumber', 1, $invoice).")"; + $sql .= " ORDER BY ref DESC"; + + $resql = $db->query($sql); + if ($resql) + { + $obj = $db->fetch_object($resql); + if ($obj) $ref = $obj->ref; + } + else dol_print_error($db); + + return $ref; + } + elseif ($mode == 'next') + { @@ -265,29 +237,23 @@ - $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 - } else { - $num = sprintf("%04s", $max + 1); - } - - dol_syslog(get_class($this)."::getNextValue return ".$prefix.$yymm."-".$num); - return $prefix.$yymm."-".$num; - } else { - dol_print_error('', 'Bad parameter for getNextValue'); - } - - return 0; - } - - /** - * Return next free value - * - * @param Societe $objsoc Object third party - * @param string $objforref Object for number to search - * @param string $mode 'next' for next value or 'last' for last value - * @return string Next free value - */ - public function getNumRef($objsoc, $objforref, $mode = 'next') - { - return $this->getNextValue($objsoc, $objforref, $mode); - } + $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 + else $num = sprintf("%04s", $max + 1); + + dol_syslog(get_class($this)."::getNextValue return ".$prefix.$yymm."-".$num); + return $prefix.$yymm."-".$num; + } + else dol_print_error('', 'Bad parameter for getNextValue'); + } + + /** + * Return next free value + * + * @param Societe $objsoc Object third party + * @param string $objforref Object for number to search + * @param string $mode 'next' for next value or 'last' for last value + * @return string Next free value + */ + public function getNumRef($objsoc, $objforref, $mode = 'next') + { + return $this->getNextValue($objsoc, $objforref, $mode); + }