diff --git a/app/Http/Controllers/DesignController.php b/app/Http/Controllers/DesignController.php index 06c6f1a946..b9205d1776 100644 --- a/app/Http/Controllers/DesignController.php +++ b/app/Http/Controllers/DesignController.php @@ -484,7 +484,6 @@ class DesignController extends BaseController $designs->each(function ($design, $key) use ($action) { if (auth()->user()->can('edit', $design)) { - info("authed"); $this->design_repo->{$action}($design); } }); diff --git a/app/Http/Controllers/GroupSettingController.php b/app/Http/Controllers/GroupSettingController.php index 4dcf7923e0..99a2ba5599 100644 --- a/app/Http/Controllers/GroupSettingController.php +++ b/app/Http/Controllers/GroupSettingController.php @@ -415,4 +415,82 @@ class GroupSettingController extends BaseController return response()->json([], 200); } + + /** + * Perform bulk actions on the list view + * + * @return Collection + * + * @OA\Post( + * path="/api/v1/group_settings/bulk", + * operationId="bulkGroupSettings", + * tags={"group_settings"}, + * summary="Performs bulk actions on an array of group_settings", + * description="", + * @OA\Parameter(ref="#/components/parameters/X-Api-Secret"), + * @OA\Parameter(ref="#/components/parameters/X-Api-Token"), + * @OA\Parameter(ref="#/components/parameters/X-Requested-With"), + * @OA\Parameter(ref="#/components/parameters/index"), + * @OA\RequestBody( + * description="An array of group_settings ids", + * required=true, + * @OA\MediaType( + * mediaType="application/json", + * @OA\Schema( + * type="array", + * @OA\Items( + * type="integer", + * description="Array of hashed IDs to be bulk 'actioned", + * example="[0,1,2,3]", + * ), + * ) + * ) + * ), + * @OA\Response( + * response=200, + * description="The Bulk Action response", + * @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"), + * @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"), + * @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"), + * ), + * @OA\Response( + * response=422, + * description="Validation error", + * @OA\JsonContent(ref="#/components/schemas/ValidationError"), + + * ), + * @OA\Response( + * response="default", + * description="Unexpected Error", + * @OA\JsonContent(ref="#/components/schemas/Error"), + * ), + * ) + * + */ + public function bulk() + { + + $action = request()->input('action'); + + $ids = request()->input('ids'); + + $group_settings = GroupSetting::withTrashed()->whereIn('id', $this->transformKeys($ids))->company()->get(); + + if (!$group_settings) { + return response()->json(['message' => 'No Group Settings Found']); + } + + /* + * Send the other actions to the switch + */ + $group_settings->each(function ($group, $key) use ($action) { + if (auth()->user()->can('edit', $group)) { + $this->group_setting_repo->{$action}($group); + } + }); + + /* Need to understand which permission are required for the given bulk action ie. view / edit */ + + return $this->listResponse(GroupSetting::withTrashed()->whereIn('id', $this->transformKeys($ids))->company()); + } } diff --git a/app/Models/Activity.php b/app/Models/Activity.php index b8dd595800..a2f6487cb6 100644 --- a/app/Models/Activity.php +++ b/app/Models/Activity.php @@ -25,11 +25,11 @@ class Activity extends StaticModel const ARCHIVE_INVOICE=8; const DELETE_INVOICE=9; const CREATE_PAYMENT=10; - //const UPDATE_PAYMENT=11; + const UPDATE_PAYMENT=11; const ARCHIVE_PAYMENT=12; const DELETE_PAYMENT=13; const CREATE_CREDIT=14; - //const UPDATE_CREDIT=15; + const UPDATE_CREDIT=15; const ARCHIVE_CREDIT=16; const DELETE_CREDIT=17; const CREATE_QUOTE=18; diff --git a/app/Repositories/GroupSettingRepository.php b/app/Repositories/GroupSettingRepository.php index db847878ad..cd1a14b627 100644 --- a/app/Repositories/GroupSettingRepository.php +++ b/app/Repositories/GroupSettingRepository.php @@ -14,7 +14,7 @@ namespace App\Repositories; use App\Models\GroupSetting; use App\Utils\Traits\MakesHash; -class GroupSettingRepository +class GroupSettingRepository extends BaseRepository { use MakesHash; /** diff --git a/app/Services/Ledger/LedgerService.php b/app/Services/Ledger/LedgerService.php index 906566441a..be81a88541 100644 --- a/app/Services/Ledger/LedgerService.php +++ b/app/Services/Ledger/LedgerService.php @@ -12,6 +12,7 @@ namespace App\Services\Ledger; use App\Factory\CompanyLedgerFactory; +use App\Models\Activity; use App\Models\CompanyLedger; class LedgerService @@ -38,6 +39,7 @@ class LedgerService $company_ledger->adjustment = $adjustment; $company_ledger->notes = $notes; $company_ledger->balance = $balance + $adjustment; + $company_ledger->activity_id = Activity::UPDATE_INVOICE; $company_ledger->save(); $this->entity->company_ledger()->save($company_ledger); @@ -60,6 +62,7 @@ class LedgerService $company_ledger->client_id = $this->entity->client_id; $company_ledger->adjustment = $adjustment; $company_ledger->balance = $balance + $adjustment; + $company_ledger->activity_id = Activity::UPDATE_PAYMENT; $company_ledger->save(); $this->entity->company_ledger()->save($company_ledger); @@ -80,6 +83,7 @@ class LedgerService $company_ledger->adjustment = $adjustment; $company_ledger->notes = $notes; $company_ledger->balance = $balance + $adjustment; + $company_ledger->activity_id = Activity::UPDATE_CREDIT; $company_ledger->save(); $this->entity->company_ledger()->save($company_ledger); diff --git a/app/Transformers/CompanyLedgerTransformer.php b/app/Transformers/CompanyLedgerTransformer.php index 9b10f54212..a9137e1706 100644 --- a/app/Transformers/CompanyLedgerTransformer.php +++ b/app/Transformers/CompanyLedgerTransformer.php @@ -35,6 +35,7 @@ class CompanyLedgerTransformer extends EntityTransformer 'notes' => (string)$company_ledger->notes ?: '', 'balance' => (float) $company_ledger->balance, 'adjustment' => (float) $company_ledger->adjustment, + 'activity_id' => (int)$company_ledger->activity_id, 'created_at' => (int)$company_ledger->created_at, 'updated_at' => (int)$company_ledger->updated_at, 'archived_at' => (int)$company_ledger->deleted_at, 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 f4a0462f04..8baaaf6000 100644 --- a/database/migrations/2014_10_13_000000_create_users_table.php +++ b/database/migrations/2014_10_13_000000_create_users_table.php @@ -1120,6 +1120,7 @@ class CreateUsersTable extends Migration $table->unsignedInteger('company_id'); $table->unsignedInteger('client_id')->nullable(); $table->unsignedInteger('user_id')->nullable(); + $table->unsignedInteger('activity_id')->nullable(); $table->decimal('adjustment', 16, 4)->nullable(); $table->decimal('balance', 16, 4)->nullable(); //this is the clients balance carried forward @@ -1167,6 +1168,7 @@ class CreateUsersTable extends Migration $table->unsignedInteger('user_id')->nullable(); $table->string('name')->nullable(); $table->mediumText('settings')->nullable(); + $table->boolean('is_default')->default(0); $table->softDeletes('deleted_at', 6); $table->timestamps(6); diff --git a/routes/api.php b/routes/api.php index e216ee0d54..48dff4be83 100644 --- a/routes/api.php +++ b/routes/api.php @@ -112,6 +112,7 @@ Route::group(['middleware' => ['api_db', 'token_auth', 'locale'], 'prefix' => 'a Route::put('company_users/{user}', 'CompanyUserController@update'); Route::resource('group_settings', 'GroupSettingController'); + Route::post('group_settings/bulk', 'GroupSettingController@bulk'); Route::resource('tax_rates', 'TaxRateController');// name = (tasks. index / create / show / update / destroy / edit