fitness-web/backend/controllers/UgiroController.php

429 lines
13 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace backend\controllers;
use common\models\TicketInstallmentRequest;
use Yii;
use common\models\Ugiro;
use backend\models\UgiroSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use common\components\DetStatProcessor;
use backend\models\DestaUploadForm;
use yii\web\UploadedFile;
use yii\data\ArrayDataProvider;
use yii\db\Query;
use yii\data\ActiveDataProvider;
use common\models\MessageDetsta;
/**
* UgiroController implements the CRUD actions for Ugiro model.
* TODO: FIX ACCESS
*/
class UgiroController extends Controller {
public function behaviors() {
return [
'verbs' => [
'class' => VerbFilter::className (),
'actions' => [
'delete' => [
'post'
]
]
],
'access' => [
'class' => \yii\filters\AccessControl::className (),
'rules' => [
// allow authenticated users
[
'actions' => [ ],
'allow' => true,
'roles' => [
'admin',
'employee',
'reception'
]
]
]
]
// everything else is denied
];
}
/**
* Lists all Ugiro models.
*
* @return mixed
*/
public function actionIndex() {
$searchModel = new UgiroSearch ();
$dataProvider = $searchModel->search ( Yii::$app->request->queryParams );
return $this->render ( 'index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider
] );
}
/**
* Lists all Ugiro models.
*
* @return mixed
*/
public function actionItems($id) {
$searchModel = new UgiroSearch ();
$dataProvider = $searchModel->search ( Yii::$app->request->queryParams );
return $this->render ( 'index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider
] );
}
public function actionActivate() {
}
/**
* Displays a single Ugiro model.
*
* @param integer $id
* @return mixed
*/
public function actionView($id) {
$model = $this->findModel ( $id );
if (Yii::$app->request->isPost) {
if ($model->status == Ugiro::$STATUS_RECIEVED) {
set_time_limit ( 1200 ); // 20 perc
$processor = new DetStatProcessor ( [
'koteg' => $model
] );
$processor->run ();
$this->redirect(['view', 'id' => $model->id_ugiro]);
} else {
\Yii::$app->session->setFlash ( 'danger', 'Nem lehet futtatni a fájlt' );
\Yii::error ( "a koteg státusza nem STATUS_RECIEVED. A koteg azonosíótja:" . $model->id_ugiro );
}
} else {
if (isset ( $_GET ['output'] )) {
$output = $_GET ['output'];
if ($output == 'pdf') {
$this->downloadUgiroPdf ( $model );
}else if ($output == 'xls') {
$this->downloadUgiroXls ( $model );
}
}
}
$query = MessageDetsta::find();
$query->andWhere(['id_ugiro' => $model->id_ugiro]);
$query->orderBy([ 'created_at' => SORT_ASC ]);
$detstaDp = new ActiveDataProvider([
'query' => $query,
'pagination' => false,
'sort' => false
]);
return $this->render ( 'view', [
'model' => $this->findModel ( $id ) ,
'detstaDp' => $detstaDp
] );
}
/**
* @param \common\models\Ugiro $model
*/
protected function downloadUgiroXls($model) {
$fn = "köteg.". $model->id_ugiro . ".xls";
$query = new Query();
$query->select([
'card.number as card_number',
'customer.id_customer as customer_id_customer',
'customer.name as customer_name',
'customer.bank_account as customer_bank_account',
'ticket_installment_request.money as request_money',
'ticket_installment_request.status as request_status',
'ticket_installment_request.request_target_time_at as request_request_target_time_at',
'ticket_installment_request.request_processed_at as request_request_processed_at',
]);
$query->from('ticket_installment_request');
$query->innerJoin('ugiro_request_assignment','ticket_installment_request.id_ticket_installment_request = ugiro_request_assignment.id_request');
$query->innerJoin('customer','customer.id_customer = ticket_installment_request.id_customer');
$query->innerJoin('card','customer.id_customer_card = card.id_card');
$query->andWhere(['ugiro_request_assignment.id_ugiro' => $model->id_ugiro]);
$query->orderBy(['customer.name' => SORT_ASC]);
$dataProvider = new ActiveDataProvider(
[
'query' => $query,
'sort' => false,
'pagination' => false
]
);
$objPHPExcel = new \PHPExcel ();
$sheet = $objPHPExcel->setActiveSheetIndex ( 0 );
$formatter = \Yii::$app->formatter;
$row = 1;
$sheet->setCellValue('A'.$row, 'Csoportos beszedés');
$row++;
$sheet->setCellValue('A'.$row, 'Köteg azonosító');
$sheet->setCellValue('B'.$row, $model->id_ugiro);
$sheet->setCellValue('C'.$row, 'Üzenetsorszám');
$sheet->setCellValue('D'.$row, $model->number);
$row++;
$sheet->setCellValue('A'.$row, 'Összeállítási dáutm');
$sheet->setCellValue('B'.$row, $model->datum);
$sheet->setCellValue('C'.$row, 'Terhelési dáutm');
$sheet->setCellValue('D'.$row, $model->terhelesi_datum);
$row++;
$sheet->setCellValue('A'.$row, 'Kártyaszám')
->setCellValue('B'.$row, 'Vendég')
->setCellValue('C'.$row, 'Bankszámlaszám')
->setCellValue('D'.$row, 'Összeg')
->setCellValue('E'.$row, 'Esedékességi dátum')
->setCellValue('F'.$row, 'Feldolgozás dátum')
->setCellValue('G'.$row, 'Státusz')
;
foreach ( $dataProvider->getModels() as $model ) {
$row ++;
$status = "";
switch ($model['request_status']){
case TicketInstallmentRequest::$STATUS_ACCEPTED:
$status = "Fizetve";
break;
case TicketInstallmentRequest::$STATUS_REJECTED:
$status = "Kosár";
break;
case TicketInstallmentRequest::$STATUS_ACCEPTED_MANUAL:
$status = "Kosár";
break;
case TicketInstallmentRequest::$STATUS_CANCELED:
$status = "Sztornó";
break;
case TicketInstallmentRequest::$STATUS_MARKED_TO_SEND:
$status = "Küldésre jelölve";
break;
case TicketInstallmentRequest::$STATUS_PENDING:
$status = "Feldolgozás alatt";
break;
case TicketInstallmentRequest::$STATUS_SENT:
$status = "Elküldve";
break;
default:
$status = "";
}
$targetTime = isset( $model['request_request_target_time_at'] ) ? $formatter->asDate($model['request_request_target_time_at']) :"";
$processedTime = isset( $model['request_request_processed_at'] ) ? $formatter->asDatetime($model['request_request_processed_at']) :"";
$sheet
->setCellValue('A'.$row, $model['card_number'])
->setCellValue('B'.$row, $model['customer_name'])
->setCellValue('C'.$row, $model['customer_bank_account'])
->setCellValue('D'.$row, ($model['request_money']))
->setCellValue('E'.$row, $targetTime)
->setCellValue('F'.$row, $processedTime)
->setCellValue('G'.$row, $status)
;
}
$styleArray = array (
'font' => array (
'bold' => true
)
);
$sheet->getStyle ( 'A1' )->applyFromArray ( $styleArray );
foreach ( range ( 'A', 'G' ) as $columnID ) {
$sheet->getColumnDimension ( $columnID )->setAutoSize ( true );
$sheet->getStyle ( $columnID . '4' )->applyFromArray ( $styleArray );
}
foreach ( ['A','C'] as $columnID ) {
$sheet->getColumnDimension ( $columnID )->setAutoSize ( true );
$sheet->getStyle ( $columnID . '2' )->applyFromArray ( $styleArray );
$sheet->getStyle ( $columnID . '3' )->applyFromArray ( $styleArray );
}
$fileName = $fn;
// Redirect output to a clients web browser (Excel5)
header ( 'Content-Type: application/vnd.ms-excel' );
header ( 'Content-Disposition: attachment;filename="' . $fileName . '"' );
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 ();
}
protected function downloadUgiroPdf($model) {
$mpdf = new \mPDF ( 'utf-8', 'A4-L' );
$fn = "köteg.". $model->id_ugiro . ".pdf";
$mpdf->useSubstitutions = false;
$mpdf->simpleTables = true;
$mpdf->SetHeader ( "" );
$mpdf->setFooter ( '{PAGENO} / {nb}' );
$query = new Query();
$query->select([
'customer.id_customer as customer_id_customer',
'customer.name as customer_name',
'customer.bank_account as customer_bank_account',
'ticket_installment_request.money as request_money',
'ticket_installment_request.request_target_time_at as request_request_target_time_at',
]);
$query->from('ticket_installment_request');
$query->innerJoin('ugiro_request_assignment','ticket_installment_request.id_ticket_installment_request = ugiro_request_assignment.id_request');
$query->innerJoin('customer','customer.id_customer = ticket_installment_request.id_customer');
$query->andWhere(['ugiro_request_assignment.id_ugiro' => $model->id_ugiro]);
$dataProvider = new ActiveDataProvider(
[
'query' => $query,
'sort' => false,
'pagination' => false
]
);
$stylesheet = file_get_contents ( \Yii::getAlias ( '@vendor' . '/bower/bootstrap/dist/css/bootstrap.css' ) ); // external css
$mpdf->WriteHTML ( $stylesheet, 1 );
$mpdf->WriteHTML ( $this->renderPartial ( '_view_pdf.php', [
'model' => $model,
'dataProvider' => $dataProvider
] ) );
$mpdf->Output ( $fn, 'D' );
exit ();
}
/**
* Creates a new Ugiro model.
* If creation is successful, the browser will be redirected to the 'view' page.
*
* @return mixed
*/
public function actionCreate() {
$model = new Ugiro ();
if ($model->load ( Yii::$app->request->post () ) && $model->save ()) {
return $this->redirect ( [
'view',
'id' => $model->id_ugiro
] );
} else {
return $this->render ( 'create', [
'model' => $model
] );
}
}
/**
* Updates an existing Ugiro model.
* If update is successful, the browser will be redirected to the 'view' page.
*
* @param integer $id
* @return mixed
*/
public function actionUpdate($id) {
$model = $this->findModel ( $id );
if ($model->load ( Yii::$app->request->post () ) && $model->save ()) {
return $this->redirect ( [
'view',
'id' => $model->id_ugiro
] );
} else {
return $this->render ( 'update', [
'model' => $model
] );
}
}
/**
* Deletes an existing Ugiro model.
* If deletion is successful, the browser will be redirected to the 'index' page.
*
* @param integer $id
* @return mixed
*/
public function actionDelete($id) {
$this->findModel ( $id )->delete ();
return $this->redirect ( [
'index'
] );
}
public function actionDetsta() {
$ugiro = Ugiro::findOne ( 31 );
$model = new DetStatProcessor ( [
'koteg' => $ugiro
] );
return $this->render ( 'detsta', [
'model' => $model
] );
}
public function actionUpload() {
$model = new DestaUploadForm ();
if (Yii::$app->request->isPost) {
$model->destaFile = UploadedFile::getInstance ( $model, 'destaFile' );
if ($model->upload ()) {
// file is uploaded successfully
return $this->redirect ( [
'view',
'id' => $model->koteg->id_ugiro
] );
}
}
return $this->render ( 'upload', [
'model' => $model
] );
}
public function actionGenerateDetsta() {
}
/**
* Finds the Ugiro model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
*
* @param integer $id
* @return Ugiro the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id) {
if (($model = Ugiro::findOne ( $id )) !== null) {
return $model;
} else {
throw new NotFoundHttpException ( 'The requested page does not exist.' );
}
}
}