mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-04 15:54:36 -04:00
Billing subscriptions: Database schema & model
This commit is contained in:
parent
ea5117ecbe
commit
9c1a3368e9
61
app/Models/BillingSubscription.php
Normal file
61
app/Models/BillingSubscription.php
Normal file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class BillingSubscription extends BaseModel
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'product_id',
|
||||
'company_id',
|
||||
'product_id',
|
||||
'is_recurring',
|
||||
'frequency_id',
|
||||
'auto_bill',
|
||||
'promo_code',
|
||||
'promo_discount',
|
||||
'is_amount_discount',
|
||||
'allow_cancellation',
|
||||
'per_set_enabled',
|
||||
'min_seats_limit',
|
||||
'max_seats_limit',
|
||||
'trial_enabled',
|
||||
'trial_duration',
|
||||
'allow_query_overrides',
|
||||
'allow_plan_changes',
|
||||
'plan_map',
|
||||
'refund_period',
|
||||
'webhook_configuration',
|
||||
];
|
||||
|
||||
public function company(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Company::class);
|
||||
}
|
||||
|
||||
public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function product(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Product::class);
|
||||
}
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateBillingSubscriptionsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('billing_subscriptions', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->unsignedInteger('user_id');
|
||||
$table->unsignedInteger('assigned_user_id');
|
||||
$table->unsignedInteger('company_id');
|
||||
$table->unsignedInteger('product_id');
|
||||
$table->boolean('is_recurring')->default(false);
|
||||
$table->unsignedInteger('frequency_id');
|
||||
$table->string('auto_bill')->default('');
|
||||
$table->string('promo_code')->default('');
|
||||
$table->float('promo_discount')->default(0);
|
||||
$table->boolean('is_amount_discount')->default(false);
|
||||
$table->boolean('allow_cancellation')->default(true);
|
||||
$table->boolean('per_set_enabled')->default(false);
|
||||
$table->unsignedInteger('min_seats_limit');
|
||||
$table->unsignedInteger('max_seats_limit');
|
||||
$table->boolean('trial_enabled')->default(false);
|
||||
$table->unsignedInteger('trial_duration');
|
||||
$table->boolean('allow_query_overrides')->default(false);
|
||||
$table->boolean('allow_plan_changes')->default(false);
|
||||
$table->mediumText('plan_map');
|
||||
$table->unsignedInteger('refund_period')->nullable();
|
||||
$table->mediumText('webhook_configuration');
|
||||
$table->softDeletes('deleted_at', 6);
|
||||
$table->boolean('is_deleted')->default(false);
|
||||
$table->timestamps();
|
||||
$table->foreign('product_id')->references('id')->on('products');
|
||||
$table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade');
|
||||
$table->index(['company_id', 'deleted_at']);
|
||||
});
|
||||
|
||||
Schema::create('client_subscriptions', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->unsignedInteger('subscription_id');
|
||||
$table->unsignedInteger('recurring_invoice_id');
|
||||
$table->unsignedInteger('client_id');
|
||||
$table->unsignedInteger('trial_started')->nullable();
|
||||
$table->unsignedInteger('trial_ends')->nullable();
|
||||
$table->timestamps();
|
||||
$table->foreign('subscription_id')->references('id')->on('billing_subscriptions');
|
||||
$table->foreign('recurring_invoice_id')->references('id')->on('recurring_invoices');
|
||||
$table->foreign('client_id')->references('id')->on('clients');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('billing_subscriptions');
|
||||
Schema::dropIfExists('client_subscriptions');
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user