account.php 27 KB

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