diff --git a/Gemfile b/Gemfile index 4cc600b0..d8b4bbf5 100644 --- a/Gemfile +++ b/Gemfile @@ -67,6 +67,7 @@ gem 'foodsoft_links', path: 'plugins/links' gem 'foodsoft_messages', path: 'plugins/messages' gem 'foodsoft_polls', path: 'plugins/polls' gem 'foodsoft_wiki', path: 'plugins/wiki' +gem "foodsoft_group_order_invoice", :path => "plugins/group_order_invoice" # plugins not enabled by default # gem 'foodsoft_current_orders', path: 'plugins/current_orders' diff --git a/Gemfile.lock b/Gemfile.lock index debba0f2..1be0a92e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,8 +1,8 @@ GIT remote: https://github.com/gregschmit/recurring_select - revision: 29febc4c4abdd6c30636c33a7d2daecb09973ecf + revision: 89af1439687a619765631a3e0c61eb3713be0cf9 specs: - recurring_select (3.0.0) + recurring_select (3.0.1) coffee-rails (>= 3.1) ice_cube (>= 0.11) jquery-rails (>= 3.0) @@ -31,6 +31,13 @@ PATH rails ruby-filemagic +PATH + remote: plugins/group_order_invoice + specs: + foodsoft_group_order_invoice (0.1.2) + deface (~> 1.0) + rails (>= 7.0.4) + PATH remote: plugins/links specs: @@ -70,47 +77,47 @@ PATH GEM remote: https://rubygems.org/ specs: - actioncable (7.0.4) - actionpack (= 7.0.4) - activesupport (= 7.0.4) + actioncable (7.0.6) + actionpack (= 7.0.6) + activesupport (= 7.0.6) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (7.0.4) - actionpack (= 7.0.4) - activejob (= 7.0.4) - activerecord (= 7.0.4) - activestorage (= 7.0.4) - activesupport (= 7.0.4) + actionmailbox (7.0.6) + actionpack (= 7.0.6) + activejob (= 7.0.6) + activerecord (= 7.0.6) + activestorage (= 7.0.6) + activesupport (= 7.0.6) mail (>= 2.7.1) net-imap net-pop net-smtp - actionmailer (7.0.4) - actionpack (= 7.0.4) - actionview (= 7.0.4) - activejob (= 7.0.4) - activesupport (= 7.0.4) + actionmailer (7.0.6) + actionpack (= 7.0.6) + actionview (= 7.0.6) + activejob (= 7.0.6) + activesupport (= 7.0.6) mail (~> 2.5, >= 2.5.4) net-imap net-pop net-smtp rails-dom-testing (~> 2.0) - actionpack (7.0.4) - actionview (= 7.0.4) - activesupport (= 7.0.4) - rack (~> 2.0, >= 2.2.0) + actionpack (7.0.6) + actionview (= 7.0.6) + activesupport (= 7.0.6) + rack (~> 2.0, >= 2.2.4) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (7.0.4) - actionpack (= 7.0.4) - activerecord (= 7.0.4) - activestorage (= 7.0.4) - activesupport (= 7.0.4) + actiontext (7.0.6) + actionpack (= 7.0.6) + activerecord (= 7.0.6) + activestorage (= 7.0.6) + activesupport (= 7.0.6) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (7.0.4) - activesupport (= 7.0.4) + actionview (7.0.6) + activesupport (= 7.0.6) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) @@ -120,29 +127,29 @@ GEM activemodel (>= 4.1, < 7.1) case_transform (>= 0.2) jsonapi-renderer (>= 0.1.1.beta1, < 0.3) - activejob (7.0.4) - activesupport (= 7.0.4) + activejob (7.0.6) + activesupport (= 7.0.6) globalid (>= 0.3.6) - activemodel (7.0.4) - activesupport (= 7.0.4) - activerecord (7.0.4) - activemodel (= 7.0.4) - activesupport (= 7.0.4) - activestorage (7.0.4) - actionpack (= 7.0.4) - activejob (= 7.0.4) - activerecord (= 7.0.4) - activesupport (= 7.0.4) + activemodel (7.0.6) + activesupport (= 7.0.6) + activerecord (7.0.6) + activemodel (= 7.0.6) + activesupport (= 7.0.6) + activestorage (7.0.6) + actionpack (= 7.0.6) + activejob (= 7.0.6) + activerecord (= 7.0.6) + activesupport (= 7.0.6) marcel (~> 1.0) mini_mime (>= 1.1.0) - activesupport (7.0.4) + activesupport (7.0.6) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) tzinfo (~> 2.0) acts_as_tree (2.9.1) activerecord (>= 3.0.0) - addressable (2.8.1) + addressable (2.8.4) public_suffix (>= 2.0.2, < 6.0) apparition (0.6.0) capybara (~> 3.13, < 4) @@ -150,22 +157,22 @@ GEM ast (2.4.2) attribute_normalizer (1.2.0) base32 (0.3.4) - better_errors (2.9.1) - coderay (>= 1.0.0) + better_errors (2.10.1) erubi (>= 1.0.0) rack (>= 0.9.0) + rouge (>= 1.0.0) bindex (0.8.1) binding_of_caller (1.0.0) debug_inspector (>= 0.0.1) - bootsnap (1.15.0) + bootsnap (1.16.0) msgpack (~> 1.2) - bootstrap-datepicker-rails (1.9.0.1) + bootstrap-datepicker-rails (1.10.0.1) railties (>= 3.0) builder (3.2.4) bullet (7.0.7) activesupport (>= 3.0.0) uniform_notifier (~> 1.11) - capybara (3.38.0) + capybara (3.39.2) addressable matrix mini_mime (>= 0.1.3) @@ -187,13 +194,13 @@ GEM coffee-script-source (1.12.2) commonjs (0.2.7) concurrent-ruby (1.2.2) - connection_pool (2.3.0) + connection_pool (2.4.1) content_for_in_controllers (0.0.2) crass (1.0.6) daemons (1.4.1) - database_cleaner (2.0.1) - database_cleaner-active_record (~> 2.0.0) - database_cleaner-active_record (2.0.1) + database_cleaner (2.0.2) + database_cleaner-active_record (>= 2, < 3) + database_cleaner-active_record (2.1.0) activerecord (>= 5.a) database_cleaner-core (~> 2.0.0) database_cleaner-core (2.0.1) @@ -227,12 +234,12 @@ GEM factory_bot_rails (6.2.0) factory_bot (~> 6.2.0) railties (>= 5.0.0) - faker (3.1.0) + faker (3.2.0) i18n (>= 1.8.11, < 2) ffi (1.15.5) gaffe (1.2.0) rails (>= 4.0.0) - globalid (1.0.1) + globalid (1.1.0) activesupport (>= 5.0) haml (5.2.2) temple (>= 0.8.0) @@ -242,7 +249,7 @@ GEM activesupport (>= 5.1) haml (>= 4.0.6) railties (>= 5.1) - has_scope (0.8.0) + has_scope (0.8.1) actionpack (>= 5.2) activesupport (>= 5.2) hashie (3.4.6) @@ -254,7 +261,7 @@ GEM i18n-spec (0.6.0) iso ice_cube (0.16.4) - importmap-rails (1.1.5) + importmap-rails (1.2.1) actionpack (>= 6.0.0) railties (>= 6.0.0) inherited_resources (1.13.1) @@ -265,7 +272,7 @@ GEM interception (0.5) iso (0.4.0) i18n - jquery-rails (4.5.1) + jquery-rails (4.6.0) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) @@ -285,6 +292,7 @@ GEM activerecord kaminari-core (= 1.2.2) kaminari-core (1.2.2) + language_server-protocol (3.17.0.3) less (2.6.0) commonjs (~> 0.2.7) less-rails (5.0.0) @@ -292,7 +300,7 @@ GEM less (~> 2.6.0) sprockets (~> 3.0) libv8 (3.16.14.19-x86_64-linux) - listen (3.7.1) + listen (3.8.0) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) loofah (2.21.3) @@ -316,20 +324,19 @@ GEM marcel (1.0.2) matrix (0.4.2) method_source (1.0.0) - midi-smtp-server (3.0.3) + midi-smtp-server (3.1.2) mime-types (3.4.1) mime-types-data (~> 3.2015) - mime-types-data (3.2022.0105) + mime-types-data (3.2023.0218.1) mini_mime (1.1.2) - mini_portile2 (2.8.2) - minitest (5.18.0) - mono_logger (1.1.1) - msgpack (1.6.0) + minitest (5.18.1) + mono_logger (1.1.2) + msgpack (1.7.2) multi_json (1.15.0) mustermann (3.0.0) ruby2_keywords (~> 0.0.1) - mysql2 (0.5.4) - net-imap (0.3.4) + mysql2 (0.5.5) + net-imap (0.3.6) date net-protocol net-pop (0.1.2) @@ -338,15 +345,13 @@ GEM timeout net-smtp (0.3.3) net-protocol - nio4r (2.5.8) - nokogiri (1.15.2) - mini_portile2 (~> 2.8.2) - racc (~> 1.4) - nokogiri (1.15.2-x86_64-linux) + nio4r (2.5.9) + nokogiri (1.15.3-x86_64-linux) racc (~> 1.4) parallel (1.23.0) - parser (3.2.2.1) + parser (3.2.2.3) ast (~> 2.4.1) + racc pdf-core (0.9.0) polyglot (0.3.5) prawn (2.4.0) @@ -354,7 +359,7 @@ GEM ttfunk (~> 1.7) prawn-table (0.2.2) prawn (>= 1.3.0, < 3.0.0) - pry (0.14.1) + pry (0.14.2) coderay (~> 1.1) method_source (~> 1.0) pry-rescue (1.5.2) @@ -363,140 +368,149 @@ GEM pry-stack_explorer (0.6.1) binding_of_caller (~> 1.0) pry (~> 0.13) - public_suffix (5.0.1) - puma (6.0.2) + public_suffix (5.0.3) + puma (6.3.0) nio4r (~> 2.0) - racc (1.7.0) + racc (1.7.1) rack (2.2.7) - rack-cors (1.1.1) + rack-cors (2.0.1) rack (>= 2.0.0) - rack-protection (3.0.5) + rack-protection (3.0.6) rack rack-test (2.1.0) rack (>= 1.3) - rails (7.0.4) - actioncable (= 7.0.4) - actionmailbox (= 7.0.4) - actionmailer (= 7.0.4) - actionpack (= 7.0.4) - actiontext (= 7.0.4) - actionview (= 7.0.4) - activejob (= 7.0.4) - activemodel (= 7.0.4) - activerecord (= 7.0.4) - activestorage (= 7.0.4) - activesupport (= 7.0.4) + rails (7.0.6) + actioncable (= 7.0.6) + actionmailbox (= 7.0.6) + actionmailer (= 7.0.6) + actionpack (= 7.0.6) + actiontext (= 7.0.6) + actionview (= 7.0.6) + activejob (= 7.0.6) + activemodel (= 7.0.6) + activerecord (= 7.0.6) + activestorage (= 7.0.6) + activesupport (= 7.0.6) bundler (>= 1.15.0) - railties (= 7.0.4) + railties (= 7.0.6) rails-assets-listjs (0.2.0.beta.4) railties (>= 3.1) - rails-dom-testing (2.0.3) - activesupport (>= 4.2.0) + rails-dom-testing (2.1.1) + activesupport (>= 5.0.0) + minitest nokogiri (>= 1.6) rails-html-sanitizer (1.6.0) loofah (~> 2.21) nokogiri (~> 1.14) - rails-i18n (7.0.6) + rails-i18n (7.0.7) i18n (>= 0.7, < 2) railties (>= 6.0.0, < 8) rails-settings-cached (0.4.3) rails (>= 4.2.0) rails_tokeninput (1.7.0) railties (>= 3.1.0) - railties (7.0.4) - actionpack (= 7.0.4) - activesupport (= 7.0.4) + railties (7.0.6) + actionpack (= 7.0.6) + activesupport (= 7.0.6) method_source rake (>= 12.2) thor (~> 1.0) zeitwerk (~> 2.5) rainbow (3.1.1) rake (13.0.6) - ransack (3.2.1) + ransack (4.0.0) activerecord (>= 6.1.5) activesupport (>= 6.1.5) i18n rb-fsevent (0.11.2) rb-inotify (0.10.1) ffi (~> 1.0) - redis (5.0.5) + redis (5.0.6) redis-client (>= 0.9.0) - redis-client (0.11.2) + redis-client (0.14.1) connection_pool - redis-namespace (1.10.0) + redis-namespace (1.11.0) redis (>= 4) ref (2.0.0) - regexp_parser (2.8.0) - responders (3.0.1) - actionpack (>= 5.0) - railties (>= 5.0) - resque (2.4.0) + regexp_parser (2.8.1) + responders (3.1.0) + actionpack (>= 5.2) + railties (>= 5.2) + resque (2.5.0) mono_logger (~> 1.0) multi_json (~> 1.0) redis-namespace (~> 1.6) sinatra (>= 0.9.2) rexml (3.2.5) - roo (2.9.0) + roo (2.10.0) nokogiri (~> 1) rubyzip (>= 1.3.0, < 3.0.0) roo-xls (1.2.0) nokogiri roo (>= 2.0.0, < 3) spreadsheet (> 0.9.0) + rouge (4.1.2) rspec (3.12.0) rspec-core (~> 3.12.0) rspec-expectations (~> 3.12.0) rspec-mocks (~> 3.12.0) - rspec-core (3.12.0) + rspec-core (3.12.2) rspec-support (~> 3.12.0) - rspec-expectations (3.12.1) + rspec-expectations (3.12.3) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.12.0) - rspec-mocks (3.12.1) + rspec-mocks (3.12.6) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.12.0) - rspec-rails (6.0.1) + rspec-rails (6.0.3) actionpack (>= 6.1) activesupport (>= 6.1) railties (>= 6.1) - rspec-core (~> 3.11) - rspec-expectations (~> 3.11) - rspec-mocks (~> 3.11) - rspec-support (~> 3.11) + rspec-core (~> 3.12) + rspec-expectations (~> 3.12) + rspec-mocks (~> 3.12) + rspec-support (~> 3.12) rspec-rerun (1.1.0) rspec (~> 3.0) - rspec-support (3.12.0) - rswag-api (2.7.0) + rspec-support (3.12.1) + rswag-api (2.10.1) railties (>= 3.1, < 7.1) - rswag-specs (2.9.0) + rswag-specs (2.10.1) activesupport (>= 3.1, < 7.1) json-schema (>= 2.2, < 4.0) railties (>= 3.1, < 7.1) rspec-core (>= 2.14) - rswag-ui (2.7.0) + rswag-ui (2.10.1) actionpack (>= 3.1, < 7.1) railties (>= 3.1, < 7.1) - rubocop (1.50.2) + rubocop (1.54.2) json (~> 2.3) + language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 3.2.0.0) + parser (>= 3.2.2.3) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) rubocop-ast (>= 1.28.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.28.1) + rubocop-ast (1.29.0) parser (>= 3.2.1.0) - rubocop-rails (2.17.4) + rubocop-capybara (2.18.0) + rubocop (~> 1.41) + rubocop-factory_bot (2.23.1) + rubocop (~> 1.33) + rubocop-rails (2.20.2) activesupport (>= 4.2.0) rack (>= 1.1) rubocop (>= 1.33.0, < 2.0) - rubocop-rspec (2.16.0) + rubocop-rspec (2.22.0) rubocop (~> 1.33) + rubocop-capybara (~> 2.17) + rubocop-factory_bot (~> 2.22) ruby-filemagic (0.7.3) ruby-ole (1.2.12.2) - ruby-prof (1.4.5) + ruby-prof (1.6.3) ruby-progressbar (1.13.0) ruby-units (3.0.0) ruby2_keywords (0.0.5) @@ -518,7 +532,7 @@ GEM simple-navigation-bootstrap (1.0.2) railties (>= 3.1) simple-navigation (>= 3.7.0, < 4.0.0) - simple_form (5.1.0) + simple_form (5.2.0) actionpack (>= 5.2) activemodel (>= 5.2) simplecov (0.22.0) @@ -528,10 +542,10 @@ GEM simplecov-html (0.12.3) simplecov-lcov (0.8.0) simplecov_json_formatter (0.1.4) - sinatra (3.0.5) + sinatra (3.0.6) mustermann (~> 3.0) rack (~> 2.2, >= 2.2.4) - rack-protection (= 3.0.5) + rack-protection (= 3.0.6) tilt (~> 2.0) skinny (0.2.4) eventmachine (~> 1.0.0) @@ -549,8 +563,8 @@ GEM sqlite3-ruby (1.3.3) sqlite3 (>= 1.3.3) table_print (1.5.7) - temple (0.9.1) - terser (1.1.13) + temple (0.10.2) + terser (1.1.17) execjs (>= 0.3.0, < 3) therubyracer (0.12.3) libv8 (~> 3.16.14.15) @@ -560,8 +574,8 @@ GEM eventmachine (>= 1.0.0) rack (>= 1.0.0) thor (1.2.2) - tilt (2.0.11) - timeout (0.3.1) + tilt (2.2.0) + timeout (0.4.0) ttfunk (1.7.0) twitter-bootstrap-rails (2.2.8) actionpack (>= 3.1) @@ -598,7 +612,6 @@ GEM zeitwerk (2.6.8) PLATFORMS - ruby x86_64-linux DEPENDENCIES @@ -624,6 +637,7 @@ DEPENDENCIES faker foodsoft_discourse! foodsoft_documents! + foodsoft_group_order_invoice! foodsoft_links! foodsoft_messages! foodsoft_polls! @@ -692,4 +706,4 @@ DEPENDENCIES whenever BUNDLED WITH - 2.4.13 + 2.4.16 diff --git a/app/controllers/concerns/send_group_order_invoice_pdf.rb b/app/controllers/concerns/send_group_order_invoice_pdf.rb deleted file mode 100644 index 0e7ad08a..00000000 --- a/app/controllers/concerns/send_group_order_invoice_pdf.rb +++ /dev/null @@ -1,13 +0,0 @@ -module Concerns::SendGroupOrderInvoicePdf - extend ActiveSupport::Concern - - protected - - def send_group_order_invoice_pdf(group_order_invoice) - invoice_data = group_order_invoice.load_data_for_invoice - invoice_data[:title] = t('documents.group_order_invoice_pdf.title', supplier: invoice_data[:supplier]) - invoice_data[:no_footer] = true - pdf = GroupOrderInvoicePdf.new invoice_data - send_data pdf.to_pdf, filename: pdf.filename, type: 'application/pdf' - end -end diff --git a/app/controllers/group_order_invoices_controller.rb b/app/controllers/group_order_invoices_controller.rb deleted file mode 100644 index 5fcca2d7..00000000 --- a/app/controllers/group_order_invoices_controller.rb +++ /dev/null @@ -1,59 +0,0 @@ -class GroupOrderInvoicesController < ApplicationController - include Concerns::SendGroupOrderInvoicePdf - before_action :authenticate_finance - - def show - begin - @group_order_invoice = GroupOrderInvoice.find(params[:id]) - if FoodsoftConfig[:contact][:tax_number] - respond_to do |format| - format.pdf do - send_group_order_invoice_pdf @group_order_invoice if FoodsoftConfig[:contact][:tax_number] - end - end - else - raise RecordInvalid - end - rescue ActiveRecord::RecordInvalid => error - redirect_back fallback_location: root_path, notice: 'Something went wrong', alert: I18n.t('errors.general_msg', msg: "#{error} " + I18n.t('errors.check_tax_number')) - end - end - - def destroy - goi = GroupOrderInvoice.find(params[:id]) - @order = goi.group_order.order - goi.destroy - respond_to do |format| - format.js - format.json { head :no_content } - end - end - - def create_multiple - invoice_date = params[:group_order_invoice][:invoice_date] - order_id = params[:group_order_invoice][:order_id] - @order = Order.find(order_id) - gos = GroupOrder.where("order_id = ?", order_id) - gos.each do |go| - goi = GroupOrderInvoice.find_or_create_by!(group_order_id: go.id) - goi.invoice_date = invoice_date - goi.invoice_number = goi.generate_invoice_number(1) - goi.save! - end - respond_to do |format| - format.js - end - end - - def create - go = GroupOrder.find(params[:group_order]) - @order = go.order - GroupOrderInvoice.find_or_create_by!(group_order_id: go.id) - respond_to do |format| - format.js - end - redirect_back fallback_location: root_path - rescue => error - redirect_back fallback_location: root_path, notice: 'Something went wrong', :alert => I18n.t('errors.general_msg', :msg => error) - end -end diff --git a/app/documents/group_order_invoice_pdf.rb b/app/documents/group_order_invoice_pdf.rb deleted file mode 100644 index 31ee4384..00000000 --- a/app/documents/group_order_invoice_pdf.rb +++ /dev/null @@ -1,202 +0,0 @@ -class GroupOrderInvoicePdf < RenderPdf - def filename - I18n.t('documents.group_order_invoice_pdf.filename', :number => @options[:invoice_number]) + '.pdf' - end - - def title - I18n.t('documents.group_order_invoice_pdf.title', :supplier => @options[:supplier]) - end - - def body - contact = FoodsoftConfig[:contact].symbolize_keys - ordergroup = @options[:ordergroup] - - # From paragraph - bounding_box [margin_box.right - 200, margin_box.top - 20], width: 200 do - text I18n.t('documents.group_order_invoice_pdf.invoicer') - move_down 7 - text FoodsoftConfig[:name], size: fontsize(9), align: :left - move_down 5 - text contact[:street], size: fontsize(9), align: :left - move_down 5 - text "#{contact[:zip_code]} #{contact[:city]}", size: fontsize(9), align: :left - move_down 5 - unless contact[:phone].blank? - text "#{Supplier.human_attribute_name :phone}: #{contact[:phone]}", size: fontsize(9), align: :left - move_down 5 - end - unless contact[:email].blank? - text "#{Supplier.human_attribute_name :email}: #{contact[:email]}", size: fontsize(9), align: :left - end - move_down 5 - text I18n.t('documents.group_order_invoice_pdf.tax_number', :number => @options[:tax_number]), size: fontsize(9), align: :left - end - - # Receiving Ordergroup - bounding_box [margin_box.left, margin_box.top - 20], width: 200 do - text I18n.t('documents.group_order_invoice_pdf.invoicee') - move_down 7 - text I18n.t('documents.group_order_invoice_pdf.ordergroup.name', ordergroup: ordergroup.name.to_s), size: fontsize(9) - move_down 5 - if ordergroup.contact_address - text I18n.t('documents.group_order_invoice_pdf.ordergroup.contact_address', contact_address: ordergroup.contact_address.to_s), size: fontsize(9) - move_down 5 - end - if ordergroup.contact_phone - text I18n.t('documents.group_order_invoice_pdf.ordergroup.contact_phone', contact_phone: ordergroup.contact_phone.to_s), size: fontsize(9) - move_down 5 - end - end - - # invoice Date and nnvoice number - bounding_box [margin_box.right - 200, margin_box.top - 150], width: 200 do - text I18n.t('documents.group_order_invoice_pdf.invoice_date', invoice_date: @options[:invoice_date].strftime(I18n.t('date.formats.default'))), align: :left - move_down 5 - text I18n.t('documents.group_order_invoice_pdf.invoice_number', invoice_number: @options[:invoice_number]), align: :left - end - - move_down 15 - - # kind of the "body" of the invoice - text I18n.t('documents.group_order_invoice_pdf.payment_method', payment_method: @options[:payment_method]) - move_down 15 - text I18n.t('documents.group_order_invoice_pdf.table_headline') - move_down 5 - - #------------- Table Data ----------------------- - - @group_order = GroupOrder.find(@options[:group_order].id) - if FoodsoftConfig[:group_order_invoices][:vat_exempt] - body_for_vat_exempt - else - body_with_vat - end - end - - def body_for_vat_exempt - total_gross = 0 - data = [I18n.t('documents.group_order_invoice_pdf.vat_exempt_rows')] - move_down 10 - group_order_articles = GroupOrderArticle.where(group_order_id: @group_order.id) - group_order_articles.each do |goa| - # if no unit is received, nothing is to be charged - next if goa.result.to_i == 0 - goa_total_gross = goa.result * goa.order_article.price.gross_price - data << [goa.order_article.article.name, - goa.result.to_i, - number_to_currency(goa.order_article.price.gross_price), - number_to_currency(goa.total_price)] - total_gross += goa_total_gross - end - - table data, position: :left, cell_style: { size: fontsize(8), overflow: :shrink_to_fit } do |table| - table.header = true - table.position = :center - table.cells.border_width = 1 - table.cells.border_color = '666666' - - table.row(0).column(1).width = 40 - table.row(0).border_bottom_width = 2 - table.columns(1).align = :right - table.columns(1..6).align = :right - end - - move_down 5 - sum = [] - sum << [nil, nil, I18n.t('documents.group_order_invoice_pdf.sum_to_pay'), number_to_currency(total_gross)] - # table for sum - indent(200) do - table sum, position: :center, cell_style: { size: fontsize(8), overflow: :shrink_to_fit } do |table| - sum.length.times do |count| - table.row(count).columns(0..3).borders = [] - end - table.row(sum.length - 1).columns(0..2).borders = [] - table.row(sum.length - 1).border_bottom_width = 2 - table.row(sum.length - 1).columns(3).borders = [:bottom] - end - end - - move_down 25 - text I18n.t('documents.group_order_invoice_pdf.small_business_regulation') - move_down 10 - end - - def body_with_vat - total_gross = 0 - total_net = 0 - # Articles - - tax_hash_net = Hash.new(0) # for summing up article net prices grouped into vat percentage - tax_hash_gross = Hash.new(0) # same here with gross prices - - marge = FoodsoftConfig[:price_markup] - - # data table looks different when price_markup > 0 - data = if marge == 0 - [I18n.t('documents.group_order_invoice_pdf.no_price_markup_rows')] - else - [I18n.t('documents.group_order_invoice_pdf.price_markup_rows', marge: marge)] - end - goa_tax_hash = GroupOrderArticle.where(group_order_id: @group_order.id).find_each.group_by { |oat| oat.order_article.price.tax } - goa_tax_hash.each do |tax, group_order_articles| - group_order_articles.each do |goa| - # if no unit is received, nothing is to be charged - next if goa.result.to_i == 0 - - order_article = goa.order_article - goa_total_net = goa.result * order_article.price.price - goa_total_gross = goa.result * order_article.price.gross_price - data << [order_article.article.name, - goa.result.to_i, - number_to_currency(order_article.price.price), - number_to_currency(goa_total_net), - tax.to_s + '%', - number_to_currency(goa.total_price)] - tax_hash_net[tax.to_i] += goa_total_net - tax_hash_gross[tax.to_i] += goa_total_gross - total_net += goa_total_net - total_gross += goa_total_gross - end - end - - # Two separate tables for sum and individual data - # article information + data - table data, cell_style: { size: fontsize(8), overflow: :shrink_to_fit } do |table| - table.header = true - table.position = :center - table.cells.border_width = 1 - table.cells.border_color = '666666' - - table.row(0).column(1).width = 40 - table.row(0).border_bottom_width = 2 - table.columns(1).align = :right - table.columns(1..6).align = :right - end - - sum = [] - sum << [nil, nil, nil, nil, I18n.t('documents.group_order_invoice_pdf.sum_to_pay_net'), number_to_currency(total_net)] - tax_hash_net.each_key.each do |tax| - sum << [nil, nil, nil, nil, I18n.t('documents.group_order_invoice_pdf.tax_included', tax: tax), number_to_currency(tax_hash_gross[tax] - tax_hash_net[tax])] - end - unless marge == 0 - sum << [nil, nil, nil, nil, I18n.t('documents.group_order_invoice_pdf.markup_included', marge: marge), number_to_currency(total_gross * marge / 100.0)] - end - end_sum = total_gross * (1 + marge / 100.0) - sum << [nil, nil, nil, nil, I18n.t('documents.group_order_invoice_pdf.sum_to_pay_gross'), number_to_currency(end_sum)] - # table for sum - table sum, position: :right, cell_style: { size: fontsize(8), overflow: :shrink_to_fit } do |table| - sum.length.times do |count| - table.row(count).columns(0..5).borders = [] - end - table.row(sum.length - 1).columns(0..4).borders = [] - table.row(sum.length - 1).border_bottom_width = 2 - table.row(sum.length - 1).columns(5).borders = [:bottom] - end - - if(FoodsoftConfig[:group_order_invoices][:vat_exempt]) - move_down 15 - text I18n.t('documents.group_order_invoice_pdf.small_business_regulation') - end - move_down 10 - end -end diff --git a/app/jobs/notify_group_order_invoice_job.rb b/app/jobs/notify_group_order_invoice_job.rb deleted file mode 100644 index 1a17fe9a..00000000 --- a/app/jobs/notify_group_order_invoice_job.rb +++ /dev/null @@ -1,10 +0,0 @@ -class NotifyGroupOrderInvoiceJob < ApplicationJob - def perform(group_order_invoice) - ordergroup = group_order_invoice.group_order.ordergroup - ordergroup.users.each do |user| - Mailer.deliver_now_with_user_locale user do - Mailer.group_order_invoice(group_order_invoice, user) - end - end - end -end diff --git a/app/models/group_order_invoice.rb b/app/models/group_order_invoice.rb deleted file mode 100644 index 21557161..00000000 --- a/app/models/group_order_invoice.rb +++ /dev/null @@ -1,58 +0,0 @@ -class GroupOrderInvoice < ApplicationRecord - belongs_to :group_order - validates_presence_of :group_order - validates_uniqueness_of :invoice_number - validate :tax_number_set - after_initialize :init, unless: :persisted? - - def generate_invoice_number(count) - trailing_number = count.to_s.rjust(4, '0') - if GroupOrderInvoice.find_by(invoice_number: self.invoice_date.strftime("%Y%m%d") + trailing_number) - generate_invoice_number(count.to_i + 1) - else - self.invoice_date.strftime("%Y%m%d") + trailing_number - end - end - - def tax_number_set - if FoodsoftConfig[:contact][:tax_number].blank? - errors.add(:group_order_invoice, "Keine Steuernummer in FoodsoftConfig :contact gesetzt") - end - end - - def init - self.invoice_date = Time.now unless invoice_date - self.invoice_number = generate_invoice_number(1) unless self.invoice_number - self.payment_method = FoodsoftConfig[:group_order_invoices]&.[](:payment_method) || I18n.t('activerecord.attributes.group_order_invoice.payment_method') unless self.payment_method - end - - def name - I18n.t('activerecord.attributes.group_order_invoice.name') + "_#{invoice_number}" - end - - def load_data_for_invoice - invoice_data = {} - order = group_order.order - invoice_data[:supplier] = order.supplier.name - invoice_data[:ordergroup] = group_order.ordergroup - invoice_data[:group_order] = group_order - invoice_data[:invoice_number] = invoice_number - invoice_data[:invoice_date] = invoice_date - invoice_data[:tax_number] = FoodsoftConfig[:contact][:tax_number] - invoice_data[:payment_method] = payment_method - invoice_data[:order_articles] = {} - group_order.order_articles.each do |order_article| - # Get the result of last time ordering, if possible - goa = group_order.group_order_articles.detect { |tmp_goa| tmp_goa.order_article_id == order_article.id } - - # Build hash with relevant data - invoice_data[:order_articles][order_article.id] = { - :price => order_article.article.fc_price, - :quantity => (goa ? goa.quantity : 0), - :total_price => (goa ? goa.total_price : 0), - :tax => order_article.article.tax - } - end - invoice_data - end -end diff --git a/app/views/finance/balancing/_orders.html.haml b/app/views/finance/balancing/_orders.html.haml index dddb00c2..9a36682c 100644 --- a/app/views/finance/balancing/_orders.html.haml +++ b/app/views/finance/balancing/_orders.html.haml @@ -9,8 +9,7 @@ %th= t('.end') %th= t('.state') %th= heading_helper Order, :updated_by - %th= heading_helper GroupOrderInvoice, :name - %th + %th %tbody - @orders.each do |order| @@ -19,14 +18,8 @@ %td=h format_time(order.ends) unless order.ends.nil? %td= order.closed? ? t('.cleared', amount: number_to_currency(order.foodcoop_result)) : t('.ended') %td= show_user(order.updated_by) - %td{id: "generate-invoice#{order.id}"} - - if order.closed? - -if FoodsoftConfig[:contact][:tax_number] && order.ordergroups.present? - = render :partial => 'group_order_invoices/links', locals:{order: order} - -else - = I18n.t('activerecord.attributes.group_order_invoice.tax_number_not_set') - - else - = t('orders.index.not_closed') + / placeholder deface to add content using erb[silent]:contains() + - '' %td - unless order.closed? - if current_user.role_orders? @@ -35,5 +28,6 @@ - else = link_to t('orders.index.action_receive'), '#', class: 'btn btn-small disabled' = link_to t('.clear'), new_finance_order_path(order_id: order.id), class: 'btn btn-small btn-primary' + - else %i= t('.no_closed_orders') diff --git a/app/views/group_order_invoices/_links.html.haml b/app/views/group_order_invoices/_links.html.haml deleted file mode 100644 index 34bd6271..00000000 --- a/app/views/group_order_invoices/_links.html.haml +++ /dev/null @@ -1,25 +0,0 @@ -.row - .column.small-12 - - show_generate_with_date = true - - order.group_orders.each do |go| - - if go.group_order_invoice.present? - - show_generate_with_date = false - - if show_generate_with_date - = form_for :group_order_invoice, url: url_for('group_order_invoice#create_multiple'), remote: true do |f| - = f.label :invoice_date, I18n.t('activerecord.attributes.group_order_invoice.links.invoice_date') - = f.date_field :invoice_date, {value: Date.today, max: Date.today, required: true} - = f.hidden_field :order_id, value: order.id - = f.submit I18n.t('activerecord.attributes.group_order_invoice.links.generate_with_date'), class: 'btn btn small' - -- order.group_orders.includes([:group_order_invoice, :ordergroup]).each do |go| - .row - .column.small-3 - = label_tag go.ordergroup.name - - if go.group_order_invoice - .column.small-3 - = link_to I18n.t('activerecord.attributes.group_order_invoice.links.download'), group_order_invoice_path(go.group_order_invoice, :format => 'pdf'), class: 'btn btn-small' - .column.small-3 - = link_to I18n.t('activerecord.attributes.group_order_invoice.links.delete'), go.group_order_invoice, method: :delete, class: 'btn btn-danger btn-small', remote: true - - else - = button_to I18n.t('activerecord.attributes.group_order_invoice.links.generate'), group_order_invoices_path(:method => :post, group_order: go) ,class: 'btn btn-small', params: {id: order.id}, remote: true - diff --git a/app/views/group_order_invoices/create.js.erb b/app/views/group_order_invoices/create.js.erb deleted file mode 100644 index 5a43e85d..00000000 --- a/app/views/group_order_invoices/create.js.erb +++ /dev/null @@ -1 +0,0 @@ -$("#generate-invoice<%= params[:id] %>").html("<%= escape_javascript(render partial: 'links', locals: {order: @order}) %>"); diff --git a/app/views/group_order_invoices/create_multiple.js.erb b/app/views/group_order_invoices/create_multiple.js.erb deleted file mode 100644 index 11ebbe45..00000000 --- a/app/views/group_order_invoices/create_multiple.js.erb +++ /dev/null @@ -1 +0,0 @@ -$("#generate-invoice<%= @order.id %>").html("<%= escape_javascript(render partial: 'links', locals: {order: @order}) %>"); diff --git a/app/views/group_order_invoices/destroy.js.erb b/app/views/group_order_invoices/destroy.js.erb deleted file mode 100644 index 30ce5985..00000000 --- a/app/views/group_order_invoices/destroy.js.erb +++ /dev/null @@ -1 +0,0 @@ -$("#generate-invoice<%= @order.id %>").html("<%= escape_javascript(render partial: 'links', locals: {order: @order}) %>"); \ No newline at end of file diff --git a/config/locales/de.yml b/config/locales/de.yml index be1fec2a..53a0f53e 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -90,17 +90,6 @@ de: tolerance: Toleranz total_price: Summe unit_price: Preis/Einheit - group_order_invoice: - name: Bestellgruppenrechnung - links: - delete: Rechnung löschen - download: Rechnung herunterladen - generate: Rechnung erzeugen - invoice_date: Datum der Bestellgruppenrechnung - generate_with_date: setzen & erzeugen - - payment_method: Guthaben - tax_number_not_set: Steuernummer in den Einstellungen nicht gesetzt invoice: amount: Betrag attachment: Anhang @@ -329,7 +318,6 @@ de: emails_title: E-Mails versenden tab_payment: schedule_title: Bestellschema - group_order_invoices: Bestellgruppenrechnungen tab_security: default_roles_title: Zugriff auf default_roles_paragraph: Jedes Mitglied der Foodcoop hat automatisch Zugriff auf folgende Bereiche. @@ -614,10 +602,6 @@ de: email_from: E-Mails werden so aussehen, als ob sie von dieser Adresse gesendet wurden. Kann leer gelassen werden, um die Kontaktadresse der Foodcoop zu benutzen. email_replyto: Setze diese Adresse, wenn Du Antworten auf Foodsoft E-Mails auf eine andere, als die oben angegebene Absenderadresse bekommen möchtest. email_sender: E-Mails werden so aussehen, als ob sie von dieser Adresse versendet wurden. Um zu vermeiden, dass E-Mails dadurch als Spam eingeordnet werden, muss der Webserver möglicherweise im SPF Eintrag der Domain der E-Mail Adresse eingetragen werden. - group_order_invoices: - use_automativ_go_invoices: Es werden auf die Bestellgruppen zugeschnittene Rechnungen für die jeweilige Bestellung beim Klicken auf "abrechnen" an alle Bestellgruppenmitglieder per Mail versendet. - payment_method: Zahlungsart wird auf der Bestellgruppenrechnung deklariert - vat_exempt: Eine Auflistung der Rechnungsartikel erfolgt ohne explizite Ausweisung der MwSt. und die Rechnung erhält den notwendigen Zusatz bzgl. der Kleinunternehmerregelung §19 (FoodCoop Marge ebenfalls nicht in Rechnung enthalten) help_url: Link zur Dokumentationsseite homepage: Webseite der Foodcoop ignore_browser_locale: Ignoriere die Sprache des Computers des Anwenders, wenn der Anwender noch keine Sprache gewählt hat. @@ -676,10 +660,6 @@ de: email_from: Absenderadresse email_replyto: Antwortadresse email_sender: Senderadresse - group_order_invoices: - use_automatic_invoices: Automatisch bei Abrechnung per Mail versenden - payment_method: Zahlungsart - vat_exempt: Diese Foodcoop ist MwSt. befreit help_url: URL Dokumentation homepage: Webseite ignore_browser_locale: Browsersprache ignorieren @@ -765,46 +745,6 @@ de: update: notice: Lieferung wurde aktualisiert. documents: - group_order_invoice_pdf: - filename: Rechnung%{number} - invoicer: Rechnungsteller*in - invoicee: Rechnungsempfänger*in - invoice_date: 'Rechnungsdatum: %{invoice_date}' - invoice_number: 'Rechnungsnummer: %{invoice_number}' - markup_included: zzgl. Foodcoop Marge auf brutto Preis %{marge}% - ordergroup: - contact_phone: 'Telefonnummer: %{contact_phone}' - contact_address: 'Adresse : %{contact_address}' - name: Bestellgruppe %{ordergroup} - payment_method: 'Zahlungsart: %{payment_method}' - sum_to_pay: Zu zahlen gesamt - sum_to_pay_net: Zu zahlen gesamt (netto) - sum_to_pay_gross: Zu zahlen gesamt (brutto) - small_business_regulation: Als Kleinunternehmer*in im Sinne von §19 Abs. 1 Umsatzsteuergesetz (UStG) wird keine Umsatzsteuer berechnet. - table_headline: 'Für die Bestellung fallen folgende Posten an:' - tax_excluded: exkl. MwSt. - tax_included: zzgl. Gesamtsumme MwSt. %{tax}% - tax_number: 'Steuernummer: %{number}' - title: Rechnung für die Bestellung bei %{supplier} - vat_exempt_rows: - - Name - - Anzahl - - Einzelpreis - - Artikel Gesamtpreis - no_price_markup_rows: - - Name - - Anzahl - - Einzelpreis (netto) - - Artikel Gesamtpreis (netto) - - MwSt. - - Artikel Gesamtpreis (brutto) - price_markup_rows: - - Name - - Anzahl - - Einzelpreis (netto) - - Artikel Gesamtpreis (netto) - - MwSt. - - Artikel Gesamtpreis (brutto) inkl. Foodcoopmarge %{marge}% order_by_articles: filename: Bestellung %{name}-%{date} - Artikelsortierung title: 'Artikelsortierung der Bestellung: %{name}, beendet am %{date}' @@ -852,8 +792,6 @@ de: close: alert: 'Ein Fehler ist beim Abrechnen aufgetreten: %{message}' notice: Bestellung wurde erfolgreich abgerechnet, die Kontostände aktualisiert. - notice_mail: Bestellung wurde erfolgreich abgerechnet, die Kontostände aktualisiert. Außerdem wurden automatisch Rechnungen an die Bestellgruppenmitglieder geschickt. - settings_not_set: Keine Emails mit Bestellgruppenrechnungen versendet. Bitte überprüfe die Einstellungen. Steuernummer gesetzt? close_all_direct_with_invoice: notice: 'Es wurden %{count} Bestellung abgerechnet.' close_direct: @@ -1330,15 +1268,6 @@ de: feedback: header: "%{user} schrieb am %{date}:" subject: Feedback zur Foodsoft - group_order_invoice: - subject: Bestellgruppenrechnung für %{group} bei %{supplier} - text: | - Liebe Bestellgruppe %{group}, - - Die Sammelbestellung bei %{supplier} wurde soeben abgerechnet und für die jeweiligen Bestellgruppen Rechnungen angelegt. - Im Anhang befindet sich daher eure Rechnung. - - Viele Grüße von %{foodcoop} invite: subject: Einladung in die Foodcoop text: | @@ -1571,7 +1500,6 @@ de: orders_finished: Beendet orders_open: Laufend orders_settled: Abgerechnet - not_closed: Bestellung noch nicht abgerechnet title: Bestellungen verwalten model: close_direct_message: Die Bestellung wurde abgechlossen, ohne die Mitgliederkonten zu belasten. diff --git a/config/locales/en.yml b/config/locales/en.yml index 20004d65..ee7c3cd7 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -90,16 +90,6 @@ en: tolerance: Tolerance total_price: Sum unit_price: Price/Unit - group_order_invoice: - name: Group order invoice - links: - delete: delete invoice - download: download invoice - invoice_date: date of group order invoice - generate: generate invoice - generate_with_date: set & generate - payment_method: Credit - tax_number_not_set: Tax number not set in configs invoice: amount: Amount attachment: Attachment @@ -328,7 +318,6 @@ en: emails_title: Sending email tab_payment: schedule_title: Ordering schedule - group_order_invoices: Group order invoices tab_security: default_roles_title: Access to default_roles_paragraph: By default every member of the foodcoop has access to the following areas. @@ -614,9 +603,6 @@ en: email_from: Emails will appear to be from this email address. Leave empty to use the foodcoop's contact address. email_replyto: Set this when you want to receive replies from emails sent by Foodsoft on a different address than the above. email_sender: Emails will appear to be sent from this email address. To avoid emails sent being classified as spam, the webserver may need to be registered in the SPF record of the email address's domain. - use_automatic_invoices: A listing of the invoice items is made without explicit display of VAT and the invoice receives the necessary addition regarding the small business regulation §19 (applies to Germany) - payment_method: Payment type is declared on the order group invoice - vat_exempt: A listing of the invoice items is made without explicit display of VAT and the invoice contains the necessary addition regarding the German Kleinunternehmerregelung §19 UStG (attention! FoodCoop marge not included in nvoice). help_url: Documentation website. homepage: Website of your foodcoop. ignore_browser_locale: Ignore the language of user's computer when the user has not chosen a language yet. @@ -644,8 +630,6 @@ en: tolerance_is_costly: Order as much of the member tolerance as possible (compared to only as much needed to fill the last box). Enabling this also includes the tolerance in the total price of the open member order. distribution_strategy: How articles should be distributed after an order has been received. use_apple_points: When the apple point system is enabled, members are required to do some tasks to be able to keep ordering. - use_automatic_invoices: When an order is settled, invoices for the individual order groups are automatically sent by mail - payment_method: Payment Method for group order invoices use_boxfill: When enabled, near end of an order, members are only able to change their order when increases the total amount ordered. This helps to fill any remaining boxes. You still need to set a box-fill date for the orders. use_iban: When enabled, supplier and user provide an additonal field for storing the international bank account number. use_nick: Show and use nicknames instead of real names. When enabling this, please check that each user has a nickname. @@ -706,10 +690,6 @@ en: first_order_first_serve: First distribute to those who ordered first no_automatic_distribution: No automatic distribution use_apple_points: Apple points - group_order_invoices: - use_automatic_invoices: Send automatically via mail after oder settlement - payment_method: Payment method - vat_exempt: This foodcoopis VAT exempt use_boxfill: Box-fill phase use_iban: Use IBAN use_nick: Use nicknames @@ -767,46 +747,6 @@ en: update: notice: Delivery was updated. documents: - group_order_invoice_pdf: - ordergroup: - contact_phone: 'Phone: %{contact_phone}' - contact_address: 'Adress : %{contact_address}' - name: 'Ordergroup: %{ordergroup}' - filename: Invoice%{number} - invoicee: Invoicee - invoicer: Invoicer - invoice_date: 'Invoice date: %{invoice_date}' - invoice_number: 'Invoice number: %{invoice_number}' - markup_included: incl Foodcoop Marge on gross price %{marge}% - payment_method: 'Payment_method: %{payment_method}' - small_business_regulation: As a small entrepreneur in the sense of §19 para. 1 of the Umsatzsteuergesetz (UStG), no value added tax is charged. - sum_to_pay: Total sum - sum_to_pay_net: Total sum (net) - sum_to_pay_gross: Total sum (gross) - table_headline: 'The following items will be charged for the order:' - tax_excluded: excl. MwSt. - tax_included: incl. VAT %{tax}% - tax_number: 'Tax number: %{number}' - title: Invoice for order at %{supplier} - vat_exempt_rows: - - Name - - Quantity - - Unit price - - Total price - no_price_markup_rows: - - Name - - Quantity - - Unit price (net) - - Total price (net) - - VAT - - Total price (gross) - price_markup_rows: - - Name - - Quantity - - Unit price (net) - - Total price (net) - - VAT - - Total price (gross) incl. foodcoop margin order_by_articles: filename: Order %{name}-%{date} - by articles title: 'Order sorted by articles: %{name}, closed at %{date}' @@ -854,7 +794,6 @@ en: close: alert: 'An error occured while accounting: %{message}' notice: Order was settled succesfully, the balance of the account was updated. - settings_not_set: No emails with order group invoices sent. Please check the settings. Tax number set? close_all_direct_with_invoice: notice: '%{count} orders have been settled.' close_direct: @@ -1332,15 +1271,6 @@ en: feedback: header: "%{user} wrote at %{date}:" subject: Feedback for Foodsoft - group_order_invoice: - subject: Order group invoice for %{group} at %{supplier} - text: | - Dear order group %{group}, - - The collective order at %{supplier} has just been settled and invoices have been created for the respective order groups. - Attached you will find your invoice. - - Best regards from %{foodcoop} from_via_foodsoft: "%{name} via Foodsoft" invite: subject: Invitation to the Foodcoop @@ -1580,7 +1510,6 @@ en: orders_finished: Closed orders_open: Open orders_settled: Settled - not_closed: Order not yet settled title: Manage orders model: close_direct_message: Order settled without charging member accounts. diff --git a/config/routes.rb b/config/routes.rb index 527d6b40..8fea34b0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -143,10 +143,6 @@ Rails.application.routes.draw do end end - - post 'finance/group_order_invoice', to: 'group_order_invoices#create_multiple' - resources :group_order_invoices - resources :article_categories ########### Finance diff --git a/db/migrate/20211208142719_create_group_order_invoices.rb b/db/migrate/20211208142719_create_group_order_invoices.rb deleted file mode 100644 index b0aa13f7..00000000 --- a/db/migrate/20211208142719_create_group_order_invoices.rb +++ /dev/null @@ -1,13 +0,0 @@ -class CreateGroupOrderInvoices < ActiveRecord::Migration[5.2] - def change - create_table :group_order_invoices do |t| - t.integer :group_order_id - t.bigint :invoice_number, unique: true, limit: 8 - t.date :invoice_date - t.string :payment_method - - t.timestamps - end - add_index :group_order_invoices, :group_order_id, unique: true - end -end diff --git a/db/schema.rb b/db/schema.rb index 50c24c41..572f9314 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,17 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_01_06_144440) do +ActiveRecord::Schema[7.0].define(version: 2023_02_15_085312) do + create_table "action_text_rich_texts", charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| + t.string "name", null: false + t.text "body", size: :long + t.string "record_type", null: false + t.bigint "record_id", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["record_type", "record_id", "name"], name: "index_action_text_rich_texts_uniqueness", unique: true + end + create_table "active_storage_attachments", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| t.string "name", null: false t.string "record_type", null: false @@ -182,6 +192,16 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_06_144440) do t.index ["order_article_id"], name: "index_group_order_articles_on_order_article_id" end + create_table "group_order_invoices", charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| + t.integer "group_order_id" + t.bigint "invoice_number" + t.date "invoice_date" + t.string "payment_method" + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false + t.index ["group_order_id"], name: "index_group_order_invoices_on_group_order_id", unique: true + end + create_table "group_orders", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| t.integer "ordergroup_id" t.integer "order_id", default: 0, null: false @@ -282,7 +302,6 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_06_144440) do create_table "messages", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| t.integer "sender_id" t.string "subject", null: false - t.text "body" t.boolean "private", default: false t.datetime "created_at", precision: nil t.integer "reply_to" diff --git a/db/seeds.rb b/db/seeds.rb index 37a996ff..f47d42ca 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,4 +1,4 @@ # default seed is minimal -require Rails.root.join('db/seeds/minimal.seeds.rb') +require Rails.root.join('db/seeds/small.en.seeds.rb') # to generate new seeds, use the seed_dumper gem diff --git a/plugins/group_order_invoice b/plugins/group_order_invoice new file mode 160000 index 00000000..4139bfd4 --- /dev/null +++ b/plugins/group_order_invoice @@ -0,0 +1 @@ +Subproject commit 4139bfd40b07c550fa0327c4429d6c8af10d80b0 diff --git a/spec/factories/group_order_invoice.rb b/spec/factories/group_order_invoice.rb deleted file mode 100644 index 89723873..00000000 --- a/spec/factories/group_order_invoice.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'factory_bot' - -FactoryBot.define do - factory :group_order_invoice do - group_order { create :group_order } - end -end diff --git a/spec/integration/group_order_invoices_spec.rb b/spec/integration/group_order_invoices_spec.rb deleted file mode 100644 index a84d9bc7..00000000 --- a/spec/integration/group_order_invoices_spec.rb +++ /dev/null @@ -1,71 +0,0 @@ -require_relative '../spec_helper' - -feature GroupOrderInvoice, js: true do - let(:admin) { create :user, groups: [create(:workgroup, role_finance: true)] } - let(:user) { create :user, groups: [create(:ordergroup)] } - let(:article) { create :article, unit_quantity: 1 } - let(:order) { create :order, supplier: article.supplier, article_ids: [article.id], ends: Time.now } # need to ref article - let(:go) { create :group_order, order: order, ordergroup: user.ordergroup} - let(:oa) { order.order_articles.find_by_article_id(article.id) } - let(:ftt) { create :financial_transaction_type } - let(:goa) { create :group_order_article, group_order: go, order_article: oa } - - include ActiveJob::TestHelper - - before { login admin } - - after { clear_enqueued_jobs } - - it 'does not enqueue MailerJob when order is settled if tax_number or options not set' do - goa.update_quantities 2, 0 - oa.update_results! - visit confirm_finance_order_path(id: order.id) - click_link_or_button I18n.t('finance.balancing.confirm.clear') - expect(NotifyGroupOrderInvoiceJob).not_to have_been_enqueued - end - - it 'enqueues MailerJob when order is settled if tax_number or options are set' do - goa.update_quantities 2, 0 - oa.update_results! - order.reload - FoodsoftConfig[:group_order_invoices] = { use_automatic_invoices: true } - FoodsoftConfig[:contact][:tax_number] = 12_345_678 - visit confirm_finance_order_path(id: order.id, type: ftt) - expect(page).to have_selector(:link_or_button, I18n.t('finance.balancing.confirm.clear')) - click_link_or_button I18n.t('finance.balancing.confirm.clear') - expect(NotifyGroupOrderInvoiceJob).to have_been_enqueued - end - - it 'generates Group Order Invoice when order is closed if tax_number is set' do - goa.update_quantities 2, 0 - oa.update_results! - FoodsoftConfig[:contact][:tax_number] = 12_345_678 - order.update!(state: 'closed') - order.reload - visit finance_order_index_path - expect(page).to have_selector(:link_or_button, I18n.t('activerecord.attributes.group_order_invoice.links.generate')) - click_link_or_button I18n.t('activerecord.attributes.group_order_invoice.links.generate') - expect(GroupOrderInvoice.all.count).to eq(1) - end - - it 'generates multiple Group Order Invoice for order when order is closed if tax_number is set' do - goa.update_quantities 2, 0 - oa.update_results! - FoodsoftConfig[:contact][:tax_number] = 12_345_678 - order.update!(state: 'closed') - order.reload - visit finance_order_index_path - 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') - expect(GroupOrderInvoice.all.count).to eq(1) - end - - it 'does not generate Group Order Invoice when order is closed if tax_number not set' do - goa.update_quantities 2, 0 - oa.update_results! - order.update!(state: 'closed') - order.reload - visit finance_order_index_path - expect(page).to have_content(I18n.t('activerecord.attributes.group_order_invoice.tax_number_not_set')) - end -end diff --git a/spec/models/group_order_invoice_spec.rb b/spec/models/group_order_invoice_spec.rb deleted file mode 100644 index 24bfcf7e..00000000 --- a/spec/models/group_order_invoice_spec.rb +++ /dev/null @@ -1,59 +0,0 @@ -require_relative '../spec_helper' - -describe GroupOrderInvoice do - let(:user) { create :user, groups: [create(:ordergroup)] } - let(:supplier) { create :supplier } - let(:article) { create :article, supplier: supplier } - let(:order) { create :order } - let(:group_order) { create :group_order, order: order, ordergroup: user.ordergroup } - - describe 'erroneous group order invoice' do - let(:goi) { create :group_order_invoice, group_order_id: group_order.id } - it 'does not create group order invoice if tax_number not set' do - expect { goi }.to raise_error(ActiveRecord::RecordInvalid, /.*/) - end - end - - describe 'valid group order invoice' do - before do - FoodsoftConfig[:contact][:tax_number] = 123_457_8 - end - - invoice_number1 = Time.now.strftime("%Y%m%d") + '0001' - invoice_number2 = Time.now.strftime("%Y%m%d") + '0002' - - let(:user2) { create :user, groups: [create(:ordergroup)] } - - let(:goi1) { create :group_order_invoice, group_order_id: group_order.id } - let(:goi2) { create :group_order_invoice, group_order_id: group_order.id } - - let(:group_order2) { create :group_order, order: order, ordergroup: user2.ordergroup } - - let(:goi3) { create :group_order_invoice, group_order_id: group_order2.id } - let(:goi4) { create :group_order_invoice, group_order_id: group_order2.id, invoice_number: invoice_number1 } - - it 'creates group order invoice if tax_number is set' do - expect(goi1).to be_valid - end - - it 'sets invoice_number according to date' do - number = Time.now.strftime("%Y%m%d") + '0001' - expect(goi1.invoice_number).to eq(number.to_i) - end - - it 'fails to create if group_order_id is used multiple times for creation' do - expect(goi1.group_order.id).to eq(group_order.id) - expect { goi2 }.to raise_error(ActiveRecord::RecordNotUnique) - end - - it 'creates two different group order invoice with different invoice_numbers' do - expect(goi1.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 - goi1 - expect { goi4 }.to raise_error(ActiveRecord::RecordInvalid) - end - end -end