mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 13:12:50 +01:00
Working on system logs
This commit is contained in:
parent
0d9df1f290
commit
ffdfaefd80
105
app/Filters/SystemLogFilters.php
Normal file
105
app/Filters/SystemLogFilters.php
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Invoice Ninja (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @license https://opensource.org/licenses/AAL
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Filters;
|
||||||
|
|
||||||
|
use App\Models\Vendor;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Gate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SystemLogFilters
|
||||||
|
*/
|
||||||
|
class SystemLogFilters extends QueryFilters
|
||||||
|
{
|
||||||
|
|
||||||
|
public function type_id(int $type_id) :Builder
|
||||||
|
{
|
||||||
|
return $this->builder->where('type_id', $type_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function category_id(int $category_id) :Builder
|
||||||
|
{
|
||||||
|
return $this->builder->where('category_id', $category_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function event_id(int $event_id) :Builder
|
||||||
|
{
|
||||||
|
return $this->builder->where('event_id', $event_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter based on search text
|
||||||
|
*
|
||||||
|
* @param string query filter
|
||||||
|
* @return Illuminate\Database\Query\Builder
|
||||||
|
* @deprecated
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function filter(string $filter = '') : Builder
|
||||||
|
{
|
||||||
|
if (strlen($filter) == 0) {
|
||||||
|
return $this->builder;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->builder;
|
||||||
|
|
||||||
|
// return $this->builder->where(function ($query) use ($filter) {
|
||||||
|
// $query->where('vendors.name', 'like', '%'.$filter.'%')
|
||||||
|
// ->orWhere('vendors.id_number', 'like', '%'.$filter.'%')
|
||||||
|
// ->orWhere('vendor_contacts.first_name', 'like', '%'.$filter.'%')
|
||||||
|
// ->orWhere('vendor_contacts.last_name', 'like', '%'.$filter.'%')
|
||||||
|
// ->orWhere('vendor_contacts.email', 'like', '%'.$filter.'%')
|
||||||
|
// ->orWhere('vendors.custom_value1', 'like', '%'.$filter.'%')
|
||||||
|
// ->orWhere('vendors.custom_value2', 'like', '%'.$filter.'%')
|
||||||
|
// ->orWhere('vendors.custom_value3', 'like', '%'.$filter.'%')
|
||||||
|
// ->orWhere('vendors.custom_value4', 'like', '%'.$filter.'%');
|
||||||
|
// });
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sorts the list based on $sort
|
||||||
|
*
|
||||||
|
* @param string sort formatted as column|asc
|
||||||
|
* @return Illuminate\Database\Query\Builder
|
||||||
|
*/
|
||||||
|
public function sort(string $sort) : Builder
|
||||||
|
{
|
||||||
|
$sort_col = explode("|", $sort);
|
||||||
|
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the base query
|
||||||
|
*
|
||||||
|
* @param int company_id
|
||||||
|
* @return Illuminate\Database\Query\Builder
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
|
public function baseQuery(int $company_id, User $user) : Builder
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filters the query by the users company ID
|
||||||
|
*
|
||||||
|
* @param $company_id The company Id
|
||||||
|
* @return Illuminate\Database\Query\Builder
|
||||||
|
*/
|
||||||
|
public function entityFilter()
|
||||||
|
{
|
||||||
|
|
||||||
|
//return $this->builder->whereCompanyId(auth()->user()->company()->id);
|
||||||
|
return $this->builder->company();
|
||||||
|
}
|
||||||
|
}
|
@ -23,32 +23,6 @@ use Illuminate\Support\Facades\Gate;
|
|||||||
class VendorFilters extends QueryFilters
|
class VendorFilters extends QueryFilters
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
|
||||||
* Filter by balance
|
|
||||||
*
|
|
||||||
* @param string $balance
|
|
||||||
* @return Illuminate\Database\Query\Builder
|
|
||||||
*/
|
|
||||||
public function balance(string $balance): Builder
|
|
||||||
{
|
|
||||||
$parts = $this->split($balance);
|
|
||||||
|
|
||||||
return $this->builder->where('balance', $parts->operator, $parts->value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Filter between balances
|
|
||||||
*
|
|
||||||
* @param string balance
|
|
||||||
* @return Illuminate\Database\Query\Builder
|
|
||||||
*/
|
|
||||||
public function between_balance(string $balance): Builder
|
|
||||||
{
|
|
||||||
$parts = explode(":", $balance);
|
|
||||||
|
|
||||||
return $this->builder->whereBetween('balance', [$parts[0], $parts[1]]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filter based on search text
|
* Filter based on search text
|
||||||
*
|
*
|
||||||
|
95
app/Http/Controllers/SystemLogController.php
Normal file
95
app/Http/Controllers/SystemLogController.php
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Filters\SystemLogFilters;
|
||||||
|
use App\Models\SystemLog;
|
||||||
|
use App\Transformers\SystemLogTransformer;
|
||||||
|
use App\Utils\Traits\MakesHash;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class SystemLogController extends Controller
|
||||||
|
{
|
||||||
|
|
||||||
|
use MakesHash;
|
||||||
|
|
||||||
|
protected $entity_type = SystemLog::class;
|
||||||
|
|
||||||
|
protected $entity_transformer = SystemLogTransformer::class;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display a listing of the resource.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function index(SystemLogFilters $filters)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show the form for creating a new resource.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function create()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store a newly created resource in storage.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function store(Request $request)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display the specified resource.
|
||||||
|
*
|
||||||
|
* @param int $id
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function show($id)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show the form for editing the specified resource.
|
||||||
|
*
|
||||||
|
* @param int $id
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function edit($id)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the specified resource in storage.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @param int $id
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function update(Request $request, $id)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the specified resource from storage.
|
||||||
|
*
|
||||||
|
* @param int $id
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function destroy($id)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
@ -202,6 +202,11 @@ class Client extends BaseModel implements HasLocalePreference
|
|||||||
return $this->belongsTo(Country::class, 'shipping_country_id', 'id');
|
return $this->belongsTo(Country::class, 'shipping_country_id', 'id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function system_logs()
|
||||||
|
{
|
||||||
|
return $this->hasMany(SystemLog::class);
|
||||||
|
}
|
||||||
|
|
||||||
public function timezone()
|
public function timezone()
|
||||||
{
|
{
|
||||||
return Timezone::find($this->getSetting('timezone_id'));
|
return Timezone::find($this->getSetting('timezone_id'));
|
||||||
|
@ -391,6 +391,11 @@ class Company extends BaseModel
|
|||||||
return $this->hasMany(CompanyToken::class);
|
return $this->hasMany(CompanyToken::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function system_logs()
|
||||||
|
{
|
||||||
|
return $this->hasMany(SystemLog::class);
|
||||||
|
}
|
||||||
|
|
||||||
public function tokens_hashed()
|
public function tokens_hashed()
|
||||||
{
|
{
|
||||||
return $this->hasMany(CompanyToken::class);
|
return $this->hasMany(CompanyToken::class);
|
||||||
|
@ -17,10 +17,12 @@ use App\Models\ClientContact;
|
|||||||
use App\Models\ClientGatewayToken;
|
use App\Models\ClientGatewayToken;
|
||||||
use App\Models\CompanyLedger;
|
use App\Models\CompanyLedger;
|
||||||
use App\Models\Document;
|
use App\Models\Document;
|
||||||
|
use App\Models\SystemLog;
|
||||||
use App\Transformers\ActivityTransformer;
|
use App\Transformers\ActivityTransformer;
|
||||||
use App\Transformers\ClientGatewayTokenTransformer;
|
use App\Transformers\ClientGatewayTokenTransformer;
|
||||||
use App\Transformers\CompanyLedgerTransformer;
|
use App\Transformers\CompanyLedgerTransformer;
|
||||||
use App\Transformers\DocumentTransformer;
|
use App\Transformers\DocumentTransformer;
|
||||||
|
use App\Transformers\SystemLogTransformer;
|
||||||
use App\Utils\Traits\MakesHash;
|
use App\Utils\Traits\MakesHash;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -44,6 +46,7 @@ class ClientTransformer extends EntityTransformer
|
|||||||
'gateway_tokens',
|
'gateway_tokens',
|
||||||
'activities',
|
'activities',
|
||||||
'ledger',
|
'ledger',
|
||||||
|
'system_logs',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
@ -91,6 +94,14 @@ class ClientTransformer extends EntityTransformer
|
|||||||
|
|
||||||
return $this->includeCollection($client->ledger, $transformer, CompanyLedger::class);
|
return $this->includeCollection($client->ledger, $transformer, CompanyLedger::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function includeSystemLogs(Client $client)
|
||||||
|
{
|
||||||
|
$transformer = new SystemLogTransformer($this->serializer);
|
||||||
|
|
||||||
|
return $this->includeCollection($client->system_logs, $transformer, SystemLog::class);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Client $client
|
* @param Client $client
|
||||||
*
|
*
|
||||||
|
@ -29,8 +29,14 @@ use App\Models\PaymentTerm;
|
|||||||
use App\Models\Product;
|
use App\Models\Product;
|
||||||
use App\Models\Project;
|
use App\Models\Project;
|
||||||
use App\Models\Quote;
|
use App\Models\Quote;
|
||||||
|
use App\Models\SystemLog;
|
||||||
use App\Models\Task;
|
use App\Models\Task;
|
||||||
use App\Models\TaxRate;
|
use App\Models\TaxRate; public function includeSystemLogs(Company $company)
|
||||||
|
{
|
||||||
|
$transformer = new SystemLogTransformer($this->serializer);
|
||||||
|
|
||||||
|
return $this->includeCollection($company->system_logs, $transformer, SystemLog::class);
|
||||||
|
}
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Models\Webhook;
|
use App\Models\Webhook;
|
||||||
use App\Transformers\CompanyLedgerTransformer;
|
use App\Transformers\CompanyLedgerTransformer;
|
||||||
@ -39,6 +45,7 @@ use App\Transformers\CompanyTokenTransformer;
|
|||||||
use App\Transformers\CreditTransformer;
|
use App\Transformers\CreditTransformer;
|
||||||
use App\Transformers\DocumentTransformer;
|
use App\Transformers\DocumentTransformer;
|
||||||
use App\Transformers\PaymentTermTransformer;
|
use App\Transformers\PaymentTermTransformer;
|
||||||
|
use App\Transformers\SystemLogTransformer;
|
||||||
use App\Transformers\TaskTransformer;
|
use App\Transformers\TaskTransformer;
|
||||||
use App\Transformers\WebhookTransformer;
|
use App\Transformers\WebhookTransformer;
|
||||||
use App\Utils\Traits\MakesHash;
|
use App\Utils\Traits\MakesHash;
|
||||||
@ -88,7 +95,8 @@ class CompanyTransformer extends EntityTransformer
|
|||||||
'ledger',
|
'ledger',
|
||||||
'webhooks',
|
'webhooks',
|
||||||
'tokens',
|
'tokens',
|
||||||
'tokens_hashed'
|
'tokens_hashed',
|
||||||
|
'system_logs',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
@ -307,4 +315,11 @@ class CompanyTransformer extends EntityTransformer
|
|||||||
|
|
||||||
return $this->includeCollection($company->payment_terms()->get(), $transformer, PaymentTerm::class);
|
return $this->includeCollection($company->payment_terms()->get(), $transformer, PaymentTerm::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function includeSystemLogs(Company $company)
|
||||||
|
{
|
||||||
|
$transformer = new SystemLogTransformer($this->serializer);
|
||||||
|
|
||||||
|
return $this->includeCollection($company->system_logs, $transformer, SystemLog::class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
39
app/Transformers/SystemLogTransformer.php
Normal file
39
app/Transformers/SystemLogTransformer.php
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Transformers;
|
||||||
|
|
||||||
|
use App\Models\SystemLog;
|
||||||
|
use App\Utils\Traits\MakesHash;
|
||||||
|
|
||||||
|
class SystemLogTransformer extends EntityTransformer
|
||||||
|
{
|
||||||
|
use MakesHash;
|
||||||
|
|
||||||
|
protected $defaultIncludes = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $availableIncludes = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Activity $system_log
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function transform(SystemLog $system_log)
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'id' => (string) $this->encodePrimaryKey($system_log->id),
|
||||||
|
'company_id' => (string) $this->encodePrimaryKey($system_log->company_id),
|
||||||
|
'user_id' => (string) $this->encodePrimaryKey($system_log->user_id),
|
||||||
|
'client_id' => (string) $this->encodePrimaryKey($system_log->client_id),
|
||||||
|
'event_id' => (int) $system_log->event_id,
|
||||||
|
'category_id' => (int) $system_log->category_id,
|
||||||
|
'type_id' => (int) $system_log->type_id,
|
||||||
|
'log' => (string) $system_log->log,
|
||||||
|
'updated_at' => (int)$system_log->updated_at,
|
||||||
|
'created_at' => (int)$system_log->created_at,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user