diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php
index 4995ab7eab0..a338f588073 100644
--- a/htdocs/compta/facture.php
+++ b/htdocs/compta/facture.php
@@ -670,6 +670,19 @@ else if ($action == 'add' && $user->rights->facture->creer) {
}
+ if(GETPOST('invoiceAvoirWithPaymentRestAmount', 'int')==1 && $id>0) {
+
+ $facture_source = new Facture($db); // fetch origin object if not previously defined
+ if($facture_source->fetch($object->fk_facture_source)>0) {
+ $totalpaye = $facture_source->getSommePaiement();
+ $totalcreditnotes = $facture_source->getSumCreditNotesUsed();
+ $totaldeposits = $facture_source->getSumDepositsUsed();
+ $remain_to_pay = abs($facture_source->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits);
+
+ $object->addline($langs->trans('invoiceAvoirLineWithPaymentRestAmount'),$remain_to_pay,1,0,0,0,0,0,'','','TTC');
+ }
+ }
+
// Add predefined lines
/*
TODO delete
@@ -2058,7 +2071,8 @@ if ($action == 'create')
$desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceAvoirDesc"), 1);
print $desc;
- print ' ";
+ print ' 0 ? 'checked="checked"':'').' /> ";
+ print '
0 ? 'checked="checked"':'').' /> ";
print '' . "\n";
}
diff --git a/htdocs/langs/en_US/bills.lang b/htdocs/langs/en_US/bills.lang
index 5e3e5af56a2..7495d6c1aad 100644
--- a/htdocs/langs/en_US/bills.lang
+++ b/htdocs/langs/en_US/bills.lang
@@ -29,6 +29,8 @@ InvoiceAvoir=Credit note
InvoiceAvoirAsk=Credit note to correct invoice
InvoiceAvoirDesc=The credit note is a negative invoice used to solve fact that an invoice has an amount that differs than amount really paid (because customer paid too much by error, or will not paid completely since he returned some products for example).
invoiceAvoirWithLines=Create Credit Note with lines from the origin invoice
+invoiceAvoirWithPaymentRestAmount=Create Credit Note with the amount of origin invoice payment's lake
+invoiceAvoirLineWithPaymentRestAmount=Credit Note amount of invoice payment's lake
ReplaceInvoice=Replace invoice %s
ReplacementInvoice=Replacement invoice
ReplacedByInvoice=Replaced by invoice %s