updatePerfexCRMInvoiceObject = $updatePerfexCRMInvoiceObject; } public function handle() { //get the client id $customer = (App()->make(FetchesPerfexCRMCustomer::class))->execute($this->updatePerfexCRMInvoiceObject->getEmail()); $transaction = $this->updatePerfexCRMInvoiceObject->getTransaction(); //get the invoice id $invoiceId = 0; $invoiceStatus = 0; $invoice = (App()->make(FetchesPerfexCRMInvoice::class))->execute($customer->userid,"INV-", $transaction->owner->bill_no); Log::channel('perfex_crm')->info('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()); if ($result) { $invoiceId = $result->payload['id']; } else { // Log::error(json_encode('UpdatePerfexCRMInvoice CreatePerfexCRMInvoiceProcessor failed')); Log::channel('perfex_crm')->info('UpdatePerfexCRMInvoice CreatePerfexCRMInvoiceProcessor failed'); } } else{ $invoiceId = $invoice->id; $invoiceStatus = $invoice->status; //This only run when invoice already exist and the invoice does not have a PAID status if($invoiceStatus != PerfexCRMInvoiceStatus::PAID){ //update invoice (App()->make(UpdatesPerfexCRMInvoice::class))->execute($invoice, $this->updatePerfexCRMInvoiceObject->getProjectId()); } } //create invoice payment if($invoiceId != 0 && $invoiceStatus != PerfexCRMInvoiceStatus::PAID){ $date = Carbon::parse($transaction->created_at)->format('Y-m-d'); $invoicePaymentPerfexCRMObject = new InvoicePaymentPerfexCRMObject( $invoiceId, "$transaction->amount", $date, 1, "", "" ); (App()->make(CreatesPerfexCRMInvoicePayment::class))->execute($invoicePaymentPerfexCRMObject); } } public function delay($delay) { // Add delay in seconds to the job $this->delay = $delay; return $this; } }