Viewing File: /home/ubuntu/efidemo/database/migrations/2022_06_28_120141_create_transaction_related_tables.php

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateTransactionRelatedTables extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {   
        if(!Schema::hasTable('user_cards')) {

            Schema::create('user_cards', function (Blueprint $table) {
                $table->id();
                $table->string('unique_id')->unique();
                $table->foreignId('user_id')->default(0);
                $table->string('customer_id')->default('');
                $table->string('card_token')->default('');
                $table->string('card_holder_name')->default('');
                $table->string('card_type')->default('');
                $table->string('last_four')->default('');
                $table->integer('is_default')->default(YES);
                $table->tinyInteger('status')->default(APPROVED);
                $table->timestamps();
            });

        }

        if(!Schema::hasTable('user_billing_accounts')) {

            Schema::create('user_billing_accounts', function (Blueprint $table) {
                $table->id();
                $table->string('unique_id')->unique();
                $table->foreignId('user_id')->default(0);
                $table->string('nickname')->nullable();
                $table->string('first_name')->default('');
                $table->string('last_name')->default('');
                $table->string('business_name')->nullable();
                $table->string('bank_name')->default('');
                $table->string('bank_type')->default(SAVINGS);
                $table->string('account_holder_name')->default('');
                $table->string('account_number')->default('');
                $table->string('ifsc_code')->default('');
                $table->string('swift_code')->default('');
                $table->string('iban_number')->default('');
                $table->string('route_number')->default('');
                $table->tinyInteger('is_default')->default(NO);
                $table->tinyInteger('status')->default(APPROVED);
                $table->timestamps();
            
            });
            
        }

        if(!Schema::hasTable('user_wallets')) {

            Schema::create('user_wallets', function (Blueprint $table) {
                $table->id();
                $table->string('unique_id')->unique();
                $table->foreignId('user_id');
                $table->float('total')->default(0.00);
                $table->float('onhold')->default(0.00);
                $table->float('used')->default(0.00);
                $table->float('remaining')->default(0.00);
                $table->tinyInteger('status')->default(APPROVED);
                $table->timestamps();
            });
            
        }

        if(!Schema::hasTable('user_wallet_payments')) {

            Schema::create('user_wallet_payments', function (Blueprint $table) {
                $table->id();
                $table->string('unique_id')->unique();
                $table->foreignId('user_id');
                $table->foreignId('to_user_id')->default(0);
                $table->foreignId('received_from_user_id')->default(0);
                $table->string('payment_id');
                $table->string('payment_type')->default(WALLET_PAYMENT_TYPE_ADD);
                $table->string('amount_type')->default(WALLET_PAYMENT_TYPE_ADD);
                $table->float('amount')->default(0.00);
                $table->float('requested_amount')->default(0.00);
                $table->float('paid_amount')->default(0.00);
                $table->string('currency')->default('$');
                $table->string('payment_mode')->default(CARD);
                $table->dateTime('paid_date')->nullable();
                $table->string('message')->default('');
                $table->tinyInteger('is_cancelled')->default(0);
                $table->string('bank_statement_picture')->default('');
                $table->tinyInteger('is_admin_approved')->default(NO);
                $table->foreignId('user_billing_account_id')->default(0);
                $table->string('cancelled_reason')->default('');
                $table->string('updated_by')->default('user');
                $table->tinyInteger('payment_status')->default(PENDING);
                $table->tinyInteger('status')->default(APPROVED);
                $table->timestamps();
            });
            
        }

        if(!Schema::hasTable('user_withdrawals')) {

            Schema::create('user_withdrawals', function (Blueprint $table) {
                $table->id();
                $table->string('unique_id')->unique();
                $table->foreignId('user_id');
                $table->foreignId('user_wallet_payment_id')->default(0);
                $table->string('payment_id')->default('');
                $table->string('payment_mode')->default(CARD);
                $table->float('requested_amount')->default(0.00);
                $table->float('paid_amount')->default(0.00);
                $table->tinyInteger('is_cancelled')->default(NO);
                $table->text('cancel_reason')->nullable();
                $table->foreignId('user_billing_account_id')->default(0);
                $table->tinyInteger('status')->default(PENDING)->comment("0 - pending, 1 - paid, 2 - rejected, 3 - cancelled");
                $table->timestamps();
            });
            
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('user_cards');
        Schema::dropIfExists('user_billing_accounts');
        Schema::dropIfExists('user_wallets');
        Schema::dropIfExists('user_wallet_payments');
        Schema::dropIfExists('user_withdrawals');
    }
}
Back to Directory File Manager