Pull from master

This commit is contained in:
San Wai Lwin
2018-08-06 17:52:03 +06:30
parent 35ac07b0a6
commit e99e907bc4
33 changed files with 455 additions and 126 deletions

View File

@@ -251,6 +251,9 @@ For Dashboard Settings for supervisor and cashier
For Customer Settings On/Off For Customer Settings On/Off
1) settings/lookups => {type:customer_settings, name:create, value: {1 or 0}} 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 * ToDo list
1. Migration 1. Migration

View File

@@ -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/

View File

@@ -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

View File

@@ -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') {

View 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();
}
});
}
}
}
});

View 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

View File

@@ -14,10 +14,35 @@ class Api::BillController < Api::ApiController
# for Multiple Cashier by Zone # for Multiple Cashier by Zone
table = DiningFacility.find(booking.dining_facility_id) 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
if booking.sale_id.nil? if booking.sale_id.nil?
@sale = Sale.new @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) @sale_data = Sale.find_by_sale_id(@sale_id)
else else
@status = true @status = true
@@ -41,8 +66,9 @@ class Api::BillController < Api::ApiController
end end
elsif (params[:order_id]) elsif (params[:order_id])
order = Order.find(params[:order_id])
@sale = Sale.new @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 # for Job
booking = Booking.find_by_sale_id(@sale_id) booking = Booking.find_by_sale_id(@sale_id)

View 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

View File

@@ -39,7 +39,9 @@ class Crm::CustomersController < BaseCrmController
@membership_types = Lookup.collection_of("member_group_type") @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 @filter = filter

View File

@@ -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)

View File

@@ -87,7 +87,9 @@ class Origami::CustomersController < BaseOrigamiController
@crm_customer = Customer.new @crm_customer = Customer.new
@count_customer = Customer.count_customer @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"] # if flash["errors"]
# @crm_customer.valid? # @crm_customer.valid?
# end # end

View File

@@ -130,6 +130,19 @@ class Origami::HomeController < BaseOrigamiController
end end
end 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
def check_emp_access_code def check_emp_access_code

View File

@@ -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)
@@ -271,6 +271,20 @@ class Origami::PaymentsController < BaseOrigamiController
if !@lookup_pdf.nil? if !@lookup_pdf.nil?
@pdf_view = @lookup_pdf.value @pdf_view = @lookup_pdf.value
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
@shop = shop_detail #show shop info @shop = shop_detail #show shop info
@customer_lists = Customer.where("customer_id = 'CUS-000000000001' or customer_id = 'CUS-000000000002'") @customer_lists = Customer.where("customer_id = 'CUS-000000000001' or customer_id = 'CUS-000000000002'")

View File

@@ -154,6 +154,19 @@ class Origami::RoomsController < BaseOrigamiController
end end
end 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
end end

View File

@@ -25,6 +25,7 @@ class Origami::SalesController < BaseOrigamiController
def add_to_existing_invoice def add_to_existing_invoice
dining = params[:dining_id] dining = params[:dining_id]
sale_id = params[:sale_id] sale_id = params[:sale_id]
tax_type = params[:tax_type]
table = DiningFacility.find(dining) table = DiningFacility.find(dining)
existing_booking = Booking.find_by_sale_id(sale_id) existing_booking = Booking.find_by_sale_id(sale_id)
table.bookings.each do |booking| table.bookings.each do |booking|
@@ -51,7 +52,7 @@ class Origami::SalesController < BaseOrigamiController
end end
# Re-compute for add # Re-compute for add
saleobj.compute(order.source) saleobj.compute(order.source,tax_type)
saleobj.save saleobj.save
order.save order.save
booking.save booking.save

View File

@@ -76,9 +76,15 @@ class Settings::TaxProfilesController < ApplicationController
# DELETE /settings/tax_profiles/1 # DELETE /settings/tax_profiles/1
# DELETE /settings/tax_profiles/1.json # DELETE /settings/tax_profiles/1.json
def destroy def destroy
customers = Customer.where("tax_profiles LIKE '%#{@settings_tax_profile.id}%'")
if customers.nil? || customers.empty?
@settings_tax_profile.destroy @settings_tax_profile.destroy
flash[:notice] = 'Tax profile was successfully destroyed.' flash[:notice] = 'Tax profile was successfully destroyed.'
render :json => {:status=> "Success", :url => settings_tax_profiles_url }.to_json 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| # respond_to do |format|
# format.html { redirect_to settings_tax_profiles_url, notice: 'Tax profile was successfully destroyed.' } # format.html { redirect_to settings_tax_profiles_url, notice: 'Tax profile was successfully destroyed.' }
# format.json { head :no_content } # format.json { head :no_content }

View File

@@ -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[:payment_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]

View File

@@ -83,10 +83,15 @@ class Sale < ApplicationRecord
self.tax_type = "exclusive" self.tax_type = "exclusive"
# set cashier # set cashier
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 <> ''") 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
@@ -318,7 +323,7 @@ class Sale < ApplicationRecord
end end
#compute - invoice total #compute - invoice total
def compute(order_source = nil) def compute(order_source = nil, tax_type = nil)
sales_items = self.sale_items sales_items = self.sale_items
#Computation Fields #Computation Fields
@@ -337,7 +342,7 @@ class Sale < ApplicationRecord
# total_taxable = total_taxable + (item.taxable_price * item.qty) # total_taxable = total_taxable + (item.taxable_price * item.qty)
end end
apply_tax(total_taxable, order_source) apply_tax(total_taxable, order_source, tax_type)
self.total_amount = subtotal_price self.total_amount = subtotal_price
self.total_discount = total_discount self.total_discount = total_discount
@@ -430,8 +435,21 @@ class Sale < ApplicationRecord
total_tax_amount = 0 total_tax_amount = 0
tax_incl_exec = "exclusive" tax_incl_exec = "exclusive"
#tax_profile - list by order_by #tax_profile - list by order_by
tax_profiles = TaxProfile.all.order("order_by asc") # tax_profiles = TaxProfile.all.order("order_by asc")
customer = Customer.find(sale.customer_id) # 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 # #Creat new tax records
if order_source.to_s == "emenu" if order_source.to_s == "emenu"
order_source = "cashier" order_source = "cashier"
@@ -501,7 +519,7 @@ class Sale < ApplicationRecord
end end
# Tax Calculate # Tax Calculate
def apply_tax(total_taxable, order_source = nil) def apply_tax(total_taxable, order_source = nil, tax_type = nil)
shop = Shop.first shop = Shop.first
#if tax is not apply create new record #if tax is not apply create new record
@@ -513,16 +531,55 @@ class Sale < ApplicationRecord
total_tax_amount = 0 total_tax_amount = 0
tax_incl_exec = "exclusive" tax_incl_exec = "exclusive"
#tax_profile - list by order_by #tax_profile - list by order_by
tax_profiles = TaxProfile.all.order("order_by asc") # tax_profiles = TaxProfile.all.order("order_by asc")
customer = Customer.find(self.customer_id)
if order_source.to_s == "emenu" if order_source.to_s == "emenu"
order_source = "cashier" order_source = "cashier"
end 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 #Create new tax records
tax_profiles.each do |tax| tax_profiles.each do |tax|
if tax.group_type.to_s == order_source.to_s if tax.group_type.to_s == order_source.to_s
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 - 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
else
# customer.tax_profiles.each do |cus_tax| # customer.tax_profiles.each do |cus_tax|
# if cus_tax.to_i == tax.id # if cus_tax.to_i == tax.id
sale_tax = SaleTax.new(:sale => self) sale_tax = SaleTax.new(:sale => self)
@@ -553,6 +610,7 @@ class Sale < ApplicationRecord
# end # end
end end
end end
end
self.tax_type = tax_incl_exec self.tax_type = tax_incl_exec
self.total_tax = total_tax_amount self.total_tax = total_tax_amount
end end
@@ -726,12 +784,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,
@@ -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, (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')")
@@ -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 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"
@@ -1499,7 +1559,7 @@ end
else 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) 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 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') .order('receipt_date')
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'
@@ -1509,7 +1569,7 @@ end
else 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) 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 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') .order('receipt_date')
else else
shift = ShiftSale.current_open_shift(current_user.id) 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) 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}'"
@@ -1742,16 +1819,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")
@@ -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) 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")
@@ -1770,8 +1870,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")
@@ -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) 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")
@@ -1791,7 +1888,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")
@@ -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) 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")
@@ -1811,7 +1906,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")
@@ -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}'" 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)
@@ -1988,7 +2107,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)
@@ -2000,7 +2118,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)
@@ -2009,7 +2126,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)
@@ -2022,7 +2138,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)
@@ -2031,7 +2146,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)
@@ -2044,7 +2158,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'
@@ -2775,6 +2888,23 @@ def self.get_sale_data_for_other_payment_credit(sale_id)
return query return query
end 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 private
def generate_custom_id def generate_custom_id

View File

@@ -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
@@ -866,22 +866,31 @@ class SalePayment < ApplicationRecord
.joins("INNER JOIN orders o ON o.order_id = so.order_id") .joins("INNER JOIN orders o ON o.order_id = so.order_id")
if params[:type] == "cashier" 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 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 end
query = query.group("s.receipt_no") query = query.group("s.receipt_no")
.order("s.receipt_date ASC, s.receipt_no ASC") .order("s.receipt_date ASC, s.receipt_no ASC")
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

View File

@@ -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") {

View File

@@ -370,7 +370,7 @@
<% else %> <% else %>
No Tax No Tax
<% end %></strong><br> <% end %></strong><br>
<%if !@webview %> <%if !@webview && @changable_tax %>
<button class="btn btn-link waves-effect bg-info change_tax">Change Tax</button> <button class="btn btn-link waves-effect bg-info change_tax">Change Tax</button>
<% end %> <% end %>
</td> </td>
@@ -1103,10 +1103,11 @@
var dining_id = "<%= @dining.id %>"; var dining_id = "<%= @dining.id %>";
var sale_id = $("#sale_id").val(); //<%= @obj_sale.sale_id rescue "" %> var sale_id = $("#sale_id").val(); //<%= @obj_sale.sale_id rescue "" %>
var ajax_url = "/origami/sale/append_order"; var ajax_url = "/origami/sale/append_order";
var tax_type = localStorage.getItem("tax_type");
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: ajax_url, 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) { success: function (result) {
swal({ swal({
title: "Information!", title: "Information!",

View File

@@ -118,7 +118,7 @@
<% else %> <% else %>
No Tax No Tax
<% end %></strong><br> <% end %></strong><br>
<%if @sale_payment.nil? %> <%if @sale_payment.nil? && @changable_tax %>
<button class="btn btn-link waves-effect bg-info change_tax">Change Tax</button> <button class="btn btn-link waves-effect bg-info change_tax">Change Tax</button>
<% end %> <% end %>
</td> </td>

View File

@@ -404,7 +404,7 @@
<% else %> <% else %>
No Tax No Tax
<% end %></strong><br> <% end %></strong><br>
<%if !@webview %> <%if !@webview && @changable_tax %>
<button class="btn btn-link waves-effect bg-info change_tax">Change Tax</button> <button class="btn btn-link waves-effect bg-info change_tax">Change Tax</button>
<% end %> <% end %>
</td> </td>
@@ -1167,10 +1167,11 @@ $('#add_invoice').on('click',function(){
var dining_id = "<%= @room.id %>" var dining_id = "<%= @room.id %>"
var sale_id = $("#sale_id").val(); //<%= @obj_sale.sale_id rescue "" %> var sale_id = $("#sale_id").val(); //<%= @obj_sale.sale_id rescue "" %>
var ajax_url = "/origami/sale/append_order"; var ajax_url = "/origami/sale/append_order";
var tax_type = localStorage.getItem("tax_type");
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: ajax_url, 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){ success:function(result){
swal({ swal({
title: "Information!", title: "Information!",

View File

@@ -52,11 +52,12 @@
<th><%= t("views.right_panel.detail.discount_amount") %></th> <th><%= t("views.right_panel.detail.discount_amount") %></th>
<th><%= t("views.right_panel.detail.delivery_fee") %></th> <th><%= t("views.right_panel.detail.delivery_fee") %></th>
<th><%= t("views.right_panel.detail.convenience_charge") %></th> <th><%= t("views.right_panel.detail.convenience_charge") %></th>
<th><%= t("views.right_panel.detail.delivery_tax") %></th> <!-- <th><%= t("views.right_panel.detail.delivery_tax") %></th>
<th><%= t("views.right_panel.detail.convenience_tax") %></th> <th><%= t("views.right_panel.detail.convenience_tax") %></th>
<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
total_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| %>
@@ -116,8 +118,9 @@
total_tax += order_reservation.total_tax.to_f total_tax += order_reservation.total_tax.to_f
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
%>
<% total_transaction_fee += order_reservation.transaction_fee.to_f
if order_reservation.provider == 'pick_up' if order_reservation.provider == 'pick_up'
provider = "Pick-Up" provider = "Pick-Up"
elsif order_reservation.provider == 'direct_delivery' elsif order_reservation.provider == 'direct_delivery'
@@ -144,11 +147,12 @@
<td><%= number_with_precision(discount_amount , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%></td> <td><%= number_with_precision(discount_amount , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%></td>
<td><%= number_with_precision(delivery_fee , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%></td> <td><%= number_with_precision(delivery_fee , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%></td>
<td><%= number_with_precision(convenience_charge , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%></td> <td><%= number_with_precision(convenience_charge , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%></td>
<td><%= number_with_precision(delivery_tax , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%></td> <!-- <td><%= number_with_precision(delivery_tax , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%></td>
<td><%= number_with_precision(convenience_tax , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%></td> <td><%= number_with_precision(convenience_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(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 %>
@@ -159,11 +163,12 @@
<td><b><%= number_with_precision(total_discount_amount , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%></b></td> <td><b><%= number_with_precision(total_discount_amount , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%></b></td>
<td><b><%= number_with_precision(total_delivery_fee , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%></b></td> <td><b><%= number_with_precision(total_delivery_fee , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%></b></td>
<td><b><%= number_with_precision(total_convenience_charge , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%></b></td> <td><b><%= number_with_precision(total_convenience_charge , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%></b></td>
<td><b><%= number_with_precision(total_delivery_tax , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%></b></td> <!-- <td><b><%= number_with_precision(total_delivery_tax , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%></b></td>
<td><b><%= number_with_precision(total_convenience_tax , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%></b></td> <td><b><%= number_with_precision(total_convenience_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_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(total_transaction_fee , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%></b></td>
</tr> </tr>
</tbody> </tbody>
</table> </table>

View File

@@ -35,11 +35,12 @@
<th><%= t("views.right_panel.detail.discount_amount") %></th> <th><%= t("views.right_panel.detail.discount_amount") %></th>
<th><%= t("views.right_panel.detail.delivery_fee") %></th> <th><%= t("views.right_panel.detail.delivery_fee") %></th>
<th><%= t("views.right_panel.detail.convenience_charge") %></th> <th><%= t("views.right_panel.detail.convenience_charge") %></th>
<th><%= t("views.right_panel.detail.delivery_tax") %></th> <!-- <th><%= t("views.right_panel.detail.delivery_tax") %></th>
<th><%= t("views.right_panel.detail.convenience_tax") %></th> <th><%= t("views.right_panel.detail.convenience_tax") %></th>
<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"
@@ -118,11 +123,12 @@
<td><%= discount_amount rescue '0.0'%></td> <td><%= discount_amount rescue '0.0'%></td>
<td><%= delivery_fee rescue '0.0'%></td> <td><%= delivery_fee rescue '0.0'%></td>
<td><%= convenience_charge rescue '0.0'%></td> <td><%= convenience_charge rescue '0.0'%></td>
<td><%= delivery_tax rescue '0.0'%></td> <!-- <td><%= delivery_tax rescue '0.0'%></td>
<td><%= convenience_tax rescue '0.0'%></td> <td><%= convenience_tax rescue '0.0'%></td>
<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 %>
@@ -133,11 +139,12 @@
<td><b><%= total_discount_amount rescue '0.0'%></b></td> <td><b><%= total_discount_amount rescue '0.0'%></b></td>
<td><b><%= total_delivery_fee rescue '0.0'%></b></td> <td><b><%= total_delivery_fee rescue '0.0'%></b></td>
<td><b><%= total_convenience_charge rescue '0.0'%></b></td> <td><b><%= total_convenience_charge rescue '0.0'%></b></td>
<td><b><%= total_delivery_tax rescue '0.0'%></b></td> <!-- <td><b><%= total_delivery_tax rescue '0.0'%></b></td>
<td><b><%= total_convenience_tax rescue '0.0'%></b></td> <td><b><%= total_convenience_tax rescue '0.0'%></b></td>
<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>

View File

@@ -11,10 +11,10 @@
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12"> <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div class="main-box-body clearfix p-l-5 p-r-5"> <div class="main-box-body clearfix p-l-5 p-r-5">
<div class="table-responsive"> <div class="table-responsive">
<table class="table table-"> <table class="table">
<tbody> <tbody>
<tr> <tr>
<td colspan="8"> <td colspan="14">
<%= form_tag transactions_order_reservations_path, :method => :get do %> <%= form_tag transactions_order_reservations_path, :method => :get do %>
<div class="row clearfix"> <div class="row clearfix">
<div class="col-lg-2 col-md-2 col-sm-2 col-xs-2"> <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2">
@@ -65,7 +65,7 @@
</div> </div>
<div class="card"> <div class="card">
<div class="table-responsive"> <div class="table-responsive">
<table class="table table-striped"> <table class="table table-bordered table-striped table-hover">
<thead> <thead>
<tr> <tr>
@@ -81,11 +81,12 @@
<th><%= t("views.right_panel.detail.discount_amount") %></th> <th><%= t("views.right_panel.detail.discount_amount") %></th>
<th><%= t("views.right_panel.detail.delivery_fee") %></th> <th><%= t("views.right_panel.detail.delivery_fee") %></th>
<th><%= t("views.right_panel.detail.convenience_charge") %></th> <th><%= t("views.right_panel.detail.convenience_charge") %></th>
<th><%= t("views.right_panel.detail.delivery_tax") %></th> <!-- <th><%= t("views.right_panel.detail.delivery_tax") %></th>
<th><%= t("views.right_panel.detail.convenience_tax") %></th> <th><%= t("views.right_panel.detail.convenience_tax") %></th>
<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>
@@ -116,6 +117,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 +127,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'
@@ -150,16 +153,17 @@
<td><%= number_with_precision(discount_amount , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%></td> <td><%= number_with_precision(discount_amount , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%></td>
<td><%= number_with_precision(delivery_fee , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%></td> <td><%= number_with_precision(delivery_fee , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%></td>
<td><%= number_with_precision(convenience_charge , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%></td> <td><%= number_with_precision(convenience_charge , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%></td>
<td><%= number_with_precision(delivery_tax , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%></td> <!-- <td><%= number_with_precision(delivery_tax , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%></td>
<td><%= number_with_precision(convenience_tax , precision:precision.to_i, delimiter:delimiter) rescue '0.0'%></td> <td><%= number_with_precision(convenience_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(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>
</td> </td>
</tr> </tr>
<% end %> <% end %>
<% else %> <% else %>
<tr><td colspan="16"><strong><p style="text-align: center">There is no data for search....</p></strong></td></tr> <tr><td colspan="14"><strong><p style="text-align: center">There is no data for search....</p></strong></td></tr>
<% end %> <% end %>
</tbody> </tbody>
</table> </table>

View File

@@ -99,11 +99,13 @@
total_tax = 0.0 total_tax = 0.0
total_amount = 0.0 total_amount = 0.0
grand_total = 0.0 grand_total = 0.0
total_transaction_fee = 0.0
%> %>
<% <%
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 +115,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
@@ -122,6 +125,7 @@
total_tax += @order_reservation.total_tax.to_f total_tax += @order_reservation.total_tax.to_f
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
total_transaction_fee += @order_reservation.transaction_fee.to_f
%> %>
<tr style="border-top:2px solid #000"> <tr style="border-top:2px solid #000">
@@ -185,6 +189,13 @@
<td colspan="4"><%= number_with_precision(grand_total, precision:precision.to_i, delimiter:delimiter) rescue ' '%></td> <td colspan="4"><%= number_with_precision(grand_total, precision:precision.to_i, delimiter:delimiter) rescue ' '%></td>
</tr> </tr>
<% end %> <% end %>
<% if total_transaction_fee > 0 %>
<tr style="border-top:2px solid #000">
<td colspan="2" style="text-align:center"></td>
<td><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.transaction_fee") %></td>
<td colspan="4"><%= number_with_precision(total_transaction_fee, precision:precision.to_i, delimiter:delimiter) rescue ' '%></td>
</tr>
<% end %>
</tbody> </tbody>
</table> </table>
</div> </div>

View File

@@ -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 )

View File

@@ -493,6 +493,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"

View File

@@ -487,6 +487,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: "ကောက်ခံသည်"

View File

@@ -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 ------------#

View File

@@ -6,7 +6,7 @@ class CreateSaleItems < ActiveRecord::Migration[5.1]
t.string :product_code, :null => false t.string :product_code, :null => false
t.string :item_instance_code t.string :item_instance_code
t.string :product_name, :null => false 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.integer :account_id, :index => true, :limit => 8, :null => false, :default => 1
t.string :status, :index => true t.string :status, :index => true
t.string :remark, :index => true t.string :remark, :index => true

View File

@@ -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