add product
This commit is contained in:
@@ -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 ,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -11,13 +11,18 @@ use yii\helpers\ArrayHelper;
|
||||
?>
|
||||
<?php
|
||||
$account_options = ArrayHelper::map($accounts, 'id_account', 'name');
|
||||
$product_category_options = ArrayHelper::map($categories, 'id_product_category', 'name');
|
||||
|
||||
?>
|
||||
<div class="product-form">
|
||||
|
||||
<?php $form = ActiveForm::begin(); ?>
|
||||
|
||||
<?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
|
||||
|
||||
<?= $form->field($model, 'id_account')->dropDownList($account_options) ?>
|
||||
|
||||
<?= $form->field($model, 'id_product_category')->dropDownList($product_category_options) ?>
|
||||
|
||||
<?= $form->field($model, 'product_number')->textInput(['maxlength' => true]) ?>
|
||||
|
||||
@@ -31,10 +36,10 @@ $account_options = ArrayHelper::map($accounts, 'id_account', 'name');
|
||||
|
||||
<?= $form->field($model, 'status')->checkbox( ['value' => 10, 'label' => Yii::t('common/product', "Active") ]) ?>
|
||||
|
||||
<?= $form->field($model, 'description')->textarea(['maxlength' => true])->hint( Yii::t( 'common/prodcut', "Max 255 character")) ?>
|
||||
<?= $form->field($model, 'description')->textarea(['maxlength' => true])->hint( Yii::t( 'common/product', "Max 255 character")) ?>
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton($model->isNewRecord ? Yii::t('common/ticket_type', 'Create') : Yii::t('common/ticket_type', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
|
||||
<?= Html::submitButton($model->isNewRecord ? Yii::t('common/product', 'Create') : Yii::t('common/product', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
|
||||
</div>
|
||||
|
||||
<?php ActiveForm::end(); ?>
|
||||
|
||||
@@ -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 */
|
||||
?>
|
||||
<?php
|
||||
|
||||
function mkOptions($options){
|
||||
$o = $options;
|
||||
$o[''] = Yii::t('common/product','All' ) ;
|
||||
return $o;
|
||||
}
|
||||
|
||||
$statusOptions = mkOptions( Product::statuses() );
|
||||
|
||||
$productCategories = mkOptions( ArrayHelper::map( ProductCategory::read(null) ,'id_product_category','name') );
|
||||
|
||||
$accounts = mkOptions( ArrayHelper::map( Account::readAccounts(null) ,'id_account','name'));
|
||||
|
||||
?>
|
||||
<div class="product-search">
|
||||
|
||||
<?php $form = ActiveForm::begin([
|
||||
@@ -15,33 +33,29 @@ use yii\widgets\ActiveForm;
|
||||
'method' => 'get',
|
||||
]); ?>
|
||||
|
||||
<?= $form->field($model, 'id_product') ?>
|
||||
|
||||
<?= $form->field($model, 'id_product_type') ?>
|
||||
|
||||
<?= $form->field($model, 'id_account') ?>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<?= $form->field($model, 'id_product_category')->dropDownList($productCategories) ?>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<?= $form->field($model, 'id_account')->dropDownList($accounts) ?>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<?php echo $form->field($model, 'status')->dropDownList($statusOptions) ?>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<?= $form->field($model, 'product_number') ?>
|
||||
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<?= $form->field($model, 'barcode') ?>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php // echo $form->field($model, 'purchase_price') ?>
|
||||
|
||||
<?php // echo $form->field($model, 'sale_price') ?>
|
||||
|
||||
<?php // echo $form->field($model, 'profit_margins') ?>
|
||||
|
||||
<?php // echo $form->field($model, 'status') ?>
|
||||
|
||||
<?php // echo $form->field($model, 'description') ?>
|
||||
|
||||
<?php // echo $form->field($model, 'created_at') ?>
|
||||
|
||||
<?php // echo $form->field($model, 'updated_at') ?>
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton(Yii::t('common/ticket_type', 'Search'), ['class' => 'btn btn-primary']) ?>
|
||||
<?= Html::resetButton(Yii::t('common/ticket_type', 'Reset'), ['class' => 'btn btn-default']) ?>
|
||||
<?= Html::submitButton(Yii::t('common/product', 'Search'), ['class' => 'btn btn-primary']) ?>
|
||||
</div>
|
||||
|
||||
<?php ActiveForm::end(); ?>
|
||||
|
||||
@@ -7,8 +7,8 @@ use yii\helpers\Html;
|
||||
/* @var $model common\models\Product */
|
||||
/* @var $accounts common\models\Account[] */
|
||||
|
||||
$this->title = Yii::t('common/ticket_type', 'Create Product');
|
||||
$this->params['breadcrumbs'][] = ['label' => Yii::t('common/ticket_type', 'Products'), 'url' => ['index']];
|
||||
$this->title = Yii::t('common/product', 'Create Product');
|
||||
$this->params['breadcrumbs'][] = ['label' => Yii::t('common/product', 'Products'), 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
?>
|
||||
<div class="product-create">
|
||||
@@ -18,6 +18,7 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
<?= $this->render('_form', [
|
||||
'model' => $model,
|
||||
'accounts' => $accounts,
|
||||
'categories' => $categories ,
|
||||
]) ?>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -7,23 +7,26 @@ use yii\grid\GridView;
|
||||
/* @var $searchModel backend\models\ProductSearch */
|
||||
/* @var $dataProvider yii\data\ActiveDataProvider */
|
||||
|
||||
$this->title = Yii::t('common/ticket_type', 'Products');
|
||||
$this->title = Yii::t('common/product', 'Products');
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
?>
|
||||
<div class="product-index">
|
||||
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
|
||||
<?php echo $this->render('_search', ['model' => $searchModel]); ?>
|
||||
|
||||
<p>
|
||||
<?= 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']) ?>
|
||||
</p>
|
||||
|
||||
<?= 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}'
|
||||
],
|
||||
],
|
||||
]); ?>
|
||||
|
||||
|
||||
@@ -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');
|
||||
?>
|
||||
<div class="product-update">
|
||||
|
||||
@@ -18,6 +16,8 @@ $this->params['breadcrumbs'][] = Yii::t('common/ticket_type', 'Update');
|
||||
|
||||
<?= $this->render('_form', [
|
||||
'model' => $model,
|
||||
'accounts' => $accounts,
|
||||
'categories' => $categories ,
|
||||
]) ?>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -6,8 +6,8 @@ use yii\widgets\DetailView;
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model common\models\Product */
|
||||
|
||||
$this->title = $model->id_product;
|
||||
$this->params['breadcrumbs'][] = ['label' => Yii::t('common/ticket_type', 'Products'), 'url' => ['index']];
|
||||
$this->title = $model->name ;
|
||||
$this->params['breadcrumbs'][] = ['label' => Yii::t('common/product', 'Products'), 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
?>
|
||||
<div class="product-view">
|
||||
@@ -15,31 +15,27 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
|
||||
<p>
|
||||
<?= 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']) ?>
|
||||
</p>
|
||||
|
||||
<?= 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',
|
||||
],
|
||||
]) ?>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user