From 62bc6e9e1f383db48d7dc7351f1a90fc227c8cc2 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Thu, 20 May 2021 13:15:32 +0200 Subject: [PATCH 1/5] on going --- htdocs/compta/facture/list.php | 23 +++++++++++++--- htdocs/core/class/html.form.class.php | 39 ++++++++++++++++----------- htdocs/langs/en_US/bills.lang | 3 ++- 3 files changed, 46 insertions(+), 19 deletions(-) diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php index 282aad95d89..6bf02d5d580 100644 --- a/htdocs/compta/facture/list.php +++ b/htdocs/compta/facture/list.php @@ -363,7 +363,7 @@ if (empty($reshook)) { include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; } -if ($massaction == 'makepayment') { +if ($massaction == 'makepayment_confirm') { $arrayofselected = is_array($toselect) ? $toselect : array(); $loc = dol_buildpath('/compta/paiement.php', 2).'?action=create&facids='.implode(',', $arrayofselected); @@ -948,8 +948,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"), TODO Blank page when using this ); + 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'] = $langs->trans("MakeWithdrawRequest"); @@ -961,7 +963,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); @@ -997,6 +999,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', '', 2, 0, 1, 0, 1, '', 1)), + array('type' => 'other', 'name' => 'bankid', 'label' => $langs->trans("Date"), '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 57bbbe3a029..763a3da6c57 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -3914,13 +3914,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(); @@ -3939,9 +3942,9 @@ class Form $selected = $conf->global->MAIN_DEFAULT_PAYMENT_TYPE_ID; } - print ''; if ($empty) { - print ''; + $out .= ''; } foreach ($this->cache_types_paiements as $id => $arraytypes) { // If not good status @@ -3960,25 +3963,25 @@ class Form } if ($format == 0) { - print ''; + $out .= $value ? $value : ' '; + $out .= ''; } - print ''; + $out .= ''; 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 940da4e35b4..1ccdd162719 100644 --- a/htdocs/langs/en_US/bills.lang +++ b/htdocs/langs/en_US/bills.lang @@ -589,4 +589,5 @@ 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' From 7c6ac86d3209d5822672ae7efd58e6cdcc137ef2 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Thu, 20 May 2021 13:41:23 +0200 Subject: [PATCH 2/5] ongoing --- htdocs/compta/facture/list.php | 54 ++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 6 deletions(-) diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php index 6bf02d5d580..067a7cb959a 100644 --- a/htdocs/compta/facture/list.php +++ b/htdocs/compta/facture/list.php @@ -363,13 +363,53 @@ if (empty($reshook)) { include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; } -if ($massaction == 'makepayment_confirm') { +if ($action == 'makepayment_confirm') { + /*require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php'; $arrayofselected = is_array($toselect) ? $toselect : array(); + if (!empty($invoices_id)) { + $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) { + $facture = new Facture($db); + $result = $facture->fetch($invoice_id); + if ($result < 0) { + setEventMessage($facture->error, 'errors'); + } else { + if (empty($facture->paye)) { - $loc = dol_buildpath('/compta/paiement.php', 2).'?action=create&facids='.implode(',', $arrayofselected); - - header('Location: '.$loc); - exit; + $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'); + } else { + $paiement = new Paiement($this->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'); + } else { + $result = $paiement->addPaymentToBank($user, 'payment', '', $bankid, '', ''); + if ($result < 0) { + setEventMessages($facture->ref . ' ' . $paiement->error, $paiement->errors, 'errors'); + } + } + } + } + } else { + setEventMessage($facture->ref.' Total 0 € Pas de réglement enregistré', 'errors'); + } + } + } + }*/ } elseif ($massaction == 'withdrawrequest') { $langs->load("withdrawals"); @@ -985,7 +1025,9 @@ if ($resql) { } print ''; print ''; - print ''; + if (!in_array($massaction, array('presend', 'predelete' ,'makepayment'))) { + print ''; + } print ''; print ''; print ''; From 4d7b09ff2ae7bde4a4caa3a6935b5552663523fb Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Thu, 20 May 2021 14:00:43 +0200 Subject: [PATCH 3/5] done --- htdocs/compta/facture/list.php | 37 ++++++++++++++++++++++------------ htdocs/langs/en_US/bills.lang | 4 +++- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php index 067a7cb959a..677d92e8765 100644 --- a/htdocs/compta/facture/list.php +++ b/htdocs/compta/facture/list.php @@ -363,21 +363,22 @@ if (empty($reshook)) { include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; } -if ($action == 'makepayment_confirm') { - /*require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php'; +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(); - if (!empty($invoices_id)) { - $bankid=GETPOST('bankid','int'); - $paiementid=GETPOST('paiementid','int'); - $paiementdate=dol_mktime(12,0,0,GETPOST('datepaimentmonth','int'),GETPOST('datepaimentday','int'),GETPOST('datepaimentyear','year')); + 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($invoice_id); + $result = $facture->fetch($toselectid); if ($result < 0) { setEventMessage($facture->error, 'errors'); + $errorpayment++; } else { - if (empty($facture->paye)) { - + if ($facture->type != Facture::TYPE_CREDIT_NOTE && $facture->statut == 1 && $facture->paye == 0) { $paiementAmount = $facture->getSommePaiement(); $totalcreditnotes = $facture->getSumCreditNotesUsed(); $totaldeposits = $facture->getSumDepositsUsed(); @@ -387,8 +388,9 @@ if ($action == 'makepayment_confirm') { $resultBank = $facture->setBankAccount($bankid); if ($resultBank < 0) { setEventMessage($facture->error, 'errors'); + $errorpayment++; } else { - $paiement = new Paiement($this->db); + $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; @@ -396,20 +398,29 @@ if ($action == 'makepayment_confirm') { $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($facture->ref.' Total 0 € Pas de réglement enregistré', 'errors'); + setEventMessage($langs->trans('NoPaymentAvailable', $facture->ref), 'warnings'); + $errorpayment++; } } + if (empty($errorpayment)) { + setEventMessage($langs->trans('RegisterPaymentAndClasiffiedPayedDone', $facture->ref)); + } } - }*/ + } } elseif ($massaction == 'withdrawrequest') { $langs->load("withdrawals"); @@ -1048,7 +1059,7 @@ if ($resql) { // 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', '', 2, 0, 1, 0, 1, '', 1)), + 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("Date"), 'value'=>$form->select_comptes('', 'bankid', 0, '', 0, '', 0, '', 1)), //array('type' => 'other', 'name' => 'invoicesid', 'label' => '', 'value'=>''), ); diff --git a/htdocs/langs/en_US/bills.lang b/htdocs/langs/en_US/bills.lang index 1ccdd162719..a43d56217b4 100644 --- a/htdocs/langs/en_US/bills.lang +++ b/htdocs/langs/en_US/bills.lang @@ -590,4 +590,6 @@ SituationTotalRayToRest=Remainder to pay without taxe PDFSituationTitle=Situation n° %d SituationTotalProgress=Total progress %d %% SearchUnpaidInvoicesWithDueDate=Search unpaid invoices with a due date = %s -RegisterPaymentAndClasiffiedPayed=Enter payment and Classify 'Paid' +RegisterPaymentAndClasiffiedPayed=Enter payment and classify 'Paid' +NoPaymentAvailable=No payment available for %s +RegisterPaymentAndClasiffiedPayedDone=Payment registered and classify 'Paid' done for invoice %s From d70bbe29b54e7055043f51f72a47bfc84af90b78 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Thu, 20 May 2021 14:03:18 +0200 Subject: [PATCH 4/5] fix --- htdocs/compta/facture/list.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php index e17e56e4378..850c012a5e7 100644 --- a/htdocs/compta/facture/list.php +++ b/htdocs/compta/facture/list.php @@ -1036,7 +1036,7 @@ if ($resql) { } print ''; print ''; - if (!in_array($massaction, array('presend', 'predelete' ,'makepayment'))) { + if (!in_array($massaction, array('makepayment'))) { print ''; } print ''; From 794db94178941cff732662916cdab1e874307c75 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 17 Aug 2021 19:08:55 +0200 Subject: [PATCH 5/5] Update list.php --- htdocs/compta/facture/list.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php index 850c012a5e7..30c1a961000 100644 --- a/htdocs/compta/facture/list.php +++ b/htdocs/compta/facture/list.php @@ -1060,7 +1060,7 @@ if ($resql) { // 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("Date"), 'value'=>$form->select_comptes('', 'bankid', 0, '', 0, '', 0, '', 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);