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

"; IF (isset($_GET['ClientId'])) { echo ""; } elseif (isset($_POST['ClientId'])) { echo ""; } if (($client_managers->client_manager_check()==1) || ($approver==1)) { echo "   "; } if (($client_managers->client_manager_check()==1) || ($approver==1)) { echo "  "; } echo "
"; if (isset($_GET['menu'])) { if ($_GET['menu']=='New Client') { $this->add_client(); } if ($_GET['menu']=='Edit Client') { $this->add_client_users(); } 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(); } if ($_GET['menu'] == 'title_override') { $this->title_override(); } } } function check_unique_project_name ($client_id, $project_id, $project_name) { global $wpdb; $db = new time_sheets_db(); $sql = "select ProjectId from {$wpdb->prefix}timesheet_client_projects where ClientId = %d and ProjectName = %s and ProjectId <> %d"; $params = array($client_id, $project_name, $project_id); $projects = $db->get_results ($sql, $params); $return = ''; if ($projects) { $return = '

The project name has already been used by another project for this client.

'; } $sql = "select ProjectId from {$wpdb->prefix}timesheet_client_projects_changequeue where ClientId = %d and ProjectName = %s and ProjectId <> %d and is_processed = 0"; $params = array($client_id, $project_name, $project_id); $projects = $db->get_results ($sql, $params); if ($projects) { $return = $return . '

The project name is queued for use by another project for this client.

'; } return $return; } function update_employee_to_title_with_expiration($project_id) { global $wpdb; $db = new time_sheets_db(); $common = new time_sheets_common(); $settings = new time_sheets_settings(); $nonce = check_admin_referer('match_employee_to_title'); $users = $settings->get_employee_list($project_id); if ($users) { foreach ($users as $user) { if ($_POST["user_{$user->ID}"] != '' && ($user->title_id != $_POST["user_{$user->ID}"])){ $expiration_date = (($_POST["employee_expiration_{$user->ID}"]!='')?"'".$common->mysql_date($_POST["employee_expiration_{$user->ID}"])."'":"NULL"); $sql = "insert into {$wpdb->prefix}timesheet_customer_project_employee_title_override (user_id, project_id, title_id, expiration_date) values (%d, %d, %d, {$expiration_date}) on duplicate key update title_id = %d, expiration_date = {$expiration_date}"; $params = array($user->ID, $project_id, intval($_POST["user_{$user->ID}"]), intval($_POST["user_{$user->ID}"])); } else { $sql = "delete from {$wpdb->prefix}timesheet_customer_project_employee_title_override where user_id = %d and project_id = %d"; $params = array($user->ID, $project_id); } $db->query($sql, $params); } } } function title_override() { global $wpdb; $db = new time_sheets_db(); $settings = new time_sheets_settings(); $inputs = array( 'page' => 'timesheet_manage_clients', 'menu' => 'title_override', 'ClientId' => intval($_GET['ClientId']), 'ProjectId' => intval($_GET['ProjectId']) ); if (isset($_POST['action'])) { if ($_POST['action'] == "Save Mappings") { $this->update_employee_to_title_with_expiration($inputs['ProjectId']); } } $settings->match_employee_to_title(TRUE, $inputs); } function view_timesheets_for_project(){ $db = new time_sheets_db(); global $wpdb; $user = wp_get_current_user(); $user_id = $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 add_client_users() { $db = new time_sheets_db(); $common = new time_sheets_common(); global $wpdb; $user = wp_get_current_user(); $user_id = $user->ID; if (isset($_POST['ClientId']) && isset($_POST['action']) && $_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 (isset($_POST[$id])) { $sql = "select * from {$wpdb->prefix}timesheet_clients_users where ClientId = %d and user_id = %d"; $parms = array(intval($_POST['ClientId']), $user->ID); unset($u); $u= $db->query($sql, $parms); if (!$u) { $sql = "INSERT IGNORE INTO {$wpdb->prefix}timesheet_clients_users set ClientId=%d, user_id=%d"; $db->query($sql, $parms); $common->archive_records ('timesheet_clients_users', 'timesheet_clients_users_archive', "user_id = {$user->ID} and ClientId", intval($_POST['ClientId']), '=', 'INSERTED'); } } else { $common->archive_records ('timesheet_clients_users', 'timesheet_clients_users_archive', "user_id = {$user->ID} and ClientId", intval($_POST['ClientId']), '=', 'DELETED'); $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, sales_person_id = %d, technical_sales_person_id = %d where ClientId = %d"; $parms = array(sanitize_text_field($_POST['ClientName']), intval($_POST['sales_person_id']), intval($_POST['technical_sales_person_id']), intval($_POST['ClientId'])); $db->query($sql, $parms); $common->archive_records ('timesheet_clients', 'timesheet_clients_archive', 'ClientId', intval($_POST['ClientId']), '=', 'UPDATED'); echo '

Client Updated.

'; } echo "
"; echo "
Client Name"; $this->GetClient(); #$clients = $db->get_results("select ClientName, tc.ClientId, tc.sales_person_id # from {$wpdb->prefix}timesheet_clients tc # order by ClientName"); #if ($clients) { # echo ""; #} echo "
"; echo ""; echo "
"; if (isset($_POST['ClientId'])) { $sql = "select u.user_login, u.ID, tcu.user_id cu, u.display_name from {$wpdb->users} u join {$wpdb->prefix}usermeta um on u.id = um.user_id left outer join {$wpdb->prefix}timesheet_clients_users tcu on u.id = tcu.user_id and tcu.ClientId = %d where um.meta_key = '{$wpdb->prefix}capabilities' and um.meta_value != 'a:0:{}' 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 "
"; echo "
Client Name:
Sales Person"; $users1 = $common->return_employee_list(); echo "
Technical Sales Person"; echo "

Employees working on this client
"; 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 = wp_get_current_user(); $user_id = $user->ID; $common = new time_sheets_common(); if (isset($_POST['action']) && $_POST['action']=='save_client' && isset($_POST['ClientName'])) { $ClientId=$db->get_var("select ClientId from {$wpdb->prefix}timesheet_clients where ClientName=%s", array(sanitize_text_field($_POST['ClientName']))); $ClientName = sanitize_text_field($_POST['ClientName']); if (!$ClientId) { $db->query("insert into {$wpdb->prefix}timesheet_clients (ClientName, Active, sales_person_id, technical_sales_person_id) values (%s, 1, %d, %d)", array(sanitize_text_field($_POST['ClientName']), intval($_POST['sales_person_id']), intval($_POST['technical_sales_person_id']))); $common->archive_records ('timesheet_clients', 'timesheet_clients_archive', 'ClientName', "'{$ClientName}'", '=', 'INSERTED'); $ClientId=$db->get_var("select ClientId from {$wpdb->prefix}timesheet_clients where ClientName=%s", array($ClientName)); $sql = "select ID from {$wpdb->users} u"; $users = $db->get_results($sql); foreach ($users as $user) { $id = "user_{$user->ID}"; if (isset($_POST[$id])) { $sql = "insert into {$wpdb->prefix}timesheet_clients_users (ClientId, user_id) values (%d, %d)"; $parms = array($ClientId, $user->ID); $db->query($sql, $parms); $common->archive_records ('timesheet_clients_users', 'timesheet_clients_users_archive', "ClientId = {$ClientId} and user_id", $user->ID, '=', 'INSERTED'); } } echo '

Client Added.

'; } else { $db->query("insert into {$wpdb->prefix}timesheet_clients_users (ClientId, user_id) values ($ClientId, $user_id)"); $common->archive_records ('timesheet_clients_users', 'timesheet_clients_users_archive', 'ClientId = {$ClinetId} and user_id', $user_id, '=', 'INSERTED'); echo '

Client already exists.
Access granted to client.

'; } } echo "
"; 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 (isset($_GET['Active'])) { $Active = 1; } $IsRetainer = ''; $BillOnProjectCompletion = ''; $MaxHours = 0; $flat_rate = ""; $close_on_completion = ""; $retainer_id = 0; $hours_included = ""; $hourly_rate = ""; $max_monthly_budget = 0; if (isset($_GET['action']) && $_GET['action']=='Save Project'){ $this->SaveNewProject(); if (isset($_GET['IsRetainer'])) { $IsRetainer = ' checked'; } if (isset($Active) && $Active==1) { $Active = ' checked'; } if (isset($_GET['BillOnProjectCompletion'])) { $BillOnProjectCompletion = ' checked'; } if (isset($_GET['MaxHours'])) { $MaxHours = intval($_GET['MaxHours']); } if (isset($_GET['flat_rate'])) { $flat_rate = " checked"; } if (isset($_GET['close_on_completion']) || isset($options['default_auto_close'])) { $close_on_completion = " checked"; } if(isset($_GET['retainer_id'])) { $retainer_id = intval($_GET['retainer_id']); $hours_included = intval($_GET['hours_included']); $hourly_rate = intval($_GET['hourly_rate']); } if (isset($_GET['max_monthly_budget'])) { $max_monthly_budget = intval($_GET['max_monthly_budget']); } } else { $Active = ' checked'; $close_on_completion = " checked"; } $ProjectName = isset($_GET['ProjectName']) ? $common->esc_textarea($_GET['ProjectName']) : ""; $PONumber = isset($_GET['po_number']) ? $common->esc_textarea($_GET['po_number']) : ""; echo "
Client Name
Sales Person"; $users = $common->return_employee_list(); echo "
Technical Sales Person"; echo "
Employees working on this client
"; $sql = "select u.user_login, u.ID, u.display_name from {$wpdb->users} u order by u.display_name"; $users = $db->get_results($sql); echo ""; foreach ($users as $user) { echo ""; } echo "
 User NameUser
{$user->user_login}{$user->display_name}
"; echo "
"; echo ""; $sql = "select retainer_name, retainer_id from {$wpdb->prefix}timesheet_custom_retainer_frequency where active = 1"; $frequencies = $db->get_results($sql); echo ""; if (!isset($options['remove_embargo'])) { echo " "; } echo ""; echo ""; $Notes = isset($_GET['Notes']) ? $common->esc_textarea($_GET['notes']) : ""; echo "
Select Client:"; $this->GetClient(); echo "
Project Name:
PO Number:
Sales Person:"; $users = $common->return_employee_list(); echo "
Technical Sales Person:"; echo "
"; if (isset($options['allow_money_based_retainers'])) { echo ""; } echo " "; if (isset($options['allow_money_based_retainers'])) { echo ""; $sql = "select e.* from {$wpdb->prefix}timesheet_employee_titles e order by e.name"; $titles = $db->get_results($sql); $valign = count((array)$titles)+1; } else { $valign = 1; } echo ""; if (isset($options['allow_money_based_retainers'])) { if ($titles) { foreach ($titles as $title) { echo ""; } } } echo "
Is Retainer Project
Retainer Type: Retainer Interval
Retainer Hours Max Project Frequency Budget{$options['currency_char']}
test
Retainer Rate
Rate for {$title->name}:{$options['currency_char']}
Max Project Hours:
Active / Visable
Bill at end of project
Flat rate billing project Bypasses invoicing queue for this project
Auto close project when project is out of hours
Notes:
"; echo ""; echo "
"; $this->ProjectJS(); } function SaveNewProject() { if ($this->ValidateProject(true)==false) { return; } global $wpdb; $db = new time_sheets_db(); $user = wp_get_current_user(); $options = get_option('time_sheets'); $common = new time_sheets_common(); if (isset($_GET['IsRetainer'])) { $IsRetainer=1; $retainer_id = $_GET['retainer_id']; $hours_included = $_GET['hours_included']; $hourly_rate = $_GET['hourly_rate']; } else { $IsRetainer=0; $retainer_id=""; $hours_included="0"; $hourly_rate="0"; } if (isset($_GET['MaxHours'])) { $MaxHours = intval($_GET['MaxHours']); } else { $MaxHours = 0; } if (isset($_GET['Active'])) { $Active = 1; } else { $Active = 0; } if (isset($_GET['flat_rate'])) { $flat_rate = 1; } else { $flat_rate = 0; } if (isset($_GET['BillOnProjectCompletion'])) { $BillOnProjectCompletion = 1; } else { $BillOnProjectCompletion = 0; } if (isset($_GET['close_on_completion']) && $_GET['close_on_completion']==1) { $close_on_completion = "1"; } else { $close_on_completion = "0"; } if (isset($_GET['max_monthly_budget'])) { $max_monthly_budget = intval($_GET['max_monthly_budget']); } else { $max_monthly_budget = 0; } if (isset($options['require_unique_project_names'])) { $msg = $this->check_unique_project_name (intval($_GET['ClientId']), 0, sanitize_text_field($_GET['ProjectName'])); if ($msg <> '') { echo $msg; return; } } $sql = "INSERT INTO {$wpdb->prefix}timesheet_client_projects (ClientId, ProjectName, IsRetainer, MaxHours, HoursUsed, Active, Notes, BillOnProjectCompletion, flat_rate, po_number, sales_person_id, technical_sales_person_id, close_on_completion, retainer_id, hours_included, hourly_rate, max_monthly_bucket) values (%d, %s, %d, %d, %d, %d, %s, %d, %d, %s, %d, %d, %d, %d, %d, %d, %d)"; $parms = array(intval($_GET['ClientId']), sanitize_text_field($_GET['ProjectName']), $IsRetainer, $MaxHours, 0, $Active, sanitize_textarea_field($_GET['notes']), $BillOnProjectCompletion, $flat_rate, sanitize_text_field($_GET['po_number']), intval($_GET['sales_person_id']), intval($_GET['technical_sales_person_id']), $close_on_completion, $retainer_id, $hours_included, $hourly_rate, $max_monthly_budget); $db->query($sql, $parms); $sql = "select max(ProjectId) project_id from {$wpdb->prefix}timesheet_client_projects"; $project = $db->get_row($sql); $common->archive_records ('timesheet_client_projects', 'timesheet_client_projects_archive', 'ProjectId', $project->project_id, '=', 'INSERTED'); if (isset($options['allow_money_based_retainers'])) { $this->write_title_rates($project->project_id); } echo "

Project added. project_id}&action=Select+Project'>Edit Project

"; } function ValidateProject($existsCheck) { global $wpdb; $db = new time_sheets_db(); $options = get_option('time_sheets'); $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 (isset($_GET['IsRetainer']) && !isset($options['retainers_per_client'])) { 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 (isset($_GET['subaction']) && $_GET['subaction']=='Save Project') { $this->SaveExistingProject(); } if (isset($_GET['subaction']) && $_GET['subaction']=='delete_queue') { $this->DeleteProjectChangeQueue(intval($_GET['ProjectId']), intval($_GET['queue_id'])); } $this->GetProjects(); echo " "; if (isset($_GET['action']) && $_GET['action']=='Select Project') { if (isset($_GET['subaction']) && $_GET['subaction']=='view_queue') { $project = $db->get_row("select * from {$wpdb->prefix}timesheet_client_projects_changequeue tcp where ProjectId=%d and queue_id=%d order by ProjectName", array(intval($_GET['ProjectId']), intval($_GET['queue_id']))); $process_date = $project->process_date; } else { $project = $db->get_row("select * from {$wpdb->prefix}timesheet_client_projects tcp where ProjectId=%d order by ProjectName", array(intval($_GET['ProjectId']))); $process_date = ''; } $IsRetainer = ''; $Active = ''; $BillOnProjectCompletion = ''; $flat_rate = ''; $close_on_completion = ''; if ($project->IsRetainer==1) { $IsRetainer=" checked"; $retainer_id = $project->retainer_id; $hours_included = $project->hours_included; $hourly_rate = $project->hourly_rate; $max_monthly_budget = $project->max_monthly_bucket; } else { $hours_included = ""; $hourly_rate = ""; $max_monthly_budget = 0; } if ($project->Active==1) { $Active=" checked"; } if ($project->BillOnProjectCompletion==1) { $BillOnProjectCompletion = " checked"; } if ($project->flat_rate==1) { $flat_rate = " checked"; } if ($project->close_on_completion==1) { $close_on_completion = " checked"; } $hoursused = (isset($project->HoursUsed)?$project->HoursUsed:0); $hoursleft = $project->MaxHours-(isset($project->HoursUsed)?$project->HoursUsed:0); echo ""; echo ""; $sql = "select retainer_name, retainer_id from {$wpdb->prefix}timesheet_custom_retainer_frequency where active = 1"; $frequencies = $db->get_results($sql); echo " "; if (!isset($options['remove_embargo'])) { echo " "; } echo "
Select Client:"; $this->GetClient(); echo "
Project Name:
Project Name:
PO Number:
Sales Person:"; $users = $common->return_employee_list(); echo "
Technical Sales Person:"; echo "
"; if (isset($options['allow_money_based_retainers'])) { echo ""; } echo " "; if (isset($options['allow_money_based_retainers'])) { echo ""; $sql = "select e.*, p.hourly_rate from {$wpdb->prefix}timesheet_employee_titles e left outer join {$wpdb->prefix}timesheet_project_employee_titles p on e.title_id = p.title_id and p.project_id = $project->ProjectId order by e.name"; $titles = $db->get_results($sql); $valign = count((array)$titles)+1; } else { $valign = 1; } echo ""; if (isset($options['allow_money_based_retainers'])) { if ($titles) { foreach ($titles as $title) { echo ""; } } } echo "
Is Retainer Project
Retainer Type: Retainer Interval
Retainer Hours Max Project Frequency Budget{$options['currency_char']}
Retainer Rate
Rate for {$title->name}:{$options['currency_char']}
Max Project Hours:
Hours Used:{$hoursused}
Hours Remaining:{$hoursleft}
Bill on project completion (Timesheets are hidden and not processed by the approval queue until a timesheet is submitted with 'Project Completed' selected)
Active / Visable
Flat rate billing project Bypasses invoicing queue for this project
Auto close project when
project is out of hours
Notes:
Delay Change Until:
"; echo ""; $this->ProjectJS(); $this->ShowProjectChangeQueue($_GET['ProjectId']); $this->ShowProjectRetainerHistory($_GET['ProjectId']); } } function ProjectJS() { global $wpdb; $db = new time_sheets_db(); $common = new time_sheets_common(); $options = get_option('time_sheets'); $sql = "select title_id from {$wpdb->prefix}timesheet_employee_titles e"; $titles = $db->get_results($sql); echo " "; } function DeleteProjectChangeQueue($project_id, $queue_id) { global $wpdb; $db = new time_sheets_db(); $common = new time_sheets_common(); $options = get_option('time_sheets'); $sql = "select * from {$wpdb->prefix}timesheet_client_projects_changequeue where queue_id = %s"; $parms = array($queue_id); $queue_record = $db->get_row($sql, $parms); if ($queue_record->ProjectId != $project_id) { echo '

Unable to delete queued record, incorrect project specified or no record found.

'; } else { $common->archive_records ('timesheet_project_employee_titles_changequeue', 'timesheet_project_employee_titles_change_archive', "queue_id", $queue_id, '=', 'DELETED'); $sql = "delete from {$wpdb->prefix}timesheet_project_employee_titles_changequeue where queue_id = %d"; $parms = array($queue_id); $db->query($sql, $parms); $common->archive_records ('timesheet_client_projects_changequeue', 'timesheet_client_projects_changequeue_archive', "queue_id", $queue_id, '=', 'DELETED'); $sql = "delete from {$wpdb->prefix}timesheet_client_projects_changequeue where queue_id = %d"; $db->query($sql, $parms); echo '

Project change queue record deleted.

'; } } function ShowProjectRetainerHistory($project_id) { global $wpdb; $db = new time_sheets_db(); $common = new time_sheets_common(); $options = get_option('time_sheets'); $currency_char = isset($options['currency_char'])?$options['currency_char']:'$'; $project_id = intval($project_id); if (!isset($options['allow_recurring_timesheets'])) { return 0; } $sql = "select mu.*, cr.retainer_name from {$wpdb->prefix}timesheet_project_retainer_money_usage mu left outer join {$wpdb->prefix}timesheet_custom_retainer_frequency cr on mu.retainer_id = cr.retainer_id where project_id = {$project_id} order by frequency_start_date ASC"; $info = $db->get_results($sql); if ($info) { echo "

"; foreach ($info as $inf) { $bgcolor= ($inf->used_amount == $inf->max_frequency_bucket)?' bgcolor=yellow ':''; $bgcolor= ($inf->used_amount > $inf->max_frequency_bucket)?' bgcolor=red style=color:white':''; if (!isset($inf->retainer_name)) { if ($inf->retainer_id==1) { $retainer = 'Monthly'; } elseif ($inf->retainer_id==2) { $retainer = 'Weekly'; } elseif ($inf->retainer_id==3) { $retainer = 'Quarterly'; } } else { $retainer = $inf->retainer_name; } echo "{$currency_char}{$inf->used_amount}"; } } echo "
Period Start DateRetainer DescriptionPeriod AmountAmount Used
{$common->mysql_date($inf->frequency_start_date)}{$retainer}{$currency_char}{$inf->max_frequency_bucket}

* If there are no time sheets for the interval, than there will be no record."; } function ShowProjectChangeQueue($project_id) { global $wpdb; $db = new time_sheets_db(); $common = new time_sheets_common(); $options = get_option('time_sheets'); $project_id = intval($project_id); $sql = "select * from {$wpdb->prefix}timesheet_client_projects_changequeue where ProjectId = $project_id and is_deleted = 0 order by process_date ASC"; $queue = $db->get_results($sql); if ($queue) { echo ""; foreach ($queue as $project) { $retainer = ($project->IsRetainer==0 ? 'False':'True'); $active = ($project->Active==0 ? 'False':'True'); $close = ($project->close_on_completion==0 ? 'False':'True'); echo ""; } echo "
ActionsProcess OnProject NameRetainerMax HoursActivePO NumberClose On CompletionRetainer HoursRetainer Rate
"; echo "queue_id}'>"; echo "  "; if ($project->is_processed == 0) { echo "queue_id}'>"; } echo "{$project->process_date}{$project->ProjectName}{$retainer}{$project->MaxHours}{$active}{$project->po_number}{$close }{$project->hours_included}{$project->hourly_rate}
"; } else { echo "No changes queued"; } } function SaveExistingProject() { if ($this->ValidateProject(false)==false) { return; } global $wpdb; $user = wp_get_current_user(); $common = new time_sheets_common(); $db = new time_sheets_db(); $options = get_option('time_sheets'); if (isset($_GET['IsRetainer'])) { $IsRetainer=1; } else { $IsRetainer=0; } if (isset($_GET['MaxHours'])) { $MaxHours = intval($_GET['MaxHours']); } else { $MaxHours = 0; } if (isset($_GET['Active'])) { $Active = 1; } else { $Active = 0; } if (isset($_GET['BillOnProjectCompletion'])) { $BillOnProjectCompletion = 1; } else { $BillOnProjectCompletion = 0; } if (isset($_GET['flat_rate'])) { $flat_rate = 1; } else { $flat_rate = 0; } if (isset($_GET['close_on_completion']) && $_GET['close_on_completion']==1) { $close_on_completion = "1"; } else { $close_on_completion = "0"; } if (isset($options['require_unique_project_names'])) { $msg = $this->check_unique_project_name (intval($_GET['ClientId']), intval($_GET['ProjectId']), sanitize_text_field($_GET['ProjectName'])); if ($msg <> '') { echo $msg; return; } } if (isset($_GET['process_date']) && $_GET['process_date'] != "") { if ($_GET['process_date'] < date('Y-m-d H:i:s')) { echo '

Project change canceled. Future date required.

'; } else { $sql = "insert into {$wpdb->prefix}timesheet_client_projects_changequeue (process_date, ProjectId, ClientId, ProjectName, IsRetainer, MaxHours, Active, notes, BillOnProjectCompletion, flat_rate, po_number, sales_person_id, technical_sales_person_id, close_on_completion, retainer_id, hours_included, hourly_rate, is_processed, is_deleted, max_monthly_bucket) values (%s, %d, %d, %s, %d, %d, %d, %s, %d, %d, %s, %d, %d, %d, %d, %d, %d, 0, 0, %d)"; $parms = array(sanitize_text_field($_GET['process_date']), intval($_GET['ProjectId']), intval($_GET['ClientId']), sanitize_text_field($_GET['ProjectName']), $IsRetainer, $MaxHours, $Active, sanitize_textarea_field($_GET['notes']), $BillOnProjectCompletion, $flat_rate, sanitize_text_field($_GET['po_number']), intval($_GET['sales_person_id']), intval($_GET['technical_sales_person_id']), $close_on_completion, intval($_GET['retainer_id']), intval($_GET['hours_included']), intval($_GET['hourly_rate']), intval($_GET['max_monthly_budget']) ); $db->query($sql, $parms); if (isset($options['allow_money_based_retainers'])) { $sql = "select max(queue_id) queue_id from {$wpdb->prefix}timesheet_client_projects_changequeue where ProjectId = %d and process_date = %s"; $parms = array(intval($_GET['ProjectId']), $_GET['process_date']); $queue = $db->get_row($sql, $parms); if ($queue) { $sql = "select * from {$wpdb->prefix}timesheet_employee_titles"; $titles = $db->get_results($sql); if ($titles) { foreach ($titles as $title) { $project_id = intval($_GET['ProjectId']); $sql = "insert into {$wpdb->prefix}timesheet_project_employee_titles_changequeue (queue_id, project_id, title_id, hourly_rate) values (%d, %d, %d, %d)"; $parms = array($queue->queue_id, $project_id, $title->title_id, intval($_GET['title_'.$title->title_id])); $db->query($sql, $parms); $common->archive_records ('timesheet_project_employee_titles_changequeue', 'timesheet_project_employee_titles_change_archive', "queue_id = {$queue->queue_id} and project_id = {$project_id} and title_id", $title->title_id, '=', 'INSERTED'); } } } } echo '

Project change queued.

'; } } else { if (isset($_GET['IsRetainer'])) { $sql = "select MaxHours from {$wpdb->prefix}timesheet_client_projects where ProjectId = %d"; $pamrs = array(intval($_GET['ProjectId'])); $project = $db->get_row($sql, $pamrs); $MaxHours = $project->MaxHours; } $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, po_number = %s, sales_person_id = %d, technical_sales_person_id = %d, close_on_completion = %d, retainer_id = %d, hours_included = %d, hourly_rate = %d, max_monthly_bucket = %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, sanitize_text_field($_GET['po_number']), intval($_GET['sales_person_id']), intval($_GET['technical_sales_person_id']), $close_on_completion, isset($_GET['retainer_id'])?intval($_GET['retainer_id']):0, isset($_GET['hours_included'])?intval($_GET['hours_included']):0, isset($_GET['hourly_rate'])?intval($_GET['hourly_rate']):0, isset($_GET['max_monthly_budget'])?intval($_GET['max_monthly_budget']):0, intval($_GET['ProjectId']) ); $db->query($sql, $parms); $common->archive_records ('timesheet_client_projects', 'timesheet_client_projects_archive', 'ProjectId', intval($_GET['ProjectId']), '=', 'UPDATED'); if (isset($options['allow_money_based_retainers'])) { $this->write_title_rates(intval($_GET['ProjectId'])); } echo '

Project updated.

'; } if ($close_on_completion == 0) { $sql = "delete from {$wpdb->prefix}timesheet_client_project_autoclose where project_id = %d"; $parms = array(intval($_GET['ProjectId'])); $db->query($sql, $parms); echo '

Any queued close requests of this project has been deleted.

'; } } function write_title_rates($project_id) { global $wpdb; $db = new time_sheets_db(); $common = new time_sheets_common(); $sql = "select * from {$wpdb->prefix}timesheet_employee_titles"; $titles = $db->get_results($sql); $common->archive_records ('timesheet_project_employee_titles', 'timesheet_project_employee_titles_archive', "project_id", intval($project_id), '=', 'DELETED'); $sql = "delete from {$wpdb->prefix}timesheet_project_employee_titles where project_id = %d"; $parms = array(intval($project_id)); $db->query($sql, $parms); if ($titles && isset($_GET['IsRetainer'])) { foreach ($titles as $title) { if (!isset($_GET['title_'.$title->title_id])) { $hourly_rate = 0; } else { $hourly_rate = $_GET['title_'.$title->title_id]; } $sql = "insert into {$wpdb->prefix}timesheet_project_employee_titles (project_id, title_id, hourly_rate) values (%d, %d, %d)"; $parms = array(intval($project_id), $title->title_id, $hourly_rate); $db->query($sql, $parms); $common->archive_records ('timesheet_project_employee_titles', 'timesheet_project_employee_titles_archive', "title_id = {$title->title_id} and project_id", intval($project_id), '=', 'INSERTED'); } } } function GetClient() { global $wpdb; $db = new time_sheets_db(); $user = wp_get_current_user(); $user_id = $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 = wp_get_current_user(); $user_id = $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 ""; } }