1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-02-19 13:54:25 +01:00

add watermark to invoices in dev/staging/test environment

This commit is contained in:
Sylvain 2019-02-27 17:44:52 +01:00
parent 672029876a
commit e543f1fe3e
7 changed files with 35 additions and 1 deletions

6
CHANGELOG_PREMIUM.md Normal file
View File

@ -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

View File

@ -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

BIN
app/pdfs/data/watermark.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View File

@ -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

View File

@ -0,0 +1,5 @@
class AddEnvironmentToInvoice < ActiveRecord::Migration
def change
add_column :invoices, :environment, :string
end
end

View File

@ -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

View File

@ -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