1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-09 20:52:56 +01:00

Update DB structure

This commit is contained in:
Joshua Dwire 2016-05-24 14:16:42 -04:00
parent 5958cd2c5e
commit f8835268b4
5 changed files with 107 additions and 0 deletions

View File

@ -60,6 +60,15 @@ class Contact extends EntityModel implements AuthenticatableContract, CanResetPa
}
}
public function getContactKeyAttribute($contact_key)
{
if (empty($contact_key) && $this->id) {
$this->contact_key = $contact_key = str_random(RANDOM_KEY_LENGTH);
static::where('id', $this->id)->update(array('contact_key' => $contact_key));
}
return $contact_key;
}
public function getFullName()
{
if ($this->first_name || $this->last_name) {

View File

@ -180,10 +180,30 @@ class Payment extends EntityModel
return PaymentMethod::lookupBankData($this->routing_number);
}
public function getBankNameAttribute($bank_name)
{
if ($bank_name) {
return $bank_name;
}
$bankData = $this->bank_data;
return $bankData?$bankData->name:null;
}
public function getLast4Attribute($value)
{
return $value ? str_pad($value, 4, '0', STR_PAD_LEFT) : null;
}
public function getIpAddressAttribute($value)
{
return !$value?$value:inet_ntop($value);
}
public function setIpAddressAttribute($value)
{
$this->attributes['ip_address'] = inet_pton($value);
}
}
Payment::creating(function ($payment) {

View File

@ -71,6 +71,16 @@ class PaymentMethod extends EntityModel
return static::lookupBankData($this->routing_number);
}
public function getBankNameAttribute($bank_name)
{
if ($bank_name) {
return $bank_name;
}
$bankData = $this->bank_data;
return $bankData?$bankData->name:null;
}
public function getLast4Attribute($value)
{
return $value ? str_pad($value, 4, '0', STR_PAD_LEFT) : null;
@ -148,6 +158,16 @@ class PaymentMethod extends EntityModel
return null;
}
}
public function getIpAddressAttribute($value)
{
return !$value?$value:inet_ntop($value);
}
public function setIpAddressAttribute($value)
{
$this->attributes['ip_address'] = inet_pton($value);
}
}
PaymentMethod::deleting(function($paymentMethod) {

View File

@ -14,6 +14,7 @@ class ContactRepository extends BaseRepository
$contact->send_invoice = true;
$contact->client_id = $data['client_id'];
$contact->is_primary = Contact::scope()->where('client_id', '=', $contact->client_id)->count() == 0;
$contact->contact_key = str_random(RANDOM_KEY_LENGTH);
} else {
$contact = Contact::scope($publicId)->firstOrFail();
}

View File

@ -0,0 +1,57 @@
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class WePayAch extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('contacts', function(Blueprint $table) {
$table->string('contact_key')->index()->default(null);
});
Schema::table('payment_methods', function($table)
{
$table->string('bank_name')->nullable();
});
Schema::table('payments', function($table)
{
$table->string('bank_name')->nullable();
});
Schema::table('accounts', function($table)
{
$table->boolean('auto_bill_on_due_date')->default(false);
});
DB::statement('ALTER TABLE `payments` ADD `ip_address` VARBINARY(16)');
DB::statement('ALTER TABLE `payment_methods` ADD `ip_address` VARBINARY(16)');
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('contacts', function(Blueprint $table) {
$table->dropColumn('contact_key');
});
Schema::table('payments', function($table) {
$table->dropColumn('ip_address');
});
Schema::table('payment_methods', function($table) {
$table->dropColumn('ip_address');
});
}
}