Skip to content

Commit

Permalink
Add pipeline and stage management to deals
Browse files Browse the repository at this point in the history
  • Loading branch information
sweep-ai[bot] authored Oct 13, 2024
1 parent 9038450 commit 219ff1c
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 0 deletions.
35 changes: 35 additions & 0 deletions app/Models/Stage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace App\Models;

use App\Traits\IsTenantModel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

class Stage extends Model
{
use HasFactory;
use IsTenantModel;

protected $fillable = [
'name',
'order',
'pipeline_id',
];

protected $casts = [
'order' => 'integer',
];

public function pipeline(): BelongsTo
{
return $this->belongsTo(Pipeline::class);
}

public function deals(): HasMany
{
return $this->hasMany(Deal::class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ class AddPipelineAndStageToDealsTable extends Migration
{
public function up()
{
if (!Schema::hasTable('deals')) {
Schema::create('deals', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->decimal('value', 15, 2);
$table->string('stage')->nullable();
$table->date('close_date')->nullable();
$table->integer('probability')->nullable();
$table->foreignId('contact_id')->nullable()->constrained()->onDelete('set null');
$table->foreignId('user_id')->nullable()->constrained()->onDelete('set null');
$table->timestamps();
});
}

Schema::table('deals', function (Blueprint $table) {
$table->foreignId('pipeline_id')->nullable()->constrained()->onDelete('set null');
$table->foreignId('stage_id')->nullable()->constrained()->onDelete('set null');
Expand Down
28 changes: 28 additions & 0 deletions database/migrations/[timestamp]_create_deals_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

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

class CreateDealsTable extends Migration
{
public function up()
{
Schema::create('deals', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->decimal('value', 15, 2);
$table->string('stage')->nullable();
$table->date('close_date')->nullable();
$table->integer('probability')->nullable();
$table->foreignId('contact_id')->nullable()->constrained()->onDelete('set null');
$table->foreignId('user_id')->nullable()->constrained()->onDelete('set null');
$table->timestamps();
});
}

public function down()
{
Schema::dropIfExists('deals');
}
}
24 changes: 24 additions & 0 deletions database/migrations/[timestamp]_create_stages_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

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

class CreateStagesTable extends Migration
{
public function up()
{
Schema::create('stages', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->integer('order');
$table->foreignId('pipeline_id')->constrained()->onDelete('cascade');
$table->timestamps();
});
}

public function down()
{
Schema::dropIfExists('stages');
}
}

0 comments on commit 219ff1c

Please sign in to comment.