mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Bulk actions for tax rates
This commit is contained in:
parent
0cd3b6925e
commit
b96e2aa78b
@ -6,5 +6,6 @@
|
||||
* @OA\Property(property="id", type="string", example="Opnel5aKBz", description="______"),
|
||||
* @OA\Property(property="name", type="string", example="GST", description="______"),
|
||||
* @OA\Property(property="rate", type="number", example="10", description="______"),
|
||||
* @OA\Property(property="is_deleted", type="boolean", example=true, description="______"),
|
||||
* )
|
||||
*/
|
||||
|
@ -12,13 +12,14 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Factory\TaxRateFactory;
|
||||
use App\Http\Requests\TaxRate\CreateTaxRateRequest;
|
||||
use App\Http\Requests\TaxRate\DestroyTaxRateRequest;
|
||||
use App\Http\Requests\TaxRate\EditTaxRateRequest;
|
||||
use App\Http\Requests\TaxRate\ShowTaxRateRequest;
|
||||
use App\Http\Requests\TaxRate\StoreTaxRateRequest;
|
||||
use App\Http\Requests\TaxRate\UpdateTaxRateRequest;
|
||||
use App\Http\Requests\TaxRate\CreateTaxRateRequest;
|
||||
use App\Models\TaxRate;
|
||||
use App\Repositories\BaseRepository;
|
||||
use App\Transformers\TaxRateTransformer;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
@ -32,9 +33,13 @@ class TaxRateController extends BaseController
|
||||
|
||||
protected $entity_transformer = TaxRateTransformer::class;
|
||||
|
||||
public function __construct()
|
||||
protected $base_repo;
|
||||
|
||||
public function __construct(BaseRepository $base_repo)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->base_repo = $base_repo;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -354,8 +359,82 @@ class TaxRateController extends BaseController
|
||||
*/
|
||||
public function destroy(DestroyTaxRateRequest $request, TaxRate $tax_rate)
|
||||
{
|
||||
$tax_rate->is_deleted = true;
|
||||
$tax_rate->save();
|
||||
$tax_rate->delete();
|
||||
|
||||
return response()->json([], 200);
|
||||
return $this->itemResponse($tax_rate);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Perform bulk actions on the list view
|
||||
*
|
||||
* @param BulkTaxRateRequest $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*
|
||||
*
|
||||
* @OA\Post(
|
||||
* path="/api/v1/tax_rates/bulk",
|
||||
* operationId="bulkTaxRates",
|
||||
* tags={"tax_rates"},
|
||||
* summary="Performs bulk actions on an array of TaxRates",
|
||||
* 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="Tax Rates",
|
||||
* 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 TaxRate List 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\JsonContent(ref="#/components/schemas/Webhook"),
|
||||
* ),
|
||||
* @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');
|
||||
|
||||
$tax_rate = TaxRate::withTrashed()->find($this->transformKeys($ids));
|
||||
|
||||
|
||||
$tax_rate->each(function ($tax_rat, $key) use ($action) {
|
||||
if (auth()->user()->can('edit', $tax_rate)) {
|
||||
$this->base_repo->{$action}($tax_rate);
|
||||
}
|
||||
});
|
||||
|
||||
return $this->listResponse(TaxRate::withTrashed()->whereIn('id', $this->transformKeys($ids)));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -44,9 +44,8 @@ class AutoBillInvoice extends AbstractService
|
||||
|
||||
if($this->invoice->balance > 0)
|
||||
$gateway_token = $this->getGateway($this->invoice->balance);
|
||||
|
||||
// else
|
||||
// return $this->invoice->service()->markPaid()->save();
|
||||
else
|
||||
return $this->invoice->service()->markPaid()->save();
|
||||
|
||||
if(!$gateway_token)
|
||||
return $this->invoice;
|
||||
@ -81,12 +80,6 @@ class AutoBillInvoice extends AbstractService
|
||||
return $gateway_token;
|
||||
}
|
||||
|
||||
// return collect($gateway_tokens)->filter(function ($token) use ($amount){
|
||||
|
||||
// return $this->validGatewayLimits($token, $amount);
|
||||
|
||||
// })->first();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -18,6 +18,7 @@ class TaxRateTransformer extends EntityTransformer
|
||||
'id' => (string) $this->encodePrimaryKey($tax_rate->id),
|
||||
'name' => (string) $tax_rate->name,
|
||||
'rate' => (float) $tax_rate->rate,
|
||||
'is_deleted' => (bool) $tax_rate->is_deleted,
|
||||
'updated_at' => (int)$tax_rate->updated_at,
|
||||
'archived_at' => (int)$tax_rate->deleted_at,
|
||||
'created_at' => (int)$tax_rate->created_at,
|
||||
|
@ -16,6 +16,10 @@ class AddTokenIdToActivityTable extends Migration
|
||||
Schema::table('activities', function (Blueprint $table) {
|
||||
$table->unsignedInteger('token_id')->nullable();
|
||||
});
|
||||
|
||||
Schema::table('tax_rates', function (Blueprint $table) {
|
||||
$table->boolean('is_deleted')->default(0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -117,6 +117,7 @@ Route::group(['middleware' => ['api_db', 'token_auth', 'locale'], 'prefix' => 'a
|
||||
Route::post('group_settings/bulk', 'GroupSettingController@bulk');
|
||||
|
||||
Route::resource('tax_rates', 'TaxRateController');// name = (tasks. index / create / show / update / destroy / edit
|
||||
Route::post('tax_rates/bulk', 'TaxRateController@bulk')->name('tax_rates.bulk');
|
||||
|
||||
Route::post('refresh', 'Auth\LoginController@refresh');
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user