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 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program. If not, see <https://www.gnu.org/licenses/>.
26 */
27
34// Load Dolibarr environment
35require '../main.inc.php';
45require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
46require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
47require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture-rec.class.php';
48require_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class.php';
49require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
50require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
51require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
52if (isModEnabled('member')) {
53 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
54}
55if (isModEnabled('accounting')) {
56 require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
57 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
58}
59if (isModEnabled('contract')) {
60 require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
61}
62
63// Load translation files required by page
64$langs->loadLangs(array('accountancy', 'companies', 'suppliers', 'products', 'bills', 'orders', 'commercial', 'contracts'));
65
66$action = GETPOST('action', 'aZ09');
67$cancel = GETPOST('cancel', 'alpha');
68
69$id = (GETPOSTINT('socid') ? GETPOSTINT('socid') : GETPOSTINT('id'));
70if ($user->isExternalUser()) {
71 $id = $user->isExternalUser();
72}
73
74// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
75$hookmanager->initHooks(array('thirdpartysupplier', 'globalcard'));
76
77$result = restrictedArea($user, 'societe&fournisseur', $id, '&societe', '', 'rowid');
78
79$object = new Fournisseur($db);
80
81// fetch optionals attributes and labels
82$extrafields->fetch_name_optionals_label($object->table_element);
83
84$permissiontoadd = $user->hasRight('societe', 'creer');
85$permissiontoeditextra = $permissiontoadd;
86if (GETPOST('attribute', 'aZ09') && isset($extrafields->attributes[$object->table_element]['perms'][GETPOST('attribute', 'aZ09')])) {
87 // For action 'update_extras', is there a specific permission set for the attribute to update
88 $permissiontoeditextra = dol_eval((string) $extrafields->attributes[$object->table_element]['perms'][GETPOST('attribute', 'aZ09')]);
89}
90
91// Security check
92$result = restrictedArea($user, 'societe', $id, '&societe', '', 'fk_soc', 'rowid', 0);
93
94if ($object->id > 0) {
95 if (!($object->fournisseur > 0) || !$user->hasRight("fournisseur", "lire")) {
97 }
98}
99
100
101/*
102 * Actions
103 */
104$error = 0;
105$parameters = array('id' => $id);
106$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
107if ($reshook < 0) {
108 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
109}
110
111if (empty($reshook)) {
112 if ($cancel) {
113 $action = "";
114 }
115
116 // set general supplier accounting account
117 if ($action == 'setsupplieraccountancycodegeneral' && $user->hasRight('societe', 'creer')) {
118 $result = $object->fetch($id);
119 $object->accountancy_code_supplier_general = GETPOST("supplieraccountancycodegeneral");
120 $result = $object->update($object->id, $user, 1, 0, 1);
121 if ($result < 0) {
122 setEventMessages($object->error, $object->errors, 'errors');
123 $_GET['action'] = 'editsupplieraccountancycode';
124 }
125 }
126
127 // Set auxiliary supplier accounting account
128 if ($action == 'setsupplieraccountancycode' && $user->hasRight('societe', 'creer')) {
129 $result = $object->fetch($id);
130 $object->code_compta_fournisseur = GETPOST("supplieraccountancycode");
131 $result = $object->update($object->id, $user, 1, 0, 1);
132 if ($result < 0) {
133 setEventMessages($object->error, $object->errors, 'errors');
134 $action = 'editsupplieraccountancycode';
135 }
136 }
137 // Set vat number accounting account
138 if ($action == 'settva_intra' && $user->hasRight('societe', 'creer')) {
139 $result = $object->fetch($id);
140 $object->tva_intra = GETPOST("tva_intra");
141 $result = $object->update($object->id, $user, 1, 0, 0);
142 if ($result < 0) {
143 setEventMessages($object->error, $object->errors, 'errors');
144 }
145 }
146 // Set payment terms of the settlement
147 if ($action == 'setconditions' && $user->hasRight('societe', 'creer')) {
148 $object->fetch($id);
149 $result = $object->setPaymentTerms(GETPOSTINT('cond_reglement_supplier_id'), GETPOSTINT('cond_reglement_supplier_id_deposit_percent'));
150 if ($result < 0) {
151 dol_print_error($db, $object->error);
152 }
153 }
154 // Payment mode
155 if ($action == 'setmode' && $user->hasRight('societe', 'creer')) {
156 $object->fetch($id);
157 $result = $object->setPaymentMethods(GETPOSTINT('mode_reglement_supplier_id'));
158 if ($result < 0) {
159 dol_print_error($db, $object->error);
160 }
161 }
162
163 // Bank account
164 if ($action == 'setbankaccount' && $user->hasRight('societe', 'creer')) {
165 $object->fetch($id);
166 $result = $object->setBankAccount(GETPOSTINT('fk_account'));
167 if ($result < 0) {
168 setEventMessages($object->error, $object->errors, 'errors');
169 }
170 }
171
172 // update supplier order min amount
173 if ($action == 'setsupplier_order_min_amount' && $user->hasRight('societe', 'creer')) {
174 $object->fetch($id);
175 $object->supplier_order_min_amount = price2num(GETPOST('supplier_order_min_amount', 'alpha'));
176 $result = $object->update($object->id, $user);
177 if ($result < 0) {
178 setEventMessages($object->error, $object->errors, 'errors');
179 }
180 }
181
182 if ($action == 'update_extras' && $permissiontoeditextra) {
183 $object->fetch($id);
184
185 $object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
186
187 $attribute_name = GETPOST('attribute', 'aZ09');
188
189 // Fill array 'array_options' with data from update form
190 $ret = $extrafields->setOptionalsFromPost(null, $object, $attribute_name);
191 if ($ret < 0) {
192 $error++;
193 }
194
195 if (!$error) {
196 $result = $object->updateExtraField($attribute_name, 'COMPANY_MODIFY');
197 if ($result < 0) {
198 setEventMessages($object->error, $object->errors, 'errors');
199 $error++;
200 }
201 }
202
203 if ($error) {
204 $action = 'edit_extras';
205 }
206 }
207}
208
209
210/*
211 * View
212 */
213
214$contactstatic = new Contact($db);
215$form = new Form($db);
216
217if ($id > 0 && empty($object->id)) {
218 // Load data of third party
219 $res = $object->fetch($id);
220 if ($object->id <= 0) {
221 if ($object->error) {
222 dol_print_error($db, $object->error);
223 exit(1);
224 }
225 // Fournisseur::fetch() filters on s.fournisseur > 0, so a third party that exists but is no
226 // longer a vendor returns no row and no database error. Show a readable message with a link to
227 // the generic card instead of the technical error page (#39618).
228 $langs->load("errors");
229 llxHeader('', $langs->trans("ThirdParty").' - '.$langs->trans('Supplier'));
230 print '<div class="warning">'.$langs->trans("ErrorRecordNotFound").' ('.$langs->trans("Supplier").')';
231 print ' <a href="'.DOL_URL_ROOT.'/societe/card.php?socid='.((int) $id).'">'.$langs->trans("ThirdParty").'</a>';
232 print '</div>';
233 llxFooter();
234 $db->close();
235 exit(0);
236 }
237}
238
239if ($object->id > 0) {
240 $title = $langs->trans("ThirdParty")." - ".$langs->trans('Supplier');
241 if (getDolGlobalString('MAIN_HTML_TITLE') && preg_match('/thirdpartynameonly/', getDolGlobalString('MAIN_HTML_TITLE')) && $object->name) {
242 $title = $object->name." - ".$langs->trans('Supplier');
243 }
244 $help_url = '';
245 llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-fourn page-card');
246
247 /*
248 * Show tabs
249 */
250 $head = societe_prepare_head($object);
251
252 print dol_get_fiche_head($head, 'supplier', $langs->trans("ThirdParty"), -1, 'company');
253
254 $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
255
256 dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom');
257
258 print '<div class="fichecenter"><div class="fichehalfleft">';
259
260 print '<div class="underbanner clearboth"></div>';
261 print '<table class="border centpercent tableforfield">';
262
263 // Nature Prospect/Customer/Supplier
264 print '<tr><td class="titlefield">'.$langs->trans('NatureOfThirdParty').'</td><td>';
265 print $object->getTypeUrl(1);
266 print '</td></tr>';
267
268 if ($object->fournisseur) {
269 $langs->load('compta');
270
271 print '<tr>';
272 print '<td class="titlefield">'.$langs->trans("SupplierCode").'</td><td>';
274 $tmpcheck = $object->check_codefournisseur();
275 if ($tmpcheck != 0 && $tmpcheck != -5) {
276 print ' <span class="paddingleftimp error inline-block valignmiddle" title="'.$object->error.'">('.$langs->trans("WrongSupplierCode").')</span>';
277 }
278 print '</td>';
279 print '</tr>';
280
281 if (isModEnabled('accounting')) {
282 $formaccounting = new FormAccounting($db);
283
284 print '<tr>';
285 print '<td>';
286 print $form->editfieldkey("SupplierAccountancyCodeGeneral", 'supplieraccountancycodegeneral', length_accountg($object->accountancy_code_supplier_general), $object, $user->hasRight('societe', 'creer'));
287 print '</td><td>';
288 if ($action == 'editsupplieraccountancycodegeneral' && $user->hasRight('societe', 'creer')) {
289 print $formaccounting->formAccountingAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->accountancy_code_supplier_general, 'supplieraccountancycodegeneral', 0, 1, '', 1);
290 } else {
291 if ($object->accountancy_code_supplier_general > 0) {
292 $accountingaccount = new AccountingAccount($db);
293 $accountingaccount->fetch(0, $object->accountancy_code_supplier_general, 1);
294
295 print $accountingaccount->getNomUrl(0, 1, 1, '', 1);
296 }
297 if (getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER')) {
298 if ($object->accountancy_code_supplier_general > 0) {
299 print ' - ';
300 }
301 $accountingAccountByDefault = '<span class="opacitymedium">' . $langs->trans("AccountingAccountByDefaultShort") . ": " . length_accountg(getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER')) . '</span>';
302 print $accountingAccountByDefault;
303 }
304 }
305 print '</td>';
306 print '</tr>';
307 }
308
309 print '<tr>';
310 print '<td>';
311 print $form->editfieldkey("SupplierAccountancyCode", 'supplieraccountancycode', $object->code_compta_fournisseur, $object, $user->hasRight('societe', 'creer'));
312 print '</td><td>';
313 print $form->editfieldval("SupplierAccountancyCode", 'supplieraccountancycode', $object->code_compta_fournisseur, $object, $user->hasRight('societe', 'creer'));
314 print '</td>';
315 print '</tr>';
316 }
317
318 // VAT is used
319 print '<tr>';
320 print '<td class="titlefield">';
321 print $form->textwithpicto($langs->trans('VATIsUsed'), $langs->trans('VATIsUsedWhenSelling'));
322 print '</td><td>';
323 print yn($object->tva_assuj);
324 print '</td>';
325 print '</tr>';
326
327 // Local Taxes
328 if ($mysoc->useLocalTax(1)) {
329 print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).'</td><td>';
330 print yn($object->localtax1_assuj);
331 print '</td></tr>';
332 }
333 if ($mysoc->useLocalTax(2)) {
334 print '<tr><td>'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).'</td><td>';
335 print yn($object->localtax2_assuj);
336 print '</td></tr>';
337 }
338
339 // VAT reverse-charge by default on supplier invoice or not
340 if (getDolGlobalString('ACCOUNTING_FORCE_ENABLE_VAT_REVERSE_CHARGE')) {
341 print '<tr>';
342 print '<td class="titlefield">';
343 print $form->textwithpicto($langs->trans('VATReverseChargeByDefault'), $langs->trans('VATReverseChargeByDefaultDesc').'<br>'.$langs->trans('ACCOUNTING_FORCE_ENABLE_VAT_REVERSE_CHARGE_DESC'));
344 print '</td><td>';
345 print '<input type="checkbox" name="vat_reverse_charge" ' . ($object->vat_reverse_charge == '1' ? ' checked' : '') . ' disabled>';
346 print '</td>';
347 print '</tr>';
348 }
349
350 // TVA Intra
351 print '<tr><td class="nowrap">';
352 //print $langs->trans('VATIntra').'</td><td>';
353 $vattoshow = ($object->tva_intra ? showValueWithClipboardCPButton(dol_escape_htmltag($object->tva_intra)) : '');
354 print $form->editfieldkey("VATIntra", 'tva_intra', $object->tva_intra, $object, $user->hasRight('societe', 'creer'));
355 print '</td><td>';
356 print $form->editfieldval("VATIntra", 'tva_intra', $vattoshow, $object, $user->hasRight('societe', 'creer'), 'string', $object->tva_intra, null, null, '', 1, '', 'id', 'auto', array('valuealreadyhtmlescaped' => 1));
357 print '</td></tr>';
358
359 // Default terms of the settlement
360 $langs->load('bills');
361 $form = new Form($db);
362 print '<tr><td>';
363 print '<table width="100%" class="nobordernopadding"><tr><td>';
364 print $langs->trans('PaymentConditions');
365 print '<td>';
366 if (($action != 'editconditions') && $user->hasRight('societe', 'creer')) {
367 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>';
368 }
369 print '</tr></table>';
370 print '</td><td>';
371 if ($action == 'editconditions') {
372 $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);
373 } else {
374 $form->form_conditions_reglement($_SERVER['PHP_SELF'] . '?socid=' . $object->id, (string) $object->cond_reglement_supplier_id, 'none', 0, '', 1, $object->deposit_percent);
375 }
376 print "</td>";
377 print '</tr>';
378
379 // Default payment mode
380 print '<tr><td class="nowrap">';
381 print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
382 print $langs->trans('PaymentMode');
383 print '<td>';
384 if (($action != 'editmode') && $user->hasRight('societe', 'creer')) {
385 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>';
386 }
387 print '</tr></table>';
388 print '</td><td>';
389 if ($action == 'editmode') {
390 $form->form_modes_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, (string) $object->mode_reglement_supplier_id, 'mode_reglement_supplier_id', 'DBIT', 1, 1);
391 } else {
392 $form->form_modes_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, (string) $object->mode_reglement_supplier_id, 'none');
393 }
394 print "</td>";
395 print '</tr>';
396
397 if (isModEnabled("bank")) {
398 // Default bank account for payments
399 print '<tr><td class="nowrap">';
400 print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
401 print $langs->trans('PaymentBankAccount');
402 print '<td>';
403 if (($action != 'editbankaccount') && $user->hasRight('societe', 'creer')) {
404 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>';
405 }
406 print '</tr></table>';
407 print '</td><td>';
408 if ($action == 'editbankaccount') {
409 $form->formSelectAccount($_SERVER['PHP_SELF'].'?socid='.$object->id, (string) $object->fk_account, 'fk_account', 1);
410 } else {
411 $form->formSelectAccount($_SERVER['PHP_SELF'].'?socid='.$object->id, (string) $object->fk_account, 'none');
412 }
413 print "</td>";
414 print '</tr>';
415 }
416
417 // Relative discounts (Discounts-Drawbacks-Rebates)
418 print '<tr><td class="nowrap">';
419 print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
420 print $langs->trans("CustomerRelativeDiscountShort");
421 print '<td><td class="right">';
422 if ($user->hasRight('societe', 'creer') && !$user->socid > 0) {
423 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>';
424 }
425 print '</td></tr></table>';
426 print '</td><td>'.($object->remise_supplier_percent ? '<a href="'.DOL_URL_ROOT.'/comm/remise.php?id='.$object->id.'">'.$object->remise_supplier_percent.'%</a>' : '').'</td>';
427 print '</tr>';
428
429 // Absolute discounts (Discounts-Drawbacks-Rebates)
430 print '<tr><td class="nowrap">';
431 print '<table width="100%" class="nobordernopadding">';
432 print '<tr><td class="nowrap">';
433 print $langs->trans("CustomerAbsoluteDiscountShort");
434 print '<td><td class="right">';
435 if ($user->hasRight('societe', 'creer') && !$user->socid > 0) {
436 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>';
437 }
438 print '</td></tr></table>';
439 print '</td>';
440 print '<td>';
441 $amount_discount = $object->getAvailableDiscounts(null, '', 0, 1);
442 if ($amount_discount < 0) {
443 dol_print_error($db, $object->error);
444 }
445 if ($amount_discount > 0) {
446 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>';
447 }
448 //else print $langs->trans("DiscountNone");
449 print '</td>';
450 print '</tr>';
451
452 if (isModEnabled("supplier_order") && getDolGlobalString('ORDER_MANAGE_MIN_AMOUNT')) {
453 print '<tr class="nowrap">';
454 print '<td>';
455 print $form->editfieldkey("OrderMinAmount", 'supplier_order_min_amount', $object->supplier_order_min_amount, $object, $user->hasRight("societe", "creer"));
456 print '</td><td>';
457 //$limit_field_type = (getDolGlobalString('MAIN_USE_EDIT_IN_PLACE')) ? 'numeric' : 'amount'; // TODO deprecated ?
458 $limit_field_type = 'amount';
459 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) : ''));
460 print '</td>';
461 print '</tr>';
462 }
463
464 // Categories
465 if (isModEnabled('category')) {
466 $langs->load("categories");
467 print '<tr><td>'.$langs->trans("SuppliersCategoriesShort").'</td>';
468 print '<td>';
469 print $form->showCategories($object->id, Categorie::TYPE_SUPPLIER, 1);
470 print "</td></tr>";
471 }
472
473 // Other attributes
474 $parameters = array('socid' => $object->id, 'colspan' => ' colspan="3"', 'colspanvalue' => '3');
475 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
476
477 // Module Adherent
478 if (isModEnabled('member')) {
479 $langs->load("members");
480 $langs->load("users");
481 print '<tr><td>'.$langs->trans("LinkedToDolibarrMember").'</td>';
482 print '<td>';
483 $adh = new Adherent($db);
484 $result = $adh->fetch(0, '', $object->id);
485 if ($result > 0) {
486 $adh->ref = $adh->getFullName($langs);
487 print $adh->getNomUrl(1);
488 } else {
489 print $langs->trans("ThirdpartyNotLinkedToMember");
490 }
491 print '</td>';
492 print "</tr>\n";
493 }
494
495 print '</table>';
496
497
498 print '</div><div class="fichehalfright">';
499
500 $boxstat = '';
501
502 // Nbre max d'elements des petites listes
503 $MAXLIST = getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT', 5);
504
505 print '<div class="underbanner underbanner-before-box clearboth"></div>';
506 print '<br>';
507
508 // Summary link
509 $boxstat .= '<div class="box divboxtable box-halfright">';
510 $boxstat .= '<table summary="'.dol_escape_htmltag($langs->trans("DolibarrStateBoard")).'" class="border boxtable boxtablenobottom boxtablenotop" width="100%">';
511 $boxstat .= '<tr class="impair nohover"><td colspan="2" class="tdboxstats nohover">';
512
513 if (isModEnabled('supplier_proposal')) {
514 // Box proposals
515 $tmp = $object->getOutstandingProposals('supplier');
516 $outstandingOpened = $tmp['opened'];
517 $outstandingTotal = $tmp['total_ht'];
518 $outstandingTotalIncTax = $tmp['total_ttc'];
519 $text = $langs->trans("OverAllSupplierProposals");
520 $link = DOL_URL_ROOT.'/supplier_proposal/list.php?socid='.$object->id;
521 $icon = 'bill';
522 if ($link) {
523 $boxstat .= '<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
524 }
525 $boxstat .= '<div class="boxstats" title="'.dol_escape_htmltag($text).'">';
526 $boxstat .= '<span class="boxstatstext">'.img_object("", $icon).' <span>'.$text.'</span></span><br>';
527 $boxstat .= '<span class="boxstatsindicator">'.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
528 $boxstat .= '</div>';
529 if ($link) {
530 $boxstat .= '</a>';
531 }
532 }
533
534 if (isModEnabled("supplier_order")) {
535 // Box proposals
536 $tmp = $object->getOutstandingOrders('supplier');
537 $outstandingOpened = $tmp['opened'];
538 $outstandingTotal = $tmp['total_ht'];
539 $outstandingTotalIncTax = $tmp['total_ttc'];
540 $text = $langs->trans("OverAllOrders");
541 $link = DOL_URL_ROOT.'/fourn/commande/list.php?socid='.$object->id;
542 $icon = 'bill';
543 if ($link) {
544 $boxstat .= '<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
545 }
546 $boxstat .= '<div class="boxstats" title="'.dol_escape_htmltag($text).'">';
547 $boxstat .= '<span class="boxstatstext">'.img_object("", $icon).' <span>'.$text.'</span></span><br>';
548 $boxstat .= '<span class="boxstatsindicator">'.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
549 $boxstat .= '</div>';
550 if ($link) {
551 $boxstat .= '</a>';
552 }
553 }
554
555 if (isModEnabled("supplier_invoice") && ($user->hasRight('fournisseur', 'facture', 'lire') || $user->hasRight('supplier_invoice', 'read'))) {
556 $warn = '';
557 $tmp = $object->getOutstandingBills('supplier');
558 $outstandingOpened = $tmp['opened'];
559 $outstandingTotal = $tmp['total_ht'];
560 $outstandingTotalIncTax = $tmp['total_ttc'];
561
562 $text = $langs->trans("OverAllInvoices");
563 $link = DOL_URL_ROOT.'/fourn/facture/list.php?socid='.$object->id;
564 $icon = 'bill';
565 if ($link) {
566 $boxstat .= '<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
567 }
568 $boxstat .= '<div class="boxstats" title="'.dol_escape_htmltag($text).'">';
569 $boxstat .= '<span class="boxstatstext">'.img_object("", $icon).' <span>'.$text.'</span></span><br>';
570 $boxstat .= '<span class="boxstatsindicator">'.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
571 $boxstat .= '</div>';
572 if ($link) {
573 $boxstat .= '</a>';
574 }
575
576 // Box outstanding bill
577 $text = $langs->trans("CurrentOutstandingBill");
578 $link = DOL_URL_ROOT.'/fourn/recap-fourn.php?socid='.$object->id;
579 $icon = 'bill';
580 if ($link) {
581 $boxstat .= '<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
582 }
583 $boxstat .= '<div class="boxstats" title="'.dol_escape_htmltag($text).'">';
584 $boxstat .= '<span class="boxstatstext">'.img_object("", $icon).' <span>'.$text.'</span></span><br>';
585 $boxstat .= '<span class="boxstatsindicator'.($outstandingOpened > 0 ? ' amountremaintopay' : '').'">'.price($outstandingOpened, 1, $langs, 1, -1, -1, $conf->currency).$warn.'</span>';
586 $boxstat .= '</div>';
587 if ($link) {
588 $boxstat .= '</a>';
589 }
590
591 $tmp = $object->getOutstandingBills('supplier', 1);
592 $outstandingOpenedLate = $tmp['opened'];
593 if ($outstandingOpened != $outstandingOpenedLate && !empty($outstandingOpenedLate)) {
594 $text = $langs->trans("CurrentOutstandingBillLate");
595 $link = DOL_URL_ROOT.'/fourn/recap-fourn.php?socid='.$object->id;
596 $icon = 'bill';
597 if ($link) {
598 $boxstat .= '<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
599 }
600 $boxstat .= '<div class="boxstats" title="'.dol_escape_htmltag($text).'">';
601 $boxstat .= '<span class="boxstatstext">'.img_object("", $icon).' <span>'.$text.'</span></span><br>';
602 $boxstat .= '<span class="boxstatsindicator'.($outstandingOpenedLate > 0 ? ' amountremaintopay' : '').'">'.price($outstandingOpenedLate, 1, $langs, 1, -1, -1, $conf->currency).$warn.'</span>';
603 $boxstat .= '</div>';
604 if ($link) {
605 $boxstat .= '</a>';
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("AllOrders").'</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($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 if (isModEnabled('supplier_proposal') && $user->hasRight("supplier_proposal", "creer")) {
1150 $langs->load("supplier_proposal");
1151 if ($object->status == 1) {
1152 print dolGetButtonAction('', $langs->trans('AddSupplierProposal'), 'default', DOL_URL_ROOT.'/supplier_proposal/card.php?action=create&socid='.$object->id, '');
1153 } else {
1154 print dolGetButtonAction($langs->trans('ThirdPartyIsClosed'), $langs->trans('AddSupplierProposal'), 'default', $_SERVER['PHP_SELF'].'#', '', false);
1155 }
1156 }
1157
1158 if ($user->hasRight('fournisseur', 'commande', 'creer') || $user->hasRight('supplier_order', 'creer')) {
1159 $langs->load("orders");
1160 if ($object->status == 1) {
1161 print dolGetButtonAction('', $langs->trans('AddSupplierOrderShort'), 'default', DOL_URL_ROOT.'/fourn/commande/card.php?action=create&socid='.$object->id, '');
1162 } else {
1163 print dolGetButtonAction($langs->trans('ThirdPartyIsClosed'), $langs->trans('AddSupplierOrderShort'), 'default', $_SERVER['PHP_SELF'].'#', '', false);
1164 }
1165 }
1166
1167 if (isModEnabled('contract') && $user->hasRight('contrat', 'creer') && $object->status == 1) {
1168 print dolGetButtonAction('', $langs->trans('AddContract'), 'default', DOL_URL_ROOT.'/contrat/card.php?action=create&amp;socid='.$object->id.'&amp;contract_type=1', '');
1169 } elseif (isModEnabled('contract') && $user->hasRight('contrat', 'creer')) {
1170 print dolGetButtonAction($langs->trans('ThirdPartyIsClosed'), $langs->trans('AddContract'), 'default', $_SERVER['PHP_SELF'].'#', '', false);
1171 }
1172
1173 if ($user->hasRight('fournisseur', 'facture', 'creer') || $user->hasRight('supplier_invoice', 'creer')) {
1174 if (!empty($orders2invoice) && $orders2invoice > 0) {
1175 if ($object->status == 1) {
1176 // Company is open
1177 print dolGetButtonAction('', $langs->trans('CreateInvoiceForThisSupplier'), 'default', DOL_URL_ROOT.'/fourn/commande/list.php?socid='.$object->id.'&search_billed=0&autoselectall=1', '');
1178 } else {
1179 print dolGetButtonAction('', $langs->trans('CreateInvoiceForThisCustomer'), 'default', $_SERVER['PHP_SELF'].'#', '', false);
1180 }
1181 } else {
1182 if ($object->status == 1) {
1183 print dolGetButtonAction($langs->trans("NoOrdersToInvoice").' ('.$langs->trans("WithReceptionFinished").')', $langs->trans('CreateInvoiceForThisCustomer'), 'default', $_SERVER['PHP_SELF'].'#', '', false);
1184 } else {
1185 print dolGetButtonAction($langs->trans('ThirdPartyIsClosed'), $langs->trans('CreateInvoiceForThisCustomer'), 'default', $_SERVER['PHP_SELF'].'#', '', false);
1186 }
1187 }
1188 }
1189
1190 if ($user->hasRight('fournisseur', 'facture', 'creer') || $user->hasRight('supplier_invoice', 'creer')) {
1191 $langs->load("bills");
1192 if ($object->status == 1) {
1193 print dolGetButtonAction('', $langs->trans('AddBill'), 'default', DOL_URL_ROOT.'/fourn/facture/card.php?action=create&socid='.$object->id, '');
1194 } else {
1195 print dolGetButtonAction($langs->trans('ThirdPartyIsClosed'), $langs->trans('AddBill'), 'default', $_SERVER['PHP_SELF'].'#', '', false);
1196 }
1197 }
1198
1199 // Add action
1200 if (isModEnabled('agenda') && getDolGlobalString('MAIN_REPEATTASKONEACHTAB') && $object->status == 1) {
1201 if ($user->hasRight("agenda", "myactions", "create")) {
1202 print dolGetButtonAction('', $langs->trans('AddAction'), 'default', DOL_URL_ROOT.'/comm/action/card.php?action=create&socid='.$object->id, '');
1203 } else {
1204 print dolGetButtonAction($langs->trans('NotAllowed'), $langs->trans('AddAction'), 'default', $_SERVER['PHP_SELF'].'#', '', false);
1205 }
1206 }
1207 }
1208
1209 print '</div>';
1210
1211
1212 if (getDolGlobalString('MAIN_DUPLICATE_CONTACTS_TAB_ON_MAIN_CARD')) {
1213 print '<br>';
1214 // List of contacts
1215 show_contacts($conf, $langs, $db, $object, $_SERVER["PHP_SELF"].'?socid='.$object->id);
1216 }
1217
1218 if (getDolGlobalString('MAIN_REPEATTASKONEACHTAB')) {
1219 print load_fiche_titre($langs->trans("ActionsOnCompany"), '', '');
1220
1221 // List of todo actions
1222 show_actions_todo($conf, $langs, $db, $object);
1223
1224 // List of done actions
1225 show_actions_done($conf, $langs, $db, $object);
1226 }
1227} else {
1228 dol_print_error($db);
1229}
1230
1231// End of page
1232llxFooter();
1233$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
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
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
price2num($amount, $rounding='', $option=0)
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:540
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:738
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:181
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.