From bd1414e07fa8f950e6f916d00627ce73d4e0fe79 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Sat, 3 Jun 2017 10:59:46 +0630 Subject: [PATCH 1/3] Gemfile and gem lock --- Gemfile | 4 ++-- Gemfile.lock | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index 7668adad..08464196 100644 --- a/Gemfile +++ b/Gemfile @@ -9,10 +9,10 @@ end # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '~> 5.1.0' # Use mysql as the database for Active Record -#gem 'mysql2', '>= 0.3.18', '< 0.5' +gem 'mysql2', '>= 0.3.18', '< 0.5' #Use PosgreSQL -gem 'pg' +#gem 'pg' # redis server for cable gem 'redis', '~> 3.0' diff --git a/Gemfile.lock b/Gemfile.lock index 24527519..79a0d2f8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -114,11 +114,11 @@ GEM mini_portile2 (2.1.0) minitest (5.10.2) multi_json (1.12.1) + mysql2 (0.4.6) nio4r (2.1.0) nokogiri (1.7.2) mini_portile2 (~> 2.1.0) pdf-core (0.7.0) - pg (0.20.0) prawn (2.2.2) pdf-core (~> 0.7.0) ttfunk (~> 1.5) @@ -251,7 +251,7 @@ DEPENDENCIES jquery-rails kaminari! listen (~> 3.0.5) - pg + mysql2 (>= 0.3.18, < 0.5) prawn prawn-table puma (~> 3.0) From 324f1e3b24f547493bd9504f164ccc5369b52d10 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Tue, 6 Jun 2017 10:10:47 +0630 Subject: [PATCH 2/3] update query in order model for origami --- Gemfile.lock | 2 -- app/models/order.rb | 18 +++++++++--------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index bd6f0991..7bf4f9a4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -116,9 +116,7 @@ GEM mini_portile2 (2.1.0) minitest (5.10.2) multi_json (1.12.1) - multi_xml (0.6.0) - mysql2 (0.4.6) nio4r (2.1.0) nokogiri (1.7.2) diff --git a/app/models/order.rb b/app/models/order.rb index 3fabf91b..497fdd9b 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -211,15 +211,15 @@ 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.id, order_items.id,dining_facilities.name") + .group("orders.order_id, order_items.id,dining_facilities.name") + end def self.get_booking_order_table @@ -270,8 +270,7 @@ class Order < ApplicationRecord left join sale_orders on sale_orders.order_id = orders.order_id left join sales on sales.sale_id = sale_orders.sale_id") .where("dining_facilities.is_active=? and orders.date between ? and ?",true,from,to) - - .group("orders.id,order_items.id,dining_facilities.name") + .group("orders.order_id,order_items.order_items_id,dining_facilities.name") end @@ -285,4 +284,5 @@ class Order < ApplicationRecord def set_order_date self.date = Time.now.utc end + end From d2ce74f648a6c271c3307d5c246532a336eb9439 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Tue, 6 Jun 2017 14:16:40 +0630 Subject: [PATCH 3/3] bootstrap datepicker and customer save --- Gemfile | 4 +- Gemfile.lock | 3 + app/assets/javascripts/application.js | 1 + app/assets/stylesheets/application.scss | 1 + app/controllers/crm/customers_controller.rb | 18 ++- app/models/customer.rb | 21 ++- app/views/api/bookings/show.json.jbuilder | 1 - app/views/crm/customers/_form.html.erb | 2 +- app/views/crm/customers/index.html.erb | 141 +++++++++++++++----- 9 files changed, 146 insertions(+), 46 deletions(-) diff --git a/Gemfile b/Gemfile index f64229aa..c0663409 100644 --- a/Gemfile +++ b/Gemfile @@ -92,4 +92,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 7bf4f9a4..ae2a3941 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) @@ -243,6 +245,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/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 5a29b74c..d866d47d 100644 --- a/app/views/crm/customers/index.html.erb +++ b/app/views/crm/customers/index.html.erb @@ -1,41 +1,110 @@ -

<%= notice %>

+
+ +
+
-

Crm Customers

+
+
+ +
+
+ + + + + + + + + + -
NameCompanyContact noEmail
- - - - - - - - - - - - - + + <% @crm_customers.each do |crm_customer| %> + + + + + + + + <% end %> + +
NameCompanyContact noEmailDate of birthMembershipMembership typeMembership authentication code
<%= crm_customer.name %><%= crm_customer.company %><%= crm_customer.contact_no %><%= crm_customer.email %>
+
+
- - <% @crm_customers.each do |crm_customer| %> - - <%= crm_customer.name %> - <%= crm_customer.company %> - <%= crm_customer.contact_no %> - <%= crm_customer.email %> - <%= crm_customer.date_of_birth %> - <%= crm_customer.membership_id %> - <%= crm_customer.membership_type %> - <%= crm_customer.membership_authentication_code %> - <%= link_to 'Show', crm_customer_path(crm_customer) %> - <%= link_to 'Edit', edit_crm_customer_path(crm_customer) %> - <%= link_to 'Destroy', crm_customer_path(crm_customer), method: :delete, data: { confirm: 'Are you sure?' } %> - - <% end %> - - +
-
+
+ <%= simple_form_for crm_customers_path, :html => { :class => 'form-horizontal' } do |f| %> + +
+ <%= f.input :name, :class => "form-control col-md-6" %> +
+
+ <%= f.input :company, :class => "form-control col-md-6" %> +
+
+ <%= f.input :contact_no, :class => "form-control col-md-6" %> +
+
+ <%= f.input :email, :class => "form-control col-md-6" %> +
-<%= link_to 'New Crm Customer', new_crm_customer_path %> +
+ + <%= f.text_field :date_of_birth,:class=>"form-control datepicker",:readonly =>true, :value => @date_of_birth%> + +
+ +
+ <%= f.select :membership_id, options_for_select(@membership.collect { |member| + [member["id"].name.titleize, member["id"].id] }, 1), {}, { id: 'countries_select' } %> + +
+ + +
+ <%= f.input :membership_type, :class => "form-control col-md-6" %> +
+
+ <%= f.input :membership_authentication_code, :class => "form-control col-md-6" %> + +
+
+ <%= f.button :submit, "Submit", :class => 'btn btn-primary' , :id => 'submit_account' %> +
+ <%end%> +
+
+ +