diff --git a/htdocs/compta/facture/class/facture-rec.class.php b/htdocs/compta/facture/class/facture-rec.class.php
index 0a9fa2872eb..dd42c8d3fb7 100644
--- a/htdocs/compta/facture/class/facture-rec.class.php
+++ b/htdocs/compta/facture/class/facture-rec.class.php
@@ -823,6 +823,30 @@ class FactureRec extends CommonInvoice
return dol_time_plus_duree($this->date_when, $this->frequency, $this->unit_frequency);
}
+ /**
+ * Return if maximum number of generation is reached
+ *
+ * @return boolean False by default, True if maximum number of generation is reached
+ */
+ function isMaxNbGenReached()
+ {
+ $ret = false;
+ if ($this->nb_gen_max > 0 && ($this->nb_gen_done >= $this->nb_gen_max)) $ret = true;
+ return $ret;
+ }
+
+ /**
+ * Format string to output with by striking the string if max number of generation was reached
+ *
+ * @param string $ret Default value to output
+ * @return boolean False by default, True if maximum number of generation is reached
+ */
+ function strikeIfMaxNbGenReached($ret)
+ {
+ // Special case to strike the date
+ return ($this->isMaxNbGenReached()?'':'').$ret.($this->isMaxNbGenReached()?'':'');
+ }
+
/**
* Create all recurrents invoices (for all entities if multicompany is used).
* A result may also be provided into this->output.
diff --git a/htdocs/compta/facture/fiche-rec.php b/htdocs/compta/facture/fiche-rec.php
index 60156e0d047..dd37828fae6 100644
--- a/htdocs/compta/facture/fiche-rec.php
+++ b/htdocs/compta/facture/fiche-rec.php
@@ -1430,7 +1430,7 @@ else
print '
';
if ($action == 'date_when' || $object->frequency > 0)
{
- print $form->editfieldval($langs->trans("NextDateToExecution"), 'date_when', $object->date_when, $object, $user->rights->facture->creer, 'day');
+ print $form->editfieldval($langs->trans("NextDateToExecution"), 'date_when', $object->date_when, $object, $user->rights->facture->creer, 'day', $object->date_when, null, '', '', 0, 'strikeIfMaxNbGenReached');
}
print ' | ';
print '';
diff --git a/htdocs/compta/facture/invoicetemplate_list.php b/htdocs/compta/facture/invoicetemplate_list.php
index f39fc7a3185..201a2806188 100644
--- a/htdocs/compta/facture/invoicetemplate_list.php
+++ b/htdocs/compta/facture/invoicetemplate_list.php
@@ -520,6 +520,8 @@ if ($resql)
$invoicerectmp->frequency=$objp->frequency;
$invoicerectmp->suspend=$objp->suspend;
$invoicerectmp->unit_frequency=$objp->unit_frequency;
+ $invoicerectmp->nb_gen_max=$objp->nb_gen_max;
+ $invoicerectmp->nb_gen_done=$objp->nb_gen_done;
print '';
@@ -603,7 +605,7 @@ if ($resql)
if (! empty($arrayfields['f.date_when']['checked']))
{
print '';
- print ($objp->frequency ? dol_print_date($db->jdate($objp->date_when),'day') : ''.$langs->trans('NA').'');
+ print ($objp->frequency ? ($invoicerectmp->isMaxNbGenReached()?'':'').dol_print_date($db->jdate($objp->date_when),'day').($invoicerectmp->isMaxNbGenReached()?'':'') : ''.$langs->trans('NA').'');
print ' | ';
if (! $i) $totalarray['nbfield']++;
}
diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php
index 93c24990af0..6f968db22d3 100644
--- a/htdocs/core/class/html.form.class.php
+++ b/htdocs/core/class/html.form.class.php
@@ -128,7 +128,7 @@ class Form
}
/**
- * Output val field for an editable field
+ * Output value of a field for an editable field
*
* @param string $text Text of label (not used in this function)
* @param string $htmlname Name of select field
@@ -141,9 +141,10 @@ class Form
* @param mixed $custommsg String or Array of custom messages : eg array('success' => 'MyMessage', 'error' => 'MyMessage')
* @param string $moreparam More param to add on a href URL
* @param int $notabletag Do no output table tags
+ * @param string $formatfunc Call a specific function to output field
* @return string HTML edit field
*/
- function editfieldval($text, $htmlname, $value, $object, $perm, $typeofdata='string', $editvalue='', $extObject=null, $custommsg=null, $moreparam='', $notabletag=0)
+ function editfieldval($text, $htmlname, $value, $object, $perm, $typeofdata='string', $editvalue='', $extObject=null, $custommsg=null, $moreparam='', $notabletag=0, $formatfunc='')
{
global $conf,$langs,$db;
@@ -257,6 +258,11 @@ class Form
$ret.=$tmpcontent;
}
else $ret.=$value;
+
+ if ($formatfunc && method_exists($object, $formatfunc))
+ {
+ $ret=$object->$formatfunc($ret);
+ }
}
}
return $ret;