diff --git a/VERSION.txt b/VERSION.txt index d7896a867fc8..2b7afee56bdb 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -5.1.31 \ No newline at end of file +5.1.32 \ No newline at end of file diff --git a/app/Http/Controllers/QuoteController.php b/app/Http/Controllers/QuoteController.php index 02045ce2897f..f4a0c7e675ab 100644 --- a/app/Http/Controllers/QuoteController.php +++ b/app/Http/Controllers/QuoteController.php @@ -572,7 +572,6 @@ class QuoteController extends BaseController * description="Performs a custom action on an Quote. The current range of actions are as follows - - clone_to_Quote - clone_to_quote - history - delivery_note @@ -580,6 +579,8 @@ class QuoteController extends BaseController - download - archive - delete + - convert + - convert_to_invoice - email", * @OA\Parameter(ref="#/components/parameters/X-Api-Secret"), * @OA\Parameter(ref="#/components/parameters/X-Api-Token"), @@ -640,6 +641,14 @@ class QuoteController extends BaseController private function performAction(Quote $quote, $action, $bulk = false) { switch ($action) { + case 'convert': + case 'convert_to_invoice': + + $this->entity_type = Invoice::class; + $this->entity_transformer = InvoiceTransformer::class; + return $this->itemResponse($quote->service()->convertToInvoice()); + + break; case 'clone_to_invoice': $this->entity_type = Invoice::class; diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index c9386d194d0b..3b91f594de4c 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -608,14 +608,19 @@ class UserController extends BaseController */ public function detach(DetachCompanyUserRequest $request, User $user) { - if($user->isOwner()) - return response()->json(['message', 'Cannot detach owner.'],400); + + if ($request->entityIsDeleted($user)) { + return $request->disallowUpdate(); + } $company_user = CompanyUser::whereUserId($user->id) ->whereCompanyId(auth()->user()->companyId()) ->withTrashed() ->first(); + if($company_user->is_owner) + 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) { diff --git a/app/Http/Requests/User/DetachCompanyUserRequest.php b/app/Http/Requests/User/DetachCompanyUserRequest.php index 2b4dcf932e8d..7a40aaa9189b 100644 --- a/app/Http/Requests/User/DetachCompanyUserRequest.php +++ b/app/Http/Requests/User/DetachCompanyUserRequest.php @@ -13,12 +13,14 @@ namespace App\Http\Requests\User; use App\Http\Requests\Request; use App\Models\User; +use App\Utils\Traits\ChecksEntityStatus; use App\Utils\Traits\MakesHash; class DetachCompanyUserRequest extends Request { use MakesHash; - + use ChecksEntityStatus; + /** * Determine if the user is authorized to make this request. * diff --git a/app/Models/Subscription.php b/app/Models/Subscription.php index 7b588bddfc97..7c7679a82a9e 100644 --- a/app/Models/Subscription.php +++ b/app/Models/Subscription.php @@ -22,10 +22,9 @@ class Subscription extends BaseModel protected $fillable = [ 'user_id', - 'product_id', + 'product_ids', + 'recurring_product_ids', 'company_id', - 'product_id', - 'is_recurring', 'frequency_id', 'auto_bill', 'promo_code', @@ -43,6 +42,7 @@ class Subscription extends BaseModel 'refund_period', 'webhook_configuration', 'currency_id', + 'group_id', ]; protected $casts = [ diff --git a/app/Repositories/UserRepository.php b/app/Repositories/UserRepository.php index 7c5ce316a17d..826eebb568ab 100644 --- a/app/Repositories/UserRepository.php +++ b/app/Repositories/UserRepository.php @@ -148,9 +148,9 @@ class UserRepository extends BaseRepository event(new UserWasDeleted($user, auth()->user(), $company, Ninja::eventVars())); - // $user->is_deleted = true; - // $user->save(); - // $user->delete(); + $user->is_deleted = true; + $user->save(); + $user->delete(); return $user->fresh(); @@ -177,7 +177,17 @@ class UserRepository extends BaseRepository return; } + $user->is_deleted = false; + $user->save(); $user->restore(); + // $user->company_user->restore(); + + $cu = CompanyUser::withTrashed() + ->where('user_id', $user->id) + ->where('company_id', auth()->user()->company()->id) + ->first(); + + $cu->restore(); event(new UserWasRestored($user, auth()->user(), auth()->user()->company, Ninja::eventVars())); diff --git a/app/Services/Client/PaymentMethod.php b/app/Services/Client/PaymentMethod.php index 84b214b2fefc..b235aad129f2 100644 --- a/app/Services/Client/PaymentMethod.php +++ b/app/Services/Client/PaymentMethod.php @@ -186,7 +186,7 @@ class PaymentMethod foreach ($child_array as $gateway_id => $gateway_type_id) { $gateway = CompanyGateway::find($gateway_id); - $fee_label = $gateway->calcGatewayFeeLabel($this->amount, $this->client); + $fee_label = $gateway->calcGatewayFeeLabel($this->amount, $this->client, $gateway_type_id); if(!$gateway_type_id){ diff --git a/composer.json b/composer.json index c615a98e5d06..1a11e0cda50b 100644 --- a/composer.json +++ b/composer.json @@ -106,7 +106,7 @@ }, "scripts": { "post-install-cmd": [ - "vendor/bin/snappdf download" + "if [ '${IS_DOCKER:-false}' != 'true' ]; then vendor/bin/snappdf download; fi" ], "post-update-cmd": [ "vendor/bin/snappdf download" diff --git a/config/ninja.php b/config/ninja.php index 6119b502a178..f6d58aa59ed6 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -13,7 +13,7 @@ return [ 'require_https' => env('REQUIRE_HTTPS', true), 'app_url' => rtrim(env('APP_URL', ''), '/'), 'app_domain' => env('APP_DOMAIN', ''), - 'app_version' => '5.1.31', + 'app_version' => '5.1.32', 'minimum_client_version' => '5.0.16', 'terms_version' => '1.0.1', 'api_secret' => env('API_SECRET', false), diff --git a/database/migrations/2021_03_25_082025_refactor_billing_scriptions_table.php b/database/migrations/2021_03_25_082025_refactor_billing_scriptions_table.php index f944dc5596de..561f19db350f 100644 --- a/database/migrations/2021_03_25_082025_refactor_billing_scriptions_table.php +++ b/database/migrations/2021_03_25_082025_refactor_billing_scriptions_table.php @@ -21,10 +21,12 @@ class RefactorBillingScriptionsTable extends Migration $table->text('recurring_product_ids'); $table->string('name'); $table->unique(['company_id', 'name']); + $table->unsignedInteger('group_id'); }); Schema::table('subscriptions', function (Blueprint $table) { $table->renameColumn('product_id', 'product_ids'); + $table->dropColumn('is_recurring'); }); } diff --git a/tests/Feature/SubscriptionApiTest.php b/tests/Feature/SubscriptionApiTest.php index 49ca0d007987..f5b8e424f4fd 100644 --- a/tests/Feature/SubscriptionApiTest.php +++ b/tests/Feature/SubscriptionApiTest.php @@ -53,7 +53,7 @@ class SubscriptionApiTest extends TestCase ]); $billing_subscription = Subscription::factory()->create([ - 'product_id' => $product->id, + 'product_ids' => $product->id, 'company_id' => $this->company->id, ]); @@ -78,7 +78,7 @@ class SubscriptionApiTest extends TestCase $response = $this->withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'), 'X-API-TOKEN' => $this->token, - ])->post('/api/v1/subscriptions', ['product_id' => $product->id, 'allow_cancellation' => true]); + ])->post('/api/v1/subscriptions', ['product_ids' => $product->id, 'allow_cancellation' => true]); $response->assertStatus(200); } @@ -92,7 +92,7 @@ class SubscriptionApiTest extends TestCase $response1 = $this ->withHeaders(['X-API-SECRET' => config('ninja.api_secret'),'X-API-TOKEN' => $this->token]) - ->post('/api/v1/subscriptions', ['product_id' => $product->id]) + ->post('/api/v1/subscriptions', ['product_ids' => $product->id]) ->assertStatus(200) ->json(); @@ -123,7 +123,7 @@ class SubscriptionApiTest extends TestCase ]); $billing_subscription = Subscription::factory()->create([ - 'product_id' => $product->id, + 'product_ids' => $product->id, 'company_id' => $this->company->id, ]);