From e76296bb779282c7e5b65c5326ee5a8013ad1592 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Tue, 6 Jun 2017 14:44:25 +0630 Subject: [PATCH 1/6] checkout crm --- .../origami/request_bills_controller.rb | 9 +- app/views/crm/customers/index.html.erb | 141 +++++++++++++----- app/views/origami/home/index.html.erb | 6 +- 3 files changed, 111 insertions(+), 45 deletions(-) diff --git a/app/controllers/origami/request_bills_controller.rb b/app/controllers/origami/request_bills_controller.rb index 31766599..3cc69ac2 100644 --- a/app/controllers/origami/request_bills_controller.rb +++ b/app/controllers/origami/request_bills_controller.rb @@ -1,6 +1,6 @@ class Origami::RequestBillsController < BaseOrigamiController - def create + def show @sale = Sale.new @@ -27,11 +27,6 @@ class Origami::RequestBillsController < BaseOrigamiController end - def show - sale_id = params[:sale_id] - if Sale.exists?(sale_id) - @sale_data = Sale.find_by_sale_id(sale_id) - end - end + end diff --git a/app/views/crm/customers/index.html.erb b/app/views/crm/customers/index.html.erb index 5a29b74c..948e3c3e 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["name"], member["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%> +
+
+ + diff --git a/app/views/origami/home/index.html.erb b/app/views/origami/home/index.html.erb index 78f59422..bb618979 100644 --- a/app/views/origami/home/index.html.erb +++ b/app/views/origami/home/index.html.erb @@ -214,7 +214,7 @@ function callOrderDetails(sale_order_id){ sale_order = sale_order_id.split("_")[0] if (sale_order == 'sale') { - sale_id = sale_order_id.split("_")[1] + order_id = sale_order_id.split("_")[1] url = "origami/"+sale_order_id.split("_")[1] data_val = { sale_id: sale_order_id.split("_")[1]} @@ -224,8 +224,10 @@ function callOrderDetails(sale_order_id){ data_val = { order_id: sale_order_id.split("_")[1]} } + table_or_order_id = order_id pay_sale_id = sale_id + alert(table_or_order_id) var tbody = "" $("#append-table").html("") if (old_order_id != order_id){ @@ -316,7 +318,7 @@ $( document ).ready(function() { $( document ).ready(function() { $('#pay').click(function() { - window.location.href = '/origami/sale/'+ pay_sale_id + "/payment" + window.location.href = '/origami/sale/'+pay_sale_id +"/payment" return false; }); }); From 9e3eaaf214c2cb447fd311b3374bd6e6e092d937 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Tue, 6 Jun 2017 18:07:38 +0630 Subject: [PATCH 2/6] finished Customer save and return data from membership in crm --- Gemfile.lock | 2 - app/controllers/crm/customers_controller.rb | 48 +++++++++++++++++---- app/models/customer.rb | 35 +++++++++++++-- app/views/crm/customers/index.html.erb | 14 +++--- 4 files changed, 76 insertions(+), 23 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 533cd08b..ae2a3941 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -124,7 +124,6 @@ GEM 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) @@ -260,7 +259,6 @@ DEPENDENCIES kaminari! listen (~> 3.0.5) mysql2 (>= 0.3.18, < 0.5) - pg prawn prawn-table puma (~> 3.0) diff --git a/app/controllers/crm/customers_controller.rb b/app/controllers/crm/customers_controller.rb index c25f6e80..15657a98 100644 --- a/app/controllers/crm/customers_controller.rb +++ b/app/controllers/crm/customers_controller.rb @@ -5,9 +5,11 @@ class Crm::CustomersController < ApplicationController # GET /crm/customers.json def index @crm_customers = Customer.all - @customers = Customer.new + @crm_customer = Customer.new @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 } @@ -33,14 +35,39 @@ class Crm::CustomersController < ApplicationController # POST /crm/customers # POST /crm/customers.json def create - @crm_customer = Customer.new(customer_params) - + puts "Hello" + puts customer_params.to_json + @crm_customers = Customer.new(customer_params) + respond_to do |format| - if @crm_customer.save - format.html { redirect_to @crm_customer, notice: 'Customer was successfully created.' } - format.json { render :show, status: :created, location: @crm_customer } + 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] + + membership = MembershipSetting.find_by_membership_type("smartpay_url") + app_token = membership.auth_token.to_s + url = membership.gateway_url.to_s + "/api/create_membership_customer".to_s + + response = HTTParty.post(url, + :body => { name: name,phone: phone,email: email,date_of_birth: date_of_birth,membership_id: membership_id}.to_json, + :headers => { + 'Content-Type' => 'application/json', + 'Accept' => 'application/json' + } + ) + + puts "rrrrrrrrrrrrrr" + puts response.to_json + + format.html { redirect_to crm_customers_path, notice: 'Customer was successfully created.' } + format.json { render :index, status: :created, location: @crm_customers } + else - format.html { render :new } + format.html { render :index } format.json { render json: @crm_customer.errors, status: :unprocessable_entity } end end @@ -78,6 +105,9 @@ class Crm::CustomersController < ApplicationController # 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_id, :membership_type, :membership_authentication_code) + + params.require(:customer).permit(:name, :company, :contact_no, :email, :date_of_birth, :membership_type, :membership_authentication_code) end end + + diff --git a/app/models/customer.rb b/app/models/customer.rb index 95901cce..206c2ada 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -10,20 +10,47 @@ class Customer < ApplicationRecord validates :contact_no, uniqueness: true validates :email, uniqueness: true + # attr_accessor :name, :company, :contact_no, :email, :date_of_birth, :membership_id, :membership_type, :membership_authentication_code + + 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) + membership = MembershipSetting.find_by_membership_type("smartpay_url") + app_token = membership.auth_token.to_s + + url = membership.gateway_url.to_s + "/api/get_all_member_group".to_s + response = HTTParty.get(url, + :body => { app_token: app_token}.to_json, + :headers => { + 'Content-Type' => 'application/json', + 'Accept' => 'application/json' + } + ) 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 self.generate(params) + puts "Hello " + puts params.to_json + customer = Customer.new + customer.name= params[:name] + customer.company= params[:company] + customer.contact_no= params[:contact_no] + customer.email= params[:email] + customer.date_of_birth= params[:date_of_birth] + customer.membership_id= params[:membership_id] + customer.membership_type= params[:membership_type] + customer.membership_authentication_code= params[:membership_authentication_code] + customer.save! + return customer + end def lastest_invoices sales.where(:customer_id => self.id).order("created_at desc").limit(5) diff --git a/app/views/crm/customers/index.html.erb b/app/views/crm/customers/index.html.erb index 8088bcba..ce4c3826 100644 --- a/app/views/crm/customers/index.html.erb +++ b/app/views/crm/customers/index.html.erb @@ -47,7 +47,7 @@
- <%= simple_form_for crm_customers_path, :html => { :class => 'form-horizontal' } do |f| %> + <%= simple_form_for @crm_customer, :url => crm_customers_path, :method => :post do |f| %>
<%= f.input :name, :class => "form-control col-md-6" %> @@ -63,22 +63,20 @@
- <%= 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["name"], member["id"]] }, 1), {}, { id: 'countries_select' } %> - - <% @membership.each do |member| %> + <% @member_group.each do |member| %> <%end %> - +
@@ -90,7 +88,7 @@
- <%= f.button :submit, "Submit", :class => 'btn btn-primary' , :id => 'submit_account' %> + <%= f.button :submit, "Submit",:class => 'btn btn-primary' , :id => 'submit_account' %>
<%end%> From 387ffa996b8382ae3446bf7eda03269e0af27ef5 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Wed, 7 Jun 2017 16:38:24 +0630 Subject: [PATCH 3/6] finished customer and join membership in crm --- app/assets/javascripts/application.js | 1 + app/controllers/crm/customers_controller.rb | 66 ++++++++---- app/controllers/crm/home_controller.rb | 30 +++--- app/models/customer.rb | 22 ---- app/models/printer/receipt_printer.rb | 10 ++ app/pdf/crm_order_pdf.rb | 38 +++++++ app/views/crm/customers/_form.html.erb | 1 - app/views/crm/customers/index.html.erb | 113 ++++++++++++++++---- app/views/crm/customers/show.html.erb | 4 - app/views/crm/customers/show.json.jbuilder | 3 +- app/views/crm/home/_booking.html.erb | 16 ++- app/views/crm/home/index.html.erb | 29 ++++- app/views/layouts/CRM.html.erb | 2 +- config/routes.rb | 5 +- 14 files changed, 248 insertions(+), 92 deletions(-) create mode 100644 app/pdf/crm_order_pdf.rb diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index f2ee34ba..8ff96589 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -18,3 +18,4 @@ //= require cable //= require settings/processing_items //= require bootstrap-datepicker + diff --git a/app/controllers/crm/customers_controller.rb b/app/controllers/crm/customers_controller.rb index 15657a98..d8cb1f69 100644 --- a/app/controllers/crm/customers_controller.rb +++ b/app/controllers/crm/customers_controller.rb @@ -4,8 +4,8 @@ class Crm::CustomersController < ApplicationController # GET /crm/customers # GET /crm/customers.json def index - @crm_customers = Customer.all - @crm_customer = Customer.new + @crm_customers = Customer.all + @crm_customer = Customer.new @membership = Customer.get_member_group if @membership["status"] == true @member_group = @membership["data"] @@ -35,12 +35,11 @@ class Crm::CustomersController < ApplicationController # POST /crm/customers # POST /crm/customers.json def create - puts "Hello" - puts customer_params.to_json @crm_customers = Customer.new(customer_params) respond_to do |format| if @crm_customers.save + name = customer_params[:name] phone = customer_params[:contact_no] @@ -52,23 +51,33 @@ class Crm::CustomersController < ApplicationController app_token = membership.auth_token.to_s url = membership.gateway_url.to_s + "/api/create_membership_customer".to_s - response = HTTParty.post(url, - :body => { name: name,phone: phone,email: email,date_of_birth: date_of_birth,membership_id: membership_id}.to_json, - :headers => { - 'Content-Type' => 'application/json', - 'Accept' => 'application/json' - } - ) + response = HTTParty.post(url, :body => { name: name,phone: phone,email: email, + date_of_birth: date_of_birth, + membership_id: membership_id}.to_json, + :headers => { + 'Content-Type' => 'application/json', + 'Accept' => 'application/json' + } + ) - puts "rrrrrrrrrrrrrr" - puts response.to_json + if response["status"] == true + + customer = Customer.find(@crm_customers.customer_id) + status = customer.update_attributes(membership_id: response["customer_datas"]["id"]) - format.html { redirect_to crm_customers_path, notice: 'Customer was successfully created.' } - format.json { render :index, status: :created, location: @crm_customers } + format.html { redirect_to crm_customers_path, notice: 'Customer was successfully created.' } + # format.json { render :index, status: :created, location: @crm_customers } + else + @crm_customers.destroy + format.html { redirect_to crm_customers_path, notice: 'Customer was not successfully created.' } + end + + + # format.json { render :index, status: :created, location: @crm_customers } else - format.html { render :index } - format.json { render json: @crm_customer.errors, status: :unprocessable_entity } + format.html { redirect_to crm_customers_path} + format.json { render json: @crm_customers.errors, status: :unprocessable_entity } end end end @@ -76,9 +85,30 @@ class Crm::CustomersController < ApplicationController # PATCH/PUT /crm/customers/1 # PATCH/PUT /crm/customers/1.json def update + respond_to do |format| if @crm_customer.update(customer_params) - format.html { redirect_to @crm_customer, notice: 'Customer was successfully updated.' } + + name = customer_params[:name] + phone = customer_params[:contact_no] + email = customer_params[:email] + date_of_birth = customer_params[:date_of_birth] + id = customer_params[:membership_id] + + membership = MembershipSetting.find_by_membership_type("smartpay_url") + app_token = membership.auth_token.to_s + url = membership.gateway_url.to_s + "/api/update_membership_customer".to_s + + response = HTTParty.post(url, :body => { name: name,phone: phone,email: email, + date_of_birth: date_of_birth, + id: id}.to_json, + :headers => { + 'Content-Type' => 'application/json', + 'Accept' => 'application/json' + } + ) + puts response.to_json + format.html { redirect_to crm_customers_path, notice: 'Customer was successfully updated.' } format.json { render :show, status: :ok, location: @crm_customer } else format.html { render :edit } diff --git a/app/controllers/crm/home_controller.rb b/app/controllers/crm/home_controller.rb index 083f2bf7..7b565ba5 100644 --- a/app/controllers/crm/home_controller.rb +++ b/app/controllers/crm/home_controller.rb @@ -3,22 +3,24 @@ class Crm::HomeController < BaseCrmController @booking = Booking.all @customer = Customer.all - - #@booking = Booking.select("bookings.id as booking_id, - # bookings.checkin_at, - # bookings.checkin_by, - # bookings.dining_facility_id, - # od.customer_id as customer, - # od.id as order_id, - # od.item_count as count, - # odt.id as order_item_id, - # odt.item_name as item_name") - # .joins("join booking_orders as bko ON bko.booking_id = bookings.id") - # .joins("right join orders as od ON od.id = bko.order_id") - # .joins("right join order_items as odt ON odt.order_id=od.id") - # .order("bookings.id DESC") end + def show end + + #print for crm + def print + + @booking = Booking.find(params[:id]) + + unique_code="CrmOrderPdf" + + #print_settings = PrintSetting.find_by_unique_code(unique_code) + + printer = Printer::ReceiptPrinter.new() + + printer.print_crm_order(@booking) + + end end diff --git a/app/models/customer.rb b/app/models/customer.rb index 206c2ada..6d2bd561 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -10,8 +10,6 @@ class Customer < ApplicationRecord validates :contact_no, uniqueness: true validates :email, uniqueness: true - # attr_accessor :name, :company, :contact_no, :email, :date_of_birth, :membership_id, :membership_type, :membership_authentication_code - def self.get_member_group @@ -32,26 +30,6 @@ class Customer < ApplicationRecord end - -# http://192.168.1.47:3006/api/create_membership_customer -#get_all_member_group - - def self.generate(params) - puts "Hello " - puts params.to_json - customer = Customer.new - customer.name= params[:name] - customer.company= params[:company] - customer.contact_no= params[:contact_no] - customer.email= params[:email] - customer.date_of_birth= params[:date_of_birth] - customer.membership_id= params[:membership_id] - customer.membership_type= params[:membership_type] - customer.membership_authentication_code= params[:membership_authentication_code] - customer.save! - return customer - end - def lastest_invoices sales.where(:customer_id => self.id).order("created_at desc").limit(5) end diff --git a/app/models/printer/receipt_printer.rb b/app/models/printer/receipt_printer.rb index 86d43190..b60d08ae 100644 --- a/app/models/printer/receipt_printer.rb +++ b/app/models/printer/receipt_printer.rb @@ -72,4 +72,14 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker pdf.render_file "tmp/receipt_bill.pdf" self.print("tmp/receipt_bill.pdf") end + + #Bill Receipt Print + def print_crm_order(booking) + #Use CUPS service + #Generate PDF + #Print + pdf = CrmOrderPdf.new(booking) + pdf.render_file "tmp/print_crm_order.pdf" + self.print("tmp/print_crm_order.pdf") + end end diff --git a/app/pdf/crm_order_pdf.rb b/app/pdf/crm_order_pdf.rb new file mode 100644 index 00000000..f9d641b3 --- /dev/null +++ b/app/pdf/crm_order_pdf.rb @@ -0,0 +1,38 @@ +class OrderItemPdf < Prawn::Document + + def initialize(order_item) + super(:margin => [10, 5, 30, 5], :page_size => [200,400]) + + # font "public/fonts/#{font_name}".to_s + ".ttf".to_s + # font "public/fonts/Zawgyi-One.ttf" + # font "public/fonts/padauk.ttf" + font_size 9 + text "#{order_item.dining}", :size => 15 + stroke_horizontal_rule + move_down 5 + + #order_info + order_info(order_item.order_by,order_item.order_at, order_item.customer) + + # order items + # order_items(order_item) + end + + # Write Order Information to PDF + def order_info(order_by, order_at, customer) + y_position = cursor + + bounding_box([0,y_position], :width => 200, :height => 15) do + text "OrderBy:#{order_by} Customer:#{customer} Date:#{order_at.strftime("%Y-%m-%d")}", :size => 7,:align => :left + end + + stroke_horizontal_rule + + move_down 20 + end + + + + end + +end diff --git a/app/views/crm/customers/_form.html.erb b/app/views/crm/customers/_form.html.erb index 533710a9..6de6d686 100644 --- a/app/views/crm/customers/_form.html.erb +++ b/app/views/crm/customers/_form.html.erb @@ -8,7 +8,6 @@ <%= 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 ce4c3826..167dccc4 100644 --- a/app/views/crm/customers/index.html.erb +++ b/app/views/crm/customers/index.html.erb @@ -1,20 +1,20 @@
-
+
@@ -22,6 +22,7 @@ + Select Name Company Contact no @@ -32,10 +33,16 @@ <% @crm_customers.each do |crm_customer| %> + + <%= crm_customer.name %> <%= crm_customer.company %> <%= crm_customer.contact_no %> <%= crm_customer.email %> + + <%= link_to 'Destroy', crm_customer_path(crm_customer), method: :delete, data: { confirm: 'Are you sure?' } %> + + <% end %> @@ -46,31 +53,36 @@
-
- <%= simple_form_for @crm_customer, :url => crm_customers_path, :method => :post do |f| %> - +
+ <%= simple_form_for @crm_customer,:url => crm_customers_path, :method => :post do |f| %> + + <%= f.hidden_field :id, :class => "form-control col-md-6 " %> +
- <%= f.input :name, :class => "form-control col-md-6" %> + <%= f.input :name, :class => "form-control col-md-6 name" %> +
- <%= f.input :company, :class => "form-control col-md-6" %> + <%= f.input :company, :class => "form-control col-md-6 company" %>
- <%= f.input :contact_no, :class => "form-control col-md-6" %> + <%= f.input :contact_no, :class => "form-control col-md-6 contact_no" %> + +
+
- <%= f.input :email, :class => "form-control col-md-6" %> + <%= f.input :email, :class => "form-control col-md-6 email" %>
-
- <%= f.text_field :date_of_birth,:class=>"form-control datepicker",:readonly =>true, :value => @date_of_birth%> - +
+ + <%= f.text_field :date_of_birth,:class=>"form-control datepicker date_of_birth",:readonly =>true, :value => @date_of_birth%>
-
- - <% @member_group.each do |member| %>
- +
- <%= f.input :membership_type, :class => "form-control col-md-6" %> + <%= f.input :membership_type, :class => "form-control col-md-6 membership_type" %>
- <%= f.input :membership_authentication_code, :class => "form-control col-md-6" %> + <%= f.input :membership_authentication_code, :class => "form-control col-md-6 membership_authentication_code" %>
- <%= f.button :submit, "Submit",:class => 'btn btn-primary' , :id => 'submit_account' %> + <%= f.button :submit, "Submit",:class => 'btn btn-primary ', :id => 'submit_customer' %> + <%= f.button :submit, "Update",:class => 'btn btn-primary ', :disabled =>'', :id => 'update_customer' %>
<%end%>
- + + + + diff --git a/app/views/crm/customers/show.html.erb b/app/views/crm/customers/show.html.erb index 30341a00..da88e887 100644 --- a/app/views/crm/customers/show.html.erb +++ b/app/views/crm/customers/show.html.erb @@ -25,10 +25,6 @@ <%= @crm_customer.date_of_birth %>

-

- Membership: - <%= @crm_customer.membership %> -

Membership type: diff --git a/app/views/crm/customers/show.json.jbuilder b/app/views/crm/customers/show.json.jbuilder index 24d20eca..bd9680de 100644 --- a/app/views/crm/customers/show.json.jbuilder +++ b/app/views/crm/customers/show.json.jbuilder @@ -1 +1,2 @@ -json.partial! "crm_customers/crm_customer", crm_customer: @crm_customer +json.extract! @crm_customer, :id, :name, :company, :contact_no, :email, :date_of_birth, :membership_id, :membership_type, :membership_authentication_code, :created_at, :updated_at +json.url crm_customer_url(@crm_customer, format: :json) diff --git a/app/views/crm/home/_booking.html.erb b/app/views/crm/home/_booking.html.erb index f69f5fe0..afacb52e 100644 --- a/app/views/crm/home/_booking.html.erb +++ b/app/views/crm/home/_booking.html.erb @@ -4,9 +4,9 @@ <% @i = 0 %> <% @booking.each do |booking| %> - <% if booking.booking_status == "assign" %> + <% if booking.booking_status == "new" %>

-
+

<%= @i += 1 %> . <%= booking.dining_facility.name %> - <%= booking.id %> @@ -36,14 +36,20 @@ diff --git a/app/views/layouts/CRM.html.erb b/app/views/layouts/CRM.html.erb index 4bd98526..41de0ca2 100644 --- a/app/views/layouts/CRM.html.erb +++ b/app/views/layouts/CRM.html.erb @@ -17,7 +17,7 @@ <%= render 'layouts/header_crm' %>
<% flash.each do |type, message| %> -
+
<%= message %>
diff --git a/config/routes.rb b/config/routes.rb index df652e6b..b5267114 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -86,12 +86,9 @@ Rails.application.routes.draw do #--------- Customer Relationship Management ------------# namespace :crm do root "home#index" #queue number - #customers resources :customers - #membership - #bookings post "update_booking" , to: "bookings#update_booking", as: "update_booking" - #queue + get 'print/:id', to: "home#print" end #--------- Order Queue Station ------------# From fd1c53432c51bbf5caf68d88f8210b473e24bd3f Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Wed, 7 Jun 2017 17:13:27 +0630 Subject: [PATCH 4/6] account model updated --- app/models/account.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/account.rb b/app/models/account.rb index a950865c..ee768fb6 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -2,7 +2,7 @@ class Account < ApplicationRecord validates_presence_of :title, :account_type has_many :menu_items - # belongs_to :lookup , :class_name => "Lookup" + def self.collection Account.select("id, title").map { |e| [e.title, e.id] } end From 7f8d3381b23aa7a54cb58597f189b15592755ce2 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Wed, 7 Jun 2017 22:31:49 +0630 Subject: [PATCH 5/6] fixed conflict order --- app/models/order.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/models/order.rb b/app/models/order.rb index dde46bc1..54e02b83 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -273,10 +273,7 @@ class Order < ApplicationRecord 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.order_id,order_items.order_items_id,dining_facilities.name,sales.receipt_no,bookings.booking_id,sales.sale_id") -<<<<<<< HEAD -======= ->>>>>>> f9c8dbc03eee1b539ce04480b411b1d761e570f4 end private From 8a5fcadb69baca7cc90443d3e1377e50b8a9bf04 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Thu, 8 Jun 2017 13:41:11 +0630 Subject: [PATCH 6/6] finished customer to sale assign in crm --- Gemfile.lock | 2 +- app/controllers/crm/customers_controller.rb | 54 +++++++++++++++--- app/controllers/crm/home_controller.rb | 24 ++++++-- app/models/printer/receipt_printer.rb | 4 +- app/pdf/crm_order_pdf.rb | 45 +++++++++++++-- app/views/crm/customers/_form.html.erb | 2 + app/views/crm/customers/index.html.erb | 63 +++++++++++++++++++-- app/views/crm/home/_booking.html.erb | 5 +- app/views/crm/home/index.html.erb | 10 ++-- app/views/origami/home/index.html.erb | 13 ++++- config/routes.rb | 7 ++- 11 files changed, 190 insertions(+), 39 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index fbf61a33..2c4c94b3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -123,6 +123,7 @@ GEM 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) @@ -258,7 +259,6 @@ DEPENDENCIES kaminari! listen (~> 3.0.5) pg - mysql2 (>= 0.3.18, < 0.5) prawn prawn-table puma (~> 3.0) diff --git a/app/controllers/crm/customers_controller.rb b/app/controllers/crm/customers_controller.rb index d8cb1f69..295a0d8f 100644 --- a/app/controllers/crm/customers_controller.rb +++ b/app/controllers/crm/customers_controller.rb @@ -4,6 +4,7 @@ class Crm::CustomersController < ApplicationController # GET /crm/customers # GET /crm/customers.json def index + @sale_id = 0 @crm_customers = Customer.all @crm_customer = Customer.new @membership = Customer.get_member_group @@ -35,6 +36,7 @@ class Crm::CustomersController < ApplicationController # POST /crm/customers # POST /crm/customers.json def create + @crm_customers = Customer.new(customer_params) respond_to do |format| @@ -61,23 +63,41 @@ class Crm::CustomersController < ApplicationController ) if response["status"] == true - + puts "hhhhhhhhhhhhhhhhhh" + puts params[:sale_id] customer = Customer.find(@crm_customers.customer_id) status = customer.update_attributes(membership_id: response["customer_datas"]["id"]) - - format.html { redirect_to crm_customers_path, notice: 'Customer was successfully created.' } + if params[:sale_id] != 0 + format.html { redirect_to crm_customers_path, notice: 'Customer was successfully created.' } + else + format.html { redirect_to '/crm/customers/'+params[:sale_id]+'/assign_sale_id', notice: 'Customer was successfully created.' } + end # format.json { render :index, status: :created, location: @crm_customers } else + @crm_customers.destroy - format.html { redirect_to crm_customers_path, notice: 'Customer was not successfully created.' } + + if params[:sale_id] != 0 + format.html { redirect_to crm_customers_path, notice: response["message"] } + + else + format.html { redirect_to '/crm/customers/'+params[:sale_id]+'/assign_sale_id', notice: response["message"] } + end + end # format.json { render :index, status: :created, location: @crm_customers } else - format.html { redirect_to crm_customers_path} - format.json { render json: @crm_customers.errors, status: :unprocessable_entity } + 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 + end end end @@ -107,13 +127,16 @@ class Crm::CustomersController < ApplicationController 'Accept' => 'application/json' } ) - puts response.to_json + format.html { redirect_to crm_customers_path, notice: 'Customer was successfully updated.' } format.json { render :show, status: :ok, location: @crm_customer } + else + format.html { render :edit } format.json { render json: @crm_customer.errors, status: :unprocessable_entity } end + end end @@ -127,6 +150,23 @@ class Crm::CustomersController < ApplicationController end end + # 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 + @membership = Customer.get_member_group + if @membership["status"] == true + @member_group = @membership["data"] + end + respond_to do |format| + format.html { render action: "index"} + format.json { render json: @crm_customers } + end + end + private # Use callbacks to share common setup or constraints between actions. def set_crm_customer diff --git a/app/controllers/crm/home_controller.rb b/app/controllers/crm/home_controller.rb index 7b565ba5..f3e82e41 100644 --- a/app/controllers/crm/home_controller.rb +++ b/app/controllers/crm/home_controller.rb @@ -10,17 +10,31 @@ class Crm::HomeController < BaseCrmController end #print for crm - def print + def print_order @booking = Booking.find(params[:id]) - unique_code="CrmOrderPdf" - #print_settings = PrintSetting.find_by_unique_code(unique_code) + print_settings = PrintSetting.find_by_unique_code(unique_code) - printer = Printer::ReceiptPrinter.new() + printer = Printer::ReceiptPrinter.new(print_settings) - printer.print_crm_order(@booking) + printer.print_crm_order(@booking,print_settings) 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 + end + diff --git a/app/models/printer/receipt_printer.rb b/app/models/printer/receipt_printer.rb index 15138f74..523b9ec9 100644 --- a/app/models/printer/receipt_printer.rb +++ b/app/models/printer/receipt_printer.rb @@ -74,11 +74,11 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker end #Bill Receipt Print - def print_crm_order(booking) + def print_crm_order(booking,setting) #Use CUPS service #Generate PDF #Print - pdf = CrmOrderPdf.new(booking) + pdf = CrmOrderPdf.new(booking,setting) pdf.render_file "tmp/print_crm_order.pdf" self.print("tmp/print_crm_order.pdf") end diff --git a/app/pdf/crm_order_pdf.rb b/app/pdf/crm_order_pdf.rb index f9d641b3..36aed0a1 100644 --- a/app/pdf/crm_order_pdf.rb +++ b/app/pdf/crm_order_pdf.rb @@ -1,21 +1,21 @@ -class OrderItemPdf < Prawn::Document +class CrmOrderPdf < Prawn::Document - def initialize(order_item) + def initialize(order_item, print_settings) super(:margin => [10, 5, 30, 5], :page_size => [200,400]) # font "public/fonts/#{font_name}".to_s + ".ttf".to_s # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" font_size 9 - text "#{order_item.dining}", :size => 15 + text "#{order_item.type}", :size => 15 stroke_horizontal_rule move_down 5 #order_info - order_info(order_item.order_by,order_item.order_at, order_item.customer) + order_info(order_item.checkin_by,order_item.checkin_at, order_item.customer_id) # order items - # order_items(order_item) + order_items(order_item) end # Write Order Information to PDF @@ -31,7 +31,40 @@ class OrderItemPdf < Prawn::Document move_down 20 end - + # Write Order items to PDF + def order_items(order_item) + y_position = cursor + + bounding_box([0,y_position], :width => 180, :height => 15) do + text "Item", :size => 7,:align => :left + end + + bounding_box([160,y_position], :width => 20, :height => 15) do + text "Qty", :size => 7,:align => :right + end + + stroke_horizontal_rule + move_down 5 + + #Add Order Item + add_order_items(order_item) + end + + # Add order items under order info + def add_order_items(order_item) + y_position = cursor + + move_down 5 + + bounding_box([0,y_position], :width => 180, :height => 20) do + text "#{order_item.sale_id}", :size => 7,:align => :left + end + + bounding_box([160,y_position], :width => 20, :height => 20) do + text "#{order_item.sale_id}", :size => 7,:align => :right + end + + move_down 5 end diff --git a/app/views/crm/customers/_form.html.erb b/app/views/crm/customers/_form.html.erb index 6de6d686..758a52a2 100644 --- a/app/views/crm/customers/_form.html.erb +++ b/app/views/crm/customers/_form.html.erb @@ -16,3 +16,5 @@ <%= f.button :submit %>
<% end %> + + \ No newline at end of file diff --git a/app/views/crm/customers/index.html.erb b/app/views/crm/customers/index.html.erb index 167dccc4..86f267b0 100644 --- a/app/views/crm/customers/index.html.erb +++ b/app/views/crm/customers/index.html.erb @@ -55,7 +55,8 @@
<%= simple_form_for @crm_customer,:url => crm_customers_path, :method => :post do |f| %> - + + <%= f.hidden_field :id, :class => "form-control col-md-6 " %>
@@ -80,7 +81,6 @@ <%= f.text_field :date_of_birth,:class=>"form-control datepicker date_of_birth",:readonly =>true, :value => @date_of_birth%>
-