30 require
'../../../main.inc.php';
31 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
32 require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
33 require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/cheque/class/remisecheque.class.php';
34 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
37 $langs->loadLangs(array(
'banks',
'categories',
'bills',
'companies',
'compta'));
41 $action =
GETPOST(
'action',
'aZ09');
42 $confirm =
GETPOST(
'confirm',
'alpha');
46 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
47 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
53 $sortfield =
"b.dateo,b.rowid";
55 if (empty($page) || $page == -1) {
58 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
59 $offset = $limit * $page;
61 $upload_dir = $conf->bank->multidir_output[$object->entity ? $object->entity : $conf->entity].
"/checkdeposits";
64 $filteraccountid =
GETPOST(
'accountid',
'int');
67 $fieldname = (!empty($ref) ?
'ref' :
'rowid');
69 $socid = $user->socid;
71 $result =
restrictedArea($user,
'cheque', $id,
'bordereau_cheque',
'',
'fk_user_author', $fieldname);
73 $usercanread = $user->rights->banque->cheque;
74 $usercancreate = $user->rights->banque->cheque;
75 $usercandelete = $user->rights->banque->cheque;
83 if ($action ==
'setdate' && $user->rights->banque->cheque) {
84 $result = $object->fetch(
GETPOST(
'id',
'int'));
88 $result = $object->set_date($user, $date);
97 if ($action ==
'setrefext' && $user->rights->banque->cheque) {
98 $result = $object->fetch(
GETPOST(
'id',
'int'));
102 $result = $object->setValueFrom(
'ref_ext', $ref_ext,
'',
null,
'text',
'', $user,
'CHECKDEPOSIT_MODIFY');
111 if ($action ==
'setref' && $user->rights->banque->cheque) {
112 $result = $object->fetch(
GETPOST(
'id',
'int'));
116 $result = $object->set_number($user, $ref);
125 if ($action ==
'create' &&
GETPOST(
"accountid",
"int") > 0 && $user->rights->banque->cheque) {
126 if (is_array(
GETPOST(
'toRemise'))) {
127 $result = $object->create($user,
GETPOST(
"accountid",
"int"), 0,
GETPOST(
'toRemise'));
129 if ($object->statut == 1) {
130 $object->fetch($object->id);
132 $outputlangs = $langs;
134 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
135 $newlang =
GETPOST(
'lang_id',
'aZ09');
138 if (!empty($newlang)) {
140 $outputlangs->setDefaultLang($newlang);
142 $result = $object->generatePdf(
GETPOST(
"model"), $outputlangs);
145 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$object->id);
156 if ($action ==
'remove' && $id > 0 &&
GETPOST(
"lineid",
'int') > 0 && $user->rights->banque->cheque) {
158 $result = $object->removeCheck(
GETPOST(
"lineid",
"int"));
160 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$object->id);
167 if ($action ==
'confirm_delete' && $confirm ==
'yes' && $user->rights->banque->cheque) {
169 $result = $object->delete();
171 header(
"Location: index.php");
178 if ($action ==
'confirm_validate' && $confirm ==
'yes' && $user->rights->banque->cheque) {
179 $result = $object->fetch($id);
180 $result = $object->validate($user);
183 $outputlangs = $langs;
185 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
186 $newlang =
GETPOST(
'lang_id',
'aZ09');
189 if (!empty($newlang)) {
191 $outputlangs->setDefaultLang($newlang);
193 $result = $object->generatePdf(
GETPOST(
'model'), $outputlangs);
195 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$object->id);
202 if ($action ==
'confirm_reject_check' && $confirm ==
'yes' && $user->rights->banque->cheque) {
204 $rejected_check =
GETPOST(
'bankid',
'int');
207 $paiement_id = $object->rejectCheck($rejected_check, $reject_date);
208 if ($paiement_id > 0) {
209 setEventMessages($langs->trans(
"CheckRejectedAndInvoicesReopened"),
null,
'mesgs');
219 if ($action ==
'builddoc' && $user->rights->banque->cheque) {
220 $result = $object->fetch($id);
225 $outputlangs = $langs;
227 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
228 $newlang =
GETPOST(
'lang_id',
'aZ09');
231 if (!empty($newlang)) {
233 $outputlangs->setDefaultLang($newlang);
235 $result = $object->generatePdf(
GETPOST(
"model"), $outputlangs);
240 header(
'Location: '.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.(empty($conf->global->MAIN_JUMP_TAG) ?
'' :
'#builddoc'));
243 } elseif ($action ==
'remove_file' && $user->rights->banque->cheque) {
245 if ($object->fetch($id) > 0) {
246 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
248 $langs->load(
"other");
250 $filetodelete =
GETPOST(
'file',
'alpha');
251 $file = $upload_dir.
'/'.$filetodelete;
269 $filteraccountid = 0;
272 $title = $langs->trans(
"Cheques").
" - ".$langs->trans(
"Card");
280 if ($action ==
'new') {
283 $head[$h][0] = $_SERVER[
"PHP_SELF"].
'?action=new';
284 $head[$h][1] = $langs->trans(
"MenuChequeDeposits");
290 $result = $object->fetch($id, $ref);
297 $head[$h][0] = $_SERVER[
"PHP_SELF"].
'?id='.$object->id;
298 $head[$h][1] = $langs->trans(
"CheckReceipt");
310 if ($action ==
'delete') {
311 print
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
"DeleteCheckReceipt"), $langs->trans(
"ConfirmDeleteCheckReceipt"),
'confirm_delete',
'',
'', 1);
317 if ($action ==
'valide') {
318 print
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
"ValidateCheckReceipt"), $langs->trans(
"ConfirmValidateCheckReceipt"),
'confirm_validate',
'',
'', 1);
324 if ($action ==
'reject_check') {
325 $formquestion = array(
326 array(
'type' =>
'hidden',
'name' =>
'bankid',
'value' =>
GETPOST(
'lineid',
'int')),
327 array(
'type' =>
'date',
'name' =>
'rejectdate_',
'label' => $langs->trans(
"RejectCheckDate"),
'value' =>
dol_now())
329 print
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
"RejectCheck"), $langs->trans(
"ConfirmRejectCheck"),
'confirm_reject_check', $formquestion,
'', 1);
335 if ($action ==
'new') {
343 print
'<span class="opacitymedium">'.$langs->trans(
"SelectChequeTransactionAndGenerate").
'</span><br><br>'.
"\n";
345 print
'<form class="nocellnopadd" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
346 print
'<input type="hidden" name="token" value="'.newToken().
'">';
347 print
'<input type="hidden" name="action" value="new">';
351 print
'<table class="border centpercent">';
354 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"DateChequeReceived").
'</td><td>';
355 print
$form->selectDate($filterdate,
'fd', 0, 0, 1,
'', 1, 1);
357 print
'<tr><td>'.$langs->trans(
"BankAccount").
'</td><td>';
358 $form->select_comptes($filteraccountid,
'accountid', 0,
'courant <> 2', 1);
364 print
'<div class="center">';
365 print
'<input type="submit" class="button" name="filter" value="'.dol_escape_htmltag($langs->trans(
"ToFilter")).
'">';
366 if ($filterdate || $filteraccountid > 0) {
368 print
'<input type="submit" class="button" name="removefilter" value="'.dol_escape_htmltag($langs->trans(
"RemoveFilter")).
'">';
374 $sql =
"SELECT ba.rowid as bid, ba.label,";
375 $sql .=
" b.rowid as transactionid, b.label as transactionlabel, b.datec as datec, b.dateo as date, ";
376 $sql .=
" b.amount, b.emetteur, b.num_chq, b.banque,";
377 $sql .=
" p.rowid as paymentid, p.ref as paymentref";
378 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
379 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement as p ON p.fk_bank = b.rowid";
380 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_account as ba ON (b.fk_account = ba.rowid)";
381 $sql .=
" WHERE b.fk_type = 'CHQ'";
382 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
383 $sql .=
" AND b.fk_bordereau = 0";
384 $sql .=
" AND b.amount > 0";
386 $sql .=
" AND b.dateo = '".$db->idate($filterdate).
"'";
388 if ($filteraccountid > 0) {
389 $sql .=
" AND ba.rowid = ".((int) $filteraccountid);
391 $sql .= $db->order(
"b.dateo,b.rowid",
"ASC");
393 $resql = $db->query($sql);
396 while ($obj = $db->fetch_object(
$resql)) {
397 $accounts[$obj->bid] = $obj->label;
398 $lines[$obj->bid][$i][
"date"] = $db->jdate($obj->datec);
399 $lines[$obj->bid][$i][
"amount"] = $obj->amount;
400 $lines[$obj->bid][$i][
"emetteur"] = $obj->emetteur;
401 $lines[$obj->bid][$i][
"numero"] = $obj->num_chq;
402 $lines[$obj->bid][$i][
"banque"] = $obj->banque;
403 $lines[$obj->bid][$i][
"id"] = $obj->transactionid;
404 $lines[$obj->bid][$i][
"ref"] = $obj->transactionid;
405 $lines[$obj->bid][$i][
"label"] = $obj->transactionlabel;
406 $lines[$obj->bid][$i][
"paymentid"] = $obj->paymentid;
407 $lines[$obj->bid][$i][
"paymentref"] = $obj->paymentref;
408 $lines[$obj->bid][$i][
"paymentdate"] = $db->jdate($obj->date);
413 print
'<div class="opacitymedium">'.$langs->trans(
"NoWaitingChecks").
'</div><br>';
417 foreach ($accounts as $bid => $account_label) {
419 <script type="text/javascript">
420 jQuery(document).ready(function()
422 jQuery("#checkall_'.$bid.
'").click(function()
424 jQuery(".checkforremise_'.$bid.
'").prop(\'checked\', true);
426 jQuery("#checknone_'.$bid.
'").click(function()
428 jQuery(".checkforremise_'.$bid.
'").prop(\'checked\', false);
434 $num = $db->num_rows(
$resql);
435 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
436 print
'<input type="hidden" name="token" value="'.newToken().
'">';
437 print
'<input type="hidden" name="action" value="create">';
438 print
'<input type="hidden" name="accountid" value="'.$bid.
'">';
441 print
'<div class="div-table-responsive-no-min">';
442 print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
444 print
'<tr class="liste_titre">';
445 print
'<td>'.$langs->trans(
"DateChequeReceived").
'</td>'.
"\n";
446 print
'<td>'.$langs->trans(
"ChequeNumber").
"</td>\n";
447 print
'<td>'.$langs->trans(
"CheckTransmitter").
"</td>\n";
448 print
'<td>'.$langs->trans(
"Bank").
"</td>\n";
449 print
'<td>'.$langs->trans(
"Amount").
"</td>\n";
450 print
'<td class="center">'.$langs->trans(
"Payment").
"</td>\n";
451 print
'<td class="center">'.$langs->trans(
"LineRecord").
"</td>\n";
452 print
'<td class="center">'.$langs->trans(
"Select").
"<br>";
453 if ($conf->use_javascript_ajax) {
454 print
'<a href="#" id="checkall_'.$bid.
'">'.$langs->trans(
"All").
'</a> / <a href="#" id="checknone_'.$bid.
'">'.$langs->trans(
"None").
'</a>';
459 if (count($lines[$bid])) {
460 foreach ($lines[$bid] as $lid => $value) {
468 print
'<tr class="oddeven">';
469 print
'<td>'.dol_print_date($value[
"date"],
'day').
'</td>';
470 print
'<td>'.$value[
"numero"].
"</td>\n";
471 print
'<td>'.$value[
"emetteur"].
"</td>\n";
472 print
'<td>'.$value[
"banque"].
"</td>\n";
473 print
'<td class="right"><span class="amount">'.price($value[
"amount"], 0, $langs, 1, -1, -1, $conf->currency).
'</span></td>';
476 print
'<td class="center">';
477 $paymentstatic->id = $value[
"paymentid"];
478 $paymentstatic->ref = $value[
"paymentref"];
479 $paymentstatic->date = $value[
"paymentdate"];
480 if ($paymentstatic->id) {
481 print $paymentstatic->getNomUrl(1);
487 print
'<td class="center">';
488 $accountlinestatic->id = $value[
"id"];
489 $accountlinestatic->ref = $value[
"ref"];
490 if ($accountlinestatic->id > 0) {
491 print $accountlinestatic->getNomUrl(1);
497 print
'<td class="center">';
498 print
'<input id="'.$value[
"id"].
'" class="flat checkforremise_'.$bid.
'" checked type="checkbox" name="toRemise[]" value="'.$value[
"id"].
'">';
508 print
'<div class="tabsAction">';
509 if ($user->rights->banque->cheque) {
510 print
'<input type="submit" class="button" value="'.$langs->trans(
'NewCheckDepositOn', $account_label).
'">';
512 print
'<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"NotEnoughPermissions").
'">'.$langs->trans(
'NewCheckDepositOn', $account_label).
'</a>';
520 $accountstatic =
new Account($db);
521 $accountstatic->fetch($object->account_id);
523 $linkback =
'<a href="'.DOL_URL_ROOT.
'/compta/paiement/cheque/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
526 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
529 print
'<div class="fichecenter">';
530 print
'<div class="underbanner clearboth"></div>';
533 print
'<table class="border centpercent">';
535 print
'<tr><td class="titlefield">';
537 print
'<table class="nobordernopadding" width="100%"><tr><td>';
538 print $langs->trans(
'Date');
540 if ($action !=
'editdate') {
541 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>';
543 print
'</tr></table>';
544 print
'</td><td colspan="2">';
545 if ($action ==
'editdate') {
546 print
'<form name="setdate" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="post">';
547 print
'<input type="hidden" name="token" value="'.newToken().
'">';
548 print
'<input type="hidden" name="action" value="setdate">';
549 print
$form->selectDate($object->date_bordereau,
'datecreate_',
'',
'',
'',
"setdate");
550 print
'<input type="submit" class="button button-edit" value="'.$langs->trans(
'Modify').
'">';
553 print $object->date_bordereau ?
dol_print_date($object->date_bordereau,
'day') :
' ';
587 print
'<tr><td>'.$langs->trans(
'Account').
'</td><td colspan="2">';
588 print $accountstatic->getNomUrl(1);
592 print
'<tr><td>'.$langs->trans(
'NbOfCheques').
'</td><td colspan="2">';
593 print $object->nbcheque;
596 print
'<tr><td>'.$langs->trans(
'Total').
'</td><td colspan="2">';
597 print
price($object->amount);
604 print
'</table><br>';
610 $sql =
"SELECT b.rowid, b.rowid as ref, b.label, b.amount, b.num_chq, b.emetteur,";
611 $sql .=
" b.dateo as date, b.datec as datec, b.banque,";
612 $sql .=
" p.rowid as pid, p.ref as pref, ba.rowid as bid, p.statut";
613 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank_account as ba";
614 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank as b ON (b.fk_account = ba.rowid)";
615 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement as p ON p.fk_bank = b.rowid";
616 $sql .=
" WHERE ba.entity IN (".getEntity(
'bank_account').
")";
617 $sql .=
" AND b.fk_type= 'CHQ'";
618 $sql .=
" AND b.fk_bordereau = ".((int) $object->id);
619 $sql .= $db->order($sortfield, $sortorder);
621 $resql = $db->query($sql);
623 $num = $db->num_rows(
$resql);
625 print
'<div class="div-table-responsive">';
626 print
'<table class="noborder centpercent">';
628 $param =
"&id=".$object->id;
630 print
'<tr class="liste_titre">';
632 print_liste_field_titre(
"DateChequeReceived", $_SERVER[
"PHP_SELF"],
"b.dateo,b.rowid",
"", $param,
'align="center"', $sortfield, $sortorder);
633 print_liste_field_titre(
"Numero", $_SERVER[
"PHP_SELF"],
"b.num_chq",
"", $param,
'align="center"', $sortfield, $sortorder);
634 print_liste_field_titre(
"CheckTransmitter", $_SERVER[
"PHP_SELF"],
"b.emetteur",
"", $param,
"", $sortfield, $sortorder);
636 print_liste_field_titre(
"Amount", $_SERVER[
"PHP_SELF"],
"b.amount",
"", $param,
'class="right"', $sortfield, $sortorder);
637 print_liste_field_titre(
"Payment", $_SERVER[
"PHP_SELF"],
"p.rowid",
"", $param,
'align="center"', $sortfield, $sortorder);
638 print_liste_field_titre(
"LineRecord", $_SERVER[
"PHP_SELF"],
"b.rowid",
"", $param,
'align="center"', $sortfield, $sortorder);
644 while ($objp = $db->fetch_object(
$resql)) {
645 $paymentstatic->id = $objp->pid;
646 $paymentstatic->ref = $objp->pref;
648 $accountlinestatic->id = $objp->rowid;
649 $accountlinestatic->ref = $objp->ref;
651 print
'<tr class="oddeven">';
652 print
'<td class="center">'.$i.
'</td>';
653 print
'<td class="center">'.dol_print_date($db->jdate($objp->date),
'day').
'</td>';
654 print
'<td class="center">'.($objp->num_chq ? $objp->num_chq :
' ').
'</td>';
655 print
'<td>'.dol_trunc($objp->emetteur, 24).
'</td>';
656 print
'<td>'.dol_trunc($objp->banque, 24).
'</td>';
657 print
'<td class="right"><span class="amount">'.price($objp->amount).
'</span></td>';
659 print
'<td class="center">';
660 if ($paymentstatic->id) {
661 print $paymentstatic->getNomUrl(1);
667 print
'<td class="center">';
668 if ($accountlinestatic->id > 0) {
669 print $accountlinestatic->getNomUrl(1);
675 print
'<td class="right">';
676 if ($object->statut == 0) {
677 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=remove&token='.
newToken().
'&lineid='.$objp->rowid.
'">'.
img_delete().
'</a>';
679 if ($object->statut == 1 && $objp->statut != 2) {
680 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=reject_check&token='.
newToken().
'&lineid='.$objp->rowid.
'">'.
img_picto($langs->trans(
"RejectCheck"),
'disable').
'</a>';
682 if ($objp->statut == 2) {
683 print
' '.img_picto($langs->trans(
'CheckRejected'),
'statut8').
'</a>';
691 print
'<td colspan="8" class="opacitymedium">';
692 print $langs->trans(
"None");
699 if ($num > 0 && $i < ($object->nbcheque + 1)) {
701 $langs->load(
"errors");
702 print
info_admin($langs->trans(
"WarningSomeBankTransactionByChequeWereRemovedAfter"), 0, 0,
'warning');
721 print
'<div class="tabsAction">';
723 if ($user->socid == 0 && !empty($object->id) && $object->statut == 0 && $user->rights->banque->cheque) {
724 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=valide&token='.
newToken().
'&sortfield='.$sortfield.
'&sortorder='.$sortorder.
'">'.$langs->trans(
'Validate').
'</a>';
727 if ($user->socid == 0 && !empty($object->id) && $user->rights->banque->cheque) {
728 print
'<a class="butActionDelete" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=delete&token='.
newToken().
'&sortfield='.$sortfield.
'&sortorder='.$sortorder.
'">'.$langs->trans(
'Delete').
'</a>';
734 if ($action !=
'new') {
735 if ($object->statut == 1) {
738 $filedir = $upload_dir.
'/'.$objref;
739 $urlsource = $_SERVER[
"PHP_SELF"].
"?id=".$object->id;
740 $genallowed = $usercancreate;
741 $delallowed = $usercandelete;
742 print $formfile->showdocuments(
'remisecheque', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0,
'',
'',
'', $langs->defaultlang);