add changes to procurement
This commit is contained in:
parent
28caac03dc
commit
5c9db98110
@ -9,6 +9,8 @@ use yii\web\Controller;
|
|||||||
use yii\web\NotFoundHttpException;
|
use yii\web\NotFoundHttpException;
|
||||||
use yii\filters\VerbFilter;
|
use yii\filters\VerbFilter;
|
||||||
use common\models\Warehouse;
|
use common\models\Warehouse;
|
||||||
|
use common\models\Product;
|
||||||
|
use common\models\User;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ProcurementController implements the CRUD actions for Procurement model.
|
* ProcurementController implements the CRUD actions for Procurement model.
|
||||||
@ -33,12 +35,20 @@ class ProcurementController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function actionIndex()
|
public function actionIndex()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
$warehouses = Warehouse::read(null);
|
||||||
|
$products = Product::read(null);
|
||||||
|
$users = User::read(null);
|
||||||
|
|
||||||
$searchModel = new ProcurementSearch();
|
$searchModel = new ProcurementSearch();
|
||||||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
||||||
|
|
||||||
return $this->render('index', [
|
return $this->render('index', [
|
||||||
'searchModel' => $searchModel,
|
'searchModel' => $searchModel,
|
||||||
'dataProvider' => $dataProvider,
|
'dataProvider' => $dataProvider,
|
||||||
|
'users' => $users,
|
||||||
|
'products' => $products,
|
||||||
|
'warehouses' => $warehouses,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,12 +72,42 @@ class ProcurementController extends Controller
|
|||||||
public function actionCreate()
|
public function actionCreate()
|
||||||
{
|
{
|
||||||
$model = new Procurement();
|
$model = new Procurement();
|
||||||
|
$model->scenario = 'create_general';
|
||||||
|
|
||||||
$model->id_user = Yii::$app->user->id;
|
$model->id_user = Yii::$app->user->id;
|
||||||
|
|
||||||
$warehouses = Warehouse::read(null);
|
$warehouses = Warehouse::read(null);
|
||||||
|
|
||||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
if ( count($warehouses) <= 0 ){
|
||||||
|
throw new NotFoundHttpException( Yii::t('common/procurement' ,'No active warehouse found.' ));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
|
||||||
|
|
||||||
|
$connection = \Yii::$app->db;
|
||||||
|
|
||||||
|
$transaction = $connection->beginTransaction();
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
$product = Product::findOne( $model->id_product );
|
||||||
|
$model->stock = $product->stock;
|
||||||
|
$result = $model->save(false);
|
||||||
|
|
||||||
|
$product->stock = $product->stock + $model->count;
|
||||||
|
$result &= $product->save(false);
|
||||||
|
|
||||||
|
if ($result) {
|
||||||
|
$transaction->commit();
|
||||||
|
} else {
|
||||||
|
$transaction->rollback();
|
||||||
|
}
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$transaction->rollback();
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return $this->redirect(['view', 'id' => $model->id_procurement]);
|
return $this->redirect(['view', 'id' => $model->id_procurement]);
|
||||||
} else {
|
} else {
|
||||||
return $this->render('create', [
|
return $this->render('create', [
|
||||||
@ -76,39 +116,64 @@ class ProcurementController extends Controller
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates an existing Procurement model.
|
* Creates a new Procurement model.
|
||||||
* If update is successful, the browser will be redirected to the 'view' page.
|
* If creation is successful, the browser will be redirected to the 'view' page.
|
||||||
* @param integer $id
|
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function actionUpdate($id)
|
public function actionCreateProduct($id)
|
||||||
{
|
{
|
||||||
$model = $this->findModel($id);
|
|
||||||
|
$product = $this->findProduct($id);
|
||||||
|
|
||||||
|
$model = new Procurement();
|
||||||
|
|
||||||
|
$warehouses = Warehouse::read(null);
|
||||||
|
|
||||||
|
$model->id_user = Yii::$app->user->id;
|
||||||
|
$model->id_product = $product->id_product;
|
||||||
|
$model->stock = $product->stock;
|
||||||
|
|
||||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
$warehouses = Warehouse::read(null);
|
||||||
|
|
||||||
|
if ( count($warehouses) <= 0 ){
|
||||||
|
throw new NotFoundHttpException( Yii::t('common/procurement' ,'No active warehouse found.' ));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
|
||||||
|
|
||||||
|
$connection = \Yii::$app->db;
|
||||||
|
|
||||||
|
$transaction = $connection->beginTransaction();
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
$result = $model->save(false);
|
||||||
|
|
||||||
|
$product->stock = $product->stock + $model->count;
|
||||||
|
$result &= $product->save(false);
|
||||||
|
|
||||||
|
if ($result) {
|
||||||
|
$transaction->commit();
|
||||||
|
} else {
|
||||||
|
$transaction->rollback();
|
||||||
|
}
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$transaction->rollback();
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return $this->redirect(['view', 'id' => $model->id_procurement]);
|
return $this->redirect(['view', 'id' => $model->id_procurement]);
|
||||||
} else {
|
} else {
|
||||||
return $this->render('update', [
|
return $this->render('create_product', [
|
||||||
'model' => $model,
|
'model' => $model,
|
||||||
|
'warehouses' =>$warehouses,
|
||||||
|
'product' => $product
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Deletes an existing Procurement 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 Procurement model based on its primary key value.
|
* Finds the Procurement model based on its primary key value.
|
||||||
* If the model is not found, a 404 HTTP exception will be thrown.
|
* If the model is not found, a 404 HTTP exception will be thrown.
|
||||||
@ -124,4 +189,19 @@ class ProcurementController extends Controller
|
|||||||
throw new NotFoundHttpException('The requested page does not exist.');
|
throw new NotFoundHttpException('The requested page does not exist.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Finds the Product model based on its primary key value.
|
||||||
|
* If the model is not found, a 404 HTTP exception will be thrown.
|
||||||
|
* @param integer $id
|
||||||
|
* @return Procurement the loaded model
|
||||||
|
* @throws NotFoundHttpException if the model cannot be found
|
||||||
|
*/
|
||||||
|
protected function findProduct($id)
|
||||||
|
{
|
||||||
|
if (($model = Product::findOne($id)) !== null) {
|
||||||
|
return $model;
|
||||||
|
} else {
|
||||||
|
throw new NotFoundHttpException('The requested page does not exist.');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,14 +12,22 @@ use common\models\Procurement;
|
|||||||
*/
|
*/
|
||||||
class ProcurementSearch extends Procurement
|
class ProcurementSearch extends Procurement
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public $date_start;
|
||||||
|
public $date_end;
|
||||||
|
|
||||||
|
public $timestampStart;
|
||||||
|
public $timestampEnd;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
public function rules()
|
public function rules()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
[['id_procurement', 'id_warehouse', 'id_user', 'id_product', 'count', 'stock', 'purchase_price'], 'integer'],
|
[[ 'id_warehouse', 'id_user', 'id_product', ], 'integer'],
|
||||||
[['description', 'created_at', 'updated_at'], 'safe'],
|
[[ 'date_start', ], 'date' , 'timestampAttribute' => 'timestampStart' ],
|
||||||
|
[[ 'date_end' , ], 'date' , 'timestampAttribute' => 'timestampEnd' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,18 +64,14 @@ class ProcurementSearch extends Procurement
|
|||||||
}
|
}
|
||||||
|
|
||||||
$query->andFilterWhere([
|
$query->andFilterWhere([
|
||||||
'id_procurement' => $this->id_procurement,
|
|
||||||
'id_warehouse' => $this->id_warehouse,
|
'id_warehouse' => $this->id_warehouse,
|
||||||
'id_user' => $this->id_user,
|
'id_user' => $this->id_user,
|
||||||
'id_product' => $this->id_product,
|
'id_product' => $this->id_product,
|
||||||
'count' => $this->count,
|
|
||||||
'stock' => $this->stock,
|
|
||||||
'purchase_price' => $this->purchase_price,
|
|
||||||
'created_at' => $this->created_at,
|
|
||||||
'updated_at' => $this->updated_at,
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$query->andFilterWhere([ '>=', 'created_at', $this->date_start ] );
|
||||||
|
$query->andFilterWhere([ '<', 'created_at', $this->timestampEnd ] );
|
||||||
|
|
||||||
$query->andFilterWhere(['like', 'description', $this->description]);
|
|
||||||
|
|
||||||
return $dataProvider;
|
return $dataProvider;
|
||||||
}
|
}
|
||||||
|
|||||||
54
backend/views/procurement/_form_product.php
Normal file
54
backend/views/procurement/_form_product.php
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use yii\helpers\Html;
|
||||||
|
use yii\widgets\ActiveForm;
|
||||||
|
use yii\helpers\ArrayHelper;
|
||||||
|
use yii\widgets\DetailView;
|
||||||
|
|
||||||
|
/* @var $this yii\web\View */
|
||||||
|
/* @var $model common\models\Procurement */
|
||||||
|
/* @var $warehouses common\models\Warehouse[] */
|
||||||
|
/* @var $form yii\widgets\ActiveForm */
|
||||||
|
?>
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$warehouseOptions = ArrayHelper::map($warehouses, 'id_warehouse', 'name') ;
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
<h3><?= Yii::t('common/product', 'Product') ?> </h3>
|
||||||
|
<?php
|
||||||
|
|
||||||
|
echo DetailView::widget([
|
||||||
|
'model' => $product,
|
||||||
|
'attributes' =>[
|
||||||
|
'productCategoryName',
|
||||||
|
'accountName',
|
||||||
|
'product_number',
|
||||||
|
'barcode',
|
||||||
|
'stock',
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div class="procurement-form">
|
||||||
|
|
||||||
|
<?php $form = ActiveForm::begin(); ?>
|
||||||
|
|
||||||
|
|
||||||
|
<?= $form->field($model, 'id_warehouse')->dropDownList($warehouseOptions) ?>
|
||||||
|
|
||||||
|
<?= $form->field($model, 'count')->textInput() ?>
|
||||||
|
|
||||||
|
<?= $form->field($model, 'purchase_price')->textInput() ?>
|
||||||
|
|
||||||
|
<?= $form->field($model, 'description')->textarea(['maxlength' => true]) ?>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<?= Html::submitButton($model->isNewRecord ? Yii::t('common/procurement', 'Create') : Yii::t('common/procurement', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php ActiveForm::end(); ?>
|
||||||
|
|
||||||
|
</div>
|
||||||
@ -2,12 +2,35 @@
|
|||||||
|
|
||||||
use yii\helpers\Html;
|
use yii\helpers\Html;
|
||||||
use yii\widgets\ActiveForm;
|
use yii\widgets\ActiveForm;
|
||||||
|
use yii\helpers\ArrayHelper;
|
||||||
|
use kartik\widgets\DatePicker;
|
||||||
|
|
||||||
/* @var $this yii\web\View */
|
/* @var $this yii\web\View */
|
||||||
/* @var $model backend\models\ProcurementSearch */
|
/* @var $model backend\models\ProcurementSearch */
|
||||||
/* @var $form yii\widgets\ActiveForm */
|
/* @var $form yii\widgets\ActiveForm */
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
|
||||||
|
function mkOptions($options){
|
||||||
|
// $o = $options;
|
||||||
|
|
||||||
|
$all = ['' => Yii::t('common/product','All' ) ];
|
||||||
|
|
||||||
|
// $o[''] = Yii::t('common/product','All' ) ;
|
||||||
|
|
||||||
|
$o = $all + $options;
|
||||||
|
|
||||||
|
return $o;
|
||||||
|
}
|
||||||
|
|
||||||
|
$products = mkOptions( ArrayHelper::map( $products ,'id_product','name') );
|
||||||
|
$users = mkOptions( ArrayHelper::map( $users ,'id','username') );
|
||||||
|
$warehouses = mkOptions( ArrayHelper::map( $warehouses ,'id_warehouse','name') );
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
|
||||||
<div class="procurement-search">
|
<div class="procurement-search">
|
||||||
|
|
||||||
<?php $form = ActiveForm::begin([
|
<?php $form = ActiveForm::begin([
|
||||||
@ -15,29 +38,39 @@ use yii\widgets\ActiveForm;
|
|||||||
'method' => 'get',
|
'method' => 'get',
|
||||||
]); ?>
|
]); ?>
|
||||||
|
|
||||||
<?= $form->field($model, 'id_procurement') ?>
|
<div class="row">
|
||||||
|
<div class="col-md-4">
|
||||||
|
<?= $form->field($model, 'id_warehouse')->dropDownList($warehouses) ?>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-4">
|
||||||
|
<?= $form->field($model, 'id_user')->dropDownList($users) ?>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-4">
|
||||||
|
<?= $form->field($model, 'id_product')->dropDownList($products) ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-4">
|
||||||
|
<?= $form->field($model, 'date_start')->widget(DatePicker::classname(), [
|
||||||
|
'pluginOptions' => [
|
||||||
|
'autoclose'=>true,
|
||||||
|
'format' => 'yyyy.mm.dd'
|
||||||
|
]
|
||||||
|
]) ?>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-4">
|
||||||
|
<?= $form->field($model, 'date_end') ->widget(DatePicker::classname(), [
|
||||||
|
'pluginOptions' => [
|
||||||
|
'autoclose'=>true,
|
||||||
|
'format' => 'yyyy.mm.dd'
|
||||||
|
]
|
||||||
|
]) ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<?= $form->field($model, 'id_warehouse') ?>
|
|
||||||
|
|
||||||
<?= $form->field($model, 'id_user') ?>
|
|
||||||
|
|
||||||
<?= $form->field($model, 'id_product') ?>
|
|
||||||
|
|
||||||
<?= $form->field($model, 'count') ?>
|
|
||||||
|
|
||||||
<?php // echo $form->field($model, 'stock') ?>
|
|
||||||
|
|
||||||
<?php // echo $form->field($model, 'purchase_price') ?>
|
|
||||||
|
|
||||||
<?php // echo $form->field($model, 'description') ?>
|
|
||||||
|
|
||||||
<?php // echo $form->field($model, 'created_at') ?>
|
|
||||||
|
|
||||||
<?php // echo $form->field($model, 'updated_at') ?>
|
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<?= Html::submitButton(Yii::t('common/procurement', 'Search'), ['class' => 'btn btn-primary']) ?>
|
<?= Html::submitButton(Yii::t('common/procurement', 'Search'), ['class' => 'btn btn-primary']) ?>
|
||||||
<?= Html::resetButton(Yii::t('common/procurement', 'Reset'), ['class' => 'btn btn-default']) ?>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?php ActiveForm::end(); ?>
|
<?php ActiveForm::end(); ?>
|
||||||
|
|||||||
24
backend/views/procurement/create_product.php
Normal file
24
backend/views/procurement/create_product.php
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use yii\helpers\Html;
|
||||||
|
|
||||||
|
|
||||||
|
/* @var $this yii\web\View */
|
||||||
|
/* @var $model common\models\Procurement */
|
||||||
|
/* @var $warehouses common\models\Warehouse[] */
|
||||||
|
|
||||||
|
$this->title = Yii::t('common/procurement', 'Create Procurement');
|
||||||
|
$this->params['breadcrumbs'][] = ['label' => Yii::t('common/procurement', 'Procurements'), 'url' => ['index']];
|
||||||
|
$this->params['breadcrumbs'][] = $this->title;
|
||||||
|
?>
|
||||||
|
<div class="procurement-create">
|
||||||
|
|
||||||
|
<h1><?= Html::encode($this->title) ?></h1>
|
||||||
|
|
||||||
|
<?= $this->render('_form_product', [
|
||||||
|
'product' => $product,
|
||||||
|
'model' => $model,
|
||||||
|
'warehouses' => $warehouses
|
||||||
|
]) ?>
|
||||||
|
|
||||||
|
</div>
|
||||||
@ -13,7 +13,11 @@ $this->params['breadcrumbs'][] = $this->title;
|
|||||||
<div class="procurement-index">
|
<div class="procurement-index">
|
||||||
|
|
||||||
<h1><?= Html::encode($this->title) ?></h1>
|
<h1><?= Html::encode($this->title) ?></h1>
|
||||||
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
|
<?php echo $this->render('_search', [
|
||||||
|
'model' => $searchModel,
|
||||||
|
'users' => $users,
|
||||||
|
'products' => $products,
|
||||||
|
'warehouses' => $warehouses,]); ?>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<?= Html::a(Yii::t('common/procurement', 'Create Procurement'), ['create'], ['class' => 'btn btn-success']) ?>
|
<?= Html::a(Yii::t('common/procurement', 'Create Procurement'), ['create'], ['class' => 'btn btn-success']) ?>
|
||||||
@ -22,26 +26,29 @@ $this->params['breadcrumbs'][] = $this->title;
|
|||||||
<?= GridView::widget([
|
<?= GridView::widget([
|
||||||
'dataProvider' => $dataProvider,
|
'dataProvider' => $dataProvider,
|
||||||
'columns' => [
|
'columns' => [
|
||||||
['class' => 'yii\grid\SerialColumn'],
|
|
||||||
|
|
||||||
[
|
[
|
||||||
'attribute' => 'id_warehouse',
|
'attribute' => 'id_warehouse',
|
||||||
'value' => 'wareHouseName'
|
'value' => 'wareHouseName'
|
||||||
|
|
||||||
],
|
],
|
||||||
'id_user',
|
[
|
||||||
'id_product',
|
'attribute' => 'id_user',
|
||||||
|
'value' => 'userName'
|
||||||
|
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'attribute' => 'id_product',
|
||||||
|
'value' => 'productName'
|
||||||
|
|
||||||
|
],
|
||||||
'count',
|
'count',
|
||||||
'stock',
|
'stock',
|
||||||
'purchase_price',
|
'purchase_price',
|
||||||
// 'description',
|
|
||||||
'created_at:datetime',
|
'created_at:datetime',
|
||||||
'updated_at:datetime',
|
|
||||||
|
|
||||||
[
|
[
|
||||||
'class' => 'yii\grid\ActionColumn',
|
'class' => 'yii\grid\ActionColumn',
|
||||||
'template' => '{view}'
|
'template' => '{view}',
|
||||||
|
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
]); ?>
|
]); ?>
|
||||||
|
|||||||
@ -14,30 +14,35 @@ $this->params['breadcrumbs'][] = $this->title;
|
|||||||
|
|
||||||
<h1><?= Html::encode($this->title) ?></h1>
|
<h1><?= Html::encode($this->title) ?></h1>
|
||||||
|
|
||||||
<p>
|
|
||||||
<?= Html::a(Yii::t('common/procurement', 'Update'), ['update', 'id' => $model->id_procurement], ['class' => 'btn btn-primary']) ?>
|
|
||||||
<?= Html::a(Yii::t('common/procurement', 'Delete'), ['delete', 'id' => $model->id_procurement], [
|
|
||||||
'class' => 'btn btn-danger',
|
|
||||||
'data' => [
|
|
||||||
'confirm' => Yii::t('common/procurement', 'Are you sure you want to delete this item?'),
|
|
||||||
'method' => 'post',
|
|
||||||
],
|
|
||||||
]) ?>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<?= DetailView::widget([
|
<?= DetailView::widget([
|
||||||
'model' => $model,
|
'model' => $model,
|
||||||
'attributes' => [
|
'attributes' => [
|
||||||
'id_procurement',
|
'id_procurement',
|
||||||
'id_warehouse',
|
[
|
||||||
'id_user',
|
'attribute' => 'id_warehouse',
|
||||||
'id_product',
|
'value' => $model->warehouseName,
|
||||||
|
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'attribute' => 'id_user',
|
||||||
|
'value' => $model->userName,
|
||||||
|
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'attribute' => 'id_product',
|
||||||
|
'value' => $model->productName,
|
||||||
|
|
||||||
|
],
|
||||||
'count',
|
'count',
|
||||||
'stock',
|
'stock',
|
||||||
'purchase_price',
|
'purchase_price',
|
||||||
'description',
|
[
|
||||||
'created_at',
|
'attribute' => 'description',
|
||||||
'updated_at',
|
'value' => nl2br($model->description),
|
||||||
|
'format' => 'raw'
|
||||||
|
],
|
||||||
|
'created_at:datetime',
|
||||||
|
'updated_at:datetime',
|
||||||
],
|
],
|
||||||
]) ?>
|
]) ?>
|
||||||
|
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
use yii\helpers\Html;
|
use yii\helpers\Html;
|
||||||
use yii\grid\GridView;
|
use yii\grid\GridView;
|
||||||
|
use yii\helpers\Url;
|
||||||
|
|
||||||
/* @var $this yii\web\View */
|
/* @var $this yii\web\View */
|
||||||
/* @var $searchModel backend\models\ProductSearch */
|
/* @var $searchModel backend\models\ProductSearch */
|
||||||
@ -41,9 +42,31 @@ $this->params['breadcrumbs'][] = $this->title;
|
|||||||
'value' => 'statusHuman',
|
'value' => 'statusHuman',
|
||||||
|
|
||||||
],
|
],
|
||||||
|
'stock',
|
||||||
['class' => 'yii\grid\ActionColumn',
|
[
|
||||||
'template' => '{view} {update}'
|
'class' => 'yii\grid\ActionColumn',
|
||||||
|
'template' => '{view} {update} {procurement}',
|
||||||
|
'buttons' =>[
|
||||||
|
'view' => function ($url, $model, $key) {
|
||||||
|
return Html::a( Yii::t('common/product', 'Details' ), $url,[ 'class' => 'btn btn-xs btn-success' ]) ;
|
||||||
|
},
|
||||||
|
'update' => function ($url, $model, $key) {
|
||||||
|
return Html::a( Yii::t('common/product', 'Update' ), $url,[ 'class' => 'btn btn-xs btn-success' ]) ;
|
||||||
|
},
|
||||||
|
'procurement' => function ($url, $model, $key) {
|
||||||
|
return Html::a( Yii::t('common/product', 'Procurement' ), $url,[ 'class' => 'btn btn-xs btn-success' ]) ;
|
||||||
|
},
|
||||||
|
],
|
||||||
|
'urlCreator' => function ( $action, $model, $key, $index ){
|
||||||
|
$result = '';
|
||||||
|
if ( $action == 'procurement' ){
|
||||||
|
$result = Url::toRoute(['procurement/create-product' , 'id' => $model->id_product]);
|
||||||
|
}else{
|
||||||
|
$result = Url::toRoute(['product/'.$action , 'id' => $model->id_product]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
]); ?>
|
]); ?>
|
||||||
|
|||||||
@ -29,6 +29,7 @@ $this->params['breadcrumbs'][] = $this->title;
|
|||||||
'sale_price',
|
'sale_price',
|
||||||
'profit_margins',
|
'profit_margins',
|
||||||
'statusHuman',
|
'statusHuman',
|
||||||
|
'stock',
|
||||||
[
|
[
|
||||||
'attribute' => 'description',
|
'attribute' => 'description',
|
||||||
'value' => nl2br($model->description),
|
'value' => nl2br($model->description),
|
||||||
|
|||||||
@ -37,10 +37,11 @@ class Procurement extends \common\models\BaseFitnessActiveRecord
|
|||||||
public function rules()
|
public function rules()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
[['id_warehouse', 'id_user', 'id_product', 'count'], 'required'],
|
[['id_warehouse', 'count', 'purchase_price' ], 'required'],
|
||||||
|
[['id_warehouse', 'count', 'productIdentifier', 'purchase_price' ], 'required' , 'on' => 'create_general'],
|
||||||
[['id_warehouse', 'id_user', 'id_product', 'count', 'stock', 'purchase_price'], 'integer'],
|
[['id_warehouse', 'id_user', 'id_product', 'count', 'stock', 'purchase_price'], 'integer'],
|
||||||
[['created_at', 'updated_at'], 'safe'],
|
|
||||||
[['description'], 'string', 'max' => 255],
|
[['description'], 'string', 'max' => 255],
|
||||||
|
[['productIdentifier'], 'string', 'max' => 128],
|
||||||
[['productIdentifier'] ,'validateProductIdentifier', 'on' => 'create_general']
|
[['productIdentifier'] ,'validateProductIdentifier', 'on' => 'create_general']
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@ -68,12 +69,16 @@ class Procurement extends \common\models\BaseFitnessActiveRecord
|
|||||||
public function validateProductIdentifier($attribute,$params){
|
public function validateProductIdentifier($attribute,$params){
|
||||||
$product = null;
|
$product = null;
|
||||||
|
|
||||||
if ( isset($this->attribute)){
|
if ( isset($this->productIdentifier)){
|
||||||
$id = $this->$attribute;
|
$id = $this->productIdentifier;
|
||||||
$conditionProductName = ['name' =>$id];
|
$conditionProductName = ['name' =>$id];
|
||||||
$conditionProductNumber = ['product_number' =>$id];
|
$conditionProductNumber = ['product_number' =>$id];
|
||||||
$conditionBarcode= ['barcode' =>$id];
|
$conditionBarcode= ['barcode' =>$id];
|
||||||
$product = Product::findOne(['or',[ $conditionProductName,$conditionProductNumber,$conditionBarcode ]]);
|
$products = Product::find()->andWhere(['or', ['name' =>$id] , ['product_number' =>$id] ,['barcode' =>$id] ] )->all();
|
||||||
|
if ( count($products) == 1 ){
|
||||||
|
$product = $products[0];
|
||||||
|
$this->id_product = $product->id_product;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $product == null ){
|
if ( $product == null ){
|
||||||
@ -111,7 +116,7 @@ class Procurement extends \common\models\BaseFitnessActiveRecord
|
|||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
public function getUser() {
|
public function getUser() {
|
||||||
return $this->hasOne ( User::className (), [
|
return $this->hasOne ( User::className (), [
|
||||||
'id_user' => 'id_user'
|
'id' => 'id_user'
|
||||||
] );
|
] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -110,4 +110,19 @@ class Product extends \common\models\BaseFitnessActiveRecord {
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* $param int $forceIncludeAccount id warehouse, that should be included in list, even if it is inactive
|
||||||
|
* */
|
||||||
|
public static function read($forceIncludeObjectWithId = null){
|
||||||
|
$warehouses = null;
|
||||||
|
|
||||||
|
if ( $forceIncludeObjectWithId == null){
|
||||||
|
$warehouses = Product::find()->andWhere(['status' => Product::STATUS_ACTIVE])->all();
|
||||||
|
}else{
|
||||||
|
$warehouses = Product::find()->andWhere( ['or', ['status' => Product::STATUS_ACTIVE], ['id_product' => $forceIncludeObjectWithId ] ])->all();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $warehouses;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -209,4 +209,21 @@ class User extends ActiveRecord implements IdentityInterface
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* $param int $forceIncludeAccount id warehouse, that should be included in list, even if it is inactive
|
||||||
|
* */
|
||||||
|
public static function read($forceIncludeObjectWithId = null){
|
||||||
|
$warehouses = null;
|
||||||
|
|
||||||
|
if ( $forceIncludeObjectWithId == null){
|
||||||
|
$warehouses = User::find()->andWhere(['status' => User::STATUS_ACTIVE])->all();
|
||||||
|
}else{
|
||||||
|
$warehouses = User::find()->andWhere( ['or', ['status' => User::STATUS_ACTIVE], ['id' => $forceIncludeObjectWithId ] ])->all();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $warehouses;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,7 +17,8 @@
|
|||||||
"php": ">=5.4.0",
|
"php": ">=5.4.0",
|
||||||
"yiisoft/yii2": ">=2.0.6",
|
"yiisoft/yii2": ">=2.0.6",
|
||||||
"yiisoft/yii2-bootstrap": "*",
|
"yiisoft/yii2-bootstrap": "*",
|
||||||
"yiisoft/yii2-swiftmailer": "*"
|
"yiisoft/yii2-swiftmailer": "*",
|
||||||
|
"kartik-v/yii2-widgets": "^3.4"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"yiisoft/yii2-codeception": "*",
|
"yiisoft/yii2-codeception": "*",
|
||||||
|
|||||||
1124
composer.lock
generated
1124
composer.lock
generated
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user