31 require
'../../../main.inc.php';
32 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
33 require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
34 require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/cheque/class/remisecheque.class.php';
35 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
38 $langs->loadLangs(array(
'banks',
'categories',
'bills',
'companies',
'compta'));
42 $action =
GETPOST(
'action',
'aZ09');
43 $confirm =
GETPOST(
'confirm',
'alpha');
47 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
48 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
54 $sortfield =
"b.dateo,b.rowid";
56 if (empty($page) || $page == -1) {
59 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
60 $offset = $limit * $page;
62 $upload_dir = $conf->bank->multidir_output[$object->entity ? $object->entity : $conf->entity].
"/checkdeposits";
64 $search_date_start_day =
GETPOST(
'search_date_start_day',
'int');
65 $search_date_start_month =
GETPOST(
'search_date_start_month',
'int');
66 $search_date_start_year =
GETPOST(
'search_date_start_year',
'int');
67 $search_date_end_day =
GETPOST(
'search_date_end_day',
'int');
68 $search_date_end_month =
GETPOST(
'search_date_end_month',
'int');
69 $search_date_end_year =
GETPOST(
'search_date_end_year',
'int');
70 $search_date_start =
dol_mktime(0, 0, 0, $search_date_start_month, $search_date_start_day, $search_date_start_year);
71 $search_date_end =
dol_mktime(23, 59, 59, $search_date_end_month, $search_date_end_day, $search_date_end_year);
72 $filteraccountid =
GETPOST(
'accountid',
'int');
75 $fieldname = (!empty($ref) ?
'ref' :
'rowid');
77 $socid = $user->socid;
79 $result =
restrictedArea($user,
'cheque', $id,
'bordereau_cheque',
'',
'fk_user_author', $fieldname);
81 $usercanread = $user->rights->banque->cheque;
82 $usercancreate = $user->rights->banque->cheque;
83 $usercandelete = $user->rights->banque->cheque;
85 $permissiontodelete = $user->rights->banque->cheque;
92 if ($action ==
'setdate' && $user->rights->banque->cheque) {
93 $result = $object->fetch(
GETPOST(
'id',
'int'));
97 $result = $object->set_date($user, $date);
106 if ($action ==
'setrefext' && $user->rights->banque->cheque) {
107 $result = $object->fetch(
GETPOST(
'id',
'int'));
111 $result = $object->setValueFrom(
'ref_ext', $ref_ext,
'',
null,
'text',
'', $user,
'CHECKDEPOSIT_MODIFY');
120 if ($action ==
'setref' && $user->rights->banque->cheque) {
121 $result = $object->fetch(
GETPOST(
'id',
'int'));
125 $result = $object->set_number($user, $ref);
134 if ($action ==
'create' &&
GETPOST(
"accountid",
"int") > 0 && $user->rights->banque->cheque) {
135 if (is_array(
GETPOST(
'toRemise'))) {
136 $result = $object->create($user,
GETPOST(
"accountid",
"int"), 0,
GETPOST(
'toRemise'));
138 if ($object->statut == 1) {
139 $object->fetch($object->id);
141 $outputlangs = $langs;
144 $newlang =
GETPOST(
'lang_id',
'aZ09');
147 if (!empty($newlang)) {
149 $outputlangs->setDefaultLang($newlang);
151 $result = $object->generatePdf(
GETPOST(
"model"), $outputlangs);
154 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$object->id);
165 if ($action ==
'remove' && $id > 0 &&
GETPOST(
"lineid",
'int') > 0 && $user->rights->banque->cheque) {
167 $result = $object->removeCheck(
GETPOST(
"lineid",
"int"));
169 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$object->id);
176 if ($action ==
'confirm_delete' && $confirm ==
'yes' && $user->rights->banque->cheque) {
178 $result = $object->delete();
180 header(
"Location: index.php");
187 if ($action ==
'confirm_validate' && $confirm ==
'yes' && $user->rights->banque->cheque) {
188 $result = $object->fetch($id);
189 $result = $object->validate($user);
192 $outputlangs = $langs;
195 $newlang =
GETPOST(
'lang_id',
'aZ09');
198 if (!empty($newlang)) {
200 $outputlangs->setDefaultLang($newlang);
202 $result = $object->generatePdf(
GETPOST(
'model'), $outputlangs);
204 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$object->id);
211 if ($action ==
'confirm_reject_check' && $confirm ==
'yes' && $user->rights->banque->cheque) {
213 $rejected_check =
GETPOST(
'bankid',
'int');
216 $paiement_id = $object->rejectCheck($rejected_check, $reject_date);
217 if ($paiement_id > 0) {
218 setEventMessages($langs->trans(
"CheckRejectedAndInvoicesReopened"),
null,
'mesgs');
228 if ($action ==
'builddoc' && $user->rights->banque->cheque) {
229 $result = $object->fetch($id);
234 $outputlangs = $langs;
237 $newlang =
GETPOST(
'lang_id',
'aZ09');
240 if (!empty($newlang)) {
242 $outputlangs->setDefaultLang($newlang);
244 $result = $object->generatePdf(
GETPOST(
"model"), $outputlangs);
249 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.(empty($conf->global->MAIN_JUMP_TAG) ?
'' :
'#builddoc'));
252 } elseif ($action ==
'remove_file' && $user->rights->banque->cheque) {
254 if ($object->fetch($id) > 0) {
255 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
257 $langs->load(
"other");
259 $filetodelete =
GETPOST(
'file',
'alpha');
260 $file = $upload_dir.
'/'.$filetodelete;
278 $search_date_start_day =
'';
279 $search_date_start_month =
'';
280 $search_date_start_year =
'';
281 $search_date_end_day =
'';
282 $search_date_end_month =
'';
283 $search_date_end_year =
'';
284 $search_date_start =
'';
285 $search_date_end =
'';
286 $filteraccountid = 0;
289 $title = $langs->trans(
"Cheques").
" - ".$langs->trans(
"Card");
297 if ($action ==
'new') {
300 $head[$h][0] = $_SERVER[
"PHP_SELF"].
'?action=new';
301 $head[$h][1] = $langs->trans(
"MenuChequeDeposits");
307 $result = $object->fetch($id, $ref);
314 $head[$h][0] = $_SERVER[
"PHP_SELF"].
'?id='.$object->id;
315 $head[$h][1] = $langs->trans(
"CheckReceipt");
327 if ($action ==
'delete') {
328 print
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
"DeleteCheckReceipt"), $langs->trans(
"ConfirmDeleteCheckReceipt"),
'confirm_delete',
'',
'', 1);
334 if ($action ==
'valide') {
335 print
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
"ValidateCheckReceipt"), $langs->trans(
"ConfirmValidateCheckReceipt"),
'confirm_validate',
'',
'', 1);
341 if ($action ==
'reject_check') {
342 $formquestion = array(
343 array(
'type' =>
'hidden',
'name' =>
'bankid',
'value' =>
GETPOST(
'lineid',
'int')),
344 array(
'type' =>
'date',
'name' =>
'rejectdate_',
'label' => $langs->trans(
"RejectCheckDate"),
'value' =>
dol_now())
346 print
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
"RejectCheck"), $langs->trans(
"ConfirmRejectCheck"),
'confirm_reject_check', $formquestion,
'', 1);
352 if ($action ==
'new') {
360 print
'<span class="opacitymedium">'.$langs->trans(
"SelectChequeTransactionAndGenerate").
'</span><br><br>'.
"\n";
362 print
'<form class="nocellnopadd" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
363 print
'<input type="hidden" name="token" value="'.newToken().
'">';
364 print
'<input type="hidden" name="action" value="new">';
368 print
'<table class="border centpercent">';
371 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"DateChequeReceived").
'</td><td>';
373 print
'<div class="nowrap">';
374 print
$form->selectDate($search_date_start,
'search_date_start_', 0, 0, 1,
'', 1, 1, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
'From'));
376 print
'<div class="nowrap">';
377 print
$form->selectDate($search_date_end,
'search_date_end_', 0, 0, 1,
'', 1, 1, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
'to'));
380 print
'<tr><td>'.$langs->trans(
"BankAccount").
'</td><td>';
381 $form->select_comptes($filteraccountid,
'accountid', 0,
'courant <> 2', 1);
387 print
'<div class="center">';
388 print
'<input type="submit" class="button small" name="filter" value="'.dol_escape_htmltag($langs->trans(
"ToFilter")).
'">';
389 if ($search_date_start || $search_date_end || $filteraccountid > 0) {
391 print
'<input type="submit" class="button" name="removefilter small" value="'.dol_escape_htmltag($langs->trans(
"RemoveFilter")).
'">';
398 $sql =
"SELECT ba.rowid as bid, ba.label,";
399 $sql .=
" b.rowid as transactionid, b.label as transactionlabel, b.datec as datec, b.dateo as date, ";
400 $sql .=
" b.amount, b.emetteur, b.num_chq, b.banque,";
401 $sql .=
" p.rowid as paymentid, p.ref as paymentref";
402 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
403 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement as p ON p.fk_bank = b.rowid";
404 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_account as ba ON (b.fk_account = ba.rowid)";
405 $sql .=
" WHERE b.fk_type = 'CHQ'";
406 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
407 $sql .=
" AND b.fk_bordereau = 0";
408 $sql .=
" AND b.amount > 0";
409 if ($search_date_start) {
410 $sql .=
" AND b.dateo >= '".$db->idate($search_date_start).
"'";
412 if ($search_date_end) {
413 $sql .=
" AND b.dateo <= '".$db->idate($search_date_end).
"'";
415 if ($filteraccountid > 0) {
416 $sql .=
" AND ba.rowid = ".((int) $filteraccountid);
418 $sql .= $db->order(
"b.dateo,b.rowid",
"ASC");
420 $resql = $db->query($sql);
423 while ($obj = $db->fetch_object(
$resql)) {
424 $accounts[$obj->bid] = $obj->label;
425 $lines[$obj->bid][$i][
"date"] = $db->jdate($obj->datec);
426 $lines[$obj->bid][$i][
"amount"] = $obj->amount;
427 $lines[$obj->bid][$i][
"emetteur"] = $obj->emetteur;
428 $lines[$obj->bid][$i][
"numero"] = $obj->num_chq;
429 $lines[$obj->bid][$i][
"banque"] = $obj->banque;
430 $lines[$obj->bid][$i][
"id"] = $obj->transactionid;
431 $lines[$obj->bid][$i][
"ref"] = $obj->transactionid;
432 $lines[$obj->bid][$i][
"label"] = $obj->transactionlabel;
433 $lines[$obj->bid][$i][
"paymentid"] = $obj->paymentid;
434 $lines[$obj->bid][$i][
"paymentref"] = $obj->paymentref;
435 $lines[$obj->bid][$i][
"paymentdate"] = $db->jdate($obj->date);
440 print
'<div class="opacitymedium">'.$langs->trans(
"NoWaitingChecks").
'</div><br>';
444 foreach ($accounts as $bid => $account_label) {
446 <script type="text/javascript">
447 jQuery(document).ready(function()
449 jQuery("#checkall_'.$bid.
'").click(function()
451 jQuery(".checkforremise_'.$bid.
'").prop(\'checked\', true);
453 jQuery("#checknone_'.$bid.
'").click(function()
455 jQuery(".checkforremise_'.$bid.
'").prop(\'checked\', false);
461 $num = $db->num_rows(
$resql);
462 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
463 print
'<input type="hidden" name="token" value="'.newToken().
'">';
464 print
'<input type="hidden" name="action" value="create">';
465 print
'<input type="hidden" name="accountid" value="'.$bid.
'">';
468 print
'<div class="div-table-responsive-no-min">';
469 print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
471 print
'<tr class="liste_titre">';
472 print
'<td>'.$langs->trans(
"DateChequeReceived").
'</td>'.
"\n";
473 print
'<td>'.$langs->trans(
"ChequeNumber").
"</td>\n";
474 print
'<td>'.$langs->trans(
"CheckTransmitter").
"</td>\n";
475 print
'<td>'.$langs->trans(
"Bank").
"</td>\n";
476 print
'<td>'.$langs->trans(
"Amount").
"</td>\n";
477 print
'<td class="center">'.$langs->trans(
"Payment").
"</td>\n";
478 print
'<td class="center">'.$langs->trans(
"LineRecord").
"</td>\n";
479 print
'<td class="center">'.$langs->trans(
"Select").
"<br>";
480 if ($conf->use_javascript_ajax) {
481 print
'<a href="#" id="checkall_'.$bid.
'">'.$langs->trans(
"All").
'</a> / <a href="#" id="checknone_'.$bid.
'">'.$langs->trans(
"None").
'</a>';
486 if (count($lines[$bid])) {
487 foreach ($lines[$bid] as $lid => $value) {
495 print
'<tr class="oddeven">';
496 print
'<td>'.dol_print_date($value[
"date"],
'day').
'</td>';
497 print
'<td>'.$value[
"numero"].
"</td>\n";
498 print
'<td>'.$value[
"emetteur"].
"</td>\n";
499 print
'<td>'.$value[
"banque"].
"</td>\n";
500 print
'<td class="right"><span class="amount">'.price($value[
"amount"], 0, $langs, 1, -1, -1, $conf->currency).
'</span></td>';
503 print
'<td class="center">';
504 $paymentstatic->id = $value[
"paymentid"];
505 $paymentstatic->ref = $value[
"paymentref"];
506 $paymentstatic->date = $value[
"paymentdate"];
507 if ($paymentstatic->id) {
508 print $paymentstatic->getNomUrl(1);
514 print
'<td class="center">';
515 $accountlinestatic->id = $value[
"id"];
516 $accountlinestatic->ref = $value[
"ref"];
517 if ($accountlinestatic->id > 0) {
518 print $accountlinestatic->getNomUrl(1);
524 print
'<td class="center">';
525 print
'<input id="'.$value[
"id"].
'" class="flat checkforremise_'.$bid.
'" checked type="checkbox" name="toRemise[]" value="'.$value[
"id"].
'">';
535 print
'<div class="tabsAction">';
536 if ($user->rights->banque->cheque) {
537 print
'<input type="submit" class="button" value="'.$langs->trans(
'NewCheckDepositOn', $account_label).
'">';
539 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"NotEnoughPermissions").
'">'.$langs->trans(
'NewCheckDepositOn', $account_label).
'</a>';
547 $accountstatic =
new Account($db);
548 $accountstatic->fetch($object->account_id);
550 $linkback =
'<a href="'.DOL_URL_ROOT.
'/compta/paiement/cheque/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
553 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
556 print
'<div class="fichecenter">';
557 print
'<div class="underbanner clearboth"></div>';
560 print
'<table class="border centpercent">';
562 print
'<tr><td class="titlefield">';
564 print
'<table class="nobordernopadding" width="100%"><tr><td>';
565 print $langs->trans(
'Date');
567 if ($action !=
'editdate') {
568 print
'<td class="right"><a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editdate&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->trans(
'SetDate'), 1).
'</a></td>';
570 print
'</tr></table>';
571 print
'</td><td colspan="2">';
572 if ($action ==
'editdate') {
573 print
'<form name="setdate" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="post">';
574 print
'<input type="hidden" name="token" value="'.newToken().
'">';
575 print
'<input type="hidden" name="action" value="setdate">';
576 print
$form->selectDate($object->date_bordereau,
'datecreate_',
'',
'',
'',
"setdate");
577 print
'<input type="submit" class="button button-edit" value="'.$langs->trans(
'Modify').
'">';
580 print $object->date_bordereau ?
dol_print_date($object->date_bordereau,
'day') :
' ';
614 print
'<tr><td>'.$langs->trans(
'Account').
'</td><td colspan="2">';
615 print $accountstatic->getNomUrl(1);
619 print
'<tr><td>'.$langs->trans(
'NbOfCheques').
'</td><td colspan="2">';
620 print $object->nbcheque;
623 print
'<tr><td>'.$langs->trans(
'Total').
'</td><td colspan="2">';
624 print
price($object->amount);
631 print
'</table><br>';
637 $sql =
"SELECT b.rowid, b.rowid as ref, b.label, b.amount, b.num_chq, b.emetteur,";
638 $sql .=
" b.dateo as date, b.datec as datec, b.banque,";
639 $sql .=
" p.rowid as pid, p.ref as pref, ba.rowid as bid, p.statut";
640 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank_account as ba";
641 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank as b ON (b.fk_account = ba.rowid)";
642 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement as p ON p.fk_bank = b.rowid";
643 $sql .=
" WHERE ba.entity IN (".getEntity(
'bank_account').
")";
644 $sql .=
" AND b.fk_type= 'CHQ'";
645 $sql .=
" AND b.fk_bordereau = ".((int) $object->id);
646 $sql .= $db->order($sortfield, $sortorder);
648 $resql = $db->query($sql);
650 $num = $db->num_rows(
$resql);
652 print
'<div class="div-table-responsive">';
653 print
'<table class="noborder centpercent">';
655 $param =
"&id=".$object->id;
657 print
'<tr class="liste_titre">';
659 print_liste_field_titre(
"DateChequeReceived", $_SERVER[
"PHP_SELF"],
"b.dateo,b.rowid",
"", $param,
'align="center"', $sortfield, $sortorder);
660 print_liste_field_titre(
"Numero", $_SERVER[
"PHP_SELF"],
"b.num_chq",
"", $param,
'align="center"', $sortfield, $sortorder);
661 print_liste_field_titre(
"CheckTransmitter", $_SERVER[
"PHP_SELF"],
"b.emetteur",
"", $param,
"", $sortfield, $sortorder);
663 print_liste_field_titre(
"Amount", $_SERVER[
"PHP_SELF"],
"b.amount",
"", $param,
'class="right"', $sortfield, $sortorder);
664 print_liste_field_titre(
"Payment", $_SERVER[
"PHP_SELF"],
"p.rowid",
"", $param,
'align="center"', $sortfield, $sortorder);
665 print_liste_field_titre(
"LineRecord", $_SERVER[
"PHP_SELF"],
"b.rowid",
"", $param,
'align="center"', $sortfield, $sortorder);
671 while ($objp = $db->fetch_object(
$resql)) {
672 $paymentstatic->id = $objp->pid;
673 $paymentstatic->ref = $objp->pref;
675 $accountlinestatic->id = $objp->rowid;
676 $accountlinestatic->ref = $objp->ref;
678 print
'<tr class="oddeven">';
679 print
'<td class="center">'.$i.
'</td>';
680 print
'<td class="center">'.dol_print_date($db->jdate($objp->date),
'day').
'</td>';
681 print
'<td class="center">'.($objp->num_chq ? $objp->num_chq :
' ').
'</td>';
682 print
'<td>'.dol_trunc($objp->emetteur, 24).
'</td>';
683 print
'<td>'.dol_trunc($objp->banque, 24).
'</td>';
684 print
'<td class="right"><span class="amount">'.price($objp->amount).
'</span></td>';
686 print
'<td class="center">';
687 if ($paymentstatic->id) {
688 print $paymentstatic->getNomUrl(1);
694 print
'<td class="center">';
695 if ($accountlinestatic->id > 0) {
696 print $accountlinestatic->getNomUrl(1);
702 print
'<td class="right">';
703 if ($object->statut == 0) {
704 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=remove&token='.
newToken().
'&lineid='.$objp->rowid.
'">'.
img_delete().
'</a>';
706 if ($object->statut == 1 && $objp->statut != 2) {
707 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=reject_check&token='.
newToken().
'&lineid='.$objp->rowid.
'">'.
img_picto($langs->trans(
"RejectCheck"),
'disable').
'</a>';
709 if ($objp->statut == 2) {
710 print
' '.img_picto($langs->trans(
'CheckRejected'),
'statut8').
'</a>';
718 print
'<td colspan="8" class="opacitymedium">';
719 print $langs->trans(
"None");
726 if ($num > 0 && $i < ($object->nbcheque + 1)) {
728 $langs->load(
"errors");
729 print
info_admin($langs->trans(
"WarningSomeBankTransactionByChequeWereRemovedAfter"), 0, 0,
'warning');
748 print
'<div class="tabsAction">';
750 if ($user->socid == 0 && !empty($object->id) && $object->statut == 0 && $user->rights->banque->cheque) {
751 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=valide&token='.
newToken().
'&sortfield='.$sortfield.
'&sortorder='.$sortorder.
'">'.$langs->trans(
'Validate').
'</a>';
754 if ($user->socid == 0 && !empty($object->id) && $user->rights->banque->cheque) {
755 print
dolGetButtonAction($langs->trans(
"Delete"),
'',
'delete', $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=delete&token='.
newToken(),
'delete', $permissiontodelete);
761 if ($action !=
'new') {
762 if ($object->statut == 1) {
765 $filedir = $upload_dir.
'/'.$objref;
766 $urlsource = $_SERVER[
"PHP_SELF"].
"?id=".$object->id;
767 $genallowed = $usercancreate;
768 $delallowed = $usercandelete;
769 print $formfile->showdocuments(
'remisecheque', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0,
'',
'',
'', $langs->defaultlang);