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) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
5  * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
6  * Copyright (C) 2005-2017 Regis Houssin <regis.houssin@capnetworks.com>
7  * Copyright (C) 2008 Raphael Bertrand (Resultic) <raphael.bertrand@resultic.fr>
8  * Copyright (C) 2010-2014 Juanjo Menent <jmenent@2byte.es>
9  * Copyright (C) 2013 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
10  * Copyright (C) 2015 Frederic France <frederic.france@free.fr>
11  * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program. If not, see <http://www.gnu.org/licenses/>.
24  */
25 
32 require '../main.inc.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
35 require_once DOL_DOCUMENT_ROOT.'/societe/class/client.class.php';
36 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
38 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
39 if (! empty($conf->facture->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
40 if (! empty($conf->facture->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture-rec.class.php';
41 if (! empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
42 if (! empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
43 if (! empty($conf->expedition->enabled)) require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
44 if (! empty($conf->contrat->enabled)) require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
45 if (! empty($conf->adherent->enabled)) require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
46 if (! empty($conf->ficheinter->enabled)) require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
47 
48 $langs->load("companies");
49 $langs->load('banks');
50 
51 if (! empty($conf->contrat->enabled)) $langs->load("contracts");
52 if (! empty($conf->commande->enabled)) $langs->load("orders");
53 if (! empty($conf->expedition->enabled)) $langs->load("sendings");
54 if (! empty($conf->facture->enabled)) $langs->load("bills");
55 if (! empty($conf->projet->enabled)) $langs->load("projects");
56 if (! empty($conf->ficheinter->enabled)) $langs->load("interventions");
57 if (! empty($conf->notification->enabled)) $langs->load("mails");
58 
59 // Security check
60 $id = (GETPOST('socid','int') ? GETPOST('socid','int') : GETPOST('id','int'));
61 if ($user->societe_id > 0) $id=$user->societe_id;
62 $result = restrictedArea($user,'societe',$id,'&societe');
63 
64 $action = GETPOST('action','aZ09');
65 $mode = GETPOST("mode");
66 
67 $sortfield = GETPOST("sortfield",'alpha');
68 $sortorder = GETPOST("sortorder",'alpha');
69 $page = GETPOST("page",'int');
70 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
71 $offset = $conf->liste_limit * $page;
72 $pageprev = $page - 1;
73 $pagenext = $page + 1;
74 if (! $sortorder) $sortorder="ASC";
75 if (! $sortfield) $sortfield="nom";
76 $cancelbutton = GETPOST('cancel','alpha');
77 
78 $object = new Client($db);
79 $extrafields = new ExtraFields($db);
80 
81 // fetch optionals attributes and labels
82 $extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
83 
84 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
85 $hookmanager->initHooks(array('commcard','globalcard'));
86 
87 
88 /*
89  * Actions
90  */
91 
92 $parameters = array('id' => $id, 'socid' => $id);
93 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some
94 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
95 
96 if (empty($reshook))
97 {
98  if ($cancelbutton)
99  {
100  $action="";
101  }
102 
103  // set accountancy code
104  if ($action == 'setcustomeraccountancycode')
105  {
106  $result=$object->fetch($id);
107  $object->code_compta=$_POST["customeraccountancycode"];
108  $result=$object->update($object->id,$user,1,1,0);
109  if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
110  }
111 
112  // conditions de reglement
113  if ($action == 'setconditions' && $user->rights->societe->creer)
114  {
115  $object->fetch($id);
116  $result=$object->setPaymentTerms(GETPOST('cond_reglement_id','int'));
117  if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
118  }
119 
120  // mode de reglement
121  if ($action == 'setmode' && $user->rights->societe->creer)
122  {
123  $object->fetch($id);
124  $result=$object->setPaymentMethods(GETPOST('mode_reglement_id','int'));
125  if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
126  }
127 
128  // Bank account
129  if ($action == 'setbankaccount' && $user->rights->societe->creer)
130  {
131  $object->fetch($id);
132  $result=$object->setBankAccount(GETPOST('fk_account','int'));
133  if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
134  }
135 
136  // customer preferred shipping method
137  if ($action == 'setshippingmethod' && $user->rights->societe->creer)
138  {
139  $object->fetch($id);
140  $result = $object->setShippingMethod(GETPOST('shipping_method_id','int'));
141  if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
142  }
143 
144  // assujetissement a la TVA
145  if ($action == 'setassujtva' && $user->rights->societe->creer)
146  {
147  $object->fetch($id);
148  $object->tva_assuj=$_POST['assujtva_value'];
149  $result=$object->update($object->id);
150  if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
151  }
152 
153  // set prospect level
154  if ($action == 'setprospectlevel' && $user->rights->societe->creer)
155  {
156  $object->fetch($id);
157  $object->fk_prospectlevel=GETPOST('prospect_level_id','alpha');
158  $result=$object->update($object->id, $user);
159  if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
160  }
161 
162  // set communication status
163  if ($action == 'setstcomm')
164  {
165  $object->fetch($id);
166  $object->stcomm_id=dol_getIdFromCode($db, GETPOST('stcomm','alpha'), 'c_stcomm');
167  $result=$object->update($object->id, $user);
168  if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
169  }
170 
171  // update outstandng limit
172  if ($action == 'setoutstanding_limit')
173  {
174  $object->fetch($id);
175  $object->outstanding_limit=GETPOST('outstanding_limit');
176  $result=$object->update($object->id, $user);
177  if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
178  }
179 
180  if ($action == 'update_extras') {
181  $object->fetch($id);
182 
183  // Fill array 'array_options' with data from update form
184  $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
185  $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute'));
186  if ($ret < 0) $error++;
187  if (! $error)
188  {
189  $result = $object->insertExtraFields();
190  if ($result < 0)
191  {
192  setEventMessages($object->error, $object->errors, 'errors');
193  $error++;
194  }
195  }
196  if ($error) $action = 'edit_extras';
197  }
198 }
199 
200 
201 /*
202  * View
203  */
204 
205 $contactstatic = new Contact($db);
206 $userstatic=new User($db);
207 $form = new Form($db);
208 $formcompany=new FormCompany($db);
209 
210 if ($id > 0 && empty($object->id))
211 {
212  // Load data of third party
213  $res=$object->fetch($id);
214  if ($object->id <= 0) dol_print_error($db,$object->error,$object->errors);
215 }
216 
217 $title=$langs->trans("CustomerCard");
218 if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name;
219 $help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
220 llxHeader('',$title,$help_url);
221 
222 
223 if ($id > 0)
224 {
225  $head = societe_prepare_head($object);
226 
227  dol_fiche_head($head, 'customer', $langs->trans("ThirdParty"), -1, 'company');
228 
229  $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php">'.$langs->trans("BackToList").'</a>';
230 
231  dol_banner_tab($object, 'socid', $linkback, ($user->societe_id?0:1), 'rowid', 'nom');
232 
233  print '<div class="fichecenter"><div class="fichehalfleft">';
234 
235  print '<div class="underbanner clearboth"></div>';
236  print '<table class="border" width="100%">';
237 
238  // Prospect/Customer
239  print '<tr><td class="titlefield">'.$langs->trans('ProspectCustomer').'</td><td>';
240  print $object->getLibCustProspStatut();
241  print '</td></tr>';
242 
243  // Prefix
244  if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field
245  {
246  print '<tr><td>'.$langs->trans("Prefix").'</td><td>';
247  print ($object->prefix_comm?$object->prefix_comm:'&nbsp;');
248  print '</td></tr>';
249  }
250 
251  if ($object->client)
252  {
253  $langs->load("compta");
254 
255  print '<tr><td>';
256  print $langs->trans('CustomerCode').'</td><td>';
257  print $object->code_client;
258  if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
259  print '</td></tr>';
260 
261  print '<tr>';
262  print '<td>';
263  print $form->editfieldkey("CustomerAccountancyCode",'customeraccountancycode',$object->code_compta,$object,$user->rights->societe->creer);
264  print '</td><td>';
265  print $form->editfieldval("CustomerAccountancyCode",'customeraccountancycode',$object->code_compta,$object,$user->rights->societe->creer);
266  print '</td>';
267  print '</tr>';
268  }
269 
270  // VAT is used
271  print '<tr>';
272  print '<td class="nowrap">'.$langs->trans('VATIsUsed').'</td>';
273  print '<td>';
274  print yn($object->tva_assuj);
275  print '</td>';
276  print '</tr>';
277 
278  // Local Taxes
279  // TODO Move this on same record than VATIsUsed
280  if ($mysoc->localtax1_assuj=="1")
281  {
282  print '<tr><td class="nowrap">'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).'</td><td>';
283  print yn($object->localtax1_assuj);
284  print '</td></tr>';
285  }
286  if ($mysoc->localtax1_assuj=="1")
287  {
288  print '<tr><td class="nowrap">'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).'</td><td>';
289  print yn($object->localtax2_assuj);
290  print '</td></tr>';
291  }
292 
293 
294  // TVA Intra
295  print '<tr><td class="nowrap">'.$langs->trans('VATIntra').'</td><td>';
296  print $object->tva_intra;
297  print '</td></tr>';
298 
299  // Conditions de reglement par defaut
300  $langs->load('bills');
301  print '<tr><td>';
302  print '<table width="100%" class="nobordernopadding"><tr><td>';
303  print $langs->trans('PaymentConditions');
304  print '<td>';
305  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>';
306  print '</tr></table>';
307  print '</td><td>';
308  if ($action == 'editconditions')
309  {
310  $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->cond_reglement_id, 'cond_reglement_id',1);
311  }
312  else
313  {
314  $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->cond_reglement_id, 'none');
315  }
316  print "</td>";
317  print '</tr>';
318 
319  // Mode de reglement par defaut
320  print '<tr><td class="nowrap">';
321  print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
322  print $langs->trans('PaymentMode');
323  print '<td>';
324  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>';
325  print '</tr></table>';
326  print '</td><td>';
327  if ($action == 'editmode')
328  {
329  $form->form_modes_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->mode_reglement_id,'mode_reglement_id');
330  }
331  else
332  {
333  $form->form_modes_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->mode_reglement_id,'none');
334  }
335  print "</td>";
336  print '</tr>';
337 
338  if (! empty($conf->banque->enabled))
339  {
340  // Compte bancaire par défaut
341  print '<tr><td class="nowrap">';
342  print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
343  print $langs->trans('PaymentBankAccount');
344  print '<td>';
345  if (($action != 'editbankaccount') && $user->rights->societe->creer) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editbankaccount&amp;socid='.$object->id.'">'.img_edit($langs->trans('SetBankAccount'),1).'</a></td>';
346  print '</tr></table>';
347  print '</td><td>';
348  if ($action == 'editbankaccount')
349  {
350  $form->formSelectAccount($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->fk_account,'fk_account',1);
351  }
352  else
353  {
354  $form->formSelectAccount($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->fk_account,'none');
355  }
356  print "</td>";
357  print '</tr>';
358  }
359 
360  // Relative discounts (Discounts-Drawbacks-Rebates)
361  print '<tr><td class="nowrap">';
362  print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
363  print $langs->trans("CustomerRelativeDiscountShort");
364  print '<td><td align="right">';
365  if ($user->rights->societe->creer && !$user->societe_id > 0)
366  {
367  print '<a href="'.DOL_URL_ROOT.'/comm/remise.php?id='.$object->id.'">'.img_edit($langs->trans("Modify")).'</a>';
368  }
369  print '</td></tr></table>';
370  print '</td><td>'.($object->remise_percent?'<a href="'.DOL_URL_ROOT.'/comm/remise.php?id='.$object->id.'">'.$object->remise_percent.'%</a>':'').'</td>';
371  print '</tr>';
372 
373  // Absolute discounts (Discounts-Drawbacks-Rebates)
374  print '<tr><td class="nowrap">';
375  print '<table width="100%" class="nobordernopadding">';
376  print '<tr><td class="nowrap">';
377  print $langs->trans("CustomerAbsoluteDiscountShort");
378  print '<td><td align="right">';
379  if ($user->rights->societe->creer && !$user->societe_id > 0)
380  {
381  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>';
382  }
383  print '</td></tr></table>';
384  print '</td>';
385  print '<td>';
386  $amount_discount=$object->getAvailableDiscounts();
387  if ($amount_discount < 0) dol_print_error($db,$object->error);
388  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>';
389  //else print $langs->trans("DiscountNone");
390  print '</td>';
391  print '</tr>';
392 
393  // Max outstanding bill
394  if ($object->client)
395  {
396  print '<tr class="nowrap">';
397  print '<td>';
398  print $form->editfieldkey("OutstandingBill",'outstanding_limit',$object->outstanding_limit,$object,$user->rights->societe->creer);
399  print '</td><td>';
400  $limit_field_type = (! empty($conf->global->MAIN_USE_JQUERY_JEDITABLE)) ? 'numeric' : 'amount';
401  print $form->editfieldval("OutstandingBill",'outstanding_limit',$object->outstanding_limit,$object,$user->rights->societe->creer,$limit_field_type,($object->outstanding_limit != '' ? price($object->outstanding_limit) : ''));
402  //if (empty($object->outstanding_limit)) print $langs->trans("NoLimit");
403 
404  print '</td>';
405  print '</tr>';
406  }
407 
408  // Multiprice level
409  if (! empty($conf->global->PRODUIT_MULTIPRICES))
410  {
411  print '<tr><td class="nowrap">';
412  print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
413  print $langs->trans("PriceLevel");
414  print '<td><td align="right">';
415  if ($user->rights->societe->creer)
416  {
417  print '<a href="'.DOL_URL_ROOT.'/comm/multiprix.php?id='.$object->id.'">'.img_edit($langs->trans("Modify")).'</a>';
418  }
419  print '</td></tr></table>';
420  print '</td><td>';
421  print $object->price_level;
422  $keyforlabel='PRODUIT_MULTIPRICES_LABEL'.$object->price_level;
423  if (! empty($conf->global->$keyforlabel)) print ' - '.$langs->trans($conf->global->$keyforlabel);
424  print "</td>";
425  print '</tr>';
426  }
427 
428  // Preferred shipping Method
429  if (! empty($conf->global->SOCIETE_ASK_FOR_SHIPPING_METHOD)) {
430  print '<tr><td class="nowrap">';
431  print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
432  print $langs->trans('SendingMethod');
433  print '<td>';
434  if (($action != 'editshipping') && $user->rights->societe->creer) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editshipping&amp;socid='.$object->id.'">'.img_edit($langs->trans('SetMode'),1).'</a></td>';
435  print '</tr></table>';
436  print '</td><td>';
437  if ($action == 'editshipping')
438  {
439  $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->shipping_method_id,'shipping_method_id');
440  }
441  else
442  {
443  $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->shipping_method_id,'none');
444  }
445  print "</td>";
446  print '</tr>';
447  }
448 
449  // Categories
450  if (!empty($conf->categorie->enabled) && !empty($user->rights->categorie->lire)) {
451  $langs->load("categories");
452  print '<tr><td>' . $langs->trans("CustomersCategoriesShort") . '</td>';
453  print '<td>';
454  print $form->showCategories( $object->id, 'customer', 1 );
455  print "</td></tr>";
456  }
457 
458  // Other attributes
459  $parameters=array('socid'=>$object->id);
460  include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
461 
462  // Sales representative
463  include DOL_DOCUMENT_ROOT.'/societe/tpl/linesalesrepresentative.tpl.php';
464 
465  // Module Adherent
466  if (! empty($conf->adherent->enabled))
467  {
468  $langs->load("members");
469  $langs->load("users");
470 
471  print '<tr><td class="titlefield">'.$langs->trans("LinkedToDolibarrMember").'</td>';
472  print '<td>';
473  $adh=new Adherent($db);
474  $result=$adh->fetch('','',$object->id);
475  if ($result > 0)
476  {
477  $adh->ref=$adh->getFullName($langs);
478  print $adh->getNomUrl(1);
479  }
480  else
481  {
482  print '<span class="opacitymedium">'.$langs->trans("ThirdpartyNotLinkedToMember").'</span>';
483  }
484  print '</td>';
485  print "</tr>\n";
486  }
487 
488  print "</table>";
489 
490  if ($object->client == 2 || $object->client == 3)
491  {
492  print '<br>';
493 
494  print '<div class="underbanner clearboth"></div>';
495  print '<table class="border" width="100%">';
496 
497  // Level of prospect
498  print '<tr><td class="titlefield nowrap">';
499  print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
500  print $langs->trans('ProspectLevel');
501  print '<td>';
502  if ($action != 'editlevel' && $user->rights->societe->creer) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editlevel&amp;socid='.$object->id.'">'.img_edit($langs->trans('Modify'),1).'</a></td>';
503  print '</tr></table>';
504  print '</td><td>';
505  if ($action == 'editlevel')
506  {
507  $formcompany->form_prospect_level($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->fk_prospectlevel,'prospect_level_id',1);
508  }
509  else
510  {
511  print $object->getLibProspLevel();
512  }
513  print "</td>";
514  print '</tr>';
515 
516  // Status
517  $object->loadCacheOfProspStatus();
518  print '<tr><td>'.$langs->trans("StatusProsp").'</td><td>'.$object->getLibProspCommStatut(4, $object->cacheprospectstatus[$object->stcomm_id]['label']);
519  print ' &nbsp; &nbsp; ';
520  print '<div class="floatright">';
521  foreach($object->cacheprospectstatus as $key => $val)
522  {
523  $titlealt='default';
524  if (! empty($val['code']) && ! in_array($val['code'], array('ST_NO', 'ST_NEVER', 'ST_TODO', 'ST_PEND', 'ST_DONE'))) $titlealt=$val['label'];
525  if ($object->stcomm_id != $val['id']) print '<a class="pictosubstatus" href="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'&stcomm='.$val['code'].'&action=setstcomm">'.img_action($titlealt,$val['code']).'</a>';
526  }
527  print '</div></td></tr>';
528  print "</table>";
529  }
530 
531  print '</div><div class="fichehalfright"><div class="ficheaddleft">';
532 
533 
534  $boxstat = '';
535 
536  // Nbre max d'elements des petites listes
537  $MAXLIST=$conf->global->MAIN_SIZE_SHORTLIST_LIMIT;
538 
539  // Lien recap
540  $boxstat.='<div class="box">';
541  $boxstat.='<table summary="'.dol_escape_htmltag($langs->trans("DolibarrStateBoard")).'" class="noborder boxtable boxtablenobottom" width="100%">';
542  $boxstat.='<tr class="impair"><td colspan="2" class="tdboxstats nohover">';
543 
544  if (! empty($conf->propal->enabled))
545  {
546  // Box proposals
547  $tmp = $object->getOutstandingProposals();
548  $outstandingOpened=$tmp['opened'];
549  $outstandingTotal=$tmp['total_ht'];
550  $outstandingTotalIncTax=$tmp['total_ttc'];
551  $text=$langs->trans("OverAllProposals");
552  $link='';
553  $icon='bill';
554  if ($link) $boxstat.='<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
555  $boxstat.='<div class="boxstats">';
556  $boxstat.='<span class="boxstatstext">'.img_object("",$icon).' '.$text.'</span><br>';
557  $boxstat.='<span class="boxstatsindicator">'.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
558  $boxstat.='</div>';
559  if ($link) $boxstat.='</a>';
560  }
561 
562  if (! empty($conf->commande->enabled))
563  {
564  // Box proposals
565  $tmp = $object->getOutstandingOrders();
566  $outstandingOpened=$tmp['opened'];
567  $outstandingTotal=$tmp['total_ht'];
568  $outstandingTotalIncTax=$tmp['total_ttc'];
569  $text=$langs->trans("OverAllOrders");
570  $link='';
571  $icon='bill';
572  if ($link) $boxstat.='<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
573  $boxstat.='<div class="boxstats">';
574  $boxstat.='<span class="boxstatstext">'.img_object("",$icon).' '.$text.'</span><br>';
575  $boxstat.='<span class="boxstatsindicator">'.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
576  $boxstat.='</div>';
577  if ($link) $boxstat.='</a>';
578  }
579 
580  if (! empty($conf->facture->enabled))
581  {
582  $tmp = $object->getOutstandingBills();
583  $outstandingOpened=$tmp['opened'];
584  $outstandingTotal=$tmp['total_ht'];
585  $outstandingTotalIncTax=$tmp['total_ttc'];
586  $text=$langs->trans("OverAllInvoices");
587  $link='';
588  $icon='bill';
589  if ($link) $boxstat.='<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
590  $boxstat.='<div class="boxstats">';
591  $boxstat.='<span class="boxstatstext">'.img_object("",$icon).' '.$text.'</span><br>';
592  $boxstat.='<span class="boxstatsindicator">'.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
593  $boxstat.='</div>';
594  if ($link) $boxstat.='</a>';
595 
596  // Box outstanding bill
597  $warn = '';
598  if ($object->outstanding_limit != '' && $object->outstanding_limit < $outstandingOpened)
599  {
600  $warn = ' '.img_warning($langs->trans("OutstandingBillReached"));
601  }
602  $text=$langs->trans("CurrentOutstandingBill");
603  $link=DOL_URL_ROOT.'/compta/recap-compta.php?socid='.$object->id;
604  $icon='bill';
605  if ($link) $boxstat.='<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
606  $boxstat.='<div class="boxstats">';
607  $boxstat.='<span class="boxstatstext">'.img_object("",$icon).' '.$text.'</span><br>';
608  $boxstat.='<span class="boxstatsindicator'.($outstandingOpened>0?' amountremaintopay':'').'">'.price($outstandingOpened, 1, $langs, 1, -1, -1, $conf->currency).$warn.'</span>';
609  $boxstat.='</div>';
610  if ($link) $boxstat.='</a>';
611  }
612 
613  $parameters = array();
614  $reshook = $hookmanager->executeHooks('addMoreBoxStatsCustomer', $parameters, $object, $action);
615  if(empty($reshook)){
616  $boxstat.= $hookmanager->resPrint;
617  }
618 
619  $boxstat.='</td></tr>';
620  $boxstat.='</table>';
621  $boxstat.='</div>';
622 
623  print $boxstat;
624 
625  $now=dol_now();
626 
627  /*
628  * Last proposals
629  */
630  if (! empty($conf->propal->enabled) && $user->rights->propal->lire)
631  {
632  $propal_static = new Propal($db);
633 
634  $sql = "SELECT s.nom, s.rowid, p.rowid as propalid, p.fk_statut, p.total_ht";
635  $sql.= ", p.tva as total_tva";
636  $sql.= ", p.total as total_ttc";
637  $sql.= ", p.ref, p.ref_client, p.remise";
638  $sql.= ", p.datep as dp, p.fin_validite as datelimite";
639  $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as p, ".MAIN_DB_PREFIX."c_propalst as c";
640  $sql.= " WHERE p.fk_soc = s.rowid AND p.fk_statut = c.id";
641  $sql.= " AND s.rowid = ".$object->id;
642  $sql.= " AND p.entity = ".$conf->entity;
643  $sql.= " ORDER BY p.datep DESC";
644 
645  $resql=$db->query($sql);
646  if ($resql)
647  {
648  $var=true;
649  $num = $db->num_rows($resql);
650 
651  if ($num > 0)
652  {
653  print '<table class="noborder" width="100%">';
654 
655  print '<tr class="liste_titre">';
656  print '<td colspan="4"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("LastPropals",($num<=$MAXLIST?"":$MAXLIST)).'</td><td align="right"><a class="notasortlink" href="'.DOL_URL_ROOT.'/comm/propal/list.php?socid='.$object->id.'">'.$langs->trans("AllPropals").' <span class="badge">'.$num.'</span></a></td>';
657  print '<td width="20px" align="right"><a href="'.DOL_URL_ROOT.'/comm/propal/stats/index.php?socid='.$object->id.'">'.img_picto($langs->trans("Statistics"),'stats').'</a></td>';
658  print '</tr></table></td>';
659  print '</tr>';
660  }
661 
662  $i = 0;
663  while ($i < $num && $i < $MAXLIST)
664  {
665  $objp = $db->fetch_object($resql);
666 
667  print '<tr class="oddeven">';
668  print '<td class="nowrap">';
669  $propal_static->id = $objp->propalid;
670  $propal_static->ref = $objp->ref;
671  $propal_static->ref_client = $objp->ref_client;
672  $propal_static->total_ht = $objp->total_ht;
673  $propal_static->total_tva = $objp->total_tva;
674  $propal_static->total_ttc = $objp->total_ttc;
675  print $propal_static->getNomUrl(1);
676  if ( ($db->jdate($objp->datelimite) < ($now - $conf->propal->cloture->warning_delay)) && $objp->fk_statut == 1 ) {
677  print " ".img_warning();
678  }
679  print '</td><td align="right" width="80px">'.dol_print_date($db->jdate($objp->dp),'day')."</td>\n";
680  print '<td align="right" style="min-width: 60px">'.price($objp->total_ht).'</td>';
681  print '<td align="right" style="min-width: 60px" class="nowrap">'.$propal_static->LibStatut($objp->fk_statut,5).'</td></tr>';
682  $i++;
683  }
684  $db->free($resql);
685 
686  if ($num > 0) print "</table>";
687  }
688  else
689  {
690  dol_print_error($db);
691  }
692  }
693 
694  /*
695  * Last orders
696  */
697  if (! empty($conf->commande->enabled) && $user->rights->commande->lire)
698  {
699  $commande_static=new Commande($db);
700 
701  $sql = "SELECT s.nom, s.rowid";
702  $sql.= ", c.rowid as cid, c.total_ht";
703  $sql.= ", c.tva as total_tva";
704  $sql.= ", c.total_ttc";
705  $sql.= ", c.ref, c.ref_client, c.fk_statut, c.facture";
706  $sql.= ", c.date_commande as dc";
707  $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande as c";
708  $sql.= " WHERE c.fk_soc = s.rowid ";
709  $sql.= " AND s.rowid = ".$object->id;
710  $sql.= " AND c.entity = ".$conf->entity;
711  $sql.= " ORDER BY c.date_commande DESC";
712 
713  $resql=$db->query($sql);
714  if ($resql)
715  {
716  $var=true;
717  $num = $db->num_rows($resql);
718 
719  if ($num > 0)
720  {
721  // Check if there are orders billable
722  $sql2 = 'SELECT s.nom, s.rowid as socid, s.client, c.rowid, c.ref, c.total_ht, c.ref_client,';
723  $sql2.= ' c.date_valid, c.date_commande, c.date_livraison, c.fk_statut, c.facture as facturee';
724  $sql2.= ' FROM '.MAIN_DB_PREFIX.'societe as s';
725  $sql2.= ', '.MAIN_DB_PREFIX.'commande as c';
726  $sql2.= ' WHERE c.fk_soc = s.rowid';
727  $sql2.= ' AND s.rowid = '.$object->id;
728  // Show orders with status validated, shipping started and delivered (well any order we can bill)
729  $sql2.= " AND ((c.fk_statut IN (1,2)) OR (c.fk_statut = 3 AND c.facture = 0))";
730 
731  $resql2=$db->query($sql2);
732  $orders2invoice = $db->num_rows($resql2);
733  $db->free($resql2);
734 
735  print '<table class="noborder" width="100%">';
736 
737  print '<tr class="liste_titre">';
738  print '<td colspan="4"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("LastCustomerOrders",($num<=$MAXLIST?"":$MAXLIST)).'</td><td align="right"><a class="notasortlink" href="'.DOL_URL_ROOT.'/commande/list.php?socid='.$object->id.'">'.$langs->trans("AllOrders").' <span class="badge">'.$num.'</span></a></td>';
739  print '<td width="20px" align="right"><a href="'.DOL_URL_ROOT.'/commande/stats/index.php?socid='.$object->id.'">'.img_picto($langs->trans("Statistics"),'stats').'</a></td>';
740  //if($num2 > 0) print '<td width="20px" align="right"><a href="'.DOL_URL_ROOT.'/commande/orderstoinvoice.php?socid='.$object->id.'">'.img_picto($langs->trans("CreateInvoiceForThisCustomer"),'object_bill').'</a></td>';
741  //else print '<td width="20px" align="right"><a href="#">'.img_picto($langs->trans("NoOrdersToInvoice"),'object_bill').'</a></td>';
742  print '</tr></table></td>';
743  print '</tr>';
744  }
745 
746  $i = 0;
747  while ($i < $num && $i < $MAXLIST)
748  {
749  $objp = $db->fetch_object($resql);
750 
751  print '<tr class="oddeven">';
752  print '<td class="nowrap">';
753  $commande_static->id = $objp->cid;
754  $commande_static->ref = $objp->ref;
755  $commande_static->ref_client=$objp->ref_client;
756  $commande_static->total_ht = $objp->total_ht;
757  $commande_static->total_tva = $objp->total_tva;
758  $commande_static->total_ttc = $objp->total_ttc;
759  print $commande_static->getNomUrl(1);
760  print '</td><td align="right" width="80px">'.dol_print_date($db->jdate($objp->dc),'day')."</td>\n";
761  print '<td align="right" style="min-width: 60px">'.price($objp->total_ht).'</td>';
762  print '<td align="right" style="min-width: 60px" class="nowrap">'.$commande_static->LibStatut($objp->fk_statut,$objp->facture,5).'</td></tr>';
763  $i++;
764  }
765  $db->free($resql);
766 
767  if ($num >0) print "</table>";
768  }
769  else
770  {
771  dol_print_error($db);
772  }
773  }
774 
775  /*
776  * Last sendings
777  */
778  if (! empty($conf->expedition->enabled) && $user->rights->expedition->lire) {
779  $sendingstatic = new Expedition($db);
780 
781  $sql = 'SELECT e.rowid as id';
782  $sql.= ', e.ref';
783  $sql.= ', e.date_creation';
784  $sql.= ', e.fk_statut as statut';
785  $sql.= ', s.nom';
786  $sql.= ', s.rowid as socid';
787  $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."expedition as e";
788  $sql.= " WHERE e.fk_soc = s.rowid AND s.rowid = ".$object->id;
789  $sql.= " AND e.entity IN (".getEntity('expedition').")";
790  $sql.= ' GROUP BY e.rowid';
791  $sql.= ', e.ref';
792  $sql.= ', e.date_creation';
793  $sql.= ', e.fk_statut';
794  $sql.= ', s.nom';
795  $sql.= ', s.rowid';
796  $sql.= " ORDER BY e.date_creation DESC";
797 
798  $resql = $db->query($sql);
799  if ($resql) {
800  $var = true;
801  $num = $db->num_rows($resql);
802  $i = 0;
803  if ($num > 0) {
804  print '<table class="noborder" width="100%">';
805 
806  print '<tr class="liste_titre">';
807  print '<td colspan="4"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("LastSendings",($num<=$MAXLIST?"":$MAXLIST)).'</td><td align="right"><a class="notasortlink" href="'.DOL_URL_ROOT.'/expedition/list.php?socid='.$object->id.'">'.$langs->trans("AllSendings").' <span class="badge">'.$num.'</span></a></td>';
808  print '<td width="20px" align="right"><a href="'.DOL_URL_ROOT.'/expedition/stats/index.php?socid='.$object->id.'">'.img_picto($langs->trans("Statistics"),'stats').'</a></td>';
809  print '</tr></table></td>';
810  print '</tr>';
811  }
812 
813  while ($i < $num && $i < $MAXLIST) {
814  $objp = $db->fetch_object($resql);
815  print '<tr class="oddeven">';
816  print '<td class="nowrap">';
817  $sendingstatic->id = $objp->id;
818  $sendingstatic->ref = $objp->ref;
819  print $sendingstatic->getNomUrl(1);
820  print '</td>';
821  if ($objp->date_creation > 0) {
822  print '<td align="right" width="80px">'.dol_print_date($db->jdate($objp->date_creation),'day').'</td>';
823  } else {
824  print '<td align="right"><b>!!!</b></td>';
825  }
826 
827  print '<td align="right" class="nowrap" width="100" >' . $sendingstatic->LibStatut($objp->statut, 5) . '</td>';
828  print "</tr>\n";
829  $i++;
830  }
831  $db->free($resql);
832 
833  if ($num > 0)
834  print "</table>";
835  } else {
836  dol_print_error($db);
837  }
838  }
839 
840  /*
841  * Last linked contracts
842  */
843  if (! empty($conf->contrat->enabled) && $user->rights->contrat->lire)
844  {
845  $contratstatic=new Contrat($db);
846 
847  $sql = "SELECT s.nom, s.rowid, c.rowid as id, c.ref as ref, c.statut, c.datec as dc, c.date_contrat as dcon, c.ref_supplier as refsup";
848  $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."contrat as c";
849  $sql.= " WHERE c.fk_soc = s.rowid ";
850  $sql.= " AND s.rowid = ".$object->id;
851  $sql.= " AND c.entity = ".$conf->entity;
852  $sql.= " ORDER BY c.datec DESC";
853 
854  $resql=$db->query($sql);
855  if ($resql)
856  {
857  $var=true;
858  $num = $db->num_rows($resql);
859  if ($num >0 )
860  {
861  print '<table class="noborder" width="100%">';
862 
863  print '<tr class="liste_titre">';
864  print '<td colspan="6"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("LastContracts",($num<=$MAXLIST?"":$MAXLIST)).'</td>';
865  print '<td align="right"><a class="notasortlink" href="'.DOL_URL_ROOT.'/contrat/list.php?socid='.$object->id.'">'.$langs->trans("AllContracts").' <span class="badge">'.$num.'</span></a></td>';
866  //print '<td width="20px" align="right"><a href="'.DOL_URL_ROOT.'/contract/stats/index.php?socid='.$object->id.'">'.img_picto($langs->trans("Statistics"),'stats').'</a></td>';
867  print '</tr></table></td>';
868  print '</tr>';
869  }
870  $i = 0;
871  while ($i < $num && $i < $MAXLIST)
872  {
873  $contrat=new Contrat($db);
874 
875  $objp = $db->fetch_object($resql);
876 
877  print '<tr class="oddeven">';
878  print '<td class="nowrap">';
879  $contrat->id=$objp->id;
880  $contrat->ref=$objp->ref?$objp->ref:$objp->id;
881  print $contrat->getNomUrl(1,12);
882  print "</td>\n";
883  print '<td class="nowrap">'.dol_trunc($objp->refsup,12)."</td>\n";
884  print '<td align="right" width="80px">'.dol_print_date($db->jdate($objp->dc),'day')."</td>\n";
885  print '<td align="right" width="80px">'.dol_print_date($db->jdate($objp->dcon),'day')."</td>\n";
886  print '<td width="20">&nbsp;</td>';
887  print '<td align="right" class="nowrap">';
888  $contrat->fetch_lines();
889  print $contrat->getLibStatut(4);
890  print "</td>\n";
891  print '</tr>';
892  $i++;
893  }
894  $db->free($resql);
895 
896  if ($num > 0) print "</table>";
897  }
898  else
899  {
900  dol_print_error($db);
901  }
902  }
903 
904  /*
905  * Last interventions
906  */
907  if (! empty($conf->ficheinter->enabled) && $user->rights->ficheinter->lire)
908  {
909  $sql = "SELECT s.nom, s.rowid, f.rowid as id, f.ref, f.fk_statut, f.duree as duration, f.datei as startdate";
910  $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."fichinter as f";
911  $sql.= " WHERE f.fk_soc = s.rowid";
912  $sql.= " AND s.rowid = ".$object->id;
913  $sql.= " AND f.entity = ".$conf->entity;
914  $sql.= " ORDER BY f.tms DESC";
915 
916  $fichinter_static=new Fichinter($db);
917 
918  $resql=$db->query($sql);
919  if ($resql)
920  {
921  $var=true;
922  $num = $db->num_rows($resql);
923  if ($num > 0)
924  {
925  print '<table class="noborder" width="100%">';
926 
927  print '<tr class="liste_titre">';
928  print '<td colspan="3"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("LastInterventions",($num<=$MAXLIST?"":$MAXLIST)).'</td><td align="right"><a class="notasortlink" href="'.DOL_URL_ROOT.'/fichinter/list.php?socid='.$object->id.'">'.$langs->trans("AllInterventions").' <span class="badge">'.$num.'</span></td>';
929  print '<td width="20px" align="right"><a href="'.DOL_URL_ROOT.'/fichinter/stats/index.php?socid='.$object->id.'">'.img_picto($langs->trans("Statistics"),'stats').'</a></td>';
930  print '</tr></table></td>';
931  print '</tr>';
932 
933  }
934  $i = 0;
935  while ($i < $num && $i < $MAXLIST)
936  {
937  $objp = $db->fetch_object($resql);
938 
939  $fichinter_static->id=$objp->id;
940  $fichinter_static->statut=$objp->fk_statut;
941 
942  print '<tr class="oddeven">';
943  print '<td class="nowrap"><a href="'.DOL_URL_ROOT.'/fichinter/card.php?id='.$objp->id.'">'.img_object($langs->trans("ShowPropal"),"propal").' '.$objp->ref.'</a></td>'."\n";
944  //print '<td align="right" width="80px">'.dol_print_date($db->jdate($objp->startdate)).'</td>'."\n";
945  print '<td align="right" style="min-width: 60px">'.convertSecondToTime($objp->duration).'</td>'."\n";
946  print '<td align="right" class="nowrap" style="min-width: 60px">'.$fichinter_static->getLibStatut(5).'</td>'."\n";
947  print '</tr>';
948 
949  $i++;
950  }
951  $db->free($resql);
952 
953  if ($num > 0) print "</table>";
954  }
955  else
956  {
957  dol_print_error($db);
958  }
959  }
960 
961  /*
962  * Last invoices templates
963  */
964  if (! empty($conf->facture->enabled) && $user->rights->facture->lire)
965  {
966  $invoicetemplate = new FactureRec($db);
967 
968  $sql = 'SELECT f.rowid as id, f.titre as ref, f.amount';
969  $sql.= ', f.total as total_ht';
970  $sql.= ', f.tva as total_tva';
971  $sql.= ', f.total_ttc';
972  $sql.= ', f.datec as dc';
973  $sql.= ', f.date_last_gen';
974  $sql.= ', f.frequency';
975  $sql.= ', f.unit_frequency';
976  $sql.= ', f.suspended as suspended';
977  $sql.= ', s.nom, s.rowid as socid';
978  $sql.= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture_rec as f";
979  $sql.= " WHERE f.fk_soc = s.rowid AND s.rowid = ".$object->id;
980  $sql.= " AND f.entity = ".$conf->entity;
981  $sql.= ' GROUP BY f.rowid, f.titre, f.amount, f.total, f.tva, f.total_ttc,';
982  $sql.= ' f.date_last_gen, f.datec, f.frequency, f.unit_frequency,';
983  $sql.= ' f.suspended,';
984  $sql.= ' s.nom, s.rowid';
985  $sql.= " ORDER BY f.date_last_gen, f.datec DESC";
986 
987  $resql=$db->query($sql);
988  if ($resql)
989  {
990  $var=true;
991  $num = $db->num_rows($resql);
992  $i = 0;
993  if ($num > 0)
994  {
995  print '<table class="noborder" width="100%">';
996 
997  print '<tr class="liste_titre">';
998  print '<td colspan="4"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("LatestCustomerTemplateInvoices",($num<=$MAXLIST?"":$MAXLIST)).'</td><td align="right"><a class="notasortlink" href="'.DOL_URL_ROOT.'/compta/facture/list.php?socid='.$object->id.'">'.$langs->trans("AllCustomerTemplateInvoices").' <span class="badge">'.$num.'</span></a></td>';
999  print '</tr></table></td>';
1000  print '</tr>';
1001  }
1002 
1003  while ($i < $num && $i < $MAXLIST)
1004  {
1005  $objp = $db->fetch_object($resql);
1006 
1007  print '<tr class="oddeven">';
1008  print '<td class="nowrap">';
1009  $invoicetemplate->id = $objp->id;
1010  $invoicetemplate->ref = $objp->ref;
1011  $invoicetemplate->suspended = $objp->suspended;
1012  $invoicetemplate->frequency = $objp->frequency;
1013  $invoicetemplate->unit_frequency = $objp->unit_frequency;
1014  $invoicetemplate->total_ht = $objp->total_ht;
1015  $invoicetemplate->total_tva = $objp->total_tva;
1016  $invoicetemplate->total_ttc = $objp->total_ttc;
1017  print $invoicetemplate->getNomUrl(1);
1018  print '</td>';
1019  if ($objp->frequency && $objp->date_last_gen > 0)
1020  {
1021  print '<td align="right" width="80px">'.dol_print_date($db->jdate($objp->date_last_gen),'day').'</td>';
1022  }
1023  else
1024  {
1025  if ($objp->dc > 0)
1026  {
1027  print '<td align="right" width="80px">'.dol_print_date($db->jdate($objp->dc),'day').'</td>';
1028  }
1029  else
1030  {
1031  print '<td align="right"><b>!!!</b></td>';
1032  }
1033  }
1034  print '<td align="right" style="min-width: 60px">';
1035  print price($objp->total_ht);
1036  print '</td>';
1037 
1038  if (! empty($conf->global->MAIN_SHOW_PRICE_WITH_TAX_IN_SUMMARIES))
1039  {
1040  print '<td align="right" style="min-width: 60px">';
1041  print price($objp->total_ttc);
1042  print '</td>';
1043  }
1044 
1045  print '<td align="right" class="nowrap" style="min-width: 60px">';
1046  print $langs->trans('FrequencyPer_'.$invoicetemplate->unit_frequency, $invoicetemplate->frequency).' - ';
1047  print ($invoicetemplate->LibStatut($invoicetemplate->frequency,$invoicetemplate->suspended,5,0));
1048  print '</td>';
1049  print "</tr>\n";
1050  $i++;
1051  }
1052  $db->free($resql);
1053 
1054  if ($num > 0) print "</table>";
1055  }
1056  else
1057  {
1058  dol_print_error($db);
1059  }
1060  }
1061 
1062  /*
1063  * Last invoices
1064  */
1065  if (! empty($conf->facture->enabled) && $user->rights->facture->lire)
1066  {
1067  $facturestatic = new Facture($db);
1068 
1069  $sql = 'SELECT f.rowid as facid, f.facnumber, f.type, f.amount';
1070  $sql.= ', f.total as total_ht';
1071  $sql.= ', f.tva as total_tva';
1072  $sql.= ', f.total_ttc';
1073  $sql.= ', f.datef as df, f.datec as dc, f.paye as paye, f.fk_statut as statut';
1074  $sql.= ', s.nom, s.rowid as socid';
1075  $sql.= ', SUM(pf.amount) as am';
1076  $sql.= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f";
1077  $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON f.rowid=pf.fk_facture';
1078  $sql.= " WHERE f.fk_soc = s.rowid AND s.rowid = ".$object->id;
1079  $sql.= " AND f.entity = ".$conf->entity;
1080  $sql.= ' GROUP BY f.rowid, f.facnumber, f.type, f.amount, f.total, f.tva, f.total_ttc,';
1081  $sql.= ' f.datef, f.datec, f.paye, f.fk_statut,';
1082  $sql.= ' s.nom, s.rowid';
1083  $sql.= " ORDER BY f.datef DESC, f.datec DESC";
1084 
1085  $resql=$db->query($sql);
1086  if ($resql)
1087  {
1088  $var=true;
1089  $num = $db->num_rows($resql);
1090  $i = 0;
1091  if ($num > 0)
1092  {
1093  print '<table class="noborder" width="100%">';
1094 
1095  print '<tr class="liste_titre">';
1096  print '<td colspan="5"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("LastCustomersBills",($num<=$MAXLIST?"":$MAXLIST)).'</td><td align="right"><a class="notasortlink" href="'.DOL_URL_ROOT.'/compta/facture/list.php?socid='.$object->id.'">'.$langs->trans("AllBills").' <span class="badge">'.$num.'</span></a></td>';
1097  print '<td width="20px" align="right"><a href="'.DOL_URL_ROOT.'/compta/facture/stats/index.php?socid='.$object->id.'">'.img_picto($langs->trans("Statistics"),'stats').'</a></td>';
1098  print '</tr></table></td>';
1099  print '</tr>';
1100  }
1101 
1102  while ($i < $num && $i < $MAXLIST)
1103  {
1104  $objp = $db->fetch_object($resql);
1105 
1106  print '<tr class="oddeven">';
1107  print '<td class="nowrap">';
1108  $facturestatic->id = $objp->facid;
1109  $facturestatic->ref = $objp->facnumber;
1110  $facturestatic->type = $objp->type;
1111  $facturestatic->total_ht = $objp->total_ht;
1112  $facturestatic->total_tva = $objp->total_tva;
1113  $facturestatic->total_ttc = $objp->total_ttc;
1114  print $facturestatic->getNomUrl(1);
1115  print '</td>';
1116  if ($objp->df > 0)
1117  {
1118  print '<td align="right" width="80px">'.dol_print_date($db->jdate($objp->df),'day').'</td>';
1119  }
1120  else
1121  {
1122  print '<td align="right"><b>!!!</b></td>';
1123  }
1124  print '<td align="right" style="min-width: 60px">';
1125  print price($objp->total_ht);
1126  print '</td>';
1127 
1128  if (! empty($conf->global->MAIN_SHOW_PRICE_WITH_TAX_IN_SUMMARIES))
1129  {
1130  print '<td align="right" style="min-width: 60px">';
1131  print price($objp->total_ttc);
1132  print '</td>';
1133  }
1134 
1135  print '<td align="right" class="nowrap" style="min-width: 60px">'.($facturestatic->LibStatut($objp->paye,$objp->statut,5,$objp->am)).'</td>';
1136  print "</tr>\n";
1137  $i++;
1138  }
1139  $db->free($resql);
1140 
1141  if ($num > 0) print "</table>";
1142  }
1143  else
1144  {
1145  dol_print_error($db);
1146  }
1147  }
1148 
1149  print '</div></div></div>';
1150  print '<div style="clear:both"></div>';
1151 
1152  dol_fiche_end();
1153 
1154 
1155  /*
1156  * Barre d'actions
1157  */
1158 
1159  print '<div class="tabsAction">';
1160 
1161  $parameters = array();
1162  $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
1163 
1164  if (empty($reshook))
1165  {
1166  if ($object->status != 1)
1167  {
1168  print '<div class="inline-block divButAction"><a class="butActionRefused" title="'.dol_escape_js($langs->trans("ThirdPartyIsClosed")).'" href="#">'.$langs->trans("ThirdPartyIsClosed").'</a></div>';
1169  }
1170 
1171  if (! empty($conf->propal->enabled) && $user->rights->propal->creer && $object->status==1)
1172  {
1173  $langs->load("propal");
1174  print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/comm/propal/card.php?socid='.$object->id.'&amp;action=create">'.$langs->trans("AddProp").'</a></div>';
1175  }
1176 
1177  if (! empty($conf->commande->enabled) && $user->rights->commande->creer && $object->status==1)
1178  {
1179  $langs->load("orders");
1180  print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/commande/card.php?socid='.$object->id.'&amp;action=create">'.$langs->trans("AddOrder").'</a></div>';
1181  }
1182 
1183  if ($user->rights->contrat->creer && $object->status==1)
1184  {
1185  $langs->load("contracts");
1186  print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/contrat/card.php?socid='.$object->id.'&amp;action=create">'.$langs->trans("AddContract").'</a></div>';
1187  }
1188 
1189  if (! empty($conf->ficheinter->enabled) && $user->rights->ficheinter->creer && $object->status==1)
1190  {
1191  $langs->load("fichinter");
1192  print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/fichinter/card.php?socid='.$object->id.'&amp;action=create">'.$langs->trans("AddIntervention").'</a></div>';
1193  }
1194 
1195  // Add invoice
1196  if ($user->societe_id == 0)
1197  {
1198  if (! empty($conf->deplacement->enabled) && $object->status==1)
1199  {
1200  $langs->load("trips");
1201  print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/deplacement/card.php?socid='.$object->id.'&amp;action=create">'.$langs->trans("AddTrip").'</a></div>';
1202  }
1203 
1204  if (! empty($conf->facture->enabled) && $object->status==1)
1205  {
1206  if (empty($user->rights->facture->creer))
1207  {
1208  print '<div class="inline-block divButAction"><a class="butActionRefused" title="'.dol_escape_js($langs->trans("NotAllowed")).'" href="#">'.$langs->trans("AddBill").'</a></div>';
1209  }
1210  else
1211  {
1212  $langs->load("bills");
1213  $langs->load("orders");
1214 
1215  if (! empty($conf->commande->enabled))
1216  {
1217  if ($object->client != 0 && $object->client != 2)
1218  {
1219  if (! empty($orders2invoice) && $orders2invoice > 0) print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/commande/orderstoinvoice.php?socid='.$object->id.'">'.$langs->trans("CreateInvoiceForThisCustomer").'</a></div>';
1220  else print '<div class="inline-block divButAction"><a class="butActionRefused" title="'.dol_escape_js($langs->trans("NoOrdersToInvoice")).'" href="#">'.$langs->trans("CreateInvoiceForThisCustomer").'</a></div>';
1221  }
1222  else print '<div class="inline-block divButAction"><a class="butActionRefused" title="'.dol_escape_js($langs->trans("ThirdPartyMustBeEditAsCustomer")).'" href="#">'.$langs->trans("AddBill").'</a></div>';
1223  }
1224 
1225  if ($object->client != 0 && $object->client != 2) print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/facture/card.php?action=create&socid='.$object->id.'">'.$langs->trans("AddBill").'</a></div>';
1226  else print '<div class="inline-block divButAction"><a class="butActionRefused" title="'.dol_escape_js($langs->trans("ThirdPartyMustBeEditAsCustomer")).'" href="#">'.$langs->trans("AddBill").'</a></div>';
1227 
1228  }
1229  }
1230  }
1231 
1232  // Add action
1233  if (! empty($conf->agenda->enabled) && ! empty($conf->global->MAIN_REPEATTASKONEACHTAB) && $object->status==1)
1234  {
1235  if ($user->rights->agenda->myactions->create)
1236  {
1237  print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create&socid='.$object->id.'">'.$langs->trans("AddAction").'</a></div>';
1238  }
1239  else
1240  {
1241  print '<div class="inline-block divButAction"><a class="butAction" title="'.dol_escape_js($langs->trans("NotAllowed")).'" href="#">'.$langs->trans("AddAction").'</a></div>';
1242  }
1243  }
1244  }
1245 
1246  print '</div>';
1247 
1248  if (! empty($conf->global->MAIN_REPEATCONTACTONEACHTAB))
1249  {
1250  // List of contacts
1251  show_contacts($conf,$langs,$db,$object,$_SERVER["PHP_SELF"].'?socid='.$object->id);
1252  }
1253 
1254  // Addresses list
1255  if (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) && ! empty($conf->global->MAIN_REPEATADDRESSONEACHTAB))
1256  {
1257  show_addresses($conf,$langs,$db,$object,$_SERVER["PHP_SELF"].'?socid='.$object->id);
1258  }
1259 
1260  if (! empty($conf->global->MAIN_REPEATTASKONEACHTAB))
1261  {
1262  print load_fiche_titre($langs->trans("ActionsOnCompany"),'','');
1263 
1264  // List of todo actions
1265  show_actions_todo($conf,$langs,$db,$object);
1266 
1267  // List of done actions
1268  show_actions_done($conf,$langs,$db,$object);
1269  }
1270 
1271 }
1272 else
1273 {
1274  dol_print_error($db,'Bad value for socid parameter');
1275 }
1276 
1277 // End of page
1278 llxFooter();
1279 
1280 $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_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 interventions.
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.
Class to manage invoice templates.
Class to manage Dolibarr users.
Definition: user.class.php:39
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0)
Return an id or code from a code or id.
Class to manage customers or prospects.
Class to manage contracts.
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...
if(empty($reshook)) $form
View.
Definition: perms.php:103
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to build HTML component for third parties management Only common components are here...
Class to manage standard extra fields.
Class to manage generation of HTML components Only common components must be here.
img_action($titlealt, $numaction)
Show logo action.
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
Class to manage shipments.
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 customers orders.
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
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
societe_prepare_head(Societe $object)
Return array of tabs to used on pages for third parties cards.
Definition: company.lib.php:40
dol_now($mode='gmt')
Return date for now.
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...
print
Draft customers invoices.
Definition: index.php:91
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
Class to manage invoices.
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)
Class to manage proposals.
$parameters
Actions.
Definition: card.php:112