class list_jobs_reports extends listing
{
public $status;
public $order;
public $method;
public $group_id;
public $department_id;
public $table;
public $avail_status;
public $avail_edit;
public $link_view;
public $link_edit;
public $db_name;
public $account_id;
public function __construct($context)
{
parent::set_data($context);
$this->status = $context['status'];
$this->client_id = $context['client_id'];
$this->method = (empty($context['list_config']['method'])) ? "id" : $context['list_config']['method'];
}
public function get_data()
{
global $database;
$status = $this->status;
$client_id = $this->client_id;
$where_sql = "";
$where_sql .= (!empty($status)) ? "status = '$status' AND" : "";
$where_sql .= (!empty($client_id)) ? "client_id = '$client_id' AND" : "";
$where_sql = (!empty($where_sql)) ? "WHERE ".substr($where_sql,0,strlen($where_sql) - 4) : "";
$get_request = "
SELECT *
FROM $db_name"."jobs
$where_sql
";
$results = $database->getAll($get_request);
$status_name = common_ref_status::get_status("jobs");
$users = common_users::get_all_names_link();
$locations = common_location::get_locations();
$quote_types = common_quotes::get_all_quotes();
$job_type[0] = "Single Site";
$job_type[1] = "Single Site";
$job_type[2] = "Multi Site";
$job_type[3] = "LED Media";
$job_type[4] = "Cost Plus";
$priorities[0] = "Medium";
$priorities[1] = "High";
$priorities[2] = "Medium";
$priorities[3] = "Low";
$context_workflow = array(
"readonly" => false,
"show_all" => true
);
$context_workflow['table'] = 'jobs';
$context_workflow['list_config'] = array(
"method" => "date_created",
"order" => $_GET['order'],
"avail_edit" => false,
"avail_status" => false,
"link_view" => "",
"link_edit" => "",
"show_search" => false,
"show_pagination" => false,
"sortable" => false
);
$return_results = array();
foreach($results AS $result)
{
$result['client_name'] = common_ref_client::get_client_name($result['client_id']);
$result['site_location'] = $locations[$result['location_id']]['name'];
$result['submitter'] = $users[$result['submitter']];
$result['job_type'] = $job_type[$quote_types[$result['quote_id']]['name']];
$result['star'] = ($result['parent_job'] == 1) ? "*" : "";
$result['priority'] = $priorities[$result['priority']];
$result['status_name'] = $status_name[$result['status']]['name'];
$stat = "";
$stat_count = 1;
$context_workflow['foreign_id'] = $result['id'];
$context_workflow['foreign_status'] = $result['status'];
$context_workflow['status'] = 0;
$result['departments'] = "";
$allocate_to = "";
$tasks = new list_workflow_tasks($context_workflow);
$tasks->get_data();
$tasks_list = $tasks->final_results;
if(count($tasks_list) > 0)
foreach($tasks_list AS $task)
{
$stat .= $stat_count.".".$task['description']." - task
";
$result['departments'] .= $task['department'].",";
$allocate_to .= (!empty($task['allocate_link'])) ? $task['allocate_link']."," : $task['owner'].",";
$stat_count++;
}
$context_workflow['status'] = 1;
$context_workflow['main_status'] = 0;
$approvals = new list_workflow_tasks_approvals($context_workflow);
$approvals->get_data();
$approval_list = $approvals->final_results;
if(count($approval_list) > 0)
foreach($approval_list AS $approval)
{
$stat .= $stat_count.".".$approval['description']." - approval
";
$result['departments'] .= $approval['department'].",";
$allocate_to .= $approval['owner'].",";
$stat_count++;
}
$context_workflow['direction'] = "";
$actions = new list_workflow_actions($context_workflow);
$actions->get_data();
$action_list = $actions->final_results;
if(count($action_list) > 0)
foreach($action_list AS $action)
{
$stat .= $stat_count.".".$action['description']." - decision
";
$result['departments'] .= $action['department'].",";
$allocate_to .= $action['owner'].",";
$stat_count++;
}
$allocate_to = substr($allocate_to,0,strlen($allocate_to) - 1);
$allocate_arr = explode(",",$allocate_to);
$new_allocate_arr = array_unique($allocate_arr);
$result['allocate_to'] = implode(",",$new_allocate_arr);
$result['departments'] = substr($result['departments'],0,strlen($result['departments']) - 1);
$result['workflow_status'] = (empty($stat)) ? "-" : $stat;
$return_results[] = $result;
}
$this->final_results = $return_results;
self::prepare();
return $this;
}
public function list_body()
{
$results = $this->final_results;
$avail_status = $this->avail_status;
$avail_edit = $this->avail_edit;
$link_view = $this->link_view;
$link_edit = $this->link_edit;
$columns = $this->columns;
$sortable = $this->sortable;
$pagination = $this->pagination;
$start = $this->start;
$size = $this->size;
$total_results = $this->total_results;
$max_size = $this->max_size;
$normalise_get = $this->normalise_get;
$new_normalised_results = $this->normalised_results;
$count = 0;
if(count($results) > 0)
{
?>