line.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  1. <?php
  2. /* Copyright (C) 2001-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2003 Xavier DUTOIT <doli@sydesy.com>
  4. * Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2004 Christophe Combelles <ccomb@free.fr>
  6. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  7. * Copyright (C) 2015-2017 Alexandre Spangaro <aspangaro@open-dsi.fr>
  8. * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
  9. * Copyright (C) 2016 Marcos García <marcosgdf@gmail.com>
  10. * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
  11. * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation; either version 3 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  25. */
  26. /**
  27. * \file htdocs/compta/bank/line.php
  28. * \ingroup bank
  29. * \brief Page to edit a bank transaction record
  30. */
  31. // Load Dolibarr environment
  32. require '../../main.inc.php';
  33. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  37. // Load translation files required by the page
  38. $langs->loadLangs(array('banks', 'categories', 'compta', 'bills', 'other'));
  39. if (isModEnabled('adherent')) {
  40. $langs->load("members");
  41. }
  42. if (isModEnabled('don')) {
  43. $langs->load("donations");
  44. }
  45. if (isModEnabled('loan')) {
  46. $langs->load("loan");
  47. }
  48. if (isModEnabled('salaries')) {
  49. $langs->load("salaries");
  50. }
  51. $id = GETPOST('rowid', 'int');
  52. $rowid = GETPOST("rowid", 'int');
  53. $accountoldid = GETPOST('account', 'int'); // GETPOST('account') is old account id
  54. $accountid = GETPOST('accountid', 'int'); // GETPOST('accountid') is new account id
  55. $ref = GETPOST('ref', 'alpha');
  56. $action = GETPOST('action', 'aZ09');
  57. $confirm = GETPOST('confirm', 'alpha');
  58. $orig_account = GETPOST("orig_account");
  59. $backtopage = GETPOST('backtopage', 'alpha');
  60. $cancel = GETPOST('cancel', 'alpha');
  61. // Security check
  62. $fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : ''));
  63. $fieldtype = (!empty($ref) ? 'ref' : 'rowid');
  64. $socid = 0;
  65. if ($user->socid) {
  66. $socid = $user->socid;
  67. }
  68. $result = restrictedArea($user, 'banque', $accountoldid, 'bank_account');
  69. if (empty($user->rights->banque->lire) && empty($user->rights->banque->consolidate)) {
  70. accessforbidden();
  71. }
  72. $hookmanager->initHooks(array('bankline'));
  73. $object = new AccountLine($db);
  74. $extrafields = new ExtraFields($db);
  75. $extrafields->fetch_name_optionals_label($object->element);
  76. /*
  77. * Actions
  78. */
  79. $parameters = array('socid' => $socid);
  80. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  81. if ($reshook < 0) {
  82. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  83. }
  84. if ($cancel) {
  85. if ($backtopage) {
  86. header("Location: ".$backtopage);
  87. exit;
  88. }
  89. }
  90. if ($user->rights->banque->consolidate && $action == 'donext') {
  91. $al = new AccountLine($db);
  92. $al->dateo_next(GETPOST("rowid", 'int'));
  93. } elseif ($user->rights->banque->consolidate && $action == 'doprev') {
  94. $al = new AccountLine($db);
  95. $al->dateo_previous(GETPOST("rowid", 'int'));
  96. } elseif ($user->rights->banque->consolidate && $action == 'dvnext') {
  97. $al = new AccountLine($db);
  98. $al->datev_next(GETPOST("rowid", 'int'));
  99. } elseif ($user->rights->banque->consolidate && $action == 'dvprev') {
  100. $al = new AccountLine($db);
  101. $al->datev_previous(GETPOST("rowid", 'int'));
  102. }
  103. if ($action == 'confirm_delete_categ' && $confirm == "yes" && $user->rights->banque->modifier) {
  104. $cat1 = GETPOST("cat1", 'int');
  105. if (!empty($rowid) && !empty($cat1)) {
  106. $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_class WHERE lineid = ".((int) $rowid)." AND fk_categ = ".((int) $cat1);
  107. if (!$db->query($sql)) {
  108. dol_print_error($db);
  109. }
  110. } else {
  111. setEventMessages($langs->trans("MissingIds"), null, 'errors');
  112. }
  113. }
  114. if ($user->rights->banque->modifier && $action == "update") {
  115. $error = 0;
  116. $result = $object->fetch($rowid);
  117. if ($result <= 0) {
  118. dol_syslog('Failed to read bank line with id '.$rowid, LOG_WARNING); // This happens due to old bug that has set fk_account to null.
  119. $object->id = $rowid;
  120. }
  121. $acsource = new Account($db);
  122. $acsource->fetch($accountoldid);
  123. $actarget = new Account($db);
  124. if (GETPOST('accountid', 'int') > 0 && !$object->rappro && !$object->getVentilExportCompta()) { // We ask to change bank account
  125. $actarget->fetch(GETPOST('accountid', 'int'));
  126. } else {
  127. $actarget->fetch($accountoldid);
  128. }
  129. if (!($actarget->id > 0)) {
  130. setEventMessages($langs->trans("ErrorFailedToLoadBankAccount"), null, 'errors');
  131. $error++;
  132. }
  133. if ($actarget->courant == Account::TYPE_CASH && GETPOST('value', 'alpha') != 'LIQ') {
  134. setEventMessages($langs->trans("ErrorCashAccountAcceptsOnlyCashMoney"), null, 'errors');
  135. $error++;
  136. }
  137. if (!$error) {
  138. $db->begin();
  139. $amount = price2num(GETPOST('amount'));
  140. $dateop = dol_mktime(12, 0, 0, GETPOST("dateomonth"), GETPOST("dateoday"), GETPOST("dateoyear"));
  141. $dateval = dol_mktime(12, 0, 0, GETPOST("datevmonth"), GETPOST("datevday"), GETPOST("datevyear"));
  142. $sql = "UPDATE ".MAIN_DB_PREFIX."bank";
  143. $sql .= " SET ";
  144. // Always opened
  145. if (GETPOSTISSET('value')) {
  146. $sql .= " fk_type='".$db->escape(GETPOST('value'))."',";
  147. }
  148. if (GETPOSTISSET('num_chq')) {
  149. $sql .= " num_chq='".$db->escape(GETPOST("num_chq"))."',";
  150. }
  151. if (GETPOSTISSET('banque')) {
  152. $sql .= " banque='".$db->escape(GETPOST("banque"))."',";
  153. }
  154. if (GETPOSTISSET('emetteur')) {
  155. $sql .= " emetteur='".$db->escape(GETPOST("emetteur"))."',";
  156. }
  157. // Blocked when conciliated
  158. if (!$object->rappro) {
  159. if (GETPOSTISSET('label')) {
  160. $sql .= " label = '".$db->escape(GETPOST("label"))."',";
  161. }
  162. if (GETPOSTISSET('amount')) {
  163. $sql .= " amount= '".$db->escape($amount)."',";
  164. }
  165. if (GETPOSTISSET('dateomonth')) {
  166. $sql .= " dateo = '".$db->idate($dateop)."',";
  167. }
  168. if (GETPOSTISSET('datevmonth')) {
  169. $sql .= " datev = '".$db->idate($dateval)."',";
  170. }
  171. }
  172. $sql .= " fk_account = ".((int) $actarget->id);
  173. $sql .= " WHERE rowid = ".((int) $object->id);
  174. $result = $db->query($sql);
  175. if (!$result) {
  176. $error++;
  177. }
  178. if (!$error) {
  179. $arrayofcategs = GETPOST('custcats', 'array');
  180. $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_class WHERE lineid = ".((int) $rowid);
  181. if (!$db->query($sql)) {
  182. $error++;
  183. dol_print_error($db);
  184. }
  185. if (count($arrayofcategs)) {
  186. foreach ($arrayofcategs as $val) {
  187. $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_class (lineid, fk_categ) VALUES (".((int) $rowid).", ".((int) $val).")";
  188. if (!$db->query($sql)) {
  189. $error++;
  190. dol_print_error($db);
  191. }
  192. }
  193. // $arrayselected will be loaded after in page output
  194. }
  195. }
  196. if (!$error) {
  197. $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET');
  198. $object->insertExtraFields();
  199. }
  200. if (!$error) {
  201. setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
  202. $db->commit();
  203. } else {
  204. $db->rollback();
  205. dol_print_error($db);
  206. }
  207. }
  208. }
  209. // Reconcile
  210. if ($user->rights->banque->consolidate && ($action == 'num_releve' || $action == 'setreconcile')) {
  211. $num_rel = trim(GETPOST("num_rel"));
  212. $rappro = GETPOST('reconciled') ? 1 : 0;
  213. // Check parameters
  214. if ($rappro && empty($num_rel)) {
  215. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("AccountStatement")), null, 'errors');
  216. $error++;
  217. }
  218. if (!$error) {
  219. $db->begin();
  220. $sql = "UPDATE ".MAIN_DB_PREFIX."bank";
  221. $sql .= " SET num_releve = ".($num_rel ? "'".$db->escape($num_rel)."'" : "null");
  222. if (empty($num_rel)) {
  223. $sql .= ", rappro = 0";
  224. } else {
  225. $sql .= ", rappro = ".((int) $rappro);
  226. }
  227. $sql .= " WHERE rowid = ".((int) $rowid);
  228. dol_syslog("line.php", LOG_DEBUG);
  229. $result = $db->query($sql);
  230. if ($result) {
  231. setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
  232. $db->commit();
  233. } else {
  234. $db->rollback();
  235. dol_print_error($db);
  236. }
  237. }
  238. }
  239. /*
  240. * View
  241. */
  242. $form = new Form($db);
  243. llxHeader('', $langs->trans("BankTransaction"));
  244. $arrayselected = array();
  245. $c = new Categorie($db);
  246. $cats = $c->containing($rowid, Categorie::TYPE_BANK_LINE);
  247. if (is_array($cats)) {
  248. foreach ($cats as $cat) {
  249. $arrayselected[] = $cat->id;
  250. }
  251. }
  252. $head = bankline_prepare_head($rowid);
  253. $sql = "SELECT b.rowid, b.dateo as do, b.datev as dv, b.amount, b.label, b.rappro,";
  254. $sql .= " b.num_releve, b.fk_user_author, b.num_chq, b.fk_type, b.fk_account, b.fk_bordereau as receiptid,";
  255. $sql .= " b.emetteur,b.banque";
  256. $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
  257. $sql .= " WHERE rowid=".((int) $rowid);
  258. $sql .= " ORDER BY dateo ASC";
  259. $result = $db->query($sql);
  260. if ($result) {
  261. $i = 0;
  262. $total = 0;
  263. if ($db->num_rows($result)) {
  264. $objp = $db->fetch_object($result);
  265. $total = $total + $objp->amount;
  266. $acct = new Account($db);
  267. $acct->fetch($objp->fk_account);
  268. $account = $acct->id;
  269. $bankline = new AccountLine($db);
  270. $bankline->fetch($rowid, $ref);
  271. $links = $acct->get_url($rowid);
  272. $bankline->load_previous_next_ref('', 'rowid');
  273. // Confirmations
  274. if ($action == 'delete_categ') {
  275. print $form->formconfirm($_SERVER['PHP_SELF']."?rowid=".urlencode($rowid)."&cat1=".urlencode(GETPOST("fk_categ", 'int'))."&orig_account=".urlencode($orig_account), $langs->trans("RemoveFromRubrique"), $langs->trans("RemoveFromRubriqueConfirm"), "confirm_delete_categ", '', 'yes', 1);
  276. }
  277. print '<form name="update" method="POST" action="'.$_SERVER['PHP_SELF'].'?rowid='.$rowid.'">';
  278. print '<input type="hidden" name="token" value="'.newToken().'">';
  279. print '<input type="hidden" name="action" value="update">';
  280. print '<input type="hidden" name="orig_account" value="'.$orig_account.'">';
  281. print '<input type="hidden" name="account" value="'.$acct->id.'">';
  282. print dol_get_fiche_head($head, 'bankline', $langs->trans('LineRecord'), 0, 'accountline', 0);
  283. $linkback = '<a href="'.DOL_URL_ROOT.'/compta/bank/bankentries_list.php?restore_lastsearch_values=1'.(GETPOST('account', 'int', 1) ? '&id='.GETPOST('account', 'int', 1) : '').'">'.$langs->trans("BackToList").'</a>';
  284. dol_banner_tab($bankline, 'rowid', $linkback);
  285. print '<div class="fichecenter2">';
  286. print '<div class="underbanner clearboth"></div>';
  287. print '<table class="border centpercent tableforfield">';
  288. $i++;
  289. // Bank account
  290. print '<tr><td class="titlefieldcreate">'.$langs->trans("Account").'</td>';
  291. print '<td>';
  292. // $objp->fk_account may be not > 0 if data was lost by an old bug. In such a case, we let a chance to user to fix it.
  293. if (($objp->rappro || $bankline->getVentilExportCompta()) && $objp->fk_account > 0) {
  294. print $acct->getNomUrl(1, 'transactions', 'reflabel');
  295. } else {
  296. print img_picto('', 'bank_account', 'class="paddingright"');
  297. print $form->select_comptes($acct->id, 'accountid', 0, '', ($acct->id > 0 ? $acct->id : 1), '', 0, '', 1);
  298. }
  299. print '</td>';
  300. print '</tr>';
  301. // Show links of bank transactions
  302. if (count($links)) {
  303. print '<tr><td class="tdtop">'.$langs->trans("Links").'</td>';
  304. print '<td>';
  305. foreach ($links as $key => $val) {
  306. if ($key) {
  307. print '<br>';
  308. }
  309. if ($links[$key]['type'] == 'payment') {
  310. require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
  311. $paymenttmp = new Paiement($db);
  312. $paymenttmp->fetch($links[$key]['url_id']);
  313. $paymenttmp->ref = $langs->trans("Payment").' '.$paymenttmp->ref;
  314. /*print '<a href="'.DOL_URL_ROOT.'/compta/paiement/card.php?id='.$links[$key]['url_id'].'">';
  315. print img_object($langs->trans('Payment'),'payment').' ';
  316. print $langs->trans("Payment");
  317. print '</a>';*/
  318. print $paymenttmp->getNomUrl(1);
  319. } elseif ($links[$key]['type'] == 'payment_supplier') {
  320. require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php';
  321. $paymenttmp = new PaiementFourn($db);
  322. $paymenttmp->fetch($links[$key]['url_id']);
  323. $paymenttmp->ref = $langs->trans("Payment").' '.$paymenttmp->ref;
  324. /*print '<a href="'.DOL_URL_ROOT.'/fourn/paiement/card.php?id='.$links[$key]['url_id'].'">';
  325. print img_object($langs->trans('Payment'),'payment').' ';
  326. print $langs->trans("Payment");
  327. print '</a>';*/
  328. print $paymenttmp->getNomUrl(1);
  329. } elseif ($links[$key]['type'] == 'company') {
  330. $societe = new Societe($db);
  331. $societe->fetch($links[$key]['url_id']);
  332. print $societe->getNomUrl(1);
  333. } elseif ($links[$key]['type'] == 'sc') {
  334. print '<a href="'.DOL_URL_ROOT.'/compta/sociales/card.php?id='.$links[$key]['url_id'].'">';
  335. print img_object($langs->trans('SocialContribution'), 'bill').' ';
  336. print $langs->trans("SocialContribution").($links[$key]['label'] ? ' - '.$links[$key]['label'] : '');
  337. print '</a>';
  338. } elseif ($links[$key]['type'] == 'vat') {
  339. print '<a href="'.DOL_URL_ROOT.'/compta/tva/card.php?id='.$links[$key]['url_id'].'">';
  340. print img_object($langs->trans('VATDeclaration'), 'bill').' ';
  341. print $langs->trans("VATDeclaration").($links[$key]['label'] ? '&nbsp;'.$links[$key]['label'] : '');
  342. print '</a>';
  343. } elseif ($links[$key]['type'] == 'salary') {
  344. print '<a href="'.DOL_URL_ROOT.'/salaries/card.php?id='.$links[$key]['url_id'].'">';
  345. print img_object($langs->trans('Salary'), 'bill').' ';
  346. print $langs->trans("Salary").($links[$key]['label'] ? ' - '.$links[$key]['label'] : '');
  347. print '</a>';
  348. } elseif ($links[$key]['type'] == 'payment_sc') {
  349. print '<a href="'.DOL_URL_ROOT.'/compta/payment_sc/card.php?id='.$links[$key]['url_id'].'">';
  350. print img_object($langs->trans('Payment'), 'payment').' ';
  351. print $langs->trans("SocialContributionPayment");
  352. print '</a>';
  353. } elseif ($links[$key]['type'] == 'payment_vat') {
  354. print '<a href="'.DOL_URL_ROOT.'/compta/payment_vat/card.php?id='.$links[$key]['url_id'].'">';
  355. print img_object($langs->trans('VATPayment'), 'payment').' ';
  356. print $langs->trans("VATPayment");
  357. print '</a>';
  358. } elseif ($links[$key]['type'] == 'payment_salary') {
  359. print '<a href="'.DOL_URL_ROOT.'/salaries/payment_salary/card.php?id='.$links[$key]['url_id'].'">';
  360. print img_object($langs->trans('PaymentSalary'), 'payment').' ';
  361. print $langs->trans("SalaryPayment");
  362. print '</a>';
  363. } elseif ($links[$key]['type'] == 'payment_loan') {
  364. print '<a href="'.DOL_URL_ROOT.'/loan/payment/card.php?id='.$links[$key]['url_id'].'">';
  365. print img_object($langs->trans('LoanPayment'), 'payment').' ';
  366. print $langs->trans("PaymentLoan");
  367. print '</a>';
  368. } elseif ($links[$key]['type'] == 'loan') {
  369. print '<a href="'.DOL_URL_ROOT.'/loan/card.php?id='.$links[$key]['url_id'].'">';
  370. print img_object($langs->trans('Loan'), 'bill').' ';
  371. print $langs->trans("Loan");
  372. print '</a>';
  373. } elseif ($links[$key]['type'] == 'member') {
  374. print '<a href="'.DOL_URL_ROOT.'/adherents/card.php?rowid='.$links[$key]['url_id'].'">';
  375. print img_object($langs->trans('Member'), 'user').' ';
  376. print $links[$key]['label'];
  377. print '</a>';
  378. } elseif ($links[$key]['type'] == 'payment_donation') {
  379. print '<a href="'.DOL_URL_ROOT.'/don/payment/card.php?id='.$links[$key]['url_id'].'">';
  380. print img_object($langs->trans('Donation'), 'payment').' ';
  381. print $langs->trans("DonationPayment");
  382. print '</a>';
  383. } elseif ($links[$key]['type'] == 'banktransfert') {
  384. print '<a href="'.DOL_URL_ROOT.'/compta/bank/line.php?rowid='.$links[$key]['url_id'].'">';
  385. print img_object($langs->trans('Transaction'), 'payment').' ';
  386. print $langs->trans("TransactionOnTheOtherAccount");
  387. print '</a>';
  388. } elseif ($links[$key]['type'] == 'user') {
  389. print '<a href="'.DOL_URL_ROOT.'/user/card.php?id='.$links[$key]['url_id'].'">';
  390. print img_object($langs->trans('User'), 'user').' ';
  391. print $langs->trans("User");
  392. print '</a>';
  393. } elseif ($links[$key]['type'] == 'payment_various') {
  394. print '<a href="'.DOL_URL_ROOT.'/compta/bank/various_payment/card.php?id='.$links[$key]['url_id'].'">';
  395. print img_object($langs->trans('VariousPayment'), 'payment').' ';
  396. print $langs->trans("VariousPayment");
  397. print '</a>';
  398. } else {
  399. print '<a href="'.$links[$key]['url'].$links[$key]['url_id'].'">';
  400. print img_object('', 'generic').' ';
  401. print $links[$key]['label'];
  402. print '</a>';
  403. }
  404. }
  405. print '</td></tr>';
  406. }
  407. //$user->rights->banque->modifier=false;
  408. //$user->rights->banque->consolidate=true;
  409. // Type of payment / Number
  410. print "<tr><td>".$langs->trans("Type")." / ".$langs->trans("Numero");
  411. print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
  412. print "</td>";
  413. if ($user->rights->banque->modifier || $user->rights->banque->consolidate) {
  414. print '<td>';
  415. $form->select_types_paiements($objp->fk_type, "value", '', 2);
  416. print '<input type="text" class="flat" name="num_chq" value="'.(empty($objp->num_chq) ? '' : $objp->num_chq).'">';
  417. if ($objp->receiptid) {
  418. include_once DOL_DOCUMENT_ROOT.'/compta/paiement/cheque/class/remisecheque.class.php';
  419. $receipt = new RemiseCheque($db);
  420. $receipt->fetch($objp->receiptid);
  421. print ' &nbsp; &nbsp; '.$langs->trans("CheckReceipt").': '.$receipt->getNomUrl(2);
  422. }
  423. print '</td>';
  424. } else {
  425. print '<td>'.$objp->fk_type.' '.dol_escape_htmltag($objp->num_chq).'</td>';
  426. }
  427. print "</tr>";
  428. // Transmitter
  429. print "<tr><td>".$langs->trans("CheckTransmitter");
  430. print ' <em>('.$langs->trans("ChequeMaker").')</em>';
  431. print "</td>";
  432. if ($user->rights->banque->modifier || $user->rights->banque->consolidate) {
  433. print '<td>';
  434. print '<input type="text" class="flat minwidth200" name="emetteur" value="'.(empty($objp->emetteur) ? '' : dol_escape_htmltag($objp->emetteur)).'">';
  435. print '</td>';
  436. } else {
  437. print '<td>'.$objp->emetteur.'</td>';
  438. }
  439. print "</tr>";
  440. // Bank of cheque
  441. print "<tr><td>".$langs->trans("Bank");
  442. print ' <em>('.$langs->trans("ChequeBank").')</em>';
  443. print "</td>";
  444. if ($user->rights->banque->modifier || $user->rights->banque->consolidate) {
  445. print '<td>';
  446. print '<input type="text" class="flat minwidth200" name="banque" value="'.(empty($objp->banque) ? '' : dol_escape_htmltag($objp->banque)).'">';
  447. print '</td>';
  448. } else {
  449. print '<td>'.dol_escape_htmltag($objp->banque).'</td>';
  450. }
  451. print "</tr>";
  452. // Date ope
  453. print '<tr><td>'.$langs->trans("DateOperation").'</td>';
  454. if ($user->rights->banque->modifier || $user->rights->banque->consolidate) {
  455. print '<td>';
  456. print $form->selectDate($db->jdate($objp->do), 'dateo', '', '', '', 'update', 1, 0, $objp->rappro);
  457. if (!$objp->rappro) {
  458. print ' &nbsp; ';
  459. print '<a class="ajaxforbankoperationchange" href="'.$_SERVER['PHP_SELF'].'?action=doprev&id='.$objp->fk_account.'&rowid='.$objp->rowid.'&token='.newToken().'">';
  460. print img_edit_remove()."</a> ";
  461. print '<a class="ajaxforbankoperationchange" href="'.$_SERVER['PHP_SELF'].'?action=donext&id='.$objp->fk_account.'&rowid='.$objp->rowid.'&token='.newToken().'">';
  462. print img_edit_add()."</a>";
  463. }
  464. print '</td>';
  465. } else {
  466. print '<td>';
  467. print dol_print_date($db->jdate($objp->do), "day");
  468. print '</td>';
  469. }
  470. print '</tr>';
  471. // Value date
  472. print "<tr><td>".$langs->trans("DateValue")."</td>";
  473. if ($user->rights->banque->modifier || $user->rights->banque->consolidate) {
  474. print '<td>';
  475. print $form->selectDate($db->jdate($objp->dv), 'datev', '', '', '', 'update', 1, 0, $objp->rappro);
  476. if (!$objp->rappro) {
  477. print ' &nbsp; ';
  478. print '<a class="ajaxforbankoperationchange" href="'.$_SERVER['PHP_SELF'].'?action=dvprev&id='.$objp->fk_account.'&rowid='.$objp->rowid.'&token='.newToken().'">';
  479. print img_edit_remove()."</a> ";
  480. print '<a class="ajaxforbankoperationchange" href="'.$_SERVER['PHP_SELF'].'?action=dvnext&id='.$objp->fk_account.'&rowid='.$objp->rowid.'&token='.newToken().'">';
  481. print img_edit_add()."</a>";
  482. }
  483. print '</td>';
  484. } else {
  485. print '<td>';
  486. print dol_print_date($db->jdate($objp->dv), "day");
  487. print '</td>';
  488. }
  489. print "</tr>";
  490. // Description
  491. $reg = array();
  492. print "<tr><td>".$langs->trans("Label")."</td>";
  493. if ($user->rights->banque->modifier || $user->rights->banque->consolidate) {
  494. print '<td>';
  495. print '<input name="label" class="flat minwidth300" '.($objp->rappro ? ' disabled' : '').' value="';
  496. if (preg_match('/^\((.*)\)$/i', $objp->label, $reg)) {
  497. // Label generique car entre parentheses. On l'affiche en le traduisant
  498. print $langs->trans($reg[1]);
  499. } else {
  500. print dol_escape_htmltag($objp->label);
  501. }
  502. print '">';
  503. print '</td>';
  504. } else {
  505. print '<td>';
  506. if (preg_match('/^\((.*)\)$/i', $objp->label, $reg)) {
  507. // Label generique car entre parentheses. On l'affiche en le traduisant
  508. print $langs->trans($reg[1]);
  509. } else {
  510. print dol_escape_htmltag($objp->label);
  511. }
  512. print '</td>';
  513. }
  514. print '</tr>';
  515. // Amount
  516. print "<tr><td>".$langs->trans("Amount")."</td>";
  517. if ($user->rights->banque->modifier) {
  518. print '<td>';
  519. print '<input name="amount" class="flat maxwidth100" '.($objp->rappro ? ' disabled' : '').' value="'.price($objp->amount).'"> '.$langs->trans("Currency".$acct->currency_code);
  520. print '</td>';
  521. } else {
  522. print '<td>';
  523. print price($objp->amount);
  524. print '</td>';
  525. }
  526. print "</tr>";
  527. // Categories
  528. if (isModEnabled('categorie') && $user->hasRight('categorie', 'lire')) {
  529. $langs->load('categories');
  530. // Bank line
  531. print '<tr><td class="toptd">'.$form->editfieldkey('RubriquesTransactions', 'custcats', '', $object, 0).'</td><td>';
  532. $cate_arbo = $form->select_all_categories(Categorie::TYPE_BANK_LINE, null, 'parent', null, null, 1);
  533. $arrayselected = array();
  534. $c = new Categorie($db);
  535. $cats = $c->containing($bankline->id, Categorie::TYPE_BANK_LINE);
  536. if (is_array($cats)) {
  537. foreach ($cats as $cat) {
  538. $arrayselected[] = $cat->id;
  539. }
  540. }
  541. print img_picto('', 'category', 'class="paddingright"').$form->multiselectarray('custcats', $cate_arbo, $arrayselected, null, null, null, null, "90%");
  542. print "</td></tr>";
  543. }
  544. // Other attributes
  545. $parameters = array();
  546. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $bankline, $action); // Note that $action and $object may have been modified by hook
  547. print $hookmanager->resPrint;
  548. if (empty($reshook)) {
  549. print $bankline->showOptionals($extrafields, ($objp->rappro ? 'view' : 'create'), $parameters);
  550. }
  551. print "</table>";
  552. // Code to adjust value date with plus and less picto using an Ajax call instead of a full reload of page
  553. /* Not yet ready. We must manage inline replacemet of input date field
  554. $urlajax = DOL_URL_ROOT.'/core/ajax/bankconciliate.php?token='.currentToken();
  555. print '
  556. <script type="text/javascript">
  557. $(function() {
  558. $("a.ajaxforbankoperationchange").each(function(){
  559. var current = $(this);
  560. current.click(function()
  561. {
  562. var url = "'.$urlajax.'&"+current.attr("href").split("?")[1];
  563. $.get(url, function(data)
  564. {
  565. console.log(url)
  566. console.log(data)
  567. current.parent().prev().replaceWith(data);
  568. });
  569. return false;
  570. });
  571. });
  572. });
  573. </script>
  574. ';
  575. */
  576. print '</div>';
  577. print dol_get_fiche_end();
  578. print '<div class="center"><input type="submit" class="button" value="'.$langs->trans("Update").'"></div><br>';
  579. print "</form>";
  580. // Releve rappro
  581. if ($acct->canBeConciliated() > 0) { // Si compte rapprochable
  582. print load_fiche_titre($langs->trans("Reconciliation"), '', 'bank_account');
  583. print '<hr>'."\n";
  584. print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'?rowid='.$objp->rowid.'">';
  585. print '<input type="hidden" name="token" value="'.newToken().'">';
  586. print '<input type="hidden" name="action" value="setreconcile">';
  587. print '<input type="hidden" name="orig_account" value="'.$orig_account.'">';
  588. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  589. print '<div class="fichecenter">';
  590. print '<table class="border centpercent">';
  591. print '<tr><td class="titlefieldcreate">'.$form->textwithpicto($langs->trans("AccountStatement"), $langs->trans("InputReceiptNumber"))."</td>";
  592. if ($user->rights->banque->consolidate) {
  593. print '<td>';
  594. if ($objp->rappro) {
  595. print '<input name="num_rel_bis" id="num_rel_bis" class="flat" type="text" value="'.$objp->num_releve.'"'.($objp->rappro ? ' disabled' : '').'>';
  596. print '<input name="num_rel" id="num_rel" class="flat" type="hidden" value="'.$objp->num_releve.'">';
  597. } else {
  598. print '<input name="num_rel" id="num_rel" class="flat" value="'.$objp->num_releve.'"'.($objp->rappro ? ' disabled' : '').'>';
  599. }
  600. if ($objp->num_releve) {
  601. print ' &nbsp; <a href="'.DOL_URL_ROOT.'/compta/bank/releve.php?num='.$objp->num_releve.'&account='.$acct->id.'">('.$langs->trans("AccountStatement").' '.$objp->num_releve.')</a>';
  602. }
  603. print '</td>';
  604. } else {
  605. print '<td>'.$objp->num_releve.'</td>';
  606. }
  607. print '</tr>';
  608. print '<tr><td><label for="reconciled">'.$langs->trans("BankLineConciliated").'</label></td>';
  609. if ($user->rights->banque->consolidate) {
  610. print '<td>';
  611. print '<input type="checkbox" id="reconciled" name="reconciled" class="flat" '.(GETPOSTISSET("reconciled") ? (GETPOST("reconciled") ? ' checked="checked"' : '') : ($objp->rappro ? ' checked="checked"' : '')).'">';
  612. print '
  613. <script type="text/javascript">
  614. jQuery(document).ready(function() {
  615. $("#reconciled").click(function(){
  616. console.log("We click on checkbox reconciled "+$("#reconciled").prop("checked"));
  617. if ($("#reconciled").prop("checked") == false) {
  618. console.log("we remove disabled");
  619. jQuery("#num_rel_bis").removeAttr("disabled");
  620. jQuery("#num_rel").removeAttr("disabled");
  621. jQuery("#num_rel_bis").attr("type", "hidden");
  622. jQuery("#num_rel").attr("type", "text");
  623. jQuery("#num_rel_bis").hide();
  624. jQuery("#num_rel").show();
  625. } else {
  626. }
  627. });
  628. });
  629. </script>
  630. ';
  631. print '</td>';
  632. } else {
  633. print '<td>'.yn($objp->rappro).'</td>';
  634. }
  635. print '</tr>';
  636. print '</table>';
  637. print '</div>';
  638. print '<div class="center">';
  639. print '<input type="submit" class="button" value="'.$langs->trans("Update").'">';
  640. if ($backtopage) {
  641. print ' &nbsp; ';
  642. print '<input type="submit" name="cancel" class="button button-cancel" value="'.$langs->trans("Cancel").'">';
  643. }
  644. print '</div>';
  645. print '</form>';
  646. }
  647. }
  648. $db->free($result);
  649. } else {
  650. dol_print_error($db);
  651. }
  652. // End of page
  653. llxFooter();
  654. $db->close();