return_payroll_list(); return count ($timesheets); } function show_payroll_list() { global $wpdb; $db = new time_sheets_db(); $main = new time_sheets_main(); $queue_approval = new time_sheets_queue_approval(); $approver = $queue_approval->employee_approver_check(); $options = get_option('time_sheets'); $common = new time_sheets_common(); $timesheets = $this->return_payroll_list(); $currency_char = $options['currency_char']; $distance_metric = $options['distance_metric']; if ($timesheets) { echo "
"; if ($approver<>0) { echo ""; } echo ""; if (isset($options['mileage'])) { echo ""; } if (isset($options['per_diem'])) { echo ""; } if (isset($options['flight_cost'])) { echo ""; } if (isset($options['hotel'])) { echo ""; } if (isset($options['rental_car'])) { echo ""; } if (isset($options['taxi'])) { echo ""; } if (isset($options['tolls'])) { echo ""; } if (isset($options['other_expenses'])) { echo ""; } echo ""; foreach ($timesheets as $timesheet) { echo ""; if ($approver<>0) { echo ""; } echo ""; if (isset($options['mileage'])) { echo ""; } if (isset($options['per_diem'])) { echo ""; } if (isset($options['flight_cost'])) { echo ""; } if (isset($options['hotel'])) { echo ""; } if (isset($options['rental_car'])) { echo ""; } if (isset($options['taxi'])) { echo ""; } if (isset($options['tolls'])) { echo ""; } if (isset($options['other_expenses'])) { echo ""; } echo ""; } echo "
TimesheetRejectViewCompletedUserStart DateClientProject NameHoursMileage ({$distance_metric})Per Diem DaysFlight/Train CostHotel ChargesRental CarTaxi/RideshareTollsOther Expenses
{$timesheet->timesheet_id}{$common->replace(' ', ' ', $timesheet->display_name)}{$common->f_date($timesheet->start_date)}{$common->clean_from_db($timesheet->client_name)}{$common->clean_from_db($timesheet->project_name)}{$common->clean_from_db($timesheet->total_hours)}{$timesheet->mileage}{$timesheet->per_diem_days}{$currency_char}{$timesheet->flight_cost}{$currency_char}{$timesheet->hotel_charges}{$currency_char}{$timesheet->rental_car_charges}{$currency_char}{$timesheet->taxi}{$currency_char}{$timesheet->tolls}{$currency_char}{$timesheet->other_expenses}

"; wp_nonce_field( 'timesheet_payroll_processing' ); echo "
"; } else { echo "No time sheets to process for payroll."; } } function payroll_timesheet(){ $entry = new time_sheets_entry(); if (isset($_GET['action']) && $_GET['action']=='preinvoice') { $entry->show_timesheet(); } else { echo "
"; } } function do_timesheet_rejectpayroll() { global $wpdb; $db = new time_sheets_db(); $user = wp_get_current_user(); $user_id = $user->ID; $options = get_option('time_sheets'); if ($options['queue_order']=='parallel') { echo '

This timesheet may be in the payroll queue and may need to be adjusted.


'; } $sql = "update {$wpdb->prefix}timesheet set invoiced = 0, invoiced_by = NULL, invoiced_date = NULL, payrolled = NULL where timesheet_id = %d"; $params = array(intval($_GET['timesheet_id'])); $db->query($sql, $params); $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($_GET['timesheet_id'])); $db->query($sql, $params); echo '

Timesheet has been rejected.

'; } function return_payroll_list() { global $wpdb; $db = new time_sheets_db(); $options = get_option('time_sheets'); $sql = "select t.timesheet_id, u.user_login, t.start_date, c.ClientName client_name, cp.ProjectName project_name, t.invoiceid, cp.notes, t.per_diem_days, t.hotel_charges, t.rental_car_charges, t.tolls, t.other_expenses, t.mileage, t.flight_cost, u.display_name, t.total_hours, t.taxi from {$wpdb->prefix}timesheet t JOIN {$wpdb->prefix}timesheet_clients c ON t.ClientId = c.ClientId JOIN {$wpdb->prefix}timesheet_client_projects cp ON t.ProjectId = cp.ProjectId join {$wpdb->users} u on t.user_id = u.ID"; if ($options['queue_order']=='parallel') { $sql = "{$sql} where t.approved = 1 and payrolled = 0"; } else { $sql = "{$sql} where t.invoiced = 1 and payrolled = 0"; } $sql = "{$sql} order by t.start_date"; $timesheets = $db->get_results($sql); return $timesheets; } function do_timesheet_payroll(){ global $wpdb; $db = new time_sheets_db(); $user = wp_get_current_user(); $user_id = $user->ID; check_admin_referer( 'timesheet_payroll_processing' ); $timesheets = $this->return_payroll_list(); foreach ($timesheets as $timesheet) { $valuename = "timesheet_{$timesheet->timesheet_id}"; if (isset($_GET[$valuename]) && $_GET[$valuename] == 1) { $sql = "update {$wpdb->prefix}timesheet set payrolled= 1, payrolled_by = {$user_id}, payrolled_on = CURDATE() where timesheet_id = {$timesheet->timesheet_id}"; $db->query($sql); $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($timesheet->timesheet_id); $db->query($sql, $params); } } echo '

Timesheet(s) have been updated.

'; } function employee_payroll_check() { global $wpdb; global $payrol_count; $user = wp_get_current_user(); $user_id = $user->ID; $db = new time_sheets_db(); if (!isset($payrol_count)) { $sql = "select count(*) from {$wpdb->prefix}timesheet_payrollers where user_id = {$user_id}"; $count = $db->get_var($sql); $payrol_count = $count; } else { $count = $payrol_count; } return $count; } }
"; $this->show_payroll_list(); echo "