apply highlighting and showing supplier name to invoice pdf
This commit is contained in:
parent
45db0575b1
commit
a65120eefc
9 changed files with 96 additions and 72 deletions
1
Gemfile
1
Gemfile
|
|
@ -78,6 +78,7 @@ gem 'foodsoft_wiki', path: 'plugins/wiki'
|
||||||
# gem 'foodsoft_uservoice', path: 'plugins/uservoice'
|
# gem 'foodsoft_uservoice', path: 'plugins/uservoice'
|
||||||
|
|
||||||
group :development do
|
group :development do
|
||||||
|
gem 'letter_opener_web'
|
||||||
gem 'listen'
|
gem 'listen'
|
||||||
gem 'mailcatcher'
|
gem 'mailcatcher'
|
||||||
gem 'sqlite3', '~> 1.3.6'
|
gem 'sqlite3', '~> 1.3.6'
|
||||||
|
|
|
||||||
17
Gemfile.lock
17
Gemfile.lock
|
|
@ -176,6 +176,8 @@ GEM
|
||||||
xpath (~> 3.2)
|
xpath (~> 3.2)
|
||||||
case_transform (0.2)
|
case_transform (0.2)
|
||||||
activesupport
|
activesupport
|
||||||
|
childprocess (5.1.0)
|
||||||
|
logger (~> 1.5)
|
||||||
chronic (0.10.2)
|
chronic (0.10.2)
|
||||||
coderay (1.1.3)
|
coderay (1.1.3)
|
||||||
coffee-rails (5.0.0)
|
coffee-rails (5.0.0)
|
||||||
|
|
@ -289,16 +291,28 @@ GEM
|
||||||
activerecord
|
activerecord
|
||||||
kaminari-core (= 1.2.2)
|
kaminari-core (= 1.2.2)
|
||||||
kaminari-core (1.2.2)
|
kaminari-core (1.2.2)
|
||||||
|
launchy (3.1.1)
|
||||||
|
addressable (~> 2.8)
|
||||||
|
childprocess (~> 5.0)
|
||||||
|
logger (~> 1.6)
|
||||||
less (2.6.0)
|
less (2.6.0)
|
||||||
commonjs (~> 0.2.7)
|
commonjs (~> 0.2.7)
|
||||||
less-rails (5.0.0)
|
less-rails (5.0.0)
|
||||||
actionpack (>= 5.0)
|
actionpack (>= 5.0)
|
||||||
less (~> 2.6.0)
|
less (~> 2.6.0)
|
||||||
sprockets (~> 3.0)
|
sprockets (~> 3.0)
|
||||||
|
letter_opener (1.10.0)
|
||||||
|
launchy (>= 2.2, < 4)
|
||||||
|
letter_opener_web (2.0.0)
|
||||||
|
actionmailer (>= 5.2)
|
||||||
|
letter_opener (~> 1.7)
|
||||||
|
railties (>= 5.2)
|
||||||
|
rexml
|
||||||
libv8 (3.16.14.19-x86_64-linux)
|
libv8 (3.16.14.19-x86_64-linux)
|
||||||
listen (3.7.1)
|
listen (3.7.1)
|
||||||
rb-fsevent (~> 0.10, >= 0.10.3)
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
||||||
rb-inotify (~> 0.9, >= 0.9.10)
|
rb-inotify (~> 0.9, >= 0.9.10)
|
||||||
|
logger (1.7.0)
|
||||||
loofah (2.21.3)
|
loofah (2.21.3)
|
||||||
crass (~> 1.0.2)
|
crass (~> 1.0.2)
|
||||||
nokogiri (>= 1.12.0)
|
nokogiri (>= 1.12.0)
|
||||||
|
|
@ -647,6 +661,7 @@ DEPENDENCIES
|
||||||
jquery-rails
|
jquery-rails
|
||||||
kaminari
|
kaminari
|
||||||
less-rails
|
less-rails
|
||||||
|
letter_opener_web
|
||||||
listen
|
listen
|
||||||
mailcatcher
|
mailcatcher
|
||||||
midi-smtp-server
|
midi-smtp-server
|
||||||
|
|
@ -700,4 +715,4 @@ DEPENDENCIES
|
||||||
whenever
|
whenever
|
||||||
|
|
||||||
BUNDLED WITH
|
BUNDLED WITH
|
||||||
2.4.21
|
2.4.22
|
||||||
|
|
|
||||||
|
|
@ -118,7 +118,7 @@ class MultiOrdersController < ApplicationController
|
||||||
format.xml do
|
format.xml do
|
||||||
multi_group_orders.map(&:ordergroup_invoice).each(&:mark_sepa_downloaded)
|
multi_group_orders.map(&:ordergroup_invoice).each(&:mark_sepa_downloaded)
|
||||||
collective_debit = OrderCollectiveDirectDebitXml.new(multi_group_orders)
|
collective_debit = OrderCollectiveDirectDebitXml.new(multi_group_orders)
|
||||||
send_data collective_debit.xml_string, filename: @multi_order.orders.first.name + '_Sammellastschrift' + '.xml', type: 'text/xml'
|
send_data collective_debit.xml_string, filename: @multi_order.name + '_Sammellastschrift' + '.xml', type: 'text/xml'
|
||||||
rescue SEPA::Error => e
|
rescue SEPA::Error => e
|
||||||
multi_group_orders.map(&:ordergroup_invoice).each(&:unmark_sepa_downloaded)
|
multi_group_orders.map(&:ordergroup_invoice).each(&:unmark_sepa_downloaded)
|
||||||
render json: { error: e.message }
|
render json: { error: e.message }
|
||||||
|
|
|
||||||
|
|
@ -81,12 +81,22 @@ class GroupOrderInvoicePdf < RenderPdf
|
||||||
data = [I18n.t('documents.group_order_invoice_pdf.vat_exempt_rows')]
|
data = [I18n.t('documents.group_order_invoice_pdf.vat_exempt_rows')]
|
||||||
move_down 10
|
move_down 10
|
||||||
# no sinle group_order_id, capice? get all the articles.
|
# no sinle group_order_id, capice? get all the articles.
|
||||||
group_order_articles = GroupOrderArticle.where(group_order_ids: @options.group_order_ids)
|
|
||||||
|
group_order_articles = GroupOrderArticle.where(group_order_id: @options[:group_order_ids])
|
||||||
separate_deposits = FoodsoftConfig[:group_order_invoices]&.[](:separate_deposits)
|
separate_deposits = FoodsoftConfig[:group_order_invoices]&.[](:separate_deposits)
|
||||||
|
supplier = ""
|
||||||
|
headlines = []
|
||||||
|
index = 0
|
||||||
group_order_articles.each do |goa|
|
group_order_articles.each do |goa|
|
||||||
# if no unit is received, nothing is to be charged
|
# if no unit is received, nothing is to be charged
|
||||||
next if goa.result.to_i == 0
|
next if goa.result.to_i == 0
|
||||||
|
index +=1
|
||||||
|
if goa.group_order.order.supplier.name != supplier
|
||||||
|
headlines << index
|
||||||
|
supplier = goa.group_order.order.supplier.name
|
||||||
|
data << [supplier,"","",""]
|
||||||
|
index +=1
|
||||||
|
end
|
||||||
goa_total_price = separate_deposits ? goa.total_price_without_deposit : goa.total_price
|
goa_total_price = separate_deposits ? goa.total_price_without_deposit : goa.total_price
|
||||||
data << [goa.order_article.article.name,
|
data << [goa.order_article.article.name,
|
||||||
goa.result.to_i,
|
goa.result.to_i,
|
||||||
|
|
@ -108,9 +118,9 @@ class GroupOrderInvoicePdf < RenderPdf
|
||||||
table.position = :center
|
table.position = :center
|
||||||
table.cells.border_width = 1
|
table.cells.border_width = 1
|
||||||
table.cells.border_color = '666666'
|
table.cells.border_color = '666666'
|
||||||
|
|
||||||
table.row(0).column(0..4).width = 80
|
table.row(0).column(0..4).width = 80
|
||||||
table.row(0).column(0).width = 180
|
table.row(0).column(0).width = 180
|
||||||
|
table.row(headlines).font_style= :bold
|
||||||
table.row(0).border_bottom_width = 2
|
table.row(0).border_bottom_width = 2
|
||||||
table.columns(1).align = :right
|
table.columns(1).align = :right
|
||||||
table.columns(1..6).align = :right
|
table.columns(1..6).align = :right
|
||||||
|
|
@ -172,13 +182,21 @@ class GroupOrderInvoicePdf < RenderPdf
|
||||||
else
|
else
|
||||||
[I18n.t('documents.group_order_invoice_pdf.price_markup_rows', marge: marge)]
|
[I18n.t('documents.group_order_invoice_pdf.price_markup_rows', marge: marge)]
|
||||||
end
|
end
|
||||||
goa_tax_hash = GroupOrderArticle.where(group_order_id: @options[:group_order_ids]).find_each.group_by { |oat| oat.order_article.price.tax }
|
|
||||||
goa_tax_hash.each do |tax, group_order_articles|
|
group_order_articles = GroupOrderArticle.where(group_order_id: @options[:group_order_ids]).includes(group_order: { order: :supplier })
|
||||||
group_order_articles.each do |goa|
|
index = 0
|
||||||
# if no unit is received, nothing is to be charged
|
supplier_headlines = []
|
||||||
|
group_order_articles.group_by { |goa| goa.group_order.order.supplier.name }.each do |supplier_name, articles|
|
||||||
|
data << [supplier_name, "", "", "", "", ""]
|
||||||
|
index += 1
|
||||||
|
supplier_headlines << index
|
||||||
|
|
||||||
|
articles.each do |goa|
|
||||||
next if goa.result.to_i == 0
|
next if goa.result.to_i == 0
|
||||||
|
index += 1
|
||||||
|
|
||||||
order_article = goa.order_article
|
order_article = goa.order_article
|
||||||
|
tax = order_article.price.tax
|
||||||
goa_total_net = goa.result * order_article.price.price
|
goa_total_net = goa.result * order_article.price.price
|
||||||
|
|
||||||
goa_total_fc = separate_deposits ? goa.total_price_without_deposit : goa.total_price
|
goa_total_fc = separate_deposits ? goa.total_price_without_deposit : goa.total_price
|
||||||
|
|
@ -236,6 +254,9 @@ class GroupOrderInvoicePdf < RenderPdf
|
||||||
table.row(0).border_bottom_width = 2
|
table.row(0).border_bottom_width = 2
|
||||||
table.columns(1).align = :right
|
table.columns(1).align = :right
|
||||||
table.columns(1..6).align = :right
|
table.columns(1..6).align = :right
|
||||||
|
supplier_headlines.each do |row_index|
|
||||||
|
table.row(row_index).columns(0..6).style(font_style: :bold)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if marge > 0
|
if marge > 0
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@
|
||||||
%th=I18n.t('activerecord.attributes.group_order_invoice.links.sepa_downloaded')
|
%th=I18n.t('activerecord.attributes.group_order_invoice.links.sepa_downloaded')
|
||||||
%th=I18n.t('activerecord.attributes.group_order_invoice.links.sepa_sequence_type')
|
%th=I18n.t('activerecord.attributes.group_order_invoice.links.sepa_sequence_type')
|
||||||
%th=I18n.t('activerecord.attributes.group_order_invoice.links.sepa_select')
|
%th=I18n.t('activerecord.attributes.group_order_invoice.links.sepa_select')
|
||||||
|
%th= "Rechnungsnummer"
|
||||||
%th
|
%th
|
||||||
%tbody
|
%tbody
|
||||||
- order.group_orders.includes([:group_order_invoice, :ordergroup]).each do |go|
|
- order.group_orders.includes([:group_order_invoice, :ordergroup]).each do |go|
|
||||||
|
|
@ -52,6 +53,7 @@
|
||||||
%td
|
%td
|
||||||
%td
|
%td
|
||||||
%td
|
%td
|
||||||
|
%td
|
||||||
|
|
||||||
- if order.group_orders.map(&:group_order_invoice).compact.present?
|
- if order.group_orders.map(&:group_order_invoice).compact.present?
|
||||||
%tr.order-row
|
%tr.order-row
|
||||||
|
|
@ -68,5 +70,6 @@
|
||||||
%td
|
%td
|
||||||
.div{id: "select_all_sepa_#{order.id}"}
|
.div{id: "select_all_sepa_#{order.id}"}
|
||||||
= render :partial => 'group_order_invoices/collective_direct_debit', locals: { order: order }
|
= render :partial => 'group_order_invoices/collective_direct_debit', locals: { order: order }
|
||||||
|
%td
|
||||||
%td
|
%td
|
||||||
= link_to I18n.t('activerecord.attributes.group_order_invoice.links.download_all_zip'), download_all_group_order_invoices_path(order), class: 'btn btn-block'
|
= link_to I18n.t('activerecord.attributes.group_order_invoice.links.download_all_zip'), download_all_group_order_invoices_path(order), class: 'btn btn-block'
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,7 @@
|
||||||
= render :partial => 'ordergroup_invoices/collective_direct_debit', locals: { multi_order: multi_order }
|
= render :partial => 'ordergroup_invoices/collective_direct_debit', locals: { multi_order: multi_order }
|
||||||
%td
|
%td
|
||||||
%td
|
%td
|
||||||
|
- if multi_order.multi_group_orders.count == multi_order.multi_group_orders.map(&:ordergroup_invoice).compact&.count
|
||||||
= link_to I18n.t('activerecord.attributes.group_order_invoice.links.download_all_zip'), download_all_ordergroup_invoices_path(multi_order), class: 'btn btn-block'
|
= link_to I18n.t('activerecord.attributes.group_order_invoice.links.download_all_zip'), download_all_ordergroup_invoices_path(multi_order), class: 'btn btn-block'
|
||||||
-# sends all ordergroup invoices to the ordergoups mail address via notifyjob
|
-# sends all ordergroup invoices to the ordergoups mail address via notifyjob
|
||||||
= link_to I18n.t('activerecord.attributes.group_order_invoice.links.send_all_by_email'), send_all_ordergroup_invoices_path(multi_order), class: 'btn btn-block', method: :post, data: { confirm: I18n.t('activerecord.attributes.group_order_invoice.links.confirm_send_all', ordergroups: "#{multi_order.multi_group_orders.map(&:ordergroup).map(&:name).join(', ')}" ) }
|
= link_to I18n.t('activerecord.attributes.group_order_invoice.links.send_all_by_email'), send_all_ordergroup_invoices_path(multi_order), class: 'btn btn-block', method: :post, data: { confirm: I18n.t('activerecord.attributes.group_order_invoice.links.confirm_send_all', ordergroups: "#{multi_order.multi_group_orders.map(&:ordergroup).map(&:name).join(', ')}" ) }
|
||||||
|
|
|
||||||
12
spec/factories/sepa_account_holder.rb
Normal file
12
spec/factories/sepa_account_holder.rb
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
require 'factory_bot'
|
||||||
|
|
||||||
|
FactoryBot.define do
|
||||||
|
factory :sepa_account_holder do
|
||||||
|
user { create :user }
|
||||||
|
group { create :ordergroup }
|
||||||
|
iban { "DE89370400440532013000" }
|
||||||
|
bic { "DEUTDEFF" }
|
||||||
|
mandate_id { "TEST-MANDATE-001" }
|
||||||
|
mandate_date_of_signature { Time.current }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -120,6 +120,10 @@ feature OrdergroupInvoice, type: :feature, js: true do
|
||||||
click_link_or_button I18n.t('activerecord.attributes.group_order_invoice.links.generate_with_date')
|
click_link_or_button I18n.t('activerecord.attributes.group_order_invoice.links.generate_with_date')
|
||||||
sleep 1
|
sleep 1
|
||||||
expect(OrdergroupInvoice.all.count).to eq(2)
|
expect(OrdergroupInvoice.all.count).to eq(2)
|
||||||
|
|
||||||
|
expect(page).not_to have_checked_field("sepa_downloaded_multi_#{OrdergroupInvoice.last.id}")
|
||||||
|
|
||||||
|
#check boxes sepa downloaded
|
||||||
check("sepa_downloaded_all_multi_#{multi_order.id}")
|
check("sepa_downloaded_all_multi_#{multi_order.id}")
|
||||||
sleep 1
|
sleep 1
|
||||||
expect(page).to have_checked_field("sepa_downloaded_multi_#{OrdergroupInvoice.last.id}")
|
expect(page).to have_checked_field("sepa_downloaded_multi_#{OrdergroupInvoice.last.id}")
|
||||||
|
|
@ -127,5 +131,32 @@ feature OrdergroupInvoice, type: :feature, js: true do
|
||||||
check("paid_all_multi_#{multi_order.id}")
|
check("paid_all_multi_#{multi_order.id}")
|
||||||
expect(page).to have_checked_field("paid_multi_#{OrdergroupInvoice.first.id}")
|
expect(page).to have_checked_field("paid_multi_#{OrdergroupInvoice.first.id}")
|
||||||
expect(page).to have_checked_field("paid_multi_#{OrdergroupInvoice.last.id}")
|
expect(page).to have_checked_field("paid_multi_#{OrdergroupInvoice.last.id}")
|
||||||
|
|
||||||
|
|
||||||
|
#sepa selects
|
||||||
|
select_box = find("#all_sepa_sequence_type_multi_#{multi_order.id}")
|
||||||
|
expect(select_box.value).to eq("RCUR")
|
||||||
|
expect(find("#sepa_sequence_type_multi_#{OrdergroupInvoice.last.id}").value).to eq("RCUR")
|
||||||
|
select "Erst-Lastschrift", from: "sepa_sequence_type_multi_#{OrdergroupInvoice.last.id}"
|
||||||
|
sleep 1
|
||||||
|
expect(find("#sepa_sequence_type_multi_#{OrdergroupInvoice.last.id}").value).to eq("FRST")
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'downloads sepa and toggles checkboxes' do
|
||||||
|
multi_order = create(:multi_order, orders: [order, order1])
|
||||||
|
sepa_account_holder = create(:sepa_account_holder, user: admin, group: admin.ordergroup)
|
||||||
|
FoodsoftConfig[:group_order_invoices] = {iban: "DE89370400440532013000", bic: "DEUTDEFF", creditor_identifier:"DE98ZZZ09999999999"}
|
||||||
|
visit finance_order_index_path
|
||||||
|
expect(page).to have_selector(:link_or_button, "Multi Bestellung auflösen")
|
||||||
|
click_link_or_button 'Toggle details'
|
||||||
|
expect(page).to have_selector(:link_or_button, I18n.t('activerecord.attributes.group_order_invoice.links.generate_with_date'))
|
||||||
|
click_link_or_button I18n.t('activerecord.attributes.group_order_invoice.links.generate_with_date')
|
||||||
|
sleep 1
|
||||||
|
expect(OrdergroupInvoice.all.count).to eq(2)
|
||||||
|
expect(page).to have_selector(:link_or_button, I18n.t('activerecord.attributes.group_order_invoice.links.download'))
|
||||||
|
# admin is the last multi_group_order
|
||||||
|
multi_group_order = multi_order.multi_group_orders.last
|
||||||
|
check("group_order_#{multi_group_order.id}_included_in_sepa")
|
||||||
|
expect(page).to have_selector(:link_or_button, 'Sammellastschrift für ausgewählt (.xml)')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,60 +0,0 @@
|
||||||
require_relative '../spec_helper'
|
|
||||||
|
|
||||||
describe OrdergroupInvoice do
|
|
||||||
# TODO: DO REAL TESTING!
|
|
||||||
let(:user) { create :user, groups: [create(:ordergroup)] }
|
|
||||||
let(:supplier) { create :supplier }
|
|
||||||
let(:article) { create :article, supplier: supplier }
|
|
||||||
let(:order) { create :order, state: 'closed' }
|
|
||||||
let(:group_order) { create :group_order, order: order, ordergroup: user.ordergroup }
|
|
||||||
let(:multi_group_order) { create :multi_group_order, multi_order: create(:multi_order, orders: [order]) }
|
|
||||||
|
|
||||||
describe 'erroneous group order invoice' do
|
|
||||||
before do
|
|
||||||
order.update!(state: 'closed')
|
|
||||||
end
|
|
||||||
let(:ogi) do
|
|
||||||
build(:ordergroup_invoice, multi_group_order: multi_group_order).tap(&:init)
|
|
||||||
end
|
|
||||||
it 'does not create group order invoice if tax_number not set' do
|
|
||||||
expect { ogi }.to raise_error(ActiveRecord::RecordInvalid, /.*/)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe 'valid group order invoice' do
|
|
||||||
before do
|
|
||||||
FoodsoftConfig[:contact][:tax_number] = 123_457_8
|
|
||||||
order.update!(state: 'closed')
|
|
||||||
end
|
|
||||||
let(:multi_group_order1) { create :multi_group_order, multi_order: create(:multi_order, orders: [order]) }
|
|
||||||
let(:ogi) do
|
|
||||||
build(:ordergroup_invoice, multi_group_order: multi_group_order1).tap(&:init)
|
|
||||||
end
|
|
||||||
invoice_number1 = Time.now.strftime("%Y%m%d") + '0001'
|
|
||||||
invoice_number2 = Time.now.strftime("%Y%m%d") + '0002'
|
|
||||||
|
|
||||||
it 'creates group order invoice if tax_number is set' do
|
|
||||||
expect(ogi).to be_valid
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'sets invoice_number according to date' do
|
|
||||||
number = Time.now.strftime("%Y%m%d") + '0001'
|
|
||||||
expect(odi1.invoice_number).to eq(number.to_i)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'fails to create if group_order_id is used multiple times for creation' do
|
|
||||||
expect(odi1.group_order.id).to eq(group_order.id)
|
|
||||||
expect { odi2 }.to raise_error(ActiveRecord::RecordInvalid)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'creates two different group order invoice with different invoice_numbers' do
|
|
||||||
expect(odi1.invoice_number).to eq(invoice_number1.to_i)
|
|
||||||
expect(goi3.invoice_number).to eq(invoice_number2.to_i)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'fails to create two different group order invoice with same invoice_numbers' do
|
|
||||||
odi1
|
|
||||||
expect { goi4 }.to raise_error(ActiveRecord::RecordInvalid)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue