card.php 29 KB

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