fix dining and change price for total price not (qty*unit_price) for sale item in bill
This commit is contained in:
@@ -17,7 +17,7 @@ class DiningCharge < ApplicationRecord
|
|||||||
if charge_type == 'hr'
|
if charge_type == 'hr'
|
||||||
block_count, price = DiningCharge.charges(dining_charges_obj, dining_minutes, 'hr')
|
block_count, price = DiningCharge.charges(dining_charges_obj, dining_minutes, 'hr')
|
||||||
elsif charge_type == 'day'
|
elsif charge_type == 'day'
|
||||||
block_count, price = charges(dining_charges_obj, dining_minutes, 'day')
|
block_count, price = DiningCharge.charges(dining_charges_obj, dining_minutes, 'day')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return block_count, price
|
return block_count, price
|
||||||
@@ -27,40 +27,44 @@ class DiningCharge < ApplicationRecord
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# dining charges calculate
|
||||||
def self.charges(chargesObj, dining_minutes, type)
|
def self.charges(chargesObj, dining_minutes, type)
|
||||||
solid_price = 0
|
solid_price = 0
|
||||||
charge_block = DiningCharge.convert_to_minutes(chargesObj.charge_block.utc.localtime.strftime('%H:%M'))
|
charge_block = DiningCharge.convert_to_minutes(chargesObj.charge_block.utc.localtime.strftime('%H:%M'))
|
||||||
|
|
||||||
result = dining_minutes / charge_block
|
result = dining_minutes / charge_block
|
||||||
if result.to_i < 1
|
if result.to_i < 1
|
||||||
|
# for dining minute is under charge_block
|
||||||
return result.to_i,chargesObj.unit_price
|
return result.to_i,chargesObj.unit_price
|
||||||
elsif result.to_i >= 1
|
elsif result.to_i >= 1
|
||||||
solid_price = result * chargesObj.unit_price
|
solid_price = result * chargesObj.unit_price
|
||||||
|
|
||||||
remain_value = dining_minutes % charge_block
|
remain_value = dining_minutes % charge_block
|
||||||
rounding_block = DiningCharge.convert_to_minutes(chargesObj.time_rounding_block.utc.localtime.strftime('%H:%M'))
|
rounding_time = DiningCharge.convert_to_minutes(chargesObj.time_rounding_block.utc.localtime.strftime('%H:%M'))
|
||||||
roundingblock = remain_value / rounding_block
|
roundingblock = remain_value / rounding_time
|
||||||
if roundingblock.to_i < 1
|
if roundingblock.to_i < 1
|
||||||
return result.to_i, DiningCharge.check_rounding(chargesObj, solid_price)
|
# no time rounding block
|
||||||
|
return result.to_i, DiningCharge.check_rounding(chargesObj, solid_price, roundingblock)
|
||||||
else
|
else
|
||||||
solid_price += roundingblock * chargesObj.time_rounding_block_price
|
solid_price += roundingblock * chargesObj.time_rounding_block_price
|
||||||
return result.to_i, DiningCharge.check_rounding(chargesObj, solid_price)
|
return result.to_i, DiningCharge.check_rounding(chargesObj, solid_price, roundingblock)
|
||||||
# remain_rounding = dining_minutes % charge_block
|
|
||||||
# if remain_rounding.to_i < 1
|
|
||||||
# return DiningCharge.check_rounding(chargesObj, solid_price)
|
|
||||||
# else
|
|
||||||
# return solid_price
|
|
||||||
# end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.check_rounding(chargesObj,solid_price)
|
# check for rounding and calculate with rounding price
|
||||||
if chargesObj.time_rounding == "down"
|
def self.check_rounding(chargesObj,solid_price, roundingblock)
|
||||||
return solid_price
|
rounding_block_remain = roundingblock % 1
|
||||||
else
|
if chargesObj.time_rounding == "down"
|
||||||
return solid_price += chargesObj.time_rounding_block_price
|
return solid_price
|
||||||
end
|
else
|
||||||
|
# check and calc for time rounding block for up
|
||||||
|
if rounding_block_remain > 0
|
||||||
|
return solid_price += chargesObj.time_rounding_block_price
|
||||||
|
else
|
||||||
|
return solid_price
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.time_diff(start_time, end_time)
|
def self.time_diff(start_time, end_time)
|
||||||
|
|||||||
@@ -145,9 +145,9 @@ class ReceiptBillPdf < Prawn::Document
|
|||||||
sale_items.each do |item|
|
sale_items.each do |item|
|
||||||
# check for item not to show
|
# check for item not to show
|
||||||
if item.price != 0
|
if item.price != 0
|
||||||
sub_total += (item.qty*item.unit_price)
|
sub_total += item.price #(item.qty*item.unit_price) - comment for room charges
|
||||||
qty = item.qty
|
qty = item.qty
|
||||||
total_price = item.qty*item.unit_price
|
total_price = item.price #item.qty*item.unit_price - comment for room charges
|
||||||
price = item.unit_price
|
price = item.unit_price
|
||||||
product_name = item.product_name
|
product_name = item.product_name
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user