mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
Code sync from Shipping Portal, independent deployment of Vue Polling, Performance Improvement and tweaking for better user experience
This commit is contained in:
@@ -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,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');
|
||||
}
|
||||
}
|
||||
@@ -5,12 +5,12 @@ namespace App\Classes\Modules\Bookings\ControllersLogic;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Jobs\ListBookingsJob;
|
||||
use App\Classes\Modules\Bookings\Standards\Rules\CanListBookings;
|
||||
use App\Classes\Modules\Jobs\DataTransferObjects\ListGenericJobObject;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use App\Classes\Modules\Jobs\Services\CreatesJobResult;
|
||||
|
||||
|
||||
class ListBookingJobLogic extends AbstractControllerLogic
|
||||
{
|
||||
@@ -24,6 +24,19 @@ class ListBookingJobLogic extends AbstractControllerLogic
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CreatesJobResult */
|
||||
private $createsJobResult;
|
||||
|
||||
/**
|
||||
* ListPackingListsJobLogic constructor.
|
||||
* @param CreatesJobResult $createsJobResult
|
||||
*/
|
||||
public function __construct(CreatesJobResult $createsJobResult)
|
||||
{
|
||||
$this->createsJobResult = $createsJobResult;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
@@ -34,13 +47,17 @@ class ListBookingJobLogic extends AbstractControllerLogic
|
||||
|
||||
$user = Auth::user();
|
||||
$userInfo = (object) [
|
||||
'email' => $user->email,
|
||||
'type' => $user->type,
|
||||
];
|
||||
|
||||
$userInfoJson = json_encode($userInfo);
|
||||
$requestSignature = md5($userInfoJson . $request->fullUrl());
|
||||
|
||||
$listGenericJobObject = new ListGenericJobObject(
|
||||
$request->fullUrl(),
|
||||
$request->all(),
|
||||
$requestSignature,
|
||||
null,
|
||||
$jobId,
|
||||
$userInfo
|
||||
);
|
||||
@@ -50,6 +67,8 @@ class ListBookingJobLogic extends AbstractControllerLogic
|
||||
$result = [];
|
||||
$result['job_id'] = $jobId;
|
||||
|
||||
$this->createsJobResult->execute($listGenericJobObject);
|
||||
|
||||
return $this->response(['data' => $result]);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,14 +3,10 @@
|
||||
namespace App\Classes\Modules\Bookings\Processors;
|
||||
|
||||
use App\Classes\Modules\Bookings\Services\ListsBookings;
|
||||
use App\Classes\Modules\Jobs\Services\CreatesJobResult;
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use App\Classes\Modules\Jobs\Processors\UpdateJobResultProcessor;
|
||||
use App\Classes\General\Helper;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\Classes\Modules\Jobs\DataTransferObjects\ListGenericJobObject;
|
||||
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||
use App\Http\Resources\BookingResource;
|
||||
use App\Http\Resources\ListBookingJobResource;
|
||||
|
||||
class ListBookingsJobProcessor
|
||||
{
|
||||
@@ -18,24 +14,25 @@ class ListBookingsJobProcessor
|
||||
/** @var ListsBookings */
|
||||
private $listsBookings;
|
||||
|
||||
/** @var CreatesJobResult */
|
||||
private $createsJobResult;
|
||||
/** @var UpdateJobResultProcessor */
|
||||
private $updateJobResultProcessor;
|
||||
|
||||
/**
|
||||
* ListBookingsJobProcessor constructor.
|
||||
* @param ListsBookings $listsBookings
|
||||
* @param CreatesJobResult $createsJobResult
|
||||
* @param UpdateJobResultProcessor $updateJobResultProcessor
|
||||
*/
|
||||
public function __construct(ListsBookings $listsBookings, CreatesJobResult $createsJobResult)
|
||||
public function __construct(ListsBookings $listsBookings, UpdateJobResultProcessor $updateJobResultProcessor)
|
||||
{
|
||||
$this->listsBookings = $listsBookings;
|
||||
$this->createsJobResult = $createsJobResult;
|
||||
$this->updateJobResultProcessor = $updateJobResultProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ListGenericJobObject $listGenericJobObject
|
||||
* @return null|object
|
||||
* @return void
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
* @throws \App\Classes\Exceptions\JobResourceNotFoundException
|
||||
*/
|
||||
public function execute(ListGenericJobObject $listGenericJobObject) {
|
||||
|
||||
@@ -43,15 +40,7 @@ class ListBookingsJobProcessor
|
||||
foreach ($query->items() as &$item) {
|
||||
$item['userInfo'] = $listGenericJobObject->getUserInfo();
|
||||
}
|
||||
|
||||
//cief todo: remove comments
|
||||
$result = Helper::collectionResponse(BookingResource::collection($query));
|
||||
|
||||
// $result = new JobBookingCollectionResponse($query, $listGenericJobObject->getuserInfo());
|
||||
// $result = $this->collectionResponse(new BookingResourceCollection(BookingResource::collection($query), $listGenericJobObject->getuserInfo()));
|
||||
|
||||
$create = $this->createsJobResult->execute($listGenericJobObject, json_encode($result));
|
||||
|
||||
return $create;
|
||||
$resultCurrent = Helper::collectionResponse(ListBookingJobResource::collection($query));
|
||||
$this->updateJobResultProcessor->execute($listGenericJobObject, $resultCurrent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,15 +4,11 @@ namespace App\Classes\Modules\Documents\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Documents\Services\ListsDocuments;
|
||||
use App\Classes\Modules\Jobs\Services\CreatesJobResult;
|
||||
use App\Classes\Modules\Jobs\DataTransferObjects\ListGenericJobObject;
|
||||
use App\Classes\Jobs\ListDocumentsJob;
|
||||
use App\Http\Resources\DocumentResource;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Classes\General\Helper;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class ListDocumentJobLogic extends AbstractControllerLogic
|
||||
@@ -28,6 +24,19 @@ class ListDocumentJobLogic extends AbstractControllerLogic
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CreatesJobResult */
|
||||
private $createsJobResult;
|
||||
|
||||
/**
|
||||
* ListDocumentJobLogic constructor.
|
||||
* @param CreatesJobResult $createsJobResult
|
||||
*/
|
||||
public function __construct(CreatesJobResult $createsJobResult)
|
||||
{
|
||||
$this->createsJobResult = $createsJobResult;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
@@ -42,33 +51,25 @@ class ListDocumentJobLogic extends AbstractControllerLogic
|
||||
'type' => $user->type,
|
||||
];
|
||||
|
||||
$userInfoJson = json_encode($userInfo);
|
||||
$requestSignature = md5($userInfoJson . $request->fullUrl());
|
||||
|
||||
$listGenericJobObject = new ListGenericJobObject(
|
||||
$request->fullUrl(),
|
||||
$request->all(),
|
||||
$requestSignature,
|
||||
null,
|
||||
$jobId,
|
||||
$userInfo
|
||||
);
|
||||
|
||||
ListDocumentsJob::dispatch($listGenericJobObject);
|
||||
|
||||
//cief todo: remove comments
|
||||
// // Create your job instance with delay, so we can back here within delay and take control in our hands.
|
||||
// $job = new ListDocuments($listGenericJobObject);
|
||||
// $job->delay(now()->addSeconds(5));
|
||||
|
||||
// // Dispath your job with our custom_dispatch helper. This will return job id from jobs table
|
||||
// // $jobId = $this->custom_dispatch($job);
|
||||
|
||||
|
||||
$result = [];
|
||||
$result['job_id'] = $jobId;
|
||||
|
||||
$this->createsJobResult->execute($listGenericJobObject);
|
||||
|
||||
return $this->response(['data' => $result]);
|
||||
}
|
||||
|
||||
//cief todo: no longer need jobId
|
||||
// function custom_dispatch($job): int {
|
||||
// return app(\Illuminate\Contracts\Bus\Dispatcher::class)->dispatch($job);
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -3,15 +3,10 @@
|
||||
namespace App\Classes\Modules\Documents\Processors;
|
||||
|
||||
use App\Classes\Modules\Documents\Services\ListsDocuments;
|
||||
use App\Classes\Modules\Jobs\Services\CreatesJobResult;
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use App\Classes\Modules\Jobs\Processors\UpdateJobResultProcessor;
|
||||
use App\Classes\General\Helper;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\Classes\Modules\Jobs\DataTransferObjects\ListGenericJobObject;
|
||||
use App\Http\Controllers\Documents\ListDocumentsController;
|
||||
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||
use App\Http\Resources\DocumentResource;
|
||||
use App\Http\Resources\ListDocumentJobResource;
|
||||
|
||||
class ListDocumentsJobProcessor
|
||||
{
|
||||
@@ -19,24 +14,25 @@ class ListDocumentsJobProcessor
|
||||
/** @var ListsDocuments */
|
||||
private $listsDocuments;
|
||||
|
||||
/** @var CreatesJobResult */
|
||||
private $createsJobResult;
|
||||
/** @var UpdateJobResultProcessor */
|
||||
private $updateJobResultProcessor;
|
||||
|
||||
/**
|
||||
* ListDocumentsJobProcessor constructor.
|
||||
* @param ListsDocuments $listsDocuments
|
||||
* @param CreatesJobResult $createsJobResult
|
||||
* @param UpdateJobResultProcessor $updateJobResultProcessor
|
||||
*/
|
||||
public function __construct(ListsDocuments $listsDocuments, CreatesJobResult $createsJobResult)
|
||||
public function __construct(ListsDocuments $listsDocuments, UpdateJobResultProcessor $updateJobResultProcessor)
|
||||
{
|
||||
$this->listsDocuments = $listsDocuments;
|
||||
$this->createsJobResult = $createsJobResult;
|
||||
$this->updateJobResultProcessor = $updateJobResultProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ListGenericJobObject $listGenericJobObject
|
||||
* @return null|object
|
||||
* @return void
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
* @throws \App\Classes\Exceptions\JobResourceNotFoundException
|
||||
*/
|
||||
public function execute(ListGenericJobObject $listGenericJobObject) {
|
||||
|
||||
@@ -44,11 +40,8 @@ class ListDocumentsJobProcessor
|
||||
foreach ($query->items() as &$item) {
|
||||
$item['userInfo'] = $listGenericJobObject->getUserInfo();
|
||||
}
|
||||
|
||||
$result = Helper::collectionResponse(DocumentResource::collection($query));
|
||||
|
||||
$create = $this->createsJobResult->execute($listGenericJobObject, json_encode($result));
|
||||
|
||||
return $create;
|
||||
$resultCurrent = Helper::collectionResponse(ListDocumentJobResource::collection($query));
|
||||
$this->updateJobResultProcessor->execute($listGenericJobObject, $resultCurrent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,9 +4,8 @@ namespace App\Classes\Modules\Jobs\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Jobs\Services\FetchesJobResult;
|
||||
use App\Classes\Modules\Jobs\Processors\FetchesJobResultProcessor;
|
||||
use App\Http\Resources\JobResultResource;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
@@ -23,16 +22,16 @@ class FetchJobResultLogic extends AbstractControllerLogic
|
||||
];
|
||||
}
|
||||
|
||||
/** @var FetchesJobResult */
|
||||
private $fetchesJobResult;
|
||||
/** @var FetchesJobResultProcessor */
|
||||
private $fetchesJobResultProcessor;
|
||||
|
||||
/**
|
||||
* FetchJobResultLogic constructor.
|
||||
* @param FetchesJobResult $fetchesJobResult
|
||||
* @param FetchesJobResultProcessor $fetchesJobResultProcessor
|
||||
*/
|
||||
public function __construct(FetchesJobResult $fetchesJobResult)
|
||||
public function __construct(FetchesJobResultProcessor $fetchesJobResultProcessor)
|
||||
{
|
||||
$this->fetchesJobResult = $fetchesJobResult;
|
||||
$this->fetchesJobResultProcessor = $fetchesJobResultProcessor;
|
||||
}
|
||||
|
||||
|
||||
@@ -45,10 +44,8 @@ class FetchJobResultLogic extends AbstractControllerLogic
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$query = $this->fetchesJobResult->execute(['job_id' => $request->route('job_id')]);
|
||||
|
||||
$query = $this->fetchesJobResultProcessor->execute($request);
|
||||
return $this->resourceResponse(new JobResultResource($query));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Classes\Modules\Jobs\DataTransferObjects;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Classes\General\Interfaces\DataTransferObject;
|
||||
|
||||
class ListGenericJobObject implements DataTransferObject
|
||||
@@ -16,6 +15,12 @@ class ListGenericJobObject implements DataTransferObject
|
||||
/** @var string */
|
||||
private $jobId;
|
||||
|
||||
/** @var string */
|
||||
private $requestSignature;
|
||||
|
||||
/** @var string */
|
||||
private $resultSignature;
|
||||
|
||||
/** @var object */
|
||||
private $userInfo;
|
||||
|
||||
@@ -25,11 +30,13 @@ class ListGenericJobObject implements DataTransferObject
|
||||
/** @var string */
|
||||
private $jobCommand;
|
||||
|
||||
public function __construct(string $name, array $payload, string $jobId, object $userInfo = null)
|
||||
public function __construct(string $name, array $payload, string $requestSignature, ?string $resultSignature, string $jobId, object $userInfo = null)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->payload = $payload;
|
||||
$this->jobId = $jobId;
|
||||
$this->requestSignature = $requestSignature;
|
||||
$this->resultSignature = $resultSignature;
|
||||
$this->userInfo = $userInfo;
|
||||
}
|
||||
|
||||
@@ -57,6 +64,22 @@ class ListGenericJobObject implements DataTransferObject
|
||||
return $this->jobId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getRequestSignature(): string
|
||||
{
|
||||
return $this->requestSignature;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getResultSignature(): ?string
|
||||
{
|
||||
return $this->resultSignature;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return object
|
||||
*/
|
||||
@@ -81,10 +104,6 @@ class ListGenericJobObject implements DataTransferObject
|
||||
return $this->jobCommand;
|
||||
}
|
||||
|
||||
// public function setJobId(int $jobId)
|
||||
// {
|
||||
// $this->jobId = $jobId;
|
||||
// }
|
||||
|
||||
public function setJobCommandName(string $jobCommandName)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Jobs\DataTransferObjects;
|
||||
|
||||
use App\Classes\General\Interfaces\DataTransferObject;
|
||||
|
||||
class UpdateJobResultObject implements DataTransferObject
|
||||
{
|
||||
/** @var string */
|
||||
private $result;
|
||||
|
||||
/** @var string */
|
||||
private $resultSignature;
|
||||
|
||||
/** @var string */
|
||||
private $jobCommandName;
|
||||
|
||||
/** @var string */
|
||||
private $jobCommand;
|
||||
|
||||
public function __construct(string $result, string $resultSignature, string $jobCommandName, string $jobCommand)
|
||||
{
|
||||
$this->result = $result;
|
||||
$this->resultSignature = $resultSignature;
|
||||
$this->jobCommandName = $jobCommandName;
|
||||
$this->jobCommand = $jobCommand;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getResult(): string
|
||||
{
|
||||
return $this->result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getResultSignature(): string
|
||||
{
|
||||
return $this->resultSignature;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getJobCommandName(): string
|
||||
{
|
||||
return $this->jobCommandName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getJobCommand(): string
|
||||
{
|
||||
return $this->jobCommand;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Jobs\Processors;
|
||||
|
||||
use App\Classes\Modules\Jobs\Services\FetchesJobResult;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class FetchesJobResultProcessor
|
||||
{
|
||||
/** @var FetchesJobResult */
|
||||
private $fetchesJobResult;
|
||||
|
||||
|
||||
/**
|
||||
* FetchesJobResultProcessor constructor.
|
||||
* @param FetchesJobResult $fetchesJobResult
|
||||
*/
|
||||
public function __construct(FetchesJobResult $fetchesJobResult)
|
||||
{
|
||||
$this->fetchesJobResult = $fetchesJobResult;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
* @throws \App\Classes\Exceptions\JobResourceNotFoundException
|
||||
* @throws \App\Classes\Exceptions\ResourceNotFoundException
|
||||
*/
|
||||
public function execute(Request $request){
|
||||
|
||||
$res1 = $this->fetchesJobResult->execute(['job_id' => $request->route('job_id')]);
|
||||
|
||||
if(!$res1->result){
|
||||
Log::info('Job id: '.$request->route('job_id'));
|
||||
$res2 = $this->fetchesJobResult->execute(['request_signature' => $res1->request_signature, 'result_not_null' => true, 'order_by_id_desc' => true]);
|
||||
Log::info('Job id: '.$res2->id." , request_signature: ".$res2->request_signature);
|
||||
return $res2;
|
||||
}
|
||||
|
||||
return $res1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Jobs\Processors;
|
||||
|
||||
|
||||
use App\Classes\Modules\Jobs\Services\UpdatesJobResult;
|
||||
use App\Classes\Modules\Jobs\Services\FetchesJobResult;
|
||||
use App\Classes\Exceptions\JobResourceNotFoundException;
|
||||
use App\Classes\Modules\Jobs\DataTransferObjects\ListGenericJobObject;
|
||||
use App\Classes\Modules\Jobs\DataTransferObjects\UpdateJobResultObject;
|
||||
|
||||
class UpdateJobResultProcessor
|
||||
{
|
||||
|
||||
/** @var FetchesJobResult */
|
||||
private $fetchesJobResult;
|
||||
|
||||
/** @var UpdatesJobResult */
|
||||
private $updatesJobResult;
|
||||
|
||||
/**
|
||||
* UpdateJobResultProcessor constructor.
|
||||
* @param FetchesJobResult $fetchesJobResult
|
||||
* @param UpdatesJobResult $updatesJobResult
|
||||
*/
|
||||
public function __construct(FetchesJobResult $fetchesJobResult, UpdatesJobResult $updatesJobResult)
|
||||
{
|
||||
$this->fetchesJobResult = $fetchesJobResult;
|
||||
$this->updatesJobResult = $updatesJobResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ListGenericJobObject $listGenericJobObject
|
||||
* @param array $resultCurrent
|
||||
* @return void
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
* @throws \App\Classes\Exceptions\JobResourceNotFoundException
|
||||
*/
|
||||
public function execute(ListGenericJobObject $listGenericJobObject, $resultCurrent) {
|
||||
$jobResultCurrent = $this->fetchesJobResult->execute(['job_id' => $listGenericJobObject->getJobId()]);
|
||||
$resultCurrentJson = json_encode($resultCurrent);
|
||||
$resultSignatureCurrent = md5($resultCurrentJson);
|
||||
|
||||
try{
|
||||
$jobResultExisting = $this->fetchesJobResult->execute(['request_signature' => $jobResultCurrent->request_signature, 'result_not_null' => true, 'order_by_id_desc' => true]);
|
||||
$resultSignatureExisting = $jobResultExisting->result_signature;
|
||||
if($resultSignatureExisting != $resultSignatureCurrent){
|
||||
$this->updateJobResult($jobResultCurrent, $resultCurrentJson, $resultSignatureCurrent, $listGenericJobObject->getJobCommandName(), $listGenericJobObject->getJobCommand());
|
||||
}
|
||||
} catch (JobResourceNotFoundException $exception){
|
||||
$this->updateJobResult($jobResultCurrent, $resultCurrentJson, $resultSignatureCurrent, $listGenericJobObject->getJobCommandName(), $listGenericJobObject->getJobCommand());
|
||||
}
|
||||
}
|
||||
|
||||
private function updateJobResult($jobResultCurrent, $resultCurrentJson, $resultSignatureCurrent, $jobCommandName, $jobCommand){
|
||||
$updateJobResultObject = new UpdateJobResultObject(
|
||||
$resultCurrentJson,
|
||||
$resultSignatureCurrent,
|
||||
$jobCommandName,
|
||||
$jobCommand
|
||||
);
|
||||
$create = $this->updatesJobResult->execute($jobResultCurrent, $updateJobResultObject);
|
||||
}
|
||||
}
|
||||
@@ -10,18 +10,16 @@ class CreatesJobResult extends AbstractUpdateRecord
|
||||
{
|
||||
/**
|
||||
* @param ListGenericJobObject $listGenericJobObject
|
||||
* @param string $result
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(ListGenericJobObject $listGenericJobObject, string $result)
|
||||
public function execute(ListGenericJobObject $listGenericJobObject)
|
||||
{
|
||||
$model = new JobResult();
|
||||
$model->job_id = $listGenericJobObject->getJobId();
|
||||
$model->result = $result;
|
||||
$model->request_signature = $listGenericJobObject->getRequestSignature();
|
||||
$model->result_signature = $listGenericJobObject->getResultSignature();
|
||||
$model->url = $listGenericJobObject->getName();
|
||||
$model->job_command_name = $listGenericJobObject->getJobCommandName();
|
||||
$model->job_command = $listGenericJobObject->getJobCommand();
|
||||
|
||||
return $this->handler($model);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Jobs\Services;
|
||||
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractListRecord;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Models\JobResult;
|
||||
|
||||
class ListsJobResult extends AbstractListRecord
|
||||
{
|
||||
|
||||
/** @var JobResult */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* ListsJobResult constructor.
|
||||
* @param JobResult $repository
|
||||
*/
|
||||
public function __construct(JobResult $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Builder
|
||||
*/
|
||||
function getRepository(): Builder
|
||||
{
|
||||
return $this->repository->newQuery();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Jobs\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\Modules\Jobs\DataTransferObjects\UpdateJobResultObject;
|
||||
use App\Models\JobResult;
|
||||
|
||||
class UpdatesJobResult extends AbstractUpdateRecord
|
||||
{
|
||||
|
||||
/**
|
||||
* @param JobResult $model
|
||||
* @param UpdateJobResultObject $updateJobResultObject
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(JobResult $model, UpdateJobResultObject $updateJobResultObject) {
|
||||
|
||||
$model->result = $updateJobResultObject->getResult();
|
||||
$model->result_signature = $updateJobResultObject->getResultSignature();
|
||||
$model->job_command_name = $updateJobResultObject->getJobCommandName();
|
||||
$model->job_command = $updateJobResultObject->getJobCommand();
|
||||
|
||||
return $this->handler($model);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -5,10 +5,11 @@ namespace App\Classes\Modules\Transactions\ControllersLogic;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Jobs\ListTransactionsJob;
|
||||
use App\Classes\Modules\Jobs\Services\CreatesJobResult;
|
||||
use App\Classes\Modules\Jobs\DataTransferObjects\ListGenericJobObject;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class ListTransactionsJobLogic extends AbstractControllerLogic
|
||||
{
|
||||
@@ -22,6 +23,19 @@ class ListTransactionsJobLogic extends AbstractControllerLogic
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CreatesJobResult */
|
||||
private $createsJobResult;
|
||||
|
||||
/**
|
||||
* ListTransactionsJobLogic constructor.
|
||||
* @param CreatesJobResult $createsJobResult
|
||||
*/
|
||||
public function __construct(CreatesJobResult $createsJobResult)
|
||||
{
|
||||
$this->createsJobResult = $createsJobResult;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
@@ -30,10 +44,21 @@ class ListTransactionsJobLogic extends AbstractControllerLogic
|
||||
{
|
||||
$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(),
|
||||
$jobId
|
||||
$requestSignature,
|
||||
null,
|
||||
$jobId,
|
||||
$userInfo
|
||||
);
|
||||
|
||||
ListTransactionsJob::dispatch($listGenericJobObject);
|
||||
@@ -41,6 +66,8 @@ class ListTransactionsJobLogic extends AbstractControllerLogic
|
||||
$result = [];
|
||||
$result['job_id'] = $jobId;
|
||||
|
||||
$this->createsJobResult->execute($listGenericJobObject);
|
||||
|
||||
return $this->response(['data' => $result]);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,14 +3,10 @@
|
||||
namespace App\Classes\Modules\Transactions\Processors;
|
||||
|
||||
use App\Classes\Modules\Transactions\Services\ListsTransactions;
|
||||
use App\Classes\Modules\Jobs\Services\CreatesJobResult;
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use App\Classes\Modules\Jobs\Processors\UpdateJobResultProcessor;
|
||||
use App\Classes\General\Helper;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\Classes\Modules\Jobs\DataTransferObjects\ListGenericJobObject;
|
||||
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||
use App\Http\Resources\TransactionResource;
|
||||
use App\Http\Resources\ListTransactionJobResource;
|
||||
|
||||
class ListTransactionsJobProcessor
|
||||
{
|
||||
@@ -18,33 +14,32 @@ class ListTransactionsJobProcessor
|
||||
/** @var ListsTransactions */
|
||||
private $listsTransactions;
|
||||
|
||||
/** @var CreatesJobResult */
|
||||
private $createsJobResult;
|
||||
/** @var UpdateJobResultProcessor */
|
||||
private $updateJobResultProcessor;
|
||||
|
||||
/**
|
||||
* ListTransactionsJobProcessor constructor.
|
||||
* @param ListsTransactions $listsTransactions
|
||||
* @param CreatesJobResult $createsJobResult
|
||||
* @param UpdateJobResultProcessor $updateJobResultProcessor
|
||||
*/
|
||||
public function __construct(ListsTransactions $listsTransactions, CreatesJobResult $createsJobResult)
|
||||
public function __construct(ListsTransactions $listsTransactions, UpdateJobResultProcessor $updateJobResultProcessor)
|
||||
{
|
||||
$this->listsTransactions = $listsTransactions;
|
||||
$this->createsJobResult = $createsJobResult;
|
||||
$this->updateJobResultProcessor = $updateJobResultProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ListGenericJobObject $listGenericJobObject
|
||||
* @return null|object
|
||||
* @return void
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
* @throws \App\Classes\Exceptions\JobResourceNotFoundException
|
||||
*/
|
||||
public function execute(ListGenericJobObject $listGenericJobObject) {
|
||||
|
||||
$query = $this->listsTransactions->execute($this->listsTransactions->deserializeFilters($listGenericJobObject->getPayload()['filters']), ['page' => $listGenericJobObject->getPayload()['page']]);
|
||||
|
||||
$result = Helper::collectionResponse(TransactionResource::collection($query));
|
||||
|
||||
$create = $this->createsJobResult->execute($listGenericJobObject, json_encode($result));
|
||||
|
||||
return $create;
|
||||
$resultCurrent = Helper::collectionResponse(ListTransactionJobResource::collection($query));
|
||||
$this->updateJobResultProcessor->execute($listGenericJobObject, $resultCurrent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,19 +11,9 @@ use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Classes\ValueObjects\Constants\DocumentType;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class BookingResource extends JsonResource
|
||||
{
|
||||
private $userInfo;
|
||||
|
||||
public function __construct($resource, $userInfo = null)
|
||||
{
|
||||
parent::__construct($resource);
|
||||
$this->userInfo = $userInfo ?? ($resource->userInfo ?? null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
@@ -35,7 +25,7 @@ class BookingResource extends JsonResource
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'company' => new CompanyResource($this->company, $this->userInfo),
|
||||
'company' => new CompanyResource($this->company),
|
||||
'bank' => new BankResource($this->bank),
|
||||
'service' => new ServiceTypeResource($this->service),
|
||||
'marking' => $this->marking,
|
||||
|
||||
@@ -15,18 +15,9 @@ use App\Models\SegmentConstant;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class CompanyResource extends JsonResource
|
||||
{
|
||||
private $userInfo;
|
||||
|
||||
public function __construct($resource, $userInfo = null)
|
||||
{
|
||||
parent::__construct($resource);
|
||||
$this->userInfo = $userInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
@@ -41,26 +32,6 @@ class CompanyResource extends JsonResource
|
||||
$segment = SegmentConstant::where('reference', SegmentConstants::SUPPLIER_CURRENCIES)->where('detail->id', $this->id)->first();
|
||||
$serviceCharge = SegmentConstant::where('reference', SegmentConstants::SERVICE_CHARGE)->where('detail->id', $this->id)->first();
|
||||
|
||||
$userResource = null;
|
||||
|
||||
$userInfoEmail = $this->userInfo && isset($this->userInfo->email) ? $this->userInfo->email : null;
|
||||
$userInfoType = $this->userInfo && isset($this->userInfo->type) ? $this->userInfo->type : null;
|
||||
|
||||
if(!$userInfoEmail && Auth::user()){
|
||||
$userInfoEmail = Auth::user()->email;
|
||||
}
|
||||
if(!$userInfoType && Auth::user()){
|
||||
$userInfoType = Auth::user()->type;
|
||||
}
|
||||
|
||||
//cief todo: remove
|
||||
// Log::error('CompanyResource 1: '. json_encode($userInfoEmail));
|
||||
// Log::error('CompanyResource 2: '. json_encode($userInfoType));
|
||||
|
||||
if(!is_null($userInfoEmail) && !is_null($userInfoType)){
|
||||
$userResource = new UserResource($userInfoType === RoleTypes::USER ? $this->employees()->where('email', '=', $userInfoEmail)->first() : $this->employees()->orderBy('id', 'DESC')->first());
|
||||
}
|
||||
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
@@ -71,8 +42,7 @@ class CompanyResource extends JsonResource
|
||||
'status' => (int) $this->status,
|
||||
'contact' => new ContactResource ($this->when($this->has('contacts'), $this->contacts->first())),
|
||||
'address' => new AddressResource($this->when($this->has('addresses'), $this->addresses->where('billing', true)->first())),
|
||||
//cief todo: this one need to decide what to do to replace Auth:user() when it is run by job queue
|
||||
'employee' => $userResource,
|
||||
'employee' => new UserResource(Auth::user()->type === RoleTypes::USER ? $this->employees()->where('email', '=', Auth::user()->email)->first() : $this->employees()->orderBy('id', 'DESC')->first()),
|
||||
'identification' => new DocumentResource($this->documents->whereIn('document_type', DocumentType::IDENTIFICATION_DOCUMENTS)->first()),
|
||||
'bookings' => $this->whenLoaded('bookings', $this->bookings()->orderBy('id', 'DESC')->get(), []),
|
||||
'confirmed_bookings' => $this->bookings()->whereHas('transactions', function ($query){
|
||||
|
||||
@@ -3,14 +3,8 @@
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use App\Models\Booking;
|
||||
use App\Models\Company;
|
||||
use App\Models\Document;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
|
||||
|
||||
class DocumentResource extends JsonResource
|
||||
{
|
||||
@@ -27,7 +21,7 @@ class DocumentResource extends JsonResource
|
||||
'reference' => $this->reference,
|
||||
'status' => (int) $this->status,
|
||||
'document_type' => $this->document_type,
|
||||
'owner' => $this->relationLoaded('owner') ? ($this->owner instanceof Booking ? new BookingResource($this->owner, $this->userInfo) : new CompanyResource($this->owner, $this->userInfo)) : null,
|
||||
'owner' => $this->relationLoaded('owner') ? ($this->owner instanceof Booking ? new BookingResource($this->owner) : new CompanyResource($this->owner)) : null,
|
||||
'files' => FileResource::collection($this->files),
|
||||
'created_at' => Carbon::parse($this->created_at)->format('d-m-Y h:i:s A')
|
||||
];
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use App\Classes\Modules\Bookings\Services\CalculatesBookingFloatingAmount;
|
||||
use App\Classes\Modules\Bookings\Services\CalculatesBookingOutstanding;
|
||||
use App\Classes\Modules\Bookings\Services\CalculatesBookingPayableAmount;
|
||||
use App\Classes\Modules\Bookings\Services\CalculatesBookingRefundAmount;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Classes\ValueObjects\Constants\DocumentType;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class ListBookingJobResource extends JsonResource
|
||||
{
|
||||
private $userInfo;
|
||||
|
||||
public function __construct($resource, $userInfo = null)
|
||||
{
|
||||
parent::__construct($resource);
|
||||
$this->userInfo = $userInfo ?? ($resource->userInfo ?? null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'company' => new CompanyResource($this->company, $this->userInfo),
|
||||
'bank' => new BankResource($this->bank),
|
||||
'service' => new ServiceTypeResource($this->service),
|
||||
'marking' => $this->marking,
|
||||
'amount' => $this->fix_amount,
|
||||
'floating_amount' => floatval((App()->make(CalculatesBookingFloatingAmount::class))->execute($this->resource, $this->fix_currency_id)),
|
||||
'paid_amount' => floatval((App()->make(CalculatesBookingPayableAmount::class))->execute($this->resource, $this->fix_currency_id)) - floatval((App()->make(CalculatesBookingRefundAmount::class))->execute($this->resource, $this->fix_currency_id)),
|
||||
'outstanding_amount' => floatval((App()->make(CalculatesBookingOutstanding::class))->execute($this->resource)) - floatval((App()->make(CalculatesBookingRefundAmount::class))->execute($this->resource, $this->fix_currency_id)),
|
||||
'fixed_currency' => new CurrencyResource($this->fixedCurrency),
|
||||
'convertible_currency' => new CurrencyResource($this->convertibleCurrency),
|
||||
'conversion_currency' => new CurrencyResource($this->conversionCurrency),
|
||||
'documents' => [
|
||||
'purchase_order' => new DocumentResource($this->documents()->where('document_type', DocumentType::PURCHASE_ORDER)->first()),
|
||||
'delivery_order' => new DocumentResource($this->documents()->where('document_type', DocumentType::DELIVER_ORDER)->first()),
|
||||
'invoice' => new DocumentResource($this->documents()->where('document_type', DocumentType::INVOICE)->first()),
|
||||
'supplier_delivery_order' => new DocumentResource($this->documents()->where('document_type', DocumentType::SUPPLIER_DELIVER_ORDER)->first()),
|
||||
'proforma_invoice' => new DocumentResource($this->documents()->where('document_type', DocumentType::PROFORMA_INVOICE)->whereNotIn('status', [ApprovalStatus::REJECTED, ApprovalStatus::EXPIRED])->orderByDesc('id')->first()),
|
||||
'ecommerce_purchase_order' => new DocumentResource($this->documents()->where('document_type', DocumentType::ECOMMERCE_PURCHASE_ORDER)->first()),
|
||||
],
|
||||
'status' => $this->status,
|
||||
'created_at' => Carbon::parse($this->created_at)->format('d-m-Y'),
|
||||
'created_at_with_time' => Carbon::parse($this->created_at)->format('d-m-Y h:i:s A'),
|
||||
$this->mergeWhen($this->relationLoaded('transactions'), [
|
||||
'purchase_order' => new TransactionResource($this->transactions()->where('type', TransactionType::PURCHASE_ORDER)->first()),
|
||||
'payment_attempts' => TransactionResource::collection(
|
||||
$this->transactions()
|
||||
->payments()->where('status', ApprovalStatus::PENDING_SUBMISSION)
|
||||
->whereDate('expires_on', '>=', Carbon::now())
|
||||
->get()
|
||||
),
|
||||
'expired_payment_attempts' => TransactionResource::collection($this->transactions()->payments()->where('status', ApprovalStatus::PENDING_SUBMISSION)->whereDate('expires_on', '>=', Carbon::now())->where('expires_on', '>', Carbon::now()->toTimeString())->get()),
|
||||
'payment_history' => TransactionResource::collection($this->transactions()->where(function($query){
|
||||
$query->where(function($query){
|
||||
$query->payments()->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::COMPLETED, ApprovalStatus::REJECTED]);
|
||||
})->orWhere(function($query){
|
||||
$query->where(function($query){
|
||||
$query->where('type', TransactionType::REFUND)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::REJECTED, ApprovalStatus::COMPLETED]);
|
||||
})->orWhere(function($query){
|
||||
$query->where('type', TransactionType::CREDIT_NOTE)->whereIn('status', [ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
|
||||
});
|
||||
});
|
||||
})->latest()->get())
|
||||
])
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use App\Models\Booking;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use App\Http\Resources\V2\BookingV2Resource;
|
||||
use App\Http\Resources\V2\CompanyV2Resource;
|
||||
|
||||
class ListDocumentJobResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'reference' => $this->reference,
|
||||
'status' => (int) $this->status,
|
||||
'document_type' => $this->document_type,
|
||||
'owner' => $this->relationLoaded('owner') ? ($this->owner instanceof Booking ? new BookingV2Resource($this->owner, $this->userInfo) : new CompanyV2Resource($this->owner, $this->userInfo)) : null,
|
||||
'files' => FileResource::collection($this->files),
|
||||
'created_at' => Carbon::parse($this->created_at)->format('d-m-Y h:i:s A')
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class ListTransactionJobResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
|
||||
$booking = in_array((int)$this->type, [TransactionType::BILL, TransactionType::REFUND])? $this->owner->owner : $this->owner;
|
||||
$days = $this->created_at->endOfDay()->addWeekdays($booking->service_id === 3 ? 3 : 1);
|
||||
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'booking' => new BookingResource($booking),
|
||||
'type' => (int) $this->type,
|
||||
'bill_no' => $this->bill_no,
|
||||
'payment_reference' => $this->payment_reference,
|
||||
'payment_method' => (float) $this->payment_method,
|
||||
'recipient_bank_account' => new BankResource($booking->bank),
|
||||
'issuer_name' => $this->issuerCompany->name,
|
||||
'issuer_id' => $this->issuerCompany->id,
|
||||
'amount' => (double) $this->amount,
|
||||
'original_amount' => (double) $this->original_amount,
|
||||
'currency' => new CurrencyResource($this->currency),
|
||||
'original_currency' => new CurrencyResource($this->original_currency),
|
||||
'service_charge' => (double) $this->service_charge,
|
||||
'tax' => (double) $this->tax,
|
||||
'currency_rate' => (double) $this->currency_rate,
|
||||
'status' => (int) $this->status,
|
||||
'details' => TransactionDetailResource::collection($this->transactionDetails),
|
||||
'documents' => new DocumentResource($this->documents()->first()),
|
||||
'transaction_bill' => new TransactionResource($this->when((int) $this->type === TransactionType::PAYMENT, $this->transactions()->bills()->first())),
|
||||
'transaction_refunds' => TransactionResource::collection($this->when((int) $this->type === TransactionType::PAYMENT, $this->transactions()->refunds()->get())),
|
||||
'expires_on' => Carbon::parse($this->expires_on)->format('d-m-Y h:i:s A'),
|
||||
'updated_at' => Carbon::parse($this->updated_at)->format('d-m-Y h:i:s A'),
|
||||
'interval' => [
|
||||
'value' => $days->gt(Carbon::now()) ? '+' : '-',
|
||||
'duration' => $days->diff(Carbon::now())->format('%d'),
|
||||
],
|
||||
'redemption' => new VoucherRedemptionResource($this->voucherRedemption)
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\V2;
|
||||
|
||||
use App\Classes\Modules\Bookings\Services\CalculatesBookingFloatingAmount;
|
||||
use App\Classes\Modules\Bookings\Services\CalculatesBookingOutstanding;
|
||||
use App\Classes\Modules\Bookings\Services\CalculatesBookingPayableAmount;
|
||||
use App\Classes\Modules\Bookings\Services\CalculatesBookingRefundAmount;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Classes\ValueObjects\Constants\DocumentType;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use App\Http\Resources as V1;
|
||||
|
||||
class BookingV2Resource extends JsonResource
|
||||
{
|
||||
private $userInfo;
|
||||
|
||||
public function __construct($resource, $userInfo = null)
|
||||
{
|
||||
parent::__construct($resource);
|
||||
$this->userInfo = $userInfo ?? ($resource->userInfo ?? null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'company' => new CompanyV2Resource($this->company, $this->userInfo),
|
||||
'bank' => new V1\BankResource($this->bank),
|
||||
'service' => new V1\ServiceTypeResource($this->service),
|
||||
'marking' => $this->marking,
|
||||
'amount' => $this->fix_amount,
|
||||
'floating_amount' => floatval((App()->make(CalculatesBookingFloatingAmount::class))->execute($this->resource, $this->fix_currency_id)),
|
||||
'paid_amount' => floatval((App()->make(CalculatesBookingPayableAmount::class))->execute($this->resource, $this->fix_currency_id)) - floatval((App()->make(CalculatesBookingRefundAmount::class))->execute($this->resource, $this->fix_currency_id)),
|
||||
'outstanding_amount' => floatval((App()->make(CalculatesBookingOutstanding::class))->execute($this->resource)) - floatval((App()->make(CalculatesBookingRefundAmount::class))->execute($this->resource, $this->fix_currency_id)),
|
||||
'fixed_currency' => new V1\CurrencyResource($this->fixedCurrency),
|
||||
'convertible_currency' => new V1\CurrencyResource($this->convertibleCurrency),
|
||||
'conversion_currency' => new V1\CurrencyResource($this->conversionCurrency),
|
||||
'documents' => [
|
||||
'purchase_order' => new V1\DocumentResource($this->documents()->where('document_type', DocumentType::PURCHASE_ORDER)->first()),
|
||||
'delivery_order' => new V1\DocumentResource($this->documents()->where('document_type', DocumentType::DELIVER_ORDER)->first()),
|
||||
'invoice' => new V1\DocumentResource($this->documents()->where('document_type', DocumentType::INVOICE)->first()),
|
||||
'supplier_delivery_order' => new V1\DocumentResource($this->documents()->where('document_type', DocumentType::SUPPLIER_DELIVER_ORDER)->first()),
|
||||
'proforma_invoice' => new V1\DocumentResource($this->documents()->where('document_type', DocumentType::PROFORMA_INVOICE)->whereNotIn('status', [ApprovalStatus::REJECTED, ApprovalStatus::EXPIRED])->orderByDesc('id')->first()),
|
||||
'ecommerce_purchase_order' => new V1\DocumentResource($this->documents()->where('document_type', DocumentType::ECOMMERCE_PURCHASE_ORDER)->first()),
|
||||
],
|
||||
'status' => $this->status,
|
||||
'created_at' => Carbon::parse($this->created_at)->format('d-m-Y'),
|
||||
'created_at_with_time' => Carbon::parse($this->created_at)->format('d-m-Y h:i:s A'),
|
||||
$this->mergeWhen($this->relationLoaded('transactions'), [
|
||||
'purchase_order' => new V1\TransactionResource($this->transactions()->where('type', TransactionType::PURCHASE_ORDER)->first()),
|
||||
'payment_attempts' => V1\TransactionResource::collection(
|
||||
$this->transactions()
|
||||
->payments()->where('status', ApprovalStatus::PENDING_SUBMISSION)
|
||||
->whereDate('expires_on', '>=', Carbon::now())
|
||||
->get()
|
||||
),
|
||||
'expired_payment_attempts' => V1\TransactionResource::collection($this->transactions()->payments()->where('status', ApprovalStatus::PENDING_SUBMISSION)->whereDate('expires_on', '>=', Carbon::now())->where('expires_on', '>', Carbon::now()->toTimeString())->get()),
|
||||
'payment_history' => V1\TransactionResource::collection($this->transactions()->where(function($query){
|
||||
$query->where(function($query){
|
||||
$query->payments()->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::COMPLETED, ApprovalStatus::REJECTED]);
|
||||
})->orWhere(function($query){
|
||||
$query->where(function($query){
|
||||
$query->where('type', TransactionType::REFUND)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::REJECTED, ApprovalStatus::COMPLETED]);
|
||||
})->orWhere(function($query){
|
||||
$query->where('type', TransactionType::CREDIT_NOTE)->whereIn('status', [ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
|
||||
});
|
||||
});
|
||||
})->latest()->get())
|
||||
])
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\V2;
|
||||
|
||||
use App\Classes\Modules\Companies\Services\FetchesCompanyServices;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\BankAccountType;
|
||||
use App\Classes\ValueObjects\Constants\BusinessType;
|
||||
use App\Classes\ValueObjects\Constants\DocumentType;
|
||||
use App\Classes\ValueObjects\Constants\RoleTypes;
|
||||
use App\Classes\ValueObjects\Constants\SegmentConstants;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Models\Currency;
|
||||
use App\Models\SegmentConstant;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use App\Http\Resources as V1;
|
||||
|
||||
|
||||
class CompanyV2Resource extends JsonResource
|
||||
{
|
||||
private $userInfo;
|
||||
|
||||
public function __construct($resource, $userInfo = null)
|
||||
{
|
||||
parent::__construct($resource);
|
||||
$this->userInfo = $userInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
$lastPayment = $this->transactions()->where('transactions.type', TransactionType::PAYMENT)->whereIn('transactions.status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->orderBy('id', 'DESC')->first();
|
||||
$totalPayments = $this->transactions()->where('transactions.type', TransactionType::PAYMENT)->whereIn('transactions.status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->sum('amount');
|
||||
|
||||
$segment = SegmentConstant::where('reference', SegmentConstants::SUPPLIER_CURRENCIES)->where('detail->id', $this->id)->first();
|
||||
$serviceCharge = SegmentConstant::where('reference', SegmentConstants::SERVICE_CHARGE)->where('detail->id', $this->id)->first();
|
||||
|
||||
$userResource = null;
|
||||
|
||||
$userInfoEmail = $this->userInfo && isset($this->userInfo->email) ? $this->userInfo->email : null;
|
||||
$userInfoType = $this->userInfo && isset($this->userInfo->type) ? $this->userInfo->type : null;
|
||||
|
||||
if(!$userInfoEmail && Auth::user()){
|
||||
$userInfoEmail = Auth::user()->email;
|
||||
}
|
||||
if(!$userInfoType && Auth::user()){
|
||||
$userInfoType = Auth::user()->type;
|
||||
}
|
||||
|
||||
if(!is_null($userInfoEmail) && !is_null($userInfoType)){
|
||||
$userResource = new V1\UserResource($userInfoType === RoleTypes::USER ? $this->employees()->where('email', '=', $userInfoEmail)->first() : $this->employees()->orderBy('id', 'DESC')->first());
|
||||
}
|
||||
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'reference' => $this->reference,
|
||||
'debtor' => $this->debtor,
|
||||
'type' => (int) $this->type,
|
||||
'business_type' => (int) $this->business_type,
|
||||
'status' => (int) $this->status,
|
||||
'contact' => new V1\ContactResource ($this->when($this->has('contacts'), $this->contacts->first())),
|
||||
'address' => new V1\AddressResource($this->when($this->has('addresses'), $this->addresses->where('billing', true)->first())),
|
||||
'employee' => $userResource,
|
||||
'identification' => new V1\DocumentResource($this->documents->whereIn('document_type', DocumentType::IDENTIFICATION_DOCUMENTS)->first()),
|
||||
'bookings' => $this->whenLoaded('bookings', $this->bookings()->orderBy('id', 'DESC')->get(), []),
|
||||
'confirmed_bookings' => $this->bookings()->whereHas('transactions', function ($query){
|
||||
$query->where('type', TransactionType::PAYMENT)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
|
||||
})->count(),
|
||||
'total_payments' => (float) $totalPayments,
|
||||
'average_spending_per_day' => (float) $totalPayments / ($this->created_at->diff(Carbon::now())->days === 0 ? 1 : $this->created_at->diff(Carbon::now())->days),
|
||||
'average_spending_per_booking' => (float) $totalPayments > 0 ? $totalPayments / $this->bookings()->whereHas('transactions', function ($query){
|
||||
$query->where('type', TransactionType::PAYMENT)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
|
||||
})->count() : $totalPayments,
|
||||
'last_payment' => $lastPayment ? $lastPayment->created_at->diffForHumans() : 'No Payments',
|
||||
'personal_banks' => V1\BankResource::collection($this->banks->where('type', BankAccountType::PERSONAL)),
|
||||
'recipient_banks' => [
|
||||
'accounts' => V1\BankResource::collection($this->banks->where('type', BankAccountType::EXTERNAL)),
|
||||
'default' => new V1\BankResource($this->banks->where('type', BankAccountType::EXTERNAL)->where('default', true)->first())
|
||||
],
|
||||
'segments' => V1\SegmentResource::collection($this->segments),
|
||||
'seasonalSegment' => $this->whenLoaded('seasonalSegments', V1\SeasonalSegmentResource::collection($this->seasonalSegments)),
|
||||
'services' => (new FetchesCompanyServices())->getServices($this->servicesConfigurations()),
|
||||
'wallet' => $this->whenLoaded('wallets', new V1\WalletResource($this->wallets()->with('transactions')->first()), new V1\WalletResource($this->wallets()->first())),
|
||||
'created_at' => $this->created_at->format('d-m-Y'),
|
||||
$this->mergeWhen($this->business_type === BusinessType::CURRENCY_VENDOR, [
|
||||
'currencies' => $segment ? V1\CurrencyResource::collection(Currency::whereIn('id', $segment->detail->currencies)->get()) : [],
|
||||
'service_charge' => $serviceCharge
|
||||
])
|
||||
|
||||
];
|
||||
}
|
||||
}
|
||||
+30
-26
@@ -1,35 +1,39 @@
|
||||
export default {
|
||||
actions: {
|
||||
crudRequestV2({getters, dispatch}, {endpoint, method, parameters}){
|
||||
const queryDomain = endpoint.split('?')[0];
|
||||
let encodedParams = endpoint.split('?')[1];
|
||||
let decodedParams = fullyDecodeURI(encodedParams);
|
||||
const queryParams = encodeURIComponent(decodedParams);
|
||||
encodedParams = queryParams.toString();
|
||||
let filteredEncodedParams = encodedParams.replace(/%3D/g,'=');
|
||||
filteredEncodedParams = filteredEncodedParams.replace(/%26/g,'&');
|
||||
let combinedAbsoluteUrl = queryDomain;
|
||||
if(filteredEncodedParams !== undefined && filteredEncodedParams !== 'undefined'){
|
||||
combinedAbsoluteUrl = queryDomain + '?' + filteredEncodedParams;
|
||||
}
|
||||
|
||||
// return fetch(endpoint, {
|
||||
return fetch(combinedAbsoluteUrl, {
|
||||
method: method,
|
||||
responseType: 'json',
|
||||
body: parameters ? JSON.stringify(parameters):null,
|
||||
headers: {
|
||||
'content-type': 'application/json',
|
||||
'Authorization': 'Bearer '+getters.getAccessToken
|
||||
}
|
||||
}).then(response => {
|
||||
if(response.status === 401 && window.location.href !== route('login') && window.location.href.indexOf(route('last_mile_delivery.login')) <= -1){
|
||||
dispatch('userAuthentication', {access_token: '', redirect_url: [7, 8].includes(getters.getCompanyModuleType) ? route('last_mile_delivery.login') : route('login')});
|
||||
return dispatch('ensureReCaptchaIsSet').then(function () {
|
||||
const queryDomain = endpoint.split('?')[0];
|
||||
let encodedParams = endpoint.split('?')[1];
|
||||
let decodedParams = fullyDecodeURI(encodedParams);
|
||||
const queryParams = encodeURIComponent(decodedParams);
|
||||
encodedParams = queryParams.toString();
|
||||
let filteredEncodedParams = encodedParams.replace(/%3D/g,'=');
|
||||
filteredEncodedParams = filteredEncodedParams.replace(/%26/g,'&');
|
||||
let combinedAbsoluteUrl = queryDomain;
|
||||
if(filteredEncodedParams !== undefined && filteredEncodedParams !== 'undefined'){
|
||||
combinedAbsoluteUrl = queryDomain + '?' + filteredEncodedParams;
|
||||
}
|
||||
|
||||
return response;
|
||||
// return fetch(endpoint, {
|
||||
return fetch(combinedAbsoluteUrl, {
|
||||
method: method,
|
||||
responseType: 'json',
|
||||
body: parameters ? JSON.stringify(parameters):null,
|
||||
headers: {
|
||||
'content-type': 'application/json',
|
||||
'Authorization': 'Bearer '+getters.getAccessToken,
|
||||
'captcha-token': getters.getReCaptcha
|
||||
}
|
||||
}).then(response => {
|
||||
|
||||
})
|
||||
if(response.status === 401 && window.location.href !== route('login')){
|
||||
dispatch('userAuthentication', {access_token: '', redirect_url: '/'});
|
||||
}
|
||||
|
||||
return response;
|
||||
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user