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

@@ -88,6 +88,9 @@ class Contract extends \yii\db\ActiveRecord
public function getTicketType(){
return $this->hasOne(TicketType::className(), ['id_ticket_type' => 'id_ticket_type']);
}
public function getTicket(){
return $this->hasOne(Ticket::className(), ['id_contract' => 'id_contract']);
}
public function getCustomer(){
return $this->hasOne(Customer::className(), ['id_customer' => 'id_customer']);
@@ -179,4 +182,20 @@ class Contract extends \yii\db\ActiveRecord
public function isFlagActive() {
return $this->flag == static::$FLAG_ACTIVE;
}
public function getPriceMonthly(){
return $this->ticket->price_brutto;
}
public function getPartsTotal(){
$money = $this->getPriceMonthly();
$money = $money * $this->part_count;
return $money;
}
public function getPriceTotal(){
$money = $this->getPartsTotal();
$money = $money + $this->getPriceMonthly();
return $money;
}
}

View File

@@ -96,6 +96,8 @@ class Customer extends \yii\db\ActiveRecord
'updated_at' => Yii::t('common/customer', 'Updated At'),
'customerCardNumber' => Yii::t('common/customer', 'Card number'),
'cardNumber' => Yii::t('common/customer', 'Card number'),
'mother_name' => Yii::t('common/customer', 'Anyja neve'),
'birth_place' => Yii::t('common/customer', 'Születési hely'),
];
}
@@ -172,6 +174,16 @@ class Customer extends \yii\db\ActiveRecord
return $result;
}
public function getFullAddress(){
$zip = $this->zip;
$city = $this->city;
$address = $this->address;
$result = $zip . " " .$city . ", ". $address;
return $result;
}
}

View File

@@ -3,6 +3,7 @@
namespace common\models;
use Yii;
use common\components\Helper;
/**
* This is the model class for table "shopping_cart".
@@ -72,6 +73,8 @@ class ShoppingCart extends \yii\db\ActiveRecord
if ( isset($account)){
$sql .= " , id_account = " . $account;
} else if ( Helper::isUserCartVisibilityAll()){
$sql .= " , id_account = " . Account::readDefault();
}
$sql .= " WHERE t.status = " . Transfer::STATUS_NOT_PAID

View File

@@ -223,9 +223,11 @@ class TicketType extends \common\models\BaseFitnessActiveRecord {
$ticketTypes = null;
if ( $forceIncludeObjectWithId == null){
$ticketTypes = TicketType::find()->andWhere(['status' => self::STATUS_ACTIVE])->andFilterWhere(['ticket_type.id_account' => $account])->all();
$ticketTypes = TicketType::find()->andWhere(['status' => self::STATUS_ACTIVE ])
->andWhere([ '<>', 'installment_enabled' , '1']) ->andFilterWhere(['ticket_type.id_account' => $account])->all();
}else{
$ticketTypes = TicketType::find()->andWhere( ['or', ['status' => self::STATUS_ACTIVE], ['id_ticket_type' => $forceIncludeObjectWithId ] ])->andFilterWhere(['ticket_type.id_account' => $account])->all();
$ticketTypes = TicketType::find()->andWhere( ['or', ['status' => self::STATUS_ACTIVE], ['id_ticket_type' => $forceIncludeObjectWithId ] ])
->andWhere([ '<>', 'installment_enabled' , '1'])->andFilterWhere(['ticket_type.id_account' => $account])->all();
}
return $ticketTypes;

View File

@@ -488,8 +488,9 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
$transfers = [ ];
$query = Transfer::find ();
$query->innerJoin("user_sold_item","user_sold_item.id_transfer = transfer.id_transfer");
$query->innerJoinWith ( 'userSoldItem' );
// $query->innerJoinWith ( 'userSoldItem' );
if ( Helper::isUserCartVisibilityUser()){
$query->andWhere ( [
'user_sold_item.id_user' => $user->id
@@ -942,6 +943,7 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
}
}
public function payout() {
if ($this->status != Transfer::STATUS_NOT_PAID) {
return false;
}
@@ -949,14 +951,18 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
$this->status = Transfer::STATUS_PAID;
$this->paid_at = Helper::getDateTimeString ();
$this->paid_by = \Yii::$app->user->id;
ShoppingCart::deleteAll ( [
'id_transfer' => $this->id_transfer
] );
UserSoldItem::deleteAll ( [
'id_transfer' => $this->id_transfer
if( Helper::isUserCartVisibilityAll() ){
$this->id_account = Account::readDefault();
}
ShoppingCart::deleteAll ( [ 'id_transfer' => $this->id_transfer ] );
UserSoldItem::deleteAll ( [ 'id_transfer' => $this->id_transfer
] );
return $this->save ();
}
public static function payoutAll($id_user, $id_array) {
ShoppingCart::deleteAll ( [
'in',
@@ -968,24 +974,29 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
'id_transfer',
$id_array
] );
Transfer::updateAll ( [
'status' => Transfer::STATUS_PAID,
'paid_at' => Helper::getDateTimeString (),
'paid_by' => $id_user
], [
[
'in',
'id_transfer',
$id_array
],
[
'in',
'status',
[
Transfer::STATUS_NOT_PAID
]
]
] );
$updateConfig = null;
if ( Helper::isUserCartVisibilityUser() ){
$updateConfig = [
'status' => Transfer::STATUS_PAID,
'paid_at' => Helper::getDateTimeString (),
'paid_by' => $id_user
];
}else{
$updateConfig = [
'status' => Transfer::STATUS_PAID,
'paid_at' => Helper::getDateTimeString (),
'paid_by' => $id_user,
'id_account' => Account::readDefault(),
];
}
$updateConditions = [
[ 'in','id_transfer', $id_array ],
[ 'in', 'status', [ Transfer::STATUS_NOT_PAID ] ]
];
Transfer::updateAll ( $updateConfig , $updateConditions );
}
/**

View File

@@ -99,8 +99,12 @@ class UserSoldItem extends \yii\db\ActiveRecord
if ( isset($account)){
$sql .= " , id_account = " . $account;
}else if ( Helper::isUserCartVisibilityAll() ){
$sql .= " , id_account = " . Account::readDefault();
}
$sql .= " WHERE t.status = " . Transfer::STATUS_NOT_PAID;
//we can see all transfer in cart, or just our