Finish 34 ( procurement )
This commit is contained in:
commit
8ee256314b
@ -41,6 +41,7 @@ class AdminMenuStructure{
|
||||
$items[] = ['label' => 'Termék kategóriák', 'url' => ['/product-category/index'] ];
|
||||
$items[] = ['label' => 'Bérlet típusok', 'url' => ['/ticket-type/index'] ];
|
||||
$items[] = ['label' => 'Termékek', 'url' => ['/product/index'] ];
|
||||
$items[] = ['label' => 'Beszerzések', 'url' => ['/procurement/index'] ];
|
||||
|
||||
if ( count($items) > 0 ){
|
||||
$userMainMenu = ['label' => 'Beállítások', 'url' => null,
|
||||
|
||||
215
backend/controllers/ProcurementController.php
Normal file
215
backend/controllers/ProcurementController.php
Normal file
@ -0,0 +1,215 @@
|
||||
<?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;
|
||||
use common\models\Product;
|
||||
use common\models\User;
|
||||
|
||||
/**
|
||||
* 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()
|
||||
{
|
||||
|
||||
$warehouses = Warehouse::read(null);
|
||||
$products = Product::read(null);
|
||||
$users = User::read(null);
|
||||
|
||||
$searchModel = new ProcurementSearch();
|
||||
|
||||
$today = time();
|
||||
$tomorrow = time()+86400;
|
||||
$searchModel->timestampStart = date("Y-m-d" , $today );
|
||||
$searchModel->timestampEnd = date("Y-m-d" , $tomorrow );
|
||||
$searchModel->date_start = Yii::$app->formatter->asDate($today);
|
||||
$searchModel->date_end = Yii::$app->formatter->asDate($tomorrow);
|
||||
|
||||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
||||
|
||||
return $this->render('index', [
|
||||
'searchModel' => $searchModel,
|
||||
'dataProvider' => $dataProvider,
|
||||
'users' => $users,
|
||||
'products' => $products,
|
||||
'warehouses' => $warehouses,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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->scenario = 'create_general';
|
||||
|
||||
$model->id_user = Yii::$app->user->id;
|
||||
|
||||
$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 {
|
||||
|
||||
$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(['index' ]);
|
||||
} else {
|
||||
return $this->render('create', [
|
||||
'model' => $model,
|
||||
'warehouses' =>$warehouses
|
||||
]);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Creates a new Procurement model.
|
||||
* If creation is successful, the browser will be redirected to the 'view' page.
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionCreateProduct($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;
|
||||
|
||||
$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]);
|
||||
} else {
|
||||
return $this->render('create_product', [
|
||||
'model' => $model,
|
||||
'warehouses' =>$warehouses,
|
||||
'product' => $product
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 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.');
|
||||
}
|
||||
}
|
||||
}
|
||||
86
backend/models/ProcurementSearch.php
Normal file
86
backend/models/ProcurementSearch.php
Normal file
@ -0,0 +1,86 @@
|
||||
<?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
|
||||
{
|
||||
|
||||
public $date_start;
|
||||
public $date_end;
|
||||
|
||||
public $timestampStart;
|
||||
public $timestampEnd;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[[ 'id_warehouse', 'id_user', 'id_product', ], 'integer'],
|
||||
[[ 'date_start', ], 'date' , 'timestampAttribute' => 'timestampStart' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ],
|
||||
[[ 'date_end' , ], 'date' , 'timestampAttribute' => 'timestampEnd' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @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;
|
||||
}
|
||||
|
||||
|
||||
if ( empty($this->date_start) ){
|
||||
$this->timestampStart = '';
|
||||
}
|
||||
if ( empty($this->date_end) ){
|
||||
$this->timestampEnd = '';
|
||||
}
|
||||
|
||||
$query->andFilterWhere([
|
||||
'id_warehouse' => $this->id_warehouse,
|
||||
'id_user' => $this->id_user,
|
||||
'id_product' => $this->id_product,
|
||||
]);
|
||||
|
||||
$query->andFilterWhere([ '>=', 'created_at', $this->date_start ] );
|
||||
$query->andFilterWhere([ '<', 'created_at', $this->timestampEnd ] );
|
||||
|
||||
|
||||
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>
|
||||
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>
|
||||
76
backend/views/procurement/_search.php
Normal file
76
backend/views/procurement/_search.php
Normal file
@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\ActiveForm;
|
||||
use yii\helpers\ArrayHelper;
|
||||
use kartik\widgets\DatePicker;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model backend\models\ProcurementSearch */
|
||||
/* @var $form yii\widgets\ActiveForm */
|
||||
?>
|
||||
|
||||
<?php
|
||||
|
||||
function mkOptions($options){
|
||||
// $o = $options;
|
||||
|
||||
$all = ['' => 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">
|
||||
|
||||
<?php $form = ActiveForm::begin([
|
||||
'action' => ['index'],
|
||||
'method' => 'get',
|
||||
]); ?>
|
||||
|
||||
<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>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton(Yii::t('common/procurement', 'Search'), ['class' => 'btn btn-primary']) ?>
|
||||
</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>
|
||||
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>
|
||||
56
backend/views/procurement/index.php
Normal file
56
backend/views/procurement/index.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?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,
|
||||
'users' => $users,
|
||||
'products' => $products,
|
||||
'warehouses' => $warehouses,]); ?>
|
||||
|
||||
<p>
|
||||
<?= Html::a(Yii::t('common/procurement', 'Create Procurement'), ['create'], ['class' => 'btn btn-success']) ?>
|
||||
</p>
|
||||
|
||||
<?= GridView::widget([
|
||||
'dataProvider' => $dataProvider,
|
||||
'columns' => [
|
||||
[
|
||||
'attribute' => 'id_warehouse',
|
||||
'value' => 'wareHouseName'
|
||||
|
||||
],
|
||||
[
|
||||
'attribute' => 'id_user',
|
||||
'value' => 'userName'
|
||||
|
||||
],
|
||||
[
|
||||
'attribute' => 'id_product',
|
||||
'value' => 'productName'
|
||||
|
||||
],
|
||||
'count',
|
||||
'stock',
|
||||
'purchase_price',
|
||||
'created_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>
|
||||
48
backend/views/procurement/view.php
Normal file
48
backend/views/procurement/view.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\DetailView;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model common\models\Procurement */
|
||||
|
||||
$this->title = Yii::t('common/procurement','Procurement') .' ' . $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>
|
||||
|
||||
<?= DetailView::widget([
|
||||
'model' => $model,
|
||||
'attributes' => [
|
||||
'id_procurement',
|
||||
[
|
||||
'attribute' => 'id_warehouse',
|
||||
'value' => $model->warehouseName,
|
||||
|
||||
],
|
||||
[
|
||||
'attribute' => 'id_user',
|
||||
'value' => $model->userName,
|
||||
|
||||
],
|
||||
[
|
||||
'attribute' => 'id_product',
|
||||
'value' => $model->productName,
|
||||
|
||||
],
|
||||
'count',
|
||||
'stock',
|
||||
'purchase_price',
|
||||
[
|
||||
'attribute' => 'description',
|
||||
'value' => nl2br($model->description),
|
||||
'format' => 'raw'
|
||||
],
|
||||
'created_at:datetime',
|
||||
],
|
||||
]) ?>
|
||||
|
||||
</div>
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
use yii\helpers\Html;
|
||||
use yii\grid\GridView;
|
||||
use yii\helpers\Url;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $searchModel backend\models\ProductSearch */
|
||||
@ -41,9 +42,31 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
'value' => 'statusHuman',
|
||||
|
||||
],
|
||||
'stock',
|
||||
[
|
||||
'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-primary' ]) ;
|
||||
},
|
||||
'update' => function ($url, $model, $key) {
|
||||
return Html::a( Yii::t('common/product', 'Update' ), $url,[ 'class' => 'btn btn-xs btn-primary' ]) ;
|
||||
},
|
||||
'procurement' => function ($url, $model, $key) {
|
||||
return Html::a( Yii::t('common/product', 'Procurement' ), $url,[ 'class' => 'btn btn-xs btn-primary' ]) ;
|
||||
},
|
||||
],
|
||||
'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]);
|
||||
}
|
||||
|
||||
['class' => 'yii\grid\ActionColumn',
|
||||
'template' => '{view} {update}'
|
||||
return $result;
|
||||
}
|
||||
],
|
||||
],
|
||||
]); ?>
|
||||
|
||||
@ -29,6 +29,7 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
'sale_price',
|
||||
'profit_margins',
|
||||
'statusHuman',
|
||||
'stock',
|
||||
[
|
||||
'attribute' => 'description',
|
||||
'value' => nl2br($model->description),
|
||||
|
||||
@ -55,6 +55,9 @@ return [
|
||||
// Message categories to ignore
|
||||
'ignoreCategories' => [
|
||||
'yii',
|
||||
'fileinput',
|
||||
'kvdate',
|
||||
'kvdatetime',
|
||||
],
|
||||
|
||||
/*
|
||||
|
||||
@ -17,6 +17,7 @@
|
||||
* NOTE: this file must be saved in UTF-8 encoding.
|
||||
*/
|
||||
return [
|
||||
'It is recommended you use an upgraded browser to display the {type} control properly.' => 'Ajánlott újabb böngésző verziót használni!',
|
||||
'Aktív' => 'Aktív',
|
||||
'Are you sure you want to delete this item?' => 'Biztosan törölni szeretné ezt az element?',
|
||||
'Delete' => 'Törlés',
|
||||
|
||||
40
common/messages/hu/common/procurement.php
Normal file
40
common/messages/hu/common/procurement.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/**
|
||||
* Message translations.
|
||||
*
|
||||
* This file is automatically generated by 'yii message' command.
|
||||
* It contains the localizable messages extracted from source code.
|
||||
* You may modify this file by translating the extracted messages.
|
||||
*
|
||||
* Each array element represents the translation (value) of a message (key).
|
||||
* If the value is empty, the message is considered as not translated.
|
||||
* Messages that no longer need translation will have their translations
|
||||
* enclosed between a pair of '@@' marks.
|
||||
*
|
||||
* Message string can be used with plural forms format. Check i18n section
|
||||
* of the guide for details.
|
||||
*
|
||||
* NOTE: this file must be saved in UTF-8 encoding.
|
||||
*/
|
||||
return [
|
||||
'Count' => 'Beszerzett mennyiség',
|
||||
'Create' => 'Mentés',
|
||||
'Create Procurement' => 'Új beszerzés',
|
||||
'Created At' => 'Beszerzés ideje',
|
||||
'Description' => 'Megjegyzés',
|
||||
'Id Procurement' => 'Beszerzés azonosító',
|
||||
'Id Product' => 'Termék',
|
||||
'Id User' => 'Felhasználó',
|
||||
'Id Warehouse' => 'Raktár',
|
||||
'Invalid product' => 'Termék nincs megadva',
|
||||
'No active warehouse found.' => 'Nem találtam aktív raktárat',
|
||||
'Procurement' => 'Beszerzés',
|
||||
'Procurements' => 'Beszerzések',
|
||||
'Product name, product number or barcode' => 'Termék neve, termék száma vagy vonalkód',
|
||||
'Purchase Price' => 'Beszerzési ár',
|
||||
'Search' => 'Keresés',
|
||||
'Stock' => 'Beszerzés előtti raktárkészlet',
|
||||
'Update' => 'Módosítás',
|
||||
'Update {modelClass}: ' => '{modelClass} módosítása: ',
|
||||
'Updated At' => 'Módosítva',
|
||||
];
|
||||
@ -17,6 +17,9 @@
|
||||
* NOTE: this file must be saved in UTF-8 encoding.
|
||||
*/
|
||||
return [
|
||||
'Details' => 'Részletek',
|
||||
'Procurement' => 'Beszerzés',
|
||||
'Product' => 'Termék',
|
||||
'Active' => 'Aktív',
|
||||
'All' => 'Mind',
|
||||
'Barcode' => 'Vonalkód',
|
||||
|
||||
127
common/models/Procurement.php
Normal file
127
common/models/Procurement.php
Normal file
@ -0,0 +1,127 @@
|
||||
<?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', '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'],
|
||||
[['description'], 'string', 'max' => 255],
|
||||
[['productIdentifier'], 'string', 'max' => 128],
|
||||
[['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->productIdentifier)){
|
||||
$id = $this->productIdentifier;
|
||||
$conditionProductName = ['name' =>$id];
|
||||
$conditionProductNumber = ['product_number' =>$id];
|
||||
$conditionBarcode= ['barcode' =>$id];
|
||||
$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 ){
|
||||
$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' => 'id_user'
|
||||
] );
|
||||
}
|
||||
|
||||
public function getUserName(){
|
||||
return $this->user->username;
|
||||
}
|
||||
|
||||
}
|
||||
@ -110,4 +110,19 @@ class Product extends \common\models\BaseFitnessActiveRecord {
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -83,4 +83,20 @@ class Warehouse extends \yii\db\ActiveRecord
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -17,7 +17,8 @@
|
||||
"php": ">=5.4.0",
|
||||
"yiisoft/yii2": ">=2.0.6",
|
||||
"yiisoft/yii2-bootstrap": "*",
|
||||
"yiisoft/yii2-swiftmailer": "*"
|
||||
"yiisoft/yii2-swiftmailer": "*",
|
||||
"kartik-v/yii2-widgets": "^3.4"
|
||||
},
|
||||
"require-dev": {
|
||||
"yiisoft/yii2-codeception": "*",
|
||||
|
||||
1136
composer.lock
generated
1136
composer.lock
generated
File diff suppressed because it is too large
Load Diff
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