Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/app/Helpers/MainHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
21 changes: 16 additions & 5 deletions app/app/Http/Controllers/Admin/ServicePlanController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
Expand All @@ -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.']);
Expand All @@ -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')
Expand Down Expand Up @@ -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();
Expand Down
13 changes: 13 additions & 0 deletions app/app/Http/Controllers/Api/Card/CardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions app/app/Http/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AddBackupCardField extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users_cards', function (Blueprint $table) {
//
$table->boolean('backup')->default(FALSE);
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users_cards', function (Blueprint $table) {
$table->dropColumn('backup');
});
}
}
Binary file removed app/public/monthly_invoice.pdf
Binary file not shown.
6 changes: 5 additions & 1 deletion app/resources/views/admin/customizations/view.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,8 @@
</div>
</div>



<!--
<div class="row form-group">
<label for="billing_flow">Billing flow</label>
<div class="controls">
Expand All @@ -422,7 +423,9 @@
</select>
</div>
</div>
-->

<!--
<div class="row form-group">
<label for="upgrade_flow">Upgrade flow</label>
<div class="controls">
Expand All @@ -440,6 +443,7 @@
</select>
</div>
</div>
-->

<div class="row form-group">
<label for="invoice_due_in_days">Invoice due in days</label>
Expand Down
Loading