diff --git a/app/assets/javascripts/origami.js b/app/assets/javascripts/origami.js index 7acdb485..0886d04e 100644 --- a/app/assets/javascripts/origami.js +++ b/app/assets/javascripts/origami.js @@ -37,7 +37,7 @@ $(document).ready(function(){ control_button(order_status); var customer_id=$(this).find(".customer-id").text(); - //show_customer_details(customer_id); + show_customer_details(customer_id); $("#re-print").val(unique_id); diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 50278d71..d0a8ca9e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -14,6 +14,7 @@ class ApplicationController < ActionController::Base # redirect_to root_path # end + def current_user @current_user ||= Employee.find_by_token_session(session[:session_token]) if session[:session_token] end diff --git a/app/controllers/crm/customers_controller.rb b/app/controllers/crm/customers_controller.rb index ce585686..dc800cea 100644 --- a/app/controllers/crm/customers_controller.rb +++ b/app/controllers/crm/customers_controller.rb @@ -63,60 +63,61 @@ class Crm::CustomersController < BaseCrmController def edit end - # POST /crm/customers + # POST /crm/customers # POST /crm/customers.json def create @crm_customers = Customer.new(customer_params) respond_to do |format| - puts @crm_customers.errors.to_json if @crm_customers.save - name = customer_params[:name] - phone = customer_params[:contact_no] - email = customer_params[:email] - dob = customer_params[:date_of_birth] - address = customer_params[:address] - nrc = customer_params[:nrc_no] - member_group_id = params[:member_group_id] - - 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 - - begin - response = HTTParty.post(url, :body => { name: name,phone: phone,email: email, - dob: dob,address: address,nrc:nrc, - member_group_id: member_group_id,merchant_uid:merchant_uid,auth_token:auth_token}.to_json, - :headers => { - 'Content-Type' => 'application/json', - 'Accept' => 'application/json' - } - ) - rescue Net::OpenTimeout - response = { status: false } - end - - if response["status"] == true + name = customer_params[:name] + phone = customer_params[:contact_no] + email = customer_params[:email] + dob = customer_params[:date_of_birth] + address = customer_params[:address] + nrc = customer_params[:nrc_no] + member_group_id = params[:member_group_id] - customer = Customer.find(@crm_customers.customer_id) - status = customer.update_attributes(membership_id: response["customer_datas"]["id"]) - - if params[:sale_id] - 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 - # format.json { render :index, status: :created, location: @crm_customers } - else - - # @crm_customers.destroy - if params[:sale_id] - format.html { redirect_to '/origami/'+params[:sale_id]+'/customers'} + if !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 + + begin + response = HTTParty.post(url, :body => { name: name,phone: phone,email: email, + dob: dob,address: address,nrc:nrc, + member_group_id: member_group_id, + merchant_uid:merchant_uid,auth_token:auth_token}.to_json, + :headers => { + 'Content-Type' => 'application/json', + 'Accept' => 'application/json' + } + ) + rescue Net::OpenTimeout + response = { status: false } + end + + if response["status"] == true + + customer = Customer.find(@crm_customers.customer_id) + 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]+'/customers', notice: 'Customer was successfully created.' } + else + format.html { redirect_to crm_customers_path, notice: 'Customer was successfully created'} + end + # format.json { render :index, status: :created, location: @crm_customers } else - format.html { redirect_to crm_customers_path, notice: response["message"] } + # @crm_customers.destroy + if params[:sale_id] + format.html { redirect_to '/origami/'+params[:sale_id]+'/customers'} + else + format.html { redirect_to crm_customers_path, notice: response["message"] } + end end end else @@ -134,7 +135,6 @@ class Crm::CustomersController < BaseCrmController end end - # PATCH/PUT /crm/customers/1 # PATCH/PUT /crm/customers/1.json def update @@ -151,25 +151,64 @@ end id = @crm_customer.membership_id member_group_id = params[:member_group_id] - 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 - begin - response = HTTParty.post(url, :body => { name: name,phone: phone,email: email, - dob: dob,address: address,nrc:nrc, - 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' - } - ) - rescue Net::OpenTimeout - response = { status: false } - end - format.html { redirect_to crm_customers_path, notice: 'Customer was successfully updated.' } - format.json { render :show, status: :ok, location: @crm_customer } + if id.nil? && !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 + + begin + response = HTTParty.post(url, :body => { name: name,phone: phone,email: email, + dob: dob,address: address,nrc:nrc, + member_group_id: member_group_id, + merchant_uid:merchant_uid,auth_token:auth_token}.to_json, + :headers => { + 'Content-Type' => 'application/json', + 'Accept' => 'application/json' + } + ) + rescue Net::OpenTimeout + response = { status: false } + end + + if response["status"] == true + + customer = Customer.find(@crm_customer.customer_id) + 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'} + else + format.html { redirect_to crm_customers_path, notice: response["message"] } + end + + else + 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 + begin + response = HTTParty.post(url, :body => { name: name,phone: phone,email: email, + dob: dob,address: address,nrc:nrc, + 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' + } + ) + rescue Net::OpenTimeout + response = { status: false } + end + + if response["status"] == true + format.html { redirect_to crm_customers_path, notice: 'Customer was successfully updated.' } + format.json { render :show, status: :ok, location: @crm_customer } + else + format.html { redirect_to crm_customers_path, notice: response["message"] } + end + + end else diff --git a/app/controllers/crm/dining_queues_controller.rb b/app/controllers/crm/dining_queues_controller.rb index 734793b3..dbcc4046 100644 --- a/app/controllers/crm/dining_queues_controller.rb +++ b/app/controllers/crm/dining_queues_controller.rb @@ -104,6 +104,6 @@ class Crm::DiningQueuesController < BaseCrmController # Never trust parameters from the scary internet, only allow the white list through. def dining_queue_params - params.require(:dining_queue).permit(:name, :contact_no, :queue_no,:status) + params.require(:dining_queue).permit(:name, :contact_no, :queue_no,:status,:seater,:remark) end end diff --git a/app/controllers/crm/home_controller.rb b/app/controllers/crm/home_controller.rb index c05e7cf3..6866ddf1 100644 --- a/app/controllers/crm/home_controller.rb +++ b/app/controllers/crm/home_controller.rb @@ -1,12 +1,12 @@ class Crm::HomeController < BaseCrmController def index - @booking = Booking.all - @customer = Customer.all - from = Time.now.beginning_of_day.utc - to = Time.now.end_of_day.utc - @queue = DiningQueue.where('created_at BETWEEN ? AND ?', from, to).order('queue_no ASC') - + # @booking = Booking.all + # @customer = Customer.all + # from = Time.now.beginning_of_day.utc + # to = Time.now.end_of_day.utc + # @queue = DiningQueue.where('created_at BETWEEN ? AND ?', from, to).order('queue_no ASC') + redirect_to crm_customers_path # .where("dining_facilities.is_active=? and orders.date between ? and ?",true,from,to) end diff --git a/app/controllers/origami/customers_controller.rb b/app/controllers/origami/customers_controller.rb index 373dc2f5..f15b8545 100644 --- a/app/controllers/origami/customers_controller.rb +++ b/app/controllers/origami/customers_controller.rb @@ -12,8 +12,17 @@ class Origami::CustomersController < BaseOrigamiController def add_customer - @sale_id = params[:sale_id] - filter = params[:filter] + @sale_id = params[:sale_id] + if(@sale_id[0,3] == "SAL") + @booking = Booking.find_by_sale_id(@sale_id) + @dining_facility = DiningFacility.find(@booking.dining_facility_id) + else + @booking_order = BookingOrder.find_by_order_id(@sale_id) + @booking = Booking.find(@booking_order.booking_id) + @dining_facility = DiningFacility.find(@booking.dining_facility_id) + end + + filter = params[:filter] filter = params[:filter] diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb index 4c35a918..60658f7d 100644 --- a/app/controllers/origami/home_controller.rb +++ b/app/controllers/origami/home_controller.rb @@ -24,6 +24,7 @@ class Origami::HomeController < BaseOrigamiController order = Order.find(booking_order.order_id) @obj_order = order + @customer = order.customer @date = order.created_at order.order_items.each do |item| @order_items.push(item) @@ -40,6 +41,7 @@ class Origami::HomeController < BaseOrigamiController @date = sale.created_at @status_sale = 'sale' @obj_sale = sale + @customer = sale.customer end end end diff --git a/app/controllers/origami/rooms_controller.rb b/app/controllers/origami/rooms_controller.rb index 56030d4f..4ef6375d 100644 --- a/app/controllers/origami/rooms_controller.rb +++ b/app/controllers/origami/rooms_controller.rb @@ -9,9 +9,11 @@ class Origami::RoomsController < BaseOrigamiController @room.bookings.each do |booking| if booking.sale_id.nil? @order_items = Array.new + booking.booking_orders.each do |booking_order| order = Order.find(booking_order.order_id) @obj = order + @customer = order.customer order.order_items.each do |item| @order_items.push(item) end @@ -23,6 +25,7 @@ class Origami::RoomsController < BaseOrigamiController if sale.sale_status != "completed" @status = 'sale' @obj = sale + @customer = sale.customer end end end diff --git a/app/controllers/transactions/sales_controller.rb b/app/controllers/transactions/sales_controller.rb index 0a069b1b..54432c38 100644 --- a/app/controllers/transactions/sales_controller.rb +++ b/app/controllers/transactions/sales_controller.rb @@ -53,7 +53,7 @@ class Transactions::SalesController < ApplicationController #get customer amount @customer = Customer.find(@sale.customer_id) - @response = Customer.get_membership_transactions(@customer) + @response = Customer.get_membership_transactions(@customer) #end customer amount respond_to do |format| diff --git a/app/views/crm/customers/_new_form.html.erb b/app/views/crm/customers/_new_form.html.erb index 968d2ca9..eb121c14 100644 --- a/app/views/crm/customers/_new_form.html.erb +++ b/app/views/crm/customers/_new_form.html.erb @@ -104,6 +104,7 @@
<%= queue.status %>
<%= @i += 1 %> . Queue No + Seater : <%= queue.seater %><%= queue.queue_no %>
diff --git a/app/views/origami/customers/index.html.erb b/app/views/origami/customers/index.html.erb index e862ea7f..0cd7d85b 100644 --- a/app/views/origami/customers/index.html.erb +++ b/app/views/origami/customers/index.html.erb @@ -73,6 +73,8 @@ + + <%= f.error_notification %> <%= f.hidden_field :id, :class => "form-control col-md-6 " %>Date: <%= @date.utc.strftime("%d/%m/%Y - %I:%M %p") rescue '-'%>
-