mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
Merge branch 'import-ambank-cief-lite-statement' of gitlab.com:CIEFWorldwideSdnBhd/exchange-2.0 into import-ambank-cief-lite-statement
# Conflicts: # app/Classes/Modules/Accounting/ControllersLogic/ImportAmbankStatementLogic.php # app/Classes/Modules/Accounting/ControllersLogic/ImportCiefLiteStatementLogic.php # app/Classes/Modules/Accounting/ControllersLogic/UpdateStatementTransactionStatusLogic.php
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Exceptions;
|
||||
|
||||
use App\Classes\ValueObjects\Constants\HttpStatus;
|
||||
|
||||
final class JobResourceNotFoundException extends ServiceApiException {
|
||||
public function __construct(?string $message = null) {
|
||||
parent::__construct($message ?? 'Unable to find the requested resource', HttpStatus::RESOURCE_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\Classes\Exceptions\JobResourceNotFoundException;
|
||||
|
||||
abstract class AbstractControllerLogic
|
||||
{
|
||||
@@ -67,7 +68,19 @@ abstract class AbstractControllerLogic
|
||||
return $response;
|
||||
|
||||
} catch (ErrorException|GeneralExceptions $exception){
|
||||
log::error($exception);
|
||||
if ($exception instanceof JobResourceNotFoundException) {
|
||||
Log::channel('vue_polling')->info(sprintf(
|
||||
"Uncaught exception '%s' with message '%s' in %s:%d",
|
||||
get_class($exception),
|
||||
$exception->getMessage(),
|
||||
$exception->getTrace()[0]['file'],
|
||||
$exception->getTrace()[0]['line']
|
||||
));
|
||||
}
|
||||
else{
|
||||
log::error($exception);
|
||||
}
|
||||
|
||||
return (new ApiResponseObject($this->getNotificationTitle().' failed', $exception->getMessage(),
|
||||
$exception->getCode() ? $exception->getCode() : HttpStatus::SERVER_ERROR))->handler();
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ use App\Classes\General\Interfaces\DataTransferObject;
|
||||
abstract class AbstractRule
|
||||
{
|
||||
|
||||
abstract protected function authorized(): bool;
|
||||
abstract protected function authorized($object): bool;
|
||||
|
||||
abstract protected function validators($object): bool;
|
||||
|
||||
@@ -26,8 +26,8 @@ abstract class AbstractRule
|
||||
*/
|
||||
public function passes(?DataTransferObject $object = null): bool {
|
||||
try {
|
||||
if(!$this->authorized()){
|
||||
throw new AccessForbiddenException('You don\'t have permission to preform this action');
|
||||
if(!$this->authorized($object)){
|
||||
throw new AccessForbiddenException('You don\'t have permission to perform this action');
|
||||
}
|
||||
|
||||
$this->validators($object);
|
||||
@@ -36,11 +36,11 @@ abstract class AbstractRule
|
||||
return true;
|
||||
|
||||
} catch(AccessForbiddenException $exception){
|
||||
throw new AccessForbiddenException('You don\'t have permission to preform this action');
|
||||
throw new AccessForbiddenException('You don\'t have permission to perform this action');
|
||||
} catch(\Exception $exception){
|
||||
throw new RequestValidationException($exception->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,11 @@ namespace App\Classes\General\Eloquent;
|
||||
|
||||
|
||||
use App\Classes\Exceptions\ResourceNotFoundException;
|
||||
use App\Classes\Exceptions\JobResourceNotFoundException;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Psy\Exception\ErrorException;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
abstract class AbstractFetchRecord extends AbstractGetRecord
|
||||
{
|
||||
@@ -27,12 +29,18 @@ abstract class AbstractFetchRecord extends AbstractGetRecord
|
||||
* @return Model
|
||||
* @throws ResourceNotFoundException
|
||||
*/
|
||||
public function getResults(Builder $query): Model {
|
||||
public function getResults(Builder $query, array $param = []): Model {
|
||||
if(!$query->exists()){
|
||||
throw new ResourceNotFoundException('Unable to find any record based on the criteria provided');
|
||||
$table = $query->getModel()->getTable();
|
||||
if($table ==='job_results'){
|
||||
throw new JobResourceNotFoundException('Unable to find any job based on the criteria provided');
|
||||
}
|
||||
else{
|
||||
throw new ResourceNotFoundException('Unable to find any record based on the criteria provided');
|
||||
}
|
||||
}
|
||||
|
||||
return $query->first();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,11 +30,25 @@ abstract class AbstractGetRecord
|
||||
return $this->filters->only(self::DECORATION_FILTERS);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @param null|string $json
|
||||
// * @return array
|
||||
// */
|
||||
// public function deserializeFilters(?string $json): array {
|
||||
// return $json !== null ? collect(json_decode($json))->toArray() : [];
|
||||
// }
|
||||
|
||||
/**
|
||||
* @param null|string $json
|
||||
* @param null|string $param
|
||||
* @return array
|
||||
*/
|
||||
public function deserializeFilters(?string $json): array {
|
||||
public function deserializeFilters($param): array {
|
||||
if(gettype($param) == "array"){
|
||||
$json = implode(',', $param);
|
||||
}
|
||||
else{
|
||||
$json = $param;
|
||||
}
|
||||
return $json !== null ? collect(json_decode($json))->toArray() : [];
|
||||
}
|
||||
|
||||
@@ -50,9 +64,9 @@ abstract class AbstractGetRecord
|
||||
* @param array $filters
|
||||
* @return mixed
|
||||
*/
|
||||
public function handler(array $filters){
|
||||
public function handler(array $filters, array $params = []){
|
||||
$this->filters = collect($filters);
|
||||
return $this->getResults($this->applyFiltersToQuery());
|
||||
return $this->getResults($this->applyFiltersToQuery(), $params);
|
||||
}
|
||||
|
||||
|
||||
@@ -65,6 +79,6 @@ abstract class AbstractGetRecord
|
||||
* @param Builder $query
|
||||
* @return mixed
|
||||
*/
|
||||
abstract function getResults(Builder $query);
|
||||
abstract function getResults(Builder $query, array $params = []);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,11 +17,11 @@ abstract class AbstractListRecord extends AbstractGetRecord
|
||||
* @return mixed
|
||||
* @throws MalformedRequestException
|
||||
*/
|
||||
public function execute(array $filters = []){
|
||||
public function execute(array $filters = [], array $param = []){
|
||||
|
||||
try{
|
||||
|
||||
return $this->handler($filters);
|
||||
return $this->handler($filters, $param);
|
||||
|
||||
} catch (QueryException $exception){
|
||||
log::error($exception);
|
||||
@@ -30,18 +30,24 @@ abstract class AbstractListRecord extends AbstractGetRecord
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Builder $query
|
||||
* @return mixed
|
||||
*/
|
||||
public function getResults(Builder $query) {
|
||||
public function getResults(Builder $query, array $param = []) {
|
||||
$filters = $this->getDecorationFilters();
|
||||
|
||||
if($filters->has('order_by')){
|
||||
$query = $query->orderBy($filters->get('order_by')->column, $filters->get('order_by')->DESC ? 'DESC': 'ASC');
|
||||
}
|
||||
|
||||
return $filters->has('per_page') ? $query->paginate($filters->get('per_page')) : $query->get();
|
||||
if(!empty($param)){
|
||||
return $filters->has('per_page') ? $query->paginate($filters->get('per_page'), ['*'], 'page', $param['page']) : $query->get(); //page data from query parameters e.g ?page=1
|
||||
}
|
||||
else{
|
||||
return $filters->has('per_page') ? $query->paginate($filters->get('per_page')) : $query->get();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class CurrencyRateIsNotEqual implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->where('currency_rate', '!=', $value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class DoesNotHaveRefundInProgress implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->whereDoesntHave('transactions', function ($query) {
|
||||
return $query->where('type', TransactionType::REFUND)->whereIn('status', [ApprovalStatus::PENDING_SUBMISSION, ApprovalStatus::PENDING_VERIFICATION]);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class GroupByImportedDate implements Filter
|
||||
{
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->groupby('imported_date');
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use App\Classes\ValueObjects\Constants\RoleTypes;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
@@ -12,33 +11,17 @@ class HasActiveReward implements Filter
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return mixed
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
if(in_array(Auth::user()->type, RoleTypes::ADMIN_ROLES)){
|
||||
// $userId = $value !== 1 ? $value : Auth::user()->id;
|
||||
$userId = $value;
|
||||
return $builder->where('user_id', $userId)
|
||||
->where(function ($query) {
|
||||
$query->whereHas('reward', function ($subquery) {
|
||||
$subquery->where('is_active', true);
|
||||
})
|
||||
->orWhereDoesntHave('reward');
|
||||
})
|
||||
->whereDoesntHave('voucher.redemptions.transaction.booking.company.employees', function ($query) use ($userId) {
|
||||
$query->where('user_id', $userId);
|
||||
return $builder->where('user_id', Auth::user()->id) //cief todo: should not use Auth::user()->id
|
||||
->where(function ($query) {
|
||||
$query->whereHas('reward', function ($subquery) {
|
||||
$subquery->where('is_active', true);
|
||||
});
|
||||
}
|
||||
else{
|
||||
return $builder->where('user_id', Auth::user()->id)
|
||||
->where(function ($query) {
|
||||
$query->whereHas('reward', function ($subquery) {
|
||||
$subquery->where('is_active', true);
|
||||
})
|
||||
->orWhereDoesntHave('reward');
|
||||
})
|
||||
->whereDoesntHave('voucher.redemptions.transaction.owner');
|
||||
}
|
||||
// ->orWhereDoesntHave('reward');
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class HasActiveRewardForAdmin implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->where('user_id', $value)
|
||||
->where(function ($query) {
|
||||
$query->whereHas('reward', function ($subquery) {
|
||||
$subquery->where('is_active', true);
|
||||
});
|
||||
// ->orWhereDoesntHave('reward');
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class HasPendingVerifyTransaction implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->whereHas('transactions', function ($q) {
|
||||
$q->where('status', ApprovalStatus::PENDING_VERIFICATION);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use App\Classes\ValueObjects\Constants\RoleTypes;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class HasVouchersAllWithCompany implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
if(in_array(Auth::user()->type, RoleTypes::ADMIN_ROLES)){
|
||||
// $userId = $value !== 1 ? $value : Auth::user()->id;
|
||||
$userId = $value;
|
||||
$user = User::where('id', $userId)->first();
|
||||
$users = $user->company()->first()->employees;
|
||||
$userIds = $users->pluck('id');
|
||||
|
||||
return $builder->whereIn('user_id', $userIds)
|
||||
->where(function ($query) {
|
||||
$query->whereHas('reward', function ($subquery) {
|
||||
$subquery->where('is_active', true);
|
||||
})
|
||||
->orWhereDoesntHave('reward');
|
||||
})
|
||||
->whereDoesntHave('voucher.redemptions.transaction.booking.company.employees', function ($query) use ($userId) {
|
||||
$query->where('user_id', $userId);
|
||||
});
|
||||
}
|
||||
else{
|
||||
$user = User::where('id', Auth::user()->id)->first();
|
||||
$users = $user->company()->first()->employees;
|
||||
$userIds = $users->pluck('id');
|
||||
|
||||
return $builder->whereIn('user_id', $userIds)
|
||||
->where(function ($query) {
|
||||
$query->whereHas('reward', function ($subquery) {
|
||||
$subquery->where('is_active', true);
|
||||
})
|
||||
->orWhereDoesntHave('reward');
|
||||
})
|
||||
->whereDoesntHave('voucher.redemptions.transaction.owner');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use App\Classes\ValueObjects\Constants\RoleTypes;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class HasVouchersAllWithUser implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
if(in_array(Auth::user()->type, RoleTypes::ADMIN_ROLES)){
|
||||
// $userId = $value !== 1 ? $value : Auth::user()->id;
|
||||
$userId = $value;
|
||||
return $builder->where('user_id', $userId)
|
||||
->where(function ($query) {
|
||||
$query->whereHas('reward', function ($subquery) {
|
||||
$subquery->where('is_active', true);
|
||||
})
|
||||
->orWhereDoesntHave('reward');
|
||||
})
|
||||
->whereDoesntHave('voucher.redemptions.transaction.booking.company.employees', function ($query) use ($userId) {
|
||||
$query->where('user_id', $userId);
|
||||
});
|
||||
}
|
||||
else{
|
||||
return $builder->where('user_id', Auth::user()->id)
|
||||
->where(function ($query) {
|
||||
$query->whereHas('reward', function ($subquery) {
|
||||
$subquery->where('is_active', true);
|
||||
})
|
||||
->orWhereDoesntHave('reward');
|
||||
})
|
||||
->whereDoesntHave('voucher.redemptions.transaction.owner');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class ImportedDateFrom implements Filter
|
||||
{
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->whereDate('imported_date', '>=', date('Y-m-d',strtotime($value)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class ImportedDateTo implements Filter
|
||||
{
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->whereDate('imported_date', '<=', date('Y-m-d',strtotime($value)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class IsNotFullyRefunded implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->withSum(['transactions as total_refund_amount' => function($q) {
|
||||
$q->refunds()->where('status', ApprovalStatus::APPROVED);
|
||||
}], 'original_amount')
|
||||
->having('total_refund_amount', '<', DB::raw('original_amount'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class IsPartialRefund implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->whereHas('owner', function ($q) use ($value) {
|
||||
if ($value) {
|
||||
$q->where('original_amount', '!=', DB::raw('transactions.original_amount'));
|
||||
} else {
|
||||
$q->where('original_amount', DB::raw('transactions.original_amount'));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -4,7 +4,7 @@ namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class RandomName implements Filter
|
||||
class JobId implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
@@ -14,7 +14,7 @@ class RandomName implements Filter
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->where('is_active', $value);
|
||||
return $builder->where('job_id', $value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class OrderByIdDesc implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->orderBy('id', 'desc');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class OwnerDoesNotHaveTransactionType implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->whereDoesntHave('owner', function($query) use($value) {
|
||||
return $query->whereHas('transactions', function($query) use($value) {
|
||||
return $query->where('transactions.type', $value);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class OwnerHasTransactionType implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->whereHas('owner', function($query) use($value) {
|
||||
return $query->whereHas('transactions', function($query) use($value) {
|
||||
return $query->where('transactions.type', $value);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class ReceiverIn implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->whereIn('receiver', $value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class RequestSignature implements Filter
|
||||
{
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->where('request_signature', $value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class ResultNotNull implements Filter
|
||||
{
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->whereNotNull('result');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class StatementTransactionInvoiceReference implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->whereHas('owners', function ($query) use ($value) {
|
||||
return $query->where('Invoice_reference', $value);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class StatementTransactionOwnerReference implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->whereHas('owners', function ($query) use ($value) {
|
||||
return $query->where('owner_reference', $value);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class StatementTransactionReceiptReference implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->whereHas('owners', function ($query) use ($value) {
|
||||
return $query->where('receipt_reference', $value);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class WithoutBillGroup implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->whereDoesntHave('billGroup');
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Classes\General;
|
||||
|
||||
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
@@ -42,4 +43,27 @@ class Helper
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null|string $param
|
||||
* @return array
|
||||
*/
|
||||
static function deserializeFilters($param): array {
|
||||
if(gettype($param) == "array"){
|
||||
$json = implode(',', $param);
|
||||
}
|
||||
else{
|
||||
$json = $param;
|
||||
}
|
||||
return $json !== null ? collect(json_decode($json))->toArray() : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ResourceCollection $collection
|
||||
* @return array
|
||||
*/
|
||||
static function collectionResponse(ResourceCollection $collection){
|
||||
return json_decode($collection->response()->getContent(), true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Interfaces;
|
||||
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
|
||||
interface KeyValueInterface
|
||||
{
|
||||
|
||||
public function attributesKVP(): morphMany;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Interfaces;
|
||||
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
|
||||
interface Remarkable
|
||||
{
|
||||
|
||||
public function remarks(): morphMany;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Jobs;
|
||||
|
||||
use App\Classes\Modules\Bookings\Processors\ListBookingsJobProcessor;
|
||||
use App\Classes\Modules\Jobs\DataTransferObjects\ListGenericJobObject;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use App\Models\JobResult;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class ListBookingsJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public $timeout = 900;
|
||||
|
||||
/** @var ListGenericJobObject */
|
||||
private $listGenericJobObject;
|
||||
|
||||
private $jobId;
|
||||
|
||||
/**
|
||||
* ListBookingsJob constructor.
|
||||
* @param ListGenericJobObject $listGenericJobObject
|
||||
*/
|
||||
public function __construct(ListGenericJobObject $listGenericJobObject)
|
||||
{
|
||||
$this->listGenericJobObject = $listGenericJobObject;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$rawPayload = $this->job->payload();
|
||||
if(isset($rawPayload['data']['commandName'])){
|
||||
$this->listGenericJobObject->setJobCommandName($rawPayload['data']['commandName']);
|
||||
}
|
||||
|
||||
if(isset($rawPayload['data']['command'])){
|
||||
$this->listGenericJobObject->setJobCommand($rawPayload['data']['command']);
|
||||
}
|
||||
|
||||
$result = (App()->make(ListBookingsJobProcessor::class))->execute($this->listGenericJobObject);
|
||||
}
|
||||
|
||||
public function getJobId(){
|
||||
return $this->job->getJobId();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Jobs;
|
||||
|
||||
use App\Classes\Modules\Documents\Processors\ListDocumentsJobProcessor;
|
||||
use App\Classes\Modules\Jobs\DataTransferObjects\ListGenericJobObject;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
|
||||
class ListDocumentsJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public $timeout = 900;
|
||||
|
||||
/** @var ListGenericJobObject */
|
||||
private $listGenericJobObject;
|
||||
|
||||
private $jobId;
|
||||
|
||||
/**
|
||||
* ListDocumentsJob constructor.
|
||||
* @param ListGenericJobObject $listGenericJobObject
|
||||
*/
|
||||
public function __construct(ListGenericJobObject $listGenericJobObject)
|
||||
{
|
||||
$this->listGenericJobObject = $listGenericJobObject;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$rawPayload = $this->job->payload();
|
||||
if(isset($rawPayload['data']['commandName'])){
|
||||
$this->listGenericJobObject->setJobCommandName($rawPayload['data']['commandName']);
|
||||
}
|
||||
|
||||
if(isset($rawPayload['data']['command'])){
|
||||
$this->listGenericJobObject->setJobCommand($rawPayload['data']['command']);
|
||||
}
|
||||
|
||||
(App()->make(ListDocumentsJobProcessor::class))->execute($this->listGenericJobObject);
|
||||
}
|
||||
|
||||
public function getJobId(){
|
||||
return $this->job->getJobId();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Jobs;
|
||||
|
||||
use App\Classes\Modules\Transactions\Processors\ListTransactionsJobProcessor;
|
||||
use App\Classes\Modules\Jobs\DataTransferObjects\ListGenericJobObject;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use App\Models\JobResult;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class ListTransactionsJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public $timeout = 900;
|
||||
|
||||
/** @var ListGenericJobObject */
|
||||
private $listGenericJobObject;
|
||||
|
||||
private $jobId;
|
||||
|
||||
/**
|
||||
* ListTransactionsJob constructor.
|
||||
* @param ListGenericJobObject $listGenericJobObject
|
||||
*/
|
||||
public function __construct(ListGenericJobObject $listGenericJobObject)
|
||||
{
|
||||
$this->listGenericJobObject = $listGenericJobObject;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$rawPayload = $this->job->payload();
|
||||
if(isset($rawPayload['data']['commandName'])){
|
||||
$this->listGenericJobObject->setJobCommandName($rawPayload['data']['commandName']);
|
||||
}
|
||||
|
||||
if(isset($rawPayload['data']['command'])){
|
||||
$this->listGenericJobObject->setJobCommand($rawPayload['data']['command']);
|
||||
}
|
||||
|
||||
$result = (App()->make(ListTransactionsJobProcessor::class))->execute($this->listGenericJobObject);
|
||||
}
|
||||
|
||||
public function getJobId(){
|
||||
return $this->job->getJobId();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Jobs;
|
||||
|
||||
use App\Classes\Modules\Accounts\DataTransferObjects\KeyValuePairObject;
|
||||
use App\Classes\Modules\Accounts\Services\CreatesKeyValuePair;
|
||||
use App\Classes\Notifications\WelcomeVoucherEmail;
|
||||
use App\Models\User;
|
||||
use App\Models\Voucher;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class SendWelcomeVoucherEmail implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
|
||||
/** @var User */
|
||||
private $user;
|
||||
|
||||
/** @var Voucher */
|
||||
private $voucher;
|
||||
|
||||
/** @var int */
|
||||
private $emailSentCount;
|
||||
|
||||
/**
|
||||
* SendWelcomeVoucherEmail constructor.
|
||||
* @param User $user
|
||||
* @param Voucher $voucher
|
||||
* @param int $emailSentCount
|
||||
*/
|
||||
public function __construct(User $user, Voucher $voucher, int $emailSentCount = 1)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->voucher = $voucher;
|
||||
$this->emailSentCount = $emailSentCount;
|
||||
}
|
||||
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$currentDatetime = Carbon::now();
|
||||
$dateToCompare = Carbon::parse($this->voucher->end_date);
|
||||
if (!$this->user->hasAttribute($this->voucher->code."_EMAIL_COUNT")
|
||||
&& $this->user->rewards->where('voucher_id', $this->voucher->id)->count() > 0
|
||||
&& $currentDatetime->isBefore($dateToCompare))
|
||||
{
|
||||
//Key #1
|
||||
$keyValuePairObject = new KeyValuePairObject(
|
||||
$this->voucher->code."_EMAIL_COUNT",
|
||||
$this->emailSentCount
|
||||
);
|
||||
(App()->make(CreatesKeyValuePair::class))->execute($this->user, $keyValuePairObject);
|
||||
|
||||
//Key #2
|
||||
$keyValuePairObject = new KeyValuePairObject(
|
||||
$this->voucher->code."_EMAIL_DATE_".$this->emailSentCount,
|
||||
Carbon::now()
|
||||
);
|
||||
(App()->make(CreatesKeyValuePair::class))->execute($this->user, $keyValuePairObject);
|
||||
|
||||
$this->user->notify(new WelcomeVoucherEmail($this->user, $this->voucher));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -57,16 +57,15 @@ class UpdatePerfexCRMInvoice implements ShouldQueue
|
||||
|
||||
$number = 'EXC-'.$number;
|
||||
$invoice = (App()->make(FetchesPerfexCRMInvoice::class))->execute($customer->userid,"INV-", $number);
|
||||
Log::error(json_encode('UpdatePerfexCRMInvoice debug $number: '.$number));
|
||||
Log::channel('perfex_crm')->info(('UpdatePerfexCRMInvoice debug $number: '.$number));
|
||||
|
||||
if(is_null($invoice)){
|
||||
$result = (App()->make(CreatePerfexCRMInvoiceProcessor::class))->execute($transaction);
|
||||
if ($result) {
|
||||
$invoiceId = $result->payload['id'];
|
||||
} else {
|
||||
// Log::error(json_encode('UpdatePerfexCRMInvoice CreatePerfexCRMInvoiceProcessor failed'));
|
||||
$log['message'] = 'UpdatePerfexCRMInvoice CreatePerfexCRMInvoiceProcessor failed';
|
||||
Helper::debugLogger($log);
|
||||
Log::channel('perfex_crm')->info($log);
|
||||
}
|
||||
}
|
||||
else{
|
||||
@@ -75,7 +74,7 @@ class UpdatePerfexCRMInvoice implements ShouldQueue
|
||||
|
||||
//This only run when invoice already exist and the invoice does not have a PAID status
|
||||
if($invoiceStatus != PerfexCRMInvoiceStatus::PAID){
|
||||
Log::error(json_encode('UpdatePerfexCRMInvoice debug $this->updatePerfexCRMInvoiceObject->getProjectId(): '.$this->updatePerfexCRMInvoiceObject->getProjectId()));
|
||||
Log::channel('perfex_crm')->info('UpdatePerfexCRMInvoice debug $this->updatePerfexCRMInvoiceObject->getProjectId(): '.$this->updatePerfexCRMInvoiceObject->getProjectId());
|
||||
|
||||
//update invoice
|
||||
(App()->make(UpdatesPerfexCRMInvoice::class))->execute($invoice, $this->updatePerfexCRMInvoiceObject->getProjectId());
|
||||
|
||||
@@ -41,7 +41,11 @@ class UpdatePerfexCRMPrelude implements ShouldQueue
|
||||
{
|
||||
$serviceTypeName = $this->transaction->owner->company->services()->where('id', $this->transaction->owner->service_id)->first()->name;
|
||||
$booking = $this->transaction->booking;
|
||||
$bankDetails = $this->generateBankDetails($booking->bank);
|
||||
$bank = $booking->bank; //cief todo: 66
|
||||
if($this->transaction->bank){
|
||||
$bank = $this->transaction->bank;
|
||||
}
|
||||
$bankDetails = $this->generateBankDetails($bank);
|
||||
|
||||
$data = [
|
||||
'amount' => number_format($this->transaction->amount, 2, '.', ''),
|
||||
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Accounting\ControllersLogic;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use App\Http\Resources\TransactionMappingLogResource;
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Accounting\Services\ListTransactionMappingLogs;
|
||||
|
||||
|
||||
class HistoryImportedTransactionMappedControllerLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification(): array
|
||||
{
|
||||
return [
|
||||
'title' => 'Retrieved History Imported Invoices',
|
||||
'message' => 'You have successfully retrieved history imported invoices'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var ListTransactionMappingLogs */
|
||||
private $listTransactionMappingLogs;
|
||||
|
||||
/**
|
||||
* UpdateAnnouncementLogic constructor.
|
||||
* @param ListTransactionMappingLogs $listTransactionMappingLogs
|
||||
*/
|
||||
public function __construct(
|
||||
ListTransactionMappingLogs $listTransactionMappingLogs
|
||||
) {
|
||||
$this->listTransactionMappingLogs = $listTransactionMappingLogs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function logic(Request $request): JsonResponse
|
||||
{
|
||||
$query = $this->listTransactionMappingLogs->execute($this->listTransactionMappingLogs->deserializeFilters($request->input('filters')));
|
||||
|
||||
return $this->collectionResponse(TransactionMappingLogResource::collection($query));
|
||||
}
|
||||
}
|
||||
+15
-34
@@ -2,16 +2,14 @@
|
||||
|
||||
namespace App\Classes\Modules\Accounting\ControllersLogic;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Accounting\Services\FetchesBankStatementTransaction;
|
||||
use App\Http\Resources\BankStatementTransactionResource;
|
||||
use App\Classes\Modules\Accounting\Services\UpdatesBankStatementTransactionOwnerStatus;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\StatementTransactionOwnerType;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus;
|
||||
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Http\Resources\BankStatementTransactionOwnerResource;
|
||||
use App\Classes\ValueObjects\Constants\StatementTransactionOwnerType;
|
||||
use App\Classes\Modules\Accounting\Services\FetchesBankStatementTransactionOwner;
|
||||
use App\Classes\Modules\Accounting\Services\UpdatesBankStatementTransactionOwnerStatus;
|
||||
|
||||
class UpdateStatementTransactionStatusLogic extends AbstractControllerLogic
|
||||
{
|
||||
@@ -27,29 +25,23 @@ class UpdateStatementTransactionStatusLogic extends AbstractControllerLogic
|
||||
];
|
||||
}
|
||||
|
||||
/** @var FetchesBankStatementTransaction */
|
||||
private $fetchesBankStatementTransaction;
|
||||
/** @var FetchesBankStatementTransactionOwner */
|
||||
private $fetchesBankStatementTransactionOwner;
|
||||
|
||||
/** @var UpdatesBankStatementTransactionOwnerStatus */
|
||||
private $updatesBankStatementTransactionOwnerStatus;
|
||||
|
||||
/** @var UpdatesTransactionStatus */
|
||||
private $updatesTransactionStatus;
|
||||
|
||||
/**
|
||||
* UpdateAnnouncementLogic constructor.
|
||||
* @param FetchesBankStatementTransaction $fetchesBankStatementTransaction
|
||||
* @param FetchesBankStatementTransactionOwner $fetchesBankStatementTransactionOwner
|
||||
* @param UpdatesBankStatementTransactionOwnerStatus $updatesBankStatementTransactionOwnerStatus
|
||||
* @param UpdatesTransactionStatus $updatesTransactionStatus
|
||||
*/
|
||||
public function __construct(
|
||||
FetchesBankStatementTransaction $fetchesBankStatementTransaction,
|
||||
UpdatesBankStatementTransactionOwnerStatus $updatesBankStatementTransactionOwnerStatus,
|
||||
UpdatesTransactionStatus $updatesTransactionStatus
|
||||
FetchesBankStatementTransactionOwner $fetchesBankStatementTransactionOwner,
|
||||
UpdatesBankStatementTransactionOwnerStatus $updatesBankStatementTransactionOwnerStatus
|
||||
) {
|
||||
$this->fetchesBankStatementTransaction = $fetchesBankStatementTransaction;
|
||||
$this->fetchesBankStatementTransactionOwner = $fetchesBankStatementTransactionOwner;
|
||||
$this->updatesBankStatementTransactionOwnerStatus = $updatesBankStatementTransactionOwnerStatus;
|
||||
$this->updatesTransactionStatus = $updatesTransactionStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -61,21 +53,10 @@ class UpdateStatementTransactionStatusLogic extends AbstractControllerLogic
|
||||
*/
|
||||
public function logic(Request $request): JsonResponse
|
||||
{
|
||||
$statementTrasaction = $this->fetchesBankStatementTransaction->execute(['id' => $request->route('id')]);
|
||||
|
||||
$statementTrasactionOwner = $statementTrasaction->owners()->where('status', '!=', ApprovalStatus::REJECTED)->first();
|
||||
$statementTrasactionOwner = $this->fetchesBankStatementTransactionOwner->execute(['id' => $request->route('id')]);
|
||||
|
||||
$this->updatesBankStatementTransactionOwnerStatus->execute($statementTrasactionOwner, $request->route('status') == 'approve' ? ApprovalStatus::APPROVED : ApprovalStatus::REJECTED);
|
||||
|
||||
// todo-new: approve payments status, need to check the owner(if system is shipping, need to api with shipping portal)
|
||||
// if ($request->route('status') == 'approve') {
|
||||
// if ($statementTrasactionOwner->transaction->type === StatementTransactionOwnerType::SALES) {
|
||||
// if ($statementTrasactionOwner->owner->status === ApprovalStatus::PENDING_VERIFICATION) {
|
||||
// $this->updatesTransactionStatus->execute($statementTrasactionOwner->owner, ApprovalStatus::APPROVED);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
return $this->resourceResponse(new BankStatementTransactionResource($statementTrasaction));
|
||||
return $this->resourceResponse(new BankStatementTransactionOwnerResource($statementTrasactionOwner));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ class ListShippingPortalTransactions
|
||||
{
|
||||
try {
|
||||
$url = 'https://izyim.cief-malaysia.com/public/api/v1/transactions/mappable/query/with-details';
|
||||
// $url = 'http://127.0.0.1:8001/public/api/v1/transactions/mappable/query/with-details';
|
||||
$client = new \GuzzleHttp\Client(['verify' => false]);
|
||||
$response = $client->request('GET', $url . '?api-key=510acd13d8d24375cf038ad626c282565451461a9c2399357e0b65365300787e&filters=' . json_encode($filters));
|
||||
$body = $response->getBody();
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Accounting\Services;
|
||||
|
||||
use App\Models\StatementTransactionOwner;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Classes\General\Eloquent\AbstractFetchRecord;
|
||||
|
||||
class FetchesBankStatementTransactionOwner extends AbstractFetchRecord
|
||||
{
|
||||
|
||||
/** @var StatementTransactionOwner */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* FetchesBankStatementDetails constructor.
|
||||
* @param StatementTransactionOwner $repository
|
||||
*/
|
||||
public function __construct(StatementTransactionOwner $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Builder
|
||||
*/
|
||||
public function getRepository(): Builder
|
||||
{
|
||||
return $this->repository->newQuery();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Accounting\Services;
|
||||
|
||||
use App\Models\TransactionMappingLog;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Classes\General\Eloquent\AbstractListRecord;
|
||||
|
||||
class ListTransactionMappingLogs extends AbstractListRecord
|
||||
{
|
||||
|
||||
/** @var TransactionMappingLog */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* ListsBankStatementDetails constructor.
|
||||
* @param TransactionMappingLog $repository
|
||||
*/
|
||||
public function __construct(TransactionMappingLog $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Builder
|
||||
*/
|
||||
public function getRepository(): Builder
|
||||
{
|
||||
return $this->repository->newQuery();
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ use App\Classes\Modules\Vouchers\Processors\Voucherify\NewCustomerToVoucherifyPr
|
||||
use App\Classes\Modules\Vouchers\Processors\CreateVoucherProcessor;
|
||||
use App\Classes\Modules\Companies\DataTransferObjects\EmploymentObject;
|
||||
use App\Classes\Modules\PerfexCRM\DataTransferObjects\CreateLeadPerfexCRMObject;
|
||||
use App\Classes\Modules\Rewards\Services\CreatesUserReward;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\BusinessType;
|
||||
use App\Classes\ValueObjects\Constants\CompanyType;
|
||||
@@ -30,6 +31,7 @@ use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use App\Classes\Modules\Segments\Services\CreatesSeasonalSegment;
|
||||
use App\Classes\ValueObjects\Constants\Vouchers;
|
||||
|
||||
class CreateCustomerLogic extends AbstractControllerLogic
|
||||
{
|
||||
@@ -77,6 +79,9 @@ class CreateCustomerLogic extends AbstractControllerLogic
|
||||
/** @var CreateVoucherProcessor */
|
||||
private $createVoucherProcessor;
|
||||
|
||||
/** @var CreatesUserReward */
|
||||
private $createsUserReward;
|
||||
|
||||
/**
|
||||
* CreateCustomerLogic constructor.
|
||||
* @param CreateUserProcessor $createUserProcessor
|
||||
@@ -90,9 +95,10 @@ class CreateCustomerLogic extends AbstractControllerLogic
|
||||
* @param CheckMilestonesForRewardProcessor $checkMilestonesForRewardProcessor
|
||||
* @param NewCustomerToVoucherifyProcessor $newCustomerToVoucherifyProcessor
|
||||
* @param CreateVoucherProcessor $createVoucherProcessor
|
||||
* @param CreatesUserReward $createsUserReward
|
||||
*/
|
||||
public function __construct(CreateUserProcessor $createUserProcessor, CreateCompanyProcessor $createCompanyProcessor, CreateContactProcessor $createContactProcessor, AssignEmployeeProcessor $assignEmployeeProcessor, AssignSegmentProcessor $assignSegmentProcessor, AuthenticationProcessor $authenticationProcessor, GenerateEmailVerificationAttemptProcessor $generateEmailVerificationAttemptProcessor,
|
||||
CreatesSeasonalSegment $createsSeasonalSegment, CheckMilestonesForRewardProcessor $checkMilestonesForRewardProcessor, NewCustomerToVoucherifyProcessor $newCustomerToVoucherifyProcessor, CreateVoucherProcessor $createVoucherProcessor)
|
||||
CreatesSeasonalSegment $createsSeasonalSegment, CheckMilestonesForRewardProcessor $checkMilestonesForRewardProcessor, NewCustomerToVoucherifyProcessor $newCustomerToVoucherifyProcessor, CreateVoucherProcessor $createVoucherProcessor, CreatesUserReward $createsUserReward)
|
||||
{
|
||||
$this->createUserProcessor = $createUserProcessor;
|
||||
$this->createCompanyProcessor = $createCompanyProcessor;
|
||||
@@ -105,6 +111,7 @@ class CreateCustomerLogic extends AbstractControllerLogic
|
||||
$this->checkMilestonesForRewardProcessor = $checkMilestonesForRewardProcessor;
|
||||
$this->newCustomerToVoucherifyProcessor = $newCustomerToVoucherifyProcessor;
|
||||
$this->createVoucherProcessor = $createVoucherProcessor;
|
||||
$this->createsUserReward = $createsUserReward;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -159,7 +166,13 @@ class CreateCustomerLogic extends AbstractControllerLogic
|
||||
|
||||
$this->newCustomerToVoucherifyProcessor->execute($company->id, $user, true);
|
||||
|
||||
$this->createVoucherProcessor->execute($user, 'WELCOME50%OFF');
|
||||
$voucher = $this->createVoucherProcessor->execute($user, Vouchers::WELCOME_50_PERCENT_OFF);
|
||||
if($voucher){
|
||||
$voucherCount = $user->rewards->where('voucher_id', $voucher->id)->count();
|
||||
if($voucherCount === 0){
|
||||
$this->createsUserReward->execute(null, $user, $voucher->id);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->response($this->authenticationProcessor->execute($request, false));
|
||||
|
||||
|
||||
@@ -9,6 +9,9 @@ use App\Classes\Modules\Accounts\Services\CompletesEmailVerificationAttempt;
|
||||
use App\Classes\Modules\Accounts\Services\FetchesEmailVerificationAttempt;
|
||||
use App\Classes\Modules\Accounts\Services\VerifiesUser;
|
||||
use App\Classes\Modules\Accounts\Standards\Criteria\EmailVerificationActiveAttemptExists;
|
||||
use App\Classes\Modules\Vouchers\Services\FetchesVoucher;
|
||||
use App\Classes\Jobs\SendWelcomeVoucherEmail;
|
||||
use App\Classes\ValueObjects\Constants\Vouchers;
|
||||
use App\Models\UserEmailVerification;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -36,19 +39,29 @@ class UserEmailVerificationLogic extends AbstractControllerLogic
|
||||
/** @var VerifiesUser */
|
||||
private $verifiesUser;
|
||||
|
||||
/** @var SendWelcomeVoucherEmail */
|
||||
private $sendWelcomeVoucherEmail;
|
||||
|
||||
/** @var FetchesVoucher */
|
||||
private $fetchesVoucher;
|
||||
|
||||
/**
|
||||
* UserEmailVerificationLogic constructor.
|
||||
* @param EmailVerificationActiveAttemptExists $emailVerificationActiveAttemptExists
|
||||
* @param CompletesEmailVerificationAttempt $completesEmailVerificationAttempt
|
||||
* @param FetchesEmailVerificationAttempt $fetchesEmailVerificationAttempt
|
||||
* @param VerifiesUser $verifiesUser
|
||||
* @param SendWelcomeVoucherEmail $sendWelcomeVoucherEmail
|
||||
* @param FetchesVoucher $fetchesVoucher
|
||||
*/
|
||||
public function __construct(EmailVerificationActiveAttemptExists $emailVerificationActiveAttemptExists, CompletesEmailVerificationAttempt $completesEmailVerificationAttempt, FetchesEmailVerificationAttempt $fetchesEmailVerificationAttempt, VerifiesUser $verifiesUser)
|
||||
public function __construct(EmailVerificationActiveAttemptExists $emailVerificationActiveAttemptExists, CompletesEmailVerificationAttempt $completesEmailVerificationAttempt, FetchesEmailVerificationAttempt $fetchesEmailVerificationAttempt, VerifiesUser $verifiesUser, SendWelcomeVoucherEmail $sendWelcomeVoucherEmail, FetchesVoucher $fetchesVoucher)
|
||||
{
|
||||
$this->emailVerificationActiveAttemptExists = $emailVerificationActiveAttemptExists;
|
||||
$this->completesEmailVerificationAttempt = $completesEmailVerificationAttempt;
|
||||
$this->fetchesEmailVerificationAttempt = $fetchesEmailVerificationAttempt;
|
||||
$this->verifiesUser = $verifiesUser;
|
||||
$this->sendWelcomeVoucherEmail = $sendWelcomeVoucherEmail;
|
||||
$this->fetchesVoucher = $fetchesVoucher;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -68,9 +81,19 @@ class UserEmailVerificationLogic extends AbstractControllerLogic
|
||||
|
||||
$this->completesEmailVerificationAttempt->execute($attempt);
|
||||
|
||||
$this->verifiesUser->execute($attempt->user);
|
||||
$user = $attempt->user;
|
||||
$this->verifiesUser->execute($user);
|
||||
|
||||
// if (env('SENDING_EMAIL_WELCOME_VOUCHER_ENABLED', false)){
|
||||
if (app()->environment('production') && env('SENDING_EMAIL_WELCOME_VOUCHER_ENABLED', false)){
|
||||
try{ //In case voucher got deleted unintentionally
|
||||
$voucher = $this->fetchesVoucher->execute(['code' => Vouchers::WELCOME_50_PERCENT_OFF]);
|
||||
if($voucher) $this->sendWelcomeVoucherEmail::dispatch($user, $voucher, 1);
|
||||
}
|
||||
catch(\Exception $e){}
|
||||
}
|
||||
|
||||
return $this->response([]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Accounts\DataTransferObjects;
|
||||
|
||||
|
||||
use App\Classes\General\Interfaces\DataTransferObject;
|
||||
|
||||
class KeyValuePairObject implements DataTransferObject
|
||||
{
|
||||
/** @var string */
|
||||
private $key;
|
||||
|
||||
/** @var string */
|
||||
private $value;
|
||||
|
||||
|
||||
/**
|
||||
* KeyValuePairObject constructor.
|
||||
* @param string $key
|
||||
* @param string $value
|
||||
*/
|
||||
public function __construct(string $key, string $value)
|
||||
{
|
||||
$this->key = $key;
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getKey(): string
|
||||
{
|
||||
return $this->key;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getValue(): string
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Accounts\Services;
|
||||
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord;
|
||||
use App\Classes\General\Interfaces\KeyValueInterface;
|
||||
use App\Classes\Modules\Accounts\DataTransferObjects\KeyValuePairObject;
|
||||
use App\Models\KeyValuePair;
|
||||
|
||||
class CreatesKeyValuePair extends AbstractUpdateRelationshipRecord
|
||||
{
|
||||
/**
|
||||
* @param KeyValueInterface $kv
|
||||
* @param KeyValuePairObject $object
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
|
||||
public function execute(KeyValueInterface $kv, KeyValuePairObject $object) {
|
||||
$model = new KeyValuePair();
|
||||
$model->key = $object->getKey();
|
||||
$model->value = $object->getValue();
|
||||
|
||||
return $this->handler($kv->attributesKVP(), $model);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Accounts\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractDeleteRecord;
|
||||
use App\Models\KeyValuePair;
|
||||
|
||||
class DeletesKeyValuePair extends AbstractDeleteRecord
|
||||
{
|
||||
|
||||
/**
|
||||
* @param KeyValuePair $model
|
||||
* @return mixed
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(KeyValuePair $model) {
|
||||
return $this->handler($model);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Accounts\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\Modules\Accounts\DataTransferObjects\KeyValuePairObject;
|
||||
use App\Models\KeyValuePair;
|
||||
|
||||
class UpdatesKeyValuePair extends AbstractUpdateRecord
|
||||
{
|
||||
/**
|
||||
* @param KeyValuePair $model
|
||||
* @param KeyValuePairObject $object
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(KeyValuePair $model, KeyValuePairObject $object) {
|
||||
$model->key = $object->getKey();
|
||||
$model->value = $object->getValue();
|
||||
return $this->handler($model);
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ class CanAuthenticateUser extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ class CanCreateUser extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -10,7 +10,7 @@ class CanDeleteUser extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -12,7 +12,7 @@ class CanFetchUser extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ class CanGeneratePasswordReset extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ class CanListUsers extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ class CanRegisterUser extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -13,7 +13,7 @@ class CanResendEmailVerification extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ class CanResetPassword extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ class CanUpdateUser extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -26,7 +26,7 @@ class CanCreateAddress extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -13,7 +13,7 @@ class CanDeleteAddress extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -13,7 +13,7 @@ class CanFetchAddress extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -13,7 +13,7 @@ class CanListAddresses extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -26,7 +26,7 @@ class CanUpdateAddress extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -13,7 +13,7 @@ class CanAssignSegment extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -24,7 +24,7 @@ class CanCreateAnnouncement extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ class CanDeleteAnnouncement extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -11,7 +11,7 @@ class CanListAnnouncements extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ class CanUpdateAnnouncement extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -3,21 +3,17 @@
|
||||
namespace App\Classes\Modules\Banks\ControllersLogic;
|
||||
|
||||
use App\Http\Resources\BankResource;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
|
||||
use App\Classes\Modules\Banks\Services\FetchesBank;
|
||||
|
||||
use App\Classes\Modules\Banks\Standards\Rules\CanUpdateBank;
|
||||
use App\Classes\Modules\Banks\Services\UpdatesBank;
|
||||
use App\Classes\Modules\Banks\Services\CreatesOrUpdateBank;
|
||||
use App\Classes\Modules\Banks\Services\CreatesBankLog;
|
||||
|
||||
use App\Classes\Modules\Banks\Processors\UpdateBankProcessor;
|
||||
use App\Classes\Modules\Banks\DataTransferObjects\BankObject;
|
||||
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
|
||||
class UpdateBankLogic extends AbstractControllerLogic
|
||||
{
|
||||
@@ -44,24 +40,36 @@ class UpdateBankLogic extends AbstractControllerLogic
|
||||
/** @var CreatesBankLog */
|
||||
private $createsBankLog;
|
||||
|
||||
/** @var CreatesOrUpdateBank */
|
||||
private $createsOrUpdateBank;
|
||||
|
||||
/** @var UpdateBankProcessor */
|
||||
private $updateBankProcessor;
|
||||
|
||||
/**
|
||||
* UpdateBankLogic constructor.
|
||||
* @param CanUpdateBank $canUpdateBank
|
||||
* @param UpdatesBank $updatesBank
|
||||
* @param FetchesBank $fetchesBank
|
||||
* @param CreatesBankLog $createsBankLog
|
||||
* @param CreatesOrUpdateBank $createsOrUpdateBank
|
||||
* @param UpdateBankProcessor $updateBankProcessor
|
||||
*/
|
||||
public function __construct(
|
||||
CanUpdateBank $canUpdateBank,
|
||||
UpdatesBank $updatesBank,
|
||||
FetchesBank $fetchesBank,
|
||||
CreatesBankLog $createsBankLog
|
||||
CreatesBankLog $createsBankLog,
|
||||
CreatesOrUpdateBank $createsOrUpdateBank,
|
||||
UpdateBankProcessor $updateBankProcessor
|
||||
)
|
||||
{
|
||||
$this->canUpdateBank = $canUpdateBank;
|
||||
$this->updatesBank = $updatesBank;
|
||||
$this->fetchesBank = $fetchesBank;
|
||||
$this->createsBankLog = $createsBankLog;
|
||||
$this->createsOrUpdateBank = $createsOrUpdateBank;
|
||||
$this->updateBankProcessor = $updateBankProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,15 +82,15 @@ class UpdateBankLogic extends AbstractControllerLogic
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$bankObject = new BankObject(
|
||||
$request->input('company_id'),
|
||||
$request->input('company_id'),
|
||||
$request->input('account_type'),
|
||||
$request->input('bank_name'),
|
||||
$request->input('holder_name'),
|
||||
$request->input('holder_name'),
|
||||
$request->input('account_no'),
|
||||
$request->input('bank_branch'),
|
||||
$request->input('swift'),
|
||||
$request->input('bank_branch'),
|
||||
$request->input('swift'),
|
||||
$request->input('snap'),
|
||||
$request->input('country_id'),
|
||||
$request->input('country_id'),
|
||||
$request->input('reference')
|
||||
);
|
||||
|
||||
@@ -90,12 +98,10 @@ class UpdateBankLogic extends AbstractControllerLogic
|
||||
|
||||
$this->canUpdateBank->passes($bankObject);
|
||||
|
||||
$bank_query = $this->updatesBank->execute($bank, $bankObject);
|
||||
|
||||
// $bankLog = $this->createsBankLog->execute($bank_query);
|
||||
$bank_query = $this->updateBankProcessor->execute($bankObject, $bank, $request->input('bill_no') ?? '', (int) $request->input('transaction_id') ?? 0 );
|
||||
|
||||
return $this->resourceResponse(new BankResource($bank_query));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Banks\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Transactions\Services\FetchesTransaction;
|
||||
use App\Classes\Modules\Banks\Standards\Rules\CanUpdateBankMetadata;
|
||||
use App\Classes\Modules\Banks\DataTransferObjects\BankMetadataObject;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class UpdateBankMetadataLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Update Bank Metadata',
|
||||
'message' => 'You have successfully updated the Bank metadata'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanUpdateBankMetadata */
|
||||
private $canUpdateBankMetadata;
|
||||
|
||||
/** @var FetchesTransaction */
|
||||
private $fetchesTransaction;
|
||||
|
||||
/**
|
||||
* UpdateBankMetadataLogic constructor.
|
||||
* @param CanUpdateBankMetadata $canUpdateBankMetadata
|
||||
* @param FetchesTransaction $fetchesTransaction
|
||||
*/
|
||||
public function __construct(
|
||||
CanUpdateBankMetadata $canUpdateBankMetadata,
|
||||
FetchesTransaction $fetchesTransaction
|
||||
)
|
||||
{
|
||||
$this->canUpdateBankMetadata = $canUpdateBankMetadata;
|
||||
$this->fetchesTransaction = $fetchesTransaction;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws \App\Classes\Exceptions\AccessForbiddenException
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$bankMetadataObject = new BankMetadataObject(
|
||||
$request->input('transactionId'),
|
||||
);
|
||||
|
||||
$this->canUpdateBankMetadata->passes($bankMetadataObject);
|
||||
|
||||
$transaction = $this->fetchesTransaction->execute(['id' => $request->input('transactionId')]);
|
||||
$transaction->attributesKVP()->delete();
|
||||
|
||||
return $this->response([]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Banks\DataTransferObjects;
|
||||
|
||||
use App\Classes\General\Interfaces\DataTransferObject;
|
||||
|
||||
class BankMetadataObject implements DataTransferObject
|
||||
{
|
||||
|
||||
/** @var int */
|
||||
private $transaction_id;
|
||||
|
||||
/**
|
||||
* BankMetadataObject constructor.
|
||||
* @param int $transaction_id
|
||||
*/
|
||||
public function __construct(int $transaction_id)
|
||||
{
|
||||
$this->transaction_id = $transaction_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTransactionId(): int
|
||||
{
|
||||
return $this->transaction_id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Classes\Modules\Banks\Processors;
|
||||
|
||||
use App\Classes\Modules\Transactions\Services\FetchesTransaction;
|
||||
use App\Classes\Modules\Banks\Services\UpdatesBank;
|
||||
use App\Classes\Modules\Banks\Services\CreatesOrUpdateBank;
|
||||
use App\Classes\Modules\Banks\DataTransferObjects\BankObject;
|
||||
use App\Classes\Modules\Accounts\DataTransferObjects\KeyValuePairObject;
|
||||
use App\Classes\Modules\Accounts\Services\CreatesKeyValuePair;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\Models\Bank;
|
||||
|
||||
|
||||
class UpdateBankProcessor
|
||||
{
|
||||
/** @var UpdatesBank */
|
||||
private $updatesBank;
|
||||
|
||||
/** @var CreatesOrUpdateBank */
|
||||
private $createsOrUpdateBank;
|
||||
|
||||
/** @var CreatesKeyValuePair */
|
||||
private $createsKeyValuePair;
|
||||
|
||||
/** @var FetchesTransaction */
|
||||
private $fetchesTransaction;
|
||||
|
||||
/**
|
||||
* UpdateBankProcessor constructor.
|
||||
* @param UpdatesBank $updatesBank
|
||||
* @param CreatesOrUpdateBank $createsOrUpdateBank
|
||||
* @param CreatesKeyValuePair $createsKeyValuePair
|
||||
* @param FetchesTransaction $fetchesTransaction
|
||||
*/
|
||||
public function __construct(
|
||||
UpdatesBank $updatesBank,
|
||||
CreatesOrUpdateBank $createsOrUpdateBank,
|
||||
CreatesKeyValuePair $createsKeyValuePair,
|
||||
FetchesTransaction $fetchesTransaction
|
||||
)
|
||||
{
|
||||
$this->updatesBank = $updatesBank;
|
||||
$this->createsOrUpdateBank = $createsOrUpdateBank;
|
||||
$this->createsKeyValuePair = $createsKeyValuePair;
|
||||
$this->fetchesTransaction = $fetchesTransaction;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param BankObject $bankObject
|
||||
* @param Bank $bank
|
||||
* @param string $billNo
|
||||
* @param int $transactionId
|
||||
* @return Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
* @throws \App\Classes\Exceptions\JobResourceNotFoundException
|
||||
*/
|
||||
public function execute(BankObject $bankObject, Bank $bank, string $billNo, int $transactionId) {
|
||||
$result = null;
|
||||
if($billNo && $transactionId){
|
||||
$transaction = $this->fetchesTransaction->execute(['id' => $transactionId]);
|
||||
//If payment transaction do not have a bank yet, create one
|
||||
if(!$transaction->bank){
|
||||
$result = $this->createsOrUpdateBank->execute($bankObject);
|
||||
|
||||
// if ($result->wasRecentlyCreated) {
|
||||
//Key #1 for Bank
|
||||
$kvp = $bank->attributesKVP()->where('key', 'App\Models\Bank')->where('value', $result->id)->latest()->first();
|
||||
if(!$kvp){
|
||||
$keyValuePairObject = new KeyValuePairObject(
|
||||
"App\Models\Bank",
|
||||
$result->id
|
||||
);
|
||||
$this->createsKeyValuePair->execute($bank, $keyValuePairObject);
|
||||
}
|
||||
|
||||
//Key #2 for Payment Transaction (owner type: booking)
|
||||
$keyValuePairObject = new KeyValuePairObject(
|
||||
"App\Models\Bank",
|
||||
$result->id
|
||||
);
|
||||
$this->createsKeyValuePair->execute($transaction, $keyValuePairObject);
|
||||
// }
|
||||
|
||||
}
|
||||
else{
|
||||
$result = $this->updatesBank->execute($transaction->bank, $bankObject);
|
||||
}
|
||||
}
|
||||
else{
|
||||
$result = $this->updatesBank->execute($bank, $bankObject);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Banks\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\Modules\Banks\DataTransferObjects\BankObject;
|
||||
use App\Classes\ValueObjects\Constants\RoleTypes;
|
||||
use App\Models\Bank;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class CreatesOrUpdateBank extends AbstractUpdateRecord
|
||||
{
|
||||
/**
|
||||
* @param BankObject $object
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(BankObject $object)
|
||||
{
|
||||
$user = Auth::user(); /** @var User $user */
|
||||
$attributes = [
|
||||
'company_id' => $object->getCompanyId(),
|
||||
'account_no' => $object->getAccountNo(),
|
||||
'reference' => $object->getReference(),
|
||||
'bank_name' => $object->getBankName(),
|
||||
'holder_name' => $object->getHolderName(),
|
||||
'bank_branch' => $object->getBankBranch(),
|
||||
'type' => $object->getType(),
|
||||
'country_id' => $object->getCountryId(),
|
||||
'created_by' => Auth::id(),
|
||||
'creator_type' => in_array($user->type, RoleTypes::ADMIN_ROLES) ? RoleTypes::ADMIN : RoleTypes::USER,
|
||||
];
|
||||
|
||||
$values = [
|
||||
'swift' => $object->getSwift(),
|
||||
'snap' => $object->getSnap(),
|
||||
];
|
||||
|
||||
$model = Bank::updateOrCreate($attributes, $values); //Bank::firstOrCreate($attributes, $values);
|
||||
|
||||
return $model;
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@ class CanCreateBank extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ class CanDeleteBank extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -12,7 +12,7 @@ class CanListBanks extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ class CanUpdateBank extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Banks\Standards\Rules;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\Banks\DataTransferObjects\BankMetadataObject;
|
||||
use App\Classes\Modules\Banks\Standards\Validators\BankMetadataValidation;
|
||||
use App\Classes\ValueObjects\Constants\RoleTypes;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class CanUpdateBankMetadata extends AbstractRule
|
||||
{
|
||||
|
||||
/** @var BankMetadataValidation */
|
||||
private $validation;
|
||||
|
||||
|
||||
/**
|
||||
* CanUpdateBankMetadata constructor.
|
||||
* @param BankMetadataValidation $validation
|
||||
*/
|
||||
public function __construct(BankMetadataValidation $validation)
|
||||
{
|
||||
$this->validation = $validation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
//cief todo: 66 - temporary workaround
|
||||
// if (!Auth::user()->can('update bank_metadata')) {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
// return true;
|
||||
|
||||
if (in_array(Auth::user()->type, RoleTypes::ADMIN_ROLES)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param BankMetadataObject $object
|
||||
* @return bool
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return $this->validation->validate($object);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param BankMetadataObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Banks\Standards\Validators;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractValidation;
|
||||
use App\Classes\Modules\Banks\DataTransferObjects\BankMetadataObject;
|
||||
|
||||
class BankMetadataValidation extends AbstractValidation
|
||||
{
|
||||
/**
|
||||
* @param BankMetadataObject $object
|
||||
* @return array
|
||||
*/
|
||||
protected function data($object): array
|
||||
{
|
||||
return [
|
||||
'transaction_id' => $object->getTransactionId(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function rules(): array
|
||||
{
|
||||
return [
|
||||
'transaction_id' => 'required',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function messages(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Classes\Modules\Bookings\ControllersLogic;
|
||||
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
|
||||
use App\Classes\Modules\Companies\Services\FetchesCompany;
|
||||
@@ -15,6 +16,7 @@ use App\Classes\Modules\Bookings\Services\GeneratesBookingMarking;
|
||||
use App\Classes\Modules\Bookings\DataTransferObjects\BookingObject;
|
||||
use App\Classes\Modules\PerfexCRM\Processors\BookingToPerfexCRMProcessor;
|
||||
use App\Classes\Modules\Milestones\Processors\CheckMilestonesForRewardProcessor;
|
||||
use App\Classes\ValueObjects\Constants\BookingAttributeNames;
|
||||
use App\Classes\ValueObjects\Constants\Milestones;
|
||||
use App\Http\Resources\BookingResource;
|
||||
|
||||
@@ -84,6 +86,21 @@ class CreateBookingLogic extends AbstractControllerLogic
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
if (in_array($request->input('service_id'), [4, 10])) {
|
||||
if (!$request['order_reference_no']) {
|
||||
throw new MalformedRequestException('At least 1 order reference required.');
|
||||
}
|
||||
|
||||
if ($request['order_reference_no']) {
|
||||
foreach ($request['order_reference_no'] as $index => $reference) {
|
||||
if (!$reference) {
|
||||
$index += 1;
|
||||
throw new MalformedRequestException("Order reference {$index} cannot be empty");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$company = $this->fetchesCompany->execute(['id' => $request->input('company_id')]);
|
||||
|
||||
$object = new BookingObject($request->input('service_id'), $request->input('transferable_bank_id'), $this->generatesBookingMarking->execute(), number_format( floatval(str_replace(',', '', $request->input('fix_amount'))), 5, '.', ''), $request->input('type') === 1 ? $request->input('convertible_currency_id') : 1, $request->input('convertible_currency_id'), 1);
|
||||
@@ -97,6 +114,15 @@ class CreateBookingLogic extends AbstractControllerLogic
|
||||
$this->bookingToPerfexCRMProcessor->execute($booking);
|
||||
}
|
||||
|
||||
if (in_array($request->input('service_id'), [4, 10])) {
|
||||
foreach ($request['order_reference_no'] as $order_reference) {
|
||||
$booking->modelAttributes()->create([
|
||||
'name' => BookingAttributeNames::ORDER_REFERENCE_NO,
|
||||
'value' => $order_reference
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
//cief todo: case study 5
|
||||
// $user = $company->employees()->first();
|
||||
// $this->checkMilestonesForRewardProcessor->execute($user, [Milestones::MILESTONE_5]);
|
||||
|
||||
@@ -19,6 +19,7 @@ use App\Classes\ValueObjects\Constants\PaymentMethodType;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Classes\Modules\Currencies\DataTransferObjects\CurrencyConversionObject;
|
||||
use App\Http\Resources\TransactionResource;
|
||||
use App\Classes\Modules\Bookings\Services\CalculatesBookingRefundAmount;
|
||||
|
||||
use App\Classes\Modules\Transactions\Processors\CreateCashBackTransactionProcessor;
|
||||
use App\Classes\Modules\Vouchers\Processors\Voucherify\BookingToVoucherifyProcessor;
|
||||
@@ -77,6 +78,9 @@ class CreateBookingPaymentLogic extends AbstractControllerLogic
|
||||
/** @var BookingToVoucherifyProcessor */
|
||||
private $bookingToVoucherifyProcessor;
|
||||
|
||||
/** @var CalculatesBookingRefundAmount */
|
||||
private $calculatesBookingRefundAmount;
|
||||
|
||||
/**
|
||||
* CreateBookingPaymentLogic constructor.
|
||||
* @param FetchesBookingQuotation $fetchBookingQuotation
|
||||
@@ -90,8 +94,9 @@ class CreateBookingPaymentLogic extends AbstractControllerLogic
|
||||
* @param CreateCashBackTransactionProcessor $createCashBackTransactionProcessor
|
||||
* @param RecalculatesWalletBalance $recalculatesWalletBalance
|
||||
* @param BookingToVoucherifyProcessor $bookingToVoucherifyProcessor
|
||||
* @param CalculatesBookingRefundAmount $calculatesBookingRefundAmount
|
||||
*/
|
||||
public function __construct(FetchesBookingQuotation $fetchBookingQuotation, FetchesCompanyPaymentAttemptLimit $fetchesCompanyPaymentAttemptLimit, GeneratesTransactionBillNumber $generatesTransactionBillNumber, CreatesTransaction $createsTransaction, CalculatesBookingOutstanding $calculatesBookingOutstanding, CreatesBillplzBill $createsBillplzBill, UpdatesWalletBalance $updatesWalletBalance, UpdatesTransactionStatus $updatesTransactionStatus, CreateCashBackTransactionProcessor $createCashBackTransactionProcessor, RecalculatesWalletBalance $recalculatesWalletBalance, BookingToVoucherifyProcessor $bookingToVoucherifyProcessor)
|
||||
public function __construct(FetchesBookingQuotation $fetchBookingQuotation, FetchesCompanyPaymentAttemptLimit $fetchesCompanyPaymentAttemptLimit, GeneratesTransactionBillNumber $generatesTransactionBillNumber, CreatesTransaction $createsTransaction, CalculatesBookingOutstanding $calculatesBookingOutstanding, CreatesBillplzBill $createsBillplzBill, UpdatesWalletBalance $updatesWalletBalance, UpdatesTransactionStatus $updatesTransactionStatus, CreateCashBackTransactionProcessor $createCashBackTransactionProcessor, RecalculatesWalletBalance $recalculatesWalletBalance, BookingToVoucherifyProcessor $bookingToVoucherifyProcessor, CalculatesBookingRefundAmount $calculatesBookingRefundAmount)
|
||||
{
|
||||
$this->fetchBookingQuotation = $fetchBookingQuotation;
|
||||
$this->fetchesCompanyPaymentAttemptLimit = $fetchesCompanyPaymentAttemptLimit;
|
||||
@@ -104,6 +109,7 @@ class CreateBookingPaymentLogic extends AbstractControllerLogic
|
||||
$this->createCashBackTransactionProcessor = $createCashBackTransactionProcessor;
|
||||
$this->recalculatesWalletBalance = $recalculatesWalletBalance;
|
||||
$this->bookingToVoucherifyProcessor = $bookingToVoucherifyProcessor;
|
||||
$this->calculatesBookingRefundAmount = $calculatesBookingRefundAmount;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,7 +125,7 @@ class CreateBookingPaymentLogic extends AbstractControllerLogic
|
||||
|
||||
$conversionObject = new CurrencyConversionObject(floatval(str_replace(',', '', $request->input('amount'))), $booking->convertible_currency_id, $booking->service_id, $booking->fix_currency_id === 1 ? 0:1, PaymentMethodType::PAYMENT_METHODS[$request->input('payment_method')]);
|
||||
|
||||
$outstanding = $this->calculatesBookingOutstanding->execute($booking);
|
||||
$outstanding = $this->calculatesBookingOutstanding->execute($booking) + $this->calculatesBookingRefundAmount->execute($booking, $booking->fix_currency_id);
|
||||
|
||||
if($conversionObject->getAmount() > round($outstanding, 2)) throw new MalformedRequestException('Your payment must not be greater than '. $outstanding .'.');
|
||||
|
||||
|
||||
@@ -14,11 +14,15 @@ use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Transactions\Services\CreatesTransaction;
|
||||
use App\Classes\Modules\Transactions\Services\FetchesTransaction;
|
||||
use App\Classes\Modules\Bookings\Services\FetchesBookingQuotation;
|
||||
use App\Classes\Modules\Currencies\DataTransferObjects\CurrencyConversionObject;
|
||||
use App\Classes\Modules\Remarks\DataTransferObjects\RemarkObject;
|
||||
use App\Classes\Modules\Transactions\ControllersLogic\UpdateRefundTransactionStatusLogic;
|
||||
use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus;
|
||||
use App\Classes\Modules\Bookings\Services\CalculatesBookingRefundAmount;
|
||||
use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject;
|
||||
use App\Classes\Modules\Transactions\Services\GeneratesTransactionBillNumber;
|
||||
use App\Classes\Modules\Transactions\DataTransferObjects\TransactionRefundCalculationObject;
|
||||
use App\Classes\ValueObjects\Constants\PaymentMethodType;
|
||||
use App\Classes\Modules\Remarks\Processors\CreateRemarkProcessor;
|
||||
|
||||
class CreateBookingRefundLogic extends AbstractControllerLogic
|
||||
{
|
||||
@@ -48,8 +52,11 @@ class CreateBookingRefundLogic extends AbstractControllerLogic
|
||||
/** @var CreatesTransaction */
|
||||
private $createsTransaction;
|
||||
|
||||
/** @var CalculatesBookingRefundAmount */
|
||||
private $calculatesBookingRefundAmount;
|
||||
/** @var UpdateRefundTransactionStatusLogic */
|
||||
private $updateRefundTransactionStatusLogic;
|
||||
|
||||
/** @var CreateRemarkProcessor */
|
||||
private $createRemarkProcessor;
|
||||
|
||||
/**
|
||||
* CreateBookingPaymentLogic constructor.
|
||||
@@ -58,16 +65,18 @@ class CreateBookingRefundLogic extends AbstractControllerLogic
|
||||
* @param UpdatesTransactionStatus $updatesTransactionStatus
|
||||
* @param GeneratesTransactionBillNumber $generatesTransactionBillNumber
|
||||
* @param CreatesTransaction $createsTransaction
|
||||
* @param CalculatesBookingRefundAmount $calculatesBookingRefundAmount
|
||||
* @param UpdateRefundTransactionStatusLogic $updateRefundTransactionStatusLogic
|
||||
* @param CreateRemarkProcessor $createRemarkProcessor
|
||||
*/
|
||||
public function __construct(FetchesBookingQuotation $fetchBookingQuotation, FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus, GeneratesTransactionBillNumber $generatesTransactionBillNumber, CreatesTransaction $createsTransaction, CalculatesBookingRefundAmount $calculatesBookingRefundAmount)
|
||||
public function __construct(FetchesBookingQuotation $fetchBookingQuotation, FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus, GeneratesTransactionBillNumber $generatesTransactionBillNumber, CreatesTransaction $createsTransaction, UpdateRefundTransactionStatusLogic $updateRefundTransactionStatusLogic, CreateRemarkProcessor $createRemarkProcessor)
|
||||
{
|
||||
$this->fetchBookingQuotation = $fetchBookingQuotation;
|
||||
$this->fetchesTransaction = $fetchesTransaction;
|
||||
$this->updatesTransactionStatus = $updatesTransactionStatus;
|
||||
$this->generatesTransactionBillNumber = $generatesTransactionBillNumber;
|
||||
$this->createsTransaction = $createsTransaction;
|
||||
$this->calculatesBookingRefundAmount = $calculatesBookingRefundAmount;
|
||||
$this->updateRefundTransactionStatusLogic = $updateRefundTransactionStatusLogic;
|
||||
$this->createRemarkProcessor = $createRemarkProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,27 +91,98 @@ class CreateBookingRefundLogic extends AbstractControllerLogic
|
||||
|
||||
$booking = $transaction->owner;
|
||||
|
||||
$invoice = $booking->transactions()->where('type', TransactionType::INVOICE)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->first();
|
||||
|
||||
if(auth()->user()->type === 3) {
|
||||
throw new MalformedRequestException('You do not have the permission to refund the order.');
|
||||
}
|
||||
|
||||
$billNumber = $this->generatesTransactionBillNumber->execute('RFD-');
|
||||
|
||||
$refund = $transaction->transactions()->refunds()->sum('amount');
|
||||
$refund = $transaction->transactions()->refunds()->whereIn('status', [ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::APPROVED])->sum('original_amount');
|
||||
|
||||
$refundInPending = $transaction->transactions()->refunds()->where('status', ApprovalStatus::PENDING_VERIFICATION)->sum('original_amount');
|
||||
|
||||
if($refund + $request->input('amount') > $transaction->original_amount) throw new MalformedRequestException('Your refund must not be greater than '. $transaction->original_amount .'.');
|
||||
|
||||
$amount = $transaction->booking->fix_currency_id == 1 ? $request->input('amount') : $request->input('amount') / $transaction->currency_rate;
|
||||
// $transactionRefundCalculationObject = new TransactionRefundCalculationObject($booking, $transaction, $request->input('amount'));
|
||||
// $transactionRefundCalculationObject->init();
|
||||
|
||||
if ((float)$request->input('amount') === (float)$transaction->original_amount) {
|
||||
$refundAmount = $transaction->original_amount / $transaction->currency_rate;
|
||||
$service_charges_to_refund = $transaction->service_charge;
|
||||
} else {
|
||||
$refundAmount = bcdiv($request->input('amount'), $transaction->currency_rate, 7);
|
||||
|
||||
$transactionRefundCalculationObject = new TransactionRefundCalculationObject($booking, $transaction, $amount);
|
||||
$transactionRefundCalculationObject->init();
|
||||
$bookingAmountBeforeCurrentRefund = $booking->fix_amount - $refundInPending;
|
||||
|
||||
$bookingAmountAfterRefunded = $booking->fix_amount - $refundInPending - $request->input('amount');
|
||||
|
||||
$isFullyRefund = ($refund + $request->input('amount')) == $transaction->original_amount;
|
||||
|
||||
$voucherCode = null;
|
||||
$redemptionId = null;
|
||||
|
||||
if ($transaction->voucherRedemption) {
|
||||
// $voucherCode = $transaction->voucherRedemption->voucher->code;
|
||||
$redemptionId = $transaction->voucherRedemption->redemption_id;
|
||||
}
|
||||
|
||||
$conversionObjectBeforeCurrentRefund = new CurrencyConversionObject($bookingAmountBeforeCurrentRefund, $booking->convertible_currency_id, $booking->service_id, $booking->fix_currency_id === 1 ? 0:1, $transaction->payment_method);
|
||||
|
||||
$conversionObjectAfterRefund = new CurrencyConversionObject($isFullyRefund ? $request->input('amount') : $bookingAmountAfterRefunded, $booking->convertible_currency_id, $booking->service_id, $booking->fix_currency_id === 1 ? 0:1, $transaction->payment_method);
|
||||
|
||||
$quotationBeforeCurrentRefund = $this->fetchBookingQuotation->execute($booking->company, $conversionObjectBeforeCurrentRefund, $voucherCode, $redemptionId);
|
||||
|
||||
$quotationAfterRefund = $this->fetchBookingQuotation->execute($booking->company, $conversionObjectAfterRefund, $voucherCode, $redemptionId);
|
||||
|
||||
$service_charges_to_refund = $isFullyRefund ? $quotationBeforeCurrentRefund->getServiceCharge() : $quotationBeforeCurrentRefund->getServiceCharge() - $quotationAfterRefund->getServiceCharge();
|
||||
}
|
||||
|
||||
// refund service charges if booking is not E2E
|
||||
$refundTotal = $refundAmount;
|
||||
|
||||
if ($booking->service_id !== 5) {
|
||||
$refundTotal = $refundTotal + $service_charges_to_refund + $transaction->tax;
|
||||
} else {
|
||||
$service_charges_to_refund = 0;
|
||||
}
|
||||
|
||||
$object = new TransactionObject($billNumber, TransactionType::REFUND, 1, $booking->company->id,
|
||||
1, $transactionRefundCalculationObject->getConversionObject()->getPaymentMethod(),
|
||||
$transactionRefundCalculationObject->getRefundTotalAmount(), $transactionRefundCalculationObject->getAmount(), 1,
|
||||
$transactionRefundCalculationObject->getConversionObject()->getCurrencyId(), $transactionRefundCalculationObject->getTransaction()->currency_rate,
|
||||
$transactionRefundCalculationObject->getRefundTax(), $transactionRefundCalculationObject->getRefundServiceCharge(), null, ApprovalStatus::PENDING_VERIFICATION, [], $transaction->bill_no);
|
||||
1, PaymentMethodType::CASH,
|
||||
$refundTotal, $request->input('amount'), 1,
|
||||
$transaction->original_currency_id, $transaction->currency_rate,
|
||||
0, $service_charges_to_refund, null, ApprovalStatus::PENDING_VERIFICATION, [], $transaction->bill_no);
|
||||
|
||||
$transaction = $this->createsTransaction->execute($transaction, $object);
|
||||
$refund_transaction = $this->createsTransaction->execute($transaction, $object);
|
||||
|
||||
return $this->resourceResponse(new TransactionResource($transaction));
|
||||
$bookingInWhiteForm = $transaction->transactions()->bills()->first();
|
||||
|
||||
// create supplier refund
|
||||
if ($bookingInWhiteForm) {
|
||||
$billNumber = $this->generatesTransactionBillNumber->execute('SRFD-');
|
||||
$supplierRefundTotal = bcdiv($request->input('amount'), $bookingInWhiteForm->currency_rate, 7);
|
||||
|
||||
$object = new TransactionObject($billNumber, TransactionType::SUPPLIER_REFUND, 1, $bookingInWhiteForm->issuer,
|
||||
1, PaymentMethodType::CASH,
|
||||
$supplierRefundTotal, $request->input('amount'), 1,
|
||||
$transaction->original_currency_id, $bookingInWhiteForm->currency_rate,
|
||||
0, 0, null, ApprovalStatus::PENDING_VERIFICATION, [], $transaction->bill_no);
|
||||
|
||||
$transaction = $this->createsTransaction->execute($transaction, $object);
|
||||
} else {
|
||||
$request->route()->setParameter('id', $refund_transaction->id);
|
||||
$request->route()->setParameter('status', ApprovalStatus::APPROVED);
|
||||
$this->updateRefundTransactionStatusLogic->execute($request);
|
||||
|
||||
}
|
||||
|
||||
if($request->input('refundRemark')){
|
||||
$remarkObject = new RemarkObject($request->input('refundRemark'), Auth()->user()->id);
|
||||
$this->createRemarkProcessor->execute($this->fetchesTransaction->execute(['id' => $refund_transaction->id]), $remarkObject);
|
||||
}
|
||||
|
||||
return $this->resourceResponse(new TransactionResource($refund_transaction));
|
||||
}
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ class ExpireBookingPaymentControllerLogic extends AbstractControllerLogic
|
||||
$booking = $this->fetchesBooking->execute(['id' => $request->route('id')]);
|
||||
|
||||
$payment = $booking->transactions()
|
||||
->payments()->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])
|
||||
->payments()->whereIn('status', [ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])
|
||||
->first();
|
||||
|
||||
$payment->status = ApprovalStatus::EXPIRED;
|
||||
|
||||
@@ -18,7 +18,7 @@ class FetchBookingLogic extends AbstractControllerLogic
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Retrieved Address',
|
||||
'title' => 'Retrieved Booking',
|
||||
'message' => 'You have successfully retrieved a Address'
|
||||
];
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ use App\Classes\ValueObjects\Constants\PaymentMethodType;
|
||||
use App\Models\Booking;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Classes\Modules\Bookings\Services\CalculatesBookingRefundAmount;
|
||||
|
||||
class FetchBookingPaymentQuotationLogic extends AbstractControllerLogic
|
||||
{
|
||||
@@ -40,6 +41,9 @@ class FetchBookingPaymentQuotationLogic extends AbstractControllerLogic
|
||||
/** @var CalculatesBookingOutstanding */
|
||||
private $calculatesBookingOutstanding;
|
||||
|
||||
/** @var CalculatesBookingRefundAmount */
|
||||
private $calculatesBookingRefundAmount;
|
||||
|
||||
/**
|
||||
* FetchBookingPaymentQuotationLogic constructor.
|
||||
* @param FetchesBookingQuotation $fetchBookingQuotation
|
||||
@@ -47,12 +51,13 @@ class FetchBookingPaymentQuotationLogic extends AbstractControllerLogic
|
||||
* @param FetchesCompanyPaymentAttemptLimit $fetchesCompanyPaymentAttemptLimit
|
||||
* @param CalculatesBookingOutstanding $calculatesBookingOutstanding
|
||||
*/
|
||||
public function __construct(FetchesBookingQuotation $fetchBookingQuotation, GeneratesBookingQuotation $generatesBookingQuotation, FetchesCompanyPaymentAttemptLimit $fetchesCompanyPaymentAttemptLimit, CalculatesBookingOutstanding $calculatesBookingOutstanding)
|
||||
public function __construct(FetchesBookingQuotation $fetchBookingQuotation, GeneratesBookingQuotation $generatesBookingQuotation, FetchesCompanyPaymentAttemptLimit $fetchesCompanyPaymentAttemptLimit, CalculatesBookingOutstanding $calculatesBookingOutstanding, CalculatesBookingRefundAmount $calculatesBookingRefundAmount)
|
||||
{
|
||||
$this->fetchBookingQuotation = $fetchBookingQuotation;
|
||||
$this->generatesBookingQuotation = $generatesBookingQuotation;
|
||||
$this->fetchesCompanyPaymentAttemptLimit = $fetchesCompanyPaymentAttemptLimit;
|
||||
$this->calculatesBookingOutstanding = $calculatesBookingOutstanding;
|
||||
$this->calculatesBookingRefundAmount = $calculatesBookingRefundAmount;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,7 +71,7 @@ class FetchBookingPaymentQuotationLogic extends AbstractControllerLogic
|
||||
|
||||
$conversionObject = new CurrencyConversionObject(floatval(str_replace(',', '', $request->input('amount'))), $booking->convertible_currency_id, $booking->service_id, $booking->fix_currency_id === 1 ? 0:1, PaymentMethodType::PAYMENT_METHODS[$request->input('payment_method')]);
|
||||
|
||||
$outstanding = $this->calculatesBookingOutstanding->execute($booking);
|
||||
$outstanding = $this->calculatesBookingOutstanding->execute($booking) + $this->calculatesBookingRefundAmount->execute($booking, $booking->fix_currency_id);
|
||||
if($conversionObject->getAmount() > round($outstanding, 2)) throw new MalformedRequestException('Your payment must not be greater than '.$booking->fixedCurrency->short_code.' '. number_format((float)$outstanding, 2, '.', ','));
|
||||
|
||||
//Voucherify
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Classes\Modules\Bookings\ControllersLogic;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Jobs\ListBookingsJob;
|
||||
use App\Classes\Modules\Jobs\DataTransferObjects\ListGenericJobObject;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use App\Classes\Modules\Jobs\Services\CreatesJobResult;
|
||||
|
||||
|
||||
class ListBookingJobLogic extends AbstractControllerLogic
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'List Booking Job',
|
||||
'message' => 'You have successfully submit a job to list bookings'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CreatesJobResult */
|
||||
private $createsJobResult;
|
||||
|
||||
/**
|
||||
* ListPackingListsJobLogic constructor.
|
||||
* @param CreatesJobResult $createsJobResult
|
||||
*/
|
||||
public function __construct(CreatesJobResult $createsJobResult)
|
||||
{
|
||||
$this->createsJobResult = $createsJobResult;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$jobId = uniqid();
|
||||
|
||||
$user = Auth::user();
|
||||
$userInfo = (object) [
|
||||
'type' => $user->type,
|
||||
];
|
||||
|
||||
$userInfoJson = json_encode($userInfo);
|
||||
$requestSignature = md5($userInfoJson . $request->fullUrl());
|
||||
|
||||
$listGenericJobObject = new ListGenericJobObject(
|
||||
$request->fullUrl(),
|
||||
$request->all(),
|
||||
$requestSignature,
|
||||
null,
|
||||
$jobId,
|
||||
$userInfo
|
||||
);
|
||||
|
||||
ListBookingsJob::dispatch($listGenericJobObject)->onQueue('high_priority');
|
||||
|
||||
$result = [];
|
||||
$result['job_id'] = $jobId;
|
||||
|
||||
$this->createsJobResult->execute($listGenericJobObject);
|
||||
|
||||
return $this->response(['data' => $result]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -81,7 +81,7 @@ class UpdateBookingAmountLogic extends AbstractControllerLogic
|
||||
|
||||
$minimum_amount = $booking->fix_amount - $this->calculatesBookingOutstanding->execute($booking);
|
||||
|
||||
if ((float)$input_amount < $minimum_amount) {
|
||||
if (((float)$input_amount + 0.01) < (float)$minimum_amount) {
|
||||
throw new MalformedRequestException('Booking Amount cannot be less than '. $minimum_amount .'.');
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Bookings\ControllersLogic;
|
||||
|
||||
use App\Http\Resources\BookingResource;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
|
||||
use App\Classes\Modules\Bookings\Services\FetchesBooking;
|
||||
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use App\Classes\ValueObjects\Constants\BookingAttributeNames;
|
||||
|
||||
class UpdateBookingOrderReferenceLogic extends AbstractControllerLogic
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Updated Booking Order References',
|
||||
'message' => 'You have successfully updated the Booking Order References'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var FetchesBooking */
|
||||
private $fetchesBooking;
|
||||
|
||||
/**
|
||||
* UpdateBookingOrderReferenceLogic constructor.
|
||||
* @param FetchesBooking $fetchesBooking
|
||||
*/
|
||||
public function __construct(FetchesBooking $fetchesBooking)
|
||||
{
|
||||
$this->fetchesBooking = $fetchesBooking;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws MalformedRequestException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
if (!$request['order_reference_no']) {
|
||||
throw new MalformedRequestException('At least 1 order reference required.');
|
||||
}
|
||||
|
||||
if ($request['order_reference_no']) {
|
||||
foreach ($request['order_reference_no'] as $index => $reference) {
|
||||
if (!$reference) {
|
||||
$index += 1;
|
||||
throw new MalformedRequestException("Order reference {$index} cannot be empty");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$booking = $this->fetchesBooking->execute(['id' => $request->route('id')]);
|
||||
$booking->modelAttributes()->delete();
|
||||
|
||||
foreach ($request['order_reference_no'] as $order_reference) {
|
||||
$booking->modelAttributes()->create([
|
||||
'name' => BookingAttributeNames::ORDER_REFERENCE_NO,
|
||||
'value' => $order_reference
|
||||
]);
|
||||
}
|
||||
|
||||
return $this->resourceResponse(new BookingResource($booking));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Bookings\ControllersLogic;
|
||||
|
||||
use App\Http\Resources\BookingResource;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
|
||||
use App\Classes\Modules\Bookings\Services\FetchesBooking;
|
||||
|
||||
use App\Classes\Modules\Bookings\Standards\Rules\CanUpdateBooking;
|
||||
use App\Classes\Modules\Bookings\Services\UpdatesBooking;
|
||||
use App\Classes\Modules\Bookings\DataTransferObjects\BookingObject;
|
||||
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class UpdateBookingRecipientLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Updated Booking',
|
||||
'message' => 'You have successfully updated the Booking'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanUpdateBooking */
|
||||
private $canUpdateBooking;
|
||||
|
||||
/** @var UpdatesBooking */
|
||||
private $updatesBooking;
|
||||
|
||||
/** @var FetchesBooking */
|
||||
private $fetchesBooking;
|
||||
|
||||
|
||||
/**
|
||||
* UpdateBookingRecipientLogic constructor.
|
||||
* @param CanUpdateBooking $canUpdateBooking
|
||||
* @param UpdatesBooking $updatesBooking
|
||||
* @param FetchesBooking $fetchesBooking
|
||||
*/
|
||||
public function __construct(
|
||||
CanUpdateBooking $canUpdateBooking,
|
||||
UpdatesBooking $updatesBooking,
|
||||
FetchesBooking $fetchesBooking
|
||||
)
|
||||
{
|
||||
$this->canUpdateBooking = $canUpdateBooking;
|
||||
$this->updatesBooking = $updatesBooking;
|
||||
$this->fetchesBooking = $fetchesBooking;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
$booking = $this->fetchesBooking->execute(['id' => $request->route('id')]);
|
||||
|
||||
|
||||
$booking_object = new BookingObject(
|
||||
$booking->service_id,
|
||||
$request->input('transferable_bank_id', $booking->transferable_bank_id),
|
||||
$booking->marking,
|
||||
$booking->fix_amount,
|
||||
$booking->fix_currency_id,
|
||||
$booking->convertible_currency_id,
|
||||
$booking->conversion_currency_id
|
||||
);
|
||||
$this->canUpdateBooking->passes($booking_object);
|
||||
$booking = $this->updatesBooking->execute($booking, $booking_object);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return $this->resourceResponse(new BookingResource($booking));
|
||||
|
||||
} catch (\Exception $exception){
|
||||
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Bookings\Processors;
|
||||
|
||||
use App\Classes\Modules\Bookings\Services\ListsBookings;
|
||||
use App\Classes\Modules\Jobs\Processors\UpdateJobResultProcessor;
|
||||
use App\Classes\General\Helper;
|
||||
use App\Classes\Modules\Jobs\DataTransferObjects\ListGenericJobObject;
|
||||
use App\Http\Resources\ListBookingJobResource;
|
||||
|
||||
class ListBookingsJobProcessor
|
||||
{
|
||||
|
||||
/** @var ListsBookings */
|
||||
private $listsBookings;
|
||||
|
||||
/** @var UpdateJobResultProcessor */
|
||||
private $updateJobResultProcessor;
|
||||
|
||||
/**
|
||||
* ListBookingsJobProcessor constructor.
|
||||
* @param ListsBookings $listsBookings
|
||||
* @param UpdateJobResultProcessor $updateJobResultProcessor
|
||||
*/
|
||||
public function __construct(ListsBookings $listsBookings, UpdateJobResultProcessor $updateJobResultProcessor)
|
||||
{
|
||||
$this->listsBookings = $listsBookings;
|
||||
$this->updateJobResultProcessor = $updateJobResultProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ListGenericJobObject $listGenericJobObject
|
||||
* @return void
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
* @throws \App\Classes\Exceptions\JobResourceNotFoundException
|
||||
*/
|
||||
public function execute(ListGenericJobObject $listGenericJobObject) {
|
||||
|
||||
$query = $this->listsBookings->execute($this->listsBookings->deserializeFilters($listGenericJobObject->getPayload()['filters']), ['page' => $listGenericJobObject->getPayload()['page']]);
|
||||
foreach ($query->items() as &$item) {
|
||||
$item['userInfo'] = $listGenericJobObject->getUserInfo();
|
||||
}
|
||||
$resultCurrent = Helper::collectionResponse(ListBookingJobResource::collection($query));
|
||||
$this->updateJobResultProcessor->execute($listGenericJobObject, $resultCurrent);
|
||||
}
|
||||
}
|
||||
@@ -24,10 +24,22 @@ class CalculatesBookingCurrencyAverageRate
|
||||
|
||||
public function execute(Booking $booking, $type){
|
||||
|
||||
$transaction = $booking->transactions()
|
||||
->where('type', TransactionType::PAYMENT)
|
||||
->latest()->get()[0];
|
||||
|
||||
$voucherRedemption = $transaction->voucherRedemption;
|
||||
|
||||
$discount = 0;
|
||||
|
||||
if ($voucherRedemption) {
|
||||
$discount = $voucherRedemption->value;
|
||||
}
|
||||
|
||||
if ($type == TransactionType::PAYMENT) {
|
||||
$totalPayment = $booking->fix_currency_id === 1 ? $booking->transactions()->payments()->complete()->sum('original_amount') :
|
||||
$booking->transactions()->payments()->complete()->selectRaw('sum(amount - service_charge - tax) as sub_total')->get()->sum('sub_total');
|
||||
return $this->calculatesBookingPayableAmount->execute($booking, $booking->fix_currency_id) / $totalPayment;
|
||||
return $this->calculatesBookingPayableAmount->execute($booking, $booking->fix_currency_id) / ($totalPayment + $discount);
|
||||
|
||||
}
|
||||
else if ($type == TransactionType::BILL) {
|
||||
|
||||
@@ -13,20 +13,25 @@ class CalculatesBookingOutstanding
|
||||
/** @var CalculatesBookingFloatingAmount */
|
||||
private $calculatesBookingFloatingAmount;
|
||||
|
||||
/** @var CalculatesBookingRefundAmount */
|
||||
private $calculatesBookingRefundAmount;
|
||||
|
||||
/**
|
||||
* CalculatesBookingOutstanding constructor.
|
||||
* @param CalculatesBookingPayableAmount $calculatesBookingPayableAmount
|
||||
* @param CalculatesBookingFloatingAmount $calculatesBookingFloatingAmount
|
||||
* @param CalculatesBookingRefundAmount $calculatesBookingRefundAmount
|
||||
*/
|
||||
public function __construct(CalculatesBookingPayableAmount $calculatesBookingPayableAmount, CalculatesBookingFloatingAmount $calculatesBookingFloatingAmount)
|
||||
public function __construct(CalculatesBookingPayableAmount $calculatesBookingPayableAmount, CalculatesBookingFloatingAmount $calculatesBookingFloatingAmount, CalculatesBookingRefundAmount $calculatesBookingRefundAmount)
|
||||
{
|
||||
$this->calculatesBookingPayableAmount = $calculatesBookingPayableAmount;
|
||||
$this->calculatesBookingFloatingAmount = $calculatesBookingFloatingAmount;
|
||||
$this->calculatesBookingRefundAmount = $calculatesBookingRefundAmount;
|
||||
}
|
||||
|
||||
|
||||
public function execute(Booking $booking){
|
||||
return $booking->fix_amount - $this->calculatesBookingFloatingAmount->execute($booking, $booking->fix_currency_id) - $this->calculatesBookingPayableAmount->execute($booking, $booking->fix_currency_id);
|
||||
return $booking->fix_amount - $this->calculatesBookingFloatingAmount->execute($booking, $booking->fix_currency_id) - $this->calculatesBookingPayableAmount->execute($booking, $booking->fix_currency_id) + $this->calculatesBookingRefundAmount->execute($booking, $booking->fix_currency_id);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,19 +2,30 @@
|
||||
|
||||
namespace App\Classes\Modules\Bookings\Services;
|
||||
|
||||
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Models\Booking;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class CalculatesBookingRefundAmount
|
||||
{
|
||||
public function execute(Booking $booking, int $type, ?string $payment_reference = null): float
|
||||
{
|
||||
$refundAmounts = $booking->transactions()->payments()->complete()->get()->map(function ($payment) use ($type) {
|
||||
return $this->calculateRefundAmount($payment, $type);
|
||||
});
|
||||
|
||||
public function execute(Booking $booking, int $type, ?string $payment_reference = NULL){
|
||||
return $type === 1 ?
|
||||
$booking->transactions()->refunds($payment_reference)
|
||||
->selectRaw('sum(amount - service_charge - tax) as sub_total')->get()->sum('sub_total') : $booking->transactions()->refunds($payment_reference)->sum('original_amount');
|
||||
$totalRefundAmount = $refundAmounts->sum();
|
||||
|
||||
return $totalRefundAmount;
|
||||
}
|
||||
|
||||
}
|
||||
public function calculateRefundAmount($payment, int $type): float
|
||||
{
|
||||
$refundTransactions = $payment->transactions()->refunds()->whereIn('status', [ApprovalStatus::APPROVED]);
|
||||
|
||||
if ($type === 1) {
|
||||
return $refundTransactions->selectRaw('sum(amount - service_charge - tax) as sub_total')->get()->sum('sub_total');
|
||||
}
|
||||
|
||||
return $refundTransactions->sum('original_amount');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ class CalculatesBookingTransferredAmount
|
||||
|
||||
public function execute(Booking $booking){
|
||||
return $booking->transactions()->payments()->complete()->whereHas('transactions', function($query){
|
||||
return $query->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
|
||||
return $query->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->where('type', TransactionType::BILL);
|
||||
})->sum('original_amount');
|
||||
}
|
||||
|
||||
|
||||
@@ -11,8 +11,10 @@ use App\Classes\Modules\Vouchers\DataTransferObjects\ValidatedVoucherObject;
|
||||
use App\Classes\Modules\Vouchers\DataTransferObjects\ValidateVoucherifyVoucherObject;
|
||||
use App\Classes\Modules\Currencies\Services\FetchesCurrency;
|
||||
use App\Classes\Modules\Vouchers\Services\Voucherify\ValidatesVoucherifyVoucher;
|
||||
use App\Classes\Modules\Vouchers\Services\Voucherify\FetchesVoucherifyRedemption;
|
||||
use App\Models\Company;
|
||||
use App\Models\Currency;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class FetchesBookingQuotation
|
||||
{
|
||||
@@ -26,27 +28,34 @@ class FetchesBookingQuotation
|
||||
/** @var ValidatesVoucherifyVoucher */
|
||||
private $validatesVoucherifyVoucher;
|
||||
|
||||
/** @var FetchesVoucherifyRedemption */
|
||||
private $fetchesVoucherifyRedemption;
|
||||
|
||||
/**
|
||||
* FetchesBookingQuotation constructor.
|
||||
* @param FetchesCompanyServiceSettings $fetchesCompanyServiceSettings
|
||||
* @param FetchesCurrency $fetchesCurrency
|
||||
* @param ValidatesVoucherifyVoucher $validatesVoucherifyVoucher
|
||||
* @param FetchesVoucherifyRedemption $fetchesVoucherifyRedemption
|
||||
*/
|
||||
public function __construct(FetchesCompanyServiceSettings $fetchesCompanyServiceSettings, FetchesCurrency $fetchesCurrency, ValidatesVoucherifyVoucher $validatesVoucherifyVoucher)
|
||||
public function __construct(FetchesCompanyServiceSettings $fetchesCompanyServiceSettings, FetchesCurrency $fetchesCurrency, ValidatesVoucherifyVoucher $validatesVoucherifyVoucher, FetchesVoucherifyRedemption $fetchesVoucherifyRedemption)
|
||||
{
|
||||
$this->fetchesCompanyServiceSettings = $fetchesCompanyServiceSettings;
|
||||
$this->fetchesCurrency = $fetchesCurrency;
|
||||
$this->validatesVoucherifyVoucher = $validatesVoucherifyVoucher;
|
||||
$this->fetchesVoucherifyRedemption = $fetchesVoucherifyRedemption;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Company $company
|
||||
* @param CurrencyConversionObject $conversionObject
|
||||
* @param string $voucherCode
|
||||
* @param null|string $voucherCode
|
||||
* @param null|string $redemptionId
|
||||
* @return CalculationObject
|
||||
* @throws MalformedRequestException
|
||||
*/
|
||||
public function execute(Company $company, CurrencyConversionObject $conversionObject, ?string $voucherCode = null){
|
||||
public function execute(Company $company, CurrencyConversionObject $conversionObject, ?string $voucherCode = null, ?string $redemptionId = null){
|
||||
if($conversionObject->getAmount() <= 0) throw new MalformedRequestException('Your transfer must be greater than zero.');
|
||||
|
||||
$configurations = $this->fetchesCompanyServiceSettings->execute($company, $conversionObject);
|
||||
@@ -57,10 +66,30 @@ class FetchesBookingQuotation
|
||||
|
||||
$calculationObject = new CalculationObject($conversionObject, $configurations, null);
|
||||
|
||||
$voucher = null;
|
||||
|
||||
//Voucherify
|
||||
if($voucherCode){
|
||||
$employee = $company->employees()->first();
|
||||
$validateVoucherifyVoucherObject = new ValidateVoucherifyVoucherObject($company->id, $voucherCode, $calculationObject->getSubTotal(), $employee);
|
||||
$employeeWhoOwnsTheVoucher = null;
|
||||
|
||||
$employees = $company->first()->employees;
|
||||
if(count($employees) > 1){
|
||||
foreach($employees as $singleEmployee){
|
||||
$userRewards = $singleEmployee->rewards;
|
||||
foreach($userRewards as $userReward){
|
||||
if ($userReward->voucher && $userReward->voucher->code === $voucherCode) {
|
||||
Log::info('1. Company with multiple employees: ' . json_encode($singleEmployee) . ", voucher: " . $voucherCode);
|
||||
$employeeWhoOwnsTheVoucher = $singleEmployee;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!$employeeWhoOwnsTheVoucher){
|
||||
$employeeWhoOwnsTheVoucher = $company->employees()->first();
|
||||
}
|
||||
|
||||
$validateVoucherifyVoucherObject = new ValidateVoucherifyVoucherObject($company->id, $voucherCode, $calculationObject->getSubTotal(), $employeeWhoOwnsTheVoucher);
|
||||
$result = $this->validatesVoucherifyVoucher->execute($validateVoucherifyVoucherObject);
|
||||
$voucher = [
|
||||
"code" => $result->code,
|
||||
@@ -68,7 +97,24 @@ class FetchesBookingQuotation
|
||||
"metadata" => $result->metadata,
|
||||
"order" => $result->order,
|
||||
];
|
||||
$validatedVoucherObject = new ValidatedVoucherObject(isset($voucher['metadata']->name) ? $voucher['metadata']->name: "", $voucher['code'], $voucher['discount']->type ?? 'AMOUNT', $voucher['order']->total_discount_amount, $voucher['order']->total_amount);
|
||||
}
|
||||
else if($redemptionId){
|
||||
$result = $this->fetchesVoucherifyRedemption->execute($redemptionId);
|
||||
$voucher = [
|
||||
"code" => $result->voucher->code ?? null,
|
||||
"discount" => null,
|
||||
"metadata" => null,
|
||||
"order" => $result->order ?? null,
|
||||
];
|
||||
}
|
||||
|
||||
if($voucher){
|
||||
$validatedVoucherObject = new ValidatedVoucherObject(
|
||||
isset($voucher['metadata']->name) ? $voucher['metadata']->name : "",
|
||||
$voucher['code'],
|
||||
$voucher['discount']->type ?? 'AMOUNT',
|
||||
$voucher['order']->total_discount_amount,
|
||||
$voucher['order']->total_amount);
|
||||
$calculationObject = new CalculationObject($conversionObject, $configurations, $validatedVoucherObject);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,31 @@ class GeneratesBookingQuotation
|
||||
$hours = $date->diffInHours($date->copy()->addMinutes($paymentAttemptLimit)->subDays($days)) ;
|
||||
$minutes = $date->diffInMinutes($date->copy()->addMinutes($paymentAttemptLimit)->subDays($days)->subHours($hours));
|
||||
|
||||
$receive_date = $currencyConversionObject ? Carbon::now()->endOfDay()->addWeekdays($currencyConversionObject->getServiceId() === 3 ? 3 : 1)->timezone('Asia/Singapore')->format('4:00 \P\M, jS M, Y \G\M\T T') : null;
|
||||
// Initialize $receive_date to null by default
|
||||
$receive_date = null;
|
||||
|
||||
if ($currencyConversionObject) {
|
||||
$serviceId = $currencyConversionObject->getServiceId();
|
||||
|
||||
switch ($serviceId) {
|
||||
case 3:
|
||||
$daysToAdd = 3;
|
||||
break;
|
||||
case 5:
|
||||
$daysToAdd = 7;
|
||||
break;
|
||||
default:
|
||||
$daysToAdd = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
$receive_date = Carbon::now()
|
||||
->endOfDay()
|
||||
->addWeekdays($daysToAdd)
|
||||
->timezone('Asia/Singapore')
|
||||
->format('4:00 \P\M, jS M, Y \G\M\T T');
|
||||
}
|
||||
|
||||
|
||||
return [
|
||||
'bank' => new BankResource(Bank::find($calculationObject->getConfigurations()->getBankId())),
|
||||
|
||||
@@ -25,7 +25,7 @@ class CanCreateBooking extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ class CanDeleteBooking extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ class CanFetchBooking extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user