@@ -282,10 +282,8 @@ public function cancelRegistration(User $user, string $state, User|null $created
282
282
283
283
if ($ newApplication ->getPayment () !== null ) {
284
284
if ($ newApplication ->getPayment ()->getPairedValidApplications ()->count () === 1 ) {
285
- $ newApplication ->getPayment ()->setState (PaymentState::NOT_PAIRED_CANCELED );
285
+ $ newApplication ->getPayment ()->setState (PaymentState::PAIRED_CANCELED );
286
286
}
287
-
288
- $ newApplication ->setPayment (null );
289
287
}
290
288
291
289
$ this ->applicationRepository ->save ($ newApplication );
@@ -448,10 +446,8 @@ public function cancelSubeventsApplication(SubeventsApplication $application, st
448
446
449
447
if ($ newApplication ->getPayment () !== null ) {
450
448
if ($ newApplication ->getPayment ()->getPairedValidApplications ()->count () === 1 ) {
451
- $ newApplication ->getPayment ()->setState (PaymentState::NOT_PAIRED_CANCELED );
449
+ $ newApplication ->getPayment ()->setState (PaymentState::PAIRED_CANCELED );
452
450
}
453
-
454
- $ newApplication ->setPayment (null );
455
451
}
456
452
457
453
$ this ->applicationRepository ->save ($ newApplication );
@@ -568,17 +564,9 @@ public function createPayment(
568
564
$ pairedApplication = $ this ->applicationRepository ->findValidByVariableSymbol ($ variableSymbol );
569
565
570
566
if ($ pairedApplication ) {
571
- if (
572
- $ pairedApplication ->getState () === ApplicationState::PAID ||
573
- $ pairedApplication ->getState () === ApplicationState::PAID_FREE ||
574
- $ pairedApplication ->getState () === ApplicationState::PAID_TRANSFERED
575
- ) {
567
+ if ($ pairedApplication ->isPaid ()) {
576
568
$ payment ->setState (PaymentState::NOT_PAIRED_PAID );
577
- } elseif (
578
- $ pairedApplication ->getState () === ApplicationState::CANCELED ||
579
- $ pairedApplication ->getState () === ApplicationState::CANCELED_NOT_PAID ||
580
- $ pairedApplication ->getState () === ApplicationState::CANCELED_TRANSFERED
581
- ) {
569
+ } elseif ($ pairedApplication ->isCanceled ()) {
582
570
$ payment ->setState (PaymentState::NOT_PAIRED_CANCELED );
583
571
} elseif (abs ($ pairedApplication ->getFee () - $ amount ) >= 0.01 ) {
584
572
$ payment ->setState (PaymentState::NOT_PAIRED_FEE );
@@ -812,39 +800,47 @@ public function transferRegistration(User $sourceUser, User $targetUser, User $c
812
800
$ targetUserPaidSubevents = $ targetUser ->getPaidSubevents ();
813
801
814
802
// přidání zaplacených podakcí od zdrojového uživatele (kromě podakcí nekompatibilních s jeho stávajícími)
815
- /** @var ArrayCollection<int, Subevent> $targetSubevents */
816
- $ targetSubevents = new ArrayCollection ();
803
+ /** @var ArrayCollection<int, Subevent> $addSubevents */
804
+ $ addSubevents = new ArrayCollection ();
817
805
foreach ($ sourceUserPaidSubevents as $ subevent ) {
818
- if (! $ targetSubevents ->contains ($ subevent )) {
806
+ if (! $ addSubevents ->contains ($ subevent )) {
819
807
foreach ($ subevent ->getIncompatibleSubevents () as $ incompatibleSubevent ) {
820
808
if ($ targetUserPaidSubevents ->contains ($ incompatibleSubevent )) {
821
809
continue 2 ;
822
810
}
823
811
}
824
812
825
- $ targetSubevents ->add ($ subevent );
813
+ $ addSubevents ->add ($ subevent );
826
814
}
827
815
}
828
816
817
+ $ addSubeventsFiltered = clone $ addSubevents ;
818
+
829
819
// odebrání podakcí, které už cílový uživatel má, ale budou mu přidány převodem
830
820
foreach ($ targetUser ->getNotCanceledSubeventsApplications () as $ application ) {
831
- $ remainingSubevents = new ArrayCollection ();
821
+ if ($ application ->isPaid ()) {
822
+ foreach ($ application ->getSubevents () as $ subevent ) {
823
+ $ addSubeventsFiltered ->removeElement ($ subevent );
824
+ }
825
+ } else {
826
+ $ remainingApplicationSubevents = new ArrayCollection ();
832
827
833
- foreach ($ application ->getSubevents () as $ subevent ) {
834
- if (! $ targetSubevents ->contains ($ subevent )) {
835
- $ remainingSubevents ->add ($ subevent );
828
+ foreach ($ application ->getSubevents () as $ subevent ) {
829
+ if (! $ addSubevents ->contains ($ subevent )) {
830
+ $ remainingApplicationSubevents ->add ($ subevent );
831
+ }
836
832
}
837
- }
838
833
839
- if ($ remainingSubevents ->isEmpty ()) {
840
- $ this ->cancelSubeventsApplication ($ application , ApplicationState::CANCELED , $ createdBy );
841
- } else {
842
- $ this ->updateSubeventsApplication ($ application , $ remainingSubevents , $ createdBy );
834
+ if ($ remainingApplicationSubevents ->isEmpty ()) {
835
+ $ this ->cancelSubeventsApplication ($ application , ApplicationState::CANCELED , $ createdBy );
836
+ } else {
837
+ $ this ->updateSubeventsApplication ($ application , $ remainingApplicationSubevents , $ createdBy );
838
+ }
843
839
}
844
840
}
845
841
846
842
$ this ->updateRoles ($ targetUser , $ targetRoles , $ createdBy , false , true );
847
- $ this ->addSubeventsApplication ($ targetUser , $ targetSubevents , $ createdBy , true );
843
+ $ this ->addSubeventsApplication ($ targetUser , $ addSubeventsFiltered , $ createdBy , true );
848
844
849
845
$ this ->cancelRegistration ($ sourceUser , ApplicationState::CANCELED_TRANSFERED , $ createdBy );
850
846
});
0 commit comments