contact.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. /**
  22. * \file htdocs/compta/facture/contact.php
  23. * \ingroup facture
  24. * \brief Onglet de gestion des contacts des factures
  25. */
  26. // Load Dolibarr environment
  27. require '../../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  33. if (isModEnabled('project')) {
  34. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  35. }
  36. // Load translation files required by the page
  37. $langs->loadLangs(array('bills', 'companies'));
  38. $id = (GETPOST('id') ?GETPOST('id', 'int') : GETPOST('facid', 'int')); // For backward compatibility
  39. $ref = GETPOST('ref', 'alpha');
  40. $lineid = GETPOST('lineid', 'int');
  41. $socid = GETPOST('socid', 'int');
  42. $action = GETPOST('action', 'aZ09');
  43. // Security check
  44. if ($user->socid) {
  45. $socid = $user->socid;
  46. }
  47. $object = new Facture($db);
  48. // Load object
  49. if ($id > 0 || !empty($ref)) {
  50. $ret = $object->fetch($id, $ref, '', '', (!empty($conf->global->INVOICE_USE_SITUATION) ? $conf->global->INVOICE_USE_SITUATION : 0));
  51. }
  52. $result = restrictedArea($user, 'facture', $object->id);
  53. $usercancreate = $user->hasRight("facture", "creer");
  54. /*
  55. * Add a new contact
  56. */
  57. if ($action == 'addcontact' && $user->rights->facture->creer) {
  58. if ($result > 0 && $id > 0) {
  59. $contactid = (GETPOST('userid') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
  60. $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
  61. $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
  62. }
  63. if ($result >= 0) {
  64. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  65. exit;
  66. } else {
  67. if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
  68. $langs->load("errors");
  69. setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
  70. } else {
  71. setEventMessages($object->error, $object->errors, 'errors');
  72. }
  73. }
  74. } elseif ($action == 'swapstatut' && $user->rights->facture->creer) {
  75. // Toggle the status of a contact
  76. $result = $object->swapContactStatus(GETPOST('ligne', 'int'));
  77. } elseif ($action == 'deletecontact' && $user->rights->facture->creer) {
  78. // Deletes a contact
  79. $result = $object->delete_contact($lineid);
  80. if ($result >= 0) {
  81. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  82. exit;
  83. } else {
  84. dol_print_error($db);
  85. }
  86. }
  87. /*
  88. * View
  89. */
  90. $title = $object->ref." - ".$langs->trans('ContactsAddresses');
  91. $helpurl = "EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes";
  92. llxHeader('', $title, $helpurl);
  93. $form = new Form($db);
  94. $formcompany = new FormCompany($db);
  95. $contactstatic = new Contact($db);
  96. $userstatic = new User($db);
  97. /* *************************************************************************** */
  98. /* */
  99. /* View and edit mode */
  100. /* */
  101. /* *************************************************************************** */
  102. if ($id > 0 || !empty($ref)) {
  103. if ($object->fetch($id, $ref) > 0) {
  104. $object->fetch_thirdparty();
  105. $head = facture_prepare_head($object);
  106. $totalpaid = $object->getSommePaiement();
  107. print dol_get_fiche_head($head, 'contact', $langs->trans('InvoiceCustomer'), -1, 'bill');
  108. // Invoice content
  109. $linkback = '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  110. $morehtmlref = '<div class="refidno">';
  111. // Ref customer
  112. $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
  113. $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
  114. // Thirdparty
  115. $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1, 'customer');
  116. // Project
  117. if (isModEnabled('project')) {
  118. $langs->load("projects");
  119. $morehtmlref .= '<br>';
  120. if (0) {
  121. $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
  122. if ($action != 'classify') {
  123. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
  124. }
  125. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
  126. } else {
  127. if (!empty($object->fk_project)) {
  128. $proj = new Project($db);
  129. $proj->fetch($object->fk_project);
  130. $morehtmlref .= $proj->getNomUrl(1);
  131. if ($proj->title) {
  132. $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
  133. }
  134. }
  135. }
  136. }
  137. $morehtmlref .= '</div>';
  138. $object->totalpaid = $totalpaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status
  139. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
  140. print dol_get_fiche_end();
  141. //print '<br>';
  142. // Contacts lines (modules that overwrite templates must declare this into descriptor)
  143. $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
  144. foreach ($dirtpls as $reldir) {
  145. $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
  146. if ($res) {
  147. break;
  148. }
  149. }
  150. } else {
  151. // Record not found
  152. print "ErrorRecordNotFound";
  153. }
  154. }
  155. // End of page
  156. llxFooter();
  157. $db->close();