dolibarr  16.0.5
card.php
Go to the documentation of this file.
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 
35 require '../main.inc.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
38 require_once DOL_DOCUMENT_ROOT.'/societe/class/client.class.php';
39 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
40 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
41 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
42 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
43 if (isModEnabled('facture')) {
44  require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
45  require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture-rec.class.php';
46 }
47 if (!empty($conf->propal->enabled)) {
48  require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
49 }
50 if (!empty($conf->commande->enabled)) {
51  require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
52 }
53 if (!empty($conf->expedition->enabled)) {
54  require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
55 }
56 if (!empty($conf->contrat->enabled)) {
57  require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
58 }
59 if (!empty($conf->adherent->enabled)) {
60  require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
61 }
62 if (!empty($conf->ficheinter->enabled)) {
63  require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
64 }
65 
66 // Load translation files required by the page
67 $langs->loadLangs(array('companies', 'banks'));
68 
69 if (!empty($conf->contrat->enabled)) {
70  $langs->load("contracts");
71 }
72 if (!empty($conf->commande->enabled)) {
73  $langs->load("orders");
74 }
75 if (!empty($conf->expedition->enabled)) {
76  $langs->load("sendings");
77 }
78 if (isModEnabled('facture')) {
79  $langs->load("bills");
80 }
81 if (!empty($conf->project->enabled)) {
82  $langs->load("projects");
83 }
84 if (!empty($conf->ficheinter->enabled)) {
85  $langs->load("interventions");
86 }
87 if (!empty($conf->notification->enabled)) {
88  $langs->load("mails");
89 }
90 
91 $action = GETPOST('action', 'aZ09');
92 
93 $id = (GETPOST('socid', 'int') ? GETPOST('socid', 'int') : GETPOST('id', 'int'));
94 
95 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
96 $sortfield = GETPOST('sortfield', 'aZ09comma');
97 $sortorder = GETPOST('sortorder', 'aZ09comma');
98 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
99 if (empty($page) || $page == -1) {
100  $page = 0;
101 } // If $page is not defined, or '' or -1
102 $offset = $limit * $page;
103 $pageprev = $page - 1;
104 $pagenext = $page + 1;
105 if (!$sortorder) {
106  $sortorder = "ASC";
107 }
108 if (!$sortfield) {
109  $sortfield = "nom";
110 }
111 $cancel = GETPOST('cancel', 'alpha');
112 
113 $object = new Client($db);
114 $extrafields = new ExtraFields($db);
115 $formfile = new FormFile($db);
116 
117 // fetch optionals attributes and labels
118 $extrafields->fetch_name_optionals_label($object->table_element);
119 
120 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
121 $hookmanager->initHooks(array('thirdpartycomm', 'globalcard'));
122 
123 $now = dol_now();
124 
125 if ($id > 0 && empty($object->id)) {
126  // Load data of third party
127  $res = $object->fetch($id);
128  if ($object->id < 0) {
129  dol_print_error($db, $object->error, $object->errors);
130  }
131 }
132 if ($object->id > 0) {
133  if (!($object->client > 0) || empty($user->rights->societe->lire)) {
134  accessforbidden();
135  }
136 }
137 
138 // Security check
139 if ($user->socid > 0) {
140  $id = $user->socid;
141 }
142 $result = restrictedArea($user, 'societe', $object->id, '&societe', '', 'fk_soc', 'rowid', 0);
143 
144 
145 /*
146  * Actions
147  */
148 
149 $parameters = array('id' => $id, 'socid' => $id);
150 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some
151 if ($reshook < 0) {
152  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
153 }
154 
155 if (empty($reshook)) {
156  if ($cancel) {
157  $action = "";
158  }
159 
160  // set accountancy code
161  if ($action == 'setcustomeraccountancycode') {
162  $result = $object->fetch($id);
163  $object->code_compta_client = GETPOST("customeraccountancycode");
164  $object->code_compta = $object->code_compta_client; // For Backward compatibility
165  $result = $object->update($object->id, $user, 1, 1, 0);
166  if ($result < 0) {
167  setEventMessages($object->error, $object->errors, 'errors');
168  }
169  }
170 
171  // terms of the settlement
172  if ($action == 'setconditions' && $user->rights->societe->creer) {
173  $object->fetch($id);
174  $result = $object->setPaymentTerms(GETPOST('cond_reglement_id', 'int'), GETPOST('cond_reglement_id_deposit_percent', 'alpha'));
175  if ($result < 0) {
176  setEventMessages($object->error, $object->errors, 'errors');
177  }
178  }
179 
180  // mode de reglement
181  if ($action == 'setmode' && $user->rights->societe->creer) {
182  $object->fetch($id);
183  $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int'));
184  if ($result < 0) {
185  setEventMessages($object->error, $object->errors, 'errors');
186  }
187  }
188 
189  // transport mode
190  if ($action == 'settransportmode' && $user->rights->societe->creer) {
191  $object->fetch($id);
192  $result = $object->setTransportMode(GETPOST('transport_mode_id', 'alpha'));
193  if ($result < 0) {
194  setEventMessages($object->error, $object->errors, 'errors');
195  }
196  }
197 
198  // Bank account
199  if ($action == 'setbankaccount' && $user->rights->societe->creer) {
200  $object->fetch($id);
201  $result = $object->setBankAccount(GETPOST('fk_account', 'int'));
202  if ($result < 0) {
203  setEventMessages($object->error, $object->errors, 'errors');
204  }
205  }
206 
207  // customer preferred shipping method
208  if ($action == 'setshippingmethod' && $user->rights->societe->creer) {
209  $object->fetch($id);
210  $result = $object->setShippingMethod(GETPOST('shipping_method_id', 'int'));
211  if ($result < 0) {
212  setEventMessages($object->error, $object->errors, 'errors');
213  }
214  }
215 
216  // assujetissement a la TVA
217  if ($action == 'setassujtva' && $user->rights->societe->creer) {
218  $object->fetch($id);
219  $object->tva_assuj = GETPOST('assujtva_value');
220  $result = $object->update($object->id);
221  if ($result < 0) {
222  setEventMessages($object->error, $object->errors, 'errors');
223  }
224  }
225 
226  // set prospect level
227  if ($action == 'setprospectlevel' && $user->rights->societe->creer) {
228  $object->fetch($id);
229  $object->fk_prospectlevel = GETPOST('prospect_level_id', 'alpha');
230  $result = $object->update($object->id, $user);
231  if ($result < 0) {
232  setEventMessages($object->error, $object->errors, 'errors');
233  }
234  }
235 
236  // set communication status
237  if ($action == 'setstcomm') {
238  $object->fetch($id);
239  $object->stcomm_id = dol_getIdFromCode($db, GETPOST('stcomm', 'alpha'), 'c_stcomm');
240  $result = $object->update($object->id, $user);
241  if ($result < 0) {
242  setEventMessages($object->error, $object->errors, 'errors');
243  } else {
244  $result = $object->fetch($object->id);
245  }
246  }
247 
248  // update outstandng limit
249  if ($action == 'setoutstanding_limit') {
250  $object->fetch($id);
251  $object->outstanding_limit = GETPOST('outstanding_limit');
252  $result = $object->update($object->id, $user);
253  if ($result < 0) {
254  setEventMessages($object->error, $object->errors, 'errors');
255  }
256  }
257 
258  // update order min amount
259  if ($action == 'setorder_min_amount') {
260  $object->fetch($id);
261  $object->order_min_amount = price2num(GETPOST('order_min_amount', 'alpha'));
262  $result = $object->update($object->id, $user);
263  if ($result < 0) {
264  setEventMessages($object->error, $object->errors, 'errors');
265  }
266  }
267 
268  // Set sales representatives
269  if ($action == 'set_salesrepresentatives' && $user->rights->societe->creer) {
270  $object->fetch($id);
271  $result = $object->setSalesRep(GETPOST('commercial', 'array'));
272  }
273 
274  if ($action == 'update_extras') {
275  $object->fetch($id);
276 
277  $object->oldcopy = dol_clone($object);
278 
279  // Fill array 'array_options' with data from update form
280  $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'restricthtml'));
281  if ($ret < 0) {
282  $error++;
283  }
284  if (!$error) {
285  $result = $object->insertExtraFields('COMPANY_MODIFY');
286  if ($result < 0) {
287  setEventMessages($object->error, $object->errors, 'errors');
288  $error++;
289  }
290  }
291  if ($error) {
292  $action = 'edit_extras';
293  }
294  }
295 
296  // warehouse
297  if ($action == 'setwarehouse' && $user->rights->societe->creer) {
298  $result = $object->setWarehouse(GETPOST('fk_warehouse', 'int'));
299  }
300 }
301 
302 
303 /*
304  * View
305  */
306 
307 $contactstatic = new Contact($db);
308 $userstatic = new User($db);
309 $form = new Form($db);
310 $formcompany = new FormCompany($db);
311 
312 $title = $langs->trans("ThirdParty")." - ".$langs->trans('Customer');
313 if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) {
314  $title = $object->name." - ".$langs->trans('Customer');
315 }
316 
317 $help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas|DE:Modul_Geschäftspartner';
318 
319 llxHeader('', $title, $help_url);
320 
321 
322 if ($object->id > 0) {
323  $head = societe_prepare_head($object);
324 
325  print dol_get_fiche_head($head, 'customer', $langs->trans("ThirdParty"), -1, 'company');
326 
327  $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
328 
329  dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom');
330 
331  print '<div class="fichecenter"><div class="fichehalfleft">';
332 
333  print '<div class="underbanner clearboth"></div>';
334  print '<table class="border centpercent tableforfield">';
335 
336  // Type Prospect/Customer/Supplier
337  print '<tr><td class="titlefield">'.$langs->trans('NatureOfThirdParty').'</td><td>';
338  print $object->getTypeUrl(1);
339  print '</td></tr>';
340 
341  // Prefix
342  if (!empty($conf->global->SOCIETE_USEPREFIX)) { // Old not used prefix field
343  print '<tr><td>'.$langs->trans("Prefix").'</td><td>';
344  print ($object->prefix_comm ? $object->prefix_comm : '&nbsp;');
345  print '</td></tr>';
346  }
347 
348  if ($object->client) {
349  $langs->load("compta");
350 
351  print '<tr><td>';
352  print $langs->trans('CustomerCode').'</td><td>';
353  print showValueWithClipboardCPButton(dol_escape_htmltag($object->code_client));
354  $tmpcheck = $object->check_codeclient();
355  if ($tmpcheck != 0 && $tmpcheck != -5) {
356  print ' <span class="error">('.$langs->trans("WrongCustomerCode").')</span>';
357  }
358  print '</td></tr>';
359 
360  print '<tr>';
361  print '<td>';
362  print $form->editfieldkey("CustomerAccountancyCode", 'customeraccountancycode', $object->code_compta_client, $object, $user->rights->societe->creer);
363  print '</td><td>';
364  print $form->editfieldval("CustomerAccountancyCode", 'customeraccountancycode', $object->code_compta_client, $object, $user->rights->societe->creer);
365  print '</td>';
366  print '</tr>';
367  }
368 
369  // 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.
370  // We don't need them into customer profile.
371  // Except for spain and localtax where localtax depends on buyer and not seller
372 
373  // VAT is used
374  /*
375  print '<tr>';
376  print '<td class="nowrap">';
377  print $form->textwithpicto($langs->trans('VATIsUsed'),$langs->trans('VATIsUsedWhenSelling'));
378  print '</td>';
379  print '<td>';
380  print yn($object->tva_assuj);
381  print '</td>';
382  print '</tr>';
383  */
384 
385  if ($mysoc->country_code == 'ES') {
386  // Local Taxes
387  if ($mysoc->localtax1_assuj == "1") {
388  print '<tr><td class="nowrap">'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).'</td><td>';
389  print yn($object->localtax1_assuj);
390  print '</td></tr>';
391  }
392  if ($mysoc->localtax1_assuj == "1") {
393  print '<tr><td class="nowrap">'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).'</td><td>';
394  print yn($object->localtax2_assuj);
395  print '</td></tr>';
396  }
397  }
398 
399  // TVA Intra
400  print '<tr><td class="nowrap">'.$langs->trans('VATIntra').'</td><td>';
401  print showValueWithClipboardCPButton(dol_escape_htmltag($object->tva_intra));
402  print '</td></tr>';
403 
404  // default terms of the settlement
405  $langs->load('bills');
406  print '<tr><td>';
407  print '<table width="100%" class="nobordernopadding"><tr><td>';
408  print $langs->trans('PaymentConditions');
409  print '<td>';
410  if (($action != 'editconditions') && $user->rights->societe->creer) {
411  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>';
412  }
413  print '</tr></table>';
414  print '</td><td>';
415  if ($action == 'editconditions') {
416  $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->cond_reglement_id, 'cond_reglement_id', 1, '', 1, $object->deposit_percent);
417  } else {
418  $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->cond_reglement_id, 'none', 0, '', 1, $object->deposit_percent);
419  }
420  print "</td>";
421  print '</tr>';
422 
423  // Mode de reglement par defaut
424  print '<tr><td class="nowrap">';
425  print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
426  print $langs->trans('PaymentMode');
427  print '<td>';
428  if (($action != 'editmode') && $user->rights->societe->creer) {
429  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>';
430  }
431  print '</tr></table>';
432  print '</td><td>';
433  if ($action == 'editmode') {
434  $form->form_modes_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->mode_reglement_id, 'mode_reglement_id', 'CRDT', 1, 1);
435  } else {
436  $form->form_modes_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->mode_reglement_id, 'none');
437  }
438  print "</td>";
439  print '</tr>';
440 
441  if (!empty($conf->banque->enabled)) {
442  // Compte bancaire par défaut
443  print '<tr><td class="nowrap">';
444  print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
445  print $langs->trans('PaymentBankAccount');
446  print '<td>';
447  if (($action != 'editbankaccount') && $user->rights->societe->creer) {
448  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>';
449  }
450  print '</tr></table>';
451  print '</td><td>';
452  if ($action == 'editbankaccount') {
453  $form->formSelectAccount($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->fk_account, 'fk_account', 1);
454  } else {
455  $form->formSelectAccount($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->fk_account, 'none');
456  }
457  print "</td>";
458  print '</tr>';
459  }
460 
461  $isCustomer = ($object->client == 1 || $object->client == 3);
462 
463  // Relative discounts (Discounts-Drawbacks-Rebates)
464  if ($isCustomer) {
465  print '<tr><td class="nowrap">';
466  print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
467  print $langs->trans("CustomerRelativeDiscountShort");
468  print '<td><td class="right">';
469  if ($user->rights->societe->creer && !$user->socid > 0) {
470  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>';
471  }
472  print '</td></tr></table>';
473  print '</td><td>'.($object->remise_percent ? '<a href="'.DOL_URL_ROOT.'/comm/remise.php?id='.$object->id.'">'.$object->remise_percent.'%</a>' : '').'</td>';
474  print '</tr>';
475 
476  // Absolute discounts (Discounts-Drawbacks-Rebates)
477  print '<tr><td class="nowrap">';
478  print '<table width="100%" class="nobordernopadding">';
479  print '<tr><td class="nowrap">';
480  print $langs->trans("CustomerAbsoluteDiscountShort");
481  print '<td><td class="right">';
482  if ($user->rights->societe->creer && !$user->socid > 0) {
483  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>';
484  }
485  print '</td></tr></table>';
486  print '</td>';
487  print '<td>';
488  $amount_discount = $object->getAvailableDiscounts();
489  if ($amount_discount < 0) {
490  dol_print_error($db, $object->error);
491  }
492  if ($amount_discount > 0) {
493  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>';
494  }
495  //else print $langs->trans("DiscountNone");
496  print '</td>';
497  print '</tr>';
498  }
499 
500  // Max outstanding bill
501  if ($object->client) {
502  print '<tr class="nowrap">';
503  print '<td>';
504  print $form->editfieldkey("OutstandingBill", 'outstanding_limit', $object->outstanding_limit, $object, $user->rights->societe->creer);
505  print '</td><td>';
506  $limit_field_type = (!empty($conf->global->MAIN_USE_JQUERY_JEDITABLE)) ? 'numeric' : 'amount';
507  print $form->editfieldval("OutstandingBill", 'outstanding_limit', $object->outstanding_limit, $object, $user->rights->societe->creer, $limit_field_type, ($object->outstanding_limit != '' ? price($object->outstanding_limit) : ''));
508  print '</td>';
509  print '</tr>';
510  }
511 
512  if ($object->client) {
513  if (!empty($conf->commande->enabled) && !empty($conf->global->ORDER_MANAGE_MIN_AMOUNT)) {
514  print '<!-- Minimim amount for orders -->'."\n";
515  print '<tr class="nowrap">';
516  print '<td>';
517  print $form->editfieldkey("OrderMinAmount", 'order_min_amount', $object->order_min_amount, $object, $user->rights->societe->creer);
518  print '</td><td>';
519  print $form->editfieldval("OrderMinAmount", 'order_min_amount', $object->order_min_amount, $object, $user->rights->societe->creer, $limit_field_type, ($object->order_min_amount != '' ? price($object->order_min_amount) : ''));
520  print '</td>';
521  print '</tr>';
522  }
523  }
524 
525 
526  // Multiprice level
527  if (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
528  print '<tr><td class="nowrap">';
529  print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
530  print $langs->trans("PriceLevel");
531  print '<td><td class="right">';
532  if ($user->rights->societe->creer) {
533  print '<a class="editfielda" href="'.DOL_URL_ROOT.'/comm/multiprix.php?id='.$object->id.'">'.img_edit($langs->trans("Modify")).'</a>';
534  }
535  print '</td></tr></table>';
536  print '</td><td>';
537  print $object->price_level;
538  $keyforlabel = 'PRODUIT_MULTIPRICES_LABEL'.$object->price_level;
539  if (!empty($conf->global->$keyforlabel)) {
540  print ' - '.$langs->trans($conf->global->$keyforlabel);
541  }
542  print "</td>";
543  print '</tr>';
544  }
545 
546  // Warehouse
547  if (!empty($conf->stock->enabled) && !empty($conf->global->SOCIETE_ASK_FOR_WAREHOUSE)) {
548  $langs->load('stocks');
549  require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
550  $formproduct = new FormProduct($db);
551  print '<tr class="nowrap">';
552  print '<td>';
553  print $form->editfieldkey("Warehouse", 'warehouse', '', $object, $user->rights->societe->creer);
554  print '</td><td>';
555  if ($action == 'editwarehouse') {
556  $formproduct->formSelectWarehouses($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_warehouse, 'fk_warehouse', 1);
557  } else {
558  if ($object->fk_warehouse > 0) {
559  print img_picto('', 'stock', 'class="paddingrightonly"');
560  }
561  $formproduct->formSelectWarehouses($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_warehouse, 'none');
562  }
563  print '</td>';
564  print '</tr>';
565  }
566 
567  // Preferred shipping Method
568  if (!empty($conf->global->SOCIETE_ASK_FOR_SHIPPING_METHOD)) {
569  print '<tr><td class="nowrap">';
570  print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
571  print $langs->trans('SendingMethod');
572  print '<td>';
573  if (($action != 'editshipping') && $user->rights->societe->creer) {
574  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>';
575  }
576  print '</tr></table>';
577  print '</td><td>';
578  if ($action == 'editshipping') {
579  $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->shipping_method_id, 'shipping_method_id', 1);
580  } else {
581  $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->shipping_method_id, 'none');
582  }
583  print "</td>";
584  print '</tr>';
585  }
586 
587  if (!empty($conf->intracommreport->enabled)) {
588  // Transport mode by default
589  print '<tr><td class="nowrap">';
590  print '<table class="centpercent nobordernopadding"><tr><td class="nowrap">';
591  print $langs->trans('IntracommReportTransportMode');
592  print '<td>';
593  if (($action != 'edittransportmode') && $user->rights->societe->creer) {
594  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>';
595  }
596  print '</tr></table>';
597  print '</td><td>';
598  if ($action == 'edittransportmode') {
599  $form->formSelectTransportMode($_SERVER['PHP_SELF'].'?socid='.$object->id, (!empty($object->transport_mode_id) ? $object->transport_mode_id : ''), 'transport_mode_id', 1);
600  } else {
601  $form->formSelectTransportMode($_SERVER['PHP_SELF'].'?socid='.$object->id, (!empty($object->transport_mode_id) ? $object->transport_mode_id : ''), 'none');
602  }
603  print "</td>";
604  print '</tr>';
605  }
606 
607  // Categories
608  if (!empty($conf->categorie->enabled) && !empty($user->rights->categorie->lire)) {
609  $langs->load("categories");
610  print '<tr><td>'.$langs->trans("CustomersCategoriesShort").'</td>';
611  print '<td>';
612  print $form->showCategories($object->id, Categorie::TYPE_CUSTOMER, 1);
613  print "</td></tr>";
614  }
615 
616  // Other attributes
617  $parameters = array('socid'=>$object->id);
618  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
619 
620  // Sales representative
621  include DOL_DOCUMENT_ROOT.'/societe/tpl/linesalesrepresentative.tpl.php';
622 
623  // Module Adherent
624  if (!empty($conf->adherent->enabled)) {
625  $langs->load("members");
626  $langs->load("users");
627 
628  print '<tr><td class="titlefield">'.$langs->trans("LinkedToDolibarrMember").'</td>';
629  print '<td>';
630  $adh = new Adherent($db);
631  $result = $adh->fetch('', '', $object->id);
632  if ($result > 0) {
633  $adh->ref = $adh->getFullName($langs);
634  print $adh->getNomUrl(-1);
635  } else {
636  print '<span class="opacitymedium">'.$langs->trans("ThirdpartyNotLinkedToMember").'</span>';
637  }
638  print '</td>';
639  print "</tr>\n";
640  }
641 
642  print "</table>";
643 
644  // Prospection level and status
645  if ($object->client == 2 || $object->client == 3) {
646  print '<br>';
647 
648  print '<div class="underbanner clearboth"></div>';
649  print '<table class="border centpercent tableforfield">';
650 
651  // Level of prospection
652  print '<tr><td class="titlefield nowrap">';
653  print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
654  print $langs->trans('ProspectLevel');
655  print '<td>';
656  if ($action != 'editlevel' && $user->rights->societe->creer) {
657  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>';
658  }
659  print '</tr></table>';
660  print '</td><td>';
661  if ($action == 'editlevel') {
662  $formcompany->form_prospect_level($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->fk_prospectlevel, 'prospect_level_id', 1);
663  } else {
664  print $object->getLibProspLevel();
665  }
666  print "</td>";
667  print '</tr>';
668 
669  // Status of prospection
670  $object->loadCacheOfProspStatus();
671  print '<tr><td>'.$langs->trans("StatusProsp").'</td><td>'.$object->getLibProspCommStatut(4, $object->cacheprospectstatus[$object->stcomm_id]['label']);
672  print ' &nbsp; &nbsp; ';
673  print '<div class="floatright">';
674  foreach ($object->cacheprospectstatus as $key => $val) {
675  $titlealt = 'default';
676  if (!empty($val['code']) && !in_array($val['code'], array('ST_NO', 'ST_NEVER', 'ST_TODO', 'ST_PEND', 'ST_DONE'))) {
677  $titlealt = $val['label'];
678  }
679  if ($object->stcomm_id != $val['id']) {
680  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>';
681  }
682  }
683  print '</div></td></tr>';
684  print "</table>";
685  }
686 
687  print '</div><div class="fichehalfright">';
688  print '<div class="underbanner underbanner-before-box clearboth"></div>';
689 
690  $boxstat = '';
691 
692  // Nbre max d'elements des petites listes
693  $MAXLIST = $conf->global->MAIN_SIZE_SHORTLIST_LIMIT;
694 
695  // Lien recap
696  $boxstat .= '<div class="box box-halfright">';
697  $boxstat .= '<table summary="'.dol_escape_htmltag($langs->trans("DolibarrStateBoard")).'" class="border boxtable boxtablenobottom boxtablenotop" width="100%">';
698  $boxstat .= '<tr class="impair nohover"><td colspan="2" class="tdboxstats nohover">';
699 
700  if (!empty($conf->propal->enabled) && $user->rights->propal->lire) {
701  // Box proposals
702  $tmp = $object->getOutstandingProposals();
703  $outstandingOpened = $tmp['opened'];
704  $outstandingTotal = $tmp['total_ht'];
705  $outstandingTotalIncTax = $tmp['total_ttc'];
706  $text = $langs->trans("OverAllProposals");
707  $link = DOL_URL_ROOT.'/comm/propal/list.php?socid='.$object->id;
708  $icon = 'bill';
709  if ($link) {
710  $boxstat .= '<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
711  }
712  $boxstat .= '<div class="boxstats" title="'.dol_escape_htmltag($text).'">';
713  $boxstat .= '<span class="boxstatstext">'.img_object("", $icon).' <span>'.$text.'</span></span><br>';
714  $boxstat .= '<span class="boxstatsindicator">'.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
715  $boxstat .= '</div>';
716  if ($link) {
717  $boxstat .= '</a>';
718  }
719  }
720 
721  if (!empty($conf->commande->enabled) && $user->rights->commande->lire) {
722  // Box commandes
723  $tmp = $object->getOutstandingOrders();
724  $outstandingOpened = $tmp['opened'];
725  $outstandingTotal = $tmp['total_ht'];
726  $outstandingTotalIncTax = $tmp['total_ttc'];
727  $text = $langs->trans("OverAllOrders");
728  $link = DOL_URL_ROOT.'/commande/list.php?socid='.$object->id;
729  $icon = 'bill';
730  if ($link) {
731  $boxstat .= '<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
732  }
733  $boxstat .= '<div class="boxstats" title="'.dol_escape_htmltag($text).'">';
734  $boxstat .= '<span class="boxstatstext">'.img_object("", $icon).' <span>'.$text.'</span></span><br>';
735  $boxstat .= '<span class="boxstatsindicator">'.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
736  $boxstat .= '</div>';
737  if ($link) {
738  $boxstat .= '</a>';
739  }
740  }
741 
742  if (isModEnabled('facture') && $user->rights->facture->lire) {
743  // Box factures
744  $tmp = $object->getOutstandingBills('customer', 0);
745  $outstandingOpened = $tmp['opened'];
746  $outstandingTotal = $tmp['total_ht'];
747  $outstandingTotalIncTax = $tmp['total_ttc'];
748 
749  $text = $langs->trans("OverAllInvoices");
750  $link = DOL_URL_ROOT.'/compta/facture/list.php?socid='.$object->id;
751  $icon = 'bill';
752  if ($link) {
753  $boxstat .= '<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
754  }
755  $boxstat .= '<div class="boxstats" title="'.dol_escape_htmltag($text).'">';
756  $boxstat .= '<span class="boxstatstext">'.img_object("", $icon).' <span>'.$text.'</span></span><br>';
757  $boxstat .= '<span class="boxstatsindicator">'.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
758  $boxstat .= '</div>';
759  if ($link) {
760  $boxstat .= '</a>';
761  }
762 
763  // Box outstanding bill
764  $warn = '';
765  if ($object->outstanding_limit != '' && $object->outstanding_limit < $outstandingOpened) {
766  $warn = ' '.img_warning($langs->trans("OutstandingBillReached"));
767  }
768  $text = $langs->trans("CurrentOutstandingBill");
769  $link = DOL_URL_ROOT.'/compta/recap-compta.php?socid='.$object->id;
770  $icon = 'bill';
771  if ($link) {
772  $boxstat .= '<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
773  }
774  $boxstat .= '<div class="boxstats" title="'.dol_escape_htmltag($text).'">';
775  $boxstat .= '<span class="boxstatstext">'.img_object("", $icon).' <span>'.$text.'</span></span><br>';
776  $boxstat .= '<span class="boxstatsindicator'.($outstandingOpened > 0 ? ' amountremaintopay' : '').'">'.price($outstandingOpened, 1, $langs, 1, -1, -1, $conf->currency).$warn.'</span>';
777  $boxstat .= '</div>';
778  if ($link) {
779  $boxstat .= '</a>';
780  }
781 
782  $tmp = $object->getOutstandingBills('customer', 1);
783  $outstandingOpenedLate = $tmp['opened'];
784  if ($outstandingOpened != $outstandingOpenedLate && !empty($outstandingOpenedLate)) {
785  $warn = '';
786  if ($object->outstanding_limit != '' && $object->outstanding_limit < $outstandingOpenedLate) {
787  $warn = ' '.img_warning($langs->trans("OutstandingBillReached"));
788  }
789  $text = $langs->trans("CurrentOutstandingBillLate");
790  $link = DOL_URL_ROOT.'/compta/recap-compta.php?socid='.$object->id;
791  $icon = 'bill';
792  if ($link) {
793  $boxstat .= '<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
794  }
795  $boxstat .= '<div class="boxstats" title="'.dol_escape_htmltag($text).'">';
796  $boxstat .= '<span class="boxstatstext">'.img_object("", $icon).' <span>'.$text.'</span></span><br>';
797  $boxstat .= '<span class="boxstatsindicator'.($outstandingOpenedLate > 0 ? ' amountremaintopay' : '').'">'.price($outstandingOpenedLate, 1, $langs, 1, -1, -1, $conf->currency).$warn.'</span>';
798  $boxstat .= '</div>';
799  if ($link) {
800  $boxstat .= '</a>';
801  }
802  }
803  }
804 
805  $parameters = array();
806  $reshook = $hookmanager->executeHooks('addMoreBoxStatsCustomer', $parameters, $object, $action);
807  if (empty($reshook)) {
808  $boxstat .= $hookmanager->resPrint;
809  }
810 
811  $boxstat .= '</td></tr>';
812  $boxstat .= '</table>';
813  $boxstat .= '</div>';
814 
815  print $boxstat;
816 
817 
818  /*
819  * Latest proposals
820  */
821  if (!empty($conf->propal->enabled) && $user->rights->propal->lire) {
822  $langs->load("propal");
823 
824  $sql = "SELECT s.nom, s.rowid, p.rowid as propalid, p.fk_statut, p.total_ht";
825  $sql .= ", p.total_tva";
826  $sql .= ", p.total_ttc";
827  $sql .= ", p.ref, p.ref_client, p.remise";
828  $sql .= ", p.datep as dp, p.fin_validite as date_limit, p.entity";
829  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as p, ".MAIN_DB_PREFIX."c_propalst as c";
830  $sql .= " WHERE p.fk_soc = s.rowid AND p.fk_statut = c.id";
831  $sql .= " AND s.rowid = ".((int) $object->id);
832  $sql .= " AND p.entity IN (".getEntity('propal').")";
833  $sql .= " ORDER BY p.datep DESC";
834 
835  $resql = $db->query($sql);
836  if ($resql) {
837  $propal_static = new Propal($db);
838 
839  $num = $db->num_rows($resql);
840  if ($num > 0) {
841  print '<div class="div-table-responsive-no-min">';
842  print '<table class="noborder centpercent lastrecordtable">';
843 
844  print '<tr class="liste_titre">';
845  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>';
846  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>';
847  print '</tr></table></td>';
848  print '</tr>';
849  }
850 
851  $i = 0;
852  while ($i < $num && $i < $MAXLIST) {
853  $objp = $db->fetch_object($resql);
854 
855  print '<tr class="oddeven">';
856  print '<td class="nowraponall">';
857  $propal_static->id = $objp->propalid;
858  $propal_static->ref = $objp->ref;
859  $propal_static->ref_client = $objp->ref_client;
860  $propal_static->total_ht = $objp->total_ht;
861  $propal_static->total_tva = $objp->total_tva;
862  $propal_static->total_ttc = $objp->total_ttc;
863  print $propal_static->getNomUrl(1);
864 
865  // Preview
866  $filedir = $conf->propal->multidir_output[$objp->entity].'/'.dol_sanitizeFileName($objp->ref);
867  $file_list = null;
868  if (!empty($filedir)) {
869  $file_list = dol_dir_list($filedir, 'files', 0, '', '(\.meta|_preview.*.*\.png)$', 'date', SORT_DESC);
870  }
871  if (is_array($file_list)) {
872  // Defined relative dir to DOL_DATA_ROOT
873  $relativedir = '';
874  if ($filedir) {
875  $relativedir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $filedir);
876  $relativedir = preg_replace('/^[\\/]/', '', $relativedir);
877  }
878  // Get list of files stored into database for same relative directory
879  if ($relativedir) {
880  completeFileArrayWithDatabaseInfo($file_list, $relativedir);
881 
882  //var_dump($sortfield.' - '.$sortorder);
883  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)
884  $file_list = dol_sort_array($file_list, $sortfield, $sortorder);
885  }
886  }
887  $relativepath = dol_sanitizeFileName($objp->ref).'/'.dol_sanitizeFileName($objp->ref).'.pdf';
888  print $formfile->showPreview($file_list, $propal_static->element, $relativepath, 0);
889  }
890  // $filename = dol_sanitizeFileName($objp->ref);
891  // $filedir = $conf->propal->multidir_output[$objp->entity].'/'.dol_sanitizeFileName($objp->ref);
892  // $urlsource = '/comm/propal/card.php?id='.$objp->cid;
893  // print $formfile->getDocumentsLink($propal_static->element, $filename, $filedir);
894  if (($db->jdate($objp->date_limit) < ($now - $conf->propal->cloture->warning_delay)) && $objp->fk_statut == $propal_static::STATUS_VALIDATED) {
895  print " ".img_warning();
896  }
897  print '</td><td class="right" width="80px">'.dol_print_date($db->jdate($objp->dp), 'day')."</td>\n";
898  print '<td class="right" style="min-width: 60px">'.price($objp->total_ht).'</td>';
899  print '<td class="right" style="min-width: 60px" class="nowrap">'.$propal_static->LibStatut($objp->fk_statut, 5).'</td></tr>';
900  $i++;
901  }
902  $db->free($resql);
903 
904  if ($num > 0) {
905  print "</table>";
906  print '</div>';
907  }
908  } else {
909  dol_print_error($db);
910  }
911  }
912 
913  /*
914  * Latest orders
915  */
916  if (!empty($conf->commande->enabled) && $user->rights->commande->lire) {
917  $param ="";
918 
919  $sql = "SELECT s.nom, s.rowid";
920  $sql .= ", c.rowid as cid, c.entity, c.total_ht";
921  $sql .= ", c.total_tva";
922  $sql .= ", c.total_ttc";
923  $sql .= ", c.ref, c.ref_client, c.fk_statut, c.facture";
924  $sql .= ", c.date_commande as dc";
925  $sql .= ", c.facture as billed";
926  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande as c";
927  $sql .= " WHERE c.fk_soc = s.rowid ";
928  $sql .= " AND s.rowid = ".((int) $object->id);
929  $sql .= " AND c.entity IN (".getEntity('commande').')';
930  $sql .= " ORDER BY c.date_commande DESC";
931 
932  $resql = $db->query($sql);
933  if ($resql) {
934  $commande_static = new Commande($db);
935 
936  $num = $db->num_rows($resql);
937  if ($num > 0) {
938  // Check if there are orders billable
939  $sql2 = 'SELECT s.nom, s.rowid as socid, s.client, c.rowid, c.ref, c.total_ht, c.ref_client,';
940  $sql2 .= ' c.date_valid, c.date_commande, c.date_livraison, c.fk_statut, c.facture as billed';
941  $sql2 .= ' FROM '.MAIN_DB_PREFIX.'societe as s';
942  $sql2 .= ', '.MAIN_DB_PREFIX.'commande as c';
943  $sql2 .= ' WHERE c.fk_soc = s.rowid';
944  $sql2 .= ' AND s.rowid = '.((int) $object->id);
945  // Show orders with status validated, shipping started and delivered (well any order we can bill)
946  $sql2 .= " AND ((c.fk_statut IN (1,2)) OR (c.fk_statut = 3 AND c.facture = 0))";
947 
948  $resql2 = $db->query($sql2);
949  $orders2invoice = $db->num_rows($resql2);
950  $db->free($resql2);
951 
952  print '<div class="div-table-responsive-no-min">';
953  print '<table class="noborder centpercent lastrecordtable">';
954 
955  print '<tr class="liste_titre">';
956  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>';
957  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>';
958  print '</tr></table></td>';
959  print '</tr>';
960  }
961 
962  $i = 0;
963  while ($i < $num && $i < $MAXLIST) {
964  $objp = $db->fetch_object($resql);
965 
966  $commande_static->id = $objp->cid;
967  $commande_static->ref = $objp->ref;
968  $commande_static->ref_client = $objp->ref_client;
969  $commande_static->total_ht = $objp->total_ht;
970  $commande_static->total_tva = $objp->total_tva;
971  $commande_static->total_ttc = $objp->total_ttc;
972  $commande_static->billed = $objp->billed;
973 
974  print '<tr class="oddeven">';
975  print '<td class="nowraponall">';
976  print $commande_static->getNomUrl(1);
977  // Preview
978  $filedir = $conf->commande->multidir_output[$objp->entity].'/'.dol_sanitizeFileName($objp->ref);
979  $file_list = null;
980  if (!empty($filedir)) {
981  $file_list = dol_dir_list($filedir, 'files', 0, '', '(\.meta|_preview.*.*\.png)$', 'date', SORT_DESC);
982  }
983  if (is_array($file_list)) {
984  // Defined relative dir to DOL_DATA_ROOT
985  $relativedir = '';
986  if ($filedir) {
987  $relativedir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $filedir);
988  $relativedir = preg_replace('/^[\\/]/', '', $relativedir);
989  }
990  // Get list of files stored into database for same relative directory
991  if ($relativedir) {
992  completeFileArrayWithDatabaseInfo($file_list, $relativedir);
993 
994  //var_dump($sortfield.' - '.$sortorder);
995  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)
996  $file_list = dol_sort_array($file_list, $sortfield, $sortorder);
997  }
998  }
999  $relativepath = dol_sanitizeFileName($objp->ref).'/'.dol_sanitizeFileName($objp->ref).'.pdf';
1000  print $formfile->showPreview($file_list, $commande_static->element, $relativepath, 0, $param);
1001  }
1002  // $filename = dol_sanitizeFileName($objp->ref);
1003  // $filedir = $conf->order->multidir_output[$objp->entity].'/'.dol_sanitizeFileName($objp->ref);
1004  // $urlsource = '/commande/card.php?id='.$objp->cid;
1005  // print $formfile->getDocumentsLink($commande_static->element, $filename, $filedir);
1006  print '</td>';
1007 
1008  print '<td class="right" width="80px">'.dol_print_date($db->jdate($objp->dc), 'day')."</td>\n";
1009  print '<td class="right" style="min-width: 60px">'.price($objp->total_ht).'</td>';
1010  print '<td class="right" style="min-width: 60px" class="nowrap">'.$commande_static->LibStatut($objp->fk_statut, $objp->facture, 5).'</td></tr>';
1011  $i++;
1012  }
1013  $db->free($resql);
1014 
1015  if ($num > 0) {
1016  print "</table>";
1017  print '</div>';
1018  }
1019  } else {
1020  dol_print_error($db);
1021  }
1022  }
1023 
1024  /*
1025  * Latest shipments
1026  */
1027  if (!empty($conf->expedition->enabled) && $user->rights->expedition->lire) {
1028  $sql = 'SELECT e.rowid as id';
1029  $sql .= ', e.ref, e.entity';
1030  $sql .= ', e.date_creation';
1031  $sql .= ', e.fk_statut as statut';
1032  $sql .= ', s.nom';
1033  $sql .= ', s.rowid as socid';
1034  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."expedition as e";
1035  $sql .= " WHERE e.fk_soc = s.rowid AND s.rowid = ".((int) $object->id);
1036  $sql .= " AND e.entity IN (".getEntity('expedition').")";
1037  $sql .= ' GROUP BY e.rowid';
1038  $sql .= ', e.ref, e.entity';
1039  $sql .= ', e.date_creation';
1040  $sql .= ', e.fk_statut';
1041  $sql .= ', s.nom';
1042  $sql .= ', s.rowid';
1043  $sql .= " ORDER BY e.date_creation DESC";
1044 
1045  $resql = $db->query($sql);
1046  if ($resql) {
1047  $sendingstatic = new Expedition($db);
1048 
1049  $num = $db->num_rows($resql);
1050  if ($num > 0) {
1051  print '<div class="div-table-responsive-no-min">';
1052  print '<table class="noborder centpercent lastrecordtable">';
1053 
1054  print '<tr class="liste_titre">';
1055  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>';
1056  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>';
1057  print '</tr></table></td>';
1058  print '</tr>';
1059  }
1060 
1061  $i = 0;
1062  while ($i < $num && $i < $MAXLIST) {
1063  $objp = $db->fetch_object($resql);
1064 
1065  $sendingstatic->id = $objp->id;
1066  $sendingstatic->ref = $objp->ref;
1067 
1068  print '<tr class="oddeven">';
1069  print '<td class="nowraponall">';
1070  print $sendingstatic->getNomUrl(1);
1071  // Preview
1072  $filedir = $conf->expedition->multidir_output[$objp->entity].'/'.dol_sanitizeFileName($objp->ref);
1073  $file_list = null;
1074  if (!empty($filedir)) {
1075  $file_list = dol_dir_list($filedir, 'files', 0, '', '(\.meta|_preview.*.*\.png)$', 'date', SORT_DESC);
1076  }
1077  if (is_array($file_list)) {
1078  // Defined relative dir to DOL_DATA_ROOT
1079  $relativedir = '';
1080  if ($filedir) {
1081  $relativedir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $filedir);
1082  $relativedir = preg_replace('/^[\\/]/', '', $relativedir);
1083  }
1084  // Get list of files stored into database for same relative directory
1085  if ($relativedir) {
1086  completeFileArrayWithDatabaseInfo($file_list, $relativedir);
1087 
1088  //var_dump($sortfield.' - '.$sortorder);
1089  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)
1090  $file_list = dol_sort_array($file_list, $sortfield, $sortorder);
1091  }
1092  }
1093  $relativepath = dol_sanitizeFileName($objp->ref).'/'.dol_sanitizeFileName($objp->ref).'.pdf';
1094  print $formfile->showPreview($file_list, $sendingstatic->element, $relativepath, 0, $param);
1095  }
1096  // $filename = dol_sanitizeFileName($objp->ref);
1097  // $filedir = $conf->expedition->multidir_output[$objp->entity].'/'.dol_sanitizeFileName($objp->ref);
1098  // $urlsource = '/expedition/card.php?id='.$objp->cid;
1099  // print $formfile->getDocumentsLink($sendingstatic->element, $filename, $filedir);
1100  print '</td>';
1101  if ($objp->date_creation > 0) {
1102  print '<td class="right" width="80px">'.dol_print_date($db->jdate($objp->date_creation), 'day').'</td>';
1103  } else {
1104  print '<td class="right"><b>!!!</b></td>';
1105  }
1106 
1107  print '<td class="nowrap right" width="100" >'.$sendingstatic->LibStatut($objp->statut, 5).'</td>';
1108  print "</tr>\n";
1109  $i++;
1110  }
1111  $db->free($resql);
1112 
1113  if ($num > 0) {
1114  print "</table>";
1115  print '</div>';
1116  }
1117  } else {
1118  dol_print_error($db);
1119  }
1120  }
1121 
1122  /*
1123  * Latest contracts
1124  */
1125  if (!empty($conf->contrat->enabled) && $user->rights->contrat->lire) {
1126  $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,";
1127  $sql .= " c.last_main_doc, c.model_pdf";
1128  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."contrat as c";
1129  $sql .= " WHERE c.fk_soc = s.rowid ";
1130  $sql .= " AND s.rowid = ".((int) $object->id);
1131  $sql .= " AND c.entity IN (".getEntity('contract').")";
1132  $sql .= " ORDER BY c.datec DESC";
1133 
1134  $resql = $db->query($sql);
1135  if ($resql) {
1136  $contrat = new Contrat($db);
1137 
1138  $num = $db->num_rows($resql);
1139  if ($num > 0) {
1140  print '<div class="div-table-responsive-no-min">';
1141  print '<table class="noborder centpercent lastrecordtable">';
1142 
1143  print '<tr class="liste_titre">';
1144  print '<td colspan="5"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("LastContracts", ($num <= $MAXLIST ? "" : $MAXLIST)).'</td>';
1145  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>';
1146  //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>';
1147  print '</tr></table></td>';
1148  print '</tr>';
1149  }
1150 
1151  $i = 0;
1152  while ($i < $num && $i < $MAXLIST) {
1153  $objp = $db->fetch_object($resql);
1154 
1155  $contrat->id = $objp->id;
1156  $contrat->ref = $objp->ref ? $objp->ref : $objp->id;
1157  $contrat->ref_customer = $objp->refcus;
1158  $contrat->ref_supplier = $objp->refsup;
1159  $contrat->statut = $objp->contract_status;
1160  $contrat->last_main_doc = $objp->last_main_doc;
1161  $contrat->model_pdf = $objp->model_pdf;
1162  $contrat->fetch_lines();
1163 
1164  $late = '';
1165  foreach ($contrat->lines as $line) {
1166  if ($contrat->statut == Contrat::STATUS_VALIDATED && $line->statut == ContratLigne::STATUS_OPEN) {
1167  if (((!empty($line->date_fin_validite) ? $line->date_fin_validite : 0) + $conf->contrat->services->expires->warning_delay) < $now) {
1168  $late = img_warning($langs->trans("Late"));
1169  }
1170  }
1171  }
1172 
1173  print '<tr class="oddeven">';
1174  print '<td class="nowraponall">';
1175  print $contrat->getNomUrl(1, 12);
1176  if (!empty($contrat->model_pdf)) {
1177  // Preview
1178  $filedir = $conf->contrat->multidir_output[$objp->entity].'/'.dol_sanitizeFileName($objp->ref);
1179  $file_list = null;
1180  if (!empty($filedir)) {
1181  $file_list = dol_dir_list($filedir, 'files', 0, '', '(\.meta|_preview.*.*\.png)$', 'date', SORT_DESC);
1182  }
1183  if (is_array($file_list)) {
1184  // Defined relative dir to DOL_DATA_ROOT
1185  $relativedir = '';
1186  if ($filedir) {
1187  $relativedir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $filedir);
1188  $relativedir = preg_replace('/^[\\/]/', '', $relativedir);
1189  }
1190  // Get list of files stored into database for same relative directory
1191  if ($relativedir) {
1192  completeFileArrayWithDatabaseInfo($file_list, $relativedir);
1193 
1194  //var_dump($sortfield.' - '.$sortorder);
1195  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)
1196  $file_list = dol_sort_array($file_list, $sortfield, $sortorder);
1197  }
1198  }
1199  $relativepath = dol_sanitizeFileName($objp->ref).'/'.dol_sanitizeFileName($objp->ref).'.pdf';
1200  print $formfile->showPreview($file_list, $contrat->element, $relativepath, 0);
1201  }
1202  }
1203  // $filename = dol_sanitizeFileName($objp->ref);
1204  // $filedir = $conf->contrat->multidir_output[$objp->entity].'/'.dol_sanitizeFileName($objp->ref);
1205  // $urlsource = '/contrat/card.php?id='.$objp->cid;
1206  // print $formfile->getDocumentsLink($contrat->element, $filename, $filedir);
1207  print $late;
1208  print "</td>\n";
1209  print '<td class="nowrap">'.dol_trunc($objp->refsup, 12)."</td>\n";
1210  //print '<td class="right" width="80px"><span title="'.$langs->trans("DateCreation").'">'.dol_print_date($db->jdate($objp->dc), 'day')."</span></td>\n";
1211  print '<td class="right" width="80px"><span title="'.$langs->trans("DateContract").'">'.dol_print_date($db->jdate($objp->dcon), 'day')."</span></td>\n";
1212  print '<td width="20">&nbsp;</td>';
1213  print '<td class="nowraponall right">';
1214  print $contrat->getLibStatut(4);
1215  print "</td>\n";
1216  print '</tr>';
1217  $i++;
1218  }
1219  $db->free($resql);
1220 
1221  if ($num > 0) {
1222  print "</table>";
1223  print '</div>';
1224  }
1225  } else {
1226  dol_print_error($db);
1227  }
1228  }
1229 
1230  /*
1231  * Latest interventions
1232  */
1233  if (!empty($conf->ficheinter->enabled) && $user->rights->ficheinter->lire) {
1234  $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";
1235  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."fichinter as f";
1236  $sql .= " WHERE f.fk_soc = s.rowid";
1237  $sql .= " AND s.rowid = ".((int) $object->id);
1238  $sql .= " AND f.entity IN (".getEntity('intervention').")";
1239  $sql .= " ORDER BY f.tms DESC";
1240 
1241  $resql = $db->query($sql);
1242  if ($resql) {
1243  $fichinter_static = new Fichinter($db);
1244 
1245  $num = $db->num_rows($resql);
1246  if ($num > 0) {
1247  print '<div class="div-table-responsive-no-min">';
1248  print '<table class="noborder centpercent lastrecordtable">';
1249 
1250  print '<tr class="liste_titre">';
1251  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>';
1252  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>';
1253  print '</tr></table></td>';
1254  print '</tr>';
1255  }
1256 
1257  $i = 0;
1258  while ($i < $num && $i < $MAXLIST) {
1259  $objp = $db->fetch_object($resql);
1260 
1261  $fichinter_static->id = $objp->id;
1262  $fichinter_static->ref = $objp->ref;
1263  $fichinter_static->statut = $objp->fk_statut;
1264 
1265  print '<tr class="oddeven">';
1266  print '<td class="nowraponall">';
1267  print $fichinter_static->getNomUrl(1);
1268  // Preview
1269  $filedir = $conf->ficheinter->multidir_output[$objp->entity].'/'.dol_sanitizeFileName($objp->ref);
1270  $file_list = null;
1271  if (!empty($filedir)) {
1272  $file_list = dol_dir_list($filedir, 'files', 0, '', '(\.meta|_preview.*.*\.png)$', 'date', SORT_DESC);
1273  }
1274  if (is_array($file_list)) {
1275  // Defined relative dir to DOL_DATA_ROOT
1276  $relativedir = '';
1277  if ($filedir) {
1278  $relativedir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $filedir);
1279  $relativedir = preg_replace('/^[\\/]/', '', $relativedir);
1280  }
1281  // Get list of files stored into database for same relative directory
1282  if ($relativedir) {
1283  completeFileArrayWithDatabaseInfo($file_list, $relativedir);
1284 
1285  //var_dump($sortfield.' - '.$sortorder);
1286  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)
1287  $file_list = dol_sort_array($file_list, $sortfield, $sortorder);
1288  }
1289  }
1290  $relativepath = dol_sanitizeFileName($objp->ref).'/'.dol_sanitizeFileName($objp->ref).'.pdf';
1291  print $formfile->showPreview($file_list, $fichinter_static->element, $relativepath, 0);
1292  }
1293  // $filename = dol_sanitizeFileName($objp->ref);
1294  // $filedir = $conf->fichinter->multidir_output[$objp->entity].'/'.dol_sanitizeFileName($objp->ref);
1295  // $urlsource = '/fichinter/card.php?id='.$objp->cid;
1296  // print $formfile->getDocumentsLink($fichinter_static->element, $filename, $filedir);
1297  print '</td>'."\n";
1298  //print '<td class="right" width="80px">'.dol_print_date($db->jdate($objp->startdate)).'</td>'."\n";
1299  print '<td class="right" style="min-width: 60px">'.convertSecondToTime($objp->duration).'</td>'."\n";
1300  print '<td class="nowrap right" style="min-width: 60px">'.$fichinter_static->getLibStatut(5).'</td>'."\n";
1301  print '</tr>';
1302 
1303  $i++;
1304  }
1305  $db->free($resql);
1306 
1307  if ($num > 0) {
1308  print "</table>";
1309  print '</div>';
1310  }
1311  } else {
1312  dol_print_error($db);
1313  }
1314  }
1315 
1316  /*
1317  * Latest invoices templates
1318  */
1319  if (isModEnabled('facture') && $user->rights->facture->lire) {
1320  $sql = 'SELECT f.rowid as id, f.titre as ref';
1321  $sql .= ', f.total_ht';
1322  $sql .= ', f.total_tva';
1323  $sql .= ', f.total_ttc';
1324  $sql .= ', f.datec as dc';
1325  $sql .= ', f.date_last_gen, f.date_when';
1326  $sql .= ', f.frequency';
1327  $sql .= ', f.unit_frequency';
1328  $sql .= ', f.suspended as suspended';
1329  $sql .= ', s.nom, s.rowid as socid';
1330  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture_rec as f";
1331  $sql .= " WHERE f.fk_soc = s.rowid AND s.rowid = ".((int) $object->id);
1332  $sql .= " AND f.entity IN (".getEntity('invoice').")";
1333  $sql .= ' GROUP BY f.rowid, f.titre, f.total_ht, f.total_tva, f.total_ttc,';
1334  $sql .= ' f.date_last_gen, f.datec, f.frequency, f.unit_frequency,';
1335  $sql .= ' f.suspended, f.date_when,';
1336  $sql .= ' s.nom, s.rowid';
1337  $sql .= " ORDER BY f.date_last_gen, f.datec DESC";
1338 
1339  $resql = $db->query($sql);
1340  if ($resql) {
1341  $invoicetemplate = new FactureRec($db);
1342 
1343  $num = $db->num_rows($resql);
1344  if ($num > 0) {
1345  print '<div class="div-table-responsive-no-min">';
1346  print '<table class="noborder centpercent lastrecordtable">';
1347 
1348  print '<tr class="liste_titre">';
1349  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>';
1350  print '</tr></table></td>';
1351  print '</tr>';
1352  }
1353 
1354  $i = 0;
1355  while ($i < $num && $i < $MAXLIST) {
1356  $objp = $db->fetch_object($resql);
1357 
1358  $invoicetemplate->id = $objp->id;
1359  $invoicetemplate->ref = $objp->ref;
1360  $invoicetemplate->suspended = $objp->suspended;
1361  $invoicetemplate->frequency = $objp->frequency;
1362  $invoicetemplate->unit_frequency = $objp->unit_frequency;
1363  $invoicetemplate->total_ht = $objp->total_ht;
1364  $invoicetemplate->total_tva = $objp->total_tva;
1365  $invoicetemplate->total_ttc = $objp->total_ttc;
1366  $invoicetemplate->date_last_gen = $objp->date_last_gen;
1367  $invoicetemplate->date_when = $objp->date_when;
1368 
1369  print '<tr class="oddeven">';
1370  print '<td class="nowrap">';
1371  print $invoicetemplate->getNomUrl(1);
1372  print '</td>';
1373 
1374  if ($objp->frequency && $objp->date_last_gen > 0) {
1375  print '<td class="right" width="80px">'.dol_print_date($db->jdate($objp->date_last_gen), 'day').'</td>';
1376  } else {
1377  if ($objp->dc > 0) {
1378  print '<td class="right" width="80px">'.dol_print_date($db->jdate($objp->dc), 'day').'</td>';
1379  } else {
1380  print '<td class="right"><b>!!!</b></td>';
1381  }
1382  }
1383  print '<td class="right" style="min-width: 60px">';
1384  print price($objp->total_ht);
1385  print '</td>';
1386 
1387  if (!empty($conf->global->MAIN_SHOW_PRICE_WITH_TAX_IN_SUMMARIES)) {
1388  print '<td class="right" style="min-width: 60px">';
1389  print price($objp->total_ttc);
1390  print '</td>';
1391  }
1392 
1393  print '<td class="nowrap right" style="min-width: 60px">';
1394  print $langs->trans('FrequencyPer_'.$invoicetemplate->unit_frequency, $invoicetemplate->frequency).' - ';
1395  print ($invoicetemplate->LibStatut($invoicetemplate->frequency, $invoicetemplate->suspended, 5, 0));
1396  print '</td>';
1397  print "</tr>\n";
1398  $i++;
1399  }
1400  $db->free($resql);
1401 
1402  if ($num > 0) {
1403  print "</table>";
1404  print '</div>';
1405  }
1406  } else {
1407  dol_print_error($db);
1408  }
1409  }
1410 
1411  /*
1412  * Latest invoices
1413  */
1414  if (isModEnabled('facture') && $user->rights->facture->lire) {
1415  $sql = 'SELECT f.rowid as facid, f.ref, f.type';
1416  $sql .= ', f.total_ht';
1417  $sql .= ', f.total_tva';
1418  $sql .= ', f.total_ttc';
1419  $sql .= ', f.entity';
1420  $sql .= ', f.datef as df, f.datec as dc, f.paye as paye, f.fk_statut as status';
1421  $sql .= ', s.nom, s.rowid as socid';
1422  $sql .= ', SUM(pf.amount) as am';
1423  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f";
1424  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON f.rowid=pf.fk_facture';
1425  $sql .= " WHERE f.fk_soc = s.rowid AND s.rowid = ".((int) $object->id);
1426  $sql .= " AND f.entity IN (".getEntity('invoice').")";
1427  $sql .= ' GROUP BY f.rowid, f.ref, f.type, f.total_ht, f.total_tva, f.total_ttc,';
1428  $sql .= ' f.entity, f.datef, f.datec, f.paye, f.fk_statut,';
1429  $sql .= ' s.nom, s.rowid';
1430  $sql .= " ORDER BY f.datef DESC, f.datec DESC";
1431 
1432  $resql = $db->query($sql);
1433  if ($resql) {
1434  $facturestatic = new Facture($db);
1435 
1436  $num = $db->num_rows($resql);
1437  if ($num > 0) {
1438  print '<div class="div-table-responsive-no-min">';
1439  print '<table class="noborder centpercent lastrecordtable">';
1440 
1441  print '<tr class="liste_titre">';
1442  print '<td colspan="5"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("LastCustomersBills", ($num <= $MAXLIST ? "" : $MAXLIST)).'</td><td class="right"><a class="notasortlink" href="'.DOL_URL_ROOT.'/compta/facture/list.php?socid='.$object->id.'">'.$langs->trans("AllBills").'<span class="badge marginleftonlyshort">'.$num.'</span></a></td>';
1443  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>';
1444  print '</tr></table></td>';
1445  print '</tr>';
1446  }
1447 
1448  $i = 0;
1449  while ($i < $num && $i < $MAXLIST) {
1450  $objp = $db->fetch_object($resql);
1451 
1452  $facturestatic->id = $objp->facid;
1453  $facturestatic->ref = $objp->ref;
1454  $facturestatic->type = $objp->type;
1455  $facturestatic->total_ht = $objp->total_ht;
1456  $facturestatic->total_tva = $objp->total_tva;
1457  $facturestatic->total_ttc = $objp->total_ttc;
1458  $facturestatic->statut = $objp->status;
1459 
1460  print '<tr class="oddeven">';
1461  print '<td class="nowraponall">';
1462  print $facturestatic->getNomUrl(1);
1463  // Preview
1464  $filedir = $conf->facture->multidir_output[$objp->entity].'/'.dol_sanitizeFileName($objp->ref);
1465  $file_list = null;
1466  if (!empty($filedir)) {
1467  $file_list = dol_dir_list($filedir, 'files', 0, '', '(\.meta|_preview.*.*\.png)$', 'date', SORT_DESC);
1468  }
1469  if (is_array($file_list)) {
1470  // Defined relative dir to DOL_DATA_ROOT
1471  $relativedir = '';
1472  if ($filedir) {
1473  $relativedir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $filedir);
1474  $relativedir = preg_replace('/^[\\/]/', '', $relativedir);
1475  }
1476  // Get list of files stored into database for same relative directory
1477  if ($relativedir) {
1478  completeFileArrayWithDatabaseInfo($file_list, $relativedir);
1479 
1480  //var_dump($sortfield.' - '.$sortorder);
1481  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)
1482  $file_list = dol_sort_array($file_list, $sortfield, $sortorder);
1483  }
1484  }
1485  $relativepath = dol_sanitizeFileName($objp->ref).'/'.dol_sanitizeFileName($objp->ref).'.pdf';
1486  print $formfile->showPreview($file_list, $facturestatic->element, $relativepath, 0);
1487  }
1488  // $filename = dol_sanitizeFileName($objp->ref);
1489  // $filedir = $conf->facture->multidir_output[$objp->entity].'/'.dol_sanitizeFileName($objp->ref);
1490  // $urlsource = '/compta/facture/card.php?id='.$objp->cid;
1491  //print $formfile->getDocumentsLink($facturestatic->element, $filename, $filedir);
1492  print '</td>';
1493  if ($objp->df > 0) {
1494  print '<td class="right" width="80px">'.dol_print_date($db->jdate($objp->df), 'day').'</td>';
1495  } else {
1496  print '<td class="right"><b>!!!</b></td>';
1497  }
1498  print '<td class="right" style="min-width: 60px">';
1499  print price($objp->total_ht);
1500  print '</td>';
1501 
1502  if (!empty($conf->global->MAIN_SHOW_PRICE_WITH_TAX_IN_SUMMARIES)) {
1503  print '<td class="right" style="min-width: 60px">';
1504  print price($objp->total_ttc);
1505  print '</td>';
1506  }
1507 
1508  print '<td class="nowrap right" style="min-width: 60px">'.($facturestatic->LibStatut($objp->paye, $objp->status, 5, $objp->am)).'</td>';
1509  print "</tr>\n";
1510  $i++;
1511  }
1512  $db->free($resql);
1513 
1514  if ($num > 0) {
1515  print "</table>";
1516  print '</div>';
1517  }
1518  } else {
1519  dol_print_error($db);
1520  }
1521  }
1522 
1523  // Allow external modules to add their own shortlist of recent objects
1524  $parameters = array();
1525  $reshook = $hookmanager->executeHooks('addMoreRecentObjects', $parameters, $object, $action);
1526  if ($reshook < 0) {
1527  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1528  } else {
1529  print $hookmanager->resPrint;
1530  }
1531 
1532  print '</div></div>';
1533  print '<div style="clear:both"></div>';
1534 
1535  print dol_get_fiche_end();
1536 
1537 
1538  /*
1539  * Action bar
1540  */
1541  print '<div class="tabsAction">';
1542 
1543  $parameters = array();
1544  $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
1545 
1546  if (empty($reshook)) {
1547  if ($object->status != 1) {
1548  print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" title="'.dol_escape_js($langs->trans("ThirdPartyIsClosed")).'" href="#">'.$langs->trans("ThirdPartyIsClosed").'</a></div>';
1549  }
1550 
1551  if (!empty($conf->propal->enabled) && $user->rights->propal->creer && $object->status == 1) {
1552  $langs->load("propal");
1553  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>';
1554  }
1555 
1556  if (!empty($conf->commande->enabled) && $user->rights->commande->creer && $object->status == 1) {
1557  $langs->load("orders");
1558  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>';
1559  }
1560 
1561  if (!empty($user->rights->contrat->creer) && $object->status == 1) {
1562  $langs->load("contracts");
1563  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>';
1564  }
1565 
1566  if (!empty($conf->ficheinter->enabled) && $user->rights->ficheinter->creer && $object->status == 1) {
1567  $langs->load("fichinter");
1568  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>';
1569  }
1570 
1571  // Add invoice
1572  if ($user->socid == 0) {
1573  if (!empty($conf->deplacement->enabled) && $object->status == 1) {
1574  $langs->load("trips");
1575  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>';
1576  }
1577 
1578  if (isModEnabled('facture') && $object->status == 1) {
1579  if (empty($user->rights->facture->creer)) {
1580  print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" title="'.dol_escape_js($langs->trans("NotAllowed")).'" href="#">'.$langs->trans("AddBill").'</a></div>';
1581  } else {
1582  $langs->loadLangs(array("orders", "bills"));
1583 
1584  if (!empty($conf->commande->enabled)) {
1585  if ($object->client != 0 && $object->client != 2) {
1586  if (!empty($orders2invoice) && $orders2invoice > 0) {
1587  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>';
1588  } else {
1589  print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" title="'.dol_escape_js($langs->trans("NoOrdersToInvoice")).'" href="#">'.$langs->trans("CreateInvoiceForThisCustomer").'</a></div>';
1590  }
1591  } else {
1592  print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" title="'.dol_escape_js($langs->trans("ThirdPartyMustBeEditAsCustomer")).'" href="#">'.$langs->trans("AddBill").'</a></div>';
1593  }
1594  }
1595 
1596  if ($object->client != 0 && $object->client != 2) {
1597  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>';
1598  } else {
1599  print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" title="'.dol_escape_js($langs->trans("ThirdPartyMustBeEditAsCustomer")).'" href="#">'.$langs->trans("AddBill").'</a></div>';
1600  }
1601  }
1602  }
1603  }
1604 
1605  // Add action
1606  if (isModEnabled('agenda') && !empty($conf->global->MAIN_REPEATTASKONEACHTAB) && $object->status == 1) {
1607  if ($user->rights->agenda->myactions->create) {
1608  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>';
1609  } else {
1610  print '<div class="inline-block divButAction"><a class="butAction" title="'.dol_escape_js($langs->trans("NotAllowed")).'" href="#">'.$langs->trans("AddAction").'</a></div>';
1611  }
1612  }
1613  }
1614 
1615  print '</div>';
1616 
1617  if (!empty($conf->global->MAIN_DUPLICATE_CONTACTS_TAB_ON_CUSTOMER_CARD)) {
1618  // List of contacts
1619  show_contacts($conf, $langs, $db, $object, $_SERVER["PHP_SELF"].'?socid='.$object->id);
1620  }
1621 
1622  if (!empty($conf->global->MAIN_REPEATTASKONEACHTAB)) {
1623  print load_fiche_titre($langs->trans("ActionsOnCompany"), '', '');
1624 
1625  // List of todo actions
1626  show_actions_todo($conf, $langs, $db, $object);
1627 
1628  // List of done actions
1629  show_actions_done($conf, $langs, $db, $object);
1630  }
1631 } else {
1632  $langs->load("errors");
1633  print $langs->trans('ErrorRecordNotFound');
1634 }
1635 
1636 // End of page
1637 llxFooter();
1638 $db->close();
yn
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
Definition: functions.lib.php:6491
dol_escape_htmltag
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
Definition: functions.lib.php:1468
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1226
restrictedArea
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
Definition: security.lib.php:234
Expedition
Class to manage shipments.
Definition: expedition.class.php:52
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
img_action
img_action($titlealt, $numaction, $picto='')
Show logo action.
Definition: functions.lib.php:4296
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
dol_sort_array
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by second index function, which produces ascending (default) or descending output...
Definition: functions.lib.php:8385
FactureRec
Class to manage invoice templates.
Definition: facture-rec.class.php:40
img_warning
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
Definition: functions.lib.php:4521
show_actions_todo
show_actions_todo($conf, $langs, $db, $filterobj, $objcon='', $noprint=0, $actioncode='')
Show html area with actions to do.
Definition: company.lib.php:1358
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
dol_dir_list
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:60
Facture
Class to manage invoices.
Definition: facture.class.php:60
dol_clone
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
Definition: functions.lib.php:1158
img_edit
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
Definition: functions.lib.php:4389
dol_banner_tab
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
Definition: functions.lib.php:2046
$help_url
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:116
price2num
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
Definition: functions.lib.php:5661
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2514
FormCompany
Class to build HTML component for third parties management Only common components are here.
Definition: html.formcompany.class.php:40
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
dol_getIdFromCode
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='')
Return an id or code from a code or id.
Definition: functions.lib.php:8535
FormFile
Class to offer components to list and upload files.
Definition: html.formfile.class.php:36
showValueWithClipboardCPButton
showValueWithClipboardCPButton($valuetocopy, $showonlyonhover=1, $texttoshow='')
Create a button to copy $valuetocopy in the clipboard (for copy and paste feature).
Definition: functions.lib.php:11087
Commande
Class to manage customers orders.
Definition: commande.class.php:46
show_actions_done
show_actions_done($conf, $langs, $db, $filterobj, $objcon='', $noprint=0, $actioncode='', $donetodo='done', $filters=array(), $sortfield='a.datep, a.id', $sortorder='DESC', $module='')
Show html area with actions (done or not, ignore the name of function).
Definition: company.lib.php:1389
completeFileArrayWithDatabaseInfo
completeFileArrayWithDatabaseInfo(&$filearray, $relativedir)
Complete $filearray with data from database.
Definition: files.lib.php:310
show_contacts
show_contacts($conf, $langs, $db, $object, $backtopage='', $showuserlogin=0)
Show html area for list of contacts.
Definition: company.lib.php:907
Contact
Class to manage contact/addresses.
Definition: contact.class.php:40
Adherent
Class to manage members of a foundation.
Definition: adherent.class.php:46
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
societe_prepare_head
societe_prepare_head(Societe $object)
Return array of tabs to used on pages for third parties cards.
Definition: company.lib.php:42
FormProduct
Class with static methods for building HTML components related to products Only components common to ...
Definition: html.formproduct.class.php:30
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:10878
Fichinter
Class to manage interventions.
Definition: fichinter.class.php:37
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:105
Contrat
Class to manage contracts.
Definition: contrat.class.php:43
User
Class to manage Dolibarr users.
Definition: user.class.php:44
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
ExtraFields
Class to manage standard extra fields.
Definition: extrafields.class.php:39
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
$parameters
$parameters
Actions.
Definition: card.php:78
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
price
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
Definition: functions.lib.php:5541
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933
Propal
Class to manage proposals.
Definition: propal.class.php:52
Client
Class to manage customers or prospects.
Definition: client.class.php:31
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59