* Copyright (C) 2004-2005 Laurent Destailleur * Copyright (C) 2004 Eric Seigne * * 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$ * */ /*! \file htdocs/comm/fiche.php \ingroup commercial \brief Onglet client de la fiche societe \version $Revision$ */ require("./pre.inc.php"); require("../contact.class.php"); require("../actioncomm.class.php"); $langs->load("companies"); $langs->load("orders"); $langs->load("contracts"); $user->getrights(); llxHeader('',$langs->trans('CustomerCard')); $sortorder=$_GET["sortorder"]; $sortfield=$_GET["sortfield"]; if ($sortorder == "") { $sortorder="ASC"; } if ($sortfield == "") { $sortfield="nom"; } if ($_GET["action"] == 'attribute_prefix') { $societe = new Societe($db, $_GET["socid"]); $societe->attribute_prefix($db, $_GET["socid"]); } if ($action == 'recontact') { $dr = mktime(0, 0, 0, $remonth, $reday, $reyear); $sql = "INSERT INTO ".MAIN_DB_PREFIX."soc_recontact (fk_soc, datere, author) VALUES ($socid, $dr,'". $user->login ."')"; $result = $db->query($sql); } if ($action == 'stcomm') { if ($stcommid <> 'null' && $stcommid <> $oldstcomm) { $sql = "INSERT INTO socstatutlog (datel, fk_soc, fk_statut, author) "; $sql .= " VALUES ('$dateaction',$socid,$stcommid,'" . $user->login . "')"; $result = @$db->query($sql); if ($result) { $sql = "UPDATE ".MAIN_DB_PREFIX."societe SET fk_stcomm=$stcommid WHERE idp=$socid"; $result = $db->query($sql); } else { $errmesg = "ERREUR DE DATE !"; } } if ($actioncommid) { $sql = "INSERT INTO ".MAIN_DB_PREFIX."actioncomm (datea, fk_action, fk_soc, fk_user_author) VALUES ('$dateaction',$actioncommid,$socid,'" . $user->id . "')"; $result = @$db->query($sql); if (!$result) { $errmesg = "ERREUR DE DATE !"; } } } /* * Recherche * * */ if ($mode == 'search') { if ($mode-search == 'soc') { $sql = "SELECT s.idp FROM ".MAIN_DB_PREFIX."societe as s "; $sql .= " WHERE lower(s.nom) like '%".strtolower($socname)."%'"; } if ( $db->query($sql) ) { if ( $db->num_rows() == 1) { $obj = $db->fetch_object(); $socid = $obj->idp; } $db->free(); } } /* * */ $_socid = $_GET["socid"]; /* * Sécurité si un client essaye d'accéder à une autre fiche que la sienne */ if ($user->societe_id > 0) { $_socid = $user->societe_id; } /********************************************************************************* * * Mode fiche * * *********************************************************************************/ if ($_socid > 0) { // On recupere les donnees societes par l'objet $objsoc = new Societe($db); $objsoc->id=$_socid; $objsoc->fetch($_socid,$to); $dac = strftime("%Y-%m-%d %H:%M", time()); if ($errmesg) { print "$errmesg
"; } /* * Affichage onglets */ $h = 0; $head[$h][0] = DOL_URL_ROOT.'/soc.php?socid='.$objsoc->id; $head[$h][1] = $langs->trans("Company"); $h++; if ($objsoc->client==1) { $hselected=$h; $head[$h][0] = DOL_URL_ROOT.'/comm/fiche.php?socid='.$objsoc->id; $head[$h][1] = $langs->trans("Customer");; $h++; } if ($objsoc->client==2) { $hselected=$h; $head[$h][0] = DOL_URL_ROOT.'/comm/prospect/fiche.php?id='.$obj->socid; $head[$h][1] = $langs->trans("Prospect"); $h++; } if ($objsoc->fournisseur) { $head[$h][0] = DOL_URL_ROOT.'/fourn/fiche.php?socid='.$objsoc->id; $head[$h][1] = $langs->trans("Supplier"); $h++; } if ($conf->compta->enabled) { $langs->load("compta"); $head[$h][0] = DOL_URL_ROOT.'/compta/fiche.php?socid='.$objsoc->id; $head[$h][1] = $langs->trans("Accountancy"); $h++; } $head[$h][0] = DOL_URL_ROOT.'/socnote.php?socid='.$objsoc->id; $head[$h][1] = $langs->trans("Note"); $h++; if ($user->societe_id == 0) { $head[$h][0] = DOL_URL_ROOT.'/docsoc.php?socid='.$objsoc->id; $head[$h][1] = $langs->trans("Documents"); $h++; } $head[$h][0] = DOL_URL_ROOT.'/societe/notify/fiche.php?socid='.$objsoc->id; $head[$h][1] = $langs->trans("Notifications"); $h++; if ($user->societe_id == 0) { $head[$h][0] = DOL_URL_ROOT."/comm/index.php?socidp=$objsoc->id&action=add_bookmark"; $head[$h][1] = 'Bookmark'; $head[$h][2] = 'image'; $h++; } dolibarr_fiche_head($head, $hselected, $objsoc->nom); /* * * */ print ''; print '\n"; print '"; print "
'; print ''; print ''; print "'; print ''; print '"; print ""; print '"; print ""; print '"; print ''; print ''; print ''; print "
'.$langs->trans("Name").''; print $objsoc->nom; print ''.$objsoc->code_client.'
".$langs->trans("Address")."".nl2br($objsoc->adresse); print '
'.$objsoc->cp." ".$objsoc->ville; print '
'.$objsoc->pays.'
'.$langs->trans("Phone").''.dolibarr_print_phone($objsoc->tel).' Fax'.dolibarr_print_phone($objsoc->fax).' 
'.$langs->trans("Web")."url\">$objsoc->url 
".$langs->transcountry("ProfId1",$objsoc->pays_code)."siren\">$objsoc->siren '.$langs->trans("Prefix").''; if ($objsoc->prefix_comm) { print $objsoc->prefix_comm; } else { print "[id&action=attribute_prefix\">Attribuer]"; } print "
".$langs->trans("Type")." $objsoc->typentEffectif$objsoc->effectif
'; print $langs->trans("CustomerDiscount").''.$objsoc->remise_client." %'; print img_edit($langs->trans("Modify")); print ""; print '
Remise exceptionnelles'; print ''; print img_edit($langs->trans("Modify")); print ""; print '
"; print "
"; /* * */ print "
'; // Nbre max d'éléments des petites listes $MAXLIST=4; /* * Dernieres propales */ if ($conf->propal->enabled) { print ''; $sql = "SELECT s.nom, s.idp, p.rowid as propalid, p.price, p.ref, p.remise, ".$db->pdate("p.datep")." as dp, c.label as statut, c.id as statutid"; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as p, ".MAIN_DB_PREFIX."c_propalst as c"; $sql .= " WHERE p.fk_soc = s.idp AND p.fk_statut = c.id"; $sql .= " AND s.idp = ".$objsoc->id; $sql .= " ORDER BY p.datep DESC"; if ( $db->query($sql) ) { $var=true; $num = $db->num_rows(); if ($num >0 ) { print ""; print ''; print ''; $var=!$var; } $i = 0; $now = time(); $lim = 3600 * 24 * 15 ; while ($i < $num && $i < $MAXLIST) { $objp = $db->fetch_object(); print ""; print "\n"; print ''; print ''; $var=!$var; $i++; } $db->free(); } else { dolibarr_print_error($db); } print "
'.$langs->trans("LastPropals",($num<=$MAXLIST?"":$MAXLIST)).''.$langs->trans("AllPropals").' ('.$num.')
propalid\">".img_object($langs->trans("ShowPropal"),"propal")." ".$objp->ref."\n"; if ( ($now - $objp->dp) > $lim && $objp->statutid == 1 ) { print " > 15 jours"; } print "".strftime("%d %B %Y",$objp->dp)."'.price($objp->price).''.$objp->statut.'
"; } /* * Dernieres commandes */ if($conf->commande->enabled) { print ''; $sql = "SELECT s.nom, s.idp, p.rowid as propalid, p.total_ht, p.ref, ".$db->pdate("p.date_commande")." as dp"; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande as p"; $sql .= " WHERE p.fk_soc = s.idp "; $sql .= " AND s.idp = $objsoc->id"; $sql .= " ORDER BY p.date_commande DESC"; if ( $db->query($sql) ) { $var=true; $num = $db->num_rows(); if ($num >0 ) { print ""; print ''; print ''; } $i = 0; $now = time(); $lim = 3600 * 24 * 15 ; while ($i < $num && $i < $MAXLIST) { $objp = $db->fetch_object(); $var=!$var; print ""; print '\n"; print ''; print ''; $i++; } $db->free(); } print "
'.$langs->trans("LastOrders",($num<=$MAXLIST?"":$MAXLIST)).''.$langs->trans("AllOrders").' ('.$num.')
'.img_object($langs->trans("ShowOrder"),"order").' '.$objp->ref."\n"; if ( ($now - $objp->dp) > $lim && $objp->statutid == 1 ) { print " > 15 jours"; } print "".strftime("%d %B %Y",$objp->dp)."'.price($objp->total_ht).''.$objp->statut.'
"; } /* * Derniers projets associés */ if ($conf->projet->enabled) { print ''; $sql = "SELECT p.rowid,p.title,p.ref,".$db->pdate("p.dateo")." as do"; $sql .= " FROM ".MAIN_DB_PREFIX."projet as p"; $sql .= " WHERE p.fk_soc = $objsoc->id"; $sql .= " ORDER BY p.dateo DESC"; if ( $db->query($sql) ) { $var=true; $i = 0 ; $num = $db->num_rows(); if ($num > 0) { print ""; print ''; print ''; } while ($i < $num && $i < $MAXLIST) { $obj = $db->fetch_object(); $var = !$var; print ""; print ''; print ""; $i++; } $db->free(); } else { dolibarr_print_error($db); } print "
'.$langs->trans("LastProjects",($num<=$MAXLIST?"":$MAXLIST)).''.$langs->trans("AllProjects").' ('.$num.')
'.$obj->title.'".$obj->ref ."
"; } /* * * */ print "
\n"; /* * Barre d'action * */ print '
'; if ($conf->propal->enabled && $user->rights->propale->creer) { $langs->load("propal"); print ''.$langs->trans("AddProp").''; } if ($user->rights->contrat->creer) { $langs->load("contracts"); print ''.$langs->trans("AddContract").''; } if ($conf->commande->enabled && $user->rights->commande->creer) { $langs->load("orders"); print ''.$langs->trans("AddOrder").''; } if ($conf->projet->enabled && $user->rights->projet->creer) { print ''.$langs->trans("AddProject").''; } if ($conf->fichinter->enabled) { print 'Intervention'; } print ''.$langs->trans("AddContact").''; print '
'; print '
'; /* * * * */ if ($action == 'changevalue') { print "
"; print "
id\" method=\"post\">"; print ""; print "Cette société est un cabinet de recrutement : "; print ""; print "trans("Valid")."\">"; print "
\n"; } else { /* * * Liste des contacts * */ if ($conf->clicktodial->enabled) { $user->fetch_clicktodial(); // lecture des infos de clicktodial } print ''; print ''; print ''; print ''; print ""; print ''; print ""; $sql = "SELECT p.idp, p.name, p.firstname, p.poste, p.phone, p.fax, p.email, p.note "; $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as p"; $sql .= " WHERE p.fk_soc = $objsoc->id"; $sql .= " ORDER by p.datec"; $result = $db->query($sql); $i = 0 ; $num = $db->num_rows(); $tag = True; while ($i < $num) { $obj = $db->fetch_object(); $var = !$var; print ""; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print "\n"; $i++; $tag = !$tag; } print "
'.$langs->trans("Firstname").' '.$langs->trans("Lastname").''.$langs->trans("Poste").''.$langs->trans("Tel").''.$langs->trans("Fax").''.$langs->trans("EMail").'  
'; print ''; print img_object($langs->trans("Show"),"contact"); print ' '.$obj->firstname.' '. $obj->name.' '; if (trim($obj->note)) { print '
'.nl2br(trim($obj->note)); } print '
'.$obj->poste.' '; /* * Lien click to dial */ if (strlen($obj->phone) && $user->clicktodial_enabled == 1) { print ''; print img_phone_out("Appel émis") ; } print ''; print ''.dolibarr_print_phone($obj->phone).' '.dolibarr_print_phone($obj->fax).' '.$obj->email.' '; print "idp\">"; print img_edit(); print ''; print img_object($langs->trans("Rendez-Vous"),"action"); print '
"; print "
"; /* * Listes des actions a faire * */ print ''; print ''; print ''; print '
'.$langs->trans("ActionsToDo").' '.$langs->trans("AddActionToDo").'
'; $sql = "SELECT a.id, ".$db->pdate("a.datea")." as da, c.libelle, u.code, a.propalrowid, a.fk_user_author, fk_contact, u.rowid "; $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm as a, ".MAIN_DB_PREFIX."c_actioncomm as c, ".MAIN_DB_PREFIX."user as u "; $sql .= " WHERE a.fk_soc = $objsoc->id "; $sql .= " AND u.rowid = a.fk_user_author"; $sql .= " AND c.id=a.fk_action AND a.percent < 100"; $sql .= " ORDER BY a.datea DESC, a.id DESC"; if ( $db->query($sql) ) { print "\n"; $i = 0 ; $num = $db->num_rows(); while ($i < $num) { $var = !$var; $obj = $db->fetch_object(); print ""; if ($oldyear == strftime("%Y",$obj->da) ) { //print ''; print "\n"; } else { print "\n"; $oldyear = strftime("%Y",$obj->da); } if ($oldmonth == strftime("%Y%b",$obj->da) ) { //print ''; print "\n"; } else { print "\n"; $oldmonth = strftime("%Y%b",$obj->da); } print "\n"; print "\n"; print ''; if ($obj->propalrowid) { print ''; } else { print ''; } /* * Contact pour cette action * */ if ($obj->fk_contact) { $contact = new Contact($db); $contact->fetch($obj->fk_contact); print ''; } else { print ''; } /* */ print ''; print "\n"; $i++; } print "
|" .strftime("%Y",$obj->da)."" .strftime("%Y",$obj->da)."|" .strftime("%b",$obj->da)."" .strftime("%b",$obj->da)."" .strftime("%d",$obj->da)."" .strftime("%H:%M",$obj->da)." '.img_object($langs->trans("ShowTask"),"task").' '.$obj->libelle.''.img_object($langs->trans("ShowTask"),"task").' '.$obj->libelle.''.img_object($langs->trans("ShowContact"),"contact").' '.$contact->fullname.' '.$obj->code.'
"; $db->free(); } else { dolibarr_print_error($db); } print "
"; /* * Listes des actions effectuees */ print ''; print ''; print ''; print '
'.$langs->trans("ActionsDone").'
'; $sql = "SELECT a.id, ".$db->pdate("a.datea")." as da, c.libelle, u.code, a.propalrowid, a.fk_user_author, fk_contact, u.rowid "; $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm as a, ".MAIN_DB_PREFIX."c_actioncomm as c, ".MAIN_DB_PREFIX."user as u "; $sql .= " WHERE a.fk_soc = $objsoc->id "; $sql .= " AND u.rowid = a.fk_user_author"; $sql .= " AND c.id=a.fk_action AND a.percent = 100"; $sql .= " ORDER BY a.datea DESC, a.id DESC"; if ( $db->query($sql) ) { print ''; $i = 0 ; $num = $db->num_rows(); $oldyear=''; $oldmonth=''; while ($i < $num) { $var = !$var; $obj = $db->fetch_object(); print ""; if ($oldyear == strftime("%Y",$obj->da) ) { print ''; } else { print "\n"; $oldyear = strftime("%Y",$obj->da); } if ($oldmonth == strftime("%Y%b",$obj->da) ) { print ''; } else { print "\n"; $oldmonth = strftime("%Y%b",$obj->da); } print "\n"; print "\n"; print ''; if ($obj->propalrowid) { print ''; } else { print ''; } /* * Contact pour cette action * */ if ($obj->fk_contact) { $contact = new Contact($db); $contact->fetch($obj->fk_contact); print ''; } else { print ''; } /* */ print ''; print "\n"; $i++; } print "
|" .strftime("%Y",$obj->da)."|" .strftime("%b",$obj->da)."" .strftime("%d",$obj->da)."" .strftime("%H:%M",$obj->da)." '.img_object($langs->trans("ShowTask"),"task").' '.$obj->libelle.''.img_object($langs->trans("ShowTask"),"task").' '.$obj->libelle.''.img_object($langs->trans("Showcontact"),"contact").' '.$contact->fullname.' '.$obj->code.'
"; $db->free(); } else { dolibarr_print_error($db); } print "
"; /* * * Notes sur la societe * */ if ($objsoc->note) { print ''; print ""; print "
".nl2br($objsoc->note)."
"; } /* * * * */ } } else { dolibarr_print_error($db); } $db->close(); llxFooter("Dernière modification $Date$ révision $Revision$"); ?>