add inventory changes

This commit is contained in:
2016-03-23 08:15:37 +01:00
parent 7db129de92
commit e7b16f20ce
15 changed files with 413 additions and 62 deletions

View File

@@ -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.
@@ -42,14 +44,95 @@ 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 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 ();
}
/**
* 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,
]);
}
}