Skip to content

Commit

Permalink
Merge pull request #42 from kamgrzeski/dev
Browse files Browse the repository at this point in the history
feat: code refactor and optimize includes relation changes
  • Loading branch information
kamgrzeski authored Sep 27, 2024
2 parents e2b1a45 + 4f36041 commit 797ba1f
Show file tree
Hide file tree
Showing 61 changed files with 553 additions and 382 deletions.
9 changes: 4 additions & 5 deletions app/Http/Controllers/CRM/ClientController.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function processRenderCreateForm(): \Illuminate\View\View
public function processShowClientDetails(ClientsModel $client): \Illuminate\View\View
{
// Return the view with the client details.
return view('crm.clients.show')->with(['clientDetails' => $this->clientService->loadClientDetails($client)]);
return view('crm.clients.show')->with(['client' => $this->clientService->loadClientDetails($client)]);
}

/**
Expand All @@ -67,7 +67,7 @@ public function processShowClientDetails(ClientsModel $client): \Illuminate\View
public function processRenderUpdateForm(ClientsModel $client): \Illuminate\View\View
{
// Return the view for updating the client record.
return view('crm.clients.edit')->with(['clientDetails' => $this->clientService->loadClientDetails($client)]);
return view('crm.clients.edit')->with(['client' => $this->clientService->loadClientDetails($client)]);
}

/**
Expand Down Expand Up @@ -139,14 +139,13 @@ public function processDeleteClient(ClientsModel $client): \Illuminate\Http\Redi
* Set the active status of a client record.
*
* @param ClientsModel $client
* @param bool $value
* @return \Illuminate\Http\RedirectResponse
* @throws \Exception
*/
public function processClientSetIsActive(ClientsModel $client, bool $value): \Illuminate\Http\RedirectResponse
public function processClientSetIsActive(ClientsModel $client): \Illuminate\Http\RedirectResponse
{
// UpdateClientJob is a job that updates the client model.
$this->dispatchSync(new UpdateClientJob(['is_active' => $value], $client));
$this->dispatchSync(new UpdateClientJob(['is_active' => ! $client->is_active], $client));

// Redirect to the clients page with a success message.
return redirect()->back()->with('message_success', $this->getMessage('messages.client_update'));
Expand Down
5 changes: 2 additions & 3 deletions app/Http/Controllers/CRM/CompaniesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,13 @@ public function processDeleteCompany(CompaniesModel $company): \Illuminate\Http\
* Set the active status of a company record.
*
* @param CompaniesModel $company
* @param bool $value
* @return \Illuminate\Http\RedirectResponse
* @throws \Exception
*/
public function processCompanySetIsActive(CompaniesModel $company, bool $value): \Illuminate\Http\RedirectResponse
public function processCompanySetIsActive(CompaniesModel $company): \Illuminate\Http\RedirectResponse
{
// Update company status.
$this->dispatchSync(new UpdateCompanyJob(['is_active' => $value], $company));
$this->dispatchSync(new UpdateCompanyJob(['is_active' => ! $company->is_active], $company));

// Store system log.
$this->dispatchSync(new StoreSystemLogJob('CompaniesModel has been updated.', 201, auth()->user()));
Expand Down
5 changes: 2 additions & 3 deletions app/Http/Controllers/CRM/DealsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,13 @@ public function processDeleteDeal(DealsModel $deal): \Illuminate\Http\RedirectRe
* Set the active status of a deal record.
*
* @param DealsModel $deal
* @param bool $value
* @return \Illuminate\Http\RedirectResponse
* @throws \Exception
*/
public function processSetIsActive(DealsModel $deal, bool $value): \Illuminate\Http\RedirectResponse
public function processSetIsActive(DealsModel $deal): \Illuminate\Http\RedirectResponse
{
// Update the deal status.
$this->dispatchSync(new UpdateDealJob(['is_active' => $value], $deal));
$this->dispatchSync(new UpdateDealJob(['is_active' => $deal->is_active], $deal));

// Log the action.
$this->dispatchSync(new StoreSystemLogJob('Deals has been enabled with id: ' . $deal->id, 201, auth()->user()));
Expand Down
5 changes: 2 additions & 3 deletions app/Http/Controllers/CRM/EmployeesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,13 @@ public function processDeleteEmployee(EmployeesModel $employee): \Illuminate\Htt
* Set the active status of an employee record.
*
* @param EmployeesModel $employee
* @param bool $value
* @return \Illuminate\Http\RedirectResponse
* @throws \Exception
*/
public function processEmployeeSetIsActive(EmployeesModel $employee, bool $value): \Illuminate\Http\RedirectResponse
public function processEmployeeSetIsActive(EmployeesModel $employee): \Illuminate\Http\RedirectResponse
{
// Dispatch the job to update the employee record.
$this->dispatchSync(new UpdateEmployeeJob(['is_active' => $value], $employee));
$this->dispatchSync(new UpdateEmployeeJob(['is_active' => ! $employee->is_active], $employee));

// Dispatch the job to store the system log.
$this->dispatchSync(new StoreSystemLogJob('Employees has been enabled with id: ' . $employee->id, 201, auth()->user()));
Expand Down
5 changes: 2 additions & 3 deletions app/Http/Controllers/CRM/FinancesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,13 @@ public function processDeleteFinance(FinancesModel $finance)
* Set the active status of a finance record.
*
* @param FinancesModel $finance
* @param bool $value
* @return \Illuminate\Http\RedirectResponse
* @throws \Exception
*/
public function processFinanceSetIsActive(FinancesModel $finance, $value)
public function processFinanceSetIsActive(FinancesModel $finance)
{
// UpdateFinanceJob is a job that updates the finance model.
$this->dispatchSync(new UpdateFinanceJob(['is_active' => $value], $finance));
$this->dispatchSync(new UpdateFinanceJob(['is_active' => ! $finance->is_active], $finance));

// StoreSystemLogJob is a job that stores the system log.
$this->dispatchSync(new StoreSystemLogJob('FinancesModel has been enabled with id: ' . $finance->id, 201, auth()->user()));
Expand Down
5 changes: 2 additions & 3 deletions app/Http/Controllers/CRM/ProductsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,13 @@ public function processDeleteProduct(ProductsModel $product): \Illuminate\Http\R
* Set the active status of a product record.
*
* @param ProductsModel $product
* @param bool $value
* @return \Illuminate\Http\RedirectResponse
* @throws \Exception
*/
public function processProductSetIsActive(ProductsModel $product, bool $value): \Illuminate\Http\RedirectResponse
public function processProductSetIsActive(ProductsModel $product): \Illuminate\Http\RedirectResponse
{
// Update the product's active status.
$this->dispatchSync(new UpdateProductJob(['is_active' => $value], $product));
$this->dispatchSync(new UpdateProductJob(['is_active' => $product->is_active], $product));

// Store a system log.
$this->dispatchSync(new StoreSystemLogJob('ProductsModel has been enabled with id: ' . $product->id, 201, auth()->user()));
Expand Down
5 changes: 2 additions & 3 deletions app/Http/Controllers/CRM/SalesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,13 @@ public function processDeleteSale(SalesModel $sale): \Illuminate\Http\RedirectRe
* Set the active status of a sale record.
*
* @param SalesModel $sale
* @param bool $value
* @return \Illuminate\Http\RedirectResponse
* @throws \Exception
*/
public function processSaleSetIsActive(SalesModel $sale, bool $value): \Illuminate\Http\RedirectResponse
public function processSaleSetIsActive(SalesModel $sale): \Illuminate\Http\RedirectResponse
{
// Dispatch the job to update the sale record.
$this->dispatchSync(new UpdateSaleJob(['is_active' => $value], $sale));
$this->dispatchSync(new UpdateSaleJob(['is_active' => ! $sale->is_active], $sale));

// Dispatch the job to store the system log.
$this->dispatchSync(new StoreSystemLogJob('SalesModel has been enabled with id: ' . $sale->id, 201, auth()->user()));
Expand Down
10 changes: 4 additions & 6 deletions app/Http/Controllers/CRM/TasksController.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,13 @@ public function processDeleteTask(TasksModel $task): \Illuminate\Http\RedirectRe
* Set the active status of a task record.
*
* @param TasksModel $task
* @param bool $value
* @return \Illuminate\Http\RedirectResponse
* @throws \Exception
*/
public function processTaskSetIsActive(TasksModel $task, bool $value): \Illuminate\Http\RedirectResponse
public function processTaskSetIsActive(TasksModel $task): \Illuminate\Http\RedirectResponse
{
// Update the task status.
$this->dispatchSync(new UpdateTaskJob(['is_active' => $value], $task));
$this->dispatchSync(new UpdateTaskJob(['is_active' => $task->is_active], $task));

// Log the task status change.
$this->dispatchSync(new StoreSystemLogJob('Tasks has been enabled with id: ' . $task->id, 201, auth()->user()));
Expand All @@ -167,14 +166,13 @@ public function processTaskSetIsActive(TasksModel $task, bool $value): \Illumina
* Set a task record to complete.
*
* @param TasksModel $task
* @param bool $value
* @return RedirectResponse
* @throws \Exception
*/
public function processSetTaskToCompleted(TasksModel $task, bool $value): \Illuminate\Http\RedirectResponse
public function processSetTaskToCompleted(TasksModel $task): \Illuminate\Http\RedirectResponse
{
// Update the task to complete.
$this->dispatchSync(new UpdateTaskJob(['completed' => $value], $task));
$this->dispatchSync(new UpdateTaskJob(['completed' => ! $task->completed], $task));

// Log the task completion.
$this->dispatchSync(new StoreSystemLogJob('Tasks has been completed with id: ' . $task->id, 201, auth()->user()));
Expand Down
14 changes: 3 additions & 11 deletions app/Models/ClientsModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,19 @@

namespace App\Models;

use App\Relations\Has\HasManyCompanies;
use App\Relations\Has\HasManyEmployees;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class ClientsModel extends Model
{
use SoftDeletes;
use SoftDeletes, HasManyEmployees, HasManyCompanies;

protected $table = 'clients';
protected $dates = ['deleted_at'];

protected $fillable = [
'full_name', 'phone', 'email', 'section', 'budget', 'location', 'zip', 'city', 'country', 'is_active', 'admin_id'
];

public function companies()
{
return $this->hasMany(CompaniesModel::class, 'client_id');
}

public function employees()
{
return $this->hasMany(EmployeesModel::class, 'id');
}
}
26 changes: 5 additions & 21 deletions app/Models/CompaniesModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

namespace App\Models;

use App\Relations\Belongs\BelongsToClient;
use App\Relations\Belongs\BelongsToEmployee;
use App\Relations\Has\HasManyDeals;
use App\Relations\Has\HasManyFinances;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class CompaniesModel extends Model
{
use SoftDeletes;
use SoftDeletes, BelongsToClient, HasManyDeals, HasManyFinances, BelongsToEmployee;

protected $fillable = [
'name',
Expand All @@ -28,24 +32,4 @@ class CompaniesModel extends Model

protected $table = 'companies';
protected $dates = ['deleted_at'];

public function client()
{
return $this->belongsTo(ClientsModel::class);
}

public function deals()
{
return $this->hasMany(DealsModel::class, 'id');
}

public function employees_size()
{
return $this->belongsTo(EmployeesModel::class);
}

public function finances()
{
return $this->hasMany(FinancesModel::class);
}
}
14 changes: 3 additions & 11 deletions app/Models/DealsModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,17 @@

namespace App\Models;

use App\Relations\Belongs\BelongsToCompany;
use App\Relations\Has\HasManyDealTerms;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class DealsModel extends Model
{
use SoftDeletes;
use SoftDeletes, BelongsToCompany, HasManyDealTerms;

protected $fillable = ['name', 'companies_id', 'is_active'];

protected $table = 'deals';
protected $dates = ['deleted_at'];

public function companies()
{
return $this->belongsTo(CompaniesModel::class);
}

public function dealTerms()
{
return $this->hasMany(DealsTermsModel::class, 'deal_id');
}
}
26 changes: 5 additions & 21 deletions app/Models/EmployeesModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

namespace App\Models;

use App\Relations\Belongs\BelongsToClient;
use App\Relations\Belongs\BelongsToDeal;
use App\Relations\Has\HasManyCompanies;
use App\Relations\Has\HasManyTasks;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class EmployeesModel extends Model
{
use SoftDeletes;
use SoftDeletes, HasManyCompanies, BelongsToDeal, BelongsToClient, HasManyTasks;

protected $fillable = [
'first_name',
Expand All @@ -23,25 +27,5 @@ class EmployeesModel extends Model

protected $table = 'employees';
protected $dates = ['deleted_at'];

public function companies()
{
return $this->hasMany(CompaniesModel::class);
}

public function deals()
{
return $this->belongsTo(DealsModel::class);
}

public function client()
{
return $this->belongsTo(ClientsModel::class);
}

public function tasks()
{
return $this->hasMany(TasksModel::class, 'employee_id');
}
}

8 changes: 2 additions & 6 deletions app/Models/FinancesModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

namespace App\Models;

use App\Relations\Belongs\BelongsToCompany;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class FinancesModel extends Model
{
use SoftDeletes;
use SoftDeletes, BelongsToCompany;

protected $fillable = [
'companies_id',
Expand All @@ -27,9 +28,4 @@ class FinancesModel extends Model
protected $dates = ['deleted_at'];

protected $table = 'finances';

public function companies()
{
return $this->belongsTo(CompaniesModel::class);
}
}
8 changes: 2 additions & 6 deletions app/Models/ProductsModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@

namespace App\Models;

use App\Relations\Has\HasManySales;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class ProductsModel extends Model
{
use SoftDeletes;
use SoftDeletes, HasManySales;

protected $table = 'products';
protected $dates = ['deleted_at'];

protected $fillable = ['name', 'category', 'count', 'price', 'is_active', 'admin_id'];

public function sales()
{
return $this->hasMany(SalesModel::class, 'id');
}
}
8 changes: 2 additions & 6 deletions app/Models/SalesModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

namespace App\Models;

use App\Relations\Belongs\BelongsToProduct;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class SalesModel extends Model
{
use SoftDeletes;
use SoftDeletes, BelongsToProduct;

protected $fillable = ['name', 'quantity', 'date_of_payment', 'product_id', 'price', 'is_active', 'admin_id'];

Expand All @@ -17,9 +18,4 @@ class SalesModel extends Model

protected $table = 'sales';
protected $dates = ['deleted_at'];

public function products()
{
return $this->belongsTo(ProductsModel::class, 'product_id');
}
}
Loading

0 comments on commit 797ba1f

Please sign in to comment.