do_timesheet_payroll(); } if ($page == "invoice_timesheet") { $queue_invoice->do_timesheet_invoicing(); } if ($page == "approve_timesheet") { $queue_approval->do_timesheet_approval_processing(); } } elseif ($action == "split2") { if ($page == "approve_timesheet") { $queue_approval->do_timesheet_split(); } } else { if ($page == "payroll_timesheet") { $queue_payroll->do_timesheet_rejectpayroll(); } if ($page == "invoice_timesheet") { $queue_invoice->do_timesheet_rejectinvoicing(); } #Disable this if ($page == "show_timesheet") { if ($this->validate_timesheet()=="true") { $timesheet_id = $this->save_timesheet(); } #$timesheet_id = $this->save_timesheet(); } } } } function email_on_submission($timesheet_id) { $options = get_option('time_sheets'); if (!$options['enable_email']) { return; } global $wpdb; $db = new time_sheets_db(); $common = new time_sheets_common(); $user = wp_get_current_user(); $user_id = $user->ID; $sql = "select user_login from {$wpdb->prefix}timesheet t join {$wpdb->users} u on u.ID = t.user_id where t.timesheet_id = %d"; $params = array($timesheet_id); $user_login = $db->get_var($sql, $params); $sql = "select user_email, display_name from {$wpdb->users} u join {$wpdb->prefix}timesheet_approvers_approvies aa on u.ID = aa.approver_user_id and aa.approvie_user_id = {$user_id}"; $users = $db->get_results($sql); $sql = "select display_name from {$wpdb->users} u join {$wpdb->prefix}timesheet t on u.ID = t.user_id where t.timesheet_id = {$timesheet_id}"; $display_user = $db->get_var($sql); $subject = "There are time sheet(s) pending approval."; $body = "A time sheet has been entered by {$display_user} and is pending approval. It can be approved from the approval menu."; foreach ($users as $user) { $common->send_email ($user->user_email, $subject, $body); } } function enter_timesheet_sc() { #enable this if ($_POST['action'] == 'save') { if ($this->validate_timesheet()=="true") { $timesheet_id = $this->save_timesheet(); } } else { $timesheet_id = intval($_GET['timesheet_id']); } #global $wpdb; #if ($_POST['submit'] == 'Save Timesheet') { # $db = new time_sheets_db(); # $user_id = get_current_user_id(); # if ($_POST['timesheet_id']) { # $timesheet_id = $_POST['timesheet_id']; # } else { # # $sql = "select max(timesheet_id) # from {$wpdb->prefix}timesheet # where user_id={$user_id}"; # # $timesheet_id = $db->get_var($sql); # } #} #echo $timesheet_id; $page = $this->show_timesheet($timesheet_id, 0); return $page; } function enter_timesheet() { #enable this #if ($_POST['action'] == 'save') { # if ($this->validate_timesheet()=="true") { # $timesheet_id = $this->save_timesheet(); # } #} echo "test1;"; global $wpdb; $db = new time_sheets_db(); $user = wp_get_current_user(); $user_id = $user->ID; if ($_POST['submit'] == 'Save Timesheet') { if ($_POST['timesheet_id']) { $timesheet_id = $_POST['timesheet_id']; } else { $sql = "select max(timesheet_id) from {$wpdb->prefix}timesheet where user_id={$user_id}"; $timesheet_id = $db->get_var($sql); } } $this->show_timesheet($timesheet_id); } function check_overages($timesheet_id, $send=0) { global $wpdb; $options = get_option('time_sheets'); $project_trigger_percent = $options['project_trigger_percent']; $email_address_on_project_over = $options['email_address_on_project_over']; if (!is_numeric($project_trigger_percent)) { $project_trigger_percent = 100; } $db = new time_sheets_db(); $common = new time_sheets_common(); $sql = "select a.MaxHours, a.HoursUsed, a.ProjectName, tc.ClientName, tc.ClientId, a.IsRetainer, trim.MonthlyHours, b.week_complete from {$wpdb->prefix}timesheet_client_projects a join {$wpdb->prefix}timesheet b on a.ProjectId = b.ProjectId join {$wpdb->prefix}timesheet_clients tc on a.ClientId = tc.ClientId left outer join {$wpdb->prefix}timesheet_recurring_invoices_monthly trim on a.ClientId = trim.client_id where timesheet_id=%d"; $params=array($timesheet_id); $project = $db->get_row($sql, $params); $send = 1; if ($project) { $MaxHours = $project->MaxHours; $HoursUsed = $project->HoursUsed; if ($project->IsRetainer==1) { $LastMonthMaxHours = $project->MaxHours-$project->MonthlyHours; $HoursUsed = $project->HoursUsed - $LastMonthMaxHours; $MaxHours = $project->MonthlyHours; } if ($project->week_complete==1) { $send=0; } if ($send==1 && isset($options['enable_email']) && $email_address_on_project_over <> "" && $project->IsRetainer==0 && $project->MaxHours<>0) { $Sales = "The sales team has been notified that this project may require additional hours."; } else { $Sales = "Contact the Sales team is assistance is needed."; } if ($HoursUsed > ($project_trigger_percent/100)*$MaxHours && $MaxHours) { echo "
The project '{$project->ProjectName}' for '{$project->ClientName}' has used {$project_trigger_percent}% of its hours. Be sure that the client approves of hours over the project max of {$project->MaxHours} hours. {$Sales}
"; if ($send==1 && isset($options['enable_email']) && $email_address_on_project_over <> "" && $project->IsRetainer==0 && $project->MaxHours<>0) { $common->send_email($options['email_address_on_project_over'], "Project '{$project->ProjectName}' for '{$project->ClientName}' has used {$project_trigger_percent}% of its hours", "The project '{$project->ProjectName}' for '{$project->ClientName}' has used {$project_trigger_percent}% of its hours.

If the project is not wrapping up, work with the team member working on this project to ensure any needed approvals from the client are received and/or a new SOW is written.

If the project is wrapping up, any post project work should be prepped.

(Sent by the time sheet system)

-----------------------------------------------------------

"); } } } } function validate_timesheet() { $passed = true; if (!$_POST['start_date']) { echo '

The week start date is required.

'; $passed="false"; } if (!$_POST['ClientId']) { echo '

The client name is required.

'; $passed="false"; } if (!$_POST['ProjectId']) { echo '

A project is required.

'; $passed="false"; } return $passed; } function int_to_weekday($week_starts, $days_to_inc) { $value = $week_starts+$days_to_inc; if ($value > 6) { $value = $value-7; } if ($value==0) { $weekday = 'Sunday'; }elseif ($value==1) { $weekday = 'Monday'; }elseif ($value==2) { $weekday = 'Tuesday'; }elseif ($value==3) { $weekday = 'Wednesday'; }elseif ($value==4) { $weekday = 'Thursday'; }elseif ($value==5) { $weekday = 'Friday'; }elseif ($value==6) { $weekday = 'Saturday'; } return $weekday; } function show_timesheet($timesheet_id=0, $show=1) { global $wpdb; #global $timesheet_id; $db = new time_sheets_db(); $user = wp_get_current_user(); $user_id = $user->ID; $main = new time_sheets_main(); $settings = new time_sheets_settings(); $options = get_option('time_sheets'); $common = new time_sheets_common(); $allow_overtime = isset($options['allow_overtime']) ? $options['allow_overtime'] : ""; $currency_char = isset($options['currency_char']) ? $options['currency_char'] : ""; $show_overtime_when_empty = isset($options['show_overtime_when_empty']) ? 1 : 0; $page = ''; $common->show_datestuff(); $queue_approval = new time_sheets_queue_approval(); $queue_invoice = new time_sheets_queue_invoice(); $queue_payroll = new time_sheets_queue_payroll(); if ($user_id == 0) { $page = $page . "

You must be logged in to view this page.

"; return $page; } if (!$timesheet_id || $timesheet_id == 0 || $timesheet_id == "") { if (isset($_POST['timesheet_id']) || isset($_GET['timesheet_id'])) { if (isset($_POST['timesheet_id'])) { $timesheet_id = intval($_POST['timesheet_id']); } else { $timesheet_id = intval($_GET['timesheet_id']); } } else { if (isset($_POST['submit']) && $_POST['submit'] == 'Save Timesheet') { $sql = "select max(timesheet_id) from {$wpdb->prefix}timesheet where user_id={$user_id}"; $timesheet_id = $db->get_var($sql); } } } $page = $page . $this->check_overages(intval($timesheet_id), 1); if (isset($_POST['action']) && ($_POST['action']=="comment_to_timesheet")) { $timesheet_id_int = intval($_POST['timesheet_id']); $comment = $common->esc_textarea($_POST['comment']); $timesheet_rejected = intval($_POST['timesheet_action']); check_admin_referer(); if (!$comment && $timesheet_rejected=1) { $page = $page . "
Time sheets can not be rejected without a comment.
"; } else { $this->save_audit_comment($timesheet_id, $comment, $timesheet_rejected); } } $sql = "select * from {$wpdb->prefix}timesheet t join {$wpdb->users} u on t.user_id = u.ID left outer join {$wpdb->prefix}timesheet_client_projects tcp on t.ProjectId = tcp.ProjectId where timesheet_id=%d"; $params = array($timesheet_id); if ($timesheet_id) { $timesheet = $db->get_row($sql, $params); $timesheet_user = $timesheet->display_name; $timesheet_user_id = $timesheet->user_id; $timesheet_id_int = $timesheet_id; if ((!$queue_approval->employee_approver_check('true') && !$queue_invoice->employee_invoicer_check() && !$queue_payroll->employee_payroll_check() ) && $timesheet_user_id <> $user_id) { $page = $page . "Only supervisors can view other employees time sheets."; return; } } else { #if ($_POST['submit']) { # $sql = "select * from {$wpdb->prefix}timesheet where user_id=%d and start_date = %s"; # $params = array($user_id, $_POST['start_date']); # $timesheet = $db->get_row($sql, $params); #} else { $timesheet = (object) $_POST; $timesheet_user_id = $user_id; #} $timesheet_id_int = 0; } $page = $page . "

Weekly Time Sheet

"; $disable_object=""; if (isset($timesheet->week_complete) && ($timesheet->week_complete=='1')) { $disable_object= " disabled"; } $page = $page . "
"; $nonce = wp_create_nonce(); $page = $page . ""; if (isset($timesheet_user)) { $page = $page . "Timesheet Number: {$timesheet_id}
"; $page = $page . "Timesheet For: {$timesheet_user}
"; } if ($timesheet_id_int == 0) { $defaultDate = get_user_option('timesheet_defaultdate', $user_id); if (!$defaultDate) { $defaultDate='Monday Last Week'; } $start_date = date('Y-m-d', strtotime($defaultDate)); $clientid = -1; } else { $start_date = date("Y-m-d", strtotime($timesheet->start_date)); $clientid = $timesheet->ClientId; } if (date('w', strtotime($start_date)) != $options['week_starts']) { $page = $page . "

This time sheet does not start on a {$this->int_to_weekday($options['week_starts'], 0)}. Please change the date to a {$this->int_to_weekday($options['week_starts'], 0)}.

"; } $page = $page . ""; if ($timesheet_id_int == 0) { $ProjectId = -1; $clientid = 0; } else { $ProjectId = $timesheet->ProjectId; $clientid = $timesheet->ClientId; } if (isset($options['hide_client_project'])) { #$Clients = $common->return_clients_for_user($timesheet_user_id); $Projects = $common->return_projects_for_user($timesheet_user_id); if (sizeof($Projects)==1) { $page = $page . ""; } else { $js_projects = $common->draw_clients_and_projects($clientid, $ProjectId, $timesheet_id_int, $disable_object, $timesheet, $clientList); } } else { $js_projects = $common->draw_clients_and_projects($clientid, $ProjectId, $timesheet_id_int, $disable_object, $timesheet, $clientList); } $page = $page . $js_projects[1]; if (isset($timesheet->notes)) { $page = $page . ""; } $page = $page . "
Week Start Date:
Project Notes:
"; $page = $page . ""; $monday_hours = isset($timesheet->monday_hours) ? $timesheet->monday_hours : '0'; $tuesday_hours = isset($timesheet->tuesday_hours) ? $timesheet->tuesday_hours : '0'; $wednesday_hours = isset($timesheet->wednesday_hours) ? $timesheet->wednesday_hours : '0'; $thursday_hours = isset($timesheet->thursday_hours) ? $timesheet->thursday_hours : '0'; $friday_hours = isset($timesheet->friday_hours) ? $timesheet->friday_hours : '0'; $saturday_hours = isset($timesheet->saturday_hours) ? $timesheet->saturday_hours : '0'; $sunday_hours = isset($timesheet->sunday_hours) ? $timesheet->sunday_hours : '0'; $monday_ot = isset($timesheet->monday_ot) ? $timesheet->monday_ot : '0'; $tuesday_ot = isset($timesheet->tuesday_ot) ? $timesheet->tuesday_ot : '0'; $wednesday_ot = isset($timesheet->wednesday_ot) ? $timesheet->wednesday_ot : '0'; $thursday_ot = isset($timesheet->thursday_ot) ? $timesheet->thursday_ot : '0'; $friday_ot = isset($timesheet->friday_ot) ? $timesheet->friday_ot : '0'; $saturday_ot = isset($timesheet->saturday_ot) ? $timesheet->saturday_ot : '0'; $sunday_ot = isset($timesheet->sunday_ot) ? $timesheet->sunday_ot : '0'; $total_ot = $monday_ot+$tuesday_ot+$wednesday_ot+$thursday_ot+$friday_ot+$saturday_ot+$sunday_ot; $page = $page . ""; $page = $page . ""; $page = $page . ""; $page = $page . ""; $page = $page . ""; $page = $page . ""; $page = $page . ""; $page = $page . ""; $hide_ot = 0; if ($show_overtime_when_empty==1 && isset($timesheet->week_complete) && $timesheet->week_complete=='1' && $total_ot==0) { $hide_ot = 1; } if (($allow_overtime) && ($hide_ot == 0)) { $page = $page . ""; $page = $page . ""; $page = $page . ""; $page = $page . ""; $page = $page . ""; $page = $page . ""; $page = $page . ""; } $page = $page . "
{$this->int_to_weekday($options['week_starts'], 0)}{$this->int_to_weekday($options['week_starts'], 1)}{$this->int_to_weekday($options['week_starts'], 2)}{$this->int_to_weekday($options['week_starts'], 3)}{$this->int_to_weekday($options['week_starts'], 4)}{$this->int_to_weekday($options['week_starts'], 5)}{$this->int_to_weekday($options['week_starts'], 6)}
Hours
Overtime
"; $monday_desc = isset($timesheet->monday_desc) ? $common->esc_textarea($timesheet->monday_desc) : ''; $tuesday_desc = isset($timesheet->tuesday_desc) ? $common->esc_textarea($timesheet->tuesday_desc) : ''; $wednesday_desc = isset($timesheet->wednesday_desc) ? $common->esc_textarea($timesheet->wednesday_desc) : ''; $thursday_desc = isset($timesheet->thursday_desc) ? $common->esc_textarea($timesheet->thursday_desc) : ''; $friday_desc = isset($timesheet->friday_desc) ? $common->esc_textarea($timesheet->friday_desc) : ''; $saturday_desc = isset($timesheet->saturday_desc) ? $common->esc_textarea($timesheet->saturday_desc) : ''; $sunday_desc = isset($timesheet->sunday_desc) ? $common->esc_textarea($timesheet->sunday_desc) : ''; if ($settings->user_can_enter_notes($timesheet_user_id, 'display_notes_toggle', 'display_notes_list')==1) { $page = $page . "
Daily Notes"; $page = $page . ""; $page = $page . ""; $page = $page . ""; $page = $page . ""; $page = $page . ""; $page = $page . ""; $page = $page . "
{$this->int_to_weekday($options['week_starts'], 0)}
{$this->int_to_weekday($options['week_starts'], 1)}
{$this->int_to_weekday($options['week_starts'], 2)}
{$this->int_to_weekday($options['week_starts'], 3)}
{$this->int_to_weekday($options['week_starts'], 4)}
{$this->int_to_weekday($options['week_starts'], 5)}
{$this->int_to_weekday($options['week_starts'], 6)}
"; } $per_diem = ($timesheet_id_int!=0 ? $common->is_match($timesheet->isPerDiem, '1', ' selected') : ''); $actual = ($timesheet_id_int!=0 ? $common->is_match($timesheet->isPerDiem, '0', ' selected') : ''); if ($settings->user_can_enter_notes($timesheet_user_id, 'display_expenses_toggle', 'display_expenses_list')==1) { $page = $page . "Additional Information"; $page = $page . ""; $per_diem_days = (isset($timesheet->per_diem_days) ? $timesheet->per_diem_days : ''); $per_diem_city = (isset($timesheet->perdiem_city) ? $timesheet->perdiem_city : ''); $flight_cost = (isset($timesheet->flight_cost) ? $timesheet->flight_cost : ''); $hotel_charges = (isset($timesheet->hotel_charges) ? $timesheet->hotel_charges : ''); $rental_car_charges = (isset($timesheet->rental_car_charges) ? $timesheet->rental_car_charges : ''); $taxi = (isset($timesheet->taxi) ? $timesheet->taxi : ''); $tolls = (isset($timesheet->tolls) ? $timesheet->tolls : ''); $mileage = (isset($timesheet->mileage) ? $timesheet->mileage : ''); $other_expenses = (isset($timesheet->other_expenses) ? $timesheet->other_expenses : ''); $other_expenses_notes = (isset($timesheet->other_expenses_notes) ? $timesheet->other_expenses_notes : ''); $page = $page . ""; $page = $page . ""; $page = $page . ""; $page = $page . ""; $page = $page . ""; $page = $page . ""; $page = $page . ""; $page = $page . ""; $page = $page . ""; $page = $page . "

Per Diem CityFlight/Train CostsHotel ChargesRental Car ChargesTaxi/RideshareTollsMileage
({$options['distance_metric']} Driven)
Other Expenses
{$currency_char}{$currency_char}{$currency_char}{$currency_char}{$currency_char}{$currency_char}
Other Expense Notes:
"; } $page = $page . ""; if (!isset($options['remove_embargo'])) { $page = $page . ""; } $page = $page . "
Week Complete:week_complete) && $timesheet->week_complete=='1') { $page = $page . " checked disabled"; } $page = $page . ">
Project Complete:project_complete) && $timesheet->project_complete=='1') { $page = $page . " checked"; } $page = $page . "> (If this is available, all project workers must select this for client to be billed as client is only billed upon project completion.)
"; if ($timesheet_id_int==0 || $timesheet->week_complete=='0') { if (isset($timesheet->user_id)) { if ($timesheet->user_id == $user_id) { $page = $page . "
"; } } else { $page = $page . "
"; } } $page = $page . ""; if ($timesheet_id != "") { $page = $page . ""; } $page = $page . ""; $page = $page . "
"; if (isset($timesheet->week_complete) && $timesheet->week_complete=='1' && !isset($options['hide_notes'])){ //Comments that are being audited for time sheets that are closed. $page = $page . "

Time Sheet Comments

"; $nonce = wp_create_nonce(); $page = $page . ""; $page = $page . ""; $page = $page . "
Timesheet Action:
Comment:
"; if ( ($queue_approval->employee_approver_check('true') || $queue_invoice->employee_invoicer_check() || $queue_payroll->employee_payroll_check() ) || ($timesheet_user_id == $user_id && $timesheet->approved==0 && isset($options['allow_users_to_reject'])) ) { $page = $page . "
"; } $page = $page . ""; $page = $page . ""; $page = $page . ""; $page = $page . "
"; } $sql = "select tca.entered_at, tca.comment, tca.timesheet_rejected, u.display_name from {$wpdb->prefix}timesheet_comment_audit tca join {$wpdb->users} u on tca.entered_by = u.ID where timesheet_id=%d order by entered_at desc"; $params = array($timesheet_id); $comments = $db->get_results($sql,$params); if ($comments) { $page = $page . "
Entered Notes
"; foreach ($comments as $comment) { $page = $page . ""; } $page = $page . "
Date EnteredEntered ByComment
{$comment->entered_at}{$comment->display_name}{$common->esc_textarea($comment->comment)}
"; } $page = $page . " "; if ($show==1) { echo $page; } else { return $page; } } function save_audit_comment($timesheet_id, $comment, $timesheet_rejected) { global $wpdb; $user = wp_get_current_user(); $user_id = $user->ID; $db = new time_sheets_db; $common = new time_sheets_common(); if ($timesheet_rejected==1) { $approval = new time_sheets_queue_approval; $approval->do_timesheet_rejectapproval($timesheet_id,$comment); } $sql = "insert into {$wpdb->prefix}timesheet_comment_audit (timesheet_id, entered_by, entered_at, comment, timesheet_rejected) values (%d, %d, now(), %s, %d)"; $params = array($timesheet_id, $user_id, $comment, $timesheet_rejected); $db->query($sql, $params); if ($timesheet_rejected!=1) { $sql = "select user_email from {$wpdb->users} u join {$wpdb->prefix}timesheet t on u.ID = t.user_id where t.timesheet_id = %d union select user_email from {$wpdb->users} u join {$wpdb->prefix}timesheet_invoicers i on u.ID = i.user_id union select user_email from {$wpdb->users} u join {$wpdb->prefix}timesheet_approvers a on u.ID = a.user_id "; $params = array($timesheet_id); $to = $db->get_var($sql, $params); $subject = "Comment on Time Sheet {$timesheet_id}"; $body = $comment . " "; $common->send_email($to, $subject, $body); } } function save_timesheet() { global $wpdb; #global $timesheet_id; $user = wp_get_current_user(); $user_id = $user->ID; $options = get_option('time_sheets'); $ot_multiplier = isset($options['ot_multiplier']) ? floatval($options['ot_multiplier']) : 1; if ($ot_multiplier==0) { $ot_multiplier = 1; } if ($user_id == 0) { echo "

You must be logged in to view this page.

"; return; } if (!$_POST['ProjectId']) { echo '

No Project Was Selected. A project must be selected. If no projects are available contact your lead.

'; return; } if (isset($_POST['timesheet_id'])) { $timesheet_id = intval($_POST['timesheet_id']); } else { $timesheet_id = ''; } $nonce = check_admin_referer( ); $db = new time_sheets_db(); $monday_hours = isset($_POST['monday_hours']) ? floatval($_POST['monday_hours']) : 0; $tuesday_hours = isset($_POST['tuesday_hours']) ? floatval($_POST['tuesday_hours']) : 0; $wednesday_hours = isset($_POST['wednesday_hours']) ? floatval($_POST['wednesday_hours']) : 0; $thursday_hours = isset($_POST['thursday_hours']) ? floatval($_POST['thursday_hours']) : 0; $friday_hours = isset($_POST['friday_hours']) ? floatval($_POST['friday_hours']) : 0; $saturday_hours = isset($_POST['saturday_hours']) ? floatval($_POST['saturday_hours']) : 0; $sunday_hours = isset($_POST['sunday_hours']) ? floatval($_POST['sunday_hours']) : 0; $monday_ot = isset($_POST['monday_ot']) ? floatval($_POST['monday_ot']) : 0; $tuesday_ot = isset($_POST['tuesday_ot']) ? floatval($_POST['tuesday_ot']) : 0; $wednesday_ot = isset($_POST['wednesday_ot']) ? floatval($_POST['wednesday_ot']) : 0; $thursday_ot = isset($_POST['thursday_ot']) ? floatval($_POST['thursday_ot']) : 0; $friday_ot = isset($_POST['friday_ot']) ? floatval($_POST['friday_ot']) : 0; $saturday_ot = isset($_POST['saturday_ot']) ? floatval($_POST['saturday_ot']) : 0; $sunday_ot = isset($_POST['saturday_ot']) ? floatval($_POST['sunday_ot']) : 0; if (isset($_POST['timesheet_id'])) { $sql = "select user_id from {$wpdb->prefix}timesheet where timesheet_id = %d"; $parm = array(intval($_POST['timesheet_id'])); $timesheet = $db->get_row($sql, $parm); if ($timesheet) { //This is an update. Make sure the person updating is this person. if ($timesheet->user_id != $user_id) { echo '

You are attempting this submit a timesheet for a different user. This is not allowed.

'; return; } } else { echo '

You appear to be updating a timesheet which does not exist.

'; return; } } $may_embargo = isset($_POST['may_embargo'])? 1 : 0 ; $project_complete = isset($_POST['project_complete'])? 1 : 0 ; $week_complete = isset($_POST['week_complete']) ? 1 : 0; //if ($_POST['week_complete']==1) { // $week_complete=1; //} else { // $week_complete=0; //} $EmbargoPendingProjectClose = $db->get_var("select BillOnProjectCompletion FROM {$wpdb->prefix}timesheet_recurring_invoices_monthly where client_id = %d", array(intval($_POST['ClientId']))); $EmbargoPendingProjectClose2 = $db->get_var("select BillOnProjectCompletion FROM {$wpdb->prefix}timesheet_client_projects where ProjectId = %d", array(intval($_POST['ProjectId']))); if ($EmbargoPendingProjectClose2==1) { $EmbargoPendingProjectClose=1; } if ($EmbargoPendingProjectClose<>1) { $EmbargoPendingProjectClose=0; } if ($project_complete<>1) { $project_complete=0; } $total_hours = $monday_hours + $tuesday_hours + $wednesday_hours + $thursday_hours + $friday_hours + $saturday_hours + $sunday_hours; $total_hours = $total_hours + (($monday_ot + $tuesday_ot + $wednesday_ot + $thursday_ot + $friday_ot + $saturday_ot + $sunday_ot)*$ot_multiplier); $start_date = date("Y-m-d", strtotime($_POST['start_date'])); if (isset($_POST['timesheet_id'])) { //UPDATE $timesheet_id = $_POST['timesheet_id']; $sql = "update {$wpdb->prefix}timesheet SET start_date=%s, ClientId=%d, ProjectId=%d, monday_hours=%s, tuesday_hours=%s, wednesday_hours=%s, thursday_hours=%s, friday_hours=%s, saturday_hours=%s, sunday_hours=%s, total_hours=%s, monday_desc=%s, tuesday_desc=%s, wednesday_desc=%s, thursday_desc=%s, friday_desc=%s, saturday_desc=%s, sunday_desc=%s, per_diem_days=%s, hotel_charges=%s, rental_car_charges=%s, tolls=%s, other_expenses=%s, other_expenses_notes=%s, week_complete=%d, mileage=%d, EmbargoPendingProjectClose=%d, project_complete=%d, flight_cost=%s, isPerDiem=%d, perdiem_city=%s, taxi=%s, monday_ot=%s, tuesday_ot=%s, wednesday_ot=%s, thursday_ot=%s, friday_ot=%s, saturday_ot=%s, sunday_ot=%s WHERE timesheet_id=%d"; $params=array($start_date, intval($_POST['ClientId']), intval($_POST['ProjectId']), floatval($monday_hours), floatval($tuesday_hours), floatval($wednesday_hours), floatval($thursday_hours), floatval($friday_hours), floatval($saturday_hours), floatval($sunday_hours), $total_hours, sanitize_textarea_field($_POST['monday_desc']), sanitize_textarea_field($_POST['tuesday_desc']), sanitize_textarea_field($_POST['wednesday_desc']), sanitize_textarea_field($_POST['thursday_desc']), sanitize_textarea_field($_POST['friday_desc']), sanitize_textarea_field($_POST['saturday_desc']), sanitize_textarea_field($_POST['sunday_desc']), floatval($_POST['per_diem_days']), floatval($_POST['hotel_charges']), floatval($_POST['rental_car_charges']), floatval($_POST['tolls']), floatval($_POST['other_expenses']), sanitize_textarea_field($_POST['other_expenses_notes']), $week_complete, floatval($_POST['mileage']), $EmbargoPendingProjectClose, $project_complete, floatval($_POST['flight_cost']), intval($_POST['isPerDiem']), sanitize_text_field($_POST['perdiem_city']), floatval($_POST['taxi']), floatval($monday_ot), floatval($tuesday_ot), floatval($wednesday_ot), floatval($thursday_ot), floatval($friday_ot), floatval($saturday_ot), floatval($sunday_ot), intval($_POST['timesheet_id'])); $db->query($sql, $params); if ($week_complete==1) { $sql = "update {$wpdb->prefix}timesheet set marked_complete_by=$user_id, marked_complete_date = CURDATE() where timesheet_id=%d"; $params=array(intval($_POST['timesheet_id'])); $db->query($sql, $params); if ($EmbargoPendingProjectClose==0) { $this->email_on_submission(intval($_POST['timesheet_id'])); } $sql = "update {$wpdb->prefix}timesheet_client_projects set HoursUsed=HoursUsed+$total_hours where ProjectId=%d"; $params=array(intval($_POST['ProjectId'])); $db->query($sql, $params); $this->set_project_inactive_on_date(intval($_POST['ProjectId'])); } //Archive the change $sql = "INSERT INTO {$wpdb->prefix}timesheet_archive SELECT $user_id, now(), 'UPDATED', timesheet_id, user_id, start_date, entered_date, client_name, project_name, monday_hours, tuesday_hours, wednesday_hours, thursday_hours, friday_hours, saturday_hours, sunday_hours, total_hours, monday_desc, tuesday_desc, wednesday_desc, thursday_desc, friday_desc, saturday_desc, sunday_desc, per_diem_days, hotel_charges, rental_car_charges, tolls, other_expenses, other_expenses_notes, week_complete, marked_complete_by, marked_complete_date, approved, approved_by, approved_date, invoiced, invoiced_by, invoiced_date, invoiceid, ClientId, mileage, EmbargoPendingProjectClose, project_complete, ProjectId, payrolled, payrolled_on, payrolled_by, flight_cost, isPerDiem, perdiem_city, taxi, monday_ot, tuesday_ot, wednesday_ot, thursday_ot, friday_ot, saturday_ot, sunday_ot FROM {$wpdb->prefix}timesheet WHERE timesheet_id = %d"; $params = array(intval($_POST['timesheet_id'])); $db->query($sql, $params); echo '

Timesheet updated.

'; } else { //INSERT $sql = "insert into {$wpdb->prefix}timesheet (user_id, start_date, entered_date, ClientId, ProjectId, monday_hours, tuesday_hours, wednesday_hours, thursday_hours, friday_hours, saturday_hours, sunday_hours, total_hours, monday_desc, tuesday_desc, wednesday_desc, thursday_desc, friday_desc, saturday_desc, sunday_desc, per_diem_days, hotel_charges, rental_car_charges, tolls, other_expenses, other_expenses_notes, week_complete, approved, invoiced, mileage, EmbargoPendingProjectClose, project_complete, flight_cost, isPerDiem, perdiem_city, taxi, monday_ot, tuesday_ot, wednesday_ot, thursday_ot, friday_ot, saturday_ot, sunday_ot) values (%d, %s, now(), %d, %d, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %d, 0, 0, %d, %d, %d, %s, %d, %s, %s, %s, %s, %s, %s, %s, %s, %s)"; $params=array($user_id, $start_date, intval($_POST['ClientId']), intval($_POST['ProjectId']), floatval($monday_hours), floatval($tuesday_hours), floatval($wednesday_hours), floatval($thursday_hours), floatval($friday_hours), floatval($saturday_hours), floatval($sunday_hours), $total_hours, sanitize_textarea_field($_POST['monday_desc']), sanitize_textarea_field($_POST['tuesday_desc']), sanitize_textarea_field($_POST['wednesday_desc']), sanitize_textarea_field($_POST['thursday_desc']), sanitize_textarea_field($_POST['friday_desc']), sanitize_textarea_field($_POST['saturday_desc']), sanitize_textarea_field($_POST['sunday_desc']), floatval($_POST['per_diem_days']), floatval($_POST['hotel_charges']), floatval($_POST['rental_car_charges']), floatval($_POST['tolls']), floatval($_POST['other_expenses']), sanitize_textarea_field($_POST['other_expenses_notes']), $week_complete, $_POST['mileage'], $EmbargoPendingProjectClose, $project_complete, floatval($_POST['flight_cost']), floatval($_POST['isPerDiem']), sanitize_text_field($_POST['perdiem_city']), floatval($_POST['taxi']), floatval($monday_ot), floatval($tuesday_ot), floatval($wednesday_ot), floatval($thursday_ot), floatval($friday_ot), floatval($saturday_ot), floatval($sunday_ot)); $db->query($sql, $params); $sql = "select max(timesheet_id) from {$wpdb->prefix}timesheet where user_id={$user_id}"; $timesheet_id = $db->get_var($sql); #$this->check_overages($timesheet_id, 1); if ($week_complete==1) { $sql = "update {$wpdb->prefix}timesheet set marked_complete_by=$user_id, marked_complete_date = CURDATE() where timesheet_id=$timesheet_id"; $db->query($sql); if ($EmbargoPendingProjectClose==0) { $this->email_on_submission($timesheet_id); } $sql = "update {$wpdb->prefix}timesheet_client_projects set HoursUsed=HoursUsed+$total_hours where ProjectId=%d"; $params=array(intval($_POST['ProjectId'])); $db->query($sql, $params); $this->set_project_inactive_on_date(intval($_POST['ProjectId'])); } //Archive the change $sql = "INSERT INTO {$wpdb->prefix}timesheet_archive SELECT $user_id, now(), 'UPDATED', timesheet_id, user_id, start_date, entered_date, client_name, project_name, monday_hours, tuesday_hours, wednesday_hours, thursday_hours, friday_hours, saturday_hours, sunday_hours, total_hours, monday_desc, tuesday_desc, wednesday_desc, thursday_desc, friday_desc, saturday_desc, sunday_desc, per_diem_days, hotel_charges, rental_car_charges, tolls, other_expenses, other_expenses_notes, week_complete, marked_complete_by, marked_complete_date, approved, approved_by, approved_date, invoiced, invoiced_by, invoiced_date, invoiceid, ClientId, mileage, EmbargoPendingProjectClose, project_complete, ProjectId, payrolled, payrolled_on, payrolled_by, flight_cost, isPerDiem, perdiem_city, taxi, monday_ot, tuesday_ot, wednesday_ot, thursday_ot, friday_ot, saturday_ot, sunday_ot FROM {$wpdb->prefix}timesheet WHERE timesheet_id = %d"; $params = array(intval($timesheet_id)); $db->query($sql, $params); echo '

Timesheet saved.

'; } if ($may_embargo==1) { if ($project_complete==1 && $week_complete==1) { $sql = "update {$wpdb->prefix}timesheet SET EmbargoPendingProjectClose = 0 WHERE ProjectId=%d AND EmbargoPendingProjectClose = 1"; $params = array(intval($_POST['ProjectId'])); $db->query($sql, $params); //Archive the change $sql = "INSERT INTO {$wpdb->prefix}timesheet_archive SELECT $user_id, now(), 'UPDATED', timesheet_id, user_id, start_date, entered_date, client_name, project_name, monday_hours, tuesday_hours, wednesday_hours, thursday_hours, friday_hours, saturday_hours, sunday_hours, total_hours, monday_desc, tuesday_desc, wednesday_desc, thursday_desc, friday_desc, saturday_desc, sunday_desc, per_diem_days, hotel_charges, rental_car_charges, tolls, other_expenses, other_expenses_notes, week_complete, marked_complete_by, marked_complete_date, approved, approved_by, approved_date, invoiced, invoiced_by, invoiced_date, invoiceid, ClientId, mileage, EmbargoPendingProjectClose, project_complete, ProjectId, payrolled, payrolled_on, payrolled_by, flight_cost, isPerDiem, perdiem_city, taxi, monday_ot, tuesday_ot, wednesday_ot, thursday_ot, friday_ot, saturday_ot, sunday_ot FROM {$wpdb->prefix}timesheet WHERE ProjectId=%d AND EmbargoPendingProjectClose = 1"; $params = array(intval($_POST['ProjectId'])); $db->query($sql, $params); echo "
Your timesheets for this client have been sent for processing.

"; $sql = "update {$wpdb->prefix}timesheet_client_projects set Active=0 where ProjectId=%d"; $params = array(intval($_POST['ProjectId'])); $db->query($sql, $params); //Archive the change $sql = "INSERT INTO {$wpdb->prefix}timesheet_client_projects_archive SELECT $user_id, now(), 'UPDATED', ProjectId, ClientId, ProjectName, IsRetainer, MaxHours, HoursUsed, Active, notes, BillOnProjectCompletion, flat_rate, po_number, sales_person_id, technical_sales_person_id, close_on_completion FROM {$wpdb->prefix}timesheet_client_projects WHERE ProjectId=%d"; $params = array(intval($_POST['ProjectId'])); $db->query($sql, $params); echo "
This project has been marked as closed.

"; $this->email_on_submission(intval($timesheet_id)); } } #$sql = "select * from {$wpdb->prefix}timesheet_client_projects where project_id = %d"; #$parm = array(intval($_POST['ClientId'])); #$client = $db->get_row($sql, $parm); return $timesheet_id; } function set_project_inactive_on_date($project_id) { global $wpdb; $user = wp_get_current_user(); $user_id = $user->ID; $db = new time_sheets_db(); $common = new time_sheets_common(); $sql = "select MaxHours, IsRetainer FROM {$wpdb->prefix}timesheet_client_projects WHERE ProjectId = %d"; $params = array($project_id); $project = $db->get_row($sql, $params); if ($project->IsRetainer==1) { #The project is a retainer, do not close it return; } if ($project->MaxHours==0) { #If the project has no max number of hours, skip it return; } $sql = "select sum(total_hours) total_hours FROM {$wpdb->prefix}timesheet WHERE ProjectId = %d and week_complete = 1"; $params = array($project_id); $timesheets = $db->get_row($sql, $params); if ($timesheets->total_hours < $project->MaxHours) { #The project hasn't run out of hours so there's nothing to do yet return; } $date = new DateTime(); // Modify the date it contains $date->modify('next tuesday'); $nextTuesday = $date->format('Y-m-d'); $sql = "delete from {$wpdb->prefix}timesheet_client_project_autoclose where project_id = %d"; $params = array($project_id); $db->query($sql, $params); $sql = "insert into {$wpdb->prefix}timesheet_client_project_autoclose (project_id, close_date) values (%d, %s)"; $params = array($project_id, $nextTuesday); $db->query($sql, $params); } }