diff --git a/backend/controllers/InventoryController.php b/backend/controllers/InventoryController.php index 308384f..4b9712e 100644 --- a/backend/controllers/InventoryController.php +++ b/backend/controllers/InventoryController.php @@ -11,6 +11,8 @@ use yii\filters\VerbFilter; use common\models\User; use yii\db\Query; use backend\models\InventoryItemSearch; +use common\models\InventoryItem; +use common\components\Helper; /** * InventoryController implements the CRUD actions for Inventory model. @@ -23,7 +25,7 @@ class InventoryController extends Controller 'verbs' => [ 'class' => VerbFilter::className(), 'actions' => [ - 'delete' => ['post'], + 'close' => ['post'], ], ], ]; @@ -55,12 +57,13 @@ class InventoryController extends Controller $model = new Inventory(); $user = User::findOne(\Yii::$app->user->id); - + $model->status = Inventory::$STATUS_OPEN; + $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(['view', 'id' => $model->id_inventory]); + return $this->redirect(['inventory-item/index', 'id' => $model->id_inventory]); } else { } return $this->render('create', [ @@ -69,6 +72,22 @@ class InventoryController extends Controller } + public function actionClose($id){ + $model = $this->findModel($id); + + $model->status = Inventory::$STATUS_CLOSED; + + $model->save(false); + + $db = \Yii::$app->db; + $command = $db->createCommand(InventoryItem::$UPDATE_COUNT,[':id_inventory' => $id]); + $command->execute(); + + Helper::flash("success", "Leltár lezárva, leltározott termékek darabszáma felülírva!"); + + return $this->redirect(['inventory-item/index','id' => $model->id_inventory]); + } + /** * Finds the Inventory model based on its primary key value. diff --git a/backend/controllers/InventoryItemController.php b/backend/controllers/InventoryItemController.php index 1091b42..166c642 100644 --- a/backend/controllers/InventoryItemController.php +++ b/backend/controllers/InventoryItemController.php @@ -12,6 +12,7 @@ use backend\models\InventoryItemForm; use common\models\Inventory; use yii\helpers\Url; use common\models\Product; +use yii\web\NotAcceptableHttpException; /** * InventoryItemController implements the CRUD actions for InventoryItem model. @@ -177,7 +178,11 @@ class InventoryItemController extends Controller { $model = $this->findModel($id); $inventory = Inventory::findOne($model->id_inventory); - + + if ( !$inventory->isOpen()){ + throw new NotAcceptableHttpException("A leltár elem nem található"); + } + if ($model->load(Yii::$app->request->post()) && $model->save()) { $prev = Url::previous("inventory-item-index"); diff --git a/backend/controllers/ProcurementController.php b/backend/controllers/ProcurementController.php index c6e07c2..62c4cb4 100644 --- a/backend/controllers/ProcurementController.php +++ b/backend/controllers/ProcurementController.php @@ -14,6 +14,7 @@ use common\models\User; use common\components\Helper; use common\models\Account; use yii\helpers\Url; +use backend\models\ProcurementUpdate; /** * ProcurementController implements the CRUD actions for Procurement model. @@ -30,7 +31,7 @@ class ProcurementController extends \backend\controllers\BackendController 'rules' => [ // allow authenticated users [ - 'actions' => ['create','index','view', 'create-product'], + 'actions' => ['create','index','view', 'create-product','update'], 'allow' => true, 'roles' => ['@'], ], @@ -79,11 +80,34 @@ class ProcurementController extends \backend\controllers\BackendController */ public function actionView($id) { + + return $this->render('view', [ 'model' => $this->findModel($id), ]); } + /** + * Update procurement + * @param integer $id + * @return mixed + */ + public function actionUpdate($id) + { + $model = ProcurementUpdate::findOne($id); + if ( !isset($model)){ + throw new NotFoundHttpException("Az oldal nem található"); + } + + if ($model->load(Yii::$app->request->post()) && $model->validate()) { + $model->save(); + } + + return $this->render('update', [ + 'model' => $model + ]); + } + /** * Creates a new Procurement model. * If creation is successful, the browser will be redirected to the 'view' page. diff --git a/backend/controllers/TransferController.php b/backend/controllers/TransferController.php index 1ae6b34..0c7145f 100644 --- a/backend/controllers/TransferController.php +++ b/backend/controllers/TransferController.php @@ -62,9 +62,14 @@ class TransferController extends \backend\controllers\BackendController $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + echo "output:".$searchModel->output; + + if ( $searchModel->output =='pdf'){ + $this->downloadPaymentLater($dataProvider); + } + $accounts = Account::read(); - - $users = User::read(); Url::remember("payment_later",Url::current()); @@ -76,6 +81,30 @@ class TransferController extends \backend\controllers\BackendController 'users' => $users, ]); } + + protected function downloadPaymentLater($dataProvider) { + + // $mpdf = new \mPDF ( 'utf-8', 'A4' ); + $mpdf = new \mPDF ( 'utf-8', 'A4-L' ); + $fn = "utolagos_fizetesek.pdf"; + + $mpdf->useSubstitutions = false; + $mpdf->simpleTables = true; + $mpdf->SetHeader ( "" ); + $mpdf->setFooter ( '{PAGENO} / {nb}' ); + + + + $stylesheet = file_get_contents ( \Yii::getAlias ( '@vendor' . '/bower/bootstrap/dist/css/bootstrap.css' ) ); // external css + $mpdf->WriteHTML ( $stylesheet, 1 ); + + $mpdf->WriteHTML ( $this->renderPartial ( '_pdf_payment_later.php', [ + 'dataProvider' => $dataProvider + ] ) ); + $mpdf->Output ( $fn, 'D' ); + exit (); + + } /** * Lists all Transfer models. diff --git a/backend/controllers/UgiroController.php b/backend/controllers/UgiroController.php index ce034ee..63869bd 100644 --- a/backend/controllers/UgiroController.php +++ b/backend/controllers/UgiroController.php @@ -11,200 +11,254 @@ use yii\filters\VerbFilter; use common\components\DetStatProcessor; use backend\models\DestaUploadForm; use yii\web\UploadedFile; +use yii\data\ArrayDataProvider; +use yii\db\Query; +use yii\data\ActiveDataProvider; /** * UgiroController implements the CRUD actions for Ugiro model. * TODO: FIX ACCESS */ -class UgiroController extends Controller -{ - public function behaviors() - { - return [ - 'verbs' => [ - 'class' => VerbFilter::className(), - 'actions' => [ - 'delete' => ['post'], - ], - ], - 'access' => [ - 'class' => \yii\filters\AccessControl::className (), - 'rules' => [ - // allow authenticated users - [ - 'actions' => [], - 'allow' => true, - 'roles' => [ - 'admin', - 'employee', - 'reception' - ] - ] - ] - // everything else is denied - - ] - ]; - } - - /** - * Lists all Ugiro models. - * @return mixed - */ - public function actionIndex() - { - $searchModel = new UgiroSearch(); - $dataProvider = $searchModel->search(Yii::$app->request->queryParams); - - return $this->render('index', [ - 'searchModel' => $searchModel, - 'dataProvider' => $dataProvider, - ]); - } - /** - * Lists all Ugiro models. - * @return mixed - */ - public function actionItems($id) - { - $searchModel = new UgiroSearch(); - $dataProvider = $searchModel->search(Yii::$app->request->queryParams); - - return $this->render('index', [ - 'searchModel' => $searchModel, - 'dataProvider' => $dataProvider, - ]); - } - - public function actionActivate(){ - - } - - /** - * Displays a single Ugiro model. - * @param integer $id - * @return mixed - */ - public function actionView($id) - { - $model = $this->findModel($id); - if (Yii::$app->request->isPost) { - if ($model->status == Ugiro::$STATUS_RECIEVED){ - set_time_limit(1200);//20 perc - $processor = new DetStatProcessor( - ['koteg' => $model] - ); - $processor->run(); - }else{ - \Yii::$app->session->setFlash('danger','Nem lehet futtatni a fájlt'); - \Yii::error("a koteg státusza nem STATUS_RECIEVED. A koteg azonosíótja:" . $model->id_ugiro ); - } - } - - return $this->render('view', [ - 'model' => $this->findModel($id), - ]); - } - - /** - * Creates a new Ugiro model. - * If creation is successful, the browser will be redirected to the 'view' page. - * @return mixed - */ - public function actionCreate() - { - $model = new Ugiro(); - - if ($model->load(Yii::$app->request->post()) && $model->save()) { - return $this->redirect(['view', 'id' => $model->id_ugiro]); - } else { - return $this->render('create', [ - 'model' => $model, - ]); - } - } - - /** - * Updates an existing Ugiro 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_ugiro]); - } else { - return $this->render('update', [ - 'model' => $model, - ]); - } - } - - /** - * Deletes an existing Ugiro 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']); - } - - public function actionDetsta(){ - - $ugiro = Ugiro::findOne(31); - $model = new DetStatProcessor( - ['koteg' => $ugiro] - ); - - - return $this->render('detsta', [ - 'model' => $model, - ]); - } - - public function actionUpload(){ - $model = new DestaUploadForm(); - - if (Yii::$app->request->isPost) { - $model->destaFile = UploadedFile::getInstance($model, 'destaFile'); - if ($model->upload()) { - // file is uploaded successfully - return $this->redirect(['view', 'id' => $model->koteg->id_ugiro]); - } - } - - return $this->render('upload', ['model' => $model]); - - } - - - public function actionGenerateDetsta(){ - - - - } - - - /** - * Finds the Ugiro model based on its primary key value. - * If the model is not found, a 404 HTTP exception will be thrown. - * @param integer $id - * @return Ugiro the loaded model - * @throws NotFoundHttpException if the model cannot be found - */ - protected function findModel($id) - { - if (($model = Ugiro::findOne($id)) !== null) { - return $model; - } else { - throw new NotFoundHttpException('The requested page does not exist.'); - } - } +class UgiroController extends Controller { + public function behaviors() { + return [ + 'verbs' => [ + 'class' => VerbFilter::className (), + 'actions' => [ + 'delete' => [ + 'post' + ] + ] + ], + 'access' => [ + 'class' => \yii\filters\AccessControl::className (), + 'rules' => [ + // allow authenticated users + [ + 'actions' => [ ], + 'allow' => true, + 'roles' => [ + 'admin', + 'employee', + 'reception' + ] + ] + ] + ] + // everything else is denied + + + ]; + } + + /** + * Lists all Ugiro models. + * + * @return mixed + */ + public function actionIndex() { + $searchModel = new UgiroSearch (); + $dataProvider = $searchModel->search ( Yii::$app->request->queryParams ); + + return $this->render ( 'index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider + ] ); + } + /** + * Lists all Ugiro models. + * + * @return mixed + */ + public function actionItems($id) { + $searchModel = new UgiroSearch (); + $dataProvider = $searchModel->search ( Yii::$app->request->queryParams ); + + return $this->render ( 'index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider + ] ); + } + public function actionActivate() { + } + + /** + * Displays a single Ugiro model. + * + * @param integer $id + * @return mixed + */ + public function actionView($id) { + $model = $this->findModel ( $id ); + if (Yii::$app->request->isPost) { + if ($model->status == Ugiro::$STATUS_RECIEVED) { + set_time_limit ( 1200 ); // 20 perc + $processor = new DetStatProcessor ( [ + 'koteg' => $model + ] ); + $processor->run (); + } else { + \Yii::$app->session->setFlash ( 'danger', 'Nem lehet futtatni a fájlt' ); + \Yii::error ( "a koteg státusza nem STATUS_RECIEVED. A koteg azonosíótja:" . $model->id_ugiro ); + } + } else { + if (isset ( $_GET ['output'] )) { + $output = $_GET ['output']; + + if ($output == 'pdf') { + $this->downloadUgiro ( $model ); + } + } + } + + return $this->render ( 'view', [ + 'model' => $this->findModel ( $id ) + ] ); + } + protected function downloadUgiro($model) { + +// $mpdf = new \mPDF ( 'utf-8', 'A4' ); + $mpdf = new \mPDF ( 'utf-8', 'A4-L' ); + $fn = "köteg.". $model->id_ugiro . ".pdf"; + + $mpdf->useSubstitutions = false; + $mpdf->simpleTables = true; + $mpdf->SetHeader ( "" ); + $mpdf->setFooter ( '{PAGENO} / {nb}' ); + + $query = new Query(); + $query->select([ + 'customer.id_customer as customer_id_customer', + 'customer.name as customer_name', + 'customer.bank_account as customer_bank_account', + 'ticket_installment_request.money as request_money', + 'ticket_installment_request.request_target_time_at as request_request_target_time_at', + ]); + $query->from('ticket_installment_request'); + $query->innerJoin('ugiro_request_assignment','ticket_installment_request.id_ticket_installment_request = ugiro_request_assignment.id_request'); + $query->innerJoin('customer','customer.id_customer = ticket_installment_request.id_customer'); + $query->andWhere(['ugiro_request_assignment.id_ugiro' => $model->id_ugiro]); + $dataProvider = new ActiveDataProvider( + [ + 'query' => $query, + 'sort' => false, + 'pagination' => false + ] + ); + + $stylesheet = file_get_contents ( \Yii::getAlias ( '@vendor' . '/bower/bootstrap/dist/css/bootstrap.css' ) ); // external css + $mpdf->WriteHTML ( $stylesheet, 1 ); + + $mpdf->WriteHTML ( $this->renderPartial ( '_view_pdf.php', [ + 'model' => $model, + 'dataProvider' => $dataProvider + ] ) ); + $mpdf->Output ( $fn, 'D' ); + exit (); + + } + + /** + * Creates a new Ugiro model. + * If creation is successful, the browser will be redirected to the 'view' page. + * + * @return mixed + */ + public function actionCreate() { + $model = new Ugiro (); + + if ($model->load ( Yii::$app->request->post () ) && $model->save ()) { + return $this->redirect ( [ + 'view', + 'id' => $model->id_ugiro + ] ); + } else { + return $this->render ( 'create', [ + 'model' => $model + ] ); + } + } + + /** + * Updates an existing Ugiro 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_ugiro + ] ); + } else { + return $this->render ( 'update', [ + 'model' => $model + ] ); + } + } + + /** + * Deletes an existing Ugiro 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' + ] ); + } + public function actionDetsta() { + $ugiro = Ugiro::findOne ( 31 ); + $model = new DetStatProcessor ( [ + 'koteg' => $ugiro + ] ); + + return $this->render ( 'detsta', [ + 'model' => $model + ] ); + } + public function actionUpload() { + $model = new DestaUploadForm (); + + if (Yii::$app->request->isPost) { + $model->destaFile = UploadedFile::getInstance ( $model, 'destaFile' ); + if ($model->upload ()) { + // file is uploaded successfully + return $this->redirect ( [ + 'view', + 'id' => $model->koteg->id_ugiro + ] ); + } + } + + return $this->render ( 'upload', [ + 'model' => $model + ] ); + } + public function actionGenerateDetsta() { + } + + /** + * Finds the Ugiro model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * + * @param integer $id + * @return Ugiro the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) { + if (($model = Ugiro::findOne ( $id )) !== null) { + return $model; + } else { + throw new NotFoundHttpException ( 'The requested page does not exist.' ); + } + } } diff --git a/backend/models/InventoryItemForm.php b/backend/models/InventoryItemForm.php index 6e53108..d818c48 100644 --- a/backend/models/InventoryItemForm.php +++ b/backend/models/InventoryItemForm.php @@ -119,9 +119,11 @@ class InventoryItemForm extends Model{ $item->id_user = \Yii::$app->user->id; if ( $this->type == 'product'){ + $item->type = InventoryItem::$TYPE_PRODUCT; $item->id_product = $this->product->id_product; }else{ $item->id_inventory_group = $this->inventoryGroup->id_inventory_group; + $item->type = InventoryItem::$TYPE_INVENTORY_GROUP; } $item->id_inventory = $this->inventory->id_inventory; diff --git a/backend/models/ProcurementUpdate.php b/backend/models/ProcurementUpdate.php new file mode 100644 index 0000000..1199ee2 --- /dev/null +++ b/backend/models/ProcurementUpdate.php @@ -0,0 +1,49 @@ +getOldAttribute('count'); +// VarDumper::dump($changed); +// VarDumper::dump($this->getDirtyAttributes(['count'])); + $this->oldCount = $this->getOldAttribute('count'); + + } + return true; + } + + public function afterSave($insert, $changedAttributes){ + $product = Product::findOne($this->id_product); + + $product->stock = $product->stock - $this->oldCount + $this->count; + + $product->save(false); + + Log::log([ + 'id_product' => $this->product->id_product, + 'type' =>Log::$TYPE_PROCUREMENT_UPDATE, + 'message' => "Beszerzés(#".$this->id_procurement.") módosítva. Beszerzett mennyiség: " . $this->oldCount . " > " .$this->count, + ]); + } + + +} \ No newline at end of file diff --git a/backend/models/TransferLaterSearch.php b/backend/models/TransferLaterSearch.php index 0ae56f2..587fdee 100644 --- a/backend/models/TransferLaterSearch.php +++ b/backend/models/TransferLaterSearch.php @@ -33,12 +33,15 @@ class TransferLaterSearch extends Transfer public $total_money; + public $output; + /** * @inheritdoc */ public function rules() { return [ + [['output' ] ,'safe'], [[ 'id_ticket_type','id_user'], 'integer'], [[ 'start', ], 'date', 'format' =>Yii::$app->formatter->datetimeFormat , 'timestampAttribute' => 'timestampStart' ,'timestampAttributeFormat' => 'yyyy-MM-dd HH:mm' ,'timeZone' => 'UTC' ], [[ 'end' , ], 'date' ,'format' =>Yii::$app->formatter->datetimeFormat , 'timestampAttribute' => 'timestampEnd' ,'timestampAttributeFormat' => 'yyyy-MM-dd HH:mm' ,'timeZone' => 'UTC' ], @@ -72,11 +75,13 @@ class TransferLaterSearch extends Transfer 'transfer.money as transfer_money', 'transfer.status as transfer_status', 'user.username as user_username', + 'customer.id_customer as customer_id_customer', 'customer.name as customer_name', 'ticket_type.name as ticket_type_name', 'product.name as product_name', 'ticket.start as ticket_start', 'ticket.end as ticket_end', + 'ticket.comment as ticket_comment', ]); $query->from("transfer"); $query->innerJoin('user', " user.id = transfer.id_user"); @@ -89,10 +94,15 @@ class TransferLaterSearch extends Transfer $query->andWhere(["transfer.payment_method" => Transfer::PAYMENT_METHOD_TRANSFER_LATER ]); $query->andWhere(['transfer.status' => Transfer::STATUS_NOT_PAID]); - + + $this->load($params); + + $valid = $this->validate(); + $dataProvider = new ActiveDataProvider([ 'query' => $query, - 'sort' =>[ + 'pagination' => $this->output == 'pdf' ? false : [], + 'sort' => [ 'defaultOrder' =>[ 'transfer_created_at' => SORT_DESC ], @@ -106,22 +116,18 @@ class TransferLaterSearch extends Transfer ['product_name'], ['ticket_start'], ['ticket_end'], + ['ticket_comment'], ]) ] ]); -// $query->addSelect( ['*' ]); - - $this->load($params); - - if (!$this->validate()) { + if (!$valid) { // uncomment the following line if you do not want to return any records when validation fails $query->where('0=1'); return $dataProvider; } - $query->andFilterWhere([ diff --git a/backend/views/inventory-item/index.php b/backend/views/inventory-item/index.php index 614f907..71df795 100644 --- a/backend/views/inventory-item/index.php +++ b/backend/views/inventory-item/index.php @@ -33,14 +33,24 @@ $this->registerJs('inventoryItemIndex.init( '. json_encode($options) .' );'); 'name', ['attribute'=>'id_user', 'value'=>$model->userName - ], + ], ['attribute'=>'id_account', 'value'=>$model->accountName ], + ['attribute'=>'status', + 'value'=>$model->getStatusHuman(), + 'label' => "Állapot" + ], 'created_at:datetime', ], ]) ?> + isOpen()){ + echo Html::a("Lezárás",['inventory/close' , 'id' => $model->id_inventory ] ,['data-method' =>'post', 'class' => 'btn btn-danger']); + } + ?> + render('_search', ['model' => $searchModel]); ?> @@ -74,9 +84,8 @@ $this->registerJs('inventoryItemIndex.init( '. json_encode($options) .' );');
$dataProvider, - 'columns' =>[ + + $columns = [ [ 'attribute' => 'item_created_at', 'label' => 'Létrehozva', @@ -96,6 +105,16 @@ $this->registerJs('inventoryItemIndex.init( '. json_encode($options) .' );'); 'attribute' => 'inventory_prev_name', 'label' => 'Utolsó leltár' + ], + [ + 'attribute' => 'item_count_system', + 'label' => 'Rendszer szerinti mennyiség (db)', + + ], + [ + 'attribute' => 'item_count', + 'label' => 'Leltározott mennyiség (db)', + ], [ 'attribute' => 'item_count_prev', @@ -111,24 +130,20 @@ $this->registerJs('inventoryItemIndex.init( '. json_encode($options) .' );'); 'attribute' => 'item_count_sold', 'label' => 'Eladott mennyiség (db)', - ], - [ - 'attribute' => 'item_count', - 'label' => 'Leltározott mennyiség (db)', - - ], - [ - 'attribute' => 'item_count_system', - 'label' => 'Rendszer szerinti mennyiség (db)', - ], [ 'attribute' => 'item_difference', 'label' => 'Különbség (db)', ], - ['class' => 'yii\grid\ActionColumn', - 'template' => '', + + + ]; + + if ( $model->isOpen() ){ + + $columns[] = ['class' => 'yii\grid\ActionColumn', + 'template' => '{update}', 'urlCreator' => function ($action, $model, $key, $index){ return Url::to(['inventory-item/update', 'id' => $model['item_id_inventory_item' ] ]) ; }, @@ -141,8 +156,14 @@ $this->registerJs('inventoryItemIndex.init( '. json_encode($options) .' );'); } ] - ] - ] + ] ; + } + + + + echo GridView::widget( [ + 'dataProvider' => $dataProvider, + 'columns' => $columns ]); ?> diff --git a/backend/views/inventory/index.php b/backend/views/inventory/index.php index 75dfff2..8c508ec 100644 --- a/backend/views/inventory/index.php +++ b/backend/views/inventory/index.php @@ -17,7 +17,7 @@ $this->params['breadcrumbs'][] = $this->title; render('_search', ['model' => $searchModel]); ?>- 'btn btn-success']) ?> + 'btn btn-success']) ?>
= GridView::widget([ @@ -28,6 +28,7 @@ $this->params['breadcrumbs'][] = $this->title; 'name', [ 'attribute' => 'id_user', "value" =>"userName" ], 'created_at:datetime', + [ 'attribute' => 'status', "value" =>"statusHuman" ], ['class' => 'yii\grid\ActionColumn', 'template' => '{view}', diff --git a/backend/views/procurement/_form_update.php b/backend/views/procurement/_form_update.php new file mode 100644 index 0000000..cdaae4c --- /dev/null +++ b/backend/views/procurement/_form_update.php @@ -0,0 +1,34 @@ + + +