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 NameInvoice NumberBillable HoursNon-Billable HoursMileage ({$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->invoiceid)}{$common->clean_from_db($timesheet->total_hours)}{$common->clean_from_db($timesheet->total_nb)}{$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'); $common = new time_sheets_common(); 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); $common->archive_records ('timesheet', 'timesheet_archive', 'timesheet_id', intval($_GET['timesheet_id']), '=', 'UPDATED'); 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, t.monday_nb+t.tuesday_nb+t.wednesday_nb+t.thursday_nb+t.friday_nb+t.saturday_nb+t.sunday_nb as total_nb 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; $common = new time_sheets_common(); 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); $common->archive_records ('timesheet', 'timesheet_archive', 'timesheet_id', $timesheet->timesheet_id, '=', 'INSERTED'); } } 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 "