add indexes, add messagedetsta
This commit is contained in:
@@ -10,6 +10,8 @@ use yii\web\NotFoundHttpException;
|
||||
use yii\filters\VerbFilter;
|
||||
use common\models\Account;
|
||||
use common\models\ProductCategory;
|
||||
use backend\models\ProductStatisticsSearch;
|
||||
use PHPExcel;
|
||||
|
||||
/**
|
||||
* ProductController implements the CRUD actions for Product model.
|
||||
@@ -17,6 +19,24 @@ use common\models\ProductCategory;
|
||||
class ProductController extends \backend\controllers\BackendController
|
||||
{
|
||||
|
||||
public function behaviors()
|
||||
{
|
||||
return [
|
||||
'access' => [
|
||||
'class' => \yii\filters\AccessControl::className(),
|
||||
'rules' => [
|
||||
// allow authenticated users
|
||||
[
|
||||
'actions' => ['create','index','view','update','statistics'],
|
||||
'allow' => true,
|
||||
'roles' => ['admin','employee','reception'],
|
||||
],
|
||||
// everything else is denied
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Lists all Product models.
|
||||
@@ -106,6 +126,60 @@ class ProductController extends \backend\controllers\BackendController
|
||||
|
||||
return $this->redirect(['index']);
|
||||
}
|
||||
|
||||
|
||||
public function actionStatistics(){
|
||||
|
||||
$searchModel = new ProductStatisticsSearch();
|
||||
|
||||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
||||
|
||||
|
||||
if ( $searchModel->output == 'xls' ){
|
||||
|
||||
$models = $dataProvider->getModels();
|
||||
$objPHPExcel = new \PHPExcel();
|
||||
|
||||
$sheet = $objPHPExcel->setActiveSheetIndex(0);
|
||||
|
||||
$row = 1;
|
||||
$sheet->setCellValue('A'.$row, "Termék név")
|
||||
->setCellValue('B'.$row, "Eladási ár")
|
||||
->setCellValue('C'.$row, "Kassza")
|
||||
->setCellValue('D'.$row, "Eladott mennyiség")
|
||||
->setCellValue('E'.$row, "Eladás összege");
|
||||
|
||||
foreach ($models as $model ){
|
||||
$row++;
|
||||
$sheet->setCellValue('A'.$row, $model['product_name'])
|
||||
->setCellValue('B'.$row, $model['product_sale_price'])
|
||||
->setCellValue('C'.$row, $model['father_account_name'])
|
||||
->setCellValue('D'.$row, $model['transfer_count'])
|
||||
->setCellValue('E'.$row, $model['transfer_money']);
|
||||
}
|
||||
|
||||
// Redirect output to a client’s web browser (Excel5)
|
||||
header('Content-Type: application/vnd.ms-excel');
|
||||
header('Content-Disposition: attachment;filename="termek_statisztika.xls"');
|
||||
header('Cache-Control: max-age=0');
|
||||
// If you're serving to IE 9, then the following may be needed
|
||||
header('Cache-Control: max-age=1');
|
||||
// If you're serving to IE over SSL, then the following may be needed
|
||||
header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
|
||||
header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
|
||||
header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
|
||||
header ('Pragma: public'); // HTTP/1.0
|
||||
$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
|
||||
$objWriter->save('php://output');
|
||||
exit;
|
||||
|
||||
}
|
||||
|
||||
return $this->render('statistics', [
|
||||
'searchModel' => $searchModel,
|
||||
'dataProvider' => $dataProvider,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the Product model based on its primary key value.
|
||||
|
||||
Reference in New Issue
Block a user