-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e8efe00
commit 3b9fccf
Showing
14 changed files
with
482 additions
and
27 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
application/YoshiKan/Application/Command/Member/ChangeLicense/ChangeLicense.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Yoshi-Kan software. | ||
* | ||
* (c) Koen Caerels | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\YoshiKan\Application\Command\Member\ChangeLicense; | ||
|
||
class ChangeLicense | ||
{ | ||
// ————————————————————————————————————————————————————————————————————————— | ||
// Constructor | ||
// ————————————————————————————————————————————————————————————————————————— | ||
|
||
private function __construct( | ||
protected int $memberId, | ||
protected int $federationId, | ||
) { | ||
} | ||
|
||
// ————————————————————————————————————————————————————————————————————————— | ||
// Hydrate from a json command | ||
// ————————————————————————————————————————————————————————————————————————— | ||
|
||
public static function hydrateFromJson(\stdClass $json): self | ||
{ | ||
return new self( | ||
$json->memberId, | ||
$json->federationId, | ||
); | ||
} | ||
|
||
// ————————————————————————————————————————————————————————————————————————— | ||
// Getters | ||
// ————————————————————————————————————————————————————————————————————————— | ||
|
||
public function getMemberId(): int | ||
{ | ||
return $this->memberId; | ||
} | ||
|
||
public function getFederationId(): int | ||
{ | ||
return $this->federationId; | ||
} | ||
} |
145 changes: 145 additions & 0 deletions
145
application/YoshiKan/Application/Command/Member/ChangeLicense/ChangeLicenseHandler.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Yoshi-Kan software. | ||
* | ||
* (c) Koen Caerels | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\YoshiKan\Application\Command\Member\ChangeLicense; | ||
|
||
use App\YoshiKan\Application\Command\Common\SubscriptionItemsFactory; | ||
use App\YoshiKan\Application\Query\Member\Readmodel\SettingsReadModel; | ||
use App\YoshiKan\Domain\Model\Member\MemberRepository; | ||
use App\YoshiKan\Domain\Model\Member\SettingsCode; | ||
use App\YoshiKan\Domain\Model\Member\Subscription; | ||
use App\YoshiKan\Domain\Model\Member\SubscriptionItemRepository; | ||
use App\YoshiKan\Domain\Model\Member\SubscriptionStatus; | ||
use App\YoshiKan\Domain\Model\Member\SubscriptionType; | ||
use App\YoshiKan\Infrastructure\Database\Member\FederationRepository; | ||
use App\YoshiKan\Infrastructure\Database\Member\LocationRepository; | ||
use App\YoshiKan\Infrastructure\Database\Member\SettingsRepository; | ||
use App\YoshiKan\Infrastructure\Database\Member\SubscriptionRepository; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
|
||
class ChangeLicenseHandler | ||
{ | ||
// ——————————————————————————————————————————————————————————————— | ||
// Constructor | ||
// ——————————————————————————————————————————————————————————————— | ||
|
||
public function __construct( | ||
protected MemberRepository $memberRepository, | ||
protected SubscriptionRepository $subscriptionRepository, | ||
protected SubscriptionItemRepository $subscriptionItemRepository, | ||
protected FederationRepository $federationRepository, | ||
protected LocationRepository $locationRepository, | ||
protected SettingsRepository $settingsRepository, | ||
protected EntityManagerInterface $entityManager, | ||
) { | ||
} | ||
|
||
// ——————————————————————————————————————————————————————————————— | ||
// Handle | ||
// ——————————————————————————————————————————————————————————————— | ||
|
||
public function change(ChangeLicense $command): \stdClass | ||
{ | ||
$member = $this->memberRepository->getById($command->getMemberId()); | ||
$federation = $this->federationRepository->getById($command->getFederationId()); | ||
$settings = $this->settingsRepository->findByCode(SettingsCode::ACTIVE->value); | ||
|
||
$extraTraining = false; | ||
if (3 === $member->getNumberOfTraining()) { | ||
$extraTraining = true; | ||
} | ||
|
||
// -- calculate the new license dates ------------------------------- | ||
|
||
$now = new \DateTimeImmutable(); | ||
$licenseStart = $now->setDate((int) $now->format('Y'), (int) $now->format('m'), 1); | ||
$licenseEnd = $licenseStart->modify('+1 year'); | ||
|
||
// -- create a new subscription ------------------------------------- | ||
|
||
$subscription = Subscription::make( | ||
$this->subscriptionRepository->nextIdentity(), | ||
$member->getContactFirstname(), | ||
$member->getContactLastname(), | ||
$member->getContactEmail(), | ||
$member->getContactPhone(), | ||
$member->getFirstname(), | ||
$member->getLastname(), | ||
$member->getDateOfBirth(), | ||
$member->getGender(), | ||
SubscriptionType::RENEWAL_LICENSE, | ||
$member->getNumberOfTraining(), | ||
$extraTraining, | ||
false, | ||
false, | ||
false, | ||
'Wijziging vergunning naar '.$federation->getName(), | ||
$member->getLocation(), | ||
json_decode(json_encode(SettingsReadModel::hydrateFromModel($settings)), true), | ||
$federation, | ||
$member->getMemberSubscriptionStart(), | ||
$member->getMemberSubscriptionEnd(), | ||
0, | ||
false, | ||
false, | ||
true, | ||
$licenseStart, | ||
$licenseEnd, | ||
$federation->getYearlySubscriptionFee(), | ||
true, | ||
false, | ||
); | ||
|
||
$subscription->setMember($member); | ||
$subscription->changeStatus(SubscriptionStatus::AWAITING_PAYMENT); | ||
$subscription->calculate(); | ||
$this->subscriptionRepository->save($subscription); | ||
$this->entityManager->flush(); | ||
|
||
// -- make some subscription lines ---------------------------------- | ||
|
||
$subscriptionItemFactory = new SubscriptionItemsFactory( | ||
$this->subscriptionRepository, | ||
$this->subscriptionItemRepository | ||
); | ||
$resultItems = $subscriptionItemFactory->saveItemsFromSubscription( | ||
$subscription, | ||
$federation, | ||
$settings | ||
); | ||
|
||
// -- flag new dates in the member ---------------------------------- | ||
|
||
$member->setLicenseDates( | ||
$subscription->getLicenseStart(), | ||
$subscription->getLicenseEnd() | ||
); | ||
$member->syncFromSubscription( | ||
federation: $federation, | ||
numberOfTraining: $subscription->getNumberOfTraining(), | ||
isHalfYearSubscription: $subscription->isMemberSubscriptionIsHalfYear(), | ||
); | ||
|
||
$this->memberRepository->save($member); | ||
$this->entityManager->flush(); | ||
|
||
// -- compile a result class ---------------------------------------- | ||
|
||
$subscriptionId = $this->subscriptionRepository->getMaxId(); | ||
$result = new \stdClass(); | ||
$result->id = $subscriptionId; | ||
$result->reference = 'YKS-'.$subscriptionId.': '.$member->getFirstname().' '.$member->getLastName(); | ||
|
||
return $result; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
application/YoshiKan/Application/Command/Member/ChangeLicense/ChangeLicenseTrait.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Yoshi-Kan software. | ||
* | ||
* (c) Koen Caerels | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\YoshiKan\Application\Command\Member\ChangeLicense; | ||
|
||
trait ChangeLicenseTrait | ||
{ | ||
public function changeLicense(\stdClass $jsonCommand): \stdClass | ||
{ | ||
$this->permission->CheckRole(['ROLE_DEVELOPER', 'ROLE_ADMIN', 'ROLE_CHIEF_EDITOR']); | ||
|
||
$command = ChangeLicense::hydrateFromJson($jsonCommand); | ||
$handler = new ChangeLicenseHandler( | ||
memberRepository: $this->memberRepository, | ||
subscriptionRepository: $this->subscriptionRepository, | ||
subscriptionItemRepository: $this->subscriptionItemRepository, | ||
federationRepository: $this->federationRepository, | ||
locationRepository: $this->locationRepository, | ||
settingsRepository: $this->settingsRepository, | ||
entityManager: $this->entityManager, | ||
); | ||
|
||
$result = $handler->change($command); | ||
$this->entityManager->flush(); | ||
|
||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
frontends/member_module/src/api/command/changeMemberLicense.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* This file is part of the Yoshi-Kan software. | ||
* | ||
* (c) Koen Caerels | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
import axios from "axios"; | ||
|
||
export interface ChangeMemberLicenseCommand { | ||
memberId: number; | ||
federationId: number; | ||
} | ||
|
||
export async function changeMemberLicense(command: ChangeMemberLicenseCommand) { | ||
const formData = new FormData(); | ||
formData.append('command', JSON.stringify(command)); | ||
const response= await axios.post<boolean>(`/member/${command.memberId}/change-license`, formData); | ||
return response.data; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.