added member discount

This commit is contained in:
Aung Myo
2017-07-11 11:06:13 +06:30
parent f1f1253bde
commit 72aa769490
5 changed files with 99 additions and 10 deletions

View File

@@ -125,6 +125,71 @@ class Origami::DiscountsController < BaseOrigamiController
sale_id = params[:sale_id]
account_types = JSON.parse(params[:account_types])
sub_total = params[:sub_total]
sale = Sale.find(sale_id)
price = SaleItem.calculate_price_by_accounts(sale.sale_items)
arr = Array.new;
account_types.each do |at|
price.each do |pc|
if pc[:name].to_s == at["name"].to_s && pc[:price]>0
str={type:pc[:name],amount:pc[:price]}
arr.push(str)
end
end
end
generic_customer_id = sale.customer.membership_id
receipt_no = sale.receipt_no
membership = MembershipSetting.find_by_membership_type("paypar_url")
memberaction = MembershipAction.find_by_membership_type("member_discount")
merchant_uid = memberaction.merchant_account_id.to_s
campaign_type_id = memberaction.additional_parameter["campaign_type_id"]
auth_token = memberaction.auth_token.to_s
url = membership.gateway_url.to_s + memberaction.gateway_url.to_s
# Control for Paypar Cloud
begin
response = HTTParty.post(url,
:body => { generic_customer_id:generic_customer_id ,
campaign_type_id: campaign_type_id,
receipt_no: receipt_no,
merchant_uid:merchant_uid,
discount_method:arr.to_json,
total_sale_transaction_amount: sale.grand_total,
auth_token:auth_token}.to_json,
:headers => {
'Content-Type' => 'application/json',
'Accept' => 'application/json'
}, :timeout => 10)
rescue HTTParty::Error
response = {status: false, message: "Can't open membership server "}
rescue Net::OpenTimeout
response = { status: false , message: "Can't open membership server "}
rescue OpenURI::HTTPError
response = { status: false, message: "Can't open membership server "}
rescue SocketError
response = { status: false, message: "Can't open membership server "}
end
puts response.to_json
table_id = sale.bookings[0].dining_facility_id
table_type = DiningFacility.find(table_id).type
# Re-calc All Amount in Sale
if response["status"] == true
sale.compute_by_sale_items(sale_id, sale.sale_items, response["rebate_earned"].to_f,"member_discount")
end
result = {:status=> "Success", :table_id => table_id, :table_type => table_type,:table_type => table_type,:url_status => response[:status],:url_message => response[:message] }
render :json => result.to_json
end
#discount for selected order

View File

@@ -84,6 +84,7 @@ class Ability
can :create, :discount
can :remove_discount_items, :discount
can :remove_all_discount, :discount
can :member_discount, :discount
can :first_bill, :payment
can :show, :payment

View File

@@ -208,7 +208,7 @@ class Sale < ApplicationRecord
end
#compute - invoice total
def compute_by_sale_items(sale_id, sale_itemss, total_discount)
def compute_by_sale_items(sale_id, sale_itemss, total_discount,discount_type=nil)
sale = Sale.find(sale_id)
sales_items = sale_itemss
@@ -227,6 +227,9 @@ class Sale < ApplicationRecord
sale.total_amount = subtotal_price
sale.total_discount = total_discount
sale.grand_total = (sale.total_amount - sale.total_discount) + sale.total_tax
if discount_type == "member_discount"
sale.discount_type = discount_type
end
#compute rounding adjustment
# adjust_rounding

View File

@@ -191,7 +191,8 @@
<button id="remove-all" class="btn btn-warning btn-block action-btn">Remove All</button>
<button id="pay-discount" class="btn btn-danger btn-block action-btn">Enter</button>
<hr />
<button id="member-discount" class="btn btn-success btn-block action-btn">Member Discount</button>
<button id="member-discount" class="btn btn-success btn-block action-btn
<%= @sale_data.customer.membership_id ? " " : "disabled"%>">Member Discount</button>
</div>
</div>
</div>
@@ -496,14 +497,33 @@ $(document).ready(function(){
type: "POST",
url: ajax_url,
data: params,
success:function(result){
alert("Successfully Discount!");
if(result.table_type == "Table"){
window.location.href = "/origami/table/" + result.table_id
success:function(result){
if (result.url_status == false) {
status = result.url_message
}else{
status = result.status
}
else {
window.location.href = "/origami/room/" + result.table_id
}
$.confirm({
title: 'Infomation!',
content: status,
buttons: {
confirm: {
text: 'Ok',
btnClass: 'btn-green',
action: function(){
if(result.table_type == "Table"){
window.location.href = "/origami/table/" + result.table_id
}
else {
window.location.href = "/origami/room/" + result.table_id
}
}
}
}
});
}
});
});

View File

@@ -105,7 +105,7 @@ Rails.application.routes.draw do
post "/:id/remove_discount_items" => "discounts#remove_discount_items"
# Discount for Member
# post "/:id/member_discount" => "discounts#member_discount"
post "/:id/member_discount" => "discounts#member_discount"
get "/:id/request_bills" => "request_bills#print",:as => "request_bill"
get '/:sale_id/reprint' => 'payments#reprint' ,:defaults => { :format => 'json' }