diff --git a/app/assets/javascripts/origami.js b/app/assets/javascripts/origami.js index 0079142f..fbf641df 100644 --- a/app/assets/javascripts/origami.js +++ b/app/assets/javascripts/origami.js @@ -185,7 +185,7 @@ $(document).ready(function(){ }else{ var sale_id = $(".selected-item").find(".order-cid").text(); } - window.location.href = '/origami/'+ sale_id + "/add_customer" + window.location.href = '/origami/'+ sale_id + "/customers" return false; }); @@ -199,6 +199,7 @@ $(document).ready(function(){ } $('.customer_detail').removeClass('hide'); + //Start Ajax $.ajax({ type: "GET", @@ -210,8 +211,16 @@ $(document).ready(function(){ $.each(data["response_data"]["data"], function (i) { if(data["response_data"]["data"][i]["accountable_type"] == "RebateAccount"){ var balance = data["response_data"]["data"][i]["balance"]; - console.log(balance); - $("#customer_amount").text(balance); + if (data["response_data"]["status"]==true) { + $('.rebate_amount').removeClass('hide'); + console.log(balance); + row = + '' + data["response_data"]["data"][i]["accountable_type"] +'' + +'' + balance + ''; + + $(".rebate_amount").append(row); + } + } }); } diff --git a/app/controllers/crm/customers_controller.rb b/app/controllers/crm/customers_controller.rb index 1f35da76..57f4eafc 100644 --- a/app/controllers/crm/customers_controller.rb +++ b/app/controllers/crm/customers_controller.rb @@ -45,6 +45,35 @@ class Crm::CustomersController < BaseCrmController @sale_items = @sale_items + sale.sale_items end end + + #get customer amount + @customer = Customer.find(params[:id]) + + membership = MembershipSetting.find_by_membership_type("paypar_url") + + memberaction = MembershipAction.find_by_membership_type("get_all_member_account") + merchant_uid = memberaction.merchant_account_id.to_s + auth_token = memberaction.auth_token.to_s + url = membership.gateway_url.to_s + memberaction.gateway_url.to_s + + response = HTTParty.get(url, :body => { membership_id: @customer.membership_id,merchant_uid:merchant_uid,auth_token:auth_token}.to_json, + :headers => { + 'Content-Type' => 'application/json', + 'Accept' => 'application/json' + } + ) + + @type = "-" + @balance = 0.00 + response["data"].each do |res| + if res["accountable_type"] == "RebateAccount" + @balance = res["balance"] + @type = "RebateAccount" + end + end + + #end customer amount + end # GET /crm/customers/new @@ -76,11 +105,12 @@ class Crm::CustomersController < BaseCrmController membership = MembershipSetting.find_by_membership_type("paypar_url") memberaction = MembershipAction.find_by_membership_type("create_membership_customer") merchant_uid = memberaction.merchant_account_id.to_s + auth_token = memberaction.auth_token.to_s url = membership.gateway_url.to_s + memberaction.gateway_url.to_s response = HTTParty.post(url, :body => { name: name,phone: phone,email: email, dob: dob, - member_group_id: member_group_id,merchant_uid:merchant_uid}.to_json, + member_group_id: member_group_id,merchant_uid:merchant_uid,auth_token:auth_token}.to_json, :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json' @@ -93,7 +123,7 @@ class Crm::CustomersController < BaseCrmController status = customer.update_attributes(membership_id: response["customer_datas"]["id"]) if params[:sale_id] - format.html { redirect_to '/origami/'+params[:sale_id]+'/add_customer', notice: 'Customer was successfully created.' } + format.html { redirect_to '/origami/'+params[:sale_id]+'/customers', notice: 'Customer was successfully created.' } else format.html { redirect_to crm_customers_path, notice: 'Customer was successfully created'} end @@ -102,7 +132,7 @@ class Crm::CustomersController < BaseCrmController @crm_customers.destroy if params[:sale_id] - format.html { redirect_to '/origami/'+params[:sale_id]+'/add_customer'} + format.html { redirect_to '/origami/'+params[:sale_id]+'/customers'} else format.html { redirect_to crm_customers_path, notice: response["message"] } end @@ -111,7 +141,7 @@ class Crm::CustomersController < BaseCrmController if params[:sale_id] flash[:errors] = @crm_customers.errors - format.html { redirect_to '/origami/'+params[:sale_id]+'/add_customer'} + format.html { redirect_to '/origami/'+params[:sale_id]+'/customers'} format.json { render json: @crm_customers.errors, status: :unprocessable_entity } else flash[:errors] = @crm_customers.errors @@ -140,11 +170,12 @@ end membership = MembershipSetting.find_by_membership_type("paypar_url") memberaction = MembershipAction.find_by_membership_type("update_membership_customer") merchant_uid = memberaction.merchant_account_id.to_s + auth_token = memberaction.auth_token.to_s url = membership.gateway_url.to_s + memberaction.gateway_url.to_s response = HTTParty.post(url, :body => { name: name,phone: phone,email: email, dob: dob, - id: id,member_group_id:member_group_id,merchant_uid:merchant_uid}.to_json, + id: id,member_group_id:member_group_id,merchant_uid:merchant_uid,auth_token:auth_token}.to_json, :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json' diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb index de526f81..22c0c119 100644 --- a/app/controllers/origami/home_controller.rb +++ b/app/controllers/origami/home_controller.rb @@ -74,9 +74,10 @@ class Origami::HomeController < BaseOrigamiController memberaction = MembershipAction.find_by_membership_type("get_all_member_account") merchant_uid = memberaction.merchant_account_id.to_s + auth_token = memberaction.auth_token.to_s url = membership.gateway_url.to_s + memberaction.gateway_url.to_s - response = HTTParty.get(url, :body => { membership_id: @customer.membership_id,merchant_uid:merchant_uid}.to_json, + response = HTTParty.get(url, :body => { membership_id: @customer.membership_id,merchant_uid:merchant_uid,auth_token:auth_token}.to_json, :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json' diff --git a/app/controllers/origami/redeem_payments_controller.rb b/app/controllers/origami/redeem_payments_controller.rb index b68fd30a..94636c70 100644 --- a/app/controllers/origami/redeem_payments_controller.rb +++ b/app/controllers/origami/redeem_payments_controller.rb @@ -18,7 +18,8 @@ class Origami::RedeemPaymentsController < BaseOrigamiController @campaign_type_id = member_actions.additional_parameter["campaign_type_id"] url = membership_setting.gateway_url.to_s + member_actions.gateway_url.to_s merchant_uid= member_actions.merchant_account_id - membership_data = SalePayment.get_paypar_account(url,membership_setting.auth_token,@membership_id,@campaign_type_id,merchant_uid) + auth_token = member_actions.auth_token.to_s + membership_data = SalePayment.get_paypar_account(url,membership_setting.auth_token,@membership_id,@campaign_type_id,merchant_uid,auth_token) if membership_data["status"]==true @membership_rebate_balance=membership_data["balance"] @out = true, @membership_rebate_balance,@membership_id diff --git a/app/controllers/reports/daily_sale_controller.rb b/app/controllers/reports/daily_sale_controller.rb index b4c701ae..b487c269 100644 --- a/app/controllers/reports/daily_sale_controller.rb +++ b/app/controllers/reports/daily_sale_controller.rb @@ -1,21 +1,9 @@ class Reports::DailySaleController < BaseReportController - PERIOD = { - "today" => 0, - "yesterday" => 1, - "this_week" => 2, - "last_week" => 3, - "last_7" => 4, - "this_month" => 5, - "last_month" => 6, - "last_30" => 7, - "this_year" => 8, - "last_year" => 9 - } def index from, to = get_date_range_from_params @sale_data = Sale.get_receipt_no_list(from,to) @sale_data = Kaminari.paginate_array(@sale_data).page(params[:page]).per(50) -end + end end \ No newline at end of file diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 894592b5..72260344 100644 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -66,9 +66,9 @@ class SalePayment < ApplicationRecord end - def self.get_paypar_account(url,token,membership_id,campaign_type_id,merchant_uid) + def self.get_paypar_account(url,token,membership_id,campaign_type_id,merchant_uid,auth_token) response = HTTParty.get(url, - :body => { app_token: token,membership_id:membership_id,campaign_type_id:campaign_type_id,merchant_uid:merchant_uid}.to_json, + :body => { app_token: token,membership_id:membership_id,campaign_type_id:campaign_type_id,merchant_uid:merchant_uid,auth_token:auth_token}.to_json, :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json' @@ -83,11 +83,12 @@ class SalePayment < ApplicationRecord if !membership_actions_data.nil? url = paypar_url.to_s + membership_actions_data.gateway_url.to_s merchant_uid = membership_actions_data.merchant_account_id + auth_token = membership_actions_data.auth_token campaign_type_id = membership_actions_data.additional_parameter["campaign_type_id"] sale_data = Sale.find_by_sale_id(sale_id) if sale_data response = HTTParty.post(url, - :body => { generic_customer_id:membership_id,redeem_amount:received_amount,receipt_no:sale_data.receipt_no,campaign_type_id:campaign_type_id,account_no:"",merchant_uid:merchant_uid}.to_json, + :body => { generic_customer_id:membership_id,redeem_amount:received_amount,receipt_no:sale_data.receipt_no,campaign_type_id:campaign_type_id,account_no:"",merchant_uid:merchant_uid,auth_token:auth_token}.to_json, :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json' diff --git a/app/views/crm/customers/show.html.erb b/app/views/crm/customers/show.html.erb index df1184b7..62ebf9c0 100644 --- a/app/views/crm/customers/show.html.erb +++ b/app/views/crm/customers/show.html.erb @@ -26,6 +26,9 @@ Contact no Company Date Of Birth + Membership Account + Balance + Type @@ -36,7 +39,11 @@ <%= @crm_customer.contact_no %> <%= @crm_customer.company %> <%= @crm_customer.date_of_birth %> - + <%= @balance %> + <%= @type %> + <% +puts "hhhhhhhhhhhhhhhhhhhhh" + puts @member_data.to_json %> diff --git a/app/views/origami/customers/index.html.erb b/app/views/origami/customers/index.html.erb index bb3c96e6..6fa5ae03 100644 --- a/app/views/origami/customers/index.html.erb +++ b/app/views/origami/customers/index.html.erb @@ -14,7 +14,7 @@
-
+
@@ -38,7 +38,6 @@ Company Contact no Email - Date of Birth @@ -51,10 +50,7 @@ <%= crm_customer.company rescue '-' %> <%= crm_customer.contact_no %> <%= crm_customer.email %> - - <%= crm_customer.date_of_birth rescue '-' %> - - + <% end %> @@ -68,7 +64,7 @@
-
+
<%= simple_form_for @crm_customer,:url => crm_customers_path, :method => :post do |f| %> @@ -92,27 +88,32 @@
- - <%= f.text_field :date_of_birth,:class=>"form-control datepicker"%> + + <%= f.text_field :date_of_birth,:class=>"form-control datepicker"%> +
+ +
+ + +
+ +
+ <%= f.button :submit, "Submit",:class => 'btn btn-primary ', :id => 'submit_customer' %> + +
+ <%end%> +
+ - -
- - -
- -
- <%= f.button :submit, "Submit",:class => 'btn btn-primary ', :id => 'submit_customer' %> - -
- <%end%> -
@@ -197,7 +198,7 @@ success: function(data) { if(data.status == true) { - alert('Customer has assigned'); + window.location.href = '/origami' }else{ alert('Record not found!'); diff --git a/app/views/origami/home/index.html.erb b/app/views/origami/home/index.html.erb index 24410ef8..f9356f68 100644 --- a/app/views/origami/home/index.html.erb +++ b/app/views/origami/home/index.html.erb @@ -297,9 +297,7 @@

Customer :

-
-

Amount :

-
+
@@ -373,6 +371,9 @@ + + +
Grand Total: <%=@selected_item.grand_total rescue 0%>
diff --git a/app/views/reports/receipt_no/_shift_sale_report_filter.html.erb b/app/views/reports/_shift_sale_report_filter.html.erb similarity index 100% rename from app/views/reports/receipt_no/_shift_sale_report_filter.html.erb rename to app/views/reports/_shift_sale_report_filter.html.erb diff --git a/config/routes.rb b/config/routes.rb index c4592d6d..1a031ded 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -99,7 +99,7 @@ Rails.application.routes.draw do #---------Add Customer --------------# #resources :customers - get '/:sale_id/add_customer', to: "customers#add_customer" + get '/:sale_id/customers', to: "customers#add_customer" get '/:customer_id/get_customer' => 'home#get_customer' post '/:sale_id/update_sale' , to: "home#update_sale_by_customer"#update customer id in sale table end diff --git a/db/seeds.rb b/db/seeds.rb index 1e3e30b1..709a20ee 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -145,13 +145,13 @@ crm_order_printer=PrintSetting.create({name: "CRM Order", unique_code: "CrmOrder member_setting = MembershipSetting.create({membership_type:"paypar_url",gateway_url: "http://192.168.1.47:3006",merchant_account_id:"vWSsseoZCzxd6xcNf_uS"}) -member_actions= MembershipAction.create([{membership_type:"get_account_balance",gateway_url:"/api/membership_campaigns/get_correspond_account_data",additional_parameter:{campaign_type_id:1},merchant_account_id:"vWSsseoZCzxd6xcNf_uS"}, - {membership_type:"redeem",gateway_url:"/api/membership_campaigns/redeem",additional_parameter:{campaign_type_id:1},merchant_account_id:"vWSsseoZCzxd6xcNf_uS"}, - {membership_type:"create_membership_customer",gateway_url:"/api/generic_customer/create_membership_customer",merchant_account_id:"vWSsseoZCzxd6xcNf_uS"}, - {membership_type:"update_membership_customer",gateway_url:"/api/generic_customer/update_membership_customer",merchant_account_id:"vWSsseoZCzxd6xcNf_uS"}, - {membership_type:"get_all_member_group",gateway_url:"/api/member_group/get_all_member_group",merchant_account_id:"vWSsseoZCzxd6xcNf_uS"}, - {membership_type:"rebate",gateway_url:"/api/membership_campaigns/rebate",additional_parameter:{campaign_type_id:1},merchant_account_id:"vWSsseoZCzxd6xcNf_uS"}, - {membership_type:"get_all_member_account",gateway_url:"/api/generic_customer/get_membership_data",merchant_account_id:"vWSsseoZCzxd6xcNf_uS"} +member_actions= MembershipAction.create([{membership_type:"get_account_balance",gateway_url:"/api/membership_campaigns/get_correspond_account_data",additional_parameter:{campaign_type_id:1},merchant_account_id:"vWSsseoZCzxd6xcNf_uS",auth_token:"code2lab"}, + {membership_type:"redeem",gateway_url:"/api/membership_campaigns/redeem",additional_parameter:{campaign_type_id:1},merchant_account_id:"vWSsseoZCzxd6xcNf_uS",auth_token:"code2lab"}, + {membership_type:"create_membership_customer",gateway_url:"/api/generic_customer/create_membership_customer",merchant_account_id:"vWSsseoZCzxd6xcNf_uS",auth_token:"code2lab"}, + {membership_type:"update_membership_customer",gateway_url:"/api/generic_customer/update_membership_customer",merchant_account_id:"vWSsseoZCzxd6xcNf_uS",auth_token:"code2lab"}, + {membership_type:"get_all_member_group",gateway_url:"/api/member_group/get_all_member_group",merchant_account_id:"vWSsseoZCzxd6xcNf_uS",auth_token:"code2lab"}, + {membership_type:"rebate",gateway_url:"/api/membership_campaigns/rebate",additional_parameter:{campaign_type_id:1},merchant_account_id:"vWSsseoZCzxd6xcNf_uS",auth_token:"code2lab"}, + {membership_type:"get_all_member_account",gateway_url:"/api/generic_customer/get_membership_data",merchant_account_id:"vWSsseoZCzxd6xcNf_uS",auth_token:"code2lab"} ]) payment_methods = PaymentMethodSetting.create({payment_method:"MPU",gateway_url: "http//192.168.1.47:3006"})