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

108 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
*
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Models;
2022-11-20 03:12:33 +01:00
use App\Models\BankTransactionRule;
2022-11-11 00:28:25 +01:00
use App\Models\Filterable;
2022-11-10 11:57:55 +01:00
use App\Models\Invoice;
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);
if(count($invoices) >= 1)
{
foreach($invoices as $invoice){
if(is_string($invoice) && strlen($invoice) > 1)
$collection->push($this->decodePrimaryKey($invoice));
}
}
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
}
2022-11-11 05:28:49 +01:00
2022-08-11 08:26:47 +02:00
}