diff --git a/changelog.txt b/changelog.txt index c86a532..b0debd8 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,5 @@ +-0.0.32 + - Add product inventory to reception -0.0.31 - Add transfer list and daily list to see only may 3 days old data -0.0.30 diff --git a/common/components/Helper.php b/common/components/Helper.php index 0ce872e..331f5d7 100644 --- a/common/components/Helper.php +++ b/common/components/Helper.php @@ -220,4 +220,22 @@ class Helper { $details = json_decode ( Helper::url_get_contents( "http://ipinfo.io/{$ip}/json" ) ); 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; + } + } \ No newline at end of file diff --git a/common/components/ProductInventory.php b/common/components/ProductInventory.php new file mode 100644 index 0000000..cca7506 --- /dev/null +++ b/common/components/ProductInventory.php @@ -0,0 +1,113 @@ +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 ); + } + + +} + +?> \ No newline at end of file diff --git a/common/config/params.php b/common/config/params.php index 99a2507..be06504 100644 --- a/common/config/params.php +++ b/common/config/params.php @@ -4,7 +4,7 @@ return [ 'supportEmail' => 'rocho02@gmail.com', 'infoEmail' => 'info@rocho-net.hu', 'user.passwordResetTokenExpire' => 3600, - 'version' => 'v0.0.31', + 'version' => 'v0.0.32', 'company' => 'movar',//gyor 'company_name' => "Freimann Kft.", 'product_visiblity' => 'account',// on reception which products to display. account or global diff --git a/frontend/components/FrontendMenuStructure.php b/frontend/components/FrontendMenuStructure.php index fbc439c..779a9c7 100644 --- a/frontend/components/FrontendMenuStructure.php +++ b/frontend/components/FrontendMenuStructure.php @@ -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'), diff --git a/frontend/controllers/ProductController.php b/frontend/controllers/ProductController.php index d451747..0aab87c 100644 --- a/frontend/controllers/ProductController.php +++ b/frontend/controllers/ProductController.php @@ -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 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; + + } + + + + 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. diff --git a/frontend/models/ProductInventorySearch.php b/frontend/models/ProductInventorySearch.php new file mode 100644 index 0000000..2b01934 --- /dev/null +++ b/frontend/models/ProductInventorySearch.php @@ -0,0 +1,64 @@ +load($params); + + $this->validate() ; + + $inventory = new ProductInventory([ + 'account' => $this->account + ]); + if ( $this->output == 'xls'){ + $inventory->pagination = false; + } + + $inventory->createDataProvider(); + $dp = $inventory->dataProvider; + + return $dp; + } +} diff --git a/frontend/views/product/inventory.php b/frontend/views/product/inventory.php new file mode 100644 index 0000000..8e10d55 --- /dev/null +++ b/frontend/views/product/inventory.php @@ -0,0 +1,64 @@ +title = "Termék leltár"; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ Kassza: account->name; ?> +
+ + = 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' +// ], + + + ], + ]); ?> + +