20230607083454_time_accounting_enhancements.rb 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class TimeAccountingEnhancements < ActiveRecord::Migration[5.0]
  3. def change
  4. # return if it's a new setup
  5. return if !Setting.exists?(name: 'system_init_done')
  6. create_ticket_time_accounting_types_table
  7. create_ticket_time_accounting_unit_settings
  8. create_ticket_time_accounting_type_settings
  9. end
  10. private
  11. def create_ticket_time_accounting_types_table
  12. create_table :ticket_time_accounting_types do |t|
  13. t.column :name, :string, limit: 250, null: false
  14. t.column :note, :string, limit: 250, null: true
  15. t.column :active, :boolean, null: false, default: true
  16. t.column :updated_by_id, :integer, null: false
  17. t.column :created_by_id, :integer, null: false
  18. t.timestamps limit: 3, null: false
  19. end
  20. add_index :ticket_time_accounting_types, [:name], unique: true
  21. add_foreign_key :ticket_time_accounting_types, :users, column: :created_by_id
  22. add_foreign_key :ticket_time_accounting_types, :users, column: :updated_by_id
  23. change_table :ticket_time_accountings do |t|
  24. t.column :type_id, :integer, null: true
  25. end
  26. add_foreign_key :ticket_time_accountings, :ticket_time_accounting_types, column: :type_id
  27. Ticket::TimeAccounting.reset_column_information
  28. end
  29. def create_ticket_time_accounting_unit_settings
  30. Setting.create_if_not_exists(
  31. title: 'Time Accounting Unit',
  32. name: 'time_accounting_unit',
  33. area: 'Web::Base',
  34. description: 'Defines the unit to be shown next to the time accounting input field.',
  35. options: {
  36. form: [
  37. {},
  38. ],
  39. },
  40. preferences: {
  41. authentication: true,
  42. permission: ['admin.time_accounting'],
  43. },
  44. state: '',
  45. frontend: true
  46. )
  47. Setting.create_if_not_exists(
  48. title: 'Time Accounting Custom Unit',
  49. name: 'time_accounting_unit_custom',
  50. area: 'Web::Base',
  51. description: 'Defines the custom unit to be shown next to the time accounting input field.',
  52. options: {
  53. form: [
  54. {},
  55. ],
  56. },
  57. preferences: {
  58. authentication: true,
  59. permission: ['admin.time_accounting'],
  60. },
  61. state: '',
  62. frontend: true
  63. )
  64. end
  65. def create_ticket_time_accounting_type_settings
  66. Setting.create_if_not_exists(
  67. title: 'Time Accounting Types',
  68. name: 'time_accounting_types',
  69. area: 'Web::Base',
  70. description: 'Defines if the time accounting types are enabled.',
  71. options: {
  72. form: [
  73. {},
  74. ],
  75. },
  76. preferences: {
  77. authentication: true,
  78. permission: ['admin.time_accounting'],
  79. },
  80. state: false,
  81. frontend: true
  82. )
  83. Setting.create_if_not_exists(
  84. title: 'Time Accounting Default Type',
  85. name: 'time_accounting_type_default',
  86. area: 'Web::Base',
  87. description: 'Defines the default time accounting type.',
  88. options: {
  89. form: [
  90. {},
  91. ],
  92. },
  93. preferences: {
  94. authentication: true,
  95. permission: ['admin.time_accounting'],
  96. },
  97. state: '',
  98. frontend: true
  99. )
  100. end
  101. end