invoice update

This commit is contained in:
Abhishek Mali
2025-11-17 10:33:11 +05:30
parent cfd128cf9b
commit df89031d36
16 changed files with 1330 additions and 139 deletions

View File

@@ -0,0 +1,70 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateInvoicesTable extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('invoices', function (Blueprint $table) {
$table->id();
// Links
$table->unsignedBigInteger('order_id')->index();
$table->unsignedBigInteger('customer_id')->nullable()->index(); // snapshot link if available
$table->string('mark_no')->nullable()->index();
// Invoice identity
$table->string('invoice_number')->unique();
$table->date('invoice_date')->nullable();
$table->date('due_date')->nullable();
// Payment / status
$table->string('payment_method')->nullable();
$table->string('reference_no')->nullable();
$table->enum('status', ['pending','paid','overdue'])->default('pending');
// Amounts
$table->decimal('final_amount', 14, 2)->default(0.00); // editable by user
$table->decimal('gst_percent', 5, 2)->default(0.00); // editable by user
$table->decimal('gst_amount', 14, 2)->default(0.00); // auto-calculated
$table->decimal('final_amount_with_gst', 14, 2)->default(0.00); // auto-calculated
// Customer snapshot (immutable fields)
$table->string('customer_name')->nullable();
$table->string('company_name')->nullable();
$table->string('customer_email')->nullable();
$table->string('customer_mobile')->nullable();
$table->text('customer_address')->nullable();
$table->string('pincode')->nullable();
// PDF / notes
$table->string('pdf_path')->nullable();
$table->text('notes')->nullable();
$table->timestamps();
// Foreign keys (optional — adjust table names/namespaces if yours are different)
$table->foreign('order_id')->references('id')->on('orders')->onDelete('cascade');
// customer_id may reference users table, keep nullable to avoid migration order issues
$table->foreign('customer_id')->references('id')->on('users')->onDelete('set null');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('invoices', function (Blueprint $table) {
$table->dropForeign(['order_id']);
$table->dropForeign(['customer_id']);
});
Schema::dropIfExists('invoices');
}
}

View File

@@ -0,0 +1,52 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateInvoiceItemsTable extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('invoice_items', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('invoice_id')->index();
// Snapshot of order item fields (not editable)
$table->text('description')->nullable();
$table->integer('ctn')->default(0);
$table->integer('qty')->default(0);
$table->integer('ttl_qty')->default(0);
$table->string('unit')->nullable();
$table->decimal('price', 14, 2)->default(0.00);
$table->decimal('ttl_amount', 14, 2)->default(0.00);
$table->decimal('cbm', 12, 3)->default(0.000);
$table->decimal('ttl_cbm', 12, 3)->default(0.000);
$table->decimal('kg', 12, 3)->default(0.000);
$table->decimal('ttl_kg', 12, 3)->default(0.000);
$table->string('shop_no')->nullable();
$table->timestamps();
// FK
$table->foreign('invoice_id')->references('id')->on('invoices')->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('invoice_items', function (Blueprint $table) {
$table->dropForeign(['invoice_id']);
});
Schema::dropIfExists('invoice_items');
}
}