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

218 lines
6.6 KiB
PHP
Raw Normal View History

2022-11-13 05:12:50 +01:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2024-04-12 06:15:41 +02:00
* @copyright Copyright (c) 2024. 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 Illuminate\Database\Eloquent\SoftDeletes;
2023-03-08 08:33:42 +01:00
/**
* App\Models\BankTransactionRule
*
* @property int $id
* @property int $company_id
* @property int $user_id
* @property string $name
* @property array|null $rules
* @property int $auto_convert
* @property int $matches_on_all
* @property string $applies_to
* @property int|null $client_id
* @property int|null $vendor_id
* @property int|null $category_id
2024-06-15 09:34:08 +02:00
* @property bool $is_deleted
2023-03-08 08:33:42 +01:00
* @property int|null $created_at
* @property int|null $updated_at
* @property int|null $deleted_at
* @property-read \App\Models\Client|null $client
* @property-read \App\Models\Company $company
* @property-read \App\Models\ExpenseCategory|null $expense_category
* @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\BankTransactionRuleFactory factory($count = null, $state = [])
* @method static \Illuminate\Database\Eloquent\Builder|BankTransactionRule filter(\App\Filters\QueryFilters $filters)
* @method static \Illuminate\Database\Eloquent\Builder|BankTransactionRule newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|BankTransactionRule newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|BankTransactionRule onlyTrashed()
* @method static \Illuminate\Database\Eloquent\Builder|BankTransactionRule query()
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel scope()
* @method static \Illuminate\Database\Eloquent\Builder|BankTransactionRule whereAppliesTo($value)
* @method static \Illuminate\Database\Eloquent\Builder|BankTransactionRule whereAutoConvert($value)
* @method static \Illuminate\Database\Eloquent\Builder|BankTransactionRule whereCategoryId($value)
* @method static \Illuminate\Database\Eloquent\Builder|BankTransactionRule whereClientId($value)
* @method static \Illuminate\Database\Eloquent\Builder|BankTransactionRule whereCompanyId($value)
* @method static \Illuminate\Database\Eloquent\Builder|BankTransactionRule whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|BankTransactionRule whereDeletedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|BankTransactionRule whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|BankTransactionRule whereIsDeleted($value)
* @method static \Illuminate\Database\Eloquent\Builder|BankTransactionRule whereMatchesOnAll($value)
* @method static \Illuminate\Database\Eloquent\Builder|BankTransactionRule whereName($value)
* @method static \Illuminate\Database\Eloquent\Builder|BankTransactionRule whereRules($value)
* @method static \Illuminate\Database\Eloquent\Builder|BankTransactionRule whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|BankTransactionRule whereUserId($value)
* @method static \Illuminate\Database\Eloquent\Builder|BankTransactionRule whereVendorId($value)
* @method static \Illuminate\Database\Eloquent\Builder|BankTransactionRule withTrashed()
* @method static \Illuminate\Database\Eloquent\Builder|BankTransactionRule withoutTrashed()
* @mixin \Eloquent
*/
2022-11-13 05:12:50 +01:00
class BankTransactionRule extends BaseModel
{
use SoftDeletes;
use Filterable;
2024-01-14 05:05:00 +01:00
2022-11-13 05:12:50 +01:00
protected $fillable = [
'name',
'rules',
'auto_convert',
'matches_on_all',
'applies_to',
'client_id',
'vendor_id',
'category_id',
];
protected $casts = [
'rules' => 'array',
'updated_at' => 'timestamp',
'created_at' => 'timestamp',
'deleted_at' => 'timestamp',
];
2024-01-14 05:05:00 +01:00
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
2023-02-07 21:31:24 +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_category()
{
return $this->belongsTo(ExpenseCategory::class, 'category_id')->withTrashed();
}
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
2024-01-14 05:05:00 +01:00
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
// }
// }
2023-02-16 02:36:09 +01:00
}