PageRenderTime 40ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/product/lib/product.lib.php

https://bitbucket.org/speedealing/speedealing
PHP | 289 lines | 195 code | 32 blank | 62 comment | 29 complexity | 29e36bc23f9f2098ec1166d7a8b64b79 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2006-2008 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  4. * Copyright (C) 2009-2010 Regis Houssin <regis.houssin@capnetworks.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. * or see http://www.gnu.org/
  19. */
  20. /**
  21. * \file htdocs/core/lib/product.lib.php
  22. * \brief Ensemble de fonctions de base pour le module produit et service
  23. * \ingroup product
  24. */
  25. /**
  26. * Prepare array with list of tabs
  27. *
  28. * @param Object $object Object related to tabs
  29. * @param User $user Object user
  30. * @return array Array of tabs to shoc
  31. */
  32. function product_prepare_head($object, $user) {
  33. global $langs, $conf;
  34. $langs->load("products");
  35. $h = 0;
  36. $head = array();
  37. $head[$h][0] = DOL_URL_ROOT . "/product/fiche.php?id=" . $object->id;
  38. $head[$h][1] = $langs->trans("Card");
  39. $head[$h][2] = 'card';
  40. $h++;
  41. $head[$h][0] = DOL_URL_ROOT . "/product/price.php?id=" . $object->id;
  42. $head[$h][1] = $langs->trans("CustomerPrices");
  43. $head[$h][2] = 'price';
  44. $h++;
  45. if (!empty($conf->fournisseur->enabled) && $user->rights->fournisseur->lire) {
  46. $head[$h][0] = DOL_URL_ROOT . "/product/fournisseurs.php?id=" . $object->id;
  47. $head[$h][1] = $langs->trans("SuppliersPrices");
  48. $head[$h][2] = 'suppliers';
  49. $h++;
  50. }
  51. $head[$h][0] = DOL_URL_ROOT . "/product/photos.php?id=" . $object->id;
  52. $head[$h][1] = $langs->trans("Photos");
  53. $head[$h][2] = 'photos';
  54. $h++;
  55. // Show category tab
  56. if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire) {
  57. $head[$h][0] = DOL_URL_ROOT . "/categories/categorie.php?id=" . $object->id . '&type=0';
  58. $head[$h][1] = $langs->trans('Categories');
  59. $head[$h][2] = 'category';
  60. $h++;
  61. }
  62. // Multilangs
  63. if (!empty($conf->global->MAIN_MULTILANGS)) {
  64. $head[$h][0] = DOL_URL_ROOT . "/product/traduction.php?id=" . $object->id;
  65. $head[$h][1] = $langs->trans("Translation");
  66. $head[$h][2] = 'translation';
  67. $h++;
  68. }
  69. // Sub products
  70. if (!empty($conf->global->PRODUIT_SOUSPRODUITS)) {
  71. $head[$h][0] = DOL_URL_ROOT . "/product/composition/fiche.php?id=" . $object->id;
  72. $head[$h][1] = $langs->trans('AssociatedProducts');
  73. $head[$h][2] = 'subproduct';
  74. $h++;
  75. }
  76. $head[$h][0] = DOL_URL_ROOT . "/product/stats/fiche.php?id=" . $object->id;
  77. $head[$h][1] = $langs->trans('Statistics');
  78. $head[$h][2] = 'stats';
  79. $h++;
  80. $head[$h][0] = DOL_URL_ROOT . "/product/stats/facture.php?id=" . $object->id;
  81. $head[$h][1] = $langs->trans('Referers');
  82. $head[$h][2] = 'referers';
  83. $h++;
  84. if ($object->isproduct()) { // Si produit stockable
  85. if (!empty($conf->stock->enabled) && $user->rights->stock->lire) {
  86. $head[$h][0] = DOL_URL_ROOT . "/product/stock/product.php?id=" . $object->id;
  87. $head[$h][1] = $langs->trans("Stock");
  88. $head[$h][2] = 'stock';
  89. $h++;
  90. }
  91. }
  92. // Show more tabs from modules
  93. // Entries must be declared in modules descriptor with line
  94. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  95. // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
  96. complete_head_from_modules($conf, $langs, $object, $head, $h, 'product');
  97. $head[$h][0] = DOL_URL_ROOT . '/product/document.php?id=' . $object->id;
  98. $head[$h][1] = $langs->trans('Documents');
  99. $head[$h][2] = 'documents';
  100. $h++;
  101. // More tabs from canvas
  102. // TODO Is this still used ?
  103. if (isset($object->onglets) && is_array($object->onglets)) {
  104. foreach ($object->onglets as $onglet) {
  105. $head[$h] = $onglet;
  106. $h++;
  107. }
  108. }
  109. complete_head_from_modules($conf, $langs, $object, $head, $h, 'product', 'remove');
  110. return $head;
  111. }
  112. /**
  113. * Return array head with list of tabs to view object informations.
  114. *
  115. * @param Object $object Product
  116. * @return array head array with tabs
  117. */
  118. function product_admin_prepare_head($object = null) {
  119. global $langs, $conf, $user;
  120. $h = 0;
  121. $head = array();
  122. $head[$h][0] = DOL_URL_ROOT . "/product/admin/product.php";
  123. $head[$h][1] = $langs->trans('Parameters');
  124. $head[$h][2] = 'general';
  125. $h++;
  126. // Show more tabs from modules
  127. // Entries must be declared in modules descriptor with line
  128. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  129. // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
  130. complete_head_from_modules($conf, $langs, $object, $head, $h, 'product_admin');
  131. $head[$h][0] = DOL_URL_ROOT . '/product/admin/product_extrafields.php';
  132. $head[$h][1] = $langs->trans("ExtraFields");
  133. $head[$h][2] = 'attributes';
  134. $h++;
  135. complete_head_from_modules($conf, $langs, $object, $head, $h, 'product_admin', 'remove');
  136. return $head;
  137. }
  138. /**
  139. * Show stats for company
  140. *
  141. * @param Product $product Product object
  142. * @param int $socid Thirdparty id
  143. * @return void
  144. */
  145. function show_stats_for_company($product, $socid) {
  146. global $conf, $langs, $user, $db;
  147. print '<tr>';
  148. print '<td align="left" width="25%" valign="top">' . $langs->trans("Referers") . '</td>';
  149. print '<td align="right" width="25%">' . $langs->trans("NbOfThirdParties") . '</td>';
  150. print '<td align="right" width="25%">' . $langs->trans("NbOfReferers") . '</td>';
  151. print '<td align="right" width="25%">' . $langs->trans("TotalQuantity") . '</td>';
  152. print '</tr>';
  153. // Propals
  154. if (!empty($conf->propal->enabled) && $user->rights->propale->lire) {
  155. $ret = $product->load_stats_propale($socid);
  156. if ($ret < 0)
  157. dol_print_error($db);
  158. $langs->load("propal");
  159. print '<tr><td>';
  160. print '<a href="propal.php?id=' . $product->id . '">' . img_object('', 'propal') . ' ' . $langs->trans("Proposals") . '</a>';
  161. print '</td><td align="right">';
  162. print $product->stats_propale['customers'];
  163. print '</td><td align="right">';
  164. print $product->stats_propale['nb'];
  165. print '</td><td align="right">';
  166. print $product->stats_propale['qty'];
  167. print '</td>';
  168. print '</tr>';
  169. }
  170. // Commandes clients
  171. if (!empty($conf->commande->enabled) && $user->rights->commande->lire) {
  172. $ret = $product->load_stats_commande($socid);
  173. if ($ret < 0)
  174. dol_print_error($db);
  175. $langs->load("orders");
  176. print '<tr><td>';
  177. print '<a href="commande.php?id=' . $product->id . '">' . img_object('', 'order') . ' ' . $langs->trans("CustomersOrders") . '</a>';
  178. print '</td><td align="right">';
  179. print $product->stats_commande['customers'];
  180. print '</td><td align="right">';
  181. print $product->stats_commande['nb'];
  182. print '</td><td align="right">';
  183. print $product->stats_commande['qty'];
  184. print '</td>';
  185. print '</tr>';
  186. }
  187. // Commandes fournisseurs
  188. if (!empty($conf->fournisseur->enabled) && $user->rights->fournisseur->commande->lire) {
  189. $ret = $product->load_stats_commande_fournisseur($socid);
  190. if ($ret < 0)
  191. dol_print_error($db);
  192. $langs->load("orders");
  193. print '<tr><td>';
  194. print '<a href="commande_fournisseur.php?id=' . $product->id . '">' . img_object('', 'order') . ' ' . $langs->trans("SuppliersOrders") . '</a>';
  195. print '</td><td align="right">';
  196. print $product->stats_commande_fournisseur['suppliers'];
  197. print '</td><td align="right">';
  198. print $product->stats_commande_fournisseur['nb'];
  199. print '</td><td align="right">';
  200. print $product->stats_commande_fournisseur['qty'];
  201. print '</td>';
  202. print '</tr>';
  203. }
  204. // Contrats
  205. if (!empty($conf->contrat->enabled) && $user->rights->contrat->lire) {
  206. $ret = $product->load_stats_contrat($socid);
  207. if ($ret < 0)
  208. dol_print_error($db);
  209. $langs->load("contracts");
  210. print '<tr><td>';
  211. print '<a href="contrat.php?id=' . $product->id . '">' . img_object('', 'contract') . ' ' . $langs->trans("Contracts") . '</a>';
  212. print '</td><td align="right">';
  213. print $product->stats_contrat['customers'];
  214. print '</td><td align="right">';
  215. print $product->stats_contrat['nb'];
  216. print '</td><td align="right">';
  217. print $product->stats_contrat['qty'];
  218. print '</td>';
  219. print '</tr>';
  220. }
  221. // Factures clients
  222. if (!empty($conf->facture->enabled) && $user->rights->facture->lire) {
  223. $ret = $product->load_stats_facture($socid);
  224. if ($ret < 0)
  225. dol_print_error($db);
  226. $langs->load("bills");
  227. print '<tr><td>';
  228. print '<a href="facture.php?id=' . $product->id . '">' . img_object('', 'bill') . ' ' . $langs->trans("CustomersInvoices") . '</a>';
  229. print '</td><td align="right">';
  230. print $product->stats_facture['customers'];
  231. print '</td><td align="right">';
  232. print $product->stats_facture['nb'];
  233. print '</td><td align="right">';
  234. print $product->stats_facture['qty'];
  235. print '</td>';
  236. print '</tr>';
  237. }
  238. // Factures fournisseurs
  239. if (!empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) {
  240. $ret = $product->load_stats_facture_fournisseur($socid);
  241. if ($ret < 0)
  242. dol_print_error($db);
  243. $langs->load("bills");
  244. print '<tr><td>';
  245. print '<a href="facture_fournisseur.php?id=' . $product->id . '">' . img_object('', 'bill') . ' ' . $langs->trans("SuppliersInvoices") . '</a>';
  246. print '</td><td align="right">';
  247. print $product->stats_facture_fournisseur['suppliers'];
  248. print '</td><td align="right">';
  249. print $product->stats_facture_fournisseur['nb'];
  250. print '</td><td align="right">';
  251. print $product->stats_facture_fournisseur['qty'];
  252. print '</td>';
  253. print '</tr>';
  254. }
  255. return 0;
  256. }
  257. ?>