Merge branch 'settings_backend' of bitbucket.org:code2lab/sxrestaurant into staging

This commit is contained in:
Yan
2017-06-20 14:21:58 +06:30
4 changed files with 44 additions and 42 deletions

View File

@@ -6,7 +6,8 @@ class Origami::RedeemPaymentsController < BaseOrigamiController
sale_data = Sale.find_by_sale_id(@sale_id)
# limit redeem_amount
food_prices, beverage_prices = SaleItem.calculate_food_beverage(sale_data.sale_items)
rebate_prices = SaleItem.calculate_food_beverage(sale_data.sale_items)
nonrebate_prices = sale_data.total_amount - rebate_prices
@payparcount = 0
others = 0
sale_data.sale_payments.each do |sale_payment|
@@ -16,11 +17,11 @@ class Origami::RedeemPaymentsController < BaseOrigamiController
others = others + sale_payment.payment_amount
end
end
is_bervage_exceed = others - (beverage_prices + sale_data.total_tax)
if is_bervage_exceed < 0
@food_prices = food_prices - @payparcount
non_rebate_exceed = others - (nonrebate_prices + sale_data.total_tax)
if non_rebate_exceed < 0
@redeem_prices = rebate_prices - @payparcount
else
@food_prices = food_prices - @payparcount -is_bervage_exceed
@redeem_prices = rebate_prices - @payparcount -non_rebate_exceed
end
if sale_data

View File

@@ -32,48 +32,49 @@ class SaleItem < ApplicationRecord
# Calculate food total and beverage total
def self.calculate_food_beverage(sale_items)
food_prices=0
beverage_prices=0
sale_items.each do |si|
food_price, beverage_price = self.get_price(si.sale_item_id)
food_prices = food_prices + food_price
beverage_prices = beverage_prices + beverage_price
rebateacc = Account.where("rebate=?",true)
puts "Account that can rebate"
rebateacc.each do |i|
puts i.title
end
puts food_prices
puts beverage_prices
return food_prices, beverage_prices
prices=0
sale_items.each do |si|
price = self.get_price(si.sale_item_id,rebateacc)
prices = prices + price
end
return prices
end
# get food price or beverage price for item
def self.get_price(sale_item_id)
food_price=0
beverage_price=0
def self.get_price(sale_item_id,rebateacc)
price=0
item=SaleItem.select("sale_items.price , menu_items.account_id")
.joins("left join menu_items on menu_items.item_code = sale_items.product_code")
.where("sale_items.sale_item_id=?", sale_item_id.to_s)
if item[0].account_id == 1
food_price = item[0].price
else
beverage_price = item[0].price
end
return food_price, beverage_price
end
def self.get_overall_discount(sale_id)
price = 0.0
item=SaleItem.where("product_code=?", sale_id)
item.each do|i|
price += i.price
rebateacc.each do |i|
if item[0].account_id == i.id
price = item[0].price
end
end
return price
end
# def self.get_overall_discount(sale_id)
# price = 0.0
# item=SaleItem.where("product_code=?", sale_id)
#
# item.each do|i|
# price += i.price
# end
#
# return price
# end
private
def generate_custom_id
self.sale_item_id = SeedGenerator.generate_id(self.class.name, "SLI")

View File

@@ -249,7 +249,9 @@ class SalePayment < ApplicationRecord
end
def rebat(sObj)
food_prices, beverage_prices = SaleItem.calculate_food_beverage(sObj.sale_items)
rebate_prices = SaleItem.calculate_food_beverage(sObj.sale_items)
puts "rebate_prices"
puts rebate_prices
generic_customer_id = sObj.customer.membership_id
if generic_customer_id != nil || generic_customer_id != "" || generic_customer_id != 0
paypar = sObj.sale_payments
@@ -259,12 +261,10 @@ class SalePayment < ApplicationRecord
payparcost = payparcost + pp.payment_amount
end
end
overall_dis = SaleItem.get_overall_discount(sObj.id)
total_amount = food_prices - payparcost + overall_dis
puts "total_amount"
puts food_prices
puts payparcost
puts total_amount
# overall_dis = SaleItem.get_overall_discount(sObj.id)
overall_dis = sObj.total_discount
total_amount = rebate_prices - payparcost + overall_dis
if total_amount > 0
receipt_no = sObj.receipt_no
membership = MembershipSetting.find_by_membership_type("paypar_url")

View File

@@ -6,7 +6,7 @@
<div class="row">
<div class="form-group col-lg-12 col-md-12 col-sm-12">
<label class="col-lg-4 col-md-4 col-sm-4">You can redeem upto </label>
<input type="text" name="" id="" class="form-control col-lg-7 col-md-7 col-sm-7" readonly="" value="<%= @food_prices %>" data-value="<%=@sale_id %>" data-member-value="<%= @membership_id %>">
<input type="text" name="" id="" class="form-control col-lg-7 col-md-7 col-sm-7" readonly="" value="<%= @redeem_prices %>" data-value="<%=@sale_id %>" data-member-value="<%= @membership_id %>">
</div>
<hr>
</div>
@@ -38,7 +38,7 @@
<!-- <% if @payparcount > 0 %>
<p class="">Last time rebate amount is <%= @payparcount %></p>
<% end %>
<p class="">You can rebate upto <span style="color:red;" id="food_prices"><%= @food_prices %></span></p> -->
<p class="">You can rebate upto <span style="color:red;" id="food_prices"><%= @redeem_prices %></span></p> -->
</div>
<div class="col-lg-6 col-md-7 col-sm-7">
@@ -151,7 +151,7 @@ $("#redeem").click(function(){
}else if(valid_amount< redeem_amount){
alert(" Insufficient Amount!")
}else{
if(redeem_amount <= "<%= @food_prices %>"){
if(redeem_amount <= "<%= @redeem_prices %>"){
$.ajax({
type: "POST",
url: "<%=origami_payment_paypar_path%>",