From 82b6474bc73303af3473140b16a33c7bb7b9edbe Mon Sep 17 00:00:00 2001 From: Pyae Bhone Zaw Date: Thu, 26 Jun 2025 11:09:11 +0630 Subject: [PATCH] feat: add mmqr in shift sale report --- app/models/sale.rb | 3 ++- app/models/shift_sale.rb | 9 +++++++++ app/views/reports/shiftsale/index.html.erb | 6 +++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/models/sale.rb b/app/models/sale.rb index 06b161dc..3c34b2e5 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -826,7 +826,8 @@ def self.get_by_shiftsales(from,to,shift) :shift_closed_at => shift_sale.shift_closed_at, :cash_sales => shift_sale.cash_sales, :credit_sales => shift_sale.credit_sales, - :other_sales => shift_sale.other_sales.to_f, + :other_sales => (shift_sale.other_sales.to_f - ShiftSale.get_by_shift_mmqr_payment(shift_sale.id).to_f).abs, + :mmqr_sales => ShiftSale.get_by_shift_mmqr_payment(shift_sale.id).to_f, :foc_sales => foc, :grand_total => shift_sale.grand_total, :shift_id => shift_sale.id diff --git a/app/models/shift_sale.rb b/app/models/shift_sale.rb index d930580e..1877bde2 100755 --- a/app/models/shift_sale.rb +++ b/app/models/shift_sale.rb @@ -152,6 +152,15 @@ class ShiftSale < ApplicationRecord return closing_balance end + def self.get_by_shift_mmqr_payment(shift) + Sale.joins(:sale_payments) + .where(shift_sale_id: shift, sale_status: 'completed') + .where(sale_payments: { payment_method: 'mmqr' }) + .where.not(sale_payments: { payment_status: 'cancelled' }) + .where.not(sale_payments: { payment_amount: 0 }) + .sum("sale_payments.payment_amount") + end + def self.get_by_shift_other_payment(shift) payment_methods = SalePayment.where.not(payment_method: ['cash', 'creditnote', 'foc']).distinct.pluck(:payment_method) diff --git a/app/views/reports/shiftsale/index.html.erb b/app/views/reports/shiftsale/index.html.erb index 7b102cdc..340930b5 100755 --- a/app/views/reports/shiftsale/index.html.erb +++ b/app/views/reports/shiftsale/index.html.erb @@ -55,6 +55,7 @@ <%= t("views.right_panel.detail.credit_payment") %> <%= t("views.btn.other_payment") %> + <%= t("views.btn.mmqr_payment") %> <%= t("views.btn.foc") %> <%= t :payment %> @@ -74,6 +75,7 @@ <% credit = 0%> <% accept_credit = 0%> <% foc = 0%> + <% mmqr = 0 %> <% card = 0%> <% total = 0%> <% rounding_adj = 0%> @@ -98,6 +100,7 @@ <%= number_format(result[:other_sales].to_f, precision:precision.to_i,delimiter:delimiter) rescue '-'%> + <%= number_format(result[:mmqr_sales].to_f, precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_format(result[:foc_sales].to_f, precision:precision.to_i,delimiter:delimiter) rescue '-'%> @@ -113,7 +116,7 @@ <% credit += result[:credit_sales].to_f %> <% card += result[:other_sales].to_f %> <% foc += result[:foc_sales].to_f %> - + <% mmqr += result[:mmqr_sales].to_f %> <% total += result[:grand_total].to_f %> <% g_total += grand_total.to_f %> @@ -127,6 +130,7 @@ <%= number_format(card, precision:precision.to_i,delimiter:delimiter) rescue '-'%> + <%= number_format(mmqr, precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_format(foc, precision:precision.to_i,delimiter:delimiter) rescue '-'%>