Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions app/HMS/Entities/Banking/Account.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?php

namespace HMS\Entities\Banking;

class Account
{
/**
* @var int
*/
protected $id;

/**
* @var string
*/
protected $paymentRef;

/**
* @var string
*/
protected $natwestRef;

/**
* @var \HMS\Entities\User
*/
protected $users;

/**
* @param string $paymentRef
*/
public function __construct($paymentRef)
{
$this->paymentRef = $paymentRef;
$this->users = new ArrayCollection();
}

/**
* Gets the value of id.
*
* @return mixed
*/
public function getId()
{
return $this->id;
}

/**
* Gets the value of paymentRef.
*
* @return mixed
*/
public function getPaymentRef()
{
return $this->paymentRef;
}

/**
* Sets the value of paymentRef.
*
* @param mixed $paymentRef the payment ref
*
* @return self
*/
protected function setPaymentRef($paymentRef)
{
$this->paymentRef = $paymentRef;

return $this;
}

/**
* Gets the value of natwestRef.
*
* @return mixed
*/
public function getNatwestRef()
{
return $this->natwestRef;
}

/**
* Gets the value of users.
*
* @return \HMS\Entities\User
*/
public function getUsers()
{
return $this->users;
}

/**
* Sets the value of users.
*
* @param \HMS\Entities\User $users the users
*
* @return self
*/
public function setUsers(\HMS\Entities\User $users)
{
$this->users = $users;

return $this;
}
}
18 changes: 9 additions & 9 deletions app/HMS/Entities/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function setJoinDate(Carbon $joinDate)
/**
* @return string
*/
public function getUnlockText(): string
public function getUnlockText()
{
return $this->unlockText;
}
Expand Down Expand Up @@ -136,7 +136,7 @@ public function setCreditLimit(int $creditLimit)
/**
* @return string
*/
public function getAddress1(): string
public function getAddress1()
{
return $this->address1;
}
Expand All @@ -155,7 +155,7 @@ public function setAddress1(string $address1)
/**
* @return string
*/
public function getAddress2(): string
public function getAddress2()
{
return $this->address2;
}
Expand All @@ -174,7 +174,7 @@ public function setAddress2(string $address2)
/**
* @return string
*/
public function getAddress3(): string
public function getAddress3()
{
return $this->address3;
}
Expand All @@ -193,7 +193,7 @@ public function setAddress3(string $address3)
/**
* @return string
*/
public function getAddressCity(): string
public function getAddressCity()
{
return $this->addressCity;
}
Expand All @@ -212,7 +212,7 @@ public function setAddressCity(string $addressCity)
/**
* @return string
*/
public function getAddressCounty(): string
public function getAddressCounty()
{
return $this->addressCounty;
}
Expand All @@ -231,7 +231,7 @@ public function setAddressCounty(string $addressCounty)
/**
* @return string
*/
public function getAddressPostcode(): string
public function getAddressPostcode()
{
return $this->addressPostcode;
}
Expand All @@ -250,7 +250,7 @@ public function setAddressPostcode(string $addressPostcode)
/**
* @return string
*/
public function getContactNumber(): string
public function getContactNumber()
{
return $this->contactNumber;
}
Expand All @@ -271,7 +271,7 @@ public function setContactNumber(string $contactNumber)
*/
public function getDateOfBirth()
{
return $this->dateOfBirth;
return Carbon::instance($this->dateOfBirth);
}

/**
Expand Down
27 changes: 26 additions & 1 deletion app/HMS/Entities/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace HMS\Entities;

use HMS\Entities\Banking\Account;
use HMS\Traits\Entities\SoftDeletable;
use HMS\Traits\Entities\Timestampable;
use LaravelDoctrine\ACL\Roles\HasRoles;
Expand Down Expand Up @@ -62,6 +63,11 @@ class User implements AuthenticatableContract, CanResetPasswordContract, HasRole
*/
protected $profile;

/**
* @var Account|null
*/
protected $account;

/**
* User constructor.
* @param string $firstname
Expand Down Expand Up @@ -205,7 +211,7 @@ public function getPermissions()
}

/**
* @return Profile The users profile
* @return Profile|null The users profile
*/
public function getProfile() : Profile
{
Expand All @@ -222,4 +228,23 @@ public function setProfile(Profile $profile)

return $this;
}

/**
* @return Account The users account
*/
public function getAccount() : Account
{
return $this->account;
}

/**
* @param Account $account
* @return self
*/
public function setAccount(Account $account)
{
$this->account = $account;

return $this;
}
}
70 changes: 70 additions & 0 deletions app/HMS/Factories/Banking/AccountFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

namespace HMS\Factories\Banking;

use HMS\Entities\Banking\Account;
use HMS\Repositories\Banking\AccountRepository;

class AccountFactory
{
/**
* @var AccountRepository
*/
protected $accountRepository;

/**
* @param AccountRepository $accountRepository
*/
public function __construct(AccountRepository $accountRepository)
{
$this->accountRepository = $accountRepository;
}

/**
* Create a new Account with a unique payment refrence.
* @return Account
*/
public function createNewAccount()
{
// TODOL: generate new
return new Account($this->generateUniquePaymentRef());
}

/**
* Generate a payment reference.
*
* @return string A unique (at the time of function-call) payment reference.
*/
protected static function generatePaymentRef()
{
// Payment ref is a randomly generates string of 'safechars'
// Stolen from London Hackspace code
$safeChars = '2346789BCDFGHJKMPQRTVWXY';
// We prefix the ref with a string that lets people know it's us
$prefix = 'HSNTSB';
// Payment references can be up to 18 chars according to: http://www.bacs.co.uk/Bacs/Businesses/BacsDirectCredit/Receiving/Pages/PaymentReferenceInformation.aspx
$maxRefLength = 16;
$paymentRef = $prefix;
for ($i = strlen($prefix); $i < $maxRefLength; $i++) {
$paymentRef .= $safeChars[rand(0, strlen($safeChars) - 1)];
}

return $paymentRef;
}

/**
* Generate a unique payment reference.
*
* @return string A unique (at the time of function-call) payment reference.
* @link http://www.bacs.co.uk/Bacs/Businesses/BacsDirectCredit/Receiving/Pages/PaymentReferenceInformation.aspx
*/
protected function generateUniquePaymentRef()
{
$paymentRef = '';
do {
$paymentRef = $this->generatePaymentRef();
} while ($this->accountRepository->findOneByPaymentRef($paymentRef) !== null);

return $paymentRef;
}
}
28 changes: 28 additions & 0 deletions app/HMS/Mappings/HMS.Entities.Banking.Account.dcm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# HMS.Entities.Banking.Account.dcm.yml
HMS\Entities\Banking\Account:
type: entity
repositoryClass: HMS\Repositories\Banking\AccountRepository
table: accounts
indexes:
payment_ref_index:
columns: [ payment_ref ]
id:
id:
type: integer
options:
unsigned: true
generator:
strategy: AUTO
fields:
paymentRef:
type: string
length: 18
unique: true
natwestRef:
type: string
length: 18
nullable: true
oneToMany:
users:
targetEntity: \HMS\Entities\User
mappedBy: account
7 changes: 7 additions & 0 deletions app/HMS/Mappings/HMS.Entities.User.dcm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ HMS\Entities\User:
targetEntity: Profile
mappedBy: user
cascade: ["all"]
manyToOne:
account:
targetEntity: \HMS\Entities\Banking\Account
inversedBy: users
joinColumns:
acccount_id:
referencedColumnName: id
manyToMany:
roles:
targetEntity: Role
Expand Down
32 changes: 32 additions & 0 deletions app/HMS/Repositories/Banking/AccountRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace HMS\Repositories\Banking;

use HMS\Entities\Banking\Account;

interface AccountRepository
{
/**
* @param $id
* @return array
*/
public function find($id);

/**
* @param string $paymentRef
* @return array
*/
public function findOneByPaymentRef(string $paymentRef);

/**
* @param string $paymentRef
* @return array
*/
public function findLikeByPaymentRef(string $paymentRef);

/**
* save Account to the DB.
* @param Account $account
*/
public function save(Account $account);
}
Loading