Browse Source

disable job editing for those that passed payroll start date

master
patrick 6 years ago
parent
commit
8a60a29e20
3 changed files with 121 additions and 22 deletions
  1. +22
    -5
      css/bts_timesheet.css
  2. +93
    -16
      js/bts_timesheet.js
  3. +6
    -1
      ts.php

+ 22
- 5
css/bts_timesheet.css View File

background-color: #eeeeee; background-color: #eeeeee;
} }


div.workspace div.blueTable.disabled *{
background-color:lightgrey;
color: black;
}

div.workspace div.blueTable.disabled span.ticon-trash,
div.workspace div.blueTable.disabled span.ticon-copy,
div.workspace div.blueTable.disabled span.ticon-save
{
display:none;
}

.divTable.blueTable .divTableCell, .divTable.blueTable .divTableCell,
.divTable.blueTable .divTableHead, .divTable.blueTable .divTableHead,
{ {
margin: 3px 0px 3px 0px; margin: 3px 0px 3px 0px;
} }


.divTable.highlight {
.divTable:not(.disabled).highlight {
box-shadow: 1px 1px 10px green; box-shadow: 1px 1px 10px green;
} }


.divTable.disabled.highlight {
box-shadow: 1px 1px 10px yellow;
}


.divTable.invalidjob.highlight { .divTable.invalidjob.highlight {
box-shadow: 1px 1px 10px #f50202;
box-shadow: 1px 1px 10px red;
} }


.divTable.highlight.newcopy { .divTable.highlight.newcopy {
direction: rtl; direction: rtl;
} }


div.workspace .brating > span:hover:before,
div.workspace .brating > span:hover ~ span:before {
div.workspace .divTable:not(.disabled) .brating > span:hover:before,
div.workspace .divTable:not(.disabled) .brating > span:hover ~ span:before {
content: "\2605"; content: "\2605";
position: absolute; position: absolute;
} }
cursor: pointer; cursor: pointer;
} }


div.workspace div > span:hover {
div.workspace .divTable:not(.disabled) div > span:hover {
box-shadow: 0px 0px 10px black; box-shadow: 0px 0px 10px black;
} }



+ 93
- 16
js/bts_timesheet.js View File

add_new_empty_job(); add_new_empty_job();
}); });


function get_workspace_start_date(){
return new Date($('span[name="w1d1"]').data().date) ;
}
function get_payroll_start()
{
return new Date(bts().pay_calendar.start + " 00:00:00");
}
// function allow_add_new(){
// var w1_begin = get_workspace_start_date();
// var pay_begin = get_payroll_start();
// return w1_begin > pay_begin;
// }
function add_new_empty_job(){ function add_new_empty_job(){
var o = new Job({empty:true}); var o = new Job({empty:true});
$('div.workspace').append(o.el); $('div.workspace').append(o.el);
$(document).on('click', 'div.divTableCell.bdelete', function(){ $(document).on('click', 'div.divTableCell.bdelete', function(){
var job = $(this).closest('.divTable').data().job; var job = $(this).closest('.divTable').data().job;
var el = $(this).closest('div.divTable');
var el = $(this).closest('div.divTable');
if (job.data.disabled)
return;
if ( job.get_job_id() == '') if ( job.get_job_id() == '')
el.remove(); el.remove();
else{ else{
return; return;
var table = $(this).closest('div.divTable'); var table = $(this).closest('div.divTable');
var job = table.data().job; var job = table.data().job;
if (job.data.disabled){
alert("Job disabled, cannot copy");
return;
}
var newj = clone_data_create_new_job(job.get_record_from_ui()); var newj = clone_data_create_new_job(job.get_record_from_ui());
$('div.workspace').append(newj.el); $('div.workspace').append(newj.el);
newj.el.get(0).scrollIntoView();//make sure it's visible; newj.el.get(0).scrollIntoView();//make sure it's visible;
dtp_init(); dtp_init();
}); });

class Job{ //save data for the record, and display it as GUI class Job{ //save data for the record, and display it as GUI
constructor(data){ constructor(data){
var html = jQuery("#job_item").html(); var html = jQuery("#job_item").html();
init_start_rating(){ init_start_rating(){
var self = this; var self = this;
this.el.find("div.brating span").click(function(){ this.el.find("div.brating span").click(function(){
if (self.data.disabled)
return;
var r = $(this).attr('data-rating'); var r = $(this).attr('data-rating');
self.mark_dirty(); self.mark_dirty();
self.set_rating(r); self.set_rating(r);
}) })
this.el.find("div.brating").mouseenter(function(){ this.el.find("div.brating").mouseenter(function(){
if (self.data.disabled)
return;
//change to all hollow star //change to all hollow star
$(this).find('span').html('☆'); $(this).find('span').html('☆');
}); });
this.el.find("div.brating").mouseleave(function(){ this.el.find("div.brating").mouseleave(function(){
if (self.data.disabled)
return;
self.set_rating(self.data.rating); self.set_rating(self.data.rating);
}); });
load_data(data) load_data(data)
{ {
//save to html element
//check is disabled?
this.data = data; this.data = data;
this.is_disabled();
//save to html element
this.el.data({job:this, data:data}); this.el.data({job:this, data:data});


//draw GUI //draw GUI
this.set_rating(data.rating); this.set_rating(data.rating);
//draw GUI by other //draw GUI by other
this.mark_disabled();
this.mark_dirty_on_new_record(data); this.mark_dirty_on_new_record(data);
this.mark_week_color(); this.mark_week_color();
this.validate(); //also triggers mark errors this.validate(); //also triggers mark errors
} }
is_disabled()
{
var s = new Date(this.data.start);
var pay_roll_start = get_payroll_start();
this.data.disabled = s < pay_roll_start;
}
get_job_id(){ get_job_id(){
return this.el.find('input[name="id"]').attr('value'); return this.el.find('input[name="id"]').attr('value');
} }
} }
set_tos(val) set_tos(val)
{ {
if (this.data.disabled)
this.el.find('div.btos select').prop('disabled', 'disabled');
if (typeof(val) =="undefined") if (typeof(val) =="undefined")
return; return;
this.el.find('div.btos select option[value="'+val+'"]').prop('selected',true); this.el.find('div.btos select option[value="'+val+'"]').prop('selected',true);
} }
get_start(){ get_start(){
return this.el.find('div.bstart input').attr('value'); return this.el.find('div.bstart input').attr('value');
} }
set_start(val) set_start(val)
{ {
if (this.data.disabled)
this.el.find('div.bstart input').prop('disabled', 'disabled');
if (typeof(val) =="undefined") if (typeof(val) =="undefined")
return; return;
this.el.find('div.bstart input').attr('value', val); this.el.find('div.bstart input').attr('value', val);
} }
set_finish(val) set_finish(val)
{ {
if (this.data.disabled)
this.el.find('div.bfinish input').prop('disabled', 'disabled');
if (typeof(val) == "undefined") if (typeof(val) == "undefined")
return; return;
this.el.find('div.bfinish input').attr('value', val); this.el.find('div.bfinish input').attr('value', val);
} }
set_rate(val) set_rate(val)
{ {
if (this.data.disabled)
this.el.find('div.brate select').prop('disabled', 'disabled');
if (typeof(val) =="undefined") if (typeof(val) =="undefined")
return; return;
this.el.find('div.brate select option[value="'+val+'"]').prop('selected',true); this.el.find('div.brate select option[value="'+val+'"]').prop('selected',true);
} }
set_staff(val) set_staff(val)
{ {
if (this.data.disabled)
this.el.find('div.bstaff select').prop('disabled', 'disabled');
if (typeof(val) =="undefined") if (typeof(val) =="undefined")
return; return;
this.el.find('div.bstaff select option[value="'+val+'"]').prop('selected',true); this.el.find('div.bstaff select option[value="'+val+'"]').prop('selected',true);
} }
set_client(val) set_client(val)
{ {
if (this.data.disabled)
this.el.find('div.bclient select').prop('disabled', 'disabled');
if (typeof(val) =="undefined") if (typeof(val) =="undefined")
return; return;
this.el.find('div.bclient select option[value="'+val+'"]').prop('selected',true); this.el.find('div.bclient select option[value="'+val+'"]').prop('selected',true);
} }
set_ack(val) set_ack(val)
{ {
if (this.data.disabled)
this.el.find('div.bconfirmed input').prop('disabled', 'disabled');
if (typeof(val) =="undefined") if (typeof(val) =="undefined")
return; return;
return this.el.find('div.bconfirmed input').prop('checked', val!=0); return this.el.find('div.bconfirmed input').prop('checked', val!=0);
},1000); },1000);
} }
mark_disabled()
{
if (this.data.disabled)
this.el.addClass('disabled');
else
this.el.removeClass('disabled');
}
//newly created empty record //newly created empty record
mark_new() mark_new()
{ {
{ {
var now = new Date(curr); var now = new Date(curr);
var d1 = new Date(now.setDate(i)); var d1 = new Date(now.setDate(i));
d1.setHours(0,0,0,0); //0 hour, 0 minute, 0 second, 0 milliseconds,
now = new Date(curr); now = new Date(curr);
var d2 = new Date(now.setDate(i+7)); var d2 = new Date(now.setDate(i+7));
d2.setHours(0,0,0,0);
set_day_number(1,pos, d1); //week 1 set_day_number(1,pos, d1); //week 1
set_day_number(2,pos, d2); //week 2 set_day_number(2,pos, d2); //week 2
pos +=1; pos +=1;
var el = $(e).closest('div.divTable'); var el = $(e).closest('div.divTable');
if (el.is(":visible")){ if (el.is(":visible")){
var j = el.data().job; var j = el.data().job;
var newj = clone_data_create_new_job(j.get_record_from_ui(),7);//add 7 days
job_els.push(newj.el);
if (! j.data.disabled ){
var newj = clone_data_create_new_job(j.get_record_from_ui(),7);//add 7 days
job_els.push(newj.el);
}
} }
} }
}); });
}); });
show_jobs(job_els); show_jobs(job_els);
debounced_calculate(); debounced_calculate();
alert("Copied .. (" + job_els.length + ") jobs");
}); });


$('div.weekly div.weekname.next > input').click(function(e){ $('div.weekly div.weekname.next > input').click(function(e){


$('div.week1 > div').click(function(e){ $('div.week1 > div').click(function(e){
e.stopPropagation(); e.stopPropagation();
if ($('div.bstart input.blink_me').length == 0){ if ($('div.bstart input.blink_me').length == 0){
alert("nothing to copy"); alert("nothing to copy");
return; return;
} }
if (!confirm ('copy to next week'))
if (!confirm ('copy to next week?'))
return; return;
var jobs_el = []; var jobs_el = [];
$('div.bstart input.blink_me').each(function(i,e){ $('div.bstart input.blink_me').each(function(i,e){
}); });
show_jobs(jobs_el); show_jobs(jobs_el);
unblink_all_date(); unblink_all_date();
alert('Copied (' +jobs_el.length + ") jobs");
}); });
$('div.week1,div.week2').click(function(e){ $('div.week1,div.week2').click(function(e){
var tb = $(el).closest('div.divTable'); var tb = $(el).closest('div.divTable');
if (tb.is(':visible')){ if (tb.is(':visible')){
var j = $(tb).data().job; var j = $(tb).data().job;
if (j.data.disabled)
return false;
var newj = clone_data_create_new_job(j.get_record_from_ui() , 7); // +7 days var newj = clone_data_create_new_job(j.get_record_from_ui() , 7); // +7 days
return newj; return newj;
} }
var strDate = format_date(date); //yyyy-mm-dd var strDate = format_date(date); //yyyy-mm-dd
var els=[]; var els=[];
unblink_all_date(); unblink_all_date();
$('div.bstart input').each(function(i,e){
if ( $(e).is(":visible") ){
var value = $(e).attr('value');
if( -1 != value.indexOf(strDate) ) //found
{
els.push(e);
$(e).addClass('blink_me');
}
$('div.bstart input:visible').each(function(i,e){
var value = $(e).attr('value');
if( -1 != value.indexOf(strDate) ) //found
{
els.push(e);
$(e).addClass('blink_me');
} }
}); });
} }
people.reset_summary(); people.reset_summary();
}); });
$('div.workspace > .divTable').each(function(i,e){
if (! $(e).is(':visible'))
return;
$('div.workspace > .divTable:visible').each(function(i,e){
var job = $(e).data().job; //class Job var job = $(e).data().job; //class Job
if (typeof job === 'undefined') if (typeof job === 'undefined')

+ 6
- 1
ts.php View File

'load_job_img'=> plugins_url('img/loading_job.gif', __FILE__), 'load_job_img'=> plugins_url('img/loading_job.gif', __FILE__),
'driving' => "259ee8e8-a1e5-42e4-9c14-517543ecdc4b", 'driving' => "259ee8e8-a1e5-42e4-9c14-517543ecdc4b",
'high_pay_keywords' => ['sat ', 'sun ', 'high ', 'public holiday'], //space is important 'high_pay_keywords' => ['sat ', 'sun ', 'high ', 'public holiday'], //space is important
'pay_calendar'=> get_option('bts_pay_roll_calendar'),
) ); ) );
} }
$response['sql'] = $query; $response['sql'] = $query;
$jobs = $this->db->get_results($query); $jobs = $this->db->get_results($query);
$calendar = get_option('bts_pay_roll_calendar');
if (! empty($jobs)){ if (! empty($jobs)){
$response['status'] = 'success'; $response['status'] = 'success';
foreach( $jobs as $s){ foreach( $jobs as $s){
$response['jobs'][] = array(
$item = array(
'id' => $s->id, 'id' => $s->id,
'tos' => $s->tos, 'tos' => $s->tos,
'start'=> $s->start, 'start'=> $s->start,
'ack' => $s->ack, 'ack' => $s->ack,
'rating' =>$s->rating, 'rating' =>$s->rating,
); );
$response['jobs'][] = $item;
} }
} }
wp_send_json($response); wp_send_json($response);

Loading…
Cancel
Save