diff --git a/10 b/10 new file mode 100644 index 00000000..e69de29b diff --git a/Can't open membership server } b/Can't open membership server } new file mode 100644 index 00000000..e69de29b diff --git a/app/controllers/crm/customers_controller.rb b/app/controllers/crm/customers_controller.rb index 52149abb..c895c4b6 100644 --- a/app/controllers/crm/customers_controller.rb +++ b/app/controllers/crm/customers_controller.rb @@ -1,6 +1,6 @@ class Crm::CustomersController < BaseCrmController load_and_authorize_resource except: [:create] - before_action :set_crm_customer, only: [:show, :edit, :update, :destroy] + before_action :set_crm_customer, only: [:show, :edit, :update, :destroy,:sync] # GET /crm/customers # GET /crm/customers.json @@ -8,6 +8,7 @@ class Crm::CustomersController < BaseCrmController filter = params[:filter] filter_card_no = params[:filter_card_no] type = params[:type] + @customer_update_phone_email =false if filter_card_no=="" @crm_customers = Customer.all elsif !filter_card_no.nil? @@ -16,25 +17,44 @@ class Crm::CustomersController < BaseCrmController @crm_customers = Customer.all else @crm_customers = Customer.search(filter) + # paymal_customer = Customer.search_paypar_account_no(filter) # search account no from paypar - if !@crm_customers.present? && type == "card" - response = Customer.search_paypar_account_no(filter) - if response["status"] == true - @crm_customers = Customer.new - @crm_customers.name = response["customer_data"]["name"] - @crm_customers.contact_no = response["customer_data"]["phone"] - @crm_customers.email = response["customer_data"]["email"] - @crm_customers.date_of_birth = response["customer_data"]["DOB"] - @crm_customers.nrc_no = response["customer_data"]["NRC"] - @crm_customers.address = response["customer_data"]["address"] - @crm_customers.card_no = response["customer_data"]["customer_card_no"] - @crm_customers.paypar_account_no = filter - @crm_customers.membership_id = response["customer_data"]["id"] - @crm_customers.membership_type = response["customer_data"]["member_group_id"] - @crm_customers.customer_type = "Dinein" - @crm_customers.tax_profiles = ["1", "2"] - @crm_customers.save - @crm_customers = Customer.search(filter) + if type == "card" + + response = Customer.search_paypar_account_no(filter) + if !@crm_customers.present? + if response["status"] == true + @crm_customers = Customer.new + @crm_customers.name = response["customer_data"]["name"] + @crm_customers.contact_no = response["customer_data"]["phone"] + @crm_customers.email = response["customer_data"]["email"] + @crm_customers.date_of_birth = response["customer_data"]["DOB"] + @crm_customers.nrc_no = response["customer_data"]["NRC"] + @crm_customers.address = response["customer_data"]["address"] + @crm_customers.card_no = response["customer_data"]["customer_card_no"] + @crm_customers.paypar_account_no = filter + @crm_customers.membership_id = response["customer_data"]["id"] + @crm_customers.membership_type = response["customer_data"]["member_group_id"] + @crm_customers.customer_type = "Dinein" + @crm_customers.tax_profiles = ["1", "2"] + @crm_customers.save + @crm_customers = Customer.search(filter) + flash[:notice]='Customer was successfully created.' + else + flash[:error]=response["message"] + end + else + @crm_customers.each do |customer| + if customer.contact_no != response["customer_data"]["phone"] + @customer_update_phone_email =true + end + if customer.email != response["customer_data"]["email"] + @customer_update_phone_email =true + end + if customer.name != response["customer_data"]["name"] + @customer_update_phone_email =true + end + end end end end @@ -69,6 +89,7 @@ class Crm::CustomersController < BaseCrmController # if flash["errors"] # @crm_customer.valid? # end + # puts @crm_customers.to_json respond_to do |format| format.html # index.html.erb format.json { render json: @crm_customers } @@ -120,7 +141,91 @@ class Crm::CustomersController < BaseCrmController def edit @customer = Customer.find(params[:id]) end + def sync + @customer = Customer.find(params[:id]) + respond_to do |format| + name = @customer.name + phone = @customer.contact_no + email = @customer.email + dob = @customer.date_of_birth + address = @customer.address + nrc = @customer.nrc_no + card_no = @customer.card_no + paypar_account_no = @customer.paypar_account_no + id = @crm_customer.membership_id + member_group_id = @customer.membership_type + if !id.present? && !member_group_id.nil? + 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 + member_params = { name: name,phone: phone,email: email, + dob: dob,address: address,nrc:nrc,card_no:card_no, + member_group_id: member_group_id, + id:id, + merchant_uid:merchant_uid,auth_token:auth_token}.to_json + + # Check for paypar account exists + # if paypar_account_no != nil || paypar_account_no != '' + if paypar_account_no.present? + member_params = { name: name,phone: phone,email: email, + dob: dob,address: address,nrc:nrc,card_no:card_no, + paypar_account_no: paypar_account_no, + member_group_id: member_group_id, + id:id, + merchant_uid:merchant_uid,auth_token:auth_token}.to_json + end + + begin + response = HTTParty.post(url, + :body => member_params, + :headers => { + 'Content-Type' => 'application/json', + 'Accept' => 'application/json; version=3' + }, + :timeout => 10 + ) + rescue Net::OpenTimeout + response = { status: false } + + rescue OpenURI::HTTPError + response = { status: false} + + rescue SocketError + response = { status: false} + end + customer = Customer.find(@crm_customer.customer_id) + Rails.logger.debug "--------Sync Member response -------" + Rails.logger.debug response.to_json + if response["status"] == true + + status = customer.update_attributes(membership_id: response["customer_datas"]["id"],membership_type:member_group_id ) + + format.html { redirect_to crm_customers_path } + flash[:member_notice] ='Member was successfully synced' + else + # Check membership id and bind to user + if response["membership_id"] != nil + status = customer.update_attributes(membership_id: response["membership_id"],membership_type:member_group_id ) + format.html { redirect_to crm_customers_path } + flash[:member_notice] ='Member was successfully synced' + else + status = customer.update_attributes(membership_type:member_group_id) + end + # When paypar account no not exist in paypar + if response["message"] == "Account does not exist." + customer.destroy + format.html { redirect_to crm_customers_path } + flash[:member_error] ='Member cannot created.Invalid Account.' + end + format.html { redirect_to crm_customers_path } + flash[:member_error] =response["message"] + end + end + end + end # POST /crm/customers # POST /crm/customers.json def create @@ -196,9 +301,11 @@ class Crm::CustomersController < BaseCrmController status = customer.update_attributes(membership_id: response["customer_datas"]["id"],membership_type:member_group_id ) if params[:sale_id] - format.html { redirect_to '/origami/'+params[:sale_id]+'/'+params[:type]+'/customers/'+params[:page], notice: 'Customer was successfully created.' } + format.html { redirect_to '/origami/'+params[:sale_id]+'/'+params[:type]+'/customers/'+params[:page] } + flash[:member_notice]='Member was successfully created.' else - format.html { redirect_to crm_customers_path, notice: 'Customer was successfully created'} + format.html { redirect_to crm_customers_path } + flash[:member_notice]='Member was successfully created.' end # format.json { render :index, status: :created, location: @crm_customers } else @@ -207,24 +314,28 @@ class Crm::CustomersController < BaseCrmController # Check membership id and bind to user if response["membership_id"] != nil status = customer.update_attributes(membership_id: response["membership_id"],membership_type:member_group_id ) + format.html { redirect_to crm_customers_path } + flash[:member_notice]='Member was successfully created.' else status = customer.update_attributes(membership_type:member_group_id) end - # When paypar account no not exist in paypar - if response["message"] == "Account has not exist." + if response["message"] == "Account does not exist." customer.destroy if params[:sale_id] - format.html { redirect_to '/origami/'+params[:sale_id]+'/'+params[:type]+'/customers/'+params[:page], notice: 'Customer cannot created.' + response["message"]} + format.html { redirect_to '/origami/'+params[:sale_id]+'/'+params[:type]+'/customers/'+params[:page] } + flash[:member_error]='Member cannot created.Invalid Account.' else - format.html { redirect_to crm_customers_path, notice: 'Customer cannot created.' + response["message"] } + format.html { redirect_to crm_customers_path } + flash[:member_error]='Member cannot created.Invalid Account.' end end - if params[:sale_id] - format.html { redirect_to '/origami/'+params[:sale_id]+'/'+params[:type]+'/customers/'+params[:page], notice: 'Customer was successfully created.' + response["message"]} + format.html { redirect_to '/origami/'+params[:sale_id]+'/'+params[:type]+'/customers/'+params[:page] } + flash[:member_notice]='Member was successfully created.' + response["message"] else - format.html { redirect_to crm_customers_path, notice: 'Customer was successfully created.' } + format.html { redirect_to crm_customers_path } + # flash[:member_notice]='Member was successfully created.' end end else @@ -333,16 +444,19 @@ class Crm::CustomersController < BaseCrmController status = customer.update_attributes(membership_id: response["customer_datas"]["id"],membership_type:member_group_id ) - format.html { redirect_to crm_customers_path, notice: 'Customer was successfully updated'} + format.html { redirect_to crm_customers_path } + flash[:member_notice]='Member was successfully updated' else # Check membership id and bind to user if response["membership_id"] != nil status = customer.update_attributes(membership_id: response["membership_id"],membership_type:member_group_id ) + format.html { redirect_to crm_customers_path } + flash[:member_notice]='Member was successfully updated' else status = customer.update_attributes(membership_type:member_group_id) + format.html { redirect_to crm_customers_path } + flash[:member_error]=response["message"] end - - format.html { redirect_to crm_customers_path, notice: response["error"] } end else membership = MembershipSetting.find_by_membership_type("paypar_url") @@ -395,7 +509,8 @@ class Crm::CustomersController < BaseCrmController else status = customer.update_attributes(membership_type:member_group_id ) end - format.html { redirect_to crm_customers_path, notice: 'Customer was successfully updated.' } + format.html { redirect_to crm_customers_path } + flash[:member_notice] ='Member was successfully updated.' format.json { render :show, status: :ok, location: @crm_customer } else customer = Customer.find(@crm_customer.customer_id) @@ -405,7 +520,8 @@ class Crm::CustomersController < BaseCrmController else status = customer.update_attributes(membership_type:member_group_id ) end - format.html { redirect_to crm_customers_path, notice: response["message"] } + format.html { redirect_to crm_customers_path } + flash[:member_error] =response["message"] end end else @@ -438,6 +554,23 @@ class Crm::CustomersController < BaseCrmController end end + def customer_update_phone_email + @customer = Customer.find(params[:id]) + response = Customer.search_paypar_account_no(@customer.paypar_account_no) + if response["status"] == true + @customer.name =response["customer_data"]["name"] + @customer.contact_no =response["customer_data"]["phone"] + @customer.email =response["customer_data"]["email"] + @customer.save + respond_to do |format| + format.html { redirect_to crm_customers_path } + flash[:member_notice]='Membership was successfully updated' + end + end + + + end + private # Use callbacks to share common setup or constraints between actions. def set_crm_customer @@ -452,3 +585,4 @@ class Crm::CustomersController < BaseCrmController end end + diff --git a/app/controllers/settings/menu_item_attributes_controller.rb b/app/controllers/settings/menu_item_attributes_controller.rb index 8187d2a9..4ac48542 100755 --- a/app/controllers/settings/menu_item_attributes_controller.rb +++ b/app/controllers/settings/menu_item_attributes_controller.rb @@ -55,7 +55,26 @@ class Settings::MenuItemAttributesController < ApplicationController # DELETE /settings/menu_item_attributes/1 # DELETE /settings/menu_item_attributes/1.json def destroy - @settings_menu_item_attribute.destroy + item_attribute_id =@settings_menu_item_attribute.id + item_attribute_id_string=""+item_attribute_id.to_s+"" + if @settings_menu_item_attribute.destroy + menu_items =MenuItem.all + menu_items.each do |item| + if item.item_attributes.include?(item_attribute_id) + item_update =item.item_attributes.reject { |i| i == item_attribute_id } + item.item_code =item.item_code + item.item_attributes =item_update + item.save + end + if item.item_attributes.include?(item_attribute_id_string) + item_update =item.item_attributes.reject { |i| i == item_attribute_id_string } + item.item_code =item.item_code + item.item_attributes =item_update + item.save + end + end + end + # @settings_menu_item_attribute.destroy flash[:notice] = 'Menu item attribute was successfully destroyed.' render :json => {:status=> "Success", :url => settings_menu_item_attributes_path }.to_json # respond_to do |format| diff --git a/app/controllers/settings/menu_item_options_controller.rb b/app/controllers/settings/menu_item_options_controller.rb index 00791e5d..339039bf 100755 --- a/app/controllers/settings/menu_item_options_controller.rb +++ b/app/controllers/settings/menu_item_options_controller.rb @@ -55,7 +55,25 @@ class Settings::MenuItemOptionsController < ApplicationController # DELETE /settings/menu_item_options/1 # DELETE /settings/menu_item_options/1.json def destroy - @settings_menu_item_option.destroy + item_option_id =@settings_menu_item_option.id + item_option_id_string=""+item_option_id.to_s+"" + if @settings_menu_item_option.destroy + menu_items =MenuItem.all + menu_items.each do |item| + if item.item_options.include?(item_option_id) + item_update =item.item_options.reject { |i| i == item_option_id } + item.item_code =item.item_code + item.item_options =item_update + item.save + end + if item.item_options.include?(item_option_id_string) + item_update =item.item_options.reject { |i| i == item_option_id_string } + item.item_code =item.item_code + item.item_options =item_update + item.save + end + end + end flash[:notice] = 'Menu item option was successfully destroyed.' render :json => {:status=> "Success", :url => settings_menu_item_options_path }.to_json # respond_to do |format| diff --git a/app/controllers/settings/simple_menu_items_controller.rb b/app/controllers/settings/simple_menu_items_controller.rb index df70f61e..cd1c4507 100755 --- a/app/controllers/settings/simple_menu_items_controller.rb +++ b/app/controllers/settings/simple_menu_items_controller.rb @@ -109,7 +109,6 @@ class Settings::SimpleMenuItemsController < ApplicationController @settings_menu_item.item_sets = sets end end - @settings_menu_item.menu_category_id = params[:menu_category_id] respond_to do |format| diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 9d418f7b..f3c076ae 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -178,7 +178,8 @@ class SalePayment < ApplicationRecord def self.redeem(paypar_url,token,membership_id,received_amount,sale_id) # membership_actions_data = MembershipAction.find_by_membership_type("redeem"); membership_actions_data = PaymentMethodSetting.find_by_payment_method("Redeem") - + puts "This is membership_actions_data" + puts membership_actions_data.to_json if !membership_actions_data.nil? url = paypar_url.to_s + membership_actions_data.gateway_url.to_s diff --git a/app/views/crm/customers/index.html.erb b/app/views/crm/customers/index.html.erb index 76d1dce8..3948d86f 100644 --- a/app/views/crm/customers/index.html.erb +++ b/app/views/crm/customers/index.html.erb @@ -9,12 +9,27 @@ --> -
+
-
+ + <% end %> <% end %> <% end %> <%= yield %> diff --git a/config/routes.rb b/config/routes.rb index 89963f1e..f25ff1b8 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -358,6 +358,8 @@ scope "(:locale)", locale: /en|mm/ do namespace :crm do root "home#index" resources :customers + get "/customers/:id/sync" => "customers#sync", as:"customer_sync" + get "/customers/:id/customer_update_phone_email" => "customers#customer_update_phone_email", as:"customer_update_phone_email" resources :dining_queues post "update_booking", to: "bookings#update_booking", as: "update_booking" #assign and cancel get '/print/:id', to: "home#print_order" #print order for crm diff --git a/db/seeds.rb b/db/seeds.rb index 7a139b6e..9d498c2e 100755 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -209,7 +209,7 @@ queue_no_printer=PrintSetting.create({name: "Queue No", unique_code: "QueueNoPdf zone = Zone.create({id:1, name: "H1", is_active:true, created_by: "SYSTEM DEFAULT"}) -member_setting = MembershipSetting.create({membership_type:"paypar_url",gateway_url: "https://staging.membership.paypar.ws",merchant_account_id:"pZBHXEFbGNj/G"}) +member_setting = MembershipSetting.create({membership_type:"paypar_url",gateway_url: "https://staging.membership.paymal.ws",merchant_account_id:"vWSsseoZCzxd6xcNf_uS"}) member_actions= MembershipAction.create([{membership_type:"get_account_balance",is_active:1,gateway_url:"/api/membership_campaigns/get_correspond_account_data",additional_parameter:{campaign_type_id:1},merchant_account_id:"vWSsseoZCzxd6xcNf_uS",auth_token:"pZBHXEFbGNj/G"}, {membership_type:"redeem",is_active:1,gateway_url:"/api/membership_campaigns/redeem",additional_parameter:{campaign_type_id:1},merchant_account_id:"vWSsseoZCzxd6xcNf_uS",auth_token:"pZBHXEFbGNj/G"}, diff --git a/false, b/false, new file mode 100644 index 00000000..e69de29b diff --git a/member_params, b/member_params, new file mode 100644 index 00000000..e69de29b diff --git a/{ b/{ new file mode 100644 index 00000000..e69de29b