add inventory to frontend
This commit is contained in:
@@ -8,13 +8,7 @@ use backend\models\InventorySearch;
|
||||
use yii\web\Controller;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\filters\VerbFilter;
|
||||
use common\models\InventoryItem;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use common\components\Helper;
|
||||
use common\models\User;
|
||||
use common\models\Product;
|
||||
use common\models\InventoryGroup;
|
||||
use yii\db\Expression;
|
||||
use yii\db\Query;
|
||||
use backend\models\InventoryItemSearch;
|
||||
|
||||
@@ -50,27 +44,7 @@ class InventoryController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a single Inventory model.
|
||||
* @param integer $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionView($id)
|
||||
{
|
||||
$inventory = $this->findModel($id);
|
||||
|
||||
$searchModel = new InventoryItemSearch(['inventory' => $inventory]);
|
||||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
||||
|
||||
|
||||
$query = new Query();
|
||||
|
||||
return $this->render('view', [
|
||||
'model' => $inventory,
|
||||
'dataProvider' => $dataProvider
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new Inventory model.
|
||||
* If creation is successful, the browser will be redirected to the 'view' page.
|
||||
@@ -86,7 +60,7 @@ class InventoryController extends Controller
|
||||
|
||||
$model->id_user = \Yii::$app->user->id;
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
// return $this->redirect(['view', 'id' => $model->id_inventory]);
|
||||
return $this->redirect(['view', 'id' => $model->id_inventory]);
|
||||
} else {
|
||||
}
|
||||
return $this->render('create', [
|
||||
@@ -94,37 +68,7 @@ class InventoryController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates an existing Inventory 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_inventory]);
|
||||
} else {
|
||||
return $this->render('update', [
|
||||
'model' => $model,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an existing Inventory 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 Inventory model based on its primary key value.
|
||||
|
||||
@@ -108,10 +108,14 @@ class InventoryItemForm extends Model{
|
||||
if ( isset( $this->last_inventory_item ) ){
|
||||
$item->id_inventory_item_prev = $this->last_inventory_item->id_inventory_item;
|
||||
$item->count_prev = $this->last_inventory_item->count;
|
||||
if ( !isset($item->count_prev)){
|
||||
$item->count_prev = 0;
|
||||
}
|
||||
}else{
|
||||
$item->count_prev = 0;
|
||||
}
|
||||
|
||||
|
||||
$item->id_user = \Yii::$app->user->id;
|
||||
|
||||
if ( $this->type == 'product'){
|
||||
@@ -121,7 +125,7 @@ class InventoryItemForm extends Model{
|
||||
}
|
||||
$item->id_inventory = $this->inventory->id_inventory;
|
||||
|
||||
if ( !$item->save() ){
|
||||
if ( !$item->save(false) ){
|
||||
throw new \Exception("Nem sikerült a leltár végrehajtása");
|
||||
}
|
||||
$this->inventory_item = $item;
|
||||
@@ -132,7 +136,7 @@ class InventoryItemForm extends Model{
|
||||
|
||||
protected function loadProductIn(){
|
||||
$query = new Query();
|
||||
$query->select(['sum(procurement.count) as total_in']);
|
||||
$query->select(['coalesce(sum(procurement.count),0) as total_in']);
|
||||
$query->from(Procurement::tableName());
|
||||
$query->innerJoin(Product::tableName(),"product.id_product = procurement.id_product");
|
||||
|
||||
@@ -153,7 +157,7 @@ class InventoryItemForm extends Model{
|
||||
protected function loadProductSold(){
|
||||
|
||||
$query = new Query();
|
||||
$query->select(['sum(transfer.count) as total_sold']);
|
||||
$query->select(['coalesce(sum(transfer.count),0) as total_sold']);
|
||||
$query->from(Transfer::tableName());
|
||||
$query->innerJoin(Sale::tableName(),"sale.id_sale = transfer.id_object and transfer.type = " .Transfer::TYPE_PRODUCT);
|
||||
$query->innerJoin(Product::tableName(),"product.id_product = sale.id_product ");
|
||||
@@ -172,7 +176,7 @@ class InventoryItemForm extends Model{
|
||||
protected function loadProductStock(){
|
||||
|
||||
$query = new Query();
|
||||
$query->select(['sum(product.stock) as total_stock']);
|
||||
$query->select(['coalesce(sum(product.stock),0) as total_stock']);
|
||||
$query->from(Product::tableName());
|
||||
|
||||
if ( $this->type == 'product') {
|
||||
|
||||
@@ -71,7 +71,7 @@ class InventoryItemSearch extends InventoryItem
|
||||
'inventory.created_at as inventory_created_at',
|
||||
'inventory_prev.id_inventory as inventory_prev_id_inventory',
|
||||
'inventory_prev.name as inventory_prev_name',
|
||||
new Expression('(inventory_item.count - ( inventory_item.count_prev + inventory_item.count_in - inventory_item.count_sold )) as item_difference'),
|
||||
new Expression('(coalesce(inventory_item.count,0) - ( coalesce(inventory_item.count_prev,0) + coalesce(inventory_item.count_in,0) - coalesce(inventory_item.count_sold,0) )) as item_difference'),
|
||||
]);
|
||||
|
||||
$query->from(InventoryItem::tableName());
|
||||
|
||||
@@ -45,6 +45,9 @@ class InventorySearch extends Inventory
|
||||
|
||||
$dataProvider = new ActiveDataProvider([
|
||||
'query' => $query,
|
||||
'sort' => [
|
||||
'defaultOrder' => ['created_at' => SORT_DESC]
|
||||
]
|
||||
]);
|
||||
|
||||
$this->load($params);
|
||||
|
||||
@@ -128,7 +128,7 @@ $this->registerJs('inventoryItemIndex.init( '. json_encode($options) .' );');
|
||||
|
||||
],
|
||||
['class' => 'yii\grid\ActionColumn',
|
||||
'template' => '{update}',
|
||||
'template' => '',
|
||||
'urlCreator' => function ($action, $model, $key, $index){
|
||||
return Url::to(['inventory-item/update', 'id' => $model['item_id_inventory_item' ] ]) ;
|
||||
},
|
||||
|
||||
@@ -17,7 +17,7 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
|
||||
|
||||
<p>
|
||||
<?= Html::a(Yii::t('common/inventory', 'Új leltár'), ['create'], ['class' => 'btn btn-success']) ?>
|
||||
<?php //echo Html::a(Yii::t('common/inventory', 'Új leltár'), ['create'], ['class' => 'btn btn-success']) ?>
|
||||
</p>
|
||||
|
||||
<?= GridView::widget([
|
||||
|
||||
Reference in New Issue
Block a user