diff --git a/ChangeLog b/ChangeLog
index 986e90047cf01718ee124c490e8ee7beb8a67ef2..2a49b467783ed3f2da9caa33b307113200f03834 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,7 @@ English Dolibarr ChangeLog
 ***** ChangeLog for 3.6.3 compared to 3.6.2 *****
 - Fix: ref_ext was not saved when recording a customer order from web service
 - Fix: amarok is a bugged theme making dolidroid failed. We swith to eldy automatically with dolidroid.
+- Fix: withdrawal create error if in the same month are deleted previus withdrawals.
 - Fix: [ bug #1801 ] FAC_FORCE_DATE_VALIDATION constant alters supplier invoice date given to numeration modules
 
 ***** ChangeLog for 3.6.2 compared to 3.6.1 *****
diff --git a/htdocs/compta/prelevement/class/bonprelevement.class.php b/htdocs/compta/prelevement/class/bonprelevement.class.php
index 3a83d9c3dba2d5ce12a77de5b7ea8783e5b4304a..4fe098b87067ef9d6d0de46c3b1779a5812edded 100644
--- a/htdocs/compta/prelevement/class/bonprelevement.class.php
+++ b/htdocs/compta/prelevement/class/bonprelevement.class.php
@@ -1,7 +1,7 @@
 <?php
 /* Copyright (C) 2004-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  * Copyright (C) 2005-2012 Regis Houssin        <regis.houssin@capnetworks.com>
- * Copyright (C) 2010-2014 Juanjo Menent        <jmenent@2byte.es>
+ * Copyright (C) 2010-2015 Juanjo Menent        <jmenent@2byte.es>
  * Copyright (C) 2010-2014 Laurent Destailleur  <eldy@users.sourceforge.net>
  * Copyright (C) 2014 		Ferran Marcet       <fmarcet@2byte.es>
  *
@@ -892,10 +892,11 @@ class BonPrelevement extends CommonObject
             {
                 $ref = "T".substr($year,-2).$month;
 
-                $sql = "SELECT count(*)";
+                $sql = "SELECT CAST(RIGHT(ref,2) AS SIGNED INTEGER)";
                 $sql.= " FROM ".MAIN_DB_PREFIX."prelevement_bons";
                 $sql.= " WHERE ref LIKE '".$ref."%'";
                 $sql.= " AND entity = ".$conf->entity;
+                $sql.= " ORDER BY ref DESC LIMIT 1";
 
                 dol_syslog(get_class($this)."::Create sql=".$sql, LOG_DEBUG);
                 $resql = $this->db->query($sql);