diff --git a/app/Http/Controllers/CRM/ClientController.php b/app/Http/Controllers/CRM/ClientController.php index 707deb5..98921e8 100644 --- a/app/Http/Controllers/CRM/ClientController.php +++ b/app/Http/Controllers/CRM/ClientController.php @@ -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)]); } /** @@ -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)]); } /** @@ -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')); diff --git a/app/Http/Controllers/CRM/CompaniesController.php b/app/Http/Controllers/CRM/CompaniesController.php index d2bfa01..1270f3c 100644 --- a/app/Http/Controllers/CRM/CompaniesController.php +++ b/app/Http/Controllers/CRM/CompaniesController.php @@ -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())); diff --git a/app/Http/Controllers/CRM/DealsController.php b/app/Http/Controllers/CRM/DealsController.php index 5d211f9..88bc72c 100644 --- a/app/Http/Controllers/CRM/DealsController.php +++ b/app/Http/Controllers/CRM/DealsController.php @@ -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())); diff --git a/app/Http/Controllers/CRM/EmployeesController.php b/app/Http/Controllers/CRM/EmployeesController.php index 6152750..c1fbbb5 100644 --- a/app/Http/Controllers/CRM/EmployeesController.php +++ b/app/Http/Controllers/CRM/EmployeesController.php @@ -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())); diff --git a/app/Http/Controllers/CRM/FinancesController.php b/app/Http/Controllers/CRM/FinancesController.php index 26eaf6e..df5e49f 100644 --- a/app/Http/Controllers/CRM/FinancesController.php +++ b/app/Http/Controllers/CRM/FinancesController.php @@ -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())); diff --git a/app/Http/Controllers/CRM/ProductsController.php b/app/Http/Controllers/CRM/ProductsController.php index 0b0833f..abd40e4 100644 --- a/app/Http/Controllers/CRM/ProductsController.php +++ b/app/Http/Controllers/CRM/ProductsController.php @@ -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())); diff --git a/app/Http/Controllers/CRM/SalesController.php b/app/Http/Controllers/CRM/SalesController.php index 8a1f5a3..c468c80 100644 --- a/app/Http/Controllers/CRM/SalesController.php +++ b/app/Http/Controllers/CRM/SalesController.php @@ -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())); diff --git a/app/Http/Controllers/CRM/TasksController.php b/app/Http/Controllers/CRM/TasksController.php index 01d3b3a..d03c7ec 100644 --- a/app/Http/Controllers/CRM/TasksController.php +++ b/app/Http/Controllers/CRM/TasksController.php @@ -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())); @@ -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())); diff --git a/app/Models/ClientsModel.php b/app/Models/ClientsModel.php index e511392..3f31220 100644 --- a/app/Models/ClientsModel.php +++ b/app/Models/ClientsModel.php @@ -2,12 +2,14 @@ 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']; @@ -15,14 +17,4 @@ class ClientsModel extends Model 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'); - } } diff --git a/app/Models/CompaniesModel.php b/app/Models/CompaniesModel.php index fc36581..29fe9c2 100644 --- a/app/Models/CompaniesModel.php +++ b/app/Models/CompaniesModel.php @@ -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', @@ -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); - } } diff --git a/app/Models/DealsModel.php b/app/Models/DealsModel.php index 2c138e6..6be4faf 100644 --- a/app/Models/DealsModel.php +++ b/app/Models/DealsModel.php @@ -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'); - } } diff --git a/app/Models/EmployeesModel.php b/app/Models/EmployeesModel.php index c10500a..b1db8b4 100644 --- a/app/Models/EmployeesModel.php +++ b/app/Models/EmployeesModel.php @@ -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', @@ -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'); - } } diff --git a/app/Models/FinancesModel.php b/app/Models/FinancesModel.php index 7ed4973..0102eab 100644 --- a/app/Models/FinancesModel.php +++ b/app/Models/FinancesModel.php @@ -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', @@ -27,9 +28,4 @@ class FinancesModel extends Model protected $dates = ['deleted_at']; protected $table = 'finances'; - - public function companies() - { - return $this->belongsTo(CompaniesModel::class); - } } diff --git a/app/Models/ProductsModel.php b/app/Models/ProductsModel.php index 8af9b26..47947ba 100644 --- a/app/Models/ProductsModel.php +++ b/app/Models/ProductsModel.php @@ -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'); - } } diff --git a/app/Models/SalesModel.php b/app/Models/SalesModel.php index 230fb87..1816df4 100644 --- a/app/Models/SalesModel.php +++ b/app/Models/SalesModel.php @@ -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']; @@ -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'); - } } diff --git a/app/Models/TasksModel.php b/app/Models/TasksModel.php index 23ad2fc..5f7591f 100644 --- a/app/Models/TasksModel.php +++ b/app/Models/TasksModel.php @@ -2,20 +2,16 @@ namespace App\Models; +use App\Relations\Belongs\BelongsToEmployee; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; class TasksModel extends Model { - use SoftDeletes; + use SoftDeletes, BelongsToEmployee; protected $fillable = ['name', 'employee_id', 'duration', 'is_active', 'completed', 'admin_id']; protected $table = 'tasks'; protected $dates = ['deleted_at']; - - public function employees() - { - return $this->belongsTo(EmployeesModel::class, 'employee_id'); - } } diff --git a/app/Relations/Belongs/BelongsToClient.php b/app/Relations/Belongs/BelongsToClient.php new file mode 100644 index 0000000..7ed512f --- /dev/null +++ b/app/Relations/Belongs/BelongsToClient.php @@ -0,0 +1,16 @@ +belongsTo(ClientsModel::class); + } +} diff --git a/app/Relations/Belongs/BelongsToCompany.php b/app/Relations/Belongs/BelongsToCompany.php new file mode 100644 index 0000000..9848211 --- /dev/null +++ b/app/Relations/Belongs/BelongsToCompany.php @@ -0,0 +1,17 @@ +belongsTo(CompaniesModel::class); + } +} diff --git a/app/Relations/Belongs/BelongsToDeal.php b/app/Relations/Belongs/BelongsToDeal.php new file mode 100644 index 0000000..d56bed9 --- /dev/null +++ b/app/Relations/Belongs/BelongsToDeal.php @@ -0,0 +1,16 @@ +belongsTo(DealsModel::class); + } +} diff --git a/app/Relations/Belongs/BelongsToEmployee.php b/app/Relations/Belongs/BelongsToEmployee.php new file mode 100644 index 0000000..a59d0b9 --- /dev/null +++ b/app/Relations/Belongs/BelongsToEmployee.php @@ -0,0 +1,16 @@ +belongsTo(EmployeesModel::class); + } +} diff --git a/app/Relations/Belongs/BelongsToProduct.php b/app/Relations/Belongs/BelongsToProduct.php new file mode 100644 index 0000000..bc0188a --- /dev/null +++ b/app/Relations/Belongs/BelongsToProduct.php @@ -0,0 +1,16 @@ +belongsTo(ProductsModel::class, 'product_id'); + } +} diff --git a/app/Relations/Has/HasManyCompanies.php b/app/Relations/Has/HasManyCompanies.php new file mode 100644 index 0000000..4ee478a --- /dev/null +++ b/app/Relations/Has/HasManyCompanies.php @@ -0,0 +1,14 @@ +hasMany(CompaniesModel::class, 'client_id'); + } +} diff --git a/app/Relations/Has/HasManyDealTerms.php b/app/Relations/Has/HasManyDealTerms.php new file mode 100644 index 0000000..a3fd964 --- /dev/null +++ b/app/Relations/Has/HasManyDealTerms.php @@ -0,0 +1,17 @@ +hasMany(DealsTermsModel::class, 'deal_id'); + } +} diff --git a/app/Relations/Has/HasManyDeals.php b/app/Relations/Has/HasManyDeals.php new file mode 100644 index 0000000..1376ffd --- /dev/null +++ b/app/Relations/Has/HasManyDeals.php @@ -0,0 +1,18 @@ +hasMany(DealsModel::class, 'id'); + } +} diff --git a/app/Relations/Has/HasManyEmployees.php b/app/Relations/Has/HasManyEmployees.php new file mode 100644 index 0000000..c7464d3 --- /dev/null +++ b/app/Relations/Has/HasManyEmployees.php @@ -0,0 +1,18 @@ +hasMany(EmployeesModel::class, 'client_id'); + } +} diff --git a/app/Relations/Has/HasManyFinances.php b/app/Relations/Has/HasManyFinances.php new file mode 100644 index 0000000..dd6e9b3 --- /dev/null +++ b/app/Relations/Has/HasManyFinances.php @@ -0,0 +1,19 @@ +hasMany(FinancesModel::class); + } +} diff --git a/app/Relations/Has/HasManySales.php b/app/Relations/Has/HasManySales.php new file mode 100644 index 0000000..1ba3540 --- /dev/null +++ b/app/Relations/Has/HasManySales.php @@ -0,0 +1,15 @@ +hasMany(SalesModel::class); + } +} diff --git a/app/Relations/Has/HasManyTasks.php b/app/Relations/Has/HasManyTasks.php new file mode 100644 index 0000000..412550d --- /dev/null +++ b/app/Relations/Has/HasManyTasks.php @@ -0,0 +1,15 @@ +hasMany(TasksModel::class, 'employee_id'); + } +} diff --git a/app/Services/EmployeesService.php b/app/Services/EmployeesService.php index 6437416..c507c33 100644 --- a/app/Services/EmployeesService.php +++ b/app/Services/EmployeesService.php @@ -25,13 +25,13 @@ public function loadEmployees(bool $createForm = false): \Illuminate\Support\Col return EmployeesModel::pluck('full_name', 'id'); } - $query = EmployeesModel::orderBy('created_at')->get(); + $employees = EmployeesModel::orderBy('created_at')->get(); - foreach($query as $key => $value) { - Arr::add($query[$key], 'taskCount', TasksQueries::getEmployeesTaskCount($value->id)); + foreach($employees as $key => $employee) { + Arr::add($employees[$key], 'taskCount', TasksQueries::getEmployeesTaskCount($employee->id)); } - return $query; + return $employees; } /** diff --git a/database/migrations/2024_09_27_122828_rename_companies_id_to_company_id_in_deals_table.php b/database/migrations/2024_09_27_122828_rename_companies_id_to_company_id_in_deals_table.php new file mode 100644 index 0000000..592a1d8 --- /dev/null +++ b/database/migrations/2024_09_27_122828_rename_companies_id_to_company_id_in_deals_table.php @@ -0,0 +1,28 @@ +renameColumn('companies_id', 'company_id'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('deals', function (Blueprint $table) { + $table->renameColumn('company_id', 'companies_id'); + }); + } +}; diff --git a/database/migrations/2024_09_27_123343_rename_companies_id_to_company_id_in_finances_table.php b/database/migrations/2024_09_27_123343_rename_companies_id_to_company_id_in_finances_table.php new file mode 100644 index 0000000..66bb69a --- /dev/null +++ b/database/migrations/2024_09_27_123343_rename_companies_id_to_company_id_in_finances_table.php @@ -0,0 +1,28 @@ +renameColumn('companies_id', 'company_id'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('finances', function (Blueprint $table) { + $table->renameColumn('company_id', 'companies_id'); + }); + } +}; diff --git a/database/migrations/2024_09_27_131146_drop_reports_table.php b/database/migrations/2024_09_27_131146_drop_reports_table.php new file mode 100644 index 0000000..feb4dc0 --- /dev/null +++ b/database/migrations/2024_09_27_131146_drop_reports_table.php @@ -0,0 +1,25 @@ + $clientDetails, 'company' => $company->id]) }}" method="POST" class="pull-right"> +