diff --git a/app/assets/javascripts/origami.js b/app/assets/javascripts/origami.js index fe209451..34a25dc1 100644 --- a/app/assets/javascripts/origami.js +++ b/app/assets/javascripts/origami.js @@ -27,11 +27,8 @@ $(document).ready(function(){ control_button(order_status); //for customer button - if(unique_id.charAt(0) == 'S'){ $("#customer").removeAttr('disabled'); - }else{ - $("#customer").attr('disabled','disabled'); - } + var customer_id=$(this).find(".customer-id").text(); show_customer_details(customer_id); @@ -161,13 +158,20 @@ $(document).ready(function(){ }); $('#customer').click(function() { - var sale_id=$(".selected-item").find(".orders-id").text(); + var sale = $(".selected-item").find(".orders-id").text(); + if (sale.substring(0, 3)=="SAL") { + var sale_id = sale + }else{ + var sale_id = $(".selected-item").find(".order-cid").text(); + } + alert(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({ @@ -176,8 +180,20 @@ $(document).ready(function(){ data: {}, dataType: "json", success: function(data) { - $("#customer_name").text(data.name); - $("#customer_name").text(data.name); + $("#customer_name").text(data["customer"].name); + $.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); + if (balance) { + $("#customer_amount").text(balance); + }else{ + $("#customer_amount").text('00'); + } + + + } + }); } }); //End Ajax diff --git a/app/controllers/crm/customers_controller.rb b/app/controllers/crm/customers_controller.rb index 9f73edcf..30c09f06 100644 --- a/app/controllers/crm/customers_controller.rb +++ b/app/controllers/crm/customers_controller.rb @@ -14,9 +14,9 @@ class Crm::CustomersController < BaseCrmController end #@crm_customers = Customer.all @crm_customer = Customer.new - @crm_customer.valid? - - + if @crm_customer.valid? + @crm_customer.errors.messages + end # @membership = Customer.get_member_group # if @membership["status"] == true # @member_group = @membership["data"] @@ -54,17 +54,17 @@ class Crm::CustomersController < BaseCrmController # POST /crm/customers # POST /crm/customers.json - def create + def create @crm_customers = Customer.new(customer_params) - + respond_to do |format| if @crm_customers.save name = customer_params[:name] phone = customer_params[:contact_no] email = customer_params[:email] date_of_birth = customer_params[:date_of_birth] - membership_id = params[:membership_id] + member_group_id = params[:member_group_id] membership = MembershipSetting.find_by_membership_type("paypar_url") memberaction = MembershipAction.find_by_membership_type("create_membership_customer") @@ -73,7 +73,7 @@ class Crm::CustomersController < BaseCrmController response = HTTParty.post(url, :body => { name: name,phone: phone,email: email, date_of_birth: date_of_birth, - membership_id: membership_id}.to_json, + member_group_id: member_group_id}.to_json, :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json' @@ -85,37 +85,34 @@ class Crm::CustomersController < BaseCrmController customer = Customer.find(@crm_customers.customer_id) status = customer.update_attributes(membership_id: response["customer_datas"]["id"]) - if params[:sale_id].nil? - - format.html { redirect_to '/origami/'+params[:sale_id]+'/add_customer', notice: 'Customer was successfully created.' } - + if params[:sale_id] + format.html { redirect_to '/origami/'+params[:sale_id]+'/add_customer', 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].nil? + if params[:sale_id] format.html { redirect_to '/origami/'+params[:sale_id]+'/add_customer'} else 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].nil? - + + if params[:sale_id] 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 end @@ -131,6 +128,7 @@ end email = customer_params[:email] date_of_birth = customer_params[:date_of_birth] id = customer_params[: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") @@ -139,7 +137,7 @@ end response = HTTParty.post(url, :body => { name: name,phone: phone,email: email, date_of_birth: date_of_birth, - id: id}.to_json, + id: id,member_group_id:member_group_id}.to_json, :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json' diff --git a/app/controllers/origami/customers_controller.rb b/app/controllers/origami/customers_controller.rb index 7917b03f..74148296 100644 --- a/app/controllers/origami/customers_controller.rb +++ b/app/controllers/origami/customers_controller.rb @@ -23,10 +23,10 @@ class Origami::CustomersController < BaseOrigamiController @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 + # @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"} diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb index 1b16ab54..e5e2128f 100644 --- a/app/controllers/origami/home_controller.rb +++ b/app/controllers/origami/home_controller.rb @@ -29,15 +29,21 @@ class Origami::HomeController < BaseOrigamiController def update_sale_by_customer - sale = Sale.find(params[:sale_id]) - status = sale.update_attributes(customer_id: params[:customer_id]) - - if status == true + id = params[:sale_id][0,3] + if(id == "SAL") + sale = Sale.find(params[:sale_id]) + else + sale = Order.find(params[:sale_id]) + end + + status = sale.update_attributes(customer_id: params[:customer_id]) + + if status == true render json: JSON.generate({:status => true}) - else + else render json: JSON.generate({:status => false, :error_message => "Record not found"}) - end + end end def get_customer @@ -50,15 +56,20 @@ class Origami::HomeController < BaseOrigamiController app_token = membership.auth_token.to_s url = membership.gateway_url.to_s + memberaction.gateway_url.to_s - response = HTTParty.post(url, :body => { membership_id: @customer.membership_id}.to_json, + response = HTTParty.get(url, :body => { membership_id: @customer.membership_id}.to_json, :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json' } ) - - - render :json => response.to_json + respond_to do |format| + format.js do + render :json => { + :response_data => response.as_json, + :customer => @customer} + end + end end + end diff --git a/app/models/customer.rb b/app/models/customer.rb index 4f013678..b5e101cb 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -14,9 +14,9 @@ class Customer < ApplicationRecord def self.get_member_group - membership = MembershipSetting.find_by_membership_type("paypar_url") + membership = MembershipSetting.find_by_membership_type("paypar_url") memberaction = MembershipAction.find_by_membership_type("get_all_member_group") - app_token = membership.auth_token.to_s + app_token = membership.auth_token.to_s url = membership.gateway_url.to_s + memberaction.gateway_url.to_s response = HTTParty.get(url, diff --git a/app/models/dining_queue.rb b/app/models/dining_queue.rb index dfcc5b43..ea6a1381 100644 --- a/app/models/dining_queue.rb +++ b/app/models/dining_queue.rb @@ -1,3 +1,2 @@ class DiningQueue < ApplicationRecord - end diff --git a/app/models/lookup.rb b/app/models/lookup.rb index e1b141df..5434cedd 100644 --- a/app/models/lookup.rb +++ b/app/models/lookup.rb @@ -17,6 +17,10 @@ class Lookup < ApplicationRecord "Gateway Communication Type" => "gateway_communication_type"} end + # def self.get_by_type( lookup_type) + # Lookup.select("value, name").where("lookup_type = ?", lookup_type ).order("name asc").map { |r| [r.name, r.value] } + # end + def self.collection_of(type) Lookup.select("name, value").where("lookup_type" => type ).map { |l| [l.name, l.value] } diff --git a/app/models/order.rb b/app/models/order.rb index f4a4eff9..0b57f9dc 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -222,7 +222,8 @@ class Order < ApplicationRecord #Origami: Cashier : to view booking order Table def self.get_booking_order_table - booking_orders = Booking.select("sales.receipt_no,orders.status as order_status,orders.customer_id as customer_id, + booking_orders = Booking.select("sales.receipt_no,orders.status as order_status, + orders.order_id as order_id,sales.customer_id as sale_customer_id,orders.customer_id as order_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") @@ -235,7 +236,9 @@ 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,orders.customer_id as customer_id, + booking_rooms = Booking.select("sales.receipt_no,orders.status as order_status, + orders.order_id as order_id,sales.customer_id as sale_customer_id,orders.customer_id as order_customer_id, + 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") @@ -264,7 +267,8 @@ 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, - orders.customer_id as customer_id,bookings.booking_id,sales.sale_id as sale_id,dining_facilities.name as table_name") + orders.order_id as order_id,sales.customer_id as sale_customer_id,orders.customer_id as order_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 c3fb4064..9f62b55b 100644 --- a/app/views/crm/customers/index.html.erb +++ b/app/views/crm/customers/index.html.erb @@ -71,7 +71,6 @@ <%= 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 " %> @@ -94,17 +93,20 @@
<%= unique_id %>
-<%= bko.customer_id %>
+<%= customer_id %>
+<%= bko.order_id %>
@@ -72,15 +76,18 @@ sale_status="" if rmo.order_status == 'new' unique_id=rmo.booking_id + customer_id=rmo.order_customer_id else unique_id=rmo.sale_id + customer_id=rmo.sale_customer_id sale_status="sold" end %>
<%= unique_id %>
-<%= rmo.customer_id %>
+<%= customer_id %>
+<%= rmo.order_id %>
Receipt No : @@ -114,15 +121,18 @@ sale_status="" if odr.order_status == 'new' unique_id=odr.booking_id + customer_id = odr.order_customer_id else unique_id=odr.sale_id + customer_id = odr.sale_customer_id sale_status="sold" end %>
<%= unique_id %>
-<%= odr.customer_id %>
+<%= customer_id %>
+<%= odr.order_id %>
Receipt No : diff --git a/db/migrate/20170608105644_create_crm_dining_queues.rb b/db/migrate/20170612031153_create_dining_queues.rb similarity index 59% rename from db/migrate/20170608105644_create_crm_dining_queues.rb rename to db/migrate/20170612031153_create_dining_queues.rb index 3929719e..3cf26418 100644 --- a/db/migrate/20170608105644_create_crm_dining_queues.rb +++ b/db/migrate/20170612031153_create_dining_queues.rb @@ -1,6 +1,6 @@ -class CreateCrmDiningQueues < ActiveRecord::Migration[5.1] +class CreateDiningQueues < ActiveRecord::Migration[5.1] def change - create_table :crm_dining_queues do |t| + create_table :dining_queues do |t| t.string :name t.string :contact_no t.string :queue_no diff --git a/spec/models/dining_queue_spec.rb b/spec/models/dining_queue_spec.rb new file mode 100644 index 00000000..185068c3 --- /dev/null +++ b/spec/models/dining_queue_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe DiningQueue, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end