status = $context['status']; $this->start_date = $context['start_date']; $this->end_date = $context['end_date']; $this->financial_type = $context['financial_type']; $this->in_pending = $context['in_pending']; $this->sales_id = $context['sales']; $this->method = (empty($context['list_config']['method'])) ? "id" : $context['list_config']['method']; } public function search($ids) { global $database; $status = $this->status; $context_workflow = array( "readonly" => false, "show_all" => true ); $context_workflow['table'] = 'quotes'; $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 ); $ids_sql = ""; if(count($ids) > 0) { foreach($ids AS $value) $ids_sql .= "'".$value['id']."',"; $ids_sql = "(".substr($ids_sql,0, strlen($ids_sql) - 1).")"; } $sql =" SELECT * FROM quotes WHERE id IN $ids_sql "; $results = $database->query($sql); $users = common_users::get_all_names_link(); $locations = common_location::get_locations(); $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(); foreach($results AS $result) { $result['client_name'] = common_ref_client::get_client_name($result['client_id']); $result['site_location'] = $locations[$result['site_location_id']]['name']; $result['job_type'] = $job_type[$result['job_type']]; $result['priority'] = $priorities[$result['priority']]; $result['submitter'] = $users[$result['submitter']]; $result['any_id'] = $result['id']; $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 get_data() { global $database; $status = $this->status; /** pagination */ $sql ="SELECT count(*) as total FROM quotes where status ='$status'"; $num_results = $database->getOne($sql); $this->pages = new paginator('quote'); $this->pages->items_total = $num_results; $this->pages->mid_range = 9; $this->pages->paginate(); $context_workflow = array( "readonly" => false, "show_all" => true ); $context_workflow['table'] = 'quotes'; $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 ); /** Kai 23/10/2012*/ $where = ""; $start_date =''; $end_date =''; $where = "WHERE status='$status'"; 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 status='$status' AND date_created >= '$start_date 00:00:00' AND date_created <= '$end_date 23:59:59'"; $where = "INNER JOIN project_workflow a ON a.foreign_id = quotes.id INNER JOIN project_tasks b ON a.id = b.project_workflow_id WHERE a.table='quotes' AND b.workflow_task_id IN (7,30,566,59,574,674,758,759,760) AND quotes.status = 1 AND b.date_created >= '$start_date 00:00:00' AND b.date_created <= '$end_date 23:59:59' GROUP BY quotes.id"; }else if($status==3){ //$where = "WHERE status='$status' AND date_submitted >= '$start_date 00:00:00' AND date_submitted <= '$end_date 23:59:59'"; $where = " INNER JOIN project_workflow ON project_workflow.foreign_id = quotes.id WHERE project_workflow.table = 'quotes'AND project_workflow.direction = 'yes' AND project_workflow.workflow_id IN (6,360,406,433) AND quotes.status = '3' AND project_workflow.date_submitted >= '$start_date 00:00:00' AND project_workflow.date_submitted <= '$end_date 23:59:59' GROUP BY quotes.id"; }else if($status==4){ $where = "WHERE status='$status' AND date_submitted >= '$start_date 00:00:00' AND date_submitted <= '$end_date 23:59:59' GROUP BY quotes.id"; }else if($status==5){ $where = "WHERE status='$status' AND date_submitted >= '$start_date 00:00:00' AND date_submitted <= '$end_date 23:59:59'"; $where = " INNER JOIN project_workflow ON project_workflow.foreign_id = quotes.id WHERE (project_workflow.table = 'quotes' AND project_workflow.direction = 'no' AND project_workflow.workflow_id IN (6,360,406,433) AND quotes.status = '3' AND project_workflow.date_submitted >= '$start_date 00:00:00' AND project_workflow.date_submitted <= '$end_date 23:59:59') OR (quotes.status = '5' AND quotes.date_submitted >= '$start_date 00:00:00' AND quotes.date_submitted <= '$end_date 23:59:59') group by quotes.id"; }else{ $where = "WHERE status='$status'"; } } $sql =" SELECT quotes.* FROM quotes ".$where." ORDER BY `quotes`.`date_created` DESC ".$this->pages->limit; $results = $database->query($sql); if(!empty($this->sales_id)){ if($this->sales_id>0){ if($status==1){ $results = common_quotes::getSalesQuotesCreated($this->sales_id,$start_date,$end_date); }elseif($status==3){ $results = common_quotes::getSalesQuotesAccepted($this->sales_id,$start_date,$end_date); }elseif($status==5){ $results = common_quotes::getSalesQuotesRejected($this->sales_id,$start_date,$end_date); } }else{ if($this->sales_id==-1){ $results = common_quotes::getQuotesNoSaleCreated($start_date,$end_date); }elseif($this->sales_id==-3){ $results = common_quotes::getQuotesNoSaleAccepted($start_date,$end_date); }elseif($this->sales_id==-5){ $results = common_quotes::getQuotesNoSaleRejected($start_date,$end_date); } } } if($this->in_pending==1){ $quotes = common_workflow::get_pending_quotes(); if($quotes){ foreach($quotes as $quote){ $quote_arr[]= $quote['foreign_id']; } $quote_string = implode(',',$quote_arr); $sql ="SELECT * FROM quotes where id IN ($quote_string) ORDER BY `quotes`.`date_created` DESC";//.$pages->limit; $results = $database->query($sql); }else{ $results = null; } } /** * Kai 22/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(); /** awaiting approval*/ if($this->financial_type==1){ $job_wait_approval = common_workflow::get_work_awaiting_approval($start_date,$end_date); if(!empty($job_wait_approval)){ $temp_quotes = array(); foreach($job_wait_approval as $quote){ if(!in_array($quote['foreign_id'],$temp_quotes)){ $temp_quotes[] = $quote['foreign_id']; } } foreach($results as $key=>$quote){ if(in_array($quote['id'], $temp_quotes)){ $filter_array[$key] = $quote; } } } } /** work not accepted*/ if($this->financial_type==4){ $jobs_not_accepted = common_workflow::get_work_not_accepted($start_date,$end_date); if(!empty($jobs_not_accepted)){ $temp_quotes = array(); foreach($jobs_not_accepted as $quote){ if(!in_array($quote['foreign_id'],$temp_quotes)){ $temp_quotes[] = $quote['foreign_id']; } } foreach($results as $key=>$quote){ if(in_array($quote['id'], $temp_quotes)){ $filter_array[$key] = $quote; } } } } $results = $filter_array; } /** End of changes Kai 22/11/2012*/ $users = common_users::get_all_names_link(); $locations = common_location::get_locations(); $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(); foreach($results AS $result) { $result['client_name'] = common_ref_client::get_client_name($result['client_id']); $result['site_location'] = $locations[$result['site_location_id']]['name']; $result['job_type'] = $job_type[$result['job_type']]; $result['priority'] = $priorities[$result['priority']]; $result['submitter'] = $users[$result['submitter']]; $result['any_id'] = $result['id']; $job_info = common_quotes::get_job_id_by_quote($result['id']); if($job_info){ if($job_info['status'] == 1){ $result['job_id'] = ''.$job_info['id'].''; }else{ $result['job_id'] = ''.$job_info['id'].''; } }else{ $result['job_id']="-"; } $total_sales_price = common_quotesheets::get_total_sales($result['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; } function showPagination(){ echo $this->pages->display_pages(); //echo "Page $this->pages->current_page of $pages->num_pages"; return $this; } }