1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

Fixes for bank transaction rules

This commit is contained in:
David Bomba 2023-02-08 07:31:24 +11:00
parent ec5bc57737
commit c631a05d1c
3 changed files with 45 additions and 38 deletions

View File

@ -18,7 +18,6 @@ use Illuminate\Database\Eloquent\SoftDeletes;
class BankTransactionRule extends BaseModel
{
use SoftDeletes;
use MakesHash;
use Filterable;
protected $fillable = [
@ -66,6 +65,37 @@ class BankTransactionRule extends BaseModel
private array $search_results = [];
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();
}
// rule object looks like this:
//[
// {
@ -138,34 +168,5 @@ class BankTransactionRule extends BaseModel
// }
// }
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', 'id')->withTrashed();
}
}

View File

@ -13,10 +13,13 @@ namespace App\Transformers;
use App\Models\BankTransaction;
use App\Models\BankTransactionRule;
use App\Models\Client;
use App\Models\Company;
use App\Models\ExpenseCategory;
use App\Transformers\VendorTransformer;
use App\Models\Vendor;
use App\Transformers\ExpenseCategoryTransformer;
use App\Transformers\ExpenseCateogryTransformer;
use App\Transformers\VendorTransformer;
use App\Utils\Traits\MakesHash;
/**
@ -74,31 +77,34 @@ class BankTransactionRuleTransformer extends EntityTransformer
public function includeClient(BankTransactionRule $bank_transaction_rule)
{
$transformer = new ClientTransformer($this->serializer);
if(!$bank_transaction_rule->client)
return null;
return $this->includeItem($bank_transaction_rule->expense, $transformer, Client::class);
$transformer = new ClientTransformer($this->serializer);
return $this->includeItem($bank_transaction_rule->client, $transformer, Client::class);
}
public function includeVendor(BankTransactionRule $bank_transaction_rule)
{
$transformer = new VendorTransformer($this->serializer);
if(!$bank_transaction_rule->vendor)
return null;
$transformer = new VendorTransformer($this->serializer);
return $this->includeItem($bank_transaction_rule->vendor, $transformer, Vendor::class);
}
public function includeExpenseCategory(BankTransactionRule $bank_transaction_rule)
{
$transformer = new ExpenseCategoryTransformer($this->serializer);
if(!$bank_transaction_rule->expense_cateogry)
if(!$bank_transaction_rule->expense_category)
return null;
$transformer = new ExpenseCategoryTransformer($this->serializer);
return $this->includeItem($bank_transaction_rule->expense_category, $transformer, ExpenseCategory::class);
}

View File

@ -185,7 +185,7 @@ class BankTransactionRuleTest extends TestCase
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->putJson('/api/v1/bank_transaction_rules/'. $br->hashed_id, $data);
])->putJson('/api/v1/bank_transaction_rules/'. $br->hashed_id. '?include=expense_category', $data);
} catch (ValidationException $e) {
$message = json_decode($e->validator->getMessageBag(), 1);
@ -194,7 +194,7 @@ class BankTransactionRuleTest extends TestCase
if($response){
$arr = $response->json();
nlog($arr);
$response->assertStatus(200);
}