|
|
|
@@ -46,7 +46,7 @@ |
|
|
|
//save it |
|
|
|
$(this.selector).data({obj:this, data:data}); |
|
|
|
//draw rating star |
|
|
|
this.set_ratings(this.data.rating); |
|
|
|
//this.set_ratings(this.data.rating); |
|
|
|
this.set_unconfirmed_job(this.data.unconfirmedjob); |
|
|
|
} |
|
|
|
|
|
|
|
@@ -61,6 +61,12 @@ |
|
|
|
this.data.rating = num; |
|
|
|
} |
|
|
|
|
|
|
|
set_km(km) |
|
|
|
{ |
|
|
|
var str = "petrol:" + km.toFixed(2) + " km"; |
|
|
|
$(this.selector + ' div[name="petrol"]').html(str); |
|
|
|
} |
|
|
|
|
|
|
|
set_unconfirmed_job(num){ |
|
|
|
if( num == 0 ) |
|
|
|
$(this.selector + " span[name='badge']").hide(); |
|
|
|
@@ -156,7 +162,6 @@ |
|
|
|
bts().staff_people[u.login] = staff_obj; |
|
|
|
}); |
|
|
|
hide_loading_staff(); |
|
|
|
calculate_total_hour_and_money(); |
|
|
|
}else{ |
|
|
|
alert('error getting staff list'); |
|
|
|
} |
|
|
|
@@ -1868,24 +1873,14 @@ |
|
|
|
total: 0, |
|
|
|
hours: 0, |
|
|
|
}; |
|
|
|
|
|
|
|
$('.stafflist > div.peopleitem').each(function(i,e){ |
|
|
|
var people = $(this).data().obj; |
|
|
|
people.reset_summary(); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
$('div.workspace > .divTable.jobTable:visible').each(function(i,e){ |
|
|
|
|
|
|
|
var id = $(e).attr('data-id'); |
|
|
|
var job = bts().job_map[id]; |
|
|
|
|
|
|
|
if (id == ''){ |
|
|
|
//is this a new Job without id? |
|
|
|
var newjob_id = $(e).attr('data-newjob_id'); |
|
|
|
if ( typeof newjob_id != "undefined"){ |
|
|
|
id = newjob_id; |
|
|
|
job = bts().job_map_new[newjob_id]; |
|
|
|
} |
|
|
|
} |
|
|
|
job = get_job_by_jobTable(e); |
|
|
|
|
|
|
|
if (typeof job === 'undefined' || !job.is_job_valid() ) |
|
|
|
return; |
|
|
|
@@ -1901,9 +1896,78 @@ |
|
|
|
}); |
|
|
|
set_wages(pays.total.toFixed(2)); |
|
|
|
set_working_hours(pays.hours.toFixed(2)); |
|
|
|
calculate_driving(); |
|
|
|
} |
|
|
|
|
|
|
|
function get_job_by_jobTable(div) |
|
|
|
{ |
|
|
|
var e = div; |
|
|
|
var id = $(e).attr('data-id'); |
|
|
|
var job = bts().job_map[id]; |
|
|
|
|
|
|
|
if (id == ''){ |
|
|
|
//is this a new Job without id? |
|
|
|
var newjob_id = $(e).attr('data-newjob_id'); |
|
|
|
if ( typeof newjob_id != "undefined"){ |
|
|
|
id = newjob_id; |
|
|
|
job = bts().job_map_new[newjob_id]; |
|
|
|
} |
|
|
|
} |
|
|
|
return job; |
|
|
|
} |
|
|
|
|
|
|
|
function calculate_driving(){ |
|
|
|
var id = bts().driving; |
|
|
|
var kms={}; |
|
|
|
$('div.jobTable[data-staff="' + id + '"]:visible').each(function(){ |
|
|
|
var el = this; |
|
|
|
var matches = find_driving_partner_job(el); |
|
|
|
console.assert(matches.length == 1); //only one match |
|
|
|
if (matches.length != 1) |
|
|
|
return; |
|
|
|
|
|
|
|
var staff = $('#' + matches[0]).data().staff; |
|
|
|
if (typeof kms[staff] =='undefined'){ |
|
|
|
kms[staff] = 0; |
|
|
|
} |
|
|
|
kms[staff] += convert_driving_to_km(el); |
|
|
|
//console.log($(this).attr('id'), matches, kms); |
|
|
|
bts().staff_people[staff].set_km(kms[staff]); |
|
|
|
console.log(bts().staff_map[staff]); |
|
|
|
ensure_visible(bts().staff_people[staff].selector); |
|
|
|
}); |
|
|
|
//console.log(kms); |
|
|
|
} |
|
|
|
|
|
|
|
function find_driving_partner_job(selector){ |
|
|
|
var job = $(selector).data(); |
|
|
|
var start = new Date(job.start); |
|
|
|
var client = job.client; |
|
|
|
var matches = []; |
|
|
|
$('div.workspace > .divTable.jobTable:visible').each(function(i,e){ |
|
|
|
var match = $(this).data(); |
|
|
|
staff = match.staff; |
|
|
|
s = new Date(match.start); |
|
|
|
c = match.client; |
|
|
|
if ((start - s == 0) && (client == c) && staff != bts().driving){ |
|
|
|
matches.push($(this).attr('id')); |
|
|
|
} |
|
|
|
}); |
|
|
|
return matches; |
|
|
|
} |
|
|
|
|
|
|
|
function convert_driving_to_km(selector){ |
|
|
|
var data = $(selector).data(); |
|
|
|
var tos = data.tos; |
|
|
|
var start = new Date(data.start); |
|
|
|
var finish = new Date(data.finish); |
|
|
|
var hours = Math.abs(finish - start) / 36e5; //in hours |
|
|
|
|
|
|
|
var rate = parseFloat(bts().tos[tos].price); |
|
|
|
var pay = hours * rate; |
|
|
|
var km = pay / 1.2; //$1.2 per km |
|
|
|
return km; |
|
|
|
} |
|
|
|
|
|
|
|
function find_staff(login) |
|
|
|
{ |