diff --git a/app/controllers/reports/saleitem_controller.rb b/app/controllers/reports/saleitem_controller.rb index 422c3020..428bf9d7 100755 --- a/app/controllers/reports/saleitem_controller.rb +++ b/app/controllers/reports/saleitem_controller.rb @@ -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} diff --git a/app/models/ability.rb b/app/models/ability.rb index 50f37fbc..4470fb4b 100755 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -41,6 +41,13 @@ class Ability can :index, :credit_payment can :index, :void_sale + can :show, :dailysale + can :show, :saleitem + can :show, :receipt_no + can :show, :shiftsale + can :show, :credit_payment + can :show, :void_sale + can :get_customer, Customer can :add_customer, Customer can :update_sale_by_customer, Customer @@ -128,6 +135,12 @@ class Ability can :index, :shiftsale can :index, :credit_payment can :index, :void_sale + can :show, :dailysale + can :show, :saleitem + can :show, :receipt_no + can :show, :shiftsale + can :show, :credit_payment + can :show, :void_sale elsif user.role == "supervisor" diff --git a/app/models/sale.rb b/app/models/sale.rb index 4b2acadc..f216a34c 100755 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -521,7 +521,7 @@ def self.daily_sales_list(from,to) 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, SUM(case when (sale_payments.payment_method='foc') then sale_payments.payment_amount else 0 end) as foc_amount") - .joins("join (select * from sale_payments group by sale_payments.sale_id, sale_payments.payment_method) sale_payments on sale_payments.sale_id = sales.sale_id") + .joins("join (select * from sale_payments group by sale_payments.sale_id, sale_payments.payment_method) sale_payments on sale_payments.sale_id = sales.sale_id") .where("sale_status = ? AND sales.receipt_date between ? and ? ", 'completed', from, to) .group("DATE_FORMAT((CONVERT_TZ(sales.receipt_date,'+00:00','+06:30')),'%Y-%m-%d')") @@ -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,13 @@ 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() + 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 +671,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 +686,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 +710,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) diff --git a/app/views/reports/credit_payment/index.xls.erb b/app/views/reports/credit_payment/index.xls.erb index 9597e3d9..af3d773e 100755 --- a/app/views/reports/credit_payment/index.xls.erb +++ b/app/views/reports/credit_payment/index.xls.erb @@ -1,20 +1,43 @@ -
-
+ + + <%= render :partial=>'shift_sale_report_filter', + :locals=>{ :period_type => true, :shift_name => true, :report_path =>reports_credit_payment_index_path} %> +
+ + + + + + + + +
+
<% unless @sale_data.blank? %> <% if !params[:from].blank?%> - + <% end %> - - - - - + + + + + @@ -36,4 +59,4 @@
From Date : <%= params[:from] rescue '-'%> , To Date : <%= params[:to] rescue '-'%><%= t("views.right_panel.detail.from_date") %> : <%= params[:from] rescue '-'%> , <%= t("views.right_panel.detail.to_date") %> : <%= params[:to] rescue '-'%>
Shift Name Receive No Cashier Name Customer Name Credit Amount <%= t("views.right_panel.detail.shift_name") %> <%= t("views.right_panel.detail.receipt_no") %> <%= t :cashier %> <%= t("views.right_panel.detail.name") %> <%= t :customer %> <%= t("views.right_panel.detail.name") %> <%= t("views.right_panel.detail.credit_amount") %>
<% end %>
-
\ No newline at end of file +
diff --git a/app/views/reports/dailysale/index.html.erb b/app/views/reports/dailysale/index.html.erb index aa464ab7..82ed099a 100755 --- a/app/views/reports/dailysale/index.html.erb +++ b/app/views/reports/dailysale/index.html.erb @@ -1,5 +1,5 @@ -