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) 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@inodbox.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 // Load translation files required by the page
49 $langs->loadLangs(array('companies', '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('thirdpartycomm','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  // update order min amount
181  if ($action == 'setorder_min_amount')
182  {
183  $object->fetch($id);
184  $object->order_min_amount=price2num(GETPOST('order_min_amount','alpha'));
185  $result=$object->update($object->id, $user);
186  if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
187  }
188 
189  if ($action == 'update_extras') {
190  $object->fetch($id);
191 
192  $object->oldcopy = dol_clone($object);
193 
194  // Fill array 'array_options' with data from update form
195  $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
196  $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute','none'));
197  if ($ret < 0) $error++;
198  if (! $error)
199  {
200  $result = $object->insertExtraFields('COMPANY_MODIFY');
201  if ($result < 0)
202  {
203  setEventMessages($object->error, $object->errors, 'errors');
204  $error++;
205  }
206  }
207  if ($error) $action = 'edit_extras';
208  }
209 }
210 
211 
212 /*
213  * View
214  */
215 
216 $contactstatic = new Contact($db);
217 $userstatic=new User($db);
218 $form = new Form($db);
219 $formcompany=new FormCompany($db);
220 
221 if ($id > 0 && empty($object->id))
222 {
223  // Load data of third party
224  $res=$object->fetch($id);
225  if ($object->id < 0) dol_print_error($db, $object->error, $object->errors);
226 }
227 
228 $title=$langs->trans("CustomerCard");
229 if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name;
230 $help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
231 llxHeader('',$title,$help_url);
232 
233 
234 if ($object->id > 0)
235 {
236  $head = societe_prepare_head($object);
237 
238  dol_fiche_head($head, 'customer', $langs->trans("ThirdParty"), -1, 'company');
239 
240  $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php">'.$langs->trans("BackToList").'</a>';
241 
242  dol_banner_tab($object, 'socid', $linkback, ($user->societe_id?0:1), 'rowid', 'nom');
243 
244  print '<div class="fichecenter"><div class="fichehalfleft">';
245 
246  print '<div class="underbanner clearboth"></div>';
247  print '<table class="border" width="100%">';
248 
249  // Prospect/Customer
250  print '<tr><td class="titlefield">'.$langs->trans('ProspectCustomer').'</td><td>';
251  print $object->getLibCustProspStatut();
252  print '</td></tr>';
253 
254  // Prefix
255  if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field
256  {
257  print '<tr><td>'.$langs->trans("Prefix").'</td><td>';
258  print ($object->prefix_comm?$object->prefix_comm:'&nbsp;');
259  print '</td></tr>';
260  }
261 
262  if ($object->client)
263  {
264  $langs->load("compta");
265 
266  print '<tr><td>';
267  print $langs->trans('CustomerCode').'</td><td>';
268  print $object->code_client;
269  if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>';
270  print '</td></tr>';
271 
272  print '<tr>';
273  print '<td>';
274  print $form->editfieldkey("CustomerAccountancyCode",'customeraccountancycode',$object->code_compta,$object,$user->rights->societe->creer);
275  print '</td><td>';
276  print $form->editfieldval("CustomerAccountancyCode",'customeraccountancycode',$object->code_compta,$object,$user->rights->societe->creer);
277  print '</td>';
278  print '</tr>';
279  }
280 
281  // This fields are used to know VAT to include in an invoice when the thirdparty is making a sale, so when it is a supplier.
282  // We don't need them into customer profile.
283  // Except for spain and localtax where localtax depends on buyer and not seller
284 
285  // VAT is used
286  /*
287  print '<tr>';
288  print '<td class="nowrap">';
289  print $form->textwithpicto($langs->trans('VATIsUsed'),$langs->trans('VATIsUsedWhenSelling'));
290  print '</td>';
291  print '<td>';
292  print yn($object->tva_assuj);
293  print '</td>';
294  print '</tr>';
295  */
296 
297  if ($mysoc->country_code == 'ES')
298  {
299  // Local Taxes
300  if ($mysoc->localtax1_assuj=="1")
301  {
302  print '<tr><td class="nowrap">'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).'</td><td>';
303  print yn($object->localtax1_assuj);
304  print '</td></tr>';
305  }
306  if ($mysoc->localtax1_assuj=="1")
307  {
308  print '<tr><td class="nowrap">'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).'</td><td>';
309  print yn($object->localtax2_assuj);
310  print '</td></tr>';
311  }
312  }
313 
314  // TVA Intra
315  print '<tr><td class="nowrap">'.$langs->trans('VATIntra').'</td><td>';
316  print $object->tva_intra;
317  print '</td></tr>';
318 
319  // Conditions de reglement par defaut
320  $langs->load('bills');
321  print '<tr><td>';
322  print '<table width="100%" class="nobordernopadding"><tr><td>';
323  print $langs->trans('PaymentConditions');
324  print '<td>';
325  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>';
326  print '</tr></table>';
327  print '</td><td>';
328  if ($action == 'editconditions')
329  {
330  $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->cond_reglement_id, 'cond_reglement_id', 1);
331  }
332  else
333  {
334  $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->cond_reglement_id, 'none');
335  }
336  print "</td>";
337  print '</tr>';
338 
339  // Mode de reglement par defaut
340  print '<tr><td class="nowrap">';
341  print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
342  print $langs->trans('PaymentMode');
343  print '<td>';
344  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>';
345  print '</tr></table>';
346  print '</td><td>';
347  if ($action == 'editmode')
348  {
349  $form->form_modes_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->mode_reglement_id, 'mode_reglement_id', 'CRDT', 1, 1);
350  }
351  else
352  {
353  $form->form_modes_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->mode_reglement_id,'none');
354  }
355  print "</td>";
356  print '</tr>';
357 
358  if (! empty($conf->banque->enabled))
359  {
360  // Compte bancaire par défaut
361  print '<tr><td class="nowrap">';
362  print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
363  print $langs->trans('PaymentBankAccount');
364  print '<td>';
365  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>';
366  print '</tr></table>';
367  print '</td><td>';
368  if ($action == 'editbankaccount')
369  {
370  $form->formSelectAccount($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->fk_account,'fk_account',1);
371  }
372  else
373  {
374  $form->formSelectAccount($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->fk_account,'none');
375  }
376  print "</td>";
377  print '</tr>';
378  }
379 
380  // Relative discounts (Discounts-Drawbacks-Rebates)
381  print '<tr><td class="nowrap">';
382  print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
383  print $langs->trans("CustomerRelativeDiscountShort");
384  print '<td><td align="right">';
385  if ($user->rights->societe->creer && !$user->societe_id > 0)
386  {
387  print '<a href="'.DOL_URL_ROOT.'/comm/remise.php?id='.$object->id.'">'.img_edit($langs->trans("Modify")).'</a>';
388  }
389  print '</td></tr></table>';
390  print '</td><td>'.($object->remise_percent?'<a href="'.DOL_URL_ROOT.'/comm/remise.php?id='.$object->id.'">'.$object->remise_percent.'%</a>':'').'</td>';
391  print '</tr>';
392 
393  // Absolute discounts (Discounts-Drawbacks-Rebates)
394  print '<tr><td class="nowrap">';
395  print '<table width="100%" class="nobordernopadding">';
396  print '<tr><td class="nowrap">';
397  print $langs->trans("CustomerAbsoluteDiscountShort");
398  print '<td><td align="right">';
399  if ($user->rights->societe->creer && !$user->societe_id > 0)
400  {
401  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>';
402  }
403  print '</td></tr></table>';
404  print '</td>';
405  print '<td>';
406  $amount_discount=$object->getAvailableDiscounts();
407  if ($amount_discount < 0) dol_print_error($db,$object->error);
408  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>';
409  //else print $langs->trans("DiscountNone");
410  print '</td>';
411  print '</tr>';
412 
413  // Max outstanding bill
414  if ($object->client)
415  {
416  print '<tr class="nowrap">';
417  print '<td>';
418  print $form->editfieldkey("OutstandingBill",'outstanding_limit',$object->outstanding_limit,$object,$user->rights->societe->creer);
419  print '</td><td>';
420  $limit_field_type = (! empty($conf->global->MAIN_USE_JQUERY_JEDITABLE)) ? 'numeric' : 'amount';
421  print $form->editfieldval("OutstandingBill",'outstanding_limit',$object->outstanding_limit,$object,$user->rights->societe->creer,$limit_field_type,($object->outstanding_limit != '' ? price($object->outstanding_limit) : ''));
422  //if (empty($object->outstanding_limit)) print $langs->trans("NoLimit");
423 
424  print '</td>';
425  print '</tr>';
426  }
427 
428  if ($object->client)
429  {
430  if (! empty($conf->commande->enabled) && ! empty($conf->global->ORDER_MANAGE_MIN_AMOUNT))
431  {
432  print '<!-- Minimim amount for orders -->'."\n";
433  print '<tr class="nowrap">';
434  print '<td>';
435  print $form->editfieldkey("OrderMinAmount",'order_min_amount',$object->order_min_amount,$object,$user->rights->societe->creer);
436  print '</td><td>';
437  print $form->editfieldval("OrderMinAmount",'order_min_amount',$object->order_min_amount,$object,$user->rights->societe->creer,$limit_field_type,($object->order_min_amount != '' ? price($object->order_min_amount) : ''));
438  print '</td>';
439  print '</tr>';
440  }
441  }
442 
443 
444  // Multiprice level
445  if (! empty($conf->global->PRODUIT_MULTIPRICES) || ! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES))
446  {
447  print '<tr><td class="nowrap">';
448  print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
449  print $langs->trans("PriceLevel");
450  print '<td><td align="right">';
451  if ($user->rights->societe->creer)
452  {
453  print '<a href="'.DOL_URL_ROOT.'/comm/multiprix.php?id='.$object->id.'">'.img_edit($langs->trans("Modify")).'</a>';
454  }
455  print '</td></tr></table>';
456  print '</td><td>';
457  print $object->price_level;
458  $keyforlabel='PRODUIT_MULTIPRICES_LABEL'.$object->price_level;
459  if (! empty($conf->global->$keyforlabel)) print ' - '.$langs->trans($conf->global->$keyforlabel);
460  print "</td>";
461  print '</tr>';
462  }
463 
464  // Preferred shipping Method
465  if (! empty($conf->global->SOCIETE_ASK_FOR_SHIPPING_METHOD)) {
466  print '<tr><td class="nowrap">';
467  print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
468  print $langs->trans('SendingMethod');
469  print '<td>';
470  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>';
471  print '</tr></table>';
472  print '</td><td>';
473  if ($action == 'editshipping')
474  {
475  $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->shipping_method_id,'shipping_method_id');
476  }
477  else
478  {
479  $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->shipping_method_id,'none');
480  }
481  print "</td>";
482  print '</tr>';
483  }
484 
485  // Categories
486  if (!empty($conf->categorie->enabled) && !empty($user->rights->categorie->lire)) {
487  $langs->load("categories");
488  print '<tr><td>' . $langs->trans("CustomersCategoriesShort") . '</td>';
489  print '<td>';
490  print $form->showCategories( $object->id, 'customer', 1 );
491  print "</td></tr>";
492  }
493 
494  // Other attributes
495  $parameters=array('socid'=>$object->id);
496  include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
497 
498  // Sales representative
499  include DOL_DOCUMENT_ROOT.'/societe/tpl/linesalesrepresentative.tpl.php';
500 
501  // Module Adherent
502  if (! empty($conf->adherent->enabled))
503  {
504  $langs->load("members");
505  $langs->load("users");
506 
507  print '<tr><td class="titlefield">'.$langs->trans("LinkedToDolibarrMember").'</td>';
508  print '<td>';
509  $adh=new Adherent($db);
510  $result=$adh->fetch('','',$object->id);
511  if ($result > 0)
512  {
513  $adh->ref=$adh->getFullName($langs);
514  print $adh->getNomUrl(1);
515  }
516  else
517  {
518  print '<span class="opacitymedium">'.$langs->trans("ThirdpartyNotLinkedToMember").'</span>';
519  }
520  print '</td>';
521  print "</tr>\n";
522  }
523 
524  print "</table>";
525 
526  if ($object->client == 2 || $object->client == 3)
527  {
528  print '<br>';
529 
530  print '<div class="underbanner clearboth"></div>';
531  print '<table class="border" width="100%">';
532 
533  // Level of prospect
534  print '<tr><td class="titlefield nowrap">';
535  print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
536  print $langs->trans('ProspectLevel');
537  print '<td>';
538  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>';
539  print '</tr></table>';
540  print '</td><td>';
541  if ($action == 'editlevel')
542  {
543  $formcompany->form_prospect_level($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->fk_prospectlevel,'prospect_level_id',1);
544  }
545  else
546  {
547  print $object->getLibProspLevel();
548  }
549  print "</td>";
550  print '</tr>';
551 
552  // Status
553  $object->loadCacheOfProspStatus();
554  print '<tr><td>'.$langs->trans("StatusProsp").'</td><td>'.$object->getLibProspCommStatut(4, $object->cacheprospectstatus[$object->stcomm_id]['label']);
555  print ' &nbsp; &nbsp; ';
556  print '<div class="floatright">';
557  foreach($object->cacheprospectstatus as $key => $val)
558  {
559  $titlealt='default';
560  if (! empty($val['code']) && ! in_array($val['code'], array('ST_NO', 'ST_NEVER', 'ST_TODO', 'ST_PEND', 'ST_DONE'))) $titlealt=$val['label'];
561  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>';
562  }
563  print '</div></td></tr>';
564  print "</table>";
565  }
566 
567  print '</div><div class="fichehalfright"><div class="ficheaddleft">';
568  print '<div class="underbanner clearboth"></div>';
569 
570  $boxstat = '';
571 
572  // Nbre max d'elements des petites listes
573  $MAXLIST=$conf->global->MAIN_SIZE_SHORTLIST_LIMIT;
574 
575  // Lien recap
576  $boxstat.='<div class="box">';
577  $boxstat.='<table summary="'.dol_escape_htmltag($langs->trans("DolibarrStateBoard")).'" class="border boxtable boxtablenobottom boxtablenotop" width="100%">';
578  $boxstat.='<tr class="impair"><td colspan="2" class="tdboxstats nohover">';
579 
580  if (! empty($conf->propal->enabled))
581  {
582  // Box proposals
583  $tmp = $object->getOutstandingProposals();
584  $outstandingOpened=$tmp['opened'];
585  $outstandingTotal=$tmp['total_ht'];
586  $outstandingTotalIncTax=$tmp['total_ttc'];
587  $text=$langs->trans("OverAllProposals");
588  $link=DOL_URL_ROOT.'/comm/propal/list.php?socid='.$object->id;
589  $icon='bill';
590  if ($link) $boxstat.='<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
591  $boxstat.='<div class="boxstats" title="'.dol_escape_htmltag($text).'">';
592  $boxstat.='<span class="boxstatstext">'.img_object("",$icon).' '.$text.'</span><br>';
593  $boxstat.='<span class="boxstatsindicator">'.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
594  $boxstat.='</div>';
595  if ($link) $boxstat.='</a>';
596  }
597 
598  if (! empty($conf->commande->enabled))
599  {
600  // Box commandes
601  $tmp = $object->getOutstandingOrders();
602  $outstandingOpened=$tmp['opened'];
603  $outstandingTotal=$tmp['total_ht'];
604  $outstandingTotalIncTax=$tmp['total_ttc'];
605  $text=$langs->trans("OverAllOrders");
606  $link=DOL_URL_ROOT.'/commande/list.php?socid='.$object->id;
607  $icon='bill';
608  if ($link) $boxstat.='<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
609  $boxstat.='<div class="boxstats" title="'.dol_escape_htmltag($text).'">';
610  $boxstat.='<span class="boxstatstext">'.img_object("",$icon).' '.$text.'</span><br>';
611  $boxstat.='<span class="boxstatsindicator">'.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
612  $boxstat.='</div>';
613  if ($link) $boxstat.='</a>';
614  }
615 
616  if (! empty($conf->facture->enabled))
617  {
618  // Box factures
619  $tmp = $object->getOutstandingBills();
620  $outstandingOpened=$tmp['opened'];
621  $outstandingTotal=$tmp['total_ht'];
622  $outstandingTotalIncTax=$tmp['total_ttc'];
623  $text=$langs->trans("OverAllInvoices");
624  $link=DOL_URL_ROOT.'/compta/facture/list.php?socid='.$object->id;
625  $icon='bill';
626  if ($link) $boxstat.='<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
627  $boxstat.='<div class="boxstats" title="'.dol_escape_htmltag($text).'">';
628  $boxstat.='<span class="boxstatstext">'.img_object("",$icon).' '.$text.'</span><br>';
629  $boxstat.='<span class="boxstatsindicator">'.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
630  $boxstat.='</div>';
631  if ($link) $boxstat.='</a>';
632 
633  // Box outstanding bill
634  $warn = '';
635  if ($object->outstanding_limit != '' && $object->outstanding_limit < $outstandingOpened)
636  {
637  $warn = ' '.img_warning($langs->trans("OutstandingBillReached"));
638  }
639  $text=$langs->trans("CurrentOutstandingBill");
640  $link=DOL_URL_ROOT.'/compta/recap-compta.php?socid='.$object->id;
641  $icon='bill';
642  if ($link) $boxstat.='<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
643  $boxstat.='<div class="boxstats" title="'.dol_escape_htmltag($text).'">';
644  $boxstat.='<span class="boxstatstext">'.img_object("",$icon).' '.$text.'</span><br>';
645  $boxstat.='<span class="boxstatsindicator'.($outstandingOpened>0?' amountremaintopay':'').'">'.price($outstandingOpened, 1, $langs, 1, -1, -1, $conf->currency).$warn.'</span>';
646  $boxstat.='</div>';
647  if ($link) $boxstat.='</a>';
648  }
649 
650  $parameters = array();
651  $reshook = $hookmanager->executeHooks('addMoreBoxStatsCustomer', $parameters, $object, $action);
652  if(empty($reshook)){
653  $boxstat.= $hookmanager->resPrint;
654  }
655 
656  $boxstat.='</td></tr>';
657  $boxstat.='</table>';
658  $boxstat.='</div>';
659 
660  print $boxstat;
661 
662  $now=dol_now();
663 
664  /*
665  * Last proposals
666  */
667  if (! empty($conf->propal->enabled) && $user->rights->propal->lire)
668  {
669  $langs->load("propal");
670 
671  $sql = "SELECT s.nom, s.rowid, p.rowid as propalid, p.fk_statut, p.total_ht";
672  $sql.= ", p.tva as total_tva";
673  $sql.= ", p.total as total_ttc";
674  $sql.= ", p.ref, p.ref_client, p.remise";
675  $sql.= ", p.datep as dp, p.fin_validite as datelimite";
676  $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as p, ".MAIN_DB_PREFIX."c_propalst as c";
677  $sql.= " WHERE p.fk_soc = s.rowid AND p.fk_statut = c.id";
678  $sql.= " AND s.rowid = ".$object->id;
679  $sql.= " AND p.entity IN (".getEntity('propal').")";
680  $sql.= " ORDER BY p.datep DESC";
681 
682  $resql=$db->query($sql);
683  if ($resql)
684  {
685  $propal_static = new Propal($db);
686 
687  $num = $db->num_rows($resql);
688  if ($num > 0)
689  {
690  print '<div class="div-table-responsive-no-min">';
691  print '<table class="noborder" width="100%">';
692 
693  print '<tr class="liste_titre">';
694  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>';
695  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>';
696  print '</tr></table></td>';
697  print '</tr>';
698  }
699 
700  $i = 0;
701  while ($i < $num && $i < $MAXLIST)
702  {
703  $objp = $db->fetch_object($resql);
704 
705  print '<tr class="oddeven">';
706  print '<td class="nowrap">';
707  $propal_static->id = $objp->propalid;
708  $propal_static->ref = $objp->ref;
709  $propal_static->ref_client = $objp->ref_client;
710  $propal_static->total_ht = $objp->total_ht;
711  $propal_static->total_tva = $objp->total_tva;
712  $propal_static->total_ttc = $objp->total_ttc;
713  print $propal_static->getNomUrl(1);
714  if ( ($db->jdate($objp->datelimite) < ($now - $conf->propal->cloture->warning_delay)) && $objp->fk_statut == 1 ) {
715  print " ".img_warning();
716  }
717  print '</td><td align="right" width="80px">'.dol_print_date($db->jdate($objp->dp),'day')."</td>\n";
718  print '<td align="right" style="min-width: 60px">'.price($objp->total_ht).'</td>';
719  print '<td align="right" style="min-width: 60px" class="nowrap">'.$propal_static->LibStatut($objp->fk_statut,5).'</td></tr>';
720  $i++;
721  }
722  $db->free($resql);
723 
724  if ($num > 0)
725  {
726  print "</table>";
727  print '</div>';
728  }
729  }
730  else
731  {
732  dol_print_error($db);
733  }
734  }
735 
736  /*
737  * Last orders
738  */
739  if (! empty($conf->commande->enabled) && $user->rights->commande->lire)
740  {
741  $sql = "SELECT s.nom, s.rowid";
742  $sql.= ", c.rowid as cid, c.total_ht";
743  $sql.= ", c.tva as total_tva";
744  $sql.= ", c.total_ttc";
745  $sql.= ", c.ref, c.ref_client, c.fk_statut, c.facture";
746  $sql.= ", c.date_commande as dc";
747  $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande as c";
748  $sql.= " WHERE c.fk_soc = s.rowid ";
749  $sql.= " AND s.rowid = ".$object->id;
750  $sql.= " AND c.entity = ".$conf->entity;
751  $sql.= " ORDER BY c.date_commande DESC";
752 
753  $resql=$db->query($sql);
754  if ($resql)
755  {
756  $commande_static=new Commande($db);
757 
758  $num = $db->num_rows($resql);
759  if ($num > 0)
760  {
761  // Check if there are orders billable
762  $sql2 = 'SELECT s.nom, s.rowid as socid, s.client, c.rowid, c.ref, c.total_ht, c.ref_client,';
763  $sql2.= ' c.date_valid, c.date_commande, c.date_livraison, c.fk_statut, c.facture as billed';
764  $sql2.= ' FROM '.MAIN_DB_PREFIX.'societe as s';
765  $sql2.= ', '.MAIN_DB_PREFIX.'commande as c';
766  $sql2.= ' WHERE c.fk_soc = s.rowid';
767  $sql2.= ' AND s.rowid = '.$object->id;
768  // Show orders with status validated, shipping started and delivered (well any order we can bill)
769  $sql2.= " AND ((c.fk_statut IN (1,2)) OR (c.fk_statut = 3 AND c.facture = 0))";
770 
771  $resql2=$db->query($sql2);
772  $orders2invoice = $db->num_rows($resql2);
773  $db->free($resql2);
774 
775  print '<div class="div-table-responsive-no-min">';
776  print '<table class="noborder" width="100%">';
777 
778  print '<tr class="liste_titre">';
779  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>';
780  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>';
781  //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>';
782  //else print '<td width="20px" align="right"><a href="#">'.img_picto($langs->trans("NoOrdersToInvoice"),'object_bill').'</a></td>';
783  print '</tr></table></td>';
784  print '</tr>';
785  }
786 
787  $i = 0;
788  while ($i < $num && $i < $MAXLIST)
789  {
790  $objp = $db->fetch_object($resql);
791 
792  $commande_static->id = $objp->cid;
793  $commande_static->ref = $objp->ref;
794  $commande_static->ref_client=$objp->ref_client;
795  $commande_static->total_ht = $objp->total_ht;
796  $commande_static->total_tva = $objp->total_tva;
797  $commande_static->total_ttc = $objp->total_ttc;
798  $commande_static->billed = $objp->billed;
799 
800  print '<tr class="oddeven">';
801  print '<td class="nowrap">';
802  print $commande_static->getNomUrl(1);
803  print '</td><td align="right" width="80px">'.dol_print_date($db->jdate($objp->dc),'day')."</td>\n";
804  print '<td align="right" style="min-width: 60px">'.price($objp->total_ht).'</td>';
805  print '<td align="right" style="min-width: 60px" class="nowrap">'.$commande_static->LibStatut($objp->fk_statut,$objp->facture,5).'</td></tr>';
806  $i++;
807  }
808  $db->free($resql);
809 
810  if ($num >0)
811  {
812  print "</table>";
813  print '</div>';
814  }
815  }
816  else
817  {
818  dol_print_error($db);
819  }
820  }
821 
822  /*
823  * Last shipments
824  */
825  if (! empty($conf->expedition->enabled) && $user->rights->expedition->lire)
826  {
827  $sql = 'SELECT e.rowid as id';
828  $sql.= ', e.ref';
829  $sql.= ', e.date_creation';
830  $sql.= ', e.fk_statut as statut';
831  $sql.= ', s.nom';
832  $sql.= ', s.rowid as socid';
833  $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."expedition as e";
834  $sql.= " WHERE e.fk_soc = s.rowid AND s.rowid = ".$object->id;
835  $sql.= " AND e.entity IN (".getEntity('expedition').")";
836  $sql.= ' GROUP BY e.rowid';
837  $sql.= ', e.ref';
838  $sql.= ', e.date_creation';
839  $sql.= ', e.fk_statut';
840  $sql.= ', s.nom';
841  $sql.= ', s.rowid';
842  $sql.= " ORDER BY e.date_creation DESC";
843 
844  $resql = $db->query($sql);
845  if ($resql)
846  {
847  $sendingstatic = new Expedition($db);
848 
849  $num = $db->num_rows($resql);
850  if ($num > 0) {
851  print '<div class="div-table-responsive-no-min">';
852  print '<table class="noborder" width="100%">';
853 
854  print '<tr class="liste_titre">';
855  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>';
856  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>';
857  print '</tr></table></td>';
858  print '</tr>';
859  }
860 
861  $i = 0;
862  while ($i < $num && $i < $MAXLIST)
863  {
864  $objp = $db->fetch_object($resql);
865 
866  $sendingstatic->id = $objp->id;
867  $sendingstatic->ref = $objp->ref;
868 
869  print '<tr class="oddeven">';
870  print '<td class="nowrap">';
871  print $sendingstatic->getNomUrl(1);
872  print '</td>';
873  if ($objp->date_creation > 0) {
874  print '<td align="right" width="80px">'.dol_print_date($db->jdate($objp->date_creation),'day').'</td>';
875  } else {
876  print '<td align="right"><b>!!!</b></td>';
877  }
878 
879  print '<td align="right" class="nowrap" width="100" >' . $sendingstatic->LibStatut($objp->statut, 5) . '</td>';
880  print "</tr>\n";
881  $i++;
882  }
883  $db->free($resql);
884 
885  if ($num > 0)
886  {
887  print "</table>";
888  print '</div>';
889  }
890  } else {
891  dol_print_error($db);
892  }
893  }
894 
895  /*
896  * Last linked contracts
897  */
898  if (! empty($conf->contrat->enabled) && $user->rights->contrat->lire)
899  {
900  $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_customer as refcus, c.ref_supplier as refsup";
901  $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."contrat as c";
902  $sql.= " WHERE c.fk_soc = s.rowid ";
903  $sql.= " AND s.rowid = ".$object->id;
904  $sql.= " AND c.entity = ".$conf->entity;
905  $sql.= " ORDER BY c.datec DESC";
906 
907  $resql=$db->query($sql);
908  if ($resql)
909  {
910  $contrat=new Contrat($db);
911 
912  $num = $db->num_rows($resql);
913  if ($num >0)
914  {
915  print '<div class="div-table-responsive-no-min">';
916  print '<table class="noborder" width="100%">';
917 
918  print '<tr class="liste_titre">';
919  print '<td colspan="6"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("LastContracts",($num<=$MAXLIST?"":$MAXLIST)).'</td>';
920  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>';
921  //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>';
922  print '</tr></table></td>';
923  print '</tr>';
924  }
925 
926  $i = 0;
927  while ($i < $num && $i < $MAXLIST)
928  {
929  $objp = $db->fetch_object($resql);
930 
931  $contrat->id=$objp->id;
932  $contrat->ref=$objp->ref?$objp->ref:$objp->id;
933  $contrat->ref_customer=$objp->refcus;
934  $contrat->ref_supplier=$objp->refsup;
935  $contrat->fetch_lines();
936 
937  print '<tr class="oddeven">';
938  print '<td class="nowrap">';
939  print $contrat->getNomUrl(1,12);
940  print "</td>\n";
941  print '<td class="nowrap">'.dol_trunc($objp->refsup,12)."</td>\n";
942  print '<td align="right" width="80px">'.dol_print_date($db->jdate($objp->dc),'day')."</td>\n";
943  print '<td align="right" width="80px">'.dol_print_date($db->jdate($objp->dcon),'day')."</td>\n";
944  print '<td width="20">&nbsp;</td>';
945  print '<td align="right" class="nowraponall">';
946  print $contrat->getLibStatut(4);
947  print "</td>\n";
948  print '</tr>';
949  $i++;
950  }
951  $db->free($resql);
952 
953  if ($num > 0)
954  {
955  print "</table>";
956  print '</div>';
957  }
958  }
959  else
960  {
961  dol_print_error($db);
962  }
963  }
964 
965  /*
966  * Last interventions
967  */
968  if (! empty($conf->ficheinter->enabled) && $user->rights->ficheinter->lire)
969  {
970  $sql = "SELECT s.nom, s.rowid, f.rowid as id, f.ref, f.fk_statut, f.duree as duration, f.datei as startdate";
971  $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."fichinter as f";
972  $sql.= " WHERE f.fk_soc = s.rowid";
973  $sql.= " AND s.rowid = ".$object->id;
974  $sql.= " AND f.entity = ".$conf->entity;
975  $sql.= " ORDER BY f.tms DESC";
976 
977  $resql=$db->query($sql);
978  if ($resql)
979  {
980  $fichinter_static=new Fichinter($db);
981 
982  $num = $db->num_rows($resql);
983  if ($num > 0)
984  {
985  print '<div class="div-table-responsive-no-min">';
986  print '<table class="noborder" width="100%">';
987 
988  print '<tr class="liste_titre">';
989  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>';
990  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>';
991  print '</tr></table></td>';
992  print '</tr>';
993  }
994 
995  $i = 0;
996  while ($i < $num && $i < $MAXLIST)
997  {
998  $objp = $db->fetch_object($resql);
999 
1000  $fichinter_static->id=$objp->id;
1001  $fichinter_static->statut=$objp->fk_statut;
1002 
1003  print '<tr class="oddeven">';
1004  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";
1005  //print '<td align="right" width="80px">'.dol_print_date($db->jdate($objp->startdate)).'</td>'."\n";
1006  print '<td align="right" style="min-width: 60px">'.convertSecondToTime($objp->duration).'</td>'."\n";
1007  print '<td align="right" class="nowrap" style="min-width: 60px">'.$fichinter_static->getLibStatut(5).'</td>'."\n";
1008  print '</tr>';
1009 
1010  $i++;
1011  }
1012  $db->free($resql);
1013 
1014  if ($num > 0)
1015  {
1016  print "</table>";
1017  print '</div>';
1018  }
1019  }
1020  else
1021  {
1022  dol_print_error($db);
1023  }
1024  }
1025 
1026  /*
1027  * Last invoices templates
1028  */
1029  if (! empty($conf->facture->enabled) && $user->rights->facture->lire)
1030  {
1031  $sql = 'SELECT f.rowid as id, f.titre as ref, f.amount';
1032  $sql.= ', f.total as total_ht';
1033  $sql.= ', f.tva as total_tva';
1034  $sql.= ', f.total_ttc';
1035  $sql.= ', f.datec as dc';
1036  $sql.= ', f.date_last_gen, f.date_when';
1037  $sql.= ', f.frequency';
1038  $sql.= ', f.unit_frequency';
1039  $sql.= ', f.suspended as suspended';
1040  $sql.= ', s.nom, s.rowid as socid';
1041  $sql.= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture_rec as f";
1042  $sql.= " WHERE f.fk_soc = s.rowid AND s.rowid = ".$object->id;
1043  $sql.= " AND f.entity = ".$conf->entity;
1044  $sql.= ' GROUP BY f.rowid, f.titre, f.amount, f.total, f.tva, f.total_ttc,';
1045  $sql.= ' f.date_last_gen, f.datec, f.frequency, f.unit_frequency,';
1046  $sql.= ' f.suspended,';
1047  $sql.= ' s.nom, s.rowid';
1048  $sql.= " ORDER BY f.date_last_gen, f.datec DESC";
1049 
1050  $resql=$db->query($sql);
1051  if ($resql)
1052  {
1053  $invoicetemplate = new FactureRec($db);
1054 
1055  $num = $db->num_rows($resql);
1056  if ($num > 0)
1057  {
1058  print '<div class="div-table-responsive-no-min">';
1059  print '<table class="noborder" width="100%">';
1060 
1061  print '<tr class="liste_titre">';
1062  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>';
1063  print '</tr></table></td>';
1064  print '</tr>';
1065  }
1066 
1067  $i = 0;
1068  while ($i < $num && $i < $MAXLIST)
1069  {
1070  $objp = $db->fetch_object($resql);
1071 
1072  $invoicetemplate->id = $objp->id;
1073  $invoicetemplate->ref = $objp->ref;
1074  $invoicetemplate->suspended = $objp->suspended;
1075  $invoicetemplate->frequency = $objp->frequency;
1076  $invoicetemplate->unit_frequency = $objp->unit_frequency;
1077  $invoicetemplate->total_ht = $objp->total_ht;
1078  $invoicetemplate->total_tva = $objp->total_tva;
1079  $invoicetemplate->total_ttc = $objp->total_ttc;
1080  $invoicetemplate->date_last_gen = $objp->date_last_gen;
1081  $invoicetemplate->date_when = $objp->date_when;
1082 
1083  print '<tr class="oddeven">';
1084  print '<td class="nowrap">';
1085  print $invoicetemplate->getNomUrl(1);
1086  print '</td>';
1087  if ($objp->frequency && $objp->date_last_gen > 0)
1088  {
1089  print '<td align="right" width="80px">'.dol_print_date($db->jdate($objp->date_last_gen),'day').'</td>';
1090  }
1091  else
1092  {
1093  if ($objp->dc > 0)
1094  {
1095  print '<td align="right" width="80px">'.dol_print_date($db->jdate($objp->dc),'day').'</td>';
1096  }
1097  else
1098  {
1099  print '<td align="right"><b>!!!</b></td>';
1100  }
1101  }
1102  print '<td align="right" style="min-width: 60px">';
1103  print price($objp->total_ht);
1104  print '</td>';
1105 
1106  if (! empty($conf->global->MAIN_SHOW_PRICE_WITH_TAX_IN_SUMMARIES))
1107  {
1108  print '<td align="right" style="min-width: 60px">';
1109  print price($objp->total_ttc);
1110  print '</td>';
1111  }
1112 
1113  print '<td align="right" class="nowrap" style="min-width: 60px">';
1114  print $langs->trans('FrequencyPer_'.$invoicetemplate->unit_frequency, $invoicetemplate->frequency).' - ';
1115  print ($invoicetemplate->LibStatut($invoicetemplate->frequency,$invoicetemplate->suspended,5,0));
1116  print '</td>';
1117  print "</tr>\n";
1118  $i++;
1119  }
1120  $db->free($resql);
1121 
1122  if ($num > 0)
1123  {
1124  print "</table>";
1125  print '</div>';
1126  }
1127  }
1128  else
1129  {
1130  dol_print_error($db);
1131  }
1132  }
1133 
1134  /*
1135  * Last invoices
1136  */
1137  if (! empty($conf->facture->enabled) && $user->rights->facture->lire)
1138  {
1139  $sql = 'SELECT f.rowid as facid, f.facnumber, f.type, f.amount';
1140  $sql.= ', f.total as total_ht';
1141  $sql.= ', f.tva as total_tva';
1142  $sql.= ', f.total_ttc';
1143  $sql.= ', f.datef as df, f.datec as dc, f.paye as paye, f.fk_statut as statut';
1144  $sql.= ', s.nom, s.rowid as socid';
1145  $sql.= ', SUM(pf.amount) as am';
1146  $sql.= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f";
1147  $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON f.rowid=pf.fk_facture';
1148  $sql.= " WHERE f.fk_soc = s.rowid AND s.rowid = ".$object->id;
1149  $sql.= " AND f.entity = ".$conf->entity;
1150  $sql.= ' GROUP BY f.rowid, f.facnumber, f.type, f.amount, f.total, f.tva, f.total_ttc,';
1151  $sql.= ' f.datef, f.datec, f.paye, f.fk_statut,';
1152  $sql.= ' s.nom, s.rowid';
1153  $sql.= " ORDER BY f.datef DESC, f.datec DESC";
1154 
1155  $resql=$db->query($sql);
1156  if ($resql)
1157  {
1158  $facturestatic = new Facture($db);
1159 
1160  $num = $db->num_rows($resql);
1161  if ($num > 0)
1162  {
1163  print '<div class="div-table-responsive-no-min">';
1164  print '<table class="noborder" width="100%">';
1165 
1166  print '<tr class="liste_titre">';
1167  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>';
1168  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>';
1169  print '</tr></table></td>';
1170  print '</tr>';
1171  }
1172 
1173  $i = 0;
1174  while ($i < $num && $i < $MAXLIST)
1175  {
1176  $objp = $db->fetch_object($resql);
1177 
1178  $facturestatic->id = $objp->facid;
1179  $facturestatic->ref = $objp->facnumber;
1180  $facturestatic->type = $objp->type;
1181  $facturestatic->total_ht = $objp->total_ht;
1182  $facturestatic->total_tva = $objp->total_tva;
1183  $facturestatic->total_ttc = $objp->total_ttc;
1184 
1185  print '<tr class="oddeven">';
1186  print '<td class="nowrap">';
1187  print $facturestatic->getNomUrl(1);
1188  print '</td>';
1189  if ($objp->df > 0)
1190  {
1191  print '<td align="right" width="80px">'.dol_print_date($db->jdate($objp->df),'day').'</td>';
1192  }
1193  else
1194  {
1195  print '<td align="right"><b>!!!</b></td>';
1196  }
1197  print '<td align="right" style="min-width: 60px">';
1198  print price($objp->total_ht);
1199  print '</td>';
1200 
1201  if (! empty($conf->global->MAIN_SHOW_PRICE_WITH_TAX_IN_SUMMARIES))
1202  {
1203  print '<td align="right" style="min-width: 60px">';
1204  print price($objp->total_ttc);
1205  print '</td>';
1206  }
1207 
1208  print '<td align="right" class="nowrap" style="min-width: 60px">'.($facturestatic->LibStatut($objp->paye,$objp->statut,5,$objp->am)).'</td>';
1209  print "</tr>\n";
1210  $i++;
1211  }
1212  $db->free($resql);
1213 
1214  if ($num > 0)
1215  {
1216  print "</table>";
1217  print '</div>';
1218  }
1219  }
1220  else
1221  {
1222  dol_print_error($db);
1223  }
1224  }
1225 
1226  print '</div></div></div>';
1227  print '<div style="clear:both"></div>';
1228 
1229  dol_fiche_end();
1230 
1231 
1232  /*
1233  * Barre d'actions
1234  */
1235 
1236  print '<div class="tabsAction">';
1237 
1238  $parameters = array();
1239  $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
1240 
1241  if (empty($reshook))
1242  {
1243  if ($object->status != 1)
1244  {
1245  print '<div class="inline-block divButAction"><a class="butActionRefused" title="'.dol_escape_js($langs->trans("ThirdPartyIsClosed")).'" href="#">'.$langs->trans("ThirdPartyIsClosed").'</a></div>';
1246  }
1247 
1248  if (! empty($conf->propal->enabled) && $user->rights->propal->creer && $object->status==1)
1249  {
1250  $langs->load("propal");
1251  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>';
1252  }
1253 
1254  if (! empty($conf->commande->enabled) && $user->rights->commande->creer && $object->status==1)
1255  {
1256  $langs->load("orders");
1257  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>';
1258  }
1259 
1260  if ($user->rights->contrat->creer && $object->status==1)
1261  {
1262  $langs->load("contracts");
1263  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>';
1264  }
1265 
1266  if (! empty($conf->ficheinter->enabled) && $user->rights->ficheinter->creer && $object->status==1)
1267  {
1268  $langs->load("fichinter");
1269  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>';
1270  }
1271 
1272  // Add invoice
1273  if ($user->societe_id == 0)
1274  {
1275  if (! empty($conf->deplacement->enabled) && $object->status==1)
1276  {
1277  $langs->load("trips");
1278  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>';
1279  }
1280 
1281  if (! empty($conf->facture->enabled) && $object->status==1)
1282  {
1283  if (empty($user->rights->facture->creer))
1284  {
1285  print '<div class="inline-block divButAction"><a class="butActionRefused" title="'.dol_escape_js($langs->trans("NotAllowed")).'" href="#">'.$langs->trans("AddBill").'</a></div>';
1286  }
1287  else
1288  {
1289  $langs->load("bills");
1290  $langs->load("orders");
1291 
1292  if (! empty($conf->commande->enabled))
1293  {
1294  if ($object->client != 0 && $object->client != 2)
1295  {
1296  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>';
1297  else print '<div class="inline-block divButAction"><a class="butActionRefused" title="'.dol_escape_js($langs->trans("NoOrdersToInvoice")).'" href="#">'.$langs->trans("CreateInvoiceForThisCustomer").'</a></div>';
1298  }
1299  else print '<div class="inline-block divButAction"><a class="butActionRefused" title="'.dol_escape_js($langs->trans("ThirdPartyMustBeEditAsCustomer")).'" href="#">'.$langs->trans("AddBill").'</a></div>';
1300  }
1301 
1302  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>';
1303  else print '<div class="inline-block divButAction"><a class="butActionRefused" title="'.dol_escape_js($langs->trans("ThirdPartyMustBeEditAsCustomer")).'" href="#">'.$langs->trans("AddBill").'</a></div>';
1304  }
1305  }
1306  }
1307 
1308  // Add action
1309  if (! empty($conf->agenda->enabled) && ! empty($conf->global->MAIN_REPEATTASKONEACHTAB) && $object->status==1)
1310  {
1311  if ($user->rights->agenda->myactions->create)
1312  {
1313  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>';
1314  }
1315  else
1316  {
1317  print '<div class="inline-block divButAction"><a class="butAction" title="'.dol_escape_js($langs->trans("NotAllowed")).'" href="#">'.$langs->trans("AddAction").'</a></div>';
1318  }
1319  }
1320  }
1321 
1322  print '</div>';
1323 
1324  if (! empty($conf->global->MAIN_DUPLICATE_CONTACTS_TAB_ON_CUSTOMER_CARD))
1325  {
1326  // List of contacts
1327  show_contacts($conf,$langs,$db,$object,$_SERVER["PHP_SELF"].'?socid='.$object->id);
1328  }
1329 
1330  // Addresses list
1331  if (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) && ! empty($conf->global->MAIN_REPEATADDRESSONEACHTAB))
1332  {
1333  show_addresses($conf,$langs,$db,$object,$_SERVER["PHP_SELF"].'?socid='.$object->id);
1334  }
1335 
1336  if (! empty($conf->global->MAIN_REPEATTASKONEACHTAB))
1337  {
1338  print load_fiche_titre($langs->trans("ActionsOnCompany"),'','');
1339 
1340  // List of todo actions
1341  show_actions_todo($conf,$langs,$db,$object);
1342 
1343  // List of done actions
1344  show_actions_done($conf,$langs,$db,$object);
1345  }
1346 }
1347 else
1348 {
1349  $langs->load("errors");
1350  print $langs->trans('ErrorRecordNotFound');
1351 }
1352 
1353 // End of page
1354 llxFooter();
1355 $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.
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 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:41
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.
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 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.
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.
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
dol_now($mode='gmt')
Return date for now.
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
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...
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.
Class to manage invoices.
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.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Class to manage proposals.
$parameters
Actions.
Definition: card.php:114