employee_invoicer_check(); $approver=$queue_approval->employee_approver_check('false'); echo "

"; if ($approver==1) { echo "   "; } if ($invoicer==1) { echo " "; } if ($approver==1) { echo "  "; } echo "
"; if ($_GET['menu']=='New Client') { $this->add_client(); } if ($_GET['menu']=='Edit Client') { $this->add_client_users(); } if ($_GET['menu']=='Setup Monthlies') { $this->setup_monthlies(); } if ($_GET['menu']=='New Project') { $this->NewProject(); } if ($_GET['menu']=='Edit Project') { $this->EditProject(); } if ($_GET['menu']=='view_timesheets_for_project') { $this->view_timesheets_for_project(); } } function view_timesheets_for_project(){ $db = new time_sheets_db(); global $wpdb; $user_id = get_current_user_id(); $sql = "select t.timesheet_id, t.start_date, t.total_hours, invoiced, approved, EmbargoPendingProjectClose, u.display_name from {$wpdb->prefix}timesheet t join {$wpdb->users} u on t.user_id = u.ID where ProjectId = %d order by start_date, display_name"; $parms = array(intval($_GET['ProjectId'])); $timesheets = $db->get_results($sql, $parms); if ($timesheets) { echo "

"; $totalhours = 0; foreach ($timesheets as $timesheet) { if ($timesheet->invoiced=="1") { $is_invoiced=plugins_url( 'check.png' , __FILE__); } else { $is_invoiced=plugins_url( 'x.png' , __FILE__); } if ($timesheet->approved=="1") { $is_approved=plugins_url( 'check.png' , __FILE__); } else { $is_approved= plugins_url( 'x.png' , __FILE__) ; } if ($timesheet->EmbargoPendingProjectClose=="1") { $is_Embargoed= plugins_url( 'check.png' , __FILE__) ; } else { $is_Embargoed= plugins_url( 'x.png' , __FILE__); } $totalhours = $totalhours + $timesheet->total_hours; $start_date = date('Y-m-d', strtotime($timesheet->start_date)); echo ""; } echo "
Timesheet IDWeek StartingEmployeeHours InvoicedIs ApprovedIs InvoicedIs Embargoed
{$timesheet->timesheet_id} {$start_date} {$timesheet->display_name} {$timesheet->total_hours}

Total Hours To Date: {$totalhours}"; } else { echo "There are no timesheets for this project at this time."; } } function setup_monthlies() { $db = new time_sheets_db(); global $wpdb; $user_id = get_current_user_id(); $common = new time_sheets_common(); if ($_POST['BillOnProjectCompletion']) { $BillOnProjectCompletion = 1; } else { $BillOnProjectCompletion = 0; } if ($_POST['sub_action']=='update_client') { $sql = "select * from {$wpdb->prefix}timesheet_recurring_invoices_monthly where client_id = %d"; $parms = array($_POST['ClientId']); $client = $db->get_row($sql, $parms); if ($_POST['enabled']) { if ($client->client_id) { $sql = "update {$wpdb->prefix}timesheet_recurring_invoices_monthly SET MonthlyHours = %d, HourlyRate = %d, Notes = '%s', BillOnProjectCompletion = %d WHERE client_id = %d"; $parm = array(intval($_POST['MonthlyHours']), $_POST['HourlyRate'], sanitize_text_field($_POST['notes']), $BillOnProjectCompletion, intval($_POST['ClientId'])); $db->query($sql, $parm); echo '

Client Updated.

'; } else { $db->query("insert into {$wpdb->prefix}timesheet_recurring_invoices_monthly (client_id, MonthlyHours, HourlyRate, Notes, BillOnProjectCompletion ) values (%d, %d, %d, '%s', %d)", array(intval($_POST['ClientId']), intval($_POST['MonthlyHours']), $_POST['HourlyRate'], sanitize_text_field($_POST['notes']), $BillOnProjectCompletion)); echo '

Client Added.

'; } } if (!$_POST['enabled']) { $db->query("delete from {$wpdb->prefix}timesheet_recurring_invoices_monthly where client_id = %d", array(intval($_POST['ClientId']))); echo '

Client Removed.

'; } } echo "
"; echo "
Select Client:"; $clients = $db->get_results("select ClientName, tc.ClientId, im.client_id IsMonthly from {$wpdb->prefix}timesheet_clients tc left outer join {$wpdb->prefix}timesheet_recurring_invoices_monthly im on tc.clientid = im.client_id order by ClientName"); if ($clients) { echo ""; } echo "
"; echo ""; echo "
"; if ($_POST['action']=='select_client') { $sql = "select * from {$wpdb->prefix}timesheet_recurring_invoices_monthly where client_id = %d"; $parms = array(intval($_POST['ClientId'])); $client = $db->get_row($sql, $parms); echo "

"; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo "
Enabled:client_id) { echo " checked"; } echo ">
Hours Included:
Hourly Rate:
Notes:
BillOnProjectCompletion == 1) { echo " checked"; } echo "> Bill On Project Completion
"; echo ""; echo ""; echo ""; echo ""; echo "
"; } } function add_client_users() { $db = new time_sheets_db(); global $wpdb; $user_id = get_current_user_id(); if ($_POST['ClientId'] && $_POST['action']=='update_client1') { $sql = "select ID from {$wpdb->users} u"; $users = $db->get_results($sql); foreach ($users as $user) { $id = "user_{$user->ID}"; if ($_POST[$id]) { $sql = "insert into {$wpdb->prefix}timesheet_clients_users (ClientId, user_id) values (%d, %d)"; $db->query($sql, array(intval($_POST['ClientId']), $user->ID)); } else { $sql = "delete from {$wpdb->prefix}timesheet_clients_users where ClientId = %d and user_id = %d"; $db->query($sql, array(intval($_POST['ClientId']), $user->ID)); } } $sql = "update {$wpdb->prefix}timesheet_clients set ClientName = %s where ClientId = %d"; $parms = array(sanitize_text_field($_POST['ClientName']), intval($_POST['ClientId'])); $db->query($sql, $parms); echo '

Client Updated.

'; } echo "
"; echo ""; $clients = $db->get_results("select ClientName, tc.ClientId from {$wpdb->prefix}timesheet_clients tc order by ClientName"); if ($clients) { echo "
Client Name"; } echo "
"; echo ""; echo "
"; if ($_POST['ClientId']) { $sql = "select u.user_login, u.ID, tcu.user_id cu, u.display_name from {$wpdb->users} u left outer join {$wpdb->prefix}timesheet_clients_users tcu on u.id = tcu.user_id and tcu.ClientId = %d order by u.display_name"; $users = $db->get_results($sql, array(intval($_POST['ClientId']))); $sql = "select * from {$wpdb->prefix}timesheet_clients where ClientId = %d"; $client = $db->get_row($sql, array(intval($_POST['ClientId']))); echo "
"; echo "
Client Name:

"; foreach ($users as $user) { echo ""; } echo "
 User NameUser
cu) { echo " checked"; } echo ">{$user->user_login}{$user->display_name}
"; echo "
"; echo ""; echo ""; echo "
"; } } function add_client() { global $wpdb; $db = new time_sheets_db(); $user_id = get_current_user_id(); if ($_POST['action']=='save_client' && $_POST['ClientName'] != '') { $ClientId=$db->get_var("select ClientId from {$wpdb->prefix}timesheet_clients where ClientName=%s", array(sanitize_text_field($_POST['ClientName']))); if (!$ClientId) { $db->query("insert into {$wpdb->prefix}timesheet_clients (ClientName, Active) values (%s, 1)", array(sanitize_text_field($_POST['ClientName']))); $ClientId=$db->get_var("select ClientId from {$wpdb->prefix}timesheet_clients where ClientName=%s", array(sanitize_text_field($_POST['ClientName']))); $db->query("insert into {$wpdb->prefix}timesheet_clients_users (ClientId, user_id) values ($ClientId, $user_id)"); echo '

Client Added.

'; } else { $db->query("insert into {$wpdb->prefix}timesheet_clients_users (ClientId, user_id) values ($ClientId, $user_id)"); echo '

Client already exists.
Access granted to client.

'; } } echo "
"; echo ""; echo ""; echo ""; echo ""; } function NewProject() { global $wpdb; $db = new time_sheets_db(); $options = get_option('time_sheets'); $common = new time_sheets_common(); if ($_GET['action']=='Save Project'){ $this->SaveNewProject(); } if ($_GET['IsRetainer']==1) { $IsRetainer = ' checked'; } if ($_GET['Active']==1) { $Active = ' checked'; } if ($_GET['BillOnProjectCompletion']==1) { $BillOnProjectCompletion = 'checked'; } if ($_GET['MaxHours']) { $MaxHours = intval($_GET['MaxHours']); } if ($_GET['flat_rate']==1) { $flat_rate = " checked"; } echo "
Client Name
"; if (!$options['remove_embargo']) { echo " "; } echo ""; echo "
Select Client:"; $this->GetClient(); echo "
Project Name:
Is Retainer Project
Max Project Hours:
Active / Visable
Bill at end of project
Flat rate billing project Bypasses invoicing queue for this project
Notes:
"; echo ""; echo "
"; } function SaveNewProject() { if ($this->ValidateProject(true)==false) { return; } global $wpdb; $db = new time_sheets_db(); if ($_GET['IsRetainer']) { $IsRetainer=1; } else { $IsRetainer=0; } if ($_GET['MaxHours']) { $MaxHours = intval($_GET['MaxHours']); } else { $MaxHours = 0; } if ($_GET['Active']) { $Active = 1; } else { $Active = 0; } if ($_GET['flat_rate']) { $flat_rate = 1; } else { $flat_rate = 0; } if ($_GET['BillOnProjectCompletion']) { $BillOnProjectCompletion = 1; } else { $BillOnProjectCompletion = 0; } $sql = "INSERT INTO {$wpdb->prefix}timesheet_client_projects (ClientId, ProjectName, IsRetainer, MaxHours, HoursUsed, Active, Notes, BillOnProjectCompletion, flat_rate) values (%d, %s, %d, %d, %d, %d, %s, %d, %d)"; $parms = array(intval($_GET['ClientId']), sanitize_text_field($_GET['ProjectName']), $IsRetainer, $MaxHours, 0, $Active, sanitize_textarea_field($_GET['notes']), $BillOnProjectCompletion, $flat_rate); $db->query($sql, $parms); echo '

Project added.

'; } function ValidateProject($existsCheck) { global $wpdb; $db = new time_sheets_db(); $valid = true; if (!$_GET['ClientId']) { echo '

The selected client is invalid.

'; $valid=false; } if (!$_GET['ProjectName']) { echo '

The name of the project is required.

'; $valid=false; } if ($_GET['IsRetainer']) { if ($_GET['ProjectId']) { $sql = "select * from {$wpdb->prefix}timesheet_client_projects where ClientId=%d and IsRetainer=1 and ProjectId<>%d"; $parms = array(intval($_GET['ClientId']), intval($_GET['ProjectId'])); } else { $sql = "select * from {$wpdb->prefix}timesheet_client_projects where ClientId=%d and IsRetainer=1"; $parms = array(intval($_GET['ClientId'])); } $project = $db->get_row($sql, $parms); if ($project) { echo "

There is already a retainer project for this client. Change the retainer status for '{$project->ProjectName}' to correct this.

"; $valid=false; } } if ($existsCheck==true) { $sql = "select count(*) from {$wpdb->prefix}timesheet_client_projects where ClientId=%d and ProjectName=%s"; $params = array(intval($_GET['ClientId']), intval($_GET['ProjectName'])); $ct = $db->get_var($sql, $params); if ($ct!=0) { echo '

This project already exists for this client.

'; $valid=false; } } return $valid; } function EditProject() { global $wpdb; $db = new time_sheets_db(); $common = new time_sheets_common(); $options = get_option('time_sheets'); if ($_GET['subaction']=='Save Project') { $this->SaveExistingProject(); } $this->GetProjects(); echo " "; if ($_GET['action']=='Select Project') { $project = $db->get_row("select * from {$wpdb->prefix}timesheet_client_projects tcp where ProjectId=%d order by ProjectName", array(intval($_GET['ProjectId']))); if ($project->IsRetainer==1) { $IsRetainer=" checked"; $DisableHours="disabled"; } if ($project->Active==1) { $Active=" checked"; } if ($project->BillOnProjectCompletion==1) { $BillOnProjectCompletion = " checked"; } if ($project->flat_rate==1) { $flat_rate = " checked"; } $hoursused = $project->MaxHours-$project->HoursUsed; echo ""; if (!$options['remove_embargo']) { echo " "; } echo "
Select Client:"; $this->GetClient(); echo "
Project Name:
Project Name:
Is Retainer Project
Max Project Hours:
Hours Used:{$project->HoursUsed}
Hours Remaining:{$hoursused}
Notes:
Bill on project completion
Active / Visable
Flat rate billing project Bypasses invoicing queue for this project
"; if ($DisableHours) { echo ""; } echo " "; } } function SaveExistingProject() { if ($this->ValidateProject(false)==false) { return; } global $wpdb; $db = new time_sheets_db(); if ($_GET['IsRetainer']) { $IsRetainer=1; } else { $IsRetainer=0; } if ($_GET['MaxHours']) { $MaxHours = intval($_GET['MaxHours']); } else { $MaxHours = 0; } if ($_GET['Active']) { $Active = 1; } else { $Active = 0; } if ($_GET['BillOnProjectCompletion']) { $BillOnProjectCompletion = 1; } else { $BillOnProjectCompletion = 0; } if ($_GET['flat_rate']) { $flat_rate = 1; } else { $flat_rate = 0; } $sql = "UPDATE {$wpdb->prefix}timesheet_client_projects SET ClientId=%d, ProjectName=%s, IsRetainer=%d, MaxHours=%d, Active=%d, Notes=%s, BillOnProjectCompletion=%d, flat_rate = %d WHERE ProjectId=%d"; $parms = array(intval($_GET['ClientId']), sanitize_text_field($_GET['ProjectName']), $IsRetainer, $MaxHours, $Active, sanitize_textarea_field($_GET['notes']), $BillOnProjectCompletion, $flat_rate, intval($_GET['ProjectId']) ); $db->query($sql, $parms); echo '

Project updated.

'; } function GetClient() { global $wpdb; $db = new time_sheets_db(); $user_id = get_current_user_id(); $common = new time_sheets_common(); $clients = $db->get_results(" select ClientName, tc1.ClientId from {$wpdb->prefix}timesheet_clients tc1 order by ClientName"); echo ""; } function GetProjects() { global $wpdb; $db = new time_sheets_db(); $user_id = get_current_user_id(); $common = new time_sheets_common(); $projects = $db->get_results("select tcp.ClientId, ProjectId, concat(ProjectName, case when Active = 0 then ' (Inactive)' else ' (Active)' end) as ProjectName from {$wpdb->prefix}timesheet_client_projects tcp order by Active desc, ProjectName"); foreach ($projects as $project) { $project->ProjectName = $common->clean_from_db($project->ProjectName); $clean_projects[] = $project; } $js_projects = json_encode($clean_projects); echo ""; } }