mrp_mo.lib.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. /* Copyright (C) ---Put here your own copyright and developer email---
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file lib/mrp_mo.lib.php
  19. * \ingroup mrp
  20. * \brief Library files with common functions for Mo
  21. */
  22. /**
  23. * Prepare array of tabs for Mo
  24. *
  25. * @param Mo $object Mo
  26. * @return array Array of tabs
  27. */
  28. function moPrepareHead($object)
  29. {
  30. global $db, $langs, $conf;
  31. $langs->loadLangs(array("mrp", "stocks"));
  32. $h = 0;
  33. $head = array();
  34. $head[$h][0] = DOL_URL_ROOT.'/mrp/mo_card.php?id='.$object->id;
  35. $head[$h][1] = $langs->trans("ManufacturingOrder");
  36. $head[$h][2] = 'card';
  37. $h++;
  38. $head[$h][0] = DOL_URL_ROOT.'/mrp/mo_production.php?id='.$object->id;
  39. $head[$h][1] = $langs->trans("Production");
  40. $arrayproduced = $object->fetchLinesLinked('produced', 0);
  41. $nbProduced = 0;
  42. foreach ($arrayproduced as $lineproduced) {
  43. $nbProduced += $lineproduced['qty'];
  44. }
  45. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbProduced.' / '.$object->qty.'</span>';
  46. $head[$h][2] = 'production';
  47. $h++;
  48. $head[$h][0] = DOL_URL_ROOT.'/mrp/mo_movements.php?id='.$object->id;
  49. $head[$h][1] = $langs->trans("StockMovements");
  50. $nbMove = $object->countMovements();
  51. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbMove.'</span>';
  52. $head[$h][2] = 'stockmovement';
  53. $h++;
  54. if (isset($object->fields['note_public']) || isset($object->fields['note_private'])) {
  55. $nbNote = 0;
  56. if (!empty($object->note_private)) {
  57. $nbNote++;
  58. }
  59. if (!empty($object->note_public)) {
  60. $nbNote++;
  61. }
  62. $head[$h][0] = dol_buildpath('/mrp/mo_note.php', 1).'?id='.$object->id;
  63. $head[$h][1] = $langs->trans('Notes');
  64. if ($nbNote > 0) {
  65. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
  66. }
  67. $head[$h][2] = 'note';
  68. $h++;
  69. }
  70. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  71. require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
  72. $upload_dir = $conf->mrp->dir_output."/".dol_sanitizeFileName($object->ref);
  73. $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
  74. $nbLinks = Link::count($db, $object->element, $object->id);
  75. $head[$h][0] = dol_buildpath("/mrp/mo_document.php", 1).'?id='.$object->id;
  76. $head[$h][1] = $langs->trans('Documents');
  77. if (($nbFiles + $nbLinks) > 0) {
  78. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
  79. }
  80. $head[$h][2] = 'document';
  81. $h++;
  82. $head[$h][0] = dol_buildpath("/mrp/mo_agenda.php", 1).'?id='.$object->id;
  83. $head[$h][1] = $langs->trans("Events");
  84. $head[$h][2] = 'agenda';
  85. $h++;
  86. // Show more tabs from modules
  87. // Entries must be declared in modules descriptor with line
  88. //$this->tabs = array(
  89. // 'entity:+tabname:Title:@mrp:/mrp/mypage.php?id=__ID__'
  90. //); // to add new tab
  91. //$this->tabs = array(
  92. // 'entity:-tabname:Title:@mrp:/mrp/mypage.php?id=__ID__'
  93. //); // to remove a tab
  94. complete_head_from_modules($conf, $langs, $object, $head, $h, 'mo@mrp');
  95. complete_head_from_modules($conf, $langs, $object, $head, $h, 'mo@mrp', 'remove');
  96. return $head;
  97. }