generate task shift_sales rake
This commit is contained in:
@@ -89,7 +89,7 @@ class Origami::PaymentsController < BaseOrigamiController
|
||||
path = request.fullpath
|
||||
latest_order_no = nil
|
||||
is_kbz = params[:is_kbz]
|
||||
|
||||
|
||||
|
||||
if saleObj = Sale.find(sale_id)
|
||||
sale_items = SaleItem.get_all_sale_items(sale_id)
|
||||
@@ -98,7 +98,7 @@ class Origami::PaymentsController < BaseOrigamiController
|
||||
Rails.logger.info '################ CASH PAYMENT #################'
|
||||
sale_payment = SalePayment.new
|
||||
if path.include? ("credit_payment")
|
||||
sale_payment.process_payment(saleObj, current_user, cash, "cash", nil, true)
|
||||
sale_payment.process_payment(saleObj, current_user, cash, "creditnote", nil, true)
|
||||
else
|
||||
sale_payment.process_payment(saleObj, current_user, cash, "cash")
|
||||
end
|
||||
@@ -107,7 +107,7 @@ class Origami::PaymentsController < BaseOrigamiController
|
||||
sp.kbz_edit_sale_payment(sp.received_amount.to_f, current_user)
|
||||
end
|
||||
|
||||
|
||||
|
||||
rebate_amount = nil
|
||||
|
||||
# For Cashier by Zone
|
||||
@@ -202,17 +202,17 @@ class Origami::PaymentsController < BaseOrigamiController
|
||||
discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(saleObj.sale_items)
|
||||
other_amount = SaleItem.calculate_other_charges(sale_items)
|
||||
credit_pdf = Lookup.find_by_lookup_type("credit_pdf")
|
||||
if (path.include? ("credit_payment")) && !credit_pdf.nil? && credit_pdf.value.to_i == 1
|
||||
if (path.include? ("credit_payment")) && !credit_pdf.nil? && credit_pdf.value.to_i == 1
|
||||
printed_status = 'credit_payment'
|
||||
else
|
||||
printed_status = 'Paid'
|
||||
end
|
||||
|
||||
|
||||
printer = Printer::ReceiptPrinter.new(print_settings)
|
||||
filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_detail, printed_status,current_balance,card_data,other_amount,latest_order_no,card_balance_amount,nil)
|
||||
|
||||
#end
|
||||
|
||||
|
||||
if !saleObj.nil?
|
||||
# InventoryJob.perform_now(self.id)
|
||||
# InventoryDefinition.calculate_product_count(saleObj)
|
||||
|
||||
121
lib/tasks/shift_sales.rake
Normal file
121
lib/tasks/shift_sales.rake
Normal file
@@ -0,0 +1,121 @@
|
||||
namespace :shift_sales do
|
||||
desc "TODO"
|
||||
task :audit, [:shift_sale_id, :repayment] => [:environment] do |tasks, args|
|
||||
Rails.logger = Logger.new(STDOUT)
|
||||
ActiveRecord::Base.transaction do
|
||||
shift_sale = ShiftSale.find(args[:shift_sale_id])
|
||||
|
||||
total_revenue = 0
|
||||
total_discounts = 0
|
||||
total_taxes = 0
|
||||
grand_total = 0
|
||||
cash_sales = 0
|
||||
credit_sales = 0
|
||||
other_sales = 0
|
||||
nett_sales = 0
|
||||
commercial_taxes = 0
|
||||
total_rounding = 0
|
||||
total_receipt = 0
|
||||
total_void = 0
|
||||
dining_count = 0
|
||||
takeaway_count = 0
|
||||
|
||||
sales = shift_sale.sales.order(:created_at)
|
||||
sales.each do |sale|
|
||||
|
||||
new_grand_total = sale.total_amount - sale.total_discount + sale.total_tax + sale.rounding_adjustment
|
||||
old_grand_total = sale.total_amount - sale.total_discount + sale.total_tax
|
||||
amount_changed = sale.amount_received - new_grand_total
|
||||
|
||||
cash_amount = 0
|
||||
credit_amount = 0
|
||||
other_amount = 0
|
||||
|
||||
sale_payments = sale.sale_payments.order(:created_at)
|
||||
sale_payments.each do |sale_payment|
|
||||
|
||||
if sale_payment.payment_method == 'creditnote'
|
||||
credit_amount += sale_payment.payment_amount
|
||||
else
|
||||
if SaleAudit.where("SUBSTRING_INDEX(sale_audits.remark,'||',1) = ? AND sale_audits.sale_id = ?", sale_payment.sale_payment_id, sale.sale_id).exists?
|
||||
if sale_payment.created_at.between?(shift_sale.shift_started_at, shift_sale.shift_closed_at)
|
||||
if credit_amount >= sale_payment.payment_amount
|
||||
credit_amount -= sale_payment.payment_amount
|
||||
else
|
||||
credit_amount = 0
|
||||
end
|
||||
if sale_payment.payment_method == 'cash'
|
||||
cash_amount += sale_payment.payment_amount
|
||||
else
|
||||
other_amount += sale_payment.payment_amount
|
||||
end
|
||||
end
|
||||
else
|
||||
if sale_payment.payment_method == 'cash'
|
||||
cash_amount += sale_payment.payment_amount
|
||||
else
|
||||
other_amount += sale_payment.payment_amount
|
||||
end
|
||||
outstanding_amount = new_grand_total - sale_payment.payment_amount
|
||||
sale_payment.update_columns(outstanding_amount: outstanding_amount)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
sale.update_columns(grand_total: new_grand_total, old_grand_total: old_grand_total, amount_changed: amount_changed)
|
||||
|
||||
if sale.sale_status != 'void'
|
||||
total_revenue += sale.total_amount
|
||||
total_discounts += sale.total_discount
|
||||
total_taxes += sale.total_tax
|
||||
grand_total += sale.grand_total
|
||||
cash_sales += cash_amount - sale.amount_changed
|
||||
credit_sales += credit_amount
|
||||
other_sales += other_amount
|
||||
nett_sales += sale.total_amount - sale.total_discount
|
||||
commercial_taxes += sale.get_commerical_tax
|
||||
total_rounding += sale.rounding_adjustment
|
||||
total_receipt += 1
|
||||
if sale.customer.customer_type == 'Dinein'
|
||||
dining_count += 1
|
||||
else
|
||||
takeaway_count += 1
|
||||
end
|
||||
else
|
||||
total_receipt += 1
|
||||
total_void += 1
|
||||
end
|
||||
end
|
||||
|
||||
if args[:repayment]
|
||||
SalePayment.joins(:sale, :sale_audit).where(sale_payments: {created_at: shift_sale.shift_started_at..shift_sale.shift_closed_at}).where.not(sales: {shift_sale_id: shift_sale.id}).each do |sale_payment|
|
||||
if sale_payment.payment_method == 'cash'
|
||||
cash_amount += sale_payment.payment_amount
|
||||
else
|
||||
other_amount += sale_payment.payment_amount
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
shift_sale.update_columns(
|
||||
{
|
||||
total_revenue: total_revenue,
|
||||
total_discounts: total_discounts,
|
||||
total_taxes: total_taxes,
|
||||
grand_total: grand_total,
|
||||
cash_sales: cash_sales,
|
||||
credit_sales: credit_sales,
|
||||
other_sales: other_sales,
|
||||
nett_sales: nett_sales,
|
||||
commercial_taxes: commercial_taxes,
|
||||
total_rounding: total_rounding,
|
||||
total_receipt: total_receipt,
|
||||
total_void: total_void,
|
||||
dining_count: dining_count,
|
||||
takeaway_count: takeaway_count,
|
||||
}
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user