update sale item with other charges
This commit is contained in:
@@ -15,7 +15,7 @@ class Reports::SaleitemController < BaseReportController
|
||||
shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',shift_sale.shift_started_at, shift_sale.shift_closed_at)
|
||||
end
|
||||
end
|
||||
@sale_data, @discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_by_shift_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED)
|
||||
@sale_data, @other_charges,@discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_by_shift_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED)
|
||||
|
||||
@account_cate_count = Hash.new {|hash, key| hash[key] = 0}
|
||||
|
||||
|
||||
@@ -608,41 +608,38 @@ def self.get_by_shift_sale(from,to,status)
|
||||
end
|
||||
|
||||
def self.get_item_query()
|
||||
# query = SaleItem.select("acc.title as account_name,account_id, item_instance_code as item_code, " +
|
||||
# "SUM(qty * unit_price) as grand_total,SUM(qty) as total_item," +
|
||||
# " unit_price as unit_price,product_name as product_name, 'cat' as" +
|
||||
# " menu_category_name,'test' as menu_category_id ")
|
||||
query = Sale.select("acc.title as account_name,mi.account_id, i.item_instance_code as item_code,i.account_id as account_id, " +
|
||||
"SUM(i.qty * i.unit_price) as grand_total,SUM(i.qty) as total_item," +
|
||||
"i.remark as status_type,"+
|
||||
" i.unit_price as unit_price,i.product_name as product_name, mc.name as" +
|
||||
" menu_category_name,mc.id as menu_category_id ")
|
||||
|
||||
# query = query.joins("JOIN sales s ON s.sale_id = sale_items.sale_id" +
|
||||
# " JOIN shift_sales sh ON sh.`id` = sales.shift_sale_id")
|
||||
# # "JOIN employee_accesses ea ON ea.`employee_id` = sales.cashier_id ")
|
||||
query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id" +
|
||||
" JOIN menu_item_instances mii ON i.item_instance_code = mii.item_instance_code" +
|
||||
" JOIN menu_items mi ON mi.id = mii.menu_item_id" +
|
||||
" JOIN shift_sales sh ON sh.`id` = sales.shift_sale_id" +
|
||||
" JOIN menu_categories mc ON mc.id = mi.menu_category_id ")
|
||||
# "JOIN employee_accesses ea ON ea.`employee_id` = sales.cashier_id ")
|
||||
query = query.joins(" JOIN accounts acc ON acc.id = mi.account_id")
|
||||
# query = query.where("i.item_instance_code IS NOT NULL")
|
||||
query = query.group("i.product_name").order("mi.account_id, mi.menu_category_id")
|
||||
end
|
||||
|
||||
# query = query.joins(" JOIN accounts acc ON acc.id = account_id")
|
||||
# query = query.where("item_instance_code is not NULL")
|
||||
# query = query.group("item_instance_code").order("account_id")
|
||||
|
||||
query = Sale.select("acc.title as account_name,mi.account_id, i.item_instance_code as item_code, " +
|
||||
"SUM(i.qty * i.unit_price) as grand_total,SUM(i.qty) as total_item," +
|
||||
"i.remark as status_type,"+
|
||||
" i.unit_price as unit_price,i.product_name as product_name, mc.name as" +
|
||||
" menu_category_name,mc.id as menu_category_id ")
|
||||
|
||||
query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id" +
|
||||
" JOIN menu_item_instances mii ON i.item_instance_code = mii.item_instance_code" +
|
||||
" JOIN menu_items mi ON mi.id = mii.menu_item_id" +
|
||||
" JOIN shift_sales sh ON sh.`id` = sales.shift_sale_id" +
|
||||
" JOIN menu_categories mc ON mc.id = mi.menu_category_id ")
|
||||
# "JOIN employee_accesses ea ON ea.`employee_id` = sales.cashier_id ")
|
||||
|
||||
query = query.joins(" JOIN accounts acc ON acc.id = mi.account_id")
|
||||
query = query.where("i.item_instance_code IS NOT NULL")
|
||||
query = query.group("i.product_name").order("mi.account_id, mi.menu_category_id")
|
||||
def self.get_other_charges()
|
||||
query = Sale.select("i.account_id as account_id, " +
|
||||
"SUM(i.qty * i.unit_price) as grand_total,SUM(i.qty) as total_item," +
|
||||
"i.remark as status_type,"+
|
||||
" i.unit_price as unit_price,i.product_name as product_name")
|
||||
query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id")
|
||||
query = query.where("i.item_instance_code IS NULL AND i.product_code = 'Other Charges'")
|
||||
query = query.group("i.sale_item_id")
|
||||
end
|
||||
|
||||
def self.get_by_shift_items(shift_sale_range, shift, from, to, status)
|
||||
# date_type_selection = get_sql_function_for_report_type(report_type)
|
||||
|
||||
query = self.get_item_query()
|
||||
|
||||
discount_query = 0
|
||||
total_card_amount = 0
|
||||
total_cash_amount = 0
|
||||
@@ -650,10 +647,14 @@ def self.get_by_shift_items(shift_sale_range, shift, from, to, status)
|
||||
total_foc_amount = 0
|
||||
total_grand_total = 0
|
||||
|
||||
other_charges = self.get_other_charges()
|
||||
puts other_charges.to_json
|
||||
|
||||
if shift.present?
|
||||
query = query.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a)
|
||||
other_charges = other_charges.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a)
|
||||
discount_query = Sale.where("sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:total_discount)
|
||||
change_amount = Sale.where("sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:amount_changed)
|
||||
change_amount = Sale.where("sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:amount_changed)
|
||||
sale_cash = Sale.select("SUM(case when (sale_payments.payment_method ='mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar') then (sale_payments.payment_amount) else 0 end) as card_amount,
|
||||
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='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount,
|
||||
@@ -671,8 +672,9 @@ def self.get_by_shift_items(shift_sale_range, shift, from, to, status)
|
||||
### => get all sales range in shift_sales
|
||||
elsif shift_sale_range.present?
|
||||
query = query.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift_sale_range.to_a)
|
||||
other_charges = other_charges.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift_sale_range.to_a)
|
||||
discount_query = Sale.where("sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:total_discount)
|
||||
change_amount = Sale.where("sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:amount_changed)
|
||||
change_amount = Sale.where("sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:amount_changed)
|
||||
sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar') then (sale_payments.payment_amount) else 0 end) as card_amount,
|
||||
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='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount,
|
||||
@@ -685,12 +687,14 @@ def self.get_by_shift_items(shift_sale_range, shift, from, to, status)
|
||||
total_credit_amount += s_c.credit_amount.to_f
|
||||
total_foc_amount += s_c.foc_amount.to_f
|
||||
end
|
||||
|
||||
total_grand_total = total_cash_amount.to_f + total_card_amount.to_f + total_credit_amount.to_f
|
||||
|
||||
else
|
||||
query = query.where("sales.receipt_date between ? and ? and sale_status='completed'",from,to)
|
||||
other_charges = other_charges.where("sales.receipt_date between ? and ? and sale_status='completed'",from,to)
|
||||
discount_query = Sale.where("sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:total_discount)
|
||||
change_amount = Sale.where("sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:amount_changed)
|
||||
change_amount = Sale.where("sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:amount_changed)
|
||||
sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar') then (sale_payments.payment_amount) else 0 end) as card_amount,
|
||||
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='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount,
|
||||
@@ -707,7 +711,7 @@ def self.get_by_shift_items(shift_sale_range, shift, from, to, status)
|
||||
|
||||
end
|
||||
|
||||
return query, discount_query , total_cash_amount , total_card_amount , total_credit_amount , total_foc_amount , total_grand_total , change_amount
|
||||
return query,other_charges, discount_query , total_cash_amount , total_card_amount , total_credit_amount , total_foc_amount , total_grand_total , change_amount
|
||||
end
|
||||
|
||||
def self.get_shift_sales_by_receipt_no(shift_sale_range,shift,from,to,payment_type)
|
||||
|
||||
@@ -50,6 +50,7 @@
|
||||
<% cate_arr = Array.new %>
|
||||
|
||||
<% sub_total = 0 %>
|
||||
<% other_sub_total = 0 %>
|
||||
<% count = 0 %>
|
||||
<% total_price = 0 %>
|
||||
<% cate_count = 0 %>
|
||||
@@ -63,68 +64,97 @@
|
||||
|
||||
<% @sale_data.each do |sale| %>
|
||||
|
||||
<% if sale.total_item > 0
|
||||
total_qty += sale.total_item
|
||||
end %>
|
||||
<% if sale.total_item > 0
|
||||
total_qty += sale.total_item
|
||||
end %>
|
||||
|
||||
<% if !acc_arr.include?(sale.account_id) %>
|
||||
<tr>
|
||||
<td><b><%= sale.account_name %></b></td>
|
||||
<td colspan="4"> </td>
|
||||
<td><%= t("views.right_panel.detail.total_price_by") %> <%= sale.account_name %></td>
|
||||
<td>
|
||||
<% @totalByAccount.each do |account, total| %>
|
||||
<% if sale.account_id == account %>
|
||||
<b><%= total %></b>
|
||||
<% grand_total += total %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</td>
|
||||
</tr>
|
||||
<% acc_arr.push(sale.account_id) %>
|
||||
|
||||
<% end %>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<% if !cate_arr.include?(sale.menu_category_id) %>
|
||||
<td><%= sale.menu_category_name %></td>
|
||||
<% cate_arr.push(sale.menu_category_id) %>
|
||||
<% else %>
|
||||
<td> </td>
|
||||
<% if !acc_arr.include?(sale.account_id) %>
|
||||
<tr>
|
||||
<td><b><%= sale.account_name %></b></td>
|
||||
<td colspan="4"> </td>
|
||||
<td><%= t("views.right_panel.detail.total_price_by") %> <%= sale.account_name %></td>
|
||||
<td>
|
||||
<% @totalByAccount.each do |account, total| %>
|
||||
<% if sale.account_id == account %>
|
||||
<b><%= total %></b>
|
||||
<% grand_total += total %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</td>
|
||||
</tr>
|
||||
<% acc_arr.push(sale.account_id) %>
|
||||
<% end %>
|
||||
<td><%= sale.item_code rescue '-' %></td>
|
||||
<td><%= sale.product_name rescue '-' %></td>
|
||||
<td><%= sale.total_item rescue '-' %></td>
|
||||
<td><%= sale.unit_price rescue '-' %></td>
|
||||
<td><%= sale.grand_total rescue '-' %></td>
|
||||
</tr>
|
||||
<!-- sub total -->
|
||||
<% @menu_cate_count.each do |key,value| %>
|
||||
<% if sale.menu_category_id == key %>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<% if !cate_arr.include?(sale.menu_category_id) %>
|
||||
<td><%= sale.menu_category_name %></td>
|
||||
<% cate_arr.push(sale.menu_category_id) %>
|
||||
<% else %>
|
||||
<td> </td>
|
||||
<% end %>
|
||||
<td><%= sale.item_code rescue '-' %></td>
|
||||
<td><%= sale.product_name rescue '-' %></td>
|
||||
<td><%= sale.total_item rescue '-' %></td>
|
||||
<td><%= sale.unit_price rescue '-' %></td>
|
||||
<td><%= sale.grand_total rescue '-' %></td>
|
||||
</tr>
|
||||
<!-- sub total -->
|
||||
<% @menu_cate_count.each do |key,value| %>
|
||||
<% if sale.menu_category_id == key %>
|
||||
|
||||
<% count = count + 1 %>
|
||||
<% sub_total += sale.grand_total %>
|
||||
<% if count == value %>
|
||||
<% count = count + 1 %>
|
||||
<% sub_total += sale.grand_total %>
|
||||
<% if count == value %>
|
||||
<tr>
|
||||
<td colspan="5"> </td>
|
||||
<td><%= t("views.right_panel.detail.sub_total") %></td>
|
||||
<td ><span class="underline"><%= sub_total %></span></td>
|
||||
</tr>
|
||||
<% if sale.status_type === "foc"
|
||||
total_item_foc += sale.grand_total
|
||||
end %>
|
||||
|
||||
<% if sale.status_type === "Discount"
|
||||
total_item_dis += sale.grand_total
|
||||
end %>
|
||||
<% sub_total = 0.0%>
|
||||
<% count = 0%>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<!-- end sub total -->
|
||||
<% end %>
|
||||
<!--Other Charges -->
|
||||
<tr>
|
||||
<td><b>Other Charges</b></td>
|
||||
<td colspan="4"> </td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<% @other_charges.each do |other| %>
|
||||
<% if other.total_item > 0
|
||||
total_qty += other.total_item
|
||||
end %>
|
||||
<% grand_total +=other.grand_total%>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>Other Charges</td>
|
||||
<td><%= other.item_code rescue '-' %></td>
|
||||
<td><%= other.product_name rescue '-' %></td>
|
||||
<td><%= other.total_item rescue '-' %></td>
|
||||
<td><%= other.unit_price rescue '-' %></td>
|
||||
<td><%= other.grand_total rescue '-' %></td>
|
||||
</tr>
|
||||
<!-- sub total -->
|
||||
|
||||
<% other_sub_total += other.grand_total %>
|
||||
<!-- end sub total -->
|
||||
<% end %>
|
||||
<tr>
|
||||
<td colspan="5"> </td>
|
||||
<td><%= t("views.right_panel.detail.sub_total") %></td>
|
||||
<td ><span class="underline"><%= sub_total %></span></td>
|
||||
<td ><span class="underline"><%= other_sub_total %></span></td>
|
||||
</tr>
|
||||
<% if sale.status_type === "foc"
|
||||
total_item_foc += sale.grand_total
|
||||
end %>
|
||||
|
||||
<% if sale.status_type === "Discount"
|
||||
total_item_dis += sale.grand_total
|
||||
end %>
|
||||
<% sub_total = 0.0%>
|
||||
<% count = 0%>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<!-- end sub total -->
|
||||
<% end %>
|
||||
|
||||
<!-- End Other Charges -->
|
||||
<tr style="border-top:2px solid grey;">
|
||||
<td colspan="3"> </td>
|
||||
<td><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.item") %></td>
|
||||
|
||||
Reference in New Issue
Block a user