From 4f360412cd01f52dfa2c15fa3fc24acb903554cc Mon Sep 17 00:00:00 2001 From: Kamil Grzechulski Date: Fri, 27 Sep 2024 16:27:53 +0200 Subject: [PATCH] feat: code refactor and optimize includes relation changes --- app/Http/Controllers/CRM/ClientController.php | 9 ++-- .../Controllers/CRM/CompaniesController.php | 5 +- app/Http/Controllers/CRM/DealsController.php | 5 +- .../Controllers/CRM/EmployeesController.php | 5 +- .../Controllers/CRM/FinancesController.php | 5 +- .../Controllers/CRM/ProductsController.php | 5 +- app/Http/Controllers/CRM/SalesController.php | 5 +- app/Http/Controllers/CRM/TasksController.php | 10 ++-- app/Models/ClientsModel.php | 14 ++---- app/Models/CompaniesModel.php | 26 ++-------- app/Models/DealsModel.php | 14 ++---- app/Models/EmployeesModel.php | 26 ++-------- app/Models/FinancesModel.php | 8 +-- app/Models/ProductsModel.php | 8 +-- app/Models/SalesModel.php | 8 +-- app/Models/TasksModel.php | 8 +-- app/Relations/Belongs/BelongsToClient.php | 16 ++++++ app/Relations/Belongs/BelongsToCompany.php | 17 +++++++ app/Relations/Belongs/BelongsToDeal.php | 16 ++++++ app/Relations/Belongs/BelongsToEmployee.php | 16 ++++++ app/Relations/Belongs/BelongsToProduct.php | 16 ++++++ app/Relations/Has/HasManyCompanies.php | 14 ++++++ app/Relations/Has/HasManyDealTerms.php | 17 +++++++ app/Relations/Has/HasManyDeals.php | 18 +++++++ app/Relations/Has/HasManyEmployees.php | 18 +++++++ app/Relations/Has/HasManyFinances.php | 19 +++++++ app/Relations/Has/HasManySales.php | 15 ++++++ app/Relations/Has/HasManyTasks.php | 15 ++++++ app/Services/EmployeesService.php | 8 +-- ...panies_id_to_company_id_in_deals_table.php | 28 +++++++++++ ...ies_id_to_company_id_in_finances_table.php | 28 +++++++++++ .../2024_09_27_131146_drop_reports_table.php | 25 ++++++++++ .../delete_client_company_form.blade.php | 2 +- .../forms/delete_client_form.blade.php | 2 +- .../forms/update_client_form.blade.php | 34 ++++++------- resources/views/crm/clients/index.blade.php | 20 +++----- resources/views/crm/clients/show.blade.php | 24 ++++----- .../views/crm/companies/create.blade.php | 2 +- resources/views/crm/companies/index.blade.php | 42 +++++++--------- resources/views/crm/companies/show.blade.php | 2 +- resources/views/crm/dashboard/index.blade.php | 12 ++--- resources/views/crm/deals/create.blade.php | 2 +- resources/views/crm/deals/index.blade.php | 32 ++++++------ resources/views/crm/deals/show.blade.php | 26 +++++----- .../views/crm/employees/create.blade.php | 2 +- resources/views/crm/employees/index.blade.php | 36 ++++++------- resources/views/crm/employees/show.blade.php | 4 +- resources/views/crm/finances/create.blade.php | 2 +- resources/views/crm/finances/index.blade.php | 42 +++++++--------- resources/views/crm/finances/show.blade.php | 2 +- resources/views/crm/products/index.blade.php | 37 ++++++-------- resources/views/crm/sales/index.blade.php | 37 ++++++-------- resources/views/crm/sales/show.blade.php | 2 +- resources/views/crm/settings/index.blade.php | 14 +++--- resources/views/crm/tasks/create.blade.php | 2 +- resources/views/crm/tasks/index.blade.php | 44 ++++++++-------- resources/views/crm/tasks/show.blade.php | 2 +- .../views/layouts/template/body.blade.php | 2 +- .../views/layouts/template/menu.blade.php | 2 +- .../views/layouts/template/navbar.blade.php | 8 +-- routes/web.php | 50 +++++++++---------- 61 files changed, 553 insertions(+), 382 deletions(-) create mode 100644 app/Relations/Belongs/BelongsToClient.php create mode 100644 app/Relations/Belongs/BelongsToCompany.php create mode 100644 app/Relations/Belongs/BelongsToDeal.php create mode 100644 app/Relations/Belongs/BelongsToEmployee.php create mode 100644 app/Relations/Belongs/BelongsToProduct.php create mode 100644 app/Relations/Has/HasManyCompanies.php create mode 100644 app/Relations/Has/HasManyDealTerms.php create mode 100644 app/Relations/Has/HasManyDeals.php create mode 100644 app/Relations/Has/HasManyEmployees.php create mode 100644 app/Relations/Has/HasManyFinances.php create mode 100644 app/Relations/Has/HasManySales.php create mode 100644 app/Relations/Has/HasManyTasks.php create mode 100644 database/migrations/2024_09_27_122828_rename_companies_id_to_company_id_in_deals_table.php create mode 100644 database/migrations/2024_09_27_123343_rename_companies_id_to_company_id_in_finances_table.php create mode 100644 database/migrations/2024_09_27_131146_drop_reports_table.php 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"> +
@csrf @method('DELETE') diff --git a/resources/views/crm/clients/forms/delete_client_form.blade.php b/resources/views/crm/clients/forms/delete_client_form.blade.php index eb06e22..b292dfb 100644 --- a/resources/views/crm/clients/forms/delete_client_form.blade.php +++ b/resources/views/crm/clients/forms/delete_client_form.blade.php @@ -1,4 +1,4 @@ - + @csrf @method('DELETE') diff --git a/resources/views/crm/clients/forms/update_client_form.blade.php b/resources/views/crm/clients/forms/update_client_form.blade.php index e59d42a..b354449 100644 --- a/resources/views/crm/clients/forms/update_client_form.blade.php +++ b/resources/views/crm/clients/forms/update_client_form.blade.php @@ -1,69 +1,69 @@
- + @csrf @method('PUT')
- +
- +
- +
- +
- +
- +
- +
- +
diff --git a/resources/views/crm/clients/index.blade.php b/resources/views/crm/clients/index.blade.php index b41bc70..af55397 100644 --- a/resources/views/crm/clients/index.blade.php +++ b/resources/views/crm/clients/index.blade.php @@ -11,7 +11,7 @@
@include('layouts.template.messages') - +

@@ -44,24 +44,20 @@ - @if($client->is_active) + + @csrf - @else - - @endif +
- More information + More information diff --git a/resources/views/crm/clients/show.blade.php b/resources/views/crm/clients/show.blade.php index ae916e6..7b10de3 100644 --- a/resources/views/crm/clients/show.blade.php +++ b/resources/views/crm/clients/show.blade.php @@ -1,8 +1,8 @@ @extends('layouts.base') -@section('caption', 'Information about client: ' . $clientDetails->full_name) +@section('caption', 'Information about client: ' . $client->full_name) -@section('title', 'Information about client: ' . $clientDetails->full_name) +@section('title', 'Information about client: ' . $client->full_name) @section('content')
@@ -15,10 +15,10 @@
  • Basic information
  • - Assigned companies {{ count($clientDetails->companies) }} + Assigned companies {{ count($client->companies) }}
  • - Assigned employees {{ count($clientDetails->employees) }} + Assigned employees {{ count($client->employees) }}
  • + Status - {{ $clientDetails->is_active ? 'Active' : 'Deactivate' }} + {{ $client->is_active ? 'Active' : 'Deactivate' }} @@ -72,7 +72,7 @@ Tax number - @foreach($clientDetails->companies as $company) + @foreach($client->companies as $company) {{ $company->name }} @@ -94,7 +94,7 @@ Job - @foreach($clientDetails->employees as $employees) + @foreach($client->employees as $employees) {{ $employees->full_name }} diff --git a/resources/views/crm/companies/create.blade.php b/resources/views/crm/companies/create.blade.php index a5e6148..56c4c30 100644 --- a/resources/views/crm/companies/create.blade.php +++ b/resources/views/crm/companies/create.blade.php @@ -9,7 +9,7 @@ @section('content') @if(count($clients) == 0)
    - Danger! There is no in system. Please create any client. Click here! + Danger! There is no in system. Please create any client. Click here!
    @endif diff --git a/resources/views/crm/companies/index.blade.php b/resources/views/crm/companies/index.blade.php index c716640..f7f7344 100644 --- a/resources/views/crm/companies/index.blade.php +++ b/resources/views/crm/companies/index.blade.php @@ -10,7 +10,7 @@
    @include('layouts.template.messages') - +

    @@ -35,38 +35,32 @@ - @foreach($companies as $key => $value) + @foreach($companies as $key => $company) - - {{ $value->name }} - {{ $value->phone }} - {{ $value->city }} - {{ $value->country }} - {{ $value->employees_size }} - {{ $value->tax_number }} + {{ $company->name }} + {{ $company->phone }} + {{ $company->city }} + {{ $company->country }} + {{ $company->employees_size }} + {{ $company->tax_number }} - {{ $value->client->full_name }} + {{ $company->client->full_name }} - @if($value->is_active) - - @else - - @endif +
    + @csrf + +
    - More information + More information diff --git a/resources/views/crm/companies/show.blade.php b/resources/views/crm/companies/show.blade.php index 2a487fe..24e0a2b 100644 --- a/resources/views/crm/companies/show.blade.php +++ b/resources/views/crm/companies/show.blade.php @@ -64,7 +64,7 @@ Assigned client - {{ $company->client->full_name }} + {{ $company->client->full_name }} diff --git a/resources/views/crm/dashboard/index.blade.php b/resources/views/crm/dashboard/index.blade.php index d62f211..8e7bc0d 100644 --- a/resources/views/crm/dashboard/index.blade.php +++ b/resources/views/crm/dashboard/index.blade.php @@ -95,7 +95,7 @@
    @if(count($dataWithAllTasks) > 0) @foreach ($dataWithAllTasks as $result) - + {{ $result['created_at']->diffForHumans() }}
    @@ -122,7 +122,7 @@
    @if(count($dataWithAllCompanies) > 0) @foreach ($dataWithAllCompanies as $result) - + {{ $result->name }} Phone: {{ $result->phone }} @@ -133,7 +133,7 @@ @endif
    @@ -148,7 +148,7 @@
    @if(count($dataWithAllProducts) > 0) @foreach ($dataWithAllProducts as $result) - + {{ $result->created_at->diffForHumans() }} @@ -163,7 +163,7 @@ @endif
    diff --git a/resources/views/crm/deals/create.blade.php b/resources/views/crm/deals/create.blade.php index 8cf535c..6c8a51d 100644 --- a/resources/views/crm/deals/create.blade.php +++ b/resources/views/crm/deals/create.blade.php @@ -9,7 +9,7 @@ @section('content') @if(count($companies) == 0)
    - Danger! There is no company in system. Please create one. Click here! + Danger! There is no company in system. Please create one. Click here!
    @endif diff --git a/resources/views/crm/deals/index.blade.php b/resources/views/crm/deals/index.blade.php index 974eb5a..d17444c 100644 --- a/resources/views/crm/deals/index.blade.php +++ b/resources/views/crm/deals/index.blade.php @@ -11,7 +11,7 @@
    @include('layouts.template.messages') - +

    @@ -33,33 +33,29 @@ - @foreach($deals as $key => $value) + @foreach($deals as $key => $deal) - {{ $value->name }} + {{ $deal->name }} - {{ $value->companies->name }} + {{ $deal->company->name }} - {{ $value->start_time }} - {{ $value->end_time }} + {{ $deal->start_time }} + {{ $deal->end_time }} - @if($value->is_active) -