Skip to content

Commit

Permalink
Merge pull request #40 from kamgrzeski/migrate_laravel_10
Browse files Browse the repository at this point in the history
Migrate to Laravel 10
  • Loading branch information
kamgrzeski authored Sep 11, 2024
2 parents 6e4b6a6 + 45bc205 commit 6ad0b8d
Show file tree
Hide file tree
Showing 125 changed files with 4,263 additions and 5,417 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
use App\Http\Requests\ChangePasswordRequest;
use App\Http\Requests\LoginAdminRequest;
use App\Jobs\ChangePasswordJob;
use Illuminate\Support\Facades\Hash;

/**
* Class AdminController
*
* Controller for handling admin-related operations in the CRM.
*/
class AdminController extends Controller
class AuthController extends Controller
{
/**
* Show the login form for admin.
Expand All @@ -22,7 +23,7 @@ class AdminController extends Controller
public function showLoginForm(): \Illuminate\View\View
{
// Render the login form.
return view('admin.login');
return view('crm.auth.login');
}

/**
Expand All @@ -37,7 +38,7 @@ public function processLoginAdmin(LoginAdminRequest $request)
if (auth()->attempt($request->validated())) {
return redirect()->to('/');
} else {
return redirect()->back()->with('message-error', 'Wrong email or password!');
return redirect()->back()->with('message_error', 'Wrong email or password!');
}
}

Expand All @@ -63,7 +64,7 @@ public function logout(): \Illuminate\Http\RedirectResponse
public function renderChangePasswordView(): \Illuminate\View\View
{
// Render the change password view.
return view('admin.passwords.reset');
return view('crm.auth.passwords.reset');
}

/**
Expand All @@ -77,8 +78,18 @@ public function processChangePassword(ChangePasswordRequest $request): \Illumina
// Get validated data.
$validatedData = $request->validated();

// Check if old password is correct.
if (!Hash::check($validatedData['old_password'], auth()->user()->password)) {
return redirect()->to('password/reset')->with('message_danger', 'Old password is incorrect.');
}

// Check if new password and confirm password match.
if ($validatedData['new_password'] !== $validatedData['confirm_password']) {
return redirect()->to('password/reset')->with('message_danger', 'New password and confirm password do not match.');
}

// Dispatch job to change password.
$this->dispatchSync(new ChangePasswordJob($validatedData['old_password'], $validatedData['new_password'], $validatedData['confirm_password'], auth()->user()));
$this->dispatchSync(new ChangePasswordJob($validatedData, auth()->user()));

// Redirect to change password page.
return redirect()->to('password/reset')->with('message_success', 'Your password has been changed.');
Expand Down
21 changes: 6 additions & 15 deletions app/Http/Controllers/CRM/ClientController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use App\Jobs\Client\UpdateClientJob;
use App\Jobs\StoreSystemLogJob;
use App\Models\ClientsModel;
use App\Queries\ClientsQueries;
use App\Services\ClientService;
use Illuminate\Foundation\Bus\DispatchesJobs;

Expand Down Expand Up @@ -42,7 +43,7 @@ public function __construct(ClientService $clientService)
public function processRenderCreateForm(): \Illuminate\View\View
{
// Return the view for creating a new client record.
return view('crm.client.create');
return view('crm.clients.create');
}

/**
Expand All @@ -54,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.client.show')->with(['clientDetails' => $this->clientService->loadClientDetails($client)]);
return view('crm.clients.show')->with(['clientDetails' => $this->clientService->loadClientDetails($client)]);
}

/**
Expand All @@ -66,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.client.edit')->with(['clientDetails' => $this->clientService->loadClientDetails($client)]);
return view('crm.clients.edit')->with(['clientDetails' => $this->clientService->loadClientDetails($client)]);
}

/**
Expand All @@ -77,8 +78,8 @@ public function processRenderUpdateForm(ClientsModel $client): \Illuminate\View\
public function processListOfClients(): \Illuminate\View\View
{
// Return the view with the paginated list of clients.
return view('crm.client.index')->with([
'clientsPaginate' => $this->clientService->loadPagination()
return view('crm.clients.index')->with([
'clients' => ClientsQueries::getPaginate()
]);
}

Expand Down Expand Up @@ -127,16 +128,6 @@ public function processUpdateClient(ClientUpdateRequest $request, ClientsModel $
*/
public function processDeleteClient(ClientsModel $client): \Illuminate\Http\RedirectResponse
{
// Check if the client has companies or employees.
if ($client->companies()->count() > 0) {
return redirect()->back()->with('message_danger', $this->getMessage('messages.first_delete_companies'));
}

// Check if the client has employees.
if ($client->employees()->count() > 0) {
return redirect()->back()->with('message_danger', $this->getMessage('messages.first_delete_employees'));
}

// Delete the client model.
$client->delete();

Expand Down
7 changes: 4 additions & 3 deletions app/Http/Controllers/CRM/CompaniesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use App\Jobs\StoreSystemLogJob;
use App\Models\CompaniesModel;
use App\Queries\ClientsQueries;
use App\Queries\CompaniesQueries;
use App\Services\CompaniesService;
use App\Services\DealsService;
use Illuminate\Foundation\Bus\DispatchesJobs;
Expand Down Expand Up @@ -47,7 +48,7 @@ public function __construct(CompaniesService $companiesService, DealsService $de
public function processRenderCreateForm(): \Illuminate\View\View
{
// Return view with clients.
return view('crm.companies.create')->with(['dataWithPluckOfClient' => ClientsQueries::getAll()]);
return view('crm.companies.create')->with(['clients' => ClientsQueries::getAll()]);
}

/**
Expand All @@ -71,7 +72,7 @@ public function processListOfCompanies(): \Illuminate\View\View
{
// Return view with companies pagination.
return view('crm.companies.index')->with([
'companiesPaginate' => $this->companiesService->loadPagination()
'companies' => CompaniesQueries::getPaginate()
]);
}

Expand Down Expand Up @@ -137,7 +138,7 @@ public function processDeleteCompany(CompaniesModel $company): \Illuminate\Http\
{
// Check if company has deals.
if ($company->deals()->count() > 0) {
return redirect()->back()->with('message_danger', $this->getMessage('messages.first_delete_deals'));
return redirect()->back()->with('message_error', $this->getMessage('messages.first_delete_deals'));
}

// Delete company.
Expand Down
12 changes: 8 additions & 4 deletions app/Http/Controllers/CRM/DealsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use App\Models\DealsModel;
use App\Models\DealsTermsModel;
use App\Queries\CompaniesQueries;
use App\Queries\DealsQueries;
use App\Services\DealsService;
use Illuminate\Foundation\Bus\DispatchesJobs;

Expand Down Expand Up @@ -58,7 +59,10 @@ public function processRenderCreateForm(): \Illuminate\View\View
public function processShowDealsDetails(DealsModel $deal): \Illuminate\View\View
{
// Load the deal record details.
return view('crm.deals.show')->with(['deal' => $deal]);
return view('crm.deals.show')->with([
'deal' => $deal,
'companies' => CompaniesQueries::getAll()
]);
}

/**
Expand All @@ -70,7 +74,7 @@ public function processListOfDeals(): \Illuminate\View\View
{
// Load the deal records with pagination.
return view('crm.deals.index')->with([
'dealsPaginate' => $this->dealsService->loadPaginate()
'deals' => DealsQueries::getPaginate()
]);
}

Expand Down Expand Up @@ -136,7 +140,7 @@ public function processDeleteDeal(DealsModel $deal): \Illuminate\Http\RedirectRe
{
// Check if the deal has any deal terms.
if ($deal->dealTerms()->count() > 0) {
return redirect()->back()->with('message_danger', $this->getMessage('messages.deal_first_delete_deal|_term'));
return redirect()->back()->with('message_error', $this->getMessage('messages.deal_first_delete_deal|_term'));
}

// Delete the deal record.
Expand Down Expand Up @@ -166,7 +170,7 @@ public function processSetIsActive(DealsModel $deal, bool $value): \Illuminate\H
$this->dispatchSync(new StoreSystemLogJob('Deals has been enabled with id: ' . $deal->id, 201, auth()->user()));

// Redirect back with a success message.
return redirect()->to('deals')->with('message_success', $this->getMessage('messages.' . $value ? 'deal_update' : 'deal_update'));
return redirect()->to('deals')->with('message_success', $this->getMessage('messages.deal_update'));
}

/**
Expand Down
20 changes: 4 additions & 16 deletions app/Http/Controllers/CRM/EmployeesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
use App\Jobs\StoreSystemLogJob;
use App\Models\EmployeesModel;
use App\Queries\ClientsQueries;
use App\Services\ClientService;
use App\Services\EmployeesService;
use App\Queries\EmployeesQueries;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Bus\DispatchesJobs;

Expand All @@ -22,21 +21,10 @@
class EmployeesController extends Controller
{
use DispatchesJobs;
private EmployeesService $employeesService;
private ClientService $clientService;

/**
* EmployeesController constructor.
*
* @param EmployeesService $employeesService
* @param ClientService $clientService
*/
public function __construct(EmployeesService $employeesService, ClientService $clientService)
public function __construct()
{
$this->middleware(self::MIDDLEWARE_AUTH);

$this->employeesService = $employeesService;
$this->clientService = $clientService;
}

/**
Expand Down Expand Up @@ -71,7 +59,7 @@ public function processListOfEmployees(): \Illuminate\View\View
{
// Load the employee records and render the list page.
return view('crm.employees.index')->with([
'employeesPaginate' => $this->employeesService->loadPaginate()
'employees' => EmployeesQueries::getPaginate()
]);
}

Expand Down Expand Up @@ -137,7 +125,7 @@ public function processDeleteEmployee(EmployeesModel $employee): \Illuminate\Htt
{
// Check if the employee has any tasks assigned.
if ($employee->tasks()->count() > 0) {
return redirect()->back()->with('message_danger', $this->getMessage('messages.task_delete_tasks'));
return redirect()->back()->with('message_error', $this->getMessage('messages.task_delete_tasks'));
}

// Dispatch the job to delete the employee record.
Expand Down
26 changes: 4 additions & 22 deletions app/Http/Controllers/CRM/FinancesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
use App\Jobs\Finance\UpdateFinanceJob;
use App\Jobs\StoreSystemLogJob;
use App\Models\FinancesModel;
use App\Queries\CompaniesQueries;
use App\Queries\FinancesQueries;
use App\Services\CompaniesService;
use App\Services\FinancesService;
use Illuminate\Foundation\Bus\DispatchesJobs;

/**
Expand All @@ -23,23 +22,6 @@ class FinancesController extends Controller
{
use DispatchesJobs;

private FinancesService $financesService;
private CompaniesService $companiesService;

/**
* FinancesController constructor.
*
* @param FinancesService $financesService
* @param CompaniesService $companiesService
*/
public function __construct(FinancesService $financesService, CompaniesService $companiesService)
{
$this->middleware(self::MIDDLEWARE_AUTH);

$this->financesService = $financesService;
$this->companiesService = $companiesService;
}

/**
* Render the form for creating a new finance record.
*
Expand All @@ -48,7 +30,7 @@ public function __construct(FinancesService $financesService, CompaniesService $
public function processRenderCreateForm()
{
// Return the view with the companies.
return view('crm.finances.create')->with(['dataWithPluckOfCompanies' => $this->companiesService->loadCompanies(true)]);
return view('crm.finances.create')->with(['companies' => CompaniesQueries::getAll(true)]);
}

/**
Expand All @@ -72,7 +54,7 @@ public function processListOfFinances()
{
// Return the view with the finances and the pagination.
return view('crm.finances.index')->with([
'financesPaginate' => FinancesQueries::getPaginate()
'finances' => FinancesQueries::getPaginate()
]);
}

Expand All @@ -87,7 +69,7 @@ public function processRenderUpdateForm(FinancesModel $finance)
// Return the view with the finance record and the companies.
return view('crm.finances.edit')->with([
'finance' => $finance,
'dataWithPluckOfCompanies' => $this->companiesService->loadCompanies(true)
'companies' => CompaniesQueries::getAll(true)
]);
}

Expand Down
5 changes: 3 additions & 2 deletions app/Http/Controllers/CRM/ProductsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use App\Jobs\Product\UpdateProductJob;
use App\Jobs\StoreSystemLogJob;
use App\Models\ProductsModel;
use App\Queries\ProductsQueries;
use App\Services\ProductsService;
use Illuminate\Foundation\Bus\DispatchesJobs;

Expand Down Expand Up @@ -78,7 +79,7 @@ public function processListOfProducts(): \Illuminate\View\View
{
// Load the products with pagination.
return view('crm.products.index')->with([
'productsPaginate' => $this->productsService->loadPagination()
'products' => ProductsQueries::getPaginate()
]);
}

Expand Down Expand Up @@ -129,7 +130,7 @@ public function processDeleteProduct(ProductsModel $product): \Illuminate\Http\R
{
// Check if the product has any sales records.
if ($product->sales()->count() > 0) {
return redirect()->back()->with('message_danger', $this->getMessage('messages.ProductsCannotBeDeleted'));
return redirect()->back()->with('message_error', $this->getMessage('messages.product_first_delete_sales'));
}

// Delete the product.
Expand Down
9 changes: 5 additions & 4 deletions app/Http/Controllers/CRM/SalesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use App\Jobs\Sale\UpdateSaleJob;
use App\Jobs\StoreSystemLogJob;
use App\Models\SalesModel;
use App\Queries\ProductsQueries;
use App\Queries\SalesQueries;
use App\Services\ProductsService;
use App\Services\SalesService;
use Illuminate\Foundation\Bus\DispatchesJobs;
Expand Down Expand Up @@ -46,7 +48,7 @@ public function __construct(SalesService $salesService, ProductsService $product
public function processRenderCreateForm(): \Illuminate\View\View
{
// Load the products data to be used in the form.
return view('crm.sales.create')->with(['dataOfProducts' => $this->productsService->loadProducts()]);
return view('crm.sales.create')->with(['products' => ProductsQueries::getAll()]);
}

/**
Expand All @@ -72,7 +74,7 @@ public function processRenderUpdateForm(SalesModel $sale): \Illuminate\View\View
// Load the sale record details and the products data to be used in the form.
return view('crm.sales.edit')->with([
'sale' => $sale,
'dataWithPluckOfProducts' => $this->productsService->loadProducts()
'products' => ProductsQueries::getAll()
]);
}

Expand All @@ -85,8 +87,7 @@ public function processListOfSales(): \Illuminate\View\View
{
// Load the sale records with pagination.
return view('crm.sales.index')->with([
'sales' => $this->salesService->loadSales(),
'salesPaginate' => $this->salesService->loadPaginate()
'sales' => SalesQueries::getPaginate()
]);
}

Expand Down
Loading

0 comments on commit 6ad0b8d

Please sign in to comment.