PageRenderTime 45ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/compta/bank/account.php

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