Merge pull request #17687 from FHenry/dev_massaction_paid_custom_invoice

NEW : mass action paid customer invoice
This commit is contained in:
Laurent Destailleur 2021-08-17 19:10:49 +02:00 committed by GitHub
commit 95721d36ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 107 additions and 25 deletions

View File

@ -376,13 +376,64 @@ if (empty($reshook)) {
include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; 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(); $arrayofselected = is_array($toselect) ? $toselect : array();
if (!empty($arrayofselected)) {
$loc = dol_buildpath('/compta/paiement.php', 2).'?action=create&facids='.implode(',', $arrayofselected); $bankid=GETPOST('bankid', 'int');
$paiementid=GETPOST('paiementid', 'int');
header('Location: '.$loc); $paiementdate=dol_mktime(12, 0, 0, GETPOST('datepaimentmonth', 'int'), GETPOST('datepaimentday', 'int'), GETPOST('datepaimentyear', 'year'));
exit; 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') { } elseif ($massaction == 'withdrawrequest') {
$langs->load("withdrawals"); $langs->load("withdrawals");
@ -972,8 +1023,10 @@ if ($resql) {
'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"), 'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"), 'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"), '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)) { if ($conf->prelevement->enabled && !empty($user->rights->prelevement->bons->creer)) {
$langs->load("withdrawals"); $langs->load("withdrawals");
$arrayofmassactions['withdrawrequest'] = img_picto('', 'payment', 'class="pictofixedwidth"').$langs->trans("MakeWithdrawRequest"); $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"); $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(); $arrayofmassactions = array();
} }
$massactionbutton = $form->selectMassAction('', $arrayofmassactions); $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
@ -1007,7 +1060,9 @@ if ($resql) {
} }
print '<input type="hidden" name="token" value="'.newToken().'">'; print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">'; print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
print '<input type="hidden" name="action" value="list">'; if (!in_array($massaction, array('makepayment'))) {
print '<input type="hidden" name="action" value="list">';
}
print '<input type="hidden" name="sortfield" value="'.$sortfield.'">'; print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
print '<input type="hidden" name="sortorder" value="'.$sortorder.'">'; print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
print '<input type="hidden" name="search_status" value="'.$search_status.'">'; print '<input type="hidden" name="search_status" value="'.$search_status.'">';
@ -1021,6 +1076,21 @@ if ($resql) {
$trackid = 'inv'.$object->id; $trackid = 'inv'.$object->id;
include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php'; 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'=>'<input type="hidden" id="invoicesid" name="invoicesid" value="'.implode('#',GETPOST('toselect','array')).'">'),
);
$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) { if ($sall) {
foreach ($fieldstosearchall as $key => $val) { foreach ($fieldstosearchall as $key => $val) {
$fieldstosearchall[$key] = $langs->trans($val); $fieldstosearchall[$key] = $langs->trans($val);

View File

@ -3928,13 +3928,16 @@ class Form
* @param int $maxlength Max length of label * @param int $maxlength Max length of label
* @param int $active Active or not, -1 = all * @param int $active Active or not, -1 = all
* @param string $morecss Add more CSS on select tag * @param string $morecss Add more CSS on select tag
* @param int $nooutput 1=Return string, do not send to output
* @return void * @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 // phpcs:enable
global $langs, $user, $conf; global $langs, $user, $conf;
$out = '';
dol_syslog(__METHOD__." ".$selected.", ".$htmlname.", ".$filtertype.", ".$format, LOG_DEBUG); dol_syslog(__METHOD__." ".$selected.", ".$htmlname.", ".$filtertype.", ".$format, LOG_DEBUG);
$filterarray = array(); $filterarray = array();
@ -3953,9 +3956,9 @@ class Form
$selected = $conf->global->MAIN_DEFAULT_PAYMENT_TYPE_ID; $selected = $conf->global->MAIN_DEFAULT_PAYMENT_TYPE_ID;
} }
print '<select id="select'.$htmlname.'" class="flat selectpaymenttypes'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'">'; $out .= '<select id="select'.$htmlname.'" class="flat selectpaymenttypes'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'">';
if ($empty) { if ($empty) {
print '<option value="">&nbsp;</option>'; $out .= '<option value="">&nbsp;</option>';
} }
foreach ($this->cache_types_paiements as $id => $arraytypes) { foreach ($this->cache_types_paiements as $id => $arraytypes) {
// If not good status // If not good status
@ -3974,25 +3977,25 @@ class Form
} }
if ($format == 0) { if ($format == 0) {
print '<option value="'.$id.'"'; $out .= '<option value="'.$id.'"';
} elseif ($format == 1) { } elseif ($format == 1) {
print '<option value="'.$arraytypes['code'].'"'; $out .= '<option value="'.$arraytypes['code'].'"';
} elseif ($format == 2) { } elseif ($format == 2) {
print '<option value="'.$arraytypes['code'].'"'; $out .= '<option value="'.$arraytypes['code'].'"';
} elseif ($format == 3) { } elseif ($format == 3) {
print '<option value="'.$id.'"'; $out .= '<option value="'.$id.'"';
} }
// Print attribute selected or not // Print attribute selected or not
if ($format == 1 || $format == 2) { if ($format == 1 || $format == 2) {
if ($selected == $arraytypes['code']) { if ($selected == $arraytypes['code']) {
print ' selected'; $out .= ' selected';
} }
} else { } else {
if ($selected == $id) { if ($selected == $id) {
print ' selected'; $out .= ' selected';
} }
} }
print '>'; $out .= '>';
if ($format == 0) { if ($format == 0) {
$value = ($maxlength ?dol_trunc($arraytypes['label'], $maxlength) : $arraytypes['label']); $value = ($maxlength ?dol_trunc($arraytypes['label'], $maxlength) : $arraytypes['label']);
} elseif ($format == 1) { } elseif ($format == 1) {
@ -4002,14 +4005,20 @@ class Form
} elseif ($format == 3) { } elseif ($format == 3) {
$value = $arraytypes['code']; $value = $arraytypes['code'];
} }
print $value ? $value : '&nbsp;'; $out .= $value ? $value : '&nbsp;';
print '</option>'; $out .= '</option>';
} }
print '</select>'; $out .= '</select>';
if ($user->admin && !$noadmininfo) { 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);
} }

View File

@ -590,4 +590,7 @@ FacParentLine=Invoice Line Parent
SituationTotalRayToRest=Remainder to pay without taxe SituationTotalRayToRest=Remainder to pay without taxe
PDFSituationTitle=Situation n° %d PDFSituationTitle=Situation n° %d
SituationTotalProgress=Total progress %d %% SituationTotalProgress=Total progress %d %%
SearchUnpaidInvoicesWithDueDate=Search unpaid invoices with a due date = %s 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