Add ContractForm, Add contract pdf, Add Display all Transfer option

This commit is contained in:
2016-02-21 21:41:25 +01:00
parent 462e93c740
commit 29a8b440b2
33 changed files with 1417 additions and 304 deletions

View File

@@ -17,6 +17,8 @@ use common\components\Helper;
use common\models\Sale;
use common\models\Product;
use common\models\ShoppingCart;
use common\models\Customer;
use frontend\models\ContractForm;
/**
* ContractController implements the CRUD actions for Contract model.
@@ -32,10 +34,10 @@ class ContractController extends Controller {
],
'payout' => [
'post'
],
],
'cancel' => [
'post'
],
]
]
]
];
@@ -43,7 +45,7 @@ class ContractController extends Controller {
/**
* Lists all Contract models.
*
*
* @return mixed
*/
public function actionIndex($id_card) {
@@ -65,7 +67,7 @@ class ContractController extends Controller {
/**
* Displays a single Contract model.
*
*
* @param integer $id
* @return mixed
*/
@@ -90,7 +92,7 @@ class ContractController extends Controller {
/**
* Creates a new Contract model.
* If creation is successful, the browser will be redirected to the 'view' page.
*
*
* @return mixed
*/
public function actionCreate() {
@@ -111,7 +113,7 @@ class ContractController extends Controller {
/**
* Updates an existing Contract model.
* If update is successful, the browser will be redirected to the 'view' page.
*
*
* @param integer $id
* @return mixed
*/
@@ -133,7 +135,7 @@ class ContractController extends Controller {
/**
* Deletes an existing Contract model.
* If deletion is successful, the browser will be redirected to the 'index' page.
*
*
* @param integer $id
* @return mixed
*/
@@ -160,21 +162,21 @@ class ContractController extends Controller {
$result = Transfer::sellContractTicket ( $contract, $part, Account::readDefaultObject (), Transfer::STATUS_NOT_PAID, Transfer::PAYMENT_METHOD_CASH, true );
$transfer = $result [0];
$ticket = $result[1];
if ( $part->status != TicketInstallmentRequest::$STATUS_REJECTED ){
$contract->part_required = $contract->part_required +1;
$ticket = $result [1];
if ($part->status != TicketInstallmentRequest::$STATUS_REJECTED) {
$contract->part_required = $contract->part_required + 1;
}
$contract->part_paid = $contract->part_paid +1;
$contract->part_paid = $contract->part_paid + 1;
if ( $contract->part_paid >= $contract->part_required){
if ($contract->part_paid >= $contract->part_required) {
$contract->status = Contract::$STATUS_PAID;
}else{
} else {
$contract->status = Contract::$STATUS_NOT_PAID;
}
$contract->save(false);
$contract->save ( false );
$part->status = TicketInstallmentRequest::$STATUS_ACCEPTED_MANUAL;
$part->id_transfer = $transfer->id_transfer;
$part->request_processed_at = Helper::getDateTimeString ();
@@ -258,16 +260,16 @@ class ContractController extends Controller {
$transaction->commit ();
\Yii::$app->session->setFlash ( 'success', "Szerződés felbontva!" );
return $this->redirect ( [
return $this->redirect ( [
'product/sale',
'number' => $card->number
'number' => $card->number
] );
} 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!" );
} else {
\Yii::$app->session->setFlash ( 'danger', "Szerződést nem lehet felbontani!" );
}
return $this->redirect ( [
@@ -275,11 +277,62 @@ class ContractController extends Controller {
'id' => $contract->id_contract
] );
}
public function actionMake($id) {
$customer = Customer::findOne ( $id );
if (! isset ( $customer )) {
throw new Exception ( "Az oldal nem található" );
}
$model = new ContractForm ( [
'customer' => $customer
] );
$model->fillOut ();
if ($model->load ( Yii::$app->request->post () ) && $model->validate ()) {
$connection = \Yii::$app->db;
$transaction = $connection->beginTransaction ();
try {
$model->make ();
$transaction->commit();
return $this->redirect ( [
'contract/view',
'id' => $model->contract->id_contract
] );
} catch ( \Exception $e ) {
$transaction->rollBack();
\Yii::$app->session->setFlash('danger', $e->getMessage());
}
}
return $this->render ( '_make_contract', [
'model' => $model
] );
}
public function actionContract($id){
$model = $this->findModel($id);
$mpdf=new \mPDF('utf-8', 'A4');
$mpdf->WriteHTML($this->renderPartial('_contract', [
'model' => $model,
]));
$fileName = "szerzodes";
$fileName .= "." . $model->customer->name;
$fileName .= "." .\Yii::$app->formatter->asDate( $model->created_at, "Y");
$fileName .=".pdf";
$mpdf->Output($fileName, 'D');//download file
// $mpdf->Output('szerzodes.pdf', 'I');//open in new tab
exit;
}
/**
* 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