contact.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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) 2017 Ferran Marcet <fmarcet@2byte.es>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/contrat/contact.php
  22. * \ingroup contrat
  23. * \brief Onglet de gestion des contacts des contrats
  24. */
  25. // Load Dolibarr environment
  26. require '../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/contract.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  31. if (isModEnabled('project')) {
  32. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  33. }
  34. // Load translation files required by the page
  35. $langs->loadLangs(array('contracts', 'companies'));
  36. $action = GETPOST('action', 'aZ09');
  37. $confirm = GETPOST('confirm', 'alpha');
  38. $socid = GETPOST('socid', 'int');
  39. $id = GETPOST('id', 'int');
  40. $ref = GETPOST('ref', 'alpha');
  41. // Security check
  42. if ($user->socid) {
  43. $socid = $user->socid;
  44. }
  45. $result = restrictedArea($user, 'contrat', $id);
  46. $object = new Contrat($db);
  47. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  48. $hookmanager->initHooks(array('contractcard', 'globalcard'));
  49. $permissiontoadd = $user->hasRight('contrat', 'creer'); // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
  50. /*
  51. * Actions
  52. */
  53. if ($action == 'addcontact' && $user->hasRight('contrat', 'creer')) {
  54. $result = $object->fetch($id);
  55. if ($result > 0 && $id > 0) {
  56. $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));
  57. $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
  58. $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
  59. }
  60. if ($result >= 0) {
  61. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  62. exit;
  63. } else {
  64. if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
  65. $langs->load("errors");
  66. $msg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");
  67. } else {
  68. $mesg = $object->error;
  69. }
  70. setEventMessages($mesg, null, 'errors');
  71. }
  72. }
  73. // bascule du statut d'un contact
  74. if ($action == 'swapstatut' && $user->hasRight('contrat', 'creer')) {
  75. if ($object->fetch($id)) {
  76. $result = $object->swapContactStatus(GETPOST('ligne', 'int'));
  77. } else {
  78. dol_print_error($db, $object->error);
  79. }
  80. }
  81. // Delete contact
  82. if ($action == 'deletecontact' && $user->hasRight('contrat', 'creer')) {
  83. $object->fetch($id);
  84. $result = $object->delete_contact(GETPOST("lineid", 'int'));
  85. if ($result >= 0) {
  86. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  87. exit;
  88. }
  89. }
  90. /*
  91. * View
  92. */
  93. llxHeader('', $langs->trans("Contract"), "");
  94. $form = new Form($db);
  95. $formcompany = new FormCompany($db);
  96. $contactstatic = new Contact($db);
  97. $userstatic = new User($db);
  98. /* *************************************************************************** */
  99. /* */
  100. /* Mode vue et edition */
  101. /* */
  102. /* *************************************************************************** */
  103. if ($id > 0 || !empty($ref)) {
  104. if ($object->fetch($id, $ref) > 0) {
  105. $object->fetch_thirdparty();
  106. $head = contract_prepare_head($object);
  107. $hselected = 1;
  108. print dol_get_fiche_head($head, $hselected, $langs->trans("Contract"), -1, 'contract');
  109. // Contract card
  110. $linkback = '<a href="'.DOL_URL_ROOT.'/contrat/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  111. $morehtmlref = '';
  112. //if (!empty($modCodeContract->code_auto)) {
  113. $morehtmlref .= $object->ref;
  114. /*} else {
  115. $morehtmlref.=$form->editfieldkey("",'ref',$object->ref,0,'string','',0,3);
  116. $morehtmlref.=$form->editfieldval("",'ref',$object->ref,0,'string','',0,2);
  117. }*/
  118. $morehtmlref .= '<div class="refidno">';
  119. // Ref customer
  120. $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_customer', $object->ref_customer, $object, 0, 'string', '', 0, 1);
  121. $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_customer', $object->ref_customer, $object, 0, 'string', '', null, null, '', 1, 'getFormatedCustomerRef');
  122. // Ref supplier
  123. $morehtmlref .= '<br>';
  124. $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1);
  125. $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1, 'getFormatedSupplierRef');
  126. // Thirdparty
  127. $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1);
  128. // Project
  129. if (isModEnabled('project')) {
  130. $langs->load("projects");
  131. $morehtmlref .= '<br>';
  132. if (0) {
  133. $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
  134. if ($action != 'classify') {
  135. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
  136. }
  137. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
  138. } else {
  139. if (!empty($object->fk_project)) {
  140. $proj = new Project($db);
  141. $proj->fetch($object->fk_project);
  142. $morehtmlref .= $proj->getNomUrl(1);
  143. if ($proj->title) {
  144. $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
  145. }
  146. }
  147. }
  148. }
  149. $morehtmlref .= '</div>';
  150. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'none', $morehtmlref);
  151. print '<div class="fichecenter">';
  152. print '<div class="underbanner clearboth"></div>';
  153. print '<table class="border tableforfield" width="100%">';
  154. // Ligne info remises tiers
  155. print '<tr><td class="titlefield">'.$langs->trans('Discount').'</td><td colspan="3">';
  156. if ($object->thirdparty->remise_percent) {
  157. print $langs->trans("CompanyHasRelativeDiscount", $object->thirdparty->remise_percent);
  158. } else {
  159. print $langs->trans("CompanyHasNoRelativeDiscount");
  160. }
  161. $absolute_discount = $object->thirdparty->getAvailableDiscounts();
  162. print '. ';
  163. if ($absolute_discount) {
  164. print $langs->trans("CompanyHasAbsoluteDiscount", price($absolute_discount), $langs->trans("Currency".$conf->currency));
  165. } else {
  166. print $langs->trans("CompanyHasNoAbsoluteDiscount");
  167. }
  168. print '.';
  169. print '</td></tr>';
  170. // Date
  171. print '<tr>';
  172. print '<td class="titlefield">';
  173. print $form->editfieldkey("Date", 'date_contrat', $object->date_contrat, $object, 0);
  174. print '</td><td>';
  175. print $form->editfieldval("Date", 'date_contrat', $object->date_contrat, $object, 0, 'datehourpicker');
  176. print '</td>';
  177. print '</tr>';
  178. print "</table>";
  179. print '</div>';
  180. print dol_get_fiche_end();
  181. print '<br>';
  182. // Contacts lines
  183. include DOL_DOCUMENT_ROOT.'/core/tpl/contacts.tpl.php';
  184. } else {
  185. print "ErrorRecordNotFound";
  186. }
  187. }
  188. llxFooter();
  189. $db->close();