2004-10-19 20:35:36 +00:00
< ? php
2005-01-11 20:29:43 +00:00
/* Copyright ( C ) 2004 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2008-04-03 20:43:12 +00:00
* Copyright ( C ) 2004 - 2008 Laurent Destailleur < eldy @ users . sourceforge . net >
2005-10-05 01:48:00 +00:00
* Copyright ( C ) 2005 Marc Barilley / Ocebo < marc @ ocebo . com >
2004-01-31 17:29:54 +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 .
*/
2004-09-14 20:46:09 +00:00
2005-04-15 21:49:23 +00:00
/**
\file htdocs / compta / paiement / fiche . php
2004-09-14 20:46:09 +00:00
\ingroup facture
2006-04-08 12:52:30 +00:00
\brief Onglet paiement d ' un paiement client
\remarks Fichier presque identique a fournisseur / paiement / fiche . php
2008-04-03 20:43:12 +00:00
\version $Id $
2004-09-14 20:46:09 +00:00
*/
2005-10-05 01:48:00 +00:00
require ( './pre.inc.php' );
require_once ( DOL_DOCUMENT_ROOT . '/paiement.class.php' );
require_once ( DOL_DOCUMENT_ROOT . '/facture.class.php' );
2006-09-13 07:48:41 +00:00
require_once ( DOL_DOCUMENT_ROOT . " /includes/modules/facture/modules_facture.php " );
2005-11-19 17:43:13 +00:00
if ( $conf -> banque -> enabled ) require_once ( DOL_DOCUMENT_ROOT . '/compta/bank/account.class.php' );
2004-01-31 17:29:54 +00:00
2005-10-05 01:48:00 +00:00
$langs -> load ( 'bills' );
$langs -> load ( 'banks' );
$langs -> load ( 'companies' );
2004-09-14 20:46:09 +00:00
2005-10-15 18:28:21 +00:00
$mesg = '' ;
2005-01-11 20:29:43 +00:00
2005-10-15 18:28:21 +00:00
/*
* Actions
*/
2007-02-04 21:23:58 +00:00
if ( $_POST [ 'action' ] == 'confirm_delete' && $_POST [ 'confirm' ] == 'yes' && $user -> rights -> facture -> paiement )
2004-02-10 15:28:00 +00:00
{
2005-10-15 18:28:21 +00:00
$db -> begin ();
2005-10-05 01:48:00 +00:00
$paiement = new Paiement ( $db );
$paiement -> fetch ( $_GET [ 'id' ]);
2005-10-15 18:28:21 +00:00
$result = $paiement -> delete ();
if ( $result > 0 )
2005-10-05 01:48:00 +00:00
{
2005-10-15 18:28:21 +00:00
$db -> commit ();
Header ( " Location: liste.php " );
exit ;
2005-10-05 01:48:00 +00:00
}
else
{
2005-10-15 18:28:21 +00:00
$mesg = '<div class="error">' . $paiement -> error . '</div>' ;
$db -> rollback ();
2005-10-05 01:48:00 +00:00
}
2004-02-10 15:28:00 +00:00
}
2004-12-16 13:26:13 +00:00
2007-02-04 21:23:58 +00:00
if ( $_POST [ 'action' ] == 'confirm_valide' && $_POST [ 'confirm' ] == 'yes' && $user -> rights -> facture -> paiement )
2004-12-16 13:26:13 +00:00
{
2005-10-15 18:28:21 +00:00
$db -> begin ();
2005-10-05 01:48:00 +00:00
$paiement = new Paiement ( $db );
$paiement -> id = $_GET [ 'id' ];
2007-05-16 12:05:44 +00:00
if ( $paiement -> valide () > 0 )
2005-10-05 01:48:00 +00:00
{
2007-05-16 12:05:44 +00:00
$db -> commit ();
2006-09-13 07:48:41 +00:00
2007-05-16 12:05:44 +00:00
// \TODO Boucler sur les facture li<6C> es <20> ce paiement et r<> g<EFBFBD> n<EFBFBD> rer le pdf
$factures = array ();
foreach ( $factures as $id )
{
$fac = new Facture ( $db );
$fac -> fetch ( $id );
if ( $_REQUEST [ 'lang_id' ])
{
2008-03-31 15:17:39 +00:00
$outputlangs = new Translate ( " " , $conf );
2007-05-16 12:05:44 +00:00
$outputlangs -> setDefaultLang ( $_REQUEST [ 'lang_id' ]);
}
facture_pdf_create ( $db , $fac -> id , '' , $fac -> modelpdf , $outputlangs );
}
2005-10-05 01:48:00 +00:00
Header ( 'Location: fiche.php?id=' . $paiement -> id );
2007-05-16 12:05:44 +00:00
exit ;
2005-10-15 18:28:21 +00:00
}
else
{
$mesg = '<div class="error">' . $paiement -> error . '</div>' ;
2007-05-16 12:05:44 +00:00
$db -> rollback ();
2005-10-05 01:48:00 +00:00
}
2004-12-16 13:26:13 +00:00
}
2005-01-11 20:29:43 +00:00
2004-01-31 17:29:54 +00:00
/*
2005-10-15 15:32:01 +00:00
* Visualisation de la fiche
2004-01-31 17:29:54 +00:00
*/
llxHeader ();
2005-10-15 15:32:01 +00:00
$paiement = new Paiement ( $db );
2007-05-23 22:39:14 +00:00
$result = $paiement -> fetch ( $_GET [ 'id' ]);
if ( $result <= 0 )
{
dolibarr_print_error ( $db , 'Payement ' . $_GET [ 'id' ] . ' not found in database' );
exit ;
}
2005-08-16 19:19:29 +00:00
2005-10-15 15:32:01 +00:00
$html = new Form ( $db );
2004-01-31 17:29:54 +00:00
2005-10-15 15:32:01 +00:00
$h = 0 ;
2005-08-16 19:19:29 +00:00
2005-10-15 15:32:01 +00:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/compta/paiement/fiche.php?id=' . $_GET [ " id " ];
$head [ $h ][ 1 ] = $langs -> trans ( " Card " );
$hselected = $h ;
$h ++ ;
2005-08-16 19:19:29 +00:00
2005-10-15 15:32:01 +00:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/compta/paiement/info.php?id=' . $_GET [ " id " ];
$head [ $h ][ 1 ] = $langs -> trans ( " Info " );
$h ++ ;
2004-02-10 15:28:00 +00:00
2005-10-15 15:32:01 +00:00
dolibarr_fiche_head ( $head , $hselected , $langs -> trans ( " Payment " ) . " : " . $paiement -> ref );
2004-02-10 15:28:00 +00:00
/*
2004-12-16 13:26:13 +00:00
* Confirmation de la suppression du paiement
2004-02-10 15:28:00 +00:00
*/
2005-10-05 01:48:00 +00:00
if ( $_GET [ 'action' ] == 'delete' )
2005-08-16 19:19:29 +00:00
{
2007-02-04 21:23:58 +00:00
$html -> form_confirm ( 'fiche.php?id=' . $paiement -> id , $langs -> trans ( " DeletePayment " ), $langs -> trans ( " ConfirmDeletePayment " ), 'confirm_delete' );
2005-10-05 01:48:00 +00:00
print '<br>' ;
2005-08-16 19:19:29 +00:00
}
2004-12-16 13:26:13 +00:00
2005-08-16 19:19:29 +00:00
/*
* Confirmation de la validation du paiement
*/
2005-10-05 01:48:00 +00:00
if ( $_GET [ 'action' ] == 'valide' )
2005-08-16 19:19:29 +00:00
{
2006-09-13 07:48:41 +00:00
$facid = $_GET [ 'facid' ];
2006-12-09 16:57:13 +00:00
$html -> form_confirm ( 'fiche.php?id=' . $paiement -> id . '&facid=' . $facid , $langs -> trans ( " ValidatePayment " ), 'Etes-vous s<> r de vouloir valider ce r<> glement, auncune modification n\'est possible une fois le r<> glement valid<69> ?' , 'confirm_valide' );
2005-10-05 01:48:00 +00:00
print '<br>' ;
2005-08-16 19:19:29 +00:00
}
2004-02-10 15:28:00 +00:00
2005-10-15 18:28:21 +00:00
if ( $mesg ) print $mesg . '<br>' ;
2005-05-08 15:36:58 +00:00
print '<table class="border" width="100%">' ;
2004-02-10 15:28:00 +00:00
2007-11-18 21:07:46 +00:00
// Ref
2005-10-15 18:28:21 +00:00
print '<tr><td valign="top" width="140">' . $langs -> trans ( 'Ref' ) . '</td><td colspan="3">' . $paiement -> id . '</td></tr>' ;
2007-11-18 21:07:46 +00:00
// Bank account
2005-10-15 18:28:21 +00:00
if ( $conf -> banque -> enabled )
2005-10-05 01:48:00 +00:00
{
2005-10-15 18:28:21 +00:00
if ( $paiement -> bank_account )
{
$bankline = new AccountLine ( $db );
$bankline -> fetch ( $paiement -> bank_line );
2007-11-18 21:07:46 +00:00
$bank = new Account ( $db );
$bank -> fetch ( $bankline -> fk_account );
2005-10-15 18:28:21 +00:00
print '<tr>' ;
print '<td valign="top" width="140">' . $langs -> trans ( 'BankAccount' ) . '</td>' ;
2007-11-18 21:07:46 +00:00
print '<td>' . $bank -> getNomUrl ( 1 ) . '</td>' ;
2005-10-15 18:28:21 +00:00
print '<td>' . $langs -> trans ( " BankLineConciliated " ) . '</td><td>' . yn ( $bankline -> rappro ) . '</td>' ;
print '</tr>' ;
}
2005-10-05 01:48:00 +00:00
}
2006-11-10 00:28:39 +00:00
// Date
2008-05-27 23:37:17 +00:00
print '<tr><td valign="top" width="120">' . $langs -> trans ( 'Date' ) . '</td><td colspan="3">' . dolibarr_print_date ( $paiement -> date , 'day' ) . '</td></tr>' ;
2006-11-10 00:28:39 +00:00
// Mode
print '<tr><td valign="top">' . $langs -> trans ( 'Mode' ) . '</td><td colspan="3">' . $langs -> trans ( " PaymentType " . $paiement -> type_code ) . '</td></tr>' ;
// Numero
//if ($paiement->montant)
//{
2005-10-15 18:28:21 +00:00
print '<tr><td valign="top">' . $langs -> trans ( 'Numero' ) . '</td><td colspan="3">' . $paiement -> numero . '</td></tr>' ;
2006-11-10 00:28:39 +00:00
//}
// Montant
2005-10-15 18:28:21 +00:00
print '<tr><td valign="top">' . $langs -> trans ( 'Amount' ) . '</td><td colspan="3">' . price ( $paiement -> montant ) . ' ' . $langs -> trans ( 'Currency' . $conf -> monnaie ) . '</td></tr>' ;
2006-11-10 00:28:39 +00:00
// Note
2005-10-15 18:28:21 +00:00
print '<tr><td valign="top">' . $langs -> trans ( 'Note' ) . '</td><td colspan="3">' . nl2br ( $paiement -> note ) . '</td></tr>' ;
2006-11-10 00:28:39 +00:00
2005-10-05 01:48:00 +00:00
print '</table>' ;
2004-01-31 17:29:54 +00:00
2004-02-10 15:28:00 +00:00
/*
2007-11-18 21:07:46 +00:00
* Liste des factures
2004-02-10 15:28:00 +00:00
*/
$allow_delete = 1 ;
2007-06-11 22:51:47 +00:00
$sql = 'SELECT f.facnumber, f.total_ttc, pf.amount, f.rowid as facid, f.paye, f.fk_statut, s.nom, s.rowid as socid' ;
2005-10-05 01:48:00 +00:00
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'paiement_facture as pf,' . MAIN_DB_PREFIX . 'facture as f,' . MAIN_DB_PREFIX . 'societe as s' ;
2007-06-11 22:51:47 +00:00
$sql .= ' WHERE pf.fk_facture = f.rowid AND f.fk_soc = s.rowid' ;
2005-10-05 01:48:00 +00:00
$sql .= ' AND pf.fk_paiement = ' . $paiement -> id ;
2005-10-15 15:32:01 +00:00
$resql = $db -> query ( $sql );
if ( $resql )
2004-02-10 15:28:00 +00:00
{
2005-10-15 15:32:01 +00:00
$num = $db -> num_rows ( $resql );
2004-02-10 15:28:00 +00:00
2005-10-05 01:48:00 +00:00
$i = 0 ;
$total = 0 ;
print '<br><table class="noborder" width="100%">' ;
print '<tr class="liste_titre">' ;
2006-04-08 12:52:30 +00:00
print '<td>' . $langs -> trans ( 'Bill' ) . '</td>' ;
print '<td align="center">' . $langs -> trans ( 'Status' ) . '</td>' ;
print '<td>' . $langs -> trans ( 'Company' ) . '</td>' ;
print '<td align="right">' . $langs -> trans ( 'AmountTTC' ) . '</td>' ;
2005-10-05 01:48:00 +00:00
print " </tr> \n " ;
2004-02-10 15:28:00 +00:00
2005-10-05 01:48:00 +00:00
if ( $num > 0 )
2004-02-10 15:28:00 +00:00
{
2005-10-05 01:48:00 +00:00
$var = True ;
2006-04-08 12:52:30 +00:00
$facturestatic = new Facture ( $db );
2005-10-05 01:48:00 +00:00
while ( $i < $num )
{
2005-10-15 15:32:01 +00:00
$objp = $db -> fetch_object ( $resql );
2005-10-05 01:48:00 +00:00
$var =! $var ;
print '<tr ' . $bc [ $var ] . '>' ;
print '<td><a href="' . DOL_URL_ROOT . '/compta/facture.php?facid=' . $objp -> facid . '">' . img_object ( $langs -> trans ( 'ShowBill' ), 'bill' ) . ' ' ;
print $objp -> facnumber ;
print " </a></td> \n " ;
2006-04-08 12:52:30 +00:00
print '<td align="center">' . $facturestatic -> LibStatut ( $objp -> paye , $objp -> fk_statut , 2 , 1 ) . '</td>' ;
2007-06-11 22:51:47 +00:00
print '<td><a href="' . DOL_URL_ROOT . '/compta/fiche.php?socid=' . $objp -> socid . '">' . img_object ( $langs -> trans ( 'ShowCompany' ), 'company' ) . ' ' . $objp -> nom . '</a></td>' ;
2005-10-05 01:48:00 +00:00
print '<td align="right">' . price ( $objp -> amount ) . '</td>' ;
print " </tr> \n " ;
if ( $objp -> paye == 1 )
{
$allow_delete = 0 ;
}
$total = $total + $objp -> amount ;
$i ++ ;
}
}
$var =! $var ;
print " </table> \n " ;
2005-10-15 15:32:01 +00:00
$db -> free ( $resql );
2004-02-10 15:28:00 +00:00
}
2005-10-05 01:48:00 +00:00
else
{
dolibarr_print_error ( $db );
2004-12-28 14:08:50 +00:00
}
2004-02-10 15:28:00 +00:00
2005-10-05 01:48:00 +00:00
print '</div>' ;
2005-07-11 00:49:16 +00:00
2004-02-10 15:28:00 +00:00
/*
2005-07-11 00:49:16 +00:00
* Boutons Actions
2004-02-10 15:28:00 +00:00
*/
2005-07-11 00:49:16 +00:00
2004-12-16 13:26:13 +00:00
print '<div class="tabsAction">' ;
2004-01-31 17:29:54 +00:00
2005-10-05 01:48:00 +00:00
if ( $user -> societe_id == 0 && $paiement -> statut == 0 && $_GET [ 'action' ] == '' )
2004-12-16 13:26:13 +00:00
{
2007-02-04 21:23:58 +00:00
if ( $user -> rights -> facture -> paiement )
{
print '<a class="butAction" href="fiche.php?id=' . $_GET [ 'id' ] . '&facid=' . $objp -> facid . '&action=valide">' . $langs -> trans ( 'Valid' ) . '</a>' ;
2004-01-31 17:29:54 +00:00
2007-02-04 21:23:58 +00:00
}
}
2008-05-19 19:18:18 +00:00
if ( $user -> societe_id == 0 && $allow_delete && $_GET [ 'action' ] == '' )
2004-12-16 13:26:13 +00:00
{
2007-02-04 21:23:58 +00:00
if ( $user -> rights -> facture -> paiement )
{
print '<a class="butActionDelete" href="fiche.php?id=' . $_GET [ 'id' ] . '&action=delete">' . $langs -> trans ( 'Delete' ) . '</a>' ;
}
2004-12-16 13:26:13 +00:00
}
2005-10-05 01:48:00 +00:00
print '</div>' ;
2005-07-11 00:49:16 +00:00
2004-12-16 13:26:13 +00:00
$db -> close ();
2004-01-31 17:29:54 +00:00
2005-07-11 00:49:16 +00:00
llxFooter ( '$Date$ - $Revision$' );
2004-01-31 17:29:54 +00:00
?>