closed_timesheet_menu(); if (isset($_POST['filled_out'])) { $this->closed_timesheet_search(); } } function closed_timesheet_search() { global $wpdb; $db = new time_sheets_db(); $common = new time_sheets_common(); $start_date = isset($_POST['start_date']) ? sanitize_text_field($_POST['start_date']) : -2; $end_date = isset($_POST['end_date']) ? sanitize_text_field($_POST['end_date']) : ""; $invoiced_start_date = isset($_POST['invoiced_start_date']) ? sanitize_text_field($_POST['invoiced_start_date']) : ""; $invoiced_end_date = isset($_POST['invoiced_end_date']) ? sanitize_text_field($_POST['invoiced_end_date']) : ""; $ClientId = isset($_POST['ClientId']) ? intval($_POST['ClientId']) : ""; $ProjectId = isset($_POST['ProjectId']) ? intval($_POST['ProjectId']) : ""; $invoice_number = isset($_POST['invoice_number']) ? intval($_POST['invoice_number']) : ""; $user_id = isset($_POST['user_id']) ? intval($_POST['user_id']) : ""; $allow_invoice_comment_snipit = get_user_option('allow_invoice_comment_snipit', $user_id); $options = get_option('time_sheets'); $Projects = $common->return_projects_for_user(-1); if ($ClientId == -2) { unset($ClientId); } if ($ProjectId == -2) { unset($ProjectId); } $sql = "select t.timesheet_id, u.user_login, t.start_date, c.ClientName client_name, cp.ProjectName project_name, t.invoiceid, cp.notes, u.display_name, cp.po_number, date_add(t.start_date, INTERVAL CASE WHEN monday_hours != 0 then 0 when tuesday_hours != 0 then 1 when wednesday_hours != 0 then 2 when thursday_hours != 0 then 3 when friday_hours != 0 then 4 when saturday_hours != 0 then 5 when sunday_hours != 0 then 6 else 0 end DAY) first_billed_day, case when cs.display_name is null then 'None' else cs.display_name end cs_display_name, case when cps.display_name is null then 'None' else cps.display_name end cps_display_name, case when tcs.display_name is null then 'None' else tcs.display_name end tcs_display_name, case when tcps.display_name is null then 'None' else tcps.display_name end tcps_display_name, t.total_hours, t.invoiceid, t.approved, t.marked_complete_by, t.other_expenses_notes from {$wpdb->prefix}timesheet t JOIN {$wpdb->prefix}timesheet_client_projects cp ON t.ProjectId = cp.ProjectId JOIN {$wpdb->prefix}timesheet_clients c ON cp.ClientId = c.ClientId left outer join {$wpdb->users} cs on c.sales_person_id = cs.ID left outer join {$wpdb->users} cps on cp.sales_person_id = cps.ID left outer join {$wpdb->users} tcs on c.technical_sales_person_id = tcs.ID left outer join {$wpdb->users} tcps on cp.technical_sales_person_id = tcps.ID join {$wpdb->users} u on t.user_id = u.ID where approved = 1 and t.invoiced = 1"; if ($start_date) { $sql = $sql . " and t.start_date > '{$start_date}'"; } if ($end_date) { $sql = $sql . " and t.start_date <= '{$end_date}'"; } if ($invoiced_start_date) { $sql = $sql . " and t.invoiced_date > '{$invoiced_start_date}'"; } if ($invoiced_end_date) { $sql = $sql . " and t.invoiced_date <= '{$invoiced_end_date}'"; } if (isset($ClientId)) { $sql = $sql . " and c.ClientId = {$ClientId}"; } if ($ProjectId) { $sql = $sql . " and t.ProjectId = {$ProjectId}"; } if ($invoice_number) { $sql = $sql . " and t.invoiceid = {$invoice_number}"; } if ($user_id) { $sql = $sql . " and t.user_id = {$user_id}"; } $timesheets = $db->get_results($sql); if (!$timesheets) { echo "
No matching time sheets found.
| Timesheet | "; if ($approver<>0) { echo "Reject | "; } echo "View | Completed | Invoice Number | User | "; if (isset($options['allow_money_based_retainers'])) { echo "Users Title | "; } echo "Start Date | First Billed Day | Last Billed Day | Client | Project Name | PO Number | Sales Person | Technical Sales Person | Hours | Expenses | {$timesheet->timesheet_id} | "; if ($approver<>0) { echo "{$common->replace(' ', ' ', $timesheet->display_name)} | "; if (isset($options['allow_money_based_retainers'])) { echo "";
if (isset($timesheet->TitleNameOverride)) {
echo $common->clean_from_db($timesheet->TitleNameOverride) . "*";
} else {
echo $common->clean_from_db($timesheet->TitleName);
}
echo " | ";
}
echo "{$common->f_date($timesheet->start_date)} | {$common->f_date($timesheet->first_billed_day)} | {$common->f_date($timesheet->last_day_billed)} | {$common->clean_from_db($timesheet->client_name)} | {$common->clean_from_db($timesheet->project_name)} | {$common->clean_from_db($timesheet->po_number)} | "; if ($options['sales_override']=='project') { if ($timesheet->cps_display_name) { echo $timesheet->cps_display_name; echo " | "; echo $timesheet->tcps_display_name; } else { echo $timesheet->cs_display_name; echo " | "; echo $timesheet->tcs_display_name; } } else { if ($timesheet->cs_display_name) { echo $timesheet->cs_display_name; echo " | "; echo $timesheet->tcs_display_name; } else { echo $timesheet->cps_display_name; echo " | "; echo $timesheet->tcps_display_name; } } $total_hours = $timesheet->total_hours; $total_hours = number_format($total_hours, 2); if (is_numeric($timesheet->expenses)) { $total_expenses = $currency_char . number_format($timesheet->expenses, 2); } else { $total_expenses = ""; } echo " | {$total_hours} | {$total_expenses} | "; } echo "
NOTE: Any titles which are being overriden for a specific project, will be marked with a *
"; } } else { echo "