add reception account state view and pdf export
This commit is contained in:
@@ -9,179 +9,231 @@ use yii\web\Controller;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\filters\VerbFilter;
|
||||
use common\models\Account;
|
||||
use common\components\DailyListing;
|
||||
use common\models\User;
|
||||
|
||||
/**
|
||||
* AccountStateController implements the CRUD actions for AccountState model.
|
||||
*/
|
||||
class AccountStateController extends Controller
|
||||
{
|
||||
public function behaviors()
|
||||
{
|
||||
return [
|
||||
'access' => [
|
||||
'class' => \yii\filters\AccessControl::className(),
|
||||
'only' => [ 'index','open','close'],
|
||||
'rules' => [
|
||||
// allow authenticated users
|
||||
[
|
||||
'allow' => true,
|
||||
'roles' => ['@'],
|
||||
],
|
||||
// everything else is denied
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all AccountState models.
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionIndex()
|
||||
{
|
||||
$searchModel = new AccountstateSearch();
|
||||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
||||
|
||||
return $this->render('index', [
|
||||
'searchModel' => $searchModel,
|
||||
'dataProvider' => $dataProvider,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new AccountState model.
|
||||
* If creation is successful, the browser will be redirected to the 'view' page.
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionOpen()
|
||||
{
|
||||
|
||||
$lastStates = AccountState::readLastForUser(AccountState::TYPE_CLOSE );
|
||||
$lastStates = AccountState::modelsToArray($lastStates);
|
||||
|
||||
$model = new AccountState();
|
||||
class AccountStateController extends Controller {
|
||||
public function behaviors() {
|
||||
return [
|
||||
'access' => [
|
||||
'class' => \yii\filters\AccessControl::className (),
|
||||
'only' => [
|
||||
'index',
|
||||
'open',
|
||||
'close',
|
||||
'view'
|
||||
],
|
||||
'rules' => [
|
||||
// allow authenticated users
|
||||
[
|
||||
'allow' => true,
|
||||
'roles' => [
|
||||
'@'
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
// everything else is denied
|
||||
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all AccountState models.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionIndex() {
|
||||
$searchModel = new AccountstateSearch ();
|
||||
|
||||
$searchModel->accounts = Account::read ();
|
||||
$searchModel->users = User::read ();
|
||||
|
||||
$dataProvider = $searchModel->search ( Yii::$app->request->queryParams );
|
||||
|
||||
return $this->render ( 'index', [
|
||||
'searchModel' => $searchModel,
|
||||
'dataProvider' => $dataProvider
|
||||
] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new AccountState model.
|
||||
* If creation is successful, the browser will be redirected to the 'view' page.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionOpen() {
|
||||
$lastStates = AccountState::readLastForUser ( AccountState::TYPE_CLOSE );
|
||||
$lastStates = AccountState::modelsToArray ( $lastStates );
|
||||
|
||||
$model = new AccountState ();
|
||||
$model->type = AccountState::TYPE_OPEN;
|
||||
$model->id_user = Yii::$app->user->id;
|
||||
$model->id_account = Account::readDefault();
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
// return $this->redirect(['view', 'id' => $model->id_account_state]);
|
||||
return $this->redirect(['index' ]);
|
||||
} else {
|
||||
|
||||
$accounts = Account::read();
|
||||
|
||||
return $this->render('open', [
|
||||
'model' => $model,
|
||||
'accounts' => $accounts,
|
||||
'lastStates' => $lastStates,
|
||||
]);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Creates a new AccountState model.
|
||||
* If creation is successful, the browser will be redirected to the 'view' page.
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionClose()
|
||||
{
|
||||
$lastStates = AccountState::readLastForUser(AccountState::TYPE_OPEN );
|
||||
$lastStates = AccountState::modelsToArray($lastStates);
|
||||
$model = new AccountState();
|
||||
$model->type = AccountState::TYPE_CLOSE;
|
||||
$model->id_user = Yii::$app->user->id;
|
||||
$model->id_account = Account::readDefault();
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
return $this->redirect(['index' ]);
|
||||
// return $this->redirect(['view', 'id' => $model->id_account_state]);
|
||||
} else {
|
||||
|
||||
$accounts = Account::read();
|
||||
|
||||
return $this->render('close', [
|
||||
'model' => $model,
|
||||
'accounts' => $accounts,
|
||||
'lastStates' => $lastStates,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Finds the AccountState model based on its primary key value.
|
||||
* If the model is not found, a 404 HTTP exception will be thrown.
|
||||
* @param integer $id
|
||||
* @return AccountState the loaded model
|
||||
* @throws NotFoundHttpException if the model cannot be found
|
||||
*/
|
||||
protected function findModel($id)
|
||||
{
|
||||
if (($model = AccountState::findOne($id)) !== null) {
|
||||
return $model;
|
||||
} else {
|
||||
throw new NotFoundHttpException('The requested page does not exist.');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Creates a new AccountState model.
|
||||
* If creation is successful, the browser will be redirected to the 'view' page.
|
||||
* @return mixed
|
||||
public function actionCreate()
|
||||
{
|
||||
$model = new AccountState();
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
return $this->redirect(['view', 'id' => $model->id_account_state]);
|
||||
} else {
|
||||
return $this->render('create', [
|
||||
'model' => $model,
|
||||
]);
|
||||
}
|
||||
}
|
||||
*/
|
||||
/**
|
||||
* Updates an existing AccountState 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_account_state]);
|
||||
} else {
|
||||
return $this->render('update', [
|
||||
'model' => $model,
|
||||
]);
|
||||
}
|
||||
}
|
||||
*/
|
||||
/**
|
||||
* Deletes an existing AccountState 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();
|
||||
\Yii::$app->session->setFlash( 'success','Kassza művelet törölve' );
|
||||
return $this->redirect(Yii::$app->request->referrer);
|
||||
}
|
||||
/**
|
||||
* Displays a single AccountState model.
|
||||
* @param integer $id
|
||||
* @return mixed
|
||||
|
||||
public function actionView($id)
|
||||
{
|
||||
return $this->render('view', [
|
||||
'model' => $this->findModel($id),
|
||||
]);
|
||||
}
|
||||
*/
|
||||
$model->id_user = Yii::$app->user->id;
|
||||
$model->id_account = Account::readDefault ();
|
||||
if ($model->load ( Yii::$app->request->post () ) && $model->save ()) {
|
||||
// return $this->redirect(['view', 'id' => $model->id_account_state]);
|
||||
return $this->redirect ( [
|
||||
'index'
|
||||
] );
|
||||
} else {
|
||||
|
||||
$accounts = Account::read ();
|
||||
|
||||
return $this->render ( 'open', [
|
||||
'model' => $model,
|
||||
'accounts' => $accounts,
|
||||
'lastStates' => $lastStates
|
||||
] );
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Creates a new AccountState model.
|
||||
* If creation is successful, the browser will be redirected to the 'view' page.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionClose() {
|
||||
$lastStates = AccountState::readLastForUser ( AccountState::TYPE_OPEN );
|
||||
$lastStates = AccountState::modelsToArray ( $lastStates );
|
||||
$model = new AccountState ();
|
||||
$model->type = AccountState::TYPE_CLOSE;
|
||||
$model->id_user = Yii::$app->user->id;
|
||||
$model->id_account = Account::readDefault ();
|
||||
if ($model->load ( Yii::$app->request->post () ) && $model->save ()) {
|
||||
return $this->redirect ( [
|
||||
'index'
|
||||
] );
|
||||
// return $this->redirect(['view', 'id' => $model->id_account_state]);
|
||||
} else {
|
||||
|
||||
$accounts = Account::read ();
|
||||
|
||||
return $this->render ( 'close', [
|
||||
'model' => $model,
|
||||
'accounts' => $accounts,
|
||||
'lastStates' => $lastStates
|
||||
] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the AccountState model based on its primary key value.
|
||||
* If the model is not found, a 404 HTTP exception will be thrown.
|
||||
*
|
||||
* @param integer $id
|
||||
* @return AccountState the loaded model
|
||||
* @throws NotFoundHttpException if the model cannot be found
|
||||
*/
|
||||
protected function findModel($id) {
|
||||
if (($model = AccountState::findOne ( $id )) !== null) {
|
||||
return $model;
|
||||
} else {
|
||||
throw new NotFoundHttpException ( 'The requested page does not exist.' );
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Creates a new AccountState model.
|
||||
* If creation is successful, the browser will be redirected to the 'view' page.
|
||||
*
|
||||
* @return mixed public function actionCreate()
|
||||
* {
|
||||
* $model = new AccountState();
|
||||
*
|
||||
* if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
* return $this->redirect(['view', 'id' => $model->id_account_state]);
|
||||
* } else {
|
||||
* return $this->render('create', [
|
||||
* 'model' => $model,
|
||||
* ]);
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
/**
|
||||
* Updates an existing AccountState 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_account_state]);
|
||||
* } else {
|
||||
* return $this->render('update', [
|
||||
* 'model' => $model,
|
||||
* ]);
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
/**
|
||||
* Deletes an existing AccountState 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 ();
|
||||
\Yii::$app->session->setFlash ( 'success', 'Kassza művelet törölve' );
|
||||
return $this->redirect ( Yii::$app->request->referrer );
|
||||
}
|
||||
/*
|
||||
* Displays a single AccountState model.
|
||||
* @param integer $id
|
||||
* $var common\models\AccountState $accountState
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionView($id) {
|
||||
$accountState = $this->findModel ( $id );
|
||||
$output = Yii::$app->getRequest ()->getQueryParam ( 'output' );
|
||||
$details = null;
|
||||
if ($accountState->isTypeClose ()) {
|
||||
|
||||
$prev;
|
||||
if ($accountState->type == AccountState::TYPE_CLOSE) {
|
||||
if (isset ( $accountState->prev_state )) {
|
||||
$prev = AccountState::findOne ( $accountState->prev_state );
|
||||
}
|
||||
if (isset ( $prev )) {
|
||||
$accountState->start_date = $prev->created_at;
|
||||
}
|
||||
}
|
||||
$details = new DailyListing ();
|
||||
$details->loadAccountState ( $accountState );
|
||||
|
||||
$details->readTotalEasy ();
|
||||
$details->readTotalDetailed ();
|
||||
$details->readTotalMedium ();
|
||||
}
|
||||
|
||||
if ($output == 'pdf') {
|
||||
$user = User::findOne(\Yii::$app->user->id);
|
||||
$mpdf=new \mPDF('utf-8', 'A4-L');
|
||||
$mpdf->useSubstitutions=false;
|
||||
$mpdf->simpleTables = true;
|
||||
$mpdf->SetHeader( \Yii::$app->params[ "company_name" ] . " - Létrehozva: " .$user->username . ", ".\Yii::$app->formatter->asDatetime(time()) );
|
||||
$mpdf->setFooter('{PAGENO} / {nb}');
|
||||
$mpdf->WriteHTML($this->renderPartial("@common/views/account-state/account_state_pdf", [
|
||||
'model' => $accountState,
|
||||
'details' => $details
|
||||
]));
|
||||
$type = $accountState->isTypeOpen() ? "kassza_nyitas" : "kassza_zaras";
|
||||
$dt= "_letrehozva_".date("Ymd_His"). "_" . $user->username;
|
||||
$fn= $type .$dt.".pdf";
|
||||
$mpdf->Output($fn, 'D');
|
||||
|
||||
} else {
|
||||
|
||||
return $this->render ( 'view', [
|
||||
'model' => $accountState,
|
||||
'details' => $details
|
||||
] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user