29 require
'../../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.
'/compta/prelevement/class/bonprelevement.class.php';
31 require_once DOL_DOCUMENT_ROOT.
'/compta/prelevement/class/ligneprelevement.class.php';
32 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
35 $langs->loadLangs(array(
'banks',
'withdrawals',
'companies',
'categories'));
37 $action =
GETPOST(
'action',
'aZ09') ?
GETPOST(
'action',
'aZ09') :
'view';
38 $massaction =
GETPOST(
'massaction',
'alpha');
39 $show_files =
GETPOST(
'show_files',
'int');
40 $confirm =
GETPOST(
'confirm',
'alpha');
41 $cancel =
GETPOST(
'cancel',
'alpha');
42 $toselect =
GETPOST(
'toselect',
'array');
43 $contextpage =
GETPOST(
'contextpage',
'aZ') ?
GETPOST(
'contextpage',
'aZ') :
'directdebitcredittransferlinelist';
44 $backtopage =
GETPOST(
'backtopage',
'alpha');
45 $optioncss =
GETPOST(
'optioncss',
'aZ');
48 $type =
GETPOST(
'type',
'aZ09');
51 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
52 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
53 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
55 if (empty($page) || $page < 0 ||
GETPOST(
'button_search',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) {
59 $offset = $limit * $page;
60 $pageprev = $page - 1;
61 $pagenext = $page + 1;
66 $sortfield =
"p.datec";
69 $search_line =
GETPOST(
'search_line',
'alpha');
70 $search_bon =
GETPOST(
'search_bon',
'alpha');
71 $search_code =
GETPOST(
'search_code',
'alpha');
72 $search_company =
GETPOST(
'search_company',
'alpha');
73 $statut =
GETPOST(
'statut',
'int');
79 $hookmanager->initHooks(array(
'withdrawalsreceiptslineslist'));
82 $socid =
GETPOST(
'socid',
'int');
84 $socid = $user->socid;
86 if ($type ==
'bank-transfer') {
87 $result =
restrictedArea($user,
'paymentbybanktransfer',
'',
'',
'');
97 if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) {
101 $search_company =
"";
112 $title = $langs->trans(
"WithdrawalsLines");
113 if ($type ==
'bank-transfer') {
114 $title = $langs->trans(
"CreditTransferLines");
118 $sql =
"SELECT p.rowid, p.ref, p.statut as status, p.datec";
119 $sql .=
" , f.rowid as facid, f.ref as invoiceref, f.total_ttc";
120 $sql .=
" , s.rowid as socid, s.nom as name, s.code_client, s.code_fournisseur, s.email";
121 $sql .=
" , pl.amount, pl.statut as statut_ligne, pl.rowid as rowid_ligne";
125 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement_bons as p";
126 $sql .=
" , ".MAIN_DB_PREFIX.
"prelevement_lignes as pl";
127 $sql .=
" , ".MAIN_DB_PREFIX.
"prelevement as pf";
128 if ($type ==
'bank-transfer') {
129 $sql .=
" , ".MAIN_DB_PREFIX.
"facture_fourn as f";
131 $sql .=
" , ".MAIN_DB_PREFIX.
"facture as f";
133 $sql .=
" , ".MAIN_DB_PREFIX.
"societe as s";
134 $sql .=
" WHERE pl.fk_prelevement_bons = p.rowid";
135 $sql .=
" AND pf.fk_prelevement_lignes = pl.rowid";
136 if ($type ==
'bank-transfer') {
137 $sql .=
" AND pf.fk_facture_fourn = f.rowid";
139 $sql .=
" AND pf.fk_facture = f.rowid";
141 $sql .=
" AND f.fk_soc = s.rowid";
142 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
144 $sql .=
" AND s.rowid = ".((int) $socid);
147 $sql .=
" AND pl.rowid = '".$db->escape($search_line).
"'";
152 if ($type ==
'bank-transfer') {
161 if ($search_company) {
166 $nbtotalofrecords =
'';
169 $sqlforcount = preg_replace(
'/^'.preg_quote($sqlfields,
'/').
'/',
'SELECT COUNT(*) as nbtotalofrecords',
$sql);
170 $sqlforcount = preg_replace(
'/GROUP BY .*$/',
'', $sqlforcount);
171 $resql = $db->query($sqlforcount);
173 $objforcount = $db->fetch_object($resql);
174 $nbtotalofrecords = $objforcount->nbtotalofrecords;
179 if (($page * $limit) > $nbtotalofrecords) {
187 $sql .= $db->order($sortfield, $sortorder);
189 $sql .= $db->plimit($limit + 1, $offset);
192 $resql = $db->query(
$sql);
198 $num = $db->num_rows($resql);
205 $arrayofselected = is_array($toselect) ? $toselect : array();
208 $param .=
"&statut=".urlencode($statut);
209 $param .=
"&search_bon=".urlencode($search_bon);
210 if ($type ==
'bank-transfer') {
211 $param .=
'&type=bank-transfer';
214 $param .=
'&mode='.urlencode($mode);
216 if (!empty($contextpage) && $contextpage != $_SERVER[
"PHP_SELF"]) {
217 $param .=
'&contextpage='.urlencode($contextpage);
219 if ($limit > 0 && $limit != $conf->liste_limit) {
220 $param .=
'&limit='.((int) $limit);
222 if ($optioncss !=
'') {
223 $param .=
'&optioncss='.urlencode($optioncss);
226 $arrayofmassactions = array(
230 $massactionbutton =
$form->selectMassAction(
'', $arrayofmassactions);
232 print
'<form method="POST" id="searchFormList" action="'.$_SERVER[
"PHP_SELF"].
'">'.
"\n";
233 print
'<input type="hidden" name="token" value="'.newToken().
'">';
234 if ($optioncss !=
'') {
235 print
'<input type="hidden" name="optioncss" value="'.$optioncss.
'">';
237 print
'<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
238 print
'<input type="hidden" name="action" value="list">';
239 print
'<input type="hidden" name="sortfield" value="'.$sortfield.
'">';
240 print
'<input type="hidden" name="sortorder" value="'.$sortorder.
'">';
241 print
'<input type="hidden" name="page" value="'.$page.
'">';
242 print
'<input type="hidden" name="contextpage" value="'.$contextpage.
'">';
243 print
'<input type="hidden" name="page_y" value="">';
244 print
'<input type="hidden" name="mode" value="'.$mode.
'">';
247 print
'<input type="hidden" name="type" value="'.$type.
'">';
251 $newcardbutton .=
dolGetButtonTitle($langs->trans(
'ViewList'),
'',
'fa fa-bars imgforviewmode', $_SERVER[
"PHP_SELF"].
'?mode=common'.preg_replace(
'/(&|\?)*mode=[^&]+/',
'', $param),
'', ((empty($mode) || $mode ==
'common') ? 2 : 1), array(
'morecss'=>
'reposition'));
252 $newcardbutton .=
dolGetButtonTitle($langs->trans(
'ViewKanban'),
'',
'fa fa-th-list imgforviewmode', $_SERVER[
"PHP_SELF"].
'?mode=kanban'.preg_replace(
'/(&|\?)*mode=[^&]+/',
'', $param),
'', ($mode ==
'kanban' ? 2 : 1), array(
'morecss'=>
'reposition'));
254 print_barre_liste($title, $page, $_SERVER[
"PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords,
'generic', 0, $newcardbutton,
'', $limit, 0, 0, 1);
261 $parameters = array();
262 $reshook = $hookmanager->executeHooks(
'printFieldPreListTitle', $parameters, $object, $action);
263 if (empty($reshook)) {
264 $moreforfilter .= $hookmanager->resPrint;
266 $moreforfilter = $hookmanager->resPrint;
269 if (!empty($moreforfilter)) {
270 print
'<div class="liste_titre liste_titre_bydiv centpercent">';
271 print $moreforfilter;
272 $parameters = array();
273 $reshook = $hookmanager->executeHooks(
'printFieldPreListTitle', $parameters, $object, $action);
274 print $hookmanager->resPrint;
278 $varpage = empty($contextpage) ? $_SERVER[
"PHP_SELF"] : $contextpage;
279 $selectedfields = ($mode !=
'kanban' ?
$form->multiSelectArrayWithCheckbox(
'selectedfields', $arrayfields, $varpage,
getDolGlobalString(
'MAIN_CHECKBOX_LEFT_COLUMN',
'')) :
'');
280 $selectedfields .= (count($arrayofmassactions) ?
$form->showCheckAddButtons(
'checkforselect', 1) :
'');
282 print
'<div class="div-table-responsive">';
283 print
'<table class="tagtable nobottomiftotal liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
287 print
'<tr class="liste_titre_filter">';
290 print
'<td class="liste_titre center maxwidthsearch">';
291 $searchpicto =
$form->showFilterButtons(
'left');
295 print
'<td class="liste_titre"><input type="text" class="flat" name="search_line" value="'.dol_escape_htmltag($search_line).
'" size="6"></td>';
296 print
'<td class="liste_titre"><input type="text" class="flat" name="search_bon" value="'.dol_escape_htmltag($search_bon).
'" size="6"></td>';
297 print
'<td class="liste_titre"> </td>';
298 print
'<td class="liste_titre"><input type="text" class="flat" name="search_company" value="'.dol_escape_htmltag($search_company).
'" size="6"></td>';
299 print
'<td class="liste_titre center"><input type="text" class="flat" name="search_code" value="'.dol_escape_htmltag($search_code).
'" size="6"></td>';
300 print
'<td class="liste_titre"> </td>';
301 print
'<td class="liste_titre"> </td>';
304 print
'<td class="liste_titre center maxwidthsearch">';
305 $searchpicto =
$form->showFilterButtons();
311 $totalarray = array();
312 $totalarray[
'nbfield'] = 0;
314 $columntitle =
"WithdrawalsReceipts";
315 $columntitlethirdparty =
"CustomerCode";
316 $columncodethirdparty =
"s.code_client";
317 if ($type ==
'bank-transfer') {
318 $columntitle =
"BankTransferReceipts";
319 $columntitlethirdparty =
"SupplierCode";
320 $columncodethirdparty =
"s.code_fournisseur";
325 print
'<tr class="liste_titre">';
328 print
getTitleFieldOfList($selectedfields, 0, $_SERVER[
"PHP_SELF"],
'',
'',
'',
'', $sortfield, $sortorder,
'center maxwidthsearch ').
"\n";
329 $totalarray[
'nbfield']++;
332 $totalarray[
'nbfield']++;
334 $totalarray[
'nbfield']++;
336 $totalarray[
'nbfield']++;
338 $totalarray[
'nbfield']++;
339 print_liste_field_titre($columntitlethirdparty, $_SERVER[
"PHP_SELF"], $columncodethirdparty,
'', $param,
'', $sortfield, $sortorder,
'center ');
340 $totalarray[
'nbfield']++;
341 print_liste_field_titre(
"Date", $_SERVER[
"PHP_SELF"],
"p.datec",
"", $param,
'', $sortfield, $sortorder,
'center ');
342 $totalarray[
'nbfield']++;
343 print_liste_field_titre(
"Amount", $_SERVER[
"PHP_SELF"],
"pl.amount",
"", $param,
'', $sortfield, $sortorder,
'right ');
344 $totalarray[
'nbfield']++;
347 print
getTitleFieldOfList($selectedfields, 0, $_SERVER[
"PHP_SELF"],
'',
'',
'',
'', $sortfield, $sortorder,
'center maxwidthsearch ').
"\n";
348 $totalarray[
'nbfield']++;
355 $savnbfield = $totalarray[
'nbfield'];
356 $totalarray = array();
357 $totalarray[
'nbfield'] = 0;
359 $imaxinloop = ($limit ? min($num, $limit) : $num);
360 while ($i < $imaxinloop) {
361 $obj = $db->fetch_object($resql);
363 $bon->id = $obj->rowid;
364 $bon->ref = $obj->ref;
365 $bon->statut = $obj->status;
366 $bon->date_echeance = $obj->datec;
367 $bon->total = $obj->amount;
371 $company->id = $obj->socid;
372 $company->name = $obj->name;
373 $company->email = $obj->email;
374 $company->code_client = $obj->code_client;
376 if ($mode ==
'kanban') {
378 print
'<tr class="trkanban"><td colspan="'.$savnbfield.
'">';
379 print
'<div class="box-flex-container kanban">';
382 if ($massactionbutton || $massaction) {
384 if (in_array($object->id, $arrayofselected)) {
388 print $object->getKanbanView(
'', array(
'selected' => in_array($bon->id, $arrayofselected)));
389 if ($i == ($imaxinloop - 1)) {
396 print
'<tr data-rowid="'.$object->id.
'" class="oddeven">';
400 print
'<td class="nowrap center">';
401 if ($massactionbutton || $massaction) {
403 if (in_array($object->id, $arrayofselected)) {
406 print
'<input id="cb'.$object->id.
'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
410 $totalarray[
'nbfield']++;
414 print $bon->getNomUrl(1);
418 print $line->LibStatut($obj->statut_ligne, 2);
420 print
'<a href="'.DOL_URL_ROOT.
'/compta/prelevement/line.php?id='.$obj->rowid_ligne.
'">';
421 print substr(
'000000'.$obj->rowid_ligne, -6);
425 $link_to_bill =
'/compta/facture/card.php?facid=';
426 $link_title =
'Invoice';
427 $link_picto =
'bill';
428 if ($type ==
'bank-transfer') {
429 $link_to_bill =
'/fourn/facture/card.php?facid=';
430 $link_title =
'SupplierInvoice';
431 $link_picto =
'supplier_invoice';
433 print
'<a href="'.DOL_URL_ROOT.$link_to_bill.$obj->facid.
'">';
434 print
img_object($langs->trans($link_title), $link_picto);
435 print
' '.$obj->invoiceref.
"</td>\n";
440 print $company->getNomUrl(1);
444 print
'<td class="center">';
445 $link_to_tab =
'/comm/card.php?socid=';
446 $link_code = $obj->code_client;
447 if ($type ==
'bank-transfer') {
448 $link_to_tab =
'/fourn/card.php?socid=';
449 $link_code = $obj->code_fournisseur;
451 print
'<a href="'.DOL_URL_ROOT.$link_to_tab.$company->id.
'">'.$link_code.
"</a></td>\n";
453 print
'<td class="center">'.dol_print_date($db->jdate($obj->datec),
'day').
"</td>\n";
455 print
'<td class="right"><span class="amount">'.price($obj->amount).
"</span></td>\n";
459 print
'<td class="nowrap center">';
460 if ($massactionbutton || $massaction) {
462 if (in_array($object->id, $arrayofselected)) {
465 print
'<input id="cb'.$object->id.
'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
469 $totalarray[
'nbfield']++;
479 print
'<tr><td colspan="8"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td></tr>';
484 $parameters = array(
'arrayfields' => $arrayfields,
'sql' =>
$sql);
485 $reshook = $hookmanager->executeHooks(
'printFieldListFooter', $parameters, $object, $action);
486 print $hookmanager->resPrint;
488 print
'</table>'.
"\n";
491 print
'</form>'.
"\n";