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