diff --git a/css/bts_timesheet.css b/css/bts_timesheet.css
index 9d5292f..f617782 100644
--- a/css/bts_timesheet.css
+++ b/css/bts_timesheet.css
@@ -661,14 +661,24 @@ div.blueTable.emptyrecord{
}
.divTable.highlight{
+ box-shadow: 1px 1px 10px green;
+}
+
+.divTable.invalidjob.highlight{
box-shadow: 1px 1px 10px #f50202;
-
}
+
.divTableRow {
display: table-row;
}
+.divTableRow.errmsg{
+ background-color:white;
+ font-weight:bolder;
+ color:red;
+}
+
.divTableHeading {
display: table-header-group;
}
@@ -760,7 +770,15 @@ div.btos select,
div.bstart input,
div.bfinish input{
width: 100%;
- height: 100%;
+ height: 98%;
+}
+
+div.divTable.validjob{
+ border: 0px solid white;
}
+
+div.divTable.invalidjob{
+ border-left: 2px solid red;
+ border-right: 2px solid red;
}
/* end of div table */
\ No newline at end of file
diff --git a/html/job.html b/html/job.html
index 1c0f840..b080ebb 100644
--- a/html/job.html
+++ b/html/job.html
@@ -24,7 +24,20 @@
-
+
+
e tos
+
+
es
+
ef
+
er
+
estaf
+
ecli
+
econfirm
+
erat
+
edel
+
eeave
+
+
\ No newline at end of file
diff --git a/html/staff.html b/html/staff.html
index 0fceb48..a866f1a 100644
--- a/html/staff.html
+++ b/html/staff.html
@@ -2,11 +2,12 @@
-
{{unconfirmedjob}}
-
${{wages}} ({{hour}}hr + {{OT}}hr)
-
petrol:{{petrol}} km
+
${{wages}}
+
({{hour}}+{{OT}}hr)
+
petrol:{{petrol}} km
{{unconfirmedjob}} div').html('');
+ }
+ set_err_msg_start(str)
+ {
+ this.el.find('div.bstart_err').html(str);
+ }
+ set_err_msg_finish(str)
+ {
+ this.el.find('div.bfinish_err').html(str);
+ }
+ set_err_msg_rate(str)
+ {
+ this.el.find('div.brate_err').html(str);
+ }
+ set_err_msg_save(str)
+ {
+ this.el.find('div.bsave_err').html(str);
+ }
+
+
+ mark_start_valid(){
+ this.el.find('div.bstart input').removeClass('invalid');
+ }
+ mark_start_invalid(){
+ this.el.find('div.bstart input').addClass('invalid');
+ }
+
+ mark_finish_valid(){
+ this.el.find('div.bfinish input').removeClass('invalid');
+ }
+ mark_finish_invalid(){
+ this.el.find('div.bfinish input').addClass('invalid');
+ }
+ mark_rate_valid(){
+ this.el.find('div.brate select').removeClass('invalid');
+ }
+ mark_rate_invalid(){
+ this.el.find('div.brate select').addClass('invalid');
}
mark_week_color(){
@@ -555,8 +659,58 @@
var me = new Date(this.data.start);
return (w2_begin <= me && me <= w2_end );
}
+ get_payment_summary(){
+ var result ={};
+ result.ot = this.get_is_high_pay();
+ result.hour = this.get_working_duration();
+ result.money = this.get_wages();
+ return result;
+ }
+ get_is_high_pay()
+ {
+ var rate_info = this.get_rate_info_by_id(this.get_rate());
+ return this.is_high_pay_hour(rate_info);
+ }
+ get_working_duration()
+ {
+ //finish - start
+ var f = new Date(this.get_finish());
+ var s = new Date(this.get_start());
+ var diff = f.getTime() - s.getTime();
+ var hours = Math.floor(diff / 1000 / 60 / 60);
+ diff -= hours * 1000 * 60 * 60;
+ var minutes = Math.floor(diff / 1000 / 60);
+ var minute_to_hour = minutes/60;
+ return (hours + minute_to_hour);
+ }
+ get_wages(){
+ var hour = this.get_working_duration();
+ var rate_info = this.get_rate_info_by_id(this.get_rate());
+ return hour * rate_info.RatePerUnit;
+ }
+ get_rate_info_by_id(id){
+ var rate_info = {};
+ var rates = bts().earnings_rate;
+ for(var i =0; i< rates.length; i++){
+ var r = rates[i];
+ if(r.EarningsRateID == id){
+ rate_info = $.extend(true,{}, r);//make a copy
+ break;
+ }
+ }
+ return rate_info;
+ }
+ is_high_pay_hour(rate_info){
+ var keywords =bts().high_pay_keywords;
+ var found = false;
+ keywords.forEach(function(e){
+ if (-1 != rate_info.Name.toLowerCase().indexOf(e.toLowerCase()) )
+ found = true;
+ });
+ return found;
+ }
}//end of class Job
//global GUI summary
@@ -809,19 +963,17 @@
$('div.sheettitle h1').click(function(){
reset_title_to_today();
- })
+ });
function reset_title_to_today(){
set_today();
init_weekdays();
set_week_number();
- load_timesheet();
}
function load_timesheet()
{
- show_loading_jobs();
clear_workspace();
var first = $('span[name="w1d1"]').data().date;
var last = $('span[name="w2d7"]').data().date;
@@ -880,7 +1032,8 @@
}
$('button[name="confirmschedule"]').click(function(){
- $('span.ticon.ticon-save').trigger('click');
+ //$('div.workspace span.ticon.ticon-save').trigger('click');
+
});
@@ -901,10 +1054,8 @@
clients.push(id.substring(1));
});
- console.log('staffs %o' , staffs);
- console.log('clients %o' , clients);
-
filter_workspace(staffs, clients);
+ calculate_total_working_hour();
}
function filter_workspace(staffs, clients){
@@ -932,7 +1083,29 @@
function calculate_total_working_hour()
{
+ //init pays for all staff;
+ var pays=[];
+ $('.stafflist > div.peopleitem').each(function(i,e){
+ var people = $(this).data().obj;
+ people.reset_summary();
+ });
+ $('div.workspace > .divTable').each(function(i,e){
+ var job = $(e).data().job; //class Job
+ var ps = job.get_payment_summary();
+ var staff = job.get_staff();
+ var people = find_staff(staff); //class People
+ if (people !=false)
+ people.add_payment_summary(ps);
+ });
+ }
+
+ function find_staff(login)
+ {
+ var d = $('#p'+login).data();
+ if (typeof d === 'undefined')
+ return false;
+ return $('#p'+login).data().obj;
}
function calculate_total_money()
@@ -940,43 +1113,37 @@
}
-
- //visually hint whether start is correct;
- $(document).on('change','div.bstart input', function(){
- var str = $(this).attr('value');
- if ( ! is_valid_date_str(str) )
- $(this).css('background-color', 'orange');
- else
- $(this).css('background-color', 'white');
- });
-
- //visually hint whether finish date is correct;
- $(document).on('change','div.bfinish input', function(){
- var job = $(this).closest('div.divTable').data().job;
- var str = $(this).attr('value');
- if ( ! is_valid_date_str(str) ){
- $(this).css('background-color', 'orange');
- return;
- }else
- $(this).css('background-color', 'white');
-
- //must be later than start
- if (! job.is_finish_resonable()){
- alert('finish date should be bigger than start date');
- $(this).css('background-color', 'orange');
- }else{
- $(this).css('background-color', 'white');
- }
-
- });
-
-
$(document).on('change', '.divTableRow select, .divTableRow input', function() {
var job = $(this).closest('.divTable').data().job;
+ job.validate();
job.mark_dirty();
});
- reset_title_to_today();
+ function init_ts(){
+ show_loading_jobs();
+ list_staff();
+ list_clients();
+ xero(false);
+ wifi(false);
+ init_user_search();
+ //ajax_earning_rate();
+ reset_title_to_today();
+ load_timesheet();
+ }
+
+// function ajax_earning_rate(){
+// $.post(bts().ajax_url, { // POST request
+// _ajax_nonce: bts().nonce, // nonce
+// action: "earnings_rate", // action
+// }, function(response, status, xhr){
+// bts().earnings_rate = response;
+// console.log("%o", bts().earnings_rate);
+// });
+// }
+
+ init_ts();
+
+
/*________________________________________________________________________*/
});
})(jQuery);
diff --git a/ts.php b/ts.php
index 6ec4da7..42f8084 100644
--- a/ts.php
+++ b/ts.php
@@ -136,6 +136,8 @@ class AcareOffice{
'userid'=> $this->acaresydney_userid,
'load_user_img'=> plugins_url('img/loading_user.gif', __FILE__),
'load_job_img'=> plugins_url('img/loading_job.gif', __FILE__),
+ 'earnings_rate'=> get_option('bts_payitem_earnings_rate'),
+ 'high_pay_keywords' => ['sat ', 'sun ', 'high ', 'public holiday'], //space is important
) );
}