contact.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. require '../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/contract.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  30. if (!empty($conf->project->enabled)) {
  31. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  32. }
  33. // Load translation files required by the page
  34. $langs->loadLangs(array('contracts', 'companies'));
  35. $action = GETPOST('action', 'aZ09');
  36. $confirm = GETPOST('confirm', 'alpha');
  37. $socid = GETPOST('socid', 'int');
  38. $id = GETPOST('id', 'int');
  39. $ref = GETPOST('ref', 'alpha');
  40. // Security check
  41. if ($user->socid) {
  42. $socid = $user->socid;
  43. }
  44. $result = restrictedArea($user, 'contrat', $id);
  45. $object = new Contrat($db);
  46. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  47. $hookmanager->initHooks(array('contractcard', 'globalcard'));
  48. /*
  49. * Actions
  50. */
  51. if ($action == 'addcontact' && $user->rights->contrat->creer) {
  52. $result = $object->fetch($id);
  53. if ($result > 0 && $id > 0) {
  54. $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));
  55. $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
  56. $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
  57. }
  58. if ($result >= 0) {
  59. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  60. exit;
  61. } else {
  62. if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
  63. $langs->load("errors");
  64. $msg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");
  65. } else {
  66. $mesg = $object->error;
  67. }
  68. setEventMessages($mesg, null, 'errors');
  69. }
  70. }
  71. // bascule du statut d'un contact
  72. if ($action == 'swapstatut' && $user->rights->contrat->creer) {
  73. if ($object->fetch($id)) {
  74. $result = $object->swapContactStatus(GETPOST('ligne', 'int'));
  75. } else {
  76. dol_print_error($db, $object->error);
  77. }
  78. }
  79. // Delete contact
  80. if ($action == 'deletecontact' && $user->rights->contrat->creer) {
  81. $object->fetch($id);
  82. $result = $object->delete_contact(GETPOST("lineid", 'int'));
  83. if ($result >= 0) {
  84. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  85. exit;
  86. }
  87. }
  88. /*
  89. * View
  90. */
  91. llxHeader('', $langs->trans("Contract"), "");
  92. $form = new Form($db);
  93. $formcompany = new FormCompany($db);
  94. $contactstatic = new Contact($db);
  95. $userstatic = new User($db);
  96. /* *************************************************************************** */
  97. /* */
  98. /* Mode vue et edition */
  99. /* */
  100. /* *************************************************************************** */
  101. if ($id > 0 || !empty($ref)) {
  102. if ($object->fetch($id, $ref) > 0) {
  103. $object->fetch_thirdparty();
  104. $head = contract_prepare_head($object);
  105. $hselected = 1;
  106. print dol_get_fiche_head($head, $hselected, $langs->trans("Contract"), -1, 'contract');
  107. // Contract card
  108. $linkback = '<a href="'.DOL_URL_ROOT.'/contrat/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  109. $morehtmlref = '';
  110. //if (! empty($modCodeContract->code_auto)) {
  111. $morehtmlref .= $object->ref;
  112. /*} else {
  113. $morehtmlref.=$form->editfieldkey("",'ref',$object->ref,0,'string','',0,3);
  114. $morehtmlref.=$form->editfieldval("",'ref',$object->ref,0,'string','',0,2);
  115. }*/
  116. $morehtmlref .= '<div class="refidno">';
  117. // Ref customer
  118. $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_customer', $object->ref_customer, $object, 0, 'string', '', 0, 1);
  119. $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_customer', $object->ref_customer, $object, 0, 'string', '', null, null, '', 1, 'getFormatedCustomerRef');
  120. // Ref supplier
  121. $morehtmlref .= '<br>';
  122. $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1);
  123. $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1, 'getFormatedSupplierRef');
  124. // Thirdparty
  125. $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
  126. // Project
  127. if (!empty($conf->project->enabled)) {
  128. $langs->load("projects");
  129. $morehtmlref .= '<br>'.$langs->trans('Project').' ';
  130. if ($user->rights->contrat->creer) {
  131. if ($action != 'classify') {
  132. //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
  133. $morehtmlref .= ' : ';
  134. }
  135. if ($action == 'classify') {
  136. //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  137. $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  138. $morehtmlref .= '<input type="hidden" name="action" value="classin">';
  139. $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
  140. $morehtmlref .= $formproject->select_projects($object->thirdparty->id, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
  141. $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  142. $morehtmlref .= '</form>';
  143. } else {
  144. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->thirdparty->id, $object->fk_project, 'none', 0, 0, 0, 1);
  145. }
  146. } else {
  147. if (!empty($object->fk_project)) {
  148. $proj = new Project($db);
  149. $proj->fetch($object->fk_project);
  150. $morehtmlref .= ' : '.$proj->getNomUrl(1);
  151. if ($proj->title) {
  152. $morehtmlref .= ' - '.$proj->title;
  153. }
  154. } else {
  155. $morehtmlref .= '';
  156. }
  157. }
  158. }
  159. $morehtmlref .= '</div>';
  160. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'none', $morehtmlref);
  161. print '<div class="fichecenter">';
  162. print '<div class="underbanner clearboth"></div>';
  163. print '<table class="border tableforfield" width="100%">';
  164. // Ligne info remises tiers
  165. print '<tr><td class="titlefield">'.$langs->trans('Discount').'</td><td colspan="3">';
  166. if ($object->thirdparty->remise_percent) {
  167. print $langs->trans("CompanyHasRelativeDiscount", $object->thirdparty->remise_percent);
  168. } else {
  169. print $langs->trans("CompanyHasNoRelativeDiscount");
  170. }
  171. $absolute_discount = $object->thirdparty->getAvailableDiscounts();
  172. print '. ';
  173. if ($absolute_discount) {
  174. print $langs->trans("CompanyHasAbsoluteDiscount", price($absolute_discount), $langs->trans("Currency".$conf->currency));
  175. } else {
  176. print $langs->trans("CompanyHasNoAbsoluteDiscount");
  177. }
  178. print '.';
  179. print '</td></tr>';
  180. // Date
  181. print '<tr>';
  182. print '<td class="titlefield">';
  183. print $form->editfieldkey("Date", 'date_contrat', $object->date_contrat, $object, 0);
  184. print '</td><td>';
  185. print $form->editfieldval("Date", 'date_contrat', $object->date_contrat, $object, 0, 'datehourpicker');
  186. print '</td>';
  187. print '</tr>';
  188. print "</table>";
  189. print '</div>';
  190. print dol_get_fiche_end();
  191. print '<br>';
  192. // Contacts lines
  193. include DOL_DOCUMENT_ROOT.'/core/tpl/contacts.tpl.php';
  194. } else {
  195. print "ErrorRecordNotFound";
  196. }
  197. }
  198. llxFooter();
  199. $db->close();