Merge branch 'master' of bitbucket.org:code2lab/sxrestaurant into adminbsb_ui_changes
This commit is contained in:
@@ -1,3 +0,0 @@
|
|||||||
# Place all the behaviors and hooks related to the matching controller here.
|
|
||||||
# All this logic will automatically be available in application.js.
|
|
||||||
# You can use CoffeeScript in this file: http://coffeescript.org/
|
|
||||||
@@ -28,6 +28,7 @@
|
|||||||
//= require raphael/raphael.min
|
//= require raphael/raphael.min
|
||||||
//= require Chart.bundle
|
//= require Chart.bundle
|
||||||
//= require chartkick
|
//= require chartkick
|
||||||
|
//= require cable
|
||||||
//= require fileinput.min.js
|
//= require fileinput.min.js
|
||||||
//= require settings/processing_items
|
//= require settings/processing_items
|
||||||
//= require BSBMaterial/admin.js
|
//= require BSBMaterial/admin.js
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ App.order = App.cable.subscriptions.create('OrderChannel', {
|
|||||||
|
|
||||||
received: function(data) {
|
received: function(data) {
|
||||||
var hostname = location.hostname.trim();
|
var hostname = location.hostname.trim();
|
||||||
console.log(hostname)
|
// console.log(hostname)
|
||||||
console.log(data.from)
|
// console.log(data.from)
|
||||||
if(data.from == "" || hostname == data.from)
|
if(data.from == "" || hostname == data.from)
|
||||||
{
|
{
|
||||||
if (data.type == 'order') {
|
if (data.type == 'order') {
|
||||||
|
|||||||
36
app/assets/javascripts/channels/sound_effect.js
Normal file
36
app/assets/javascripts/channels/sound_effect.js
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
App.sound_effect = App.cable.subscriptions.create('SoundEffectChannel', {
|
||||||
|
connected: function() {},
|
||||||
|
|
||||||
|
disconnected: function() {},
|
||||||
|
|
||||||
|
received: function(data) {
|
||||||
|
var hostname = location.hostname.trim();
|
||||||
|
if(data.from == "" || hostname == data.from){
|
||||||
|
var shop_code = data.shop_code;
|
||||||
|
var audio = data.audio;
|
||||||
|
var data = data.data;
|
||||||
|
|
||||||
|
if(data.status){
|
||||||
|
var audio = new Audio('/'+audio); // define your audio
|
||||||
|
audio.play();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(data.status && ((data.message != undefined) && (data.message!=""))){
|
||||||
|
swal({
|
||||||
|
title: 'Information',
|
||||||
|
text: data.message,
|
||||||
|
type: 'success',
|
||||||
|
html: true,
|
||||||
|
closeOnConfirm: false,
|
||||||
|
closeOnCancel: false,
|
||||||
|
allowOutsideClick: false
|
||||||
|
}, function (isConfirm) {
|
||||||
|
if(isConfirm){
|
||||||
|
swal.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
10
app/channels/sound_effect_channel.rb
Normal file
10
app/channels/sound_effect_channel.rb
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
class SoundEffectChannel < ApplicationCable::Channel
|
||||||
|
def subscribed
|
||||||
|
stream_from "sound_effect_channel"
|
||||||
|
end
|
||||||
|
|
||||||
|
def unsubscribed
|
||||||
|
stop_all_streams
|
||||||
|
# Any cleanup needed when channel is unsubscribed
|
||||||
|
end
|
||||||
|
end
|
||||||
30
app/controllers/api/sound_effect_controller.rb
Normal file
30
app/controllers/api/sound_effect_controller.rb
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
class Api::SoundEffectController < Api::ApiController
|
||||||
|
|
||||||
|
#sound effect / alarm api for doemal side calling
|
||||||
|
def sound_effect
|
||||||
|
shop = Shop.find_by_id(1)
|
||||||
|
if !shop.nil?
|
||||||
|
shop_code = shop.shop_code
|
||||||
|
order_audio = DisplayImage.find_by_shop_id_and_name(shop.id, "order_audio")
|
||||||
|
if !order_audio.nil?
|
||||||
|
audio = order_audio.image
|
||||||
|
end
|
||||||
|
else
|
||||||
|
shop_code = nil
|
||||||
|
audio = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
if !shop_code.nil? && !audio.nil?
|
||||||
|
if ENV["SERVER_MODE"] == 'cloud'
|
||||||
|
from = request.subdomain + "." + request.domain
|
||||||
|
else
|
||||||
|
from = ""
|
||||||
|
end
|
||||||
|
ActionCable.server.broadcast "sound_effect_channel",data: {status: params[:status], message: params[:message]},shop_code: shop_code,from:from,audio:audio
|
||||||
|
else
|
||||||
|
render :json => { :status => true, :message => "Something wrongs!" }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
#sound effect / alarm api for doemal side calling
|
||||||
|
|
||||||
|
end
|
||||||
@@ -126,10 +126,13 @@ class HomeController < ApplicationController
|
|||||||
if !employee_sales.nil?
|
if !employee_sales.nil?
|
||||||
employee_sales.each do |emp|
|
employee_sales.each do |emp|
|
||||||
emp_data = []
|
emp_data = []
|
||||||
|
if emp.payment_amount > 0
|
||||||
emp_data.push([emp.e_name, emp.payment_amount])
|
emp_data.push([emp.e_name, emp.payment_amount])
|
||||||
|
|
||||||
@employee_sales.push({'name' => emp.payment_method, 'data' => emp_data})
|
@employee_sales.push({'name' => emp.payment_method, 'data' => emp_data})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
@inventories = StockJournal.inventory_balances(today,@from,@to,@from_time,@to_time).sum(:balance)
|
@inventories = StockJournal.inventory_balances(today,@from,@to,@from_time,@to_time).sum(:balance)
|
||||||
|
|
||||||
@total_trans = Sale.total_trans(today,current_user,@from,@to,@from_time,@to_time)
|
@total_trans = Sale.total_trans(today,current_user,@from,@to,@from_time,@to_time)
|
||||||
|
|||||||
@@ -241,7 +241,7 @@ class Origami::PaymentsController < BaseOrigamiController
|
|||||||
sale_id = params[:sale_id]
|
sale_id = params[:sale_id]
|
||||||
@cashier_type = params[:type]
|
@cashier_type = params[:type]
|
||||||
if path.include? ("credit_payment")
|
if path.include? ("credit_payment")
|
||||||
@sale_payment = SalePayment.get_credit_total_left(sale_id)
|
@sale_payment = SalePayment.get_credit_amount_due_left(sale_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
@member_discount = MembershipSetting.find_by_discount(1)
|
@member_discount = MembershipSetting.find_by_discount(1)
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ class OrderReservation < ApplicationRecord
|
|||||||
order_reservation.discount_amount = order_reserve[:payment_info][:discount_amount]
|
order_reservation.discount_amount = order_reserve[:payment_info][:discount_amount]
|
||||||
order_reservation.convenience_charge = order_reserve[:payment_info][:convenience_charge]
|
order_reservation.convenience_charge = order_reserve[:payment_info][:convenience_charge]
|
||||||
order_reservation.grand_total = order_reserve[:payment_info][:grand_total]
|
order_reservation.grand_total = order_reserve[:payment_info][:grand_total]
|
||||||
|
order_reservation.transaction_fee = order_reserve[:order_info][:transaction_fee]
|
||||||
order_reservation.order_remark = order_reserve[:order_info][:order_remark]
|
order_reservation.order_remark = order_reserve[:order_info][:order_remark]
|
||||||
end
|
end
|
||||||
if order_reserve[:reservation_info]
|
if order_reserve[:reservation_info]
|
||||||
|
|||||||
@@ -82,10 +82,15 @@ class Sale < ApplicationRecord
|
|||||||
self.tax_type = "exclusive"
|
self.tax_type = "exclusive"
|
||||||
|
|
||||||
# set cashier
|
# set cashier
|
||||||
|
if order_source = "emenu"
|
||||||
|
table = DiningFacility.find(booking.dining_facility_id)
|
||||||
|
cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id)
|
||||||
|
shift = ShiftSale.where("shift_started_at is not null and shift_closed_at is null and cashier_terminal_id = #{cashier_zone.cashier_terminal_id}").first
|
||||||
|
else
|
||||||
open_cashier = Employee.where("role = 'cashier' AND token_session <> ''")
|
open_cashier = Employee.where("role = 'cashier' AND token_session <> ''")
|
||||||
current_shift = ShiftSale.current_shift
|
current_shift = ShiftSale.current_shift
|
||||||
shift = ShiftSale.current_open_shift(cashier.id)
|
shift = ShiftSale.current_open_shift(cashier.id)
|
||||||
|
end
|
||||||
# set cashier
|
# set cashier
|
||||||
if shift != nil
|
if shift != nil
|
||||||
self.cashier_id = cashier.id
|
self.cashier_id = cashier.id
|
||||||
@@ -735,12 +740,13 @@ class Sale < ApplicationRecord
|
|||||||
|
|
||||||
|
|
||||||
def self.daily_sales_list(from,to)
|
def self.daily_sales_list(from,to)
|
||||||
sub_query = "SELECT (CASE WHEN SUM(sale_payments.payment_amount) > 0 THEN SUM(sale_payments.payment_amount) ELSE 0 END)
|
sub_query = "SELECT (CASE WHEN SUM(sale_payments.payment_amount) > 0 THEN
|
||||||
|
(SUM(sale_payments.payment_amount) + SUM(sale_payments.outstanding_amount)) ELSE 0 END)
|
||||||
FROM sale_payments
|
FROM sale_payments
|
||||||
INNER JOIN sale_audits sa
|
INNER JOIN sale_audits sa ON SUBSTRING_INDEX(sa.remark,'||',1)=sale_payments.sale_payment_id
|
||||||
ON SUBSTRING_INDEX(sa.remark,'||',1)=sale_payments.sale_payment_id
|
INNER JOIN sales s ON s.sale_id=sa.sale_id
|
||||||
INNER JOIN sales ON sa.sale_id = sales.sale_id
|
WHERE s.sale_status='completed'
|
||||||
WHERE sales.sale_status='completed' AND sales.receipt_date between '#{from}' and '#{to}'"
|
AND DATE_FORMAT(CONVERT_TZ(s.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') = DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d')"
|
||||||
|
|
||||||
payments_total = Sale.select("CAST((CONVERT_TZ(sales.receipt_date,'+00:00','+06:30')) AS DATE) as sale_date,
|
payments_total = Sale.select("CAST((CONVERT_TZ(sales.receipt_date,'+00:00','+06:30')) AS DATE) as sale_date,
|
||||||
SUM(case when (sale_payments.payment_method='mpu') then sale_payments.payment_amount else 0 end) as mpu_amount,
|
SUM(case when (sale_payments.payment_method='mpu') then sale_payments.payment_amount else 0 end) as mpu_amount,
|
||||||
@@ -757,7 +763,7 @@ def self.daily_sales_list(from,to)
|
|||||||
(CASE WHEN (SUM(case when (sale_payments.payment_method='creditnote') then sale_payments.payment_amount else 0 end)) > 0 THEN (SUM(case when (sale_payments.payment_method='creditnote') then sale_payments.payment_amount else 0 end) - (#{sub_query})) ELSE 0 END) as credit_amount,
|
(CASE WHEN (SUM(case when (sale_payments.payment_method='creditnote') then sale_payments.payment_amount else 0 end)) > 0 THEN (SUM(case when (sale_payments.payment_method='creditnote') then sale_payments.payment_amount else 0 end) - (#{sub_query})) ELSE 0 END) as credit_amount,
|
||||||
SUM(case when (sale_payments.payment_method='giftvoucher') then sale_payments.payment_amount else 0 end) as giftvoucher_amount,
|
SUM(case when (sale_payments.payment_method='giftvoucher') then sale_payments.payment_amount else 0 end) as giftvoucher_amount,
|
||||||
SUM(case when (sale_payments.payment_method='foc') then sale_payments.payment_amount else 0 end) as foc_amount")
|
SUM(case when (sale_payments.payment_method='foc') then sale_payments.payment_amount else 0 end) as foc_amount")
|
||||||
.joins(" left join sale_payments on sale_payments.sale_id = sales.sale_id")
|
.joins(" join sale_payments on sale_payments.sale_id = sales.sale_id")
|
||||||
.where("sale_status = ? AND sales.receipt_date between ? and ? ", 'completed', from, to)
|
.where("sale_status = ? AND sales.receipt_date between ? and ? ", 'completed', from, to)
|
||||||
.group("DATE_FORMAT((CONVERT_TZ(sales.receipt_date,'+00:00','+06:30')),'%Y-%m-%d')")
|
.group("DATE_FORMAT((CONVERT_TZ(sales.receipt_date,'+00:00','+06:30')),'%Y-%m-%d')")
|
||||||
|
|
||||||
@@ -1123,7 +1129,8 @@ def self.get_by_shift_sale_credit_payment(shift_sale_range,shift,from,to,filter)
|
|||||||
INNER JOIN sale_audits ON SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id
|
INNER JOIN sale_audits ON SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id
|
||||||
WHERE sale_audits.sale_id = s.sale_id"
|
WHERE sale_audits.sale_id = s.sale_id"
|
||||||
|
|
||||||
sub_query1 = "SELECT (CASE WHEN SUM(payment_amount) > 0 THEN SUM(payment_amount) ELSE 0 END)
|
sub_query1 = "SELECT (CASE WHEN SUM(payment_amount) > 0 THEN SUM(payment_amount) -
|
||||||
|
(SUM(payment_amount) - (SELECT SUM(payment_amount) FROM sale_payments WHERE payment_method='creditnote' AND sale_id=s.sale_id)) ELSE 0 END)
|
||||||
FROM `sale_payments`
|
FROM `sale_payments`
|
||||||
INNER JOIN sale_audits ON SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id
|
INNER JOIN sale_audits ON SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id
|
||||||
WHERE sale_audits.sale_id = s.sale_id"
|
WHERE sale_audits.sale_id = s.sale_id"
|
||||||
@@ -1561,16 +1568,33 @@ end
|
|||||||
|
|
||||||
def self.employee_sales(today,current_user,from,to,from_time,to_time)
|
def self.employee_sales(today,current_user,from,to,from_time,to_time)
|
||||||
#sub query for credit payment
|
#sub query for credit payment
|
||||||
sub_query = "SELECT (CASE WHEN SUM(sale_payments.payment_amount) > 0 THEN SUM(sale_payments.payment_amount) ELSE 0 END) AS payment_amount
|
outstanding_query = "SELECT CASE WHEN SUM(sale_payments.outstanding_amount) < 0 THEN SUM(sale_payments.outstanding_amount) ELSE 0 END
|
||||||
|
FROM sale_payments
|
||||||
|
JOIN sale_audits ON SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id
|
||||||
|
JOIN sales ON sale_audits.sale_id = sales.sale_id
|
||||||
|
WHERE sale_payments.outstanding_amount LIKE '%-%' AND sales.sale_status='completed'"
|
||||||
|
|
||||||
|
if !from.nil? && !to.nil?
|
||||||
|
if !from_time.nil? && !to_time.nil?
|
||||||
|
outstanding_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'"
|
||||||
|
else
|
||||||
|
outstanding_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
outstanding_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') = '#{today}'"
|
||||||
|
end
|
||||||
|
|
||||||
|
sub_query = "SELECT (CASE WHEN SUM(sale_payments.payment_amount) > 0 THEN SUM(sale_payments.payment_amount) + (#{outstanding_query}) ELSE 0 END)
|
||||||
FROM sale_payments
|
FROM sale_payments
|
||||||
INNER JOIN sale_audits ON SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id
|
INNER JOIN sale_audits ON SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id
|
||||||
INNER JOIN sales ON sale_audits.sale_id = sales.sale_id
|
INNER JOIN sales ON sale_audits.sale_id = sales.sale_id
|
||||||
WHERE sales.sale_status='completed'"
|
WHERE sales.sale_status='completed'"
|
||||||
|
|
||||||
if !from.nil? && !to.nil?
|
if !from.nil? && !to.nil?
|
||||||
if !from_time.nil? && !to_time.nil?
|
if !from_time.nil? && !to_time.nil?
|
||||||
sub_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'"
|
sub_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' AND '#{to}' AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'"
|
||||||
else
|
else
|
||||||
sub_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"
|
sub_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' AND '#{to}'"
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
sub_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') = '#{today}'"
|
sub_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') = '#{today}'"
|
||||||
@@ -1751,16 +1775,40 @@ end
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.credit_payment(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
|
def self.credit_payment(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
|
||||||
sub_query = SalePayment.select("(CASE WHEN SUM(sale_payments.payment_amount) > 0 THEN SUM(sale_payments.payment_amount) ELSE 0 END) as total_credit_payment")
|
outstanding_query = "SELECT CASE WHEN SUM(sale_payments.outstanding_amount) < 0 THEN SUM(sale_payments.outstanding_amount) ELSE 0 END
|
||||||
|
FROM sale_payments
|
||||||
|
JOIN sale_audits ON SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id
|
||||||
|
JOIN sales ON sale_audits.sale_id = sales.sale_id
|
||||||
|
WHERE sale_payments.outstanding_amount LIKE '%-%' AND sales.sale_status='completed'"
|
||||||
|
|
||||||
|
if !from.nil? && !to.nil?
|
||||||
|
if !from_time.nil? && !to_time.nil?
|
||||||
|
outstanding_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'"
|
||||||
|
else
|
||||||
|
outstanding_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
outstanding_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') = '#{today}'"
|
||||||
|
end
|
||||||
|
|
||||||
|
sub_query = SalePayment.select("(CASE WHEN SUM(sale_payments.payment_amount) > 0 THEN SUM(sale_payments.payment_amount) + (#{outstanding_query}) ELSE 0 END) as total_credit_payment")
|
||||||
.joins(" JOIN sale_audits ON SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id")
|
.joins(" JOIN sale_audits ON SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id")
|
||||||
.joins(" JOIN sales ON sale_audits.sale_id = sales.sale_id")
|
.joins(" JOIN sales ON sale_audits.sale_id = sales.sale_id")
|
||||||
.where("sales.sale_status='completed'")
|
.where("sales.sale_status='completed'")
|
||||||
|
|
||||||
if !from.nil? && !to.nil?
|
if !from.nil? && !to.nil?
|
||||||
if current_user.nil?
|
|
||||||
if !from_time.nil? && !to_time.nil?
|
if !from_time.nil? && !to_time.nil?
|
||||||
sub_query = sub_query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' AND '#{to}' AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'")
|
sub_query = sub_query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' AND '#{to}' AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'")
|
||||||
|
else
|
||||||
|
sub_query = sub_query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' AND '#{to}'")
|
||||||
|
end
|
||||||
|
else
|
||||||
|
sub_query = sub_query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') = '#{today}'")
|
||||||
|
end
|
||||||
|
|
||||||
|
if !from.nil? && !to.nil?
|
||||||
|
if current_user.nil?
|
||||||
|
if !from_time.nil? && !to_time.nil?
|
||||||
query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time)
|
query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time)
|
||||||
.joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
|
.joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
|
||||||
.sum("payment_amount")
|
.sum("payment_amount")
|
||||||
@@ -1768,7 +1816,6 @@ end
|
|||||||
query = query.to_f - (sub_query[0].total_credit_payment.to_f > 0 ? sub_query[0].total_credit_payment.to_f : 0)
|
query = query.to_f - (sub_query[0].total_credit_payment.to_f > 0 ? sub_query[0].total_credit_payment.to_f : 0)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
sub_query = sub_query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' AND '#{to}'")
|
|
||||||
query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to)
|
query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to)
|
||||||
.joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
|
.joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
|
||||||
.sum("payment_amount")
|
.sum("payment_amount")
|
||||||
@@ -1779,8 +1826,6 @@ end
|
|||||||
else
|
else
|
||||||
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor'
|
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor'
|
||||||
if !from_time.nil? && !to_time.nil?
|
if !from_time.nil? && !to_time.nil?
|
||||||
sub_query = sub_query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' AND '#{to}' AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'")
|
|
||||||
|
|
||||||
query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time)
|
query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time)
|
||||||
.joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
|
.joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
|
||||||
.sum("payment_amount")
|
.sum("payment_amount")
|
||||||
@@ -1788,7 +1833,6 @@ end
|
|||||||
query = query.to_f - (sub_query[0].total_credit_payment.to_f > 0 ? sub_query[0].total_credit_payment.to_f : 0)
|
query = query.to_f - (sub_query[0].total_credit_payment.to_f > 0 ? sub_query[0].total_credit_payment.to_f : 0)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
sub_query = sub_query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' AND '#{to}'")
|
|
||||||
query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to)
|
query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to)
|
||||||
.joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
|
.joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
|
||||||
.sum("payment_amount")
|
.sum("payment_amount")
|
||||||
@@ -1800,7 +1844,6 @@ end
|
|||||||
shift = ShiftSale.current_open_shift(current_user.id)
|
shift = ShiftSale.current_open_shift(current_user.id)
|
||||||
if !shift.nil?
|
if !shift.nil?
|
||||||
if !from_time.nil? && !to_time.nil?
|
if !from_time.nil? && !to_time.nil?
|
||||||
sub_query = sub_query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' AND '#{to}' AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'")
|
|
||||||
query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ? and s.shift_sale_id=?',from,to,from_time,to_time,shift.id)
|
query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ? and s.shift_sale_id=?',from,to,from_time,to_time,shift.id)
|
||||||
.joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
|
.joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
|
||||||
.sum("payment_amount")
|
.sum("payment_amount")
|
||||||
@@ -1808,7 +1851,6 @@ end
|
|||||||
query = query.to_f - (sub_query[0].total_credit_payment.to_f > 0 ? sub_query[0].total_credit_payment.to_f : 0)
|
query = query.to_f - (sub_query[0].total_credit_payment.to_f > 0 ? sub_query[0].total_credit_payment.to_f : 0)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
sub_query = sub_query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' AND '#{to}'")
|
|
||||||
query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and s.shift_sale_id=?',from,to,shift.id)
|
query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and s.shift_sale_id=?',from,to,shift.id)
|
||||||
.joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
|
.joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
|
||||||
.sum("payment_amount")
|
.sum("payment_amount")
|
||||||
@@ -1820,7 +1862,6 @@ end
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
sub_query = sub_query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{today}' AND '#{today}'")
|
|
||||||
if current_user.nil?
|
if current_user.nil?
|
||||||
query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',today,today)
|
query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',today,today)
|
||||||
.joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
|
.joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
|
||||||
@@ -1979,16 +2020,41 @@ end
|
|||||||
time_query = " and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'"
|
time_query = " and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'"
|
||||||
end
|
end
|
||||||
|
|
||||||
sub_query = "SELECT (CASE WHEN SUM(sale_payments.payment_amount) > 0 THEN SUM(sale_payments.payment_amount) ELSE 0 END)
|
outstanding_query = "SELECT CASE WHEN SUM(sale_payments.outstanding_amount) < 0 THEN SUM(sale_payments.outstanding_amount) ELSE 0 END
|
||||||
|
FROM sale_payments
|
||||||
|
JOIN sale_audits ON SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id
|
||||||
|
JOIN sales ON sale_audits.sale_id = sales.sale_id
|
||||||
|
WHERE sale_payments.outstanding_amount LIKE '%-%' AND sales.sale_status='completed'"
|
||||||
|
|
||||||
|
if !from.nil? && !to.nil?
|
||||||
|
if !from_time.nil? && !to_time.nil?
|
||||||
|
outstanding_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'"
|
||||||
|
else
|
||||||
|
outstanding_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
outstanding_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') = '#{today}'"
|
||||||
|
end
|
||||||
|
|
||||||
|
sub_query = "SELECT (CASE WHEN SUM(sale_payments.payment_amount) > 0 THEN SUM(sale_payments.payment_amount) + (#{outstanding_query}) ELSE 0 END)
|
||||||
FROM sale_payments
|
FROM sale_payments
|
||||||
INNER JOIN sale_audits ON SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id
|
INNER JOIN sale_audits ON SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id
|
||||||
INNER JOIN sales ON sale_audits.sale_id = sales.sale_id
|
INNER JOIN sales ON sale_audits.sale_id = sales.sale_id
|
||||||
WHERE sales.sale_status='completed'"
|
WHERE sales.sale_status='completed'"
|
||||||
|
|
||||||
|
if !from.nil? && !to.nil?
|
||||||
|
if !from_time.nil? && !to_time.nil?
|
||||||
|
sub_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' AND '#{to}' AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'"
|
||||||
|
else
|
||||||
|
sub_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' AND '#{to}'"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
sub_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') = '#{today}'"
|
||||||
|
end
|
||||||
|
|
||||||
if !from.nil? && !to.nil?
|
if !from.nil? && !to.nil?
|
||||||
if current_user.nil?
|
if current_user.nil?
|
||||||
if !from_time.nil? && !to_time.nil?
|
if !from_time.nil? && !to_time.nil?
|
||||||
sub_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'"
|
|
||||||
query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
|
query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
|
||||||
if payment_method == 'card'
|
if payment_method == 'card'
|
||||||
query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%H:%i") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method="alipay" or sp.payment_method="paymal" or sp.payment_method="dinga" or sp.payment_method="JunctionPay" or sp.payment_method = "giftvoucher")',from,to,from_time,to_time)
|
query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%H:%i") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method="alipay" or sp.payment_method="paymal" or sp.payment_method="dinga" or sp.payment_method="JunctionPay" or sp.payment_method = "giftvoucher")',from,to,from_time,to_time)
|
||||||
@@ -1997,7 +2063,6 @@ end
|
|||||||
end
|
end
|
||||||
query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) WHEN sp.payment_method='creditnote' THEN SUM(sp.payment_amount) - (#{sub_query}) ELSE SUM(sp.payment_amount) END) as payment_amount").first()
|
query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) WHEN sp.payment_method='creditnote' THEN SUM(sp.payment_amount) - (#{sub_query}) ELSE SUM(sp.payment_amount) END) as payment_amount").first()
|
||||||
else
|
else
|
||||||
sub_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"
|
|
||||||
query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
|
query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
|
||||||
if payment_method == 'card'
|
if payment_method == 'card'
|
||||||
query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay" or sp.payment_method = "giftvoucher")',from,to)
|
query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay" or sp.payment_method = "giftvoucher")',from,to)
|
||||||
@@ -2009,7 +2074,6 @@ end
|
|||||||
else
|
else
|
||||||
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor'
|
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor'
|
||||||
if !from_time.nil? && !to_time.nil?
|
if !from_time.nil? && !to_time.nil?
|
||||||
sub_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'"
|
|
||||||
query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
|
query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
|
||||||
if payment_method == 'card'
|
if payment_method == 'card'
|
||||||
query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%H:%i") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay" or sp.payment_method = "giftvoucher")',from,to,from_time,to_time)
|
query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%H:%i") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay" or sp.payment_method = "giftvoucher")',from,to,from_time,to_time)
|
||||||
@@ -2018,7 +2082,6 @@ end
|
|||||||
end
|
end
|
||||||
query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) WHEN sp.payment_method='creditnote' THEN SUM(sp.payment_amount) - (#{sub_query}) ELSE SUM(sp.payment_amount) END) as payment_amount").first()
|
query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) WHEN sp.payment_method='creditnote' THEN SUM(sp.payment_amount) - (#{sub_query}) ELSE SUM(sp.payment_amount) END) as payment_amount").first()
|
||||||
else
|
else
|
||||||
sub_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"
|
|
||||||
query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
|
query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
|
||||||
if payment_method == 'card'
|
if payment_method == 'card'
|
||||||
query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay" or sp.payment_method = "giftvoucher")',from,to)
|
query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay" or sp.payment_method = "giftvoucher")',from,to)
|
||||||
@@ -2031,7 +2094,6 @@ end
|
|||||||
shift = ShiftSale.current_open_shift(current_user.id)
|
shift = ShiftSale.current_open_shift(current_user.id)
|
||||||
if !shift.nil?
|
if !shift.nil?
|
||||||
if !from_time.nil? && !to_time.nil?
|
if !from_time.nil? && !to_time.nil?
|
||||||
sub_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'"
|
|
||||||
query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
|
query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
|
||||||
if payment_method == 'card'
|
if payment_method == 'card'
|
||||||
query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%H:%i") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay" or sp.payment_method = "giftvoucher") and sales.shift_sale_id=?',from,to,from_time,to_time,shift.id)
|
query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%H:%i") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay" or sp.payment_method = "giftvoucher") and sales.shift_sale_id=?',from,to,from_time,to_time,shift.id)
|
||||||
@@ -2040,7 +2102,6 @@ end
|
|||||||
end
|
end
|
||||||
query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) WHEN sp.payment_method='creditnote' THEN SUM(sp.payment_amount) - (#{sub_query}) ELSE SUM(sp.payment_amount) END) as payment_amount").first()
|
query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) WHEN sp.payment_method='creditnote' THEN SUM(sp.payment_amount) - (#{sub_query}) ELSE SUM(sp.payment_amount) END) as payment_amount").first()
|
||||||
else
|
else
|
||||||
sub_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"
|
|
||||||
query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
|
query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
|
||||||
if payment_method == 'card'
|
if payment_method == 'card'
|
||||||
query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay" or sp.payment_method = "giftvoucher") and sales.shift_sale_id=?',from,to,shift.id)
|
query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay" or sp.payment_method = "giftvoucher") and sales.shift_sale_id=?',from,to,shift.id)
|
||||||
@@ -2053,7 +2114,6 @@ end
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
sub_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') = '#{today}'"
|
|
||||||
if current_user.nil?
|
if current_user.nil?
|
||||||
query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
|
query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
|
||||||
if payment_method == 'card'
|
if payment_method == 'card'
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ class SalePayment < ApplicationRecord
|
|||||||
#get all payment for this invoices
|
#get all payment for this invoices
|
||||||
if payment_for
|
if payment_for
|
||||||
invoice_sale_payments = SalePayment.get_sale_payment_for_credit(invoice)
|
invoice_sale_payments = SalePayment.get_sale_payment_for_credit(invoice)
|
||||||
amount_due = SalePayment.get_credit_total_left(self.sale_id)[0] ? SalePayment.get_credit_total_left(self.sale_id)[0].payment_amount.to_f : 0
|
amount_due = SalePayment.get_credit_amount_due_left(self.sale_id)[0] ? SalePayment.get_credit_amount_due_left(self.sale_id)[0].payment_amount.to_f : 0
|
||||||
else
|
else
|
||||||
invoice_sale_payments = invoice.sale_payments
|
invoice_sale_payments = invoice.sale_payments
|
||||||
amount_due = invoice.grand_total
|
amount_due = invoice.grand_total
|
||||||
@@ -875,13 +875,22 @@ class SalePayment < ApplicationRecord
|
|||||||
return query
|
return query
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.get_credit_total_left(sale_id)
|
def self.get_credit_amount_due_left(sale_id)
|
||||||
query = SalePayment.select("(SUM(sale_payments.payment_amount) -
|
query = SalePayment.select("(SUM(sale_payments.payment_amount) -
|
||||||
(CASE WHEN SUBSTRING_INDEX(sa.remark,'||',1)=sale_payments.sale_payment_id
|
(CASE WHEN SUBSTRING_INDEX(sa.remark,'||',1)=sale_payments.sale_payment_id
|
||||||
THEN SUM(sale_payments.payment_amount) ELSE 0 END)) as payment_amount")
|
THEN SUM(sale_payments.payment_amount) ELSE 0 END)) as payment_amount")
|
||||||
.joins(" LEFT JOIN sale_audits sa on SUBSTRING_INDEX(sa.remark,'||',1)=sale_payments.sale_payment_id")
|
.joins(" LEFT JOIN sale_audits sa on SUBSTRING_INDEX(sa.remark,'||',1)=sale_payments.sale_payment_id")
|
||||||
.where("sale_payments.payment_method = 'creditnote' AND sale_payments.sale_id = '#{sale_id}'")
|
.where("sale_payments.payment_method = 'creditnote' AND sale_payments.sale_id = '#{sale_id}'")
|
||||||
.group("sale_payments.sale_id")
|
return query
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.get_credit_total_left(sale_id)
|
||||||
|
query = SalePayment.select("(SUM(sale_payments.payment_amount) -
|
||||||
|
(SELECT (CASE WHEN SUM(sale_payments.payment_amount) > 0 THEN SUM(sale_payments.payment_amount) ELSE 0 END) AS payment_amount
|
||||||
|
FROM sale_payments
|
||||||
|
INNER JOIN sale_audits ON SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id
|
||||||
|
WHERE sale_payments.sale_id = '#{sale_id}')) as payment_amount")
|
||||||
|
.where("sale_payments.payment_method = 'creditnote' AND sale_payments.sale_id = '#{sale_id}'")
|
||||||
return query
|
return query
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -44,8 +44,8 @@
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
var old_value = $("#login_form_password").val();
|
var old_value = $("#login_form_password").val();
|
||||||
var value = $(this).data("value");
|
var value = $(this).data("value");
|
||||||
console.log(old_value);
|
// console.log(old_value);
|
||||||
console.log(value);
|
// console.log(value);
|
||||||
if (value == "CLR") {
|
if (value == "CLR") {
|
||||||
$("#login_form_password").val("");
|
$("#login_form_password").val("");
|
||||||
} else if (value == "ENT") {
|
} else if (value == "ENT") {
|
||||||
|
|||||||
@@ -57,6 +57,7 @@
|
|||||||
<th><%= t("views.right_panel.detail.commercial_tax") %></th>
|
<th><%= t("views.right_panel.detail.commercial_tax") %></th>
|
||||||
<th><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.tax") %></th>
|
<th><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.tax") %></th>
|
||||||
<th><%= t("views.right_panel.detail.grand_total") %></th>
|
<th><%= t("views.right_panel.detail.grand_total") %></th>
|
||||||
|
<th><%= t("views.right_panel.detail.transaction_fee") %></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@@ -88,6 +89,7 @@
|
|||||||
total_tax = 0.0
|
total_tax = 0.0
|
||||||
total_amount = 0.0
|
total_amount = 0.0
|
||||||
grand_total = 0.0
|
grand_total = 0.0
|
||||||
|
transaction_fee = 0.0
|
||||||
%>
|
%>
|
||||||
<% unless @order_reservation_data.blank? %>
|
<% unless @order_reservation_data.blank? %>
|
||||||
<% @order_reservation_data.each do |order_reservation| %>
|
<% @order_reservation_data.each do |order_reservation| %>
|
||||||
@@ -117,6 +119,9 @@
|
|||||||
total_amount += order_reservation.total_amount.to_f
|
total_amount += order_reservation.total_amount.to_f
|
||||||
grand_total += order_reservation.grand_total.to_f
|
grand_total += order_reservation.grand_total.to_f
|
||||||
%>
|
%>
|
||||||
|
<% if order_reservation.transaction_fee && order_reservation.transaction_fee > 0
|
||||||
|
transaction_fee += order_reservation.transaction_fee.to_f
|
||||||
|
end %>
|
||||||
<%
|
<%
|
||||||
if order_reservation.provider == 'pick_up'
|
if order_reservation.provider == 'pick_up'
|
||||||
provider = "Pick-Up"
|
provider = "Pick-Up"
|
||||||
@@ -149,6 +154,7 @@
|
|||||||
<td><%= number_with_precision(commercial_tax , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%></td>
|
<td><%= number_with_precision(commercial_tax , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%></td>
|
||||||
<td><%= number_with_precision(order_reservation.total_tax , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%></td>
|
<td><%= number_with_precision(order_reservation.total_tax , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%></td>
|
||||||
<td><%= number_with_precision(order_reservation.grand_total , precision:precision.to_i, delimiter:delimiter) rescue '0.0' %></td>
|
<td><%= number_with_precision(order_reservation.grand_total , precision:precision.to_i, delimiter:delimiter) rescue '0.0' %></td>
|
||||||
|
<td><%= number_with_precision(order_reservation.transaction_fee , precision:precision.to_i, delimiter:delimiter) rescue '0.0' %></td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end
|
<% end
|
||||||
end %>
|
end %>
|
||||||
@@ -164,6 +170,7 @@
|
|||||||
<td><b><%= number_with_precision(total_commercial_tax , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%></b></td>
|
<td><b><%= number_with_precision(total_commercial_tax , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%></b></td>
|
||||||
<td><b><%= number_with_precision(total_tax , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%></b></td>
|
<td><b><%= number_with_precision(total_tax , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%></b></td>
|
||||||
<td><b><%= number_with_precision(grand_total , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%></b></td>
|
<td><b><%= number_with_precision(grand_total , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%></b></td>
|
||||||
|
<td><b><%= number_with_precision(transaction_fee , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%></b></td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
@@ -40,6 +40,7 @@
|
|||||||
<th><%= t("views.right_panel.detail.commercial_tax") %></th>
|
<th><%= t("views.right_panel.detail.commercial_tax") %></th>
|
||||||
<th><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.tax") %></th>
|
<th><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.tax") %></th>
|
||||||
<th><%= t("views.right_panel.detail.grand_total") %></th>
|
<th><%= t("views.right_panel.detail.grand_total") %></th>
|
||||||
|
<th><%= t("views.right_panel.detail.transaction_fee") %></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@@ -61,6 +62,7 @@
|
|||||||
total_tax = 0.0
|
total_tax = 0.0
|
||||||
total_amount = 0.0
|
total_amount = 0.0
|
||||||
grand_total = 0.0
|
grand_total = 0.0
|
||||||
|
transaction_fee = 0.0
|
||||||
%>
|
%>
|
||||||
<% unless @order_reservation_data.blank? %>
|
<% unless @order_reservation_data.blank? %>
|
||||||
<% @order_reservation_data.each do |order_reservation| %>
|
<% @order_reservation_data.each do |order_reservation| %>
|
||||||
@@ -91,6 +93,9 @@
|
|||||||
total_amount += order_reservation.total_amount.to_f
|
total_amount += order_reservation.total_amount.to_f
|
||||||
grand_total += order_reservation.grand_total.to_f
|
grand_total += order_reservation.grand_total.to_f
|
||||||
%>
|
%>
|
||||||
|
<% if order_reservation.transaction_fee && order_reservation.transaction_fee > 0
|
||||||
|
transaction_fee += order_reservation.transaction_fee.to_f
|
||||||
|
end %>
|
||||||
<%
|
<%
|
||||||
if order_reservation.provider == 'pick_up'
|
if order_reservation.provider == 'pick_up'
|
||||||
provider = "Pick-Up"
|
provider = "Pick-Up"
|
||||||
@@ -123,6 +128,7 @@
|
|||||||
<td><%= commercial_tax rescue '0.0'%></td>
|
<td><%= commercial_tax rescue '0.0'%></td>
|
||||||
<td><%= order_reservation.total_tax rescue '0.0'%></td>
|
<td><%= order_reservation.total_tax rescue '0.0'%></td>
|
||||||
<td><%= order_reservation.grand_total rescue '0.0' %></td>
|
<td><%= order_reservation.grand_total rescue '0.0' %></td>
|
||||||
|
<td><%= order_reservation.transaction_fee rescue '0.0' %></td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end
|
<% end
|
||||||
end %>
|
end %>
|
||||||
@@ -138,6 +144,7 @@
|
|||||||
<td><b><%= total_commercial_tax rescue '0.0'%></b></td>
|
<td><b><%= total_commercial_tax rescue '0.0'%></b></td>
|
||||||
<td><b><%= total_tax rescue '0.0'%></b></td>
|
<td><b><%= total_tax rescue '0.0'%></b></td>
|
||||||
<td><b><%= grand_total rescue '0.0'%></b></td>
|
<td><b><%= grand_total rescue '0.0'%></b></td>
|
||||||
|
<td><b><%= transaction_fee rescue '0.0'%></b></td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
@@ -116,6 +116,7 @@
|
|||||||
discount_amount = order_reservation.discount_amount
|
discount_amount = order_reservation.discount_amount
|
||||||
delivery_fee = order_reservation.delivery_fee ? order_reservation.delivery_fee : 0.0
|
delivery_fee = order_reservation.delivery_fee ? order_reservation.delivery_fee : 0.0
|
||||||
convenience_charge = order_reservation.convenience_charge
|
convenience_charge = order_reservation.convenience_charge
|
||||||
|
if !JSON.parse(order_reservation.taxes).empty?
|
||||||
JSON.parse(order_reservation.taxes).each do |tax_data|
|
JSON.parse(order_reservation.taxes).each do |tax_data|
|
||||||
if tax_data[0] == "delivery_tax"
|
if tax_data[0] == "delivery_tax"
|
||||||
delivery_tax = tax_data[1]
|
delivery_tax = tax_data[1]
|
||||||
@@ -125,6 +126,7 @@
|
|||||||
commercial_tax = tax_data[1]
|
commercial_tax = tax_data[1]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
%>
|
%>
|
||||||
<%
|
<%
|
||||||
if order_reservation.provider == 'pick_up'
|
if order_reservation.provider == 'pick_up'
|
||||||
|
|||||||
@@ -104,6 +104,7 @@
|
|||||||
discount_amount = @order_reservation.discount_amount
|
discount_amount = @order_reservation.discount_amount
|
||||||
delivery_fee = @order_reservation.delivery_fee ? @order_reservation.delivery_fee : 0.0
|
delivery_fee = @order_reservation.delivery_fee ? @order_reservation.delivery_fee : 0.0
|
||||||
convenience_charge = @order_reservation.convenience_charge
|
convenience_charge = @order_reservation.convenience_charge
|
||||||
|
if !JSON.parse(order_reservation.taxes).empty?
|
||||||
JSON.parse(@order_reservation.taxes).each do |tax_data|
|
JSON.parse(@order_reservation.taxes).each do |tax_data|
|
||||||
if tax_data[0] == "delivery_tax"
|
if tax_data[0] == "delivery_tax"
|
||||||
delivery_tax = tax_data[1]
|
delivery_tax = tax_data[1]
|
||||||
@@ -113,6 +114,7 @@
|
|||||||
commercial_tax = tax_data[1]
|
commercial_tax = tax_data[1]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
total_discount_amount += discount_amount.to_f
|
total_discount_amount += discount_amount.to_f
|
||||||
total_delivery_fee += delivery_fee.to_f
|
total_delivery_fee += delivery_fee.to_f
|
||||||
total_convenience_charge += convenience_charge.to_f
|
total_convenience_charge += convenience_charge.to_f
|
||||||
|
|||||||
@@ -53,9 +53,7 @@ Rails.application.config.assets.precompile += %w( sx-sidebar.css )
|
|||||||
Rails.application.config.assets.precompile += %w( inventory_definitions.css )
|
Rails.application.config.assets.precompile += %w( inventory_definitions.css )
|
||||||
Rails.application.config.assets.precompile += %w( inventory.js )
|
Rails.application.config.assets.precompile += %w( inventory.js )
|
||||||
|
|
||||||
# --- Customer/ Customer - Crm ----
|
# --- Order Reservation/ Order ----
|
||||||
Rails.application.config.assets.precompile += %w( order_reservation.css )
|
Rails.application.config.assets.precompile += %w( order_reservation.css )
|
||||||
Rails.application.config.assets.precompile += %w( order_reservation.js )
|
Rails.application.config.assets.precompile += %w( order_reservation.js )
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -491,6 +491,7 @@ en:
|
|||||||
induty_report: "Induty Report"
|
induty_report: "Induty Report"
|
||||||
in_time: "In Time"
|
in_time: "In Time"
|
||||||
out_time: "Out Time"
|
out_time: "Out Time"
|
||||||
|
transaction_fee: "Transaction Fee"
|
||||||
|
|
||||||
code_txt: "code "
|
code_txt: "code "
|
||||||
charge_txt: "charge"
|
charge_txt: "charge"
|
||||||
|
|||||||
@@ -485,6 +485,7 @@ mm:
|
|||||||
induty_report: "Induty Report"
|
induty_report: "Induty Report"
|
||||||
in_time: "In Time"
|
in_time: "In Time"
|
||||||
out_time: "Out Time"
|
out_time: "Out Time"
|
||||||
|
transaction_fee: "Transaction Fee"
|
||||||
|
|
||||||
code_txt: "ကုတ်ဒ် "
|
code_txt: "ကုတ်ဒ် "
|
||||||
charge_txt: "ကောက်ခံသည်"
|
charge_txt: "ကောက်ခံသည်"
|
||||||
|
|||||||
@@ -91,6 +91,8 @@ scope "(:locale)", locale: /en|mm/ do
|
|||||||
post "callback/:id" => "order_reservation#update_status"
|
post "callback/:id" => "order_reservation#update_status"
|
||||||
get "get_tax_profile" => "order_reservation#get_tax_profile"
|
get "get_tax_profile" => "order_reservation#get_tax_profile"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
post "sound_effect" => "sound_effect#sound_effect"
|
||||||
end
|
end
|
||||||
|
|
||||||
#--------- Cashier ------------#
|
#--------- Cashier ------------#
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ class CreateOrderReservations < ActiveRecord::Migration[5.1]
|
|||||||
t.decimal :discount_amount, :precision => 10, :scale => 2, :null => false, :default => 0.00
|
t.decimal :discount_amount, :precision => 10, :scale => 2, :null => false, :default => 0.00
|
||||||
t.decimal :convenience_charge, :precision => 10, :scale => 2, :null => false, :default => 0.00
|
t.decimal :convenience_charge, :precision => 10, :scale => 2, :null => false, :default => 0.00
|
||||||
t.decimal :grand_total, :precision => 10, :scale => 2, :null => false, :default => 0.00
|
t.decimal :grand_total, :precision => 10, :scale => 2, :null => false, :default => 0.00
|
||||||
|
t.decimal :transaction_fee, :precision => 10, :scale => 2, :null => false, :default => 0.00
|
||||||
t.string :status, :null => false, :default => "new"
|
t.string :status, :null => false, :default => "new"
|
||||||
t.string :order_remark
|
t.string :order_remark
|
||||||
t.string :remark
|
t.string :remark
|
||||||
|
|||||||
Reference in New Issue
Block a user