order item split bill process

This commit is contained in:
phyusin
2018-02-06 09:46:30 +06:30
parent 3dc6f42bd5
commit 991bc48505
10 changed files with 309 additions and 505 deletions

View File

@@ -103,6 +103,8 @@ Change type in mysql
=> 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
For split bill
1) settings/lookups => { type:split_bill, name:SplitBill, value:1 }
* ToDo list

View File

@@ -5,7 +5,7 @@ class Api::BillController < Api::ApiController
def create
@status = false
@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)
#create Bill by Booking ID
table = 0

View File

@@ -18,4 +18,9 @@ class BaseOrigamiController < ActionController::Base
# def checkin_process
# CheckinJob.set(wait: 1.minute).perform_later()
# end
# Get current Cashier
def get_cashier
@cashier = Employee.where("role = 'cashier' AND token_session <> ''")
end
end

View File

@@ -88,6 +88,12 @@ class Origami::HomeController < BaseOrigamiController
#for bank integration
@checkout_time = Lookup.collection_of('checkout_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
private

View File

@@ -1,4 +1,5 @@
class Origami::SplitBillController < BaseOrigamiController
authorize_resource :class => false
def index
dining_id = params[:dining_id]
@@ -18,4 +19,54 @@ class Origami::SplitBillController < BaseOrigamiController
@booking = nil
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

View File

@@ -132,6 +132,10 @@ class Ability
can :manage, Commissioner
can :manage, Promotion
can :manage, Product
#ability for split_bill
can :index, :split_bill
can :create, :split_bill
elsif user.role == "account"

View File

@@ -672,7 +672,9 @@
// Bill Request
$('#request_bills').click(function () {
swal({
var lookup_split_bill = '<%= @spit_bill %>';
if(lookup_split_bill == '1'){
swal({
title: "Alert",
text: "Do you want to Split bill?",
type: "warning",
@@ -680,30 +682,37 @@
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, split it!",
closeOnConfirm: false
}, function (isConfirm) {
if (isConfirm) {
var dining_id = "<%= @dining.id %>";
window.location.href = '/origami/table/' + dining_id + "/split_bills";
}else{
var order_id = $('#save_order_id').attr('data-order');
var ajax_url = "/origami/" + order_id + "/request_bills";
$.ajax({
type: "GET",
url: ajax_url,
// data: 'order_id='+ order_id,
success: function (result) {
if (!result.status) {
swal("Information!", result.error_message);
}
else {
location.reload();
}
}
});
}
});
}, function (isConfirm) {
if (isConfirm) {
var dining_id = "<%= @dining.id %>";
window.location.href = '/origami/table/' + dining_id + "/split_bills";
}else{
requestBillProcess();
}
});
}else{
requestBillProcess();
}
});
function requestBillProcess(){
var order_id = $('#save_order_id').attr('data-order');
var ajax_url = "/origami/" + order_id + "/request_bills";
$.ajax({
type: "GET",
url: ajax_url,
// data: 'order_id='+ order_id,
success: function (result) {
if (!result.status) {
swal("Information!", result.error_message);
}
else {
location.reload();
}
}
});
}
$('#move').on('click', function () {
var dining_id = "<%= @dining.id %>";
window.location.href = '/origami/table/' + dining_id + "/movetable";

View File

@@ -39,22 +39,37 @@
<div class="card-columns" style="padding-top:10px; column-gap: 1.2rem;">
<% @tables.each do |table| %>
<% 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? %>
<span style="font-size:12px;float:right;line-height:inherit;"> billed</span>
<% else %>
<span style="font-size:12px;float:right;line-height:inherit;"> new</span>
<% end %>
</div>
</div>
<% if table.get_booking.nil? %>
<% if table.get_checkout_booking.nil? %>
<div class="card tables red 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 %>"> 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" data-id="<%= table.id %>">
<div class="card-block">
<div class="card tables green text-white table_<%= table.id %>" data-id="<%= table.id %>">
<div class="card-block">
<%= table.name %>
</div>
</div>
<span class="float-right font-12 new_text_<%= table.id %> hide"> new</span>
</div>
</div>
<% end %>
<% end %>
</div>
@@ -64,24 +79,30 @@
<div class="tab-pane" id="rooms" role="tabpanel" style="">
<div class="card-columns" style="padding-top:10px; column-gap: 1.2rem;">
<% @rooms.each do |room| %>
<% 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? %>
<span style="font-size:12px;float:right;line-height:inherit;"> billed</span>
<% if room.status == 'occupied' %>
<% if room.get_booking.nil? %>
<div class="card rooms red 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 %>"> billed</span>
</div>
</div>
<% else %>
<span style="font-size:12px;float:right;line-height:inherit;"> new</span>
<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 %>
</div>
</div>
<% else %>
<div class="card rooms green text-white" data-id="<%= room.id %>">
<div class="card-block">
<%= room.name %>
</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>
<% end %>
<% end %>
</div>
</div>

View File

@@ -4,139 +4,78 @@
</div>
<div class="row">
<!-- 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 -->
<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">
<span class="hidden" id ="table_id" value="<%=@table.id%>"><%=@table.id%></span>
<span class="hidden" id="table_type" value="<%=@table.type%>"><%=@table.type%></span>
<p class="m-l-10">Order No: <span id="order_no"><%=@order.order_id rescue ' '%></span></p>
</div>
<div class="col-lg-6 col-md-6 col-sm-6 text-right">
<p class="m-r-10">Date: <span id="order_date"> <%=@order.created_at.strftime("%d/%m/%Y - %I:%M %p") rescue '-'%></span></p>
</div>
</div>
<div id="order-detail-slimscroll" data-height="160">
<div class="card-text dining">
<table class="table table-default" id="order-items-table">
<thead>
<tr>
<th class="item-name">Items</th>
<th class="item-attr">QTY</th>
<th class="item-attr">Price</th>
</tr>
</thead>
<tbody>
<% sub_total = 0 %>
<% @order_items.each do |order_item| %>
<%
sub_total += order_item.qty*order_item.price
%>
<tr class="item-row" id=<%= order_item.order_items_id %> >
<td style="width:60%; text-align:left">
<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>
</td>
<td style="width:20%; text-align:right">
<span id="item-qty"><%=order_item.qty%></span>
</td>
<td style="width:20%; text-align:right">
<span id="item-total-price"><%=(order_item.qty*order_item.price)%></span>
</td>
</tr>
<%
end
%>
</tbody>
</table>
</div>
</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>
</table>
</div>
</div>
</div>
<!-- <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">
<span class="hidden" id ="table_id" value="<%=@table.id%>"><%=@table.id%></span>
<span class="hidden" id="table_type" value="<%=@table.type%>"><%=@table.type%></span>
<p class="m-l-10">Order No: <span id="order_no"><%=@order.order_id rescue ' '%></span></p>
</div>
<div class="col-lg-6 col-md-6 col-sm-6 text-right">
<p class="m-r-10">Date: <span id="order_date"> <%=@order.created_at.strftime("%d/%m/%Y - %I:%M %p") rescue '-'%></span></p>
</div>
</div>
<div id="order-detail-slimscroll" data-height="160">
<div class="card-text dining">
<table class="table table-default" id="order-items-table">
<thead>
<tr>
<th class="item-name">Items</th>
<th class="item-attr">QTY</th>
<th class="item-attr">Price</th>
</tr>
</thead>
<tbody>
<% sub_total = 0 %>
<% @order_items.each do |order_item| %>
<%
sub_total += order_item.qty*order_item.price
%>
<tr class="item-row" id=<%= order_item.order_items_id %> >
<td style="width:60%; text-align:left">
<span id="item-account-type" class="hidden"><%=order_item.account_id%></span>
<span id="item-name-price"><%=order_item.item_name%></span>
</td>
<td style="width:20%; text-align:right">
<span id="item-qty"><%=order_item.qty%></span>
</td>
<td style="width:20%; text-align:right">
<span id="item-total-price"><%=(order_item.qty*order_item.price)%></span>
</td>
</tr>
<%
end
%>
</tbody>
</table>
</div>
</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>
</table>
</div>
</div>
</div>
</div>
<!-- Column One -->
<div class="col-lg-3 col-md-3 col-sm-3 clearfix"></div>
<!-- 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">
<!-- Action Panel -->
<div>
<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="remove-all" class="btn bg-primary btn-block action-btn">Remove All</button>
<button id="pay-discount" class="btn bg-primary btn-block action-btn">Enter</button>
<button id="order_item_split" class="btn btn-primary btn- action-btn">Order Items Split</button>
<!-- <button id="per_person" class="btn bg-primary btn-block action-btn">Per Person</button> -->
</div>
</div>
</div>
@@ -146,13 +85,7 @@
$(document).ready(function(){
$('#back').on('click',function(){
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
}
backToOrigami();
})
$(".cashier_number").on('click', function(event){
@@ -162,28 +95,28 @@
var input_type = $(this).attr("data-type");
switch (input_type) {
case 'num':
var input_value = $(this).attr("data-value");
if (original_value == "0"){
$('#per_person').val(input_value);
}
else{
$('#per_person').val(original_value + '' + input_value);
}
var input_value = $(this).attr("data-value");
if (original_value == "0"){
$('#per_person').val(input_value);
}
else{
$('#per_person').val(original_value + '' + input_value);
}
break;
case 'add':
var input_value = $(this).attr("data-value");
amount = parseInt(input_value);
$('#per_person').val(amount);
var input_value = $(this).attr("data-value");
amount = parseInt(input_value);
$('#per_person').val(amount);
break;
case 'del' :
var discount_text=$('#per_person').val();
$('#per_person').val(discount_text.substr(0,discount_text.length-1));
var discount_text=$('#per_person').val();
$('#per_person').val(discount_text.substr(0,discount_text.length-1));
break;
case 'clr':
$('#per_person').val("0");
$('#per_person').val("0");
break;
}
event.handled = true;
@@ -202,327 +135,99 @@
}
});
// Select discount-item
$('#order-items-table tbody').on('click', '.discount-item-row',function(){
if($(this).hasClass('selected-item') == true){
$(this).removeClass('selected-item');
}
else {
$(this).addClass('selected-item');
}
});
// 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
$("#percentage").on('click', function(e){
e.preventDefault();
var sale_id = $('#sale-id').text();
var discount_value = $('#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(1, discount_value);
}
else {
calculate_item_discount(1, discount_value, sale_items, account_types);
}
// Remove Selection
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({
type: "POST",
url: ajax_url,
data: params,
success:function(result){
$("#loading_wrapper").hide();
//order_item_split
$('#order_item_split').on('click',function () {
var cnt_order_item = "<%= @order_items.count %>";
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: "Information!",
text: result.status,
}, function () {
if(result.table_type == "Table"){
window.location.href = "/origami/table/" + result.table_id
}
else {
window.location.href = "/origami/room/" + result.table_id
}
});
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);
}
});
}
});
});
// 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;
else{
splitBillProcess(cnt_items);
}
}else{
swal("Opps","Please select at least on item!","warning");
}
for(var i=0;i < sale_items.length;i++){
if(sale_items[i].price < 0){
discount_items.push(sale_items[i]);
}
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
}
});
}
});
});
/* function for split bill process */
function splitBillProcess(cnt_items){
var order_items = get_selected_order_items();// Selected Order Items
var json_booking = JSON.parse('<%= @booking.to_json.html_safe %>');
var booking_id = "";
if(cnt_items == 0){
booking_id = json_booking.booking_id;
}
/* Remove Selection */
function selection_remove(){
$(".item-row").removeClass("selected-item");
}
var ajax_url = "/origami/split_bills";
$.ajax({
type: "POST",
url: ajax_url,
dataType: 'JSON',
data: {'booking_id' : booking_id, 'order_items' : JSON.stringify(order_items)},
success: function (result) {
if (!result.status) {
swal("Information!", result.error_message);
}
else {
if (cnt_items > 0){
window.location.reload();
}else{
backToOrigami();
}
}
}
});
}
/* 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;
}
/* back to origami */
function backToOrigami(){
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
}
}
/* Get Selected Sale Item's ID and Price */
function get_selected_sale_items(){
var sale_items = [];
function get_selected_order_items(){
var order_items = [];
$('.item-row.selected-item').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);
var order_item = {};
order_item.id = $(this).attr('id').substr(0,16);
order_item.name = $(this).find('#item-name-price').text().split('@')[0];
order_item.account_id = $(this).find('#item-account-type').text();
order_item.price = $(this).find('#item-total-price').text();
order_items.push(order_item);
});
return sale_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);
return order_items;
}
//check for isNumber
function isNumberKey(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode;
if (charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57)) {
return false;
} else {
return true;
}
var charCode = (evt.which) ? evt.which : event.keyCode;
if (charCode > 31 && (charCode < 48 || charCode > 57)) {
return false;
} else {
return true;
}
}
</script>

View File

@@ -222,6 +222,7 @@ scope "(:locale)", locale: /en|mm/ do
#split bill
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
#--------- Waiter/Ordering Station ------------#