Skip to content

Commit

Permalink
implemented multiple payment slips, refs #425
Browse files Browse the repository at this point in the history
  • Loading branch information
bihorco36 committed Dec 7, 2017
1 parent 2b4b13f commit 0789363
Show file tree
Hide file tree
Showing 18 changed files with 221 additions and 80 deletions.
20 changes: 13 additions & 7 deletions app/assets/stylesheets/hitobito/modules/_invoice.scss
Expand Up @@ -6,23 +6,22 @@

.invoice-state-table {
float: left;
margin-left: 50px;
margin-bottom: 20px;

tr th {
color: $gray;
font-weight: normal;
text-align: left;
}
tr td{
tr td, tr th{
padding-right: 30px;
}
}

.invoice-history{
table {
float: left;
margin-left: 50px;
margin-left: 30px;

td:first-child { font-size: 6px; padding-right: 5px; }
td.red:first-child { color: $red; }
Expand All @@ -38,14 +37,21 @@
}

.invoice {
margin: 0px 50px;

.invoice-recipient-address{
margin: 30px 0px;
.invoice-info {
margin-top: 20px;
width: 100%;
.invoice-payment {
float: right;
}

.invoice-recipient-address{
float: left;
}
}


.invoice-table {
.invoice-articles-table {
table.header {
border-bottom: 1px solid $grayLight;
width: 100%;
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/invoice_configs_controller.rb
Expand Up @@ -8,7 +8,8 @@
class InvoiceConfigsController < CrudController

self.nesting = Group
self.permitted_attrs = [:payment_information, :address, :iban, :account_number, :contact_id]
self.permitted_attrs = [:payment_information, :address, :iban, :account_number,
:contact_id, :payment_slip, :beneficiary]

private

Expand Down
8 changes: 5 additions & 3 deletions app/models/invoice.rb
Expand Up @@ -51,6 +51,7 @@ class Invoice < ActiveRecord::Base
validates :state, inclusion: { in: STATES }
validates :due_at, timeliness: { after: :sent_at }, presence: true, if: :sent?
validate :assert_sendable?, unless: :recipient_id?
validates_associated :invoice_config

before_create :set_recipient_fields, if: :recipient
after_create :increment_sequence_number
Expand All @@ -59,6 +60,7 @@ class Invoice < ActiveRecord::Base
accepts_nested_attributes_for :invoice_items, allow_destroy: true

i18n_enum :state, STATES
i18n_enum :payment_slip, InvoiceConfig::PAYMENT_SLIPS

validates_by_schema

Expand Down Expand Up @@ -168,9 +170,9 @@ def set_esr_number
end

def set_payment_attributes
self.address = invoice_config.address
self.account_number = invoice_config.account_number
self.iban = invoice_config.iban
[:address, :account_number, :iban, :payment_slip, :beneficiary].each do |at|
assign_attributes(at => invoice_config.send(at))
end
end

def set_dates
Expand Down
33 changes: 23 additions & 10 deletions app/models/invoice_config.rb
Expand Up @@ -19,27 +19,40 @@
#

class InvoiceConfig < ActiveRecord::Base
include I18nEnums

PAYMENT_SLIPS = %w(ch_es ch_bes ch_esr ch_besr).freeze

belongs_to :group, class_name: 'Group'
belongs_to :contact, class_name: 'Person'

validates :group_id, uniqueness: true
validates :address, presence: true, on: :update
validates :iban, format: { with: /\A[A-Z]{2}[0-9]{2}\s?([A-Z]|[0-9]\s?){16,30}\z/ }, on: :update
validates :account_number, format: { with: /\A[0-9][-0-9]{4,20}[0-9]\z/ }, on: :update
validate :account_number_or_iban_present?, on: :update
validates :beneficiary, presence: true, on: :update

# TODO: probably the if condition is not correct, it has to be specified by the product owner
validates :iban, presence: true, on: :update, if: proc { |ic| ic.ch_es? || ic.ch_bes? }
validates :iban, format: { with: /\A[A-Z]{2}[0-9]{2}\s?([A-Z]|[0-9]\s?){12,30}\z/ },
on: :update, allow_blank: true

# TODO: Same as todo above
validates :account_number, presence: true, on: :update
validates :account_number, format: { with: /\A[0-9][-0-9]{4,20}[0-9]\z/ },
on: :update, allow_blank: true

i18n_enum :payment_slip, PAYMENT_SLIPS

validates_by_schema

def to_s
[model_name.human, group.to_s].join(' - ')
end

private

def account_number_or_iban_present?
# TODO: validate presence if orange or red deposit slip
return if account_number.present? || iban.present?
errors.add(:iban, :required) if iban.blank?
errors.add(:account_number, :required) if account_number.blank?
PAYMENT_SLIPS.each do |payment_slip|
scope payment_slip.to_sym, -> { where(payment_slip: payment_slip) }
define_method "#{payment_slip}?" do
self.payment_slip == payment_slip
end
end

end
16 changes: 16 additions & 0 deletions app/views/invoice_configs/_attrs.html.haml
@@ -0,0 +1,16 @@
-# Copyright (c) 2012-2017, Jungwacht Blauring Schweiz. This file is part of
-# hitobito 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.
%dl.dl-horizontal
= labeled_attr(entry, :contact)
= labeled_attr(entry, :due_days)
= labeled_attr(entry, :payment_information)

= labeled(captionize(:payment_slip, object_class(entry)), entry.payment_slip_label)
= labeled_attr(entry, :beneficiary)
= labeled_attr(entry, :address)
= labeled_attr(entry, :account_number)
= labeled_attr(entry, :iban)
8 changes: 6 additions & 2 deletions app/views/invoice_configs/_form.html.haml
Expand Up @@ -8,8 +8,12 @@
= f.labeled_person_field(:contact)
= f.labeled_input_field :due_days
= f.labeled_input_field :payment_information
%hr
= f.labeled(:payment_slip) do
= f.collection_select(:payment_slip, InvoiceConfig.payment_slip_labels.to_a, :first, :second, {}, class: 'span6')
= f.labeled_input_field :beneficiary
= f.labeled_input_field :address
= f.labeled_input_field :account_number
= f.labeled_input_field :iban
= f.labeled_input_field :account_number, help: t('.account_number_example')
= f.labeled_input_field :iban, help: t('.iban_example')

= save_form_buttons(f, nil, group_invoice_config_path(parent))
11 changes: 9 additions & 2 deletions app/views/invoices/_attrs.html.haml
Expand Up @@ -7,5 +7,12 @@
= render 'payment_reminder_form', url: group_invoice_payment_reminders_path(parent, entry) if @reminder
= render 'payment_form' if @payment

= render 'summary'
= render 'details'
.invoice
= render 'summary'
= render 'infos'
= render 'invoice_articles'

%br
%p
%b= entry.payment_information
%p= entry.description
48 changes: 0 additions & 48 deletions app/views/invoices/_details.html.haml

This file was deleted.

19 changes: 19 additions & 0 deletions app/views/invoices/_infos.html.haml
@@ -0,0 +1,19 @@
-# Copyright (c) 2012-2017, Jungwacht Blauring Schweiz. This file is part of
-# hitobito 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.
.invoice-info.clearfix
%dl.dl-horizontal
.invoice-recipient-address
.contactable
.address
= invoice_receiver_address(entry)

.invoice-payment
= labeled(captionize(:payment_slip, object_class(entry)), entry.payment_slip_label)
= labeled_attr(entry, :beneficiary)
= labeled_attr(entry, :address)
= labeled_attr(entry, :account_number)
= labeled_attr(entry, :iban) if entry.iban.present?

40 changes: 40 additions & 0 deletions app/views/invoices/_invoice_articles.html.haml
@@ -0,0 +1,40 @@
-# Copyright (c) 2012-2017, Jungwacht Blauring Schweiz. This file is part of
-# hitobito 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.
.invoice-articles-table
%h2= entry.title

%table.header
%tr
%td.left
= "#{t('activerecord.models.invoice.one')}: ##{entry.sequence_number}"
%td.right
= l(entry.sent_at, format: :long) if entry.sent_at?

= table(entry.invoice_items.list, class: 'table table-striped') do |t|
- t.attr(:name)
- t.attr(:description)
- t.attr(:count)
- t.attr(:vat_rate) { |i| i.decorate.vat_rate }
- t.attr(:unit_cost) { |i| i.decorate.unit_cost }
- t.attr(:total) { |i| i.decorate.cost }

.invoice-items-total
%table
%tr
%td.left
= captionize(:cost, Invoice)
%td.right
= entry.cost
%tr
%td.left
= captionize(:vat_rate, InvoiceItem)
%td.right
= entry.vat
%tr
%td.left
%b= captionize(:total_inkl_vat, Invoice)
%td.right
%b= entry.total
24 changes: 23 additions & 1 deletion config/locales/models.de.yml
Expand Up @@ -110,6 +110,9 @@ de:

invoice:
recipient_address_or_email_required: 'Empfänger Addresse oder E-Mail muss ausgefüllt werden'
attributes:
invoice_config:
invalid: 'ist nicht gültig, passen sie die Einstellungen an bevor sie eine Rechnung erstellen'
invoice_config:
attributes:
iban:
Expand Down Expand Up @@ -578,6 +581,7 @@ de:
subject: Betreff
body: Inhalt


label_format:
name: Bezeichnung
page_size: Seitengrösse
Expand All @@ -598,10 +602,16 @@ de:
description: Beschreibung
invoice_items: Rechnungsposten
invoice_item_article: Rechnungsartikel
invoice_config: Rechnungseinstellung
state: Status
sequence_number: Nummer
esr_number: Referenz Nummer
amount_paid: Total bezahlt
payment_slips:
ch_es: Roter Einzahlungsschein Post (CH)
ch_bes: Roter Einzahlungsschein Bank (CH)
ch_esr: Oranger Einzahlungsschein Post (CH)
ch_besr: Oranger Einzahlungsschein Bank (CH)
states:
draft: Entwurf
issued: Gestellt
Expand All @@ -623,6 +633,11 @@ de:
vat: MWSt.
payment_information: Zahlungsinformation
payment_purpose: Zahlungszweck
address: Absender Adresse
beneficiary: Zugunsten von
account_number: Kontonummer
iban: IBAN
payment_slip: Einzahlungsschein

invoice_article:
number: Artikelnummer
Expand All @@ -636,12 +651,19 @@ de:

invoice_config:
payment_information: Zahlungsinformation
address: Adresse
address: Absender Adresse
account_number: Kontonummer
iban: IBAN
due_days: Tage bis Fällig
contact: Kontaktperson
contact_id: Kontaktperson
beneficiary: Zugunsten von
payment_slip: Einzahlungsschein
payment_slips:
ch_es: Roter Einzahlungsschein Post (CH)
ch_bes: Roter Einzahlungsschein Bank (CH)
ch_esr: Oranger Einzahlungsschein Post (CH)
ch_besr: Oranger Einzahlungsschein Bank (CH)

invoice_item:
name: Name
Expand Down
3 changes: 3 additions & 0 deletions config/locales/views.de.yml
Expand Up @@ -607,6 +607,9 @@ de:
update:
flash:
success: Rechnungseinstellungen wurden erfolgreich aktualisiert
form:
account_number_example: 'Beispiel: 16075473007'
iban_example: 'Beispiel: CH93 0076 2011 6238 5295 7'

invoice_lists:
form:
Expand Down
16 changes: 16 additions & 0 deletions db/migrate/20171206164713_multiple_payment_slips.rb
@@ -0,0 +1,16 @@
# encoding: utf-8

# Copyright (c) 2012-2017, Jungwacht Blauring Schweiz. This file is part of
# hitobito 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 MultiplePaymentSlips < ActiveRecord::Migration
def change
add_column :invoices, :payment_slip, :string, null: false, default: 'ch_es'
add_column :invoices, :beneficiary, :text

add_column :invoice_configs, :payment_slip, :string, null: false, default: 'ch_es'
add_column :invoice_configs, :beneficiary, :text
end
end

0 comments on commit 0789363

Please sign in to comment.