2004-10-19 20:35:36 +00:00
< ? php
2003-05-16 10:48:34 +00:00
/* Copyright ( C ) 2001 - 2003 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2004-02-15 03:12:50 +00:00
* Copyright ( C ) 2004 Laurent Destailleur < eldy @ users . sourceforge . net >
2002-12-22 03:32:07 +00: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 18:53:13 +00:00
* $Id $
* $Source $
*
*/
2004-10-10 13:53:57 +00:00
/*!
\file htdocs / compta / bank / virement . php
\ingroup banque
2004-10-10 14:26:43 +00:00
\brief Page de saisie d ' un virement
2004-10-10 13:53:57 +00:00
\version $Revision $
*/
2003-09-11 20:18:51 +00:00
require ( " ./pre.inc.php " );
require ( " ./bank.lib.php " );
2002-05-11 18:53:13 +00:00
2004-06-11 00:54:19 +00:00
$user -> getrights ( 'banque' );
2003-11-21 12:35:05 +00:00
if ( ! $user -> rights -> banque -> modifier )
2003-11-05 09:59:16 +00:00
accessforbidden ();
2003-08-26 10:10:42 +00:00
llxHeader ();
2002-05-11 18:53:13 +00:00
2004-10-10 13:53:57 +00:00
/*
* Action ajout d ' un virement
*/
if ( $_POST [ " action " ] == 'add' )
2002-12-22 03:32:07 +00:00
{
2004-06-11 00:54:19 +00:00
$mesg = '' ;
2004-10-10 13:53:57 +00:00
$dateo = $_POST [ " reyear " ] . " - " . $_POST [ " remonth " ] . " - " . $_POST [ " reday " ];
2004-06-11 00:54:19 +00:00
$label = $_POST [ " label " ];
$amount = $_POST [ " amount " ];
if ( $label && $amount ) {
2002-05-11 18:53:13 +00:00
2004-06-11 00:54:19 +00:00
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " bank (datec, datev, dateo, label, amount, fk_user_author,fk_account, fk_type) " ;
2004-10-10 14:26:43 +00:00
$sql .= " VALUES (now(), ' $dateo ', ' $dateo ', ' $label ', (0 - $amount ), $user->id , " . $_POST [ " account_from " ] . " , 'VIR') " ;
2004-06-11 00:54:19 +00:00
$result = $db -> query ( $sql );
if ( ! $result )
{
2004-10-10 13:53:57 +00:00
dolibarr_print_error ( $db );
2004-06-11 00:54:19 +00:00
}
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " bank (datec, datev, dateo, label, amount, fk_user_author,fk_account, fk_type) " ;
2004-10-10 14:26:43 +00:00
$sql .= " VALUES (now(), ' $dateo ', ' $dateo ', ' $label ', $amount , $user->id , " . $_POST [ " account_to " ] . " , 'VIR') " ;
2004-06-11 00:54:19 +00:00
$result = $db -> query ( $sql );
if ( $result )
{
2004-10-10 13:53:57 +00:00
$accountfrom = new Account ( $db );
$accountfrom -> fetch ( $_POST [ " account_from " ]);
$accountto = new Account ( $db );
$accountto -> fetch ( $_POST [ " account_to " ]);
2004-12-04 20:19:53 +00:00
$mesg .= " <div class= \" ok \" ><b>Votre virement entre <a href= \" account.php?account= " . $accountfrom -> id . " \" > " . $accountfrom -> label . " </a> et <a href= \" account.php?account= " . $accountto -> id . " \" > " . $accountto -> label . " </a> de " . $amount . " " . $conf -> monnaie . " a <20> t<EFBFBD> cr<63> e.</b></div> " ;
2004-06-11 00:54:19 +00:00
}
else {
2004-10-10 13:53:57 +00:00
dolibarr_print_error ( $db );
2004-06-11 00:54:19 +00:00
}
} else {
$mesg .= " <div class= \" error \" ><b>Un libell<6C> de virement et un montant non nul est obligatoire.</b></div> " ;
}
}
2002-06-20 13:23:17 +00:00
2004-06-11 00:54:19 +00:00
print_titre ( " Virement inter-compte " );
print '<br>' ;
2002-06-20 13:23:17 +00:00
2004-06-11 00:54:19 +00:00
if ( $mesg ) {
2004-10-10 13:53:57 +00:00
print " $mesg <br> " ;
2002-05-11 18:53:13 +00:00
}
2004-06-11 00:54:19 +00:00
print " En saisissant un virement d'un de vos comptes bancaire vers un autre, Dolibarr cr<63> e deux <20> critures comptables (une de d<> bit dans un compte et l'autre de cr<63> dit, du m<> me montant, dans l'autre compte. Le m<> me libell<6C> de transaction, et la m<> me date, sont utilis<69> s pour les 2 <20> critures)<br><br> " ;
2002-05-11 18:53:13 +00:00
2004-07-30 10:32:27 +00:00
print " <form method= \" post \" action= \" virement.php \" > " ;
2002-05-11 18:53:13 +00:00
2003-05-16 10:48:34 +00:00
print '<input type="hidden" name="action" value="add">' ;
2002-05-11 18:53:13 +00:00
2004-10-10 13:53:57 +00:00
print '<table class="noborder" width="100%">' ;
2004-02-15 03:05:16 +00:00
print '<tr class="liste_titre">' ;
2004-10-10 13:53:57 +00:00
print '<td>' . $langs -> trans ( " From " ) . '</td><td>' . $langs -> trans ( " To " ) . '</td><td>' . $langs -> trans ( " Date " ) . '</td><td>' . $langs -> trans ( " Description " ) . '</td><td>' . $langs -> trans ( " Amount " ) . '</td>' ;
2004-02-15 03:05:16 +00:00
print '</tr>' ;
2003-09-13 13:39:12 +00:00
print " <tr $bc[1] ><td> " ;
2002-06-20 13:23:17 +00:00
print " <select name= \" account_from \" > " ;
2004-02-01 01:50:21 +00:00
$sql = " SELECT rowid, label FROM " . MAIN_DB_PREFIX . " bank_account " ;
2002-05-11 18:53:13 +00:00
$result = $db -> query ( $sql );
2002-12-22 03:32:07 +00:00
if ( $result )
{
2002-05-11 18:53:13 +00:00
$var = True ;
$num = $db -> num_rows ();
$i = 0 ; $total = 0 ;
2002-12-22 03:32:07 +00:00
while ( $i < $num )
{
2004-10-23 16:55:07 +00:00
$objp = $db -> fetch_object ( $result );
2003-10-21 14:12:44 +00:00
print " <option value= \" $objp->rowid\ " > $objp -> label </ option > " ;
2002-12-22 03:32:07 +00:00
$i ++ ;
}
2002-05-11 18:53:13 +00:00
}
2003-05-16 10:48:34 +00:00
print " </select></td><td> \n " ;
2002-05-11 18:53:13 +00:00
2002-06-20 13:23:17 +00:00
print " <select name= \" account_to \" > " ;
2004-02-01 01:50:21 +00:00
$sql = " SELECT rowid, label FROM " . MAIN_DB_PREFIX . " bank_account " ;
2002-05-11 18:53:13 +00:00
$result = $db -> query ( $sql );
2002-12-22 03:32:07 +00:00
if ( $result )
{
2002-05-11 18:53:13 +00:00
$var = True ;
$num = $db -> num_rows ();
$i = 0 ; $total = 0 ;
2002-12-22 03:32:07 +00:00
while ( $i < $num )
{
2004-10-23 16:55:07 +00:00
$objp = $db -> fetch_object ( $result );
2003-11-05 09:59:16 +00:00
print " <option value= \" $objp->rowid\ " > $objp -> label </ option > " ;
2002-12-22 03:32:07 +00:00
$i ++ ;
}
2002-05-11 18:53:13 +00:00
}
2003-05-16 10:48:34 +00:00
print " </select></td> \n " ;
2002-05-11 18:53:13 +00:00
2003-05-16 10:48:34 +00:00
print " <td> " ;
print_date_select ();
print " </td> \n " ;
2003-10-21 14:12:44 +00:00
print '<td><input name="label" type="text" size="40"></td>' ;
print '<td><input name="amount" type="text" size="8"></td>' ;
2003-05-16 10:48:34 +00:00
2004-10-10 13:53:57 +00:00
print " </table> " ;
print '<p align="center"><input type="submit" value="' . $langs -> trans ( " Add " ) . '"</p>' ;
2002-05-11 18:53:13 +00:00
2004-10-10 13:53:57 +00:00
print " </form> " ;
2002-05-11 18:53:13 +00:00
$db -> close ();
2002-12-22 03:32:07 +00:00
llxFooter ( " - <em>Dernière modification $Date $ révision $Revision $ </em> " );
2002-05-11 18:53:13 +00:00
?>