dolibarr  17.0.3
contact.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2005 Patrick Rouillon <patrick@rouillon.net>
3  * Copyright (C) 2005-2009 Destailleur Laurent <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2011-2015 Philippe Grand <philippe.grand@atoo-net.com>
6  * Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
28 // Load Dolibarr environment
29 require '../../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
35 if (isModEnabled('project')) {
36  require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
37 }
38 
39 // Load translation files required by the page
40 $langs->loadLangs(array('bills', 'companies'));
41 
42 $id = (GETPOST('id') ?GETPOST('id', 'int') : GETPOST('facid', 'int')); // For backward compatibility
43 $ref = GETPOST('ref', 'alpha');
44 $lineid = GETPOST('lineid', 'int');
45 $socid = GETPOST('socid', 'int');
46 $action = GETPOST('action', 'aZ09');
47 
48 // Security check
49 if ($user->socid) {
50  $socid = $user->socid;
51 }
52 
53 $object = new Facture($db);
54 // Load object
55 if ($id > 0 || !empty($ref)) {
56  $ret = $object->fetch($id, $ref, '', '', (!empty($conf->global->INVOICE_USE_SITUATION) ? $conf->global->INVOICE_USE_SITUATION : 0));
57 }
58 
59 $result = restrictedArea($user, 'facture', $object->id);
60 
61 $usercancreate = $user->hasRight("facture", "creer");
62 
63 
64 /*
65  * Add a new contact
66  */
67 
68 if ($action == 'addcontact' && $user->rights->facture->creer) {
69  if ($result > 0 && $id > 0) {
70  $contactid = (GETPOST('userid') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
71  $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
72  $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
73  }
74 
75  if ($result >= 0) {
76  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
77  exit;
78  } else {
79  if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
80  $langs->load("errors");
81  setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
82  } else {
83  setEventMessages($object->error, $object->errors, 'errors');
84  }
85  }
86 } elseif ($action == 'swapstatut' && $user->rights->facture->creer) {
87  // Toggle the status of a contact
88  $result = $object->swapContactStatus(GETPOST('ligne', 'int'));
89 } elseif ($action == 'deletecontact' && $user->rights->facture->creer) {
90  // Deletes a contact
91  $result = $object->delete_contact($lineid);
92 
93  if ($result >= 0) {
94  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
95  exit;
96  } else {
97  dol_print_error($db);
98  }
99 }
100 
101 
102 /*
103  * View
104  */
105 
106 $title = $object->ref." - ".$langs->trans('ContactsAddresses');
107 $helpurl = "EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes";
108 llxHeader('', $title, $helpurl);
109 
110 $form = new Form($db);
111 $formcompany = new FormCompany($db);
112 $contactstatic = new Contact($db);
113 $userstatic = new User($db);
114 
115 
116 /* *************************************************************************** */
117 /* */
118 /* View and edit mode */
119 /* */
120 /* *************************************************************************** */
121 
122 if ($id > 0 || !empty($ref)) {
123  if ($object->fetch($id, $ref) > 0) {
124  $object->fetch_thirdparty();
125 
126  $head = facture_prepare_head($object);
127 
128  $totalpaid = $object->getSommePaiement();
129 
130  print dol_get_fiche_head($head, 'contact', $langs->trans('InvoiceCustomer'), -1, 'bill');
131 
132  // Invoice content
133 
134  $linkback = '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
135 
136  $morehtmlref = '<div class="refidno">';
137  // Ref customer
138  $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
139  $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
140  // Thirdparty
141  $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1, 'customer');
142  // Project
143  if (isModEnabled('project')) {
144  $langs->load("projects");
145  $morehtmlref .= '<br>';
146  if (0) {
147  $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
148  if ($action != 'classify') {
149  $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
150  }
151  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
152  } else {
153  if (!empty($object->fk_project)) {
154  $proj = new Project($db);
155  $proj->fetch($object->fk_project);
156  $morehtmlref .= $proj->getNomUrl(1);
157  if ($proj->title) {
158  $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
159  }
160  }
161  }
162  }
163  $morehtmlref .= '</div>';
164 
165  $object->totalpaid = $totalpaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status
166 
167  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
168 
169  print dol_get_fiche_end();
170 
171  //print '<br>';
172 
173  // Contacts lines (modules that overwrite templates must declare this into descriptor)
174  $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
175  foreach ($dirtpls as $reldir) {
176  $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
177  if ($res) {
178  break;
179  }
180  }
181  } else {
182  // Record not found
183  print "ErrorRecordNotFound";
184  }
185 }
186 
187 // End of page
188 llxFooter();
189 $db->close();
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:70
Project
Class to manage projects.
Definition: project.class.php:35
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:520
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4993
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1061
facture_prepare_head
facture_prepare_head($object)
Initialize the array of tabs for customer invoice.
Definition: invoice.lib.php:36
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
Facture
Class to manage invoices.
Definition: facture.class.php:60
img_edit
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
Definition: functions.lib.php:4538
dol_banner_tab
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.
Definition: functions.lib.php:2082
FormCompany
Class to build HTML component for third parties management Only common components are here.
Definition: html.formcompany.class.php:40
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:4024
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
Contact
Class to manage contact/addresses.
Definition: contact.class.php:40
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1858
restrictedArea
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
Definition: security.lib.php:346
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:11290
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2054
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:137
User
Class to manage Dolibarr users.
Definition: user.class.php:46
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:53
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8465