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; ?>
- = Html::a(Yii::t('common/ticket_type', 'Create Product'), ['create'], ['class' => 'btn btn-success']) ?> + = Html::a(Yii::t('common/product', 'Create Product'), ['create'], ['class' => 'btn btn-success']) ?>
= GridView::widget([ 'dataProvider' => $dataProvider, 'columns' => [ [ - 'attribute' => 'id_product_type', + 'attribute' => 'name', + ], + [ + 'attribute' => 'id_product_category', 'value' => 'productCategoryName', ], [ @@ -32,15 +35,16 @@ $this->params['breadcrumbs'][] = $this->title; ], 'product_number', 'barcode', - 'purchase_price', 'sale_price', - 'profit_margins', - 'status', - 'description', - 'created_at:datetime', - 'updated_at:datetime', + [ + 'attribute' => 'status', + 'value' => 'statusHuman', + + ], - ['class' => 'yii\grid\ActionColumn'], + ['class' => 'yii\grid\ActionColumn', + 'template' => '{view} {update}' + ], ], ]); ?> diff --git a/backend/views/product/update.php b/backend/views/product/update.php index 2b6f0a3..30cf1f0 100644 --- a/backend/views/product/update.php +++ b/backend/views/product/update.php @@ -5,12 +5,10 @@ use yii\helpers\Html; /* @var $this yii\web\View */ /* @var $model common\models\Product */ -$this->title = Yii::t('common/ticket_type', 'Update {modelClass}: ', [ - 'modelClass' => 'Product', -]) . ' ' . $model->id_product; -$this->params['breadcrumbs'][] = ['label' => Yii::t('common/ticket_type', 'Products'), 'url' => ['index']]; -$this->params['breadcrumbs'][] = ['label' => $model->id_product, 'url' => ['view', 'id' => $model->id_product]]; -$this->params['breadcrumbs'][] = Yii::t('common/ticket_type', 'Update'); +$this->title = Yii::t('common/product', 'Update product:' ) . ' ' . $model->name; +$this->params['breadcrumbs'][] = ['label' => Yii::t('common/product', 'Products'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id_product]]; +$this->params['breadcrumbs'][] = Yii::t('common/product', 'Update'); ?>- = Html::a(Yii::t('common/ticket_type', 'Update'), ['update', 'id' => $model->id_product], ['class' => 'btn btn-primary']) ?> - = Html::a(Yii::t('common/ticket_type', 'Delete'), ['delete', 'id' => $model->id_product], [ - 'class' => 'btn btn-danger', - 'data' => [ - 'confirm' => Yii::t('common/ticket_type', 'Are you sure you want to delete this item?'), - 'method' => 'post', - ], - ]) ?> + = Html::a(Yii::t('common/product', 'Update'), ['update', 'id' => $model->id_product], ['class' => 'btn btn-primary']) ?>
= DetailView::widget([ 'model' => $model, 'attributes' => [ - 'id_product', - 'id_product_type', - 'id_account', + 'productCategoryName', + 'accountName', 'product_number', 'barcode', 'purchase_price', 'sale_price', 'profit_margins', - 'status', - 'description', - 'created_at', - 'updated_at', + 'statusHuman', + [ + 'attribute' => 'description', + 'value' => nl2br($model->description), + 'format' => 'raw' + ], + 'created_at:datetime', + 'updated_at:datetime', ], ]) ?> diff --git a/common/messages/hu/common/product.php b/common/messages/hu/common/product.php new file mode 100644 index 0000000..da3e15f --- /dev/null +++ b/common/messages/hu/common/product.php @@ -0,0 +1,43 @@ + 'Aktív', + 'All' => 'Mind', + 'Barcode' => 'Vonalkód', + 'Create' => 'Mentés', + 'Create Product' => 'Új termék', + 'Created At' => 'Létrehozás ideje', + 'Description' => 'Leírás', + 'Id Account' => 'Kassza', + 'Id Product' => 'Termék', + 'Id Product Category' => 'Termék kategória', + 'Inactive' => 'Inaktív', + 'Max 255 character' => 'Max 255 karakter', + 'Name' => 'Név', + 'Product Number' => 'Termék szám', + 'Products' => 'Termékek', + 'Profit Margins' => 'Haszonkulcs', + 'Purchase Price' => 'Beszerzési ár', + 'Sale Price' => 'Eladási ár', + 'Search' => 'Keresés', + 'Status' => 'Státusz', + 'Update' => 'Módosítás', + 'Update product:' => 'Termék módosítása:', + 'Updated At' => 'Módosítás ideje', +]; diff --git a/common/models/Product.php b/common/models/Product.php index 41600ab..6410e4f 100644 --- a/common/models/Product.php +++ b/common/models/Product.php @@ -8,7 +8,8 @@ use Yii; * This is the model class for table "product". * * @property integer $id_product - * @property integer $id_product_type + * @property string $name length 64 + * @property integer $id_product_category * @property integer $id_account * @property string $product_number * @property string $barcode @@ -16,6 +17,7 @@ use Yii; * @property integer $sale_price * @property integer $profit_margins * @property integer $status + * @property integer $stock * @property string $description * @property string $created_at * @property string $updated_at @@ -39,10 +41,13 @@ class Product extends \common\models\BaseFitnessActiveRecord { public function rules() { return [ - [['id_product_type', 'id_account'], 'required'], - [['id_product_type', 'id_account', 'purchase_price', 'sale_price', 'profit_margins', 'status'], 'integer'], + [['id_product_category', 'id_account', 'name'], 'required'], + [['id_product_category', 'id_account', 'purchase_price', 'sale_price', 'profit_margins', 'status'], 'integer'], [['product_number', 'barcode'], 'string', 'max' => 20], - [['description'], 'string', 'max' => 255] + [['name'], 'string', 'max' => 128], + [['description'], 'string', 'max' => 255], + [['product_number'], 'unique' ], + [['barcode'], 'unique' ], ]; } @@ -53,7 +58,7 @@ class Product extends \common\models\BaseFitnessActiveRecord { { return [ 'id_product' => Yii::t('common/product', 'Id Product'), - 'id_product_type' => Yii::t('common/product', 'Id Product Type'), + 'id_product_category' => Yii::t('common/product', 'Id Product Category'), 'id_account' => Yii::t('common/product', 'Id Account'), 'product_number' => Yii::t('common/product', 'Product Number'), 'barcode' => Yii::t('common/product', 'Barcode'), @@ -61,6 +66,7 @@ class Product extends \common\models\BaseFitnessActiveRecord { 'sale_price' => Yii::t('common/product', 'Sale Price'), 'profit_margins' => Yii::t('common/product', 'Profit Margins'), 'status' => Yii::t('common/product', 'Status'), + 'name' => Yii::t('common/product', 'Name'), 'description' => Yii::t('common/product', 'Description'), 'created_at' => Yii::t('common/product', 'Created At'), 'updated_at' => Yii::t('common/product', 'Updated At'), diff --git a/common/models/ProductCategory.php b/common/models/ProductCategory.php index 70b255a..cb5dd4d 100644 --- a/common/models/ProductCategory.php +++ b/common/models/ProductCategory.php @@ -69,4 +69,20 @@ class ProductCategory extends \common\models\BaseFitnessActiveRecord return $result; } + + /** + * $param int $forceIncludeAccount id account, that should be included in list, even if it is inactive + * */ + public static function read($forceIncludeObjectWithId = null){ + $categories = null; + + if ( $forceIncludeObjectWithId == null){ + $categories = ProductCategory::find()->andWhere(['status' => ProductCategory::STATUS_ACTIVE])->all(); + }else{ + $categories = ProductCategory::find()->andWhere( ['or', ['status' => ProductCategory::STATUS_ACTIVE], ['id_product_category' => $forceIncludeObjectWithId ] ])->all(); + } + + return $categories; + } + } diff --git a/composer.json b/composer.json index 4ef624f..22993b0 100644 --- a/composer.json +++ b/composer.json @@ -17,8 +17,7 @@ "php": ">=5.4.0", "yiisoft/yii2": ">=2.0.6", "yiisoft/yii2-bootstrap": "*", - "yiisoft/yii2-swiftmailer": "*", - "npm-asset/grunt": "^0.4.5" + "yiisoft/yii2-swiftmailer": "*" }, "require-dev": { "yiisoft/yii2-codeception": "*", diff --git a/composer.lock b/composer.lock index e7e2ee1..6a29fb3 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "5fe15fcdcc6c43b39968ffd29104ac62", + "hash": "8580bd82955b1fbb80d47024e184056e", "packages": [ { "name": "bower-asset/bootstrap", diff --git a/console/migrations/m150924_162425_alter__table__product_fix_columns.php b/console/migrations/m150924_162425_alter__table__product_fix_columns.php new file mode 100644 index 0000000..475db33 --- /dev/null +++ b/console/migrations/m150924_162425_alter__table__product_fix_columns.php @@ -0,0 +1,32 @@ +renameColumn('product','id_product_type','id_product_category'); + $this->addColumn('product','stock', 'int(11)' ); + } + + public function down() + { + echo "m150924_162425_alter__table__product_fix_columns cannot be reverted.\n"; + + return false; + } + + /* + // Use safeUp/safeDown to run migration code within a transaction + public function safeUp() + { + } + + public function safeDown() + { + } + */ +} diff --git a/console/migrations/m150924_170806_alter__table__product__add__column__name.php b/console/migrations/m150924_170806_alter__table__product__add__column__name.php new file mode 100644 index 0000000..8dac7a9 --- /dev/null +++ b/console/migrations/m150924_170806_alter__table__product__add__column__name.php @@ -0,0 +1,30 @@ +addColumn('product','name', 'varchar(128)' ); + } + + public function down() + { + echo "m150924_170806_alter__table__product__add__column__name cannot be reverted.\n"; + + return false; + } + + /* + // Use safeUp/safeDown to run migration code within a transaction + public function safeUp() + { + } + + public function safeDown() + { + } + */ +}