diff --git a/htdocs/fourn/facture/list.php b/htdocs/fourn/facture/list.php
index 0ebfd024658..c1c6329cb43 100644
--- a/htdocs/fourn/facture/list.php
+++ b/htdocs/fourn/facture/list.php
@@ -270,6 +270,103 @@ if (empty($reshook))
}
+if ($massaction == 'transfer_request')
+{
+ $langs->load("withdrawals");
+
+ if (!$user->rights->paymentbybanktransfer->create)
+ {
+ $error++;
+ setEventMessages($langs->trans("NotEnoughPermissions"), null, 'errors');
+ }
+ else
+ {
+ //Checking error
+ $error = 0;
+
+ $arrayofselected = is_array($toselect) ? $toselect : array();
+ $listofbills = array();
+ foreach ($arrayofselected as $toselectid)
+ {
+ $objecttmp = new FactureFournisseur($db);
+ $result = $objecttmp->fetch($toselectid);
+ if ($result > 0)
+ {
+ $totalpaye = $objecttmp->getSommePaiement();
+ $totalcreditnotes = $objecttmp->getSumCreditNotesUsed();
+ $totaldeposits = $objecttmp->getSumDepositsUsed();
+ $objecttmp->resteapayer = price2num($objecttmp->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits, 'MT');
+ if ($objecttmp->paye || $objecttmp->resteapayer == 0) {
+ $error++;
+ setEventMessages($objecttmp->ref.' '.$langs->trans("AlreadyPaid"), $objecttmp->errors, 'errors');
+ } elseif ($objecttmp->resteapayer < 0) {
+ $error++;
+ setEventMessages($objecttmp->ref.' '.$langs->trans("AmountMustBePositive"), $objecttmp->errors, 'errors');
+ }
+ if (!($objecttmp->statut > FactureFournisseur::STATUS_DRAFT)) {
+ $error++;
+ setEventMessages($objecttmp->ref.' '.$langs->trans("Draft"), $objecttmp->errors, 'errors');
+ }
+
+ $rsql = "SELECT pfd.rowid, pfd.traite, pfd.date_demande as date_demande";
+ $rsql .= " , pfd.date_traite as date_traite";
+ $rsql .= " , pfd.amount";
+ $rsql .= " , u.rowid as user_id, u.lastname, u.firstname, u.login";
+ $rsql .= " FROM ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
+ $rsql .= " , ".MAIN_DB_PREFIX."user as u";
+ $rsql .= " WHERE fk_facture_fourn = ".$objecttmp->id;
+ $rsql .= " AND pfd.fk_user_demande = u.rowid";
+ $rsql .= " AND pfd.traite = 0";
+ $rsql .= " ORDER BY pfd.date_demande DESC";
+
+ $result_sql = $db->query($rsql);
+ if ($result_sql)
+ {
+ $numprlv = $db->num_rows($result_sql);
+ }
+
+ if ($numprlv > 0) {
+ $error++;
+ setEventMessages($objecttmp->ref.' '.$langs->trans("RequestAlreadyDone"), $objecttmp->errors, 'warnings');
+ }
+ elseif (!empty($objecttmp->mode_reglement_code) && $objecttmp->mode_reglement_code != 'VIR') {
+ $error++;
+ setEventMessages($objecttmp->ref.' '.$langs->trans("BadPaymentMethod"), $objecttmp->errors, 'errors');
+ }
+ else {
+ $listofbills[] = $objecttmp; // $listofbills will only contains invoices with good payment method and no request already done
+ }
+ }
+ }
+
+ //Massive withdraw request for request with no errors
+ if (!empty($listofbills))
+ {
+ $nbwithdrawrequestok = 0;
+ foreach ($listofbills as $aBill)
+ {
+ $db->begin();
+ $result = $aBill->demande_prelevement($user, $aBill->resteapayer, 'bank-transfer', 'supplier_invoice');
+ if ($result > 0)
+ {
+ $db->commit();
+ $nbwithdrawrequestok++;
+ }
+ else
+ {
+ $db->rollback();
+ setEventMessages($aBill->error, $aBill->errors, 'errors');
+ }
+ }
+ if ($nbwithdrawrequestok > 0)
+ {
+ setEventMessages($langs->trans("BankTransferRequestsDone", $nbwithdrawrequestok), null, 'mesgs');
+ }
+ }
+ }
+}
+
+
/*
* View
*/
@@ -505,6 +602,10 @@ if ($resql)
//'builddoc'=>$langs->trans("PDFMerge"),
//'presend'=>$langs->trans("SendByMail"),
);
+ if ($conf->paymentbybanktransfer->enabled) {
+ $langs->load("withdrawals");
+ $arrayofmassactions['transfer_request'] = $langs->trans("MakeBankTransferOrder");
+ }
//if($user->rights->fournisseur->facture->creer) $arrayofmassactions['createbills']=$langs->trans("CreateInvoiceForThisCustomer");
if ($user->rights->fournisseur->facture->supprimer) $arrayofmassactions['predelete'] = ''.$langs->trans("Delete");
if (in_array($massaction, array('presend', 'predelete', 'createbills'))) $arrayofmassactions = array();
diff --git a/htdocs/langs/en_US/withdrawals.lang b/htdocs/langs/en_US/withdrawals.lang
index a18ff7a8d31..1b8f2441b33 100644
--- a/htdocs/langs/en_US/withdrawals.lang
+++ b/htdocs/langs/en_US/withdrawals.lang
@@ -42,6 +42,7 @@ LastWithdrawalReceipt=Latest %s direct debit receipts
MakeWithdrawRequest=Make a direct debit payment request
MakeBankTransferOrder=Make a credit transfer request
WithdrawRequestsDone=%s direct debit payment requests recorded
+BankTransferRequestsDone=%s credit transfer requests recorded
ThirdPartyBankCode=Third-party bank code
NoInvoiceCouldBeWithdrawed=No invoice debited successfully. Check that invoices are on companies with a valid IBAN and that IBAN has a UMR (Unique Mandate Reference) with mode %s.
ClassCredited=Classify credited