<commit_before>class ManagementController < ApplicationController

  
  include ActionView::Helpers::FormOptionsHelper
  include ActionView::Helpers::NumberHelper
 
  def index
    @deliveries = @current_company.deliveries.find(:all,:conditions=>{:moved_on=>nil})
    @purchases = @current_company.purchase_orders.find(:all, :conditions=>{:moved_on=>nil})
    all_product_stocks = ProductStock.find(:all, :conditions=>{:company_id=>@current_company.id})
    @stock_locations = @current_company.stock_locations
    @product_stocks = []
    for product_stock in all_product_stocks
      @product_stocks << product_stock if product_stock.state == "critic"
    end
    @stock_transfers = @current_company.stock_transfers.find(:all, :conditions=>{:moved_on=>nil}) 
    @payments_to_embank = @current_company.checks_to_embank(-1)
    @embankments_to_lock = @current_company.embankments_to_lock

#     sn = @current_company.subscription_natures.find(:first, :order=>"COALESCE(reduction_rate, 0) DESC")
#     g = Gruff::Line.new(800,200)
#     g.title = sn.name
#     start, finish  = 700, sn.actual_number
#     for x in 0..2
#       months = []
#       f = finish-22*x+1
#       s = f-21
#       for i in s..f
#         months << sn.subscriptions.count(:conditions=>["? between first_number AND last_number", i])
#       end
#       g.data "Du #{s} au #{f}", months
#     end
#     g.write("#{RAILS_ROOT}/public/images/gruff/#{@current_company.id}-test.png")

#     g = Gruff::Line.new(800,200)
#     g.title = sn.name
#     start, finish  = 700, sn.actual_number
#     months = []
#     for i in start..finish
#       months << sn.subscriptions.count(:conditions=>["? between first_number AND last_number", i])
#     end
#     g.data "Du #{start} au #{finish}", months
#     g.write("#{RAILS_ROOT}/public/images/gruff/#{@current_company.id}-test.png")
    

#     g = Gruff::Line.new(800,200)
#     sn = @current_company.subscription_natures.find(:first, :order=>"COALESCE(reduction_rate, 0) DESC")
#     g.title = sn.name
#     for x in 2007..2009
#       months = []
#       12.times do |i|
#         months << sn.subscriptions.count(:conditions=>["started_on BETWEEN ? AND ?", Date.civil(x,i+1,1), Date.civil(x,i+1,1).end_of_month])
#       end
#       g.data x.to_s, months
#     end
#     g.write("#{RAILS_ROOT}/public/images/gruff/#{@current_company.id}-test.png")
  end
  
  
  dyta(:delays, :conditions=>{:company_id=>['@current_company.id']}) do |t|
    t.column :name
    t.column :active
    t.column :expression
    t.column :comment
    t.action :delay, :image=>:show
    t.action :delay_update
    t.action :delay_delete, :method=>:delete, :confirm=>:are_you_sure
  end

  def delays
  end

  def delay
    @delay = find_and_check(:delay, params[:id])
    @title = {:value=>@delay.name}
  end

  manage :delays
  

  #this method allows to create a graphism
  def statistics
    session[:nb_year] = params[:nb_year]||2
    if request.post?
      return unless product = find_and_check(:product, params[:product_id])
      session[:product_id] = product.id

      g = Gruff::Line.new('800x600')
      g.title = product.catalog_name.to_s
      g.title_font_size=20
      g.line_width = 2
      g.dot_radius = 2

      (params[:nb_year].to_i+1).times do |x|
        d = (Date.today - x.year) - 12.month
        sales=[]
        
        12.times do |m|
          sales << @current_company.sale_order_lines.sum(:quantity, :conditions=>['product_id=? and created_on BETWEEN ? AND ?', product.id, d.beginning_of_month, d.end_of_month], :joins=>"INNER JOIN sale_orders as s ON s.id=sale_order_lines.order_id").to_f
          d += 1.month
          g.labels[m] = t('date.abbr_month_names')[d.month]
        end
        g.data('N'+(x>0 ? '-'+x.to_s : '').to_s, sales) # +d.year.to_s
      end

      dir = "#{RAILS_ROOT}/public/images/gruff/#{@current_company.code}"
      @graph = "management-statistics-#{product.code}-#{rand.to_s[2..-1]}.png"
      
      File.makedirs dir unless File.exists? dir
      g.write(dir+"/"+@graph)
<commit_msg>Test on abbr_month_names<commit_after>class ManagementController < ApplicationController

  
  include ActionView::Helpers::FormOptionsHelper
  include ActionView::Helpers::NumberHelper
 
  def index
    @deliveries = @current_company.deliveries.find(:all,:conditions=>{:moved_on=>nil})
    @purchases = @current_company.purchase_orders.find(:all, :conditions=>{:moved_on=>nil})
    all_product_stocks = ProductStock.find(:all, :conditions=>{:company_id=>@current_company.id})
    @stock_locations = @current_company.stock_locations
    @product_stocks = []
    for product_stock in all_product_stocks
      @product_stocks << product_stock if product_stock.state == "critic"
    end
    @stock_transfers = @current_company.stock_transfers.find(:all, :conditions=>{:moved_on=>nil}) 
    @payments_to_embank = @current_company.checks_to_embank(-1)
    @embankments_to_lock = @current_company.embankments_to_lock

#     sn = @current_company.subscription_natures.find(:first, :order=>"COALESCE(reduction_rate, 0) DESC")
#     g = Gruff::Line.new(800,200)
#     g.title = sn.name
#     start, finish  = 700, sn.actual_number
#     for x in 0..2
#       months = []
#       f = finish-22*x+1
#       s = f-21
#       for i in s..f
#         months << sn.subscriptions.count(:conditions=>["? between first_number AND last_number", i])
#       end
#       g.data "Du #{s} au #{f}", months
#     end
#     g.write("#{RAILS_ROOT}/public/images/gruff/#{@current_company.id}-test.png")

#     g = Gruff::Line.new(800,200)
#     g.title = sn.name
#     start, finish  = 700, sn.actual_number
#     months = []
#     for i in start..finish
#       months << sn.subscriptions.count(:conditions=>["? between first_number AND last_number", i])
#     end
#     g.data "Du #{start} au #{finish}", months
#     g.write("#{RAILS_ROOT}/public/images/gruff/#{@current_company.id}-test.png")
    

#     g = Gruff::Line.new(800,200)
#     sn = @current_company.subscription_natures.find(:first, :order=>"COALESCE(reduction_rate, 0) DESC")
#     g.title = sn.name
#     for x in 2007..2009
#       months = []
#       12.times do |i|
#         months << sn.subscriptions.count(:conditions=>["started_on BETWEEN ? AND ?", Date.civil(x,i+1,1), Date.civil(x,i+1,1).end_of_month])
#       end
#       g.data x.to_s, months
#     end
#     g.write("#{RAILS_ROOT}/public/images/gruff/#{@current_company.id}-test.png")
  end
  
  
  dyta(:delays, :conditions=>{:company_id=>['@current_company.id']}) do |t|
    t.column :name
    t.column :active
    t.column :expression
    t.column :comment
    t.action :delay, :image=>:show
    t.action :delay_update
    t.action :delay_delete, :method=>:delete, :confirm=>:are_you_sure
  end

  def delays
  end

  def delay
    @delay = find_and_check(:delay, params[:id])
    @title = {:value=>@delay.name}
  end

  manage :delays
  

  #this method allows to create a graphism
  def statistics
    session[:nb_year] = params[:nb_year]||2
    if request.post?
      return unless product = find_and_check(:product, params[:product_id])
      session[:product_id] = product.id

      g = Gruff::Line.new('800x600')
      g.title = product.catalog_name.to_s
      g.title_font_size=20
      g.line_width = 2
      g.dot_radius = 2

      (params[:nb_year].to_i+1).times do |x|
        d = (Date.today - x.year) - 12.month
        sales=[]
        
        12.times do |m|
          sales << @current_company.sale_order_lines.sum(:quantity, :conditions=>['product_id=? and created_on BETWEEN ? AND ?', product.id, d.beginning_of_month, d.end_of_month], :joins=>"INNER JOIN sale_orders as s ON s.id=sale_order_lines.order_id").to_f
          d += 1.month
          puts d.month.inspect
          puts t('date.abbr_month_names').inspect
          puts ::I18n.t('date.abbr_month_names').inspect
          puts t('date.abbr_month_names')[d.month].inspect
          g.labels[m] = t('date.abbr_month_names')[d.month].to_s
        end
        g.data('N'+(x>0 ? '-'+x.to_s : '').to_s, sales) # +d.year.to_s
      end

      dir = "#{RAILS_ROOT}/public/images/gruff/#{@current_company.code}"
      @graph = "management-statistics-#{product.code}-#{rand.to_s[2..-1]}.png"
      
      File.makedirs dir unless File.exists? dir
      g.write(dir+"/"+@graph)

{'fraction_non_alphanumeric': 0.15604289673454633, 'fraction_numerical': 0.01662850945897096, 'mean_word_length': 3.1961577350859454, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5987915', 'n_tokens_mistral': 3083, 'n_tokens_neox': 2955, 'n_words': 510}