diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 8ff9f3070a99..f8ffe75fb6e5 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -260,8 +260,8 @@ class UserController extends BaseController /** @var \App\Models\User $logged_in_user */ $logged_in_user = auth()->user(); - $company_user = CompanyUser::whereUserId($user->id) - ->whereCompanyId($logged_in_user->companyId()) + $company_user = CompanyUser::where('user_id',$user->id) + ->where('company_id', $logged_in_user->companyId()) ->withTrashed() ->first(); @@ -269,14 +269,10 @@ class UserController extends BaseController return response()->json(['message', 'Cannot detach owner.'], 401); } - $token = $company_user->token->where('company_id', $company_user->company_id)->where('user_id', $company_user->user_id)->first(); - - if ($token) { - $token->delete(); - } + $company_user->tokens()->where('company_id', $company_user->company_id)->where('user_id', $company_user->user_id)->forceDelete(); if ($company_user) { - $company_user->delete(); + $company_user->forceDelete(); } return response()->json(['message' => ctrans('texts.user_detached')], 200); diff --git a/app/Http/Requests/Payment/StorePaymentRequest.php b/app/Http/Requests/Payment/StorePaymentRequest.php index 463086acefae..554d729dbe78 100644 --- a/app/Http/Requests/Payment/StorePaymentRequest.php +++ b/app/Http/Requests/Payment/StorePaymentRequest.php @@ -50,7 +50,7 @@ class StorePaymentRequest extends Request 'invoices.*.invoice_id' => ['bail','required','distinct', new ValidInvoicesRules($this->all()),Rule::exists('invoices','id')->where('company_id', $user->company()->id)->where('client_id', $this->client_id)], 'credits.*.credit_id' => ['bail','required','distinct', new ValidCreditsRules($this->all()),Rule::exists('credits','id')->where('company_id', $user->company()->id)->where('client_id', $this->client_id)], 'credits.*.amount' => ['bail','required', new CreditsSumRule($this->all())], - 'invoices' => ['bail','sometimes','array', new ValidPayableInvoicesRule()], + 'invoices' => ['bail','sometimes', 'nullable', 'array', new ValidPayableInvoicesRule()], 'number' => ['bail', 'nullable', Rule::unique('payments')->where('company_id', $user->company()->id)], 'idempotency_key' => ['nullable', 'bail', 'string','max:64', Rule::unique('payments')->where('company_id', $user->company()->id)], ]; diff --git a/app/Http/Requests/Payment/UpdatePaymentRequest.php b/app/Http/Requests/Payment/UpdatePaymentRequest.php index befbe9499c5b..02cc11d45edc 100644 --- a/app/Http/Requests/Payment/UpdatePaymentRequest.php +++ b/app/Http/Requests/Payment/UpdatePaymentRequest.php @@ -44,7 +44,7 @@ class UpdatePaymentRequest extends Request $rules = [ 'client_id' => ['sometimes', 'bail', Rule::in([$this->payment->client_id])], 'number' => ['sometimes', 'bail', Rule::unique('payments')->where('company_id', $user->company()->id)->ignore($this->payment->id)], - 'invoices' => ['sometimes', 'bail', 'array', new PaymentAppliedValidAmount($this->all())], + 'invoices' => ['sometimes', 'bail', 'nullable', 'array', new PaymentAppliedValidAmount($this->all())], 'invoices.*.invoice_id' => ['sometimes','distinct',Rule::exists('invoices','id')->where('company_id', $user->company()->id)->where('client_id', $this->client_id)], 'invoices.*.amount' => ['sometimes','numeric','min:0'], 'credits.*.credit_id' => ['sometimes','bail','distinct',Rule::exists('credits','id')->where('company_id', $user->company()->id)->where('client_id', $this->client_id)], diff --git a/tests/Feature/PaymentTest.php b/tests/Feature/PaymentTest.php index 49de5339b260..3dd9813def58 100644 --- a/tests/Feature/PaymentTest.php +++ b/tests/Feature/PaymentTest.php @@ -590,19 +590,13 @@ class PaymentTest extends TestCase $response = false; - // try { $response = $this->withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'), 'X-API-TOKEN' => $this->token, ])->postJson('/api/v1/payments?include=invoices', $data); - // } catch (ValidationException $e) { - // $message = json_decode($e->validator->getMessageBag(), 1); - // $this->assertNotNull($message); - // } - // if ($response) { $response->assertStatus(200); - // } + } public function testPartialPaymentAmount()