order.lib.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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@inodbox.com>
  5. * Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. * or see https://www.gnu.org/
  20. */
  21. /**
  22. * \file htdocs/core/lib/order.lib.php
  23. * \brief Ensemble de fonctions de base pour le module commande
  24. * \ingroup commande
  25. */
  26. /**
  27. * Prepare array with list of tabs
  28. *
  29. * @param Commande $object Object related to tabs
  30. * @return array Array of tabs to show
  31. */
  32. function commande_prepare_head(Commande $object)
  33. {
  34. global $db, $langs, $conf, $user;
  35. if (!empty($conf->expedition->enabled)) $langs->load("sendings");
  36. $langs->load("orders");
  37. $h = 0;
  38. $head = array();
  39. if (!empty($conf->commande->enabled) && $user->rights->commande->lire)
  40. {
  41. $head[$h][0] = DOL_URL_ROOT.'/commande/card.php?id='.$object->id;
  42. $head[$h][1] = $langs->trans("CustomerOrder");
  43. $head[$h][2] = 'order';
  44. $h++;
  45. }
  46. if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB))
  47. {
  48. $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external'));
  49. $head[$h][0] = DOL_URL_ROOT.'/commande/contact.php?id='.$object->id;
  50. $head[$h][1] = $langs->trans('ContactsAddresses');
  51. if ($nbContact > 0) $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
  52. $head[$h][2] = 'contact';
  53. $h++;
  54. }
  55. if (($conf->expedition_bon->enabled && $user->rights->expedition->lire)
  56. || ($conf->livraison_bon->enabled && $user->rights->expedition->livraison->lire))
  57. {
  58. $nbShipments = $object->getNbOfShipments(); $nbReceiption = 0;
  59. $head[$h][0] = DOL_URL_ROOT.'/expedition/shipment.php?id='.$object->id;
  60. $text = '';
  61. if ($conf->expedition_bon->enabled) $text .= $langs->trans("Shipments");
  62. if ($conf->expedition_bon->enabled && $conf->livraison_bon->enabled) $text .= ' - ';
  63. if ($conf->livraison_bon->enabled) $text .= $langs->trans("Receivings");
  64. if ($nbShipments > 0 || $nbReceiption > 0) $text .= '<span class="badge marginleftonlyshort">'.($nbShipments ? $nbShipments : 0);
  65. if ($conf->expedition_bon->enabled && $conf->livraison_bon->enabled && ($nbShipments > 0 || $nbReceiption > 0)) $text .= ' - ';
  66. if ($conf->expedition_bon->enabled && $conf->livraison_bon->enabled && ($nbShipments > 0 || $nbReceiption > 0)) $text .= ($nbReceiption ? $nbReceiption : 0);
  67. if ($nbShipments > 0 || $nbReceiption > 0) $text .= '</span>';
  68. $head[$h][1] = $text;
  69. $head[$h][2] = 'shipping';
  70. $h++;
  71. }
  72. // Show more tabs from modules
  73. // Entries must be declared in modules descriptor with line
  74. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  75. // $this->tabs = array('entity:-tabname); to remove a tab
  76. complete_head_from_modules($conf, $langs, $object, $head, $h, 'order');
  77. if (empty($conf->global->MAIN_DISABLE_NOTES_TAB))
  78. {
  79. $nbNote = 0;
  80. if (!empty($object->note_private)) $nbNote++;
  81. if (!empty($object->note_public)) $nbNote++;
  82. $head[$h][0] = DOL_URL_ROOT.'/commande/note.php?id='.$object->id;
  83. $head[$h][1] = $langs->trans('Notes');
  84. if ($nbNote > 0) $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
  85. $head[$h][2] = 'note';
  86. $h++;
  87. }
  88. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  89. require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
  90. $upload_dir = $conf->commande->multidir_output[$object->entity]."/".dol_sanitizeFileName($object->ref);
  91. $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
  92. $nbLinks = Link::count($db, $object->element, $object->id);
  93. $head[$h][0] = DOL_URL_ROOT.'/commande/document.php?id='.$object->id;
  94. $head[$h][1] = $langs->trans('Documents');
  95. if (($nbFiles + $nbLinks) > 0) $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
  96. $head[$h][2] = 'documents';
  97. $h++;
  98. $head[$h][0] = DOL_URL_ROOT.'/commande/info.php?id='.$object->id;
  99. $head[$h][1] = $langs->trans("Info");
  100. $head[$h][2] = 'info';
  101. $h++;
  102. complete_head_from_modules($conf, $langs, $object, $head, $h, 'order', 'remove');
  103. return $head;
  104. }
  105. /**
  106. * Return array head with list of tabs to view object informations.
  107. *
  108. * @return array head array with tabs
  109. */
  110. function order_admin_prepare_head()
  111. {
  112. global $langs, $conf, $user;
  113. $h = 0;
  114. $head = array();
  115. $head[$h][0] = DOL_URL_ROOT.'/admin/commande.php';
  116. $head[$h][1] = $langs->trans("Miscellaneous");
  117. $head[$h][2] = 'general';
  118. $h++;
  119. complete_head_from_modules($conf, $langs, null, $head, $h, 'order_admin');
  120. $head[$h][0] = DOL_URL_ROOT.'/admin/order_extrafields.php';
  121. $head[$h][1] = $langs->trans("ExtraFields");
  122. $head[$h][2] = 'attributes';
  123. $h++;
  124. $head[$h][0] = DOL_URL_ROOT.'/admin/orderdet_extrafields.php';
  125. $head[$h][1] = $langs->trans("ExtraFieldsLines");
  126. $head[$h][2] = 'attributeslines';
  127. $h++;
  128. complete_head_from_modules($conf, $langs, null, $head, $h, 'order_admin', 'remove');
  129. return $head;
  130. }