contact.php 7.1 KB

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