daily sale net sales & tax
This commit is contained in:
@@ -4,7 +4,7 @@ class Reports::DailysaleController < BaseReportController
|
||||
def index
|
||||
from, to = get_date_range_from_params
|
||||
@sale_data = Sale.daily_sales_list(from,to)
|
||||
@tax = SaleTax.get_tax(from,to)
|
||||
@tax_profiles = TaxProfile.group(:name).order(:order_by).pluck(:name)
|
||||
@from = from
|
||||
@to = to
|
||||
@payment_methods = PaymentMethodSetting.where("is_active='1'").pluck("payment_method")
|
||||
|
||||
@@ -754,6 +754,8 @@ class Sale < ApplicationRecord
|
||||
def self.daily_sales_list(from,to)
|
||||
payment_methods = SalePayment.where.not(payment_method: ['cash', 'creditnote', 'foc']).distinct.pluck(:payment_method)
|
||||
|
||||
tax_profiles = TaxProfile.group(:name).order(:order_by).pluck(:name)
|
||||
|
||||
sales = select(Sale.column_names)
|
||||
.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(', ')}
|
||||
SUM(case when (sale_payments.payment_method='cash') then sale_payments.payment_amount else 0 end) as cash_amount,
|
||||
@@ -764,6 +766,15 @@ class Sale < ApplicationRecord
|
||||
.where("(sale_status = ? OR sale_status = ?) AND sales.receipt_date between ? AND ? ", 'completed', 'void', from, to)
|
||||
.group("sale_id").to_sql
|
||||
|
||||
sale_taxes = Sale.select('sales.sale_id, sale_taxes.tax_name')
|
||||
.joins(:sale_taxes)
|
||||
.where('(sale_status = ? OR sale_status = ?) AND sales.receipt_date between ? AND ? ', 'completed', 'void', from, to)
|
||||
.group('sale_id')
|
||||
|
||||
if tax_profiles.present?
|
||||
sale_taxes = sale_taxes.select(tax_profiles.map { |name| "SUM(case when (sale_taxes.tax_name = '#{name}') then sale_taxes.tax_payable_amount else 0 end) as `#{name.parameterize}`"}.join(', '))
|
||||
end
|
||||
|
||||
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,
|
||||
@@ -772,8 +783,9 @@ class Sale < ApplicationRecord
|
||||
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,
|
||||
#{tax_profiles.map { |name| "SUM(`#{name.parameterize}`) as `#{name.parameterize}`"}.push('').join(', ') if tax_profiles.present?}
|
||||
IFNULL(SUM(case when (sale_status='completed') then total_tax else 0 end),0) as tax,
|
||||
(IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0)) - (IFNULL(SUM(case when (sale_status='completed') then total_tax else 0 end),0)) 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,
|
||||
#{payment_methods.map { |method| pm = method == 'paypar' ? 'redeem' : method; "SUM(`#{pm}`) as `#{pm}`"}.push('').join(', ')}
|
||||
@@ -783,6 +795,7 @@ class Sale < ApplicationRecord
|
||||
FROM (
|
||||
#{sales}
|
||||
) as s
|
||||
JOIN (#{sale_taxes.to_sql}) AS st ON s.sale_id = st.sale_id
|
||||
GROUP BY DATE(CONVERT_TZ(receipt_date,'+00:00','+06:30'))").to_hash.map(&:symbolize_keys)
|
||||
return daily_total
|
||||
end
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<table class="table table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="<%= column_count = @payment_methods.length + 12 %>"> <%= t("views.right_panel.detail.from_date") %> : <%= @from.utc.getlocal.strftime("%Y-%b-%d") rescue '-' %> - <%= t("views.right_panel.detail.to_date") %> : <%= @to.utc.getlocal.strftime("%Y-%b-%d") rescue '-'%></th>
|
||||
<th colspan="<%= column_count = @payment_methods.length + 11 + @tax_profiles.length %>"> <%= t("views.right_panel.detail.from_date") %> : <%= @from.utc.getlocal.strftime("%Y-%b-%d") rescue '-' %> - <%= t("views.right_panel.detail.to_date") %> : <%= @to.utc.getlocal.strftime("%Y-%b-%d") rescue '-'%></th>
|
||||
</tr>
|
||||
<% @count = 1 %>
|
||||
<% @payment_methods.each_slice(10) do |slice| %>
|
||||
@@ -72,13 +72,11 @@
|
||||
<th></th>
|
||||
<th></th>
|
||||
<th colspan="<%= @count + 1 %>" style='text-align:center;'>Income</th>
|
||||
<th colspan=4 style='text-align:center;'>Outgoing</th>
|
||||
<th style='text-align:center; cursor: help;' data-toggle="tooltip" data-placement="top" title="Gross Sales = (Income+Discount) - Void"><i class="material-icons md-18">live_help</i></th>
|
||||
<th colspan='4' style='text-align:center;'>Outgoing</th>
|
||||
<th colspan='<%= @tax_profiles.size %>' style='text-align:center;'>Tax</th>
|
||||
<th style='text-align:center; cursor: help;' data-toggle="tooltip" data-placement="top" title="Net Sales = Income - Tax"><i class="material-icons md-18">live_help</i></th>
|
||||
<th style='text-align:center; cursor: help;' data-toggle="tooltip" data-placement="top" title="Gross Sales = Income + Discount"><i class="material-icons md-18">live_help</i></th>
|
||||
<th style='text-align:center; cursor: help;' data-toggle="tooltip" data-placement="top" title="Total Sales = Gross Sales - Discount"><i class="material-icons md-18">live_help</i></th>
|
||||
<% if @tax.blank? %>
|
||||
<th style='text-align:center; cursor: help;' data-toggle="tooltip" data-placement="top" title="Tax = Total Sales / 21"><i class="material-icons md-18">live_help</i></th>
|
||||
<th style='text-align:center; cursor: help;' data-toggle="tooltip" data-placement="top" title="Net Sales = Total Sales - Tax"><i class="material-icons md-18">live_help</i></th>
|
||||
<% end %>
|
||||
</tr>
|
||||
<tr>
|
||||
<th style='text-align:center;'><%= t("views.right_panel.detail.sr") %></th>
|
||||
@@ -86,22 +84,21 @@
|
||||
<% @payment_methods.each do |method| %>
|
||||
<th style='text-align:center;' class="d-none d-sm-table-cell"><%= t("views.right_panel.detail.#{method}") %></th>
|
||||
<% end %>
|
||||
|
||||
<th style='text-align:center;'><%= t("views.right_panel.detail.cash_sales") %></th>
|
||||
<th style='text-align:center;'><%= t("views.right_panel.detail.credit_sales") %></th>
|
||||
<th style='text-align:center;'><%= t("views.right_panel.detail.void_amount") %></th>
|
||||
<th style='text-align:center;'><%= t("views.right_panel.detail.foc_sales") %></th>
|
||||
|
||||
<th style='text-align:center;'>(<%= t("views.right_panel.detail.discount") %>)</th>
|
||||
<!-- <th style='text-align:center;'><%= t("views.right_panel.detail.grand_total") %> + <br/> <%= t("views.right_panel.detail.rnd_adj_sh") %></th> -->
|
||||
<th style='text-align:center;'><%= t("views.right_panel.detail.rnd_adj_sh") %></th>
|
||||
<% if @tax_profiles.present? %>
|
||||
<% @tax_profiles.each do |name| %>
|
||||
<th style='text-align:center;'><%= t name %></th>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<th style='text-align:center;'><%= t("views.right_panel.detail.net_sales") %></th>
|
||||
<th style='text-align:center;'><%= t("views.right_panel.detail.gross_sales") %></th>
|
||||
<th style='text-align:center;'><%= t("views.right_panel.detail.total_sales") %></th>
|
||||
<% if @tax.blank? %>
|
||||
<th style='text-align:center;'><%= t("views.right_panel.detail.tax") %></th>
|
||||
<th style='text-align:center;'><%= t("views.right_panel.detail.net_sales") %></th>
|
||||
<% end %>
|
||||
|
||||
</tr>
|
||||
</thead>
|
||||
<% unless @sale_data.blank? %>
|
||||
@@ -148,12 +145,16 @@
|
||||
<td style='text-align:right;'>(<%= number_format(sale[:total_discount], precision:precision,delimiter:delimiter) rescue '-'%>)</td>
|
||||
<!-- <td style='text-align:right;'><%= number_format(sale[:grand_total].to_f + sale[:rounding_adj].to_f , precision:precision.to_i,delimiter:delimiter) rescue '-'%></td> -->
|
||||
<td style='text-align:right;'><%= number_format(sale[:rounding_adj], precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
|
||||
|
||||
<% if @tax_profiles.present? %>
|
||||
<% @tax_profiles.each do |name| %>
|
||||
<td style='text-align:right;'><%= number_format(sale[name.parameterize.to_sym], precision:precision.to_i,delimiter:delimiter) rescue '-' %></td>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<td style='text-align:right;'><%= number_format(sale[:net_sale], precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
|
||||
<td style='text-align:right;'><%= number_format(sale[:gross_sale], precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
|
||||
<td style='text-align:right;'><%= number_format(sale[:total_sale], precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
|
||||
<% if @tax.blank? %>
|
||||
<td style='text-align:right;'><%= number_format(sale[:tax], precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
|
||||
<td style='text-align:right;'><%= number_format(sale[:net_sale], precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
|
||||
<% end %>
|
||||
|
||||
</tr>
|
||||
<% count = count + 1 %>
|
||||
@@ -172,33 +173,37 @@
|
||||
|
||||
<td style='text-align:right;'>(<%= number_format(discount, precision:precision.to_i,delimiter:delimiter) rescue '-'%>)</td>
|
||||
<td style='text-align:right;'><%= number_format(rounding_adj, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
|
||||
<td style='text-align:right;'><%= number_format(gross_sale, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
|
||||
<td style='text-align:right;'><%= number_format(total_sale, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
|
||||
<% if @tax.blank? %>
|
||||
<td style='text-align:right;'><%= number_format(tax, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
|
||||
<td style='text-align:right;'><%= number_format(net_sale, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
|
||||
|
||||
<% if @tax_profiles.present? %>
|
||||
<% @tax_profiles.each do |name| %>
|
||||
<td style='text-align:right;'><%= number_format(@sale_data.inject(0.0.to_d) { |sum, sale| sum + sale[name.parameterize.to_sym] }, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<td style='text-align:right;'><%= number_format(net_sale, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
|
||||
<td style='text-align:right;'><%= number_format(gross_sale, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
|
||||
<td style='text-align:right;'><%= number_format(total_sale, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
|
||||
</tr>
|
||||
<tr style="font-weight:600;">
|
||||
<td colspan="<%= column_count %>"> </td>
|
||||
</tr>
|
||||
<% total_tax = 0 %>
|
||||
<% net = 0 %>
|
||||
<% unless @tax.blank? %>
|
||||
<% @tax.each do |tax|
|
||||
total_tax += tax.tax_amount.to_f %>
|
||||
<tr style="font-weight:600;">
|
||||
<td colspan="<%= colspan + 2 %>" style='text-align:right;'><%= tax.tax_name rescue '-'%></td>
|
||||
<td colspan="5" style='text-align:right;'><%= number_format(tax.tax_amount, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
|
||||
</tr>
|
||||
<% if @tax_profiles.present? %>
|
||||
<% @tax_profiles.each do |name| %>
|
||||
<tr style="font-weight:600;">
|
||||
<td colspan="<%= colspan + 2 %>" style='text-align:right;'><%= t name rescue '-'%></td>
|
||||
<td colspan="5" style='text-align:right;'>
|
||||
<%= number_format(@sale_data.inject(0.0.to_d) { |sum, sale| sum + sale[name.parameterize.to_sym] }, precision:precision.to_i,delimiter:delimiter) rescue '-'%>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<% net = grand_total %>
|
||||
<% net = net - rounding_adj%>
|
||||
<% net = net - total_tax %>
|
||||
<tr style="font-weight:600;">
|
||||
<td colspan="<%= colspan + 2 %>" style='text-align:right;'><%= t("views.right_panel.detail.net_amount") %></td>
|
||||
<td colspan="5" style='text-align:right;'><%= number_format(net, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
|
||||
<td colspan="5" style='text-align:right;'><%= number_format(net, precision:precision.to_i,delimiter:delimiter) rescue '-' %></td>
|
||||
</tr>
|
||||
<% else %>
|
||||
<tr style="font-weight:600;">
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
<th></th>
|
||||
<th colspan="<%= @count + 1 %>" style='text-align:center;'>Income</th>
|
||||
<th colspan=4 style='text-align:center;'>Outgoing</th>
|
||||
<th colspan='<%= @tax_profiles.size %>' style='text-align:center;'>Tax</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th style='text-align:center;'><%= t("views.right_panel.detail.sr") %></th>
|
||||
@@ -38,13 +39,14 @@
|
||||
<th style='text-align:center;'>(<%= t("views.right_panel.detail.discount") %>)</th>
|
||||
<!-- <th style='text-align:center;'><%= t("views.right_panel.detail.grand_total") %> + <br/> <%= t("views.right_panel.detail.rnd_adj_sh") %></th> -->
|
||||
<th style='text-align:center;'><%= t("views.right_panel.detail.rnd_adj_sh") %></th>
|
||||
<% if @tax_profiles.present? %>
|
||||
<% @tax_profiles.each do |name| %>
|
||||
<th style='text-align:center;'><%= t name %></th>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<th style='text-align:center;'><%= t("views.right_panel.detail.net_sales") %></th>
|
||||
<th style='text-align:center;'><%= t("views.right_panel.detail.gross_sales") %></th>
|
||||
<th style='text-align:center;'><%= t("views.right_panel.detail.total_sales") %></th>
|
||||
<% if @tax.blank? %>
|
||||
<th style='text-align:center;'><%= t("views.right_panel.detail.tax") %></th>
|
||||
<th style='text-align:center;'><%= t("views.right_panel.detail.net_sales") %></th>
|
||||
<% end %>
|
||||
|
||||
</tr>
|
||||
</thead>
|
||||
<% unless @sale_data.blank? %>
|
||||
@@ -90,12 +92,16 @@
|
||||
<td style='text-align:right;'>(<%= number_format(sale[:total_discount], precision:precision,delimiter:delimiter) rescue '-'%>)</td>
|
||||
<!-- <td style='text-align:right;'><%= number_format(sale[:grand_total].to_f + sale[:rounding_adj].to_f , precision:precision.to_i,delimiter:delimiter) rescue '-'%></td> -->
|
||||
<td style='text-align:right;'><%= number_format(sale[:rounding_adj].to_f, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
|
||||
|
||||
<% if @tax_profiles.present? %>
|
||||
<% @tax_profiles.each do |name| %>
|
||||
<td style='text-align:right;'><%= number_format(sale[name.parameterize.to_sym], precision:precision.to_i,delimiter:delimiter) rescue '-' %></td>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<td style='text-align:right;'><%= number_format(sale[:net_sale], precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
|
||||
<td style='text-align:right;'><%= number_format(sale[:gross_sale], precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
|
||||
<td style='text-align:right;'><%= number_format(sale[:total_sale], precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
|
||||
<% if @tax.blank? %>
|
||||
<td style='text-align:right;'><%= number_format(sale[:tax], precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
|
||||
<td style='text-align:right;'><%= number_format(sale[:net_sale], precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
|
||||
<% end %>
|
||||
|
||||
</tr>
|
||||
<% count = count + 1 %>
|
||||
@@ -114,12 +120,15 @@
|
||||
|
||||
<td style='text-align:right;'>(<%= number_format(discount, precision:precision.to_i,delimiter:delimiter) rescue '-'%>)</td>
|
||||
<td style='text-align:right;'><%= number_format(rounding_adj, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
|
||||
<% if @tax_profiles.present? %>
|
||||
<% @tax_profiles.each do |name| %>
|
||||
<td style='text-align:right;'><%= number_format(@sale_data.inject(0.0.to_d) { |sum, sale| sum + sale[name.parameterize.to_sym] }, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<td style='text-align:right;'><%= number_format(net_sale, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
|
||||
<td style='text-align:right;'><%= number_format(gross_sale, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
|
||||
<td style='text-align:right;'><%= number_format(total_sale, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
|
||||
<% if @tax.blank? %>
|
||||
<td style='text-align:right;'><%= number_format(tax, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
|
||||
<td style='text-align:right;'><%= number_format(net_sale, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
|
||||
<% end %>
|
||||
|
||||
</tr>
|
||||
<tr style="font-weight:600;">
|
||||
@@ -127,20 +136,21 @@
|
||||
</tr>
|
||||
<% total_tax = 0 %>
|
||||
<% net = 0 %>
|
||||
<% unless @tax.blank? %>
|
||||
<% @tax.each do |tax|
|
||||
total_tax += tax.tax_amount.to_f %>
|
||||
<tr style="font-weight:600;">
|
||||
<td colspan="<%= colspan + 2 %>" style='text-align:right;'><%= tax.tax_name rescue '-'%></td>
|
||||
<td colspan="1" style='text-align:right;'><%= number_format(tax.tax_amount, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
|
||||
</tr>
|
||||
<% if @tax_profiles.present? %>
|
||||
<% @tax_profiles.each do |name| %>
|
||||
<tr style="font-weight:600;">
|
||||
<td colspan="<%= colspan + 2 %>" style='text-align:right;'><%= t name rescue '-'%></td>
|
||||
<td colspan="4" style='text-align:right;'>
|
||||
<%= number_format(@sale_data.inject(0.0.to_d) { |sum, sale| sum + sale[name.parameterize.to_sym] }, precision:precision.to_i,delimiter:delimiter) rescue '-'%>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<% net = grand_total %>
|
||||
<% net = net - rounding_adj%>
|
||||
<% net = net - total_tax %>
|
||||
<tr style="font-weight:600;">
|
||||
<td colspan="<%= colspan + 2 %>" style='text-align:right;'><%= t("views.right_panel.detail.net_amount") %></td>
|
||||
<td colspan="1" style='text-align:right;'><%= number_format(net, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
|
||||
<td colspan="4" style='text-align:right;'><%= number_format(net, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
|
||||
</tr>
|
||||
<% else %>
|
||||
<tr style="font-weight:600;">
|
||||
|
||||
Reference in New Issue
Block a user