Merge branch 'master' into cloud

This commit is contained in:
Yan
2017-12-13 18:30:39 +06:30
11 changed files with 114 additions and 27 deletions

View File

@@ -0,0 +1,25 @@
App.order = App.cable.subscriptions.create('CheckinChannel', {
// App.messages = App.cable.subscriptions.create('MessagesChannel', {
connected: function() {},
disconnected: function() {},
received: function(data) {
if((data.table != undefined) && (data.table.length > 0)){
$.each(data.table,function(key,value){
if($('.table_'+value.table_id).hasClass('blue')){
$('.table_'+value.table_id).removeClass('blue');
$('.table_'+value.table_id).addClass('orange');
}
else if($('.table_'+value.table_id).hasClass('red')){
$('.table_'+value.table_id).removeClass('red');
$('.table_'+value.table_id).addClass('orange');
}
$('.new_text_'+value.table_id).removeClass('hide');
});
}
}
});

View File

@@ -0,0 +1,10 @@
class CheckinChannel < ApplicationCable::Channel
def subscribed
stream_from "checkin_channel"
end
def unsubscribed
stop_all_streams
# Any cleanup needed when channel is unsubscribed
end
end

View File

@@ -2,6 +2,8 @@ class BaseOrigamiController < ActionController::Base
include LoginVerification
layout "origami"
before_action :checkin_process
#before_action :check_installation
protect_from_forgery with: :exception
rescue_from CanCan::AccessDenied do |exception|
@@ -13,4 +15,7 @@ class BaseOrigamiController < ActionController::Base
@current_user ||= Employee.find_by_token_session(session[:session_token]) if session[:session_token]
end
def checkin_process
CheckinJob.set(wait: 30.seconds).perform_later()
end
end

View File

@@ -72,7 +72,7 @@ class HomeController < ApplicationController
@hourly_sales = Sale.hourly_sales(today).sum(:grand_total)
# .group_by_hour(:created_at, :time_zone => 'Asia/Rangoon',format: '%I:%p')
# .sum(:grand_total)
@employee_sales = Sale.employee_sales(today).sum(:grand_total)
@employee_sales = Sale.employee_sales(today).sum('total_amount')
@inventories = StockJournal.inventory_balances(today).sum(:balance)
@total_sale = Sale.total_sale(today)

View File

@@ -37,7 +37,7 @@ class Origami::OtherChargesController < BaseOrigamiController
sale_item.qty = 1
sale_item.unit_price = di["price"]
sale_item.taxable_price = di["price"] * 1
sale_item.is_taxable = 1
sale_item.is_taxable = di["is_taxable"]
sale_item.account_id = 0
sale_item.price = di["price"] * 1

10
app/jobs/checkin_job.rb Normal file
View File

@@ -0,0 +1,10 @@
class CheckinJob < ApplicationJob
queue_as :default
def perform()
table = DiningFacility.get_checkin_booking
ActionCable.server.broadcast "checkin_channel",table: table
end
end

View File

@@ -96,4 +96,26 @@ class DiningFacility < ApplicationRecord
end
end
end
def self.get_checkin_booking
bookings = Booking.where("booking_status ='assign' and checkin_at between '#{DateTime.now.utc - 5.hours}' and '#{DateTime.now.utc}' and reserved_by is not null and checkout_by is null")
arr_booking = Array.new
if bookings
bookings.each do |booking|
now = Time.now.utc.getlocal
hr = (now.strftime("%H").to_i).to_int
min = (now.strftime("%M").to_i).to_int
if !booking.checkout_at.nil?
checkout_at = booking.checkout_at.utc.getlocal
checkout_at_hr = (checkout_at.strftime("%H").to_i).to_int
checkout_at_min = (checkout_at.strftime("%M").to_i).to_int
checkout_at_min -= min
if (checkout_at_hr <= hr) && (checkout_at_min <= 15)
arr_booking.push({'table_id' => booking.dining_facility_id})
end
end
end
end
return arr_booking
end
end

View File

@@ -984,7 +984,7 @@ end
end
def self.employee_sales(today)
query = Sale.select("e.name as employee_name,grand_total")
query = Sale.select("e.name as employee_name,(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) ELSE sp.payment_amount END) as total_amount")
.where('sales.payment_status="paid" and sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today)
.joins("join employees e on e.id=sales.cashier_id")
.joins("join sale_payments sp on sp.sale_id=sales.sale_id")
@@ -1103,7 +1103,7 @@ end
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
.where("sales.sale_status = 'completed' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today)
.group("a.product_code")
.order("SUM(a.price) DESC")
.order("SUM(a.qty) DESC")
.first()
end

View File

@@ -8,7 +8,7 @@
<div><strong id="order-title">ORDER DETAILS</strong></div>
</div> -->
<div class="card-block">
<div class="card-title row">
<div class="row card-title">
<div class="col-lg-6 col-md-6 col-sm-6">
<p id="sale-id" class="hidden"><%=@sale_data.sale_id %></p>
<p>Receipt No: <span id="receipt_no"><%=@sale_data.receipt_no rescue ' '%></span></p>
@@ -95,12 +95,16 @@
<div class="card-title">
<div class="form-horizontal">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<div class="-group">
<div class="bottom-5">
<input type="text" id="other-charges-amount" name="other-charges-amount" class="form-control" placeholder="Amount" />
</div>
<div class="-group">
<div class="bottom-5">
<textarea id="reasons" name="reasons" rows="2" class="form-control" placeholder="Reasons"></textarea>
</div>
</div>
<div class="bottom-5">
<input type="checkbox" id="is_taxable" name="is_taxable" />
<lable for="is_taxable">Is Taxable</lable>
</div>
</div>
</div>
</div>
@@ -199,7 +203,7 @@
</div>
</div>
<script type="text/javascript">
$(document).ready(function(){
$(document).ready(function(){
$(".cashier_number").on('click', function(event){
if(event.handled !== true) {
var original_value=0;
@@ -270,11 +274,15 @@
var sub_total = $('#order-sub-total').text();
var charge_amount = $("#other-charges-amount").val();
var reasons = $("#reasons").val();
var is_taxable = 0
if ($("#is_taxable:checked").length > 0) {
is_taxable = 1
}
// Update sub total
$('#order-sub-total').text(parseFloat(sub_total) + parseFloat(charge_amount));
var item_row = item_row_template(sale_id, charge_amount, reasons);
var item_row = item_row_template(sale_id, charge_amount, reasons, is_taxable);
$("#order-items-table tbody").append(item_row);
});
@@ -323,13 +331,14 @@
var sale_item = {};
sale_item.id = $(this).attr('id');
sale_item.name = $(this).find('#item-name-price').text();
sale_item.price = $(this).find('#item-total-price').text();
sale_item.price = $(this).find('#item-total-price').text()
sale_item.is_taxable = $(this).find('#item_taxable').text();
sale_items.push(sale_item);
});
return sale_items;
}
function item_row_template(sale_id, charge_amount, reasons){
function item_row_template(sale_id, charge_amount, reasons, is_taxable){
var item_row = "<tr class='other-item-row' id='SLI-000000000000'>" +
"<td style='width: 60%; text-align: left;'>" +
"<span id='item_account_type' class='hidden'>" +
@@ -338,6 +347,7 @@
"<span id='item-name-price'>" +
reasons +
"</span>" +
"<span id='item_taxable' class='hidden'>" + is_taxable + "</span>" +
"</td>" +
"<td style='width: 20%; text-align: right;'>" +
"<span id='item-qty'>1</span>" +