diff --git a/README.md b/README.md
index 8c5cf006..8655b6d9 100755
--- a/README.md
+++ b/README.md
@@ -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
diff --git a/app/controllers/api/bill_controller.rb b/app/controllers/api/bill_controller.rb
index 387b7bf8..2c2ac133 100755
--- a/app/controllers/api/bill_controller.rb
+++ b/app/controllers/api/bill_controller.rb
@@ -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
diff --git a/app/controllers/base_origami_controller.rb b/app/controllers/base_origami_controller.rb
index ec415bad..e448cf17 100755
--- a/app/controllers/base_origami_controller.rb
+++ b/app/controllers/base_origami_controller.rb
@@ -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
diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb
index c00b39bf..d90d7f2d 100755
--- a/app/controllers/origami/home_controller.rb
+++ b/app/controllers/origami/home_controller.rb
@@ -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
diff --git a/app/controllers/origami/split_bill_controller.rb b/app/controllers/origami/split_bill_controller.rb
index 87b8644d..59cdae1e 100644
--- a/app/controllers/origami/split_bill_controller.rb
+++ b/app/controllers/origami/split_bill_controller.rb
@@ -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
diff --git a/app/models/ability.rb b/app/models/ability.rb
index a72a47d2..406d757a 100755
--- a/app/models/ability.rb
+++ b/app/models/ability.rb
@@ -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"
diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb
index f9599783..edbcaced 100755
--- a/app/views/origami/home/show.html.erb
+++ b/app/views/origami/home/show.html.erb
@@ -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";
diff --git a/app/views/origami/orders/show.html.erb b/app/views/origami/orders/show.html.erb
index b08328b6..70e1ba9d 100755
--- a/app/views/origami/orders/show.html.erb
+++ b/app/views/origami/orders/show.html.erb
@@ -39,22 +39,37 @@
<% @tables.each do |table| %>
<% if table.status == 'occupied' %>
-
-
- <%= table.name %>
- <% if table.get_booking.nil? %>
- billed
- <% else %>
- new
- <% end %>
-
-
+ <% if table.get_booking.nil? %>
+ <% if table.get_checkout_booking.nil? %>
+
+ <% else %>
+
+ <% end %>
+
+ <%= table.name %>
+
billed
+
+
+
+ <% else %>
+ <% if table.get_checkout_booking.nil? %>
+
+ <% else %>
+
+ <% end %>
+
+ <%= table.name %>
+ new
+
+
+ <% end %>
<% else %>
-
<% end %>
<% end %>
@@ -64,24 +79,30 @@
<% @rooms.each do |room| %>
- <% if room.status == 'occupied' %>
-
-
- <%= room.name %>
- <% if room.get_booking.nil? %>
-
billed
+ <% if room.status == 'occupied' %>
+ <% if room.get_booking.nil? %>
+
+
+ <%= room.name %>
+ billed
+
+
<% else %>
-
new
+
+
+ <%= room.name %>
+ new
+
+
<% end %>
-
-
- <% else %>
-
- <% end %>
+ <% else %>
+
+
+ <%= room.name %>
+
+
+
+ <% end %>
<% end %>
diff --git a/app/views/origami/split_bill/index.html.erb b/app/views/origami/split_bill/index.html.erb
index 9aa09d37..c96e2674 100755
--- a/app/views/origami/split_bill/index.html.erb
+++ b/app/views/origami/split_bill/index.html.erb
@@ -4,139 +4,78 @@
-
+
-
-
-
-
-
<%=@table.id%>
-
<%=@table.type%>
-
Order No: <%=@order.order_id rescue ' '%>
-
-
-
Date: <%=@order.created_at.strftime("%d/%m/%Y - %I:%M %p") rescue '-'%>
-
-
-
-
-
-
+
+
+
+
+
<%=@table.id%>
+
<%=@table.type%>
+
Order No: <%=@order.order_id rescue ' '%>
+
+
+
Date: <%=@order.created_at.strftime("%d/%m/%Y - %I:%M %p") rescue '-'%>
+
+
+
+
+
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
@@ -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;
+ }
}
+
diff --git a/config/routes.rb b/config/routes.rb
index 12c263d5..5afcb32e 100755
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -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 ------------#