mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-19 13:54:25 +01:00
link statistic profile to invoices
This commit is contained in:
parent
818d1357a9
commit
37b9e3da60
@ -13,6 +13,7 @@ class Invoice < ActiveRecord::Base
|
||||
has_many :invoice_items, dependent: :destroy
|
||||
accepts_nested_attributes_for :invoice_items
|
||||
belongs_to :invoicing_profile
|
||||
belongs_to :statistic_profile
|
||||
belongs_to :wallet_transaction
|
||||
belongs_to :coupon
|
||||
|
||||
|
@ -292,12 +292,12 @@ class StatisticService
|
||||
result = []
|
||||
member = Role.find_by(name: 'member')
|
||||
StatisticProfile.where('role_id = :member AND created_at >= :start_date AND created_at <= :end_date', options.merge(member: member.id))
|
||||
.each do |u|
|
||||
next if u.need_completion?
|
||||
.each do |sp|
|
||||
next if sp.user&.need_completion?
|
||||
|
||||
result.push OpenStruct.new({
|
||||
date: options[:start_date].to_date
|
||||
}.merge(user_info(u)))
|
||||
}.merge(user_info(sp)))
|
||||
end
|
||||
result
|
||||
end
|
||||
|
@ -12,6 +12,7 @@ class CreateStatisticProfile < ActiveRecord::Migration
|
||||
|
||||
add_reference :reservations, :statistic_profile, index: true, foreign_key: true
|
||||
add_reference :subscriptions, :statistic_profile, index: true, foreign_key: true
|
||||
add_reference :invoices, :statistic_profile, index: true, foreign_key: true
|
||||
|
||||
add_column :projects, :author_statistic_profile_id, :integer, index: true
|
||||
add_foreign_key :projects, :statistic_profiles, column: :author_statistic_profile_id
|
@ -14,6 +14,7 @@ class MigrateUserToInvoicingProfile < ActiveRecord::Migration
|
||||
Invoice.order(:id).all.each do |i|
|
||||
user = User.find(i.user_id)
|
||||
i.update_column('invoicing_profile_id', user.invoicing_profile.id)
|
||||
i.update_column('statistic_profile_id', user.statistic_profile.id)
|
||||
i.update_column('user_id', nil)
|
||||
end
|
||||
# chain all records
|
||||
@ -32,6 +33,7 @@ class MigrateUserToInvoicingProfile < ActiveRecord::Migration
|
||||
Invoice.order(:created_at).all.each do |i|
|
||||
i.update_column('user_id', i.invoicing_profile.user_id)
|
||||
i.update_column('invoicing_profile_id', nil)
|
||||
i.update_column('statistic_profile_id', nil)
|
||||
end
|
||||
# chain all records
|
||||
InvoiceItem.order(:id).all.each(&:chain_record)
|
||||
|
@ -280,11 +280,13 @@ ActiveRecord::Schema.define(version: 20190606074801) do
|
||||
t.string "environment"
|
||||
t.integer "operator_id"
|
||||
t.integer "invoicing_profile_id"
|
||||
t.integer "statistic_profile_id"
|
||||
end
|
||||
|
||||
add_index "invoices", ["coupon_id"], name: "index_invoices_on_coupon_id", using: :btree
|
||||
add_index "invoices", ["invoice_id"], name: "index_invoices_on_invoice_id", using: :btree
|
||||
add_index "invoices", ["invoicing_profile_id"], name: "index_invoices_on_invoicing_profile_id", using: :btree
|
||||
add_index "invoices", ["statistic_profile_id"], name: "index_invoices_on_statistic_profile_id", using: :btree
|
||||
add_index "invoices", ["wallet_transaction_id"], name: "index_invoices_on_wallet_transaction_id", using: :btree
|
||||
|
||||
create_table "invoicing_profiles", force: :cascade do |t|
|
||||
@ -908,6 +910,7 @@ ActiveRecord::Schema.define(version: 20190606074801) do
|
||||
add_foreign_key "history_values", "settings"
|
||||
add_foreign_key "invoices", "coupons"
|
||||
add_foreign_key "invoices", "invoicing_profiles"
|
||||
add_foreign_key "invoices", "statistic_profiles"
|
||||
add_foreign_key "invoices", "users", column: "operator_id"
|
||||
add_foreign_key "invoices", "wallet_transactions"
|
||||
add_foreign_key "invoicing_profiles", "users"
|
||||
|
15
test/fixtures/invoices.yml
vendored
15
test/fixtures/invoices.yml
vendored
@ -8,6 +8,7 @@ invoice_1:
|
||||
created_at: 2012-03-12 11:03:31.651441000 Z
|
||||
updated_at: 2012-03-12 11:03:31.651441000 Z
|
||||
invoicing_profile_id: 3
|
||||
statistic_profile_id: 3
|
||||
reference: 1604001/VL
|
||||
avoir_mode:
|
||||
avoir_date:
|
||||
@ -15,7 +16,7 @@ invoice_1:
|
||||
type:
|
||||
subscription_to_expire:
|
||||
description:
|
||||
footprint: d477d23a473c565e2c379263d4c86c9cc80cdd88adc9a3ff7246afccec0e2a18
|
||||
footprint: e7fffd325cacbb76218626ea2a35a7a9f052c208c41aac13f70c31eae9f81bc7
|
||||
environment: test
|
||||
operator_id:
|
||||
|
||||
@ -28,6 +29,7 @@ invoice_2:
|
||||
created_at: 2012-03-12 13:40:22.342717000 Z
|
||||
updated_at: 2012-03-12 13:40:22.342717000 Z
|
||||
invoicing_profile_id: 4
|
||||
statistic_profile_id: 4
|
||||
reference: '1604002'
|
||||
avoir_mode:
|
||||
avoir_date:
|
||||
@ -35,7 +37,7 @@ invoice_2:
|
||||
type:
|
||||
subscription_to_expire:
|
||||
description:
|
||||
footprint: 4cef4ec78543075af4d782ef919ca95ccbdfbd3bad91f2dfe01fe9b5113eb4d4
|
||||
footprint: bd0b739c211b40abed7ddb07bc054281513acab4a0adde6c416dc1715dd9f005
|
||||
environment: test
|
||||
operator_id:
|
||||
|
||||
@ -48,6 +50,7 @@ invoice_3:
|
||||
created_at: 2015-06-10 11:20:01.341130000 Z
|
||||
updated_at: 2015-06-10 11:20:01.341130000 Z
|
||||
invoicing_profile_id: 7
|
||||
statistic_profile_id: 7
|
||||
reference: '1203001'
|
||||
avoir_mode:
|
||||
avoir_date:
|
||||
@ -55,7 +58,7 @@ invoice_3:
|
||||
type:
|
||||
subscription_to_expire:
|
||||
description:
|
||||
footprint: 295f687cfc1df1c9dfe6759f0c3a4d7e92bc8959ee909d944537dffa6b8a0a5e
|
||||
footprint: ab00a9318314b75d29ec220e00c96e738d608d64423b1c5abb25786551f12f8b
|
||||
environment: test
|
||||
operator_id:
|
||||
|
||||
@ -69,6 +72,7 @@ invoice_4:
|
||||
created_at: 2016-04-05 08:35:52.931187000 Z
|
||||
updated_at: 2016-04-05 08:35:52.931187000 Z
|
||||
invoicing_profile_id: 7
|
||||
statistic_profile_id: 7
|
||||
reference: '1203002'
|
||||
avoir_mode:
|
||||
avoir_date:
|
||||
@ -76,7 +80,7 @@ invoice_4:
|
||||
type:
|
||||
subscription_to_expire:
|
||||
description:
|
||||
footprint: 18a80a204730011d5c5b753bf9ff86bda49acf7acbdcf31cf37d67df9ae6e53e
|
||||
footprint: 6c70f2bbbb3fd02a1ad7437ccd14456d1281d5a1f8666cce2e9d0b64701a837d
|
||||
environment: test
|
||||
operator_id:
|
||||
|
||||
@ -89,6 +93,7 @@ invoice_5:
|
||||
created_at: 2016-04-05 08:36:46.853368000 Z
|
||||
updated_at: 2016-04-05 08:36:46.853368000 Z
|
||||
invoicing_profile_id: 3
|
||||
statistic_profile_id: 3
|
||||
reference: '1506031'
|
||||
avoir_mode:
|
||||
avoir_date:
|
||||
@ -96,6 +101,6 @@ invoice_5:
|
||||
type:
|
||||
subscription_to_expire:
|
||||
description:
|
||||
footprint: c94afc0e5054da75522d438e8f33e6fcadc94c960ce7bdcf4cb4d83e7ca2a8e9
|
||||
footprint: cccd4f290d900cb7004baa63896191a6938305e75589d137655cb91a0e7dede2
|
||||
environment: test
|
||||
operator_id:
|
||||
|
Loading…
x
Reference in New Issue
Block a user