1<?php 2/* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org> 3 * Copyright (C) 2004-2019 Laurent Destailleur <eldy@users.sourceforge.net> 4 * Copyright (C) 2005-2013 Regis Houssin <regis.houssin@inodbox.com> 5 * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr> 6 * Copyright (C) 2017 Patrick Delcroix <pmpdelcroix@gmail.com> 7 * Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.com> 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 3 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 <https://www.gnu.org/licenses/>. 21 */ 22 23/** 24 * \file htdocs/compta/bank/releve.php 25 * \ingroup banque 26 * \brief Page to show a bank statement report 27 */ 28 29require '../../main.inc.php'; 30require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php'; 31require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; 32require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; 33require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php'; 34require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php'; 35require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php'; 36require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php'; 37require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; 38require_once DOL_DOCUMENT_ROOT.'/compta/paiement/cheque/class/remisecheque.class.php'; 39require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; 40require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; 41require_once DOL_DOCUMENT_ROOT.'/don/class/paymentdonation.class.php'; 42require_once DOL_DOCUMENT_ROOT.'/loan/class/paymentloan.class.php'; 43require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/paymentvarious.class.php'; 44//show files 45require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; 46require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php'; 47 48// Load translation files required by the page 49$langs->loadLangs(array("banks", "categories", "companies", "bills", "trips", "donations", "loan")); 50 51$action = GETPOST('action', 'aZ09'); 52$id = GETPOST('account', 'int') ? GETPOST('account', 'int') : GETPOST('id', 'int'); 53$ref = GETPOST('ref', 'alpha'); 54$dvid = GETPOST('dvid', 'alpha'); 55$numref = GETPOST('num', 'alpha'); 56$ve = GETPOST("ve", 'alpha'); 57$brref = GETPOST('brref', 'alpha'); 58$oldbankreceipt = GETPOST('oldbankreceipt', 'alpha'); 59$newbankreceipt = GETPOST('newbankreceipt', 'alpha'); 60 61// Security check 62$fieldid = (!empty($ref) ? $ref : $id); 63$fieldname = isset($ref) ? 'ref' : 'rowid'; 64if ($user->socid) { 65 $socid = $user->socid; 66} 67$result = restrictedArea($user, 'banque', $fieldid, 'bank_account', '', '', $fieldname); 68 69if ($user->rights->banque->consolidate && $action == 'dvnext' && !empty($dvid)) { 70 $al = new AccountLine($db); 71 $al->datev_next($dvid); 72} 73 74if ($user->rights->banque->consolidate && $action == 'dvprev' && !empty($dvid)) { 75 $al = new AccountLine($db); 76 $al->datev_previous($dvid); 77} 78 79 80$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; 81$sortfield = GETPOST("sortfield", 'alpha'); 82$sortorder = GETPOST("sortorder", 'alpha'); 83$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); 84$pageplusone = GETPOST("pageplusone", 'int'); 85if ($pageplusone) { 86 $page = $pageplusone - 1; 87} 88if (empty($page) || $page == -1) { 89 $page = 0; 90} // If $page is not defined, or '' or -1 91$offset = $limit * $page; 92$pageprev = $page - 1; 93$pagenext = $page + 1; 94if (!$sortorder) { 95 $sortorder = "ASC"; 96} 97if (!$sortfield) { 98 $sortfield = "s.nom"; 99} 100 101$object = new Account($db); 102if ($id > 0 || !empty($ref)) { 103 $result = $object->fetch($id, $ref); 104 $account = $object->id; // Force the search field on id of account 105} 106 107 108// Initialize technical object to manage context to save list fields 109$contextpage = 'banktransactionlist'.(empty($object->ref) ? '' : '-'.$object->id); 110 111 112// Define number of receipt to show (current, previous or next one ?) 113$found = false; 114if ($_GET["rel"] == 'prev') { 115 // Recherche valeur pour num = numero releve precedent 116 $sql = "SELECT DISTINCT(b.num_releve) as num"; 117 $sql .= " FROM ".MAIN_DB_PREFIX."bank as b"; 118 $sql .= " WHERE b.num_releve < '".$db->escape($numref)."'"; 119 $sql .= " AND b.fk_account = ".((int) $object->id); 120 $sql .= " ORDER BY b.num_releve DESC"; 121 122 dol_syslog("htdocs/compta/bank/releve.php", LOG_DEBUG); 123 $resql = $db->query($sql); 124 if ($resql) { 125 $numrows = $db->num_rows($resql); 126 if ($numrows > 0) { 127 $obj = $db->fetch_object($resql); 128 $numref = $obj->num; 129 $found = true; 130 } 131 } 132} elseif ($_GET["rel"] == 'next') { 133 // Recherche valeur pour num = numero releve precedent 134 $sql = "SELECT DISTINCT(b.num_releve) as num"; 135 $sql .= " FROM ".MAIN_DB_PREFIX."bank as b"; 136 $sql .= " WHERE b.num_releve > '".$db->escape($numref)."'"; 137 $sql .= " AND b.fk_account = ".((int) $object->id); 138 $sql .= " ORDER BY b.num_releve ASC"; 139 140 dol_syslog("htdocs/compta/bank/releve.php", LOG_DEBUG); 141 $resql = $db->query($sql); 142 if ($resql) { 143 $numrows = $db->num_rows($resql); 144 if ($numrows > 0) { 145 $obj = $db->fetch_object($resql); 146 $numref = $obj->num; 147 $found = true; 148 } 149 } 150} else { 151 // On veut le releve num 152 $found = true; 153} 154 155 156$sql = "SELECT b.rowid, b.dateo as do, b.datev as dv,"; 157$sql .= " b.amount, b.label, b.rappro, b.num_releve, b.num_chq, b.fk_type,"; 158$sql .= " b.fk_bordereau,"; 159$sql .= " bc.ref,"; 160$sql .= " ba.rowid as bankid, ba.ref as bankref, ba.label as banklabel"; 161$sql .= " FROM ".MAIN_DB_PREFIX."bank_account as ba"; 162$sql .= ", ".MAIN_DB_PREFIX."bank as b"; 163$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bordereau_cheque as bc ON bc.rowid=b.fk_bordereau'; 164$sql .= " WHERE b.num_releve='".$db->escape($numref)."'"; 165if (empty($numref)) { 166 $sql .= " OR b.num_releve is null"; 167} 168$sql .= " AND b.fk_account = ".((int) $object->id); 169$sql .= " AND b.fk_account = ba.rowid"; 170$sql .= $db->order("b.datev, b.datec", "ASC"); // We add date of creation to have correct order when everything is done the same day 171 172$sqlrequestforbankline = $sql; 173 174 175 176/* 177 * Actions 178 */ 179 180if ($action == 'confirm_editbankreceipt' && !empty($oldbankreceipt) && !empty($newbankreceipt)) { 181 // TODO Add a test to check newbankreceipt does not exists yet 182 $sqlupdate = "UPDATE ".MAIN_DB_PREFIX."bank SET num_releve = '".$db->escape($newbankreceipt)."'"; 183 $sqlupdate .= " WHERE num_releve = '".$db->escape($oldbankreceipt)."' AND fk_account = ".((int) $id); 184 $result = $db->query($sqlupdate); 185 if ($result < 0) { 186 dol_print_error($db); 187 } 188 189 $action = 'view'; 190} 191 192 193/* 194 * View 195 */ 196 197$title = $langs->trans("FinancialAccount").' - '.$langs->trans("AccountStatements"); 198$helpurl = ""; 199llxHeader('', $title, $helpurl); 200 201$form = new Form($db); 202$societestatic = new Societe($db); 203$chargestatic = new ChargeSociales($db); 204$memberstatic = new Adherent($db); 205$paymentstatic = new Paiement($db); 206$paymentsupplierstatic = new PaiementFourn($db); 207$paymentvatstatic = new Tva($db); 208$bankstatic = new Account($db); 209$banklinestatic = new AccountLine($db); 210$remisestatic = new RemiseCheque($db); 211$paymentdonationstatic = new PaymentDonation($db); 212$paymentloanstatic = new PaymentLoan($db); 213$paymentvariousstatic = new PaymentVarious($db); 214 215// Must be before button action 216$param = ''; 217if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) { 218 $param .= '&contextpage='.$contextpage; 219} 220if ($limit > 0 && $limit != $conf->liste_limit) { 221 $param .= '&limit='.$limit; 222} 223if ($id > 0) { 224 $param .= '&id='.urlencode($id); 225} 226 227 228if (empty($numref)) { 229 $sortfield = 'numr'; 230 $sortorder = 'DESC'; 231 232 // List of all standing receipts 233 $sql = "SELECT DISTINCT(b.num_releve) as numr"; 234 $sql .= " FROM ".MAIN_DB_PREFIX."bank as b"; 235 $sql .= " WHERE b.fk_account = ".((int) $object->id); 236 $sql .= $db->order($sortfield, $sortorder); 237 238 // Count total nb of records 239 $nbtotalofrecords = ''; 240 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { 241 $result = $db->query($sql); 242 $nbtotalofrecords = $db->num_rows($result); 243 } 244 245 $sql .= $db->plimit($conf->liste_limit + 1, $offset); 246 247 $result = $db->query($sql); 248 if ($result) { 249 $numrows = $db->num_rows($result); 250 $i = 0; 251 252 // Onglets 253 $head = bank_prepare_head($object); 254 print dol_get_fiche_head($head, 'statement', $langs->trans("FinancialAccount"), 0, 'account'); 255 256 $linkback = '<a href="'.DOL_URL_ROOT.'/compta/bank/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>'; 257 258 $morehtmlref = ''; 259 260 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1); 261 262 print dol_get_fiche_end(); 263 264 265 print '<div class="tabsAction">'; 266 267 if ($object->canBeConciliated() > 0) { 268 $allowautomaticconciliation = false; // TODO 269 $titletoconciliatemanual = $langs->trans("Conciliate"); 270 $titletoconciliateauto = $langs->trans("Conciliate"); 271 if ($allowautomaticconciliation) { 272 $titletoconciliatemanual .= ' ('.$langs->trans("Manual").')'; 273 $titletoconciliateauto .= ' ('.$langs->trans("Auto").')'; 274 } 275 276 // If not cash account and can be reconciliate 277 if ($user->rights->banque->consolidate) { 278 $buttonreconcile = '<a class="butAction" href="'.DOL_URL_ROOT.'/compta/bank/bankentries_list.php?action=reconcile&sortfield=b.datev,b.dateo,b.rowid&sortorder=asc,asc,asc&search_conciliated=0&search_account='.$id.$param.'">'.$titletoconciliatemanual.'</a>'; 279 } else { 280 $buttonreconcile = '<a class="butActionRefused classfortooltip" title="'.$langs->trans("NotEnoughPermissions").'" href="#">'.$titletoconciliatemanual.'</a>'; 281 } 282 283 284 if ($allowautomaticconciliation) { 285 // If not cash account and can be reconciliate 286 if ($user->rights->banque->consolidate) { 287 $newparam = $param; 288 $newparam = preg_replace('/search_conciliated=\d+/i', '', $newparam); 289 $buttonreconcile .= ' <a class="butAction" style="margin-bottom: 5px !important; margin-top: 5px !important" href="'.DOL_URL_ROOT.'/compta/bank/bankentries_list.php?action=reconcile&sortfield=b.datev,b.dateo,b.rowid&sortorder=asc,asc,asc&search_conciliated=0'.$newparam.'">'.$titletoconciliateauto.'</a>'; 290 } else { 291 $buttonreconcile .= ' <a class="butActionRefused" style="margin-bottom: 5px !important; margin-top: 5px !important" title="'.$langs->trans("NotEnoughPermissions").'" href="#">'.$titletoconciliateauto.'</a>'; 292 } 293 } 294 295 print $buttonreconcile; 296 } 297 298 print '</div>'; 299 300 301 print_barre_liste('', $page, $_SERVER["PHP_SELF"], "&account=".$object->id, $sortfield, $sortorder, '', $numrows, $totalnboflines, ''); 302 303 print '<form name="aaa" action="'.$_SERVER["PHP_SELF"].'" method="POST">'; 304 print '<input type="hidden" name="token" value="'.newToken().'">'; 305 print '<input type="hidden" name="action" value="confirm_editbankreceipt">'; 306 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">'; 307 print '<input type="hidden" name="account" value="'.$object->id.'">'; 308 print '<input type="hidden" name="page" value="'.$page.'">'; 309 310 print '<table class="noborder centpercent">'; 311 print '<tr class="liste_titre">'; 312 print '<td>'.$langs->trans("Ref").'</td>'; 313 print '<td class="right">'.$langs->trans("InitialBankBalance").'</td>'; 314 print '<td class="right">'.$langs->trans("EndBankBalance").'</td>'; 315 print '<td></td>'; 316 print '</tr>'; 317 318 $balancestart = array(); 319 $content = array(); 320 321 while ($i < min($numrows, $conf->liste_limit)) { 322 $objp = $db->fetch_object($result); 323 324 if (!isset($objp->numr)) { 325 // 326 } else { 327 print '<tr class="oddeven">'; 328 print '<td>'; 329 if ($action != 'editbankreceipt' || $objp->numr != $brref) { 330 print '<a href="releve.php?num='.$objp->numr.'&account='.$object->id.'">'.$objp->numr.'</a>'; 331 } else { 332 print '<input type="hidden" name="oldbankreceipt" value="'.$objp->numr.'">'; 333 print '<input type="text" name="newbankreceipt" value="'.$objp->numr.'">'; 334 print '<input type="submit" class="button" name="actionnewbankreceipt" value="'.$langs->trans("Rename").'">'; 335 print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">'; 336 } 337 print '</td>'; 338 339 // Calculate start amount 340 $sql = "SELECT sum(b.amount) as amount"; 341 $sql .= " FROM ".MAIN_DB_PREFIX."bank as b"; 342 $sql .= " WHERE b.num_releve < '".$db->escape($objp->numr)."'"; 343 $sql .= " AND b.fk_account = ".((int) $object->id); 344 $resql = $db->query($sql); 345 if ($resql) { 346 $obj = $db->fetch_object($resql); 347 $balancestart[$objp->numr] = $obj->amount; 348 $db->free($resql); 349 } 350 print '<td class="right"><span class="amount">'.price($balancestart[$objp->numr], '', $langs, 1, -1, -1, $conf->currency).'</span></td>'; 351 352 // Calculate end amount 353 $sql = "SELECT sum(b.amount) as amount"; 354 $sql .= " FROM ".MAIN_DB_PREFIX."bank as b"; 355 $sql .= " WHERE b.num_releve = '".$db->escape($objp->numr)."'"; 356 $sql .= " AND b.fk_account = ".((int) $object->id); 357 $resql = $db->query($sql); 358 if ($resql) { 359 $obj = $db->fetch_object($resql); 360 $content[$objp->numr] = $obj->amount; 361 $db->free($resql); 362 } 363 print '<td class="right"><span class="amount">'.price(($balancestart[$objp->numr] + $content[$objp->numr]), '', $langs, 1, -1, -1, $conf->currency).'</span></td>'; 364 365 print '<td class="center">'; 366 if ($user->rights->banque->consolidate && $action != 'editbankreceipt') { 367 print '<a href="'.$_SERVER["PHP_SELF"].'?account='.$object->id.($page > 0 ? '&page='.$page : '').'&action=editbankreceipt&brref='.$objp->numr.'">'.img_edit().'</a>'; 368 } 369 print '</td>'; 370 371 print '</tr>'."\n"; 372 } 373 $i++; 374 } 375 print "</table>\n"; 376 print '</form>'; 377 378 print "\n</div>\n"; 379 } else { 380 dol_print_error($db); 381 } 382} else { 383 /** 384 * Show list of record into a bank statement 385 */ 386 387 // Onglets 388 $head = account_statement_prepare_head($object, $numref); 389 print dol_get_fiche_head($head, 'statement', $langs->trans("AccountStatement"), -1, 'account'); 390 391 392 $morehtmlright = ''; 393 $morehtmlright .= '<div class="pagination"><ul>'; 394 $morehtmlright .= '<li class="pagination"><a class="paginationnext" href="'.$_SERVER["PHP_SELF"].'?rel=prev&num='.$numref.'&ve='.$ve.'&account='.$object->id.'"><i class="fa fa-chevron-left" title="'.dol_escape_htmltag($langs->trans("Previous")).'"></i></a></li>'; 395 $morehtmlright .= '<li class="pagination"><span class="active">'.$langs->trans("AccountStatement")." ".$numref.'</span></li>'; 396 $morehtmlright .= '<li class="pagination"><a class="paginationnext" href="'.$_SERVER["PHP_SELF"].'?rel=next&num='.$numref.'&ve='.$ve.'&account='.$object->id.'"><i class="fa fa-chevron-right" title="'.dol_escape_htmltag($langs->trans("Next")).'"></i></a></li>'; 397 $morehtmlright .= '</ul></div>'; 398 399 $title = $langs->trans("AccountStatement").' '.$numref.' - '.$langs->trans("BankAccount").' '.$object->getNomUrl(1, 'receipts'); 400 print load_fiche_titre($title, $morehtmlright, ''); 401 //print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, 0, $nbtotalofrecords, 'bank_account', 0, '', '', 0, 1); 402 403 print "<form method=\"post\" action=\"releve.php\">"; 404 print '<input type="hidden" name="token" value="'.newToken().'">'; 405 print '<input type="hidden" name="action" value="add">'; 406 407 print '<div class="div-table-responsive">'; 408 print '<table class="noborder centpercent">'; 409 print '<tr class="liste_titre">'; 410 print '<td class="center">'.$langs->trans("DateOperationShort").'</td>'; 411 print '<td class="center">'.$langs->trans("DateValueShort").'</td>'; 412 print '<td>'.$langs->trans("Type").'</td>'; 413 print '<td>'.$langs->trans("Description").'</td>'; 414 print '<td class="right" width="60">'.$langs->trans("Debit").'</td>'; 415 print '<td class="right" width="60">'.$langs->trans("Credit").'</td>'; 416 print '<td class="right">'.$langs->trans("Balance").'</td>'; 417 print '<td> </td>'; 418 print "</tr>\n"; 419 420 // Calcul du solde de depart du releve 421 $sql = "SELECT sum(b.amount) as amount"; 422 $sql .= " FROM ".MAIN_DB_PREFIX."bank as b"; 423 $sql .= " WHERE b.num_releve < '".$db->escape($numref)."'"; 424 $sql .= " AND b.fk_account = ".((int) $object->id); 425 426 $resql = $db->query($sql); 427 if ($resql) { 428 $obj = $db->fetch_object($resql); 429 $total = $obj->amount; 430 $db->free($resql); 431 } 432 433 // Recherche les ecritures pour le releve 434 $sql = $sqlrequestforbankline; 435 436 $result = $db->query($sql); 437 if ($result) { 438 $numrows = $db->num_rows($result); 439 $i = 0; 440 441 // Ligne Solde debut releve 442 print '<tr class="oddeven"><td colspan="3"></td>'; 443 print '<td colspan="3"><b>'.$langs->trans("InitialBankBalance")." :</b></td>"; 444 print '<td class="right"><b>'.price($total).'</b></td><td> </td>'; 445 print "</tr>\n"; 446 447 while ($i < $numrows) { 448 $objp = $db->fetch_object($result); 449 $total = $total + $objp->amount; 450 451 print '<tr class="oddeven">'; 452 453 // Date operation 454 print '<td class="nowrap center">'.dol_print_date($db->jdate($objp->do), "day").'</td>'; 455 456 // Date de valeur 457 print '<td valign="center" class="center nowrap">'; 458 print '<span class="spanforajaxedit">'.dol_print_date($db->jdate($objp->dv), "day").'</span>'; 459 print ' '; 460 print '<span class="inline-block">'; 461 print '<a class="ajaxforbankoperationchange reposition" href="'.$_SERVER['PHP_SELF'].'?action=dvprev&num='.$numref.'&account='.$object->id.'&rowid='.$objp->rowid.'&dvid='.$objp->rowid.'">'; 462 print img_edit_remove()."</a> "; 463 print '<a class="ajaxforbankoperationchange reposition" href="'.$_SERVER['PHP_SELF'].'?action=dvnext&num='.$numref.'&account='.$object->id.'&rowid='.$objp->rowid.'&dvid='.$objp->rowid.'">'; 464 print img_edit_add()."</a>"; 465 print '</span>'; 466 print "</td>\n"; 467 468 // Type and num 469 if ($objp->fk_type == 'SOLD') { 470 $type_label = ' '; 471 } else { 472 $type_label = ($langs->trans("PaymentTypeShort".$objp->fk_type) != "PaymentTypeShort".$objp->fk_type) ? $langs->trans("PaymentTypeShort".$objp->fk_type) : $objp->fk_type; 473 } 474 $link = ''; 475 if ($objp->fk_bordereau > 0) { 476 $remisestatic->id = $objp->fk_bordereau; 477 $remisestatic->ref = $objp->ref; 478 $link = ' '.$remisestatic->getNomUrl(1); 479 } 480 print '<td class="nowrap">'.$type_label.' '.($objp->num_chq ? $objp->num_chq : '').$link.'</td>'; 481 482 // Description 483 print '<td valign="center">'; 484 print '<a href="'.DOL_URL_ROOT.'/compta/bank/line.php?rowid='.$objp->rowid.'&account='.$object->id.'">'; 485 $reg = array(); 486 preg_match('/\((.+)\)/i', $objp->label, $reg); // Si texte entoure de parenthese on tente recherche de traduction 487 if ($reg[1] && $langs->trans($reg[1]) != $reg[1]) { 488 print $langs->trans($reg[1]); 489 } else { 490 print $objp->label; 491 } 492 print '</a>'; 493 494 /* 495 * Ajout les liens (societe, company...) 496 */ 497 $newline = 1; 498 $links = $object->get_url($objp->rowid); 499 foreach ($links as $key => $val) { 500 if (!$newline) { 501 print ' - '; 502 } else { 503 print '<br>'; 504 } 505 if ($links[$key]['type'] == 'payment') { 506 $paymentstatic->id = $links[$key]['url_id']; 507 $paymentstatic->ref = $langs->trans("Payment"); 508 print ' '.$paymentstatic->getNomUrl(1); 509 $newline = 0; 510 } elseif ($links[$key]['type'] == 'payment_supplier') { 511 $paymentsupplierstatic->id = $links[$key]['url_id']; 512 $paymentsupplierstatic->ref = $langs->trans("Payment"); 513 print ' '.$paymentsupplierstatic->getNomUrl(1); 514 $newline = 0; 515 } elseif ($links[$key]['type'] == 'payment_sc') { 516 print '<a href="'.DOL_URL_ROOT.'/compta/payment_sc/card.php?id='.$links[$key]['url_id'].'">'; 517 print ' '.img_object($langs->trans('ShowPayment'), 'payment').' '; 518 print $langs->trans("SocialContributionPayment"); 519 print '</a>'; 520 $newline = 0; 521 } elseif ($links[$key]['type'] == 'payment_vat') { 522 $paymentvatstatic->id = $links[$key]['url_id']; 523 $paymentvatstatic->ref = $langs->trans("Payment"); 524 print ' '.$paymentvatstatic->getNomUrl(1); 525 } elseif ($links[$key]['type'] == 'payment_salary') { 526 print '<a href="'.DOL_URL_ROOT.'/salaries/card.php?id='.$links[$key]['url_id'].'">'; 527 print ' '.img_object($langs->trans('ShowPayment'), 'payment').' '; 528 print $langs->trans("Payment"); 529 print '</a>'; 530 $newline = 0; 531 } elseif ($links[$key]['type'] == 'payment_donation') { 532 $paymentdonationstatic->id = $links[$key]['url_id']; 533 $paymentdonationstatic->ref = $langs->trans("Payment"); 534 print ' '.$paymentdonationstatic->getNomUrl(1); 535 $newline = 0; 536 } elseif ($links[$key]['type'] == 'payment_loan') { 537 $paymentloanstatic->id = $links[$key]['url_id']; 538 $paymentloanstatic->ref = $langs->trans("Payment"); 539 print ' '.$paymentloanstatic->getNomUrl(1); 540 $newline = 0; 541 } elseif ($links[$key]['type'] == 'payment_various') { 542 $paymentvariousstatic->id = $links[$key]['url_id']; 543 $paymentvariousstatic->ref = $langs->trans("Payment"); 544 print ' '.$paymentvariousstatic->getNomUrl(1); 545 $newline = 0; 546 } elseif ($links[$key]['type'] == 'banktransfert') { 547 // Do not show link to transfer since there is no transfer card (avoid confusion). Can already be accessed from transaction detail. 548 if ($objp->amount > 0) { 549 $banklinestatic->fetch($links[$key]['url_id']); 550 $bankstatic->id = $banklinestatic->fk_account; 551 $bankstatic->label = $banklinestatic->bank_account_label; 552 print ' ('.$langs->trans("from").' '; 553 print $bankstatic->getNomUrl(1, 'transactions'); 554 print ' '.$langs->trans("toward").' '; 555 $bankstatic->id = $objp->bankid; 556 $bankstatic->label = $objp->bankref; 557 print $bankstatic->getNomUrl(1, ''); 558 print ')'; 559 } else { 560 $bankstatic->id = $objp->bankid; 561 $bankstatic->label = $objp->bankref; 562 print ' ('.$langs->trans("from").' '; 563 print $bankstatic->getNomUrl(1, ''); 564 print ' '.$langs->trans("toward").' '; 565 $banklinestatic->fetch($links[$key]['url_id']); 566 $bankstatic->id = $banklinestatic->fk_account; 567 $bankstatic->label = $banklinestatic->bank_account_label; 568 print $bankstatic->getNomUrl(1, 'transactions'); 569 print ')'; 570 } 571 } elseif ($links[$key]['type'] == 'company') { 572 $societestatic->id = $links[$key]['url_id']; 573 $societestatic->name = $links[$key]['label']; 574 print $societestatic->getNomUrl(1, 'company', 24); 575 $newline = 0; 576 } elseif ($links[$key]['type'] == 'member') { 577 print '<a href="'.DOL_URL_ROOT.'/adherents/card.php?rowid='.$links[$key]['url_id'].'">'; 578 print img_object($langs->trans('ShowMember'), 'user').' '; 579 print $links[$key]['label']; 580 print '</a>'; 581 $newline = 0; 582 } elseif ($links[$key]['type'] == 'user') { 583 print '<a href="'.DOL_URL_ROOT.'/user/card.php?id='.$links[$key]['url_id'].'">'; 584 print img_object($langs->trans('ShowUser'), 'user').' '; 585 print $links[$key]['label']; 586 print '</a>'; 587 $newline = 0; 588 } elseif ($links[$key]['type'] == 'sc') { 589 print '<a href="'.DOL_URL_ROOT.'/compta/sociales/card.php?id='.$links[$key]['url_id'].'">'; 590 print img_object($langs->trans('ShowBill'), 'bill').' '; 591 print $langs->trans("SocialContribution"); 592 print '</a>'; 593 $newline = 0; 594 } else { 595 print '<a href="'.$links[$key]['url'].$links[$key]['url_id'].'">'; 596 print $links[$key]['label']; 597 print '</a>'; 598 $newline = 0; 599 } 600 } 601 602 // Categories 603 if ($ve) { 604 $sql = "SELECT label"; 605 $sql .= " FROM ".MAIN_DB_PREFIX."bank_categ as ct"; 606 $sql .= ", ".MAIN_DB_PREFIX."bank_class as cl"; 607 $sql .= " WHERE ct.rowid = cl.fk_categ"; 608 $sql .= " AND ct.entity = ".((int) $conf->entity); 609 $sql .= " AND cl.lineid = ".((int) $objp->rowid); 610 611 $resc = $db->query($sql); 612 if ($resc) { 613 $numc = $db->num_rows($resc); 614 $ii = 0; 615 if ($numc && !$newline) { 616 print '<br>'; 617 } 618 while ($ii < $numc) { 619 $objc = $db->fetch_object($resc); 620 print "<br>- <i>".$objc->label."</i>"; 621 $ii++; 622 } 623 } else { 624 dol_print_error($db); 625 } 626 } 627 628 print "</td>"; 629 630 if ($objp->amount < 0) { 631 $totald = $totald + abs($objp->amount); 632 print '<td class="nowrap right">'.price($objp->amount * -1)."</td><td> </td>\n"; 633 } else { 634 $totalc = $totalc + abs($objp->amount); 635 print '<td> </td><td class="nowrap right">'.price($objp->amount)."</td>\n"; 636 } 637 638 print '<td class="nowrap right">'.price(price2num($total, 'MT'))."</td>\n"; 639 640 if ($user->rights->banque->modifier || $user->rights->banque->consolidate) { 641 print '<td class="center"><a class="editfielda reposition" href="'.DOL_URL_ROOT.'/compta/bank/line.php?rowid='.$objp->rowid.'&account='.$object->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?account='.$object->id.'&num='.$numref).'">'; 642 print img_edit(); 643 print "</a></td>"; 644 } else { 645 print "<td class=\"center\"> </td>"; 646 } 647 print "</tr>"; 648 $i++; 649 } 650 $db->free($result); 651 } 652 653 // Line Total 654 print "\n".'<tr class="liste_total"><td class="right" colspan="4">'.$langs->trans("Total")." :</td><td class=\"right\">".price($totald)."</td><td class=\"right\">".price($totalc)."</td><td> </td><td> </td></tr>"; 655 656 // Line Balance 657 print "\n<tr>"; 658 print "<td class=\"right\" colspan=\"3\"> </td><td colspan=\"3\"><b>".$langs->trans("EndBankBalance")." :</b></td>"; 659 print '<td class="right"><b>'.price(price2num($total, 'MT'))."</b></td><td> </td>"; 660 print "</tr>\n"; 661 print "</table>"; 662 663 // Code to adjust value date with plus and less picto using an Ajax call instead of a full reload of page 664 $urlajax = DOL_URL_ROOT.'/core/ajax/bankconciliate.php?token='.currentToken(); 665 print ' 666 <script type="text/javascript"> 667 $(function() { 668 $("a.ajaxforbankoperationchange").each(function(){ 669 var current = $(this); 670 current.click(function() 671 { 672 var url = "'.$urlajax.'&"+current.attr("href").split("?")[1]; 673 $.get(url, function(data) 674 { 675 console.log(url) 676 console.log(data) 677 current.parent().parent().find(".spanforajaxedit").replaceWith(data); 678 }); 679 return false; 680 }); 681 }); 682 }); 683 </script> 684 '; 685 686 print "</div>"; 687 688 print "</form>\n"; 689} 690 691// End of page 692llxFooter(); 693$db->close(); 694