Blame view

database/migrations/2017_09_01_000000_create_bills_table.php 3.78 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 CreateBillsTable extends Migration
  {
      /**
       * Run the migrations.
       *
       * @return void
       */
      public function up()
      {
          Schema::create('bills', function (Blueprint $table) {
              $table->increments('id');
              $table->integer('company_id');
              $table->string('bill_number');
              $table->string('order_number')->nullable();
              $table->string('bill_status_code');
              $table->date('billed_at');
              $table->date('due_at');
              $table->double('amount', 15, 4);
              $table->string('currency_code');
              $table->double('currency_rate', 15, 8);
              $table->integer('vendor_id');
              $table->string('vendor_name');
              $table->string('vendor_email');
              $table->string('vendor_tax_number')->nullable();
              $table->string('vendor_phone')->nullable();
              $table->text('vendor_address')->nullable();
              $table->text('notes')->nullable();
              $table->string('attachment')->nullable();
              $table->timestamps();
              $table->softDeletes();
  
              $table->index('company_id');
              $table->unique(['company_id', 'bill_number', 'deleted_at']);
          });
  
          Schema::create('bill_items', function (Blueprint $table) {
              $table->increments('id');
              $table->integer('company_id');
              $table->integer('bill_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->float('tax', 15, 4)->default('0.0000');
              $table->integer('tax_id');
              $table->timestamps();
              $table->softDeletes();
  
              $table->index('company_id');
          });
  
          Schema::create('bill_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('bill_payments', function (Blueprint $table) {
              $table->increments('id');
              $table->integer('company_id');
              $table->integer('bill_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('bill_histories', function (Blueprint $table) {
              $table->increments('id');
              $table->integer('company_id');
              $table->integer('bill_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('bills');
          Schema::drop('bill_items');
          Schema::drop('bill_statuses');
          Schema::drop('bill_payments');
          Schema::drop('bill_histories');
      }
  }