improve customer timetable
This commit is contained in:
@@ -10,8 +10,8 @@ use common\models\EventRegistration;
|
||||
use common\models\Ticket;
|
||||
use customerapi\models\available\EventInterval;
|
||||
use customerapi\models\registrations\EventRegistrationAvailable;
|
||||
use customerapi\models\details\EventRegistrationView;
|
||||
use Exception;
|
||||
use Throwable;
|
||||
use Yii;
|
||||
use yii\base\BaseObject;
|
||||
use yii\db\ActiveRecord;
|
||||
@@ -37,6 +37,7 @@ class EventRegistrationManager extends BaseObject
|
||||
const UNKNOWN_ERROR = 7;
|
||||
const MAX_SEAT_COUNT_EXCEEDED = 8;
|
||||
const EVENT_UNAVAILABLE = 9;
|
||||
const ALREADY_REGISTERED = 10;
|
||||
|
||||
public static $STATES = [
|
||||
self::CARD_NOT_FOUND => 'CARD_NOT_FOUND',
|
||||
@@ -48,8 +49,7 @@ class EventRegistrationManager extends BaseObject
|
||||
self::UNKNOWN_ERROR => 'UNKNOWN_ERROR',
|
||||
self::MAX_SEAT_COUNT_EXCEEDED => 'MAX_SEAT_COUNT_EXCEEDED',
|
||||
self::EVENT_UNAVAILABLE => 'EVENT_UNAVAILABLE',
|
||||
|
||||
|
||||
self::ALREADY_REGISTERED => 'ALREADY_REGISTERED',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -77,7 +77,7 @@ class EventRegistrationManager extends BaseObject
|
||||
|
||||
$activeTickets = $card->getActiveTickets();
|
||||
if (count($activeTickets) === 0) {
|
||||
throw new NotFoundHttpException('Ticket not found', self::TICKET_NOT_FOUND);
|
||||
throw new NotFoundHttpException('Ticket not found1', self::TICKET_NOT_FOUND);
|
||||
}
|
||||
|
||||
/** @var Event $event */
|
||||
@@ -101,24 +101,23 @@ class EventRegistrationManager extends BaseObject
|
||||
}
|
||||
|
||||
//detect if customer is already registered to event
|
||||
/** @var EventRegistration[] $registrations */
|
||||
$registrations = $event->getActiveEventRegistrations()->all();
|
||||
|
||||
foreach ($registrations as $registration ){
|
||||
if ($registration->customer_id == $card->customer->id_customer){
|
||||
throw new BadRequestHttpException("Already registered");
|
||||
if ($registration->id_customer == $card->customer->id_customer){
|
||||
throw new BadRequestHttpException("Already registered", self::ALREADY_REGISTERED);
|
||||
}
|
||||
}
|
||||
|
||||
$selectedTicket = $eventType->findTicketAllowingEventType($activeTickets);
|
||||
|
||||
|
||||
if (!isset($selectedTicket)) {
|
||||
throw new NotFoundHttpException('Ticket not found', self::TICKET_INSUFFICIENT);
|
||||
throw new NotFoundHttpException('Ticket not found2', self::TICKET_INSUFFICIENT);
|
||||
}
|
||||
|
||||
if ($selectedTicket->hasOpenReservationCount()) {
|
||||
$selectedTicket->consumeReservationCount(1);
|
||||
}
|
||||
$selectedTicket->consumeReservationCount(1);
|
||||
|
||||
$selectedTicket->save();
|
||||
|
||||
$registration = new EventRegistration();
|
||||
|
||||
@@ -83,4 +83,56 @@ class EventRegistration extends \yii\db\ActiveRecord
|
||||
public function getCustomerClass(){
|
||||
return Customer::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param EventRegistration $eventRegistration
|
||||
*/
|
||||
public static function isActive($eventRegistration){
|
||||
if ( !isset($eventRegistration ) ){
|
||||
return false;
|
||||
}
|
||||
if ( isset($eventRegistration->canceled_at ) ){
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( isset($eventRegistration->deleted_at ) ){
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param EventRegistration $eventRegistration
|
||||
*/
|
||||
public static function isForCustomer($eventRegistration,$idCustomer){
|
||||
if ( !isset($eventRegistration ) ){
|
||||
return false;
|
||||
}
|
||||
if ( !isset($eventRegistration->id_customer ) ){
|
||||
return false;
|
||||
}
|
||||
|
||||
return $eventRegistration->id_customer == $idCustomer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param EventRegistration[] $eventRegistrations
|
||||
*/
|
||||
public static function filterActive($eventRegistrations){
|
||||
return array_filter($eventRegistrations, EventRegistration::class.'::isActive' );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param EventRegistration[] $eventRegistrations
|
||||
*/
|
||||
public static function filterForCustomer($eventRegistrations,$idCustomer){
|
||||
$result = [];
|
||||
foreach ($eventRegistrations as $eventRegistration){
|
||||
if ( EventRegistration::isForCustomer($eventRegistration,$idCustomer)){
|
||||
$result[] = $eventRegistration;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ class Ticket extends \common\models\BaseFitnessActiveRecord
|
||||
const STATUS_DELETED = 0;
|
||||
const STATUS_ACTIVE = 10;
|
||||
const STATUS_INACTIVE = 20;
|
||||
|
||||
|
||||
public static $SQL_UPDATE = "UPDATE card as c1
|
||||
left JOIN ( select ticket.id_card as id_card , max(ticket.id_ticket) as id_ticket
|
||||
from ticket
|
||||
@@ -68,7 +68,7 @@ class Ticket extends \common\models\BaseFitnessActiveRecord
|
||||
, c1.flag = case when c1.type = 50 then ( c1.flag & ~(1 << 0) ) when t.id_card is null then ( c1.flag | 1 << 0 ) else ( c1.flag & ~(1 << 0) ) end
|
||||
, c1.id_ticket_current = case when t.id_ticket is null then null else t.id_ticket end
|
||||
where c1.status = 10";
|
||||
|
||||
|
||||
public static $SQL_UPDATE_CARD = "UPDATE card as c1
|
||||
left JOIN ( select ticket.id_card as id_card , max(ticket.id_ticket) as id_ticket
|
||||
from ticket
|
||||
@@ -141,11 +141,11 @@ class Ticket extends \common\models\BaseFitnessActiveRecord
|
||||
[['start', 'end', 'created_at', 'updated_at'], 'safe'],
|
||||
[['comment'], 'required'],
|
||||
[['comment'], 'string', 'max' => 255],
|
||||
|
||||
|
||||
[[ 'start', ], 'date' , 'timestampAttribute' => 'timestampStart' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ],
|
||||
[[ 'end' , ], 'date' , 'timestampAttribute' => 'timestampEnd' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ],
|
||||
|
||||
|
||||
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
@@ -176,12 +176,12 @@ class Ticket extends \common\models\BaseFitnessActiveRecord
|
||||
'original_end' => Yii::t('common/transfer', 'Eredeti érvényesség vége'),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function getCard(){
|
||||
return $this->hasOne( Card::className(), ["id_card" =>"id_card" ] );
|
||||
}
|
||||
|
||||
|
||||
public function getContract(){
|
||||
return $this->hasOne( Contract::className(), ["id_contract" =>"id_contract" ] );
|
||||
}
|
||||
@@ -189,7 +189,7 @@ class Ticket extends \common\models\BaseFitnessActiveRecord
|
||||
public function getTransfer(){
|
||||
return $this->hasOne( Transfer::className(), ["id_object" =>"id_ticket"] )->andWhere(['transfer.type' => Transfer::TYPE_TICKET]);
|
||||
}
|
||||
|
||||
|
||||
public function getCardNumber(){
|
||||
$result = "";
|
||||
/** @noinspection PhpUndefinedFieldInspection */
|
||||
@@ -199,11 +199,11 @@ class Ticket extends \common\models\BaseFitnessActiveRecord
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
public function getCustomer(){
|
||||
return $this->hasOne( Customer::className(), ["id_customer_card" =>"id_card" ] )->via('card');
|
||||
}
|
||||
|
||||
|
||||
public function getCustomerName(){
|
||||
$result = "";
|
||||
/** @noinspection PhpUndefinedFieldInspection */
|
||||
@@ -217,14 +217,14 @@ class Ticket extends \common\models\BaseFitnessActiveRecord
|
||||
public function getUser(){
|
||||
return $this->hasOne( User::className(), ["id" =>"id_user" ] );
|
||||
}
|
||||
|
||||
|
||||
public function getTicketType(){
|
||||
return $this->hasOne( TicketType::className(), ["id_ticket_type" =>"id_ticket_type" ] );
|
||||
}
|
||||
public function getDiscount(){
|
||||
return $this->hasOne( Discount::className(), ["id_discount" =>"id_discount" ] );
|
||||
}
|
||||
|
||||
|
||||
public function getAccount() {
|
||||
return $this->hasOne ( Account::className (), [
|
||||
'id_account' => 'id_account'
|
||||
@@ -277,10 +277,10 @@ class Ticket extends \common\models\BaseFitnessActiveRecord
|
||||
* @return array|\yii\db\ActiveRecord[]
|
||||
*/
|
||||
public static function readActive($card, $validOnDay = null){
|
||||
|
||||
|
||||
if ( $card == null )
|
||||
return [];
|
||||
|
||||
|
||||
$query = Ticket::find();
|
||||
if (!isset( $validOnDay ) ){
|
||||
$today = date('Y-m-d');
|
||||
@@ -292,11 +292,11 @@ class Ticket extends \common\models\BaseFitnessActiveRecord
|
||||
$query->andWhere( 'ticket.start <= :today' ,[ 'today' => $today] );
|
||||
$query->andWhere( 'ticket.end >= :today' ,[ 'today' => $today] );
|
||||
$query->andWhere( 'ticket.status = :status' ,[ 'status' => Ticket::STATUS_ACTIVE] );
|
||||
$query->orderBy([ "ticket.created_at" =>SORT_DESC] );
|
||||
$query->orderBy([ "ticket.created_at" =>SORT_DESC] );
|
||||
$result = $query->all();
|
||||
|
||||
return $result;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -305,10 +305,10 @@ class Ticket extends \common\models\BaseFitnessActiveRecord
|
||||
* @return array|\yii\db\ActiveRecord[]
|
||||
*/
|
||||
public static function readUnpaid($card){
|
||||
|
||||
|
||||
if ( $card == null )
|
||||
return [];
|
||||
|
||||
|
||||
$query = Ticket::find();
|
||||
$query->innerJoin("transfer", "transfer.id_object = ticket.id_ticket ");
|
||||
$today = date('Y-m-d');
|
||||
@@ -320,39 +320,39 @@ class Ticket extends \common\models\BaseFitnessActiveRecord
|
||||
$query->andWhere( ["transfer.type" => Transfer::TYPE_TICKET] );
|
||||
$query->andWhere( [ "transfer.status" => Transfer::STATUS_NOT_PAID ]);
|
||||
$query->orderBy([ "ticket.created_at" =>SORT_DESC] );
|
||||
|
||||
|
||||
$result = $query->all();
|
||||
|
||||
return $result;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static function mkStatisticQuery($start,$end,$id_card = null){
|
||||
|
||||
|
||||
|
||||
|
||||
$query = new Query();
|
||||
$query->addSelect( [
|
||||
new Expression( 'ticket_type.id_ticket_type as id'),
|
||||
new Expression( 'ticket_type.name as name'),
|
||||
new Expression( 'coalesce( count(ticket.id_ticket),0) as total'),
|
||||
|
||||
|
||||
new Expression( "coalesce( sum( case when ticket.status <> " .Ticket::STATUS_DELETED ." AND ". Helper::sqlValidRule('ticket.start', 'ticket.end', ':start', ':end') . " then 1 else 0 end) , 0) as valid" ), //valid
|
||||
new Expression( "coalesce( sum( case when ticket.status <> " .Ticket::STATUS_DELETED ." AND ". Helper::sqlInIntervalRule('ticket.created_at', ':start', ':end') . " then 1 else 0 end) , 0) as created" ),//created
|
||||
new Expression( "coalesce( sum( case when ticket.status <> " .Ticket::STATUS_DELETED ." AND ". Helper::sqlInIntervalRule('ticket.created_at', ':start', ':end') . " then transfer.money else 0 end) , 0) as created_money" ),//created_money
|
||||
new Expression( "coalesce( sum( case when ticket.status <> " .Ticket::STATUS_DELETED ." AND " . Helper::sqlExpireRule('ticket.start', 'ticket.end', ':start', ":end") . " then 1 else 0 end) , 0) as expired" ),
|
||||
|
||||
|
||||
|
||||
|
||||
]);
|
||||
|
||||
|
||||
$query->from('ticket_type');
|
||||
$query->innerJoin('ticket', 'ticket.id_ticket_type = ticket_type.id_ticket_type');
|
||||
$query->innerJoin('transfer', 'ticket.id_ticket = transfer.id_object and transfer.type = '. Transfer::TYPE_TICKET );
|
||||
|
||||
|
||||
Helper::queryAccountConstraint($query, 'ticket.id_account');
|
||||
|
||||
|
||||
$query->andFilterWhere(['id_card' =>$id_card]);
|
||||
|
||||
|
||||
$query->andWhere(
|
||||
[
|
||||
'or',
|
||||
@@ -361,23 +361,23 @@ class Ticket extends \common\models\BaseFitnessActiveRecord
|
||||
Helper::queryExpireRule('ticket.start', 'ticket.end', $start, $end),
|
||||
]
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
$query->groupBy("ticket_type.id_ticket_type, ticket_type.name");
|
||||
|
||||
|
||||
$query->params([':start' => $start, ':end' => $end]);
|
||||
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
|
||||
public static function statuses( ) {
|
||||
return [
|
||||
Ticket::STATUS_ACTIVE => 'Aktív',
|
||||
Ticket::STATUS_DELETED => 'Törölve',
|
||||
Ticket::STATUS_INACTIVE => 'Inaktív',
|
||||
Ticket::STATUS_ACTIVE => 'Aktív',
|
||||
Ticket::STATUS_DELETED => 'Törölve',
|
||||
Ticket::STATUS_INACTIVE => 'Inaktív',
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public static function toStatusName($id_status){
|
||||
$result = "Ismeretlen";
|
||||
$statuses = Ticket::statuses();
|
||||
@@ -386,23 +386,23 @@ class Ticket extends \common\models\BaseFitnessActiveRecord
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
public function getStatusName(){
|
||||
return static::toStatusName($this->status);
|
||||
}
|
||||
|
||||
|
||||
public function isDeleted(){
|
||||
return $this->status == Ticket::STATUS_DELETED;
|
||||
}
|
||||
|
||||
|
||||
/**csoportos beszedéses a bérlet*/
|
||||
public function isInstallmentTicket(){
|
||||
return ( isset($this->part_count) && $this->part_count > 0 );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Apply request
|
||||
*
|
||||
*
|
||||
* @var \common\models\TicketInstallmentRequest $request megbízás
|
||||
* */
|
||||
public function applyTicketInstallmentRequest( $request ) {
|
||||
@@ -414,12 +414,12 @@ class Ticket extends \common\models\BaseFitnessActiveRecord
|
||||
}
|
||||
$this->recalclulate();
|
||||
}else if ( $request->isStatusRejected() ){
|
||||
$this->status = static::STATUS_INACTIVE;
|
||||
$this->status = static::STATUS_INACTIVE;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* *
|
||||
* *
|
||||
* @param common\models\TicketInstallmentRequest $request megbízás
|
||||
*/
|
||||
public function setPartRequired($request){
|
||||
@@ -431,7 +431,7 @@ class Ticket extends \common\models\BaseFitnessActiveRecord
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Csoportos beszedéses bérlet érvényességének újraszámolása
|
||||
* */
|
||||
@@ -457,7 +457,7 @@ class Ticket extends \common\models\BaseFitnessActiveRecord
|
||||
public function consumeReservationCount($count){
|
||||
$newReservationCount = $this->reservation_count + $count;
|
||||
if ( $newReservationCount > $this->max_reservation_count ){
|
||||
throw new HttpException(406, 'Max ticket seat count exceeded',EventRegistrationManager::MAX_SEAT_COUNT_EXCEEDED);
|
||||
throw new HttpException(400, 'Max ticket seat count exceeded',EventRegistrationManager::MAX_SEAT_COUNT_EXCEEDED);
|
||||
}
|
||||
$this->reservation_count = $newReservationCount;
|
||||
}
|
||||
@@ -473,7 +473,7 @@ class Ticket extends \common\models\BaseFitnessActiveRecord
|
||||
public function afterSave($insert, $changedAttributes) {
|
||||
Card::updateCardFlagTicket($this->id_card);;
|
||||
}
|
||||
|
||||
|
||||
public function afterDelete(){
|
||||
Card::updateCardFlagTicket($this->id_card);;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user