status = $context['status']; $this->start_date = $context['start_date']; $this->end_date = $context['end_date']; $this->install_type = $context['install_type']; $this->material_type= $context['material_type']; $this->labour_type = $context['labour_type']; $this->financial_type = $context['financial_type']; $this->in_production = $context['in_production']; $this->method = (empty($context['list_config']['method'])) ? "id" : $context['list_config']['method']; } public function search($ids) { global $database; $ids_sql = ""; if(count($ids) > 0) { foreach($ids AS $value) $ids_sql .= "'".$value['id']."',"; $ids_sql = "(".substr($ids_sql,0, strlen($ids_sql) - 1).")"; } $get_request = " SELECT * FROM $db_name"."jobs WHERE id IN $ids_sql "; $results = $database->getAll($get_request); $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"; $job_type[5] = "Quick Job"; $priorities[0] = "Medium"; $priorities[1] = "High"; $priorities[2] = "Medium"; $priorities[3] = "Low"; $return_results = array(); $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']]; $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; } //bug::bug_array('',$return_results); $this->final_results = $return_results; self::prepare(); return $this; } public function get_data() { global $database; $status = $this->status; /** pagination */ $sql ="SELECT count(*) as total FROM jobs where jobs.status ='$status'"; $num_results = $database->getOne($sql); $this->pages = new paginator('jobs'); $this->pages->items_total = $num_results; $this->pages->mid_range = 9; $this->pages->paginate(); /** Kai 23/10/2012 * * get jobs based on the uri, no date specified means normal job page, date passed to this page means data from * */ $where = ""; if(!empty($this->start_date)&&!empty($this->end_date)){ $start_date = $this->start_date; $end_date = $this->end_date; //$start_date = dates::change_to_sql($start_date)." 00:00:00"; //$end_date = dates::change_to_sql($end_date)." 23:59:59"; $start_date_unix = dates::to_unix($start_date." 00:00:00"); $end_date_unix = dates::to_unix($end_date." 23:59:59"); if($status ==1) $where = "WHERE jobs.status='$status' AND jobs.date_submitted >= '$start_date 00:00:00' AND jobs.date_submitted <= '$end_date 23:59:59'"; else if($status==52) $where = "WHERE jobs.status='$status' AND jobs.date_submitted >= '$start_date 00:00:00' AND jobs.date_submitted <= '$end_date 23:59:59'"; }else{ $where = "WHERE jobs.status='$status'"; } if($status==1&&!empty($this->start_date)&&!empty($this->end_date)){ $sql = "SELECT jobs.* FROM jobs INNER JOIN project_workflow ON project_workflow.foreign_id = jobs.quote_id WHERE project_workflow.table = 'quotes' AND project_workflow.direction = 'yes' AND project_workflow.workflow_id IN (6,360,406,433) AND jobs.status = '1' AND project_workflow.date_submitted >= '$start_date 00:00:00' AND project_workflow.date_submitted <= '$end_date 23:59:59' ORDER BY jobs.date_created DESC "; $results = $database->getAll($sql); }elseif($status==52&&!empty($this->start_date)&&!empty($this->end_date)){ // $sql = " // SELECT jobs.* FROM jobs // LEFT JOIN quotes ON quotes.id = jobs.quote_id // LEFT JOIN project_workflow ON project_workflow.foreign_id = quotes.id // WHERE quotes.status = '3' AND project_workflow.date_submitted >= '$start_date 00:00:00' AND project_workflow.date_submitted <= '$end_date 23:59:59' // AND jobs.status = 52 AND jobs.date_submitted >= '$start_date 00:00:00' AND jobs.date_submitted <= '$end_date 23:59:59' // "; $sql = " SELECT jobs.* FROM jobs WHERE jobs.status = 52 AND jobs.date_submitted >= '$start_date 00:00:00' AND jobs.date_submitted <= '$end_date 23:59:59' ORDER BY jobs.date_created DESC "; $job_results = $database->getAll($sql); $results = array(); foreach($job_results as $r){ $quote_id = $r['quote_id']; if(common_project_tasks::job_has_closed_quote($quote_id)>0){ continue; } $results[]=$r; } }else{ $order = $_GET['order']; $by = $_GET['method']; if($order&&$by){ if( $by == 'job_type' ){ $sql ="SELECT jobs.*, quotes.job_type FROM jobs LEFT JOIN quotes ON jobs.quote_id = quotes.id ".$where." ORDER BY quotes.job_type ".$order." ".$this->pages->limit; } elseif( $by == 'departments' ){ $sql ="SELECT * FROM jobs ".$where." ORDER BY jobs.date_created DESC ".$this->pages->limit; } elseif( $by == 'allocate_to' ){ $sql ="SELECT jobs.*, quotes.sales_alloc FROM jobs LEFT JOIN quotes ON jobs.quote_id = quotes.id ".$where." ORDER BY quotes.sales_alloc ".$order." ".$this->pages->limit; } elseif( $by == 'workflow_status' ){ $sql ="SELECT * FROM jobs ".$where." ORDER BY jobs.date_created DESC ".$this->pages->limit; } else { $sql ="SELECT * FROM jobs ".$where." ORDER BY jobs.".$by." ".$order." ".$this->pages->limit; } }else{ $sql ="SELECT * FROM jobs ".$where." ORDER BY jobs.date_created DESC ".$this->pages->limit; } $results = $database->query($sql); } if($this->in_production==1){ $jobs_in_production = common_workflow::get_production_jobs(); if($jobs_in_production){ foreach($jobs_in_production as $job){ $parent_job = common_jobs::get_parent_job_id($job); if(!$parent_job){ $job_arr[]= $job; } } $job_string = implode(',',$job_arr); $sql ="SELECT * FROM jobs where id IN ($job_string) ORDER BY jobs.date_created DESC ";//.$pages->limit; $results = $database->query($sql); }else{ $results = null; } }elseif($this->in_production==2){ $jobs_in_production = common_workflow::get_production_jobs(); if($jobs_in_production){ foreach($jobs_in_production as $job){ $parent_job = common_jobs::get_parent_job_id($job); if($parent_job){ $job_arr[]= $job; } } $job_string = implode(',',$job_arr); $sql ="SELECT * FROM jobs where id IN ($job_string) ORDER BY jobs.date_created DESC ";//.$pages->limit; $results = $database->query($sql); }else{ $results = null; } } /** Kai 24/10/2012*/ /** make a temp array to filter results array with budget type: 1->on budget 2->under 3->over 4->No*/ if(!empty($this->material_type)){ $filter_array = array(); foreach($results as $key=>$job){ if(common_project_tasks::job_has_closed_quote($job['quote_id'])>0){ continue; } $total_quoted_materials = common_quotes::get_quote_materials_summary($job['quote_id']); $quote_materials = $total_quoted_materials['total_quote']; $job_materials = $total_quoted_materials['total_job']; /** on budget*/ if($this->material_type==1) if($quote_materials == $job_materials) $filter_array[$key] = $job; /** under budget*/ if($this->material_type==2) if($quote_materials > $job_materials) $filter_array[$key] = $job; /** over budget*/ if($this->material_type==3) if($quote_materials < $job_materials) $filter_array[$key] = $job; } $results = $filter_array; } if(!empty($this->install_type)){ $filter_array = array(); foreach($results as $key=>$job){ $quote_id = $job['quote_id']; $job_id = $job['id']; if(common_project_tasks::job_has_closed_quote($quote_id)>0){ continue; } /** quote cost of installation * * external installation, installation labour cost, job contractor supplied price * */ $quote_install = common_installation::get_quote_install($quote_id,$job_id); /** actual cost of installation * * external installation, installation labour cost, job contractor supplied price * */ $job_install = common_installation::get_job_install($quote_id,$job_id); //bug::bug_array('',$job['id'].' - '.$quote_install.'/'.$job_install); $actual_install = common_labours::get_actual_install($quote_id); if(!empty($actual_install)){ if($quote_install ==0 && $job_install ==0 ){ /** quote installation no figure */ if($this->install_type==4) $filter_array[$key] = $job; }else{ /** on budget*/ if($this->install_type==1) if($quote_install == $job_install) $filter_array[$key] = $job; /** under budget*/ if($this->install_type==2) if($quote_install > $job_install) $filter_array[$key] = $job; /** over budget*/ if($this->install_type==3) if($quote_install < $job_install) $filter_array[$key] = $job; } }elseif(empty($actual_install)){ /** actual installation no figure yet*/ if($this->install_type==4) $filter_array[$key] = $job; } } $results = $filter_array; } if(!empty($this->labour_type)){ $filter_array = array(); foreach($results as $key=>$job){ $quote_labour = common_quotes::get_quote_labour_times($job['quote_id']); $job_labour = common_jobs::get_job_tracking_summary($job['id']); if(common_project_tasks::job_has_closed_quote($job['quote_id'])>0){ continue; } if(!empty($quote_labour)){ /** on budget*/ if($this->labour_type==1) if($quote_labour == $job_labour) $filter_array[$key] = $job; /** under budget*/ if($this->labour_type==2) if($quote_labour > $job_labour) $filter_array[$key] = $job; /** over budget*/ if($this->labour_type==3) if($quote_labour < $job_labour) $filter_array[$key] = $job; }else{ if($this->labour_type==3) $filter_array[$key] = $job; } } $results = $filter_array; } /** END Kai 24/10/2012*/ /** * Kai 23/11/2012 * * make a temp array to filter results array: * * 1->awaiting approval 2->work in production 3->work completed 4->work not accepted * * */ if(!empty($this->financial_type)){ $filter_array = array(); /** work In production*/ if($this->financial_type==2){ $jobs_in_production = common_workflow::get_work_in_production($start_date,$end_date); if(!empty($jobs_in_production)){ $temp_jobs = array(); $temp_quotes=array(); foreach($jobs_in_production as $job){ /** some jobs have same production stages, remove redundant job number*/ if(!in_array($job['foreign_id'],$temp_jobs)){ $quote_id = common_jobs::get_quote_number($job['foreign_id']); /** ignore if it's same quote id which means there are child jobs*/ if(!in_array($quote_id,$temp_quotes)){ $temp_quotes[]=$quote_id; } $temp_jobs[] = $job['foreign_id']; } } foreach($results as $key=>$job){ if(in_array($job['id'], $temp_jobs)){ $filter_array[$key] = $job; } } } } $results = $filter_array; } /** End of changes Kai 23/11/2012*/ //$results = common_jobs::get_jobs($status); $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"; $job_type[5] = "Quick Job"; $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']]; $sql = "SELECT count(id) FROM jobs WHERE quote_id =".$result['quote_id']." AND parent_job = 0"; $num_child_jobs = $database->getOne($sql); $total_sales_price = common_quotesheets::get_total_sales($result['quote_id']); if($num_child_jobs>0){ $result['total_sales_price'] = '$'.number_format($total_sales_price['total_sales_price']/$num_child_jobs,2); }else{ $result['total_sales_price'] = '$'.number_format($total_sales_price['total_sales_price'],2); } // $total_sales_price = common_quotesheets::get_total_sales($result['quote_id']); // $result['total_sales_price'] = $total_sales_price['total_sales_price']; $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; // $_SESSION['jobs_list_order'] = $new_normalised_results; $_SESSION['jobs_list'] = array(); if(count($results) > 0) for($i = $start; $i < $max_size; $i++) { $key = $new_normalised_results[$i]; $_SESSION['jobs_list'][] = $results[$key]['id']; } $count = 0; if(count($results) > 0) { ?>edit $value) { if($value['view'] == true) { ?> list_footer(); } return $this; } public function get_data_all() { global $database; //$results =common_jobs::get_all_active_jobs_for_tablet(); $results = common_jobs::get_all_active_jobs_for_tablet_sort_ordering(); $count = 0; $return_results = array(); $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 ); foreach($results AS $result) { $id = $result['id']; $job_id = $result['job_id']; $client_id = $result['client_id']; $client_name = common_clients::get_client_name($client_id); $job_name = $result['job_name']; $job_number = $result['job_number']; $description = $result['description']; $location_id = $result['location_id']; $stage_id = $result['stage_id']; $depts = explode(':',$result['department_id']); $dept_id = $result['department_id']; $ordering = $result['ordering']; $is_ptp = $result['is_ptp']; $status = explode(':',$result['status']); $cnt= count($status); $dept_array=array_map(null,$depts,$status); $submitter = $result['submitter']; $date_submitted = $result['date_submitted']; $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
"; $depts[] = $task['department']; $allocate_to .= (!empty($task['allocate_link'])) ? $task['allocate_link']."," : $task['owner'].","; $stat_count++; } $array=array(); foreach($depts AS $dept) { if($dept == "Production") { $return_results[] = array( "id" => $id, "client_id" => $client_id, "client_name" => $client_name, "department_id" => $department_id, "dept_id" => $dept_id, "job_id" => $job_id , "job_name" => $job_name, "job_number" => $job_number, "description" => $description, "location_id" => $location_id, "company_name" => $company_name, "department_name" => $department_name, "stage_name" => $stage_name, "ordering" => $ordering, "status" => $status, "status1" => $status1, "status_name" => $status_name, "status_name1" => $status_name1, "submitter" => $submitter, "date_submitted" => $date_submitted ); } }*/ $in_production = false; $get_current_job_tasks = " SELECT project_tasks.*,project_workflow.table,project_workflow.foreign_id FROM project_tasks, project_workflow WHERE project_tasks.project_workflow_id = project_workflow.id AND project_tasks.status=0 AND project_workflow.foreign_id=".$id." AND project_workflow.table = 'jobs' "; $current_job_tasks = $database->getRow($get_current_job_tasks); //check in production if(in_array($current_job_tasks['workflow_task_id'],array(36,594,699,751,762,777))){ $in_production = true; //bug::bug_array('current workflow_task_id',$current_job_tasks['workflow_task_id']); }else{ $get_finished_job_tasks = " SELECT project_tasks.*,project_workflow.table,project_workflow.foreign_id FROM project_tasks, project_workflow WHERE project_tasks.project_workflow_id = project_workflow.id AND project_tasks.status=1 AND project_workflow.foreign_id=".$id." AND project_workflow.table = 'jobs' "; $finished_job_tasks = $database->getAll($get_finished_job_tasks); foreach($finished_job_tasks as $tasks){ if(in_array($tasks['workflow_task_id'],array(36,594,699,751,762,777))){ $in_production = true; //bug::bug_array('finished workflow_task_id',$current_job_tasks['workflow_task_id']); } } } if( $is_ptp == 1 ){ $in_production = true; } if($in_production){ $return_results[] = array( "id" => $id, "client_id" => $client_id, "client_name" => $client_name, "department_id" => $department_id, "dept_id" => $dept_id, "job_id" => $id , "job_name" => $job_name, "job_number" => $job_number, "description" => $description, "location_id" => $location_id, "company_name" => $company_name, "department_name" => $department_name, "stage_name" => $stage_name, "ordering" => $ordering, "status" => $status, "status1" => $status1, "status_name" => $status_name, "status_name1" => $status_name1, "submitter" => $submitter, "date_submitted" => $date_submitted ); } } $this->final_results = $return_results; return $this; } public function show() { global $database; $order = $this->order; $method = $this->method; $results = $this->final_results; $avail_status = $this->avail_status; $avail_edit = $this->avail_edit; $link_view = $this->link_view; $link_edit = $this->link_edit; $normalised_results = filter::sort_results($method,$order,$results); $normalise_get = filter::normalise_get($order); $pagination_results = filter::pagination($normalised_results,$normalise_get); $pagination_results['show_pagination'] = $this->show_pagination; $pagination_results['show_search'] = $this->show_search; filter::pagination_html($pagination_results); $pagination = $pagination_results['pagination']; $start = $pagination_results['start']; $size = $pagination_results['size']; $total_results = $pagination_results['total_results']; $max_size = $pagination_results['max_size']; $order = ($order == "ASC") ? "DESC" : "ASC"; $normalise_get = filter::normalise_get($order); $new_normalised_results = array(); foreach($normalised_results AS $key => $value) $new_normalised_results[] = $key; ?> 0) { ?>
Edit Job # Client Job Name Stage Department Status Submitter
edit
                  
order; $method = $this->method; $results = $this->final_results; $avail_status = $this->avail_status; $avail_edit = $this->avail_edit; $link_view = $this->link_view; $link_edit = $this->link_edit; $normalised_results = filter::sort_results($method,$order,$results); $normalise_get = filter::normalise_get($order); $pagination_results = filter::pagination($normalised_results,$normalise_get); //filter::pagination_html($pagination_results); //$pagination = $pagination_results['pagination']; $start = $pagination_results['start']; $size = $pagination_results['size']; $total_results = $pagination_results['total_results']; $max_size = $pagination_results['max_size']; $order = "ASC"; $normalise_get = filter::normalise_get($order); $new_normalised_results = array(); foreach($normalised_results AS $key => $value) $new_normalised_results[] = $key; ?>
0) { ?>
Job ID Job Name Description
     
pages->display_pages(); //echo "Page $this->pages->current_page of $pages->num_pages"; return $this; } }