PageRenderTime 47ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 1ms

/htdocs/compta/bank/account.php

https://github.com/asterix14/dolibarr
PHP | 782 lines | 604 code | 83 blank | 95 comment | 123 complexity | 6a9d8c53b8a0c23fec8368cc9464eef6 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2003 Jean-Louis Bergamo <jlb@j1b.org>
  4. * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copytight (C) 2004 Christophe Combelles <ccomb@free.fr>
  6. * Copytight (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
  7. * Copytight (C) 2010-2011 Juanjo Menent <jmenent@@2byte.es>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/compta/bank/account.php
  24. * \ingroup banque
  25. * \brief List of details of bank transactions for an account
  26. */
  27. require("./pre.inc.php"); // We use pre.inc.php to have a dynamic menu
  28. require_once(DOL_DOCUMENT_ROOT."/core/lib/bank.lib.php");
  29. require_once(DOL_DOCUMENT_ROOT."/societe/class/societe.class.php");
  30. require_once(DOL_DOCUMENT_ROOT."/adherents/class/adherent.class.php");
  31. require_once(DOL_DOCUMENT_ROOT."/compta/sociales/class/chargesociales.class.php");
  32. require_once(DOL_DOCUMENT_ROOT."/compta/paiement/class/paiement.class.php");
  33. require_once(DOL_DOCUMENT_ROOT."/compta/tva/class/tva.class.php");
  34. require_once(DOL_DOCUMENT_ROOT."/fourn/class/paiementfourn.class.php");
  35. $langs->load("bills");
  36. // Security check
  37. if (isset($_GET["account"]) || isset($_GET["ref"]))
  38. {
  39. $id = isset($_GET["account"])?$_GET["account"]:(isset($_GET["ref"])?$_GET["ref"]:'');
  40. }
  41. $fieldid = isset($_GET["ref"])?'ref':'rowid';
  42. if ($user->societe_id) $socid=$user->societe_id;
  43. $result=restrictedArea($user,'banque',$id,'bank_account','','',$fieldid);
  44. $req_nb=GETPOST("req_nb",'',3);
  45. $thirdparty=GETPOST("thirdparty",'',3);
  46. $account=GETPOST("account");
  47. $vline=GETPOST("vline");
  48. $action=GETPOST("action");
  49. $page=isset($_GET["page"])?$_GET["page"]:0;
  50. $negpage=isset($_GET["negpage"])?$_GET["negpage"]:0;
  51. if ($negpage)
  52. {
  53. $page=$_GET["nbpage"] - $negpage;
  54. if ($page > $_GET["nbpage"]) $page = $_GET["nbpage"];
  55. }
  56. $mesg='';
  57. /*
  58. * Action
  59. */
  60. $dateop=-1;
  61. if ($action == 'add' && $account && ! isset($_POST["cancel"]) && $user->rights->banque->modifier)
  62. {
  63. if (price2num($_POST["credit"]) > 0)
  64. {
  65. $amount = price2num($_POST["credit"]);
  66. }
  67. else
  68. {
  69. $amount = - price2num($_POST["debit"]);
  70. }
  71. $dateop = dol_mktime(12,0,0,$_POST["opmonth"],$_POST["opday"],$_POST["opyear"]);
  72. $operation=$_POST["operation"];
  73. $num_chq=$_POST["num_chq"];
  74. $label=$_POST["label"];
  75. $cat1=$_POST["cat1"];
  76. if (! $dateop) $mesg=$langs->trans("ErrorFieldRequired",$langs->trans("Date"));
  77. if (! $operation) $mesg=$langs->trans("ErrorFieldRequired",$langs->trans("Type"));
  78. if (! $amount) $mesg=$langs->trans("ErrorFieldRequired",$langs->trans("Amount"));
  79. if (! $mesg)
  80. {
  81. $acct=new Account($db);
  82. $acct->fetch($account);
  83. $insertid = $acct->addline($dateop, $operation, $label, $amount, $num_chq, $cat1, $user);
  84. if ($insertid > 0)
  85. {
  86. Header("Location: ".$_SERVER['PHP_SELF']."?account=" . $account."&action=addline");
  87. exit;
  88. }
  89. else
  90. {
  91. dol_print_error($db,$acct->error);
  92. }
  93. }
  94. else
  95. {
  96. $action='addline';
  97. }
  98. }
  99. if ($action == 'confirm_delete' && $_POST["confirm"]=='yes' && $user->rights->banque->modifier)
  100. {
  101. $accline=new AccountLine($db);
  102. $accline->fetch($_GET["rowid"]);
  103. $result=$accline->delete();
  104. }
  105. /*
  106. * View
  107. */
  108. llxHeader();
  109. $societestatic=new Societe($db);
  110. $chargestatic=new ChargeSociales($db);
  111. $memberstatic=new Adherent($db);
  112. $paymentstatic=new Paiement($db);
  113. $paymentsupplierstatic=new PaiementFourn($db);
  114. $paymentvatstatic=new TVA($db);
  115. $form = new Form($db);
  116. if ($account || $_GET["ref"])
  117. {
  118. if ($vline)
  119. {
  120. $viewline = $vline;
  121. }
  122. else
  123. {
  124. $viewline = empty($conf->global->MAIN_SIZE_LISTE_LIMIT)?20:$conf->global->MAIN_SIZE_LISTE_LIMIT;
  125. }
  126. $acct = new Account($db);
  127. if ($account)
  128. {
  129. $result=$acct->fetch($account);
  130. }
  131. if ($_GET["ref"])
  132. {
  133. $result=$acct->fetch(0,$_GET["ref"]);
  134. $account=$acct->id;
  135. }
  136. // Chargement des categories bancaires dans $options
  137. $nbcategories=0;
  138. $sql = "SELECT rowid, label";
  139. $sql.= " FROM ".MAIN_DB_PREFIX."bank_categ";
  140. $sql.= " WHERE entity = ".$conf->entity;
  141. $sql.= " ORDER BY label";
  142. $result = $db->query($sql);
  143. if ($result)
  144. {
  145. $var=True;
  146. $num = $db->num_rows($result);
  147. $i = 0;
  148. $options = '<option value="0" selected="true">&nbsp;</option>';
  149. while ($i < $num)
  150. {
  151. $obj = $db->fetch_object($result);
  152. $options.= '<option value="'.$obj->rowid.'">'.$obj->label.'</option>'."\n";
  153. $nbcategories++;
  154. $i++;
  155. }
  156. $db->free($result);
  157. }
  158. // Definition de sql_rech et param
  159. $param='';
  160. $sql_rech='';
  161. $mode_search = 0;
  162. if ($req_nb)
  163. {
  164. $sql_rech.= " AND b.num_chq LIKE '%".$db->escape($req_nb)."%'";
  165. $param.='&amp;req_nb='.urlencode($req_nb);
  166. $mode_search = 1;
  167. }
  168. if ($_REQUEST["req_desc"])
  169. {
  170. $sql_rech.= " AND b.label LIKE '%".$db->escape($_REQUEST["req_desc"])."%'";
  171. $param.='&amp;req_desc='.urlencode($_REQUEST["req_desc"]);
  172. $mode_search = 1;
  173. }
  174. if ($_REQUEST["req_debit"])
  175. {
  176. $sql_rech.=" AND b.amount = -".price2num($_REQUEST["req_debit"]);
  177. $param.='&amp;req_debit='.urlencode($_REQUEST["req_debit"]);
  178. $mode_search = 1;
  179. }
  180. if ($_REQUEST["req_credit"])
  181. {
  182. $sql_rech.=" AND b.amount = ".price2num($_REQUEST["req_credit"]);
  183. $param.='&amp;req_credit='.urlencode($_REQUEST["req_credit"]);
  184. $mode_search = 1;
  185. }
  186. if ($thirdparty)
  187. {
  188. $sql_rech.=" AND s.nom LIKE '%".$db->escape($thirdparty)."%'";
  189. $param.='&amp;thirdparty='.urlencode($thirdparty);
  190. $mode_search = 1;
  191. }
  192. if ($_REQUEST["paiementtype"])
  193. {
  194. $sql_rech.=" AND b.fk_type = '".$db->escape($_REQUEST["paiementtype"])."'";
  195. $param.='&amp;paiementtype='.urlencode($_REQUEST["paiementtype"]);
  196. $mode_search = 1;
  197. }
  198. $sql = "SELECT count(*) as nb";
  199. $sql.= " FROM ".MAIN_DB_PREFIX."bank_account as ba";
  200. $sql.= ", ".MAIN_DB_PREFIX."bank as b";
  201. if ($mode_search)
  202. {
  203. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_url as bu ON bu.fk_bank = b.rowid AND bu.type='company'";
  204. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON bu.url_id = s.rowid";
  205. }
  206. $sql.= " WHERE b.fk_account = ".$acct->id;
  207. $sql.= " AND b.fk_account = ba.rowid";
  208. $sql.= " AND ba.entity = ".$conf->entity;
  209. $sql.= $sql_rech;
  210. dol_syslog("account.php count transactions - sql=".$sql, LOG_DEBUG);
  211. $result=$db->query($sql);
  212. if ($result)
  213. {
  214. $obj = $db->fetch_object($result);
  215. $nbline = $obj->nb;
  216. $total_lines = $nbline;
  217. if ($nbline > $viewline ) $limit = $nbline - $viewline ;
  218. else $limit = $viewline;
  219. $db->free($result);
  220. }
  221. else
  222. {
  223. dol_print_error($db);
  224. }
  225. if ($page > 0)
  226. {
  227. $limitsql = $nbline - ($page * $viewline);
  228. if ($limitsql < $viewline) $limitsql = $viewline;
  229. $nbline = $limitsql;
  230. }
  231. else
  232. {
  233. $page = 0;
  234. $limitsql = $nbline;
  235. }
  236. //print $limitsql.'-'.$page.'-'.$viewline;
  237. // Onglets
  238. $head=bank_prepare_head($acct);
  239. dol_fiche_head($head,'journal',$langs->trans("FinancialAccount"),0,'account');
  240. print '<table class="border" width="100%">';
  241. // Ref
  242. print '<tr><td valign="top" width="25%">'.$langs->trans("Ref").'</td>';
  243. print '<td colspan="3">';
  244. print $form->showrefnav($acct,'ref','',1,'ref');
  245. print '</td></tr>';
  246. // Label
  247. print '<tr><td valign="top">'.$langs->trans("Label").'</td>';
  248. print '<td colspan="3">'.$acct->label.'</td></tr>';
  249. print '</table>';
  250. print '<br>';
  251. dol_htmloutput_errors($mesg);
  252. /**
  253. * Search form
  254. */
  255. $param.='&amp;account='.$acct->id;
  256. // Define transaction list navigation string
  257. $navig='';
  258. $navig.='<form action="'.$_SERVER["PHP_SELF"].'" name="newpage" method="GET">';
  259. $nbpage=floor($total_lines/$viewline)+($total_lines % $viewline > 0?1:0); // Nombre de page total
  260. //print 'nbpage='.$nbpage.' viewline='.$viewline.' limitsql='.$limitsql;
  261. if ($limitsql > $viewline) $navig.='<a href="account.php?'.$param.'&amp;page='.($page+1).'">'.img_previous().'</a>';
  262. $navig.= $langs->trans("Page")." "; // ' Page ';
  263. $navig.='<input type="text" name="negpage" size="1" class="flat" value="'.($nbpage-$page).'">';
  264. $navig.='<input type="hidden" name="req_nb" value="'.$req_nb.'">';
  265. $navig.='<input type="hidden" name="req_desc" value="'.$_REQUEST["req_desc"].'">';
  266. $navig.='<input type="hidden" name="req_debit" value="'.$_REQUEST["req_debit"].'">';
  267. $navig.='<input type="hidden" name="req_credit" value="'.$_REQUEST["req_credit"].'">';
  268. $navig.='<input type="hidden" name="thirdparty" value="'.$thirdparty.'">';
  269. $navig.='<input type="hidden" name="nbpage" value="'.$nbpage.'">';
  270. $navig.='<input type="hidden" name="account" value="'.($acct->id).'">';
  271. $navig.='/'.$nbpage.' ';
  272. if ($total_lines > $limitsql )
  273. {
  274. $navig.= '<a href="account.php?'.$param.'&amp;page='.($page-1).'">'.img_next().'</a>';
  275. }
  276. $navig.='</form>';
  277. //var_dump($navig);
  278. // Confirmation delete
  279. if ($action == 'delete')
  280. {
  281. $text=$langs->trans('ConfirmDeleteTransaction');
  282. $ret=$form->form_confirm($_SERVER['PHP_SELF'].'?account='.$acct->id.'&amp;rowid='.$_GET["rowid"],$langs->trans('DeleteTransaction'),$text,'confirm_delete');
  283. if ($ret == 'html') print '<br>';
  284. }
  285. print '<table class="notopnoleftnoright" width="100%">';
  286. // Show title
  287. if ($action != 'addline' && $action != 'delete')
  288. {
  289. print '<tr><td colspan="9" align="right">'.$navig.'</td></tr>';
  290. }
  291. // Form to add a transaction with no invoice
  292. if ($user->rights->banque->modifier && $action == 'addline')
  293. {
  294. print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
  295. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  296. print '<input type="hidden" name="action" value="add">';
  297. print '<input type="hidden" name="vline" value="' . $vline . '">';
  298. print '<input type="hidden" name="account" value="' . $acct->id . '">';
  299. print '<tr>';
  300. print '<td align="left" colspan="10"><b>'.$langs->trans("AddBankRecordLong").'</b></td>';
  301. print '</tr>';
  302. print '<tr class="liste_titre">';
  303. print '<td>'.$langs->trans("Date").'</td>';
  304. print '<td>&nbsp;</td>';
  305. print '<td>'.$langs->trans("Type").'</td>';
  306. print '<td>'.$langs->trans("Numero").'</td>';
  307. print '<td colspan="2">'.$langs->trans("Description").'</td>';
  308. print '<td align=right>'.$langs->trans("Debit").'</td>';
  309. print '<td align=right>'.$langs->trans("Credit").'</td>';
  310. print '<td colspan="2" align="center">&nbsp;</td>';
  311. print '</tr>';
  312. print '<tr '.$bc[false].'>';
  313. print '<td nowrap="nowrap" colspan="2">';
  314. $form->select_date($dateop,'op',0,0,0,'transaction');
  315. print '</td>';
  316. print '<td nowrap="nowrap">';
  317. $form->select_types_paiements((isset($_POST["operation"])?$_POST["operation"]:''),'operation','1,2',2,1);
  318. print '</td><td>';
  319. print '<input name="num_chq" class="flat" type="text" size="4" value="'.(isset($_POST["num_chq"])?$_POST["num_chq"]:'').'"></td>';
  320. print '<td colspan="2">';
  321. print '<input name="label" class="flat" type="text" size="24" value="'.(isset($_POST["label"])?$_POST["label"]:'').'">';
  322. if ($nbcategories)
  323. {
  324. print '<br>'.$langs->trans("Category").': <select class="flat" name="cat1">'.$options.'</select>';
  325. }
  326. print '</td>';
  327. print '<td align=right><input name="debit" class="flat" type="text" size="4" value="'.(isset($_POST["debit"])?$_POST["debit"]:'').'"></td>';
  328. print '<td align=right><input name="credit" class="flat" type="text" size="4" value="'.(isset($_POST["credit"])?$_POST["credit"]:'').'"></td>';
  329. print '<td colspan="2" align="center">';
  330. print '<input type="submit" name="save" class="button" value="'.$langs->trans("Add").'"><br>';
  331. print '<input type="submit" name="cancel" class="button" value="'.$langs->trans("Cancel").'">';
  332. print '</td></tr>';
  333. print "</form>";
  334. print '<tr class="noborder"><td colspan="8">&nbsp;</td></tr>'."\n";
  335. }
  336. /*
  337. * Affiche tableau des transactions bancaires
  338. */
  339. // Ligne de titre tableau des ecritures
  340. print '<tr class="liste_titre">';
  341. print '<td>'.$langs->trans("Date").'</td>';
  342. print '<td>'.$langs->trans("Value").'</td>';
  343. print '<td>'.$langs->trans("Type").'</td>';
  344. print '<td>'.$langs->trans("Numero").'</td>';
  345. print '<td>'.$langs->trans("Description").'</td>';
  346. print '<td>'.$langs->trans("ThirdParty").'</td>';
  347. print '<td align="right">'.$langs->trans("Debit").'</td>';
  348. print '<td align="right">'.$langs->trans("Credit").'</td>';
  349. print '<td align="right" width="80">'.$langs->trans("BankBalance").'</td>';
  350. print '<td align="center" width="60">';
  351. if ($acct->type != 2 && $acct->rappro) print $langs->trans("AccountStatementShort");
  352. else print '&nbsp;';
  353. print '</td></tr>';
  354. print '<form action="'.$_SERVER["PHP_SELF"].'?'.$param.'" name="search" method="POST">';
  355. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  356. print '<input type="hidden" name="action" value="search">';
  357. print '<input type="hidden" name="account" value="' . $acct->id . '">';
  358. print '<tr class="liste_titre">';
  359. print '<td>&nbsp;</td>';
  360. print '<td>&nbsp;</td>';
  361. print '<td>';
  362. //$filtertype=array('TIP'=>'TIP','PRE'=>'PRE',...)
  363. $filtertype='';
  364. print $form->select_types_paiements($_REQUEST['paiementtype'],'paiementtype',$filtertype,2,1,1,8);
  365. print '</td>';
  366. print '<td><input type="text" class="flat" name="req_nb" value="'.$req_nb.'" size="2"></td>';
  367. print '<td><input type="text" class="flat" name="req_desc" value="'.$_REQUEST["req_desc"].'" size="24"></td>';
  368. print '<td><input type="text" class="flat" name="thirdparty" value="'.$thirdparty.'" size="14"></td>';
  369. print '<td align="right"><input type="text" class="flat" name="req_debit" value="'.$_REQUEST["req_debit"].'" size="4"></td>';
  370. print '<td align="right"><input type="text" class="flat" name="req_credit" value="'.$_REQUEST["req_credit"].'" size="4"></td>';
  371. print '<td align="center">&nbsp;</td>';
  372. print '<td align="center" width="40"><input type="image" class="liste_titre" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/search.png" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'"></td>';
  373. print "</tr>\n";
  374. print "</form>\n";
  375. /*
  376. * Another solution
  377. * create temporary table solde type=heap select amount from llx_bank limit 100 ;
  378. * select sum(amount) from solde ;
  379. */
  380. $sql = "SELECT b.rowid, b.dateo as do, b.datev as dv,";
  381. $sql.= " b.amount, b.label, b.rappro, b.num_releve, b.num_chq, b.fk_type";
  382. if ($mode_search)
  383. {
  384. $sql.= ", s.rowid as socid, s.nom as thirdparty";
  385. }
  386. /*
  387. if ($mode_search && $conf->adherent->enabled)
  388. {
  389. }
  390. if ($mode_search && $conf->tax->enabled)
  391. {
  392. }
  393. */
  394. $sql.= " FROM ".MAIN_DB_PREFIX."bank_account as ba";
  395. $sql.= ", ".MAIN_DB_PREFIX."bank as b";
  396. if ($mode_search)
  397. {
  398. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_url as bu1 ON bu1.fk_bank = b.rowid AND bu1.type='company'";
  399. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON bu1.url_id = s.rowid";
  400. }
  401. if ($mode_search && $conf->tax->enabled)
  402. {
  403. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_url as bu2 ON bu2.fk_bank = b.rowid AND bu2.type='payment_vat'";
  404. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."tva as t ON bu2.url_id = t.rowid";
  405. }
  406. if ($mode_search && $conf->adherent->enabled)
  407. {
  408. // TODO Mettre jointure sur adherent pour recherche sur un adherent
  409. //$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_url as bu3 ON bu3.fk_bank = b.rowid AND bu3.type='company'";
  410. //$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON bu3.url_id = s.rowid";
  411. }
  412. $sql.= " WHERE b.fk_account=".$acct->id;
  413. $sql.= " AND b.fk_account = ba.rowid";
  414. $sql.= " AND ba.entity = ".$conf->entity;
  415. $sql.= $sql_rech;
  416. $sql.= $db->order("b.datev, b.datec", "ASC"); // We add date of creation to have correct order when everything is done the same day
  417. $sql.= $db->plimit($limitsql, 0);
  418. dol_syslog("account.php get transactions - sql=".$sql, LOG_DEBUG);
  419. $result = $db->query($sql);
  420. if ($result)
  421. {
  422. $now=dol_now();
  423. $nows=dol_print_date($now,'%Y%m%d');
  424. //$form->load_cache_types_paiements();
  425. //$form->cache_types_paiements
  426. $var=true;
  427. $num = $db->num_rows($result);
  428. $i = 0; $total = 0; $sep = 0;
  429. while ($i < $num)
  430. {
  431. $objp = $db->fetch_object($result);
  432. $total = price2num($total + $objp->amount,'MT');
  433. if ($i >= ($nbline - $viewline))
  434. {
  435. $var=!$var;
  436. // Is it a transaction in future ?
  437. $dos=dol_print_date($db->jdate($objp->do),'%Y%m%d');
  438. //print "dos=".$dos." nows=".$nows;
  439. if ($dos > $nows && !$sep) // Yes, we show a subtotal
  440. {
  441. $sep = 1 ;
  442. print '<tr class="liste_total"><td colspan="8">';
  443. print $langs->trans("CurrentBalance");
  444. print '</td>';
  445. print '<td align="right" nowrap><b>'.price($total - $objp->amount).'</b></td>';
  446. print "<td>&nbsp;</td>";
  447. print '</tr>';
  448. }
  449. print '<tr '.$bc[$var].'>';
  450. print '<td nowrap="nowrap">'.dol_print_date($db->jdate($objp->do),"day")."</td>\n";
  451. print '<td nowrap="nowrap">'.dol_print_date($db->jdate($objp->dv),"day");
  452. print "</td>\n";
  453. // Payment type
  454. print "<td nowrap>";
  455. $label=($langs->trans("PaymentTypeShort".$objp->fk_type)!="PaymentTypeShort".$objp->fk_type)?$langs->trans("PaymentTypeShort".$objp->fk_type):$objp->fk_type;
  456. // $label=$langs->getTradFromKey("PaymentTypeShort".$objp->fk_type);
  457. if ($objp->fk_type == 'SOLD') $label='&nbsp;';
  458. print $label;
  459. print "</td>\n";
  460. // Num
  461. print '<td nowrap>'.($objp->num_chq?$objp->num_chq:"")."</td>\n";
  462. // Description
  463. print '<td>';
  464. // Show generic description
  465. if (preg_match('/^\((.*)\)$/i',$objp->label,$reg))
  466. {
  467. // Generic description because between (). We show it after translating.
  468. print $langs->trans($reg[1]);
  469. }
  470. else
  471. {
  472. print dol_trunc($objp->label,60);
  473. }
  474. // Add links after description
  475. $links = $acct->get_url($objp->rowid);
  476. foreach($links as $key=>$val)
  477. {
  478. if ($links[$key]['type']=='payment')
  479. {
  480. $paymentstatic->id=$links[$key]['url_id'];
  481. print ' '.$paymentstatic->getNomUrl(2);
  482. }
  483. else if ($links[$key]['type']=='payment_supplier')
  484. {
  485. $paymentsupplierstatic->id=$links[$key]['url_id'];
  486. $paymentsupplierstatic->ref=$links[$key]['url_id'];
  487. print ' '.$paymentsupplierstatic->getNomUrl(2);
  488. }
  489. else if ($links[$key]['type']=='company')
  490. {
  491. }
  492. else if ($links[$key]['type']=='payment_sc')
  493. {
  494. //print ' - ';
  495. print '<a href="'.DOL_URL_ROOT.'/compta/payment_sc/fiche.php?id='.$links[$key]['url_id'].'">';
  496. print ' '.img_object($langs->trans('ShowPayment'),'payment').' ';
  497. //print $langs->trans("SocialContributionPayment");
  498. print '</a>';
  499. }
  500. else if ($links[$key]['type']=='payment_vat')
  501. {
  502. $paymentvatstatic->id=$links[$key]['url_id'];
  503. $paymentvatstatic->ref=$links[$key]['url_id'];
  504. print ' '.$paymentvatstatic->getNomUrl(2);
  505. }
  506. else if ($links[$key]['type']=='banktransfert')
  507. {
  508. // Do not show this link (avoid confusion). Can already be accessed from transaction detail
  509. }
  510. else if ($links[$key]['type']=='member')
  511. {
  512. }
  513. else if ($links[$key]['type']=='sc')
  514. {
  515. }
  516. else
  517. {
  518. // Show link with label $links[$key]['label']
  519. if (! empty($objp->label) && ! empty($links[$key]['label'])) print ' - ';
  520. print '<a href="'.$links[$key]['url'].$links[$key]['url_id'].'">';
  521. if (preg_match('/^\((.*)\)$/i',$links[$key]['label'],$reg))
  522. {
  523. // Label generique car entre parentheses. On l'affiche en le traduisant
  524. if ($reg[1]=='paiement') $reg[1]='Payment';
  525. print ' '.$langs->trans($reg[1]);
  526. }
  527. else
  528. {
  529. print ' '.$links[$key]['label'];
  530. }
  531. print '</a>';
  532. }
  533. }
  534. print '</td>';
  535. // Add third party column
  536. print '<td>';
  537. foreach($links as $key=>$val)
  538. {
  539. if ($links[$key]['type']=='company')
  540. {
  541. $societestatic->id=$links[$key]['url_id'];
  542. $societestatic->nom=$links[$key]['label'];
  543. print $societestatic->getNomUrl(1,'',16);
  544. }
  545. else if ($links[$key]['type']=='sc')
  546. {
  547. // sc=old value
  548. $chargestatic->id=$links[$key]['url_id'];
  549. if (preg_match('/^\((.*)\)$/i',$links[$key]['label'],$reg))
  550. {
  551. if ($reg[1]=='socialcontribution') $reg[1]='SocialContribution';
  552. $chargestatic->lib=$langs->trans($reg[1]);
  553. }
  554. else
  555. {
  556. $chargestatic->lib=$links[$key]['label'];
  557. }
  558. $chargestatic->ref=$chargestatic->lib;
  559. print $chargestatic->getNomUrl(1,16);
  560. }
  561. else if ($links[$key]['type']=='member')
  562. {
  563. $memberstatic->id=$links[$key]['url_id'];
  564. $memberstatic->ref=$links[$key]['label'];
  565. print $memberstatic->getNomUrl(1,16,'card');
  566. }
  567. }
  568. print '</td>';
  569. // Amount
  570. if ($objp->amount < 0)
  571. {
  572. print '<td align="right" nowrap>'.price($objp->amount * -1).'</td><td>&nbsp;</td>'."\n";
  573. }
  574. else
  575. {
  576. print '<td>&nbsp;</td><td align="right" nowrap>&nbsp;'.price($objp->amount).'</td>'."\n";
  577. }
  578. // Balance
  579. if ($action != 'search')
  580. {
  581. if ($total >= 0)
  582. {
  583. print '<td align="right" nowrap>&nbsp;'.price($total).'</td>';
  584. }
  585. else
  586. {
  587. print '<td align="right" class="error" nowrap>&nbsp;'.price($total).'</td>';
  588. }
  589. }
  590. else
  591. {
  592. print '<td align="right">-</td>';
  593. }
  594. // Transaction reconciliated or edit link
  595. if ($objp->rappro && $acct->canBeConciliated() > 0) // If line not conciliated and account can be conciliated
  596. {
  597. print '<td align="center" nowrap>';
  598. print '<a href="'.DOL_URL_ROOT.'/compta/bank/ligne.php?rowid='.$objp->rowid.'&amp;account='.$acct->id.'&amp;page='.$page.'">';
  599. print img_edit();
  600. print '</a>';
  601. print "&nbsp; ";
  602. print '<a href="releve.php?num='.$objp->num_releve.'&amp;account='.$acct->id.'">'.$objp->num_releve.'</a>';
  603. print "</td>";
  604. }
  605. else
  606. {
  607. print '<td align="center">';
  608. if ($user->rights->banque->modifier || $user->rights->banque->consolidate)
  609. {
  610. print '<a href="'.DOL_URL_ROOT.'/compta/bank/ligne.php?rowid='.$objp->rowid.'&amp;account='.$acct->id.'&amp;page='.$page.'">';
  611. print img_edit();
  612. print '</a>';
  613. }
  614. else
  615. {
  616. print '<a href="'.DOL_URL_ROOT.'/compta/bank/ligne.php?rowid='.$objp->rowid.'&amp;account='.$acct->id.'&amp;page='.$page.'">';
  617. print img_view();
  618. print '</a>';
  619. }
  620. if ($acct->canBeConciliated() > 0 && empty($objp->rappro))
  621. {
  622. if ($db->jdate($objp->dv) < ($now - $conf->bank->rappro->warning_delay))
  623. {
  624. print ' '.img_warning($langs->trans("Late"));
  625. }
  626. }
  627. print '&nbsp;';
  628. if ($user->rights->banque->modifier)
  629. {
  630. print '<a href="'.DOL_URL_ROOT.'/compta/bank/account.php?action=delete&amp;rowid='.$objp->rowid.'&amp;account='.$acct->id.'&amp;page='.$page.'">';
  631. print img_delete();
  632. print '</a>';
  633. }
  634. print '</td>';
  635. }
  636. print "</tr>";
  637. }
  638. $i++;
  639. }
  640. // Show total
  641. if ($page == 0 && ! $mode_search)
  642. {
  643. print '<tr class="liste_total"><td align="left" colspan="8">';
  644. if ($sep) print '&nbsp;';
  645. else print $langs->trans("CurrentBalance");
  646. print '</td>';
  647. print '<td align="right" nowrap>'.price($total).'</td>';
  648. print '<td>&nbsp;</td>';
  649. print '</tr>';
  650. }
  651. $db->free($result);
  652. }
  653. else
  654. {
  655. dol_print_error($db);
  656. }
  657. print "</table>";
  658. print "\n</div>\n";
  659. /*
  660. * Boutons actions
  661. */
  662. if ($action != 'delete')
  663. {
  664. print '<div class="tabsAction">';
  665. if ($acct->type != 2 && $acct->rappro) // If not cash account and can be reconciliate
  666. {
  667. if ($user->rights->banque->consolidate)
  668. {
  669. print '<a class="butAction" href="'.DOL_URL_ROOT.'/compta/bank/rappro.php?account='.$acct->id.'">'.$langs->trans("Conciliate").'</a>';
  670. }
  671. else
  672. {
  673. print '<a class="butActionRefused" title="'.$langs->trans("NotEnoughPermissions").'" href="#">'.$langs->trans("Conciliate").'</a>';
  674. }
  675. }
  676. if ($action != 'addline')
  677. {
  678. if ($user->rights->banque->modifier)
  679. {
  680. print '<a class="butAction" href="account.php?action=addline&amp;account='.$acct->id.'&amp;page='.$page.'">'.$langs->trans("AddBankRecord").'</a>';
  681. }
  682. else
  683. {
  684. print '<a class="butActionRefused" title="'.$langs->trans("NotEnoughPermissions").'" href="#">'.$langs->trans("AddBankRecord").'</a>';
  685. }
  686. }
  687. print '</div>';
  688. }
  689. print '<br>';
  690. }
  691. else
  692. {
  693. print $langs->trans("ErrorBankAccountNotFound");
  694. }
  695. $db->close();
  696. llxFooter();
  697. ?>