2004-10-19 22:35:36 +02:00
< ? php
2006-12-22 16:13:46 +01:00
/* Copyright ( C ) 2001 - 2006 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2008-01-27 01:16:02 +01:00
* Copyright ( C ) 2004 - 2008 Laurent Destailleur < eldy @ users . sourceforge . net >
2006-12-22 16:13:46 +01:00
* Copyright ( C ) 2005 Marc Barilley / Ocebo < marc @ ocebo . com >
2007-01-05 16:51:43 +01:00
* Copyright ( C ) 2007 Franky Van Liedekerke < franky . van . liedekerke @ telenet . be >
2002-04-29 23:19:51 +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 .
*/
2004-11-18 00:15:40 +01:00
2005-03-28 15:52:40 +02:00
/**
2008-08-08 20:13:41 +02:00
* \file htdocs / compta / paiement . php
* \ingroup compta
* \brief Page to create a payment
* \version $Id $
2008-07-04 12:44:54 +02:00
*/
2004-11-18 00:15:40 +01:00
2005-10-05 03:48:00 +02:00
include_once ( './pre.inc.php' );
require_once ( DOL_DOCUMENT_ROOT . '/paiement.class.php' );
include_once ( DOL_DOCUMENT_ROOT . '/facture.class.php' );
include_once ( DOL_DOCUMENT_ROOT . '/compta/bank/account.class.php' );
2004-02-10 16:24:22 +01:00
2006-05-25 18:43:09 +02:00
$langs -> load ( 'companies' );
2005-10-05 03:48:00 +02:00
$langs -> load ( 'bills' );
$langs -> load ( 'banks' );
2005-09-05 00:39:53 +02:00
2005-10-05 03:48:00 +02:00
$facid = isset ( $_GET [ 'facid' ]) ? $_GET [ 'facid' ] : $_POST [ 'facid' ];
$socname = isset ( $_GET [ 'socname' ]) ? $_GET [ 'socname' ] : $_POST [ 'socname' ];
2005-05-07 00:56:15 +02:00
2005-10-05 03:48:00 +02:00
$sortfield = isset ( $_GET [ 'sortfield' ]) ? $_GET [ 'sortfield' ] : $_POST [ 'sortfield' ];
$sortorder = isset ( $_GET [ 'sortorder' ]) ? $_GET [ 'sortorder' ] : $_POST [ 'sortorder' ];
$page = isset ( $_GET [ 'page' ]) ? $_GET [ 'page' ] : $_POST [ 'page' ];
2004-12-19 01:42:40 +01:00
2006-11-10 01:28:39 +01:00
$amounts = array ();
$amountsresttopay = array ();
$addwarning = 0 ;
2005-05-07 00:56:15 +02:00
/*
2008-07-04 12:44:54 +02:00
* Action add_paiement et confirm_paiement
*/
2006-11-10 01:28:39 +01:00
if ( $_POST [ 'action' ] == 'add_paiement' || $_POST [ 'action' ] == 'confirm_paiement' )
2004-02-10 16:24:22 +01:00
{
2008-07-04 12:44:54 +02:00
$error = 0 ;
2009-02-20 23:53:15 +01:00
$datepaye = dol_mktime ( 12 , 0 , 0 ,
2008-07-04 12:44:54 +02:00
$_POST [ 'remonth' ],
$_POST [ 'reday' ],
$_POST [ 'reyear' ]);
$paiement_id = 0 ;
// Verifie si des paiements sont sup<75> rieurs au montant facture
foreach ( $_POST as $key => $value )
{
if ( substr ( $key , 0 , 7 ) == 'amount_' )
{
$cursorfacid = substr ( $key , 7 );
$amounts [ $cursorfacid ] = price2num ( $_POST [ $key ]);
$totalpaiement = $totalpaiement + $amounts [ $cursorfacid ];
$tmpfacture = new Facture ( $db );
$tmpfacture -> fetch ( $cursorfacid );
$amountsresttopay [ $cursorfacid ] = price2num ( $tmpfacture -> total_ttc - $tmpfacture -> getSommePaiement ());
if ( $amounts [ $cursorfacid ] && $amounts [ $cursorfacid ] > $amountsresttopay [ $cursorfacid ])
{
$addwarning = 1 ;
$formquestion [ 'text' ] = img_warning ( $langs -> trans ( " PaymentHigherThanReminderToPay " )) . ' Attention, le montant de paiement pour une ou plusieurs facture est superieur au reste a payer.' ;
$formquestion [ 'text' ] .= '<br>Corriger votre saisie, sinon, confirmer et penser a creer un avoir du trop percu lors de la fermeture de chacune des factures surpayees.' ;
}
2009-02-21 18:43:02 +01:00
2008-07-04 12:44:54 +02:00
$formquestion [ $i ++ ] = array ( 'type' => 'hidden' , 'name' => $key , 'value' => $_POST [ $key ]);
}
}
// Effectue les verifications des parametres
if ( $_POST [ 'paiementid' ] <= 0 )
{
$fiche_erreur_message = '<div class="error">' . $langs -> trans ( 'ErrorFieldRequired' , $langs -> transnoentities ( 'PaymentMode' )) . '</div>' ;
$error ++ ;
2005-10-05 03:48:00 +02:00
}
2008-07-04 12:44:54 +02:00
if ( $conf -> banque -> enabled )
2005-10-05 03:48:00 +02:00
{
2008-07-04 12:44:54 +02:00
// Si module bank actif, un compte est obligatoire lors de la saisie
// d'un paiement
if ( ! $_POST [ 'accountid' ])
{
2006-12-22 16:13:46 +01:00
$fiche_erreur_message = '<div class="error">' . $langs -> trans ( 'ErrorFieldRequired' , $langs -> transnoentities ( 'AccountToCredit' )) . '</div>' ;
$error ++ ;
2008-07-04 12:44:54 +02:00
}
}
if ( $totalpaiement == 0 )
{
$fiche_erreur_message = '<div class="error">' . $langs -> transnoentities ( 'ErrorFieldRequired' , $langs -> trans ( 'Amount' )) . '</div>' ;
$error ++ ;
}
if ( empty ( $datepaye ))
{
$fiche_erreur_message = '<div class="error">' . $langs -> trans ( 'ErrorFieldRequired' , $langs -> transnoentities ( 'Date' )) . '</div>' ;
$error ++ ;
2005-10-05 03:48:00 +02:00
}
2006-11-10 01:28:39 +01:00
}
/*
2008-07-04 12:44:54 +02:00
* Action add_paiement
*/
2006-11-10 01:28:39 +01:00
if ( $_POST [ 'action' ] == 'add_paiement' )
{
2008-07-04 12:44:54 +02:00
if ( $error )
{
$_POST [ 'action' ] = '' ;
$_GET [ 'action' ] = 'create' ;
}
// Le reste propre a cette action s'affiche en bas de page.
2006-11-10 01:28:39 +01:00
}
2005-10-05 03:48:00 +02:00
2006-11-10 01:28:39 +01:00
/*
2008-07-04 12:44:54 +02:00
* Action confirm_paiement
*/
2006-11-10 01:28:39 +01:00
if ( $_POST [ 'action' ] == 'confirm_paiement' && $_POST [ 'confirm' ] == 'yes' )
{
2009-02-20 23:53:15 +01:00
$datepaye = dol_mktime ( 12 , 0 , 0 ,
2008-07-07 01:49:12 +02:00
$_POST [ 'remonth' ],
$_POST [ 'reday' ],
$_POST [ 'reyear' ]);
2009-02-21 18:43:02 +01:00
2008-07-04 12:44:54 +02:00
if ( ! $error )
{
$db -> begin ();
2009-02-21 18:43:02 +01:00
2008-07-04 12:44:54 +02:00
// Creation de la ligne paiement
$paiement = new Paiement ( $db );
$paiement -> datepaye = $datepaye ;
$paiement -> amounts = $amounts ; // Tableau de montant
$paiement -> paiementid = $_POST [ 'paiementid' ];
$paiement -> num_paiement = $_POST [ 'num_paiement' ];
$paiement -> note = $_POST [ 'comment' ];
$paiement_id = $paiement -> create ( $user );
if ( $paiement_id > 0 )
{
if ( $conf -> banque -> enabled )
{
// Insertion dans llx_bank
$label = " (CustomerInvoicePayment) " ;
$acc = new Account ( $db , $_POST [ 'accountid' ]);
//paiementid contient "CHQ ou VIR par exemple"
$bank_line_id = $acc -> addline ( $paiement -> datepaye ,
$paiement -> paiementid ,
$label ,
$totalpaiement ,
$paiement -> num_paiement ,
2007-03-30 17:56:42 +02:00
'' ,
2008-07-04 12:44:54 +02:00
$user ,
$_POST [ 'chqemetteur' ],
$_POST [ 'chqbank' ]);
2009-02-21 18:43:02 +01:00
2008-07-04 12:44:54 +02:00
// Mise a jour fk_bank dans llx_paiement.
// On connait ainsi le paiement qui a g<> n<EFBFBD> r<EFBFBD> l'<27> criture bancaire
if ( $bank_line_id > 0 )
{
$paiement -> update_fk_bank ( $bank_line_id );
// Mise a jour liens (pour chaque facture concern<72> es par le paiement)
foreach ( $paiement -> amounts as $key => $value )
{
$facid = $key ;
$fac = new Facture ( $db );
$fac -> fetch ( $facid );
$fac -> fetch_client ();
$acc -> add_url_line ( $bank_line_id ,
$paiement_id ,
DOL_URL_ROOT . '/compta/paiement/fiche.php?id=' ,
2007-03-30 17:56:42 +02:00
'(paiement)' ,
'payment' );
2008-07-04 12:44:54 +02:00
$acc -> add_url_line ( $bank_line_id ,
$fac -> client -> id ,
DOL_URL_ROOT . '/compta/fiche.php?socid=' ,
$fac -> client -> nom ,
2007-03-30 17:56:42 +02:00
'company' );
2008-07-04 12:44:54 +02:00
}
}
else
{
$error ++ ;
}
}
}
else
{
$error ++ ;
}
2009-02-21 18:43:02 +01:00
2008-07-04 12:44:54 +02:00
if ( $error == 0 )
{
$loc = DOL_URL_ROOT . '/compta/paiement/fiche.php?id=' . $paiement_id ;
$db -> commit ();
Header ( 'Location: ' . $loc );
exit ;
}
else
{
$db -> rollback ();
}
}
2004-02-10 16:24:22 +01:00
}
2002-04-29 23:19:51 +02:00
2008-08-08 20:13:41 +02:00
// Security check
2005-10-05 03:48:00 +02:00
if ( $user -> societe_id > 0 )
2003-03-23 16:19:03 +01:00
{
2005-10-05 03:48:00 +02:00
$action = '' ;
2006-09-13 20:56:30 +02:00
$socid = $user -> societe_id ;
2003-03-23 16:19:03 +01:00
}
2005-09-05 00:39:53 +02:00
2003-05-18 17:20:55 +02:00
/*
2008-07-04 12:44:54 +02:00
* View
2003-05-18 17:20:55 +02:00
*/
2002-04-29 23:19:51 +02:00
2003-05-18 17:20:55 +02:00
llxHeader ();
2005-03-28 15:52:40 +02:00
$html = new Form ( $db );
2006-10-21 20:21:27 +02:00
$facturestatic = new Facture ( $db );
2005-03-28 15:52:40 +02:00
2006-11-10 01:28:39 +01:00
if ( $_GET [ 'action' ] == 'create' || $_POST [ 'action' ] == 'confirm_paiement' || $_POST [ 'action' ] == 'add_paiement' )
2003-05-18 17:20:55 +02:00
{
2005-10-05 03:48:00 +02:00
$facture = new Facture ( $db );
2006-10-21 20:21:27 +02:00
$result = $facture -> fetch ( $facid );
2008-07-04 12:44:54 +02:00
2006-10-21 20:21:27 +02:00
if ( $result >= 0 )
2005-10-05 03:48:00 +02:00
{
2006-11-10 01:28:39 +01:00
$facture -> fetch_client ();
2008-07-04 12:44:54 +02:00
2006-11-10 01:28:39 +01:00
$title = '' ;
if ( $facture -> type != 2 ) $title .= $langs -> trans ( " EnterPaymentReceivedFromCustomer " );
if ( $facture -> type == 2 ) $title .= $langs -> trans ( " EnterPaymentDueToCustomer " );
print_fiche_titre ( $title );
2005-10-05 03:48:00 +02:00
2007-03-25 05:07:46 +02:00
// Bouchon
if ( $facture -> type == 2 )
{
print $langs -> trans ( " FeatureNotYetAvailable " );
llxFooter ();
exit ;
}
2008-07-04 12:44:54 +02:00
2006-11-10 01:28:39 +01:00
// Initialise donnees pour page de confirmation
if ( $_POST [ " action " ] == 'add_paiement' )
{
$i = 0 ;
2009-02-21 18:43:02 +01:00
2006-11-10 01:28:39 +01:00
$formquestion [ $i ++ ] = array ( 'type' => 'hidden' , 'name' => 'facid' , 'value' => $facture -> id );
$formquestion [ $i ++ ] = array ( 'type' => 'hidden' , 'name' => 'socid' , 'value' => $facture -> socid );
$formquestion [ $i ++ ] = array ( 'type' => 'hidden' , 'name' => 'type' , 'value' => $facture -> type );
2005-10-05 03:48:00 +02:00
2006-11-10 01:28:39 +01:00
}
2005-10-05 03:48:00 +02:00
2006-11-10 01:28:39 +01:00
print '<form name="add_paiement" action="paiement.php" method="post">' ;
print '<input type="hidden" name="action" value="add_paiement">' ;
print '<input type="hidden" name="facid" value="' . $facture -> id . '">' ;
print '<input type="hidden" name="socid" value="' . $facture -> socid . '">' ;
print '<input type="hidden" name="type" value="' . $facture -> type . '">' ;
print '<table class="border" width="100%">' ;
print '<tr><td>' . $langs -> trans ( 'Company' ) . '</td><td colspan="2">' . $facture -> client -> getNomUrl ( 4 ) . " </td></tr> \n " ;
2005-10-05 03:48:00 +02:00
2008-07-07 01:49:12 +02:00
// Date payment
2006-11-10 01:28:39 +01:00
print '<tr><td>' . $langs -> trans ( 'Date' ) . '</td><td>' ;
2009-02-20 23:53:15 +01:00
$datepayment = dol_mktime ( 12 , 0 , 0 , $_POST [ 'remonth' ], $_POST [ 'reday' ], $_POST [ 'reyear' ]);
2008-07-18 00:11:45 +02:00
$datepayment = ( $datepayment == '' ? ( empty ( $conf -> global -> MAIN_AUTOFILL_DATE ) ? - 1 : 0 ) : $datepayment );
$html -> select_date ( $datepayment , '' , '' , '' , 0 , " add_paiement " );
2006-11-10 01:28:39 +01:00
print '</td>' ;
print '<td>' . $langs -> trans ( 'Comments' ) . '</td></tr>' ;
print '<tr><td>' . $langs -> trans ( 'PaymentMode' ) . '</td><td>' ;
$html -> select_types_paiements ( empty ( $_POST [ 'paiementid' ]) ? '' : $_POST [ 'paiementid' ], 'paiementid' );
print " </td> \n " ;
2006-12-22 16:13:46 +01:00
print '<td rowspan="5" valign="top">' ;
2006-11-10 01:28:39 +01:00
print '<textarea name="comment" wrap="soft" cols="60" rows="' . ROWS_4 . '">' . ( empty ( $_POST [ 'comment' ]) ? '' : $_POST [ 'comment' ]) . '</textarea></td></tr>' ;
2005-10-05 03:48:00 +02:00
2006-11-10 01:28:39 +01:00
print '<tr>' ;
if ( $conf -> banque -> enabled )
{
2008-07-04 12:44:54 +02:00
if ( $facture -> type != 2 ) print '<td>' . $langs -> trans ( 'AccountToCredit' ) . '</td>' ;
if ( $facture -> type == 2 ) print '<td>' . $langs -> trans ( 'AccountToDebit' ) . '</td>' ;
print '<td>' ;
$html -> select_comptes ( empty ( $_POST [ 'accountid' ]) ? '' : $_POST [ 'accountid' ], 'accountid' , 0 , '' , 1 );
print '</td>' ;
2006-11-10 01:28:39 +01:00
}
else
{
2008-07-04 12:44:54 +02:00
print '<td colspan="2"> </td>' ;
2006-11-10 01:28:39 +01:00
}
print " </tr> \n " ;
2005-10-05 03:48:00 +02:00
2006-12-22 16:13:46 +01:00
print '<tr><td>' . $langs -> trans ( 'Numero' );
2008-02-12 04:25:35 +01:00
print ' <em>(' . $langs -> trans ( " ChequeOrTransferNumber " ) . ')</em>' ;
2006-12-22 16:13:46 +01:00
print '</td>' ;
print '<td><input name="num_paiement" type="text" value="' . ( empty ( $_POST [ 'num_paiement' ]) ? '' : $_POST [ 'num_paiement' ]) . '"></td></tr>' ;
print '<tr><td>' . $langs -> trans ( 'CheckTransmitter' );
2008-02-12 04:25:35 +01:00
print ' <em>(' . $langs -> trans ( " ChequeMaker " ) . ')</em>' ;
2006-12-22 16:13:46 +01:00
print '</td>' ;
print '<td><input name="chqemetteur" size="30" type="text" value="' . ( empty ( $_POST [ 'chqemetteur' ]) ? $facture -> client -> nom : $_POST [ 'chqemetteur' ]) . '"></td></tr>' ;
print '<tr><td>' . $langs -> trans ( 'Bank' );
2008-02-12 04:25:35 +01:00
print ' <em>(' . $langs -> trans ( " ChequeBank " ) . ')</em>' ;
2006-12-22 16:13:46 +01:00
print '</td>' ;
print '<td><input name="chqbank" size="30" type="text" value="' . ( empty ( $_POST [ 'chqbank' ]) ? '' : $_POST [ 'chqbank' ]) . '"></td></tr>' ;
2005-10-05 03:48:00 +02:00
2006-11-10 01:28:39 +01:00
/*
2009-02-21 18:43:02 +01:00
* List of unpayed invoices
2006-11-10 01:28:39 +01:00
*/
$sql = 'SELECT f.rowid as facid, f.facnumber, f.total_ttc, f.type, ' ;
$sql .= $db -> pdate ( 'f.datef' ) . ' as df, ' ;
$sql .= ' sum(pf.amount) as am' ;
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'facture as f' ;
$sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'paiement_facture as pf ON pf.fk_facture = f.rowid' ;
$sql .= ' WHERE f.fk_soc = ' . $facture -> socid ;
$sql .= ' AND f.paye = 0' ;
2009-02-21 18:43:02 +01:00
$sql .= ' AND f.fk_statut = 1' ; // Statut=0 => not validated, Statut=2 => canceled
2006-11-10 01:28:39 +01:00
if ( $facture -> type != 2 )
{
2009-02-21 18:43:02 +01:00
$sql .= ' AND type in (0,1,3)' ; // Standard invoice, replacement, deposit
2006-11-10 01:28:39 +01:00
}
else
{
2009-02-21 18:43:02 +01:00
$sql .= ' AND type = 2' ; // If paying back a credit note, we show all credit notes
2006-11-10 01:28:39 +01:00
}
$sql .= ' GROUP BY f.facnumber' ;
$resql = $db -> query ( $sql );
if ( $resql )
{
$num = $db -> num_rows ( $resql );
if ( $num > 0 )
{
2005-10-05 03:48:00 +02:00
2006-11-10 01:28:39 +01:00
$i = 0 ;
print '<tr><td colspan="3">' ;
print '<table class="noborder" width="100%">' ;
print '<tr class="liste_titre">' ;
print '<td>' . $langs -> trans ( 'Invoice' ) . '</td>' ;
print '<td align="center">' . $langs -> trans ( 'Date' ) . '</td>' ;
print '<td align="right">' . $langs -> trans ( 'AmountTTC' ) . '</td>' ;
print '<td align="right">' . $langs -> trans ( 'Received' ) . '</td>' ;
print '<td align="right">' . $langs -> trans ( 'RemainderToPay' ) . '</td>' ;
print '<td align="right">' . $langs -> trans ( 'PaymentAmount' ) . '</td>' ;
print '<td align="right"> </td>' ;
print " </tr> \n " ;
$var = True ;
$total = 0 ;
$totalrecu = 0 ;
2009-03-02 22:21:49 +01:00
$totalrecucreditnote = 0 ;
$totalrecudeposits = 0 ;
2006-11-10 01:28:39 +01:00
while ( $i < $num )
{
$objp = $db -> fetch_object ( $resql );
$var =! $var ;
2008-07-04 12:44:54 +02:00
$facturestatic -> ref = $objp -> facnumber ;
$facturestatic -> id = $objp -> facid ;
$facturestatic -> type = $objp -> type ;
2009-02-21 18:43:02 +01:00
2009-03-02 22:21:49 +01:00
$creditnotes = $facturestatic -> getSumCreditNotesUsed ();
$deposits = $facturestatic -> getSumDepositsUsed ();
2009-02-21 18:43:02 +01:00
2008-08-07 19:47:44 +02:00
print '<tr ' . $bc [ $var ] . '>' ;
print '<td>' ;
2008-07-04 12:44:54 +02:00
print $facturestatic -> getNomUrl ( 1 , '' );
2006-11-10 01:28:39 +01:00
print " </td> \n " ;
// Date
2009-02-20 23:53:15 +01:00
print '<td align="center">' . dol_print_date ( $objp -> df , 'day' ) . " </td> \n " ;
2006-11-10 01:28:39 +01:00
// Prix
print '<td align="right">' . price ( $objp -> total_ttc ) . '</td>' ;
2009-02-21 18:43:02 +01:00
2006-11-10 01:28:39 +01:00
// Recu
2008-08-07 19:47:44 +02:00
print '<td align="right">' . price ( $objp -> am );
2009-03-02 22:21:49 +01:00
if ( $creditnotes ) print '+' . price ( $creditnotes );
if ( $deposits ) print '+' . price ( $deposits );
2008-08-07 19:47:44 +02:00
print '</td>' ;
2009-02-21 18:43:02 +01:00
2006-11-10 01:28:39 +01:00
// Reste a payer
2009-03-02 22:21:49 +01:00
print '<td align="right">' . price ( price2num ( $objp -> total_ttc - $objp -> am - $creditnotes - $deposits , 'MT' )) . '</td>' ;
2006-11-10 01:28:39 +01:00
// Montant
print '<td align="right">' ;
$namef = 'amount_' . $objp -> facid ;
print '<input type="text" size="8" name="' . $namef . '" value="' . $_POST [ $namef ] . '">' ;
print " </td> " ;
// Warning
print '<td align="center" width="16">' ;
if ( $amounts [ $facturestatic -> id ] && $amounts [ $facturestatic -> id ] > $amountsresttopay [ $facturestatic -> id ])
2005-10-05 03:48:00 +02:00
{
2008-07-04 12:44:54 +02:00
print ' ' . img_warning ( $langs -> trans ( " PaymentHigherThanReminderToPay " ));
2005-10-05 03:48:00 +02:00
}
2006-11-10 01:28:39 +01:00
print '</td>' ;
2009-02-21 18:43:02 +01:00
2006-11-10 01:28:39 +01:00
print " </tr> \n " ;
$total += $objp -> total ;
$total_ttc += $objp -> total_ttc ;
$totalrecu += $objp -> am ;
2009-03-02 22:21:49 +01:00
$totalrecucreditnote += $creditnotes ;
$totalrecudeposits += $deposits ;
2006-11-10 01:28:39 +01:00
$i ++ ;
2005-10-05 03:48:00 +02:00
}
2006-11-10 01:28:39 +01:00
if ( $i > 1 )
{
// Print total
print '<tr class="liste_total">' ;
2009-02-21 18:43:02 +01:00
print '<td colspan="2" align="left">' . $langs -> trans ( 'TotalTTC' ) . '</td>' ;
2006-11-10 01:28:39 +01:00
print '<td align="right"><b>' . price ( $total_ttc ) . '</b></td>' ;
2008-08-08 20:13:41 +02:00
print '<td align="right"><b>' . price ( $totalrecu );
if ( $totalrecucreditnote ) print '+' . price ( $totalrecucreditnote );
2009-03-02 22:21:49 +01:00
if ( $totalrecudeposits ) print '+' . price ( $totalrecudeposits );
2008-08-08 20:13:41 +02:00
print '</b></td>' ;
2009-03-02 22:21:49 +01:00
print '<td align="right"><b>' . price ( price2num ( $total_ttc - $totalrecu - $totalrecucreditnote - $totalrecudeposits , 'MT' )) . '</b></td>' ;
2008-08-08 20:13:41 +02:00
print '<td align="center"> </td>' ;
2006-11-10 01:28:39 +01:00
print '<td align="center"> </td>' ;
print " </tr> \n " ;
}
print " </table></td></tr> \n " ;
2005-10-05 03:48:00 +02:00
}
2006-11-10 01:28:39 +01:00
$db -> free ( $resql );
}
else
{
2009-02-20 23:53:15 +01:00
dol_print_error ( $db );
2006-11-10 01:28:39 +01:00
}
2005-10-05 03:48:00 +02:00
2006-11-10 01:28:39 +01:00
// Bouton Enregistrer
if ( $_POST [ " action " ] != 'add_paiement' )
{
2005-10-05 03:48:00 +02:00
print '<tr><td colspan="3" align="center"><input type="submit" class="button" value="' . $langs -> trans ( 'Save' ) . '"></td></tr>' ;
2006-11-10 01:28:39 +01:00
}
2008-07-04 12:44:54 +02:00
2006-11-10 01:28:39 +01:00
print '</table>' ;
// Message d'erreur
if ( $fiche_erreur_message )
{
2008-07-04 12:44:54 +02:00
print $fiche_erreur_message ;
2006-11-10 01:28:39 +01:00
}
// Formulaire confirmation
if ( $_POST [ " action " ] == 'add_paiement' )
{
2008-07-04 12:44:54 +02:00
// print '<tr><td colspan="3">';
2006-11-10 01:28:39 +01:00
print '<br />' ;
$text = $langs -> trans ( 'ConfirmCustomerPayment' , $totalpaiement , $langs -> trans ( " Currency " . $conf -> monnaie ));
$html -> form_confirm ( $_SERVER [ 'PHP_SELF' ] . '?facid=' . $facture -> id . '&socid=' . $facture -> socid . '&type=' . $facture -> type , $langs -> trans ( 'ReceivedCustomersPayments' ), $text , 'confirm_paiement' , $formquestion );
2008-07-04 12:44:54 +02:00
// print '</td></tr>';
2006-11-10 01:28:39 +01:00
}
print " </form> \n " ;
2005-10-05 03:48:00 +02:00
}
}
2002-04-29 23:19:51 +02:00
2004-12-19 01:42:40 +01:00
/**
2009-02-21 18:43:02 +01:00
* \brief Affichage de la liste des paiements
2004-12-19 01:42:40 +01:00
*/
2005-10-05 03:48:00 +02:00
if ( ! $_GET [ 'action' ] && ! $_POST [ 'action' ])
2004-05-25 15:09:24 +02:00
{
2005-10-05 03:48:00 +02:00
if ( $page == - 1 ) $page = 0 ;
$limit = $conf -> liste_limit ;
$offset = $limit * $page ;
if ( ! $sortorder ) $sortorder = 'DESC' ;
if ( ! $sortfield ) $sortfield = 'p.datep' ;
$sql = 'SELECT ' . $db -> pdate ( 'p.datep' ) . ' as dp, p.amount, f.amount as fa_amount, f.facnumber' ;
$sql .= ', f.rowid as facid, c.libelle as paiement_type, p.num_paiement' ;
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'paiement as p, ' . MAIN_DB_PREFIX . 'facture as f, ' . MAIN_DB_PREFIX . 'c_paiement as c' ;
$sql .= ' WHERE p.fk_facture = f.rowid AND p.fk_paiement = c.id' ;
2006-09-13 20:56:30 +02:00
if ( $socid )
2005-10-05 03:48:00 +02:00
{
2006-09-13 20:56:30 +02:00
$sql .= ' AND f.fk_soc = ' . $socid ;
2005-10-05 03:48:00 +02:00
}
$sql .= ' ORDER BY ' . $sortfield . ' ' . $sortorder ;
$sql .= $db -> plimit ( $limit + 1 , $offset );
$resql = $db -> query ( $sql );
if ( $resql )
2003-07-08 22:58:33 +02:00
{
2005-10-05 03:48:00 +02:00
$num = $db -> num_rows ( $resql );
$i = 0 ;
$var = True ;
print_barre_liste ( $langs -> trans ( 'Payments' ), $page , 'paiement.php' , '' , $sortfield , $sortorder , '' , $num );
print '<table class="noborder" width="100%">' ;
print '<tr class="liste_titre">' ;
2007-11-11 16:55:45 +01:00
print_liste_field_titre ( $langs -> trans ( 'Invoice' ), 'paiement.php' , 'facnumber' , '' , '' , '' , $sortfield , $sortorder );
print_liste_field_titre ( $langs -> trans ( 'Date' ), 'paiement.php' , 'dp' , '' , '' , '' , $sortfield , $sortorder );
print_liste_field_titre ( $langs -> trans ( 'Type' ), 'paiement.php' , 'libelle' , '' , '' , '' , $sortfield , $sortorder );
print_liste_field_titre ( $langs -> trans ( 'Amount' ), 'paiement.php' , 'fa_amount' , '' , '' , 'align="right"' , $sortfield , $sortorder );
2005-10-05 03:48:00 +02:00
print '<td> </td>' ;
print " </tr> \n " ;
while ( $i < min ( $num , $limit ))
{
$objp = $db -> fetch_object ( $resql );
$var =! $var ;
print '<tr ' . $bc [ $var ] . '>' ;
print '<td><a href="facture.php?facid=' . $objp -> facid . '">' . $objp -> facnumber . " </a></td> \n " ;
2009-02-20 23:53:15 +01:00
print '<td>' . dol_print_date ( $objp -> dp ) . " </td> \n " ;
2005-10-05 03:48:00 +02:00
print '<td>' . $objp -> paiement_type . ' ' . $objp -> num_paiement . " </td> \n " ;
print '<td align="right">' . price ( $objp -> amount ) . '</td><td> </td>' ;
print '</tr>' ;
$i ++ ;
}
print '</table>' ;
2003-07-08 22:58:33 +02:00
}
2002-04-29 23:19:51 +02:00
}
$db -> close ();
2006-10-21 20:21:27 +02:00
llxFooter ( '$Date$ - $Revision$' );
2002-04-29 23:19:51 +02:00
?>