Added report csv epxort to job model

This commit is contained in:
2024-09-17 15:50:13 +02:00
parent cb1879055c
commit 8bef03c2ce
6 changed files with 20 additions and 4 deletions

View File

@@ -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