2004-10-19 22:35:36 +02:00
< ? php
2004-01-30 11:16:56 +01:00
/* Copyright ( C ) 2002 - 2004 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2004-02-07 00:22:11 +01:00
* Copyright ( C ) 2004 <EFBFBD> ric Seigne < eric . seigne @ ryxeo . com >
2005-01-08 01:50:59 +01:00
* Copyright ( C ) 2004 - 2005 Laurent Destailleur < eldy @ users . sourceforge . net >
2002-04-30 12:44:42 +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-07-03 14:46:00 +02:00
* $Id $
* $Source $
2003-06-22 12:58:04 +02:00
*
2002-04-30 12:44:42 +02:00
*/
2004-08-15 17:04:24 +02:00
2005-01-11 21:26:22 +01:00
/** \file htdocs / compta / facture . php
2004-08-15 17:04:24 +02:00
\ingroup facture
\brief Page de cr<EFBFBD> ation d ' une facture
\version $Revision $
*/
2003-09-11 22:18:51 +02:00
require ( " ./pre.inc.php " );
2003-08-06 14:38:46 +02:00
$user -> getrights ( 'facture' );
2004-10-10 14:24:56 +02:00
$user -> getrights ( 'banque' );
2003-08-06 14:40:29 +02:00
if ( ! $user -> rights -> facture -> lire )
2003-08-06 14:38:46 +02:00
accessforbidden ();
2004-12-16 10:45:55 +01:00
$langs -> load ( " main " ); // BUG De chargement de traduction ne pas modifier cette ligne
2004-07-28 00:37:51 +02:00
$langs -> load ( " bills " );
2004-11-29 10:33:07 +01:00
require_once " ../facture.class.php " ;
require_once " ../paiement.class.php " ;
2004-11-26 01:54:45 +01:00
if ( $conf -> projet -> enabled ) {
2004-11-29 10:33:07 +01:00
require_once " ../project.class.php " ;
2004-11-26 01:54:45 +01:00
}
if ( $conf -> propal -> enabled ) {
2004-11-29 10:33:07 +01:00
require_once " ../propal.class.php " ;
2004-11-26 01:54:45 +01:00
}
if ( $conf -> contrat -> enabled ) {
2004-11-29 10:33:07 +01:00
require_once " ../contrat/contrat.class.php " ;
2004-11-26 01:54:45 +01:00
}
if ( $conf -> commande -> enabled ) {
2004-11-29 10:33:07 +01:00
require_once " ../commande/commande.class.php " ;
2004-11-26 01:54:45 +01:00
}
2004-11-29 10:33:07 +01:00
require_once " ../lib/CMailFile.class.php " ;
2002-04-30 12:44:42 +02:00
2004-11-26 01:54:45 +01:00
if ( $_GET [ " socidp " ]) { $socidp = $_GET [ " socidp " ]; }
2003-03-23 16:53:03 +01:00
/*
* S<EFBFBD> curit<EFBFBD> acc<EFBFBD> s client
*/
if ( $user -> societe_id > 0 )
{
$action = '' ;
$socidp = $user -> societe_id ;
}
2004-05-17 19:07:16 +02:00
// Nombre de ligne pour choix de produit/service pr<70> d<EFBFBD> finis
$NBLINES = 4 ;
2003-10-22 17:38:43 +02:00
/*
*
2004-01-08 23:58:10 +01:00
*/
2004-05-15 17:55:25 +02:00
if ( $_POST [ " action " ] == 'classin' )
2003-10-22 17:38:43 +02:00
{
$facture = new Facture ( $db );
2004-07-19 23:27:20 +02:00
$facture -> fetch ( $_POST [ " facid " ]);
2004-05-15 17:55:25 +02:00
$facture -> classin ( $_POST [ " projetid " ]);
2003-10-22 17:38:43 +02:00
}
2004-10-23 18:55:07 +02:00
2003-03-23 16:53:03 +01:00
/*
*
*/
2004-05-15 17:55:25 +02:00
if ( $_POST [ " action " ] == 'add' )
2003-09-09 18:06:22 +02:00
{
2004-05-15 17:55:25 +02:00
$datefacture = mktime ( 12 , 0 , 0 , $_POST [ " remonth " ], $_POST [ " reday " ], $_POST [ " reyear " ]);
2003-09-09 18:06:22 +02:00
2004-05-15 17:55:25 +02:00
$facture = new Facture ( $db , $_POST [ " socid " ]);
2003-09-09 18:06:22 +02:00
2004-05-15 17:55:25 +02:00
$facture -> number = $_POST [ " facnumber " ];
2003-09-09 18:06:22 +02:00
$facture -> date = $datefacture ;
2004-05-15 17:55:25 +02:00
$facture -> note = $_POST [ " note " ];
2003-10-12 16:41:22 +02:00
2004-05-15 17:55:25 +02:00
if ( $_POST [ " fac_rec " ] > 0 )
2003-10-12 16:41:22 +02:00
{
/*
* Facture r<EFBFBD> currente
*/
2004-05-15 17:55:25 +02:00
$facture -> fac_rec = $_POST [ " fac_rec " ];
2003-09-09 18:06:22 +02:00
$facid = $facture -> create ( $user );
}
else
{
2004-05-15 17:55:25 +02:00
$facture -> projetid = $_POST [ " projetid " ];
$facture -> cond_reglement = $_POST [ " condid " ];
$facture -> amount = $_POST [ " amount " ];
$facture -> remise = $_POST [ " remise " ];
$facture -> remise_percent = $_POST [ " remise_percent " ];
2003-11-24 11:15:11 +01:00
2004-05-15 17:55:25 +02:00
if ( ! $_POST [ " propalid " ] && ! $_POST [ " commandeid " ])
2003-10-12 16:41:22 +02:00
{
2004-07-13 09:54:13 +02:00
for ( $i = 1 ; $i <= $NBLINES ; $i ++ )
{
if ( $_POST [ " idprod ${ i } " ]) {
2004-05-17 19:07:16 +02:00
$startday = '' ;
$endday = '' ;
if ( $_POST [ " date_start ${ i } year " ] && $_POST [ " date_start ${ i } month " ] && $_POST [ " date_start ${ i } day " ]) {
2004-07-20 10:54:43 +02:00
$startday = $_POST [ " date_start ${ i}year"].'-'.$_POST["date_start${i}month"].'-'.$_POST["date_start${i } day " ];
2004-07-13 09:54:13 +02:00
}
2004-05-17 19:07:16 +02:00
if ( $_POST [ " date_end ${ i } year " ] && $_POST [ " date_end ${ i } month " ] && $_POST [ " date_end ${ i } day " ]) {
2004-07-13 09:54:13 +02:00
$endday = $_POST [ " date_end ${ i}year"].'-'.$_POST["date_end${i}month"].'-'.$_POST["date_end${i } day " ];
2004-05-17 19:07:16 +02:00
}
2004-07-13 09:54:13 +02:00
$facture -> add_product ( $_POST [ " idprod ${ i}"],$_POST["qty${i}"],$_POST["remise_percent${i } " ], $startday , $endday );
2004-05-17 19:07:16 +02:00
2004-07-13 09:54:13 +02:00
}
}
2003-10-12 16:41:22 +02:00
$facid = $facture -> create ( $user );
2004-07-13 09:54:13 +02:00
2004-02-10 20:02:19 +01:00
if ( $facid )
{
Header ( " Location: facture.php?facid= " . $facid );
}
2003-10-12 16:41:22 +02:00
}
else
2003-09-09 18:06:22 +02:00
{
2003-11-24 11:15:11 +01:00
/*
* Propale
*/
2004-05-15 17:55:25 +02:00
if ( $_POST [ " propalid " ])
2003-11-24 11:15:11 +01:00
{
2004-05-15 17:55:25 +02:00
$facture -> propalid = $_POST [ " propalid " ];
2003-10-12 16:41:22 +02:00
2003-11-24 11:15:11 +01:00
$facid = $facture -> create ( $user );
if ( $facid )
{
$prop = New Propal ( $db );
2004-05-15 17:55:25 +02:00
if ( $prop -> fetch ( $_POST [ " propalid " ]) )
2003-11-24 11:15:11 +01:00
{
for ( $i = 0 ; $i < sizeof ( $prop -> lignes ) ; $i ++ )
{
2004-11-06 09:06:16 +01:00
// print "<pre>DEBUG: la propale pr<70> c<EFBFBD> dente en ligne " . $prop->lignes[$i]->libelle . " avait comme prix : " . $prop->lignes[$i]->price . " !</pre>\n";
2003-11-24 11:15:11 +01:00
$result = $facture -> addline ( $facid ,
addslashes ( $prop -> lignes [ $i ] -> libelle ),
$prop -> lignes [ $i ] -> subprice ,
$prop -> lignes [ $i ] -> qty ,
$prop -> lignes [ $i ] -> tva_tx ,
$prop -> lignes [ $i ] -> product_id ,
$prop -> lignes [ $i ] -> remise_percent );
}
}
else
{
print " Erreur " ;
}
}
}
2004-10-09 14:59:07 +02:00
2003-11-24 11:15:11 +01:00
/*
* Commande
*/
2004-05-15 17:55:25 +02:00
if ( $_POST [ " commandeid " ])
2003-09-09 18:06:22 +02:00
{
2004-05-15 17:55:25 +02:00
$facture -> commandeid = $_POST [ " commandeid " ];
2003-11-24 11:15:11 +01:00
$facid = $facture -> create ( $user );
if ( $facid )
2003-10-12 16:41:22 +02:00
{
2003-11-24 11:15:11 +01:00
$comm = New Commande ( $db );
2004-05-15 17:55:25 +02:00
if ( $comm -> fetch ( $_POST [ " commandeid " ]) )
2003-10-12 16:41:22 +02:00
{
2003-11-24 11:15:11 +01:00
$lines = $comm -> fetch_lignes ();
2004-02-05 16:53:51 +01:00
for ( $i = 0 ; $i < sizeof ( $lines ) ; $i ++ )
2003-11-24 11:15:11 +01:00
{
$result = $facture -> addline ( $facid ,
addslashes ( $lines [ $i ] -> description ),
$lines [ $i ] -> subprice ,
$lines [ $i ] -> qty ,
$lines [ $i ] -> tva_tx ,
$lines [ $i ] -> product_id ,
$lines [ $i ] -> remise_percent );
}
}
else
{
print " Erreur " ;
2003-10-12 16:41:22 +02:00
}
}
else
2003-09-09 18:06:22 +02:00
{
2004-07-20 10:54:43 +02:00
print " <p><b>Erreur : la facture n'a pas <20> t<EFBFBD> cr<63> <72> e, v<> rifier le num<75> ro !</b> " ;
print " <p>Retour <20> la <a href= \" propal.php?propalid= $propalid\ " > propale </ a > " ;
print $db -> error ();
2003-09-09 18:06:22 +02:00
}
}
2004-07-15 11:40:54 +02:00
if ( $facid )
{
Header ( " Location: facture.php?facid= " . $facid );
}
2003-09-09 18:06:22 +02:00
}
}
}
2004-10-09 14:59:07 +02:00
2003-04-14 18:24:14 +02:00
/*
*
*/
2005-01-08 01:50:59 +01:00
if ( $_POST [ " action " ] == 'confirm_valid' && $_POST [ " confirm " ] == " yes " && $user -> rights -> facture -> valider )
2002-12-14 17:25:46 +01:00
{
$fac = new Facture ( $db );
2004-07-13 15:49:54 +02:00
$fac -> fetch ( $_GET [ " facid " ]);
2003-09-23 19:50:20 +02:00
$soc = new Societe ( $db );
$soc -> fetch ( $fac -> socidp );
2004-07-13 15:49:54 +02:00
$result = $fac -> set_valid ( $fac -> id , $user , $soc );
2003-04-13 16:47:33 +02:00
if ( $result )
{
2004-07-20 10:54:43 +02:00
facture_pdf_create ( $db , $fac -> id );
2003-04-13 16:47:33 +02:00
}
2002-04-30 12:44:42 +02:00
}
2004-07-13 15:28:30 +02:00
if ( $_GET [ " action " ] == 'payed' && $user -> rights -> facture -> paiement )
2002-12-14 17:25:46 +01:00
{
$fac = new Facture ( $db );
2004-07-13 15:28:30 +02:00
$result = $fac -> set_payed ( $_GET [ " facid " ]);
2002-04-30 12:44:42 +02:00
}
2004-05-15 17:55:25 +02:00
if ( $_POST [ " action " ] == 'setremise' && $user -> rights -> facture -> creer )
2003-09-06 02:31:41 +02:00
{
$fac = new Facture ( $db );
$fac -> fetch ( $facid );
2004-05-15 17:55:25 +02:00
$fac -> set_remise ( $user , $_POST [ " remise " ]);
2003-09-06 02:31:41 +02:00
}
2004-07-19 10:36:53 +02:00
if ( $_POST [ " action " ] == 'addligne' && $user -> rights -> facture -> creer )
2003-02-01 20:45:45 +01:00
{
$fac = new Facture ( $db );
2004-07-19 23:27:20 +02:00
$fac -> fetch ( $_POST [ " facid " ]);
2004-05-17 19:07:16 +02:00
$datestart = '' ;
$dateend = '' ;
if ( $_POST [ " date_startyear " ] && $_POST [ " date_startmonth " ] && $_POST [ " date_startday " ]) {
$datestart = $_POST [ " date_startyear " ] . '-' . $_POST [ " date_startmonth " ] . '-' . $_POST [ " date_startday " ];
}
if ( $_POST [ " date_endyear " ] && $_POST [ " date_endmonth " ] && $_POST [ " date_endday " ]) {
$dateend = $_POST [ " date_endyear " ] . '-' . $_POST [ " date_endmonth " ] . '-' . $_POST [ " date_endday " ];
}
2004-07-19 23:27:20 +02:00
$result = $fac -> addline ( $_POST [ " facid " ],
2004-07-20 10:54:43 +02:00
$_POST [ " desc " ],
$_POST [ " pu " ],
$_POST [ " qty " ],
$_POST [ " tva_tx " ],
0 ,
$_POST [ " remise_percent " ],
$datestart ,
$dateend
);
2004-07-19 23:27:20 +02:00
$_GET [ " facid " ] = $_POST [ " facid " ]; // Pour r<> affichage de la fiche en cours d'<27> dition
2003-02-01 20:45:45 +01:00
}
2004-12-14 11:52:49 +01:00
if ( $_POST [ " action " ] == 'updateligne' && $user -> rights -> facture -> creer && $_POST [ " save " ] == $langs -> trans ( " Save " ))
2003-02-01 22:12:52 +01:00
{
2004-07-19 23:27:20 +02:00
$fac = new Facture ( $db , " " , $_POST [ " facid " ]);
$fac -> fetch ( $_POST [ " facid " ]);
2004-05-17 19:07:16 +02:00
$datestart = '' ;
$dateend = '' ;
if ( $_POST [ " date_startyear " ] && $_POST [ " date_startmonth " ] && $_POST [ " date_startday " ]) {
$datestart = $_POST [ " date_startyear " ] . '-' . $_POST [ " date_startmonth " ] . '-' . $_POST [ " date_startday " ];
}
if ( $_POST [ " date_endyear " ] && $_POST [ " date_endmonth " ] && $_POST [ " date_endday " ]) {
$dateend = $_POST [ " date_endyear " ] . '-' . $_POST [ " date_endmonth " ] . '-' . $_POST [ " date_endday " ];
}
2004-07-19 23:27:20 +02:00
$result = $fac -> updateline ( $_POST [ " rowid " ],
2004-05-15 17:55:25 +02:00
$_POST [ " desc " ],
$_POST [ " price " ],
$_POST [ " qty " ],
2004-05-17 19:07:16 +02:00
$_POST [ " remise_percent " ],
$datestart ,
$dateend
);
2004-07-19 23:27:20 +02:00
$_GET [ " facid " ] = $_POST [ " facid " ]; // Pour r<> affichage de la fiche en cours d'<27> dition
2003-02-01 22:12:52 +01:00
}
2004-12-14 11:52:49 +01:00
if ( $_POST [ " action " ] == 'updateligne' && $user -> rights -> facture -> creer && $_POST [ " cancel " ] == $langs -> trans ( " Cancel " ))
{
2004-12-16 10:45:55 +01:00
Header ( " Location: facture.php?facid= " . $_POST [ " facid " ]); // Pour r<> affichage de la fiche en cours d'<27> dition
2004-12-14 11:52:49 +01:00
}
2004-07-19 23:27:20 +02:00
if ( $_GET [ " action " ] == 'deleteline' && $user -> rights -> facture -> creer )
2003-02-01 20:45:45 +01:00
{
2004-07-19 23:27:20 +02:00
$fac = new Facture ( $db , " " , $_GET [ " facid " ]);
$fac -> fetch ( $_GET [ " facid " ]);
$result = $fac -> deleteline ( $_GET [ " rowid " ]);
2003-02-01 20:45:45 +01:00
}
2004-05-15 17:55:25 +02:00
if ( $_POST [ " action " ] == 'confirm_delete' && $_POST [ " confirm " ] == yes )
2002-12-14 17:25:46 +01:00
{
2003-10-21 13:44:01 +02:00
if ( $user -> rights -> facture -> supprimer )
{
$fac = new Facture ( $db );
2004-07-21 12:33:11 +02:00
$fac -> delete ( $_GET [ " facid " ]);
2003-11-24 11:15:11 +01:00
$_GET [ " facid " ] = 0 ;
2004-07-21 12:33:11 +02:00
Header ( " Location: facture.php " );
2003-10-21 13:44:01 +02:00
}
2002-04-30 12:44:42 +02:00
}
2004-07-28 00:37:51 +02:00
if ( $_POST [ " action " ] == 'confirm_canceled' && $_POST [ " confirm " ] == yes )
{
if ( $user -> rights -> facture -> supprimer )
{
$fac = new Facture ( $db );
$result = $fac -> set_canceled ( $_GET [ " facid " ]);
$_GET [ " facid " ] = 0 ;
Header ( " Location: facture.php " );
}
}
2003-02-02 16:01:56 +01:00
/*
*
*/
2004-05-15 17:55:25 +02:00
if ( $_POST [ " action " ] == 'send' || $_POST [ " action " ] == 'relance' )
2003-02-02 16:01:56 +01:00
{
2004-07-19 23:27:20 +02:00
$fac = new Facture ( $db , " " , $_POST [ " facid " ]);
if ( $fac -> fetch ( $_POST [ " facid " ]) )
2003-02-02 16:01:56 +01:00
{
2004-10-24 13:15:21 +02:00
$forbidden_chars = array ( " / " , " \\ " , " : " , " * " , " ? " , " \" " , " < " , " > " , " | " , " [ " , " ] " , " , " , " ; " , " = " );
$facref = str_replace ( $forbidden_chars , " _ " , $fac -> ref );
2004-12-23 19:28:58 +01:00
$file = $conf -> facture -> dir_output . " / " . $facref . " / " . $facref . " .pdf " ;
2004-02-10 20:23:55 +01:00
2004-07-20 10:54:43 +02:00
if ( is_readable ( $file ))
{
if ( $_POST [ " sendto " ]) {
// Le destinataire a <20> t<EFBFBD> fourni via le champ libre
$sendto = $_POST [ " sendto " ];
$sendtoid = 0 ;
}
2004-10-23 18:55:07 +02:00
elseif ( $_POST [ " receiver " ]) {
2004-07-20 10:54:43 +02:00
// Le destinataire a <20> t<EFBFBD> fourni via la liste d<> roulante
$soc = new Societe ( $db , $fac -> socidp );
2004-10-23 18:55:07 +02:00
$sendto = $soc -> contact_get_email ( $_POST [ " receiver " ]);
$sendtoid = $_POST [ " receiver " ];
2004-07-20 10:54:43 +02:00
}
if ( strlen ( $sendto ))
{
if ( $_POST [ " action " ] == 'send' ) {
2004-08-12 23:35:59 +02:00
$subject = $langs -> trans ( " Bill " ) . " $fac->ref " ;
2004-07-20 10:54:43 +02:00
$actioncode = 9 ;
$actionmsg = " Envoy<EFBFBD> e <20> $sendto " ;
$actionmsg2 = " Envoi Facture par mail " ;
}
if ( $_POST [ " action " ] == 'relance' ) {
$subject = " Relance facture $fac->ref " ;
$actioncode = 10 ;
$actionmsg = " Relance envoy<6F> e <20> $sendto " ;
$actionmsg2 = " Relance Facture par mail " ;
}
$message = $_POST [ " message " ];
2005-01-11 21:26:22 +01:00
$from = $_POST [ " fromname " ] . " < " . $_POST [ " frommail " ] . " > " ;
$replyto = $_POST [ " replytoname " ] . " < " . $_POST [ " replytomail " ] . " > " ;
2004-11-06 09:59:26 +01:00
$filepath [ 0 ] = $file ;
$filename [ 0 ] = $fac -> ref . " .pdf " ;
$mimetype [ 0 ] = " application/pdf " ;
$filepath [ 1 ] = $_FILES [ 'addedfile' ][ 'tmp_name' ];
$filename [ 1 ] = $_FILES [ 'addedfile' ][ 'name' ];
$mimetype [ 1 ] = $_FILES [ 'addedfile' ][ 'type' ];
2004-07-20 10:54:43 +02:00
// Envoi de la facture
2005-01-11 21:26:22 +01:00
$mailfile = new CMailFile ( $subject , $sendto , $from , $message , $filepath , $mimetype , $filename , $sendtocc );
2004-11-06 09:59:26 +01:00
2004-07-20 10:54:43 +02:00
if ( $mailfile -> sendfile () )
{
$sendto = htmlentities ( $sendto );
2004-02-14 22:50:09 +01:00
2004-07-20 10:54:43 +02:00
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " actioncomm (datea,fk_action,fk_soc,note,fk_facture, fk_contact,fk_user_author, label, percent) VALUES (now(), ' $actioncode ' ,' $fac->socidp ' ,' $actionmsg ',' $fac->id ',' $sendtoid ',' $user->id ', ' $actionmsg2 ',100); " ;
2004-02-14 22:50:09 +01:00
2004-07-20 10:54:43 +02:00
if ( ! $db -> query ( $sql ) )
{
2005-01-11 21:26:22 +01:00
dolibarr_print_error ( $db );
2004-11-16 17:09:04 +01:00
}
else
{
// Renvoie sur la page de la facture
Header ( " Location: facture.php?facid= " . $fac -> id );
}
2004-02-10 20:23:55 +01:00
}
2004-07-20 10:54:43 +02:00
else
2003-02-02 16:01:56 +01:00
{
2004-09-18 14:33:45 +02:00
print $langs -> trans ( " ErrorFailedToSendMail " , $replyto , $sendto );
2004-07-20 10:54:43 +02:00
}
}
else
{
dolibarr_syslog ( " Le mail du destinataire est vide " );
}
}
else
{
dolibarr_syslog ( " Impossible de lire : " . $file );
}
2003-02-02 16:01:56 +01:00
}
2004-02-10 20:23:55 +01:00
else
{
2004-02-10 23:16:57 +01:00
dolibarr_syslog ( " Impossible de lire les donn<6E> es de la facture. Le fichier facture n'a peut-<2D> tre pas <20> t<EFBFBD> g<> n<EFBFBD> r<EFBFBD> . " );
2004-02-10 20:23:55 +01:00
}
2003-02-02 16:01:56 +01:00
}
2003-07-24 13:05:57 +02:00
/*
2004-02-14 22:50:09 +01:00
* G<EFBFBD> n<EFBFBD> rer ou reg<EFBFBD> n<EFBFBD> rer le PDF
2003-07-24 13:05:57 +02:00
*/
2004-07-19 23:27:20 +02:00
if ( $_GET [ " action " ] == 'pdf' )
2003-04-13 16:47:33 +02:00
{
2004-08-12 23:35:59 +02:00
// Generation de la facture d<> finie dans /includes/modules/facture/modules_facture.php
2004-12-23 19:28:58 +01:00
// G<> n<EFBFBD> re <20> galement le fichier meta dans le m$eme r<> pertoire (pour faciliter les recherches et indexation)
2004-07-19 23:27:20 +02:00
facture_pdf_create ( $db , $_GET [ " facid " ]);
2003-04-13 16:47:33 +02:00
}
2004-08-12 23:35:59 +02:00
2004-09-18 14:33:45 +02:00
llxHeader ( '' , $langs -> trans ( " Bill " ), 'Facture' );
2004-02-10 20:02:19 +01:00
2003-05-16 15:30:46 +02:00
$html = new Form ( $db );
2003-04-13 16:47:33 +02:00
2004-06-09 20:37:17 +02:00
2003-09-03 16:00:35 +02:00
/*********************************************************************
2002-05-11 20:53:13 +02:00
*
* Mode creation
*
2003-09-03 16:00:35 +02:00
************************************************************************/
2003-11-24 11:15:11 +01:00
if ( $_GET [ " action " ] == 'create' )
2002-12-14 17:25:46 +01:00
{
2004-09-18 14:33:45 +02:00
2002-05-11 20:53:13 +02:00
print_titre ( " Emettre une facture " );
2004-02-05 16:53:51 +01:00
2003-08-11 21:58:31 +02:00
if ( $propalid )
2002-12-14 17:25:46 +01:00
{
2003-09-06 02:31:41 +02:00
$sql = " SELECT s.nom, s.prefix_comm, s.idp, p.price, p.remise, p.remise_percent, p.tva, p.total, p.ref, " . $db -> pdate ( " p.datep " ) . " as dp, c.id as statut, c.label as lst " ;
2004-01-30 11:16:56 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " societe as s, " . MAIN_DB_PREFIX . " propal as p, " . MAIN_DB_PREFIX . " c_propalst as c " ;
2003-05-16 22:35:47 +02:00
$sql .= " WHERE p.fk_soc = s.idp AND p.fk_statut = c.id " ;
2002-12-14 17:25:46 +01:00
$sql .= " AND p.rowid = $propalid " ;
2003-03-12 20:08:57 +01:00
}
else
{
2002-12-14 17:25:46 +01:00
$sql = " SELECT s.nom, s.prefix_comm, s.idp " ;
2004-01-30 11:16:56 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " societe as s " ;
2003-11-24 11:15:11 +01:00
$sql .= " WHERE s.idp = " . $_GET [ " socidp " ];
2002-12-14 17:25:46 +01:00
}
2002-05-11 20:53:13 +02:00
2003-11-24 11:15:11 +01:00
if ( $_GET [ " commandeid " ])
{
$commande = New Commande ( $db );
$commande -> fetch ( $_GET [ " commandeid " ]);
$societe_id = $commande -> soc_id ;
}
2004-01-08 23:58:10 +01:00
if ( $db -> query ( $sql ) )
2002-12-14 17:25:46 +01:00
{
$num = $db -> num_rows ();
2003-08-11 21:58:31 +02:00
if ( $num )
{
2004-10-23 18:55:07 +02:00
$obj = $db -> fetch_object ();
2003-08-27 13:21:08 +02:00
$soc = new Societe ( $db );
2004-01-09 00:20:05 +01:00
$soc -> fetch ( $obj -> idp );
2003-08-27 13:21:08 +02:00
2004-07-19 23:27:20 +02:00
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '" method="post">' ;
2003-08-11 21:58:31 +02:00
print '<input type="hidden" name="action" value="add">' ;
2004-01-09 00:20:05 +01:00
print '<input type="hidden" name="socid" value="' . $obj -> idp . '">' . " \n " ;
2003-09-14 10:19:55 +02:00
print '<input type="hidden" name="remise_percent" value="0">' ;
2004-10-02 16:25:50 +02:00
print '<table class="border" width="100%">' ;
2003-08-11 21:58:31 +02:00
2004-11-26 02:02:06 +01:00
print '<tr><td>' . $langs -> trans ( " Company " ) . ' :</td><td>' . $soc -> nom . '</td>' ;
2004-12-21 21:06:17 +01:00
print '<td class="border">' . $langs -> trans ( " Comments " ) . '</td></tr>' ;
2003-09-14 10:19:55 +02:00
2004-09-18 14:33:45 +02:00
print '<tr><td>' . $langs -> trans ( " Author " ) . ' :</td><td>' . $user -> fullname . '</td>' ;
2003-08-11 21:58:31 +02:00
2004-12-21 21:06:17 +01:00
print '<td rowspan="5" valign="top">' ;
print '<textarea name="note" wrap="soft" cols="60" rows="5"></textarea></td></tr>' ;
2003-08-11 21:58:31 +02:00
2004-09-18 14:33:45 +02:00
print '<tr><td>' . $langs -> trans ( " Date " ) . ' :</td><td>' ;
2003-08-11 21:58:31 +02:00
print_date_select ( time ());
2004-09-18 14:33:45 +02:00
print '</td></tr>' ;
2004-12-21 21:06:17 +01:00
2004-09-18 14:33:45 +02:00
print '<tr><td>' . $langs -> trans ( " Ref " ) . ' :</td><td>Provisoire</td></tr>' ;
2003-09-23 19:50:20 +02:00
print '<input name="facnumber" type="hidden" value="provisoire">' ;
2004-12-21 21:06:17 +01:00
2003-08-11 21:58:31 +02:00
print " <tr><td>Conditions de r<> glement :</td><td> " ;
2004-01-30 11:16:56 +01:00
$sql = " SELECT rowid, libelle FROM " . MAIN_DB_PREFIX . " cond_reglement ORDER BY sortorder " ;
2003-08-11 21:58:31 +02:00
$result = $db -> query ( $sql );
$conds = array ();
if ( $result )
{
$num = $db -> num_rows ();
$i = 0 ;
while ( $i < $num )
{
2004-10-23 18:55:07 +02:00
$objp = $db -> fetch_object ();
2003-08-11 21:58:31 +02:00
$conds [ $objp -> rowid ] = $objp -> libelle ;
$i ++ ;
}
$db -> free ();
}
$html -> select_array ( " condid " , $conds );
print " </td></tr> " ;
2004-09-18 14:33:45 +02:00
if ( $conf -> projet -> enabled ) {
$langs -> load ( " projects " );
print '<tr><td>' . $langs -> trans ( " Project " ) . ' :</td><td>' ;
$proj = new Project ( $db );
$html -> select_array ( " projetid " , $proj -> liste_array ( $socidp ));
print " </td></tr> " ;
2004-12-21 21:06:17 +01:00
} else {
print " <tr><td colspan= \" 2 \" > </td></tr> " ;
2004-09-18 14:33:45 +02:00
}
2003-11-24 11:15:11 +01:00
if ( $_GET [ " propalid " ] > 0 )
2003-08-11 21:58:31 +02:00
{
2003-09-06 02:31:41 +02:00
$amount = ( $obj -> price );
print '<input type="hidden" name="amount" value="' . $amount . '">' . " \n " ;
print '<input type="hidden" name="total" value="' . $obj -> total . '">' . " \n " ;
print '<input type="hidden" name="remise" value="' . $obj -> remise . '">' . " \n " ;
print '<input type="hidden" name="remise_percent" value="' . $obj -> remise_percent . '">' . " \n " ;
print '<input type="hidden" name="tva" value="' . $obj -> tva . '">' . " \n " ;
2003-08-11 21:58:31 +02:00
print '<input type="hidden" name="propalid" value="' . $propalid . '">' ;
print '<tr><td>Proposition</td><td colspan="2">' . $obj -> ref . '</td></tr>' ;
2004-12-21 21:06:17 +01:00
print '<tr><td>' . $langs -> trans ( " TotalHT " ) . '</td><td colspan="2">' . price ( $amount ) . '</td></tr>' ;
print '<tr><td>' . $langs -> trans ( " VAT " ) . '</td><td colspan="2">' . price ( $obj -> tva ) . " </td></tr> " ;
2004-07-31 15:34:32 +02:00
print '<tr><td>' . $langs -> trans ( " TotalTTC " ) . '</td><td colspan="2">' . price ( $obj -> total ) . " </td></tr> " ;
2003-11-24 11:15:11 +01:00
}
elseif ( $_GET [ " commandeid " ] > 0 )
{
print '<input type="hidden" name="commandeid" value="' . $commande -> id . '">' ;
2004-12-21 21:06:17 +01:00
print '<tr><td>' . $langs -> trans ( " Order " ) . '</td><td colspan="2">' . $commande -> ref . '</td></tr>' ;
print '<tr><td>' . $langs -> trans ( " TotalHT " ) . '</td><td colspan="2">' . price ( $commande -> total_ht ) . '</td></tr>' ;
print '<tr><td>' . $langs -> trans ( " VAT " ) . '</td><td colspan="2">' . price ( $commande -> total_tva ) . " </td></tr> " ;
2004-07-31 15:34:32 +02:00
print '<tr><td>' . $langs -> trans ( " TotalTTC " ) . '</td><td colspan="2">' . price ( $commande -> total_ttc ) . " </td></tr> " ;
2003-11-24 11:15:11 +01:00
}
2003-08-13 01:05:01 +02:00
else
2003-08-11 21:58:31 +02:00
{
2004-03-24 15:09:33 +01:00
print '<tr><td colspan="3"> </td></tr>' ;
2003-08-13 01:05:01 +02:00
print '<tr><td colspan="3">' ;
2003-08-11 21:58:31 +02:00
/*
*
* Liste des elements
*
*/
2004-01-30 11:16:56 +01:00
$sql = " SELECT p.rowid,p.label,p.ref,p.price FROM " . MAIN_DB_PREFIX . " product as p " ;
2003-08-11 21:58:31 +02:00
$sql .= " WHERE envente = 1 " ;
2004-03-14 16:57:09 +01:00
$sql .= " ORDER BY p.nbvente DESC LIMIT " . $conf -> liste_limit ;
2003-08-11 21:58:31 +02:00
if ( $db -> query ( $sql ) )
{
2004-07-19 23:27:20 +02:00
$opt = " <option value= \" 0 \" selected></option> " ;
2003-08-11 21:58:31 +02:00
if ( $result )
{
$num = $db -> num_rows (); $i = 0 ;
while ( $i < $num )
{
2004-10-23 18:55:07 +02:00
$objp = $db -> fetch_object ();
2003-08-11 21:58:31 +02:00
$opt .= " <option value= \" $objp->rowid\ " > [ $objp -> ref ] $objp -> label : $objp -> price </ option > \n " ;
$i ++ ;
}
}
$db -> free ();
}
else
{
2004-12-21 21:06:17 +01:00
dolibarr_print_error ( $db );
2003-08-11 21:58:31 +02:00
}
2003-08-13 01:05:01 +02:00
2004-12-23 19:28:58 +01:00
print '<table class="noborder">' ;
2004-12-21 21:06:17 +01:00
print '<tr><td>Services/Produits pr<70> d<EFBFBD> finis</td><td>' . $langs -> trans ( " Qty " ) . '</td><td>' . $langs -> trans ( " Discount " ) . '</td><td> </td>' ;
2004-07-20 10:54:43 +02:00
if ( $conf -> service -> enabled ) {
print '<td>Si produit de type service <20> dur<75> e limit<69> e</td></tr>' ;
2004-05-17 19:07:16 +02:00
}
for ( $i = 1 ; $i <= $NBLINES ; $i ++ )
2003-08-11 21:58:31 +02:00
{
print '<tr><td><select name="idprod' . $i . '">' . $opt . '</select></td>' ;
2003-10-10 20:35:42 +02:00
print '<td><input type="text" size="3" name="qty' . $i . '" value="1"></td>' ;
2004-05-17 19:07:16 +02:00
print '<td><input type="text" size="4" name="remise_percent' . $i . '" value="0">%</td>' ;
print '<td> </td>' ;
// Si le module service est actif, on propose des dates de d<> but et fin <20> la ligne
2004-07-20 10:54:43 +02:00
if ( $conf -> service -> enabled ) {
print '<td>' ;
2004-05-17 19:07:16 +02:00
print 'Du ' ;
2004-07-20 10:54:43 +02:00
print $html -> select_date ( '' , " date_start $i " , 0 , 0 , 1 );
2004-05-17 19:07:16 +02:00
print ' au ' ;
print $html -> select_date ( '' , " date_end $i " , 0 , 0 , 1 );
2004-07-20 10:54:43 +02:00
print '</td>' ;
2004-05-17 19:07:16 +02:00
}
print " </tr> \n " ;
2003-10-12 16:41:22 +02:00
}
2003-08-13 01:05:01 +02:00
print '</table>' ;
print '</td></tr>' ;
2003-08-11 21:58:31 +02:00
}
2003-10-12 16:41:22 +02:00
/*
* Factures r<EFBFBD> currentes
*
*/
2003-11-24 11:15:11 +01:00
if ( $_GET [ " propalid " ] == 0 && $_GET [ " commandeid " ] == 0 )
2003-10-12 16:41:22 +02:00
{
2004-01-30 11:16:56 +01:00
$sql = " SELECT r.rowid, r.titre, r.amount FROM " . MAIN_DB_PREFIX . " facture_rec as r " ;
2003-11-24 11:15:11 +01:00
$sql .= " WHERE r.fk_soc = " . $soc -> id ;
2003-10-12 16:41:22 +02:00
if ( $db -> query ( $sql ) )
{
$num = $db -> num_rows ();
$i = 0 ;
if ( $num > 0 )
{
print '<tr><td colspan="3">Factures r<> currentes : <select name="fac_rec">' ;
print '<option value="0" selected></option>' ;
while ( $i < $num )
{
2004-10-23 18:55:07 +02:00
$objp = $db -> fetch_object ();
2003-10-12 16:41:22 +02:00
print " <option value= \" $objp->rowid\ " > $objp -> titre : $objp -> amount </ option > \n " ;
$i ++ ;
}
print '</select></td></tr>' ;
}
$db -> free ();
}
else
{
2004-12-23 19:28:58 +01:00
dolibarr_print_error ( $db );
2003-10-12 16:41:22 +02:00
}
}
/*
*
*/
2004-05-17 19:07:16 +02:00
print '<tr><td colspan="3" align="center"><input type="submit" name="bouton" value="Cr<43> er brouillon"></td></tr>' ;
2003-08-13 01:05:01 +02:00
print " </form> \n " ;
print " </table> \n " ;
2003-09-09 18:06:22 +02:00
2003-11-24 11:15:11 +01:00
if ( $_GET [ " propalid " ])
2003-09-09 18:06:22 +02:00
{
/*
* Produits
*/
print_titre ( " Produits " );
2004-12-23 19:28:58 +01:00
print '<table class="noborder" width="100%">' ;
2004-08-07 03:06:49 +02:00
print '<tr class="liste_titre"><td>' . $langs -> trans ( " Ref " ) . '</td><td>Produit</td>' ;
2004-08-02 04:58:38 +02:00
print '<td align="right">' . $langs -> trans ( " Price " ) . '</td><td align="center">Remise</td><td align="center">Qt<51> .</td></tr>' ;
2003-09-09 18:06:22 +02:00
2003-10-11 15:45:58 +02:00
$sql = " SELECT pt.rowid, p.label as product, p.ref, pt.price, pt.qty, p.rowid as prodid, pt.remise_percent " ;
2004-01-30 11:16:56 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " propaldet as pt, " . MAIN_DB_PREFIX . " product as p WHERE pt.fk_product = p.rowid AND pt.fk_propal = $propalid " ;
2003-09-23 19:59:50 +02:00
$sql .= " ORDER BY pt.rowid ASC " ;
2003-09-09 18:06:22 +02:00
$result = $db -> query ( $sql );
if ( $result )
{
$num = $db -> num_rows ();
$i = 0 ;
$var = True ;
while ( $i < $num )
{
2004-10-23 18:55:07 +02:00
$objp = $db -> fetch_object ();
2003-09-09 18:06:22 +02:00
$var =! $var ;
2003-10-11 15:45:58 +02:00
print " <tr $bc[$var] ><td>[ $objp->ref ]</td> \n " ;
2003-09-09 18:06:22 +02:00
print '<td>' . $objp -> product . '</td>' ;
2004-03-24 15:09:33 +01:00
print " <td align= \" right \" > " . price ( $objp -> price ) . " </td> " ;
2003-10-11 15:45:58 +02:00
print '<td align="center">' . $objp -> remise_percent . ' %</td>' ;
2003-09-09 18:06:22 +02:00
print " <td align= \" center \" > " . $objp -> qty . " </td></tr> \n " ;
$i ++ ;
}
}
2003-10-11 15:45:58 +02:00
$sql = " SELECT pt.rowid, pt.description as product, pt.price, pt.qty, pt.remise_percent " ;
2004-01-30 11:16:56 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " propaldet as pt WHERE pt.fk_propal = $propalid AND pt.fk_product = 0 " ;
2003-10-11 15:45:58 +02:00
$sql .= " ORDER BY pt.rowid ASC " ;
if ( $db -> query ( $sql ))
{
$num = $db -> num_rows ();
$i = 0 ;
while ( $i < $num )
{
2004-10-23 18:55:07 +02:00
$objp = $db -> fetch_object ();
2003-10-11 15:45:58 +02:00
$var =! $var ;
print " <tr $bc[$var] ><td> </td> \n " ;
print '<td>' . $objp -> product . '</td>' ;
print '<td align="right">' . price ( $objp -> price ) . '</td>' ;
print '<td align="center">' . $objp -> remise_percent . ' %</td>' ;
print " <td align= \" center \" > " . $objp -> qty . " </td></tr> \n " ;
$i ++ ;
}
}
else
{
2004-12-23 19:28:58 +01:00
dolibarr_print_error ( $db );
2003-10-11 15:45:58 +02:00
}
2003-09-09 18:06:22 +02:00
print '</table>' ;
2003-11-24 11:15:11 +01:00
}
2004-08-12 23:35:59 +02:00
2003-11-24 11:15:11 +01:00
/*
* Produits dans la commande
*
*/
if ( $_GET [ " commandeid " ])
{
print_titre ( " Produits " );
2004-03-04 17:53:03 +01:00
print '<table class="noborder" width="100%" cellspacing="0" cellpadding="3">' ;
2004-08-07 03:06:49 +02:00
print '<tr class="liste_titre"><td>' . $langs -> trans ( " Ref " ) . '</td><td>Produit</td>' ;
2004-08-02 04:58:38 +02:00
print '<td align="right">' . $langs -> trans ( " Price " ) . '</td><td align="center">Remise</td><td align="center">Qt<51> .</td></tr>' ;
2003-11-24 11:15:11 +01:00
$sql = " SELECT pt.rowid, p.label as product, p.ref, pt.subprice, pt.qty, p.rowid as prodid, pt.remise_percent " ;
2004-02-05 16:53:51 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " commandedet as pt, " . MAIN_DB_PREFIX . " product as p " ;
$sql .= " WHERE pt.fk_product = p.rowid AND pt.fk_commande = " . $commande -> id ;
2003-11-24 11:15:11 +01:00
$sql .= " ORDER BY pt.rowid ASC " ;
2004-02-05 16:53:51 +01:00
2003-11-24 11:15:11 +01:00
$result = $db -> query ( $sql );
if ( $result )
{
$num = $db -> num_rows ();
$i = 0 ;
$var = True ;
while ( $i < $num )
{
2004-10-23 18:55:07 +02:00
$objp = $db -> fetch_object ();
2003-11-24 11:15:11 +01:00
$var =! $var ;
print " <tr $bc[$var] ><td>[ $objp->ref ]</td> \n " ;
print '<td>' . $objp -> product . '</td>' ;
2004-02-05 16:53:51 +01:00
print '<td align="right">' . price ( $objp -> subprice ) . '</td>' ;
2003-11-24 11:15:11 +01:00
print '<td align="center">' . $objp -> remise_percent . ' %</td>' ;
2004-02-05 16:53:51 +01:00
print '<td align="center">' . $objp -> qty . '</td></tr>' ;
2003-11-24 11:15:11 +01:00
$i ++ ;
}
}
else
{
2004-12-23 19:28:58 +01:00
dolibarr_print_error ( $db );
2003-11-24 11:15:11 +01:00
}
print '</table>' ;
}
2003-08-11 21:58:31 +02:00
}
2002-12-14 17:25:46 +01:00
}
else
{
2004-08-15 17:04:24 +02:00
dolibarr_print_error ( $db );
2002-04-30 12:44:42 +02:00
}
2002-12-14 17:25:46 +01:00
}
else
/* *************************************************************************** */
/* */
2003-11-21 19:25:03 +01:00
/* Mode fiche */
2002-12-14 17:25:46 +01:00
/* */
/* *************************************************************************** */
{
2005-01-08 01:50:59 +01:00
2003-11-21 19:25:03 +01:00
if ( $_GET [ " facid " ] > 0 )
{
2003-07-12 12:33:55 +02:00
$fac = New Facture ( $db );
2003-11-21 19:25:03 +01:00
if ( $fac -> fetch ( $_GET [ " facid " ], $user -> societe_id ) > 0 )
2005-01-08 01:50:59 +01:00
{
2003-09-09 18:06:22 +02:00
$soc = new Societe ( $db , $fac -> socidp );
$soc -> fetch ( $fac -> socidp );
2005-01-08 01:50:59 +01:00
2003-09-09 18:06:22 +02:00
$author = new User ( $db );
$author -> id = $fac -> user_author ;
$author -> fetch ();
2003-10-21 13:44:01 +02:00
2004-09-18 14:33:45 +02:00
$h = 0 ;
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/compta/facture.php?facid=' . $fac -> id ;
2004-11-26 01:32:31 +01:00
$head [ $h ][ 1 ] = $langs -> trans ( " CardBill " );
2004-09-18 14:33:45 +02:00
$hselected = $h ;
$h ++ ;
2004-10-07 11:37:51 +02:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/compta/facture/apercu.php?facid=' . $fac -> id ;
$head [ $h ][ 1 ] = $langs -> trans ( " Apercu " );
$h ++ ;
2005-01-07 14:40:51 +01:00
if ( $fac -> mode_reglement == 3 )
{
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/compta/facture/prelevement.php?facid=' . $fac -> id ;
$head [ $h ][ 1 ] = $langs -> trans ( " Pr<EFBFBD> l<EFBFBD> vement " );
$h ++ ;
}
2004-09-18 14:33:45 +02:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/compta/facture/note.php?facid=' . $fac -> id ;
$head [ $h ][ 1 ] = $langs -> trans ( " Note " );
$h ++ ;
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/compta/facture/info.php?facid=' . $fac -> id ;
$head [ $h ][ 1 ] = $langs -> trans ( " Info " );
$h ++ ;
2004-11-26 01:32:31 +01:00
dolibarr_fiche_head ( $head , $hselected , $langs -> trans ( " Bill " ) . " : $fac->ref " );
2004-05-25 16:08:56 +02:00
2003-10-21 13:44:01 +02:00
/*
* Confirmation de la suppression de la facture
*
*/
2003-11-24 11:15:11 +01:00
if ( $_GET [ " action " ] == 'delete' )
2003-10-21 13:44:01 +02:00
{
2004-07-19 23:27:20 +02:00
$html -> form_confirm ( $_SERVER [ " PHP_SELF " ] . " ?facid= $fac->id " , " Supprimer la facture " , " Etes-vous s<> r de vouloir supprimer cette facture ? " , " confirm_delete " );
2003-10-21 13:44:01 +02:00
}
2004-07-28 00:37:51 +02:00
/*
* Confirmation du classement abandonn<EFBFBD>
*
*/
if ( $_GET [ " action " ] == 'canceled' )
{
$html -> form_confirm ( $_SERVER [ " PHP_SELF " ] . " ?facid= $fac->id " , " Classer la facture <20> l'<27> tat 'Abandonn<6E> e' " , " La totalit<69> du paiement de cette facture n'a pas <20> t<EFBFBD> r<> alis<69> e. Etes-vous s<> r de vouloir abandonner d<> finitivement cette facture ? " , " confirm_canceled " );
}
2003-09-09 18:06:22 +02:00
2003-10-21 13:44:01 +02:00
/*
* Confirmation de la validation
*
*/
2004-07-13 15:49:54 +02:00
if ( $_GET [ " action " ] == 'valid' )
2003-10-21 13:44:01 +02:00
{
$numfa = facture_get_num ( $soc );
2004-08-15 17:04:24 +02:00
$html -> form_confirm ( " facture.php?facid= $fac->id " , " Valider la facture sous la r<> f<EFBFBD> rence no " . $numfa , " Etes-vous s<> r de vouloir valider cette facture avec la r<> f<EFBFBD> rence no $numfa ? " , " confirm_valid " );
2003-10-21 13:44:01 +02:00
}
2003-09-09 18:06:22 +02:00
/*
* Facture
*/
2004-11-26 01:54:45 +01:00
print '<table class="border" width="100%">' ;
2004-11-26 02:02:06 +01:00
print '<tr><td>' . $langs -> trans ( " Company " ) . '</td>' ;
2004-09-18 14:33:45 +02:00
print '<td colspan="3">' ;
2003-09-11 22:18:51 +02:00
print '<b><a href="fiche.php?socid=' . $soc -> id . '">' . $soc -> nom . '</a></b></td>' ;
2003-09-09 18:06:22 +02:00
print " <td>Conditions de r<> glement : " . $fac -> cond_reglement . " </td></tr> " ;
2004-09-18 14:33:45 +02:00
print '<tr><td>' . $langs -> trans ( " Date " ) . '</td>' ;
2003-09-09 18:06:22 +02:00
print " <td colspan= \" 3 \" > " . strftime ( " %A %d %B %Y " , $fac -> date ) . " </td> \n " ;
print " <td>Date limite de r<> glement : " . strftime ( " %d %B %Y " , $fac -> date_lim_reglement ) . " </td></tr> " ;
2003-10-22 16:24:13 +02:00
2004-09-18 14:33:45 +02:00
print '<tr>' ;
if ( $conf -> projet -> enabled ) {
$langs -> load ( " projects " );
print '<td height=\"10\">' . $langs -> trans ( " Project " ) . '</td><td colspan="3">' ;
if ( $fac -> projetid > 0 )
{
$projet = New Project ( $db );
$projet -> fetch ( $fac -> projetid );
print '<a href="' . DOL_URL_ROOT . '/projet/fiche.php?id=' . $fac -> projetid . '">' . $projet -> title . '</a>' ;
}
else
{
print '<a href="facture.php?facid=' . $fac -> id . '&action=classer">Classer la facture</a>' ;
}
print " </td> " ;
} else {
print '<td height=\"10\"> </td><td colspan="3">' ;
print " </td> " ;
}
2004-07-20 10:54:43 +02:00
print '<td rowspan="8" valign="top">' ;
2003-10-11 15:45:58 +02:00
2003-09-09 18:06:22 +02:00
/*
* Paiements
*/
2004-09-18 14:33:45 +02:00
print $langs -> trans ( " Payments " ) . ' :<br>' ;
2004-07-20 10:54:43 +02:00
$sql = " SELECT " . $db -> pdate ( " datep " ) . " as dp, pf.amount, " ;
$sql .= " c.libelle as paiement_type, p.num_paiement, p.rowid " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " paiement as p, " . MAIN_DB_PREFIX . " c_paiement as c, " . MAIN_DB_PREFIX . " paiement_facture as pf " ;
$sql .= " WHERE pf.fk_facture = " . $fac -> id . " AND p.fk_paiement = c.id AND pf.fk_paiement = p.rowid " ;
$sql .= " ORDER BY dp DESC " ;
2003-03-23 16:53:03 +01:00
2004-07-20 10:54:43 +02:00
$result = $db -> query ( $sql );
2004-10-09 14:59:07 +02:00
2004-07-20 10:54:43 +02:00
if ( $result )
{
$num = $db -> num_rows ();
$i = 0 ; $total = 0 ;
2004-10-09 14:59:07 +02:00
print '<table class="noborder" width="100%">' ;
2004-11-26 01:54:45 +01:00
print '<tr class="liste_titre"><td>' . $langs -> trans ( " Date " ) . '</td><td>' . $langs -> trans ( " Type " ) . '</td>' ;
2004-09-18 14:33:45 +02:00
print '<td align="right">' . $langs -> trans ( " Amount " ) . '</td><td> </td></tr>' ;
2003-02-01 20:45:45 +01:00
2004-07-20 10:54:43 +02:00
$var = True ;
while ( $i < $num )
{
2004-10-23 18:55:07 +02:00
$objp = $db -> fetch_object ();
2004-07-20 10:54:43 +02:00
$var =! $var ;
print " <tr $bc[$var] ><td> " ;
print '<a href="' . DOL_URL_ROOT . '/compta/paiement/fiche.php?id=' . $objp -> rowid . '">' . img_file () . '</a>' ;
print " " . strftime ( " %d %B %Y " , $objp -> dp ) . " </td> \n " ;
print " <td> $objp->paiement_type $objp->num_paiement </td> \n " ;
2004-12-04 21:19:53 +01:00
print '<td align="right">' . price ( $objp -> amount ) . " </td><td> " . $conf -> monnaie . " </td> \n " ;
2004-07-20 10:54:43 +02:00
print " </tr> " ;
$totalpaye += $objp -> amount ;
$i ++ ;
}
2003-02-01 20:45:45 +01:00
2004-07-20 10:54:43 +02:00
if ( $fac -> paye == 0 )
{
2004-12-04 21:19:53 +01:00
print " <tr><td colspan= \" 2 \" align= \" right \" >Total d<> j<EFBFBD> pay<61> :</td><td align= \" right \" ><b> " . price ( $totalpaye ) . " </b></td><td> " . $conf -> monnaie . " </td></tr> \n " ;
2004-07-20 10:54:43 +02:00
print " <tr><td colspan= \" 2 \" align= \" right \" >Factur<75> :</td><td align= \" right \" style= \" border: 1px solid; \" > " . price ( $fac -> total_ttc ) . " </td><td> " . MAIN_MONNAIE . " </td></tr> \n " ;
2003-03-23 16:53:03 +01:00
2004-07-20 10:54:43 +02:00
$resteapayer = $fac -> total_ttc - $totalpaye ;
2002-04-30 12:44:42 +02:00
2004-07-20 10:54:43 +02:00
print " <tr><td colspan= \" 2 \" align= \" right \" >Reste <20> payer :</td> " ;
2004-12-04 21:19:53 +01:00
print " <td align= \" right \" style= \" border: 1px solid; \" bgcolor= \" #f0f0f0 \" ><b> " . price ( $resteapayer ) . " </b></td><td> " . $conf -> monnaie . " </td></tr> \n " ;
2004-07-20 10:54:43 +02:00
}
print " </table> " ;
$db -> free ();
} else {
print $db -> error ();
}
2003-03-23 16:53:03 +01:00
2004-07-20 10:54:43 +02:00
print " </td></tr> " ;
2003-07-21 15:05:24 +02:00
2004-08-02 04:12:01 +02:00
print " <tr><td height= \" 10 \" > " . $langs -> trans ( " Author " ) . " </td><td colspan= \" 3 \" > $author->fullname </td> " ;
2004-06-09 23:25:50 +02:00
2004-07-20 10:54:43 +02:00
print '<tr><td height=\"10\">Remise globale</td>' ;
print '<td align="right" colspan="2">' . $fac -> remise_percent . '</td>' ;
print '<td>%</td></tr>' ;
2004-09-18 14:33:45 +02:00
print '<tr><td height=\"10\">' . $langs -> trans ( " AmountHT " ) . '</td>' ;
2004-07-20 10:54:43 +02:00
print '<td align="right" colspan="2"><b>' . price ( $fac -> total_ht ) . '</b></td>' ;
2004-12-04 21:19:53 +01:00
print '<td>' . $conf -> monnaie . ' HT</td></tr>' ;
2004-07-20 10:54:43 +02:00
2004-09-18 14:33:45 +02:00
print '<tr><td height=\"10\">' . $langs -> trans ( " VAT " ) . '</td><td align="right" colspan="2">' . price ( $fac -> total_tva ) . '</td>' ;
2004-12-04 21:19:53 +01:00
print '<td>' . $conf -> monnaie . '</td></tr>' ;
2004-09-18 14:33:45 +02:00
print '<tr><td height=\"10\">' . $langs -> trans ( " AmountTTC " ) . '</td><td align="right" colspan="2">' . price ( $fac -> total_ttc ) . '</td>' ;
2004-12-04 21:19:53 +01:00
print '<td>' . $conf -> monnaie . ' TTC</td></tr>' ;
2004-08-29 21:03:50 +02:00
print '<tr><td height=\"10\">' . $langs -> trans ( " Status " ) . '</td><td align="left" colspan="3">' . ( $fac -> get_libstatut ()) . '</td></tr>' ;
2004-07-20 10:54:43 +02:00
if ( $fac -> note )
{
2004-09-18 14:33:45 +02:00
print '<tr><td colspan="4">' . $langs -> trans ( " Note " ) . ' : ' . nl2br ( $fac -> note ) . " </td></tr> " ;
2004-07-20 10:54:43 +02:00
}
else {
2004-06-09 23:25:50 +02:00
print '<tr><td colspan="4"> </td></tr>' ;
2004-07-20 10:54:43 +02:00
}
2003-07-21 15:05:24 +02:00
2004-07-20 10:54:43 +02:00
print " </table><br> " ;
2003-09-06 02:31:41 +02:00
2004-07-20 10:54:43 +02:00
if ( $fac -> brouillon == 1 && $user -> rights -> facture -> creer )
{
print '<form action="facture.php?facid=' . $fac -> id . '" method="post">' ;
print '<input type="hidden" name="action" value="setremise">' ;
2004-11-26 01:54:45 +01:00
print '<table class="border"><tr><td>Remise</td><td align="right">' ;
2004-07-20 10:54:43 +02:00
print '<input type="text" name="remise" size="3" value="' . $fac -> remise_percent . '">%' ;
2004-10-02 16:25:50 +02:00
print '<input type="submit" value="' . $langs -> trans ( " Save " ) . '">' ;
2004-07-20 10:54:43 +02:00
print '</td></tr></table></form>' ;
}
/*
* Lignes de factures
*
*/
$sql = " SELECT l.fk_product, l.description, l.price, l.qty, l.rowid, l.tva_taux, l.remise_percent, l.subprice, " . $db -> pdate ( " l.date_start " ) . " as date_start, " . $db -> pdate ( " l.date_end " ) . " as date_end " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " facturedet as l WHERE l.fk_facture = $fac->id ORDER BY l.rowid " ;
2003-09-06 02:31:41 +02:00
2004-07-20 10:54:43 +02:00
$result = $db -> query ( $sql );
if ( $result )
{
$num_lignes = $db -> num_rows ();
$i = 0 ; $total = 0 ;
2003-03-23 16:53:03 +01:00
2004-09-18 19:56:30 +02:00
echo '<table class="noborder" width="100%">' ;
2004-07-20 10:54:43 +02:00
if ( $num_lignes )
{
print " <tr class= \" liste_titre \" > " ;
2004-08-29 21:03:50 +02:00
print '<td width="54%">' . $langs -> trans ( " Description " ) . '</td>' ;
2004-09-18 14:33:45 +02:00
print '<td width="8%" align="right">' . $langs -> trans ( " VAT " ) . '</td>' ;
2004-07-20 10:54:43 +02:00
print '<td width="12%" align="right">P.U. HT</td>' ;
2004-09-18 14:33:45 +02:00
print '<td width="8%" align="right">' . $langs -> trans ( " Quantity " ) . '</td>' ;
2004-07-20 10:54:43 +02:00
print '<td width="8%" align="right">Remise</td>' ;
2004-09-18 14:33:45 +02:00
print '<td width="10%" align="right">' . $langs -> trans ( " AmountHT " ) . '</td>' ;
2004-07-20 10:54:43 +02:00
print '<td> </td><td> </td>' ;
print " </tr> \n " ;
}
$var = True ;
while ( $i < $num_lignes )
{
2004-10-23 18:55:07 +02:00
$objp = $db -> fetch_object ();
2004-07-20 10:54:43 +02:00
$var =! $var ;
print " <tr $bc[$var] > " ;
if ( $objp -> fk_product > 0 )
{
print '<td><a href="' . DOL_URL_ROOT . '/product/fiche.php?id=' . $objp -> fk_product . '">' . stripslashes ( nl2br ( $objp -> description )) . '</a>' ;
2004-08-12 23:35:59 +02:00
if ( $objp -> date_start && $objp -> date_end ) { print " (Du " . dolibarr_print_date ( $objp -> date_start ) . " au " . dolibarr_print_date ( $objp -> date_end ) . " ) " ; }
if ( $objp -> date_start && ! $objp -> date_end ) { print " (A partir du " . dolibarr_print_date ( $objp -> date_start ) . " ) " ; }
if ( ! $objp -> date_start && $objp -> date_end ) { print " (Jusqu'au " . dolibarr_print_date ( $objp -> date_end ) . " ) " ; }
2004-07-20 10:54:43 +02:00
print '</td>' ;
}
else
{
print " <td> " . stripslashes ( nl2br ( $objp -> description ));
2004-08-12 23:35:59 +02:00
if ( $objp -> date_start && $objp -> date_end ) { print " (Du " . dolibarr_print_date ( $objp -> date_start ) . " au " . dolibarr_print_date ( $objp -> date_end ) . " ) " ; }
if ( $objp -> date_start && ! $objp -> date_end ) { print " (A partir du " . dolibarr_print_date ( $objp -> date_start ) . " ) " ; }
if ( ! $objp -> date_start && $objp -> date_end ) { print " (Jusqu'au " . dolibarr_print_date ( $objp -> date_end ) . " ) " ; }
2004-07-20 10:54:43 +02:00
print " </td> \n " ;
}
print '<td align="right">' . $objp -> tva_taux . ' %</td>' ;
print '<td align="right">' . price ( $objp -> subprice ) . " </td> \n " ;
print '<td align="right">' . $objp -> qty . '</td>' ;
if ( $objp -> remise_percent > 0 )
{
print '<td align="right">' . $objp -> remise_percent . " %</td> \n " ;
}
else
{
print '<td> </td>' ;
}
print '<td align="right">' . price ( $objp -> subprice * $objp -> qty * ( 100 - $objp -> remise_percent ) / 100 ) . " </td> \n " ;
2004-02-28 20:49:12 +01:00
2004-07-20 10:54:43 +02:00
// Icone d'edition et suppression
if ( $fac -> statut == 0 && $user -> rights -> facture -> creer )
{
2004-07-21 17:40:23 +02:00
print '<td align="right"><a href="facture.php?facid=' . $fac -> id . '&action=editline&rowid=' . $objp -> rowid . '">' ;
2004-07-20 10:54:43 +02:00
print img_edit ();
print '</a></td>' ;
2004-07-21 17:40:23 +02:00
print '<td align="right"><a href="facture.php?facid=' . $fac -> id . '&action=deleteline&rowid=' . $objp -> rowid . '">' ;
2004-07-20 10:54:43 +02:00
print img_delete ();
print '</a></td>' ;
}
else
{
print '<td> </td><td> </td>' ;
}
print " </tr> " ;
2003-03-23 16:53:03 +01:00
2004-07-20 10:54:43 +02:00
// Update ligne de facture
if ( $_GET [ " action " ] == 'editline' && $_GET [ " rowid " ] == $objp -> rowid )
{
2004-07-21 13:11:45 +02:00
print '<form action="facture.php" method="post">' ;
2004-07-20 10:54:43 +02:00
print '<input type="hidden" name="action" value="updateligne">' ;
print '<input type="hidden" name="facid" value="' . $fac -> id . '">' ;
print '<input type="hidden" name="rowid" value="' . $_GET [ " rowid " ] . '">' ;
print " <tr $bc[$var] > " ;
print '<td><textarea name="desc" cols="60" rows="2">' . stripslashes ( $objp -> description ) . '</textarea></td>' ;
print '<td align="right">' ;
//print $html->select_tva("tva_tx",$objp->tva_taux);
print " $objp->tva_taux % " ; // Taux tva d<> pend du produit, donc on ne doit pas pouvoir le changer ici
print '</td>' ;
print '<td align="right"><input size="8" type="text" name="price" value="' . price ( $objp -> subprice ) . '"></td>' ;
print '<td align="right"><input size="4" type="text" name="qty" value="' . $objp -> qty . '"></td>' ;
print '<td align="right"><input size="3" type="text" name="remise_percent" value="' . $objp -> remise_percent . '"> %</td>' ;
2004-12-14 11:52:49 +01:00
print '<td align="center" colspan="3"><input type="submit" name="save" value="' . $langs -> trans ( " Save " ) . '"><br /><input type="submit" name="cancel" value="' . $langs -> trans ( " Cancel " ) . '"></td>' ;
2004-07-20 10:54:43 +02:00
print '</tr>' . " \n " ;
2004-12-14 11:52:49 +01:00
if ( $conf -> service -> enabled )
{
print " <tr $bc[$var] > " ;
print '<td colspan="8">Si produit de type service <20> dur<75> e limit<69> e: Du ' ;
print $html -> select_date ( $objp -> date_start , " date_start " , 0 , 0 , $objp -> date_start ? 0 : 1 );
print ' au ' ;
print $html -> select_date ( $objp -> date_end , " date_end " , 0 , 0 , $objp -> date_end ? 0 : 1 );
print '</td>' ;
print '</tr>' . " \n " ;
}
2004-07-20 10:54:43 +02:00
print " </form> \n " ;
}
2003-03-23 16:53:03 +01:00
2004-07-20 10:54:43 +02:00
$total = $total + ( $objp -> qty * $objp -> price );
$i ++ ;
}
2003-03-23 16:53:03 +01:00
2004-07-20 10:54:43 +02:00
$db -> free ();
}
else
{
2004-09-18 14:33:45 +02:00
dolibarr_print_error ( $db -> error ());
2004-07-20 10:54:43 +02:00
}
2003-02-01 20:45:45 +01:00
2004-07-20 10:54:43 +02:00
/*
* Ajouter une ligne
*
*/
2004-12-14 11:52:49 +01:00
if ( $fac -> statut == 0 && $user -> rights -> facture -> creer && $_GET [ " action " ] <> 'editline' && $_GET [ " action " ] <> 'valid' )
2004-07-20 10:54:43 +02:00
{
print " <form action= \" " . $_SERVER [ " PHP_SELF " ] . " \" method= \" post \" > " ;
print " <tr class= \" liste_titre \" > " ;
2004-08-29 21:03:50 +02:00
print '<td width="54%">' . $langs -> trans ( " Description " ) . '</td>' ;
2004-09-18 14:33:45 +02:00
print '<td width="8%" align="right">' . $langs -> trans ( " VAT " ) . '</td>' ;
2004-07-20 10:54:43 +02:00
print '<td width="12%" align="right">P.U. HT</TD>' ;
2004-09-18 14:33:45 +02:00
print '<td width="8%" align="right">' . $langs -> trans ( " Quantity " ) . '</td>' ;
2004-07-20 10:54:43 +02:00
print '<td width="8%" align="right">Remise</td>' ;
print '<td> </td>' ;
print '<td> </td>' ;
print '<td> </td>' ;
print " </tr> \n " ;
print '<input type="hidden" name="facid" value="' . $fac -> id . '">' ;
print '<input type="hidden" name="action" value="addligne">' ;
print '<tr><td><textarea name="desc" cols="60" rows="2"></textarea></td>' ;
print '<td align="right">' ;
print $html -> select_tva ( " tva_tx " , $conf -> defaulttx );
print '</td>' ;
print '<td align="right"><input type="text" name="pu" size="8"></td>' ;
print '<td align="right"><input type="text" name="qty" value="1" size="2"></td>' ;
print '<td align="right"><input type="text" name="remise_percent" size="4" value="0"> %</td>' ;
2004-07-31 14:52:37 +02:00
print '<td align="center" colspan="3"><input type="submit" value="' . $langs -> trans ( " Add " ) . '"></td></tr>' ;
2004-07-20 10:54:43 +02:00
if ( $conf -> service -> enabled ) {
print '<tr>' ;
print '<td colspan="8">Si produit de type service <20> dur<75> e limit<69> e: Du ' ;
print $html -> select_date ( '' , " date_start " , 0 , 0 , 1 );
2004-05-17 19:07:16 +02:00
print ' au ' ;
print $html -> select_date ( '' , " date_end " , 0 , 0 , 1 );
print '</td>' ;
2003-03-23 16:53:03 +01:00
}
2004-07-20 10:54:43 +02:00
print '</tr>' ;
print " </form> " ;
}
print " </table><br> \n " ;
2003-11-09 18:24:14 +01:00
2004-07-20 10:54:43 +02:00
/*
* Fin Ajout ligne
*
*/
2004-12-22 21:19:24 +01:00
print " </div> \n " ;
2004-12-14 11:52:49 +01:00
if ( $user -> societe_id == 0 && $_GET [ " action " ] <> 'valid' && $_GET [ " action " ] <> 'editline' )
2004-07-20 10:54:43 +02:00
{
2004-08-22 12:01:45 +02:00
print " <div class= \" tabsAction \" > \n " ;
2004-12-22 21:19:24 +01:00
2004-07-20 10:54:43 +02:00
// Valider
if ( $fac -> statut == 0 && $num_lignes > 0 )
{
if ( $user -> rights -> facture -> valider )
{
2004-12-22 21:19:24 +01:00
print " <a class= \" tabAction \" href= \" facture.php?facid= " . $fac -> id . " &action=valid \" > " . $langs -> trans ( " Valid " ) . " </a> \n " ;
2004-07-20 10:54:43 +02:00
}
}
else
{
// G<> n<EFBFBD> rer
if ( $fac -> statut == 1 && ( $fac -> paye == 0 || $user -> admin ) && $user -> rights -> facture -> creer )
{
if ( $fac -> paye == 0 )
{
2004-12-22 21:19:24 +01:00
print " <a class= \" tabAction \" href= \" facture.php?facid= $fac->id &action=pdf \" > " . $langs -> trans ( " BuildPDF " ) . " </a> \n " ;
2004-07-20 10:54:43 +02:00
}
else
{
2004-12-22 21:19:24 +01:00
print " <a class= \" tabAction \" href= \" facture.php?facid= $fac->id &action=pdf \" > " . $langs -> trans ( " RebuildPDF " ) . " </a> \n " ;
2004-07-20 10:54:43 +02:00
}
}
}
2004-12-23 19:28:58 +01:00
2004-07-20 10:54:43 +02:00
// Supprimer
2004-12-21 21:06:17 +01:00
if ( $fac -> statut == 0 && $user -> rights -> facture -> supprimer && $_GET [ " action " ] != 'delete' )
2004-07-20 10:54:43 +02:00
{
2004-12-21 21:06:17 +01:00
print " <a class= \" butDelete \" href= \" facture.php?facid= $fac->id &action=delete \" > " . $langs -> trans ( " Delete " ) . " </a> " ;
2004-07-20 10:54:43 +02:00
}
// Envoyer
if ( $fac -> statut == 1 && $user -> rights -> facture -> envoyer )
{
2004-12-22 21:19:24 +01:00
print " <a class= \" tabAction \" href= \" " . $_SERVER [ " PHP_SELF " ] . " ?facid= $fac->id &action=presend \" > " . $langs -> trans ( " Send " ) . " </a> \n " ;
2004-07-20 10:54:43 +02:00
}
2004-02-14 15:50:04 +01:00
2004-07-20 10:54:43 +02:00
// Envoyer une relance
if ( $fac -> statut == 1 && price ( $resteapayer ) > 0 && $user -> rights -> facture -> envoyer )
{
2004-12-22 21:19:24 +01:00
print " <a class= \" tabAction \" href= \" " . $_SERVER [ " PHP_SELF " ] . " ?facid= $fac->id &action=prerelance \" > " . $langs -> trans ( " SendRemind " ) . " </a> \n " ;
2004-07-20 10:54:43 +02:00
}
2004-02-10 23:16:57 +01:00
2004-07-20 10:54:43 +02:00
// Emettre paiement
2005-01-09 21:34:35 +01:00
if ( $fac -> statut == 1 && $fac -> paye == 0 && $user -> rights -> facture -> paiement )
2004-07-20 10:54:43 +02:00
{
2004-12-22 21:19:24 +01:00
print " <a class= \" tabAction \" href= \" paiement.php?facid= " . $fac -> id . " &action=create \" > " . $langs -> trans ( " DoPaiement " ) . " </a> \n " ;
2004-07-20 10:54:43 +02:00
}
2004-02-14 15:50:04 +01:00
2004-07-20 10:54:43 +02:00
// Classer 'pay<61> '
if ( $fac -> statut == 1 && price ( $resteapayer ) <= 0
&& $fac -> paye == 0 && $user -> rights -> facture -> paiement )
{
2004-12-22 21:19:24 +01:00
print " <a class= \" tabAction \" href= \" " . $_SERVER [ " PHP_SELF " ] . " ?facid= $fac->id &action=payed \" > " . $langs -> trans ( " ClassifyPayed " ) . " </a> \n " ;
2004-07-20 10:54:43 +02:00
}
2004-02-14 15:50:04 +01:00
2004-07-28 00:37:51 +02:00
// Classer 'abandonn<6E> e' (possible si valid<69> e et pas encore classer pay<61> e)
if ( $fac -> statut == 1 && $fac -> paye == 0 && $user -> rights -> facture -> paiement )
2004-07-20 10:54:43 +02:00
{
2004-12-22 21:19:24 +01:00
print " <a class= \" tabAction \" href= \" " . $_SERVER [ " PHP_SELF " ] . " ?facid= $fac->id &action=canceled \" > " . $langs -> trans ( " ClassifyCanceled " ) . " </a> \n " ;
2004-07-20 10:54:43 +02:00
}
2004-03-24 15:09:33 +01:00
2004-07-20 10:54:43 +02:00
// R<> currente
if ( ! defined ( " FACTURE_DISABLE_RECUR " )) // Possibilit<69> de d<> sactiver les factures r<> currentes
{
if ( $fac -> statut > 0 )
{
2004-12-22 21:19:24 +01:00
print " <a class= \" tabAction \" href= \" facture/fiche-rec.php?facid= " . $fac -> id . " &action=create \" >R<> currente</a> \n " ;
2004-07-20 10:54:43 +02:00
}
}
2004-02-14 15:50:04 +01:00
2004-12-22 21:19:24 +01:00
print " </div> \n " ;
2004-02-14 15:50:04 +01:00
2004-07-20 10:54:43 +02:00
}
print " <p> \n " ;
2003-04-13 16:47:33 +02:00
2004-07-20 10:54:43 +02:00
/*
* Documents g<EFBFBD> n<EFBFBD> r<EFBFBD> s
*
2005-01-11 12:15:12 +01:00
* Le fichier de facture d<EFBFBD> taill<EFBFBD> e est de la forme
*
* REFFACTURE - XXXXXX - detail . pdf ou XXXXX est une forme diverse
*
2004-07-20 10:54:43 +02:00
*/
2004-11-09 09:58:35 +01:00
$forbidden_chars = array ( " / " , " \\ " , " : " , " * " , " ? " , " \" " , " < " , " > " , " | " , " [ " , " ] " , " , " , " ; " , " = " );
$facref = str_replace ( $forbidden_chars , " _ " , $fac -> ref );
2004-12-23 19:28:58 +01:00
$file = $conf -> facture -> dir_output . " / " . $facref . " / " . $facref . " .pdf " ;
2004-12-31 18:03:20 +01:00
2005-01-11 12:15:12 +01:00
$relativepath = " ${ facref}/${facref } .pdf " ;
$var = true ;
print '<table width="100%"><tr><td width="50%" valign="top">' ;
2004-05-15 17:55:25 +02:00
2004-07-20 10:54:43 +02:00
if ( file_exists ( $file ))
{
print_titre ( " Documents " );
2004-10-09 14:59:07 +02:00
print '<table class="border" width="100%">' ;
2003-09-23 19:50:20 +02:00
2004-12-31 18:03:20 +01:00
print " <tr $bc[$var] ><td> " . $langs -> trans ( " Bill " ) . " PDF</td> " ;
2004-07-20 10:54:43 +02:00
2004-12-31 18:03:20 +01:00
print '<td><a href="' . DOL_URL_ROOT . '/document.php?modulepart=facture&file=' . urlencode ( $relativepath ) . '">' . $fac -> ref . '.pdf</a></td>' ;
2004-07-20 10:54:43 +02:00
print '<td align="right">' . filesize ( $file ) . ' bytes</td>' ;
print '<td align="right">' . strftime ( " %d %b %Y %H:%M:%S " , filemtime ( $file )) . '</td>' ;
print '</tr>' ;
2004-11-09 09:58:35 +01:00
2004-12-23 19:28:58 +01:00
$dir = $conf -> facture -> dir_output . " / " . $facref . " / " ;
2004-11-09 09:58:35 +01:00
$handle = opendir ( $dir );
while (( $file = readdir ( $handle )) !== false )
2004-09-08 14:31:25 +02:00
{
2004-11-09 09:58:35 +01:00
if ( is_readable ( $dir . $file ) && substr ( $file , - 10 ) == 'detail.pdf' )
{
2004-12-31 18:03:20 +01:00
print " <tr $bc[$var] ><td>Facture d<> taill<6C> e</td> " ;
2005-01-11 12:16:43 +01:00
$relativepathdetail = " ${ facref } / $file " ;
2004-11-09 09:58:35 +01:00
2005-01-11 12:15:12 +01:00
print '<td><a href="' . DOL_URL_ROOT . '/document.php?modulepart=facture&file=' . urlencode ( $relativepathdetail ) . '">' . $file . '</a></td>' ;
print '<td align="right">' . filesize ( $dir . $file ) . ' bytes</td>' ;
print '<td align="right">' . strftime ( " %d %b %Y %H:%M:%S " , filemtime ( $dir . $file )) . '</td>' ;
2004-11-09 09:58:35 +01:00
print '</tr>' ;
}
2004-09-08 14:31:25 +02:00
}
2004-07-20 10:54:43 +02:00
print " </table> \n " ;
}
print '</td><td valign="top" width="50%">' ;
/*
2004-10-02 16:25:50 +02:00
* Liste des actions propres <EFBFBD> la facture
2004-07-20 10:54:43 +02:00
*
*/
2004-10-02 16:25:50 +02:00
$sql = " SELECT id, " . $db -> pdate ( " a.datea " ) . " as da, a.note, code " ;
2004-07-20 10:54:43 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " actioncomm as a, " . MAIN_DB_PREFIX . " user as u " ;
2004-10-06 15:00:15 +02:00
$sql .= " WHERE a.fk_user_author = u.rowid " ;
$sql .= " AND a.fk_action in (9,10) " ;
$sql .= " AND a.fk_soc = " . $fac -> socidp ;
$sql .= " AND a.fk_facture = " . $fac -> id ;
2004-05-15 17:55:25 +02:00
2004-07-20 10:54:43 +02:00
$result = $db -> query ( $sql );
if ( $result )
{
$num = $db -> num_rows ();
if ( $num )
{
2004-10-02 16:25:50 +02:00
print_titre ( $langs -> trans ( " ActionsOnBill " ));
2004-05-15 17:55:25 +02:00
2004-07-20 10:54:43 +02:00
$i = 0 ; $total = 0 ;
2004-09-18 19:56:30 +02:00
print '<table class="border" width="100%">' ;
2004-10-02 16:25:50 +02:00
print '<tr ' . $bc [ $var ] . '><td>' . $langs -> trans ( " Ref " ) . '</td><td>' . $langs -> trans ( " Date " ) . '</td><td>' . $langs -> trans ( " Action " ) . '</td><td>' . $langs -> trans ( " By " ) . '</td></tr>' ;
2004-09-18 14:33:45 +02:00
print " \n " ;
2004-07-20 10:54:43 +02:00
$var = True ;
while ( $i < $num )
{
2004-10-23 18:55:07 +02:00
$objp = $db -> fetch_object ();
2004-07-20 10:54:43 +02:00
$var =! $var ;
print " <tr $bc[$var] > " ;
2004-10-02 16:25:50 +02:00
print '<td><a href="' . DOL_URL_ROOT . '/comm/action/fiche.php?id=' . $objp -> id . '">' . $objp -> id . '</a></td>' ;
print '<td>' . dolibarr_print_date ( $objp -> da ) . " </td> \n " ;
2004-07-20 10:54:43 +02:00
print '<td>' . stripslashes ( $objp -> note ) . '</td>' ;
print '<td>' . $objp -> code . '</td>' ;
2004-09-18 14:33:45 +02:00
print " </tr> \n " ;
2004-07-20 10:54:43 +02:00
$i ++ ;
}
2004-09-18 14:33:45 +02:00
print " </table> \n " ;
2004-07-20 10:54:43 +02:00
}
}
else
{
2004-09-18 14:33:45 +02:00
dolibarr_print_error ( $db );
2004-07-20 10:54:43 +02:00
}
2004-05-15 17:55:25 +02:00
2004-07-20 10:54:43 +02:00
print " </td></tr></table> " ;
2003-03-23 16:53:03 +01:00
2003-09-23 19:50:20 +02:00
2004-07-20 10:54:43 +02:00
/*
2004-11-26 01:54:45 +01:00
* Choix d ' un projet
2004-07-20 10:54:43 +02:00
*
*/
if ( $_GET [ " action " ] == 'classer' )
{
print " <p><form method= \" post \" action= \" " . $_SERVER [ " PHP_SELF " ] . " ?facid= $fac->id\ " > \n " ;
print '<input type="hidden" name="facid" value="' . $fac -> id . '">' ;
print '<input type="hidden" name="action" value="classin">' ;
2004-10-09 14:59:07 +02:00
print '<table class="border">' ;
2004-09-18 14:33:45 +02:00
print '<tr><td>' . $langs -> trans ( " Project " ) . '</td><td>' ;
2003-10-22 17:38:43 +02:00
2004-07-20 10:54:43 +02:00
$proj = new Project ( $db );
$html -> select_array ( " projetid " , $proj -> liste_array ( $soc -> id ));
2003-10-22 17:38:43 +02:00
2004-07-20 10:54:43 +02:00
print " </td></tr> " ;
2004-09-18 14:33:45 +02:00
print '<tr><td colspan="2" align="center"><input type="submit" value="' . $langs -> trans ( " Save " ) . '"></td></tr></table></form></p>' ;
2004-07-20 10:54:43 +02:00
}
2004-11-26 01:54:45 +01:00
2005-01-11 21:26:22 +01:00
2004-07-20 10:54:43 +02:00
/*
2005-01-11 21:26:22 +01:00
* Affiche formulaire mail
2004-07-20 10:54:43 +02:00
*
*/
if ( $_GET [ " action " ] == 'presend' )
{
2005-01-11 21:26:22 +01:00
print '<br>' ;
2004-10-23 18:55:07 +02:00
print_titre ( " Envoyer la facture par mail " );
2005-01-11 21:26:22 +01:00
// Cr<43> <72> l'objet formulaire mail
include_once ( " ../html.formmail.class.php " );
$formmail = new FormMail ( $db );
$formmail -> fromname = $user -> fullname ;
$formmail -> frommail = $user -> email ;
$formmail -> withfrom = 1 ;
$formmail -> withto = array_merge ( array ( " " ), $soc -> contact_email_array ());
$formmail -> withcc = 1 ;
$formmail -> withtopic = 1 ;
$formmail -> withfile = 1 ;
$formmail -> withbody = 1 ;
// Tableau des substitutions
$formmail -> substit [ " __FACREF__ " ] = $fac -> ref ;
// Tableau des param<61> tres compl<70> mentaires du post
$formmail -> param [ " action " ] = " send " ;
$formmail -> param [ " models " ] = " facture_send " ;
$formmail -> param [ " facid " ] = $fac -> id ;
$formmail -> param [ " returnurl " ] = DOL_URL_ROOT . " /compta/facture.php?facid= $fac->id " ;
$formmail -> show_form ();
2004-10-23 18:55:07 +02:00
2005-01-11 21:26:22 +01:00
print '<br>' ;
2004-07-20 10:54:43 +02:00
}
2003-07-24 13:05:57 +02:00
2004-07-20 10:54:43 +02:00
if ( $_GET [ " action " ] == 'prerelance' )
{
print '<br>' ;
2005-01-11 21:26:22 +01:00
print_titre ( " Envoyer une relance par mail " );
2004-11-06 09:59:26 +01:00
2005-01-11 21:26:22 +01:00
// Cr<43> <72> l'objet formulaire mail
include_once ( " ../html.formmail.class.php " );
$formmail = new FormMail ( $db );
$formmail -> fromname = $user -> fullname ;
$formmail -> frommail = $user -> email ;
$formmail -> withfrom = 1 ;
$formmail -> withto = array_merge ( array ( " " ), $soc -> contact_email_array ());
$formmail -> withcc = 1 ;
$formmail -> withtopic = 1 ;
$formmail -> withfile = 1 ;
$formmail -> withbody = 1 ;
// Tableau des substitutions
$formmail -> substit [ " __FACREF__ " ] = $fac -> ref ;
// Tableau des param<61> tres compl<70> mentaires
$formmail -> param [ " action " ] = " relance " ;
$formmail -> param [ " models " ] = " facture_relance " ;
$formmail -> param [ " facid " ] = $fac -> id ;
$formmail -> param [ " returnurl " ] = DOL_URL_ROOT . " /compta/facture.php?facid= $fac->id " ;
$formmail -> show_form ();
print '<br>' ;
2004-07-20 10:54:43 +02:00
}
2003-03-23 16:53:03 +01:00
2004-07-20 10:54:43 +02:00
/*
* Propales
*/
2003-03-23 16:53:03 +01:00
2004-07-20 10:54:43 +02:00
$sql = " SELECT " . $db -> pdate ( " p.datep " ) . " as dp, p.price, p.ref, p.rowid as propalid " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " propal as p, " . MAIN_DB_PREFIX . " fa_pr as fp WHERE fp.fk_propal = p.rowid AND fp.fk_facture = $fac->id " ;
2002-04-30 12:44:42 +02:00
2004-07-20 10:54:43 +02:00
$result = $db -> query ( $sql );
if ( $result )
{
$num = $db -> num_rows ();
if ( $num )
{
$i = 0 ; $total = 0 ;
print " <p> " ;
if ( $num > 1 )
{
print_titre ( " Propositions commerciales associ<63> es " );
}
else
{
print_titre ( " Proposition commerciale associ<63> e " );
}
2003-06-24 22:53:03 +02:00
2004-10-09 14:59:07 +02:00
print '<table class="noborder" width="100%">' ;
2004-07-20 10:54:43 +02:00
print '<tr class="liste_titre">' ;
2004-09-18 14:33:45 +02:00
print '<td>' . $langs -> trans ( " Ref " ) . '</td>' ;
print '<td>' . $langs -> trans ( " Date " ) . '</td>' ;
2004-08-02 04:58:38 +02:00
print '<td align="right">' . $langs -> trans ( " Price " ) . '</td>' ;
print " </tr> \n " ;
2003-03-23 16:53:03 +01:00
2004-07-20 10:54:43 +02:00
$var = True ;
while ( $i < $num )
{
2004-10-23 18:55:07 +02:00
$objp = $db -> fetch_object ();
2004-07-20 10:54:43 +02:00
$var =! $var ;
2004-09-18 14:33:45 +02:00
print " <tr $bc[$var] > " ;
print " <td><a href= \" propal.php?propalid= $objp->propalid\ " > $objp -> ref </ a ></ td > \n " ;
print " <td> " . strftime ( " %d %B %Y " , $objp -> dp ) . " </td> \n " ;
print '<td align="right">' . price ( $objp -> price ) . '</td>' ;
2004-07-20 10:54:43 +02:00
print " </tr> " ;
$total = $total + $objp -> price ;
$i ++ ;
}
2004-12-04 21:19:53 +01:00
print " <tr><td align= \" right \" colspan= \" 3 \" > " . $langs -> trans ( " TotalHT " ) . " : <b> " . price ( $total ) . " </b> " . $conf -> monnaie . " </td></tr> \n " ;
2004-07-20 10:54:43 +02:00
print " </table> " ;
}
} else {
2004-09-18 14:33:45 +02:00
dolibarr_print_error ( $db );
2004-07-20 10:54:43 +02:00
}
}
else
{
/* Facture non trouv<75> e */
2004-09-18 14:33:45 +02:00
print " Facture inexistante " ;
2004-07-20 10:54:43 +02:00
}
2004-12-17 15:47:35 +01:00
}
else
{
2004-07-20 10:54:43 +02:00
/***************************************************************************
* *
* Mode Liste *
* *
***************************************************************************/
2004-12-17 15:47:35 +01:00
$page = $_GET [ " page " ];
2004-07-27 01:32:36 +02:00
$sortorder = $_GET [ " sortorder " ];
$sortfield = $_GET [ " sortfield " ];
$month = $_GET [ " month " ];
$year = $_GET [ " year " ];
2004-07-20 10:54:43 +02:00
if ( $page == - 1 )
{
$page = 0 ;
}
if ( $user -> rights -> facture -> lire )
{
$limit = $conf -> liste_limit ;
$offset = $limit * $page ;
if ( $sortorder == " " )
$sortorder = " DESC " ;
if ( $sortfield == " " )
$sortfield = " f.datef " ;
2005-01-07 14:40:51 +01:00
$sql = " SELECT s.nom,s.idp,f.facnumber,f.increment,f.total,f.total_ttc, " . $db -> pdate ( " f.datef " ) . " as df, f.paye as paye, f.rowid as facid, f.fk_statut, sum(pf.amount) as am " ;
2004-12-17 16:57:19 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " societe as s " ;
$sql .= " , " . MAIN_DB_PREFIX . " facture as f " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " paiement_facture as pf ON f.rowid=pf.fk_facture " ;
$sql .= " WHERE f.fk_soc = s.idp " ;
2003-08-06 14:38:46 +02:00
2004-07-20 10:54:43 +02:00
if ( $socidp )
$sql .= " AND s.idp = $socidp " ;
2003-08-06 14:38:46 +02:00
2004-07-20 10:54:43 +02:00
if ( $month > 0 )
$sql .= " AND date_format(f.datef, '%m') = $month " ;
2003-08-06 14:38:46 +02:00
2004-07-20 10:54:43 +02:00
if ( $_GET [ " filtre " ])
{
$filtrearr = split ( " , " , $_GET [ " filtre " ]);
foreach ( $filtrearr as $fil )
{
$filt = split ( " : " , $fil );
$sql .= " AND " . $filt [ 0 ] . " = " . $filt [ 1 ];
}
}
2003-08-06 14:38:46 +02:00
2004-12-17 16:57:19 +01:00
if ( $_GET [ " search_ref " ])
{
$sql .= " AND f.facnumber like '% " . $_GET [ " search_ref " ] . " %' " ;
}
if ( $_GET [ " search_societe " ])
{
$sql .= " AND s.nom like '% " . $_GET [ " search_societe " ] . " %' " ;
}
2004-12-22 09:38:58 +01:00
if ( $_GET [ " search_montant_ht " ])
{
$sql .= " AND f.total = ' " . $_GET [ " search_montant_ht " ] . " ' " ;
}
if ( $_GET [ " search_montant_ttc " ])
{
$sql .= " AND f.total_ttc = ' " . $_GET [ " search_montant_ttc " ] . " ' " ;
}
2004-07-20 10:54:43 +02:00
if ( $year > 0 )
$sql .= " AND date_format(f.datef, '%Y') = $year " ;
2003-09-03 16:00:35 +02:00
2004-07-20 10:54:43 +02:00
if ( strlen ( $_POST [ " sf_ref " ]) > 0 )
{
$sql .= " AND f.facnumber like '% " . $_POST [ " sf_ref " ] . " %' " ;
}
2003-09-03 16:00:35 +02:00
2004-07-20 10:54:43 +02:00
$sql .= " GROUP BY f.facnumber " ;
2004-01-24 20:09:04 +01:00
2004-07-20 10:54:43 +02:00
$sql .= " ORDER BY " ;
$listfield = split ( ',' , $sortfield );
foreach ( $listfield as $key => $value ) {
2004-06-09 20:37:17 +02:00
$sql .= " $listfield[$key] $sortorder , " ;
2004-07-20 10:54:43 +02:00
}
$sql .= " f.rowid DESC " ;
2003-08-06 14:38:46 +02:00
2004-12-17 15:47:35 +01:00
$sql .= $db -> plimit ( $limit + 1 , $offset );
2005-01-08 01:50:59 +01:00
2004-07-20 10:54:43 +02:00
$result = $db -> query ( $sql );
2004-12-17 15:47:35 +01:00
2004-07-20 10:54:43 +02:00
if ( $result )
{
$num = $db -> num_rows ();
2004-12-17 15:47:35 +01:00
if ( $socidp )
{
$soc = new Societe ( $db );
$soc -> fetch ( $socidp );
}
print_barre_liste ( " Factures client " . ( $socidp ? " $soc->nom " : " " ), $page , " facture.php " , " &socidp= $socidp " , $sortfield , $sortorder , '' , $num );
2005-01-08 01:50:59 +01:00
2004-07-20 10:54:43 +02:00
$i = 0 ;
2004-09-18 19:56:30 +02:00
print '<table class="noborder" width="100%">' ;
2004-07-20 10:54:43 +02:00
print '<tr class="liste_titre">' ;
2004-11-26 01:54:45 +01:00
print_liste_field_titre ( $langs -> trans ( " Ref " ), $_SERVER [ " PHP_SELF " ], " f.facnumber " , " " , " &socidp= $socidp " , " " , $sortfield );
print_liste_field_titre ( $langs -> trans ( " Date " ), $_SERVER [ " PHP_SELF " ], " f.datef " , " " , " &socidp= $socidp " , 'align="center"' , $sortfield );
print_liste_field_titre ( $langs -> trans ( " Company " ), $_SERVER [ " PHP_SELF " ], " s.nom " , " " , " &socidp= $socidp " , " " , $sortfield );
print_liste_field_titre ( $langs -> trans ( " AmountHT " ), $_SERVER [ " PHP_SELF " ], " f.total " , " " , " &socidp= $socidp " , 'align="right"' , $sortfield );
print_liste_field_titre ( $langs -> trans ( " AmountTTC " ), $_SERVER [ " PHP_SELF " ], " f.total_ttc " , " " , " &socidp= $socidp " , 'align="right"' , $sortfield );
print_liste_field_titre ( $langs -> trans ( " Received " ), $_SERVER [ " PHP_SELF " ], " am " , " " , " &socidp= $socidp " , 'align="right"' , $sortfield );
print_liste_field_titre ( $langs -> trans ( " Status " ), $_SERVER [ " PHP_SELF " ], " fk_statut,paye " , " " , " &socidp= $socidp " , 'align="right"' , $sortfield );
2004-07-20 10:54:43 +02:00
print " </tr> \n " ;
2004-12-17 15:47:35 +01:00
// Lignes des champs de filtre
2004-12-17 16:57:19 +01:00
print '<form method="get" action="facture.php">' ;
2004-12-17 15:47:35 +01:00
print '<tr class="liste_titre">' ;
print '<td valign="right">' ;
2004-12-17 16:57:19 +01:00
print '<input class="fat" size="10" type="text" name="search_ref" value="' . $_GET [ " search_ref " ] . '">' ;
2004-12-17 15:47:35 +01:00
print '</td><td> </td>' ;
2004-12-22 09:38:58 +01:00
print '<td align="left">' ;
2004-12-17 16:57:19 +01:00
print '<input class="fat" type="text" name="search_societe" value="' . $_GET [ " search_societe " ] . '">' ;
2004-12-22 09:38:58 +01:00
print '</td><td align="right">' ;
print '<input class="fat" type="text" size="10" name="search_montant_ht" value="' . $_GET [ " search_montant_ht " ] . '">' ;
print '</td><td align="right">' ;
print '<input class="fat" type="text" size="10" name="search_montant_ttc" value="' . $_GET [ " search_montant_ttc " ] . '">' ;
print '</td><td colspan="2" align="center">' ;
2004-12-17 15:47:35 +01:00
print '<input type="submit" class="button" name="button_search" value="' . $langs -> trans ( " Search " ) . '">' ;
print '</td>' ;
print " </tr> \n " ;
print '</form>' ;
2004-07-20 10:54:43 +02:00
if ( $num > 0 )
{
$var = True ;
$total = 0 ;
$totalrecu = 0 ;
2003-07-22 18:05:14 +02:00
2004-07-20 10:54:43 +02:00
while ( $i < min ( $num , $limit ))
{
2005-01-08 01:50:59 +01:00
$objp = $db -> fetch_object ( $result );
2004-07-20 10:54:43 +02:00
$var =! $var ;
print " <tr $bc[$var] > " ;
if ( $objp -> paye )
{
$class = " normal " ;
}
else
{
if ( $objp -> fk_statut == 0 )
{
$class = " normal " ;
}
else
{
$class = " impayee " ;
}
}
print '<td><a href="facture.php?facid=' . $objp -> facid . '">' . img_file () . " </a> \n " ;
2005-01-07 14:40:51 +01:00
print '<a href="facture.php?facid=' . $objp -> facid . '">' . $objp -> facnumber . '</a>' . $objp -> increment . " </td> \n " ;
2003-07-12 12:33:55 +02:00
2004-07-20 10:54:43 +02:00
if ( $objp -> df > 0 )
{
2004-09-18 19:56:30 +02:00
print " <td align= \" center \" > " ;
2004-07-20 10:54:43 +02:00
$y = strftime ( " %Y " , $objp -> df );
$m = strftime ( " %m " , $objp -> df );
2003-07-12 12:33:55 +02:00
2004-07-20 10:54:43 +02:00
print strftime ( " %d " , $objp -> df ) . " \n " ;
print ' <a href="facture.php?year=' . $y . '&month=' . $m . '">' ;
print substr ( strftime ( " %B " , $objp -> df ), 0 , 3 ) . " </a> \n " ;
print ' <a href="facture.php?year=' . $y . '">' ;
print strftime ( " %Y " , $objp -> df ) . " </a></TD> \n " ;
}
else
{
print " <td align= \" center \" ><b>!!!</b></td> \n " ;
}
print '<td><a href="fiche.php?socid=' . $objp -> idp . '">' . $objp -> nom . '</a></td>' ;
2003-07-12 12:33:55 +02:00
2004-07-20 10:54:43 +02:00
print " <td align= \" right \" > " . price ( $objp -> total ) . " </td> " ;
print " <td align= \" right \" > " . price ( $objp -> total_ttc ) . " </td> " ;
print " <td align= \" right \" > " . price ( $objp -> am ) . " </td> " ;
// Affiche statut de la facture
if ( ! $objp -> paye )
{
if ( $objp -> fk_statut == 0 )
{
print '<td align="center">brouillon</td>' ;
}
elseif ( $objp -> fk_statut == 3 )
{
2004-07-28 00:37:51 +02:00
print '<td align="center">abandonn<6E> e</td>' ;
2004-07-20 10:54:43 +02:00
}
else
{
print '<td align="center"><a class="' . $class . '" href="facture.php?filtre=paye:0,fk_statut:1">' . ( $objp -> am ? " commenc<EFBFBD> " : " impay<EFBFBD> e " ) . '</a></td>' ;
}
}
else
{
print '<td align="center">pay<61> e</td>' ;
}
2003-07-12 12:33:55 +02:00
2004-07-20 10:54:43 +02:00
print " </tr> \n " ;
$total += $objp -> total ;
$total_ttc += $objp -> total_ttc ;
$totalrecu += $objp -> am ;
$i ++ ;
}
2004-01-24 20:09:04 +01:00
2004-07-20 10:54:43 +02:00
if ( $num <= $limit ) {
2004-07-31 15:34:32 +02:00
// Print total
2004-01-24 20:09:04 +01:00
print " <tr " . $bc [ ! $var ] . " > " ;
2004-07-31 15:34:32 +02:00
print " <td colspan=3 align= \" left \" > " . $langs -> trans ( " Total " ) . " : </td> " ;
print " <td align= \" right \" ><b> " . price ( $total ) . " </b></td> " ;
print " <td align= \" right \" ><b> " . price ( $total_ttc ) . " </b></td> " ;
print " <td align= \" right \" ><b> " . price ( $totalrecu ) . " </b></td> " ;
2004-01-24 20:09:04 +01:00
print '<td align="center"> </td>' ;
print " </tr> \n " ;
2004-07-20 10:54:43 +02:00
}
}
2002-05-11 20:53:13 +02:00
2004-07-20 10:54:43 +02:00
print " </table> " ;
$db -> free ();
}
else
{
2004-09-18 14:33:45 +02:00
dolibarr_print_error ( $db );
2004-07-20 10:54:43 +02:00
}
2005-01-08 01:50:59 +01:00
}
2004-07-20 10:54:43 +02:00
}
2003-07-12 12:33:55 +02:00
2002-04-30 12:44:42 +02:00
}
$db -> close ();
llxFooter ( " <em>Dernière modification $Date $ révision $Revision $ </em> " );
?>