fix daily sale creditnote
This commit is contained in:
@@ -1,11 +1,12 @@
|
|||||||
class Origami::VoidController < BaseOrigamiController
|
class Origami::VoidController < BaseOrigamiController
|
||||||
authorize_resource :class => false
|
authorize_resource :class => false
|
||||||
def overall_void
|
|
||||||
|
|
||||||
|
def overall_void
|
||||||
sale_id = params[:sale_id]
|
sale_id = params[:sale_id]
|
||||||
remark = params[:remark]
|
remark = params[:remark]
|
||||||
order_source = params[:type] #tax profile source
|
order_source = params[:type] #tax profile source
|
||||||
access_code = params[:access_code]
|
access_code = params[:access_code]
|
||||||
|
|
||||||
if Sale.exists?(sale_id)
|
if Sale.exists?(sale_id)
|
||||||
sale = Sale.find_by_sale_id(sale_id)
|
sale = Sale.find_by_sale_id(sale_id)
|
||||||
if sale.discount_type == "member_discount"
|
if sale.discount_type == "member_discount"
|
||||||
@@ -42,32 +43,10 @@ class Origami::VoidController < BaseOrigamiController
|
|||||||
# end
|
# end
|
||||||
# end
|
# end
|
||||||
|
|
||||||
if sale.bookings[0].dining_facility_id.to_i > 0
|
if table = sale.booking.dining_facility
|
||||||
table_avaliable = true
|
unless table.current_bookings.exists?
|
||||||
table_count = 0
|
table.update_attributes(status: 'available')
|
||||||
table = sale.bookings[0].dining_facility
|
|
||||||
table.bookings.each do |booking|
|
|
||||||
if booking.booking_status != 'moved'
|
|
||||||
if booking.sale_id
|
|
||||||
if booking.sale.sale_status != 'completed' && booking.sale.sale_status != 'void' && booking.sale.sale_status != 'spoile' && booking.sale.sale_status != 'waste'
|
|
||||||
table_avaliable = false
|
|
||||||
table_count += 1
|
|
||||||
else
|
|
||||||
table_avaliable = true
|
|
||||||
end
|
|
||||||
else
|
|
||||||
table_avaliable = false
|
|
||||||
table_count += 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if table_avaliable && table_count == 0
|
|
||||||
table.status = 'available'
|
|
||||||
table.save
|
|
||||||
end
|
|
||||||
else
|
|
||||||
table = nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# FOr Sale Audit
|
# FOr Sale Audit
|
||||||
@@ -113,49 +92,49 @@ class Origami::VoidController < BaseOrigamiController
|
|||||||
# unique_code = 'ReceiptBillStarPdf'
|
# unique_code = 'ReceiptBillStarPdf'
|
||||||
# end
|
# end
|
||||||
|
|
||||||
customer= Customer.find(sale.customer_id)
|
customer= Customer.find(sale.customer_id)
|
||||||
|
|
||||||
#shop detail
|
#shop detail
|
||||||
shop_details = Shop.current_shop
|
shop_details = Shop.current_shop
|
||||||
# get member information
|
# get member information
|
||||||
rebate = MembershipSetting.find_by_rebate(1)
|
rebate = MembershipSetting.find_by_rebate(1)
|
||||||
if customer.membership_id != nil && rebate
|
if customer.membership_id != nil && rebate
|
||||||
member_info = Customer.get_member_account(customer)
|
member_info = Customer.get_member_account(customer)
|
||||||
rebate_amount = Customer.get_membership_transactions(customer,sale.receipt_no)
|
rebate_amount = Customer.get_membership_transactions(customer,sale.receipt_no)
|
||||||
# current_balance = SaleAudit.paymal_search(sale_id)
|
# current_balance = SaleAudit.paymal_search(sale_id)
|
||||||
current_balance = 0
|
current_balance = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
printer = PrintSetting.all
|
printer = PrintSetting.all
|
||||||
|
|
||||||
unique_code="ReceiptBillPdf"
|
unique_code="ReceiptBillPdf"
|
||||||
if !printer.empty?
|
if !printer.empty?
|
||||||
printer.each do |printer_setting|
|
printer.each do |printer_setting|
|
||||||
if printer_setting.unique_code == 'ReceiptBillPdf'
|
if printer_setting.unique_code == 'ReceiptBillPdf'
|
||||||
unique_code="ReceiptBillPdf"
|
unique_code="ReceiptBillPdf"
|
||||||
elsif printer_setting.unique_code == 'ReceiptBillA5Pdf'
|
elsif printer_setting.unique_code == 'ReceiptBillA5Pdf'
|
||||||
unique_code="ReceiptBillA5Pdf"
|
unique_code="ReceiptBillA5Pdf"
|
||||||
elsif printer_setting.unique_code == 'ReceiptBillStarPdf'
|
elsif printer_setting.unique_code == 'ReceiptBillStarPdf'
|
||||||
unique_code="ReceiptBillStarPdf"
|
unique_code="ReceiptBillStarPdf"
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
# get printer info
|
end
|
||||||
print_settings=PrintSetting.find_by_unique_code(unique_code)
|
# get printer info
|
||||||
# Calculate Food and Beverage Total
|
print_settings=PrintSetting.find_by_unique_code(unique_code)
|
||||||
item_price_by_accounts = SaleItem.calculate_price_by_accounts(sale.sale_items)
|
# Calculate Food and Beverage Total
|
||||||
discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(sale.sale_items)
|
item_price_by_accounts = SaleItem.calculate_price_by_accounts(sale.sale_items)
|
||||||
other_amount = SaleItem.calculate_other_charges(sale.sale_items)
|
discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(sale.sale_items)
|
||||||
printer = Printer::ReceiptPrinter.new(print_settings)
|
other_amount = SaleItem.calculate_other_charges(sale.sale_items)
|
||||||
filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil,cashier_terminal,sale.sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "VOID",current_balance,nil,other_amount,nil,nil,nil)
|
printer = Printer::ReceiptPrinter.new(print_settings)
|
||||||
result = {
|
filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil,cashier_terminal,sale.sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "VOID",current_balance,nil,other_amount,nil,nil,nil)
|
||||||
:filepath => filename,
|
result = {
|
||||||
:printer_model => print_settings.brand_name,
|
:filepath => filename,
|
||||||
:printer_url => print_settings.api_settings
|
:printer_model => print_settings.brand_name,
|
||||||
}
|
:printer_url => print_settings.api_settings
|
||||||
|
}
|
||||||
|
|
||||||
# Mobile Print
|
# Mobile Print
|
||||||
render :json => result.to_json
|
render :json => result.to_json
|
||||||
# end
|
# end
|
||||||
|
|
||||||
#end print
|
#end print
|
||||||
|
|||||||
@@ -34,7 +34,10 @@ class Sale < ApplicationRecord
|
|||||||
scope :paid, -> { where(payment_status: 'paid')}
|
scope :paid, -> { where(payment_status: 'paid')}
|
||||||
scope :completed, -> { where(sale_status: 'completed') }
|
scope :completed, -> { where(sale_status: 'completed') }
|
||||||
scope :receipt_date_between, -> (from, to) { where(receipt_date: from..to) }
|
scope :receipt_date_between, -> (from, to) { where(receipt_date: from..to) }
|
||||||
scope :along_with_sale_payments_except_void_between, -> (from, to) { joins(sanitize_sql_array(["LEFT JOIN sale_payments ON sales.sale_status != 'void' AND sale_payments.sale_id = sales.sale_id AND sale_payments.created_at BETWEEN ? and ?", from, to])) }
|
scope :sale_payments_with_audit_except_void_between, -> (from, to) do
|
||||||
|
joins(sanitize_sql_array(["LEFT JOIN sale_payments ON sales.sale_status != 'void' AND sale_payments.sale_id = sales.sale_id AND sale_payments.created_at BETWEEN ? and ?", from, to]))
|
||||||
|
.joins("LEFT JOIN sale_audits ON sale_audits.sale_id = sale_payments.sale_id AND SUBSTRING_INDEX(sale_audits.remark,'||',1) = sale_payments.sale_payment_id")
|
||||||
|
end
|
||||||
|
|
||||||
def qty_of(item_instance_code)
|
def qty_of(item_instance_code)
|
||||||
order_items.select(:order_items_id, :item_instance_code, 'SUM(qty) as qty').where(item_instance_code: item_instance_code).group(:item_instance_code).first
|
order_items.select(:order_items_id, :item_instance_code, 'SUM(qty) as qty').where(item_instance_code: item_instance_code).group(:item_instance_code).first
|
||||||
@@ -749,20 +752,15 @@ class Sale < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.daily_sales_list(from,to)
|
def self.daily_sales_list(from,to)
|
||||||
payment_methods = SalePayment.where.not(payment_method: ['cash', 'creditnote', 'foc']).distinct.pluck(:payment_method)
|
payment_methods = SalePayment.where.not(payment_method: ['cash', 'creditnote', 'foc']).distinct.pluck(:payment_method)
|
||||||
|
|
||||||
unless payment_methods.empty?
|
sales = select(Sale.column_names)
|
||||||
sales = select("
|
.select("#{payment_methods.map { |method| "SUM(case when (sale_payments.payment_method='#{method}') then sale_payments.payment_amount else 0 end) as #{method == 'paypar' ? 'redeem' : method}"}.push('').join(', ')}
|
||||||
sales.*,
|
|
||||||
#{payment_methods.map { |method| "SUM(case when (sale_payments.payment_method='#{method}') then sale_payments.payment_amount else 0 end) as #{method == 'paypar' ? 'redeem' : method}"}.join(', ')},
|
|
||||||
SUM(case when (sale_payments.payment_method='cash') then sale_payments.payment_amount else 0 end) as cash_amount,
|
SUM(case when (sale_payments.payment_method='cash') then sale_payments.payment_amount else 0 end) as cash_amount,
|
||||||
CASE WHEN SUM(case when sale_payments.payment_method not in('creditnote')
|
SUM(case when (sale_payments.payment_method='creditnote') then sale_payments.payment_amount else 0 end) -
|
||||||
then sale_payments.payment_amount else 0 end) < sales.grand_total
|
SUM(case when (sale_payments.payment_method not in('creditnote') and sale_audits.sale_audit_id IS NOT NULL) then sale_payments.payment_amount else 0 end) as credit_amount,
|
||||||
THEN sales.grand_total - SUM(case when sale_payments.payment_method not in('creditnote')
|
|
||||||
then sale_payments.payment_amount else 0 end)
|
|
||||||
ELSE 0 END as credit_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")
|
||||||
.along_with_sale_payments_except_void_between(from, to)
|
.sale_payments_with_audit_except_void_between(from, to)
|
||||||
.where("(sale_status = ? OR sale_status = ?) AND sales.receipt_date between ? AND ? ", 'completed', 'void', from, to)
|
.where("(sale_status = ? OR sale_status = ?) AND sales.receipt_date between ? AND ? ", 'completed', 'void', from, to)
|
||||||
.group("sale_id").to_sql
|
.group("sale_id").to_sql
|
||||||
|
|
||||||
@@ -775,10 +773,10 @@ class Sale < ApplicationRecord
|
|||||||
IFNULL(SUM(case when (sale_status='void') then grand_total else 0 end),0) as void_amount,
|
IFNULL(SUM(case when (sale_status='void') then grand_total else 0 end),0) as void_amount,
|
||||||
IFNULL(SUM(case when (sale_status='completed') then rounding_adjustment else 0 end),0) as rounding_adj,
|
IFNULL(SUM(case when (sale_status='completed') then rounding_adjustment else 0 end),0) as rounding_adj,
|
||||||
IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0) / 21 as tax,
|
IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0) / 21 as tax,
|
||||||
(IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0))-(IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0) / 21) as net_sale,
|
(IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0)) - (IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0) / 21) as net_sale,
|
||||||
(IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0)) + (IFNULL(SUM(case when (sale_status='completed') then total_discount else 0 end),0)) as gross_sale,
|
(IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0)) + (IFNULL(SUM(case when (sale_status='completed') then total_discount else 0 end),0)) as gross_sale,
|
||||||
CAST((CONVERT_TZ(receipt_date,'+00:00','+06:30')) AS DATE) as sale_date,
|
CAST((CONVERT_TZ(receipt_date,'+00:00','+06:30')) AS DATE) as sale_date,
|
||||||
#{payment_methods.map { |method| pm = method == 'paypar' ? 'redeem' : method; "SUM(#{pm}) as #{pm}"}.join(', ')},
|
#{payment_methods.map { |method| pm = method == 'paypar' ? 'redeem' : method; "SUM(#{pm}) as #{pm}"}.push('').join(', ')}
|
||||||
SUM(cash_amount) as cash_amount,
|
SUM(cash_amount) as cash_amount,
|
||||||
SUM(credit_amount) as credit_amount,
|
SUM(credit_amount) as credit_amount,
|
||||||
SUM(foc_amount) as foc_amount
|
SUM(foc_amount) as foc_amount
|
||||||
@@ -786,44 +784,7 @@ class Sale < ApplicationRecord
|
|||||||
#{sales}
|
#{sales}
|
||||||
) as s
|
) as s
|
||||||
GROUP BY DATE(CONVERT_TZ(receipt_date,'+00:00','+06:30'))").to_hash.map(&:symbolize_keys)
|
GROUP BY DATE(CONVERT_TZ(receipt_date,'+00:00','+06:30'))").to_hash.map(&:symbolize_keys)
|
||||||
else
|
return daily_total
|
||||||
sales = select("
|
|
||||||
sales.*,
|
|
||||||
SUM(case when (sale_payments.payment_method='cash') then sale_payments.payment_amount else 0 end) as cash_amount,
|
|
||||||
CASE WHEN SUM(case when sale_payments.payment_method not in('creditnote')
|
|
||||||
then sale_payments.payment_amount else 0 end) < sales.grand_total
|
|
||||||
THEN sales.grand_total - SUM(case when sale_payments.payment_method not in('creditnote')
|
|
||||||
then sale_payments.payment_amount else 0 end)
|
|
||||||
ELSE 0 END as credit_amount,
|
|
||||||
SUM(case when (sale_payments.payment_method='foc') then sale_payments.payment_amount else 0 end) as foc_amount")
|
|
||||||
.along_with_sale_payments_except_void_between(from, to)
|
|
||||||
.where("(sale_status = ? OR sale_status = ?) AND sales.receipt_date between ? AND ? ", 'completed', 'void', from, to)
|
|
||||||
.group("sale_id").to_sql
|
|
||||||
|
|
||||||
daily_total = connection.select_all("SELECT
|
|
||||||
IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0) as grand_total,
|
|
||||||
IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0) as total_sale,
|
|
||||||
IFNULL(SUM(case when (sale_status='completed') then old_grand_total else 0 end),0) as old_grand_total,
|
|
||||||
IFNULL(SUM(case when (sale_status='completed') then total_discount else 0 end),0) as total_discount,
|
|
||||||
IFNULL(SUM(case when (sale_status='completed') then amount_changed else 0 end),0) as total_change_amount,
|
|
||||||
IFNULL(SUM(case when (sale_status='void') then grand_total else 0 end),0) as void_amount,
|
|
||||||
IFNULL(SUM(case when (sale_status='completed') then rounding_adjustment else 0 end),0) as rounding_adj,
|
|
||||||
IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0) / 21 as tax,
|
|
||||||
(IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0))-(IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0) / 21) as net_sale,
|
|
||||||
(IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0)) + (IFNULL(SUM(case when (sale_status='completed') then total_discount else 0 end),0)) as gross_sale,
|
|
||||||
CAST((CONVERT_TZ(receipt_date,'+00:00','+06:30')) AS DATE) as sale_date,
|
|
||||||
SUM(cash_amount) as cash_amount,
|
|
||||||
SUM(credit_amount) as credit_amount,
|
|
||||||
SUM(foc_amount) as foc_amount
|
|
||||||
FROM (
|
|
||||||
#{sales}
|
|
||||||
) as s
|
|
||||||
GROUP BY DATE(CONVERT_TZ(receipt_date,'+00:00','+06:30'))").to_hash.map(&:symbolize_keys)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return daily_total
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.get_by_range_by_saleitems(from,to,status,report_type)
|
def self.get_by_range_by_saleitems(from,to,status,report_type)
|
||||||
@@ -2343,7 +2304,7 @@ private
|
|||||||
self.total_tax = self.total_tax.round(precision)
|
self.total_tax = self.total_tax.round(precision)
|
||||||
end
|
end
|
||||||
self.grand_total = (self.total_amount - self.total_discount) + self.total_tax
|
self.grand_total = (self.total_amount - self.total_discount) + self.total_tax
|
||||||
if (!['foc','waste','spoile'].include? self.payment_status)
|
if (!['foc', 'waste', 'spoile', 'void'].include? self.payment_status)
|
||||||
adjust_rounding
|
adjust_rounding
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -132,13 +132,13 @@ class ShiftSale < ApplicationRecord
|
|||||||
self.commercial_taxes = self.commercial_taxes.to_f - tax.to_f
|
self.commercial_taxes = self.commercial_taxes.to_f - tax.to_f
|
||||||
self.total_rounding = self.total_rounding - saleobj.rounding_adjustment
|
self.total_rounding = self.total_rounding - saleobj.rounding_adjustment
|
||||||
self.total_void = self.total_void + saleobj.grand_total
|
self.total_void = self.total_void + saleobj.grand_total
|
||||||
|
|
||||||
if saleobj.customer.customer_type == "Dinein"
|
if saleobj.customer.customer_type == "Dinein"
|
||||||
self.dining_count = self.dining_count - 1
|
self.dining_count = self.dining_count - 1
|
||||||
else
|
else
|
||||||
self.takeaway_count = self.takeaway_count - 1
|
self.takeaway_count = self.takeaway_count - 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
self.save
|
self.save
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user