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

117 lines
2.4 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-10 11:57:55 +01:00
use App\Models\Invoice;
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;
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-10 11:57:55 +01:00
public function matchInvoiceNumber()
{
if(strlen($this->description) > 1)
{
$i = Invoice::where('company_id', $this->company_id)
->whereIn('status_id', [1,2,3])
->where('is_deleted', 0)
->where('number', 'LIKE', '%'.$this->description.'%')
->first();
return $i ?: false;
}
return false;
}
2022-08-11 08:26:47 +02:00
}