Skip to content

Commit

Permalink
Several fixes related to the calculation of work hours in timesheet(w…
Browse files Browse the repository at this point in the history
…ktime)
  • Loading branch information
aleroot committed Jul 19, 2018
1 parent 300dc43 commit 43ad85a
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 29 deletions.
12 changes: 7 additions & 5 deletions app/controllers/wktime_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1176,10 +1176,10 @@ def gatherEntries
unless entryHash.nil?
entryHash.each_with_index do |entry, i|
if !entry['project_id'].blank?
hours = params['hours' + (i+1).to_s()]
ids = params['ids' + (i+1).to_s()]
comments = params['comments' + (i+1).to_s()]
disabled = params['disabled' + (i+1).to_s()]
hours = params['hours' + (i+1).to_s()] || params['hours-' + (i+1).to_s()]
ids = params['ids' + (i+1).to_s()] || params['ids-' + (i+1).to_s()]
comments = params['comments' + (i+1).to_s()] || params['comments-' + (i+1).to_s()]
disabled = params['disabled' + (i+1).to_s()] || params['disabled-' + (i+1).to_s()]
@wkvalidEntry=true
if use_detail_popup
custom_values.clear
Expand All @@ -1189,6 +1189,7 @@ def gatherEntries
end

j = 0
unless ids.nil?
ids.each_with_index do |id, k|
if disabled[k] == "false"
if(!id.blank? || !hours[j].blank?)
Expand Down Expand Up @@ -1235,6 +1236,7 @@ def gatherEntries
@teEntrydisabled=true
end
end
end
end
end
end
Expand Down Expand Up @@ -2105,4 +2107,4 @@ def setUserIdsInSession(ids)
def getUserIdsFromSession
session[:wktimes][:all_user_ids]
end
end
end
2 changes: 1 addition & 1 deletion app/views/wktime/_edit_hours.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,4 @@
</tr>
<% @trOpen = false %>
<% end %>
<% end %>
<% end %>
6 changes: 3 additions & 3 deletions app/views/wktime/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
Setting.plugin_redmine_wktime['wktime_work_time_header'].to_i == 1 %>
showWorkHeader = true;
footerRows = 2;
headerRows = 4;
headerRows = 1;
<% if controller.enterCommentInRow %>
hStartIndex = hStartIndex + 1 ;
<% end %>
Expand Down Expand Up @@ -142,7 +142,7 @@
</td></tr>
<% end %>
<!-- script type="text/javascript"> wkcf_ids = '<%=wkcf_ids%>';</script -->
<script type="text/javascript"> cf_ids = '<%=wkcf_ids%>';</script>
<% end %>
</table>
</td>
Expand All @@ -157,4 +157,4 @@
<%= render :partial => 'edit_footer' %>
<% end %>
<% end %>
49 changes: 29 additions & 20 deletions assets/javascripts/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ function projectChanged(projDropdown, row){
if((issuId==null)||(issuId != null && !issuId.checked))
{
var id;
if(row != 0){
if(row > 0){
id = projDropdown.options[projDropdown.selectedIndex].value;
}
else{
Expand Down Expand Up @@ -665,7 +665,8 @@ function addRow(){
var issueTemplate = document.getElementById("issueTemplate");
var rowCount = issueTable.rows.length;
//there is a header row and a total row present, so the empty count is 2
var row = issueTable.insertRow(rowCount - footerRows);
var rowIndex = rowCount - footerRows + 1;
var row = issueTable.insertRow(rowIndex);

var cellCount = issueTemplate.rows[0].cells.length;
var i, cell;
Expand All @@ -675,7 +676,7 @@ function addRow(){
cell.className = issueTemplate.rows[0].cells[i].className;
cell.align = issueTemplate.rows[0].cells[i].align;
}
renameElemProperties(row, 0, rowCount- (headerRows + footerRows - 1));
renameElemProperties(row, 0, rowIndex);
saveButton.disabled = false;
if(submitButton!=undefined)
{
Expand Down Expand Up @@ -851,7 +852,7 @@ function renameHref(child, str, newStr){

function renameOnChange(child, index, newIndex){

var row = newIndex;
var row = Math.abs(newIndex);
var onchng = child.onchange;
var func = null;
var enterIsueIdChk = document.getElementById("enter_issue_id");
Expand Down Expand Up @@ -917,7 +918,7 @@ function calculateTotal(day){
var hours, i, j, k, val, children;

//since it has a header,start,end,totalhr and total row use < rowCount-2 and i=4
for(i=headerRows; i < rowCount-footerRows; i++){
for(i=headerRows; i < rowCount-footerRows+headerRows; i++){
//There is a bug in IE7, the getElementsByName doesn't get the new elements
//hours = document.getElementsByName("hours" + i + "[]");
hours = myGetElementsByName(issueTable.rows[i], "input","hours" + (i - (headerRows - 1)) + "[]");
Expand Down Expand Up @@ -1069,9 +1070,11 @@ function myTrim(val){

function updateDayTotal(day, dayTotal){
var day_total = document.getElementById('day_total_'+day);
var currDayTotal = Number(day_total.innerHTML);
day_total.innerHTML = dayTotal.toFixed(2);
updateTotal(dayTotal - currDayTotal);
if(day_total) {
var currDayTotal = Number(day_total.innerHTML);
day_total.innerHTML = dayTotal.toFixed(2);
updateTotal(dayTotal - currDayTotal);
}
}

function updateTotal(increment){
Expand All @@ -1094,13 +1097,15 @@ function updateRemainingHr(day, element)
totTime = getTotalTime(day, element);

var day_total = document.getElementById('day_total_'+day);
dayTt = Number(day_total.innerHTML);
rmTimeCell = rmTimeRow.cells[hStartIndex + day];
if(totTime > 0)
{
remainingTm = totTime - dayTt;
}
rmTimeCell.innerHTML = remainingTm.toFixed(2);
if(day_total) {
dayTt = Number(day_total.innerHTML);
rmTimeCell = rmTimeRow.cells[hStartIndex + day];
if(totTime > 0)
{
remainingTm = totTime - dayTt;
rmTimeCell.innerHTML = remainingTm.toFixed(2);
}
}
}

function getTotalTime(day, element)
Expand Down Expand Up @@ -1240,8 +1245,10 @@ function updateTotalHr(day, element)
}
else{
var totTimeRow = issueTable.rows[3];
totHrCell = totTimeRow.cells[hStartIndex + day];
totHrCell.innerHTML = totTime + " <a href='javascript:showclkDialog("+day+");'><img id='imgid' src='../plugin_assets/redmine_wktime/images/clockdetail.png' border=0 title=''/></a>";
if(totTimeRow) {
//totHrCell = totTimeRow.cells[hStartIndex + day];
//totHrCell.innerHTML = totTime + " <a href='javascript:showclkDialog("+day+");'><img id='imgid' src='../plugin_assets/redmine_wktime/images/clockdetail.png' border=0 title=''/></a>";
}
}

}
Expand Down Expand Up @@ -1508,8 +1515,10 @@ function calculatebreakTimeNew(totTime, day, element){
var startval, endval, breakStart, breakEnd, startTime, endTime, workedHours;
var breakTime = new Array();
var breakValue = new Array();
startval = document.getElementById(element ? element[0] : 'start_'+day).value;
endval = document.getElementById(element ? element[1] : 'end_'+day).value;
startval = document.getElementById(element ? element[0] : 'start_'+day);
if(startval) { startval = startval.value; }
endval = document.getElementById(element ? element[1] : 'end_'+day);
if(endval) { endval = endval.value; }
workedHours = convertTimeToSec(totTime);

if(startval && endval)
Expand Down Expand Up @@ -1565,4 +1574,4 @@ function convertSecToTime(seconds)
var m = Math.floor(d % 3600 / 60);
var timeVal = ((h > 0 ? h + ":" + (m < 10 ? "0" : "") : "") + (h > 0 ? m : ("0:" + m)) );
return timeVal;
}
}

0 comments on commit 43ad85a

Please sign in to comment.