mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-09-02 21:31:01 +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),
|
||||
]]);
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Contacts\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class CustomerPortalMiddleware
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param Closure(Request): (\Illuminate\Http\Response|RedirectResponse) $next
|
||||
* @return \Illuminate\Http\Response|RedirectResponse
|
||||
*/
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
$user = Auth::guard('customer')->user();
|
||||
|
||||
if (! $user->enable_portal) {
|
||||
Auth::guard('customer')->logout();
|
||||
|
||||
return response('Unauthorized.', 401);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Contacts\Http\Requests\CustomerPortal;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class CustomerLoginRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'email' => [
|
||||
'required',
|
||||
'string',
|
||||
],
|
||||
'password' => [
|
||||
'required',
|
||||
'string',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,143 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Contacts\Http\Requests\CustomerPortal;
|
||||
|
||||
use App\Domains\Contacts\Models\Address;
|
||||
use App\Rules\IdnEmail;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class CustomerProfileRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => [
|
||||
'nullable',
|
||||
],
|
||||
'password' => [
|
||||
'nullable',
|
||||
'min:8',
|
||||
],
|
||||
'email' => [
|
||||
'nullable',
|
||||
new IdnEmail,
|
||||
Rule::unique('customers')->where('company_id', $this->header('company'))->ignore(Auth::id(), 'id'),
|
||||
],
|
||||
'billing.name' => [
|
||||
'nullable',
|
||||
],
|
||||
'billing.address_street_1' => [
|
||||
'nullable',
|
||||
],
|
||||
'billing.address_street_2' => [
|
||||
'nullable',
|
||||
],
|
||||
'billing.city' => [
|
||||
'nullable',
|
||||
],
|
||||
'billing.state' => [
|
||||
'nullable',
|
||||
],
|
||||
'billing.country_id' => [
|
||||
'nullable',
|
||||
],
|
||||
'billing.zip' => [
|
||||
'nullable',
|
||||
],
|
||||
'billing.phone' => [
|
||||
'nullable',
|
||||
],
|
||||
'billing.fax' => [
|
||||
'nullable',
|
||||
],
|
||||
'shipping.name' => [
|
||||
'nullable',
|
||||
],
|
||||
'shipping.address_street_1' => [
|
||||
'nullable',
|
||||
],
|
||||
'shipping.address_street_2' => [
|
||||
'nullable',
|
||||
],
|
||||
'shipping.city' => [
|
||||
'nullable',
|
||||
],
|
||||
'shipping.state' => [
|
||||
'nullable',
|
||||
],
|
||||
'shipping.country_id' => [
|
||||
'nullable',
|
||||
],
|
||||
'shipping.zip' => [
|
||||
'nullable',
|
||||
],
|
||||
'shipping.phone' => [
|
||||
'nullable',
|
||||
],
|
||||
'shipping.fax' => [
|
||||
'nullable',
|
||||
],
|
||||
'customer_avatar' => [
|
||||
'nullable',
|
||||
'file',
|
||||
'mimes:gif,jpg,png',
|
||||
'max:20000',
|
||||
],
|
||||
'is_customer_avatar_removed' => [
|
||||
'nullable',
|
||||
'boolean',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
public function customerAttributes(): array
|
||||
{
|
||||
return $this->safe()->only(['name', 'email', 'password']);
|
||||
}
|
||||
|
||||
/** @return array<string, mixed>|null */
|
||||
public function shippingAddress(): ?array
|
||||
{
|
||||
$address = $this->input('shipping');
|
||||
|
||||
if (! is_array($address)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return collect($address)
|
||||
->merge([
|
||||
'type' => Address::SHIPPING_TYPE,
|
||||
])
|
||||
->toArray();
|
||||
}
|
||||
|
||||
/** @return array<string, mixed>|null */
|
||||
public function billingAddress(): ?array
|
||||
{
|
||||
$address = $this->input('billing');
|
||||
|
||||
if (! is_array($address)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return collect($address)
|
||||
->merge([
|
||||
'type' => Address::BILLING_TYPE,
|
||||
])
|
||||
->toArray();
|
||||
}
|
||||
}
|
||||
@@ -1,200 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Contacts\Http\Requests;
|
||||
|
||||
use App\Domains\Contacts\Models\Address;
|
||||
use App\Rules\IdnEmail;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class CustomerRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
$rules = [
|
||||
'name' => [
|
||||
'required',
|
||||
],
|
||||
'email' => [
|
||||
new IdnEmail,
|
||||
'nullable',
|
||||
Rule::unique('customers')->where('company_id', $this->header('company')),
|
||||
],
|
||||
'password' => [
|
||||
'nullable',
|
||||
],
|
||||
'phone' => [
|
||||
'nullable',
|
||||
],
|
||||
'company_name' => [
|
||||
'nullable',
|
||||
],
|
||||
'contact_name' => [
|
||||
'nullable',
|
||||
],
|
||||
'website' => [
|
||||
'nullable',
|
||||
],
|
||||
'prefix' => [
|
||||
'nullable',
|
||||
],
|
||||
'tax_id' => [
|
||||
'nullable',
|
||||
],
|
||||
'enable_portal' => [
|
||||
'boolean',
|
||||
],
|
||||
'currency_id' => [
|
||||
'nullable',
|
||||
],
|
||||
'billing.name' => [
|
||||
'nullable',
|
||||
],
|
||||
'billing.address_street_1' => [
|
||||
'nullable',
|
||||
],
|
||||
'billing.address_street_2' => [
|
||||
'nullable',
|
||||
],
|
||||
'billing.city' => [
|
||||
'nullable',
|
||||
],
|
||||
'billing.state' => [
|
||||
'nullable',
|
||||
],
|
||||
'billing.country_id' => [
|
||||
'nullable',
|
||||
],
|
||||
'billing.zip' => [
|
||||
'nullable',
|
||||
],
|
||||
'billing.phone' => [
|
||||
'nullable',
|
||||
],
|
||||
'billing.fax' => [
|
||||
'nullable',
|
||||
],
|
||||
'shipping.name' => [
|
||||
'nullable',
|
||||
],
|
||||
'shipping.address_street_1' => [
|
||||
'nullable',
|
||||
],
|
||||
'shipping.address_street_2' => [
|
||||
'nullable',
|
||||
],
|
||||
'shipping.city' => [
|
||||
'nullable',
|
||||
],
|
||||
'shipping.state' => [
|
||||
'nullable',
|
||||
],
|
||||
'shipping.country_id' => [
|
||||
'nullable',
|
||||
],
|
||||
'shipping.zip' => [
|
||||
'nullable',
|
||||
],
|
||||
'shipping.phone' => [
|
||||
'nullable',
|
||||
],
|
||||
'shipping.fax' => [
|
||||
'nullable',
|
||||
],
|
||||
];
|
||||
|
||||
if ($this->isMethod('PUT') && $this->email != null) {
|
||||
$rules['email'] = [
|
||||
new IdnEmail,
|
||||
'nullable',
|
||||
Rule::unique('customers')->where('company_id', $this->header('company'))->ignore($this->route('customer')->id),
|
||||
];
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
public function customerAttributes(): array
|
||||
{
|
||||
return collect($this->validated())
|
||||
->only([
|
||||
'name',
|
||||
'email',
|
||||
'currency_id',
|
||||
'password',
|
||||
'phone',
|
||||
'prefix',
|
||||
'tax_id',
|
||||
'company_name',
|
||||
'contact_name',
|
||||
'website',
|
||||
'enable_portal',
|
||||
'estimate_prefix',
|
||||
'payment_prefix',
|
||||
'invoice_prefix',
|
||||
])
|
||||
->merge([
|
||||
'creator_id' => $this->user()->id,
|
||||
'company_id' => $this->header('company'),
|
||||
])
|
||||
->toArray();
|
||||
}
|
||||
|
||||
/** @return array<string, mixed>|null */
|
||||
public function shippingAddress(): ?array
|
||||
{
|
||||
$address = $this->input('shipping');
|
||||
|
||||
if (! is_array($address) || ! $this->hasAddress($address)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return collect($address)
|
||||
->merge([
|
||||
'type' => Address::SHIPPING_TYPE,
|
||||
])
|
||||
->toArray();
|
||||
}
|
||||
|
||||
/** @return array<string, mixed>|null */
|
||||
public function billingAddress(): ?array
|
||||
{
|
||||
$address = $this->input('billing');
|
||||
|
||||
if (! is_array($address) || ! $this->hasAddress($address)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return collect($address)
|
||||
->merge([
|
||||
'type' => Address::BILLING_TYPE,
|
||||
])
|
||||
->toArray();
|
||||
}
|
||||
|
||||
/** @return array<int, mixed>|null */
|
||||
public function customFields(): ?array
|
||||
{
|
||||
$customFields = $this->input('customFields');
|
||||
|
||||
return is_array($customFields) && $customFields !== [] ? $customFields : null;
|
||||
}
|
||||
|
||||
private function hasAddress(array $address): bool
|
||||
{
|
||||
return Arr::where($address, fn ($value): bool => isset($value)) !== [];
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Contacts\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class DeleteCustomersRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'ids' => [
|
||||
'required',
|
||||
],
|
||||
'ids.*' => [
|
||||
'required',
|
||||
Rule::exists('customers', 'id'),
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Contacts\Http\Resources;
|
||||
|
||||
use App\Domains\Accounts\Http\Resources\UserResource;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class AddressResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param Request $request
|
||||
*/
|
||||
public function toArray($request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'address_street_1' => $this->address_street_1,
|
||||
'address_street_2' => $this->address_street_2,
|
||||
'city' => $this->city,
|
||||
'state' => $this->state,
|
||||
'country_id' => $this->country_id,
|
||||
'zip' => $this->zip,
|
||||
'phone' => $this->phone,
|
||||
'fax' => $this->fax,
|
||||
'type' => $this->type,
|
||||
'user_id' => $this->user_id,
|
||||
'company_id' => $this->company_id,
|
||||
'customer_id' => $this->customer_id,
|
||||
'country' => $this->when($this->country()->exists(), function () {
|
||||
return new CountryResource($this->country);
|
||||
}),
|
||||
'user' => $this->when($this->user()->exists(), function () {
|
||||
return new UserResource($this->user);
|
||||
}),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Contacts\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class CountryResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param Request $request
|
||||
*/
|
||||
public function toArray($request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'code' => $this->code,
|
||||
'name' => $this->name,
|
||||
'phone_code' => $this->phone_code,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Contacts\Http\Resources\CustomerPortal;
|
||||
|
||||
use App\Domains\Accounts\Http\Resources\CustomerPortal\UserResource;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class AddressResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param Request $request
|
||||
*/
|
||||
public function toArray($request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'address_street_1' => $this->address_street_1,
|
||||
'address_street_2' => $this->address_street_2,
|
||||
'city' => $this->city,
|
||||
'state' => $this->state,
|
||||
'country_id' => $this->country_id,
|
||||
'zip' => $this->zip,
|
||||
'phone' => $this->phone,
|
||||
'fax' => $this->fax,
|
||||
'type' => $this->type,
|
||||
'user_id' => $this->user_id,
|
||||
'company_id' => $this->company_id,
|
||||
'customer_id' => $this->customer_id,
|
||||
'country' => $this->when($this->country()->exists(), function () {
|
||||
return new CountryResource($this->country);
|
||||
}),
|
||||
'user' => $this->when($this->user()->exists(), function () {
|
||||
return new UserResource($this->user);
|
||||
}),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Contacts\Http\Resources\CustomerPortal;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class CountryResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param Request $request
|
||||
*/
|
||||
public function toArray($request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'code' => $this->code,
|
||||
'name' => $this->name,
|
||||
'phonecode' => $this->phonecode,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Contacts\Http\Resources\CustomerPortal;
|
||||
|
||||
use App\Domains\Accounts\Http\Resources\CustomerPortal\CompanyResource;
|
||||
use App\Domains\Metadata\Http\Resources\CustomerPortal\CustomFieldValueResource;
|
||||
use App\Domains\Money\Http\Resources\CustomerPortal\CurrencyResource;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class CustomerResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param Request $request
|
||||
*/
|
||||
public function toArray($request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'email' => $this->email,
|
||||
'phone' => $this->phone,
|
||||
'contact_name' => $this->contact_name,
|
||||
'company_name' => $this->company_name,
|
||||
'website' => $this->website,
|
||||
'enable_portal' => $this->enable_portal,
|
||||
'currency_id' => $this->currency_id,
|
||||
'company_id' => $this->company_id,
|
||||
'facebook_id' => $this->facebook_id,
|
||||
'google_id' => $this->google_id,
|
||||
'github_id' => $this->github_id,
|
||||
'formatted_created_at' => $this->formattedCreatedAt,
|
||||
'avatar' => $this->avatar,
|
||||
'prefix' => $this->prefix,
|
||||
'tax_id' => $this->tax_id,
|
||||
'billing' => $this->when($this->billingAddress()->exists(), function () {
|
||||
return new AddressResource($this->billingAddress);
|
||||
}),
|
||||
'shipping' => $this->when($this->shippingAddress()->exists(), function () {
|
||||
return new AddressResource($this->shippingAddress);
|
||||
}),
|
||||
'fields' => $this->when($this->fields()->exists(), function () {
|
||||
return CustomFieldValueResource::collection($this->fields);
|
||||
}),
|
||||
'company' => $this->when($this->company()->exists(), function () {
|
||||
return new CompanyResource($this->company);
|
||||
}),
|
||||
'currency' => $this->when($this->currency()->exists(), function () {
|
||||
return new CurrencyResource($this->currency);
|
||||
}),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Contacts\Http\Resources;
|
||||
|
||||
use App\Domains\Accounts\Http\Resources\CompanyResource;
|
||||
use App\Domains\Metadata\Http\Resources\CustomFieldValueResource;
|
||||
use App\Domains\Money\Http\Resources\CurrencyResource;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class CustomerResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param Request $request
|
||||
*/
|
||||
public function toArray($request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'email' => $this->email,
|
||||
'phone' => $this->phone,
|
||||
'contact_name' => $this->contact_name,
|
||||
'company_name' => $this->company_name,
|
||||
'website' => $this->website,
|
||||
'enable_portal' => $this->enable_portal,
|
||||
'password_added' => $this->password ? true : false,
|
||||
'currency_id' => $this->currency_id,
|
||||
'company_id' => $this->company_id,
|
||||
'facebook_id' => $this->facebook_id,
|
||||
'google_id' => $this->google_id,
|
||||
'github_id' => $this->github_id,
|
||||
'created_at' => $this->created_at,
|
||||
'formatted_created_at' => $this->formattedCreatedAt,
|
||||
'updated_at' => $this->updated_at,
|
||||
'avatar' => $this->avatar,
|
||||
'due_amount' => $this->due_amount,
|
||||
'base_due_amount' => $this->base_due_amount,
|
||||
'invoice_due_amount' => $this->invoice_due_amount,
|
||||
'base_invoice_due_amount' => $this->base_invoice_due_amount,
|
||||
'available_credit' => $this->available_credit,
|
||||
'base_available_credit' => $this->base_available_credit,
|
||||
'account_balance' => $this->account_balance,
|
||||
'base_account_balance' => $this->base_account_balance,
|
||||
'prefix' => $this->prefix,
|
||||
'tax_id' => $this->tax_id,
|
||||
'billing' => $this->when($this->billingAddress()->exists(), function () {
|
||||
return new AddressResource($this->billingAddress);
|
||||
}),
|
||||
'shipping' => $this->when($this->shippingAddress()->exists(), function () {
|
||||
return new AddressResource($this->shippingAddress);
|
||||
}),
|
||||
'fields' => $this->when($this->fields()->exists(), function () {
|
||||
return CustomFieldValueResource::collection($this->fields);
|
||||
}),
|
||||
'company' => $this->when($this->company()->exists(), function () {
|
||||
return new CompanyResource($this->company);
|
||||
}),
|
||||
'currency' => $this->when($this->currency()->exists(), function () {
|
||||
return new CurrencyResource($this->currency);
|
||||
}),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user