add rfid check to card package import

This commit is contained in:
Roland Schneider 2016-07-30 20:08:42 +02:00
parent 167d614927
commit d6c570a31b

View File

@ -21,7 +21,8 @@ use common\components\Upload;
/** /**
* CardPackageController implements the CRUD actions for CardPackage model. * CardPackageController implements the CRUD actions for CardPackage model.
*/ */
class CardPackageController extends \backend\controllers\BackendController { class CardPackageController extends \backend\controllers\BackendController
{
public function behaviors() public function behaviors()
@ -41,12 +42,14 @@ class CardPackageController extends \backend\controllers\BackendController {
], ],
]; ];
} }
/** /**
* Lists all CardPackage models. * Lists all CardPackage models.
* *
* @return mixed * @return mixed
*/ */
public function actionIndex() { public function actionIndex()
{
$searchModel = new CardPackageSearch (); $searchModel = new CardPackageSearch ();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams); $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
@ -62,7 +65,8 @@ class CardPackageController extends \backend\controllers\BackendController {
* @param integer $id * @param integer $id
* @return mixed * @return mixed
*/ */
public function actionView($id) { public function actionView($id)
{
$model = $this->findModel($id); $model = $this->findModel($id);
$query = Card::find(); $query = Card::find();
@ -80,7 +84,9 @@ class CardPackageController extends \backend\controllers\BackendController {
'dataProvider' => $dataProvider 'dataProvider' => $dataProvider
]); ]);
} }
public function actionDownload($id) {
public function actionDownload($id)
{
$model = $this->findModel($id); $model = $this->findModel($id);
$model->updateCounters([ $model->updateCounters([
@ -109,7 +115,8 @@ class CardPackageController extends \backend\controllers\BackendController {
* *
* @return mixed * @return mixed
*/ */
public function actionCreate() { public function actionCreate()
{
$model = new CardPackage (); $model = new CardPackage ();
$model->id_user = \Yii::$app->user->id; $model->id_user = \Yii::$app->user->id;
$model->printed = 0; $model->printed = 0;
@ -163,7 +170,9 @@ class CardPackageController extends \backend\controllers\BackendController {
]); ]);
} }
} }
protected function generateXLS($model, $numbers) {
protected function generateXLS($model, $numbers)
{
$objPHPExcel = new \PHPExcel (); $objPHPExcel = new \PHPExcel ();
$sheet = $objPHPExcel->setActiveSheetIndex(0); $sheet = $objPHPExcel->setActiveSheetIndex(0);
@ -201,14 +210,15 @@ class CardPackageController extends \backend\controllers\BackendController {
$objWriter->save('php://output'); $objWriter->save('php://output');
exit (); exit ();
} }
public function actionImport() {
public function actionImport()
{
$model = new CardPackageImportForm (); $model = new CardPackageImportForm ();
if (Yii::$app->request->isPost) { if (Yii::$app->request->isPost) {
$model->file = UploadedFile::getInstance($model, 'file'); $model->file = UploadedFile::getInstance($model, 'file');
if ($model->validate()) { if ($model->validate()) {
@ -230,6 +240,17 @@ class CardPackageController extends \backend\controllers\BackendController {
try { try {
$tx = \Yii::$app->db->beginTransaction(); $tx = \Yii::$app->db->beginTransaction();
$rfidIsValid = false;
$rfid = $row[2];
if (isset($rfid) && !empty($rfid) && strlen($rfid) > 8) {
$rfidIsValid = true;
}
if ( !$rfidIsValid ){
throw new \Exception("Rfid is invalid");
}
$card = Card::find()->andWhere([ $card = Card::find()->andWhere([
'number' => $row [0] 'number' => $row [0]
])->one(); ])->one();
@ -241,10 +262,10 @@ class CardPackageController extends \backend\controllers\BackendController {
throw new \Exception("Card not found"); throw new \Exception("Card not found");
} }
$tx->commit(); $tx->commit();
$model->done = $model->done + 1; $model->done = $model->done + 1;
} catch (\Exception $e) { } catch (\Exception $e) {
$tx->rollBack(); $tx->rollBack();
$model->failed = $model->failed + 1; $model->failed = $model->failed + 1;
@ -273,7 +294,8 @@ class CardPackageController extends \backend\controllers\BackendController {
* @param integer $id * @param integer $id
* @return mixed * @return mixed
*/ */
public function actionUpdate($id) { public function actionUpdate($id)
{
$model = $this->findModel($id); $model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) { if ($model->load(Yii::$app->request->post()) && $model->save()) {
@ -295,7 +317,8 @@ class CardPackageController extends \backend\controllers\BackendController {
* @param integer $id * @param integer $id
* @return mixed * @return mixed
*/ */
public function actionDelete($id) { public function actionDelete($id)
{
$this->findModel($id)->delete(); $this->findModel($id)->delete();
return $this->redirect([ return $this->redirect([
@ -311,7 +334,8 @@ class CardPackageController extends \backend\controllers\BackendController {
* @return CardPackage the loaded model * @return CardPackage the loaded model
* @throws NotFoundHttpException if the model cannot be found * @throws NotFoundHttpException if the model cannot be found
*/ */
protected function findModel($id) { protected function findModel($id)
{
if (($model = CardPackage::findOne($id)) !== null) { if (($model = CardPackage::findOne($id)) !== null) {
return $model; return $model;
} else { } else {