2022-11-13 05:12:50 +01: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-11-13 05:12:50 +01:00
|
|
|
*
|
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
use App\Models\Filterable;
|
|
|
|
use App\Utils\Traits\MakesHash;
|
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
|
|
|
|
class BankTransactionRule extends BaseModel
|
|
|
|
{
|
|
|
|
use SoftDeletes;
|
|
|
|
use MakesHash;
|
|
|
|
use Filterable;
|
|
|
|
|
|
|
|
protected $fillable = [
|
|
|
|
'name',
|
|
|
|
'rules',
|
|
|
|
'auto_convert',
|
|
|
|
'matches_on_all',
|
|
|
|
'applies_to',
|
|
|
|
'client_id',
|
|
|
|
'vendor_id',
|
|
|
|
'category_id',
|
|
|
|
];
|
|
|
|
|
2022-11-20 01:25:57 +01:00
|
|
|
protected $casts = [
|
|
|
|
'rules' => 'array',
|
|
|
|
'updated_at' => 'timestamp',
|
|
|
|
'created_at' => 'timestamp',
|
|
|
|
'deleted_at' => 'timestamp',
|
|
|
|
];
|
|
|
|
|
2022-11-13 05:12:50 +01:00
|
|
|
protected $dates = [
|
|
|
|
];
|
|
|
|
|
2022-11-13 05:41:34 +01:00
|
|
|
protected array $search_keys = [
|
2022-11-20 03:12:33 +01:00
|
|
|
'description' => 'string',
|
|
|
|
'amount' => 'number',
|
2022-11-13 05:41:34 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
/* Amount */
|
|
|
|
protected array $number_operators = [
|
|
|
|
'=',
|
|
|
|
'>',
|
|
|
|
'>=',
|
|
|
|
'<',
|
|
|
|
'<='
|
|
|
|
];
|
|
|
|
|
|
|
|
/* Description, Client, Vendor, Reference Number */
|
|
|
|
protected array $string_operators = [
|
|
|
|
'is',
|
|
|
|
'contains',
|
|
|
|
'starts_with',
|
|
|
|
'is_empty',
|
|
|
|
];
|
|
|
|
|
2022-11-13 06:46:14 +01:00
|
|
|
private array $search_results = [];
|
2022-11-13 05:52:57 +01:00
|
|
|
|
|
|
|
// rule object looks like this:
|
|
|
|
//[
|
|
|
|
// {
|
|
|
|
// 'search_key': 'client_id',
|
|
|
|
// 'operator' : 'is',
|
|
|
|
// 'value' : 'Sparky'
|
|
|
|
// }
|
|
|
|
//]
|
2022-11-13 06:46:14 +01:00
|
|
|
|
2022-11-20 03:12:33 +01:00
|
|
|
// public function processRule(BankTransaction $bank_transaction)
|
|
|
|
// {
|
|
|
|
// foreach($this->rules as $key => $rule)
|
|
|
|
// {
|
|
|
|
// $this->search($rule, $key, $bank_transaction);
|
|
|
|
// }
|
|
|
|
// }
|
2022-11-13 06:46:14 +01:00
|
|
|
|
2022-11-20 03:12:33 +01:00
|
|
|
// private function search($rule, $key, $bank_transaction)
|
|
|
|
// {
|
|
|
|
// if($rule->search_key == 'amount')
|
|
|
|
// {
|
|
|
|
// //number search
|
|
|
|
// }
|
|
|
|
// else {
|
|
|
|
// //string search
|
|
|
|
// }
|
|
|
|
// }
|
2022-11-13 06:46:14 +01:00
|
|
|
|
2022-11-20 03:12:33 +01:00
|
|
|
// private function findAmount($amount, $bank_transaction)
|
|
|
|
// {
|
|
|
|
// if($bank_transaction->base_type == 'CREDIT'){
|
|
|
|
// //search invoices
|
|
|
|
// }
|
|
|
|
// else{
|
|
|
|
// //search expenses
|
|
|
|
// }
|
2022-11-13 06:46:14 +01:00
|
|
|
|
2022-11-20 03:12:33 +01:00
|
|
|
// }
|
2022-11-13 06:46:14 +01:00
|
|
|
|
2022-11-20 03:12:33 +01:00
|
|
|
// private function searchClient($rule, $bank_transaction)
|
|
|
|
// {
|
|
|
|
// if($bank_transaction->base_type == 'CREDIT'){
|
|
|
|
// //search invoices
|
|
|
|
// }
|
|
|
|
// else{
|
|
|
|
// //search expenses
|
|
|
|
// }
|
2022-11-13 06:46:14 +01:00
|
|
|
|
2022-11-20 03:12:33 +01:00
|
|
|
// }
|
2022-11-13 06:46:14 +01:00
|
|
|
|
2022-11-20 03:12:33 +01:00
|
|
|
// private function searchVendor($rule, $bank_transaction)
|
|
|
|
// {
|
|
|
|
// //search expenses
|
2022-11-13 06:46:14 +01:00
|
|
|
|
|
|
|
|
2022-11-20 03:12:33 +01:00
|
|
|
// }
|
2022-11-13 06:46:14 +01:00
|
|
|
|
2022-11-20 03:12:33 +01:00
|
|
|
// private function searchDescription($rule, $bank_transaction)
|
|
|
|
// {
|
|
|
|
// //search expenses public notes
|
|
|
|
// }
|
2022-11-13 06:46:14 +01:00
|
|
|
|
2022-11-20 03:12:33 +01:00
|
|
|
// private function searchReference($rule, $bank_transaction)
|
|
|
|
// {
|
|
|
|
// if($bank_transaction->base_type == 'CREDIT'){
|
|
|
|
// //search invoices
|
|
|
|
// }
|
|
|
|
// else{
|
|
|
|
// //search expenses
|
|
|
|
// }
|
|
|
|
// }
|
2022-11-13 06:46:14 +01:00
|
|
|
|
2022-11-13 05:12:50 +01:00
|
|
|
public function getEntityType()
|
|
|
|
{
|
|
|
|
return self::class;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function company()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Company::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function vendor()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Vendor::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function client()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Client::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function user()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(User::class)->withTrashed();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function expense_cateogry()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(ExpenseCategory::class)->withTrashed();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|