Added cost and cost_qm in job model
Changes to the migration file makes it necessary to reimport the database: db:drop db:create db:migrate db:seed
This commit is contained in:
@@ -10,6 +10,7 @@ class Job < ApplicationRecord
|
|||||||
before_save :update_printed_at, if: :will_save_change_to_status?
|
before_save :update_printed_at, if: :will_save_change_to_status?
|
||||||
before_save :update_paid_at, if: :will_save_change_to_status?
|
before_save :update_paid_at, if: :will_save_change_to_status?
|
||||||
before_save :update_status_changed_at, if: :will_save_change_to_status?
|
before_save :update_status_changed_at, if: :will_save_change_to_status?
|
||||||
|
before_save :set_cost_qm
|
||||||
|
|
||||||
# TODO: works only when job is created. Should move analyzer to activestorage :https://discuss.rubyonrails.org/t/active-storage-in-production-lessons-learned-and-in-depth-look-at-how-it-works/83289
|
# TODO: works only when job is created. Should move analyzer to activestorage :https://discuss.rubyonrails.org/t/active-storage-in-production-lessons-learned-and-in-depth-look-at-how-it-works/83289
|
||||||
after_create_commit :analyze_pdf
|
after_create_commit :analyze_pdf
|
||||||
@@ -86,18 +87,29 @@ class Job < ApplicationRecord
|
|||||||
self.status_changed_at = Time.now
|
self.status_changed_at = Time.now
|
||||||
end
|
end
|
||||||
|
|
||||||
|
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)
|
||||||
|
end
|
||||||
|
|
||||||
|
def set_cost_qm
|
||||||
|
# TODO: get cost from global settings
|
||||||
|
self.cost_qm = 7
|
||||||
|
end
|
||||||
|
|
||||||
def analyze_pdf
|
def analyze_pdf
|
||||||
# return unless pdf.attached? && pdf.new_record?
|
# return unless pdf.attached? && pdf.new_record?
|
||||||
|
self.number_of_plans_a0 = 0
|
||||||
|
self.number_of_plans_a1 = 0
|
||||||
|
self.number_of_plans_a2 = 0
|
||||||
|
self.number_of_plans_a3 = 0
|
||||||
|
self.costum_qm_plan = 0
|
||||||
|
|
||||||
# TODO: add any check if attachment has changed
|
# TODO: add any check if attachment has changed
|
||||||
|
|
||||||
# pdfs.each do |pdf|
|
# pdfs.each do |pdf|
|
||||||
pdf.blob.open do |file|
|
pdf.blob.open do |file|
|
||||||
self.number_of_plans_a0 = 0
|
|
||||||
self.number_of_plans_a1 = 0
|
|
||||||
self.number_of_plans_a2 = 0
|
|
||||||
self.number_of_plans_a3 = 0
|
|
||||||
self.costum_qm_plan = 0
|
|
||||||
# file = ActiveStorage::Blob.service.path_for(pdf.key).to_s
|
# file = ActiveStorage::Blob.service.path_for(pdf.key).to_s
|
||||||
pdf_analyzer = Services::PdfAnalyzer.new(file)
|
pdf_analyzer = Services::PdfAnalyzer.new(file)
|
||||||
pdf_analyzer.analyze
|
pdf_analyzer.analyze
|
||||||
@@ -106,8 +118,9 @@ class Job < ApplicationRecord
|
|||||||
self.number_of_plans_a2 += pdf_analyzer.pages_a2
|
self.number_of_plans_a2 += pdf_analyzer.pages_a2
|
||||||
self.number_of_plans_a3 += pdf_analyzer.pages_a3
|
self.number_of_plans_a3 += pdf_analyzer.pages_a3
|
||||||
self.costum_qm_plan += pdf_analyzer.costum_qm
|
self.costum_qm_plan += pdf_analyzer.costum_qm
|
||||||
save
|
|
||||||
end
|
end
|
||||||
# end
|
# end
|
||||||
|
calc_cost
|
||||||
|
save
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -14,7 +14,8 @@
|
|||||||
<td class="p-3 text-sm text-left text-hsrm-gray whitespace-nowrap"><span class="p-1.5 bg-gray-300 bg-opacity-50 font-medium rounded-lg"><%= job.number_of_plans_a1 %></span></td>
|
<td class="p-3 text-sm text-left text-hsrm-gray whitespace-nowrap"><span class="p-1.5 bg-gray-300 bg-opacity-50 font-medium rounded-lg"><%= job.number_of_plans_a1 %></span></td>
|
||||||
<td class="p-3 text-sm text-left text-hsrm-gray whitespace-nowrap"><span class="p-1.5 bg-gray-300 bg-opacity-50 font-medium rounded-lg"><%= job.number_of_plans_a2 %></span></td>
|
<td class="p-3 text-sm text-left text-hsrm-gray whitespace-nowrap"><span class="p-1.5 bg-gray-300 bg-opacity-50 font-medium rounded-lg"><%= job.number_of_plans_a2 %></span></td>
|
||||||
<td class="p-3 text-sm text-left text-hsrm-gray whitespace-nowrap"><span class="p-1.5 bg-gray-300 bg-opacity-50 font-medium rounded-lg"><%= job.number_of_plans_a3 %></span></td>
|
<td class="p-3 text-sm text-left text-hsrm-gray whitespace-nowrap"><span class="p-1.5 bg-gray-300 bg-opacity-50 font-medium rounded-lg"><%= job.number_of_plans_a3 %></span></td>
|
||||||
<td class="p-3 text-sm text-left text-hsrm-gray whitespace-nowrap"><span class="p-1.5 bg-gray-300 bg-opacity-50 font-medium rounded-lg"><%= job.costum_qm_plan.round(2) %></span></td>
|
<td class="p-3 text-sm text-left text-hsrm-gray whitespace-nowrap"><span class="p-1.5 bg-gray-300 bg-opacity-50 font-medium rounded-lg"><%= job.costum_qm_plan.round(2) %> m²</span></td>
|
||||||
|
<td class="p-3 text-sm text-left text-hsrm-gray whitespace-nowrap"><span class="p-1.5 bg-gray-300 bg-opacity-50 font-medium rounded-lg"><%= job.cost.round(2) %> €</span></td>
|
||||||
<td class="p-3 text-sm text-left text-hsrm-gray whitespace-nowrap">
|
<td class="p-3 text-sm text-left text-hsrm-gray whitespace-nowrap">
|
||||||
<span class="p-1.5 text-xs font-medium uppercase tracking-wider bg-opacity-50 text-status-<%= job.status.to_sym %> bg-status-<%= job.status %>-light rounded-lg"><%= job.status %></span>
|
<span class="p-1.5 text-xs font-medium uppercase tracking-wider bg-opacity-50 text-status-<%= job.status.to_sym %> bg-status-<%= job.status %>-light rounded-lg"><%= job.status %></span>
|
||||||
</td>
|
</td>
|
||||||
|
|||||||
@@ -17,7 +17,8 @@
|
|||||||
<th class="p-3 text-sm font-semibold tracking-wide text-left w-1"> A1 </th>
|
<th class="p-3 text-sm font-semibold tracking-wide text-left w-1"> A1 </th>
|
||||||
<th class="p-3 text-sm font-semibold tracking-wide text-left w-1"> A2 </th>
|
<th class="p-3 text-sm font-semibold tracking-wide text-left w-1"> A2 </th>
|
||||||
<th class="p-3 text-sm font-semibold tracking-wide text-left w-1"> A3 </th>
|
<th class="p-3 text-sm font-semibold tracking-wide text-left w-1"> A3 </th>
|
||||||
<th class="p-3 text-sm font-semibold tracking-wide text-left w-1"> qm </th>
|
<th class="p-3 text-sm font-semibold tracking-wide text-left w-1"> noDIN </th>
|
||||||
|
<th class="p-3 text-sm font-semibold tracking-wide text-left w-1"> Kosten </th>
|
||||||
<th class="p-3 text-sm font-semibold tracking-wide text-left w-1"> Status </th>
|
<th class="p-3 text-sm font-semibold tracking-wide text-left w-1"> Status </th>
|
||||||
<th class="p-3 text-sm font-semibold tracking-wide text-left w-1"> Actions </th>
|
<th class="p-3 text-sm font-semibold tracking-wide text-left w-1"> Actions </th>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ class CreateJobs < ActiveRecord::Migration[7.1]
|
|||||||
t.integer :number_of_plans_a2, default: 0
|
t.integer :number_of_plans_a2, default: 0
|
||||||
t.integer :number_of_plans_a3, default: 0
|
t.integer :number_of_plans_a3, default: 0
|
||||||
t.float :costum_qm_plan, default: 0
|
t.float :costum_qm_plan, default: 0
|
||||||
|
t.float :cost, default: 0
|
||||||
|
t.float :cost_qm, default: 0
|
||||||
t.boolean :privacy_policy_accepted, default: false
|
t.boolean :privacy_policy_accepted, default: false
|
||||||
|
|
||||||
t.timestamps
|
t.timestamps
|
||||||
|
|||||||
2
db/schema.rb
generated
2
db/schema.rb
generated
@@ -59,6 +59,8 @@ ActiveRecord::Schema[7.1].define(version: 2024_08_01_153403) do
|
|||||||
t.integer "number_of_plans_a2", default: 0
|
t.integer "number_of_plans_a2", default: 0
|
||||||
t.integer "number_of_plans_a3", default: 0
|
t.integer "number_of_plans_a3", default: 0
|
||||||
t.float "costum_qm_plan", default: 0.0
|
t.float "costum_qm_plan", default: 0.0
|
||||||
|
t.float "cost", default: 0.0
|
||||||
|
t.float "cost_qm", default: 0.0
|
||||||
t.boolean "privacy_policy_accepted", default: false
|
t.boolean "privacy_policy_accepted", default: false
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
|
|||||||
Reference in New Issue
Block a user