-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
202 additions
and
218 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright (c) 2023, Schweizer Alpen-Club. This file is part of | ||
# hitobito_sac_cas and licensed under the Affero General Public License version 3 | ||
# or later. See the COPYING file at the top-level directory or at | ||
# https://github.com/hitobito/hitobito | ||
|
||
class People::Membership::InvoiceForm | ||
include ActiveModel::Model | ||
include ActiveModel::Attributes | ||
|
||
DISCOUNTS = ["0", "50", "100"].freeze | ||
|
||
attribute :reference_date, :date | ||
attribute :invoice_date, :date | ||
attribute :send_date, :date | ||
attribute :discount, :string | ||
attribute :new_entry, :boolean | ||
attribute :section_id, :string | ||
|
||
validates :reference_date, :invoice_date, :send_date, :discount, presence: true | ||
|
||
validates_date :reference_date, :invoice_date, between: Time.zone.today.beginning_of_year..Time.zone.today.next_year.end_of_year | ||
validates_date :send_date, between: [Time.zone.today.beginning_of_year, :send_date_end_date] | ||
|
||
validates :discount, inclusion: {in: DISCOUNTS} | ||
|
||
def initialize(attributes = {}, person = nil) | ||
super(attributes) | ||
@person = person | ||
end | ||
|
||
private | ||
|
||
def send_date_end_date | ||
@person.sac_membership.stammsektion_role.delete_on.year > date_today.year ? date_today.end_of_year : date_today.next_year.end_of_year | ||
end | ||
|
||
def date_today | ||
Time.zone.today | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.