Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JournalEntries and TAF Reports #340

Merged
merged 13 commits into from
Dec 6, 2024
3 changes: 2 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Layout/LineLength:
Max: 120

Metrics/ClassLength:
Max: 120
Max: 150

Metrics/MethodLength:
Exclude:
Expand Down Expand Up @@ -62,6 +62,7 @@ Naming/MethodParameterName:
AllowedNames:
- "to"
- "at"
- "as"

Rails/EnvironmentVariableAccess:
AllowReads: true
Expand Down
45 changes: 23 additions & 22 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ GEM
rake (>= 0.8.7)
ast (2.4.2)
aws-eventstream (1.3.0)
aws-partitions (1.1014.0)
aws-partitions (1.1018.0)
aws-sdk-core (3.214.0)
aws-eventstream (~> 1, >= 1.3.0)
aws-partitions (~> 1, >= 1.992.0)
Expand All @@ -93,7 +93,7 @@ GEM
aws-sdk-kms (1.96.0)
aws-sdk-core (~> 3, >= 3.210.0)
aws-sigv4 (~> 1.5)
aws-sdk-s3 (1.174.0)
aws-sdk-s3 (1.176.0)
aws-sdk-core (~> 3, >= 3.210.0)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.5)
Expand Down Expand Up @@ -158,7 +158,7 @@ GEM
activerecord (>= 5.a)
database_cleaner-core (~> 2.0.0)
database_cleaner-core (2.0.1)
date (3.4.0)
date (3.4.1)
debug (1.9.2)
irb (~> 1.10)
reline (>= 0.3.8)
Expand Down Expand Up @@ -266,12 +266,12 @@ GEM
ostruct
ice_cube (0.17.0)
interception (0.5)
io-console (0.7.2)
io-console (0.8.0)
irb (1.14.1)
rdoc (>= 4.0.0)
reline (>= 0.4.2)
jmespath (1.6.2)
json (2.8.2)
json (2.9.0)
kramdown (2.5.1)
rexml (>= 3.3.9)
language_server-protocol (3.17.0.3)
Expand All @@ -283,7 +283,7 @@ GEM
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
locale (2.1.4)
logger (1.6.1)
logger (1.6.2)
loofah (2.23.1)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
Expand All @@ -299,14 +299,14 @@ GEM
actionpack (>= 6.0.0, < 8.1)
method_source (1.1.0)
mini_mime (1.1.5)
minitest (5.25.2)
mobility (1.2.9)
minitest (5.25.4)
mobility (1.3.1)
i18n (>= 0.6.10, < 2)
request_store (~> 1.0)
msgpack (1.7.5)
multi_json (1.15.0)
mutex_m (0.3.0)
net-http (0.5.0)
net-http (0.6.0)
uri
net-imap (0.5.1)
date
Expand All @@ -318,7 +318,7 @@ GEM
net-smtp (0.5.0)
net-protocol
nio4r (2.7.4)
nokogiri (1.16.7-x86_64-linux)
nokogiri (1.16.8-x86_64-linux)
racc (~> 1.4)
orm_adapter (0.5.0)
ostruct (0.6.1)
Expand Down Expand Up @@ -349,7 +349,8 @@ GEM
pry-rescue (1.6.0)
interception (>= 0.5)
pry (>= 0.12.0)
psych (5.2.0)
psych (5.2.1)
date
stringio
public_suffix (6.0.1)
puma (6.5.0)
Expand Down Expand Up @@ -385,9 +386,9 @@ GEM
activesupport (>= 5.0.0)
minitest
nokogiri (>= 1.6)
rails-html-sanitizer (1.6.0)
rails-html-sanitizer (1.6.1)
loofah (~> 2.21)
nokogiri (~> 1.14)
nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
rails-i18n (8.0.1)
i18n (>= 0.7, < 2)
railties (>= 8.0.0, < 9)
Expand All @@ -406,7 +407,7 @@ GEM
rb-fsevent (0.11.2)
rb-inotify (0.11.1)
ffi (~> 1.0)
rbs (3.6.1)
rbs (3.7.0)
logger
rdoc (6.8.1)
psych (>= 4.0.0)
Expand All @@ -420,7 +421,7 @@ GEM
redis-client (>= 0.22.0)
redis-client (0.22.2)
connection_pool
regexp_parser (2.9.2)
regexp_parser (2.9.3)
reline (0.5.12)
io-console (~> 0.5)
request_store (1.7.0)
Expand Down Expand Up @@ -449,15 +450,15 @@ GEM
rspec-expectations (~> 3.13)
rspec-mocks (~> 3.13)
rspec-support (~> 3.13)
rspec-support (3.13.1)
rubocop (1.69.0)
rspec-support (3.13.2)
rubocop (1.69.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 2.4, < 3.0)
rubocop-ast (>= 1.36.1, < 2.0)
regexp_parser (>= 2.9.3, < 3.0)
rubocop-ast (>= 1.36.2, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.36.2)
Expand All @@ -481,7 +482,7 @@ GEM
ruby-lsp (>= 0.22.0, < 0.23.0)
ruby-progressbar (1.13.0)
rubyzip (2.3.2)
securerandom (0.3.2)
securerandom (0.4.0)
selenium-webdriver (4.27.0)
base64 (~> 0.2)
logger (~> 1.4)
Expand Down Expand Up @@ -513,7 +514,7 @@ GEM
actionpack (>= 3.1)
railties (>= 3.1)
slim (>= 3.0, < 6.0, != 5.0.0)
sorbet-runtime (0.5.11670)
sorbet-runtime (0.5.11681)
squasher (0.8.0)
statesman (12.1.0)
statsd-ruby (1.5.0)
Expand All @@ -535,7 +536,7 @@ GEM
unicode (0.4.4.5)
unicode-display_width (2.6.0)
uri (1.0.2)
useragent (0.16.10)
useragent (0.16.11)
vite_rails (3.0.19)
railties (>= 5.1, < 9)
vite_ruby (~> 3.0, >= 3.2.2)
Expand Down
4 changes: 3 additions & 1 deletion app/controllers/manage/data_digests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ def index
respond_with :manage, @data_digests.order(created_at: :ASC)
end

def show
def show # rubocop:disable Metrics/AbcSize
respond_to do |format|
format.html
format.csv { send_data @data_digest.format(:csv), filename: "#{@data_digest.label}.csv" }
format.pdf { send_data @data_digest.format(:pdf), filename: "#{@data_digest.label}.pdf" }
format.taf { send_data @data_digest.format(:taf), filename: "#{@data_digest.label}.taf" }
format.text { render plain: @data_digest.format(:taf) }
end
rescue Prawn::Errors::CannotFit
redirect_to manage_data_digests_path, alert: t('.pdf_error')
Expand Down
39 changes: 39 additions & 0 deletions app/controllers/manage/vat_categories_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# frozen_string_literal: true

module Manage
class VatCategoriesController < BaseController
load_and_authorize_resource :vat_category

def index
@vat_categories = @vat_categories.where(organisation: current_organisation).ordered
respond_with :manage, @vat_categories
end

def edit
respond_with :manage, @vat_category
end

def create
@vat_category.organisation = current_organisation
@vat_category.save
respond_with :manage, location: manage_vat_categories_path
end

def update
@vat_category.update(vat_category_params)
respond_with :manage, location: manage_vat_categories_path
end

def destroy
@vat_category.discarded? ? @vat_category.destroy : @vat_category.discard!
respond_with :manage, @vat_category, location: manage_vat_categories_path
end

private

def vat_category_params
locale_params = I18n.available_locales.map { |locale| ["label_#{locale}"] }
params.require(:vat_category).permit(:percentage, :accounting_vat_code, locale_params.flatten)
end
end
end
50 changes: 26 additions & 24 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,16 @@ class Manage < Base

can(:manage, BookingAgent, organisation:)
can(:manage, BookingCategory, organisation:)
can :manage, BookingCondition, tarif: { organisation: }
can(:manage, BookingCondition, tarif: { organisation: })
can(:manage, BookingQuestion, organisation:)
can(:manage, BookingValidation, organisation:)
can(:manage, DesignatedDocument, organisation:)
can(:manage, Occupiable, organisation:)
can(:manage, Operator, organisation:)
can %i[read edit update], Organisation, id: organisation.id
can(%i[read edit update], Organisation, id: organisation.id)
can(:manage, OrganisationUser, organisation:)
can :manage, Tarif, organisation:
can(:manage, Tarif, organisation:)
can(:manage, VatCategory, organisation:)
end

role :manager do |user, organisation|
Expand All @@ -50,21 +51,21 @@ class Manage < Base
abilities_for_role(:readonly, user, organisation)

can(:manage, Booking, organisation:)
can :manage, Contract, booking: { organisation: }
can(:manage, Contract, booking: { organisation: })
can(:manage, DataDigest, organisation:)
can(:manage, DataDigestTemplate, organisation:)
can :manage, Deadline, booking: { organisation: }
can :manage, Invoice, booking: { organisation: }
can :manage, InvoicePart, invoice: { booking: { organisation: } }
can :manage, Notification, booking: { organisation: }
can :new, Occupancy
can :manage, Occupancy, occupiable: { organisation: }
can(:manage, Deadline, booking: { organisation: })
can(:manage, Invoice, booking: { organisation: })
can(:manage, InvoicePart, invoice: { booking: { organisation: } })
can(:manage, Notification, booking: { organisation: })
can(:new, Occupancy)
can(:manage, Occupancy, occupiable: { organisation: })
can(:manage, OperatorResponsibility, organisation:)
can :manage, Payment, booking: { organisation: }
can(:manage, Payment, booking: { organisation: })
can(:manage, Tenant, organisation:)
can :manage, Usage, booking: { organisation: }
can(:manage, Usage, booking: { organisation: })
can(:manage, RichTextTemplate, organisation:)
can :read, PlanBBackup, organisation:
can(:read, PlanBBackup, organisation:)
end

role :readonly do |user, organisation|
Expand All @@ -73,28 +74,29 @@ class Manage < Base
can(%i[read calendar], Booking, organisation:)
can(:read, BookingAgent, organisation:)
can(:read, BookingCategory, organisation:)
can :read, BookingCondition, tarif: { organisation: }
can(:read, BookingCondition, tarif: { organisation: })
can(:read, BookingQuestion, organisation:)
can(:read, BookingValidation, organisation:)
can :read, Contract, booking: { organisation: }
can(:read, Contract, booking: { organisation: })
can(%i[read new create], DataDigest, organisation:)
can(:read, DataDigestTemplate, organisation:)
can :read, Deadline, booking: { organisation: }
can(:read, Deadline, booking: { organisation: })
can(%i[read calendar at embed], Home, organisation:)
can :read, Invoice, booking: { organisation: }
can :read, InvoicePart, invoice: { booking: { organisation: } }
can :read, Notification, booking: { organisation: }
can %i[read calendar at embed], Occupancy, occupiable: { organisation: }
can(:read, Invoice, booking: { organisation: })
can(:read, InvoicePart, invoice: { booking: { organisation: } })
can(:read, Notification, booking: { organisation: })
can(%i[read calendar at embed], Occupancy, occupiable: { organisation: })
can(%i[read calendar], Occupiable, organisation:)
can(:read, Operator, organisation:)
can(:read, OperatorResponsibility, organisation:)
can %i[read edit], Organisation, id: organisation.id
can :read, Payment, booking: { organisation: }
can(%i[read edit], Organisation, id: organisation.id)
can(:read, Payment, booking: { organisation: })
can(:read, RichTextTemplate, organisation:)
can(:read, Tarif, organisation:)
can(:read, Tenant, organisation:)
can :read, Usage, booking: { organisation: }
can :read, User, organisation:
can(:read, Usage, booking: { organisation: })
can(:read, User, organisation:)
can(:read, VatCategory, organisation:)
end
end

Expand Down
49 changes: 49 additions & 0 deletions app/models/accounting.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# frozen_string_literal: true

module Accounting
JournalEntry = Data.define(:id, :account, :date, :tax_code, :text, :amount, :side, :cost_center,
:index, :amount_type, :source, :reference, :currency, :booking) do
extend ActiveModel::Translation
extend ActiveModel::Naming

def initialize(**args)
args.symbolize_keys!
defaults = { id: nil, index: nil, tax_code: nil, text: nil, cost_center: nil, source: nil }
side = args.delete(:side) if %i[soll haben].include?(args[:side])
date = args.delete(:date)&.then { _1.try(:to_date) || Date.parse(_1).to_date }
super(**defaults, **args, side:, date:)
end

def soll?
side == :soll
end

def haben?
side == :haben
end

def soll_account
account if soll?
end

def haben_account
account if haben?
end

def valid?
(soll_account.present? || haben_account.present?) && amount.present?
end

def to_s
[
(id || index).presence&.then { "[#{_1}]" },
soll_account,
'->',
haben_account,
ActiveSupport::NumberHelper.number_to_currency(amount, unit: currency),
':',
text
].compact.join(' ')
end
end
end
7 changes: 7 additions & 0 deletions app/models/accounting_settings.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class AccountingSettings < Settings
attribute :tenant_debitor_account_nr_base, :integer, default: -> { 0 }
attribute :debitor_account_nr, :string
attribute :currency_account_nr, :string
end
1 change: 1 addition & 0 deletions app/models/application_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
self.attributes_for_inspect = :all

def self.human_enum(enum, value, default: '-', **)
return default if value.blank?
Expand Down
Loading
Loading