[b]IMPORTANT:
Amending code your code using the method below will enable the feature only in the current version that you are using. If you upgrade your Dolibarr version, then this code will be automatically erased (and the feature will be removed). Unless the feature below has been included in the core, you would need to apply this code again in your new version. Always backup the files mentioned before manually changing any code.
[tt]This has been accepted to be part of the core (maybe from v10) but it’s quite easy to implement. I’ve tested this on my v7.0.4.[/tt][/b]
Add Autofill Remainder Amount to Expense Report Payment Page
What this does:
When making a payment in an expense report, the remainder to pay field shows a clickable arrow which autofills the remainder amount, thus saving you from typing it in. You may be familiar with this functionality around other parts of Dolibarr in recent versions.
How to do it:
In file:
/expensereport/payment/payment.php
Before line: [tt](around line 186)[/tt]
print load_fiche_titre($langs->trans("DoPayment"));
Add:
[code]
// autofill remainder amount
if (! empty($conf->use_javascript_ajax))
{
print “\n”.’’;
//Add js for AutoFill
print ’ $(document).ready(function () {’;
print ’ $(".AutoFillAmount").on(
Then, Replace: [tt](around line 298 or 311)[/tt]
print '<input type="text" size="8" name="'.$namef.'">';
With:
$nameRemain = "remain_".$objp->id; // autofill remainder amount
if (!empty($conf->use_javascript_ajax)) // autofill remainder amount
print img_picto("Auto fill",'rightarrow', "class='AutoFillAmount' data-rowid='".$namef."' data-value='".($objp->total_ttc - $sumpaid)."'"); // autofill remainder amount
$remaintopay=$objp->total_ttc - $sumpaid; // autofill remainder amount
print '<input type=hidden class="sum_remain" name="'.$nameRemain.'" value="'.$remaintopay.'">'; // autofill remainder amount
print '<input type="text" size="8" name="'.$namef.'" id="'.$namef.'">';
click touchstart
Then, Replace: [tt](around line 298 or 311)[/tt]
print '<input type="text" size="8" name="'.$namef.'">';
With:
$nameRemain = "remain_".$objp->id; // autofill remainder amount
if (!empty($conf->use_javascript_ajax)) // autofill remainder amount
print img_picto("Auto fill",'rightarrow', "class='AutoFillAmount' data-rowid='".$namef."' data-value='".($objp->total_ttc - $sumpaid)."'"); // autofill remainder amount
$remaintopay=$objp->total_ttc - $sumpaid; // autofill remainder amount
print '<input type=hidden class="sum_remain" name="'.$nameRemain.'" value="'.$remaintopay.'">'; // autofill remainder amount
print '<input type="text" size="8" name="'.$namef.'" id="'.$namef.'">';
, function(){
var amount = $(this).data(“value”);
document.getElementById($(this).data(
Then, Replace: [tt](around line 298 or 311)[/tt]
print '<input type="text" size="8" name="'.$namef.'">';
With:
$nameRemain = "remain_".$objp->id; // autofill remainder amount
if (!empty($conf->use_javascript_ajax)) // autofill remainder amount
print img_picto("Auto fill",'rightarrow', "class='AutoFillAmount' data-rowid='".$namef."' data-value='".($objp->total_ttc - $sumpaid)."'"); // autofill remainder amount
$remaintopay=$objp->total_ttc - $sumpaid; // autofill remainder amount
print '<input type=hidden class="sum_remain" name="'.$nameRemain.'" value="'.$remaintopay.'">'; // autofill remainder amount
print '<input type="text" size="8" name="'.$namef.'" id="'.$namef.'">';
rowid
Then, Replace: [tt](around line 298 or 311)[/tt]
print '<input type="text" size="8" name="'.$namef.'">';
With:
$nameRemain = "remain_".$objp->id; // autofill remainder amount
if (!empty($conf->use_javascript_ajax)) // autofill remainder amount
print img_picto("Auto fill",'rightarrow', "class='AutoFillAmount' data-rowid='".$namef."' data-value='".($objp->total_ttc - $sumpaid)."'"); // autofill remainder amount
$remaintopay=$objp->total_ttc - $sumpaid; // autofill remainder amount
print '<input type=hidden class="sum_remain" name="'.$nameRemain.'" value="'.$remaintopay.'">'; // autofill remainder amount
print '<input type="text" size="8" name="'.$namef.'" id="'.$namef.'">';
[/code])).value = amount ;
});';
print ' });'."\n";
print ' </script>'."\n";
}
Then, Replace: [tt](around line 298 or 311)[/tt]
print '<input type="text" size="8" name="'.$namef.'">';
With:
$nameRemain = "remain_".$objp->id; // autofill remainder amount
if (!empty($conf->use_javascript_ajax)) // autofill remainder amount
print img_picto("Auto fill",'rightarrow', "class='AutoFillAmount' data-rowid='".$namef."' data-value='".($objp->total_ttc - $sumpaid)."'"); // autofill remainder amount
$remaintopay=$objp->total_ttc - $sumpaid; // autofill remainder amount
print '<input type=hidden class="sum_remain" name="'.$nameRemain.'" value="'.$remaintopay.'">'; // autofill remainder amount
print '<input type="text" size="8" name="'.$namef.'" id="'.$namef.'">';