dolibarr  13.0.2
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  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program. If not, see <https://www.gnu.org/licenses/>.
23  */
24 
31 require '../main.inc.php';
32 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
38 if (!empty($conf->adherent->enabled)) require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
39 if (!empty($conf->categorie->enabled)) require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
40 
41 // Load translation files required by page
42 $langs->loadLangs(array(
43  'companies',
44  'suppliers',
45  'products',
46  'bills',
47  'orders',
48  'commercial',
49 ));
50 
51 $action = GETPOST('action', 'aZ09');
52 $cancelbutton = GETPOST('cancel', 'alpha');
53 
54 // Security check
55 $id = (GETPOST('socid', 'int') ? GETPOST('socid', 'int') : GETPOST('id', 'int'));
56 if ($user->socid) $id = $user->socid;
57 $result = restrictedArea($user, 'societe&fournisseur', $id, '&societe', '', 'rowid');
58 
59 $object = new Fournisseur($db);
60 $extrafields = new ExtraFields($db);
61 
62 // fetch optionals attributes and labels
63 $extrafields->fetch_name_optionals_label($object->table_element);
64 
65 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
66 $hookmanager->initHooks(array('suppliercard', 'globalcard'));
67 
68 // Security check
69 $result = restrictedArea($user, 'societe', $socid, '&societe', '', 'fk_soc', 'rowid', 0);
70 
71 if ($object->id > 0) {
72  if (!($object->fournisseur > 0) || empty($user->rights->fournisseur->lire)) {
74  }
75 }
76 
77 
78 /*
79  * Action
80  */
81 
82 $parameters = array('id'=>$id);
83 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
84 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
85 
86 if (empty($reshook))
87 {
88  if ($cancelbutton)
89  {
90  $action = "";
91  }
92 
93  if ($action == 'setsupplieraccountancycode')
94  {
95  $result = $object->fetch($id);
96  $object->code_compta_fournisseur = $_POST["supplieraccountancycode"];
97  $result = $object->update($object->id, $user, 1, 0, 1);
98  if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
99  }
100  // terms of the settlement
101  if ($action == 'setconditions' && $user->rights->societe->creer)
102  {
103  $object->fetch($id);
104  $result = $object->setPaymentTerms(GETPOST('cond_reglement_supplier_id', 'int'));
105  if ($result < 0) dol_print_error($db, $object->error);
106  }
107  // mode de reglement
108  if ($action == 'setmode' && $user->rights->societe->creer)
109  {
110  $object->fetch($id);
111  $result = $object->setPaymentMethods(GETPOST('mode_reglement_supplier_id', 'int'));
112  if ($result < 0) dol_print_error($db, $object->error);
113  }
114 
115  // update supplier order min amount
116  if ($action == 'setsupplier_order_min_amount')
117  {
118  $object->fetch($id);
119  $object->supplier_order_min_amount = price2num(GETPOST('supplier_order_min_amount', 'alpha'));
120  $result = $object->update($object->id, $user);
121  if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
122  }
123 
124  if ($action == 'update_extras') {
125  $object->fetch($id);
126 
127  $object->oldcopy = dol_clone($object);
128 
129  // Fill array 'array_options' with data from update form
130  $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'restricthtml'));
131 
132  if ($ret < 0) $error++;
133 
134  if (!$error)
135  {
136  $result = $object->insertExtraFields('COMPANY_MODIFY');
137  if ($result < 0) $error++;
138  }
139 
140  if ($error) $action = 'edit_extras';
141  }
142 }
143 
144 
145 /*
146  * View
147  */
148 
149 $contactstatic = new Contact($db);
150 $form = new Form($db);
151 
152 if ($id > 0 && empty($object->id))
153 {
154  // Load data of third party
155  $res = $object->fetch($id);
156  if ($object->id <= 0) dol_print_error($db, $object->error);
157 }
158 
159 if ($object->id > 0)
160 {
161  $title = $langs->trans("ThirdParty")." - ".$langs->trans('Supplier');
162  if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) $title = $object->name." - ".$langs->trans('Supplier');
163  $help_url = '';
164  llxHeader('', $title, $help_url);
165 
166  /*
167  * Show tabs
168  */
169  $head = societe_prepare_head($object);
170 
171  print dol_get_fiche_head($head, 'supplier', $langs->trans("ThirdParty"), -1, 'company');
172 
173  $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
174 
175  dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom');
176 
177  print '<div class="fichecenter"><div class="fichehalfleft">';
178 
179  print '<div class="underbanner clearboth"></div>';
180  print '<table width="100%" class="border">';
181 
182  if (!empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field
183  {
184  print '<tr><td>'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>';
185  }
186 
187  if ($object->fournisseur)
188  {
189  print '<tr>';
190  print '<td class="titlefield">'.$langs->trans("SupplierCode").'</td><td>';
191  print $object->code_fournisseur;
192  $tmpcheck = $object->check_codefournisseur();
193  if ($tmpcheck != 0 && $tmpcheck != -5) {
194  print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>';
195  }
196  print '</td>';
197  print '</tr>';
198 
199  $langs->load('compta');
200  print '<tr>';
201  print '<td>';
202  print $form->editfieldkey("SupplierAccountancyCode", 'supplieraccountancycode', $object->code_compta_fournisseur, $object, $user->rights->societe->creer);
203  print '</td><td>';
204  print $form->editfieldval("SupplierAccountancyCode", 'supplieraccountancycode', $object->code_compta_fournisseur, $object, $user->rights->societe->creer);
205  print '</td>';
206  print '</tr>';
207  }
208 
209  // Assujetti a TVA ou pas
210  print '<tr>';
211  print '<td class="titlefield">';
212  print $form->textwithpicto($langs->trans('VATIsUsed'), $langs->trans('VATIsUsedWhenSelling'));
213  print '</td><td>';
214  print yn($object->tva_assuj);
215  print '</td>';
216  print '</tr>';
217 
218  // Local Taxes
219  if ($mysoc->useLocalTax(1))
220  {
221  print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).'</td><td>';
222  print yn($object->localtax1_assuj);
223  print '</td></tr>';
224  }
225  if ($mysoc->useLocalTax(2))
226  {
227  print '<tr><td>'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).'</td><td>';
228  print yn($object->localtax2_assuj);
229  print '</td></tr>';
230  }
231 
232  // TVA Intra
233  print '<tr><td class="nowrap">'.$langs->trans('VATIntra').'</td><td>';
234  print $object->tva_intra;
235  print '</td></tr>';
236 
237  // Default terms of the settlement
238  $langs->load('bills');
239  $form = new Form($db);
240  print '<tr><td>';
241  print '<table width="100%" class="nobordernopadding"><tr><td>';
242  print $langs->trans('PaymentConditions');
243  print '<td>';
244  if (($action != 'editconditions') && $user->rights->societe->creer) print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editconditions&amp;socid='.$object->id.'">'.img_edit($langs->trans('SetConditions'), 1).'</a></td>';
245  print '</tr></table>';
246  print '</td><td>';
247  if ($action == 'editconditions')
248  {
249  $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->cond_reglement_supplier_id, 'cond_reglement_supplier_id', -1, 1);
250  } else {
251  $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->cond_reglement_supplier_id, 'none');
252  }
253  print "</td>";
254  print '</tr>';
255 
256  // Mode de reglement par defaut
257  print '<tr><td class="nowrap">';
258  print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
259  print $langs->trans('PaymentMode');
260  print '<td>';
261  if (($action != 'editmode') && $user->rights->societe->creer) print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editmode&amp;socid='.$object->id.'">'.img_edit($langs->trans('SetMode'), 1).'</a></td>';
262  print '</tr></table>';
263  print '</td><td>';
264  if ($action == 'editmode')
265  {
266  $form->form_modes_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->mode_reglement_supplier_id, 'mode_reglement_supplier_id', 'DBIT', 1, 1);
267  } else {
268  $form->form_modes_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->mode_reglement_supplier_id, 'none');
269  }
270  print "</td>";
271  print '</tr>';
272 
273  // Relative discounts (Discounts-Drawbacks-Rebates)
274  print '<tr><td class="nowrap">';
275  print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
276  print $langs->trans("CustomerRelativeDiscountShort");
277  print '<td><td class="right">';
278  if ($user->rights->societe->creer && !$user->socid > 0)
279  {
280  print '<a class="editfielda" href="'.DOL_URL_ROOT.'/comm/remise.php?id='.$object->id.'">'.img_edit($langs->trans("Modify")).'</a>';
281  }
282  print '</td></tr></table>';
283  print '</td><td>'.($object->remise_supplier_percent ? '<a href="'.DOL_URL_ROOT.'/comm/remise.php?id='.$object->id.'">'.$object->remise_supplier_percent.'%</a>' : '').'</td>';
284  print '</tr>';
285 
286  // Absolute discounts (Discounts-Drawbacks-Rebates)
287  print '<tr><td class="nowrap">';
288  print '<table width="100%" class="nobordernopadding">';
289  print '<tr><td class="nowrap">';
290  print $langs->trans("CustomerAbsoluteDiscountShort");
291  print '<td><td class="right">';
292  if ($user->rights->societe->creer && !$user->socid > 0)
293  {
294  print '<a class="editfielda" href="'.DOL_URL_ROOT.'/comm/remx.php?id='.$object->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?socid='.$object->id).'">'.img_edit($langs->trans("Modify")).'</a>';
295  }
296  print '</td></tr></table>';
297  print '</td>';
298  print '<td>';
299  $amount_discount = $object->getAvailableDiscounts('', '', 0, 1);
300  if ($amount_discount < 0) dol_print_error($db, $object->error);
301  if ($amount_discount > 0) print '<a href="'.DOL_URL_ROOT.'/comm/remx.php?id='.$object->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?socid='.$object->id).'">'.price($amount_discount, 1, $langs, 1, -1, -1, $conf->currency).'</a>';
302  //else print $langs->trans("DiscountNone");
303  print '</td>';
304  print '</tr>';
305 
306  if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_order->enabled)) && !empty($conf->global->ORDER_MANAGE_MIN_AMOUNT))
307  {
308  print '<tr class="nowrap">';
309  print '<td>';
310  print $form->editfieldkey("OrderMinAmount", 'supplier_order_min_amount', $object->supplier_order_min_amount, $object, $user->rights->societe->creer);
311  print '</td><td>';
312  $limit_field_type = (!empty($conf->global->MAIN_USE_JQUERY_JEDITABLE)) ? 'numeric' : 'amount';
313  print $form->editfieldval("OrderMinAmount", 'supplier_order_min_amount', $object->supplier_order_min_amount, $object, $user->rights->societe->creer, $limit_field_type, ($object->supplier_order_min_amount != '' ? price($object->supplier_order_min_amount) : ''));
314  print '</td>';
315  print '</tr>';
316  }
317 
318  // Categories
319  if (!empty($conf->categorie->enabled))
320  {
321  $langs->load("categories");
322  print '<tr><td>'.$langs->trans("SuppliersCategoriesShort").'</td>';
323  print '<td>';
324  print $form->showCategories($object->id, Categorie::TYPE_SUPPLIER, 1);
325  print "</td></tr>";
326  }
327 
328  // Other attributes
329  $parameters = array('socid'=>$object->id, 'colspan' => ' colspan="3"', 'colspanvalue' => '3');
330  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
331 
332  // Module Adherent
333  if (!empty($conf->adherent->enabled))
334  {
335  $langs->load("members");
336  $langs->load("users");
337  print '<tr><td>'.$langs->trans("LinkedToDolibarrMember").'</td>';
338  print '<td>';
339  $adh = new Adherent($db);
340  $result = $adh->fetch('', '', $object->id);
341  if ($result > 0)
342  {
343  $adh->ref = $adh->getFullName($langs);
344  print $adh->getNomUrl(1);
345  } else {
346  print $langs->trans("ThirdpartyNotLinkedToMember");
347  }
348  print '</td>';
349  print "</tr>\n";
350  }
351 
352  print '</table>';
353 
354 
355  print '</div><div class="fichehalfright"><div class="ficheaddleft">';
356 
357  $boxstat = '';
358 
359  // Nbre max d'elements des petites listes
360  $MAXLIST = $conf->global->MAIN_SIZE_SHORTLIST_LIMIT;
361 
362  print '<div class="underbanner clearboth"></div>';
363 
364  // Lien recap
365  $boxstat .= '<div class="box">';
366  $boxstat .= '<table summary="'.dol_escape_htmltag($langs->trans("DolibarrStateBoard")).'" class="border boxtable boxtablenobottom boxtablenotop" width="100%">';
367  $boxstat .= '<tr class="impair nohover"><td colspan="2" class="tdboxstats nohover">';
368 
369  if ($conf->supplier_proposal->enabled)
370  {
371  // Box proposals
372  $tmp = $object->getOutstandingProposals('supplier');
373  $outstandingOpened = $tmp['opened'];
374  $outstandingTotal = $tmp['total_ht'];
375  $outstandingTotalIncTax = $tmp['total_ttc'];
376  $text = $langs->trans("OverAllSupplierProposals");
377  $link = DOL_URL_ROOT.'/supplier_proposal/list.php?socid='.$object->id;
378  $icon = 'bill';
379  if ($link) $boxstat .= '<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
380  $boxstat .= '<div class="boxstats" title="'.dol_escape_htmltag($text).'">';
381  $boxstat .= '<span class="boxstatstext">'.img_object("", $icon).' <span>'.$text.'</span></span><br>';
382  $boxstat .= '<span class="boxstatsindicator">'.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
383  $boxstat .= '</div>';
384  if ($link) $boxstat .= '</a>';
385  }
386 
387  if (!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled))
388  {
389  // Box proposals
390  $tmp = $object->getOutstandingOrders('supplier');
391  $outstandingOpened = $tmp['opened'];
392  $outstandingTotal = $tmp['total_ht'];
393  $outstandingTotalIncTax = $tmp['total_ttc'];
394  $text = $langs->trans("OverAllOrders");
395  $link = DOL_URL_ROOT.'/fourn/commande/list.php?socid='.$object->id;
396  $icon = 'bill';
397  if ($link) $boxstat .= '<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
398  $boxstat .= '<div class="boxstats" title="'.dol_escape_htmltag($text).'">';
399  $boxstat .= '<span class="boxstatstext">'.img_object("", $icon).' <span>'.$text.'</span></span><br>';
400  $boxstat .= '<span class="boxstatsindicator">'.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
401  $boxstat .= '</div>';
402  if ($link) $boxstat .= '</a>';
403  }
404 
405  if (!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled))
406  {
407  $tmp = $object->getOutstandingBills('supplier');
408  $outstandingOpened = $tmp['opened'];
409  $outstandingTotal = $tmp['total_ht'];
410  $outstandingTotalIncTax = $tmp['total_ttc'];
411 
412  $text = $langs->trans("OverAllInvoices");
413  $link = DOL_URL_ROOT.'/fourn/facture/list.php?socid='.$object->id;
414  $icon = 'bill';
415  if ($link) $boxstat .= '<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
416  $boxstat .= '<div class="boxstats" title="'.dol_escape_htmltag($text).'">';
417  $boxstat .= '<span class="boxstatstext">'.img_object("", $icon).' <span>'.$text.'</span></span><br>';
418  $boxstat .= '<span class="boxstatsindicator">'.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
419  $boxstat .= '</div>';
420  if ($link) $boxstat .= '</a>';
421 
422  // Box outstanding bill
423  $text = $langs->trans("CurrentOutstandingBill");
424  $link = DOL_URL_ROOT.'/fourn/recap-fourn.php?socid='.$object->id;
425  $icon = 'bill';
426  if ($link) $boxstat .= '<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
427  $boxstat .= '<div class="boxstats" title="'.dol_escape_htmltag($text).'">';
428  $boxstat .= '<span class="boxstatstext">'.img_object("", $icon).' <span>'.$text.'</span></span><br>';
429  $boxstat .= '<span class="boxstatsindicator'.($outstandingOpened > 0 ? ' amountremaintopay' : '').'">'.price($outstandingOpened, 1, $langs, 1, -1, -1, $conf->currency).$warn.'</span>';
430  $boxstat .= '</div>';
431  if ($link) $boxstat .= '</a>';
432 
433  $tmp = $object->getOutstandingBills('supplier', 1);
434  $outstandingOpenedLate = $tmp['opened'];
435  if ($outstandingOpened != $outstandingOpenedLate && !empty($outstandingOpenedLate)) {
436  $text = $langs->trans("CurrentOutstandingBillLate");
437  $link = DOL_URL_ROOT.'/fourn/recap-fourn.php?socid='.$object->id;
438  $icon = 'bill';
439  if ($link) $boxstat .= '<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
440  $boxstat .= '<div class="boxstats" title="'.dol_escape_htmltag($text).'">';
441  $boxstat .= '<span class="boxstatstext">'.img_object("", $icon).' <span>'.$text.'</span></span><br>';
442  $boxstat .= '<span class="boxstatsindicator'.($outstandingOpenedLate > 0 ? ' amountremaintopay' : '').'">'.price($outstandingOpenedLate, 1, $langs, 1, -1, -1, $conf->currency).$warn.'</span>';
443  $boxstat .= '</div>';
444  if ($link) $boxstat .= '</a>';
445  }
446  }
447 
448  $boxstat .= '</td></tr>';
449  $boxstat .= '</table>';
450  $boxstat .= '</div>';
451 
452  print $boxstat;
453 
454 
455  $MAXLIST = $conf->global->MAIN_SIZE_SHORTLIST_LIMIT;
456 
457  // Lien recap
458  /*
459  print '<table class="noborder centpercent">';
460  print '<tr class="liste_titre">';
461  print '<td colspan="4"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("Summary").'</td>';
462  print '<td class="right"><a class="notasortlink" href="'.DOL_URL_ROOT.'/fourn/recap-fourn.php?socid='.$object->id.'">'.$langs->trans("ShowSupplierPreview").'</a></td></tr></table></td>';
463  print '</tr>';
464  print '</table>';
465  print '<br>';
466  */
467 
468  /*
469  * List of products
470  */
471  if (!empty($conf->product->enabled) || !empty($conf->service->enabled))
472  {
473  $langs->load("products");
474  //Query from product/liste.php
475  $sql = 'SELECT p.rowid, p.ref, p.label, p.fk_product_type, p.entity,';
476  $sql .= ' pfp.tms, pfp.ref_fourn as supplier_ref, pfp.price, pfp.quantity, pfp.unitprice';
477  $sql .= ' FROM '.MAIN_DB_PREFIX.'product_fournisseur_price as pfp';
478  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = pfp.fk_product";
479  $sql .= ' WHERE p.entity IN ('.getEntity('product').')';
480  $sql .= ' AND pfp.fk_soc = '.$object->id;
481  $sql .= $db->order('pfp.tms', 'desc');
482  $sql .= $db->plimit($MAXLIST);
483 
484  $query = $db->query($sql);
485  if (!$query) dol_print_error($db);
486 
487  $num = $db->num_rows($query);
488 
489  print '<table class="noborder centpercent lastrecordtable">';
490  print '<tr class="liste_titre'.(($num == 0) ? ' nobottom' : '').'">';
491  print '<td colspan="3">'.$langs->trans("ProductsAndServices").'</td><td class="right">';
492  print '<a class="notasortlink" href="'.DOL_URL_ROOT.'/fourn/product/list.php?fourn_id='.$object->id.'">'.$langs->trans("AllProductReferencesOfSupplier").'<span class="badge marginleftonlyshort">'.$object->nbOfProductRefs().'</span>';
493  print '</a></td></tr>';
494 
495  $return = array();
496  if ($num > 0)
497  {
498  $productstatic = new Product($db);
499 
500  while ($objp = $db->fetch_object($query))
501  {
502  $productstatic->id = $objp->rowid;
503  $productstatic->ref = $objp->ref;
504  $productstatic->label = $objp->label;
505  $productstatic->type = $objp->fk_product_type;
506  $productstatic->entity = $objp->entity;
507 
508  print '<tr class="oddeven">';
509  print '<td class="nowrap">';
510  print $productstatic->getNomUrl(1);
511  print '</td>';
512  print '<td>';
513  print $objp->supplier_ref;
514  print '</td>';
515  print '<td class="maxwidthonsmartphone">';
516  print dol_trunc(dol_htmlentities($objp->label), 30);
517  print '</td>';
518  //print '<td class="right" class="nowrap">'.dol_print_date($objp->tms, 'day').'</td>';
519  print '<td class="right">';
520  //print (isset($objp->unitprice) ? price($objp->unitprice) : '');
521  if (isset($objp->price))
522  {
523  print price($objp->price);
524  if ($objp->quantity > 1)
525  {
526  print ' / ';
527  print $objp->quantity;
528  }
529  }
530  print '</td>';
531  print '</tr>';
532  }
533  }
534 
535  print '</table>';
536  }
537 
538 
539  /*
540  * Latest supplier proposal
541  */
542  $proposalstatic = new SupplierProposal($db);
543 
544  if ($user->rights->supplier_proposal->lire)
545  {
546  $langs->loadLangs(array("supplier_proposal"));
547 
548  $sql = "SELECT p.rowid, p.ref, p.date_valid as dc, p.fk_statut, p.total_ht, p.tva as total_tva, p.total as total_ttc";
549  $sql .= " FROM ".MAIN_DB_PREFIX."supplier_proposal as p ";
550  $sql .= " WHERE p.fk_soc =".$object->id;
551  $sql .= " AND p.entity IN (".getEntity('supplier_proposal').")";
552  $sql .= " ORDER BY p.date_valid DESC";
553  $sql .= " ".$db->plimit($MAXLIST);
554 
555  $resql = $db->query($sql);
556  if ($resql)
557  {
558  $i = 0;
559  $num = $db->num_rows($resql);
560 
561  if ($num > 0)
562  {
563  print '<table class="noborder centpercent lastrecordtable">';
564 
565  print '<tr class="liste_titre">';
566  print '<td colspan="3">';
567  print '<table class="nobordernopadding centpercent"><tr><td>'.$langs->trans("LastSupplierProposals", ($num < $MAXLIST ? "" : $MAXLIST)).'</td>';
568  print '<td class="right"><a class="notasortlink" href="'.DOL_URL_ROOT.'/supplier_proposal/list.php?socid='.$object->id.'">'.$langs->trans("AllPriceRequests").'<span class="badge marginleftonlyshort">'.$num.'</span></td>';
569  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>';
570  print '</tr></table>';
571  print '</td></tr>';
572  }
573 
574  while ($i < $num && $i <= $MAXLIST)
575  {
576  $obj = $db->fetch_object($resql);
577 
578  print '<tr class="oddeven">';
579  print '<td class="nowrap">';
580  $proposalstatic->id = $obj->rowid;
581  $proposalstatic->ref = $obj->ref;
582  $proposalstatic->total_ht = $obj->total_ht;
583  $proposalstatic->total_tva = $obj->total_tva;
584  $proposalstatic->total_ttc = $obj->total_ttc;
585  print $proposalstatic->getNomUrl(1);
586  print '</td>';
587  print '<td class="center" width="80">';
588  if ($obj->dc)
589  {
590  print dol_print_date($db->jdate($obj->dc), 'day');
591  } else {
592  print "-";
593  }
594  print '</td>';
595  print '<td class="right" class="nowrap">'.$proposalstatic->LibStatut($obj->fk_statut, 5).'</td>';
596  print '</tr>';
597  $i++;
598  }
599  $db->free($resql);
600 
601  if ($num > 0) print "</table>";
602  } else {
603  dol_print_error($db);
604  }
605  }
606 
607  /*
608  * Latest supplier orders
609  */
610  $orderstatic = new CommandeFournisseur($db);
611 
612  if ($user->rights->fournisseur->commande->lire)
613  {
614  // TODO move to DAO class
615  // Check if there are supplier orders billable
616  $sql2 = 'SELECT s.nom, s.rowid as socid, s.client, c.rowid, c.ref, c.total_ht, c.ref_supplier,';
617  $sql2 .= ' c.date_valid, c.date_commande, c.date_livraison, c.fk_statut';
618  $sql2 .= ' FROM '.MAIN_DB_PREFIX.'societe as s';
619  $sql2 .= ', '.MAIN_DB_PREFIX.'commande_fournisseur as c';
620  $sql2 .= ' WHERE c.fk_soc = s.rowid';
621  $sql2 .= " AND c.entity IN (".getEntity('commande_fournisseur').")";
622  $sql2 .= ' AND s.rowid = '.$object->id;
623  // Show orders we can bill
624  if (empty($conf->global->SUPPLIER_ORDER_TO_INVOICE_STATUS))
625  {
626  $sql2 .= " AND c.fk_statut IN (".$db->sanitize(CommandeFournisseur::STATUS_RECEIVED_COMPLETELY).")"; // Must match filter in htdocs/fourn/commande/list.php
627  } else {
628  // CommandeFournisseur::STATUS_ORDERSENT.", ".CommandeFournisseur::STATUS_RECEIVED_PARTIALLY.", ".CommandeFournisseur::STATUS_RECEIVED_COMPLETELY
629  $sql2 .= " AND c.fk_statut IN (".$db->sanitize($db->escape($conf->global->SUPPLIER_ORDER_TO_INVOICE_STATUS)).")";
630  }
631  $sql2 .= " AND c.billed = 0";
632  // Find order that are not already invoiced
633  // just need to check received status because we have the billed status now
634  //$sql2 .= " AND c.rowid NOT IN (SELECT fk_source FROM " . MAIN_DB_PREFIX . "element_element WHERE targettype='invoice_supplier')";
635  $resql2 = $db->query($sql2);
636  if ($resql2) {
637  $orders2invoice = $db->num_rows($resql2);
638  $db->free($resql2);
639  } else {
640  setEventMessages($db->lasterror(), null, 'errors');
641  }
642 
643  // TODO move to DAO class
644  $sql = "SELECT count(p.rowid) as total";
645  $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as p";
646  $sql .= " WHERE p.fk_soc =".$object->id;
647  $sql .= " AND p.entity IN (".getEntity('commande_fournisseur').")";
648  $resql = $db->query($sql);
649  if ($resql)
650  {
651  $object_count = $db->fetch_object($resql);
652  $num = $object_count->total;
653  }
654 
655  $sql = "SELECT p.rowid,p.ref, p.date_commande as dc, p.fk_statut, p.total_ht, p.tva as total_tva, p.total_ttc";
656  $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as p";
657  $sql .= " WHERE p.fk_soc =".$object->id;
658  $sql .= " AND p.entity IN (".getEntity('commande_fournisseur').")";
659  $sql .= " ORDER BY p.date_commande DESC";
660  $sql .= " ".$db->plimit($MAXLIST);
661  $resql = $db->query($sql);
662  if ($resql)
663  {
664  $i = 0;
665 
666  if ($num > 0)
667  {
668  print '<table class="noborder centpercent lastrecordtable">';
669 
670  print '<tr class="liste_titre">';
671  print '<td colspan="3">';
672  print '<table class="nobordernopadding" width="100%"><tr><td>'.$langs->trans("LastSupplierOrders", ($num < $MAXLIST ? "" : $MAXLIST)).'</td>';
673  print '<td class="right"><a class="notasortlink" href="'.DOL_URL_ROOT.'/fourn/commande/list.php?socid='.$object->id.'">'.$langs->trans("AllOrders").'<span class="badge marginleftonlyshort">'.$num.'</span></td>';
674  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>';
675  print '</tr></table>';
676  print '</td></tr>';
677  }
678 
679  while ($i < $num && $i < $MAXLIST)
680  {
681  $obj = $db->fetch_object($resql);
682 
683  print '<tr class="oddeven">';
684  print '<td class="nowrap">';
685  $orderstatic->id = $obj->rowid;
686  $orderstatic->ref = $obj->ref;
687  $orderstatic->total_ht = $obj->total_ht;
688  $orderstatic->total_tva = $obj->total_tva;
689  $orderstatic->total_ttc = $obj->total_ttc;
690  print $orderstatic->getNomUrl(1);
691  print '</td>';
692  print '<td class="center" width="80">';
693  if ($obj->dc)
694  {
695  print dol_print_date($db->jdate($obj->dc), 'day');
696  } else {
697  print "-";
698  }
699  print '</td>';
700  print '<td class="right" class="nowrap">'.$orderstatic->LibStatut($obj->fk_statut, 5).'</td>';
701  print '</tr>';
702  $i++;
703  }
704  $db->free($resql);
705 
706  if ($num > 0) print "</table>";
707  } else {
708  dol_print_error($db);
709  }
710  }
711 
712  /*
713  * Latest supplier invoices
714  */
715 
716  $langs->load('bills');
717  $facturestatic = new FactureFournisseur($db);
718 
719  if ($user->rights->fournisseur->facture->lire)
720  {
721  // TODO move to DAO class
722  $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 as amount,f.paye,';
723  $sql .= ' SUM(pf.amount) as am';
724  $sql .= ' FROM '.MAIN_DB_PREFIX.'facture_fourn as f';
725  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON f.rowid=pf.fk_facturefourn';
726  $sql .= ' WHERE f.fk_soc = '.$object->id;
727  $sql .= " AND f.entity IN (".getEntity('facture_fourn').")";
728  $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';
729  $sql .= ' ORDER BY f.datef DESC';
730  $resql = $db->query($sql);
731  if ($resql)
732  {
733  $i = 0;
734  $num = $db->num_rows($resql);
735  if ($num > 0)
736  {
737  print '<table class="noborder centpercent lastrecordtable">';
738 
739  print '<tr class="liste_titre">';
740  print '<td colspan="4">';
741  print '<table class="nobordernopadding" width="100%"><tr><td>'.$langs->trans('LastSuppliersBills', ($num <= $MAXLIST ? "" : $MAXLIST)).'</td><td class="right"><a class="notasortlink" href="'.DOL_URL_ROOT.'/fourn/facture/list.php?socid='.$object->id.'">'.$langs->trans('AllBills').'<span class="badge marginleftonlyshort">'.$num.'</span></td>';
742  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>';
743  print '</tr></table>';
744  print '</td></tr>';
745  }
746 
747  while ($i < min($num, $MAXLIST))
748  {
749  $obj = $db->fetch_object($resql);
750 
751  print '<tr class="oddeven">';
752  print '<td>';
753  print '<a href="facture/card.php?facid='.$obj->rowid.'">';
754  $facturestatic->id = $obj->rowid;
755  $facturestatic->ref = ($obj->ref ? $obj->ref : $obj->rowid);
756  $facturestatic->ref_supplier = $obj->ref_supplier;
757  $facturestatic->libelle = $obj->label; // deprecated
758  $facturestatic->label = $obj->label;
759  $facturestatic->total_ht = $obj->total_ht;
760  $facturestatic->total_tva = $obj->total_tva;
761  $facturestatic->total_ttc = $obj->total_ttc;
762  print $facturestatic->getNomUrl(1);
763  print $obj->ref_supplier ? ' - '.$obj->ref_supplier : '';
764  print ($obj->label ? ' - ' : '').dol_trunc($obj->label, 14);
765  print '</td>';
766  print '<td class="center nowrap">'.dol_print_date($db->jdate($obj->df), 'day').'</td>';
767  print '<td class="right nowrap">'.price($obj->amount).'</td>';
768  print '<td class="right nowrap">';
769  print $facturestatic->LibStatut($obj->paye, $obj->fk_statut, 5, $obj->am);
770  print '</td>';
771  print '</tr>';
772  $i++;
773  }
774  $db->free($resql);
775  if ($num > 0) print '</table>';
776  } else {
777  dol_print_error($db);
778  }
779  }
780 
781  print '</div></div></div>';
782  print '<div style="clear:both"></div>';
783 
784  print dol_get_fiche_end();
785 
786 
787  /*
788  * Barre d'actions
789  */
790  print '<div class="tabsAction">';
791 
792  $parameters = array();
793  $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
794  // modified by hook
795  if (empty($reshook))
796  {
797  if ($object->status != 1)
798  {
799  print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" title="'.dol_escape_js($langs->trans("ThirdPartyIsClosed")).'" href="#">'.$langs->trans("ThirdPartyIsClosed").'</a></div>';
800  }
801 
802  if ($conf->supplier_proposal->enabled && $user->rights->supplier_proposal->creer)
803  {
804  $langs->load("supplier_proposal");
805  if ($object->status == 1) {
806  print '<a class="butAction" href="'.DOL_URL_ROOT.'/supplier_proposal/card.php?action=create&socid='.$object->id.'">'.$langs->trans("AddSupplierProposal").'</a>';
807  } else {
808  print '<a class="butActionRefused classfortooltip" title="'.dol_escape_js($langs->trans("ThirdPartyIsClosed")).'" href="#">'.$langs->trans("AddSupplierProposal").'</a>';
809  }
810  }
811 
812  if ($user->rights->fournisseur->commande->creer)
813  {
814  $langs->load("orders");
815  if ($object->status == 1) {
816  print '<a class="butAction" href="'.DOL_URL_ROOT.'/fourn/commande/card.php?action=create&socid='.$object->id.'">'.$langs->trans("AddOrder").'</a>';
817  } else {
818  print '<a class="butActionRefused classfortooltip" title="'.dol_escape_js($langs->trans("ThirdPartyIsClosed")).'" href="#">'.$langs->trans("AddOrder").'</a>';
819  }
820  }
821 
822  if ($user->rights->fournisseur->facture->creer)
823  {
824  if (!empty($orders2invoice) && $orders2invoice > 0)
825  {
826  if ($object->status == 1) {
827  // Company is open
828  print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/fourn/commande/list.php?socid='.$object->id.'&search_billed=0&autoselectall=1">'.$langs->trans("CreateInvoiceForThisSupplier").'</a></div>';
829  } else {
830  print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#">'.$langs->trans("CreateInvoiceForThisCustomer").'</a></div>';
831  }
832  } else print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" title="'.dol_escape_js($langs->trans("NoOrdersToInvoice").' ('.$langs->trans("WithReceptionFinished").')').'" href="#">'.$langs->trans("CreateInvoiceForThisCustomer").'</a></div>';
833  }
834 
835  if ($user->rights->fournisseur->facture->creer)
836  {
837  $langs->load("bills");
838  if ($object->status == 1) {
839  print '<a class="butAction" href="'.DOL_URL_ROOT.'/fourn/facture/card.php?action=create&socid='.$object->id.'">'.$langs->trans("AddBill").'</a>';
840  } else {
841  print '<a class="butActionRefused classfortooltip" title="'.dol_escape_js($langs->trans("ThirdPartyIsClosed")).'" href="#">'.$langs->trans("AddBill").'</a>';
842  }
843  }
844 
845  // Add action
846  if (!empty($conf->agenda->enabled) && !empty($conf->global->MAIN_REPEATTASKONEACHTAB) && $object->status == 1)
847  {
848  if ($user->rights->agenda->myactions->create)
849  {
850  print '<a class="butAction" href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create&socid='.$object->id.'">'.$langs->trans("AddAction").'</a>';
851  } else {
852  print '<a class="butAction" title="'.dol_escape_js($langs->trans("NotAllowed")).'" href="#">'.$langs->trans("AddAction").'</a>';
853  }
854  }
855  }
856 
857  print '</div>';
858 
859 
860  if (!empty($conf->global->MAIN_DUPLICATE_CONTACTS_TAB_ON_MAIN_CARD))
861  {
862  print '<br>';
863  // List of contacts
864  show_contacts($conf, $langs, $db, $object, $_SERVER["PHP_SELF"].'?socid='.$object->id);
865  }
866 
867  if (!empty($conf->global->MAIN_REPEATTASKONEACHTAB))
868  {
869  print load_fiche_titre($langs->trans("ActionsOnCompany"), '', '');
870 
871  // List of todo actions
872  show_actions_todo($conf, $langs, $db, $object);
873 
874  // List of done actions
875  show_actions_done($conf, $langs, $db, $object);
876  }
877 } else {
878  dol_print_error($db);
879 }
880 
881 // End of page
882 llxFooter();
883 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
img_edit($titlealt= 'default', $float=0, $other= '')
Show logo editer/modifier fiche.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
const STATUS_RECEIVED_COMPLETELY
Received completely.
Class to manage contact/addresses.
Class to manage products or services.
dol_htmlentities($string, $flags=null, $encoding= 'UTF-8', $double_encode=false)
Replace htmlentities functions.
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for properties) With native = 0: P...
show_actions_done($conf, $langs, $db, $filterobj, $objcon= '', $noprint=0, $actioncode= '', $donetodo= 'done', $filters=array(), $sortfield= 'a.datep, a.id', $sortorder= 'DESC', $module= '')
Show html area with actions (done or not, ignore the name of function).
show_contacts($conf, $langs, $db, $object, $backtopage= '')
Show html area for list of contacts.
Class to manage suppliers invoices.
Class to manage suppliers.
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...
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to manage standard extra fields.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
Class to manage members of a foundation.
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
societe_prepare_head(Societe $object)
Return array of tabs to used on pages for third parties cards.
Definition: company.lib.php:42
Class to manage predefined suppliers products.
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Class to manage price ask supplier.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_trunc($string, $size=40, $trunc= 'right', $stringencoding= 'UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding &#39;...&#39; if string larger than length.
dol_banner_tab($object, $paramid, $morehtml= '', $shownav=1, $fieldid= 'rowid', $fieldref= 'ref', $morehtmlref= '', $moreparam= '', $nodbprefix=0, $morehtmlleft= '', $morehtmlstatus= '', $onlybanner=0, $morehtmlright= '')
Show tab footer of a card.
llxFooter()
Empty footer.
Definition: wrapper.php:59
show_actions_todo($conf, $langs, $db, $filterobj, $objcon= '', $noprint=0, $actioncode= '')
Show html area with actions to do.