card.php 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665
  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, $user);
  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 (getDolGlobalString($keyforlabel)) {
  477. print ' - '.$langs->trans(getDolGlobalString($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.'"><span class="hideonsmartphone">'.$langs->trans("AllPropals").'</span><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; // deprecated
  764. $propal_static->ref_customer = $objp->ref_client;
  765. $propal_static->total_ht = $objp->total_ht;
  766. $propal_static->total_tva = $objp->total_tva;
  767. $propal_static->total_ttc = $objp->total_ttc;
  768. print $propal_static->getNomUrl(1);
  769. // Preview
  770. $filedir = $conf->propal->multidir_output[$objp->entity].'/'.dol_sanitizeFileName($objp->ref);
  771. $file_list = null;
  772. if (!empty($filedir)) {
  773. $file_list = dol_dir_list($filedir, 'files', 0, '', '(\.meta|_preview.*.*\.png)$', 'date', SORT_DESC);
  774. }
  775. if (is_array($file_list)) {
  776. // Defined relative dir to DOL_DATA_ROOT
  777. $relativedir = '';
  778. if ($filedir) {
  779. $relativedir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $filedir);
  780. $relativedir = preg_replace('/^[\\/]/', '', $relativedir);
  781. }
  782. // Get list of files stored into database for same relative directory
  783. if ($relativedir) {
  784. completeFileArrayWithDatabaseInfo($file_list, $relativedir);
  785. //var_dump($sortfield.' - '.$sortorder);
  786. 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)
  787. $file_list = dol_sort_array($file_list, $sortfield, $sortorder);
  788. }
  789. }
  790. $relativepath = dol_sanitizeFileName($objp->ref).'/'.dol_sanitizeFileName($objp->ref).'.pdf';
  791. print $formfile->showPreview($file_list, $propal_static->element, $relativepath, 0);
  792. }
  793. // $filename = dol_sanitizeFileName($objp->ref);
  794. // $filedir = $conf->propal->multidir_output[$objp->entity].'/'.dol_sanitizeFileName($objp->ref);
  795. // $urlsource = '/comm/propal/card.php?id='.$objp->cid;
  796. // print $formfile->getDocumentsLink($propal_static->element, $filename, $filedir);
  797. if (($db->jdate($objp->date_limit) < ($now - $conf->propal->cloture->warning_delay)) && $objp->fk_statut == $propal_static::STATUS_VALIDATED) {
  798. print " ".img_warning();
  799. }
  800. print '</td><td class="right" width="80px">'.dol_print_date($db->jdate($objp->dp), 'day')."</td>\n";
  801. print '<td class="right nowraponall">'.price($objp->total_ht).'</td>';
  802. print '<td class="right" style="min-width: 60px" class="nowrap">'.$propal_static->LibStatut($objp->fk_statut, 5).'</td></tr>';
  803. $i++;
  804. }
  805. $db->free($resql);
  806. if ($num > 0) {
  807. print "</table>";
  808. print '</div>';
  809. }
  810. } else {
  811. dol_print_error($db);
  812. }
  813. }
  814. /*
  815. * Latest orders
  816. */
  817. if (isModEnabled('commande') && $user->hasRight('commande', 'lire')) {
  818. $param ="";
  819. $sql = "SELECT s.nom, s.rowid";
  820. $sql .= ", c.rowid as cid, c.entity, c.total_ht";
  821. $sql .= ", c.total_tva";
  822. $sql .= ", c.total_ttc";
  823. $sql .= ", c.ref, c.ref_client, c.fk_statut, c.facture";
  824. $sql .= ", c.date_commande as dc";
  825. $sql .= ", c.facture as billed";
  826. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande as c";
  827. $sql .= " WHERE c.fk_soc = s.rowid ";
  828. $sql .= " AND s.rowid = ".((int) $object->id);
  829. $sql .= " AND c.entity IN (".getEntity('commande').')';
  830. $sql .= " ORDER BY c.date_commande DESC";
  831. $resql = $db->query($sql);
  832. if ($resql) {
  833. $commande_static = new Commande($db);
  834. $num = $db->num_rows($resql);
  835. if ($num > 0) {
  836. // Check if there are orders billable
  837. $sql2 = 'SELECT s.nom, s.rowid as socid, s.client, c.rowid, c.ref, c.total_ht, c.ref_client,';
  838. $sql2 .= ' c.date_valid, c.date_commande, c.date_livraison, c.fk_statut, c.facture as billed';
  839. $sql2 .= ' FROM '.MAIN_DB_PREFIX.'societe as s';
  840. $sql2 .= ', '.MAIN_DB_PREFIX.'commande as c';
  841. $sql2 .= ' WHERE c.fk_soc = s.rowid';
  842. $sql2 .= ' AND s.rowid = '.((int) $object->id);
  843. // Show orders with status validated, shipping started and delivered (well any order we can bill)
  844. $sql2 .= " AND ((c.fk_statut IN (1,2)) OR (c.fk_statut = 3 AND c.facture = 0))";
  845. $resql2 = $db->query($sql2);
  846. $orders2invoice = $db->num_rows($resql2);
  847. $db->free($resql2);
  848. print '<div class="div-table-responsive-no-min">';
  849. print '<table class="noborder centpercent lastrecordtable">';
  850. print '<tr class="liste_titre">';
  851. 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.'"><span class="hideonsmartphone">'.$langs->trans("AllOrders").'</span><span class="badge marginleftonlyshort">'.$num.'</span></a></td>';
  852. 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>';
  853. print '</tr></table></td>';
  854. print '</tr>';
  855. }
  856. $i = 0;
  857. while ($i < $num && $i < $MAXLIST) {
  858. $objp = $db->fetch_object($resql);
  859. $commande_static->id = $objp->cid;
  860. $commande_static->ref = $objp->ref;
  861. $commande_static->ref_client = $objp->ref_client;
  862. $commande_static->total_ht = $objp->total_ht;
  863. $commande_static->total_tva = $objp->total_tva;
  864. $commande_static->total_ttc = $objp->total_ttc;
  865. $commande_static->billed = $objp->billed;
  866. print '<tr class="oddeven">';
  867. print '<td class="nowraponall">';
  868. print $commande_static->getNomUrl(1);
  869. // Preview
  870. $filedir = $conf->commande->multidir_output[$objp->entity].'/'.dol_sanitizeFileName($objp->ref);
  871. $file_list = null;
  872. if (!empty($filedir)) {
  873. $file_list = dol_dir_list($filedir, 'files', 0, '', '(\.meta|_preview.*.*\.png)$', 'date', SORT_DESC);
  874. }
  875. if (is_array($file_list)) {
  876. // Defined relative dir to DOL_DATA_ROOT
  877. $relativedir = '';
  878. if ($filedir) {
  879. $relativedir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $filedir);
  880. $relativedir = preg_replace('/^[\\/]/', '', $relativedir);
  881. }
  882. // Get list of files stored into database for same relative directory
  883. if ($relativedir) {
  884. completeFileArrayWithDatabaseInfo($file_list, $relativedir);
  885. //var_dump($sortfield.' - '.$sortorder);
  886. 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)
  887. $file_list = dol_sort_array($file_list, $sortfield, $sortorder);
  888. }
  889. }
  890. $relativepath = dol_sanitizeFileName($objp->ref).'/'.dol_sanitizeFileName($objp->ref).'.pdf';
  891. print $formfile->showPreview($file_list, $commande_static->element, $relativepath, 0, $param);
  892. }
  893. // $filename = dol_sanitizeFileName($objp->ref);
  894. // $filedir = $conf->order->multidir_output[$objp->entity].'/'.dol_sanitizeFileName($objp->ref);
  895. // $urlsource = '/commande/card.php?id='.$objp->cid;
  896. // print $formfile->getDocumentsLink($commande_static->element, $filename, $filedir);
  897. print '</td>';
  898. print '<td class="right" width="80px">'.dol_print_date($db->jdate($objp->dc), 'day')."</td>\n";
  899. print '<td class="right nowraponall">'.price($objp->total_ht).'</td>';
  900. print '<td class="right" style="min-width: 60px" class="nowrap">'.$commande_static->LibStatut($objp->fk_statut, $objp->facture, 5).'</td></tr>';
  901. $i++;
  902. }
  903. $db->free($resql);
  904. if ($num > 0) {
  905. print "</table>";
  906. print '</div>';
  907. }
  908. } else {
  909. dol_print_error($db);
  910. }
  911. }
  912. /*
  913. * Latest shipments
  914. */
  915. if (isModEnabled("expedition") && $user->hasRight('expedition', 'lire')) {
  916. $sql = 'SELECT e.rowid as id';
  917. $sql .= ', e.ref, e.entity';
  918. $sql .= ', e.date_creation';
  919. $sql .= ', e.fk_statut as statut';
  920. $sql .= ', s.nom';
  921. $sql .= ', s.rowid as socid';
  922. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."expedition as e";
  923. $sql .= " WHERE e.fk_soc = s.rowid AND s.rowid = ".((int) $object->id);
  924. $sql .= " AND e.entity IN (".getEntity('expedition').")";
  925. $sql .= ' GROUP BY e.rowid';
  926. $sql .= ', e.ref, e.entity';
  927. $sql .= ', e.date_creation';
  928. $sql .= ', e.fk_statut';
  929. $sql .= ', s.nom';
  930. $sql .= ', s.rowid';
  931. $sql .= " ORDER BY e.date_creation DESC";
  932. $resql = $db->query($sql);
  933. if ($resql) {
  934. $sendingstatic = new Expedition($db);
  935. $num = $db->num_rows($resql);
  936. if ($num > 0) {
  937. print '<div class="div-table-responsive-no-min">';
  938. print '<table class="noborder centpercent lastrecordtable">';
  939. print '<tr class="liste_titre">';
  940. print '<td colspan="4"><table class="centpercent 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.'"><span class="hideonsmartphone">'.$langs->trans("AllSendings").'</span><span class="badge marginleftonlyshort">'.$num.'</span></a></td>';
  941. 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>';
  942. print '</tr></table></td>';
  943. print '</tr>';
  944. }
  945. $i = 0;
  946. while ($i < $num && $i < $MAXLIST) {
  947. $objp = $db->fetch_object($resql);
  948. $sendingstatic->id = $objp->id;
  949. $sendingstatic->ref = $objp->ref;
  950. print '<tr class="oddeven">';
  951. print '<td class="nowraponall">';
  952. print $sendingstatic->getNomUrl(1);
  953. // Preview
  954. $filedir = $conf->expedition->multidir_output[$objp->entity].'/'.dol_sanitizeFileName($objp->ref);
  955. $file_list = null;
  956. if (!empty($filedir)) {
  957. $file_list = dol_dir_list($filedir, 'files', 0, '', '(\.meta|_preview.*.*\.png)$', 'date', SORT_DESC);
  958. }
  959. if (is_array($file_list)) {
  960. // Defined relative dir to DOL_DATA_ROOT
  961. $relativedir = '';
  962. if ($filedir) {
  963. $relativedir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $filedir);
  964. $relativedir = preg_replace('/^[\\/]/', '', $relativedir);
  965. }
  966. // Get list of files stored into database for same relative directory
  967. if ($relativedir) {
  968. completeFileArrayWithDatabaseInfo($file_list, $relativedir);
  969. //var_dump($sortfield.' - '.$sortorder);
  970. 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)
  971. $file_list = dol_sort_array($file_list, $sortfield, $sortorder);
  972. }
  973. }
  974. $relativepath = dol_sanitizeFileName($objp->ref).'/'.dol_sanitizeFileName($objp->ref).'.pdf';
  975. print $formfile->showPreview($file_list, $sendingstatic->table_element, $relativepath, 0, $param);
  976. }
  977. // $filename = dol_sanitizeFileName($objp->ref);
  978. // $filedir = $conf->expedition->multidir_output[$objp->entity].'/'.dol_sanitizeFileName($objp->ref);
  979. // $urlsource = '/expedition/card.php?id='.$objp->cid;
  980. // print $formfile->getDocumentsLink($sendingstatic->element, $filename, $filedir);
  981. print '</td>';
  982. if ($objp->date_creation > 0) {
  983. print '<td class="right" width="80px">'.dol_print_date($db->jdate($objp->date_creation), 'day').'</td>';
  984. } else {
  985. print '<td class="right"><b>!!!</b></td>';
  986. }
  987. print '<td class="nowrap right centpercent">'.$sendingstatic->LibStatut($objp->statut, 5).'</td>';
  988. print "</tr>\n";
  989. $i++;
  990. }
  991. $db->free($resql);
  992. if ($num > 0) {
  993. print "</table>";
  994. print '</div>';
  995. }
  996. } else {
  997. dol_print_error($db);
  998. }
  999. }
  1000. /*
  1001. * Latest contracts
  1002. */
  1003. if (isModEnabled('contrat') && $user->hasRight('contrat', 'lire')) {
  1004. $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,";
  1005. $sql .= " c.last_main_doc, c.model_pdf";
  1006. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."contrat as c";
  1007. $sql .= " WHERE c.fk_soc = s.rowid ";
  1008. $sql .= " AND s.rowid = ".((int) $object->id);
  1009. $sql .= " AND c.entity IN (".getEntity('contract').")";
  1010. $sql .= " ORDER BY c.datec DESC";
  1011. $resql = $db->query($sql);
  1012. if ($resql) {
  1013. $contrat = new Contrat($db);
  1014. $num = $db->num_rows($resql);
  1015. if ($num > 0) {
  1016. print '<div class="div-table-responsive-no-min">';
  1017. print '<table class="noborder centpercent lastrecordtable">';
  1018. print '<tr class="liste_titre">';
  1019. print '<td colspan="5"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("LastContracts", ($num <= $MAXLIST ? "" : $MAXLIST)).'</td>';
  1020. 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>';
  1021. //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>';
  1022. print '</tr></table></td>';
  1023. print '</tr>';
  1024. }
  1025. $i = 0;
  1026. while ($i < $num && $i < $MAXLIST) {
  1027. $objp = $db->fetch_object($resql);
  1028. $contrat->id = $objp->id;
  1029. $contrat->ref = $objp->ref ? $objp->ref : $objp->id;
  1030. $contrat->ref_customer = $objp->refcus;
  1031. $contrat->ref_supplier = $objp->refsup;
  1032. $contrat->statut = $objp->contract_status;
  1033. $contrat->last_main_doc = $objp->last_main_doc;
  1034. $contrat->model_pdf = $objp->model_pdf;
  1035. $contrat->fetch_lines();
  1036. $late = '';
  1037. foreach ($contrat->lines as $line) {
  1038. if ($contrat->statut == Contrat::STATUS_VALIDATED && $line->statut == ContratLigne::STATUS_OPEN) {
  1039. if (((!empty($line->date_end) ? $line->date_end : 0) + $conf->contrat->services->expires->warning_delay) < $now) {
  1040. $late = img_warning($langs->trans("Late"));
  1041. }
  1042. }
  1043. }
  1044. print '<tr class="oddeven">';
  1045. print '<td class="nowraponall">';
  1046. print $contrat->getNomUrl(1, 12);
  1047. if (!empty($contrat->model_pdf)) {
  1048. // Preview
  1049. $filedir = $conf->contrat->multidir_output[$objp->entity].'/'.dol_sanitizeFileName($objp->ref);
  1050. $file_list = null;
  1051. if (!empty($filedir)) {
  1052. $file_list = dol_dir_list($filedir, 'files', 0, '', '(\.meta|_preview.*.*\.png)$', 'date', SORT_DESC);
  1053. }
  1054. if (is_array($file_list)) {
  1055. // Defined relative dir to DOL_DATA_ROOT
  1056. $relativedir = '';
  1057. if ($filedir) {
  1058. $relativedir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $filedir);
  1059. $relativedir = preg_replace('/^[\\/]/', '', $relativedir);
  1060. }
  1061. // Get list of files stored into database for same relative directory
  1062. if ($relativedir) {
  1063. completeFileArrayWithDatabaseInfo($file_list, $relativedir);
  1064. //var_dump($sortfield.' - '.$sortorder);
  1065. 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)
  1066. $file_list = dol_sort_array($file_list, $sortfield, $sortorder);
  1067. }
  1068. }
  1069. $relativepath = dol_sanitizeFileName($objp->ref).'/'.dol_sanitizeFileName($objp->ref).'.pdf';
  1070. print $formfile->showPreview($file_list, $contrat->element, $relativepath, 0);
  1071. }
  1072. }
  1073. // $filename = dol_sanitizeFileName($objp->ref);
  1074. // $filedir = $conf->contrat->multidir_output[$objp->entity].'/'.dol_sanitizeFileName($objp->ref);
  1075. // $urlsource = '/contrat/card.php?id='.$objp->cid;
  1076. // print $formfile->getDocumentsLink($contrat->element, $filename, $filedir);
  1077. print $late;
  1078. print "</td>\n";
  1079. print '<td class="nowrap">'.dol_trunc($objp->refsup, 12)."</td>\n";
  1080. //print '<td class="right" width="80px"><span title="'.$langs->trans("DateCreation").'">'.dol_print_date($db->jdate($objp->dc), 'day')."</span></td>\n";
  1081. print '<td class="right" width="80px"><span title="'.$langs->trans("DateContract").'">'.dol_print_date($db->jdate($objp->dcon), 'day')."</span></td>\n";
  1082. print '<td width="20">&nbsp;</td>';
  1083. print '<td class="nowraponall right">';
  1084. print $contrat->getLibStatut(4);
  1085. print "</td>\n";
  1086. print '</tr>';
  1087. $i++;
  1088. }
  1089. $db->free($resql);
  1090. if ($num > 0) {
  1091. print "</table>";
  1092. print '</div>';
  1093. }
  1094. } else {
  1095. dol_print_error($db);
  1096. }
  1097. }
  1098. /*
  1099. * Latest interventions
  1100. */
  1101. if (isModEnabled('ficheinter') && $user->hasRight('ficheinter', 'lire')) {
  1102. $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";
  1103. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."fichinter as f";
  1104. $sql .= " WHERE f.fk_soc = s.rowid";
  1105. $sql .= " AND s.rowid = ".((int) $object->id);
  1106. $sql .= " AND f.entity IN (".getEntity('intervention').")";
  1107. $sql .= " ORDER BY f.tms DESC";
  1108. $resql = $db->query($sql);
  1109. if ($resql) {
  1110. $fichinter_static = new Fichinter($db);
  1111. $num = $db->num_rows($resql);
  1112. if ($num > 0) {
  1113. print '<div class="div-table-responsive-no-min">';
  1114. print '<table class="noborder centpercent lastrecordtable">';
  1115. print '<tr class="liste_titre">';
  1116. print '<td colspan="3"><table class="centpercent 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.'"><span class="hideonsmartphone">'.$langs->trans("AllInterventions").'</span><span class="badge marginleftonlyshort">'.$num.'</span></td>';
  1117. 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>';
  1118. print '</tr></table></td>';
  1119. print '</tr>';
  1120. }
  1121. $i = 0;
  1122. while ($i < $num && $i < $MAXLIST) {
  1123. $objp = $db->fetch_object($resql);
  1124. $fichinter_static->id = $objp->id;
  1125. $fichinter_static->ref = $objp->ref;
  1126. $fichinter_static->statut = $objp->fk_statut;
  1127. print '<tr class="oddeven">';
  1128. print '<td class="nowraponall">';
  1129. print $fichinter_static->getNomUrl(1);
  1130. // Preview
  1131. $filedir = $conf->ficheinter->multidir_output[$objp->entity].'/'.dol_sanitizeFileName($objp->ref);
  1132. $file_list = null;
  1133. if (!empty($filedir)) {
  1134. $file_list = dol_dir_list($filedir, 'files', 0, '', '(\.meta|_preview.*.*\.png)$', 'date', SORT_DESC);
  1135. }
  1136. if (is_array($file_list)) {
  1137. // Defined relative dir to DOL_DATA_ROOT
  1138. $relativedir = '';
  1139. if ($filedir) {
  1140. $relativedir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $filedir);
  1141. $relativedir = preg_replace('/^[\\/]/', '', $relativedir);
  1142. }
  1143. // Get list of files stored into database for same relative directory
  1144. if ($relativedir) {
  1145. completeFileArrayWithDatabaseInfo($file_list, $relativedir);
  1146. //var_dump($sortfield.' - '.$sortorder);
  1147. 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)
  1148. $file_list = dol_sort_array($file_list, $sortfield, $sortorder);
  1149. }
  1150. }
  1151. $relativepath = dol_sanitizeFileName($objp->ref).'/'.dol_sanitizeFileName($objp->ref).'.pdf';
  1152. print $formfile->showPreview($file_list, $fichinter_static->element, $relativepath, 0);
  1153. }
  1154. // $filename = dol_sanitizeFileName($objp->ref);
  1155. // $filedir = getMultidirOutput($fichinter_static).'/'.dol_sanitizeFileName($objp->ref);
  1156. // $urlsource = '/fichinter/card.php?id='.$objp->cid;
  1157. // print $formfile->getDocumentsLink($fichinter_static->element, $filename, $filedir);
  1158. print '</td>'."\n";
  1159. //print '<td class="right" width="80px">'.dol_print_date($db->jdate($objp->startdate)).'</td>'."\n";
  1160. print '<td class="right" style="min-width: 60px">'.convertSecondToTime($objp->duration).'</td>'."\n";
  1161. print '<td class="nowrap right" style="min-width: 60px">'.$fichinter_static->getLibStatut(5).'</td>'."\n";
  1162. print '</tr>';
  1163. $i++;
  1164. }
  1165. $db->free($resql);
  1166. if ($num > 0) {
  1167. print "</table>";
  1168. print '</div>';
  1169. }
  1170. } else {
  1171. dol_print_error($db);
  1172. }
  1173. }
  1174. /*
  1175. * Latest invoices templates
  1176. */
  1177. if (isModEnabled('facture') && $user->hasRight('facture', 'lire')) {
  1178. $sql = 'SELECT f.rowid as id, f.titre as ref';
  1179. $sql .= ', f.total_ht';
  1180. $sql .= ', f.total_tva';
  1181. $sql .= ', f.total_ttc';
  1182. $sql .= ', f.datec as dc';
  1183. $sql .= ', f.date_last_gen, f.date_when';
  1184. $sql .= ', f.frequency';
  1185. $sql .= ', f.unit_frequency';
  1186. $sql .= ', f.suspended as suspended';
  1187. $sql .= ', s.nom, s.rowid as socid';
  1188. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture_rec as f";
  1189. $sql .= " WHERE f.fk_soc = s.rowid AND s.rowid = ".((int) $object->id);
  1190. $sql .= " AND f.entity IN (".getEntity('invoice').")";
  1191. $sql .= ' GROUP BY f.rowid, f.titre, f.total_ht, f.total_tva, f.total_ttc,';
  1192. $sql .= ' f.date_last_gen, f.datec, f.frequency, f.unit_frequency,';
  1193. $sql .= ' f.suspended, f.date_when,';
  1194. $sql .= ' s.nom, s.rowid';
  1195. $sql .= " ORDER BY f.date_last_gen, f.datec DESC";
  1196. $resql = $db->query($sql);
  1197. if ($resql) {
  1198. $invoicetemplate = new FactureRec($db);
  1199. $num = $db->num_rows($resql);
  1200. if ($num > 0) {
  1201. print '<div class="div-table-responsive-no-min">';
  1202. print '<table class="noborder centpercent lastrecordtable">';
  1203. print '<tr class="liste_titre">';
  1204. $colspan = 4;
  1205. if (getDolGlobalString('MAIN_SHOW_PRICE_WITH_TAX_IN_SUMMARIES')) {
  1206. $colspan++;
  1207. }
  1208. print '<td colspan="'.$colspan.'">';
  1209. print '<table class="centpercent nobordernopadding"><tr>';
  1210. print '<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.'"><span class="hideonsmartphone">'.$langs->trans("AllCustomerTemplateInvoices").'</span><span class="badge marginleftonlyshort">'.$num.'</span></a></td>';
  1211. print '</tr></table>';
  1212. print '</td>';
  1213. print '</tr>';
  1214. }
  1215. $i = 0;
  1216. while ($i < $num && $i < $MAXLIST) {
  1217. $objp = $db->fetch_object($resql);
  1218. $invoicetemplate->id = $objp->id;
  1219. $invoicetemplate->ref = $objp->ref;
  1220. $invoicetemplate->suspended = $objp->suspended;
  1221. $invoicetemplate->frequency = $objp->frequency;
  1222. $invoicetemplate->unit_frequency = $objp->unit_frequency;
  1223. $invoicetemplate->total_ht = $objp->total_ht;
  1224. $invoicetemplate->total_tva = $objp->total_tva;
  1225. $invoicetemplate->total_ttc = $objp->total_ttc;
  1226. $invoicetemplate->date_last_gen = $objp->date_last_gen;
  1227. $invoicetemplate->date_when = $objp->date_when;
  1228. print '<tr class="oddeven">';
  1229. print '<td class="tdoverflowmax250">';
  1230. print $invoicetemplate->getNomUrl(1);
  1231. print '</td>';
  1232. if ($objp->frequency && $objp->date_last_gen > 0) {
  1233. print '<td class="right" width="80px">'.dol_print_date($db->jdate($objp->date_last_gen), 'day').'</td>';
  1234. } else {
  1235. if ($objp->dc > 0) {
  1236. print '<td class="right" width="80px">'.dol_print_date($db->jdate($objp->dc), 'day').'</td>';
  1237. } else {
  1238. print '<td class="right"><b>!!!</b></td>';
  1239. }
  1240. }
  1241. print '<td class="right nowraponall">';
  1242. print price($objp->total_ht);
  1243. print '</td>';
  1244. if (getDolGlobalString('MAIN_SHOW_PRICE_WITH_TAX_IN_SUMMARIES')) {
  1245. print '<td class="right nowraponall">';
  1246. print price($objp->total_ttc);
  1247. print '</td>';
  1248. }
  1249. print '<td class="nowrap right" style="min-width: 60px">';
  1250. print $langs->trans('FrequencyPer_'.$invoicetemplate->unit_frequency, $invoicetemplate->frequency).' - ';
  1251. print($invoicetemplate->LibStatut($invoicetemplate->frequency, $invoicetemplate->suspended, 5, 0));
  1252. print '</td>';
  1253. print "</tr>\n";
  1254. $i++;
  1255. }
  1256. $db->free($resql);
  1257. if ($num > 0) {
  1258. print "</table>";
  1259. print '</div>';
  1260. }
  1261. } else {
  1262. dol_print_error($db);
  1263. }
  1264. }
  1265. /*
  1266. * Latest invoices
  1267. */
  1268. if (isModEnabled('facture') && $user->hasRight('facture', 'lire')) {
  1269. $sql = 'SELECT f.rowid as facid, f.ref, f.type';
  1270. $sql .= ', f.total_ht';
  1271. $sql .= ', f.total_tva';
  1272. $sql .= ', f.total_ttc';
  1273. $sql .= ', f.entity';
  1274. $sql .= ', f.datef as df, f.date_lim_reglement as dl, f.datec as dc, f.paye as paye, f.fk_statut as status';
  1275. $sql .= ', s.nom, s.rowid as socid';
  1276. $sql .= ', SUM(pf.amount) as am';
  1277. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f";
  1278. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON f.rowid=pf.fk_facture';
  1279. $sql .= " WHERE f.fk_soc = s.rowid AND s.rowid = ".((int) $object->id);
  1280. $sql .= " AND f.entity IN (".getEntity('invoice').")";
  1281. $sql .= ' GROUP BY f.rowid, f.ref, f.type, f.total_ht, f.total_tva, f.total_ttc,';
  1282. $sql .= ' f.entity, f.datef, f.date_lim_reglement, f.datec, f.paye, f.fk_statut,';
  1283. $sql .= ' s.nom, s.rowid';
  1284. $sql .= " ORDER BY f.datef DESC, f.datec DESC";
  1285. $resql = $db->query($sql);
  1286. if ($resql) {
  1287. $facturestatic = new Facture($db);
  1288. $num = $db->num_rows($resql);
  1289. if ($num > 0) {
  1290. print '<div class="div-table-responsive-no-min">';
  1291. print '<table class="noborder centpercent lastrecordtable">';
  1292. print '<tr class="liste_titre">';
  1293. $colspan = 5;
  1294. if (getDolGlobalString('MAIN_SHOW_PRICE_WITH_TAX_IN_SUMMARIES')) {
  1295. $colspan++;
  1296. }
  1297. print '<td colspan="'.$colspan.'">';
  1298. print '<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.'"><span class="hideonsmartphone">'.$langs->trans("AllBills").'</span><span class="badge marginleftonlyshort">'.$num.'</span></a></td>';
  1299. 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>';
  1300. print '</tr></table>';
  1301. print '</td>';
  1302. print '</tr>';
  1303. }
  1304. $i = 0;
  1305. while ($i < $num && $i < $MAXLIST) {
  1306. $objp = $db->fetch_object($resql);
  1307. $facturestatic->id = $objp->facid;
  1308. $facturestatic->ref = $objp->ref;
  1309. $facturestatic->type = $objp->type;
  1310. $facturestatic->total_ht = $objp->total_ht;
  1311. $facturestatic->total_tva = $objp->total_tva;
  1312. $facturestatic->total_ttc = $objp->total_ttc;
  1313. $facturestatic->statut = $objp->status;
  1314. $facturestatic->status = $objp->status;
  1315. $facturestatic->paye = $objp->paye;
  1316. $facturestatic->alreadypaid = $objp->am;
  1317. $facturestatic->totalpaid = $objp->am;
  1318. $facturestatic->date = $db->jdate($objp->df);
  1319. $facturestatic->date_lim_reglement = $db->jdate($objp->dl);
  1320. print '<tr class="oddeven">';
  1321. print '<td class="nowraponall">';
  1322. print $facturestatic->getNomUrl(1);
  1323. // Preview
  1324. $filedir = $conf->facture->multidir_output[$objp->entity].'/'.dol_sanitizeFileName($objp->ref);
  1325. $file_list = null;
  1326. if (!empty($filedir)) {
  1327. $file_list = dol_dir_list($filedir, 'files', 0, '', '(\.meta|_preview.*.*\.png)$', 'date', SORT_DESC);
  1328. }
  1329. if (is_array($file_list)) {
  1330. // Defined relative dir to DOL_DATA_ROOT
  1331. $relativedir = '';
  1332. if ($filedir) {
  1333. $relativedir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $filedir);
  1334. $relativedir = preg_replace('/^[\\/]/', '', $relativedir);
  1335. }
  1336. // Get list of files stored into database for same relative directory
  1337. if ($relativedir) {
  1338. completeFileArrayWithDatabaseInfo($file_list, $relativedir);
  1339. //var_dump($sortfield.' - '.$sortorder);
  1340. 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)
  1341. $file_list = dol_sort_array($file_list, $sortfield, $sortorder);
  1342. }
  1343. }
  1344. $relativepath = dol_sanitizeFileName($objp->ref).'/'.dol_sanitizeFileName($objp->ref).'.pdf';
  1345. print $formfile->showPreview($file_list, $facturestatic->element, $relativepath, 0);
  1346. }
  1347. // $filename = dol_sanitizeFileName($objp->ref);
  1348. // $filedir = $conf->facture->multidir_output[$objp->entity].'/'.dol_sanitizeFileName($objp->ref);
  1349. // $urlsource = '/compta/facture/card.php?id='.$objp->cid;
  1350. //print $formfile->getDocumentsLink($facturestatic->element, $filename, $filedir);
  1351. print '</td>';
  1352. if ($objp->df > 0) {
  1353. print '<td width="80px" title="'.dol_escape_htmltag($langs->trans('DateInvoice')).'">'.dol_print_date($db->jdate($objp->df), 'day').'</td>';
  1354. } else {
  1355. print '<td><b>!!!</b></td>';
  1356. }
  1357. if ($objp->dl > 0) {
  1358. print '<td width="80px" title="'.dol_escape_htmltag($langs->trans('DateMaxPayment')).'">'.dol_print_date($db->jdate($objp->dl), 'day').'</td>';
  1359. } else {
  1360. print '<td><b>!!!</b></td>';
  1361. }
  1362. print '<td class="right nowraponall">';
  1363. print price($objp->total_ht);
  1364. print '</td>';
  1365. if (getDolGlobalString('MAIN_SHOW_PRICE_WITH_TAX_IN_SUMMARIES')) {
  1366. print '<td class="right nowraponall">';
  1367. print price($objp->total_ttc);
  1368. print '</td>';
  1369. }
  1370. print '<td class="nowrap right" style="min-width: 60px">'.($facturestatic->LibStatut($objp->paye, $objp->status, 5, $objp->am)).'</td>';
  1371. print "</tr>\n";
  1372. $i++;
  1373. }
  1374. $db->free($resql);
  1375. if ($num > 0) {
  1376. print "</table>";
  1377. print '</div>';
  1378. }
  1379. } else {
  1380. dol_print_error($db);
  1381. }
  1382. }
  1383. // Allow external modules to add their own shortlist of recent objects
  1384. $parameters = array();
  1385. $reshook = $hookmanager->executeHooks('addMoreRecentObjects', $parameters, $object, $action);
  1386. if ($reshook < 0) {
  1387. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  1388. } else {
  1389. print $hookmanager->resPrint;
  1390. }
  1391. print '</div></div>';
  1392. print '<div class="clearboth"></div>';
  1393. print dol_get_fiche_end();
  1394. /*
  1395. * Action bar
  1396. */
  1397. print '<div class="tabsAction">';
  1398. $parameters = array();
  1399. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
  1400. if (empty($reshook)) {
  1401. if ($object->status != 1) {
  1402. print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" title="'.dol_escape_js($langs->trans("ThirdPartyIsClosed")).'" href="#">'.$langs->trans("ThirdPartyIsClosed").'</a></div>';
  1403. }
  1404. if (isModEnabled("propal") && $user->hasRight('propal', 'creer') && $object->status == 1) {
  1405. $langs->load("propal");
  1406. 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>';
  1407. }
  1408. if (isModEnabled('commande') && $user->hasRight('commande', 'creer') && $object->status == 1) {
  1409. $langs->load("orders");
  1410. 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>';
  1411. }
  1412. if ($user->hasRight('contrat', 'creer') && $object->status == 1) {
  1413. $langs->load("contracts");
  1414. 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>';
  1415. }
  1416. if (isModEnabled('ficheinter') && $user->hasRight('ficheinter', 'creer') && $object->status == 1) {
  1417. $langs->load("fichinter");
  1418. 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>';
  1419. }
  1420. // Add invoice
  1421. if ($user->socid == 0) {
  1422. if (isModEnabled('deplacement') && $object->status == 1) {
  1423. $langs->load("trips");
  1424. 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>';
  1425. }
  1426. if (isModEnabled('facture') && $object->status == 1) {
  1427. if (!$user->hasRight('facture', 'creer')) {
  1428. $langs->load("bills");
  1429. print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" title="'.dol_escape_js($langs->trans("NotAllowed")).'" href="#">'.$langs->trans("AddBill").'</a></div>';
  1430. } else {
  1431. $langs->loadLangs(array("orders", "bills"));
  1432. if (isModEnabled('commande')) {
  1433. if ($object->client != 0 && $object->client != 2) {
  1434. if (!empty($orders2invoice) && $orders2invoice > 0) {
  1435. 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>';
  1436. } else {
  1437. print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" title="'.dol_escape_js($langs->trans("NoOrdersToInvoice")).'" href="#">'.$langs->trans("CreateInvoiceForThisCustomer").'</a></div>';
  1438. }
  1439. } else {
  1440. print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" title="'.dol_escape_js($langs->trans("ThirdPartyMustBeEditAsCustomer")).'" href="#">'.$langs->trans("CreateInvoiceForThisCustomer").'</a></div>';
  1441. }
  1442. }
  1443. if ($object->client != 0 && $object->client != 2) {
  1444. 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>';
  1445. } else {
  1446. print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" title="'.dol_escape_js($langs->trans("ThirdPartyMustBeEditAsCustomer")).'" href="#">'.$langs->trans("AddBill").'</a></div>';
  1447. }
  1448. }
  1449. }
  1450. }
  1451. // Add action
  1452. if (isModEnabled('agenda') && getDolGlobalString('MAIN_REPEATTASKONEACHTAB') && $object->status == 1) {
  1453. if ($user->hasRight('agenda', 'myactions', 'create')) {
  1454. 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>';
  1455. } else {
  1456. print '<div class="inline-block divButAction"><a class="butAction" title="'.dol_escape_js($langs->trans("NotAllowed")).'" href="#">'.$langs->trans("AddAction").'</a></div>';
  1457. }
  1458. }
  1459. }
  1460. print '</div>';
  1461. if (getDolGlobalString('MAIN_DUPLICATE_CONTACTS_TAB_ON_CUSTOMER_CARD')) {
  1462. // List of contacts
  1463. show_contacts($conf, $langs, $db, $object, $_SERVER["PHP_SELF"].'?socid='.$object->id);
  1464. }
  1465. if (getDolGlobalString('MAIN_REPEATTASKONEACHTAB')) {
  1466. print load_fiche_titre($langs->trans("ActionsOnCompany"), '', '');
  1467. // List of todo actions
  1468. show_actions_todo($conf, $langs, $db, $object);
  1469. // List of done actions
  1470. show_actions_done($conf, $langs, $db, $object);
  1471. }
  1472. } else {
  1473. $langs->load("errors");
  1474. print $langs->trans('ErrorRecordNotFound');
  1475. }
  1476. // End of page
  1477. llxFooter();
  1478. $db->close();