From 41e88ac828fcc3b1620fece898ead928440b15aa Mon Sep 17 00:00:00 2001 From: chris Date: Mon, 25 Nov 2024 17:45:24 +0100 Subject: [PATCH] Create the first models with migrations for handling invoices. --- app/Models/Address.php | 11 ++++++ app/Models/Customer.php | 11 ++++++ app/Models/Invoice.php | 10 +++++ app/Models/Invoiceitem.php | 11 ++++++ app/Models/Payment.php | 11 ++++++ ...24_11_25_161631_create_customers_table.php | 31 +++++++++++++++ ...24_11_25_161729_create_addresses_table.php | 38 +++++++++++++++++++ ...024_11_25_162738_create_invoices_table.php | 36 ++++++++++++++++++ ...11_25_163628_create_invoiceitems_table.php | 35 +++++++++++++++++ ...024_11_25_164059_create_payments_table.php | 34 +++++++++++++++++ 10 files changed, 228 insertions(+) create mode 100644 app/Models/Address.php create mode 100644 app/Models/Customer.php create mode 100644 app/Models/Invoice.php create mode 100644 app/Models/Invoiceitem.php create mode 100644 app/Models/Payment.php create mode 100644 database/migrations/2024_11_25_161631_create_customers_table.php create mode 100644 database/migrations/2024_11_25_161729_create_addresses_table.php create mode 100644 database/migrations/2024_11_25_162738_create_invoices_table.php create mode 100644 database/migrations/2024_11_25_163628_create_invoiceitems_table.php create mode 100644 database/migrations/2024_11_25_164059_create_payments_table.php diff --git a/app/Models/Address.php b/app/Models/Address.php new file mode 100644 index 0000000..7e4ccfe --- /dev/null +++ b/app/Models/Address.php @@ -0,0 +1,11 @@ +id(); + + $table->string('name'); + $table->string('email')->unique(); + + $table->timestamps(); + $table->softDeletes(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('customers'); + } +}; diff --git a/database/migrations/2024_11_25_161729_create_addresses_table.php b/database/migrations/2024_11_25_161729_create_addresses_table.php new file mode 100644 index 0000000..c14419f --- /dev/null +++ b/database/migrations/2024_11_25_161729_create_addresses_table.php @@ -0,0 +1,38 @@ +id(); + $table->foreignId('user_id')->constrained(); + + $table->string('name'); + $table->string('email')->nullable(); + $table->string('phone')->nullable(); + $table->string('address')->nullable(); + $table->string('city')->nullable(); + $table->string('state')->nullable(); + $table->string('zip')->nullable(); + $table->string('country')->nullable(); + + $table->timestamps(); + $table->softDeletes(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('addresses'); + } +}; diff --git a/database/migrations/2024_11_25_162738_create_invoices_table.php b/database/migrations/2024_11_25_162738_create_invoices_table.php new file mode 100644 index 0000000..a3ba443 --- /dev/null +++ b/database/migrations/2024_11_25_162738_create_invoices_table.php @@ -0,0 +1,36 @@ +id(); + $table->foreignId('user_id')->constrained(); + $table->foreignId('customer_id')->constrained(); + $table->foreignId('address_id')->constrained(); + $table->foreign('delivery_id')->references('id')->on('addresses'); + + $table->string('invoice_number'); + $table->string('type'); // Map to external formats + $table->string('status'); // Open, payed ... + + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('invoices'); + } +}; diff --git a/database/migrations/2024_11_25_163628_create_invoiceitems_table.php b/database/migrations/2024_11_25_163628_create_invoiceitems_table.php new file mode 100644 index 0000000..625abcf --- /dev/null +++ b/database/migrations/2024_11_25_163628_create_invoiceitems_table.php @@ -0,0 +1,35 @@ +id(); + $table->foreignId('invoice_id')->constrained(); + + $table->decimal('amount', 8, 2); + $table->decimal('discount', 8, 2); + $table->decimal('tax', 8, 2); + $table->decimal('price', 8, 2); + $table->decimal('total', 8, 2); + + $table->timestamps(); + $table->softDeletes(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('invoiceitems'); + } +}; diff --git a/database/migrations/2024_11_25_164059_create_payments_table.php b/database/migrations/2024_11_25_164059_create_payments_table.php new file mode 100644 index 0000000..2072a47 --- /dev/null +++ b/database/migrations/2024_11_25_164059_create_payments_table.php @@ -0,0 +1,34 @@ +id(); + $table->foreignId('invoice_id')->constrained(); + + $table->decimal('paid_amount', 15, 2); + $table->string('status'); + $table->string('payment_method')->nullable(); + + $table->timestamps(); + $table->softDeletes(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('payments'); + } +};