From e878a6387e01e6cd865e5505fcce3b316aa3dcdb Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Thu, 14 Sep 2017 17:36:00 +0630 Subject: [PATCH] update member discount --- .../origami/discounts_controller.rb | 165 ++--- app/controllers/origami/jcb_controller.rb | 3 + app/controllers/origami/master_controller.rb | 3 + app/controllers/origami/mpu_controller.rb | 8 +- .../origami/payments_controller.rb | 2 + app/controllers/origami/visa_controller.rb | 3 + app/models/sale_item.rb | 10 + app/models/sale_payment.rb | 2 + app/views/origami/discounts/index.html.erb | 2 +- app/views/origami/jcb/index.html.erb | 289 +++++---- app/views/origami/master/index.html.erb | 295 +++++---- app/views/origami/mpu/index.html.erb | 302 +++++---- app/views/origami/payments/show.html.erb | 608 +++++++++--------- app/views/origami/visa/index.html.erb | 295 +++++---- 14 files changed, 1055 insertions(+), 932 deletions(-) diff --git a/app/controllers/origami/discounts_controller.rb b/app/controllers/origami/discounts_controller.rb index 1e14fbc5..8fddfa0f 100644 --- a/app/controllers/origami/discounts_controller.rb +++ b/app/controllers/origami/discounts_controller.rb @@ -127,88 +127,91 @@ class Origami::DiscountsController < BaseOrigamiController # Member Discount def member_discount - sale_id = params[:sale_id] - # account_types = JSON.parse(params[:account_types]) - account_types = Account.where("discount=?",true) - 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] == at.title && 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 - - # Check for items for Paypar Cloud - if arr.length > 0 - begin - response = HTTParty.post(url, - :body => { account_no: nil, - generic_customer_id:generic_customer_id , - campaign_type_id: campaign_type_id, - receipt_no: receipt_no, - merchant_uid:merchant_uid, - campaign_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 - else - response = {:status=> false, :message => "You have no selected discount item" } - end - - 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 - discount_amount = response["discount_earned"] - if response["discount_bonus_earned"] - discount_amount = discount_amount + response["discount_bonus_earned"] - end - sale.compute_by_sale_items(sale_id, sale.sale_items, discount_amount, 'member_discount') - result = {:status=> "Success",:title=>"Member Discount", :table_id => table_id,:table_type => table_type } - end - - if response["status"] == "500" - result = {:status=> response["error"],:title=>"Alert", :table_id => table_id,:table_type => table_type } - end - if !response.nil? - if response[:status] == false - result = {:status=> response[:message],:title=>"Alert", :table_id => table_id,:table_type => table_type } - end - end - render :json => result.to_json + sale_id = params[:sale_id] + is_card = params[:is_card] + sub_total = params[:sub_total] + sale = Sale.find(sale_id) + + # Check for Card Payment + is_card_payment = SaleItem.get_sale_payments_by_card(sale.sale_payments) + + if is_card_payment != true + account_types = Account.where("discount=?",true) + table_id = sale.bookings[0].dining_facility_id + table_type = DiningFacility.find(table_id).type + + # Get Prices for each accounts (eg: food, beverage) + account_price = SaleItem.calculate_price_by_accounts(sale.sale_items) + acc_prices = Array.new; + + account_types.each do |at| + account_price.each do |pc| + if pc[:name] == at.title && pc[:price]>0 + str={type:pc[:name],amount:pc[:price]} + acc_prices.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 + + # Check for items for Paypar Cloud + if acc_prices.length > 0 + begin + response = HTTParty.post(url, + :body => { account_no: nil, + generic_customer_id:generic_customer_id , + campaign_type_id: campaign_type_id, + receipt_no: receipt_no, + merchant_uid:merchant_uid, + campaign_method:acc_prices.to_json, + total_sale_transaction_amount: sale.grand_total, + is_card: is_card, + 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 + else + response = {"status": false, "message": "You have no selected discount item" } + end + + # Re-calc All Amount in Sale + if response["status"] == true + discount_amount = response["discount_earned"] + if response["discount_bonus_earned"] + discount_amount = discount_amount + response["discount_bonus_earned"] + end + sale.compute_by_sale_items(sale_id, sale.sale_items, discount_amount, 'member_discount') + result = {:status=> "Success",:title=>"Member Discount", :table_id => table_id,:table_type => table_type } + elsif response["status"] == "500" + result = {:status=> response["error"],:title=>"Alert", :table_id => table_id,:table_type => table_type } + else + result = {:status=> response["message"],:title=>"Alert", :table_id => table_id,:table_type => table_type } + end + + render :json => result.to_json + + end #end Is Card Payment end #discount for selected order diff --git a/app/controllers/origami/jcb_controller.rb b/app/controllers/origami/jcb_controller.rb index 5bed3470..a8b77861 100644 --- a/app/controllers/origami/jcb_controller.rb +++ b/app/controllers/origami/jcb_controller.rb @@ -17,6 +17,9 @@ class Origami::JcbController < BaseOrigamiController end @can_jcb = total - @jcbcount - others + @member_discount = MembershipSetting.find_by_discount(1) + @sub_total = sale_data.total_amount + @membership_id = sale_data.customer.membership_id end def create diff --git a/app/controllers/origami/master_controller.rb b/app/controllers/origami/master_controller.rb index 67107167..ba97cad9 100644 --- a/app/controllers/origami/master_controller.rb +++ b/app/controllers/origami/master_controller.rb @@ -16,6 +16,9 @@ class Origami::MasterController < BaseOrigamiController end end @can_master = total - @mastercount - others + @member_discount = MembershipSetting.find_by_discount(1) + @sub_total = sale_data.total_amount + @membership_id = sale_data.customer.membership_id end def create diff --git a/app/controllers/origami/mpu_controller.rb b/app/controllers/origami/mpu_controller.rb index 3707d1f4..c9f707e3 100644 --- a/app/controllers/origami/mpu_controller.rb +++ b/app/controllers/origami/mpu_controller.rb @@ -5,9 +5,10 @@ class Origami::MpuController < BaseOrigamiController # limit mpu_amount sale_data = Sale.find_by_sale_id(@sale_id) - total = sale_data.grand_total + total = sale_data.grand_total @mpucount = 0 - others = 0 + others = 0 + sale_data.sale_payments.each do |sale_payment| if sale_payment.payment_method == "mpu" @mpucount = @mpucount + sale_payment.payment_amount @@ -17,6 +18,9 @@ class Origami::MpuController < BaseOrigamiController end @can_mpu = total - @mpucount - others + @member_discount = MembershipSetting.find_by_discount(1) + @sub_total = sale_data.total_amount + @membership_id = sale_data.customer.membership_id end def create diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 109138a5..2a9fe5d9 100644 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -75,6 +75,8 @@ class Origami::PaymentsController < BaseOrigamiController def show sale_id = params[:sale_id] + + @member_discount = MembershipSetting.find_by_discount(1) if Sale.exists?(sale_id) @cash = 0.0 diff --git a/app/controllers/origami/visa_controller.rb b/app/controllers/origami/visa_controller.rb index 3cb8cabb..552d960b 100644 --- a/app/controllers/origami/visa_controller.rb +++ b/app/controllers/origami/visa_controller.rb @@ -16,6 +16,9 @@ class Origami::VisaController < BaseOrigamiController end end @can_visa = total - @visacount - others + @member_discount = MembershipSetting.find_by_discount(1) + @sub_total = sale_data.total_amount + @membership_id = sale_data.customer.membership_id end def create diff --git a/app/models/sale_item.rb b/app/models/sale_item.rb index b8ae456d..c4aae1fa 100644 --- a/app/models/sale_item.rb +++ b/app/models/sale_item.rb @@ -107,7 +107,17 @@ class SaleItem < ApplicationRecord return price,type end + # Check for Card Payment + def self.get_sale_payments_by_card(sale_payments) + # Check for Card Payment + sale_payments.each do |sp| + if sp.payment_method == "jcb" || sp.payment_method == "mpu" || sp.payment_method == "visa" || sp.payment_method == "master" + return true; + end + end + + end # def self.get_overall_discount(sale_id) # price = 0.0 # item=SaleItem.where("product_code=?", sale_id) diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 4719e546..5f97bcfc 100644 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -263,6 +263,8 @@ class SalePayment < ApplicationRecord end def sale_update_payment_status(paid_amount) + puts paid_amount + puts "parid Masssssssssssssssssssssssssssssssssssssssss" #update amount_outstanding self.sale.amount_received = self.sale.amount_received.to_f + paid_amount.to_f self.sale.save! diff --git a/app/views/origami/discounts/index.html.erb b/app/views/origami/discounts/index.html.erb index 378bcbe3..55e649ed 100644 --- a/app/views/origami/discounts/index.html.erb +++ b/app/views/origami/discounts/index.html.erb @@ -510,7 +510,7 @@ $(document).ready(function(){ url: ajax_url, data: params, success:function(result){ - +console.log(result) if (result.status == "Success") { type = 'green' btn_color = 'btn-green' diff --git a/app/views/origami/jcb/index.html.erb b/app/views/origami/jcb/index.html.erb index e9cc09fa..42927273 100644 --- a/app/views/origami/jcb/index.html.erb +++ b/app/views/origami/jcb/index.html.erb @@ -7,163 +7,180 @@

JCB

-
-
-
-
- - -
-
+ + + +
+
+
+
+ +
- <% if @jcbcount != 0 %> -
-
- - -
-
+
+
+ <% if @jcbcount != 0 %> +
+
+ +
- <% end %> -
-
- - -
-
-
-
-
- -
0.0
-
-
-
-
+
+
+ <% end %> +
+
+ + +
+
+
+
+
+ +
0.0
+
+
+
+
-
+
-
-
-
-
1
-
2
-
3
-
-
-
4
-
5
-
6
-
-
-
7
-
8
-
9
-
-
-
0
-
.
-
00
-
-
-
Nett
-
Del
-
Clr
-
-
-
-
-
1000
-
3000
-
-
-
5000
-
10000
-
-
-
Pay
-
-
-
- -
- -
- +
+
+
+
1
+
2
+
3
+
+
+
4
+
5
+
6
+
+
+
7
+
8
+
9
+
+
+
0
+
.
+
00
+
+
+
Nett
+
Del
+
Clr
+
+
+
+
+
1000
+
3000
+
+
+
5000
+
10000
+
+
+
Pay
+
+
+ +
+ +
+ +
diff --git a/app/views/origami/master/index.html.erb b/app/views/origami/master/index.html.erb index 6afc1081..14286215 100644 --- a/app/views/origami/master/index.html.erb +++ b/app/views/origami/master/index.html.erb @@ -7,160 +7,177 @@

Master

-
-
-
-
- - -
-
-
- <% if @mastercount != 0 %> -
-
- - -
-
-
- <% end %> -
-
- - -
-
-
-
-
- -
0.0
-
-
-
-
-
- - -
- -
-
-
-
1
-
2
-
3
-
-
-
4
-
5
-
6
-
-
-
7
-
8
-
9
-
-
-
0
-
.
-
00
-
-
-
Nett
-
Del
-
Clr
-
-
-
-
-
1000
-
3000
-
-
-
5000
-
10000
-
-
-
Pay
-
-
+ + + +
+
+
+
+ + +
+
- + <% if @mastercount != 0 %> +
+
+ + +
+
+
+ <% end %> +
+
+ + +
+
+
+
+ +
0.0
+
+
+
+
+
+
-
- -
+
+ +
+
+
+
1
+
2
+
3
+
+
+
4
+
5
+
6
+
+
+
7
+
8
+
9
+
+
+
0
+
.
+
00
+
+
+
Nett
+
Del
+
Clr
+
+
+
+
+
1000
+
3000
+
+
+
5000
+
10000
+
+
+
Pay
+
+
+
+ +
+ +
+ +
diff --git a/app/views/origami/mpu/index.html.erb b/app/views/origami/mpu/index.html.erb index e8e25b2f..263996b7 100644 --- a/app/views/origami/mpu/index.html.erb +++ b/app/views/origami/mpu/index.html.erb @@ -7,160 +7,178 @@

MPU

-
-
-
-
- - -
-
-
- <% if @mpucount != 0 %> -
-
- - -
-
-
- <% end %> -
-
- - -
-
-
-
-
- -
0.0
-
-
-
-
+ + + +
+
+
+
+ + +
+
+
+ <% if @mpucount != 0 %> +
+
+ + +
+
+
+ <% end %> +
+
+ + +
+
+
+
+
+ +
0.0
+
+
+
+
-
+
-
-
-
-
1
-
2
-
3
-
-
-
4
-
5
-
6
-
-
-
7
-
8
-
9
-
-
-
0
-
.
-
00
-
-
-
Nett
-
Del
-
Clr
-
-
-
-
-
1000
-
3000
-
-
-
5000
-
10000
-
-
-
Pay
-
-
-
- -
- -
- +
+
+
+
1
+
2
+
3
+
+
+
4
+
5
+
6
+
+
+
7
+
8
+
9
+
+
+
0
+
.
+
00
+
+
+
Nett
+
Del
+
Clr
+
+
+
+
+
1000
+
3000
+
+
+
5000
+
10000
+
+
+
Pay
+
+
+ +
+ +
+ +
+ }); + $('#mpu_pay').on('click',function(){ + var amount = $('#amount').text(); + var sale_id = "<%= @sale_id %>"; + if(parseFloat(amount) <= parseFloat($("#validamount").attr("value")) ){ + //start member discount 5% by pay card + var sub_total = $('#sub-total').text(); + var member_id = $('#membership_id').text(); + var member_discount = $('#member_discount').text(); + if (member_id && member_discount) { + $.ajax({ + type: "POST", + url: "/origami/" + sale_id + "/member_discount", + data: {'sale_id':sale_id, 'sub_total':sub_total,'is_card':true }, + // success:function(result){ + // } + }); + } + //end member discount + //Mpu Payment + $.ajax({type: "POST", + url: "<%= origami_payment_mpu_path %>", + data: "amount="+ amount + "&sale_id="+ sale_id, + success:function(result){ + if(result){ + alert("Payment success") + window.location.href = '/origami/sale/'+ sale_id + "/payment"; + } + } + }); + }else{ + alert("Paid Amount is over!") + } + }) + diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index 36c4cc0e..f0298e73 100644 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -1,8 +1,8 @@ +
+
-
+
@@ -17,6 +17,8 @@ Customer : <%= @sale_data.customer.name%> + + Customer ID : <%= @sale_data.customer.customer_id%> @@ -26,82 +28,82 @@
- - - - + + + - -
#ItemsQTY +
#ItemsQTY Price -
-
-
- - - <% sub_total = 0 - count = 0 - %> - <% @sale_data.sale_items.each do |sale_item| - count += 1 - %> + + +
+
+
+ + + <% sub_total = 0 + count = 0 + %> + <% @sale_data.sale_items.each do |sale_item| + count += 1 + %> - <% sub_total += sale_item.price%> - + <% sub_total += sale_item.price%> + - - - - <%end %> - -
<%= count %> - <%=sale_item.product_name%>@<%=sale_item.unit_price%> - - <%=sale_item.qty%> - - <%=(sale_item.price)%> -
-
- -
+ <%=sale_item.product_name%>@<%=sale_item.unit_price%> + + + <%=sale_item.qty%> + + + <%=(sale_item.price)%> + + + <%end %> + + +
+ +
+ -->
@@ -123,159 +125,159 @@
<%= @credit %>
<% if @other == 0.0 && @ppamount == 0.0 && @visacount == 0.0 && @jcbcount == 0.0 && @mastercount == 0.0%> -
-
Other Payments
-
<%= @other %>
-
+
+
Other Payments
+
<%= @other %>
+
<% else %> -
-
Other Payments
-
+
+
Other Payments
+
<% end %> - - <% if @other != 0.0 %> -
-
-
MPU
-
<%= @other %>
-
- <% else %> - - <% end %> - - <% if @ppamount != 0.0 %> -
-
-
Redeem
-
<%= @ppamount %>
-
- <% else %> - - <% end %> - - <% if @visacount != 0.0 %> -
-
-
Visa
-
<%= @visacount %>
-
- <% else %> - - <% end %> - - <% if @jcbcount != 0.0 %> -
-
-
JCB
-
<%= @jcbcount %>
-
- <% else %> - - <% end %> - - <% if @mastercount != 0.0 %> -
-
-
Master
-
<%= @mastercount %>
-
- <% else %> - - <% end %> -
+ + <% if @other != 0.0 %> +
+
+
MPU
+
<%= @other %>
+
+ <% else %> + + <% end %> + + <% if @ppamount != 0.0 %> +
+
+
Redeem
+
<%= @ppamount %>
+
+ <% else %> + + <% end %> + + <% if @visacount != 0.0 %> +
+
+
Visa
+
<%= @visacount %>
+
+ <% else %> + + <% end %> + + <% if @jcbcount != 0.0 %> +
+
+
JCB
+
<%= @jcbcount %>
+
+ <% else %> + + <% end %> + + <% if @mastercount != 0.0 %> +
+
+
Master
+
<%= @mastercount %>
+
+ <% else %> + + <% end %> +
Balance
<%= @sale_data.grand_total %>

-
-
-
-
1
-
2
-
3
-
-
-
4
-
5
-
6
-
-
-
7
-
8
-
9
-
-
-
0
-
.
-
00
-
-
-
Nett
-
Del
-
Clr
-
-
-
-
-
1000
-
3000
-
-
-
5000
-
10000
-
-
-
Pay
-
-
-
+
+
+
+
1
+
2
+
3
+
+
+
4
+
5
+
6
+
+
+
7
+
8
+
9
+
+
+
0
+
.
+
00
+
+
+
Nett
+
Del
+
Clr
+
+
+
+
+
1000
+
3000
+
+
+
5000
+
10000
+
+
+
Pay
+
+
+
-
-
- +
+
+ - - - -
+ + + +
-
+ \ No newline at end of file diff --git a/app/views/origami/visa/index.html.erb b/app/views/origami/visa/index.html.erb index 1589ca1b..bc78608b 100644 --- a/app/views/origami/visa/index.html.erb +++ b/app/views/origami/visa/index.html.erb @@ -7,160 +7,177 @@

VISA

-
-
-
-
- - -
-
-
- <% if @visacount != 0 %> -
-
- - -
-
-
- <% end %> -
-
- - -
-
-
-
-
- -
0.0
-
-
-
-
-
- - -
- -
-
-
-
1
-
2
-
3
-
-
-
4
-
5
-
6
-
-
-
7
-
8
-
9
-
-
-
0
-
.
-
00
-
-
-
Nett
-
Del
-
Clr
-
-
-
-
-
1000
-
3000
-
-
-
5000
-
10000
-
-
-
Pay
-
-
+ + + +
+
+
+
+ + +
+
- + <% if @visacount != 0 %> +
+
+ + +
+
+
+ <% end %> +
+
+ + +
+
+
+
+ +
0.0
+
+
+
+
+
+
-
- -
+
+ +
+
+
+
1
+
2
+
3
+
+
+
4
+
5
+
6
+
+
+
7
+
8
+
9
+
+
+
0
+
.
+
00
+
+
+
Nett
+
Del
+
Clr
+
+
+
+
+
1000
+
3000
+
+
+
5000
+
10000
+
+
+
Pay
+
+
+
+ +
+ +
+ +