card.php 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652
  1. <?php
  2. /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2020 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-2020 Juanjo Menent <jmenent@2byte.es>
  9. * Copyright (C) 2013 Alexandre Spangaro <aspangaro@open-dsi.fr>
  10. * Copyright (C) 2015-2021 Frédéric France <frederic.france@netlogic.fr>
  11. * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
  12. * Copyright (C) 2020 Open-Dsi <support@open-dsi.fr>
  13. * Copyright (C) 2022 Anthony Berton <anthony.berton@bb2a.fr>
  14. *
  15. * This program is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License as published by
  17. * the Free Software Foundation; either version 3 of the License, or
  18. * (at your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  27. */
  28. /**
  29. * \file htdocs/comm/card.php
  30. * \ingroup commercial compta
  31. * \brief Page to show customer card of a third party
  32. */
  33. // Load Dolibarr environment
  34. require '../main.inc.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  37. require_once DOL_DOCUMENT_ROOT.'/societe/class/client.class.php';
  38. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  39. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  40. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  41. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  42. if (isModEnabled('facture')) {
  43. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  44. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture-rec.class.php';
  45. }
  46. if (isModEnabled("propal")) {
  47. require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
  48. }
  49. if (isModEnabled('commande')) {
  50. require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
  51. }
  52. if (isModEnabled("expedition")) {
  53. require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
  54. }
  55. if (isModEnabled('contrat')) {
  56. require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
  57. }
  58. if (isModEnabled('adherent')) {
  59. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  60. }
  61. if (isModEnabled('ficheinter')) {
  62. require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
  63. }
  64. // Load translation files required by the page
  65. $langs->loadLangs(array('companies', 'banks'));
  66. if (isModEnabled('contrat')) {
  67. $langs->load("contracts");
  68. }
  69. if (isModEnabled('commande')) {
  70. $langs->load("orders");
  71. }
  72. if (isModEnabled("expedition")) {
  73. $langs->load("sendings");
  74. }
  75. if (isModEnabled('facture')) {
  76. $langs->load("bills");
  77. }
  78. if (isModEnabled('project')) {
  79. $langs->load("projects");
  80. }
  81. if (isModEnabled('ficheinter')) {
  82. $langs->load("interventions");
  83. }
  84. if (isModEnabled('notification')) {
  85. $langs->load("mails");
  86. }
  87. $action = GETPOST('action', 'aZ09');
  88. $id = (GETPOST('socid', 'int') ? GETPOST('socid', 'int') : GETPOST('id', 'int'));
  89. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  90. $sortfield = GETPOST('sortfield', 'aZ09comma');
  91. $sortorder = GETPOST('sortorder', 'aZ09comma');
  92. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  93. if (empty($page) || $page == -1) {
  94. $page = 0;
  95. } // If $page is not defined, or '' or -1
  96. $offset = $limit * $page;
  97. $pageprev = $page - 1;
  98. $pagenext = $page + 1;
  99. if (!$sortorder) {
  100. $sortorder = "ASC";
  101. }
  102. if (!$sortfield) {
  103. $sortfield = "nom";
  104. }
  105. $cancel = GETPOST('cancel', 'alpha');
  106. $object = new Client($db);
  107. $extrafields = new ExtraFields($db);
  108. $formfile = new FormFile($db);
  109. // fetch optionals attributes and labels
  110. $extrafields->fetch_name_optionals_label($object->table_element);
  111. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  112. $hookmanager->initHooks(array('thirdpartycomm', 'globalcard'));
  113. $now = dol_now();
  114. if ($id > 0 && empty($object->id)) {
  115. // Load data of third party
  116. $res = $object->fetch($id);
  117. if ($object->id < 0) {
  118. dol_print_error($db, $object->error, $object->errors);
  119. }
  120. }
  121. if ($object->id > 0) {
  122. if (!($object->client > 0) || !$user->hasRight('societe', 'lire')) {
  123. accessforbidden();
  124. }
  125. }
  126. // Security check
  127. if ($user->socid > 0) {
  128. $id = $user->socid;
  129. }
  130. $result = restrictedArea($user, 'societe', $object->id, '&societe', '', 'fk_soc', 'rowid', 0);
  131. /*
  132. * Actions
  133. */
  134. $parameters = array('id' => $id, 'socid' => $id);
  135. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some
  136. if ($reshook < 0) {
  137. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  138. }
  139. if (empty($reshook)) {
  140. if ($cancel) {
  141. $action = "";
  142. }
  143. // Set accountancy code
  144. if ($action == 'setcustomeraccountancycode') {
  145. $result = $object->fetch($id);
  146. $object->code_compta_client = GETPOST("customeraccountancycode");
  147. $object->code_compta = $object->code_compta_client; // For Backward compatibility
  148. $result = $object->update($object->id, $user, 1, 1, 0);
  149. if ($result < 0) {
  150. setEventMessages($object->error, $object->errors, 'errors');
  151. $action = 'editcustomeraccountancycode';
  152. }
  153. }
  154. // Payment terms of the settlement
  155. if ($action == 'setconditions' && $user->hasRight('societe', 'creer')) {
  156. $object->fetch($id);
  157. $result = $object->setPaymentTerms(GETPOST('cond_reglement_id', 'int'), GETPOST('cond_reglement_id_deposit_percent', 'alpha'));
  158. if ($result < 0) {
  159. setEventMessages($object->error, $object->errors, 'errors');
  160. }
  161. }
  162. // Payment mode
  163. if ($action == 'setmode' && $user->hasRight('societe', 'creer')) {
  164. $object->fetch($id);
  165. $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int'));
  166. if ($result < 0) {
  167. setEventMessages($object->error, $object->errors, 'errors');
  168. }
  169. }
  170. // Transport mode
  171. if ($action == 'settransportmode' && $user->hasRight('societe', 'creer')) {
  172. $object->fetch($id);
  173. $result = $object->setTransportMode(GETPOST('transport_mode_id', 'alpha'));
  174. if ($result < 0) {
  175. setEventMessages($object->error, $object->errors, 'errors');
  176. }
  177. }
  178. // Bank account
  179. if ($action == 'setbankaccount' && $user->hasRight('societe', 'creer')) {
  180. $object->fetch($id);
  181. $result = $object->setBankAccount(GETPOST('fk_account', 'int'));
  182. if ($result < 0) {
  183. setEventMessages($object->error, $object->errors, 'errors');
  184. }
  185. }
  186. // customer preferred shipping method
  187. if ($action == 'setshippingmethod' && $user->hasRight('societe', 'creer')) {
  188. $object->fetch($id);
  189. $result = $object->setShippingMethod(GETPOST('shipping_method_id', 'int'));
  190. if ($result < 0) {
  191. setEventMessages($object->error, $object->errors, 'errors');
  192. }
  193. }
  194. // assujetissement a la TVA
  195. if ($action == 'setassujtva' && $user->hasRight('societe', 'creer')) {
  196. $object->fetch($id);
  197. $object->tva_assuj = GETPOST('assujtva_value');
  198. $result = $object->update($object->id);
  199. if ($result < 0) {
  200. setEventMessages($object->error, $object->errors, 'errors');
  201. }
  202. }
  203. // set prospect level
  204. if ($action == 'setprospectlevel' && $user->hasRight('societe', 'creer')) {
  205. $object->fetch($id);
  206. $object->fk_prospectlevel = GETPOST('prospect_level_id', 'alpha');
  207. $result = $object->update($object->id, $user);
  208. if ($result < 0) {
  209. setEventMessages($object->error, $object->errors, 'errors');
  210. }
  211. }
  212. // set communication status
  213. if ($action == 'setstcomm') {
  214. $object->fetch($id);
  215. $object->stcomm_id = dol_getIdFromCode($db, GETPOST('stcomm', 'alpha'), 'c_stcomm');
  216. $result = $object->update($object->id, $user);
  217. if ($result < 0) {
  218. setEventMessages($object->error, $object->errors, 'errors');
  219. } else {
  220. $result = $object->fetch($object->id);
  221. }
  222. }
  223. // update outstandng limit
  224. if ($action == 'setoutstanding_limit') {
  225. $object->fetch($id);
  226. $object->outstanding_limit = GETPOST('outstanding_limit');
  227. $result = $object->update($object->id, $user);
  228. if ($result < 0) {
  229. setEventMessages($object->error, $object->errors, 'errors');
  230. }
  231. }
  232. // update order min amount
  233. if ($action == 'setorder_min_amount') {
  234. $object->fetch($id);
  235. $object->order_min_amount = price2num(GETPOST('order_min_amount', 'alpha'));
  236. $result = $object->update($object->id, $user);
  237. if ($result < 0) {
  238. setEventMessages($object->error, $object->errors, 'errors');
  239. }
  240. }
  241. // Set sales representatives
  242. if ($action == 'set_salesrepresentatives' && $user->hasRight('societe', 'creer')) {
  243. $object->fetch($id);
  244. $result = $object->setSalesRep(GETPOST('commercial', 'array'));
  245. }
  246. if ($action == 'update_extras') {
  247. $object->fetch($id);
  248. $object->oldcopy = dol_clone($object, 2);
  249. // Fill array 'array_options' with data from update form
  250. $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'restricthtml'));
  251. if ($ret < 0) {
  252. $error++;
  253. }
  254. if (!$error) {
  255. $result = $object->insertExtraFields('COMPANY_MODIFY');
  256. if ($result < 0) {
  257. setEventMessages($object->error, $object->errors, 'errors');
  258. $error++;
  259. }
  260. }
  261. if ($error) {
  262. $action = 'edit_extras';
  263. }
  264. }
  265. // warehouse
  266. if ($action == 'setwarehouse' && $user->hasRight('societe', 'creer')) {
  267. $result = $object->setWarehouse(GETPOST('fk_warehouse', 'int'));
  268. }
  269. }
  270. /*
  271. * View
  272. */
  273. $contactstatic = new Contact($db);
  274. $userstatic = new User($db);
  275. $form = new Form($db);
  276. $formcompany = new FormCompany($db);
  277. $title = $langs->trans("ThirdParty")." - ".$langs->trans('Customer');
  278. if (getDolGlobalString('MAIN_HTML_TITLE') && preg_match('/thirdpartynameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) {
  279. $title = $object->name." - ".$langs->trans('Customer');
  280. }
  281. $help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas|DE:Modul_Geschäftspartner';
  282. llxHeader('', $title, $help_url);
  283. if ($object->id > 0) {
  284. $head = societe_prepare_head($object);
  285. print dol_get_fiche_head($head, 'customer', $langs->trans("ThirdParty"), -1, 'company');
  286. $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  287. dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom');
  288. print '<div class="fichecenter"><div class="fichehalfleft">';
  289. print '<div class="underbanner clearboth"></div>';
  290. print '<table class="border centpercent tableforfield">';
  291. // Type Prospect/Customer/Supplier
  292. print '<tr><td class="titlefield">'.$langs->trans('NatureOfThirdParty').'</td><td>';
  293. print $object->getTypeUrl(1);
  294. print '</td></tr>';
  295. // Prefix
  296. if (getDolGlobalString('SOCIETE_USEPREFIX')) { // Old not used prefix field
  297. print '<tr><td>'.$langs->trans("Prefix").'</td><td>';
  298. print($object->prefix_comm ? $object->prefix_comm : '&nbsp;');
  299. print '</td></tr>';
  300. }
  301. if ($object->client) {
  302. $langs->load("compta");
  303. print '<tr><td>';
  304. print $langs->trans('CustomerCode').'</td><td>';
  305. print showValueWithClipboardCPButton(dol_escape_htmltag($object->code_client));
  306. $tmpcheck = $object->check_codeclient();
  307. if ($tmpcheck != 0 && $tmpcheck != -5) {
  308. print ' <span class="error">('.$langs->trans("WrongCustomerCode").')</span>';
  309. }
  310. print '</td></tr>';
  311. print '<tr>';
  312. print '<td>';
  313. print $form->editfieldkey("CustomerAccountancyCode", 'customeraccountancycode', $object->code_compta_client, $object, $user->hasRight('societe', 'creer'));
  314. print '</td><td>';
  315. print $form->editfieldval("CustomerAccountancyCode", 'customeraccountancycode', $object->code_compta_client, $object, $user->hasRight('societe', 'creer'));
  316. print '</td>';
  317. print '</tr>';
  318. }
  319. // 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.
  320. // We don't need them into customer profile.
  321. // Except for spain and localtax where localtax depends on buyer and not seller
  322. // VAT is used
  323. /*
  324. print '<tr>';
  325. print '<td class="nowrap">';
  326. print $form->textwithpicto($langs->trans('VATIsUsed'),$langs->trans('VATIsUsedWhenSelling'));
  327. print '</td>';
  328. print '<td>';
  329. print yn($object->tva_assuj);
  330. print '</td>';
  331. print '</tr>';
  332. */
  333. if ($mysoc->country_code == 'ES') {
  334. // Local Taxes
  335. if ($mysoc->localtax1_assuj == "1") {
  336. print '<tr><td class="nowrap">'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).'</td><td>';
  337. print yn($object->localtax1_assuj);
  338. print '</td></tr>';
  339. }
  340. if ($mysoc->localtax1_assuj == "1") {
  341. print '<tr><td class="nowrap">'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).'</td><td>';
  342. print yn($object->localtax2_assuj);
  343. print '</td></tr>';
  344. }
  345. }
  346. // TVA Intra
  347. print '<tr><td class="nowrap">'.$langs->trans('VATIntra').'</td><td>';
  348. print showValueWithClipboardCPButton(dol_escape_htmltag($object->tva_intra));
  349. print '</td></tr>';
  350. // default terms of the settlement
  351. $langs->load('bills');
  352. print '<tr><td>';
  353. print '<table width="100%" class="nobordernopadding"><tr><td>';
  354. print $langs->trans('PaymentConditions');
  355. print '<td>';
  356. if (($action != 'editconditions') && $user->hasRight('societe', 'creer')) {
  357. print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editconditions&token='.newToken().'&socid='.$object->id.'">'.img_edit($langs->trans('SetConditions'), 1).'</a></td>';
  358. }
  359. print '</tr></table>';
  360. print '</td><td>';
  361. if ($action == 'editconditions') {
  362. $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->cond_reglement_id, 'cond_reglement_id', 1, '', 1, $object->deposit_percent);
  363. } else {
  364. $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->cond_reglement_id, 'none', 0, '', 1, $object->deposit_percent);
  365. }
  366. print "</td>";
  367. print '</tr>';
  368. // Default payment mode
  369. print '<tr><td class="nowrap">';
  370. print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
  371. print $langs->trans('PaymentMode');
  372. print '<td>';
  373. if (($action != 'editmode') && $user->hasRight('societe', 'creer')) {
  374. print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editmode&token='.newToken().'&socid='.$object->id.'">'.img_edit($langs->trans('SetMode'), 1).'</a></td>';
  375. }
  376. print '</tr></table>';
  377. print '</td><td>';
  378. if ($action == 'editmode') {
  379. $form->form_modes_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->mode_reglement_id, 'mode_reglement_id', 'CRDT', 1, 1);
  380. } else {
  381. $form->form_modes_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->mode_reglement_id, 'none');
  382. }
  383. print "</td>";
  384. print '</tr>';
  385. if (isModEnabled("banque")) {
  386. // Default bank account for payments
  387. print '<tr><td class="nowrap">';
  388. print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
  389. print $langs->trans('PaymentBankAccount');
  390. print '<td>';
  391. if (($action != 'editbankaccount') && $user->hasRight('societe', 'creer')) {
  392. print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editbankaccount&token='.newToken().'&socid='.$object->id.'">'.img_edit($langs->trans('SetBankAccount'), 1).'</a></td>';
  393. }
  394. print '</tr></table>';
  395. print '</td><td>';
  396. if ($action == 'editbankaccount') {
  397. $form->formSelectAccount($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->fk_account, 'fk_account', 1);
  398. } else {
  399. $form->formSelectAccount($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->fk_account, 'none');
  400. }
  401. print "</td>";
  402. print '</tr>';
  403. }
  404. $isCustomer = ($object->client == 1 || $object->client == 3);
  405. // Relative discounts (Discounts-Drawbacks-Rebates)
  406. if ($isCustomer) {
  407. print '<tr><td class="nowrap">';
  408. print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
  409. print $langs->trans("CustomerRelativeDiscountShort");
  410. print '<td><td class="right">';
  411. if ($user->hasRight('societe', 'creer') && !$user->socid > 0) {
  412. print '<a class="editfielda" href="'.DOL_URL_ROOT.'/comm/remise.php?id='.$object->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?socid='.$object->id).'&action=create&token='.newToken().'">'.img_edit($langs->trans("Modify")).'</a>';
  413. }
  414. print '</td></tr></table>';
  415. print '</td><td>'.($object->remise_percent ? '<a href="'.DOL_URL_ROOT.'/comm/remise.php?id='.$object->id.'">'.$object->remise_percent.'%</a>' : '').'</td>';
  416. print '</tr>';
  417. // Absolute discounts (Discounts-Drawbacks-Rebates)
  418. print '<tr><td class="nowrap">';
  419. print '<table width="100%" class="nobordernopadding">';
  420. print '<tr><td class="nowrap">';
  421. print $langs->trans("CustomerAbsoluteDiscountShort");
  422. print '<td><td class="right">';
  423. if ($user->hasRight('societe', 'creer') && !$user->socid > 0) {
  424. print '<a class="editfielda" href="'.DOL_URL_ROOT.'/comm/remx.php?id='.$object->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?socid='.$object->id).'&action=create&token='.newToken().'">'.img_edit($langs->trans("Modify")).'</a>';
  425. }
  426. print '</td></tr></table>';
  427. print '</td>';
  428. print '<td>';
  429. $amount_discount = $object->getAvailableDiscounts();
  430. if ($amount_discount < 0) {
  431. dol_print_error($db, $object->error);
  432. }
  433. if ($amount_discount > 0) {
  434. print '<a href="'.DOL_URL_ROOT.'/comm/remx.php?id='.$object->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?socid='.$object->id).'&action=create&token='.newToken().'">'.price($amount_discount, 1, $langs, 1, -1, -1, $conf->currency).'</a>';
  435. }
  436. //else print $langs->trans("DiscountNone");
  437. print '</td>';
  438. print '</tr>';
  439. }
  440. // Max outstanding bill
  441. if ($object->client) {
  442. print '<tr class="nowrap">';
  443. print '<td>';
  444. print $form->editfieldkey("OutstandingBill", 'outstanding_limit', $object->outstanding_limit, $object, $user->hasRight('societe', 'creer'));
  445. print '</td><td>';
  446. $limit_field_type = (getDolGlobalString('MAIN_USE_JQUERY_JEDITABLE')) ? 'numeric' : 'amount';
  447. print $form->editfieldval("OutstandingBill", 'outstanding_limit', $object->outstanding_limit, $object, $user->hasRight('societe', 'creer'), $limit_field_type, ($object->outstanding_limit != '' ? price($object->outstanding_limit) : ''));
  448. print '</td>';
  449. print '</tr>';
  450. }
  451. if ($object->client) {
  452. if (isModEnabled('commande') && getDolGlobalString('ORDER_MANAGE_MIN_AMOUNT')) {
  453. print '<!-- Minimim amount for orders -->'."\n";
  454. print '<tr class="nowrap">';
  455. print '<td>';
  456. print $form->editfieldkey("OrderMinAmount", 'order_min_amount', $object->order_min_amount, $object, $user->hasRight('societe', 'creer'));
  457. print '</td><td>';
  458. print $form->editfieldval("OrderMinAmount", 'order_min_amount', $object->order_min_amount, $object, $user->hasRight('societe', 'creer'), $limit_field_type, ($object->order_min_amount != '' ? price($object->order_min_amount) : ''));
  459. print '</td>';
  460. print '</tr>';
  461. }
  462. }
  463. // Multiprice level
  464. if (getDolGlobalString('PRODUIT_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) {
  465. print '<tr><td class="nowrap">';
  466. print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
  467. print $langs->trans("PriceLevel");
  468. print '<td><td class="right">';
  469. if ($user->hasRight('societe', 'creer')) {
  470. print '<a class="editfielda" href="'.DOL_URL_ROOT.'/comm/multiprix.php?id='.$object->id.'">'.img_edit($langs->trans("Modify")).'</a>';
  471. }
  472. print '</td></tr></table>';
  473. print '</td><td>';
  474. print $object->price_level;
  475. $keyforlabel = 'PRODUIT_MULTIPRICES_LABEL'.$object->price_level;
  476. if (!empty($conf->global->$keyforlabel)) {
  477. print ' - '.$langs->trans($conf->global->$keyforlabel);
  478. }
  479. print "</td>";
  480. print '</tr>';
  481. }
  482. // Warehouse
  483. if (isModEnabled('stock') && getDolGlobalString('SOCIETE_ASK_FOR_WAREHOUSE')) {
  484. $langs->load('stocks');
  485. require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
  486. $formproduct = new FormProduct($db);
  487. print '<tr class="nowrap">';
  488. print '<td>';
  489. print $form->editfieldkey("Warehouse", 'warehouse', '', $object, $user->hasRight('societe', 'creer'));
  490. print '</td><td>';
  491. if ($action == 'editwarehouse') {
  492. $formproduct->formSelectWarehouses($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_warehouse, 'fk_warehouse', 1);
  493. } else {
  494. if ($object->fk_warehouse > 0) {
  495. print img_picto('', 'stock', 'class="paddingrightonly"');
  496. }
  497. $formproduct->formSelectWarehouses($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_warehouse, 'none');
  498. }
  499. print '</td>';
  500. print '</tr>';
  501. }
  502. // Preferred shipping Method
  503. if (getDolGlobalString('SOCIETE_ASK_FOR_SHIPPING_METHOD')) {
  504. print '<tr><td class="nowrap">';
  505. print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
  506. print $langs->trans('SendingMethod');
  507. print '<td>';
  508. if (($action != 'editshipping') && $user->hasRight('societe', 'creer')) {
  509. print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editshipping&token='.newToken().'&socid='.$object->id.'">'.img_edit($langs->trans('SetMode'), 1).'</a></td>';
  510. }
  511. print '</tr></table>';
  512. print '</td><td>';
  513. if ($action == 'editshipping') {
  514. $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->shipping_method_id, 'shipping_method_id', 1);
  515. } else {
  516. $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->shipping_method_id, 'none');
  517. }
  518. print "</td>";
  519. print '</tr>';
  520. }
  521. if (isModEnabled('intracommreport')) {
  522. // Transport mode by default
  523. print '<tr><td class="nowrap">';
  524. print '<table class="centpercent nobordernopadding"><tr><td class="nowrap">';
  525. print $langs->trans('IntracommReportTransportMode');
  526. print '<td>';
  527. if (($action != 'edittransportmode') && $user->hasRight('societe', 'creer')) {
  528. print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=edittransportmode&token='.newToken().'&socid='.$object->id.'">'.img_edit($langs->trans('SetMode'), 1).'</a></td>';
  529. }
  530. print '</tr></table>';
  531. print '</td><td>';
  532. if ($action == 'edittransportmode') {
  533. $form->formSelectTransportMode($_SERVER['PHP_SELF'].'?socid='.$object->id, (!empty($object->transport_mode_id) ? $object->transport_mode_id : ''), 'transport_mode_id', 1);
  534. } else {
  535. $form->formSelectTransportMode($_SERVER['PHP_SELF'].'?socid='.$object->id, (!empty($object->transport_mode_id) ? $object->transport_mode_id : ''), 'none');
  536. }
  537. print "</td>";
  538. print '</tr>';
  539. }
  540. // Categories
  541. if (isModEnabled('categorie') && $user->hasRight('categorie', 'lire')) {
  542. $langs->load("categories");
  543. print '<tr><td>'.$langs->trans("CustomersCategoriesShort").'</td>';
  544. print '<td>';
  545. print $form->showCategories($object->id, Categorie::TYPE_CUSTOMER, 1);
  546. print "</td></tr>";
  547. }
  548. // Other attributes
  549. $parameters = array('socid'=>$object->id);
  550. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  551. // Sales representative
  552. include DOL_DOCUMENT_ROOT.'/societe/tpl/linesalesrepresentative.tpl.php';
  553. // Module Adherent
  554. if (isModEnabled('adherent')) {
  555. $langs->load("members");
  556. $langs->load("users");
  557. print '<tr><td class="titlefield">'.$langs->trans("LinkedToDolibarrMember").'</td>';
  558. print '<td>';
  559. $adh = new Adherent($db);
  560. $result = $adh->fetch('', '', $object->id);
  561. if ($result > 0) {
  562. $adh->ref = $adh->getFullName($langs);
  563. print $adh->getNomUrl(-1);
  564. } else {
  565. print '<span class="opacitymedium">'.$langs->trans("ThirdpartyNotLinkedToMember").'</span>';
  566. }
  567. print '</td>';
  568. print "</tr>\n";
  569. }
  570. print "</table>";
  571. print '</div><div class="fichehalfright">';
  572. // Prospection level and status
  573. if ($object->client == 2 || $object->client == 3) {
  574. print '<div class="underbanner clearboth"></div>';
  575. print '<table class="border centpercent tableforfield">';
  576. // Level of prospection
  577. print '<tr><td class="titlefield nowrap">';
  578. print '<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
  579. print $langs->trans('ProspectLevel');
  580. print '<td>';
  581. if ($action != 'editlevel' && $user->hasRight('societe', 'creer')) {
  582. print '<td class="right"><a class="editfielda reposition" href="'.$_SERVER["PHP_SELF"].'?action=editlevel&token='.newToken().'&socid='.$object->id.'">'.img_edit($langs->trans('Modify'), 1).'</a></td>';
  583. }
  584. print '</tr></table>';
  585. print '</td><td>';
  586. if ($action == 'editlevel') {
  587. $formcompany->form_prospect_level($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->fk_prospectlevel, 'prospect_level_id', 1);
  588. } else {
  589. print $object->getLibProspLevel();
  590. }
  591. print "</td>";
  592. print '</tr>';
  593. // Status of prospection
  594. $object->loadCacheOfProspStatus();
  595. print '<tr><td>'.$langs->trans("StatusProsp").'</td><td>'.$object->getLibProspCommStatut(4, $object->cacheprospectstatus[$object->stcomm_id]['label']);
  596. print ' &nbsp; &nbsp; ';
  597. print '<div class="floatright">';
  598. foreach ($object->cacheprospectstatus as $key => $val) {
  599. $titlealt = 'default';
  600. if (!empty($val['code']) && !in_array($val['code'], array('ST_NO', 'ST_NEVER', 'ST_TODO', 'ST_PEND', 'ST_DONE'))) {
  601. $titlealt = $val['label'];
  602. }
  603. if ($object->stcomm_id != $val['id']) {
  604. print '<a class="pictosubstatus reposition" href="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'&stcomm='.$val['code'].'&action=setstcomm&token='.newToken().'">'.img_action($titlealt, $val['code'], $val['picto']).'</a>';
  605. }
  606. }
  607. print '</div></td></tr>';
  608. print "</table>";
  609. print '<br>';
  610. } else {
  611. print '<div class="underbanner underbanner-before-box clearboth"></div><br>';
  612. }
  613. $boxstat = '';
  614. // Nbre max d'elements des petites listes
  615. $MAXLIST = $conf->global->MAIN_SIZE_SHORTLIST_LIMIT;
  616. // Lien recap
  617. $boxstat .= '<div class="box divboxtable box-halfright">';
  618. $boxstat .= '<table summary="'.dol_escape_htmltag($langs->trans("DolibarrStateBoard")).'" class="border boxtable boxtablenobottom boxtablenotop boxtablenomarginbottom centpercent">';
  619. $boxstat .= '<tr class="impair nohover"><td colspan="2" class="tdboxstats nohover">';
  620. if (isModEnabled("propal") && $user->hasRight('propal', 'lire')) {
  621. // Box proposals
  622. $tmp = $object->getOutstandingProposals();
  623. $outstandingOpened = $tmp['opened'];
  624. $outstandingTotal = $tmp['total_ht'];
  625. $outstandingTotalIncTax = $tmp['total_ttc'];
  626. $text = $langs->trans("OverAllProposals");
  627. $link = DOL_URL_ROOT.'/comm/propal/list.php?socid='.$object->id;
  628. $icon = 'bill';
  629. if ($link) {
  630. $boxstat .= '<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
  631. }
  632. $boxstat .= '<div class="boxstats" title="'.dol_escape_htmltag($text).'">';
  633. $boxstat .= '<span class="boxstatstext">'.img_object("", $icon).' <span>'.$text.'</span></span><br>';
  634. $boxstat .= '<span class="boxstatsindicator">'.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
  635. $boxstat .= '</div>';
  636. if ($link) {
  637. $boxstat .= '</a>';
  638. }
  639. }
  640. if (isModEnabled('commande') && $user->hasRight('commande', 'lire')) {
  641. // Box commandes
  642. $tmp = $object->getOutstandingOrders();
  643. $outstandingOpened = $tmp['opened'];
  644. $outstandingTotal = $tmp['total_ht'];
  645. $outstandingTotalIncTax = $tmp['total_ttc'];
  646. $text = $langs->trans("OverAllOrders");
  647. $link = DOL_URL_ROOT.'/commande/list.php?socid='.$object->id;
  648. $icon = 'bill';
  649. if ($link) {
  650. $boxstat .= '<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
  651. }
  652. $boxstat .= '<div class="boxstats" title="'.dol_escape_htmltag($text).'">';
  653. $boxstat .= '<span class="boxstatstext">'.img_object("", $icon).' <span>'.$text.'</span></span><br>';
  654. $boxstat .= '<span class="boxstatsindicator">'.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
  655. $boxstat .= '</div>';
  656. if ($link) {
  657. $boxstat .= '</a>';
  658. }
  659. }
  660. if (isModEnabled('facture') && $user->hasRight('facture', 'lire')) {
  661. // Box factures
  662. $tmp = $object->getOutstandingBills('customer', 0);
  663. $outstandingOpened = $tmp['opened'];
  664. $outstandingTotal = $tmp['total_ht'];
  665. $outstandingTotalIncTax = $tmp['total_ttc'];
  666. $text = $langs->trans("OverAllInvoices");
  667. $link = DOL_URL_ROOT.'/compta/facture/list.php?socid='.$object->id;
  668. $icon = 'bill';
  669. if ($link) {
  670. $boxstat .= '<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
  671. }
  672. $boxstat .= '<div class="boxstats" title="'.dol_escape_htmltag($text).'">';
  673. $boxstat .= '<span class="boxstatstext">'.img_object("", $icon).' <span>'.$text.'</span></span><br>';
  674. $boxstat .= '<span class="boxstatsindicator">'.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
  675. $boxstat .= '</div>';
  676. if ($link) {
  677. $boxstat .= '</a>';
  678. }
  679. // Box outstanding bill
  680. $warn = '';
  681. if ($object->outstanding_limit != '' && $object->outstanding_limit < $outstandingOpened) {
  682. $warn = ' '.img_warning($langs->trans("OutstandingBillReached"));
  683. }
  684. $text = $langs->trans("CurrentOutstandingBill");
  685. $link = DOL_URL_ROOT.'/compta/recap-compta.php?socid='.$object->id;
  686. $icon = 'bill';
  687. if ($link) {
  688. $boxstat .= '<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
  689. }
  690. $boxstat .= '<div class="boxstats" title="'.dol_escape_htmltag($text).'">';
  691. $boxstat .= '<span class="boxstatstext">'.img_object("", $icon).' <span>'.$text.'</span></span><br>';
  692. $boxstat .= '<span class="boxstatsindicator'.($outstandingOpened > 0 ? ' amountremaintopay' : '').'">'.price($outstandingOpened, 1, $langs, 1, -1, -1, $conf->currency).$warn.'</span>';
  693. $boxstat .= '</div>';
  694. if ($link) {
  695. $boxstat .= '</a>';
  696. }
  697. $tmp = $object->getOutstandingBills('customer', 1);
  698. $outstandingOpenedLate = $tmp['opened'];
  699. if ($outstandingOpened != $outstandingOpenedLate && !empty($outstandingOpenedLate)) {
  700. $warn = '';
  701. if ($object->outstanding_limit != '' && $object->outstanding_limit < $outstandingOpenedLate) {
  702. $warn = ' '.img_warning($langs->trans("OutstandingBillReached"));
  703. }
  704. $text = $langs->trans("CurrentOutstandingBillLate");
  705. $link = DOL_URL_ROOT.'/compta/recap-compta.php?socid='.$object->id;
  706. $icon = 'bill';
  707. if ($link) {
  708. $boxstat .= '<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
  709. }
  710. $boxstat .= '<div class="boxstats" title="'.dol_escape_htmltag($text).'">';
  711. $boxstat .= '<span class="boxstatstext">'.img_object("", $icon).' <span>'.$text.'</span></span><br>';
  712. $boxstat .= '<span class="boxstatsindicator'.($outstandingOpenedLate > 0 ? ' amountremaintopay' : '').'">'.price($outstandingOpenedLate, 1, $langs, 1, -1, -1, $conf->currency).$warn.'</span>';
  713. $boxstat .= '</div>';
  714. if ($link) {
  715. $boxstat .= '</a>';
  716. }
  717. }
  718. }
  719. $parameters = array();
  720. $reshook = $hookmanager->executeHooks('addMoreBoxStatsCustomer', $parameters, $object, $action);
  721. if (empty($reshook)) {
  722. $boxstat .= $hookmanager->resPrint;
  723. }
  724. $boxstat .= '</td></tr>';
  725. $boxstat .= '</table>';
  726. $boxstat .= '</div>';
  727. print $boxstat;
  728. /*
  729. * Latest proposals
  730. */
  731. if (isModEnabled("propal") && $user->hasRight('propal', 'lire')) {
  732. $langs->load("propal");
  733. $sql = "SELECT s.nom, s.rowid, p.rowid as propalid, p.fk_statut, p.total_ht";
  734. $sql .= ", p.total_tva";
  735. $sql .= ", p.total_ttc";
  736. $sql .= ", p.ref, p.ref_client, p.remise";
  737. $sql .= ", p.datep as dp, p.fin_validite as date_limit, p.entity";
  738. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as p, ".MAIN_DB_PREFIX."c_propalst as c";
  739. $sql .= " WHERE p.fk_soc = s.rowid AND p.fk_statut = c.id";
  740. $sql .= " AND s.rowid = ".((int) $object->id);
  741. $sql .= " AND p.entity IN (".getEntity('propal').")";
  742. $sql .= " ORDER BY p.datep DESC";
  743. $resql = $db->query($sql);
  744. if ($resql) {
  745. $propal_static = new Propal($db);
  746. $num = $db->num_rows($resql);
  747. if ($num > 0) {
  748. print '<div class="div-table-responsive-no-min">';
  749. print '<table class="noborder centpercent lastrecordtable">';
  750. print '<tr class="liste_titre">';
  751. 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 marginleftonlyshort">'.$num.'</span></a></td>';
  752. 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>';
  753. print '</tr></table></td>';
  754. print '</tr>';
  755. }
  756. $i = 0;
  757. while ($i < $num && $i < $MAXLIST) {
  758. $objp = $db->fetch_object($resql);
  759. print '<tr class="oddeven">';
  760. print '<td class="nowraponall">';
  761. $propal_static->id = $objp->propalid;
  762. $propal_static->ref = $objp->ref;
  763. $propal_static->ref_client = $objp->ref_client;
  764. $propal_static->total_ht = $objp->total_ht;
  765. $propal_static->total_tva = $objp->total_tva;
  766. $propal_static->total_ttc = $objp->total_ttc;
  767. print $propal_static->getNomUrl(1);
  768. // Preview
  769. $filedir = $conf->propal->multidir_output[$objp->entity].'/'.dol_sanitizeFileName($objp->ref);
  770. $file_list = null;
  771. if (!empty($filedir)) {
  772. $file_list = dol_dir_list($filedir, 'files', 0, '', '(\.meta|_preview.*.*\.png)$', 'date', SORT_DESC);
  773. }
  774. if (is_array($file_list)) {
  775. // Defined relative dir to DOL_DATA_ROOT
  776. $relativedir = '';
  777. if ($filedir) {
  778. $relativedir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $filedir);
  779. $relativedir = preg_replace('/^[\\/]/', '', $relativedir);
  780. }
  781. // Get list of files stored into database for same relative directory
  782. if ($relativedir) {
  783. completeFileArrayWithDatabaseInfo($file_list, $relativedir);
  784. //var_dump($sortfield.' - '.$sortorder);
  785. if (!empty($sortfield) && !empty($sortorder)) { // If $sortfield is for example 'position_name', we will sort on the property 'position_name' (that is concat of position+name)
  786. $file_list = dol_sort_array($file_list, $sortfield, $sortorder);
  787. }
  788. }
  789. $relativepath = dol_sanitizeFileName($objp->ref).'/'.dol_sanitizeFileName($objp->ref).'.pdf';
  790. print $formfile->showPreview($file_list, $propal_static->element, $relativepath, 0);
  791. }
  792. // $filename = dol_sanitizeFileName($objp->ref);
  793. // $filedir = $conf->propal->multidir_output[$objp->entity].'/'.dol_sanitizeFileName($objp->ref);
  794. // $urlsource = '/comm/propal/card.php?id='.$objp->cid;
  795. // print $formfile->getDocumentsLink($propal_static->element, $filename, $filedir);
  796. if (($db->jdate($objp->date_limit) < ($now - $conf->propal->cloture->warning_delay)) && $objp->fk_statut == $propal_static::STATUS_VALIDATED) {
  797. print " ".img_warning();
  798. }
  799. print '</td><td class="right" width="80px">'.dol_print_date($db->jdate($objp->dp), 'day')."</td>\n";
  800. print '<td class="right" style="min-width: 60px">'.price($objp->total_ht).'</td>';
  801. print '<td class="right" style="min-width: 60px" class="nowrap">'.$propal_static->LibStatut($objp->fk_statut, 5).'</td></tr>';
  802. $i++;
  803. }
  804. $db->free($resql);
  805. if ($num > 0) {
  806. print "</table>";
  807. print '</div>';
  808. }
  809. } else {
  810. dol_print_error($db);
  811. }
  812. }
  813. /*
  814. * Latest orders
  815. */
  816. if (isModEnabled('commande') && $user->hasRight('commande', 'lire')) {
  817. $param ="";
  818. $sql = "SELECT s.nom, s.rowid";
  819. $sql .= ", c.rowid as cid, c.entity, c.total_ht";
  820. $sql .= ", c.total_tva";
  821. $sql .= ", c.total_ttc";
  822. $sql .= ", c.ref, c.ref_client, c.fk_statut, c.facture";
  823. $sql .= ", c.date_commande as dc";
  824. $sql .= ", c.facture as billed";
  825. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande as c";
  826. $sql .= " WHERE c.fk_soc = s.rowid ";
  827. $sql .= " AND s.rowid = ".((int) $object->id);
  828. $sql .= " AND c.entity IN (".getEntity('commande').')';
  829. $sql .= " ORDER BY c.date_commande DESC";
  830. $resql = $db->query($sql);
  831. if ($resql) {
  832. $commande_static = new Commande($db);
  833. $num = $db->num_rows($resql);
  834. if ($num > 0) {
  835. // Check if there are orders billable
  836. $sql2 = 'SELECT s.nom, s.rowid as socid, s.client, c.rowid, c.ref, c.total_ht, c.ref_client,';
  837. $sql2 .= ' c.date_valid, c.date_commande, c.date_livraison, c.fk_statut, c.facture as billed';
  838. $sql2 .= ' FROM '.MAIN_DB_PREFIX.'societe as s';
  839. $sql2 .= ', '.MAIN_DB_PREFIX.'commande as c';
  840. $sql2 .= ' WHERE c.fk_soc = s.rowid';
  841. $sql2 .= ' AND s.rowid = '.((int) $object->id);
  842. // Show orders with status validated, shipping started and delivered (well any order we can bill)
  843. $sql2 .= " AND ((c.fk_statut IN (1,2)) OR (c.fk_statut = 3 AND c.facture = 0))";
  844. $resql2 = $db->query($sql2);
  845. $orders2invoice = $db->num_rows($resql2);
  846. $db->free($resql2);
  847. print '<div class="div-table-responsive-no-min">';
  848. print '<table class="noborder centpercent lastrecordtable">';
  849. print '<tr class="liste_titre">';
  850. 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 marginleftonlyshort">'.$num.'</span></a></td>';
  851. 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>';
  852. print '</tr></table></td>';
  853. print '</tr>';
  854. }
  855. $i = 0;
  856. while ($i < $num && $i < $MAXLIST) {
  857. $objp = $db->fetch_object($resql);
  858. $commande_static->id = $objp->cid;
  859. $commande_static->ref = $objp->ref;
  860. $commande_static->ref_client = $objp->ref_client;
  861. $commande_static->total_ht = $objp->total_ht;
  862. $commande_static->total_tva = $objp->total_tva;
  863. $commande_static->total_ttc = $objp->total_ttc;
  864. $commande_static->billed = $objp->billed;
  865. print '<tr class="oddeven">';
  866. print '<td class="nowraponall">';
  867. print $commande_static->getNomUrl(1);
  868. // Preview
  869. $filedir = $conf->commande->multidir_output[$objp->entity].'/'.dol_sanitizeFileName($objp->ref);
  870. $file_list = null;
  871. if (!empty($filedir)) {
  872. $file_list = dol_dir_list($filedir, 'files', 0, '', '(\.meta|_preview.*.*\.png)$', 'date', SORT_DESC);
  873. }
  874. if (is_array($file_list)) {
  875. // Defined relative dir to DOL_DATA_ROOT
  876. $relativedir = '';
  877. if ($filedir) {
  878. $relativedir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $filedir);
  879. $relativedir = preg_replace('/^[\\/]/', '', $relativedir);
  880. }
  881. // Get list of files stored into database for same relative directory
  882. if ($relativedir) {
  883. completeFileArrayWithDatabaseInfo($file_list, $relativedir);
  884. //var_dump($sortfield.' - '.$sortorder);
  885. if (!empty($sortfield) && !empty($sortorder)) { // If $sortfield is for example 'position_name', we will sort on the property 'position_name' (that is concat of position+name)
  886. $file_list = dol_sort_array($file_list, $sortfield, $sortorder);
  887. }
  888. }
  889. $relativepath = dol_sanitizeFileName($objp->ref).'/'.dol_sanitizeFileName($objp->ref).'.pdf';
  890. print $formfile->showPreview($file_list, $commande_static->element, $relativepath, 0, $param);
  891. }
  892. // $filename = dol_sanitizeFileName($objp->ref);
  893. // $filedir = $conf->order->multidir_output[$objp->entity].'/'.dol_sanitizeFileName($objp->ref);
  894. // $urlsource = '/commande/card.php?id='.$objp->cid;
  895. // print $formfile->getDocumentsLink($commande_static->element, $filename, $filedir);
  896. print '</td>';
  897. print '<td class="right" width="80px">'.dol_print_date($db->jdate($objp->dc), 'day')."</td>\n";
  898. print '<td class="right" style="min-width: 60px">'.price($objp->total_ht).'</td>';
  899. print '<td class="right" style="min-width: 60px" class="nowrap">'.$commande_static->LibStatut($objp->fk_statut, $objp->facture, 5).'</td></tr>';
  900. $i++;
  901. }
  902. $db->free($resql);
  903. if ($num > 0) {
  904. print "</table>";
  905. print '</div>';
  906. }
  907. } else {
  908. dol_print_error($db);
  909. }
  910. }
  911. /*
  912. * Latest shipments
  913. */
  914. if (isModEnabled("expedition") && $user->hasRight('expedition', 'lire')) {
  915. $sql = 'SELECT e.rowid as id';
  916. $sql .= ', e.ref, e.entity';
  917. $sql .= ', e.date_creation';
  918. $sql .= ', e.fk_statut as statut';
  919. $sql .= ', s.nom';
  920. $sql .= ', s.rowid as socid';
  921. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."expedition as e";
  922. $sql .= " WHERE e.fk_soc = s.rowid AND s.rowid = ".((int) $object->id);
  923. $sql .= " AND e.entity IN (".getEntity('expedition').")";
  924. $sql .= ' GROUP BY e.rowid';
  925. $sql .= ', e.ref, e.entity';
  926. $sql .= ', e.date_creation';
  927. $sql .= ', e.fk_statut';
  928. $sql .= ', s.nom';
  929. $sql .= ', s.rowid';
  930. $sql .= " ORDER BY e.date_creation DESC";
  931. $resql = $db->query($sql);
  932. if ($resql) {
  933. $sendingstatic = new Expedition($db);
  934. $num = $db->num_rows($resql);
  935. if ($num > 0) {
  936. print '<div class="div-table-responsive-no-min">';
  937. print '<table class="noborder centpercent lastrecordtable">';
  938. print '<tr class="liste_titre">';
  939. 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 marginleftonlyshort">'.$num.'</span></a></td>';
  940. 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>';
  941. print '</tr></table></td>';
  942. print '</tr>';
  943. }
  944. $i = 0;
  945. while ($i < $num && $i < $MAXLIST) {
  946. $objp = $db->fetch_object($resql);
  947. $sendingstatic->id = $objp->id;
  948. $sendingstatic->ref = $objp->ref;
  949. print '<tr class="oddeven">';
  950. print '<td class="nowraponall">';
  951. print $sendingstatic->getNomUrl(1);
  952. // Preview
  953. $filedir = $conf->expedition->multidir_output[$objp->entity].'/'.dol_sanitizeFileName($objp->ref);
  954. $file_list = null;
  955. if (!empty($filedir)) {
  956. $file_list = dol_dir_list($filedir, 'files', 0, '', '(\.meta|_preview.*.*\.png)$', 'date', SORT_DESC);
  957. }
  958. if (is_array($file_list)) {
  959. // Defined relative dir to DOL_DATA_ROOT
  960. $relativedir = '';
  961. if ($filedir) {
  962. $relativedir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $filedir);
  963. $relativedir = preg_replace('/^[\\/]/', '', $relativedir);
  964. }
  965. // Get list of files stored into database for same relative directory
  966. if ($relativedir) {
  967. completeFileArrayWithDatabaseInfo($file_list, $relativedir);
  968. //var_dump($sortfield.' - '.$sortorder);
  969. if (!empty($sortfield) && !empty($sortorder)) { // If $sortfield is for example 'position_name', we will sort on the property 'position_name' (that is concat of position+name)
  970. $file_list = dol_sort_array($file_list, $sortfield, $sortorder);
  971. }
  972. }
  973. $relativepath = dol_sanitizeFileName($objp->ref).'/'.dol_sanitizeFileName($objp->ref).'.pdf';
  974. print $formfile->showPreview($file_list, $sendingstatic->table_element, $relativepath, 0, $param);
  975. }
  976. // $filename = dol_sanitizeFileName($objp->ref);
  977. // $filedir = $conf->expedition->multidir_output[$objp->entity].'/'.dol_sanitizeFileName($objp->ref);
  978. // $urlsource = '/expedition/card.php?id='.$objp->cid;
  979. // print $formfile->getDocumentsLink($sendingstatic->element, $filename, $filedir);
  980. print '</td>';
  981. if ($objp->date_creation > 0) {
  982. print '<td class="right" width="80px">'.dol_print_date($db->jdate($objp->date_creation), 'day').'</td>';
  983. } else {
  984. print '<td class="right"><b>!!!</b></td>';
  985. }
  986. print '<td class="nowrap right" width="100" >'.$sendingstatic->LibStatut($objp->statut, 5).'</td>';
  987. print "</tr>\n";
  988. $i++;
  989. }
  990. $db->free($resql);
  991. if ($num > 0) {
  992. print "</table>";
  993. print '</div>';
  994. }
  995. } else {
  996. dol_print_error($db);
  997. }
  998. }
  999. /*
  1000. * Latest contracts
  1001. */
  1002. if (isModEnabled('contrat') && $user->hasRight('contrat', 'lire')) {
  1003. $sql = "SELECT s.nom, s.rowid, c.rowid as id, c.ref as ref, c.statut as contract_status, c.datec as dc, c.date_contrat as dcon, c.ref_customer as refcus, c.ref_supplier as refsup, c.entity,";
  1004. $sql .= " c.last_main_doc, c.model_pdf";
  1005. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."contrat as c";
  1006. $sql .= " WHERE c.fk_soc = s.rowid ";
  1007. $sql .= " AND s.rowid = ".((int) $object->id);
  1008. $sql .= " AND c.entity IN (".getEntity('contract').")";
  1009. $sql .= " ORDER BY c.datec DESC";
  1010. $resql = $db->query($sql);
  1011. if ($resql) {
  1012. $contrat = new Contrat($db);
  1013. $num = $db->num_rows($resql);
  1014. if ($num > 0) {
  1015. print '<div class="div-table-responsive-no-min">';
  1016. print '<table class="noborder centpercent lastrecordtable">';
  1017. print '<tr class="liste_titre">';
  1018. print '<td colspan="5"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("LastContracts", ($num <= $MAXLIST ? "" : $MAXLIST)).'</td>';
  1019. print '<td class="right"><a class="notasortlink" href="'.DOL_URL_ROOT.'/contrat/list.php?socid='.$object->id.'">'.$langs->trans("AllContracts").'<span class="badge marginleftonlyshort">'.$num.'</span></a></td>';
  1020. //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>';
  1021. print '</tr></table></td>';
  1022. print '</tr>';
  1023. }
  1024. $i = 0;
  1025. while ($i < $num && $i < $MAXLIST) {
  1026. $objp = $db->fetch_object($resql);
  1027. $contrat->id = $objp->id;
  1028. $contrat->ref = $objp->ref ? $objp->ref : $objp->id;
  1029. $contrat->ref_customer = $objp->refcus;
  1030. $contrat->ref_supplier = $objp->refsup;
  1031. $contrat->statut = $objp->contract_status;
  1032. $contrat->last_main_doc = $objp->last_main_doc;
  1033. $contrat->model_pdf = $objp->model_pdf;
  1034. $contrat->fetch_lines();
  1035. $late = '';
  1036. foreach ($contrat->lines as $line) {
  1037. if ($contrat->statut == Contrat::STATUS_VALIDATED && $line->statut == ContratLigne::STATUS_OPEN) {
  1038. if (((!empty($line->date_end) ? $line->date_end : 0) + $conf->contrat->services->expires->warning_delay) < $now) {
  1039. $late = img_warning($langs->trans("Late"));
  1040. }
  1041. }
  1042. }
  1043. print '<tr class="oddeven">';
  1044. print '<td class="nowraponall">';
  1045. print $contrat->getNomUrl(1, 12);
  1046. if (!empty($contrat->model_pdf)) {
  1047. // Preview
  1048. $filedir = $conf->contrat->multidir_output[$objp->entity].'/'.dol_sanitizeFileName($objp->ref);
  1049. $file_list = null;
  1050. if (!empty($filedir)) {
  1051. $file_list = dol_dir_list($filedir, 'files', 0, '', '(\.meta|_preview.*.*\.png)$', 'date', SORT_DESC);
  1052. }
  1053. if (is_array($file_list)) {
  1054. // Defined relative dir to DOL_DATA_ROOT
  1055. $relativedir = '';
  1056. if ($filedir) {
  1057. $relativedir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $filedir);
  1058. $relativedir = preg_replace('/^[\\/]/', '', $relativedir);
  1059. }
  1060. // Get list of files stored into database for same relative directory
  1061. if ($relativedir) {
  1062. completeFileArrayWithDatabaseInfo($file_list, $relativedir);
  1063. //var_dump($sortfield.' - '.$sortorder);
  1064. if (!empty($sortfield) && !empty($sortorder)) { // If $sortfield is for example 'position_name', we will sort on the property 'position_name' (that is concat of position+name)
  1065. $file_list = dol_sort_array($file_list, $sortfield, $sortorder);
  1066. }
  1067. }
  1068. $relativepath = dol_sanitizeFileName($objp->ref).'/'.dol_sanitizeFileName($objp->ref).'.pdf';
  1069. print $formfile->showPreview($file_list, $contrat->element, $relativepath, 0);
  1070. }
  1071. }
  1072. // $filename = dol_sanitizeFileName($objp->ref);
  1073. // $filedir = $conf->contrat->multidir_output[$objp->entity].'/'.dol_sanitizeFileName($objp->ref);
  1074. // $urlsource = '/contrat/card.php?id='.$objp->cid;
  1075. // print $formfile->getDocumentsLink($contrat->element, $filename, $filedir);
  1076. print $late;
  1077. print "</td>\n";
  1078. print '<td class="nowrap">'.dol_trunc($objp->refsup, 12)."</td>\n";
  1079. //print '<td class="right" width="80px"><span title="'.$langs->trans("DateCreation").'">'.dol_print_date($db->jdate($objp->dc), 'day')."</span></td>\n";
  1080. print '<td class="right" width="80px"><span title="'.$langs->trans("DateContract").'">'.dol_print_date($db->jdate($objp->dcon), 'day')."</span></td>\n";
  1081. print '<td width="20">&nbsp;</td>';
  1082. print '<td class="nowraponall right">';
  1083. print $contrat->getLibStatut(4);
  1084. print "</td>\n";
  1085. print '</tr>';
  1086. $i++;
  1087. }
  1088. $db->free($resql);
  1089. if ($num > 0) {
  1090. print "</table>";
  1091. print '</div>';
  1092. }
  1093. } else {
  1094. dol_print_error($db);
  1095. }
  1096. }
  1097. /*
  1098. * Latest interventions
  1099. */
  1100. if (isModEnabled('ficheinter') && $user->hasRight('ficheinter', 'lire')) {
  1101. $sql = "SELECT s.nom, s.rowid, f.rowid as id, f.ref, f.fk_statut, f.duree as duration, f.datei as startdate, f.entity";
  1102. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."fichinter as f";
  1103. $sql .= " WHERE f.fk_soc = s.rowid";
  1104. $sql .= " AND s.rowid = ".((int) $object->id);
  1105. $sql .= " AND f.entity IN (".getEntity('intervention').")";
  1106. $sql .= " ORDER BY f.tms DESC";
  1107. $resql = $db->query($sql);
  1108. if ($resql) {
  1109. $fichinter_static = new Fichinter($db);
  1110. $num = $db->num_rows($resql);
  1111. if ($num > 0) {
  1112. print '<div class="div-table-responsive-no-min">';
  1113. print '<table class="noborder centpercent lastrecordtable">';
  1114. print '<tr class="liste_titre">';
  1115. 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 marginleftonlyshort">'.$num.'</span></td>';
  1116. 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>';
  1117. print '</tr></table></td>';
  1118. print '</tr>';
  1119. }
  1120. $i = 0;
  1121. while ($i < $num && $i < $MAXLIST) {
  1122. $objp = $db->fetch_object($resql);
  1123. $fichinter_static->id = $objp->id;
  1124. $fichinter_static->ref = $objp->ref;
  1125. $fichinter_static->statut = $objp->fk_statut;
  1126. print '<tr class="oddeven">';
  1127. print '<td class="nowraponall">';
  1128. print $fichinter_static->getNomUrl(1);
  1129. // Preview
  1130. $filedir = $conf->ficheinter->multidir_output[$objp->entity].'/'.dol_sanitizeFileName($objp->ref);
  1131. $file_list = null;
  1132. if (!empty($filedir)) {
  1133. $file_list = dol_dir_list($filedir, 'files', 0, '', '(\.meta|_preview.*.*\.png)$', 'date', SORT_DESC);
  1134. }
  1135. if (is_array($file_list)) {
  1136. // Defined relative dir to DOL_DATA_ROOT
  1137. $relativedir = '';
  1138. if ($filedir) {
  1139. $relativedir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $filedir);
  1140. $relativedir = preg_replace('/^[\\/]/', '', $relativedir);
  1141. }
  1142. // Get list of files stored into database for same relative directory
  1143. if ($relativedir) {
  1144. completeFileArrayWithDatabaseInfo($file_list, $relativedir);
  1145. //var_dump($sortfield.' - '.$sortorder);
  1146. if (!empty($sortfield) && !empty($sortorder)) { // If $sortfield is for example 'position_name', we will sort on the property 'position_name' (that is concat of position+name)
  1147. $file_list = dol_sort_array($file_list, $sortfield, $sortorder);
  1148. }
  1149. }
  1150. $relativepath = dol_sanitizeFileName($objp->ref).'/'.dol_sanitizeFileName($objp->ref).'.pdf';
  1151. print $formfile->showPreview($file_list, $fichinter_static->element, $relativepath, 0);
  1152. }
  1153. // $filename = dol_sanitizeFileName($objp->ref);
  1154. // $filedir = getMultidirOutput($fichinter_static).'/'.dol_sanitizeFileName($objp->ref);
  1155. // $urlsource = '/fichinter/card.php?id='.$objp->cid;
  1156. // print $formfile->getDocumentsLink($fichinter_static->element, $filename, $filedir);
  1157. print '</td>'."\n";
  1158. //print '<td class="right" width="80px">'.dol_print_date($db->jdate($objp->startdate)).'</td>'."\n";
  1159. print '<td class="right" style="min-width: 60px">'.convertSecondToTime($objp->duration).'</td>'."\n";
  1160. print '<td class="nowrap right" style="min-width: 60px">'.$fichinter_static->getLibStatut(5).'</td>'."\n";
  1161. print '</tr>';
  1162. $i++;
  1163. }
  1164. $db->free($resql);
  1165. if ($num > 0) {
  1166. print "</table>";
  1167. print '</div>';
  1168. }
  1169. } else {
  1170. dol_print_error($db);
  1171. }
  1172. }
  1173. /*
  1174. * Latest invoices templates
  1175. */
  1176. if (isModEnabled('facture') && $user->hasRight('facture', 'lire')) {
  1177. $sql = 'SELECT f.rowid as id, f.titre as ref';
  1178. $sql .= ', f.total_ht';
  1179. $sql .= ', f.total_tva';
  1180. $sql .= ', f.total_ttc';
  1181. $sql .= ', f.datec as dc';
  1182. $sql .= ', f.date_last_gen, f.date_when';
  1183. $sql .= ', f.frequency';
  1184. $sql .= ', f.unit_frequency';
  1185. $sql .= ', f.suspended as suspended';
  1186. $sql .= ', s.nom, s.rowid as socid';
  1187. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture_rec as f";
  1188. $sql .= " WHERE f.fk_soc = s.rowid AND s.rowid = ".((int) $object->id);
  1189. $sql .= " AND f.entity IN (".getEntity('invoice').")";
  1190. $sql .= ' GROUP BY f.rowid, f.titre, f.total_ht, f.total_tva, f.total_ttc,';
  1191. $sql .= ' f.date_last_gen, f.datec, f.frequency, f.unit_frequency,';
  1192. $sql .= ' f.suspended, f.date_when,';
  1193. $sql .= ' s.nom, s.rowid';
  1194. $sql .= " ORDER BY f.date_last_gen, f.datec DESC";
  1195. $resql = $db->query($sql);
  1196. if ($resql) {
  1197. $invoicetemplate = new FactureRec($db);
  1198. $num = $db->num_rows($resql);
  1199. if ($num > 0) {
  1200. print '<div class="div-table-responsive-no-min">';
  1201. print '<table class="noborder centpercent lastrecordtable">';
  1202. print '<tr class="liste_titre">';
  1203. 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/invoicetemplate_list.php?socid='.$object->id.'">'.$langs->trans("AllCustomerTemplateInvoices").'<span class="badge marginleftonlyshort">'.$num.'</span></a></td>';
  1204. print '</tr></table></td>';
  1205. print '</tr>';
  1206. }
  1207. $i = 0;
  1208. while ($i < $num && $i < $MAXLIST) {
  1209. $objp = $db->fetch_object($resql);
  1210. $invoicetemplate->id = $objp->id;
  1211. $invoicetemplate->ref = $objp->ref;
  1212. $invoicetemplate->suspended = $objp->suspended;
  1213. $invoicetemplate->frequency = $objp->frequency;
  1214. $invoicetemplate->unit_frequency = $objp->unit_frequency;
  1215. $invoicetemplate->total_ht = $objp->total_ht;
  1216. $invoicetemplate->total_tva = $objp->total_tva;
  1217. $invoicetemplate->total_ttc = $objp->total_ttc;
  1218. $invoicetemplate->date_last_gen = $objp->date_last_gen;
  1219. $invoicetemplate->date_when = $objp->date_when;
  1220. print '<tr class="oddeven">';
  1221. print '<td class="tdoverflowmax250">';
  1222. print $invoicetemplate->getNomUrl(1);
  1223. print '</td>';
  1224. if ($objp->frequency && $objp->date_last_gen > 0) {
  1225. print '<td class="right" width="80px">'.dol_print_date($db->jdate($objp->date_last_gen), 'day').'</td>';
  1226. } else {
  1227. if ($objp->dc > 0) {
  1228. print '<td class="right" width="80px">'.dol_print_date($db->jdate($objp->dc), 'day').'</td>';
  1229. } else {
  1230. print '<td class="right"><b>!!!</b></td>';
  1231. }
  1232. }
  1233. print '<td class="right" style="min-width: 60px">';
  1234. print price($objp->total_ht);
  1235. print '</td>';
  1236. if (getDolGlobalString('MAIN_SHOW_PRICE_WITH_TAX_IN_SUMMARIES')) {
  1237. print '<td class="right" style="min-width: 60px">';
  1238. print price($objp->total_ttc);
  1239. print '</td>';
  1240. }
  1241. print '<td class="nowrap right" style="min-width: 60px">';
  1242. print $langs->trans('FrequencyPer_'.$invoicetemplate->unit_frequency, $invoicetemplate->frequency).' - ';
  1243. print($invoicetemplate->LibStatut($invoicetemplate->frequency, $invoicetemplate->suspended, 5, 0));
  1244. print '</td>';
  1245. print "</tr>\n";
  1246. $i++;
  1247. }
  1248. $db->free($resql);
  1249. if ($num > 0) {
  1250. print "</table>";
  1251. print '</div>';
  1252. }
  1253. } else {
  1254. dol_print_error($db);
  1255. }
  1256. }
  1257. /*
  1258. * Latest invoices
  1259. */
  1260. if (isModEnabled('facture') && $user->hasRight('facture', 'lire')) {
  1261. $sql = 'SELECT f.rowid as facid, f.ref, f.type';
  1262. $sql .= ', f.total_ht';
  1263. $sql .= ', f.total_tva';
  1264. $sql .= ', f.total_ttc';
  1265. $sql .= ', f.entity';
  1266. $sql .= ', f.datef as df, f.date_lim_reglement as dl, f.datec as dc, f.paye as paye, f.fk_statut as status';
  1267. $sql .= ', s.nom, s.rowid as socid';
  1268. $sql .= ', SUM(pf.amount) as am';
  1269. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f";
  1270. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON f.rowid=pf.fk_facture';
  1271. $sql .= " WHERE f.fk_soc = s.rowid AND s.rowid = ".((int) $object->id);
  1272. $sql .= " AND f.entity IN (".getEntity('invoice').")";
  1273. $sql .= ' GROUP BY f.rowid, f.ref, f.type, f.total_ht, f.total_tva, f.total_ttc,';
  1274. $sql .= ' f.entity, f.datef, f.date_lim_reglement, f.datec, f.paye, f.fk_statut,';
  1275. $sql .= ' s.nom, s.rowid';
  1276. $sql .= " ORDER BY f.datef DESC, f.datec DESC";
  1277. $resql = $db->query($sql);
  1278. if ($resql) {
  1279. $facturestatic = new Facture($db);
  1280. $num = $db->num_rows($resql);
  1281. if ($num > 0) {
  1282. print '<div class="div-table-responsive-no-min">';
  1283. print '<table class="noborder centpercent lastrecordtable">';
  1284. print '<tr class="liste_titre">';
  1285. print '<td colspan="5"><table class="centpercent 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 marginleftonlyshort">'.$num.'</span></a></td>';
  1286. 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>';
  1287. print '</tr></table></td>';
  1288. print '</tr>';
  1289. }
  1290. $i = 0;
  1291. while ($i < $num && $i < $MAXLIST) {
  1292. $objp = $db->fetch_object($resql);
  1293. $facturestatic->id = $objp->facid;
  1294. $facturestatic->ref = $objp->ref;
  1295. $facturestatic->type = $objp->type;
  1296. $facturestatic->total_ht = $objp->total_ht;
  1297. $facturestatic->total_tva = $objp->total_tva;
  1298. $facturestatic->total_ttc = $objp->total_ttc;
  1299. $facturestatic->statut = $objp->status;
  1300. $facturestatic->status = $objp->status;
  1301. $facturestatic->paye = $objp->paye;
  1302. $facturestatic->alreadypaid = $objp->am;
  1303. $facturestatic->date = $db->jdate($objp->df);
  1304. $facturestatic->date_lim_reglement = $db->jdate($objp->dl);
  1305. print '<tr class="oddeven">';
  1306. print '<td class="nowraponall">';
  1307. print $facturestatic->getNomUrl(1);
  1308. // Preview
  1309. $filedir = $conf->facture->multidir_output[$objp->entity].'/'.dol_sanitizeFileName($objp->ref);
  1310. $file_list = null;
  1311. if (!empty($filedir)) {
  1312. $file_list = dol_dir_list($filedir, 'files', 0, '', '(\.meta|_preview.*.*\.png)$', 'date', SORT_DESC);
  1313. }
  1314. if (is_array($file_list)) {
  1315. // Defined relative dir to DOL_DATA_ROOT
  1316. $relativedir = '';
  1317. if ($filedir) {
  1318. $relativedir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $filedir);
  1319. $relativedir = preg_replace('/^[\\/]/', '', $relativedir);
  1320. }
  1321. // Get list of files stored into database for same relative directory
  1322. if ($relativedir) {
  1323. completeFileArrayWithDatabaseInfo($file_list, $relativedir);
  1324. //var_dump($sortfield.' - '.$sortorder);
  1325. if (!empty($sortfield) && !empty($sortorder)) { // If $sortfield is for example 'position_name', we will sort on the property 'position_name' (that is concat of position+name)
  1326. $file_list = dol_sort_array($file_list, $sortfield, $sortorder);
  1327. }
  1328. }
  1329. $relativepath = dol_sanitizeFileName($objp->ref).'/'.dol_sanitizeFileName($objp->ref).'.pdf';
  1330. print $formfile->showPreview($file_list, $facturestatic->element, $relativepath, 0);
  1331. }
  1332. // $filename = dol_sanitizeFileName($objp->ref);
  1333. // $filedir = $conf->facture->multidir_output[$objp->entity].'/'.dol_sanitizeFileName($objp->ref);
  1334. // $urlsource = '/compta/facture/card.php?id='.$objp->cid;
  1335. //print $formfile->getDocumentsLink($facturestatic->element, $filename, $filedir);
  1336. print '</td>';
  1337. if ($objp->df > 0) {
  1338. print '<td width="80px" title="'.dol_escape_htmltag($langs->trans('DateInvoice')).'">'.dol_print_date($db->jdate($objp->df), 'day').'</td>';
  1339. } else {
  1340. print '<td><b>!!!</b></td>';
  1341. }
  1342. if ($objp->dl > 0) {
  1343. print '<td width="80px" title="'.dol_escape_htmltag($langs->trans('DateMaxPayment')).'">'.dol_print_date($db->jdate($objp->dl), 'day').'</td>';
  1344. } else {
  1345. print '<td><b>!!!</b></td>';
  1346. }
  1347. print '<td class="right" style="min-width: 60px">';
  1348. print price($objp->total_ht);
  1349. print '</td>';
  1350. if (getDolGlobalString('MAIN_SHOW_PRICE_WITH_TAX_IN_SUMMARIES')) {
  1351. print '<td class="right" style="min-width: 60px">';
  1352. print price($objp->total_ttc);
  1353. print '</td>';
  1354. }
  1355. print '<td class="nowrap right" style="min-width: 60px">'.($facturestatic->LibStatut($objp->paye, $objp->status, 5, $objp->am)).'</td>';
  1356. print "</tr>\n";
  1357. $i++;
  1358. }
  1359. $db->free($resql);
  1360. if ($num > 0) {
  1361. print "</table>";
  1362. print '</div>';
  1363. }
  1364. } else {
  1365. dol_print_error($db);
  1366. }
  1367. }
  1368. // Allow external modules to add their own shortlist of recent objects
  1369. $parameters = array();
  1370. $reshook = $hookmanager->executeHooks('addMoreRecentObjects', $parameters, $object, $action);
  1371. if ($reshook < 0) {
  1372. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  1373. } else {
  1374. print $hookmanager->resPrint;
  1375. }
  1376. print '</div></div>';
  1377. print '<div class="clearboth"></div>';
  1378. print dol_get_fiche_end();
  1379. /*
  1380. * Action bar
  1381. */
  1382. print '<div class="tabsAction">';
  1383. $parameters = array();
  1384. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
  1385. if (empty($reshook)) {
  1386. if ($object->status != 1) {
  1387. print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" title="'.dol_escape_js($langs->trans("ThirdPartyIsClosed")).'" href="#">'.$langs->trans("ThirdPartyIsClosed").'</a></div>';
  1388. }
  1389. if (isModEnabled("propal") && $user->hasRight('propal', 'creer') && $object->status == 1) {
  1390. $langs->load("propal");
  1391. 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>';
  1392. }
  1393. if (isModEnabled('commande') && $user->hasRight('commande', 'creer') && $object->status == 1) {
  1394. $langs->load("orders");
  1395. 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>';
  1396. }
  1397. if ($user->hasRight('contrat', 'creer') && $object->status == 1) {
  1398. $langs->load("contracts");
  1399. 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>';
  1400. }
  1401. if (isModEnabled('ficheinter') && $user->hasRight('ficheinter', 'creer') && $object->status == 1) {
  1402. $langs->load("fichinter");
  1403. 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>';
  1404. }
  1405. // Add invoice
  1406. if ($user->socid == 0) {
  1407. if (isModEnabled('deplacement') && $object->status == 1) {
  1408. $langs->load("trips");
  1409. 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>';
  1410. }
  1411. if (isModEnabled('facture') && $object->status == 1) {
  1412. if (!$user->hasRight('facture', 'creer')) {
  1413. $langs->load("bills");
  1414. print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" title="'.dol_escape_js($langs->trans("NotAllowed")).'" href="#">'.$langs->trans("AddBill").'</a></div>';
  1415. } else {
  1416. $langs->loadLangs(array("orders", "bills"));
  1417. if (isModEnabled('commande')) {
  1418. if ($object->client != 0 && $object->client != 2) {
  1419. if (!empty($orders2invoice) && $orders2invoice > 0) {
  1420. print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/commande/list.php?socid='.$object->id.'&search_billed=0&autoselectall=1">'.$langs->trans("CreateInvoiceForThisCustomer").'</a></div>';
  1421. } else {
  1422. print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" title="'.dol_escape_js($langs->trans("NoOrdersToInvoice")).'" href="#">'.$langs->trans("CreateInvoiceForThisCustomer").'</a></div>';
  1423. }
  1424. } else {
  1425. print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" title="'.dol_escape_js($langs->trans("ThirdPartyMustBeEditAsCustomer")).'" href="#">'.$langs->trans("CreateInvoiceForThisCustomer").'</a></div>';
  1426. }
  1427. }
  1428. if ($object->client != 0 && $object->client != 2) {
  1429. 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>';
  1430. } else {
  1431. print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" title="'.dol_escape_js($langs->trans("ThirdPartyMustBeEditAsCustomer")).'" href="#">'.$langs->trans("AddBill").'</a></div>';
  1432. }
  1433. }
  1434. }
  1435. }
  1436. // Add action
  1437. if (isModEnabled('agenda') && getDolGlobalString('MAIN_REPEATTASKONEACHTAB') && $object->status == 1) {
  1438. if ($user->hasRight('agenda', 'myactions', 'create')) {
  1439. 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>';
  1440. } else {
  1441. print '<div class="inline-block divButAction"><a class="butAction" title="'.dol_escape_js($langs->trans("NotAllowed")).'" href="#">'.$langs->trans("AddAction").'</a></div>';
  1442. }
  1443. }
  1444. }
  1445. print '</div>';
  1446. if (getDolGlobalString('MAIN_DUPLICATE_CONTACTS_TAB_ON_CUSTOMER_CARD')) {
  1447. // List of contacts
  1448. show_contacts($conf, $langs, $db, $object, $_SERVER["PHP_SELF"].'?socid='.$object->id);
  1449. }
  1450. if (getDolGlobalString('MAIN_REPEATTASKONEACHTAB')) {
  1451. print load_fiche_titre($langs->trans("ActionsOnCompany"), '', '');
  1452. // List of todo actions
  1453. show_actions_todo($conf, $langs, $db, $object);
  1454. // List of done actions
  1455. show_actions_done($conf, $langs, $db, $object);
  1456. }
  1457. } else {
  1458. $langs->load("errors");
  1459. print $langs->trans('ErrorRecordNotFound');
  1460. }
  1461. // End of page
  1462. llxFooter();
  1463. $db->close();