finished customer to sale assign in crm

This commit is contained in:
Aung Myo
2017-06-08 13:41:11 +06:30
parent 7f8d3381b2
commit 8a5fcadb69
11 changed files with 190 additions and 39 deletions

View File

@@ -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)

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -16,3 +16,5 @@
<%= f.button :submit %>
</div>
<% end %>
<!-- -->

View File

@@ -55,7 +55,8 @@
<div class="col-lg-4">
<%= simple_form_for @crm_customer,:url => crm_customers_path, :method => :post do |f| %>
<span class="patch_method"></span>
<span class="patch_method"></span>
<input type="hidden" id="sale_id" name="sale_id" value="<%= @sale_id %>" />
<%= f.hidden_field :id, :class => "form-control col-md-6 " %>
<div class="form-group">
@@ -80,7 +81,6 @@
<%= f.text_field :date_of_birth,:class=>"form-control datepicker date_of_birth",:readonly =>true, :value => @date_of_birth%>
</div>
<div class="form-group">
<select class="selectpicker form-control col-md-12" name="membership_id">
<option>Select Member Group</option>
@@ -106,6 +106,8 @@
<%end%>
</div>
</div>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.2.0/jquery-confirm.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.2.0/jquery-confirm.min.js"></script>
<script type="text/javascript">
$(function () {
if (jQuery().datepicker) {
@@ -120,11 +122,22 @@
});
$(document).on('click',".checkbox_check",function(){
if(this.checked){
var customer_id = $(this).val();
if(this.checked){
var sale_id = $("#sale_id").val() || 0;
var customer_id = $(this).val();
if(sale_id != 0){
var url = "../"+customer_id;
update_sale(customer_id,sale_id);
}else{
var url = "customers/"+customer_id;
}
$.ajax({
type: "GET",
url: "customers/"+customer_id,
url: url,
data: {},
dataType: "json",
success: function(data) {
@@ -156,6 +169,46 @@
}
})
function update_sale(customer_id,sale_id) {
$.confirm({
title: 'Confirm!',
content: 'Are You Sure to assign this customer!',
buttons: {
cancel: function () {
},
confirm: {
text: 'Confirm',
btnClass: 'btn-green',
keys: ['enter', 'shift'],
action: function(){
$.ajax({
type: "POST",
url: "../../update_sale/" ,
data: {customer_id:customer_id,sale_id:sale_id},
dataType: "json",
success: function(data) {
if(data.status == true)
{
alert('Customer has assigned');
window.location.href = '/origami'
}else{
alert('Record not found!');
location.reload();
}
}
});
}
}
}
});
}
/*function changeMethod() {
$("#update_customer").attr('method', 'put');
}*/

View File

@@ -6,7 +6,7 @@
<% @booking.each do |booking| %>
<% if booking.booking_status == "new" %>
<div class="card">
<div class="card-block booking_click" data-ref="<%= api_booking_path booking.id%>" id="card-block booking_block" style="width:100%;" data="<%= booking.id %>">
<div class="card-block booking_click" data-id="sfddf" data-ref="<%= api_booking_path booking.id%>" id="card-block booking_block" style="width:100%;" >
<h4 class="card-title">
<%= @i += 1 %> . <%= booking.dining_facility.name %>
- <%= booking.id %>
@@ -43,7 +43,7 @@ $(function(){
$("#cancel").removeAttr("disabled");
$("#assign").removeAttr("disabled");
$("#crm_print").removeAttr("disabled");
$("#crm_print").attr('data',$(this).attr('data'));
//$("#crm_print").val($(this).attr('data'));
var url = $(this).attr('data-ref');
show_details(url);
@@ -66,7 +66,6 @@ $(function(){
});
});
function show_details(url_item){

View File

@@ -92,10 +92,10 @@
<!-- Column Three--->
<div class="col-lg-1 col-md-1 col-sm-1">
<!-- OQS Buttons -->
<button type="button" id="crm_print" value="" class="btn btn-primary btn-lg btn-block" disabled="disabled">
<button id="crm_print" value="" disabled="disabled" data-type="assign" class="btn crm_print btn-primary btn-lg btn-block" >
Print
</button>
<button type="button" class="btn btn-primary btn-lg btn-block" disabled>Print <br/>Order<br/>Summary</button>
<button type="button" class="btn btn-primary btn-lg btn-block" disabled>Print <br/>Order<br/>Summary</button>
<button id="assign" value="" disabled="disabled" data-type="assign" class="btn assign btn-primary btn-lg btn-block">ASSIGN</button>
<button id="cancel" value="" disabled="disabled" data-type="cancel" class="btn btn-danger cancel btn-lg btn-block">CANCLE</button>
@@ -105,11 +105,11 @@
<script type="text/javascript">
$( document ).ready(function() {
$('#crm_print').click(function() {
var id = $(this).attr('data');
$('.crm_print').click(function() {
var id = "BKI-000000000004"
$.ajax({
type: "GET",
url: "print/"+id ,
url: "crm/print/"+id,
data: {},
dataType: "json",
success: function(data) {

View File

@@ -206,15 +206,14 @@
</div>
</div>
</div>
</div>
</div><p id="sale" value=""></p>
<!-- Column Three -->
<div class="col-lg-1 col-md-1 col-sm-1">
<!-- Waiter Buttons -->
<button type="button" class="btn btn-primary btn-lg btn-block" disabled>Add Order</button>
<button type="button" class="btn btn-primary btn-lg btn-block" disabled>Edit</button>
<button type="button" class="btn btn-primary btn-lg btn-block" disabled>Move</button>
<button type="button" class="btn btn-primary btn-lg btn-block" disabled>Customer</button>
<button type="button" id="customer" value="SAL-000000000001" class="btn btn-primary btn-lg btn-block">Customer</button>
<button type="button" id="request_bills" class="btn btn-primary btn-lg btn-block">Req.Bill</button>
<!-- Cashier Buttons -->
<button type="button" class="btn btn-primary btn-lg btn-block">Discount</button>
@@ -242,6 +241,7 @@ function callOrderDetails(sale_order_id){
url = "origami/"+sale_order_id.split("_")[1]
data_val = { sale_id: sale_order_id.split("_")[1]}
$("#pay").prop('disabled',false);
$("#customer").prop('disabled',false);
$("#request_bills").prop('disabled',true);
}else{
order_id = sale_order_id.split("_")[1]
@@ -249,6 +249,7 @@ function callOrderDetails(sale_order_id){
data_val = { order_id: sale_order_id.split("_")[1]}
$("#request_bills").prop('disabled',false);
$("#pay").prop('disabled',true);
$("#customer").prop('disabled',true);
}
table_or_order_id = order_id
@@ -347,6 +348,12 @@ $( document ).ready(function() {
return false;
});
$('#customer').click(function() {
var sale_id = $(this).val();
window.location.href = '/crm/customers/'+ sale_id + "/assign_sale_id"
return false;
});
});

View File

@@ -93,9 +93,12 @@ Rails.application.routes.draw do
#--------- Customer Relationship Management ------------#
namespace :crm do
root "home#index" #queue number
get 'customers/:sale_id/assign_sale_id', to: "customers#get_sale_id", :as => "assign_sale"#get sale id with customer for crm
resources :customers
post "update_booking" , to: "bookings#update_booking", as: "update_booking"
get 'print/:id', to: "home#print"
post "update_booking" , to: "bookings#update_booking", as: "update_booking"#assign and cancel
post "update_sale" , to: "home#update_sale_by_customer"#update customer id in sale table
get '/print/:id', to: "home#print_order"#print order for crm
end
#--------- Order Queue Station ------------#