Skip to content

Commit

Permalink
Merge pull request #8294 from hregis/7.0_bug5
Browse files Browse the repository at this point in the history
Fix: avoid conflict between invoice and invoicenumber sharings
  • Loading branch information
eldy committed Mar 8, 2018
2 parents 7a7c4b8 + a0774d5 commit 343ca1b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
11 changes: 7 additions & 4 deletions htdocs/core/lib/functions2.lib.php
Expand Up @@ -715,9 +715,12 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$m
global $conf,$user;

if (! is_object($objsoc)) $valueforccc=$objsoc;
else if($table == "commande_fournisseur" || $table == "facture_fourn" ) $valueforccc=$objsoc->code_fournisseur;
else if ($table == "commande_fournisseur" || $table == "facture_fourn" ) $valueforccc=$objsoc->code_fournisseur;
else $valueforccc=$objsoc->code_client;

$sharetable = $table;
if ($table == 'facture' || $table == 'invoice') $sharetable = 'invoicenumber'; // for getEntity function

// Clean parameters
if ($date == '') $date=dol_now(); // We use local year and month of PHP server to search numbers
// but we should use local year and month of user
Expand Down Expand Up @@ -979,7 +982,7 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$m
$sql.= " WHERE ".$field." LIKE '".$maskLike."'";
$sql.= " AND ".$field." NOT LIKE '(PROV%)'";
if ($bentityon) // only if entity enable
$sql.= " AND entity IN (".getEntity($table, 1).")";
$sql.= " AND entity IN (".getEntity($sharetable).")";

if ($where) $sql.=$where;
if ($sqlwhere) $sql.=' AND '.$sqlwhere;
Expand Down Expand Up @@ -1027,7 +1030,7 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$m
$sql.= " WHERE ".$field." LIKE '".$maskLike."'";
$sql.= " AND ".$field." NOT LIKE '%PROV%'";
if ($bentityon) // only if entity enable
$sql.= " AND entity IN (".getEntity($table, 1).")";
$sql.= " AND entity IN (".getEntity($sharetable).")";
if ($where) $sql.=$where;
if ($sqlwhere) $sql.=' AND '.$sqlwhere;

Expand Down Expand Up @@ -1081,7 +1084,7 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$m
//$sql.= " WHERE ".$field." not like '(%'";
$maskrefclient_sql.= " WHERE ".$field." LIKE '".$maskrefclient_maskLike."'";
if ($bentityon) // only if entity enable
$maskrefclient_sql.= " AND entity IN (".getEntity($table, 1).")";
$maskrefclient_sql.= " AND entity IN (".getEntity($sharetable).")";
if ($where) $maskrefclient_sql.=$where; //use the same optional where as general mask
if ($sqlwhere) $maskrefclient_sql.=' AND '.$sqlwhere; //use the same sqlwhere as general mask
$maskrefclient_sql.=' AND (SUBSTRING('.$field.', '.(strpos($maskwithnocode,$maskrefclient)+1).', '.dol_strlen($maskrefclient_maskclientcode).")='".$maskrefclient_clientcode."')";
Expand Down
4 changes: 2 additions & 2 deletions htdocs/core/modules/facture/mod_facture_mars.php
Expand Up @@ -153,7 +153,7 @@ function getNextValue($objsoc,$facture,$mode='next')
$sql = "SELECT MAX(CAST(SUBSTRING(facnumber FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL
$sql.= " FROM ".MAIN_DB_PREFIX."facture";
$sql.= " WHERE facnumber LIKE '".$prefix."____-%'";
$sql.= " AND entity IN (".getEntity('facture').")";
$sql.= " AND entity IN (".getEntity('invoicenumber').")";

$resql=$db->query($sql);
dol_syslog(get_class($this)."::getNextValue", LOG_DEBUG);
Expand All @@ -177,7 +177,7 @@ function getNextValue($objsoc,$facture,$mode='next')
$sql = "SELECT facnumber as ref";
$sql.= " FROM ".MAIN_DB_PREFIX."facture";
$sql.= " WHERE facnumber LIKE '".$prefix."____-".$num."'";
$sql.= " AND entity IN (".getEntity('facture').")";
$sql.= " AND entity IN (".getEntity('invoicenumber').")";

dol_syslog(get_class($this)."::getNextValue", LOG_DEBUG);
$resql=$db->query($sql);
Expand Down
4 changes: 2 additions & 2 deletions htdocs/core/modules/facture/mod_facture_terre.php
Expand Up @@ -169,7 +169,7 @@ function getNextValue($objsoc,$facture,$mode='next')
$sql = "SELECT MAX(CAST(SUBSTRING(facnumber FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL
$sql.= " FROM ".MAIN_DB_PREFIX."facture";
$sql.= " WHERE facnumber LIKE '".$prefix."____-%'";
$sql.= " AND entity IN (".getEntity('facture').")";
$sql.= " AND entity IN (".getEntity('invoicenumber').")";

$resql=$db->query($sql);
dol_syslog(get_class($this)."::getNextValue", LOG_DEBUG);
Expand All @@ -193,7 +193,7 @@ function getNextValue($objsoc,$facture,$mode='next')
$sql = "SELECT facnumber as ref";
$sql.= " FROM ".MAIN_DB_PREFIX."facture";
$sql.= " WHERE facnumber LIKE '".$prefix."____-".$num."'";
$sql.= " AND entity IN (".getEntity('facture').")";
$sql.= " AND entity IN (".getEntity('invoicenumber').")";

dol_syslog(get_class($this)."::getNextValue", LOG_DEBUG);
$resql=$db->query($sql);
Expand Down

0 comments on commit 343ca1b

Please sign in to comment.