1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 15:13:29 +01:00
invoiceninja/app/Models/BankTransaction.php

180 lines
5.3 KiB
PHP
Raw Normal View History

2022-08-11 08:26:47 +02:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2024-04-12 06:15:41 +02:00
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
2022-08-11 08:26:47 +02:00
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Models;
2023-10-09 06:16:35 +02:00
use App\Services\Bank\BankService;
2023-10-26 04:57:44 +02:00
use App\Utils\Traits\MakesHash;
2022-08-11 08:26:47 +02:00
use Illuminate\Database\Eloquent\SoftDeletes;
2023-03-08 08:33:42 +01:00
/**
* App\Models\BankTransaction
*
* @property int $id
* @property int $company_id
* @property int $user_id
* @property int $bank_integration_id
* @property int $transaction_id
* @property string $nordigen_transaction_id
2023-03-08 08:33:42 +01:00
* @property string $amount
* @property string|null $currency_code
* @property int|null $currency_id
* @property string|null $account_type
* @property int|null $category_id
* @property int|null $ninja_category_id
* @property string $category_type
* @property string $base_type
* @property string|null $date
* @property int $bank_account_id
* @property string|null $description
2023-12-15 16:51:24 +01:00
* @property string|null $participant
* @property string|null $participant_name
2023-03-08 08:33:42 +01:00
* @property string $invoice_ids
* @property int|null $expense_id
* @property int|null $vendor_id
* @property int $status_id
* @property int $is_deleted
* @property int|null $created_at
* @property int|null $updated_at
* @property int|null $deleted_at
* @property int|null $bank_transaction_rule_id
* @property int|null $payment_id
* @property-read \App\Models\BankIntegration $bank_integration
* @property-read \App\Models\Company $company
* @property-read \App\Models\Expense|null $expense
* @property-read mixed $hashed_id
* @property-read \App\Models\User $user
* @property-read \App\Models\Vendor|null $vendor
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel company()
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel exclude($columns)
* @method static \Database\Factories\BankTransactionFactory factory($count = null, $state = [])
* @method static \Illuminate\Database\Eloquent\Builder|BankTransaction filter(\App\Filters\QueryFilters $filters)
* @method static \Illuminate\Database\Eloquent\Builder|BankTransaction newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|BankTransaction newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|BankTransaction onlyTrashed()
* @method static \Illuminate\Database\Eloquent\Builder|BankTransaction query()
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel scope()
* @method static \Illuminate\Database\Eloquent\Builder|BankTransaction withoutTrashed()
2023-04-26 00:43:54 +02:00
* @property-read \App\Models\Payment|null $payment
2023-03-08 08:33:42 +01:00
* @mixin \Eloquent
*/
2022-08-11 08:26:47 +02:00
class BankTransaction extends BaseModel
{
use SoftDeletes;
2022-09-21 05:21:52 +02:00
use MakesHash;
2022-11-11 00:28:25 +01:00
use Filterable;
2024-01-14 05:05:00 +01:00
public const STATUS_UNMATCHED = 1;
2022-09-21 05:21:52 +02:00
2024-01-14 05:05:00 +01:00
public const STATUS_MATCHED = 2;
2022-09-21 05:21:52 +02:00
2024-01-14 05:05:00 +01:00
public const STATUS_CONVERTED = 3;
2022-08-11 08:26:47 +02:00
protected $fillable = [
2022-09-22 07:54:58 +02:00
'currency_id',
2022-09-21 05:38:33 +02:00
'category_id',
'ninja_category_id',
'date',
'description',
2022-09-23 04:51:10 +02:00
'base_type',
2022-09-23 08:54:22 +02:00
'expense_id',
2022-10-24 00:17:30 +02:00
'vendor_id',
'amount',
2023-12-15 16:51:24 +01:00
'participant',
'participant_name'
2022-08-11 08:26:47 +02:00
];
2022-09-21 05:21:52 +02:00
public function getInvoiceIds()
{
$collection = collect();
$invoices = explode(",", $this->invoice_ids);
2023-02-16 02:36:09 +01:00
if (count($invoices) >= 1) {
foreach ($invoices as $invoice) {
if (is_string($invoice) && strlen($invoice) > 1) {
2022-09-21 05:21:52 +02:00
$collection->push($this->decodePrimaryKey($invoice));
2023-02-16 02:36:09 +01:00
}
2022-09-21 05:21:52 +02:00
}
}
return $collection;
}
public function getExpenseIds()
{
$collection = collect();
$expenses = explode(",", $this->expense_id);
if (count($expenses) >= 1) {
foreach ($expenses as $expense) {
if (is_string($expense) && strlen($expense) > 1) {
$collection->push($this->decodePrimaryKey($expense));
}
}
}
return $collection;
}
2022-08-11 08:26:47 +02:00
public function getEntityType()
{
return self::class;
}
public function company(): \Illuminate\Database\Eloquent\Relations\BelongsTo
2022-08-11 08:26:47 +02:00
{
return $this->belongsTo(Company::class);
}
public function vendor(): \Illuminate\Database\Eloquent\Relations\BelongsTo
2022-08-11 08:26:47 +02:00
{
return $this->belongsTo(Vendor::class)->withTrashed();
2022-08-11 08:26:47 +02:00
}
public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo
2022-08-11 08:26:47 +02:00
{
return $this->belongsTo(User::class)->withTrashed();
}
public function bank_integration(): \Illuminate\Database\Eloquent\Relations\BelongsTo
2022-08-11 08:26:47 +02:00
{
return $this->belongsTo(BankIntegration::class)->withTrashed();
}
2023-08-01 12:30:47 +02:00
public function account(): \Illuminate\Database\Eloquent\Relations\BelongsTo
2022-08-11 08:26:47 +02:00
{
2023-08-06 09:03:12 +02:00
return $this->belongsTo(Account::class);
2022-08-11 08:26:47 +02:00
}
public function payment(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(Payment::class)->withTrashed();
}
2023-10-09 06:16:35 +02:00
// public function expense(): \Illuminate\Database\Eloquent\Relations\BelongsTo
// {
// return $this->belongsTo(Expense::class)->withTrashed();
// }
public function service(): BankService
2022-11-10 11:57:55 +01:00
{
2022-11-11 05:28:49 +01:00
return new BankService($this);
2022-11-10 11:57:55 +01:00
}
2023-10-09 06:16:35 +02:00
public function getExpenses()
{
return Expense::whereIn('id', $this->getExpenseIds())->get();
}
2023-02-16 02:36:09 +01:00
}