card.php 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355
  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-2017 Regis Houssin <regis.houssin@inodbox.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@open-dsi.fr>
  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->facture->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture-rec.class.php';
  39. if (! empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
  40. if (! empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
  41. if (! empty($conf->expedition->enabled)) require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
  42. if (! empty($conf->contrat->enabled)) require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
  43. if (! empty($conf->adherent->enabled)) require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  44. if (! empty($conf->ficheinter->enabled)) require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
  45. // Load translation files required by the page
  46. $langs->loadLangs(array('companies', 'banks'));
  47. if (! empty($conf->contrat->enabled)) $langs->load("contracts");
  48. if (! empty($conf->commande->enabled)) $langs->load("orders");
  49. if (! empty($conf->expedition->enabled)) $langs->load("sendings");
  50. if (! empty($conf->facture->enabled)) $langs->load("bills");
  51. if (! empty($conf->projet->enabled)) $langs->load("projects");
  52. if (! empty($conf->ficheinter->enabled)) $langs->load("interventions");
  53. if (! empty($conf->notification->enabled)) $langs->load("mails");
  54. // Security check
  55. $id = (GETPOST('socid','int') ? GETPOST('socid','int') : GETPOST('id','int'));
  56. if ($user->societe_id > 0) $id=$user->societe_id;
  57. $result = restrictedArea($user,'societe',$id,'&societe');
  58. $action = GETPOST('action','aZ09');
  59. $mode = GETPOST("mode");
  60. $sortfield = GETPOST("sortfield",'alpha');
  61. $sortorder = GETPOST("sortorder",'alpha');
  62. $page = GETPOST("page",'int');
  63. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  64. $offset = $conf->liste_limit * $page;
  65. $pageprev = $page - 1;
  66. $pagenext = $page + 1;
  67. if (! $sortorder) $sortorder="ASC";
  68. if (! $sortfield) $sortfield="nom";
  69. $cancelbutton = GETPOST('cancel','alpha');
  70. $object = new Client($db);
  71. $extrafields = new ExtraFields($db);
  72. // fetch optionals attributes and labels
  73. $extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
  74. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  75. $hookmanager->initHooks(array('thirdpartycomm','globalcard'));
  76. /*
  77. * Actions
  78. */
  79. $parameters = array('id' => $id, 'socid' => $id);
  80. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some
  81. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  82. if (empty($reshook))
  83. {
  84. if ($cancelbutton)
  85. {
  86. $action="";
  87. }
  88. // set accountancy code
  89. if ($action == 'setcustomeraccountancycode')
  90. {
  91. $result=$object->fetch($id);
  92. $object->code_compta=$_POST["customeraccountancycode"];
  93. $result=$object->update($object->id,$user,1,1,0);
  94. if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
  95. }
  96. // conditions de reglement
  97. if ($action == 'setconditions' && $user->rights->societe->creer)
  98. {
  99. $object->fetch($id);
  100. $result=$object->setPaymentTerms(GETPOST('cond_reglement_id','int'));
  101. if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
  102. }
  103. // mode de reglement
  104. if ($action == 'setmode' && $user->rights->societe->creer)
  105. {
  106. $object->fetch($id);
  107. $result=$object->setPaymentMethods(GETPOST('mode_reglement_id','int'));
  108. if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
  109. }
  110. // Bank account
  111. if ($action == 'setbankaccount' && $user->rights->societe->creer)
  112. {
  113. $object->fetch($id);
  114. $result=$object->setBankAccount(GETPOST('fk_account','int'));
  115. if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
  116. }
  117. // customer preferred shipping method
  118. if ($action == 'setshippingmethod' && $user->rights->societe->creer)
  119. {
  120. $object->fetch($id);
  121. $result = $object->setShippingMethod(GETPOST('shipping_method_id','int'));
  122. if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
  123. }
  124. // assujetissement a la TVA
  125. if ($action == 'setassujtva' && $user->rights->societe->creer)
  126. {
  127. $object->fetch($id);
  128. $object->tva_assuj=$_POST['assujtva_value'];
  129. $result=$object->update($object->id);
  130. if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
  131. }
  132. // set prospect level
  133. if ($action == 'setprospectlevel' && $user->rights->societe->creer)
  134. {
  135. $object->fetch($id);
  136. $object->fk_prospectlevel=GETPOST('prospect_level_id','alpha');
  137. $result=$object->update($object->id, $user);
  138. if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
  139. }
  140. // set communication status
  141. if ($action == 'setstcomm')
  142. {
  143. $object->fetch($id);
  144. $object->stcomm_id=dol_getIdFromCode($db, GETPOST('stcomm','alpha'), 'c_stcomm');
  145. $result=$object->update($object->id, $user);
  146. if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
  147. }
  148. // update outstandng limit
  149. if ($action == 'setoutstanding_limit')
  150. {
  151. $object->fetch($id);
  152. $object->outstanding_limit=GETPOST('outstanding_limit');
  153. $result=$object->update($object->id, $user);
  154. if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
  155. }
  156. // update order min amount
  157. if ($action == 'setorder_min_amount')
  158. {
  159. $object->fetch($id);
  160. $object->order_min_amount=price2num(GETPOST('order_min_amount','alpha'));
  161. $result=$object->update($object->id, $user);
  162. if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
  163. }
  164. if ($action == 'update_extras') {
  165. $object->fetch($id);
  166. $object->oldcopy = dol_clone($object);
  167. // Fill array 'array_options' with data from update form
  168. $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
  169. $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute','none'));
  170. if ($ret < 0) $error++;
  171. if (! $error)
  172. {
  173. $result = $object->insertExtraFields('COMPANY_MODIFY');
  174. if ($result < 0)
  175. {
  176. setEventMessages($object->error, $object->errors, 'errors');
  177. $error++;
  178. }
  179. }
  180. if ($error) $action = 'edit_extras';
  181. }
  182. }
  183. /*
  184. * View
  185. */
  186. $contactstatic = new Contact($db);
  187. $userstatic=new User($db);
  188. $form = new Form($db);
  189. $formcompany=new FormCompany($db);
  190. if ($id > 0 && empty($object->id))
  191. {
  192. // Load data of third party
  193. $res=$object->fetch($id);
  194. if ($object->id < 0) dol_print_error($db, $object->error, $object->errors);
  195. }
  196. $title=$langs->trans("CustomerCard");
  197. if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name;
  198. $help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
  199. llxHeader('',$title,$help_url);
  200. if ($object->id > 0)
  201. {
  202. $head = societe_prepare_head($object);
  203. dol_fiche_head($head, 'customer', $langs->trans("ThirdParty"), -1, 'company');
  204. $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php">'.$langs->trans("BackToList").'</a>';
  205. dol_banner_tab($object, 'socid', $linkback, ($user->societe_id?0:1), 'rowid', 'nom');
  206. print '<div class="fichecenter"><div class="fichehalfleft">';
  207. print '<div class="underbanner clearboth"></div>';
  208. print '<table class="border" width="100%">';
  209. // Prospect/Customer
  210. print '<tr><td class="titlefield">'.$langs->trans('ProspectCustomer').'</td><td>';
  211. print $object->getLibCustProspStatut();
  212. print '</td></tr>';
  213. // Prefix
  214. if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field
  215. {
  216. print '<tr><td>'.$langs->trans("Prefix").'</td><td>';
  217. print ($object->prefix_comm?$object->prefix_comm:'&nbsp;');
  218. print '</td></tr>';
  219. }
  220. if ($object->client)
  221. {
  222. $langs->load("compta");
  223. print '<tr><td>';
  224. print $langs->trans('CustomerCode').'</td><td>';
  225. print $object->code_client;
  226. if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
  227. print '</td></tr>';
  228. print '<tr>';
  229. print '<td>';
  230. print $form->editfieldkey("CustomerAccountancyCode",'customeraccountancycode',$object->code_compta,$object,$user->rights->societe->creer);
  231. print '</td><td>';
  232. print $form->editfieldval("CustomerAccountancyCode",'customeraccountancycode',$object->code_compta,$object,$user->rights->societe->creer);
  233. print '</td>';
  234. print '</tr>';
  235. }
  236. // This fields are used to know VAT to include in an invoice when the thirdparty is making a sale, so when it is a supplier.
  237. // We don't need them into customer profile.
  238. // Except for spain and localtax where localtax depends on buyer and not seller
  239. // VAT is used
  240. /*
  241. print '<tr>';
  242. print '<td class="nowrap">';
  243. print $form->textwithpicto($langs->trans('VATIsUsed'),$langs->trans('VATIsUsedWhenSelling'));
  244. print '</td>';
  245. print '<td>';
  246. print yn($object->tva_assuj);
  247. print '</td>';
  248. print '</tr>';
  249. */
  250. if ($mysoc->country_code == 'ES')
  251. {
  252. // Local Taxes
  253. if ($mysoc->localtax1_assuj=="1")
  254. {
  255. print '<tr><td class="nowrap">'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).'</td><td>';
  256. print yn($object->localtax1_assuj);
  257. print '</td></tr>';
  258. }
  259. if ($mysoc->localtax1_assuj=="1")
  260. {
  261. print '<tr><td class="nowrap">'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).'</td><td>';
  262. print yn($object->localtax2_assuj);
  263. print '</td></tr>';
  264. }
  265. }
  266. // TVA Intra
  267. print '<tr><td class="nowrap">'.$langs->trans('VATIntra').'</td><td>';
  268. print $object->tva_intra;
  269. print '</td></tr>';
  270. // Conditions de reglement par defaut
  271. $langs->load('bills');
  272. print '<tr><td>';
  273. print '<table width="100%" class="nobordernopadding"><tr><td>';
  274. print $langs->trans('PaymentConditions');
  275. print '<td>';
  276. if (($action != 'editconditions') && $user->rights->societe->creer) print '<td class="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editconditions&amp;socid='.$object->id.'">'.img_edit($langs->trans('SetConditions'),1).'</a></td>';
  277. print '</tr></table>';
  278. print '</td><td>';
  279. if ($action == 'editconditions')
  280. {
  281. $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->cond_reglement_id, 'cond_reglement_id', 1);
  282. }
  283. else
  284. {
  285. $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->cond_reglement_id, 'none');
  286. }
  287. print "</td>";
  288. print '</tr>';
  289. // Mode de reglement par defaut
  290. print '<tr><td class="nowrap">';
  291. print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
  292. print $langs->trans('PaymentMode');
  293. print '<td>';
  294. if (($action != 'editmode') && $user->rights->societe->creer) print '<td class="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editmode&amp;socid='.$object->id.'">'.img_edit($langs->trans('SetMode'),1).'</a></td>';
  295. print '</tr></table>';
  296. print '</td><td>';
  297. if ($action == 'editmode')
  298. {
  299. $form->form_modes_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->mode_reglement_id, 'mode_reglement_id', 'CRDT', 1, 1);
  300. }
  301. else
  302. {
  303. $form->form_modes_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->mode_reglement_id,'none');
  304. }
  305. print "</td>";
  306. print '</tr>';
  307. if (! empty($conf->banque->enabled))
  308. {
  309. // Compte bancaire par défaut
  310. print '<tr><td class="nowrap">';
  311. print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
  312. print $langs->trans('PaymentBankAccount');
  313. print '<td>';
  314. if (($action != 'editbankaccount') && $user->rights->societe->creer) print '<td class="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editbankaccount&amp;socid='.$object->id.'">'.img_edit($langs->trans('SetBankAccount'),1).'</a></td>';
  315. print '</tr></table>';
  316. print '</td><td>';
  317. if ($action == 'editbankaccount')
  318. {
  319. $form->formSelectAccount($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->fk_account,'fk_account',1);
  320. }
  321. else
  322. {
  323. $form->formSelectAccount($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->fk_account,'none');
  324. }
  325. print "</td>";
  326. print '</tr>';
  327. }
  328. // Relative discounts (Discounts-Drawbacks-Rebates)
  329. print '<tr><td class="nowrap">';
  330. print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
  331. print $langs->trans("CustomerRelativeDiscountShort");
  332. print '<td><td class="right">';
  333. if ($user->rights->societe->creer && !$user->societe_id > 0)
  334. {
  335. print '<a href="'.DOL_URL_ROOT.'/comm/remise.php?id='.$object->id.'">'.img_edit($langs->trans("Modify")).'</a>';
  336. }
  337. print '</td></tr></table>';
  338. print '</td><td>'.($object->remise_percent?'<a href="'.DOL_URL_ROOT.'/comm/remise.php?id='.$object->id.'">'.$object->remise_percent.'%</a>':'').'</td>';
  339. print '</tr>';
  340. // Absolute discounts (Discounts-Drawbacks-Rebates)
  341. print '<tr><td class="nowrap">';
  342. print '<table width="100%" class="nobordernopadding">';
  343. print '<tr><td class="nowrap">';
  344. print $langs->trans("CustomerAbsoluteDiscountShort");
  345. print '<td><td class="right">';
  346. if ($user->rights->societe->creer && !$user->societe_id > 0)
  347. {
  348. 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>';
  349. }
  350. print '</td></tr></table>';
  351. print '</td>';
  352. print '<td>';
  353. $amount_discount=$object->getAvailableDiscounts();
  354. if ($amount_discount < 0) dol_print_error($db,$object->error);
  355. 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>';
  356. //else print $langs->trans("DiscountNone");
  357. print '</td>';
  358. print '</tr>';
  359. // Max outstanding bill
  360. if ($object->client)
  361. {
  362. print '<tr class="nowrap">';
  363. print '<td>';
  364. print $form->editfieldkey("OutstandingBill",'outstanding_limit',$object->outstanding_limit,$object,$user->rights->societe->creer);
  365. print '</td><td>';
  366. $limit_field_type = (! empty($conf->global->MAIN_USE_JQUERY_JEDITABLE)) ? 'numeric' : 'amount';
  367. print $form->editfieldval("OutstandingBill",'outstanding_limit',$object->outstanding_limit,$object,$user->rights->societe->creer,$limit_field_type,($object->outstanding_limit != '' ? price($object->outstanding_limit) : ''));
  368. //if (empty($object->outstanding_limit)) print $langs->trans("NoLimit");
  369. print '</td>';
  370. print '</tr>';
  371. }
  372. if ($object->client)
  373. {
  374. if (! empty($conf->commande->enabled) && ! empty($conf->global->ORDER_MANAGE_MIN_AMOUNT))
  375. {
  376. print '<!-- Minimim amount for orders -->'."\n";
  377. print '<tr class="nowrap">';
  378. print '<td>';
  379. print $form->editfieldkey("OrderMinAmount",'order_min_amount',$object->order_min_amount,$object,$user->rights->societe->creer);
  380. print '</td><td>';
  381. print $form->editfieldval("OrderMinAmount",'order_min_amount',$object->order_min_amount,$object,$user->rights->societe->creer,$limit_field_type,($object->order_min_amount != '' ? price($object->order_min_amount) : ''));
  382. print '</td>';
  383. print '</tr>';
  384. }
  385. }
  386. // Multiprice level
  387. if (! empty($conf->global->PRODUIT_MULTIPRICES) || ! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES))
  388. {
  389. print '<tr><td class="nowrap">';
  390. print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
  391. print $langs->trans("PriceLevel");
  392. print '<td><td class="right">';
  393. if ($user->rights->societe->creer)
  394. {
  395. print '<a href="'.DOL_URL_ROOT.'/comm/multiprix.php?id='.$object->id.'">'.img_edit($langs->trans("Modify")).'</a>';
  396. }
  397. print '</td></tr></table>';
  398. print '</td><td>';
  399. print $object->price_level;
  400. $keyforlabel='PRODUIT_MULTIPRICES_LABEL'.$object->price_level;
  401. if (! empty($conf->global->$keyforlabel)) print ' - '.$langs->trans($conf->global->$keyforlabel);
  402. print "</td>";
  403. print '</tr>';
  404. }
  405. // Preferred shipping Method
  406. if (! empty($conf->global->SOCIETE_ASK_FOR_SHIPPING_METHOD)) {
  407. print '<tr><td class="nowrap">';
  408. print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
  409. print $langs->trans('SendingMethod');
  410. print '<td>';
  411. if (($action != 'editshipping') && $user->rights->societe->creer) print '<td class="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editshipping&amp;socid='.$object->id.'">'.img_edit($langs->trans('SetMode'),1).'</a></td>';
  412. print '</tr></table>';
  413. print '</td><td>';
  414. if ($action == 'editshipping')
  415. {
  416. $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->shipping_method_id,'shipping_method_id');
  417. }
  418. else
  419. {
  420. $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->shipping_method_id,'none');
  421. }
  422. print "</td>";
  423. print '</tr>';
  424. }
  425. // Categories
  426. if (!empty($conf->categorie->enabled) && !empty($user->rights->categorie->lire)) {
  427. $langs->load("categories");
  428. print '<tr><td>' . $langs->trans("CustomersCategoriesShort") . '</td>';
  429. print '<td>';
  430. print $form->showCategories( $object->id, 'customer', 1 );
  431. print "</td></tr>";
  432. }
  433. // Other attributes
  434. $parameters=array('socid'=>$object->id);
  435. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
  436. // Sales representative
  437. include DOL_DOCUMENT_ROOT.'/societe/tpl/linesalesrepresentative.tpl.php';
  438. // Module Adherent
  439. if (! empty($conf->adherent->enabled))
  440. {
  441. $langs->load("members");
  442. $langs->load("users");
  443. print '<tr><td class="titlefield">'.$langs->trans("LinkedToDolibarrMember").'</td>';
  444. print '<td>';
  445. $adh=new Adherent($db);
  446. $result=$adh->fetch('','',$object->id);
  447. if ($result > 0)
  448. {
  449. $adh->ref=$adh->getFullName($langs);
  450. print $adh->getNomUrl(1);
  451. }
  452. else
  453. {
  454. print '<span class="opacitymedium">'.$langs->trans("ThirdpartyNotLinkedToMember").'</span>';
  455. }
  456. print '</td>';
  457. print "</tr>\n";
  458. }
  459. print "</table>";
  460. if ($object->client == 2 || $object->client == 3)
  461. {
  462. print '<br>';
  463. print '<div class="underbanner clearboth"></div>';
  464. print '<table class="border" width="100%">';
  465. // Level of prospect
  466. print '<tr><td class="titlefield nowrap">';
  467. print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
  468. print $langs->trans('ProspectLevel');
  469. print '<td>';
  470. if ($action != 'editlevel' && $user->rights->societe->creer) print '<td class="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editlevel&amp;socid='.$object->id.'">'.img_edit($langs->trans('Modify'),1).'</a></td>';
  471. print '</tr></table>';
  472. print '</td><td>';
  473. if ($action == 'editlevel')
  474. {
  475. $formcompany->form_prospect_level($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->fk_prospectlevel,'prospect_level_id',1);
  476. }
  477. else
  478. {
  479. print $object->getLibProspLevel();
  480. }
  481. print "</td>";
  482. print '</tr>';
  483. // Status
  484. $object->loadCacheOfProspStatus();
  485. print '<tr><td>'.$langs->trans("StatusProsp").'</td><td>'.$object->getLibProspCommStatut(4, $object->cacheprospectstatus[$object->stcomm_id]['label']);
  486. print ' &nbsp; &nbsp; ';
  487. print '<div class="floatright">';
  488. foreach($object->cacheprospectstatus as $key => $val)
  489. {
  490. $titlealt='default';
  491. if (! empty($val['code']) && ! in_array($val['code'], array('ST_NO', 'ST_NEVER', 'ST_TODO', 'ST_PEND', 'ST_DONE'))) $titlealt=$val['label'];
  492. 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>';
  493. }
  494. print '</div></td></tr>';
  495. print "</table>";
  496. }
  497. print '</div><div class="fichehalfright"><div class="ficheaddleft">';
  498. print '<div class="underbanner clearboth"></div>';
  499. $boxstat = '';
  500. // Nbre max d'elements des petites listes
  501. $MAXLIST=$conf->global->MAIN_SIZE_SHORTLIST_LIMIT;
  502. // Lien recap
  503. $boxstat.='<div class="box">';
  504. $boxstat.='<table summary="'.dol_escape_htmltag($langs->trans("DolibarrStateBoard")).'" class="border boxtable boxtablenobottom boxtablenotop" width="100%">';
  505. $boxstat.='<tr class="impair"><td colspan="2" class="tdboxstats nohover">';
  506. if (! empty($conf->propal->enabled))
  507. {
  508. // Box proposals
  509. $tmp = $object->getOutstandingProposals();
  510. $outstandingOpened=$tmp['opened'];
  511. $outstandingTotal=$tmp['total_ht'];
  512. $outstandingTotalIncTax=$tmp['total_ttc'];
  513. $text=$langs->trans("OverAllProposals");
  514. $link=DOL_URL_ROOT.'/comm/propal/list.php?socid='.$object->id;
  515. $icon='bill';
  516. if ($link) $boxstat.='<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
  517. $boxstat.='<div class="boxstats" title="'.dol_escape_htmltag($text).'">';
  518. $boxstat.='<span class="boxstatstext">'.img_object("",$icon).' '.$text.'</span><br>';
  519. $boxstat.='<span class="boxstatsindicator">'.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
  520. $boxstat.='</div>';
  521. if ($link) $boxstat.='</a>';
  522. }
  523. if (! empty($conf->commande->enabled))
  524. {
  525. // Box commandes
  526. $tmp = $object->getOutstandingOrders();
  527. $outstandingOpened=$tmp['opened'];
  528. $outstandingTotal=$tmp['total_ht'];
  529. $outstandingTotalIncTax=$tmp['total_ttc'];
  530. $text=$langs->trans("OverAllOrders");
  531. $link=DOL_URL_ROOT.'/commande/list.php?socid='.$object->id;
  532. $icon='bill';
  533. if ($link) $boxstat.='<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
  534. $boxstat.='<div class="boxstats" title="'.dol_escape_htmltag($text).'">';
  535. $boxstat.='<span class="boxstatstext">'.img_object("",$icon).' '.$text.'</span><br>';
  536. $boxstat.='<span class="boxstatsindicator">'.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
  537. $boxstat.='</div>';
  538. if ($link) $boxstat.='</a>';
  539. }
  540. if (! empty($conf->facture->enabled))
  541. {
  542. // Box factures
  543. $tmp = $object->getOutstandingBills();
  544. $outstandingOpened=$tmp['opened'];
  545. $outstandingTotal=$tmp['total_ht'];
  546. $outstandingTotalIncTax=$tmp['total_ttc'];
  547. $text=$langs->trans("OverAllInvoices");
  548. $link=DOL_URL_ROOT.'/compta/facture/list.php?socid='.$object->id;
  549. $icon='bill';
  550. if ($link) $boxstat.='<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
  551. $boxstat.='<div class="boxstats" title="'.dol_escape_htmltag($text).'">';
  552. $boxstat.='<span class="boxstatstext">'.img_object("",$icon).' '.$text.'</span><br>';
  553. $boxstat.='<span class="boxstatsindicator">'.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
  554. $boxstat.='</div>';
  555. if ($link) $boxstat.='</a>';
  556. // Box outstanding bill
  557. $warn = '';
  558. if ($object->outstanding_limit != '' && $object->outstanding_limit < $outstandingOpened)
  559. {
  560. $warn = ' '.img_warning($langs->trans("OutstandingBillReached"));
  561. }
  562. $text=$langs->trans("CurrentOutstandingBill");
  563. $link=DOL_URL_ROOT.'/compta/recap-compta.php?socid='.$object->id;
  564. $icon='bill';
  565. if ($link) $boxstat.='<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
  566. $boxstat.='<div class="boxstats" title="'.dol_escape_htmltag($text).'">';
  567. $boxstat.='<span class="boxstatstext">'.img_object("",$icon).' '.$text.'</span><br>';
  568. $boxstat.='<span class="boxstatsindicator'.($outstandingOpened>0?' amountremaintopay':'').'">'.price($outstandingOpened, 1, $langs, 1, -1, -1, $conf->currency).$warn.'</span>';
  569. $boxstat.='</div>';
  570. if ($link) $boxstat.='</a>';
  571. }
  572. $parameters = array();
  573. $reshook = $hookmanager->executeHooks('addMoreBoxStatsCustomer', $parameters, $object, $action);
  574. if(empty($reshook)){
  575. $boxstat.= $hookmanager->resPrint;
  576. }
  577. $boxstat.='</td></tr>';
  578. $boxstat.='</table>';
  579. $boxstat.='</div>';
  580. print $boxstat;
  581. $now=dol_now();
  582. /*
  583. * Last proposals
  584. */
  585. if (! empty($conf->propal->enabled) && $user->rights->propal->lire)
  586. {
  587. $langs->load("propal");
  588. $sql = "SELECT s.nom, s.rowid, p.rowid as propalid, p.fk_statut, p.total_ht";
  589. $sql.= ", p.tva as total_tva";
  590. $sql.= ", p.total as total_ttc";
  591. $sql.= ", p.ref, p.ref_client, p.remise";
  592. $sql.= ", p.datep as dp, p.fin_validite as datelimite";
  593. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as p, ".MAIN_DB_PREFIX."c_propalst as c";
  594. $sql.= " WHERE p.fk_soc = s.rowid AND p.fk_statut = c.id";
  595. $sql.= " AND s.rowid = ".$object->id;
  596. $sql.= " AND p.entity IN (".getEntity('propal').")";
  597. $sql.= " ORDER BY p.datep DESC";
  598. $resql=$db->query($sql);
  599. if ($resql)
  600. {
  601. $propal_static = new Propal($db);
  602. $num = $db->num_rows($resql);
  603. if ($num > 0)
  604. {
  605. print '<div class="div-table-responsive-no-min">';
  606. print '<table class="noborder" width="100%">';
  607. print '<tr class="liste_titre">';
  608. print '<td colspan="4"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("LastPropals",($num<=$MAXLIST?"":$MAXLIST)).'</td><td class="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>';
  609. print '<td width="20px" class="right"><a href="'.DOL_URL_ROOT.'/comm/propal/stats/index.php?socid='.$object->id.'">'.img_picto($langs->trans("Statistics"),'stats').'</a></td>';
  610. print '</tr></table></td>';
  611. print '</tr>';
  612. }
  613. $i = 0;
  614. while ($i < $num && $i < $MAXLIST)
  615. {
  616. $objp = $db->fetch_object($resql);
  617. print '<tr class="oddeven">';
  618. print '<td class="nowrap">';
  619. $propal_static->id = $objp->propalid;
  620. $propal_static->ref = $objp->ref;
  621. $propal_static->ref_client = $objp->ref_client;
  622. $propal_static->total_ht = $objp->total_ht;
  623. $propal_static->total_tva = $objp->total_tva;
  624. $propal_static->total_ttc = $objp->total_ttc;
  625. print $propal_static->getNomUrl(1);
  626. if ( ($db->jdate($objp->datelimite) < ($now - $conf->propal->cloture->warning_delay)) && $objp->fk_statut == 1 ) {
  627. print " ".img_warning();
  628. }
  629. print '</td><td class="right" width="80px">'.dol_print_date($db->jdate($objp->dp),'day')."</td>\n";
  630. print '<td class="right" style="min-width: 60px">'.price($objp->total_ht).'</td>';
  631. print '<td class="right" style="min-width: 60px" class="nowrap">'.$propal_static->LibStatut($objp->fk_statut,5).'</td></tr>';
  632. $i++;
  633. }
  634. $db->free($resql);
  635. if ($num > 0)
  636. {
  637. print "</table>";
  638. print '</div>';
  639. }
  640. }
  641. else
  642. {
  643. dol_print_error($db);
  644. }
  645. }
  646. /*
  647. * Last orders
  648. */
  649. if (! empty($conf->commande->enabled) && $user->rights->commande->lire)
  650. {
  651. $sql = "SELECT s.nom, s.rowid";
  652. $sql.= ", c.rowid as cid, c.total_ht";
  653. $sql.= ", c.tva as total_tva";
  654. $sql.= ", c.total_ttc";
  655. $sql.= ", c.ref, c.ref_client, c.fk_statut, c.facture";
  656. $sql.= ", c.date_commande as dc";
  657. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande as c";
  658. $sql.= " WHERE c.fk_soc = s.rowid ";
  659. $sql.= " AND s.rowid = ".$object->id;
  660. $sql.= " AND c.entity = ".$conf->entity;
  661. $sql.= " ORDER BY c.date_commande DESC";
  662. $resql=$db->query($sql);
  663. if ($resql)
  664. {
  665. $commande_static=new Commande($db);
  666. $num = $db->num_rows($resql);
  667. if ($num > 0)
  668. {
  669. // Check if there are orders billable
  670. $sql2 = 'SELECT s.nom, s.rowid as socid, s.client, c.rowid, c.ref, c.total_ht, c.ref_client,';
  671. $sql2.= ' c.date_valid, c.date_commande, c.date_livraison, c.fk_statut, c.facture as billed';
  672. $sql2.= ' FROM '.MAIN_DB_PREFIX.'societe as s';
  673. $sql2.= ', '.MAIN_DB_PREFIX.'commande as c';
  674. $sql2.= ' WHERE c.fk_soc = s.rowid';
  675. $sql2.= ' AND s.rowid = '.$object->id;
  676. // Show orders with status validated, shipping started and delivered (well any order we can bill)
  677. $sql2.= " AND ((c.fk_statut IN (1,2)) OR (c.fk_statut = 3 AND c.facture = 0))";
  678. $resql2=$db->query($sql2);
  679. $orders2invoice = $db->num_rows($resql2);
  680. $db->free($resql2);
  681. print '<div class="div-table-responsive-no-min">';
  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("LastCustomerOrders",($num<=$MAXLIST?"":$MAXLIST)).'</td><td class="right"><a class="notasortlink" href="'.DOL_URL_ROOT.'/commande/list.php?socid='.$object->id.'">'.$langs->trans("AllOrders").' <span class="badge">'.$num.'</span></a></td>';
  685. print '<td width="20px" class="right"><a href="'.DOL_URL_ROOT.'/commande/stats/index.php?socid='.$object->id.'">'.img_picto($langs->trans("Statistics"),'stats').'</a></td>';
  686. //if($num2 > 0) print '<td width="20px" class="right"><a href="'.DOL_URL_ROOT.'/commande/orderstoinvoice.php?socid='.$object->id.'">'.img_picto($langs->trans("CreateInvoiceForThisCustomer"),'object_bill').'</a></td>';
  687. //else print '<td width="20px" class="right"><a href="#">'.img_picto($langs->trans("NoOrdersToInvoice"),'object_bill').'</a></td>';
  688. print '</tr></table></td>';
  689. print '</tr>';
  690. }
  691. $i = 0;
  692. while ($i < $num && $i < $MAXLIST)
  693. {
  694. $objp = $db->fetch_object($resql);
  695. $commande_static->id = $objp->cid;
  696. $commande_static->ref = $objp->ref;
  697. $commande_static->ref_client=$objp->ref_client;
  698. $commande_static->total_ht = $objp->total_ht;
  699. $commande_static->total_tva = $objp->total_tva;
  700. $commande_static->total_ttc = $objp->total_ttc;
  701. $commande_static->billed = $objp->billed;
  702. print '<tr class="oddeven">';
  703. print '<td class="nowrap">';
  704. print $commande_static->getNomUrl(1);
  705. print '</td><td class="right" width="80px">'.dol_print_date($db->jdate($objp->dc),'day')."</td>\n";
  706. print '<td class="right" style="min-width: 60px">'.price($objp->total_ht).'</td>';
  707. print '<td class="right" style="min-width: 60px" class="nowrap">'.$commande_static->LibStatut($objp->fk_statut,$objp->facture,5).'</td></tr>';
  708. $i++;
  709. }
  710. $db->free($resql);
  711. if ($num >0)
  712. {
  713. print "</table>";
  714. print '</div>';
  715. }
  716. }
  717. else
  718. {
  719. dol_print_error($db);
  720. }
  721. }
  722. /*
  723. * Last shipments
  724. */
  725. if (! empty($conf->expedition->enabled) && $user->rights->expedition->lire)
  726. {
  727. $sql = 'SELECT e.rowid as id';
  728. $sql.= ', e.ref';
  729. $sql.= ', e.date_creation';
  730. $sql.= ', e.fk_statut as statut';
  731. $sql.= ', s.nom';
  732. $sql.= ', s.rowid as socid';
  733. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."expedition as e";
  734. $sql.= " WHERE e.fk_soc = s.rowid AND s.rowid = ".$object->id;
  735. $sql.= " AND e.entity IN (".getEntity('expedition').")";
  736. $sql.= ' GROUP BY e.rowid';
  737. $sql.= ', e.ref';
  738. $sql.= ', e.date_creation';
  739. $sql.= ', e.fk_statut';
  740. $sql.= ', s.nom';
  741. $sql.= ', s.rowid';
  742. $sql.= " ORDER BY e.date_creation DESC";
  743. $resql = $db->query($sql);
  744. if ($resql)
  745. {
  746. $sendingstatic = new Expedition($db);
  747. $num = $db->num_rows($resql);
  748. if ($num > 0) {
  749. print '<div class="div-table-responsive-no-min">';
  750. print '<table class="noborder" width="100%">';
  751. print '<tr class="liste_titre">';
  752. print '<td colspan="4"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("LastSendings",($num<=$MAXLIST?"":$MAXLIST)).'</td><td class="right"><a class="notasortlink" href="'.DOL_URL_ROOT.'/expedition/list.php?socid='.$object->id.'">'.$langs->trans("AllSendings").' <span class="badge">'.$num.'</span></a></td>';
  753. print '<td width="20px" class="right"><a href="'.DOL_URL_ROOT.'/expedition/stats/index.php?socid='.$object->id.'">'.img_picto($langs->trans("Statistics"),'stats').'</a></td>';
  754. print '</tr></table></td>';
  755. print '</tr>';
  756. }
  757. $i = 0;
  758. while ($i < $num && $i < $MAXLIST)
  759. {
  760. $objp = $db->fetch_object($resql);
  761. $sendingstatic->id = $objp->id;
  762. $sendingstatic->ref = $objp->ref;
  763. print '<tr class="oddeven">';
  764. print '<td class="nowrap">';
  765. print $sendingstatic->getNomUrl(1);
  766. print '</td>';
  767. if ($objp->date_creation > 0) {
  768. print '<td class="right" width="80px">'.dol_print_date($db->jdate($objp->date_creation),'day').'</td>';
  769. } else {
  770. print '<td class="right"><b>!!!</b></td>';
  771. }
  772. print '<td align="right" class="nowrap" width="100" >' . $sendingstatic->LibStatut($objp->statut, 5) . '</td>';
  773. print "</tr>\n";
  774. $i++;
  775. }
  776. $db->free($resql);
  777. if ($num > 0)
  778. {
  779. print "</table>";
  780. print '</div>';
  781. }
  782. } else {
  783. dol_print_error($db);
  784. }
  785. }
  786. /*
  787. * Last linked contracts
  788. */
  789. if (! empty($conf->contrat->enabled) && $user->rights->contrat->lire)
  790. {
  791. $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_customer as refcus, c.ref_supplier as refsup";
  792. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."contrat as c";
  793. $sql.= " WHERE c.fk_soc = s.rowid ";
  794. $sql.= " AND s.rowid = ".$object->id;
  795. $sql.= " AND c.entity = ".$conf->entity;
  796. $sql.= " ORDER BY c.datec DESC";
  797. $resql=$db->query($sql);
  798. if ($resql)
  799. {
  800. $contrat=new Contrat($db);
  801. $num = $db->num_rows($resql);
  802. if ($num >0)
  803. {
  804. print '<div class="div-table-responsive-no-min">';
  805. print '<table class="noborder" width="100%">';
  806. print '<tr class="liste_titre">';
  807. print '<td colspan="6"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("LastContracts",($num<=$MAXLIST?"":$MAXLIST)).'</td>';
  808. print '<td class="right"><a class="notasortlink" href="'.DOL_URL_ROOT.'/contrat/list.php?socid='.$object->id.'">'.$langs->trans("AllContracts").' <span class="badge">'.$num.'</span></a></td>';
  809. //print '<td width="20px" class="right"><a href="'.DOL_URL_ROOT.'/contract/stats/index.php?socid='.$object->id.'">'.img_picto($langs->trans("Statistics"),'stats').'</a></td>';
  810. print '</tr></table></td>';
  811. print '</tr>';
  812. }
  813. $i = 0;
  814. while ($i < $num && $i < $MAXLIST)
  815. {
  816. $objp = $db->fetch_object($resql);
  817. $contrat->id=$objp->id;
  818. $contrat->ref=$objp->ref?$objp->ref:$objp->id;
  819. $contrat->ref_customer=$objp->refcus;
  820. $contrat->ref_supplier=$objp->refsup;
  821. $contrat->fetch_lines();
  822. print '<tr class="oddeven">';
  823. print '<td class="nowrap">';
  824. print $contrat->getNomUrl(1,12);
  825. print "</td>\n";
  826. print '<td class="nowrap">'.dol_trunc($objp->refsup,12)."</td>\n";
  827. print '<td class="right" width="80px">'.dol_print_date($db->jdate($objp->dc),'day')."</td>\n";
  828. print '<td class="right" width="80px">'.dol_print_date($db->jdate($objp->dcon),'day')."</td>\n";
  829. print '<td width="20">&nbsp;</td>';
  830. print '<td align="right" class="nowraponall">';
  831. print $contrat->getLibStatut(4);
  832. print "</td>\n";
  833. print '</tr>';
  834. $i++;
  835. }
  836. $db->free($resql);
  837. if ($num > 0)
  838. {
  839. print "</table>";
  840. print '</div>';
  841. }
  842. }
  843. else
  844. {
  845. dol_print_error($db);
  846. }
  847. }
  848. /*
  849. * Last interventions
  850. */
  851. if (! empty($conf->ficheinter->enabled) && $user->rights->ficheinter->lire)
  852. {
  853. $sql = "SELECT s.nom, s.rowid, f.rowid as id, f.ref, f.fk_statut, f.duree as duration, f.datei as startdate";
  854. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."fichinter as f";
  855. $sql.= " WHERE f.fk_soc = s.rowid";
  856. $sql.= " AND s.rowid = ".$object->id;
  857. $sql.= " AND f.entity = ".$conf->entity;
  858. $sql.= " ORDER BY f.tms DESC";
  859. $resql=$db->query($sql);
  860. if ($resql)
  861. {
  862. $fichinter_static=new Fichinter($db);
  863. $num = $db->num_rows($resql);
  864. if ($num > 0)
  865. {
  866. print '<div class="div-table-responsive-no-min">';
  867. print '<table class="noborder" width="100%">';
  868. print '<tr class="liste_titre">';
  869. print '<td colspan="3"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("LastInterventions",($num<=$MAXLIST?"":$MAXLIST)).'</td><td class="right"><a class="notasortlink" href="'.DOL_URL_ROOT.'/fichinter/list.php?socid='.$object->id.'">'.$langs->trans("AllInterventions").' <span class="badge">'.$num.'</span></td>';
  870. print '<td width="20px" class="right"><a href="'.DOL_URL_ROOT.'/fichinter/stats/index.php?socid='.$object->id.'">'.img_picto($langs->trans("Statistics"),'stats').'</a></td>';
  871. print '</tr></table></td>';
  872. print '</tr>';
  873. }
  874. $i = 0;
  875. while ($i < $num && $i < $MAXLIST)
  876. {
  877. $objp = $db->fetch_object($resql);
  878. $fichinter_static->id=$objp->id;
  879. $fichinter_static->statut=$objp->fk_statut;
  880. print '<tr class="oddeven">';
  881. 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";
  882. //print '<td class="right" width="80px">'.dol_print_date($db->jdate($objp->startdate)).'</td>'."\n";
  883. print '<td class="right" style="min-width: 60px">'.convertSecondToTime($objp->duration).'</td>'."\n";
  884. print '<td align="right" class="nowrap" style="min-width: 60px">'.$fichinter_static->getLibStatut(5).'</td>'."\n";
  885. print '</tr>';
  886. $i++;
  887. }
  888. $db->free($resql);
  889. if ($num > 0)
  890. {
  891. print "</table>";
  892. print '</div>';
  893. }
  894. }
  895. else
  896. {
  897. dol_print_error($db);
  898. }
  899. }
  900. /*
  901. * Last invoices templates
  902. */
  903. if (! empty($conf->facture->enabled) && $user->rights->facture->lire)
  904. {
  905. $sql = 'SELECT f.rowid as id, f.titre as ref, f.amount';
  906. $sql.= ', f.total as total_ht';
  907. $sql.= ', f.tva as total_tva';
  908. $sql.= ', f.total_ttc';
  909. $sql.= ', f.datec as dc';
  910. $sql.= ', f.date_last_gen, f.date_when';
  911. $sql.= ', f.frequency';
  912. $sql.= ', f.unit_frequency';
  913. $sql.= ', f.suspended as suspended';
  914. $sql.= ', s.nom, s.rowid as socid';
  915. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture_rec as f";
  916. $sql.= " WHERE f.fk_soc = s.rowid AND s.rowid = ".$object->id;
  917. $sql.= " AND f.entity = ".$conf->entity;
  918. $sql.= ' GROUP BY f.rowid, f.titre, f.amount, f.total, f.tva, f.total_ttc,';
  919. $sql.= ' f.date_last_gen, f.datec, f.frequency, f.unit_frequency,';
  920. $sql.= ' f.suspended,';
  921. $sql.= ' s.nom, s.rowid';
  922. $sql.= " ORDER BY f.date_last_gen, f.datec DESC";
  923. $resql=$db->query($sql);
  924. if ($resql)
  925. {
  926. $invoicetemplate = new FactureRec($db);
  927. $num = $db->num_rows($resql);
  928. if ($num > 0)
  929. {
  930. print '<div class="div-table-responsive-no-min">';
  931. print '<table class="noborder" width="100%">';
  932. print '<tr class="liste_titre">';
  933. print '<td colspan="4"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("LatestCustomerTemplateInvoices",($num<=$MAXLIST?"":$MAXLIST)).'</td><td class="right"><a class="notasortlink" href="'.DOL_URL_ROOT.'/compta/facture/list.php?socid='.$object->id.'">'.$langs->trans("AllCustomerTemplateInvoices").' <span class="badge">'.$num.'</span></a></td>';
  934. print '</tr></table></td>';
  935. print '</tr>';
  936. }
  937. $i = 0;
  938. while ($i < $num && $i < $MAXLIST)
  939. {
  940. $objp = $db->fetch_object($resql);
  941. $invoicetemplate->id = $objp->id;
  942. $invoicetemplate->ref = $objp->ref;
  943. $invoicetemplate->suspended = $objp->suspended;
  944. $invoicetemplate->frequency = $objp->frequency;
  945. $invoicetemplate->unit_frequency = $objp->unit_frequency;
  946. $invoicetemplate->total_ht = $objp->total_ht;
  947. $invoicetemplate->total_tva = $objp->total_tva;
  948. $invoicetemplate->total_ttc = $objp->total_ttc;
  949. $invoicetemplate->date_last_gen = $objp->date_last_gen;
  950. $invoicetemplate->date_when = $objp->date_when;
  951. print '<tr class="oddeven">';
  952. print '<td class="nowrap">';
  953. print $invoicetemplate->getNomUrl(1);
  954. print '</td>';
  955. if ($objp->frequency && $objp->date_last_gen > 0)
  956. {
  957. print '<td class="right" width="80px">'.dol_print_date($db->jdate($objp->date_last_gen),'day').'</td>';
  958. }
  959. else
  960. {
  961. if ($objp->dc > 0)
  962. {
  963. print '<td class="right" width="80px">'.dol_print_date($db->jdate($objp->dc),'day').'</td>';
  964. }
  965. else
  966. {
  967. print '<td class="right"><b>!!!</b></td>';
  968. }
  969. }
  970. print '<td class="right" style="min-width: 60px">';
  971. print price($objp->total_ht);
  972. print '</td>';
  973. if (! empty($conf->global->MAIN_SHOW_PRICE_WITH_TAX_IN_SUMMARIES))
  974. {
  975. print '<td class="right" style="min-width: 60px">';
  976. print price($objp->total_ttc);
  977. print '</td>';
  978. }
  979. print '<td align="right" class="nowrap" style="min-width: 60px">';
  980. print $langs->trans('FrequencyPer_'.$invoicetemplate->unit_frequency, $invoicetemplate->frequency).' - ';
  981. print ($invoicetemplate->LibStatut($invoicetemplate->frequency,$invoicetemplate->suspended,5,0));
  982. print '</td>';
  983. print "</tr>\n";
  984. $i++;
  985. }
  986. $db->free($resql);
  987. if ($num > 0)
  988. {
  989. print "</table>";
  990. print '</div>';
  991. }
  992. }
  993. else
  994. {
  995. dol_print_error($db);
  996. }
  997. }
  998. /*
  999. * Last invoices
  1000. */
  1001. if (! empty($conf->facture->enabled) && $user->rights->facture->lire)
  1002. {
  1003. $sql = 'SELECT f.rowid as facid, f.ref, f.type, f.amount';
  1004. $sql.= ', f.total as total_ht';
  1005. $sql.= ', f.tva as total_tva';
  1006. $sql.= ', f.total_ttc';
  1007. $sql.= ', f.datef as df, f.datec as dc, f.paye as paye, f.fk_statut as statut';
  1008. $sql.= ', s.nom, s.rowid as socid';
  1009. $sql.= ', SUM(pf.amount) as am';
  1010. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f";
  1011. $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON f.rowid=pf.fk_facture';
  1012. $sql.= " WHERE f.fk_soc = s.rowid AND s.rowid = ".$object->id;
  1013. $sql.= " AND f.entity IN (".getEntity('invoice').")";
  1014. $sql.= ' GROUP BY f.rowid, f.ref, f.type, f.amount, f.total, f.tva, f.total_ttc,';
  1015. $sql.= ' f.datef, f.datec, f.paye, f.fk_statut,';
  1016. $sql.= ' s.nom, s.rowid';
  1017. $sql.= " ORDER BY f.datef DESC, f.datec DESC";
  1018. $resql=$db->query($sql);
  1019. if ($resql)
  1020. {
  1021. $facturestatic = new Facture($db);
  1022. $num = $db->num_rows($resql);
  1023. if ($num > 0)
  1024. {
  1025. print '<div class="div-table-responsive-no-min">';
  1026. print '<table class="noborder" width="100%">';
  1027. print '<tr class="liste_titre">';
  1028. print '<td colspan="5"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("LastCustomersBills",($num<=$MAXLIST?"":$MAXLIST)).'</td><td class="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>';
  1029. print '<td width="20px" class="right"><a href="'.DOL_URL_ROOT.'/compta/facture/stats/index.php?socid='.$object->id.'">'.img_picto($langs->trans("Statistics"),'stats').'</a></td>';
  1030. print '</tr></table></td>';
  1031. print '</tr>';
  1032. }
  1033. $i = 0;
  1034. while ($i < $num && $i < $MAXLIST)
  1035. {
  1036. $objp = $db->fetch_object($resql);
  1037. $facturestatic->id = $objp->facid;
  1038. $facturestatic->ref = $objp->ref;
  1039. $facturestatic->type = $objp->type;
  1040. $facturestatic->total_ht = $objp->total_ht;
  1041. $facturestatic->total_tva = $objp->total_tva;
  1042. $facturestatic->total_ttc = $objp->total_ttc;
  1043. print '<tr class="oddeven">';
  1044. print '<td class="nowrap">';
  1045. print $facturestatic->getNomUrl(1);
  1046. print '</td>';
  1047. if ($objp->df > 0)
  1048. {
  1049. print '<td class="right" width="80px">'.dol_print_date($db->jdate($objp->df),'day').'</td>';
  1050. }
  1051. else
  1052. {
  1053. print '<td class="right"><b>!!!</b></td>';
  1054. }
  1055. print '<td class="right" style="min-width: 60px">';
  1056. print price($objp->total_ht);
  1057. print '</td>';
  1058. if (! empty($conf->global->MAIN_SHOW_PRICE_WITH_TAX_IN_SUMMARIES))
  1059. {
  1060. print '<td class="right" style="min-width: 60px">';
  1061. print price($objp->total_ttc);
  1062. print '</td>';
  1063. }
  1064. print '<td align="right" class="nowrap" style="min-width: 60px">'.($facturestatic->LibStatut($objp->paye,$objp->statut,5,$objp->am)).'</td>';
  1065. print "</tr>\n";
  1066. $i++;
  1067. }
  1068. $db->free($resql);
  1069. if ($num > 0)
  1070. {
  1071. print "</table>";
  1072. print '</div>';
  1073. }
  1074. }
  1075. else
  1076. {
  1077. dol_print_error($db);
  1078. }
  1079. }
  1080. print '</div></div></div>';
  1081. print '<div style="clear:both"></div>';
  1082. dol_fiche_end();
  1083. /*
  1084. * Barre d'actions
  1085. */
  1086. print '<div class="tabsAction">';
  1087. $parameters = array();
  1088. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
  1089. if (empty($reshook))
  1090. {
  1091. if ($object->status != 1)
  1092. {
  1093. print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" title="'.dol_escape_js($langs->trans("ThirdPartyIsClosed")).'" href="#">'.$langs->trans("ThirdPartyIsClosed").'</a></div>';
  1094. }
  1095. if (! empty($conf->propal->enabled) && $user->rights->propal->creer && $object->status==1)
  1096. {
  1097. $langs->load("propal");
  1098. 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>';
  1099. }
  1100. if (! empty($conf->commande->enabled) && $user->rights->commande->creer && $object->status==1)
  1101. {
  1102. $langs->load("orders");
  1103. 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>';
  1104. }
  1105. if ($user->rights->contrat->creer && $object->status==1)
  1106. {
  1107. $langs->load("contracts");
  1108. 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>';
  1109. }
  1110. if (! empty($conf->ficheinter->enabled) && $user->rights->ficheinter->creer && $object->status==1)
  1111. {
  1112. $langs->load("fichinter");
  1113. 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>';
  1114. }
  1115. // Add invoice
  1116. if ($user->societe_id == 0)
  1117. {
  1118. if (! empty($conf->deplacement->enabled) && $object->status==1)
  1119. {
  1120. $langs->load("trips");
  1121. 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>';
  1122. }
  1123. if (! empty($conf->facture->enabled) && $object->status==1)
  1124. {
  1125. if (empty($user->rights->facture->creer))
  1126. {
  1127. print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" title="'.dol_escape_js($langs->trans("NotAllowed")).'" href="#">'.$langs->trans("AddBill").'</a></div>';
  1128. }
  1129. else
  1130. {
  1131. $langs->load("bills");
  1132. $langs->load("orders");
  1133. if (! empty($conf->commande->enabled))
  1134. {
  1135. if ($object->client != 0 && $object->client != 2)
  1136. {
  1137. 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>';
  1138. else print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" title="'.dol_escape_js($langs->trans("NoOrdersToInvoice")).'" href="#">'.$langs->trans("CreateInvoiceForThisCustomer").'</a></div>';
  1139. }
  1140. else print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" title="'.dol_escape_js($langs->trans("ThirdPartyMustBeEditAsCustomer")).'" href="#">'.$langs->trans("AddBill").'</a></div>';
  1141. }
  1142. 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>';
  1143. else print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" title="'.dol_escape_js($langs->trans("ThirdPartyMustBeEditAsCustomer")).'" href="#">'.$langs->trans("AddBill").'</a></div>';
  1144. }
  1145. }
  1146. }
  1147. // Add action
  1148. if (! empty($conf->agenda->enabled) && ! empty($conf->global->MAIN_REPEATTASKONEACHTAB) && $object->status==1)
  1149. {
  1150. if ($user->rights->agenda->myactions->create)
  1151. {
  1152. 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>';
  1153. }
  1154. else
  1155. {
  1156. print '<div class="inline-block divButAction"><a class="butAction" title="'.dol_escape_js($langs->trans("NotAllowed")).'" href="#">'.$langs->trans("AddAction").'</a></div>';
  1157. }
  1158. }
  1159. }
  1160. print '</div>';
  1161. if (! empty($conf->global->MAIN_DUPLICATE_CONTACTS_TAB_ON_CUSTOMER_CARD))
  1162. {
  1163. // List of contacts
  1164. show_contacts($conf,$langs,$db,$object,$_SERVER["PHP_SELF"].'?socid='.$object->id);
  1165. }
  1166. // Addresses list
  1167. if (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) && ! empty($conf->global->MAIN_REPEATADDRESSONEACHTAB))
  1168. {
  1169. show_addresses($conf,$langs,$db,$object,$_SERVER["PHP_SELF"].'?socid='.$object->id);
  1170. }
  1171. if (! empty($conf->global->MAIN_REPEATTASKONEACHTAB))
  1172. {
  1173. print load_fiche_titre($langs->trans("ActionsOnCompany"),'','');
  1174. // List of todo actions
  1175. show_actions_todo($conf,$langs,$db,$object);
  1176. // List of done actions
  1177. show_actions_done($conf,$langs,$db,$object);
  1178. }
  1179. }
  1180. else
  1181. {
  1182. $langs->load("errors");
  1183. print $langs->trans('ErrorRecordNotFound');
  1184. }
  1185. // End of page
  1186. llxFooter();
  1187. $db->close();