PageRenderTime 154ms CodeModel.GetById 40ms RepoModel.GetById 9ms app.codeStats 0ms

/htdocs/comm/fiche.php

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