fix dining and change price for total price not (qty*unit_price) for sale item in bill

This commit is contained in:
Yan
2017-11-08 17:12:36 +06:30
parent 482d0559eb
commit d928deaa2f
2 changed files with 23 additions and 19 deletions

View File

@@ -17,7 +17,7 @@ class DiningCharge < ApplicationRecord
if charge_type == 'hr'
block_count, price = DiningCharge.charges(dining_charges_obj, dining_minutes, 'hr')
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
return block_count, price
@@ -27,40 +27,44 @@ class DiningCharge < ApplicationRecord
end
# dining charges calculate
def self.charges(chargesObj, dining_minutes, type)
solid_price = 0
charge_block = DiningCharge.convert_to_minutes(chargesObj.charge_block.utc.localtime.strftime('%H:%M'))
result = dining_minutes / charge_block
if result.to_i < 1
# for dining minute is under charge_block
return result.to_i,chargesObj.unit_price
elsif result.to_i >= 1
solid_price = result * chargesObj.unit_price
remain_value = dining_minutes % charge_block
rounding_block = DiningCharge.convert_to_minutes(chargesObj.time_rounding_block.utc.localtime.strftime('%H:%M'))
roundingblock = remain_value / rounding_block
rounding_time = DiningCharge.convert_to_minutes(chargesObj.time_rounding_block.utc.localtime.strftime('%H:%M'))
roundingblock = remain_value / rounding_time
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
solid_price += roundingblock * chargesObj.time_rounding_block_price
return result.to_i, DiningCharge.check_rounding(chargesObj, solid_price)
# remain_rounding = dining_minutes % charge_block
# if remain_rounding.to_i < 1
# return DiningCharge.check_rounding(chargesObj, solid_price)
# else
# return solid_price
# end
return result.to_i, DiningCharge.check_rounding(chargesObj, solid_price, roundingblock)
end
end
end
def self.check_rounding(chargesObj,solid_price)
if chargesObj.time_rounding == "down"
return solid_price
else
return solid_price += chargesObj.time_rounding_block_price
end
# check for rounding and calculate with rounding price
def self.check_rounding(chargesObj,solid_price, roundingblock)
rounding_block_remain = roundingblock % 1
if chargesObj.time_rounding == "down"
return solid_price
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
def self.time_diff(start_time, end_time)

View File

@@ -145,9 +145,9 @@ class ReceiptBillPdf < Prawn::Document
sale_items.each do |item|
# check for item not to show
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
total_price = item.qty*item.unit_price
total_price = item.price #item.qty*item.unit_price - comment for room charges
price = item.unit_price
product_name = item.product_name