2004-10-19 22:35:36 +02:00
< ? php
2003-03-18 16:15:23 +01:00
/* Copyright ( C ) 2001 - 2003 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2004-01-28 23:23:34 +01:00
* Copyright ( C ) 2004 Laurent Destailleur < eldy @ users . sourceforge . net >
2002-06-18 18:36:02 +02:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 2 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software
* Foundation , Inc . , 59 Temple Place - Suite 330 , Boston , MA 02111 - 1307 , USA .
*
2002-05-11 20:53:13 +02:00
* $Id $
* $Source $
*/
2004-10-09 15:53:14 +02:00
/*! \file htdocs / compta / bank / rappro . php
\ingroup banque
\brief Page de rapprochement bancaire
\version $Revision $
*/
2003-09-11 22:18:51 +02:00
require ( " ./pre.inc.php " );
2002-05-11 20:53:13 +02:00
2003-11-05 10:59:16 +01:00
$user -> getrights ( 'compta' );
2004-12-22 23:43:44 +01:00
if ( ! $user -> rights -> banque -> modifier )
2003-11-05 10:59:16 +01:00
accessforbidden ();
2004-10-09 15:53:14 +02:00
2002-05-11 20:53:13 +02:00
llxHeader ();
2004-10-09 15:53:14 +02:00
2004-06-05 01:09:27 +02:00
/*
* Action rapprochement
*/
2004-08-03 22:16:27 +02:00
if ( $_POST [ " action " ] == 'rappro' )
2003-08-26 12:10:42 +02:00
{
2004-08-03 22:16:27 +02:00
if ( $_POST [ " num_releve " ] > 0 ) {
2004-10-09 15:53:14 +02:00
$valrappro = 1 ;
2004-08-03 22:16:27 +02:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " bank set rappro= $valrappro , num_releve= " . $_POST [ " num_releve " ];
if ( $_POST [ " rappro " ]) {
2004-06-05 01:09:27 +02:00
# Si on fait un rapprochement, le user de rapprochement est inclus dans l'update
$sql .= " , fk_user_rappro= " . $user -> id ;
}
2004-08-03 22:16:27 +02:00
$sql .= " WHERE rowid= " . $_POST [ " rowid " ];
2002-05-11 20:53:13 +02:00
$result = $db -> query ( $sql );
2004-08-03 22:16:27 +02:00
2002-05-11 20:53:13 +02:00
if ( $result ) {
2004-08-03 22:16:27 +02:00
if ( $cat1 && $_POST [ " action " ]) {
2004-10-09 15:53:14 +02:00
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " bank_class (lineid, fk_categ) VALUES ( $rowid , $cat1 ) " ;
$result = $db -> query ( $sql );
2002-05-11 20:53:13 +02:00
}
} else {
2004-08-03 22:16:27 +02:00
print dolibarr_print_error ( $db , $sql );
2002-05-11 20:53:13 +02:00
}
}
2004-10-09 15:53:14 +02:00
else {
$msg = " Erreur: Saisissez le relev<65> qui r<> f<EFBFBD> rence la transaction pour la rapprocher. " ;
}
2002-05-11 20:53:13 +02:00
}
2004-06-05 01:09:27 +02:00
/*
* Action suppression ecriture
*/
2004-08-03 22:16:27 +02:00
if ( $_GET [ " action " ] == 'del' ) {
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " bank WHERE rowid= " . $_GET [ " rowid " ];
2002-05-11 20:53:13 +02:00
$result = $db -> query ( $sql );
if ( ! $result ) {
2004-08-03 22:16:27 +02:00
print dolibarr_print_error ( $db , $sql );
2002-05-11 20:53:13 +02:00
}
}
2004-08-03 22:16:27 +02:00
$sql = " SELECT rowid, label FROM " . MAIN_DB_PREFIX . " bank_categ ORDER BY label " ;
2002-05-11 20:53:13 +02:00
$result = $db -> query ( $sql );
2004-02-15 19:40:50 +01:00
$options = " " ;
2002-05-11 20:53:13 +02:00
if ( $result ) {
$var = True ;
$num = $db -> num_rows ();
$i = 0 ;
while ( $i < $num ) {
2004-02-15 19:40:50 +01:00
if ( $options == " " ) { $options = " <option value= \" 0 \" selected> </option> " ; }
2004-10-23 18:55:07 +02:00
$obj = $db -> fetch_object ( $result );
2002-05-11 20:53:13 +02:00
$options .= " <option value= \" $obj->rowid\ " > $obj -> label </ option > \n " ; $i ++;
}
$db -> free ();
}
2004-06-05 01:09:27 +02:00
2004-10-09 15:53:14 +02:00
// Recup<75> re nom du dernier relev<65>
2004-08-03 22:16:27 +02:00
$sql = " SELECT max(num_releve) FROM " . MAIN_DB_PREFIX . " bank WHERE fk_account= " . $_GET [ " account " ];
2003-10-20 18:53:09 +02:00
if ( $db -> query ( $sql ) )
{
if ( $db -> num_rows () )
{
$last_releve = $db -> result ( 0 , 0 );
}
2002-05-11 20:53:13 +02:00
$db -> free ();
2003-10-20 18:53:09 +02:00
}
else
{
2004-10-09 15:53:14 +02:00
dolibarr_print_error ( $db );
2003-10-20 18:53:09 +02:00
}
2004-10-09 15:53:14 +02:00
/*
* Affichage liste des transactions <EFBFBD> rapprocher
*/
2003-10-20 18:53:09 +02:00
$acct = new Account ( $db );
2004-08-03 22:16:27 +02:00
$acct -> fetch ( $_GET [ " account " ]);
2002-05-11 20:53:13 +02:00
2004-10-09 15:53:14 +02:00
$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 as type " ;
2004-08-03 22:16:27 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " bank as b WHERE rappro=0 AND fk_account= " . $_GET [ " account " ];
2004-10-09 15:53:14 +02:00
$sql .= " ORDER BY dateo " ;
$sql .= " ASC LIMIT " . $conf -> liste_limit ;
2002-06-18 19:05:10 +02:00
2002-05-11 20:53:13 +02:00
$result = $db -> query ( $sql );
2003-03-18 16:15:23 +01:00
if ( $result )
{
2002-05-11 20:53:13 +02:00
$var = True ;
$num = $db -> num_rows ();
2004-01-28 23:23:34 +01:00
if ( $num == 0 ) {
2004-10-09 15:53:14 +02:00
header ( " Location: /compta/bank/account.php?account= " . $_GET [ " account " ]);
2004-06-13 22:56:04 +02:00
exit ;
2004-01-28 23:23:34 +01:00
}
else {
2004-06-13 22:56:04 +02:00
2004-10-09 15:53:14 +02:00
print_titre ( 'Rapprochement compte bancaire: <a href="account.php?account=' . $_GET [ " account " ] . '">' . $acct -> label . '</a>' );
2004-06-13 22:56:04 +02:00
print '<br>' ;
2004-10-09 15:53:14 +02:00
if ( $msg ) {
print " $msg <br><br> " ;
}
print '<table class="noborder" width="100%">' ;
2004-02-15 19:40:50 +01:00
print " <tr class= \" liste_titre \" > " ;
2004-10-09 15:53:14 +02:00
print '<td>Date Ope</td>' ;
print '<td>Date Valeur</td>' ;
print '<td>' . $langs -> trans ( " Type " ) . '</td>' ;
print '<td>' . $langs -> trans ( " Description " ) . '</td>' ;
print '<td align="right">Debit</td>' ;
print '<td align="right">Credit</td>' ;
print '<td align="center" width="100">Releve<br>(Ex: YYYYMM)</td>' ;
print '<td align="center" width="100" colspan="2">' . $langs -> trans ( " Action " ) . '</td>' ;
2004-02-15 19:40:50 +01:00
print " </tr> \n " ;
2004-01-28 23:23:34 +01:00
}
2003-10-14 18:00:12 +02:00
$i = 0 ;
2003-03-18 16:15:23 +01:00
while ( $i < $num )
{
2004-10-23 18:55:07 +02:00
$objp = $db -> fetch_object ();
2002-05-11 20:53:13 +02:00
2003-03-18 16:15:23 +01:00
$var =! $var ;
print " <tr $bc[$var] > " ;
2004-08-03 22:16:27 +02:00
print '<form method="post" action="rappro.php?account=' . $_GET [ " account " ] . '">' ;
2003-03-18 16:15:23 +01:00
print " <input type= \" hidden \" name= \" action \" value= \" rappro \" > " ;
2004-08-03 22:16:27 +02:00
print " <input type= \" hidden \" name= \" account \" value= \" " . $_GET [ " account " ] . " \" > " ;
print " <input type= \" hidden \" name= \" rowid \" value= \" " . $objp -> rowid . " \" > " ;
2003-03-18 16:15:23 +01:00
2004-10-09 15:53:14 +02:00
print '<td>' . dolibarr_print_date ( $objp -> do ) . '</td>' ;
print '<td>' . dolibarr_print_date ( $objp -> dv ) . '</td>' ;
print '<td>' . $objp -> type . ( $objp -> num_chq ? ' ' . $objp -> num_chq : '' ) . '</td>' ;
print '<td>' . $objp -> label . '</td>' ;
2002-05-11 20:53:13 +02:00
2003-03-18 16:15:23 +01:00
if ( $objp -> amount < 0 )
{
2004-08-03 22:16:27 +02:00
print " <td align= \" right \" > " . price ( $objp -> amount * - 1 ) . " </td><td> </td> \n " ;
2003-03-18 16:15:23 +01:00
}
else
{
2004-10-09 15:53:14 +02:00
print " <td> </td><td align= \" right \" > " . price ( $objp -> amount ) . " </td> \n " ;
2003-03-18 16:15:23 +01:00
}
2002-05-11 20:53:13 +02:00
2004-02-15 19:40:50 +01:00
if ( $objp -> do <= mktime () ) {
print " <td align= \" center \" > " ;
2004-10-09 15:53:14 +02:00
print " <input name= \" num_releve \" type= \" text \" value= \" \" size= \" 8 \" > " ;
if ( $options ) {
print " <br><select name= \" cat1 \" > $options " ;
print " </select> " ;
}
2004-08-03 22:16:27 +02:00
print " </td> " ;
2004-10-09 15:53:14 +02:00
print " <td align= \" center \" ><input type= \" submit \" value= \" " . $langs -> trans ( " Rapprocher " ) . " \" > " ;
print " </td> " ;
2004-02-15 19:40:50 +01:00
}
else {
2004-10-09 15:53:14 +02:00
print " <td align= \" left \" colspan= \" 2 \" > " ;
2004-02-15 19:40:50 +01:00
print " Ecriture future. Ne peut pas encore <20> tre rapproch<63> e. " ;
print " </td> " ;
}
2003-03-18 16:15:23 +01:00
if ( $objp -> rappro )
{
2004-01-28 23:23:34 +01:00
print " <td align= \" center \" ><a href= \" releve.php?num= $objp->num_releve &account= $acct->id\ " > $objp -> num_releve </ a ></ td > " ;
2003-03-18 16:15:23 +01:00
}
else
{
2004-01-28 23:23:34 +01:00
if ( $user -> rights -> banque -> modifier )
{
2004-10-09 15:53:14 +02:00
print '<td align="center" width="30">' ;
2004-02-15 19:40:50 +01:00
if ( $objp -> do <= mktime () ) {
2004-07-30 12:32:27 +02:00
print " <a href= \" rappro.php?action=del&rowid= $objp->rowid &account= $acct->id\ " > " ;
2004-02-15 19:40:50 +01:00
print img_delete ();
print " </a> " ;
}
else {
print " " ; // On n'empeche la suppression car le raprochement ne pourra se faire qu'apr<70> s la date pass<73> e et que l'<27> criture apparaissent bien sur le compte.
}
print " </td> " ;
2004-01-28 23:23:34 +01:00
}
else
{
print " <td align= \" center \" > </td> " ;
}
2003-03-18 16:15:23 +01:00
}
2004-01-28 23:23:34 +01:00
2003-03-18 16:15:23 +01:00
print " </tr> " ;
2004-10-09 15:53:14 +02:00
2003-03-18 16:15:23 +01:00
print " </form> " ;
$i ++ ;
2002-05-11 20:53:13 +02:00
}
$db -> free ();
2004-01-28 23:23:34 +01:00
if ( $num != 0 ) {
print " </table> " ;
}
2004-06-13 22:56:04 +02:00
} else {
2004-10-09 15:53:14 +02:00
dolibarr_print_error ( $db );
2002-05-11 20:53:13 +02:00
}
2004-08-03 22:16:27 +02:00
print '<br>Dernier relev<65> : <a href="releve.php?account=' . $_GET [ " account " ] . '&num=' . $last_releve . '">' . $last_releve . '</a>' ;
2003-03-18 16:15:23 +01:00
2002-05-11 20:53:13 +02:00
$db -> close ();
llxFooter ( " <em>Dernière modification $Date $ révision $Revision $ </em> " );
?>