Merge pull request #8577 from turbo124/v5-develop

Minor fixes for bank transaction processing
This commit is contained in:
David Bomba 2023-06-25 14:53:26 +10:00 committed by GitHub
commit 4b48fccbef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 103 additions and 8 deletions

View File

@ -127,9 +127,12 @@ class IncomeTransformer implements BankRevenueInterface
foreach ($transaction->transaction as $transaction) {
//do not store duplicate / pending transactions
if (property_exists($transaction, 'status') && $transaction->status == 'PENDING') {
if (property_exists($transaction, 'status') && $transaction->status == 'PENDING')
continue;
//some object do no store amounts ignore these
if(!property_exists($transaction, 'amount'))
continue;
}
$data[] = $this->transformTransaction($transaction);
}
@ -148,7 +151,7 @@ class IncomeTransformer implements BankRevenueInterface
'category_type' => $transaction->categoryType,
'date' => $transaction->date,
'bank_account_id' => $transaction->accountId,
'description' => $transaction->description->original,
'description' => $transaction?->description?->original ?? '',
'base_type' => property_exists($transaction, 'baseType') ? $transaction->baseType : $this->calculateBaseType($transaction),
];
}

View File

@ -11,17 +11,19 @@
namespace App\Jobs\Bank;
use App\Helpers\Bank\Yodlee\Yodlee;
use App\Models\Company;
use App\Libraries\MultiDB;
use Illuminate\Bus\Queueable;
use App\Models\BankIntegration;
use App\Models\BankTransaction;
use App\Models\Company;
use App\Helpers\Bank\Yodlee\Yodlee;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use App\Services\Bank\BankMatchingService;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\Middleware\WithoutOverlapping;
use App\Notifications\Ninja\GenericNinjaAdminNotification;
class ProcessBankTransactions implements ShouldQueue
{
@ -70,6 +72,14 @@ class ProcessBankTransactions implements ShouldQueue
$this->processTransactions();
} catch(\Exception $e) {
nlog("{$this->bank_integration_account_id} - exited abnormally => ". $e->getMessage());
$content = [
"Processing transactions for account: {$this->bank_integration->account->key} failed",
"Exception Details => ",
$e->getMessage(),
];
$this->bank_integration->account->company->notification(new GenericNinjaAdminNotification($content))->ninja();
return;
}
} while ($this->stop_loop);
@ -152,4 +162,15 @@ class ProcessBankTransactions implements ShouldQueue
$this->bank_integration->save();
}
}
public function middleware()
{
return [new WithoutOverlapping($this->bank_integration_account_id)];
}
public function backoff()
{
return [rand(10, 15), rand(30, 40), rand(60, 79), rand(160, 200), rand(3000, 5000)];
}
}

View File

@ -0,0 +1,71 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Notifications\Ninja;
use Illuminate\Notifications\Messages\SlackMessage;
use Illuminate\Notifications\Notification;
class GenericNinjaAdminNotification extends Notification
{
public function __construct(protected array $message_array)
{
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['slack'];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
*/
public function toMail($notifiable)
{
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
//
];
}
public function toSlack($notifiable)
{
$content = '';
foreach($this->message_array as $message) {
$content .= $message . "\n";
}
return (new SlackMessage)
->success()
->from(ctrans('texts.notification_bot'))
->image('https://app.invoiceninja.com/favicon.png')
->content($content);
}
}