2
0
forked from Wavyzz/dolibarr

Fix: Numbering errors

This commit is contained in:
Laurent Destailleur
2008-07-08 22:29:34 +00:00
parent 1c43e655dc
commit 940cf2bc31
3 changed files with 18 additions and 51 deletions

View File

@@ -1,5 +1,5 @@
<?php
/* Copyright (C) 2005 Laurent Destailleur <eldy@users.sourceforge.net>
/* Copyright (C) 2005-2008 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2006 Regis Houssin <regis@dolibarr.fr>
*
* This program is free software; you can redistribute it and/or modify
@@ -93,16 +93,17 @@ class mod_commande_marbre extends ModeleNumRefCommandes
global $db;
// D'abord on r<>cup<75>re la valeur max (r<>ponse imm<6D>diate car champ ind<6E>x<EFBFBD>)
$coyymm='';
$sql = "SELECT MAX(ref)";
$posindice=8;
$sql = "SELECT MAX(0+SUBSTRING(ref,".$posindice.")) as max";
$sql.= " FROM ".MAIN_DB_PREFIX."commande";
$sql.= " WHERE ref like '".$this->prefix."%'";
$resql=$db->query($sql);
if ($resql)
{
$row = $db->fetch_row($resql);
if ($row) $coyymm = substr($row[0],0,6);
$obj = $db->fetch_object($resql);
if ($obj) $max = $obj->max;
else $max=0;
}
else
{
@@ -110,25 +111,6 @@ class mod_commande_marbre extends ModeleNumRefCommandes
return -1;
}
// Si champ respectant le mod<6F>le a <20>t<EFBFBD> trouv<75>e
if (eregi('^'.$this->prefix.'[0-9][0-9][0-9][0-9]',$coyymm))
{
// Recherche rapide car restreint par un like sur champ index<65>
$posindice=8;
$sql = "SELECT MAX(0+SUBSTRING(ref,$posindice))";
$sql.= " FROM ".MAIN_DB_PREFIX."commande";
$sql.= " WHERE ref like '${coyymm}%'";
$resql=$db->query($sql);
if ($resql)
{
$row = $db->fetch_row($resql);
$max = $row[0];
}
}
else
{
$max=0;
}
//$date=time();
$date=$commande->date;
$yymm = strftime("%y%m",$date);

View File

@@ -121,7 +121,7 @@ class mod_facture_terre extends ModeleNumRefFactures
// D'abord on r<>cup<75>re la valeur max (r<>ponse imm<6D>diate car champ ind<6E>x<EFBFBD>)
$posindice=8;
$sql = "SELECT MAX(facnumber+SUBSTRING(facnumber,".$posindice.")) as ref";
$sql = "SELECT MAX(0+SUBSTRING(facnumber,".$posindice.")) as max";
$sql.= " FROM ".MAIN_DB_PREFIX."facture";
$sql.= " WHERE facnumber like '".$prefix."%'";
@@ -129,7 +129,7 @@ class mod_facture_terre extends ModeleNumRefFactures
if ($resql)
{
$obj = $db->fetch_object($resql);
if ($obj) $max = $obj->ref;
if ($obj) $max = $obj->max;
else $max=0;
}
else

View File

@@ -95,14 +95,17 @@ class mod_propale_marbre extends ModeleNumRefPropales
global $db;
// D'abord on r<>cup<75>re la valeur max (r<>ponse imm<6D>diate car champ ind<6E>x<EFBFBD>)
$pryymm='';
$sql = "SELECT MAX(ref)";
$posindice=8;
$sql = "SELECT MAX(0+SUBSTRING(ref,".$posindice.")) as max";
$sql.= " FROM ".MAIN_DB_PREFIX."propal";
$sql.= " WHERE ref like '".$this->prefix."%'";
$resql=$db->query($sql);
if ($resql)
{
$row = $db->fetch_row($resql);
if ($row) $pryymm = substr($row[0],0,6);
$obj = $db->fetch_object($resql);
if ($obj) $max = $obj->max;
else $max=0;
}
else
{
@@ -110,27 +113,9 @@ class mod_propale_marbre extends ModeleNumRefPropales
return -1;
}
// Si champ respectant le mod<6F>le a <20>t<EFBFBD> trouv<75>e
if (eregi('^'.$this->prefix.'[0-9][0-9][0-9][0-9]',$pryymm))
{
// Recherche rapide car restreint par un like sur champ index<65>
$posindice=8;
$sql = "SELECT MAX(0+SUBSTRING(ref,".$posindice."))";
$sql.= " FROM ".MAIN_DB_PREFIX."propal";
$sql.= " WHERE ref like '".$pryymm."%'";
$resql=$db->query($sql);
if ($resql)
{
$row = $db->fetch_row($resql);
$max = $row[0];
}
}
else
{
$max=0;
}
$date=$propal->date;
//$yymm = strftime("%y%m",time());
$yymm = strftime("%y%m",$propal->date);
$yymm = strftime("%y%m",$date);
$num = sprintf("%04s",$max+1);
dolibarr_syslog("mod_propale_marbre::getNextValue return ".$this->prefix.$yymm."-".$num);