From a2b835225a9c27d7f711322bd052a36ff74909af Mon Sep 17 00:00:00 2001 From: rocho Date: Thu, 24 Sep 2015 22:14:09 +0200 Subject: [PATCH] add product --- backend/controllers/ProductController.php | 12 +++- backend/models/ProductSearch.php | 15 ++--- backend/views/product/_form.php | 9 ++- backend/views/product/_search.php | 58 ++++++++++++------- backend/views/product/create.php | 5 +- backend/views/product/index.php | 26 +++++---- backend/views/product/update.php | 12 ++-- backend/views/product/view.php | 30 +++++----- common/messages/hu/common/product.php | 43 ++++++++++++++ common/models/Product.php | 16 +++-- common/models/ProductCategory.php | 16 +++++ composer.json | 3 +- composer.lock | 2 +- ...2425_alter__table__product_fix_columns.php | 32 ++++++++++ ...ter__table__product__add__column__name.php | 30 ++++++++++ 15 files changed, 229 insertions(+), 80 deletions(-) create mode 100644 common/messages/hu/common/product.php create mode 100644 console/migrations/m150924_162425_alter__table__product_fix_columns.php create mode 100644 console/migrations/m150924_170806_alter__table__product__add__column__name.php diff --git a/backend/controllers/ProductController.php b/backend/controllers/ProductController.php index 3ce635f..24da95f 100644 --- a/backend/controllers/ProductController.php +++ b/backend/controllers/ProductController.php @@ -9,6 +9,7 @@ use yii\web\Controller; use yii\web\NotFoundHttpException; use yii\filters\VerbFilter; use common\models\Account; +use common\models\ProductCategory; /** * ProductController implements the CRUD actions for Product model. @@ -62,8 +63,10 @@ class ProductController extends Controller public function actionCreate() { $model = new Product(); + $model->stock = 0; + $model->status = Product::STATUS_ACTIVE; $accounts = Account::readAccounts(null); - + $categories = ProductCategory::read(null); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id_product]); @@ -71,6 +74,8 @@ class ProductController extends Controller return $this->render('create', [ 'model' => $model, 'accounts' => $accounts, + 'categories' => $categories , + ]); } } @@ -85,11 +90,16 @@ class ProductController extends Controller { $model = $this->findModel($id); + $accounts = Account::readAccounts($model->id_account); + $categories = ProductCategory::read($model->id_product_category); + if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id_product]); } else { return $this->render('update', [ 'model' => $model, + 'accounts' => $accounts, + 'categories' => $categories , ]); } } diff --git a/backend/models/ProductSearch.php b/backend/models/ProductSearch.php index a528662..a74a216 100644 --- a/backend/models/ProductSearch.php +++ b/backend/models/ProductSearch.php @@ -18,8 +18,8 @@ class ProductSearch extends Product public function rules() { return [ - [['id_product', 'id_product_type', 'id_account', 'purchase_price', 'sale_price', 'profit_margins', 'status'], 'integer'], - [['product_number', 'barcode', 'description', 'created_at', 'updated_at'], 'safe'], + [[ 'id_product_category', 'id_account', 'status'], 'integer'], + [['product_number', 'barcode' ], 'safe'], ]; } @@ -56,20 +56,13 @@ class ProductSearch extends Product } $query->andFilterWhere([ - 'id_product' => $this->id_product, - 'id_product_type' => $this->id_product_type, + 'id_product_category' => $this->id_product_category, 'id_account' => $this->id_account, - 'purchase_price' => $this->purchase_price, - 'sale_price' => $this->sale_price, - 'profit_margins' => $this->profit_margins, 'status' => $this->status, - 'created_at' => $this->created_at, - 'updated_at' => $this->updated_at, ]); $query->andFilterWhere(['like', 'product_number', $this->product_number]) - ->andFilterWhere(['like', 'barcode', $this->barcode]) - ->andFilterWhere(['like', 'description', $this->description]); + ->andFilterWhere(['like', 'barcode', $this->barcode]); return $dataProvider; } diff --git a/backend/views/product/_form.php b/backend/views/product/_form.php index 941c04d..182b4b5 100644 --- a/backend/views/product/_form.php +++ b/backend/views/product/_form.php @@ -11,13 +11,18 @@ use yii\helpers\ArrayHelper; ?>
+ field($model, 'name')->textInput(['maxlength' => true]) ?> field($model, 'id_account')->dropDownList($account_options) ?> + + field($model, 'id_product_category')->dropDownList($product_category_options) ?> field($model, 'product_number')->textInput(['maxlength' => true]) ?> @@ -31,10 +36,10 @@ $account_options = ArrayHelper::map($accounts, 'id_account', 'name'); field($model, 'status')->checkbox( ['value' => 10, 'label' => Yii::t('common/product', "Active") ]) ?> - field($model, 'description')->textarea(['maxlength' => true])->hint( Yii::t( 'common/prodcut', "Max 255 character")) ?> + field($model, 'description')->textarea(['maxlength' => true])->hint( Yii::t( 'common/product', "Max 255 character")) ?>
- isNewRecord ? Yii::t('common/ticket_type', 'Create') : Yii::t('common/ticket_type', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> + isNewRecord ? Yii::t('common/product', 'Create') : Yii::t('common/product', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
diff --git a/backend/views/product/_search.php b/backend/views/product/_search.php index aba1bcc..0ce8aa3 100644 --- a/backend/views/product/_search.php +++ b/backend/views/product/_search.php @@ -2,12 +2,30 @@ use yii\helpers\Html; use yii\widgets\ActiveForm; +use common\models\Product; +use common\models\ProductCategory; +use yii\helpers\ArrayHelper; +use common\models\Account; /* @var $this yii\web\View */ /* @var $model backend\models\ProductSearch */ /* @var $form yii\widgets\ActiveForm */ ?> +