diff --git a/htdocs/admin/facture.php b/htdocs/admin/facture.php
index c4c8c19169da8cbeb83e9f653c35ff76e4acd9d4..214d1ad7c0a4f6df75279b26452500bdb7b09e47 100644
--- a/htdocs/admin/facture.php
+++ b/htdocs/admin/facture.php
@@ -53,10 +53,13 @@ if ($action == 'updateMask')
 {
     $maskconstinvoice=GETPOST('maskconstinvoice','alpha');
     $maskconstcredit=GETPOST('maskconstcredit','alpha');
+	$maskconstdeposit=GETPOST('maskconstdeposit','alpha');
     $maskinvoice=GETPOST('maskinvoice','alpha');
     $maskcredit=GETPOST('maskcredit','alpha');
+	$maskdeposit=GETPOST('maskdeposit','alpha');
     if ($maskconstinvoice) $res = dolibarr_set_const($db,$maskconstinvoice,$maskinvoice,'chaine',0,'',$conf->entity);
     if ($maskconstcredit)  $res = dolibarr_set_const($db,$maskconstcredit,$maskcredit,'chaine',0,'',$conf->entity);
+	if ($maskconstdeposit)  $res = dolibarr_set_const($db,$maskconstdeposit,$maskdeposit,'chaine',0,'',$conf->entity);
 
 	if (! $res > 0) $error++;
 
@@ -387,6 +390,21 @@ foreach ($dirmodels as $reldir)
                             {
                                 $htmltooltip.=$langs->trans("NextValueForCreditNotes").': ';
                                 if ($nextval)
+                                {
+                                    $htmltooltip.=$nextval.'<br>';
+                                }
+                                else
+                                {
+                                    $htmltooltip.=$langs->trans($module->error).'<br>';
+                                }
+                            }
+                            // Example for deposit invoice
+                            $facture->type=3;
+                            $nextval=$module->getNextValue($mysoc,$facture);
+                            if ("$nextval" != $langs->trans("NotAvailable"))	// Keep " on nextval
+                            {
+                                $htmltooltip.=$langs->trans("NextValueForDeposit").': ';
+                                if ($nextval)
                                 {
                                     $htmltooltip.=$nextval;
                                 }
diff --git a/htdocs/core/modules/facture/mod_facture_mercure.php b/htdocs/core/modules/facture/mod_facture_mercure.php
index 405908bd872c73f1dacc9d325c423d90a5dc016e..2d8fed55213b77932e51053bd4da889c9d7d3596 100644
--- a/htdocs/core/modules/facture/mod_facture_mercure.php
+++ b/htdocs/core/modules/facture/mod_facture_mercure.php
@@ -56,6 +56,7 @@ class mod_facture_mercure extends ModeleNumRefFactures
         $texte.= '<input type="hidden" name="action" value="updateMask">';
         $texte.= '<input type="hidden" name="maskconstinvoice" value="FACTURE_MERCURE_MASK_INVOICE">';
         $texte.= '<input type="hidden" name="maskconstcredit" value="FACTURE_MERCURE_MASK_CREDIT">';
+		$texte.= '<input type="hidden" name="maskconstdeposit" value="FACTURE_MERCURE_MASK_DEPOSIT">';
         $texte.= '<table class="nobordernopadding" width="100%">';
 
         $tooltip=$langs->trans("GenericMaskCodes",$langs->transnoentities("Invoice"),$langs->transnoentities("Invoice"));
@@ -68,7 +69,7 @@ class mod_facture_mercure extends ModeleNumRefFactures
         $texte.= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("InvoiceStandard").'):</td>';
         $texte.= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="maskinvoice" value="'.$conf->global->FACTURE_MERCURE_MASK_INVOICE.'">',$tooltip,1,1).'</td>';
 
-        $texte.= '<td align="left" rowspan="2">&nbsp; <input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"></td>';
+        $texte.= '<td align="left" rowspan="3">&nbsp; <input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"></td>';
 
         $texte.= '</tr>';
 
@@ -77,6 +78,11 @@ class mod_facture_mercure extends ModeleNumRefFactures
         $texte.= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="maskcredit" value="'.$conf->global->FACTURE_MERCURE_MASK_CREDIT.'">',$tooltip,1,1).'</td>';
         $texte.= '</tr>';
 
+        // Parametrage du prefix des acomptes
+        $texte.= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("InvoiceDeposit").'):</td>';
+        $texte.= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="maskdeposit" value="'.$conf->global->FACTURE_MERCURE_MASK_DEPOSIT.'">',$tooltip,1,1).'</td>';
+        $texte.= '</tr>';
+
         $texte.= '</table>';
         $texte.= '</form>';
 
@@ -124,6 +130,7 @@ class mod_facture_mercure extends ModeleNumRefFactures
         // Get Mask value
         $mask = '';
         if (is_object($facture) && $facture->type == 2) $mask=$conf->global->FACTURE_MERCURE_MASK_CREDIT;
+		else if (is_object($facture) && $facture->type == 3) $mask=$conf->global->FACTURE_MERCURE_MASK_DEPOSIT;
         else $mask=$conf->global->FACTURE_MERCURE_MASK_INVOICE;
         if (! $mask)
         {
diff --git a/htdocs/core/modules/facture/mod_facture_terre.php b/htdocs/core/modules/facture/mod_facture_terre.php
index 1b7072ebbb57b99e6c4547b81528b6e12d8a51b2..799dc1da2042dab7d98ab51c434b8636660a303c 100644
--- a/htdocs/core/modules/facture/mod_facture_terre.php
+++ b/htdocs/core/modules/facture/mod_facture_terre.php
@@ -32,6 +32,7 @@ class mod_facture_terre extends ModeleNumRefFactures
 	var $version='dolibarr';		// 'development', 'experimental', 'dolibarr'
 	var $prefixinvoice='FA';
 	var $prefixcreditnote='AV';
+	var $prefixdeposit='AC';
 	var $error='';
 
 	/**
@@ -43,7 +44,7 @@ class mod_facture_terre extends ModeleNumRefFactures
 	{
 		global $langs;
 		$langs->load("bills");
-		return $langs->trans('TerreNumRefModelDesc1',$this->prefixinvoice,$this->prefixcreditnote);
+		return $langs->trans('TerreNumRefModelDesc1',$this->prefixinvoice,$this->prefixcreditnote,$this->prefixdeposit);
 	}
 
 	/**
@@ -110,6 +111,27 @@ class mod_facture_terre extends ModeleNumRefFactures
 			$this->error=$langs->trans('ErrorNumRefModel',$max);
 			return false;
 		}
+		
+		// Check deposit num
+		$fayymm='';
+
+		$posindice=8;
+		$sql = "SELECT MAX(SUBSTRING(facnumber FROM ".$posindice.")) as max";	// This is standard SQL
+		$sql.= " FROM ".MAIN_DB_PREFIX."facture";
+		$sql.= " WHERE facnumber LIKE '".$this->prefixdeposit."____-%'";
+		$sql.= " AND entity = ".$conf->entity;
+
+		$resql=$db->query($sql);
+		if ($resql)
+		{
+			$row = $db->fetch_row($resql);
+			if ($row) { $fayymm = substr($row[0],0,6); $max=$row[0]; }
+		}
+		if ($fayymm && ! preg_match('/'.$this->prefixdeposit.'[0-9][0-9][0-9][0-9]/i',$fayymm))
+		{
+			$this->error=$langs->trans('ErrorNumRefModel',$max);
+			return false;
+		}
 
 		return true;
 	}
@@ -127,6 +149,7 @@ class mod_facture_terre extends ModeleNumRefFactures
 		global $db,$conf;
 
 		if ($facture->type == 2) $prefix=$this->prefixcreditnote;
+		else if ($facture->type == 3) $prefix=$this->prefixdeposit;
 		else $prefix=$this->prefixinvoice;
 
 		// D'abord on recupere la valeur max
diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang
index c1386cf33c329f314daa90f163fcbef42fa821a2..4cf9ab6d37f02306f8b1911026a9239b407a40ca 100644
--- a/htdocs/langs/en_US/admin.lang
+++ b/htdocs/langs/en_US/admin.lang
@@ -72,6 +72,7 @@ Mask=Mask
 NextValue=Next value
 NextValueForInvoices=Next value (invoices)
 NextValueForCreditNotes=Next value (credit notes)
+NextValueForDeposit=Next value (deposit)
 MustBeLowerThanPHPLimit=Note: your PHP limits each file upload's size to <b>%s</b> %s, whatever this parameter's value is
 NoMaxSizeByPHPLimit=Note: No limit is set in your PHP configuration
 MaxSizeForUploadedFiles=Maximum size for uploaded files (0 to disallow any upload)
diff --git a/htdocs/langs/en_US/bills.lang b/htdocs/langs/en_US/bills.lang
index ceab52445e2fea734c630374475ff06ce13e3432..e475eaf7cf3bd3a2945f9ec93379b1cfcaa9d6ea 100644
--- a/htdocs/langs/en_US/bills.lang
+++ b/htdocs/langs/en_US/bills.lang
@@ -411,7 +411,7 @@ PDFCrabeDescription=Invoice PDF template Crabe. A complete invoice template (Tem
 # oursin PDF Model
 PDFOursinDescription=Invoice PDF template Oursin. A complete invoice template (Template alternative)
 # NumRef Modules
-TerreNumRefModelDesc1=Return numero with format %syymm-nnnn for standard invoices and %syymm-nnnn for credit notes where yy is year, mm is month and nnnn is a sequence with no break and no return to 0
+TerreNumRefModelDesc1=Return numero with format %syymm-nnnn for standard invoices, %syymm-nnnn for credit notes and %syymm-nnnn for deposits where yy is year, mm is month and nnnn is a sequence with no break and no return to 0
 MarsNumRefModelDesc1=Return numero with format %syymm-nnnn for standard invoices, %syymm-nnnn for replacement invoices, %syymm-nnnn for proforma invoices and %syymm-nnnn for credit notes where yy is year, mm is month and nnnn is a sequence with no break and no return to 0
 
 TerreNumRefModelError=A bill starting with $syymm already exists and is not compatible with this model of sequence. Remove it or rename it to activate this module.
diff --git a/htdocs/langs/fr_FR/admin.lang b/htdocs/langs/fr_FR/admin.lang
index 8a0c565e8a1003d3018e21c8c1c37c72591f6b3e..de78b75f1106a77ee28d152a1445d5b476401703 100644
--- a/htdocs/langs/fr_FR/admin.lang
+++ b/htdocs/langs/fr_FR/admin.lang
@@ -72,6 +72,7 @@ Mask=Masque
 NextValue=Prochaine valeur
 NextValueForInvoices=Prochaine valeur (factures)
 NextValueForCreditNotes=Prochaine valeur (avoirs)
+NextValueForDeposit=Prochaine valeur (acomptes)
 MustBeLowerThanPHPLimit=Remarque : Votre PHP limite la taille des envois à <b>%s</b> %s, quelle que soit la valeur de ce paramètre
 NoMaxSizeByPHPLimit=Aucune limite configurée dans votre serveur PHP
 MaxSizeForUploadedFiles=Taille maximum des fichiers envoyés (0 pour interdire l'envoi)
diff --git a/htdocs/langs/fr_FR/bills.lang b/htdocs/langs/fr_FR/bills.lang
index 4b56bcd1b1f7f26b091453c949597368ac094291..ba3214dbf6dc042c45b78f8dc228a521f3875898 100644
--- a/htdocs/langs/fr_FR/bills.lang
+++ b/htdocs/langs/fr_FR/bills.lang
@@ -411,7 +411,7 @@ PDFCrabeDescription=Modèle de facture PDF complet (modèle recommandé par déf
 # oursin PDF Model
 PDFOursinDescription=Modèle de facture PDF complet (modèle alternatif)
 # NumRef Modules
-TerreNumRefModelDesc1=Renvoie le numéro sous la forme %syymm-nnnn pour les factures et %syymm-nnnn pour les avoirs où yy est l'année, mm le mois et nnnn un compteur séquentiel sans rupture et sans remise à 0
+TerreNumRefModelDesc1=Renvoie le numéro sous la forme %syymm-nnnn pour les factures, %syymm-nnnn pour les avoirs et %syymm-nnnn pour les acomptes où yy est l'année, mm le mois et nnnn un compteur séquentiel sans rupture et sans remise à 0
 MarsNumRefModelDesc1=Renvoie le numéro sous la forme %syymm-nnnn pour les factures, %syymm-nnnn pour les factures de remplacement, %syymm-nnnn pour les factures proforma et %syymm-nnnn pour les avoirs où yy est l'année, mm le mois et nnnn un compteur séquentiel sans rupture et sans remise à 0
 
 TerreNumRefModelError=Une facture commençant par $syymm existe déjà et est incompatible avec cet modèle de numérotation. Supprimez-la ou renommez-la pour activer ce module.