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