diff --git a/app/Http/Controllers/ClientController.php b/app/Http/Controllers/ClientController.php index 599da3593f3a..78d70bfb8dc8 100644 --- a/app/Http/Controllers/ClientController.php +++ b/app/Http/Controllers/ClientController.php @@ -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))); } diff --git a/app/Http/Controllers/OpenAPI/CompanyGatewaySchema.php b/app/Http/Controllers/OpenAPI/CompanyGatewaySchema.php index c55a072f27c3..38f8a896d19d 100644 --- a/app/Http/Controllers/OpenAPI/CompanyGatewaySchema.php +++ b/app/Http/Controllers/OpenAPI/CompanyGatewaySchema.php @@ -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", + * ), + * ), * ) */ \ No newline at end of file diff --git a/app/Http/Controllers/OpenAPI/FeesAndLimitsSchema.php b/app/Http/Controllers/OpenAPI/FeesAndLimitsSchema.php new file mode 100644 index 000000000000..3808bd25f1d3 --- /dev/null +++ b/app/Http/Controllers/OpenAPI/FeesAndLimitsSchema.php @@ -0,0 +1,19 @@ +first(); } + public function activities() + { + return $this->hasMany(Activity::class, 'id', 'client_id'); + } + public function contacts() { return $this->hasMany(ClientContact::class)->orderBy('is_primary', 'desc'); diff --git a/app/Models/Company.php b/app/Models/Company.php index 1492fabd1fae..e678006f6e1d 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -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(); + } } diff --git a/app/Models/CompanyGateway.php b/app/Models/CompanyGateway.php index df928d157c83..a1152b5e1c76 100644 --- a/app/Models/CompanyGateway.php +++ b/app/Models/CompanyGateway.php @@ -242,4 +242,9 @@ class CompanyGateway extends BaseModel return $fee; } + public function resolveRouteBinding($value) + { + return $this + ->where('id', $this->decodePrimaryKey($value))->firstOrFail(); + } } diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index b8a82407a682..320528aa2cdb 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -387,4 +387,5 @@ class Invoice extends BaseModel $this->status_id = $status; $this->save(); } + } \ No newline at end of file diff --git a/app/Models/InvoiceInvitation.php b/app/Models/InvoiceInvitation.php index 6d3eff6706d6..8fd890ad423c 100644 --- a/app/Models/InvoiceInvitation.php +++ b/app/Models/InvoiceInvitation.php @@ -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', diff --git a/app/Models/Payment.php b/app/Models/Payment.php index cf849b92d118..7f0013382bf1 100644 --- a/app/Models/Payment.php +++ b/app/Models/Payment.php @@ -143,4 +143,10 @@ class Payment extends BaseModel break; } } + + public function resolveRouteBinding($value) + { + return $this + ->where('id', $this->decodePrimaryKey($value))->firstOrFail(); + } } diff --git a/app/Models/Quote.php b/app/Models/Quote.php index cd0e0a5e4fa8..3fa46c43950e 100644 --- a/app/Models/Quote.php +++ b/app/Models/Quote.php @@ -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', diff --git a/app/Models/RecurringInvoice.php b/app/Models/RecurringInvoice.php index afa00d39b3cd..64298b186cf1 100644 --- a/app/Models/RecurringInvoice.php +++ b/app/Models/RecurringInvoice.php @@ -255,5 +255,5 @@ class RecurringInvoice extends BaseModel break; } } - + } diff --git a/app/Models/RecurringQuote.php b/app/Models/RecurringQuote.php index f4ccdccbfe0c..47be0425fbc7 100644 --- a/app/Models/RecurringQuote.php +++ b/app/Models/RecurringQuote.php @@ -116,4 +116,5 @@ class RecurringQuote extends BaseModel { $this->morphMany(RecurringQuoteInvitation::class); } + } diff --git a/app/Repositories/BaseRepository.php b/app/Repositories/BaseRepository.php index 0c7c4e6fdfc1..ac920c9b490a 100644 --- a/app/Repositories/BaseRepository.php +++ b/app/Repositories/BaseRepository.php @@ -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)); - } + } /** diff --git a/app/Repositories/ClientRepository.php b/app/Repositories/ClientRepository.php index f2da7ecdf78b..dce7b2a4f759 100644 --- a/app/Repositories/ClientRepository.php +++ b/app/Repositories/ClientRepository.php @@ -77,4 +77,5 @@ class ClientRepository extends BaseRepository } + } \ No newline at end of file diff --git a/app/Transformers/ClientTransformer.php b/app/Transformers/ClientTransformer.php index 4556e9568065..9757a183d067 100644 --- a/app/Transformers/ClientTransformer.php +++ b/app/Transformers/ClientTransformer.php @@ -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 * diff --git a/database/migrations/2014_10_13_000000_create_users_table.php b/database/migrations/2014_10_13_000000_create_users_table.php index 47f5cfeab638..a5e67cd8900d 100644 --- a/database/migrations/2014_10_13_000000_create_users_table.php +++ b/database/migrations/2014_10_13_000000_create_users_table.php @@ -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'); diff --git a/database/seeds/RandomDataSeeder.php b/database/seeds/RandomDataSeeder.php index 11813e49ad94..6e0e39ca9f65 100644 --- a/database/seeds/RandomDataSeeder.php +++ b/database/seeds/RandomDataSeeder.php @@ -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,