Last active
March 14, 2016 21:13
-
-
Save nplusp/75c70db642e42eb6a784 to your computer and use it in GitHub Desktop.
InstitutionsController
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class InstitutionsController < ApplicationController | |
load_and_authorize_resource :only => [:destroy,:edit,:new,:create,:update] | |
before_filter :authenticate_user!, :except => [:student_registration, :show, :validate_registration_pin, :result, :admission, :buy_registration_pin,:paygate_callback_failure, :paygate_cancel, :paygate_pending, :paygate_callback_success, :pin_transaction_info_print] | |
before_filter :find_institution, :except => [:show,:index, :new, :create, :semesters_for_institute_type, :start_end_date_for_assessment_period, :courses_for_batch, :paygate_callback_failure, :paygate_cancel, :paygate_pending, :paygate_callback_success, :pin_transaction_info_print] | |
before_filter :add_bread_crumb,:except => [:show] | |
# layout 'print', :only => [:pin_transaction_info_print] | |
# add_breadcrumb "Dashboard", :root_path | |
# layout "schoolit", :only => [:dashboard] | |
#layout 'print', :only => [:pin_transaction_info_print] | |
def add_bread_crumb | |
# add_breadcrumb "Dashboard", dashboard_institution_path(@institution) | |
end | |
def take_attendance | |
add_breadcrumb "Attendances", '#' | |
end | |
def view_attendance_report | |
add_breadcrumb "Attendances", '#' | |
end | |
def student_registration | |
add_breadcrumb "Student Registration", '#' | |
if request.get? | |
@registration = Registration.find params[:registration_id] | |
@has_pin_group = @registration.pin_groups.present? ? true : false | |
end | |
end | |
def registration_fee_details | |
add_breadcrumb "Registration Fee Details", '#' | |
@registration_transaction_records = @institution.registration_transaction_history(params[:registration_id]) | |
@amount = 0.0 | |
@registration_transaction_records.each do |rtr| | |
@amount += rtr.settlement_amount | |
end | |
@registration_transaction_records = @registration_transaction_records.paginate(:page => params[:page], :per_page => 30) | |
respond_to do |format| | |
format.html | |
format.csv { render text: TransactionRecord.to_csv(@registration_transaction_records) } | |
end | |
end | |
def pin_transaction_history | |
if params[:start_date].present? && params[:end_date].present? | |
start_date = params[:start_date] | |
end_date = params[:end_date] | |
@transaction_records = @institution.transaction_records.where("transaction_date BETWEEN ? AND ? ",start_date.to_time.strftime("%Y-%m-%d"), end_date.to_time.strftime("%Y-%m-%d") ).paginate(:page => params[:page], :per_page => 30).order('updated_at DESC') | |
elsif params[:order_number].present? | |
@transaction_records = @institution.transaction_records.where(:order_number => params[:order_number]).paginate(:page => params[:page], :per_page => 30).order('updated_at DESC') | |
end | |
respond_to do |format| | |
format.html | |
format.csv { render text: TransactionRecord.to_csv(@transaction_records) } | |
end | |
end | |
def transaction_history | |
add_breadcrumb "Transaction History", '#' | |
if !request.get? | |
start_date = params[:date][:date_from] | |
end_date = params[:date][:date_to] | |
order_number = params[:order][:order_number] | |
if( order_number.present? || (start_date.present? && end_date.present?)) | |
redirect_to pin_transaction_history_institution_path(@institution, :start_date => start_date, :end_date => end_date, :order_number => order_number) | |
else | |
redirect_to :back, :notice => "Please enter Order number or Dates." | |
end | |
end | |
end | |
def finance_settings | |
add_breadcrumb "Finance Setting", '#' | |
end | |
def paygate_callback_success | |
@pay_gate_config = YAML::load(File.open("#{Rails.root}/config/pay_gate_config.yml"))[Rails.env] | |
@payment = TransactionRecord.find_by_order_number(params[:OrderID]) | |
uri = URI("https://fidelitypaygate.fidelitybankplc.com/cipg/MerchantServices/UpayTransactionStatus.ashx") | |
parameters = {:MERCHANT_ID => "#{@pay_gate_config['merchant_id']}", :ORDER_ID => "#{@payment.order_number}"} | |
uri.query = URI.encode_www_form(parameters) | |
result =open(uri).read | |
result_hash = Hash.from_xml(result) | |
record_payment_details(result_hash) | |
if result_hash["CIPG"]["StatusCode"] == PaymentRecord::PAYMENT_SUCCESS_CODE | |
if @payment.transactionable_type.eql?("PaymentRecord") | |
redirect_to institution_fees_path(@payment.transactionable_type.fee.institution), :notice => "Payment transaction has been #{result_hash['CIPG']['Status']}" | |
elsif @payment.transactionable_type.eql?("PinBuyerInfo") | |
unless @payment.transactionable.pin_id.present? | |
@registration = @payment.transactionable.registration | |
@valid_registration_pin_groups = @registration.valid_registration_pin_groups | |
@online_valid_registration_pin_groups = @valid_registration_pin_groups.where(:pin_available_type => 'Online') | |
@offline_valid_registration_pin_groups = @valid_registration_pin_groups.where(:pin_available_type => 'Offline') | |
@available_pin = nil | |
@online_valid_registration_pin_groups.each do |vpg| | |
if vpg.available_pins.present? | |
@available_pin = vpg.available_pins.first | |
break | |
else | |
next | |
end | |
end | |
if !@available_pin.present? | |
@offline_valid_registration_pin_groups.each do |vpg| | |
if vpg.available_pins.present? | |
@available_pin = vpg.available_pins.first | |
break | |
else | |
next | |
end | |
end | |
end | |
if @available_pin.present? | |
@payment.transactionable.pin_id = @available_pin.id | |
@payment.transactionable.save | |
@available_pin.is_available = false | |
@available_pin.save | |
@available_pin.reload | |
if @available_pin.pin_group.pin_available_type == 'Offline' | |
@message = "Your Order Number is #{@payment.order_number}. Please Print Transaction report to claim you PIN from Institution." | |
else | |
@assigned_pin = @available_pin.number | |
@message = "Your PIN is #{@assigned_pin}. Please keep this PIN secret." | |
end | |
else | |
@message = "No pin available for #{@registration.name}. Your order number is #{@payment.order_number}.Please contact with institution to get your money back if you have paid." | |
end | |
else | |
pin = Pin.find @payment.transactionable.pin_id | |
if(pin.present? && pin.pin_group.pin_available_type == 'Offline') | |
@message = "Your Order Number is #{@payment.order_number}. Please Print Transaction report to claim you PIN from Institution." | |
else | |
@available_pin = Pin.find @payment.transactionable.pin_id | |
@assigned_pin = @available_pin.number | |
@message = "Your PIN is #{ @assigned_pin}. Please keep this PIN secret." | |
end | |
end | |
render 'show_pin' | |
end | |
else | |
@registration = @payment.transactionable.registration | |
@message = "Your payment is not successful. Please buy a new PIN to register for #{@registration.name}." | |
render 'show_pin' | |
end | |
end | |
def paygate_pending | |
@pay_gate_config = YAML::load(File.open("#{Rails.root}/config/pay_gate_config.yml"))[Rails.env] | |
@payment = TransactionRecord.find_by_order_number(params[:OrderID]) | |
uri = URI("https://fidelitypaygate.fidelitybankplc.com/cipg/MerchantServices/UpayTransactionStatus.ashx") | |
parameters = {:MERCHANT_ID => "#{@pay_gate_config['merchant_id']}", :ORDER_ID => "#{@payment.order_number}"} | |
uri.query = URI.encode_www_form(parameters) | |
result =open(uri).read | |
result_hash = Hash.from_xml(result) | |
record_payment_details(result_hash) | |
if @payment.transactionable_type.eql?("PaymentRecord") | |
redirect_to institution_fees_path(@payment.transactionable_type.fee.institution), :notice => "Payment transaction has been #{result_hash['CIPG']['Status']}" | |
elsif @payment.transactionable_type.eql?("PinBuyerInfo") | |
@registration = @payment.transactionable.registration | |
@message = "Your payment is not completed. Please buy a new PIN to register for #{@registration.name}." | |
render 'show_pin' | |
end | |
end | |
def paygate_callback_failure | |
@pay_gate_config = YAML::load(File.open("#{Rails.root}/config/pay_gate_config.yml"))[Rails.env] | |
@payment = TransactionRecord.find_by_order_number(params[:OrderID]) | |
uri = URI("https://fidelitypaygate.fidelitybankplc.com/cipg/MerchantServices/UpayTransactionStatus.ashx") | |
parameters = {:MERCHANT_ID => "#{@pay_gate_config['merchant_id']}", :ORDER_ID => "#{@payment.order_number}"} | |
uri.query = URI.encode_www_form(parameters) | |
result =open(uri).read | |
result_hash = Hash.from_xml(result) | |
record_payment_details(result_hash) | |
if @payment.transactionable_type.eql?("PaymentRecord") | |
redirect_to institution_fees_path(@payment.transactionable_type.fee.institution), :notice => "Payment transaction has been #{result_hash['CIPG']['Status']}" | |
elsif @payment.transactionable_type.eql?("PinBuyerInfo") | |
@registration = @payment.transactionable.registration | |
@message = "Your payment is not successful. Please buy a new PIN to register for #{@registration.name}." | |
render 'show_pin' | |
end | |
end | |
def paygate_cancel | |
@pay_gate_config = YAML::load(File.open("#{Rails.root}/config/pay_gate_config.yml"))[Rails.env] | |
@payment = TransactionRecord.find_by_order_number(params[:OrderID]) | |
uri = URI("https://fidelitypaygate.fidelitybankplc.com/cipg/MerchantServices/UpayTransactionStatus.ashx") | |
parameters = {:MERCHANT_ID => "#{@pay_gate_config['merchant_id']}", :ORDER_ID => "#{@payment.order_number}"} | |
uri.query = URI.encode_www_form(parameters) | |
result =open(uri).read | |
result_hash = Hash.from_xml(result) | |
record_payment_details(result_hash) | |
if @payment.transactionable_type.eql?("PaymentRecord") | |
redirect_to institution_fees_path(@payment.transactionable_type.fee.institution), :notice => "Payment transaction has been #{result_hash['CIPG']['Status']}" | |
elsif @payment.transactionable_type.eql?("PinBuyerInfo") | |
@registration = @payment.transactionable.registration | |
@message = "You payment has been cancelled. Please buy a new PIN to register for #{@registration.name}" | |
render 'show_pin' | |
end | |
end | |
def student_ranks | |
if request.get? | |
render 'student_ranks' | |
else | |
@batch = @institution.batches.find_by_id(params[:batch_id]) | |
if params[:entire_batch] == 'true' | |
if @institution.is_a?(UBE) | |
redirect_to student_ranks_institution_form_class_path(@institution, @batch.program, @batch) | |
else | |
redirect_to student_ranks_institution_program_batch_path(@institution, @batch.program, @batch) | |
end | |
elsif params[:course_id].present? | |
@course = @batch.courses.find_by_id(params[:course_id]) | |
if @institution.is_a?(UBE) | |
redirect_to student_ranks_institution_form_subject_path(@institution, @course.program, @course, :batch_id => params[:batch_id]) | |
else | |
redirect_to student_ranks_institution_program_course_path(@institution, @course.program, @course, :batch_id => params[:batch_id]) | |
end | |
end | |
end | |
end | |
def courses_for_batch | |
courses = Batch.find_by_id(params[:batch_id]).courses | |
respond_to do |format| | |
format.json {render json: courses} | |
end | |
end | |
def show_courses_for_batch | |
add_breadcrumb "Courses", '#' | |
if params[:batch_id].present? | |
@batch = @institution.batches.find params[:batch_id] | |
else | |
@batch = @institution.batches.find params[:institution][:batch_id] | |
end | |
@batch_courses = @batch.courses.includes(:program, :employees).paginate(:page => params[:page]).order('updated_at DESC') | |
end | |
def semesters_for_institute_type | |
semesters = params[:type].constantize.new.semesters | |
respond_to do |format| | |
format.json {render json: semesters} | |
end | |
end | |
def start_end_date_for_assessment_period | |
@institution = Institution.find_by_code params['institution_code'] | |
start_end_date = {'start_date' => @institution.current_assessment_period.start_date, 'end_date' => @institution.current_assessment_period.end_date} | |
respond_to do |format| | |
format.json {render json: start_end_date} | |
end | |
end | |
def exams | |
add_breadcrumb "Exams", '#' | |
if params[:search_result] | |
@exams = @institution.exams.where(:academic_session => @institution.academic_session).includes(:batches).where(:id => params[:search_result]) | |
else | |
@exams = @institution.exams.where(:academic_session => @institution.academic_session).includes(:batches).all | |
end | |
end | |
def create_exam | |
add_breadcrumb "Exams", '#' | |
batch_ids = params[:batches][:batch_ids].reject! {|id| id.empty?} if params[:batches].present? | |
if batch_ids.present? | |
if @institution.create_exam(batch_ids, params[:exam_name], params[:assessment_period], params[:date]) | |
redirect_to exams_institution_path, notice: 'Exams successfully created.' | |
else | |
render 'new_exam' | |
end | |
else | |
render 'new_exam' | |
end | |
end | |
def show_courses | |
if @institution.is_a?(UBE) | |
redirect_to institution_form_subjects_path(@institution, @institution.programs.find(params[:institution][:program_id])) | |
else | |
redirect_to institution_program_courses_path(@institution, @institution.programs.find(params[:institution][:program_id])) | |
end | |
end | |
def show_programs | |
if @institution.is_a?(UBE) | |
redirect_to institution_arm_forms_path(@institution, @institution.schools.find(params[:school_id])) | |
else | |
redirect_to institution_school_programs_path(@institution, @institution.schools.find(params[:school_id])) | |
end | |
end | |
def assign_school_to_program | |
# bread add_bread_crumb | |
add_breadcrumb "School Select", '#' | |
@school = @institution.schools.find(params[:school_id]) | |
@program = @institution.programs.find_by_id(params[:program_id]) | |
if @program && @school | |
@program.school = @school | |
if @program.save | |
redirect_to select_school_institution_path(@institution), notice: "#{@institution.section_name} successfully assigned to the selected #{@institution.sub_section_name}." | |
else | |
redirect_to select_school_institution_path(@institution), alert: "Could not assign #{@institution.section_name} to #{@institution.sub_section_name}. : #{@program.errors.full_messages} " | |
end | |
else | |
redirect_to select_school_institution_path(@institution), alert: "Invalid #{@institution.section_name} or #{@institution.sub_section_name} submitted." | |
end | |
end | |
def assign_program_to_batch | |
add_breadcrumb "Programs", '#' | |
@program = @institution.programs.find(params[:institution][:program_id]) | |
@batch = Batch.find_by_id(params[:institution][:batch_id]) | |
if @program && @batch | |
@batch.program = @program | |
if @batch.save | |
redirect_to select_program_institution_path(@institution, :for => 'batches'), notice: "#{@institution.group_name} successfully assigned to the selected program." | |
else | |
redirect_to select_program_institution_path(@institution, :for => 'batches'), alert: "Could not assign primary #{@institution.sub_section_name} to #{@institution.group_name}. : #{@batch.errors.full_messages} " | |
end | |
else | |
redirect_to select_program_institution_path(@institution, :for => 'batches'), alert: "Invalid #{@institution.sub_section_name} or #{@institution.group_name} submitted." | |
end | |
end | |
def assign_lecturer_to_course | |
add_breadcrumb "Lecturer", '#' | |
if request.get? | |
@batch = @institution.batches.find params[:batch_id] | |
@course = @batch.courses.find params[:course_id] | |
@instructor = @course.has_lecturer?(@batch.id) ? @course.course_lecturer(@batch.id).id : nil | |
else | |
@batch = @institution.batches.find params[:institution][:batch_id] | |
@course = @batch.courses.find params[:institution][:course_id] | |
course_instructor = @course.course_instructors.find_or_initialize_by_batch_id(@batch.id) | |
course_instructor.employee_id = params[:employee_id][:employee_id] | |
course_instructor.institution_id = @institution.id | |
if course_instructor.save | |
redirect_to show_courses_for_batch_institution_path(@institution, :batch_id => @batch.id), :notice => "#{@institution.instructor_name} was successfully assigned" | |
end | |
end | |
end | |
def show_batches | |
if @institution.is_a?(UBE) | |
redirect_to institution_form_classes_path(@institution, @institution.programs.find(params[:institution][:program_id])) | |
else | |
redirect_to institution_program_batches_path(@institution, @institution.programs.find(params[:institution][:program_id])) | |
end | |
end | |
def text_report_record_csv | |
@text_report = TextReport.find(params[:text_report]) | |
@report_for = @text_report.report_for | |
@query_string = @text_report.query_string | |
if @query_string.present? | |
if @report_for == 'student' | |
#@search_result = @institution.students.joins("LEFT OUTER JOIN addresses ON addresses.addressable_id = students.id LEFT OUTER JOIN batches ON batches.id = students.batch_id LEFT OUTER JOIN student_categories ON student_categories.id = students.student_category_id" ).uniq.where(@query_string) | |
@search_result = @institution.students.joins("LEFT OUTER JOIN addresses ON addresses.addressable_id = students.id | |
LEFT OUTER JOIN registrations ON registrations.id = students.registration_id | |
LEFT OUTER JOIN programs ON programs.id = students.program_id | |
LEFT OUTER JOIN batches ON batches.id = students.batch_id | |
LEFT OUTER JOIN student_categories ON student_categories.id = students.student_category_id | |
LEFT OUTER JOIN student_courses ON students.id = student_courses.student_id" ) | |
.uniq.where(@query_string).order('updated_at DESC') | |
else | |
@search_result = @institution.employees.joins("LEFT OUTER JOIN positions ON positions.id = employees.position_id LEFT OUTER JOIN departments ON departments.id = employees.department_id LEFT OUTER JOIN categories ON categories.id = employees.category_id").uniq.where(@query_string) | |
end | |
end | |
respond_to do |format| | |
format.html | |
format.csv { render text: Institution.text_report_csv(@text_report, @search_result) } | |
end | |
end | |
def view_reports | |
@text_reports = @institution.text_reports.paginate(:page => params[:page], :per_page => 30).order('updated_at DESC') | |
@active_tab = params[:active_tab].present? ? params[:active_tab] : "" | |
@program_courses = LazyHighCharts::HighChart.new('graph') do |f| | |
f.title({:text => "Program Report"}) | |
f.zoomType('x') | |
f.xAxis(:categories => @institution.programs.map(&:code)) | |
f.series(:type => 'line', :name => 'Students', :data => @institution.programs.map { |b| b.students.count }) | |
f.series(:type => 'line', :name => 'Courses', :data => @institution.programs.map { |b| b.courses.count }) | |
end | |
@students_distribution = LazyHighCharts::HighChart.new('pie') do |f| | |
f.chart({:defaultSeriesType => "pie", :margin => [50, 200, 60, 170]}) | |
series = { | |
:type => 'pie', | |
:name => 'Students Share', | |
:data => @institution.programs.collect { |p| {:name => p.name, :y => (p.students.count * 100 / @institution.students.count)} }, | |
:tooltip => { | |
:valueSuffix => ' %' | |
}} | |
f.series(series) | |
f.options[:title][:text] = "Students Distribution" | |
f.legend(:layout => 'vertical', :style => {:left => 'auto', :bottom => 'auto', :right => '50px', :top => '100px'}) | |
f.plot_options(:pie => { | |
:allowPointSelect => true, | |
:cursor => "pointer", | |
:dataLabels => { | |
:enabled => true, | |
:color => "black", | |
:style => { | |
:font => "13px Trebuchet MS, Verdana, sans-serif" | |
} | |
} | |
}) | |
end | |
@courses_distribution = LazyHighCharts::HighChart.new('pie') do |f| | |
f.chart({:defaultSeriesType => "pie", :margin => [50, 200, 60, 170]}) | |
series = { | |
:type => 'pie', | |
:name => 'Courses Share', | |
:data => @institution.programs.collect { |p| {:name => p.name, :y => p.courses.count} }, | |
} | |
f.series(series) | |
f.options[:title][:text] = "Courses Distribution" | |
f.legend(:layout => 'vertical', :style => {:left => 'auto', :bottom => 'auto', :right => '50px', :top => '100px'}) | |
f.plot_options(:pie => { | |
:allowPointSelect => true, | |
:cursor => "pointer", | |
:dataLabels => { | |
:enabled => true, | |
:color => "black", | |
:style => { | |
:font => "13px Trebuchet MS, Verdana, sans-serif" | |
} | |
} | |
}) | |
end | |
end | |
def create_text_report | |
if request.get? | |
@query_options = "<option>LIKE</option><option>BEGIN WITH</option><option>EQUAL</option>" | |
@blood_group_options = [ "A+", "A-","B+", "B-", "O+", "O-", "AB+", "AB-" ] | |
@religion_options = ["Buddhism", "Christianity", "Hinduism", "Islam", "Judaism", "Other"] | |
@gender_options = ["Male", "Female"] | |
@marital_status_options = ["Single", "Married", "Divorced"] | |
@default_query_option = "<option> EQUAL</option>" | |
@student_category_options = StudentCategory.all.uniq | |
@student_batch_options = @institution.batches.uniq | |
@employee_position_options = Position.all.uniq | |
@employee_department_options = Department.all.uniq | |
@employee_category_options = Category.all.uniq | |
@text_report = TextReport.new() | |
elsif request.post? | |
if params[:edit_text_report].present? | |
# Edit existing text_report | |
@text_report = TextReport.find params[:edit_text_report][:text_report_id].to_i | |
text_report_name = params[:search_param][:name] | |
text_report_report_for = params[:user] | |
text_report_order_fields = params[:order_fields][:selected_fields] | |
checked_fields = params[:text_report_check].to_json | |
if params[:user] == 'student' | |
text_report_query_options = params[:student_query_options].to_json | |
text_report_query_text = params[:student].to_s #this store all parameters of the critesia to be searched | |
search_result_query = Student.search(params[:student], params[:student_query_options], params[:text_report_check]) | |
elsif params[:user] == 'employee' | |
text_report_query_text = params[:employee] | |
text_report_query_options = params[:employee_query_options].to_json | |
text_report_query_text = params[:employee].to_s #this store all parameters of the critesia to be searched | |
search_result_query = Employee.search(params[:employee], params[:employee_query_options], params[:text_report_check]) | |
end | |
if @text_report.update_attributes(:name => text_report_name, :query_string => search_result_query, :order_fields => text_report_order_fields, :query_options => text_report_query_options, :query_text => text_report_query_text, :report_for => text_report_report_for, :checked_fields => checked_fields) | |
flash[:notice] = "#{@text_report.name} was successfully updated." | |
redirect_to view_reports_institution_path(@institution, :active_tab => "text_report") | |
else | |
render action: "create_text_report" | |
end | |
else | |
#create new text_report | |
text_report = @institution.text_reports.new | |
text_report.name = params[:search_param][:name] | |
text_report.order_fields = params[:order_fields][:selected_fields] | |
text_report.report_for = params[:user] | |
text_report.checked_fields = params[:text_report_check].to_json | |
if params[:user] == 'student' | |
text_report.query_options = params[:student_query_options].to_json | |
text_report.query_text = params[:student].to_s #this store all parameters of the critesia to be searched | |
search_result_query = Student.search(params[:student], params[:student_query_options], params[:text_report_check]) | |
text_report.query_string = search_result_query | |
elsif params[:user] == 'employee' | |
text_report.query_text = params[:employee] | |
text_report.query_options = params[:employee_query_options].to_json | |
text_report.query_text = params[:employee].to_s #this store all parameters of the critesia to be searched | |
search_result_query = Employee.search(params[:employee], params[:employee_query_options], params[:text_report_check]) | |
text_report.query_string = search_result_query | |
end | |
respond_to do |format| | |
if text_report.save | |
format.html { redirect_to view_reports_institution_path(@institution, :active_tab => "text_report"), notice: "#{text_report.name} was successfully created." } | |
else | |
format.html { render action: "create_text_report" } | |
end | |
end | |
end | |
end | |
end | |
def edit_text_report | |
@query_options = "<option>LIKE</option><option>BEGIN WITH</option><option>EQUAL</option>" | |
@blood_group_options = [ "A+", "A-","B+", "B-", "O+", "O-", "AB+", "AB-" ] | |
@religion_options = ["Buddhism", "Christianity", "Hinduism", "Islam", "Judaism", "Other"] | |
@gender_options = ["Male", "Female"] | |
@marital_status_options = ["Single", "Married", "Divorced"] | |
@default_query_option = "<option> EQUAL</option>" | |
@student_category_options = StudentCategory.all.uniq | |
@student_batch_options = @institution.batches.uniq | |
@employee_position_options = Position.all.uniq | |
@employee_department_options = Department.all.uniq | |
@employee_category_options = Category.all.uniq | |
@text_report = TextReport.find(params[:text_report]) | |
query_text_full = @text_report.query_text.slice(1,(@text_report.query_text.length-2)) | |
query_text_filter = "" | |
i = 0 | |
query_text_full_length = query_text_full.length | |
while i != query_text_full_length do | |
if( query_text_full_length >= 0 && query_text_full[i] == '[') | |
while( query_text_full[i] != ']' ) | |
if(query_text_full[i] != ' ') | |
query_text_filter = query_text_filter.concat(query_text_full[i]) | |
end | |
i += 1 | |
end | |
i -= 1 | |
else | |
query_text_filter = query_text_filter.concat(query_text_full[i]) | |
i += 1 | |
end | |
end | |
@checked_box_hash = Hash.new | |
@criteria_text_value = Hash.new | |
query_text_array = query_text_filter.split(", "); | |
query_text_array.each do |i| | |
query_text_input = i.split("=>") | |
field_name = query_text_input[0] | |
field_value = query_text_input[1] | |
field_name = field_name.gsub('"','') | |
@criteria_text_value["#{field_name}"] = field_value.gsub('"', '') | |
checked_box_array = @text_report.checked_fields.split(",") | |
checked_box_array.each do |check| | |
#check = check.gsub("_student","") | |
check = check.gsub("\"","") | |
check = check.gsub("{","") | |
check = check.gsub("}","") | |
check_value = check.split(":") | |
@checked_box_hash[check_value[0]] = check_value[1] | |
end | |
if(field_value[0] == '[' && field_value != '["""]') | |
field_value = field_value.slice(1,(field_value.length-3)) | |
field_value_array = field_value.split(",") | |
if field_name == 'student_state' | |
@student_state_array = [] | |
if @checked_box_hash["state_student"]=="1" | |
field_value_array.each do |field_value| | |
field_value = field_value.gsub("\"","") | |
@student_state_array << field_value.to_i | |
end | |
end | |
end | |
if field_name == 'employee_state' | |
@employee_state_array = [] | |
if @checked_box_hash["state"]=="1" | |
field_value_array.each do |field_value| | |
field_value = field_value.gsub("\"","") | |
@employee_state_array << field_value.to_i | |
end | |
end | |
end | |
if field_name == 'student_lga' | |
@student_lga_array = [] | |
if @checked_box_hash["lga_student"]=="1" | |
field_value_array.each do |field_value| | |
field_value = field_value.gsub("\"","") | |
@student_lga_array << field_value.to_i | |
end | |
end | |
end | |
if field_name == 'employee_lga' | |
@employee_lga_array = [] | |
if @checked_box_hash["lga"]=="1" | |
field_value_array.each do |field_value| | |
field_value = field_value.gsub("\"","") | |
@employee_lga_array << field_value.to_i | |
end | |
end | |
end | |
if field_name == 'student_country' | |
@student_country_array = [] | |
if @checked_box_hash["country_student"]=="1" | |
field_value_array.each do |field_value| | |
field_value = field_value.gsub("\"","") | |
@student_country_array << field_value.to_i | |
end | |
end | |
end | |
if field_name == 'employee_country' | |
@employee_country_array = [] | |
if @checked_box_hash["country"]=="1" | |
field_value_array.each do |field_value| | |
field_value = field_value.gsub("\"","") | |
@employee_country_array << field_value.to_i | |
end | |
end | |
end | |
if(field_name == 'student_gender') | |
@student_gender_array = [] | |
if @checked_box_hash["gender_student"]=="1" | |
field_value_array.each do |field_value| | |
field_value = field_value.gsub("\"","") | |
@student_gender_array << field_value | |
end | |
end | |
end | |
if(field_name == 'employee_gender') | |
@employee_gender_array = [] | |
if @checked_box_hash["gender"]=="1" | |
field_value_array.each do |field_value| | |
field_value = field_value.gsub("\"","") | |
@employee_gender_array << field_value | |
end | |
end | |
end | |
if field_name == 'student_blood_group' | |
@student_blood_group_array = [] | |
if @checked_box_hash["blood_group_student"]=="1" | |
field_value_array.each do |field_value| | |
field_value = field_value.gsub("\"","") | |
@student_blood_group_array << field_value | |
end | |
end | |
end | |
if field_name == 'employee_blood_group' | |
@employee_blood_group_array = [] | |
if @checked_box_hash["blood_group"]=="1" | |
field_value_array.each do |field_value| | |
field_value = field_value.gsub("\"","") | |
@employee_blood_group_array << field_value | |
end | |
end | |
end | |
if field_name == 'student_religion' | |
@student_religion_array = [] | |
if @checked_box_hash["religion_student"]=="1" | |
field_value_array.each do |field_value| | |
field_value = field_value.gsub("\"","") | |
@student_religion_array << field_value | |
end | |
end | |
end | |
if field_name == 'employee_religion' | |
@employee_religion_array = [] | |
if @checked_box_hash["religion"]=="1" | |
field_value_array.each do |field_value| | |
field_value = field_value.gsub("\"","") | |
@employee_religion_array << field_value | |
end | |
end | |
end | |
if field_name == 'student_marital_status' | |
@student_marital_status_array = [] | |
if @checked_box_hash["marital_status_student"]=="1" | |
field_value_array.each do |field_value| | |
field_value = field_value.gsub("\"","") | |
@student_marital_status_array << field_value | |
end | |
end | |
end | |
if field_name == 'employee_marital_status' | |
@employee_marital_status_array = [] | |
if @checked_box_hash["marital_status"]=="1" | |
field_value_array.each do |field_value| | |
field_value = field_value.gsub("\"","") | |
@employee_marital_status_array << field_value | |
end | |
end | |
end | |
if field_name == 'student_student_category' | |
@student_student_category_array = [] | |
if @checked_box_hash["student_category_student"]=="1" | |
field_value_array.each do |field_value| | |
field_value = field_value.gsub("\"","") | |
@student_student_category_array << field_value.to_i | |
end | |
end | |
end | |
if field_name == 'student_subject' | |
@student_subject_array = [] | |
if @checked_box_hash["subject_student"]=="1" | |
field_value_array.each do |field_value| | |
field_value = field_value.gsub("\"","") | |
@student_subject_array << field_value.to_i | |
end | |
end | |
end | |
if field_name == 'student_batch' | |
@student_batch_array = [] | |
if @checked_box_hash["batch_student"]=="1" | |
field_value_array.each do |field_value| | |
field_value = field_value.gsub("\"","") | |
@student_batch_array << field_value.to_i | |
end | |
end | |
end | |
if field_name == 'student_class' | |
@student_class_array = [] | |
if @checked_box_hash["class_student"]=="1" | |
field_value_array.each do |field_value| | |
field_value = field_value.gsub("\"","") | |
@student_class_array << field_value.to_i | |
end | |
end | |
end | |
if field_name == 'student_program' | |
@student_program_array = [] | |
if @checked_box_hash["program_student"] == "1" | |
field_value_array.each do |field_value| | |
field_value = field_value.gsub("\"","") | |
@student_program_array << field_value.to_i | |
end | |
end | |
end | |
if field_name == 'student_registration' | |
@student_registration_array = [] | |
if @checked_box_hash["registration_student"] == "1" | |
field_value_array.each do |field_value| | |
field_value = field_value.gsub("\"","") | |
@student_registration_array << field_value.to_i | |
end | |
end | |
end | |
if field_name == 'employee_department' | |
@employee_department_array = [] | |
if @checked_box_hash["department"]=="1" | |
field_value_array.each do |field_value| | |
field_value = field_value.gsub("\"","") | |
@employee_department_array << field_value.to_i | |
end | |
end | |
end | |
if field_name == 'employee_category' | |
@employee_category_array = [] | |
if @checked_box_hash["category"]=="1" | |
field_value_array.each do |field_value| | |
field_value = field_value.gsub("\"","") | |
@employee_category_array << field_value.to_i | |
end | |
end | |
end | |
if field_name == 'employee_position' | |
@employee_position_array = [] | |
if @checked_box_hash["position"]=="1" | |
field_value_array.each do |field_value| | |
field_value = field_value.gsub("\"","") | |
@employee_position_array << field_value.to_i | |
end | |
end | |
end | |
end | |
end | |
end | |
def show_text_reports | |
if params[:text_report].present? | |
@text_report = TextReport.find(params[:text_report]) | |
@order_fields = @text_report.order_fields.split(' ') | |
@search_result_query = @text_report.query_string | |
if @search_result_query.present? | |
if @text_report.report_for == 'student' | |
# @search_result = @institution.students.joins("LEFT OUTER JOIN addresses ON addresses.addressable_id = students.id | |
# LEFT OUTER JOIN registrations ON registrations.id = students.registration_id | |
# LEFT OUTER JOIN programs ON programs.id = students.program_id | |
# LEFT OUTER JOIN batches ON batches.id = students.batch_id | |
# LEFT OUTER JOIN student_categories ON student_categories.id = students.student_category_id | |
# LEFT OUTER JOIN student_courses ON students.id = student_courses.student_id" ) | |
# .uniq.where(@search_result_query).paginate(:page => params[:page], :per_page => 30).order('updated_at DESC') | |
@search_result = @institution.students.joins("LEFT OUTER JOIN addresses ON addresses.addressable_id = students.id LEFT OUTER JOIN registrations ON registrations.id = students.registration_id LEFT OUTER JOIN programs ON programs.id = students.program_id LEFT OUTER JOIN batches ON batches.id = students.batch_id LEFT OUTER JOIN student_categories ON student_categories.id = students.student_category_id LEFT OUTER JOIN student_courses ON students.id = student_courses.student_id" ).uniq.where(@search_result_query).paginate(:page => params[:page], :per_page => 30).order('updated_at DESC') | |
#@search_result = @institution.students.joins("LEFT OUTER JOIN addresses ON addresses.addressable_id = students.id LEFT OUTER JOIN batches ON batches.id = students.batch_id LEFT OUTER JOIN student_categories ON student_categories.id = students.student_category_id" ).uniq.where(@search_result_query).paginate(:page => params[:page], :per_page => 30).order('updated_at DESC') | |
else | |
@search_result = @institution.employees.joins("LEFT OUTER JOIN positions ON positions.id = employees.position_id LEFT OUTER JOIN departments ON departments.id = employees.department_id LEFT OUTER JOIN categories ON categories.id = employees.category_id").uniq.where(@search_result_query).paginate(:page => params[:page], :per_page => 30).order('updated_at DESC') | |
end | |
end | |
end | |
end | |
def delete_text_report | |
@institution.text_reports.find(params[:text_report]).destroy | |
redirect_to view_reports_institution_path(@institution, :active_tab => "text_report") | |
end | |
def text_report_pdf | |
if params[:text_report].present? | |
@text_report = TextReport.find(params[:text_report]) | |
@order_fields = @text_report.order_fields.split(' ') | |
@search_result_query = @text_report.query_string | |
if @search_result_query.present? | |
if @text_report.report_for == 'student' | |
@search_result = @institution.students.joins("LEFT OUTER JOIN addresses ON addresses.addressable_id = students.id LEFT OUTER JOIN registrations ON registrations.id = students.registration_id LEFT OUTER JOIN programs ON programs.id = students.program_id LEFT OUTER JOIN batches ON batches.id = students.batch_id LEFT OUTER JOIN student_categories ON student_categories.id = students.student_category_id LEFT OUTER JOIN student_courses ON students.id = student_courses.student_id" ).uniq.where(@search_result_query).order('updated_at DESC') | |
else | |
@search_result = @institution.employees.joins("LEFT OUTER JOIN positions ON positions.id = employees.position_id LEFT OUTER JOIN departments ON departments.id = employees.department_id LEFT OUTER JOIN categories ON categories.id = employees.category_id").uniq.where(@search_result_query).order('updated_at DESC') | |
end | |
end | |
render :pdf => "#{@text_report.name}", :layout => 'pdf' | |
end | |
end | |
def graphical_reports | |
@program_courses = LazyHighCharts::HighChart.new('graph') do |f| | |
f.title({:text => "Program Report"}) | |
f.zoomType('x') | |
f.xAxis(:categories => @institution.programs.map(&:code)) | |
f.series(:type => 'line', :name => 'Students', :data => @institution.programs.map { |b| b.students.count }) | |
f.series(:type => 'line', :name => 'Courses', :data => @institution.programs.map { |b| b.courses.count }) | |
end | |
@students_distribution = LazyHighCharts::HighChart.new('pie') do |f| | |
f.chart({:defaultSeriesType => "pie", :margin => [50, 200, 60, 170]}) | |
series = { | |
:type => 'pie', | |
:name => 'Students Share', | |
:data => @institution.programs.collect { |p| {:name => p.name, :y => (p.students.count * 100 / @institution.students.count)} }, | |
:tooltip => { | |
:valueSuffix => ' %' | |
}} | |
f.series(series) | |
f.options[:title][:text] = "Students Distribution" | |
f.legend(:layout => 'vertical', :style => {:left => 'auto', :bottom => 'auto', :right => '50px', :top => '100px'}) | |
f.plot_options(:pie => { | |
:allowPointSelect => true, | |
:cursor => "pointer", | |
:dataLabels => { | |
:enabled => true, | |
:color => "black", | |
:style => { | |
:font => "13px Trebuchet MS, Verdana, sans-serif" | |
} | |
} | |
}) | |
end | |
@courses_distribution = LazyHighCharts::HighChart.new('pie') do |f| | |
f.chart({:defaultSeriesType => "pie", :margin => [50, 200, 60, 170]}) | |
series = { | |
:type => 'pie', | |
:name => 'Courses Share', | |
:data => @institution.programs.collect { |p| {:name => p.name, :y => p.courses.count} }, | |
} | |
f.series(series) | |
f.options[:title][:text] = "Courses Distribution" | |
f.legend(:layout => 'vertical', :style => {:left => 'auto', :bottom => 'auto', :right => '50px', :top => '100px'}) | |
f.plot_options(:pie => { | |
:allowPointSelect => true, | |
:cursor => "pointer", | |
:dataLabels => { | |
:enabled => true, | |
:color => "black", | |
:style => { | |
:font => "13px Trebuchet MS, Verdana, sans-serif" | |
} | |
} | |
}) | |
end | |
end | |
def upload_users | |
@institution = User.upload_csv(@institution.id, params[:file]) | |
respond_to do |format| | |
format.html do | |
if @institution.errors.count > 0 | |
render action: "upload_users_form" | |
else | |
redirect_to institution_users_path(@institution), notice: 'Users successfully uploaded.' | |
end | |
end | |
end | |
end | |
def validate_registration_pin | |
valid_usable_pin = Student.new(registration_id: params[:format], program_id: params[:institution][:program_id], registration_pin: params[:institution][:registration_pin]).validate_registration_pin | |
pin = (Pin.find_by_number params[:institution][:registration_pin]) | |
used_pin = pin.present? && (pin.is_active == false) && (pin.student_id.present?) ? true : false | |
@registration = Registration.find params[:format] | |
if used_pin | |
flash[:notice] = 'Valid Used Pin' | |
student = Student.find pin.student_id | |
session[:student] = student.id | |
if student.program.id != params[:institution][:program_id].to_i | |
program = Program.find params[:institution][:program_id] | |
flash[:notice] = "Student associated to pin: #{pin.number}, is not registered for #{@institution.sub_section_name}: #{program.name}, Please select correct #{@institution.sub_section_name}" | |
redirect_to :back | |
elsif @institution.is_a?(UBE) | |
redirect_to institution_form_student_path( :institution_id => student.institution.id,:program_id => params[:institution][:program_id], :id => student.id ) | |
else | |
redirect_to institution_program_student_path( :institution_id => student.institution.id,:program_id => params[:institution][:program_id], :id => student.id ) | |
end | |
#redirect_to edit_institution_student_path( student.institution, student, :program_id => params[:institution][:program_id], :registration_id => @registration.id ) | |
elsif valid_usable_pin | |
flash[:notice] = 'Valid Usable Pin' | |
redirect_to new_institution_registration_student_path(@institution, @registration, :program_id => params[:institution][:program_id], :registration_pin => params[:institution][:registration_pin] ) | |
else | |
flash[:error] = 'Invalid Pin' | |
redirect_to :back | |
end | |
end | |
def index | |
@institutions = Institution.all | |
respond_to do |format| | |
format.html | |
format.json { render json: @institutions } | |
end | |
end | |
def result | |
respond_to do |format| | |
format.html do | |
if request.get? | |
render 'result' | |
else | |
registration_or_admission_no = params[:institution][:registration_number] | |
student = Student.where('registration_number =? OR admission_no =?', registration_or_admission_no,registration_or_admission_no).first | |
if student | |
result_pin = params[:institution][:pin] | |
if student.program.present? || student.program_offered.present? | |
if student.validate_result_pin result_pin | |
Pin.find_by_number(result_pin).consume student | |
set_student_in_session(student) | |
redirect_to result_institution_student_path(@institution, student) | |
else | |
redirect_to result_institution_path(@institution), alert: 'Invalid Pin' | |
end | |
else | |
redirect_to result_institution_path(@institution), alert: 'You have not been enrolled in any program yet' | |
end | |
else | |
redirect_to result_institution_path(@institution), alert: 'Invalid Exam Number' | |
end | |
end | |
end | |
end | |
end | |
def admission | |
respond_to do |format| | |
format.html do | |
if request.get? | |
render 'admission' | |
else | |
if params[:institution][:returning_student].eql? '1' | |
student = Student.find_by_institution_id_and_registration_number_and_admission_remark(@institution.id, params[:institution][:registration_number], 'Admitted') | |
student ||= Student.find_or_initialize_by_institution_id_and_admission_no_and_admission_remark(@institution.id, params[:institution][:registration_number], 'Admitted') | |
if student.present? | |
student.batch = Batch.find params[:institution][:batch_id] | |
student.returning_student = true | |
student.save(:validate => false) | |
end | |
else | |
student = Student.find_by_registration_number params[:institution][:registration_number] | |
student ||= Student.find_by_admission_no(params[:institution][:registration_number]) | |
end | |
if student && student.admitted? | |
pin = params[:institution][:pin] | |
if student.validate_course_registration_pin pin | |
Pin.find_by_number(pin).consume student | |
student.admit_to_institute | |
set_student_in_session(student) | |
redirect_to admission_institution_student_path(@institution, student) | |
else | |
redirect_to admission_institution_path(@institution), alert: 'Invalid Pin' | |
end | |
else | |
if student.blank? | |
alert = 'Invalid Registration/Admission Number' | |
elsif !student.admitted? | |
alert = 'Sorry!! You cannot proceed. You are not admitted yet.' | |
end | |
redirect_to admission_institution_path(@institution), alert: alert | |
end | |
end | |
end | |
end | |
end | |
def upload_students | |
if request.get? | |
render 'upload_students' | |
else | |
if params[:file].present? | |
url = request.protocol+request.host_with_port | |
@institution = Student.upload_csv(@institution.id, params[:file], url) | |
respond_to do |format| | |
format.html do | |
if @institution.errors.count > 0 | |
render 'upload_students' | |
else | |
redirect_to institution_students_path(@institution), notice: 'Students successfully uploaded.' | |
end | |
end | |
end | |
else | |
redirect_to :back, notice: "Please select a CSV file to upload" | |
end | |
end | |
end | |
def upload_employees | |
if request.get? | |
render 'upload_employees' | |
else | |
if params[:file].present? | |
url = request.protocol+request.host_with_port | |
role_manage = can?(:manage, Role) | |
@institution = Employee.upload_csv(@institution.id, params[:file], url, role_manage) | |
respond_to do |format| | |
format.html do | |
if @institution.errors.count > 0 | |
render 'upload_employees' | |
else | |
redirect_to institution_employees_path(@institution), notice: 'Employee Details successfully uploaded.' | |
end | |
end | |
end | |
else | |
redirect_to :back, notice: "Please select a CSV file to upload" | |
end | |
end | |
end | |
def download_sample_students_csv | |
respond_to do |format| | |
format.csv { render text: sample_students_csv } | |
end | |
end | |
def download_sample_employees_csv | |
respond_to do |format| | |
format.csv { render text: sample_employees_csv } | |
end | |
end | |
def upload_skills | |
if request.get? | |
render 'upload_skills' | |
else | |
if params[:file].present? | |
@institution = Student.upload_skills_csv(@institution.id, params[:file]) | |
respond_to do |format| | |
format.html do | |
if @institution.errors.count > 0 | |
render 'upload_skills' | |
else | |
redirect_to institution_students_path(@institution), notice: 'Skills successfully uploaded.' | |
end | |
end | |
end | |
else | |
redirect_to :back, notice: "Please select a CSV file to upload" | |
end | |
end | |
end | |
def download_sample_skills_csv | |
respond_to do |format| | |
format.csv { render text: sample_skills_csv } | |
end | |
end | |
def dashboard | |
@institution = params[:id].present? ? Institution.find(params[:id]) : Institution.first | |
if current_user.accountable_type == 'Student' | |
@student = Student.find(current_user.accountable_id) | |
render "students/dashboard" | |
return | |
elsif(!current_user.role?(:super_admin) && ( (current_user.roles.map{|r| r.permissions.count}.sum == 0) || ((current_user.roles.map{|r| r.permissions.count}.sum == 1) && (can?(:show, Employee) || can?(:edit, Employee) ) ) || ((current_user.roles.map{|r| r.permissions.count}.sum == 2) && (can?(:show, Employee) && can?(:edit, Employee) ) )) ) | |
@employee = current_user.accountable if current_user.accountable.present? | |
render "employees/dashboard" | |
return | |
end | |
respond_to do |format| | |
format.html | |
format.json { render json: @institution } | |
end | |
end | |
def show | |
add_breadcrumb "institution",'#' | |
if params[:txnref].present? | |
redirect_to create_fee_payments_path and return | |
end | |
@institution = params[:id].present? ? Institution.find(params[:id]) : Institution.first | |
respond_to do |format| | |
format.html | |
format.json { render json: @institution } | |
end | |
end | |
def new | |
@institution = params[:type].constantize.new | |
@academic_session = @institution.academic_session | |
build_address | |
build_assessment_periods | |
respond_to do |format| | |
format.html | |
format.json { render json: @institution } | |
end | |
end | |
def edit | |
@academic_session = params[:academic_session] || @institution.academic_session | |
build_address | |
build_assessment_periods(@academic_session) | |
end | |
def create | |
@institution = params[:institution][:type].constantize.new(params[:institution].except(:assessment_periods_attributes)) | |
respond_to do |format| | |
if @institution.save | |
unless params[:institution][:assessment_periods_attributes].blank? | |
params[:institution][:assessment_periods_attributes].each do |key,value| | |
@institution.assessment_periods.build(value).save | |
end | |
end | |
format.html { redirect_to institutions_path, notice: 'Institution was successfully created.' } | |
format.json { render json: @institution, status: :created, location: @institution } | |
else | |
format.html { render action: 'new' } | |
format.json { render json: @institution.errors, status: :unprocessable_entity } | |
end | |
end | |
end | |
def update | |
respond_to do |format| | |
if @institution.update_attributes(params[:institution]) | |
if params[:institution]['course_registration_on'].to_i == 0 | |
@institution.batches.where('course_registration_on = ?', true).update_all("course_registration_on = 'false'") | |
else | |
@institution.batches.update_all("course_registration_on = '1'") # setting value to true is not working. NO IDEA WHY | |
end | |
format.html { redirect_to institutions_path, notice: 'Institution was successfully updated.' } | |
format.json { head :no_content } | |
else | |
format.html { render action: 'edit' } | |
format.json { render json: @institution.errors, status: :unprocessable_entity } | |
end | |
end | |
end | |
def destroy | |
@institution.destroy | |
respond_to do |format| | |
format.html { redirect_to institutions_url } | |
format.json { head :no_content } | |
end | |
end | |
def registration_income | |
add_breadcrumb "Registration Income", '#' | |
@registrations = @institution.registrations.includes(:pin_groups => :pins).all | |
end | |
def publish_result | |
if request.post? | |
@exam = @institution.exams.find(params[:exam], :include => [:batches => :students]) | |
if(params[:commit] == "Publish Result" || params[:commit] == "Republish Result") | |
if @exam.present? | |
@exam.update_attributes(:is_published => true) | |
## Result publish SMS Send | |
@exam.batches.each do |batch| | |
batch.students.each do |student| | |
## Send SMS to this student | |
result_smses = @exam.other_sms_settings | |
if result_smses.present? && result_smses.last.is_active | |
## Send SMS from here | |
mobile_numbers = [] | |
if student.mobile.present? | |
mob = add_country_code_to_mobile(student.mobile) | |
mobile_numbers << mob | |
end | |
send_sms(mobile_numbers, result_smses.first.sms_text, result_smses.first.sender) | |
end | |
end | |
end | |
end | |
redirect_to exams_institution_path, :notice => "Exam result was successfully published" | |
elsif params[:commit] == "Depublish" | |
@exam.update_attributes(:is_published => false) | |
redirect_to exams_institution_path, :notice => "Exam result was successfully depublished" | |
else | |
redirect_to exams_institution_path | |
end | |
else | |
render 'publish_result' | |
end | |
end | |
def buy_registration_pin | |
@registration = @institution.registrations.find params[:registration_id] | |
@valid_registration_pin_groups = @registration.valid_registration_pin_groups | |
@available_pin = nil | |
@valid_registration_pin_groups.each do |vpg| | |
if vpg.available_pins.present? | |
@available_pin = vpg.available_pins.first | |
break | |
else | |
next | |
end | |
end | |
if request.get? | |
if @available_pin.present? | |
render 'buy_registration_pin' | |
else | |
flash[:error] = "No available PINs for #{@registration.name}." | |
redirect_to :root | |
end | |
else | |
## get information of the buyer and save to db | |
@registration = @institution.registrations.find(params[:registration_id]) | |
if @registration.present? | |
@pin_buyer = @institution.pin_buyer_infos.new() | |
@pin_buyer.first_name = params[:first_name] | |
@pin_buyer.last_name = params[:last_name] | |
@pin_buyer.email = params[:email] | |
@pin_buyer.mobile = params[:mobile] | |
@pin_buyer.registration_id = @registration.id | |
if @pin_buyer.save | |
render 'payment_records/payment_redirect' | |
else | |
render 'buy_registration_pin' | |
end | |
else | |
redirect_to :root, :notice => "Please select a registration to buy PIN" | |
end | |
end | |
end | |
def show_pin | |
end | |
private | |
def sample_students_csv | |
Student.to_csv([],{},@institution) | |
end | |
def sample_employees_csv | |
Employee.to_csv([]) | |
end | |
def sample_skills_csv | |
respond_to do |format| | |
format.csv { render text: sample_skills_csv } | |
end | |
end | |
def build_address | |
@institution.address = Address.new(:addressable_type => "Institution", :addressable_id => @institution.id) if @institution.address.blank? | |
end | |
def build_assessment_periods(academic_session = nil) | |
academic_session ||= @institution.academic_session | |
@institution.semesters.each do |sem| | |
@institution.assessment_periods.find_or_initialize_by_name_and_academic_session(:name => sem, :academic_session => academic_session) | |
end | |
end | |
def find_student | |
@student = @institution.students.find(params[:id]) | |
end | |
def find_institution | |
@institution = Institution.find params[:id] | |
end | |
private | |
def sample_skills_csv | |
CSV.generate do |csv| | |
csv << ["admission_no", "registration_number", "first_name", "middle_name", "surname", "skill_name", "skill_type", "score"] | |
csv << ["ADM123", "", "", "", "", "Reading", "Psychomotor", "A"] | |
csv << ["", "REG123", "", "", "", "Punctuality", "EffectiveArea", "B"] | |
end | |
end | |
def send_sms(mobile_numbers, sms_text, sender) | |
unless mobile_numbers.empty? | |
begin | |
sms = SmsSender.new(sms_text, "1", "0", mobile_numbers,sender) | |
sms.submitMessage(@institution.id) | |
flash[:notice] = "SMS was successfully sent" | |
rescue | |
flash[:notice] = "SMS was not sent. Try again later." | |
end | |
else | |
flash[:notice] = "SMS was not sent. No destination number found." | |
end | |
end | |
def record_payment_details(result_hash) | |
if result_hash.present? | |
status_code = result_hash["CIPG"]["StatusCode"] | |
case status_code | |
when PaymentRecord::PAYMENT_SUCCESS_CODE | |
@payment.status = PaymentRecord::PAYMENT_SUCCESS | |
when PaymentRecord::PAYMENT_FAIL_CODE | |
@payment.status = PaymentRecord::PAYMENT_FAILURE | |
when PaymentRecord::PAYMENT_PENDING_CODE | |
@payment.status = PaymentRecord::PAYMENT_PENDING | |
when PaymentRecord::PAYMENT_CANCELL_CODE | |
@payment.status = PaymentRecord::PAYMENT_CANCELL | |
else | |
@payment.status = PaymentRecord::PAYMENT_FAILURE | |
end | |
@payment.paygate_status = result_hash["CIPG"]["Status"] | |
@payment.paygate_token = result_hash["CIPG"]["TransactionRef"] | |
@payment.paygate_params = result_hash["CIPG"] | |
@payment.amount = result_hash["CIPG"]["Amount"] if result_hash["CIPG"]["Amount"].present? | |
@payment.transaction_date = result_hash["CIPG"]["Date"] if result_hash["CIPG"]["Date"].present? | |
@payment.save | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment