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