actions_card_service.class.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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 $conf, $langs, $user, $mysoc, $canvas;
  74. global $form;
  75. $tmpobject = new Product($this->db);
  76. if (!empty($id) || !empty($ref)) {
  77. $tmpobject->fetch($id, $ref);
  78. }
  79. $this->object = $tmpobject;
  80. foreach ($this->object as $key => $value) {
  81. $this->tpl[$key] = $value;
  82. }
  83. $this->tpl['error'] = get_htmloutput_errors($this->object->error, $this->object->errors);
  84. // canvas
  85. $this->tpl['canvas'] = $this->canvas;
  86. // id
  87. $this->tpl['id'] = $this->id;
  88. // Ref
  89. $this->tpl['ref'] = $this->ref;
  90. // Label
  91. $this->tpl['label'] = $this->label;
  92. // Description
  93. $this->tpl['description'] = nl2br($this->description);
  94. // Statut
  95. $this->tpl['status'] = $this->object->getLibStatut(2);
  96. // Note
  97. $this->tpl['note'] = nl2br($this->note);
  98. if ($action == 'create') {
  99. // Price
  100. $this->tpl['price'] = $this->price;
  101. $this->tpl['price_min'] = $this->price_min;
  102. $this->tpl['price_base_type'] = $form->selectPriceBaseType($this->price_base_type, "price_base_type");
  103. // VAT
  104. $this->tpl['tva_tx'] = $form->load_tva("tva_tx", -1, $mysoc, '');
  105. }
  106. if ($action == 'view') {
  107. $head = product_prepare_head($this->object);
  108. $this->tpl['showrefnav'] = $form->showrefnav($this->object, 'ref', '', 1, 'ref');
  109. $titre = $langs->trans("CardProduct".$this->object->type);
  110. $picto = ($this->object->type == Product::TYPE_SERVICE ? 'service' : 'product');
  111. $this->tpl['showhead'] = dol_get_fiche_head($head, 'card', $titre, 0, $picto);
  112. $this->tpl['showend'] = dol_get_fiche_end();
  113. // Accountancy buy code
  114. $this->tpl['accountancyBuyCodeKey'] = $form->editfieldkey("ProductAccountancyBuyCode", 'productaccountancycodesell', $this->accountancy_code_sell, $this, $user->rights->produit->creer);
  115. $this->tpl['accountancyBuyCodeVal'] = $form->editfieldval("ProductAccountancyBuyCode", 'productaccountancycodesell', $this->accountancy_code_sell, $this, $user->rights->produit->creer);
  116. // Accountancy sell code
  117. $this->tpl['accountancySellCodeKey'] = $form->editfieldkey("ProductAccountancySellCode", 'productaccountancycodebuy', $this->accountancy_code_buy, $this, $user->rights->produit->creer);
  118. $this->tpl['accountancySellCodeVal'] = $form->editfieldval("ProductAccountancySellCode", 'productaccountancycodebuy', $this->accountancy_code_buy, $this, $user->rights->produit->creer);
  119. }
  120. $this->tpl['finished'] = $this->object->finished;
  121. $this->tpl['ref'] = $this->object->ref;
  122. $this->tpl['label'] = $this->object->label;
  123. $this->tpl['id'] = $this->object->id;
  124. $this->tpl['type'] = $this->object->type;
  125. $this->tpl['note'] = $this->object->note_private;
  126. $this->tpl['seuil_stock_alerte'] = $this->object->seuil_stock_alerte;
  127. // Duration
  128. $this->tpl['duration_value'] = $this->object->duration_value;
  129. if ($action == 'create') {
  130. // Title
  131. $this->tpl['title'] = $langs->trans("NewService");
  132. }
  133. if ($action == 'edit') {
  134. $this->tpl['title'] = $langs->trans('Modify').' '.$langs->trans('Service').' : '.$this->object->ref;
  135. }
  136. if ($action == 'create' || $action == 'edit') {
  137. // Status
  138. $statutarray = array('1' => $langs->trans("OnSell"), '0' => $langs->trans("NotOnSell"));
  139. $this->tpl['status'] = $form->selectarray('statut', $statutarray, $this->object->status);
  140. $statutarray = array('1' => $langs->trans("ProductStatusOnBuy"), '0' => $langs->trans("ProductStatusNotOnBuy"));
  141. $this->tpl['status_buy'] = $form->selectarray('statut_buy', $statutarray, $this->object->status_buy);
  142. $this->tpl['description'] = $this->description;
  143. $this->tpl['note'] = $this->note;
  144. // Duration unit
  145. // TODO creer fonction
  146. $duration_unit = '<input name="duration_unit" type="radio" value="h"'.($this->object->duration_unit == 'h' ? ' checked' : '').'>'.$langs->trans("Hour");
  147. $duration_unit .= '&nbsp; ';
  148. $duration_unit .= '<input name="duration_unit" type="radio" value="d"'.($this->object->duration_unit == 'd' ? ' checked' : '').'>'.$langs->trans("Day");
  149. $duration_unit .= '&nbsp; ';
  150. $duration_unit .= '<input name="duration_unit" type="radio" value="w"'.($this->object->duration_unit == 'w' ? ' checked' : '').'>'.$langs->trans("Week");
  151. $duration_unit .= '&nbsp; ';
  152. $duration_unit .= '<input name="duration_unit" type="radio" value="m"'.($this->object->duration_unit == 'm' ? ' checked' : '').'>'.$langs->trans("Month");
  153. $duration_unit .= '&nbsp; ';
  154. $duration_unit .= '<input name="duration_unit" type="radio" value="y"'.($this->object->duration_unit == 'y' ? ' checked' : '').'>'.$langs->trans("Year");
  155. $this->tpl['duration_unit'] = $duration_unit;
  156. }
  157. if ($action == 'view') {
  158. // Photo
  159. $this->tpl['nblines'] = 4;
  160. if ($this->object->is_photo_available($conf->service->multidir_output[$this->object->entity])) {
  161. $this->tpl['photos'] = $this->object->show_photos('product', $conf->service->multidir_output[$this->object->entity], 1, 1, 0, 0, 0, 80);
  162. }
  163. // Duration
  164. $dur = array();
  165. if ($this->object->duration_value > 1) {
  166. $dur = array("h"=>$langs->trans("Hours"), "d"=>$langs->trans("Days"), "w"=>$langs->trans("Weeks"), "m"=>$langs->trans("Months"), "y"=>$langs->trans("Years"));
  167. } elseif ($this->object->duration_value > 0) {
  168. $dur = array("h"=>$langs->trans("Hour"), "d"=>$langs->trans("Day"), "w"=>$langs->trans("Week"), "m"=>$langs->trans("Month"), "y"=>$langs->trans("Year"));
  169. }
  170. $this->tpl['duration_unit'] = $langs->trans($dur[$this->object->duration_unit]);
  171. $this->tpl['fiche_end'] = dol_get_fiche_end();
  172. }
  173. }
  174. /**
  175. * Fetch field list
  176. *
  177. * @return void
  178. */
  179. private function getFieldListCanvas()
  180. {
  181. global $conf, $langs;
  182. $this->field_list = array();
  183. $sql = "SELECT rowid, name, alias, title, align, sort, search, visible, enabled, rang";
  184. $sql .= " FROM ".MAIN_DB_PREFIX."c_field_list";
  185. $sql .= " WHERE element = '".$this->db->escape($this->fieldListName)."'";
  186. $sql .= " AND entity = ".$conf->entity;
  187. $sql .= " ORDER BY rang ASC";
  188. $resql = $this->db->query($sql);
  189. if ($resql) {
  190. $num = $this->db->num_rows($resql);
  191. $i = 0;
  192. while ($i < $num) {
  193. $fieldlist = array();
  194. $obj = $this->db->fetch_object($resql);
  195. $fieldlist["id"] = $obj->rowid;
  196. $fieldlist["name"] = $obj->name;
  197. $fieldlist["alias"] = $obj->alias;
  198. $fieldlist["title"] = $langs->trans($obj->title);
  199. $fieldlist["align"] = $obj->align;
  200. $fieldlist["sort"] = $obj->sort;
  201. $fieldlist["search"] = $obj->search;
  202. $fieldlist["visible"] = $obj->visible;
  203. $fieldlist["enabled"] = verifCond($obj->enabled);
  204. $fieldlist["order"] = $obj->rang;
  205. array_push($this->field_list, $fieldlist);
  206. $i++;
  207. }
  208. $this->db->free($resql);
  209. } else {
  210. dol_print_error($this->db, $sql);
  211. }
  212. }
  213. }