actions_card_service.class.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <?php
  2. /* Copyright (C) 2010-2018 Regis Houssin <regis.houssin@inodbox.com>
  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 htdocs/product/canvas/service/actions_card_service.class.php
  19. * \ingroup service
  20. * \brief File with class of actions for canvas service
  21. */
  22. include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  23. /**
  24. * Class with controller methods for product canvas
  25. */
  26. class ActionsCardService
  27. {
  28. public $targetmodule;
  29. public $canvas;
  30. public $card;
  31. //! Template container
  32. public $tpl = array();
  33. // List of fiels for action=list
  34. public $field_list = array();
  35. public $id;
  36. public $ref;
  37. public $description;
  38. public $note;
  39. public $price;
  40. public $price_min;
  41. /**
  42. * Constructor
  43. *
  44. * @param DoliDB $db Handler acces base de donnees
  45. * @param string $targetmodule Name of directory of module where canvas is stored
  46. * @param string $canvas Name of canvas
  47. * @param string $card Name of tab (sub-canvas)
  48. */
  49. public function __construct($db, $targetmodule, $canvas, $card)
  50. {
  51. $this->db = $db;
  52. $this->targetmodule = $targetmodule;
  53. $this->canvas = $canvas;
  54. $this->card = $card;
  55. $this->module = "service";
  56. $this->name = "service";
  57. $this->definition = "Services canvas";
  58. $this->fieldListName = "product_service";
  59. $this->next_prev_filter = "canvas='service'";
  60. }
  61. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  62. /**
  63. * Assign custom values for canvas (for example into this->tpl to be used by templates)
  64. *
  65. * @param string $action Type of action
  66. * @param integer $id Id of object
  67. * @param string $ref Ref of object
  68. * @return void
  69. */
  70. public function assign_values(&$action, $id = 0, $ref = '')
  71. {
  72. // phpcs:enable
  73. global $limit, $offset, $sortfield, $sortorder;
  74. global $conf, $langs, $user, $mysoc, $canvas;
  75. global $form, $formproduct;
  76. $tmpobject = new Product($this->db);
  77. if (!empty($id) || !empty($ref)) {
  78. $tmpobject->fetch($id, $ref);
  79. }
  80. $this->object = $tmpobject;
  81. foreach ($this->object as $key => $value) {
  82. $this->tpl[$key] = $value;
  83. }
  84. $this->tpl['error'] = get_htmloutput_errors($this->object->error, $this->object->errors);
  85. // canvas
  86. $this->tpl['canvas'] = $this->canvas;
  87. // id
  88. $this->tpl['id'] = $this->id;
  89. // Ref
  90. $this->tpl['ref'] = $this->ref;
  91. // Label
  92. $this->tpl['label'] = $this->label;
  93. // Description
  94. $this->tpl['description'] = nl2br($this->description);
  95. // Statut
  96. $this->tpl['status'] = $this->object->getLibStatut(2);
  97. // Note
  98. $this->tpl['note'] = nl2br($this->note);
  99. if ($action == 'create') {
  100. // Price
  101. $this->tpl['price'] = $this->price;
  102. $this->tpl['price_min'] = $this->price_min;
  103. $this->tpl['price_base_type'] = $form->selectPriceBaseType($this->price_base_type, "price_base_type");
  104. // VAT
  105. $this->tpl['tva_tx'] = $form->load_tva("tva_tx", -1, $mysoc, '');
  106. }
  107. if ($action == 'view') {
  108. $head = product_prepare_head($this->object);
  109. $this->tpl['showrefnav'] = $form->showrefnav($this->object, 'ref', '', 1, 'ref');
  110. $titre = $langs->trans("CardProduct".$this->object->type);
  111. $picto = ($this->object->type == Product::TYPE_SERVICE ? 'service' : 'product');
  112. $this->tpl['showhead'] = dol_get_fiche_head($head, 'card', $titre, 0, $picto);
  113. $this->tpl['showend'] = dol_get_fiche_end();
  114. // Accountancy buy code
  115. $this->tpl['accountancyBuyCodeKey'] = $form->editfieldkey("ProductAccountancyBuyCode", 'productaccountancycodesell', $this->accountancy_code_sell, $this, $user->rights->produit->creer);
  116. $this->tpl['accountancyBuyCodeVal'] = $form->editfieldval("ProductAccountancyBuyCode", 'productaccountancycodesell', $this->accountancy_code_sell, $this, $user->rights->produit->creer);
  117. // Accountancy sell code
  118. $this->tpl['accountancySellCodeKey'] = $form->editfieldkey("ProductAccountancySellCode", 'productaccountancycodebuy', $this->accountancy_code_buy, $this, $user->rights->produit->creer);
  119. $this->tpl['accountancySellCodeVal'] = $form->editfieldval("ProductAccountancySellCode", 'productaccountancycodebuy', $this->accountancy_code_buy, $this, $user->rights->produit->creer);
  120. }
  121. $this->tpl['finished'] = $this->object->finished;
  122. $this->tpl['ref'] = $this->object->ref;
  123. $this->tpl['label'] = $this->object->label;
  124. $this->tpl['id'] = $this->object->id;
  125. $this->tpl['type'] = $this->object->type;
  126. $this->tpl['note'] = $this->object->note;
  127. $this->tpl['seuil_stock_alerte'] = $this->object->seuil_stock_alerte;
  128. // Duration
  129. $this->tpl['duration_value'] = $this->object->duration_value;
  130. if ($action == 'create') {
  131. // Title
  132. $this->tpl['title'] = $langs->trans("NewService");
  133. }
  134. if ($action == 'edit') {
  135. $this->tpl['title'] = $langs->trans('Modify').' '.$langs->trans('Service').' : '.$this->object->ref;
  136. }
  137. if ($action == 'create' || $action == 'edit') {
  138. // Status
  139. $statutarray = array('1' => $langs->trans("OnSell"), '0' => $langs->trans("NotOnSell"));
  140. $this->tpl['status'] = $form->selectarray('statut', $statutarray, $this->object->status);
  141. $statutarray = array('1' => $langs->trans("ProductStatusOnBuy"), '0' => $langs->trans("ProductStatusNotOnBuy"));
  142. $this->tpl['status_buy'] = $form->selectarray('statut_buy', $statutarray, $this->object->status_buy);
  143. $this->tpl['description'] = $this->description;
  144. $this->tpl['note'] = $this->note;
  145. // Duration unit
  146. // TODO creer fonction
  147. $duration_unit = '<input name="duration_unit" type="radio" value="h"'.($this->object->duration_unit == 'h' ? ' checked' : '').'>'.$langs->trans("Hour");
  148. $duration_unit .= '&nbsp; ';
  149. $duration_unit .= '<input name="duration_unit" type="radio" value="d"'.($this->object->duration_unit == 'd' ? ' checked' : '').'>'.$langs->trans("Day");
  150. $duration_unit .= '&nbsp; ';
  151. $duration_unit .= '<input name="duration_unit" type="radio" value="w"'.($this->object->duration_unit == 'w' ? ' checked' : '').'>'.$langs->trans("Week");
  152. $duration_unit .= '&nbsp; ';
  153. $duration_unit .= '<input name="duration_unit" type="radio" value="m"'.($this->object->duration_unit == 'm' ? ' checked' : '').'>'.$langs->trans("Month");
  154. $duration_unit .= '&nbsp; ';
  155. $duration_unit .= '<input name="duration_unit" type="radio" value="y"'.($this->object->duration_unit == 'y' ? ' checked' : '').'>'.$langs->trans("Year");
  156. $this->tpl['duration_unit'] = $duration_unit;
  157. }
  158. if ($action == 'view') {
  159. // Photo
  160. $this->tpl['nblines'] = 4;
  161. if ($this->object->is_photo_available($conf->service->multidir_output[$this->object->entity])) {
  162. $this->tpl['photos'] = $this->object->show_photos('product', $conf->service->multidir_output[$this->object->entity], 1, 1, 0, 0, 0, 80);
  163. }
  164. // Duration
  165. $dur = array();
  166. if ($this->object->duration_value > 1) {
  167. $dur = array("h"=>$langs->trans("Hours"), "d"=>$langs->trans("Days"), "w"=>$langs->trans("Weeks"), "m"=>$langs->trans("Months"), "y"=>$langs->trans("Years"));
  168. } elseif ($this->object->duration_value > 0) {
  169. $dur = array("h"=>$langs->trans("Hour"), "d"=>$langs->trans("Day"), "w"=>$langs->trans("Week"), "m"=>$langs->trans("Month"), "y"=>$langs->trans("Year"));
  170. }
  171. $this->tpl['duration_unit'] = $langs->trans($dur[$this->object->duration_unit]);
  172. $this->tpl['fiche_end'] = dol_get_fiche_end();
  173. }
  174. }
  175. /**
  176. * Fetch field list
  177. *
  178. * @return void
  179. */
  180. private function getFieldListCanvas()
  181. {
  182. global $conf, $langs;
  183. $this->field_list = array();
  184. $sql = "SELECT rowid, name, alias, title, align, sort, search, visible, enabled, rang";
  185. $sql .= " FROM ".MAIN_DB_PREFIX."c_field_list";
  186. $sql .= " WHERE element = '".$this->db->escape($this->fieldListName)."'";
  187. $sql .= " AND entity = ".$conf->entity;
  188. $sql .= " ORDER BY rang ASC";
  189. $resql = $this->db->query($sql);
  190. if ($resql) {
  191. $num = $this->db->num_rows($resql);
  192. $i = 0;
  193. while ($i < $num) {
  194. $fieldlist = array();
  195. $obj = $this->db->fetch_object($resql);
  196. $fieldlist["id"] = $obj->rowid;
  197. $fieldlist["name"] = $obj->name;
  198. $fieldlist["alias"] = $obj->alias;
  199. $fieldlist["title"] = $langs->trans($obj->title);
  200. $fieldlist["align"] = $obj->align;
  201. $fieldlist["sort"] = $obj->sort;
  202. $fieldlist["search"] = $obj->search;
  203. $fieldlist["visible"] = $obj->visible;
  204. $fieldlist["enabled"] = verifCond($obj->enabled);
  205. $fieldlist["order"] = $obj->rang;
  206. array_push($this->field_list, $fieldlist);
  207. $i++;
  208. }
  209. $this->db->free($resql);
  210. } else {
  211. dol_print_error($this->db, $sql);
  212. }
  213. }
  214. }