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