dolibarr 25.0.0-alpha
card.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2003 Eric Seigne <erics@rycks.com>
4 * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
5 * Copyright (C) 2005-2010 Regis Houssin <regis.houssin@inodbox.com>
6 * Copyright (C) 2010-2015 Juanjo Menent <jmenent@2byte.es>
7 * Copyright (C) 2014 Jean Heimburger <jean@tiaris.info>
8 * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
9 * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
10 * Copyright (C) 2021-2026 Frédéric France <frederic.france@free.fr>
11 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
12 * Copyright (C) 2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
13 * Copyright (C) 2026 Nick Fragoulis
14 * Copyright (C) 2026 Joachim Kueter <git-jk@bloxera.com>
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 3 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program. If not, see <https://www.gnu.org/licenses/>.
28 */
29
36// Load Dolibarr environment
37require '../main.inc.php';
47require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
48require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
49require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture-rec.class.php';
50require_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class.php';
51require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
52require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
53require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
54if (isModEnabled('member')) {
55 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
56}
57if (isModEnabled('accounting')) {
58 require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
59 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
60}
61if (isModEnabled('contract')) {
62 require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
63}
64
65// Load translation files required by page
66$langs->loadLangs(array('accountancy', 'companies', 'suppliers', 'products', 'bills', 'orders', 'commercial', 'contracts'));
67
68$action = GETPOST('action', 'aZ09');
69$cancel = GETPOST('cancel', 'alpha');
70
71$id = (GETPOSTINT('socid') ? GETPOSTINT('socid') : GETPOSTINT('id'));
72if ($user->isExternalUser()) {
73 $id = $user->isExternalUser();
74}
75
76// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
77$hookmanager->initHooks(array('thirdpartysupplier', 'globalcard'));
78
79$result = restrictedArea($user, 'societe&fournisseur', $id, '&societe', '', 'rowid');
80
81$object = new Fournisseur($db);
82
83// fetch optionals attributes and labels
84$extrafields->fetch_name_optionals_label($object->table_element);
85
86$permissiontoadd = $user->hasRight('societe', 'creer');
87$permissiontoeditextra = $permissiontoadd;
88if (GETPOST('attribute', 'aZ09') && isset($extrafields->attributes[$object->table_element]['perms'][GETPOST('attribute', 'aZ09')])) {
89 // For action 'update_extras', is there a specific permission set for the attribute to update
90 $permissiontoeditextra = dol_eval((string) $extrafields->attributes[$object->table_element]['perms'][GETPOST('attribute', 'aZ09')]);
91}
92
93// Security check
94$result = restrictedArea($user, 'societe', $id, '&societe', '', 'fk_soc', 'rowid', 0);
95
96if ($object->id > 0) {
97 if (!($object->fournisseur > 0) || !$user->hasRight("fournisseur", "lire")) {
99 }
100}
101
102
103/*
104 * Actions
105 */
106$error = 0;
107$parameters = array('id' => $id);
108$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
109if ($reshook < 0) {
110 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
111}
112
113if (empty($reshook)) {
114 if ($cancel) {
115 $action = "";
116 }
117
118 // set general supplier accounting account
119 if ($action == 'setsupplieraccountancycodegeneral' && $user->hasRight('societe', 'creer')) {
120 $result = $object->fetch($id);
121 $object->accountancy_code_supplier_general = GETPOST("supplieraccountancycodegeneral");
122 $result = $object->update($object->id, $user, 1, 0, 1);
123 if ($result < 0) {
124 setEventMessages($object->error, $object->errors, 'errors');
125 $_GET['action'] = 'editsupplieraccountancycode';
126 }
127 }
128
129 // Set auxiliary supplier accounting account
130 if ($action == 'setsupplieraccountancycode' && $user->hasRight('societe', 'creer')) {
131 $result = $object->fetch($id);
132 $object->code_compta_fournisseur = GETPOST("supplieraccountancycode");
133 $result = $object->update($object->id, $user, 1, 0, 1);
134 if ($result < 0) {
135 setEventMessages($object->error, $object->errors, 'errors');
136 $action = 'editsupplieraccountancycode';
137 }
138 }
139 // Set vat number accounting account
140 if ($action == 'settva_intra' && $user->hasRight('societe', 'creer')) {
141 $result = $object->fetch($id);
142 $object->tva_intra = GETPOST("tva_intra");
143 $result = $object->update($object->id, $user, 1, 0, 0);
144 if ($result < 0) {
145 setEventMessages($object->error, $object->errors, 'errors');
146 }
147 }
148 // Set payment terms of the settlement
149 if ($action == 'setconditions' && $user->hasRight('societe', 'creer')) {
150 $object->fetch($id);
151 $result = $object->setPaymentTerms(GETPOSTINT('cond_reglement_supplier_id'), GETPOSTINT('cond_reglement_supplier_id_deposit_percent'));
152 if ($result < 0) {
153 dol_print_error($db, $object->error);
154 }
155 }
156 // Payment mode
157 if ($action == 'setmode' && $user->hasRight('societe', 'creer')) {
158 $object->fetch($id);
159 $result = $object->setPaymentMethods(GETPOSTINT('mode_reglement_supplier_id'));
160 if ($result < 0) {
161 dol_print_error($db, $object->error);
162 }
163 }
164
165 // Bank account
166 if ($action == 'setbankaccount' && $user->hasRight('societe', 'creer')) {
167 $object->fetch($id);
168 $result = $object->setBankAccount(GETPOSTINT('fk_account'));
169 if ($result < 0) {
170 setEventMessages($object->error, $object->errors, 'errors');
171 }
172 }
173
174 // update supplier order min amount
175 if ($action == 'setsupplier_order_min_amount' && $user->hasRight('societe', 'creer')) {
176 $object->fetch($id);
177 $object->supplier_order_min_amount = price2num(GETPOST('supplier_order_min_amount', 'alpha'));
178 $result = $object->update($object->id, $user);
179 if ($result < 0) {
180 setEventMessages($object->error, $object->errors, 'errors');
181 }
182 }
183
184 if ($action == 'update_extras' && $permissiontoeditextra) {
185 $object->fetch($id);
186
187 $object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
188
189 $attribute_name = GETPOST('attribute', 'aZ09');
190
191 // Fill array 'array_options' with data from update form
192 $ret = $extrafields->setOptionalsFromPost(null, $object, $attribute_name);
193 if ($ret < 0) {
194 $error++;
195 }
196
197 if (!$error) {
198 $result = $object->updateExtraField($attribute_name, 'COMPANY_MODIFY');
199 if ($result < 0) {
200 setEventMessages($object->error, $object->errors, 'errors');
201 $error++;
202 }
203 }
204
205 if ($error) {
206 $action = 'edit_extras';
207 }
208 }
209}
210
211
212/*
213 * View
214 */
215
216$contactstatic = new Contact($db);
217$form = new Form($db);
218
219if ($id > 0 && empty($object->id)) {
220 // Load data of third party
221 $res = $object->fetch($id);
222 if ($object->id <= 0) {
223 if ($object->error) {
224 dol_print_error($db, $object->error);
225 exit(1);
226 }
227 // Fournisseur::fetch() filters on s.fournisseur > 0, so a third party that exists but is no
228 // longer a vendor returns no row and no database error. Show a readable message with a link to
229 // the generic card instead of the technical error page (#39618).
230 $langs->load("errors");
231 llxHeader('', $langs->trans("ThirdParty").' - '.$langs->trans('Supplier'));
232 print '<div class="warning">'.$langs->trans("ErrorRecordNotFound").' ('.$langs->trans("Supplier").')';
233 print ' <a href="'.DOL_URL_ROOT.'/societe/card.php?socid='.((int) $id).'">'.$langs->trans("ThirdParty").'</a>';
234 print '</div>';
235 llxFooter();
236 $db->close();
237 exit(0);
238 }
239}
240
241if ($object->id > 0) {
242 $title = $langs->trans("ThirdParty")." - ".$langs->trans('Supplier');
243 if (getDolGlobalString('MAIN_HTML_TITLE') && preg_match('/thirdpartynameonly/', getDolGlobalString('MAIN_HTML_TITLE')) && $object->name) {
244 $title = $object->name." - ".$langs->trans('Supplier');
245 }
246 $help_url = '';
247 llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-fourn page-card');
248
249 /*
250 * Show tabs
251 */
252 $head = societe_prepare_head($object);
253
254 print dol_get_fiche_head($head, 'supplier', $langs->trans("ThirdParty"), -1, 'company');
255
256 $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
257
258 dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom');
259
260 print '<div class="fichecenter"><div class="fichehalfleft">';
261
262 print '<div class="underbanner clearboth"></div>';
263 print '<table class="border centpercent tableforfield">';
264
265 // Nature Prospect/Customer/Supplier
266 print '<tr><td class="titlefield">'.$langs->trans('NatureOfThirdParty').'</td><td>';
267 print $object->getTypeUrl(1);
268 print '</td></tr>';
269
270 if ($object->fournisseur) {
271 $langs->load('compta');
272
273 print '<tr>';
274 print '<td class="titlefield">'.$langs->trans("SupplierCode").'</td><td>';
276 $tmpcheck = $object->check_codefournisseur();
277 if ($tmpcheck != 0 && $tmpcheck != -5) {
278 print ' <span class="paddingleftimp error inline-block valignmiddle" title="'.$object->error.'">('.$langs->trans("WrongSupplierCode").')</span>';
279 }
280 print '</td>';
281 print '</tr>';
282
283 if (isModEnabled('accounting')) {
284 $formaccounting = new FormAccounting($db);
285
286 print '<tr>';
287 print '<td>';
288 print $form->editfieldkey("SupplierAccountancyCodeGeneral", 'supplieraccountancycodegeneral', length_accountg($object->accountancy_code_supplier_general), $object, $user->hasRight('societe', 'creer'));
289 print '</td><td>';
290 if ($action == 'editsupplieraccountancycodegeneral' && $user->hasRight('societe', 'creer')) {
291 print $formaccounting->formAccountingAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->accountancy_code_supplier_general, 'supplieraccountancycodegeneral', 0, 1, '', 1);
292 } else {
293 if ($object->accountancy_code_supplier_general > 0) {
294 $accountingaccount = new AccountingAccount($db);
295 $accountingaccount->fetch(0, $object->accountancy_code_supplier_general, 1);
296
297 print $accountingaccount->getNomUrl(0, 1, 1, '', 1);
298 }
299 if (getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER')) {
300 if ($object->accountancy_code_supplier_general > 0) {
301 print ' - ';
302 }
303 $accountingAccountByDefault = '<span class="opacitymedium">' . $langs->trans("AccountingAccountByDefaultShort") . ": " . length_accountg(getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER')) . '</span>';
304 print $accountingAccountByDefault;
305 }
306 }
307 print '</td>';
308 print '</tr>';
309 }
310
311 print '<tr>';
312 print '<td>';
313 print $form->editfieldkey("SupplierAccountancyCode", 'supplieraccountancycode', $object->code_compta_fournisseur, $object, $user->hasRight('societe', 'creer'));
314 print '</td><td>';
315 print $form->editfieldval("SupplierAccountancyCode", 'supplieraccountancycode', $object->code_compta_fournisseur, $object, $user->hasRight('societe', 'creer'));
316 print '</td>';
317 print '</tr>';
318 }
319
320 // VAT is used
321 print '<tr>';
322 print '<td class="titlefield">';
323 print $form->textwithpicto($langs->trans('VATIsUsed'), $langs->trans('VATIsUsedWhenSelling'));
324 print '</td><td>';
325 print yn($object->tva_assuj);
326 print '</td>';
327 print '</tr>';
328
329 // Local Taxes
330 if ($mysoc->useLocalTax(1)) {
331 print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).'</td><td>';
332 print yn($object->localtax1_assuj);
333 print '</td></tr>';
334 }
335 if ($mysoc->useLocalTax(2)) {
336 print '<tr><td>'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).'</td><td>';
337 print yn($object->localtax2_assuj);
338 print '</td></tr>';
339 }
340
341 // VAT reverse-charge by default on supplier invoice or not
342 if (getDolGlobalString('ACCOUNTING_FORCE_ENABLE_VAT_REVERSE_CHARGE')) {
343 print '<tr>';
344 print '<td class="titlefield">';
345 print $form->textwithpicto($langs->trans('VATReverseChargeByDefault'), $langs->trans('VATReverseChargeByDefaultDesc').'<br>'.$langs->trans('ACCOUNTING_FORCE_ENABLE_VAT_REVERSE_CHARGE_DESC'));
346 print '</td><td>';
347 print '<input type="checkbox" name="vat_reverse_charge" ' . ($object->vat_reverse_charge == '1' ? ' checked' : '') . ' disabled>';
348 print '</td>';
349 print '</tr>';
350 }
351
352 // TVA Intra
353 print '<tr><td class="nowrap">';
354 //print $langs->trans('VATIntra').'</td><td>';
355 $vattoshow = ($object->tva_intra ? showValueWithClipboardCPButton(dol_escape_htmltag($object->tva_intra)) : '');
356 print $form->editfieldkey("VATIntra", 'tva_intra', $object->tva_intra, $object, $user->hasRight('societe', 'creer'));
357 print '</td><td>';
358 print $form->editfieldval("VATIntra", 'tva_intra', $vattoshow, $object, $user->hasRight('societe', 'creer'), 'string', $object->tva_intra, null, null, '', 1, '', 'id', 'auto', array('valuealreadyhtmlescaped' => 1));
359 print '</td></tr>';
360
361 // Default terms of the settlement
362 $langs->load('bills');
363 $form = new Form($db);
364 print '<tr><td>';
365 print '<table width="100%" class="nobordernopadding"><tr><td>';
366 print $langs->trans('PaymentConditions');
367 print '<td>';
368 if (($action != 'editconditions') && $user->hasRight('societe', 'creer')) {
369 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>';
370 }
371 print '</tr></table>';
372 print '</td><td>';
373 if ($action == 'editconditions') {
374 $form->form_conditions_reglement($_SERVER['PHP_SELF'] . '?socid=' . $object->id, (string) $object->cond_reglement_supplier_id, 'cond_reglement_supplier_id', 1, '', 1, $object->deposit_percent);
375 } else {
376 $form->form_conditions_reglement($_SERVER['PHP_SELF'] . '?socid=' . $object->id, (string) $object->cond_reglement_supplier_id, 'none', 0, '', 1, $object->deposit_percent);
377 }
378 print "</td>";
379 print '</tr>';
380
381 // Default payment mode
382 print '<tr><td class="nowrap">';
383 print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
384 print $langs->trans('PaymentMode');
385 print '<td>';
386 if (($action != 'editmode') && $user->hasRight('societe', 'creer')) {
387 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>';
388 }
389 print '</tr></table>';
390 print '</td><td>';
391 if ($action == 'editmode') {
392 $form->form_modes_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, (string) $object->mode_reglement_supplier_id, 'mode_reglement_supplier_id', 'DBIT', 1, 1);
393 } else {
394 $form->form_modes_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, (string) $object->mode_reglement_supplier_id, 'none');
395 }
396 print "</td>";
397 print '</tr>';
398
399 if (isModEnabled("bank")) {
400 // Default bank account for payments
401 print '<tr><td class="nowrap">';
402 print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
403 print $langs->trans('PaymentBankAccount');
404 print '<td>';
405 if (($action != 'editbankaccount') && $user->hasRight('societe', 'creer')) {
406 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>';
407 }
408 print '</tr></table>';
409 print '</td><td>';
410 if ($action == 'editbankaccount') {
411 $form->formSelectAccount($_SERVER['PHP_SELF'].'?socid='.$object->id, (string) $object->fk_account, 'fk_account', 1);
412 } else {
413 $form->formSelectAccount($_SERVER['PHP_SELF'].'?socid='.$object->id, (string) $object->fk_account, 'none');
414 }
415 print "</td>";
416 print '</tr>';
417 }
418
419 // Relative discounts (Discounts-Drawbacks-Rebates)
420 print '<tr><td class="nowrap">';
421 print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
422 print $langs->trans("CustomerRelativeDiscountShort");
423 print '<td><td class="right">';
424 if ($user->hasRight('societe', 'creer') && !$user->socid > 0) {
425 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>';
426 }
427 print '</td></tr></table>';
428 print '</td><td>'.($object->remise_supplier_percent ? '<a href="'.DOL_URL_ROOT.'/comm/remise.php?id='.$object->id.'">'.$object->remise_supplier_percent.'%</a>' : '').'</td>';
429 print '</tr>';
430
431 // Absolute discounts (Discounts-Drawbacks-Rebates)
432 print '<tr><td class="nowrap">';
433 print '<table width="100%" class="nobordernopadding">';
434 print '<tr><td class="nowrap">';
435 print $langs->trans("CustomerAbsoluteDiscountShort");
436 print '<td><td class="right">';
437 if ($user->hasRight('societe', 'creer') && !$user->socid > 0) {
438 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>';
439 }
440 print '</td></tr></table>';
441 print '</td>';
442 print '<td>';
443 $amount_discount = $object->getAvailableDiscounts(null, '', 0, 1);
444 if ($amount_discount < 0) {
445 dol_print_error($db, $object->error);
446 }
447 if ($amount_discount > 0) {
448 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>';
449 }
450 //else print $langs->trans("DiscountNone");
451 print '</td>';
452 print '</tr>';
453
454 if (isModEnabled("supplier_order") && getDolGlobalString('ORDER_MANAGE_MIN_AMOUNT')) {
455 print '<tr class="nowrap">';
456 print '<td>';
457 print $form->editfieldkey("OrderMinAmount", 'supplier_order_min_amount', $object->supplier_order_min_amount, $object, $user->hasRight("societe", "creer"));
458 print '</td><td>';
459 //$limit_field_type = (getDolGlobalString('MAIN_USE_EDIT_IN_PLACE')) ? 'numeric' : 'amount'; // TODO deprecated ?
460 $limit_field_type = 'amount';
461 print $form->editfieldval("OrderMinAmount", 'supplier_order_min_amount', $object->supplier_order_min_amount, $object, $user->hasRight("societe", "creer"), $limit_field_type, ($object->supplier_order_min_amount != '' ? price($object->supplier_order_min_amount) : ''));
462 print '</td>';
463 print '</tr>';
464 }
465
466 // Categories
467 if (isModEnabled('category')) {
468 $langs->load("categories");
469 print '<tr><td>'.$langs->trans("SuppliersCategoriesShort").'</td>';
470 print '<td>';
471 print $form->showCategories($object->id, Categorie::TYPE_SUPPLIER, 1);
472 print "</td></tr>";
473 }
474
475 // Other attributes
476 $parameters = array('socid' => $object->id, 'colspan' => ' colspan="3"', 'colspanvalue' => '3');
477 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
478
479 // Module Adherent
480 if (isModEnabled('member')) {
481 $langs->load("members");
482 $langs->load("users");
483 print '<tr><td>'.$langs->trans("LinkedToDolibarrMember").'</td>';
484 print '<td>';
485 $adh = new Adherent($db);
486 $result = $adh->fetch(0, '', $object->id);
487 if ($result > 0) {
488 $adh->ref = $adh->getFullName($langs);
489 print $adh->getNomUrl(1);
490 } else {
491 print $langs->trans("ThirdpartyNotLinkedToMember");
492 }
493 print '</td>';
494 print "</tr>\n";
495 }
496
497 print '</table>';
498
499
500 print '</div><div class="fichehalfright">';
501
502 $boxstat = '';
503
504 // Nbre max d'elements des petites listes
505 $MAXLIST = getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT', 5);
506
507 print '<div class="underbanner underbanner-before-box clearboth"></div>';
508 print '<br>';
509
510 // Summary link
511 $boxstat .= '<div class="box divboxtable box-halfright">';
512 $boxstat .= '<table summary="'.dol_escape_htmltag($langs->trans("DolibarrStateBoard")).'" class="border boxtable boxtablenobottom boxtablenotop" width="100%">';
513 $boxstat .= '<tr class="impair nohover"><td colspan="2" class="tdboxstats nohover">';
514
515 if (isModEnabled('supplier_proposal')) {
516 // Box proposals
517 $tmp = $object->getOutstandingProposals('supplier');
518 $outstandingOpened = $tmp['opened'];
519 $outstandingTotal = $tmp['total_ht'];
520 $outstandingTotalIncTax = $tmp['total_ttc'];
521 $text = $langs->trans("OverAllSupplierProposals");
522 $link = DOL_URL_ROOT.'/supplier_proposal/list.php?socid='.$object->id;
523 $icon = 'bill';
524 if ($link) {
525 $boxstat .= '<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
526 }
527 $boxstat .= '<div class="boxstats" title="'.dol_escape_htmltag($text).'">';
528 $boxstat .= '<span class="boxstatstext">'.img_object("", $icon).' <span>'.$text.'</span></span><br>';
529 $boxstat .= '<span class="boxstatsindicator">'.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
530 $boxstat .= '</div>';
531 if ($link) {
532 $boxstat .= '</a>';
533 }
534 }
535
536 if (isModEnabled("supplier_order")) {
537 // Box proposals
538 $tmp = $object->getOutstandingOrders('supplier');
539 $outstandingOpened = $tmp['opened'];
540 $outstandingTotal = $tmp['total_ht'];
541 $outstandingTotalIncTax = $tmp['total_ttc'];
542 $text = $langs->trans("OverAllOrders");
543 $link = DOL_URL_ROOT.'/fourn/commande/list.php?socid='.$object->id;
544 $icon = 'bill';
545 if ($link) {
546 $boxstat .= '<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
547 }
548 $boxstat .= '<div class="boxstats" title="'.dol_escape_htmltag($text).'">';
549 $boxstat .= '<span class="boxstatstext">'.img_object("", $icon).' <span>'.$text.'</span></span><br>';
550 $boxstat .= '<span class="boxstatsindicator">'.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
551 $boxstat .= '</div>';
552 if ($link) {
553 $boxstat .= '</a>';
554 }
555 }
556
557 if (isModEnabled("supplier_invoice") && ($user->hasRight('fournisseur', 'facture', 'lire') || $user->hasRight('supplier_invoice', 'read'))) {
558 $warn = '';
559 $tmp = $object->getOutstandingBills('supplier');
560 $outstandingOpened = $tmp['opened'];
561 $outstandingTotal = $tmp['total_ht'];
562 $outstandingTotalIncTax = $tmp['total_ttc'];
563
564 $text = $langs->trans("OverAllInvoices");
565 $link = DOL_URL_ROOT.'/fourn/facture/list.php?socid='.$object->id;
566 $icon = 'bill';
567 if ($link) {
568 $boxstat .= '<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
569 }
570 $boxstat .= '<div class="boxstats" title="'.dol_escape_htmltag($text).'">';
571 $boxstat .= '<span class="boxstatstext">'.img_object("", $icon).' <span>'.$text.'</span></span><br>';
572 $boxstat .= '<span class="boxstatsindicator">'.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
573 $boxstat .= '</div>';
574 if ($link) {
575 $boxstat .= '</a>';
576 }
577
578 // Box outstanding bill
579 $text = $langs->trans("CurrentOutstandingBill");
580 $link = DOL_URL_ROOT.'/fourn/recap-fourn.php?socid='.$object->id.'&search_status=unpaid';
581 $icon = 'bill';
582 $boxstattmp = '<div class="boxstats" title="'.dol_escape_htmltag($text).'">';
583 $boxstattmp .= '<span class="boxstatstext">'.img_object("", $icon).' <span>'.$text.'</span></span><br>';
584 $boxstattmp .= '<span class="boxstatsindicator'.($outstandingOpened > 0 ? ' amountremaintopay' : '').'">'.price($outstandingOpened, 1, $langs, 1, -1, -1, $conf->currency).$warn.'</span>';
585 $boxstattmp .= '</div>';
586 if ($link) {
587 $boxstat .= dolButtonToOpenUrlInDialogPopup('popupoutstanding', $langs->transnoentitiesnoconv("CurrentOutstandingBill"), $boxstattmp, '/fourn/recap-fourn.php?socid='.$object->id.'&search_status=unpaid', '', '');
588 } else {
589 $boxstat .= $boxstattmp;
590 }
591
592 $tmp = $object->getOutstandingBills('supplier', 1);
593 $outstandingOpenedLate = $tmp['opened'];
594 if ($outstandingOpened != $outstandingOpenedLate && !empty($outstandingOpenedLate)) {
595 $text = $langs->trans("CurrentOutstandingBillLate");
596 $link = DOL_URL_ROOT.'/fourn/recap-fourn.php?socid='.$object->id.'&search_status=unpaid&search_late=late';
597 $icon = 'bill';
598 $boxstattmp = '<div class="boxstats" title="'.dol_escape_htmltag($text).'">';
599 $boxstattmp .= '<span class="boxstatstext">'.img_object("", $icon).' <span>'.$text.'</span></span><br>';
600 $boxstattmp .= '<span class="boxstatsindicator'.($outstandingOpenedLate > 0 ? ' amountremaintopay' : '').'">'.price($outstandingOpenedLate, 1, $langs, 1, -1, -1, $conf->currency).$warn.'</span>';
601 $boxstattmp .= '</div>';
602 if ($link) {
603 $boxstat .= dolButtonToOpenUrlInDialogPopup('popupoutstandinglate', $langs->transnoentitiesnoconv("CurrentOutstandingBillLate"), $boxstattmp, '/fourn/recap-fourn.php?socid='.$object->id.'&search_status=unpaid&search_late=late', '', '');
604 } else {
605 $boxstat .= $boxstattmp;
606 }
607 }
608 }
609
610
611 $parameters = array();
612 $reshook = $hookmanager->executeHooks('addMoreBoxStatsSupplier', $parameters, $object, $action);
613 if (empty($reshook)) {
614 $boxstat .= $hookmanager->resPrint;
615 }
616
617 $boxstat .= '</td></tr>';
618 $boxstat .= '</table>';
619 $boxstat .= '</div>';
620
621 print $boxstat;
622
623
624 $MAXLIST = getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT', 5);
625
626
627 /*
628 * List of products prices
629 */
630 if (isModEnabled("product") || isModEnabled("service")) {
631 $langs->load("products");
632 //Query from product/liste.php
633 $sql = 'SELECT p.rowid, p.ref, p.label, p.fk_product_type, p.entity, p.tosell as status, p.tobuy as status_buy, p.tobatch as status_batch,';
634 $sql .= ' pfp.tms, pfp.ref_fourn as supplier_ref, pfp.price, pfp.quantity, pfp.unitprice';
635 $sql .= ' FROM '.MAIN_DB_PREFIX.'product_fournisseur_price as pfp';
636 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = pfp.fk_product";
637 $sql .= ' WHERE p.entity IN ('.getEntity('product').')';
638 $sql .= ' AND pfp.fk_soc = '.((int) $object->id);
639 $sql .= $db->order('pfp.tms', 'desc');
640 $sql .= $db->plimit($MAXLIST);
641
642 $query = $db->query($sql);
643 if (!$query) {
644 dol_print_error($db);
645 }
646
647 $num = $db->num_rows($query);
648
649 print '<div class="div-table-responsive-no-min">';
650 print '<table class="noborder centpercent lastrecordtable">';
651 print '<tr class="liste_titre'.(($num == 0) ? ' nobottom' : '').'">';
652 print '<td colspan="2">'.$langs->trans("ProductsAndServices").'</td><td class="right" colspan="2">';
653 print '<a class="notasortlink" href="'.DOL_URL_ROOT.'/fourn/product/list.php?fourn_id='.$object->id.'"><span class="hideonsmartphone">'.$langs->trans("AllProductReferencesOfSupplier").'</span><span class="badge marginleftonlyshort">'.$object->nbOfProductRefs().'</span>';
654 print '</a></td></tr>';
655
656 $return = array();
657 if ($num > 0) {
658 $productstatic = new Product($db);
659
660 while ($objp = $db->fetch_object($query)) {
661 $productstatic->id = $objp->rowid;
662 $productstatic->ref = $objp->ref;
663 $productstatic->label = $objp->label;
664 $productstatic->type = $objp->fk_product_type;
665 $productstatic->entity = $objp->entity;
666 $productstatic->status = $objp->status;
667 $productstatic->status_buy = $objp->status_buy;
668 $productstatic->status_batch = $objp->status_batch;
669
670 print '<tr class="oddeven">';
671 print '<td class="nowrap">';
672 print $productstatic->getNomUrl(1);
673 print '</td>';
674 print '<td>';
675 print dol_escape_htmltag($objp->supplier_ref);
676 print '</td>';
677 print '<td class="tdoverflowmax200">';
678 print dol_trunc(dol_htmlentities($objp->label), 30);
679 print '</td>';
680 //print '<td class="right" class="nowrap">'.dol_print_date($objp->tms, 'day').'</td>';
681 print '<td class="right">';
682 //print (isset($objp->unitprice) ? price($objp->unitprice) : '');
683 if (isset($objp->price)) {
684 print '<span class="amount">'.price($objp->price).'</span>';
685 if ($objp->quantity > 1) {
686 print ' / ';
687 print $objp->quantity;
688 }
689 }
690 print '</td>';
691 print '</tr>';
692 }
693 } else {
694 print '<tr><td colspan="4"><span class="opacitymedium">'.$langs->trans("NoProductPriceDefinedForThisSupplier").'</span></td></tr>';
695 }
696
697 print '</table>';
698 print '</div>';
699 }
700
701
702 /*
703 * Latest supplier proposal
704 */
705 $proposalstatic = new SupplierProposal($db);
706
707 if ($user->hasRight("supplier_proposal", "lire")) {
708 $langs->loadLangs(array("supplier_proposal"));
709
710 $sql = "SELECT p.rowid, p.ref, p.date_valid as dc, p.fk_statut, p.total_ht, p.total_tva, p.total_ttc";
711 $sql .= " FROM ".MAIN_DB_PREFIX."supplier_proposal as p ";
712 $sql .= " WHERE p.fk_soc = ".((int) $object->id);
713 $sql .= " AND p.entity IN (".getEntity('supplier_proposal').")";
714 $sql .= " ORDER BY p.date_valid DESC";
715 $sql .= $db->plimit($MAXLIST);
716
717 $resql = $db->query($sql);
718 if ($resql) {
719 $i = 0;
720 $num = $db->num_rows($resql);
721
722 if ($num > 0) {
723 print '<div class="div-table-responsive-no-min">';
724 print '<table class="noborder centpercent lastrecordtable">';
725
726 print '<tr class="liste_titre">';
727 print '<td colspan="3">';
728 print '<table class="nobordernopadding centpercent"><tr><td>'.$langs->trans("LastSupplierProposals", ($num < $MAXLIST ? "" : $MAXLIST)).'</td>';
729 print '<td class="right"><a class="notasortlink" href="'.DOL_URL_ROOT.'/supplier_proposal/list.php?socid='.$object->id.'"><span class="hideonsmartphone">'.$langs->trans("AllPriceRequests").'</span><span class="badge marginleftonlyshort">'.$num.'</span></td>';
730 // print '<td width="20px" class="right"><a href="'.DOL_URL_ROOT.'/supplier_proposal/stats/index.php?mode=supplier&socid='.$object->id.'">'.img_picto($langs->trans("Statistics"), 'stats').'</a></td>';
731 print '</tr></table>';
732 print '</td></tr>';
733 }
734
735 while ($i < $num && $i <= $MAXLIST) {
736 $obj = $db->fetch_object($resql);
737
738 print '<tr class="oddeven">';
739 print '<td class="nowrap">';
740 $proposalstatic->id = $obj->rowid;
741 $proposalstatic->ref = $obj->ref;
742 $proposalstatic->total_ht = $obj->total_ht;
743 $proposalstatic->total_tva = $obj->total_tva;
744 $proposalstatic->total_ttc = $obj->total_ttc;
745 print $proposalstatic->getNomUrl(1);
746 print '</td>';
747 print '<td class="center" width="80">';
748 if ($obj->dc) {
749 print dol_print_date($db->jdate($obj->dc), 'day');
750 } else {
751 print "-";
752 }
753 print '</td>';
754 print '<td class="right" class="nowrap">'.$proposalstatic->LibStatut($obj->fk_statut, 5).'</td>';
755 print '</tr>';
756 $i++;
757 }
758 $db->free($resql);
759
760 if ($num > 0) {
761 print "</table></div>";
762 }
763 } else {
764 dol_print_error($db);
765 }
766 }
767
768 /*
769 * Latest supplier orders
770 */
771 $orderstatic = new CommandeFournisseur($db);
772 $orders2invoice = 0;
773
774 if ($user->hasRight("fournisseur", "commande", "lire")) {
775 // TODO move to DAO class
776 // Check if there are supplier orders billable
777 $sql2 = 'SELECT s.nom, s.rowid as socid, s.client, c.rowid, c.ref, c.total_ht, c.ref_supplier,';
778 $sql2 .= ' c.date_valid, c.date_commande, c.date_livraison, c.fk_statut';
779 $sql2 .= ' FROM '.MAIN_DB_PREFIX.'societe as s';
780 $sql2 .= ', '.MAIN_DB_PREFIX.'commande_fournisseur as c';
781 $sql2 .= ' WHERE c.fk_soc = s.rowid';
782 $sql2 .= " AND c.entity IN (".getEntity('commande_fournisseur').")";
783 $sql2 .= ' AND s.rowid = '.((int) $object->id);
784 // Show orders we can bill
785 if (!getDolGlobalString('SUPPLIER_ORDER_TO_INVOICE_STATUS')) {
786 $sql2 .= " AND c.fk_statut IN (".$db->sanitize((string) CommandeFournisseur::STATUS_RECEIVED_COMPLETELY).")"; // Must match filter in htdocs/fourn/commande/list.php
787 } else {
788 // CommandeFournisseur::STATUS_ORDERSENT.", ".CommandeFournisseur::STATUS_RECEIVED_PARTIALLY.", ".CommandeFournisseur::STATUS_RECEIVED_COMPLETELY
789 $sql2 .= " AND c.fk_statut IN (".$db->sanitize(getDolGlobalString('SUPPLIER_ORDER_TO_INVOICE_STATUS')).")";
790 }
791 $sql2 .= " AND c.billed = 0";
792 // Find order that are not already invoiced
793 // just need to check received status because we have the billed status now
794 //$sql2 .= " AND c.rowid NOT IN (SELECT fk_source FROM " . MAIN_DB_PREFIX . "element_element WHERE targettype='invoice_supplier')";
795 $resql2 = $db->query($sql2);
796 if ($resql2) {
797 $orders2invoice = $db->num_rows($resql2);
798 $db->free($resql2);
799 } else {
800 setEventMessages($db->lasterror(), null, 'errors');
801 }
802
803 // TODO move to DAO class
804 $sql = "SELECT count(p.rowid) as total";
805 $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as p";
806 $sql .= " WHERE p.fk_soc = ".((int) $object->id);
807 $sql .= " AND p.entity IN (".getEntity('commande_fournisseur').")";
808 $num = 0;
809 $resql = $db->query($sql);
810 if ($resql) {
811 $object_count = $db->fetch_object($resql);
812 $num = $object_count->total;
813 }
814
815 $sql = "SELECT p.rowid,p.ref, p.date_commande as date, p.fk_statut, p.total_ht, p.total_tva, p.total_ttc";
816 $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as p";
817 $sql .= " WHERE p.fk_soc = ".((int) $object->id);
818 $sql .= " AND p.entity IN (".getEntity('commande_fournisseur').")";
819 $sql .= " ORDER BY p.date_commande DESC";
820 $sql .= $db->plimit($MAXLIST);
821
822 $resql = $db->query($sql);
823 if ($resql) {
824 $i = 0;
825
826 if ($num > 0) {
827 print '<div class="div-table-responsive-no-min">';
828 print '<table class="noborder centpercent lastrecordtable">';
829
830 print '<tr class="liste_titre">';
831 print '<td colspan="4">';
832 print '<table class="nobordernopadding" width="100%"><tr><td>'.$langs->trans("LastSupplierOrders", ($num < $MAXLIST ? "" : $MAXLIST)).'</td>';
833 print '<td class="right"><a class="notasortlink" href="'.DOL_URL_ROOT.'/fourn/commande/list.php?socid='.$object->id.'"><span class="hideonsmartphone">'.$langs->trans("AllSupplierOrders").'</span><span class="badge marginleftonlyshort">'.$num.'</span></td>';
834 print '<td width="20px" class="right"><a href="'.DOL_URL_ROOT.'/commande/stats/index.php?mode=supplier&socid='.$object->id.'">'.img_picto($langs->trans("Statistics"), 'stats').'</a></td>';
835 print '</tr></table>';
836 print '</td></tr>';
837 }
838
839 while ($i < $num && $i < $MAXLIST) {
840 $obj = $db->fetch_object($resql);
841
842 $orderstatic->id = $obj->rowid;
843 $orderstatic->ref = $obj->ref;
844 $orderstatic->total_ht = $obj->total_ht;
845 $orderstatic->total_tva = $obj->total_tva;
846 $orderstatic->total_ttc = $obj->total_ttc;
847 $orderstatic->date = $db->jdate($obj->date);
848
849 print '<tr class="oddeven">';
850 print '<td class="nowraponall">';
851 print $orderstatic->getNomUrl(1);
852 print '</td>';
853 print '<td class="center" width="80">';
854 if ($obj->date) {
855 print dol_print_date($orderstatic->date, 'day');
856 }
857 print '</td>';
858 print '<td class="right nowrap"><span class="amount">'.price($orderstatic->total_ttc).'</span></td>';
859 print '<td class="right" class="nowrap">'.$orderstatic->LibStatut($obj->fk_statut, 5).'</td>';
860 print '</tr>';
861 $i++;
862 }
863 $db->free($resql);
864
865 if ($num > 0) {
866 print "</table></div>";
867 }
868 } else {
869 dol_print_error($db);
870 }
871 }
872
873
874 /*
875 * Latest invoices templates
876 */
877 if (isModEnabled("supplier_invoice") && ($user->hasRight('fournisseur', 'facture', 'lire') || $user->hasRight('supplier_invoice', 'read'))) {
878 $sql = 'SELECT f.rowid as id, f.titre as ref';
879 $sql .= ', f.total_ht';
880 $sql .= ', f.total_tva';
881 $sql .= ', f.total_ttc';
882 $sql .= ', f.datec as dc';
883 $sql .= ', f.date_last_gen, f.date_when';
884 $sql .= ', f.frequency';
885 $sql .= ', f.unit_frequency';
886 $sql .= ', f.suspended as suspended';
887 $sql .= ', s.nom, s.rowid as socid';
888 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture_fourn_rec as f";
889 $sql .= " WHERE f.fk_soc = s.rowid AND s.rowid = ".((int) $object->id);
890 $sql .= " AND f.entity IN (".getEntity('invoice').")";
891 $sql .= ' GROUP BY f.rowid, f.titre, f.total_ht, f.total_tva, f.total_ttc,';
892 $sql .= ' f.date_last_gen, f.datec, f.frequency, f.unit_frequency,';
893 $sql .= ' f.suspended, f.date_when,';
894 $sql .= ' s.nom, s.rowid';
895 $sql .= $db->order("f.date_last_gen, f.datec", "DESC");
896
897 $resql = $db->query($sql);
898 if ($resql) {
899 $invoicetemplate = new FactureFournisseurRec($db);
900
901 $num = $db->num_rows($resql);
902 if ($num > 0) {
903 print '<div class="div-table-responsive-no-min">';
904 print '<table class="noborder centpercent lastrecordtable">';
905 print '<tr class="liste_titre">';
906 $colspan = 4;
907 if (getDolGlobalString('MAIN_SHOW_PRICE_WITH_TAX_IN_SUMMARIES')) {
908 $colspan++;
909 }
910 print '<td colspan="'.$colspan.'">';
911 print '<table class="centpercent nobordernopadding"><tr>';
912 print '<td>'.$langs->trans("LatestSupplierTemplateInvoices", ($num <= $MAXLIST ? "" : $MAXLIST)).'</td>';
913 print '<td class="right">';
914 print '<a class="notasortlink" href="'.DOL_URL_ROOT.'/fourn/facture/list-rec.php?socid='.$object->id.'">';
915 print '<span class="hideonsmartphone">'.$langs->trans("AllSupplierTemplateInvoices").'</span><span class="badge marginleftonlyshort">'.$num.'</span></a></td>';
916 print '</tr></table>';
917 print '</td>';
918 print '</tr>';
919 }
920
921 $i = 0;
922 while ($i < $num && $i < $MAXLIST) {
923 $objp = $db->fetch_object($resql);
924
925 $invoicetemplate->id = $objp->id;
926 $invoicetemplate->ref = $objp->ref;
927 $invoicetemplate->suspended = $objp->suspended;
928 $invoicetemplate->frequency = $objp->frequency;
929 $invoicetemplate->unit_frequency = $objp->unit_frequency;
930 $invoicetemplate->total_ht = $objp->total_ht;
931 $invoicetemplate->total_tva = $objp->total_tva;
932 $invoicetemplate->total_ttc = $objp->total_ttc;
933 $invoicetemplate->date_last_gen = $db->jdate($objp->date_last_gen);
934 $invoicetemplate->date_when = $db->jdate($objp->date_when);
935
936 print '<tr class="oddeven">';
937 print '<td class="tdoverflowmax250">';
938 print $invoicetemplate->getNomUrl(1);
939 print '</td>';
940
941 if ($objp->frequency && $objp->date_last_gen > 0) {
942 print '<td class="right" width="80px">'.dol_print_date($db->jdate($objp->date_last_gen), 'day').'</td>';
943 } else {
944 if ($objp->dc > 0) {
945 print '<td class="right" width="80px">'.dol_print_date($db->jdate($objp->dc), 'day').'</td>';
946 } else {
947 print '<td class="right"><b>!!!</b></td>';
948 }
949 }
950 print '<td class="right nowraponall">';
951 print price($objp->total_ht);
952 print '</td>';
953
954 if (getDolGlobalString('MAIN_SHOW_PRICE_WITH_TAX_IN_SUMMARIES')) {
955 print '<td class="right nowraponall">';
956 print price($objp->total_ttc);
957 print '</td>';
958 }
959
960 print '<td class="nowrap right" style="min-width: 60px">';
961 print $langs->trans('FrequencyPer_'.$invoicetemplate->unit_frequency, $invoicetemplate->frequency).' - ';
962 print($invoicetemplate->LibStatut($invoicetemplate->frequency, $invoicetemplate->suspended, 5, 0));
963 print '</td>';
964 print "</tr>\n";
965 $i++;
966 }
967 $db->free($resql);
968
969 if ($num > 0) {
970 print "</table>";
971 print '</div>';
972 }
973 } else {
974 dol_print_error($db);
975 }
976 }
977
978
979 /*
980 * Latest supplier invoices
981 */
982
983 $langs->load('bills');
984 $facturestatic = new FactureFournisseur($db);
985
986 if ($user->hasRight('fournisseur', 'facture', 'lire')) {
987 // TODO move to DAO class
988 $sql = 'SELECT f.rowid, f.libelle as label, f.ref, f.ref_supplier, f.fk_statut, f.datef as df, f.total_ht, f.total_tva, f.total_ttc, f.paye,';
989 $sql .= ' SUM(pf.amount) as am';
990 $sql .= ' FROM '.MAIN_DB_PREFIX.'facture_fourn as f';
991 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON f.rowid=pf.fk_facturefourn';
992 $sql .= ' WHERE f.fk_soc = '.((int) $object->id);
993 $sql .= " AND f.entity IN (".getEntity('facture_fourn').")";
994 $sql .= ' GROUP BY f.rowid,f.libelle,f.ref,f.ref_supplier,f.fk_statut,f.datef,f.total_ht,f.total_tva,f.total_ttc,f.paye';
995 $sql .= ' ORDER BY f.datef DESC';
996 $resql = $db->query($sql);
997 if ($resql) {
998 $i = 0;
999 $num = $db->num_rows($resql);
1000 if ($num > 0) {
1001 print '<div class="div-table-responsive-no-min">';
1002 print '<table class="noborder centpercent lastrecordtable">';
1003
1004 print '<tr class="liste_titre">';
1005 print '<td colspan="4">';
1006 print '<table class="nobordernopadding" width="100%"><tr><td>'.$langs->trans('LastSuppliersBills', ($num <= $MAXLIST ? "" : $MAXLIST)).'</td>';
1007 print '<td class="right"><a class="notasortlink" href="'.DOL_URL_ROOT.'/fourn/facture/list.php?socid='.$object->id.'"><span class="hideonsmartphone">'.$langs->trans('AllBills').'</span><span class="badge marginleftonlyshort">'.$num.'</span></td>';
1008 print '<td width="20px" class="right"><a href="'.DOL_URL_ROOT.'/compta/facture/stats/index.php?mode=supplier&socid='.$object->id.'">'.img_picto($langs->trans("Statistics"), 'stats').'</a></td>';
1009 print '</tr></table>';
1010 print '</td></tr>';
1011 }
1012
1013 while ($i < min($num, $MAXLIST)) {
1014 $obj = $db->fetch_object($resql);
1015
1016 $facturestatic->id = $obj->rowid;
1017 $facturestatic->ref = ($obj->ref ? $obj->ref : $obj->rowid);
1018 $facturestatic->ref_supplier = $obj->ref_supplier;
1019 $facturestatic->libelle = $obj->label; // deprecated
1020 $facturestatic->label = $obj->label;
1021 $facturestatic->total_ht = $obj->total_ht;
1022 $facturestatic->total_tva = $obj->total_tva;
1023 $facturestatic->total_ttc = $obj->total_ttc;
1024 $facturestatic->date = $db->jdate($obj->df);
1025
1026 print '<tr class="oddeven">';
1027 print '<td class="tdoverflowmax200">';
1028 print '<span class="nowraponall">'.$facturestatic->getNomUrl(1).'</span>';
1029 print $obj->ref_supplier ? ' - '.$obj->ref_supplier : '';
1030 print($obj->label ? ' - ' : '').dol_trunc($obj->label, 14);
1031 print '</td>';
1032 print '<td class="center nowrap">'.dol_print_date($facturestatic->date, 'day').'</td>';
1033 print '<td class="right nowrap"><span class="amount">'.price($facturestatic->total_ttc).'</span></td>';
1034 print '<td class="right nowrap">';
1035 print $facturestatic->LibStatut($obj->paye, $obj->fk_statut, 5, $obj->am);
1036 print '</td>';
1037 print '</tr>';
1038 $i++;
1039 }
1040 $db->free($resql);
1041 if ($num > 0) {
1042 print '</table></div>';
1043 }
1044 } else {
1045 dol_print_error($db);
1046 }
1047 }
1048
1049 /*
1050 * Latest supplier contracts
1051 */
1052 if (isModEnabled('contract') && $user->hasRight('contrat', 'lire')) {
1053 $sql = "SELECT s.nom, s.rowid, c.rowid as id, c.ref as ref, c.fk_projet, c.statut as contract_status, c.datec as dc, c.date_contrat as dcon, c.ref_customer as refcus, c.ref_supplier as refsup, c.entity,";
1054 $sql .= " c.last_main_doc, c.model_pdf";
1055 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."contrat as c";
1056 $sql .= " WHERE c.fk_soc = s.rowid";
1057 $sql .= " AND s.rowid = ".((int) $object->id);
1058 $sql .= " AND c.fk_contract_type = 1";
1059 $sql .= " AND c.entity IN (".getEntity('contract').")";
1060 $sql .= " ORDER BY c.datec DESC";
1061
1062 $resql = $db->query($sql);
1063 if ($resql) {
1064 $contrat = new Contrat($db);
1065
1066 $num = $db->num_rows($resql);
1067 if ($num > 0) {
1068 print '<div class="div-table-responsive-no-min">';
1069 print '<table class="noborder centpercent lastrecordtable">';
1070
1071 print '<tr class="liste_titre">';
1072 print '<td colspan="5"><table class="centpercent nobordernopadding"><tr><td>'.$langs->trans("LastSupplierContracts", ($num <= $MAXLIST ? "" : $MAXLIST)).'</td>';
1073 print '<td class="right"><a class="notasortlink" href="'.DOL_URL_ROOT.'/contrat/list.php?socid='.$object->id.'&search_type=1">'.$langs->trans("AllContracts").'<span class="badge marginleftonlyshort">'.$num.'</span></a></td>';
1074 print '</tr></table></td>';
1075 print '</tr>';
1076 }
1077
1078 $i = 0;
1079 while ($i < $num && $i < $MAXLIST) {
1080 $objp = $db->fetch_object($resql);
1081
1082 $contrat->id = $objp->id;
1083 $contrat->ref = $objp->ref ? $objp->ref : $objp->id;
1084 $contrat->ref_customer = $objp->refcus;
1085 $contrat->ref_supplier = $objp->refsup;
1086 $contrat->fk_project = $objp->fk_projet;
1087 $contrat->statut = $objp->contract_status;
1088 $contrat->status = $objp->contract_status;
1089 $contrat->last_main_doc = $objp->last_main_doc;
1090 $contrat->model_pdf = $objp->model_pdf;
1091
1092 print '<tr class="oddeven">';
1093 print '<td class="nowraponall">';
1094 print $contrat->getNomUrl(1, 12);
1095 print '</td>';
1096 print '<td class="tdoverflowmax125">';
1097 if ($contrat->fk_project > 0) {
1098 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
1099 $project = new Project($db);
1100 $project->fetch((int) $contrat->fk_project);
1101 print $project->getNomUrl(1);
1102 }
1103 print "</td>\n";
1104 print '<td class="nowrap">';
1105 print dol_trunc($objp->refsup, 12);
1106 print "</td>\n";
1107 print '<td class="right" width="80px"><span title="'.$langs->trans("DateContract").'">'.dol_print_date($db->jdate($objp->dcon), 'day')."</span></td>\n";
1108 print '<td class="nowraponall right">';
1109 print $contrat->getLibStatut(4);
1110 print "</td>\n";
1111 print '</tr>';
1112 $i++;
1113 }
1114 $db->free($resql);
1115
1116 if ($num > 0) {
1117 print "</table>";
1118 print '</div>';
1119 }
1120 } else {
1121 dol_print_error($db);
1122 }
1123 }
1124
1125 // Allow external modules to add their own shortlist of recent objects
1126 $parameters = array();
1127 $reshook = $hookmanager->executeHooks('addMoreRecentObjects', $parameters, $object, $action);
1128 if ($reshook < 0) {
1129 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1130 } else {
1131 print $hookmanager->resPrint;
1132 }
1133
1134 print '</div></div>';
1135 print '<div class="clearboth"></div>';
1136
1137 print dol_get_fiche_end();
1138
1139
1140 /*
1141 * Action bar
1142 */
1143 print '<div class="tabsAction">';
1144
1145 $parameters = array();
1146 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
1147 // modified by hook
1148 if (empty($reshook)) {
1149 // Tooltip to use on buttons when the thirdparty is closed
1150 $thirdpartyclosedtitle = ($object->status == 1 ? '' : $langs->trans("ThirdPartyIsClosed"));
1151
1152 // Url to go back to the thirdparty card when clicking on the cancel button of the creation page
1153 $backtopageforcancel = $_SERVER['PHP_SELF'].'?socid='.$object->id;
1154
1155 $arrayforbutaction = array();
1156
1157 // Create a supplier proposal
1158 $arrayforbutaction[] = array(
1159 'lang' => 'supplier_proposal',
1160 'enabled' => isModEnabled('supplier_proposal'),
1161 'perm' => ($object->status == 1 && $user->hasRight('supplier_proposal', 'creer')),
1162 'label' => 'AddSupplierProposal',
1163 'url' => '/supplier_proposal/card.php?action=create&socid='.$object->id.'&backtopageforcancel='.urlencode($backtopageforcancel),
1164 'attr' => ($thirdpartyclosedtitle ? array('title' => $thirdpartyclosedtitle) : array()),
1165 'params' => ($thirdpartyclosedtitle ? array('attr' => array('title' => $thirdpartyclosedtitle)) : array())
1166 );
1167
1168 // Create a supplier order
1169 $arrayforbutaction[] = array(
1170 'lang' => 'orders',
1171 'enabled' => isModEnabled('supplier_order'),
1172 'perm' => ($object->status == 1 && ($user->hasRight('fournisseur', 'commande', 'creer') || $user->hasRight('supplier_order', 'creer'))),
1173 'label' => 'AddSupplierOrderShort',
1174 'url' => '/fourn/commande/card.php?action=create&socid='.$object->id.'&backtopageforcancel='.urlencode($backtopageforcancel),
1175 'attr' => ($thirdpartyclosedtitle ? array('title' => $thirdpartyclosedtitle) : array()),
1176 'params' => ($thirdpartyclosedtitle ? array('attr' => array('title' => $thirdpartyclosedtitle)) : array())
1177 );
1178
1179 // Create a contract
1180 $arrayforbutaction[] = array(
1181 'lang' => 'contracts',
1182 'enabled' => isModEnabled('contract'),
1183 'perm' => ($object->status == 1 && $user->hasRight('contrat', 'creer')),
1184 'label' => 'AddContract',
1185 'url' => '/contrat/card.php?action=create&socid='.$object->id.'&contract_type=1&backtopageforcancel='.urlencode($backtopageforcancel),
1186 'attr' => ($thirdpartyclosedtitle ? array('title' => $thirdpartyclosedtitle) : array()),
1187 'params' => ($thirdpartyclosedtitle ? array('attr' => array('title' => $thirdpartyclosedtitle)) : array())
1188 );
1189
1190 // Create a supplier invoice
1191 $arrayforbutaction[] = array(
1192 'lang' => 'bills',
1193 'enabled' => isModEnabled('supplier_invoice'),
1194 'perm' => ($object->status == 1 && ($user->hasRight('fournisseur', 'facture', 'creer') || $user->hasRight('supplier_invoice', 'creer'))),
1195 'label' => 'AddBill',
1196 'url' => '/fourn/facture/card.php?action=create&socid='.$object->id.'&backtopageforcancel='.urlencode($backtopageforcancel),
1197 'attr' => ($thirdpartyclosedtitle ? array('title' => $thirdpartyclosedtitle) : array()),
1198 'params' => ($thirdpartyclosedtitle ? array('attr' => array('title' => $thirdpartyclosedtitle)) : array())
1199 );
1200
1201 // Check if at least one object can be created
1202 $permissiontocreateatleastone = 0;
1203 foreach ($arrayforbutaction as $butaction) {
1204 if (!empty($butaction['perm'])) {
1205 $permissiontocreateatleastone = 1;
1206 break;
1207 }
1208 }
1209
1210 // Show the "Create" button with a dropdown list of objects (or flat buttons if option MAIN_REMOVE_DROPDOWN_CREATE_BUTTONS_ON_THIRDPARTY is set)
1211 if (!empty($arrayforbutaction)) {
1212 $createbuttontitle = '';
1213 $createbuttonright = 1;
1214 if ($object->status != 1) {
1215 $createbuttontitle = $langs->trans("ThirdPartyIsClosed");
1216 $createbuttonright = 0;
1217 } elseif (empty($permissiontocreateatleastone)) {
1218 $createbuttontitle = $langs->trans("NotAllowed");
1219 $createbuttonright = 0;
1220 }
1221
1222 print dolGetButtonAction($createbuttontitle, $langs->trans("Create"), 'default', $arrayforbutaction, '', $createbuttonright, array('areDropdownButtons' => !getDolGlobalInt("MAIN_REMOVE_DROPDOWN_CREATE_BUTTONS_ON_THIRDPARTY")));
1223 }
1224
1225 if ($user->hasRight('fournisseur', 'facture', 'creer') || $user->hasRight('supplier_invoice', 'creer')) {
1226 if (!empty($orders2invoice) && $orders2invoice > 0) {
1227 if ($object->status == 1) {
1228 // Company is open
1229 print dolGetButtonAction('', $langs->trans('CreateInvoiceForThisSupplier'), 'default', DOL_URL_ROOT.'/fourn/commande/list.php?socid='.$object->id.'&search_billed=0&autoselectall=1', '');
1230 } else {
1231 print dolGetButtonAction('', $langs->trans('CreateInvoiceForThisCustomer'), 'default', $_SERVER['PHP_SELF'].'#', '', false);
1232 }
1233 } else {
1234 if ($object->status == 1) {
1235 print dolGetButtonAction($langs->trans("NoSupplierOrdersToInvoice").' ('.$langs->trans("WithReceptionFinished").')', $langs->trans('CreateInvoiceForThisCustomer'), 'default', $_SERVER['PHP_SELF'].'#', '', false);
1236 } else {
1237 print dolGetButtonAction($langs->trans('ThirdPartyIsClosed'), $langs->trans('CreateInvoiceForThisCustomer'), 'default', $_SERVER['PHP_SELF'].'#', '', false);
1238 }
1239 }
1240 }
1241
1242 // Add action
1243 if (isModEnabled('agenda') && getDolGlobalString('MAIN_REPEATTASKONEACHTAB') && $object->status == 1) {
1244 if ($user->hasRight("agenda", "myactions", "create")) {
1245 print dolGetButtonAction('', $langs->trans('AddAction'), 'default', DOL_URL_ROOT.'/comm/action/card.php?action=create&socid='.$object->id, '');
1246 } else {
1247 print dolGetButtonAction($langs->trans('NotAllowed'), $langs->trans('AddAction'), 'default', $_SERVER['PHP_SELF'].'#', '', false);
1248 }
1249 }
1250 }
1251
1252 print '</div>';
1253
1254
1255 if (getDolGlobalString('MAIN_DUPLICATE_CONTACTS_TAB_ON_MAIN_CARD')) {
1256 print '<br>';
1257 // List of contacts
1258 show_contacts($conf, $langs, $db, $object, $_SERVER["PHP_SELF"].'?socid='.$object->id);
1259 }
1260
1261 if (getDolGlobalString('MAIN_REPEATTASKONEACHTAB')) {
1262 print load_fiche_titre($langs->trans("ActionsOnCompany"), '', '');
1263
1264 // List of todo actions
1265 show_actions_todo($conf, $langs, $db, $object);
1266
1267 // List of done actions
1268 show_actions_done($conf, $langs, $db, $object);
1269 }
1270} else {
1271 dol_print_error($db);
1272}
1273
1274// End of page
1275llxFooter();
1276$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage accounting accounts.
Class to manage members of a foundation.
Class to manage predefined suppliers products.
const STATUS_RECEIVED_COMPLETELY
Received completely.
Class to manage contact/addresses.
Class to manage suppliers invoices.
Class to manage invoice templates.
Class to manage generation of HTML components for accounting management.
Class to manage generation of HTML components Only common components must be here.
Class to manage suppliers.
Class to manage products or services.
Class to manage projects.
Class to manage price ask supplier.
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, $subtabs='')
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.
global $mysoc
price2num($amount, $rounding='', $option=0, $currencycode='')
Function that return a number with universal decimal format (decimal separator is '.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
dol_htmlentities($string, $flags=ENT_QUOTES|ENT_SUBSTITUTE, $encoding='UTF-8', $double_encode=false)
Replace htmlentities functions.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
showValueWithClipboardCPButton($valuetocopy, $showonlyonhover=1, $texttoshow='')
Create a button to copy $valuetocopy in the clipboard (for copy and paste feature).
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
Definition html.lib.php:542
dolButtonToOpenUrlInDialogPopup($name, $label, $buttonstring, $url, $disabled='', $morecss='classlink button bordertransp', $jsonopen='', $jsonclose='', $accesskey='')
Return HTML code to output a button to open a dialog popup box.
Definition html.lib.php:437
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:740
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Definition html.lib.php:183
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
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.