PageRenderTime 56ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/comm/fiche.php

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