This repository has been archived on 2021-11-24. You can view files and clone it, but cannot push or open issues or pull requests.
phone_app/app/models/p_commercial_object_month.rb
2021-08-23 10:26:02 +02:00

24 lines
598 B
Ruby

class PCommercialObjectMonth < ApplicationRecord
belongs_to :p_commercial
belongs_to :p_commercial_objective
before_validation :set_end_at
validates :objective_percent, :presence => true
validates :weight_objective, :presence => true
def set_end_at
self.end_at = self.start_at.end_of_month
end
def ca_total_ca
(self.objective_percent.to_f * self.p_commercial_objective.total_ca) / 100 if self.p_commercial_objective
end
def ca_total_weight
(self.weight_objective.to_f * self.p_commercial_objective.total_weight) / 100 if self.p_commercial_objective
end
end