diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php
index 0becff9e54b..93be3ba445a 100644
--- a/htdocs/compta/facture/list.php
+++ b/htdocs/compta/facture/list.php
@@ -376,13 +376,64 @@ if (empty($reshook)) {
include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
}
-if ($massaction == 'makepayment_confirm') {
+if ($action == 'makepayment_confirm' && $user->rights->facture->paiement) {
+ require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
$arrayofselected = is_array($toselect) ? $toselect : array();
-
- $loc = dol_buildpath('/compta/paiement.php', 2).'?action=create&facids='.implode(',', $arrayofselected);
-
- header('Location: '.$loc);
- exit;
+ if (!empty($arrayofselected)) {
+ $bankid=GETPOST('bankid', 'int');
+ $paiementid=GETPOST('paiementid', 'int');
+ $paiementdate=dol_mktime(12, 0, 0, GETPOST('datepaimentmonth', 'int'), GETPOST('datepaimentday', 'int'), GETPOST('datepaimentyear', 'year'));
+ foreach ($arrayofselected as $toselectid) {
+ $errorpayment=0;
+ $facture = new Facture($db);
+ $result = $facture->fetch($toselectid);
+ if ($result < 0) {
+ setEventMessage($facture->error, 'errors');
+ $errorpayment++;
+ } else {
+ if ($facture->type != Facture::TYPE_CREDIT_NOTE && $facture->statut == 1 && $facture->paye == 0) {
+ $paiementAmount = $facture->getSommePaiement();
+ $totalcreditnotes = $facture->getSumCreditNotesUsed();
+ $totaldeposits = $facture->getSumDepositsUsed();
+ $totalpay = $paiementAmount + $totalcreditnotes + $totaldeposits;
+ $remaintopay = price2num($facture->total_ttc - $totalpay);
+ if ($remaintopay!=0) {
+ $resultBank = $facture->setBankAccount($bankid);
+ if ($resultBank < 0) {
+ setEventMessage($facture->error, 'errors');
+ $errorpayment++;
+ } else {
+ $paiement = new Paiement($db);
+ $paiement->datepaye = $paiementdate;
+ $paiement->amounts[$facture->id] = $remaintopay; // Array with all payments dispatching with invoice id
+ $paiement->multicurrency_amounts[$facture->id] = $remaintopay;
+ $paiement->paiementid = $paiementid;
+ $paiement_id = $paiement->create($user, 1, $facture->thirdparty);
+ if ($paiement_id < 0) {
+ setEventMessage($facture->ref . ' ' . $paiement->error, 'errors');
+ $errorpayment++;
+ } else {
+ $result = $paiement->addPaymentToBank($user, 'payment', '', $bankid, '', '');
+ if ($result < 0) {
+ setEventMessages($facture->ref . ' ' . $paiement->error, $paiement->errors, 'errors');
+ $errorpayment++;
+ }
+ }
+ }
+ } else {
+ setEventMessage($langs->trans('NoPaymentAvailable', $facture->ref), 'warnings');
+ $errorpayment++;
+ }
+ } else {
+ setEventMessage($langs->trans('NoPaymentAvailable', $facture->ref), 'warnings');
+ $errorpayment++;
+ }
+ }
+ if (empty($errorpayment)) {
+ setEventMessage($langs->trans('RegisterPaymentAndClasiffiedPayedDone', $facture->ref));
+ }
+ }
+ }
} elseif ($massaction == 'withdrawrequest') {
$langs->load("withdrawals");
@@ -972,8 +1023,10 @@ if ($resql) {
'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
- //'makepayment'=>$langs->trans("InvoicePaymentsLimits"),
);
+ if ($user->rights->facture->paiement) {
+ $arrayofmassactions['makepayment'] = $langs->trans("RegisterPaymentAndClasiffiedPayed");
+ }
if ($conf->prelevement->enabled && !empty($user->rights->prelevement->bons->creer)) {
$langs->load("withdrawals");
$arrayofmassactions['withdrawrequest'] = img_picto('', 'payment', 'class="pictofixedwidth"').$langs->trans("MakeWithdrawRequest");
@@ -985,7 +1038,7 @@ if ($resql) {
$arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
}
}
- if (in_array($massaction, array('presend', 'predelete'))) {
+ if (in_array($massaction, array('presend', 'predelete' ,'makepayment'))) {
$arrayofmassactions = array();
}
$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
@@ -1007,7 +1060,9 @@ if ($resql) {
}
print '';
print '';
- print '';
+ if (!in_array($massaction, array('makepayment'))) {
+ print '';
+ }
print '';
print '';
print '';
@@ -1021,6 +1076,21 @@ if ($resql) {
$trackid = 'inv'.$object->id;
include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
+ if ($massaction=='makepayment') {
+ $formconfirm = '';
+ $formquestion = array(
+ // 'text' => $langs->trans("ConfirmClone"),
+ // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
+ // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
+ array('type' => 'date', 'name' => 'datepaiment', 'label' => $langs->trans("Date")),
+ array('type' => 'other', 'name' => 'paiementid', 'label' => $langs->trans("PaymentMode"), 'value' => $form->select_types_paiements(GETPOST('search_paymentmode'), 'paiementid', '', 0, 0, 1, 0, 1, '', 1)),
+ array('type' => 'other', 'name' => 'bankid', 'label' => $langs->trans("BankAccount"), 'value'=>$form->select_comptes('', 'bankid', 0, '', 0, '', 0, '', 1)),
+ //array('type' => 'other', 'name' => 'invoicesid', 'label' => '', 'value'=>''),
+ );
+ $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans('RegisterPaymentAndClasiffiedPayed'), $langs->trans('RegisterPaymentAndClasiffiedPayed', $object->ref), 'makepayment_confirm', $formquestion, 1, 0, 200, 500, 1);
+ print $formconfirm;
+ }
+
if ($sall) {
foreach ($fieldstosearchall as $key => $val) {
$fieldstosearchall[$key] = $langs->trans($val);
diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php
index 8e69a4b49df..07abdb4b465 100644
--- a/htdocs/core/class/html.form.class.php
+++ b/htdocs/core/class/html.form.class.php
@@ -3928,13 +3928,16 @@ class Form
* @param int $maxlength Max length of label
* @param int $active Active or not, -1 = all
* @param string $morecss Add more CSS on select tag
+ * @param int $nooutput 1=Return string, do not send to output
* @return void
*/
- public function select_types_paiements($selected = '', $htmlname = 'paiementtype', $filtertype = '', $format = 0, $empty = 1, $noadmininfo = 0, $maxlength = 0, $active = 1, $morecss = '')
+ public function select_types_paiements($selected = '', $htmlname = 'paiementtype', $filtertype = '', $format = 0, $empty = 1, $noadmininfo = 0, $maxlength = 0, $active = 1, $morecss = '', $nooutput = 0)
{
// phpcs:enable
global $langs, $user, $conf;
+ $out = '';
+
dol_syslog(__METHOD__." ".$selected.", ".$htmlname.", ".$filtertype.", ".$format, LOG_DEBUG);
$filterarray = array();
@@ -3953,9 +3956,9 @@ class Form
$selected = $conf->global->MAIN_DEFAULT_PAYMENT_TYPE_ID;
}
- print '';
if ($user->admin && !$noadmininfo) {
- print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
+ $out .= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
+ }
+ $out .= ajax_combobox('select'.$htmlname);
+
+ if (empty($nooutput)) {
+ print $out;
+ } else {
+ return $out;
}
- print ajax_combobox('select'.$htmlname);
}
diff --git a/htdocs/langs/en_US/bills.lang b/htdocs/langs/en_US/bills.lang
index 0c660de8e22..a921aac9e48 100644
--- a/htdocs/langs/en_US/bills.lang
+++ b/htdocs/langs/en_US/bills.lang
@@ -590,4 +590,7 @@ FacParentLine=Invoice Line Parent
SituationTotalRayToRest=Remainder to pay without taxe
PDFSituationTitle=Situation n° %d
SituationTotalProgress=Total progress %d %%
-SearchUnpaidInvoicesWithDueDate=Search unpaid invoices with a due date = %s
\ No newline at end of file
+SearchUnpaidInvoicesWithDueDate=Search unpaid invoices with a due date = %s
+RegisterPaymentAndClasiffiedPayed=Enter payment and classify 'Paid'
+NoPaymentAvailable=No payment available for %s
+RegisterPaymentAndClasiffiedPayedDone=Payment registered and classify 'Paid' done for invoice %s