Blame view

database/migrations/2017_09_01_000000_create_invoices_table.php 3.85 KB
b7c7a5f6   Alexey Boroda   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
  <?php
  
  use Illuminate\Database\Migrations\Migration;
  use Illuminate\Database\Schema\Blueprint;
  
  class CreateInvoicesTable extends Migration
  {
      /**
       * Run the migrations.
       *
       * @return void
       */
      public function up()
      {
          Schema::create('invoices', function (Blueprint $table) {
              $table->increments('id');
              $table->integer('company_id');
              $table->string('invoice_number');
              $table->string('order_number')->nullable();
              $table->string('invoice_status_code');
              $table->date('invoiced_at');
              $table->date('due_at');
              $table->double('amount', 15, 4);
              $table->string('currency_code');
              $table->double('currency_rate', 15, 8);
              $table->integer('customer_id');
              $table->string('customer_name');
              $table->string('customer_email');
              $table->string('customer_tax_number')->nullable();
              $table->string('customer_phone')->nullable();
              $table->text('customer_address')->nullable();
              $table->text('notes')->nullable();
              $table->string('attachment')->nullable();
              $table->timestamps();
              $table->softDeletes();
  
              $table->index('company_id');
              $table->unique(['company_id', 'invoice_number', 'deleted_at']);
          });
  
          Schema::create('invoice_items', function (Blueprint $table) {
              $table->increments('id');
              $table->integer('company_id');
              $table->integer('invoice_id');
              $table->integer('item_id')->nullable();
              $table->string('name');
              $table->string('sku')->nullable();
              $table->double('quantity', 7, 2);
              $table->double('price', 15, 4);
              $table->double('total', 15, 4);
              $table->double('tax', 15, 4)->default('0.0000');
              $table->integer('tax_id');
              $table->timestamps();
              $table->softDeletes();
  
              $table->index('company_id');
          });
  
          Schema::create('invoice_statuses', function (Blueprint $table) {
              $table->increments('id');
              $table->integer('company_id');
              $table->string('name');
              $table->string('code');
              $table->timestamps();
              $table->softDeletes();
  
              $table->index('company_id');
          });
  
          Schema::create('invoice_payments', function (Blueprint $table) {
              $table->increments('id');
              $table->integer('company_id');
              $table->integer('invoice_id');
              $table->integer('account_id');
              $table->date('paid_at');
              $table->double('amount', 15, 4);
              $table->string('currency_code');
              $table->double('currency_rate', 15, 8);
              $table->text('description')->nullable();
              $table->string('payment_method');
              $table->string('reference')->nullable();
              $table->string('attachment')->nullable();
              $table->timestamps();
              $table->softDeletes();
  
              $table->index('company_id');
          });
  
          Schema::create('invoice_histories', function (Blueprint $table) {
              $table->increments('id');
              $table->integer('company_id');
              $table->integer('invoice_id');
              $table->string('status_code');
              $table->boolean('notify');
              $table->text('description')->nullable();
              $table->timestamps();
              $table->softDeletes();
  
              $table->index('company_id');
          });
      }
  
      /**
       * Reverse the migrations.
       *
       * @return void
       */
      public function down()
      {
          Schema::drop('invoices');
          Schema::drop('invoice_items');
          Schema::drop('invoice_statuses');
          Schema::drop('invoice_payments');
          Schema::drop('invoice_histories');
      }
  }