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