1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-16 16:13:20 +01:00
invoiceninja/app/Http/Controllers/BankTransactionRuleController.php

491 lines
20 KiB
PHP
Raw Normal View History

2022-11-13 05:12:50 +01:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2023-01-28 23:21:40 +01:00
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
2022-11-13 05:12:50 +01:00
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Http\Controllers;
2023-07-26 04:59:36 +02:00
use App\Factory\BankTransactionRuleFactory;
2022-11-13 05:12:50 +01:00
use App\Filters\BankTransactionRuleFilters;
use App\Http\Requests\BankTransactionRule\BulkBankTransactionRuleRequest;
2023-10-26 04:57:44 +02:00
use App\Http\Requests\BankTransactionRule\CreateBankTransactionRuleRequest;
use App\Http\Requests\BankTransactionRule\DestroyBankTransactionRuleRequest;
2022-11-13 05:12:50 +01:00
use App\Http\Requests\BankTransactionRule\EditBankTransactionRuleRequest;
use App\Http\Requests\BankTransactionRule\ShowBankTransactionRuleRequest;
use App\Http\Requests\BankTransactionRule\StoreBankTransactionRuleRequest;
use App\Http\Requests\BankTransactionRule\UpdateBankTransactionRuleRequest;
2023-10-26 04:57:44 +02:00
use App\Models\BankTransactionRule;
use App\Repositories\BankTransactionRuleRepository;
use App\Services\Bank\BankMatchingService;
2023-10-26 04:57:44 +02:00
use App\Transformers\BankTransactionRuleTransformer;
use App\Utils\Traits\MakesHash;
2022-11-13 05:12:50 +01:00
class BankTransactionRuleController extends BaseController
{
use MakesHash;
2024-01-14 05:05:00 +01:00
2022-11-13 05:12:50 +01:00
protected $entity_type = BankTransactionRule::class;
2022-11-13 05:21:37 +01:00
protected $entity_transformer = BankTransactionRuleTransformer::class;
2022-11-13 05:12:50 +01:00
protected $bank_transaction_repo;
public function __construct(BankTransactionRuleRepository $bank_transaction_repo)
{
parent::__construct();
$this->bank_transaction_repo = $bank_transaction_repo;
}
/**
* @OA\Get(
* path="/api/v1/bank_transaction_rules",
* operationId="getBankTransactionRules",
* tags={"bank_transaction_rules"},
* summary="Gets a list of bank_transaction_rules",
* description="Lists all bank transaction rules",
2023-02-10 10:21:10 +01:00
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
2022-11-13 05:12:50 +01:00
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
* @OA\Parameter(ref="#/components/parameters/include"),
* @OA\Parameter(ref="#/components/parameters/index"),
* @OA\Parameter(
* name="rows",
* in="query",
* description="The number of bank integrations to return",
* example="50",
* required=false,
* @OA\Schema(
* type="number",
* format="integer",
* ),
* ),
* @OA\Response(
* response=200,
* description="A list of bank integrations",
* @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/BankTransactionRule"),
2022-11-13 05:12:50 +01:00
* ),
* @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"),
* ),
* )
2023-08-04 08:40:44 +02:00
* @param BankTransactionRuleFilters $filters
2022-11-13 05:12:50 +01:00
* @return Response|mixed
*/
public function index(BankTransactionRuleFilters $filters)
{
$bank_transaction_rules = BankTransactionRule::filter($filters);
return $this->listResponse($bank_transaction_rules);
}
/**
* Display the specified resource.
*
* @param ShowBankTransactionRuleRequest $request
* @param BankTransactionRule $bank_transaction_rule
2023-07-26 04:59:36 +02:00
* @return \Illuminate\Http\JsonResponse
2022-11-13 05:12:50 +01:00
*
*
* @OA\Get(
* path="/api/v1/bank_transaction_rules/{id}",
* operationId="showBankTransactionRule",
* tags={"bank_transaction_rules"},
* summary="Shows a bank_transaction",
* description="Displays a bank_transaction by id",
2023-02-10 10:21:10 +01:00
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
2022-11-13 05:12:50 +01:00
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
* @OA\Parameter(ref="#/components/parameters/include"),
* @OA\Parameter(
* name="id",
* in="path",
* description="The Bank Transaction RuleHashed ID",
* example="D2J234DFA",
* required=true,
* @OA\Schema(
* type="string",
* format="string",
* ),
* ),
* @OA\Response(
* response=200,
* description="Returns the bank_transaction rule object",
* @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/BankTransactionRule"),
2022-11-13 05:12:50 +01:00
* ),
* @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 show(ShowBankTransactionRuleRequest $request, BankTransactionRule $bank_transaction_rule)
{
return $this->itemResponse($bank_transaction_rule);
}
/**
* Show the form for editing the specified resource.
*
* @param EditBankTransactionRuleRequest $request
* @param BankTransactionRule $bank_transaction_rule
2023-07-26 04:59:36 +02:00
* @return \Illuminate\Http\JsonResponse
2022-11-13 05:12:50 +01:00
*
*
* @OA\Get(
* path="/api/v1/bank_transaction_rules/{id}/edit",
* operationId="editBankTransactionRule",
* tags={"bank_transaction_rules"},
* summary="Shows a bank_transaction for editing",
* description="Displays a bank_transaction by id",
2023-02-10 10:21:10 +01:00
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
2022-11-13 05:12:50 +01:00
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
* @OA\Parameter(ref="#/components/parameters/include"),
* @OA\Parameter(
* name="id",
* in="path",
* description="The Bank Transaction Rule Hashed ID",
* example="D2J234DFA",
* required=true,
* @OA\Schema(
* type="string",
* format="string",
* ),
* ),
* @OA\Response(
* response=200,
* description="Returns the bank_transaction rule object",
* @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/BankTransactionRule"),
2022-11-13 05:12:50 +01:00
* ),
* @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 edit(EditBankTransactionRuleRequest $request, BankTransactionRule $bank_transaction_rule)
{
return $this->itemResponse($bank_transaction_rule);
}
/**
* Update the specified resource in storage.
*
* @param UpdateBankTransactionRuleRequest $request
* @param BankTransactionRule $bank_transaction_rule
2023-07-26 04:59:36 +02:00
* @return \Illuminate\Http\JsonResponse
2022-11-13 05:12:50 +01:00
*
*
*
* @OA\Put(
* path="/api/v1/bank_transaction_rules/{id}",
* operationId="updateBankTransactionRule",
* tags={"bank_transaction_rules"},
* summary="Updates a bank_transaction Rule",
* description="Handles the updating of a bank_transaction rule by id",
2023-02-10 10:21:10 +01:00
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
2022-11-13 05:12:50 +01:00
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
* @OA\Parameter(ref="#/components/parameters/include"),
* @OA\Parameter(
* name="id",
* in="path",
* description="The Bank Transaction Rule Hashed ID",
* example="D2J234DFA",
* required=true,
* @OA\Schema(
* type="string",
* format="string",
* ),
* ),
* @OA\Response(
* response=200,
* description="Returns the bank_transaction rule object",
* @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/BankTransactionRule"),
2022-11-13 05:12:50 +01:00
* ),
* @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 update(UpdateBankTransactionRuleRequest $request, BankTransactionRule $bank_transaction_rule)
{
/** @var \App\Models\User $user */
$user = auth()->user();
$bank_transaction_rule = $this->bank_transaction_repo->save($request->all(), $bank_transaction_rule);
BankMatchingService::dispatch($user->company()->id, $user->company()->db);
2022-11-13 05:12:50 +01:00
return $this->itemResponse($bank_transaction_rule->fresh());
}
/**
* Show the form for creating a new resource.
*
* @param CreateBankTransactionRuleRequest $request
2023-07-26 04:59:36 +02:00
* @return \Illuminate\Http\JsonResponse
2022-11-13 05:12:50 +01:00
*
*
*
* @OA\Get(
* path="/api/v1/bank_transaction_rules/create",
* operationId="getBankTransactionRulesCreate",
* tags={"bank_transaction_rules"},
* summary="Gets a new blank bank_transaction rule object",
* description="Returns a blank object with default values",
2023-02-10 10:21:10 +01:00
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
2022-11-13 05:12:50 +01:00
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
* @OA\Parameter(ref="#/components/parameters/include"),
* @OA\Response(
* response=200,
* description="A blank bank_transaction rule object",
* @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/BankTransactionRule"),
2022-11-13 05:12:50 +01:00
* ),
* @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 create(CreateBankTransactionRuleRequest $request)
{
2023-08-04 08:40:44 +02:00
/** @var \App\Models\User $user **/
$user = auth()->user();
2023-08-04 08:40:44 +02:00
$bank_transaction_rule = BankTransactionRuleFactory::create($user->company()->id, $user->id);
2022-11-13 05:12:50 +01:00
return $this->itemResponse($bank_transaction_rule);
}
/**
* Store a newly created resource in storage.
*
* @param StoreBankTransactionRuleRequest $request
2023-07-26 04:59:36 +02:00
* @return \Illuminate\Http\JsonResponse
2022-11-13 05:12:50 +01:00
*
*
*
* @OA\Post(
* path="/api/v1/bank_transaction_rules",
* operationId="storeBankTransactionRule",
2022-11-13 05:12:50 +01:00
* tags={"bank_transaction_rules"},
* summary="Adds a bank_transaction rule",
* description="Adds an bank_transaction to a company",
2023-02-10 10:21:10 +01:00
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
2022-11-13 05:12:50 +01:00
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
* @OA\Parameter(ref="#/components/parameters/include"),
* @OA\Response(
* response=200,
* description="Returns the saved bank_transaction rule object",
* @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/BankTransactionRule"),
2022-11-13 05:12:50 +01:00
* ),
* @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 store(StoreBankTransactionRuleRequest $request)
{
2024-01-14 05:05:00 +01:00
2023-08-04 08:40:44 +02:00
/** @var \App\Models\User $user **/
$user = auth()->user();
$bank_transaction_rule = $this->bank_transaction_repo->save($request->all(), BankTransactionRuleFactory::create($user->company()->id, $user->id));
2022-11-13 05:12:50 +01:00
BankMatchingService::dispatch($user->company()->id, $user->company()->db);
2022-11-13 05:12:50 +01:00
return $this->itemResponse($bank_transaction_rule);
}
/**
* Remove the specified resource from storage.
*
* @param DestroyBankTransactionRuleRequest $request
* @param BankTransactionRule $bank_transaction_rule
2023-07-26 04:59:36 +02:00
* @return \Illuminate\Http\JsonResponse
2022-11-13 05:12:50 +01:00
*
*
* @throws \Exception
* @OA\Delete(
* path="/api/v1/bank_transaction_rules/{id}",
* operationId="deleteBankTransactionRule",
* tags={"bank_transaction_rules"},
* summary="Deletes a bank_transaction rule",
* description="Handles the deletion of a bank_transaction rule by id",
2023-02-10 10:21:10 +01:00
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
2022-11-13 05:12:50 +01:00
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
* @OA\Parameter(ref="#/components/parameters/include"),
* @OA\Parameter(
* name="id",
* in="path",
* description="The Bank Transaction Rule Hashed ID",
* example="D2J234DFA",
* required=true,
* @OA\Schema(
* type="string",
* format="string",
* ),
* ),
* @OA\Response(
* response=200,
* description="Returns a HTTP status",
* @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 destroy(DestroyBankTransactionRuleRequest $request, BankTransactionRule $bank_transaction_rule)
{
$this->bank_transaction_repo->delete($bank_transaction_rule);
return $this->itemResponse($bank_transaction_rule->fresh());
}
/**
* Perform bulk actions on the list view.
*
2023-07-26 04:59:36 +02:00
* @return \Illuminate\Support\Collection
2022-11-13 05:12:50 +01:00
*
* @OA\Post(
* path="/api/v1/bank_transation_rules/bulk",
* operationId="bulkBankTransactionRules",
* tags={"bank_transaction_rules"},
* summary="Performs bulk actions on an array of bank_transation rules",
* description="",
2023-02-10 10:21:10 +01:00
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
2022-11-13 05:12:50 +01:00
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
* @OA\Parameter(ref="#/components/parameters/index"),
* @OA\RequestBody(
* description="Action paramters",
* 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(BulkBankTransactionRuleRequest $request)
2022-11-13 05:12:50 +01:00
{
$action = $request->input('action');
2022-11-13 05:12:50 +01:00
$ids = $request->input('ids');
2024-01-14 05:05:00 +01:00
$bank_transaction_rules = BankTransactionRule::withTrashed()
->whereIn('id', $this->transformKeys($ids))
->company()
->cursor()
->each(function ($bank_transaction_rule, $key) use ($action) {
2023-02-16 02:36:09 +01:00
$this->bank_transaction_repo->{$action}($bank_transaction_rule);
});
2022-11-13 05:12:50 +01:00
/* Need to understand which permission are required for the given bulk action ie. view / edit */
return $this->listResponse(BankTransactionRule::withTrashed()->whereIn('id', $this->transformKeys($ids))->company());
}
2023-02-16 02:36:09 +01:00
}