Merge branch 'master' of bitbucket.org:code2lab/sxrestaurant into loyalty

This commit is contained in:
Moe Su
2017-06-08 17:57:43 +06:30
25 changed files with 857 additions and 126 deletions

View File

@@ -9,9 +9,7 @@ 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'
@@ -45,9 +43,6 @@ gem 'to_xls-rails'
#Reporting gem
#gem 'compendium'
# Pagination
gem 'kaminari', :git => "git://github.com/amatsuda/kaminari.git", :branch => 'master'
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
@@ -62,7 +57,7 @@ gem 'bcrypt', '~> 3.1.7'
gem 'sidekiq'
# Pagination
gem 'kaminari', :git => "git://github.com/amatsuda/kaminari.git", :branch => 'master'
gem 'kaminari', '~> 0.16.3' #:git => "git://github.com/amatsuda/kaminari.git", :branch => 'master'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

View File

@@ -1,21 +1,3 @@
GIT
remote: git://github.com/amatsuda/kaminari.git
revision: bc52ae73d41386d344b5d1b18e689e5a988f1a03
branch: master
specs:
kaminari (1.0.1)
activesupport (>= 4.1.0)
kaminari-actionview (= 1.0.1)
kaminari-activerecord (= 1.0.1)
kaminari-core (= 1.0.1)
kaminari-actionview (1.0.1)
actionview
kaminari-core (= 1.0.1)
kaminari-activerecord (1.0.1)
activerecord
kaminari-core (= 1.0.1)
kaminari-core (1.0.1)
GEM
remote: https://rubygems.org/
specs:
@@ -104,6 +86,9 @@ GEM
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
kaminari (0.16.3)
actionpack (>= 3.0.0)
activesupport (>= 3.0.0)
listen (3.0.8)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
@@ -119,6 +104,7 @@ GEM
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)
mini_portile2 (~> 2.1.0)
@@ -256,8 +242,9 @@ DEPENDENCIES
httparty (~> 0.15.5)
jbuilder (~> 2.5)
jquery-rails
kaminari!
kaminari (~> 0.16.3)
listen (~> 3.0.5)
mysql2 (>= 0.3.18, < 0.5)
pg
prawn
prawn-table

View File

@@ -18,3 +18,4 @@
//= require cable
//= require settings/processing_items
//= require bootstrap-datepicker

View File

@@ -90,6 +90,13 @@ $(document).ready(function(){
return false;
});
// Discount for Payment
$('#discount').click(function() {
var order_id=$(".selected-item").find(".orders-id").text();
window.location.href = '/origami/discount/'+ order_id
return false;
});
// Payment for Bill
$('#pay').click(function() {
var sale_id=$(".selected-item").find(".orders-id").text();
@@ -98,5 +105,67 @@ $(document).ready(function(){
});
});
/* For Receipt - discount or tax */
$(document).on('click', '.cashier_number', function(event){
if(event.handled !== true) {
var original_value=0;
original_value = $('#discount-amount').val();
var input_type = $(this).attr("data-type");
switch (input_type) {
case 'num':
var input_value = $(this).attr("data-value");
if (original_value == "0.0"){
$('#discount-amount').val(input_value);
update_balance();
}
else{
$('#discount-amount').val(original_value + '' + input_value);
update_balance();
}
break;
case 'add':
var input_value = $(this).attr("data-value");
amount = parseInt(input_value) + parseInt(original_value);
$('#discount-amount').val(amount);
update_balance();
break;
case 'del' :
var discount_text=$('#discount-amount').val();
$('#discount-amount').val(discount_text.substr(0,discount_text.length-1));
update_balance();
break;
case 'clr':
$('#discount-amount').val("0.0");
update_balance();
break;
}
event.handled = true;
} else {
return false;
}
});
function update_balance(){
var discount_type = $('#discount-type').val();
var discount_amount = $('#discount-amount').val();
var sub_total = $('#order-sub-total').text();
var tax = $('#order-Tax').text();
// For Percentage Discount
if(discount_type='1'){
discount-amount=(sub_total*discount-amount)/100;
}
var total = (parseFloat(sub_total) + parseFloat(tax)) - discount_amount;
$('#order-discount').text(discount_amount);
$('#order-grand-total').text(total);
}

View File

@@ -69,3 +69,10 @@
.green{
background-color: #009900
}
/*----- Reset -----*/
select.form-control {
height: inherit !important;
}

View File

@@ -4,10 +4,13 @@ class Crm::CustomersController < ApplicationController
# GET /crm/customers
# GET /crm/customers.json
def index
@crm_customers = Customer.all
@customers = Customer.new
@sale_id = 0
@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 # index.html.erb
format.json { render json: @crm_customers }
@@ -33,15 +36,68 @@ class Crm::CustomersController < ApplicationController
# POST /crm/customers
# POST /crm/customers.json
def create
@crm_customer = Customer.new(customer_params)
@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'
}
)
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"])
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
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 { render :new }
format.json { render json: @crm_customer.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
@@ -49,14 +105,38 @@ 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'
}
)
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
@@ -70,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
@@ -78,6 +175,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

View File

@@ -3,22 +3,38 @@ 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_order
@booking = Booking.find(params[:id])
unique_code="CrmOrderPdf"
print_settings = PrintSetting.find_by_unique_code(unique_code)
printer = Printer::ReceiptPrinter.new(print_settings)
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

@@ -1,6 +1,15 @@
class Origami::DiscountsController < BaseOrigamiController
#discount page show from origami index with selected order
def index
sale_id = params[:id]
if Sale.exists?(sale_id)
@sale_data = Sale.find(sale_id)
end
end
def create
end
end

View File

@@ -1,5 +1,6 @@
class Origami::RequestBillsController < BaseOrigamiController
def print
@sale = Sale.new
sale_order=SaleOrder.new
@@ -25,4 +26,4 @@ class Origami::RequestBillsController < BaseOrigamiController
printer.print_receipt_bill(print_settings,@sale_items,@sale_data,customer_name)
redirect_to origami_root_path
end
end

View File

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

View File

@@ -10,21 +10,26 @@ class Customer < ApplicationRecord
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)
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 lastest_invoices
sales.where(:customer_id => self.id).order("created_at desc").limit(5)
end

View File

@@ -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,setting)
#Use CUPS service
#Generate PDF
#Print
pdf = CrmOrderPdf.new(booking,setting)
pdf.render_file "tmp/print_crm_order.pdf"
self.print("tmp/print_crm_order.pdf")
end
end

View File

@@ -55,8 +55,8 @@ class Sale < ApplicationRecord
generate_receipt_no
order = Order.find(order_id)
#Default - Values
self.tax_type = "execlusive"
#Default Tax - Values
self.tax_type = "exclusive"
self.requested_by = requested_by
self.requested_at = DateTime.now.utc

71
app/pdf/crm_order_pdf.rb Normal file
View File

@@ -0,0 +1,71 @@
class CrmOrderPdf < Prawn::Document
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.type}", :size => 15
stroke_horizontal_rule
move_down 5
#order_info
order_info(order_item.checkin_by,order_item.checkin_at, order_item.customer_id)
# 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
# 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
end

View File

@@ -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 %>
</div>
@@ -17,3 +16,5 @@
<%= f.button :submit %>
</div>
<% end %>
<!-- -->

View File

@@ -1,20 +1,20 @@
<div class="row">
<div class="col-lg-12">
<ol class="breadcrumb">
<li><a href="<%= dashboard_path %>">Home</a></li>
<li><a href="<%= crm_root_path %>">Home</a></li>
<li class="active">
<a href="<%= crm_customers_path %>">Customer</a>
</li>
<a href="<%= new_crm_customer_path%>" class="btn btn-primary pull-right">
<!-- <a href="<%= new_crm_customer_path%>" class="btn btn-primary pull-right">
<i class="fa fa-plus-circle fa-lg"></i> Add Customer
</a>
</a> -->
</ol>
</div>
</div>
<br/>
<div class="row">
<div class="col-lg-7">
<div class="col-lg-8">
<div class="main-box-body clearfix">
<div class="table-responsive">
@@ -22,6 +22,7 @@
<thead>
<tr>
<th>Select</th>
<th>Name</th>
<th>Company</th>
<th>Contact no</th>
@@ -32,10 +33,16 @@
<tbody>
<% @crm_customers.each do |crm_customer| %>
<tr>
<td>
<input type="radio" style="width:20px;" value="<%= crm_customer.customer_id %>" name="checkbox" class="checkbox_check" ></td>
<td><%= crm_customer.name %></td>
<td><%= crm_customer.company %></td>
<td><%= crm_customer.contact_no %></td>
<td><%= crm_customer.email %></td>
<td>
<%= link_to 'Destroy', crm_customer_path(crm_customer), method: :delete, data: { confirm: 'Are you sure?' } %>
</td>
</tr>
<% end %>
@@ -46,55 +53,61 @@
</div>
<div class="col-lg-5">
<%= simple_form_for crm_customers_path, :html => { :class => 'form-horizontal' } do |f| %>
<div class="col-lg-4">
<%= simple_form_for @crm_customer,:url => crm_customers_path, :method => :post do |f| %>
<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">
<%= f.input :name, :class => "form-control col-md-6" %>
</div>
<div class="form-group">
<%= f.input :company, :class => "form-control col-md-6" %>
</div>
<div class="form-group">
<%= f.input :contact_no, :class => "form-control col-md-6" %>
</div>
<div class="form-group">
<%= f.input :email, :class => "form-control col-md-6" %>
</div>
<%= f.input :name, :class => "form-control col-md-6 name" %>
</div>
<div class="form-group">
<label for="date_of_birth" class="col-md-6 control-label">Date Of Birth</label>
<%= f.text_field :date_of_birth,:class=>"form-control datepicker",:readonly =>true, :value => @date_of_birth%>
<%= f.input :company, :class => "form-control col-md-6 company" %>
</div>
<div class="form-group">
<%= f.input :contact_no, :class => "form-control col-md-6 contact_no" %>
</div>
<div class="form-group">
<%= f.input :email, :class => "form-control col-md-6 email" %>
</div>
<div class="form-group">
<label>Date Of Birth</label>
<%= f.text_field :date_of_birth,:class=>"form-control datepicker date_of_birth",:readonly =>true, :value => @date_of_birth%>
</div>
<div class="form-group">
<%= f.select :membership_id, options_for_select(@membership.collect { |member|
[member["id"].name.titleize, member["id"].id] }, 1), {}, { id: 'countries_select' } %>
<select class="selectpicker form-control col-md-6" name="membership_id">
<select class="selectpicker form-control col-md-12" name="membership_id">
<option>Select Member Group</option>
<% @membership.each do |member| %>
<% @member_group.each do |member| %>
<option value="<%= member["id"] %>">
<%= member["name"] %></option>
<%end %>
</select>
</select>
</div>
<div class="form-group">
<%= f.input :membership_type, :class => "form-control col-md-6" %>
<%= f.input :membership_type, :class => "form-control col-md-6 membership_type" %>
</div>
<div class="form-group">
<%= 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" %>
</div>
<div class="form-group">
<%= 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' %>
</div>
<%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) {
@@ -107,4 +120,112 @@
}
});
$(document).on('click',".checkbox_check",function(){
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: url,
data: {},
dataType: "json",
success: function(data) {
$('#customer_id').val(data.id);
$('#customer_name').val(data.name);
$('#customer_company').val(data.company);
$('#customer_contact_no').val(data.contact_no);
$('#customer_email').val(data.email);
$('#customer_date_of_birth').val(data.date_of_birth);
$('#customer_membership_type').val(data.membership_type);
$('.select > option[value="'+data.membership_id+'"]').attr('selected','selected');
$('.membership_authentication_code').val(data.membership_authentication_code);
$('#update_customer').removeAttr('disabled').val('');
$('#update_customer').attr('value', 'Update');
$('#submit_customer').attr('disabled','disabled');
$("#new_customer").attr('class', 'simple_form edit_customer');
var id = "edit_customer_"+$('#customer_id').val();
$("#new_customer").attr('id', id);
$(".edit_customer").attr('action', '/crm/customers/' + $('#customer_id').val());
$(".edit_customer").attr('action', '/crm/customers/' + $('#customer_id').val());
$(".patch_method").append('<input type="hidden" name="_method" value="patch">');
//$(".edit_customer").attr('method', 'PATCH');
}
});
}else{
}
})
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');
}*/
/* $("#update_customer").click(function() {
$("#new_customer").attr('class', 'edit_customer');
var id = "edit_customer_"+$('#customer_id').val();alert(id);
$("#new_customer").attr('id', id);
alert(";;")
//$('#new_customer').removeClass('new_customer');
//$('#new_customer').addClass('edit_customer')
}); */
</script>

View File

@@ -25,10 +25,6 @@
<%= @crm_customer.date_of_birth %>
</p>
<p>
<strong>Membership:</strong>
<%= @crm_customer.membership %>
</p>
<p>
<strong>Membership type:</strong>

View File

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

View File

@@ -4,9 +4,9 @@
<% @i = 0 %>
<% @booking.each do |booking| %>
<% if booking.booking_status == "assign" %>
<% 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%;">
<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 %>
@@ -36,14 +36,21 @@
<script type="text/javascript">
$(function(){
$(".booking_click").on("click", function(){
$(".summary-items tbody tr").remove();
$("#cancel").removeAttr("disabled");
$("#assign").removeAttr("disabled");
$("#crm_print").removeAttr("disabled");
//$("#crm_print").val($(this).attr('data'));
var url = $(this).attr('data-ref');
show_details(url);
});
$('.assign').click(function(e){
var booking_id = $(this).val()
var type = $(this).attr("data-type")
@@ -58,6 +65,7 @@ $(function(){
update_booking(booking_id,type)
});
});
function show_details(url_item){
@@ -97,7 +105,7 @@ function show_details(url_item){
function update_booking(booking_id,type) {
$.ajax({
type: "POST",
url: "crm/update_booking/" ,
url: "update_booking/" ,
data: {booking_id:booking_id,type:type},
dataType: "json",
success: function(data) {

View File

@@ -92,10 +92,37 @@
<!-- Column Three--->
<div class="col-lg-1 col-md-1 col-sm-1">
<!-- OQS Buttons -->
<button type="button" class="btn btn-primary btn-lg btn-block" disabled>Print</button>
<button type="button" class="btn btn-primary btn-lg btn-block" disabled>Print <br/>Order<br/>Summary</button>
<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 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>
</div>
</div>
<script type="text/javascript">
$( document ).ready(function() {
$('.crm_print').click(function() {
var id = "BKI-000000000004"
$.ajax({
type: "GET",
url: "crm/print/"+id,
data: {},
dataType: "json",
success: function(data) {
/*if(data.status == true && data.type == "cancel")
{
alert('Booking has canceled!');
}else{
alert('Booking has completed!');
}
location.reload();*/
}
});
});
});
</script>

View File

@@ -17,7 +17,7 @@
<%= render 'layouts/header_crm' %>
<div class="container-fluid">
<% flash.each do |type, message| %>
<div class="alert fade in">
<div class="alert-danger fade in">
<button class="close" aria-hidden="true" data-dismiss="alert" type="button">×</button>
<%= message %>
</div>

View File

@@ -0,0 +1,174 @@
<div class="row">
<!-- Column One -->
<div class="col-lg-6 col-md-6 col-sm-6">
<!-- Order Details -->
<div class="card" >
<div class="card-header">
<div><strong id="order-title">ORDER DETAILS -</strong></div>
</div>
<div class="card-block">
<div class="card-title row">
<div class="col-lg-6 col-md-6 col-sm-6">
<p>Receipt No: <span id="receipt_no"><%=@sale_data.receipt_no rescue ' '%></span></p>
<p>Cashier: <span id="cashier"><%=@sale_data.cashier_name rescue ' '%></span></p>
</div>
<div class="col-lg-6 col-md-6 col-sm-6 text-right">
<p>Date: <span id="receipt_date"> <%=@sale_data.receipt_date.strftime("%d/%m/%Y - %I:%M %p") rescue '-'%></span></p>
</div>
</div>
<div class="card-text">
<table class="table table-striped" id="order-items-table">
<thead>
<tr>
<th class="item-name">Items</th>
<th class="item-attr">QTY</td>
<th class="item-attr">Price</td>
</tr>
</thead>
<tbody>
<% sub_total = 0 %>
<% @sale_data.sale_items.each do |sale_item| %>
<% sub_total += sale_item.qty*sale_item.unit_price%>
<tr>
<td style="width:60%; text-align:left">
<span id="item-name-price"><%=sale_item.product_name%>@<%=sale_item.unit_price%></span>
</td>
<td style="width:20%; text-align:right">
<span id="item-qty"><%=sale_item.qty%></span>
</td>
<td style="width:20%; text-align:right">
<span id="item-total-price"><%=(sale_item.qty*sale_item.unit_price)%></span>
</td>
</tr>
<%end %>
</tbody>
</table>
</div>
<div class="card-footer">
<table class="table" id="order-charges-table" border="0">
<tr>
<td class="charges-name"><strong>Sub Total:</strong></td>
<td class="item-attr"><strong id="order-sub-total"><%=sub_total%></strong></td>
</tr>
<tr>
<td class="charges-name"><strong>Food:</strong></td>
<td class="item-attr"><strong id="order-food"></strong></td>
</tr>
<tr>
<td class="charges-name"><strong>Beverage:</strong></td>
<td class="item-attr"><strong id="order-beverage"></strong></td>
</tr>
<tr>
<td class="charges-name"><strong>Discount:</strong></td>
<td class="item-attr"><strong id="order-discount">(<%=@sale_data.total_discount rescue 0%>)</strong></td>
</tr>
<tr>
<td class="charges-name"><strong>Tax:</strong></td>
<td class="item-attr"><strong id="order-Tax"><%=@sale_data.total_tax rescue 0%></strong></td>
</tr>
<tr>
<td class="charges-name"><strong>Grand Total:</strong></td>
<td class="item-attr"><strong id="order-grand-total"><%=@sale_data.grand_total rescue 0%></strong></td>
</tr>
</table>
</div>
</div>
</div>
</div>
<!-- Column One -->
<!-- Column Two -->
<div class="col-lg-6 col-md-6 col-sm-6">
<!-- Discount Amount -->
<div class="card row">
<div class="card-header">
<div><strong id="order-title">Pay Discount</strong></div>
</div>
<div class="card-block">
<div class="card-title">
<form class="form-horizontal">
<div class="form-group">
<div class="col-md-3">
<select name="discount_type" id="discount-type" class="form-control">
<option val=0 >Net</option>
<option val=1 >Percentage</option>
</select>
</div>
<div class="col-md-9">
<input type="text" id="discount-amount" name="discount-amount" value="<%= @sale_data.total_discount rescue 0 %>" class="form-control" />
</div>
</div>
<button id="pay-discount" class="btn btn-primary long">Discount</button>
</form>
</div>
<div class="col-md-12">
<div class="row">
<div class="col-md-7">
<div class="row">
<div class="col-md-3 cashier_number" data-value="1" data-type="num">1</div>
<div class="col-md-3 cashier_number" data-value="2" data-type="num">2</div>
<div class="col-md-3 cashier_number" data-value="3" data-type="num">3</div>
</div>
</div>
<div class="col-md-5">
<div class="col-md-12 cashier_number long" data-value="500" data-type="add">500</div>
</div>
</div>
<div class="row">
<div class="col-md-7">
<div class="row">
<div class="col-md-3 cashier_number" data-value="4" data-type="num">4</div>
<div class="col-md-3 cashier_number" data-value="5" data-type="num">5</div>
<div class="col-md-3 cashier_number" data-value="6" data-type="num">6</div>
</div>
</div>
<div class="col-md-5">
<div class="col-md-12 cashier_number long" data-value="1000" data-type="add">1000</div>
</div>
</div>
<div class="row">
<div class="col-md-7">
<div class="row">
<div class="col-md-3 cashier_number" data-value="7" data-type="num">7</div>
<div class="col-md-3 cashier_number" data-value="8" data-type="num">8</div>
<div class="col-md-3 cashier_number" data-value="9" data-type="num">9</div>
</div>
</div>
<div class="col-md-5">
<div class="col-md-12 cashier_number long" data-value="5000" data-type="add">5000</div>
</div>
</div>
<div class="row">
<div class="col-md-7">
<div class="row">
<div class="col-md-3 cashier_number" data-value="0" data-type="num">0</div>
<div class="col-md-3 cashier_number" data-value="." data-type="num">.</div>
<div class="col-md-3 cashier_number" data-value="00" data-type="num">00</div>
</div>
</div>
<div class="col-md-5">
<div class="col-md-12 cashier_number long" data-value="10000" data-type="add">10000</div>
</div>
</div>
<div class="row">
<div class="col-md-7">
<div class="row">
<div class="col-md-3 cashier_number"></div>
<div class="col-md-3 cashier_number red" data-type="del">DEL</div>
<div class="col-md-3 cashier_number green" data-type="clr">CLR</div>
</div>
</div>
<div class="col-md-5">
<div class="col-md-12 cashier_number long" data-value="50000" data-type="add">50000</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

View File

@@ -1,6 +1,6 @@
<div class="row">
<!-- Column One -->
<div class="col-lg-6 col-md-6 col-sm-8">
<div class="col-lg-6 col-md-6 col-sm-6">
<!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist">
@@ -206,20 +206,162 @@
</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>
<button type="button" id="discount" class="btn btn-primary btn-lg btn-block">Discount</button>
<button type="button" class="btn btn-primary btn-lg btn-block">Tax</button>
<button type="button" id="pay" class="btn btn-primary btn-lg btn-block" >Pay</button>
<button type="button" class="btn btn-primary btn-lg btn-block" disabled>Re.Print</button>
</div>
</div>
<script>
var old_order_id = 0
var old_table_name = ""
var table_or_order_id = 0
var pay_sale_id = 0
function callOrderDetails(sale_order_id){
var order_id = 0
var sale_id = 0
var data_val = ""
sale_order = sale_order_id.split("_")[0]
if (sale_order == 'sale') {
order_id = sale_order_id.split("_")[1]
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]
url = "origami/"+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
pay_sale_id = sale_id
alert(table_or_order_id)
var tbody = ""
$("#append-table").html("")
if (old_order_id != order_id){
$("#table-order-"+old_order_id).removeClass("selected_color")
$("#table-order-"+order_id).addClass("selected_color")
old_order_id = order_id
}
$("#order-detail-header").html("")
$("#order-detail-header").append("Table Name : "+document.getElementById("table-name-"+order_id).innerHTML)
$("#sub-total").html("")
$.ajax({type: "GET",
url: url,
data: data_val,
success:function(result){
var sub_total = 0
var discount_amount = 0
var receipt_no = ""
var cashier_name = ""
var receipt_date = ""
var tax_amount = 0
var grand_total_amount = 0
row = "<tbody>"
for (i = 0; i < result.length; i++) {
var data = JSON.stringify(result[i]);
var parse_data = JSON.parse(data)
sub_total += (parse_data.qty*parse_data.price)
row = '<tr><td style="width:60%; text-align:left"><span id="item-name-price">'+parse_data.item_name+"@"+(parse_data.price*1)+'</span></td>'
+'<td style="width:20%; text-align:right"><span id="item-qty">'+(parse_data.qty*1)+'</span></td>s'
+'<td style="width:20%; text-align:right"><span id="item-total-price">'+(parse_data.qty*parse_data.price)+'</span></td>'
+'</tr>>'
tbody += row
discount_amount = result[i].discount_amount;
tax_amount = result[i].tax_amount;
grand_total_amount = result[i].grand_total_amount;
receipt_no = result[i].receipt_no;
cashier_name = result[i].cashier_name;
receipt_date = result[i].receipt_date;
}
row = "</tbody>"
$("#append-table").append(tbody)
$("#sub-total").append((sub_total)+"<br/>")
if (discount_amount > 0 ) {
$("#discount-header").html("(Discount)")
$("#discount_amount").html("("+discount_amount+")")
}
if (tax_amount > 0 ) {
$("#tax-header").html("Tax")
$("#tax_amount").html(tax_amount)
}
if (grand_total_amount > 0 ) {
$("#grand-total-header").html("Grand Total")
$("#grand_total_amount").html(grand_total_amount)
}
if (cashier_name == null){
cashier_name = ""
}
if(receipt_no != null){
$("#receipt-no").html("Receipt No : "+receipt_no)
}
if (receipt_date != null) {
$("#receipt-date").html("Receipt Date : "+receipt_date);
}
if (cashier_name != null) {
$("#cashier-name").html("Cashier Name : "+cashier_name);
}
},
error:function(result){
// alert('error');
}
});
}
$( document ).ready(function() {
$('#request_bills').click(function() {
window.location.href = '/origami/request_bills/'+ table_or_order_id
return false;
});
$('#pay').click(function() {
window.location.href = '/origami/sale/'+ pay_sale_id + "/payment"
return false;
});
$('#customer').click(function() {
var sale_id = $(this).val();
window.location.href = '/crm/customers/'+ sale_id + "/assign_sale_id"
return false;
});
});
</script>
<style type="text/css">
.selected_color{
color:white;
background-color: blue;
}
</style>

View File

@@ -77,12 +77,12 @@ Rails.application.routes.draw do
get "/request_bills/:id" => "request_bills#print"
get "/discount/:id" => "discounts#index"
#--------- Payment ------------#
get 'sale/:sale_id/payment' => 'payments#show'
post 'payment_process' => 'payments#create'
post 'paypar_payment_process' => 'paypar_payments#create'
get 'sale/:sale_id/payment/credit_payment' => "credit_payments#index"
get 'sale/:sale_id/payment/others_payment' => "others_payments#index"
@@ -98,12 +98,12 @@ Rails.application.routes.draw do
#--------- Customer Relationship Management ------------#
namespace :crm do
root "home#index" #queue number
#customers
get 'customers/:sale_id/assign_sale_id', to: "customers#get_sale_id", :as => "assign_sale"#get sale id with customer for crm
resources :customers
#membership
#bookings
post "update_booking" , to: "bookings#update_booking", as: "update_booking"
#queue
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 ------------#

View File

@@ -1,10 +0,0 @@
class CreateAccounts < ActiveRecord::Migration[5.1]
def change
create_table :accounts do |t|
t.string :title
t.string :account_type
t.timestamps
end
end
end