31 require
'../../main.inc.php';
32 require_once DOL_DOCUMENT_ROOT.
'/compta/prelevement/class/bonprelevement.class.php';
33 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
34 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
35 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
36 require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
37 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
38 require_once DOL_DOCUMENT_ROOT.
'/core/lib/prelevement.lib.php';
39 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
42 $langs->loadLangs(array(
'banks',
'categories',
'withdrawals',
'companies',
'bills'));
44 $type =
GETPOST(
'type',
'aZ09');
47 $action =
GETPOST(
'action',
'aZ09');
48 $massaction =
GETPOST(
'massaction',
'alpha');
49 $toselect =
GETPOST(
'toselect',
'array');
51 $mode =
GETPOST(
'mode',
'alpha') ?
GETPOST(
'mode',
'alpha') :
'real';
52 $format =
GETPOST(
'format',
'aZ09');
53 $id_bankaccount =
GETPOST(
'id_bankaccount',
'int');
56 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
58 if (empty($page) || $page == -1) {
61 $offset = $limit * $page;
63 $hookmanager->initHooks(array(
'directdebitcreatecard',
'globalcard'));
66 $socid =
GETPOST(
'socid',
'int');
68 $socid = $user->socid;
70 if ($type ==
'bank-transfer') {
71 $result =
restrictedArea($user,
'paymentbybanktransfer',
'',
'',
'');
83 if (
GETPOST(
'cancel',
'alpha')) {
87 $parameters = array(
'mode' => $mode,
'format' => $format,
'limit' => $limit,
'page' => $page,
'offset' => $offset);
88 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
93 if (empty($reshook)) {
95 if ($action ==
'modify') {
96 for ($i = 1; $i < 9; $i++) {
100 if ($action ==
'create') {
101 $default_account = ($type ==
'bank-transfer' ?
'PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT' :
'PRELEVEMENT_ID_BANKACCOUNT');
105 if ($id_bankaccount != $conf->global->$default_account) {
106 $res =
dolibarr_set_const($db, $default_account, $id_bankaccount,
'chaine', 0,
'', $conf->entity);
109 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
111 $bank->fetch($conf->global->{$default_account});
116 if (empty($bank->ics) && $type !==
'bank-transfer') {
117 $errormessage = str_replace(
'{url}', $bank->getNomUrl(1,
'',
'', -1, 1), $langs->trans(
"ErrorICSmissing",
'{url}'));
128 $result = $bprev->create($conf->global->PRELEVEMENT_CODE_BANQUE, $conf->global->PRELEVEMENT_CODE_GUICHET, $mode, $format, $executiondate, 0, $type);
131 } elseif ($result == 0) {
132 $mesg = $langs->trans(
"NoInvoiceCouldBeWithdrawed", $format);
134 $mesg .=
'<br>'.
"\n";
135 foreach ($bprev->invoice_in_error as $key => $val) {
136 $mesg .=
'<span class="warning">'.$val.
"</span><br>\n";
139 if ($type !=
'bank-transfer') {
140 $texttoshow = $langs->trans(
"DirectDebitOrderCreated",
'{s}');
141 $texttoshow = str_replace(
'{s}', $bprev->getNomUrl(1), $texttoshow);
144 $texttoshow = $langs->trans(
"CreditTransferOrderCreated",
'{s}');
145 $texttoshow = str_replace(
'{s}', $bprev->getNomUrl(1), $texttoshow);
149 header(
"Location: ".DOL_URL_ROOT.
'/compta/prelevement/card.php?id='.urlencode($bprev->id).
'&type='.urlencode($type));
154 $objectclass =
"BonPrelevement";
155 if ($type ==
'bank-transfer') {
156 $uploaddir = $conf->paymentbybanktransfer->dir_output;
158 $uploaddir = $conf->prelevement->dir_output;
160 include DOL_DOCUMENT_ROOT.
'/core/actions_massactions.inc.php';
170 $thirdpartystatic =
new Societe($db);
171 if ($type !=
'bank-transfer') {
172 $invoicestatic =
new Facture($db);
177 $arrayofselected = is_array($toselect) ? $toselect : array();
179 $arrayofmassactions = array(
181 if (
GETPOST(
'nomassaction',
'int') || in_array($massaction, array(
'presend',
'predelete'))) {
182 $arrayofmassactions = array();
184 $massactionbutton =
$form->selectMassAction(
'', $arrayofmassactions);
187 $langs->load(
"errors");
188 $modulenametoshow =
"Withdraw";
189 if ($type ==
'bank-transfer') {
190 $modulenametoshow =
"PaymentByBankTransfer";
192 setEventMessages($langs->trans(
"ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv($modulenametoshow)),
null,
'errors');
196 $title = $langs->trans(
"NewStandingOrder");
197 if ($type ==
'bank-transfer') {
198 $title = $langs->trans(
"NewPaymentByBankTransfer");
207 $nb = $bprev->nbOfInvoiceToPay($type);
208 $pricetowithdraw = $bprev->SommeAPrelever($type);
212 print
'<table class="border centpercent tableforfield">';
214 $labeltoshow = $langs->trans(
"NbOfInvoiceToWithdraw");
215 if ($type ==
'bank-transfer') {
216 $labeltoshow = $langs->trans(
"NbOfInvoiceToPayByBankTransfer");
219 print
'<tr><td class="titlefield">'.$labeltoshow.
'</td>';
224 print
'<tr><td>'.$langs->trans(
"AmountTotal").
'</td>';
225 print
'<td class="amount">';
226 print
price($pricetowithdraw);
237 print
'<div class="tabsAction">'.
"\n";
239 print
'<form action="'.$_SERVER[
'PHP_SELF'].
'?action=create" method="POST">';
240 print
'<input type="hidden" name="token" value="'.newToken().
'">';
241 print
'<input type="hidden" name="type" value="'.$type.
'">';
243 if ($pricetowithdraw) {
244 $title = $langs->trans(
'BankToReceiveWithdraw').
': ';
245 if ($type ==
'bank-transfer') {
246 $title = $langs->trans(
'BankToPayCreditTransfer').
': ';
251 $default_account = ($type ==
'bank-transfer' ?
'PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT' :
'PRELEVEMENT_ID_BANKACCOUNT');
253 print
$form->select_comptes($conf->global->$default_account,
'id_bankaccount', 0,
"courant=1", 0,
'', 0,
'', 1);
256 if (empty($executiondate)) {
258 if ($type !=
'bank-transfer') {
259 $delayindays = $conf->global->PRELEVEMENT_ADDDAYS;
261 $delayindays = $conf->global->PAYMENTBYBANKTRANSFER_ADDDAYS;
267 print $langs->trans(
'ExecutionDate').
' ';
268 $datere = $executiondate;
269 print
$form->selectDate($datere,
're');
272 if ($mysoc->isInEEC()) {
273 $title = $langs->trans(
"CreateForSepa");
274 if ($type ==
'bank-transfer') {
275 $title = $langs->trans(
"CreateSepaFileForPaymentByBankTransfer");
278 if ($type !=
'bank-transfer') {
279 print
'<select name="format">';
280 print
'<option value="FRST"'.($format ==
'FRST' ?
' selected="selected"' :
'').
'>'.$langs->trans(
'SEPAFRST').
'</option>';
281 print
'<option value="RCUR"'.($format ==
'RCUR' ?
' selected="selected"' :
'').
'>'.$langs->trans(
'SEPARCUR').
'</option>';
284 print
'<input type="submit" class="butAction" value="'.$title.
'"/>';
286 $title = $langs->trans(
"CreateAll");
287 if ($type ==
'bank-transfer') {
288 $title = $langs->trans(
"CreateFileForPaymentByBankTransfer");
290 print
'<input type="hidden" name="format" value="ALL">'.
"\n";
291 print
'<input type="submit" class="butAction" value="'.$title.
'">'.
"\n";
294 if ($mysoc->isInEEC()) {
295 $title = $langs->trans(
"CreateForSepaFRST");
296 if ($type ==
'bank-transfer') {
297 $title = $langs->trans(
"CreateSepaFileForPaymentByBankTransfer");
299 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"AmountMustBePositive").
'">'.$title.
"</a>\n";
301 if ($type !=
'bank-transfer') {
302 $title = $langs->trans(
"CreateForSepaRCUR");
303 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"AmountMustBePositive").
'">'.$title.
"</a>\n";
306 $title = $langs->trans(
"CreateAll");
307 if ($type ==
'bank-transfer') {
308 $title = $langs->trans(
"CreateFileForPaymentByBankTransfer");
310 print
'<a class="butActionRefused classfortooltip" href="#">'.$title.
"</a>\n";
314 $titlefortab = $langs->transnoentitiesnoconv(
"StandingOrders");
315 $title = $langs->trans(
"CreateAll");
316 if ($type ==
'bank-transfer') {
317 $titlefortab = $langs->transnoentitiesnoconv(
"PaymentByBankTransfers");
318 $title = $langs->trans(
"CreateFileForPaymentByBankTransfer");
320 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv(
"NoInvoiceToWithdraw", $titlefortab, $titlefortab)).
'">'.$title.
"</a>\n";
334 $sql =
"SELECT f.ref, f.rowid, f.total_ttc, s.nom as name, s.rowid as socid,";
335 $sql .=
" pfd.rowid as request_row_id, pfd.date_demande, pfd.amount";
336 if ($type ==
'bank-transfer') {
337 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f,";
339 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f,";
341 $sql .=
" ".MAIN_DB_PREFIX.
"societe as s,";
342 $sql .=
" ".MAIN_DB_PREFIX.
"prelevement_demande as pfd";
343 $sql .=
" WHERE s.rowid = f.fk_soc";
344 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
345 if (empty($conf->global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS)) {
346 $sql .=
" AND f.fk_statut = ".Facture::STATUS_VALIDATED;
349 $sql .=
" AND f.total_ttc > 0";
350 $sql .=
" AND pfd.traite = 0";
351 $sql .=
" AND pfd.ext_payment_id IS NULL";
352 if ($type ==
'bank-transfer') {
353 $sql .=
" AND pfd.fk_facture_fourn = f.rowid";
355 $sql .=
" AND pfd.fk_facture = f.rowid";
358 $sql .=
" AND f.fk_soc = ".((int) $socid);
362 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
363 $result = $db->query($sql);
372 $sql .= $db->plimit($limit + 1, $offset);
374 $resql = $db->query($sql);
376 $num = $db->num_rows(
$resql);
380 if ($limit > 0 && $limit != $conf->liste_limit) {
381 $param .=
'&limit='.urlencode($limit);
384 $param .=
'&socid='.urlencode($socid);
387 $param .=
"&option=".urlencode($option);
390 print
'<form method="POST" id="searchFormList" action="'.$_SERVER[
"PHP_SELF"].
'">';
391 print
'<input type="hidden" name="token" value="'.newToken().
'">';
392 print
'<input type="hidden" name="page" value="'.$page.
'">';
393 if (!empty($limit)) {
394 print
'<input type="hidden" name="limit" value="'.$limit.
'"/>';
397 print
'<input type="hidden" name="type" value="'.$type.
'">';
400 $title = $langs->trans(
"InvoiceWaitingWithdraw");
401 if ($type ==
'bank-transfer') {
402 $title = $langs->trans(
"InvoiceWaitingPaymentByBankTransfer");
404 print_barre_liste($title, $page, $_SERVER[
'PHP_SELF'], $param,
'',
'', $massactionbutton, $num,
$nbtotalofrecords,
'bill', 0,
'',
'', $limit);
406 $tradinvoice =
"Invoice";
407 if ($type ==
'bank-transfer') {
408 $tradinvoice =
"SupplierInvoice";
411 print
'<table class="noborder centpercent">';
412 print
'<tr class="liste_titre">';
413 print
'<td>'.$langs->trans($tradinvoice).
'</td>';
414 print
'<td>'.$langs->trans(
"ThirdParty").
'</td>';
415 print
'<td>'.$langs->trans(
"RIB").
'</td>';
416 print
'<td>'.$langs->trans(
"RUM").
'</td>';
417 print
'<td class="right">'.$langs->trans(
"AmountTTC").
'</td>';
418 print
'<td class="right">'.$langs->trans(
"DateRequest").
'</td>';
419 if ($massactionbutton || $massaction) {
420 print
'<td align="center">'.$form->showCheckAddButtons(
'checkforselect', 1).
'</td>';
425 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
427 while ($i < $num && $i < $limit) {
428 $obj = $db->fetch_object(
$resql);
431 $bac->fetch(0, $obj->socid);
433 print
'<tr class="oddeven">';
437 $invoicestatic->id = $obj->rowid;
438 $invoicestatic->ref = $obj->ref;
439 print $invoicestatic->getNomUrl(1,
'withdraw');
444 $thirdpartystatic->fetch($obj->socid);
445 print $thirdpartystatic->getNomUrl(1,
'ban');
451 if (!empty($bac->iban) || !empty($bac->bic)) {
452 print $bac->iban.(($bac->iban && $bac->bic) ?
' / ' :
'').$bac->bic;
453 if ($bac->verif() <= 0) {
454 print
img_warning(
'Error on default bank number for IBAN : '.$langs->trans($bac->error_message));
457 print
img_warning($langs->trans(
"IBANNotDefined"));
460 print
img_warning($langs->trans(
"NoBankAccountDefined"));
466 $rumtoshow = $thirdpartystatic->display_rib(
'rum');
469 $format = $thirdpartystatic->display_rib(
'format');
470 if ($type !=
'bank-transfer') {
472 print
' ('.$format.
')';
476 print
img_warning($langs->trans(
"NoBankAccountDefined"));
480 print
'<td class="right amount">';
481 print
price($obj->amount, 0, $langs, 0, 0, -1, $conf->currency);
484 print
'<td class="right">';
488 if ($massactionbutton || $massaction) {
489 print
'<td class="nowrap center">';
491 if (in_array($obj->request_row_id, $arrayofselected)) {
494 print
'<input id="cb'.$obj->request_row_id.
'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->request_row_id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
501 print
'<tr class="oddeven"><td colspan="6"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td></tr>';
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Class to manage bank accounts.
Class to manage withdrawal receipts.
Class to manage bank accounts description of third parties.
Class to manage suppliers invoices.
Class to manage invoices.
Class to manage third parties objects (customers, suppliers, prospects...)
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
prelevement_check_config($type='direct-debit')
Check need data to create standigns orders receipt file.
$nbtotalofrecords
Count total nb of records.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.