function activity_pichart()
{
$this->layout = 'ajax';
$this->loadModel('Easycase');
$project_id = $this->params['data']['pjid'];
$cond = "";
if ($project_id == 'all') {
$cond = '';
} else {
$easycase = $this->Easycase->query('SELECT id from projects WHERE uniq_id="' . $project_id . '"');
$cond = "AND `project_id` = '" . $easycase[0]['projects']['id'] . "'";
}
$color_arr = array(1 => '#AE432E', 2 => '#244F7A', 3 => '#77AB13', 4 => '#244F7A', 5 => '#EF6807');
$legend_arr = array(1 => 'New', 2 => 'Opened', 3 => 'Closed', 4 => 'Start', 5 => 'Resolved');
$sql = "SELECT legend, count(*) AS cnt FROM easycases WHERE project_id !=0 " . $cond . " AND legend != 0 GROUP BY legend ORDER BY FIELD(legend,1,6,2,4,5,3)";
$easycase = $this->Easycase->query($sql);
$wip = 0;
$new = 0;
if (!empty($easycase)) {
foreach ($easycase as $k => $v) {
$cnt_array[] = $v[0]['cnt'];
if ($v['easycases']['legend'] == 2 || $v['easycases']['legend'] == 4) {
$wip = $wip + $v[0]['cnt'];
}
if ($v['easycases']['legend'] == 1 || $v['easycases']['legend'] == 6) {
$new = $new + $v[0]['cnt'];
}
}
$tot = !empty($cnt_array) ? array_sum($cnt_array) : 0;
$i = 0;
$add = 0;
$wipadd = 0;
$piearr = array();
foreach ($easycase as $k => $v) {
if ($v['easycases']['legend'] == 2 || $v['easycases']['legend'] == 4) {
if ($wipadd == 0) {
$piearr[$i]['name'] = 'In Progress';
$piearr[$i]['y'] = (double) number_format($wip / $tot * 100, 2);
$piearr[$i]['color'] = $color_arr[$v['easycases']['legend']];
$i++;
$wipadd++;
}
} else {
if ($v['easycases']['legend'] == 1 || $v['easycases']['legend'] == 6) {
if ($add == 0) {
$piearr[$i]['name'] = 'New';
$piearr[$i]['y'] = (double) number_format($new / $tot * 100, 2);
$piearr[$i]['color'] = $color_arr[$v['easycases']['legend']];
$i++;
$add++;
}
} else {
$piearr[$i]['name'] = $legend_arr[$v['easycases']['legend']];
$piearr[$i]['y'] = (double) number_format($v[0]['cnt'] / $tot * 100, 2);
$piearr[$i]['color'] = $color_arr[$v['easycases']['legend']];
$i++;
}
}
}
$this->set('piearr', json_encode($piearr));
}
}