2004-10-19 22:35:36 +02:00
< ? php
2003-06-29 11:11:23 +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 >
2003-06-29 11:11:23 +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 .
*
* $Id $
* $Source $
*
*/
require ( " ./pre.inc.php " );
2003-06-29 11:22:38 +02:00
require ( " ./lib.inc.php " );
2003-06-29 11:11:23 +02:00
function propals ( $db , $year , $month ) {
global $bc ;
2003-09-09 18:06:22 +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 " ;
2003-09-04 23:52:35 +02:00
$sql .= " AND c.id in (1,2,4) " ;
2003-06-29 11:11:23 +02:00
$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 ;
2004-06-08 16:33:13 +02:00
print " <table class= \" noborder \" width= \" 100% \" cellspacing= \" 0 \" cellpadding= \" 4 \" > " ;
print " <tr class= \" liste_titre \" ><td colspan= \" 5 \" ><b>Propal</b></td></tr> " ;
2003-06-29 11:11:23 +02:00
$oldstatut = - 1 ;
$subtotal = 0 ;
while ( $i < $num ) {
2004-10-23 18:55:07 +02:00
$objp = $db -> fetch_object ( $result );
2003-06-29 11:11:23 +02:00
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 ;
2004-06-08 16:33:13 +02:00
print " <tr class= \" liste_titre \" > " ;
print " <td>Societe</td> " ;
2004-08-02 04:58:38 +02:00
print " <td> " . $langs -> trans ( " Ref " ) . " </td> " ;
2004-06-08 16:33:13 +02:00
print " <td align= \" right \" >Date</td> " ;
2004-08-02 04:58:38 +02:00
print " <td align= \" right \" > " . $langs -> trans ( " Price " ) . " </td> " ;
2004-08-29 21:03:50 +02:00
print " <td align= \" center \" > " . $langs -> trans ( " Status " ) . " </td> " ;
2004-06-08 16:33:13 +02:00
print " </tr> \n " ;
2003-06-29 11:11:23 +02:00
$var = True ;
}
$var =! $var ;
2004-06-08 16:33:13 +02:00
print " <tr $bc[$var] > " ;
2003-06-29 11:11:23 +02:00
2004-06-08 16:33:13 +02:00
print " <td><a href= \" comp.php?socidp= $objp->idp\ " > $objp -> nom </ a ></ td > \n " ;
2003-06-29 11:11:23 +02:00
2004-06-08 16:33:13 +02:00
print " <td><a href= \" ../../comm/propal.php?propalid= $objp->propalid\ " > $objp -> ref </ a ></ td > \n " ;
2003-06-29 11:11:23 +02:00
2004-06-08 16:33:13 +02:00
print " <td align= \" right \" > " . dolibarr_print_date ( $objp -> dp ) . " </td> \n " ;
2003-06-29 11:11:23 +02:00
2004-06-08 16:33:13 +02:00
print " <td align= \" right \" > " . price ( $objp -> price ) . " </td> \n " ;
print " <td align= \" center \" > $objp->statut </td> \n " ;
print " </tr> \n " ;
2003-06-29 11:11:23 +02:00
$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-02 20:44:39 +02:00
print " <tr> " ;
print " <td colspan= \" 3 \" align= \" right \" ><b>Total : " . price ( $total ) . " </b></td> " ;
2003-06-29 11:11:23 +02:00
print " <td align= \" left \" ><b>Euros HT</b></td></tr> " ;
2004-06-08 16:33:13 +02:00
print " </table> " ;
2003-06-29 11:11:23 +02:00
$db -> free ();
}
function factures ( $db , $year , $month , $paye ) {
2004-05-05 23:35:26 +02:00
global $bc , $conf ;
2003-06-29 11:11:23 +02:00
2003-09-09 18:06:22 +02:00
$sql = " SELECT s.nom, s.idp, f.facnumber, f.total, " . $db -> pdate ( " f.datef " ) . " as df, f.paye, f.rowid as facid " ;
2004-02-14 03:04:29 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " societe as s, " . MAIN_DB_PREFIX . " facture as f " ;
$sql .= " WHERE f.fk_statut = 1 " ;
if ( $conf -> compta -> mode != 'CREANCES-DETTES' ) {
$sql .= " AND f.paye = $paye " ;
}
$sql .= " AND f.fk_soc = s.idp " ;
2003-06-29 11:11:23 +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 );
2003-08-31 01:59:13 +02:00
if ( $result )
{
$num = $db -> num_rows ();
if ( $num > 0 )
{
$i = 0 ;
2004-06-08 16:33:13 +02:00
print " <table class= \" noborder \" width= \" 100% \" cellspacing= \" 0 \" cellpadding= \" 3 \" > " ;
print " <tr class= \" liste_titre \" ><td colspan= \" 5 \" ><b>Factures</b></td></tr> " ;
print " <tr class= \" liste_titre \" > " ;
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 " ;
2003-08-31 01:59:13 +02:00
$var = True ;
while ( $i < $num )
{
2004-10-23 18:55:07 +02:00
$objp = $db -> fetch_object ( $result );
2003-08-31 01:59:13 +02:00
$var =! $var ;
2004-06-08 16:33:13 +02:00
print " <tr $bc[$var] > " ;
print " <td><a href= \" comp.php?socidp= $objp->idp\ " > $objp -> nom </ a ></ td > \n " ;
print " <td><a href= \" ../facture.php?facid= $objp->facid\ " > $objp -> facnumber </ a ></ td > \n " ;
2003-08-31 01:59:13 +02:00
if ( $objp -> df > 0 )
{
2004-06-08 16:33:13 +02:00
print " <td align= \" right \" > " . dolibarr_print_date ( $objp -> df ) . " </td> \n " ;
2003-08-31 01:59:13 +02:00
}
else
{
2004-06-08 16:33:13 +02:00
print " <td align= \" right \" ><b>!!!</b></td> \n " ;
2003-08-31 01:59:13 +02:00
}
2004-06-08 16:33:13 +02:00
print " <td align= \" right \" > " . price ( $objp -> total ) . " </td> \n " ;
2003-08-31 01:59:13 +02:00
$payes [ 1 ] = " oui " ;
$payes [ 0 ] = " <b>non</b> " ;
2004-06-08 16:33:13 +02:00
print " <td align= \" right \" > " . $payes [ $objp -> paye ] . " </td> \n " ;
print " </tr> \n " ;
2003-08-31 01:59:13 +02:00
2003-09-09 18:06:22 +02:00
$total = $total + $objp -> total ;
2003-08-31 01:59:13 +02:00
$i ++ ;
}
2003-09-02 20:44:39 +02:00
print " <tr><td colspan= \" 4 \" align= \" right \" > " ;
print " <b>Total : " . price ( $total ) . " </b></td><td></td></tr> " ;
2004-06-08 16:33:13 +02:00
print " </table> " ;
2003-08-31 01:59:13 +02:00
$db -> free ();
2003-06-29 11:11:23 +02:00
}
}
2003-08-31 01:59:13 +02:00
else
{
print $db -> error ();
}
2003-06-29 11:11:23 +02:00
}
function pt ( $db , $sql , $year ) {
2004-09-10 23:52:52 +02:00
global $bc , $langs ;
2003-06-29 11:11:23 +02:00
$result = $db -> query ( $sql );
if ( $result ) {
$num = $db -> num_rows ();
$i = 0 ; $total = 0 ;
2003-11-03 09:44:04 +01:00
print '<table class="border" width="100%" cellspacing="0" cellpadding="3">' ;
2004-06-08 16:33:13 +02:00
print " <tr class= \" liste_titre \" > " ;
2004-07-31 15:46:12 +02:00
print '<td>' . $langs -> trans ( " Month " ) . '</td>' ;
2003-06-29 11:11:23 +02:00
print " <td align= \" right \" >Montant</td></tr> \n " ;
$var = True ;
$month = 1 ;
while ( $i < $num ) {
2004-10-23 18:55:07 +02:00
$obj = $db -> fetch_object ( $result );
2003-06-29 11:11:23 +02:00
$var =! $var ;
if ( $obj -> dm > $month ) {
for ( $b = $month ; $b < $obj -> dm ; $b ++ ) {
2004-06-08 16:33:13 +02:00
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 " ;
2003-06-29 11:11:23 +02:00
$var =! $var ;
$ca [ $b ] = 0 ;
}
}
if ( $obj -> sum > 0 ) {
2004-06-08 16:33:13 +02:00
print " <tr $bc[$var] > " ;
2003-06-29 11:11:23 +02:00
print " <td><a href= \" comp.php?details=1&year= $year &month= $obj->dm\ " > " ;
2004-06-08 16:33:13 +02:00
print strftime ( " %B " , mktime ( 12 , 0 , 0 , $obj -> dm , 1 , $year )) . " </td> \n " ;
print " <td align= \" right \" > " . price ( $obj -> sum ) . " </td> \n " ;
2003-06-29 11:11:23 +02:00
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 ;
2004-06-08 16:33:13 +02:00
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 " ;
2003-06-29 11:11:23 +02:00
$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> " ;
2003-06-29 11:11:23 +02:00
print " </table> " ;
$db -> free ();
return $ca ;
} else {
print $db -> error ();
}
}
2003-06-29 11:27:45 +02:00
function ppt ( $db , $year , $socidp )
{
2004-09-10 23:52:52 +02:00
global $bc , $conf , $langs ;
2003-06-29 11:11:23 +02:00
print " <table width= \" 100% \" > " ;
2004-06-08 16:33:13 +02:00
print '<tr class="liste_titre"><td align="center" valign="top" width="30%">' ;
2003-06-29 11:11:23 +02:00
print " CA Pr<50> visionnel bas<61> sur les propal $year " ;
2003-09-23 19:24:18 +02:00
print " </td><td align= \" center \" valign= \" top \" >CA R<> alis<69> $year </td> " ;
print " <td align= \" center \" valign= \" top \" >Delta $year </td></tr> " ;
2003-06-29 11:11:23 +02:00
2003-09-23 19:24:18 +02:00
print '<tr><td valign="top" align="center" width="30%">' ;
2003-06-29 11:11:23 +02:00
2003-09-05 21:46:54 +02:00
$sql = " SELECT sum(f.price) as sum, round(date_format(f.datep,'%m')) as dm " ;
2004-02-01 01:55:46 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " propal as f WHERE fk_statut in (1,2,4) AND date_format(f.datep,'%Y') = $year " ;
2003-06-29 11:11:23 +02:00
2003-06-29 11:27:45 +02:00
if ( $socidp )
{
$sql .= " AND f.fk_soc = $socidp " ;
}
2003-06-29 11:11:23 +02:00
$sql .= " GROUP BY dm " ;
$prev = pt ( $db , $sql , $year );
print " </td><td valign= \" top \" width= \" 30% \" > " ;
2003-09-09 18:06:22 +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:27:45 +02:00
if ( $socidp )
{
$sql .= " AND f.fk_soc = $socidp " ;
}
2003-06-29 11:11:23 +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 '<table class="border" width="100%" cellspacing="0" cellpadding="3">' ;
2004-06-08 16:33:13 +02:00
print " <tr class= \" liste_titre \" > " ;
2004-07-31 15:46:12 +02:00
print '<td>' . $langs -> trans ( " Month " ) . '</td>' ;
print '<td align="right">' . $langs -> trans ( " Amount " ) . '</td>' ;
2004-06-08 16:33:13 +02:00
print " </tr> \n " ;
2003-06-29 11:11:23 +02:00
$var = 1 ;
2003-06-29 11:27:45 +02:00
for ( $b = 1 ; $b <= 12 ; $b ++ )
{
$var =! $var ;
2003-06-29 11:11:23 +02:00
2003-06-29 11:27:45 +02:00
$delta = $ca [ $b ] - $prev [ $b ];
$deltat = $deltat + $delta ;
2004-06-08 16:33:13 +02:00
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 " ;
2003-06-29 11:27:45 +02:00
}
2003-06-29 11:11:23 +02:00
$ayear = $year - 1 ;
$acat = get_ca ( $db , $ayear , $socidp ) - get_ca_propal ( $db , $ayear , $socidp );
2003-09-16 06:36:16 +02:00
print " <tr class= \" total \" ><td align= \" right \" >Total :</td><td align= \" right \" > " . price ( $deltat ) . " </td></tr> " ;
print " <tr class= \" total \" ><td align= \" right \" >Rappel $ayear :</td><td align= \" right \" > " . price ( $acat ) . " </td></tr> " ;
print " <tr class= \" total \" ><td align= \" right \" >Soit :</td><td align= \" right \" ><b> " . price ( $acat + $deltat ) . " </b></td></tr> " ;
2003-06-29 11:11:23 +02:00
print " </table> " ;
print " </td></tr></table> " ;
}
/*
*
*/
llxHeader ();
/*
* S<EFBFBD> curit<EFBFBD> acc<EFBFBD> s client
*/
if ( $user -> societe_id > 0 )
{
$socidp = $user -> societe_id ;
}
2004-06-08 16:33:13 +02:00
$cyear = isset ( $_GET [ " year " ]) ? $_GET [ " year " ] : 0 ;
if ( ! $cyear ) { $cyear = strftime ( " %Y " , time ()); }
2003-06-29 11:11:23 +02:00
2004-07-30 12:32:27 +02:00
print_fiche_titre ( " Chiffre d'Affaire transform<72> (pr<70> vu-r<> alis<69> ) " ,( $cyear ? " <a href='comp.php?year= " . ( $cyear - 1 ) . " '> " . img_previous () . " </a> Ann<6E> e $cyear <a href='comp.php?year= " . ( $cyear + 1 ) . " '> " . img_next () . " </a> " : " " ));
2003-06-29 11:11:23 +02:00
ppt ( $db , $cyear , $socidp );
if ( $details == 1 )
{
print " <TABLE border= \" 0 \" width= \" 100% \" cellspacing= \" 0 \" cellpadding= \" 4 \" ><tr><td valign= \" top \" width= \" 50% \" > " ;
factures ( $db , $year , $month , 1 );
print " </td><td valign= \" top \" width= \" 50% \" > " ;
propals ( $db , $year , $month );
print " </td></tr></table> " ;
}
$db -> close ();
llxFooter ( " <em>Dernière modification $Date $ révision $Revision $ </em> " );
?>