order item split bill process
This commit is contained in:
@@ -103,6 +103,8 @@ Change type in mysql
|
|||||||
=> ALTER TABLE [table_name] CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci #for table
|
=> ALTER TABLE [table_name] CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci #for table
|
||||||
=> ALTER DATABASE [database_name] CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci #for database
|
=> ALTER DATABASE [database_name] CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci #for database
|
||||||
|
|
||||||
|
For split bill
|
||||||
|
1) settings/lookups => { type:split_bill, name:SplitBill, value:1 }
|
||||||
|
|
||||||
* ToDo list
|
* ToDo list
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ class Api::BillController < Api::ApiController
|
|||||||
def create
|
def create
|
||||||
@status = false
|
@status = false
|
||||||
@error_message = "Order ID or Booking ID is require to request for a bill."
|
@error_message = "Order ID or Booking ID is require to request for a bill."
|
||||||
|
byebug
|
||||||
if shift_by_terminal = ShiftSale.current_open_shift(get_cashier[0].id)
|
if shift_by_terminal = ShiftSale.current_open_shift(get_cashier[0].id)
|
||||||
#create Bill by Booking ID
|
#create Bill by Booking ID
|
||||||
table = 0
|
table = 0
|
||||||
|
|||||||
@@ -18,4 +18,9 @@ class BaseOrigamiController < ActionController::Base
|
|||||||
# def checkin_process
|
# def checkin_process
|
||||||
# CheckinJob.set(wait: 1.minute).perform_later()
|
# CheckinJob.set(wait: 1.minute).perform_later()
|
||||||
# end
|
# end
|
||||||
|
|
||||||
|
# Get current Cashier
|
||||||
|
def get_cashier
|
||||||
|
@cashier = Employee.where("role = 'cashier' AND token_session <> ''")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -88,6 +88,12 @@ class Origami::HomeController < BaseOrigamiController
|
|||||||
#for bank integration
|
#for bank integration
|
||||||
@checkout_time = Lookup.collection_of('checkout_time')
|
@checkout_time = Lookup.collection_of('checkout_time')
|
||||||
@checkout_alert_time = Lookup.collection_of('checkout_alert_time')
|
@checkout_alert_time = Lookup.collection_of('checkout_alert_time')
|
||||||
|
#for split bill
|
||||||
|
lookup_spit_bill = Lookup.collection_of('split_bill')
|
||||||
|
@spit_bill = 0
|
||||||
|
if !lookup_spit_bill[0].nil?
|
||||||
|
@spit_bill = lookup_spit_bill[0][1]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
class Origami::SplitBillController < BaseOrigamiController
|
class Origami::SplitBillController < BaseOrigamiController
|
||||||
|
authorize_resource :class => false
|
||||||
|
|
||||||
def index
|
def index
|
||||||
dining_id = params[:dining_id]
|
dining_id = params[:dining_id]
|
||||||
@@ -18,4 +19,54 @@ class Origami::SplitBillController < BaseOrigamiController
|
|||||||
@booking = nil
|
@booking = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
order_items = JSON.parse(params[:order_items])
|
||||||
|
# byebug
|
||||||
|
status = false
|
||||||
|
if shift_by_terminal = ShiftSale.current_open_shift(get_cashier[0].id)
|
||||||
|
#create Bill by Booking ID
|
||||||
|
table = 0
|
||||||
|
if !params[:booking_id].empty?
|
||||||
|
booking = Booking.find(params[:booking_id])
|
||||||
|
# for Multiple Cashier by Zone
|
||||||
|
table = DiningFacility.find(booking.dining_facility_id)
|
||||||
|
|
||||||
|
cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id)
|
||||||
|
|
||||||
|
shift_by_terminal = ShiftSale.find_by_cashier_terminal_id_and_shift_closed_at(cashier_zone.cashier_terminal_id,nil)
|
||||||
|
get_cashier_by_terminal = Employee.find(shift_by_terminal.employee_id)
|
||||||
|
|
||||||
|
if booking
|
||||||
|
if booking.sale_id.nil?
|
||||||
|
sale = Sale.new
|
||||||
|
status, sale_id = sale.generate_invoice_from_booking(params[:booking_id], current_user, get_cashier_by_terminal)
|
||||||
|
sale_data = Sale.find_by_sale_id(sale_id)
|
||||||
|
else
|
||||||
|
status = true
|
||||||
|
sale_id = booking.sale_id
|
||||||
|
sale_data = Sale.find_by_sale_id(sale_id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
puts "new booking"
|
||||||
|
puts "new order"
|
||||||
|
puts "update order_id in order"
|
||||||
|
puts "do process"
|
||||||
|
end
|
||||||
|
|
||||||
|
# Bind shift sale id to sale
|
||||||
|
sale_data.shift_sale_id = shift_by_terminal.id
|
||||||
|
sale_data.save
|
||||||
|
|
||||||
|
Promotion.promo_activate(sale)
|
||||||
|
|
||||||
|
BillBroadcastJob.perform_later(table)
|
||||||
|
|
||||||
|
render :json => { status: status }
|
||||||
|
else
|
||||||
|
render :json => { status: false, error_message: 'No Current Open Shift!'}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -133,6 +133,10 @@ class Ability
|
|||||||
can :manage, Promotion
|
can :manage, Promotion
|
||||||
can :manage, Product
|
can :manage, Product
|
||||||
|
|
||||||
|
#ability for split_bill
|
||||||
|
can :index, :split_bill
|
||||||
|
can :create, :split_bill
|
||||||
|
|
||||||
elsif user.role == "account"
|
elsif user.role == "account"
|
||||||
|
|
||||||
can :index, :dailysale
|
can :index, :dailysale
|
||||||
|
|||||||
@@ -672,6 +672,8 @@
|
|||||||
|
|
||||||
// Bill Request
|
// Bill Request
|
||||||
$('#request_bills').click(function () {
|
$('#request_bills').click(function () {
|
||||||
|
var lookup_split_bill = '<%= @spit_bill %>';
|
||||||
|
if(lookup_split_bill == '1'){
|
||||||
swal({
|
swal({
|
||||||
title: "Alert",
|
title: "Alert",
|
||||||
text: "Do you want to Split bill?",
|
text: "Do you want to Split bill?",
|
||||||
@@ -685,6 +687,15 @@
|
|||||||
var dining_id = "<%= @dining.id %>";
|
var dining_id = "<%= @dining.id %>";
|
||||||
window.location.href = '/origami/table/' + dining_id + "/split_bills";
|
window.location.href = '/origami/table/' + dining_id + "/split_bills";
|
||||||
}else{
|
}else{
|
||||||
|
requestBillProcess();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}else{
|
||||||
|
requestBillProcess();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function requestBillProcess(){
|
||||||
var order_id = $('#save_order_id').attr('data-order');
|
var order_id = $('#save_order_id').attr('data-order');
|
||||||
var ajax_url = "/origami/" + order_id + "/request_bills";
|
var ajax_url = "/origami/" + order_id + "/request_bills";
|
||||||
$.ajax({
|
$.ajax({
|
||||||
@@ -701,8 +712,6 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#move').on('click', function () {
|
$('#move').on('click', function () {
|
||||||
var dining_id = "<%= @dining.id %>";
|
var dining_id = "<%= @dining.id %>";
|
||||||
|
|||||||
@@ -39,20 +39,35 @@
|
|||||||
<div class="card-columns" style="padding-top:10px; column-gap: 1.2rem;">
|
<div class="card-columns" style="padding-top:10px; column-gap: 1.2rem;">
|
||||||
<% @tables.each do |table| %>
|
<% @tables.each do |table| %>
|
||||||
<% if table.status == 'occupied' %>
|
<% if table.status == 'occupied' %>
|
||||||
<div class="card tables red text-white table_<%= table.id %>" data-id="<%= table.id %>">
|
|
||||||
<div class="card-block">
|
|
||||||
<%= table.name %>
|
|
||||||
<% if table.get_booking.nil? %>
|
<% if table.get_booking.nil? %>
|
||||||
<span style="font-size:12px;float:right;line-height:inherit;"> billed</span>
|
<% if table.get_checkout_booking.nil? %>
|
||||||
|
<div class="card tables red text-white table_<%= table.id %>" data-id="<%= table.id %>">
|
||||||
<% else %>
|
<% else %>
|
||||||
<span style="font-size:12px;float:right;line-height:inherit;"> new</span>
|
<div class="card tables orange text-white table_<%= table.id %>" data-id="<%= table.id %>">
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<% else %>
|
|
||||||
<div class="card tables green text-white" data-id="<%= table.id %>">
|
|
||||||
<div class="card-block">
|
<div class="card-block">
|
||||||
<%= table.name %>
|
<%= table.name %>
|
||||||
|
<span class="float-right font-12 new_text_<%= table.id %>"> billed</span>
|
||||||
|
<div style="font-size:12px;"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<% else %>
|
||||||
|
<% if table.get_checkout_booking.nil? %>
|
||||||
|
<div class="card tables blue text-white table_<%= table.id %>" data-id="<%= table.id %>">
|
||||||
|
<% else %>
|
||||||
|
<div class="card tables orange text-white table_<%= table.id %>" data-id="<%= table.id %>">
|
||||||
|
<% end %>
|
||||||
|
<div class="card-block">
|
||||||
|
<%= table.name %>
|
||||||
|
<span class="float-right font-12 new_text_<%= table.id %>"> new</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
<% else %>
|
||||||
|
<div class="card tables green text-white table_<%= table.id %>" data-id="<%= table.id %>">
|
||||||
|
<div class="card-block">
|
||||||
|
<%= table.name %>
|
||||||
|
<span class="float-right font-12 new_text_<%= table.id %> hide"> new</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
@@ -65,20 +80,26 @@
|
|||||||
<div class="card-columns" style="padding-top:10px; column-gap: 1.2rem;">
|
<div class="card-columns" style="padding-top:10px; column-gap: 1.2rem;">
|
||||||
<% @rooms.each do |room| %>
|
<% @rooms.each do |room| %>
|
||||||
<% if room.status == 'occupied' %>
|
<% if room.status == 'occupied' %>
|
||||||
<div class="card rooms red text-white" data-id="<%= room.id %>">
|
|
||||||
<div class="card-block">
|
|
||||||
<%= room.name %>
|
|
||||||
<% if room.get_booking.nil? %>
|
<% if room.get_booking.nil? %>
|
||||||
<span style="font-size:12px;float:right;line-height:inherit;"> billed</span>
|
<div class="card rooms red text-white table_<%= room.id %>" data-id="<%= room.id %>">
|
||||||
<% else %>
|
|
||||||
<span style="font-size:12px;float:right;line-height:inherit;"> new</span>
|
|
||||||
<% end %>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<% else %>
|
|
||||||
<div class="card rooms green text-white" data-id="<%= room.id %>">
|
|
||||||
<div class="card-block">
|
<div class="card-block">
|
||||||
<%= room.name %>
|
<%= room.name %>
|
||||||
|
<span class="float-right font-12 new_text_<%= room.id %>"> billed</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<% else %>
|
||||||
|
<div class="card rooms blue text-white table_<%= room.id %>" data-id="<%= room.id %>">
|
||||||
|
<div class="card-block">
|
||||||
|
<%= room.name %>
|
||||||
|
<span class="float-right font-12 new_text_<%= room.id %>"> new</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
<% else %>
|
||||||
|
<div class="card rooms green text-white table_<%= room.id %>" data-id="<%= room.id %>">
|
||||||
|
<div class="card-block">
|
||||||
|
<%= room.name %>
|
||||||
|
<span class="float-right font-12 new_text_<%= room.id %> hide">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<!-- Column One -->
|
<!-- Column One -->
|
||||||
<div class="col-lg-6 col-md-6 col-sm-6">
|
<div class="col-lg-8 col-md-8 col-sm-8">
|
||||||
<!-- Order Details -->
|
<!-- Order Details -->
|
||||||
<div class="card" >
|
<div class="card" >
|
||||||
<!-- <div class="card-header">
|
<!-- <div class="card-header">
|
||||||
@@ -40,7 +40,7 @@
|
|||||||
<tr class="item-row" id=<%= order_item.order_items_id %> >
|
<tr class="item-row" id=<%= order_item.order_items_id %> >
|
||||||
<td style="width:60%; text-align:left">
|
<td style="width:60%; text-align:left">
|
||||||
<span id="item-account-type" class="hidden"><%=order_item.account_id%></span>
|
<span id="item-account-type" class="hidden"><%=order_item.account_id%></span>
|
||||||
<span id="item-name-price"><%=order_item.item_name%>@<%=order_item.price%></span>
|
<span id="item-name-price"><%=order_item.item_name%></span>
|
||||||
</td>
|
</td>
|
||||||
<td style="width:20%; text-align:right">
|
<td style="width:20%; text-align:right">
|
||||||
<span id="item-qty"><%=order_item.qty%></span>
|
<span id="item-qty"><%=order_item.qty%></span>
|
||||||
@@ -68,75 +68,14 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!-- Column One -->
|
<!-- Column One -->
|
||||||
|
<div class="col-lg-3 col-md-3 col-sm-3 clearfix"></div>
|
||||||
<!-- Column Two -->
|
<!-- Column Two -->
|
||||||
<div class="col-lg-5 col-md-5 col-sm-5">
|
|
||||||
<!-- Discount Amount -->
|
|
||||||
<div class="card">
|
|
||||||
<div class="card-header">
|
|
||||||
<div><strong id="order-title">Split Bill Control</strong></div>
|
|
||||||
</div>
|
|
||||||
<div class="card-block">
|
|
||||||
<div class="card-title">
|
|
||||||
<div class="form-horizontal">
|
|
||||||
<div class="col-md-12">
|
|
||||||
<div class="form-group">
|
|
||||||
<input type="text" id="per_person" name="per_person" value="" class="form-control" placeholder="Bill per person" onkeypress="return isNumberKey(event);" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<hr />
|
|
||||||
|
|
||||||
<div class="m-t-10 p-l-20">
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-lg-8 col-md-8 col-sm-8">
|
|
||||||
<div class="row bottom">
|
|
||||||
<div class="col-md-3 cashier_number border-left" data-value="1" data-type="num">1</div>
|
|
||||||
<div class="col-md-3 left cashier_number border-left" data-value="2" data-type="num">2</div>
|
|
||||||
<div class="col-md-3 left cashier_number border-left" data-value="3" data-type="num">3</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row bottom">
|
|
||||||
<div class="col-md-3 cashier_number border-left" data-value="4" data-type="num">4</div>
|
|
||||||
<div class="col-md-3 left cashier_number border-left" data-value="5" data-type="num">5</div>
|
|
||||||
<div class="col-md-3 left cashier_number border-left" data-value="6" data-type="num">6</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row bottom">
|
|
||||||
<div class="col-md-3 cashier_number border-left" data-value="7" data-type="num">7</div>
|
|
||||||
<div class="col-md-3 left cashier_number border-left" data-value="8" data-type="num">8</div>
|
|
||||||
<div class="col-md-3 left cashier_number border-left" data-value="9" data-type="num">9</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row bottom">
|
|
||||||
<div class="col-md-3 cashier_number border-left" data-value="0" data-type="num">0</div>
|
|
||||||
<div class="col-md-3 left cashier_number red border-left" data-type="del">DEL</div>
|
|
||||||
<div class="col-md-3 left cashier_number green border-left" data-type="clr">CLR</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="col-md-4">
|
|
||||||
<div class="form-group">
|
|
||||||
<button id="net" class="btn bg-info fluid action-btn">Order Item Split</button>
|
|
||||||
<button id="percentage" class="btn bg-primary fluid action-btn" style="font-size: 12.4px">Per Person</button>
|
|
||||||
<button id="remove-item" class="btn bg-default fluid action-btn">Clear Split Bill</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Column Three -->
|
|
||||||
<div class="col-lg-1 col-md-1 col-sm-1">
|
<div class="col-lg-1 col-md-1 col-sm-1">
|
||||||
<!-- Action Panel -->
|
<!-- Action Panel -->
|
||||||
<div>
|
<div>
|
||||||
<button type="button" class="btn bg-default btn-block" id="back" ><i class="material-icons">reply</i> Back </button>
|
<button type="button" class="btn bg-default btn-block" id="back" ><i class="material-icons">reply</i> Back </button>
|
||||||
<button id="remove-item-discount" class="btn btn-primary btn- action-btn">Remove Item Split</button>
|
<button id="order_item_split" class="btn btn-primary btn- action-btn">Order Items Split</button>
|
||||||
<button id="remove-all" class="btn bg-primary btn-block action-btn">Remove All</button>
|
<!-- <button id="per_person" class="btn bg-primary btn-block action-btn">Per Person</button> -->
|
||||||
<button id="pay-discount" class="btn bg-primary btn-block action-btn">Enter</button>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -146,13 +85,7 @@
|
|||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
|
|
||||||
$('#back').on('click',function(){
|
$('#back').on('click',function(){
|
||||||
var id = $("#table_id").text();
|
backToOrigami();
|
||||||
var type = $("#table_type").text();
|
|
||||||
if (type=="Table") {
|
|
||||||
window.location.href = '/origami/table/'+id
|
|
||||||
}else{
|
|
||||||
window.location.href = '/origami/room/'+id
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
$(".cashier_number").on('click', function(event){
|
$(".cashier_number").on('click', function(event){
|
||||||
@@ -202,327 +135,99 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Select discount-item
|
//order_item_split
|
||||||
$('#order-items-table tbody').on('click', '.discount-item-row',function(){
|
$('#order_item_split').on('click',function () {
|
||||||
if($(this).hasClass('selected-item') == true){
|
var cnt_order_item = "<%= @order_items.count %>";
|
||||||
$(this).removeClass('selected-item');
|
var order_items = get_selected_order_items();// Selected Order Items
|
||||||
|
var cnt_items = parseInt(cnt_order_item) - parseInt(order_items.length);
|
||||||
|
if (order_items.length > 0){
|
||||||
|
if(cnt_items > 0){
|
||||||
|
swal({
|
||||||
|
title: "Alert",
|
||||||
|
text: "Are you sure, you want to Split?",
|
||||||
|
type: "warning",
|
||||||
|
showCancelButton: true,
|
||||||
|
confirmButtonColor: "#DD6B55",
|
||||||
|
confirmButtonText: "Yes, split it!",
|
||||||
|
closeOnConfirm: false
|
||||||
|
}, function (isConfirm) {
|
||||||
|
if(isConfirm){
|
||||||
|
splitBillProcess(cnt_items);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
$(this).addClass('selected-item');
|
splitBillProcess(cnt_items);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
swal("Opps","Please select at least on item!","warning");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Calculate Net Discount for Payment
|
|
||||||
$("#net").on('click', function(e){
|
|
||||||
e.preventDefault();
|
|
||||||
var sale_id = $('#sale-id').text();
|
|
||||||
var discount_value = parseFloat($('#discount-amount').val());
|
|
||||||
var ajax_url = "/origami/" + sale_id + "/discount";
|
|
||||||
|
|
||||||
// Selected Items
|
|
||||||
var sale_items = get_selected_sale_items();
|
|
||||||
|
|
||||||
// Selected Account
|
|
||||||
var account_types = get_selected_account_types();
|
|
||||||
|
|
||||||
if(sale_items.length == 0 && account_types.length == 0){
|
|
||||||
calculate_overall_discount(0, discount_value);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
calculate_item_discount(0, discount_value, sale_items, account_types);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove Selection
|
|
||||||
selection_remove();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Calculate Percentage Discount for Payment
|
/* function for split bill process */
|
||||||
$("#percentage").on('click', function(e){
|
function splitBillProcess(cnt_items){
|
||||||
e.preventDefault();
|
var order_items = get_selected_order_items();// Selected Order Items
|
||||||
var sale_id = $('#sale-id').text();
|
var json_booking = JSON.parse('<%= @booking.to_json.html_safe %>');
|
||||||
var discount_value = $('#discount-amount').val();
|
var booking_id = "";
|
||||||
var ajax_url = "/origami/" + sale_id + "/discount";
|
if(cnt_items == 0){
|
||||||
|
booking_id = json_booking.booking_id;
|
||||||
// Selected Items
|
|
||||||
var sale_items = get_selected_sale_items();
|
|
||||||
|
|
||||||
// Selected Account
|
|
||||||
var account_types = get_selected_account_types();
|
|
||||||
|
|
||||||
if(sale_items.length == 0 && account_types.length == 0){
|
|
||||||
calculate_overall_discount(1, discount_value);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
calculate_item_discount(1, discount_value, sale_items, account_types);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove Selection
|
var ajax_url = "/origami/split_bills";
|
||||||
selection_remove();
|
|
||||||
});
|
|
||||||
|
|
||||||
// Remove selected discount items
|
|
||||||
$("#remove-item").on('click', function(e){
|
|
||||||
e.preventDefault();
|
|
||||||
var origin_sub_total = parseFloat($("#order-sub-total").text());
|
|
||||||
var total = 0;
|
|
||||||
|
|
||||||
$('.discount-item-row.selected-item').each(function(i){
|
|
||||||
var amount = parseFloat($(this).find('#item-total-price').text());
|
|
||||||
total = total + Math.abs(amount);
|
|
||||||
$(this).remove();
|
|
||||||
});
|
|
||||||
$("#order-sub-total").text(origin_sub_total + total);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Pay Discount for Payment
|
|
||||||
$("#pay-discount").on('click', function(e){
|
|
||||||
e.preventDefault();
|
|
||||||
$("#loading_wrapper").show();
|
|
||||||
var sale_id = $('#sale-id').text();
|
|
||||||
var discount_items = JSON.stringify(get_discount_item_rows());
|
|
||||||
var overall_discount = $("#order-discount").text();
|
|
||||||
var sub_total = $('#order-sub-total').text();
|
|
||||||
var ajax_url = "/origami/" + sale_id + "/discount";
|
|
||||||
|
|
||||||
var params = { 'sale_id': sale_id, 'sub_total': sub_total, 'discount_items': discount_items, 'overall_discount': overall_discount };
|
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "POST",
|
type: "POST",
|
||||||
url: ajax_url,
|
url: ajax_url,
|
||||||
data: params,
|
dataType: 'JSON',
|
||||||
|
data: {'booking_id' : booking_id, 'order_items' : JSON.stringify(order_items)},
|
||||||
success: function (result) {
|
success: function (result) {
|
||||||
$("#loading_wrapper").hide();
|
if (!result.status) {
|
||||||
swal({
|
swal("Information!", result.error_message);
|
||||||
title: "Information!",
|
|
||||||
text: result.status,
|
|
||||||
}, function () {
|
|
||||||
if(result.table_type == "Table"){
|
|
||||||
window.location.href = "/origami/table/" + result.table_id
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
window.location.href = "/origami/room/" + result.table_id
|
if (cnt_items > 0){
|
||||||
|
window.location.reload();
|
||||||
|
}else{
|
||||||
|
backToOrigami();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Remove selected given discount item
|
|
||||||
$("#remove-item-discount").on('click', function(e){
|
|
||||||
e.preventDefault();
|
|
||||||
var sale_id = $('#sale-id').text();
|
|
||||||
var discount_items = [];
|
|
||||||
|
|
||||||
// Selected Items
|
|
||||||
var sale_items = get_selected_sale_items();
|
|
||||||
console.log(sale_items.length);
|
|
||||||
if(sale_items.length == 0){
|
|
||||||
//swal("Information!", "You have no selected item!");
|
|
||||||
swal ( "Oops" , "You have no selected item!" , "error" );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(var i=0;i < sale_items.length;i++){
|
/* back to origami */
|
||||||
if(sale_items[i].price < 0){
|
function backToOrigami(){
|
||||||
discount_items.push(sale_items[i]);
|
var id = $("#table_id").text();
|
||||||
|
var type = $("#table_type").text();
|
||||||
|
if (type=="Table") {
|
||||||
|
window.location.href = '/origami/table/'+id
|
||||||
|
}else{
|
||||||
|
window.location.href = '/origami/room/'+id
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
swal ("Oops" , "You have no selected item!" , "error" );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var params = { 'sale_id': sale_id, 'discount_items': JSON.stringify(discount_items) };
|
|
||||||
$.ajax({
|
|
||||||
type: "POST",
|
|
||||||
url: "/origami/" + sale_id + "/remove_discount_items",
|
|
||||||
data: params,
|
|
||||||
success: function(result){
|
|
||||||
swal({
|
|
||||||
title: "Information!",
|
|
||||||
text: result.status,
|
|
||||||
type: "success",
|
|
||||||
}, function () {
|
|
||||||
if(result.table_type == "Table"){
|
|
||||||
window.location.href = "/origami/table/" + result.table_id
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
window.location.href = "/origami/room/" + result.table_id
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
$("#remove-all").on('click', function(e){
|
|
||||||
e.preventDefault();
|
|
||||||
var sale_id = $('#sale-id').text();
|
|
||||||
$.ajax({
|
|
||||||
type: "GET",
|
|
||||||
url: "/origami/" + sale_id + "/remove_all_discount",
|
|
||||||
success: function(result){
|
|
||||||
swal({
|
|
||||||
title: "Information!",
|
|
||||||
text: result.status,
|
|
||||||
type: "success",
|
|
||||||
}, function () {
|
|
||||||
if(result.table_type == "Table"){
|
|
||||||
window.location.href = "/origami/table/" + result.table_id
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
window.location.href = "/origami/room/" + result.table_id
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
/* Remove Selection */
|
|
||||||
function selection_remove(){
|
|
||||||
$(".item-row").removeClass("selected-item");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Get Item rows but not discount*/
|
|
||||||
function get_item_rows(){
|
|
||||||
var sale_items = [];
|
|
||||||
$('.item-row').not('.discount-item-row').each(function(i){
|
|
||||||
var sale_item = {};
|
|
||||||
sale_item.id = $(this).attr('id').substr(0,16);
|
|
||||||
sale_item.name = $(this).find('#item-name-price').text().split('@')[0];
|
|
||||||
sale_item.account_id = $(this).find('#item-account-type').text();
|
|
||||||
sale_item.price = $(this).find('#item-total-price').text();
|
|
||||||
sale_items.push(sale_item);
|
|
||||||
});
|
|
||||||
return sale_items;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Get discount Item rows */
|
|
||||||
function get_discount_item_rows(){
|
|
||||||
var sale_items = [];
|
|
||||||
$('.discount-item-row').each(function(i){
|
|
||||||
var sale_item = {};
|
|
||||||
sale_item.id = $(this).attr('id');
|
|
||||||
sale_item.name = $(this).find('#item-name-price').text();
|
|
||||||
sale_item.account_id = $(this).find('#item_account_type').text();
|
|
||||||
sale_item.price = $(this).find('#item-total-price').text();
|
|
||||||
sale_items.push(sale_item);
|
|
||||||
});
|
|
||||||
return sale_items;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get Selected Sale Item's ID and Price */
|
/* Get Selected Sale Item's ID and Price */
|
||||||
function get_selected_sale_items(){
|
function get_selected_order_items(){
|
||||||
var sale_items = [];
|
var order_items = [];
|
||||||
$('.item-row.selected-item').each(function(i){
|
$('.item-row.selected-item').each(function(i){
|
||||||
var sale_item = {};
|
var order_item = {};
|
||||||
sale_item.id = $(this).attr('id').substr(0,16);
|
order_item.id = $(this).attr('id').substr(0,16);
|
||||||
sale_item.name = $(this).find('#item-name-price').text().split('@')[0];
|
order_item.name = $(this).find('#item-name-price').text().split('@')[0];
|
||||||
sale_item.account_id = $(this).find('#item-account-type').text();
|
order_item.account_id = $(this).find('#item-account-type').text();
|
||||||
sale_item.price = $(this).find('#item-total-price').text();
|
order_item.price = $(this).find('#item-total-price').text();
|
||||||
sale_items.push(sale_item);
|
order_items.push(order_item);
|
||||||
});
|
});
|
||||||
return sale_items;
|
return order_items;
|
||||||
}
|
|
||||||
|
|
||||||
/* Get Selected Accounts ID and Price */
|
|
||||||
function get_selected_account_types(){
|
|
||||||
var account_types = [];
|
|
||||||
|
|
||||||
$('.selected-account').each(function(i){
|
|
||||||
var account= {};
|
|
||||||
account.id = $(this).attr('id').substr(8);
|
|
||||||
account.name = $(this).text();
|
|
||||||
account_types.push(account);
|
|
||||||
});
|
|
||||||
return account_types;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Calculate Overall Discount*/
|
|
||||||
function calculate_overall_discount(type, amount){
|
|
||||||
var origin_sub_total = parseFloat($("#order-sub-total").text());
|
|
||||||
var dis_amount = 0;
|
|
||||||
var sub_total = 0;
|
|
||||||
var total_discount = 0;
|
|
||||||
|
|
||||||
// For Net Pay
|
|
||||||
if(type == 0){
|
|
||||||
total_discount = amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
// For Percentage Pay
|
|
||||||
if(type == 1){
|
|
||||||
if(amount > 100 ){
|
|
||||||
swal({
|
|
||||||
title:"Oops!",
|
|
||||||
text:'Percentage Value over 100!',
|
|
||||||
type: "error",
|
|
||||||
confirmButtonText: 'OK',
|
|
||||||
confirmButtonColor:"red"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
total_discount = (origin_sub_total * amount)/100;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$("#order-discount").text(total_discount);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Calculate Items Discount*/
|
|
||||||
function calculate_item_discount(type, amount, sale_items, account_types){
|
|
||||||
var origin_sub_total = parseFloat($("#order-sub-total").text());
|
|
||||||
var dis_amount = 0;
|
|
||||||
var sub_total = 0;
|
|
||||||
var total_discount = 0;
|
|
||||||
// For Net Pay
|
|
||||||
if(type == 0){
|
|
||||||
dis_amount = (0 - amount);
|
|
||||||
if(sale_items.length > 0){
|
|
||||||
for(var i=0;i < sale_items.length;i++){
|
|
||||||
var discount_item_row = item_row_template(type,sale_items[i], dis_amount, amount);
|
|
||||||
$("#order-items-table tbody").append(discount_item_row);
|
|
||||||
total_discount = total_discount + amount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sub_total = origin_sub_total - total_discount;
|
|
||||||
}
|
|
||||||
|
|
||||||
// For Percentage Pay
|
|
||||||
if(type == 1){
|
|
||||||
if(amount > 100 ){
|
|
||||||
swal({
|
|
||||||
title:"Oops!",
|
|
||||||
text:'Percentage Value over 100!',
|
|
||||||
type: "error",
|
|
||||||
confirmButtonText: 'OK',
|
|
||||||
confirmButtonColor:"red"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
// Check sale items exists
|
|
||||||
if(sale_items.length > 0){
|
|
||||||
for(var i=0;i < sale_items.length;i++){
|
|
||||||
dis_amount = 0 - ((sale_items[i].price * amount)/100);
|
|
||||||
var discount_item_row = item_row_template(type,sale_items[i], dis_amount, amount);
|
|
||||||
$("#order-items-table tbody").append(discount_item_row);
|
|
||||||
total_discount = total_discount + dis_amount;
|
|
||||||
}
|
|
||||||
sub_total = origin_sub_total + total_discount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$("#order-sub-total").text(sub_total);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//check for isNumber
|
//check for isNumber
|
||||||
function isNumberKey(evt) {
|
function isNumberKey(evt) {
|
||||||
var charCode = (evt.which) ? evt.which : event.keyCode;
|
var charCode = (evt.which) ? evt.which : event.keyCode;
|
||||||
if (charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57)) {
|
if (charCode > 31 && (charCode < 48 || charCode > 57)) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -222,6 +222,7 @@ scope "(:locale)", locale: /en|mm/ do
|
|||||||
|
|
||||||
#split bill
|
#split bill
|
||||||
get '/table/:dining_id/split_bills' => 'split_bill#index', as:'split_bill_index'
|
get '/table/:dining_id/split_bills' => 'split_bill#index', as:'split_bill_index'
|
||||||
|
post '/split_bills', to: 'split_bill#create', as:"order_item_split_bills"
|
||||||
end
|
end
|
||||||
|
|
||||||
#--------- Waiter/Ordering Station ------------#
|
#--------- Waiter/Ordering Station ------------#
|
||||||
|
|||||||
Reference in New Issue
Block a user