diff --git a/app/assets/javascripts/origami.js b/app/assets/javascripts/origami.js index 5626634f..14f9fbe9 100644 --- a/app/assets/javascripts/origami.js +++ b/app/assets/javascripts/origami.js @@ -43,6 +43,10 @@ $(document).ready(function(){ $("#customer").attr('disabled','disabled'); } + var customer_id=$(this).find(".customer-id").text(); + show_customer_details(customer_id); + + var cashier=""; var receipt_date=""; var sub_total=0; @@ -165,6 +169,7 @@ $(document).ready(function(){ }); }); + // Payment for Bill $('#pay-bill').click(function() { var sale_id=$(".selected-item").find(".orders-id").text(); @@ -180,10 +185,27 @@ $(document).ready(function(){ $('#customer').click(function() { var sale_id=$(".selected-item").find(".orders-id").text(); - window.location.href = '/crm/customers/'+ sale_id + "/assign_sale_id" + window.location.href = '/origami/'+ sale_id + "/add_customer" + return false; }); + function show_customer_details(customer_id){ + $('.customer_detail').removeClass('hide'); + //Start Ajax + $.ajax({ + type: "GET", + url: "origami/"+customer_id+"/get_customer/", + data: {}, + dataType: "json", + success: function(data) { + $("#customer_name").text(data.name); + $("#customer_name").text(data.name); + } + }); + //End Ajax +} + /* For Receipt - Calculate discount or tax */ $('.cashier_number').on('click', function(event){ if(event.handled !== true) { diff --git a/app/controllers/crm/customers_controller.rb b/app/controllers/crm/customers_controller.rb index 5eef1914..f6159cb7 100644 --- a/app/controllers/crm/customers_controller.rb +++ b/app/controllers/crm/customers_controller.rb @@ -4,21 +4,23 @@ class Crm::CustomersController < BaseCrmController # GET /crm/customers # GET /crm/customers.json def index - @sale_id = 0 filter = params[:filter] if filter.nil? - @crm_customers = Customer.order("name").page(params[:page]) + @crm_customers = Customer.order("customer_id").page(params[:page]) #@products = Product.order("name").page(params[:page]).per(5) else @crm_customers = Customer.where("name LIKE ?", "%#{filter}%").order("name").page(params[:page]) end #@crm_customers = Customer.all - @crm_customer = Customer.new - @membership = Customer.get_member_group - if @membership["status"] == true - @member_group = @membership["data"] - end + @crm_customer = Customer.new + @crm_customer.valid? + + + # @membership = Customer.get_member_group + # if @membership["status"] == true + # @member_group = @membership["data"] + # end respond_to do |format| format.html # index.html.erb format.json { render json: @crm_customers } @@ -49,8 +51,6 @@ class Crm::CustomersController < BaseCrmController respond_to do |format| if @crm_customers.save - - name = customer_params[:name] phone = customer_params[:contact_no] email = customer_params[:email] @@ -71,40 +71,37 @@ class Crm::CustomersController < BaseCrmController } ) - if response["status"] == true + if response["status"] == true customer = Customer.find(@crm_customers.customer_id) status = customer.update_attributes(membership_id: response["customer_datas"]["id"]) - if params[:sale_id] != 0 - format.html { redirect_to crm_customers_path, notice: 'Customer was successfully created.' } + + if params[:sale_id].nil? + + format.html { redirect_to '/origami/'+params[:sale_id]+'/add_customer', notice: 'Customer was successfully created.' } else - format.html { redirect_to '/crm/customers/'+params[:sale_id]+'/assign_sale_id', notice: 'Customer was successfully created.' } + 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] != 0 - format.html { redirect_to crm_customers_path, notice: response["message"] } - + if params[:sale_id].nil? + format.html { redirect_to '/origami/'+params[:sale_id]+'/add_customer'} else - format.html { redirect_to '/crm/customers/'+params[:sale_id]+'/assign_sale_id', notice: response["message"] } + format.html { redirect_to crm_customers_path, notice: response["message"] } end - end - - # format.json { render :index, status: :created, location: @crm_customers } - else - if params[:sale_id] != 0 - format.html { redirect_to crm_customers_path} - format.json { render json: @crm_customers.errors, status: :unprocessable_entity } - - else - format.html { redirect_to '/crm/customers/'+params[:sale_id]+'/assign_sale_id', notice: response["message"] } - end - + + if params[:sale_id].nil? + + format.html { redirect_to '/origami/'+params[:sale_id]+'/add_customer'} + else + + format.html { redirect_to crm_customers_path} + format.json { render json: @crm_customers.errors, status: :unprocessable_entity } + end end end end @@ -161,7 +158,6 @@ class Crm::CustomersController < BaseCrmController # DELETE /crm/customers/1 # DELETE /crm/customers/1.json def get_sale_id - @sale_id = params[:sale_id] @crm_customers = Customer.all @crm_customer = Customer.new @@ -184,6 +180,6 @@ class Crm::CustomersController < BaseCrmController # Never trust parameters from the scary internet, only allow the white list through. def customer_params - params.require(:customer).permit(:name, :company, :contact_no, :email, :date_of_birth, :membership_type, :membership_authentication_code) + params.require(:customer).permit(:name, :company, :contact_no, :email, :date_of_birth) end end diff --git a/app/controllers/origami/customers_controller.rb b/app/controllers/origami/customers_controller.rb index d9bfc39b..7917b03f 100644 --- a/app/controllers/origami/customers_controller.rb +++ b/app/controllers/origami/customers_controller.rb @@ -1,7 +1,38 @@ class Origami::CustomersController < BaseOrigamiController #Form to add customer - def index + + end - def create + + # GET /crm/customers/1 + # GET /crm/customers/1.json + def show end + + + + def add_customer + + @sale_id = params[:sale_id] + filter = params[:filter] + + if filter.nil? + @crm_customers = Customer.order("name").page(params[:page]) + else + @crm_customers = Customer.where("name LIKE ?", "%#{filter}%").order("name").page(params[:page]) + end + @crm_customer = Customer.new + @membership = Customer.get_member_group + if @membership["status"] == true + @member_group = @membership["data"] + end + respond_to do |format| + # format.html { render :template => "crm/customers/index" } + format.html { render action: "index"} + format.json { render json: @crm_customers } + end + end + + end diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb index 83c6bd81..4c97c80e 100644 --- a/app/controllers/origami/home_controller.rb +++ b/app/controllers/origami/home_controller.rb @@ -17,7 +17,12 @@ class Origami::HomeController < BaseOrigamiController @booking_orders = Order.get_booking_order_table() @booking_rooms = Order.get_booking_order_rooms() @orders = Order.get_orders() +<<<<<<< HEAD end +======= + + end +>>>>>>> d65882ac5bcdce934116e65b66a8a3cb34965ba3 def item_show selection(params[:booking_id],1) @@ -45,4 +50,23 @@ class Origami::HomeController < BaseOrigamiController str end end + + def update_sale_by_customer + + sale = Sale.find(params[:sale_id]) + status = sale.update_attributes(customer_id: params[:customer_id]) + + if status == true + render json: JSON.generate({:status => true}) + else + render json: JSON.generate({:status => false, :error_message => "Record not found"}) + + end + end + + def get_customer + @customer = Customer.find(params[:customer_id]) + + render :json => @customer.to_json + end end diff --git a/app/models/order.rb b/app/models/order.rb index f882e0a0..5e123060 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -221,8 +221,8 @@ class Order < ApplicationRecord end #Origami: Cashier : to view booking order Table - def self.get_selected_order(id) - booking_orders = Booking.select("sales.receipt_no,orders.status as order_status, + def self.get_booking_order_table + booking_orders = Booking.select("sales.receipt_no,orders.status as order_status,orders.customer_id as customer_id, bookings.booking_id,sales.sale_id as sale_id,dining_facilities.name as table_name") .joins("left join booking_orders on booking_orders.booking_id = bookings.booking_id") .joins("left join dining_facilities on dining_facilities.id = bookings.dining_facility_id") @@ -261,7 +261,7 @@ class Order < ApplicationRecord #Origami: Cashier : to view order type Room def self.get_booking_order_rooms - booking_rooms = Booking.select("sales.receipt_no,orders.status as order_status,bookings.booking_id, + booking_rooms = Booking.select("sales.receipt_no,orders.status as order_status,bookings.booking_id,orders.customer_id as customer_id, sales.sale_id as sale_id,dining_facilities.name as room_name") .joins("left join booking_orders on booking_orders.booking_id = bookings.booking_id") .joins("left join dining_facilities on dining_facilities.id = bookings.dining_facility_id") @@ -290,7 +290,7 @@ class Order < ApplicationRecord from = Time.now.beginning_of_day.utc to = Time.now.end_of_day.utc orders = Order.select("orders.order_id as order_id,sales.receipt_no,orders.status as order_status, - bookings.booking_id,sales.sale_id as sale_id,dining_facilities.name as table_name") + orders.customer_id as customer_id,bookings.booking_id,sales.sale_id as sale_id,dining_facilities.name as table_name") .joins("left join booking_orders on booking_orders.order_id = orders.order_id left join bookings on bookings.booking_id = booking_orders.order_id left join dining_facilities on dining_facilities.id = bookings.dining_facility_id diff --git a/app/views/crm/customers/index.html.erb b/app/views/crm/customers/index.html.erb index 184bce41..e4f6d07d 100644 --- a/app/views/crm/customers/index.html.erb +++ b/app/views/crm/customers/index.html.erb @@ -69,8 +69,10 @@
<%= simple_form_for @crm_customer,:url => crm_customers_path, :method => :post do |f| %> + + <%= f.error_notification %> <%= f.hidden_field :id, :class => "form-control col-md-6 " %>
@@ -95,24 +97,14 @@ <%= f.text_field :date_of_birth,:class=>"form-control date_of_birth datepicker"%>
-
- -
- -
+
<%= f.button :submit, "Submit",:class => 'btn btn-primary ', :id => 'submit_customer' %> <%= f.button :submit, "Update",:class => 'btn btn-primary ', :disabled =>'', :id => 'update_customer' %> @@ -140,11 +132,11 @@ $(document).on('click',".checkbox_check",function(){ if(this.checked){ - var sale_id = $("#sale_id").val() || 0; + var sale_id = $("#sale_id").val() || 0; var customer_id = $(this).val(); if(sale_id != 0){ - var url = "../"+customer_id; + // var url = "/"+customer_id; update_sale(customer_id,sale_id); }else{ @@ -201,7 +193,7 @@ action: function(){ $.ajax({ type: "POST", - url: "../../update_sale/" , + url: "update_sale/" , data: {customer_id:customer_id,sale_id:sale_id}, dataType: "json", success: function(data) { diff --git a/app/views/crm/home/_booking.html.erb b/app/views/crm/home/_booking.html.erb index 5d865002..fbe837a7 100644 --- a/app/views/crm/home/_booking.html.erb +++ b/app/views/crm/home/_booking.html.erb @@ -76,8 +76,9 @@ $(function(){ //End Print Click $('.assign').click(function(e){ - var booking_id = $(this).val() - var type = $(this).attr("data-type") + var booking_id = $(this).val(); + var type = $(this).attr("data-type"); + alert(booking_id); update_booking(booking_id,type) }); @@ -190,7 +191,7 @@ function update_booking(booking_id,type) { //Start Ajax $.ajax({ type: "POST", - url: "update_booking/" , + url: "crm/update_booking/" , data: {booking_id:booking_id,type:type}, dataType: "json", success: function(data) { diff --git a/app/views/crm/home/index.html.erb b/app/views/crm/home/index.html.erb index 87e601d9..c1938bc4 100644 --- a/app/views/crm/home/index.html.erb +++ b/app/views/crm/home/index.html.erb @@ -3,7 +3,7 @@ -