Fixes for actions (#3056)

* Update API docs

* cleaning up migrations

* Fixes for tests

* fixes for tests

* Delete client contacts when soft deleting a client

* Fixes for actions
This commit is contained in:
David Bomba 2019-11-12 15:41:02 +11:00 committed by GitHub
parent e4c18e734a
commit 2ce89e5f48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 115 additions and 53 deletions

View File

@ -509,16 +509,16 @@ class ClientController extends BaseController
$ids = request()->input('ids');
$clients = Client::withTrashed()->find($ids);
$clients = Client::withTrashed()->find($this->transformKeys($ids));
$clients->each(function ($client, $key) use($action){
if(auth()->user()->can('edit', $client))
$this->client_repo->{$action}($invoice);
$this->client_repo->{$action}($client);
});
return $this->listResponse(Client::withTrashed()->whereIn('id', $ids));
return $this->listResponse(Client::withTrashed()->whereIn('id', $this->transformKeys($ids)));
}

View File

@ -9,20 +9,16 @@
* @OA\Property(property="accepted_credit_cards", type="integer", example="32", description="Bitmask representation of cards"),
* @OA\Property(property="show_billing_address", type="boolean", example=true, description="______"),
* @OA\Property(property="show_shipping_address", type="boolean", example=true, description="______"),
* @OA\Property(property="config", type="string", example="2", description="______"),
* @OA\Property(property="config", type="string", example="dfadsfdsafsafd", description="The configuration map for the gateway"),
* @OA\Property(property="update_details", type="boolean", example=true, description="______"),
* @OA\Property(property="adjust_fee_percent", type="boolean", example=true, description="______"),
* @OA\Property(property="fees_and_limits", type="object", description="A mapped collection of the fees and limits for the configured gateway"),
* @OA\Property(property="user_id", type="string", example="2", description="______"),
* @OA\Property(property="min_limit", type="string", example="2", description="______"),
* @OA\Property(property="max_limit", type="string", example="2", description="______"),
* @OA\Property(property="fee_amount", type="number", format="float", example="2.0", description="______"),
* @OA\Property(property="fee_percent", type="number", format="float", example="2.0", description="______"),
* @OA\Property(property="fee_tax_name1", type="string", example="2", description="______"),
* @OA\Property(property="fee_tax_name2", type="string", example="2", description="______"),
* @OA\Property(property="fee_tax_rate1", type="number", format="float", example="2.0", description="______"),
* @OA\Property(property="fee_tax_rate2", type="number", format="float", example="2.0", description="______"),
* @OA\Property(property="fee_cap", type="number", format="float", example="2.0", description="______"),
* @OA\Property(
* property="fees_and_limits",
* type="array",
* description="A mapped collection of the fees and limits for the configured gateway",
* @OA\Items(
* ref="#/components/schemas/FeesAndLimits",
* ),
* ),
* )
*/

View File

@ -0,0 +1,19 @@
<?php
/**
* @OA\Schema(
* schema="FeesAndLimits",
* type="object",
* @OA\Property(property="min_limit", type="string", example="2", description="______"),
* @OA\Property(property="max_limit", type="string", example="2", description="______"),
* @OA\Property(property="fee_amount", type="number", format="float", example="2.0", description="______"),
* @OA\Property(property="fee_percent", type="number", format="float", example="2.0", description="______"),
* @OA\Property(property="fee_tax_name1", type="string", example="2", description="______"),
* @OA\Property(property="fee_tax_name2", type="string", example="2", description="______"),
* @OA\Property(property="fee_tax_name3", type="string", example="2", description="______"),
* @OA\Property(property="fee_tax_rate1", type="number", format="float", example="2.0", description="______"),
* @OA\Property(property="fee_tax_rate2", type="number", format="float", example="2.0", description="______"),
* @OA\Property(property="fee_tax_rate3", type="number", format="float", example="2.0", description="______"),
* @OA\Property(property="fee_cap", type="number", format="float", example="2.0", description="______"),
* @OA\Property(property="adjust_fee_percent", type="boolean", example=true, description="______"),
* )
*/

View File

@ -25,7 +25,6 @@ class BaseModel extends Model
{
use MakesHash;
use UserSessionAttributes;
use SoftDeletes;
//todo customise names of archived_at / updated_at columns
///const CREATED_AT = 'creation_date';

View File

@ -64,7 +64,6 @@ class Client extends BaseModel
'private_notes',
'industry_id',
'size_id',
// 'currency_id',
'address1',
'address2',
'city',
@ -129,6 +128,11 @@ class Client extends BaseModel
->first();
}
public function activities()
{
return $this->hasMany(Activity::class, 'id', 'client_id');
}
public function contacts()
{
return $this->hasMany(ClientContact::class)->orderBy('is_primary', 'desc');

View File

@ -257,4 +257,9 @@ class Company extends BaseModel
return User::find($c->user_id);
}
public function resolveRouteBinding($value)
{
return $this
->where('id', $this->decodePrimaryKey($value))->firstOrFail();
}
}

View File

@ -242,4 +242,9 @@ class CompanyGateway extends BaseModel
return $fee;
}
public function resolveRouteBinding($value)
{
return $this
->where('id', $this->decodePrimaryKey($value))->firstOrFail();
}
}

View File

@ -387,4 +387,5 @@ class Invoice extends BaseModel
$this->status_id = $status;
$this->save();
}
}

View File

@ -14,13 +14,15 @@ namespace App\Models;
use App\Models\Invoice;
use App\Utils\Traits\MakesDates;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Carbon;
class InvoiceInvitation extends BaseModel
{
use MakesDates;
use SoftDeletes;
protected $fillable = [
'id',
'client_contact_id',

View File

@ -143,4 +143,10 @@ class Payment extends BaseModel
break;
}
}
public function resolveRouteBinding($value)
{
return $this
->where('id', $this->decodePrimaryKey($value))->firstOrFail();
}
}

View File

@ -14,12 +14,14 @@ namespace App\Models;
use App\Models\Filterable;
use App\Utils\Traits\MakesHash;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Quote extends BaseModel
{
use MakesHash;
use Filterable;
use SoftDeletes;
protected $fillable = [
'client_id',
'quote_number',

View File

@ -255,5 +255,5 @@ class RecurringInvoice extends BaseModel
break;
}
}
}

View File

@ -116,4 +116,5 @@ class RecurringQuote extends BaseModel
{
$this->morphMany(RecurringQuoteInvitation::class);
}
}

View File

@ -11,6 +11,7 @@
namespace App\Repositories;
use App\Models\Client;
use App\Utils\Traits\MakesHash;
/**
@ -53,17 +54,19 @@ class BaseRepository
*/
public function archive($entity)
{
if ($entity->trashed()) {
if ($entity->trashed())
return;
}
if(get_class($entity) == Client::class)
$entity->contacts()->delete();
$entity->delete();
$className = $this->getEventClass($entity, 'Archived');
if (class_exists($className)) {
if (class_exists($className))
event(new $className($entity));
}
}
/**
@ -76,8 +79,12 @@ class BaseRepository
}
$fromDeleted = false;
$entity->restore();
if(get_class($entity) == Client::class)
$entity->contacts()->restore();
if ($entity->is_deleted) {
$fromDeleted = true;
$entity->is_deleted = false;
@ -86,9 +93,9 @@ class BaseRepository
$className = $this->getEventClass($entity, 'Restored');
if (class_exists($className)) {
if (class_exists($className))
event(new $className($entity, $fromDeleted));
}
}
/**

View File

@ -77,4 +77,5 @@ class ClientRepository extends BaseRepository
}
}

View File

@ -11,9 +11,11 @@
namespace App\Transformers;
use App\Models\Activity;
use App\Models\Client;
use App\Models\ClientContact;
use App\Models\ClientGatewayToken;
use App\Transformers\ActivityTransformer;
use App\Transformers\ClientGatewayTokenTransformer;
use App\Utils\Traits\MakesHash;
@ -32,10 +34,23 @@ class ClientTransformer extends EntityTransformer
* @var array
*/
protected $availableIncludes = [
'gateway_tokens'
'gateway_tokens',
'activities',
];
/**
* @param Client $client
*
* @return \League\Fractal\Resource\Collection
*/
public function includeActivities(Client $client)
{
$transformer = new ActivityTransformer($this->serializer);
return $this->includeCollection($client->activities, $transformer, Activity::class);
}
/**
* @param Client $client
*

View File

@ -131,7 +131,7 @@ class CreateUsersTable extends Migration
$table->string('referral_code')->nullable();
$table->timestamps(6);
$table->softDeletes();
$table->softDeletes('deleted_at', 6);
});
Schema::create('companies', function (Blueprint $table) {
@ -166,7 +166,7 @@ class CreateUsersTable extends Migration
$table->text('settings');
$table->timestamps(6);
$table->softDeletes();
//$table->softDeletes('deleted_at', 6);
//$table->foreign('country_id')->references('id')->on('countries');
$table->foreign('industry_id')->references('id')->on('industries');
@ -248,7 +248,7 @@ class CreateUsersTable extends Migration
$table->rememberToken();
$table->timestamps(6);
$table->softDeletes();
$table->softDeletes('deleted_at', 6);
$table->unique(['oauth_user_id', 'oauth_provider_id']);
@ -317,7 +317,7 @@ class CreateUsersTable extends Migration
$table->string('id_number')->nullable();
$table->timestamps(6);
$table->softDeletes();
$table->softDeletes('deleted_at', 6);
$table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade');
$table->foreign('industry_id')->references('id')->on('industries');
@ -359,7 +359,7 @@ class CreateUsersTable extends Migration
$table->string('contact_key')->nullable();
$table->rememberToken();
$table->timestamps(6);
$table->softDeletes();
$table->softDeletes('deleted_at', 6);
$table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade');
$table->foreign('client_id')->references('id')->on('clients')->onDelete('cascade');
@ -382,7 +382,7 @@ class CreateUsersTable extends Migration
$table->text('fees_and_limits');
$table->timestamps(6);
$table->softDeletes();
$table->softDeletes('deleted_at', 6);
$table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade');
@ -459,7 +459,7 @@ class CreateUsersTable extends Migration
$t->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$t->timestamps(6);
$t->softDeletes();
$t->softDeletes('deleted_at', 6);
$t->unique(['company_id', 'invoice_number']);
});
@ -524,7 +524,7 @@ class CreateUsersTable extends Migration
$t->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$t->timestamps(6);
$t->softDeletes();
$t->softDeletes('deleted_at', 6);
});
@ -586,7 +586,7 @@ class CreateUsersTable extends Migration
$t->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$t->timestamps(6);
$t->softDeletes();
$t->softDeletes('deleted_at', 6);
});
@ -645,7 +645,7 @@ class CreateUsersTable extends Migration
$t->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$t->timestamps(6);
$t->softDeletes();
$t->softDeletes('deleted_at', 6);
$t->unique(['company_id', 'quote_number']);
});
@ -657,9 +657,6 @@ class CreateUsersTable extends Migration
$t->unsignedInteger('client_contact_id');
$t->unsignedInteger('invoice_id')->index();
$t->string('key')->index();
$t->timestamps(6);
$t->softDeletes();
$t->string('transaction_reference')->nullable();
$t->string('message_id')->nullable();
$t->text('email_error')->nullable();
@ -675,18 +672,20 @@ class CreateUsersTable extends Migration
$t->foreign('invoice_id')->references('id')->on('invoices')->onDelete('cascade');
$t->foreign('company_id')->references('id')->on('companies')->onDelete('cascade');
$t->timestamps(6);
$t->softDeletes('deleted_at', 6);
$t->index(['deleted_at', 'invoice_id']);
});
Schema::create('tax_rates', function ($t) {
$t->increments('id');
$t->unsignedInteger('company_id')->index();
$t->unsignedInteger('user_id')->nullable();
$t->timestamps(6);
$t->softDeletes();
$t->softDeletes('deleted_at', 6);
$t->string('name',100);
$t->decimal('rate', 13, 3)->default(0);
@ -728,7 +727,7 @@ class CreateUsersTable extends Migration
$t->timestamps(6);
$t->softDeletes();
$t->softDeletes('deleted_at', 6);
});
@ -748,7 +747,7 @@ class CreateUsersTable extends Migration
$t->string('transaction_reference')->nullable();
$t->string('payer_id')->nullable();
$t->timestamps(6);
$t->softDeletes();
$t->softDeletes('deleted_at', 6);
$t->boolean('is_deleted')->default(false);
$t->foreign('company_id')->references('id')->on('companies')->onDelete('cascade');
@ -784,7 +783,7 @@ class CreateUsersTable extends Migration
$table->unsignedInteger('client_id')->nullable();
$table->unsignedInteger('invoice_id')->nullable();
$table->timestamps(6);
$table->softDeletes();
$table->softDeletes('deleted_at', 6);
$table->string('custom_value1')->nullable();
$table->string('custom_value2')->nullable();
@ -817,7 +816,7 @@ class CreateUsersTable extends Migration
$table->string('username')->nullable();
$table->timestamps(6);
$table->softDeletes();
$table->softDeletes('deleted_at', 6);
$table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
@ -837,7 +836,7 @@ class CreateUsersTable extends Migration
$table->string('account_number')->nullable();
$table->timestamps(6);
$table->softDeletes();
$table->softDeletes('deleted_at', 6);
$table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
@ -852,7 +851,7 @@ class CreateUsersTable extends Migration
$table->unsignedInteger('company_id');
$table->unsignedInteger('user_id');
$table->timestamps(6);
$table->softDeletes();
$table->softDeletes('deleted_at', 6);
$table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
@ -939,7 +938,7 @@ class CreateUsersTable extends Migration
$table->unsignedInteger('gateway_type_id');
$table->boolean('is_default')->default(0);
$table->text('meta')->nullable();
$table->softDeletes();
$table->softDeletes('deleted_at', 6);
$table->timestamps(6);
$table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade');

View File

@ -93,7 +93,7 @@ class RandomDataSeeder extends Seeder
]);
factory(\App\Models\Client::class, 10)->create(['user_id' => $user->id, 'company_id' => $company->id])->each(function ($c) use ($user, $company){
factory(\App\Models\Client::class, 50)->create(['user_id' => $user->id, 'company_id' => $company->id])->each(function ($c) use ($user, $company){
factory(\App\Models\ClientContact::class,1)->create([
'user_id' => $user->id,