diff --git a/Gemfile b/Gemfile index a64a696..48d238a 100644 --- a/Gemfile +++ b/Gemfile @@ -84,3 +84,5 @@ gem "pwned" gem "action_policy", "~> 0.7.1" gem "pagy", "~> 9.0" + +gem "csv", "~> 3.3" diff --git a/Gemfile.lock b/Gemfile.lock index 51b855b..9955394 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -102,6 +102,7 @@ GEM concurrent-ruby (1.3.4) connection_pool (2.4.1) crass (1.0.6) + csv (3.3.0) date (3.3.4) debug (1.9.2) irb (~> 1.10) @@ -364,6 +365,7 @@ DEPENDENCIES bootsnap brakeman capybara + csv (~> 3.3) debug faker (~> 3.4) image_processing (~> 1.2) diff --git a/app/models/job.rb b/app/models/job.rb index 98fc5f1..aab0360 100644 --- a/app/models/job.rb +++ b/app/models/job.rb @@ -110,6 +110,18 @@ class Job < ApplicationRecord save end + def self.report_to_csv(jobs) + columns = [ "id", "costumer_firstname", "costumer_lastname", "paid_at", "cost" ] + columns_readable = [ "ID", "Name", "Nachname", "bezahlt am", "Betrag" ] + CSV.generate(col_sep: ";") do |csv| + csv << columns_readable + jobs.each do |job| + # csv << job.attributes.values_at(*columns) + csv << [ job.id, job.costumer_firstname, job.costumer_lastname, job.paid_at.localtime.strftime("%Y-%m-%d"), job.cost.to_s + " €" ] + end + end + end + private def printed_pages_changes? @@ -131,7 +143,7 @@ class Job < ApplicationRecord def calc_cost self.cost = (number_of_plans_a0 * cost_qm) + (number_of_plans_a1 * cost_qm / 2) + (number_of_plans_a2 * cost_qm / 4) + (number_of_plans_a3 * cost_qm / 8) + - (costum_qm_plan * cost_qm) + (costum_qm_plan * cost_qm).round(2) end def set_cost_qm diff --git a/app/views/admin/jobs/_job_tr.html.erb b/app/views/admin/jobs/_job_tr.html.erb index 4b2cbbf..31ecd73 100644 --- a/app/views/admin/jobs/_job_tr.html.erb +++ b/app/views/admin/jobs/_job_tr.html.erb @@ -52,7 +52,7 @@