diff --git a/README.md b/README.md
index bdc4c76b..bdaec79e 100755
--- a/README.md
+++ b/README.md
@@ -251,6 +251,9 @@ For Dashboard Settings for supervisor and cashier
For Customer Settings On/Off
1) settings/lookups => {type:customer_settings, name:create, value: {1 or 0}}
+For TaxProfiles On/Off
+ 1) settings/lookups => {type:changable_tax, name:change, value: {1 or 0}}
+
* ToDo list
1. Migration
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/bill_controller.rb b/app/controllers/api/bill_controller.rb
index d5eb77b1..b71d3460 100755
--- a/app/controllers/api/bill_controller.rb
+++ b/app/controllers/api/bill_controller.rb
@@ -14,10 +14,35 @@ class Api::BillController < Api::ApiController
# for Multiple Cashier by Zone
table = DiningFacility.find(booking.dining_facility_id)
+ bk_order = BookingOrder.find_by_booking_id(booking.booking_id)
+ order = Order.find(bk_order.order_id)
+
+ cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id)
+ puts cashier_zone.to_json
+ puts "cashier_zone"
+ 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
+ if !shift.nil?
+ cashier = Employee.find(shift.employee_id)
+ else
+ multiple_zone = CashierTerminalByZone.where('zone_id = #{cashier_zone.zone_id}')
+ puts cashier_zone.to_json
+ puts "cashier_zone"
+ multiple_zone.each do |zone|
+ shift = ShiftSale.where("shift_started_at is not null and shift_closed_at is null and cashier_terminal_id = #{zone.cashier_terminal_id}").first
+ puts shift.to_json
+ puts "shift"
+ if !shift.nil? then
+ cashier = Employee.find(shift.employee_id)
+ break
+ end
+
+ end
+ end
+
if booking
if booking.sale_id.nil?
@sale = Sale.new
- @status, @sale_id = @sale.generate_invoice_from_booking(params[:booking_id], current_login_employee, current_login_employee, "cashier")
+ @status, @sale_id = @sale.generate_invoice_from_booking(params[:booking_id], current_login_employee, cashier, order.source)
@sale_data = Sale.find_by_sale_id(@sale_id)
else
@status = true
@@ -41,8 +66,9 @@ class Api::BillController < Api::ApiController
end
elsif (params[:order_id])
+ order = Order.find(params[:order_id])
@sale = Sale.new
- @status, @sale_id = @sale.generate_invoice_from_order(params[:order_id], current_login_employee, get_cashier, "cashier")
+ @status, @sale_id = @sale.generate_invoice_from_order(params[:order_id], current_login_employee, get_cashier, order.source)
# for Job
booking = Booking.find_by_sale_id(@sale_id)
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/crm/customers_controller.rb b/app/controllers/crm/customers_controller.rb
index 70f5a617..a64d7af4 100644
--- a/app/controllers/crm/customers_controller.rb
+++ b/app/controllers/crm/customers_controller.rb
@@ -39,7 +39,9 @@ class Crm::CustomersController < BaseCrmController
@membership_types = Lookup.collection_of("member_group_type")
- @taxes = TaxProfile.where(:group_type => 'cashier')
+ # @taxes = TaxProfile.where(:group_type => 'cashier')
+ @taxes = TaxProfile.unscoped.select("id, (CONCAT(name,'(',(SELECT name FROM lookups WHERE lookup_type='tax_profiles' AND value=group_type),')')) as name")
+ .order("group_type ASC,order_by ASC")
@filter = filter
diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb
index 7d87ea8f..0d155b9e 100755
--- a/app/controllers/home_controller.rb
+++ b/app/controllers/home_controller.rb
@@ -126,8 +126,11 @@ class HomeController < ApplicationController
if !employee_sales.nil?
employee_sales.each do |emp|
emp_data = []
- emp_data.push([emp.e_name, emp.payment_amount])
- @employee_sales.push({'name' => emp.payment_method, 'data' => emp_data})
+ if emp.payment_amount > 0
+ emp_data.push([emp.e_name, emp.payment_amount])
+
+ @employee_sales.push({'name' => emp.payment_method, 'data' => emp_data})
+ end
end
end
@inventories = StockJournal.inventory_balances(today,@from,@to,@from_time,@to_time).sum(:balance)
diff --git a/app/controllers/origami/customers_controller.rb b/app/controllers/origami/customers_controller.rb
index 8e002532..0eee0400 100644
--- a/app/controllers/origami/customers_controller.rb
+++ b/app/controllers/origami/customers_controller.rb
@@ -87,7 +87,9 @@ class Origami::CustomersController < BaseOrigamiController
@crm_customer = Customer.new
@count_customer = Customer.count_customer
- @taxes = TaxProfile.where(:group_type => 'cashier')
+ # @taxes = TaxProfile.where(:group_type => 'cashier')
+ @taxes = TaxProfile.unscoped.select("id, (CONCAT(name,'(',(SELECT name FROM lookups WHERE lookup_type='tax_profiles' AND value=group_type),')')) as name")
+ .order("group_type ASC,order_by ASC")
# if flash["errors"]
# @crm_customer.valid?
# end
diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb
index 46c7e236..44b3e1e3 100755
--- a/app/controllers/origami/home_controller.rb
+++ b/app/controllers/origami/home_controller.rb
@@ -130,6 +130,19 @@ class Origami::HomeController < BaseOrigamiController
end
end
end
+
+ #for changable on/off
+ @changable_tax = true
+ lookup_changable_tax = Lookup.collection_of('changable_tax')
+ if !lookup_changable_tax.empty?
+ lookup_changable_tax.each do |changable_tax|
+ if changable_tax[0].downcase == "change"
+ if changable_tax[1] == '0'
+ @changable_tax = false
+ end
+ end
+ end
+ end
end
def check_emp_access_code
diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb
index 6447858b..4db5e225 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)
@@ -271,6 +271,20 @@ class Origami::PaymentsController < BaseOrigamiController
if !@lookup_pdf.nil?
@pdf_view = @lookup_pdf.value
end
+
+ #for changable on/off
+ @changable_tax = true
+ lookup_changable_tax = Lookup.collection_of('changable_tax')
+ if !lookup_changable_tax.empty?
+ lookup_changable_tax.each do |changable_tax|
+ if changable_tax[0].downcase == "change"
+ if changable_tax[1] == '0'
+ @changable_tax = false
+ end
+ end
+ end
+ end
+
@shop = shop_detail #show shop info
@customer_lists = Customer.where("customer_id = 'CUS-000000000001' or customer_id = 'CUS-000000000002'")
diff --git a/app/controllers/origami/rooms_controller.rb b/app/controllers/origami/rooms_controller.rb
index c833c7dd..abdd8842 100755
--- a/app/controllers/origami/rooms_controller.rb
+++ b/app/controllers/origami/rooms_controller.rb
@@ -154,6 +154,19 @@ class Origami::RoomsController < BaseOrigamiController
end
end
end
+
+ #for changable on/off
+ @changable_tax = true
+ lookup_changable_tax = Lookup.collection_of('changable_tax')
+ if !lookup_changable_tax.empty?
+ lookup_changable_tax.each do |changable_tax|
+ if changable_tax[0].downcase == "change"
+ if changable_tax[1] == '0'
+ @changable_tax = false
+ end
+ end
+ end
+ end
end
end
diff --git a/app/controllers/origami/sales_controller.rb b/app/controllers/origami/sales_controller.rb
index 876a8ed3..b9cc40ec 100755
--- a/app/controllers/origami/sales_controller.rb
+++ b/app/controllers/origami/sales_controller.rb
@@ -25,6 +25,7 @@ class Origami::SalesController < BaseOrigamiController
def add_to_existing_invoice
dining = params[:dining_id]
sale_id = params[:sale_id]
+ tax_type = params[:tax_type]
table = DiningFacility.find(dining)
existing_booking = Booking.find_by_sale_id(sale_id)
table.bookings.each do |booking|
@@ -51,7 +52,7 @@ class Origami::SalesController < BaseOrigamiController
end
# Re-compute for add
- saleobj.compute(order.source)
+ saleobj.compute(order.source,tax_type)
saleobj.save
order.save
booking.save
diff --git a/app/controllers/settings/tax_profiles_controller.rb b/app/controllers/settings/tax_profiles_controller.rb
index 75e4343e..7357e21d 100755
--- a/app/controllers/settings/tax_profiles_controller.rb
+++ b/app/controllers/settings/tax_profiles_controller.rb
@@ -76,9 +76,15 @@ class Settings::TaxProfilesController < ApplicationController
# DELETE /settings/tax_profiles/1
# DELETE /settings/tax_profiles/1.json
def destroy
- @settings_tax_profile.destroy
- flash[:notice] = 'Tax profile was successfully destroyed.'
- render :json => {:status=> "Success", :url => settings_tax_profiles_url }.to_json
+ customers = Customer.where("tax_profiles LIKE '%#{@settings_tax_profile.id}%'")
+ if customers.nil? || customers.empty?
+ @settings_tax_profile.destroy
+ flash[:notice] = 'Tax profile was successfully destroyed.'
+ render :json => {:status=> "Success", :url => settings_tax_profiles_url }.to_json
+ else
+ flash[:error] = 'Tax profile could not destroy! This record is using in somewhere.'
+ render :json => {:status=> "Error", :url => settings_tax_profiles_url }.to_json
+ end
# respond_to do |format|
# format.html { redirect_to settings_tax_profiles_url, notice: 'Tax profile was successfully destroyed.' }
# format.json { head :no_content }
diff --git a/app/models/order_reservation.rb b/app/models/order_reservation.rb
index a1450444..9fbc7e4d 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[:payment_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 e504bb3d..26ed6e43 100644
--- a/app/models/sale.rb
+++ b/app/models/sale.rb
@@ -83,10 +83,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.downcase == "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
@@ -318,7 +323,7 @@ class Sale < ApplicationRecord
end
#compute - invoice total
- def compute(order_source = nil)
+ def compute(order_source = nil, tax_type = nil)
sales_items = self.sale_items
#Computation Fields
@@ -337,7 +342,7 @@ class Sale < ApplicationRecord
# total_taxable = total_taxable + (item.taxable_price * item.qty)
end
- apply_tax(total_taxable, order_source)
+ apply_tax(total_taxable, order_source, tax_type)
self.total_amount = subtotal_price
self.total_discount = total_discount
@@ -430,8 +435,21 @@ class Sale < ApplicationRecord
total_tax_amount = 0
tax_incl_exec = "exclusive"
#tax_profile - list by order_by
- tax_profiles = TaxProfile.all.order("order_by asc")
- customer = Customer.find(sale.customer_id)
+ # tax_profiles = TaxProfile.all.order("order_by asc")
+ # customer = Customer.find(sale.customer_id)
+ arr_tax = []
+ arr_tax = unique_tax_profiles(order_source, self.customer_id)
+
+ if !arr_tax.empty?
+ if tax_type.nil?
+ tax_profiles = TaxProfile.unscoped.where(:id => arr_tax)
+ else
+ tax_profiles = TaxProfile.unscoped.where("group_type=?",order_source)
+ end
+ else
+ tax_profiles = TaxProfile.unscoped.where("group_type=?",order_source)
+ end
+
# #Creat new tax records
if order_source.to_s == "emenu"
order_source = "cashier"
@@ -501,7 +519,7 @@ class Sale < ApplicationRecord
end
# Tax Calculate
- def apply_tax(total_taxable, order_source = nil)
+ def apply_tax(total_taxable, order_source = nil, tax_type = nil)
shop = Shop.first
#if tax is not apply create new record
@@ -513,24 +531,37 @@ class Sale < ApplicationRecord
total_tax_amount = 0
tax_incl_exec = "exclusive"
#tax_profile - list by order_by
- tax_profiles = TaxProfile.all.order("order_by asc")
-
- customer = Customer.find(self.customer_id)
+ # tax_profiles = TaxProfile.all.order("order_by asc")
if order_source.to_s == "emenu"
order_source = "cashier"
end
+ # tax_data = TaxProfile.unscoped.where("group_type=?",order_source).pluck(:id)
+ # customer = Customer.find(self.customer_id).tax_profiles
+
+ arr_tax = []
+ arr_tax = unique_tax_profiles(order_source, self.customer_id)
+
+ if !arr_tax.empty?
+ if tax_type.nil?
+ tax_profiles = TaxProfile.unscoped.where(:id => arr_tax)
+ else
+ tax_profiles = TaxProfile.unscoped.where("group_type=?",order_source)
+ end
+ else
+ tax_profiles = TaxProfile.unscoped.where("group_type=?",order_source)
+ end
#Create new tax records
tax_profiles.each do |tax|
if tax.group_type.to_s == order_source.to_s
- # customer.tax_profiles.each do |cus_tax|
- # if cus_tax.to_i == tax.id
+ if tax_type
+ if tax_type.to_s == tax.name.to_s || tax_type == 'all'
sale_tax = SaleTax.new(:sale => self)
sale_tax.tax_name = tax.name
sale_tax.tax_rate = tax.rate
# substract , to give after discount
- total_tax = total_taxable - self.total_discount
+ total_tax = total_taxable - total_discount
#include or execulive
if tax.inclusive
tax_incl_exec = "inclusive"
@@ -541,20 +572,47 @@ class Sale < ApplicationRecord
sale_tax.tax_payable_amount = total_tax * tax.rate / 100
total_tax_amount = total_tax_amount + sale_tax.tax_payable_amount
end
-
#new taxable amount is standard rule for step by step
if shop.calc_tax_order
total_taxable = total_taxable + sale_tax.tax_payable_amount
end
-
sale_tax.inclusive = tax.inclusive
sale_tax.save
- # end
- # end
+ end
+ else
+ # customer.tax_profiles.each do |cus_tax|
+ # if cus_tax.to_i == tax.id
+ sale_tax = SaleTax.new(:sale => self)
+ sale_tax.tax_name = tax.name
+ sale_tax.tax_rate = tax.rate
+
+ # substract , to give after discount
+ total_tax = total_taxable - self.total_discount
+ #include or execulive
+ if tax.inclusive
+ tax_incl_exec = "inclusive"
+ rate = tax.rate
+ divided_value = (100 + rate)/rate
+ sale_tax.tax_payable_amount = total_tax / divided_value
+ else
+ sale_tax.tax_payable_amount = total_tax * tax.rate / 100
+ total_tax_amount = total_tax_amount + sale_tax.tax_payable_amount
+ end
+
+ #new taxable amount is standard rule for step by step
+ if shop.calc_tax_order
+ total_taxable = total_taxable + sale_tax.tax_payable_amount
+ end
+
+ sale_tax.inclusive = tax.inclusive
+ sale_tax.save
+ # end
+ # end
+ end
end
end
- self.tax_type = tax_incl_exec
- self.total_tax = total_tax_amount
+ self.tax_type = tax_incl_exec
+ self.total_tax = total_tax_amount
end
def product_get_unit_price(item_code)
@@ -726,12 +784,13 @@ class Sale < ApplicationRecord
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)
- FROM sale_payments
- INNER JOIN sale_audits sa
- ON SUBSTRING_INDEX(sa.remark,'||',1)=sale_payments.sale_payment_id
- INNER JOIN sales ON sa.sale_id = sales.sale_id
- WHERE sales.sale_status='completed' AND sales.receipt_date between '#{from}' and '#{to}'"
+ 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
+ INNER JOIN sale_audits sa ON SUBSTRING_INDEX(sa.remark,'||',1)=sale_payments.sale_payment_id
+ INNER JOIN sales s ON s.sale_id=sa.sale_id
+ WHERE s.sale_status='completed'
+ 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,
SUM(case when (sale_payments.payment_method='mpu') then sale_payments.payment_amount else 0 end) as mpu_amount,
@@ -748,7 +807,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,
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")
- .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)
.group("DATE_FORMAT((CONVERT_TZ(sales.receipt_date,'+00:00','+06:30')),'%Y-%m-%d')")
@@ -1114,7 +1173,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
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`
INNER JOIN sale_audits ON SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id
WHERE sale_audits.sale_id = s.sale_id"
@@ -1499,7 +1559,7 @@ end
else
query = query.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to)
end
- query = query.group("date_format(CONVERT_TZ(receipt_date,'+00:00', 'SYSTEM'), '%I %p')")
+ query = query.group("date_format(CONVERT_TZ(receipt_date,'+00:00', '+06:30'), '%I %p')")
.order('receipt_date')
else
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor'
@@ -1509,7 +1569,7 @@ end
else
query = query.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to)
end
- query = query.group("date_format(CONVERT_TZ(receipt_date,'+00:00', 'SYSTEM'), '%I %p')")
+ query = query.group("date_format(CONVERT_TZ(receipt_date,'+00:00', '+06:30'), '%I %p')")
.order('receipt_date')
else
shift = ShiftSale.current_open_shift(current_user.id)
@@ -1552,16 +1612,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) 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}'"
@@ -1742,16 +1819,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) 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")
@@ -1759,7 +1860,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")
@@ -1770,8 +1870,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")
@@ -1779,7 +1877,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")
@@ -1791,7 +1888,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")
@@ -1799,7 +1895,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")
@@ -1811,7 +1906,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")
@@ -1970,16 +2064,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) 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)
@@ -1988,7 +2107,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)
@@ -2000,7 +2118,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)
@@ -2009,7 +2126,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)
@@ -2022,7 +2138,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)
@@ -2031,7 +2146,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)
@@ -2044,7 +2158,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'
@@ -2775,6 +2888,23 @@ def self.get_sale_data_for_other_payment_credit(sale_id)
return query
end
+def unique_tax_profiles(order_source, customer_id)
+ tax_data = TaxProfile.unscoped.where("group_type='#{order_source}'").pluck(:id)
+ customer_tax_profiles = Customer.find(customer_id).tax_profiles
+
+ arr_data = []
+ if !customer_tax_profiles.empty?
+ customer_tax_profiles.each do |value1|
+ if tax_data.include? value1.to_i
+ arr_data.push(value1.to_i)
+ end
+ end
+ return arr_data
+ else
+ return tax_data
+ end
+end
+
private
def generate_custom_id
diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb
index 93395250..36f88638 100755
--- a/app/models/sale_payment.rb
+++ b/app/models/sale_payment.rb
@@ -16,12 +16,12 @@ 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
end
-
+
invoice_sale_payments.each do |payment|
if (payment.payment_status == "paid" )
amount_due = amount_due - payment.payment_amount
@@ -866,22 +866,31 @@ class SalePayment < ApplicationRecord
.joins("INNER JOIN orders o ON o.order_id = so.order_id")
if 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' END) and s.sale_status = 'completed' AND o.source='#{params[:type]}' OR o.source='emenu' #{receipt_no} #{customer}")
+ 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 o.source='#{params[:type]}' OR o.source='emenu' END) and s.sale_status = 'completed' #{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' END) and s.sale_status = 'completed' AND o.source='#{params[:type]}' #{receipt_no} #{customer}")
+ 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 o.source='#{params[:type]}' END) and s.sale_status = 'completed' #{receipt_no} #{customer}")
end
query = query.group("s.receipt_no")
.order("s.receipt_date ASC, s.receipt_no ASC")
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/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb
index eed3d8ce..aef82ecf 100755
--- a/app/views/origami/home/show.html.erb
+++ b/app/views/origami/home/show.html.erb
@@ -370,7 +370,7 @@
<% else %>
No Tax
<% end %>
- <%if !@webview %>
+ <%if !@webview && @changable_tax %>
<% end %>
@@ -1103,10 +1103,11 @@
var dining_id = "<%= @dining.id %>";
var sale_id = $("#sale_id").val(); //<%= @obj_sale.sale_id rescue "" %>
var ajax_url = "/origami/sale/append_order";
+ var tax_type = localStorage.getItem("tax_type");
$.ajax({
type: "POST",
url: ajax_url,
- data: 'dining_id=' + dining_id + "&sale_id=" + sale_id,
+ data: 'dining_id=' + dining_id + "&sale_id=" + sale_id + "&tax_type=" + tax_type,
success: function (result) {
swal({
title: "Information!",
diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb
index 195719bd..245467f9 100755
--- a/app/views/origami/payments/show.html.erb
+++ b/app/views/origami/payments/show.html.erb
@@ -118,7 +118,7 @@
<% else %>
No Tax
<% end %>
- <%if @sale_payment.nil? %>
+ <%if @sale_payment.nil? && @changable_tax %>
<% end %>
diff --git a/app/views/origami/rooms/show.html.erb b/app/views/origami/rooms/show.html.erb
index 155e1e07..59546349 100755
--- a/app/views/origami/rooms/show.html.erb
+++ b/app/views/origami/rooms/show.html.erb
@@ -404,7 +404,7 @@
<% else %>
No Tax
<% end %>
- <%if !@webview %>
+ <%if !@webview && @changable_tax %>
<% end %>
@@ -1167,10 +1167,11 @@ $('#add_invoice').on('click',function(){
var dining_id = "<%= @room.id %>"
var sale_id = $("#sale_id").val(); //<%= @obj_sale.sale_id rescue "" %>
var ajax_url = "/origami/sale/append_order";
+ var tax_type = localStorage.getItem("tax_type");
$.ajax({
type: "POST",
url: ajax_url,
- data: 'dining_id='+ dining_id + "&sale_id=" + sale_id,
+ data: 'dining_id='+ dining_id + "&sale_id=" + sale_id + "&tax_type=" + tax_type,
success:function(result){
swal({
title: "Information!",
diff --git a/app/views/reports/order_reservation/index.html.erb b/app/views/reports/order_reservation/index.html.erb
index b59dc3db..0ccaef5b 100755
--- a/app/views/reports/order_reservation/index.html.erb
+++ b/app/views/reports/order_reservation/index.html.erb
@@ -52,11 +52,12 @@
<%= t("views.right_panel.detail.discount_amount") %> |
<%= t("views.right_panel.detail.delivery_fee") %> |
<%= t("views.right_panel.detail.convenience_charge") %> |
- <%= t("views.right_panel.detail.delivery_tax") %> |
+
<%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.tax") %> |
<%= t("views.right_panel.detail.grand_total") %> |
+ <%= t("views.right_panel.detail.transaction_fee") %> |
@@ -88,6 +89,7 @@
total_tax = 0.0
total_amount = 0.0
grand_total = 0.0
+ total_transaction_fee = 0.0
%>
<% unless @order_reservation_data.blank? %>
<% @order_reservation_data.each do |order_reservation| %>
@@ -116,8 +118,9 @@
total_tax += order_reservation.total_tax.to_f
total_amount += order_reservation.total_amount.to_f
grand_total += order_reservation.grand_total.to_f
- %>
- <%
+
+ total_transaction_fee += order_reservation.transaction_fee.to_f
+
if order_reservation.provider == 'pick_up'
provider = "Pick-Up"
elsif order_reservation.provider == 'direct_delivery'
@@ -144,11 +147,12 @@
<%= number_with_precision(discount_amount , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> |
<%= number_with_precision(delivery_fee , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> |
<%= number_with_precision(convenience_charge , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> |
- <%= number_with_precision(delivery_tax , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> |
+
<%= number_with_precision(order_reservation.total_tax , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> |
<%= number_with_precision(order_reservation.grand_total , precision:precision.to_i, delimiter:delimiter) rescue '0.0' %> |
+ <%= number_with_precision(order_reservation.transaction_fee , precision:precision.to_i, delimiter:delimiter) rescue '0.0' %> |
<% end
end %>
@@ -159,11 +163,12 @@
<%= number_with_precision(total_discount_amount , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> |
<%= number_with_precision(total_delivery_fee , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> |
<%= number_with_precision(total_convenience_charge , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> |
- <%= number_with_precision(total_delivery_tax , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> |
+
+ <%= number_with_precision(total_tax , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> |
<%= number_with_precision(grand_total , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> |
+ <%= number_with_precision(total_transaction_fee , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> |
diff --git a/app/views/reports/order_reservation/index.xls.erb b/app/views/reports/order_reservation/index.xls.erb
index d5617225..08f2c5e9 100755
--- a/app/views/reports/order_reservation/index.xls.erb
+++ b/app/views/reports/order_reservation/index.xls.erb
@@ -35,11 +35,12 @@
<%= t("views.right_panel.detail.discount_amount") %> |
<%= t("views.right_panel.detail.delivery_fee") %> |
<%= t("views.right_panel.detail.convenience_charge") %> |
- <%= t("views.right_panel.detail.delivery_tax") %> |
+
<%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.tax") %> |
<%= t("views.right_panel.detail.grand_total") %> |
+ <%= t("views.right_panel.detail.transaction_fee") %> |
@@ -61,6 +62,7 @@
total_tax = 0.0
total_amount = 0.0
grand_total = 0.0
+ transaction_fee = 0.0
%>
<% unless @order_reservation_data.blank? %>
<% @order_reservation_data.each do |order_reservation| %>
@@ -91,6 +93,9 @@
total_amount += order_reservation.total_amount.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'
provider = "Pick-Up"
@@ -118,11 +123,12 @@
<%= discount_amount rescue '0.0'%> |
<%= delivery_fee rescue '0.0'%> |
<%= convenience_charge rescue '0.0'%> |
- <%= delivery_tax rescue '0.0'%> |
+
<%= order_reservation.total_tax rescue '0.0'%> |
<%= order_reservation.grand_total rescue '0.0' %> |
+ <%= order_reservation.transaction_fee rescue '0.0' %> |
<% end
end %>
@@ -133,11 +139,12 @@
<%= total_discount_amount rescue '0.0'%> |
<%= total_delivery_fee rescue '0.0'%> |
<%= total_convenience_charge rescue '0.0'%> |
- <%= total_delivery_tax rescue '0.0'%> |
+
<%= total_tax rescue '0.0'%> |
<%= grand_total rescue '0.0'%> |
+ <%= transaction_fee rescue '0.0'%> |
diff --git a/app/views/transactions/order_reservations/index.html.erb b/app/views/transactions/order_reservations/index.html.erb
index 7709e402..3766f092 100644
--- a/app/views/transactions/order_reservations/index.html.erb
+++ b/app/views/transactions/order_reservations/index.html.erb
@@ -11,10 +11,10 @@
-
+
- |
+ |
<%= form_tag transactions_order_reservations_path, :method => :get do %>
@@ -65,7 +65,7 @@
-
+
@@ -81,11 +81,12 @@
| <%= t("views.right_panel.detail.discount_amount") %> |
<%= t("views.right_panel.detail.delivery_fee") %> |
<%= t("views.right_panel.detail.convenience_charge") %> |
- <%= t("views.right_panel.detail.delivery_tax") %> |
+
<%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.tax") %> |
<%= t("views.right_panel.detail.grand_total") %> |
+ <%= t("views.right_panel.detail.transaction_fee") %> |
@@ -116,13 +117,15 @@
discount_amount = order_reservation.discount_amount
delivery_fee = order_reservation.delivery_fee ? order_reservation.delivery_fee : 0.0
convenience_charge = order_reservation.convenience_charge
- JSON.parse(order_reservation.taxes).each do |tax_data|
- if tax_data[0] == "delivery_tax"
- delivery_tax = tax_data[1]
- elsif tax_data[0] == "convenience_tax"
- convenience_tax = tax_data[1]
- elsif tax_data[0] == "commercial_tax"
- commercial_tax = tax_data[1]
+ if !JSON.parse(order_reservation.taxes).empty?
+ JSON.parse(order_reservation.taxes).each do |tax_data|
+ if tax_data[0] == "delivery_tax"
+ delivery_tax = tax_data[1]
+ elsif tax_data[0] == "convenience_tax"
+ convenience_tax = tax_data[1]
+ elsif tax_data[0] == "commercial_tax"
+ commercial_tax = tax_data[1]
+ end
end
end
%>
@@ -150,16 +153,17 @@
<%= number_with_precision(discount_amount , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> |
<%= number_with_precision(delivery_fee , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> |
<%= number_with_precision(convenience_charge , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> |
- <%= number_with_precision(delivery_tax , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> |
+
<%= number_with_precision(order_reservation.total_tax , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%> |
<%= number_with_precision(order_reservation.grand_total , precision:precision.to_i, delimiter:delimiter) rescue '0.0' %> |
+ <%= number_with_precision(order_reservation.transaction_fee , precision:precision.to_i, delimiter:delimiter) rescue '0.0' %> |
<% end %>
<% else %>
- There is no data for search.... |
+ There is no data for search.... |
<% end %>
diff --git a/app/views/transactions/order_reservations/show.html.erb b/app/views/transactions/order_reservations/show.html.erb
index ed6d2da8..a0c59af5 100755
--- a/app/views/transactions/order_reservations/show.html.erb
+++ b/app/views/transactions/order_reservations/show.html.erb
@@ -99,18 +99,21 @@
total_tax = 0.0
total_amount = 0.0
grand_total = 0.0
+ total_transaction_fee = 0.0
%>
<%
discount_amount = @order_reservation.discount_amount
delivery_fee = @order_reservation.delivery_fee ? @order_reservation.delivery_fee : 0.0
convenience_charge = @order_reservation.convenience_charge
- JSON.parse(@order_reservation.taxes).each do |tax_data|
- if tax_data[0] == "delivery_tax"
- delivery_tax = tax_data[1]
- elsif tax_data[0] == "convenience_tax"
- convenience_tax = tax_data[1]
- elsif tax_data[0] == "commercial_tax"
- commercial_tax = tax_data[1]
+ if !JSON.parse(@order_reservation.taxes).empty?
+ JSON.parse(@order_reservation.taxes).each do |tax_data|
+ if tax_data[0] == "delivery_tax"
+ delivery_tax = tax_data[1]
+ elsif tax_data[0] == "convenience_tax"
+ convenience_tax = tax_data[1]
+ elsif tax_data[0] == "commercial_tax"
+ commercial_tax = tax_data[1]
+ end
end
end
total_discount_amount += discount_amount.to_f
@@ -122,6 +125,7 @@
total_tax += @order_reservation.total_tax.to_f
total_amount += @order_reservation.total_amount.to_f
grand_total += @order_reservation.grand_total.to_f
+ total_transaction_fee += @order_reservation.transaction_fee.to_f
%>
@@ -185,6 +189,13 @@
| <%= number_with_precision(grand_total, precision:precision.to_i, delimiter:delimiter) rescue ' '%> |
<% end %>
+ <% if total_transaction_fee > 0 %>
+
+ |
+ <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.transaction_fee") %> |
+ <%= number_with_precision(total_transaction_fee, precision:precision.to_i, delimiter:delimiter) rescue ' '%> |
+
+ <% end %>
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/locales/en.yml b/config/locales/en.yml
index 038da651..3d99a17d 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -493,6 +493,7 @@ en:
induty_report: "Induty Report"
in_time: "In Time"
out_time: "Out Time"
+ transaction_fee: "Transaction Fee"
code_txt: "code "
charge_txt: "charge"
diff --git a/config/locales/mm.yml b/config/locales/mm.yml
index e728f844..10e105d1 100644
--- a/config/locales/mm.yml
+++ b/config/locales/mm.yml
@@ -487,6 +487,7 @@ mm:
induty_report: "Induty Report"
in_time: "In Time"
out_time: "Out Time"
+ transaction_fee: "Transaction Fee"
code_txt: "ကုတ်ဒ် "
charge_txt: "ကောက်ခံသည်"
diff --git a/config/routes.rb b/config/routes.rb
index f1d0da0b..4d4585eb 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 ------------#
diff --git a/db/migrate/20170403161857_create_sale_items.rb b/db/migrate/20170403161857_create_sale_items.rb
index 14882cbc..66a32f14 100755
--- a/db/migrate/20170403161857_create_sale_items.rb
+++ b/db/migrate/20170403161857_create_sale_items.rb
@@ -6,7 +6,7 @@ class CreateSaleItems < ActiveRecord::Migration[5.1]
t.string :product_code, :null => false
t.string :item_instance_code
t.string :product_name, :null => false
- t.string :product_alt_name, :null => false
+ t.string :product_alt_name
t.integer :account_id, :index => true, :limit => 8, :null => false, :default => 1
t.string :status, :index => true
t.string :remark, :index => true
diff --git a/db/migrate/20180406080240_create_order_reservations.rb b/db/migrate/20180406080240_create_order_reservations.rb
index a343958f..f5a46dd2 100644
--- a/db/migrate/20180406080240_create_order_reservations.rb
+++ b/db/migrate/20180406080240_create_order_reservations.rb
@@ -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 :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 :transaction_fee, :precision => 10, :scale => 2, :null => false, :default => 0.00
t.string :status, :null => false, :default => "new"
t.string :order_remark
t.string :remark
|