class DiningCharge < ApplicationRecord belongs_to :table belongs_to :room def amount_calculate(dining_charges_obj, checkin , checkout) if !checkin.nil? && !checkout.nil? && !dining_charges_obj.nil? minutes = ((checkin - checkout) * 24 * 60).to_i # stay minutes dining_minutes = minutes - dining_charges_obj.minimum_free_time # stayminutes - free minutes charge_type = dining_charges_obj.charge_type if charge_type == 'hr' elsif charge_type == 'day' price = charge_by_day end end end def charge_by_hour end def charge_by_day(chargesObj, dining_minutes) minues_per_day = 12 * 60 result = dining_minutes / minues_per_day if result < 1 return chargesObj.unit_price elsif result > 1 solid_price = result * chargesObj.unit_price remain_value = dining_minutes % minues_per_day roundingblock = remain_value / chargesObj.time_rounding_block if roundingblock > 1 end end end end