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