Added report csv epxort to job model
This commit is contained in:
2
Gemfile
2
Gemfile
@@ -84,3 +84,5 @@ gem "pwned"
|
|||||||
gem "action_policy", "~> 0.7.1"
|
gem "action_policy", "~> 0.7.1"
|
||||||
|
|
||||||
gem "pagy", "~> 9.0"
|
gem "pagy", "~> 9.0"
|
||||||
|
|
||||||
|
gem "csv", "~> 3.3"
|
||||||
|
|||||||
@@ -102,6 +102,7 @@ GEM
|
|||||||
concurrent-ruby (1.3.4)
|
concurrent-ruby (1.3.4)
|
||||||
connection_pool (2.4.1)
|
connection_pool (2.4.1)
|
||||||
crass (1.0.6)
|
crass (1.0.6)
|
||||||
|
csv (3.3.0)
|
||||||
date (3.3.4)
|
date (3.3.4)
|
||||||
debug (1.9.2)
|
debug (1.9.2)
|
||||||
irb (~> 1.10)
|
irb (~> 1.10)
|
||||||
@@ -364,6 +365,7 @@ DEPENDENCIES
|
|||||||
bootsnap
|
bootsnap
|
||||||
brakeman
|
brakeman
|
||||||
capybara
|
capybara
|
||||||
|
csv (~> 3.3)
|
||||||
debug
|
debug
|
||||||
faker (~> 3.4)
|
faker (~> 3.4)
|
||||||
image_processing (~> 1.2)
|
image_processing (~> 1.2)
|
||||||
|
|||||||
@@ -110,6 +110,18 @@ class Job < ApplicationRecord
|
|||||||
save
|
save
|
||||||
end
|
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
|
private
|
||||||
|
|
||||||
def printed_pages_changes?
|
def printed_pages_changes?
|
||||||
@@ -131,7 +143,7 @@ class Job < ApplicationRecord
|
|||||||
def calc_cost
|
def calc_cost
|
||||||
self.cost = (number_of_plans_a0 * cost_qm) + (number_of_plans_a1 * cost_qm / 2) +
|
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) +
|
(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
|
end
|
||||||
|
|
||||||
def set_cost_qm
|
def set_cost_qm
|
||||||
|
|||||||
@@ -52,7 +52,7 @@
|
|||||||
</td>
|
</td>
|
||||||
<td class="w-24 p-2 py-3 text-right">
|
<td class="w-24 p-2 py-3 text-right">
|
||||||
<span class="badge">
|
<span class="badge">
|
||||||
<%= job.cost.round(2) %> €
|
<%= job.cost %> €
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
<td class="p-2 py-3">
|
<td class="p-2 py-3">
|
||||||
|
|||||||
@@ -45,7 +45,7 @@
|
|||||||
</td>
|
</td>
|
||||||
<td class="w-24 p-2 py-3 text-right">
|
<td class="w-24 p-2 py-3 text-right">
|
||||||
<span class="badge">
|
<span class="badge">
|
||||||
<%= job.cost.round(2) %> €
|
<%= job.cost %> €
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
<td class="p-2 py-3">
|
<td class="p-2 py-3">
|
||||||
|
|||||||
@@ -63,7 +63,7 @@
|
|||||||
</td>
|
</td>
|
||||||
<td class="w-24 p-2 py-3 text-right">
|
<td class="w-24 p-2 py-3 text-right">
|
||||||
<span class="badge">
|
<span class="badge">
|
||||||
<%= job.cost.round(2) %> €
|
<%= job.cost %> €
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
<td class="p-2 py-3">
|
<td class="p-2 py-3">
|
||||||
|
|||||||
Reference in New Issue
Block a user