1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-05 18:52:44 +01:00

Bulk actions on groups

This commit is contained in:
David Bomba 2020-06-24 09:39:49 +10:00
parent ddb246c8b0
commit 889ac65f26
8 changed files with 89 additions and 4 deletions

View File

@ -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);
}
});

View File

@ -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());
}
}

View File

@ -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;

View File

@ -14,7 +14,7 @@ namespace App\Repositories;
use App\Models\GroupSetting;
use App\Utils\Traits\MakesHash;
class GroupSettingRepository
class GroupSettingRepository extends BaseRepository
{
use MakesHash;
/**

View File

@ -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);

View File

@ -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,

View File

@ -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);

View File

@ -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