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.
";
}
echo "| Timesheet | View | User | Approved | Week Completed | Invoice Number | Start Date | First Billed Date | ";
if ((isset($options['hide_client_project']) && sizeof($Projects) != 1) || !isset($options['hide_client_project'])) {
echo "Client | Project Name | ";
}
echo "Total Hours | Sales Person | Technical Sales Person | ";
if ($allow_invoice_comment_snipit) {
echo "Notes | ";
}
echo "
";
foreach ($timesheets as $timesheet) {
echo "{$timesheet->timesheet_id} |
 |
{$timesheet->display_name} | ";
if ($timesheet->approved==1) {
echo " ";
} else {
echo " ";
}
echo " | ";
if ($timesheet->marked_complete_by) {
echo " ";
} else {
echo " ";
}
echo " | {$timesheet->invoiceid} | {$common->f_date($timesheet->start_date)} | {$common->f_date($timesheet->first_billed_day)} | ";
if ((isset($options['hide_client_project']) && sizeof($Projects) != 1) || !isset($options['hide_client_project'])) {
echo "{$common->clean_from_db($timesheet->client_name)} | {$common->clean_from_db($timesheet->project_name)} | ";
}
echo "{$timesheet->total_hours} | ";
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;
}
}
if ($allow_invoice_comment_snipit) {
echo "";
echo substr($common->esc_textarea($timesheet->other_expenses_notes), 0, 20);
if (strlen($common->esc_textarea($timesheet->other_expenses_notes)) > 20) {
echo " ...";
}
echo " | ";
}
echo "";
}
echo "
";
}
function closed_timesheet_menu() {
global $wpdb;
$common = new time_sheets_common();
$db = new time_sheets_db();
$start_date = isset($_POST['start_date']) ? sanitize_text_field($_POST['start_date']) : "";
$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['ClientId']) ? intval($_POST['ClientId']) : "";
$invoice_number = isset($_POST['invoice_number']) ? sanitize_text_field($_POST['invoice_number']) : "";
$user_id = isset($_POST['user_id']) ? intval($_POST['user_id']) : "";
$options = get_option('time_sheets');
$Projects = $common->return_projects_for_user(-1);
$users = $common->return_employee_list();
if (!$ClientId) {
$ClientId = -1;
}
if (!$ProjectId) {
$ProjectId = -1;
}
echo "Search for Invoiced Time Sheets
";
echo "";
echo "
";
}
function show_invoicing_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();
$common = new time_sheets_common();
$user = wp_get_current_user();
$user_id = $user->ID;
$options = get_option('time_sheets');
$timesheets = $this->return_invoicing_list();
$allow_show_record_invoicing = get_user_option('time_sheets_invoicing_allow_show_record_invoicing', $user_id);
$currency_char = $options['currency_char'];
$retainers_parm = "";
if (isset($_GET['show_retainers'])) {
$retainers_parm = "&show_retainers=checked";
}
if (isset($_GET['hide_nonretainers'])) {
$retainers_parm = $retainers_parm . "&hide_nonretainers=checked";
}
if ($timesheets) {
echo "
";
if (isset($_GET['show_retainers'])) {
echo "";
}
if (isset($_GET['hide_nonretainers'])) {
echo "";
}
wp_nonce_field( 'timesheet_invoice_processing' );
if (isset($_GET['retainer_type'])) {
$retainer_type = $_GET['retainer_type'];
} else {
$retainer_type = "";
}
echo "
";
} else {
echo "No time sheets to invoice.
";
}
}
function invoice_timesheet(){
global $wpdb;
$entry = new time_sheets_entry();
$common = new time_sheets_common();
$db = new time_sheets_db();
$user = wp_get_current_user();
$user_id = $user->ID;
$allow_show_record_invoicing = get_user_option('time_sheets_invoicing_allow_show_record_invoicing', $user_id);
if (isset($_GET['retainer_type'])) {
$retainer_type=intval($_GET['retainer_type']);
} else {
$retainer_type=0;
}
if (isset($_GET['action']) && $_GET['action']=='preinvoice') {
$entry->show_timesheet();
} else {
$show_retainers = isset($_GET['show_retainers']) ? " checked" : "";
$hide_nonretainers = isset($_GET['hide_nonretainers']) ? " checked" : "";
$sql = "select retainer_name, retainer_id from {$wpdb->prefix}timesheet_custom_retainer_frequency where active = 1";
$frequencies = $db->get_results($sql);
echo "
";
echo "