From df9ea70806085cdf7e4d2a5a3424a29d17339533 Mon Sep 17 00:00:00 2001 From: ajikamaludin Date: Sun, 18 Sep 2022 11:37:12 +0700 Subject: [PATCH] done set database, model and seeder --- app/Models/Department.php | 7 +++ app/Models/Document.php | 43 ++++++++++++++++++ app/Models/DocumentReminder.php | 21 +++++++++ app/Models/DocumentShare.php | 27 +++++++++++ app/Models/Setting.php | 11 +++++ app/Models/TypeDoc.php | 18 ++++++++ ..._09_18_020641_create_departments_table.php | 1 + ...22_09_18_034351_create_type_docs_table.php | 31 +++++++++++++ ...22_09_18_034528_create_documents_table.php | 45 +++++++++++++++++++ ...042542_create_document_reminders_table.php | 33 ++++++++++++++ ...18_042619_create_document_shares_table.php | 34 ++++++++++++++ ...022_09_18_043459_create_settings_table.php | 33 ++++++++++++++ database/seeders/DatabaseSeeder.php | 26 +++++++++-- resources/js/Layouts/AuthenticatedLayout.jsx | 1 - 14 files changed, 326 insertions(+), 5 deletions(-) create mode 100644 app/Models/Document.php create mode 100644 app/Models/DocumentReminder.php create mode 100644 app/Models/DocumentShare.php create mode 100644 app/Models/Setting.php create mode 100644 app/Models/TypeDoc.php create mode 100644 database/migrations/2022_09_18_034351_create_type_docs_table.php create mode 100644 database/migrations/2022_09_18_034528_create_documents_table.php create mode 100644 database/migrations/2022_09_18_042542_create_document_reminders_table.php create mode 100644 database/migrations/2022_09_18_042619_create_document_shares_table.php create mode 100644 database/migrations/2022_09_18_043459_create_settings_table.php diff --git a/app/Models/Department.php b/app/Models/Department.php index c38e561..6883cf1 100644 --- a/app/Models/Department.php +++ b/app/Models/Department.php @@ -8,4 +8,11 @@ use Illuminate\Database\Eloquent\Model; class Department extends Model { use HasFactory; + + protected $fillable = ['name']; + + public function documents() + { + $this->hasMany(Document::class, 'document_id'); + } } diff --git a/app/Models/Document.php b/app/Models/Document.php new file mode 100644 index 0000000..fafa758 --- /dev/null +++ b/app/Models/Document.php @@ -0,0 +1,43 @@ +belongsTo(Department::class, 'department_id'); + } + + public function type() + { + return $this->belongsTo(TypeDoc::class, 'type_doc_id'); + } + + public function creator() + { + return $this->belongsTo(User::class, 'user_id'); + } +} diff --git a/app/Models/DocumentReminder.php b/app/Models/DocumentReminder.php new file mode 100644 index 0000000..fead284 --- /dev/null +++ b/app/Models/DocumentReminder.php @@ -0,0 +1,21 @@ +belongsTo(Document::class, 'document_id'); + } +} diff --git a/app/Models/DocumentShare.php b/app/Models/DocumentShare.php new file mode 100644 index 0000000..0be8358 --- /dev/null +++ b/app/Models/DocumentShare.php @@ -0,0 +1,27 @@ +belongsTo(Document::class, 'document_id'); + } + + public function user() + { + $this->belongsTo(User::class, 'user_id'); + } +} diff --git a/app/Models/Setting.php b/app/Models/Setting.php new file mode 100644 index 0000000..0fe60af --- /dev/null +++ b/app/Models/Setting.php @@ -0,0 +1,11 @@ +hasMany(Document::class, 'document_id'); + } +} diff --git a/database/migrations/2022_09_18_020641_create_departments_table.php b/database/migrations/2022_09_18_020641_create_departments_table.php index b9a3461..cecd327 100644 --- a/database/migrations/2022_09_18_020641_create_departments_table.php +++ b/database/migrations/2022_09_18_020641_create_departments_table.php @@ -14,6 +14,7 @@ return new class extends Migration { { Schema::create('departments', function (Blueprint $table) { $table->id(); + $table->string('name'); $table->timestamps(); }); } diff --git a/database/migrations/2022_09_18_034351_create_type_docs_table.php b/database/migrations/2022_09_18_034351_create_type_docs_table.php new file mode 100644 index 0000000..a3d14e3 --- /dev/null +++ b/database/migrations/2022_09_18_034351_create_type_docs_table.php @@ -0,0 +1,31 @@ +id(); + $table->string('name'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('type_docs'); + } +}; diff --git a/database/migrations/2022_09_18_034528_create_documents_table.php b/database/migrations/2022_09_18_034528_create_documents_table.php new file mode 100644 index 0000000..30736fd --- /dev/null +++ b/database/migrations/2022_09_18_034528_create_documents_table.php @@ -0,0 +1,45 @@ +id(); + $table->integer('no', false); + $table->string('no_doc'); + $table->foreignId('type_doc_id')->constrained(); + $table->string('company_name'); + $table->string('first_person_name'); + $table->string('second_person_name'); + $table->dateTime('start_date'); + $table->dateTime('end_date'); + $table->foreignId('department_id')->constrained(); + $table->string('pic_name'); + $table->string('email'); + $table->text('note'); + $table->string('document'); + $table->foreignId('user_id')->constrained(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('documents'); + } +}; diff --git a/database/migrations/2022_09_18_042542_create_document_reminders_table.php b/database/migrations/2022_09_18_042542_create_document_reminders_table.php new file mode 100644 index 0000000..4c675ee --- /dev/null +++ b/database/migrations/2022_09_18_042542_create_document_reminders_table.php @@ -0,0 +1,33 @@ +id(); + $table->foreignId('document_id')->constrained(); + $table->dateTime('date'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('document_reminders'); + } +}; diff --git a/database/migrations/2022_09_18_042619_create_document_shares_table.php b/database/migrations/2022_09_18_042619_create_document_shares_table.php new file mode 100644 index 0000000..780f149 --- /dev/null +++ b/database/migrations/2022_09_18_042619_create_document_shares_table.php @@ -0,0 +1,34 @@ +id(); + $table->foreignId('document_id')->constrained(); + $table->foreignId('user_id')->nullable()->constrained(); + $table->string('share_to')->nullable(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('document_shares'); + } +}; diff --git a/database/migrations/2022_09_18_043459_create_settings_table.php b/database/migrations/2022_09_18_043459_create_settings_table.php new file mode 100644 index 0000000..949385b --- /dev/null +++ b/database/migrations/2022_09_18_043459_create_settings_table.php @@ -0,0 +1,33 @@ +id(); + $table->string('key'); + $table->text('value'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('settings'); + } +}; diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index cf6dd8f..37ca77f 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -3,6 +3,10 @@ namespace Database\Seeders; // use Illuminate\Database\Console\Seeds\WithoutModelEvents; + +use App\Models\Department; +use App\Models\TypeDoc; +use App\Models\User; use Illuminate\Database\Seeder; class DatabaseSeeder extends Seeder @@ -14,20 +18,34 @@ class DatabaseSeeder extends Seeder */ public function run() { - // \App\Models\User::factory(10)->create(); - - \App\Models\User::factory()->create([ + User::factory()->create([ 'name' => 'Administrator', 'email' => 'admin@admin.com', 'password' => bcrypt('password'), 'is_admin' => 1, // admin user ]); - \App\Models\User::factory()->create([ + User::factory()->create([ 'name' => 'User', 'email' => 'user@admin.com', 'password' => bcrypt('password'), 'is_admin' => 0, // normal user ]); + + if (Department::count() == 0) { + $departments = ['HRD', 'Purchasing', 'Finance, Accounting & Tax', 'Sales','HSE','Produksi','QA / QC','Maintenance']; + + foreach ($departments as $dep) { + Department::create(['name' => $dep]); + } + } + + if (TypeDoc::count() == 0) { + $types = ['Perijinan', 'Perjanjian Kerjasama', 'Kontrak Kerja']; + + foreach ($types as $type) { + TypeDoc::create(['name' => $type]); + } + } } } diff --git a/resources/js/Layouts/AuthenticatedLayout.jsx b/resources/js/Layouts/AuthenticatedLayout.jsx index bff9090..9fc3eca 100644 --- a/resources/js/Layouts/AuthenticatedLayout.jsx +++ b/resources/js/Layouts/AuthenticatedLayout.jsx @@ -140,7 +140,6 @@ export default function Authenticated({ auth, children }) {