Commit 2dc4bf3a by Phạm Văn Đoan

fix lỗi data BXH ngày

parent 44fc0d69
...@@ -6,8 +6,7 @@ ...@@ -6,8 +6,7 @@
* Time: 2:22 CH * Time: 2:22 CH
*/ */
if (!defined('BASEPATH')) exit('No direct script access allowed'); if (!defined('BASEPATH')) exit('No direct script access allowed');
//require_once APPPATH."/third_party/PHPExcel.php";
//include FCPATH . "/application/third_party/PHPExcel/IOFactory.php";
include FCPATH . "/application/third_party/PHPExcel.php"; include FCPATH . "/application/third_party/PHPExcel.php";
class CmsRanking extends CI_Controller class CmsRanking extends CI_Controller
...@@ -35,7 +34,6 @@ class CmsRanking extends CI_Controller ...@@ -35,7 +34,6 @@ class CmsRanking extends CI_Controller
public function listByDailyAjax() public function listByDailyAjax()
{ {
die('Đang cập nhật...');
$data = array(); $data = array();
$fByName = $this->input->post('fByName'); $fByName = $this->input->post('fByName');
$fByName = str_replace('/', '-', $fByName); $fByName = str_replace('/', '-', $fByName);
...@@ -123,23 +121,47 @@ class CmsRanking extends CI_Controller ...@@ -123,23 +121,47 @@ class CmsRanking extends CI_Controller
public function exportReport($type, $time) public function exportReport($type, $time)
{ {
if ($type && $time) { if ($type && $time) {
$arrayTime = explode('-', $time); $array_time = explode('-', $time);
$week = date('W'); $week = date('W');
$month = date('n'); $month = date('n');
$year = date('Y'); $year = date('Y');
if ($type == 'week') { switch ($type) {
$week = trim($arrayTime[0]); case 'daily':
$year = trim($arrayTime[1]); if ($time) {
$daily_at = date('Y-m-d', strtotime($time));
$filename = 'Daily-report-' . $daily_at;
$reports = $this->track_model->getReportDaily($daily_at);
}
break;
case 'weekly':
$week = trim($array_time[0]);
$year = trim($array_time[1]);
$filename = 'Weekly-tuan' . (($week < 10) ? '0'.$time : $time);
$reports = $this->track_model->getReportWeekly($week, $year);
break;
case 'monthly':
$month = trim($array_time[0]);
$year = trim($array_time[1]);
$filename = 'Monthly-' . (($month < 10) ? '0'.$time : $time);
$reports = $this->track_model->getReportMonthly($month, $year);
break;
}
/*if ($type == 'week') {
$week = trim($array_time[0]);
$year = trim($array_time[1]);
$filename = 'Weekly-tuan' . (($week < 10) ? '0'.$time : $time); $filename = 'Weekly-tuan' . (($week < 10) ? '0'.$time : $time);
$reports = $this->track_model->getReportWeekly($week, $year); $reports = $this->track_model->getReportWeekly($week, $year);
} elseif ($type == 'month') { } elseif ($type == 'month') {
$month = trim($arrayTime[0]); $month = trim($array_time[0]);
$year = trim($arrayTime[1]); $year = trim($array_time[1]);
$filename = 'Monthly-' . (($month < 10) ? '0'.$time : $time); $filename = 'Monthly-' . (($month < 10) ? '0'.$time : $time);
$reports = $this->track_model->getReportMonthly($month, $year); $reports = $this->track_model->getReportMonthly($month, $year);
} }*/
$count_views = []; $count_views = [];
foreach ($reports as $key => $result) { foreach ($reports as $key => $result) {
...@@ -171,7 +193,7 @@ class CmsRanking extends CI_Controller ...@@ -171,7 +193,7 @@ class CmsRanking extends CI_Controller
$track_detail = $this->track_model->getTrackById($result['track_id']); $track_detail = $this->track_model->getTrackById($result['track_id']);
$track_detail = $track_detail[0]; $track_detail = $track_detail[0];
$count_views[] = array( $count_views[] = array(
'A' => $result['order'], 'A' => isset($result['order']) ? $result['order'] : $result['ranking'],
//'B' => ($track_detail['title'] != '') ? $track_detail['title'] . ' (' . $track_detail['id'] . ')' : '', //'B' => ($track_detail['title'] != '') ? $track_detail['title'] . ' (' . $track_detail['id'] . ')' : '',
'B' => ($track_detail['title'] != '') ? $track_detail['title'] : '', 'B' => ($track_detail['title'] != '') ? $track_detail['title'] : '',
'C' => ($casi[$key] && count($casi[$key]) > 0 ) ? implode(", ", $casi[$key]) : '', 'C' => ($casi[$key] && count($casi[$key]) > 0 ) ? implode(", ", $casi[$key]) : '',
......
...@@ -231,7 +231,35 @@ class Track_model extends CI_Model ...@@ -231,7 +231,35 @@ class Track_model extends CI_Model
$query = $this->db->get(); $query = $this->db->get();
return $query->result_array(); return $query->result_array();
} }
/**
* Hàm lấy dữ liệu BXH ngày trong bảng report_views_daily
* @param $daily_at
* @param int $limit
* @param int $offset
*
* @return mixed
*/
public function getReportDaily($daily_at, $limit = 100, $offset = 0)
{
$this->db->from('report_views_daily');
$this->db->where('date =', $daily_at);
$this->db->limit($limit, $offset);
$query = $this->db->get();
return $query->result_array();
}
/**
* Hàm lấy dữ liệu BXH tuần trong bảng report_views_weekly (cũ) và bảng report_views_weekly_new (từ 29/3-4/4)
*
* @param $week
* @param $year
* @param int $limit
* @param int $offset
*
* @return mixed
*/
public function getReportWeekly($week, $year, $limit = 100, $offset = 0) public function getReportWeekly($week, $year, $limit = 100, $offset = 0)
{ {
//$sql = "SELECT * FROM report_views_weekly WHERE `week` = ? AND `year` = ? ORDER BY total_point DESC LIMIT {$offset}, {$limit} "; //$sql = "SELECT * FROM report_views_weekly WHERE `week` = ? AND `year` = ? ORDER BY total_point DESC LIMIT {$offset}, {$limit} ";
...@@ -244,7 +272,17 @@ class Track_model extends CI_Model ...@@ -244,7 +272,17 @@ class Track_model extends CI_Model
return $query->result_array(); return $query->result_array();
} }
/**
* Hàm lấy dữ liệu BXH tháng
*
* @param $month
* @param $year
* @param int $limit
* @param int $offset
*
* @return mixed
*/
public function getReportMonthly($month, $year, $limit = 100, $offset = 0) public function getReportMonthly($month, $year, $limit = 100, $offset = 0)
{ {
//$sql = "SELECT * FROM reports_views_monthly WHERE `month` = ? AND `year` = ? ORDER BY total_point DESC LIMIT {$offset}, {$limit} "; //$sql = "SELECT * FROM reports_views_monthly WHERE `month` = ? AND `year` = ? ORDER BY total_point DESC LIMIT {$offset}, {$limit} ";
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
<?php endif; ?> <?php endif; ?>
<div class="row"> <div class="row">
<?php echo form_open(base_url().'backend/cmsRanking/listByDailyAjax'); ?> <?php //echo form_open(base_url().'backend/cmsRanking/listByDailyAjax'); ?>
<div class="col-lg-3"> <div class="col-lg-3">
<div class="input-group text-center"> <div class="input-group text-center">
<input class="form-control date-picker" id="input-date-picker" type="text" data-date-format="dd/mm/yyyy" <input class="form-control date-picker" id="input-date-picker" type="text" data-date-format="dd/mm/yyyy"
...@@ -32,10 +32,15 @@ ...@@ -32,10 +32,15 @@
</span> </span>
</div> </div>
</div> </div>
<div class="col-lg-1"> <!--<div class="col-lg-1">
<button class="btn btn-sm btn-default" id="delete-filter">Xóa bộ lọc</button> <button class="btn btn-sm btn-default" id="delete-filter">Xóa bộ lọc</button>
</div>-->
<div class="col-lg-1">
<a href="" id="btn-export">
<button class="btn btn-sm btn-warning"><i class="fa fa-download"></i> Export ra Excel</button>
</a>
</div> </div>
<?php echo form_close(); ?> <?php //echo form_close(); ?>
</div> </div>
<!-- /.row --> <!-- /.row -->
<div class="space-6"></div> <div class="space-6"></div>
...@@ -69,6 +74,7 @@ ...@@ -69,6 +74,7 @@
}); });
changePagination('0'); changePagination('0');
updateExportLink();
}); });
//Ham chung cho cac input //Ham chung cho cac input
...@@ -117,4 +123,11 @@ ...@@ -117,4 +123,11 @@
}); });
} }
function updateExportLink() {
var date_picker = ($("#input-date-picker").val()) ? $("#input-date-picker").val() : null;
if (date_picker) { date_picker = date_picker.replace(/\//g, '-') }
var href = '<?php echo base_url("backend/cmsRanking/exportReport/daily"); ?>/' + date_picker;
$('#btn-export').attr('href', href);
}
</script> </script>
\ No newline at end of file
...@@ -116,7 +116,7 @@ ...@@ -116,7 +116,7 @@
} }
function updateExportLink() { function updateExportLink() {
var href = '<?php echo base_url("backend/cmsRanking/exportReport/month"); ?>/' + $("#input-name").val(); var href = '<?php echo base_url("backend/cmsRanking/exportReport/monthly"); ?>/' + $("#input-name").val();
$('#btn-export').attr('href', href); $('#btn-export').attr('href', href);
} }
......
...@@ -161,7 +161,7 @@ ...@@ -161,7 +161,7 @@
} }
function updateExportLink() { function updateExportLink() {
var href = '<?php echo base_url("backend/cmsRanking/exportReport/week"); ?>/' + $("#input-name").val(); var href = '<?php echo base_url("backend/cmsRanking/exportReport/weekly"); ?>/' + $("#input-name").val();
$('#btn-export').attr('href', href); $('#btn-export').attr('href', href);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment