1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 16:31:33 +02:00
invoiceninja/database/migrations/2016_04_23_182223_payments_changes.php

89 lines
2.7 KiB
PHP
Raw Normal View History

2016-04-23 22:40:19 +02:00
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class PaymentsChanges extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::dropIfExists('payment_statuses');
2016-05-09 22:29:02 +02:00
2016-04-23 22:40:19 +02:00
Schema::create('payment_statuses', function($table)
{
$table->increments('id');
$table->string('name');
});
2016-05-09 22:29:02 +02:00
2016-04-23 22:40:19 +02:00
(new \PaymentStatusSeeder())->run();
2016-05-09 22:29:02 +02:00
2016-04-23 22:40:19 +02:00
Schema::table('payments', function($table)
{
$table->decimal('refunded', 13, 2);
2016-05-06 23:05:42 +02:00
$table->unsignedInteger('payment_status_id')->default(PAYMENT_STATUS_COMPLETED);
2016-04-23 22:40:19 +02:00
$table->foreign('payment_status_id')->references('id')->on('payment_statuses');
2016-05-09 22:29:02 +02:00
$table->unsignedInteger('routing_number')->nullable();
$table->smallInteger('last4')->unsigned()->nullable();
$table->date('expiration')->nullable();
2016-04-30 23:54:56 +02:00
$table->text('gateway_error')->nullable();
2016-05-07 04:33:03 +02:00
$table->string('email')->nullable();
2016-04-23 22:40:19 +02:00
});
Schema::table('invoices', function($table)
{
2016-05-09 22:29:02 +02:00
$table->boolean('client_enable_auto_bill')->default(false);
});
\DB::table('invoices')
->where('auto_bill', '=', 1)
2016-05-09 22:29:02 +02:00
->update(array('client_enable_auto_bill' => 1, 'auto_bill' => AUTO_BILL_OPT_OUT));
2016-04-23 22:40:19 +02:00
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('payments', function($table)
{
$table->dropColumn('refunded');
$table->dropForeign('payments_payment_status_id_foreign');
$table->dropColumn('payment_status_id');
$table->dropColumn('routing_number');
$table->dropColumn('last4');
$table->dropColumn('expiration');
2016-04-30 23:54:56 +02:00
$table->dropColumn('gateway_error');
2016-05-07 04:33:03 +02:00
$table->dropColumn('email');
2016-04-23 22:40:19 +02:00
});
2016-05-09 22:29:02 +02:00
\DB::table('invoices')
->where(function($query){
$query->where('auto_bill', '=', AUTO_BILL_ALWAYS);
$query->orwhere(function($query){
$query->where('auto_bill', '!=', AUTO_BILL_OFF);
$query->where('client_enable_auto_bill', '=', 1);
});
})
->update(array('auto_bill' => 1));
\DB::table('invoices')
->where('auto_bill', '!=', 1)
->update(array('auto_bill' => 0));
Schema::table('invoices', function ($table) {
2016-05-09 22:29:02 +02:00
$table->dropColumn('client_enable_auto_bill');
});
2016-04-23 22:40:19 +02:00
Schema::dropIfExists('payment_statuses');
}
}