diff --git a/app/Factory/BankTransactionFactory.php b/app/Factory/BankTransactionFactory.php index a6f4eceb677d..b8d33c039ac1 100644 --- a/app/Factory/BankTransactionFactory.php +++ b/app/Factory/BankTransactionFactory.php @@ -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; } diff --git a/app/Helpers/Bank/Yodlee/Transformer/IncomeTransformer.php b/app/Helpers/Bank/Yodlee/Transformer/IncomeTransformer.php index d772c5f45d66..e992055bb5da 100644 --- a/app/Helpers/Bank/Yodlee/Transformer/IncomeTransformer.php +++ b/app/Helpers/Bank/Yodlee/Transformer/IncomeTransformer.php @@ -132,7 +132,7 @@ class IncomeTransformer implements BankRevenueInterface public function transformTransaction($transaction) { - + nlog($transaction); return [ 'transaction_id' => $transaction->id, 'amount' => $transaction->amount->amount, diff --git a/app/Jobs/Bank/MatchBankTransactions.php b/app/Jobs/Bank/MatchBankTransactions.php index 46edcee40575..4bff84816d6b 100644 --- a/app/Jobs/Bank/MatchBankTransactions.php +++ b/app/Jobs/Bank/MatchBankTransactions.php @@ -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(); } diff --git a/database/factories/BankTransactionFactory.php b/database/factories/BankTransactionFactory.php index 8bd2b1bdce2c..cc3dbb3f5f81 100644 --- a/database/factories/BankTransactionFactory.php +++ b/database/factories/BankTransactionFactory.php @@ -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 ]; } } diff --git a/database/migrations/2022_08_05_023357_bank_integration.php b/database/migrations/2022_08_05_023357_bank_integration.php index 02e386da23da..e78efe8869b2 100644 --- a/database/migrations/2022_08_05_023357_bank_integration.php +++ b/database/migrations/2022_08_05_023357_bank_integration.php @@ -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(); + }); + } /** diff --git a/tests/Feature/Bank/YodleeApiTest.php b/tests/Feature/Bank/YodleeApiTest.php index e8c7c0fbd2a0..1ddf3b23bc2f 100644 --- a/tests/Feature/Bank/YodleeApiTest.php +++ b/tests/Feature/Bank/YodleeApiTest.php @@ -64,7 +64,6 @@ class YodleeApiTest extends TestCase $data = [ [ 'id' => $bt->id, - 'is_expense' => true ] ];