Browse Source

feat: model, migration, database design

Muhammad Iqbal Afandi 3 years ago
parent
commit
32c3443f11

+ 19
- 0
app/Models/Customer.php View File

@@ -0,0 +1,19 @@
1
+<?php
2
+
3
+namespace App\Models;
4
+
5
+use Illuminate\Database\Eloquent\Factories\HasFactory;
6
+use Illuminate\Database\Eloquent\Model;
7
+
8
+class Customer extends Model
9
+{
10
+    use HasFactory;
11
+
12
+    protected $fillable = [
13
+        'customer_number',
14
+        'name',
15
+        'phone',
16
+        'address',
17
+        'gender',
18
+    ];
19
+}

+ 19
- 0
app/Models/Expense.php View File

@@ -0,0 +1,19 @@
1
+<?php
2
+
3
+namespace App\Models;
4
+
5
+use Illuminate\Database\Eloquent\Factories\HasFactory;
6
+use Illuminate\Database\Eloquent\Model;
7
+
8
+class Expense extends Model
9
+{
10
+    use HasFactory;
11
+
12
+    protected $fillable = [
13
+        'expense_number',
14
+        'description',
15
+        'amount',
16
+        'user_id',
17
+        'outlet_id',
18
+    ];
19
+}

+ 17
- 0
app/Models/Laundry.php View File

@@ -0,0 +1,17 @@
1
+<?php
2
+
3
+namespace App\Models;
4
+
5
+use Illuminate\Database\Eloquent\Factories\HasFactory;
6
+use Illuminate\Database\Eloquent\Model;
7
+
8
+class Laundry extends Model
9
+{
10
+    use HasFactory;
11
+
12
+    protected $fillable = [
13
+        'name',
14
+        'price',
15
+        'unit',
16
+    ];
17
+}

+ 19
- 0
app/Models/Mutation.php View File

@@ -0,0 +1,19 @@
1
+<?php
2
+
3
+namespace App\Models;
4
+
5
+use Illuminate\Database\Eloquent\Factories\HasFactory;
6
+use Illuminate\Database\Eloquent\Model;
7
+
8
+class Mutation extends Model
9
+{
10
+    use HasFactory;
11
+
12
+    protected $fillable = [
13
+        'type',
14
+        'amount',
15
+        'outlet_id',
16
+        'transaction_id',
17
+        'expense_id',
18
+    ];
19
+}

+ 18
- 0
app/Models/Outlet.php View File

@@ -0,0 +1,18 @@
1
+<?php
2
+
3
+namespace App\Models;
4
+
5
+use Illuminate\Database\Eloquent\Factories\HasFactory;
6
+use Illuminate\Database\Eloquent\Model;
7
+
8
+class Outlet extends Model
9
+{
10
+    use HasFactory;
11
+
12
+    protected $fillable = [
13
+        'outlet_number',
14
+        'name',
15
+        'address',
16
+        'phone',
17
+    ];
18
+}

+ 15
- 0
app/Models/Role.php View File

@@ -0,0 +1,15 @@
1
+<?php
2
+
3
+namespace App\Models;
4
+
5
+use Illuminate\Database\Eloquent\Factories\HasFactory;
6
+use Illuminate\Database\Eloquent\Model;
7
+
8
+class Role extends Model
9
+{
10
+    use HasFactory;
11
+
12
+    protected $fillable = [
13
+        'name',
14
+    ];
15
+}

+ 21
- 0
app/Models/Transaction.php View File

@@ -0,0 +1,21 @@
1
+<?php
2
+
3
+namespace App\Models;
4
+
5
+use Illuminate\Database\Eloquent\Factories\HasFactory;
6
+use Illuminate\Database\Eloquent\Model;
7
+
8
+class Transaction extends Model
9
+{
10
+    use HasFactory;
11
+
12
+    protected $fillable = [
13
+        'transaction_number',
14
+        'discount',
15
+        'transaction_status_id',
16
+        'user_id',
17
+        'customer_id',
18
+        'laundry_id',
19
+        'outlet_id',
20
+    ];
21
+}

+ 19
- 0
app/Models/TransactionDetail.php View File

@@ -0,0 +1,19 @@
1
+<?php
2
+
3
+namespace App\Models;
4
+
5
+use Illuminate\Database\Eloquent\Factories\HasFactory;
6
+use Illuminate\Database\Eloquent\Model;
7
+
8
+class TransactionDetail extends Model
9
+{
10
+    use HasFactory;
11
+
12
+    protected $fillable = [
13
+        'price',
14
+        'discount',
15
+        'quantity',
16
+        'transaction_id',
17
+        'laundry_id',
18
+    ];
19
+}

+ 16
- 0
app/Models/TransactionStatus.php View File

@@ -0,0 +1,16 @@
1
+<?php
2
+
3
+namespace App\Models;
4
+
5
+use Illuminate\Database\Eloquent\Factories\HasFactory;
6
+use Illuminate\Database\Eloquent\Model;
7
+
8
+class TransactionStatus extends Model
9
+{
10
+    use HasFactory;
11
+
12
+    protected $fillable = [
13
+        'id',
14
+        'name',
15
+    ];
16
+}

+ 6
- 1
app/Models/User.php View File

@@ -2,7 +2,6 @@
2 2
 
3 3
 namespace App\Models;
4 4
 
5
-use Illuminate\Contracts\Auth\MustVerifyEmail;
6 5
 use Illuminate\Database\Eloquent\Factories\HasFactory;
7 6
 use Illuminate\Foundation\Auth\User as Authenticatable;
8 7
 use Illuminate\Notifications\Notifiable;
@@ -19,8 +18,14 @@ class User extends Authenticatable
19 18
      */
20 19
     protected $fillable = [
21 20
         'name',
21
+        'phone',
22 22
         'email',
23
+        'address',
24
+        'status',
25
+        'gender',
23 26
         'password',
27
+        'role_id',
28
+        'outlet_id',
24 29
     ];
25 30
 
26 31
     /**

+ 35
- 0
database/migrations/2022_02_22_031458_create_outlets_table.php View File

@@ -0,0 +1,35 @@
1
+<?php
2
+
3
+use Illuminate\Database\Migrations\Migration;
4
+use Illuminate\Database\Schema\Blueprint;
5
+use Illuminate\Support\Facades\Schema;
6
+
7
+return new class extends Migration
8
+{
9
+    /**
10
+     * Run the migrations.
11
+     *
12
+     * @return void
13
+     */
14
+    public function up()
15
+    {
16
+        Schema::create('outlets', function (Blueprint $table) {
17
+            $table->id();
18
+            $table->string('outlet_number');
19
+            $table->string('name');
20
+            $table->string('address');
21
+            $table->string('phone');
22
+            $table->timestamps();
23
+        });
24
+    }
25
+
26
+    /**
27
+     * Reverse the migrations.
28
+     *
29
+     * @return void
30
+     */
31
+    public function down()
32
+    {
33
+        Schema::dropIfExists('outlets');
34
+    }
35
+};

+ 36
- 0
database/migrations/2022_02_22_031511_create_customers_table.php View File

@@ -0,0 +1,36 @@
1
+<?php
2
+
3
+use Illuminate\Database\Migrations\Migration;
4
+use Illuminate\Database\Schema\Blueprint;
5
+use Illuminate\Support\Facades\Schema;
6
+
7
+return new class extends Migration
8
+{
9
+    /**
10
+     * Run the migrations.
11
+     *
12
+     * @return void
13
+     */
14
+    public function up()
15
+    {
16
+        Schema::create('customers', function (Blueprint $table) {
17
+            $table->id();
18
+            $table->string('customer_number');
19
+            $table->string('name');
20
+            $table->string('phone');
21
+            $table->string('address');
22
+            $table->enum('gender', ['Perempuan', 'Laki-laki']);
23
+            $table->timestamps();
24
+        });
25
+    }
26
+
27
+    /**
28
+     * Reverse the migrations.
29
+     *
30
+     * @return void
31
+     */
32
+    public function down()
33
+    {
34
+        Schema::dropIfExists('customers');
35
+    }
36
+};

+ 32
- 0
database/migrations/2022_02_22_031554_create_transaction_statuses_table.php View File

@@ -0,0 +1,32 @@
1
+<?php
2
+
3
+use Illuminate\Database\Migrations\Migration;
4
+use Illuminate\Database\Schema\Blueprint;
5
+use Illuminate\Support\Facades\Schema;
6
+
7
+return new class extends Migration
8
+{
9
+    /**
10
+     * Run the migrations.
11
+     *
12
+     * @return void
13
+     */
14
+    public function up()
15
+    {
16
+        Schema::create('transaction_statuses', function (Blueprint $table) {
17
+            $table->id();
18
+            $table->string('name');
19
+            $table->timestamps();
20
+        });
21
+    }
22
+
23
+    /**
24
+     * Reverse the migrations.
25
+     *
26
+     * @return void
27
+     */
28
+    public function down()
29
+    {
30
+        Schema::dropIfExists('transaction_status');
31
+    }
32
+};

+ 34
- 0
database/migrations/2022_02_22_031714_create_laundries_table.php View File

@@ -0,0 +1,34 @@
1
+<?php
2
+
3
+use Illuminate\Database\Migrations\Migration;
4
+use Illuminate\Database\Schema\Blueprint;
5
+use Illuminate\Support\Facades\Schema;
6
+
7
+return new class extends Migration
8
+{
9
+    /**
10
+     * Run the migrations.
11
+     *
12
+     * @return void
13
+     */
14
+    public function up()
15
+    {
16
+        Schema::create('laundries', function (Blueprint $table) {
17
+            $table->id();
18
+            $table->string('name');
19
+            $table->unsignedInteger('price');
20
+            $table->string('unit');
21
+            $table->timestamps();
22
+        });
23
+    }
24
+
25
+    /**
26
+     * Reverse the migrations.
27
+     *
28
+     * @return void
29
+     */
30
+    public function down()
31
+    {
32
+        Schema::dropIfExists('laundries');
33
+    }
34
+};

+ 32
- 0
database/migrations/2022_02_22_031726_create_roles_table.php View File

@@ -0,0 +1,32 @@
1
+<?php
2
+
3
+use Illuminate\Database\Migrations\Migration;
4
+use Illuminate\Database\Schema\Blueprint;
5
+use Illuminate\Support\Facades\Schema;
6
+
7
+return new class extends Migration
8
+{
9
+    /**
10
+     * Run the migrations.
11
+     *
12
+     * @return void
13
+     */
14
+    public function up()
15
+    {
16
+        Schema::create('roles', function (Blueprint $table) {
17
+            $table->id();
18
+            $table->string('name');
19
+            $table->timestamps();
20
+        });
21
+    }
22
+
23
+    /**
24
+     * Reverse the migrations.
25
+     *
26
+     * @return void
27
+     */
28
+    public function down()
29
+    {
30
+        Schema::dropIfExists('roles');
31
+    }
32
+};

database/migrations/2014_10_12_000000_create_users_table.php → database/migrations/2022_02_22_031727_create_users_table.php View File

@@ -16,9 +16,15 @@ return new class extends Migration
16 16
         Schema::create('users', function (Blueprint $table) {
17 17
             $table->id();
18 18
             $table->string('name');
19
+            $table->string('phone')->unique();
20
+            $table->string('address');
21
+            $table->boolean('status')->default(1);
22
+            $table->string('gender');
19 23
             $table->string('email')->unique();
20 24
             $table->timestamp('email_verified_at')->nullable();
21 25
             $table->string('password');
26
+            $table->foreignId('role_id')->constrained();
27
+            $table->foreignId('outlet_id')->constrained();
22 28
             $table->rememberToken();
23 29
             $table->timestamps();
24 30
         });

+ 38
- 0
database/migrations/2022_02_22_031728_create_transactions_table.php View File

@@ -0,0 +1,38 @@
1
+<?php
2
+
3
+use Illuminate\Database\Migrations\Migration;
4
+use Illuminate\Database\Schema\Blueprint;
5
+use Illuminate\Support\Facades\Schema;
6
+
7
+return new class extends Migration
8
+{
9
+    /**
10
+     * Run the migrations.
11
+     *
12
+     * @return void
13
+     */
14
+    public function up()
15
+    {
16
+        Schema::create('transactions', function (Blueprint $table) {
17
+            $table->id();
18
+            $table->string('transaction_number');
19
+            $table->unsignedInteger('discount');
20
+            $table->foreignId('transaction_status_id')->constrained();
21
+            $table->foreignId('user_id')->constrained();
22
+            $table->foreignId('customer_id')->constrained();
23
+            $table->foreignId('laundry_id')->constrained();
24
+            $table->foreignId('outlet_id')->constrained();
25
+            $table->timestamps();
26
+        });
27
+    }
28
+
29
+    /**
30
+     * Reverse the migrations.
31
+     *
32
+     * @return void
33
+     */
34
+    public function down()
35
+    {
36
+        Schema::dropIfExists('tansactions');
37
+    }
38
+};

+ 36
- 0
database/migrations/2022_02_22_031729_create_expenses_table.php View File

@@ -0,0 +1,36 @@
1
+<?php
2
+
3
+use Illuminate\Database\Migrations\Migration;
4
+use Illuminate\Database\Schema\Blueprint;
5
+use Illuminate\Support\Facades\Schema;
6
+
7
+return new class extends Migration
8
+{
9
+    /**
10
+     * Run the migrations.
11
+     *
12
+     * @return void
13
+     */
14
+    public function up()
15
+    {
16
+        Schema::create('expenses', function (Blueprint $table) {
17
+            $table->id();
18
+            $table->string('expense_number');
19
+            $table->text('description');
20
+            $table->unsignedBigInteger('amount');
21
+            $table->foreignId('user_id')->constrained();
22
+            $table->foreignId('outlet_id')->constrained();
23
+            $table->timestamps();
24
+        });
25
+    }
26
+
27
+    /**
28
+     * Reverse the migrations.
29
+     *
30
+     * @return void
31
+     */
32
+    public function down()
33
+    {
34
+        Schema::dropIfExists('expenses');
35
+    }
36
+};

+ 36
- 0
database/migrations/2022_02_22_031729_create_mutations_table.php View File

@@ -0,0 +1,36 @@
1
+<?php
2
+
3
+use Illuminate\Database\Migrations\Migration;
4
+use Illuminate\Database\Schema\Blueprint;
5
+use Illuminate\Support\Facades\Schema;
6
+
7
+return new class extends Migration
8
+{
9
+    /**
10
+     * Run the migrations.
11
+     *
12
+     * @return void
13
+     */
14
+    public function up()
15
+    {
16
+        Schema::create('mutations', function (Blueprint $table) {
17
+            $table->id();
18
+            $table->string('type');
19
+            $table->unsignedBigInteger('amount');
20
+            $table->foreignId('outlet_id')->constrained();
21
+            $table->foreignId('transaction_id')->constrained();
22
+            $table->foreignId('expense_id')->constrained();
23
+            $table->timestamps();
24
+        });
25
+    }
26
+
27
+    /**
28
+     * Reverse the migrations.
29
+     *
30
+     * @return void
31
+     */
32
+    public function down()
33
+    {
34
+        Schema::dropIfExists('mutations');
35
+    }
36
+};

+ 36
- 0
database/migrations/2022_02_22_031729_create_transaction_details_table.php View File

@@ -0,0 +1,36 @@
1
+<?php
2
+
3
+use Illuminate\Database\Migrations\Migration;
4
+use Illuminate\Database\Schema\Blueprint;
5
+use Illuminate\Support\Facades\Schema;
6
+
7
+return new class extends Migration
8
+{
9
+    /**
10
+     * Run the migrations.
11
+     *
12
+     * @return void
13
+     */
14
+    public function up()
15
+    {
16
+        Schema::create('transaction_details', function (Blueprint $table) {
17
+            $table->id();
18
+            $table->unsignedInteger('price');
19
+            $table->unsignedInteger('discount');
20
+            $table->unsignedInteger('quantity');
21
+            $table->foreignId('transaction_id')->constrained();
22
+            $table->foreignId('laundry_id')->constrained();
23
+            $table->timestamps();
24
+        });
25
+    }
26
+
27
+    /**
28
+     * Reverse the migrations.
29
+     *
30
+     * @return void
31
+     */
32
+    public function down()
33
+    {
34
+        Schema::dropIfExists('transacation_details');
35
+    }
36
+};

+ 109
- 0
designs/diagrams/database.puml View File

@@ -0,0 +1,109 @@
1
+@startuml Database
2
+entity  Outlet {
3
+  * id
4
+  __
5
+  * outlet_number
6
+  * name
7
+  * address
8
+  * phone
9
+}
10
+
11
+entity Customer {
12
+  * id
13
+  __
14
+  * customer_number
15
+  * name
16
+  * phone
17
+  * address
18
+  * gender
19
+}
20
+
21
+entity Mutation {
22
+  * id
23
+  __
24
+  * type
25
+  * amount
26
+  * outlet_id
27
+  transaction_id
28
+  expense_id
29
+}
30
+
31
+entity Transaction {
32
+  * id
33
+  __
34
+  * transaction_number
35
+  discount
36
+  * transaction_status_id
37
+  * user_id
38
+  * customer_id
39
+  * laundry_id
40
+  * outlet_id
41
+}
42
+
43
+entity TransactionDetail {
44
+  * id
45
+  __
46
+  * price
47
+  discount
48
+  * quantity
49
+  * transaction_id
50
+  * laundry_id
51
+}
52
+
53
+entity Laundry {
54
+  * id
55
+  __
56
+  * name
57
+  * price
58
+  * unit
59
+}
60
+
61
+entity TransactionStatus {
62
+  * id
63
+  __
64
+  * name
65
+}
66
+
67
+entity User {
68
+  * id
69
+  __
70
+  * name
71
+  * phone
72
+  * email
73
+  * address
74
+  * status
75
+  * gender
76
+  * password
77
+  * role_id
78
+  * outlet_id
79
+}
80
+
81
+entity Role {
82
+  * id
83
+  __
84
+  * name
85
+}
86
+
87
+entity Expense {
88
+  * id
89
+  __
90
+  * expense_number
91
+  * description
92
+  * amount
93
+  * user_id
94
+  * outlet_id
95
+}
96
+
97
+Mutation }|--|| Expense
98
+Mutation }|--|| Transaction
99
+Mutation ||--|{ Outlet
100
+Transaction }|--|| TransactionDetail
101
+Transaction ||--|{ TransactionStatus
102
+Transaction ||--|{ Outlet
103
+Transaction ||--|{ Customer
104
+Transaction ||--|{ User
105
+Expense ||--|{ User
106
+Expense ||--|{ Outlet
107
+User ||--|{ Role
108
+User ||--|{ Outlet
109
+TransactionDetail ||--|{ Laundry

BIN
designs/diagrams/database/Database.png View File