add contract
This commit is contained in:
284
frontend/controllers/ContractController.php
Normal file
284
frontend/controllers/ContractController.php
Normal file
@@ -0,0 +1,284 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\controllers;
|
||||
|
||||
use Yii;
|
||||
use common\models\Contract;
|
||||
use frontend\models\ContractSearch;
|
||||
use yii\web\Controller;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\filters\VerbFilter;
|
||||
use common\models\Card;
|
||||
use common\models\TicketInstallmentRequest;
|
||||
use common\models\Ticket;
|
||||
use common\models\Transfer;
|
||||
use common\models\Account;
|
||||
use common\components\Helper;
|
||||
use common\models\Sale;
|
||||
use common\models\Product;
|
||||
use common\models\ShoppingCart;
|
||||
|
||||
/**
|
||||
* ContractController implements the CRUD actions for Contract model.
|
||||
*/
|
||||
class ContractController extends Controller {
|
||||
public function behaviors() {
|
||||
return [
|
||||
'verbs' => [
|
||||
'class' => VerbFilter::className (),
|
||||
'actions' => [
|
||||
'delete' => [
|
||||
'post'
|
||||
],
|
||||
'payout' => [
|
||||
'post'
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all Contract models.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionIndex($id_card) {
|
||||
$card = Card::findOne ( $id_card );
|
||||
|
||||
if (! isset ( $card ))
|
||||
throw new NotFoundHttpException ( 'A bérlet nem található' );
|
||||
|
||||
$searchModel = new ContractSearch ();
|
||||
$searchModel->card = $card;
|
||||
$searchModel->customer = $card->customer;
|
||||
$dataProvider = $searchModel->search ( Yii::$app->request->queryParams );
|
||||
|
||||
return $this->render ( 'index', [
|
||||
'searchModel' => $searchModel,
|
||||
'dataProvider' => $dataProvider
|
||||
] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a single Contract model.
|
||||
*
|
||||
* @param integer $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionView($id) {
|
||||
$model = $this->findModel ( $id );
|
||||
$customer = $model->customer;
|
||||
$card = $customer->card;
|
||||
|
||||
$installments = TicketInstallmentRequest::find ()->andWhere ( [
|
||||
'id_contract' => $model->id_contract
|
||||
] )->orderBy ( [
|
||||
'ticket_installment_request.priority' => SORT_ASC
|
||||
] )->all ();
|
||||
|
||||
return $this->render ( 'view', [
|
||||
'model' => $model,
|
||||
'intstallments' => $installments,
|
||||
'card' => $card
|
||||
] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Contract model.
|
||||
* If creation is successful, the browser will be redirected to the 'view' page.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionCreate() {
|
||||
$model = new Contract ();
|
||||
|
||||
if ($model->load ( Yii::$app->request->post () ) && $model->save ()) {
|
||||
return $this->redirect ( [
|
||||
'view',
|
||||
'id' => $model->id_contract
|
||||
] );
|
||||
} else {
|
||||
return $this->render ( 'create', [
|
||||
'model' => $model
|
||||
] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates an existing Contract 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_contract
|
||||
] );
|
||||
} else {
|
||||
return $this->render ( 'update', [
|
||||
'model' => $model
|
||||
] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an existing Contract 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'
|
||||
] );
|
||||
}
|
||||
|
||||
/**
|
||||
* EGY RÉSZLET KIFIZETÉSE
|
||||
*/
|
||||
public function actionPayout($id) {
|
||||
$part = TicketInstallmentRequest::findOne ( $id );
|
||||
$contract = $part->contract;
|
||||
$customer = $contract->customer;
|
||||
$card = $customer->card;
|
||||
|
||||
$connection = \Yii::$app->db;
|
||||
$transaction = $connection->beginTransaction ();
|
||||
try {
|
||||
|
||||
$result = Transfer::sellContractTicket ( $contract, $part, Account::readDefaultObject (), Transfer::STATUS_NOT_PAID, Transfer::PAYMENT_METHOD_CASH, true );
|
||||
$transfer = $result [0];
|
||||
if ( $part->status != TicketInstallmentRequest::$STATUS_REJECTED ){
|
||||
$contract->part_required = $contract->part_required +1;
|
||||
}
|
||||
|
||||
$contract->part_paid = $contract->part_paid +1;
|
||||
|
||||
if ( $contract->part_paid >= $contract->part_required){
|
||||
$contract->status = Contract::$STATUS_PAID;
|
||||
}else{
|
||||
$contract->status = Contract::$STATUS_NOT_PAID;
|
||||
}
|
||||
|
||||
$contract->save(false);
|
||||
|
||||
$part->status = TicketInstallmentRequest::$STATUS_ACCEPTED_MANUAL;
|
||||
$part->id_transfer = $transfer->id_transfer;
|
||||
$part->request_processed_at = Helper::getDateTimeString ();
|
||||
|
||||
$part->save ( false );
|
||||
$transaction->commit ();
|
||||
\Yii::$app->session->setFlash ( 'success', "Részlet a bevásárló kosárba helyezve!" );
|
||||
} catch ( Exception $e ) {
|
||||
$transaction->rollback ();
|
||||
Yii::error ( "Nem sikerült a kifizetés." );
|
||||
}
|
||||
|
||||
return $this->redirect ( [
|
||||
'view',
|
||||
'id' => $contract->id_contract
|
||||
] );
|
||||
}
|
||||
|
||||
/**
|
||||
* EGY RÉSZLET KIFIZETÉSE
|
||||
*/
|
||||
public function actionCancel($id) {
|
||||
$contract = $this->findModel ( $id );
|
||||
$customer = $contract->customer;
|
||||
$card = $customer->card;
|
||||
|
||||
if ($contract->canCancel ()) {
|
||||
$connection = \Yii::$app->db;
|
||||
$transaction = $connection->beginTransaction ();
|
||||
try {
|
||||
|
||||
$contract->flag = Contract::$FLAG_CANCELED;
|
||||
$contract->save ();
|
||||
$requests = $contract->requests;
|
||||
$buntetes = 0;
|
||||
|
||||
foreach ( $requests as $request ) {
|
||||
/** @var common\models\TicketInstallmentRequest $request*/
|
||||
if ($request->isStatusAccepted ()) {
|
||||
$buntetes = $buntetes + 1;
|
||||
} else {
|
||||
$request->status = TicketInstallmentRequest::$STATUS_CANCELED;
|
||||
$request->save ( false );
|
||||
}
|
||||
}
|
||||
|
||||
$productBuntetes = Product::find ()->andWhere ( [
|
||||
'product_number' => Product::$BUNTETES
|
||||
] )->one ();
|
||||
|
||||
if (isset ( $productBuntetes )) {
|
||||
if ($buntetes > 0) {
|
||||
|
||||
$sale = new Sale ();
|
||||
$sale->id_account = Account::readDefault ();
|
||||
$sale->id_product = $productBuntetes->id_product;
|
||||
$sale->status = Sale::STATUS_NOT_PAID;
|
||||
$sale->type = Sale::TYPE_PRODUCT;
|
||||
$sale->item_price = $productBuntetes->sale_price;
|
||||
$sale->count = $buntetes;
|
||||
$sale->money = $buntetes * $sale->item_price;
|
||||
$sale->id_user = \Yii::$app->user->id;
|
||||
|
||||
$sale->save ( false );
|
||||
|
||||
$transfer = Transfer::createProductTransfer ( $sale, Account::readDefaultObject (), null, null, $sale->count, $productBuntetes, Transfer::STATUS_NOT_PAID, $customer );
|
||||
$transfer->payment_method = Transfer::PAYMENT_METHOD_CASH;
|
||||
|
||||
$transfer->id_user = Yii::$app->user->id;
|
||||
|
||||
$transfer->save ( false );
|
||||
|
||||
$cart = new ShoppingCart ();
|
||||
$cart->id_customer = $customer->id_customer;
|
||||
$cart->id_transfer = $transfer->id_transfer;
|
||||
$cart->save ( false );
|
||||
}
|
||||
}
|
||||
|
||||
$transaction->commit ();
|
||||
\Yii::$app->session->setFlash ( 'success', "Szerződés felbontva!" );
|
||||
} catch ( Exception $e ) {
|
||||
$transaction->rollback ();
|
||||
Yii::error ( "Szerződés felbontása nem sikerült!" );
|
||||
}
|
||||
}else{
|
||||
\Yii::$app->session->setFlash ( 'danger', "Szerződést nem lehet felbontani!" );
|
||||
}
|
||||
|
||||
return $this->redirect ( [
|
||||
'view',
|
||||
'id' => $contract->id_contract
|
||||
] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the Contract model based on its primary key value.
|
||||
* If the model is not found, a 404 HTTP exception will be thrown.
|
||||
*
|
||||
* @param integer $id
|
||||
* @return Contract the loaded model
|
||||
* @throws NotFoundHttpException if the model cannot be found
|
||||
*/
|
||||
protected function findModel($id) {
|
||||
if (($model = Contract::findOne ( $id )) !== null) {
|
||||
return $model;
|
||||
} else {
|
||||
throw new NotFoundHttpException ( 'The requested page does not exist.' );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,7 @@ class CustomerController extends Controller
|
||||
],
|
||||
'access' => [
|
||||
'class' => \yii\filters\AccessControl::className(),
|
||||
'only' => ['create', 'update','reception'],
|
||||
'only' => ['create', 'update','reception','contract'],
|
||||
'rules' => [
|
||||
// allow authenticated users
|
||||
[
|
||||
@@ -199,6 +199,18 @@ class CustomerController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function actionContract($id){
|
||||
$model = $this->findModel($id);
|
||||
|
||||
$mpdf=new \mPDF('utf-8', 'A4-L');
|
||||
$mpdf->WriteHTML($this->renderPartial('_contract', [
|
||||
'model' => $model,
|
||||
]));
|
||||
$mpdf->Output('szerzodes.pdf', 'D');
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an existing Customer model.
|
||||
* If deletion is successful, the browser will be redirected to the 'index' page.
|
||||
|
||||
@@ -19,6 +19,7 @@ use common\models\ProductCategory;
|
||||
use common\models\Product;
|
||||
use common\models\TransferTicketSearch;
|
||||
use common\models\TicketType;
|
||||
use frontend\models\UserCartForm;
|
||||
|
||||
/**
|
||||
* TransferController implements the CRUD actions for Transfer model.
|
||||
@@ -337,4 +338,15 @@ class TransferController extends Controller
|
||||
exit;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function actionUserCart(){
|
||||
|
||||
$model = new UserCartForm();
|
||||
if ($model->load(Yii::$app->request->post()) && $model->payout()) {
|
||||
return $this->redirect(['user-cart']);
|
||||
}
|
||||
$model->run();
|
||||
return $this->render("usercart",[ 'model' => $model]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user