Finish inventory3
This commit is contained in:
commit
167a303296
31
backend/assets/InventoryItemIndexAsset.php
Normal file
31
backend/assets/InventoryItemIndexAsset.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* @link http://www.yiiframework.com/
|
||||
* @copyright Copyright (c) 2008 Yii Software LLC
|
||||
* @license http://www.yiiframework.com/license/
|
||||
*/
|
||||
|
||||
namespace backend\assets;
|
||||
|
||||
use yii\web\AssetBundle;
|
||||
|
||||
/**
|
||||
* @author Qiang Xue <qiang.xue@gmail.com>
|
||||
* @since 2.0
|
||||
*/
|
||||
class InventoryItemIndexAsset extends AssetBundle
|
||||
{
|
||||
public $basePath = '@webroot';
|
||||
public $baseUrl = '@web';
|
||||
public $css = [
|
||||
];
|
||||
public $js = [
|
||||
'js/app.js',
|
||||
'js/inventory.item.index.js',
|
||||
];
|
||||
public $depends = [
|
||||
'backend\assets\AppAsset',
|
||||
'yii\jui\JuiAsset',
|
||||
'common\assets\TypeAheadAsset',
|
||||
];
|
||||
}
|
||||
@ -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,26 +44,6 @@ 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.
|
||||
@ -88,43 +62,13 @@ class InventoryController extends Controller
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
return $this->redirect(['view', 'id' => $model->id_inventory]);
|
||||
} else {
|
||||
}
|
||||
return $this->render('create', [
|
||||
'model' => $model,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
|
||||
@ -10,6 +10,8 @@ use yii\web\NotFoundHttpException;
|
||||
use yii\filters\VerbFilter;
|
||||
use backend\models\InventoryItemForm;
|
||||
use common\models\Inventory;
|
||||
use yii\helpers\Url;
|
||||
use common\models\Product;
|
||||
|
||||
/**
|
||||
* InventoryItemController implements the CRUD actions for InventoryItem model.
|
||||
@ -43,13 +45,94 @@ class InventoryItemController extends Controller
|
||||
$searchModel = new InventoryItemSearch(['inventory' => $inventory]);
|
||||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
||||
|
||||
$productOptions = Product::buildProductAndInventoryGroupList();
|
||||
|
||||
if ($searchModel->output == 'xls') {
|
||||
$this->downloadIndexXls($dataProvider);
|
||||
}else{
|
||||
Url::remember(Url::current(),"inventory-item-index");
|
||||
}
|
||||
|
||||
|
||||
return $this->render('index', [
|
||||
'model' => $inventory,
|
||||
'searchModel' => $searchModel,
|
||||
'dataProvider' => $dataProvider,
|
||||
'productOptions' =>$productOptions
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
protected function downloadIndexXls($dataProvider){
|
||||
|
||||
|
||||
$defs = [['item_created_at', 'Létrehozva'],
|
||||
['item_name', 'Termék/Termék csoport'],
|
||||
['user_username', 'Felhasználó'],
|
||||
['item_count_prev', 'Előző leltár (db)'],
|
||||
['item_count_sold', 'Eladott mennyiség (db)'],
|
||||
['item_count_in', 'Beszerzett mennyiség (db)'],
|
||||
['item_count', 'Leltározott mennyiség (db)'],
|
||||
['item_difference', 'Különbség (db)'],
|
||||
['item_count_system', 'Rendszer szerinti mennyiség (db)'],
|
||||
];
|
||||
$cols = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P'];
|
||||
|
||||
$models = $dataProvider->getModels ();
|
||||
$objPHPExcel = new \PHPExcel ();
|
||||
|
||||
$sheet = $objPHPExcel->setActiveSheetIndex ( 0 );
|
||||
/**
|
||||
* Termék azonosító Termék neve Termék szám Termék vonalkód Termék raktáron Termék eladva
|
||||
*/
|
||||
$row = 1;
|
||||
$col = 0;
|
||||
foreach ( $defs as $def ) {
|
||||
$sheet->setCellValue ( $cols [$col] . $row, $def [1] );
|
||||
$col ++;
|
||||
}
|
||||
|
||||
foreach ( $models as $model ) {
|
||||
$row ++;
|
||||
$col = 0;
|
||||
foreach ( $defs as $def ) {
|
||||
$sheet->setCellValue ( $cols [$col] . $row, $model[$def [0]] );
|
||||
$col ++;
|
||||
}
|
||||
}
|
||||
|
||||
$styleArray = array (
|
||||
'font' => array (
|
||||
'bold' => true
|
||||
)
|
||||
);
|
||||
// 'color' => array('rgb' => 'FF0000'),
|
||||
// 'size' => 15,
|
||||
// 'name' => 'Verdana'
|
||||
|
||||
|
||||
|
||||
foreach ( range ( 'A', 'I' ) as $columnID ) {
|
||||
$sheet->getColumnDimension ( $columnID )->setAutoSize ( true );
|
||||
$sheet->getStyle ( $columnID . '1' )->applyFromArray ( $styleArray );
|
||||
}
|
||||
|
||||
// Redirect output to a client’s web browser (Excel5)
|
||||
header ( 'Content-Type: application/vnd.ms-excel' );
|
||||
header ( 'Content-Disposition: attachment;filename="leltar.xls"' );
|
||||
header ( 'Cache-Control: max-age=0' );
|
||||
// If you're serving to IE 9, then the following may be needed
|
||||
header ( 'Cache-Control: max-age=1' );
|
||||
// If you're serving to IE over SSL, then the following may be needed
|
||||
header ( 'Expires: Mon, 26 Jul 1997 05:00:00 GMT' ); // Date in the past
|
||||
header ( 'Last-Modified: ' . gmdate ( 'D, d M Y H:i:s' ) . ' GMT' ); // always modified
|
||||
header ( 'Cache-Control: cache, must-revalidate' ); // HTTP/1.1
|
||||
header ( 'Pragma: public' ); // HTTP/1.0
|
||||
$objWriter = \PHPExcel_IOFactory::createWriter ( $objPHPExcel, 'Excel5' );
|
||||
$objWriter->save ( 'php://output' );
|
||||
exit ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a single InventoryItem model.
|
||||
* @param integer $id
|
||||
@ -93,12 +176,21 @@ class InventoryItemController extends Controller
|
||||
public function actionUpdate($id)
|
||||
{
|
||||
$model = $this->findModel($id);
|
||||
$inventory = Inventory::findOne($model->id_inventory);
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
return $this->redirect(['view', 'id' => $model->id_inventory_item]);
|
||||
|
||||
$prev = Url::previous("inventory-item-index");
|
||||
if ( isset($prev)){
|
||||
return $this->redirect($prev);
|
||||
}else{
|
||||
return $this->redirect([ 'index', 'id' => $inventory->id_inventory ]);
|
||||
}
|
||||
|
||||
} else {
|
||||
return $this->render('update', [
|
||||
'model' => $model,
|
||||
'inventory' => $inventory,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -89,7 +89,6 @@ class InventoryItemForm extends Model{
|
||||
}
|
||||
|
||||
public function save(){
|
||||
if ( $this->validate()) {
|
||||
|
||||
|
||||
$this->loadLastInventory();
|
||||
@ -109,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'){
|
||||
@ -122,19 +125,18 @@ 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;
|
||||
return true;
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
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");
|
||||
|
||||
@ -155,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 ");
|
||||
@ -174,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') {
|
||||
|
||||
@ -20,7 +20,10 @@ use common\models\Inventory;
|
||||
class InventoryItemSearch extends InventoryItem
|
||||
{
|
||||
public $inventory;
|
||||
|
||||
public $output;
|
||||
public $item_name;
|
||||
public $item_type;
|
||||
public $item_id;
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
@ -28,6 +31,10 @@ class InventoryItemSearch extends InventoryItem
|
||||
{
|
||||
return [
|
||||
[['id_inventory_item', 'id_inventory', 'count_in', 'count_sold', 'count', 'type', 'id_product', 'id_inventory_group', 'id_user'], 'integer'],
|
||||
['output', 'string'],
|
||||
['item_name', 'string'],
|
||||
['item_type', 'string'],
|
||||
['item_id', 'integer'],
|
||||
];
|
||||
}
|
||||
|
||||
@ -50,6 +57,7 @@ class InventoryItemSearch extends InventoryItem
|
||||
public function search($params)
|
||||
{
|
||||
$query = new Query();
|
||||
|
||||
$query->select([
|
||||
'inventory_item.id_inventory_item as item_id_inventory_item',
|
||||
'inventory_item.created_at as item_created_at',
|
||||
@ -63,8 +71,9 @@ 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());
|
||||
|
||||
|
||||
@ -78,9 +87,19 @@ class InventoryItemSearch extends InventoryItem
|
||||
|
||||
$query->andWhere( ['inventory_item.id_inventory' => $this->inventory->id_inventory] );
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
$dataProvider = new ActiveDataProvider(
|
||||
['query' => $query ,
|
||||
'pagination' => ( empty($this->output) ? [] : false ),
|
||||
'sort' => [
|
||||
'defaultOrder' => ['item_name' => SORT_ASC],
|
||||
'attributes' => Helper::mkYiiSortItems([
|
||||
['item_created_at', 'item_created_at'],
|
||||
['item_name', 'item_name'],
|
||||
@ -100,22 +119,16 @@ class InventoryItemSearch extends InventoryItem
|
||||
]
|
||||
]
|
||||
);
|
||||
$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([
|
||||
'inventory_item.id_inventory_item' => $this->id_inventory_item,
|
||||
'inventory_item.type' => $this->type,
|
||||
'inventory_item.id_product' => $this->id_product,
|
||||
'inventory_item.id_inventory_group' => $this->id_inventory_group,
|
||||
'inventory_item.id_user' => $this->id_user,
|
||||
'inventory_item.created_at' => $this->created_at,
|
||||
]);
|
||||
if ( !empty($this->item_type) && is_numeric($this->item_id) ){
|
||||
if ( $this->item_type == 'product'){
|
||||
$query->andFilterWhere(['product.id_product' => $this->item_id]);
|
||||
}else if ( $this->item_type == 'group' ){
|
||||
$query->andFilterWhere(['inventory_group.id_inventory_group' => $this->item_id]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $dataProvider;
|
||||
}
|
||||
|
||||
@ -45,6 +45,9 @@ class InventorySearch extends Inventory
|
||||
|
||||
$dataProvider = new ActiveDataProvider([
|
||||
'query' => $query,
|
||||
'sort' => [
|
||||
'defaultOrder' => ['created_at' => SORT_DESC]
|
||||
]
|
||||
]);
|
||||
|
||||
$this->load($params);
|
||||
|
||||
@ -12,8 +12,6 @@ use yii\widgets\ActiveForm;
|
||||
|
||||
<?php $form = ActiveForm::begin(); ?>
|
||||
|
||||
<?= $form->field($model, 'name')->textInput(['autocomplete' => 'off']) ?>
|
||||
<?= $form->field($model, 'id_product')->hiddenInput()->label(false) ?>
|
||||
<?= $form->field($model, 'type')->hiddenInput()->label(false) ?>
|
||||
<?= $form->field($model, 'count')->textInput() ?>
|
||||
|
||||
|
||||
@ -11,36 +11,22 @@ use yii\widgets\ActiveForm;
|
||||
<div class="inventory-item-search">
|
||||
|
||||
<?php $form = ActiveForm::begin([
|
||||
'action' => ['index'],
|
||||
'action' => ['index','id' => $model->inventory->id_inventory],
|
||||
'method' => 'get',
|
||||
]); ?>
|
||||
|
||||
<?= $form->field($model, 'id_inventory_item') ?>
|
||||
|
||||
<?= $form->field($model, 'id_inventory') ?>
|
||||
|
||||
<?= $form->field($model, 'count_in') ?>
|
||||
|
||||
<?= $form->field($model, 'count_sold') ?>
|
||||
|
||||
<?= $form->field($model, 'count') ?>
|
||||
|
||||
<?php // echo $form->field($model, 'type') ?>
|
||||
|
||||
<?php // echo $form->field($model, 'id_product') ?>
|
||||
|
||||
<?php // echo $form->field($model, 'id_inventory_group') ?>
|
||||
|
||||
<?php // echo $form->field($model, 'id_user') ?>
|
||||
<?= $form->field($model, 'item_type')->hiddenInput()->label(false) ?>
|
||||
<?= $form->field($model, 'item_id')->hiddenInput()->label(false) ?>
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<?= $form->field($model, 'item_name')->label("Termék/Termék csoport neve") ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<?php // echo $form->field($model, 'created_at') ?>
|
||||
|
||||
<?php // echo $form->field($model, 'updated_at') ?>
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton(Yii::t('common/inventory-item', 'Search'), ['class' => 'btn btn-primary']) ?>
|
||||
<?= Html::resetButton(Yii::t('common/inventory-item', 'Reset'), ['class' => 'btn btn-default']) ?>
|
||||
<?= Html::submitButton(Yii::t('common/inventory-item', 'Keresés'), ['class' => 'btn btn-primary']) ?>
|
||||
</div>
|
||||
|
||||
<?php ActiveForm::end(); ?>
|
||||
|
||||
@ -4,6 +4,7 @@ use yii\helpers\Html;
|
||||
use yii\grid\GridView;
|
||||
use yii\widgets\DetailView;
|
||||
use yii\helpers\Url;
|
||||
use backend\assets\InventoryItemIndexAsset;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $searchModel backend\models\InventoryItemSearch */
|
||||
@ -11,6 +12,15 @@ use yii\helpers\Url;
|
||||
|
||||
$this->title = Yii::t('common/inventory-item', 'Leltár részletei');
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
|
||||
|
||||
InventoryItemIndexAsset::register($this);
|
||||
|
||||
$options = [];
|
||||
$options['products'] = $productOptions;
|
||||
|
||||
$this->registerJs('inventoryItemIndex.init( '. json_encode($options) .' );');
|
||||
|
||||
?>
|
||||
<div class="inventory-item-index">
|
||||
|
||||
@ -23,17 +33,17 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
'name',
|
||||
['attribute'=>'id_user',
|
||||
'value'=>$model->userName
|
||||
],
|
||||
['attribute'=>'id_account',
|
||||
'value'=>$model->accountName
|
||||
],
|
||||
'created_at:datetime',
|
||||
],
|
||||
]) ?>
|
||||
|
||||
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
|
||||
<?php echo $this->render('_search', ['model' => $searchModel]); ?>
|
||||
|
||||
|
||||
<p>
|
||||
<?= Html::a(Yii::t('common/inventory', 'Új termék felvétele a leltárba'), ['inventory-item/create','id' =>$model->id_inventory], ['class' => 'btn btn-success']) ?>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Magyarázat:
|
||||
@ -59,6 +69,10 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
</ul>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<?php echo Html::a("XLS letöltése", Url::current(['InventoryItemSearch[output]' =>'xls']),['class' =>'btn btn-primary'])?>
|
||||
</p>
|
||||
|
||||
<?php
|
||||
echo GridView::widget( [
|
||||
'dataProvider' => $dataProvider,
|
||||
@ -114,16 +128,14 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
|
||||
],
|
||||
['class' => 'yii\grid\ActionColumn',
|
||||
'template' => '{delete}',
|
||||
'template' => '',
|
||||
'urlCreator' => function ($action, $model, $key, $index){
|
||||
return Url::to(['inventory-item/delete', 'id' => $model['item_id_inventory_item' ] ]) ;
|
||||
return Url::to(['inventory-item/update', 'id' => $model['item_id_inventory_item' ] ]) ;
|
||||
},
|
||||
'buttons' =>[
|
||||
'delete' =>function ($url, $model, $key) {
|
||||
return Html::a('Törlés', $url,['class' => 'btn btn-xs btn-danger',
|
||||
'update' =>function ($url, $model, $key) {
|
||||
return Html::a('Módosítás', $url,['class' => 'btn btn-xs btn-success',
|
||||
'data' => [
|
||||
'confirm' => Yii::t('common/inventory-item', 'Biztosan törlöd ezt az elemet?'),
|
||||
'method' => 'post',
|
||||
],
|
||||
]) ;
|
||||
}
|
||||
|
||||
@ -1,13 +1,12 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\DetailView;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model common\models\InventoryItem */
|
||||
|
||||
$this->title = Yii::t('common/inventory-item', 'Update {modelClass}: ', [
|
||||
'modelClass' => 'Inventory Item',
|
||||
]) . ' ' . $model->id_inventory_item;
|
||||
$this->title = Yii::t('common/inventory-item', 'Leltár termék');
|
||||
$this->params['breadcrumbs'][] = ['label' => Yii::t('common/inventory-item', 'Inventory Items'), 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = ['label' => $model->id_inventory_item, 'url' => ['view', 'id' => $model->id_inventory_item]];
|
||||
$this->params['breadcrumbs'][] = Yii::t('common/inventory-item', 'Update');
|
||||
@ -16,6 +15,37 @@ $this->params['breadcrumbs'][] = Yii::t('common/inventory-item', 'Update');
|
||||
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
|
||||
<h2>Leltár</h2>
|
||||
<?= DetailView::widget([
|
||||
'model' => $inventory,
|
||||
'attributes' => [
|
||||
'id_inventory',
|
||||
'name',
|
||||
['attribute'=>'id_user',
|
||||
'value'=>$inventory->userName
|
||||
],
|
||||
['attribute'=>'id_account',
|
||||
'value'=>$inventory->accountName
|
||||
],
|
||||
'created_at:datetime',
|
||||
],
|
||||
]) ?>
|
||||
|
||||
<h2>Termék</h2>
|
||||
<?= DetailView::widget([
|
||||
'model' => $model,
|
||||
'attributes' => [
|
||||
[
|
||||
|
||||
'value' => $model->name,
|
||||
'label' =>"Név"
|
||||
],
|
||||
|
||||
|
||||
|
||||
],
|
||||
]) ?>
|
||||
|
||||
<?= $this->render('_form', [
|
||||
'model' => $model,
|
||||
]) ?>
|
||||
|
||||
@ -2,18 +2,27 @@
|
||||
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\ActiveForm;
|
||||
use common\models\Account;
|
||||
use common\components\Helper;
|
||||
use frontend\components\HtmlHelper;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model common\models\Inventory */
|
||||
/* @var $form yii\widgets\ActiveForm */
|
||||
?>
|
||||
|
||||
<?php
|
||||
|
||||
$accounts = ['' =>'Mind'] + HtmlHelper::mkAccountOptions( Account::readAccounts() );
|
||||
?>
|
||||
|
||||
<div class="inventory-form">
|
||||
|
||||
<?php $form = ActiveForm::begin(); ?>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<?php echo $form->field($model, "id_account")->dropDownList($accounts)?>
|
||||
<?php echo $form->field($model, "name")->textInput()?>
|
||||
<?= Html::submitButton($model->isNewRecord ? Yii::t('common/inventory', 'Létrehoz') : Yii::t('common/inventory', 'Módosít'), [ 'name'=>'Inventory[submit]' ,'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
|
||||
</div>
|
||||
|
||||
@ -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([
|
||||
|
||||
58
backend/web/js/inventory.item.index.js
Normal file
58
backend/web/js/inventory.item.index.js
Normal file
@ -0,0 +1,58 @@
|
||||
|
||||
|
||||
var inventoryItemIndex = {
|
||||
|
||||
defaults : {
|
||||
products: [],
|
||||
selector_type : '#inventoryitemsearch-item_type',
|
||||
selector_name : '#inventoryitemsearch-item_name',
|
||||
selector_id : '#inventoryitemsearch-item_id',
|
||||
},
|
||||
product: null,
|
||||
init: function(o){
|
||||
this.defaults = $.extend( this.defaults, o );
|
||||
this.initAutocomplete();
|
||||
|
||||
},
|
||||
|
||||
initAutocomplete : function (){
|
||||
var self = this;
|
||||
|
||||
var $input = $(self.defaults.selector_name);
|
||||
$input.typeahead({source : self.defaults.products,
|
||||
autoSelect: true,
|
||||
items: 20,
|
||||
minLength: 3,
|
||||
});
|
||||
$input.change(function() {
|
||||
var current = $input.typeahead("getActive");
|
||||
$("#filter_text").val('');
|
||||
if (current) {
|
||||
// Some item from your model is active!
|
||||
if (current.name == $input.val()) {
|
||||
self.product = current;
|
||||
} else {
|
||||
self.product = null;
|
||||
}
|
||||
} else {
|
||||
self.product = null;
|
||||
}
|
||||
self.productChange();
|
||||
});
|
||||
},
|
||||
productChange: function( ){
|
||||
this.clearProductData();
|
||||
this.setProductData();
|
||||
},
|
||||
clearProductData: function(){
|
||||
$(this.defaults.selector_type).val('');
|
||||
$(this.defaults.selector_id).val('');
|
||||
},
|
||||
setProductData: function(){
|
||||
if ( this.product ){
|
||||
$(this.defaults.selector_type).val( this.product.type);
|
||||
$(this.defaults.selector_id ).val( this.product.id);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -5,12 +5,16 @@ namespace common\models;
|
||||
use Yii;
|
||||
use common\components\UserAwareBehavior;
|
||||
use yii\helpers\ArrayHelper;
|
||||
use yii\db\Query;
|
||||
use backend\models\InventoryItemForm;
|
||||
use common\components\AccountAwareBehavior;
|
||||
|
||||
/**
|
||||
* This is the model class for table "inventory".
|
||||
*
|
||||
* @property integer $id_inventory
|
||||
* @property integer $id_user
|
||||
* @property integer $id_account
|
||||
* @property string $name
|
||||
* @property string $created_at
|
||||
* @property string $updated_at
|
||||
@ -27,13 +31,15 @@ class Inventory extends \common\models\BaseFitnessActiveRecord
|
||||
return 'inventory';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['name'], 'string']
|
||||
[['name'], 'string'],
|
||||
[['id_account'], 'integer'],
|
||||
];
|
||||
}
|
||||
|
||||
@ -46,6 +52,7 @@ class Inventory extends \common\models\BaseFitnessActiveRecord
|
||||
'id_inventory' => Yii::t('common/inventory', 'Leltár azonosító'),
|
||||
'name' => Yii::t('common/inventory', 'Megnevezés'),
|
||||
'id_user' => Yii::t('common/inventory', 'Felhasználó'),
|
||||
'id_account' => Yii::t('common/inventory', 'Kassza'),
|
||||
'created_at' => Yii::t('common/inventory', 'Létrehozás'),
|
||||
'updated_at' => Yii::t('common/inventory', 'Módosítás'),
|
||||
];
|
||||
@ -59,7 +66,59 @@ class Inventory extends \common\models\BaseFitnessActiveRecord
|
||||
return ArrayHelper::merge( [
|
||||
[
|
||||
'class' => UserAwareBehavior::className(),
|
||||
],
|
||||
[
|
||||
'class' => AccountAwareBehavior::className()
|
||||
|
||||
]
|
||||
], parent::behaviors());
|
||||
}
|
||||
|
||||
public function afterSave($insert, $changedAttributes){
|
||||
if ( $insert ){
|
||||
|
||||
$query = Product::find();
|
||||
if ( isset($this->id_account) && is_numeric($this->id_account)){
|
||||
$query->andWhere(['id_account' => $this->id_account]);
|
||||
|
||||
}
|
||||
// $query->andWhere("product.id_inventory_group is null");
|
||||
$products = $query->all();
|
||||
|
||||
echo "Products found: " . count($products);
|
||||
|
||||
$inventoryGroups = InventoryGroup::find()->all();
|
||||
|
||||
|
||||
foreach ($products as $product){
|
||||
$form = new InventoryItemForm(
|
||||
[
|
||||
'inventory' => $this,
|
||||
'id_product' => $product->id_product,
|
||||
'product' => $product,
|
||||
'type' => 'product'
|
||||
]
|
||||
);
|
||||
$form->save();
|
||||
}
|
||||
|
||||
foreach ($inventoryGroups as $group){
|
||||
$form = new InventoryItemForm(
|
||||
[
|
||||
'inventory' => $this,
|
||||
'id_product' => $group->id_inventory_group,
|
||||
'inventoryGroup' => $group,
|
||||
'type' => 'group'
|
||||
]
|
||||
);
|
||||
$form->save();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -6,6 +6,7 @@ use Yii;
|
||||
use yii\helpers\ArrayHelper;
|
||||
use common\components\UserAwareBehavior;
|
||||
use common\components\Helper;
|
||||
use common\components\ProductAwareBehavior;
|
||||
|
||||
/**
|
||||
* This is the model class for table "inventory_item".
|
||||
@ -45,6 +46,8 @@ class InventoryItem extends BaseFitnessActiveRecord
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['count'],'integer'] ,
|
||||
[['count'],'required'] ,
|
||||
];
|
||||
}
|
||||
|
||||
@ -58,7 +61,7 @@ class InventoryItem extends BaseFitnessActiveRecord
|
||||
'id_inventory' => Yii::t('common/inventory_item', 'Id Inventory'),
|
||||
'count_in' => Yii::t('common/inventory_item', 'Count In'),
|
||||
'count_sold' => Yii::t('common/inventory_item', 'Count Sold'),
|
||||
'count' => Yii::t('common/inventory_item', 'Count'),
|
||||
'count' => Yii::t('common/inventory_item', 'Leltározott mennyiség'),
|
||||
'type' => Yii::t('common/inventory_item', 'Type'),
|
||||
'id_product' => Yii::t('common/inventory_item', 'Id Product'),
|
||||
'id_inventory_group' => Yii::t('common/inventory_item', 'Id Inventory Group'),
|
||||
@ -72,6 +75,9 @@ class InventoryItem extends BaseFitnessActiveRecord
|
||||
return ArrayHelper::merge( [
|
||||
[
|
||||
'class' => UserAwareBehavior::className(),
|
||||
],
|
||||
[
|
||||
'class' => ProductAwareBehavior::className(),
|
||||
]
|
||||
], parent::behaviors());
|
||||
}
|
||||
@ -133,4 +139,18 @@ class InventoryItem extends BaseFitnessActiveRecord
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function afterSave($insert, $changedAttributes){
|
||||
if ( !$insert ){
|
||||
if ( $this->type == 'product'){
|
||||
$product = $this->product;
|
||||
$product->stock = $this->count;
|
||||
if ( !$product->save(false) ){
|
||||
\Yii::error("Failed to save product stock");
|
||||
throw new \Exception("A leltár elem mentése nem sikerült");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -264,4 +264,36 @@ class Product extends \common\models\BaseFitnessActiveRecord {
|
||||
$product->stock = $product->stock - $count;
|
||||
}
|
||||
|
||||
|
||||
public static function readProductsNotPartOfInventoryGroup( $id_account = null ){
|
||||
$query = Product::find();
|
||||
$query->andWhere("id_inventory_group is null");
|
||||
$query->andWhere(['status' => Product::STATUS_ACTIVE]);
|
||||
return $query->all();
|
||||
}
|
||||
|
||||
public static function readInventoryGroups(){
|
||||
$query = InventoryGroup::find();
|
||||
$query->andWhere(['status' => Product::STATUS_ACTIVE]);
|
||||
return $query->all();
|
||||
}
|
||||
|
||||
public static function buildProductAndInventoryGroupList($id_account = null){
|
||||
$productOptions = [];
|
||||
|
||||
$products = Product::readProductsNotPartOfInventoryGroup($id_account);
|
||||
$inventoryGroups = Product::readInventoryGroups();
|
||||
|
||||
foreach ($products as $product ){
|
||||
$productOptions[]= [ 'type' =>'product', 'id' => $product->id_product ,'name' => $product->name . " (Termék/" .$product->productCategoryName ."/" . $product->accountName .")" ];
|
||||
}
|
||||
|
||||
foreach ($inventoryGroups as $inventoryGroup ){
|
||||
$productOptions[] = ['type' =>'group', 'id' =>$inventoryGroup->id_inventory_group ,'name' =>$inventoryGroup->name ."/Termékcsoport" ];
|
||||
|
||||
}
|
||||
return $productOptions;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
use yii\db\Schema;
|
||||
use yii\db\Migration;
|
||||
|
||||
class m160321_082725_alter__inventory__add__column__id_account extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
$this->addColumn("inventory", "id_account", "int");
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
echo "m160321_082725_alter__inventory__add__column__id_account cannot be reverted.\n";
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
// Use safeUp/safeDown to run migration code within a transaction
|
||||
public function safeUp()
|
||||
{
|
||||
}
|
||||
|
||||
public function safeDown()
|
||||
{
|
||||
}
|
||||
*/
|
||||
}
|
||||
30
frontend/assets/InventoryItemIndexAsset.php
Normal file
30
frontend/assets/InventoryItemIndexAsset.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* @link http://www.yiiframework.com/
|
||||
* @copyright Copyright (c) 2008 Yii Software LLC
|
||||
* @license http://www.yiiframework.com/license/
|
||||
*/
|
||||
|
||||
namespace frontend\assets;
|
||||
|
||||
use yii\web\AssetBundle;
|
||||
|
||||
/**
|
||||
* @author Qiang Xue <qiang.xue@gmail.com>
|
||||
* @since 2.0
|
||||
*/
|
||||
class InventoryItemIndexAsset extends AssetBundle
|
||||
{
|
||||
public $basePath = '@webroot';
|
||||
public $baseUrl = '@web';
|
||||
public $css = [
|
||||
];
|
||||
public $js = [
|
||||
'js/inventory.item.index.js',
|
||||
];
|
||||
public $depends = [
|
||||
'frontend\assets\AppAsset',
|
||||
'yii\jui\JuiAsset',
|
||||
'common\assets\TypeAheadAsset',
|
||||
];
|
||||
}
|
||||
@ -88,7 +88,8 @@ class FrontendMenuStructure{
|
||||
// }
|
||||
|
||||
$items[] = ['label' => Yii::t('frontend/card','Vendégek'), 'url' => [ '/card/index' ] ];
|
||||
$items[] = ['label' => Yii::t('frontend/card','Leltár'), 'url' => [ '/product/inventory' ] ];
|
||||
// $items[] = ['label' => Yii::t('frontend/card','Leltár'), 'url' => [ '/product/inventory' ] ];
|
||||
$items[] = ['label' => Yii::t('frontend/card','Leltár'), 'url' => [ '/inventory/index' ] ];
|
||||
|
||||
|
||||
$this->menuItems[] = ['label' => Yii::t('frontend/account', 'Account'),
|
||||
|
||||
86
frontend/controllers/InventoryController.php
Normal file
86
frontend/controllers/InventoryController.php
Normal file
@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\controllers;
|
||||
|
||||
use Yii;
|
||||
use common\models\Inventory;
|
||||
use frontend\models\InventorySearch;
|
||||
use yii\web\Controller;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\filters\VerbFilter;
|
||||
use common\models\User;
|
||||
|
||||
/**
|
||||
* InventoryController implements the CRUD actions for Inventory model.
|
||||
*/
|
||||
class InventoryController extends Controller
|
||||
{
|
||||
public function behaviors()
|
||||
{
|
||||
return [
|
||||
'verbs' => [
|
||||
'class' => VerbFilter::className(),
|
||||
'actions' => [
|
||||
'delete' => ['post'],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all Inventory models.
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionIndex()
|
||||
{
|
||||
$searchModel = new InventorySearch();
|
||||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
||||
|
||||
return $this->render('index', [
|
||||
'searchModel' => $searchModel,
|
||||
'dataProvider' => $dataProvider,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new Inventory model.
|
||||
* If creation is successful, the browser will be redirected to the 'view' page.
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionCreate()
|
||||
{
|
||||
$model = new Inventory();
|
||||
$user = User::findOne(\Yii::$app->user->id);
|
||||
|
||||
|
||||
$model->name = 'Leltár_'.date('Ymd_His') .'_' . $user->username;
|
||||
|
||||
$model->id_user = \Yii::$app->user->id;
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
return $this->redirect(['inventory-item/index', 'id' => $model->id_inventory]);
|
||||
} else {
|
||||
}
|
||||
return $this->render('create', [
|
||||
'model' => $model,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Finds the Inventory model based on its primary key value.
|
||||
* If the model is not found, a 404 HTTP exception will be thrown.
|
||||
* @param integer $id
|
||||
* @return Inventory the loaded model
|
||||
* @throws NotFoundHttpException if the model cannot be found
|
||||
*/
|
||||
protected function findModel($id)
|
||||
{
|
||||
if (($model = Inventory::findOne($id)) !== null) {
|
||||
return $model;
|
||||
} else {
|
||||
throw new NotFoundHttpException('The requested page does not exist.');
|
||||
}
|
||||
}
|
||||
}
|
||||
228
frontend/controllers/InventoryItemController.php
Normal file
228
frontend/controllers/InventoryItemController.php
Normal file
@ -0,0 +1,228 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\controllers;
|
||||
|
||||
use Yii;
|
||||
use common\models\InventoryItem;
|
||||
use frontend\models\InventoryItemSearch;
|
||||
use yii\web\Controller;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\filters\VerbFilter;
|
||||
use backend\models\InventoryItemForm;
|
||||
use common\models\Inventory;
|
||||
use yii\helpers\Url;
|
||||
use common\models\Product;
|
||||
|
||||
/**
|
||||
* InventoryItemController implements the CRUD actions for InventoryItem model.
|
||||
*/
|
||||
class InventoryItemController extends Controller
|
||||
{
|
||||
public function behaviors()
|
||||
{
|
||||
return [
|
||||
'verbs' => [
|
||||
'class' => VerbFilter::className(),
|
||||
'actions' => [
|
||||
'delete' => ['post'],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all InventoryItem models.
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionIndex($id)
|
||||
{
|
||||
$inventory = Inventory::findOne($id);
|
||||
|
||||
if ( !isset($inventory)){
|
||||
throw new NotFoundHttpException("Leltár nem található");
|
||||
}
|
||||
|
||||
$searchModel = new InventoryItemSearch(['inventory' => $inventory]);
|
||||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
||||
|
||||
$productOptions = Product::buildProductAndInventoryGroupList();
|
||||
|
||||
if ($searchModel->output == 'xls') {
|
||||
$this->downloadIndexXls($dataProvider);
|
||||
}else{
|
||||
Url::remember(Url::current(),"inventory-item-index");
|
||||
}
|
||||
|
||||
|
||||
return $this->render('index', [
|
||||
'model' => $inventory,
|
||||
'searchModel' => $searchModel,
|
||||
'dataProvider' => $dataProvider,
|
||||
'productOptions' =>$productOptions
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
protected function downloadIndexXls($dataProvider){
|
||||
|
||||
|
||||
$defs = [['item_created_at', 'Létrehozva'],
|
||||
['item_name', 'Termék/Termék csoport'],
|
||||
['user_username', 'Felhasználó'],
|
||||
['item_count_prev', 'Előző leltár (db)'],
|
||||
['item_count_sold', 'Eladott mennyiség (db)'],
|
||||
['item_count_in', 'Beszerzett mennyiség (db)'],
|
||||
['item_count', 'Leltározott mennyiség (db)'],
|
||||
['item_difference', 'Különbség (db)'],
|
||||
['item_count_system', 'Rendszer szerinti mennyiség (db)'],
|
||||
];
|
||||
$cols = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P'];
|
||||
|
||||
$models = $dataProvider->getModels ();
|
||||
$objPHPExcel = new \PHPExcel ();
|
||||
|
||||
$sheet = $objPHPExcel->setActiveSheetIndex ( 0 );
|
||||
/**
|
||||
* Termék azonosító Termék neve Termék szám Termék vonalkód Termék raktáron Termék eladva
|
||||
*/
|
||||
$row = 1;
|
||||
$col = 0;
|
||||
foreach ( $defs as $def ) {
|
||||
$sheet->setCellValue ( $cols [$col] . $row, $def [1] );
|
||||
$col ++;
|
||||
}
|
||||
|
||||
foreach ( $models as $model ) {
|
||||
$row ++;
|
||||
$col = 0;
|
||||
foreach ( $defs as $def ) {
|
||||
$sheet->setCellValue ( $cols [$col] . $row, $model[$def [0]] );
|
||||
$col ++;
|
||||
}
|
||||
}
|
||||
|
||||
$styleArray = array (
|
||||
'font' => array (
|
||||
'bold' => true
|
||||
)
|
||||
);
|
||||
// 'color' => array('rgb' => 'FF0000'),
|
||||
// 'size' => 15,
|
||||
// 'name' => 'Verdana'
|
||||
|
||||
|
||||
|
||||
foreach ( range ( 'A', 'I' ) as $columnID ) {
|
||||
$sheet->getColumnDimension ( $columnID )->setAutoSize ( true );
|
||||
$sheet->getStyle ( $columnID . '1' )->applyFromArray ( $styleArray );
|
||||
}
|
||||
|
||||
// Redirect output to a client’s web browser (Excel5)
|
||||
header ( 'Content-Type: application/vnd.ms-excel' );
|
||||
header ( 'Content-Disposition: attachment;filename="leltar.xls"' );
|
||||
header ( 'Cache-Control: max-age=0' );
|
||||
// If you're serving to IE 9, then the following may be needed
|
||||
header ( 'Cache-Control: max-age=1' );
|
||||
// If you're serving to IE over SSL, then the following may be needed
|
||||
header ( 'Expires: Mon, 26 Jul 1997 05:00:00 GMT' ); // Date in the past
|
||||
header ( 'Last-Modified: ' . gmdate ( 'D, d M Y H:i:s' ) . ' GMT' ); // always modified
|
||||
header ( 'Cache-Control: cache, must-revalidate' ); // HTTP/1.1
|
||||
header ( 'Pragma: public' ); // HTTP/1.0
|
||||
$objWriter = \PHPExcel_IOFactory::createWriter ( $objPHPExcel, 'Excel5' );
|
||||
$objWriter->save ( 'php://output' );
|
||||
exit ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a single InventoryItem model.
|
||||
* @param integer $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionView($id)
|
||||
{
|
||||
return $this->render('view', [
|
||||
'model' => $this->findModel($id),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new InventoryItem model.
|
||||
* If creation is successful, the browser will be redirected to the 'view' page.
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionCreate($id)
|
||||
{
|
||||
$model = new InventoryItemForm([
|
||||
'id_inventory' => $id
|
||||
]);
|
||||
|
||||
$model->read();
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
return $this->redirect(['inventory-item/index', 'id' => $model->inventory->id_inventory]);
|
||||
} else {
|
||||
return $this->render('create', [
|
||||
'model' => $model,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates an existing InventoryItem 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);
|
||||
$inventory = Inventory::findOne($model->id_inventory);
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
|
||||
$prev = Url::previous("inventory-item-index");
|
||||
if ( isset($prev)){
|
||||
return $this->redirect($prev);
|
||||
}else{
|
||||
return $this->redirect([ 'index', 'id' => $inventory->id_inventory ]);
|
||||
}
|
||||
|
||||
} else {
|
||||
return $this->render('update', [
|
||||
'model' => $model,
|
||||
'inventory' => $inventory,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an existing InventoryItem model.
|
||||
* If deletion is successful, the browser will be redirected to the 'index' page.
|
||||
* @param integer $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionDelete($id)
|
||||
{
|
||||
$item = $this->findModel($id);
|
||||
$id_inventory = $item->id_inventory;
|
||||
$item->delete();
|
||||
|
||||
return $this->redirect(['index', 'id' => $id_inventory]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the InventoryItem model based on its primary key value.
|
||||
* If the model is not found, a 404 HTTP exception will be thrown.
|
||||
* @param integer $id
|
||||
* @return InventoryItem the loaded model
|
||||
* @throws NotFoundHttpException if the model cannot be found
|
||||
*/
|
||||
protected function findModel($id)
|
||||
{
|
||||
if (($model = InventoryItem::findOne($id)) !== null) {
|
||||
return $model;
|
||||
} else {
|
||||
throw new NotFoundHttpException('The requested page does not exist.');
|
||||
}
|
||||
}
|
||||
}
|
||||
135
frontend/models/InventoryItemSearch.php
Normal file
135
frontend/models/InventoryItemSearch.php
Normal file
@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\models;
|
||||
|
||||
use Yii;
|
||||
use yii\base\Model;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use common\models\InventoryItem;
|
||||
use yii\db\Query;
|
||||
use yii\db\Expression;
|
||||
use common\models\User;
|
||||
use common\models\Product;
|
||||
use common\models\InventoryGroup;
|
||||
use common\components\Helper;
|
||||
use common\models\Inventory;
|
||||
|
||||
/**
|
||||
* InventoryItemSearch represents the model behind the search form about `common\models\InventoryItem`.
|
||||
*/
|
||||
class InventoryItemSearch extends InventoryItem
|
||||
{
|
||||
public $inventory;
|
||||
public $output;
|
||||
public $item_name;
|
||||
public $item_type;
|
||||
public $item_id;
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['id_inventory_item', 'id_inventory', 'count_in', 'count_sold', 'count', 'type', 'id_product', 'id_inventory_group', 'id_user'], 'integer'],
|
||||
['output', 'string'],
|
||||
['item_name', 'string'],
|
||||
['item_type', 'string'],
|
||||
['item_id', 'integer'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 = new Query();
|
||||
|
||||
$query->select([
|
||||
'inventory_item.id_inventory_item as item_id_inventory_item',
|
||||
'inventory_item.created_at as item_created_at',
|
||||
new Expression('case when inventory_item.id_product is null then inventory_group.name else product.name end as item_name'),
|
||||
'user.username as user_username',
|
||||
'coalesce(inventory_item.count_prev ,0)as item_count_prev',
|
||||
'coalesce(inventory_item.count_in,0) as item_count_in',
|
||||
'coalesce(inventory_item.count_sold,0) as item_count_sold',
|
||||
'coalesce(inventory_item.count,0) as item_count',
|
||||
'coalesce(inventory_item.count_system,0) as item_count_system',
|
||||
'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('(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());
|
||||
|
||||
|
||||
$query->innerJoin(User::tableName(), "user.id = inventory_item.id_user");
|
||||
$query->leftJoin(Product::tableName(), "product.id_product = inventory_item.id_product");
|
||||
$query->leftJoin(InventoryGroup::tableName(), "inventory_group.id_inventory_group = inventory_item.id_inventory_group");
|
||||
$query->leftJoin(Inventory::tableName(), "inventory.id_inventory = inventory_item.id_inventory");
|
||||
|
||||
$query->leftJoin( "inventory_item as item_prev", "item_prev.id_inventory_item = inventory_item.id_inventory_item_prev" );
|
||||
$query->leftJoin( "inventory as inventory_prev", "inventory_prev.id_inventory = item_prev.id_inventory" );
|
||||
|
||||
$query->andWhere( ['inventory_item.id_inventory' => $this->inventory->id_inventory] );
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
$dataProvider = new ActiveDataProvider(
|
||||
['query' => $query ,
|
||||
'pagination' => ( empty($this->output) ? [] : false ),
|
||||
'sort' => [
|
||||
'defaultOrder' => ['item_name' => SORT_ASC],
|
||||
'attributes' => Helper::mkYiiSortItems([
|
||||
['item_created_at', 'item_created_at'],
|
||||
['item_name', 'item_name'],
|
||||
['user_username', 'user_username'],
|
||||
['item_count_prev', 'item_count_prev'],
|
||||
['item_count_sold', 'item_count_sold'],
|
||||
['item_count_in', 'item_count_in'],
|
||||
['item_count', 'item_count'],
|
||||
['item_count', 'item_count'],
|
||||
['item_difference', 'item_difference'],
|
||||
['item_count_system', 'item_count_system'],
|
||||
['inventory.id_inventory', 'inventory_id_inventory'],
|
||||
['inventory.name', 'inventory_name'],
|
||||
['inventory_prev_name', 'inventory_prev_name'],
|
||||
])
|
||||
,
|
||||
]
|
||||
]
|
||||
);
|
||||
|
||||
|
||||
if ( !empty($this->item_type) && is_numeric($this->item_id) ){
|
||||
if ( $this->item_type == 'product'){
|
||||
$query->andFilterWhere(['product.id_product' => $this->item_id]);
|
||||
}else if ( $this->item_type == 'group' ){
|
||||
$query->andFilterWhere(['inventory_group.id_inventory_group' => $this->item_id]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $dataProvider;
|
||||
}
|
||||
}
|
||||
70
frontend/models/InventorySearch.php
Normal file
70
frontend/models/InventorySearch.php
Normal file
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\models;
|
||||
|
||||
use Yii;
|
||||
use yii\base\Model;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use common\models\Inventory;
|
||||
|
||||
/**
|
||||
* InventorySearch represents the model behind the search form about `common\models\Inventory`.
|
||||
*/
|
||||
class InventorySearch extends Inventory
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['id_inventory', 'id_user'], 'integer'],
|
||||
[['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 = Inventory::find();
|
||||
|
||||
$dataProvider = new ActiveDataProvider([
|
||||
'query' => $query,
|
||||
'sort' =>[
|
||||
'defaultOrder' => [ 'created_at' => SORT_DESC ]
|
||||
]
|
||||
]);
|
||||
|
||||
$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_inventory' => $this->id_inventory,
|
||||
'id_user' => $this->id_user,
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
]);
|
||||
|
||||
return $dataProvider;
|
||||
}
|
||||
}
|
||||
25
frontend/views/inventory-item/_form.php
Normal file
25
frontend/views/inventory-item/_form.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\ActiveForm;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model common\models\InventoryItem */
|
||||
/* @var $form yii\widgets\ActiveForm */
|
||||
?>
|
||||
|
||||
<div class="inventory-item-form">
|
||||
|
||||
<?php $form = ActiveForm::begin(); ?>
|
||||
|
||||
<?= $form->field($model, 'type')->hiddenInput()->label(false) ?>
|
||||
<?= $form->field($model, 'count')->textInput() ?>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton( Yii::t('common/inventory-item', 'Mentés') , ['class' => 'btn btn-success' ]) ?>
|
||||
</div>
|
||||
|
||||
<?php ActiveForm::end(); ?>
|
||||
|
||||
</div>
|
||||
34
frontend/views/inventory-item/_search.php
Normal file
34
frontend/views/inventory-item/_search.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\ActiveForm;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model backend\models\InventoryItemSearch */
|
||||
/* @var $form yii\widgets\ActiveForm */
|
||||
?>
|
||||
|
||||
<div class="inventory-item-search">
|
||||
|
||||
<?php $form = ActiveForm::begin([
|
||||
'action' => ['index','id' => $model->inventory->id_inventory],
|
||||
'method' => 'get',
|
||||
]); ?>
|
||||
|
||||
<?= $form->field($model, 'item_type')->hiddenInput()->label(false) ?>
|
||||
<?= $form->field($model, 'item_id')->hiddenInput()->label(false) ?>
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<?= $form->field($model, 'item_name')->label("Termék/Termék csoport neve") ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton(Yii::t('common/inventory-item', 'Keresés'), ['class' => 'btn btn-primary']) ?>
|
||||
</div>
|
||||
|
||||
<?php ActiveForm::end(); ?>
|
||||
|
||||
</div>
|
||||
33
frontend/views/inventory-item/create.php
Normal file
33
frontend/views/inventory-item/create.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
use backend\assets\InventoryItemCreateAsset;
|
||||
use yii\helpers\Url;
|
||||
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model common\models\InventoryItem */
|
||||
|
||||
$this->title = Yii::t('common/inventory-item', 'Új leltár elem');
|
||||
$this->params['breadcrumbs'][] = ['label' => 'Leltár' , 'url' => ['inventory/view', 'id' => $model->inventory->id_inventory]];
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
|
||||
InventoryItemCreateAsset::register($this);
|
||||
|
||||
|
||||
$options = [];
|
||||
$options['products'] = $model->productOptions;
|
||||
$options['url_product_find'] = Url::toRoute(['product/find']);
|
||||
|
||||
$this->registerJs('inventoryItemCreate.init( '. json_encode($options) .' );');
|
||||
|
||||
?>
|
||||
<div class="inventory-item-create">
|
||||
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
|
||||
<?= $this->render('_form', [
|
||||
'model' => $model,
|
||||
]) ?>
|
||||
|
||||
</div>
|
||||
146
frontend/views/inventory-item/index.php
Normal file
146
frontend/views/inventory-item/index.php
Normal file
@ -0,0 +1,146 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
use yii\grid\GridView;
|
||||
use yii\widgets\DetailView;
|
||||
use yii\helpers\Url;
|
||||
use backend\assets\InventoryItemIndexAsset;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $searchModel backend\models\InventoryItemSearch */
|
||||
/* @var $dataProvider yii\data\ActiveDataProvider */
|
||||
|
||||
$this->title = Yii::t('common/inventory-item', 'Leltár részletei');
|
||||
|
||||
$this->params['breadcrumbs'][] = ['label' => 'Leltár lista' , 'url' => ['inventory/index']];;
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
|
||||
|
||||
InventoryItemIndexAsset::register($this);
|
||||
|
||||
$options = [];
|
||||
$options['products'] = $productOptions;
|
||||
|
||||
$this->registerJs('inventoryItemIndex.init( '. json_encode($options) .' );');
|
||||
|
||||
?>
|
||||
<style>
|
||||
.table thead th{
|
||||
white-space: normal;
|
||||
}
|
||||
</style>
|
||||
<div class="inventory-item-index">
|
||||
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
|
||||
<?= DetailView::widget([
|
||||
'model' => $model,
|
||||
'attributes' => [
|
||||
'id_inventory',
|
||||
'name',
|
||||
['attribute'=>'id_user',
|
||||
'value'=>$model->userName
|
||||
],
|
||||
['attribute'=>'id_account',
|
||||
'value'=>$model->accountName
|
||||
],
|
||||
'created_at:datetime',
|
||||
],
|
||||
]) ?>
|
||||
|
||||
<?php echo $this->render('_search', ['model' => $searchModel]); ?>
|
||||
|
||||
|
||||
|
||||
<p>
|
||||
Magyarázat:
|
||||
<ul>
|
||||
<li>
|
||||
Előző leltár (db): az előző leltárban összeszámolt mennyiség. Ha ez a termék első leltározása akkor 0.
|
||||
</li>
|
||||
<li>
|
||||
Beszerzett mennyiség: Az előző leltár óta történt beszerzett mennyiségek összege
|
||||
</li>
|
||||
<li>
|
||||
Eladott mennyiség: Az előző leltár óta eladott darabszám összege
|
||||
</li>
|
||||
<li>
|
||||
Leltározott mennyiség: A felhasználó által összeszámolt és leltár létrehozásakor beírt mennyiség
|
||||
</li>
|
||||
<li>
|
||||
Rendszer szerinti mennyiség: a rendszer által számolt és aktuális látott mennyiség
|
||||
</li>
|
||||
<li>
|
||||
Különbség: = "Leltározott mennyiség - ( "Előző leltár" + "Beszerzett mennyiség" - "Eladott mennyiség" )
|
||||
</li>
|
||||
</ul>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<?php echo Html::a("XLS letöltése", Url::current(['InventoryItemSearch[output]' =>'xls']),['class' =>'btn btn-primary'])?>
|
||||
</p>
|
||||
|
||||
<?php
|
||||
echo GridView::widget( [
|
||||
'dataProvider' => $dataProvider,
|
||||
'columns' =>[
|
||||
[
|
||||
'attribute' => 'item_name',
|
||||
'label' => 'Név',
|
||||
|
||||
],
|
||||
[
|
||||
'attribute' => 'item_count_system',
|
||||
'label' => 'Rendszer szerinti mennyiség (db)',
|
||||
|
||||
],
|
||||
|
||||
|
||||
[
|
||||
'attribute' => 'item_count',
|
||||
'label' => 'Leltározott mennyiség (db)',
|
||||
|
||||
],
|
||||
[
|
||||
'attribute' => 'item_count_prev',
|
||||
'label' => 'Előzö leltár (db)'
|
||||
|
||||
],
|
||||
[
|
||||
'attribute' => 'item_count_in',
|
||||
'label' => 'Beszerzett mennyiség (db)'
|
||||
|
||||
],
|
||||
[
|
||||
'attribute' => 'item_count_sold',
|
||||
'label' => 'Eladott mennyiség (db)',
|
||||
|
||||
],
|
||||
|
||||
|
||||
[
|
||||
'attribute' => 'item_difference',
|
||||
'label' => 'Különbség (db)',
|
||||
|
||||
],
|
||||
['class' => 'yii\grid\ActionColumn',
|
||||
'template' => '{update}',
|
||||
'urlCreator' => function ($action, $model, $key, $index){
|
||||
return Url::to(['inventory-item/update', 'id' => $model['item_id_inventory_item' ] ]) ;
|
||||
},
|
||||
'buttons' =>[
|
||||
'update' =>function ($url, $model, $key) {
|
||||
return Html::a('Módosítás', $url,['class' => 'btn btn-xs btn-success',
|
||||
'data' => [
|
||||
],
|
||||
]) ;
|
||||
}
|
||||
]
|
||||
|
||||
]
|
||||
]
|
||||
|
||||
]);
|
||||
?>
|
||||
|
||||
</div>
|
||||
81
frontend/views/inventory-item/update.php
Normal file
81
frontend/views/inventory-item/update.php
Normal file
@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\DetailView;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model common\models\InventoryItem */
|
||||
|
||||
$this->title = Yii::t('common/inventory-item', 'Leltár termék');
|
||||
$this->params['breadcrumbs'][] = ['label' => 'Leltár lista', 'url' => ['inventory/index']];
|
||||
$this->params['breadcrumbs'][] = ['label' => 'Leltár', 'url' => ['inventory-item/index', 'id' => $model->id_inventory ]];
|
||||
$this->params['breadcrumbs'][] = Yii::t('common/inventory-item', 'Update');
|
||||
?>
|
||||
<div class="inventory-item-update">
|
||||
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
|
||||
<h2>Leltár</h2>
|
||||
<?= DetailView::widget([
|
||||
'model' => $inventory,
|
||||
'attributes' => [
|
||||
'id_inventory',
|
||||
'name',
|
||||
['attribute'=>'id_user',
|
||||
'value'=>$inventory->userName
|
||||
],
|
||||
['attribute'=>'id_account',
|
||||
'value'=>$inventory->accountName
|
||||
],
|
||||
'created_at:datetime',
|
||||
],
|
||||
]) ?>
|
||||
|
||||
<h2>Termék</h2>
|
||||
<?= DetailView::widget([
|
||||
'model' => $model,
|
||||
'attributes' => [
|
||||
[
|
||||
|
||||
'value' => $model->name,
|
||||
'label' =>"Név"
|
||||
],
|
||||
[
|
||||
'value' => $model->count_system,
|
||||
'label' => 'Rendszer szerinti mennyiség (db)',
|
||||
],
|
||||
[
|
||||
'value' => $model->count,
|
||||
'label' => 'Leltározott mennyiség (db)',
|
||||
],
|
||||
[
|
||||
'value' => $model->count_prev,
|
||||
'label' => 'Előző leltár (db)',
|
||||
],
|
||||
[
|
||||
'value' => $model->count_in,
|
||||
'label' => 'Beszerzett mennyiség (db)',
|
||||
],
|
||||
[
|
||||
'value' => $model->count_sold,
|
||||
'label' => 'Eladott mennyiség (db)',
|
||||
],
|
||||
[
|
||||
'value' => $model->getDifference(),
|
||||
'label' => 'Különbség',
|
||||
],
|
||||
[
|
||||
'value' => '',
|
||||
'label' => '',
|
||||
],
|
||||
|
||||
|
||||
|
||||
],
|
||||
]) ?>
|
||||
|
||||
<?= $this->render('_form', [
|
||||
'model' => $model,
|
||||
]) ?>
|
||||
|
||||
</div>
|
||||
45
frontend/views/inventory-item/view.php
Normal file
45
frontend/views/inventory-item/view.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\DetailView;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model common\models\InventoryItem */
|
||||
|
||||
$this->title = $model->id_inventory_item;
|
||||
$this->params['breadcrumbs'][] = ['label' => Yii::t('common/inventory-item', 'Inventory Items'), 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
?>
|
||||
<div class="inventory-item-view">
|
||||
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
|
||||
<p>
|
||||
<?= Html::a(Yii::t('common/inventory-item', 'Update'), ['update', 'id' => $model->id_inventory_item], ['class' => 'btn btn-primary']) ?>
|
||||
<?= Html::a(Yii::t('common/inventory-item', 'Delete'), ['delete', 'id' => $model->id_inventory_item], [
|
||||
'class' => 'btn btn-danger',
|
||||
'data' => [
|
||||
'confirm' => Yii::t('common/inventory-item', 'Are you sure you want to delete this item?'),
|
||||
'method' => 'post',
|
||||
],
|
||||
]) ?>
|
||||
</p>
|
||||
|
||||
<?= DetailView::widget([
|
||||
'model' => $model,
|
||||
'attributes' => [
|
||||
'id_inventory_item',
|
||||
'id_inventory',
|
||||
'count_in',
|
||||
'count_sold',
|
||||
'count',
|
||||
'type',
|
||||
'id_product',
|
||||
'id_inventory_group',
|
||||
'id_user',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
],
|
||||
]) ?>
|
||||
|
||||
</div>
|
||||
32
frontend/views/inventory/_form.php
Normal file
32
frontend/views/inventory/_form.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\ActiveForm;
|
||||
use common\models\Account;
|
||||
use common\components\Helper;
|
||||
use frontend\components\HtmlHelper;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model common\models\Inventory */
|
||||
/* @var $form yii\widgets\ActiveForm */
|
||||
?>
|
||||
|
||||
<?php
|
||||
|
||||
$accounts = ['' =>'Mind'] + HtmlHelper::mkAccountOptions( Account::readAccounts() );
|
||||
?>
|
||||
|
||||
<div class="inventory-form">
|
||||
|
||||
<?php $form = ActiveForm::begin(); ?>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<?php echo $form->field($model, "id_account")->dropDownList($accounts)?>
|
||||
<?php echo $form->field($model, "name")->textInput()?>
|
||||
<?= Html::submitButton($model->isNewRecord ? Yii::t('common/inventory', 'Létrehoz') : Yii::t('common/inventory', 'Módosít'), [ 'name'=>'Inventory[submit]' ,'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
|
||||
</div>
|
||||
|
||||
<?php ActiveForm::end(); ?>
|
||||
|
||||
</div>
|
||||
33
frontend/views/inventory/_search.php
Normal file
33
frontend/views/inventory/_search.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\ActiveForm;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model backend\models\InventorySearch */
|
||||
/* @var $form yii\widgets\ActiveForm */
|
||||
?>
|
||||
|
||||
<div class="inventory-search">
|
||||
|
||||
<?php $form = ActiveForm::begin([
|
||||
'action' => ['index'],
|
||||
'method' => 'get',
|
||||
]); ?>
|
||||
|
||||
<?= $form->field($model, 'id_inventory') ?>
|
||||
|
||||
<?= $form->field($model, 'id_user') ?>
|
||||
|
||||
<?= $form->field($model, 'created_at') ?>
|
||||
|
||||
<?= $form->field($model, 'updated_at') ?>
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton(Yii::t('common/inventory', 'Search'), ['class' => 'btn btn-primary']) ?>
|
||||
<?= Html::resetButton(Yii::t('common/inventory', 'Reset'), ['class' => 'btn btn-default']) ?>
|
||||
</div>
|
||||
|
||||
<?php ActiveForm::end(); ?>
|
||||
|
||||
</div>
|
||||
21
frontend/views/inventory/create.php
Normal file
21
frontend/views/inventory/create.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model common\models\Inventory */
|
||||
|
||||
$this->title = Yii::t('common/inventory', 'Új leltár');
|
||||
$this->params['breadcrumbs'][] = ['label' => Yii::t('common/inventory', 'Leltár lista'), 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
?>
|
||||
<div class="inventory-create">
|
||||
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
|
||||
<?= $this->render('_form', [
|
||||
'model' => $model,
|
||||
]) ?>
|
||||
|
||||
</div>
|
||||
50
frontend/views/inventory/index.php
Normal file
50
frontend/views/inventory/index.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
use yii\grid\GridView;
|
||||
use yii\helpers\Url;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $searchModel backend\models\InventorySearch */
|
||||
/* @var $dataProvider yii\data\ActiveDataProvider */
|
||||
|
||||
$this->title = Yii::t('common/inventory', 'Leltár lista');
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
?>
|
||||
<div class="inventory-index">
|
||||
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
|
||||
|
||||
<p>
|
||||
<?= Html::a(Yii::t('common/inventory', 'Új leltár'), ['create'], ['class' => 'btn btn-success']) ?>
|
||||
</p>
|
||||
|
||||
<?= GridView::widget([
|
||||
'dataProvider' => $dataProvider,
|
||||
'columns' => [
|
||||
|
||||
'id_inventory',
|
||||
'name',
|
||||
[ 'attribute' => 'id_user', "value" =>"userName" ],
|
||||
'created_at:datetime',
|
||||
|
||||
['class' => 'yii\grid\ActionColumn',
|
||||
'template' => '{view}',
|
||||
'urlCreator' => function( $action, $model, $key, $index ){
|
||||
if ( $action == 'view' ){
|
||||
return Url::to(['inventory-item/index' , 'id'=> $model->id_inventory]);
|
||||
}
|
||||
},
|
||||
'buttons' =>[
|
||||
'view' =>function ($url, $model, $key) {
|
||||
return Html::a('Részletek', $url,['class' => 'btn btn-xs btn-primary',
|
||||
]) ;
|
||||
}
|
||||
]
|
||||
|
||||
],
|
||||
],
|
||||
]); ?>
|
||||
|
||||
</div>
|
||||
23
frontend/views/inventory/update.php
Normal file
23
frontend/views/inventory/update.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model common\models\Inventory */
|
||||
|
||||
$this->title = Yii::t('common/inventory', 'Update {modelClass}: ', [
|
||||
'modelClass' => 'Inventory',
|
||||
]) . ' ' . $model->id_inventory;
|
||||
$this->params['breadcrumbs'][] = ['label' => Yii::t('common/inventory', 'Inventories'), 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = ['label' => $model->id_inventory, 'url' => ['view', 'id' => $model->id_inventory]];
|
||||
$this->params['breadcrumbs'][] = Yii::t('common/inventory', 'Update');
|
||||
?>
|
||||
<div class="inventory-update">
|
||||
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
|
||||
<?= $this->render('_form', [
|
||||
'model' => $model,
|
||||
]) ?>
|
||||
|
||||
</div>
|
||||
89
frontend/views/inventory/view.php
Normal file
89
frontend/views/inventory/view.php
Normal file
@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\DetailView;
|
||||
use yii\grid\GridView;
|
||||
use yii\base\Widget;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model common\models\Inventory */
|
||||
|
||||
$this->title = $model->id_inventory;
|
||||
$this->params['breadcrumbs'][] = ['label' => Yii::t('common/inventory', 'Leltár lista'), 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = "Leltár";
|
||||
?>
|
||||
<div class="inventory-view">
|
||||
|
||||
<h1><?= Html::encode("Leltár") ?></h1>
|
||||
|
||||
|
||||
<?= DetailView::widget([
|
||||
'model' => $model,
|
||||
'attributes' => [
|
||||
'id_inventory',
|
||||
'name',
|
||||
['attribute'=>'id_user',
|
||||
'value'=>$model->userName
|
||||
],
|
||||
'created_at:datetime',
|
||||
],
|
||||
]) ?>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<p>
|
||||
<?= Html::a(Yii::t('common/inventory', 'Új termék'), ['inventory-item/create','id' =>$model->id_inventory], ['class' => 'btn btn-success']) ?>
|
||||
</p>
|
||||
|
||||
<?php
|
||||
|
||||
echo GridView::widget( [
|
||||
'dataProvider' => $dataProvider,
|
||||
'columns' =>[
|
||||
[
|
||||
'attribute' => 'item_created_at',
|
||||
'label' => 'Létrehozva',
|
||||
'format' => 'datetime'
|
||||
],
|
||||
[
|
||||
'attribute' => 'item_name',
|
||||
'label' => 'Név',
|
||||
|
||||
],
|
||||
[
|
||||
'attribute' => 'user_username',
|
||||
'label' => 'Felhasználó',
|
||||
|
||||
],
|
||||
[
|
||||
'attribute' => 'item_count_prev',
|
||||
'label' => 'Előzö leltár (db)'
|
||||
|
||||
],
|
||||
[
|
||||
'attribute' => 'item_count_in',
|
||||
'label' => 'Beszerzett mennyiség (db)'
|
||||
|
||||
],
|
||||
[
|
||||
'attribute' => 'item_count_sold',
|
||||
'label' => 'Eladott mennyiség (db)',
|
||||
|
||||
],
|
||||
[
|
||||
'attribute' => 'item_count',
|
||||
'label' => 'Leltározott mennyiség (db)',
|
||||
|
||||
],
|
||||
[
|
||||
'attribute' => 'item_difference',
|
||||
'label' => 'Különbség (db)',
|
||||
|
||||
],
|
||||
]
|
||||
|
||||
]);
|
||||
?>
|
||||
|
||||
58
frontend/web/js/inventory.item.index.js
Normal file
58
frontend/web/js/inventory.item.index.js
Normal file
@ -0,0 +1,58 @@
|
||||
|
||||
|
||||
var inventoryItemIndex = {
|
||||
|
||||
defaults : {
|
||||
products: [],
|
||||
selector_type : '#inventoryitemsearch-item_type',
|
||||
selector_name : '#inventoryitemsearch-item_name',
|
||||
selector_id : '#inventoryitemsearch-item_id',
|
||||
},
|
||||
product: null,
|
||||
init: function(o){
|
||||
this.defaults = $.extend( this.defaults, o );
|
||||
this.initAutocomplete();
|
||||
|
||||
},
|
||||
|
||||
initAutocomplete : function (){
|
||||
var self = this;
|
||||
|
||||
var $input = $(self.defaults.selector_name);
|
||||
$input.typeahead({source : self.defaults.products,
|
||||
autoSelect: true,
|
||||
items: 20,
|
||||
minLength: 3,
|
||||
});
|
||||
$input.change(function() {
|
||||
var current = $input.typeahead("getActive");
|
||||
$("#filter_text").val('');
|
||||
if (current) {
|
||||
// Some item from your model is active!
|
||||
if (current.name == $input.val()) {
|
||||
self.product = current;
|
||||
} else {
|
||||
self.product = null;
|
||||
}
|
||||
} else {
|
||||
self.product = null;
|
||||
}
|
||||
self.productChange();
|
||||
});
|
||||
},
|
||||
productChange: function( ){
|
||||
this.clearProductData();
|
||||
this.setProductData();
|
||||
},
|
||||
clearProductData: function(){
|
||||
$(this.defaults.selector_type).val('');
|
||||
$(this.defaults.selector_id).val('');
|
||||
},
|
||||
setProductData: function(){
|
||||
if ( this.product ){
|
||||
$(this.defaults.selector_type).val( this.product.type);
|
||||
$(this.defaults.selector_id ).val( this.product.id);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user