| [ Index ] |
|
Code source de Dolibarr 2.0.1 |
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-2005 Laurent Destailleur <eldy@users.sourceforge.net> 5 * Copytight (C) 2004 Christophe Combelles <ccomb@free.fr> 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation; either version 2 of the License, or 10 * (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 * 21 * $Id: account.php,v 1.63 2005/10/15 16:01:56 eldy Exp $ 22 * $Source: /cvsroot/dolibarr/dolibarr/htdocs/compta/bank/account.php,v $ 23 */ 24 25 /** 26 \file htdocs/compta/bank/account.php 27 \ingroup banque 28 \brief Page de détail des transactions bancaires 29 \version $Revision: 1.63 $ 30 */ 31 32 require ("./pre.inc.php"); 33 34 if (!$user->rights->banque->lire) 35 accessforbidden(); 36 37 $langs->load("bills"); 38 39 40 $account=isset($_GET["account"])?$_GET["account"]:$_POST["account"]; 41 $vline=isset($_GET["vline"])?$_GET["vline"]:$_POST["vline"]; 42 $action=isset($_GET["action"])?$_GET["action"]:$_POST["action"]; 43 $page=isset($_GET["page"])?$_GET["page"]:0; 44 45 if ($_POST["action"] == 'add' && $account && ! isset($_POST["cancel"])) 46 { 47 if ($_POST["credit"] > 0) 48 { 49 $amount = $_POST["credit"]; 50 } 51 else 52 { 53 $amount = - $_POST["debit"]; 54 } 55 56 $dateop = $_POST["dateoy"].$_POST["dateo"]; 57 $operation=$_POST["operation"]; 58 $label=$_POST["label"]; 59 $operation=$_POST["operation"]; 60 $num_chq=$_POST["num_chq"]; 61 $cat1=$_POST["cat1"]; 62 63 $acct=new Account($db,$account); 64 65 $insertid = $acct->addline($dateop, $operation, $label, $amount, $num_chq, $cat1); 66 67 if ($insertid) 68 { 69 Header("Location: account.php?account=" . $account); 70 } 71 else 72 { 73 dolibarr_print_error($db); 74 } 75 } 76 if ($_GET["action"] == 'del' && $account && $user->rights->banque->modifier) 77 { 78 $acct=new Account($db,$account); 79 $acct->deleteline($_GET["rowid"]); 80 } 81 82 83 84 llxHeader(); 85 86 if ($account > 0) 87 { 88 if ($vline) 89 { 90 $viewline = $vline; 91 } 92 else 93 { 94 $viewline = 20; 95 } 96 $acct = new Account($db); 97 $acct->fetch($account); 98 99 // Chargement des categories dans $options 100 $nbcategories=0; 101 $sql = "SELECT rowid, label FROM ".MAIN_DB_PREFIX."bank_categ;"; 102 $result = $db->query($sql); 103 if ($result) 104 { 105 $var=True; 106 $num = $db->num_rows($result); 107 $i = 0; 108 $options = "<option value=\"0\" selected=\"true\"> </option>"; 109 while ($i < $num) 110 { 111 $obj = $db->fetch_object($result); 112 $options .= "<option value=\"$obj->rowid\">$obj->label</option>\n"; 113 $nbcategories++; 114 $i++; 115 } 116 $db->free($result); 117 } 118 119 /* 120 * 121 * 122 */ 123 $sql = "SELECT count(*) as nb FROM ".MAIN_DB_PREFIX."bank as b"; 124 $sql .= " WHERE b.fk_account=".$acct->id; 125 $sql_rech=""; 126 if ($_POST["req_desc"]) 127 { 128 $sql_rech .= " AND b.label like '%".strtolower($_POST["req_desc"])."%'"; 129 $mode_search = 1; 130 } 131 else 132 { 133 $mode_search = 0; 134 } 135 if ($_POST["req_debit"]) $sql_rech.=" AND amount = -".$_POST["req_debit"]; 136 if ($_POST["req_credit"]) $sql_rech.=" AND amount = ".$_POST["req_credit"]; 137 138 $sql .= $sql_rech; 139 $result=$db->query($sql); 140 if ($result) 141 { 142 $obj = $db->fetch_object($result); 143 $nbline = $obj->nb; 144 $total_lines = $nbline; 145 146 if ($nbline > $viewline ) 147 { 148 $limit = $nbline - $viewline ; 149 } 150 else 151 { 152 $limit = $viewline; 153 } 154 155 $db->free($result); 156 } 157 else { 158 dolibarr_print_error($db); 159 } 160 161 if ($page > 0 && $mode_search == 0) 162 { 163 $limitsql = $nbline - ($page * $viewline); 164 if ($limitsql < $viewline) 165 { 166 $limitsql = $viewline; 167 } 168 $nbline = $limitsql; 169 } 170 else 171 { 172 $page = 0; 173 $limitsql = $nbline; 174 } 175 176 /** 177 * Formulaire de recherche 178 * 179 */ 180 $mesg=''; 181 182 $nbpage=floor($total_lines/$viewline)+($total_lines % $viewline > 0?1:0); // Nombre de page total 183 if ($limitsql > $viewline) 184 { 185 $mesg.='<a href="account.php?account='.$acct->id.'&page='.($page+1).'">'.img_previous().'</a>'; 186 } 187 $mesg.= ' Page '.($nbpage-$page).'/'.$nbpage.' '; 188 if ($total_lines > $limitsql ) 189 { 190 $mesg.= '<a href="account.php?account='.$acct->id.'&page='.($page-1).'">'.img_next().'</a>'; 191 } 192 193 194 print_fiche_titre("Journal de trésorerie du compte : " .$acct->label,$mesg); 195 196 print '<br>'; 197 print '<table class="notopnoleftnoright" width="100%">'; 198 199 /* 200 * Affiche tableau des transactions bancaires 201 * 202 */ 203 204 // Formulaire de saisie d'une opération hors factures 205 if ($user->rights->banque->modifier && $_GET["action"]=='rappro') 206 { 207 $html=new Form($db); 208 209 print '<form method="post" action="account.php">'; 210 print '<input type="hidden" name="action" value="add">'; 211 print '<input type="hidden" name="vline" value="' . $vline . '">'; 212 print '<input type="hidden" name="account" value="' . $acct->id . '">'; 213 214 print '<tr>'; 215 print '<td align="left" colspan="8"><b>'.$langs->trans("AddBankRecordLong").'</b></td>'; 216 print '</tr>'; 217 218 print '<tr class="liste_titre">'; 219 print '<td><small>YYYY MMDD</small></td><td colspan="2">'.$langs->trans("Type").'</td><td>'.$langs->trans("Description").'</td><td align=right>'.$langs->trans("Debit").'</td><td align=right>'.$langs->trans("Credit").'</td>'; 220 print '<td colspan="2" align="center"> '; 221 print '</td></tr>'; 222 223 print '<tr '.$bc[false].'>'; 224 print '<td nowrap>'; 225 print '<input name="dateoy" class="flat" type="text" size="2" value="'.strftime("%Y",time()).'" maxlength="4">'; 226 print '<input name="dateo" class="flat" type="text" size="2" maxlength="4"></td>'; 227 print '<td colspan="2" nowrap>'; 228 $html->select_types_paiements('','operation','1,2',1); 229 print '<input name="num_chq" class="flat" type="text" size="4"></td>'; 230 print '<td>'; 231 print '<input name="label" class="flat" type="text" size="40">'; 232 if ($nbcategories) 233 { 234 print '<br>'.$langs->trans("Category").': <select class="flat" name="cat1">'.$options.'</select>'; 235 } 236 print '</td>'; 237 print '<td align=right><input name="debit" class="flat" type="text" size="6"></td>'; 238 print '<td align=right><input name="credit" class="flat" type="text" size="6"></td>'; 239 print '<td colspan="2" align="center">'; 240 print '<input type="submit" name="save" class="button" value="'.$langs->trans("Add").'"><br>'; 241 print '<input type="submit" name="cancel" class="button" value="'.$langs->trans("Cancel").'">'; 242 print '</td></tr>'; 243 print "</form>"; 244 245 print "<tr class=\"noborder\"><td colspan=\"8\"> </td></tr>\n"; 246 } 247 248 // Ligne de titre tableau des acritures 249 print '<tr class="liste_titre">'; 250 print '<td>'.$langs->trans("Date").'</td><td>'.$langs->trans("Value").'</td><td>'.$langs->trans("Type").'</td><td>'.$langs->trans("Description").'</td>'; 251 print '<td align="right">'.$langs->trans("Debit").'</td><td align="right">'.$langs->trans("Credit").'</td>'; 252 print '<td align="right" width="80">'.$langs->trans("BankBalance").'</td>'; 253 print '<td align="center" width="60">'; 254 if ($acct->type != 2 && $acct->rappro) print $langs->trans("AccountStatementShort"); 255 else print ' '; 256 print '</td></tr>'; 257 258 print '<form method="post" action="account.php">'; 259 print '<input type="hidden" name="action" value="search">'; 260 print '<input type="hidden" name="account" value="' . $acct->id . '">'; 261 262 print '<tr class="liste_titre">'; 263 print '<td colspan="3"><a href="graph.php?id='.$acct->id.'">Graph</a></td>'; 264 print '<td><input type="text" class="flat" name="req_desc" value="'.$_POST["req_desc"].'" size="40"></td>'; 265 print '<td align="right"><input type="text" class="flat" name="req_debit" value="'.$_POST["req_debit"].'" size="6"></td>'; 266 print '<td align="right"><input type="text" class="flat" name="req_credit" value="'.$_POST["req_credit"].'" size="6"></td>'; 267 print '<td align="center"> </td>'; 268 print '<td align="center" width="40"><input type="image" class="liste_titre" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/search.png" alt="'.$langs->trans("Search").'"></td>'; 269 print "</tr>\n"; 270 print "</form>\n"; 271 272 /* Another solution 273 * create temporary table solde type=heap select amount from llx_bank limit 100 ; 274 * select sum(amount) from solde ; 275 */ 276 277 $sql = "SELECT b.rowid,".$db->pdate("b.dateo")." as do,".$db->pdate("b.datev")." as dv, b.amount, b.label, b.rappro, b.num_releve, b.num_chq, b.fk_type"; 278 $sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; 279 $sql.= " WHERE fk_account=".$acct->id; 280 if ($req_debit) $sql .= " AND b.amount = -".$req_debit; 281 if ($req_credit) $sql .= " AND b.amount = ".$req_credit; 282 $sql.= $sql_rech; 283 if ($vue) 284 { 285 if ($vue == 'credit') 286 { 287 $sql .= " AND b.amount >= 0 "; 288 } 289 else 290 { 291 $sql .= " AND b.amount < 0 "; 292 } 293 } 294 $sql.= " ORDER BY b.datev ASC"; 295 $sql.= $db->plimit($limitsql, 0); 296 297 $result = $db->query($sql); 298 if ($result) 299 { 300 $total = _print_lines($db, $result, $sql, $acct); 301 if ($page == 0) 302 { 303 print '<tr class="liste_total"><td align="right" colspan="6">'.$langs->trans("Balance").'</td>'; 304 print '<td align="right" nowrap>'.price($total).'</td>'; 305 print '<td> </td>'; 306 print '</tr>'; 307 } 308 $db->free($result); 309 } 310 311 312 print "</table>"; 313 314 315 /* 316 * Boutons actions 317 */ 318 if ($_GET["action"] != 'rappro') 319 { 320 print '<div class="tabsAction">'; 321 322 if ($user->rights->banque->modifier && $acct->type != 2 && $acct->rappro) // Si non compte cash et rapprochable 323 { 324 print '<a class="tabAction" href="rappro.php?account='.$acct->id.'">'.$langs->trans("Conciliate").'</a>'; 325 } 326 327 if ($user->rights->banque->modifier) 328 { 329 print '<a class="tabAction" href="account.php?action=rappro&account='.$acct->id.'&page='.$page.'">'.$langs->trans("AddBankRecord").'</a>'; 330 } 331 332 print '</div>'; 333 } 334 335 print '<br>'; 336 337 } 338 else 339 { 340 print $langs->trans("ErrorBankAccountNotFound"); 341 } 342 343 $db->close(); 344 345 llxFooter('$Date: 2005/10/15 16:01:56 $ - $Revision: 1.63 $'); 346 347 348 /** 349 * \brief Affiche ligne ecriture 350 * \param db Handler d'accès base 351 * \param result Resultset du select 352 * \param sql Requete sql 353 * \param acct Compte 354 * \return Renvoi total solde 355 */ 356 function _print_lines($db,$result,$sql,$acct) 357 { 358 global $langs, $bc, $nbline, $viewline, $user, $page; 359 360 $var=true; 361 $total=0; 362 363 $num = $db->num_rows($result); 364 $i = 0; $total = 0; $sep = 0; 365 366 while ($i < $num) 367 { 368 $objp = $db->fetch_object($result); 369 $total = $total + $objp->amount; 370 $time = time(); 371 if ($i >= ($nbline - $viewline)) 372 { 373 $var=!$var; 374 375 if ($objp->do > $time && !$sep) 376 { 377 $sep = 1 ; 378 print "<tr><td align=\"right\" colspan=\"6\"> </td>"; 379 print "<td align=\"right\" nowrap><b>".price($total - $objp->amount)."</b></td>"; 380 print "<td> </td>"; 381 print '</tr>'; 382 } 383 384 print "<tr $bc[$var]>"; 385 print "<td nowrap>".dolibarr_print_date($objp->do,"%d/%m/%y")."</td>\n"; 386 print "<td nowrap> ".dolibarr_print_date($objp->dv,"%d/%m/%y")."</td>\n"; 387 print "<td nowrap> ".$objp->fk_type." ".($objp->num_chq?$objp->num_chq:"")."</td>\n"; 388 print '<td><a href="ligne.php?rowid='.$objp->rowid.'&account='.$acct->id.'">'.$objp->label.'</a>'; 389 390 /* 391 * Ajout les liens 392 */ 393 $links = $acct->get_url($objp->rowid); 394 foreach($links as $key=>$val) 395 { 396 print ' - '; 397 print '<a href="'.$links[$key]['url'].$links[$key]['url_id'].'">'; 398 if ($links[$key]['type']=='payment') { 399 //print img_object($langs->trans('ShowPayment'),'payment').' '; 400 print $langs->trans("Payment"); 401 } 402 else if ($links[$key]['type']=='company') { 403 //print img_object($langs->trans('ShowCustomer'),'company').' '; 404 print $links[$key]['label']; 405 } 406 else print $links[$key]['label']; 407 print '</a>'; 408 } 409 print '</td>'; 410 411 if ($objp->amount < 0) 412 { 413 print "<td align=\"right\" nowrap>".price($objp->amount * -1)."</td><td> </td>\n"; 414 } 415 else 416 { 417 print "<td> </td><td align=\"right\" nowrap> ".price($objp->amount)."</td>\n"; 418 } 419 420 if ($action !='search') 421 { 422 if ($total >= 0) 423 { 424 print '<td align="right" nowrap> '.price($total).'</td>'; 425 } 426 else 427 { 428 print '<td align="right" class="error" nowrap> '.price($total).'</td>'; 429 } 430 } 431 else 432 { 433 print '<td align="right">-</td>'; 434 } 435 436 // Relevé rappro ou lien edition 437 if ($objp->rappro && $acct->type != 2) // Si non compte cash 438 { 439 print "<td align=\"center\" nowrap> "; 440 print "<a href=\"releve.php?num=$objp->num_releve&account=$acct->id\">$objp->num_releve</a>"; 441 print "</td>"; 442 } 443 else 444 { 445 if ($user->rights->banque->modifier) 446 { 447 print '<td align="center">'; 448 print '<a href="'.DOL_URL_ROOT.'/compta/bank/ligne.php?rowid='.$objp->rowid.'&account='.$acct->id.'&page='.$page.'">'; 449 print img_edit(); 450 print '</a> '; 451 print '<a href="account.php?action=del&rowid='.$objp->rowid.'&account='.$acct->id.'&page='.$page.'">'; 452 print img_delete(); 453 print '</a></td>'; 454 } 455 else 456 { 457 print "<td align=\"center\"> </td>"; 458 } 459 } 460 461 print "</tr>"; 462 463 } 464 465 $i++; 466 } 467 468 return $total; 469 } 470 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Mon Nov 26 12:29:37 2007 | par Balluche grâce à PHPXref 0.7 |
|