contact.php 7.4 KB

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