product.lib.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  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. {
  34. global $langs, $conf;
  35. $langs->load("products");
  36. $h = 0;
  37. $head = array();
  38. $head[$h][0] = DOL_URL_ROOT."/product/fiche.php?id=".$object->id;
  39. $head[$h][1] = $langs->trans("Card");
  40. $head[$h][2] = 'card';
  41. $h++;
  42. $head[$h][0] = DOL_URL_ROOT."/product/price.php?id=".$object->id;
  43. $head[$h][1] = $langs->trans("CustomerPrices");
  44. $head[$h][2] = 'price';
  45. $h++;
  46. if (! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->lire)
  47. {
  48. $head[$h][0] = DOL_URL_ROOT."/product/fournisseurs.php?id=".$object->id;
  49. $head[$h][1] = $langs->trans("SuppliersPrices");
  50. $head[$h][2] = 'suppliers';
  51. $h++;
  52. }
  53. $head[$h][0] = DOL_URL_ROOT."/product/photos.php?id=".$object->id;
  54. $head[$h][1] = $langs->trans("Photos");
  55. $head[$h][2] = 'photos';
  56. $h++;
  57. // Show category tab
  58. if (! empty($conf->categorie->enabled) && $user->rights->categorie->lire)
  59. {
  60. $head[$h][0] = DOL_URL_ROOT."/categories/categorie.php?id=".$object->id.'&type=0';
  61. $head[$h][1] = $langs->trans('Categories');
  62. $head[$h][2] = 'category';
  63. $h++;
  64. }
  65. // Multilangs
  66. if (! empty($conf->global->MAIN_MULTILANGS))
  67. {
  68. $head[$h][0] = DOL_URL_ROOT."/product/traduction.php?id=".$object->id;
  69. $head[$h][1] = $langs->trans("Translation");
  70. $head[$h][2] = 'translation';
  71. $h++;
  72. }
  73. // Sub products
  74. if (! empty($conf->global->PRODUIT_SOUSPRODUITS))
  75. {
  76. $head[$h][0] = DOL_URL_ROOT."/product/composition/fiche.php?id=".$object->id;
  77. $head[$h][1] = $langs->trans('AssociatedProducts');
  78. $head[$h][2] = 'subproduct';
  79. $h++;
  80. }
  81. $head[$h][0] = DOL_URL_ROOT."/product/stats/fiche.php?id=".$object->id;
  82. $head[$h][1] = $langs->trans('Statistics');
  83. $head[$h][2] = 'stats';
  84. $h++;
  85. $head[$h][0] = DOL_URL_ROOT."/product/stats/facture.php?id=".$object->id;
  86. $head[$h][1] = $langs->trans('Referers');
  87. $head[$h][2] = 'referers';
  88. $h++;
  89. if($object->isproduct()) // Si produit stockable
  90. {
  91. if (! empty($conf->stock->enabled) && $user->rights->stock->lire)
  92. {
  93. $head[$h][0] = DOL_URL_ROOT."/product/stock/product.php?id=".$object->id;
  94. $head[$h][1] = $langs->trans("Stock");
  95. $head[$h][2] = 'stock';
  96. $h++;
  97. }
  98. }
  99. // Show more tabs from modules
  100. // Entries must be declared in modules descriptor with line
  101. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  102. // $this->tabs = array('entity:-tabname); to remove a tab
  103. complete_head_from_modules($conf,$langs,$object,$head,$h,'product');
  104. // Attachments
  105. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  106. if (! empty($conf->product->enabled)) $upload_dir = $conf->product->multidir_output[$object->entity].'/'.dol_sanitizeFileName($object->ref);
  107. elseif (! empty($conf->service->enabled)) $upload_dir = $conf->service->multidir_output[$object->entity].'/'.dol_sanitizeFileName($object->ref);
  108. $nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview\.png)$'));
  109. $head[$h][0] = DOL_URL_ROOT.'/product/document.php?id='.$object->id;
  110. $head[$h][1] = $langs->trans('Documents');
  111. if($nbFiles > 0) $head[$h][1].= ' ('.$nbFiles.')';
  112. $head[$h][2] = 'documents';
  113. $h++;
  114. // More tabs from canvas
  115. // TODO Is this still used ?
  116. if (isset($object->onglets) && is_array($object->onglets))
  117. {
  118. foreach ($object->onglets as $onglet)
  119. {
  120. $head[$h] = $onglet;
  121. $h++;
  122. }
  123. }
  124. complete_head_from_modules($conf,$langs,$object,$head,$h,'product', 'remove');
  125. return $head;
  126. }
  127. /**
  128. * Return array head with list of tabs to view object informations.
  129. *
  130. * @param Object $object Product
  131. * @return array head array with tabs
  132. */
  133. function product_admin_prepare_head($object=null)
  134. {
  135. global $langs, $conf, $user;
  136. $h = 0;
  137. $head = array();
  138. $head[$h][0] = DOL_URL_ROOT."/product/admin/product.php";
  139. $head[$h][1] = $langs->trans('Parameters');
  140. $head[$h][2] = 'general';
  141. $h++;
  142. // Show more tabs from modules
  143. // Entries must be declared in modules descriptor with line
  144. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  145. // $this->tabs = array('entity:-tabname); to remove a tab
  146. complete_head_from_modules($conf,$langs,$object,$head,$h,'product_admin');
  147. $head[$h][0] = DOL_URL_ROOT.'/product/admin/product_extrafields.php';
  148. $head[$h][1] = $langs->trans("ExtraFields");
  149. $head[$h][2] = 'attributes';
  150. $h++;
  151. complete_head_from_modules($conf,$langs,$object,$head,$h,'product_admin','remove');
  152. return $head;
  153. }
  154. /**
  155. * Show stats for company
  156. *
  157. * @param Product $product Product object
  158. * @param int $socid Thirdparty id
  159. * @return void
  160. */
  161. function show_stats_for_company($product,$socid)
  162. {
  163. global $conf,$langs,$user,$db;
  164. print '<tr>';
  165. print '<td align="left" width="25%" valign="top">'.$langs->trans("Referers").'</td>';
  166. print '<td align="right" width="25%">'.$langs->trans("NbOfThirdParties").'</td>';
  167. print '<td align="right" width="25%">'.$langs->trans("NbOfReferers").'</td>';
  168. print '<td align="right" width="25%">'.$langs->trans("TotalQuantity").'</td>';
  169. print '</tr>';
  170. // Propals
  171. if (! empty($conf->propal->enabled) && $user->rights->propale->lire)
  172. {
  173. $ret=$product->load_stats_propale($socid);
  174. if ($ret < 0) dol_print_error($db);
  175. $langs->load("propal");
  176. print '<tr><td>';
  177. print '<a href="propal.php?id='.$product->id.'">'.img_object('','propal').' '.$langs->trans("Proposals").'</a>';
  178. print '</td><td align="right">';
  179. print $product->stats_propale['customers'];
  180. print '</td><td align="right">';
  181. print $product->stats_propale['nb'];
  182. print '</td><td align="right">';
  183. print $product->stats_propale['qty'];
  184. print '</td>';
  185. print '</tr>';
  186. }
  187. // Commandes clients
  188. if (! empty($conf->commande->enabled) && $user->rights->commande->lire)
  189. {
  190. $ret=$product->load_stats_commande($socid);
  191. if ($ret < 0) dol_print_error($db);
  192. $langs->load("orders");
  193. print '<tr><td>';
  194. print '<a href="commande.php?id='.$product->id.'">'.img_object('','order').' '.$langs->trans("CustomersOrders").'</a>';
  195. print '</td><td align="right">';
  196. print $product->stats_commande['customers'];
  197. print '</td><td align="right">';
  198. print $product->stats_commande['nb'];
  199. print '</td><td align="right">';
  200. print $product->stats_commande['qty'];
  201. print '</td>';
  202. print '</tr>';
  203. }
  204. // Commandes fournisseurs
  205. if (! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->commande->lire)
  206. {
  207. $ret=$product->load_stats_commande_fournisseur($socid);
  208. if ($ret < 0) dol_print_error($db);
  209. $langs->load("orders");
  210. print '<tr><td>';
  211. print '<a href="commande_fournisseur.php?id='.$product->id.'">'.img_object('','order').' '.$langs->trans("SuppliersOrders").'</a>';
  212. print '</td><td align="right">';
  213. print $product->stats_commande_fournisseur['suppliers'];
  214. print '</td><td align="right">';
  215. print $product->stats_commande_fournisseur['nb'];
  216. print '</td><td align="right">';
  217. print $product->stats_commande_fournisseur['qty'];
  218. print '</td>';
  219. print '</tr>';
  220. }
  221. // Contrats
  222. if (! empty($conf->contrat->enabled) && $user->rights->contrat->lire)
  223. {
  224. $ret=$product->load_stats_contrat($socid);
  225. if ($ret < 0) dol_print_error($db);
  226. $langs->load("contracts");
  227. print '<tr><td>';
  228. print '<a href="contrat.php?id='.$product->id.'">'.img_object('','contract').' '.$langs->trans("Contracts").'</a>';
  229. print '</td><td align="right">';
  230. print $product->stats_contrat['customers'];
  231. print '</td><td align="right">';
  232. print $product->stats_contrat['nb'];
  233. print '</td><td align="right">';
  234. print $product->stats_contrat['qty'];
  235. print '</td>';
  236. print '</tr>';
  237. }
  238. // Factures clients
  239. if (! empty($conf->facture->enabled) && $user->rights->facture->lire)
  240. {
  241. $ret=$product->load_stats_facture($socid);
  242. if ($ret < 0) dol_print_error($db);
  243. $langs->load("bills");
  244. print '<tr><td>';
  245. print '<a href="facture.php?id='.$product->id.'">'.img_object('','bill').' '.$langs->trans("CustomersInvoices").'</a>';
  246. print '</td><td align="right">';
  247. print $product->stats_facture['customers'];
  248. print '</td><td align="right">';
  249. print $product->stats_facture['nb'];
  250. print '</td><td align="right">';
  251. print $product->stats_facture['qty'];
  252. print '</td>';
  253. print '</tr>';
  254. }
  255. // Factures fournisseurs
  256. if (! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire)
  257. {
  258. $ret=$product->load_stats_facture_fournisseur($socid);
  259. if ($ret < 0) dol_print_error($db);
  260. $langs->load("bills");
  261. print '<tr><td>';
  262. print '<a href="facture_fournisseur.php?id='.$product->id.'">'.img_object('','bill').' '.$langs->trans("SuppliersInvoices").'</a>';
  263. print '</td><td align="right">';
  264. print $product->stats_facture_fournisseur['suppliers'];
  265. print '</td><td align="right">';
  266. print $product->stats_facture_fournisseur['nb'];
  267. print '</td><td align="right">';
  268. print $product->stats_facture_fournisseur['qty'];
  269. print '</td>';
  270. print '</tr>';
  271. }
  272. return 0;
  273. }
  274. /**
  275. * Return translation label of a unit key
  276. *
  277. * @param int $unit Unit key (-3,0,3,98,99...)
  278. * @param string $measuring_style Style of unit: weight, volume,...
  279. * @return string Unit string
  280. * @see load_measuring_units
  281. */
  282. function measuring_units_string($unit,$measuring_style='')
  283. {
  284. global $langs;
  285. if ($measuring_style == 'weight')
  286. {
  287. $measuring_units[3] = $langs->trans("WeightUnitton");
  288. $measuring_units[0] = $langs->trans("WeightUnitkg");
  289. $measuring_units[-3] = $langs->trans("WeightUnitg");
  290. $measuring_units[-6] = $langs->trans("WeightUnitmg");
  291. $measuring_units[99] = $langs->trans("WeightUnitpound");
  292. }
  293. else if ($measuring_style == 'size')
  294. {
  295. $measuring_units[0] = $langs->trans("SizeUnitm");
  296. $measuring_units[-1] = $langs->trans("SizeUnitdm");
  297. $measuring_units[-2] = $langs->trans("SizeUnitcm");
  298. $measuring_units[-3] = $langs->trans("SizeUnitmm");
  299. $measuring_units[98] = $langs->trans("SizeUnitfoot");
  300. $measuring_units[99] = $langs->trans("SizeUnitinch");
  301. }
  302. else if ($measuring_style == 'surface')
  303. {
  304. $measuring_units[0] = $langs->trans("SurfaceUnitm2");
  305. $measuring_units[-2] = $langs->trans("SurfaceUnitdm2");
  306. $measuring_units[-4] = $langs->trans("SurfaceUnitcm2");
  307. $measuring_units[-6] = $langs->trans("SurfaceUnitmm2");
  308. $measuring_units[98] = $langs->trans("SurfaceUnitfoot2");
  309. $measuring_units[99] = $langs->trans("SurfaceUnitinch2");
  310. }
  311. else if ($measuring_style == 'volume')
  312. {
  313. $measuring_units[0] = $langs->trans("VolumeUnitm3");
  314. $measuring_units[-3] = $langs->trans("VolumeUnitdm3");
  315. $measuring_units[-6] = $langs->trans("VolumeUnitcm3");
  316. $measuring_units[-9] = $langs->trans("VolumeUnitmm3");
  317. $measuring_units[88] = $langs->trans("VolumeUnitfoot3");
  318. $measuring_units[89] = $langs->trans("VolumeUnitinch3");
  319. $measuring_units[97] = $langs->trans("VolumeUnitounce");
  320. $measuring_units[98] = $langs->trans("VolumeUnitlitre");
  321. $measuring_units[99] = $langs->trans("VolumeUnitgallon");
  322. }
  323. return $measuring_units[$unit];
  324. }
  325. ?>