fixed conflict

This commit is contained in:
Nweni
2019-12-04 10:37:52 +06:30
15 changed files with 82 additions and 108 deletions

View File

@@ -1,11 +1,20 @@
class Api::ApiController < ActionController::API
include TokenVerification, MultiTenancy
include MultiTenancy
include TokenVerification
include ActionController::MimeResponds
include ActionView::Rendering
# before_action :lookup_domain
helper_method :current_token, :current_login_employee, :get_cashier
private
# ActionView::Rendering override render_to_body breaks render :json,
# resulting in an ActionView::MissingTemplate error.
def render_to_body(options)
_render_to_body_with_renderer(options) || super
end
#this is base api base controller to need to inherit.
#all token authentication must be done here
#response format must be set to JSON

View File

@@ -1,5 +1,6 @@
class ApplicationController < ActionController::Base
include LoginVerification, MultiTenancy
include MultiTenancy
include LoginVerification
#before_action :check_installation
protect_from_forgery with: :exception
@@ -17,5 +18,4 @@ class ApplicationController < ActionController::Base
flash[:warning] = exception.message
redirect_to root_path
end
end

View File

@@ -1,5 +1,7 @@
class BaseCrmController < ActionController::Base
include LoginVerification,
include MultiTenancy
include LoginVerification
layout "CRM"
before_action :check_user

View File

@@ -1,5 +1,7 @@
class BaseInventoryController < ActionController::Base
include LoginVerification, MultiTenancy
include MultiTenancy
include LoginVerification
layout "inventory"
before_action :check_user

View File

@@ -1,5 +1,8 @@
class BaseOqsController < ActionController::Base
include LoginVerification, MultiTenancy
include MultiTenancy
include LoginVerification
layout "OQS"
before_action :check_user

View File

@@ -1,5 +1,7 @@
class BaseOrigamiController < ActionController::Base
include LoginVerification, MultiTenancy
include MultiTenancy
include LoginVerification
layout "origami"
before_action :check_user

View File

@@ -1,5 +1,7 @@
class BaseReportController < ActionController::Base
include LoginVerification, MultiTenancy
include MultiTenancy
include LoginVerification
layout "application"
before_action :check_user

View File

@@ -1,5 +1,7 @@
class BaseWaiterController < ActionController::Base
include LoginVerification, MultiTenancy
include MultiTenancy
include LoginVerification
layout "waiter"
before_action :check_user

View File

@@ -4,8 +4,9 @@ class Origami::HomeController < BaseOrigamiController
def index
@webview = check_mobile
@tables = Table.unscope(:order).all.active.order('status desc')
@rooms = Room.unscope(:order).all.active.order('status desc')
@tables = Table.unscope(:order).includes(:zone).all.active.order('status desc')
@rooms = Room.unscope(:order).includes(:zone).all.active.order('status desc')
@complete = Sale.completed_sale("cashier")
@orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc')
@@ -21,8 +22,8 @@ class Origami::HomeController < BaseOrigamiController
@print_settings = PrintSetting.get_precision_delimiter()
@webview = check_mobile
@tables = Table.unscope(:order).all.active.order('status desc')
@rooms = Room.unscope(:order).all.active.order('status desc')
@tables = Table.unscope(:order).includes(:zone).all.active.order('status desc')
@rooms = Room.unscope(:order).includes(:zone).all.active.order('status desc')
@complete = Sale.completed_sale("cashier")
@orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc')
@customers = Customer.pluck("customer_id, name")

View File

@@ -176,14 +176,14 @@ class Origami::PaymentsController < BaseOrigamiController
# For Cashier by Zone
# bookings = Booking.where("sale_id='#{sale_id}'")
bookings = Booking.find_by_sale_id(sale_id)
bookings = saleObj.bookings[0]
shift = ShiftSale.current_open_shift(current_user.id)
if !shift.nil?
cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id)
else
if bookings.dining_facility_id.to_i > 0
table = DiningFacility.find(bookings.dining_facility_id)
table = bookings.dining_facility
cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id)
cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id)

View File

@@ -33,50 +33,22 @@ class DiningFacility < ApplicationRecord
def get_current_booking
checkin_time_lookup = Lookup.get_checkin_time_limit
booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='assign' and (CASE WHEN checkin_at > '#{DateTime.now.utc}' THEN checkin_at >= '#{DateTime.now.utc}' ELSE checkin_at between '#{DateTime.now.utc - checkin_time_lookup.hours}' and '#{DateTime.now.utc}' END) and checkout_by is null").limit(1) #and checkout_at is null
# booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='assign' and checkin_at between '#{DateTime.now.utc - 5.hours}' and '#{DateTime.now.utc}' and checkout_by is null").limit(1) #and checkout_at is null
if booking.count > 0 then
return booking[0]
else
return nil
end
Booking.where(dining_facility_id: self.id, booking_status: 'assign', checkout_at: nil).where("checkin_at > ?", checkin_time_lookup.hours.ago).first #and checkout_at is null
end
def get_moved_booking
checkin_time_lookup = Lookup.get_checkin_time_limit
booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='moved' and checkin_at between '#{DateTime.now.utc - checkin_time_lookup.hours}' and '#{DateTime.now.utc}' and checkout_at is null").limit(1)
if booking.count > 0 then
return booking[0]
else
return nil
end
Booking.where(dining_facility_id: self.id, booking_status: 'moved', checkout_at: nil).where("checkin_at > ?", checkin_time_lookup.hours.ago).first
end
def get_new_booking
# query for new
# if status
# to ask when req bill booking_status?
booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='assign' and sale_id is null and checkout_at is null").limit(1)
# else
# booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='assign' and sale_id not null").limit(1)
# end
if booking.count > 0 then
return booking[0].booking_id
else
return nil
end
Booking.where(dining_facility_id: self.id, booking_status: 'assign', sale_id: nil, checkout_at: nil).first
end
def get_current_checkout_booking
checkin_time_lookup = Lookup.get_checkin_time_limit
booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='assign' and checkin_at between '#{DateTime.now.utc - checkin_time_lookup.hours}' and '#{DateTime.now.utc}' and reserved_by is not null and checkout_by is null").limit(1)
if booking.count > 0 then
return booking[0]
else
return nil
end
Booking.where(dining_facility_id: self.id, booking_status: 'assign', checkout_at: nil).where.not(reserved_at: nil).where("checkin_at > ?", checkin_time_lookup.hours.ago).first
end
def get_checkout_booking
@@ -119,7 +91,7 @@ class DiningFacility < ApplicationRecord
def self.get_checkin_booking
checkin_time_lookup = Lookup.get_checkin_time_limit
bookings = Booking.where("booking_status ='assign' and checkin_at between '#{DateTime.now.utc - checkin_time_lookup.hours}' and '#{DateTime.now.utc}' and reserved_by is not null and checkout_by is null")
bookings = Booking.where(booking_status: 'assign', checkout_at: nil).where.not(reserved_at: nil).where("checkin_at > ?", checkin_time_lookup.hours.ago)
arr_booking = Array.new
if bookings
lookup_checkout_time = Lookup.collection_of("checkout_alert_time")

View File

@@ -4,6 +4,8 @@ class Lookup < ApplicationRecord
scope :number_formats, -> { where(lookup_type: 'number_format')}
TIME_LIMIT = 5
def available_types
{'Employee Roles' => 'employee_roles',
'Dining Facilities Status' => 'dining_facilities_status',
@@ -23,15 +25,13 @@ class Lookup < ApplicationRecord
# Lookup.select("value, name").where("lookup_type = ?", lookup_type ).order("name asc").map { |r| [r.name, r.value] }
# end
def self.time_limit
TIME_LIMIT
end
def self.get_checkin_time_limit
time_limit = 5
lookup = Lookup.find_by_lookup_type('checkin_time_limit')
if !lookup.nil?
time_limit = lookup.value.to_i
end
return time_limit
return RequestStore[:checkin_time_limit] if RequestStore[:checkin_time_limit]
RequestStore[:checkin_time_limit] = Lookup.find_by_lookup_type('checkin_time_limit').value.to_i rescue time_limit
end
def self.sync_url
@@ -58,7 +58,6 @@ class Lookup < ApplicationRecord
def self.collection_of(type)
Lookup.select("name, value").where("lookup_type" => type ).map { |l| [l.name, l.value] }
end
def self.create_shift_sale_lookup

View File

@@ -2025,7 +2025,7 @@ end
query = query.joins("join sale_orders as sale_orders on sale_orders.sale_id = sales.sale_id")
.joins("join orders as orders on orders.order_id = sale_orders.order_id")
query = query.where("sales.sale_status != 'new' AND orders.status = 'billed' #{type}")
query = query.where("DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ? ",DateTime.now.strftime('%Y-%m-%d'))
query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day)
.group("sales.sale_id")
end

View File

@@ -87,7 +87,7 @@ class SalePayment < ApplicationRecord
amount_due = amount_due - payment.payment_amount
end
end
if (amount_due >= 0)
if (amount_due > 0)
payment_status = false
membership_data = nil
#route to payment type
@@ -780,27 +780,14 @@ class SalePayment < ApplicationRecord
def table_update_status(sale_obj)
status = true
sale_count = 0
booking = Booking.find_by_sale_id(sale_obj.id)
if booking
if booking = sale_obj.bookings[0]
if booking.dining_facility_id.to_i > 0
table = DiningFacility.find(booking.dining_facility_id)
bookings = table.bookings
bookings.each do |tablebooking|
if tablebooking.booking_status != 'moved'
if tablebooking.sale_id
if tablebooking.sale.sale_status != 'completed' && tablebooking.sale.sale_status != 'void' && tablebooking.sale.sale_status != 'spoile' && tablebooking.sale.sale_status != 'waste'
status = false
sale_count += 1
else
status = true
end
else
status = false
sale_count += 1
end
end
table = booking.dining_facility
if Booking.left_joins(:sale).where(dining_facility_id: booking.dining_facility_id).where.not(booking_status: 'moved').where("sales.sale_status NOT IN ('completed', 'void', 'spoile', 'waste') OR sales.sale_status IS NULL").exists?
status = false
end
if status && sale_count == 0
if status
table.update_attributes(status: "available")
# table.status = "available"
# table.save
@@ -973,37 +960,30 @@ class SalePayment < ApplicationRecord
#credit payment query
def self.get_credit_sales(params)
receipt_no = ""
customer = ""
if !params["receipt_no"].blank?
receipt_no = " and s.receipt_no LIKE '%#{params["receipt_no"]}%'"
payments = SalePayment.select("sale_payments.sale_id, sale_payments.sale_payment_id, sale_payments.payment_method, sale_payments.payment_amount")
.select("SUM(sale_payments.payment_amount) OVER (PARTITION BY sale_payments.sale_id) total_payment_amount")
credit_sales = Sale.select("sales.sale_id, sales.receipt_no, sales.receipt_date as sale_date, sales.cashier_name")
.select("sale_payments.sale_payment_id, sale_payments.payment_amount").select("customers.name as customer_name")
.joins("JOIN (#{payments.to_sql}) AS sale_payments ON sale_payments.sale_id = sales.sale_id").joins(:customer).joins(:orders)
.completed.paid.where("sale_payments.payment_method = 'creditnote' AND sales.grand_total > sale_payments.total_payment_amount - sale_payments.payment_amount")
.group(:receipt_no)
.order(:receipt_date).order(:receipt_no)
if params["receipt_no"].present?
credit_sales = credit_sales.where("sales.receipt_no LIKE ?", "%#{params["receipt_no"]}%")
end
if !params["customer_id"].blank?
customer = " and s.customer_id = '#{params["customer_id"]}'"
if params["customer_id"].present?
credit_sales = credit_sales.where("sales.customer_id = ?", params["customer_id"])
end
order_source_query = "(select orders.source FROM orders JOIN sale_orders so ON so.order_id=orders.order_id WHERE so.sale_id=s.sale_id GROUP BY so.sale_id)"
query = SalePayment.select("s.receipt_no, sale_payments.sale_payment_id,
sale_payments.payment_method,
SUM(sale_payments.payment_amount) as payment_amount,
s.receipt_date as sale_date,
s.sale_id,
s.cashier_name as cashier_name, c.name as customer_name")
.joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
.joins("INNER JOIN customers c ON c.customer_id = s.customer_id")
if params[:type].nil?
query = query.where("(CASE WHEN (s.grand_total + s.amount_changed)=(select SUM(payment_amount) FROM sale_payments WHERE sale_id=s.sale_id AND payment_method!='creditnote') THEN NULL ELSE payment_method='creditnote' END) and s.sale_status = 'completed' and s.payment_status='paid' #{receipt_no} #{customer}")
elsif params[:type] == "cashier"
query = query.where("(CASE WHEN (s.grand_total + s.amount_changed)=(select SUM(payment_amount) FROM sale_payments WHERE sale_id=s.sale_id AND payment_method!='creditnote') THEN NULL ELSE payment_method='creditnote' AND #{order_source_query}='#{params[:type]}' OR #{order_source_query}='emenu' END) and s.sale_status = 'completed' and s.payment_status='paid' #{receipt_no} #{customer}")
else
query = query.where("(CASE WHEN (s.grand_total + s.amount_changed)=(select SUM(payment_amount) FROM sale_payments WHERE sale_id=s.sale_id AND payment_method!='creditnote') THEN NULL ELSE payment_method='creditnote' AND #{order_source_query}='#{params[:type]}' END) and s.sale_status = 'completed' and s.payment_status='paid' #{receipt_no} #{customer}")
if params[:type].present?
sources = []
sources << params[:type]
sources << 'emenu' if params[:type] == 'cashier'
credit_sales = credit_sales.where("orders.source IN (?)", sources)
end
query = query.group("s.receipt_no")
.order("s.receipt_date ASC, s.receipt_no ASC")
return query
end
def self.get_credit_amount_due_left(sale_id)

View File

@@ -65,7 +65,7 @@
<% end %>
<div class="card-block">
Table <%= table.name %> ( <%= table.seater %> Seat ) <br>
<%= table.zone.name %>
<%= table.zone.name %>
</div>
</div>
<% end %>
@@ -160,7 +160,7 @@
<th><%= t :credit %> <%= t :sale %> <%= t("views.right_panel.detail.date") %></th>
<th><%= t("views.right_panel.detail.receipt_no") %></th>
<th> <%= t :cashier %> <%= t("views.right_panel.detail.name") %></th>
<th> <%= t :customer %> <%= t("views.right_panel.detail.name") %></th>
<th> <%= t :customer %> <%= t("views.right_panel.detail.name") %></th>
<th> <%= t("views.right_panel.detail.credit_amount") %> </th>
</thead>
<tbody class="tbd_credit_lists"></tbody>
@@ -338,8 +338,8 @@ function warnBeforeRedirect(linkURL,occupied_count) {
text = "Are you sure you want to close cashier?";
}
swal({
title: "Alert!",
text: text,
title: "Alert!",
text: text,
type: "warning",
showCancelButton: true,
html: true