create migration invoices

This commit is contained in:
Muhammad Fajar
2022-11-08 10:52:00 +07:00
parent a2e6eb6b8c
commit 16dd3ab1df
2 changed files with 110 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('invoices', function (Blueprint $table) {
$table->id();
$table->string('invoice_number')->nullable();
$table->string('status')->nullable();
$table->string('cancellation_reason')->nullable();
$table->string('subject')->nullable();
$table->string('recipient')->nullable();
$table->date('invoiced_date')->nullable();
$table->string('total_net')->nullable();
$table->string('total_gross')->nullable();
$table->string('details')->nullable();
$table->string('note')->nullable();
$table->timestamp('waiting_for_payment_at')->nullable();
$table->timestamp('paid_at')->nullable();
$table->timestamp('expired_at')->nullable();
$table->timestamps();
$table->softDeletes();
$table->foreignId('created_by')->nullable()->index();
$table->foreignId('updated_by')->nullable()->index();
$table->foreignId('deleted_by')->nullable()->index();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('invoices');
}
};

View File

@@ -0,0 +1,60 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('invoice_items', function (Blueprint $table) {
$table->id();
$table->nullableMorphs('itemable');
$table->foreignId('parent_id')->nullable();
$table->unsignedBigInteger('invoice_id')->nullable();
$table->unsignedBigInteger('price_group_id')->nullable();
$table->unsignedBigInteger('organization_id')->nullable();
$table->string('type')->nullable();
$table->string('price_gross')->nullable();
$table->string('discount_type')->nullable()->default('percentage');
$table->string('discount_percentage')->nullable();
$table->string('discount_value')->nullable();
$table->string('tax_type')->nullable()->default('percentage');
$table->string('tax_percentage')->nullable();
$table->string('tax_value')->nullable();
$table->string('price_net')->nullable()->comment("price_net = price_gross - discount_value + tax_value");
$table->string('total_net')->nullable()->comment("total_net = price_net * quantity");
$table->string('notes')->nullable();
$table->timestamps();
$table->softDeletes();
$table->unsignedBigInteger('created_by')->nullable();
$table->unsignedBigInteger('updated_by')->nullable();
$table->unsignedBigInteger('deleted_by')->nullable();
$table->index(['itemable_id', 'itemable_type']);
$table->index('organization_id');
$table->index('invoice_id');
$table->index('price_group_id');
$table->index('created_by');
$table->index('updated_by');
$table->index('deleted_by');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('invoice_items');
}
};