card.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  1. <?php
  2. /* Copyright (C) 2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2007-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2009-2012 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2011-2016 Juanjo Menent <jmenent@2byte.es>
  6. * Copyright (C) 2013 Philippe Grand <philippe.grand@atoo-net.com>
  7. * Copyright (C) 2015-2016 Alexandre Spangaro <aspangaro@open-dsi.fr>
  8. * Copyright (C) 2018-2021 Frédéric France <frederic.france@netlogic.fr>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  22. */
  23. /**
  24. * \file htdocs/compta/paiement/cheque/card.php
  25. * \ingroup bank, invoice
  26. * \brief Page for cheque deposits
  27. */
  28. require '../../../main.inc.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/compta/paiement/cheque/class/remisecheque.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  33. // Load translation files required by the page
  34. $langs->loadLangs(array('banks', 'categories', 'bills', 'companies', 'compta'));
  35. $id = GETPOST('id', 'int');
  36. $ref = GETPOST('ref', 'alpha');
  37. $action = GETPOST('action', 'aZ09');
  38. $confirm = GETPOST('confirm', 'alpha');
  39. // Security check
  40. $fieldname = (!empty($ref) ? 'ref' : 'rowid');
  41. if ($user->socid) {
  42. $socid = $user->socid;
  43. }
  44. $result = restrictedArea($user, 'cheque', $id, 'bordereau_cheque', '', 'fk_user_author', $fieldname);
  45. $sortfield = GETPOST('sortfield', 'aZ09comma');
  46. $sortorder = GETPOST('sortorder', 'aZ09comma');
  47. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  48. if (!$sortorder) {
  49. $sortorder = "ASC";
  50. }
  51. if (!$sortfield) {
  52. $sortfield = "b.dateo,b.rowid";
  53. }
  54. if (empty($page) || $page == -1) {
  55. $page = 0;
  56. }
  57. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  58. $offset = $limit * $page;
  59. $dir = $conf->bank->dir_output.'/checkdeposits/';
  60. $filterdate = dol_mktime(0, 0, 0, GETPOST('fdmonth'), GETPOST('fdday'), GETPOST('fdyear'));
  61. $filteraccountid = GETPOST('accountid', 'int');
  62. $object = new RemiseCheque($db);
  63. /*
  64. * Actions
  65. */
  66. if ($action == 'setdate' && $user->rights->banque->cheque) {
  67. $result = $object->fetch(GETPOST('id', 'int'));
  68. if ($result > 0) {
  69. $date = dol_mktime(0, 0, 0, GETPOST('datecreate_month', 'int'), GETPOST('datecreate_day', 'int'), GETPOST('datecreate_year', 'int'));
  70. $result = $object->set_date($user, $date);
  71. if ($result < 0) {
  72. setEventMessages($object->error, $object->errors, 'errors');
  73. }
  74. } else {
  75. setEventMessages($object->error, $object->errors, 'errors');
  76. }
  77. }
  78. if ($action == 'setrefext' && $user->rights->banque->cheque) {
  79. $result = $object->fetch(GETPOST('id', 'int'));
  80. if ($result > 0) {
  81. $ref_ext = GETPOST('ref_ext');
  82. $result = $object->setValueFrom('ref_ext', $ref_ext, '', null, 'text', '', $user, 'CHECKDEPOSIT_MODIFY');
  83. if ($result < 0) {
  84. setEventMessages($object->error, $object->errors, 'errors');
  85. }
  86. } else {
  87. setEventMessages($object->error, $object->errors, 'errors');
  88. }
  89. }
  90. if ($action == 'setref' && $user->rights->banque->cheque) {
  91. $result = $object->fetch(GETPOST('id', 'int'));
  92. if ($result > 0) {
  93. $ref = GETPOST('ref');
  94. $result = $object->set_number($user, $ref);
  95. if ($result < 0) {
  96. setEventMessages($object->error, $object->errors, 'errors');
  97. }
  98. } else {
  99. setEventMessages($object->error, $object->errors, 'errors');
  100. }
  101. }
  102. if ($action == 'create' && GETPOST("accountid", "int") > 0 && $user->rights->banque->cheque) {
  103. if (is_array(GETPOST('toRemise'))) {
  104. $result = $object->create($user, GETPOST("accountid", "int"), 0, GETPOST('toRemise'));
  105. if ($result > 0) {
  106. if ($object->statut == 1) { // If statut is validated, we build doc
  107. $object->fetch($object->id); // To force to reload all properties in correct property name
  108. // Define output language
  109. $outputlangs = $langs;
  110. $newlang = '';
  111. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
  112. $newlang = GETPOST('lang_id', 'aZ09');
  113. }
  114. //if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
  115. if (!empty($newlang)) {
  116. $outputlangs = new Translate("", $conf);
  117. $outputlangs->setDefaultLang($newlang);
  118. }
  119. $result = $object->generatePdf(GETPOST("model"), $outputlangs);
  120. }
  121. header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id);
  122. exit;
  123. } else {
  124. setEventMessages($object->error, $object->errors, 'errors');
  125. }
  126. } else {
  127. setEventMessages($langs->trans("ErrorSelectAtLeastOne"), null, 'mesgs');
  128. $action = 'new';
  129. }
  130. }
  131. if ($action == 'remove' && $id > 0 && GETPOST("lineid", 'int') > 0 && $user->rights->banque->cheque) {
  132. $object->id = $id;
  133. $result = $object->removeCheck(GETPOST("lineid", "int"));
  134. if ($result === 0) {
  135. header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id);
  136. exit;
  137. } else {
  138. setEventMessages($object->error, $object->errors, 'errors');
  139. }
  140. }
  141. if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->banque->cheque) {
  142. $object->id = $id;
  143. $result = $object->delete();
  144. if ($result == 0) {
  145. header("Location: index.php");
  146. exit;
  147. } else {
  148. setEventMessages($paiement->error, $paiement->errors, 'errors');
  149. }
  150. }
  151. if ($action == 'confirm_validate' && $confirm == 'yes' && $user->rights->banque->cheque) {
  152. $result = $object->fetch($id);
  153. $result = $object->validate($user);
  154. if ($result >= 0) {
  155. // Define output language
  156. $outputlangs = $langs;
  157. $newlang = '';
  158. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
  159. $newlang = GETPOST('lang_id', 'aZ09');
  160. }
  161. //if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
  162. if (!empty($newlang)) {
  163. $outputlangs = new Translate("", $conf);
  164. $outputlangs->setDefaultLang($newlang);
  165. }
  166. $result = $object->generatePdf(GETPOST('model'), $outputlangs);
  167. header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id);
  168. exit;
  169. } else {
  170. setEventMessages($object->error, $object->errors, 'errors');
  171. }
  172. }
  173. if ($action == 'confirm_reject_check' && $confirm == 'yes' && $user->rights->banque->cheque) {
  174. $reject_date = dol_mktime(0, 0, 0, GETPOST('rejectdate_month'), GETPOST('rejectdate_day'), GETPOST('rejectdate_year'));
  175. $rejected_check = GETPOST('bankid', 'int');
  176. $object->fetch($id);
  177. $paiement_id = $object->rejectCheck($rejected_check, $reject_date);
  178. if ($paiement_id > 0) {
  179. setEventMessages($langs->trans("CheckRejectedAndInvoicesReopened"), null, 'mesgs');
  180. //header("Location: ".DOL_URL_ROOT.'/compta/paiement/card.php?id='.$paiement_id);
  181. //exit;
  182. $action = '';
  183. } else {
  184. setEventMessages($object->error, $object->errors, 'errors');
  185. $action = '';
  186. }
  187. }
  188. if ($action == 'builddoc' && $user->rights->banque->cheque) {
  189. $result = $object->fetch($id);
  190. // Save last template used to generate document
  191. //if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha'));
  192. $outputlangs = $langs;
  193. $newlang = '';
  194. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
  195. $newlang = GETPOST('lang_id', 'aZ09');
  196. }
  197. //if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
  198. if (!empty($newlang)) {
  199. $outputlangs = new Translate("", $conf);
  200. $outputlangs->setDefaultLang($newlang);
  201. }
  202. $result = $object->generatePdf(GETPOST("model"), $outputlangs);
  203. if ($result <= 0) {
  204. dol_print_error($db, $object->error);
  205. exit;
  206. } else {
  207. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.(empty($conf->global->MAIN_JUMP_TAG) ? '' : '#builddoc'));
  208. exit;
  209. }
  210. } elseif ($action == 'remove_file' && $user->rights->banque->cheque) {
  211. // Remove file in doc form
  212. if ($object->fetch($id) > 0) {
  213. include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  214. $langs->load("other");
  215. $file = $dir.get_exdir($object->ref, 0, 1, 0, $object, 'cheque').GETPOST('file');
  216. $ret = dol_delete_file($file, 0, 0, 0, $object);
  217. if ($ret) {
  218. setEventMessages($langs->trans("FileWasRemoved", GETPOST('file')), null, 'mesgs');
  219. } else {
  220. setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('file')), null, 'errors');
  221. }
  222. }
  223. }
  224. /*
  225. * View
  226. */
  227. if (GETPOST('removefilter')) {
  228. $filterdate = '';
  229. $filteraccountid = 0;
  230. }
  231. $title = $langs->trans("Cheques")." - ".$langs->trans("Card");
  232. $helpurl = "";
  233. llxHeader("", $title, $helpurl);
  234. $form = new Form($db);
  235. $formfile = new FormFile($db);
  236. if ($action == 'new') {
  237. $head = array();
  238. $h = 0;
  239. $head[$h][0] = $_SERVER["PHP_SELF"].'?action=new';
  240. $head[$h][1] = $langs->trans("MenuChequeDeposits");
  241. $hselected = $h;
  242. $h++;
  243. print load_fiche_titre($langs->trans("Cheques"), '', 'bank_account');
  244. } else {
  245. $result = $object->fetch($id, $ref);
  246. if ($result < 0) {
  247. dol_print_error($db, $object->error);
  248. exit;
  249. }
  250. $h = 0;
  251. $head[$h][0] = $_SERVER["PHP_SELF"].'?id='.$object->id;
  252. $head[$h][1] = $langs->trans("CheckReceipt");
  253. $hselected = $h;
  254. $h++;
  255. // $head[$h][0] = DOL_URL_ROOT.'/compta/paiement/cheque/info.php?id='.$object->id;
  256. // $head[$h][1] = $langs->trans("Info");
  257. // $h++;
  258. print dol_get_fiche_head($head, $hselected, $langs->trans("Cheques"), -1, 'payment');
  259. /*
  260. * Confirmation of slip's delete
  261. */
  262. if ($action == 'delete') {
  263. print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans("DeleteCheckReceipt"), $langs->trans("ConfirmDeleteCheckReceipt"), 'confirm_delete', '', '', 1);
  264. }
  265. /*
  266. * Confirmation of slip's validation
  267. */
  268. if ($action == 'valide') {
  269. print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans("ValidateCheckReceipt"), $langs->trans("ConfirmValidateCheckReceipt"), 'confirm_validate', '', '', 1);
  270. }
  271. /*
  272. * Confirm check rejection
  273. */
  274. if ($action == 'reject_check') {
  275. $formquestion = array(
  276. array('type' => 'hidden', 'name' => 'bankid', 'value' => GETPOST('lineid', 'int')),
  277. array('type' => 'date', 'name' => 'rejectdate_', 'label' => $langs->trans("RejectCheckDate"), 'value' => dol_now())
  278. );
  279. print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans("RejectCheck"), $langs->trans("ConfirmRejectCheck"), 'confirm_reject_check', $formquestion, '', 1);
  280. }
  281. }
  282. $accounts = array();
  283. if ($action == 'new') {
  284. $paymentstatic = new Paiement($db);
  285. $accountlinestatic = new AccountLine($db);
  286. $lines = array();
  287. $now = dol_now();
  288. print '<span class="opacitymedium">'.$langs->trans("SelectChequeTransactionAndGenerate").'</span><br><br>'."\n";
  289. print '<form class="nocellnopadd" action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  290. print '<input type="hidden" name="token" value="'.newToken().'">';
  291. print '<input type="hidden" name="action" value="new">';
  292. print dol_get_fiche_head();
  293. print '<table class="border centpercent">';
  294. //print '<tr><td width="30%">'.$langs->trans('Date').'</td><td width="70%">'.dol_print_date($now,'day').'</td></tr>';
  295. // Filter
  296. print '<tr><td class="titlefieldcreate">'.$langs->trans("DateChequeReceived").'</td><td>';
  297. print $form->selectDate($filterdate, 'fd', 0, 0, 1, '', 1, 1);
  298. print '</td></tr>';
  299. print '<tr><td>'.$langs->trans("BankAccount").'</td><td>';
  300. $form->select_comptes($filteraccountid, 'accountid', 0, 'courant <> 2', 1);
  301. print '</td></tr>';
  302. print '</table>';
  303. print dol_get_fiche_end();
  304. print '<div class="center">';
  305. print '<input type="submit" class="button" name="filter" value="'.dol_escape_htmltag($langs->trans("ToFilter")).'">';
  306. if ($filterdate || $filteraccountid > 0) {
  307. print ' &nbsp; ';
  308. print '<input type="submit" class="button" name="removefilter" value="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'">';
  309. }
  310. print '</div>';
  311. print '</form>';
  312. print '<br>';
  313. $sql = "SELECT ba.rowid as bid, ba.label,";
  314. $sql .= " b.rowid as transactionid, b.label as transactionlabel, b.datec as datec, b.dateo as date, ";
  315. $sql .= " b.amount, b.emetteur, b.num_chq, b.banque,";
  316. $sql .= " p.rowid as paymentid, p.ref as paymentref";
  317. $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
  318. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement as p ON p.fk_bank = b.rowid";
  319. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON (b.fk_account = ba.rowid)";
  320. $sql .= " WHERE b.fk_type = 'CHQ'";
  321. $sql .= " AND ba.entity IN (".getEntity('bank_account').")";
  322. $sql .= " AND b.fk_bordereau = 0";
  323. $sql .= " AND b.amount > 0";
  324. if ($filterdate) {
  325. $sql .= " AND b.dateo = '".$db->idate($filterdate)."'";
  326. }
  327. if ($filteraccountid > 0) {
  328. $sql .= " AND ba.rowid = ".((int) $filteraccountid);
  329. }
  330. $sql .= $db->order("b.dateo,b.rowid", "ASC");
  331. $resql = $db->query($sql);
  332. if ($resql) {
  333. $i = 0;
  334. while ($obj = $db->fetch_object($resql)) {
  335. $accounts[$obj->bid] = $obj->label;
  336. $lines[$obj->bid][$i]["date"] = $db->jdate($obj->datec);
  337. $lines[$obj->bid][$i]["amount"] = $obj->amount;
  338. $lines[$obj->bid][$i]["emetteur"] = $obj->emetteur;
  339. $lines[$obj->bid][$i]["numero"] = $obj->num_chq;
  340. $lines[$obj->bid][$i]["banque"] = $obj->banque;
  341. $lines[$obj->bid][$i]["id"] = $obj->transactionid;
  342. $lines[$obj->bid][$i]["ref"] = $obj->transactionid;
  343. $lines[$obj->bid][$i]["label"] = $obj->transactionlabel;
  344. $lines[$obj->bid][$i]["paymentid"] = $obj->paymentid;
  345. $lines[$obj->bid][$i]["paymentref"] = $obj->paymentref;
  346. $lines[$obj->bid][$i]["paymentdate"] = $db->jdate($obj->date);
  347. $i++;
  348. }
  349. if ($i == 0) {
  350. print '<div class="opacitymedium">'.$langs->trans("NoWaitingChecks").'</div><br>';
  351. }
  352. }
  353. foreach ($accounts as $bid => $account_label) {
  354. print '
  355. <script type="text/javascript">
  356. jQuery(document).ready(function()
  357. {
  358. jQuery("#checkall_'.$bid.'").click(function()
  359. {
  360. jQuery(".checkforremise_'.$bid.'").prop(\'checked\', true);
  361. });
  362. jQuery("#checknone_'.$bid.'").click(function()
  363. {
  364. jQuery(".checkforremise_'.$bid.'").prop(\'checked\', false);
  365. });
  366. });
  367. </script>
  368. ';
  369. $num = $db->num_rows($resql);
  370. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  371. print '<input type="hidden" name="token" value="'.newToken().'">';
  372. print '<input type="hidden" name="action" value="create">';
  373. print '<input type="hidden" name="accountid" value="'.$bid.'">';
  374. $moreforfilter = '';
  375. print '<div class="div-table-responsive-no-min">';
  376. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  377. print '<tr class="liste_titre">';
  378. print '<td>'.$langs->trans("DateChequeReceived").'</td>'."\n";
  379. print '<td>'.$langs->trans("ChequeNumber")."</td>\n";
  380. print '<td>'.$langs->trans("CheckTransmitter")."</td>\n";
  381. print '<td>'.$langs->trans("Bank")."</td>\n";
  382. print '<td>'.$langs->trans("Amount")."</td>\n";
  383. print '<td class="center">'.$langs->trans("Payment")."</td>\n";
  384. print '<td class="center">'.$langs->trans("LineRecord")."</td>\n";
  385. print '<td class="center">'.$langs->trans("Select")."<br>";
  386. if ($conf->use_javascript_ajax) {
  387. print '<a href="#" id="checkall_'.$bid.'">'.$langs->trans("All").'</a> / <a href="#" id="checknone_'.$bid.'">'.$langs->trans("None").'</a>';
  388. }
  389. print '</td>';
  390. print "</tr>\n";
  391. if (count($lines[$bid])) {
  392. foreach ($lines[$bid] as $lid => $value) {
  393. //$account_id = $bid; FIXME not used
  394. // FIXME $accounts[$bid] is a label !
  395. /*if (! isset($accounts[$bid]))
  396. $accounts[$bid]=0;
  397. $accounts[$bid] += 1;*/
  398. print '<tr class="oddeven">';
  399. print '<td>'.dol_print_date($value["date"], 'day').'</td>';
  400. print '<td>'.$value["numero"]."</td>\n";
  401. print '<td>'.$value["emetteur"]."</td>\n";
  402. print '<td>'.$value["banque"]."</td>\n";
  403. print '<td class="right"><span class="amount">'.price($value["amount"], 0, $langs, 1, -1, -1, $conf->currency).'</span></td>';
  404. // Link to payment
  405. print '<td class="center">';
  406. $paymentstatic->id = $value["paymentid"];
  407. $paymentstatic->ref = $value["paymentref"];
  408. $paymentstatic->date = $value["paymentdate"];
  409. if ($paymentstatic->id) {
  410. print $paymentstatic->getNomUrl(1);
  411. } else {
  412. print '&nbsp;';
  413. }
  414. print '</td>';
  415. // Link to bank transaction
  416. print '<td class="center">';
  417. $accountlinestatic->id = $value["id"];
  418. $accountlinestatic->ref = $value["ref"];
  419. if ($accountlinestatic->id > 0) {
  420. print $accountlinestatic->getNomUrl(1);
  421. } else {
  422. print '&nbsp;';
  423. }
  424. print '</td>';
  425. print '<td class="center">';
  426. print '<input id="'.$value["id"].'" class="flat checkforremise_'.$bid.'" checked type="checkbox" name="toRemise[]" value="'.$value["id"].'">';
  427. print '</td>';
  428. print '</tr>';
  429. $i++;
  430. }
  431. }
  432. print "</table>";
  433. print '</div>';
  434. print '<div class="tabsAction">';
  435. if ($user->rights->banque->cheque) {
  436. print '<input type="submit" class="button" value="'.$langs->trans('NewCheckDepositOn', $account_label).'">';
  437. } else {
  438. print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans('NewCheckDepositOn', $account_label).'</a>';
  439. }
  440. print '</div><br>';
  441. print '</form>';
  442. }
  443. } else {
  444. $paymentstatic = new Paiement($db);
  445. $accountlinestatic = new AccountLine($db);
  446. $accountstatic = new Account($db);
  447. $accountstatic->fetch($object->account_id);
  448. $linkback = '<a href="'.DOL_URL_ROOT.'/compta/paiement/cheque/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  449. $morehtmlref = '';
  450. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  451. print '<div class="fichecenter">';
  452. print '<div class="underbanner clearboth"></div>';
  453. print '<table class="border centpercent">';
  454. print '<tr><td class="titlefield">';
  455. print '<table class="nobordernopadding" width="100%"><tr><td>';
  456. print $langs->trans('Date');
  457. print '</td>';
  458. if ($action != 'editdate') {
  459. 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>';
  460. }
  461. print '</tr></table>';
  462. print '</td><td colspan="2">';
  463. if ($action == 'editdate') {
  464. print '<form name="setdate" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
  465. print '<input type="hidden" name="token" value="'.newToken().'">';
  466. print '<input type="hidden" name="action" value="setdate">';
  467. print $form->selectDate($object->date_bordereau, 'datecreate_', '', '', '', "setdate");
  468. print '<input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
  469. print '</form>';
  470. } else {
  471. print $object->date_bordereau ? dol_print_date($object->date_bordereau, 'day') : '&nbsp;';
  472. }
  473. print '</td>';
  474. print '</tr>';
  475. // External ref
  476. /* Ext ref are not visible field on standard usage
  477. print '<tr><td>';
  478. print '<table class="nobordernopadding" width="100%"><tr><td>';
  479. print $langs->trans('RefExt');
  480. print '</td>';
  481. if ($action != 'editrefext') print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editrefext&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->trans('SetRefExt'),1).'</a></td>';
  482. print '</tr></table>';
  483. print '</td><td colspan="2">';
  484. if ($action == 'editrefext')
  485. {
  486. print '<form name="setrefext" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
  487. print '<input type="hidden" name="token" value="'.newToken().'">';
  488. print '<input type="hidden" name="action" value="setrefext">';
  489. print '<input type="text" name="ref_ext" value="'.$object->ref_ext.'">';
  490. print '<input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
  491. print '</form>';
  492. }
  493. else
  494. {
  495. print $object->ref_ext;
  496. }
  497. print '</td>';
  498. print '</tr>';
  499. */
  500. print '<tr><td>'.$langs->trans('Account').'</td><td colspan="2">';
  501. print $accountstatic->getNomUrl(1);
  502. print '</td></tr>';
  503. // Number of bank checks
  504. print '<tr><td>'.$langs->trans('NbOfCheques').'</td><td colspan="2">';
  505. print $object->nbcheque;
  506. print '</td></tr>';
  507. print '<tr><td>'.$langs->trans('Total').'</td><td colspan="2">';
  508. print price($object->amount);
  509. print '</td></tr>';
  510. /*print '<tr><td>'.$langs->trans('Status').'</td><td colspan="2">';
  511. print $object->getLibStatut(4);
  512. print '</td></tr>';*/
  513. print '</table><br>';
  514. print '</div>';
  515. // List of bank checks
  516. $sql = "SELECT b.rowid, b.rowid as ref, b.label, b.amount, b.num_chq, b.emetteur,";
  517. $sql .= " b.dateo as date, b.datec as datec, b.banque,";
  518. $sql .= " p.rowid as pid, p.ref as pref, ba.rowid as bid, p.statut";
  519. $sql .= " FROM ".MAIN_DB_PREFIX."bank_account as ba";
  520. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON (b.fk_account = ba.rowid)";
  521. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement as p ON p.fk_bank = b.rowid";
  522. $sql .= " WHERE ba.entity IN (".getEntity('bank_account').")";
  523. $sql .= " AND b.fk_type= 'CHQ'";
  524. $sql .= " AND b.fk_bordereau = ".((int) $object->id);
  525. $sql .= $db->order($sortfield, $sortorder);
  526. $resql = $db->query($sql);
  527. if ($resql) {
  528. $num = $db->num_rows($resql);
  529. print '<div class="div-table-responsive">';
  530. print '<table class="noborder centpercent">';
  531. $param = "&amp;id=".$object->id;
  532. print '<tr class="liste_titre">';
  533. print_liste_field_titre("Cheques", '', '', '', '', 'width="30"');
  534. print_liste_field_titre("DateChequeReceived", $_SERVER["PHP_SELF"], "b.dateo,b.rowid", "", $param, 'align="center"', $sortfield, $sortorder);
  535. print_liste_field_titre("Numero", $_SERVER["PHP_SELF"], "b.num_chq", "", $param, 'align="center"', $sortfield, $sortorder);
  536. print_liste_field_titre("CheckTransmitter", $_SERVER["PHP_SELF"], "b.emetteur", "", $param, "", $sortfield, $sortorder);
  537. print_liste_field_titre("Bank", $_SERVER["PHP_SELF"], "b.banque", "", $param, "", $sortfield, $sortorder);
  538. print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "b.amount", "", $param, 'class="right"', $sortfield, $sortorder);
  539. print_liste_field_titre("Payment", $_SERVER["PHP_SELF"], "p.rowid", "", $param, 'align="center"', $sortfield, $sortorder);
  540. print_liste_field_titre("LineRecord", $_SERVER["PHP_SELF"], "b.rowid", "", $param, 'align="center"', $sortfield, $sortorder);
  541. print_liste_field_titre('');
  542. print "</tr>\n";
  543. $i = 1;
  544. if ($num > 0) {
  545. while ($objp = $db->fetch_object($resql)) {
  546. print '<tr class="oddeven">';
  547. print '<td class="center">'.$i.'</td>';
  548. print '<td class="center">'.dol_print_date($db->jdate($objp->date), 'day').'</td>'; // Operation date
  549. print '<td class="center">'.($objp->num_chq ? $objp->num_chq : '&nbsp;').'</td>';
  550. print '<td>'.dol_trunc($objp->emetteur, 24).'</td>';
  551. print '<td>'.dol_trunc($objp->banque, 24).'</td>';
  552. print '<td class="right"><span class="amount">'.price($objp->amount).'</span></td>';
  553. // Link to payment
  554. print '<td class="center">';
  555. $paymentstatic->id = $objp->pid;
  556. $paymentstatic->ref = $objp->pref;
  557. if ($paymentstatic->id) {
  558. print $paymentstatic->getNomUrl(1);
  559. } else {
  560. print '&nbsp;';
  561. }
  562. print '</td>';
  563. // Link to bank transaction
  564. print '<td class="center">';
  565. $accountlinestatic->id = $objp->rowid;
  566. $accountlinestatic->ref = $objp->ref;
  567. if ($accountlinestatic->id > 0) {
  568. print $accountlinestatic->getNomUrl(1);
  569. } else {
  570. print '&nbsp;';
  571. }
  572. print '</td>';
  573. // Action button
  574. print '<td class="right">';
  575. if ($object->statut == 0) {
  576. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=remove&amp;lineid='.$objp->rowid.'">'.img_delete().'</a>';
  577. }
  578. if ($object->statut == 1 && $objp->statut != 2) {
  579. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=reject_check&amp;lineid='.$objp->rowid.'">'.img_picto($langs->trans("RejectCheck"), 'disable').'</a>';
  580. }
  581. if ($objp->statut == 2) {
  582. print ' &nbsp; '.img_picto($langs->trans('CheckRejected'), 'statut8').'</a>';
  583. }
  584. print '</td>';
  585. print '</tr>';
  586. $i++;
  587. }
  588. } else {
  589. print '<td colspan="8" class="opacitymedium">';
  590. print $langs->trans("None");
  591. print '</td>';
  592. }
  593. print "</table>";
  594. // Cheque denormalized data nbcheque is similar to real number of bank check
  595. if ($num > 0 && $i < ($object->nbcheque + 1)) {
  596. // Show warning that some records were removed.
  597. $langs->load("errors");
  598. print info_admin($langs->trans("WarningSomeBankTransactionByChequeWereRemovedAfter"), 0, 0, 'warning');
  599. // TODO Fix data ->nbcheque and ->amount
  600. }
  601. print "</div>";
  602. } else {
  603. dol_print_error($db);
  604. }
  605. print dol_get_fiche_end();
  606. }
  607. /*
  608. * Actions Buttons
  609. */
  610. print '<div class="tabsAction">';
  611. if ($user->socid == 0 && !empty($object->id) && $object->statut == 0 && $user->rights->banque->cheque) {
  612. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=valide&token='.newToken().'&sortfield='.$sortfield.'&sortorder='.$sortorder.'">'.$langs->trans('Validate').'</a>';
  613. }
  614. if ($user->socid == 0 && !empty($object->id) && $user->rights->banque->cheque) {
  615. print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken().'&sortfield='.$sortfield.'&sortorder='.$sortorder.'">'.$langs->trans('Delete').'</a>';
  616. }
  617. print '</div>';
  618. if ($action != 'new') {
  619. if ($object->statut == 1) {
  620. $filename = dol_sanitizeFileName($object->ref);
  621. $filedir = $dir.get_exdir($object->ref, 0, 1, 0, $object, 'checkdeposits');
  622. $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
  623. print $formfile->showdocuments('remisecheque', $filename, $filedir, $urlsource, 1, 1);
  624. print '<br>';
  625. }
  626. }
  627. // End of page
  628. llxFooter();
  629. $db->close();