card.php 27 KB

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