2002-09-25 20:19:37 +02:00
< ? PHP
2003-06-18 15:01:15 +02:00
/* Copyright ( C ) 2001 - 2003 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2004-02-14 03:04:29 +01:00
* Copyright ( C ) 2004 Laurent Destailleur < eldy @ users . sourceforge . net >
2002-09-25 20:19:37 +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 .
*
2003-06-18 15:01:15 +02:00
* $Id $
* $Source $
*
2002-09-25 20:19:37 +02:00
*/
2003-06-29 11:22:17 +02:00
require ( " ./pre.inc.php " );
require ( " ./lib.inc.php " );
2002-09-25 20:19:37 +02:00
function propals ( $db , $year , $month ) {
global $bc ;
2003-09-06 18:06:15 +02:00
$sql = " SELECT s.nom, s.idp, p.rowid as propalid, p.price, p.ref, " . $db -> pdate ( " p.datep " ) . " as dp, c.label as statut, c.id as statutid " ;
2004-02-01 01:55:46 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " societe as s, " . MAIN_DB_PREFIX . " propal as p, " . MAIN_DB_PREFIX . " c_propalst as c WHERE p.fk_soc = s.idp AND p.fk_statut = c.id " ;
2002-09-25 20:19:37 +02:00
$sql .= " AND c.id in (1,2) " ;
$sql .= " AND date_format(p.datep, '%Y') = $year " ;
$sql .= " AND round(date_format(p.datep, '%m')) = $month " ;
$sql .= " ORDER BY p.fk_statut " ;
$result = $db -> query ( $sql );
$num = $db -> num_rows ();
$i = 0 ;
2003-11-03 09:44:04 +01:00
print '<p><table class="border" width="100%" cellspacing="0" cellpadding="4">' ;
2002-09-25 20:19:37 +02:00
print " <TR bgcolor= \" #e0e0e0 \" ><td colspan= \" 3 \" ><b>Propal</b></td></tr> " ;
$oldstatut = - 1 ;
$subtotal = 0 ;
while ( $i < $num ) {
$objp = $db -> fetch_object ( $i );
if ( $objp -> statut <> $oldstatut ) {
$oldstatut = $objp -> statut ;
if ( $i > 0 ) {
print " <tr><td align= \" right \" colspan= \" 4 \" >Total : <b> " . price ( $subtotal ) . " </b></td> \n " ;
print " <td align= \" left \" >Euros HT</td></tr> \n " ;
}
$subtotal = 0 ;
print " <TR bgcolor= \" #e0e0e0 \" > " ;
print " <TD>Societe</td> " ;
print " <TD>R<> f</TD> " ;
print " <TD align= \" right \" >Date</TD> " ;
print " <TD align= \" right \" >Prix</TD> " ;
print " <TD align= \" center \" >Statut</TD> " ;
print " </TR> \n " ;
$var = True ;
}
$var =! $var ;
print " <TR $bc[$var] > " ;
2003-08-31 01:59:13 +02:00
print " <TD><a href= \" comp.php?socidp= $objp->idp\ " > $objp -> nom </ a ></ TD > \n " ;
2002-09-25 20:19:37 +02:00
2003-09-11 22:18:51 +02:00
print " <TD><a href= \" ../comm/propal.php?propalid= $objp->propalid\ " > $objp -> ref </ a ></ TD > \n " ;
2002-09-25 20:19:37 +02:00
print " <TD align= \" right \" > " . strftime ( " %d %B %Y " , $objp -> dp ) . " </TD> \n " ;
print " <TD align= \" right \" > " . price ( $objp -> price ) . " </TD> \n " ;
print " <TD align= \" center \" > $objp->statut </TD> \n " ;
print " </TR> \n " ;
$total = $total + $objp -> price ;
$subtotal = $subtotal + $objp -> price ;
$i ++ ;
}
print " <tr><td align= \" right \" colspan= \" 4 \" >Total : <b> " . price ( $subtotal ) . " </b></td> \n " ;
print " <td align= \" left \" >Euros HT</td></tr> \n " ;
2003-09-03 02:17:19 +02:00
print " <tr> " ;
2002-09-25 20:19:37 +02:00
print " <td colspan= \" 2 \" align= \" right \" ><b>Total : " . price ( $total ) . " </b></td> " ;
print " <td align= \" left \" ><b>Euros HT</b></td></tr> " ;
2003-11-03 09:44:04 +01:00
print " </table> " ;
2002-09-25 20:19:37 +02:00
$db -> free ();
}
function factures ( $db , $year , $month , $paye ) {
global $bc ;
2003-09-09 17:38:11 +02:00
$sql = " SELECT s.nom, s.idp, f.facnumber, f.total as amount, " . $db -> pdate ( " f.datef " ) . " as df, f.paye, f.rowid as facid " ;
2004-02-01 01:55:46 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " societe as s, " . MAIN_DB_PREFIX . " facture as f WHERE f.fk_soc = s.idp AND f.paye = $paye " ;
2002-09-25 20:19:37 +02:00
$sql .= " AND date_format(f.datef, '%Y') = $year " ;
$sql .= " AND round(date_format(f.datef, '%m')) = $month " ;
$sql .= " ORDER BY f.datef DESC " ;
$result = $db -> query ( $sql );
if ( $result ) {
$num = $db -> num_rows ();
if ( $num > 0 ) {
$i = 0 ;
print " <p><TABLE border= \" 0 \" width= \" 100% \" cellspacing= \" 0 \" cellpadding= \" 3 \" > " ;
print " <TR bgcolor= \" orange \" ><td colspan= \" 3 \" ><b>Factures</b></td></tr> " ;
print " <TR bgcolor= \" orange \" > " ;
print " <TD>Societe</td> " ;
print " <TD>Num</TD> " ;
print " <TD align= \" right \" >Date</TD> " ;
print " <TD align= \" right \" >Montant</TD> " ;
print " <TD align= \" right \" >Pay<61> </TD> " ;
print " </TR> \n " ;
$var = True ;
while ( $i < $num ) {
$objp = $db -> fetch_object ( $i );
$var =! $var ;
print " <TR $bc[$var] > " ;
2003-08-31 01:59:13 +02:00
print " <TD><a href= \" comp.php?socidp= $objp->idp\ " > $objp -> nom </ a ></ TD > \n " ;
2003-09-11 22:18:51 +02:00
print " <TD><a href= \" facture.php?facid= $objp->facid\ " > $objp -> facnumber </ a ></ TD > \n " ;
2002-09-25 20:19:37 +02:00
if ( $objp -> df > 0 ) {
print " <TD align= \" right \" > " . strftime ( " %d %B %Y " , $objp -> df ) . " </TD> \n " ;
} else {
print " <TD align= \" right \" ><b>!!!</b></TD> \n " ;
}
print " <TD align= \" right \" > " . price ( $objp -> amount ) . " </TD> \n " ;
$payes [ 1 ] = " oui " ;
$payes [ 0 ] = " <b>non</b> " ;
print " <TD align= \" right \" > " . $payes [ $objp -> paye ] . " </TD> \n " ;
print " </TR> \n " ;
$total = $total + $objp -> amount ;
$i ++ ;
}
2003-09-03 02:17:19 +02:00
print " <tr><td align= \" right \" ><b>Total : " . price ( $total ) . " </b></td><td></td></tr> " ;
2002-09-25 20:19:37 +02:00
print " </TABLE> " ;
$db -> free ();
}
}
}
function pt ( $db , $sql , $year ) {
global $bc ;
$result = $db -> query ( $sql );
if ( $result ) {
$num = $db -> num_rows ();
$i = 0 ; $total = 0 ;
2003-11-03 09:44:04 +01:00
print '<p><table class="border" width="100%" cellspacing="0" cellpadding="3">' ;
2002-09-25 20:19:37 +02:00
print " <TR class= \" liste_titre \" > " ;
print " <TD>Mois</TD> " ;
print " <td align= \" right \" >Montant</td></tr> \n " ;
$var = True ;
$month = 1 ;
while ( $i < $num ) {
$obj = $db -> fetch_object ( $i );
$var =! $var ;
if ( $obj -> dm > $month ) {
for ( $b = $month ; $b < $obj -> dm ; $b ++ ) {
print " <TR $bc[$var] > " ;
print " <TD> " . strftime ( " %B " , mktime ( 12 , 0 , 0 , $b , 1 , $year )) . " </TD> \n " ;
print " <TD align= \" right \" >0</TD> \n " ;
print " </TR> \n " ;
$var =! $var ;
$ca [ $b ] = 0 ;
}
}
if ( $obj -> sum > 0 ) {
print " <TR $bc[$var] > " ;
2003-09-14 14:23:58 +02:00
print " <td> " ;
2002-09-25 20:19:37 +02:00
print strftime ( " %B " , mktime ( 12 , 0 , 0 , $obj -> dm , 1 , $year )) . " </TD> \n " ;
print " <TD align= \" right \" > " . price ( $obj -> sum ) . " </TD> \n " ;
print " </TR> \n " ;
$month = $obj -> dm + 1 ;
$ca [ $obj -> dm ] = $obj -> sum ;
$total = $total + $obj -> sum ;
}
$i ++ ;
}
if ( $num ) {
$beg = $obj -> dm ;
} else {
$beg = 1 ;
}
if ( $beg <= 12 ) {
for ( $b = $beg + 1 ; $b < 13 ; $b ++ ) {
$var =! $var ;
print " <TR $bc[$var] > " ;
print " <TD> " . strftime ( " %B " , mktime ( 12 , 0 , 0 , $b , 1 , $year )) . " </TD> \n " ;
print " <TD align= \" right \" >0</TD> \n " ;
print " </TR> \n " ;
$ca [ $b ] = 0 ;
}
}
2003-09-16 06:36:16 +02:00
print " <tr class= \" total \" ><td align= \" right \" >Total :</td><td align= \" right \" ><b> " . price ( $total ) . " </b></td></tr> " ;
2002-09-25 20:19:37 +02:00
print " </table> " ;
$db -> free ();
return $ca ;
} else {
print $db -> error ();
}
}
2003-06-29 11:12:55 +02:00
function ppt ( $db , $year , $socidp )
{
2002-09-25 20:19:37 +02:00
global $bc ;
print " <table width= \" 100% \" > " ;
2003-09-16 06:36:16 +02:00
print " <tr class= \" liste_titre \" ><td align= \" center \" width= \" 30% \" > " ;
2002-09-25 20:19:37 +02:00
print " CA " . ( $year - 1 );
print " </td><td align= \" center \" >CA $year </td> " ;
2003-11-03 09:44:04 +01:00
print '<td align="center">Delta</td></tr>' ;
2002-09-25 20:19:37 +02:00
print " <tr><td valign= \" top \" width= \" 30% \" > " ;
2003-09-09 17:38:11 +02:00
$sql = " SELECT sum(f.total) as sum, round(date_format(f.datef, '%m')) as dm " ;
2004-02-14 03:04:29 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " facture as f " ;
$sql .= " WHERE f.fk_statut = 1 " ;
if ( $conf -> compta -> mode != 'CREANCES-DETTES' ) {
$sql .= " AND f.paye = 1 " ;
}
$sql .= " AND date_format(f.datef,'%Y') = " . ( $year - 1 );
2003-06-29 11:12:55 +02:00
if ( $socidp )
{
$sql .= " AND f.fk_soc = $socidp " ;
}
2002-09-25 20:19:37 +02:00
$sql .= " GROUP BY dm " ;
$prev = pt ( $db , $sql , $year - 1 );
print " </td><td valign= \" top \" width= \" 30% \" > " ;
2003-09-09 17:38:11 +02:00
$sql = " SELECT sum(f.total) as sum, round(date_format(f.datef, '%m')) as dm " ;
2004-02-14 03:04:29 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " facture as f " ;
$sql .= " WHERE f.fk_statut = 1 " ;
if ( $conf -> compta -> mode != 'CREANCES-DETTES' ) {
$sql .= " AND f.paye = 1 " ;
}
$sql .= " AND date_format(f.datef,'%Y') = $year " ;
2003-06-29 11:12:55 +02:00
if ( $socidp )
{
$sql .= " AND f.fk_soc = $socidp " ;
}
2002-09-25 20:19:37 +02:00
$sql .= " GROUP BY dm " ;
$ca = pt ( $db , $sql , $year );
print " </td><td valign= \" top \" width= \" 30% \" > " ;
2003-11-03 09:44:04 +01:00
print '<p><table class="border" width="100%" cellspacing="0" cellpadding="3">' ;
2002-09-25 20:19:37 +02:00
print " <TR class= \" liste_titre \" > " ;
print " <TD>Mois</TD> " ;
print " <TD align= \" right \" >Montant</TD> " ;
print " </TR> \n " ;
$var = 1 ;
2003-06-29 11:12:55 +02:00
for ( $b = 1 ; $b <= 12 ; $b ++ )
{
$var =! $var ;
2002-09-25 20:19:37 +02:00
2003-06-29 11:12:55 +02:00
$delta = $ca [ $b ] - $prev [ $b ];
$deltat = $deltat + $delta ;
print " <TR $bc[$var] > " ;
print " <TD> " . strftime ( " %B " , mktime ( 12 , 0 , 0 , $b , 1 , $year )) . " </TD> \n " ;
print " <TD align= \" right \" > " . price ( $delta ) . " </TD> \n " ;
print " </TR> \n " ;
}
2002-09-25 20:19:37 +02:00
2003-09-16 06:36:16 +02:00
print '<tr class="total"><td align="right">Total :</td><td align="right"><b>' . price ( $deltat ) . '<b></td></tr>' ;
2002-09-25 20:19:37 +02:00
print '</table>' ;
print '</td></tr></table>' ;
}
/*
*
*/
llxHeader ();
2003-06-29 11:12:55 +02:00
/*
* S<EFBFBD> curit<EFBFBD> acc<EFBFBD> s client
*/
if ( $user -> societe_id > 0 )
{
$socidp = $user -> societe_id ;
}
2003-06-29 11:22:17 +02:00
$cyear = strftime ( " %Y " , time ());
ppt ( $db , $cyear , $socidp );
2002-09-25 20:19:37 +02:00
$db -> close ();
llxFooter ( " <em>Dernière modification $Date $ révision $Revision $ </em> " );
?>