From 8a5fcadb69baca7cc90443d3e1377e50b8a9bf04 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Thu, 8 Jun 2017 13:41:11 +0630 Subject: [PATCH] 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%>
-