card.php 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156
  1. <?php
  2. /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2015 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-2014 Juanjo Menent <jmenent@2byte.es>
  9. * Copyright (C) 2013 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
  10. * Copyright (C) 2015 Frederic France <frederic.france@free.fr>
  11. * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 3 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. */
  25. /**
  26. * \file htdocs/comm/card.php
  27. * \ingroup commercial compta
  28. * \brief Page to show customer card of a third party
  29. */
  30. require '../main.inc.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  33. require_once DOL_DOCUMENT_ROOT.'/societe/class/client.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  36. require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
  37. if (! empty($conf->facture->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  38. if (! empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
  39. if (! empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
  40. if (! empty($conf->expedition->enabled)) require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
  41. if (! empty($conf->contrat->enabled)) require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
  42. if (! empty($conf->adherent->enabled)) require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  43. if (! empty($conf->ficheinter->enabled)) require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
  44. $langs->load("companies");
  45. $langs->load('banks');
  46. if (! empty($conf->contrat->enabled)) $langs->load("contracts");
  47. if (! empty($conf->commande->enabled)) $langs->load("orders");
  48. if (! empty($conf->expedition->enabled)) $langs->load("sendings");
  49. if (! empty($conf->facture->enabled)) $langs->load("bills");
  50. if (! empty($conf->projet->enabled)) $langs->load("projects");
  51. if (! empty($conf->ficheinter->enabled)) $langs->load("interventions");
  52. if (! empty($conf->notification->enabled)) $langs->load("mails");
  53. // Security check
  54. $id = (GETPOST('socid','int') ? GETPOST('socid','int') : GETPOST('id','int'));
  55. if ($user->societe_id > 0) $id=$user->societe_id;
  56. $result = restrictedArea($user,'societe',$id,'&societe');
  57. $action = GETPOST('action');
  58. $mode = GETPOST("mode");
  59. $sortfield = GETPOST("sortfield",'alpha');
  60. $sortorder = GETPOST("sortorder",'alpha');
  61. $page = GETPOST("page",'int');
  62. if ($page == -1) { $page = 0; }
  63. $offset = $conf->liste_limit * $page;
  64. $pageprev = $page - 1;
  65. $pagenext = $page + 1;
  66. if (! $sortorder) $sortorder="ASC";
  67. if (! $sortfield) $sortfield="nom";
  68. $cancelbutton = GETPOST('cancel');
  69. $object = new Client($db);
  70. $extrafields = new ExtraFields($db);
  71. // fetch optionals attributes and labels
  72. $extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
  73. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  74. $hookmanager->initHooks(array('commcard','globalcard'));
  75. /*
  76. * Actions
  77. */
  78. $parameters = array('id' => $id, 'socid' => $id);
  79. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some
  80. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  81. if (empty($reshook))
  82. {
  83. if ($cancelbutton)
  84. {
  85. $action="";
  86. }
  87. // set accountancy code
  88. if ($action == 'setcustomeraccountancycode')
  89. {
  90. $result=$object->fetch($id);
  91. $object->code_compta=$_POST["customeraccountancycode"];
  92. $result=$object->update($object->id,$user,1,1,0);
  93. if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
  94. }
  95. // conditions de reglement
  96. if ($action == 'setconditions' && $user->rights->societe->creer)
  97. {
  98. $object->fetch($id);
  99. $result=$object->setPaymentTerms(GETPOST('cond_reglement_id','int'));
  100. if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
  101. }
  102. // mode de reglement
  103. if ($action == 'setmode' && $user->rights->societe->creer)
  104. {
  105. $object->fetch($id);
  106. $result=$object->setPaymentMethods(GETPOST('mode_reglement_id','int'));
  107. if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
  108. }
  109. // Bank account
  110. if ($action == 'setbankaccount' && $user->rights->societe->creer)
  111. {
  112. $object->fetch($id);
  113. $result=$object->setBankAccount(GETPOST('fk_account','int'));
  114. if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
  115. }
  116. // customer preferred shipping method
  117. if ($action == 'setshippingmethod' && $user->rights->societe->creer)
  118. {
  119. $object->fetch($id);
  120. $result = $object->setShippingMethod(GETPOST('shipping_method_id','int'));
  121. if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
  122. }
  123. // assujetissement a la TVA
  124. if ($action == 'setassujtva' && $user->rights->societe->creer)
  125. {
  126. $object->fetch($id);
  127. $object->tva_assuj=$_POST['assujtva_value'];
  128. $result=$object->update($object->id);
  129. if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
  130. }
  131. // set prospect level
  132. if ($action == 'setprospectlevel' && $user->rights->societe->creer)
  133. {
  134. $object->fetch($id);
  135. $object->fk_prospectlevel=GETPOST('prospect_level_id','alpha');
  136. $result=$object->update($object->id, $user);
  137. if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
  138. }
  139. // set communication status
  140. if ($action == 'setstcomm')
  141. {
  142. $object->fetch($id);
  143. $object->stcomm_id=dol_getIdFromCode($db, GETPOST('stcomm','alpha'), 'c_stcomm');
  144. $result=$object->update($object->id, $user);
  145. if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
  146. }
  147. // update outstandng limit
  148. if ($action == 'setoutstanding_limit')
  149. {
  150. $object->fetch($id);
  151. $object->outstanding_limit=GETPOST('outstanding_limit');
  152. $result=$object->update($object->id, $user);
  153. if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
  154. }
  155. }
  156. /*
  157. * View
  158. */
  159. $contactstatic = new Contact($db);
  160. $userstatic=new User($db);
  161. $form = new Form($db);
  162. $formcompany=new FormCompany($db);
  163. if ($id > 0 && empty($object->id))
  164. {
  165. // Load data of third party
  166. $res=$object->fetch($id);
  167. if ($object->id <= 0) dol_print_error($db,$object->error);
  168. }
  169. $title=$langs->trans("CustomerCard");
  170. if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name;
  171. $help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
  172. llxHeader('',$title,$help_url);
  173. if ($id > 0)
  174. {
  175. $head = societe_prepare_head($object);
  176. dol_fiche_head($head, 'customer', $langs->trans("ThirdParty"),0,'company');
  177. $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php">'.$langs->trans("BackToList").'</a>';
  178. dol_banner_tab($object, 'socid', $linkback, ($user->societe_id?0:1), 'rowid', 'nom');
  179. print '<div class="fichecenter"><div class="fichehalfleft">';
  180. print '<div class="underbanner clearboth"></div>';
  181. print '<table class="border" width="100%">';
  182. // Prospect/Customer
  183. print '<tr><td class="titlefield">'.$langs->trans('ProspectCustomer').'</td><td>';
  184. print $object->getLibCustProspStatut();
  185. print '</td></tr>';
  186. // Prefix
  187. if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field
  188. {
  189. print '<tr><td>'.$langs->trans("Prefix").'</td><td>';
  190. print ($object->prefix_comm?$object->prefix_comm:'&nbsp;');
  191. print '</td></tr>';
  192. }
  193. if ($object->client)
  194. {
  195. $langs->load("compta");
  196. print '<tr><td>';
  197. print $langs->trans('CustomerCode').'</td><td>';
  198. print $object->code_client;
  199. if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
  200. print '</td></tr>';
  201. print '<tr>';
  202. print '<td>';
  203. print $form->editfieldkey("CustomerAccountancyCode",'customeraccountancycode',$object->code_compta,$object,$user->rights->societe->creer);
  204. print '</td><td>';
  205. print $form->editfieldval("CustomerAccountancyCode",'customeraccountancycode',$object->code_compta,$object,$user->rights->societe->creer);
  206. print '</td>';
  207. print '</tr>';
  208. }
  209. // Assujeti a TVA ou pas
  210. print '<tr>';
  211. print '<td class="nowrap">'.$langs->trans('VATIsUsed').'</td><td>';
  212. print yn($object->tva_assuj);
  213. print '</td>';
  214. print '</tr>';
  215. // Local Taxes
  216. if ($mysoc->useLocalTax(1))
  217. {
  218. print '<tr><td class="nowrap">'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).'</td><td>';
  219. print yn($object->localtax1_assuj);
  220. print '</td></tr>';
  221. }
  222. if ($mysoc->useLocalTax(2))
  223. {
  224. print '<tr><td class="nowrap">'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).'</td><td>';
  225. print yn($object->localtax2_assuj);
  226. print '</td></tr>';
  227. }
  228. // TVA Intra
  229. print '<tr><td class="nowrap">'.$langs->trans('VATIntra').'</td><td>';
  230. print $object->tva_intra;
  231. print '</td></tr>';
  232. // Conditions de reglement par defaut
  233. $langs->load('bills');
  234. print '<tr><td>';
  235. print '<table width="100%" class="nobordernopadding"><tr><td>';
  236. print $langs->trans('PaymentConditions');
  237. print '<td>';
  238. 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>';
  239. print '</tr></table>';
  240. print '</td><td>';
  241. if ($action == 'editconditions')
  242. {
  243. $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->cond_reglement_id, 'cond_reglement_id',1);
  244. }
  245. else
  246. {
  247. $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->cond_reglement_id, 'none');
  248. }
  249. print "</td>";
  250. print '</tr>';
  251. // Mode de reglement par defaut
  252. print '<tr><td class="nowrap">';
  253. print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
  254. print $langs->trans('PaymentMode');
  255. print '<td>';
  256. 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>';
  257. print '</tr></table>';
  258. print '</td><td>';
  259. if ($action == 'editmode')
  260. {
  261. $form->form_modes_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->mode_reglement_id,'mode_reglement_id');
  262. }
  263. else
  264. {
  265. $form->form_modes_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->mode_reglement_id,'none');
  266. }
  267. print "</td>";
  268. print '</tr>';
  269. // Compte bancaire par défaut
  270. print '<tr><td class="nowrap">';
  271. print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
  272. print $langs->trans('PaymentBankAccount');
  273. print '<td>';
  274. if (($action != 'editbankaccount') && $user->rights->societe->creer) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editbankaccount&amp;socid='.$object->id.'">'.img_edit($langs->trans('SetBankAccount'),1).'</a></td>';
  275. print '</tr></table>';
  276. print '</td><td>';
  277. if ($action == 'editbankaccount')
  278. {
  279. $form->formSelectAccount($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->fk_account,'fk_account',1);
  280. }
  281. else
  282. {
  283. $form->formSelectAccount($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->fk_account,'none');
  284. }
  285. print "</td>";
  286. print '</tr>';
  287. // Relative discounts (Discounts-Drawbacks-Rebates)
  288. print '<tr><td class="nowrap">';
  289. print '<table width="100%" class="nobordernopadding"><tr><td class="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>'.($object->remise_percent?'<a href="'.DOL_URL_ROOT.'/comm/remise.php?id='.$object->id.'">'.$object->remise_percent.'%</a>':'').'</td>';
  298. print '</tr>';
  299. // Absolute discounts (Discounts-Drawbacks-Rebates)
  300. print '<tr><td class="nowrap">';
  301. print '<table width="100%" class="nobordernopadding">';
  302. print '<tr><td class="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>';
  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,1,$langs,1,-1,-1,$conf->currency).'</a>';
  315. //else print $langs->trans("DiscountNone");
  316. print '</td>';
  317. print '</tr>';
  318. // Max outstanding bill
  319. if ($object->client)
  320. {
  321. print '<tr class="nowrap">';
  322. print '<td>';
  323. print $form->editfieldkey("OutstandingBill",'outstanding_limit',$object->outstanding_limit,$object,$user->rights->societe->creer);
  324. print '</td><td>';
  325. $limit_field_type = (! empty($conf->global->MAIN_USE_JQUERY_JEDITABLE)) ? 'numeric' : 'amount';
  326. print $form->editfieldval("OutstandingBill",'outstanding_limit',$object->outstanding_limit,$object,$user->rights->societe->creer,$limit_field_type,($object->outstanding_limit != '' ? price($object->outstanding_limit) : ''));
  327. //if (empty($object->outstanding_limit)) print $langs->trans("NoLimit");
  328. print '</td>';
  329. print '</tr>';
  330. }
  331. // Multiprice level
  332. if (! empty($conf->global->PRODUIT_MULTIPRICES))
  333. {
  334. print '<tr><td class="nowrap">';
  335. print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
  336. print $langs->trans("PriceLevel");
  337. print '<td><td align="right">';
  338. if ($user->rights->societe->creer)
  339. {
  340. print '<a href="'.DOL_URL_ROOT.'/comm/multiprix.php?id='.$object->id.'">'.img_edit($langs->trans("Modify")).'</a>';
  341. }
  342. print '</td></tr></table>';
  343. print '</td><td>';
  344. print $object->price_level;
  345. $keyforlabel='PRODUIT_MULTIPRICES_LABEL'.$object->price_level;
  346. if (! empty($conf->global->$keyforlabel)) print ' - '.$langs->trans($conf->global->$keyforlabel);
  347. print "</td>";
  348. print '</tr>';
  349. }
  350. // Preferred shipping Method
  351. if (! empty($conf->global->SOCIETE_ASK_FOR_SHIPPING_METHOD)) {
  352. print '<tr><td class="nowrap">';
  353. print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
  354. print $langs->trans('SendingMethod');
  355. print '<td>';
  356. if (($action != 'editshipping') && $user->rights->societe->creer) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editshipping&amp;socid='.$object->id.'">'.img_edit($langs->trans('SetMode'),1).'</a></td>';
  357. print '</tr></table>';
  358. print '</td><td>';
  359. if ($action == 'editshipping')
  360. {
  361. $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->shipping_method_id,'shipping_method_id');
  362. }
  363. else
  364. {
  365. $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->shipping_method_id,'none');
  366. }
  367. print "</td>";
  368. print '</tr>';
  369. }
  370. // Categories
  371. if (!empty($conf->categorie->enabled) && !empty($user->rights->categorie->lire)) {
  372. $langs->load("categories");
  373. print '<tr><td>' . $langs->trans("CustomersCategoriesShort") . '</td>';
  374. print '<td>';
  375. print $form->showCategories( $object->id, 'customer', 1 );
  376. print "</td></tr>";
  377. }
  378. // Other attributes
  379. $parameters=array('socid'=>$object->id, 'colspan' => ' colspan="3"', 'colspanvalue' => '3');
  380. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  381. print $hookmanager->resPrint;
  382. if (empty($reshook) && ! empty($extrafields->attribute_label))
  383. {
  384. print $object->showOptionals($extrafields);
  385. }
  386. // Sales representative
  387. include DOL_DOCUMENT_ROOT.'/societe/tpl/linesalesrepresentative.tpl.php';
  388. // Module Adherent
  389. if (! empty($conf->adherent->enabled))
  390. {
  391. $langs->load("members");
  392. $langs->load("users");
  393. print '<tr><td class="titlefield">'.$langs->trans("LinkedToDolibarrMember").'</td>';
  394. print '<td>';
  395. $adh=new Adherent($db);
  396. $result=$adh->fetch('','',$object->id);
  397. if ($result > 0)
  398. {
  399. $adh->ref=$adh->getFullName($langs);
  400. print $adh->getNomUrl(1);
  401. }
  402. else
  403. {
  404. print '<span class="opacitymedium">'.$langs->trans("ThirdpartyNotLinkedToMember").'</span>';
  405. }
  406. print '</td>';
  407. print "</tr>\n";
  408. }
  409. print "</table>";
  410. if ($object->client == 2 || $object->client == 3)
  411. {
  412. print '<br>';
  413. print '<div class="underbanner clearboth"></div>';
  414. print '<table class="border" width="100%">';
  415. // Level of prospect
  416. print '<tr><td class="titlefield nowrap">';
  417. print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
  418. print $langs->trans('ProspectLevel');
  419. print '<td>';
  420. if ($action != 'editlevel' && $user->rights->societe->creer) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editlevel&amp;socid='.$object->id.'">'.img_edit($langs->trans('Modify'),1).'</a></td>';
  421. print '</tr></table>';
  422. print '</td><td>';
  423. if ($action == 'editlevel')
  424. {
  425. $formcompany->form_prospect_level($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->fk_prospectlevel,'prospect_level_id',1);
  426. }
  427. else
  428. {
  429. print $object->getLibProspLevel();
  430. }
  431. print "</td>";
  432. print '</tr>';
  433. // Status
  434. $object->loadCacheOfProspStatus();
  435. print '<tr><td>'.$langs->trans("StatusProsp").'</td><td>'.$object->getLibProspCommStatut(4, $object->cacheprospectstatus[$object->stcomm_id]['label']);
  436. print ' &nbsp; &nbsp; ';
  437. print '<div class="floatright">';
  438. foreach($object->cacheprospectstatus as $key => $val)
  439. {
  440. $titlealt='default';
  441. if (! empty($val['code']) && ! in_array($val['code'], array('ST_NO', 'ST_NEVER', 'ST_TODO', 'ST_PEND', 'ST_DONE'))) $titlealt=$val['label'];
  442. if ($object->stcomm_id != $val['id']) print '<a class="pictosubstatus" href="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'&stcomm='.$val['code'].'&action=setstcomm">'.img_action($titlealt,$val['code']).'</a>';
  443. }
  444. print '</div></td></tr>';
  445. print "</table>";
  446. }
  447. print '</div><div class="fichehalfright"><div class="ficheaddleft">';
  448. $boxstat = '';
  449. // Nbre max d'elements des petites listes
  450. $MAXLIST=$conf->global->MAIN_SIZE_SHORTLIST_LIMIT;
  451. // Lien recap
  452. $boxstat.='<div class="box">';
  453. $boxstat.='<table summary="'.dol_escape_htmltag($langs->trans("DolibarrStateBoard")).'" class="noborder boxtable boxtablenobottom" width="100%">';
  454. $boxstat.='<tr class="impair"><td colspan="2" class="tdboxstats nohover">';
  455. if ($conf->propal->enabled)
  456. {
  457. // Box proposals
  458. $tmp = $object->getOutstandingProposals();
  459. $outstandingOpened=$tmp['opened'];
  460. $outstandingTotal=$tmp['total_ht'];
  461. $outstandingTotalIncTax=$tmp['total_ttc'];
  462. $text=$langs->trans("OverAllProposals");
  463. $link='';
  464. $icon='bill';
  465. if ($link) $boxstat.='<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
  466. $boxstat.='<div class="boxstats">';
  467. $boxstat.='<span class="boxstatstext">'.img_object("",$icon).' '.$text.'</span><br>';
  468. $boxstat.='<span class="boxstatsindicator">'.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
  469. $boxstat.='</div>';
  470. if ($link) $boxstat.='</a>';
  471. }
  472. if ($conf->commande->enabled)
  473. {
  474. // Box proposals
  475. $tmp = $object->getOutstandingOrders();
  476. $outstandingOpened=$tmp['opened'];
  477. $outstandingTotal=$tmp['total_ht'];
  478. $outstandingTotalIncTax=$tmp['total_ttc'];
  479. $text=$langs->trans("OverAllOrders");
  480. $link='';
  481. $icon='bill';
  482. if ($link) $boxstat.='<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
  483. $boxstat.='<div class="boxstats">';
  484. $boxstat.='<span class="boxstatstext">'.img_object("",$icon).' '.$text.'</span><br>';
  485. $boxstat.='<span class="boxstatsindicator">'.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
  486. $boxstat.='</div>';
  487. if ($link) $boxstat.='</a>';
  488. }
  489. if ($conf->facture->enabled)
  490. {
  491. $tmp = $object->getOutstandingBills();
  492. $outstandingOpened=$tmp['opened'];
  493. $outstandingTotal=$tmp['total_ht'];
  494. $outstandingTotalIncTax=$tmp['total_ttc'];
  495. $text=$langs->trans("OverAllInvoices");
  496. $link='';
  497. $icon='bill';
  498. if ($link) $boxstat.='<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
  499. $boxstat.='<div class="boxstats">';
  500. $boxstat.='<span class="boxstatstext">'.img_object("",$icon).' '.$text.'</span><br>';
  501. $boxstat.='<span class="boxstatsindicator">'.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
  502. $boxstat.='</div>';
  503. if ($link) $boxstat.='</a>';
  504. // Box outstanding bill
  505. $warn = '';
  506. if ($object->outstanding_limit != '' && $object->outstanding_limit < $outstandingOpened)
  507. {
  508. $warn = ' '.img_warning($langs->trans("OutstandingBillReached"));
  509. }
  510. $text=$langs->trans("CurrentOutstandingBill");
  511. $link=DOL_URL_ROOT.'/compta/recap-compta.php?socid='.$object->id;
  512. $icon='bill';
  513. if ($link) $boxstat.='<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
  514. $boxstat.='<div class="boxstats">';
  515. $boxstat.='<span class="boxstatstext">'.img_object("",$icon).' '.$text.'</span><br>';
  516. $boxstat.='<span class="boxstatsindicator'.($outstandingOpened>0?' amountremaintopay':'').'">'.price($outstandingOpened, 1, $langs, 1, -1, -1, $conf->currency).$warn.'</span>';
  517. $boxstat.='</div>';
  518. if ($link) $boxstat.='</a>';
  519. }
  520. $boxstat.='</td></tr>';
  521. $boxstat.='</table>';
  522. $boxstat.='</div>';
  523. print $boxstat;
  524. $now=dol_now();
  525. /*
  526. * Last proposals
  527. */
  528. if (! empty($conf->propal->enabled) && $user->rights->propal->lire)
  529. {
  530. $propal_static = new Propal($db);
  531. $sql = "SELECT s.nom, s.rowid, p.rowid as propalid, p.fk_statut, p.total_ht";
  532. $sql.= ", p.tva as total_tva";
  533. $sql.= ", p.total as total_ttc";
  534. $sql.= ", p.ref, p.ref_client, p.remise";
  535. $sql.= ", p.datep as dp, p.fin_validite as datelimite";
  536. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as p, ".MAIN_DB_PREFIX."c_propalst as c";
  537. $sql.= " WHERE p.fk_soc = s.rowid AND p.fk_statut = c.id";
  538. $sql.= " AND s.rowid = ".$object->id;
  539. $sql.= " AND p.entity = ".$conf->entity;
  540. $sql.= " ORDER BY p.datep DESC";
  541. $resql=$db->query($sql);
  542. if ($resql)
  543. {
  544. $var=true;
  545. $num = $db->num_rows($resql);
  546. if ($num > 0)
  547. {
  548. print '<table class="noborder" width="100%">';
  549. print '<tr class="liste_titre">';
  550. print '<td colspan="4"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("LastPropals",($num<=$MAXLIST?"":$MAXLIST)).'</td><td align="right"><a class="notasortlink" href="'.DOL_URL_ROOT.'/comm/propal/list.php?socid='.$object->id.'">'.$langs->trans("AllPropals").' <span class="badge">'.$num.'</span></a></td>';
  551. 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>';
  552. print '</tr></table></td>';
  553. print '</tr>';
  554. }
  555. $i = 0;
  556. while ($i < $num && $i < $MAXLIST)
  557. {
  558. $objp = $db->fetch_object($resql);
  559. print '<tr class="oddeven">';
  560. print '<td class="nowrap">';
  561. $propal_static->id = $objp->propalid;
  562. $propal_static->ref = $objp->ref;
  563. $propal_static->ref_client = $objp->ref_client;
  564. $propal_static->total_ht = $objp->total_ht;
  565. $propal_static->total_tva = $objp->total_tva;
  566. $propal_static->total_ttc = $objp->total_ttc;
  567. print $propal_static->getNomUrl(1);
  568. if ( ($db->jdate($objp->datelimite) < ($now - $conf->propal->cloture->warning_delay)) && $objp->fk_statut == 1 ) {
  569. print " ".img_warning();
  570. }
  571. print '</td><td align="right" width="80px">'.dol_print_date($db->jdate($objp->dp),'day')."</td>\n";
  572. print '<td align="right" style="min-width: 60px">'.price($objp->total_ht).'</td>';
  573. print '<td align="right" style="min-width: 60px" class="nowrap">'.$propal_static->LibStatut($objp->fk_statut,5).'</td></tr>';
  574. $i++;
  575. }
  576. $db->free($resql);
  577. if ($num > 0) print "</table>";
  578. }
  579. else
  580. {
  581. dol_print_error($db);
  582. }
  583. }
  584. /*
  585. * Last orders
  586. */
  587. if (! empty($conf->commande->enabled) && $user->rights->commande->lire)
  588. {
  589. $commande_static=new Commande($db);
  590. $sql = "SELECT s.nom, s.rowid";
  591. $sql.= ", c.rowid as cid, c.total_ht";
  592. $sql.= ", c.tva as total_tva";
  593. $sql.= ", c.total_ttc";
  594. $sql.= ", c.ref, c.ref_client, c.fk_statut, c.facture";
  595. $sql.= ", c.date_commande as dc";
  596. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande as c";
  597. $sql.= " WHERE c.fk_soc = s.rowid ";
  598. $sql.= " AND s.rowid = ".$object->id;
  599. $sql.= " AND c.entity = ".$conf->entity;
  600. $sql.= " ORDER BY c.date_commande DESC";
  601. $resql=$db->query($sql);
  602. if ($resql)
  603. {
  604. $var=true;
  605. $num = $db->num_rows($resql);
  606. if ($num > 0)
  607. {
  608. // Check if there are orders billable
  609. $sql2 = 'SELECT s.nom, s.rowid as socid, s.client, c.rowid, c.ref, c.total_ht, c.ref_client,';
  610. $sql2.= ' c.date_valid, c.date_commande, c.date_livraison, c.fk_statut, c.facture as facturee';
  611. $sql2.= ' FROM '.MAIN_DB_PREFIX.'societe as s';
  612. $sql2.= ', '.MAIN_DB_PREFIX.'commande as c';
  613. $sql2.= ' WHERE c.fk_soc = s.rowid';
  614. $sql2.= ' AND s.rowid = '.$object->id;
  615. // Show orders with status validated, shipping started and delivered (well any order we can bill)
  616. $sql2.= " AND ((c.fk_statut IN (1,2)) OR (c.fk_statut = 3 AND c.facture = 0))";
  617. $resql2=$db->query($sql2);
  618. $orders2invoice = $db->num_rows($resql2);
  619. $db->free($resql2);
  620. print '<table class="noborder" width="100%">';
  621. print '<tr class="liste_titre">';
  622. print '<td colspan="4"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("LastCustomerOrders",($num<=$MAXLIST?"":$MAXLIST)).'</td><td align="right"><a class="notasortlink" href="'.DOL_URL_ROOT.'/commande/list.php?socid='.$object->id.'">'.$langs->trans("AllOrders").' <span class="badge">'.$num.'</span></a></td>';
  623. 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>';
  624. //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>';
  625. //else print '<td width="20px" align="right"><a href="#">'.img_picto($langs->trans("NoOrdersToInvoice"),'object_bill').'</a></td>';
  626. print '</tr></table></td>';
  627. print '</tr>';
  628. }
  629. $i = 0;
  630. while ($i < $num && $i < $MAXLIST)
  631. {
  632. $objp = $db->fetch_object($resql);
  633. print '<tr class="oddeven">';
  634. print '<td class="nowrap">';
  635. $commande_static->id = $objp->cid;
  636. $commande_static->ref = $objp->ref;
  637. $commande_static->ref_client=$objp->ref_client;
  638. $commande_static->total_ht = $objp->total_ht;
  639. $commande_static->total_tva = $objp->total_tva;
  640. $commande_static->total_ttc = $objp->total_ttc;
  641. print $commande_static->getNomUrl(1);
  642. print '</td><td align="right" width="80px">'.dol_print_date($db->jdate($objp->dc),'day')."</td>\n";
  643. print '<td align="right" style="min-width: 60px">'.price($objp->total_ht).'</td>';
  644. print '<td align="right" style="min-width: 60px" class="nowrap">'.$commande_static->LibStatut($objp->fk_statut,$objp->facture,5).'</td></tr>';
  645. $i++;
  646. }
  647. $db->free($resql);
  648. if ($num >0) print "</table>";
  649. }
  650. else
  651. {
  652. dol_print_error($db);
  653. }
  654. }
  655. /*
  656. * Last sendings
  657. */
  658. if (! empty($conf->expedition->enabled) && $user->rights->expedition->lire) {
  659. $sendingstatic = new Expedition($db);
  660. $sql = 'SELECT e.rowid as id';
  661. $sql.= ', e.ref';
  662. $sql.= ', e.date_creation';
  663. $sql.= ', e.fk_statut as statut';
  664. $sql.= ', s.nom';
  665. $sql.= ', s.rowid as socid';
  666. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."expedition as e";
  667. $sql.= " WHERE e.fk_soc = s.rowid AND s.rowid = ".$object->id;
  668. $sql.= " AND e.entity IN (".getEntity('expedition', 1).")";
  669. $sql.= ' GROUP BY e.rowid';
  670. $sql.= ', e.ref';
  671. $sql.= ', e.date_creation';
  672. $sql.= ', e.fk_statut';
  673. $sql.= ', s.nom';
  674. $sql.= ', s.rowid';
  675. $sql.= " ORDER BY e.date_creation DESC";
  676. $resql = $db->query($sql);
  677. if ($resql) {
  678. $var = true;
  679. $num = $db->num_rows($resql);
  680. $i = 0;
  681. if ($num > 0) {
  682. print '<table class="noborder" width="100%">';
  683. print '<tr class="liste_titre">';
  684. print '<td colspan="4"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("LastSendings",($num<=$MAXLIST?"":$MAXLIST)).'</td><td align="right"><a class="notasortlink" href="'.DOL_URL_ROOT.'/expedition/list.php?socid='.$object->id.'">'.$langs->trans("AllSendings").' <span class="badge">'.$num.'</span></a></td>';
  685. print '<td width="20px" align="right"><a href="'.DOL_URL_ROOT.'/expedition/stats/index.php?socid='.$object->id.'">'.img_picto($langs->trans("Statistics"),'stats').'</a></td>';
  686. print '</tr></table></td>';
  687. print '</tr>';
  688. }
  689. while ($i < $num && $i < $MAXLIST) {
  690. $objp = $db->fetch_object($resql);
  691. $var = ! $var;
  692. print "<tr " . $bc[$var] . ">";
  693. print '<td class="nowrap">';
  694. $sendingstatic->id = $objp->id;
  695. $sendingstatic->ref = $objp->ref;
  696. print $sendingstatic->getNomUrl(1);
  697. print '</td>';
  698. if ($objp->date_creation > 0) {
  699. print '<td align="right" width="80px">'.dol_print_date($db->jdate($objp->date_creation),'day').'</td>';
  700. } else {
  701. print '<td align="right"><b>!!!</b></td>';
  702. }
  703. print '<td align="right" class="nowrap" width="100" >' . $sendingstatic->LibStatut($objp->statut, 5) . '</td>';
  704. print "</tr>\n";
  705. $i++;
  706. }
  707. $db->free($resql);
  708. if ($num > 0)
  709. print "</table>";
  710. } else {
  711. dol_print_error($db);
  712. }
  713. }
  714. /*
  715. * Last linked contracts
  716. */
  717. if (! empty($conf->contrat->enabled) && $user->rights->contrat->lire)
  718. {
  719. $contratstatic=new Contrat($db);
  720. $sql = "SELECT s.nom, s.rowid, c.rowid as id, c.ref as ref, c.statut, c.datec as dc, c.date_contrat as dcon, c.ref_supplier as refsup";
  721. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."contrat as c";
  722. $sql.= " WHERE c.fk_soc = s.rowid ";
  723. $sql.= " AND s.rowid = ".$object->id;
  724. $sql.= " AND c.entity = ".$conf->entity;
  725. $sql.= " ORDER BY c.datec DESC";
  726. $resql=$db->query($sql);
  727. if ($resql)
  728. {
  729. $var=true;
  730. $num = $db->num_rows($resql);
  731. if ($num >0 )
  732. {
  733. print '<table class="noborder" width="100%">';
  734. print '<tr class="liste_titre">';
  735. print '<td colspan="6"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("LastContracts",($num<=$MAXLIST?"":$MAXLIST)).'</td>';
  736. print '<td align="right"><a class="notasortlink" href="'.DOL_URL_ROOT.'/contrat/list.php?socid='.$object->id.'">'.$langs->trans("AllContracts").' <span class="badge">'.$num.'</span></a></td>';
  737. //print '<td width="20px" align="right"><a href="'.DOL_URL_ROOT.'/contract/stats/index.php?socid='.$object->id.'">'.img_picto($langs->trans("Statistics"),'stats').'</a></td>';
  738. print '</tr></table></td>';
  739. print '</tr>';
  740. }
  741. $i = 0;
  742. while ($i < $num && $i < $MAXLIST)
  743. {
  744. $contrat=new Contrat($db);
  745. $objp = $db->fetch_object($resql);
  746. print '<tr class="oddeven">';
  747. print '<td class="nowrap">';
  748. $contrat->id=$objp->id;
  749. $contrat->ref=$objp->ref?$objp->ref:$objp->id;
  750. print $contrat->getNomUrl(1,12);
  751. print "</td>\n";
  752. print '<td class="nowrap">'.dol_trunc($objp->refsup,12)."</td>\n";
  753. print '<td align="right" width="80px">'.dol_print_date($db->jdate($objp->dc),'day')."</td>\n";
  754. print '<td align="right" width="80px">'.dol_print_date($db->jdate($objp->dcon),'day')."</td>\n";
  755. print '<td width="20">&nbsp;</td>';
  756. print '<td align="right" class="nowrap">';
  757. $contrat->fetch_lines();
  758. print $contrat->getLibStatut(4);
  759. print "</td>\n";
  760. print '</tr>';
  761. $i++;
  762. }
  763. $db->free($resql);
  764. if ($num > 0) print "</table>";
  765. }
  766. else
  767. {
  768. dol_print_error($db);
  769. }
  770. }
  771. /*
  772. * Last interventions
  773. */
  774. if (! empty($conf->ficheinter->enabled) && $user->rights->ficheinter->lire)
  775. {
  776. $sql = "SELECT s.nom, s.rowid, f.rowid as id, f.ref, f.fk_statut, f.duree as duration, f.datei as startdate";
  777. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."fichinter as f";
  778. $sql.= " WHERE f.fk_soc = s.rowid";
  779. $sql.= " AND s.rowid = ".$object->id;
  780. $sql.= " AND f.entity = ".$conf->entity;
  781. $sql.= " ORDER BY f.tms DESC";
  782. $fichinter_static=new Fichinter($db);
  783. $resql=$db->query($sql);
  784. if ($resql)
  785. {
  786. $var=true;
  787. $num = $db->num_rows($resql);
  788. if ($num > 0)
  789. {
  790. print '<table class="noborder" width="100%">';
  791. print '<tr class="liste_titre">';
  792. print '<td colspan="3"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("LastInterventions",($num<=$MAXLIST?"":$MAXLIST)).'</td><td align="right"><a class="notasortlink" href="'.DOL_URL_ROOT.'/fichinter/list.php?socid='.$object->id.'">'.$langs->trans("AllInterventions").' <span class="badge">'.$num.'</span></td>';
  793. print '<td width="20px" align="right"><a href="'.DOL_URL_ROOT.'/fichinter/stats/index.php?socid='.$object->id.'">'.img_picto($langs->trans("Statistics"),'stats').'</a></td>';
  794. print '</tr></table></td>';
  795. print '</tr>';
  796. }
  797. $i = 0;
  798. while ($i < $num && $i < $MAXLIST)
  799. {
  800. $objp = $db->fetch_object($resql);
  801. $fichinter_static->id=$objp->id;
  802. $fichinter_static->statut=$objp->fk_statut;
  803. print '<tr class="oddeven">';
  804. print '<td class="nowrap"><a href="'.DOL_URL_ROOT.'/fichinter/card.php?id='.$objp->id.'">'.img_object($langs->trans("ShowPropal"),"propal").' '.$objp->ref.'</a></td>'."\n";
  805. //print '<td align="right" width="80px">'.dol_print_date($db->jdate($objp->startdate)).'</td>'."\n";
  806. print '<td align="right" style="min-width: 60px">'.convertSecondToTime($objp->duration).'</td>'."\n";
  807. print '<td align="right" class="nowrap" style="min-width: 60px">'.$fichinter_static->getLibStatut(5).'</td>'."\n";
  808. print '</tr>';
  809. $i++;
  810. }
  811. $db->free($resql);
  812. if ($num > 0) print "</table>";
  813. }
  814. else
  815. {
  816. dol_print_error($db);
  817. }
  818. }
  819. /*
  820. * Last invoices
  821. */
  822. if (! empty($conf->facture->enabled) && $user->rights->facture->lire)
  823. {
  824. $facturestatic = new Facture($db);
  825. $sql = 'SELECT f.rowid as facid, f.facnumber, f.type, f.amount';
  826. $sql.= ', f.total as total_ht';
  827. $sql.= ', f.tva as total_tva';
  828. $sql.= ', f.total_ttc';
  829. $sql.= ', f.datef as df, f.datec as dc, f.paye as paye, f.fk_statut as statut';
  830. $sql.= ', s.nom, s.rowid as socid';
  831. $sql.= ', SUM(pf.amount) as am';
  832. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f";
  833. $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON f.rowid=pf.fk_facture';
  834. $sql.= " WHERE f.fk_soc = s.rowid AND s.rowid = ".$object->id;
  835. $sql.= " AND f.entity = ".$conf->entity;
  836. $sql.= ' GROUP BY f.rowid, f.facnumber, f.type, f.amount, f.total, f.tva, f.total_ttc,';
  837. $sql.= ' f.datef, f.datec, f.paye, f.fk_statut,';
  838. $sql.= ' s.nom, s.rowid';
  839. $sql.= " ORDER BY f.datef DESC, f.datec DESC";
  840. $resql=$db->query($sql);
  841. if ($resql)
  842. {
  843. $var=true;
  844. $num = $db->num_rows($resql);
  845. $i = 0;
  846. if ($num > 0)
  847. {
  848. print '<table class="noborder" width="100%">';
  849. print '<tr class="liste_titre">';
  850. print '<td colspan="5"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("LastCustomersBills",($num<=$MAXLIST?"":$MAXLIST)).'</td><td align="right"><a class="notasortlink" href="'.DOL_URL_ROOT.'/compta/facture/list.php?socid='.$object->id.'">'.$langs->trans("AllBills").' <span class="badge">'.$num.'</span></a></td>';
  851. 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>';
  852. print '</tr></table></td>';
  853. print '</tr>';
  854. }
  855. while ($i < $num && $i < $MAXLIST)
  856. {
  857. $objp = $db->fetch_object($resql);
  858. print '<tr class="oddeven">';
  859. print '<td class="nowrap">';
  860. $facturestatic->id = $objp->facid;
  861. $facturestatic->ref = $objp->facnumber;
  862. $facturestatic->type = $objp->type;
  863. $facturestatic->total_ht = $objp->total_ht;
  864. $facturestatic->total_tva = $objp->total_tva;
  865. $facturestatic->total_ttc = $objp->total_ttc;
  866. print $facturestatic->getNomUrl(1);
  867. print '</td>';
  868. if ($objp->df > 0)
  869. {
  870. print '<td align="right" width="80px">'.dol_print_date($db->jdate($objp->df),'day').'</td>';
  871. }
  872. else
  873. {
  874. print '<td align="right"><b>!!!</b></td>';
  875. }
  876. print '<td align="right" style="min-width: 60px">';
  877. print price($objp->total_ht);
  878. print '</td>';
  879. if (! empty($conf->global->MAIN_SHOW_PRICE_WITH_TAX_IN_SUMMARIES))
  880. {
  881. print '<td align="right" style="min-width: 60px">';
  882. print price($objp->total_ttc);
  883. print '</td>';
  884. }
  885. print '<td align="right" class="nowrap" style="min-width: 60px">'.($facturestatic->LibStatut($objp->paye,$objp->statut,5,$objp->am)).'</td>';
  886. print "</tr>\n";
  887. $i++;
  888. }
  889. $db->free($resql);
  890. if ($num > 0) print "</table>";
  891. }
  892. else
  893. {
  894. dol_print_error($db);
  895. }
  896. }
  897. print '</div></div></div>';
  898. print '<div style="clear:both"></div>';
  899. dol_fiche_end();
  900. /*
  901. * Barre d'actions
  902. */
  903. print '<div class="tabsAction">';
  904. $parameters = array();
  905. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
  906. if (empty($reshook))
  907. {
  908. if ($object->status != 1)
  909. {
  910. print '<div class="inline-block divButAction"><a class="butActionRefused" title="'.dol_escape_js($langs->trans("ThirdPartyIsClosed")).'" href="#">'.$langs->trans("ThirdPartyIsClosed").'</a></div>';
  911. }
  912. if (! empty($conf->propal->enabled) && $user->rights->propal->creer && $object->status==1)
  913. {
  914. $langs->load("propal");
  915. print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/comm/propal/card.php?socid='.$object->id.'&amp;action=create">'.$langs->trans("AddProp").'</a></div>';
  916. }
  917. if (! empty($conf->commande->enabled) && $user->rights->commande->creer && $object->status==1)
  918. {
  919. $langs->load("orders");
  920. print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/commande/card.php?socid='.$object->id.'&amp;action=create">'.$langs->trans("AddOrder").'</a></div>';
  921. }
  922. if ($user->rights->contrat->creer && $object->status==1)
  923. {
  924. $langs->load("contracts");
  925. print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/contrat/card.php?socid='.$object->id.'&amp;action=create">'.$langs->trans("AddContract").'</a></div>';
  926. }
  927. if (! empty($conf->ficheinter->enabled) && $user->rights->ficheinter->creer && $object->status==1)
  928. {
  929. $langs->load("fichinter");
  930. print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/fichinter/card.php?socid='.$object->id.'&amp;action=create">'.$langs->trans("AddIntervention").'</a></div>';
  931. }
  932. // Add invoice
  933. if ($user->societe_id == 0)
  934. {
  935. if (! empty($conf->deplacement->enabled) && $object->status==1)
  936. {
  937. $langs->load("trips");
  938. print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/deplacement/card.php?socid='.$object->id.'&amp;action=create">'.$langs->trans("AddTrip").'</a></div>';
  939. }
  940. if (! empty($conf->facture->enabled) && $object->status==1)
  941. {
  942. if (empty($user->rights->facture->creer))
  943. {
  944. print '<div class="inline-block divButAction"><a class="butActionRefused" title="'.dol_escape_js($langs->trans("NotAllowed")).'" href="#">'.$langs->trans("AddBill").'</a></div>';
  945. }
  946. else
  947. {
  948. $langs->load("bills");
  949. $langs->load("orders");
  950. if (! empty($conf->commande->enabled))
  951. {
  952. if ($object->client != 0 && $object->client != 2)
  953. {
  954. if (! empty($orders2invoice) && $orders2invoice > 0) print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/commande/orderstoinvoice.php?socid='.$object->id.'">'.$langs->trans("CreateInvoiceForThisCustomer").'</a></div>';
  955. else print '<div class="inline-block divButAction"><a class="butActionRefused" title="'.dol_escape_js($langs->trans("NoOrdersToInvoice")).'" href="#">'.$langs->trans("CreateInvoiceForThisCustomer").'</a></div>';
  956. }
  957. else print '<div class="inline-block divButAction"><a class="butActionRefused" title="'.dol_escape_js($langs->trans("ThirdPartyMustBeEditAsCustomer")).'" href="#">'.$langs->trans("AddBill").'</a></div>';
  958. }
  959. if ($object->client != 0 && $object->client != 2) print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/facture/card.php?action=create&socid='.$object->id.'">'.$langs->trans("AddBill").'</a></div>';
  960. else print '<div class="inline-block divButAction"><a class="butActionRefused" title="'.dol_escape_js($langs->trans("ThirdPartyMustBeEditAsCustomer")).'" href="#">'.$langs->trans("AddBill").'</a></div>';
  961. }
  962. }
  963. }
  964. // Add action
  965. if (! empty($conf->agenda->enabled) && ! empty($conf->global->MAIN_REPEATTASKONEACHTAB) && $object->status==1)
  966. {
  967. if ($user->rights->agenda->myactions->create)
  968. {
  969. print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create&socid='.$object->id.'">'.$langs->trans("AddAction").'</a></div>';
  970. }
  971. else
  972. {
  973. print '<div class="inline-block divButAction"><a class="butAction" title="'.dol_escape_js($langs->trans("NotAllowed")).'" href="#">'.$langs->trans("AddAction").'</a></div>';
  974. }
  975. }
  976. }
  977. print '</div>';
  978. if (! empty($conf->global->MAIN_REPEATCONTACTONEACHTAB))
  979. {
  980. // List of contacts
  981. show_contacts($conf,$langs,$db,$object,$_SERVER["PHP_SELF"].'?socid='.$object->id);
  982. }
  983. // Addresses list
  984. if (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) && ! empty($conf->global->MAIN_REPEATADDRESSONEACHTAB))
  985. {
  986. show_addresses($conf,$langs,$db,$object,$_SERVER["PHP_SELF"].'?socid='.$object->id);
  987. }
  988. if (! empty($conf->global->MAIN_REPEATTASKONEACHTAB))
  989. {
  990. print load_fiche_titre($langs->trans("ActionsOnCompany"),'','');
  991. // List of todo actions
  992. show_actions_todo($conf,$langs,$db,$object);
  993. // List of done actions
  994. show_actions_done($conf,$langs,$db,$object);
  995. }
  996. }
  997. else
  998. {
  999. dol_print_error($db,'Bad value for socid parameter');
  1000. }
  1001. // End of page
  1002. llxFooter();
  1003. $db->close();