diff --git a/CHANGELOG_PREMIUM.md b/CHANGELOG_PREMIUM.md new file mode 100644 index 000000000..70f9e322d --- /dev/null +++ b/CHANGELOG_PREMIUM.md @@ -0,0 +1,6 @@ +# Changelog Fab Manager Premium + +- Based on fab-manager v2.8.xx +- [TODO DEPLOY] rake fablab:setup:set_environment_to_invoices +- [TODO DEPLOY] rake fablab:setup:chain_invoices_items_records +- [TODO DEPLOY] rake fablab:setup:chain_invoices_records diff --git a/app/models/invoice.rb b/app/models/invoice.rb index ae8a90f57..4754ab089 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -14,6 +14,7 @@ class Invoice < ActiveRecord::Base has_one :avoir, class_name: 'Invoice', foreign_key: :invoice_id, dependent: :destroy + before_create :add_environment after_create :update_reference, :chain_record after_commit :generate_and_send_invoice, on: [:create], if: :persisted? @@ -211,6 +212,10 @@ class Invoice < ActiveRecord::Base total - (wallet_amount || 0) end + def add_environment + self.environment = Rails.env + end + def chain_record self.footprint = compute_footprint end diff --git a/app/pdfs/data/watermark.png b/app/pdfs/data/watermark.png new file mode 100644 index 000000000..d6cdec1e6 Binary files /dev/null and b/app/pdfs/data/watermark.png differ diff --git a/app/pdfs/pdf/invoice.rb b/app/pdfs/pdf/invoice.rb index c958e5cb6..152dfc43b 100644 --- a/app/pdfs/pdf/invoice.rb +++ b/app/pdfs/pdf/invoice.rb @@ -334,6 +334,15 @@ class PDF::Invoice < Prawn::Document text line, align: :right, leading: 4, inline_format: true end end + + # factice watermark + return unless %w[staging test development].include?(invoice.environment) + + transparent(0.3) do + rotate(45, origin: [0, 0]) do + image "#{Rails.root}/app/pdfs/data/watermark.png", at: [90, 150] + end + end end private diff --git a/db/migrate/20190227143153_add_environment_to_invoice.rb b/db/migrate/20190227143153_add_environment_to_invoice.rb new file mode 100644 index 000000000..285051106 --- /dev/null +++ b/db/migrate/20190227143153_add_environment_to_invoice.rb @@ -0,0 +1,5 @@ +class AddEnvironmentToInvoice < ActiveRecord::Migration + def change + add_column :invoices, :environment, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 639fdd150..9d7ae7914 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20190225102847) do +ActiveRecord::Schema.define(version: 20190227143153) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -277,6 +277,7 @@ ActiveRecord::Schema.define(version: 20190225102847) do t.integer "wallet_transaction_id" t.integer "coupon_id" t.string "footprint" + t.string "environment" end add_index "invoices", ["coupon_id"], name: "index_invoices_on_coupon_id", using: :btree diff --git a/lib/tasks/fablab/setup.rake b/lib/tasks/fablab/setup.rake index eecf11e39..891c7cd2c 100644 --- a/lib/tasks/fablab/setup.rake +++ b/lib/tasks/fablab/setup.rake @@ -21,5 +21,13 @@ namespace :fablab do i.save! end end + + 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 end end