2019-02-12 14:45:21 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
namespace :fablab do
|
|
|
|
namespace :setup do
|
2019-02-27 17:44:52 +01:00
|
|
|
desc 'assign environment value to all invoices'
|
|
|
|
task set_environment_to_invoices: :environment do
|
|
|
|
Invoice.all.each do |i|
|
|
|
|
i.environment = Rails.env
|
|
|
|
i.save!
|
|
|
|
end
|
|
|
|
end
|
2019-03-13 12:03:14 +01:00
|
|
|
|
|
|
|
desc 'add missing VAT rate to history'
|
|
|
|
task :add_vat_rate, %i[rate date] => :environment do |_task, args|
|
2020-03-25 17:58:53 +01:00
|
|
|
raise 'Missing argument. Usage exemple: rails fablab:setup:add_vat_rate[20,2014-01-01]. Use 0 to disable' unless args.rate && args.date
|
2019-03-13 12:03:14 +01:00
|
|
|
|
2019-03-27 12:58:08 +01:00
|
|
|
if args.rate == '0'
|
2019-03-13 12:03:14 +01:00
|
|
|
setting = Setting.find_by(name: 'invoice_VAT-active')
|
|
|
|
HistoryValue.create!(
|
|
|
|
setting_id: setting.id,
|
|
|
|
user_id: User.admins.first.id,
|
|
|
|
value: 'false',
|
|
|
|
created_at: DateTime.parse(args.date)
|
|
|
|
)
|
|
|
|
else
|
|
|
|
setting = Setting.find_by(name: 'invoice_VAT-rate')
|
|
|
|
HistoryValue.create!(
|
|
|
|
setting_id: setting.id,
|
|
|
|
user_id: User.admins.first.id,
|
|
|
|
value: args.rate,
|
|
|
|
created_at: DateTime.parse(args.date)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2019-06-11 16:56:11 +02:00
|
|
|
|
2019-06-12 12:22:38 +02:00
|
|
|
desc 'migrate PDF invoices to folders numbered by invoicing_profile'
|
|
|
|
task migrate_pdf_invoices_folders: :environment do
|
2019-06-17 15:01:23 +02:00
|
|
|
puts 'No invoices, exiting...' and return if Invoice.count.zero?
|
|
|
|
|
2019-06-11 16:56:11 +02:00
|
|
|
require 'fileutils'
|
|
|
|
Invoice.all.each do |i|
|
|
|
|
invoicing_profile = i.invoicing_profile
|
|
|
|
user_id = invoicing_profile.user_id
|
|
|
|
|
|
|
|
src = "invoices/#{user_id}/#{i.filename}"
|
|
|
|
dest = "tmp/invoices/#{invoicing_profile.id}"
|
|
|
|
|
2019-06-12 12:22:38 +02:00
|
|
|
if FileTest.exist?(src)
|
|
|
|
FileUtils.mkdir_p dest
|
|
|
|
FileUtils.mv src, "#{dest}/#{i.filename}", force: true
|
|
|
|
end
|
2019-06-11 16:56:11 +02:00
|
|
|
end
|
|
|
|
FileUtils.rm_rf 'invoices'
|
|
|
|
FileUtils.mv 'tmp/invoices', 'invoices'
|
|
|
|
end
|
2020-05-19 16:20:59 +02:00
|
|
|
|
2020-11-16 16:37:40 +01:00
|
|
|
desc 'add model for payment-schedules reference'
|
|
|
|
task add_schedule_reference: :environment do
|
|
|
|
setting = Setting.find_by(name: 'invoice_reference')
|
|
|
|
current = setting.value
|
|
|
|
setting.value = "#{current}S[/E]" unless /S\[([^\]]+)\]/.match?(current)
|
|
|
|
end
|
|
|
|
|
2020-05-19 16:20:59 +02:00
|
|
|
desc 'migrate environment variables to the database (settings)'
|
|
|
|
task env_to_db: :environment do
|
2020-05-26 10:53:49 +02:00
|
|
|
include ApplicationHelper
|
|
|
|
|
2020-05-19 16:20:59 +02:00
|
|
|
mapping = [
|
2020-07-01 12:31:52 +02:00
|
|
|
%w[_ PHONE_REQUIRED phone_required],
|
2020-05-26 10:53:49 +02:00
|
|
|
%w[_ GA_ID tracking_id],
|
2020-07-01 12:31:52 +02:00
|
|
|
%w[_ BOOK_SLOT_AT_SAME_TIME book_overlapping_slots],
|
|
|
|
%w[_ SLOT_DURATION slot_duration],
|
|
|
|
%w[_ EVENTS_IN_CALENDAR events_in_calendar],
|
|
|
|
%w[! FABLAB_WITHOUT_SPACES spaces_module],
|
|
|
|
%w[! FABLAB_WITHOUT_PLANS plans_module],
|
|
|
|
%w[! FABLAB_WITHOUT_INVOICES invoicing_module],
|
2020-05-27 15:39:39 +02:00
|
|
|
%w[_ FACEBOOK_APP_ID facebook_app_id],
|
2020-05-27 16:35:30 +02:00
|
|
|
%w[_ TWITTER_NAME twitter_analytics],
|
|
|
|
%w[_ RECAPTCHA_SITE_KEY recaptcha_site_key],
|
2020-05-27 18:49:53 +02:00
|
|
|
%w[_ RECAPTCHA_SECRET_KEY recaptcha_secret_key],
|
2020-07-01 12:31:52 +02:00
|
|
|
%w[_ FEATURE_TOUR_DISPLAY feature_tour_display],
|
2020-06-01 17:32:32 +02:00
|
|
|
%w[_ DEFAULT_MAIL_FROM email_from],
|
2020-06-03 16:25:13 +02:00
|
|
|
%w[_ DISQUS_SHORTNAME disqus_shortname],
|
|
|
|
%w[_ ALLOWED_EXTENSIONS allowed_cad_extensions],
|
2020-06-08 11:38:49 +02:00
|
|
|
%w[_ ALLOWED_MIME_TYPES allowed_cad_mime_types],
|
|
|
|
%w[_ OPENLAB_APP_ID openlab_app_id],
|
2020-06-08 16:15:44 +02:00
|
|
|
%w[_ OPENLAB_APP_SECRET openlab_app_secret],
|
2020-06-08 17:42:59 +02:00
|
|
|
%w[_ OPENLAB_DEFAULT openlab_default],
|
2020-07-01 12:31:52 +02:00
|
|
|
%w[! FABLAB_WITHOUT_ONLINE_PAYMENT online_payment_module],
|
2020-06-09 13:09:31 +02:00
|
|
|
%w[_ STRIPE_PUBLISHABLE_KEY stripe_public_key],
|
2020-06-10 16:37:11 +02:00
|
|
|
%w[_ STRIPE_API_KEY stripe_secret_key],
|
2020-06-15 10:58:15 +02:00
|
|
|
%w[_ STRIPE_CURRENCY stripe_currency],
|
2020-06-15 11:57:13 +02:00
|
|
|
%w[_ INVOICE_PREFIX invoice_prefix FabManager_invoice],
|
2020-07-01 12:31:52 +02:00
|
|
|
%w[_ USER_CONFIRMATION_NEEDED_TO_SIGN_IN confirmation_required],
|
|
|
|
%w[! FABLAB_WITHOUT_WALLET wallet_module],
|
|
|
|
%w[! FABLAB_WITHOUT_STATISTICS statistics_module]
|
2020-05-19 16:20:59 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
mapping.each do |m|
|
2020-05-26 10:53:49 +02:00
|
|
|
setting = Setting.find_or_initialize_by(name: m[2])
|
|
|
|
value = ENV.fetch(m[1], m[3])
|
|
|
|
next unless value
|
|
|
|
|
2020-05-27 15:39:39 +02:00
|
|
|
# if the array starts with a "!", invert the boolean value
|
2020-05-26 10:53:49 +02:00
|
|
|
value = (!str_to_bool(value)).to_s if m[0] == '!'
|
|
|
|
setting.value = value
|
|
|
|
setting.save
|
2020-05-19 16:20:59 +02:00
|
|
|
end
|
|
|
|
end
|
2019-02-12 14:45:21 +01:00
|
|
|
end
|
2019-02-13 10:59:44 +01:00
|
|
|
end
|