card.php 66 KB

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