diff --git a/Gemfile b/Gemfile index 6b3740a7..ccffbe23 100644 --- a/Gemfile +++ b/Gemfile @@ -13,7 +13,6 @@ gem 'rails', '~> 5.1.0' gem 'mysql2', '>= 0.3.18', '< 0.5' #Use PosgreSQL - gem 'pg' # redis server for cable # gem 'redis', '~> 3.0' @@ -92,4 +91,6 @@ end # Windows does not include zoneinfo files, so bundle the tzinfo-data gem gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] -gem 'httparty', '~> 0.15.5' \ No newline at end of file +gem 'httparty', '~> 0.15.5' + +gem 'bootstrap-datepicker-rails' \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index 17b395eb..533cd08b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -64,6 +64,8 @@ GEM bootstrap (4.0.0.alpha6) autoprefixer-rails (>= 6.0.3) sass (>= 3.4.19) + bootstrap-datepicker-rails (1.6.4.1) + railties (>= 3.0) builder (3.2.3) byebug (9.0.6) coffee-rails (4.2.2) @@ -244,6 +246,7 @@ PLATFORMS DEPENDENCIES bcrypt (~> 3.1.7) bootstrap (~> 4.0.0.alpha3) + bootstrap-datepicker-rails byebug coffee-rails (~> 4.2) cups (~> 0.0.7) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index f7b2e2b0..f2ee34ba 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -17,3 +17,4 @@ //= require turbolinks //= require cable //= require settings/processing_items +//= require bootstrap-datepicker diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 9456be10..d8101494 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -2,6 +2,7 @@ @import "bootstrap"; @import "font-awesome"; @import "theme"; +@import "bootstrap-datepicker3"; /* Show it is fixed to the top */ // body { diff --git a/app/controllers/crm/customers_controller.rb b/app/controllers/crm/customers_controller.rb index 896d9d14..c25f6e80 100644 --- a/app/controllers/crm/customers_controller.rb +++ b/app/controllers/crm/customers_controller.rb @@ -5,6 +5,13 @@ class Crm::CustomersController < ApplicationController # GET /crm/customers.json def index @crm_customers = Customer.all + @customers = Customer.new + @membership = Customer.get_member_group + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @crm_customers } + end end # GET /crm/customers/1 @@ -15,7 +22,8 @@ class Crm::CustomersController < ApplicationController # GET /crm/customers/new def new @crm_customer = Customer.new - @membership = Customer.get_member_group + @membership = Customer.get_member_group() + end # GET /crm/customers/1/edit @@ -25,7 +33,7 @@ class Crm::CustomersController < ApplicationController # POST /crm/customers # POST /crm/customers.json def create - @crm_customer = Customer.new(crm_customer_params) + @crm_customer = Customer.new(customer_params) respond_to do |format| if @crm_customer.save @@ -42,7 +50,7 @@ class Crm::CustomersController < ApplicationController # PATCH/PUT /crm/customers/1.json def update respond_to do |format| - if @crm_customer.update(crm_customer_params) + if @crm_customer.update(customer_params) format.html { redirect_to @crm_customer, notice: 'Customer was successfully updated.' } format.json { render :show, status: :ok, location: @crm_customer } else @@ -69,7 +77,7 @@ class Crm::CustomersController < ApplicationController end # Never trust parameters from the scary internet, only allow the white list through. - def crm_customer_params - params.require(:crm_customer).permit(:name, :company, :contact_no, :email, :date_of_birth, :membership_id, :membership_type, :membership_authentication_code) + def customer_params + params.require(:customer).permit(:name, :company, :contact_no, :email, :date_of_birth, :membership_id, :membership_type, :membership_authentication_code) end end diff --git a/app/models/customer.rb b/app/models/customer.rb index 4bdc290a..95901cce 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -1,12 +1,29 @@ class Customer < ApplicationRecord - self.primary_key = "customer_id" + + #self.primary_key = :customer_id before_create :generate_custom_id has_many :orders has_many :sales - validates_presence_of :name, :contact_no + validates_presence_of :name, :contact_no, :email validates :contact_no, uniqueness: true + validates :email, uniqueness: true + + def self.get_member_group + + gateway_url = MembershipSetting.find_by_membership_type("smartpay_url") + url = gateway_url.gateway_url.to_s + "/api/get_all_member_group".to_s + response = HTTParty.get(url) + puts response.body, response.code, response.message, response.headers.inspect + + return response; + + end + +# http://192.168.1.47:3006/api/create_membership_customer +#get_all_member_group + def lastest_invoices sales.where(:customer_id => self.id).order("created_at desc").limit(5) diff --git a/app/models/order.rb b/app/models/order.rb index 036f9006..9807758c 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -211,16 +211,17 @@ class Order < ApplicationRecord #Origami: Cashier : to view order type Table def self.get_order_table - order_table = Order.select("orders.id as order_id,sum(order_items.qty*order_items.price) as total_price, - order_items.id as order_items_id,dining_facilities.name as table_name") - .joins("left join booking_orders on booking_orders.order_id = orders.id - left join bookings on bookings.id = booking_orders.id + order_table = Order.select("orders.order_id as order_id,sum(order_items.qty*order_items.price) as total_price, + order_items.order_items_id as order_items_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.booking_order_id left join dining_facilities on dining_facilities.id = bookings.dining_facility_id - left join order_items on order_items.order_id = orders.id") + left join order_items on order_items.order_id = orders.order_id") .where("dining_facilities.type=? and orders.order_type=? and dining_facilities.is_active=?",DiningFacility::TABLE_TYPE,"dine_in",true) .group("orders.order_id, order_items.order_items_id,dining_facilities.name") end + def self.get_booking_order_table booking_orders = Booking.select("sales.receipt_no,orders.status as order_status, bookings.booking_id,sales.sale_id as sale_id,dining_facilities.name as table_name") diff --git a/app/views/api/bookings/show.json.jbuilder b/app/views/api/bookings/show.json.jbuilder index cbd1575a..27ec21b9 100644 --- a/app/views/api/bookings/show.json.jbuilder +++ b/app/views/api/bookings/show.json.jbuilder @@ -13,7 +13,6 @@ if (@booking) @total_amount = 0.00 @total_tax = 0.00 - @booking_orders = BookingOrder.where("booking_id = #{@booking.booking_id}").all; if @booking.booking_orders order_items = [] @booking.booking_orders.each do |bo| diff --git a/app/views/crm/customers/_form.html.erb b/app/views/crm/customers/_form.html.erb index 7c37a2fe..533710a9 100644 --- a/app/views/crm/customers/_form.html.erb +++ b/app/views/crm/customers/_form.html.erb @@ -8,7 +8,7 @@ <%= f.input :contact_no %> <%= f.input :email %> <%= f.input :date_of_birth %> - + <%= f.input :membership_id, :collection => @membership %> <%= f.input :membership_type %> <%= f.input :membership_authentication_code %> diff --git a/app/views/crm/customers/index.html.erb b/app/views/crm/customers/index.html.erb index 948e3c3e..8088bcba 100644 --- a/app/views/crm/customers/index.html.erb +++ b/app/views/crm/customers/index.html.erb @@ -71,6 +71,7 @@