From 66542b63675e7f608a23306b911fafd89d5fc0d9 Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@destailleur.fr>
Date: Fri, 10 Feb 2017 10:43:54 +0100
Subject: [PATCH] Fix translation and link to direct debit payment

---
 htdocs/compta/facture.php           | 34 +++++++++++++++++------------
 htdocs/langs/en_US/bills.lang       |  4 ++--
 htdocs/langs/en_US/withdrawals.lang |  4 ++--
 3 files changed, 24 insertions(+), 18 deletions(-)

diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php
index f6aebb09703..19eb19ad00f 100644
--- a/htdocs/compta/facture.php
+++ b/htdocs/compta/facture.php
@@ -3939,7 +3939,7 @@ else if ($id > 0 || ! empty($ref))
 			}
 
 			// Send by mail
-			if (($object->statut == 1 || $object->statut == 2) || ! empty($conf->global->FACTURE_SENDBYEMAIL_FOR_ALL_STATUS)) {
+			if (($object->statut == Facture::STATUS_VALIDATED || $object->statut == Facture::STATUS_CLOSED) || ! empty($conf->global->FACTURE_SENDBYEMAIL_FOR_ALL_STATUS)) {
 				if ($objectidnext) {
 					print '<div class="inline-block divButAction"><span class="butActionRefused" title="' . $langs->trans("DisabledBecauseReplacedInvoice") . '">' . $langs->trans('SendByMail') . '</span></div>';
 				} else {
@@ -3950,21 +3950,27 @@ else if ($id > 0 || ! empty($ref))
 				}
 			}
 
-			// deprecated. Useless because now we can use templates
-			if (! empty($conf->global->FACTURE_SHOW_SEND_REMINDER)) 			// For backward compatibility
+			// Request a direct debit order
+			if ($object->statut > Facture::STATUS_DRAFT && $object->paye == 0 && $num == 0)
 			{
-				if (($object->statut == 1 || $object->statut == 2) && $resteapayer > 0) {
-					if ($objectidnext) {
-						print '<div class="inline-block divButAction"><span class="butActionRefused" title="' . $langs->trans("DisabledBecauseReplacedInvoice") . '">' . $langs->trans('SendRemindByMail') . '</span></div>';
-					} else {
-						if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->facture->invoice_advance->send) {
-							print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER['PHP_SELF'] . '?facid=' . $object->id . '&amp;action=prerelance&amp;mode=init">' . $langs->trans('SendRemindByMail') . '</a></div>';
-						} else
-							print '<div class="inline-block divButAction"><a class="butActionRefused" href="#">' . $langs->trans('SendRemindByMail') . '</a></div>';
-					}
-				}
+			    if ($resteapayer > 0)
+			    {
+			        if ($user->rights->prelevement->bons->creer)
+			        {
+			            $langs->load("withdrawals");
+			            print '<a class="butAction" href="'.DOL_URL_ROOT.'/compta/facture/prelevement.php?facid='.$object->id.'" title="'.dol_escape_htmltag($langs->trans("MakeWithdrawRequest")).'">'.$langs->trans("MakeWithdrawRequest").'</a>';
+			        }
+			        else
+			        {
+			            //print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("MakeWithdrawRequest").'</a>';
+			        }
+			    }
+			    else
+			    {
+			        //print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("AmountMustBePositive")).'">'.$langs->trans("MakeWithdrawRequest").'</a>';
+			    }
 			}
-
+			
 			// Create payment
 			if ($object->type != Facture::TYPE_CREDIT_NOTE && $object->statut == 1 && $object->paye == 0 && $user->rights->facture->paiement) {
 				if ($objectidnext) {
diff --git a/htdocs/langs/en_US/bills.lang b/htdocs/langs/en_US/bills.lang
index 548bc370004..0e591ad880a 100644
--- a/htdocs/langs/en_US/bills.lang
+++ b/htdocs/langs/en_US/bills.lang
@@ -102,8 +102,8 @@ SearchACustomerInvoice=Search for a customer invoice
 SearchASupplierInvoice=Search for a supplier invoice
 CancelBill=Cancel an invoice
 SendRemindByMail=Send reminder by EMail
-DoPayment=Do payment
-DoPaymentBack=Do payment back
+DoPayment=Enter payment
+DoPaymentBack=Enter refund
 ConvertToReduc=Convert into future discount
 EnterPaymentReceivedFromCustomer=Enter payment received from customer
 EnterPaymentDueToCustomer=Make payment due to customer
diff --git a/htdocs/langs/en_US/withdrawals.lang b/htdocs/langs/en_US/withdrawals.lang
index a0706fe11a9..1e7f42c2f51 100644
--- a/htdocs/langs/en_US/withdrawals.lang
+++ b/htdocs/langs/en_US/withdrawals.lang
@@ -76,8 +76,8 @@ RUM=UMR
 RUMLong=Unique Mandate Reference
 RUMWillBeGenerated=UMR number will be generated once bank account information are saved
 WithdrawMode=Direct debit mode (FRST or RECUR)
-WithdrawRequestAmount=Withdraw request amount: 
-WithdrawRequestErrorNilAmount=Unable to create withdraw request for nil amount.
+WithdrawRequestAmount=Amount of Direct debit request: 
+WithdrawRequestErrorNilAmount=Unable to create direct debit request for empty amount.
 SepaMandate=SEPA Direct Debit Mandate
 SepaMandateShort=SEPA Mandate
 PleaseReturnMandate=Please return this mandate form by email to %s or by mail to
-- 
GitLab