mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-01 10:54:36 -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->category_type = '';
|
||||||
$bank_transaction->date = now()->format('Y-m-d');
|
$bank_transaction->date = now()->format('Y-m-d');
|
||||||
$bank_transaction->description = '';
|
$bank_transaction->description = '';
|
||||||
$bank_transaction->is_matched = 0;
|
$bank_transaction->status_id = 1;
|
||||||
|
|
||||||
return $bank_transaction;
|
return $bank_transaction;
|
||||||
}
|
}
|
||||||
|
@ -132,7 +132,7 @@ class IncomeTransformer implements BankRevenueInterface
|
|||||||
|
|
||||||
public function transformTransaction($transaction)
|
public function transformTransaction($transaction)
|
||||||
{
|
{
|
||||||
|
nlog($transaction);
|
||||||
return [
|
return [
|
||||||
'transaction_id' => $transaction->id,
|
'transaction_id' => $transaction->id,
|
||||||
'amount' => $transaction->amount->amount,
|
'amount' => $transaction->amount->amount,
|
||||||
|
@ -75,6 +75,7 @@ class MatchBankTransactions implements ShouldQueue
|
|||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
|
nlog("match bank transactions");
|
||||||
|
|
||||||
MultiDB::setDb($this->db);
|
MultiDB::setDb($this->db);
|
||||||
|
|
||||||
@ -87,11 +88,13 @@ class MatchBankTransactions implements ShouldQueue
|
|||||||
if($_categories)
|
if($_categories)
|
||||||
$this->categories = collect($_categories->transactionCategory);
|
$this->categories = collect($_categories->transactionCategory);
|
||||||
|
|
||||||
|
nlog($this->input);
|
||||||
|
|
||||||
foreach($this->input as $match)
|
foreach($this->input as $match)
|
||||||
{
|
{
|
||||||
if(array_key_exists('invoice_id', $match) && strlen($match['invoice_id']) > 1)
|
if(array_key_exists('invoice_id', $match) && strlen($match['invoice_id']) > 1)
|
||||||
$this->matchInvoicePayment($match);
|
$this->matchInvoicePayment($match);
|
||||||
elseif(array_key_exists('is_expense', $match) && $match['is_expense'])
|
else
|
||||||
$this->matchExpense($match);
|
$this->matchExpense($match);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,8 +104,12 @@ class MatchBankTransactions implements ShouldQueue
|
|||||||
{
|
{
|
||||||
$this->bt = BankTransaction::find($match['id']);
|
$this->bt = BankTransaction::find($match['id']);
|
||||||
|
|
||||||
|
nlog($this->bt->toArray());
|
||||||
|
|
||||||
$_invoice = Invoice::withTrashed()->find($match['invoice_id']);
|
$_invoice = Invoice::withTrashed()->find($match['invoice_id']);
|
||||||
|
|
||||||
|
nlog($_invoice->toArray());
|
||||||
|
|
||||||
if(array_key_exists('amount', $match) && $match['amount'] > 0)
|
if(array_key_exists('amount', $match) && $match['amount'] > 0)
|
||||||
$amount = $match['amount'];
|
$amount = $match['amount'];
|
||||||
else
|
else
|
||||||
@ -130,12 +137,11 @@ class MatchBankTransactions implements ShouldQueue
|
|||||||
$expense->public_notes = $this->bt->description;
|
$expense->public_notes = $this->bt->description;
|
||||||
$expense->save();
|
$expense->save();
|
||||||
|
|
||||||
nlog($expense->toArray());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function createPayment(int $invoice_id, float $amount) :void
|
private function createPayment(int $invoice_id, float $amount) :void
|
||||||
{
|
{
|
||||||
|
nlog("creating payment");
|
||||||
|
|
||||||
\DB::connection(config('database.default'))->transaction(function () use($invoice_id, $amount) {
|
\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->status_id = Payment::STATUS_COMPLETED;
|
||||||
$payment->client_id = $this->invoice->client_id;
|
$payment->client_id = $this->invoice->client_id;
|
||||||
$payment->transaction_reference = $this->bt->transaction_id;
|
$payment->transaction_reference = $this->bt->transaction_id;
|
||||||
|
$payment->transaction_id = $this->bt->transaction_id;
|
||||||
$payment->currency_id = $this->harvestCurrencyId();
|
$payment->currency_id = $this->harvestCurrencyId();
|
||||||
$payment->is_manual = false;
|
$payment->is_manual = false;
|
||||||
$payment->date = $this->bt->date ? Carbon::parse($this->bt->date) : now();
|
$payment->date = $this->bt->date ? Carbon::parse($this->bt->date) : now();
|
||||||
@ -169,6 +176,8 @@ class MatchBankTransactions implements ShouldQueue
|
|||||||
|
|
||||||
$payment->saveQuietly();
|
$payment->saveQuietly();
|
||||||
|
|
||||||
|
nlog($payment->toArray());
|
||||||
|
|
||||||
$payment->service()->applyNumber()->save();
|
$payment->service()->applyNumber()->save();
|
||||||
|
|
||||||
if($payment->client->getSetting('send_email_on_mark_paid'))
|
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 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)));
|
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();
|
$this->bt->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ class BankTransactionFactory extends Factory
|
|||||||
'date' => $this->faker->date('Y-m-d') ,
|
'date' => $this->faker->date('Y-m-d') ,
|
||||||
'bank_account_id' => 1 ,
|
'bank_account_id' => 1 ,
|
||||||
'description' =>$this->faker->words(5, true) ,
|
'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();
|
$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 = [
|
$data = [
|
||||||
[
|
[
|
||||||
'id' => $bt->id,
|
'id' => $bt->id,
|
||||||
'is_expense' => true
|
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user