diff --git a/app/assets/javascripts/app/controllers/origami/bank_integration.coffee b/app/assets/javascripts/app/controllers/origami/bank_integration.coffee deleted file mode 100644 index 24f83d18..00000000 --- a/app/assets/javascripts/app/controllers/origami/bank_integration.coffee +++ /dev/null @@ -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/ diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index c6247962..54b1996e 100755 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -28,6 +28,7 @@ //= require raphael/raphael.min //= require Chart.bundle //= require chartkick +//= require cable //= require fileinput.min.js //= require settings/processing_items //= require BSBMaterial/admin.js diff --git a/app/assets/javascripts/channels/order.js b/app/assets/javascripts/channels/order.js index 9326b2cc..4a9e8a95 100755 --- a/app/assets/javascripts/channels/order.js +++ b/app/assets/javascripts/channels/order.js @@ -5,8 +5,8 @@ App.order = App.cable.subscriptions.create('OrderChannel', { received: function(data) { var hostname = location.hostname.trim(); - console.log(hostname) - console.log(data.from) + // console.log(hostname) + // console.log(data.from) if(data.from == "" || hostname == data.from) { if (data.type == 'order') { diff --git a/app/assets/javascripts/channels/sound_effect.js b/app/assets/javascripts/channels/sound_effect.js new file mode 100644 index 00000000..4b988dda --- /dev/null +++ b/app/assets/javascripts/channels/sound_effect.js @@ -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(); + } + }); + } + } + } +}); + diff --git a/app/channels/sound_effect_channel.rb b/app/channels/sound_effect_channel.rb new file mode 100644 index 00000000..2b3f3ee6 --- /dev/null +++ b/app/channels/sound_effect_channel.rb @@ -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 \ No newline at end of file diff --git a/app/controllers/api/sound_effect_controller.rb b/app/controllers/api/sound_effect_controller.rb new file mode 100644 index 00000000..e53e69b9 --- /dev/null +++ b/app/controllers/api/sound_effect_controller.rb @@ -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 diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 6447858b..235b5073 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -241,7 +241,7 @@ class Origami::PaymentsController < BaseOrigamiController sale_id = params[:sale_id] @cashier_type = params[:type] 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 @member_discount = MembershipSetting.find_by_discount(1) diff --git a/app/models/order_reservation.rb b/app/models/order_reservation.rb index a1450444..5fdc9643 100644 --- a/app/models/order_reservation.rb +++ b/app/models/order_reservation.rb @@ -70,6 +70,7 @@ class OrderReservation < ApplicationRecord order_reservation.discount_amount = order_reserve[:payment_info][:discount_amount] order_reservation.convenience_charge = order_reserve[:payment_info][:convenience_charge] 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] end if order_reserve[:reservation_info] diff --git a/app/models/sale.rb b/app/models/sale.rb index db9ca306..2634a695 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -82,10 +82,15 @@ class Sale < ApplicationRecord self.tax_type = "exclusive" # set cashier - open_cashier = Employee.where("role = 'cashier' AND token_session <> ''") - current_shift = ShiftSale.current_shift - shift = ShiftSale.current_open_shift(cashier.id) - + 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 <> ''") + current_shift = ShiftSale.current_shift + shift = ShiftSale.current_open_shift(cashier.id) + end # set cashier if shift != nil self.cashier_id = cashier.id @@ -1553,16 +1558,33 @@ end def self.employee_sales(today,current_user,from,to,from_time,to_time) #sub query for credit payment - 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) AS payment_amount - FROM sale_payments - 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 - WHERE sales.sale_status='completed'" + 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? - 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}'" + 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 - sub_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'" + 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 + 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 + 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}'" @@ -1743,16 +1765,40 @@ end end 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) + SUM(sale_payments.outstanding_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 sales ON sale_audits.sale_id = sales.sale_id") .where("sales.sale_status='completed'") + if !from.nil? && !to.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}'") + 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? - 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) .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") .sum("payment_amount") @@ -1760,7 +1806,6 @@ end query = query.to_f - (sub_query[0].total_credit_payment.to_f > 0 ? sub_query[0].total_credit_payment.to_f : 0) end 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) .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") .sum("payment_amount") @@ -1771,8 +1816,6 @@ end else if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' 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) .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") .sum("payment_amount") @@ -1780,7 +1823,6 @@ end query = query.to_f - (sub_query[0].total_credit_payment.to_f > 0 ? sub_query[0].total_credit_payment.to_f : 0) end 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) .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") .sum("payment_amount") @@ -1792,7 +1834,6 @@ end shift = ShiftSale.current_open_shift(current_user.id) if !shift.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) .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") .sum("payment_amount") @@ -1800,7 +1841,6 @@ end query = query.to_f - (sub_query[0].total_credit_payment.to_f > 0 ? sub_query[0].total_credit_payment.to_f : 0) end 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) .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") .sum("payment_amount") @@ -1812,7 +1852,6 @@ end end end 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? 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") @@ -1971,16 +2010,41 @@ end time_query = " and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'" 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) + 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 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 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 current_user.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") 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) @@ -1989,7 +2053,6 @@ 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() 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") 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) @@ -2001,7 +2064,6 @@ end else if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' 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") 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) @@ -2010,7 +2072,6 @@ 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() 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") 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) @@ -2023,7 +2084,6 @@ end shift = ShiftSale.current_open_shift(current_user.id) if !shift.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") 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) @@ -2032,7 +2092,6 @@ 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() 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") 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) @@ -2045,7 +2104,6 @@ end end end else - sub_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') = '#{today}'" if current_user.nil? query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") if payment_method == 'card' diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 41ec593a..3e0ad377 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -16,7 +16,7 @@ class SalePayment < ApplicationRecord #get all payment for this invoices if payment_for 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 invoice_sale_payments = invoice.sale_payments amount_due = invoice.grand_total @@ -875,13 +875,22 @@ class SalePayment < ApplicationRecord return query 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) - (CASE WHEN SUBSTRING_INDEX(sa.remark,'||',1)=sale_payments.sale_payment_id 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") .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 end diff --git a/app/views/home/show.html.erb b/app/views/home/show.html.erb index 4d1096c8..c8fc81a8 100755 --- a/app/views/home/show.html.erb +++ b/app/views/home/show.html.erb @@ -44,8 +44,8 @@ event.preventDefault(); var old_value = $("#login_form_password").val(); var value = $(this).data("value"); - console.log(old_value); - console.log(value); + // console.log(old_value); + // console.log(value); if (value == "CLR") { $("#login_form_password").val(""); } else if (value == "ENT") { diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index bd889f51..cede4a18 100755 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -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.js ) -# --- Customer/ Customer - Crm ---- +# --- Order Reservation/ Order ---- Rails.application.config.assets.precompile += %w( order_reservation.css ) Rails.application.config.assets.precompile += %w( order_reservation.js ) - - diff --git a/config/routes.rb b/config/routes.rb index cb5f742b..2926ab5c 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -91,6 +91,8 @@ scope "(:locale)", locale: /en|mm/ do post "callback/:id" => "order_reservation#update_status" get "get_tax_profile" => "order_reservation#get_tax_profile" end + + post "sound_effect" => "sound_effect#sound_effect" end #--------- Cashier ------------#