reception.lib.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. /* Copyright (C) 2006-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  4. * Copyright (C) 2010-2012 Regis Houssin <regis.houssin@capnetworks.com>
  5. * Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
  6. * Copyright (C) 2015 Claudio Aschieri <c.aschieri@19.coop>
  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. * or see https://www.gnu.org/
  21. */
  22. /**
  23. * \file htdocs/core/lib/reception.lib.php
  24. * \brief Function for reception module
  25. * \ingroup reception
  26. */
  27. /**
  28. * Prepare array with list of tabs
  29. *
  30. * @param Reception $object Object related to tabs
  31. * @return array Array of tabs to show
  32. */
  33. function reception_prepare_head(Reception $object)
  34. {
  35. global $db, $langs, $conf, $user;
  36. $langs->loadLangs(array("sendings", "deliveries"));
  37. $h = 0;
  38. $head = array();
  39. $head[$h][0] = DOL_URL_ROOT."/reception/card.php?id=".$object->id;
  40. $head[$h][1] = $langs->trans("ReceptionCard");
  41. $head[$h][2] = 'reception';
  42. $h++;
  43. if ($object->statut == Reception::STATUS_DRAFT) {
  44. $head[$h][0] = DOL_URL_ROOT."/reception/dispatch.php?id=".$object->id;
  45. $head[$h][1] = $langs->trans("ReceptionDistribution");
  46. $head[$h][2] = 'dispatch';
  47. $h++;
  48. }
  49. if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
  50. $objectsrc = $object;
  51. if ($object->origin == 'supplier_order' && $object->origin_id > 0) {
  52. $objectsrc = new CommandeFournisseur($db);
  53. $objectsrc->fetch($object->origin_id);
  54. }
  55. $nbContact = count($objectsrc->liste_contact(-1, 'internal')) + count($objectsrc->liste_contact(-1, 'external'));
  56. $head[$h][0] = DOL_URL_ROOT."/reception/contact.php?id=".$object->id;
  57. $head[$h][1] = $langs->trans("ContactsAddresses");
  58. if ($nbContact > 0) {
  59. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
  60. }
  61. $head[$h][2] = 'contact';
  62. $h++;
  63. }
  64. // Show more tabs from modules
  65. // Entries must be declared in modules descriptor with line
  66. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  67. // $this->tabs = array('entity:-tabname); to remove a tab
  68. complete_head_from_modules($conf, $langs, $object, $head, $h, 'reception', 'add', 'core');
  69. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  70. require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
  71. $upload_dir = $conf->reception->dir_output."/".dol_sanitizeFileName($object->ref);
  72. $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
  73. $nbLinks = Link::count($db, $object->element, $object->id);
  74. $head[$h][0] = DOL_URL_ROOT.'/reception/document.php?id='.$object->id;
  75. $head[$h][1] = $langs->trans('Documents');
  76. if (($nbFiles + $nbLinks) > 0) {
  77. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
  78. }
  79. $head[$h][2] = 'documents';
  80. $h++;
  81. $nbNote = 0;
  82. if (!empty($object->note_private)) {
  83. $nbNote++;
  84. }
  85. if (!empty($object->note_public)) {
  86. $nbNote++;
  87. }
  88. $head[$h][0] = DOL_URL_ROOT."/reception/note.php?id=".$object->id;
  89. $head[$h][1] = $langs->trans("Notes");
  90. if ($nbNote > 0) {
  91. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
  92. }
  93. $head[$h][2] = 'note';
  94. $h++;
  95. complete_head_from_modules($conf, $langs, $object, $head, $h, 'reception', 'add', 'external');
  96. complete_head_from_modules($conf, $langs, $object, $head, $h, 'reception', 'remove');
  97. return $head;
  98. }
  99. /**
  100. * Return array head with list of tabs to view object informations.
  101. *
  102. * @return array head array with tabs
  103. */
  104. function reception_admin_prepare_head()
  105. {
  106. global $langs, $conf, $user, $db;
  107. $langs->load("receptions");
  108. $extrafields = new ExtraFields($db);
  109. $extrafields->fetch_name_optionals_label('reception');
  110. $extrafields->fetch_name_optionals_label('commande_fournisseur_dispatch');
  111. $h = 0;
  112. $head = array();
  113. $head[$h][0] = DOL_URL_ROOT."/admin/reception_setup.php";
  114. $head[$h][1] = $langs->trans("Reception");
  115. $head[$h][2] = 'reception';
  116. $h++;
  117. complete_head_from_modules($conf, $langs, null, $head, $h, 'reception_admin');
  118. if (!empty($conf->global->MAIN_SUBMODULE_RECEPTION)) {
  119. $head[$h][0] = DOL_URL_ROOT.'/admin/reception_extrafields.php';
  120. $head[$h][1] = $langs->trans("ExtraFields");
  121. $nbExtrafields = $extrafields->attributes['reception']['count'];
  122. if ($nbExtrafields > 0) {
  123. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
  124. }
  125. $head[$h][2] = 'attributes_reception';
  126. $h++;
  127. }
  128. if (!empty($conf->global->MAIN_SUBMODULE_RECEPTION)) {
  129. $head[$h][0] = DOL_URL_ROOT.'/admin/commande_fournisseur_dispatch_extrafields.php';
  130. $head[$h][1] = $langs->trans("ExtraFieldsLines");
  131. $nbExtrafields = $extrafields->attributes['commande_fournisseur_dispatch']['count'];
  132. if ($nbExtrafields > 0) {
  133. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
  134. }
  135. $head[$h][2] = 'attributeslines_reception';
  136. $h++;
  137. }
  138. complete_head_from_modules($conf, $langs, null, $head, $h, 'reception_admin', 'remove');
  139. return $head;
  140. }