Add ContractForm, Add contract pdf, Add Display all Transfer option
This commit is contained in:
@@ -56,4 +56,7 @@ class ContactForm extends Model
|
||||
->setTextBody($this->body)
|
||||
->send();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
307
frontend/models/ContractForm.php
Normal file
307
frontend/models/ContractForm.php
Normal file
@@ -0,0 +1,307 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\models;
|
||||
|
||||
use Yii;
|
||||
use yii\base\Model;
|
||||
use yii\base\Exception;
|
||||
use common\models\Ticket;
|
||||
use common\models\Account;
|
||||
use common\models\TicketType;
|
||||
use common\models\Transfer;
|
||||
use common\models\Contract;
|
||||
use common\models\TicketInstallmentRequest;
|
||||
use common\models\Discount;
|
||||
use common\models\ShoppingCart;
|
||||
|
||||
/**
|
||||
* ContactForm is the model behind the contact form.
|
||||
*/
|
||||
class ContractForm extends Model {
|
||||
public $name;
|
||||
public $birthdate;
|
||||
public $birthplace;
|
||||
public $mothername;
|
||||
public $zip;
|
||||
public $city;
|
||||
public $address;
|
||||
public $bank_account;
|
||||
public $bank_name;
|
||||
public $phone;
|
||||
public $email;
|
||||
public $ticket_type;
|
||||
public $customer;
|
||||
public $payment_method;
|
||||
public $id_discount;
|
||||
private $ticket;
|
||||
private $transfer;
|
||||
public $contract;
|
||||
private $ticketType;
|
||||
private $money;
|
||||
private $discount;
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules() {
|
||||
return [
|
||||
// name, email, subject and body are required
|
||||
[
|
||||
[
|
||||
'ticket_type',
|
||||
'name',
|
||||
'birthdate',
|
||||
'birthplace',
|
||||
'mothername',
|
||||
"zip",
|
||||
"city",
|
||||
"address",
|
||||
"bank_account",
|
||||
"bank_name",
|
||||
'phone',
|
||||
'email',
|
||||
'payment_method'
|
||||
],
|
||||
'required'
|
||||
],
|
||||
// email has to be a valid email address
|
||||
[
|
||||
'email',
|
||||
'email'
|
||||
],
|
||||
[
|
||||
'ticket_type',
|
||||
'integer'
|
||||
],
|
||||
[
|
||||
[
|
||||
'phone'
|
||||
],
|
||||
'string',
|
||||
'max' => 20
|
||||
],
|
||||
[
|
||||
[
|
||||
'bank_account'
|
||||
],
|
||||
'string',
|
||||
'max' => 24
|
||||
],
|
||||
[
|
||||
[
|
||||
'bank_name'
|
||||
],
|
||||
'string',
|
||||
'max' => 100
|
||||
],
|
||||
[
|
||||
[
|
||||
'mothername',
|
||||
'birthplace',
|
||||
'name',
|
||||
'zip',
|
||||
'city',
|
||||
'address'
|
||||
],
|
||||
'string',
|
||||
'max' => 100
|
||||
],
|
||||
[
|
||||
[
|
||||
'birthdate'
|
||||
],
|
||||
'date'
|
||||
],
|
||||
[
|
||||
[
|
||||
'ticket_type',
|
||||
'id_discount',
|
||||
'payment_method'
|
||||
],
|
||||
'integer'
|
||||
],
|
||||
[
|
||||
[
|
||||
'ticket_type'
|
||||
],
|
||||
'validateTicketType'
|
||||
]
|
||||
];
|
||||
}
|
||||
public function validateTicketType($attribute, $params) {
|
||||
$this->ticketType = TicketType::findOne ( $this->ticket_type );
|
||||
if (! isset ( $this->ticketType )) {
|
||||
$this->addError ( $attribute, "Bérlet típus nem található" );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function attributeLabels() {
|
||||
return [
|
||||
'name' => 'Név',
|
||||
'birthdate' => 'Születési dátum',
|
||||
'birthplace' => 'Születési hely',
|
||||
'mothername' => 'Anyja neve',
|
||||
'zip' => 'Irányítószám',
|
||||
'city' => 'Város',
|
||||
'address' => 'Cím',
|
||||
'bank_account' => 'Bankszámlaszám',
|
||||
'bank_name' => 'Bank neve',
|
||||
'phone' => 'Telefonszám',
|
||||
'email' => 'E-mail',
|
||||
'ticket_type' => 'Bérlet típus' ,
|
||||
'payment_method' => 'Fizetési mód' ,
|
||||
'id_discount' => 'Kedvezmény' ,
|
||||
];
|
||||
}
|
||||
public function fillOut() {
|
||||
$this->name = $this->customer->name;
|
||||
$this->birthdate = isset ( $this->customer->birthdate ) ? \Yii::$app->formatter->asDate ( $this->customer->birthdate ) : '';
|
||||
$this->birthplace = $this->customer->birth_place;
|
||||
$this->mothername = $this->customer->mother_name;
|
||||
$this->zip = $this->customer->zip;
|
||||
$this->city = $this->customer->city;
|
||||
$this->address = $this->customer->address;
|
||||
$this->bank_account = $this->customer->bank_account;
|
||||
$this->bank_name = $this->customer->bank_name;
|
||||
$this->phone = $this->customer->phone;
|
||||
$this->email = $this->customer->email;
|
||||
}
|
||||
public function make() {
|
||||
$this->money = $this->ticketType->price_brutto;
|
||||
$this->discount = Discount::findOne($this->id_discount);
|
||||
if ( isset($this->discount)){
|
||||
$this->money = Discount::applyDiscount($this->ticketType->price_brutto, $this->discount);
|
||||
}
|
||||
$this->updateCustomer ();
|
||||
|
||||
|
||||
$this->createTicket ();
|
||||
$this->createTransfer ();
|
||||
$this->appendToCustomerCart();
|
||||
$this->addContract();
|
||||
|
||||
$this->ticket->id_contract = $this->contract->id_contract;
|
||||
|
||||
if ( !$this->ticket->update(false)){
|
||||
\Yii::error("Nem sikerült a bérlethez hozzárendelni a szerződést");
|
||||
throw new Exception("Hiba történt mentés közben!");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
public function updateCustomer() {
|
||||
$this->customer->name = $this->name;
|
||||
$this->customer->birthdate = $this->birthdate;
|
||||
$this->customer->birth_place = $this->birthplace;
|
||||
$this->customer->mother_name = $this->mothername;
|
||||
$this->customer->zip = $this->zip;
|
||||
$this->customer->city = $this->city;
|
||||
$this->customer->address = $this->address;
|
||||
$this->customer->bank_account = $this->bank_account;
|
||||
$this->customer->bank_name = $this->bank_name;
|
||||
$this->customer->phone = $this->phone;
|
||||
$this->customer->email = $this->email;
|
||||
|
||||
if (! $this->customer->save ( false )) {
|
||||
throw new Exception ( 'nem sikerült a szerződés létrehozása' );
|
||||
}
|
||||
}
|
||||
public function createTicket() {
|
||||
|
||||
$ticket = new Ticket ();
|
||||
$ticket->id_user = \Yii::$app->user->id;
|
||||
$ticket->id_account = Account::readDefault ();
|
||||
$ticket->id_discount = $this->id_discount;
|
||||
$ticket->start = date ( 'Y-m-d' );
|
||||
$date = new \DateTime ();
|
||||
$date->modify ( '+1 month' );
|
||||
$date->modify ( '-1 day' );
|
||||
$ticket->end = $date->format ( 'Y-m-d H:i:s' );
|
||||
$ticket->id_ticket_type = $this->ticketType->id_ticket_type;
|
||||
$ticket->price_brutto = $this->money;
|
||||
$ticket->max_usage_count = $this->ticketType->max_usage_count;
|
||||
$ticket->usage_count = 0;
|
||||
$ticket->status = Ticket::STATUS_ACTIVE;
|
||||
$ticket->comment = "Szerződéses bérlet";
|
||||
$ticket->id_card = $this->customer->card->id_card;
|
||||
$ticket->part = 0;
|
||||
$ticket->part_paid = 0;
|
||||
$ticket->part_count = $this->ticketType->installment_count;
|
||||
|
||||
if (! $ticket->save ( false )) {
|
||||
\Yii::error ( "A bérlet mentése sikertelen volt" );
|
||||
throw new Exception ( "Hiba történt mentés közben" );
|
||||
}
|
||||
|
||||
$this->ticket = $ticket;
|
||||
}
|
||||
public function createTransfer() {
|
||||
$transfer = new Transfer ();
|
||||
$transfer->id_object = $this->ticket->id_ticket;
|
||||
$transfer->status = Transfer::STATUS_NOT_PAID;
|
||||
$transfer->type = Transfer::TYPE_TICKET;
|
||||
$transfer->item_price = $this->money;
|
||||
$transfer->count = 1;
|
||||
$transfer->money = $this->money;
|
||||
$transfer->id_user = \Yii::$app->user->id;
|
||||
$transfer->comment = "Szerződéses bérlet";
|
||||
$transfer->id_account = Account::readDefault ();
|
||||
$transfer->direction = Transfer::DIRECTION_IN;
|
||||
$transfer->id_customer = $this->customer->id_customer;
|
||||
$transfer->payment_method = $this->payment_method;
|
||||
$transfer->id_discount = $this->id_discount;
|
||||
|
||||
if (! $transfer->save ( false )) {
|
||||
\Yii::error ( "A tranzakció mentése sikertelen volt" );
|
||||
throw new Exception ( "Hiba történt mentés közben" );
|
||||
}
|
||||
$this->transfer = $transfer;
|
||||
}
|
||||
|
||||
public function addContract() {
|
||||
if (! $this->ticketType->isInstallment ()) {
|
||||
\Yii::error ( "A bérlet típus nem tágmogatja a szerződés kötést!" );
|
||||
throw new Exception ( "A bérlet típus nem tágmogatja a szerződés kötést!" );
|
||||
}
|
||||
|
||||
$contract = new Contract ();
|
||||
$contract->id_customer = $this->customer->id_customer;
|
||||
$contract->id_user = \Yii::$app->user->id;
|
||||
$contract->status = Contract::$STATUS_PAID;
|
||||
$contract->flag = Contract::$FLAG_ACTIVE;
|
||||
$contract->part_count = $this->ticketType->installment_count;
|
||||
$contract->part_paid = 0;
|
||||
$contract->part_required = 0;
|
||||
$contract->expired_at = date ( 'Y-m-d', strtotime ( "today +12 month -1 day" ) );
|
||||
$contract->id_ticket_type = $this->ticketType->id_ticket_type;
|
||||
|
||||
if (! $contract->save ( false )) {
|
||||
\Yii::error ( "A szerződés mentése sikertelen volt" );
|
||||
throw new Exception ( "Hiba történt mentés közben" );
|
||||
}
|
||||
|
||||
$this->contract = $contract;
|
||||
|
||||
$requests = TicketInstallmentRequest::createInstallments ( $this->ticket, $this->ticketType, $this->customer, $contract );
|
||||
foreach ( $requests as $request ) {
|
||||
$request->save ( false );
|
||||
if (! $request->save ( false )) {
|
||||
\Yii::error ( "A szerződés részlet mentése sikertelen volt" );
|
||||
throw new Exception ( "Hiba történt mentés közben" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function appendToCustomerCart(){
|
||||
$item = new ShoppingCart();
|
||||
$item->id_customer = $this->customer->id_customer;
|
||||
$item->id_transfer = $this->transfer->id_transfer;
|
||||
if ( !$item->save(false) ){
|
||||
\Yii::error("Vendég kosár hozzárendelés sikertelen!");
|
||||
throw new Exception ( "Hiba történt mentés közben" );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ use Yii;
|
||||
use yii\base\Model;
|
||||
use common\models\Transfer;
|
||||
use common\models\Account;
|
||||
use common\components\TransferPayout;
|
||||
|
||||
/**
|
||||
* ContactForm is the model behind the contact form.
|
||||
@@ -60,19 +61,34 @@ class CustomerCartForm extends Model
|
||||
}
|
||||
|
||||
if ( isset($this->selected) && count($this->selected) > 0 ){
|
||||
$items = $this->loadTransfers($this->selected);
|
||||
if ( count($items) == count($this->selected) ){
|
||||
foreach ($items as $item){
|
||||
$this->changePaymentMethod($item);
|
||||
$item->id_account = Account::readDefault();
|
||||
$item->payout();
|
||||
}
|
||||
\Yii::$app->session->setFlash('success', 'Kifizetve');
|
||||
return true;
|
||||
}else{
|
||||
\Yii::$app->session->setFlash('danger', 'Időközben változtak a kosrában található tételek');
|
||||
return false;
|
||||
}
|
||||
|
||||
$connection = \Yii::$app->db;
|
||||
$transaction = $connection->beginTransaction();
|
||||
try {
|
||||
$tp = new TransferPayout( [
|
||||
'idUser' => \Yii::$app->user->id,
|
||||
'idTransfers' => $this->selected,
|
||||
'idAccount' => Account::readDefault (),
|
||||
'cartType' => 'customer',
|
||||
'overridePaymentMethod' => $this->payment_method,
|
||||
'idCustomer' => $this->customer->id_customer
|
||||
] );
|
||||
|
||||
$tp->payout ();
|
||||
|
||||
$transaction->commit ();
|
||||
\Yii::$app->session->setFlash ( 'success', 'A vásárló kosár kiválasztott tranzakciói ki lettek kifizetve!');
|
||||
return true;
|
||||
|
||||
} catch ( Exception $e ) {
|
||||
$transaction->rollback ();
|
||||
Yii::error ( "faled to save :" . $e->getMessage () );
|
||||
} catch ( \Exception $e ) {
|
||||
$transaction->rollback ();
|
||||
Yii::error ( "faled to save :" . $e->getMessage () );
|
||||
}
|
||||
return false;
|
||||
|
||||
}else{
|
||||
\Yii::$app->session->setFlash('danger', 'Nem választott ki terméket');
|
||||
return false;
|
||||
|
||||
@@ -105,7 +105,9 @@ class CustomerCreate extends \common\models\Customer
|
||||
[['zip'], 'string', 'max' => 8],
|
||||
|
||||
[['city'], 'string', 'max' => 30],
|
||||
[['photo_data'] ,'safe']
|
||||
[['photo_data'] ,'safe'],
|
||||
[['birth_place'] ,'safe'],
|
||||
[['mother_name'] ,'safe'],
|
||||
|
||||
// [['email','phone'], 'validateEmailOrPhoneRequired' ],
|
||||
];
|
||||
|
||||
@@ -115,7 +115,9 @@ class CustomerUpdate extends \common\models\Customer
|
||||
[['zip'], 'string', 'max' => 8],
|
||||
|
||||
[['city'], 'string', 'max' => 30],
|
||||
[['photo_data'] ,'safe']
|
||||
[['photo_data'] ,'safe'],
|
||||
[['birth_place'] ,'safe'],
|
||||
[['mother_name'] ,'safe'],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ class KeyToggleForm extends Model
|
||||
public $card;
|
||||
public $customer;
|
||||
public $keyModel;
|
||||
|
||||
public $action;
|
||||
|
||||
|
||||
|
||||
@@ -55,6 +55,7 @@ class KeyToggleForm extends Model
|
||||
$assignments = CardKeyAssignment::find()->andWhere(['id_key' => $this->keyModel->id_key])->all();
|
||||
if ( count($assignments) > 0){
|
||||
$this->unassign();
|
||||
$this->action = 'unassign';
|
||||
}else{
|
||||
$this->assign();
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ use yii\base\Model;
|
||||
use common\models\Transfer;
|
||||
use common\components\Helper;
|
||||
use common\models\Account;
|
||||
use common\components\TransferPayout;
|
||||
|
||||
/**
|
||||
* ContactForm is the model behind the contact form.
|
||||
@@ -60,19 +61,48 @@ class UserCartForm extends Model
|
||||
}
|
||||
|
||||
if ( isset($this->selected) && count($this->selected) > 0 ){
|
||||
$items = $this->loadTransfers($this->selected);
|
||||
if ( count($items) == count($this->selected) ){
|
||||
foreach ($items as $item){
|
||||
$this->changePaymentMethod($item);
|
||||
$item->id_account = Account::readDefault();
|
||||
$item->payout();
|
||||
}
|
||||
\Yii::$app->session->setFlash('success', 'Kifizetve');
|
||||
return true;
|
||||
}else{
|
||||
\Yii::$app->session->setFlash('danger', 'Időközben változtak a kosrában található tételek');
|
||||
return false;
|
||||
}
|
||||
|
||||
$connection = \Yii::$app->db;
|
||||
$transaction = $connection->beginTransaction();
|
||||
try {
|
||||
$tp = new TransferPayout( [
|
||||
'idUser' => \Yii::$app->user->id,
|
||||
'idTransfers' => $this->selected,
|
||||
'idAccount' => Account::readDefault (),
|
||||
'cartType' => 'user',
|
||||
'overridePaymentMethod' => $this->payment_method
|
||||
] );
|
||||
|
||||
$tp->payout ();
|
||||
|
||||
$transaction->commit ();
|
||||
\Yii::$app->session->setFlash ( 'success', 'A recepció kosár kiválasztott tranzakciói ki lettek kifizetve!');
|
||||
return true;
|
||||
|
||||
} catch ( Exception $e ) {
|
||||
$transaction->rollback ();
|
||||
Yii::error ( "faled to save :" . $e->getMessage () );
|
||||
} catch ( \Exception $e ) {
|
||||
$transaction->rollback ();
|
||||
Yii::error ( "faled to save :" . $e->getMessage () );
|
||||
}
|
||||
return false;
|
||||
|
||||
// $items = $this->loadTransfers($this->selected);
|
||||
// if ( count($items) == count($this->selected) ){
|
||||
// foreach ($items as $item){
|
||||
// $this->changePaymentMethod($item);
|
||||
// if ( Helper::isUserCartVisibilityAll() ){
|
||||
// $item->id_account = Account::readDefault();
|
||||
// }
|
||||
// $item->payout();
|
||||
// }
|
||||
// \Yii::$app->session->setFlash('success', 'Kifizetve');
|
||||
// return true;
|
||||
// }else{
|
||||
// \Yii::$app->session->setFlash('danger', 'Időközben változtak a kosrában található tételek');
|
||||
// return false;
|
||||
// }
|
||||
}else{
|
||||
\Yii::$app->session->setFlash('danger', 'Nem választott ki terméket');
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user