add account state changes
This commit is contained in:
@@ -10,6 +10,7 @@ use yii\web\NotFoundHttpException;
|
||||
use yii\filters\VerbFilter;
|
||||
use common\models\Account;
|
||||
use common\models\User;
|
||||
use common\components\DailyListing;
|
||||
|
||||
/**
|
||||
* AccountStateController implements the CRUD actions for AccountState model.
|
||||
@@ -17,6 +18,24 @@ use common\models\User;
|
||||
class AccountStateController extends \backend\controllers\BackendController
|
||||
{
|
||||
|
||||
public function behaviors()
|
||||
{
|
||||
return [
|
||||
'access' => [
|
||||
'class' => \yii\filters\AccessControl::className(),
|
||||
'rules' => [
|
||||
// allow authenticated users
|
||||
[
|
||||
'actions' => ['create','index','view','update','delete'],
|
||||
'allow' => true,
|
||||
'roles' => ['admin','employee','reception'],
|
||||
],
|
||||
// everything else is denied
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all AccountState models.
|
||||
* @return mixed
|
||||
@@ -30,7 +49,6 @@ class AccountStateController extends \backend\controllers\BackendController
|
||||
$users = User::read();
|
||||
|
||||
|
||||
|
||||
return $this->render('index', [
|
||||
'searchModel' => $searchModel,
|
||||
'dataProvider' => $dataProvider,
|
||||
@@ -44,12 +62,65 @@ class AccountStateController extends \backend\controllers\BackendController
|
||||
* @param integer $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionView($id)
|
||||
{
|
||||
return $this->render('view', [
|
||||
'model' => $this->findModel($id),
|
||||
]);
|
||||
}
|
||||
/*
|
||||
* Displays a single AccountState model.
|
||||
* @param integer $id
|
||||
* $var common\models\AccountState $accountState
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionView($id) {
|
||||
echo "view";
|
||||
$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}');
|
||||
|
||||
$stylesheet = file_get_contents( \Yii::getAlias('@vendor'.'/bower/bootstrap/dist/css/bootstrap.css')); // external css
|
||||
$mpdf->WriteHTML($stylesheet,1);
|
||||
|
||||
|
||||
$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
|
||||
] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new AccountState model.
|
||||
@@ -88,6 +159,37 @@ class AccountStateController extends \backend\controllers\BackendController
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
$model = $this->findModel ( $id );
|
||||
|
||||
$delete = true;
|
||||
if ( $model->isTypeOpen() ){
|
||||
$closeStates = AccountState::find()->andWhere( ['prev_state' => $model->id_account_state] )->all();
|
||||
|
||||
if ( count($closeStates) > 0){
|
||||
$delete = false;
|
||||
\Yii::$app->session->setFlash('error', ['Nem lehet törölni a nyitást, mert van kapcsolódó zárás!']);
|
||||
throw new \Exception('Nem lehet törölni a nyitást, mert van kapcsolódó zárás!');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ( $delete == true ){
|
||||
$model->delete();
|
||||
\Yii::$app->session->setFlash ( 'success', 'Kassza művelet törölve' );
|
||||
}
|
||||
|
||||
return $this->redirect ( ["index"] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an existing AccountState model.
|
||||
* If deletion is successful, the browser will be redirected to the 'index' page.
|
||||
|
||||
Reference in New Issue
Block a user