1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00
invoiceninja/app/Models/BankTransaction.php

102 lines
2.1 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
*
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;
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;
}
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 expense()
{
return $this->belongsTo(Expense::class);
}
public function user()
{
return $this->belongsTo(User::class)->withTrashed();
}
public function bank_integration()
{
return $this->belongsTo(BankIntegration::class)->withTrashed();
}
public function account()
{
return $this->belongsTo(Account::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
}