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