mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 12:34:18 +00:00
Compare commits
190 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4c3dead6b7 | |||
| 058ba592bf | |||
| d950ee3d68 | |||
| 575379adc0 | |||
| da6ec00dbd | |||
| 412dbd64d5 | |||
| 496df549f6 | |||
| 97eaefa45a | |||
| 68c9e0451a | |||
| 671c7a54fb | |||
| 2a28183426 | |||
| 0ebea79750 | |||
| a701242646 | |||
| 4bdeae997d | |||
| 36809f34cc | |||
| 032171bb18 | |||
| d41bd3db39 | |||
| 56bba0eaaf | |||
| af8444e0d9 | |||
| b2a7d1f73d | |||
| 9d2ff3fafa | |||
| 487d07e28c | |||
| 4176e09ea3 | |||
| c44bf46a42 | |||
| e687dd2b9a | |||
| 59951c4efd | |||
| c00a4712a0 | |||
| 1bb07e9402 | |||
| 683bdec1f7 | |||
| ee53a9438a | |||
| 2e2087f16e | |||
| 998b0b4da5 | |||
| dcf5c2e455 | |||
| 156b1dee07 | |||
| 544d7907c3 | |||
| 5b77f7baa6 | |||
| b33016aac4 | |||
| 2788e349ae | |||
| 04af87f640 | |||
| 5b190d5334 | |||
| 8f32769656 | |||
| 0e79bbfd6a | |||
| 3a411e8b9a | |||
| bffe438455 | |||
| d17beda04b | |||
| 7acc6932b5 | |||
| 2d175f4acc | |||
| 31905e56be | |||
| 6508155aea | |||
| 760f8684ea | |||
| 979b8b2ef9 | |||
| 9a0073e906 | |||
| 976e54bb4c | |||
| 87226377be | |||
| 674fd84fa0 | |||
| da1ed10740 | |||
| eb73d20b00 | |||
| 782aed06e4 | |||
| 158fa2eefe | |||
| fa4cfc0d75 | |||
| f87bcff930 | |||
| e774962c44 | |||
| f5482a29e4 | |||
| 0a14a64fbb | |||
| ee5051fc26 | |||
| 034c93091a | |||
| 8b184313cb | |||
| c2b097e6d1 | |||
| b0195a9640 | |||
| 38d69434fa | |||
| 1b559f91a2 | |||
| 05a21af5a6 | |||
| 3e7fbdbafc | |||
| 527eca50fe | |||
| d010a8f8c7 | |||
| 7bc2ca512a | |||
| b76e0ebeef | |||
| f595c43f2c | |||
| 5584d22376 | |||
| 42b6140df7 | |||
| 619fc25605 | |||
| 8c24c86c77 | |||
| 822046cc69 | |||
| d708b8b540 | |||
| 553d2c44aa | |||
| 0f7f5f7ab9 | |||
| a5c1ae14b7 | |||
| 8f5aa0a861 | |||
| 1bed7f1cc9 | |||
| 0a16e40a23 | |||
| 5c24b6f81e | |||
| b81f3e50ad | |||
| 3f1a8a6d12 | |||
| 2240c1723d | |||
| 5d07598c5e | |||
| c493b3786c | |||
| e4f60a7bff | |||
| fe000b7a6f | |||
| 707ef9d9f3 | |||
| b5abb04c63 | |||
| 1dbad7d6e5 | |||
| 25417ba5be | |||
| fe67cc6c5b | |||
| 90b85c0df1 | |||
| 0cdff7c544 | |||
| 42561a7c56 | |||
| 99f4699260 | |||
| 0ea52048e1 | |||
| a47bb95e50 | |||
| 431aed18d3 | |||
| 6ab289057b | |||
| c55a8e7af9 | |||
| 60fbe77829 | |||
| fbf097eb62 | |||
| 30c2673fdf | |||
| fd3709e103 | |||
| 08473d85ab | |||
| 489974ca5a | |||
| 6a6a0f0ee7 | |||
| 402f64364b | |||
| a3bff9d079 | |||
| 2a7a448059 | |||
| 7d855064da | |||
| efc0a3b94e | |||
| 01654ee0d3 | |||
| 23c2f92e6d | |||
| 3945c47f52 | |||
| 51ab6ce48b | |||
| ca8140a1ba | |||
| a84580c1dd | |||
| 63b212a66c | |||
| 7979d89997 | |||
| bc603fc125 | |||
| b55fd49830 | |||
| 60ceac645f | |||
| 90c599049b | |||
| f538fb7f2f | |||
| a45105f5ae | |||
| 2f1a8ee648 | |||
| aacf4ea53d | |||
| 1fa2b60871 | |||
| 203dc0c230 | |||
| fcc4da1a56 | |||
| c5a49bbc44 | |||
| f8131b3a1e | |||
| 336cc0b37f | |||
| 42f096b09c | |||
| 614167cac5 | |||
| e5421f8810 | |||
| 8dc84baee0 | |||
| a413533975 | |||
| 0a98f8a8c6 | |||
| aceed5f754 | |||
| 761d191c1d | |||
| d769be137e | |||
| d6a5dd56c6 | |||
| f279d39ddb | |||
| 2e1e8875b4 | |||
| c30c5a36f2 | |||
| 7d3901ee48 | |||
| 463398945f | |||
| d619862e63 | |||
| 9665a0e242 | |||
| 7ed6c11f37 | |||
| 3eaee0d122 | |||
| b7816873fe | |||
| 8809caa046 | |||
| b8b6910a45 | |||
| 64bfbac4f7 | |||
| a5b7e79964 | |||
| 03c9bec256 | |||
| 06134e006c | |||
| 7563b455ba | |||
| 26edb3bebd | |||
| 55e1a6ad02 | |||
| 381425c6bc | |||
| 09ab95faf8 | |||
| 8bb6f0317a | |||
| fe95db2605 | |||
| 02640e6ae8 | |||
| 104dd19a6f | |||
| 89117c0706 | |||
| bc650b0816 | |||
| a6a239c489 | |||
| 45b78465da | |||
| 71edeca994 | |||
| cd229c6a8f | |||
| 18579d5c1d | |||
| 1060401128 | |||
| 5b00b7b45f |
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Exceptions;
|
||||
|
||||
use App\Classes\ValueObjects\Constants\HttpStatus;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
final class ConnectionErrorException extends ServiceApiException {
|
||||
public function __construct(?string $message = null, ?string $exceptionMessage = null, ?string $payload = null, ?string $exceptionTrace = null) {
|
||||
Log::error($message. ": ". $exceptionMessage);
|
||||
if($payload){
|
||||
Log::error('Payload: '.$payload);
|
||||
}
|
||||
if($exceptionTrace){
|
||||
Log::error($exceptionTrace);
|
||||
}
|
||||
parent::__construct($message ?? 'A connection error has occurred. Please check application logs for more information.',
|
||||
HttpStatus::SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Abstracts;
|
||||
|
||||
|
||||
use App\Classes\Exceptions\ErrorException;
|
||||
use App\Classes\Exceptions\InternalServerErrorException;
|
||||
use App\Classes\ValueObjects\Constants\Notifications;
|
||||
use App\Classes\ValueObjects\Constants\HttpStatus;
|
||||
use App\Classes\ValueObjects\Response\ApiResponseObject;
|
||||
use ErrorException as GeneralExceptions;
|
||||
use TypeError;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
abstract class Abstract2ControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
abstract protected function notification(): array;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function getNotificationTitle():string {
|
||||
return $this->notification()['title'] ? $this->notification()['title']: Notifications::UNDEFINED['title'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function getNotificationMessage():string {
|
||||
return $this->notification()['message'] ? $this->notification()['message']: Notifications::UNDEFINED['message'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return BinaryFileResponse
|
||||
* @throws ErrorException
|
||||
*/
|
||||
abstract protected function logic(Request $request) : BinaryFileResponse;
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return BinaryFileResponse
|
||||
*/
|
||||
public function execute(Request $request) : BinaryFileResponse {
|
||||
|
||||
try {
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
$response = $this->logic($request);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return $response;
|
||||
|
||||
} catch (ErrorException|GeneralExceptions|TypeError $exception){
|
||||
abort(404, $exception->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|null $data
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function response(?array $data = []) : JsonResponse {
|
||||
|
||||
return (new ApiResponseObject($this->getNotificationTitle().' Successful',
|
||||
$this->getNotificationMessage(),
|
||||
HttpStatus::OK_WITH_MESSAGE, $data))->handler();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param JsonResource $resource
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function resourceResponse(JsonResource $resource){
|
||||
return $this->response(['data' => $resource]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ResourceCollection $collection
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function collectionResponse(ResourceCollection $collection){
|
||||
return $this->response(json_decode($collection->response()->getContent(), true));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class CreatedAfterOrEqual implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
$table = $builder->getModel()->getTable();
|
||||
$startDate = Carbon::createFromFormat('d-m-Y', $value)->startOfDay();
|
||||
return $builder->where("{$table}.created_at", '>=', $startDate);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class CreatedBeforeOrEqual implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
$table = $builder->getModel()->getTable();
|
||||
$endDate = Carbon::createFromFormat('d-m-Y', $value)->endOfDay();
|
||||
return $builder->where("{$table}.created_at", '<=', $endDate);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class HasQuestionnaireGroupIn implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->whereHas('question.questionnaire', function (Builder $query) use ($value) {
|
||||
$query->whereIn('group', $value);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class IdNext implements Filter
|
||||
{
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->where('id', '>', $value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class NextMainQuestion implements Filter
|
||||
{
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->where('next_main_question', $value);
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,8 @@ class OwnerId implements Filter
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->where('owner_id', $value);
|
||||
$table = $builder->getModel()->getTable();
|
||||
return $builder->where("{$table}.owner_id", $value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class OwnerType implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
$table = $builder->getModel()->getTable();
|
||||
return $builder->where("{$table}.owner_type", $value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class PaymentMethodNotIn implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->whereNotIn('payment_method', $value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class QuestionId implements Filter
|
||||
{
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->where('question_id', $value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class QuestionNumber implements Filter
|
||||
{
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->where('question_number', $value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class QuestionnaireSetId implements Filter
|
||||
{
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->where('questionnaire_set_id', $value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class ShortUrl implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->where('short_url', $value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,7 +14,8 @@ class StatusIn implements Filter
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->whereIn('status', $value);
|
||||
$table = $builder->getModel()->getTable();
|
||||
return $builder->whereIn("{$table}.status", $value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class UserId implements Filter
|
||||
{
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->where('user_id', $value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class WithAgingColumn implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
$today = Carbon::now();
|
||||
return $builder->select('packing_lists.*')
|
||||
->addSelect(DB::raw("DATEDIFF('$today', transactions.updated_at) as days_over_duedate"))
|
||||
->addSelect(DB::raw("CASE
|
||||
WHEN DATEDIFF('$today', transactions.updated_at) <= 0 THEN 0
|
||||
WHEN DATEDIFF('$today', transactions.updated_at) > 0 AND DATEDIFF('$today', transactions.updated_at) <= 30 THEN 1
|
||||
WHEN DATEDIFF('$today', transactions.updated_at) > 30 AND DATEDIFF('$today', transactions.updated_at) <= 60 THEN 2
|
||||
WHEN DATEDIFF('$today', transactions.updated_at) > 60 AND DATEDIFF('$today', transactions.updated_at) <= 90 THEN 3
|
||||
ELSE 4
|
||||
END AS due_date_number"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class WithOrderReferenceLike implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->join('transactions as t2', 't2.payment_reference', '=', 'transactions.bill_no')
|
||||
->join('transactions as t3', 't3.id', '=', 't2.owner_id')
|
||||
->join('packing_lists', 'packing_lists.id', '=', 't3.owner_id')
|
||||
->join('orders', function ($join) use ($value) {
|
||||
$join->on('orders.id', '=', 'packing_lists.owner_id')
|
||||
->where('orders.reference', 'LIKE', '%'.$value.'%');
|
||||
})
|
||||
->addSelect(['transactions.*', 't2.id as paymentTransactionId', 't3.id as invoiceTransactionId', 'packing_lists.id as packingListId', 'orders.reference as orderReference']);
|
||||
}
|
||||
}
|
||||
@@ -24,12 +24,11 @@ class Helper
|
||||
return array_slice(get_class_methods($className), 1);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* @param $log
|
||||
* @return none
|
||||
*/
|
||||
static function debugLoggerForPerfexCRM($log){
|
||||
if($log){
|
||||
static function debugLogger($log){
|
||||
if($log && isset($log['message'])){
|
||||
$message = $log['message'];
|
||||
$substring = 'No data were found';
|
||||
if (isset($message)) {
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
namespace App\Classes\Jobs;
|
||||
|
||||
use App\Classes\Modules\PerfexCRM\Processors\UpdatePerfexCRMProcessor;
|
||||
use App\Classes\Modules\PerfexCRM\Processors\FetchPerfexCRMInvoiceProcessor;
|
||||
use App\Models\Transaction;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
@@ -10,6 +12,8 @@ use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use App\Classes\Modules\PerfexCRM\DataTransferObjects\UpdatePerfexCRMObject;
|
||||
use App\Classes\Modules\PerfexCRM\DataTransferObjects\UpdatePerfexCRMInvoiceObject;
|
||||
use App\Classes\Modules\PerfexCRM\DataTransferObjects\FetchPerfexCRMInvoiceObject;
|
||||
|
||||
|
||||
class UpdatePerfexCRM implements ShouldQueue
|
||||
{
|
||||
@@ -18,37 +22,51 @@ class UpdatePerfexCRM implements ShouldQueue
|
||||
/** @var UpdatePerfexCRMObject */
|
||||
private $updatePerfexCRMObject;
|
||||
|
||||
/** @var UpdatePerfexCRMInvoice */
|
||||
private $nextJob;
|
||||
|
||||
/** @var */
|
||||
private $transaction;
|
||||
|
||||
/** @var bool|null */
|
||||
private $shouldCreateInvoice;
|
||||
|
||||
/**
|
||||
* UpdatePerfexCRM constructor.
|
||||
* @param UpdatePerfexCRMObject $updatePerfexCRMObject
|
||||
* @param UpdatePerfexCRMInvoice $nextJob
|
||||
* @param $transaction
|
||||
* @param Transaction $transaction
|
||||
* @param bool|null $shouldCreateInvoice
|
||||
*/
|
||||
public function __construct(UpdatePerfexCRMObject $updatePerfexCRMObject, $transaction, $nextJob)
|
||||
public function __construct(UpdatePerfexCRMObject $updatePerfexCRMObject, $transaction, ?bool $shouldCreateInvoice = false)
|
||||
{
|
||||
$this->updatePerfexCRMObject = $updatePerfexCRMObject;
|
||||
$this->nextJob = $nextJob;
|
||||
$this->transaction = $transaction;
|
||||
$this->shouldCreateInvoice = $shouldCreateInvoice;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
//To use invoice as a reference to decide whether more tasks should be created
|
||||
$this->updatePerfexCRMObject->setInvoiceId($this->getInvoiceIdOrCreateInvoice());
|
||||
|
||||
$result = (App()->make(UpdatePerfexCRMProcessor::class))->execute($this->updatePerfexCRMObject);
|
||||
if($this->nextJob != null && $this->transaction != null){
|
||||
if($this->transaction != null && $this->shouldCreateInvoice){
|
||||
$updatePerfexCRMInvoiceOject = new UpdatePerfexCRMInvoiceObject(
|
||||
$this->updatePerfexCRMObject->getContactEmail(),
|
||||
$result->projectId,
|
||||
$this->transaction,
|
||||
true
|
||||
);
|
||||
/** @var UpdatePerfexCRMInvoice $nextJob */
|
||||
$this->nextJob::dispatch($updatePerfexCRMInvoiceOject);
|
||||
UpdatePerfexCRMInvoice::dispatch($updatePerfexCRMInvoiceOject);
|
||||
}
|
||||
}
|
||||
|
||||
private function getInvoiceIdOrCreateInvoice(){
|
||||
if($this->transaction != null){
|
||||
$fetchPerfexCRMInvoiceObject = new FetchPerfexCRMInvoiceObject(
|
||||
$this->updatePerfexCRMObject->getContactEmail(),
|
||||
$this->transaction
|
||||
);
|
||||
$invoiceId = (App()->make(FetchPerfexCRMInvoiceProcessor::class))->execute($fetchPerfexCRMInvoiceObject);
|
||||
return $invoiceId;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ class UpdatePerfexCRMInvoice implements ShouldQueue
|
||||
|
||||
/**
|
||||
* CreatePerfexCRMSingleTask constructor.
|
||||
* @param UpdatePerfexCRMInvoiceObject $createTaskPerfexCRMObject
|
||||
* @param UpdatePerfexCRMInvoiceObject $updatePerfexCRMInvoiceObject
|
||||
*/
|
||||
public function __construct(UpdatePerfexCRMInvoiceObject $updatePerfexCRMInvoiceObject)
|
||||
{
|
||||
@@ -47,7 +47,7 @@ class UpdatePerfexCRMInvoice implements ShouldQueue
|
||||
$invoiceId = 0;
|
||||
$invoiceStatus = 0;
|
||||
$invoice = (App()->make(FetchesPerfexCRMInvoice::class))->execute($customer->userid,"INV-", $transaction->owner->bill_no);
|
||||
Log::error(json_encode('UpdatePerfexCRMInvoice debug $transaction->owner->bill_no: '.$transaction->owner->bill_no));
|
||||
Log::error('UpdatePerfexCRMInvoice debug bill_no: ' . $transaction->owner->bill_no . ', Project Id: ' . $this->updatePerfexCRMInvoiceObject->getProjectId());
|
||||
|
||||
if(is_null($invoice)){
|
||||
$result = (App()->make(CreatePerfexCRMInvoiceProcessor::class))->execute($transaction->owner, $this->updatePerfexCRMInvoiceObject->getIsPaid());
|
||||
@@ -55,7 +55,7 @@ class UpdatePerfexCRMInvoice implements ShouldQueue
|
||||
$invoiceId = $result->payload['id'];
|
||||
} else {
|
||||
// Log::error(json_encode('UpdatePerfexCRMInvoice CreatePerfexCRMInvoiceProcessor failed'));
|
||||
Helper::debugLoggerForPerfexCRM('UpdatePerfexCRMInvoice CreatePerfexCRMInvoiceProcessor failed');
|
||||
Helper::debugLogger('UpdatePerfexCRMInvoice CreatePerfexCRMInvoiceProcessor failed');
|
||||
}
|
||||
}
|
||||
else{
|
||||
@@ -64,7 +64,6 @@ 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()));
|
||||
//update invoice
|
||||
(App()->make(UpdatesPerfexCRMInvoice::class))->execute($invoice, $this->updatePerfexCRMInvoiceObject->getProjectId());
|
||||
}
|
||||
|
||||
@@ -27,27 +27,22 @@ class UpdatePerfexCRMPrelude implements ShouldQueue
|
||||
/** @var UpdatePerfexCRMObject */
|
||||
private $updatePerfexCRMObject;
|
||||
|
||||
/** @var UpdatePerfexCRM */
|
||||
private $nextJob1;
|
||||
|
||||
/** @var UpdatePerfexCRMInvoice */
|
||||
private $nextJob2;
|
||||
/** @var bool|null */
|
||||
private $shouldCreateInvoice;
|
||||
|
||||
/**
|
||||
* UpdatePerfexCRMPrelude constructor.
|
||||
* @param $packingList
|
||||
* @param $transaction
|
||||
* @param Transaction $transaction
|
||||
* @param UpdatePerfexCRMObject $updatePerfexCRMObject
|
||||
* @param UpdatePerfexCRM $nextJob1
|
||||
* @param UpdatePerfexCRMInvoice $nextJob2
|
||||
* @param bool|null $shouldCreateInvoice
|
||||
*/
|
||||
public function __construct($packingList, $transaction, UpdatePerfexCRMObject $updatePerfexCRMObject, $nextJob1, $nextJob2)
|
||||
public function __construct($packingList, $transaction, UpdatePerfexCRMObject $updatePerfexCRMObject, ?bool $shouldCreateInvoice = false)
|
||||
{
|
||||
$this->packingList = $packingList;
|
||||
$this->transaction = $transaction;
|
||||
$this->updatePerfexCRMObject = $updatePerfexCRMObject;
|
||||
$this->nextJob1 = $nextJob1;
|
||||
$this->nextJob2 = $nextJob2;
|
||||
$this->shouldCreateInvoice = $shouldCreateInvoice;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
@@ -69,9 +64,7 @@ class UpdatePerfexCRMPrelude implements ShouldQueue
|
||||
|
||||
$result = $this->replacePlaceholders($this->updatePerfexCRMObject->getTasks(), $data);
|
||||
$this->updatePerfexCRMObject->setTasks($result);
|
||||
/** @var UpdatePerfexCRM $nextJob1 */
|
||||
/** @var UpdatePerfexCRMInvoice $nextJob2 */
|
||||
$this->nextJob1::dispatch($this->updatePerfexCRMObject, $this->transaction, $this->nextJob2);
|
||||
UpdatePerfexCRM::dispatch($this->updatePerfexCRMObject, $this->transaction, $this->shouldCreateInvoice);
|
||||
}
|
||||
|
||||
function replacePlaceholders($template, $data, $prefix = '')
|
||||
|
||||
@@ -28,7 +28,8 @@ use App\Classes\ValueObjects\Constants\CompanyType;
|
||||
use App\Classes\ValueObjects\Constants\RoleTypes;
|
||||
|
||||
use App\Classes\Jobs\CreatePerfexCRMCustomer;
|
||||
|
||||
use App\Classes\Modules\Accounts\Processors\RegisterOnExchangeProcessor;
|
||||
use App\Classes\Modules\Companies\Services\ConnectCompanyModuleToExchangeCompany;
|
||||
use App\Models\Company;
|
||||
use App\Models\CompanyModule;
|
||||
use App\Models\User;
|
||||
@@ -36,6 +37,7 @@ use App\Models\User;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class CreateCustomerLogic extends AbstractControllerLogic
|
||||
{
|
||||
@@ -87,6 +89,12 @@ class CreateCustomerLogic extends AbstractControllerLogic
|
||||
/** @var CreatePerfexCRMLeadProcessor */
|
||||
private $createPerfexCRMLeadProcessor;
|
||||
|
||||
/** @var RegisterOnExchangeProcessor */
|
||||
private $registerOnExchangeProcessor;
|
||||
|
||||
/** @var ConnectCompanyModuleToExchangeCompany */
|
||||
private $connectCompanyModuleToExchangeCompany;
|
||||
|
||||
/**
|
||||
* CreateCustomerLogic constructor.
|
||||
* @param CreateUserProcessor $createUserProcessor
|
||||
@@ -101,8 +109,10 @@ class CreateCustomerLogic extends AbstractControllerLogic
|
||||
* @param GenerateEmailVerificationAttemptProcessor $generateEmailVerificationAttemptProcessor
|
||||
* @param FetchesCompanyModule $fetchesCompanyModule
|
||||
* @param CreatePerfexCRMLeadProcessor $createPerfexCRMLeadProcessor
|
||||
* @param RegisterOnExchangeProcessor $registerOnExchangeProcessor
|
||||
* @param ConnectCompanyModuleToExchangeCompany $connectCompanyModuleToExchangeCompany
|
||||
*/
|
||||
public function __construct(CreateUserProcessor $createUserProcessor, CreateCompanyProcessor $createCompanyProcessor, CreateCompanyModuleProcessor $createCompanyModuleProcessor, CreateContactProcessor $createContactProcessor, CreatesCompanyConnection $createsCompanyConnection, ApprovesCompanyConnection $approvesCompanyConnection, AssignEmployeeProcessor $assignEmployeeProcessor, UploadIdentityDocumentProcessor $uploadIdentityDocumentProcessor, AuthenticationProcessor $authenticationProcessor, GenerateEmailVerificationAttemptProcessor $generateEmailVerificationAttemptProcessor, FetchesCompanyModule $fetchesCompanyModule, CreatePerfexCRMLeadProcessor $createPerfexCRMLeadProcessor)
|
||||
public function __construct(CreateUserProcessor $createUserProcessor, CreateCompanyProcessor $createCompanyProcessor, CreateCompanyModuleProcessor $createCompanyModuleProcessor, CreateContactProcessor $createContactProcessor, CreatesCompanyConnection $createsCompanyConnection, ApprovesCompanyConnection $approvesCompanyConnection, AssignEmployeeProcessor $assignEmployeeProcessor, UploadIdentityDocumentProcessor $uploadIdentityDocumentProcessor, AuthenticationProcessor $authenticationProcessor, GenerateEmailVerificationAttemptProcessor $generateEmailVerificationAttemptProcessor, FetchesCompanyModule $fetchesCompanyModule, CreatePerfexCRMLeadProcessor $createPerfexCRMLeadProcessor, RegisterOnExchangeProcessor $registerOnExchangeProcessor, ConnectCompanyModuleToExchangeCompany $connectCompanyModuleToExchangeCompany)
|
||||
{
|
||||
$this->createUserProcessor = $createUserProcessor;
|
||||
$this->createCompanyProcessor = $createCompanyProcessor;
|
||||
@@ -116,6 +126,8 @@ class CreateCustomerLogic extends AbstractControllerLogic
|
||||
$this->generateEmailVerificationAttemptProcessor = $generateEmailVerificationAttemptProcessor;
|
||||
$this->fetchesCompanyModule = $fetchesCompanyModule;
|
||||
$this->createPerfexCRMLeadProcessor = $createPerfexCRMLeadProcessor;
|
||||
$this->registerOnExchangeProcessor = $registerOnExchangeProcessor;
|
||||
$this->connectCompanyModuleToExchangeCompany = $connectCompanyModuleToExchangeCompany;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -153,7 +165,7 @@ class CreateCustomerLogic extends AbstractControllerLogic
|
||||
|
||||
$this->assignEmployeeProcessor->execute($Object);
|
||||
|
||||
$this->uploadIdentityDocumentProcessor->execute($request, $company);
|
||||
// $this->uploadIdentityDocumentProcessor->execute($request, $company);
|
||||
|
||||
if(config('perfexcrm.is_enabled') == 'true'){
|
||||
// $this->createPerfexCRMLeadProcessor->execute($request);
|
||||
@@ -169,6 +181,19 @@ class CreateCustomerLogic extends AbstractControllerLogic
|
||||
|
||||
// $this->generateEmailVerificationAttemptProcessor->execute($user);
|
||||
|
||||
$exchangeCompanyId = null;
|
||||
if ($request->input('exchange_company_id')) {
|
||||
$exchangeCompanyId = $request->input('exchange_company_id');
|
||||
} else {
|
||||
// register account on exchange portal if this registration not coming from exchange
|
||||
$exchangeCompanyId = $this->registerOnExchangeProcessor->execute($request, $companyModule->id);
|
||||
}
|
||||
|
||||
if ($exchangeCompanyId) {
|
||||
// create exchange company connection
|
||||
$this->connectCompanyModuleToExchangeCompany->execute($companyModule, $exchangeCompanyId);
|
||||
}
|
||||
|
||||
return $this->response($this->authenticationProcessor->execute($request));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Accounts\ControllersLogic;
|
||||
|
||||
use App\Classes\Exceptions\AccessUnauthorisedException;
|
||||
use App\Classes\Modules\Accounts\Processors\AuthenticationProcessor;
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Accounts\Services\GeneratesAuthenticationToken;
|
||||
use App\Classes\Modules\Accounts\Services\GeneratesAuthenticationTokenWithExchangeBookingId;
|
||||
use App\Models\ExchangeCompanyConnection;
|
||||
use App\Models\Order;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class LoginThroughExchangeLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Authentication',
|
||||
'message' => 'You have successfully logged in to your account'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var AuthenticationProcessor */
|
||||
private $authenticationProcessor;
|
||||
|
||||
/** @var GeneratesAuthenticationToken */
|
||||
private $generatesAuthenticationToken;
|
||||
|
||||
/** @var GeneratesAuthenticationTokenWithExchangeBookingId */
|
||||
private $generatesAuthenticationTokenWithExchangeBookingId;
|
||||
|
||||
|
||||
/**
|
||||
* LoginThroughExchangeLogic constructor.
|
||||
* @param AuthenticationProcessor $authenticationProcessor
|
||||
* @param GeneratesAuthenticationToken $generatesAuthenticationToken
|
||||
* @param GeneratesAuthenticationTokenWithExchangeBookingId $generatesAuthenticationTokenWithExchangeBookingId
|
||||
*/
|
||||
public function __construct(GeneratesAuthenticationToken $generatesAuthenticationToken, GeneratesAuthenticationTokenWithExchangeBookingId $generatesAuthenticationTokenWithExchangeBookingId)
|
||||
{
|
||||
$this->generatesAuthenticationToken = $generatesAuthenticationToken;
|
||||
$this->generatesAuthenticationTokenWithExchangeBookingId = $generatesAuthenticationTokenWithExchangeBookingId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws \App\Classes\Exceptions\AccessForbiddenException
|
||||
* @throws \App\Classes\Exceptions\AccessUnauthorisedException
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
protected function logic(Request $request): JsonResponse {
|
||||
|
||||
$token = explode('.', $request->input("exchangeToken"))[1];
|
||||
$decodedToken = base64_decode($token);
|
||||
$exchangeUser = json_decode($decodedToken, true)['user'];
|
||||
$exchangeCompanyId = $exchangeUser['company_id'];
|
||||
$connection = ExchangeCompanyConnection::where("exchange_company_id", $exchangeCompanyId)->first();
|
||||
if (!$connection) {
|
||||
throw new AccessUnauthorisedException('These credentials do not match our records.');
|
||||
}
|
||||
$companyModule = $connection->companyModule;
|
||||
$user = $companyModule->employees->last();
|
||||
|
||||
$exchangeBookingId = null;
|
||||
if (isset($exchangeUser['booking_id']) && $exchangeUser['booking_id']) {
|
||||
$exchangeBookingId = $exchangeUser['booking_id'];
|
||||
$token = $this->generatesAuthenticationTokenWithExchangeBookingId->execute($user, $exchangeBookingId);
|
||||
|
||||
return $this->response(['access_token' => $token, 'redirect_url' => route('dashboard') . "?createOrder=true"]);
|
||||
} else {
|
||||
$token = $this->generatesAuthenticationToken->execute($user);
|
||||
$order = Order::where('id', $request->input("orderId"))->first();
|
||||
|
||||
return $this->response(['access_token' => $token, 'redirect_url' => route('order.show' , $order->reference)]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Accounts\Processors;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class RegisterOnExchangeProcessor
|
||||
{
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return string
|
||||
* @throws \App\Classes\Exceptions\AccessForbiddenException
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
public function execute(Request $request, $companyModuleId) {
|
||||
if (App::environment(['production'])) {
|
||||
dd("Delete this line before push to production");
|
||||
$url = 'https://exchange.cief-malaysia.com/api/v1/account/registration/registration';
|
||||
} else if (App::environment(['local'])) {
|
||||
$url = 'http://127.0.0.1:8000/api/v1/account/registration/registration';
|
||||
} else {
|
||||
$url = 'https://dev.exchange.cief-malaysia.com/api/v1/account/registration/registration';
|
||||
}
|
||||
try {
|
||||
$client = new \GuzzleHttp\Client(['verify' => false]);
|
||||
$formParams = $request->toArray();
|
||||
$formParams['shipping_company_module_id'] = $companyModuleId;
|
||||
$response = $client->request('POST', $url, ['form_params' => $formParams]);
|
||||
$body = $response->getBody();
|
||||
$contents = json_decode($body, true);
|
||||
$payload = $contents['payload'];
|
||||
$token = explode('.', $payload['access_token'])[1];
|
||||
$decodedToken = base64_decode($token);
|
||||
$exchangeUser = json_decode($decodedToken, true)['user'];
|
||||
|
||||
return $exchangeUser['company_id'];
|
||||
} catch(\GuzzleHttp\Exception\RequestException $exception){
|
||||
Log::error($exception->getResponse()->getBody()->getContents());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Accounts\Services;
|
||||
|
||||
use App\Classes\Exceptions\InternalServerErrorException;
|
||||
use App\Classes\ValueObjects\Constants\OrderRoleTypes;
|
||||
use App\Classes\ValueObjects\Constants\RoleTypes;
|
||||
use App\Models\Company;
|
||||
use App\Models\Role;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use Tymon\JWTAuth\JWT;
|
||||
|
||||
class GeneratesAuthenticationTokenWithExchangeBookingId {
|
||||
|
||||
/** @var JWT */
|
||||
private $builder;
|
||||
|
||||
|
||||
/**
|
||||
* GeneratesAuthenticationTokenWithExchangeBookingId constructor.
|
||||
* @param JWT $builder
|
||||
*/
|
||||
public function __construct(JWT $builder) {
|
||||
$this->builder = $builder;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @param bool $rememberUser
|
||||
* @return string
|
||||
*/
|
||||
public function execute(User $user, $bookingId): string {
|
||||
|
||||
$this->builder->manager()->setBlacklistEnabled(false);
|
||||
|
||||
// generate token for the customer
|
||||
$this->builder->factory()->setTTL(Carbon::now()->addDay()->timestamp);
|
||||
|
||||
// set the claim based on the object
|
||||
$this->setTokenClaims($user, $bookingId);
|
||||
|
||||
return $this->builder->fromUser($user);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
*/
|
||||
private function setTokenClaims(User $user, $bookingId): void {
|
||||
|
||||
$claims = [
|
||||
'id' => $user->id,
|
||||
'name' => $user->name,
|
||||
'email' => $user->email,
|
||||
'type' => $user->type,
|
||||
'status' => $user->status
|
||||
];
|
||||
|
||||
if($user->type === RoleTypes::USER) {
|
||||
|
||||
/** @var Company $companyModule */
|
||||
$companyModule = $user->companyModule()->first();
|
||||
|
||||
$claims = array_merge($claims, [
|
||||
'company_id' => $companyModule->company_id,
|
||||
'company_module_id' => $companyModule->id,
|
||||
'company_module_type' => $companyModule->type,
|
||||
'company_name' => $companyModule->name,
|
||||
'company_marking' => $companyModule->type !== 8 ? $companyModule->inviters()->withPivot('invitee_reference')->first()->pivot->invitee_reference : 'HWT',
|
||||
'exchange_booking_id' => $bookingId
|
||||
]);
|
||||
}
|
||||
|
||||
$this->builder->factory()->customClaims(['user' => $claims]);
|
||||
|
||||
|
||||
$this->builder->factory()->buildClaimsCollection();
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ class CanAuthenticateUser extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
@@ -54,4 +54,4 @@ class CanAuthenticateUser extends AbstractRule
|
||||
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;
|
||||
@@ -54,4 +54,4 @@ class CanCreateUser extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ class CanCrossAuthenticateUser extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
@@ -51,4 +51,4 @@ class CanCrossAuthenticateUser extends AbstractRule
|
||||
{
|
||||
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;
|
||||
@@ -37,4 +37,4 @@ class CanDeleteUser extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ class CanFetchUser extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
@@ -39,4 +39,4 @@ class CanFetchUser extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ class CanGeneratePasswordReset extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
@@ -62,4 +62,4 @@ class CanGeneratePasswordReset extends AbstractRule
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ class CanListUsers extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
@@ -39,4 +39,4 @@ class CanListUsers extends AbstractRule
|
||||
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;
|
||||
@@ -48,4 +48,4 @@ class CanRegisterUser extends AbstractRule
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ class CanResetPassword extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
@@ -62,4 +62,4 @@ class CanResetPassword extends AbstractRule
|
||||
return $this->passwordResetTokenExists->execute($object->getToken());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -54,4 +54,4 @@ class CanUpdateUser extends AbstractRule
|
||||
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;
|
||||
@@ -54,4 +54,4 @@ class CanCreateAddress extends AbstractRule
|
||||
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;
|
||||
@@ -40,4 +40,4 @@ class CanDeleteAddress extends AbstractRule
|
||||
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;
|
||||
@@ -40,4 +40,4 @@ class CanFetchAddress extends AbstractRule
|
||||
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;
|
||||
@@ -40,4 +40,4 @@ class CanListAddresses extends AbstractRule
|
||||
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;
|
||||
@@ -54,4 +54,4 @@ class CanUpdateAddress extends AbstractRule
|
||||
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;
|
||||
@@ -37,4 +37,4 @@ class CanAssignSegment extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ class CanCreateAnnouncement extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -47,4 +47,4 @@ class CanCreateAnnouncement extends AbstractRule
|
||||
{
|
||||
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;
|
||||
@@ -37,4 +37,4 @@ class CanDeleteAnnouncement extends AbstractRule
|
||||
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;
|
||||
@@ -51,4 +51,4 @@ class CanUpdateAnnouncement extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ class CanCreateBank extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -47,4 +47,4 @@ class CanCreateBank extends AbstractRule
|
||||
{
|
||||
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;
|
||||
@@ -37,4 +37,4 @@ class CanDeleteBank extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ class CanListBanks extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -34,4 +34,4 @@ class CanListBanks extends AbstractRule
|
||||
{
|
||||
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;
|
||||
@@ -51,4 +51,4 @@ class CanUpdateBank extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ use App\Classes\Exceptions\MalformedRequestException;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\Modules\Billplzs\Services\GetBillplzBill;
|
||||
use App\Classes\Modules\Billplzs\DataTransferObjects\BillplzXSignatureObject;
|
||||
use App\Classes\Modules\Billplzs\Processors\CallbackBillplzProcessor;
|
||||
use App\Classes\Modules\Transactions\Services\FetchesTransaction;
|
||||
use App\Classes\Modules\Transactions\Processors\CreatePaymentTransactionProcessor;
|
||||
use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus;
|
||||
@@ -46,6 +47,9 @@ class CallbackBillplzLogic
|
||||
/** @var CreatePaymentTransactionProcessor */
|
||||
private $createPaymentTransactionProcessor;
|
||||
|
||||
/** @var CallbackBillplzProcessor */
|
||||
private $callbackBillplzProcessor;
|
||||
|
||||
/**
|
||||
* CallbackBillplzLogic constructor.
|
||||
* @param GetBillplzBill $getBillplzBill
|
||||
@@ -54,8 +58,9 @@ class CallbackBillplzLogic
|
||||
* @param UpdateDoFromVTPortalProcessor $updateDoFromVTPortalProcessor
|
||||
* @param UpdateDoFromYDPortalProcessor $updateDoFromYDPortalProcessor
|
||||
* @param CreatePaymentTransactionProcessor $createPaymentTransactionProcessor
|
||||
* @param CallbackBillplzProcessor $callbackBillplzProcessor
|
||||
*/
|
||||
public function __construct(GetBillplzBill $getBillplzBill, FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus, UpdateDoFromVTPortalProcessor $updateDoFromVTPortalProcessor, UpdateDoFromYDPortalProcessor $updateDoFromYDPortalProcessor, UpdatesWalletBalance $updatesWalletBalance, CreatePaymentTransactionProcessor $createPaymentTransactionProcessor)
|
||||
public function __construct(GetBillplzBill $getBillplzBill, FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus, UpdateDoFromVTPortalProcessor $updateDoFromVTPortalProcessor, UpdateDoFromYDPortalProcessor $updateDoFromYDPortalProcessor, UpdatesWalletBalance $updatesWalletBalance, CreatePaymentTransactionProcessor $createPaymentTransactionProcessor, CallbackBillplzProcessor $callbackBillplzProcessor)
|
||||
{
|
||||
$this->getBillplzBill = $getBillplzBill;
|
||||
$this->fetchesTransaction = $fetchesTransaction;
|
||||
@@ -64,6 +69,7 @@ class CallbackBillplzLogic
|
||||
$this->updateDoFromYDPortalProcessor = $updateDoFromYDPortalProcessor;
|
||||
$this->updatesWalletBalance = $updatesWalletBalance;
|
||||
$this->createPaymentTransactionProcessor = $createPaymentTransactionProcessor;
|
||||
$this->callbackBillplzProcessor = $callbackBillplzProcessor;
|
||||
}
|
||||
|
||||
|
||||
@@ -106,41 +112,7 @@ class CallbackBillplzLogic
|
||||
$token = Auth::fromUser(User::find(1));
|
||||
$request->headers->set('Authorization', 'Bearer '.$token);
|
||||
|
||||
// check if is wallet top up
|
||||
if($transaction->owner instanceof Wallet && $status === ApprovalStatus::APPROVED &&!in_array($transaction->status, [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])) {
|
||||
$this->updatesWalletBalance->execute($transaction->owner, $transaction->amount);
|
||||
}
|
||||
|
||||
// group payment
|
||||
if ($transaction->type == TransactionType::GROUP_PAYMENT && $status === ApprovalStatus::APPROVED &&!in_array($transaction->status, [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])) {
|
||||
$group = Group::where('reference', $billplzXSignatureObject->getBillPlzId())->first();
|
||||
|
||||
foreach($group->groupTransactions as $groupTransaction) {
|
||||
$invoice = $groupTransaction->transaction;
|
||||
$this->createPaymentTransactionProcessor->execute($invoice, PaymentMethodType::WALLET, null);
|
||||
}
|
||||
|
||||
$group->status = $status;
|
||||
$group->save();
|
||||
}
|
||||
|
||||
$this->updatesTransactionStatus->execute($transaction, $status);
|
||||
|
||||
if (!$transaction->owner instanceof Wallet) {
|
||||
$totalPaidAmount = $invoice->transactions->where('type', TransactionType::PAYMENT)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->sum('amount');
|
||||
|
||||
if(($invoice->amount - $totalPaidAmount) < 0.01) {
|
||||
$this->updatesTransactionStatus->execute($invoice, ApprovalStatus::COMPLETED);
|
||||
|
||||
$packingList->status = ApprovalStatus::APPROVED;
|
||||
$packingList->save();
|
||||
|
||||
if(app()->environment('production')){
|
||||
$this->updateDoFromVTPortalProcessor->execute($packingList);
|
||||
$this->updateDoFromYDPortalProcessor->execute($packingList);
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->callbackBillplzProcessor->execute($transaction, $status);
|
||||
|
||||
$company_module_marking = $transaction->owner->owner->connections? $transaction->owner->owner->connections->first()->invitee_reference: null;
|
||||
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Billplzs\Processors;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Wallet;
|
||||
use App\Models\Group;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Classes\ValueObjects\Constants\PaymentMethodType;
|
||||
use App\Classes\Modules\Transactions\Processors\CreatePaymentTransactionProcessor;
|
||||
use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus;
|
||||
use App\Classes\Modules\Wallets\Services\UpdatesWalletBalance;
|
||||
use App\Classes\Modules\Orders\Processors\UpdateDoFromVTPortalProcessor;
|
||||
use App\Classes\Modules\Orders\Processors\UpdateDoFromYDPortalProcessor;
|
||||
|
||||
class CallbackBillplzProcessor
|
||||
{
|
||||
/** @var UpdatesTransactionStatus */
|
||||
private $updatesTransactionStatus;
|
||||
|
||||
/** @var UpdateDoFromVTPortalProcessor */
|
||||
private $updateDoFromVTPortalProcessor;
|
||||
|
||||
/** @var UpdateDoFromYDPortalProcessor */
|
||||
private $updateDoFromYDPortalProcessor;
|
||||
|
||||
/** @var UpdatesWalletBalance */
|
||||
private $updatesWalletBalance;
|
||||
|
||||
/** @var CreatePaymentTransactionProcessor */
|
||||
private $createPaymentTransactionProcessor;
|
||||
|
||||
/**
|
||||
* CreateUserProcessor constructor.
|
||||
* @param UpdatesTransactionStatus $updatesTransactionStatus
|
||||
* @param UpdateDoFromVTPortalProcessor $updateDoFromVTPortalProcessor
|
||||
* @param UpdateDoFromYDPortalProcessor $updateDoFromYDPortalProcessor
|
||||
* @param UpdatesWalletBalance $updatesWalletBalance
|
||||
* @param CreatePaymentTransactionProcessor $createPaymentTransactionProcessor
|
||||
*/
|
||||
public function __construct(UpdatesTransactionStatus $updatesTransactionStatus, UpdateDoFromVTPortalProcessor $updateDoFromVTPortalProcessor, UpdateDoFromYDPortalProcessor $updateDoFromYDPortalProcessor, UpdatesWalletBalance $updatesWalletBalance, CreatePaymentTransactionProcessor $createPaymentTransactionProcessor)
|
||||
{
|
||||
$this->updatesTransactionStatus = $updatesTransactionStatus;
|
||||
$this->updateDoFromVTPortalProcessor = $updateDoFromVTPortalProcessor;
|
||||
$this->updateDoFromYDPortalProcessor = $updateDoFromYDPortalProcessor;
|
||||
$this->updatesWalletBalance = $updatesWalletBalance;
|
||||
$this->createPaymentTransactionProcessor = $createPaymentTransactionProcessor;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute($transaction, $status)
|
||||
{
|
||||
$invoice = $transaction->owner;
|
||||
$packingList = $invoice->owner;
|
||||
|
||||
$this->updatesTransactionStatus->execute($transaction, $status);
|
||||
|
||||
// check if is wallet top up
|
||||
if ($transaction->owner instanceof Wallet && $status === ApprovalStatus::APPROVED) {
|
||||
|
||||
$this->updatesWalletBalance->execute($transaction->owner, $transaction->amount);
|
||||
|
||||
$group = Group::where('reference', $transaction->payment_reference)->first();
|
||||
|
||||
// check if is group payment
|
||||
if ($group) {
|
||||
foreach ($group->groupTransactions as $groupTransaction) {
|
||||
$invoice = $groupTransaction->transaction;
|
||||
$this->createPaymentTransactionProcessor->execute($invoice, PaymentMethodType::WALLET, null);
|
||||
}
|
||||
|
||||
$group->status = $status;
|
||||
$group->save();
|
||||
}
|
||||
}
|
||||
|
||||
if (!$transaction->owner instanceof Wallet) {
|
||||
$totalPaidAmount = $invoice->transactions->where('type', TransactionType::PAYMENT)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->sum('amount');
|
||||
|
||||
if (($invoice->amount - $totalPaidAmount) < 0.01) {
|
||||
$this->updatesTransactionStatus->execute($invoice, ApprovalStatus::COMPLETED);
|
||||
|
||||
$packingList->status = ApprovalStatus::APPROVED;
|
||||
$packingList->save();
|
||||
|
||||
if (app()->environment('production')) {
|
||||
$this->updateDoFromVTPortalProcessor->execute($packingList);
|
||||
$this->updateDoFromYDPortalProcessor->execute($packingList);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+23
-4
@@ -10,16 +10,18 @@ use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Http\Resources\DocumentResource;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
|
||||
use App\Classes\Modules\Companies\Processors\ApproveIdentificationDocumentOnExchangeProcessor;
|
||||
use App\Classes\Modules\Documents\Services\FetchesDocument;
|
||||
|
||||
use App\Classes\Modules\Documents\Services\ApprovesDocument;
|
||||
use App\Classes\Modules\Notifications\DataTransferObjects\NotificationObject;
|
||||
Use App\Classes\Modules\Notifications\Processors\CreateNotificationProcessor;
|
||||
|
||||
use App\Classes\ValueObjects\Constants\DocumentType;
|
||||
use App\Models\Document;
|
||||
use App\Models\ExchangeCompanyConnection;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class ApproveIdentificationDocumentLogic extends AbstractControllerLogic
|
||||
{
|
||||
@@ -55,6 +57,9 @@ class ApproveIdentificationDocumentLogic extends AbstractControllerLogic
|
||||
/** @var CreateNotificationProcessor */
|
||||
private $createNotificationProcessor;
|
||||
|
||||
/** @var ApproveIdentificationDocumentOnExchangeProcessor */
|
||||
private $approveIdentificationDocumentOnExchangeProcessor;
|
||||
|
||||
/**
|
||||
* ApproveIdentificationDocumentLogic constructor.
|
||||
* @param CanApproveDocument $canApproveDocument
|
||||
@@ -64,8 +69,9 @@ class ApproveIdentificationDocumentLogic extends AbstractControllerLogic
|
||||
* @param UpdatesCompanyStatus $updatesCompanyStatus
|
||||
* @param UpdatesOrdersStatus $updatesOrdersStatus
|
||||
* @param CreateNotificationProcessor $createNotificationProcessor
|
||||
* @param ApproveIdentificationDocumentOnExchangeProcessor $approveIdentificationDocumentOnExchangeProcessor
|
||||
*/
|
||||
public function __construct(CanApproveDocument $canApproveDocument, ApprovesDocument $approvesDocument, RejectsDocument $rejectsDocument, FetchesDocument $fetchesDocument, UpdatesCompanyStatus $updatesCompanyStatus, UpdatesOrdersStatus $updatesOrdersStatus, CreateNotificationProcessor $createNotificationProcessor)
|
||||
public function __construct(CanApproveDocument $canApproveDocument, ApprovesDocument $approvesDocument, RejectsDocument $rejectsDocument, FetchesDocument $fetchesDocument, UpdatesCompanyStatus $updatesCompanyStatus, UpdatesOrdersStatus $updatesOrdersStatus, CreateNotificationProcessor $createNotificationProcessor, ApproveIdentificationDocumentOnExchangeProcessor $approveIdentificationDocumentOnExchangeProcessor)
|
||||
{
|
||||
$this->canApproveDocument = $canApproveDocument;
|
||||
$this->approvesDocument = $approvesDocument;
|
||||
@@ -74,6 +80,7 @@ class ApproveIdentificationDocumentLogic extends AbstractControllerLogic
|
||||
$this->updatesCompanyStatus = $updatesCompanyStatus;
|
||||
$this->updatesOrdersStatus = $updatesOrdersStatus;
|
||||
$this->createNotificationProcessor = $createNotificationProcessor;
|
||||
$this->approveIdentificationDocumentOnExchangeProcessor = $approveIdentificationDocumentOnExchangeProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,11 +92,18 @@ class ApproveIdentificationDocumentLogic extends AbstractControllerLogic
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$documentId = $request->route('document_id');
|
||||
|
||||
if ($request->route('exchange_company_id')) {
|
||||
$companyModule = ExchangeCompanyConnection::where('exchange_company_id', $request->route('exchange_company_id'))->first()->companyModule;
|
||||
$company = $companyModule->company;
|
||||
$documentId = $company->documents()->whereIn('document_type', DocumentType::IDENTIFICATION_DOCUMENTS)->where('status', ApprovalStatus::PENDING_VERIFICATION)->first()->id;
|
||||
}
|
||||
|
||||
$status = $request->route('status');
|
||||
|
||||
/** @var Document $document */
|
||||
$document = $this->fetchesDocument->execute(['id' => $request->route('document_id')]);
|
||||
$document = $this->fetchesDocument->execute(['id' => $documentId]);
|
||||
|
||||
$this->canApproveDocument->passes();
|
||||
|
||||
@@ -111,6 +125,11 @@ class ApproveIdentificationDocumentLogic extends AbstractControllerLogic
|
||||
$orders = $this->updatesOrdersStatus->execute($document->owner, ApprovalStatus::APPROVED);
|
||||
}
|
||||
|
||||
// if this request is not calling from exchange portal, then approve the document on exchange portal for this user
|
||||
$companyModule = $document->owner->companyModules()->first();
|
||||
if (!$request->route('exchange_company_id') && $companyModule->exchangeCompanyConnection()->first()) {
|
||||
$this->approveIdentificationDocumentOnExchangeProcessor->execute($request, $companyModule->id, $status);
|
||||
}
|
||||
|
||||
return $this->resourceResponse(new DocumentResource($document));
|
||||
|
||||
|
||||
+22
-2
@@ -4,6 +4,7 @@ namespace App\Classes\Modules\Companies\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Companies\Processors\CreateIdentificationDocumentOnExchangeProcessor;
|
||||
use App\Classes\Modules\Companies\Services\FetchesCompany;
|
||||
use App\Classes\Modules\Companies\Services\UpdatesCompanyStatus;
|
||||
use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject;
|
||||
@@ -14,6 +15,7 @@ use App\Classes\ValueObjects\Constants\CompanyType;
|
||||
use App\Classes\ValueObjects\Constants\DocumentType;
|
||||
use App\Models\Company;
|
||||
use App\Models\Document;
|
||||
use App\Models\ExchangeCompanyConnection;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
@@ -42,6 +44,9 @@ class CreateIdentificationDocumentLogic extends AbstractControllerLogic
|
||||
/** @var UpdatesCompanyStatus */
|
||||
private $updatesCompanyStatus;
|
||||
|
||||
/** @var CreateIdentificationDocumentOnExchangeProcessor */
|
||||
private $createIdentificationDocumentOnExchangeProcessor;
|
||||
|
||||
|
||||
/**
|
||||
* CreateIdentificationDocumentLogic constructor.
|
||||
@@ -49,13 +54,15 @@ class CreateIdentificationDocumentLogic extends AbstractControllerLogic
|
||||
* @param CreatesDocument $createsDocument
|
||||
* @param CreatesFiles $createsFile
|
||||
* @param UpdatesCompanyStatus $updatesCompanyStatus
|
||||
* @param CreateIdentificationDocumentOnExchangeProcessor $createIdentificationDocumentOnExchangeProcessor
|
||||
*/
|
||||
public function __construct(FetchesCompany $fetchesCompany, CreatesDocument $createsDocument, CreatesFiles $createsFile, UpdatesCompanyStatus $updatesCompanyStatus)
|
||||
public function __construct(FetchesCompany $fetchesCompany, CreatesDocument $createsDocument, CreatesFiles $createsFile, UpdatesCompanyStatus $updatesCompanyStatus, CreateIdentificationDocumentOnExchangeProcessor $createIdentificationDocumentOnExchangeProcessor)
|
||||
{
|
||||
$this->fetchesCompany = $fetchesCompany;
|
||||
$this->createsDocument = $createsDocument;
|
||||
$this->createsFile = $createsFile;
|
||||
$this->updatesCompanyStatus = $updatesCompanyStatus;
|
||||
$this->createIdentificationDocumentOnExchangeProcessor = $createIdentificationDocumentOnExchangeProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,8 +73,15 @@ class CreateIdentificationDocumentLogic extends AbstractControllerLogic
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
|
||||
if ($request->route('exchange_company_id')) {
|
||||
$companyModule = ExchangeCompanyConnection::where('exchange_company_id', $request->route('exchange_company_id'))->first()->companyModule;
|
||||
$companyId = $companyModule->company_id;
|
||||
} else {
|
||||
$companyId = $request->route('id');
|
||||
}
|
||||
|
||||
/** @var Company $company */
|
||||
$company = $this->fetchesCompany->execute(['id' => $request->route('id')]);
|
||||
$company = $this->fetchesCompany->execute(['id' => $companyId]);
|
||||
$object = new DocumentObject($company->type === CompanyType::COMPANY_BUSINESS ?
|
||||
DocumentType::SSM_REGISTRATION : DocumentType::IDENTITY_CARD, $request->input('files'),
|
||||
$request->input('identification_no'), ApprovalStatus::PENDING_VERIFICATION, 'identifications');
|
||||
@@ -78,6 +92,12 @@ class CreateIdentificationDocumentLogic extends AbstractControllerLogic
|
||||
|
||||
$this->updatesCompanyStatus->execute($company, ApprovalStatus::PENDING_VERIFICATION);
|
||||
|
||||
// create identification on exchange if this request not coming from exchange
|
||||
$companyModule = $company->companyModules()->first();
|
||||
if (!$request->route('exchange_company_id') && $companyModule->exchangeCompanyConnection()->first()) {
|
||||
$this->createIdentificationDocumentOnExchangeProcessor->execute($request, $companyModule->id);
|
||||
}
|
||||
|
||||
return $this->response([]);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Companies\ControllersLogic;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Companies\Processors\LinkExchangeCompanyProcessor;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class LinkExchangeCompanyLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Connect Exchange with Izyim Account',
|
||||
'message' => 'You have successfully connect your exchange account to Izyim Account'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var LinkExchangeCompanyProcessor */
|
||||
private $linkExchangeCompanyProcessor;
|
||||
|
||||
|
||||
/**
|
||||
* LinkExchangeCompanyLogic constructor.
|
||||
* @param LinkExchangeCompanyProcessor $linkExchangeCompanyProcessor
|
||||
*/
|
||||
public function __construct(LinkExchangeCompanyProcessor $linkExchangeCompanyProcessor)
|
||||
{
|
||||
$this->linkExchangeCompanyProcessor = $linkExchangeCompanyProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws \App\Classes\Exceptions\AccessForbiddenException
|
||||
* @throws \App\Classes\Exceptions\AccessUnauthorisedException
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
protected function logic(Request $request): JsonResponse {
|
||||
|
||||
return $this->response($this->linkExchangeCompanyProcessor->execute($request));
|
||||
}
|
||||
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Companies\Processors;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class ApproveIdentificationDocumentOnExchangeProcessor
|
||||
{
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return string
|
||||
* @throws \App\Classes\Exceptions\AccessForbiddenException
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
public function execute(Request $request, $companyModuleId, $status) {
|
||||
if (App::environment(['production'])) {
|
||||
dd("Delete this line before push to production");
|
||||
$url = "https://exchange.cief-malaysia.com/api/v1/shipping/company/{$companyModuleId}/identification/approval/{$status}";
|
||||
} else if (App::environment(['local'])) {
|
||||
$url = "http://127.0.0.1:8000/api/v1/shipping/company/{$companyModuleId}/identification/approval/{$status}";
|
||||
} else {
|
||||
$url = "https://dev.exchange.cief-malaysia.com/api/v1/shipping/company/{$companyModuleId}/identification/approval/{$status}";
|
||||
}
|
||||
try {
|
||||
$client = new \GuzzleHttp\Client(['verify' => false]);
|
||||
$token = $request->bearerToken();
|
||||
$headers = [
|
||||
'Authorization' => 'Bearer ' . $token,
|
||||
'Accept' => 'application/json',
|
||||
];
|
||||
$formParams = $request->toArray();
|
||||
$response = $client->request('PUT', $url, [
|
||||
'headers' => $headers,
|
||||
'form_params' => $formParams
|
||||
]);
|
||||
$body = $response->getBody();
|
||||
$contents = json_decode($body, true);
|
||||
|
||||
return $contents;
|
||||
} catch(\GuzzleHttp\Exception\RequestException $exception){
|
||||
Log::error($exception->getResponse()->getBody()->getContents());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Companies\Processors;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class CreateIdentificationDocumentOnExchangeProcessor
|
||||
{
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return string
|
||||
* @throws \App\Classes\Exceptions\AccessForbiddenException
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
public function execute(Request $request, $companyModuleId) {
|
||||
if (App::environment(['production'])) {
|
||||
dd("Delete this line before push to production");
|
||||
$url = "https://exchange.cief-malaysia.com/api/v1/shipping/company/{$companyModuleId}/identification/create";
|
||||
} else if (App::environment(['local'])) {
|
||||
$url = "http://127.0.0.1:8000/api/v1/shipping/company/{$companyModuleId}/identification/create";
|
||||
} else {
|
||||
$url = "https://dev.exchange.cief-malaysia.com/api/v1/shipping/company/{$companyModuleId}/identification/create";
|
||||
}
|
||||
try {
|
||||
$client = new \GuzzleHttp\Client(['verify' => false]);
|
||||
$token = $request->bearerToken();
|
||||
$headers = [
|
||||
'Authorization' => 'Bearer ' . $token,
|
||||
'Accept' => 'application/json',
|
||||
];
|
||||
$formParams = $request->toArray();
|
||||
$response = $client->request('POST', $url, [
|
||||
'headers' => $headers,
|
||||
'form_params' => $formParams
|
||||
]);
|
||||
$body = $response->getBody();
|
||||
$contents = json_decode($body, true);
|
||||
|
||||
return $contents;
|
||||
} catch(\GuzzleHttp\Exception\RequestException $exception){
|
||||
Log::error($exception->getResponse()->getBody()->getContents());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Companies\Processors;
|
||||
|
||||
use App\Classes\Modules\Accounts\DataTransferObjects\AuthenticationCredentialsObject;
|
||||
use App\Classes\Modules\Accounts\Services\AuthenticatesUser;
|
||||
use App\Classes\Modules\Accounts\Services\AuthenticationRedirect;
|
||||
use App\Classes\Modules\Accounts\Services\FetchesUser;
|
||||
use App\Classes\Modules\Accounts\Services\GeneratesAuthenticationToken;
|
||||
use App\Classes\Modules\Accounts\Standards\Rules\CanAuthenticateUser;
|
||||
use App\Classes\Modules\Companies\Services\ConnectCompanyModuleToExchangeCompany;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class LinkExchangeCompanyProcessor
|
||||
{
|
||||
|
||||
/** @var CanAuthenticateUser */
|
||||
private $canAuthenticateUser;
|
||||
|
||||
/** @var AuthenticatesUser */
|
||||
private $authenticatesUser;
|
||||
|
||||
/** @var GeneratesAuthenticationToken */
|
||||
private $generatesAuthenticationToken;
|
||||
|
||||
/** @var FetchesUser */
|
||||
private $fetchesUser;
|
||||
|
||||
/** @var AuthenticationRedirect */
|
||||
private $authenticationRedirect;
|
||||
|
||||
/** @var ConnectCompanyModuleToExchangeCompany */
|
||||
private $connectCompanyModuleToExchangeCompany;
|
||||
|
||||
/**
|
||||
* AuthenticationProcessor constructor.
|
||||
* @param CanAuthenticateUser $canAuthenticateUser
|
||||
* @param AuthenticatesUser $authenticatesUser
|
||||
* @param GeneratesAuthenticationToken $generatesAuthenticationToken
|
||||
* @param FetchesUser $fetchesUser
|
||||
* @param AuthenticationRedirect $authenticationRedirect
|
||||
* @param ConnectCompanyModuleToExchangeCompany $connectCompanyModuleToExchangeCompany
|
||||
*/
|
||||
public function __construct(CanAuthenticateUser $canAuthenticateUser, AuthenticatesUser $authenticatesUser, GeneratesAuthenticationToken $generatesAuthenticationToken, FetchesUser $fetchesUser, AuthenticationRedirect $authenticationRedirect, ConnectCompanyModuleToExchangeCompany $connectCompanyModuleToExchangeCompany)
|
||||
{
|
||||
$this->canAuthenticateUser = $canAuthenticateUser;
|
||||
$this->authenticatesUser = $authenticatesUser;
|
||||
$this->generatesAuthenticationToken = $generatesAuthenticationToken;
|
||||
$this->fetchesUser = $fetchesUser;
|
||||
$this->authenticationRedirect = $authenticationRedirect;
|
||||
$this->connectCompanyModuleToExchangeCompany = $connectCompanyModuleToExchangeCompany;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return array
|
||||
* @throws \App\Classes\Exceptions\AccessForbiddenException
|
||||
* @throws \App\Classes\Exceptions\AccessUnauthorisedException
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
public function execute(Request $request): array {
|
||||
|
||||
$object = new AuthenticationCredentialsObject($request->input('email'), $request->input('password'));
|
||||
|
||||
$this->canAuthenticateUser->passes($object);
|
||||
|
||||
$this->authenticatesUser->execute($object);
|
||||
|
||||
$user = $this->fetchesUser->execute(['email' => $object->getEmail()]);
|
||||
|
||||
$companyModule = $user->companyModule()->first();
|
||||
|
||||
$this->connectCompanyModuleToExchangeCompany->execute($companyModule, $request->route('exchange_company_id'));
|
||||
|
||||
return ['shipping_company_module_id' => $companyModule->id];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Companies\Services;
|
||||
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Models\CompanyModule;
|
||||
use App\Models\ExchangeCompanyConnection;
|
||||
|
||||
class ConnectCompanyModuleToExchangeCompany extends AbstractUpdateRecord
|
||||
{
|
||||
/**
|
||||
* @param Company $company
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws MalformedRequestException
|
||||
*/
|
||||
public function execute(CompanyModule $companyModule, $exchangeCompanyId)
|
||||
{
|
||||
$model = new ExchangeCompanyConnection();
|
||||
$model->company_module_id = $companyModule->id;
|
||||
$model->exchange_company_id = $exchangeCompanyId;
|
||||
|
||||
return $this->handler($model);
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ class CanAssignEmployee extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
@@ -51,4 +51,4 @@ class CanAssignEmployee extends AbstractRule
|
||||
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;
|
||||
@@ -37,4 +37,4 @@ class CanAssignSegment extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ class CanCreateCompany extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
@@ -48,4 +48,4 @@ class CanCreateCompany extends AbstractRule
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ class CanCreateCompanyModule extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -13,7 +13,7 @@ class CanFetchCompany extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
@@ -40,4 +40,4 @@ class CanFetchCompany extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ class CanListCompanies extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
@@ -40,4 +40,4 @@ class CanListCompanies extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ class CanUpdateCompany extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
@@ -48,4 +48,4 @@ class CanUpdateCompany extends AbstractRule
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ class CanCreateContact extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
@@ -51,4 +51,4 @@ class CanCreateContact extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ class CanCreateCurrency extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
@@ -48,4 +48,4 @@ class CanCreateCurrency extends AbstractRule
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ class CanDeleteCurrency extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
@@ -36,4 +36,4 @@ class CanDeleteCurrency extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ class CanFetchCurrency extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
@@ -37,4 +37,4 @@ class CanFetchCurrency extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ class CanListCurrency extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
|
||||
@@ -38,4 +38,4 @@ class CanListCurrency extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ class CanUpdateCurrency extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
@@ -51,4 +51,4 @@ class CanUpdateCurrency extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ class CanCreateRate extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
if (!\Auth::user()->can('add currency_rate')) {
|
||||
@@ -52,4 +52,4 @@ class CanCreateRate extends AbstractRule
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ class CanDeleteRate extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
|
||||
@@ -42,4 +42,4 @@ class CanDeleteRate extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ class CanFetchRate extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
@@ -40,4 +40,4 @@ class CanFetchRate extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ class CanListRates extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
|
||||
@@ -42,4 +42,4 @@ class CanListRates extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ class CanUpdateRate extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
|
||||
@@ -55,4 +55,4 @@ class CanUpdateRate extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Documents\Processors;
|
||||
|
||||
use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject;
|
||||
use App\Classes\Modules\Documents\Services\CreatesDocument;
|
||||
use App\Classes\Modules\Documents\Services\CreatesFiles;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Models\Document;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\QAUserAnswerSelected;
|
||||
|
||||
class UploadDocumentForHelpMenuProcessor
|
||||
{
|
||||
|
||||
/** @var CreatesDocument */
|
||||
private $createsDocument;
|
||||
|
||||
/** @var CreatesFiles */
|
||||
private $createsFiles;
|
||||
|
||||
/**
|
||||
* UploadDocumentForHelpMenuProcessor constructor.
|
||||
* @param CreatesDocument $createsDocument
|
||||
* @param CreatesFiles $createsFiles
|
||||
*/
|
||||
public function __construct(CreatesDocument $createsDocument, CreatesFiles $createsFiles)
|
||||
{
|
||||
$this->createsDocument = $createsDocument;
|
||||
$this->createsFiles = $createsFiles;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $filesUpload
|
||||
* @param QAUserAnswerSelected qaUserAnswerSelected
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute($filesUpload, QAUserAnswerSelected $qaUserAnswerSelected) {
|
||||
$object = new DocumentObject("HELP_MENU", $filesUpload,
|
||||
'123456', ApprovalStatus::PENDING_VERIFICATION, 'help_menu'); //cief todo: 123456 cannot be hardcoded
|
||||
|
||||
/** @var Document $document */
|
||||
$document = $this->createsDocument->execute($qaUserAnswerSelected, $object);
|
||||
|
||||
$result = $this->createsFiles->execute($document, $object);
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,6 +5,7 @@ namespace App\Classes\Modules\Documents\Services;
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Models\Document;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class ApprovesDocument extends AbstractUpdateRecord
|
||||
@@ -17,8 +18,19 @@ class ApprovesDocument extends AbstractUpdateRecord
|
||||
*/
|
||||
public function execute(Document $model)
|
||||
{
|
||||
$user = Auth()->user();
|
||||
// if auth user is null, then this services is calling from exchange
|
||||
if (!$user) {
|
||||
$token = explode('.', request()->bearerToken())[1];
|
||||
$decodedToken = base64_decode($token);
|
||||
$exchangeUser = json_decode($decodedToken, true)['user'];
|
||||
$user = User::where('email', $exchangeUser['email'])->first();
|
||||
if (!$user) {
|
||||
$user = User::find(1);
|
||||
}
|
||||
}
|
||||
$model->status = ApprovalStatus::APPROVED;
|
||||
$model->approver = Auth()->user()->id;
|
||||
$model->approver = $user->id;
|
||||
$model->approval_date = Carbon::now();
|
||||
|
||||
return $this->handler($model);
|
||||
|
||||
@@ -5,7 +5,10 @@ namespace App\Classes\Modules\Documents\Services;
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Models\Document;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class RejectsDocument extends AbstractUpdateRecord
|
||||
{
|
||||
@@ -17,8 +20,19 @@ class RejectsDocument extends AbstractUpdateRecord
|
||||
*/
|
||||
public function execute(Document $model)
|
||||
{
|
||||
$user = Auth()->user();
|
||||
// if auth user is null, then this services is calling from exchange
|
||||
if (!$user) {
|
||||
$token = explode('.', request()->bearerToken())[1];
|
||||
$decodedToken = base64_decode($token);
|
||||
$exchangeUser = json_decode($decodedToken, true)['user'];
|
||||
$user = User::where('email', $exchangeUser['email'])->first();
|
||||
if (!$user) {
|
||||
$user = User::find(1);
|
||||
}
|
||||
}
|
||||
$model->status = ApprovalStatus::REJECTED;
|
||||
$model->approver = Auth()->user()->id;
|
||||
$model->approver = $user->id;
|
||||
$model->approval_date = Carbon::now();
|
||||
|
||||
return $this->handler($model);
|
||||
|
||||
@@ -12,7 +12,7 @@ class CanApproveDocument extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
@@ -36,4 +36,4 @@ class CanApproveDocument extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ class CanCreateDocument extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
@@ -50,4 +50,4 @@ class CanCreateDocument extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ class CanCreateFile extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
@@ -50,4 +50,4 @@ class CanCreateFile extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ class CanListDocuments extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
|
||||
/*
|
||||
@@ -44,4 +44,4 @@ class CanListDocuments extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ class CanRenderDocument extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
@@ -36,4 +36,4 @@ class CanRenderDocument extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ class CanUpdateDocument extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
@@ -50,4 +50,4 @@ class CanUpdateDocument extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ class CanUpdateDocumentReference extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
@@ -36,4 +36,4 @@ class CanUpdateDocumentReference extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Exports\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\Abstract2ControllerLogic;
|
||||
use App\Classes\Modules\Exports\Services\ExportsFeedback;
|
||||
use App\Classes\Modules\Exports\Standards\Rules\CanExportFeedback;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
use Maatwebsite\Excel\Excel;
|
||||
|
||||
class ExportFeedbackDataLogic extends Abstract2ControllerLogic
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Retrieved Feedback',
|
||||
'message' => 'You have successfully exported feedback data'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var ExportsFeedback */
|
||||
private $exportsFeedback;
|
||||
|
||||
/** @var CanExportFeedback */
|
||||
private $canExportFeedback;
|
||||
|
||||
/**
|
||||
* ExportFeedbackDataLogic constructor.
|
||||
* @param ExportsFeedback $exportsFeedback
|
||||
* @param CanExportFeedback $canExportFeedback
|
||||
*/
|
||||
public function __construct(ExportsFeedback $exportsFeedback, CanExportFeedback $canExportFeedback)
|
||||
{
|
||||
$this->exportsFeedback = $exportsFeedback;
|
||||
$this->canExportFeedback = $canExportFeedback;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
public function logic(Request $request) : BinaryFileResponse
|
||||
{
|
||||
$this->canExportFeedback->passes();
|
||||
|
||||
$response = $this->exportsFeedback->download('feedback.xls', Excel::XLS, ['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']);
|
||||
ob_end_clean();
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Exports\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\Abstract2ControllerLogic;
|
||||
use App\Classes\Modules\Exports\Standards\Rules\CanExportPackingList;
|
||||
use App\Classes\Modules\Exports\Services\ExportsOnHoldPackingList;
|
||||
use App\Classes\Modules\Exports\Services\ExportsPendingArrangementDeliveryList;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
use Maatwebsite\Excel\Excel;
|
||||
|
||||
class ExportPackingListLogic extends Abstract2ControllerLogic
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Retrieved PackingList',
|
||||
'message' => 'You have successfully exported PackingList'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var ExportsOnHoldPackingList */
|
||||
private $exportsOnHoldPackingList;
|
||||
|
||||
/** @var ExportsPendingArrangementDeliveryList */
|
||||
private $exportsPendingArrangementDeliveryList;
|
||||
|
||||
/** @var CanExportPackingList */
|
||||
private $canExportPackingList;
|
||||
|
||||
/**
|
||||
* ExportPackingListLogic constructor.
|
||||
* @param ExportsPendingArrangementDeliveryList $exportsPendingArrangementDeliveryList
|
||||
* @param ExportsOnHoldPackingList $exportsOnHoldPackingList
|
||||
* @param CanExportPackingList $canExportPackingList
|
||||
*/
|
||||
public function __construct(ExportsPendingArrangementDeliveryList $exportsPendingArrangementDeliveryList, ExportsOnHoldPackingList $exportsOnHoldPackingList, CanExportPackingList $canExportPackingList)
|
||||
{
|
||||
$this->exportsPendingArrangementDeliveryList = $exportsPendingArrangementDeliveryList;
|
||||
$this->exportsOnHoldPackingList = $exportsOnHoldPackingList;
|
||||
$this->canExportPackingList = $canExportPackingList;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
public function logic(Request $request) : BinaryFileResponse
|
||||
{
|
||||
$this->canExportPackingList->passes();
|
||||
$isSetPendingArrangement = $request->header('PendingArrangement');
|
||||
if($isSetPendingArrangement){
|
||||
$response = $this->exportsPendingArrangementDeliveryList->download('packing-list-delivery.xls', Excel::XLS, ['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']);
|
||||
}
|
||||
else {
|
||||
$response = $this->exportsOnHoldPackingList->download('packing-list-on-hold.xls', Excel::XLS, ['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']);
|
||||
}
|
||||
|
||||
ob_end_clean();
|
||||
return $response;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Exports\Services;
|
||||
|
||||
use App\Models\Order;
|
||||
use App\Models\PackingList;
|
||||
use Maatwebsite\Excel\Concerns\FromQuery;
|
||||
use Maatwebsite\Excel\Concerns\Exportable;
|
||||
use Maatwebsite\Excel\Concerns\WithMapping;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadingRow;
|
||||
use App\Classes\General\Eloquent\ApplyFiltersToQuery;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use DateTime;
|
||||
|
||||
class ExportsAgingList implements WithHeadings, WithHeadingRow, WithMapping, ShouldAutoSize, FromQuery
|
||||
{
|
||||
use Exportable;
|
||||
|
||||
private $filters;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->filters = [
|
||||
"has_invoice_status_in" => [2],
|
||||
"packing_list_ordered_by_invoice_date" => true,
|
||||
"with_aging_column" => true
|
||||
];
|
||||
}
|
||||
|
||||
public function headings(): array
|
||||
{
|
||||
return [
|
||||
'Company Name',
|
||||
'Customer Marking',
|
||||
'Order Number',
|
||||
'Invoice No',
|
||||
'Invoice Date',
|
||||
'Days',
|
||||
'Amount',
|
||||
];
|
||||
}
|
||||
|
||||
public function query()
|
||||
{
|
||||
return (new ApplyFiltersToQuery())->execute(PackingList::query(), $this->filters);
|
||||
}
|
||||
|
||||
public function map($list): array
|
||||
{
|
||||
$marking = null;
|
||||
$orderNo = null;
|
||||
$name = null;
|
||||
$invDate = 'n/a';
|
||||
$invNo = 'n/a';
|
||||
$days = 'n/a';
|
||||
|
||||
if ($list->owner instanceof Order) {
|
||||
$inviterPivotInviteeReference = $list->owner->companyModule->inviters()->withPivot('invitee_reference')->first();
|
||||
|
||||
if ($inviterPivotInviteeReference) {
|
||||
$marking = $inviterPivotInviteeReference->pivot->invitee_reference;
|
||||
$orderNo = $list->owner->reference;
|
||||
}
|
||||
$name = $list->owner->companyModule->company->name;
|
||||
}
|
||||
|
||||
$transaction = $list->transactions()->whereIn('status', [ApprovalStatus::APPROVED])->first();
|
||||
if ($transaction) {
|
||||
|
||||
$invoiceDate = $transaction->created_at;
|
||||
$invDate = date_format($invoiceDate, 'd-m-Y');
|
||||
$invNo = $transaction->bill_no;
|
||||
$amt = number_format($transaction->amount, 2);
|
||||
|
||||
$currentDate = new DateTime();
|
||||
$interval = $currentDate->diff($invoiceDate);
|
||||
$days = $interval->format('%a');
|
||||
}
|
||||
|
||||
return [
|
||||
$name,
|
||||
$marking,
|
||||
$orderNo,
|
||||
$invNo,
|
||||
$invDate,
|
||||
$days,
|
||||
$amt,
|
||||
];
|
||||
}
|
||||
|
||||
private function dueDateColumn($colNum, $dueDateNumber, $amt)
|
||||
{
|
||||
if ($colNum == $dueDateNumber) return $amt;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -15,9 +15,17 @@ use App\Classes\ValueObjects\Constants\OrderRoleTypes;
|
||||
|
||||
class ExportsArrivedParcel implements WithHeadings, WithHeadingRow, WithMapping, ShouldAutoSize, FromQuery
|
||||
{
|
||||
|
||||
use Exportable;
|
||||
|
||||
private $start_date;
|
||||
private $end_date;
|
||||
|
||||
public function __construct($start_date = null, $end_date = null)
|
||||
{
|
||||
$this->start_date = $start_date;
|
||||
$this->end_date = $end_date;
|
||||
}
|
||||
|
||||
public function headings(): array
|
||||
{
|
||||
return [
|
||||
@@ -26,38 +34,49 @@ class ExportsArrivedParcel implements WithHeadings, WithHeadingRow, WithMapping,
|
||||
'Warehouse',
|
||||
'Cbm',
|
||||
'Description',
|
||||
'quantity',
|
||||
'Quantity',
|
||||
'Received Date',
|
||||
'Recorded On',
|
||||
'Days to Record',
|
||||
'Remarks'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Support\Collection|mixed
|
||||
*/
|
||||
public function query()
|
||||
{
|
||||
return PackingList::where('type', '=', 1)->where('status', '=', 2)->where('owner_type', Order::class);
|
||||
$query = PackingList::with([
|
||||
'owner.companyModule.inviters',
|
||||
'owner.orderRoles',
|
||||
'packages',
|
||||
'transports'
|
||||
])
|
||||
->where('type', '=', 1)
|
||||
->where('status', '=', 2)
|
||||
->where('owner_type', Order::class);
|
||||
|
||||
if (!is_null($this->start_date) && !is_null($this->end_date)) {
|
||||
$query->whereHas('transports', function ($q) {
|
||||
$q->whereBetween('drop_date', [
|
||||
Carbon::parse($this->start_date)->startOfDay(),
|
||||
Carbon::parse($this->end_date)->endOfDay()
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $packingList
|
||||
* @return array
|
||||
*/
|
||||
public function map($packingList): array
|
||||
{
|
||||
$order = $packingList->owner;
|
||||
|
||||
$connection = $order->companyModule()->first()->inviters()->withPivot('invitee_reference')->first();
|
||||
$marking = $connection ? $connection->pivot->invitee_reference:'';
|
||||
|
||||
$warehouse = $order->orderRoles()->where('role_id', '=', OrderRoleTypes::ORIGIN_WAREHOUSE)->first()->appointee;
|
||||
|
||||
$cbm = $packingList->packages->sum(function($package){
|
||||
return (($package->width / 100) * ($package->height / 100) * ($package->length / 100)) * $package->quantity;
|
||||
$marking = $order->companyModule->getMarking();
|
||||
$warehouse = $order->orderRoles->firstWhere('role_id', '=', OrderRoleTypes::ORIGIN_WAREHOUSE)->appointee;
|
||||
$cbm = $packingList->packages->sum(function ($package) {
|
||||
return (($package->width / 100) * ($package->height / 100) * ($package->length / 100)) * $package->quantity;
|
||||
});
|
||||
|
||||
$arrival_date = $packingList->transports()->first()->drop_date->format('d-m-Y');
|
||||
$arrival_date = $packingList->transports->first()->drop_date->format('d-m-Y');
|
||||
$recorded_on = $packingList->created_at->format('d-m-Y');
|
||||
$days_to_record = Carbon::parse($arrival_date)->diffInDays(Carbon::parse($recorded_on));
|
||||
|
||||
return [
|
||||
$packingList->owner->reference,
|
||||
@@ -67,7 +86,9 @@ class ExportsArrivedParcel implements WithHeadings, WithHeadingRow, WithMapping,
|
||||
$packingList->packages->implode('description', ', '),
|
||||
$packingList->packages->sum('quantity'),
|
||||
$arrival_date,
|
||||
$recorded_on,
|
||||
$days_to_record,
|
||||
''
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Exports\Services;
|
||||
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Models\Transaction;
|
||||
use App\Models\Company;
|
||||
use App\Models\Wallet;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Maatwebsite\Excel\Concerns\Exportable;
|
||||
use Maatwebsite\Excel\Concerns\FromQuery;
|
||||
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadingRow;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\WithMapping;
|
||||
|
||||
class ExportsCustomersWalletTransactionHistory implements FromQuery, WithHeadings, WithHeadingRow, WithMapping, ShouldAutoSize
|
||||
{
|
||||
use Exportable;
|
||||
|
||||
private $request;
|
||||
private $runningBalance = 0;
|
||||
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
public function headings(): array
|
||||
{
|
||||
return [
|
||||
'Date',
|
||||
'Description',
|
||||
'Incoming',
|
||||
'Outgoing',
|
||||
'Balance',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Support\Collection|mixed
|
||||
*/
|
||||
public function query()
|
||||
{
|
||||
$wallet = Wallet::find($this->request->route('wallet_id'));
|
||||
$transactions = $wallet->transactions()->whereIn('transactions.status', [2, 3])->orderBy('id');
|
||||
|
||||
return $transactions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Transaction $transaction
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function map($transaction): array
|
||||
{
|
||||
$decimals = $this->request->route('is_precise') == 'true' ? 5 : 2;
|
||||
|
||||
$description = '';
|
||||
switch ((int) $transaction->type) {
|
||||
case TransactionType::TOP_UP:
|
||||
$description = (float) $transaction->amount . ' Credit Top up';
|
||||
break;
|
||||
case TransactionType::GROUP_PAYMENT:
|
||||
$description = (float) $transaction->amount . ' Credit Top up';
|
||||
break;
|
||||
case TransactionType::CREDIT_NOTE:
|
||||
$description = 'Credit Voucher for ' . $transaction->payment_reference;
|
||||
break;
|
||||
case TransactionType::PAYMENT:
|
||||
$booking = Transaction::where('payment_reference', $transaction->bill_no)->first()->owner;
|
||||
|
||||
if (!$booking) {
|
||||
$description = 'Payment for unknown booking, please contact tech support.';
|
||||
break;
|
||||
}
|
||||
|
||||
$marking = $booking->marking;
|
||||
$description = 'Payment For booking refs' . $marking;
|
||||
break;
|
||||
case TransactionType::DEBIT_NOTE:
|
||||
$description = 'Debit Voucher for ' . $transaction->payment_reference;
|
||||
break;
|
||||
}
|
||||
|
||||
$incoming = $outgoing = '';
|
||||
|
||||
if (in_array($transaction->type, [TransactionType::TOP_UP, TransactionType::CREDIT_NOTE, TransactionType::GROUP_PAYMENT])) {
|
||||
$incoming = number_format($transaction->amount, $decimals, '.', ',');
|
||||
$this->runningBalance += $transaction->amount;
|
||||
}
|
||||
|
||||
if (in_array($transaction->type, [TransactionType::PAYMENT, TransactionType::DEBIT_NOTE])) {
|
||||
$outgoing = number_format($transaction->amount, $decimals, '.', ',');
|
||||
$this->runningBalance -= $transaction->amount;
|
||||
}
|
||||
|
||||
return [
|
||||
Carbon::parse($transaction->created_at)->format('d-m-Y h:i:s A'),
|
||||
$description,
|
||||
$incoming,
|
||||
$outgoing,
|
||||
number_format($this->runningBalance, $decimals, '.', ',')
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Exports\Services;
|
||||
|
||||
use App\Models\QAUserAnswerSelected;
|
||||
use Maatwebsite\Excel\Concerns\Exportable;
|
||||
use Maatwebsite\Excel\Concerns\FromQuery;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadingRow;
|
||||
use Maatwebsite\Excel\Concerns\WithMapping;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||
use App\Classes\ValueObjects\Constants\QASystemSourceType;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class ExportsFeedback implements FromQuery, WithHeadings, WithHeadingRow, WithMapping, ShouldAutoSize
|
||||
{
|
||||
|
||||
use Exportable;
|
||||
|
||||
public function headings(): array
|
||||
{
|
||||
return [
|
||||
'Question Set',
|
||||
'Question Text',
|
||||
'Answer',
|
||||
'Source System',
|
||||
'Source Marking',
|
||||
'Source Email',
|
||||
'Created Date'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Support\Collection|mixed
|
||||
*/
|
||||
public function query()
|
||||
{
|
||||
return QAUserAnswerSelected::whereHas('question', function ($query) {
|
||||
$query->whereHas('questionnaire', function ($innerQuery) {
|
||||
$innerQuery->where('group', 'feedback');
|
||||
}); //->where('created_at', '>', Carbon::now()->subMonths(1));
|
||||
})->orderBy('created_at', 'desc');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param QAUserAnswerSelected $userAnswer
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function map($userAnswer): array
|
||||
{
|
||||
$source = $userAnswer->userSource;
|
||||
$user = $userAnswer->source_id === 0 ? $userAnswer->user : null;
|
||||
$user_marking = '';
|
||||
if($user){
|
||||
$companyModule = $user->companyModule()->first();
|
||||
$user_marking = $companyModule ? $companyModule->inviters()->withPivot('invitee_reference')->first()->pivot->invitee_reference : "";
|
||||
}
|
||||
|
||||
return [
|
||||
$userAnswer->question->questionnaire->description,
|
||||
$userAnswer->question->question_text,
|
||||
$userAnswer->free_text_answer,
|
||||
$user ? QASystemSourceType::getText(QASystemSourceType::IZYIM) : QASystemSourceType::getText($source->system),
|
||||
$user ? $user_marking : $source->marking,
|
||||
$user ? $user->email : $source->email,
|
||||
Carbon::parse($userAnswer->created_at)->format('d-m-Y'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,7 @@ class ExportsPaymentTransactions implements FromQuery, WithHeadings, WithHeading
|
||||
'DocNo',
|
||||
'DocDate',
|
||||
'DebtorCode',
|
||||
'DebtorCode',
|
||||
'Ref',
|
||||
'ShipInfo',
|
||||
'AccNo',
|
||||
'DetailDescription',
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Exports\Standards\Rules;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\ValueObjects\Constants\RoleTypes;
|
||||
|
||||
class CanExportFeedback extends AbstractRule
|
||||
{
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
if(Auth()->user()){
|
||||
$roleToCheck = Auth()->user()->type;
|
||||
if (in_array($roleToCheck, RoleTypes::ADMIN_ROLES)) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Exports\Standards\Rules;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\ValueObjects\Constants\RoleTypes;
|
||||
|
||||
class CanExportPackingList extends AbstractRule
|
||||
{
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
if(Auth()->user()){
|
||||
$roleToCheck = Auth()->user()->type;
|
||||
if (in_array($roleToCheck, RoleTypes::ADMIN_ROLES)) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\HelpMenu\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\HelpMenu\Standards\Rules\CanFetchHelpMenuQuestion;
|
||||
use App\Classes\Modules\HelpMenu\Processors\FetchFirstQuestionQAProcessor;
|
||||
use App\Http\Resources\HelpMenuQuestionResource;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class FetchQuestionQALogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Retrieved Help Menu First Question',
|
||||
'message' => 'You have successfully retrieved a Help Menu First Question'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanFetchHelpMenuQuestion */
|
||||
private $canFetchHelpMenuQuestion;
|
||||
|
||||
/** @var FetchFirstQuestionQAProcessor */
|
||||
private $fetchFirstQuestionQAProcessor;
|
||||
|
||||
/**
|
||||
* FetchQuestionQALogic constructor.
|
||||
* @param CanFetchHelpMenuQuestion $canFetchHelpMenuQuestion
|
||||
* @param FetchFirstQuestionQAProcessor $fetchFirstQuestionQAProcessor
|
||||
*/
|
||||
public function __construct(CanFetchHelpMenuQuestion $canFetchHelpMenuQuestion, FetchFirstQuestionQAProcessor $fetchFirstQuestionQAProcessor)
|
||||
{
|
||||
$this->canFetchHelpMenuQuestion = $canFetchHelpMenuQuestion;
|
||||
$this->fetchFirstQuestionQAProcessor = $fetchFirstQuestionQAProcessor;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$this->canFetchHelpMenuQuestion->passes();
|
||||
|
||||
$userId = Auth::user()->id;
|
||||
|
||||
$query = $this->fetchFirstQuestionQAProcessor->execute($request);
|
||||
|
||||
return $this->resourceResponse(new HelpMenuQuestionResource($query, $userId));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\HelpMenu\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\HelpMenu\DataTransferObjects\UrlObject;
|
||||
use App\Classes\Modules\HelpMenu\Standards\Rules\CanGenerateFeedbackUrl;
|
||||
use App\Classes\Modules\HelpMenu\Services\CreatesUrl;
|
||||
use App\Classes\Modules\HelpMenu\DataTransferObjects\GenerateFeedbackUrlObject;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class GenerateFeedbackUrlLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Generate Feedback Url',
|
||||
'message' => 'You have successfully generated a feedback url'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanGenerateFeedbackUrl */
|
||||
private $canGenerateFeedbackUrl;
|
||||
|
||||
/** @var CreatesUrl */
|
||||
private $createsUrl;
|
||||
|
||||
/**
|
||||
* GenerateFeedbackUrlLogic constructor.
|
||||
* @param CanGenerateFeedbackUrl $canGenerateFeedbackUrl
|
||||
* @param CreatesUrl $createsUrl
|
||||
*/
|
||||
public function __construct(CanGenerateFeedbackUrl $canGenerateFeedbackUrl, CreatesUrl $createsUrl)
|
||||
{
|
||||
$this->canGenerateFeedbackUrl = $canGenerateFeedbackUrl;
|
||||
$this->createsUrl = $createsUrl;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$apiKey = "";
|
||||
if($request->get('apiKeyExist'))
|
||||
{
|
||||
$apiKey = $request->get('apiKeyExist');
|
||||
}
|
||||
$object = new GenerateFeedbackUrlObject($apiKey, $request->input('system'), $request->input('customer_marking'), $request->input('email'), $request->input('question_set'));
|
||||
$this->canGenerateFeedbackUrl->passes($object);
|
||||
|
||||
$shortUrl = Str::random(20);
|
||||
$originalText = $object->getSystem() . '|' . $object->getCustomerMarking(). '|' . $object->getEmail(). '|' . $object->getQuestionSet() . '|' . $shortUrl;
|
||||
$originalUrl = Crypt::encryptString($originalText);
|
||||
|
||||
|
||||
$url = $this->createsUrl->execute(new UrlObject('feedback', $shortUrl, $originalUrl));
|
||||
$resource = ['token' => $url->short_url];
|
||||
|
||||
return $this->response(['data' => $resource]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\HelpMenu\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\HelpMenu\Services\ListsHelpMenuUserAnswerSelected;
|
||||
use App\Classes\Modules\HelpMenu\Standards\Rules\CanListHelpMenuQuestions;
|
||||
use App\Http\Resources\HelpMenuQuestionsAnswersResource;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ListQuestionsAnswersQALogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Retrieved Questions Answers',
|
||||
'message' => 'You have successfully retrieved a list of questions and answers'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanListHelpMenuQuestions */
|
||||
private $canListHelpMenuQuestions;
|
||||
|
||||
/** @var ListsHelpMenuUserAnswerSelected */
|
||||
private $listsHelpMenuUserAnswerSelected;
|
||||
|
||||
/**
|
||||
* ListQuestionsAnswersQALogic constructor.
|
||||
* @param CanListHelpMenuQuestions $canListHelpMenuQuestions
|
||||
* @param ListsHelpMenuUserAnswerSelected $listsHelpMenuUserAnswerSelected
|
||||
*/
|
||||
public function __construct(CanListHelpMenuQuestions $canListHelpMenuQuestions, ListsHelpMenuUserAnswerSelected $listsHelpMenuUserAnswerSelected)
|
||||
{
|
||||
$this->canListHelpMenuQuestions = $canListHelpMenuQuestions;
|
||||
$this->listsHelpMenuUserAnswerSelected = $listsHelpMenuUserAnswerSelected;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @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
|
||||
{
|
||||
$this->canListHelpMenuQuestions->passes();
|
||||
|
||||
$query = $this->listsHelpMenuUserAnswerSelected->execute($this->listsHelpMenuUserAnswerSelected->deserializeFilters($request->input('filters')));
|
||||
|
||||
return $this->collectionResponse(HelpMenuQuestionsAnswersResource::collection($query));
|
||||
}
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user