mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Refactor for bank transactions
This commit is contained in:
parent
f4a12660ad
commit
d14df7ef2d
@ -28,7 +28,7 @@ class BankTransactionFactory
|
||||
$bank_transaction->category_type = '';
|
||||
$bank_transaction->date = now()->format('Y-m-d');
|
||||
$bank_transaction->description = '';
|
||||
$bank_transaction->is_matched = 0;
|
||||
$bank_transaction->status_id = 1;
|
||||
|
||||
return $bank_transaction;
|
||||
}
|
||||
|
@ -132,7 +132,7 @@ class IncomeTransformer implements BankRevenueInterface
|
||||
|
||||
public function transformTransaction($transaction)
|
||||
{
|
||||
|
||||
nlog($transaction);
|
||||
return [
|
||||
'transaction_id' => $transaction->id,
|
||||
'amount' => $transaction->amount->amount,
|
||||
|
@ -75,6 +75,7 @@ class MatchBankTransactions implements ShouldQueue
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
nlog("match bank transactions");
|
||||
|
||||
MultiDB::setDb($this->db);
|
||||
|
||||
@ -87,11 +88,13 @@ class MatchBankTransactions implements ShouldQueue
|
||||
if($_categories)
|
||||
$this->categories = collect($_categories->transactionCategory);
|
||||
|
||||
nlog($this->input);
|
||||
|
||||
foreach($this->input as $match)
|
||||
{
|
||||
if(array_key_exists('invoice_id', $match) && strlen($match['invoice_id']) > 1)
|
||||
$this->matchInvoicePayment($match);
|
||||
elseif(array_key_exists('is_expense', $match) && $match['is_expense'])
|
||||
else
|
||||
$this->matchExpense($match);
|
||||
}
|
||||
|
||||
@ -101,8 +104,12 @@ class MatchBankTransactions implements ShouldQueue
|
||||
{
|
||||
$this->bt = BankTransaction::find($match['id']);
|
||||
|
||||
nlog($this->bt->toArray());
|
||||
|
||||
$_invoice = Invoice::withTrashed()->find($match['invoice_id']);
|
||||
|
||||
nlog($_invoice->toArray());
|
||||
|
||||
if(array_key_exists('amount', $match) && $match['amount'] > 0)
|
||||
$amount = $match['amount'];
|
||||
else
|
||||
@ -130,12 +137,11 @@ class MatchBankTransactions implements ShouldQueue
|
||||
$expense->public_notes = $this->bt->description;
|
||||
$expense->save();
|
||||
|
||||
nlog($expense->toArray());
|
||||
|
||||
}
|
||||
|
||||
private function createPayment(int $invoice_id, float $amount) :void
|
||||
{
|
||||
nlog("creating payment");
|
||||
|
||||
\DB::connection(config('database.default'))->transaction(function () use($invoice_id, $amount) {
|
||||
|
||||
@ -159,6 +165,7 @@ class MatchBankTransactions implements ShouldQueue
|
||||
$payment->status_id = Payment::STATUS_COMPLETED;
|
||||
$payment->client_id = $this->invoice->client_id;
|
||||
$payment->transaction_reference = $this->bt->transaction_id;
|
||||
$payment->transaction_id = $this->bt->transaction_id;
|
||||
$payment->currency_id = $this->harvestCurrencyId();
|
||||
$payment->is_manual = false;
|
||||
$payment->date = $this->bt->date ? Carbon::parse($this->bt->date) : now();
|
||||
@ -169,6 +176,8 @@ class MatchBankTransactions implements ShouldQueue
|
||||
|
||||
$payment->saveQuietly();
|
||||
|
||||
nlog($payment->toArray());
|
||||
|
||||
$payment->service()->applyNumber()->save();
|
||||
|
||||
if($payment->client->getSetting('send_email_on_mark_paid'))
|
||||
@ -209,7 +218,7 @@ class MatchBankTransactions implements ShouldQueue
|
||||
event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
|
||||
event(new InvoiceWasPaid($this->invoice, $payment, $payment->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
|
||||
|
||||
$this->bt->is_matched = true;
|
||||
$this->bt->status_id = BankTransaction::STATUS_CONVERTED;
|
||||
$this->bt->save();
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ class BankTransactionFactory extends Factory
|
||||
'date' => $this->faker->date('Y-m-d') ,
|
||||
'bank_account_id' => 1 ,
|
||||
'description' =>$this->faker->words(5, true) ,
|
||||
'is_matched'=> false
|
||||
'status_id'=> 1
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -81,6 +81,10 @@ return new class extends Migration
|
||||
$table->unsignedInteger('bank_category_id')->nullable();
|
||||
});
|
||||
|
||||
Schema::table('payments', function (Blueprint $table) {
|
||||
$table->unsignedBigInteger('transaction_id')->nullable();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -64,7 +64,6 @@ class YodleeApiTest extends TestCase
|
||||
$data = [
|
||||
[
|
||||
'id' => $bt->id,
|
||||
'is_expense' => true
|
||||
]
|
||||
];
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user