add inventory

This commit is contained in:
2016-02-03 22:50:17 +01:00
parent 41de4ee6a7
commit b871022329
8 changed files with 358 additions and 1 deletions

View File

@@ -88,6 +88,7 @@ class FrontendMenuStructure{
}
$items[] = ['label' => Yii::t('frontend/card','Vendégek'), 'url' => [ '/card/index' ] ];
$items[] = ['label' => Yii::t('frontend/card','Leltár'), 'url' => [ '/product/inventory' ] ];
$this->menuItems[] = ['label' => Yii::t('frontend/account', 'Account'),

View File

@@ -26,6 +26,8 @@ use frontend\models\CustomerCartPayoutForm;
use frontend\models\UserCartPayoutForm;
use frontend\components\DefaultAccountBehavior;
use frontend\components\CassaOpenBehavior;
use common\components\ProductInventory;
use frontend\models\ProductInventorySearch;
/**
* ProductController implements the CRUD actions for Product model.
@@ -278,6 +280,97 @@ class ProductController extends Controller {
return $result;
}
public function actionInventory( ) {
$searchModel = new ProductInventorySearch(
['account' => Account::readDefaultObject()]
);
// $searchModel->search(\Yii::$app->request->params);
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
// $inventory = new ProductInventory([
// ]);
// if ( $output == 'xls'){
// $inventory->pagination = false;
// }
// $inventory->createDataProvider();
// $dp = $inventory->dataProvider;
if ( $searchModel->output == 'xls' ){
$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;
$sheet
->setCellValue('A'.$row, "Termék azonosító")
->setCellValue('B'.$row, "Termék név")
->setCellValue('C'.$row, "Termék szám")
->setCellValue('D'.$row, "Termék vonalkód")
->setCellValue('E'.$row, "Termék raktáron");
// ->setCellValue('F'.$row, "Eladott mennyiség");
foreach ($models as $model ){
$row++;
$sheet->setCellValue('A'.$row, $model['product_id'])
->setCellValue('B'.$row, $model['product_name'])
->setCellValue('C'.$row, $model['product_number'])
->setCellValue('D'.$row, $model['product_barcode'])
->setCellValue('E'.$row, $model['product_stock']);
// ->setCellValue('F'.$row, $model['product_sold']);
}
$styleArray = array(
'font' => array(
'bold' => true,
// 'color' => array('rgb' => 'FF0000'),
// 'size' => 15,
// 'name' => 'Verdana'
));
foreach(range('A','E') as $columnID)
{
$sheet->getColumnDimension($columnID)->setAutoSize(true);
$sheet->getStyle($columnID.'1')->applyFromArray($styleArray);
}
// Redirect output to a clients 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;
}
return $this->render('inventory',[ 'searchModel' =>$searchModel, 'dataProvider' => $dataProvider]);
}
/**
* Finds the Product model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
@@ -305,6 +398,8 @@ class ProductController extends Controller {
}
}
}
/**
* Lists all Product models.

View File

@@ -0,0 +1,64 @@
<?php
namespace frontend\models;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\Product;
use common\components\ProductInventory;
/**
* ProductSearch represents the model behind the search form about `common\models\Product`.
*/
class ProductInventorySearch extends Product
{
public $output = '';
public $account = null;
/**
* @inheritdoc
*/
public function rules()
{
return [
[[ 'output'], '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)
{
$this->load($params);
$this->validate() ;
$inventory = new ProductInventory([
'account' => $this->account
]);
if ( $this->output == 'xls'){
$inventory->pagination = false;
}
$inventory->createDataProvider();
$dp = $inventory->dataProvider;
return $dp;
}
}

View File

@@ -0,0 +1,64 @@
<?php
use yii\helpers\Html;
use yii\grid\GridView;
use yii\helpers\Url;
/* @var $this yii\web\View */
/* @var $searchModel frontend\models\ProductSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = "Termék leltár";
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="product-index">
<h1><?= Html::encode($this->title) ?></h1>
<?php // echo $this->render('_search_inventory', ['model' => $searchModel]); ?>
<?php
echo Html::a('XLS letöltése',Url::current(['ProductInventorySearch[output]' => 'xls']),['class' => 'btn btn-primary'] );
?>
<p>
<b>Kassza:</b> <?php echo $searchModel->account->name; ?>
</p>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
[
'attribute' => 'product_id',
'label' => 'Termék azonosító'
],
[
'attribute' => 'product_name',
'label' => 'Termék neve'
],
[
'attribute' => 'account_name',
'label' => 'Kassza'
],
[
'attribute' => 'product_number',
'label' => 'Termék szám'
],
[
'attribute' => 'product_barcode',
'label' => 'Termék vonalkód'
],
[
'attribute' => 'product_stock',
'label' => 'Termék raktáron'
],
// [
// 'attribute' => 'product_sold',
// 'label' => 'Termék eladva'
// ],
],
]); ?>
</div>