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