-
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.
Feature/744/membership invoice form (#799)
* create form and adjsut controller to create external invoice with passed params * imrpove validation of passed params * fix rubocop and cleanup code * Adjust form validation to use active model * remove trailing whitespaces * Add acitve model to validate membership invoice * fix rubocop and adjust translations * change to standard form * implement review * adjust specs and fix rubocop * Some hopefully safe refactorings * Some more refactorings * further cleanup and add some additional specs * Render instead of redirect * further refactoring * cleanup currently_paying method filter * adjust methods in invoice form --------- Co-authored-by: Andreas Maierhofer <[email protected]>
- Loading branch information
1 parent
4aa9901
commit cd33423
Showing
9 changed files
with
298 additions
and
85 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright (c) 2024, 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_sac_cas | ||
|
||
module Sheet | ||
module People | ||
class MembershipInvoice < Base | ||
self.parent_sheet = Sheet::Person | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# 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: [:min_date, :max_date], allow_blank: true | ||
validates_date :send_date, between: [:min_date, :max_send_date], allow_blank: true | ||
|
||
validates :discount, inclusion: {in: DISCOUNTS} | ||
|
||
def initialize(attributes = {}, person = nil) | ||
super(attributes) | ||
@person = person | ||
end | ||
|
||
def date_range(attr = nil) | ||
max_date = (attr == :send_date && !already_member_next_year?) ? date_today.end_of_year : date_today.next_year.end_of_year | ||
|
||
{minDate: date_today.beginning_of_year, maxDate: max_date} | ||
end | ||
|
||
private | ||
|
||
def already_member_next_year? | ||
next_year = date_today.next_year.year | ||
@person.sac_membership.stammsektion_role.delete_on&.year&.>= next_year | ||
end | ||
|
||
def min_date = date_range[:minDate] | ||
|
||
def max_date = date_range[:maxDate] | ||
|
||
def max_send_date = date_range(:send_date)[:maxDate] | ||
|
||
def date_today = Time.zone.today | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
- title t(".form_title") | ||
- if @person.sac_membership_invoice? | ||
.alert.alert-info=t(".alert_info") | ||
|
||
= standard_form(@invoice_form, url: group_person_membership_invoices_path(@group, @person), method: :post) do |f| | ||
= f.error_messages | ||
= f.labeled(:reference_date) do | ||
= f.date_field(:reference_date, @invoice_form.date_range) | ||
= f.labeled(:invoice_date) do | ||
= f.date_field(:invoice_date, @invoice_form.date_range) | ||
= f.labeled(:send_date) do | ||
= f.date_field(:send_date, @invoice_form.date_range(:send_date)) | ||
|
||
= f.labeled(:section_id) do | ||
- main_section = @person.sac_membership.stammsektion_role.layer_group | ||
= f.inline_radio_button :section_id, main_section.id, t(".mv_yearly_invoice"), true, checked: true | ||
|
||
.nested-radio-group | ||
= f.labeled(:new_entry, class: "ms-3") do | ||
= f.inline_radio_button :new_entry, true, t("global.yes"), true | ||
= f.inline_radio_button :new_entry, false, t("global.no"), true, checked: true | ||
|
||
- @person.sac_membership.zusatzsektion_roles(currently_paying: true).map(&:layer_group).each do |section| | ||
%div | ||
= f.inline_radio_button :section_id, section.id, "#{t(".zusatzsektion_eintrittsrechnung")} #{section.name}", false, checked: false | ||
|
||
= f.labeled(:discount) do | ||
= f.inline_radio_button :discount, 0, t("global.no"), true, checked: true | ||
= f.inline_radio_button :discount, 50, "50%", true | ||
= f.inline_radio_button :discount, 100, "100%", true | ||
|
||
= f.indented do | ||
= submit_button(f, t(".create_invoice")) | ||
= cancel_link(external_invoices_group_person_path(@group, @person)) | ||
- else | ||
.alert.alert-warning= t(".alert_warning") | ||
= cancel_link(external_invoices_group_person_path(@group, @person)) |
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.