add contract

This commit is contained in:
2016-01-25 01:43:19 +01:00
parent fd4d38ab44
commit df14401b28
47 changed files with 2868 additions and 766 deletions

View File

@@ -0,0 +1,88 @@
<?php
namespace frontend\models;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\Contract;
/**
* ContractSearch represents the model behind the search form about `common\models\Contract`.
*/
class ContractSearch extends Contract
{
public $card;
public $customer;
public $parts;
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id_contract', 'id_user', 'id_customer', 'status', 'flag', 'part_paid', 'part_count', 'part_required'], 'integer'],
[['expired_at', 'created_at', 'updated_at'], 'safe'],
];
}
/**
* @inheritdoc
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Contract::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
$query->andWhere([
'id_customer' => $this->customer->id_customer
]);
$query->andFilterWhere([
// 'id_contract' => $this->id_contract,
// 'id_user' => $this->id_user,
// 'id_customer' => $this->id_customer,
// 'status' => $this->status,
// 'flag' => $this->flag,
// 'part_paid' => $this->part_paid,
// 'part_count' => $this->part_count,
// 'part_required' => $this->part_required,
// 'expired_at' => $this->expired_at,
// 'created_at' => $this->created_at,
// 'updated_at' => $this->updated_at,
]);
return $dataProvider;
}
}

View File

@@ -56,12 +56,17 @@ class KeyToggleForm extends Model
public function assign(){
if ( isset($this->card) && isset($this->customer) ){
$assignment = new CardKeyAssignment();
$assignment->id_card = $this->card->id_card;
$assignment->id_key = $this->keyModel->id_key;
$assignment->id_user = \Yii::$app->user->id;
$assignment->save(false);
\Yii::$app->session->setFlash ( 'success', 'Kulcs kiadva!' );
$assignments = CardKeyAssignment::find()->andWhere(['id_card' => $this->card->id_card])->all();
if ( count($assignments) > 0 ){
\Yii::$app->session->setFlash ( 'danger', 'A vendégnél egyszerre csak egy kulcs lehet' );
}else{
$assignment = new CardKeyAssignment();
$assignment->id_card = $this->card->id_card;
$assignment->id_key = $this->keyModel->id_key;
$assignment->id_user = \Yii::$app->user->id;
$assignment->save(false);
\Yii::$app->session->setFlash ( 'success', 'Kulcs kiadva!' );
}
}else{
\Yii::$app->session->setFlash ( 'danger', 'Nincs vendég kiválasztva vagy érvénytelen kártya!' );
}

View File

@@ -12,6 +12,8 @@ use common\models\CardSearch;
use common\models\AccountState;
use common\models\Key;
use common\models\CardKeyAssignment;
use common\models\Contract;
use yii\db\Expression;
/**
* ContactForm is the model behind the contact form.
@@ -26,6 +28,7 @@ class ReceptionForm extends Model
public $cardSearchModel;
public $lastCassaState;
public $keys;
public $contract;
/**
* @inheritdoc
*/
@@ -73,6 +76,7 @@ class ReceptionForm extends Model
$this->customer = $this->card->customer;
$this->readValidTickets();
$this->readAssignedKeys();
$this->readContract();
}
$defaultAccount = Account::readDefault();
@@ -104,6 +108,18 @@ class ReceptionForm extends Model
}
}
public function readContract(){
if ($this->isCardWithCustomer()){
$query = Contract::find();
$query->andWhere(['id_customer' => $this->customer->id_customer ]);
$query->andWhere([ '>=' ,'expired_at' , new Expression("now()") ]);
$query->andWhere(["not in" , 'flag' , [Contract::$FLAG_DELETED, Contract::$FLAG_CANCELED]]);
$this->contract = $query->one();
}
}
public function hasCassa(){
return isset($this->lastCassaState) ;
}

View File

@@ -10,6 +10,8 @@ use common\models\UserSoldItem;
use common\models\ShoppingCart;
use yii\base\Object;
use common\models\TicketInstallmentRequest;
use common\models\Contract;
use common\components\Helper;
/**
* @property $cart string name of cart, into we put the ticket
@@ -103,6 +105,17 @@ class TicketCreate extends Ticket{
$this->addError($attribute,"Vendég bankszámlaszáma nem 16 vagy 24 hosszú");
return;
}
//find
$query = Contract::find();
$query->andWhere( [ 'id_customer' => $this->customer->id_customer ]);
$query->andWhere( [ '>', 'expired_at' , Helper::getDateTimeString() ]);
$query->andWhere( [ 'not in', 'flag', [Contract::$FLAG_DELETED ] ]);
$contracts = $query->all();
if ( count($contracts) > 0 ){
$this->addError($attribute,"A vendégnek már van érvényes vagy felbontott szerződése!");
}
}
}
}
@@ -142,15 +155,28 @@ class TicketCreate extends Ticket{
$this->addTransfer();
$this->appendToUserCart();
$this->appendToCustomerCart();
$this->addTicketInstallmentRequests($insert);
$this->addContract($insert);
}
public function addTicketInstallmentRequests($insert){
public function addContract($insert){
if ($insert){
$ticketType = TicketType::findOne($this->id_ticket_type);
if ( isset($ticketType) && $ticketType->isInstallment() ){
$requests = TicketInstallmentRequest::createInstallments($this, $ticketType, $this->customer);
$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 = $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->id_ticket_type;
$contract->save();
$requests = TicketInstallmentRequest::createInstallments($this, $ticketType, $this->customer,$contract);
foreach ($requests as $request){
$request->save(false);
}

View File

@@ -0,0 +1,103 @@
<?php
namespace frontend\models;
use Yii;
use yii\base\Model;
use common\models\Transfer;
/**
* ContactForm is the model behind the contact form.
*/
class UserCartForm extends Model
{
public $items = [];
public $transfers;
public $payment_method;
public $money = 0;
public $selected = [];
/**
* @inheritdoc
*/
public function rules()
{
return [
['selected', 'each', 'rule' => ['integer']],
[['money' ,'payment_method'],'integer'],
[['payment_method'],'validatePaymentMethod'],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
];
}
public function validatePaymentMethod( $attribute, $params ){
if ( !empty($this->payment_method)){
// echo $this->payment_method;
$arr = Transfer::paymentMethods();
if ( !array_key_exists($this->payment_method, $arr) ){
$this->addError($attribute, "Érvénytelen fizetési mód");
}
}
}
public function payout(){
$valid = $this->validate();
if ( !$valid ){
return false;
}
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->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;
}
}
public function changePaymentMethod($item){
if ( !empty($this->payment_method)){
$item->payment_method = $this->payment_method;
}
}
public function run(){
$this->readTransfers();
}
public function readTransfers( ) {
$this->transfers = $this->loadTransfers();
}
public function loadTransfers($id_tranfer_array = null){
$query = Transfer::find();
$query->innerJoin("user_sold_item", "user_sold_item.id_transfer = transfer.id_transfer");
$query->andWhere(["user_sold_item.id_user" => \Yii::$app->user->id]);
if (isset($id_tranfer_array)){
$query->andWhere(["in", "transfer.id_transfer" , $id_tranfer_array ]);
}
return $query->all();
}
}