diff --git a/app/controllers/base_report_controller.rb b/app/controllers/base_report_controller.rb index 77e38f2c..c1ae1a01 100644 --- a/app/controllers/base_report_controller.rb +++ b/app/controllers/base_report_controller.rb @@ -1,8 +1,77 @@ class BaseReportController < ActionController::Base - include LoginVerification + include LoginVerification + layout "application" - #before_action :check_installation - protect_from_forgery with: :exception + #before_action :check_installation + protect_from_forgery with: :exception + PERIOD = { + "today" => 0, + "yesterday" => 1, + "this_week" => 2, + "last_week" => 3, + "last_7" => 4, + "this_month" => 5, + "last_month" => 6, + "last_30" => 7, + "this_year" => 8, + "last_year" => 9 + } + + def get_date_range_from_params + period_type = params[:period_type] + period = params[:period] + from = params[:from] + to = params[:to] + day_ref = Time.now + if period_type.to_i == 1 + if params[:from] && params[:to] + if params[:from] != "" && params[:to] !="" + from = DateTime.strptime(params[:from], "%m/%d/%Y") + to = DateTime.strptime(params[:to], "%m/%d/%Y") + else + from = day_ref.beginning_of_day.utc + to = day_ref.end_of_day.utc + end + end + else + case period.to_i + when PERIOD["today"] + + from = day_ref.beginning_of_day.utc + to = day_ref.end_of_day.utc + + when PERIOD["yesterday"] + from = (day_ref - 1.day).beginning_of_day.utc + to = (day_ref - 1.day).end_of_day.utc + + when PERIOD["this_week"] + from = Time.now.beginning_of_week.utc + to = Time.now.utc + when PERIOD["last_week"] + from = (day_ref - 7.day).beginning_of_week.utc + to = (day_ref - 7.day).end_of_week.utc + when PERIOD["last_7"] + from = (day_ref - 7.day).utc + to = Time.now.utc + when PERIOD["this_month"] + from = Time.now.beginning_of_month.utc + to = Time.now.utc + when PERIOD["last_month"] + from = (day_ref - 1.month).beginning_of_month.utc + to = (day_ref - 1.month).end_of_month.utc + when PERIOD["last_30"] + from = (day_ref - 30.day).utc + to = Time.now.utc + when PERIOD["this_year"] + from = Time.now.beginning_of_year.utc + to = Time.now.utc + when PERIOD["last_year"] + from = (day_ref - 1.year).beginning_of_year.utc + to = (day_ref - 1.year).end_of_year.utc + end + end + return from, to + end end diff --git a/app/controllers/reports/daily_sale_controller.rb b/app/controllers/reports/daily_sale_controller.rb new file mode 100644 index 00000000..b4c701ae --- /dev/null +++ b/app/controllers/reports/daily_sale_controller.rb @@ -0,0 +1,21 @@ +class Reports::DailySaleController < BaseReportController + PERIOD = { + "today" => 0, + "yesterday" => 1, + "this_week" => 2, + "last_week" => 3, + "last_7" => 4, + "this_month" => 5, + "last_month" => 6, + "last_30" => 7, + "this_year" => 8, + "last_year" => 9 + } + + def index + from, to = get_date_range_from_params + @sale_data = Sale.get_receipt_no_list(from,to) + @sale_data = Kaminari.paginate_array(@sale_data).page(params[:page]).per(50) +end + +end \ No newline at end of file diff --git a/app/controllers/reports/receipt_no_controller.rb b/app/controllers/reports/receipt_no_controller.rb index 930659b9..8569c051 100644 --- a/app/controllers/reports/receipt_no_controller.rb +++ b/app/controllers/reports/receipt_no_controller.rb @@ -1,17 +1,4 @@ -class Reports::ReceiptNoController < ApplicationController - PERIOD = { - "today" => 0, - "yesterday" => 1, - "this_week" => 2, - "last_week" => 3, - "last_7" => 4, - "this_month" => 5, - "last_month" => 6, - "last_30" => 7, - "this_year" => 8, - "last_year" => 9 - } - +class Reports::ReceiptNoController < BaseReportController def index from, to = get_date_range_from_params puts "from..." @@ -25,61 +12,4 @@ class Reports::ReceiptNoController < ApplicationController def show end - - private - def get_date_range_from_params - period_type = params[:period_type] - period = params[:period] - from = params[:from] - to = params[:to] - day_ref = Time.now - if period_type.to_i == 1 - if params[:from] && params[:to] - if params[:from] != "" && params[:to] !="" - from = DateTime.strptime(params[:from], "%m/%d/%Y") - to = DateTime.strptime(params[:to], "%m/%d/%Y") - else - from = day_ref.beginning_of_day.utc - to = day_ref.end_of_day.utc - end - end - else - case period.to_i - when PERIOD["today"] - - from = day_ref.beginning_of_day.utc - to = day_ref.end_of_day.utc - - when PERIOD["yesterday"] - from = (day_ref - 1.day).beginning_of_day.utc - to = (day_ref - 1.day).end_of_day.utc - - when PERIOD["this_week"] - from = Time.now.beginning_of_week.utc - to = Time.now.utc - when PERIOD["last_week"] - from = (day_ref - 7.day).beginning_of_week.utc - to = (day_ref - 7.day).end_of_week.utc - when PERIOD["last_7"] - from = (day_ref - 7.day).utc - to = Time.now.utc - when PERIOD["this_month"] - from = Time.now.beginning_of_month.utc - to = Time.now.utc - when PERIOD["last_month"] - from = (day_ref - 1.month).beginning_of_month.utc - to = (day_ref - 1.month).end_of_month.utc - when PERIOD["last_30"] - from = (day_ref - 30.day).utc - to = Time.now.utc - when PERIOD["this_year"] - from = Time.now.beginning_of_year.utc - to = Time.now.utc - when PERIOD["last_year"] - from = (day_ref - 1.year).beginning_of_year.utc - to = (day_ref - 1.year).end_of_year.utc - end - end - return from, to - end end \ No newline at end of file diff --git a/app/views/origami/home/index.html.erb b/app/views/origami/home/index.html.erb index 77fb4df0..3477364a 100644 --- a/app/views/origami/home/index.html.erb +++ b/app/views/origami/home/index.html.erb @@ -316,7 +316,7 @@ sub_total = 0 if @selected_item_type == "Sale" @selected_item.sale_items.each do |sale_item| - sub_total += sale_item.qty*sale_item.unit_price + sub_total += (sale_item.qty*sale_item.unit_price) %> <%= sale_item.product_name %> @@ -351,7 +351,7 @@ - +
Sub Total:<%=sub_total%><%= sub_total %>