modReceiptPrinter.class.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. /* Copyright (C) 2014-2015 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2015 Frederic France <frederic.france@free.fr>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. /** \defgroup printing Module Receipt Printer
  19. * \brief Module for activation of printing icon to make receipt ticket
  20. */
  21. /**
  22. * \file htdocs/core/modules/modReceiptPrinter.class.php
  23. * \ingroup printing
  24. * \brief Description and activation file for the module Receipt Printer
  25. */
  26. include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
  27. /**
  28. * Class to describe and activate module Receipt Printer
  29. */
  30. class modReceiptPrinter extends DolibarrModules
  31. {
  32. /**
  33. * Constructor
  34. *
  35. * @param DoliDB $db Database handler
  36. */
  37. public function __construct($db)
  38. {
  39. $this->db = $db;
  40. $this->numero = 67000;
  41. // Family can be 'crm','financial','hr','projects','products','ecm','technic','other'
  42. // It is used to group modules in module setup page
  43. $this->family = "interface";
  44. $this->module_position = '53';
  45. // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
  46. $this->name = preg_replace('/^mod/i', '', get_class($this));
  47. // Module description, used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module)
  48. $this->description = "ReceiptPrinterDesc";
  49. // Possible values for version are: 'development', 'experimental', 'dolibarr' or 'dolibarr_deprecated' or version
  50. $this->version = 'dolibarr';
  51. $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
  52. // Name of image file used for this module.
  53. // If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue'
  54. // If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module'
  55. $this->picto = 'printer';
  56. // Data directories to create when module is enabled.
  57. $this->dirs = array();
  58. // Config pages
  59. $this->config_page_url = array("receiptprinter.php");
  60. // Dependencies
  61. $this->hidden = false; // A condition to hide module
  62. $this->depends = array(); // List of module class names as string that must be enabled if this module is enabled
  63. $this->requiredby = array(); // List of module ids to disable if this one is disabled
  64. $this->conflictwith = array(); // List of module class names as string this module is in conflict with
  65. $this->phpmin = array(5, 6); // Minimum version of PHP required by module
  66. $this->need_dolibarr_version = array(3, 9, -2); // Minimum version of Dolibarr required by module
  67. $this->conflictwith = array();
  68. $this->langfiles = array("receiptprinter");
  69. // Constants
  70. $this->const = array();
  71. // Boxes
  72. $this->boxes = array();
  73. // Permissions
  74. $this->rights = array();
  75. $this->rights_class = 'receiptprinter';
  76. $r = 0;
  77. // $this->rights[$r][0] Id permission (unique tous modules confondus)
  78. // $this->rights[$r][1] Libelle par defaut si traduction de cle "PermissionXXX" non trouvee (XXX = Id permission)
  79. // $this->rights[$r][2] Non utilise
  80. // $this->rights[$r][3] 1=Permis par defaut, 0=Non permis par defaut
  81. // $this->rights[$r][4] Niveau 1 pour nommer permission dans code
  82. // $this->rights[$r][5] Niveau 2 pour nommer permission dans code
  83. $r++;
  84. $this->rights[$r][0] = 67001;
  85. $this->rights[$r][1] = 'ReceiptPrinter';
  86. $this->rights[$r][2] = 'r';
  87. $this->rights[$r][3] = 0;
  88. $this->rights[$r][4] = 'read';
  89. // Main menu entries
  90. $this->menus = array(); // List of menus to add
  91. $r = 0;
  92. // This is to declare the Top Menu entry:
  93. //$this->menu[$r]=array( 'fk_menu'=>'fk_mainmenu=home,fk_leftmenu=admintools', // Put 0 if this is a top menu
  94. // 'type'=>'left', // This is a Top menu entry
  95. // 'titre'=>'MenuDirectPrinting',
  96. // 'mainmenu'=>'printing',
  97. // 'url'=>'/printing/index.php',
  98. // 'langs'=>'printing', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
  99. // 'position'=>300,
  100. // 'enabled'=>'$conf->printing->enabled && preg_match(\'/^(admintools|all)/\',$leftmenu)',
  101. // 'perms'=>'$user->rights->printing->read', // Use 'perms'=>'1' if you want your menu with no permission rules
  102. // 'target'=>'',
  103. // 'user'=>0); // 0=Menu for internal users, 1=external users, 2=both
  104. $r++;
  105. }
  106. /**
  107. * Function called when module is enabled.
  108. * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
  109. * It also creates data directories
  110. *
  111. * @param string $options Options when enabling module ('', 'noboxes')
  112. * @return int 1 if OK, 0 if KO
  113. */
  114. public function init($options = '')
  115. {
  116. global $conf, $langs;
  117. // Clean before activation
  118. $this->remove($options);
  119. $templateexample = '{dol_align_center}\r\n{dol_print_text}{dol_value_mysoc_name}\r\n{dol_print_text}{dol_value_mysoc_address}\r\n{dol_print_text}{dol_value_mysoc_zip}{dol_value_mysoc_town}\r\n{dol_line_feed}\r\n{dol_print_text}Facture {dol_value_object_ref}\r\n{dol_line_feed}\r\n{dol_align_left}\r\n{dol_print_object_lines}\r\n{dol_line_feed}\r\n{dol_print_object_tax}\r\n{dol_line_feed}\r\n{dol_print_object_total}\r\n{dol_line_feed}\r\n{dol_cut_paper_full}';
  120. $sql = array(
  121. "CREATE TABLE IF NOT EXISTS ".MAIN_DB_PREFIX."printer_receipt (rowid integer AUTO_INCREMENT PRIMARY KEY, name varchar(128), fk_type integer, fk_profile integer, parameter varchar(128), entity integer) ENGINE=innodb;",
  122. "CREATE TABLE IF NOT EXISTS ".MAIN_DB_PREFIX."printer_receipt_template (rowid integer AUTO_INCREMENT PRIMARY KEY, name varchar(128), template text, entity integer) ENGINE=innodb;",
  123. "DELETE FROM ".MAIN_DB_PREFIX."printer_receipt_template WHERE name = '".$langs->trans('Example')."';",
  124. "INSERT INTO ".MAIN_DB_PREFIX."printer_receipt_template (name,template,entity) VALUES ('".$langs->trans('Example')."', '".$templateexample."', 1);",
  125. );
  126. return $this->_init($sql, $options);
  127. }
  128. }