stocktransfer_stocktransfer.lib.php 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /* Copyright (C) ---Put here your own copyright and developer email---
  3. * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file lib/stocktransfer_stocktransfer.lib.php
  20. * \ingroup stocktransfer
  21. * \brief Library files with common functions for StockTransfer
  22. */
  23. /**
  24. * Prepare array of tabs for StockTransfer
  25. *
  26. * @param StockTransfer $object StockTransfer
  27. * @return array Array of tabs
  28. */
  29. function stocktransferPrepareHead($object)
  30. {
  31. global $db, $langs, $conf;
  32. $langs->load("stocks");
  33. $h = 0;
  34. $head = array();
  35. $head[$h][0] = dol_buildpath("/product/stock/stocktransfer/stocktransfer_card.php", 1).'?id='.$object->id;
  36. $head[$h][1] = $langs->trans("Card");
  37. $head[$h][2] = 'card';
  38. $h++;
  39. if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
  40. $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external'));
  41. $head[$h][0] = dol_buildpath('/product/stock/stocktransfer/stocktransfer_contact.php', 1).'?id='.$object->id;
  42. $head[$h][1] = $langs->trans('ContactsAddresses');
  43. if ($nbContact > 0) $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
  44. $head[$h][2] = 'contact';
  45. $h++;
  46. }
  47. if (isset($object->fields['note_public']) || isset($object->fields['note_private'])) {
  48. $nbNote = 0;
  49. if (!empty($object->note_private)) $nbNote++;
  50. if (!empty($object->note_public)) $nbNote++;
  51. $head[$h][0] = dol_buildpath('/product/stock/stocktransfer/stocktransfer_note.php', 1).'?id='.$object->id;
  52. $head[$h][1] = $langs->trans('Notes');
  53. if ($nbNote > 0) $head[$h][1] .= (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) ? '<span class="badge marginleftonlyshort">'.$nbNote.'</span>' : '');
  54. $head[$h][2] = 'note';
  55. $h++;
  56. }
  57. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  58. require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
  59. $upload_dir = $conf->stocktransfer->dir_output."/stocktransfer/".dol_sanitizeFileName($object->ref);
  60. $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
  61. $nbLinks = Link::count($db, $object->element, $object->id);
  62. $head[$h][0] = dol_buildpath("/product/stock/stocktransfer/stocktransfer_document.php", 1).'?id='.$object->id;
  63. $head[$h][1] = $langs->trans('Documents');
  64. if (($nbFiles + $nbLinks) > 0) $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
  65. $head[$h][2] = 'document';
  66. $h++;
  67. $head[$h][0] = dol_buildpath("/product/stock/stocktransfer/stocktransfer_agenda.php", 1).'?id='.$object->id;
  68. $head[$h][1] = $langs->trans("Events");
  69. $head[$h][2] = 'agenda';
  70. $h++;
  71. // Show more tabs from modules
  72. // Entries must be declared in modules descriptor with line
  73. //$this->tabs = array(
  74. // 'entity:+tabname:Title:@stocktransfer:/stocktransfer/mypage.php?id=__ID__'
  75. //); // to add new tab
  76. //$this->tabs = array(
  77. // 'entity:-tabname:Title:@stocktransfer:/stocktransfer/mypage.php?id=__ID__'
  78. //); // to remove a tab
  79. complete_head_from_modules($conf, $langs, $object, $head, $h, 'stocktransfer@stocktransfer');
  80. complete_head_from_modules($conf, $langs, $object, $head, $h, 'stocktransfer@stocktransfer', 'remove');
  81. return $head;
  82. }