# File app/controllers/fusioncharts/db_js_controller.rb, line 15
  def default
    headers["content-type"]="text/html";
    @factory_data = [] 
    @js_var_string =""
    index_count = -1
    #Get data from factory masters table
    factory_masters = Fusioncharts::FactoryMaster.find(:all)
      factory_masters.each do |factory_master| 
        total=0.0
        index_count = index_count + 1
        factory_id = factory_master.id
        factory_name = factory_master.name
        # Construct the javascript variable to hold an array.
        @js_var_string =@js_var_string+ "data[" + index_count.to_s + "] = new Array();\n" ; 

        factory_master.factory_output_quantities.each do |factory_output|
                      date_of_production = factory_output.date_pro
                      # Formats the date to dd/mm without leading zeroes
                      formatted_date = format_date_remove_zeroes(date_of_production)
                      quantity_number = factory_output.quantity
                      # Calculate the total quantity for this factory
                      total = total + factory_output.quantity
                      # Append values to the javascript array
                      @js_var_string =@js_var_string+ "\t\t\t\tdata[" + index_count.to_s + "].push(new Array('" + formatted_date + "','" +quantity_number.to_s+"'));\n" 
                    end
        #Formatting the output html
        @js_var_string =@js_var_string+"\t\t\t";
        #Push hash of values into the array          
        @factory_data<<{:factory_index=>index_count,:factory_name=>factory_name,:factory_output=>total}
      end
  end