diff --git a/app/Filters/SystemLogFilters.php b/app/Filters/SystemLogFilters.php new file mode 100644 index 0000000000..2f467502e0 --- /dev/null +++ b/app/Filters/SystemLogFilters.php @@ -0,0 +1,105 @@ +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(); + } +} diff --git a/app/Filters/VendorFilters.php b/app/Filters/VendorFilters.php index 183232a1ec..769608d49c 100644 --- a/app/Filters/VendorFilters.php +++ b/app/Filters/VendorFilters.php @@ -23,32 +23,6 @@ use Illuminate\Support\Facades\Gate; 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 * diff --git a/app/Http/Controllers/SystemLogController.php b/app/Http/Controllers/SystemLogController.php new file mode 100644 index 0000000000..22658a66a8 --- /dev/null +++ b/app/Http/Controllers/SystemLogController.php @@ -0,0 +1,95 @@ +belongsTo(Country::class, 'shipping_country_id', 'id'); } + public function system_logs() + { + return $this->hasMany(SystemLog::class); + } + public function timezone() { return Timezone::find($this->getSetting('timezone_id')); diff --git a/app/Models/Company.php b/app/Models/Company.php index d54f712a93..9027999579 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -391,6 +391,11 @@ class Company extends BaseModel return $this->hasMany(CompanyToken::class); } + public function system_logs() + { + return $this->hasMany(SystemLog::class); + } + public function tokens_hashed() { return $this->hasMany(CompanyToken::class); diff --git a/app/Transformers/ClientTransformer.php b/app/Transformers/ClientTransformer.php index 0f06ab572f..cc533fc253 100644 --- a/app/Transformers/ClientTransformer.php +++ b/app/Transformers/ClientTransformer.php @@ -17,10 +17,12 @@ use App\Models\ClientContact; use App\Models\ClientGatewayToken; use App\Models\CompanyLedger; use App\Models\Document; +use App\Models\SystemLog; use App\Transformers\ActivityTransformer; use App\Transformers\ClientGatewayTokenTransformer; use App\Transformers\CompanyLedgerTransformer; use App\Transformers\DocumentTransformer; +use App\Transformers\SystemLogTransformer; use App\Utils\Traits\MakesHash; /** @@ -44,6 +46,7 @@ class ClientTransformer extends EntityTransformer 'gateway_tokens', 'activities', 'ledger', + 'system_logs', ]; @@ -91,6 +94,14 @@ class ClientTransformer extends EntityTransformer 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 * diff --git a/app/Transformers/CompanyTransformer.php b/app/Transformers/CompanyTransformer.php index 513aa56876..afdccec116 100644 --- a/app/Transformers/CompanyTransformer.php +++ b/app/Transformers/CompanyTransformer.php @@ -29,8 +29,14 @@ use App\Models\PaymentTerm; use App\Models\Product; use App\Models\Project; use App\Models\Quote; +use App\Models\SystemLog; 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\Webhook; use App\Transformers\CompanyLedgerTransformer; @@ -39,6 +45,7 @@ use App\Transformers\CompanyTokenTransformer; use App\Transformers\CreditTransformer; use App\Transformers\DocumentTransformer; use App\Transformers\PaymentTermTransformer; +use App\Transformers\SystemLogTransformer; use App\Transformers\TaskTransformer; use App\Transformers\WebhookTransformer; use App\Utils\Traits\MakesHash; @@ -88,7 +95,8 @@ class CompanyTransformer extends EntityTransformer 'ledger', 'webhooks', '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); } + + public function includeSystemLogs(Company $company) + { + $transformer = new SystemLogTransformer($this->serializer); + + return $this->includeCollection($company->system_logs, $transformer, SystemLog::class); + } } diff --git a/app/Transformers/SystemLogTransformer.php b/app/Transformers/SystemLogTransformer.php new file mode 100644 index 0000000000..1e286d3ff3 --- /dev/null +++ b/app/Transformers/SystemLogTransformer.php @@ -0,0 +1,39 @@ + (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, + ]; + } +}