2002-05-10 14:28:10 +02:00
< ? PHP
2003-03-23 19:41:16 +01:00
/* Copyright ( C ) 2001 - 2003 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2004-01-31 00:38:49 +01:00
* Copyright ( C ) 2004 Laurent Destailleur < eldy @ users . sourceforge . net >
2002-05-10 14:28:10 +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-03-23 19:41:16 +01:00
* $Id $
* $Source $
*
2002-05-10 14:28:10 +02:00
*/
2003-09-11 22:18:51 +02:00
require ( " ./pre.inc.php " );
require ( " ../contact.class.php " );
require ( " ../lib/webcal.class.php " );
require ( " ../cactioncomm.class.php " );
require ( " ../actioncomm.class.php " );
2002-05-10 14:28:10 +02:00
2003-03-23 19:41:16 +01:00
/*
* S<EFBFBD> curit<EFBFBD> acc<EFBFBD> s client
*/
if ( $user -> societe_id > 0 )
{
$action = '' ;
$socid = $user -> societe_id ;
}
2003-08-12 15:28:56 +02:00
$user -> getrights ( 'facture' );
2002-05-10 14:28:10 +02:00
llxHeader ();
2003-08-12 15:28:56 +02:00
2002-05-10 14:28:10 +02:00
if ( $action == 'add_action' ) {
/*
2003-09-11 22:18:51 +02:00
* Vient de actioncomm . php
2002-05-10 14:28:10 +02:00
*
*/
$actioncomm = new ActionComm ( $db );
$actioncomm -> date = $date ;
$actioncomm -> type = $actionid ;
$actioncomm -> contact = $contactid ;
$actioncomm -> societe = $socid ;
$actioncomm -> note = $note ;
$actioncomm -> add ( $user );
$societe = new Societe ( $db );
$societe -> fetch ( $socid );
}
2003-03-23 19:41:16 +01:00
if ( $action == 'attribute_prefix' )
{
2002-05-10 14:28:10 +02:00
$societe = new Societe ( $db , $socid );
$societe -> attribute_prefix ( $db , $socid );
}
2003-03-23 19:41:16 +01:00
if ( $action == 'recontact' )
{
2002-05-10 14:28:10 +02:00
$dr = mktime ( 0 , 0 , 0 , $remonth , $reday , $reyear );
2004-01-31 00:35:43 +01:00
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " soc_recontact (fk_soc, datere, author) VALUES ( $socid , $dr ,' " . $GLOBALS [ " REMOTE_USER " ] . " ') " ;
2002-05-10 14:28:10 +02:00
$result = $db -> query ( $sql );
}
2003-03-23 19:41:16 +01:00
if ( $action == 'stcomm' )
{
if ( $stcommid <> 'null' && $stcommid <> $oldstcomm )
{
$sql = " INSERT INTO socstatutlog (datel, fk_soc, fk_statut, author) " ;
$sql .= " VALUES (' $dateaction ', $socid , $stcommid ,' " . $GLOBALS [ " REMOTE_USER " ] . " ') " ;
$result = @ $db -> query ( $sql );
if ( $result )
{
2004-01-31 00:35:43 +01:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " societe SET fk_stcomm= $stcommid WHERE idp= $socid " ;
2003-03-23 19:41:16 +01:00
$result = $db -> query ( $sql );
}
else
{
$errmesg = " ERREUR DE DATE ! " ;
}
2002-05-10 14:28:10 +02:00
}
2003-03-23 19:41:16 +01:00
if ( $actioncommid )
{
2004-01-31 00:35:43 +01:00
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " actioncomm (datea, fk_action, fk_soc, fk_user_author) VALUES (' $dateaction ', $actioncommid , $socid ,' " . $user -> id . " ') " ;
2003-03-23 19:41:16 +01:00
$result = @ $db -> query ( $sql );
if ( ! $result )
{
$errmesg = " ERREUR DE DATE ! " ;
}
2002-05-10 14:28:10 +02:00
}
}
/*
* Recherche
*
*
*/
2003-03-23 19:41:16 +01:00
if ( $mode == 'search' )
{
if ( $mode - search == 'soc' )
{
2004-01-31 00:38:49 +01:00
$sql = " SELECT s.idp FROM " . MAIN_DB_PREFIX . " societe as s " ;
2003-03-23 19:41:16 +01:00
$sql .= " WHERE lower(s.nom) like '% " . strtolower ( $socname ) . " %' " ;
2002-05-10 14:28:10 +02:00
}
2003-03-23 19:41:16 +01:00
if ( $db -> query ( $sql ) )
{
if ( $db -> num_rows () == 1 )
{
$obj = $db -> fetch_object ( 0 );
$socid = $obj -> idp ;
}
$db -> free ();
}
if ( $user -> societe_id > 0 )
{
$socid = $user -> societe_id ;
}
2002-05-10 14:28:10 +02:00
}
/*
*
* Mode fiche
*
*
*/
2003-05-02 13:57:36 +02:00
if ( $socid > 0 )
{
2002-05-10 14:28:10 +02:00
$societe = new Societe ( $db , $socid );
2004-01-31 00:35:43 +01:00
$sql = " SELECT s.idp as idp, s.nom, " . $db -> pdate ( " s.datec " ) . " as dc, s.tel, s.fax, st.libelle as stcomm, s.fk_stcomm, s.url,s.address,s.cp,s.ville, s.note, t.libelle as typent, e.libelle as effectif, s.siren, s.prefix_comm, s.services,s.parent, s.description FROM " . MAIN_DB_PREFIX . " societe as s, " . MAIN_DB_PREFIX . " c_stcomm as st, " . MAIN_DB_PREFIX . " c_typent as t, " . MAIN_DB_PREFIX . " c_effectif as e " ;
2002-05-10 14:28:10 +02:00
$sql .= " WHERE s.fk_stcomm=st.id AND s.fk_typent = t.id AND s.fk_effectif = e.id " ;
2003-03-23 19:41:16 +01:00
if ( $to == 'next' )
{
$sql .= " AND s.idp > $socid ORDER BY idp ASC LIMIT 1 " ;
}
elseif ( $to == 'prev' ) {
2002-05-10 14:28:10 +02:00
$sql .= " AND s.idp < $socid ORDER BY idp DESC LIMIT 1 " ;
} else {
$sql .= " AND s.idp = $socid " ;
}
$result = $db -> query ( $sql );
if ( $result ) {
$objsoc = $db -> fetch_object ( 0 );
2004-01-24 20:30:03 +01:00
if ( ! $objsoc -> idp ) {
print ( " Cette societe n'existe pas ou plus " );
$db -> close ();
llxFooter ( " <em>Dernière modification $Date $ révision $Revision $ </em> " );
exit ;
}
2002-05-10 14:28:10 +02:00
$dac = strftime ( " %Y-%m-%d %H:%M " , time ());
if ( $errmesg ) {
print " <b> $errmesg </b><br> " ;
}
/*
*
*/
print " <table width= \" 100% \" border= \" 0 \" cellspacing= \" 1 \" > \n " ;
print " <tr><td><div class= \" titre \" >Fiche client : $objsoc->nom </div></td> " ;
2003-03-23 19:41:16 +01:00
if ( $user -> societe_id == 0 )
{
2003-09-11 22:18:51 +02:00
print '<td align="center"><a href="../comm/fiche.php?socid=' . $objsoc -> idp . '">Commercial</a></td>' ;
2004-01-24 20:30:03 +01:00
print " <td align= \" center \" >[<a href= \" ../comm/docsoc.php?socid= $objsoc->idp\ " > Documents </ a > ] </ td > " ;
print " <td align= \" center \" >[<a href= \" index.php?socidp= $objsoc->idp &action=add \" >Bookmark</a>]</td> " ;
2003-08-06 11:25:40 +02:00
if ( $user -> rights -> facture -> creer )
2004-01-24 20:30:03 +01:00
print " <td>[<a href= \" facture.php?action=create&socidp= $objsoc->idp\ " > " .translate( " Facturer " ). " </ a > ] </ td > " ;
print " <td>[<a href= \" ../socnote.php?socid= $objsoc->idp\ " > Notes </ a > ] </ td > " ;
2003-09-02 16:37:43 +02:00
print " <td align= \" center \" >[<a href= \" deplacement/fiche.php?socid= $objsoc->idp &action=create \" >D<> placement</a>]</td> " ;
2003-03-23 19:41:16 +01:00
}
2002-05-10 14:28:10 +02:00
print " </tr></table> " ;
/*
*
*
*/
2003-05-02 13:57:36 +02:00
print '<table width="100%" border="0"><tr>' ;
2003-10-12 16:35:10 +02:00
print '<tr><td valign="top">' ;
print '<table class="border" cellspacing="0" width="100%">' ;
2003-05-16 23:05:08 +02:00
print '<tr><td>Tel</td><td>' . $objsoc -> tel . ' </td><td>Fax</td><td>' . $objsoc -> fax . ' </td></tr>' ;
print '<tr><td>Ville</td><td colspan="3">' . nl2br ( $objsoc -> address ) . " <br> $objsoc->cp $objsoc->ville </td></tr> " ;
2002-05-10 14:28:10 +02:00
2003-05-16 23:05:08 +02:00
print '<tr><td>siren</td><td><a href="http://www.societe.com/cgi-bin/recherche?rncs=' . $objsoc -> siren . '">' . $objsoc -> siren . '</a> </td>' ;
2002-05-10 14:28:10 +02:00
print " <td>prefix</td><td> " ;
2003-05-02 13:57:36 +02:00
if ( $objsoc -> prefix_comm )
{
print $objsoc -> prefix_comm ;
}
else
{
print " [<a href= \" $PHP_SELF ?socid= $objsoc->idp &action=attribute_prefix \" >Attribuer</a>] " ;
}
2002-05-10 14:28:10 +02:00
print " </td></tr> " ;
2003-05-16 23:05:08 +02:00
print " <tr><td>Site</td><td colspan= \" 3 \" ><a href= \" http:// $objsoc->url\ " > $objsoc -> url </ a >& nbsp ; </ td ></ tr > " ;
2002-05-10 14:28:10 +02:00
print " </table> " ;
/*
*
*/
print " </td> \n " ;
print '<td valign="top" width="50%">' ;
/*
* Factures
*/
2003-08-06 11:25:40 +02:00
if ( $user -> rights -> facture -> lire )
2003-06-18 15:16:09 +02:00
{
2003-10-12 16:35:10 +02:00
print '<table class="border" width="100%" cellspacing="0" cellpadding="1">' ;
2003-08-06 11:25:40 +02:00
$var =! $var ;
$sql = " SELECT s.nom, s.idp, f.facnumber, f.amount, " . $db -> pdate ( " f.datef " ) . " as df, f.paye, f.rowid as facid " ;
2004-01-31 00:38:49 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " societe as s, " . MAIN_DB_PREFIX . " facture as f WHERE f.fk_soc = s.idp AND s.idp = " . $objsoc -> idp . " ORDER BY f.datef DESC " ;
2004-01-24 20:30:03 +01:00
2003-08-06 11:25:40 +02:00
if ( $db -> query ( $sql ) )
2003-06-18 15:16:09 +02:00
{
2003-08-06 11:25:40 +02:00
$num = $db -> num_rows (); $i = 0 ;
if ( $num > 0 )
2003-06-18 15:16:09 +02:00
{
2003-08-06 11:25:40 +02:00
print " <tr $bc[$var] > " ;
2003-09-11 22:18:51 +02:00
print " <td colspan= \" 4 \" ><a href= \" facture.php?socidp= $objsoc->idp\ " > liste des factures ( $num ) </ td ></ tr > " ;
2003-06-18 15:16:09 +02:00
}
2003-08-06 11:25:40 +02:00
while ( $i < $num && $i < 5 )
2003-06-18 15:16:09 +02:00
{
2003-08-06 11:25:40 +02:00
$objp = $db -> fetch_object ( $i );
$var =! $var ;
print " <TR $bc[$var] > " ;
2003-09-11 22:18:51 +02:00
print " <TD><a href= \" ../compta/facture.php?facid= $objp->facid\ " > $objp -> facnumber </ a ></ TD > \n " ;
2003-08-06 11:25:40 +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 \" > " . number_format ( $objp -> amount , 2 , ',' , ' ' ) . " </TD> \n " ;
$paye [ 1 ] = " pay<EFBFBD> e " ;
2004-01-24 20:30:03 +01:00
$paye [ 0 ] = " <b>impay<61> e</b> " ;
2003-08-06 11:25:40 +02:00
print " <TD align= \" center \" > " . $paye [ $objp -> paye ] . " </TD> \n " ;
print " </TR> \n " ;
$i ++ ;
2003-06-18 15:16:09 +02:00
}
2003-08-06 11:25:40 +02:00
$db -> free ();
2003-06-18 15:16:09 +02:00
}
2003-08-06 11:25:40 +02:00
else
{
print $db -> error ();
}
print " </table> " ;
2002-05-10 14:28:10 +02:00
}
/*
*
* Liste des projets associ<EFBFBD> s
*
*/
$sql = " SELECT p.rowid,p.title,p.ref, " . $db -> pdate ( " p.dateo " ) . " as do " ;
2004-01-31 00:38:49 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " projet as p WHERE p.fk_soc = $objsoc->idp " ;
2002-05-10 14:28:10 +02:00
if ( $db -> query ( $sql ) ) {
print " <table border=1 cellspacing=0 width=100% cellpadding= \" 1 \" > " ;
$i = 0 ;
$num = $db -> num_rows ();
if ( $num > 0 ) {
$tag = ! $tag ; print " <tr $bc[$tag] > " ;
2003-09-04 13:15:13 +02:00
print " <td colspan= \" 2 \" ><a href= \" ../projet/index.php?socidp= $objsoc->idp\ " > liste des projets ( $num ) </ td ></ tr > " ;
2002-05-10 14:28:10 +02:00
}
while ( $i < $num && $i < 5 ) {
$obj = $db -> fetch_object ( $i );
$tag = ! $tag ;
print " <tr $bc[$tag] > " ;
2003-09-04 13:15:13 +02:00
print '<td><a href="../projet/fiche.php?id=' . $obj -> rowid . '">' . $obj -> title . '</a></td>' ;
2002-05-10 14:28:10 +02:00
print " <td align= \" right \" > " . strftime ( " %d %b %Y " , $obj -> do ) . " </td></tr> " ;
$i ++ ;
}
$db -> free ();
print " </table> " ;
} else {
print $db -> error ();
}
/*
*
*
*/
print " </td></tr> " ;
print " </table> \n " ;
/*
*
*
*
*/
if ( $action == 'changevalue' ) {
print " <HR noshade> " ;
2003-08-25 12:19:25 +02:00
print " <form action= \" index.php?socid= $objsoc->idp\ " method = \ " post \" > " ;
2002-05-10 14:28:10 +02:00
print " <input type= \" hidden \" name= \" action \" value= \" cabrecrut \" > " ;
print " Cette soci<63> t<EFBFBD> est un cabinet de recrutement : " ;
print " <select name= \" selectvalue \" > " ;
print " <option value= \" \" > " ;
print " <option value= \" t \" >Oui " ;
print " <option value= \" f \" >Non " ;
print " </select> " ;
print " <input type= \" submit \" value= \" Mettre à jour \" > " ;
print " </form> \n " ;
} else {
/*
*
* Liste des contacts
*
*/
2003-05-02 13:57:36 +02:00
print '<table width="100%" cellspacing="0" border="0" cellpadding="2">' ;
2002-05-10 14:28:10 +02:00
2003-05-02 13:57:36 +02:00
print '<tr class="liste_titre"><td><b>Prénom Nom</b></td>' ;
2002-05-10 14:28:10 +02:00
print '<td><b>Poste</b></td><td><b>Tél</b></td>' ;
print " <td><b>Fax</b></td><td><b>Email</b></td> " ;
2003-09-11 22:18:51 +02:00
print " <td><a href= \" ../comm/people.php?socid= $objsoc->idp &action=addcontact \" >Ajouter</a></td></tr> " ;
2002-05-10 14:28:10 +02:00
2004-01-31 00:38:49 +01:00
$sql = " SELECT p.idp, p.name, p.firstname, p.poste, p.phone, p.fax, p.email, p.note FROM " . MAIN_DB_PREFIX . " socpeople as p WHERE p.fk_soc = $objsoc->idp ORDER by p.datec " ;
2002-05-10 14:28:10 +02:00
$result = $db -> query ( $sql );
2003-05-02 13:57:36 +02:00
$i = 0 ; $num = $db -> num_rows ();
2002-05-10 14:28:10 +02:00
2003-05-02 13:57:36 +02:00
while ( $i < $num )
{
$obj = $db -> fetch_object ( $i );
$var = ! $var ;
print " <tr $bc[$var] > " ;
print '<td>' ;
2003-09-11 22:18:51 +02:00
//print '<a href="action/fiche.php?action=create&actionid=5&contactid='.$obj->idp.'&socid='.$objsoc->idp.'">';
2003-05-02 13:57:36 +02:00
//print '<img border="0" src="/theme/'.$conf->theme.'/img/filenew.png"></a> ';
2003-09-11 22:18:51 +02:00
print '<a href="../comm/action/fiche.php?action=create&actionid=5&contactid=' . $obj -> idp . '&socid=' . $objsoc -> idp . '">' . $obj -> firstname . ' ' . $obj -> name . '</a> </td>' ;
2003-05-02 13:57:36 +02:00
if ( $obj -> note )
{
print " <br><b> " . nl2br ( $obj -> note );
}
print " </td> " ;
print " <td> $obj->poste </td> " ;
2003-09-11 22:18:51 +02:00
print '<td><a href="../comm/action/fiche.php?action=create&actionid=1&contactid=' . $obj -> idp . '&socid=' . $objsoc -> idp . '">' . $obj -> phone . '</a> </td>' ;
print '<td><a href="../comm/action/fiche.php?action=create&actionid=2&contactid=' . $obj -> idp . '&socid=' . $objsoc -> idp . '">' . $obj -> fax . '</a> </td>' ;
print '<td><a href="../comm/action/fiche.php?action=create&actionid=4&contactid=' . $obj -> idp . '&socid=' . $objsoc -> idp . '">' . $obj -> email . '</a> </td>' ;
print " <td><a href= \" ../comm/people.php?socid= $objsoc->idp &action=editcontact&contactid= $obj->idp\ " > Modifier </ a ></ td > " ;
2003-05-02 13:57:36 +02:00
print " </tr> \n " ;
$i ++ ;
$tag = ! $tag ;
2002-05-10 14:28:10 +02:00
}
print " </table> " ;
2003-05-02 13:57:36 +02:00
2002-05-10 14:28:10 +02:00
print " \n <hr noshade size=1> \n " ;
/*
*
*/
print '<table width="100%" cellspacing=0 border=0 cellpadding=2>' ;
print '<tr>' ;
print '<td valign="top">' ;
/*
*
* Listes des actions
*
*/
$sql = " SELECT a.id, " . $db -> pdate ( " a.datea " ) . " as da, c.libelle, u.code, a.propalrowid, a.fk_user_author, fk_contact, u.rowid " ;
2004-01-31 00:35:43 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " actioncomm as a, " . MAIN_DB_PREFIX . " c_actioncomm as c, " . MAIN_DB_PREFIX . " user as u " ;
2002-05-10 14:28:10 +02:00
$sql .= " WHERE a.fk_soc = $objsoc->idp " ;
$sql .= " AND u.rowid = a.fk_user_author " ;
$sql .= " AND c.id=a.fk_action " ;
$sql .= " ORDER BY a.datea DESC, a.id DESC " ;
if ( $db -> query ( $sql ) ) {
print " <table width= \" 100% \" cellspacing=0 border=0 cellpadding=2> \n " ;
$i = 0 ; $num = $db -> num_rows ();
while ( $i < $num ) {
$var = ! $var ;
$obj = $db -> fetch_object ( $i );
print " <tr $bc[$var] > " ;
if ( $oldyear == strftime ( " %Y " , $obj -> da ) ) {
print '<td align="center">|</td>' ;
} else {
print " <TD align= \" center \" > " . strftime ( " %Y " , $obj -> da ) . " </TD> \n " ;
$oldyear = strftime ( " %Y " , $obj -> da );
}
if ( $oldmonth == strftime ( " %Y%b " , $obj -> da ) ) {
print '<td align="center">|</td>' ;
} else {
print " <TD align= \" center \" > " . strftime ( " %b " , $obj -> da ) . " </TD> \n " ;
$oldmonth = strftime ( " %Y%b " , $obj -> da );
}
print " <TD> " . strftime ( " %d " , $obj -> da ) . " </TD> \n " ;
print " <TD> " . strftime ( " %H:%M " , $obj -> da ) . " </TD> \n " ;
print '<td width="10%"> </td>' ;
if ( $obj -> propalrowid ) {
2003-09-11 22:18:51 +02:00
print '<td width="40%"><a href="propal.php?propalid=' . $obj -> propalrowid . '">' . $obj -> libelle . '</a></td>' ;
2002-05-10 14:28:10 +02:00
} else {
print '<td width="40%">' . $obj -> libelle . '</td>' ;
}
/*
* Contact pour cette action
*
*/
if ( $obj -> fk_contact ) {
$contact = new Contact ( $db );
$contact -> fetch ( $obj -> fk_contact );
2003-09-11 22:18:51 +02:00
print '<td width="40%"><a href="people.php?socid=' . $objsoc -> idp . '&contactid=' . $contact -> id . '">' . $contact -> fullname . '</a></td>' ;
2002-05-10 14:28:10 +02:00
} else {
print '<td width="40%"> </td>' ;
}
/*
*/
2003-09-11 22:18:51 +02:00
print '<td width="20%"><a href="../user.php">' . $obj -> code . '</a></td>' ;
2002-05-10 14:28:10 +02:00
print " </tr> \n " ;
$i ++ ;
}
print " </table> " ;
$db -> free ();
} else {
print $db -> error ();
}
print " </td></tr></table> " ;
/*
*
* Notes sur la societe
*
*/
print '<table border="1" width="100%" cellspacing="0" bgcolor="#e0e0e0">' ;
print " <tr><td> " . nl2br ( $objsoc -> note ) . " </td></tr> " ;
print " </table> " ;
/*
*
*
*
*/
}
} else {
print $db -> error () . " <br> " . $sql ;
}
} else {
print " Erreur " ;
}
$db -> close ();
llxFooter ( " <em>Dernière modification $Date $ révision $Revision $ </em> " );
?>