diff --git a/app/Classes/Jobs/Commands/V2/DeleteBulkInvoiceFilesV2CommandJob.php b/app/Classes/Jobs/Commands/V2/DeleteBulkInvoiceFilesV2CommandJob.php index 3b6815d5..89733472 100644 --- a/app/Classes/Jobs/Commands/V2/DeleteBulkInvoiceFilesV2CommandJob.php +++ b/app/Classes/Jobs/Commands/V2/DeleteBulkInvoiceFilesV2CommandJob.php @@ -23,15 +23,15 @@ class DeleteBulkInvoiceFilesV2CommandJob implements ShouldQueue $start = new Carbon(); $directories = [ - storage_path('app/bulk_invoice'), - storage_path('app/bulk_whiteform'), + storage_path('app/bulk_invoice'), //cief todo: should map to the equivalent in AWS S3 bucket + storage_path('app/bulk_whiteform'), //cief todo: should map to the equivalent in AWS S3 bucket ]; foreach ($directories as $directory) { $start = new Carbon(); Log::info(Carbon::now() . ' Start cleaning - ' . $directory); - if (File::isDirectory($directory)) { + if (File::isDirectory($directory)) { //cief todo: should map to the equivalent in AWS S3 bucket File::cleanDirectory($directory); Log::info('All files have been deleted.'); } else { diff --git a/app/Classes/Jobs/Commands/V2/DeleteOrderV2CommandJob.php b/app/Classes/Jobs/Commands/V2/DeleteOrderV2CommandJob.php index a5489eec..256ed7b8 100644 --- a/app/Classes/Jobs/Commands/V2/DeleteOrderV2CommandJob.php +++ b/app/Classes/Jobs/Commands/V2/DeleteOrderV2CommandJob.php @@ -74,7 +74,7 @@ class DeleteOrderV2CommandJob implements ShouldQueue Log::info(Carbon::now() . ' : ' . $text); - $filePath = storage_path('logs/delete-orders.log'); + $filePath = storage_path('logs/delete-orders.log'); //cief todo: should map to the equivalent in AWS S3 bucket $textToAppend = Carbon::now()->format('[Y-m-d H:i:s]') . ' ' . $text . PHP_EOL; file_put_contents($filePath, $textToAppend, FILE_APPEND); } diff --git a/app/Classes/Modules/Accounts/Processors/GenerateEmailVerificationAttemptProcessor.php b/app/Classes/Modules/Accounts/Processors/GenerateEmailVerificationAttemptProcessor.php index 7c4b35a7..b07b0cc9 100644 --- a/app/Classes/Modules/Accounts/Processors/GenerateEmailVerificationAttemptProcessor.php +++ b/app/Classes/Modules/Accounts/Processors/GenerateEmailVerificationAttemptProcessor.php @@ -50,7 +50,7 @@ class GenerateEmailVerificationAttemptProcessor $attempt = $this->generatesEmailVerificationAttempt->execute($user); - // $this->emailVerificationAttemptExpiration::dispatch($attempt)->delay(now()->addHours(48)); //cief todo: changed to schedule task + // $this->emailVerificationAttemptExpiration::dispatch($attempt)->delay(now()->addHours(48)); //cief todo: changed to schedule task (DONE) $this->sendUserVerificationEmail::dispatch($user, $attempt); diff --git a/app/Classes/Modules/Bookings/Processors/ListBookingsJobProcessor.php b/app/Classes/Modules/Bookings/Processors/ListBookingsJobProcessor.php index 2a09eb12..672c6846 100644 --- a/app/Classes/Modules/Bookings/Processors/ListBookingsJobProcessor.php +++ b/app/Classes/Modules/Bookings/Processors/ListBookingsJobProcessor.php @@ -6,7 +6,7 @@ use App\Classes\Modules\Bookings\Services\ListsBookings; use App\Classes\Modules\Jobs\Processors\UpdateJobResultProcessor; use App\Classes\General\Helper; use App\Classes\Modules\Jobs\DataTransferObjects\ListGenericJobObject; -use App\Http\Resources\ListBookingJobResource; +use App\Http\Resources\V2\ListBookingJobResource; class ListBookingsJobProcessor { @@ -37,7 +37,7 @@ class ListBookingsJobProcessor public function execute(ListGenericJobObject $listGenericJobObject) { $query = $this->listsBookings->execute($this->listsBookings->deserializeFilters($listGenericJobObject->getPayload()['filters']), ['page' => $listGenericJobObject->getPayload()['page']]); - foreach ($query->items() as &$item) { + foreach ($query->items() as $item) { $item['userInfo'] = $listGenericJobObject->getUserInfo(); } $resultCurrent = Helper::collectionResponse(ListBookingJobResource::collection($query)); diff --git a/app/Classes/Modules/Documents/Processors/ListDocumentsJobProcessor.php b/app/Classes/Modules/Documents/Processors/ListDocumentsJobProcessor.php index 70777f0c..f7090d31 100644 --- a/app/Classes/Modules/Documents/Processors/ListDocumentsJobProcessor.php +++ b/app/Classes/Modules/Documents/Processors/ListDocumentsJobProcessor.php @@ -6,7 +6,7 @@ use App\Classes\Modules\Documents\Services\ListsDocuments; use App\Classes\Modules\Jobs\Processors\UpdateJobResultProcessor; use App\Classes\General\Helper; use App\Classes\Modules\Jobs\DataTransferObjects\ListGenericJobObject; -use App\Http\Resources\ListDocumentJobResource; +use App\Http\Resources\V2\ListDocumentJobResource; class ListDocumentsJobProcessor { @@ -37,7 +37,7 @@ class ListDocumentsJobProcessor public function execute(ListGenericJobObject $listGenericJobObject) { $query = $this->listsDocuments->execute($this->listsDocuments->deserializeFilters($listGenericJobObject->getPayload()['filters']), ['page' => $listGenericJobObject->getPayload()['page']]); - foreach ($query->items() as &$item) { + foreach ($query->items() as $item) { $item['userInfo'] = $listGenericJobObject->getUserInfo(); } $resultCurrent = Helper::collectionResponse(ListDocumentJobResource::collection($query)); diff --git a/app/Classes/Modules/Transactions/Processors/ListTransactionsJobProcessor.php b/app/Classes/Modules/Transactions/Processors/ListTransactionsJobProcessor.php index 475d4715..9d325abc 100644 --- a/app/Classes/Modules/Transactions/Processors/ListTransactionsJobProcessor.php +++ b/app/Classes/Modules/Transactions/Processors/ListTransactionsJobProcessor.php @@ -6,7 +6,7 @@ use App\Classes\Modules\Transactions\Services\ListsTransactions; use App\Classes\Modules\Jobs\Processors\UpdateJobResultProcessor; use App\Classes\General\Helper; use App\Classes\Modules\Jobs\DataTransferObjects\ListGenericJobObject; -use App\Http\Resources\ListTransactionJobResource; +use App\Http\Resources\V2\ListTransactionJobResource; class ListTransactionsJobProcessor { @@ -37,7 +37,9 @@ class ListTransactionsJobProcessor public function execute(ListGenericJobObject $listGenericJobObject) { $query = $this->listsTransactions->execute($this->listsTransactions->deserializeFilters($listGenericJobObject->getPayload()['filters']), ['page' => $listGenericJobObject->getPayload()['page']]); - + foreach ($query->items() as $item) { + $item['userInfo'] = $listGenericJobObject->getUserInfo(); + } $resultCurrent = Helper::collectionResponse(ListTransactionJobResource::collection($query)); $this->updateJobResultProcessor->execute($listGenericJobObject, $resultCurrent); } diff --git a/app/Http/Resources/ListBookingJobResource.php b/app/Http/Resources/ListBookingJobResource.php deleted file mode 100644 index 06f8c38d..00000000 --- a/app/Http/Resources/ListBookingJobResource.php +++ /dev/null @@ -1,81 +0,0 @@ -userInfo = $userInfo ?? ($resource->userInfo ?? null); - } - - /** - * Transform the resource into an array. - * - * @param \Illuminate\Http\Request $request - * @return array - * @throws \Illuminate\Contracts\Container\BindingResolutionException - */ - public function toArray($request) - { - return [ - 'id' => $this->id, - 'company' => new CompanyResource($this->company, $this->userInfo), - 'bank' => new BankResource($this->bank), - 'service' => new ServiceTypeResource($this->service), - 'marking' => $this->marking, - 'amount' => $this->fix_amount, - 'floating_amount' => floatval((App()->make(CalculatesBookingFloatingAmount::class))->execute($this->resource, $this->fix_currency_id)), - 'paid_amount' => floatval((App()->make(CalculatesBookingPayableAmount::class))->execute($this->resource, $this->fix_currency_id)) - floatval((App()->make(CalculatesBookingRefundAmount::class))->execute($this->resource, $this->fix_currency_id)), - 'outstanding_amount' => floatval((App()->make(CalculatesBookingOutstanding::class))->execute($this->resource)) - floatval((App()->make(CalculatesBookingRefundAmount::class))->execute($this->resource, $this->fix_currency_id)), - 'fixed_currency' => new CurrencyResource($this->fixedCurrency), - 'convertible_currency' => new CurrencyResource($this->convertibleCurrency), - 'conversion_currency' => new CurrencyResource($this->conversionCurrency), - 'documents' => [ - 'purchase_order' => new DocumentResource($this->documents()->where('document_type', DocumentType::PURCHASE_ORDER)->first()), - 'delivery_order' => new DocumentResource($this->documents()->where('document_type', DocumentType::DELIVER_ORDER)->first()), - 'invoice' => new DocumentResource($this->documents()->where('document_type', DocumentType::INVOICE)->first()), - 'supplier_delivery_order' => new DocumentResource($this->documents()->where('document_type', DocumentType::SUPPLIER_DELIVER_ORDER)->first()), - 'proforma_invoice' => new DocumentResource($this->documents()->where('document_type', DocumentType::PROFORMA_INVOICE)->whereNotIn('status', [ApprovalStatus::REJECTED, ApprovalStatus::EXPIRED])->orderByDesc('id')->first()), - 'ecommerce_purchase_order' => new DocumentResource($this->documents()->where('document_type', DocumentType::ECOMMERCE_PURCHASE_ORDER)->first()), - ], - 'status' => $this->status, - 'created_at' => Carbon::parse($this->created_at)->format('d-m-Y'), - 'created_at_with_time' => Carbon::parse($this->created_at)->format('d-m-Y h:i:s A'), - $this->mergeWhen($this->relationLoaded('transactions'), [ - 'purchase_order' => new TransactionResource($this->transactions()->where('type', TransactionType::PURCHASE_ORDER)->first()), - 'payment_attempts' => TransactionResource::collection( - $this->transactions() - ->payments()->where('status', ApprovalStatus::PENDING_SUBMISSION) - ->whereDate('expires_on', '>=', Carbon::now()) - ->get() - ), - 'expired_payment_attempts' => TransactionResource::collection($this->transactions()->payments()->where('status', ApprovalStatus::PENDING_SUBMISSION)->whereDate('expires_on', '>=', Carbon::now())->where('expires_on', '>', Carbon::now()->toTimeString())->get()), - 'payment_history' => TransactionResource::collection($this->transactions()->where(function($query){ - $query->where(function($query){ - $query->payments()->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::COMPLETED, ApprovalStatus::REJECTED]); - })->orWhere(function($query){ - $query->where(function($query){ - $query->where('type', TransactionType::REFUND)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::REJECTED, ApprovalStatus::COMPLETED]); - })->orWhere(function($query){ - $query->where('type', TransactionType::CREDIT_NOTE)->whereIn('status', [ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]); - }); - }); - })->latest()->get()) - ]) - ]; - } -} diff --git a/app/Http/Resources/V2/BookingV2Resource.php b/app/Http/Resources/V2/BookingV2Resource.php index ee17181e..a41d7e35 100644 --- a/app/Http/Resources/V2/BookingV2Resource.php +++ b/app/Http/Resources/V2/BookingV2Resource.php @@ -12,17 +12,10 @@ use App\Classes\ValueObjects\Constants\DocumentType; use Carbon\Carbon; use Illuminate\Http\Resources\Json\JsonResource; use App\Http\Resources as V1; +use App\Http\Resources\V2 as V2; class BookingV2Resource extends JsonResource { - private $userInfo; - - public function __construct($resource, $userInfo = null) - { - parent::__construct($resource); - $this->userInfo = $userInfo ?? ($resource->userInfo ?? null); - } - /** * Transform the resource into an array. * @@ -32,9 +25,12 @@ class BookingV2Resource extends JsonResource */ public function toArray($request) { + if($this->userInfo){ + $this->company->userInfo = $this->userInfo; + } return [ 'id' => $this->id, - 'company' => new CompanyV2Resource($this->company, $this->userInfo), + 'company' => new V2\CompanyV2Resource($this->company), 'bank' => new V1\BankResource($this->bank), 'service' => new V1\ServiceTypeResource($this->service), 'marking' => $this->marking, @@ -46,26 +42,26 @@ class BookingV2Resource extends JsonResource 'convertible_currency' => new V1\CurrencyResource($this->convertibleCurrency), 'conversion_currency' => new V1\CurrencyResource($this->conversionCurrency), 'documents' => [ - 'purchase_order' => new V1\DocumentResource($this->documents()->where('document_type', DocumentType::PURCHASE_ORDER)->first()), - 'delivery_order' => new V1\DocumentResource($this->documents()->where('document_type', DocumentType::DELIVER_ORDER)->first()), - 'invoice' => new V1\DocumentResource($this->documents()->where('document_type', DocumentType::INVOICE)->first()), - 'supplier_delivery_order' => new V1\DocumentResource($this->documents()->where('document_type', DocumentType::SUPPLIER_DELIVER_ORDER)->first()), - 'proforma_invoice' => new V1\DocumentResource($this->documents()->where('document_type', DocumentType::PROFORMA_INVOICE)->whereNotIn('status', [ApprovalStatus::REJECTED, ApprovalStatus::EXPIRED])->orderByDesc('id')->first()), - 'ecommerce_purchase_order' => new V1\DocumentResource($this->documents()->where('document_type', DocumentType::ECOMMERCE_PURCHASE_ORDER)->first()), + 'purchase_order' => new V2\DocumentV2Resource($this->documents()->where('document_type', DocumentType::PURCHASE_ORDER)->first()), + 'delivery_order' => new V2\DocumentV2Resource($this->documents()->where('document_type', DocumentType::DELIVER_ORDER)->first()), + 'invoice' => new V2\DocumentV2Resource($this->documents()->where('document_type', DocumentType::INVOICE)->first()), + 'supplier_delivery_order' => new V2\DocumentV2Resource($this->documents()->where('document_type', DocumentType::SUPPLIER_DELIVER_ORDER)->first()), + 'proforma_invoice' => new V2\DocumentV2Resource($this->documents()->where('document_type', DocumentType::PROFORMA_INVOICE)->whereNotIn('status', [ApprovalStatus::REJECTED, ApprovalStatus::EXPIRED])->orderByDesc('id')->first()), + 'ecommerce_purchase_order' => new V2\DocumentV2Resource($this->documents()->where('document_type', DocumentType::ECOMMERCE_PURCHASE_ORDER)->first()), ], 'status' => $this->status, 'created_at' => Carbon::parse($this->created_at)->format('d-m-Y'), 'created_at_with_time' => Carbon::parse($this->created_at)->format('d-m-Y h:i:s A'), $this->mergeWhen($this->relationLoaded('transactions'), [ - 'purchase_order' => new V1\TransactionResource($this->transactions()->where('type', TransactionType::PURCHASE_ORDER)->first()), - 'payment_attempts' => V1\TransactionResource::collection( + 'purchase_order' => new V2\TransactionV2Resource($this->transactions()->where('type', TransactionType::PURCHASE_ORDER)->first()), + 'payment_attempts' => V2\TransactionV2Resource::collection( $this->transactions() ->payments()->where('status', ApprovalStatus::PENDING_SUBMISSION) ->whereDate('expires_on', '>=', Carbon::now()) ->get() ), - 'expired_payment_attempts' => V1\TransactionResource::collection($this->transactions()->payments()->where('status', ApprovalStatus::PENDING_SUBMISSION)->whereDate('expires_on', '>=', Carbon::now())->where('expires_on', '>', Carbon::now()->toTimeString())->get()), - 'payment_history' => V1\TransactionResource::collection($this->transactions()->where(function($query){ + 'expired_payment_attempts' => V2\TransactionV2Resource::collection($this->transactions()->payments()->where('status', ApprovalStatus::PENDING_SUBMISSION)->whereDate('expires_on', '>=', Carbon::now())->where('expires_on', '>', Carbon::now()->toTimeString())->get()), + 'payment_history' => V2\TransactionV2Resource::collection($this->transactions()->where(function($query){ $query->where(function($query){ $query->payments()->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::COMPLETED, ApprovalStatus::REJECTED]); })->orWhere(function($query){ diff --git a/app/Http/Resources/V2/CompanyV2Resource.php b/app/Http/Resources/V2/CompanyV2Resource.php index 64fca7c7..11eff32f 100644 --- a/app/Http/Resources/V2/CompanyV2Resource.php +++ b/app/Http/Resources/V2/CompanyV2Resource.php @@ -20,14 +20,6 @@ use App\Http\Resources as V1; class CompanyV2Resource extends JsonResource { - private $userInfo; - - public function __construct($resource, $userInfo = null) - { - parent::__construct($resource); - $this->userInfo = $userInfo; - } - /** * Transform the resource into an array. * @@ -47,12 +39,12 @@ class CompanyV2Resource extends JsonResource $userInfoEmail = $this->userInfo && isset($this->userInfo->email) ? $this->userInfo->email : null; $userInfoType = $this->userInfo && isset($this->userInfo->type) ? $this->userInfo->type : null; - if(!$userInfoEmail && Auth::user()){ - $userInfoEmail = Auth::user()->email; - } - if(!$userInfoType && Auth::user()){ - $userInfoType = Auth::user()->type; - } + // if(!$userInfoEmail && Auth::user()){ + // $userInfoEmail = Auth::user()->email; + // } + // if(!$userInfoType && Auth::user()){ + // $userInfoType = Auth::user()->type; + // } if(!is_null($userInfoEmail) && !is_null($userInfoType)){ $userResource = new V1\UserResource($userInfoType === RoleTypes::USER ? $this->employees()->where('email', '=', $userInfoEmail)->first() : $this->employees()->orderBy('id', 'DESC')->first()); diff --git a/app/Http/Resources/V2/DocumentV2Resource.php b/app/Http/Resources/V2/DocumentV2Resource.php new file mode 100644 index 00000000..17da64c7 --- /dev/null +++ b/app/Http/Resources/V2/DocumentV2Resource.php @@ -0,0 +1,28 @@ + $this->id, + 'reference' => $this->reference, + 'status' => (int) $this->status, + 'document_type' => $this->document_type, + 'files' => FileV2Resource::collection($this->files), + 'created_at' => Carbon::parse($this->created_at)->format('d-m-Y h:i:s A') + ]; + } +} diff --git a/app/Http/Resources/V2/FileV2Resource.php b/app/Http/Resources/V2/FileV2Resource.php new file mode 100644 index 00000000..8e7ac98a --- /dev/null +++ b/app/Http/Resources/V2/FileV2Resource.php @@ -0,0 +1,23 @@ + $this->id, + 'file' => $this->file, + 'type' => (int) $this->file_type, + ]; + } +} diff --git a/app/Http/Resources/V2/ListBookingJobResource.php b/app/Http/Resources/V2/ListBookingJobResource.php new file mode 100644 index 00000000..1d5d47f0 --- /dev/null +++ b/app/Http/Resources/V2/ListBookingJobResource.php @@ -0,0 +1,76 @@ +userInfo){ + $this->company->userInfo = $this->userInfo; + } + return [ + 'id' => $this->id, + 'company' => new CompanyV2Resource($this->company), + 'bank' => new V1\BankResource($this->bank), + 'service' => new V1\ServiceTypeResource($this->service), + 'marking' => $this->marking, + 'amount' => $this->fix_amount, + 'floating_amount' => floatval((App()->make(CalculatesBookingFloatingAmount::class))->execute($this->resource, $this->fix_currency_id)), + 'paid_amount' => floatval((App()->make(CalculatesBookingPayableAmount::class))->execute($this->resource, $this->fix_currency_id)) - floatval((App()->make(CalculatesBookingRefundAmount::class))->execute($this->resource, $this->fix_currency_id)), + 'outstanding_amount' => floatval((App()->make(CalculatesBookingOutstanding::class))->execute($this->resource)) - floatval((App()->make(CalculatesBookingRefundAmount::class))->execute($this->resource, $this->fix_currency_id)), + 'fixed_currency' => new V1\CurrencyResource($this->fixedCurrency), + 'convertible_currency' => new V1\CurrencyResource($this->convertibleCurrency), + 'conversion_currency' => new V1\CurrencyResource($this->conversionCurrency), + 'documents' => [ + 'purchase_order' => new DocumentV2Resource($this->documents()->where('document_type', DocumentType::PURCHASE_ORDER)->first()), + 'delivery_order' => new DocumentV2Resource($this->documents()->where('document_type', DocumentType::DELIVER_ORDER)->first()), + 'invoice' => new DocumentV2Resource($this->documents()->where('document_type', DocumentType::INVOICE)->first()), + 'supplier_delivery_order' => new DocumentV2Resource($this->documents()->where('document_type', DocumentType::SUPPLIER_DELIVER_ORDER)->first()), + 'proforma_invoice' => new DocumentV2Resource($this->documents()->where('document_type', DocumentType::PROFORMA_INVOICE)->whereNotIn('status', [ApprovalStatus::REJECTED, ApprovalStatus::EXPIRED])->orderByDesc('id')->first()), + 'ecommerce_purchase_order' => new DocumentV2Resource($this->documents()->where('document_type', DocumentType::ECOMMERCE_PURCHASE_ORDER)->first()), + ], + 'status' => $this->status, + 'created_at' => Carbon::parse($this->created_at)->format('d-m-Y'), + 'created_at_with_time' => Carbon::parse($this->created_at)->format('d-m-Y h:i:s A'), + // $this->mergeWhen($this->relationLoaded('transactions'), [ + // 'purchase_order' => new V1\TransactionResource($this->transactions()->where('type', TransactionType::PURCHASE_ORDER)->first()), + // 'payment_attempts' => V1\TransactionResource::collection( + // $this->transactions() + // ->payments()->where('status', ApprovalStatus::PENDING_SUBMISSION) + // ->whereDate('expires_on', '>=', Carbon::now()) + // ->get() + // ), + // 'expired_payment_attempts' => V1\TransactionResource::collection($this->transactions()->payments()->where('status', ApprovalStatus::PENDING_SUBMISSION)->whereDate('expires_on', '>=', Carbon::now())->where('expires_on', '>', Carbon::now()->toTimeString())->get()), + // 'payment_history' => V1\TransactionResource::collection($this->transactions()->where(function($query){ + // $query->where(function($query){ + // $query->payments()->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::COMPLETED, ApprovalStatus::REJECTED]); + // })->orWhere(function($query){ + // $query->where(function($query){ + // $query->where('type', TransactionType::REFUND)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::REJECTED, ApprovalStatus::COMPLETED]); + // })->orWhere(function($query){ + // $query->where('type', TransactionType::CREDIT_NOTE)->whereIn('status', [ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]); + // }); + // }); + // })->latest()->get()) + // ]) + ]; + } +} diff --git a/app/Http/Resources/ListDocumentJobResource.php b/app/Http/Resources/V2/ListDocumentJobResource.php similarity index 68% rename from app/Http/Resources/ListDocumentJobResource.php rename to app/Http/Resources/V2/ListDocumentJobResource.php index edf549ef..cc233aac 100644 --- a/app/Http/Resources/ListDocumentJobResource.php +++ b/app/Http/Resources/V2/ListDocumentJobResource.php @@ -1,12 +1,11 @@ userInfo){ + $this->owner->userInfo = $this->userInfo; + } + return [ 'id' => $this->id, 'reference' => $this->reference, 'status' => (int) $this->status, 'document_type' => $this->document_type, - 'owner' => $this->relationLoaded('owner') ? ($this->owner instanceof Booking ? new BookingV2Resource($this->owner, $this->userInfo) : new CompanyV2Resource($this->owner, $this->userInfo)) : null, - 'files' => FileResource::collection($this->files), + 'owner' => $this->relationLoaded('owner') ? ($this->owner instanceof Booking ? new BookingV2Resource($this->owner) : new CompanyV2Resource($this->owner)) : null, + 'files' => FileV2Resource::collection($this->files), 'created_at' => Carbon::parse($this->created_at)->format('d-m-Y h:i:s A') ]; } diff --git a/app/Http/Resources/ListTransactionJobResource.php b/app/Http/Resources/V2/ListTransactionJobResource.php similarity index 50% rename from app/Http/Resources/ListTransactionJobResource.php rename to app/Http/Resources/V2/ListTransactionJobResource.php index 6c4c0ece..df4bbd2d 100644 --- a/app/Http/Resources/ListTransactionJobResource.php +++ b/app/Http/Resources/V2/ListTransactionJobResource.php @@ -1,10 +1,12 @@ type, [TransactionType::BILL, TransactionType::REFUND])? $this->owner->owner : $this->owner; $days = $this->created_at->endOfDay()->addWeekdays($booking->service_id === 3 ? 3 : 1); + $transactionBillQuery = $this->when((int) $this->type === TransactionType::PAYMENT, $this->transactions()->bills()->first()); + $transactionRefundsQuery = $this->when((int) $this->type === TransactionType::PAYMENT, $this->transactions()->refunds()->get()); + + if($this->userInfo){ + $booking->userInfo = $this->userInfo; + if ($transactionBillQuery) { + $transactionBillQuery->userInfo = $this->userInfo; + } + if ($transactionRefundsQuery) { + foreach ($transactionRefundsQuery as $item) { + $item['userInfo'] = $this->userInfo; + } + } + } + $transactionBill = new TransactionV2Resource($transactionBillQuery); + $transactionRefunds = TransactionV2Resource::collection($transactionRefundsQuery); + return [ 'id' => $this->id, - 'booking' => new BookingResource($booking), + 'booking' => new BookingV2Resource($booking), 'type' => (int) $this->type, 'bill_no' => $this->bill_no, 'payment_reference' => $this->payment_reference, 'payment_method' => (float) $this->payment_method, - 'recipient_bank_account' => new BankResource($booking->bank), + 'recipient_bank_account' => new V1\BankResource($booking->bank), 'issuer_name' => $this->issuerCompany->name, 'issuer_id' => $this->issuerCompany->id, 'amount' => (double) $this->amount, 'original_amount' => (double) $this->original_amount, - 'currency' => new CurrencyResource($this->currency), - 'original_currency' => new CurrencyResource($this->original_currency), + 'currency' => new V1\CurrencyResource($this->currency), + 'original_currency' => new V1\CurrencyResource($this->original_currency), 'service_charge' => (double) $this->service_charge, 'tax' => (double) $this->tax, 'currency_rate' => (double) $this->currency_rate, 'status' => (int) $this->status, - 'details' => TransactionDetailResource::collection($this->transactionDetails), - 'documents' => new DocumentResource($this->documents()->first()), - 'transaction_bill' => new TransactionResource($this->when((int) $this->type === TransactionType::PAYMENT, $this->transactions()->bills()->first())), - 'transaction_refunds' => TransactionResource::collection($this->when((int) $this->type === TransactionType::PAYMENT, $this->transactions()->refunds()->get())), + 'details' => V1\TransactionDetailResource::collection($this->transactionDetails), + 'documents' => new DocumentV2Resource($this->documents()->first()), + 'transaction_bill' => $transactionBill, + 'transaction_refunds' => $transactionRefunds, 'expires_on' => Carbon::parse($this->expires_on)->format('d-m-Y h:i:s A'), 'updated_at' => Carbon::parse($this->updated_at)->format('d-m-Y h:i:s A'), 'interval' => [ 'value' => $days->gt(Carbon::now()) ? '+' : '-', 'duration' => $days->diff(Carbon::now())->format('%d'), ], - 'redemption' => new VoucherRedemptionResource($this->voucherRedemption) + 'redemption' => new V1\VoucherRedemptionResource($this->voucherRedemption) ]; } } diff --git a/app/Http/Resources/V2/TransactionV2Resource.php b/app/Http/Resources/V2/TransactionV2Resource.php new file mode 100644 index 00000000..d358e490 --- /dev/null +++ b/app/Http/Resources/V2/TransactionV2Resource.php @@ -0,0 +1,72 @@ +type, [TransactionType::BILL, TransactionType::REFUND])? $this->owner->owner : $this->owner; + $days = $this->created_at->endOfDay()->addWeekdays($booking->service_id === 3 ? 3 : 1); + $transactionBillQuery = $this->when((int) $this->type === TransactionType::PAYMENT, $this->transactions()->bills()->first()); + $transactionRefundsQuery = $this->when((int) $this->type === TransactionType::PAYMENT, $this->transactions()->refunds()->get()); + + if($this->userInfo){ + $booking->userInfo = $this->userInfo; + if ($transactionBillQuery) { + $transactionBillQuery->userInfo = $this->userInfo; + } + if ($transactionRefundsQuery) { + foreach ($transactionRefundsQuery as $item) { + $item['userInfo'] = $this->userInfo; + } + } + } + $transactionBill = new TransactionV2Resource($transactionBillQuery); + $transactionRefunds = TransactionV2Resource::collection($transactionRefundsQuery); + return [ + 'id' => $this->id, + 'booking' => new BookingV2Resource($booking), + 'type' => (int) $this->type, + 'bill_no' => $this->bill_no, + 'payment_reference' => $this->payment_reference, + 'payment_method' => (float) $this->payment_method, + 'recipient_bank_account' => new V1\BankResource($booking->bank), + 'issuer_name' => $this->issuerCompany->name, + 'issuer_id' => $this->issuerCompany->id, + 'amount' => (double) $this->amount, + 'original_amount' => (double) $this->original_amount, + 'currency' => new V1\CurrencyResource($this->currency), + 'original_currency' => new V1\CurrencyResource($this->original_currency), + 'service_charge' => (double) $this->service_charge, + 'tax' => (double) $this->tax, + 'currency_rate' => (double) $this->currency_rate, + 'status' => (int) $this->status, + 'details' => V1\TransactionDetailResource::collection($this->transactionDetails), + 'documents' => new DocumentV2Resource($this->documents()->first()), + 'transaction_bill' => $transactionBill, + 'transaction_refunds' => $transactionRefunds, + 'refunded_amount' => $this->booking ? floatval((App()->make(CalculatesBookingRefundAmount::class))->calculateRefundAmount($this->resource, $this->booking->fix_currency_id)) : null, + 'expires_on' => Carbon::parse($this->expires_on)->format('d-m-Y h:i:s A'), + 'updated_at' => Carbon::parse($this->updated_at)->format('d-m-Y h:i:s A'), + 'created_at' => Carbon::parse($this->created_at)->format('d-m-Y h:i:s A'), + 'interval' => [ + 'value' => $days->gt(Carbon::now()) ? '+' : '-', + 'duration' => $days->diff(Carbon::now())->format('%d'), + ], + 'redemption' => new V1\VoucherRedemptionResource($this->voucherRedemption) + ]; + } +} diff --git a/config/perfexcrm.php b/config/perfexcrm.php index 7644a489..848c833e 100644 --- a/config/perfexcrm.php +++ b/config/perfexcrm.php @@ -1,7 +1,7 @@ env('PERFEXCRM_BASE_URL', 'http://192.168.1.101:8084'), //cief todo: Update crm api domain here + 'base_url' => env('PERFEXCRM_BASE_URL', 'http://192.168.1.101:8084'), //cief todo: Environment variables 'api_key' => env('PERFEXCRM_API_KEY', 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyIjoiZXhjaGFuZ2Utc2hpcHBpbmciLCJuYW1lIjoiRXhjaGFuZ2UgYW5kIFNoaXBwaW5nIFBvcnRhbCIsIkFQSV9USU1FIjoxNjc1MDg2Mzc4fQ.SGAHWl5stcxQwp55TBGeMRVTdlLeWQIbsvJh5glyVvs'), 'is_enabled' => env('PERFEXCRM_IS_ENABLED', 'true'), ];