PageRenderTime 172ms CodeModel.GetById 61ms app.highlight 70ms RepoModel.GetById 30ms app.codeStats 1ms

/htdocs/comm/fiche.php

https://github.com/asterix14/dolibarr
PHP | 868 lines | 656 code | 117 blank | 95 comment | 145 complexity | de21a69d68cba9a2ef3691b600a3a228 MD5 | raw file
  1<?php
  2/* Copyright (C) 2001-2005 Rodolphe Quiedeville        <rodolphe@quiedeville.org>
  3 * Copyright (C) 2004-2011 Laurent Destailleur         <eldy@users.sourceforge.net>
  4 * Copyright (C) 2004      Eric Seigne                 <eric.seigne@ryxeo.com>
  5 * Copyright (C) 2006      Andre Cianfarani            <acianfa@free.fr>
  6 * Copyright (C) 2005-2011 Regis Houssin               <regis@dolibarr.fr>
  7 * Copyright (C) 2008      Raphael Bertrand (Resultic) <raphael.bertrand@resultic.fr>
  8 * Copyright (C) 2010-2011 Juanjo Menent               <jmenent@2byte.es>
  9 *
 10 * This program is free software; you can redistribute it and/or modify
 11 * it under the terms of the GNU General Public License as published by
 12 * the Free Software Foundation; either version 2 of the License, or
 13 * (at your option) any later version.
 14 *
 15 * This program is distributed in the hope that it will be useful,
 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 18 * GNU General Public License for more details.
 19 *
 20 * You should have received a copy of the GNU General Public License
 21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 22 */
 23
 24/**
 25 *       \file       htdocs/comm/fiche.php
 26 *       \ingroup    commercial compta
 27 *       \brief      Page to show customer card of a third party
 28 */
 29
 30require("../main.inc.php");
 31require_once(DOL_DOCUMENT_ROOT."/core/lib/company.lib.php");
 32require_once(DOL_DOCUMENT_ROOT."/core/lib/date.lib.php");
 33require_once(DOL_DOCUMENT_ROOT."/contact/class/contact.class.php");
 34if ($conf->facture->enabled) require_once(DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php");
 35if ($conf->propal->enabled) require_once(DOL_DOCUMENT_ROOT."/comm/propal/class/propal.class.php");
 36if ($conf->commande->enabled) require_once(DOL_DOCUMENT_ROOT."/commande/class/commande.class.php");
 37if ($conf->contrat->enabled) require_once(DOL_DOCUMENT_ROOT."/contrat/class/contrat.class.php");
 38if ($conf->adherent->enabled) require_once(DOL_DOCUMENT_ROOT."/adherents/class/adherent.class.php");
 39if ($conf->ficheinter->enabled) require_once(DOL_DOCUMENT_ROOT."/fichinter/class/fichinter.class.php");
 40if (!empty($conf->global->MAIN_MODULE_CHRONODOCS)) require_once(DOL_DOCUMENT_ROOT."/chronodocs/chronodocs_entries.class.php");
 41
 42$langs->load("companies");
 43if ($conf->contrat->enabled)  $langs->load("contracts");
 44if ($conf->commande->enabled) $langs->load("orders");
 45if ($conf->facture->enabled) $langs->load("bills");
 46if ($conf->projet->enabled)  $langs->load("projects");
 47if ($conf->ficheinter->enabled) $langs->load("interventions");
 48if ($conf->notification->enabled) $langs->load("mails");
 49if (!empty($conf->global->MAIN_MODULE_CHRONODOCS)) $langs->load("chronodocs");
 50
 51// Security check
 52$id = (GETPOST('socid','int') ? GETPOST('socid','int') : GETPOST('id'));
 53if ($user->societe_id > 0) $id=$user->societe_id;
 54$result = restrictedArea($user,'societe',$id,'');
 55
 56$action		= GETPOST('action');
 57$mode		= GETPOST("mode");
 58$modesearch	= GETPOST("mode_search");
 59
 60$sortfield = GETPOST("sortfield",'alpha');
 61$sortorder = GETPOST("sortorder",'alpha');
 62$page = GETPOST("page",'int');
 63if ($page == -1) { $page = 0; }
 64$offset = $conf->liste_limit * $page;
 65$pageprev = $page - 1;
 66$pagenext = $page + 1;
 67if (! $sortorder) $sortorder="ASC";
 68if (! $sortfield) $sortfield="nom";
 69
 70$object = new Societe($db);
 71
 72/*
 73 * Actions
 74 */
 75
 76if ($action == 'setcustomeraccountancycode')
 77{
 78	$result=$object->fetch($id);
 79	$object->code_compta=$_POST["customeraccountancycode"];
 80	$result=$object->update($object->id,$user,1,1,0);
 81	if ($result < 0)
 82	{
 83		$mesg=join(',',$object->errors);
 84	}
 85	$action="";
 86}
 87
 88if ($action == 'attribute_prefix' && $user->rights->societe->creer)
 89{
 90	$object->fetch($id);
 91	$object->attribute_prefix($db, $id);
 92}
 93// conditions de reglement
 94if ($action == 'setconditions' && $user->rights->societe->creer)
 95{
 96	$object->fetch($id);
 97	$object->cond_reglement=$_POST['cond_reglement_id'];
 98	
 99	// TODO move to DAO class
100	$sql = "UPDATE ".MAIN_DB_PREFIX."societe SET cond_reglement='".$_POST['cond_reglement_id'];
101	$sql.= "' WHERE rowid='".$id."'";
102	$result = $db->query($sql);
103	if (! $result) dol_print_error($result);
104}
105// mode de reglement
106if ($action == 'setmode' && $user->rights->societe->creer)
107{
108	$object->fetch($id);
109	$object->mode_reglement=$_POST['mode_reglement_id'];
110	
111	// TODO move to DAO class
112	$sql = "UPDATE ".MAIN_DB_PREFIX."societe SET mode_reglement='".$_POST['mode_reglement_id'];
113	$sql.= "' WHERE rowid='".$id."'";
114	$result = $db->query($sql);
115	if (! $result) dol_print_error($result);
116}
117// assujetissement a la TVA
118if ($action == 'setassujtva' && $user->rights->societe->creer)
119{
120	$object->fetch($id);
121	$object->tva_assuj=$_POST['assujtva_value'];
122	
123	// TODO move to DAO class
124	$sql = "UPDATE ".MAIN_DB_PREFIX."societe SET tva_assuj='".$_POST['assujtva_value']."' WHERE rowid='".$id."'";
125	$result = $db->query($sql);
126	if (! $result) dol_print_error($result);
127}
128
129
130
131/*
132 * View
133 */
134
135llxHeader('',$langs->trans('CustomerCard'));
136
137
138$contactstatic = new Contact($db);
139$userstatic=new User($db);
140$form = new Form($db);
141
142
143if ($mode == 'search')
144{
145	if ($modesearch == 'soc')
146	{
147		// TODO move to DAO class
148		$sql = "SELECT s.rowid";
149		if (!$user->rights->societe->client->voir && !$id) $sql .= ", sc.fk_soc, sc.fk_user ";
150		$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
151		if (!$user->rights->societe->client->voir && !$id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
152		$sql .= " WHERE lower(s.nom) like '%".strtolower($socname)."%'";
153		if (!$user->rights->societe->client->voir && !$id) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
154	}
155
156	$resql=$db->query($sql);
157	if ($resql)
158	{
159		if ( $db->num_rows($resql) == 1)
160		{
161			$obj = $db->fetch_object($resql);
162			$id = $obj->rowid;
163		}
164		$db->free($resql);
165	}
166}
167
168
169if ($id > 0)
170{
171	// Load data of third party
172	$object->fetch($id);
173	if ($object->id <= 0)
174	{
175		dol_print_error($db,$object->error);
176	}
177
178	if ($errmesg)
179	{
180		print "<b>".$errmesg."</b><br>";
181	}
182
183	/*
184	 * Affichage onglets
185	 */
186
187	$head = societe_prepare_head($object);
188
189	dol_fiche_head($head, 'customer', $langs->trans("ThirdParty"),0,'company');
190
191
192	print '<table width="100%" class="notopnoleftnoright">';
193	print '<tr><td valign="top" class="notopnoleft">';
194
195	print '<table class="border" width="100%">';
196
197	print '<tr><td width="30%">'.$langs->trans("ThirdPartyName").'</td><td width="70%" colspan="3">';
198	$object->next_prev_filter="te.client in (1,3)";
199	print $form->showrefnav($object,'socid','',($user->societe_id?0:1),'rowid','nom','','');
200	print '</td></tr>';
201
202	// Prefix
203    if (! empty($conf->global->SOCIETE_USEPREFIX))  // Old not used prefix field
204    {
205        print '<tr><td>'.$langs->trans("Prefix").'</td><td colspan="3">';
206	   print ($object->prefix_comm?$object->prefix_comm:'&nbsp;');
207	   print '</td></tr>';
208    }
209
210	if ($object->client)
211	{
212        $langs->load("compta");
213
214		print '<tr><td nowrap>';
215		print $langs->trans('CustomerCode').'</td><td colspan="3">';
216		print $object->code_client;
217		if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
218		print '</td></tr>';
219
220		print '<tr>';
221		print '<td>';
222		print $form->editfieldkey("CustomerAccountancyCode",'customeraccountancycode',$object->code_compta,$object,$user->rights->societe->creer);
223		print '</td><td colspan="3">';
224		print $form->editfieldval("CustomerAccountancyCode",'customeraccountancycode',$object->code_compta,$object,$user->rights->societe->creer);
225		print '</td>';
226		print '</tr>';
227	}
228
229	// Address
230	print '<tr><td valign="top">'.$langs->trans('Address').'</td><td colspan="3">';
231	dol_print_address($object->address,'gmap','thirdparty',$object->id);
232	print "</td></tr>";
233
234	// Zip / Town
235	print '<tr><td nowrap="nowrap">'.$langs->trans('Zip').' / '.$langs->trans('Town').'</td>';
236	print '<td colspan="3">'.$object->zip.(($object->zip && $object->town)?' / ':'').$object->town."</td>";
237	print '</tr>';
238
239	// Country
240	print '<tr><td>'.$langs->trans("Country").'</td><td colspan="3">';
241	$img=picto_from_langcode($object->country_code);
242	if ($object->isInEEC()) print $form->textwithpicto(($img?$img.' ':'').$object->country,$langs->trans("CountryIsInEEC"),1,0);
243	else print ($img?$img.' ':'').$object->country;
244	print '</td></tr>';
245
246	// Phone
247	print '<tr><td>'.$langs->trans('Phone').'</td><td style="min-width: 25%;">'.dol_print_phone($object->tel,$object->country_code,0,$object->id,'AC_TEL').'</td>';
248
249	// Fax
250	print '<td>'.$langs->trans('Fax').'</td><td style="min-width: 25%;">'.dol_print_phone($object->fax,$object->country_code,0,$object->id,'AC_FAX').'</td></tr>';
251
252	// EMail
253	print '<td>'.$langs->trans('EMail').'</td><td colspan="3">'.dol_print_email($object->email,0,$object->id,'AC_EMAIL').'</td></tr>';
254
255	// Web
256	print '<tr><td>'.$langs->trans("Web").'</td><td colspan="3">'.dol_print_url($object->url,'_blank').'</td></tr>';
257
258	// Assujeti a TVA ou pas
259	print '<tr>';
260	print '<td nowrap="nowrap">'.$langs->trans('VATIsUsed').'</td><td colspan="3">';
261	print yn($object->tva_assuj);
262	print '</td>';
263	print '</tr>';
264
265	// Local Taxes
266	if($mysoc->pays_code=='ES')
267	{
268		if($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj=="1")
269		{
270			print '<tr><td nowrap="nowrap">'.$langs->trans('LocalTax1IsUsedES').'</td><td colspan="3">';
271			print yn($object->localtax1_assuj);
272			print '</td></tr>';
273			print '<tr><td nowrap="nowrap">'.$langs->trans('LocalTax2IsUsedES').'</td><td colspan="3">';
274			print yn($object->localtax2_assuj);
275			print '</td></tr>';
276		}
277		elseif($mysoc->localtax1_assuj=="1")
278		{
279			print '<tr><td>'.$langs->trans("LocalTax1IsUsedES").'</td><td colspan="3">';
280			print yn($object->localtax1_assuj);
281			print '</td></tr>';
282		}
283		elseif($mysoc->localtax2_assuj=="1")
284		{
285			print '<tr><td>'.$langs->trans("LocalTax2IsUsedES").'</td><td colspan="3">';
286			print yn($object->localtax2_assuj);
287			print '</td></tr>';
288		}
289	}
290
291	// TVA Intra
292	print '<tr><td nowrap>'.$langs->trans('VATIntraVeryShort').'</td><td colspan="3">';
293	print $object->tva_intra;
294	print '</td></tr>';
295
296	// Conditions de reglement par defaut
297	$langs->load('bills');
298	$form = new Form($db);
299	print '<tr><td nowrap>';
300	print '<table width="100%" class="nobordernopadding"><tr><td nowrap>';
301	print $langs->trans('PaymentConditions');
302	print '<td>';
303	if (($action != 'editconditions') && $user->rights->societe->creer) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editconditions&amp;socid='.$object->id.'">'.img_edit($langs->trans('SetConditions'),1).'</a></td>';
304	print '</tr></table>';
305	print '</td><td colspan="3">';
306	if ($action == 'editconditions')
307	{
308		$form->form_conditions_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->cond_reglement,'cond_reglement_id',-1,1);
309	}
310	else
311	{
312		$form->form_conditions_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->cond_reglement,'none');
313	}
314	print "</td>";
315	print '</tr>';
316
317	// Mode de reglement par defaut
318	print '<tr><td nowrap>';
319	print '<table width="100%" class="nobordernopadding"><tr><td nowrap>';
320	print $langs->trans('PaymentMode');
321	print '<td>';
322	if (($action != 'editmode') && $user->rights->societe->creer) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editmode&amp;socid='.$object->id.'">'.img_edit($langs->trans('SetMode'),1).'</a></td>';
323	print '</tr></table>';
324	print '</td><td colspan="3">';
325	if ($action == 'editmode')
326	{
327		$form->form_modes_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->mode_reglement,'mode_reglement_id');
328	}
329	else
330	{
331		$form->form_modes_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->mode_reglement,'none');
332	}
333	print "</td>";
334	print '</tr>';
335
336	// Relative discounts (Discounts-Drawbacks-Rebates)
337	print '<tr><td nowrap>';
338	print '<table width="100%" class="nobordernopadding"><tr><td nowrap>';
339	print $langs->trans("CustomerRelativeDiscountShort");
340	print '<td><td align="right">';
341	if ($user->rights->societe->creer && !$user->societe_id > 0)
342	{
343		print '<a href="'.DOL_URL_ROOT.'/comm/remise.php?id='.$object->id.'">'.img_edit($langs->trans("Modify")).'</a>';
344	}
345	print '</td></tr></table>';
346	print '</td><td colspan="3">'.($object->remise_client?'<a href="'.DOL_URL_ROOT.'/comm/remise.php?id='.$object->id.'">'.$object->remise_client.'%</a>':$langs->trans("DiscountNone")).'</td>';
347	print '</tr>';
348
349	// Absolute discounts (Discounts-Drawbacks-Rebates)
350	print '<tr><td nowrap>';
351	print '<table width="100%" class="nobordernopadding">';
352	print '<tr><td nowrap>';
353	print $langs->trans("CustomerAbsoluteDiscountShort");
354	print '<td><td align="right">';
355	if ($user->rights->societe->creer && !$user->societe_id > 0)
356	{
357		print '<a href="'.DOL_URL_ROOT.'/comm/remx.php?id='.$object->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?socid='.$object->id).'">'.img_edit($langs->trans("Modify")).'</a>';
358	}
359	print '</td></tr></table>';
360	print '</td>';
361	print '<td colspan="3">';
362	$amount_discount=$object->getAvailableDiscounts();
363	if ($amount_discount < 0) dol_print_error($db,$object->error);
364	if ($amount_discount > 0) print '<a href="'.DOL_URL_ROOT.'/comm/remx.php?id='.$object->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?socid='.$object->id).'">'.price($amount_discount).'</a>&nbsp;'.$langs->trans("Currency".$conf->monnaie);
365	else print $langs->trans("DiscountNone");
366	print '</td>';
367	print '</tr>';
368
369	// Multiprice level
370	if ($conf->global->PRODUIT_MULTIPRICES)
371	{
372		print '<tr><td nowrap>';
373		print '<table width="100%" class="nobordernopadding"><tr><td nowrap>';
374		print $langs->trans("PriceLevel");
375		print '<td><td align="right">';
376		if ($user->rights->societe->creer)
377		{
378			print '<a href="'.DOL_URL_ROOT.'/comm/multiprix.php?id='.$object->id.'">'.img_edit($langs->trans("Modify")).'</a>';
379		}
380		print '</td></tr></table>';
381		print '</td><td colspan="3">'.$object->price_level."</td>";
382		print '</tr>';
383	}
384
385	// Old way to define delivery address (deprecated).
386	// Now all addresses types (like delivery addresses, invoices addresses,...) are saved as contacts.
387	if ($conf->global->PROPALE_ADD_DELIVERY_ADDRESS)	// Hidden deprecated feature.
388	{
389		print '<tr><td nowrap>';
390		print '<table width="100%" class="nobordernopadding"><tr><td nowrap>';
391		print $langs->trans("DeliveriesAddress");
392		print '<td><td align="right">';
393		if ($user->rights->societe->creer)
394		{
395			print '<a href="'.DOL_URL_ROOT.'/comm/address.php?socid='.$object->id.'">'.img_edit($langs->trans("Modify")).'</a>';
396		}
397		print '</td></tr></table>';
398		print '</td><td colspan="3">';
399		
400		// TODO move to DAO class
401		$sql = "SELECT count(rowid) as nb";
402		$sql.= " FROM ".MAIN_DB_PREFIX."societe_address";
403		$sql.= " WHERE fk_soc =".$object->id;
404
405		$resql = $db->query($sql);
406		if ($resql)
407		{
408			$num = $db->num_rows($resql);
409			$objal = $db->fetch_object($resql);
410			print $objal->nb?($objal->nb):$langs->trans("NoOtherDeliveryAddress");
411		}
412		else
413		{
414			dol_print_error($db);
415		}
416
417		print '</td>';
418		print '</tr>';
419	}
420
421    // Module Adherent
422    if ($conf->adherent->enabled)
423    {
424        $langs->load("members");
425        $langs->load("users");
426        print '<tr><td width="25%" valign="top">'.$langs->trans("LinkedToDolibarrMember").'</td>';
427        print '<td colspan="3">';
428        $adh=new Adherent($db);
429        $result=$adh->fetch('','',$object->id);
430        if ($result > 0)
431        {
432            $adh->ref=$adh->getFullName($langs);
433            print $adh->getNomUrl(1);
434        }
435        else
436        {
437            print $langs->trans("UserNotLinkedToMember");
438        }
439        print '</td>';
440        print "</tr>\n";
441    }
442
443	print "</table>";
444
445	print "</td>\n";
446
447
448	print '<td valign="top" width="50%" class="notopnoleftnoright">';
449
450	// Nbre max d'elements des petites listes
451	$MAXLIST=4;
452	$tableaushown=1;
453
454	// Lien recap
455	print '<table class="noborder" width="100%">';
456	print '<tr class="liste_titre">';
457	print '<td colspan="4"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("Summary").'</td>';
458	print '<td align="right"><a href="'.DOL_URL_ROOT.'/compta/recap-compta.php?socid='.$object->id.'">'.$langs->trans("ShowCustomerPreview").'</a></td></tr></table></td>';
459	print '</tr>';
460	print '</table>';
461	print '<br>';
462
463	$now=dol_now();
464
465	/*
466	 * Last proposals
467	 */
468	if ($conf->propal->enabled && $user->rights->propale->lire)
469	{
470		$propal_static = new Propal($db);
471
472		$proposals = $propal_static->liste_array(0, 0, 0, $object->id, $MAXLIST);
473
474		//var_dump($proposals);
475
476		$sql = "SELECT s.nom, s.rowid, p.rowid as propalid, p.fk_statut, p.total_ht, p.ref, p.remise, ";
477		$sql.= " p.datep as dp, p.fin_validite as datelimite";
478		$sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as p, ".MAIN_DB_PREFIX."c_propalst as c";
479		$sql.= " WHERE p.fk_soc = s.rowid AND p.fk_statut = c.id";
480		$sql.= " AND s.rowid = ".$object->id;
481		$sql.= " ORDER BY p.datep DESC";
482
483		$resql=$db->query($sql);
484		if ($resql)
485		{
486			$var=true;
487			$num = $db->num_rows($resql);
488
489            if ($num > 0)
490            {
491		        print '<table class="noborder" width="100%">';
492
493                print '<tr class="liste_titre">';
494    			print '<td colspan="4"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("LastPropals",($num<=$MAXLIST?"":$MAXLIST)).'</td><td align="right"><a href="'.DOL_URL_ROOT.'/comm/propal.php?socid='.$object->id.'">'.$langs->trans("AllPropals").' ('.$num.')</a></td>';
495                print '<td width="20px" align="right"><a href="'.DOL_URL_ROOT.'/comm/propal/stats/index.php?socid='.$object->id.'">'.img_picto($langs->trans("Statistics"),'stats').'</a></td>';
496    			print '</tr></table></td>';
497    			print '</tr>';
498            }
499
500			$i = 0;
501			while ($i < $num && $i < $MAXLIST)
502			{
503				$objp = $db->fetch_object($resql);
504				print "<tr $bc[$var]>";
505				print '<td nowrap><a href="propal.php?id='.$objp->propalid.'">'.img_object($langs->trans("ShowPropal"),"propal").' '.$objp->ref.'</a>'."\n";
506				if ( ($db->jdate($objp->dp) < ($now - $conf->propal->cloture->warning_delay)) && $objp->fk_statut == 1 )
507				{
508					print " ".img_warning();
509				}
510				print '</td><td align="right" width="80">'.dol_print_date($db->jdate($objp->dp),'day')."</td>\n";
511				print '<td align="right" width="120">'.price($objp->total_ht).'</td>';
512				print '<td align="right" nowrap="nowrap">'.$propal_static->LibStatut($objp->fk_statut,5).'</td></tr>';
513				$var=!$var;
514				$i++;
515			}
516			$db->free($resql);
517
518			if ($num > 0) print "</table>";
519		}
520		else
521		{
522			dol_print_error($db);
523		}
524	}
525
526	/*
527	 * Last orders
528	 */
529	if ($conf->commande->enabled && $user->rights->commande->lire)
530	{
531		$commande_static=new Commande($db);
532
533		$sql = "SELECT s.nom, s.rowid,";
534		$sql.= " c.rowid as cid, c.total_ht, c.ref, c.fk_statut, c.facture,";
535		$sql.= " c.date_commande as dc";
536		$sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande as c";
537		$sql.= " WHERE c.fk_soc = s.rowid ";
538		$sql.= " AND s.rowid = ".$object->id;
539		$sql.= " ORDER BY c.date_commande DESC";
540
541		$resql=$db->query($sql);
542		if ($resql)
543		{
544			$var=true;
545			$num = $db->num_rows($resql);
546
547			if ($num > 0)
548			{
549        		print '<table class="noborder" width="100%">';
550
551			    print '<tr class="liste_titre">';
552    			print '<td colspan="4"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("LastOrders",($num<=$MAXLIST?"":$MAXLIST)).'</td><td align="right"><a href="'.DOL_URL_ROOT.'/commande/liste.php?socid='.$object->id.'">'.$langs->trans("AllOrders").' ('.$num.')</a></td>';
553                print '<td width="20px" align="right"><a href="'.DOL_URL_ROOT.'/commande/stats/index.php?socid='.$object->id.'">'.img_picto($langs->trans("Statistics"),'stats').'</a></td>';
554    			print '</tr></table></td>';
555    			print '</tr>';
556			}
557
558			$i = 0;
559			while ($i < $num && $i < $MAXLIST)
560			{
561				$objp = $db->fetch_object($resql);
562				$var=!$var;
563				print "<tr $bc[$var]>";
564				print '<td nowrap="nowrap"><a href="'.DOL_URL_ROOT.'/commande/fiche.php?id='.$objp->cid.'">'.img_object($langs->trans("ShowOrder"),"order").' '.$objp->ref."</a>\n";
565				print '</td><td align="right" width="80">'.dol_print_date($db->jdate($objp->dc),'day')."</td>\n";
566				print '<td align="right" width="120">'.price($objp->total_ht).'</td>';
567				print '<td align="right" width="100">'.$commande_static->LibStatut($objp->fk_statut,$objp->facture,5).'</td></tr>';
568				$i++;
569			}
570			$db->free($resql);
571
572			if ($num >0) print "</table>";
573		}
574		else
575		{
576			dol_print_error($db);
577		}
578	}
579
580	/*
581	 * Last linked contracts
582	 */
583	if ($conf->contrat->enabled && $user->rights->contrat->lire)
584	{
585		$contratstatic=new Contrat($db);
586
587		$sql = "SELECT s.nom, s.rowid, c.rowid as id, c.ref as ref, c.statut, c.datec as dc";
588		$sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."contrat as c";
589		$sql .= " WHERE c.fk_soc = s.rowid ";
590		$sql .= " AND s.rowid = ".$object->id;
591		$sql .= " ORDER BY c.datec DESC";
592
593		$resql=$db->query($sql);
594		if ($resql)
595		{
596			$var=true;
597			$num = $db->num_rows($resql);
598			if ($num >0 )
599			{
600		        print '<table class="noborder" width="100%">';
601
602			    print '<tr class="liste_titre">';
603				print '<td colspan="4"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("LastContracts",($num<=$MAXLIST?"":$MAXLIST)).'</td>';
604				print '<td align="right"><a href="'.DOL_URL_ROOT.'/contrat/liste.php?socid='.$object->id.'">'.$langs->trans("AllContracts").' ('.$num.')</a></td></tr></table></td>';
605				print '</tr>';
606			}
607			$i = 0;
608			while ($i < $num && $i < $MAXLIST)
609			{
610				$contrat=new Contrat($db);
611
612				$objp = $db->fetch_object($resql);
613				$var=!$var;
614				print "<tr $bc[$var]>";
615				print '<td nowrap="nowrap">';
616				$contrat->id=$objp->id;
617				$contrat->ref=$objp->ref?$objp->ref:$objp->id;
618				print $contrat->getNomUrl(1,12);
619				print "</td>\n";
620				print '<td align="right" width="80">'.dol_print_date($db->jdate($objp->dc),'day')."</td>\n";
621				print '<td width="20">&nbsp;</td>';
622				print '<td align="right" nowrap="nowrap">';
623				$contrat->fetch_lines();
624				print $contrat->getLibStatut(4);
625				print "</td>\n";
626				print '</tr>';
627				$i++;
628			}
629			$db->free($resql);
630
631			if ($num > 0) print "</table>";
632		}
633		else
634		{
635			dol_print_error($db);
636		}
637	}
638
639	/*
640	 * Last interventions
641	 */
642	if ($conf->ficheinter->enabled && $user->rights->ficheinter->lire)
643	{
644		$sql = "SELECT s.nom, s.rowid, f.rowid as id, f.ref, f.duree as duration, f.datei as startdate";
645		$sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."fichinter as f";
646		$sql .= " WHERE f.fk_soc = s.rowid";
647		$sql .= " AND s.rowid = ".$object->id;
648		$sql .= " ORDER BY f.tms DESC";
649
650		$fichinter_static=new Fichinter($db);
651
652		$resql=$db->query($sql);
653		if ($resql)
654		{
655			$var=true;
656			$num = $db->num_rows($resql);
657			if ($num > 0)
658			{
659		        print '<table class="noborder" width="100%">';
660
661			    print '<tr class="liste_titre">';
662				print '<td colspan="4"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("LastInterventions",($num<=$MAXLIST?"":$MAXLIST)).'</td><td align="right"><a href="'.DOL_URL_ROOT.'/fichinter/list.php?socid='.$object->id.'">'.$langs->trans("AllInterventions").' ('.$num.')</td></tr></table></td>';
663				print '</tr>';
664				$var=!$var;
665			}
666			$i = 0;
667			while ($i < $num && $i < $MAXLIST)
668			{
669                $fichinter_static->id=$objp->id;
670
671				$objp = $db->fetch_object($resql);
672				print "<tr ".$bc[$var].">";
673				print '<td nowrap="nowrap"><a href="'.DOL_URL_ROOT.'/fichinter/fiche.php?id='.$objp->id.'">'.img_object($langs->trans("ShowPropal"),"propal").' '.$objp->ref.'</a></td>'."\n";
674                //print '<td align="right">'.dol_print_date($db->jdate($objp->startdate)).'</td>'."\n";
675				print '<td align="right">'.ConvertSecondToTime($objp->duration).'</td>'."\n";
676				print '<td align="right">'.$fichinter_static->getLibStatut(3).'</td>'."\n";
677				print '</tr>';
678				$var=!$var;
679				$i++;
680			}
681			$db->free($resql);
682
683			if ($num > 0) print "</table>";
684		}
685		else
686		{
687			dol_print_error($db);
688		}
689	}
690
691	/*
692	 *   Last invoices
693	 */
694	if ($conf->facture->enabled && $user->rights->facture->lire)
695	{
696		$facturestatic = new Facture($db);
697
698		$sql = 'SELECT f.rowid as facid, f.facnumber, f.type, f.amount, f.total, f.total_ttc,';
699		$sql.= ' f.datef as df, f.datec as dc, f.paye as paye, f.fk_statut as statut,';
700		$sql.= ' s.nom, s.rowid as socid,';
701		$sql.= ' SUM(pf.amount) as am';
702		$sql.= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f";
703		$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON f.rowid=pf.fk_facture';
704		$sql.= " WHERE f.fk_soc = s.rowid AND s.rowid = ".$object->id;
705		$sql.= ' GROUP BY f.rowid, f.facnumber, f.type, f.amount, f.total, f.total_ttc,';
706		$sql.= ' f.datef, f.datec, f.paye, f.fk_statut,';
707		$sql.= ' s.nom, s.rowid';
708		$sql.= " ORDER BY f.datef DESC, f.datec DESC";
709
710		$resql=$db->query($sql);
711		if ($resql)
712		{
713			$var=true;
714			$num = $db->num_rows($resql);
715			$i = 0;
716			if ($num > 0)
717			{
718		        print '<table class="noborder" width="100%">';
719
720			    $tableaushown=1;
721				print '<tr class="liste_titre">';
722				print '<td colspan="4"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("LastCustomersBills",($num<=$MAXLIST?"":$MAXLIST)).'</td><td align="right"><a href="'.DOL_URL_ROOT.'/compta/facture.php?socid='.$object->id.'">'.$langs->trans("AllBills").' ('.$num.')</a></td>';
723                print '<td width="20px" align="right"><a href="'.DOL_URL_ROOT.'/compta/facture/stats/index.php?socid='.$object->id.'">'.img_picto($langs->trans("Statistics"),'stats').'</a></td>';
724				print '</tr></table></td>';
725				print '</tr>';
726			}
727
728			while ($i < $num && $i < $MAXLIST)
729			{
730				$objp = $db->fetch_object($resql);
731				$var=!$var;
732				print "<tr $bc[$var]>";
733				print '<td>';
734				$facturestatic->id=$objp->facid;
735				$facturestatic->ref=$objp->facnumber;
736				$facturestatic->type=$objp->type;
737				print $facturestatic->getNomUrl(1);
738				print '</td>';
739				if ($objp->df > 0)
740				{
741					print "<td align=\"right\">".dol_print_date($db->jdate($objp->df),'day')."</td>\n";
742				}
743				else
744				{
745					print "<td align=\"right\"><b>!!!</b></td>\n";
746				}
747				print "<td align=\"right\">".price($objp->total_ttc)."</td>\n";
748
749				print '<td align="right" nowrap="nowrap">'.($facturestatic->LibStatut($objp->paye,$objp->statut,5,$objp->am))."</td>\n";
750				print "</tr>\n";
751				$i++;
752			}
753			$db->free($resql);
754
755			if ($num > 0) print "</table>";
756		}
757		else
758		{
759			dol_print_error($db);
760		}
761	}
762
763	print "</td></tr>";
764	print "</table>";
765
766	print "\n</div>\n";
767
768
769	/*
770	 * Barre d'actions
771	 */
772	print '<div class="tabsAction">';
773
774	if ($conf->propal->enabled && $user->rights->propale->creer)
775	{
776		$langs->load("propal");
777		print '<a class="butAction" href="'.DOL_URL_ROOT.'/comm/addpropal.php?socid='.$object->id.'&amp;action=create">'.$langs->trans("AddProp").'</a>';
778	}
779
780	if ($conf->commande->enabled && $user->rights->commande->creer)
781	{
782		$langs->load("orders");
783		print '<a class="butAction" href="'.DOL_URL_ROOT.'/commande/fiche.php?socid='.$object->id.'&amp;action=create">'.$langs->trans("AddOrder").'</a>';
784	}
785
786	if ($user->rights->contrat->creer)
787	{
788		$langs->load("contracts");
789		print '<a class="butAction" href="'.DOL_URL_ROOT.'/contrat/fiche.php?socid='.$object->id.'&amp;action=create">'.$langs->trans("AddContract").'</a>';
790	}
791
792	if ($conf->ficheinter->enabled && $user->rights->ficheinter->creer)
793	{
794		$langs->load("fichinter");
795		print '<a class="butAction" href="'.DOL_URL_ROOT.'/fichinter/fiche.php?socid='.$object->id.'&amp;action=create">'.$langs->trans("AddIntervention").'</a>';
796	}
797
798	// Add invoice
799	if ($user->societe_id == 0)
800	{
801		if ($conf->deplacement->enabled)
802		{
803			$langs->load("trips");
804			print '<a class="butAction" href="'.DOL_URL_ROOT.'/compta/deplacement/fiche.php?socid='.$object->id.'&amp;action=create">'.$langs->trans("AddTrip").'</a>';
805		}
806
807		if ($conf->facture->enabled)
808		{
809			if ($user->rights->facture->creer)
810			{
811				$langs->load("bills");
812				if ($object->client != 0) print '<a class="butAction" href="'.DOL_URL_ROOT.'/compta/facture.php?action=create&socid='.$object->id.'">'.$langs->trans("AddBill").'</a>';
813				else print '<a class="butActionRefused" title="'.dol_escape_js($langs->trans("ThirdPartyMustBeEditAsCustomer")).'" href="#">'.$langs->trans("AddBill").'</a>';
814			}
815			else
816			{
817				print '<a class="butActionRefused" title="'.dol_escape_js($langs->trans("ThirdPartyMustBeEditAsCustomer")).'" href="#">'.$langs->trans("AddBill").'</a>';
818			}
819		}
820	}
821
822	// Add action
823	if ($conf->agenda->enabled && ! empty($conf->global->MAIN_REPEATTASKONEACHTAB))
824	{
825		if ($user->rights->agenda->myactions->create)
826		{
827			print '<a class="butAction" href="'.DOL_URL_ROOT.'/comm/action/fiche.php?action=create&socid='.$object->id.'">'.$langs->trans("AddAction").'</a>';
828		}
829		else
830		{
831			print '<a class="butAction" title="'.dol_escape_js($langs->trans("NotAllowed")).'" href="#">'.$langs->trans("AddAction").'</a>';
832		}
833	}
834
835	/*if ($user->rights->societe->contact->creer)
836	{
837		print '<a class="butAction" href="'.DOL_URL_ROOT.'/contact/fiche.php?socid='.$object->id.'&amp;action=create">'.$langs->trans("AddContact").'</a>';
838	}*/
839
840	print '</div>';
841	print "<br>\n";
842
843	if (! empty($conf->global->MAIN_REPEATCONTACTONEACHTAB))
844	{
845	    print '<br>';
846		// List of contacts
847		show_contacts($conf,$langs,$db,$object,$_SERVER["PHP_SELF"].'?socid='.$object->id);
848	}
849
850    if (! empty($conf->global->MAIN_REPEATTASKONEACHTAB))
851    {
852		// List of todo actions
853		show_actions_todo($conf,$langs,$db,$object);
854
855        // List of done actions
856		show_actions_done($conf,$langs,$db,$object);
857	}
858}
859else
860{
861	dol_print_error($db,'Bad value for socid parameter');
862}
863
864$db->close();
865
866
867llxFooter();
868?>