Finish version/v.0.0.32

This commit is contained in:
Roland Schneider 2016-02-03 22:51:39 +01:00
commit 212db2a6d7
8 changed files with 358 additions and 1 deletions

View File

@ -1,3 +1,5 @@
-0.0.32
- Add product inventory to reception
-0.0.31 -0.0.31
- Add transfer list and daily list to see only may 3 days old data - Add transfer list and daily list to see only may 3 days old data
-0.0.30 -0.0.30

View File

@ -220,4 +220,22 @@ class Helper {
$details = json_decode ( Helper::url_get_contents( "http://ipinfo.io/{$ip}/json" ) ); $details = json_decode ( Helper::url_get_contents( "http://ipinfo.io/{$ip}/json" ) );
return $details; return $details;
} }
public static function mkYiiSortItem($field, $column){
return [
$field => [
'asc' => [$column => SORT_ASC ],
'desc' => [$column => SORT_DESC],
]
];
}
public static function mkYiiSortItems($config){
$result = [];
foreach ($config as $col ){
$result = $result + Helper::mkYiiSortItem($col[0] ,$col[1]);
}
return $result;
}
} }

View File

@ -0,0 +1,113 @@
<?php
namespace common\components;
use yii\base\Object;
use yii\db\Query;
use common\models\Product;
use yii\data\ActiveDataProvider;
use common\models\Transfer;
/**
*
* @property common\models\Account $account a kassza
* @property common\models\Product[] $products a termékek
* */
class ProductInventory extends Object{
/**melyik kassza, csak akkor használjuk , ha a params['product_visiblity'] == 'account'*/
public $account;
/**read products query*/
protected $query;
/**
* a termék lista
* */
public $products;
public $dataProvider;
public $pagination ;
public function createDataProvider(){
$this->buildQuery();
$this->mkDataProvider();
}
public function createProductList(){
$this->buildQuery();
$this->readProducts();
}
protected function buildQuery(){
$this->query = Product::find();
$this->query = new Query();
$this->query->select([ 'account.id_account as account_id_account','account.name as account_name', 'product.barcode as product_barcode', 'product.product_number as product_number', 'product.id_product as product_id','product.name as product_name','product.stock as product_stock','coalesce( sum(transfer.count),0 ) as product_sold']);
$this->query->from('product');
$this->query->leftJoin('transfer', 'product.id_product = transfer.id_object and transfer.type = 10');
$this->query->innerJoin('account', 'product.id_account = account.id_account');
$this->query->groupBy(['product.id_product','product.name','product.stock','product.barcode', 'product.product_number','account.id_account','account.name' ]);
$this->query->andWhere(['in','transfer.status', [Transfer::STATUS_PAID, Transfer::STATUS_NOT_PAID]]);
if ( Helper::isProductVisibilityAccount() && isset($this->account)){
$this->query->andWhere(['product.id_account' => $this->account->id_account]);
}
// $this->query->orderBy('product.name');
}
protected function getSortAttributes(){
return Helper::mkYiiSortItems([
['product_id','product.id_product'],
['product_number','product.product_number'],
['product_barcode','product.barcode'],
['product_name','product.name'],
['product_sold','sum(transfer.count)'],
['product_stock','product.stock'],
['account_name','account.name'],
]);
}
protected function readProducts(){
$this->products = $this->query->findAll();
}
protected function mkDataProvider(){
$this->dataProvider = new ActiveDataProvider(
[
'query' => $this->query,
'sort' =>[
'defaultOrder' => ['product_name' => SORT_ASC],
'attributes' => $this->getSortAttributes()
],
]
);
if ( isset($this->pagination) && $this->pagination == false ){
$this->dataProvider->pagination = false;
}
// echo print_r( $this->dataProvider->sort );
}
}
?>

View File

@ -4,7 +4,7 @@ return [
'supportEmail' => 'rocho02@gmail.com', 'supportEmail' => 'rocho02@gmail.com',
'infoEmail' => 'info@rocho-net.hu', 'infoEmail' => 'info@rocho-net.hu',
'user.passwordResetTokenExpire' => 3600, 'user.passwordResetTokenExpire' => 3600,
'version' => 'v0.0.31', 'version' => 'v0.0.32',
'company' => 'movar',//gyor 'company' => 'movar',//gyor
'company_name' => "Freimann Kft.", 'company_name' => "Freimann Kft.",
'product_visiblity' => 'account',// on reception which products to display. account or global 'product_visiblity' => 'account',// on reception which products to display. account or global

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','Vendégek'), 'url' => [ '/card/index' ] ];
$items[] = ['label' => Yii::t('frontend/card','Leltár'), 'url' => [ '/product/inventory' ] ];
$this->menuItems[] = ['label' => Yii::t('frontend/account', 'Account'), $this->menuItems[] = ['label' => Yii::t('frontend/account', 'Account'),

View File

@ -26,6 +26,8 @@ use frontend\models\CustomerCartPayoutForm;
use frontend\models\UserCartPayoutForm; use frontend\models\UserCartPayoutForm;
use frontend\components\DefaultAccountBehavior; use frontend\components\DefaultAccountBehavior;
use frontend\components\CassaOpenBehavior; use frontend\components\CassaOpenBehavior;
use common\components\ProductInventory;
use frontend\models\ProductInventorySearch;
/** /**
* ProductController implements the CRUD actions for Product model. * ProductController implements the CRUD actions for Product model.
@ -278,6 +280,97 @@ class ProductController extends Controller {
return $result; 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. * Finds the Product model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown. * If the model is not found, a 404 HTTP exception will be thrown.
@ -306,6 +399,8 @@ class ProductController extends Controller {
} }
} }
/** /**
* Lists all Product models. * 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>