add default account to frontend
This commit is contained in:
145
frontend/controllers/AccountController.php
Normal file
145
frontend/controllers/AccountController.php
Normal file
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\controllers;
|
||||
|
||||
use Yii;
|
||||
use common\models\Account;
|
||||
use frontend\models\AccountSearch;
|
||||
use frontend\models\AccountSelect;
|
||||
use yii\web\Controller;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\filters\VerbFilter;
|
||||
use yii\base\Object;
|
||||
|
||||
/**
|
||||
* AccountController implements the CRUD actions for Account model.
|
||||
*/
|
||||
class AccountController extends Controller
|
||||
{
|
||||
public function behaviors()
|
||||
{
|
||||
return [
|
||||
'verbs' => [
|
||||
'class' => VerbFilter::className(),
|
||||
'actions' => [
|
||||
'delete' => ['post'],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Lists all Account models.
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionSelect()
|
||||
{
|
||||
$model = new AccountSelect();
|
||||
|
||||
$model->id_account = Account::readDefault();
|
||||
|
||||
$accounts = Account::read();
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->writeToSession()) {
|
||||
Yii::$app->session->setFlash('success', Yii::t('frontend/ticket', 'Default session is set!') );
|
||||
}
|
||||
return $this->render('select', [
|
||||
'model' => $model,
|
||||
'accounts' => $accounts
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all Account models.
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionIndex()
|
||||
{
|
||||
$searchModel = new AccountSearch();
|
||||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
||||
|
||||
return $this->render('index', [
|
||||
'searchModel' => $searchModel,
|
||||
'dataProvider' => $dataProvider,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a single Account model.
|
||||
* @param integer $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionView($id)
|
||||
{
|
||||
return $this->render('view', [
|
||||
'model' => $this->findModel($id),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Account model.
|
||||
* If creation is successful, the browser will be redirected to the 'view' page.
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionCreate()
|
||||
{
|
||||
$model = new Account();
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
return $this->redirect(['view', 'id' => $model->id_account]);
|
||||
} else {
|
||||
return $this->render('create', [
|
||||
'model' => $model,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates an existing Account 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]);
|
||||
} else {
|
||||
return $this->render('update', [
|
||||
'model' => $model,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an existing Account 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']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the Account model based on its primary key value.
|
||||
* If the model is not found, a 404 HTTP exception will be thrown.
|
||||
* @param integer $id
|
||||
* @return Account the loaded model
|
||||
* @throws NotFoundHttpException if the model cannot be found
|
||||
*/
|
||||
protected function findModel($id)
|
||||
{
|
||||
if (($model = Account::findOne($id)) !== null) {
|
||||
return $model;
|
||||
} else {
|
||||
throw new NotFoundHttpException('The requested page does not exist.');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -55,6 +55,14 @@ class CustomerController extends Controller
|
||||
$model->readCard();
|
||||
|
||||
|
||||
if ( $model->isFreeCard() ){
|
||||
return $this->redirect([ 'create', 'number' => $model->card->number ]);
|
||||
}else if ( $model->isCustomerWithTicket()){
|
||||
return $this->redirect([ 'product/sale', 'number' => $model->card->number ]);
|
||||
}else if ( $model->isCardWithCustomer() ){
|
||||
return $this->redirect([ 'ticket/create', 'number' => $model->card->number ]);
|
||||
}
|
||||
|
||||
return $this->render('reception',['model' => $model]);
|
||||
}
|
||||
|
||||
@@ -102,6 +110,10 @@ class CustomerController extends Controller
|
||||
$model->id_user = Yii::$app->user->id;
|
||||
|
||||
|
||||
$receptionForm = new ReceptionForm();
|
||||
$receptionForm->number = $number;
|
||||
$receptionForm->readCard();
|
||||
|
||||
if ( isset($number)){
|
||||
$model->cardNumber = $number;
|
||||
}
|
||||
@@ -112,6 +124,7 @@ class CustomerController extends Controller
|
||||
} else {
|
||||
return $this->render('create', [
|
||||
'model' => $model,
|
||||
'receptionForm' => $receptionForm
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -126,6 +139,11 @@ class CustomerController extends Controller
|
||||
{
|
||||
$card = null;
|
||||
$model = null;
|
||||
|
||||
$receptionForm = new ReceptionForm();
|
||||
$receptionForm->number = $number;
|
||||
$receptionForm->readCard();
|
||||
|
||||
if ( $number != null ){
|
||||
$card = Card::readCard($number);
|
||||
if ( $card != null ){
|
||||
@@ -151,6 +169,7 @@ class CustomerController extends Controller
|
||||
|
||||
return $this->render('update', [
|
||||
'model' => $model,
|
||||
'receptionForm' => $receptionForm
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,6 +65,7 @@ class MoneyMovementController extends Controller
|
||||
|
||||
$model->id_user = Yii::$app->user->id;
|
||||
$model->type = MoneyMovement::TYPE_OUT;
|
||||
$model->id_account = Account::readDefault();
|
||||
|
||||
$accounts = Account::read();
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ use common\models\Transfer;
|
||||
use common\models\User;
|
||||
use common\models\UserSoldItem;
|
||||
use common\models\ShoppingCart;
|
||||
|
||||
use frontend\models\ReceptionForm;
|
||||
/**
|
||||
* ProductController implements the CRUD actions for Product model.
|
||||
*/
|
||||
@@ -58,7 +58,14 @@ class ProductController extends Controller
|
||||
|
||||
public function actionSale( $number = null){
|
||||
|
||||
$this->findByNumber($number);
|
||||
// $this->findByNumber($number);
|
||||
|
||||
$receptionForm = new ReceptionForm() ;
|
||||
$receptionForm->number = $number;
|
||||
$receptionForm->readCard();
|
||||
|
||||
$this->card = $receptionForm->card;
|
||||
$this->customer = $receptionForm->customer;
|
||||
|
||||
$model = new ProductSaleForm();
|
||||
|
||||
@@ -83,6 +90,7 @@ class ProductController extends Controller
|
||||
$model->accounts = $accounts;
|
||||
$model->discounts = $discounts;
|
||||
|
||||
$model->id_account = Account::readDefault();
|
||||
|
||||
$result = [];
|
||||
$result['code'] = 'unknown';
|
||||
@@ -120,6 +128,7 @@ class ProductController extends Controller
|
||||
'accounts' => $accounts,
|
||||
'discounts' => $discounts,
|
||||
'userTransfers' => $userTransfers,
|
||||
'receptionForm' => $receptionForm,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -80,9 +80,7 @@ class TicketController extends Controller
|
||||
{
|
||||
|
||||
$receptionForm = new ReceptionForm();
|
||||
|
||||
$receptionForm->number = $number;
|
||||
|
||||
$receptionForm->readCard();
|
||||
|
||||
if ( !isset($receptionForm->card ) ){
|
||||
@@ -104,6 +102,7 @@ class TicketController extends Controller
|
||||
$model->status = Ticket::STATUS_ACTIVE;
|
||||
$model->usage_count = 0;
|
||||
$model->id_card = $receptionForm->card->id_card;
|
||||
$model->id_account = Account::readDefault();
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
Yii::$app->session->setFlash('success', Yii::t('frontend/ticket', 'Ticket added to customer') );
|
||||
|
||||
Reference in New Issue
Block a user