Rename ab_account to accounts

This commit is contained in:
Deon George 2021-07-07 17:45:16 +10:00
parent f6751e7a63
commit 24ff62094a
No known key found for this signature in database
GPG Key ID: 7670E8DC27415254
5 changed files with 41 additions and 106 deletions

View File

@ -1,72 +0,0 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Models\{Account,User};
class UserAccountMerge extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'user:merge';
/**
* The console command description.
*
* @var string
*/
protected $description = 'This utility will create a User account from the Account entries';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
foreach (Account::all() as $ao)
{
if (is_null($ao->user_id) AND $ao->email)
{
$o = User::where('email',$ao->email)->first();
if (! $o) {
$o = new User;
$o->id = $ao->id;
$o->site_id = $ao->site_id;
$o->email = $ao->email;
$o->password = $ao->password;
$o->active = $ao->active;
$o->title = $ao->title;
$o->firstname = $ao->first_name;
$o->lastname = $ao->last_name;
$o->country_id = $ao->country_id;
$o->address1 = $ao->address1;
$o->address2 = $ao->address2;
$o->city = $ao->city;
$o->state = $ao->state;
$o->postcode = $ao->zip;
$o->save();
}
$ao->user_id = $o->id;
$ao->save();
}
}
}
}

View File

@ -26,8 +26,8 @@ class Account extends Model implements IDs
const RECORD_ID = 'account'; const RECORD_ID = 'account';
public $incrementing = FALSE; public $incrementing = FALSE;
protected $table = 'ab_account'; const CREATED_AT = 'date_orig';
public $timestamps = FALSE; const UPDATED_AT = 'date_last';
protected $appends = [ protected $appends = [
'active_display', 'active_display',
@ -97,30 +97,14 @@ class Account extends Model implements IDs
public function scopeSearch($query,string $term) public function scopeSearch($query,string $term)
{ {
// Build our where clause // Build our where clause
// First Name, Last name if (is_numeric($term)) {
if (preg_match('/\ /',$term)) {
[$fn,$ln] = explode(' ',$term,2);
$query->where(function($query1) use ($fn,$ln,$term) {
$query1->where(function($query2) use ($fn,$ln) {
return $query2
->where('first_name','like','%'.$fn.'%')
->where('last_name','like','%'.$ln.'%');
})
->orWhere('company','like','%'.$term.'%');
});
} elseif (is_numeric($term)) {
$query->where('id','like','%'.$term.'%'); $query->where('id','like','%'.$term.'%');
} elseif (preg_match('/\@/',$term)) {
$query->where('email','like','%'.$term.'%');
} else { } else {
$query $query->where('company','like','%'.$term.'%')
->where('company','like','%'.$term.'%') ->orWhere('address1','like','%'.$term.'%')
->orWhere('first_name','like','%'.$term.'%') ->orWhere('address2','like','%'.$term.'%')
->orWhere('last_name','like','%'.$term.'%'); ->orWhere('city','like','%'.$term.'%');
} }
return $query; return $query;

View File

@ -37,23 +37,13 @@ class AccountFactory extends Factory
'country_id' => $co->id, 'country_id' => $co->id,
// 'rtm_id', // 'rtm_id',
'currency_id' => $cyo->id, 'currency_id' => $cyo->id,
// 'username',
// 'password',
'active' => TRUE, 'active' => TRUE,
// 'first_name',
// 'last_name',
// 'title',
// 'email',
// 'company', // 'company',
// 'address1', // 'address1',
// 'address2', // 'address2',
// 'city', // 'city',
// 'state', // 'state',
// 'zip', // 'zip',
// 'email_type',
// 'invoice_delivery',
// 'mail_type',
// 'remember_token',
// 'user_id', // 'user_id',
]; ];
} }

View File

@ -0,0 +1,33 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class ReworkAccount extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('ab_account', function (Blueprint $table) {
$table->dropUnique('uq_username');
$table->dropColumn(['username','password','first_name','last_name','title','email','email_type','invoice_delivery','mail_type','remember_token']);
});
DB::statement('ALTER TABLE ab_account RENAME TO accounts');
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//abort(500,'cant go back');
}
}

View File

@ -49,7 +49,7 @@
<strong>{{ $o->account->company }}</strong><br> <strong>{{ $o->account->company }}</strong><br>
{!! join('<br>',$o->account->address) !!} {!! join('<br>',$o->account->address) !!}
<br> <br>
<strong>Email:</strong> {{ $o->account->email }}<br> <strong>Email:</strong> {{ $o->account->user->email }}<br>
@if ($o->account->phone) @if ($o->account->phone)
<strong>Phone:</strong> {{ $o->account->phone }}<br> <strong>Phone:</strong> {{ $o->account->phone }}<br>
@endif @endif