initial commit
This commit is contained in:
1
database/.gitignore
vendored
Normal file
1
database/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
*.sqlite*
|
||||
23
database/factories/MarketFactory.php
Normal file
23
database/factories/MarketFactory.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Market>
|
||||
*/
|
||||
class MarketFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
||||
23
database/factories/SaleFactory.php
Normal file
23
database/factories/SaleFactory.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Sale>
|
||||
*/
|
||||
class SaleFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
||||
23
database/factories/SubMarketFactory.php
Normal file
23
database/factories/SubMarketFactory.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\SubMarket>
|
||||
*/
|
||||
class SubMarketFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
||||
44
database/factories/UserFactory.php
Normal file
44
database/factories/UserFactory.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User>
|
||||
*/
|
||||
class UserFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The current password being used by the factory.
|
||||
*/
|
||||
protected static ?string $password;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => fake()->name(),
|
||||
'email' => fake()->unique()->safeEmail(),
|
||||
'email_verified_at' => now(),
|
||||
'password' => static::$password ??= Hash::make('password'),
|
||||
'remember_token' => Str::random(10),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the model's email address should be unverified.
|
||||
*/
|
||||
public function unverified(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'email_verified_at' => null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
49
database/migrations/0001_01_01_000000_create_users_table.php
Normal file
49
database/migrations/0001_01_01_000000_create_users_table.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('users', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->string('email')->unique();
|
||||
$table->timestamp('email_verified_at')->nullable();
|
||||
$table->string('password');
|
||||
$table->rememberToken();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::create('password_reset_tokens', function (Blueprint $table) {
|
||||
$table->string('email')->primary();
|
||||
$table->string('token');
|
||||
$table->timestamp('created_at')->nullable();
|
||||
});
|
||||
|
||||
Schema::create('sessions', function (Blueprint $table) {
|
||||
$table->string('id')->primary();
|
||||
$table->foreignId('user_id')->nullable()->index();
|
||||
$table->string('ip_address', 45)->nullable();
|
||||
$table->text('user_agent')->nullable();
|
||||
$table->longText('payload');
|
||||
$table->integer('last_activity')->index();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('users');
|
||||
Schema::dropIfExists('password_reset_tokens');
|
||||
Schema::dropIfExists('sessions');
|
||||
}
|
||||
};
|
||||
35
database/migrations/0001_01_01_000001_create_cache_table.php
Normal file
35
database/migrations/0001_01_01_000001_create_cache_table.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('cache', function (Blueprint $table) {
|
||||
$table->string('key')->primary();
|
||||
$table->mediumText('value');
|
||||
$table->integer('expiration');
|
||||
});
|
||||
|
||||
Schema::create('cache_locks', function (Blueprint $table) {
|
||||
$table->string('key')->primary();
|
||||
$table->string('owner');
|
||||
$table->integer('expiration');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('cache');
|
||||
Schema::dropIfExists('cache_locks');
|
||||
}
|
||||
};
|
||||
57
database/migrations/0001_01_01_000002_create_jobs_table.php
Normal file
57
database/migrations/0001_01_01_000002_create_jobs_table.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('jobs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('queue')->index();
|
||||
$table->longText('payload');
|
||||
$table->unsignedTinyInteger('attempts');
|
||||
$table->unsignedInteger('reserved_at')->nullable();
|
||||
$table->unsignedInteger('available_at');
|
||||
$table->unsignedInteger('created_at');
|
||||
});
|
||||
|
||||
Schema::create('job_batches', function (Blueprint $table) {
|
||||
$table->string('id')->primary();
|
||||
$table->string('name');
|
||||
$table->integer('total_jobs');
|
||||
$table->integer('pending_jobs');
|
||||
$table->integer('failed_jobs');
|
||||
$table->longText('failed_job_ids');
|
||||
$table->mediumText('options')->nullable();
|
||||
$table->integer('cancelled_at')->nullable();
|
||||
$table->integer('created_at');
|
||||
$table->integer('finished_at')->nullable();
|
||||
});
|
||||
|
||||
Schema::create('failed_jobs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('uuid')->unique();
|
||||
$table->text('connection');
|
||||
$table->text('queue');
|
||||
$table->longText('payload');
|
||||
$table->longText('exception');
|
||||
$table->timestamp('failed_at')->useCurrent();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('jobs');
|
||||
Schema::dropIfExists('job_batches');
|
||||
Schema::dropIfExists('failed_jobs');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('markets', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string("name");
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('markets');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('sub_markets', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string("name");
|
||||
$table->foreignId("market_id")->constrained();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('sub_markets');
|
||||
}
|
||||
};
|
||||
80
database/migrations/2025_05_24_201310_create_sales_table.php
Normal file
80
database/migrations/2025_05_24_201310_create_sales_table.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('sales', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->string('sale_id');
|
||||
$table->string('sale_name');
|
||||
$table->string('record_type');
|
||||
$table->string('status');
|
||||
$table->string('comp_source')->nullable();
|
||||
$table->date('date_last_verified')->nullable();
|
||||
$table->string('property_name')->nullable();
|
||||
$table->string('comp_id')->nullable();
|
||||
$table->string('street')->nullable();
|
||||
$table->string('city')->nullable();
|
||||
$table->string('state_province')->nullable();
|
||||
$table->string('zip_postal_code')->nullable();
|
||||
$table->string('property_county')->nullable();
|
||||
|
||||
// $table->string('market')->nullable();
|
||||
// $table->string('sub_market')->nullable();
|
||||
$table->foreignId("market_id")->nullable()->constrained()->nullOnDelete();
|
||||
$table->foreignId("sub_market_id")->nullable()->constrained()->nullOnDelete();
|
||||
|
||||
$table->string('property_sub_type')->nullable();
|
||||
$table->integer('num_units')->nullable();
|
||||
$table->integer('building_size_sf')->nullable();
|
||||
$table->integer('year_built')->nullable();
|
||||
$table->date('listing_date')->nullable();
|
||||
$table->integer('dom_cumulative')->nullable();
|
||||
$table->integer('original_listing_price')->nullable(); // in cents
|
||||
$table->integer('listing_price')->nullable(); // in cents
|
||||
$table->integer('adv_agi')->nullable(); // in cents
|
||||
$table->integer('x_agi')->nullable(); // in cents
|
||||
$table->integer('adv_noi')->nullable(); // in cents
|
||||
$table->integer('x_noi')->nullable(); // in cents
|
||||
$table->integer('asking_price_unit')->nullable(); // in cents
|
||||
$table->integer('asking_price_sf')->nullable(); // in cents
|
||||
$table->integer('asking_grm')->nullable(); // e.g. multiply 13.08 → 1308
|
||||
$table->integer('asking_cap')->nullable(); // e.g. 4.98% → 498
|
||||
$table->date('can_exp_wth_date')->nullable();
|
||||
$table->integer('dom_can_exp')->nullable();
|
||||
$table->date('pending_date')->nullable();
|
||||
$table->integer('dom_pending')->nullable();
|
||||
$table->date('sale_date')->nullable();
|
||||
$table->integer('dom_sold')->nullable();
|
||||
$table->integer('length_of_escrow')->nullable();
|
||||
$table->integer('sale_price')->nullable(); // in cents
|
||||
$table->integer('sold_price_unit')->nullable(); // in cents
|
||||
$table->integer('sold_price_delivered')->nullable(); // in cents
|
||||
$table->integer('sold_price_sf')->nullable(); // in cents
|
||||
$table->string('sales_terms')->nullable();
|
||||
$table->integer('sold_grm')->nullable(); // e.g. 12.61 → 1261
|
||||
$table->integer('sold_cap')->nullable(); // e.g. 5.16% → 516
|
||||
$table->integer('loan_amount')->nullable(); // in cents
|
||||
$table->integer('percent_down_payment')->nullable(); // e.g. 100% → 10000
|
||||
$table->boolean('owner_occ_purchase')->nullable(); // 1 or 0
|
||||
$table->integer('land_area_acre')->nullable(); // e.g. 0.12 → 12 (store hundredths of an acre)
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('sales');
|
||||
}
|
||||
};
|
||||
18
database/seeders/DatabaseSeeder.php
Normal file
18
database/seeders/DatabaseSeeder.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
// use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class DatabaseSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Seed the application's database.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$this->call(UsersSeeder::class);
|
||||
$this->call(SalesSeeder::class);
|
||||
}
|
||||
}
|
||||
148
database/seeders/SalesSeeder.php
Normal file
148
database/seeders/SalesSeeder.php
Normal file
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Market;
|
||||
use Illuminate\Database\Seeder;
|
||||
use App\Models\Sale;
|
||||
use App\Models\SubMarket;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class SalesSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
$file = base_path('Test Data for Market Reports.csv');
|
||||
|
||||
if (!file_exists($file)) {
|
||||
$this->command->error("CSV file not found at {$file}");
|
||||
return;
|
||||
}
|
||||
|
||||
$handle = fopen($file, 'r');
|
||||
$headers = fgetcsv($handle);
|
||||
|
||||
// Manual header mapping to correct column names
|
||||
$headerMap = [
|
||||
'Sale ID' => 'sale_id',
|
||||
'Sale Name' => 'sale_name',
|
||||
'Record Type' => 'record_type',
|
||||
'Status' => 'status',
|
||||
'Comp Source' => 'comp_source',
|
||||
'Date Last Verified' => 'date_last_verified',
|
||||
'Property Name' => 'property_name',
|
||||
'Comp ID' => 'comp_id',
|
||||
'Street' => 'street',
|
||||
'City' => 'city',
|
||||
'State/Province' => 'state_province',
|
||||
'Zip/Postal Code' => 'zip_postal_code',
|
||||
'Market' => 'market',
|
||||
'Property County' => 'property_county',
|
||||
'Sub-Market' => 'sub_market',
|
||||
'Property Sub Type' => 'property_sub_type',
|
||||
'# of Units' => 'num_units',
|
||||
'Building Size (SF)' => 'building_size_sf',
|
||||
'Year Built' => 'year_built',
|
||||
'Listing Date' => 'listing_date',
|
||||
'DOM (Cumulative)' => 'dom_cumulative',
|
||||
'Original Listing Price' => 'original_listing_price',
|
||||
'Listing Price' => 'listing_price',
|
||||
'Adv - AGI' => 'adv_agi',
|
||||
'X - AGI' => 'x_agi',
|
||||
'Adv - NOI' => 'adv_noi',
|
||||
'X - NOI' => 'x_noi',
|
||||
'Asking Price (Unit)' => 'asking_price_unit',
|
||||
'Asking Price (SF)' => 'asking_price_sf',
|
||||
'Asking GRM' => 'asking_grm',
|
||||
'Asking Cap' => 'asking_cap',
|
||||
'CAN/EXP/WTH Date' => 'can_exp_wth_date',
|
||||
'DOM (Can/Exp)' => 'dom_can_exp',
|
||||
'Pending Date' => 'pending_date',
|
||||
'DOM (Pending)' => 'dom_pending',
|
||||
'Sale Date' => 'sale_date',
|
||||
'DOM (Sold)' => 'dom_sold',
|
||||
'Length of Escrow' => 'length_of_escrow',
|
||||
'Sale Price' => 'sale_price',
|
||||
'Sold Price (Unit)' => 'sold_price_unit',
|
||||
'Sold Price Delivered' => 'sold_price_delivered',
|
||||
'Sold Price (SF)' => 'sold_price_sf',
|
||||
'Sales Terms' => 'sales_terms',
|
||||
'Sold GRM' => 'sold_grm',
|
||||
'Sold Cap' => 'sold_cap',
|
||||
'Loan Amount' => 'loan_amount',
|
||||
'% Down Payment' => 'percent_down_payment',
|
||||
'Owner Occ Purchase' => 'owner_occ_purchase',
|
||||
'Land Area (Acre)' => 'land_area_acre',
|
||||
];
|
||||
|
||||
// Map headers to DB columns
|
||||
$columns = array_map(fn($h) => $headerMap[$h] ?? null, $headers);
|
||||
|
||||
|
||||
// List of date columns in your schema
|
||||
$dateColumns = [
|
||||
'date_last_verified',
|
||||
'listing_date',
|
||||
'can_exp_wth_date',
|
||||
'pending_date',
|
||||
'sale_date',
|
||||
];
|
||||
|
||||
while (($row = fgetcsv($handle)) !== false) {
|
||||
$data = [];
|
||||
|
||||
foreach ($columns as $index => $column) {
|
||||
if ($column) {
|
||||
$data[$column] = $row[$index];
|
||||
}
|
||||
}
|
||||
|
||||
// used in a moment
|
||||
if ($data["market"]) {
|
||||
$market = Market::firstOrCreate(["name" => $data["market"]]);
|
||||
|
||||
if ($data["sub_market"]) {
|
||||
$subMarket = SubMarket::firstOrCreate(["name" => $data["market"], "market_id" => $market->id]);
|
||||
}
|
||||
} else {
|
||||
$market = "";
|
||||
$subMarket = "";
|
||||
}
|
||||
|
||||
$data["market_id"] = $market ? $market->id : "";
|
||||
$data["sub_market_id"] = $subMarket ? $subMarket->id : "";
|
||||
unset($data["market"]);
|
||||
unset($data["sub_market"]);
|
||||
|
||||
|
||||
foreach ($dateColumns as $column) {
|
||||
if (!empty($data[$column])) {
|
||||
try {
|
||||
// Normalize date from M/D/YY → Y-m-d
|
||||
$data[$column] = Carbon::createFromFormat('n/j/y', $data[$column])->format('Y-m-d');
|
||||
} catch (\Exception $e) {
|
||||
// You can log or handle formatting errors if needed
|
||||
$data[$column] = null;
|
||||
}
|
||||
} else {
|
||||
$data[$column] = null;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($data as $col => $val) {
|
||||
if (trim($val) === "") {
|
||||
$data[$col] = null;
|
||||
}
|
||||
if ($val === "#Error!") {
|
||||
$data[$col] = -1;
|
||||
}
|
||||
}
|
||||
|
||||
Sale::create($data);
|
||||
}
|
||||
|
||||
fclose($handle);
|
||||
|
||||
$this->command->info('✅ Sales imported successfully.');
|
||||
}
|
||||
}
|
||||
25
database/seeders/UsersSeeder.php
Normal file
25
database/seeders/UsersSeeder.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class UsersSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
User::factory()->create([
|
||||
'name' => 'Kurtis Holsapple',
|
||||
'email' => 'kurtis@openfunctioncomputers.com',
|
||||
]);
|
||||
User::factory()->create([
|
||||
'name' => 'Ben Ficker',
|
||||
'email' => 'bficker@kwcommercial.com',
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user