mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-09-02 05:10:59 +00:00
chore(catalog,contacts): remove legacy-era catalog and contacts sources
This commit is contained in:
@@ -1,37 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Contacts\Http\Controllers\Company;
|
||||
|
||||
use App\Domains\Contacts\Contracts\CustomerStatsProvider;
|
||||
use App\Domains\Contacts\Http\Resources\CustomerResource;
|
||||
use App\Domains\Contacts\Models\Customer;
|
||||
use App\Domains\Reporting\Queries\CustomerStatementQuery;
|
||||
use App\Platform\Http\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CustomerStatsController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly CustomerStatsProvider $customerStatsProvider,
|
||||
private readonly CustomerStatementQuery $customerStatementQuery,
|
||||
) {}
|
||||
|
||||
public function __invoke(Request $request, Customer $customer)
|
||||
{
|
||||
$this->authorize('view', $customer);
|
||||
|
||||
$chartData = $this->customerStatsProvider->get(
|
||||
$customer,
|
||||
$request->header('company'),
|
||||
$request->has('previous_year')
|
||||
);
|
||||
|
||||
$customer = Customer::find($customer->id);
|
||||
$this->customerStatementQuery->hydrateAccountSummaries([$customer]);
|
||||
|
||||
return (new CustomerResource($customer))
|
||||
->additional(['meta' => [
|
||||
'chartData' => $chartData,
|
||||
]]);
|
||||
}
|
||||
}
|
||||
@@ -1,126 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Contacts\Http\Controllers\Company;
|
||||
|
||||
use App\Domains\Contacts\Application\CustomerService;
|
||||
use App\Domains\Contacts\Http\Requests\CustomerRequest;
|
||||
use App\Domains\Contacts\Http\Requests\DeleteCustomersRequest;
|
||||
use App\Domains\Contacts\Http\Resources\CustomerResource;
|
||||
use App\Domains\Contacts\Models\Customer;
|
||||
use App\Domains\Reporting\Queries\CustomerStatementQuery;
|
||||
use App\Platform\Http\Controller;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
|
||||
class CustomersController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly CustomerService $customerService,
|
||||
private readonly CustomerStatementQuery $customerStatementQuery,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$this->authorize('viewAny', Customer::class);
|
||||
|
||||
$limit = $request->has('limit') ? $request->limit : 10;
|
||||
|
||||
$customers = Customer::with('creator')
|
||||
->whereCompany()
|
||||
->applyFilters($request->all())
|
||||
->paginateData($limit);
|
||||
|
||||
$this->customerStatementQuery->hydrateAccountSummaries(
|
||||
$customers instanceof LengthAwarePaginator ? $customers->getCollection() : $customers
|
||||
);
|
||||
|
||||
return CustomerResource::collection($customers)
|
||||
->additional(['meta' => [
|
||||
'customer_total_count' => Customer::whereCompany()->count(),
|
||||
]]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function store(CustomerRequest $request)
|
||||
{
|
||||
$this->authorize('create', Customer::class);
|
||||
|
||||
$customer = $this->customerService->create(
|
||||
attributes: $request->customerAttributes(),
|
||||
shippingAddress: $request->shippingAddress(),
|
||||
billingAddress: $request->billingAddress(),
|
||||
customFields: $request->customFields(),
|
||||
);
|
||||
$this->customerStatementQuery->hydrateAccountSummaries([$customer]);
|
||||
|
||||
return new CustomerResource($customer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function show(Customer $customer)
|
||||
{
|
||||
$this->authorize('view', $customer);
|
||||
|
||||
$this->customerStatementQuery->hydrateAccountSummaries([$customer]);
|
||||
|
||||
return new CustomerResource($customer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function update(CustomerRequest $request, Customer $customer)
|
||||
{
|
||||
$this->authorize('update', $customer);
|
||||
|
||||
$customer = $this->customerService->update(
|
||||
customer: $customer,
|
||||
attributes: $request->customerAttributes(),
|
||||
shippingAddress: $request->shippingAddress(),
|
||||
billingAddress: $request->billingAddress(),
|
||||
customFields: $request->customFields(),
|
||||
);
|
||||
$this->customerStatementQuery->hydrateAccountSummaries([$customer]);
|
||||
|
||||
return new CustomerResource($customer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a list of Customers along side all their resources (ie. Estimates, Invoices, Payments and Addresses)
|
||||
*
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function delete(DeleteCustomersRequest $request)
|
||||
{
|
||||
$this->authorize('delete multiple customers');
|
||||
|
||||
$ids = Customer::whereCompany()
|
||||
->whereIn('id', $request->ids)
|
||||
->pluck('id');
|
||||
|
||||
$this->customerService->delete($ids);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Contacts\Http\Controllers;
|
||||
|
||||
use App\Domains\Contacts\Http\Resources\CountryResource;
|
||||
use App\Domains\Contacts\Models\Country;
|
||||
use App\Platform\Http\Controller;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CountriesController extends Controller
|
||||
{
|
||||
/**
|
||||
* Handle the incoming request.
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function __invoke(Request $request)
|
||||
{
|
||||
$countries = Country::all();
|
||||
|
||||
return CountryResource::collection($countries);
|
||||
}
|
||||
}
|
||||
-56
@@ -1,56 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Contacts\Http\Controllers\CustomerPortal\Auth;
|
||||
|
||||
use App\Platform\Http\Controller;
|
||||
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Password;
|
||||
|
||||
class ForgotPasswordController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Password Reset Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller is responsible for handling password reset emails and
|
||||
| includes a trait which assists in sending these notifications from
|
||||
| your application to your users. Feel free to explore this trait.
|
||||
|
|
||||
*/
|
||||
|
||||
use SendsPasswordResetEmails;
|
||||
|
||||
public function broker()
|
||||
{
|
||||
return Password::broker('customers');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the response for a successful password reset link.
|
||||
*
|
||||
* @param string $response
|
||||
* @return RedirectResponse|JsonResponse
|
||||
*/
|
||||
protected function sendResetLinkResponse(Request $request, $response)
|
||||
{
|
||||
return response()->json([
|
||||
'message' => 'Password reset email sent.',
|
||||
'data' => $response,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the response for a failed password reset link.
|
||||
*
|
||||
* @param string $response
|
||||
* @return RedirectResponse|JsonResponse
|
||||
*/
|
||||
protected function sendResetLinkFailedResponse(Request $request, $response)
|
||||
{
|
||||
return response('Email could not be sent to this email address.', 403);
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Contacts\Http\Controllers\CustomerPortal\Auth;
|
||||
|
||||
use App\Domains\Accounts\Models\Company;
|
||||
use App\Domains\Contacts\Http\Requests\CustomerPortal\CustomerLoginRequest;
|
||||
use App\Domains\Contacts\Models\Customer;
|
||||
use App\Platform\Http\Controller;
|
||||
use Hash;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class LoginController extends Controller
|
||||
{
|
||||
/**
|
||||
* Handle the incoming request.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function __invoke(CustomerLoginRequest $request, Company $company)
|
||||
{
|
||||
$user = Customer::whereRaw('LOWER(email) = ?', [strtolower($request->email)])
|
||||
->where('company_id', $company->id)
|
||||
->first();
|
||||
|
||||
if (! $user || ! Hash::check($request->password, $user->password)) {
|
||||
throw ValidationException::withMessages([
|
||||
'email' => ['The provided credentials are incorrect.'],
|
||||
]);
|
||||
}
|
||||
|
||||
if (! $user->enable_portal) {
|
||||
throw ValidationException::withMessages([
|
||||
'email' => ['Customer portal not available for this user.'],
|
||||
]);
|
||||
}
|
||||
|
||||
Auth::guard('customer')->login($user);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Contacts\Http\Controllers\CustomerPortal\Auth;
|
||||
|
||||
use App\Platform\Http\Controller;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Illuminate\Auth\Events\PasswordReset;
|
||||
use Illuminate\Contracts\Auth\CanResetPassword;
|
||||
use Illuminate\Foundation\Auth\ResetsPasswords;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Str;
|
||||
use Password;
|
||||
|
||||
class ResetPasswordController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Password Reset Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller is responsible for handling password reset requests
|
||||
| and uses a simple trait to include this behavior. You're free to
|
||||
| explore this trait and override any methods you wish to tweak.
|
||||
|
|
||||
*/
|
||||
|
||||
use ResetsPasswords;
|
||||
|
||||
/**
|
||||
* Where to redirect users after resetting their password.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $redirectTo = RouteServiceProvider::CUSTOMER_HOME;
|
||||
|
||||
public function broker()
|
||||
{
|
||||
return Password::broker('customers');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the response for a successful password reset.
|
||||
*
|
||||
* @param string $response
|
||||
* @return RedirectResponse|JsonResponse
|
||||
*/
|
||||
protected function sendResetResponse(Request $request, $response)
|
||||
{
|
||||
return response()->json([
|
||||
'message' => 'Password reset successfully.',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the given user's password.
|
||||
*
|
||||
* @param CanResetPassword $user
|
||||
* @param string $password
|
||||
* @return void
|
||||
*/
|
||||
protected function resetPassword($user, $password)
|
||||
{
|
||||
$user->password = $password;
|
||||
|
||||
$user->setRememberToken(Str::random(60));
|
||||
|
||||
$user->save();
|
||||
|
||||
event(new PasswordReset($user));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the response for a failed password reset.
|
||||
*
|
||||
* @param string $response
|
||||
* @return RedirectResponse|JsonResponse
|
||||
*/
|
||||
protected function sendResetFailedResponse(Request $request, $response)
|
||||
{
|
||||
return response('Failed, Invalid Token.', 403);
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Contacts\Http\Controllers\CustomerPortal;
|
||||
|
||||
use App\Domains\Accounts\Models\CompanySetting;
|
||||
use App\Domains\Contacts\Http\Resources\CustomerPortal\CustomerResource;
|
||||
use App\Domains\Money\Models\Currency;
|
||||
use App\Platform\Http\Controller;
|
||||
use App\Platform\Modules\Models\Module;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class BootstrapController extends Controller
|
||||
{
|
||||
/**
|
||||
* Handle the incoming request.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function __invoke(Request $request)
|
||||
{
|
||||
$customer = Auth::guard('customer')->user();
|
||||
|
||||
foreach (\Menu::get('customer_portal_menu')->items->toArray() as $data) {
|
||||
if ($customer) {
|
||||
$menu[] = [
|
||||
'title' => $data->title,
|
||||
'link' => $data->link->path['url'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$companyCurrencyId = CompanySetting::getSetting('currency', $customer->company_id);
|
||||
|
||||
return (new CustomerResource($customer))
|
||||
->additional(['meta' => [
|
||||
'menu' => $menu,
|
||||
'current_customer_currency' => Currency::find($customer->currency_id),
|
||||
'current_company_currency' => $companyCurrencyId ? Currency::find($companyCurrencyId) : null,
|
||||
'modules' => Module::where('enabled', true)->pluck('name'),
|
||||
'current_company_language' => CompanySetting::getSetting('language', $customer->company_id),
|
||||
]]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user