diff --git a/app/app/Helpers/MainHelper.php b/app/app/Helpers/MainHelper.php index 82da11e73..1e3b7b9f2 100755 --- a/app/app/Helpers/MainHelper.php +++ b/app/app/Helpers/MainHelper.php @@ -1028,6 +1028,12 @@ public static function makeCardPrimary($card, $user, $workspace) } + public static function makeCardBackup($card, $user, $workspace) + { + $all = UserCard::where('workspace_id', $workspace->id)->update(['backup' => FALSE]); + $card->update(['backup' => TRUE]); + } + public static function determineFileType( $mime, $extension ) { if ( $mime == 'text/csv') { return 'csv'; diff --git a/app/app/Http/Controllers/Admin/ServicePlanController.php b/app/app/Http/Controllers/Admin/ServicePlanController.php index 11e38d083..b7fe91af6 100755 --- a/app/app/Http/Controllers/Admin/ServicePlanController.php +++ b/app/app/Http/Controllers/Admin/ServicePlanController.php @@ -94,7 +94,7 @@ public function edit(ServicePlan $serviceplan) $migratePlans = []; $allPlans = ServicePlan::where('id', '!=', $serviceplan->id)->get()->toArray(); foreach ($allPlans as $key => $plan) { - $migratePlans[$plan['nice_name']] = $plan['nice_name'] . ' (' . $plan['key_name'] . ')'; + $migratePlans[$plan['key_name']] = $plan['nice_name'] . ' (' . $plan['key_name'] . ')'; } return view('admin.serviceplan.create_edit', compact('serviceplan', 'features', 'callDurations', 'recordingSpace', 'migratePlans', 'statuses')); } @@ -108,13 +108,13 @@ public function edit(ServicePlan $serviceplan) public function migrate(Request $request, ServicePlan $serviceplan) { try { - $targetPlanNiceName = $request->input('migrate_plan'); + $targetPlanKeyName = $request->input('migrate_plan'); - if (!$targetPlanNiceName) { + if (!$targetPlanKeyName) { return redirect()->back()->withErrors(['migrate_plan' => 'Please select a target plan for migration.']); } - $targetPlan = ServicePlan::where('nice_name', $targetPlanNiceName)->first(); + $targetPlan = ServicePlan::where('key_name', $targetPlanKeyName)->first(); if (!$targetPlan) { return redirect()->back()->withErrors(['migrate_plan' => 'Target service plan not found.']); @@ -124,6 +124,16 @@ public function migrate(Request $request, ServicePlan $serviceplan) return redirect()->back()->withErrors(['migrate_plan' => 'Cannot migrate to the exact same plan.']); } + // Determine scheduled effective date + $effectiveDate = \Carbon\Carbon::now(); + $dateOption = $request->input('scheduled_effective_date', 'now'); + + if ($dateOption === 'next_month') { + $effectiveDate = \Carbon\Carbon::now()->firstOfNextMonth(); + } elseif ($dateOption === 'next_year') { + $effectiveDate = \Carbon\Carbon::now()->firstOfYear()->addYear(); + } + DB::beginTransaction(); $subscriptionsToMigrate = Subscription::where('current_plan_id', $serviceplan->id)->get(); $subscriptionsToMigrate = Subscription::join('workspaces', 'subscriptions.workspace_id', '=', 'workspaces.id') @@ -153,9 +163,10 @@ public function migrate(Request $request, ServicePlan $serviceplan) } } } + Subscription::where('current_plan_id', $serviceplan->id)->update([ 'scheduled_plan_id' => $targetPlan->id, - 'scheduled_effective_date' => \Carbon\Carbon::now() + 'scheduled_effective_date' => $effectiveDate ]); DB::commit(); diff --git a/app/app/Http/Controllers/Api/Card/CardController.php b/app/app/Http/Controllers/Api/Card/CardController.php index 1ace261a2..b01eaf0d3 100755 --- a/app/app/Http/Controllers/Api/Card/CardController.php +++ b/app/app/Http/Controllers/Api/Card/CardController.php @@ -38,8 +38,21 @@ public function setPrimary(Request $request, $cardId) $workspace = $this->getWorkspace($request); $card = UserCard::findOrFail($cardId); MainHelper::makeCardPrimary($card, $user, $workspace); + $card->backup = false; + $card->save(); + return $this->response->noContent(); + } + public function setBackup(Request $request, $cardId) + { + $user = $this->getUser($request); + $workspace = $this->getWorkspace($request); + $card = UserCard::findOrFail($cardId); + MainHelper::makeCardBackup($card, $user, $workspace); + $card->primary = false; + $card->save(); + return $this->response->noContent(); } public function listCards(Request $request) diff --git a/app/app/Http/routes.php b/app/app/Http/routes.php index 79964dba6..c24ec2a54 100755 --- a/app/app/Http/routes.php +++ b/app/app/Http/routes.php @@ -817,6 +817,7 @@ $api->get("/list", "CardController@listCards"); $api->post("/", "CardController@addCard"); $api->put("/{cardId}/setPrimary", "CardController@setPrimary"); + $api->put("/{cardId}/setBackup", "CardController@setBackup"); $api->delete("/{cardId}", "CardController@deleteCard"); }); diff --git a/app/database/migrations/2026_07_02_181214_add_backup_card_field.php b/app/database/migrations/2026_07_02_181214_add_backup_card_field.php new file mode 100644 index 000000000..27d9c6b00 --- /dev/null +++ b/app/database/migrations/2026_07_02_181214_add_backup_card_field.php @@ -0,0 +1,32 @@ +boolean('backup')->default(FALSE); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('users_cards', function (Blueprint $table) { + $table->dropColumn('backup'); + }); + } +} diff --git a/app/public/monthly_invoice.pdf b/app/public/monthly_invoice.pdf deleted file mode 100755 index 2a227ffda..000000000 Binary files a/app/public/monthly_invoice.pdf and /dev/null differ diff --git a/app/resources/views/admin/customizations/view.blade.php b/app/resources/views/admin/customizations/view.blade.php index 2357f1221..f8924adaf 100755 --- a/app/resources/views/admin/customizations/view.blade.php +++ b/app/resources/views/admin/customizations/view.blade.php @@ -404,7 +404,8 @@ - + + +