mmsc_app/app/controllers/admin/p_stats_controller.rb
2020-07-23 13:09:42 +02:00

56 lines
1.2 KiB
Ruby

# -*- encoding : utf-8 -*-
class Admin::PStatsController < ApplicationController
layout "admin"
before_action :auth_admin
before_action :admin_space
def admin_space
@admin_space = "statistiques"
end
def index
date_regex = /^(0[1-9]|[12][0-9]|3[01])[\/](0[1-9]|1[012])[\/](19|20)\d\d$/i
if params[:start] and params[:start] =~ date_regex
@start = Date.parse(params[:start]).beginning_of_day
elsif !params[:start]
@start = Date.today.beginning_of_year
else
@start = Date.parse("2000-01-01")
end
params[:start]= @start.strftime('%d/%m/%Y')
if params[:stop] and params[:stop] =~ date_regex
@stop = Date.parse(params[:stop]).end_of_day
else
@stop = Date.today.end_of_month
end
params[:stop]= @stop.strftime('%d/%m/%Y')
@p_customer_sheets = PCustomerSheet.where("created_at >= ? and created_at <= ?",@start, @stop).order("id DESC").all
@sans_marges = PSheetLine.where(:p_customer_sheet_id => @p_customer_sheets.ids).where(:externe => false, :stock_done => false, :shiped => true)
@finished = @p_customer_sheets.where(:state => ["livrée","facturée"])
end
end