Skip to content

Commit

Permalink
Merge pull request #64 from dhanasingh/dev
Browse files Browse the repository at this point in the history
v2.3
  • Loading branch information
karthickmadhiazhagan authored Aug 19, 2016
2 parents 372d36d + 6058304 commit 7befa9f
Show file tree
Hide file tree
Showing 48 changed files with 1,438 additions and 345 deletions.
18 changes: 10 additions & 8 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,17 @@ If an apache passenger module is used then make sure the following settings are
b) RailsAppSpawnerIdleTime 0
c) PassengerPreStart http://rails-app-url/

Release Notes for 2.2.1
Release Notes for 2.3
Features:
- Made compatible with Redmine 3.3.0.
- Time & Expense report in Report module.
- Show the first clock in and last clock out of the day.
- Show the List page for view permission holder also.
- File Based Integration with Attendance / Time Clock Device.
- Manually import Attendance data.
- clock in/out list and edit pages are avialable from Attendance module.
- Manually re-run the period end process for attendance module.
Bugs:
- Fixed the clock in/out column shift error.
- Fixed the leave total hours bug in attendance list.
- Added permission logic for viewing expenses report.
- Left align the report header.
- Fixed the total hours for month column total in Attendance report.
- Fixed Date range calendar popup problem in Time & Attendance module.
- Fixed the sqlite query problem on the T&E list page.
Customization:
For any Customization/Support, please contact us, our consulting team will be happy to help you

Expand Down Expand Up @@ -116,3 +116,5 @@ Resources:
https://www.youtube.com/watch?v=BptCOCWgivY
https://www.youtube.com/watch?v=afdVgCj-TUc
https://www.youtube.com/watch?v=cTZ2FCqgdwQ
https://www.youtube.com/watch?v=RFlYw-ZpiYI
https://www.youtube.com/watch?v=RecxTps_jws
212 changes: 207 additions & 5 deletions app/controllers/wkattendance_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ class WkattendanceController < WkbaseController

include WktimeHelper
include WkattendanceHelper
include WkimportattendanceHelper

before_filter :require_login
before_filter :check_perm_and_redirect, :only => [:edit, :update]
require 'csv'

def index
@status = params[:status] || 1
Expand Down Expand Up @@ -35,7 +37,154 @@ def index
if !params[:name].blank?
sqlStr = sqlStr + " and (LOWER(u.firstname) like LOWER('%#{params[:name]}%') or LOWER(u.lastname) like LOWER('%#{params[:name]}%'))"
end
findBySql(sqlStr)
findBySql(sqlStr, WkUserLeave)
end

def clockindex
@clk_entries = nil
@groups = Group.sorted.all
set_filter_session
retrieve_date_range
@members = Array.new
userIds = Array.new
userList = getGroupMembers
userList.each do |users|
@members << [users.name,users.id.to_s()]
userIds << users.id
end
ids = nil
user_id = session[:wkattendance][:user_id]
group_id = session[:wkattendance][:group_id]
status = session[:wkattendance][:status]

if user_id.blank?
ids = User.current.id
elsif user_id.to_i != 0 && group_id.to_i == 0
ids = user_id.to_i
elsif group_id.to_i != 0
ids =user_id.to_i == 0 ? (userIds.blank? ? 0 : userIds.join(',')) : user_id.to_i
else
ids = userIds.join(',')
end
if @from.blank? && @to.blank?
getAllTimeRange(ids, false)
end
noOfDays = 't4.i*1*10000 + t3.i*1*1000 + t2.i*1*100 + t1.i*1*10 + t0.i*1'
sqlQuery = "select vw.id as user_id, vw.firstname, vw.lastname, vw.created_on, vw.selected_date as entry_date, evw.start_time, evw.end_time, evw.hours from
(select u.id, u.firstname, u.lastname, u.created_on, v.selected_date from" +
"(select " + getAddDateStr(@from, noOfDays) + " selected_date from " +
"(select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t0,
(select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t1,
(select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t2,
(select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t3,
(select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9)t4)v,
(select u.id, u.firstname, u.lastname, u.created_on from users u where u.type = 'User' ) u
WHERE v.selected_date between '#{@from}' and '#{@to}' order by u.id, v.selected_date) vw left join
(select min(start_time) as start_time, max(end_time) as end_time, " + getConvertDateStr('start_time') + "
entry_date,sum(hours) as hours, user_id from wk_attendances WHERE " + getConvertDateStr('start_time') +" between '#{@from}' and '#{@to}'
group by user_id, " + getConvertDateStr('start_time') + ") evw on (vw.selected_date = evw.entry_date and vw.id = evw.user_id) where vw.id in(#{ids}) "
findBySql(sqlQuery, WkAttendance)
end


def clockedit
sqlQuery = "select a.id,a.user_id, a.start_time, a.end_time, a.hours, u.firstname, u.lastname FROM users u
left join wk_attendances a on u.id = a.user_id and #{getConvertDateStr('a.start_time')} = '#{params[:date]}' where u.id = '#{params[:user_id]}' ORDER BY a.start_time"
@wkattnEntries = WkAttendance.find_by_sql(sqlQuery)
end

def getMembersbyGroup
group_by_users=""
userList=[]
userList = getGroupMembers
userList.each do |users|
group_by_users << users.id.to_s() + ',' + users.name + "\n"
end
respond_to do |format|
format.text { render :text => group_by_users }
end
end

def getGroupMembers
userList = nil
group_id = nil
if (!params[:group_id].blank?)
group_id = params[:group_id]
else
group_id = session[:wkattendance][:group_id]
end

if !group_id.blank? && group_id.to_i > 0
userList = User.in_group(group_id)
else
userList = User.order("#{User.table_name}.firstname ASC,#{User.table_name}.lastname ASC")
end
userList
end

def set_filter_session
if params[:searchlist].blank? && session[:wkattendance].nil?
session[:wkattendance] = {:period_type => params[:period_type], :period => params[:period],:group_id => params[:group_id], :user_id => params[:user_id], :from => @from, :to => @to}
elsif params[:searchlist] =='wkattendance'
session[:wkattendance][:period_type] = params[:period_type]
session[:wkattendance][:period] = params[:period]
session[:wkattendance][:group_id] = params[:group_id]
session[:wkattendance][:user_id] = params[:user_id]
session[:wkattendance][:from] = params[:from]
session[:wkattendance][:to] = params[:to]
end
end

# Retrieves the date range based on predefined ranges or specific from/to param dates
def retrieve_date_range
@free_period = false
@from, @to = nil, nil
period_type = session[:wkattendance][:period_type]
period = session[:wkattendance][:period]
fromdate = session[:wkattendance][:from]
todate = session[:wkattendance][:to]
if (period_type == '1' || (period_type.nil? && !period.nil?))
case period.to_s
when 'today'
@from = @to = Date.today
when 'yesterday'
@from = @to = Date.today - 1
when 'current_week'
@from = getStartDay(Date.today - (Date.today.cwday - 1)%7)
@to = Date.today #@from + 6
when 'last_week'
@from =getStartDay(Date.today - 7 - (Date.today.cwday - 1)%7)
@to = @from + 6
when '7_days'
@from = Date.today - 7
@to = Date.today
when 'current_month'
@from = Date.civil(Date.today.year, Date.today.month, 1)
@to = Date.today #(@from >> 1) - 1
when 'last_month'
@from = Date.civil(Date.today.year, Date.today.month, 1) << 1
@to = (@from >> 1) - 1
when '30_days'
@from = Date.today - 30
@to = Date.today
when 'current_year'
@from = Date.civil(Date.today.year, 1, 1)
@to = Date.today #Date.civil(Date.today.year, 12, 31)
end
#elsif params[:period_type] == '2' || (params[:period_type].nil? && (!params[:from].nil? || !params[:to].nil?))
elsif period_type == '2' || (period_type.nil? && (!fromdate.nil? || !todate.nil?))
begin; @from = fromdate.to_s.to_date unless fromdate.blank?; rescue; end
begin; @to = todate.to_s.to_date unless todate.blank?; rescue; end
@free_period = true
else
# default
# 'current_month'
@from = Date.civil(Date.today.year, Date.today.month, 1)
@to = Date.today #(@from >> 1) - 1
end

@from, @to = @to, @from if @from && @to && @from > @to

end

def edit
Expand All @@ -44,6 +193,16 @@ def edit
render :action => 'edit'
end

def runPeriodEndProcess
populateWkUserLeaves
respond_to do |format|
format.html {
flash[:notice] = l(:notice_successful_update)
redirect_back_or_default :action => 'index', :tab => params[:tab]
}
end
end

def update
errorMsg =nil
wkuserleave = nil
Expand Down Expand Up @@ -190,12 +349,16 @@ def setLimitAndOffset
end
end

def findBySql(query)
result = WkUserLeave.find_by_sql("select count(*) as id from (" + query + ") as v2")
def findBySql(query, model)
result = model.find_by_sql("select count(*) as id from (" + query + ") as v2")
@entry_count = result.blank? ? 0 : result[0].id
setLimitAndOffset()
rangeStr = formPaginationCondition()
@leave_entries = WkUserLeave.find_by_sql(query + " order by u.firstname " + rangeStr )
if model == WkUserLeave
@leave_entries = model.find_by_sql(query + " order by u.firstname " + rangeStr )
else
@clk_entries = model.find_by_sql(query + " order by vw.selected_date desc, vw.firstname " + rangeStr )
end
end

def formPaginationCondition
Expand All @@ -206,5 +369,44 @@ def formPaginationCondition
rangeStr = " LIMIT " + @limit.to_s + " OFFSET " + @offset.to_s
end
rangeStr
end
end

def saveClockInOut
errorMsg =nil
sucessMsg = nil
endtime = nil
for i in 0..params[:attnDayEntriesCnt].to_i-1
starttime = params[:startdate] + " " + params["attnstarttime#{i}"] + ":00"
entry_start_time = DateTime.strptime(starttime, "%Y-%m-%d %T") rescue starttime
endtime = params[:startdate] + " " + params["attnendtime#{i}"] + ":00" if !params["attnendtime#{i}"].blank?
entry_end_time = DateTime.strptime(endtime, "%Y-%m-%d %T") rescue endtime
if params["attnstarttime#{i}"] == '0:00' && params["attnendtime#{i}"] == '0:00'
wkattendance = WkAttendance.find(params["attnEntriesId#{i}"].to_i) if !params["attnEntriesId#{i}"].blank?
wkattendance.destroy()
sucessMsg = l(:notice_successful_delete)
else
if !params["attnEntriesId#{i}"].blank?
wkattendance = WkAttendance.find(params["attnEntriesId#{i}"].to_i)
wkattendance.start_time = getFormatedTimeEntry(entry_start_time)
wkattendance.end_time = getFormatedTimeEntry(entry_end_time) #if !entry_end_time.blank?
wkattendance.hours = computeWorkedHours(wkattendance.start_time, wkattendance.end_time, true) if !wkattendance.end_time.blank?
wkattendance.save()
sucessMsg = l(:notice_successful_update)
else
addNewAttendance(getFormatedTimeEntry(entry_start_time),getFormatedTimeEntry(entry_end_time), params[:user_id].to_i)
sucessMsg = l(:notice_successful_update)
end
end
end

if errorMsg.nil?
redirect_to :controller => 'wkattendance',:action => 'clockindex' , :tab => 'clock'
flash[:notice] = sucessMsg #l(:notice_successful_update)
else
flash[:error] = errorMsg
redirect_to :action => 'edit'
end
end


end
45 changes: 7 additions & 38 deletions app/controllers/wkbase_controller.rb
Original file line number Diff line number Diff line change
@@ -1,49 +1,18 @@
class WkbaseController < ApplicationController
unloadable
unloadable
include WkattendanceHelper



def updateClockInOut
if !findLastAttnEntry.blank?
@lastAttnEntry = findLastAttnEntry[0]
lastAttnEntries = findLastAttnEntry(true)
if !lastAttnEntries.blank?
@lastAttnEntry = lastAttnEntries[0]
end
currentDate = (DateTime.parse params[:startdate])
if params[:str] != "start" #&& isAccountUser
entrydate = @lastAttnEntry.start_time
start_local = entrydate.localtime
if ((Date.parse params[:startdate]) != @lastAttnEntry.start_time.to_date)
endtime = start_local.change({ hour: "23:59".to_time.strftime("%H"), min: "23:59".to_time.strftime("%M"), sec: '59' })
addNewAttendance
else
endtime = start_local.change({ hour: currentDate.to_time.strftime("%H"), min:currentDate.to_time.strftime("%M"), sec: currentDate.to_time.strftime("%S") })
end
@lastAttnEntry.end_time = endtime
@lastAttnEntry.hours = computeWorkedHours(@lastAttnEntry.start_time,@lastAttnEntry.end_time, true)
@lastAttnEntry.save()
else
addNewAttendance
end
entryTime = Time.parse("#{currentDate.to_date.to_s} #{currentDate.utc.to_time.to_s} ").localtime
@lastAttnEntry = saveAttendance(@lastAttnEntry, entryTime, nil, User.current.id, false)
ret = 'done'
respond_to do |format|
format.text { render :text => ret }
end
end

def addNewAttendance
wkattendance = WkAttendance.new
currentDate = DateTime.parse params[:startdate]
entrydate = Date.parse params[:startdate]
wkattendance.user_id = params[:user_id].to_i
if params[:str] != "start"
wkattendance.start_time = Time.parse("#{entrydate.to_s} 00:00:00 ").localtime.to_s
wkattendance.end_time = currentDate
endtime = currentDate
wkattendance.hours = computeWorkedHours(wkattendance.start_time,wkattendance.end_time, true)
else
wkattendance.start_time = currentDate
endtime = nil
end
wkattendance.user_id = User.current.id
wkattendance.save()
end
end
4 changes: 2 additions & 2 deletions app/controllers/wkexpense_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def getQuery(teQuery, ids, from, to, status)
spField = getSpecificField()
dtRangeForUsrSqlStr = "(" + getAllWeekSql(from, to) + ") tmp1"
teSqlStr = "(" + teQuery + ") tmp2"
query = "select tmp3.user_id, tmp3.spent_on, tmp3.#{spField}, tmp3.status, tmp3.status_updater, tmp3.created_on, tmp3.currency from (select tmp1.id as user_id, tmp1.created_on, tmp1.selected_date as spent_on, " +
query = "select tmp3.user_id as user_id , tmp3.spent_on as spent_on, tmp3.#{spField} as #{spField}, tmp3.status as status, tmp3.status_updater as status_updater, tmp3.created_on as created_on, tmp3.currency as currency from (select tmp1.id as user_id, tmp1.created_on, tmp1.selected_date as spent_on, " +
"case when tmp2.#{spField} is null then 0 else tmp2.#{spField} end as #{spField}, " +
"case when tmp2.status is null then 'e' else tmp2.status end as status, tmp2.currency, tmp2.status_updater from "
query = query + dtRangeForUsrSqlStr + " left join " + teSqlStr
Expand All @@ -206,7 +206,7 @@ def findBySql(query)
end

def getTEAllTimeRange(ids)
teQuery = "select v.startday from (select #{getDateSqlString('t.spent_on')} as startday " +
teQuery = "select v.startday as startday from (select #{getDateSqlString('t.spent_on')} as startday " +
"from wk_expense_entries t where user_id in (#{ids})) v group by v.startday order by v.startday"
teResult = WkExpenseEntry.find_by_sql(teQuery)
end
Expand Down
29 changes: 29 additions & 0 deletions app/controllers/wkimportattendance_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class WkimportattendanceController < WkattendanceController
unloadable

include WkimportattendanceHelper

before_filter :require_login
require 'csv'

def new
end

def show
file = params[:file]
unless file.blank?
filePath = file.path
begin
isSuccess = importAttendance(filePath, false)
#redirect_to :action => 'show'
rescue Exception => e
@errorMsg = "Import failed: #{e.message}"
flash[:error] = @errorMsg
redirect_to :action => 'new'
end
else
redirect_to :action => 'new'
end
end

end
Loading

0 comments on commit 7befa9f

Please sign in to comment.