add changes to procurement
This commit is contained in:
parent
e2fe006899
commit
28caac03dc
@ -41,6 +41,7 @@ class AdminMenuStructure{
|
|||||||
$items[] = ['label' => 'Termék kategóriák', 'url' => ['/product-category/index'] ];
|
$items[] = ['label' => 'Termék kategóriák', 'url' => ['/product-category/index'] ];
|
||||||
$items[] = ['label' => 'Bérlet típusok', 'url' => ['/ticket-type/index'] ];
|
$items[] = ['label' => 'Bérlet típusok', 'url' => ['/ticket-type/index'] ];
|
||||||
$items[] = ['label' => 'Termékek', 'url' => ['/product/index'] ];
|
$items[] = ['label' => 'Termékek', 'url' => ['/product/index'] ];
|
||||||
|
$items[] = ['label' => 'Beszerzések', 'url' => ['/procurement/index'] ];
|
||||||
|
|
||||||
if ( count($items) > 0 ){
|
if ( count($items) > 0 ){
|
||||||
$userMainMenu = ['label' => 'Beállítások', 'url' => null,
|
$userMainMenu = ['label' => 'Beállítások', 'url' => null,
|
||||||
|
|||||||
127
backend/controllers/ProcurementController.php
Normal file
127
backend/controllers/ProcurementController.php
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace backend\controllers;
|
||||||
|
|
||||||
|
use Yii;
|
||||||
|
use common\models\Procurement;
|
||||||
|
use backend\models\ProcurementSearch;
|
||||||
|
use yii\web\Controller;
|
||||||
|
use yii\web\NotFoundHttpException;
|
||||||
|
use yii\filters\VerbFilter;
|
||||||
|
use common\models\Warehouse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ProcurementController implements the CRUD actions for Procurement model.
|
||||||
|
*/
|
||||||
|
class ProcurementController extends Controller
|
||||||
|
{
|
||||||
|
public function behaviors()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'verbs' => [
|
||||||
|
'class' => VerbFilter::className(),
|
||||||
|
'actions' => [
|
||||||
|
'delete' => ['post'],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lists all Procurement models.
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function actionIndex()
|
||||||
|
{
|
||||||
|
$searchModel = new ProcurementSearch();
|
||||||
|
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
||||||
|
|
||||||
|
return $this->render('index', [
|
||||||
|
'searchModel' => $searchModel,
|
||||||
|
'dataProvider' => $dataProvider,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Displays a single Procurement model.
|
||||||
|
* @param integer $id
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function actionView($id)
|
||||||
|
{
|
||||||
|
return $this->render('view', [
|
||||||
|
'model' => $this->findModel($id),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new Procurement model.
|
||||||
|
* If creation is successful, the browser will be redirected to the 'view' page.
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function actionCreate()
|
||||||
|
{
|
||||||
|
$model = new Procurement();
|
||||||
|
|
||||||
|
$model->id_user = Yii::$app->user->id;
|
||||||
|
|
||||||
|
$warehouses = Warehouse::read(null);
|
||||||
|
|
||||||
|
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||||
|
return $this->redirect(['view', 'id' => $model->id_procurement]);
|
||||||
|
} else {
|
||||||
|
return $this->render('create', [
|
||||||
|
'model' => $model,
|
||||||
|
'warehouses' =>$warehouses
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates an existing Procurement model.
|
||||||
|
* If update is successful, the browser will be redirected to the 'view' page.
|
||||||
|
* @param integer $id
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function actionUpdate($id)
|
||||||
|
{
|
||||||
|
$model = $this->findModel($id);
|
||||||
|
|
||||||
|
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||||
|
return $this->redirect(['view', 'id' => $model->id_procurement]);
|
||||||
|
} else {
|
||||||
|
return $this->render('update', [
|
||||||
|
'model' => $model,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
* 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 findModel($id)
|
||||||
|
{
|
||||||
|
if (($model = Procurement::findOne($id)) !== null) {
|
||||||
|
return $model;
|
||||||
|
} else {
|
||||||
|
throw new NotFoundHttpException('The requested page does not exist.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
74
backend/models/ProcurementSearch.php
Normal file
74
backend/models/ProcurementSearch.php
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace backend\models;
|
||||||
|
|
||||||
|
use Yii;
|
||||||
|
use yii\base\Model;
|
||||||
|
use yii\data\ActiveDataProvider;
|
||||||
|
use common\models\Procurement;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ProcurementSearch represents the model behind the search form about `common\models\Procurement`.
|
||||||
|
*/
|
||||||
|
class ProcurementSearch extends Procurement
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
[['id_procurement', 'id_warehouse', 'id_user', 'id_product', 'count', 'stock', 'purchase_price'], 'integer'],
|
||||||
|
[['description', 'created_at', 'updated_at'], 'safe'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
public function scenarios()
|
||||||
|
{
|
||||||
|
// bypass scenarios() implementation in the parent class
|
||||||
|
return Model::scenarios();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates data provider instance with search query applied
|
||||||
|
*
|
||||||
|
* @param array $params
|
||||||
|
*
|
||||||
|
* @return ActiveDataProvider
|
||||||
|
*/
|
||||||
|
public function search($params)
|
||||||
|
{
|
||||||
|
$query = Procurement::find();
|
||||||
|
|
||||||
|
$dataProvider = new ActiveDataProvider([
|
||||||
|
'query' => $query,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->load($params);
|
||||||
|
|
||||||
|
if (!$this->validate()) {
|
||||||
|
// uncomment the following line if you do not want to return any records when validation fails
|
||||||
|
// $query->where('0=1');
|
||||||
|
return $dataProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
$query->andFilterWhere([
|
||||||
|
'id_procurement' => $this->id_procurement,
|
||||||
|
'id_warehouse' => $this->id_warehouse,
|
||||||
|
'id_user' => $this->id_user,
|
||||||
|
'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(['like', 'description', $this->description]);
|
||||||
|
|
||||||
|
return $dataProvider;
|
||||||
|
}
|
||||||
|
}
|
||||||
38
backend/views/procurement/_form.php
Normal file
38
backend/views/procurement/_form.php
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use yii\helpers\Html;
|
||||||
|
use yii\widgets\ActiveForm;
|
||||||
|
use yii\helpers\ArrayHelper;
|
||||||
|
|
||||||
|
/* @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') ;
|
||||||
|
|
||||||
|
?>
|
||||||
|
<div class="procurement-form">
|
||||||
|
|
||||||
|
<?php $form = ActiveForm::begin(); ?>
|
||||||
|
|
||||||
|
<?= $form->field($model, 'productIdentifier')->textInput()->hint(Yii::t('common/procurement', "Product name, product number or barcode")) ?>
|
||||||
|
|
||||||
|
<?= $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>
|
||||||
45
backend/views/procurement/_search.php
Normal file
45
backend/views/procurement/_search.php
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use yii\helpers\Html;
|
||||||
|
use yii\widgets\ActiveForm;
|
||||||
|
|
||||||
|
/* @var $this yii\web\View */
|
||||||
|
/* @var $model backend\models\ProcurementSearch */
|
||||||
|
/* @var $form yii\widgets\ActiveForm */
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div class="procurement-search">
|
||||||
|
|
||||||
|
<?php $form = ActiveForm::begin([
|
||||||
|
'action' => ['index'],
|
||||||
|
'method' => 'get',
|
||||||
|
]); ?>
|
||||||
|
|
||||||
|
<?= $form->field($model, 'id_procurement') ?>
|
||||||
|
|
||||||
|
<?= $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">
|
||||||
|
<?= Html::submitButton(Yii::t('common/procurement', 'Search'), ['class' => 'btn btn-primary']) ?>
|
||||||
|
<?= Html::resetButton(Yii::t('common/procurement', 'Reset'), ['class' => 'btn btn-default']) ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php ActiveForm::end(); ?>
|
||||||
|
|
||||||
|
</div>
|
||||||
23
backend/views/procurement/create.php
Normal file
23
backend/views/procurement/create.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?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', [
|
||||||
|
'model' => $model,
|
||||||
|
'warehouses' => $warehouses
|
||||||
|
]) ?>
|
||||||
|
|
||||||
|
</div>
|
||||||
49
backend/views/procurement/index.php
Normal file
49
backend/views/procurement/index.php
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use yii\helpers\Html;
|
||||||
|
use yii\grid\GridView;
|
||||||
|
|
||||||
|
/* @var $this yii\web\View */
|
||||||
|
/* @var $searchModel backend\models\ProcurementSearch */
|
||||||
|
/* @var $dataProvider yii\data\ActiveDataProvider */
|
||||||
|
|
||||||
|
$this->title = Yii::t('common/procurement', 'Procurements');
|
||||||
|
$this->params['breadcrumbs'][] = $this->title;
|
||||||
|
?>
|
||||||
|
<div class="procurement-index">
|
||||||
|
|
||||||
|
<h1><?= Html::encode($this->title) ?></h1>
|
||||||
|
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<?= Html::a(Yii::t('common/procurement', 'Create Procurement'), ['create'], ['class' => 'btn btn-success']) ?>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<?= GridView::widget([
|
||||||
|
'dataProvider' => $dataProvider,
|
||||||
|
'columns' => [
|
||||||
|
['class' => 'yii\grid\SerialColumn'],
|
||||||
|
|
||||||
|
[
|
||||||
|
'attribute' => 'id_warehouse',
|
||||||
|
'value' => 'wareHouseName'
|
||||||
|
|
||||||
|
],
|
||||||
|
'id_user',
|
||||||
|
'id_product',
|
||||||
|
'count',
|
||||||
|
'stock',
|
||||||
|
'purchase_price',
|
||||||
|
// 'description',
|
||||||
|
'created_at:datetime',
|
||||||
|
'updated_at:datetime',
|
||||||
|
|
||||||
|
[
|
||||||
|
'class' => 'yii\grid\ActionColumn',
|
||||||
|
'template' => '{view}'
|
||||||
|
|
||||||
|
],
|
||||||
|
],
|
||||||
|
]); ?>
|
||||||
|
|
||||||
|
</div>
|
||||||
23
backend/views/procurement/update.php
Normal file
23
backend/views/procurement/update.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use yii\helpers\Html;
|
||||||
|
|
||||||
|
/* @var $this yii\web\View */
|
||||||
|
/* @var $model common\models\Procurement */
|
||||||
|
|
||||||
|
$this->title = Yii::t('common/procurement', 'Update {modelClass}: ', [
|
||||||
|
'modelClass' => 'Procurement',
|
||||||
|
]) . ' ' . $model->id_procurement;
|
||||||
|
$this->params['breadcrumbs'][] = ['label' => Yii::t('common/procurement', 'Procurements'), 'url' => ['index']];
|
||||||
|
$this->params['breadcrumbs'][] = ['label' => $model->id_procurement, 'url' => ['view', 'id' => $model->id_procurement]];
|
||||||
|
$this->params['breadcrumbs'][] = Yii::t('common/procurement', 'Update');
|
||||||
|
?>
|
||||||
|
<div class="procurement-update">
|
||||||
|
|
||||||
|
<h1><?= Html::encode($this->title) ?></h1>
|
||||||
|
|
||||||
|
<?= $this->render('_form', [
|
||||||
|
'model' => $model,
|
||||||
|
]) ?>
|
||||||
|
|
||||||
|
</div>
|
||||||
44
backend/views/procurement/view.php
Normal file
44
backend/views/procurement/view.php
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use yii\helpers\Html;
|
||||||
|
use yii\widgets\DetailView;
|
||||||
|
|
||||||
|
/* @var $this yii\web\View */
|
||||||
|
/* @var $model common\models\Procurement */
|
||||||
|
|
||||||
|
$this->title = $model->id_procurement;
|
||||||
|
$this->params['breadcrumbs'][] = ['label' => Yii::t('common/procurement', 'Procurements'), 'url' => ['index']];
|
||||||
|
$this->params['breadcrumbs'][] = $this->title;
|
||||||
|
?>
|
||||||
|
<div class="procurement-view">
|
||||||
|
|
||||||
|
<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([
|
||||||
|
'model' => $model,
|
||||||
|
'attributes' => [
|
||||||
|
'id_procurement',
|
||||||
|
'id_warehouse',
|
||||||
|
'id_user',
|
||||||
|
'id_product',
|
||||||
|
'count',
|
||||||
|
'stock',
|
||||||
|
'purchase_price',
|
||||||
|
'description',
|
||||||
|
'created_at',
|
||||||
|
'updated_at',
|
||||||
|
],
|
||||||
|
]) ?>
|
||||||
|
|
||||||
|
</div>
|
||||||
122
common/models/Procurement.php
Normal file
122
common/models/Procurement.php
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace common\models;
|
||||||
|
|
||||||
|
use Yii;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the model class for table "procurement".
|
||||||
|
*
|
||||||
|
* @property integer $id_procurement
|
||||||
|
* @property integer $id_warehouse
|
||||||
|
* @property integer $id_user
|
||||||
|
* @property integer $id_product
|
||||||
|
* @property integer $count
|
||||||
|
* @property integer $stock
|
||||||
|
* @property integer $purchase_price
|
||||||
|
* @property string $description
|
||||||
|
* @property string $created_at
|
||||||
|
* @property string $updated_at
|
||||||
|
*/
|
||||||
|
class Procurement extends \common\models\BaseFitnessActiveRecord
|
||||||
|
{
|
||||||
|
|
||||||
|
public $productIdentifier;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
public static function tableName()
|
||||||
|
{
|
||||||
|
return 'procurement';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
[['id_warehouse', 'id_user', 'id_product', 'count'], 'required'],
|
||||||
|
[['id_warehouse', 'id_user', 'id_product', 'count', 'stock', 'purchase_price'], 'integer'],
|
||||||
|
[['created_at', 'updated_at'], 'safe'],
|
||||||
|
[['description'], 'string', 'max' => 255],
|
||||||
|
[['productIdentifier'] ,'validateProductIdentifier', 'on' => 'create_general']
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
public function attributeLabels()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'id_procurement' => Yii::t('common/procurement', 'Id Procurement'),
|
||||||
|
'id_warehouse' => Yii::t('common/procurement', 'Id Warehouse'),
|
||||||
|
'id_user' => Yii::t('common/procurement', 'Id User'),
|
||||||
|
'id_product' => Yii::t('common/procurement', 'Id Product'),
|
||||||
|
'count' => Yii::t('common/procurement', 'Count'),
|
||||||
|
'stock' => Yii::t('common/procurement', 'Stock'),
|
||||||
|
'purchase_price' => Yii::t('common/procurement', 'Purchase Price'),
|
||||||
|
'description' => Yii::t('common/procurement', 'Description'),
|
||||||
|
'created_at' => Yii::t('common/procurement', 'Created At'),
|
||||||
|
'updated_at' => Yii::t('common/procurement', 'Updated At'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function validateProductIdentifier($attribute,$params){
|
||||||
|
$product = null;
|
||||||
|
|
||||||
|
if ( isset($this->attribute)){
|
||||||
|
$id = $this->$attribute;
|
||||||
|
$conditionProductName = ['name' =>$id];
|
||||||
|
$conditionProductNumber = ['product_number' =>$id];
|
||||||
|
$conditionBarcode= ['barcode' =>$id];
|
||||||
|
$product = Product::findOne(['or',[ $conditionProductName,$conditionProductNumber,$conditionBarcode ]]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $product == null ){
|
||||||
|
$this->addError('productIdentifier' , Yii::t("common/procurement", "Invalid product"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////
|
||||||
|
// PRODUCT
|
||||||
|
////////////////////////////////
|
||||||
|
public function getProduct() {
|
||||||
|
return $this->hasOne ( Product::className (), [
|
||||||
|
'id_product' => 'id_product'
|
||||||
|
] );
|
||||||
|
}
|
||||||
|
public function getProductName() {
|
||||||
|
return $this->product->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////
|
||||||
|
// WAREHOUSE
|
||||||
|
////////////////////////////////
|
||||||
|
public function getWarehouse() {
|
||||||
|
return $this->hasOne ( Warehouse::className (), [
|
||||||
|
'id_warehouse' => 'id_warehouse'
|
||||||
|
] );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getWarehouseName(){
|
||||||
|
return $this->warehouse->name;
|
||||||
|
}
|
||||||
|
////////////////////////////////
|
||||||
|
// USER
|
||||||
|
////////////////////////////////
|
||||||
|
public function getUser() {
|
||||||
|
return $this->hasOne ( User::className (), [
|
||||||
|
'id_user' => 'id_user'
|
||||||
|
] );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUserName(){
|
||||||
|
return $this->user->username;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -82,5 +82,21 @@ class Warehouse extends \yii\db\ActiveRecord
|
|||||||
}
|
}
|
||||||
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 = Warehouse::find()->andWhere(['status' => Warehouse::STATUS_ACTIVE])->all();
|
||||||
|
}else{
|
||||||
|
$warehouses = Warehouse::find()->andWhere( ['or', ['status' => Warehouse::STATUS_ACTIVE], ['id_warehouse' => $forceIncludeObjectWithId ] ])->all();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $warehouses;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
47
console/migrations/m150925_055052_add__table_procurement.php
Normal file
47
console/migrations/m150925_055052_add__table_procurement.php
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use yii\db\Schema;
|
||||||
|
use yii\db\Migration;
|
||||||
|
|
||||||
|
class m150925_055052_add__table_procurement extends Migration
|
||||||
|
{
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
$tableOptions = null;
|
||||||
|
if ($this->db->driverName === 'mysql') {
|
||||||
|
// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
|
||||||
|
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->createTable('{{%procurement}}', [
|
||||||
|
'id_procurement' => $this->primaryKey(),
|
||||||
|
'id_warehouse' => $this->integer()->notNull(),
|
||||||
|
'id_user' => $this->integer()->notNull(),
|
||||||
|
'id_product' => $this->integer()->notNull(),
|
||||||
|
'count' => $this->integer()->notNull(),
|
||||||
|
'stock' => $this->integer(),
|
||||||
|
'purchase_price' => $this->integer(),
|
||||||
|
'description' => $this->string(255),
|
||||||
|
'created_at' => $this->timestamp()->notNull(),
|
||||||
|
'updated_at' => $this->timestamp()->notNull(),
|
||||||
|
], $tableOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
echo "m150925_055052_add__table_procurement cannot be reverted.\n";
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
// Use safeUp/safeDown to run migration code within a transaction
|
||||||
|
public function safeUp()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function safeDown()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user