dolibarr 18.0.6
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
36require '../main.inc.php';
37require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
38require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
39require_once DOL_DOCUMENT_ROOT.'/societe/class/client.class.php';
40require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
41require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
42require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
43require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
44if (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}
48if (isModEnabled("propal")) {
49 require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
50}
51if (isModEnabled('commande')) {
52 require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
53}
54if (isModEnabled("expedition")) {
55 require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
56}
57if (isModEnabled('contrat')) {
58 require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
59}
60if (isModEnabled('adherent')) {
61 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
62}
63if (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
70if (isModEnabled('contrat')) {
71 $langs->load("contracts");
72}
73if (isModEnabled('commande')) {
74 $langs->load("orders");
75}
76if (isModEnabled("expedition")) {
77 $langs->load("sendings");
78}
79if (isModEnabled('facture')) {
80 $langs->load("bills");
81}
82if (isModEnabled('project')) {
83 $langs->load("projects");
84}
85if (isModEnabled('ficheinter')) {
86 $langs->load("interventions");
87}
88if (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');
100if (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;
106if (!$sortorder) {
107 $sortorder = "ASC";
108}
109if (!$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
126if ($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}
133if ($object->id > 0) {
134 if (!($object->client > 0) || !$user->hasRight('societe', 'lire')) {
136 }
137}
138
139// Security check
140if ($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
152if ($reshook < 0) {
153 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
154}
155
156if (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');
314if (!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
320llxHeader('', $title, $help_url);
321
322
323if ($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, dol_sanitizeFileName($objp->ref).'.pdf', '(\.meta|_preview.*.*\.png)$', 'date', SORT_DESC);
872 }
873 if (is_array($file_list) && !empty($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, dol_sanitizeFileName($objp->ref).'.pdf', '(\.meta|_preview.*.*\.png)$', 'date', SORT_DESC);
984 }
985 if (is_array($file_list) && !empty($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, dol_sanitizeFileName($objp->ref).'.pdf', '(\.meta|_preview.*.*\.png)$', 'date', SORT_DESC);
1078 }
1079 if (is_array($file_list) && !empty($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, dol_sanitizeFileName($objp->ref).'.pdf', '(\.meta|_preview.*.*\.png)$', 'date', SORT_DESC);
1184 }
1185 if (is_array($file_list) && !empty($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, dol_sanitizeFileName($objp->ref).'.pdf', '(\.meta|_preview.*.*\.png)$', 'date', SORT_DESC);
1275 }
1276 if (is_array($file_list) && !empty($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->status = $objp->status;
1462 $facturestatic->paye = $objp->paye;
1463 $facturestatic->alreadypaid = $objp->am;
1464 $facturestatic->date = $db->jdate($objp->df);
1465 $facturestatic->date_lim_reglement = $db->jdate($objp->dl);
1466
1467 print '<tr class="oddeven">';
1468 print '<td class="nowraponall">';
1469 print $facturestatic->getNomUrl(1);
1470 // Preview
1471 $filedir = $conf->facture->multidir_output[$objp->entity].'/'.dol_sanitizeFileName($objp->ref);
1472 $file_list = null;
1473 if (!empty($filedir)) {
1474 $file_list = dol_dir_list($filedir, 'files', 0, dol_sanitizeFileName($objp->ref).'.pdf', '(\.meta|_preview.*.*\.png)$', 'date', SORT_DESC);
1475 }
1476 if (is_array($file_list) && !empty($file_list)) {
1477 // Defined relative dir to DOL_DATA_ROOT
1478 $relativedir = '';
1479 if ($filedir) {
1480 $relativedir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $filedir);
1481 $relativedir = preg_replace('/^[\\/]/', '', $relativedir);
1482 }
1483 // Get list of files stored into database for same relative directory
1484 if ($relativedir) {
1485 completeFileArrayWithDatabaseInfo($file_list, $relativedir);
1486
1487 //var_dump($sortfield.' - '.$sortorder);
1488 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)
1489 $file_list = dol_sort_array($file_list, $sortfield, $sortorder);
1490 }
1491 }
1492 $relativepath = dol_sanitizeFileName($objp->ref).'/'.dol_sanitizeFileName($objp->ref).'.pdf';
1493 print $formfile->showPreview($file_list, $facturestatic->element, $relativepath, 0);
1494 }
1495 // $filename = dol_sanitizeFileName($objp->ref);
1496 // $filedir = $conf->facture->multidir_output[$objp->entity].'/'.dol_sanitizeFileName($objp->ref);
1497 // $urlsource = '/compta/facture/card.php?id='.$objp->cid;
1498 //print $formfile->getDocumentsLink($facturestatic->element, $filename, $filedir);
1499 print '</td>';
1500 if ($objp->df > 0) {
1501 print '<td width="80px" title="'.dol_escape_htmltag($langs->trans('DateInvoice')).'">'.dol_print_date($db->jdate($objp->df), 'day').'</td>';
1502 } else {
1503 print '<td><b>!!!</b></td>';
1504 }
1505 if ($objp->dl > 0) {
1506 print '<td width="80px" title="'.dol_escape_htmltag($langs->trans('DateMaxPayment')).'">'.dol_print_date($db->jdate($objp->dl), 'day').'</td>';
1507 } else {
1508 print '<td><b>!!!</b></td>';
1509 }
1510 print '<td class="right" style="min-width: 60px">';
1511 print price($objp->total_ht);
1512 print '</td>';
1513
1514 if (!empty($conf->global->MAIN_SHOW_PRICE_WITH_TAX_IN_SUMMARIES)) {
1515 print '<td class="right" style="min-width: 60px">';
1516 print price($objp->total_ttc);
1517 print '</td>';
1518 }
1519
1520 print '<td class="nowrap right" style="min-width: 60px">'.($facturestatic->LibStatut($objp->paye, $objp->status, 5, $objp->am)).'</td>';
1521 print "</tr>\n";
1522 $i++;
1523 }
1524 $db->free($resql);
1525
1526 if ($num > 0) {
1527 print "</table>";
1528 print '</div>';
1529 }
1530 } else {
1531 dol_print_error($db);
1532 }
1533 }
1534
1535 // Allow external modules to add their own shortlist of recent objects
1536 $parameters = array();
1537 $reshook = $hookmanager->executeHooks('addMoreRecentObjects', $parameters, $object, $action);
1538 if ($reshook < 0) {
1539 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1540 } else {
1541 print $hookmanager->resPrint;
1542 }
1543
1544 print '</div></div>';
1545 print '<div class="clearboth"></div>';
1546
1547 print dol_get_fiche_end();
1548
1549
1550 /*
1551 * Action bar
1552 */
1553 print '<div class="tabsAction">';
1554
1555 $parameters = array();
1556 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
1557
1558 if (empty($reshook)) {
1559 if ($object->status != 1) {
1560 print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" title="'.dol_escape_js($langs->trans("ThirdPartyIsClosed")).'" href="#">'.$langs->trans("ThirdPartyIsClosed").'</a></div>';
1561 }
1562
1563 if (isModEnabled("propal") && $user->hasRight('propal', 'creer') && $object->status == 1) {
1564 $langs->load("propal");
1565 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>';
1566 }
1567
1568 if (isModEnabled('commande') && $user->hasRight('commande', 'creer') && $object->status == 1) {
1569 $langs->load("orders");
1570 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>';
1571 }
1572
1573 if (!empty($user->rights->contrat->creer) && $object->status == 1) {
1574 $langs->load("contracts");
1575 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>';
1576 }
1577
1578 if (isModEnabled('ficheinter') && $user->hasRight('ficheinter', 'creer') && $object->status == 1) {
1579 $langs->load("fichinter");
1580 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>';
1581 }
1582
1583 // Add invoice
1584 if ($user->socid == 0) {
1585 if (isModEnabled('deplacement') && $object->status == 1) {
1586 $langs->load("trips");
1587 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>';
1588 }
1589
1590 if (isModEnabled('facture') && $object->status == 1) {
1591 if (empty($user->rights->facture->creer)) {
1592 $langs->load("bills");
1593 print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" title="'.dol_escape_js($langs->trans("NotAllowed")).'" href="#">'.$langs->trans("AddBill").'</a></div>';
1594 } else {
1595 $langs->loadLangs(array("orders", "bills"));
1596
1597 if (isModEnabled('commande')) {
1598 if ($object->client != 0 && $object->client != 2) {
1599 if (!empty($orders2invoice) && $orders2invoice > 0) {
1600 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>';
1601 } else {
1602 print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" title="'.dol_escape_js($langs->trans("NoOrdersToInvoice")).'" href="#">'.$langs->trans("CreateInvoiceForThisCustomer").'</a></div>';
1603 }
1604 } else {
1605 print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" title="'.dol_escape_js($langs->trans("ThirdPartyMustBeEditAsCustomer")).'" href="#">'.$langs->trans("CreateInvoiceForThisCustomer").'</a></div>';
1606 }
1607 }
1608
1609 if ($object->client != 0 && $object->client != 2) {
1610 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>';
1611 } else {
1612 print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" title="'.dol_escape_js($langs->trans("ThirdPartyMustBeEditAsCustomer")).'" href="#">'.$langs->trans("AddBill").'</a></div>';
1613 }
1614 }
1615 }
1616 }
1617
1618 // Add action
1619 if (isModEnabled('agenda') && !empty($conf->global->MAIN_REPEATTASKONEACHTAB) && $object->status == 1) {
1620 if ($user->rights->agenda->myactions->create) {
1621 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>';
1622 } else {
1623 print '<div class="inline-block divButAction"><a class="butAction" title="'.dol_escape_js($langs->trans("NotAllowed")).'" href="#">'.$langs->trans("AddAction").'</a></div>';
1624 }
1625 }
1626 }
1627
1628 print '</div>';
1629
1630 if (!empty($conf->global->MAIN_DUPLICATE_CONTACTS_TAB_ON_CUSTOMER_CARD)) {
1631 // List of contacts
1632 show_contacts($conf, $langs, $db, $object, $_SERVER["PHP_SELF"].'?socid='.$object->id);
1633 }
1634
1635 if (!empty($conf->global->MAIN_REPEATTASKONEACHTAB)) {
1636 print load_fiche_titre($langs->trans("ActionsOnCompany"), '', '');
1637
1638 // List of todo actions
1639 show_actions_todo($conf, $langs, $db, $object);
1640
1641 // List of done actions
1642 show_actions_done($conf, $langs, $db, $object);
1643 }
1644} else {
1645 $langs->load("errors");
1646 print $langs->trans('ErrorRecordNotFound');
1647}
1648
1649// End of page
1650llxFooter();
1651$db->close();
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
llxFooter()
Empty footer.
Definition wrapper.php:70
Class to manage members of a foundation.
Class to manage customers or prospects.
Class to manage customers orders.
Class to manage contact/addresses.
Class to manage contracts.
Class to manage shipments.
Class to manage standard extra fields.
Class to manage invoices.
Class to manage invoice templates.
Class to manage interventions.
Class to build HTML component for third parties management Only common components are here.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
Class with static methods for building HTML components related to products Only components common to ...
Class to manage proposals.
Class to manage Dolibarr users.
show_contacts($conf, $langs, $db, $object, $backtopage='', $showuserlogin=0)
Show html area for list of contacts.
show_actions_todo($conf, $langs, $db, $filterobj, $objcon='', $noprint=0, $actioncode='')
Show html area with actions to do.
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).
societe_prepare_head(Societe $object)
Return array of tabs to used on pages for third parties cards.
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
completeFileArrayWithDatabaseInfo(&$filearray, $relativedir)
Complete $filearray with data from database.
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.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
showValueWithClipboardCPButton($valuetocopy, $showonlyonhover=1, $texttoshow='')
Create a button to copy $valuetocopy in the clipboard (for copy and paste feature).
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
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.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
img_action($titlealt, $numaction, $picto='', $moreatt='')
Show logo action.
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.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='')
Return an id or code from a code or id.
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...
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
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...
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.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.