dolibarr  16.0.5
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 require '../../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
34 if (isModEnabled('project')) {
35  require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
36 }
37 
38 // Load translation files required by the page
39 $langs->loadLangs(array('bills', 'companies'));
40 
41 $id = (GETPOST('id') ?GETPOST('id', 'int') : GETPOST('facid', 'int')); // For backward compatibility
42 $ref = GETPOST('ref', 'alpha');
43 $lineid = GETPOST('lineid', 'int');
44 $socid = GETPOST('socid', 'int');
45 $action = GETPOST('action', 'aZ09');
46 
47 // Security check
48 if ($user->socid) {
49  $socid = $user->socid;
50 }
51 
52 $object = new Facture($db);
53 // Load object
54 if ($id > 0 || !empty($ref)) {
55  $ret = $object->fetch($id, $ref, '', '', (!empty($conf->global->INVOICE_USE_SITUATION) ? $conf->global->INVOICE_USE_SITUATION : 0));
56 }
57 
58 $result = restrictedArea($user, 'facture', $object->id);
59 
60 
61 /*
62  * Add a new contact
63  */
64 
65 if ($action == 'addcontact' && $user->rights->facture->creer) {
66  if ($result > 0 && $id > 0) {
67  $contactid = (GETPOST('userid') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
68  $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
69  $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
70  }
71 
72  if ($result >= 0) {
73  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
74  exit;
75  } else {
76  if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
77  $langs->load("errors");
78  setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
79  } else {
80  setEventMessages($object->error, $object->errors, 'errors');
81  }
82  }
83 } elseif ($action == 'swapstatut' && $user->rights->facture->creer) {
84  // Toggle the status of a contact
85  $result = $object->swapContactStatus(GETPOST('ligne', 'int'));
86 } elseif ($action == 'deletecontact' && $user->rights->facture->creer) {
87  // Deletes a contact
88  $result = $object->delete_contact($lineid);
89 
90  if ($result >= 0) {
91  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
92  exit;
93  } else {
94  dol_print_error($db);
95  }
96 }
97 
98 
99 /*
100  * View
101  */
102 
103 $title = $langs->trans('InvoiceCustomer')." - ".$langs->trans('ContactsAddresses');
104 $helpurl = "EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes";
105 llxHeader('', $title, $helpurl);
106 
107 $form = new Form($db);
108 $formcompany = new FormCompany($db);
109 $contactstatic = new Contact($db);
110 $userstatic = new User($db);
111 
112 
113 /* *************************************************************************** */
114 /* */
115 /* View and edit mode */
116 /* */
117 /* *************************************************************************** */
118 
119 if ($id > 0 || !empty($ref)) {
120  if ($object->fetch($id, $ref) > 0) {
121  $object->fetch_thirdparty();
122 
123  $head = facture_prepare_head($object);
124 
125  $totalpaid = $object->getSommePaiement();
126 
127  print dol_get_fiche_head($head, 'contact', $langs->trans('InvoiceCustomer'), -1, 'bill');
128 
129  // Invoice content
130 
131  $linkback = '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
132 
133  $morehtmlref = '<div class="refidno">';
134  // Ref customer
135  $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
136  $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
137  // Thirdparty
138  $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1, 'customer');
139  // Project
140  if (isModEnabled('project')) {
141  $langs->load("projects");
142  $morehtmlref .= '<br>'.$langs->trans('Project').' ';
143  if ($user->rights->facture->creer) {
144  if ($action != 'classify') {
145  //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
146  $morehtmlref .= ' : ';
147  }
148  if ($action == 'classify') {
149  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
150  $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
151  $morehtmlref .= '<input type="hidden" name="action" value="classin">';
152  $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
153  $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
154  $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
155  $morehtmlref .= '</form>';
156  } else {
157  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
158  }
159  } else {
160  if (!empty($object->fk_project)) {
161  $proj = new Project($db);
162  $proj->fetch($object->fk_project);
163  $morehtmlref .= ' : '.$proj->getNomUrl(1);
164  if ($proj->title) {
165  $morehtmlref .= ' - '.$proj->title;
166  }
167  } else {
168  $morehtmlref .= '';
169  }
170  }
171  }
172  $morehtmlref .= '</div>';
173 
174  $object->totalpaid = $totalpaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status
175 
176  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
177 
178  print dol_get_fiche_end();
179 
180  //print '<br>';
181 
182  // Contacts lines (modules that overwrite templates must declare this into descriptor)
183  $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
184  foreach ($dirtpls as $reldir) {
185  $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
186  if ($res) {
187  break;
188  }
189  }
190  } else {
191  // Record not found
192  print "ErrorRecordNotFound";
193  }
194 }
195 
196 // End of page
197 llxFooter();
198 $db->close();
restrictedArea
restrictedArea($user, $features, $objectid=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:234
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
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:484
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:4844
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1062
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:142
Facture
Class to manage invoices.
Definition: facture.class.php:60
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:2046
FormCompany
Class to build HTML component for third parties management Only common components are here.
Definition: html.formcompany.class.php:40
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:1822
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:105
User
Class to manage Dolibarr users.
Definition: user.class.php:44
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59