2002-04-30 12:44:42 +02:00
< ? PHP
2003-02-01 20:45:45 +01:00
/* Copyright ( C ) 2002 - 2003 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
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 $
*
2002-04-30 12:44:42 +02:00
*/
require ( " ./pre.inc.php3 " );
2002-09-25 20:03:18 +02:00
require ( " ../facture.class.php3 " );
2003-02-02 16:01:56 +01:00
require ( " ../lib/CMailFile.class.php3 " );
2003-04-14 18:24:14 +02:00
require ( " ../paiement.class.php " );
2002-04-30 12:44:42 +02:00
llxHeader ();
2002-05-11 20:53:13 +02:00
2002-04-30 12:44:42 +02:00
$db = new Db ();
2002-05-13 19:43:45 +02:00
$yn [ 1 ] = " oui " ;
$yn [ 0 ] = " <b>non</b> " ;
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 ;
}
/*
*
*/
2003-04-14 18:24:14 +02:00
if ( $action == 'add_paiement' ) {
$datepaye = $db -> idate ( mktime ( 12 , 0 , 0 , $pmonth , $pday , $pyear ));
$paiement = new Paiement ( $db );
$paiement -> facid = $facid ;
$paiement -> datepaye = $datepaye ;
$paiement -> amount = $amount ;
$paiement -> author = $author ;
$paiement -> paiementid = $paiementid ;
$paiement -> num_paiement = $num_paiement ;
$paiement -> note = $note ;
$paiement -> create ();
$action = '' ;
}
/*
*
*/
2002-12-14 17:25:46 +01:00
if ( $action == 'valid' )
{
$fac = new Facture ( $db );
$result = $fac -> set_valid ( $facid , $user -> id );
2003-04-13 16:47:33 +02:00
if ( $result )
{
facture_pdf_create ( $db , $facid );
}
2002-04-30 12:44:42 +02:00
}
2002-12-14 17:25:46 +01:00
if ( $action == 'payed' )
{
$fac = new Facture ( $db );
$result = $fac -> set_payed ( $facid );
2002-04-30 12:44:42 +02:00
}
2003-02-01 20:45:45 +01:00
if ( $action == 'addligne' )
{
$fac = new Facture ( $db );
$result = $fac -> addline ( $facid , $HTTP_POST_VARS [ " desc " ], $HTTP_POST_VARS [ " pu " ], $HTTP_POST_VARS [ " qty " ]);
}
2003-02-01 22:12:52 +01:00
if ( $action == 'updateligne' )
{
$fac = new Facture ( $db , " " , $facid );
$result = $fac -> updateline ( $rowid , $HTTP_POST_VARS [ " desc " ], $HTTP_POST_VARS [ " price " ], $HTTP_POST_VARS [ " qty " ]);
}
2003-02-01 20:45:45 +01:00
if ( $action == 'deleteline' )
{
2003-02-01 22:12:52 +01:00
$fac = new Facture ( $db , " " , $facid );
2003-02-01 20:45:45 +01:00
$fac -> id = $facid ;
$result = $fac -> deleteline ( $rowid );
}
2002-12-14 17:25:46 +01:00
if ( $action == 'delete' )
{
$fac = new Facture ( $db );
$fac -> delete ( $facid );
2002-04-30 12:44:42 +02:00
$facid = 0 ;
}
2002-12-14 17:25:46 +01:00
if ( $action == 'add' )
{
2003-02-01 20:55:32 +01:00
$datefacture = $db -> idate ( mktime ( 12 , 0 , 0 , $remonth , $reday , $reyear ));
2002-12-14 17:25:46 +01:00
if ( ! $propalid )
{
$facture = new Facture ( $db , $socid );
$facture -> number = $facnumber ;
$facture -> date = $datefacture ;
2002-09-25 20:03:18 +02:00
2002-12-14 17:25:46 +01:00
$facture -> note = $note ;
$facture -> amount = $amount ;
$facture -> remise = $remise ;
2003-04-13 21:23:35 +02:00
$facid = $facture -> create ( $user -> id , $statut , $note );
2002-12-14 17:25:46 +01:00
}
else
{
$facture = new Facture ( $db , $socid );
$facture -> number = $facnumber ;
$facture -> date = $datefacture ;
$facture -> note = $note ;
$facture -> amount = $amount ;
$facture -> remise = $remise ;
$facture -> propalid = $propalid ;
2003-04-13 21:23:35 +02:00
$facid = $facture -> create ( $user -> id );
if ( ! $facid )
2002-12-14 17:25:46 +01: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.php3?propalid= $propalid\ " > propal </ a > " ;
print $db -> error ();
}
2002-05-11 20:53:13 +02:00
}
2003-03-23 16:53:03 +01:00
$action = '' ;
2003-04-13 21:23:35 +02:00
2002-05-11 20:53:13 +02:00
}
2003-02-02 16:01:56 +01:00
/*
*
*/
if ( $action == 'send' )
{
$fac = new Facture ( $db , " " , $facid );
$fac -> fetch ( $facid );
$soc = new Societe ( $db , $fac -> socidp );
$file = $conf -> facture -> outputdir . " / " . $fac -> ref . " / " . $fac -> ref . " .pdf " ;
if ( file_exists ( $file ))
{
$sendto = $soc -> contact_get_email ( $HTTP_POST_VARS [ " destinataire " ]);
2003-02-02 16:14:50 +01:00
$sendtoid = $HTTP_POST_VARS [ " destinataire " ];
2003-02-02 16:01:56 +01:00
if ( strlen ( $sendto ))
{
$subject = " Facture $fac->ref " ;
$message = " Veuillez trouver ci-joint la facture $fac->ref\n\nCordialement\n\n " ;
$filename = " $fac->ref .pdf " ;
$replyto = $HTTP_POST_VARS [ " replytoname " ] . " < " . $HTTP_POST_VARS [ " replytomail " ] . " > " ;
$mailfile = new CMailFile ( $subject , $sendto , $replyto , $message , $file , " application/pdf " , $filename );
if ( $mailfile -> sendfile () )
{
2003-02-02 16:14:50 +01:00
$sendto = htmlentities ( $sendto );
2003-02-02 16:01:56 +01:00
2003-02-02 16:14:50 +01:00
$sql = " INSERT INTO actioncomm (datea,fk_action,fk_soc,note,fk_facture, fk_contact,fk_user_author, label) VALUES (now(), 9 , $fac->socidp ,'Envoy<6F> e <20> $sendto ', $fac->id , $sendtoid , $user->id , 'Envoi Facture par mail'); " ;
2003-02-02 16:01:56 +01:00
if ( ! $db -> query ( $sql ) )
{
print $db -> error ();
print " <p> $sql </p> " ;
}
}
else
{
print " <b>!! erreur d'envoi<br> $sendto <br> $replyto <br> $filename " ;
}
}
else
{
print " Can't get email $sendto " ;
}
}
}
2003-04-13 16:47:33 +02:00
if ( $action == 'pdf' )
{
/*
* Generation de la facture
*
*/
print facture_pdf_create ( $db , $facid ); // d<> finit dans /includes/modules/facture/modules_facture.php
}
2002-05-11 20:53:13 +02:00
/*
*
* Mode creation
*
*
*
*/
2002-12-14 17:25:46 +01:00
if ( $action == 'create' )
{
2002-05-11 20:53:13 +02:00
print_titre ( " Emettre une facture " );
2002-12-14 17:25:46 +01:00
if ( $propalid )
{
$sql = " SELECT s.nom, s.prefix_comm, s.idp, p.price, p.remise, p.tva, p.total, p.ref, " . $db -> pdate ( " p.datep " ) . " as dp, c.id as statut, c.label as lst " ;
$sql .= " FROM societe as s, llx_propal as p, c_propalst as c WHERE p.fk_soc = s.idp AND p.fk_statut = c.id " ;
$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 " ;
$sql .= " FROM societe as s " ;
2003-03-12 20:08:57 +01:00
$sql .= " WHERE s.idp = $socidp " ;
2002-12-14 17:25:46 +01:00
}
2002-05-11 20:53:13 +02:00
2002-12-14 17:25:46 +01:00
if ( $db -> query ( $sql ) )
{
$num = $db -> num_rows ();
if ( $num ) {
$obj = $db -> fetch_object ( 0 );
2003-03-12 20:08:57 +01:00
$numfa = facture_get_num (); // d<> finit dans includes/modules/facture
2002-12-14 17:25:46 +01:00
print " <form action= \" $PHP_SELF\ " method = \ " post \" > " ;
2003-04-13 21:23:35 +02:00
print '<input type="hidden" name="action" value="add">' ;
2002-12-14 17:25:46 +01:00
print " <input type= \" hidden \" name= \" socid \" value= \" $obj->idp\ " > " ;
print '<table cellspacing="0" border="1" width="100%">' ;
2003-03-12 20:08:57 +01:00
print " <tr bgcolor= \" #e0e0e0 \" ><td>Client :</td><td> $obj->nom </td> " ;
2002-12-14 17:25:46 +01:00
2003-04-13 20:58:30 +02:00
print '<td rowspan="4">' ;
2003-02-01 20:45:45 +01:00
print '<textarea name="note" wrap="soft" cols="60" rows="15"></textarea></td></tr>' ;
2002-12-14 17:25:46 +01:00
if ( $propalid )
{
$amount = ( $obj -> price - $obj -> remise );
print '<input type="hidden" name="amount" value="' . $amount . '">' ;
print '<input type="hidden" name="total" value="' . $obj -> total . '">' ;
print '<input type="hidden" name="remise" value="' . $obj -> remise . '">' ;
print '<input type="hidden" name="tva" value="' . $obj -> tva . '">' ;
print '<input type="hidden" name="propalid" value="' . $propalid . '">' ;
print " <tr><td>Propal :</td><td> $obj->ref </td></tr> " ;
print '<tr bgcolor="#e0e0e0"><td>Montant HT :</td><td>' . price ( $amount ) . '</td></tr>' ;
print " <tr bgcolor= \" #e0e0e0 \" ><td>TVA 19.6% :</td><td> " . price ( $obj -> tva ) . " </td></tr> " ;
2003-02-01 20:55:32 +01:00
print " <tr bgcolor= \" #e0e0e0 \" ><td>Total TTC :</td><td> " . price ( $obj -> total ) . " </td></tr> " ;
2002-12-14 17:25:46 +01:00
}
else
2003-02-01 20:55:32 +01:00
{
2003-04-13 20:58:30 +02:00
2002-12-14 17:25:46 +01:00
}
print " <input type= \" hidden \" name= \" author \" value= \" $author\ " > " ;
print " <tr><td>Auteur :</td><td> " . $user -> fullname . " </td></tr> " ;
print " <tr><td>Date :</td><td> " ;
2003-02-01 20:55:32 +01:00
print_date_select ( time ());
print " </td></tr> " ;
2002-12-14 17:25:46 +01:00
print " <tr><td>Num<75> ro :</td><td> <input name= \" facnumber \" type= \" text \" value= \" $numfa\ " ></ td ></ tr > " ;
2003-03-12 20:08:57 +01:00
print '<tr><td colspan="3" align="center"><input type="submit" value="Cr<43> er"></td></tr>' ;
print " </form> \n " ;
print " </table> \n " ;
2002-12-14 17:25:46 +01:00
2002-05-11 20:53:13 +02:00
}
2002-12-14 17:25:46 +01:00
}
else
{
print $db -> error ();
2002-04-30 12:44:42 +02:00
}
2002-05-11 20:53:13 +02:00
2002-12-14 17:25:46 +01:00
}
else
/* *************************************************************************** */
/* */
/* */
/* */
/* *************************************************************************** */
{
2002-05-11 20:53:13 +02:00
if ( $facid > 0 ) {
2002-12-14 17:25:46 +01:00
$sql = " SELECT s.nom as socnom, s.idp as socidp, f.facnumber, f.amount, f.total, " . $db -> pdate ( " f.datef " ) . " as df, f.paye, f.fk_statut as statut, f.fk_user_author, f.note " ;
2002-05-11 20:53:13 +02:00
$sql .= " FROM societe as s,llx_facture as f WHERE f.fk_soc = s.idp AND f.rowid = $facid " ;
2003-03-23 16:53:03 +01:00
if ( $user -> societe_id > 0 )
{
$sql .= " AND s.idp = " . $user -> societe_id ;
}
2002-05-11 20:53:13 +02:00
$result = $db -> query ( $sql );
2002-04-30 12:44:42 +02:00
2002-12-14 17:25:46 +01:00
if ( $result )
{
$num = $db -> num_rows ();
if ( $num )
{
$obj = $db -> fetch_object ( $i );
}
$db -> free ();
2002-05-11 20:53:13 +02:00
}
2002-12-14 17:25:46 +01:00
else
{
print $db -> error ();
}
2003-03-23 16:53:03 +01:00
if ( $num > 0 )
{
2002-07-03 14:46:00 +02:00
2003-03-23 16:53:03 +01:00
$soc = new Societe ( $db , $obj -> socidp );
2002-04-30 12:44:42 +02:00
2003-03-23 16:53:03 +01:00
$author = new User ( $db );
$author -> id = $obj -> fk_user_author ;
$author -> fetch ();
2002-05-11 20:53:13 +02:00
2003-03-23 16:53:03 +01:00
print_titre ( " Facture : " . $obj -> facnumber );
2002-04-30 12:44:42 +02:00
2003-03-23 16:53:03 +01:00
print " <table border= \" 0 \" cellspacing= \" 0 \" cellpadding= \" 2 \" width= \" 100% \" > " ;
print " <tr><td width= \" 50% \" > " ;
/*
* Facture
*/
print " <table border= \" 1 \" cellspacing= \" 0 \" cellpadding= \" 2 \" width= \" 100% \" > " ;
print " <tr><td>Client</td> " ;
print " <td colspan= \" 3 \" > " ;
print " <b><a href= \" fiche.php3?socid= $obj->socidp\ " > $obj -> socnom </ a ></ b ></ td ></ tr > " ;
2002-07-03 14:46:00 +02:00
2003-03-23 16:53:03 +01:00
print " <tr><td>Date</td> " ;
print " <td colspan= \" 3 \" > " . strftime ( " %A %d %B %Y " , $obj -> df ) . " </td></tr> \n " ;
2003-04-13 17:06:17 +02:00
print " <tr><td>Auteur</td><td colspan= \" 3 \" > $author->fullname </td> " ;
2003-02-01 20:45:45 +01:00
2003-03-23 16:53:03 +01:00
print '<tr><td>Montant</td>' ;
print '<td align="right" colspan="2"><b>' . price ( $obj -> amount ) . '</b></td>' ;
print '<td>euros HT</td></tr>' ;
print '<tr><td>TVA</td><td align="right" colspan="2">' . tva ( $obj -> amount ) . '</td>' ;
print '<td>euros</td></tr>' ;
print '<tr><td>Total</td><td align="right" colspan="2">' . price ( $obj -> total ) . '</td>' ;
print '<td>euros TTC</td></tr>' ;
print '<tr><td>Statut</td><td align="center">' . $obj -> statut . '</td>' ;
2003-04-13 17:06:17 +02:00
print " <td>Pay<61> </td> " ;
2003-03-23 16:53:03 +01:00
print " <td align= \" center \" bgcolor= \" #f0f0f0 \" ><b> " . $yn [ $obj -> paye ] . " </b></td></tr> " ;
2003-02-01 20:45:45 +01:00
print " </table> " ;
2003-03-23 16:53:03 +01:00
print " </td><td valign= \" top \" > " ;
2003-02-01 20:45:45 +01:00
2003-03-23 16:53:03 +01:00
$_MONNAIE = " euros " ;
2003-02-01 20:45:45 +01:00
2003-03-23 16:53:03 +01:00
/*
* Paiements
*/
$sql = " SELECT " . $db -> pdate ( " datep " ) . " as dp, p.amount, c.libelle as paiement_type, p.num_paiement, p.rowid " ;
$sql .= " FROM llx_paiement as p, c_paiement as c WHERE p.fk_facture = $facid AND p.fk_paiement = c.id " ;
$result = $db -> query ( $sql );
if ( $result )
{
$num = $db -> num_rows ();
$i = 0 ; $total = 0 ;
print " <p><b>Paiements</b> " ;
echo '<TABLE border="0" width="100%" cellspacing="0" cellpadding="3">' ;
print " <TR class= \" liste_titre \" > " ;
print " <td>Date</td> " ;
print " <td>Type</td> " ;
print " <td align= \" right \" >Montant</TD><td> </td> " ;
print " </TR> \n " ;
2003-02-01 20:45:45 +01:00
2003-03-23 16:53:03 +01:00
$var = True ;
while ( $i < $num )
{
$objp = $db -> fetch_object ( $i );
$var =! $var ;
print " <TR $bc[$var] > " ;
print " <TD> " . strftime ( " %d %B %Y " , $objp -> dp ) . " </TD> \n " ;
print " <TD> $objp->paiement_type $objp->num_paiement </TD> \n " ;
print " <TD align= \" right \" > " . price ( $objp -> amount ) . " </TD><td> $_MONNAIE </td> \n " ;
print " </tr> " ;
$total = $total + $objp -> amount ;
$i ++ ;
}
2003-02-01 20:45:45 +01:00
2003-03-23 16:53:03 +01:00
if ( $obj -> paye == 0 )
{
print " <tr><td colspan= \" 2 \" align= \" right \" >Total :</td><td align= \" right \" ><b> " . price ( $total ) . " </b></td><td> $_MONNAIE </td></tr> \n " ;
print " <tr><td colspan= \" 2 \" align= \" right \" >Factur<75> :</td><td align= \" right \" bgcolor= \" #d0d0d0 \" > " . price ( $obj -> total ) . " </td><td bgcolor= \" #d0d0d0 \" > $_MONNAIE </td></tr> \n " ;
$resteapayer = $obj -> total - $total ;
2002-04-30 12:44:42 +02:00
2003-03-23 16:53:03 +01:00
print " <tr><td colspan= \" 2 \" align= \" right \" >Reste a payer :</td> " ;
print " <td align= \" right \" bgcolor= \" #f0f0f0 \" ><b> " . price ( $resteapayer ) . " </b></td><td bgcolor= \" #f0f0f0 \" > $_MONNAIE </td></tr> \n " ;
}
print " </table> " ;
$db -> free ();
} else {
print $db -> error ();
}
print " </td></tr> " ;
print " <tr><td>Note : " . nl2br ( $obj -> note ) . " </td></tr> " ;
print " </table> " ;
/*
* Lignes de factures
*
*/
2003-04-13 16:47:33 +02:00
$sql = " SELECT l.description, l.price, l.qty, l.rowid, l.tva_taux " ;
2003-03-23 16:53:03 +01:00
$sql .= " FROM llx_facturedet as l WHERE l.fk_facture = $facid " ;
$result = $db -> query ( $sql );
if ( $result )
2003-02-02 16:01:56 +01:00
{
2003-03-23 16:53:03 +01:00
$num = $db -> num_rows ();
2003-02-02 16:01:56 +01:00
$i = 0 ; $total = 0 ;
2003-03-23 16:53:03 +01:00
echo '<TABLE border="0" width="100%" cellspacing="0" cellpadding="3">' ;
print " <TR class= \" liste_titre \" > " ;
2003-04-13 16:47:33 +02:00
print '<td width="62%">Description</td>' ;
2003-04-13 21:23:35 +02:00
print '<td width="8%" align="center">Tva Tx</td>' ;
print '<td width="8%" align="center">Quantit<69> </td>' ;
2003-03-23 16:53:03 +01:00
print '<td width="12%" align="right">Montant</TD><td width="10%"> </td><td width="10%"> </td>' ;
2003-02-02 16:01:56 +01:00
print " </TR> \n " ;
$var = True ;
while ( $i < $num )
{
$objp = $db -> fetch_object ( $i );
$var =! $var ;
print " <TR $bc[$var] > " ;
2003-03-23 16:53:03 +01:00
print " <TD> " . stripslashes ( nl2br ( $objp -> description )) . " </TD> \n " ;
2003-04-13 16:47:33 +02:00
print '<TD align="center">' . $objp -> tva_taux . ' %</TD>' ;
2003-03-23 16:53:03 +01:00
print '<TD align="center">' . $objp -> qty . '</TD>' ;
print '<TD align="right">' . price ( $objp -> price ) . " </TD> \n " ;
if ( $obj -> statut == 0 )
{
print '<td align="right"><a href="' . $PHPSELF . '?facid=' . $facid . '&action=deleteline&rowid=' . $objp -> rowid . '">del</a></td>' ;
print '<td align="right"><a href="' . $PHPSELF . '?facid=' . $facid . '&action=editline&rowid=' . $objp -> rowid . '">edit</a></td>' ;
}
else
{
print '<td> </td><td> </td>' ;
}
2003-02-02 16:01:56 +01:00
print " </tr> " ;
2003-03-23 16:53:03 +01:00
if ( $action == 'editline' && $rowid == $objp -> rowid )
{
print " <form action= \" $PHP_SELF ?facid= $facid\ " method = \ " post \" > " ;
print '<input type="hidden" name="action" value="updateligne">' ;
print '<input type="hidden" name="rowid" value="' . $rowid . '">' ;
print " <TR $bc[$var] > " ;
print '<TD><textarea name="desc" cols="60" rows="3">' . stripslashes ( $objp -> description ) . '</textarea></TD>' ;
print '<TD align="center"><input type="text" name="qty" value="' . $objp -> qty . '"></TD>' ;
print '<TD align="right"><input type="text" name="price" value="' . price ( $objp -> price ) . '"></TD>' ;
print '<td colspan="2"><input type="submit"></td>' ;
print '</tr>' . " \n " ;
print " </form> \n " ;
}
$total = $total + ( $objp -> qty * $objp -> price );
2003-02-02 16:01:56 +01:00
$i ++ ;
}
2003-03-23 16:53:03 +01:00
$db -> free ();
2003-04-13 21:23:35 +02:00
// print "</table>";
2003-03-23 16:53:03 +01:00
}
else
{
print $db -> error ();
2003-02-02 16:01:56 +01:00
}
2003-02-01 20:45:45 +01:00
2003-03-23 16:53:03 +01:00
/*
* Ajouter une ligne
*
*/
if ( $obj -> statut == 0 )
{
print " <form action= \" $PHP_SELF ?facid= $facid\ " method = \ " post \" > " ;
2003-04-13 21:23:35 +02:00
// echo '<TABLE border="1" width="100%" cellspacing="0" cellpadding="1">';
2003-03-23 16:53:03 +01:00
print " <TR class= \" liste_titre \" > " ;
2003-04-13 21:23:35 +02:00
print '<td width="62%">Description</td>' ;
print '<td width="8%" align="center">Tva Tx</td>' ;
print '<td width="8%" align="center">Quantit<69> </td>' ;
print '<td width="12%" align="right">Montant</TD>' ;
print '<td> </td>' ;
print '<td> </td>' ;
2003-03-23 16:53:03 +01:00
print " </TR> \n " ;
print '<input type="hidden" name="action" value="addligne">' ;
print '<tr><td><textarea name="desc" cols="60" rows="3"></textarea></td>' ;
2003-04-13 21:23:35 +02:00
print '<td align="center"><input type="text" name="tva_tx" size="4" value="19.6"></td>' ;
print '<td align="center"><input type="text" name="qty" size="2"></td>' ;
print '<td align="right"><input type="text" name="pu" size="8"></td>' ;
2003-03-23 16:53:03 +01:00
print '</tr>' ;
2003-04-13 21:23:35 +02:00
print '<tr><td align="center" colspan="3"><input type="submit" value="Ajouter"></td></tr>' ;
// print "</table>";
2003-03-23 16:53:03 +01:00
print " </form> " ;
}
2003-04-13 21:23:35 +02:00
print " </table> " ;
2003-03-23 16:53:03 +01:00
/*
* Fin Ajout ligne
*
*/
if ( $user -> societe_id == 0 )
{
print " <p><TABLE border= \" 1 \" width= \" 100% \" cellspacing= \" 0 \" cellpadding= \" 4 \" ><tr> " ;
2003-02-02 16:01:56 +01:00
2003-03-23 16:53:03 +01:00
if ( $obj -> statut == 0 )
{
print " <td align= \" center \" width= \" 25% \" >[<a href= \" $PHP_SELF ?facid= $facid &action=delete \" >Supprimer</a>]</td> " ;
}
elseif ( $obj -> statut == 1 && $resteapayer > 0 )
{
print " <td align= \" center \" width= \" 25% \" >[<a href= \" $PHP_SELF ?facid= $facid &action=presend \" >Envoyer</a>]</td> " ;
}
else
{
print " <td align= \" center \" width= \" 25% \" >-</td> " ;
}
if ( $obj -> statut == 1 && $resteapayer > 0 )
{
print " <td align= \" center \" width= \" 25% \" >[<a href= \" paiement.php3?facid= $facid &action=create \" >Emettre un paiement</a>]</td> " ;
}
else
{
print " <td align= \" center \" width= \" 25% \" >-</td> " ;
}
if ( $obj -> statut == 1 && abs ( $resteapayer == 0 ) && $obj -> paye == 0 )
{
print " <td align= \" center \" width= \" 25% \" >[<a href= \" $PHP_SELF ?facid= $facid &action=payed \" >Classer 'Pay<61> e'</a>]</td> " ;
}
else
{
print " <td align= \" center \" width= \" 25% \" >-</td> " ;
}
if ( $obj -> statut == 0 )
{
print " <td align= \" center \" bgcolor= \" #e0e0e0 \" width= \" 25% \" >[<a href= \" $PHP_SELF ?facid= $facid &action=valid \" >Valider</a>]</td> " ;
}
2003-04-13 16:47:33 +02:00
elseif ( $obj -> statut == 1 && $obj -> paye == 0 )
2003-03-23 16:53:03 +01:00
{
print " <td align= \" center \" width= \" 25% \" ><a href= \" facture.php3?facid= $facid &action=pdf \" >G<> n<EFBFBD> rer la facture</a></td> " ;
}
2003-04-13 16:47:33 +02:00
else
{
print " <td align= \" center \" width= \" 25% \" >-</td> " ;
}
2003-03-23 16:53:03 +01:00
print " </tr></table> " ;
}
print " <p> \n " ;
2003-04-13 16:47:33 +02:00
2003-03-23 16:53:03 +01:00
/*
* Documents g<EFBFBD> n<EFBFBD> r<EFBFBD> s
*
*/
print " <hr> " ;
print " <table width= \" 100% \" cellspacing=2><tr><td width= \" 60% \" valign= \" top \" > " ;
print_titre ( " Documents g<> n<EFBFBD> r<EFBFBD> s " );
print '<table width="100%" cellspacing="0" border="1" cellpadding="3">' ;
$file = $conf -> facture -> outputdir . " / " . $obj -> facnumber . " / " . $obj -> facnumber . " .pdf " ;
if ( file_exists ( $file ))
{
print " <tr $bc[0] ><td>Facture PDF</a></td> " ;
print '<td><a href="' . $conf -> facture -> outputurl . " / " . $obj -> facnumber . " / " . $obj -> facnumber . '.pdf">' . $obj -> facnumber . '.pdf</a></td>' ;
print '<td align="right">' . filesize ( $file ) . ' bytes</td>' ;
print '<td align="right">' . strftime ( " %d %b %Y %H:%M:%S " , filemtime ( $file )) . '</td>' ;
print '</tr>' ;
}
$file = $conf -> facture -> outputdir . " / " . $obj -> facnumber . " / " . $obj -> facnumber . " .ps " ;
if ( file_exists ( $file ))
{
print " <tr $bc[0] ><td>Facture Postscript</a></td> " ;
print '<td><a href="' . $conf -> facture -> outputurl . " / " . $obj -> facnumber . " / " . $obj -> facnumber . '.ps">' . $obj -> facnumber . '.ps</a></td>' ;
print '<td align="right">' . filesize ( $file ) . ' bytes</td>' ;
print '<td align="right">' . strftime ( " %d %b %Y %H:%M:%S " , filemtime ( $file )) . '</td>' ;
print '</tr>' ;
}
print '<tr $bc[0]><td colspan="4">(<a href="' . $conf -> facture -> outputurl . '/' . $facid . '/">liste...</a>)</td></tr>' ;
print " </table> \n " ;
print " </td> " ;
print '<td valign="top" width="40%">' ;
print_titre ( " Actions " );
/*
* Liste des actions
*
*/
$sql = " SELECT " . $db -> pdate ( " a.datea " ) . " as da, a.note " ;
$sql .= " FROM actioncomm as a WHERE a.fk_soc = $obj->socidp AND a.fk_action = 9 AND a.fk_facture = $facid " ;
$result = $db -> query ( $sql );
if ( $result )
{
$num = $db -> num_rows ();
if ( $num )
{
$i = 0 ; $total = 0 ;
print '<TABLE border="1" cellspacing="0" cellpadding="4">' ;
print " <TR $bc[$var] > " ;
print " <td>Date</td> " ;
print " <td>Action</td> " ;
print " </TR> \n " ;
$var = True ;
while ( $i < $num )
{
$objp = $db -> fetch_object ( $i );
$var =! $var ;
print " <TR $bc[$var] > " ;
print " <TD> " . strftime ( " %d %B %Y " , $objp -> da ) . " </TD> \n " ;
print '<TD align="right">' . stripslashes ( $objp -> note ) . '</TD>' ;
print " </tr> " ;
$i ++ ;
}
print " </table> " ;
}
}
else
{
print $db -> error ();
}
2003-02-02 16:01:56 +01:00
2003-03-23 16:53:03 +01:00
/*
*
*
*/
print " </td></tr> " ;
2003-02-02 16:01:56 +01:00
print " </table> " ;
2003-03-23 16:53:03 +01:00
/*
*
*
*/
if ( $action == 'presend' )
{
2003-04-13 21:37:14 +02:00
$replytoname = $user -> fullname ;
2003-03-23 16:53:03 +01:00
$from_name = $replytoname ;
2003-04-13 21:37:14 +02:00
$replytomail = $user -> email ;
2003-03-23 16:53:03 +01:00
$from_mail = $replytomail ;
print " <form method= \" post \" action= \" $PHP_SELF ?facid= $facid &action=send \" > \n " ;
print " <input type= \" hidden \" name= \" replytoname \" value= \" $replytoname\ " > \n " ;
print " <input type= \" hidden \" name= \" replytomail \" value= \" $replytomail\ " > \n " ;
print " <p><b>Envoyer la facture par mail</b> " ;
print " <table cellspacing=0 border=1 cellpadding=3> " ;
print '<tr><td>Destinataire</td><td colspan="5">' ;
$form = new Form ( $db );
$form -> select_array ( " destinataire " , $soc -> contact_email_array ());
print '</td>' ;
print " <td><input size= \" 30 \" name= \" sendto \" value= \" $obj->email\ " ></ td ></ tr > " ;
print " <tr><td>Exp<78> diteur</td><td colspan= \" 5 \" > $from_name </td><td> $from_mail </td></tr> " ;
print " <tr><td>Reply-to</td><td colspan= \" 5 \" > $replytoname </td> " ;
print " <td> $replytomail </td></tr> " ;
print " </table> " ;
print " <input type= \" submit \" value= \" Envoyer \" > " ;
print " </form> " ;
}
/*
* Propales
*/
$sql = " SELECT " . $db -> pdate ( " p.datep " ) . " as dp, p.price, p.ref, p.rowid as propalid " ;
$sql .= " FROM llx_propal as p, llx_fa_pr as fp WHERE fp.fk_propal = p.rowid AND fp.fk_facture = $facid " ;
2002-04-30 12:44:42 +02:00
2003-03-23 16:53:03 +01:00
$result = $db -> query ( $sql );
if ( $result )
{
$num = $db -> num_rows ();
if ( $num )
{
$i = 0 ; $total = 0 ;
print " <p><b>Proposition(s) commerciale(s) associ<63> e(s)</b> " ;
print '<TABLE border="1" width="100%" cellspacing="0" cellpadding="4">' ;
print " <TR class= \" liste_titre \" > " ;
print " <td>Num</td> " ;
print " <td>Date</td> " ;
print " <td align= \" right \" >Prix</TD> " ;
print " </TR> \n " ;
$var = True ;
while ( $i < $num )
{
$objp = $db -> fetch_object ( $i );
$var =! $var ;
print " <TR $bc[$var] > " ;
print " <TD><a href= \" propal.php3?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>' ;
print " </tr> " ;
$total = $total + $objp -> price ;
$i ++ ;
}
print " <tr><td align= \" right \" colspan= \" 3 \" >Total : <b> " . price ( $total ) . " </b> $_MONNAIE HT</td></tr> \n " ;
print " </table> " ;
}
} else {
print $db -> error ();
}
}
else
{
/* Facture non trouv<75> e */
print " Facture inexistante ou acc<63> s refus<75> " ;
2002-05-11 20:53:13 +02:00
}
2002-04-30 12:44:42 +02:00
} else {
2002-05-11 20:53:13 +02:00
/*
2002-05-12 22:29:15 +02:00
*
2003-03-23 16:53:03 +01:00
* Mode Liste
2002-05-11 20:53:13 +02:00
*
2002-05-12 22:29:15 +02:00
*
2002-05-11 20:53:13 +02:00
*/
print_barre_liste ( " Factures " , $page , $PHP_SELF );
2002-04-30 12:44:42 +02:00
2002-05-11 20:53:13 +02:00
$sql = " SELECT s.nom,s.idp,f.facnumber,f.amount, " . $db -> pdate ( " f.datef " ) . " as df,f.paye,f.rowid as facid " ;
$sql .= " FROM societe as s,llx_facture as f WHERE f.fk_soc = s.idp " ;
2002-04-30 12:44:42 +02:00
if ( $socidp ) {
$sql .= " AND s.idp = $socidp " ;
}
2002-05-11 20:53:13 +02:00
2002-04-30 12:44:42 +02:00
if ( $month > 0 ) {
2002-05-11 20:53:13 +02:00
$sql .= " AND date_format(f.datef, '%m') = $month " ;
2002-04-30 12:44:42 +02:00
}
if ( $year > 0 ) {
2002-05-02 20:04:23 +02:00
$sql .= " AND date_format(f.datef, '%Y') = $year " ;
2002-04-30 12:44:42 +02:00
}
2002-05-11 20:53:13 +02:00
2003-04-13 20:58:30 +02:00
$sql .= " ORDER BY f.datef DESC, f.facnumber DESC " ;
2002-05-11 20:53:13 +02:00
2002-04-30 12:44:42 +02:00
$result = $db -> query ( $sql );
if ( $result ) {
$num = $db -> num_rows ();
2002-05-11 20:53:13 +02:00
$i = 0 ;
print " <TABLE border= \" 0 \" width= \" 100% \" cellspacing= \" 0 \" cellpadding= \" 4 \" > " ;
print '<TR class="liste_titre">' ;
print " <TD>Numéro</TD><td> " ;
print_liste_field_titre ( " Soci<EFBFBD> t<EFBFBD> " , $PHP_SELF , " s.nom " );
print " </td><TD align= \" right \" >Date</TD><TD align= \" right \" >Montant</TD> " ;
2003-04-13 20:58:30 +02:00
print '<td> </td>' ;
2002-05-11 20:53:13 +02:00
print " </TR> \n " ;
2002-04-30 12:44:42 +02:00
if ( $num > 0 ) {
$var = True ;
while ( $i < $num ) {
$objp = $db -> fetch_object ( $i );
$var =! $var ;
2003-04-13 20:58:30 +02:00
2002-05-11 20:53:13 +02:00
print " <TR $bc[$var] > " ;
2002-09-25 20:03:18 +02:00
print " <td><a href= \" facture.php3?facid= $objp->facid\ " > " ;
2003-04-13 20:58:30 +02:00
if ( $objp -> paye )
{
print $objp -> facnumber ;
}
else
{
print '<b>' . $objp -> facnumber . '</b>' ;
}
2002-09-25 20:03:18 +02:00
print " </a></TD> \n " ;
2002-05-11 20:53:13 +02:00
print " <TD><a href= \" fiche.php3?socid= $objp->idp\ " > $objp -> nom </ a ></ TD > \n " ;
2002-04-30 12:44:42 +02:00
if ( $objp -> df > 0 ) {
print " <TD align= \" right \" > " ;
$y = strftime ( " %Y " , $objp -> df );
$m = strftime ( " %m " , $objp -> df );
2002-05-11 20:53:13 +02:00
2002-04-30 12:44:42 +02:00
print strftime ( " %d " , $objp -> df ) . " \n " ;
print " <a href= \" facture.php3?year= $y &month= $m\ " > " ;
print strftime ( " %B " , $objp -> df ) . " </a> \n " ;
print " <a href= \" facture.php3?year= $y\ " > " ;
print strftime ( " %Y " , $objp -> df ) . " </a></TD> \n " ;
} else {
print " <TD align= \" right \" ><b>!!!</b></TD> \n " ;
}
2002-05-11 20:53:13 +02:00
print " <TD align= \" right \" > " . price ( $objp -> amount ) . " </TD> \n " ;
2003-04-13 20:58:30 +02:00
if ( ! $objp -> paye )
{
print '<td align="center">impay<61> e</td>' ;
}
else
{
print '<td> </td>' ;
}
2002-05-11 20:53:13 +02:00
$total = $total + $objp -> amount ;
$subtotal = $subtotal + $objp -> amount ;
2002-09-25 20:03:18 +02:00
2002-05-11 20:53:13 +02:00
2002-04-30 12:44:42 +02:00
print " </TR> \n " ;
$i ++ ;
2002-05-11 20:53:13 +02:00
$j ++ ;
2002-04-30 12:44:42 +02:00
}
}
2002-05-11 20:53:13 +02:00
if ( $i == 0 ) { $i = 1 ; } if ( $j == 0 ) { $j = 1 ; }
print " <tr><td></td><td> $j factures</td><td colspan= \" 1 \" align= \" right \" > </td> " ;
2003-04-13 20:58:30 +02:00
print " <td align= \" right \" >Sous Total :<b> " . price ( $subtotal ) . " </b></td> " ;
print '<td> </td></tr>' ;
2002-05-11 20:53:13 +02:00
print " <tr bgcolor= \" #d0d0d0 \" ><td></td><td> $i factures</td><td colspan= \" 1 \" align= \" right \" > </td> " ;
2003-04-13 20:58:30 +02:00
print " <td align= \" right \" ><b>Total <small>(euros HT)</small>: " . price ( $total ) . " </b></td> " ;
print '<td> </td></tr>' ;
2002-05-11 20:53:13 +02:00
print " </TABLE> " ;
2002-04-30 12:44:42 +02:00
$db -> free ();
} else {
print $db -> error ();
}
2002-05-11 20:53:13 +02:00
2002-04-30 12:44:42 +02:00
}
}
$db -> close ();
llxFooter ( " <em>Dernière modification $Date $ révision $Revision $ </em> " );
?>