diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..47c6d2439 --- /dev/null +++ b/.gitignore @@ -0,0 +1,25 @@ +.bundle +.rvmrc +nbproject +db/*.sqlite3 +log/*.log* +log/*.lck +tmp/* +.sass-cache/ +config/database.yml +.DS_Store +public/assets/sources_manifest.yml +public/assets/ +public/system/ +public/form_templates/ +public/javascript/cache +dump.rdb +.idea/ +*.swp +*.orig +*_clean.csv +*.log +*.sql.backup +.~lock* +coverage/ + diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 000000000..c82eec79e --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +1.9.3-p448 diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 000000000..57476cae3 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,18 @@ +before_script: + - sh -e /etc/init.d/xvfb start + - export DISPLAY=:99.0 +bundler_args: --without development production --quiet +branches: + only: + - master +script: + - RAILS_ENV=test bundle exec rake db:create db:migrate --trace + - bundle exec rake spec +before_script: + - gem update --system 1.8.25 + - cp config/database.travis.yml config/database.yml +addons: + code_climate: + repo_token: 025bcf02e070a831bd107a2cd72bb110c6086ee114560a8cfcb128d0ccc7bae0 +rvm: + - 1.9.3 diff --git a/Gemfile b/Gemfile new file mode 100644 index 000000000..d10f19cbe --- /dev/null +++ b/Gemfile @@ -0,0 +1,36 @@ +source 'http://rubygems.org' + +gem 'rails', '2.3.18' +gem 'i18n' + +gem 'delayed_job', '2.0.8' +gem 'mysql' +gem 'in_place_editing' +gem 'nokogiri' + +group :development, :test do + gem 'debugger' + gem 'rspec-rails', '1.3.4' +end + +group :test do + gem 'codeclimate-test-reporter', :require => nil + gem 'factory_girl' + gem 'test-unit', '1.2.3' + gem 'shoulda-matchers' + gem 'database_cleaner' + gem 'webrat' + gem 'simplecov', :require => false + gem 'mocha', '0.12.8' + gem 'rspec-multi-mock', '0.1.0' +end + +gem 'will_paginate', '2.3.16' +gem 'paperclip', '2.7.5' +gem 'wicked_pdf', '0.7.0' +gem 'xss_terminate' +gem 'translator', '1.0.0' +gem 'declarative_authorization' +gem 'searchlogic', '2.5.8' +gem 'calendar_date_select', '1.16.1' +gem 'has_and_belongs_to_many_with_deferred_save', '0.2.0' diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 000000000..d122ab4c6 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,123 @@ +GEM + remote: http://rubygems.org/ + specs: + actionmailer (2.3.18) + actionpack (= 2.3.18) + actionpack (2.3.18) + activesupport (= 2.3.18) + rack (~> 1.1.0) + activerecord (2.3.18) + activesupport (= 2.3.18) + activeresource (2.3.18) + activesupport (= 2.3.18) + activesupport (2.3.18) + calendar_date_select (1.16.1) + chardet (0.9.0) + cocaine (0.3.2) + codeclimate-test-reporter (0.0.9) + simplecov (>= 0.7.1, < 1.0.0) + columnize (0.3.6) + daemons (1.0.10) + database_cleaner (1.1.1) + debugger (1.6.1) + columnize (>= 0.3.1) + debugger-linecache (~> 1.2.0) + debugger-ruby_core_source (~> 1.2.3) + debugger-linecache (1.2.0) + debugger-ruby_core_source (1.2.3) + declarative_authorization (0.5.7) + delayed_job (2.0.8) + activesupport (~> 2.0) + daemons (= 1.0.10) + factory_girl (2.6.4) + activesupport (>= 2.3.9) + has_and_belongs_to_many_with_deferred_save (0.2.0) + activerecord + hoe (3.7.1) + rake (>= 0.8, < 11.0) + html5 (0.10.0) + chardet (>= 0.9.0) + hoe (>= 1.2.0) + i18n (0.6.5) + in_place_editing (1.2.0) + metaclass (0.0.1) + mime-types (1.25) + mini_portile (0.5.1) + mocha (0.12.8) + metaclass (~> 0.0.1) + multi_json (1.8.0) + mysql (2.9.1) + nokogiri (1.6.0) + mini_portile (~> 0.5.0) + paperclip (2.7.5) + activerecord (>= 2.3.0) + activesupport (>= 2.3.2) + cocaine (~> 0.3.0) + mime-types + rack (1.1.6) + rack-test (0.6.2) + rack (>= 1.0) + rails (2.3.18) + actionmailer (= 2.3.18) + actionpack (= 2.3.18) + activerecord (= 2.3.18) + activeresource (= 2.3.18) + activesupport (= 2.3.18) + rake (>= 0.8.3) + rake (10.1.0) + rspec (1.3.1) + rspec-multi-mock (0.1.0) + rspec (= 1.3.1) + rspec-rails (1.3.4) + rack (>= 1.0.0) + rspec (~> 1.3.1) + searchlogic (2.5.8) + activerecord (~> 2.3.12) + activerecord (~> 2.3.12) + shoulda-matchers (1.0.0) + simplecov (0.7.1) + multi_json (~> 1.0) + simplecov-html (~> 0.7.1) + simplecov-html (0.7.1) + test-unit (1.2.3) + hoe (>= 1.5.1) + translator (1.0.0) + webrat (0.7.3) + nokogiri (>= 1.2.0) + rack (>= 1.0) + rack-test (>= 0.5.3) + wicked_pdf (0.7.0) + will_paginate (2.3.16) + xss_terminate (0.22) + html5 (>= 0.10.0) + +PLATFORMS + ruby + +DEPENDENCIES + calendar_date_select (= 1.16.1) + codeclimate-test-reporter + database_cleaner + debugger + declarative_authorization + delayed_job (= 2.0.8) + factory_girl + has_and_belongs_to_many_with_deferred_save (= 0.2.0) + i18n + in_place_editing + mocha (= 0.12.8) + mysql + nokogiri + paperclip (= 2.7.5) + rails (= 2.3.18) + rspec-multi-mock (= 0.1.0) + rspec-rails (= 1.3.4) + searchlogic (= 2.5.8) + shoulda-matchers + simplecov + test-unit (= 1.2.3) + translator (= 1.0.0) + webrat + wicked_pdf (= 0.7.0) + will_paginate (= 2.3.16) + xss_terminate diff --git a/README.markdown b/README.markdown index 71d434b66..4638853fd 100755 --- a/README.markdown +++ b/README.markdown @@ -1,24 +1,115 @@ -#Fedena : Open source school management system +# Fedena LTS: Open source school management system -Project Fedena is the open source school management system based on Ruby on Rails. It is developed by a team of developers at Foradian Technologies. The project was made open source by Foradian, and is now maintained by the open source community. Fedena is the ideal solution for schools and campuses that want an easy means to manage all campus records. +## The project is now DEAD. We failed to attract enough interests, plus there is strong competition from the official Fedena with their updated codebase. -The Project Fedena website http://www.projectfedena.org/ is the home to the developer community behind Fedena project. There you can find forums and bug tracker for Fedena. +[![Build Status](https://travis-ci.org/ruby-journal/fedena_lts.png?branch=master)](https://travis-ci.org/ruby-journal/fedena_lts) -#Demo +Project Fedena is the open source school management system based on Ruby on Rails. It is developed by a team of developers at Foradian Technologies. +The project was made open source by Foradian, and is now maintained by the open source community. Fedena is the ideal solution for schools and campuses that want an easy means to manage all campus records. + +The Project Fedena website http://www.projectfedena.org/ is the home to the developer community behind Fedena project. + +# What is Fedena LTS edition? + +Fedena LTS is a fork of the fedena project, that provides: + +* Security fixes for Rails 2.3.x branch +* Bundler support +* TravisCI support +* More test coverage +* Refactor and cleanup codebase +* Extended support for other DBs such as PostgreSQL +* Support Ruby 1.9.x +* Cease support for Ruby 1.8.x + +The main reasons behind the decision to fork are: + +* Main project repository is stagnated - no development nor patches since the early of 2013 +* Lack of effective communication with fedena team +* Lack of test coverages, which makes fedena prone to regressions for modification and updation + +# Is Fedora LTS free? + +Yes, it is. All fixes will be available to commercial support customers first. We'll release these +patches for public after 3 months. We hope for your understanding as we try to cover the costs +to support this legacy product. + +# Commercial Support + +There are many customers who are planning to move away from fedena platform due to lack of update from the official project. Yet some could +not afford other alternative solutions due to costs and other reasons. For this very reason, we'd like to announce commercial support plan for Fedena/Fedena Pro. + +With the commercial support plan, you would get: + +* Latest security patches and fixes to current Fedena 2.3 codebase +* Customer Email support (with 24 hours latest reply) +* Customer Chat support +* More test coverages for fedena codebase, increase production quality and Rails 4 upgrade ready (see Project Athena) +* 3 days development fixes + +For more information, please contact our support at: trung.le@ruby-journal.com + +# Project Athena + +Your investment to Fedena is very important to your business. We understand and believe that Fedena should not impede the growth of your business. Sadly the clunky and obsolete Fedena makes it hard us for us, developers and you to achieve that goal. Hence, we decided to take a bold decision by starting a new project from scratch. Learning from your valuable feedbacks and combining with the state of the art Lotus Framework, we are ambitious to bring you the best product of the industry. + +What would you expect with this new product? + +* Lotus Framework based +* 1st class microservice architecture +* Ruby 2.0.0 or newer support +* Support PostgresSQL, MySQL, Redis and MongoDB +* ~300% performance increase +* Cloud Deployment - Heroku, EngineYard, OpenShift +* New plugin engine infrastructure +* Extensive customer product support for upgrade from Fedena 2.3 or Fedena LTS +* Responsive CSS - support mobile, tablet and desktop + +Previously, we aimed to rewrite in Rails 4. After 6 months in development, we failed to achieve the objectives due to financial problems and technical shortages. It was a tough time for our company and we apologize to our customers who have been patiently waiting for the good news. In July 2014, we successfully secured a first round funding from a private investor, enough for us to restart the project. This time we'll take a new approach by moving away from Rails 4 and toward Lotus Framework. We truly believe the simplicty yet superiosity over Rails would be the game changer for your business. For more details, please do not hesitate to contact us. + +# Demo A demo website for Fedena has been set up at demo.projectfedena.org. You can log in with following usernames and passwords: * As admin -- username - admin, password - admin123 * As student -- username - 1, password - 1123 * As employee -- username - E1, password - E1123 -#License +On localhost, after running ```rake db:seed```, you can login as admin with: + + * username - Admin, password - password + +# License +Fedena LTS is released under the Apache License 2.0. Fedena is released under the Apache License 2.0. -#Installation +# Installation + +RubyGems has deprecated `Gem::SourceIndex#search` after 2011-11-01. Thus Slimgems should be installed instead to maintain compatability. + +``` +gem install slimgems +``` + +Bootstraping with: + +``` +bundle install +bundle exec rake db:create db:migrate +bundle exec rake db:seed +./scipt/server +``` + +# Test + +``` +RAILS_ENV=test bundle exec rake db:create db:migrate +bundle exec rake spec +``` -Visit http://projectfedena.org/install for detailed installation instruction. +to run individual test, do: -#Community Support: +``` +./script/spec spec/models/abc_spec.rb +``` -Visit www.projectfedena.org for community support. diff --git a/Rakefile b/Rakefile index 3bb0e8592..4711a9575 100755 --- a/Rakefile +++ b/Rakefile @@ -5,6 +5,4 @@ require(File.join(File.dirname(__FILE__), 'config', 'boot')) require 'rake' require 'rake/testtask' -require 'rake/rdoctask' - require 'tasks/rails' diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 697896a30..9a8458fda 100755 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,27 +1,26 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class ApplicationController < ActionController::Base helper :all helper_method :can_access_request? protect_from_forgery # :secret => '434571160a81b5595319c859d32060c1' filter_parameter_logging :password - + before_filter { |c| Authorization.current_user = c.current_user } before_filter :message_user before_filter :set_user_language @@ -36,7 +35,7 @@ def login_check unless (controller_name == "user") and ["first_login_change_password","login","logout","forgot_password"].include? action_name user = User.active.find(session[:user_id]) setting = Configuration.get_config_value('FirstTimeLoginEnable') - if setting == "1" and user.is_first_login != false + if setting == "1" and user.is_first_login? flash[:notice] = "#{t('first_login_attempt')}" redirect_to :controller => "user",:action => "first_login_change_password",:id => user.username end @@ -97,7 +96,7 @@ def set_language end end - + def only_assigned_employee_allowed @privilege = @current_user.privileges.map{|p| p.name} if @current_user.employee? @@ -134,7 +133,7 @@ def block_unauthorised_entry end end end - + def initialize @title = FedenaSetting.company_details[:company_name] end @@ -147,7 +146,7 @@ def current_user User.active.find(session[:user_id]) unless session[:user_id].nil? end - + def find_finance_managers Privilege.find_by_name('FinanceControl').users end @@ -156,7 +155,7 @@ def permission_denied flash[:notice] = "#{t('flash_msg4')}" redirect_to :controller => 'user', :action => 'dashboard' end - + protected def login_required unless session[:user_id] @@ -179,7 +178,7 @@ def configuration_settings_for_hr end end - + def configuration_settings_for_finance finance = Configuration.find_by_config_value("Finance") @@ -213,7 +212,7 @@ def protect_user_data end end end - + def limit_employee_profile_access unless @current_user.employee unless params[:id] == @current_user.employee_record.id @@ -229,7 +228,7 @@ def limit_employee_profile_access def protect_other_employee_data if current_user.employee? employee = current_user.employee_record - # pri = Privilege.find(:all,:select => "privilege_id",:conditions=> 'privileges_users.user_id = ' + current_user.id.to_s, :joins =>'INNER JOIN `privileges_users` ON `privileges`.id = `privileges_users`.privilege_id' ) + # pri = Privilege.find(:all,:select => "privilege_id",:conditions=> 'privileges_users.user_id = ' + current_user.id.to_s, :joins =>'INNER JOIN privileges_users ON privileges.id = privileges_users.privilege_id' ) # privilege =[] # pri.each do |p| # privilege.push p.privilege_id @@ -343,12 +342,13 @@ def can_access_request? (action,controller) end private + def set_user_language lan = Configuration.find_by_config_key("Locale") I18n.default_locale = :en Translator.fallback(true) if session[:language].nil? - I18n.locale = lan.config_value + I18n.locale = lan.config_value if lan else I18n.locale = session[:language] end diff --git a/app/controllers/archived_employee_controller.rb b/app/controllers/archived_employee_controller.rb index dfcbbbb66..d93d6bffa 100755 --- a/app/controllers/archived_employee_controller.rb +++ b/app/controllers/archived_employee_controller.rb @@ -1,33 +1,32 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class ArchivedEmployeeController < ApplicationController before_filter :login_required,:configuration_settings_for_hr filter_access_to :all # prawnto :prawn => {:left_margin => 25, :right_margin => 25} - + def profile @current_user = current_user @employee = ArchivedEmployee.find(params[:id]) - @new_reminder_count = Reminder.find_all_by_recipient(@current_user.id, :conditions=>"is_read = false") + @new_reminder_count = Reminder.find_all_by_recipient(@current_user.id, :conditions=>{:is_read => false}) @gender = "Male" @gender = "Female" if @employee.gender == "f" @status = "Active" @@ -121,11 +120,11 @@ def profile_pdf @office_country = Country.find(@employee.office_country_id).name unless @employee.office_country_id.nil? @bank_details = ArchivedEmployeeBankDetail.find_all_by_employee_id(@employee.id) @additional_details = ArchivedEmployeeAdditionalDetail.find_all_by_employee_id(@employee.id) - + render :pdf => 'profile_pdf' - - + + end def show diff --git a/app/controllers/archived_student_controller.rb b/app/controllers/archived_student_controller.rb index 65e573a4f..7a2447246 100755 --- a/app/controllers/archived_student_controller.rb +++ b/app/controllers/archived_student_controller.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class ArchivedStudentController < ApplicationController filter_access_to :all before_filter :login_required @@ -23,7 +22,7 @@ class ArchivedStudentController < ApplicationController def profile @current_user = current_user @archived_student = ArchivedStudent.find(params[:id]) - @additional_fields = StudentAdditionalField.all(:conditions=>"status = true") + @additional_fields = StudentAdditionalField.all(:conditions=>{:status => true}) end def show @@ -36,7 +35,7 @@ def show def guardians @archived_student = ArchivedStudent.find(params[:id]) - @parents = ArchivedGuardian.find(:all, :conditions=>"ward_id = #{@archived_student.id}") + @parents = ArchivedGuardian.find(:all, :conditions=>{:ward_id => @archived_student.id}) end @@ -51,7 +50,7 @@ def reports @student= ArchivedStudent.find params[:id] @batch = @student.batch @grouped_exams = GroupedExam.find_all_by_batch_id(@batch.id) - @normal_subjects = Subject.find_all_by_batch_id(@batch.id,:conditions=>"no_exams = false AND elective_group_id IS NULL AND is_deleted = false") + @normal_subjects = Subject.find_all_by_batch_id(@batch.id,:conditions=> {:no_exams => false, :elective_group_id => nil, :is_deleted => false}) @student_electives = StudentsSubject.find_all_by_student_id(@student.former_id,:conditions=>{:batch_id=>@batch.id}) @elective_subjects = [] @student_electives.each do |e| @@ -59,7 +58,7 @@ def reports end @subjects = @normal_subjects+@elective_subjects @exam_groups = @batch.exam_groups - @exam_groups.reject!{|e| e.result_published==false} + @exam_groups.reject!{|e| !e.result_published? } @old_batches = @student.all_batches end @@ -88,8 +87,8 @@ def academic_report else @exam_groups = ExamGroup.find_all_by_batch_id(@batch.id) end - general_subjects = Subject.find_all_by_batch_id(@batch.id, :conditions=>"elective_group_id IS NULL and is_deleted=false") - student_electives = StudentsSubject.find_all_by_student_id(@student.id,:conditions=>"batch_id = #{@batch.id}") + general_subjects = Subject.find_all_by_batch_id(@batch.id, :conditions=>{:elective_group_id=>nil, :is_deleted=>false}) + student_electives = StudentsSubject.find_all_by_student_id(@student.id,:conditions=> {:batch_id=>@batch.id}) elective_subjects = [] student_electives.each do |elect| elective_subjects.push Subject.find(elect.subject_id) @@ -101,9 +100,9 @@ def student_report @config = Configuration.find_by_config_key('StudentAttendanceType') @student = ArchivedStudent.find(params[:id]) @batch = Batch.find(params[:year]) - @start_date = @batch.start_date.to_date - if @student.created_at.to_date > @batch.end_date.to_date - @end_date = @batch.end_date.to_date + @start_date = @batch.started_on + if @student.created_at.to_date > @batch.ended_on + @end_date = @batch.ended_on else @end_date = @student.created_at.to_date end @@ -134,8 +133,8 @@ def generated_report @exam_group = ExamGroup.find(params[:exam_report][:exam_group_id]) @batch = @exam_group.batch @student = @batch.students.first - general_subjects = Subject.find_all_by_batch_id(@batch.id, :conditions=>"elective_group_id IS NULL") - student_electives = StudentsSubject.find_all_by_student_id(@student.id,:conditions=>"batch_id = #{@batch.id}") + general_subjects = Subject.find_all_by_batch_id(@batch.id, :conditions=>{:elective_group_id => nil}) + student_electives = StudentsSubject.find_all_by_student_id(@student.id,:conditions=>{:batch_id => @batch.id}) elective_subjects = [] student_electives.each do |elect| elective_subjects.push Subject.find(elect.subject_id) @@ -153,8 +152,8 @@ def generated_report @student = ArchivedStudent.find(params[:student]) @student.id=@student.former_id @batch = @student.batch - general_subjects = Subject.find_all_by_batch_id(@student.batch.id, :conditions=>"elective_group_id IS NULL") - student_electives = StudentsSubject.find_all_by_student_id(@student.former_id,:conditions=>"batch_id = #{@student.batch.id}") + general_subjects = Subject.find_all_by_batch_id(@student.batch.id, :conditions=>{:elective_group_id => nil}) + student_electives = StudentsSubject.find_all_by_student_id(@student.former_id,:conditions=>{:batch_id => @student.batch.id}) elective_subjects = [] student_electives.each do |elect| elective_subjects.push Subject.find(elect.subject_id) @@ -176,8 +175,8 @@ def generated_report_pdf @student = ArchivedStudent.find_by_former_id(params[:student]) @student.id = @student.former_id @batch = @student.batch - general_subjects = Subject.find_all_by_batch_id(@student.batch.id, :conditions=>"elective_group_id IS NULL") - student_electives = StudentsSubject.find_all_by_student_id(@student.id,:conditions=>"batch_id = #{@student.batch.id}") + general_subjects = Subject.find_all_by_batch_id(@student.batch.id, :conditions=>{:elective_group_id => nil}) + student_electives = StudentsSubject.find_all_by_student_id(@student.id,:conditions=>{:batch_id => @student.batch.id}) elective_subjects = [] student_electives.each do |elect| elective_subjects.push Subject.find(elect.subject_id) @@ -189,7 +188,7 @@ def generated_report_pdf @exams.push exam unless exam.nil? end render :pdf => 'generated_report_pdf' - + # respond_to do |format| # format.pdf { render :layout => false } # end @@ -232,8 +231,8 @@ def generated_report4 @exam_groups = ExamGroup.find_all_by_batch_id(@batch.id) @exam_groups.reject!{|e| e.result_published==false} end - general_subjects = Subject.find_all_by_batch_id(@student.batch.id, :conditions=>"elective_group_id IS NULL AND is_deleted=false") - student_electives = StudentsSubject.find_all_by_student_id(@student.former_id,:conditions=>"batch_id = #{@student.batch.id}") + general_subjects = Subject.find_all_by_batch_id(@student.batch.id, :conditions=>{:elective_group_id => nil, :is_deleted => false}) + student_electives = StudentsSubject.find_all_by_student_id(@student.former_id,:conditions=>{:batch_id => @student.batch.id}) elective_subjects = [] student_electives.each do |elect| elective_subjects.push Subject.find(elect.subject_id) @@ -243,7 +242,7 @@ def generated_report4 end - + def generated_report4_pdf #grouped-exam-report-for-batch @@ -261,8 +260,8 @@ def generated_report4_pdf @exam_groups = ExamGroup.find_all_by_batch_id(@batch.id) @exam_groups.reject!{|e| e.result_published==false} end - general_subjects = Subject.find_all_by_batch_id(@student.batch.id, :conditions=>"elective_group_id IS NULL") - student_electives = StudentsSubject.find_all_by_student_id(@student.id,:conditions=>"batch_id = #{@student.batch.id}") + general_subjects = Subject.find_all_by_batch_id(@student.batch.id, :conditions=>{:elective_group_id => nil}) + student_electives = StudentsSubject.find_all_by_student_id(@student.id,:conditions=>{:batch_id => @student.batch.id}) elective_subjects = [] student_electives.each do |elect| elective_subjects.push Subject.find(elect.subject_id) @@ -285,7 +284,7 @@ def graph_for_generated_report student.id=student.former_id examgroup = ExamGroup.find(params[:examgroup]) batch = student.batch - general_subjects = Subject.find_all_by_batch_id(batch.id, :conditions=>"elective_group_id IS NULL") + general_subjects = Subject.find_all_by_batch_id(batch.id, :conditions=>{:elective_group_id => nil}) student_electives = StudentsSubject.find_all_by_student_id(student.id,:conditions=>"batch_id = #{batch.id}") elective_subjects = [] student_electives.each do |elect| @@ -307,7 +306,7 @@ def graph_for_generated_report end end - bargraph = BarFilled.new() + bargraph = BarFilled.new bargraph.width = 1; bargraph.colour = '#bb0000'; bargraph.dot_size = 5; @@ -408,7 +407,7 @@ def graph_for_previous_years_marks_overview student.all_batches.each do |b| x_labels << b.name - exam = ArchivedExamScore.new() + exam = ArchivedExamScore.new data << exam.batch_wise_aggregate(student,b) end diff --git a/app/controllers/assessment_scores_controller.rb b/app/controllers/assessment_scores_controller.rb index 8a1470444..ead2e604f 100644 --- a/app/controllers/assessment_scores_controller.rb +++ b/app/controllers/assessment_scores_controller.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class AssessmentScoresController < ApplicationController before_filter :login_required filter_access_to :all diff --git a/app/controllers/assessment_tools_controller.rb b/app/controllers/assessment_tools_controller.rb index c31b7970b..65ece4bf2 100644 --- a/app/controllers/assessment_tools_controller.rb +++ b/app/controllers/assessment_tools_controller.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class AssessmentToolsController < ApplicationController before_filter :login_required filter_access_to :all diff --git a/app/controllers/attendance_reports_controller.rb b/app/controllers/attendance_reports_controller.rb index e5c831fab..306293e6d 100755 --- a/app/controllers/attendance_reports_controller.rb +++ b/app/controllers/attendance_reports_controller.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class AttendanceReportsController < ApplicationController before_filter :login_required filter_access_to :all @@ -42,7 +41,7 @@ def subject if @current_user.employee? and @allow_access ==true role_symb = @current_user.role_symbols if role_symb.include?(:student_attendance_view) or role_symb.include?(:student_attendance_register) - @subjects= Subject.find(:all,:conditions=>"batch_id = '#{@batch.id}' ") + @subjects= Subject.find(:all,:conditions=>{:batch_id => @batch.id}) else if @batch.employee_id.to_i==@current_user.employee_record.id @subjects= @batch.subjects @@ -51,7 +50,7 @@ def subject end end else - @subjects = Subject.find_all_by_batch_id(@batch.id,:conditions=>'is_deleted = false') + @subjects = Subject.find_all_by_batch_id(@batch.id,:conditions=>{:is_deleted => false}) end render :update do |page| @@ -93,7 +92,7 @@ def mode end def show @batch = Batch.find params[:batch_id] - @start_date = @batch.start_date.to_date + @start_date = @batch.started_on @end_date = @local_tzone_time.to_date @leaves=Hash.new { |h, k| h[k] = Hash.new(&h.default_proc) } @mode = params[:mode] @@ -232,7 +231,7 @@ def report @date = '01-'+@month+'-'+@year @start_date = @date.to_date @today = @local_tzone_time.to_date - if (@start_date<@batch.start_date.to_date.beginning_of_month || @start_date>@batch.end_date.to_date || @start_date>=@today.next_month.beginning_of_month) + if @start_date<@batch.started_on.beginning_of_month || @start_date>@batch.ended_on || @start_date>=@today.next_month.beginning_of_month render :update do |page| page.replace_html 'report', :text => t('no_reports') end @@ -305,7 +304,7 @@ def student_details @report = Attendance.find(:all,:conditions=>{:student_id=>@student.id,:batch_id=>@batch.id}) else @report = SubjectLeave.find(:all,:conditions=>{:student_id=>@student.id,:batch_id=>@batch.id}) - + end end @@ -469,7 +468,7 @@ def report_pdf @report = '' end render :pdf => 'report_pdf' - + # render :layout=>'pdf' # respond_to do |format| # format.pdf { render :layout => false } @@ -541,7 +540,7 @@ def filter_report_pdf end end render :pdf => 'filter_report_pdf' - + # respond_to do |format| diff --git a/app/controllers/attendances_controller.rb b/app/controllers/attendances_controller.rb index 1141a25e0..80688eae7 100755 --- a/app/controllers/attendances_controller.rb +++ b/app/controllers/attendances_controller.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class AttendancesController < ApplicationController before_filter :login_required filter_access_to :all @@ -170,7 +169,7 @@ def daily_register # format.js { render :action => 'show' } end end - + def new @config = Configuration.find_by_config_key('StudentAttendanceType') if @config.config_value=='Daily' @@ -198,19 +197,19 @@ def create # @absentee.subject_id=@tte.subject_id @absentee.class_timing_id=@tte.class_timing_id @absentee.batch_id = @student.batch_id - + else @student = Student.find(params[:attendance][:student_id]) @absentee = Attendance.new(params[:attendance]) end respond_to do |format| if @absentee.save - sms_setting = SmsSetting.new() + sms_setting = SmsSetting.new message = "" if sms_setting.application_sms_active and @student.is_sms_enabled and sms_setting.attendance_sms_active recipients = [] unless @config.config_value=="SubjectWise" - if @absentee.is_full_day + if @absentee.full_day? message = "#{@student.first_name} #{@student.last_name} #{t('flash_msg7')} #{@absentee.month_date}" elsif @absentee.forenoon == true and @absentee.afternoon == false message = "#{@student.first_name} #{@student.last_name} #{t('flash_msg7')} (forenoon) #{@absentee.month_date}" diff --git a/app/controllers/batch_transfers_controller.rb b/app/controllers/batch_transfers_controller.rb index 155a191ab..862ec4f56 100755 --- a/app/controllers/batch_transfers_controller.rb +++ b/app/controllers/batch_transfers_controller.rb @@ -1,25 +1,24 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class BatchTransfersController < ApplicationController before_filter :login_required filter_access_to :all - + def index @batches = Batch.active end @@ -93,7 +92,7 @@ def subject_transfer @batch = Batch.find(params[:id]) @elective_groups = @batch.elective_groups.all(:conditions => {:is_deleted => false}) @normal_subjects = @batch.normal_batch_subject - @elective_subjects = Subject.find_all_by_batch_id(@batch.id,:conditions=>["elective_group_id IS NOT NULL AND is_deleted = false"]) + @elective_subjects = Subject.find_all_by_batch_id(@batch.id,:conditions=>["elective_group_id IS NOT NULL AND is_deleted = ?", false]) end def get_previous_batch_subjects diff --git a/app/controllers/batches_controller.rb b/app/controllers/batches_controller.rb index 337d8c9a5..1628cad8d 100755 --- a/app/controllers/batches_controller.rb +++ b/app/controllers/batches_controller.rb @@ -1,27 +1,27 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class BatchesController < ApplicationController - before_filter :init_data,:except=>[:assign_tutor,:update_employees,:assign_employee,:remove_employee,:batches_ajax] + before_filter :init_data, :except => [:assign_tutor, :update_employees, :assign_employee, :remove_employee, :batches_ajax] filter_access_to :all before_filter :login_required + def index - @batches = @course.batches + @batches = @course.batches end def new @@ -37,7 +37,8 @@ def create msg = [] msg << "
    " course_id = @batch.course_id - @previous_batch = Batch.find(:first,:order=>'id desc', :conditions=>"batches.id < '#{@batch.id }' AND batches.is_deleted = 0 AND course_id = ' #{course_id }'",:joins=>"INNER JOIN subjects ON subjects.batch_id = batches.id AND subjects.is_deleted = 0") + @previous_batch = Batch.find(:first, :order => 'id DESC', :conditions => ["batches.id < ? AND batches.is_deleted = ? AND course_id = ?", @batch.id, false, course_id], + :joins => ["INNER JOIN subjects ON subjects.batch_id = batches.id AND subjects.is_deleted = ?", false]) unless @previous_batch.blank? subjects = Subject.find_all_by_batch_id(@previous_batch.id,:conditions=>'is_deleted=false') subjects.each do |subject| @@ -126,7 +127,7 @@ def create end flash[:warn_notice] = err1 + err unless err.empty? flash[:fees_import] = fee_msg unless fee_msg.nil? - + redirect_to [@course, @batch] else @grade_types=[] diff --git a/app/controllers/calendar_controller.rb b/app/controllers/calendar_controller.rb index bcf646650..4779c8a20 100755 --- a/app/controllers/calendar_controller.rb +++ b/app/controllers/calendar_controller.rb @@ -1,82 +1,80 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class CalendarController < ApplicationController before_filter :login_required before_filter :default_time_zone_present_time filter_access_to :event_delete + def index @user = current_user - if params[:new_month].nil? + if params[:new_month].blank? @show_month = @local_tzone_time.to_date else d = params[:new_month].to_i passed_date = (params[:passed_date]).to_date if params[:new_month].to_i > passed_date.month - @show_month = passed_date+1.month + @show_month = passed_date + 1.month else - @show_month = passed_date-1.month - end - end - @start_date = @show_month.beginning_of_month + @show_month = passed_date - 1.month + end + end + @start_date = @show_month.beginning_of_month @start_date_day = @start_date.wday - @last_day = @show_month.end_of_month - @notifications = Hash.new{|h,k| h[k]=Array.new} - first_day = @show_month.beginning_of_month - last_day = @show_month.end_of_month - @events = Event.find(:all,:conditions => ["(start_date >= ? and end_date <= ?) or (start_date <= ? and end_date <= ?) or (start_date>=? and end_date>=?) or (start_date<=? and end_date>=?) ", first_day, last_day, first_day,last_day, first_day,last_day,first_day,last_day]) + @last_day = @show_month.end_of_month + @notifications = Hash.new { |h,k| h[k] = Array.new } + first_day = @show_month.beginning_of_month + last_day = @show_month.end_of_month + @events = Event.find(:all,:conditions => ["(start_date >= ? AND end_date <= ?) OR (start_date <= ? AND end_date <= ?) OR (start_date >= ? AND end_date >= ?) OR (start_date <= ? AND end_date >= ?)", first_day, last_day, first_day, last_day, first_day, last_day, first_day, last_day]) load_notifications - end def new_calendar - @user = current_user - d = params[:new_month].to_i + @user = current_user + d = params[:new_month].to_i passed_date = (params[:passed_date]).to_date if params[:new_month].to_i > passed_date.month - @show_month = passed_date+1.month + @show_month = passed_date + 1.month else - @show_month = passed_date-1.month + @show_month = passed_date - 1.month end - @start_date = @show_month.beginning_of_month + @start_date = @show_month.beginning_of_month @start_date_day = @start_date.wday - @last_day = @show_month.end_of_month - @notifications = Hash.new{|h,k| h[k]=Array.new} - first_day = @show_month.beginning_of_month - last_day = @show_month.end_of_month - @events = Event.find(:all,:conditions => ["(start_date >= ? and end_date <= ?) or (start_date <= ? and end_date <= ?) or (start_date>=? and end_date>=?) or (start_date<=? and end_date>=?) ", first_day, last_day, first_day,last_day, first_day,last_day,first_day,last_day]) + @last_day = @show_month.end_of_month + @notifications = Hash.new { |h,k| h[k] = Array.new } + first_day = @show_month.beginning_of_month + last_day = @show_month.end_of_month + @events = Event.find(:all, :conditions => ["(start_date >= ? AND end_date <= ?) OR (start_date <= ? AND end_date <= ?) OR (start_date >= ? AND end_date >= ?) OR (start_date <= ? AND end_date >= ?)", first_day, last_day, first_day, last_day, first_day, last_day, first_day, last_day]) load_notifications + render :update do |page| - page.replace_html 'calendar', :partial => 'month',:object => @show_month + page.replace_html 'calendar', :partial => 'month', :object => @show_month page.replace_html :tooltip_header, :text => '' end end - - def show_event_tooltip - @user = current_user - @date = params[:id].to_date + @user = current_user + @date = params[:id].to_date first_day = @date.beginning_of_month.to_time - last_day = @date.end_of_month.to_time + last_day = @date.end_of_month.to_time - common_event = Event.find_all_by_is_common_and_is_holiday(true,false, :conditions => ["(start_date >= ? and end_date <= ?) or (start_date <= ? and end_date <= ?) or (start_date>=? and end_date>=?) or (start_date<=? and end_date>=?) ", first_day, last_day, first_day,last_day, first_day,last_day,first_day,last_day]) - non_common_events = Event.find_all_by_is_common_and_is_holiday_and_is_exam_and_is_due(false,false,false,false, :conditions => ["(start_date >= ? and end_date <= ?) or (start_date <= ? and end_date <= ?) or (start_date>=? and end_date>=?) or (start_date<=? and end_date>=?) ", first_day, last_day, first_day,last_day, first_day,last_day,first_day,last_day]) + common_event = Event.find_all_by_is_common_and_is_holiday(true, false, :conditions => ["(start_date >= ? AND end_date <= ?) OR (start_date <= ? AND end_date <= ?) OR (start_date >= ? AND end_date >= ?) OR (start_date <= ? AND end_date >= ?)", first_day, last_day, first_day, last_day, first_day, last_day, first_day, last_day]) + non_common_events = Event.find_all_by_is_common_and_is_holiday_and_is_exam_and_is_due(false, false, false, false, :conditions => ["(start_date >= ? AND end_date <= ?) OR (start_date <= ? AND end_date <= ?) OR (start_date >= ? AND end_date >= ?) OR (start_date <= ? AND end_date >= ?)", first_day, last_day, first_day, last_day, first_day, last_day, first_day, last_day]) @common_event_array = [] common_event.each do |h| if h.start_date.to_date == h.end_date.to_date @@ -87,57 +85,57 @@ def show_event_tooltip end end end - if @user.student == true or @user.parent == true + if @user.student? || @user.parent? user_student = @user.student_record if @user.student user_student = @user.parent_record if @user.parent batch = user_student.batch @student_batch_not_common_event_array = [] non_common_events.each do |h| - student_batch_event = BatchEvent.find_by_batch_id(batch.id, :conditions=>"event_id = #{h.id}") + student_batch_event = BatchEvent.find_by_batch_id(batch.id, :conditions => { :event_id => h.id }) if h.start_date.to_date == "#{h.end_date.year}-#{h.end_date.month}-#{h.end_date.day}".to_date if "#{h.start_date.year}-#{h.start_date.month}-#{h.start_date.day}".to_date == @date - @student_batch_not_common_event_array.push(h) unless student_batch_event.nil? + @student_batch_not_common_event_array.push(h) if student_batch_event.present? end else (h.start_date.to_date..h.end_date.to_date).each do |d| if d == @date - @student_batch_not_common_event_array.push(h) unless student_batch_event.nil? + @student_batch_not_common_event_array.push(h) if student_batch_event.present? end end end end @events = @common_event_array + @student_batch_not_common_event_array - elsif @user.employee == true - user_employee = @user.employee_record + elsif @user.employee? + user_employee = @user.employee_record department = user_employee.employee_department @employee_dept_not_common_event_array = [] non_common_events.each do |h| - employee_dept_event = EmployeeDepartmentEvent.find_by_employee_department_id(department.id, :conditions=>"event_id = #{h.id}") + employee_dept_event = EmployeeDepartmentEvent.find_by_employee_department_id(department.id, :conditions => { :event_id => h.id }) if h.start_date.to_date == h.end_date.to_date if h.start_date.to_date == @date - @employee_dept_not_common_event_array.push(h) unless employee_dept_event.nil? + @employee_dept_not_common_event_array.push(h) if employee_dept_event.present? end else (h.start_date.to_date..h.end_date.to_date).each do |d| if d == @date - @employee_dept_not_common_event_array.push(h) unless employee_dept_event.nil? + @employee_dept_not_common_event_array.push(h) if employee_dept_event.present? end end end end @events = @common_event_array + @employee_dept_not_common_event_array - elsif @user.admin == true + elsif @user.admin? @employee_dept_not_common_event_array = [] non_common_events.each do |h| - employee_dept_event = EmployeeDepartmentEvent.find(:all, :conditions=>"event_id = #{h.id}") + employee_dept_event = EmployeeDepartmentEvent.find(:all, :conditions => { :event_id => h.id }) if h.start_date.to_date == h.end_date.to_date if h.start_date.to_date == @date - @employee_dept_not_common_event_array.push(h) unless employee_dept_event.nil? + @employee_dept_not_common_event_array.push(h) if employee_dept_event.present? end else (h.start_date.to_date..h.end_date.to_date).each do |d| if d == @date - @employee_dept_not_common_event_array.push(h) unless employee_dept_event.nil? + @employee_dept_not_common_event_array.push(h) if employee_dept_event.present? end end end @@ -147,74 +145,74 @@ def show_event_tooltip end def show_holiday_event_tooltip - @user = current_user - @date = params[:id].to_date + @user = current_user + @date = params[:id].to_date first_day = @date.beginning_of_month.to_time - last_day = @date.end_of_month.to_time + last_day = @date.end_of_month.to_time - common_holiday_event = Event.find_all_by_is_common_and_is_holiday(true,true, :conditions => ["(start_date >= ? and end_date <= ?) or (start_date <= ? and end_date <= ?) or (start_date>=? and end_date>=?) or (start_date<=? and end_date>=?) ", first_day, last_day, first_day,last_day, first_day,last_day,first_day,last_day]) - non_common_holiday_events = Event.find_all_by_is_common_and_is_holiday(false,true, :conditions => ["(start_date >= ? and end_date <= ?) or (start_date <= ? and end_date <= ?) or (start_date>=? and end_date>=?) or (start_date<=? and end_date>=?) ", first_day, last_day, first_day,last_day, first_day,last_day,first_day,last_day]) + common_holiday_event = Event.find_all_by_is_common_and_is_holiday(true, true, :conditions => ["(start_date >= ? AND end_date <= ?) OR (start_date <= ? AND end_date <= ?) OR (start_date >= ? AND end_date >= ?) OR (start_date <= ? AND end_date >= ?)", first_day, last_day, first_day, last_day, first_day, last_day, first_day, last_day]) + non_common_holiday_events = Event.find_all_by_is_common_and_is_holiday(false, true, :conditions => ["(start_date >= ? AND end_date <= ?) OR (start_date <= ? AND end_date <= ?) OR (start_date >= ? AND end_date >= ?) OR (start_date <= ? AND end_date >= ?)", first_day, last_day, first_day, last_day, first_day, last_day, first_day, last_day]) @common_holiday_event_array = [] common_holiday_event.each do |h| if h.start_date.to_date == h.end_date.to_date @common_holiday_event_array.push h if h.start_date.to_date == @date else - ( h.start_date.to_date..h.end_date.to_date).each do |d| + (h.start_date.to_date..h.end_date.to_date).each do |d| @common_holiday_event_array.push h if d == @date end end end - if @user.student == true or @user.parent == true + if @user.student? || @user.parent? user_student = @user.student_record if @user.student user_student = @user.parent_record if @user.parent - batch = user_student.batch unless user_student.nil? + batch = user_student.batch if user_student.present? @student_batch_not_common_holiday_event_array = [] non_common_holiday_events.each do |h| - student_batch_holiday_event = BatchEvent.find_by_batch_id(batch.id, :conditions=>"event_id = #{h.id}") + student_batch_holiday_event = BatchEvent.find_by_batch_id(batch.id, :conditions => { :event_id => h.id }) if h.start_date.to_date == h.end_date.to_date if h.start_date.to_date == @date - @student_batch_not_common_holiday_event_array.push(h) unless student_batch_holiday_event.nil? + @student_batch_not_common_holiday_event_array.push(h) if student_batch_holiday_event.present? end else (h.start_date.to_date..h.end_date.to_date).each do |d| if d == @date - @student_batch_not_common_holiday_event_array.push(h) unless student_batch_holiday_event.nil? + @student_batch_not_common_holiday_event_array.push(h) if student_batch_holiday_event.present? end end end end @events = @common_holiday_event_array.to_a + @student_batch_not_common_holiday_event_array.to_a - elsif @user.employee == true + elsif @user.employee? user_employee = @user.employee_record - department = user_employee.employee_department unless user_employee.nil? + department = user_employee.employee_department if user_employee.present? @employee_dept_not_common_holiday_event_array = [] non_common_holiday_events.each do |h| - employee_dept_holiday_event = EmployeeDepartmentEvent.find_by_employee_department_id(department.id, :conditions=>"event_id = #{h.id}") + employee_dept_holiday_event = EmployeeDepartmentEvent.find_by_employee_department_id(department.id, :conditions => { :event_id => h.id }) if h.start_date.to_date == h.end_date.to_date if h.start_date.to_date == @date - @employee_dept_not_common_holiday_event_array.push(h) unless employee_dept_holiday_event.nil? + @employee_dept_not_common_holiday_event_array.push(h) if employee_dept_holiday_event.present? end else (h.start_date.to_date..h.end_date.to_date).each do |d| if d == @date - @employee_dept_not_common_holiday_event_array.push(h) unless employee_dept_holiday_event.nil? + @employee_dept_not_common_holiday_event_array.push(h) if employee_dept_holiday_event.present? end end end end @events = @common_holiday_event_array.to_a + @employee_dept_not_common_holiday_event_array.to_a - elsif @user.admin == true + elsif @user.admin? @employee_dept_not_common_holiday_event_array = [] non_common_holiday_events.each do |h| - employee_dept_holiday_event = EmployeeDepartmentEvent.find(:all, :conditions=>"event_id = #{h.id}") + employee_dept_holiday_event = EmployeeDepartmentEvent.find(:all, :conditions => { :event_id => h.id }) if h.start_date.to_date == h.end_date.to_date if h.start_date.to_date == @date - @employee_dept_not_common_holiday_event_array.push(h) unless employee_dept_holiday_event.nil? + @employee_dept_not_common_holiday_event_array.push(h) if employee_dept_holiday_event.present? end else (h.start_date.to_date..h.end_date.to_date).each do |d| if d == @date - @employee_dept_not_common_holiday_event_array.push(h) unless employee_dept_holiday_event.nil? + @employee_dept_not_common_holiday_event_array.push(h) if employee_dept_holiday_event.present? end end end @@ -224,38 +222,38 @@ def show_holiday_event_tooltip end def show_exam_event_tooltip - @user = current_user - @date = params[:id].to_date + @user = current_user + @date = params[:id].to_date first_day = @date.beginning_of_month.to_time - last_day = @date.end_of_month.to_time - not_common_exam_event = Event.find_all_by_is_common_and_is_holiday_and_is_exam(false,false,true, :conditions => ["(start_date >= ? and end_date <= ?) or (start_date <= ? and end_date <= ?) or (start_date>=? and end_date>=?) or (start_date<=? and end_date>=?) ", first_day, last_day, first_day,last_day, first_day,last_day,first_day,last_day]) - not_common_exam_event.reject! { |x|x.origin.nil? } + last_day = @date.end_of_month.to_time + not_common_exam_event = Event.find_all_by_is_common_and_is_holiday_and_is_exam(false, false, true, :conditions => ["(start_date >= ? AND end_date <= ?) OR (start_date <= ? AND end_date <= ?) OR (start_date >= ? AND end_date >= ?) OR (start_date <= ? AND end_date >= ?)", first_day, last_day, first_day, last_day, first_day, last_day, first_day, last_day]) + not_common_exam_event.reject! { |x|x.origin.nil? } @student_batch_exam_event_array = [] - if @user.student == true or @user.parent == true + if @user.student? || @user.parent? user_student = @user.student_record if @user.student user_student = @user.parent_record if @user.parent batch = user_student.batch not_common_exam_event.each do |h| - student_batch_exam_event = BatchEvent.find_by_batch_id(batch.id, :conditions=>"event_id = #{h.id}") + student_batch_exam_event = BatchEvent.find_by_batch_id(batch.id, :conditions => { :event_id => h.id }) if h.start_date.to_date == h.end_date.to_date if h.start_date.to_date == @date - @student_batch_exam_event_array.push h unless student_batch_exam_event.nil? + @student_batch_exam_event_array.push h if student_batch_exam_event.present? end else (h.start_date.to_date..h.end_date.to_date).each do |d| if d == @date - @student_batch_exam_event_array.push h unless student_batch_exam_event.nil? + @student_batch_exam_event_array.push h if student_batch_exam_event.present? end end end end else not_common_exam_event.each do |h| - if h.start_date.to_date == h.end_date.to_date - @student_batch_exam_event_array.push h if h.start_date.to_date == @date + if h.start_date.to_date == h.end_date.to_date + @student_batch_exam_event_array.push h if h.start_date.to_date == @date else (h.start_date.to_date..h.end_date.to_date).each do |d| - @student_batch_exam_event_array.push h if d == @date + @student_batch_exam_event_array.push h if d == @date end end end @@ -265,13 +263,13 @@ def show_exam_event_tooltip def show_due_tooltip @user = current_user @date = params[:id].to_date - finance_due_check = Event.find_all_by_is_due(true,true, :conditions => " events.start_date >= '#{@date.strftime("%Y-%m-%d 00:00:00")}' AND events.start_date <= '#{@date.strftime("%Y-%m-%d 23:59:59")}'") - finance_due_check.reject!{|x| !x.is_active_event } - if @user.student? or @user.parent? - finance_due_check.reject!{|x| !x.is_student_event(@user.student_record) } if @user.student - finance_due_check.reject!{|x| !x.is_student_event(@user.parent_record) } if @user.parent + finance_due_check = Event.find_all_by_is_due(true, true, :conditions => "events.start_date >= '#{@date.strftime("%Y-%m-%d 00:00:00")}' AND events.start_date <= '#{@date.strftime("%Y-%m-%d 23:59:59")}'") + finance_due_check.reject!{|x| !x.active_event? } + if @user.student? || @user.parent? + finance_due_check.reject! { |x| !x.student_event?(@user.student_record) } if @user.student + finance_due_check.reject! { |x| !x.student_event?(@user.parent_record) } if @user.parent elsif @user.employee? - finance_due_check.reject!{|x| !x.is_employee_event(@user) } + finance_due_check.reject! { |x| !x.employee_event?(@user) } end @finance_due = [] finance_due_check.each do |h| @@ -283,8 +281,8 @@ def show_due_tooltip def event_delete @event = Event.find_by_id(params[:id]) - @event.destroy unless @event.nil? - redirect_to :controller=>"calendar" + @event.destroy if @event.present? + redirect_to :controller => "calendar" end @@ -302,24 +300,24 @@ def build_common_events_hash(e,key,today) def build_student_events_hash(h,key,batch_id,today) if h.start_date.to_date == h.end_date.to_date - student_batch_event = BatchEvent.find_by_batch_id(batch_id, :conditions=>"event_id = #{h.id}") - @notifications["#{key}"] << h.start_date.to_date unless student_batch_event.nil? + student_batch_event = BatchEvent.find_by_batch_id(batch_id, :conditions => { :event_id => h.id }) + @notifications["#{key}"] << h.start_date.to_date if student_batch_event.present? else (h.start_date.to_date..h.end_date.to_date).each do |d| - student_batch_event = BatchEvent.find_by_batch_id(batch_id, :conditions=>"event_id = #{h.id}") - @notifications["#{key}"] << d.to_date unless student_batch_event.nil? + student_batch_event = BatchEvent.find_by_batch_id(batch_id, :conditions => { :event_id => h.id }) + @notifications["#{key}"] << d.to_date if student_batch_event.present? end end end def build_employee_events_hash(h,key,department_id,today) if h.start_date.to_date == h.end_date.to_date - employee_dept_event = EmployeeDepartmentEvent.find_by_employee_department_id(department_id, :conditions=>"event_id = #{h.id}") unless department_id.nil? - @notifications["#{key}"] << h.start_date.to_date unless employee_dept_event.nil? + employee_dept_event = EmployeeDepartmentEvent.find_by_employee_department_id(department_id, :conditions => { :event_id => h.id }) if department_id.present? + @notifications["#{key}"] << h.start_date.to_date if employee_dept_event.present? else - employee_dept_event = EmployeeDepartmentEvent.find_by_employee_department_id(department_id, :conditions=>"event_id = #{h.id}") + employee_dept_event = EmployeeDepartmentEvent.find_by_employee_department_id(department_id, :conditions => { :event_id => h.id }) (h.start_date.to_date..h.end_date.to_date).each do |d| - @notifications["#{key}"] << d.to_date unless employee_dept_event.nil? + @notifications["#{key}"] << d.to_date if employee_dept_event.present? end end end @@ -327,93 +325,91 @@ def build_employee_events_hash(h,key,department_id,today) def load_notifications @events.each do |e| #common events and holidays - if e.is_common ==true - if e.is_holiday == true - build_common_events_hash(e,'common_holidays',@show_month) + if e.is_common? + if e.is_holiday? + build_common_events_hash(e, 'common_holidays', @show_month) else - build_common_events_hash(e,'common_events',@show_month) + build_common_events_hash(e, 'common_events', @show_month) end end #finance dues - if e.is_due == true - if e.is_active_event + if e.is_due? + if e.active_event? if @user.admin? - build_common_events_hash(e,'finance_due',@show_month) - elsif @user.student? or @user.parent? + build_common_events_hash(e, 'finance_due', @show_month) + elsif @user.student? || @user.parent? student= @user.student_record if @user.student student= @user.parent_record if @user.parent - if e.is_student_event(student) - build_common_events_hash(e,'finance_due',@show_month) + if e.student_event?(student) + build_common_events_hash(e, 'finance_due', @show_month) end elsif @user.employee? - if e.is_employee_event(@user) - build_common_events_hash(e,'finance_due',@show_month) + if e.employee_event?(@user) + build_common_events_hash(e, 'finance_due', @show_month) end end end end - if e.is_common ==false and e.is_holiday==false and e.is_exam==false and e.is_due==false #not_common_event - build_student_events_hash(e,'student_batch_not_common',@user.student_record.batch_id,@show_month) if @user.student? - build_employee_events_hash(e,'employee_dept_not_common',@user.employee_record.employee_department_id,@show_month) if @user.employee? + if e.is_common? && e.is_holiday? && e.is_exam? && e.is_due? #not_common_event + build_student_events_hash(e, 'student_batch_not_common', @user.student_record.batch_id, @show_month) if @user.student? + build_employee_events_hash(e, 'employee_dept_not_common', @user.employee_record.employee_department_id, @show_month) if @user.employee? end - if e.is_common ==false and e.is_holiday==true # not_common_holiday_event - build_student_events_hash(e,'student_batch_not_common_holiday',@user.student_record.batch_id,@show_month) if @user.student? - build_employee_events_hash(e,'employee_dept_not_common_holiday',@user.employee_record.employee_department_id,@show_month) if @user.employee? + if e.is_common? && e.is_holiday? # not_common_holiday_event + build_student_events_hash(e, 'student_batch_not_common_holiday', @user.student_record.batch_id, @show_month) if @user.student? + build_employee_events_hash(e, 'employee_dept_not_common_holiday', @user.employee_record.employee_department_id, @show_month) if @user.employee? if @user.admin? - employee_dept_holiday_event = EmployeeDepartmentEvent.find(:all, :conditions=>"event_id = #{e.id}") + employee_dept_holiday_event = EmployeeDepartmentEvent.find(:all, :conditions => "event_id = #{e.id}") if e.start_date.to_date == e.end_date.to_date - @notifications['employee_dept_not_common_holiday'].push e.start_date.to_date unless employee_dept_holiday_event.nil? + @notifications['employee_dept_not_common_holiday'].push e.start_date.to_date if employee_dept_holiday_event.present? else (e.start_date.to_date..e.end_date.to_date).each do |d| - @notifications['employee_dept_not_common_holiday'].push d.to_date unless employee_dept_holiday_event.nil? + @notifications['employee_dept_not_common_holiday'].push d.to_date if employee_dept_holiday_event.present? end end end end - if e.is_common ==false and e.is_holiday==false and e.is_exam ==true # not_common_exam_event + if e.is_common? && e.is_holiday? && e.is_exam? # not_common_exam_event unless e.origin.nil? if @user.student? subject=e.origin.subject - if subject.elective_group_id == nil - build_student_events_hash(e,'student_batch_exam',@user.student_record.batch_id,@show_month) + if subject.elective_group_id.blank? + build_student_events_hash(e, 'student_batch_exam', @user.student_record.batch_id, @show_month) else - build_student_events_hash(e,'student_batch_exam',@user.student_record.batch_id,@show_month) if (@user.student_record.students_subjects.map{|sub| sub.subject_id}.include?(subject.id)) + build_student_events_hash(e, 'student_batch_exam', @user.student_record.batch_id, @show_month) if (@user.student_record.students_subjects.map{|sub| sub.subject_id}.include?(subject.id)) end end if @user.employee? - build_common_events_hash(e,'student_batch_exam',@show_month) + build_common_events_hash(e, 'student_batch_exam', @show_month) end if @user.admin? - student_batch_exam_event = BatchEvent.find(:all, :conditions=>"event_id = #{e.id}") - if e.start_date.to_date == e.end_date.to_date - @notifications['student_batch_exam'] << e.start_date.to_date unless student_batch_exam_event.nil? + student_batch_exam_event = BatchEvent.find(:all, :conditions => "event_id = #{e.id}") + if e.start_date.to_date == e.end_date.to_date + @notifications['student_batch_exam'] << e.start_date.to_date if student_batch_exam_event.present? else (e.start_date.to_date..e.end_date.to_date).each do |d| - @notifications['student_batch_exam'] << d.to_date unless student_batch_exam_event.nil? + @notifications['student_batch_exam'] << d.to_date if student_batch_exam_event.present? end end end end end - if e.is_common ==false and e.is_holiday==false and e.is_due==false and e.is_exam ==false and @user.admin? # not_common_exam_due_event - build_common_events_hash(e,'employee_dept_not_common',@show_month) + if e.is_common? && e.is_holiday? && e.is_due? && e.is_exam? && @user.admin? # not_common_exam_due_event + build_common_events_hash(e, 'employee_dept_not_common', @show_month) end end - if @user.student? or @user.parent? + if @user.student? || @user.parent? @events = @notifications['common_events'] + @notifications['student_batch_not_common'] - @holiday_event = @notifications['common_holidays']+ @notifications['student_batch_not_common_holiday'] + @holiday_event = @notifications['common_holidays'] + @notifications['student_batch_not_common_holiday'] elsif @user.employee? @events = @notifications['common_events'] + @notifications['employee_dept_not_common'] - @holiday_event = @notifications['common_holidays']+ @notifications['employee_dept_not_common_holiday'] + @holiday_event = @notifications['common_holidays'] + @notifications['employee_dept_not_common_holiday'] elsif @user.admin? @events = @notifications['common_events'] + @notifications['employee_dept_not_common'] - @holiday_event = @notifications['common_holidays']+ @notifications['employee_dept_not_common_holiday'] + @holiday_event = @notifications['common_holidays'] + @notifications['employee_dept_not_common_holiday'] end end - - end \ No newline at end of file diff --git a/app/controllers/cce_exam_categories_controller.rb b/app/controllers/cce_exam_categories_controller.rb index 39f70632e..0d09963dc 100644 --- a/app/controllers/cce_exam_categories_controller.rb +++ b/app/controllers/cce_exam_categories_controller.rb @@ -1,62 +1,69 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class CceExamCategoriesController < ApplicationController before_filter :login_required + before_filter :find_category, :only => [:edit, :update, :destroy] filter_access_to :all + def index - @categories=CceExamCategory.all + @categories = CceExamCategory.all end + def new - @category=CceExamCategory.new + @category = CceExamCategory.new end + def create - @category=CceExamCategory.new(params[:cce_exam_category]) + @category = CceExamCategory.new(params[:cce_exam_category]) if @category.save - flash[:notice]="Exam Category created successfully." - @categories=CceExamCategory.all + flash[:success] = "Exam Category created successfully." + @categories = CceExamCategory.all else - @error=true + @error = true end end def edit - @category=CceExamCategory.find(params[:id]) end def update - @category=CceExamCategory.find(params[:id]) - @category.name=params[:cce_exam_category][:name] - @category.desc=params[:cce_exam_category][:desc] + @category.name = params[:cce_exam_category][:name] + @category.desc = params[:cce_exam_category][:desc] if @category.save - flash[:notice]="Exam Category updated successfully." - @categories=CceExamCategory.all + flash[:success] = "Exam Category updated successfully." + @categories = CceExamCategory.all else - @error=true + @error = true end end + def destroy - @category=CceExamCategory.find(params[:id]) if @category.destroy - flash[:notice]="Exam Category Deleted" + flash[:success] = "Exam Category Deleted" else - flash[:notice]="Exam category cannot be deleted" + flash[:error] = "Exam category cannot be deleted" end - redirect_to :action => "index" + redirect_to cce_exam_categories_path + end + + private + + def find_category + @category = CceExamCategory.find(params[:id]) end end diff --git a/app/controllers/cce_grade_sets_controller.rb b/app/controllers/cce_grade_sets_controller.rb index 55c5b0c15..966fbbf22 100644 --- a/app/controllers/cce_grade_sets_controller.rb +++ b/app/controllers/cce_grade_sets_controller.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class CceGradeSetsController < ApplicationController before_filter :login_required filter_access_to :all @@ -122,5 +121,5 @@ def destroy_grade end end - + end diff --git a/app/controllers/cce_reports_controller.rb b/app/controllers/cce_reports_controller.rb index 0b8978487..4918a2e1c 100644 --- a/app/controllers/cce_reports_controller.rb +++ b/app/controllers/cce_reports_controller.rb @@ -1,75 +1,63 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class CceReportsController < ApplicationController before_filter :login_required - # before_filter :load_cce_report, :only=>[:show_student_wise_report] - filter_access_to :all - # filter_access_to :show_student_wise_report, :attribute_check => true - + filter_access_to :all + def index - + end - + def create_reports @courses = Course.cce - if request.post? - unless params[:course][:batch_ids].blank? - errors = [] - batches = Batch.find_all_by_id(params[:course][:batch_ids]) - batches.each do |batch| - if batch.check_credit_points - batch.job_type = "3" - Delayed::Job.enqueue(batch) - batch.delete_student_cce_report_cache - else - errors += ["Incomplete grading level credit points for #{batch.full_name}, report generation failed."] - end - end - flash[:notice]="Report generation in queue for batches #{batches.collect(&:full_name).join(", ")}. Click Here to view the scheduled job." - flash[:error]=errors + if request.post? + if params[:course][:batch_ids].present? + notice, errors = Batch.create_reports(params[:course][:batch_ids]) + flash[:notice] = notice + flash[:error] = errors else - flash[:notice]="No batch selected" - end + flash[:notice] = "No batch selected" + end end - end def student_wise_report - @batches=Batch.cce - if request.post? - @batch=Batch.find(params[:batch_id]) - @students=@batch.students.all(:order=>"first_name ASC") + @batches = Batch.cce + if request.post? + @batch = Batch.find(params[:batch_id]) + @students = @batch.students.all(:order => "first_name ASC") @student = @students.first - if @student - fetch_report - end + fetch_report if @student render(:update) do |page| - page.replace_html 'student_list', :partial=>"student_list", :object=>@students - @student.nil? ? (page.replace_html 'report', :text=>"") : (page.replace_html 'report', :partial=>"student_report") - page.replace_html 'hider', :text=>"" + page.replace_html 'student_list', partial: "student_list", object: @students + if @student.nil? + page.replace_html 'report', text: "" + else + page.replace_html 'report', partial: "student_report" + end + page.replace_html 'hider', text: '' end end end def student_report @student = Student.find(params[:student]) - @batch=@student.batch + @batch = @student.batch fetch_report render(:update) do |page| page.replace_html 'report', :partial=>"student_report" @@ -77,19 +65,19 @@ def student_report end def student_report_pdf - @student= (params[:type]=="former" ? ArchivedStudent.find(params[:id]) : Student.find(params[:id])) - @type= params[:type] || "regular" - @batch=Batch.find(params[:batch_id]) + @student = CceReport.find_student(params[:type], params[:id]) + @type = params[:type] || "regular" + @batch = Batch.find(params[:batch_id]) @student.batch_in_context = @batch fetch_report render :pdf => "#{@student.first_name}-CCE_Report" end def student_transcript - @student= (params[:type]=="former" ? ArchivedStudent.find(params[:id]) : Student.find(params[:id])) - @type= params[:type] || "regular" - @batch=(params[:batch_id].blank? ? @student.batch : Batch.find(params[:batch_id])) - @batches=@student.all_batches.reverse unless request.xhr? + @student = CceReport.find_student(params[:type], params[:id]) + @type = params[:type] || "regular" + @batch = (params[:batch_id].blank? ? @student.batch : Batch.find(params[:batch_id])) + @batches = @student.all_batches.reverse unless request.xhr? @student.batch_in_context = @batch fetch_report if request.xhr? @@ -102,20 +90,22 @@ def student_transcript private def fetch_report - @report=@student.individual_cce_report_cached - @subjects=@student.all_subjects.select{|x| x.no_exams==false} - @exam_groups=ExamGroup.find_all_by_id(@report.exam_group_ids, :include=>:cce_exam_category) - coscholastic=@report.coscholastic - @observation_group_ids=coscholastic.collect(&:observation_group_id) - @observation_groups=ObservationGroup.find_all_by_id(@observation_group_ids).collect(&:name) - @co_hash=Hash.new { |h, k| h[k] = Hash.new(&h.default_proc) } - @obs_groups=@batch.observation_groups.to_a - @og=@obs_groups.group_by(&:observation_kind) + @report = @student.individual_cce_report_cached + @subjects = @student.all_subjects.select{|x| x.no_exams == false} + @exam_groups = ExamGroup.find_all_by_id(@report.exam_group_ids, :include => :cce_exam_category) + coscholastic = @report.coscholastic + @observation_group_ids = coscholastic.map(&:observation_group_id) + @observation_groups = ObservationGroup.find_all_by_id(@observation_group_ids).map(&:name) + @co_hash = Hash.new { |h, k| h[k] = Hash.new(&h.default_proc) } + @obs_groups = @batch.observation_groups.to_a + @og = @obs_groups.group_by(&:observation_kind) @co_hashi = {} @og.each do |kind, ogs| - @co_hashi[kind]=[] - coscholastic.each{|cs| @co_hashi[kind] << cs if ogs.collect(&:id).include? cs.observation_group_id} - end + id_list = ogs.map(&:id) + @co_hashi[kind] = coscholastic.map do |cs| + cs if id_list.include?(cs.observation_group_id) + end.compact + end end - + end diff --git a/app/controllers/cce_settings_controller.rb b/app/controllers/cce_settings_controller.rb index 89a8567d1..1a6593ebc 100644 --- a/app/controllers/cce_settings_controller.rb +++ b/app/controllers/cce_settings_controller.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class CceSettingsController < ApplicationController before_filter :login_required filter_access_to :all diff --git a/app/controllers/cce_weightages_controller.rb b/app/controllers/cce_weightages_controller.rb index 1be488599..37088d239 100644 --- a/app/controllers/cce_weightages_controller.rb +++ b/app/controllers/cce_weightages_controller.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class CceWeightagesController < ApplicationController before_filter :login_required filter_access_to :all @@ -43,7 +42,7 @@ def show @weightage=CceWeightage.find(params[:id]) @courses=@weightage.courses end - + def edit @weightage=CceWeightage.find(params[:id]) @criteria=['FA','SA'] @@ -122,7 +121,7 @@ def update_course_weightages page.replace_html 'select_weightages',:partial=>"select_weightage" end end - + end end diff --git a/app/controllers/class_designations_controller.rb b/app/controllers/class_designations_controller.rb index 80aa79290..c5616abbd 100644 --- a/app/controllers/class_designations_controller.rb +++ b/app/controllers/class_designations_controller.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class ClassDesignationsController < ApplicationController before_filter :login_required filter_access_to :all @@ -105,7 +104,7 @@ def delete_class_designation page.replace_html 'errors', :partial=>"form_errors" page.replace_html 'class_form', :partial=>"class_form" end - + end end diff --git a/app/controllers/class_timings_controller.rb b/app/controllers/class_timings_controller.rb index 976fd7d61..268fb2334 100755 --- a/app/controllers/class_timings_controller.rb +++ b/app/controllers/class_timings_controller.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class ClassTimingsController < ApplicationController before_filter :login_required filter_access_to :all @@ -81,7 +80,7 @@ def update def show @batch = nil if params[:batch_id] == '' - @class_timings = ClassTiming.find(:all, :conditions=>["batch_id is null and is_deleted = false"]) + @class_timings = ClassTiming.find(:all, :conditions=>{:batch_id => nil, :is_deleted => false}) else @class_timings = ClassTiming.active_for_batch(params[:batch_id]) @batch = Batch.find params[:batch_id] unless params[:batch_id] == '' diff --git a/app/controllers/configuration_controller.rb b/app/controllers/configuration_controller.rb index 87d6dda73..b044fd540 100755 --- a/app/controllers/configuration_controller.rb +++ b/app/controllers/configuration_controller.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class ConfigurationController < ApplicationController before_filter :login_required filter_access_to :all diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 888843ffe..63a5b5dfc 100755 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -1,33 +1,32 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class CoursesController < ApplicationController before_filter :login_required before_filter :find_course, :only => [:show, :edit, :update, :destroy] filter_access_to :all - + def index @courses = Course.active end def new @course = Course.new - @grade_types=Course.grading_types_as_options + @grade_types = Course.grading_types_as_options # gpa = Configuration.find_by_config_key("GPA").config_value # if gpa == "1" # @grade_types << "GPA" @@ -43,9 +42,9 @@ def manage_course end def assign_subject_amount - @course = Course.active.find(params[:id]) + @course = Course.active.find(params[:id]) @subjects = @course.batches.map(&:subjects).flatten.compact.map(&:code).compact.flatten.uniq - @subject_amount = @course.subject_amounts.build + @subject_amount = @course.subject_amounts.build @subject_amounts = @course.subject_amounts.reject{|sa| sa.new_record?} if request.post? code = params[:subject_amount][:code] @@ -252,7 +251,7 @@ def destroy flash[:warn_notice]="

    #{t('courses.flash4')}

    " redirect_to :action=>'manage_course' end - + end def show @@ -260,6 +259,7 @@ def show end private + def find_course @course = Course.find params[:id] end diff --git a/app/controllers/descriptive_indicators_controller.rb b/app/controllers/descriptive_indicators_controller.rb index 6dfc29e2c..ce7e9a1e7 100644 --- a/app/controllers/descriptive_indicators_controller.rb +++ b/app/controllers/descriptive_indicators_controller.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class DescriptiveIndicatorsController < ApplicationController before_filter :login_required filter_access_to :all @@ -78,7 +77,7 @@ def update end def show - + end def destroy_indicator diff --git a/app/controllers/elective_groups_controller.rb b/app/controllers/elective_groups_controller.rb index 78b965946..4571f8f85 100755 --- a/app/controllers/elective_groups_controller.rb +++ b/app/controllers/elective_groups_controller.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class ElectiveGroupsController < ApplicationController before_filter :pre_load_objects before_filter :login_required @@ -62,7 +61,7 @@ def destroy end def show - @electives = Subject.find_all_by_batch_id_and_elective_group_id(@batch.id,@elective_group.id, :conditions=>["is_deleted = false"]) + @electives = Subject.find_all_by_batch_id_and_elective_group_id(@batch.id,@elective_group.id, :conditions=>{:is_deleted => false}) end private diff --git a/app/controllers/employee_attendance_controller.rb b/app/controllers/employee_attendance_controller.rb index 09a117105..bb535526d 100755 --- a/app/controllers/employee_attendance_controller.rb +++ b/app/controllers/employee_attendance_controller.rb @@ -1,130 +1,99 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class EmployeeAttendanceController < ApplicationController - before_filter :login_required,:configuration_settings_for_hr - before_filter :protect_leave_dashboard, :only => [:leaves]#, :employee_attendance_pdf] + before_filter :login_required, :configuration_settings_for_hr + before_filter :protect_leave_dashboard, :only => [:leaves] before_filter :protect_applied_leave, :only => [:own_leave_application, :cancel_application] before_filter :protect_manager_leave_application_view, :only => [:leave_application] before_filter :protect_leave_history, :only => [:leave_history,:update_leave_history] - # prawnto :prawn => {:left_margin => 25, :right_margin => 25} filter_access_to :all def add_leave_types - @leave_types = EmployeeLeaveType.find(:all, :order => "name ASC",:conditions=>'status = 1') - @inactive_leave_types = EmployeeLeaveType.find(:all, :order => "name ASC",:conditions=>'status = 0') + @leave_types = EmployeeLeaveType.all(:order => "name ASC", :conditions => {:status => true}) + @inactive_leave_types = EmployeeLeaveType.all(:order => "name ASC", :conditions => {:status => false}) @leave_type = EmployeeLeaveType.new(params[:leave_type]) @employee = Employee.all - if request.post? and @leave_type.save + if request.post? && @leave_type.save @employee.each do |e| EmployeeLeave.create( :employee_id => e.id, :employee_leave_type_id => @leave_type.id, :leave_count => @leave_type.max_leave_count) end - flash[:notice] = t('flash1') + flash[:notice] = t('flash1') redirect_to :action => "add_leave_types" end end def edit_leave_types @leave_type = EmployeeLeaveType.find(params[:id]) - if request.post? and @leave_type.update_attributes(params[:leave_type]) - flash[:notice] = t('flash2') + if request.post? && @leave_type.update_attributes(params[:leave_type]) + flash[:notice] = t('flash2') redirect_to :action => "add_leave_types" end end def delete_leave_types - @leave_type = EmployeeLeaveType.find(params[:id]) - @attendance = EmployeeAttendance.find_all_by_employee_leave_type_id(@leave_type.id) - @leave_count = EmployeeLeave.find_all_by_employee_leave_type_id(@leave_type.id) - if @attendance.blank? - @leave_type.delete - @leave_count.each do |e| + leave_type = EmployeeLeaveType.find(params[:id]) + attendance = EmployeeAttendance.find_all_by_employee_leave_type_id(leave_type.id) + if attendance.blank? + leave_count = EmployeeLeave.find_all_by_employee_leave_type_id(leave_type.id) + leave_type.delete + leave_count.each do |e| e.delete end - flash[:notice] = t('flash3') + flash[:notice] = t('flash3') else - flash[:notice] = "#{t('flash_msg12')}" + flash[:notice] = t('flash_msg12') end redirect_to :action => "add_leave_types" - - end def leave_reset_settings - # @config = Configuration.get_multiple_configs_as_hash ['AutomaticLeaveReset', 'LeaveResetPeriod', 'LastAutoLeaveReset'] @auto_reset = Configuration.find_by_config_key('AutomaticLeaveReset') @reset_period = Configuration.find_by_config_key('LeaveResetPeriod') @last_reset = Configuration.find_by_config_key('LastAutoLeaveReset') @fin_start_date = Configuration.find_by_config_key('FinancialYearStartDate') if request.post? - @auto_reset.update_attributes(:config_value=> params[:configuration][:automatic_leave_reset]) - @reset_period.update_attributes(:config_value=> params[:configuration][:leave_reset_period]) - @last_reset.update_attributes(:config_value=> params[:configuration][:financial_year_start_date]) - - flash[:notice] = t('flash_msg8') - end + @auto_reset.update_attributes(:config_value => params[:configuration][:automatic_leave_reset]) + @reset_period.update_attributes(:config_value => params[:configuration][:leave_reset_period]) + @last_reset.update_attributes(:config_value => params[:configuration][:financial_year_start_date]) + flash[:notice] = t('flash_msg8') end - + end + + # I thinks this action should be a POST def update_employee_leave_reset_all - @leave_count = EmployeeLeave.all - @leave_count.each do |e| - @leave_type = EmployeeLeaveType.find_by_id(e.employee_leave_type_id) - if @leave_type.status - default_leave_count = @leave_type.max_leave_count - if @leave_type.carry_forward - leave_taken = e.leave_taken - available_leave = e.leave_count - if leave_taken <= available_leave - balance_leave = available_leave - leave_taken - available_leave = balance_leave.to_f - available_leave += default_leave_count.to_f - leave_taken = 0 - e.update_attributes(:leave_taken => leave_taken,:leave_count => available_leave, :reset_date => Date.today) - else - available_leave = default_leave_count.to_f - leave_taken = 0 - e.update_attributes(:leave_taken => leave_taken,:leave_count => available_leave, :reset_date => Date.today) - end - else - available_leave = default_leave_count.to_f - leave_taken = 0 - e.update_attributes(:leave_taken => leave_taken,:leave_count => available_leave, :reset_date => Date.today) - end - end - end + EmployeeLeave.reset_all + notice = t('leave_count_reset_sucessfull') render :update do |page| - page.replace_html "main-reset-box", :text => "

    #{t('leave_count_reset_sucessfull')}

    " + page.replace_html "main-reset-box", :text => "

    #{notice}

    " end end def employee_leave_reset_by_department - @departments = EmployeeDepartment.find(:all, :conditions => "status = true", :order=> "name ASC") - + @departments = EmployeeDepartment.all(:conditions => {:status => true}, :order => "name ASC") end def list_department_leave_reset - @leave_types = EmployeeLeaveType.find(:all, :conditions => "status = true") - if params[:department_id] == "" + @leave_types = EmployeeLeaveType.all(:conditions => {:status => true}) + if params[:department_id].blank? render :update do |page| page.replace_html "department-list", :text => "" - end - return + end and return end @employees = Employee.find_all_by_employee_department_id(params[:department_id]) render :update do |page| @@ -133,88 +102,31 @@ def list_department_leave_reset end def update_department_leave_reset - @employee = params[:employee_id] - @employee.each do |e| - @leave_count = EmployeeLeave.find_all_by_employee_id(e) - @leave_count.each do |c| - #attendance = EmployeeAttendance.find_all_by_employee_id(e, :conditions=> "employee_leave_type_id = '#{c.employee_leave_type_id }' and attendance_date >= '#{Date.today.strftime('%Y-%m-%d')}'" ) - @leave_type = EmployeeLeaveType.find_by_id(c.employee_leave_type_id) - if @leave_type.status - default_leave_count = @leave_type.max_leave_count - if @leave_type.carry_forward - leave_taken = c.leave_taken - available_leave = c.leave_count - if leave_taken <= available_leave - balance_leave = available_leave - leave_taken - available_leave = balance_leave.to_f - available_leave += default_leave_count.to_f - leave_taken = 0 -# unless attendance.blank? -# attendance.each do |a| -# if a.is_half_day -# leave_taken += (0.5).to_f -# -# else -# leave_taken += (1).to_f -# -# end -# end -# end - c.update_attributes(:leave_taken => leave_taken,:leave_count => available_leave, :reset_date => Date.today) - else - available_leave = default_leave_count.to_f - leave_taken = 0 - c.update_attributes(:leave_taken => leave_taken,:leave_count => available_leave, :reset_date => Date.today) - end - else - available_leave = default_leave_count.to_f - leave_taken = 0 - c.update_attributes(:leave_taken => leave_taken,:leave_count => available_leave, :reset_date => Date.today) - end - end - - end - end - flash[:notice]=t('flash12') - redirect_to :controller=>"employee_attendance", :action => "employee_leave_reset_by_department" + leave_count = EmployeeLeave.all(conditions: ['employee_id IN (?)', params[:employee_id]]) + leave_count.each(&:reset) + flash[:notice] = t('flash12') + redirect_to :action => "employee_leave_reset_by_department" end - def employee_leave_reset_by_employee - @departments = EmployeeDepartment.find(:all) - @categories = EmployeeCategory.find(:all) - @positions = EmployeePosition.find(:all) - @grades = EmployeeGrade.find(:all) + @departments = EmployeeDepartment.all + @categories = EmployeeCategory.all + @positions = EmployeePosition.all + @grades = EmployeeGrade.all end def employee_search_ajax - other_conditions = "" - other_conditions += " AND employee_department_id = '#{params[:employee_department_id]}'" unless params[:employee_department_id] == "" - other_conditions += " AND employee_category_id = '#{params[:employee_category_id]}'" unless params[:employee_category_id] == "" - other_conditions += " AND employee_position_id = '#{params[:employee_position_id]}'" unless params[:employee_position_id] == "" - other_conditions += " AND employee_grade_id = '#{params[:employee_grade_id]}'" unless params[:employee_grade_id] == "" - unless params[:query].length < 3 - @employee = Employee.find(:all, - :conditions => ["(first_name LIKE ? OR middle_name LIKE ? OR last_name LIKE ? - OR employee_number LIKE ? OR (concat(first_name, \" \", last_name) LIKE ?))" + other_conditions, - "#{params[:query]}%","#{params[:query]}%","#{params[:query]}%", - "#{params[:query]}", "#{params[:query]}"], - :order => "first_name asc") unless params[:query] == '' - else - @employee = Employee.find(:all, - :conditions => ["employee_number = ? "+ other_conditions, "#{params[:query]}%"], - :order => "first_name asc") unless params[:query] == '' - end + @employee = Employee.search_employees(params) render :layout => false end def employee_view_all - @departments = EmployeeDepartment.find(:all) + @departments = EmployeeDepartment.all end def employees_list - department_id = params[:department_id] - @employees = Employee.find_all_by_employee_department_id(department_id,:order=>'first_name ASC') + @employees = Employee.find_all_by_employee_department_id(params[:department_id], + :order=>'first_name ASC') render :update do |page| page.replace_html 'employee_list', :partial => 'employee_view_all_list', :object => @employees @@ -223,66 +135,40 @@ def employees_list def employee_leave_details @employee = Employee.find_by_id(params[:id]) - @leave_count = EmployeeLeave.find_all_by_employee_id(@employee.id) + @leave_count = EmployeeLeave.find_all_by_employee_id(params[:id]) end def employee_wise_leave_reset @employee = Employee.find_by_id(params[:id]) - @leave_count = EmployeeLeave.find_all_by_employee_id(@employee.id) - @leave_count.each do |e| - #attendance = EmployeeAttendance.find_all_by_employee_id(@employee.id, :conditions=> "employee_leave_type_id = '#{e.employee_leave_type_id }' and attendance_date >= '#{Date.today.strftime('%Y-%m-%d')}'" ) - @leave_type = EmployeeLeaveType.find_by_id(e.employee_leave_type_id) - if @leave_type.status - default_leave_count = @leave_type.max_leave_count - if @leave_type.carry_forward - leave_taken = e.leave_taken - available_leave = e.leave_count - if leave_taken <= available_leave - balance_leave = available_leave - leave_taken - available_leave = balance_leave.to_f - available_leave += default_leave_count.to_f - leave_taken = 0 - e.update_attributes(:leave_taken => leave_taken,:leave_count => available_leave, :reset_date => Date.today) - else - available_leave = default_leave_count.to_f - leave_taken = 0 - e.update_attributes(:leave_taken => leave_taken,:leave_count => available_leave, :reset_date => Date.today) - end - else - available_leave = default_leave_count.to_f - leave_taken = 0 - e.update_attributes(:leave_taken => leave_taken,:leave_count => available_leave, :reset_date => Date.today) - end - end - end + @leave_count = EmployeeLeave.find_all_by_employee_id(params[:id]) + @leave_count.each(&:reset) + notice = t('flash_msg12') render :update do |page| - flash.now[:notice]= "#{t('flash_msg12')}" - page.replace_html "list", :partial => 'employee_reset_sucess' + flash.now[:notice] = notice + page.replace_html "list", :partial => 'employee_reset_success' end end - def register - @departments = EmployeeDepartment.find(:all, :conditions=>"status = true", :order=> "name ASC") + @departments = EmployeeDepartment.all(:conditions => {:status => true}, :order=> "name ASC") if request.post? - unless params[:employee_attendance].nil? + if params[:employee_attendance] params[:employee_attendance].each_pair do |emp, att| - @employee_attendance = EmployeeAttendance.create(:attendance_date => params[:date], - :employees_id => emp, :employee_leave_types_id=> att) unless att == "" + EmployeeAttendance.create(:attendance_date => params[:date], reason: 'No reason', + :employee_id => emp, :employee_leave_type_id => att) unless att == "" end - flash[:notice]=t('flash3') - redirect_to :controller=>"employee_attendance", :action => "register" + flash[:notice] = t('flash3') + redirect_to :action => "register" end end end def update_attendance_form - @leave_types = EmployeeLeaveType.find(:all, :conditions=>"status = true", :order=>"name ASC") - if params[:department_id] == "" + @leave_types = EmployeeLeaveType.all(:conditions => {:status => true}, :order => "name ASC") + if params[:department_id].blank? render :update do |page| page.replace_html "attendance_form", :text => "" - end - return + end and return end @employees = Employee.find_all_by_employee_department_id(params[:department_id]) @@ -292,16 +178,15 @@ def update_attendance_form end def report - @departments = EmployeeDepartment.find(:all, :conditions => "status = true", :order=> "name ASC") + @departments = EmployeeDepartment.all(:conditions => {:status => true}, :order => "name ASC") end def update_attendance_report - @leave_types = EmployeeLeaveType.find(:all, :conditions => "status = true") - if params[:department_id] == "" + @leave_types = EmployeeLeaveType.all(:conditions => {:status => true}) + if params[:department_id].blank? render :update do |page| page.replace_html "attendance_report", :text => "" - end - return + end and return end @employees = Employee.find_all_by_employee_department_id(params[:department_id]) render :update do |page| @@ -312,12 +197,12 @@ def update_attendance_report def emp_attendance @employee = Employee.find(params[:id]) @attendance_report = EmployeeAttendance.find_all_by_employee_id(@employee.id) - @leave_types = EmployeeLeaveType.find(:all, :conditions => "status = true") - @leave_count = EmployeeLeave.find_all_by_employee_id(@employee,:joins=>:employee_leave_type,:conditions=>"status = true") - @total_leaves = 0 - @leave_types.each do |lt| - leave_count = EmployeeAttendance.find_all_by_employee_id_and_employee_leave_type_id(@employee.id,lt.id).size - @total_leaves = @total_leaves +leave_count + @leave_types = EmployeeLeaveType.all(:conditions => {:status => true}) + @leave_count = EmployeeLeave.find_all_by_employee_id(@employee.id, + joins: :employee_leave_type, + conditions: 'employee_leave_types.status IS TRUE') + @total_leaves = @leave_types.inject(0) do |sum, lt| + sum += EmployeeAttendance.find_all_by_employee_id_and_employee_leave_type_id(@employee.id, lt.id).size end end @@ -327,48 +212,48 @@ def leave_history def update_leave_history @employee = Employee.find(params[:id]) - @start_date = (params[:period][:start_date]) - @end_date = (params[:period][:end_date]) - @leave_types = EmployeeLeaveType.find(:all, :conditions => "status = true") - @employee_attendances = {} - @leave_types.each do |lt| - @employee_attendances[lt.name] = EmployeeAttendance.find_all_by_employee_id_and_employee_leave_type_id(@employee.id,lt.id,:conditions=> "attendance_date between '#{@start_date.to_date}' and '#{@end_date.to_date}'") - end + @start_date = params[:period][:start_date] + @end_date = params[:period][:end_date] + @leave_types = EmployeeLeaveType.all(:conditions => {:status => true}) + @employee_attendances = Hash[@leave_types.map do |leave_type| + [leave_type.name, EmployeeAttendance.all(conditions: {employee_id: @employee.id, + employee_leave_type_id: leave_type.id, + attendance_date: @start_date.to_date..@end_date.to_date})] + end] render :update do |page| page.replace_html "attendance-report", :partial => 'update_leave_history' end end def leaves - @leave_types = EmployeeLeaveType.find(:all, :conditions=>"status = true") + @leave_types = EmployeeLeaveType.all(:conditions => {:status => true}) @employee = Employee.find(params[:id]) @reporting_employees = Employee.find_all_by_reporting_manager_id(@employee.id) - @total_leave_count = 0 - @reporting_employees.each do |e| - @app_leaves = ApplyLeave.count(:conditions=>["employee_id =? AND viewed_by_manager =?", e.id, false]) - @total_leave_count = @total_leave_count + @app_leaves + @total_leave_count = @reporting_employees.inject(0) do |sum, e| + sum += ApplyLeave.count(:conditions => {:employee_id => e.id, :viewed_by_manager => false}) end @leave_apply = ApplyLeave.new(params[:leave_apply]) - if request.post? and @leave_apply.save - ApplyLeave.update(@leave_apply, :approved=> false, :viewed_by_manager=> false) - flash[:notice]=t('flash5') - redirect_to :controller => "employee_attendance", :action=> "leaves", :id=>@employee.id + if request.post? && @leave_apply.save + ApplyLeave.update(@leave_apply, :approved => false, :viewed_by_manager => false) + flash[:notice] = t('flash5') + redirect_to action: "leaves", id: @employee.id, controller: :employee_attendance end end def leave_application @applied_leave = ApplyLeave.find(params[:id]) @applied_employee = Employee.find(@applied_leave.employee_id) - @leave_type = EmployeeLeaveType.find(@applied_leave.employee_leave_types_id) + @leave_type = EmployeeLeaveType.find(@applied_leave.employee_leave_type_id) @manager = @applied_employee.reporting_manager_id - @leave_count = EmployeeLeave.find_by_employee_id(@applied_employee.id,:conditions=> "employee_leave_type_id = '#{@leave_type.id}'") + @leave_count = EmployeeLeave.find_by_employee_id_and_employee_leave_type_id(@applied_employee.id, + @leave_type.id) end def leave_app @employee = Employee.find(params[:id2]) @applied_leave = ApplyLeave.find(params[:id]) - @leave_type = EmployeeLeaveType.find(@applied_leave.employee_leave_types_id) + @leave_type = EmployeeLeaveType.find(@applied_leave.employee_leave_type_id) @applied_employee = Employee.find(@applied_leave.employee_id) @manager = @applied_employee.reporting_manager_id end @@ -382,46 +267,26 @@ def deny_remarks end def approve_leave - @applied_leave = ApplyLeave.find(params[:applied_leave]) - @applied_employee = Employee.find(@applied_leave.employee_id) - @manager = @applied_employee.reporting_manager_id - if @applied_leave.update_attributes( :approved => true, :viewed_by_manager => true, :manager_remark => params[:manager_remark]) - start_date = @applied_leave.start_date - end_date = @applied_leave.end_date - (start_date..end_date).each do |d| - - unless(d.strftime('%A') == "Sunday") - EmployeeAttendance.create(:attendance_date=>d, :employee_id=>@applied_employee.id,:employee_leave_type_id=>@applied_leave.employee_leave_types_id, :reason => @applied_leave.reason, :is_half_day => @applied_leave.is_half_day) - att = EmployeeAttendance.find_by_attendance_date(d) - EmployeeAttendance.update(att.id, :is_half_day => @applied_leave.is_half_day) - @reset_count = EmployeeLeave.find_by_employee_id(@applied_leave.employee_id, :conditions=> "employee_leave_type_id = '#{@applied_leave.employee_leave_types_id}'") - leave_taken = @reset_count.leave_taken - if @applied_leave.is_half_day - leave_taken += 0.5 - @reset_count.update_attributes(:leave_taken=> leave_taken) - else - leave_taken += 1 - @reset_count.update_attributes(:leave_taken=> leave_taken) - end - end - end - end - - flash[:notice]="#{t('flash6')} #{@applied_employee.first_name} from #{@applied_leave.start_date} to #{@applied_leave.end_date}" - redirect_to :controller=>"employee_attendance", :action=>"leaves", :id=>@manager + applied_leave = ApplyLeave.find(params[:applied_leave]) + applied_employee = Employee.find(applied_leave.employee_id) + manager = applied_employee.reporting_manager_id + applied_leave.calculate_reset_count(params) + + flash[:notice] = "#{t('flash6')} #{applied_employee.first_name} from #{applied_leave.start_date} to #{applied_leave.end_date}" + redirect_to :action => "leaves", :id => manager end def deny_leave - @applied_leave = ApplyLeave.find(params[:applied_leave]) - @applied_employee = Employee.find(@applied_leave.employee_id) - @manager = @applied_employee.reporting_manager_id - ApplyLeave.update(@applied_leave, :viewed_by_manager => true, :manager_remark =>params[:manager_remark]) - flash[:notice]="#{t('flash7')} #{@applied_employee.first_name} from #{@applied_leave.start_date} to #{@applied_leave.end_date}" - redirect_to :action=>"leaves", :id=>@manager + applied_leave = ApplyLeave.find(params[:applied_leave]) + applied_employee = Employee.find(applied_leave.employee_id) + manager = applied_employee.reporting_manager_id + applied_leave.deny(params[:manager_remark]) + flash[:notice] = "#{t('flash7')} #{applied_employee.first_name} from #{applied_leave.start_date} to #{applied_leave.end_date}" + redirect_to :action => "leaves", :id => manager end def cancel - render :text=>"" + render :text => "" end def new_leave_applications @@ -432,7 +297,7 @@ def new_leave_applications def all_employee_new_leave_applications @employee = Employee.find(params[:id]) - @all_employees = Employee.find(:all) + @all_employees = Employee.all render :partial => "all_employee_new_leave_applications" end @@ -444,40 +309,50 @@ def all_leave_applications def individual_leave_applications @employee = Employee.find(params[:id]) - @pending_applied_leaves = ApplyLeave.find_all_by_employee_id(@employee.id, :conditions=> "approved = false AND viewed_by_manager = false", :order=>"start_date DESC") - @applied_leaves = ApplyLeave.paginate(:page => params[:page],:per_page=>10 , :conditions=>[ "employee_id = '#{@employee.id}'"], :order=>"start_date DESC") + @pending_applied_leaves = ApplyLeave.find_all_by_employee_id(@employee.id, + :conditions => {:approved => false, :viewed_by_manager => false}, + :order=>"start_date DESC") + @applied_leaves = ApplyLeave.paginate(:page => params[:page], + :per_page => 10 , + :conditions => {:employee_id => @employee.id}, + :order => "start_date DESC") render :partial => "individual_leave_applications" end def own_leave_application @applied_leave = ApplyLeave.find(params[:id]) - @leave_type = EmployeeLeaveType.find(@applied_leave.employee_leave_types_id) + @leave_type = EmployeeLeaveType.find(@applied_leave.employee_leave_type_id) @employee = Employee.find(@applied_leave.employee_id) end def cancel_application - @applied_leave = ApplyLeave.find(params[:id]) - @employee = Employee.find(@applied_leave.employee_id) - unless @applied_leave.viewed_by_manager - ApplyLeave.destroy(params[:id]) - flash[:notice] = t('flash8') + applied_leave = ApplyLeave.find(params[:id]) + employee = Employee.find(applied_leave.employee_id) + if applied_leave.viewed_by_manager + flash[:notice] = t('flash10') else - flash[:notice] = t('flash10') + ApplyLeave.destroy(params[:id]) + flash[:notice] = t('flash8') end - redirect_to :action=>"leaves", :id=>@employee.id + redirect_to :action => "leaves", :id => employee.id end def update_all_application_view if params[:employee_id] == "" render :update do |page| page.replace_html "all-application-view", :text => "" - end - return + end and return end - @employee = Employee.find(params[:employee_id]) - @all_pending_applied_leaves = ApplyLeave.find_all_by_employee_id(params[:employee_id], :conditions=> "approved = false AND viewed_by_manager = false", :order=>"start_date DESC") - @all_applied_leaves = ApplyLeave.paginate(:page => params[:page], :per_page=>10, :conditions=> ["employee_id = '#{@employee.id}'"], :order=>"start_date DESC") + @employee = Employee.find(params[:employee_id]) + @all_pending_applied_leaves = ApplyLeave.all(conditions: {employee_id: @employee.id, + approved: false, + viewed_by_manager: false}, + order: "start_date DESC") + @all_applied_leaves = ApplyLeave.paginate(:page => params[:page], + :per_page => 10, + :conditions => {:employee_id => @employee.id}, + :order=>"start_date DESC") render :update do |page| page.replace_html "all-application-view", :partial => "all_leave_application_lists" end @@ -488,18 +363,12 @@ def update_all_application_view def employee_attendance_pdf @employee = Employee.find(params[:id]) @attendance_report = EmployeeAttendance.find_all_by_employee_id(@employee.id) - @leave_types = EmployeeLeaveType.find(:all, :conditions => "status = true") - @leave_count = EmployeeLeave.find_all_by_employee_id(@employee,:joins=>:employee_leave_type,:conditions=>"status = true") - @total_leaves = 0 - @leave_types.each do |lt| - leave_count = EmployeeAttendance.find_all_by_employee_id_and_employee_leave_type_id(@employee.id,lt.id).size - @total_leaves = @total_leaves + leave_count + @leave_types = EmployeeLeaveType.all(:conditions => {:status => true}) + @leave_count = EmployeeLeave.all(:joins => :employee_leave_type, + :conditions => ["employee_leave_types.status IS TRUE AND employee_id = ?", @employee.id]) + @total_leaves = @leave_types.inject(0) do |sum, lt| + sum += EmployeeAttendance.find_all_by_employee_id_and_employee_leave_type_id(@employee.id,lt.id).size end render :pdf => 'employee_attendance_pdf' - - - # respond_to do |format| - # format.pdf { render :layout => false } - # end end end diff --git a/app/controllers/employee_attendances_controller.rb b/app/controllers/employee_attendances_controller.rb index 5d4536f4f..a3627995a 100755 --- a/app/controllers/employee_attendances_controller.rb +++ b/app/controllers/employee_attendances_controller.rb @@ -19,9 +19,9 @@ class EmployeeAttendancesController < ApplicationController before_filter :login_required,:configuration_settings_for_hr filter_access_to :all - + def index - @departments = EmployeeDepartment.find(:all, :conditions=>"status = true", :order=> "name ASC") + @departments = EmployeeDepartment.find(:all, :conditions=>{:status => true}, :order=> "name ASC") end def show @@ -43,7 +43,7 @@ def new @attendance = EmployeeAttendance.new @employee = Employee.find(params[:id2]) @date = params[:id] - @leave_types = EmployeeLeaveType.find(:all, :conditions=>"status = true", :order=>"name ASC") + @leave_types = EmployeeLeaveType.find(:all, :conditions=>{:status => true}, :order=>"name ASC") respond_to do |format| format.js {render :action => 'new'} @@ -54,7 +54,7 @@ def create @attendance = EmployeeAttendance.new(params[:employee_attendance]) @employee = Employee.find(params[:employee_attendance][:employee_id]) @date = params[:employee_attendance][:attendance_date] - @reset_count = EmployeeLeave.find_by_employee_id(@attendance.employee_id, :conditions=> "employee_leave_type_id = '#{@attendance.employee_leave_type_id}'") + @reset_count = EmployeeLeave.find_by_employee_id(@attendance.employee_id, :conditions=> {:employee_leave_type_id => @attendance.employee_leave_type_id}) if @attendance.save leaves_taken = @reset_count.leave_taken if @attendance.is_half_day @@ -75,7 +75,7 @@ def create def edit @attendance = EmployeeAttendance.find(params[:id]) @employee = Employee.find(@attendance.employee_id) - @leave_types = EmployeeLeaveType.find(:all, :conditions=>"status = true", :order=>"name ASC") + @leave_types = EmployeeLeaveType.find(:all, :conditions=>{:status => true}, :order=>"name ASC") respond_to do |format| format.js {render :action => 'edit'} end @@ -83,7 +83,7 @@ def edit def update @attendance = EmployeeAttendance.find params[:id] - @reset_count = EmployeeLeave.find_by_employee_id(@attendance.employee_id, :conditions=> "employee_leave_type_id = '#{@attendance.employee_leave_type_id}'") + @reset_count = EmployeeLeave.find_by_employee_id(@attendance.employee_id, :conditions=> {:employee_leave_type_id => @attendance.employee_leave_type_id}) leaves_taken = @reset_count.leave_taken day_status = @attendance.is_half_day leave_type = EmployeeLeaveType.find_by_id(@attendance.employee_leave_type_id) @@ -110,7 +110,7 @@ def update leave = leaves_taken.to_f-(1.0) end @reset_count.update_attributes(:leave_taken => leave) - @new_reset_count = EmployeeLeave.find_by_employee_id(@attendance.employee_id, :conditions=> "employee_leave_type_id = '#{@attendance.employee_leave_type_id}'") + @new_reset_count = EmployeeLeave.find_by_employee_id(@attendance.employee_id, :conditions=> {:employee_leave_type_id => @attendance.employee_leave_type_id}) leaves_taken = @new_reset_count.leave_taken if @attendance.is_half_day leave = leaves_taken.to_f+(0.5) @@ -129,7 +129,7 @@ def update def destroy @attendance = EmployeeAttendance.find(params[:id]) - @reset_count = EmployeeLeave.find_by_employee_id(@attendance.employee_id, :conditions=> "employee_leave_type_id = '#{@attendance.employee_leave_type_id}'") + @reset_count = EmployeeLeave.find_by_employee_id(@attendance.employee_id, :conditions=> {:employee_leave_type_id => @attendance.employee_leave_type_id}) leaves_taken = @reset_count.leave_taken if @attendance.is_half_day leave = leaves_taken.to_f-(0.5) diff --git a/app/controllers/employee_controller.rb b/app/controllers/employee_controller.rb index ab494d085..c145cde5b 100755 --- a/app/controllers/employee_controller.rb +++ b/app/controllers/employee_controller.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class EmployeeController < ApplicationController before_filter :login_required,:configuration_settings_for_hr filter_access_to :all @@ -32,13 +31,13 @@ def add_category redirect_to :controller => "employee", :action => "add_category" end end - + def edit_category @category = EmployeeCategory.find(params[:id]) employees = Employee.find(:all ,:conditions=>"employee_category_id = #{params[:id]}") if request.post? if (params[:category][:status] == 'false' and employees.blank?) or params[:category][:status] == 'true' - + if @category.update_attributes(params[:category]) unless @category.status position = EmployeePosition.find_all_by_employee_category_id(@category.id) @@ -52,7 +51,7 @@ def edit_category else flash[:warn_notice] = "

    #{t('flash2')}

    " end - + end end @@ -87,7 +86,7 @@ def add_position def edit_position @categories = EmployeeCategory.find(:all) @position = EmployeePosition.find(params[:id]) - employees = Employee.find(:all ,:conditions=>"employee_position_id = #{params[:id]}") + employees = Employee.find(:all, :conditions => { :employee_position_id => params[:id] }) if request.post? if (params[:position][:status] == 'false' and employees.blank?) or params[:position][:status] == 'true' if @position.update_attributes(params[:position]) @@ -101,9 +100,9 @@ def edit_position end def delete_position - employees = Employee.find(:all ,:conditions=>"employee_position_id = #{params[:id]}") + employees = Employee.find(:all ,:conditions => { :employee_position_id => params[:id] }) if employees.empty? - employees = ArchivedEmployee.find(:all ,:conditions=>"employee_position_id = #{params[:id]}") + employees = ArchivedEmployee.find(:all ,:conditions => { :employee_position_id => params[:id] }) end if employees.empty? EmployeePosition.find(params[:id]).destroy @@ -128,7 +127,7 @@ def add_department def edit_department @department = EmployeeDepartment.find(params[:id]) - employees = Employee.find(:all ,:conditions=>"employee_department_id = #{params[:id]}") + employees = Employee.find(:all, :conditions => { :employee_department_id => params[:id] }) if request.post? if (params[:department][:status] == 'false' and employees.blank?) or params[:department][:status] == 'true' if @department.update_attributes(params[:department]) @@ -141,9 +140,9 @@ def edit_department end def delete_department - employees = Employee.find(:all ,:conditions=>"employee_department_id = #{params[:id]}") + employees = Employee.find(:all, :conditions => { :employee_department_id => params[:id] }) if employees.empty? - employees = ArchivedEmployee.find(:all ,:conditions=>"employee_department_id = #{params[:id]}") + employees = ArchivedEmployee.find(:all, :conditions => { :employee_department_id => params[:id] }) end if employees.empty? EmployeeDepartment.find(params[:id]).destroy @@ -245,7 +244,7 @@ def add_additional_details end end end - + def change_field_priority @additional_field = AdditionalField.find(params[:id]) priority = @additional_field.priority @@ -391,7 +390,7 @@ def admission2 @employee = Employee.find(params[:id]) @selected_value = Configuration.default_country if request.post? and @employee.update_attributes(params[:employee]) - sms_setting = SmsSetting.new() + sms_setting = SmsSetting.new if sms_setting.application_sms_active and sms_setting.employee_sms_active recipient = ["#{@employee.mobile_phone}"] message = "#{t('joining_info')} #{@employee.first_name}. #{t('username')}: #{@employee.employee_number}, #{t('password')}: #{@employee.employee_number}123. #{t('change_password_after_login')}" @@ -401,7 +400,7 @@ def admission2 redirect_to :action => "admission3", :id => @employee.id end end - + def edit2 @employee = Employee.find(params[:id]) @countries = Country.find(:all) @@ -436,7 +435,7 @@ def admission3 redirect_to :action => "admission3_1", :id => @employee.id end end - + def edit3 @employee = Employee.find(params[:id]) @bank_fields = BankField.find(:all, :conditions=>"status = true") @@ -538,7 +537,7 @@ def edit_privilege redirect_to :action => 'admission4',:id => @employee.id end end - + def edit3_1 @employee = Employee.find(params[:id]) @additional_fields = AdditionalField.find(:all, :conditions=>"status = true") @@ -572,7 +571,7 @@ def admission4 flash[:notice]=t('flash25') redirect_to :controller => "payroll", :action => "manage_payroll", :id=>@employee.id end - + end def view_rep_manager @@ -764,8 +763,8 @@ def profile_pdf @bank_details = EmployeeBankDetail.find_all_by_employee_id(@employee.id) @additional_details = EmployeeAdditionalDetail.find_all_by_employee_id(@employee.id) render :pdf => 'profile_pdf' - - + + # respond_to do |format| # format.pdf { render :layout => false } # end @@ -887,7 +886,7 @@ def create_monthly_payslip flash[:warn_notice] = "#{t('flash45')} #{params[:salary_date]}" end end - + end def view_payslip @@ -1134,7 +1133,7 @@ def edit_rejected_payslip @employee_additional_categories = IndividualPayslipCategory.find_all_by_employee_id(@employee.id, :conditions=>"include_every_month = true") @new_payslip_category = IndividualPayslipCategory.find_all_by_employee_id_and_salary_date(@employee.id,nil) @user = current_user - + if request.post? salary_date = Date.parse(params[:salary_date]) @@ -1145,7 +1144,7 @@ def edit_rejected_payslip payslip_exists.each do |p| p.delete end - + params[:manage_payroll].each_pair do |k, v| row_id = EmployeeSalaryStructure.find_by_employee_id_and_payroll_category_id(@employee, k) category_name = PayrollCategory.find(k).name @@ -1171,7 +1170,7 @@ def edit_rejected_payslip :body=>body )) flash[:notice] = "#{@employee.first_name} #{t('flash27')} #{params[:salary_date]}" redirect_to :controller => "employee", :action => "profile", :id=> @employee.id - + end end def update_rejected_payslip @@ -1442,7 +1441,7 @@ def department_payslip_pdf @currency_type = Configuration.find_by_config_key("CurrencyType").config_value @salary_date = params[:salary_date] if params[:salary_date] - + render :pdf => 'department_payslip_pdf', :margin => { :top=> 10, :bottom => 10, @@ -1504,20 +1503,20 @@ def individual_payslip_pdf @net_amount = @net_non_deductionable_amount - @net_deductionable_amount render :pdf => 'individual_payslip_pdf' - + # respond_to do |format| # format.pdf { render :layout => false } # end end def employee_individual_payslip_pdf - @employee = Employee.find(:first,:conditions=>"id=#{params[:id]}") + @employee = Employee.find(:first, :conditions => { :id => params[:id] }) if @employee.blank? - @employee = ArchivedEmployee.find(:first,:conditions=>"former_id=#{params[:id]}") + @employee = ArchivedEmployee.find(:first, :conditions => { :former_id => params[:id] }) @employee.id = @employee.former_id end @bank_details = EmployeeBankDetail.find_all_by_employee_id(@employee.id) - @employee ||= ArchivedEmployee.find(:first,:conditions=>"former_id=#{params[:id]}") + @employee ||= ArchivedEmployee.find(:first, :conditions => { :former_id => params[:id] }) @department = EmployeeDepartment.find(@employee.employee_department_id).name @currency_type = Configuration.find_by_config_key("CurrencyType").config_value @category = EmployeeCategory.find(@employee.employee_category_id).name @@ -1565,7 +1564,7 @@ def employee_individual_payslip_pdf @net_deductionable_amount = @individual_category_deductionable + @deductionable_amount @net_amount = @net_non_deductionable_amount - @net_deductionable_amount - + render :pdf => 'individual_payslip_pdf' # respond_to do |format| # format.pdf { render :layout => false } diff --git a/app/controllers/event_controller.rb b/app/controllers/event_controller.rb index 28910391d..02a865803 100755 --- a/app/controllers/event_controller.rb +++ b/app/controllers/event_controller.rb @@ -19,7 +19,7 @@ class EventController < ApplicationController before_filter :login_required filter_access_to :all - + def index @events = Event.new(params[:events]) if params[:id].nil? @@ -160,7 +160,7 @@ def confirm_event end @users = User.active.find(:all) reminder_recipient_ids << @users.map(&:id) - sms_setting = SmsSetting.new() + sms_setting = SmsSetting.new if sms_setting.application_sms_active and sms_setting.event_news_sms_active recipients = [] @users.each do |u| @@ -193,7 +193,7 @@ def confirm_event end else recipients = [] - sms_setting = SmsSetting.new() + sms_setting = SmsSetting.new batch_event = BatchEvent.find_all_by_event_id(event.id) unless batch_event.empty? batch_event.each do |b| @@ -252,10 +252,10 @@ def confirm_event def cancel_event event = Event.find(params[:id]) - batch_event = BatchEvent.find(:all, :conditions=>"event_id = #{params[:id]}") - dept_event = EmployeeDepartmentEvent.find(:all, :conditions=>"event_id = #{params[:id]}") + batch_event = BatchEvent.find(:all, :conditions => { :event_id => params[:id] }) + dept_event = EmployeeDepartmentEvent.find(:all, :conditions => { :event_id => params[:id] }) event.destroy - + batch_event.each { |x| x.destroy } unless batch_event.nil? dept_event.each { |x| x.destroy } unless dept_event.nil? flash[:notice] ="#{t('flash3')}" diff --git a/app/controllers/exam_controller.rb b/app/controllers/exam_controller.rb index 615ca80b8..84bc08d65 100755 --- a/app/controllers/exam_controller.rb +++ b/app/controllers/exam_controller.rb @@ -1,27 +1,26 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class ExamController < ApplicationController before_filter :login_required before_filter :protect_other_student_data before_filter :restrict_employees_from_exam filter_access_to :all - + def index end @@ -55,7 +54,7 @@ def update_exam_form page.replace_html 'flash', :text=>'' end end - + else render(:update) do |page| page.replace_html 'flash', :text=>"

    #{t('flash_msg9')}

    " @@ -82,7 +81,7 @@ def publish unless @exams.empty? ExamGroup.update(@exam_group.id,:is_published=>true) if params[:status] == "schedule" ExamGroup.update(@exam_group.id,:result_published=>true) if params[:status] == "result" - sms_setting = SmsSetting.new() + sms_setting = SmsSetting.new if sms_setting.application_sms_active and sms_setting.exam_result_schedule_sms_active students = @batch.students students.each do |s| @@ -405,7 +404,7 @@ def generated_report2_pdf @students = @batch.students @exam_groups = ExamGroup.find(:all,:conditions=>{:batch_id=>@batch.id}) render :pdf => 'generated_report_pdf' - + # respond_to do |format| # format.pdf { render :layout => false } # end @@ -430,7 +429,7 @@ def student_batch_rank_pdf @ranked_students = @batch.find_batch_rank render :pdf => "student_batch_rank_pdf" end - + def course_rank end @@ -978,8 +977,6 @@ def student_combined_report_pdf render :pdf=>"student_combined_report_pdf"#, :show_as_html=>true end - - def select_report_type unless params[:batch_id].nil? or params[:batch_id]=="" @batch = Batch.find(params[:batch_id]) @@ -1089,9 +1086,8 @@ def generated_report4 @students = Student.find_all_by_id(params[:student]) end end - - end + def generated_report4_pdf #grouped-exam-report-for-batch if params[:student].nil? @@ -1181,14 +1177,14 @@ def previous_years_marks_overview end end - + def previous_years_marks_overview_pdf @student = Student.find(params[:student]) @all_batches = @student.all_batches render :pdf => 'previous_years_marks_overview_pdf', :orientation => 'Landscape' - - + + end def academic_report @@ -1364,7 +1360,7 @@ def update_batch end - + #GRAPHS def graph_for_generated_report @@ -1393,7 +1389,7 @@ def graph_for_generated_report end end - bargraph = BarFilled.new() + bargraph = BarFilled.new bargraph.width = 1; bargraph.colour = '#bb0000'; bargraph.dot_size = 5; @@ -1492,7 +1488,7 @@ def graph_for_previous_years_marks_overview student.all_batches.each do |b| x_labels << b.name - exam = ExamScore.new() + exam = ExamScore.new data << exam.batch_wise_aggregate(student,b) end diff --git a/app/controllers/exam_groups_controller.rb b/app/controllers/exam_groups_controller.rb index cad6f0679..a81b9bc9a 100755 --- a/app/controllers/exam_groups_controller.rb +++ b/app/controllers/exam_groups_controller.rb @@ -1,28 +1,29 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class ExamGroupsController < ApplicationController before_filter :login_required filter_access_to :all before_filter :initial_queries + before_filter :check_admin_privileges, :only => [:new] before_filter :protect_other_student_data before_filter :restrict_employees_from_exam before_filter :protect_other_batch_exams, :only => [:show, :index] + before_filter :check_employee_privileges, :only => [:show, :index, :destroy] in_place_edit_with_validation_for :exam_group, :name in_place_edit_with_validation_for :exam, :maximum_marks in_place_edit_with_validation_for :exam, :minimum_marks @@ -31,46 +32,35 @@ class ExamGroupsController < ApplicationController def index @sms_setting = SmsSetting.new @exam_groups = @batch.exam_groups - if @current_user.employee? - @user_privileges = @current_user.privileges - @employee_subjects= @current_user.employee_record.subjects.map { |n| n.id} - if @employee_subjects.empty? and !@user_privileges.map{|p| p.name}.include?('ExaminationControl') and !@user_privileges.map{|p| p.name}.include?('EnterResults') - flash[:notice] = "#{t('flash_msg4')}" - redirect_to :controller => 'user', :action => 'dashboard' - end - end end def new - @user_privileges = @current_user.privileges @cce_exam_categories = CceExamCategory.all if @batch.cce_enabled? - if !@current_user.admin? and !@user_privileges.map{|p| p.name}.include?('ExaminationControl') and !@user_privileges.map{|p| p.name}.include?('EnterResults') - flash[:notice] = "#{t('flash_msg4')}" - redirect_to :controller => 'user', :action => 'dashboard' - end end def create @exam_group = ExamGroup.new(params[:exam_group]) @exam_group.batch_id = @batch.id - @type = @exam_group.exam_type - @error=false - unless @type=="Grades" + @type = @exam_group.exam_type + @error = false + + if @type != 'Grades' params[:exam_group][:exams_attributes].each do |exam| - if exam[1][:_delete].to_s=="0" and @error==false - unless exam[1][:maximum_marks].present? + if exam[1][:_delete].to_s == '0' and @error == false + if exam[1][:maximum_marks].blank? @exam_group.errors.add_to_base("#{t('maxmarks_cant_be_blank')}") - @error=true + @error = true end - unless exam[1][:minimum_marks].present? + if exam[1][:minimum_marks].blank? @exam_group.errors.add_to_base("#{t('minmarks_cant_be_blank')}") - @error=true + @error = true end end end end - if @error==false and @exam_group.save - flash[:notice] = "#{t('flash1')}" + + if @error == false and @exam_group.save + flash[:notice] = "#{t('flash1')}" redirect_to batch_exam_groups_path(@batch) else @cce_exam_categories = CceExamCategory.all if @batch.cce_enabled? @@ -79,12 +69,12 @@ def create end def edit - @exam_group = ExamGroup.find params[:id] + @exam_group = ExamGroup.find(params[:id]) @cce_exam_categories = CceExamCategory.all if @batch.cce_enabled? end def update - @exam_group = ExamGroup.find params[:id] + @exam_group = ExamGroup.find(params[:id]) if @exam_group.update_attributes(params[:exam_group]) flash[:notice] = "#{t('flash2')}" redirect_to [@batch, @exam_group] @@ -96,40 +86,45 @@ def update def destroy @exam_group = ExamGroup.find(params[:id], :include => :exams) - if @current_user.employee? - @employee_subjects= @current_user.employee_record.subjects.map { |n| n.id} - if @employee_subjects.empty? and !@current_user.privileges.map{|p| p.name}.include?("ExaminationControl") and !@current_user.privileges.map{|p| p.name}.include?("EnterResults") - flash[:notice] = "#{t('flash_msg4')}" - redirect_to :controller => 'user', :action => 'dashboard' - end - end flash[:notice] = "#{t('flash3')}" if @exam_group.destroy redirect_to batch_exam_groups_path(@batch) end def show @exam_group = ExamGroup.find(params[:id], :include => :exams) + end + + private + + def initial_queries + @batch = Batch.find(params[:batch_id], :include => :course) unless params[:batch_id].nil? + @course = @batch.course unless @batch.nil? + end + + def check_employee_privileges if @current_user.employee? - @user_privileges = @current_user.privileges - @employee_subjects= @current_user.employee_record.subjects.map { |n| n.id} - if @employee_subjects.empty? and !@current_user.privileges.map{|p| p.name}.include?("ExaminationControl") and !@current_user.privileges.map{|p| p.name}.include?("EnterResults") + @user_privileges = @current_user.privileges + @employee_subjects = @current_user.employee_record.subject_ids + if @employee_subjects.empty? and !@user_privileges.find_by_name('ExaminationControl') and !@user_privileges.find_by_name('EnterResults') flash[:notice] = "#{t('flash_msg4')}" redirect_to :controller => 'user', :action => 'dashboard' end end end - private - def initial_queries - @batch = Batch.find params[:batch_id], :include => :course unless params[:batch_id].nil? - @course = @batch.course unless @batch.nil? + def check_admin_privileges + @user_privileges = @current_user.privileges + if !@current_user.admin? and !@user_privileges.find_by_name('ExaminationControl') and !@user_privileges.find_by_name('EnterResults') + flash[:notice] = "#{t('flash_msg4')}" + redirect_to :controller => 'user', :action => 'dashboard' + end end def protect_other_batch_exams @user_privileges = @current_user.privileges - if !@current_user.admin? and !@user_privileges.map{|p| p.name}.include?('ExaminationControl') and !@user_privileges.map{|p| p.name}.include?('EnterResults') + if !@current_user.admin? and !@user_privileges.find_by_name('ExaminationControl') and !@user_privileges.find_by_name('EnterResults') @user_subjects = @current_user.employee_record.subjects.all(:group => 'batch_id') - @user_batches = @user_subjects.map{|x|x.batch_id} unless @current_user.employee_record.blank? or @user_subjects.nil? + @user_batches = @user_subjects.map { |x| x.batch_id } unless @current_user.employee_record.blank? or @user_subjects.nil? unless @user_batches.include?(params[:batch_id].to_i) flash[:notice] = "#{t('flash_msg4')}" diff --git a/app/controllers/exam_reports_controller.rb b/app/controllers/exam_reports_controller.rb index ed10eb43e..0763f311d 100644 --- a/app/controllers/exam_reports_controller.rb +++ b/app/controllers/exam_reports_controller.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class ExamReportsController < ApplicationController before_filter :login_required @@ -250,7 +249,7 @@ def consolidated_exam_report_pdf :page_size=> 'A3' end - + private diff --git a/app/controllers/exam_scores_controller.rb b/app/controllers/exam_scores_controller.rb index fb10af258..ef8388e1b 100755 --- a/app/controllers/exam_scores_controller.rb +++ b/app/controllers/exam_scores_controller.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class ExamScoresController < ApplicationController before_filter :login_required in_place_edit_for :exam_score, :score diff --git a/app/controllers/exams_controller.rb b/app/controllers/exams_controller.rb index c4597b3c2..98777dcb6 100755 --- a/app/controllers/exams_controller.rb +++ b/app/controllers/exams_controller.rb @@ -1,36 +1,33 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class ExamsController < ApplicationController before_filter :login_required before_filter :query_data + before_filter :load_exam, :only => [:edit, :update, :show, :destroy] before_filter :protect_other_student_data - before_filter :restrict_employees_from_exam, :except=>[:edit, :destroy] - before_filter :restrict_employees_from_exam_edit, :only=>[:edit, :destroy] + before_filter :restrict_employees_from_exam, :except => [:edit, :destroy] + before_filter :restrict_employees_from_exam_edit, :only => [:edit, :destroy] filter_access_to :all def new @exam = Exam.new - @subjects = @batch.subjects - if @current_user.employee? and !@current_user.privileges.map{|m| m.name}.include?("ExaminationControl") - @subjects= Subject.find(:all,:joins=>"INNER JOIN employees_subjects ON employees_subjects.subject_id = subjects.id AND employee_id = #{@current_user.employee_record.id} AND batch_id = #{@batch.id} ") - end - @subjects.reject!{|s| (@exam_group.exams.map{|e| e.subject_id}.include?(s.id))} + load_subjects + @subjects = @subjects.not_in_exam_group(@exam_group) if @subjects.blank? flash[:notice] = "#{t('flash_msg4')}" redirect_to [@batch, @exam_group] @@ -39,96 +36,78 @@ def new def create @exam = Exam.new(params[:exam]) - @exam.exam_group_id = @exam_group.id - @error=false - unless @exam_group.exam_type=="Grades" + @exam.exam_group = @exam_group + + @error = false + + if @exam_group.exam_type != 'Grades' unless params[:exam][:maximum_marks].present? @exam.errors.add_to_base("#{t('maxmarks_cant_be_blank')}") - @error=true + @error = true end unless params[:exam][:minimum_marks].present? @exam.errors.add_to_base("#{t('minmarks_cant_be_blank')}") - @error=true + @error = true end end - if @error==false and @exam.save + + if !@error and @exam.save flash[:notice] = "#{t('flash_msg10')}" redirect_to [@batch, @exam_group] else - @subjects = @batch.subjects - if @current_user.employee? and !@current_user.privileges.map{|m| m.name}.include?("ExaminationControl") - @subjects= Subject.find(:all,:joins=>"INNER JOIN employees_subjects ON employees_subjects.subject_id = subjects.id AND employee_id = #{@current_user.employee_record.id} AND batch_id = #{@batch.id} ") - end + load_subjects render 'new' end end def edit - @exam = Exam.find params[:id], :include => :exam_group @subjects = @exam_group.batch.subjects - if @current_user.employee? and !@current_user.privileges.map{|m| m.name}.include?("ExaminationControl") - @subjects= Subject.find(:all,:joins=>"INNER JOIN employees_subjects ON employees_subjects.subject_id = subjects.id AND employee_id = #{@current_user.employee_record.id} AND batch_id = #{@batch.id} ") - unless @subjects.map{|m| m.id}.include?(@exam.subject_id) - flash[:notice] = "#{t('flash_msg4')}" - redirect_to [@batch, @exam_group] - end - end + check_for_employee_with_examination_control_access end def update - @exam = Exam.find params[:id], :include => :exam_group - if @exam.update_attributes(params[:exam]) flash[:notice] = "#{t('flash1')}" redirect_to [@exam_group, @exam] else - @subjects = @batch.subjects - if @current_user.employee? and !@current_user.privileges.map{|m| m.name}.include?("ExaminationControl") - @subjects= Subject.find(:all,:joins=>"INNER JOIN employees_subjects ON employees_subjects.subject_id = subjects.id AND employee_id = #{@current_user.employee_record.id} AND batch_id = #{@batch.id} ") - end + load_subjects render 'edit' end end def show - @employee_subjects=[] - @employee_subjects= @current_user.employee_record.subjects.map { |n| n.id} if @current_user.employee? - @exam = Exam.find params[:id], :include => :exam_group - unless @employee_subjects.include?(@exam.subject_id) or @current_user.admin? or @current_user.privileges.map{|p| p.name}.include?('ExaminationControl') or @current_user.privileges.map{|p| p.name}.include?('EnterResults') + @employee_subjects = [] + @employee_subjects = @current_user.employee_record.subject_ids if @current_user.employee? + unless @employee_subjects.include?(@exam.subject_id) or @current_user.admin? or @current_user.privileges.map(&:name).include?('ExaminationControl') or @current_user.privileges.map(&:name).include?('EnterResults') flash[:notice] = "#{t('flash_msg6')}" - redirect_to :controller=>"user", :action=>"dashboard" + redirect_to :controller => 'user', :action => 'dashboard' end + exam_subject = Subject.find(@exam.subject_id) - is_elective = exam_subject.elective_group_id - if is_elective == nil - @students = @batch.students.by_first_name - else + is_elective = exam_subject.elective_group_id + + if is_elective assigned_students = StudentsSubject.find_all_by_subject_id(exam_subject.id) @students = [] assigned_students.each do |s| student = Student.find_by_id(s.student_id) - @students.push [student.first_name, student.id, student] unless student.nil? + @students.push [student.first_name, student.id, student] if student end @ordered_students = @students.sort - @students=[] + @students = [] @ordered_students.each do|s| @students.push s[2] end + else + @students = @batch.students.by_first_name end - @config = Configuration.get_config_value('ExamResultType') || 'Marks' @grades = @batch.grading_level_list end def destroy - @exam = Exam.find params[:id], :include => :exam_group - if @current_user.employee? and !@current_user.privileges.map{|m| m.name}.include?("ExaminationControl") - @subjects= Subject.find(:all,:joins=>"INNER JOIN employees_subjects ON employees_subjects.subject_id = subjects.id AND employee_id = #{@current_user.employee_record.id} AND batch_id = #{@batch.id} ") - unless @subjects.map{|m| m.id}.include?(@exam.subject_id) - flash[:notice] = "#{t('flash_msg4')}" - redirect_to [@batch, @exam_group] and return - end - end + check_for_employee_with_examination_control_access + if @exam.destroy batch_id = @exam.exam_group.batch_id batch_event = BatchEvent.find_by_event_id_and_batch_id(@exam.event_id,batch_id) @@ -144,7 +123,7 @@ def save_scores @exam = Exam.find(params[:id]) @error= false params[:exam].each_pair do |student_id, details| - @exam_score = ExamScore.find(:first, :conditions => {:exam_id => @exam.id, :student_id => student_id} ) + @exam_score = ExamScore.find(:first, :conditions => { :exam_id => @exam.id, :student_id => student_id }) if @exam_score.nil? if details[:marks].to_f <= @exam.maximum_marks.to_f ExamScore.create do |score| @@ -169,22 +148,47 @@ def save_scores end end end + flash[:warn_notice] = "#{t('flash2')}" if @error == true - flash[:notice] = "#{t('flash3')}" if @error == false + flash[:notice] = "#{t('flash3')}" if @error == false + redirect_to [@exam_group, @exam] end - private + def query_data @exam_group = ExamGroup.find(params[:exam_group_id], :include => :batch) - @batch = @exam_group.batch - @course = @batch.course + @batch = @exam_group.batch + @course = @batch.course + end + + def load_exam + @exam = Exam.find(params[:id], :include => :exam_group) + end + + def load_subjects + @subjects = @batch.subjects + if @current_user.employee? and !@current_user.privileges.map(&:name).include?('ExaminationControl') + @subjects = Subject.find(:all, :joins => %Q{ + INNER JOIN employees_subjects ON employees_subjects.subject_id = subjects.id + AND employee_id = #{@current_user.employee_record.id} AND batch_id = #{@batch.id} }) + end + end + + def check_for_employee_with_examination_control_access + if @current_user.employee? and !@current_user.privileges.map(&:name).include?('ExaminationControl') + @subjects = Subject.find(:all, :joins => "INNER JOIN employees_subjects ON employees_subjects.subject_id = subjects.id AND employee_id = #{@current_user.employee_record.id} AND batch_id = #{@batch.id}") + unless @subjects.map(&:id).include?(@exam.subject_id) + flash[:notice] = "#{t('flash_msg4')}" + redirect_to [@batch, @exam_group] + end + end end def restrict_employees_from_exam_edit if @current_user.employee? - if !@current_user.privileges.map{|p| p.name}.include?("ExaminationControl") + if !@current_user.privileges.map{|p| p.name}.include?('ExaminationControl') flash[:notice] = "#{t('flash_msg4')}" redirect_to :back else diff --git a/app/controllers/fa_criterias_controller.rb b/app/controllers/fa_criterias_controller.rb index 5491e7640..6ae3b2ff9 100644 --- a/app/controllers/fa_criterias_controller.rb +++ b/app/controllers/fa_criterias_controller.rb @@ -1,32 +1,32 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class FaCriteriasController < ApplicationController before_filter :login_required filter_access_to :all + def index - @fa_group=FaGroup.find(params[:fa_group_id]) - @fa_criterias=@fa_group.fa_criterias + @fa_group = FaGroup.find(params[:fa_group_id]) + @fa_criterias = @fa_group.fa_criterias end def show - @fa_criteria=FaCriteria.find(params[:id]) - @descriptives=@fa_criteria.descriptive_indicators + @fa_criteria = FaCriteria.find(params[:id]) + @descriptives = @fa_criteria.descriptive_indicators end end diff --git a/app/controllers/fa_groups_controller.rb b/app/controllers/fa_groups_controller.rb index bfd8e054c..1690b1df8 100644 --- a/app/controllers/fa_groups_controller.rb +++ b/app/controllers/fa_groups_controller.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class FaGroupsController < ApplicationController before_filter :login_required filter_access_to :all @@ -110,7 +109,7 @@ def update_subject_fa_groups a=s.save end end - + # flash[:notice] = (!a ? "not saved" : "saved" ) if a flash[:notice] = "FA groups successfully assigned for the selected subject." diff --git a/app/controllers/finance_controller.rb b/app/controllers/finance_controller.rb index 3477279ed..0076b8038 100755 --- a/app/controllers/finance_controller.rb +++ b/app/controllers/finance_controller.rb @@ -1,38 +1,37 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class FinanceController < ApplicationController before_filter :login_required,:configuration_settings_for_finance filter_access_to :all - + def index @hr = Configuration.find_by_config_value("HR") end - + def automatic_transactions @cat_names = ["'Fee'","'Salary'"] FedenaPlugin::FINANCE_CATEGORY.each do |category| @cat_names << "'#{category[:category_name]}'" end @triggers = FinanceTransactionTrigger.all - @categories = FinanceTransactionCategory.find(:all ,:conditions => ["name NOT IN (#{@cat_names.join(',')}) and is_income=1 and deleted=0 "]) + @categories = FinanceTransactionCategory.all(:conditions => ['name NOT IN (?) AND is_income = ? AND deleted = ?', @cat_names.join(','), true, false]) end - + def donation @donation = FinanceDonation.new(params[:donation]) if request.post? and @donation.save @@ -50,12 +49,16 @@ def donation_edit @transaction = FinanceTransaction.find(@donation.transaction_id) if request.post? and @donation.update_attributes(params[:donation]) donor = "#{t('flash15')} #{params[:donation][:donor]}" - FinanceTransaction.update(@transaction.id, :description => params[:donation][:description], :title=>donor, :amount=>params[:donation][:amount], :transaction_date=>@donation.transaction_date) + FinanceTransaction.update(@transaction.id, + :description => params[:donation][:description], + :title => donor, + :amount => params[:donation][:amount], + :transaction_date => @donation.transaction_date) redirect_to :action => 'donors' flash[:notice] = "#{t('flash16')}" end end - + def donation_delete @donation = FinanceDonation.find(params[:id]) @transaction = FinanceTransaction.find(@donation.transaction_id) @@ -70,7 +73,6 @@ def donation_receipt_pdf @donation = FinanceDonation.find(params[:id]) @currency_type = Configuration.find_by_config_key("CurrencyType").config_value render :pdf => 'donation_receipt_pdf' - end def donors @@ -96,7 +98,7 @@ def expense_create def expense_edit @transaction = FinanceTransaction.find(params[:id]) - @categories = FinanceTransactionCategory.all(:conditions =>"name != 'Salary' and is_income = false" ) + @categories = FinanceTransactionCategory.all(:conditions => ['name != ? AND is_income = ?', 'Salary', false]) if request.post? and @transaction.update_attributes(params[:transaction]) flash[:notice] = "#{t('flash4')}" redirect_to :action=>:expense_list @@ -123,26 +125,25 @@ def expense_list_pdf @expenses = FinanceTransaction.expenses(@start_date,@end_date) render :pdf => 'expense_list_pdf' end - + def income_create - @finance_transaction = FinanceTransaction.new() + @finance_transaction = FinanceTransaction.new @categories = FinanceTransactionCategory.income_categories if @categories.empty? flash[:notice] = "#{t('flash5')}" end - if request.post? + if request.post? @finance_transaction = FinanceTransaction.new(params[:finance_transaction]) if @finance_transaction.save flash[:notice] = "#{t('flash6')}" - redirect_to :action=>"income_create" + redirect_to :action => "income_create" else - render :action=>"income_create" + render :action => "income_create" end end end def monthly_income - end def income_edit @@ -151,10 +152,10 @@ def income_edit @cat_names << "'#{category[:category_name]}'" end @transaction = FinanceTransaction.find(params[:id]) - @categories = FinanceTransactionCategory.all(:conditions => "is_income=true and name NOT IN (#{@cat_names.join(',')})") + @categories = FinanceTransactionCategory.all(:conditions => ["is_income = ? and name NOT IN (?)", true, @cat_names.join(',')]) if request.post? and @transaction.update_attributes(params[:transaction]) flash[:notice] = "#{t('flash7')}" - redirect_to :action=> 'income_list' + redirect_to :action => 'income_list' end end @@ -175,21 +176,19 @@ def delete_transaction else redirect_to :action=>'expense_list' end - - end def income_list_update @start_date = (params[:start_date]).to_date - @end_date = (params[:end_date]).to_date - @incomes = FinanceTransaction.incomes(@start_date,@end_date) + @end_date = (params[:end_date]).to_date + @incomes = FinanceTransaction.incomes(@start_date, @end_date) end def income_details @start_date = params[:start].to_date - @end_date = params[:end].to_date + @end_date = params[:end].to_date @income_category = FinanceTransactionCategory.find(params[:id]) - @incomes = @income_category.finance_transactions.find(:all,:conditions => ["transaction_date >= '#{@start_date}' and transaction_date <= '#{@end_date}'"]) + @incomes = @income_category.finance_transactions.find(:all, :conditions => { :transaction_date => @start_date..@end_date }) end def income_list_pdf @@ -197,34 +196,34 @@ def income_list_pdf @start_date = (params[:start_date]).to_date @end_date = (params[:end_date]).to_date @incomes = FinanceTransaction.incomes(@start_date,@end_date) - render :pdf => 'income_list_pdf', :zoom=>0.68#, :show_as_html=>true + render :pdf => 'income_list_pdf', :zoom => 0.68#, :show_as_html=>true end def income_details_pdf @start_date = params[:start_date].to_date @end_date = params[:end_date].to_date @income_category = FinanceTransactionCategory.find(params[:id]) - @incomes = @income_category.finance_transactions.find(:all,:conditions => ["transaction_date >= '#{@start_date}' and transaction_date <= '#{@end_date}'"]) + @incomes = @income_category.finance_transactions.find(:all, :conditions => { :transaction_date => @start_date..@end_date }) render :pdf => 'income_details_pdf' end def categories - @categories = FinanceTransactionCategory.all(:conditions => {:deleted => false},:order=>'name asc') - @fixed_categories = @categories.reject{|c|!c.is_fixed} - @other_categories = @categories.reject{|c|c.is_fixed} + @categories = FinanceTransactionCategory.all(:conditions => { :deleted => false }, :order => 'name ASC') + @fixed_categories = @categories.reject { |c| !c.fixed? } + @other_categories = @categories.reject { |c| c.fixed? } end def category_new @finance_transaction_category = FinanceTransactionCategory.new end - + def category_create @finance_category = FinanceTransactionCategory.new(params[:finance_category]) render :update do |page| if @finance_category.save @categories = FinanceTransactionCategory.all(:conditions => {:deleted => false}) - @fixed_categories = @categories.reject{|c|!c.is_fixed} - @other_categories = @categories.reject{|c|c.is_fixed} + @fixed_categories = @categories.reject { |c| !c.fixed? } + @other_categories = @categories.reject { |c| c.fixed? } page.replace_html 'form-errors', :text => '' page << "Modalbox.hide();" page.replace_html 'category-list', :partial => 'category_list' @@ -241,8 +240,8 @@ def category_delete @finance_category = FinanceTransactionCategory.find(params[:id]) @finance_category.update_attributes(:deleted => true) @categories = FinanceTransactionCategory.all(:conditions => {:deleted => false}) - @fixed_categories = @categories.reject{|c|!c.is_fixed} - @other_categories = @categories.reject{|c|c.is_fixed} + @fixed_categories = @categories.reject { |c| !c.fixed? } + @other_categories = @categories.reject { |c| c.fixed? } end def category_edit @@ -254,12 +253,12 @@ def category_update @finance_category = FinanceTransactionCategory.find(params[:id]) @finance_category.update_attributes(params[:finance_category]) @categories = FinanceTransactionCategory.all(:conditions => {:deleted => false}) - @fixed_categories = @categories.reject{|c|!c.is_fixed} - @other_categories = @categories.reject{|c|c.is_fixed} + @fixed_categories = @categories.reject { |c| !c.fixed? } + @other_categories = @categories.reject { |c| c.fixed? } end def transaction_trigger_create - @trigger = FinanceTransactionTrigger.new(params[:transaction_trigger]) + @trigger = FinanceTransactionTrigger.new(params[:transaction_trigger]) render :update do |page| if @trigger.save @triggers = FinanceTransactionTrigger.all @@ -275,8 +274,8 @@ def transaction_trigger_create end end - - + + def transaction_trigger_edit @cat_names = ["'Fee'","'Salary'"] @@ -284,7 +283,7 @@ def transaction_trigger_edit @cat_names << "'#{category[:category_name]}'" end @transaction_trigger = FinanceTransactionTrigger.find(params[:id]) - @categories = FinanceTransactionCategory.find(:all ,:conditions => ["name NOT IN (#{@cat_names.join(',')}) and is_income=1 and deleted=0 "]) + @categories = FinanceTransactionCategory.all(:conditions => ["name NOT IN (?) AND is_income = ? AND deleted = ?", @cat_names.join(','), true, false]) end def transaction_trigger_update @@ -316,14 +315,14 @@ def transaction_trigger_delete #transaction----------------------- - + def update_monthly_report fixed_category_name @hr = Configuration.find_by_config_value("HR") @start_date = (params[:start_date]).to_date @end_date = (params[:end_date]).to_date - @transactions = FinanceTransaction.find(:all, - :order => 'transaction_date desc', :conditions => ["transaction_date >= '#{@start_date}' and transaction_date <= '#{@end_date}'"]) + @transactions = FinanceTransaction.all(:order => 'transaction_date desc', + :conditions => { :transaction_date => @start_date..@end_date }) #@other_transactions = FinanceTransaction.report(@start_date,@end_date,params[:page]) @other_transaction_categories = FinanceTransaction.find(:all,params[:page], :conditions => ["transaction_date >= '#{@start_date}' and transaction_date <= '#{@end_date}'and category_id NOT IN (#{@fixed_cat_ids.join(",")})"], :order => 'transaction_date').map{|ft| ft.category}.uniq @@ -337,14 +336,14 @@ def update_monthly_report end @graph = open_flash_chart_object(960, 500, "graph_for_update_monthly_report?start_date=#{@start_date}&end_date=#{@end_date}") end - + def transaction_pdf fixed_category_name @hr = Configuration.find_by_config_value("HR") @start_date = (params[:start_date]).to_date @end_date = (params[:end_date]).to_date - @transactions = FinanceTransaction.find(:all, - :order => 'transaction_date desc', :conditions => ["transaction_date >= '#{@start_date}' and transaction_date <= '#{@end_date}'"]) + @transactions = FinanceTransaction.all(:order => 'transaction_date desc', + :conditions => { :transaction_date => @start_date..@end_date }) #@other_transactions = FinanceTransaction.report(@start_date,@end_date,params[:page]) @other_transaction_categories = FinanceTransaction.find(:all,params[:page], :conditions => ["transaction_date >= '#{@start_date}' and transaction_date <= '#{@end_date}'and category_id NOT IN (#{@fixed_cat_ids.join(",")})"], :order => 'transaction_date').map{|ft| ft.category}.uniq @@ -372,11 +371,11 @@ def salary_employee end def employee_payslip_monthly_report - + @salary_date = params[:id2] @employee = Employee.find_in_active_or_archived(params[:id]) @currency_type = Configuration.find_by_config_key("CurrencyType").config_value - + if params[:salary_date] == "" render :update do |page| page.replace_html "payslip_view", :text => "" @@ -386,21 +385,21 @@ def employee_payslip_monthly_report @monthly_payslips = MonthlyPayslip.find(:all,:conditions=>["employee_id=? AND salary_date = ?",params[:id],@salary_date],:include=>:payroll_category) @individual_payslips = IndividualPayslipCategory.find(:all,:conditions=>["employee_id=? AND salary_date = ?",params[:id],@salary_date]) @salary = Employee.calculate_salary(@monthly_payslips, @individual_payslips) - + end def donations_report month_date category_id = FinanceTransactionCategory.find_by_name("Donation").id - @donations = FinanceTransaction.find(:all,:order => 'transaction_date desc', :conditions => ["transaction_date >= '#{@start_date}' and transaction_date <= '#{@end_date}'and category_id ='#{category_id}'"]) - + @donations = FinanceTransaction.find(:all,:order => 'transaction_date desc', :conditions => ["transaction_date >= ? AND transaction_date <= ? AND category_id = ?", @start_date, @end_date, category_id]) + end def fees_report month_date fees_id = FinanceTransactionCategory.find_by_name('Fee').id @fee_collection = FinanceFeeCollection.find(:all,:joins=>"INNER JOIN finance_fees ON finance_fees.fee_collection_id = finance_fee_collections.id INNER JOIN finance_transactions ON finance_transactions.finance_id = finance_fees.id AND finance_transactions.transaction_date >= '#{@start_date}' AND finance_transactions.transaction_date <= '#{@end_date}' AND finance_transactions.category_id = #{fees_id}",:group=>"finance_fee_collections.id") - + end def batch_fees_report @@ -411,22 +410,22 @@ def batch_fees_report end def student_fees_structure - + month_date @student = Student.find(params[:id]) @components = @student.get_fee_strucure_elements - + end # approve montly payslip ---------------------- def approve_monthly_payslip @salary_dates = MonthlyPayslip.find(:all, :select => "distinct salary_date") - + end def one_click_approve - @dates = MonthlyPayslip.find_all_by_salary_date(params[:salary_date],:conditions => ["is_approved = false"]) + @dates = MonthlyPayslip.find_all_by_salary_date(params[:salary_date],:conditions => { :is_approved => false }) @salary_date = params[:salary_date] render :update do |page| page.replace_html "approve",:partial=> "one_click_approve" @@ -434,7 +433,7 @@ def one_click_approve end def one_click_approve_submit - dates = MonthlyPayslip.find_all_by_salary_date(Date.parse(params[:date]), :conditions=>["is_rejected is false"]) + dates = MonthlyPayslip.find_all_by_salary_date(Date.parse(params[:date]), :conditions => { :is_rejected => false }) dates.each do |d| d.approve(current_user.id,"Approved") @@ -449,7 +448,7 @@ def one_click_approve_submit flash[:notice] = "#{t('flash8')}" redirect_to :action => "index" - + end def employee_payslip_approve @@ -504,9 +503,9 @@ def employee_payslip_reject_form #view monthly payslip ------------------------------- def view_monthly_payslip - - @departments = EmployeeDepartment.find(:all, :conditions=>"status = true", :order=> "name ASC") - @salary_dates = MonthlyPayslip.find(:all,:select => "distinct salary_date") + + @departments = EmployeeDepartment.find(:all, :conditions => { :status => true }, :order => "name ASC") + @salary_dates = MonthlyPayslip.find(:all, :select => "distinct salary_date") if request.post? post_data = params[:payslip] unless post_data.blank? @@ -524,13 +523,13 @@ def view_monthly_payslip def view_employee_payslip @is_present_employee=true @is_present_employee=false if (Employee.find_by_id(params[:id]).nil?) - @monthly_payslips = MonthlyPayslip.find(:all,:conditions=>["employee_id=? AND salary_date = ?",params[:id],params[:salary_date]],:include=>:payroll_category) - @individual_payslips = IndividualPayslipCategory.find(:all,:conditions=>["employee_id=? AND salary_date = ?",params[:id],params[:salary_date]]) + @monthly_payslips = MonthlyPayslip.find(:all, :conditions => ["employee_id=? AND salary_date = ?", params[:id],params[:salary_date]],:include=>:payroll_category) + @individual_payslips = IndividualPayslipCategory.find(:all, :conditions => ["employee_id=? AND salary_date = ?", params[:id],params[:salary_date]]) @salary = Employee.calculate_salary(@monthly_payslips, @individual_payslips) @currency_type= Configuration.find_by_config_key("CurrencyType").config_value end - - + + def search_ajax other_conditions = "" other_conditions += " AND employee_department_id = '#{params[:employee_department_id]}'" unless params[:employee_department_id] == "" @@ -566,7 +565,7 @@ def create_liability page.visual_effect(:highlight, 'form-errors') end end - + end def edit_liability @@ -576,10 +575,10 @@ def edit_liability def update_liability @liability = Liability.find(params[:id]) @currency_type = Configuration.find_by_config_key("CurrencyType").config_value - + render :update do |page| if @liability.update_attributes(params[:liability]) - @liabilities = Liability.find(:all,:conditions => 'is_deleted = 0') + @liabilities = Liability.find(:all, :conditions => { :is_deleted => false }) page.replace_html "liability_list", :partial => "liability_list" page << "Modalbox.hide();" page.replace_html 'flash_box', :text => "

    #{t('flash_msg24')}

    " @@ -591,12 +590,12 @@ def update_liability end def view_liability - @liabilities = Liability.find(:all,:conditions => 'is_deleted = 0') + @liabilities = Liability.find(:all,:conditions => { :is_deleted => false }) @currency_type = Configuration.find_by_config_key("CurrencyType").config_value end - + def liability_pdf - @liabilities = Liability.find(:all,:conditions => 'is_deleted = 0') + @liabilities = Liability.find(:all,:conditions => { :is_deleted => false }) @currency_type = Configuration.find_by_config_key("CurrencyType").config_value render :pdf => 'liability_report_pdf' end @@ -604,7 +603,7 @@ def liability_pdf def delete_liability @liability = Liability.find(params[:id]) @liability.update_attributes(:is_deleted => true) - @liabilities = Liability.find(:all ,:conditions => 'is_deleted = 0') + @liabilities = Liability.all(:conditions => { :is_deleted => false }) @currency_type = Configuration.find_by_config_key("CurrencyType").config_value render :update do |page| page.replace_html "liability_list", :partial => "liability_list" @@ -633,12 +632,12 @@ def create_asset end def view_asset - @assets = Asset.find(:all,:conditions => 'is_deleted = 0') + @assets = Asset.find(:all,:conditions => { :is_deleted => false }) @currency_type = Configuration.find_by_config_key("CurrencyType").config_value end def asset_pdf - @assets = Asset.find(:all,:conditions => 'is_deleted = 0') + @assets = Asset.find(:all,:conditions => { :is_deleted => false }) @currency_type = Configuration.find_by_config_key("CurrencyType").config_value render :pdf => 'asset_report_pdf' end @@ -650,10 +649,10 @@ def edit_asset def update_asset @asset = Asset.find(params[:id]) @currency_type = Configuration.find_by_config_key("CurrencyType").config_value - + render :update do |page| if @asset.update_attributes(params[:asset]) - @assets = Asset.find(:all,:conditions => 'is_deleted = 0') + @assets = Asset.find(:all,:conditions => { :is_deleted => false }) page.replace_html "asset_list", :partial => "asset_list" page << "Modalbox.hide();" page.replace_html 'flash_box', :text => "

    #{t('flash_msg21')}

    " @@ -667,7 +666,7 @@ def update_asset def delete_asset @asset = Asset.find(params[:id]) @asset.update_attributes(:is_deleted => true) - @assets = Asset.all(:conditions => 'is_deleted = 0') + @assets = Asset.all(:conditions => { :is_deleted => false }) @currency_type = Configuration.find_by_config_key("CurrencyType").config_value render :update do |page| page.replace_html "asset_list", :partial => "asset_list" @@ -685,10 +684,10 @@ def master_fees @finance_fee_category = FinanceFeeCategory.new @finance_fee_particular = FinanceFeeParticular.new @batchs = Batch.active - @master_categories = FinanceFeeCategory.find(:all,:conditions=> ["is_deleted = '#{false}' and is_master = 1 and batch_id=?",params[:batch_id]]) unless params[:batch_id].blank? + @master_categories = FinanceFeeCategory.find(:all,:conditions => { :is_deleted => false, :is_master => true, :batch_id => params[:batch_id] }) unless params[:batch_id].blank? @student_categories = StudentCategory.active end - + def master_category_new @finance_fee_category = FinanceFeeCategory.new @batches = Batch.active @@ -703,7 +702,7 @@ def master_category_create unless @batches.nil? unless @batches.empty? @batches.each do |b| - @finance_fee_category = FinanceFeeCategory.new() + @finance_fee_category = FinanceFeeCategory.new @finance_fee_category.name = params[:finance_fee_category][:name] @finance_fee_category.description = params[:finance_fee_category][:description] @finance_fee_category.batch_id = b @@ -718,13 +717,13 @@ def master_category_create @finance_fee_category.valid? @error = true end - @master_categories = FinanceFeeCategory.find(:all,:conditions=> ["is_deleted = '#{false}' and is_master = 1"]) + @master_categories = FinanceFeeCategory.find(:all,:conditions=> { :is_deleted => false, :is_master => true }) respond_to do |format| format.js { render :action => 'master_category_create' } end end end - + def master_category_edit @finance_fee_category = FinanceFeeCategory.find(params[:id]) respond_to do |format| @@ -736,7 +735,7 @@ def master_category_update @finance_fee_category = FinanceFeeCategory.find(params[:id]) render :update do |page| if @finance_fee_category.update_attributes(params[:finance_fee_category]) - @master_categories = FinanceFeeCategory.find(:all, :conditions =>["is_deleted = '#{false}' and is_master = 1 and batch_id = #{@finance_fee_category.batch_id}"]) + @master_categories = FinanceFeeCategory.find(:all, :conditions => { :is_deleted => false, :is_master => true, :batch_id => @finance_fee_category.batch_id }) page.replace_html 'form-errors', :text => '' page << "Modalbox.hide();" page.replace_html 'categories', :partial => 'master_category_list' @@ -750,7 +749,7 @@ def master_category_update def master_category_particulars @finance_fee_category = FinanceFeeCategory.find(params[:id]) - @particulars = FinanceFeeParticular.paginate(:page => params[:page],:conditions => ["is_deleted = '#{false}' and finance_fee_category_id = '#{@finance_fee_category.id}' "]) + @particulars = FinanceFeeParticular.paginate(:page => params[:page],:conditions => { :is_deleted => false, :finance_fee_category_id => @finance_fee_category.id }) end def master_category_particulars_edit @finance_fee_particular= FinanceFeeParticular.find(params[:id]) @@ -766,7 +765,7 @@ def master_category_particulars_update params[:finance_fee_particular][:student_category_id]="" if params[:finance_fee_particular][:student_category_id].nil? if @feeparticulars.update_attributes(params[:finance_fee_particular]) @finance_fee_category = FinanceFeeCategory.find(@feeparticulars.finance_fee_category_id) - @particulars = FinanceFeeParticular.paginate(:page => params[:page],:conditions => ["is_deleted = '#{false}' and finance_fee_category_id = '#{@finance_fee_category.id}' "]) + @particulars = FinanceFeeParticular.paginate(:page => params[:page],:conditions => { :is_deleted => false, :finance_fee_category_id => @finance_fee_category.id }) page.replace_html 'form-errors', :text => '' page << "Modalbox.hide();" page.replace_html 'categories', :partial => 'master_particulars_list' @@ -784,7 +783,7 @@ def master_category_particulars_delete @feeparticulars = FinanceFeeParticular.find( params[:id]) @feeparticulars.update_attributes(:is_deleted => true ) @finance_fee_category = FinanceFeeCategory.find(@feeparticulars.finance_fee_category_id) - @particulars = FinanceFeeParticular.paginate(:page => params[:page],:conditions => ["is_deleted = '#{false}' and finance_fee_category_id = '#{@finance_fee_category.id}' "]) + @particulars = FinanceFeeParticular.paginate(:page => params[:page],:conditions => { :is_deleted => false, :finance_fee_category_id => @finance_fee_category.id }) respond_to do |format| format.js { render :action => 'master_category_particulars' } end @@ -793,7 +792,7 @@ def master_category_delete @finance_fee_category = FinanceFeeCategory.find(params[:id]) @finance_fee_category.update_attributes(:is_deleted => true) @finance_fee_category.delete_particulars - @master_categories = FinanceFeeCategory.find(:all, :conditions =>["is_deleted = '#{false}' and is_master = 1 and batch_id = #{@finance_fee_category.batch_id}"]) + @master_categories = FinanceFeeCategory.find(:all, :conditions => { :is_deleted => false, :is_master => true, :batch_id => @finance_fee_category.batch_id }) respond_to do |format| format.js { render :action => 'master_category_delete' } end @@ -804,7 +803,7 @@ def show_master_categories_list @finance_fee_category = FinanceFeeCategory.new @finance_fee_particular = FinanceFeeParticular.new @batches = Batch.find params[:id] unless params[:id] == "" - @master_categories = FinanceFeeCategory.find(:all,:conditions=> ["is_deleted = '#{false}' and is_master = 1 and batch_id=?",params[:id]]) + @master_categories = FinanceFeeCategory.find(:all, :conditions => { :is_deleted => false, :is_master => true, :batch_id => params[:id] }) @student_categories = StudentCategory.active render :update do |page| @@ -814,7 +813,7 @@ def show_master_categories_list end def fees_particulars_new - @fees_categories = FinanceFeeCategory.find(:all ,:conditions=> "is_deleted = 0 and is_master = 1", :order=>"name ASC") + @fees_categories = FinanceFeeCategory.find(:all, :conditions => { :is_deleted => false, :is_master => true }, :order=>"name ASC") @fees_categories.reject!{|f|f.batch.is_deleted or !f.batch.is_active } @student_categories = StudentCategory.active end @@ -861,11 +860,11 @@ def fees_particulars_create @error = true unless @finance_fee_particular.save end end - @particulars = FinanceFeeParticular.all(:conditions => {:is_deleted => false,:finance_fee_category_id => finance_fee_categories.map{|ffc| ffc.id}}) + @particulars = FinanceFeeParticular.all(:conditions => { :is_deleted => false, :finance_fee_category_id => finance_fee_categories.map{|ffc| ffc.id}}) if @error.blank? flash[:notice] = t('particulars_created_successfully') else - @fees_categories = FinanceFeeCategory.find(:all ,:conditions=> "is_deleted = 0 and is_master = 1") + @fees_categories = FinanceFeeCategory.all(:conditions=> "is_deleted = 0 and is_master = 1") @fees_categories.reject!{|f|f.batch.is_deleted or !f.batch.is_active } render :action => 'fees_particulars_new' return @@ -925,7 +924,7 @@ def fees_particulars_create2 @error = true unless @finance_fee_particular.save end end - @particulars = FinanceFeeParticular.all(:conditions => {:is_deleted => false,:finance_fee_category_id => finance_fee_categories.map{|ffc| ffc.id}}) + @particulars = FinanceFeeParticular.all(:conditions => { :is_deleted => false, :finance_fee_category_id => finance_fee_categories.map{|ffc| ffc.id}}) end @@ -933,7 +932,7 @@ def additional_fees_create_form @batches = Batch.active @student_categories = StudentCategory.active end - + def additional_fees_create batch = params[:additional_fees][:batch_id] unless params[:additional_fees][:batch_id].nil? @@ -1010,7 +1009,7 @@ def additional_fees_update if @finance_fee_category.update_attributes(:name =>params[:finance_fee_category][:name], :description =>params[:finance_fee_category][:description]) if @collection_date.update_attributes(:start_date=>params[:additional_fees][:start_date], :end_date=>params[:additional_fees][:end_date],:due_date=>params[:additional_fees][:due_date]) @collection_date.event.update_attributes(:start_date=>@collection_date.due_date.to_datetime, :end_date=>@collection_date.due_date.to_datetime) - @additional_categories = FinanceFeeCategory.find(:all, :conditions =>["is_deleted = '#{false}' and is_master = '#{false}' and batch_id = '#{@finance_fee_category.batch_id}'"]) + @additional_categories = FinanceFeeCategory.find(:all, :conditions => { :is_deleted => false, :is_master => false, :batch_id => @finance_fee_category.batch_id }) # page.replace_html 'form-errors', :text => '' # page << "Modalbox.hide();" # page.replace_html 'particulars', :partial => 'additional_fees_list' @@ -1106,7 +1105,7 @@ def add_particulars_create def student_or_student_category @student_categories = StudentCategory.active - + select_value = params[:select_value] if select_value == "category" @@ -1145,7 +1144,7 @@ def additional_particulars def add_particulars_edit @finance_fee_particulars = FeeCollectionParticular.find(params[:id]) end - + def add_particulars_update @finance_fee_particulars = FeeCollectionParticular.find(params[:id]) render :update do |page| @@ -1284,7 +1283,7 @@ def fee_collection_edit @finance_fee_collection = FinanceFeeCollection.find params[:id] end - + def fee_collection_update @user = current_user @finance_fee_collection = FinanceFeeCollection.find params[:id] @@ -1311,7 +1310,7 @@ def fee_collection_update :recipient_ids => recipient_ids, :subject=>subject, :body=>body )) - @finance_fee_collections = FinanceFeeCollection.all(:conditions => ["is_deleted = '#{false}' and batch_id = '#{@finance_fee_collection.batch_id}'"]) + @finance_fee_collections = FinanceFeeCollection.all(:conditions => { :is_deleted => false, :batch_id => @finance_fee_collection.batch_id }) page.replace_html 'form-errors', :text => '' page << "Modalbox.hide();" page.replace_html 'fee_collection_dates', :partial => 'fee_collection_list' @@ -1323,16 +1322,16 @@ def fee_collection_update else page.replace_html 'form-errors', :text => "
    " flash[:notice]="" - + end end - @finance_fee_collections = FinanceFeeCollection.all(:conditions => ["is_deleted = '#{false}' and batch_id = '#{@finance_fee_collection.batch_id}'"]) + @finance_fee_collections = FinanceFeeCollection.all(:conditions => { :is_deleted => false, :batch_id => @finance_fee_collection.batch_id }) end def fee_collection_delete @finance_fee_collection = FinanceFeeCollection.find params[:id] @finance_fee_collection.update_attributes(:is_deleted => true) - @finance_fee_collections = FinanceFeeCollection.all(:conditions => ["is_deleted = '#{false}' and batch_id = '#{@finance_fee_collection.batch_id}'"]) + @finance_fee_collections = FinanceFeeCollection.all(:conditions => { :is_deleted => false, :batch_id => @finance_fee_collection.batch_id }) end #fees_submission----------------------------------- @@ -1343,9 +1342,9 @@ def fees_submission_batch @dates = [] end - + def update_fees_collection_dates - + @batch = Batch.find(params[:batch_id]) @dates = @batch.fee_collection_dates @@ -1355,12 +1354,12 @@ def update_fees_collection_dates end def load_fees_submission_batch - + @batch = Batch.find(params[:batch_id]) @dates = FinanceFeeCollection.find(:all) @date = @fee_collection = FinanceFeeCollection.find(params[:date]) @student = Student.find(params[:student]) if params[:student] - @fee = FinanceFee.first(:conditions=>"fee_collection_id = #{@date.id}" ,:joins=>'INNER JOIN students ON finance_fees.student_id = students.id') + @fee = FinanceFee.first(:conditions => { :fee_collection_id => @date.id },:joins=>'INNER JOIN students ON finance_fees.student_id = students.id') unless @fee.nil? @student ||= @fee.student @prev_student = @student.previous_fee_student(@date.id) @@ -1370,7 +1369,7 @@ def load_fees_submission_batch unless @financefee.transaction_id.blank? @paid_fees = FinanceTransaction.find(:all,:conditions=>"FIND_IN_SET(id,\"#{@financefee.transaction_id}\")", :order=>"created_at ASC") end - @fee_category = FinanceFeeCategory.find(@fee_collection.fee_category_id,:conditions => ["is_deleted = false"]) + @fee_category = FinanceFeeCategory.find(@fee_collection.fee_category_id,:conditions => { :is_deleted => false }) @fee_particulars = @date.fees_particulars(@student) @batch_discounts = BatchFeeCollectionDiscount.find_all_by_finance_fee_collection_id(@date.id) @@ -1401,14 +1400,14 @@ def update_ajax @dates = FinanceFeeCollection.find(:all) @date = @fee_collection = FinanceFeeCollection.find(params[:date]) @student = Student.find(params[:student]) if params[:student] - @student ||= FinanceFee.first(:conditions=>"fee_collection_id = #{@date.id}",:joins=>'INNER JOIN students ON finance_fees.student_id = students.id').student + @student ||= FinanceFee.first(:conditions => { :fee_collection_id => @date.id },:joins=>'INNER JOIN students ON finance_fees.student_id = students.id').student @prev_student = @student.previous_fee_student(@date.id) @next_student = @student.next_fee_student(@date.id) @due_date = @fee_collection.due_date total_fees =0 @financefee = @student.finance_fee_by_date @date - + @fee_category = FinanceFeeCategory.find(@fee_collection.fee_category_id,:conditions => ["is_deleted IS NOT NULL"]) @fee_particulars = @date.fees_particulars(@student) @@ -1423,7 +1422,7 @@ def update_ajax @total_discount = [@batch_discounts,@student_discounts,@category_discounts].flatten.compact.map{|s| s.total_payable(@student) * s.discount(@student) / 100}.sum.to_f end @total_discount_percentage = [@batch_discounts,@student_discounts,@category_discounts].flatten.compact.map{|s| s.discount(@student)}.sum - + @fee_particulars.each do |p| total_fees += p.amount end @@ -1454,7 +1453,7 @@ def update_ajax is_paid = (params[:fees][:fees_paid].to_f == params[:total_fees].to_f) ? true : false @financefee.update_attributes(:transaction_id=>tid, :is_paid=>is_paid) - + @paid_fees = FinanceTransaction.find(:all,:conditions=>"FIND_IN_SET(id,\"#{tid}\")") else @paid_fees = FinanceTransaction.find(:all,:conditions=>"FIND_IN_SET(id,\"#{@financefee.transaction_id}\")") @@ -1466,7 +1465,7 @@ def update_ajax end render :update do |page| page.replace_html "student", :partial => "student_fees_submission" - + end end @@ -1476,11 +1475,11 @@ def student_fee_receipt_pdf @student = Student.find(params[:id]) @financefee = @student.finance_fee_by_date @date @due_date = @fee_collection.due_date - + unless @financefee.transaction_id.blank? @paid_fees = FinanceTransaction.find(:all,:conditions=>"FIND_IN_SET(id,\"#{@financefee.transaction_id}\")", :order=>"created_at ASC") end - @fee_category = FinanceFeeCategory.find(@fee_collection.fee_category_id,:conditions => ["is_deleted = false"]) + @fee_category = FinanceFeeCategory.find(@fee_collection.fee_category_id,:conditions => { :is_deleted => false }) @fee_particulars = @date.fees_particulars(@student) @currency_type = Configuration.find_by_config_key("CurrencyType").config_value @@ -1495,9 +1494,9 @@ def student_fee_receipt_pdf @total_discount = [@batch_discounts,@student_discounts,@category_discounts].flatten.compact.map{|s| s.total_payable(@student) * s.discount(@student) / 100}.sum.to_f end @total_discount_percentage = [@batch_discounts,@student_discounts,@category_discounts].flatten.compact.map{|s| s.discount(@student)}.sum - + render :pdf => 'fee_receipt_pdf' - + # respond_to do |format| # format.pdf { render :layout => false } # end @@ -1510,10 +1509,10 @@ def update_fine_ajax @dates = FinanceFeeCollection.find(:all) @date = @fee_collection = FinanceFeeCollection.find(params[:fine][:date]) @student = Student.find(params[:fine][:student]) if params[:fine][:student] - @student ||= FinanceFee.first(:conditions=>"fee_collection_id = #{@date.id}",:joins=>'INNER JOIN students ON finance_fees.student_id = students.id').student + @student ||= FinanceFee.first(:conditions => { :fee_collection_id => @date.id },:joins=>'INNER JOIN students ON finance_fees.student_id = students.id').student @prev_student = @student.previous_fee_student(@date.id) @next_student = @student.next_fee_student(@date.id) - + @financefee = @student.finance_fee_by_date @date unless @financefee.transaction_id.blank? @paid_fees = FinanceTransaction.find(:all,:conditions=>"FIND_IN_SET(id,\"#{@financefee.transaction_id}\")", :order=>"created_at ASC") @@ -1571,11 +1570,11 @@ def fees_student_dates end def fees_submission_student - + @student = Student.find(params[:id]) @date = @fee_collection = FinanceFeeCollection.find(params[:date]) @financefee = @student.finance_fee_by_date(@date) - + @due_date = @fee_collection.due_date @fee_category = FinanceFeeCategory.find(@fee_collection.fee_category_id,:conditions => ["is_deleted IS NOT NULL"]) @fee_particulars = @date.fees_particulars(@student) @@ -1594,7 +1593,7 @@ def fees_submission_student @total_discount = [@batch_discounts,@student_discounts,@category_discounts].flatten.compact.map{|s| s.total_payable(@student) * s.discount(@student) / 100}.sum.to_f end @total_discount_percentage = [@batch_discounts,@student_discounts,@category_discounts].flatten.compact.map{|s| s.discount(@student)}.sum - + render :update do |page| page.replace_html "fee_submission", :partial => "fees_submission_form" end @@ -1703,7 +1702,7 @@ def fees_submission_save #fees structure ---------------------- - + def fees_student_structure_search_logic # student search fees structure query = params[:query] unless query.length < 3 @@ -1757,7 +1756,7 @@ def student_fees_structure @fee_category = FinanceFeeCategory.find(@fee_collection.fee_category_id,:conditions => ["is_deleted IS NOT NULL"]) @fee_particulars = @fee_collection.fees_particulars(@student) end - + #fees defaulters----------------------- @@ -1800,7 +1799,7 @@ def fee_defaulters_pdf @date = FinanceFeeCollection.find(params[:date]) @students = @date.students.reject{|s| s.batch_id != @batch.id} @currency_type = Configuration.find_by_config_key("CurrencyType").config_value - + render :pdf => 'fee_defaulters_pdf' end @@ -1824,7 +1823,7 @@ def pay_fees_defaulters @total_discount = [@batch_discounts,@student_discounts,@category_discounts].flatten.compact.map{|s| s.total_payable(@student) * s.discount(@student) / 100}.sum.to_f end @total_discount_percentage = [@batch_discounts,@student_discounts,@category_discounts].flatten.compact.map{|s| s.discount(@student)}.sum - + unless @financefee.transaction_id.blank? @paid_fees = FinanceTransaction.find(:all,:conditions=>"FIND_IN_SET(id,\"#{@financefee.transaction_id}\")", :order=>"created_at ASC") end @@ -1866,7 +1865,7 @@ def pay_fees_defaulters else flash[:notice] = "#{t('flash23')}" end - + end end @@ -1892,7 +1891,7 @@ def update_defaulters_fine_ajax end def compare_report - + end def report_compare @@ -1902,8 +1901,8 @@ def report_compare @end_date = (params[:end_date]).to_date @start_date2 = (params[:start_date2]).to_date @end_date2 = (params[:end_date2]).to_date - @transactions = FinanceTransaction.find(:all, - :order => 'transaction_date desc', :conditions => ["transaction_date >= '#{@start_date}' and transaction_date <= '#{@end_date}'"]) + @transactions = FinanceTransaction.all(:order => 'transaction_date desc', + :conditions => { :transaction_date => @start_date..@end_date }) @transactions2 = FinanceTransaction.find(:all, :order => 'transaction_date desc', :conditions => ["transaction_date >= '#{@start_date2}' and transaction_date <= '#{@end_date2}'"]) @other_transaction_categories = FinanceTransaction.find(:all,params[:page], :conditions => ["transaction_date >= '#{@start_date}' and transaction_date <= '#{@end_date}'and category_id NOT IN (#{@fixed_cat_ids.join(",")})"], @@ -1933,7 +1932,7 @@ def report_compare end @graph = open_flash_chart_object(960, 500, "graph_for_compare_monthly_report?start_date=#{@start_date}&end_date=#{@end_date}&start_date2=#{@start_date2}&end_date2=#{@end_date2}") end - + def month_date @start_date = params[:start] @end_date = params[:end] @@ -1969,21 +1968,21 @@ def pdf_fee_structure @total_discount = 100 end render :pdf => 'pdf_fee_structure' - + # respond_to do |format| # format.pdf { render :layout => false } # end end #graph------------------------------------ - + def graph_for_update_monthly_report - + start_date = (params[:start_date]).to_date end_date = (params[:end_date]).to_date employees = Employee.find(:all) - + hr = Configuration.find_by_config_value("HR") donations_total = FinanceTransaction.donations_triggers(start_date,end_date) fees = FinanceTransaction.total_fees(start_date,end_date) @@ -1991,12 +1990,12 @@ def graph_for_update_monthly_report expense = FinanceTransaction.total_other_trans(start_date,end_date)[1] # other_transactions = FinanceTransaction.find(:all, # :conditions => ["transaction_date >= '#{start_date}' and transaction_date <= '#{end_date}'and category_id !='#{3}' and category_id !='#{2}'and category_id !='#{1}'"]) - + x_labels = [] data = [] largest_value =0 - + unless hr.nil? salary = Employee.total_employees_salary(employees,start_date,end_date) unless salary <= 0 @@ -2010,7 +2009,7 @@ def graph_for_update_monthly_report data << donations_total largest_value = donations_total if largest_value < donations_total end - + unless fees <= 0 x_labels << "#{t('fees_text')}" data << fees @@ -2038,7 +2037,7 @@ def graph_for_update_monthly_report largest_value = expense if largest_value < expense end - + # other_transactions.each do |trans| # x_labels << trans.title # if trans.category.is_income? and trans.master_transaction_id == 0 @@ -2051,7 +2050,7 @@ def graph_for_update_monthly_report largest_value += 500 - bargraph = BarFilled.new() + bargraph = BarFilled.new bargraph.width = 1; bargraph.colour = '#bb0000'; bargraph.dot_size = 3; @@ -2083,7 +2082,7 @@ def graph_for_update_monthly_report render :text => chart.render - + end def graph_for_compare_monthly_report @@ -2140,7 +2139,7 @@ def graph_for_compare_monthly_report largest_value = fees if largest_value < fees largest_value = fees2 if largest_value < fees2 end - + FedenaPlugin::FINANCE_CATEGORY.each do |category| transaction1 = FinanceTransaction.total_transaction_amount(category[:category_name],start_date,end_date) transaction2 = FinanceTransaction.total_transaction_amount(category[:category_name],start_date2,end_date2) @@ -2196,13 +2195,13 @@ def graph_for_compare_monthly_report largest_value += 500 - bargraph = BarFilled.new() + bargraph = BarFilled.new bargraph.width = 1; bargraph.colour = '#bb0000'; bargraph.dot_size = 3; bargraph.text = "#{t('for_the_period')} #{start_date}-#{end_date}" bargraph.values = data - bargraph2 = BarFilled.new() + bargraph2 = BarFilled.new bargraph2.width = 1; bargraph2.colour = '#000000'; bargraph2.dot_size = 3; @@ -2237,7 +2236,7 @@ def graph_for_compare_monthly_report render :text => chart.render end - + #ddnt complete this graph! def graph_for_transaction_comparison @@ -2258,7 +2257,7 @@ def graph_for_transaction_comparison x_labels = [] data1 = [] data2 = [] - + largest_value =0 unless hr.nil? @@ -2286,13 +2285,13 @@ def graph_for_transaction_comparison data << income largest_value = income if largest_value < income end - + unless expense <= 0 x_labels << "#{t('other_expense')}" data << expense largest_value = expense if largest_value < expense end - + # other_transactions.each do |trans| # x_labels << trans.title # if trans.category.is_income? and trans.master_transaction_id == 0 @@ -2305,7 +2304,7 @@ def graph_for_transaction_comparison largest_value += 500 - bargraph = BarFilled.new() + bargraph = BarFilled.new bargraph.width = 1; bargraph.colour = '#bb0000'; bargraph.dot_size = 3; @@ -2337,8 +2336,8 @@ def graph_for_transaction_comparison render :text => chart.render - - + + end #fee Discount def fee_discounts @@ -2471,7 +2470,7 @@ def student_wise_fee_discount_create @fee_discount.errors.add_to_base("#{t('fees_category_cant_blank')}") end end - + def update_master_fee_category_list @batch = Batch.find(params[:id]) diff --git a/app/controllers/grading_levels_controller.rb b/app/controllers/grading_levels_controller.rb index b750d4de2..12fc8b0f9 100755 --- a/app/controllers/grading_levels_controller.rb +++ b/app/controllers/grading_levels_controller.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class GradingLevelsController < ApplicationController before_filter :login_required filter_access_to :all diff --git a/app/controllers/news_controller.rb b/app/controllers/news_controller.rb index 0dbe3766e..669de6d79 100755 --- a/app/controllers/news_controller.rb +++ b/app/controllers/news_controller.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class NewsController < ApplicationController before_filter :login_required filter_access_to :all @@ -24,7 +23,7 @@ def add @news = News.new(params[:news]) @news.author = current_user if request.post? and @news.save - sms_setting = SmsSetting.new() + sms_setting = SmsSetting.new if sms_setting.application_sms_active students = Student.find(:all,:select=>'phone2',:conditions=>'is_sms_enabled = true') end @@ -37,7 +36,7 @@ def add_comment @cmnt = NewsComment.new(params[:comment]) @cmnt.author = current_user @cmnt.is_approved =true if @current_user.privileges.include?(Privilege.find_by_name('ManageNews')) || @current_user.admin? - @config = Configuration.find_by_config_key('EnableNewsCommentModeration') + @config = Configuration.find_by_config_key('EnableNewsCommentModeration') @cmnt.save end @@ -84,7 +83,7 @@ def view @news = News.find(params[:id]) @comments = @news.comments @is_moderator = @current_user.privileges.include?(Privilege.find_by_name('ManageNews')) || @current_user.admin? - @config = Configuration.find_by_config_key('EnableNewsCommentModeration') + @config = Configuration.find_by_config_key('EnableNewsCommentModeration') end def comment_approved diff --git a/app/controllers/observation_groups_controller.rb b/app/controllers/observation_groups_controller.rb index 0086cbb07..0820de5e2 100644 --- a/app/controllers/observation_groups_controller.rb +++ b/app/controllers/observation_groups_controller.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class ObservationGroupsController < ApplicationController before_filter :login_required filter_access_to :all diff --git a/app/controllers/observations_controller.rb b/app/controllers/observations_controller.rb index 737344c47..20d80fc08 100644 --- a/app/controllers/observations_controller.rb +++ b/app/controllers/observations_controller.rb @@ -1,27 +1,27 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class ObservationsController < ApplicationController before_filter :login_required filter_access_to :all + def show - @observation=Observation.find params[:id] - @descriptives=@observation.descriptive_indicators + @observation = Observation.find params[:id] + @descriptives = @observation.descriptive_indicators end end diff --git a/app/controllers/payroll_controller.rb b/app/controllers/payroll_controller.rb index 55cb9ac98..aff359434 100755 --- a/app/controllers/payroll_controller.rb +++ b/app/controllers/payroll_controller.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class PayrollController < ApplicationController before_filter :login_required filter_access_to :all @@ -28,7 +27,7 @@ def add_category flash[:notice]="#{t('flash1')}" redirect_to :action => "add_category" end - + end def edit_category @@ -79,7 +78,7 @@ def manage_payroll unless @independent_categories.empty? and @dependent_categories.empty? if payroll_created.empty? if request.post? - + params[:manage_payroll].each_pair do |k, v| EmployeeSalaryStructure.create(:employee_id => params[:id], :payroll_category_id => k, :amount => v['amount']) end @@ -125,7 +124,7 @@ def edit_payroll_details else EmployeeSalaryStructure.create(:employee_id => params[:id], :payroll_category_id => k, :amount => v['amount']) end - + end flash[:notice] = "#{t('data_saved_for')} #{@employee.first_name}" redirect_to :controller => "employee", :action => "profile", :id=> @employee.id diff --git a/app/controllers/ranking_levels_controller.rb b/app/controllers/ranking_levels_controller.rb index f213916ae..4f3491519 100644 --- a/app/controllers/ranking_levels_controller.rb +++ b/app/controllers/ranking_levels_controller.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class RankingLevelsController < ApplicationController before_filter :login_required @@ -101,7 +100,7 @@ def update_ranking_level end end end - + def delete_ranking_level @ranking_level = RankingLevel.find(params[:id]) @course = @ranking_level.course diff --git a/app/controllers/reminder_controller.rb b/app/controllers/reminder_controller.rb index bb28ef4c4..daf2d7d89 100755 --- a/app/controllers/reminder_controller.rb +++ b/app/controllers/reminder_controller.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class ReminderController < ApplicationController before_filter :login_required before_filter :protect_view_reminders, :only=>[:view_reminder,:mark_unread,:delete_reminder_by_recipient] diff --git a/app/controllers/scheduled_jobs_controller.rb b/app/controllers/scheduled_jobs_controller.rb index accccb8c3..1c3946830 100644 --- a/app/controllers/scheduled_jobs_controller.rb +++ b/app/controllers/scheduled_jobs_controller.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class ScheduledJobsController < ApplicationController before_filter :login_required filter_access_to :all diff --git a/app/controllers/sms_controller.rb b/app/controllers/sms_controller.rb index fdfc4620e..69419669a 100755 --- a/app/controllers/sms_controller.rb +++ b/app/controllers/sms_controller.rb @@ -1,27 +1,26 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class SmsController < ApplicationController before_filter :login_required filter_access_to :all - + def index - @sms_setting = SmsSetting.new() + @sms_setting = SmsSetting.new @parents_sms_enabled = SmsSetting.find_by_settings_key("ParentSmsEnabled") @students_sms_enabled = SmsSetting.find_by_settings_key("StudentSmsEnabled") @employees_sms_enabled = SmsSetting.find_by_settings_key("EmployeeSmsEnabled") @@ -64,13 +63,13 @@ def students if request.post? unless params[:send_sms][:student_ids].nil? student_ids = params[:send_sms][:student_ids] - sms_setting = SmsSetting.new() + sms_setting = SmsSetting.new @recipients=[] student_ids.each do |s_id| student = Student.find(s_id) guardian = student.immediate_contact if student.is_sms_enabled - if sms_setting.student_sms_active + if sms_setting.student_sms_active @recipients.push student.phone2 unless (student.phone2.nil? or student.phone2 == "") end if sms_setting.parent_sms_active @@ -92,7 +91,7 @@ def students end end end - + def list_students batch = Batch.find(params[:batch_id]) @students = Student.find_all_by_batch_id(batch.id,:conditions=>'is_sms_enabled=true') @@ -103,7 +102,7 @@ def batches if request.post? unless params[:send_sms][:batch_ids].nil? batch_ids = params[:send_sms][:batch_ids] - sms_setting = SmsSetting.new() + sms_setting = SmsSetting.new @recipients = [] batch_ids.each do |b_id| batch = Batch.find(b_id) @@ -136,7 +135,7 @@ def batches def sms_all batches = Batch.active - sms_setting = SmsSetting.new() + sms_setting = SmsSetting.new @recipients = [] batches.each do |batch| batch_students = batch.students @@ -178,7 +177,7 @@ def employees if request.post? unless params[:send_sms][:employee_ids].nil? employee_ids = params[:send_sms][:employee_ids] - sms_setting = SmsSetting.new() + sms_setting = SmsSetting.new @recipients=[] employee_ids.each do |e_id| employee = Employee.find(e_id) @@ -208,7 +207,7 @@ def departments if request.post? unless params[:send_sms][:dept_ids].nil? dept_ids = params[:send_sms][:dept_ids] - sms_setting = SmsSetting.new() + sms_setting = SmsSetting.new @recipients = [] dept_ids.each do |d_id| department = EmployeeDepartment.find(d_id) diff --git a/app/controllers/sms_settings_controller.rb b/app/controllers/sms_settings_controller.rb index a3b2be12b..15dc35187 100755 --- a/app/controllers/sms_settings_controller.rb +++ b/app/controllers/sms_settings_controller.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class SmsSettingsController < ApplicationController filter_access_to :all before_filter :login_required diff --git a/app/controllers/student_attendance_controller.rb b/app/controllers/student_attendance_controller.rb index 11941ff80..9c8c51a2d 100755 --- a/app/controllers/student_attendance_controller.rb +++ b/app/controllers/student_attendance_controller.rb @@ -1,27 +1,26 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class StudentAttendanceController < ApplicationController before_filter :login_required before_filter :only_assigned_employee_allowed before_filter :protect_other_student_data filter_access_to :all - + def index end @@ -37,7 +36,7 @@ def student if request.post? @detail_report = [] if params[:advance_search][:mode]== 'Overall' - @start_date = @batch.start_date.to_date + @start_date = @batch.started_on @end_date = Date.today unless @config.config_value == 'Daily' unless params[:advance_search][:subject_id].empty? @@ -101,13 +100,13 @@ def student end return end - + render :update do |page| page.replace_html 'report', :partial => 'report' page.replace_html 'error-container', :text => '' end end - + end def month @@ -129,11 +128,11 @@ def student_report @config = Configuration.find_by_config_key('StudentAttendanceType') @student = Student.find(params[:id]) @batch = Batch.find(params[:year]) - @start_date = @batch.start_date.to_date - @end_date = @batch.end_date.to_date + @start_date = @batch.started_on + @end_date = @batch.ended_on unless @config.config_value == 'Daily' @academic_days=@batch.subject_hours(@start_date, @end_date, 0).values.flatten.compact.count - @student_leaves = SubjectLeave.find(:all, :conditions =>{:batch_id=>@batch.id,:student_id=>@student.id,:month_date => @start_date..@end_date}) + @student_leaves = SubjectLeave.find(:all, :conditions => {:batch_id => @batch.id, :student_id => @student.id, :month_date => @start_date..@end_date}) @leaves= @student_leaves.count @leaves||=0 @attendance = (@academic_days - @leaves) diff --git a/app/controllers/student_controller.rb b/app/controllers/student_controller.rb index f31c3c59b..55f7e0739 100755 --- a/app/controllers/student_controller.rb +++ b/app/controllers/student_controller.rb @@ -1,47 +1,46 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class StudentController < ApplicationController filter_access_to :all before_filter :login_required before_filter :protect_other_student_data, :except =>[:show] - + before_filter :find_student, :only => [ :academic_report, :academic_report_all, :admission3, :change_to_former, :delete, :edit, :add_guardian, :email, :remove, :reports, :profile, :guardians, :academic_pdf,:show_previous_details,:fees,:fee_details ] - + def academic_report_all @user = current_user @prev_student = @student.previous_student @next_student = @student.next_student @course = @student.course @examtypes = ExaminationType.find( ( @course.examinations.collect { |x| x.examination_type_id } ).uniq ) - + @graph = open_flash_chart_object(965, 350, "/student/graph_for_academic_report?course=#{@course.id}&student=#{@student.id}") @graph2 = open_flash_chart_object(965, 350, "/student/graph_for_annual_academic_report?course=#{@course.id}&student=#{@student.id}") end def admission1 @student = Student.new(params[:student]) - @selected_value = Configuration.default_country + @selected_value = Configuration.default_country @application_sms_enabled = SmsSetting.find_by_settings_key("ApplicationEnabled") @last_admitted_student = Student.find(:last) @config = Configuration.find_by_config_key('AdmissionNumberAutoIncrement') @@ -60,7 +59,7 @@ def admission1 @status = @student.save end if @status - sms_setting = SmsSetting.new() + sms_setting = SmsSetting.new if sms_setting.application_sms_active and @student.is_sms_enabled recipients = [] message = "#{t('student_admission_done')} #{@student.admission_no} #{t('password_is')} #{@student.admission_no}123" @@ -93,7 +92,7 @@ def admission3 end return if params[:immediate_contact].nil? if request.post? - sms_setting = SmsSetting.new() + sms_setting = SmsSetting.new @student = Student.update(@student.id, :immediate_contact_id => params[:immediate_contact][:contact]) if sms_setting.application_sms_active and sms_setting.student_admission_sms_active and @student.is_sms_enabled recipients = [] @@ -118,7 +117,7 @@ def admission3_1 end return if params[:immediate_contact].nil? if request.post? - sms_setting = SmsSetting.new() + sms_setting = SmsSetting.new @student = Student.update(@student.id, :immediate_contact_id => params[:immediate_contact][:contact]) if sms_setting.application_sms_active and sms_setting.student_admission_sms_active and @student.is_sms_enabled recipients = [] @@ -228,12 +227,12 @@ def edit_admission4 @student = Student.find(params[:id]) @additional_fields = StudentAdditionalField.find(:all, :conditions=> "status = true") @additional_details = StudentAdditionalDetail.find_all_by_student_id(@student) - + if @additional_details.empty? redirect_to :controller => "student",:action => "admission4" , :id => @student.id end if request.post? - + params[:student_additional_details].each_pair do |k, v| row_id=StudentAdditionalDetail.find_by_student_id_and_additional_field_id(@student.id,k) unless row_id.nil? @@ -250,7 +249,7 @@ def edit_admission4 def add_additional_details @additional_details = StudentAdditionalField.find(:all, :conditions=>{:status=>true},:order=>"priority ASC") @inactive_additional_details = StudentAdditionalField.find(:all, :conditions=>{:status=>false},:order=>"priority ASC") - @additional_field = StudentAdditionalField.new + @additional_field = StudentAdditionalField.new @student_additional_field_option = @additional_field.student_additional_field_options.build if request.post? priority = 1 @@ -304,7 +303,7 @@ def edit_additional_details end def delete_additional_details - students = StudentAdditionalDetail.find(:all ,:conditions=>"additional_field_id = #{params[:id]}") + students = StudentAdditionalDetail.find(:all, :conditions => { :additional_field_id => params[:id] }) if students.blank? StudentAdditionalField.find(params[:id]).destroy @additional_details = StudentAdditionalField.find(:all, :conditions=>{:status=>true},:order=>"priority ASC") @@ -342,7 +341,7 @@ def generate_tc_pdf def generate_all_tc_pdf @ids = params[:stud] @students = @ids.map { |st_id| ArchivedStudent.find(st_id) } - + render :pdf=>'generate_all_tc_pdf' end @@ -569,7 +568,7 @@ def profile @immediate_contact = Guardian.find(@student.immediate_contact_id) \ unless @student.immediate_contact_id.nil? or @student.immediate_contact_id == '' end - + def profile_pdf @current_user = current_user @student = Student.find(params[:id]) @@ -580,7 +579,7 @@ def profile_pdf @previous_data = StudentPreviousData.find_by_student_id(@student.id) @immediate_contact = Guardian.find(@student.immediate_contact_id) \ unless @student.immediate_contact_id.nil? or @student.immediate_contact_id == '' - + render :pdf=>'profile_pdf' end @@ -588,7 +587,7 @@ def show_previous_details @previous_data = StudentPreviousData.find_by_student_id(@student.id) @previous_subjects = StudentPreviousSubjectMark.find_all_by_student_id(@student.id) end - + def show @student = Student.find_by_admission_no(params[:id]) send_data(@student.photo_data, @@ -604,7 +603,7 @@ def guardians def del_guardian @guardian = Guardian.find(params[:id]) @student = @guardian.ward - if @guardian.is_immediate_contact? + if @guardian.immediate_contact? if @guardian.destroy flash[:notice] = "#{t('flash6')}" redirect_to :controller => 'student', :action => 'admission3', :id => @student.id @@ -749,7 +748,7 @@ def advanced_search end end - + # def adv_search # @batches = [] @@ -936,7 +935,7 @@ def advanced_search_pdf end end render :pdf=>'generate_tc_pdf' - + end # def new_adv @@ -1019,7 +1018,7 @@ def fee_details @paid_fees = FinanceTransaction.find(:all,:conditions=>"FIND_IN_SET(id,\"#{@financefee.transaction_id}\")") end - @fee_category = FinanceFeeCategory.find(@fee_collection.fee_category_id,:conditions => ["is_deleted = false"]) + @fee_category = FinanceFeeCategory.find(@fee_collection.fee_category_id,:conditions => { :is_deleted => false }) @fee_particulars = @fee_collection.fees_particulars(@student) @currency_type = Configuration.find_by_config_key("CurrencyType").config_value @@ -1036,7 +1035,7 @@ def fee_details end - + # # Graphs # # def graph_for_previous_years_marks_overview @@ -1201,7 +1200,7 @@ def fee_details # end # end # - # bargraph = BarFilled.new() + # bargraph = BarFilled.new # bargraph.width = 1; # bargraph.colour = '#bb0000'; # bargraph.dot_size = 5; @@ -1275,7 +1274,7 @@ def fee_details # data2 << class_avg # end # - # bargraph = BarFilled.new() + # bargraph = BarFilled.new # bargraph.width = 1; # bargraph.colour = '#bb0000'; # bargraph.dot_size = 5; @@ -1329,7 +1328,7 @@ def fee_details # data << student.annual_weighted_marks(student.course.academic_year_id) # data2 << t # - # bargraph = BarFilled.new() + # bargraph = BarFilled.new # bargraph.width = 1; # bargraph.colour = '#bb0000'; # bargraph.dot_size = 5; diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index 070e843e2..1a7aa7585 100755 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class SubjectsController < ApplicationController before_filter :login_required filter_access_to :all diff --git a/app/controllers/timetable_controller.rb b/app/controllers/timetable_controller.rb index 7f56165f5..3c3bcea52 100755 --- a/app/controllers/timetable_controller.rb +++ b/app/controllers/timetable_controller.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class TimetableController < ApplicationController before_filter :login_required before_filter :protect_other_student_data @@ -23,7 +22,6 @@ class TimetableController < ApplicationController filter_access_to :all def new_timetable - if request.post? @timetable=Timetable.new(params[:timetable]) @error=false @@ -460,19 +458,18 @@ def work_allotment admin = EmployeeCategory.find_by_prefix('admin') admin_ids = [] admin_ids << admin.id unless admin.nil? - @employees = Employee.all(:conditions=>["employee_category_id not in (?)",admin_ids],:include=>[:employee_grade,:employees_subjects]) + @employees = Employee.all(:conditions => ['employee_category_id NOT IN (?)', admin_ids], :include => [:employee_grade, :employees_subjects]) @emp_subs = [] - @employees.map{|employee| (employee[:total_time] = ((employee.max_hours_week).to_i))} + @employees.map { |employee| (employee[:total_time] = ((employee.max_hours_week).to_i)) } if request.post? params[:employee_subjects].delete_blank - success,@error_obj = EmployeesSubject.allot_work(params[:employee_subjects]) - if success + if EmployeesSubject.allot_work(params[:employee_subjects]) flash[:notice] = t('work_allotment_success') else flash[:notice] = t('updated_with_errors') end end - @batches = Batch.active.scoped :include=>[{:subjects=>:employees},:course] + @batches = Batch.active.scoped(:include=>[{ :subjects => :employees }, :course]) @subjects = @batches.collect(&:subjects).flatten end def timetable @@ -487,7 +484,7 @@ def timetable @today = @local_tzone_time.to_date end end - + end class Hash def delete_blank diff --git a/app/controllers/timetable_entries_controller.rb b/app/controllers/timetable_entries_controller.rb index c2dbb6d01..448abd87f 100644 --- a/app/controllers/timetable_entries_controller.rb +++ b/app/controllers/timetable_entries_controller.rb @@ -1,28 +1,27 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class TimetableEntriesController < ApplicationController before_filter :login_required filter_access_to :all def new @timetable=Timetable.find(params[:timetable_id]) - + @batches = Batch.active end @@ -164,7 +163,7 @@ def tt_entry_update2 end # TimetableEntry.update(params[:tte_id], :subject_id => params[:sub_id], :employee_id => params[:emp_id]) end - + tte_from_batch_and_tt(@timetable.id) render :update do |page| page.replace_html "box", :partial=> "timetable_box" diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index 452768052..6a8ccc648 100755 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class UserController < ApplicationController layout :choose_layout before_filter :login_required, :except => [:forgot_password, :login, :set_new_password, :reset_password,:first_login_change_password] @@ -29,11 +28,11 @@ def choose_layout return 'dashboard' if action_name == 'dashboard' 'application' end - + def all @users = User.active.all end - + def list_user if params[:user_type] == 'Admin' @users = User.active.find(:all, :conditions => {:admin => true}, :order => 'first_name ASC') @@ -104,7 +103,7 @@ def list_parent_user end def change_password - + if request.post? @user = current_user if User.authenticate?(@user.username, params[:user][:old_password]) @@ -145,7 +144,7 @@ def user_change_password end end - + end end @@ -154,14 +153,14 @@ def create @user = User.new(params[:user]) if request.post? - + if @user.save flash[:notice] = "#{t('flash17')}" redirect_to :controller => 'user', :action => 'edit', :id => @user.username else flash[:notice] = "#{t('flash16')}" end - + end end @@ -174,7 +173,7 @@ def delete end redirect_to :controller => 'user' end - + def dashboard @user = current_user @config = Configuration.available_modules diff --git a/app/controllers/weekday_controller.rb b/app/controllers/weekday_controller.rb index 2a9556db0..f03f07ffa 100755 --- a/app/controllers/weekday_controller.rb +++ b/app/controllers/weekday_controller.rb @@ -1,67 +1,66 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class WeekdayController < ApplicationController before_filter :login_required + before_filter :week_array, :only => [:index, :week, :create] filter_access_to :all + def index - @batches = Batch.active + @batches = Batch.active @weekdays = Weekday.default - @day = ["#{t('sunday')}", "#{t('monday')}", "#{t('tuesday')}", "#{t('wednesday')}", "#{t('thursday')}", "#{t('friday')}", "#{t('saturday')}"] - @days = ["0", "1", "2", "3", "4", "5", "6"] end def week @batch = nil - @days = ["0", "1", "2", "3", "4", "5", "6"] - @day = ["#{t('sunday')}", "#{t('monday')}", "#{t('tuesday')}", "#{t('wednesday')}", "#{t('thursday')}", "#{t('friday')}", "#{t('saturday')}"] - if params[:batch_id] == '' + if params[:batch_id].blank? @weekdays = Weekday.default else @weekdays = Weekday.for_batch(params[:batch_id]) - @b = Batch.find params[:batch_id] + @b = Batch.find params[:batch_id] end render :update do |page| page.replace_html "weekdays", :partial => "weekdays" end end - - def create - @day = ["#{t('sunday')}", "#{t('monday')}", "#{t('tuesday')}", "#{t('wednesday')}", "#{t('thursday')}", "#{t('friday')}", "#{t('saturday')}"] - batch = params[:weekday][:batch_id] if request.post? - new_weekdays = params[:weekdays]||[] - batch = params[:weekday][:batch_id].present? ? params[:weekday][:batch_id] : nil - old = Weekday.find(:all,:conditions=>{:batch_id=>batch,:is_deleted=>false}) - batch_id = params[:weekday][:batch_id].present? ? params[:weekday][:batch_id] : 0 - old_weekdays = old.map{|w| w.weekday} - flash[:notice] = "" - (new_weekdays-old_weekdays).each do |new| + new_weekdays = params[:weekdays] || [] + batch_id = params[:weekday][:batch_id].present? ? params[:weekday][:batch_id] : nil + old = Weekday.find(:all, :conditions => { :batch_id => batch_id, :is_deleted => false }) + old_weekdays = old.map{ |w| w.weekday } + flash[:notice] = "" + (new_weekdays - old_weekdays).each do |new| Weekday.add_day(batch_id, new) end - (old_weekdays-new_weekdays).each do |week| - weekday = Weekday.find_by_weekday(week.to_s,:conditions=>{:batch_id=>batch}) + (old_weekdays - new_weekdays).each do |week| + weekday = Weekday.find_by_weekday(week.to_s, :conditions => { :batch_id => batch_id }) weekday.deactivate end flash[:notice] = "#{t('weekdays_modified')}" end redirect_to :action => "index" end + + private + + def week_array + @day = ["#{t('sunday')}", "#{t('monday')}", "#{t('tuesday')}", "#{t('wednesday')}", "#{t('thursday')}", "#{t('friday')}", "#{t('saturday')}"] + @days = ["0", "1", "2", "3", "4", "5", "6"] + end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 2201b23f8..9b01f11a8 100755 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,20 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. module ApplicationHelper def get_stylesheets @@ -158,7 +158,7 @@ def render_generic_hook h[:description] = t(hook[:description]) hooks << h end - end + end return hooks.to_json end end diff --git a/app/helpers/archived_employee_helper.rb b/app/helpers/archived_employee_helper.rb deleted file mode 100755 index 4093a848f..000000000 --- a/app/helpers/archived_employee_helper.rb +++ /dev/null @@ -1,20 +0,0 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited -# -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ -# -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - -module ArchivedEmployeeHelper -end diff --git a/app/helpers/assessment_scores_helper.rb b/app/helpers/assessment_scores_helper.rb deleted file mode 100644 index e5b9de373..000000000 --- a/app/helpers/assessment_scores_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module AssessmentScoresHelper -end diff --git a/app/helpers/assessment_tools_helper.rb b/app/helpers/assessment_tools_helper.rb deleted file mode 100644 index 7b0f20d3c..000000000 --- a/app/helpers/assessment_tools_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module AssessmentToolsHelper -end diff --git a/app/helpers/autosuggest_menu_helper.rb b/app/helpers/autosuggest_menu_helper.rb index 656764687..b7db198f8 100644 --- a/app/helpers/autosuggest_menu_helper.rb +++ b/app/helpers/autosuggest_menu_helper.rb @@ -1,20 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. module AutosuggestMenuHelper def autosuggest_menuitems diff --git a/app/helpers/cce_exam_categories_helper.rb b/app/helpers/cce_exam_categories_helper.rb deleted file mode 100644 index 5d6e1a19f..000000000 --- a/app/helpers/cce_exam_categories_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module CceExamCategoriesHelper -end diff --git a/app/helpers/cce_grade_sets_helper.rb b/app/helpers/cce_grade_sets_helper.rb deleted file mode 100644 index a4f6aec80..000000000 --- a/app/helpers/cce_grade_sets_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module CceGradeSetsHelper -end diff --git a/app/helpers/cce_reports_helper.rb b/app/helpers/cce_reports_helper.rb deleted file mode 100644 index b873d4236..000000000 --- a/app/helpers/cce_reports_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module CceReportsHelper -end diff --git a/app/helpers/cce_weightages_helper.rb b/app/helpers/cce_weightages_helper.rb deleted file mode 100644 index 108cfcc60..000000000 --- a/app/helpers/cce_weightages_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module CceWeightagesHelper -end diff --git a/app/helpers/class_designations_helper.rb b/app/helpers/class_designations_helper.rb deleted file mode 100644 index 2b85cf528..000000000 --- a/app/helpers/class_designations_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module ClassDesignationsHelper -end diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 5cbe31d81..053b0bd8c 100755 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -1,25 +1,24 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. module CoursesHelper def setup_course(course) - returning(course) do |c| + course.tap do |c| c.batches.build if c.batches.empty? end end diff --git a/app/helpers/descriptive_indicators_helper.rb b/app/helpers/descriptive_indicators_helper.rb deleted file mode 100644 index ad6a63add..000000000 --- a/app/helpers/descriptive_indicators_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module DescriptiveIndicatorsHelper -end diff --git a/app/helpers/electives_helper.rb b/app/helpers/electives_helper.rb deleted file mode 100755 index 46de5c034..000000000 --- a/app/helpers/electives_helper.rb +++ /dev/null @@ -1,20 +0,0 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited -# -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ -# -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - -module ElectivesHelper -end diff --git a/app/helpers/exam_ajax_helper.rb b/app/helpers/exam_ajax_helper.rb deleted file mode 100755 index 3904b92ee..000000000 --- a/app/helpers/exam_ajax_helper.rb +++ /dev/null @@ -1,20 +0,0 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited -# -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ -# -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - -module ExamAjaxHelper -end diff --git a/app/helpers/fa_criterias_helper.rb b/app/helpers/fa_criterias_helper.rb deleted file mode 100644 index 6cae813a0..000000000 --- a/app/helpers/fa_criterias_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module FaCriteriasHelper -end diff --git a/app/helpers/fa_groups_helper.rb b/app/helpers/fa_groups_helper.rb deleted file mode 100644 index ecbb9e50a..000000000 --- a/app/helpers/fa_groups_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module FaGroupsHelper -end diff --git a/app/helpers/observation_groups_helper.rb b/app/helpers/observation_groups_helper.rb deleted file mode 100644 index 62a667eee..000000000 --- a/app/helpers/observation_groups_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module ObservationGroupsHelper -end diff --git a/app/helpers/observations_helper.rb b/app/helpers/observations_helper.rb deleted file mode 100644 index 251a946b5..000000000 --- a/app/helpers/observations_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module ObservationsHelper -end diff --git a/app/helpers/ranking_levels_helper.rb b/app/helpers/ranking_levels_helper.rb deleted file mode 100644 index 017043d0c..000000000 --- a/app/helpers/ranking_levels_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module RankingLevelsHelper -end diff --git a/app/helpers/remote_link_renderer.rb b/app/helpers/remote_link_renderer.rb index 643b616f7..74d7c5347 100644 --- a/app/helpers/remote_link_renderer.rb +++ b/app/helpers/remote_link_renderer.rb @@ -1,29 +1,29 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class RemoteLinkRenderer < WillPaginate::LinkRenderer def prepare(collection, options, template) @remote = options.delete(:remote) || {} super end -protected + protected + def page_link(page, text, attributes = {}) - @template.link_to_remote(text, {:url => url_for(page), :method => :post,:eval_scripts=>true}.merge(@remote), attributes) + @template.link_to_remote(text, { :url => url_for(page), :method => :post, :eval_scripts =>true }.merge(@remote), attributes) end end \ No newline at end of file diff --git a/app/helpers/scheduled_jobs_helper.rb b/app/helpers/scheduled_jobs_helper.rb deleted file mode 100644 index c3b616bb7..000000000 --- a/app/helpers/scheduled_jobs_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module ScheduledJobsHelper -end diff --git a/app/helpers/sms_settings_helper.rb b/app/helpers/sms_settings_helper.rb deleted file mode 100755 index 9e7e3da40..000000000 --- a/app/helpers/sms_settings_helper.rb +++ /dev/null @@ -1,20 +0,0 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited -# -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ -# -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - -module SmsSettingsHelper -end diff --git a/app/helpers/student_attendance_helper.rb b/app/helpers/student_attendance_helper.rb deleted file mode 100755 index 91b928c87..000000000 --- a/app/helpers/student_attendance_helper.rb +++ /dev/null @@ -1,20 +0,0 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited -# -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ -# -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - -module StudentAttendanceHelper -end diff --git a/app/helpers/students_helper.rb b/app/helpers/students_helper.rb index 5f8781495..ac7b386d3 100644 --- a/app/helpers/students_helper.rb +++ b/app/helpers/students_helper.rb @@ -1,9 +1,23 @@ -# To change this template, choose Tools | Templates -# and open the template in the editor. - +# Fedena +# Copyright 2011 Foradian Technologies Private Limited +# +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. module StudentsHelper - def link_to_remove_fields(name, c) - c.hidden_field(:_destroy) + link_to_function(name, "remove_fields(this)", {:class=>"delete_button_img"}) + def link_to_remove_fields(name, c) + c.hidden_field(:_destroy) + link_to_function(name, "remove_fields(this)", { :class => "delete_button_img" }) end def link_to_add_fields(name, c, association) @@ -11,6 +25,6 @@ def link_to_add_fields(name, c, association) fields = c.fields_for(association, new_object, :child_index => "new_#{association}") do |builder| render(association.to_s.singularize + "_fields", :c => builder) end - link_to_function(name, h("add_fields(this, \"#{association}\", \"#{escape_javascript(fields)}\")"),{:class=>"add_button_img"}) + link_to_function(name, h("add_fields(this, \"#{association}\", \"#{escape_javascript(fields)}\")"),{ :class => "add_button_img" }) end end diff --git a/app/helpers/timetable_entries_helper.rb b/app/helpers/timetable_entries_helper.rb deleted file mode 100644 index 11ea434a5..000000000 --- a/app/helpers/timetable_entries_helper.rb +++ /dev/null @@ -1,20 +0,0 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited -# -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ -# -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - -module TimetableEntriesHelper -end diff --git a/app/helpers/timetables_helper.rb b/app/helpers/timetables_helper.rb index 0b1ac0c97..08753f78f 100644 --- a/app/helpers/timetables_helper.rb +++ b/app/helpers/timetables_helper.rb @@ -1,55 +1,59 @@ +# Fedena +# Copyright 2011 Foradian Technologies Private Limited +# +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. module TimetablesHelper - def formatted_timetable_cell(tt) - ## Produces view for one particular timetable entry cell - unless tt.blank? - unless tt.subject.blank? - "#{tt.subject.code}\n" - end + def subject_code(tte) + if tte && tte.subject.present? + "#{tte.subject.code}\n" end end - def formatted_timetable_cell_2(tt,emp) - ## Produces view for one particular timetable entry cell - unless tt.blank? - unless tt.subject.blank? - unless tt.subject.elective_group.nil? - sub=tt.subject.elective_group.subjects.select{|s| s.employees.include?(emp)} - "#{sub.first.code}\n" unless sub.empty? - else - "#{tt.subject.code}\n" - end - end + + def subject_name(tte) + if tte && tte.subject.present? + "#{tte.subject.name}\n" end end - def subject_name(tt) - ## Produces view for one particular timetable entry cell - unless tt.blank? - unless tt.subject.blank? - "#{tt.subject.name}\n" + + def elective_subject_code(tte, emp) + if tte && tte.subject.present? + if tte.subject.elective_group.present? + sub = tte.subject.elective_group.subjects.select { |s| s.employees.include?(emp) } + "#{sub.first.code}\n" unless sub.empty? + else + "#{tte.subject.code}\n" end end end - def timetable_batch(tt) - ## Produces view for one particular timetable entry cell - unless tt.blank? - unless tt.batch.blank? - "#{tt.batch.full_name}" - end + + def timetable_batch(tte) + if tte && tte.batch.present? + "#{tte.batch.full_name}" end end - def employee_name(tt) - ## Produces view for one particular timetable entry cell - unless tt.blank? - unless tt.employee.blank? - "#{tt.employee.first_name}" - end + + def employee_name(tte) + if tte && tte.employee.present? + "#{tte.employee.first_name}" end end - def employee_full_name(tt) - ## Produces view for one particular timetable entry cell - unless tt.blank? - unless tt.employee.blank? - "#{tt.employee.full_name}" - end + + def employee_full_name(tte) + if tte && tte.employee.present? + "#{tte.employee.full_name}" end end end \ No newline at end of file diff --git a/app/models/additional_field.rb b/app/models/additional_field.rb index 24952aa70..f0132c964 100755 --- a/app/models/additional_field.rb +++ b/app/models/additional_field.rb @@ -1,25 +1,24 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class AdditionalField < ActiveRecord::Base has_many :additional_field_options, :dependent=>:destroy validates_presence_of :name - validates_format_of :name, :with => /^[^~`@%$*()\-\[\]{}"':;\/.,\\=+|]*$/i, + validates_format_of :name, :with => /\A[^~`@%$*()\-\[\]{}"':;\/.,\\=+|]*\z/i, :message => "#{t('must_contain_only_letters_numbers_space')}" validates_uniqueness_of :name,:case_sensitive => false diff --git a/app/models/additional_field_option.rb b/app/models/additional_field_option.rb index 127885d67..21f6ecefd 100644 --- a/app/models/additional_field_option.rb +++ b/app/models/additional_field_option.rb @@ -1,5 +1,5 @@ class AdditionalFieldOption < ActiveRecord::Base - belongs_to :additional_field + belongs_to :school end diff --git a/app/models/archived_employee.rb b/app/models/archived_employee.rb index c03c2c9a5..95b757d49 100755 --- a/app/models/archived_employee.rb +++ b/app/models/archived_employee.rb @@ -1,36 +1,34 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class ArchivedEmployee < ActiveRecord::Base belongs_to :employee_category belongs_to :employee_position belongs_to :employee_grade belongs_to :employee_department belongs_to :nationality, :class_name => 'Country' - has_many :archived_employee_bank_details - has_many :archived_employee_additional_details - before_save :status_false + has_many :archived_employee_bank_details, :foreign_key => 'employee_id' + has_many :archived_employee_additional_details, :foreign_key => 'employee_id' + before_save :set_status_false - def status_false - unless self.status==0 - self.status=0 - end - end + has_attached_file :photo, + :styles => { :thumb => '100x100#', :small => '150x150>' }, + :url => '/system/:class/:attachment/:id/:style/:basename.:extension', + :path => ':rails_root/public/system/:class/:attachment/:id/:style/:basename.:extension' def image_file=(input_data) return if input_data.blank? @@ -39,16 +37,15 @@ def image_file=(input_data) self.photo_data = input_data.read end - - has_attached_file :photo, - :styles => { - :thumb=> "100x100#", - :small => "150x150>"}, - :url => "/system/:class/:attachment/:id/:style/:basename.:extension", - :path => ":rails_root/public/system/:class/:attachment/:id/:style/:basename.:extension" - def full_name "#{first_name} #{middle_name} #{last_name}" end + private + + def set_status_false + self.status = false unless status? + true + end + end diff --git a/app/models/archived_employee_additional_detail.rb b/app/models/archived_employee_additional_detail.rb index dfefd69c6..87d95ed6b 100755 --- a/app/models/archived_employee_additional_detail.rb +++ b/app/models/archived_employee_additional_detail.rb @@ -1,22 +1,21 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class ArchivedEmployeeAdditionalDetail < ActiveRecord::Base - belongs_to :archived_employee + belongs_to :archived_employee, :foreign_key => 'employee_id' belongs_to :additional_field end diff --git a/app/models/archived_employee_bank_detail.rb b/app/models/archived_employee_bank_detail.rb index 9ca4a63e7..3a4daf32f 100755 --- a/app/models/archived_employee_bank_detail.rb +++ b/app/models/archived_employee_bank_detail.rb @@ -1,22 +1,21 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class ArchivedEmployeeBankDetail < ActiveRecord::Base - belongs_to :archived_employee + belongs_to :archived_employee, :foreign_key => 'employee_id' belongs_to :bank_field end diff --git a/app/models/archived_employee_salary_structure.rb b/app/models/archived_employee_salary_structure.rb index d85582013..44bcbdc69 100755 --- a/app/models/archived_employee_salary_structure.rb +++ b/app/models/archived_employee_salary_structure.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class ArchivedEmployeeSalaryStructure < ActiveRecord::Base - has_many :payroll_categories + has_many :payroll_categories end diff --git a/app/models/archived_exam_score.rb b/app/models/archived_exam_score.rb index 9f5f340cc..dfd0053ea 100755 --- a/app/models/archived_exam_score.rb +++ b/app/models/archived_exam_score.rb @@ -1,78 +1,69 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class ArchivedExamScore < ActiveRecord::Base belongs_to :student belongs_to :exam belongs_to :grading_level - - before_save :calculate_grade def calculate_percentage percentage = self.marks.to_i * 100 / self.exam.maximum_marks end - def grouped_exam_subject_total(subject,student,type,batch = "") - if batch == "" - batch = student.batch.id - end + def grouped_exam_subject_total(subject ,student ,type ,batch = "") + batch = student.batch_id if batch.blank? + if type == 'grouped' grouped_exams = GroupedExam.find_all_by_batch_id(batch) exam_groups = [] grouped_exams.each do |x| eg = ExamGroup.find(x.exam_group_id) - exam_groups.push ExamGroup.find(x.exam_group_id) + exam_groups << eg if eg end else exam_groups = ExamGroup.find_all_by_batch_id(batch) end + total_marks = 0 exam_groups.each do |exam_group| - unless exam_group.exam_type == 'Grades' + if exam_group.exam_type != 'Grades' exam = Exam.find_by_subject_id_and_exam_group_id(subject.id,exam_group.id) - unless exam.nil? - exam_score = ArchivedExamScore.find_by_student_id(student.id, :conditions=>{:exam_id=>exam.id}) - total_marks = total_marks+ (exam_score.marks || 0) unless exam_score.nil? + if exam.present? + exam_score = ArchivedExamScore.find_by_student_id(student.id, :conditions=>{:exam_id => exam.id}) + + total_marks = total_marks + (exam_score.marks || 0) unless exam_score.nil? end end end total_marks end - def batch_wise_aggregate(student,batch) check = ExamGroup.find_all_by_batch_id(batch.id) var = [] - check.each do |x| - if x.exam_type == 'Grades' - var << 1 - end - end + check.each {|x| var << 1 if x.exam_type == 'Grades' } if var.empty? grouped_exam = GroupedExam.find_all_by_batch_id(batch.id) if grouped_exam.empty? exam_groups = ExamGroup.find_all_by_batch_id(batch.id) else exam_groups = [] - grouped_exam.each do |x| - exam_groups.push ExamGroup.find(x.exam_group_id) - end + grouped_exam.each {|x| exam_groups << ExamGroup.find(x.exam_group_id)} end exam_groups.size max_total = 0 @@ -81,21 +72,21 @@ def batch_wise_aggregate(student,batch) max_total = max_total + exam_group.archived_total_marks(student)[1] marks_total = marks_total + exam_group.archived_total_marks(student)[0] end - aggr = (marks_total*100/max_total) unless max_total ==0 + aggr = (marks_total * 100 / max_total) unless max_total ==0 else - aggr = 'nil' + aggr = nil end - end private + def calculate_grade exam = self.exam exam_group = exam.exam_group exam_type = exam_group.exam_type student_batch = ArchivedStudent.find(self.student_id).batch_id - unless exam_type == 'Grades' - unless self.marks.nil? + if exam_type != 'Grades' + if self.marks.present? percent_score = self.marks.to_i * 100 / self.exam.maximum_marks grade = GradingLevel.percentage_to_grade(percent_score, student_batch) self.grading_level_id = grade.id if exam_type == 'MarksAndGrades' @@ -104,5 +95,4 @@ def calculate_grade end end end - end diff --git a/app/models/archived_guardian.rb b/app/models/archived_guardian.rb index 34c56e08d..5c55e5968 100755 --- a/app/models/archived_guardian.rb +++ b/app/models/archived_guardian.rb @@ -1,32 +1,29 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class ArchivedGuardian < ActiveRecord::Base belongs_to :country belongs_to :ward, :class_name => 'ArchivedStudent' - - def full_name "#{first_name} #{last_name}" end - def is_immediate_contact? + def immediate_contact? ward.immediate_contact_id == id end end \ No newline at end of file diff --git a/app/models/archived_student.rb b/app/models/archived_student.rb index 7bd59e2ca..0497d1422 100755 --- a/app/models/archived_student.rb +++ b/app/models/archived_student.rb @@ -1,25 +1,24 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class ArchivedStudent < ActiveRecord::Base include CceReportMod - + belongs_to :country belongs_to :batch belongs_to :student_category @@ -29,14 +28,12 @@ class ArchivedStudent < ActiveRecord::Base has_many :students_subjects, :primary_key=>:former_id, :foreign_key=>'student_id' has_many :subjects ,:through => :students_subjects - + has_many :cce_reports, :primary_key=>:former_id, :foreign_key=>'student_id' has_many :assessment_scores, :primary_key=>:former_id, :foreign_key=>'student_id' has_many :exam_scores, :primary_key=>:former_id, :foreign_key=>'student_id' - before_save :is_active_false - - #has_and_belongs_to_many :graduated_batches, :class_name => 'Batch', :join_table => 'batch_students',:foreign_key => 'student_id' ,:finder_sql =>'SELECT * FROM `batches`,`archived_students` INNER JOIN `batch_students` ON `batches`.id = `batch_students`.batch_id WHERE (`batch_students`.student_id = `archived_students`.former_id )' + before_save :inactive_student has_attached_file :photo, :styles => { @@ -45,10 +42,9 @@ class ArchivedStudent < ActiveRecord::Base :url => "/system/:class/:attachment/:id/:style/:basename.:extension", :path => ":rails_root/public/system/:class/:attachment/:id/:style/:basename.:extension" - def is_active_false - unless self.is_active==0 - self.is_active=0 - end + def inactive_student + self.is_active = false + true end def gender_as_text @@ -64,23 +60,23 @@ def full_name end def immediate_contact - ArchivedGuardian.find(self.immediate_contact_id) unless self.immediate_contact_id.nil? + ArchivedGuardian.find(self.immediate_contact_id) if self.immediate_contact_id.present? end def all_batches - self.graduated_batches + self.batch.to_a + self.graduated_batches + [self.batch] end def graduated_batches - # SELECT * FROM `batches` INNER JOIN `batch_students` ON `batches`.id = `batch_students`.batch_id - Batch.find(:all,:conditions=> ["batch_students.student_id = #{former_id.to_i}"], :joins =>'INNER JOIN batch_students ON batches.id = batch_students.batch_id' ) + # SELECT * FROM batches INNER JOIN batch_students ON batches.id = batch_students.batch_id + Batch.find(:all,:conditions=> ["batch_students.student_id = ?", former_id], :joins =>'INNER JOIN batch_students ON batches.id = batch_students.batch_id' ) end - def additional_detail(additional_field) - StudentAdditionalDetail.find_by_additional_field_id_and_student_id(additional_field,self.former_id) + def additional_detail(additional_field_id) + StudentAdditionalDetail.find_by_additional_field_id_and_student_id(additional_field_id, self.former_id) end - def has_retaken_exam(subject_id) + def has_retaken_exam?(subject_id) retaken_exams = PreviousExamScore.find_all_by_student_id(self.former_id) if retaken_exams.empty? return false @@ -91,7 +87,6 @@ def has_retaken_exam(subject_id) end return false end - end -end \ No newline at end of file +end diff --git a/app/models/assessment_score.rb b/app/models/assessment_score.rb index 03eb74579..ec5ac3b0c 100644 --- a/app/models/assessment_score.rb +++ b/app/models/assessment_score.rb @@ -1,26 +1,26 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class AssessmentScore < ActiveRecord::Base belongs_to :student belongs_to :descriptive_indicator belongs_to :exam - named_scope :co_scholastic, {:conditions=>{:exam_id=>nil}} - named_scope :scholastic, {:conditions=>['exam_id > 0']} + named_scope :co_scholastic, :conditions => { :exam_id => nil } + named_scope :scholastic, :conditions => ['exam_id > 0'] # belongs_to :cce_grade end diff --git a/app/models/assessment_tool.rb b/app/models/assessment_tool.rb index 38efa03ba..c1e12e382 100644 --- a/app/models/assessment_tool.rb +++ b/app/models/assessment_tool.rb @@ -1,20 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class AssessmentTool < ActiveRecord::Base # belongs_to :descriptive_indicator # has_many :assessment_scores diff --git a/app/models/attendance.rb b/app/models/attendance.rb index 56fe18f86..d51b29b34 100755 --- a/app/models/attendance.rb +++ b/app/models/attendance.rb @@ -1,56 +1,45 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class Attendance < ActiveRecord::Base belongs_to :student belongs_to :batch - validates_presence_of :reason,:month_date,:batch_id,:student_id - validates_uniqueness_of :student_id, :scope => [:month_date],:message=>"already marked as absent" - named_scope :by_month, lambda { |d| { :conditions => { :month_date => d.beginning_of_month..d.end_of_month } } } - named_scope :by_month_and_batch, lambda { |d,b| {:conditions => { :month_date => d.beginning_of_month..d.end_of_month,:batch_id=>b } } } - #validate :student_current_batch + validates_presence_of :reason, :month_date, :batch_id, :student_id + validates_uniqueness_of :student_id, :scope => [:month_date], :message => "already marked as absent" + named_scope :by_month, lambda { |d| { :conditions => { :month_date => d.beginning_of_month..d.end_of_month } } } + named_scope :by_month_and_batch, lambda { |d, b| { :conditions => { :month_date => d.beginning_of_month..d.end_of_month, :batch_id => b } } } + validate :student_current_batch, :valid_month_date - def validate - unless self.student.nil? - if self.student.batch_id == self.batch_id - return true - else - errors.add('batch_id',"attendance is not marked for present batch") - return false - end - end + def full_day? + forenoon? && afternoon? end - def after_validate - unless self.month_date.nil? - errors.add("#{t('attendance_before_the_date_of_admission')}") if self.student.present? and self.month_date < self.student.admission_date - else - errors.add("#{t('month_date_cant_be_blank')}") - end + def half_day? + forenoon? || afternoon? end - def is_full_day - forenoon == true and afternoon == true - end + private - def is_half_day - forenoon == true or afternoon == true - end - + def student_current_batch + errors.add('batch_id', "attendance is not marked for present batch") if student && student.batch_id != batch_id + end + + def valid_month_date + errors.add('month_date', "#{t('attendance_before_the_date_of_admission')}") if month_date && student && month_date < student.admission_date + end end \ No newline at end of file diff --git a/app/models/batch.rb b/app/models/batch.rb index ab31374c1..c84261158 100755 --- a/app/models/batch.rb +++ b/app/models/batch.rb @@ -1,23 +1,22 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class Batch < ActiveRecord::Base - GRADINGTYPES = {"1"=>"GPA","2"=>"CWA","3"=>"CCE"} + GRADINGTYPES = { '1' => 'GPA', '2' => 'CWA', '3' => 'CCE' } belongs_to :course @@ -26,42 +25,41 @@ class Batch < ActiveRecord::Base has_many :grouped_batches has_many :archived_students has_many :grading_levels, :conditions => { :is_deleted => false } - has_many :subjects, :conditions => { :is_deleted => false } - has_many :employees_subjects, :through =>:subjects + has_many :subjects, :conditions => { :is_deleted => false } + has_many :employees_subjects, :through => :subjects has_many :exam_groups - has_many :fee_category , :class_name => "FinanceFeeCategory" + has_many :fee_category, :class_name => 'FinanceFeeCategory' has_many :elective_groups has_many :finance_fee_collections has_many :finance_transactions, :through => :students has_many :batch_events - has_many :events , :through =>:batch_events - has_many :batch_fee_discounts , :foreign_key => 'receiver_id' - has_many :student_category_fee_discounts , :foreign_key => 'receiver_id' + has_many :events, :through => :batch_events + has_many :batch_fee_discounts, :foreign_key => 'receiver_id' + has_many :student_category_fee_discounts, :foreign_key => 'receiver_id' has_many :attendances has_many :subject_leaves has_many :timetable_entries has_many :cce_reports has_many :assessment_scores - has_and_belongs_to_many :graduated_students, :class_name => 'Student', :join_table => 'batch_students' delegate :course_name,:section_name, :code, :to => :course delegate :grading_type, :cce_enabled?, :observation_groups, :cce_weightages, :to=>:course - validates_presence_of :name, :start_date, :end_date + validates_presence_of :name, :started_on, :ended_on attr_accessor :job_type - named_scope :active,{ :conditions => { :is_deleted => false, :is_active => true },:joins=>:course,:select=>"`batches`.*,CONCAT(courses.code,'-',batches.name) as course_full_name",:order=>"course_full_name"} - named_scope :inactive,{ :conditions => { :is_deleted => false, :is_active => false },:joins=>:course,:select=>"`batches`.*,CONCAT(courses.code,'-',batches.name) as course_full_name",:order=>"course_full_name"} - named_scope :deleted,{:conditions => { :is_deleted => true },:joins=>:course,:select=>"`batches`.*,CONCAT(courses.code,'-',batches.name) as course_full_name",:order=>"course_full_name"} - named_scope :cce, {:select => "batches.*",:joins => :course,:conditions=>["courses.grading_type = #{GRADINGTYPES.invert["CCE"]}"],:order=>:code} + named_scope :active, { :conditions => { :is_deleted => false, :is_active => true }, :joins => :course, :select => 'batches.*, CONCAT(courses.code, "-", batches.name) AS course_full_name', :order => 'course_full_name' } + named_scope :inactive, { :conditions => { :is_deleted => false, :is_active => false }, :joins => :course, :select => 'batches.*, CONCAT(courses.code, "-", batches.name) AS course_full_name', :order => 'course_full_name' } + named_scope :deleted, { :conditions => { :is_deleted => true }, :joins => :course, :select => 'batches.*, CONCAT(courses.code, "-", batches.name) AS course_full_name', :order => 'course_full_name' } + named_scope :cce, { :select => 'batches.*', :joins => :course, :conditions => ['courses.grading_type = ?', GRADINGTYPES.invert['CCE']], :order => :code } def validate - errors.add(:start_date, "#{t('should_be_before_end_date')}.") \ - if self.start_date > self.end_date \ - if self.start_date and self.end_date + if self.started_on && self.ended_on && self.started_on > self.ended_on + errors.add(:started_on, "#{t('should_be_before_end_date')}.") + end end def full_name @@ -71,7 +69,7 @@ def full_name def course_section_name "#{course_name} - #{section_name}" end - + def inactivate update_attribute(:is_deleted, true) self.employees_subjects.destroy_all @@ -83,7 +81,7 @@ def grading_level_list end def fee_collection_dates - FinanceFeeCollection.find_all_by_batch_id(self.id,:conditions => "is_deleted = false") + FinanceFeeCollection.find_all_by_batch_id(self.id, :conditions => { :is_deleted => false }) end def all_students @@ -91,19 +89,19 @@ def all_students end def normal_batch_subject - Subject.find_all_by_batch_id(self.id,:conditions=>["elective_group_id IS NULL AND is_deleted = false"]) + Subject.find_all_by_batch_id(self.id, :conditions => { :elective_group_id => nil, :is_deleted => false }) end - + def elective_batch_subject(elect_group) Subject.find_all_by_batch_id_and_elective_group_id(self.id,elect_group,:conditions=>["elective_group_id IS NOT NULL AND is_deleted = false"]) end def all_elective_subjects - elective_groups.map(&:subjects).compact.flatten.select{|subject| subject.is_deleted == false} + elective_groups.map(&:subjects).compact.flatten.select { |subject| !subject.is_deleted? } end def has_own_weekday - Weekday.find_all_by_batch_id(self.id,:conditions=>{:is_deleted=>false}).present? + Weekday.find_all_by_batch_id(self.id, :conditions => { :is_deleted => false }).any? end def allow_exam_acess(user) @@ -115,7 +113,7 @@ def allow_exam_acess(user) end def is_a_holiday_for_batch?(day) - return true if Event.holidays.count(:all, :conditions => ["start_date <=? AND end_date >= ?", day, day] ) > 0 + return true if Event.holidays.count(:all, :conditions => ["started_on <=? AND ended_on >= ?", day, day] ) > 0 false end @@ -129,12 +127,12 @@ def holiday_event_dates end return event_holidays #array of holiday event dates end - - def return_holidays(start_date,end_date) + + def return_holidays(started_on,ended_on) @common_holidays ||= Event.holidays.is_common @batch_holidays=self.events(:all,:conditions=>{:is_holiday=>true}) all_holiday_events = @batch_holidays+@common_holidays - all_holiday_events.reject!{|h| !(h.start_date>=start_date and h.end_date<=end_date)} + all_holiday_events.reject!{|h| !(h.started_on >= started_on && h.ended_on <= ended_on)} event_holidays = [] all_holiday_events.each do |event| event_holidays+=event.dates @@ -142,16 +140,16 @@ def return_holidays(start_date,end_date) return event_holidays #array of holiday event dates end - def find_working_days(start_date,end_date) + def find_working_days(started_on,ended_on) start=[] - start<["student_id = ? and month_date >= ? and month_date <= ?",student.id,start_date,end_date]) + leaves = Attendance.find(:all,:conditions=>["student_id = ? and month_date >= ? and month_date <= ?",student.id,started_on,ended_on]) absents = 0 unless leaves.empty? leaves.each do|leave| @@ -557,7 +555,7 @@ def generate_previous_batch_reports end end - + def subject_hours(starting_date,ending_date,subject_id) unless subject_id == 0 @@ -565,10 +563,10 @@ def subject_hours(starting_date,ending_date,subject_id) unless subject.elective_group.nil? subject=subject.elective_group.subjects.first end - # Timetable.all(:conditions=>["('#{starting_date}' BETWEEN start_date AND end_date) OR ('#{ending_date}' BETWEEN start_date AND end_date) OR (start_date BETWEEN '#{starting_date}' AND #{ending_date}) OR (end_date BETWEEN '#{starting_date}' AND '#{ending_date}')"]) - entries = TimetableEntry.find(:all,:joins=>:timetable,:include=>:weekday,:conditions=>["((? BETWEEN start_date AND end_date) OR (? BETWEEN start_date AND end_date) OR (start_date BETWEEN ? AND ?) OR (end_date BETWEEN ? AND ?)) AND timetable_entries.subject_id = ? AND timetable_entries.batch_id = ?",starting_date,ending_date,starting_date,ending_date,starting_date,ending_date,subject.id,id]).group_by(&:timetable_id) + # Timetable.all(:conditions=>["('#{starting_date}' BETWEEN started_on AND ended_on) OR ('#{ending_date}' BETWEEN started_on AND ended_on) OR (started_on BETWEEN '#{starting_date}' AND #{ending_date}) OR (ended_on BETWEEN '#{starting_date}' AND '#{ending_date}')"]) + entries = TimetableEntry.find(:all,:joins=>:timetable,:include=>:weekday,:conditions=>["((? BETWEEN started_on AND ended_on) OR (? BETWEEN started_on AND ended_on) OR (started_on BETWEEN ? AND ?) OR (ended_on BETWEEN ? AND ?)) AND timetable_entries.subject_id = ? AND timetable_entries.batch_id = ?",starting_date,ending_date,starting_date,ending_date,starting_date,ending_date,subject.id,id]).group_by(&:timetable_id) else - entries = TimetableEntry.find(:all,:joins=>:timetable,:include=>:weekday,:conditions=>["((? BETWEEN start_date AND end_date) OR (? BETWEEN start_date AND end_date) OR (start_date BETWEEN ? AND ?) OR (end_date BETWEEN ? AND ?)) AND timetable_entries.batch_id = ?",starting_date,ending_date,starting_date,ending_date,starting_date,ending_date,id]).group_by(&:timetable_id) + entries = TimetableEntry.find(:all,:joins=>:timetable,:include=>:weekday,:conditions=>["((? BETWEEN started_on AND ended_on) OR (? BETWEEN started_on AND ended_on) OR (started_on BETWEEN ? AND ?) OR (ended_on BETWEEN ? AND ?)) AND timetable_entries.batch_id = ?",starting_date,ending_date,starting_date,ending_date,starting_date,ending_date,id]).group_by(&:timetable_id) end timetable_ids=entries.keys hsh2=Hash.new @@ -580,7 +578,7 @@ def subject_hours(starting_date,ending_date,subject_id) hsh[k]=val.group_by(&:day_of_week) end timetables.each do |tt| - ([starting_date,start_date.to_date,tt.start_date].max..[tt.end_date,end_date.to_date,ending_date,Configuration.default_time_zone_present_time.to_date].min).each do |d| + ([starting_date,started_on,tt.started_on].max..[tt.ended_on,ended_on,ending_date,Configuration.default_time_zone_present_time.to_date].min).each do |d| hsh2[d]=hsh[tt.id][d.wday] end end @@ -612,7 +610,7 @@ def delete_coscholastic_reports def fa_groups FaGroup.all(:joins=>:subjects, :conditions=>{:subjects=>{:batch_id=>id}}).uniq end - + def create_scholastic_reports report_hash={} fa_groups.each do |fg| @@ -656,7 +654,7 @@ def employees def perform #this is for cce_report_generation use flags if need job for other works - + if job_type=="1" generate_batch_reports elsif job_type=="2" @@ -685,6 +683,24 @@ def check_credit_points def user_is_authorized?(u) employees.collect(&:user_id).include? u.id end - - + + def self.create_reports(batch_ids) + errors = [] + batches = self.find_all_by_id(batch_ids) + batches.each do |batch| + if batch.check_credit_points + batch.job_type = "3" + Delayed::Job.enqueue(batch) + batch.delete_student_cce_report_cache + else + errors += ["Incomplete grading level credit points for #{batch.full_name}, report generation failed."] + end + end + notice = self.create_report_notice(batches) + [notice, errors] + end + + def self.create_report_notice(batches) + "Report generation in queue for batches #{batches.map(&:full_name).join(", ")}. Click Here to view the scheduled job." + end end diff --git a/app/models/batch_event.rb b/app/models/batch_event.rb index ce5fb25e4..ff613c9a8 100755 --- a/app/models/batch_event.rb +++ b/app/models/batch_event.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class BatchEvent < ActiveRecord::Base belongs_to :batch belongs_to :event diff --git a/app/models/batch_group.rb b/app/models/batch_group.rb index e933eaea6..9ca7ab483 100644 --- a/app/models/batch_group.rb +++ b/app/models/batch_group.rb @@ -1,32 +1,29 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class BatchGroup < ActiveRecord::Base belongs_to :course - has_many :grouped_batches, :dependent=>:destroy - has_many :batches, :through=>:grouped_batches + has_many :grouped_batches, :dependent => :destroy + has_many :batches, :through => :grouped_batches validates_presence_of :name, :course_id - def has_active_batches - self.batches.each do|b| - return true if (b.is_active and !b.is_deleted) - end - return false + def has_active_batches? + batches.any? { |b| b.is_active? && !b.is_deleted? } end end diff --git a/app/models/batch_student.rb b/app/models/batch_student.rb index f0ae03099..0a8af1b0c 100644 --- a/app/models/batch_student.rb +++ b/app/models/batch_student.rb @@ -1,23 +1,22 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class BatchStudent < ActiveRecord::Base belongs_to :batch belongs_to :student - belongs_to :school - validates_presence_of :student_id,:batch_id + validates_presence_of :student_id, :batch_id end diff --git a/app/models/cce_exam_category.rb b/app/models/cce_exam_category.rb index 830725747..0c8b43f67 100644 --- a/app/models/cce_exam_category.rb +++ b/app/models/cce_exam_category.rb @@ -1,20 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class CceExamCategory < ActiveRecord::Base has_many :cce_weightages has_many :cce_exam_categories_exam_groups diff --git a/app/models/cce_grade.rb b/app/models/cce_grade.rb index 27bded1f1..92cd80c8a 100644 --- a/app/models/cce_grade.rb +++ b/app/models/cce_grade.rb @@ -1,20 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class CceGrade < ActiveRecord::Base # has_many :assessment_scores belongs_to :cce_grade_set diff --git a/app/models/cce_grade_set.rb b/app/models/cce_grade_set.rb index dffcff186..fad6d05b9 100644 --- a/app/models/cce_grade_set.rb +++ b/app/models/cce_grade_set.rb @@ -1,20 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class CceGradeSet < ActiveRecord::Base has_many :observation_groups has_many :cce_grades#,:dependent => :destroy diff --git a/app/models/cce_report.rb b/app/models/cce_report.rb index 09bf36f31..c98e00443 100644 --- a/app/models/cce_report.rb +++ b/app/models/cce_report.rb @@ -1,28 +1,31 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class CceReport < ActiveRecord::Base belongs_to :batch belongs_to :student -# has_and_belongs_to_many :exams belongs_to :observable, :polymorphic=>true belongs_to :exam named_scope :scholastic,{:conditions=>{:observable_type=>"FaCriteria"}} named_scope :coscholastic,{:conditions=>{:observable_type=>"Observation"}} + + def self.find_student(type, student_id) + type == "former" ? ArchivedStudent.find(student_id) : Student.find(student_id) + end end diff --git a/app/models/cce_weightage.rb b/app/models/cce_weightage.rb index 17dae56f5..04aaa4e3b 100644 --- a/app/models/cce_weightage.rb +++ b/app/models/cce_weightage.rb @@ -1,25 +1,22 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class CceWeightage < ActiveRecord::Base has_and_belongs_to_many :courses belongs_to :cce_exam_category - validates_presence_of :weightage,:criteria_type - def validate - errors.add_to_base("CCE Exam category can't be blank") if self.cce_exam_category_id.blank? - end + validates_presence_of :weightage,:criteria_type, :cce_exam_category_id end diff --git a/app/models/class_designation.rb b/app/models/class_designation.rb index 870649038..d81519536 100644 --- a/app/models/class_designation.rb +++ b/app/models/class_designation.rb @@ -1,36 +1,36 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class ClassDesignation < ActiveRecord::Base validates_presence_of :name - validates_numericality_of :cgpa,:if=>:has_gpa - validates_numericality_of :marks, :if=>:has_cwa + validates_numericality_of :cgpa, :if => :has_gpa? + validates_numericality_of :marks, :if => :has_cwa? belongs_to :course - def has_gpa - self.course.gpa_enabled? + def has_gpa? + course && course.gpa_enabled? end - def has_cwa - self.course.cwa_enabled? or self.course.normal_enabled? + def has_cwa? + course && (course.cwa_enabled? || course.normal_enabled?) end - HUMANIZED_COLUMNS = {:cgpa => "CGPA"} + HUMANIZED_COLUMNS = { :cgpa => "CGPA" } def self.human_attribute_name(attribute) HUMANIZED_COLUMNS[attribute.to_sym] || super diff --git a/app/models/class_timing.rb b/app/models/class_timing.rb index d314e751c..1e08efd57 100755 --- a/app/models/class_timing.rb +++ b/app/models/class_timing.rb @@ -1,44 +1,62 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class ClassTiming < ActiveRecord::Base - has_many :timetable_entries, :dependent=>:destroy + has_many :timetable_entries, :dependent => :destroy belongs_to :batch validates_presence_of :name - validates_uniqueness_of :name, :scope => [:batch_id , :is_deleted] - - named_scope :for_batch, lambda { |b| { :conditions => { :batch_id => b.to_i, :is_deleted=>false, :is_break => false}, :order =>'start_time ASC' } } - named_scope :default, :conditions => { :batch_id => nil, :is_break => false, :is_deleted=>false }, :order =>'start_time ASC' - named_scope :active_for_batch, lambda { |b| { :conditions => { :batch_id => b.to_i, :is_deleted=>false}, :order =>'start_time ASC' } } - named_scope :active, :conditions => { :batch_id => nil, :is_deleted=>false }, :order =>'start_time ASC' - - def validate - errors.add(:end_time, "#{t('should_be_later')}.") \ - if self.start_time > self.end_time \ - unless self.start_time.nil? or self.end_time.nil? - self_check= self.new_record? ? "" : "id != #{self.id} and " - start_overlap = !ClassTiming.find(:first, :conditions=>[self_check+"start_time < ? and end_time > ? and is_deleted = ? and batch_id #{self.batch_id.nil? ? 'is null' : '='+ self.batch_id.to_s}", self.start_time,self.start_time,false]).nil? - end_overlap = !ClassTiming.find(:first, :conditions=>[self_check+"start_time < ? and end_time > ? and is_deleted = ? and batch_id #{self.batch_id.nil? ? 'is null' : '='+ self.batch_id.to_s}", self.end_time,self.end_time,false]).nil? - between_overlap = !ClassTiming.find(:first, :conditions=>[self_check+"start_time < ? and end_time > ? and is_deleted = ? and batch_id #{self.batch_id.nil? ? 'is null' : '='+ self.batch_id.to_s}",self.end_time, self.start_time,false]).nil? - errors.add(:start_time, "#{t('overlap_existing_class_timing')}.") if start_overlap - errors.add(:end_time, "#{t('overlap_existing_class_timing')}.") if end_overlap - errors.add_to_base("#{t('class_time_overlaps_with_existing')}.") if between_overlap - errors.add(:start_time,"#{t('is_same_as_end_time')}") if self.start_time == self.end_time + validates_uniqueness_of :name, :scope => [:batch_id , :is_deleted] + + named_scope :for_batch, lambda { |b| { :conditions => { :batch_id => b.to_i, :is_deleted => false, :is_break => false }, :order =>'start_time ASC' } } + named_scope :default, :conditions => { :batch_id => nil, :is_break => false, :is_deleted => false }, :order => 'start_time ASC' + named_scope :active_for_batch, lambda { |b| { :conditions => { :batch_id => b.to_i, :is_deleted => false }, :order => 'start_time ASC'} } + named_scope :active, :conditions => { :batch_id => nil, :is_deleted => false }, :order => 'start_time ASC' + validate :end_date_is_later_than_start_date, :start_time_same_end_time, :check_start_overlap, :check_between_overlap, :check_end_overlap + + private + + def overlap_condition(first_time, second_time) + self_check = new_record? ? '' : "id != #{connection.quote(self.id)} AND " + self_batch_id = batch_id.nil? ? 'batch_id IS NULL' : 'batch_id = ' + connection.quote(batch_id.to_s) + start_date_and_end_date_exists? && !!ClassTiming.find(:first, :conditions => [self_check + self_batch_id + " AND start_time < ? AND end_time > ? AND is_deleted = ?", first_time, second_time, false]) + end + + def start_date_and_end_date_exists? + start_time && end_time + end + + def end_date_is_later_than_start_date + errors.add(:end_time, "#{t('should_be_later')}.") if start_date_and_end_date_exists? && start_time > end_time + end + + def start_time_same_end_time + errors.add(:start_time,"#{t('is_same_as_end_time')}") if start_date_and_end_date_exists? && start_time == end_time + end + + def check_start_overlap + errors.add(:start_time, "#{t('overlap_existing_class_timing')}.") if overlap_condition(start_time, start_time) + end + + def check_between_overlap + errors.add_to_base("#{t('class_time_overlaps_with_existing')}.") if overlap_condition(end_time, start_time) + end + + def check_end_overlap + errors.add(:end_time, "#{t('overlap_existing_class_timing')}.") if overlap_condition(end_time, end_time) end end diff --git a/app/models/configuration.rb b/app/models/configuration.rb index 94f136b95..28aff32e0 100755 --- a/app/models/configuration.rb +++ b/app/models/configuration.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class Configuration < ActiveRecord::Base STUDENT_ATTENDANCE_TYPE_OPTIONS = [["#{t('daily_text')}", "Daily"], ["#{t('subject_wise_text')}", "SubjectWise"]] @@ -47,7 +46,7 @@ def get_config_value(key) c = find_by_config_key(key) c.nil? ? nil : c.config_value end - + def save_institution_logo(upload) directory, filename = "#{RAILS_ROOT}/public/uploads/image", 'institute_logo.jpg' path = File.join(directory, filename) # create the file path @@ -79,14 +78,14 @@ def get_multiple_configs_as_hash(keys) def get_grading_types grading_types = Course::GRADINGTYPES types= all(:conditions=>{:config_key=>grading_types.values, :config_value=>"1"},:group=>:config_key) - grading_types.keys.select{|k| types.collect(&:config_key).include? grading_types[k]} + grading_types.keys.select{|k| types.collect(&:config_key).include? grading_types[k]} end def default_country default_country_value = self.find_by_config_key('DefaultCountry').config_value.to_i return default_country_value end - + def set_grading_types(updates) #expects an array of integers types grading_types = Course::GRADINGTYPES @@ -116,7 +115,7 @@ def default_time_zone_present_time end return local_tzone_time end - + def cce_enabled? get_config_value("CCE") == "1" end diff --git a/app/models/country.rb b/app/models/country.rb index c80d65761..e3ad32766 100755 --- a/app/models/country.rb +++ b/app/models/country.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class Country < ActiveRecord::Base default_scope :order=>'name ASC' end diff --git a/app/models/course.rb b/app/models/course.rb index 38303313d..3dc0d3008 100755 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -1,25 +1,25 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class Course < ActiveRecord::Base - GRADINGTYPES = {"1"=>"GPA","2"=>"CWA","3"=>"CCE"} - + GRADINGTYPES = { '1' => 'GPA', '2' => 'CWA', '3' => 'CCE' } + INVERT_GRADINGTYPES = GRADINGTYPES.invert + validates_presence_of :course_name, :code validate :presence_of_initial_batch, :on => :create @@ -31,27 +31,23 @@ class Course < ActiveRecord::Base accepts_nested_attributes_for :batches has_and_belongs_to_many :observation_groups has_and_belongs_to_many_with_deferred_save :cce_weightages - - before_save :cce_weightage_valid - named_scope :active, :conditions => { :is_deleted => false }, :order => 'course_name asc' - named_scope :deleted, :conditions => { :is_deleted => true }, :order => 'course_name asc' - named_scope :cce, {:select => "courses.*",:conditions=>{:grading_type => GRADINGTYPES.invert["CCE"]}, :order => 'course_name asc'} + validate :cce_weightage_valid - def presence_of_initial_batch - errors.add_to_base "#{t('should_have_an_initial_batch')}" if batches.length == 0 - end + named_scope :active, :conditions => { :is_deleted => false }, :order => 'course_name ASC' + named_scope :deleted, :conditions => { :is_deleted => true }, :order => 'course_name ASC' + named_scope :cce, { :select => 'courses.*', :conditions => { :grading_type => GRADINGTYPES.invert['CCE'] }, :order => 'course_name ASC' } def inactivate update_attribute(:is_deleted, true) end - + def full_name "#{course_name} #{section_name}" end def active_batches - self.batches.all(:conditions=>{:is_active=>true,:is_deleted=>false}) + self.batches.all(:conditions => { :is_active => true, :is_deleted => false }) end def has_batch_groups_with_active_batches @@ -60,43 +56,44 @@ def has_batch_groups_with_active_batches return false else batch_groups.each do|b| - return true if b.has_active_batches==true + return true if b.has_active_batches? end end return false end - def find_course_rank(batch_ids,sort_order) - batches = Batch.find_all_by_id(batch_ids) + def find_course_rank(batch_ids, sort_order) + batches = Batch.find_all_by_id(batch_ids) @students = Student.find_all_by_batch_id(batches) - @grouped_exams = GroupedExam.find_all_by_batch_id(batches) - ordered_scores = [] - student_scores = [] + ordered_scores = [] + student_scores = [] ranked_students = [] - @students.each do|student| - score = GroupedExamReport.find_by_student_id_and_batch_id_and_score_type(student.id,student.batch_id,"c") + + @students.each do |student| + score = GroupedExamReport.find_by_student_id_and_batch_id_and_score_type(student.id, student.batch_id, 'c') marks = 0 - unless score.nil? - marks = score.marks - end + marks = score.marks if score.present? ordered_scores << marks - student_scores << [student.id,marks] + student_scores << [student.id, marks] end + ordered_scores = ordered_scores.compact.uniq.sort.reverse + @students.each do |student| m = 0 - student_scores.each do|student_score| - if student_score[0]==student.id + student_scores.each do |student_score| + if student_score[0] == student.id m = student_score[1] end end - if sort_order=="" or sort_order=="rank-ascend" or sort_order=="rank-descend" - ranked_students << [(ordered_scores.index(m) + 1),m,student.id,student] + if sort_order == '' || sort_order == 'rank-ascend' || sort_order == 'rank-descend' + ranked_students << [(ordered_scores.index(m) + 1), m.to_f, student.id, student] else - ranked_students << [student.full_name,(ordered_scores.index(m) + 1),m,student.id,student] + ranked_students << [student.full_name, (ordered_scores.index(m) + 1), m.to_f, student.id, student] end end - if sort_order=="" or sort_order=="rank-ascend" or sort_order=="name-ascend" + + if sort_order == '' || sort_order == 'rank-ascend' ranked_students = ranked_students.sort else ranked_students = ranked_students.sort.reverse @@ -104,20 +101,21 @@ def find_course_rank(batch_ids,sort_order) end def cce_enabled? - Configuration.cce_enabled? and grading_type == "3" + Configuration.cce_enabled? && grading_type == INVERT_GRADINGTYPES['CCE'] end def gpa_enabled? - Configuration.has_gpa? and self.grading_type=="1" + Configuration.has_gpa? && grading_type == INVERT_GRADINGTYPES['GPA'] end def cwa_enabled? - Configuration.has_cwa? and self.grading_type=="2" + Configuration.has_cwa? && grading_type == INVERT_GRADINGTYPES['CWA'] end def normal_enabled? - self.grading_type.nil? or self.grading_type=="0" + self.grading_type.nil? || self.grading_type == '0' end + # def guardian_email_list # email_addresses = [] # students = self.students @@ -135,34 +133,36 @@ def normal_enabled? # end # email_addresses # end - class << self - def grading_types - hsh = ActiveSupport::OrderedHash.new - hsh["0"]="Normal" - types = Configuration.get_grading_types - types.each{|t| hsh[t] = GRADINGTYPES[t]} - hsh - end - def grading_types_as_options - grading_types.invert.sort_by{|k,v| v} - end + + def self.grading_types + hsh = {} + hsh["0"] = "Normal" + types = Configuration.get_grading_types + types.each { |t| hsh[t] = GRADINGTYPES[t] } + hsh + end + + def self.grading_types_as_options + grading_types.invert.sort_by { |k, v| v } end def cce_weightages_for_exam_category(cce_exam_cateogry_id) - cce_weightages.all(:conditions=>{:cce_exam_category_id=>cce_exam_cateogry_id}) + cce_weightages.all(:conditions => { :cce_exam_category_id => cce_exam_cateogry_id }) end private + def presence_of_initial_batch + errors.add_to_base "#{t('should_have_an_initial_batch')}" if batches.length == 0 + end + def cce_weightage_valid + cce_weightages.group_by(&:criteria_type).values.each do |v| - unless v.collect(&:cce_exam_category_id).length == v.collect(&:cce_exam_category_id).uniq.length - errors.add(:cce_weightages,"can't assign more than one FA or SA under a single exam category.") - return false + if v.collect(&:cce_exam_category_id).count != v.collect(&:cce_exam_category_id).uniq.count + errors.add(:cce_weightages, "can't assign more than one FA or SA under a single exam category.") end end - true - end end \ No newline at end of file diff --git a/app/models/descriptive_indicator.rb b/app/models/descriptive_indicator.rb index b03d2c518..605b7754e 100644 --- a/app/models/descriptive_indicator.rb +++ b/app/models/descriptive_indicator.rb @@ -1,21 +1,21 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class DescriptiveIndicator < ActiveRecord::Base belongs_to :describable,:polymorphic=>true has_many :assessment_scores diff --git a/app/models/elective.rb b/app/models/elective.rb index 381db7ed9..0f6d28907 100755 --- a/app/models/elective.rb +++ b/app/models/elective.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class Elective < ActiveRecord::Base diff --git a/app/models/elective_group.rb b/app/models/elective_group.rb index 601b8c575..52a77168c 100755 --- a/app/models/elective_group.rb +++ b/app/models/elective_group.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class ElectiveGroup < ActiveRecord::Base belongs_to :batch has_many :subjects diff --git a/app/models/event.rb b/app/models/event.rb index 188fd4aee..fdae4b80c 100755 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -1,23 +1,23 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class Event < ActiveRecord::Base validates_presence_of :title, :description, :start_date, :end_date + validate :valid_date named_scope :holidays, :conditions => {:is_holiday => true} named_scope :exams, :conditions => {:is_exam => true} @@ -26,54 +26,16 @@ class Event < ActiveRecord::Base has_many :user_events, :dependent => :destroy belongs_to :origin , :polymorphic => true - def validate - unless self.start_date.nil? or self.end_date.nil? - errors.add(:end_time, "#{t('can_not_be_before_the_start_time')}") if self.end_date < self.start_date - end + def student_event?(student) + fiance_fee_collection_event?(student) || user_event?(student) end - def is_student_event(student) - flag = false - base = self.origin - unless base.blank? - if base.respond_to?('batch_id') - if base.batch_id == student.batch_id - finance = base.fee_table - if finance.present? - flag = true if finance.map{|fee|fee.student_id}.include?(student.id) - end - end - end - end - user_events = self.user_events - unless user_events.nil? - flag = true if user_events.map{|x|x.user_id }.include?(student.user.id) - end - return flag + def employee_event?(user) + !!user_events && user_events.map{|x|x.user_id }.include?(user.id) end - def is_employee_event(user) - user_events = self.user_events - unless user_events.nil? - return true if user_events.map{|x|x.user_id }.include?(user.id) - end - return false - end - - def is_active_event - flag = false - unless self.origin.nil? - if self.origin.respond_to?('is_deleted') - unless self.origin.is_deleted - flag = true - end - else - flag = true - end - else - flag = true - end - return flag + def active_event? + !!(origin.nil? || (origin && origin.respond_to?('is_deleted') && !origin.is_deleted)) end def dates @@ -81,11 +43,25 @@ def dates end class << self - def is_a_holiday?(day) - return true if Event.holidays.count(:all, :conditions => ["start_date <=? AND end_date >= ?", day, day] ) > 0 - false + def a_holiday?(day) + Event.holidays.find(:all, :conditions => ["start_date <= ? AND end_date >= ?", day.beginning_of_day, day.end_of_day]).any? end end - -end + private + + def valid_date + errors.add(:end_time, "#{t('can_not_be_before_the_start_time')}") if start_date && end_date && end_date < start_date + end + + def fiance_fee_collection_event?(student) + if origin && origin.respond_to?('batch_id') && origin.batch_id == student.batch_id + !!origin.fee_table && origin.fee_table.map{|fee|fee.student_id}.include?(student.id) + end + end + + def user_event?(student) + !!user_events && user_events.map{ |x|x.user_id }.include?(student.user.id) + end + +end \ No newline at end of file diff --git a/app/models/exam.rb b/app/models/exam.rb index be043f6ec..781d45c41 100755 --- a/app/models/exam.rb +++ b/app/models/exam.rb @@ -1,87 +1,59 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class Exam < ActiveRecord::Base validates_presence_of :start_time, :end_time validates_numericality_of :maximum_marks, :minimum_marks, :allow_nil => true - validates_presence_of :maximum_marks, :minimum_marks, :if => :validation_should_present?, :on=>:update + validates_presence_of :maximum_marks, :minimum_marks, :if => :validation_should_present?, :on => :update + validate :minmarks_cant_be_more_than_maxmarks, :end_time_cannot_before_start_time belongs_to :exam_group belongs_to :subject, :conditions => { :is_deleted => false } before_destroy :removable? - before_save :update_exam_group_date + before_save :update_exam_group_date, :update_weightage + after_create :create_exam_event + after_update :update_exam_event - has_one :event ,:as=>:origin + has_one :event, :as => :origin has_many :exam_scores + accepts_nested_attributes_for :exam_scores + has_many :archived_exam_scores has_many :previous_exam_scores has_many :assessment_scores # has_and_belongs_to_many :cce_reports - accepts_nested_attributes_for :exam_scores - def validation_should_present? - if self.exam_group.exam_type=="Grades" - return false - else - return true - end - end - - def removable? - self.exam_scores.reject{|es| es.marks.nil? and es.grading_level_id.nil?}.empty? - - end - - def validate - errors.add_to_base("#{t('minmarks_cant_be_more_than_maxmarks')}") \ - if minimum_marks and maximum_marks and minimum_marks > maximum_marks - errors.add_to_base("#{t('minmarks_cant_be_more_than_maxmarks')}") \ - if minimum_marks and maximum_marks and minimum_marks > maximum_marks - unless self.start_time.nil? or self.end_time.nil? - errors.add_to_base("#{t('end_time_cannot_before_start_time')}")if self.end_time < self.start_time - end - end - - def before_save - self.weightage = 0 if self.weightage.nil? - #update_exam_group_date - end - - def after_create - create_exam_event + self.exam_group.exam_type != "Grades" end - def after_update - update_exam_event + def removable? + self.exam_scores.reject{|es| es.marks.nil? && es.grading_level_id.nil?}.empty? end def score_for(student_id) - exam_score = self.exam_scores.find(:first, :conditions => { :student_id => student_id }) - exam_score.nil? ? ExamScore.new : exam_score + self.exam_scores.find_or_initialize_by_student_id(student_id) end def class_average_marks results = ExamScore.find_all_by_exam_id(self) - scores = results.collect { |x| x.marks unless x.marks.nil?} + scores = results.collect { |x| x.marks if x.marks } scores.delete(nil) - return (scores.sum / scores.size) unless scores.size == 0 - return 0 + scores.size == 0 ? 0 : scores.sum / scores.size end def fa_groups @@ -89,27 +61,40 @@ def fa_groups end private + + def minmarks_cant_be_more_than_maxmarks + errors.add_to_base("#{t('minmarks_cant_be_more_than_maxmarks')}") if minimum_marks && maximum_marks and minimum_marks > maximum_marks + end + + def end_time_cannot_before_start_time + errors.add_to_base("#{t('end_time_cannot_before_start_time')}") if start_time && end_time and self.end_time < self.start_time + end + + def update_weightage + self.weightage = 0 if self.weightage.nil? + end + def update_exam_group_date group = self.exam_group - group.update_attribute(:exam_date, self.start_time.to_date) if !group.exam_date.nil? and self.start_time.to_date < group.exam_date + group.update_attribute(:exam_date, self.start_time.to_date) if group.exam_date and self.start_time.to_date < group.exam_date end def create_exam_event if self.event.blank? - new_event = Event.create do |e| - e.title = "#{t('exam_text')}" - e.description = "#{self.exam_group.name} #{t('for')} #{self.subject.batch.full_name} - #{self.subject.name}" - e.start_date = self.start_time - e.end_date = self.end_time - e.is_exam = true - e.origin = self - end - batch_event = BatchEvent.create do |be| - be.event_id = new_event.id - be.batch_id = self.exam_group.batch_id - end + new_event = Event.create( + :title => "#{t('exam_text')}", + :description => "#{self.exam_group.name} #{t('for')} #{self.try(:subject).try(:batch).try(:full_name)} - #{self.try(:subject).try(:name)}", + :start_date => self.start_time, + :end_date => self.end_time, + :is_exam => true, + :origin => self + ) + batch_event = BatchEvent.create( + :event_id => new_event.id, + :batch_id => self.exam_group.batch_id + ) #self.event_id = new_event.id - self.update_attributes(:event_id=>new_event.id) + self.update_attributes(:event_id => new_event.id) end end diff --git a/app/models/exam_group.rb b/app/models/exam_group.rb index 06eadf80d..a4c8e26fa 100755 --- a/app/models/exam_group.rb +++ b/app/models/exam_group.rb @@ -1,154 +1,113 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class ExamGroup < ActiveRecord::Base - validates_presence_of :name + attr_accessor :maximum_marks, :minimum_marks, :weightage belongs_to :batch belongs_to :grouped_exam - - has_many :exams, :dependent => :destroy - before_destroy :removable? belongs_to :cce_exam_category + has_many :exams, :dependent => :destroy accepts_nested_attributes_for :exams - - attr_accessor :maximum_marks, :minimum_marks, :weightage + validates_presence_of :name validates_associated :exams + validates_uniqueness_of :cce_exam_category_id, :scope => :batch_id, :message => "already assigned for another Exam Group", :unless => lambda { |e| e.cce_exam_category_id.nil? } - validates_uniqueness_of :cce_exam_category_id, :scope=>:batch_id, :message=>"already assigned for another Exam Group",:unless => lambda { |e| e.cce_exam_category_id.nil?} - - def removable? - self.exams.reject{|e| e.removable?}.empty? - end + before_save :set_exam_date + before_validation :grade_exam_marks - def before_save - self.exam_date = self.exam_date || Date.today - end - - def before_validation - if self.exam_type.downcase == "grades" - self.exams.each do |ex| - ex.maximum_marks = 0 - ex.minimum_marks = 0 - end - end + def removable? + self.exams.all?{ |e| e.removable? } end + # TODO: all these methods can be refactor using meta programing def batch_average_marks(marks) - batch = self.batch - exams = self.exams batch_students = batch.students total_students_marks = 0 - # total_max_marks = 0 students_attended = [] exams.each do |exam| batch_students.each do |student| - exam_score = ExamScore.find_by_student_id_and_exam_id(student.id,exam.id) - unless exam_score.nil? - unless exam_score.marks.nil? - total_students_marks = total_students_marks+exam_score.marks - unless students_attended.include? student.id - students_attended.push student.id - end - end + exam_score = ExamScore.find_by_student_id_and_exam_id(student.id, exam.id) + if exam_score && exam_score.marks + total_students_marks += exam_score.marks + students_attended << student.id unless students_attended.include?(student.id) end end - # total_max_marks = total_max_marks+exam.maximum_marks end - unless students_attended.size == 0 - batch_average_marks = total_students_marks/students_attended.size + + batch_average_marks = if students_attended.size == 0 + 0 else - batch_average_marks = 0 + total_students_marks / students_attended.size end - return batch_average_marks if marks == 'marks' - # return total_max_marks if marks == 'percentage' + batch_average_marks if marks == 'marks' end def weightage - grp = GroupedExam.find_by_batch_id_and_exam_group_id(self.batch.id,self.id) - unless grp.nil? - weight = grp.weightage - else - weight=0 - end - return weight + grp = GroupedExam.find_by_batch_id_and_exam_group_id(self.batch.id, self.id) + grp.present? ? grp.weightage : 0 end def archived_batch_average_marks(marks) - batch = self.batch - exams = self.exams batch_students = ArchivedStudent.find_all_by_batch_id(self.batch.id) total_students_marks = 0 - # total_max_marks = 0 students_attended = [] exams.each do |exam| batch_students.each do |student| - exam_score = ArchivedExamScore.find_by_student_id_and_exam_id(student.id,exam.id) - unless exam_score.nil? - unless exam_score.marks.nil? - total_students_marks = total_students_marks+exam_score.marks - unless students_attended.include? student.id - students_attended.push student.id - end - end + exam_score = ArchivedExamScore.find_by_student_id_and_exam_id(student.id, exam.id) + if exam_score && exam_score.marks + total_students_marks += exam_score.marks + students_attended << student.id unless students_attended.include?(student.id) end end - # total_max_marks = total_max_marks+exam.maximum_marks end - unless students_attended.size == 0 - batch_average_marks = total_students_marks/students_attended.size + batch_average_marks = if students_attended.size == 0 + 0 else - batch_average_marks = 0 + total_students_marks / students_attended.size end - return batch_average_marks if marks == 'marks' + batch_average_marks if marks == 'marks' end def batch_average_percentage - end def subject_wise_batch_average_marks(subject_id) - batch = self.batch subject = Subject.find(subject_id) - exam = Exam.find_by_exam_group_id_and_subject_id(self.id,subject.id) + exam = Exam.find_by_exam_group_id_and_subject_id(self.id, subject.id) batch_students = batch.students total_students_marks = 0 - # total_max_marks = 0 students_attended = [] batch_students.each do |student| - exam_score = ExamScore.find_by_student_id_and_exam_id(student.id,exam.id) - unless exam_score.nil? - total_students_marks = total_students_marks+ (exam_score.marks || 0) - unless students_attended.include? student.id - students_attended.push student.id - end + exam_score = ExamScore.find_by_student_id_and_exam_id(student.id, exam.id) + if exam_score.present? + total_students_marks += (exam_score.marks || 0) + students_attended << student.id unless students_attended.include?(student.id) end end - # total_max_marks = total_max_marks+exam.maximum_marks - unless students_attended.size == 0 - subject_wise_batch_average_marks = total_students_marks/students_attended.size.to_f + + batch_average_marks = if students_attended.size == 0 + 0 else - subject_wise_batch_average_marks = 0 + total_students_marks / students_attended.size.to_f end - return subject_wise_batch_average_marks - # return total_max_marks if marks == 'percentage' + batch_average_marks end def total_marks(student) @@ -156,11 +115,13 @@ def total_marks(student) total_marks = 0 max_total = 0 exams.each do |exam| - exam_score = ExamScore.find_by_exam_id_and_student_id(exam.id,student.id) - total_marks = total_marks + (exam_score.marks || 0) unless exam_score.nil? - max_total = max_total + exam.maximum_marks unless exam_score.nil? + exam_score = ExamScore.find_by_exam_id_and_student_id(exam.id, student.id) + if exam_score.present? + total_marks += (exam_score.marks || 0) + max_total += exam.maximum_marks + end end - result = [total_marks,max_total] + [total_marks, max_total] end def archived_total_marks(student) @@ -168,15 +129,29 @@ def archived_total_marks(student) total_marks = 0 max_total = 0 exams.each do |exam| - exam_score = ArchivedExamScore.find_by_exam_id_and_student_id(exam.id,student.id) + exam_score = ArchivedExamScore.find_by_exam_id_and_student_id(exam.id, student.id) total_marks = total_marks + (exam_score.marks || 0 ) unless exam_score.nil? max_total = max_total + exam.maximum_marks unless exam_score.nil? end - result = [total_marks,max_total] + result = [total_marks, max_total] end def course batch.course if batch end -end \ No newline at end of file + private + + def set_exam_date + self.exam_date ||= Date.today + end + + def grade_exam_marks + if self.exam_type && self.exam_type.downcase == "grades" + self.exams.each do |ex| + ex.maximum_marks = 0 + ex.minimum_marks = 0 + end + end + end +end diff --git a/app/models/exam_score.rb b/app/models/exam_score.rb index 20579a3a1..e4a379a7f 100755 --- a/app/models/exam_score.rb +++ b/app/models/exam_score.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class ExamScore < ActiveRecord::Base belongs_to :student belongs_to :exam @@ -24,111 +23,89 @@ class ExamScore < ActiveRecord::Base before_save :calculate_grade before_save :check_existing - + validate :marks_cannot_be_greater_than_maximum_marks validates_presence_of :student_id - validates_presence_of :exam_id,:message => "Name/Batch Name/Subject Code is invalid" - validates_numericality_of :marks,:allow_nil => true - - + validates_presence_of :exam_id, :message => "Name/Batch Name/Subject Code is invalid" + validates_numericality_of :marks, :allow_nil => true - def check_existing - exam_score = ExamScore.find(:first,:conditions => {:exam_id => self.exam_id,:student_id => self.student_id}) - if exam_score - self.id = exam_score.id - self.instance_variable_set("@new_record",false) #If the record exists,then make the new record as a copy of the existing one and allow rails to chhose - #the update operation instead of insert. - end - return true - end - - - def validate - unless self.marks.nil? - unless self.exam.nil? - if self.exam.maximum_marks.to_f < self.marks.to_f - errors.add('marks','cannot be greater than maximum marks') - return false - else - return true - end - end - end - end - - def calculate_percentage percentage = self.marks.to_f * 100 / self.exam.maximum_marks.to_f end - def grouped_exam_subject_total(subject,student,type,batch = "") - if batch == "" - batch = student.batch.id - end + def exam_groups_from(batch, type) if type == 'grouped' - grouped_exams = GroupedExam.find_all_by_batch_id(batch) - exam_groups = [] - grouped_exams.each do |x| - eg = ExamGroup.find(x.exam_group_id) - exam_groups.push ExamGroup.find(x.exam_group_id) - end + exam_group_ids = GroupedExam.find_all_by_batch_id(batch).map(&:exam_group_id) + ExamGroup.find_all_by_id(exam_group_ids) else - exam_groups = ExamGroup.find_all_by_batch_id(batch) + ExamGroup.find_all_by_batch_id(batch) end + end + + def grouped_exam_subject_total(subject, student, type, batch = "") + batch = student.batch_id if batch.blank? + exam_groups = exam_groups_from(batch, type) total_marks = 0 exam_groups.each do |exam_group| - unless exam_group.exam_type == 'Grades' - exam = Exam.find_by_subject_id_and_exam_group_id(subject.id,exam_group.id) - unless exam.nil? - exam_score = ExamScore.find_by_student_id(student.id, :conditions=>{:exam_id=>exam.id}) - marks = exam_score.nil? ? 0 : exam_score.marks.nil? ? 0 : exam_score.marks - total_marks = total_marks + marks unless exam_score.nil? + if exam_group.exam_type != 'Grades' + exam = Exam.find_by_subject_id_and_exam_group_id(subject.id, exam_group.id) + if exam.present? + exam_score = ExamScore.find_by_student_id_and_exam_id(student.id, exam.id) + total_marks += exam_score && exam_score.marks ? exam_score.marks : 0 end end end - total_marks + total_marks.to_f end - + def var_from(batch_id) + ExamGroup.find_all_by_batch_id(batch_id).map do |group| + 1 if group.exam_type == 'Grades' + end.compact + end - def batch_wise_aggregate(student,batch) - check = ExamGroup.find_all_by_batch_id(batch.id) - var = [] - check.each do |x| - if x.exam_type == 'Grades' - var << 1 - end - end - if var.empty? - grouped_exam = GroupedExam.find_all_by_batch_id(batch.id) - if grouped_exam.empty? - exam_groups = ExamGroup.find_all_by_batch_id(batch.id) + def batch_wise_aggregate(student, batch) + if var_from(batch.id).empty? + grouped_exams = GroupedExam.find_all_by_batch_id(batch.id) + exam_groups = if grouped_exams.empty? + ExamGroup.find_all_by_batch_id(batch.id) else - exam_groups = [] - grouped_exam.each do |x| - exam_groups.push ExamGroup.find(x.exam_group_id) - end + ExamGroup.find_all_by_id(grouped_exams.map(&:exam_group_id)) end - exam_groups.size max_total = 0 marks_total = 0 exam_groups.each do |exam_group| - max_total = max_total + exam_group.total_marks(student)[1] - marks_total = marks_total + exam_group.total_marks(student)[0] + max_total += exam_group.total_marks(student)[1] + marks_total += exam_group.total_marks(student)[0] end - aggr = (marks_total*100/max_total) unless max_total==0 + marks_total * 100 / max_total unless max_total == 0 else - aggr = 'nil' + nil end - end private + + def marks_cannot_be_greater_than_maximum_marks + if marks.present? && exam.present? && exam.maximum_marks.to_f < marks.to_f + errors.add(:marks, 'cannot be greater than maximum marks') + end + end + + def check_existing + exam_score = ExamScore.first(:conditions => {:exam_id => self.exam_id, :student_id => self.student_id}) + if exam_score + self.id = exam_score.id + self.instance_variable_set("@new_record",false) #If the record exists,then make the new record as a copy of the existing one and allow rails to chhose + #the update operation instead of insert. + end + true + end + def calculate_grade - exam = self.exam exam_group = exam.exam_group exam_type = exam_group.exam_type - unless exam_type == 'Grades' - unless self.marks.nil? + if exam_type != 'Grades' + if self.marks.present? percent_score = self.marks.to_i * 100 / self.exam.maximum_marks grade = GradingLevel.percentage_to_grade(percent_score, self.exam.exam_group.batch_id) self.grading_level_id = grade.id if exam_type == 'MarksAndGrades' @@ -136,6 +113,7 @@ def calculate_grade self.grading_level_id = nil end end + true end end diff --git a/app/models/fa_criteria.rb b/app/models/fa_criteria.rb index d28bb9c53..0950a3bfc 100644 --- a/app/models/fa_criteria.rb +++ b/app/models/fa_criteria.rb @@ -1,20 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class FaCriteria < ActiveRecord::Base has_many :descriptive_indicators, :as=>:describable has_many :assessment_scores, :through=>:descriptive_indicators diff --git a/app/models/fa_group.rb b/app/models/fa_group.rb index 538a3041f..7c7fbeee1 100644 --- a/app/models/fa_group.rb +++ b/app/models/fa_group.rb @@ -1,25 +1,25 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class FaGroup < ActiveRecord::Base has_many :fa_criterias has_and_belongs_to_many :subjects belongs_to :cce_exam_category - has_many :cce_reports, :through=>:fa_criterias + has_many :cce_reports, :through=>:fa_criterias named_scope :active,:conditions=>{:is_deleted=>false} @@ -28,5 +28,5 @@ def validate errors.add_to_base("CCE exam category can't be blank") if self.cce_exam_category_id.blank? errors.add_to_base("Description can't be blank") if self.desc.blank? end - + end diff --git a/app/models/fedena_mailer.rb b/app/models/fedena_mailer.rb index 3a0dfcdd7..1f06b4fa3 100755 --- a/app/models/fedena_mailer.rb +++ b/app/models/fedena_mailer.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class FedenaMailer < ActionMailer::Base def email(sender,recipients, subject, message) recipient_emails = (recipients.class == String) ? recipients.gsub(' ','').split(',').compact : recipients.compact @@ -30,5 +29,5 @@ def setup_email(sender, emails, subject, message) @sent_on = Time.now @body['message'] = message end - + end diff --git a/app/models/finance/asset.rb b/app/models/finance/asset.rb index 1bf2cc8bc..051c58272 100755 --- a/app/models/finance/asset.rb +++ b/app/models/finance/asset.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class Asset < ActiveRecord::Base validates_presence_of :title, :amount validates_numericality_of :amount diff --git a/app/models/finance/batch_fee_collection_discount.rb b/app/models/finance/batch_fee_collection_discount.rb index efb6b9058..ae78bcb7a 100644 --- a/app/models/finance/batch_fee_collection_discount.rb +++ b/app/models/finance/batch_fee_collection_discount.rb @@ -1,44 +1,40 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class BatchFeeCollectionDiscount < FeeCollectionDiscount - - belongs_to :receiver ,:class_name=>'Batch' + belongs_to :receiver, :class_name => 'Batch' belongs_to :finance_fee_collection - validates_presence_of :receiver_id , :message => "#{t('batch_cant_be_blank')}" + validates_presence_of :receiver_id, :message => "#{t('batch_cant_be_blank')}" def total_payable(student = nil) - if student.nil? - payable = finance_fee_collection.fee_category.fee_particulars.active.map(&:amount).compact.flatten.sum + if student + finance_fee_collection.fees_particulars(student).map(&:amount).compact.flatten.sum else - payable = finance_fee_collection.fees_particulars(student).map(&:amount).compact.flatten.sum + finance_fee_collection.fee_category.fee_particulars.active.map(&:amount).compact.flatten.sum end - payable end - + def discount(student = nil) - if is_amount == false - super - elsif is_amount == true + if is_amount? payable = student.nil? ? total_payable : total_payable(student) percentage = (super.to_f / payable.to_f).to_f * 100 percentage + else + super end end end diff --git a/app/models/finance/batch_fee_discount.rb b/app/models/finance/batch_fee_discount.rb index 87e84c849..c551c5c4e 100644 --- a/app/models/finance/batch_fee_discount.rb +++ b/app/models/finance/batch_fee_discount.rb @@ -1,44 +1,27 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class BatchFeeDiscount < FeeDiscount + belongs_to :receiver, :class_name => 'Batch' - belongs_to :receiver ,:class_name=>'Batch' - validates_presence_of :receiver_id , :message => "#{t('batch_cant_be_blank')}" - - validates_uniqueness_of :name, :scope=>[:receiver_id, :type] - - # validates_uniqueness_of :receiver_id, :scope=>[:type,:finance_fee_category_id],:message=>'Discount already exists for batch' - - def total_payable - payable = finance_fee_category.fee_particulars.map(&:amount).compact.flatten.sum - payable - end - - def discount - if is_amount == false - super - elsif is_amount == true - payable = total_payable - percentage = (super.to_f / payable.to_f).to_f * 100 - percentage - end - end + validates_presence_of :receiver_id, :message => "#{t('batch_cant_be_blank')}" + validates_uniqueness_of :name, :scope => [:receiver_id, :type] + # validates_uniqueness_of :receiver_id, :scope => [:type, :finance_fee_category_id],:message => 'Discount already exists for batch' end diff --git a/app/models/finance/fee_collection_discount.rb b/app/models/finance/fee_collection_discount.rb index e4e9f6495..56cd99123 100644 --- a/app/models/finance/fee_collection_discount.rb +++ b/app/models/finance/fee_collection_discount.rb @@ -1,31 +1,30 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class FeeCollectionDiscount < ActiveRecord::Base def category_name - c =StudentCategory.find(self.receiver_id) - c.name unless c.nil? + c = StudentCategory.find_by_id(self.receiver_id) + c.name if c end def student_name - s =Student.find(self.receiver_id) - "#{s.first_name} (#{s.admission_no})" unless s.nil? + s = Student.find_by_id(self.receiver_id) + "#{s.first_name} (#{s.admission_no})" if s end end diff --git a/app/models/finance/fee_collection_particular.rb b/app/models/finance/fee_collection_particular.rb index 6dc0c0504..0e9ea23d8 100644 --- a/app/models/finance/fee_collection_particular.rb +++ b/app/models/finance/fee_collection_particular.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class FeeCollectionParticular < ActiveRecord::Base belongs_to :finance_fee_collection belongs_to :student_category diff --git a/app/models/finance/fee_discount.rb b/app/models/finance/fee_discount.rb index 442366ddb..78e3e1eee 100644 --- a/app/models/finance/fee_discount.rb +++ b/app/models/finance/fee_discount.rb @@ -1,65 +1,55 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class FeeDiscount < ActiveRecord::Base belongs_to :finance_fee_category validates_presence_of :name, :discount, :type validates_numericality_of :discount - - def validate - if is_amount == false - if discount.to_f < 0.00 or discount.to_f > 100.00 - errors.add("discount","must be between 0 to 100") - end - elsif is_amount == true - payable = finance_fee_category.fee_particulars.map(&:amount).compact.flatten.sum - if discount.to_f > payable.to_f - errors.add("discount","cannot be greater than total payable amount") - end - end - end + validate :discount_must_be_between_0_to_100, :discount_cannot_be_greater_than_total_payable_amount def total_payable - payable = finance_fee_category.fee_particulars.map(&:amount).compact.flatten.sum - payable + finance_fee_category.fee_particulars.map(&:amount).compact.flatten.sum end def discount - if is_amount == false - super - elsif is_amount == true - payable = total_payable - percentage = (super.to_f / payable.to_f).to_f * 100 - percentage - end + is_amount? ? (super.to_f / total_payable.to_f).to_f * 100 : super end - - def category_name - c =StudentCategory.find(self.receiver_id) + c = StudentCategory.find_by_id(self.receiver_id) c.name unless c.nil? end def student_name - s =Student.find(self.receiver_id) + s = Student.find_by_id(self.receiver_id) "#{s.first_name} (#{s.admission_no})" unless s.nil? end + private + def discount_must_be_between_0_to_100 + errors.add(:discount,"must be between 0 to 100") if !is_amount? && discount.to_f < 0.00 || discount.to_f > 100.00 + end + + def discount_cannot_be_greater_than_total_payable_amount + if is_amount? + payable = finance_fee_category.fee_particulars.map(&:amount).compact.flatten.sum + errors.add(:discount,"cannot be greater than total payable amount") if discount.to_f > payable.to_f + end + end + end diff --git a/app/models/finance/finance_donation.rb b/app/models/finance/finance_donation.rb index 43afda1c7..d1f288950 100755 --- a/app/models/finance/finance_donation.rb +++ b/app/models/finance/finance_donation.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class FinanceDonation < ActiveRecord::Base belongs_to :transaction, :class_name => 'FinanceTransaction', :dependent => :destroy validates_presence_of :donor, :amount diff --git a/app/models/finance/finance_fee.rb b/app/models/finance/finance_fee.rb index c1eaa8156..c3947971a 100755 --- a/app/models/finance/finance_fee.rb +++ b/app/models/finance/finance_fee.rb @@ -1,35 +1,29 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class FinanceFee < ActiveRecord::Base - + belongs_to :finance_fee_collection ,:foreign_key => 'fee_collection_id' has_many :finance_transactions ,:as=>:finance has_many :components, :class_name => 'FinanceFeeComponent', :foreign_key => 'fee_id' belongs_to :student - def check_transaction_done - unless self.transaction_id.nil? - return true - else - return false - end + self.transaction_id.present? end def former_student diff --git a/app/models/finance/finance_fee_category.rb b/app/models/finance/finance_fee_category.rb index c31e735c9..980e19387 100755 --- a/app/models/finance/finance_fee_category.rb +++ b/app/models/finance/finance_fee_category.rb @@ -1,25 +1,24 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class FinanceFeeCategory < ActiveRecord::Base belongs_to :batch belongs_to :student -# + has_many :fee_particulars, :class_name => "FinanceFeeParticular" has_many :fee_collections, :class_name => "FinanceFeeCollection" has_many :fee_discounts @@ -29,85 +28,75 @@ class FinanceFeeCategory < ActiveRecord::Base @@per_page = 10 validates_presence_of :name - validates_presence_of :batch_id,:message=>"#{t('not_specified')}" - validates_uniqueness_of :name, :scope=>[:batch_id, :is_deleted],:if=> 'is_deleted == false' + validates_presence_of :batch_id,:message => "#{t('not_specified')}" + validates_uniqueness_of :name, :scope => [:batch_id, :is_deleted], :if => 'is_deleted == false' def fees(student) FinanceFeeParticular.find_all_by_finance_fee_category_id(self.id, - :conditions => ["((student_category_id IS NULL AND admission_no IS NULL )OR(student_category_id = '#{student.student_category_id}'AND admission_no IS NULL) OR (student_category_id IS NULL AND admission_no = '#{student.admission_no}')) and is_deleted=0"]) + :conditions => ["((student_category_id IS NULL AND admission_no IS NULL) OR (student_category_id = ? AND admission_no IS NULL) OR (student_category_id IS NULL AND admission_no = ?)) AND is_deleted = ?", student.student_category_id, student.admission_no, false]) end def check_fee_collection - fee_collection = FinanceFeeCollection.find_all_by_fee_category_id(self.id,:conditions=>{:is_deleted=>0}) - fee_collection.empty? ? true : false + FinanceFeeCollection.find_all_by_fee_category_id(self.id, :conditions => { :is_deleted => 0 }).empty? end def check_fee_collection_for_additional_fees - flag =0 fee_collection = FinanceFeeCollection.find_all_by_fee_category_id(self.id) - fee_collection.each do |fee| - flag = 1 if fee.check_fee_category == true - end - flag == 1 ? true : false - + fee_collection.each { |fee| return true if fee.check_fee_category == true } + return false end def delete_particulars - self.fee_particulars.each do |fees| - fees.update_attributes(:is_deleted => true) - end + self.fee_particulars.each { |fees| fees.update_attributes(:is_deleted => true) } end - def student_fee_balance(student,date) - particulars= FinanceFeeParticular.find_all_by_finance_fee_category_id(self.id, - :conditions => ["((student_category_id IS NULL AND admission_no IS NULL )OR(student_category_id = '#{student.student_category_id}'AND admission_no IS NULL) OR (student_category_id IS NULL AND admission_no = '#{student.admission_no}')) and is_deleted=0"]) + def student_fee_balance(student, date) + particulars = FinanceFeeParticular.find_all_by_finance_fee_category_id(self.id, + :conditions => ["( (student_category_id IS NULL AND admission_no IS NULL) OR (student_category_id = ? AND admission_no IS NULL) OR (student_category_id IS NULL AND admission_no = ?) ) AND is_deleted = ?", student.student_category_id, student.admission_no, false]) financefee = student.finance_fee_by_date(date) - paid_fees = FinanceTransaction.find(:all,:conditions=>"FIND_IN_SET(id,\"#{financefee.transaction_id}\")") unless financefee.transaction_id.blank? + paid_fees = FinanceTransaction.find(:all, :conditions => ["FIND_IN_SET(id, ?)", financefee.transaction_id]) unless financefee.transaction_id.blank? batch_discounts = BatchFeeDiscount.find_all_by_finance_fee_category_id(self.id) - student_discounts = StudentFeeDiscount.find_all_by_finance_fee_category_id_and_receiver_id(self.id,student.id) - category_discounts = StudentCategoryFeeDiscount.find_all_by_finance_fee_category_id(self.id, :joins=>'INNER JOIN students ON fee_discounts.receiver_id = students.student_category_id') + student_discounts = StudentFeeDiscount.find_all_by_finance_fee_category_id_and_receiver_id(self.id, student.id) + category_discounts = StudentCategoryFeeDiscount.find_all_by_finance_fee_category_id(self.id, :joins => 'INNER JOIN students ON fee_discounts.receiver_id = students.student_category_id') total_discount = 0 total_discount += batch_discounts.map{|s| s.discount}.sum unless batch_discounts.nil? total_discount += student_discounts.map{|s| s.discount}.sum unless student_discounts.nil? total_discount += category_discounts.map{|s| s.discount}.sum unless category_discounts.nil? - if total_discount > 100 - total_discount = 100 - end - total_fees =0 - unless particulars.nil? + total_discount = 100 if total_discount > 100 + + total_fees = 0 + if particulars.present? total_fees += particulars.collect{|x|x.amount.to_f}.sum total_fees = (total_fees - ((total_fees*total_discount)/100)) - - unless paid_fees.nil? + + if paid_fees.present? paid = 0 paid += paid_fees.collect{|x|x.amount.to_f}.sum total_fees -= paid trans = FinanceTransaction.find(financefee.transaction_id) - unless trans.nil? - total_fees += trans.fine_amount.to_f if trans.fine_included - end + total_fees += trans.fine_amount.to_f if trans && trans.fine_included end end return total_fees end def self.common_active - self.find(:all , :conditions => ["finance_fee_categories.is_master = '#{1}' and finance_fee_categories.is_deleted = '#{false}'"], :joins=>"INNER JOIN batches on finance_fee_categories.batch_id = batches.id AND batches.is_active = 1 AND batches.is_deleted = 0 ",:group => :name) + self.find(:all , :conditions => ["finance_fee_categories.is_master = ? AND finance_fee_categories.is_deleted = ?", 1, false], :joins => "INNER JOIN batches on finance_fee_categories.batch_id = batches.id AND batches.is_active = 1 AND batches.is_deleted = 0 ", :group => :name) end def is_collection_open - collection = FinanceFeeCollection.find_all_by_fee_category_id(self.id,:conditions=>"start_date < '#{Date.today.to_date}' and due_date > '#{Date.today.to_date}'") - collection.reject!{ |c|c.no_transaction_present } unless collection.nil? + collection = FinanceFeeCollection.find_all_by_fee_category_id(self.id, :conditions => ["start_date < ? AND due_date > ?", Date.today.to_date, Date.today.to_date]) + collection.reject!{ |c| c.no_transaction_present } unless collection.nil? collection.present? end def have_common_particular? - self.fee_particulars.find_all_by_student_category_id_and_admission_no(nil,nil).count > 0 ? true : false + self.fee_particulars.find_all_by_student_category_id_and_admission_no(nil, nil).count > 0 end - - + + end diff --git a/app/models/finance/finance_fee_collection.rb b/app/models/finance/finance_fee_collection.rb index bd2bdaa00..774080d2c 100755 --- a/app/models/finance/finance_fee_collection.rb +++ b/app/models/finance/finance_fee_collection.rb @@ -1,60 +1,49 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class FinanceFeeCollection < ActiveRecord::Base belongs_to :batch - has_many :finance_fees, :foreign_key =>"fee_collection_id",:dependent=>:destroy + has_many :finance_fees, :foreign_key => "fee_collection_id", :dependent => :destroy has_many :finance_transactions, :through => :finance_fees has_many :students, :through => :finance_fees - has_many :fee_collection_particulars ,:dependent=>:destroy - has_many :fee_collection_discounts ,:dependent=>:destroy - belongs_to :fee_category,:class_name => "FinanceFeeCategory" + has_many :fee_collection_particulars, :dependent => :destroy + has_many :fee_collection_discounts, :dependent => :destroy + belongs_to :fee_category, :class_name => "FinanceFeeCategory" has_one :event, :as => :origin - - validates_presence_of :name,:start_date,:fee_category_id,:end_date,:due_date + validates_presence_of :name, :start_date, :fee_category_id, :end_date, :due_date + validate :valid_date after_create :create_associates - def validate - unless self.start_date.nil? or self.end_date.nil? - errors.add_to_base("#{t('start_date_cant_be_after_end_date')}") if self.start_date > self.end_date - errors.add_to_base("#{t('start_date_cant_be_after_due_date')}") if self.start_date > self.due_date - errors.add_to_base("#{t('end_date_cant_be_after_due_date')}") if self.end_date > self.due_date - else - end - end - def full_name "#{name} - #{start_date.to_s}" end def fee_transactions(student_id) - FinanceFee.find_by_fee_collection_id_and_student_id(self.id,student_id) + FinanceFee.find_by_fee_collection_id_and_student_id(self.id, student_id) end def check_transaction(transactions) - transactions.finance_fees_id.nil? ? false : true - + !!transactions.finance_fees_id end def fee_table - self.finance_fees.all(:conditions=>"is_paid = 0") + self.finance_fees.all(:conditions => { :is_paid => false }) end def self.shorten_string(string, count) @@ -62,7 +51,7 @@ def self.shorten_string(string, count) shortened = string[0, count] splitted = shortened.split(/\s/) words = splitted.length - splitted[0, words-1].join(" ") + ' ...' + splitted[0, words - 1].join(" ") + ' ...' else string end @@ -70,73 +59,39 @@ def self.shorten_string(string, count) def check_fee_category finance_fees = FinanceFee.find_all_by_fee_collection_id(self.id) - flag = 1 finance_fees.each do |f| - flag = 0 unless f.transaction_id.nil? + return false unless f.transaction_id.nil? end - flag == 1 ? true : false + return true end def no_transaction_present f = FinanceFee.find_all_by_fee_collection_id(self.id) - f.reject! {|x|x.transaction_id.nil?} unless f.nil? + f.reject! { |x| x.transaction_id.nil? } unless f.nil? f.blank? end - def create_associates - - batch_discounts = BatchFeeDiscount.find_all_by_finance_fee_category_id(self.fee_category_id) - batch_discounts.each do |discount| - discount_attributes = discount.attributes - discount_attributes.delete "type" - discount_attributes.delete "finance_fee_category_id" - discount_attributes["finance_fee_collection_id"]= self.id - BatchFeeCollectionDiscount.create(discount_attributes) - end - category_discount = StudentCategoryFeeDiscount.find_all_by_finance_fee_category_id(self.fee_category_id) - category_discount.each do |discount| - discount_attributes = discount.attributes - discount_attributes.delete "type" - discount_attributes.delete "finance_fee_category_id" - discount_attributes["finance_fee_collection_id"]= self.id - StudentCategoryFeeCollectionDiscount.create(discount_attributes) - end - student_discount = StudentFeeDiscount.find_all_by_finance_fee_category_id(self.fee_category_id) - student_discount.each do |discount| - discount_attributes = discount.attributes - discount_attributes.delete "type" - discount_attributes.delete "finance_fee_category_id" - discount_attributes["finance_fee_collection_id"]= self.id - StudentFeeCollectionDiscount.create(discount_attributes) - end - particlulars = FinanceFeeParticular.find_all_by_finance_fee_category_id(self.fee_category_id,:conditions=>"is_deleted=0") - particlulars.each do |p| - particlulars_attributes = p.attributes - particlulars_attributes.delete "finance_fee_category_id" - particlulars_attributes["finance_fee_collection_id"]= self.id - FeeCollectionParticular.create(particlulars_attributes) - end - end - def fees_particulars(student) FeeCollectionParticular.find_all_by_finance_fee_collection_id(self.id, - :conditions => ["((student_category_id IS NULL AND admission_no IS NULL )OR(student_category_id = '#{student.student_category_id}'AND admission_no IS NULL) OR (student_category_id IS NULL AND admission_no = '#{student.admission_no}')) and is_deleted=0"]) + :conditions => ["((student_category_id IS NULL AND admission_no IS NULL) OR (student_category_id = ? AND admission_no IS NULL) OR (student_category_id IS NULL AND admission_no = ?)) and is_deleted = ?", student.student_category_id, student.admission_no, false]) end - def transaction_total(start_date,end_date) - trans = self.finance_transactions.all(:conditions=>"transaction_date >= '#{start_date}' AND transaction_date <= '#{end_date}'") + def transaction_total(start_date, end_date) + trans = self.finance_transactions.all(:conditions => { :transaction_date => start_date..end_date }) total = trans.map{|t|t.amount}.sum end - - def student_fee_balance(student) - particulars= self.fees_particulars(student) + + def student_fee_balance(student_id) + student = Student.find(student_id) + particulars = self.fees_particulars(student) financefee = self.fee_transactions(student.id) + - paid_fees = FinanceTransaction.find(:all,:conditions=>"FIND_IN_SET(id,\"#{financefee.transaction_id}\")") unless financefee.transaction_id.blank? + paid_fees = FinanceTransaction.find(:all, :conditions => [ "FIND_IN_SET(id, ?)", financefee.transaction_id ]) unless financefee.transaction_id.blank? batch_discounts = BatchFeeCollectionDiscount.find_all_by_finance_fee_collection_id(self.id) - student_discounts = StudentFeeCollectionDiscount.find_all_by_finance_fee_collection_id_and_receiver_id(self.id,student.id) - category_discounts = StudentCategoryFeeCollectionDiscount.find_all_by_finance_fee_collection_id_and_receiver_id(self.id,student.student_category_id) + student_discounts = StudentFeeCollectionDiscount.find_all_by_finance_fee_collection_id_and_receiver_id(self.id, student.id) + category_discounts = StudentCategoryFeeCollectionDiscount.find_all_by_finance_fee_collection_id_and_receiver_id(self.id, student.student_category_id) total_discount = 0 total_discount += batch_discounts.map{|s| s.discount}.sum unless batch_discounts.nil? total_discount += student_discounts.map{|s| s.discount}.sum unless student_discounts.nil? @@ -145,9 +100,8 @@ def student_fee_balance(student) total_discount = 100 end - total_fees =0 - particulars.map { |s| total_fees += s.amount.to_f} unless particulars.nil? - total_fees -= total_fees*(total_discount/100) + total_fees = particulars.inject(0) { |result, s| result + s.amount.to_f } unless particulars.nil? + total_fees -= total_fees*(total_discount / 100) unless paid_fees.nil? paid = 0 @@ -161,4 +115,47 @@ def student_fee_balance(student) return total_fees end + private + + def valid_date + if self.start_date.present? && self.end_date.present? + errors.add_to_base("#{t('start_date_cant_be_after_end_date')}") if self.start_date > self.end_date + errors.add_to_base("#{t('start_date_cant_be_after_due_date')}") if self.start_date > self.due_date + errors.add_to_base("#{t('end_date_cant_be_after_due_date')}") if self.end_date > self.due_date + end + end + + def create_associates + batch_discounts = BatchFeeDiscount.find_all_by_finance_fee_category_id(self.fee_category_id) + batch_discounts.each do |discount| + discount_attributes = discount.attributes + discount_attributes.delete "type" + discount_attributes.delete "finance_fee_category_id" + discount_attributes["finance_fee_collection_id"]= self.id + BatchFeeCollectionDiscount.create(discount_attributes) + end + category_discount = StudentCategoryFeeDiscount.find_all_by_finance_fee_category_id(self.fee_category_id) + category_discount.each do |discount| + discount_attributes = discount.attributes + discount_attributes.delete "type" + discount_attributes.delete "finance_fee_category_id" + discount_attributes["finance_fee_collection_id"]= self.id + StudentCategoryFeeCollectionDiscount.create(discount_attributes) + end + student_discount = StudentFeeDiscount.find_all_by_finance_fee_category_id(self.fee_category_id) + student_discount.each do |discount| + discount_attributes = discount.attributes + discount_attributes.delete "type" + discount_attributes.delete "finance_fee_category_id" + discount_attributes["finance_fee_collection_id"]= self.id + StudentFeeCollectionDiscount.create(discount_attributes) + end + particlulars = FinanceFeeParticular.find_all_by_finance_fee_category_id(self.fee_category_id,:conditions=>"is_deleted=0") + particlulars.each do |p| + particlulars_attributes = p.attributes + particlulars_attributes.delete "finance_fee_category_id" + particlulars_attributes["finance_fee_collection_id"]= self.id + FeeCollectionParticular.create(particlulars_attributes) + end + end end diff --git a/app/models/finance/finance_fee_particular.rb b/app/models/finance/finance_fee_particular.rb index 626ae9998..49af43e23 100755 --- a/app/models/finance/finance_fee_particular.rb +++ b/app/models/finance/finance_fee_particular.rb @@ -1,39 +1,33 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class FinanceFeeParticular < ActiveRecord::Base belongs_to :finance_fee_category belongs_to :student_category - validates_presence_of :name,:amount + validates_presence_of :name, :amount validates_numericality_of :amount, :greater_than_or_equal_to => 0, :message => "#{t('must_be_positive')}" - named_scope :active,{ :conditions => { :is_deleted => false}} + named_scope :active, { :conditions => { :is_deleted => false } } cattr_reader :per_page @@per_page = 10 - + def deleted_category - flag = false - category = self.student_category - unless category.blank? - flag = true if category.is_deleted - end - return flag + self.student_category.present? && self.student_category.is_deleted? end end diff --git a/app/models/finance/finance_fee_structure_element.rb b/app/models/finance/finance_fee_structure_element.rb index a7b76e727..d12483edc 100755 --- a/app/models/finance/finance_fee_structure_element.rb +++ b/app/models/finance/finance_fee_structure_element.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class FinanceFeeStructureElement < ActiveRecord::Base # t.decimal :amount, :precision => 8, :scale => 2 @@ -23,135 +22,119 @@ class FinanceFeeStructureElement < ActiveRecord::Base # t.references :batch # t.references :student_category # t.references :student - # t.references :finance_fee # t.references :parent # t.references :fee_collection - + belongs_to :batch belongs_to :student_category belongs_to :student - belongs_to :finance_fee belongs_to :parent, :class_name => 'FinanceFeeStructureElement' belongs_to :fee_collection, :class_name => 'FinanceFeeCollection' has_one :descendant, :class_name => 'FinanceFeeStructureElement', :foreign_key => 'parent_id' def has_descendant_for_student?(student) - FinanceFeeStructureElement.exists?(:parent_id => id, :student_id => student.id, :deleted => false) + FinanceFeeStructureElement.exists?(:parent_id => id, + :student_id => student.id, + :deleted => false) end class << self + def all_fee_components + all(:conditions => {:batch_id => nil, + :student_category_id => nil, + :student_id => nil, + :deleted => false}) + end + + def all_fee_components_by_batch + all(:conditions => "batch_id IS NOT NULL AND + student_id IS NULL AND + student_category_id IS NULL AND + deleted = false") + end + + def all_fee_components_by_category + all(:conditions => "student_category_id IS NOT NULL AND + batch_id IS NULL") + end + + def all_fee_components_by_batch_and_category + all(:conditions => "batch_id IS NOT NULL AND + student_category_id IS NOT NULL") + end + + def fee_components_by_batch_and_category(batch_id, student_category_id) + all(:conditions => { batch_id: batch_id, + student_category_id: student_category_id, + student_id: nil, + deleted: false }) + end + + def student_fee_components_by_batch(batch_id) + all(:conditions => { batch_id: batch_id, + student_category_id: nil, + fee_collection_id: nil, + student_id: nil, + deleted: false }) + end + + def student_fee_components_by_collection(date) + all(:conditions => { student_category_id: nil, + fee_collection_id: date, + student_id: nil, + deleted: false }) + end + + def student_fee_components_by_student(student_id) + all(:conditions => { batch_id: nil, + student_category_id: nil, + student_id: student_id, + parent_id: nil, + deleted: false }) + end + + def student_current_fee_cycle(student_id, date) + all(:conditions => ["student_id = ? AND + fee_collection_id = ? AND + parent_id IS NOT NULL AND + deleted = false", student_id, date]) + end + + def batch_fee_component_by_batch(batch_id) + all(:conditions => ["batch_id = ? AND + student_category_id IS NOT NULL", batch_id]) + end + def get_all_fee_components elements = {} - elements[:all] = find(:all, - :conditions => { - :batch_id => nil, - :student_category_id => nil, - :student_id => nil, - :deleted => false - }) - elements[:by_batch] = find(:all, - :conditions => " - batch_id IS NOT NULL AND - student_id IS NULL AND - student_category_id IS NULL AND - deleted = false - ") - elements[:by_category] = find(:all, :conditions => " - student_category_id IS NOT NULL AND - batch_id IS NULL - ") - elements[:by_batch_and_category] = find(:all, :conditions => " - batch_id IS NOT NULL AND - student_category_id IS NOT NULL - ") + elements[:all] = all_fee_components + elements[:by_batch] = all_fee_components_by_batch + elements[:by_category] = all_fee_components_by_category + elements[:by_batch_and_category] = all_fee_components_by_batch_and_category elements end - def get_student_fee_components(student,date) + def get_student_fee_components(student, date) elements = {} - elements[:all] = find(:all, - :conditions => " - batch_id IS NULL AND - student_category_id IS NULL AND - student_id IS NULL AND - deleted = false" - ) - elements[:by_batch] = find(:all, - :conditions => " - batch_id = #{student.batch_id} AND - student_category_id IS NULL AND - fee_collection_id = NULL AND - student_id IS NULL AND - deleted = false - ") - elements[:by_batch_and_fee_collection] = find(:all, - :conditions => " - - student_category_id IS NULL AND - fee_collection_id = #{date} AND - student_id IS NULL AND - deleted = false - ") - elements[:by_category] = find(:all, :conditions => " - batch_id IS NULL AND - student_category_id = #{student.student_category_id} AND - student_id IS NULL AND - deleted = false - ") - elements[:by_batch_and_category] = find(:all, :conditions => " - batch_id = #{student.batch_id} AND - student_category_id = #{student.student_category_id} AND - student_id IS NULL AND - deleted = false - ") - elements[:student] = find(:all, :conditions => " - batch_id IS NULL AND - student_category_id IS NULL AND - student_id = #{student.id} AND - parent_id IS NULL AND - deleted = false - ") - elements[:student_current_fee_cycle] = find(:all, :conditions => " - student_id = #{student.id} AND - fee_collection_id = #{date} AND - parent_id IS NOT NULL AND - deleted = false - ") + elements[:all] = all_fee_components + elements[:by_batch] = student_fee_components_by_batch(student.batch_id) + elements[:by_batch_and_fee_collection] = student_fee_components_by_collection(date) + elements[:by_category] = fee_components_by_batch_and_category(nil, student.student_category_id) + elements[:by_batch_and_category] = fee_components_by_batch_and_category(student.batch_id, + student.student_category_id) + elements[:student] = student_fee_components_by_student(student.id) + elements[:student_current_fee_cycle] = student_current_fee_cycle(student.id, date) elements end def get_batch_fee_components(batch) elements = {} - elements[:all] = find(:all, - :conditions => " - batch_id IS NULL AND - student_category_id IS NULL AND - student_id IS NULL AND - deleted = false" - ) - elements[:by_batch] = find(:all, - :conditions => " - batch_id = #{batch.id} AND - student_category_id IS NULL AND - student_id IS NULL AND - deleted = false - ") - elements[:by_category] = find(:all, :conditions => " - student_category_id IS NOT NULL AND - batch_id IS NULL - ") - elements[:by_batch_and_category] = find(:all, :conditions => " - batch_id = #{batch.id} AND - student_category_id IS NOT NULL - ") - elements - + elements[:all] = all_fee_components + elements[:by_batch] = fee_components_by_batch_and_category(batch.id, nil) + elements[:by_category] = all_fee_components_by_category + elements[:by_batch_and_category] = batch_fee_component_by_batch(batch.id) elements - end - end - - end diff --git a/app/models/finance/finance_transaction.rb b/app/models/finance/finance_transaction.rb index da21711a6..1a572035c 100755 --- a/app/models/finance/finance_transaction.rb +++ b/app/models/finance/finance_transaction.rb @@ -1,136 +1,124 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class FinanceTransaction < ActiveRecord::Base belongs_to :category, :class_name => 'FinanceTransactionCategory', :foreign_key => 'category_id' belongs_to :student belongs_to :finance, :polymorphic => true belongs_to :payee, :polymorphic => true cattr_reader :per_page - validates_presence_of :title,:amount,:transaction_date - validates_presence_of :category,:message=>"#{t('not_specified')}." + validates_presence_of :title, :amount, :transaction_date + validates_presence_of :category, :message => "#{t('not_specified')}" validates_numericality_of :amount, :greater_than_or_equal_to => 0, :message => "#{t('must_be_positive')}" after_create :create_auto_transaction after_update :update_auto_transaction after_destroy :delete_auto_transaction - after_create :add_voucher_or_receipt_number + after_create :add_voucher_or_receipt_number - def self.report(start_date,end_date,page) - cat_names = ['Fee','Salary','Donation'] + def self.report(start_date, end_date, page) + cat_names = ['Fee', 'Salary', 'Donation'] FedenaPlugin::FINANCE_CATEGORY.each do |category| cat_names << "#{category[:category_name]}" end - fixed_cat_ids = FinanceTransactionCategory.find(:all,:conditions=>{:name=>cat_names}).collect(&:id) - self.find(:all, - :conditions => ["transaction_date >= '#{start_date}' and transaction_date <= '#{end_date}'and category_id NOT IN (#{fixed_cat_ids.join(",")})"], - :order => 'transaction_date' ) + + fixed_cat_ids = FinanceTransactionCategory.find(:all, :conditions => { :name => cat_names }).collect(&:id) + self.find(:all, + :conditions => ["transaction_date >= ? AND transaction_date <= ? AND category_id NOT IN (?)", start_date, end_date, fixed_cat_ids.join(",")], + :order => 'transaction_date') end - def self.grand_total(start_date,end_date) + def self.grand_total(start_date, end_date) fee_id = FinanceTransactionCategory.find_by_name("Fee").id donation_id = FinanceTransactionCategory.find_by_name("Donation").id - cat_names = ['Fee','Salary','Donation'] + cat_names = ['Fee', 'Salary', 'Donation'] plugin_name = [] + FedenaPlugin::FINANCE_CATEGORY.each do |category| cat_names << "#{category[:category_name]}" plugin_name << "#{category[:category_name]}" end - fixed_categories = FinanceTransactionCategory.find(:all,:conditions=>{:name=>cat_names}) + fixed_categories = FinanceTransactionCategory.find(:all, :conditions => { :name => cat_names }) fixed_cat_ids = fixed_categories.collect(&:id) fixed_transactions = FinanceTransaction.find(:all , - :conditions => ["transaction_date >= '#{start_date}' and transaction_date <= '#{end_date}'and category_id IN (#{fixed_cat_ids.join(",")})"]) + :conditions => ["transaction_date >= ? AND transaction_date <= ? AND category_id IN (#{fixed_cat_ids.join(",")})", start_date, end_date]) other_transactions = FinanceTransaction.find(:all , - :conditions => ["transaction_date >= '#{start_date}' and transaction_date <= '#{end_date}'and category_id NOT IN (#{fixed_cat_ids.join(",")})"]) - # transactions_fees = FinanceTransaction.find(:all, - # :conditions => ["transaction_date >= '#{start_date}' and transaction_date <= '#{end_date}'and category_id ='#{fee_id}'"]) - # donations = FinanceTransaction.find(:all, - # :conditions => ["transaction_date >= '#{start_date}' and transaction_date <= '#{end_date}'and category_id ='#{donation_id}'"]) + :conditions => ["transaction_date >= ? AND transaction_date <= ? AND category_id NOT IN (#{fixed_cat_ids.join(",")})", start_date, end_date]) trigger = FinanceTransactionTrigger.find(:all) hr = Configuration.find_by_config_value("HR") income_total = 0 expenses_total = 0 - fees_total =0 + fees_total = 0 salary = 0 - - unless hr.nil? + + if hr salary = MonthlyPayslip.total_employees_salary(start_date, end_date) expenses_total += salary[:total_salary].to_f end - + transactions_fees = fixed_transactions.reject{|tr|tr.category_id != fee_id} donations = fixed_transactions.reject{|tr|tr.category_id != donation_id} donations.each do |d| - if d.master_transaction_id == 0 - income_total +=d.amount - else - expenses_total +=d.amount - end - + d.master_transaction_id == 0 ? income_total += d.amount : expenses_total += d.amount end + transactions_fees.each do |fees| - income_total +=fees.amount + income_total += fees.amount fees_total += fees.amount end # plugin transactions plugin_name.each do |p| category = fixed_categories.reject{|cat|cat.name.downcase != p.downcase} - unless category.blank? + if category.present? cat_id = category.first.id transactions_plugin = fixed_transactions.reject{|tr|tr.category_id != cat_id} transactions_plugin.each do |t| - if t.category.is_income? - income_total +=t.amount - else - expenses_total +=t.amount - end + t.category.is_income? ? income_total += t.amount : expenses_total += t.amount end end end - + other_transactions.each do |t| - if t.category.is_income? and t.master_transaction_id == 0 - income_total +=t.amount + if t.category.is_income? && t.master_transaction_id == 0 + income_total += t.amount else - expenses_total +=t.amount + expenses_total += t.amount end end - income_total-expenses_total - + income_total - expenses_total end - def self.total_fees(start_date,end_date) + def self.total_fees(start_date, end_date) fee_id = FinanceTransactionCategory.find_by_name("Fee").id fees = 0 fees = FinanceTransaction.find(:all, - :conditions => ["transaction_date >= '#{start_date.to_date}' and transaction_date <= '#{end_date.to_date}'and category_id ='#{fee_id}'"]).map{|ft| ft.amount}.sum + :conditions => ["transaction_date >= ? AND transaction_date <= ? AND category_id = ?", start_date.to_date, end_date.to_date, fee_id]).map{|ft| ft.amount}.sum end - def self.total_other_trans(start_date,end_date) - cat_names = ['Fee','Salary','Donation'] + def self.total_other_trans(start_date, end_date) + cat_names = ['Fee', 'Salary', 'Donation'] FedenaPlugin::FINANCE_CATEGORY.each do |category| cat_names << "#{category[:category_name]}" end - fixed_cat_ids = FinanceTransactionCategory.find(:all,:conditions=>{:name=>cat_names}).collect(&:id) + fixed_cat_ids = FinanceTransactionCategory.find(:all, :conditions => { :name => cat_names }).collect(&:id) fees = 0 - transactions = FinanceTransaction.find(:all, :conditions => ["created_at >= '#{start_date}' and created_at <= '#{end_date}'and category_id NOT IN (#{fixed_cat_ids.join(",")})"]) + transactions = FinanceTransaction.find(:all, :conditions => ["created_at >= ? AND created_at <= ? AND category_id NOT IN (#{fixed_cat_ids.join(",")})", start_date, end_date]) transactions_income = transactions.reject{|x| !x.category.is_income? }.compact transactions_expense = transactions.reject{|x| x.category.is_income? }.compact income = 0 @@ -141,70 +129,36 @@ def self.total_other_trans(start_date,end_date) transactions_expense.each do |f| expense += f.amount end - [income,expense] + [income, expense] end - def self.donations_triggers(start_date,end_date) - donation_id = FinanceTransactionCategory.find_by_name("Donation").id - donations_income =0 - donations_expenses =0 - donations = FinanceTransaction.find(:all,:conditions => ["transaction_date >= '#{start_date}' and transaction_date <= '#{end_date}' and master_transaction_id = 0 and category_id ='#{donation_id}'"]) - trigger = FinanceTransaction.find(:all,:conditions => ["transaction_date >= '#{start_date}' and transaction_date <= '#{end_date}' and master_transaction_id != 0 and category_id ='#{donation_id}'"]) - donations.each do |d| - if d.category.is_income? - donations_income+=d.amount - else - donations_expenses+=d.amount + def self.donations_triggers(start_date, end_date) + donation = FinanceTransactionCategory.find_by_name("Donation") + donations_income = 0 + donations_expenses = 0 + if donation + donations = FinanceTransaction.find(:all, :conditions => ["transaction_date >= ? AND transaction_date <= ? AND master_transaction_id = 0 AND category_id = ?", start_date, end_date, donation.id]) + trigger = FinanceTransaction.find(:all, :conditions => ["transaction_date >= ? AND transaction_date <= ? AND master_transaction_id != 0 AND category_id = ?", start_date, end_date, donation.id]) + donations.each do |d| + d.category.is_income? ? donations_income += d.amount : donations_expenses += d.amount + end + trigger.each do |t| + donations_expenses += t.amount end end - trigger.each do |t| - #unless t.finance_category.id.nil? - # if d.category_id == t.finance_category.id - donations_expenses += t.amount - #end - #end - end - donations_income-donations_expenses - + donations_income - donations_expenses end - def self.expenses(start_date,end_date) - expenses = FinanceTransaction.find(:all, :select=>'finance_transactions.*', :joins=>' INNER JOIN finance_transaction_categories ON finance_transaction_categories.id = finance_transactions.category_id',\ - :conditions => ["finance_transaction_categories.is_income = 0 and finance_transaction_categories.id != 1 and transaction_date >= '#{start_date}' and transaction_date <= '#{end_date}'"]) - expenses - end - - def self.incomes(start_date,end_date) - incomes = FinanceTransaction.find(:all, :select=>'finance_transactions.*', :joins=>' INNER JOIN finance_transaction_categories ON finance_transaction_categories.id = finance_transactions.category_id',\ - :conditions => ["finance_transaction_categories.is_income = 1 and transaction_date >= '#{start_date}' and transaction_date <= '#{end_date}' "]) - incomes = incomes.reject{|income| (income.category.is_fixed or income.master_transaction_id != 0)} - incomes + def self.expenses(start_date, end_date) + expenses = FinanceTransaction.find(:all, :select => 'finance_transactions.*', :joins => 'INNER JOIN finance_transaction_categories ON finance_transaction_categories.id = finance_transactions.category_id', + :conditions => ["finance_transaction_categories.is_income = 0 AND finance_transaction_categories.id != 1 AND transaction_date >= ? AND transaction_date <= ?", start_date, end_date]) end - def create_auto_transaction - if self.master_transaction_id == 0 - trigger = FinanceTransactionTrigger.find(:all,:conditions=>['finance_category_id = ?',self.category_id]) - trigger.each do |t| - trigger_amount = (self.amount * t.percentage ) / 100 - FinanceTransaction.create(:title=> self.title + ' - ' + t.title.to_s ,:transaction_date=>self.transaction_date, \ - :amount=>trigger_amount,:category_id =>self.category_id,:master_transaction_id=>self.id) - end - end - end - - def update_auto_transaction - FinanceTransaction.find_all_by_master_transaction_id(self.id).each do |f| - f.destroy - end - if self.master_transaction_id == 0 - trigger = FinanceTransactionTrigger.find(:all,:conditions=>['finance_category_id = ?',self.category_id]) - trigger.each do |t| - trigger_amount = (self.amount * t.percentage ) / 100 - FinanceTransaction.create(:title=> self.title + ' - ' + t.title.to_s ,:transaction_date=>self.transaction_date, \ - :amount=>trigger_amount,:category_id =>self.category_id,:master_transaction_id=>self.id) - end - end + def self.incomes(start_date, end_date) + incomes = FinanceTransaction.find(:all, :select => 'finance_transactions.*', :joins => 'INNER JOIN finance_transaction_categories ON finance_transaction_categories.id = finance_transactions.category_id', + :conditions => ["finance_transaction_categories.is_income = 1 AND transaction_date >= ? AND transaction_date <= ?", start_date, end_date]) + incomes = incomes.reject{|income| (income.category.fixed? || income.master_transaction_id != 0)} end def student_payee @@ -212,52 +166,78 @@ def student_payee stu ||= ArchivedStudent.find_by_former_id(self.payee_id) end + private - def delete_auto_transaction - FinanceTransaction.find_all_by_master_transaction_id(self.id).each do |f| - f.destroy + def create_auto_transaction + if self.master_transaction_id == 0 + trigger = FinanceTransactionTrigger.find(:all, :conditions => ['finance_category_id = ?', self.category_id]) + trigger.each do |t| + trigger_amount = (self.amount * t.percentage) / 100 + FinanceTransaction.create(:title => self.title + ' - ' + t.title.to_s , :transaction_date => self.transaction_date, + :amount => trigger_amount, :category_id => self.category_id, :master_transaction_id => self.id) + end + end end - end - def self.total_transaction_amount(transaction_category,start_date,end_date) - amount = 0 - finance_transaction_category = FinanceTransactionCategory.find_by_name("#{transaction_category}") - category_type = finance_transaction_category.is_income ? "income" : "expense" - transactions = FinanceTransaction.find(:all, - :conditions => ["transaction_date >= '#{start_date}' and transaction_date <= '#{end_date}'and category_id ='#{finance_transaction_category.id}'"]) - transactions.each {|transaction| amount += transaction.amount} - return {:amount=>amount,:category_type=>category_type} - end - - def add_voucher_or_receipt_number - if self.category.is_income and self.master_transaction_id == 0 - last_transaction = FinanceTransaction.last(:conditions=>"receipt_no IS NOT NULL") - last_receipt_no = last_transaction.receipt_no unless last_transaction.nil? - unless last_receipt_no.nil? - receipt_split = last_receipt_no.to_s.scan(/[A-Z]+|\d+/i) - if receipt_split[1].blank? - receipt_number = receipt_split[0].next - else - receipt_number = receipt_split[0]+receipt_split[1].next + def update_auto_transaction + FinanceTransaction.find_all_by_master_transaction_id(self.id).each do |f| + f.destroy + end + if self.master_transaction_id == 0 + trigger = FinanceTransactionTrigger.find(:all, :conditions => ['finance_category_id = ?', self.category_id]) + trigger.each do |t| + trigger_amount = (self.amount * t.percentage) / 100 + FinanceTransaction.create(:title => self.title + ' - ' + t.title.to_s, :transaction_date => self.transaction_date, + :amount => trigger_amount, :category_id => self.category_id, :master_transaction_id => self.id) end - else - receipt_number = "1" end - self.update_attributes(:receipt_no=>receipt_number) - else - last_transaction = FinanceTransaction.last(:conditions=>"voucher_no IS NOT NULL") - last_voucher_no = last_transaction.voucher_no unless last_transaction.nil? - unless last_voucher_no.nil? - voucher_split = last_voucher_no.to_s.scan(/[A-Z]+|\d+/i) - if voucher_split[1].blank? - voucher_number = voucher_split[0].next + end + + def delete_auto_transaction + FinanceTransaction.find_all_by_master_transaction_id(self.id).each do |f| + f.destroy + end + end + + def self.total_transaction_amount(transaction_category,start_date,end_date) + amount = 0 + finance_transaction_category = FinanceTransactionCategory.find_by_name("#{transaction_category}") + category_type = finance_transaction_category.is_income ? "income" : "expense" + transactions = FinanceTransaction.find(:all, + :conditions => ["transaction_date >= ? AND transaction_date <= AND category_id = ?", start_date, end_date, finance_transaction_category.id]) + transactions.each {|transaction| amount += transaction.amount} + return {:amount=>amount,:category_type=>category_type} + end + + def add_voucher_or_receipt_number + if self.category.is_income && self.master_transaction_id == 0 + last_transaction = FinanceTransaction.last(:conditions => "receipt_no IS NOT NULL") + last_receipt_no = last_transaction.receipt_no if last_transaction + if last_receipt_no + receipt_split = last_receipt_no.to_s.scan(/[A-Z]+|\d+/i) + if receipt_split[1].blank? + receipt_number = receipt_split[0].next + else + receipt_number = receipt_split[0] + receipt_split[1].next + end else - voucher_number = voucher_split[0]+voucher_split[1].next + receipt_number = "1" end + self.update_attributes(:receipt_no => receipt_number) else - voucher_number = "1" + last_transaction = FinanceTransaction.last(:conditions => "voucher_no IS NOT NULL") + last_voucher_no = last_transaction.voucher_no if last_transaction + if last_voucher_no + voucher_split = last_voucher_no.to_s.scan(/[A-Z]+|\d+/i) + if voucher_split[1].blank? + voucher_number = voucher_split[0].next + else + voucher_number = voucher_split[0]+voucher_split[1].next + end + else + voucher_number = "1" + end + self.update_attributes(:voucher_no=>voucher_number) end - self.update_attributes(:voucher_no=>voucher_number) end - end end diff --git a/app/models/finance/finance_transaction_category.rb b/app/models/finance/finance_transaction_category.rb index f7d95e96e..8310b8d67 100755 --- a/app/models/finance/finance_transaction_category.rb +++ b/app/models/finance/finance_transaction_category.rb @@ -1,70 +1,57 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class FinanceTransactionCategory < ActiveRecord::Base - has_many :finance_transactions,:class_name => 'FinanceTransaction', :foreign_key => 'category_id' - has_one :trigger, :class_name => "FinanceTransactionTrigger", :foreign_key => "category_id" - + has_many :finance_transactions, :class_name => 'FinanceTransaction', :foreign_key => 'category_id' + has_one :trigger, :class_name => "FinanceTransactionTrigger", :foreign_key => "finance_category_id" validates_presence_of :name validates_uniqueness_of :name, :case_sensitive => false named_scope :expense_categories, :conditions => "is_income = false AND name NOT LIKE 'Salary'and deleted = 0" - # named_scope :income_categories, :conditions => "is_income = true AND name NOT IN ('Fee','Salary','Donation','Library','Hostel','Transport') and deleted = 0" - # def self.expense_categories - # FinanceTransactionCategory.all(:conditions => "is_income = false AND name NOT LIKE 'Salary'") - # end - # - # def self.income_categories - # FinanceTransactionCategory.all(:conditions => "is_income = true AND name NOT LIKE 'Fee' AND name NOT LIKE 'Donation'") - # end - - def self.income_categories - cat_names = ["'Fee'","'Salary'","'Donation'"] + def self.income_category_names + cat_names = ['Fee', 'Salary', 'Donation'] FedenaPlugin::FINANCE_CATEGORY.each do |category| - cat_names << "'#{category[:category_name]}'" + cat_names << "#{category[:category_name]}" end - self.find(:all,:conditions=>"is_income = true AND name NOT IN (#{cat_names.join(',')}) and deleted = 0") + cat_names end - def is_fixed - cat_names = ['fee','salary','donation'] - FedenaPlugin::FINANCE_CATEGORY.each do |category| - cat_names << "#{category[:category_name].downcase}" - end - return true if cat_names.include?(self.name.downcase) - return false + INCOME_CATEGORY_NAMES = self.income_category_names + FIX_CATEGORY_NAMES = INCOME_CATEGORY_NAMES.map(&:downcase) + + def self.income_categories + self.all(:conditions => ["is_income = true AND name NOT IN (?) and deleted = 0", INCOME_CATEGORY_NAMES]) end - def total_income(start_date,end_date) - if is_income - self.finance_transactions.find(:all,:conditions => ["transaction_date >= '#{start_date}' and transaction_date <= '#{end_date}' and master_transaction_id=0"]).map{|ft| ft.amount}.sum - else - 0 - end + def fixed? + FIX_CATEGORY_NAMES.include?(self.name.downcase) + end + + def total_income(start_date, end_date) + is_income ? self.finance_transactions.sum(:amount, :conditions => ["transaction_date BETWEEN ? AND ? and master_transaction_id = 0", start_date, end_date]) : 0 end def total_expense(start_date,end_date) if is_income - self.finance_transactions.find(:all,:conditions => ["transaction_date >= '#{start_date}' and transaction_date <= '#{end_date}' and master_transaction_id!=0"]).map{|ft| ft.amount}.sum + self.finance_transactions.sum(:amount, :conditions => ["transaction_date BETWEEN ? AND ? and master_transaction_id != 0", start_date, end_date]) else - self.finance_transactions.find(:all,:conditions => ["transaction_date >= '#{start_date}' and transaction_date <= '#{end_date}'"]).map{|ft| ft.amount}.sum + self.finance_transactions.sum(:amount, :conditions => ["transaction_date BETWEEN ? AND ?", start_date, end_date]) end end diff --git a/app/models/finance/finance_transaction_trigger.rb b/app/models/finance/finance_transaction_trigger.rb index d51d00faa..f144a85c9 100755 --- a/app/models/finance/finance_transaction_trigger.rb +++ b/app/models/finance/finance_transaction_trigger.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class FinanceTransactionTrigger < ActiveRecord::Base belongs_to :finance_category, :class_name => "FinanceTransactionCategory", :foreign_key => 'finance_category_id' validates_presence_of :percentage diff --git a/app/models/finance/liability.rb b/app/models/finance/liability.rb index 90e1f87ec..ccee24dc7 100755 --- a/app/models/finance/liability.rb +++ b/app/models/finance/liability.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class Liability < ActiveRecord::Base validates_presence_of :title, :amount validates_numericality_of :amount diff --git a/app/models/finance/student_category_fee_collection_discount.rb b/app/models/finance/student_category_fee_collection_discount.rb index fc983e9a4..b3be6acd8 100644 --- a/app/models/finance/student_category_fee_collection_discount.rb +++ b/app/models/finance/student_category_fee_collection_discount.rb @@ -1,20 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class StudentCategoryFeeCollectionDiscount < FeeCollectionDiscount @@ -30,7 +30,7 @@ def total_payable(student = nil) end payable end - + def discount(student = nil) if is_amount == false super diff --git a/app/models/finance/student_category_fee_discount.rb b/app/models/finance/student_category_fee_discount.rb index b34bd8085..337807e5a 100644 --- a/app/models/finance/student_category_fee_discount.rb +++ b/app/models/finance/student_category_fee_discount.rb @@ -1,50 +1,27 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class StudentCategoryFeeDiscount < FeeDiscount - belongs_to :receiver ,:class_name=>'StudentCategory' - validates_presence_of :receiver_id , :message => "#{t('student_category_cant_be_blank')}" - - validates_uniqueness_of :name, :scope=>[:finance_fee_category_id, :type] + belongs_to :receiver, :class_name => 'StudentCategory' + validates_presence_of :receiver_id, :message => "#{t('student_category_cant_be_blank')}" + validates_uniqueness_of :name, :scope => [:finance_fee_category_id, :type] #validates_uniqueness_of :receiver_id, :scope=>[:type,:finance_fee_category_id],:message=>'Discount already exists for the student category' - - def total_payable - payable = finance_fee_collection.fee_category.fee_particulars.map(&:amount).compact.flatten.sum - payable - end - - def discount - if is_amount == false - super - elsif is_amount == true - payable = total_payable - percentage = (super.to_f / payable.to_f).to_f * 100 - percentage - end - end - - def category_name - c =StudentCategory.find(self.receiver_id) - c.name unless c.nil? - end - end diff --git a/app/models/finance/student_fee_collection_discount.rb b/app/models/finance/student_fee_collection_discount.rb index 8462dff86..f90b5106c 100644 --- a/app/models/finance/student_fee_collection_discount.rb +++ b/app/models/finance/student_fee_collection_discount.rb @@ -1,32 +1,28 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class StudentFeeCollectionDiscount < FeeCollectionDiscount - belongs_to :receiver ,:class_name=>'Student' - - validates_presence_of :receiver_id , :message => "#{t('student_admission_no_cant_be_blank')}" - - + belongs_to :receiver ,:class_name => 'Student' + validates_presence_of :receiver_id, :message => "#{t('student_admission_no_cant_be_blank')}" def student_name - s =Student.find(self.receiver_id) + s = Student.find(self.receiver_id) "#{s.first_name} (#{s.admission_no})" unless s.nil? end - + end diff --git a/app/models/finance/student_fee_discount.rb b/app/models/finance/student_fee_discount.rb index c3fc5e7ec..362383398 100644 --- a/app/models/finance/student_fee_discount.rb +++ b/app/models/finance/student_fee_discount.rb @@ -1,45 +1,24 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class StudentFeeDiscount < FeeDiscount - - belongs_to :receiver ,:class_name=>'Student' - - validates_presence_of :receiver_id , :message => "#{t('student_admission_no_cant_be_blank')}" - - validates_uniqueness_of :name, :scope=>[:finance_fee_category_id, :type, :receiver_id ] + belongs_to :receiver, :class_name => 'Student' + validates_presence_of :receiver_id, :message => "#{t('student_admission_no_cant_be_blank')}" + validates_uniqueness_of :name, :scope => [:finance_fee_category_id, :type, :receiver_id] # validates_uniqueness_of :receiver_id, :scope=>[:type,:finance_fee_category_id],:message=>'Discount already exists for the student' - - def total_payable - payable = finance_fee_category.fee_particulars.map(&:amount).compact.flatten.sum - payable - end - - def discount - if is_amount == false - super - elsif is_amount == true - payable = total_payable - percentage = (super.to_f / payable.to_f).to_f * 100 - percentage - end - end - end diff --git a/app/models/grading_level.rb b/app/models/grading_level.rb index e5dfb78a2..4a33091dc 100755 --- a/app/models/grading_level.rb +++ b/app/models/grading_level.rb @@ -1,66 +1,60 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class GradingLevel < ActiveRecord::Base belongs_to :batch validates_presence_of :name, :min_score - validates_presence_of :credit_points, :if=>:batch_has_gpa - validates_uniqueness_of :name, :scope => [:batch_id, :is_deleted],:case_sensitive => false + validates_presence_of :credit_points, :if => :batch_has_gpa? + validates_uniqueness_of :name, :scope => [:batch_id, :is_deleted]#, :case_sensitive => false - default_scope :order => 'min_score desc' + default_scope :order => 'min_score DESC' named_scope :default, :conditions => { :batch_id => nil, :is_deleted => false } - named_scope :for_batch, lambda { |b| { :conditions => { :batch_id => b.to_i, :is_deleted => false } } } + named_scope :for_batch, lambda { |b| { :conditions => { :batch_id => b, :is_deleted => false } } } def inactivate - update_attribute :is_deleted, true - end - - def batch_has_gpa - self.batch_id and self.batch.gpa_enabled? + update_attribute(:is_deleted, true) end def to_s name end - def self.exists_for_batch?(batch_id) - batch_grades = GradingLevel.find_all_by_batch_id(batch_id, :conditions=> 'is_deleted = false') + def self.exists_for_batch?(batch_id) + batch_grades = GradingLevel.find_all_by_batch_id(batch_id, :conditions => { :is_deleted => false }) default_grade = GradingLevel.default - if batch_grades.blank? and default_grade.blank? - return false + batch_grades.present? && default_grade.present? + end + + def self.percentage_to_grade(percent_score, batch_id) + batch_grades = GradingLevel.for_batch(batch_id) + if batch_grades.empty? + grade = GradingLevel.default.find(:first, :conditions => [ 'min_score <= ?', percent_score.round ], :order => 'min_score DESC') else - return true + grade = GradingLevel.for_batch(batch_id).find(:first, + :conditions => [ 'min_score <= ?', percent_score.round ], :order => 'min_score DESC') end + grade end - - class << self - def percentage_to_grade(percent_score, batch_id) - batch_grades = GradingLevel.for_batch(batch_id) - if batch_grades.empty? - grade = GradingLevel.default.find :first, - :conditions => [ "min_score <= ?", percent_score.round ], :order => 'min_score desc' - else - grade = GradingLevel.for_batch(batch_id).find :first, - :conditions => [ "min_score <= ?", percent_score.round ], :order => 'min_score desc' - end - grade - end + private + + def batch_has_gpa? + batch_id? && batch.gpa_enabled? end + end diff --git a/app/models/grouped_batch.rb b/app/models/grouped_batch.rb index b6f2cacc1..e8bca4b59 100644 --- a/app/models/grouped_batch.rb +++ b/app/models/grouped_batch.rb @@ -1,20 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class GroupedBatch < ActiveRecord::Base belongs_to :batch_group belongs_to :batch diff --git a/app/models/grouped_exam.rb b/app/models/grouped_exam.rb index 902c10e2c..c7b4a6d63 100755 --- a/app/models/grouped_exam.rb +++ b/app/models/grouped_exam.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class GroupedExam < ActiveRecord::Base has_many :exam_groups end diff --git a/app/models/grouped_exam_report.rb b/app/models/grouped_exam_report.rb index a6a8d09f8..cf302bee4 100644 --- a/app/models/grouped_exam_report.rb +++ b/app/models/grouped_exam_report.rb @@ -1,20 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class GroupedExamReport < ActiveRecord::Base belongs_to :batch belongs_to :student diff --git a/app/models/guardian.rb b/app/models/guardian.rb index 8bf086a76..f24222ac0 100755 --- a/app/models/guardian.rb +++ b/app/models/guardian.rb @@ -1,36 +1,32 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class Guardian < ActiveRecord::Base belongs_to :country belongs_to :ward, :class_name => 'Student' belongs_to :user - validates_presence_of :first_name, :relation,:ward_id - validates_format_of :email, :with => /^[A-Z0-9._%-]+@([A-Z0-9-]+\.)+[A-Z]{2,4}$/i, :allow_blank=>true, + validates_presence_of :first_name, :relation, :ward_id + validates_format_of :email, :with => /\A[A-Z0-9._%-]+@([A-Z0-9-]+\.)+[A-Z]{2,4}\z/i, :allow_blank => true, :message => "#{t('must_be_a_valid_email_address')}" before_destroy :immediate_contact_nil + validate :cant_be_a_future_date - def validate - errors.add(:dob, "#{t('cant_be_a_future_date')}.") if self.dob > Date.today unless self.dob.nil? - end - - def is_immediate_contact? + def immediate_contact? ward.immediate_contact_id == id end @@ -53,30 +49,32 @@ def create_guardian_user(student) user = User.new do |u| u.first_name = self.first_name u.last_name = self.last_name - u.username = "p"+student.admission_no.to_s + u.username = "p" + student.admission_no.to_s u.password = "p#{student.admission_no.to_s}123" u.role = 'Parent' u.email = ( email == '' or User.active.find_by_email(self.email) ) ? "" :self.email.to_s - end + end self.update_attributes(:user_id => user.id) if user.save end - - def self.shift_user(student) self.find_all_by_ward_id(student.id).each do |g| parent_user = g.user - parent_user.soft_delete if parent_user.present? and (parent_user.is_deleted==false) + parent_user.soft_delete if parent_user.present? && (parent_user.is_deleted == false) end - current_guardian = student.immediate_contact - current_guardian.create_guardian_user(student) if current_guardian.present? + + current_guardian = student.immediate_contact + current_guardian.create_guardian_user(student) if current_guardian.present? + end + + private + def cant_be_a_future_date + errors.add(:dob, "#{t('cant_be_a_future_date')}.") if self.dob && self.dob > Date.current end def immediate_contact_nil - student = self.ward - if student.present? and (student.immediate_contact_id==self.id) - student.update_attributes(:immediate_contact_id=>nil) + if ward.present? && immediate_contact? + ward.update_attributes(:immediate_contact_id => nil) end end - end diff --git a/app/models/hr/apply_leave.rb b/app/models/hr/apply_leave.rb index df5deef27..9e2d3f685 100755 --- a/app/models/hr/apply_leave.rb +++ b/app/models/hr/apply_leave.rb @@ -1,67 +1,94 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class ApplyLeave < ActiveRecord::Base - validates_presence_of :employee_leave_types_id, :start_date, :end_date, :reason + validates_presence_of :employee_leave_type_id, :start_date, :end_date, :reason belongs_to :employee belongs_to :employee_leave_type before_create :check_leave_count - + cattr_reader :per_page @@per_page = 12 def check_leave_count - unless self.start_date.nil? or self.end_date.nil? + unless self.start_date.nil? || self.end_date.nil? errors.add_to_base("#{t('end_date_cant_before_start_date')}") if self.end_date < self.start_date - end - unless self.start_date.nil? or self.end_date.nil? or self.employee_leave_types_id.nil? - leave = EmployeeLeave.find_by_employee_id(self.employee_id, :conditions=> "employee_leave_type_id = '#{self.employee_leave_types_id}'") - leave_required = (self.end_date.to_date-self.start_date.to_date).numerator+1 - if self.start_date.to_date < self.employee.joining_date.to_date - errors.add_to_base("#{t('date_marked_is_before_join_date')}") - else + unless self.start_date.nil? || self.end_date.nil? || self.employee_leave_type_id.nil? + leave = EmployeeLeave.find_by_employee_id_and_employee_leave_type_id(self.employee_id, + self.employee_leave_type_id) + leave_required = (self.end_date.to_date-self.start_date.to_date).numerator + 1 + if self.employee.present? && self.start_date.to_date < self.employee.joining_date.to_date + errors.add_to_base("#{t('date_marked_is_before_join_date')}") + elsif leave.present? if leave.leave_taken.to_f == leave.leave_count.to_f errors.add_to_base("#{t('you_have_already_availed')}") - else if self.is_half_day == true new_leave_count = (leave_required)/2 if leave.leave_taken.to_f+new_leave_count.to_f > leave.leave_count.to_f errors.add_to_base("#{t('no_of_leaves_exceeded_max_allowed')}") - end else new_leave_count = leave_required.to_f if leave.leave_taken.to_f+new_leave_count.to_f > leave.leave_count.to_f errors.add_to_base("#{t('no_of_leaves_exceeded_max_allowed')}") - end end end end end - if self.errors.present? - return false - else - return true + + self.errors.present? ? false : true + end + + def approve(manager_remark) + update_attributes(:approved => true, + :viewed_by_manager => true, + :manager_remark => manager_remark) + end + + def deny(manager_remark) + update_attributes(:viewed_by_manager => true, + :manager_remark => manager_remark) + end + + def create_employee_attendance(day) + EmployeeAttendance.create(:attendance_date => day, + :employee_id => self.id, + :employee_leave_type_id => employee_leave_type_id, + :reason => reason, + :is_half_day => is_half_day) + end + + def calculate_reset_count(params) + if self.approve(params[:manager_remark]) + (start_date..end_date).each do |day| + unless day.sunday? + create_employee_attendance(day) + att = EmployeeAttendance.find_by_attendance_date(day) + att.try(:update_attributes, { is_half_day: is_half_day }) + reset_count = EmployeeLeave.find_by_employee_id_and_employee_leave_type_id(employee_id, + employee_leave_type_id) + reset_count.update_leave_taken_by(is_half_day) + end + end end end end diff --git a/app/models/hr/bank_field.rb b/app/models/hr/bank_field.rb index 23109796f..02df4f6b6 100755 --- a/app/models/hr/bank_field.rb +++ b/app/models/hr/bank_field.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class BankField < ActiveRecord::Base validates_presence_of :name end diff --git a/app/models/hr/employee.rb b/app/models/hr/employee.rb index 515f49893..f5b3d9ef9 100755 --- a/app/models/hr/employee.rb +++ b/app/models/hr/employee.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class Employee < ActiveRecord::Base belongs_to :employee_category belongs_to :employee_position @@ -24,7 +23,7 @@ class Employee < ActiveRecord::Base belongs_to :nationality, :class_name => 'Country' belongs_to :user belongs_to :reporting_manager,:class_name => "Employee" - + has_many :employees_subjects has_many :subjects ,:through => :employees_subjects has_many :timetable_entries @@ -36,11 +35,11 @@ class Employee < ActiveRecord::Base has_many :finance_transactions, :as => :payee has_many :employee_attendances - validates_format_of :email, :with => /^[A-Z0-9._%-]+@([A-Z0-9-]+\.)+[A-Z]{2,4}$/i, :allow_blank=>true, + validates_format_of :email, :with => /\A[A-Z0-9._%-]+@([A-Z0-9-]+\.)+[A-Z]{2,4}\z/i, :allow_blank=>true, :message => "#{t('must_be_a_valid_email_address')}" validates_presence_of :employee_category_id, :employee_number, :first_name, :employee_position_id, - :employee_department_id, :date_of_birth,:joining_date,:nationality_id + :employee_department_id, :date_of_birth, :joining_date, :nationality_id validates_uniqueness_of :employee_number validates_associated :user @@ -52,6 +51,12 @@ class Employee < ActiveRecord::Base :path => ":rails_root/public/system/:class/:attachment/:id/:style/:basename.:extension" VALID_IMAGE_TYPES = ['image/gif', 'image/png','image/jpeg', 'image/jpg'] + EMPLOYEE_QUERY_VARIABLES = [ + :employee_department_id, + :employee_category_id, + :employee_position_id, + :employee_grade_id + ] validates_attachment_content_type :photo, :content_type =>VALID_IMAGE_TYPES, :message=>'Image can only be GIF, PNG, JPG',:if=> Proc.new { |p| !p.photo_file_name.blank? } @@ -59,9 +64,7 @@ class Employee < ActiveRecord::Base :message=>'must be less than 500 KB.',:if=> Proc.new { |p| p.photo_file_name_changed? } def status_true - unless self.status==1 - self.status=1 - end + self.status = true if self.status == false end def create_user_and_validate @@ -78,9 +81,9 @@ def create_user_and_validate changes_to_be_checked = ['employee_number','first_name','last_name','email'] check_changes = self.changed & changes_to_be_checked # self.user.role ||= "Employee" - unless check_changes.blank? + if check_changes.any? emp_user = self.user - emp_user.username = self.employee_number if check_changes.include?('employee_number') + emp_user.username = self.employee_number.to_s if check_changes.include?('employee_number') emp_user.password = self.employee_number.to_s + "123" if check_changes.include?('employee_number') emp_user.first_name = self.first_name if check_changes.include?('first_name') emp_user.last_name = self.last_name if check_changes.include?('last_name') @@ -92,14 +95,14 @@ def create_user_and_validate def check_user_errors(user) unless user.valid? - user.errors.each{|attr,msg| errors.add(attr.to_sym,"#{msg}")} + user.errors.each{ |attr,msg| errors.add(attr.to_sym,"#{msg}") } end user.errors.blank? end def employee_batches - batches_with_employees = Batch.active.reject{|b| b.employee_id.nil?} - assigned_batches = batches_with_employees.reject{|e| !e.employee_id.split(",").include?(self.id.to_s)} + batches_with_employees = Batch.active.reject{ |b| b.employee_id.nil? } + assigned_batches = batches_with_employees.reject{ |e| !e.employee_id.split(",").include?(self.id.to_s) } return assigned_batches end @@ -119,41 +122,30 @@ def max_hours_per_week end alias_method(:max_hours_day, :max_hours_per_day) alias_method(:max_hours_week, :max_hours_per_week) - + def next_employee - next_st = self.employee_department.employees.first(:conditions => "id>#{self.id}",:order => "id ASC") - next_st ||= employee_department.employees.first(:order => "id ASC") + next_st = self.employee_department.employees.first(:conditions => ["id > ?", self.id], :order => "id ASC") next_st ||= self.employee_department.employees.first(:order => "id ASC") end def previous_employee - prev_st = self.employee_department.employees.first(:conditions => "id<#{self.id}",:order => "id DESC") - prev_st ||= employee_department.employees.first(:order => "id DESC") - prev_st ||= self.employee_department.empoyees.first(:order => "id DESC") + prev_st = self.employee_department.employees.first(:conditions => ["id < ?", self.id], :order => "id DESC") + prev_st ||= self.employee_department.employees.first(:order => "id DESC") end def full_name "#{first_name} #{middle_name} #{last_name}" end - def is_payslip_approved(date) - approve = MonthlyPayslip.find_all_by_salary_date_and_employee_id(date,self.id,:conditions => ["is_approved = true"]) - if approve.empty? - return false - else - return true - end + def payslip_approved?(date) + MonthlyPayslip.find_all_by_salary_date_and_employee_id_and_is_approved(date, self.id, true).any? end - def is_payslip_rejected(date) - approve = MonthlyPayslip.find_all_by_salary_date_and_employee_id(date,self.id,:conditions => ["is_rejected = true"]) - if approve.empty? - return false - else - return true - end + + def payslip_rejected?(date) + MonthlyPayslip.find_all_by_salary_date_and_employee_id_and_is_rejected(date, self.id, true).any? end - def self.total_employees_salary(employees,start_date,end_date) + def self.total_employees_salary(employees, start_date, end_date) salary = 0 employees.each do |e| salary_dates = e.all_salaries(start_date,end_date) @@ -165,54 +157,38 @@ def self.total_employees_salary(employees,start_date,end_date) end def employee_salary(salary_date) - - monthly_payslips = MonthlyPayslip.find(:all, - :order => 'salary_date desc', - :conditions => ["employee_id ='#{self.id}'and salary_date = '#{salary_date}' and is_approved = 1"]) - individual_payslip_category = IndividualPayslipCategory.find(:all, - :order => 'salary_date desc', - :conditions => ["employee_id ='#{self.id}'and salary_date >= '#{salary_date}'"]) + monthly_payslips = MonthlyPayslip.find(:all, :order => 'salary_date desc', :conditions => ["employee_id = ? AND salary_date = ? AND is_approved = ?", self.id, salary_date, true]) + individual_payslip_category = IndividualPayslipCategory.find(:all, :order => 'salary_date desc', :conditions => ["employee_id = ? AND salary_date >= ?", self.id, salary_date]) individual_category_non_deductionable = 0 individual_category_deductionable = 0 individual_payslip_category.each do |pc| - unless pc.is_deduction == true - individual_category_non_deductionable = individual_category_non_deductionable + pc.amount.to_f - end - end - - individual_payslip_category.each do |pc| - unless pc.is_deduction == false + if pc.is_deduction? individual_category_deductionable = individual_category_deductionable + pc.amount.to_f + else + individual_category_non_deductionable = individual_category_non_deductionable + pc.amount.to_f end end non_deductionable_amount = 0 deductionable_amount = 0 monthly_payslips.each do |mp| - category1 = PayrollCategory.find(mp.payroll_category_id) - unless category1.is_deduction == true + category = PayrollCategory.find(mp.payroll_category_id) + if category.is_deduction? + deductionable_amount = deductionable_amount + mp.amount.to_f + else non_deductionable_amount = non_deductionable_amount + mp.amount.to_f end end - monthly_payslips.each do |mp| - category2 = PayrollCategory.find(mp.payroll_category_id) - unless category2.is_deduction == false - deductionable_amount = deductionable_amount + mp.amount.to_f - end - end net_non_deductionable_amount = individual_category_non_deductionable + non_deductionable_amount net_deductionable_amount = individual_category_deductionable + deductionable_amount - net_amount = net_non_deductionable_amount - net_deductionable_amount - return net_amount.to_f + net_non_deductionable_amount - net_deductionable_amount end - def salary(start_date,end_date) - MonthlyPayslip.find_by_employee_id(self.id,:order => 'salary_date desc', - :conditions => ["salary_date >= '#{start_date.to_date}' and salary_date <= '#{end_date.to_date}' and is_approved = 1"]).salary_date - + def salary(start_date, end_date) + MonthlyPayslip.find_by_employee_id(self.id, :order => 'salary_date desc', :conditions => ["salary_date >= ? AND salary_date <= ? and is_approved = ?", start_date.to_date, end_date.to_date, true]).salary_date end def archive_employee(status) @@ -222,7 +198,7 @@ def archive_employee(status) employee_attributes.delete "photo_file_size" employee_attributes.delete "photo_file_name" employee_attributes.delete "photo_content_type" - employee_attributes["former_id"]= self.id + employee_attributes["former_id"] = self.id archived_employee = ArchivedEmployee.new(employee_attributes) archived_employee.photo = self.photo if archived_employee.save @@ -243,65 +219,79 @@ def archive_employee(status) self.destroy end end - - def all_salaries(start_date,end_date) - MonthlyPayslip.find_all_by_employee_id(self.id,:select =>"distinct salary_date" ,:order => 'salary_date desc', - :conditions => ["salary_date >= '#{start_date.to_date}' and salary_date <= '#{end_date.to_date}' and is_approved = 1"]) + + def all_salaries(start_date, end_date) + MonthlyPayslip.find_all_by_employee_id(self.id, :select =>"distinct salary_date", :order => 'salary_date desc', :conditions => ["salary_date >= ? and salary_date <= ? and is_approved = ?", start_date.to_date, end_date.to_date, true]) end - def self.calculate_salary(monthly_payslip,individual_payslip_category) + def self.calculate_salary(monthly_payslip, individual_payslip_category) individual_category_non_deductionable = 0 individual_category_deductionable = 0 - unless individual_payslip_category.blank? - individual_payslip_category.each do |pc| - if pc.is_deduction == true - individual_category_deductionable = individual_category_deductionable + pc.amount.to_f - else - individual_category_non_deductionable = individual_category_non_deductionable + pc.amount.to_f - end + + individual_payslip_category.each do |pc| + if pc.is_deduction? + individual_category_deductionable = individual_category_deductionable + pc.amount.to_f + else + individual_category_non_deductionable = individual_category_non_deductionable + pc.amount.to_f end end + non_deductionable_amount = 0 deductionable_amount = 0 - unless monthly_payslip.blank? - monthly_payslip.each do |mp| - unless mp.payroll_category.blank? - if mp.payroll_category.is_deduction == true - deductionable_amount = deductionable_amount + mp.amount.to_f - else - non_deductionable_amount = non_deductionable_amount + mp.amount.to_f - end + + monthly_payslip.each do |mp| + if mp.payroll_category.present? + if mp.payroll_category.is_deduction? + deductionable_amount = deductionable_amount + mp.amount.to_f + else + non_deductionable_amount = non_deductionable_amount + mp.amount.to_f end end end + net_non_deductionable_amount = individual_category_non_deductionable + non_deductionable_amount net_deductionable_amount = individual_category_deductionable + deductionable_amount net_amount = net_non_deductionable_amount - net_deductionable_amount - return_hash = {:net_amount=>net_amount,:net_deductionable_amount=>net_deductionable_amount,\ - :net_non_deductionable_amount=>net_non_deductionable_amount } - return_hash + {:net_amount => net_amount, :net_deductionable_amount => net_deductionable_amount, :net_non_deductionable_amount => net_non_deductionable_amount } end def self.find_in_active_or_archived(id) - employee = Employee.find(:first,:conditions=>"id=#{id}") - if employee.blank? - return ArchivedEmployee.find(:first,:conditions=>"former_id=#{id}") - else - return employee - end + Employee.find_by_id(id) || ArchivedEmployee.find_by_id(id) end def has_dependency - return true if self.monthly_payslips.present? or self.employee_salary_structures.present? or self.employees_subjects.present? \ - or self.apply_leaves.present? or self.finance_transactions.present? or self.timetable_entries.present? or self.employee_attendances.present? - return true if FedenaPlugin.check_dependency(self,"permanant").present? - return false + self.monthly_payslips.present? || self.employee_salary_structures.present? || self.employees_subjects.present? \ + || self.apply_leaves.present? || self.finance_transactions.present? || self.timetable_entries.present? \ + || self.employee_attendances.present? || FedenaPlugin.check_dependency(self,"permanant").present? end def former_dependency FedenaPlugin.check_dependency(self,"former") end - + + def self.search_employees(params) + if params[:query].length >= 3 + conditions = "(first_name LIKE ? OR middle_name LIKE ? OR last_name LIKE ?" \ + " OR employee_number LIKE ? OR (concat(first_name, \" \", last_name) LIKE ?))" + query_values = ["#{params[:query]}%","#{params[:query]}%","#{params[:query]}%", + params[:query], params[:query]] + elsif params[:query].present? + conditions = "employee_number = ? " + query_values = [params[:query]] + else + conditions = "1 = 1" # always true conditions to prevent wrong syntax error + query_values = [] + end + + EMPLOYEE_QUERY_VARIABLES.each do |key| + if params[key].present? + conditions << " AND #{key} = ?" + query_values << params[key] + end + end + + Employee.all(conditions: [conditions] + query_values, order: "first_name asc") + end end diff --git a/app/models/hr/employee_additional_detail.rb b/app/models/hr/employee_additional_detail.rb index a723aef0b..ad1b365aa 100755 --- a/app/models/hr/employee_additional_detail.rb +++ b/app/models/hr/employee_additional_detail.rb @@ -1,25 +1,26 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class EmployeeAdditionalDetail < ActiveRecord::Base belongs_to :employee belongs_to :additional_field - + validates_presence_of :additional_info, :if => Proc.new { |ead| ead.additional_field && ead.additional_field.is_mandatory? } + validate :destroy_if_additional_info_is_blank + def archive_employee_additional_detail(archived_employee) additional_detail_attributes = self.attributes additional_detail_attributes.delete "id" @@ -27,28 +28,11 @@ def archive_employee_additional_detail(archived_employee) self.delete if ArchivedEmployeeAdditionalDetail.create(additional_detail_attributes) end - def save - unless self.destroyed? - super - end - true - end + private - def validate - if self.additional_field.is_mandatory == true - if self.additional_info.blank? - errors.add("additional_info","can't be blank") - return false - else - return true - end - else - if self.additional_info.blank? - self.destroy - return true - else - return true - end - end + def destroy_if_additional_info_is_blank + self.destroy if additional_field && !additional_field.is_mandatory? && additional_info.blank? + return true end + end diff --git a/app/models/hr/employee_attendance.rb b/app/models/hr/employee_attendance.rb index 50164f5f4..542ec2835 100755 --- a/app/models/hr/employee_attendance.rb +++ b/app/models/hr/employee_attendance.rb @@ -1,32 +1,30 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class EmployeeAttendance < ActiveRecord::Base validates_presence_of :employee_leave_type_id, :reason - validates_uniqueness_of :employee_id, :scope=> :attendance_date + validates_uniqueness_of :employee_id, :scope => :attendance_date belongs_to :employee belongs_to :employee_leave_type - before_save :validate + validate :date_marked_is_earlier_than_joining_date - def validate - if self.attendance_date.to_date < self.employee.joining_date.to_date - errors.add(:employee_attendance,"#{t('date_marked_is_earlier_than_joining_date')}") - end + private + def date_marked_is_earlier_than_joining_date + errors.add(:employee_attendance,"#{t('date_marked_is_earlier_than_joining_date')}") if self.attendance_date && self.employee && self.employee.joining_date && self.attendance_date.to_date < self.employee.joining_date.to_date end - + end diff --git a/app/models/hr/employee_bank_detail.rb b/app/models/hr/employee_bank_detail.rb index e91b9816f..c0f1cc9be 100755 --- a/app/models/hr/employee_bank_detail.rb +++ b/app/models/hr/employee_bank_detail.rb @@ -1,29 +1,29 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class EmployeeBankDetail < ActiveRecord::Base belongs_to :employee belongs_to :bank_field - def archive_employee_bank_detail(archived_employee) + def archive_employee_bank_detail(archived_employee_id) bank_detail_attributes = self.attributes bank_detail_attributes.delete "id" - bank_detail_attributes["employee_id"] = archived_employee - self.delete if ArchivedEmployeeBankDetail.create(bank_detail_attributes) + bank_detail_attributes["employee_id"] = archived_employee_id + archive_employee_bank_detail = ArchivedEmployeeBankDetail.create(bank_detail_attributes) + self.delete if archive_employee_bank_detail.valid? end end diff --git a/app/models/hr/employee_category.rb b/app/models/hr/employee_category.rb index 6631fdae7..d0273297a 100755 --- a/app/models/hr/employee_category.rb +++ b/app/models/hr/employee_category.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class EmployeeCategory < ActiveRecord::Base validates_presence_of :name, :prefix validates_uniqueness_of :name, :prefix diff --git a/app/models/hr/employee_department.rb b/app/models/hr/employee_department.rb index 3bd217ee2..9ee5da6d6 100755 --- a/app/models/hr/employee_department.rb +++ b/app/models/hr/employee_department.rb @@ -1,29 +1,27 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class EmployeeDepartment < ActiveRecord::Base validates_presence_of :name validates_uniqueness_of :name, :code has_many :employees has_many :employee_department_events - has_many :events, :through=>:employee_department_events - named_scope :active, :conditions => {:status => true } - + has_many :events, :through => :employee_department_events + named_scope :active, :conditions => { :status => true } def department_total_salary(start_date,end_date) total = 0 diff --git a/app/models/hr/employee_department_event.rb b/app/models/hr/employee_department_event.rb index 761842d0d..15d29c644 100755 --- a/app/models/hr/employee_department_event.rb +++ b/app/models/hr/employee_department_event.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class EmployeeDepartmentEvent < ActiveRecord::Base belongs_to :event belongs_to :employee_department diff --git a/app/models/hr/employee_grade.rb b/app/models/hr/employee_grade.rb index 12d099fa7..ae97742ac 100755 --- a/app/models/hr/employee_grade.rb +++ b/app/models/hr/employee_grade.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class EmployeeGrade < ActiveRecord::Base validates_presence_of :name validates_uniqueness_of :name, :priority @@ -23,10 +22,12 @@ class EmployeeGrade < ActiveRecord::Base has_many :employee named_scope :active, :conditions => {:status => true } + validate :max_hours_week_should_be_greater_than_max_hours_day - def validate - self.errors.add(:max_hours_week, "#{t('should_be_greater_than_max_period')}.") \ - if self.max_hours_day > self.max_hours_week \ - unless self.max_hours_day.nil? or self.max_hours_week.nil? + private + def max_hours_week_should_be_greater_than_max_hours_day + if self.max_hours_day && self.max_hours_week && self.max_hours_day > self.max_hours_week + self.errors.add(:max_hours_week, "#{t('should_be_greater_than_max_period')}.") + end end end diff --git a/app/models/hr/employee_leave.rb b/app/models/hr/employee_leave.rb index a67e3129e..b6af929b0 100755 --- a/app/models/hr/employee_leave.rb +++ b/app/models/hr/employee_leave.rb @@ -1,21 +1,46 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class EmployeeLeave < ActiveRecord::Base - belongs_to :employee_leave_type + belongs_to :employee_leave_type + + def self.reset_all + EmployeeLeave.all.each(&:reset) + end + + def reset + calculate_leave_days if employee_leave_type.status + end + + def calculate_leave_days + default_leave_count = employee_leave_type.max_leave_count + if employee_leave_type.carry_forward && self.leave_taken <= self.leave_count + self.leave_count -= self.leave_taken + self.leave_count += default_leave_count.to_f + else + self.leave_count = default_leave_count.to_f + end + self.leave_taken = 0 + self.reset_date = Date.today + self.save + end + + def update_leave_taken_by(is_half_day) + self.leave_taken += is_half_day ? 0.5 : 1 + self.save + end end diff --git a/app/models/hr/employee_leave_type.rb b/app/models/hr/employee_leave_type.rb index 11fa1b4a0..31a249fbb 100755 --- a/app/models/hr/employee_leave_type.rb +++ b/app/models/hr/employee_leave_type.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class EmployeeLeaveType < ActiveRecord::Base has_many :employee_leaves has_many :employee_attendances diff --git a/app/models/hr/employee_position.rb b/app/models/hr/employee_position.rb index a85ea3271..428f76cb9 100755 --- a/app/models/hr/employee_position.rb +++ b/app/models/hr/employee_position.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class EmployeePosition < ActiveRecord::Base validates_presence_of :name, :employee_category_id validates_uniqueness_of :name,:scope=>:employee_category_id diff --git a/app/models/hr/employee_salary_structure.rb b/app/models/hr/employee_salary_structure.rb index 2ad67d495..aaf6084c2 100755 --- a/app/models/hr/employee_salary_structure.rb +++ b/app/models/hr/employee_salary_structure.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class EmployeeSalaryStructure < ActiveRecord::Base belongs_to :payroll_category belongs_to :employee diff --git a/app/models/hr/employees_subject.rb b/app/models/hr/employees_subject.rb index 8d602e86e..77ee83ed5 100755 --- a/app/models/hr/employees_subject.rb +++ b/app/models/hr/employees_subject.rb @@ -1,59 +1,60 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class EmployeesSubject < ActiveRecord::Base - belongs_to :employee - belongs_to :subject - has_one :batch,:through=>:subject + belongs_to :employee + belongs_to :subject + has_one :batch, :through => :subject - def self.allot_work(employee_subj_ids) - status,error_carrier = false,self.new - self.transaction do - emp_subjs = [] - employee_subj_ids.each do |subj_id,emp_id| - a = self.find_or_create_by_subject_id(:subject_id=>subj_id) - a.employee_id = emp_id - a.save - emp_subjs << a - end + def self.allot_work(subject_employee_ids) + status = true + employee_assignments = {} - employee_assignments = emp_subjs.group_by{|es|es.employee_id} - emp_assigned_hours = {} - employee_assignments.each do |emp_id,emp_subs| - emp_assigned_hours[emp_id] ||= {} - emp_assigned_hours[emp_id][:assigned]=emp_subs.sum{|es| es.subject.max_weekly_classes} || 0 - emp_assigned_hours[emp_id][:max]=emp_subs.first.employee.max_hours_week || 0 - emp_assigned_hours[emp_id][:emp_name]=emp_subs.first.employee.full_name - end - overloaded_emps = emp_assigned_hours.reject{|emp_id,details| details[:assigned].to_i <= details[:max].to_i} - status = overloaded_emps.blank? + subject_employee_ids.each do |subject_id, employee_id| + employee_assignments[employee_id] ||= [] + employee_assignments[employee_id] << subject_id + end + + transaction do + employee_assignments.each do |employee_id, subject_ids| + if employee_overloaded?(employee_id, subject_ids) + status = false + raise ActiveRecord::Rollback + end - - unless overloaded_emps.blank? - puts overloaded_emps.inspect - overloaded_emps.each do |emp_id,details| - error_carrier.errors.add_to_base("#{details[:emp_name]} has #{details[:assigned]-details[:max].to_i} extra periods assigned") + subject_ids.each do |subject_id| + es = self.find_or_initialize_by_employee_id_and_subject_id(:subject_id => subject_id, :employee_id => employee_id) + if !es.save + status = false + raise ActiveRecord::Rollback + end end -# raise ActiveRecord::Rollback end end - return [status,error_carrier] + + status + end + + def self.employee_overloaded?(employee_id, subject_ids) + employee = Employee.find(employee_id) + subjects = Subject.find(subject_ids) + assigned_hrs = subjects.sum { |s| s.max_weekly_classes } || 0 + max_hrs = employee.max_hours_per_week || 0 + + assigned_hrs > max_hrs end - - end diff --git a/app/models/hr/individual_payslip_category.rb b/app/models/hr/individual_payslip_category.rb index b41127315..073616ea0 100755 --- a/app/models/hr/individual_payslip_category.rb +++ b/app/models/hr/individual_payslip_category.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class IndividualPayslipCategory < ActiveRecord::Base validates_numericality_of :amount, :allow_nil=>true end diff --git a/app/models/hr/monthly_payslip.rb b/app/models/hr/monthly_payslip.rb index f1462b28d..94bd47965 100755 --- a/app/models/hr/monthly_payslip.rb +++ b/app/models/hr/monthly_payslip.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class MonthlyPayslip < ActiveRecord::Base validates_presence_of :salary_date @@ -25,7 +24,7 @@ class MonthlyPayslip < ActiveRecord::Base belongs_to :approver ,:class_name => 'User' belongs_to :rejector ,:class_name => 'User' - def approve(user_id,remark) + def approve(user_id, remark) self.is_approved = true self.approver_id = user_id self.remark = remark @@ -39,78 +38,64 @@ def reject(user_id, reason) self.save end - def self.find_and_filter_by_department(salary_date,dept_id) + def self.find_and_filter_by_department(salary_date, dept_id) payslips = "" individual_payslip_category = "" - unless dept_id =="All" - active_employees_in_dept = Employee.find(:all,:select=>"id",:conditions=>"employee_department_id = #{dept_id}") - archived_employees_in_dept = ArchivedEmployee.find(:all,:select=>"former_id",:conditions=>"employee_department_id = #{dept_id}") + if dept_id != "All" + active_employees_in_dept = Employee.find(:all, :select => "id", :conditions => ["employee_department_id = ?", dept_id]) + archived_employees_in_dept = ArchivedEmployee.find(:all, :select => "former_id", :conditions => ["employee_department_id = ?", dept_id]) all_employees_in_dept = active_employees_in_dept.collect(&:id) + archived_employees_in_dept.collect{|a| a.former_id.to_i} - payslips = self.find_all_by_salary_date(salary_date.to_date,:conditions=>["employee_id IN (?)",all_employees_in_dept],:order=> "payroll_category_id ASC",:include=>[:payroll_category]) - individual_payslip_category = IndividualPayslipCategory.find_all_by_salary_date(salary_date.to_date,:conditions=>["employee_id IN (?)",all_employees_in_dept],:order=>"id ASC") + payslips = self.find_all_by_salary_date(salary_date.to_date, :conditions => ["employee_id IN (?)", all_employees_in_dept], :order => "payroll_category_id ASC", :include => [:payroll_category]) + individual_payslip_category = IndividualPayslipCategory.find_all_by_salary_date(salary_date.to_date, :conditions => ["employee_id IN (?)", all_employees_in_dept], :order => "id ASC") else - payslips = self.find_all_by_salary_date(salary_date.to_date,:order=> "payroll_category_id ASC",:include=>[:payroll_category]) - individual_payslip_category = IndividualPayslipCategory.find_all_by_salary_date(salary_date.to_date,:order=>"id ASC") + payslips = self.find_all_by_salary_date(salary_date.to_date, :order => "payroll_category_id ASC", :include => [:payroll_category]) + individual_payslip_category = IndividualPayslipCategory.find_all_by_salary_date(salary_date.to_date, :order => "id ASC") end - grouped_monthly_payslips = payslips.group_by(&:employee_id) unless payslips.blank? - grouped_individual_payslip_categories = individual_payslip_category.group_by(&:employee_id) unless individual_payslip_category.blank? - return_hash = {:monthly_payslips=>grouped_monthly_payslips,:individual_payslip_category=>grouped_individual_payslip_categories } - return_hash + grouped_monthly_payslips = payslips.group_by(&:employee_id) if payslips.present? + grouped_individual_payslip_categories = individual_payslip_category.group_by(&:employee_id) if individual_payslip_category.present? + { :monthly_payslips => grouped_monthly_payslips, :individual_payslip_category => grouped_individual_payslip_categories } end def active_or_archived_employee - employee = Employee.find(:first,:conditions=>"id=#{self.employee_id}") - if employee.blank? - return ArchivedEmployee.find(:first,:conditions=>"former_id=#{self.employee_id}") - else - return employee - end + employee = Employee.find(:first, :conditions => ["id = ?", self.employee_id]) + archived_employee = ArchivedEmployee.find(:first, :conditions => ["former_id = ?", self.employee_id]) + employee.present? ? employee : archived_employee end - def status_as_text - if is_approved ==true - status = "#{t('approved')}" - elsif is_rejected ==true - status = "#{t('rejected')}" - else - status = "#{t('pending')}" - end - return status + is_approved ? "#{t('approved')}" : is_rejected ? "#{t('rejected')}" : "#{t('pending')}" end - def self.total_employees_salary(start_date,end_date,dept_id="") + def self.total_employees_salary(start_date, end_date, dept_id = "") total_monthly_payslips = "" - unless dept_id.blank? - active_employees_in_dept = Employee.find(:all,:select=>"id",:conditions=>"employee_department_id = #{dept_id}") - archived_employees_in_dept = ArchivedEmployee.find(:all,:select=>"former_id",:conditions=>"employee_department_id = #{dept_id}") + if dept_id.present? + active_employees_in_dept = Employee.find(:all, :select => "id", :conditions => ["employee_department_id = ?", dept_id]) + archived_employees_in_dept = ArchivedEmployee.find(:all, :select => "former_id", :conditions => ["employee_department_id = ?", dept_id]) all_employees_in_dept = active_employees_in_dept.collect(&:id) + archived_employees_in_dept.collect{|a| a.former_id.to_i} - total_monthly_payslips = self.find(:all,:select=>"employee_id,amount,payroll_category_id,salary_date",:order => 'salary_date desc',:conditions => ["salary_date >= ? and salary_date <= ? and is_approved = 1 and employee_id IN (?)",start_date.to_date,end_date.to_date,all_employees_in_dept],:include=>[:payroll_category]) + total_monthly_payslips = self.find(:all, :select => "employee_id, amount, payroll_category_id, salary_date", :order => 'salary_date desc', :conditions => ["salary_date >= ? and salary_date <= ? and is_approved = 1 and employee_id IN (?)", start_date.to_date, end_date.to_date, all_employees_in_dept], :include => [:payroll_category]) else - total_monthly_payslips = self.find(:all,:select=>"employee_id,amount,payroll_category_id,salary_date",:order => 'salary_date desc',:conditions => ["salary_date >= ? and salary_date <= ? and is_approved = 1",start_date.to_date,end_date.to_date],:include=>[:payroll_category]) + total_monthly_payslips = self.find(:all, :select => "employee_id, amount, payroll_category_id, salary_date", :order => 'salary_date desc', :conditions => ["salary_date >= ? and salary_date <= ? and is_approved = 1", start_date.to_date, end_date.to_date], :include => [:payroll_category]) end - + employee_ids = [] - employee_ids = total_monthly_payslips.collect(&:employee_id) unless total_monthly_payslips.blank? - unless employee_ids.blank? - employee_ids.uniq! - total_individual_payslips = IndividualPayslipCategory.find(:all,:conditions =>"salary_date >= '#{start_date.to_date}' and salary_date <= '#{end_date.to_date}' AND employee_id IN (#{employee_ids.join(",")})",:order=>"id ASC") + total_individual_payslips = [] + employee_ids = total_monthly_payslips.collect(&:employee_id) if total_monthly_payslips.any? + if employee_ids.any? + total_individual_payslips = IndividualPayslipCategory.find(:all, :conditions => ["salary_date >= ? and salary_date <= ? AND employee_id IN (?)", start_date.to_date, end_date.to_date, employee_ids.uniq.join(",")], :order => "id ASC") end total_salary = 0 - unless total_monthly_payslips.blank? + if total_monthly_payslips.any? total_monthly_payslips.each do |payslip| - total_salary += payslip.amount.to_f if payslip.payroll_category.is_deduction==false - total_salary -= payslip.amount.to_f if payslip.payroll_category.is_deduction==true + payslip.payroll_category.is_deduction? ? total_salary -= payslip.amount.to_f : total_salary += payslip.amount.to_f end end - unless total_individual_payslips.blank? + if total_individual_payslips.any? total_individual_payslips.each do |payslip| - total_salary += payslip.amount.to_f if payslip.is_deduction==false - total_salary -= payslip.amount.to_f if payslip.is_deduction==true + payslip.is_deduction? ? total_salary -= payslip.amount.to_f : total_salary += payslip.amount.to_f end end - {:total_salary=>total_salary,:monthly_payslips=>total_monthly_payslips,:individual_categories=>total_individual_payslips} + {:total_salary => total_salary, :monthly_payslips => total_monthly_payslips, :individual_categories => total_individual_payslips} end diff --git a/app/models/hr/payroll_category.rb b/app/models/hr/payroll_category.rb index 6d4c9c5f3..b69f121c2 100755 --- a/app/models/hr/payroll_category.rb +++ b/app/models/hr/payroll_category.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class PayrollCategory < ActiveRecord::Base validates_uniqueness_of :name validates_presence_of :name diff --git a/app/models/language.rb b/app/models/language.rb index dff8d4c0c..8757e43a5 100644 --- a/app/models/language.rb +++ b/app/models/language.rb @@ -1,20 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class Language < ActiveRecord::Base named_scope :translation_available, :conditions => { :code => Configuration::LOCALES } end diff --git a/app/models/news.rb b/app/models/news.rb index 5b199f358..dc24b44d4 100755 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class News < ActiveRecord::Base belongs_to :author, :class_name => 'User' has_many :comments, :class_name => 'NewsComment' @@ -41,5 +40,5 @@ def reload_news_bar def self.cache_fragment_name 'News_latest_fragment' end - + end \ No newline at end of file diff --git a/app/models/news_comment.rb b/app/models/news_comment.rb index ccb75720b..7e9ae91a7 100755 --- a/app/models/news_comment.rb +++ b/app/models/news_comment.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class NewsComment < ActiveRecord::Base belongs_to :news belongs_to :author, :class_name => 'User' diff --git a/app/models/observation.rb b/app/models/observation.rb index a9af19168..dfe66c881 100644 --- a/app/models/observation.rb +++ b/app/models/observation.rb @@ -1,20 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class Observation < ActiveRecord::Base belongs_to :observation_group has_many :descriptive_indicators, :as=>:describable @@ -34,6 +34,6 @@ def prev_record def validate errors.add_to_base("Name can't be blank") if self.name.blank? - errors.add_to_base("Description can't be blank") if self.desc.blank? + errors.add_to_base("Description can't be blank") if self.desc.blank? end end diff --git a/app/models/observation_group.rb b/app/models/observation_group.rb index 1c64b9ade..3a865d6ce 100644 --- a/app/models/observation_group.rb +++ b/app/models/observation_group.rb @@ -1,35 +1,38 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class ObservationGroup < ActiveRecord::Base - has_many :observations - has_many :descriptive_indicators, :through=>:observations - belongs_to :cce_grade_set - has_and_belongs_to_many :courses - - named_scope :active,:conditions=>{:is_deleted=>false} - - OBSERVATION_KINDS={'0'=>'Scholastic','1'=>'Co Scholastic Activity','3'=>'Co Scholastic Area'} + has_many :observations + has_many :descriptive_indicators, :through => :observations + belongs_to :cce_grade_set + has_and_belongs_to_many :courses validates_presence_of :name validates_presence_of :header_name validates_presence_of :observation_kind #,:max_marks - def validate - errors.add_to_base("CCE grade set can't be blank") if self.cce_grade_set_id.blank? - errors.add_to_base("Description can't be blank") if self.desc.blank? - end + validates_presence_of :cce_grade_set_id + validates_presence_of :desc + + named_scope :active, :conditions => { :is_deleted => false } + + OBSERVATION_KINDS = { + '0' => 'Scholastic', + '1' => 'Co Scholastic Activity', + '3' => 'Co Scholastic Area' + } + end diff --git a/app/models/period_entry.rb b/app/models/period_entry.rb index 0624c61a2..02001a192 100755 --- a/app/models/period_entry.rb +++ b/app/models/period_entry.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class PeriodEntry < ActiveRecord::Base belongs_to :batch belongs_to :class_timing diff --git a/app/models/previous_exam_score.rb b/app/models/previous_exam_score.rb index b17693c83..fdb27cbae 100644 --- a/app/models/previous_exam_score.rb +++ b/app/models/previous_exam_score.rb @@ -1,20 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class PreviousExamScore < ActiveRecord::Base belongs_to :student belongs_to :exam diff --git a/app/models/privilege.rb b/app/models/privilege.rb index 1b4e766e4..abaaec619 100755 --- a/app/models/privilege.rb +++ b/app/models/privilege.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class Privilege < ActiveRecord::Base has_and_belongs_to_many :users belongs_to :privilege_tag diff --git a/app/models/ranking_level.rb b/app/models/ranking_level.rb index b1588cca1..51fcdfb21 100644 --- a/app/models/ranking_level.rb +++ b/app/models/ranking_level.rb @@ -1,35 +1,35 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class RankingLevel < ActiveRecord::Base - validates_presence_of :name - validates_numericality_of :gpa,:if=>:has_gpa - validates_numericality_of :marks, :if=>:has_cwa - validates_numericality_of :subject_count, :allow_nil=>true + validates_presence_of :name + validates_numericality_of :gpa, :if => :has_gpa? + validates_numericality_of :marks, :if => :has_cwa? + validates_numericality_of :subject_count, :allow_nil => true belongs_to :course LIMIT_TYPES = %w(upper lower exact) - def has_gpa - self.course.gpa_enabled? + def has_gpa? + course && course.gpa_enabled? end - def has_cwa - self.course.cwa_enabled? or self.course.normal_enabled? + def has_cwa? + course && (course.cwa_enabled? || course.normal_enabled?) end end diff --git a/app/models/reminder.rb b/app/models/reminder.rb index a7500b8bf..f93d90a6d 100755 --- a/app/models/reminder.rb +++ b/app/models/reminder.rb @@ -1,25 +1,24 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class Reminder < ActiveRecord::Base validates_presence_of :body - belongs_to :user , :foreign_key => 'sender' - belongs_to :to_user, :class_name=>"User",:foreign_key => 'recipient' + belongs_to :user, :foreign_key => 'sender' + belongs_to :to_user, :class_name => 'User', :foreign_key => 'recipient' cattr_reader :per_page @@per_page = 12 diff --git a/app/models/school.rb b/app/models/school.rb new file mode 100644 index 000000000..07b90d4b1 --- /dev/null +++ b/app/models/school.rb @@ -0,0 +1,4 @@ +class School < ActiveRecord::Base + has_one :school_details + has_one :additional_field_option +end diff --git a/app/models/school_detail.rb b/app/models/school_detail.rb index da1369bcd..8c8163d6c 100644 --- a/app/models/school_detail.rb +++ b/app/models/school_detail.rb @@ -1,21 +1,23 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class SchoolDetail < ActiveRecord::Base + belongs_to :school + has_attached_file :logo, :styles => { :original=> "150x110#"}, :url => "/system/:class/:attachment/:id_partition/:style/:basename.:extension", diff --git a/app/models/sms_log.rb b/app/models/sms_log.rb index 41864089f..f0dd57ef7 100644 --- a/app/models/sms_log.rb +++ b/app/models/sms_log.rb @@ -1,20 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class SmsLog < ActiveRecord::Base belongs_to :sms_message diff --git a/app/models/sms_message.rb b/app/models/sms_message.rb index 8393169f7..6d93181ab 100644 --- a/app/models/sms_message.rb +++ b/app/models/sms_message.rb @@ -1,20 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class SmsMessage < ActiveRecord::Base has_many :sms_logs diff --git a/app/models/sms_setting.rb b/app/models/sms_setting.rb index ab6e6b5f7..b64d2b929 100755 --- a/app/models/sms_setting.rb +++ b/app/models/sms_setting.rb @@ -1,61 +1,52 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class SmsSetting < ActiveRecord::Base def application_sms_active - application_sms = SmsSetting.find_by_settings_key("ApplicationEnabled") - return true if application_sms.is_enabled + !!SmsSetting.find_by_settings_key_and_is_enabled("ApplicationEnabled", true) end def student_sms_active - student_sms = SmsSetting.find_by_settings_key("StudentSmsEnabled") - return true if student_sms.is_enabled + !!SmsSetting.find_by_settings_key_and_is_enabled("StudentSmsEnabled", true) end def student_admission_sms_active - student_sms = SmsSetting.find_by_settings_key("StudentAdmissionEnabled") - return true if student_sms.is_enabled + !!SmsSetting.find_by_settings_key_and_is_enabled("StudentAdmissionEnabled", true) end def parent_sms_active - parent_sms = SmsSetting.find_by_settings_key("ParentSmsEnabled") - return true if parent_sms.is_enabled + !!SmsSetting.find_by_settings_key_and_is_enabled("ParentSmsEnabled", true) end def employee_sms_active - employee_sms = SmsSetting.find_by_settings_key("EmployeeSmsEnabled") - return true if employee_sms.is_enabled + !!SmsSetting.find_by_settings_key_and_is_enabled("EmployeeSmsEnabled", true) end def attendance_sms_active - attendance_sms = SmsSetting.find_by_settings_key("AttendanceEnabled") - return true if attendance_sms.is_enabled + !!SmsSetting.find_by_settings_key_and_is_enabled("AttendanceEnabled", true) end def event_news_sms_active - event_news_sms = SmsSetting.find_by_settings_key("NewsEventsEnabled") - return true if event_news_sms.is_enabled + !!SmsSetting.find_by_settings_key_and_is_enabled("NewsEventsEnabled", true) end def exam_result_schedule_sms_active - result_schedule_sms = SmsSetting.find_by_settings_key("ExamScheduleResultEnabled") - return true if result_schedule_sms.is_enabled + !!SmsSetting.find_by_settings_key_and_is_enabled("ExamScheduleResultEnabled", true) end def self.get_sms_config @@ -66,7 +57,6 @@ def self.get_sms_config end def self.application_sms_status - application_sms = SmsSetting.find_by_settings_key("ApplicationEnabled") - return true if application_sms and application_sms.is_enabled + !!SmsSetting.find_by_settings_key_and_is_enabled("ApplicationEnabled", true) end end diff --git a/app/models/student.rb b/app/models/student.rb index 8cce394aa..0a5b93d60 100755 --- a/app/models/student.rb +++ b/app/models/student.rb @@ -1,25 +1,24 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class Student < ActiveRecord::Base include CceReportMod - + belongs_to :country belongs_to :batch belongs_to :student_category @@ -29,7 +28,7 @@ class Student < ActiveRecord::Base has_one :immediate_contact has_one :student_previous_data has_many :student_previous_subject_mark - has_many :guardians, :foreign_key => 'ward_id' + has_many :guardians, :foreign_key => 'ward_id', :dependent => :destroy has_many :finance_transactions, :as => :payee has_many :attendances has_many :finance_fees @@ -44,25 +43,20 @@ class Student < ActiveRecord::Base has_many :assessment_scores has_many :exam_scores has_many :previous_exam_scores - - - named_scope :active, :conditions => { :is_active => true } - named_scope :with_full_name_only, :select=>"id, CONCAT_WS('',first_name,' ',last_name) AS name,first_name,last_name", :order=>:first_name - named_scope :with_name_admission_no_only, :select=>"id, CONCAT_WS('',first_name,' ',last_name,' - ',admission_no) AS name,first_name,last_name,admission_no", :order=>:first_name - - named_scope :by_first_name, :order=>'first_name',:conditions => { :is_active => true } validates_presence_of :admission_no, :admission_date, :first_name, :batch_id, :date_of_birth validates_uniqueness_of :admission_no validates_presence_of :gender - validates_format_of :email, :with => /^[A-Z0-9._%-]+@([A-Z0-9-]+\.)+[A-Z]{2,4}$/i, :allow_blank=>true, + validates_inclusion_of :gender, :in => %w( m f M F ), :message => "#{t('model_errors.student.error2')}." + validates_format_of :email, :with => /\A[A-Z0-9._%-]+@([A-Z0-9-]+\.)+[A-Z]{2,4}\z/i, :allow_blank=>true, :message => "#{t('must_be_a_valid_email_address')}" - validates_format_of :admission_no, :with => /^[A-Z0-9_-]*$/i, + validates_format_of :admission_no, :with => /\A[A-Z0-9_-]*\z/i, :message => "#{t('must_contain_only_letters')}" + validate :date_of_birth_must_not_be_future, :check_admission_no validates_associated :user - before_validation :create_user_and_validate + before_validation :create_user_and_validate before_save :is_active_true has_attached_file :photo, @@ -76,54 +70,11 @@ class Student < ActiveRecord::Base :message=>'Image can only be GIF, PNG, JPG',:if=> Proc.new { |p| !p.photo_file_name.blank? } validates_attachment_size :photo, :less_than => 512000,\ :message=>'must be less than 500 KB.',:if=> Proc.new { |p| p.photo_file_name_changed? } - - def validate - errors.add(:date_of_birth, "#{t('cant_be_a_future_date')}.") if self.date_of_birth >= Date.today \ - unless self.date_of_birth.nil? - errors.add(:gender, "#{t('model_errors.student.error2')}.") unless ['m', 'f'].include? self.gender.downcase \ - unless self.gender.nil? - errors.add(:admission_no, "#{t('model_errors.student.error3')}.") if self.admission_no=='0' - errors.add(:admission_no, "#{t('should_not_be_admin')}") if self.admission_no.to_s.downcase== 'admin' - - end - - def is_active_true - unless self.is_active==1 - self.is_active=1 - end - end - - def create_user_and_validate - if self.new_record? - user_record = self.build_user - user_record.first_name = self.first_name - user_record.last_name = self.last_name - user_record.username = self.admission_no.to_s - user_record.password = self.admission_no.to_s + "123" - user_record.role = 'Student' - user_record.email = self.email.blank? ? "" : self.email.to_s - check_user_errors(user_record) - return false unless errors.blank? - else - self.user.role = "Student" - changes_to_be_checked = ['admission_no','first_name','last_name','email','immediate_contact_id'] - check_changes = self.changed & changes_to_be_checked - unless check_changes.blank? - self.user.username = self.admission_no if check_changes.include?('admission_no') - self.user.first_name = self.first_name if check_changes.include?('first_name') - self.user.last_name = self.last_name if check_changes.include?('last_name') - self.user.email = self.email if check_changes.include?('email') - check_user_errors(self.user) - end - if check_changes.include?('immediate_contact_id') or check_changes.include?('admission_no') - Guardian.shift_user(self) - end - - end - self.email = "" if self.email.blank? - return false unless errors.blank? - end + named_scope :active, :conditions => { :is_active => true } + named_scope :with_full_name_only, :select => "id, CONCAT_WS('', first_name, ' ', last_name) AS name, first_name, last_name", :order => :first_name + named_scope :with_name_admission_no_only, :select => "id, CONCAT_WS('', first_name, ' ', last_name, ' - ', admission_no) AS name, first_name, last_name, admission_no", :order => :first_name + named_scope :by_first_name, :order => 'first_name', :conditions => { :is_active => true } def check_user_errors(user) unless user.valid? @@ -141,9 +92,11 @@ def full_name end def gender_as_text - return 'Male' if gender.downcase == 'm' - return 'Female' if gender.downcase == 'f' - nil + case gender.downcase + when 'm' then 'Male' + when 'f' then 'Female' + else nil + end end def graduated_batches @@ -151,7 +104,7 @@ def graduated_batches end def all_batches - self.graduated_batches + self.batch.to_a + self.graduated_batches << self.batch end def immediate_contact @@ -166,29 +119,28 @@ def image_file=(input_data) end def next_student - next_st = self.batch.students.first(:conditions => "id > #{self.id}", :order => "id ASC") - next_st ||= batch.students.first(:order => "id ASC") + next_st = self.batch.students.first(:conditions => ["id > ?", self.id], :order => "id ASC") + next_st ||= self.batch.students.first(:order => "id ASC") end def previous_student - prev_st = self.batch.students.first(:conditions => "id < #{self.id}", :order => "admission_no DESC") - prev_st ||= batch.students.first(:order => "id DESC") + prev_st = self.batch.students.first(:conditions => ["id < ?", self.id], :order => "admission_no DESC") prev_st ||= self.batch.students.first(:order => "id DESC") end def previous_fee_student(date) - fee = FinanceFee.first(:conditions => "student_id < #{self.id} and fee_collection_id = #{date}", :joins=>'INNER JOIN students ON finance_fees.student_id = students.id',:order => "student_id DESC") - prev_st = fee.student unless fee.blank? - fee ||= FinanceFee.first(:conditions=>"fee_collection_id = #{date}", :joins=>'INNER JOIN students ON finance_fees.student_id = students.id',:order => "student_id DESC") - prev_st ||= fee.student unless fee.blank? + fee = FinanceFee.first(:conditions => ["student_id < ? AND fee_collection_id = ?", self.id, date], :joins => 'INNER JOIN students ON finance_fees.student_id = students.id', :order => "student_id DESC") + prev_st = fee.student if fee.present? + fee ||= FinanceFee.find_by_fee_collection_id(date, :joins => 'INNER JOIN students ON finance_fees.student_id = students.id', :order => "student_id DESC") + prev_st ||= fee.student if fee.present? # prev_st ||= self.batch.students.first(:order => "id DESC") end def next_fee_student(date) - fee = FinanceFee.first(:conditions => "student_id > #{self.id} and fee_collection_id = #{date}", :joins=>'INNER JOIN students ON finance_fees.student_id = students.id', :order => "student_id ASC") + fee = FinanceFee.first(:conditions => ["student_id > ? AND fee_collection_id = ?", self.id, date], :joins => 'INNER JOIN students ON finance_fees.student_id = students.id', :order => "student_id ASC") next_st = fee.student unless fee.nil? - fee ||= FinanceFee.first(:conditions=>"fee_collection_id = #{date}", :joins=>'INNER JOIN students ON finance_fees.student_id = students.id',:order => "student_id ASC") + fee ||= FinanceFee.find_by_fee_collection_id(date, :joins => 'INNER JOIN students ON finance_fees.student_id = students.id', :order => "student_id ASC") next_st ||= fee.student unless fee.nil? # prev_st ||= self.batch.students.first(:order => "id DESC") end @@ -199,21 +151,21 @@ def finance_fee_by_date(date) def check_fees_paid(date) particulars = date.fees_particulars(self) - total_fees=0 + total_fees = 0 financefee = date.fee_transactions(self.id) batch_discounts = BatchFeeCollectionDiscount.find_all_by_finance_fee_collection_id(date.id) - student_discounts = StudentFeeCollectionDiscount.find_all_by_finance_fee_collection_id_and_receiver_id(date.id,self.id) - category_discounts = StudentCategoryFeeCollectionDiscount.find_all_by_finance_fee_collection_id_and_receiver_id(date.id,self.student_category_id) + student_discounts = StudentFeeCollectionDiscount.find_all_by_finance_fee_collection_id_and_receiver_id(date.id, self.id) + category_discounts = StudentCategoryFeeCollectionDiscount.find_all_by_finance_fee_collection_id_and_receiver_id(date.id, self.student_category_id) total_discount = 0 - total_discount += batch_discounts.map{|s| s.discount}.sum unless batch_discounts.nil? - total_discount += student_discounts.map{|s| s.discount}.sum unless student_discounts.nil? - total_discount += category_discounts.map{|s| s.discount}.sum unless category_discounts.nil? + total_discount += batch_discounts.map{ |s| s.discount }.sum if batch_discounts.present? + total_discount += student_discounts.map{ |s| s.discount }.sum if student_discounts.present? + total_discount += category_discounts.map{ |s| s.discount }.sum if category_discounts.present? if total_discount > 100 total_discount = 100 end particulars.map { |s| total_fees += s.amount.to_f} - total_fees -= total_fees*(total_discount/100) - paid_fees_transactions = FinanceTransaction.find(:all,:select=>'amount,fine_amount',:conditions=>"FIND_IN_SET(id,\"#{financefee.transaction_id}\")") unless financefee.nil? + total_fees -= total_fees * (total_discount / 100) + paid_fees_transactions = FinanceTransaction.find(:all,:select=>'amount, fine_amount', :conditions => ["FIND_IN_SET(id, ?)", financefee.transaction_id]) unless financefee.nil? paid_fees = 0 paid_fees_transactions.map { |m| paid_fees += (m.amount.to_f - m.fine_amount.to_f) } unless paid_fees_transactions.nil? amount_pending = total_fees.to_f - paid_fees.to_f @@ -231,51 +183,41 @@ def check_fees_paid(date) # end end - def has_retaken_exam(subject_id) + def has_retaken_exam?(subject_id) retaken_exams = PreviousExamScore.find_all_by_student_id(self.id) - if retaken_exams.empty? - return false - else + if retaken_exams.any? exams = Exam.find_all_by_id(retaken_exams.collect(&:exam_id)) if exams.collect(&:subject_id).include?(subject_id) return true end - return false end - end def check_fee_pay(date) - date.finance_fees.first(:conditions=>"student_id = #{self.id}").is_paid + date.finance_fees.first(:conditions => ["student_id = ?", self.id]).is_paid end def self.next_admission_no '' #stub for logic to be added later. end - + def get_fee_strucure_elements(date) - elements = FinanceFeeStructureElement.get_student_fee_components(self,date) + elements = FinanceFeeStructureElement.get_student_fee_components(self, date) elements[:all] + elements[:by_batch] + elements[:by_category] + elements[:by_batch_and_category] end def total_fees(particulars) - total = 0 - particulars.each do |fee| - total += fee.amount - end - total + particulars.inject(0) { |total, fee| total + fee.amount } end def has_associated_fee_particular?(fee_category) - status = false - status = true if fee_category.fee_particulars.find_all_by_admission_no(admission_no).count > 0 - status = true if student_category_id.present? and fee_category.fee_particulars.find_all_by_student_category_id(student_category_id).count > 0 - return status + fee_category.fee_particulars.find_all_by_admission_no(admission_no).count > 0 \ + || student_category_id.present? && fee_category.fee_particulars.find_all_by_student_category_id(student_category_id).count > 0 end def archive_student(status) student_attributes = self.attributes - student_attributes["former_id"]= self.id + student_attributes["former_id"] = self.id student_attributes["status_description"] = status student_attributes.delete "id" student_attributes.delete "has_paid_fees" @@ -301,157 +243,103 @@ def archive_student(status) # end # end - + end - + def check_dependency - return true if self.finance_transactions.present? or self.graduated_batches.present? or self.attendances.present? or self.finance_fees.present? - return true if FedenaPlugin.check_dependency(self,"permanant").present? - return false + self.finance_transactions.present? || self.graduated_batches.present? || self.attendances.present? || self.finance_fees.present? || FedenaPlugin.check_dependency(self,"permanant").present? end def former_dependency plugin_dependencies = FedenaPlugin.check_dependency(self,"former") end - def assessment_score_for(indicator_id,exam_id,batch_id) - assessment_score = self.assessment_scores.find(:first, :conditions => { :student_id => self.id,:descriptive_indicator_id=>indicator_id,:exam_id=>exam_id,:batch_id=>batch_id }) - assessment_score.nil? ? assessment_scores.build(:descriptive_indicator_id=>indicator_id,:exam_id=>exam_id,:batch_id=>batch_id) : assessment_score + def assessment_score_for(indicator_id, exam_id, batch_id) + self.assessment_scores.find_by_student_id_and_descriptive_indicator_id_and_exam_id_and_batch_id(self.id, indicator_id, exam_id, batch_id) \ + || assessment_scores.build(:descriptive_indicator_id => indicator_id, :exam_id => exam_id, :batch_id => batch_id) end - def observation_score_for(indicator_id,batch_id) - assessment_score = self.assessment_scores.find(:first, :conditions => { :student_id => self.id,:descriptive_indicator_id=>indicator_id,:batch_id=>batch_id }) - assessment_score.nil? ? assessment_scores.build(:descriptive_indicator_id=>indicator_id,:batch_id=>batch_id) : assessment_score + + def observation_score_for(indicator_id, batch_id) + self.assessment_scores.find_by_student_id_and_descriptive_indicator_id_and_batch_id(self.id, indicator_id, batch_id) \ + || assessment_scores.build(:descriptive_indicator_id => indicator_id, :batch_id => batch_id) end - def has_higher_priority_ranking_level(ranking_level_id,type,subject_id) + def has_higher_priority_ranking_level(ranking_level_id, type, subject_id) ranking_level = RankingLevel.find(ranking_level_id) - higher_levels = RankingLevel.find(:all,:conditions=>["course_id = ? AND priority < ?", ranking_level.course_id,ranking_level.priority]) + higher_levels = RankingLevel.find(:all, :conditions=>["course_id = ? AND priority < ?", ranking_level.course_id, ranking_level.priority]) if higher_levels.empty? return false else higher_levels.each do|level| - if type=="subject" + if type == "subject" score = GroupedExamReport.find_by_student_id_and_subject_id_and_batch_id_and_score_type(self.id,subject_id,self.batch_id,"s") - unless score.nil? - if self.batch.gpa_enabled? - return true if((score.marks < level.gpa if level.marks_limit_type=="upper") or (score.marks >= level.gpa if level.marks_limit_type=="lower") or (score.marks == level.gpa if level.marks_limit_type=="exact")) - else - return true if((score.marks < level.marks if level.marks_limit_type=="upper") or (score.marks >= level.marks if level.marks_limit_type=="lower") or (score.marks == level.marks if level.marks_limit_type=="exact")) - end - end - elsif type=="overall" - unless level.subject_count.nil? - unless level.full_course==true + return true if score.present? && check_score_marks(score.marks, level) + + elsif type == "overall" + if level.subject_count.present? + if level.full_course == false subjects = self.batch.subjects - scores = GroupedExamReport.find(:all,:conditions=>{:student_id=>self.id,:batch_id=>self.batch.id,:subject_id=>subjects.collect(&:id),:score_type=>"s"}) + scores = GroupedExamReport.find_all_by_student_id_and_batch_id_and_subject_id_and_score_type(self.id, self.batch.id, subjects.collect(&:id), 's') else - scores = GroupedExamReport.find(:all,:conditions=>{:student_id=>self.id,:score_type=>"s"}) + scores = GroupedExamReport.find_all_by_student_id_and_score_type(self.id, 's') end - unless scores.empty? - if self.batch.gpa_enabled? - scores.reject!{|s| !((s.marks < level.gpa if level.marks_limit_type=="upper") or (s.marks >= level.gpa if level.marks_limit_type=="lower") or (s.marks == level.gpa if level.marks_limit_type=="exact"))} - else - scores.reject!{|s| !((s.marks < level.marks if level.marks_limit_type=="upper") or (s.marks >= level.marks if level.marks_limit_type=="lower") or (s.marks == level.marks if level.marks_limit_type=="exact"))} - end - unless scores.empty? - sub_count = level.subject_count - if level.subject_limit_type=="upper" - return true if scores.count < sub_count - elsif level.subject_limit_type=="exact" - return true if scores.count == sub_count - else - return true if scores.count >= sub_count - end - end + if scores.any? + scores = reject_scores(scores, level) + return true if scores.any? && check_scores_count_and_subject_count(level.subject_limit_type, scores.count, level.subject_count) end else - unless level.full_course==true - score = GroupedExamReport.find_by_student_id(self.id,:conditions=>{:batch_id=>self.batch.id,:score_type=>"c"}) + if level.full_course == false + score = GroupedExamReport.find_by_student_id_and_batch_id_and_score_type(self.id, self.batch.id, 'c') else total_student_score = 0 avg_student_score = 0 - marks = GroupedExamReport.find_all_by_student_id_and_score_type(self.id,"c") - unless marks.empty? - marks.map{|m| total_student_score+=m.marks} - avg_student_score = total_student_score.to_f/marks.count.to_f + marks = GroupedExamReport.find_all_by_student_id_and_score_type(self.id, 'c') + if marks.any? + marks.map{|m| total_student_score += m.marks} + avg_student_score = total_student_score.to_f / marks.count.to_f marks.first.marks = avg_student_score score = marks.first end end - unless score.nil? - if self.batch.gpa_enabled? - return true if((score.marks < level.gpa if level.marks_limit_type=="upper") or (score.marks >= level.gpa if level.marks_limit_type=="lower") or (score.marks == level.gpa if level.marks_limit_type=="exact")) - else - return true if((score.marks < level.marks if level.marks_limit_type=="upper") or (score.marks >= level.marks if level.marks_limit_type=="lower") or (score.marks == level.marks if level.marks_limit_type=="exact")) - end - end + return true if score.present? && check_score_marks(score.marks, level) end - elsif type=="course" - unless level.subject_count.nil? - scores = GroupedExamReport.find(:all,:conditions=>{:student_id=>self.id,:score_type=>"s"}) - unless scores.empty? - if level.marks_limit_type=="upper" - scores.reject!{|s| !(((s.marks < level.gpa unless level.gpa.nil?) if s.student.batch.gpa_enabled?) or (s.marks < level.marks unless level.marks.nil?))} - elsif level.marks_limit_type=="exact" - scores.reject!{|s| !(((s.marks == level.gpa unless level.gpa.nil?) if s.student.batch.gpa_enabled?) or (s.marks == level.marks unless level.marks.nil?))} - else - scores.reject!{|s| !(((s.marks >= level.gpa unless level.gpa.nil?) if s.student.batch.gpa_enabled?) or (s.marks >= level.marks unless level.marks.nil?))} - end - unless scores.empty? - sub_count = level.subject_count - unless level.full_course==true + elsif type == "course" + if level.subject_count.present? + scores = GroupedExamReport.find_all_by_student_id_and_score_type(self.id, 's') + + if scores.any? + scores = reject_scores(scores, level) + + if scores.any? + if level.full_course == false batch_ids = scores.collect(&:batch_id) batch_ids.each do|batch_id| - unless batch_ids.empty? + if batch_ids.any? count = batch_ids.count(batch_id) - if level.subject_limit_type=="upper" - return true if count < sub_count - elsif level.subject_limit_type=="exact" - return true if count == sub_count - else - return true if count >= sub_count - end + return true if check_scores_count_and_subject_count(level.subject_limit_type, count, level.subject_count) batch_ids.delete(batch_id) end end else - if level.subject_limit_type=="upper" - return true if scores.count < sub_count - elsif level.subject_limit_type=="exact" - return true if scores.count == sub_count - else - return true if scores.count >= sub_count - end + return true if check_scores_count_and_subject_count(level.subject_limit_type, scores.count, level.subject_count) end end end else - unless level.full_course==true - scores = GroupedExamReport.find(:all,:conditions=>{:student_id=>self.id,:score_type=>"c"}) - unless scores.empty? - if level.marks_limit_type=="upper" - scores.reject!{|s| !(((s.marks < level.gpa unless level.gpa.nil?) if s.student.batch.gpa_enabled?) or (s.marks < level.marks unless level.marks.nil?))} - elsif level.marks_limit_type=="exact" - scores.reject!{|s| !(((s.marks == level.gpa unless level.gpa.nil?) if s.student.batch.gpa_enabled?) or (s.marks == level.marks unless level.marks.nil?))} - else - scores.reject!{|s| !(((s.marks >= level.gpa unless level.gpa.nil?) if s.student.batch.gpa_enabled?) or (s.marks >= level.marks unless level.marks.nil?))} - end - return true unless scores.empty? + if level.full_course == false + scores = GroupedExamReport.find_all_by_student_id_and_score_type(self.id, 'c') + if scores.any? + scores = reject_scores(scores, level) + return true if scores.any? end else total_student_score = 0 avg_student_score = 0 - marks = GroupedExamReport.find_all_by_student_id_and_score_type(self.id,"c") - unless marks.empty? - marks.map{|m| total_student_score+=m.marks} - avg_student_score = total_student_score.to_f/marks.count.to_f - if level.marks_limit_type=="upper" - return true if(((avg_student_score < level.gpa unless level.gpa.nil?) if self.batch.gpa_enabled?) or (avg_student_score < level.marks unless level.marks.nil?)) - elsif level.marks_limit_type=="exact" - return true if(((avg_student_score == level.gpa unless level.gpa.nil?) if self.batch.gpa_enabled?) or (avg_student_score == level.marks unless level.marks.nil?)) - else - return true if(((avg_student_score >= level.gpa unless level.gpa.nil?) if self.batch.gpa_enabled?) or (avg_student_score >= level.marks unless level.marks.nil?)) - end + marks = GroupedExamReport.find_all_by_student_id_and_score_type(self.id, 'c') + if marks.any? + marks.map{|m| total_student_score += m.marks} + avg_student_score = total_student_score.to_f / marks.count.to_f + return true if check_score_marks(avg_student_score, level) end end end @@ -461,5 +349,68 @@ def has_higher_priority_ranking_level(ranking_level_id,type,subject_id) return false end - + private + + def date_of_birth_must_not_be_future + errors.add(:date_of_birth, "#{t('cant_be_a_future_date')}.") if self.date_of_birth.present? && self.date_of_birth >= Date.current + end + + def check_admission_no + errors.add(:admission_no, "#{t('model_errors.student.error3')}.") if self.admission_no == '0' + errors.add(:admission_no, "#{t('should_not_be_admin')}") if self.admission_no.to_s.downcase == 'admin' + end + + def is_active_true + self.is_active = true if self.is_active == false + end + + def create_user_and_validate + if self.new_record? + user_record = self.build_user + user_record.first_name = self.first_name + user_record.last_name = self.last_name + user_record.username = self.admission_no.to_s + user_record.password = self.admission_no.to_s + "123" + user_record.role = 'Student' + user_record.email = self.email.blank? ? "" : self.email.to_s + check_user_errors(user_record) + else + self.user.role = "Student" + changes_to_be_checked = ['admission_no','first_name','last_name','email','immediate_contact_id'] + check_changes = self.changed & changes_to_be_checked + if check_changes.any? + self.user.username = self.admission_no if check_changes.include?('admission_no') + self.user.first_name = self.first_name if check_changes.include?('first_name') + self.user.last_name = self.last_name if check_changes.include?('last_name') + self.user.email = self.email if check_changes.include?('email') + check_user_errors(self.user) + if check_changes.include?('immediate_contact_id') || check_changes.include?('admission_no') + Guardian.shift_user(self) + end + end + end + self.email = "" if self.email.blank? + return false unless errors.blank? + end + + def check_score_marks(score_marks, level) + if self.batch.gpa_enabled? + return true if (score_marks < level.gpa && level.marks_limit_type == 'upper') || (score_marks >= level.gpa && level.marks_limit_type == 'lower') || (score_marks == level.gpa && level.marks_limit_type == 'exact') + else + return true if (score_marks < level.marks && level.marks_limit_type == 'upper') || (score_marks >= level.marks && level.marks_limit_type == 'lower') || (score_marks == level.marks && level.marks_limit_type == 'exact') + end + end + + def reject_scores(scores, level) + if self.batch.gpa_enabled? + scores.reject{ |s| !((s.marks < level.gpa && level.marks_limit_type == 'upper') || (s.marks >= level.gpa && level.marks_limit_type == 'lower') || (s.marks == level.gpa && level.marks_limit_type == 'exact')) } + else + scores.reject{ |s| !((s.marks < level.marks && level.marks_limit_type == 'upper') || (s.marks >= level.marks && level.marks_limit_type == 'lower') || (s.marks == level.marks && level.marks_limit_type == 'exact')) } + end + end + + def check_scores_count_and_subject_count(subject_limit_type, scores_count, subject_count) + return true if (scores_count < subject_count && subject_limit_type == 'upper') || (scores_count >= subject_count && subject_limit_type == 'lower') || (scores_count == subject_count && subject_limit_type == 'exact') + end + end diff --git a/app/models/student_additional_detail.rb b/app/models/student_additional_detail.rb index 4537d46b5..bf30a2abd 100755 --- a/app/models/student_additional_detail.rb +++ b/app/models/student_additional_detail.rb @@ -1,48 +1,38 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class StudentAdditionalDetail < ActiveRecord::Base belongs_to :student belongs_to :student_additional_field, :foreign_key=>'additional_field_id' - #validates_presence_of :additional_info + validates_presence_of :additional_info, :if => :student_additional_field_is_mandatory? + before_validation :destroy_when_additional_info_blank def save - unless self.destroyed? - super - end + super unless self.destroyed? true end - def validate - if self.student_additional_field.is_mandatory == true - if self.additional_info.blank? - errors.add("additional_info","can't be blank") - return false - else - return true - end - else - if self.additional_info.blank? - self.destroy - return true - else - return true - end - end + def student_additional_field_is_mandatory? + student_additional_field && student_additional_field.is_mandatory? + end + + private + + def destroy_when_additional_info_blank + self.destroy if self.additional_info.blank? || !student_additional_field_is_mandatory? end end diff --git a/app/models/student_additional_field.rb b/app/models/student_additional_field.rb index 55461b6e9..d98fddcb7 100755 --- a/app/models/student_additional_field.rb +++ b/app/models/student_additional_field.rb @@ -1,28 +1,28 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class StudentAdditionalField < ActiveRecord::Base belongs_to :student belongs_to :student_additional_detail - has_many :student_additional_field_options, :dependent=>:destroy - validates_presence_of :name - validates_uniqueness_of :name,:case_sensitive => false - validates_format_of :name, :with => /^[^~`@%$*()\-\[\]{}"':;\/.,\\=+|]*$/i, + has_many :student_additional_field_options, :dependent => :destroy + + validates_presence_of :name + validates_uniqueness_of :name, :case_sensitive => false + validates_format_of :name, :with => /\A[^~`@%$*()\-\[\]{}"':;\/.,\\=+|]*\z/i, :message => "#{t('must_contain_only_letters_numbers_space')}" - accepts_nested_attributes_for :student_additional_field_options, :allow_destroy=>true + accepts_nested_attributes_for :student_additional_field_options, :allow_destroy => true end diff --git a/app/models/student_additional_field_option.rb b/app/models/student_additional_field_option.rb index 205baa6ef..d91c5db67 100644 --- a/app/models/student_additional_field_option.rb +++ b/app/models/student_additional_field_option.rb @@ -1,6 +1,3 @@ class StudentAdditionalFieldOption < ActiveRecord::Base - belongs_to :student_additional_field - - end diff --git a/app/models/student_category.rb b/app/models/student_category.rb index f075edf62..ed7bffb7a 100755 --- a/app/models/student_category.rb +++ b/app/models/student_category.rb @@ -1,36 +1,34 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class StudentCategory < ActiveRecord::Base has_many :students has_many :fee_category ,:class_name =>"FinanceFeeCategory" before_destroy :check_dependence validates_presence_of :name - validates_uniqueness_of :name, :scope=>:is_deleted,:case_sensitive => false, :if=> 'is_deleted == false' + validates_uniqueness_of :name, :scope => :is_deleted,:case_sensitive => false, :if => 'is_deleted == false' named_scope :active, :conditions => { :is_deleted => false} def empty_students Student.find_all_by_student_category_id(self.id).each do |s| - s.update_attributes(:student_category_id=>nil) + s.update_attributes(:student_category_id => nil) end - end def check_dependence @@ -38,6 +36,5 @@ def check_dependence errors.add_to_base( "#{t('category_is_in_use')}") return false end - end end diff --git a/app/models/student_previous_data.rb b/app/models/student_previous_data.rb index 4ca27398b..983650ce5 100755 --- a/app/models/student_previous_data.rb +++ b/app/models/student_previous_data.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class StudentPreviousData < ActiveRecord::Base belongs_to :student validates_presence_of :institution diff --git a/app/models/student_previous_subject_mark.rb b/app/models/student_previous_subject_mark.rb index ed644b062..2b581d6a4 100755 --- a/app/models/student_previous_subject_mark.rb +++ b/app/models/student_previous_subject_mark.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class StudentPreviousSubjectMark < ActiveRecord::Base belongs_to :student validates_presence_of :subject, :mark diff --git a/app/models/students_subject.rb b/app/models/students_subject.rb index 2619a510c..862d30fbb 100755 --- a/app/models/students_subject.rb +++ b/app/models/students_subject.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class StudentsSubject < ActiveRecord::Base belongs_to :student belongs_to :subject diff --git a/app/models/subject.rb b/app/models/subject.rb index 3d6bb480b..e8544c42b 100755 --- a/app/models/subject.rb +++ b/app/models/subject.rb @@ -1,63 +1,56 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class Subject < ActiveRecord::Base - belongs_to :batch belongs_to :elective_group - has_many :timetable_entries,:foreign_key=>'subject_id' + has_many :timetable_entries, :foreign_key => 'subject_id' has_many :employees_subjects - has_many :employees ,:through => :employees_subjects has_many :students_subjects - has_many :students, :through => :students_subjects + has_many :employees, :through => :employees_subjects + has_many :students, :through => :students_subjects has_many :grouped_exam_reports has_and_belongs_to_many_with_deferred_save :fa_groups - validates_presence_of :name, :max_weekly_classes, :code,:batch_id - validates_presence_of :credit_hours, :if=>:check_grade_type + validates_presence_of :name, :max_weekly_classes, :code, :batch_id + validates_presence_of :credit_hours, :if => :check_grade_type validates_numericality_of :max_weekly_classes - validates_numericality_of :amount,:allow_nil => true - validates_uniqueness_of :code, :case_sensitive => false, :scope=>[:batch_id,:is_deleted] ,:if=> 'is_deleted == false' + validates_numericality_of :amount, :allow_nil => true + validates_uniqueness_of :code, :case_sensitive => false, :scope => [:batch_id, :is_deleted] , :if => lambda { |s| !s.is_deleted? } named_scope :for_batch, lambda { |b| { :conditions => { :batch_id => b.to_i, :is_deleted => false } } } named_scope :without_exams, :conditions => { :no_exams => false, :is_deleted => false } named_scope :active, :conditions => { :is_deleted => false } + named_scope :not_in_exam_group, lambda { |exam_group| { :conditions => ['id NOT IN (?)', exam_group.exams.map(&:subject_id)] } } - before_save :fa_group_valid + validate :fa_group_valid def check_grade_type - unless self.batch.nil? - batch = self.batch - batch.gpa_enabled? or batch.cwa_enabled? - else - return false - end + batch && (batch.gpa_enabled? || batch.cwa_enabled?) end def inactivate - update_attributes(:is_deleted=>true) - self.employees_subjects.destroy_all + update_attributes(:is_deleted => true) + employees_subjects.destroy_all end def lower_day_grade - subjects = Subject.find_all_by_elective_group_id(self.elective_group_id) unless self.elective_group_id.nil? + subjects = Subject.find_all_by_elective_group_id(self.elective_group_id) if elective_group selected_employee = nil subjects.each do |subject| - employees = subject.employees - employees.each do |employee| + subject.employees.each do |employee| if selected_employee.nil? selected_employee = employee else @@ -65,48 +58,45 @@ def lower_day_grade end end end - return selected_employee + + selected_employee end def lower_week_grade - subjects = Subject.find_all_by_elective_group_id(self.elective_group_id) unless self.elective_group_id.nil? + subjects = Subject.find_all_by_elective_group_id(self.elective_group_id) if elective_group selected_employee = nil subjects.each do |subject| - employees = subject.employees - employees.each do |employee| + subject.employees.each do |employee| if selected_employee.nil? selected_employee = employee else - selected_employee = employee if employee.max_hours_per_week.to_i < selected_employee.max_hours_per_week.to_i + selected_employee = employee if employee.max_hours_per_week.to_i < selected_employee.max_hours_per_week.to_i end end end - return selected_employee + + selected_employee end def no_exam_for_batch(batch_id) - grouped_exams = GroupedExam.find_all_by_batch_id(batch_id).collect(&:exam_group_id) - return exam_not_created(grouped_exams) + exam_group_ids = GroupedExam.find_all_by_batch_id(batch_id).collect(&:exam_group_id) + + exam_not_created(exam_group_ids) end def exam_not_created(exam_group_ids) - exams = Exam.find_all_by_exam_group_id_and_subject_id(exam_group_ids,self.id) - if exams.empty? - return true - else - return false - end + exams = Exam.find_all_by_exam_group_id_and_subject_id(exam_group_ids, self.id) + exams.empty? end private def fa_group_valid fa_groups.group_by(&:cce_exam_category_id).values.each do |fg| - if fg.length > 2 + if fg.count > 2 errors.add(:fa_group, "cannot have more than 2 fa group under a single exam category") - return false end end end - + end diff --git a/app/models/subject_leave.rb b/app/models/subject_leave.rb index b764fbc2e..72967d4df 100644 --- a/app/models/subject_leave.rb +++ b/app/models/subject_leave.rb @@ -1,27 +1,27 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class SubjectLeave < ActiveRecord::Base belongs_to :student belongs_to :batch belongs_to :subject belongs_to :employee belongs_to :class_timing - + validates_presence_of :subject_id validates_presence_of :batch_id validates_presence_of :student_id @@ -30,7 +30,10 @@ class SubjectLeave < ActiveRecord::Base named_scope :by_month_and_subject, lambda { |d,s| { :conditions => { :month_date => d.beginning_of_month..d.end_of_month , :subject_id => s} } } named_scope :by_month_batch_subject, lambda { |d,b,s| { :conditions => { :month_date => d.beginning_of_month..d.end_of_month , :subject_id => s,:batch_id=>b} } } validates_uniqueness_of :student_id,:scope=>[:class_timing_id,:month_date],:message=>"already marked as absent" - def validate - errors.add("#{t('attendance_before_the_date_of_admission')}") if self.month_date < self.student.admission_date + validate :check_attendance_before_the_date_of_admission + + private + def check_attendance_before_the_date_of_admission + errors.add("#{t('attendance_before_the_date_of_admission')}") if self.student && self.month_date < self.student.admission_date end end diff --git a/app/models/time_zone.rb b/app/models/time_zone.rb index 1f0b9c72e..26e8c7bf0 100644 --- a/app/models/time_zone.rb +++ b/app/models/time_zone.rb @@ -1,19 +1,19 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class TimeZone < ActiveRecord::Base end diff --git a/app/models/timetable.rb b/app/models/timetable.rb index c8287c7ef..22188dfb8 100644 --- a/app/models/timetable.rb +++ b/app/models/timetable.rb @@ -1,20 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class Timetable < ActiveRecord::Base has_many :timetable_entries , :dependent=>:destroy validates_presence_of :start_date @@ -102,11 +102,11 @@ def self.subject_tte(subject_id,date) def self.register_range(batch,date) start=[] - start<:start_date,:order=>:start_date).start_date.to_date stop=[] - stop<:end_date,:order=>:end_date).end_date.to_date range=(start.max..stop.min).to_a - batch.holiday_event_dates diff --git a/app/models/timetable_entry.rb b/app/models/timetable_entry.rb index 379751e98..bc6e485b5 100755 --- a/app/models/timetable_entry.rb +++ b/app/models/timetable_entry.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class TimetableEntry < ActiveRecord::Base belongs_to :timetable belongs_to :batch @@ -23,5 +22,5 @@ class TimetableEntry < ActiveRecord::Base belongs_to :subject belongs_to :employee belongs_to :weekday - delegate :day_of_week,:to=>:weekday -end \ No newline at end of file + delegate :day_of_week, :to => :weekday +end diff --git a/app/models/user.rb b/app/models/user.rb index c69fd506b..3aed09cf6 100755 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,52 +1,50 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class User < ActiveRecord::Base attr_accessor :password, :role, :old_password, :new_password, :confirm_password - validates_uniqueness_of :username, :scope=> [:is_deleted],:if=> 'is_deleted == false' #, :email + validates_uniqueness_of :username, :scope => [:is_deleted], :if => 'is_deleted == false' validates_length_of :username, :within => 1..20 validates_length_of :password, :within => 4..40, :allow_nil => true - validates_format_of :username, :with => /^[A-Z0-9_-]*$/i, + validates_format_of :username, :with => /\A[A-Z0-9_-]*\z/i, :message => "#{t('must_contain_only_letters')}" - validates_format_of :email, :with => /^[A-Z0-9._%-]+@([A-Z0-9-]+\.)+[A-Z]{2,4}$/i, :allow_blank=>true, + validates_format_of :email, :with => /\A[A-Z0-9._%-]+@([A-Z0-9-]+\.)+[A-Z]{2,4}\z/i, :allow_blank => true, :message => "#{t('must_be_a_valid_email_address')}" - validates_presence_of :role , :on=>:create + validates_presence_of :role, :on => :create validates_presence_of :password, :on => :create has_and_belongs_to_many :privileges has_many :user_events - has_many :events,:through=>:user_events - has_one :student_record,:class_name=>"Student",:foreign_key=>"user_id" - has_one :employee_record,:class_name=>"Employee",:foreign_key=>"user_id" + has_many :events, :through => :user_events + has_one :student_record, :class_name => 'Student', :foreign_key => 'user_id' + has_one :employee_record, :class_name => 'Employee', :foreign_key => 'user_id' - named_scope :active, :conditions => { :is_deleted => false } + named_scope :active, :conditions => { :is_deleted => false } named_scope :inactive, :conditions => { :is_deleted => true } def before_save - self.salt = random_string(8) if self.salt == nil - self.hashed_password = Digest::SHA1.hexdigest(self.salt + self.password) unless self.password.nil? + self.salt = random_string(8) if self.salt.blank? + self.hashed_password = Digest::SHA1.hexdigest(self.salt + self.password) if self.password.present? if self.new_record? - self.admin, self.student, self.employee = false, false, false - self.admin = true if self.role == 'Admin' - self.student = true if self.role == 'Student' - self.employee = true if self.role == 'Employee' - self.parent = true if self.role == 'Parent' + self.admin = self.role == 'Admin' + self.student = self.role == 'Student' + self.employee = self.role == 'Employee' + self.parent = self.role == 'Parent' self.is_first_login = true end end @@ -56,19 +54,11 @@ def full_name end def check_reminders - reminders =[] - reminders = Reminder.find(:all , :conditions => ["recipient = '#{self.id}'"]) - count = 0 - reminders.each do |r| - unless r.is_read - count += 1 - end - end - return count + Reminder.find(:all, :conditions => { :recipient => self.id, :is_read => true }).count end def self.authenticate?(username, password) - u = User.find_by_username username + u = User.find_by_username(username) u.hashed_password == Digest::SHA1.hexdigest(u.salt + password) end @@ -80,11 +70,10 @@ def random_string(len) end def role_name - return "#{t('admin')}" if self.admin? - return "#{t('student_text')}" if self.student? + return "#{t('admin')}" if self.admin? + return "#{t('student_text')}" if self.student? return "#{t('employee_text')}" if self.employee? - return "#{t('parent')}" if self.parent? - return nil + return "#{t('parent')}" if self.parent? end def role_symbols @@ -124,28 +113,28 @@ def parent_record end def has_subject_in_batch(b) - employee_record.subjects.collect(&:batch_id).include? b.id + employee_record.subjects.collect(&:batch_id).include?(b.id) end def days_events(date) - all_events=[] + all_events = [] case(role_name) - when "Admin" - all_events=Event.find(:all,:conditions => ["? between date(events.start_date) and date(events.end_date)",date]) - when "Student" - all_events+= events.all(:conditions=>["? between date(events.start_date) and date(events.end_date)",date]) - all_events+= student_record.batch.events.all(:conditions=>["? between date(events.start_date) and date(events.end_date)",date]) - all_events+= Event.all(:conditions=>["(? between date(events.start_date) and date(events.end_date)) and is_common = true",date]) - when "Parent" - all_events+= events.all(:conditions=>["? between date(events.start_date) and date(events.end_date)",date]) - all_events+= parent_record.user.events.all(:conditions=>["? between date(events.start_date) and date(events.end_date)",date]) - all_events+= parent_record.batch.events.all(:conditions=>["? between date(events.start_date) and date(events.end_date)",date]) - all_events+= Event.all(:conditions=>["(? between date(events.start_date) and date(events.end_date)) and is_common = true",date]) - when "Employee" - all_events+= events.all(:conditions=>["? between events.start_date and events.end_date",date]) - all_events+= employee_record.employee_department.events.all(:conditions=>["? between date(events.start_date) and date(events.end_date)",date]) - all_events+= Event.all(:conditions=>["(? between date(events.start_date) and date(events.end_date)) and is_exam = true",date]) - all_events+= Event.all(:conditions=>["(? between date(events.start_date) and date(events.end_date)) and is_common = true",date]) + when 'Admin' + all_events = Event.find(:all, :conditions => ['? BETWEEN DATE(events.start_date) AND DATE(events.end_date)', date]) + when 'Student' + all_events += events.all(:conditions => ['? BETWEEN DATE(events.start_date) AND DATE(events.end_date)', date]) + all_events += student_record.batch.events.all(:conditions => ['? BETWEEN DATE(events.start_date) AND DATE(events.end_date)', date]) + all_events += Event.all(:conditions => ['(? BETWEEN DATE(events.start_date) AND DATE(events.end_date)) AND is_common = ?', date, true]) + when 'Parent' + all_events += events.all(:conditions => ['? BETWEEN DATE(events.start_date) AND DATE(events.end_date)', date]) + all_events += parent_record.user.events.all(:conditions => ['? BETWEEN DATE(events.start_date) AND DATE(events.end_date)', date]) + all_events += parent_record.batch.events.all(:conditions => ['? BETWEEN DATE(events.start_date) AND DATE(events.end_date)', date]) + all_events += Event.all(:conditions => ['(? BETWEEN DATE(events.start_date) AND DATE(events.end_date)) AND is_common = ?', date, true]) + when 'Employee' + all_events += events.all(:conditions => ['? BETWEEN events.start_date AND events.end_date', date]) + all_events += employee_record.employee_department.events.all(:conditions => ['? BETWEEN DATE(events.start_date) AND DATE(events.end_date)', date]) + all_events += Event.all(:conditions => ['(? BETWEEN DATE(events.start_date) AND DATE(events.end_date)) AND is_exam = ?', date, true]) + all_events += Event.all(:conditions => ['(? BETWEEN DATE(events.start_date) AND DATE(events.end_date)) AND is_common = ?', date, true]) end all_events end @@ -153,33 +142,34 @@ def days_events(date) def next_event(date) all_events=[] case(role_name) - when "Admin" - all_events=Event.find(:all,:conditions => ["? < date(events.end_date)",date],:order=>"start_date") - when "Student" - all_events+= events.all(:conditions=>["? < date(events.end_date)",date]) - all_events+= student_record.batch.events.all(:conditions=>["? < date(events.end_date)",date],:order=>"start_date") - all_events+= Event.all(:conditions=>["(? < date(events.end_date)) and is_common = true",date],:order=>"start_date") - when "Parent" - all_events+= events.all(:conditions=>["? < date(events.end_date)",date]) - all_events+= parent_record.user.events.all(:conditions=>["? < date(events.end_date)",date]) - all_events+= parent_record.batch.events.all(:conditions=>["? < date(events.end_date)",date],:order=>"start_date") - all_events+= Event.all(:conditions=>["(? < date(events.end_date)) and is_common = true",date],:order=>"start_date") - when "Employee" - all_events+= events.all(:conditions=>["? < date(events.end_date)",date],:order=>"start_date") - all_events+= employee_record.employee_department.events.all(:conditions=>["? < date(events.end_date)",date],:order=>"start_date") - all_events+= Event.all(:conditions=>["(? < date(events.end_date)) and is_exam = true",date],:order=>"start_date") - all_events+= Event.all(:conditions=>["(? < date(events.end_date)) and is_common = true",date],:order=>"start_date") + when 'Admin' + all_events = Event.find(:all,:conditions => ['? < DATE(events.end_date)', date], :order => 'start_date') + when 'Student' + all_events += events.all(:conditions => ['? < DATE(events.end_date)', date]) + all_events += student_record.batch.events.all(:conditions => ['? < DATE(events.end_date)', date], :order => 'start_date') + all_events += Event.all(:conditions => ['(? < DATE(events.end_date)) AND is_common = ?', date, true], :order => 'start_date') + when 'Parent' + all_events += events.all(:conditions => ['? < DATE(events.end_date)', date]) + all_events += parent_record.user.events.all(:conditions => ['? < DATE(events.end_date)', date]) + all_events += parent_record.batch.events.all(:conditions => ['? < DATE(events.end_date)', date], :order => 'start_date') + all_events += Event.all(:conditions => ['(? < DATE(events.end_date)) AND is_common = ?', date, true], :order => 'start_date') + when 'Employee' + all_events += events.all(:conditions => ['? < DATE(events.end_date)', date], :order => 'start_date') + all_events += employee_record.employee_department.events.all(:conditions => ['? < DATE(events.end_date)', date], :order => 'start_date') + all_events += Event.all(:conditions => ['(? < DATE(events.end_date)) AND is_exam = ?', date, true], :order => 'start_date') + all_events += Event.all(:conditions => ['(? < DATE(events.end_date)) AND is_common = ?', date, true], :order => 'start_date') end - start_date=all_events.collect(&:start_date).min + start_date = all_events.collect(&:start_date).min unless start_date - return "" + return '' else - next_date=(start_date.to_date<=date ? date+1.days : start_date ) + next_date = (start_date.to_date <= date ? date + 1.days : start_date ) next_date end end + def soft_delete - self.update_attributes(:is_deleted =>true) + self.update_attributes(:is_deleted => true) end end diff --git a/app/models/user_event.rb b/app/models/user_event.rb index d703710df..deb6027ed 100644 --- a/app/models/user_event.rb +++ b/app/models/user_event.rb @@ -1,23 +1,23 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class UserEvent < ActiveRecord::Base belongs_to :user belongs_to :event - validates_uniqueness_of :user_id,:scope =>:event_id + validates_uniqueness_of :user_id, :scope => :event_id end \ No newline at end of file diff --git a/app/models/user_notifier.rb b/app/models/user_notifier.rb index c4e9f6de0..01ff025ba 100755 --- a/app/models/user_notifier.rb +++ b/app/models/user_notifier.rb @@ -1,21 +1,20 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class UserNotifier < ActionMailer::Base def forgot_password(user,current_url) setup_email(user,current_url) diff --git a/app/models/weekday.rb b/app/models/weekday.rb index ba565e0df..b503d552d 100755 --- a/app/models/weekday.rb +++ b/app/models/weekday.rb @@ -1,63 +1,57 @@ -#Fedena -#Copyright 2011 Foradian Technologies Private Limited +# Fedena +# Copyright 2011 Foradian Technologies Private Limited # -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ +# This product includes software developed at +# Project Fedena - http://www.projectfedena.org/ # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. - +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. class Weekday < ActiveRecord::Base + + WEEKDAYS = { + '0' => I18n.t('sunday'), + '1' => I18n.t('monday'), + '2' => I18n.t('tuesday'), + '3' => I18n.t('wednesday'), + '4' => I18n.t('thursday'), + '5' => I18n.t('friday'), + '6' => I18n.t('saturday') + } + belongs_to :batch - has_many :timetable_entries , :dependent=>:destroy - default_scope :order => 'weekday asc' - named_scope :default, :conditions => { :batch_id => nil,:is_deleted=>false} - named_scope :for_batch, lambda { |b| { :conditions => { :batch_id => b.to_i,:is_deleted=>false } } } + has_many :timetable_entries, :dependent => :destroy + + default_scope :order => 'weekday ASC' + named_scope :default, :conditions => { :batch_id => nil, :is_deleted => false } + named_scope :for_batch, lambda { |b| { :conditions => { :batch_id => b, :is_deleted => false } } } def self.weekday_by_day(batch_id) - days={} weekdays = Weekday.find_all_by_batch_id(batch_id) - if weekdays.empty? - weekdays = Weekday.default - end - days=weekdays.group_by(&:day_of_week) + weekdays = Weekday.default if weekdays.empty? + + weekdays.group_by(&:day_of_week) end def deactivate - self.update_attribute(:is_deleted,true) + self.update_attribute(:is_deleted, true) end - def self.add_day(batch_id,day) - unless batch_id==0 - unless Weekday.find_by_batch_id_and_day_of_week(batch_id,day).nil? - Weekday.find_by_batch_id_and_day_of_week(batch_id,day).update_attributes(:is_deleted=>false,:day_of_week => day) - else - w=Weekday.new - w.day_of_week = day - w.weekday = day - w.batch_id = batch_id - w.is_deleted = false - w.save - end + def self.add_day(batch_id, day) + batch_id = nil if batch_id == 0 + + if weekday = Weekday.find_by_batch_id_and_day_of_week(batch_id, day) + weekday.update_attributes(:is_deleted => false, :day_of_week => day) else - unless Weekday.find_by_batch_id_and_day_of_week(nil,day).nil? - Weekday.find_by_batch_id_and_day_of_week(nil,day).update_attributes(:is_deleted=>false,:day_of_week => day) - else - w=Weekday.new - w.day_of_week = day - w.weekday = day - w.is_deleted = false - w.save - end + Weekday.create(:day_of_week => day, :weekday => day, :batch_id => batch_id, :is_deleted => false) end end end diff --git a/app/views/archived_student/academic_report.html.erb b/app/views/archived_student/academic_report.html.erb index 4f4f074ec..e451d84a1 100755 --- a/app/views/archived_student/academic_report.html.erb +++ b/app/views/archived_student/academic_report.html.erb @@ -63,7 +63,7 @@ <% @g = 0 %> <% end %> <% end %> - <% total_score = ArchivedExamScore.new() %> + <% total_score = ArchivedExamScore.new %> <% if @mmg == @g %> <%= total_score.grouped_exam_subject_total(subject,@student,@type,@batch) %> <% else %> diff --git a/app/views/archived_student/generated_report4.html.erb b/app/views/archived_student/generated_report4.html.erb index b6cd3c657..858f713b2 100755 --- a/app/views/archived_student/generated_report4.html.erb +++ b/app/views/archived_student/generated_report4.html.erb @@ -34,7 +34,7 @@ <% unless flash[:notice].nil? %>

    <%= flash[:notice] %>

    <% end %> - +

    <%= @student.batch.name %> - <%= @student.batch.course.full_name %>

    <%= @student.full_name %>

    @@ -70,7 +70,7 @@ <% end %> <% end %> - <% total_score = ArchivedExamScore.new() %> + <% total_score = ArchivedExamScore.new %> <% if @mmg == @g %> <%= total_score.grouped_exam_subject_total(subject,@student,@type) %> <% else %> diff --git a/app/views/archived_student/generated_report4_pdf.erb b/app/views/archived_student/generated_report4_pdf.erb index d4ea2beda..64c6f4f44 100644 --- a/app/views/archived_student/generated_report4_pdf.erb +++ b/app/views/archived_student/generated_report4_pdf.erb @@ -59,7 +59,7 @@ <% end %> <% end %> - <% total_score = ArchivedExamScore.new() %> + <% total_score = ArchivedExamScore.new %> <% if @mmg == @g %> <%= total_score.grouped_exam_subject_total(subject,@student,@type) %> <% else %> diff --git a/app/views/archived_student/previous_years_marks_overview.html.erb b/app/views/archived_student/previous_years_marks_overview.html.erb index 4fe8b514d..e3234cbfe 100755 --- a/app/views/archived_student/previous_years_marks_overview.html.erb +++ b/app/views/archived_student/previous_years_marks_overview.html.erb @@ -51,7 +51,7 @@
    - <% exam = ArchivedExamScore.new() %> + <% exam = ArchivedExamScore.new %> <% aggr = exam.batch_wise_aggregate(@student,b) %> <%= b.name %> | <%= t('aggregate') %> : <%="%.2f" %aggr.to_f unless aggr=="nil" %>
    @@ -92,7 +92,7 @@ <% end %> <% end %> - <% total_score = ArchivedExamScore.new() %> + <% total_score = ArchivedExamScore.new %> <% if @mmg == @g %> <%= total_score.grouped_exam_subject_total(subject,@student,@type,b) %> <% else %> diff --git a/app/views/courses/new.html.erb b/app/views/courses/new.html.erb index 5daf23bb0..2c7c454c3 100755 --- a/app/views/courses/new.html.erb +++ b/app/views/courses/new.html.erb @@ -84,12 +84,12 @@
    <%= batch_form.label "#{t('start_date')}" %>
    -
    <%= calendar_date_select_tag 'course[batches_attributes][0][start_date]', I18n.l(Date.today,:format=>:default), :popup=>"force" %>
    +
    <%= calendar_date_select_tag 'course[batches_attributes][0][started_on]', I18n.l(Date.today,:format=>:default), :popup=>"force" %>
    <%= batch_form.label "#{t('end_date')}" %>
    -
    <%= calendar_date_select_tag 'course[batches_attributes][0][end_date]', I18n.l(Date.today + 1.year,:format=>:default), :popup=>"force" %>
    +
    <%= calendar_date_select_tag 'course[batches_attributes][0][ended_on]', I18n.l(Date.today + 1.year,:format=>:default), :popup=>"force" %>
    <% end %> diff --git a/app/views/employee/leave_management.erb b/app/views/employee/leave_management.erb index a9c065688..bd9c3ba92 100755 --- a/app/views/employee/leave_management.erb +++ b/app/views/employee/leave_management.erb @@ -125,7 +125,7 @@ <%= l.hidden_field :employee_id, :value=>@employee.id %>
    -
    <%= select :leave_apply, :employee_leave_types_id, @leave_types.map {|s| [s.name, s.id]},:prompt => "Select" %>
    +
    <%= select :leave_apply, :employee_leave_type_id, @leave_types.map {|s| [s.name, s.id]},:prompt => "Select" %>
    @@ -158,4 +158,4 @@ -
    \ No newline at end of file +
    diff --git a/app/views/employee_attendance/_attendance_report.erb b/app/views/employee_attendance/_attendance_report.erb index b60f9201b..79ccef3b2 100755 --- a/app/views/employee_attendance/_attendance_report.erb +++ b/app/views/employee_attendance/_attendance_report.erb @@ -37,7 +37,7 @@ - + <% @employees.each do |e| %> @@ -50,7 +50,7 @@ <% @leave_types.each do |lt1| %> <% leave_count = EmployeeLeave.find_by_employee_leave_type_id_and_employee_id(lt1.id, e.id)%> - <% unless leave_count.reset_date.nil? %> + <% if leave_count.present? && leave_count.reset_date.present? %> <% report = EmployeeAttendance.find_all_by_employee_id_and_employee_leave_type_id(e.id, lt1.id, :conditions=> ["attendance_date >= '#{leave_count.reset_date}'"]) %> <% else %> <% report = EmployeeAttendance.find_all_by_employee_id_and_employee_leave_type_id(e.id, lt1.id) %> diff --git a/app/views/employee_attendance/_employee_reset_success.erb b/app/views/employee_attendance/_employee_reset_success.erb new file mode 100755 index 000000000..12a1e5a28 --- /dev/null +++ b/app/views/employee_attendance/_employee_reset_success.erb @@ -0,0 +1,45 @@ +<%-# Fedena +#Copyright 2010 Foradian Technologies Private Limited +# +#This product includes software developed at +#Project Fedena - http://www.projectfedena.org/ +# +#Licensed under the Apache License, Version 2.0 (the "License"); +#you may not use this file except in compliance with the License. +#You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +#Unless required by applicable law or agreed to in writing, +#software distributed under the License is distributed on an +#"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +#KIND, either express or implied. See the License for the +#specific language governing permissions and limitations +#under the License. -%> + +<% unless flash[:notice].nil? %> +

    <%= flash[:notice] %>

    + <% end %> + + + + + + + + <% @leave_count.each do |e| %> + <% leave_type = EmployeeLeaveType.find_by_id(e.employee_leave_type_id)%> + <% if leave_type.present? && leave_type.status %> + + + + + <%unless e.reset_date.nil? %> + + <%else%> + + <%end%> + + <%end%> + <% end %> +
    <%= t('leave_types') %><%= t('available_leave') %><%= t('leave_taken') %><%= t('last_reset_date') %>
    <%=leave_type.name %><%=e.leave_count %><%=e.leave_taken %><%= I18n.l(e.reset_date,:format=>"%d / %m / %Y") %>-
    diff --git a/app/views/employee_attendance/_employee_reset_sucess.erb b/app/views/employee_attendance/_employee_reset_sucess.erb deleted file mode 100755 index c1ffad778..000000000 --- a/app/views/employee_attendance/_employee_reset_sucess.erb +++ /dev/null @@ -1,45 +0,0 @@ -<%-# Fedena -#Copyright 2010 Foradian Technologies Private Limited -# -#This product includes software developed at -#Project Fedena - http://www.projectfedena.org/ -# -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -#Unless required by applicable law or agreed to in writing, -#software distributed under the License is distributed on an -#"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -#KIND, either express or implied. See the License for the -#specific language governing permissions and limitations -#under the License. -%> - -<% unless flash[:notice].nil? %> -

    <%= flash[:notice] %>

    - <% end %> - - - - - - - - <% @leave_count.each do |e| %> - <% leave_type =EmployeeLeaveType.find_by_id(e.employee_leave_type_id)%> - <% if leave_type.status %> - - - - - <%unless e.reset_date.nil? %> - - <%else%> - - <%end%> - - <%end%> - <% end %> -
    <%= t('leave_types') %><%= t('available_leave') %><%= t('leave_taken') %><%= t('last_reset_date') %>
    <%=leave_type.name %><%=e.leave_count %><%=e.leave_taken %><%= I18n.l(e.reset_date,:format=>"%d / %m / %Y") %>-
    \ No newline at end of file diff --git a/app/views/employee_attendance/apply_leave.erb b/app/views/employee_attendance/apply_leave.erb index 871ecaad6..5eef65847 100755 --- a/app/views/employee_attendance/apply_leave.erb +++ b/app/views/employee_attendance/apply_leave.erb @@ -50,7 +50,7 @@ <% form_for :leave_apply do |l| %> <%= error_messages_for :leave_apply %> <%= l.hidden_field :employee_id, :value=>@employee.id %> - <%= t('leave_types') %>:<%= select :leave_apply, :employee_leave_types_id, @leave_types.map {|s| [s.name, s.id]},:prompt => "#{t('select')}" %>
    + <%= t('leave_types') %>:<%= select :leave_apply, :employee_leave_type_id, @leave_types.map {|s| [s.name, s.id]},:prompt => "#{t('select')}" %>
    <%= t('start_date') %>:<%= l.text_field :start_date %>
    <%= t('end_date') %>:<%= l.text_field :end_date %>
    <%= t('reason') %>:<%= l.text_field :reason %> @@ -58,4 +58,4 @@ <% end %> -
    \ No newline at end of file + diff --git a/app/views/employee_attendance/leaves.erb b/app/views/employee_attendance/leaves.erb index 895c97c46..e6eabbaeb 100755 --- a/app/views/employee_attendance/leaves.erb +++ b/app/views/employee_attendance/leaves.erb @@ -76,7 +76,7 @@ <%= l.hidden_field :employee_id, :value=>@employee.id %>
    -
    <%= select :leave_apply, :employee_leave_types_id, @leave_types.map {|s| [s.name, s.id]},:prompt => "Select" %>
    +
    <%= select :leave_apply, :employee_leave_type_id, @leave_types.map {|s| [s.name, s.id]},:prompt => "Select" %>
    diff --git a/app/views/exam/_grouped_exam_report.erb b/app/views/exam/_grouped_exam_report.erb index a62cdb727..74577c5a0 100644 --- a/app/views/exam/_grouped_exam_report.erb +++ b/app/views/exam/_grouped_exam_report.erb @@ -138,7 +138,7 @@ <% end %> <% end %> - <% total_score = ExamScore.new() %> + <% total_score = ExamScore.new %> <% unless all_exams.empty? %> <% if @mmg == @g %> <%= total_score.grouped_exam_subject_total(subject,@student,@type) %> diff --git a/app/views/exam/academic_report.html.erb b/app/views/exam/academic_report.html.erb index fb8a57c06..6d970da54 100755 --- a/app/views/exam/academic_report.html.erb +++ b/app/views/exam/academic_report.html.erb @@ -63,7 +63,7 @@ <% @g = 0 %> <% end %> <% end %> - <% total_score = ExamScore.new() %> + <% total_score = ExamScore.new %> <% if @mmg == @g %> <%= total_score.grouped_exam_subject_total(subject,@student,@type,@batch) %> <% else %> diff --git a/app/views/exam/combined_grouped_exam_report_pdf.html.erb b/app/views/exam/combined_grouped_exam_report_pdf.html.erb index af0413f99..03af199d8 100644 --- a/app/views/exam/combined_grouped_exam_report_pdf.html.erb +++ b/app/views/exam/combined_grouped_exam_report_pdf.html.erb @@ -146,7 +146,7 @@ <% end %> <% end %> - <% total_score = ExamScore.new() %> + <% total_score = ExamScore.new %> <% unless all_exams.empty? %> <% if @mmg == @g %> <%= total_score.grouped_exam_subject_total(subject,student,@type) %> diff --git a/app/views/exam/generated_report4_pdf.erb b/app/views/exam/generated_report4_pdf.erb index be7d7b7ce..3a1c2e5f5 100644 --- a/app/views/exam/generated_report4_pdf.erb +++ b/app/views/exam/generated_report4_pdf.erb @@ -128,7 +128,7 @@ <% end %> <% end %> - <% total_score = ExamScore.new() %> + <% total_score = ExamScore.new %> <% unless all_exams.empty? %> <% if @mmg == @g %> <%= total_score.grouped_exam_subject_total(subject,@student,@type) %> diff --git a/app/views/exam/previous_years_marks_overview.html.erb b/app/views/exam/previous_years_marks_overview.html.erb index fa9bb0d5b..266e593b2 100755 --- a/app/views/exam/previous_years_marks_overview.html.erb +++ b/app/views/exam/previous_years_marks_overview.html.erb @@ -75,7 +75,7 @@
    - <% exam = ExamScore.new() %> + <% exam = ExamScore.new %> <% @aggr = exam.batch_wise_aggregate(@student,b) %> <%= b.name %> |<%= t('aggregate') %> : <%="%.2f" %@aggr.to_f unless @aggr== 'nil' or @aggr.nil? %>
    @@ -116,7 +116,7 @@ <% end %> <% end %> - <% total_score = ExamScore.new() %> + <% total_score = ExamScore.new %> <% if @mmg == @g %> <%= total_score.grouped_exam_subject_total(subject,@student,@type,b) %> <% else %> diff --git a/app/views/exam/previous_years_marks_overview_pdf.erb b/app/views/exam/previous_years_marks_overview_pdf.erb index 642acb0ce..56841b8bc 100644 --- a/app/views/exam/previous_years_marks_overview_pdf.erb +++ b/app/views/exam/previous_years_marks_overview_pdf.erb @@ -47,7 +47,7 @@
    - <% exam = ExamScore.new() %> + <% exam = ExamScore.new %> <% @aggr = exam.batch_wise_aggregate(@student,b) %>

    <%= b.course.full_name+" "+b.name %> |<%= t('aggregate') %> : <%="%.2f" %@aggr.to_f unless @aggr== 'nil' or @aggr.nil? %>

    @@ -102,7 +102,7 @@ <% end %> <% end %> - <% total_score = ExamScore.new() %> + <% total_score = ExamScore.new %> <% if @mmg == @g %> <%= total_score.grouped_exam_subject_total(subject,@student,@type,b) %> <% else %> diff --git a/app/views/exam/student_transcript.html.erb b/app/views/exam/student_transcript.html.erb index e7fa98da1..449ce9577 100644 --- a/app/views/exam/student_transcript.html.erb +++ b/app/views/exam/student_transcript.html.erb @@ -118,7 +118,7 @@ <% subject_average = GroupedExamReport.find_by_student_id_and_subject_id_and_score_type(@student.id,s.id,"s") %> <% unless subject_average.nil? %> - <% if @student.has_retaken_exam(s.id) %> + <% if @student.has_retaken_exam?(s.id) %> <%= s.code %> - <% else %> <%= s.code %> diff --git a/app/views/exam/student_transcript_pdf.html.erb b/app/views/exam/student_transcript_pdf.html.erb index e8770e318..ce9c2097a 100644 --- a/app/views/exam/student_transcript_pdf.html.erb +++ b/app/views/exam/student_transcript_pdf.html.erb @@ -79,7 +79,7 @@ <% subject_average = GroupedExamReport.find_by_student_id_and_subject_id_and_score_type(@student.id,s.id,"s") %> <% unless subject_average.nil? %> "> - <% if @student.has_retaken_exam(s.id) %> + <% if @student.has_retaken_exam?(s.id) %> <%= s.code %> - <% else %> <%= s.code %> @@ -139,4 +139,4 @@ <% end %>
    -
    \ No newline at end of file +
    diff --git a/app/views/exam_reports/_grouped_exam_report.erb b/app/views/exam_reports/_grouped_exam_report.erb index d4d3cb602..2eaf66038 100644 --- a/app/views/exam_reports/_grouped_exam_report.erb +++ b/app/views/exam_reports/_grouped_exam_report.erb @@ -135,7 +135,7 @@ <% end %> <% end %> - <% total_score = ExamScore.new() %> + <% total_score = ExamScore.new %> <% if @mmg == @g %> <%= total_score.grouped_exam_subject_total(subject,@student,@type) %> <% else %> diff --git a/app/views/exam_reports/archived_batches_exam_report_pdf.erb b/app/views/exam_reports/archived_batches_exam_report_pdf.erb index d3cdc8a5e..286dfd1ca 100644 --- a/app/views/exam_reports/archived_batches_exam_report_pdf.erb +++ b/app/views/exam_reports/archived_batches_exam_report_pdf.erb @@ -125,7 +125,7 @@ <% end %> <% end %> - <% total_score = ExamScore.new() %> + <% total_score = ExamScore.new %> <% if @mmg == @g %> <%= total_score.grouped_exam_subject_total(subject,@student,@type) %> <% else %> diff --git a/app/views/layouts/_autosuggest_menu.html.erb b/app/views/layouts/_autosuggest_menu.html.erb index 1a6cd0b7c..675e323b5 100644 --- a/app/views/layouts/_autosuggest_menu.html.erb +++ b/app/views/layouts/_autosuggest_menu.html.erb @@ -70,5 +70,5 @@ -<%= text_field_tag :autosuggest_menu,{} ,:id=>'autosuggest_menu_input',:placeholder => "#{t('autosuggest_menu.search_actions_and_events')}" %> +<%= text_field_tag :autosuggest_menu, nil, :id=>'autosuggest_menu_input',:placeholder => "#{t('autosuggest_menu.search_actions_and_events')}" %> diff --git a/app/views/student/_all_assign.erb b/app/views/student/_all_assign.erb index 4a02de1b6..68003089c 100755 --- a/app/views/student/_all_assign.erb +++ b/app/views/student/_all_assign.erb @@ -22,7 +22,7 @@
    <% @students.each do |s| %>
  1. - <% stud_assigned = StudentsSubject.new() %> + <% stud_assigned = StudentsSubject.new %> <% assigned = stud_assigned.student_assigned(s.id,@elective_subject.id) %>
    <%= s.full_name %>
    <% unless assigned.nil? %> diff --git a/app/views/student/admission3.erb b/app/views/student/admission3.erb index f714da5a6..08529938c 100755 --- a/app/views/student/admission3.erb +++ b/app/views/student/admission3.erb @@ -34,7 +34,7 @@