2022-08-11 08:26:47 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2023-01-28 23:21:40 +01:00
|
|
|
* @copyright Copyright (c) 2023. 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;
|
|
|
|
|
2022-11-11 05:28:49 +01:00
|
|
|
use App\Services\Bank\BankService;
|
2022-09-21 05:21:52 +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 $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
|
|
|
|
* @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()
|
2023-08-01 12:30:47 +02:00
|
|
|
* @method static \Illuminate\Database\Eloquent\Account withTrashed()
|
2023-03-08 08:33:42 +01:00
|
|
|
* @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;
|
|
|
|
|
2022-09-21 05:21:52 +02:00
|
|
|
const STATUS_UNMATCHED = 1;
|
|
|
|
|
|
|
|
const STATUS_MATCHED = 2;
|
|
|
|
|
|
|
|
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'
|
2022-08-11 08:26:47 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
protected $dates = [
|
|
|
|
];
|
2022-09-14 08:29:00 +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;
|
|
|
|
}
|
|
|
|
|
2023-04-05 06:53:48 +02:00
|
|
|
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()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Company::class);
|
|
|
|
}
|
|
|
|
|
2022-09-21 05:21:52 +02:00
|
|
|
public function vendor()
|
2022-08-11 08:26:47 +02:00
|
|
|
{
|
2022-09-21 05:21:52 +02:00
|
|
|
return $this->belongsTo(Vendor::class);
|
2022-08-11 08:26:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function user()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(User::class)->withTrashed();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function bank_integration()
|
|
|
|
{
|
|
|
|
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
|
|
|
{
|
|
|
|
return $this->belongsTo(Account::class)->withTrashed();
|
|
|
|
}
|
|
|
|
|
2023-04-26 00:30:41 +02:00
|
|
|
public function payment()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Payment::class)->withTrashed();
|
|
|
|
}
|
|
|
|
|
2022-11-11 05:28:49 +01:00
|
|
|
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-02-16 02:36:09 +01:00
|
|
|
}
|