Transaction send function re-factoring..

This commit is contained in:
Cüneyt Şentürk 2023-11-30 17:45:54 +03:00
parent 0ad0cd5c90
commit 8dc76b7d5a
3 changed files with 42 additions and 8 deletions

View File

@ -13,6 +13,7 @@ use App\Imports\Banking\Transactions as Import;
use App\Jobs\Banking\CreateTransaction;
use App\Jobs\Banking\DeleteTransaction;
use App\Jobs\Banking\DuplicateTransaction;
use App\Jobs\Banking\SendTransaction;
use App\Jobs\Banking\MatchBankingDocumentTransaction;
use App\Jobs\Banking\SplitTransaction;
use App\Jobs\Banking\UpdateTransaction;
@ -20,7 +21,6 @@ use App\Models\Banking\Account;
use App\Models\Banking\Transaction;
use App\Models\Document\Document;
use App\Models\Setting\Currency;
use App\Notifications\Banking\Transaction as Notification;
use App\Traits\Currencies;
use App\Traits\DateTime;
use App\Traits\Transactions as TransactionsTrait;
@ -298,12 +298,17 @@ class Transactions extends Controller
return redirect()->back();
}
// Notify the customer/vendor
$transaction->contact->notify(new Notification($transaction, config('type.transaction.' . $transaction->type . '.email_template'), true));
$response = $this->ajaxDispatch(new SendTransaction($transaction));
event(new TransactionSent($transaction));
if ($response['success']) {
$message = trans('documents.messages.email_sent', ['type' => trans_choice('general.transactions', 1)]);
flash(trans('documents.messages.email_sent', ['type' => trans_choice('general.transactions', 1)]))->success();
flash($message)->success();
} else {
$message = $response['message'];
flash($message)->error()->important();
}
return redirect()->back();
}

View File

@ -0,0 +1,27 @@
<?php
namespace App\Jobs\Banking;
use App\Abstracts\Job;
use App\Events\Banking\TransactionSending;
use App\Events\Banking\TransactionSent;
use App\Models\Banking\Transaction;
use App\Notifications\Banking\Transaction as Notification;
class SendTransaction extends Job
{
public function __construct(Transaction $transaction)
{
$this->transaction = $transaction;
}
public function handle(): void
{
event(new TransactionSending($this->transaction));
// Notify the customer/vendor
$this->transaction->contact->notify(new Notification($this->transaction, config('type.transaction.' . $this->transaction->type . '.email_template'), true));
event(new TransactionSent($this->transaction));
}
}

View File

@ -16,11 +16,13 @@ class SendDocument extends Job
public function handle(): void
{
event(new DocumentSending($document));
event(new DocumentSending($this->document));
$notification = config('type.document.' . $this->document->type . '.notification.class');
// Notify the customer
$invoice->contact->notify(new Notification($invoice, 'invoice_new_customer', true));
$this->document->contact->notify(new $notification($this->document, 'invoice_new_customer', true));
event(new DocumentSent($document));
event(new DocumentSent($this->document));
}
}