--- /tmp/dsg/dolibarr/htdocs/core/modules/facture/github_mod_facture_mars.php +++ /tmp/dsg/dolibarr/htdocs/core/modules/facture/client_mod_facture_mars.php @@ -31,9 +31,9 @@ class mod_facture_mars extends ModeleNumRefFactures { /** - * Dolibarr version of the loaded document - * @var string - */ + * Dolibarr version of the loaded document + * @var string + */ public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr' public $prefixinvoice = 'FA'; @@ -146,7 +146,7 @@ * * @param Societe $objsoc Object third party * @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 */ public function getNextValue($objsoc, $invoice, $mode = 'next') @@ -162,7 +162,7 @@ $posindice = strlen($prefix) + 6; $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL $sql .= " FROM ".MAIN_DB_PREFIX."facture"; - $sql .= " WHERE ref LIKE '".$db->escape($prefix)."____-%'"; + $sql .= " WHERE ref LIKE '".$prefix."____-%'"; $sql .= " AND entity IN (".getEntity('invoicenumber', 1, $invoice).")"; $resql = $db->query($sql); @@ -172,54 +172,59 @@ $obj = $db->fetch_object($resql); if ($obj) $max = intval($obj->max); else $max = 0; - } else { + } + else + { return -1; } 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 ($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') { $date = $invoice->date; // This is invoice date (not creation 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 - 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); - } + $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_mod_facture_mercure.php +++ /tmp/dsg/dolibarr/htdocs/core/modules/facture/client_mod_facture_mercure.php @@ -33,156 +33,157 @@ */ class mod_facture_mercure extends ModeleNumRefFactures { - /** - * Dolibarr version of the loaded document - * @var string - */ + /** + * Dolibarr version of the loaded document + * @var string + */ public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr' - /** + /** * @var string Error message */ public $error = ''; - /** - * Returns the description of the numbering model - * - * @return string Texte descripif - */ - public function info() - { - global $db, $conf, $langs; + /** + * Returns the description of the numbering model + * + * @return string Texte descripif + */ + public function info() + { + global $db, $conf, $langs; - $langs->load("bills"); + $langs->load("bills"); - $form = new Form($db); + $form = new Form($db); - $texte = $langs->trans('GenericNumRefModelDesc')."
\n"; - $texte .= '
'; - $texte .= ''; - $texte .= ''; - $texte .= ''; - $texte .= ''; - $texte .= ''; + $texte = $langs->trans('GenericNumRefModelDesc')."
\n"; + $texte .= ''; + $texte .= ''; + $texte .= ''; + $texte .= ''; + $texte .= ''; + $texte .= ''; $texte .= ''; - $texte .= ''; + $texte .= '
'; - $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"); - // Setting the prefix - $texte .= ''; - $texte .= ''; + // Setting the prefix + $texte .= ''; + $texte .= ''; - $texte .= ''; + $texte .= ''; - $texte .= ''; + $texte .= ''; - // Prefix setting of replacement invoices - $texte .= ''; - $texte .= ''; - $texte .= ''; + // Prefix setting of replacement invoices + $texte .= ''; + $texte .= ''; + $texte .= ''; - // Prefix setting of credit note - $texte .= ''; - $texte .= ''; - $texte .= ''; + // Prefix setting of credit note + $texte .= ''; + $texte .= ''; + $texte .= ''; - // Prefix setting of deposit - $texte .= ''; - $texte .= ''; - $texte .= ''; + // Prefix setting of deposit + $texte .= ''; + $texte .= ''; + $texte .= ''; - $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 .= ''; - return $texte; - } + return $texte; + } - /** - * Return an example of number value - * - * @return string Example - */ - public function getExample() - { - global $conf, $langs, $mysoc; + /** + * Return an example of number value + * + * @return string Example + */ + public function getExample() + { + global $conf, $langs, $mysoc; - $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; - if (!$numExample) - { - $numExample = 'NotConfigured'; - } - return $numExample; - } + if (!$numExample) + { + $numExample = 'NotConfigured'; + } + return $numExample; + } - /** - * 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; + /** + * 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; - require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; + require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; - // 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; - } + // 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; + } - $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"; - // Get entities - $entity = getEntity('invoicenumber', 1, $invoice); + // Get entities + $entity = getEntity('invoicenumber', 1, $invoice); - $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; - return $numFinal; - } + return $numFinal; + } - /** - * 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_mod_facture_terre.php +++ /tmp/dsg/dolibarr/htdocs/core/modules/facture/client_mod_facture_terre.php @@ -30,34 +30,34 @@ */ class mod_facture_terre extends ModeleNumRefFactures { - /** - * 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 = ''; + /** + * 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 = ''; /** @@ -177,7 +177,7 @@ * * @param Societe $objsoc Object third party * @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 */ public function getNextValue($objsoc, $invoice, $mode = 'next') @@ -194,7 +194,7 @@ $posindice = strlen($prefix) + 6; $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL $sql .= " FROM ".MAIN_DB_PREFIX."facture"; - $sql .= " WHERE ref LIKE '".$db->escape($prefix)."____-%'"; + $sql .= " WHERE ref LIKE '".$prefix."____-%'"; $sql .= " AND entity IN (".getEntity('invoicenumber', 1, $invoice).")"; $resql = $db->query($sql); @@ -203,53 +203,58 @@ $obj = $db->fetch_object($resql); if ($obj) $max = intval($obj->max); else $max = 0; - } else { + } + else + { return -1; } 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 ($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') { $date = $invoice->date; // This is invoice date (not creation 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 - 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); - } + $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); + } }