diff --git a/app/Classes/Exceptions/JobResourceNotFoundException.php b/app/Classes/Exceptions/JobResourceNotFoundException.php new file mode 100644 index 00000000..a8ef358e --- /dev/null +++ b/app/Classes/Exceptions/JobResourceNotFoundException.php @@ -0,0 +1,11 @@ +getMessage(), + $exception->getTrace()[0]['file'], + $exception->getTrace()[0]['line'] + )); + } + else{ + log::error($exception); + } + return (new ApiResponseObject($this->getNotificationTitle().' failed', $exception->getMessage(), $exception->getCode() ? $exception->getCode() : HttpStatus::SERVER_ERROR))->handler(); diff --git a/app/Classes/General/Eloquent/AbstractFetchRecord.php b/app/Classes/General/Eloquent/AbstractFetchRecord.php index 36224038..503fb369 100644 --- a/app/Classes/General/Eloquent/AbstractFetchRecord.php +++ b/app/Classes/General/Eloquent/AbstractFetchRecord.php @@ -4,9 +4,11 @@ namespace App\Classes\General\Eloquent; use App\Classes\Exceptions\ResourceNotFoundException; +use App\Classes\Exceptions\JobResourceNotFoundException; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; use Psy\Exception\ErrorException; +use Illuminate\Support\Facades\Log; abstract class AbstractFetchRecord extends AbstractGetRecord { @@ -29,7 +31,13 @@ abstract class AbstractFetchRecord extends AbstractGetRecord */ public function getResults(Builder $query, array $param = []): Model { if(!$query->exists()){ - throw new ResourceNotFoundException('Unable to find any record based on the criteria provided'); + $table = $query->getModel()->getTable(); + if($table ==='job_results'){ + throw new JobResourceNotFoundException('Unable to find any job based on the criteria provided'); + } + else{ + throw new ResourceNotFoundException('Unable to find any record based on the criteria provided'); + } } return $query->first(); diff --git a/app/Classes/Jobs/ListBookings.php b/app/Classes/Jobs/ListBookings.php index 2c6c048c..6be0c9c7 100644 --- a/app/Classes/Jobs/ListBookings.php +++ b/app/Classes/Jobs/ListBookings.php @@ -32,6 +32,15 @@ class ListBookings implements ShouldQueue public function handle() { + $rawPayload = $this->job->payload(); + if(isset($rawPayload['data']['commandName'])){ + $this->listGenericJobObject->setJobCommandName($rawPayload['data']['commandName']); + } + + if(isset($rawPayload['data']['command'])){ + $this->listGenericJobObject->setJobCommand($rawPayload['data']['command']); + } + $result = (App()->make(ListBookingJobProcessor::class))->execute($this->listGenericJobObject); } diff --git a/app/Classes/Jobs/ListDocuments.php b/app/Classes/Jobs/ListDocuments.php index 42197a6b..e4707f49 100644 --- a/app/Classes/Jobs/ListDocuments.php +++ b/app/Classes/Jobs/ListDocuments.php @@ -32,9 +32,16 @@ class ListDocuments implements ShouldQueue public function handle() { - $result = (App()->make(ListDocumentJobProcessor::class))->execute($this->listGenericJobObject); + $rawPayload = $this->job->payload(); + if(isset($rawPayload['data']['commandName'])){ + $this->listGenericJobObject->setJobCommandName($rawPayload['data']['commandName']); + } - // Log::error(json_encode($result)); + if(isset($rawPayload['data']['command'])){ + $this->listGenericJobObject->setJobCommand($rawPayload['data']['command']); + } + + $result = (App()->make(ListDocumentJobProcessor::class))->execute($this->listGenericJobObject); //cief todo: Insert into DB: job id, query result, timestamp // Store the result in the job_results table diff --git a/app/Classes/Jobs/ListTransactions.php b/app/Classes/Jobs/ListTransactions.php index 4d94ea42..67c4a6b9 100644 --- a/app/Classes/Jobs/ListTransactions.php +++ b/app/Classes/Jobs/ListTransactions.php @@ -32,6 +32,15 @@ class ListTransactions implements ShouldQueue public function handle() { + $rawPayload = $this->job->payload(); + if(isset($rawPayload['data']['commandName'])){ + $this->listGenericJobObject->setJobCommandName($rawPayload['data']['commandName']); + } + + if(isset($rawPayload['data']['command'])){ + $this->listGenericJobObject->setJobCommand($rawPayload['data']['command']); + } + $result = (App()->make(ListTransactionJobProcessor::class))->execute($this->listGenericJobObject); } diff --git a/app/Classes/Modules/Bookings/ControllersLogic/ListBookingJobLogic.php b/app/Classes/Modules/Bookings/ControllersLogic/ListBookingJobLogic.php index e97028c0..5a7d0994 100644 --- a/app/Classes/Modules/Bookings/ControllersLogic/ListBookingJobLogic.php +++ b/app/Classes/Modules/Bookings/ControllersLogic/ListBookingJobLogic.php @@ -39,7 +39,7 @@ class ListBookingJobLogic extends AbstractControllerLogic ]; $listGenericJobObject = new ListGenericJobObject( - "Proof of Concept", + $request->fullUrl(), $request->all(), $jobId, $userInfo diff --git a/app/Classes/Modules/Bookings/Processors/ListBookingJobProcessor.php b/app/Classes/Modules/Bookings/Processors/ListBookingJobProcessor.php index da2c3969..b622ce79 100644 --- a/app/Classes/Modules/Bookings/Processors/ListBookingJobProcessor.php +++ b/app/Classes/Modules/Bookings/Processors/ListBookingJobProcessor.php @@ -39,16 +39,15 @@ class ListBookingJobProcessor public function execute(ListGenericJobObject $listGenericJobObject) { $query = $this->listsBookings->execute($this->listsBookings->deserializeFilters($listGenericJobObject->getPayload()['filters']), ['page' => $listGenericJobObject->getPayload()['page']]); - Log::error('ListBookingJobProcessor: '. json_encode($listGenericJobObject->getuserInfo())); - Log::error('ListBookingJobProcessor: '. json_encode(gettype($query))); + //cief todo: remove comments // $result = $this->collectionResponse(BookingResource::collection($query)->userInfo($listGenericJobObject->getuserInfo())); $result = $this->collectionResponse(BookingResource::customResourceCollection($query, $listGenericJobObject->getuserInfo())); // $result = new JobBookingCollectionResponse($query, $listGenericJobObject->getuserInfo()); // $result = $this->collectionResponse(new BookingResourceCollection(BookingResource::collection($query), $listGenericJobObject->getuserInfo())); - $create = $this->createsJobResult->execute($listGenericJobObject->getJobId(), json_encode($result)); + $create = $this->createsJobResult->execute($listGenericJobObject, json_encode($result)); return $create; } diff --git a/app/Classes/Modules/Documents/ControllersLogic/ListDocumentJobLogic.php b/app/Classes/Modules/Documents/ControllersLogic/ListDocumentJobLogic.php index 100cdd5b..4328ded8 100644 --- a/app/Classes/Modules/Documents/ControllersLogic/ListDocumentJobLogic.php +++ b/app/Classes/Modules/Documents/ControllersLogic/ListDocumentJobLogic.php @@ -44,7 +44,7 @@ class ListDocumentJobLogic extends AbstractControllerLogic $listGenericJobObject = new ListGenericJobObject( - "Proof of Concept", + $request->fullUrl(), $request->all(), $jobId, $userInfo @@ -52,6 +52,7 @@ class ListDocumentJobLogic extends AbstractControllerLogic ListDocuments::dispatch($listGenericJobObject); + //cief todo: remove comments // // Create your job instance with delay, so we can back here within delay and take control in our hands. // $job = new ListDocuments($listGenericJobObject); // $job->delay(now()->addSeconds(5)); diff --git a/app/Classes/Modules/Documents/Processors/ListDocumentJobProcessor.php b/app/Classes/Modules/Documents/Processors/ListDocumentJobProcessor.php index 24239c0b..4b0309ed 100644 --- a/app/Classes/Modules/Documents/Processors/ListDocumentJobProcessor.php +++ b/app/Classes/Modules/Documents/Processors/ListDocumentJobProcessor.php @@ -40,8 +40,8 @@ class ListDocumentJobProcessor public function execute(ListGenericJobObject $listGenericJobObject) { $query = $this->listsDocuments->execute($this->listsDocuments->deserializeFilters($listGenericJobObject->getPayload()['filters']), ['page' => $listGenericJobObject->getPayload()['page']]); - Log::error('ListDocumentJobProcessor: '. json_encode($listGenericJobObject->getuserInfo())); + //cief todo: remove comments //attempt 1 // $result = $this->collectionResponse(DocumentResource::collection($query, $listGenericJobObject->getuserInfo())); @@ -50,7 +50,7 @@ class ListDocumentJobProcessor $result = $this->collectionResponse(DocumentResource::customResourceCollection($query, $listGenericJobObject->getuserInfo())); // $result = $this->collectionResponse(new DocumentResourceCollection(DocumentResource::collection($query), $listGenericJobObject->getuserInfo())); - $create = $this->createsJobResult->execute($listGenericJobObject->getJobId(), json_encode($result)); + $create = $this->createsJobResult->execute($listGenericJobObject, json_encode($result)); return $create; } diff --git a/app/Classes/Modules/Generic/DataTransferObjects/ListGenericJobObject.php b/app/Classes/Modules/Generic/DataTransferObjects/ListGenericJobObject.php index 5b0bf4c2..791522c5 100644 --- a/app/Classes/Modules/Generic/DataTransferObjects/ListGenericJobObject.php +++ b/app/Classes/Modules/Generic/DataTransferObjects/ListGenericJobObject.php @@ -19,6 +19,12 @@ class ListGenericJobObject implements DataTransferObject /** @var object */ private $userInfo; + /** @var string */ + private $jobCommandName; + + /** @var string */ + private $jobCommand; + public function __construct(string $name, array $payload, string $jobId, object $userInfo = null) { $this->name = $name; @@ -59,9 +65,35 @@ class ListGenericJobObject implements DataTransferObject return $this->userInfo; } + /** + * @return string + */ + public function getJobCommandName(): string + { + return $this->jobCommandName; + } + + /** + * @return string + */ + public function getJobCommand(): string + { + return $this->jobCommand; + } + // public function setJobId(int $jobId) // { // $this->jobId = $jobId; // } + public function setJobCommandName(string $jobCommandName) + { + $this->jobCommandName = $jobCommandName; + } + + public function setJobCommand(string $jobCommand) + { + $this->jobCommand = $jobCommand; + } + } diff --git a/app/Classes/Modules/Jobs/Services/CreatesJobResult.php b/app/Classes/Modules/Jobs/Services/CreatesJobResult.php index a3fdb93f..953e7882 100644 --- a/app/Classes/Modules/Jobs/Services/CreatesJobResult.php +++ b/app/Classes/Modules/Jobs/Services/CreatesJobResult.php @@ -4,6 +4,7 @@ namespace App\Classes\Modules\Jobs\Services; use App\Classes\General\Eloquent\AbstractUpdateRecord; use App\Models\JobResult; +use App\Classes\Modules\Generic\DataTransferObjects\ListGenericJobObject; class CreatesJobResult extends AbstractUpdateRecord { @@ -13,11 +14,14 @@ class CreatesJobResult extends AbstractUpdateRecord * @return \Illuminate\Database\Eloquent\Model * @throws \App\Classes\Exceptions\MalformedRequestException */ - public function execute(string $job_id, string $result) + public function execute(ListGenericJobObject $listGenericJobObject, string $result) { $model = new JobResult(); - $model->job_id = $job_id; + $model->job_id = $listGenericJobObject->getJobId(); $model->result = $result; + $model->url = $listGenericJobObject->getName(); + $model->job_command_name = $listGenericJobObject->getJobCommandName(); + $model->job_command = $listGenericJobObject->getJobCommand(); return $this->handler($model); } diff --git a/app/Classes/Modules/PerfexCRM/Processors/CreatePerfexCRMInvoiceProcessor.php b/app/Classes/Modules/PerfexCRM/Processors/CreatePerfexCRMInvoiceProcessor.php index 4dbaa2d5..f40021c4 100644 --- a/app/Classes/Modules/PerfexCRM/Processors/CreatePerfexCRMInvoiceProcessor.php +++ b/app/Classes/Modules/PerfexCRM/Processors/CreatePerfexCRMInvoiceProcessor.php @@ -229,26 +229,6 @@ class CreatePerfexCRMInvoiceProcessor ); $result = $this->createsPerfexCRMInvoice->execute($invoicePerfexCRMObject); - - //cief todo: When invoices need to be regenerated, need to ensure payment do not get double created - - // if(!is_null($result)) - // { - // if($result->payload['id']){ - // $invoicePaymentPerfexCRMObject = new InvoicePaymentPerfexCRMObject( - // $result->payload['id'], - // $total, - // $date, - // 1, - // "", - // "" - // ); - // $this->createsPerfexCRMInvoicePayment->execute($invoicePaymentPerfexCRMObject); - // } - // } - //else: logs will record the following: - //"status":false,"error":{"number":"The Invoice number is already in use"},"message":"

The Invoice number is already in use<\/p>"} - return $result; } } diff --git a/app/Classes/Modules/PerfexCRM/Processors/UpdatePerfexCRMProcessor.php b/app/Classes/Modules/PerfexCRM/Processors/UpdatePerfexCRMProcessor.php index 752c9644..5f4a9444 100644 --- a/app/Classes/Modules/PerfexCRM/Processors/UpdatePerfexCRMProcessor.php +++ b/app/Classes/Modules/PerfexCRM/Processors/UpdatePerfexCRMProcessor.php @@ -109,7 +109,7 @@ class UpdatePerfexCRMProcessor */ public function execute(UpdatePerfexCRMObject $updatePerfexCRMObject) { $projectId = ""; - + // Customer has to exist first before Project can appear under it // Check with Perfex CRM, if this user (email) was previously a lead, should automatically now become a customer $crmCompany = $updatePerfexCRMObject->getCompanyName(); @@ -214,11 +214,6 @@ class UpdatePerfexCRMProcessor else{ $result = $this->createsPerfexCRMTask->execute($tasks[$count]['name'], $tasks[$count]['description'], '', $milestoneId, $projectId, $tasks[$count]['reference'], $tasks[$count]['on_task_completion'], $tasks[$count]['department'], $taskStatus, $tasks[$count]['priority'], $tasks[$count]['duedate']); } - - //cief todo: to evaluate if this is still needed - // if(is_null($result)){ - // break; //Breaking the rest of the tasks in array assuming that they are all created as a batch previously - // } } } diff --git a/app/Classes/Modules/Transactions/ControllersLogic/ListTransactionsJobLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/ListTransactionsJobLogic.php index b844b4a9..5ea497a0 100644 --- a/app/Classes/Modules/Transactions/ControllersLogic/ListTransactionsJobLogic.php +++ b/app/Classes/Modules/Transactions/ControllersLogic/ListTransactionsJobLogic.php @@ -31,7 +31,7 @@ class ListTransactionsJobLogic extends AbstractControllerLogic $jobId = uniqid(); $listGenericJobObject = new ListGenericJobObject( - "Proof of Concept", + $request->fullUrl(), $request->all(), $jobId ); diff --git a/app/Classes/Modules/Transactions/Processors/ListTransactionJobProcessor.php b/app/Classes/Modules/Transactions/Processors/ListTransactionJobProcessor.php index 17c43d60..4f754cf5 100644 --- a/app/Classes/Modules/Transactions/Processors/ListTransactionJobProcessor.php +++ b/app/Classes/Modules/Transactions/Processors/ListTransactionJobProcessor.php @@ -42,7 +42,7 @@ class ListTransactionJobProcessor $result = $this->collectionResponse(TransactionResource::collection($query)); - $create = $this->createsJobResult->execute($listGenericJobObject->getJobId(), json_encode($result)); + $create = $this->createsJobResult->execute($listGenericJobObject, json_encode($result)); return $create; } diff --git a/database/migrations/2023_08_29_063531_add_new_column_to_job_results_table.php b/database/migrations/2023_08_29_063531_add_new_column_to_job_results_table.php new file mode 100644 index 00000000..3d962eca --- /dev/null +++ b/database/migrations/2023_08_29_063531_add_new_column_to_job_results_table.php @@ -0,0 +1,36 @@ +string('url')->after('result')->nullable(); + $table->string('job_command_name')->after('url')->nullable(); + $table->longText('job_command')->after('job_command_name')->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('job_results', function (Blueprint $table) { + $table->dropColumn('url'); + $table->dropColumn('job_command_name'); + $table->dropColumn('job_command'); + }); + } +} diff --git a/resources/assets/vue/components/bookings/sections/SupplierPendingOrdersSectionComponent.vue b/resources/assets/vue/components/bookings/sections/SupplierPendingOrdersSectionComponent.vue index 5cc561f7..6c64fdee 100644 --- a/resources/assets/vue/components/bookings/sections/SupplierPendingOrdersSectionComponent.vue +++ b/resources/assets/vue/components/bookings/sections/SupplierPendingOrdersSectionComponent.vue @@ -165,7 +165,7 @@ } }, created(){ - this.submit(route('api.company.list') + '?filters=' + JSON.stringify({'business_type': 3, 'status_in': [1, 2, 0]}), 'get', 'pendingOrdersSection', false, false) + this.submit(route('api.company.list') + '?filters=' + JSON.stringify({'business_type': 3, 'status_in': [1, 2, 0]}), 'get', 'pendingOrdersSection', false, false); //cief todo: Uncaught (in promise) null }, methods: { successHandler(response){ diff --git a/resources/assets/vue/components/general/elements/ListPollingComponent.vue b/resources/assets/vue/components/general/elements/ListPollingComponent.vue index 8f204720..f6a65342 100644 --- a/resources/assets/vue/components/general/elements/ListPollingComponent.vue +++ b/resources/assets/vue/components/general/elements/ListPollingComponent.vue @@ -80,7 +80,7 @@ }, created(){ this.setDecoratorDefault(); - this.$store.dispatch('updateListQueue', {'name': this.section, 'page': 1, 'filters': this.filters}); + this.$store.dispatch('updateListQueue', {'name': this.section, 'page': 1, 'filters': this.filters}); //cief todo: Uncaught (in promise) null }, computed: { pendingList () { @@ -101,11 +101,13 @@ this.isLoading = true; this.submitJob(url); }, - updateFilters(filters){ - this.filters = filters; - this.setDecoratorDefault(); - this.submit(this.endpoint + '?page=1&filters=' + JSON.stringify(this.filters), 'get', this.section, false, false) - }, + //cief todo: remove? + // updateFilters(filters){ + // this.filters = filters; + // this.setDecoratorDefault(); + // console.log('updateFilters'); + // this.submit(this.endpoint + '?page=1&filters=' + JSON.stringify(this.filters), 'get', this.section, false, false); //cief todo: Uncaught (in promise) null + // }, successHandler(response){ let result = JSON.parse(response.payload.data.result); result.meta = { @@ -173,7 +175,7 @@ fetchJobResult(jobId) { try { let anotherEndpoint = route('api.job.fetch', jobId); - this.submit(anotherEndpoint, 'get', this.section, false, false); + this.submit(anotherEndpoint, 'get', this.section, false, false); //cief todo: Uncaught (in promise) null } catch (error) { console.error('Error fetchJobResult', error); }