27require_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
 
   39  public $version = 
'dolibarr';
 
   45  public $prefixinvoice = 
'FA';
 
   51  public $prefixreplacement = 
'FA';
 
   57  public $prefixcreditnote = 
'AV';
 
   63  public $prefixdeposit = 
'AC';
 
   78    if (((
float) 
getDolGlobalString(
'MAIN_VERSION_LAST_INSTALL')) >= 16.0 && $mysoc->country_code != 
'FR') {
 
   79      $this->prefixinvoice = 
'IN'; 
 
   80      $this->prefixreplacement = 
'IR';
 
   81      $this->prefixdeposit = 
'ID';
 
   82      $this->prefixcreditnote = 
'IC';
 
 
   96  public function info($langs)
 
   99    $langs->load(
"bills");
 
  100    return $langs->trans(
'TerreNumRefModelDesc1', $this->prefixinvoice, $this->prefixcreditnote, $this->prefixdeposit);
 
 
  110    return $this->prefixinvoice.
"0501-0001";
 
 
  122    global $langs, 
$conf, $db;
 
  124    $langs->load(
"bills");
 
  130    $posindice = strlen($this->prefixinvoice) + 6;
 
  131    $sql = 
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max"; 
 
  132    $sql .= 
" FROM ".MAIN_DB_PREFIX.
"facture";
 
  133    $sql .= 
" WHERE ref LIKE '".$db->escape($this->prefixinvoice).
"____-%'";
 
  134    $sql .= 
" AND entity = ".$conf->entity;
 
  136    $resql = $db->query($sql);
 
  138      $row = $db->fetch_row($resql);
 
  140        $fayymm = substr($row[0], 0, 6);
 
  144    if ($fayymm && !preg_match(
'/'.$this->prefixinvoice.
'[0-9][0-9][0-9][0-9]/i', $fayymm)) {
 
  145      $langs->load(
"errors");
 
  146      $this->error = $langs->trans(
'ErrorNumRefModel', $max);
 
  153    $posindice = strlen($this->prefixcreditnote) + 6;
 
  154    $sql = 
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max"; 
 
  155    $sql .= 
" FROM ".MAIN_DB_PREFIX.
"facture";
 
  156    $sql .= 
" WHERE ref LIKE '".$db->escape($this->prefixcreditnote).
"____-%'";
 
  157    $sql .= 
" AND entity = ".$conf->entity;
 
  159    $resql = $db->query($sql);
 
  161      $row = $db->fetch_row($resql);
 
  163        $fayymm = substr($row[0], 0, 6);
 
  167    if ($fayymm && !preg_match(
'/'.$this->prefixcreditnote.
'[0-9][0-9][0-9][0-9]/i', $fayymm)) {
 
  168      $this->error = $langs->trans(
'ErrorNumRefModel', $max);
 
  175    $posindice = strlen($this->prefixdeposit) + 6;
 
  176    $sql = 
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max"; 
 
  177    $sql .= 
" FROM ".MAIN_DB_PREFIX.
"facture";
 
  178    $sql .= 
" WHERE ref LIKE '".$db->escape($this->prefixdeposit).
"____-%'";
 
  179    $sql .= 
" AND entity = ".$conf->entity;
 
  181    $resql = $db->query($sql);
 
  183      $row = $db->fetch_row($resql);
 
  185        $fayymm = substr($row[0], 0, 6);
 
  189    if ($fayymm && !preg_match(
'/'.$this->prefixdeposit.
'[0-9][0-9][0-9][0-9]/i', $fayymm)) {
 
  190      $this->error = $langs->trans(
'ErrorNumRefModel', $max);
 
 
  212    dol_syslog(get_class($this).
"::getNextValue mode=".$mode, LOG_DEBUG);
 
  214    $prefix = $this->prefixinvoice;
 
  215    if ($invoice->type == 2) {
 
  216      $prefix = $this->prefixcreditnote;
 
  217    } elseif ($invoice->type == 3) {
 
  218      $prefix = $this->prefixdeposit;
 
  222    $posindice = strlen($prefix) + 6;
 
  223    $sql = 
"SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.
") AS SIGNED)) as max"; 
 
  224    $sql .= 
" FROM ".MAIN_DB_PREFIX.
"facture";
 
  225    $sql .= 
" WHERE ref LIKE '".$db->escape($prefix).
"____-%'";
 
  226    $sql .= 
" AND entity IN (".getEntity(
'invoicenumber', 1, $invoice).
")";
 
  228    $resql = $db->query($sql);
 
  230      $obj = $db->fetch_object($resql);
 
  232        $max = intval($obj->max);
 
  240    if ($mode == 
'last') {
 
  241      if ($max >= (pow(10, 4) - 1)) {
 
  244        $num = sprintf(
"%04d", $max);
 
  248      $sql = 
"SELECT ref as ref";
 
  249      $sql .= 
" FROM ".MAIN_DB_PREFIX.
"facture";
 
  250      $sql .= 
" WHERE ref LIKE '".$db->escape($prefix).
"____-".$num.
"'";
 
  251      $sql .= 
" AND entity IN (".getEntity(
'invoicenumber', 1, $invoice).
")";
 
  252      $sql .= 
" ORDER BY ref DESC";
 
  254      $resql = $db->query($sql);
 
  256        $obj = $db->fetch_object($resql);
 
  265    } elseif ($mode == 
'next') {
 
  266      $date = $invoice->date; 
 
  269      if ($max >= (pow(10, 4) - 1)) {
 
  272        $num = sprintf(
"%04d", $max + 1);
 
  275      dol_syslog(get_class($this).
"::getNextValue return ".$prefix.$yymm.
"-".$num);
 
  276      return $prefix.$yymm.
"-".$num;
 
 
  293  public function getNumRef($objsoc, $objforref, $mode = 
'next')
 
 
 
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
 
Parent class of invoice reference numbering templates.
 
Class of numbering module Terre for invoices.
 
getNextValue($objsoc, $invoice, $mode='next')
Return next value not used or last value used.
 
info($langs)
Returns the description of the numbering model.
 
getNumRef($objsoc, $objforref, $mode='next')
Return next free value.
 
getExample()
Return an example of numbering.
 
canBeActivated($object)
Checks if the numbers already in the database do not cause conflicts that would prevent this numberin...
 
__construct()
Constructor.
 
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
 
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
 
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
 
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
 
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...