From b21344693ce8a2449738f91a1a5a2876edc25bb7 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 26 Apr 2023 07:58:40 +1000 Subject: [PATCH] Clear up bank transactions --- .../Controllers/BankTransactionController.php | 417 ------------------ .../MatchBankTransactionRequest.php | 16 +- app/Jobs/Bank/MatchBankTransactions.php | 2 - 3 files changed, 1 insertion(+), 434 deletions(-) diff --git a/app/Http/Controllers/BankTransactionController.php b/app/Http/Controllers/BankTransactionController.php index be049d7c17..eefad1dd49 100644 --- a/app/Http/Controllers/BankTransactionController.php +++ b/app/Http/Controllers/BankTransactionController.php @@ -44,50 +44,6 @@ class BankTransactionController extends BaseController $this->bank_transaction_repo = $bank_transaction_repo; } - /** - * @OA\Get( - * path="/api/v1/bank_transactions", - * operationId="getBankTransactions", - * tags={"bank_transactions"}, - * summary="Gets a list of bank_transactions", - * description="Lists all bank integrations", - * @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"), - * @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/BankTransaction"), - * ), - * @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"), - * ), - * ) - * @param BankTransactionFilters $filter - * @return Response|mixed - */ public function index(BankTransactionFilters $filters) { $bank_transactions = BankTransaction::filter($filters); @@ -95,165 +51,16 @@ class BankTransactionController extends BaseController return $this->listResponse($bank_transactions); } - /** - * Display the specified resource. - * - * @param ShowBankTransactionRequest $request - * @param BankTransaction $bank_transaction - * @return Response - * - * - * @OA\Get( - * path="/api/v1/bank_transactions/{id}", - * operationId="showBankTransaction", - * tags={"bank_transactions"}, - * summary="Shows a bank_transaction", - * description="Displays a bank_transaction by id", - * @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"), - * @OA\Parameter(ref="#/components/parameters/X-Requested-With"), - * @OA\Parameter(ref="#/components/parameters/include"), - * @OA\Parameter( - * name="id", - * in="path", - * description="The BankTransaction Hashed ID", - * example="D2J234DFA", - * required=true, - * @OA\Schema( - * type="string", - * format="string", - * ), - * ), - * @OA\Response( - * response=200, - * description="Returns the bank_transaction 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/BankTransaction"), - * ), - * @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(ShowBankTransactionRequest $request, BankTransaction $bank_transaction) { return $this->itemResponse($bank_transaction); } - - /** - * Show the form for editing the specified resource. - * - * @param EditBankTransactionRequest $request - * @param BankTransaction $bank_transaction - * @return Response - * - * - * @OA\Get( - * path="/api/v1/bank_transactions/{id}/edit", - * operationId="editBankTransaction", - * tags={"bank_transactions"}, - * summary="Shows a bank_transaction for editing", - * description="Displays a bank_transaction by id", - * @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"), - * @OA\Parameter(ref="#/components/parameters/X-Requested-With"), - * @OA\Parameter(ref="#/components/parameters/include"), - * @OA\Parameter( - * name="id", - * in="path", - * description="The BankTransaction Hashed ID", - * example="D2J234DFA", - * required=true, - * @OA\Schema( - * type="string", - * format="string", - * ), - * ), - * @OA\Response( - * response=200, - * description="Returns the bank_transaction 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/BankTransaction"), - * ), - * @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(EditBankTransactionRequest $request, BankTransaction $bank_transaction) { return $this->itemResponse($bank_transaction); } - /** - * Update the specified resource in storage. - * - * @param UpdateBankTransactionRequest $request - * @param BankTransaction $bank_transaction - * @return Response - * - * - * - * @OA\Put( - * path="/api/v1/bank_transactions/{id}", - * operationId="updateBankTransaction", - * tags={"bank_transactions"}, - * summary="Updates a bank_transaction", - * description="Handles the updating of a bank_transaction by id", - * @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"), - * @OA\Parameter(ref="#/components/parameters/X-Requested-With"), - * @OA\Parameter(ref="#/components/parameters/include"), - * @OA\Parameter( - * name="id", - * in="path", - * description="The BankTransaction Hashed ID", - * example="D2J234DFA", - * required=true, - * @OA\Schema( - * type="string", - * format="string", - * ), - * ), - * @OA\Response( - * response=200, - * description="Returns the bank_transaction 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/BankTransaction"), - * ), - * @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(UpdateBankTransactionRequest $request, BankTransaction $bank_transaction) { //stubs for updating the model @@ -262,44 +69,6 @@ class BankTransactionController extends BaseController return $this->itemResponse($bank_transaction->fresh()); } - /** - * Show the form for creating a new resource. - * - * @param CreateBankTransactionRequest $request - * @return Response - * - * - * - * @OA\Get( - * path="/api/v1/bank_transactions/create", - * operationId="getBankTransactionsCreate", - * tags={"bank_transactions"}, - * summary="Gets a new blank bank_transaction object", - * description="Returns a blank object with default values", - * @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"), - * @OA\Parameter(ref="#/components/parameters/X-Requested-With"), - * @OA\Parameter(ref="#/components/parameters/include"), - * @OA\Response( - * response=200, - * description="A blank bank_transaction 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/BankTransaction"), - * ), - * @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(CreateBankTransactionRequest $request) { $bank_transaction = BankTransactionFactory::create(auth()->user()->company()->id, auth()->user()->id, auth()->user()->account_id); @@ -307,44 +76,6 @@ class BankTransactionController extends BaseController return $this->itemResponse($bank_transaction); } - /** - * Store a newly created resource in storage. - * - * @param StoreBankTransactionRequest $request - * @return Response - * - * - * - * @OA\Post( - * path="/api/v1/bank_transactions", - * operationId="storeBankTransaction", - * tags={"bank_transactions"}, - * summary="Adds a bank_transaction", - * description="Adds an bank_transaction to a company", - * @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"), - * @OA\Parameter(ref="#/components/parameters/X-Requested-With"), - * @OA\Parameter(ref="#/components/parameters/include"), - * @OA\Response( - * response=200, - * description="Returns the saved bank_transaction 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/BankTransaction"), - * ), - * @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(StoreBankTransactionRequest $request) { //stub to store the model @@ -353,55 +84,6 @@ class BankTransactionController extends BaseController return $this->itemResponse($bank_transaction); } - /** - * Remove the specified resource from storage. - * - * @param DestroyBankTransactionRequest $request - * @param BankTransaction $bank_transaction - * @return Response - * - * - * @throws \Exception - * @OA\Delete( - * path="/api/v1/bank_transactions/{id}", - * operationId="deleteBankTransaction", - * tags={"bank_transactions"}, - * summary="Deletes a bank_transaction", - * description="Handles the deletion of a bank_transaction by id", - * @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"), - * @OA\Parameter(ref="#/components/parameters/X-Requested-With"), - * @OA\Parameter(ref="#/components/parameters/include"), - * @OA\Parameter( - * name="id", - * in="path", - * description="The BankTransaction 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(DestroyBankTransactionRequest $request, BankTransaction $bank_transaction) { $this->bank_transaction_repo->delete($bank_transaction); @@ -409,56 +91,6 @@ class BankTransactionController extends BaseController return $this->itemResponse($bank_transaction->fresh()); } - - /** - * Perform bulk actions on the list view. - * - * @return Collection - * - * @OA\Post( - * path="/api/v1/bank_transations/bulk", - * operationId="bulkBankTransactions", - * tags={"bank_transactions"}, - * summary="Performs bulk actions on an array of bank_transations", - * description="", - * @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="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(BulkBankTransactionRequest $request) { $action = $request->input('action'); @@ -480,55 +112,6 @@ class BankTransactionController extends BaseController return $this->listResponse(BankTransaction::withTrashed()->whereIn('id', $this->transformKeys($ids))->company()); } - /** - * Perform bulk actions on the list view. - * - * @return Collection - * - * @OA\Post( - * path="/api/v1/bank_transations/match", - * operationId="matchBankTransactions", - * tags={"bank_transactions"}, - * summary="Performs match actions on an array of bank_transactions", - * description="", - * @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="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 match(MatchBankTransactionRequest $request) { $bts = (new MatchBankTransactions(auth()->user()->company()->id, auth()->user()->company()->db, $request->all()))->handle(); diff --git a/app/Http/Requests/BankTransaction/MatchBankTransactionRequest.php b/app/Http/Requests/BankTransaction/MatchBankTransactionRequest.php index fae58d38b5..0ee23451ba 100644 --- a/app/Http/Requests/BankTransaction/MatchBankTransactionRequest.php +++ b/app/Http/Requests/BankTransaction/MatchBankTransactionRequest.php @@ -13,7 +13,6 @@ namespace App\Http\Requests\BankTransaction; use App\Http\Requests\Request; use App\Models\BankTransaction; -use App\Models\Expense; use App\Models\Payment; class MatchBankTransactionRequest extends Request @@ -39,7 +38,6 @@ class MatchBankTransactionRequest extends Request $rules['transactions.*.vendor_id'] = 'bail|nullable|sometimes|exists:vendors,id,company_id,'.auth()->user()->company()->id.',is_deleted,0'; $rules['transactions.*.id'] = 'bail|required|exists:bank_transactions,id,company_id,'.auth()->user()->company()->id.',is_deleted,0'; $rules['transactions.*.payment_id'] = 'bail|sometimes|nullable|exists:payments,id,company_id,'.auth()->user()->company()->id.',is_deleted,0'; - // $rules['transactions.*.expense_id'] = 'bail|sometimes|nullable|exists:expenses,id,company_id,'.auth()->user()->company()->id.',is_deleted,0'; return $rules; } @@ -47,7 +45,7 @@ class MatchBankTransactionRequest extends Request public function prepareForValidation() { $inputs = $this->all(); - nlog($inputs); + foreach ($inputs['transactions'] as $key => $input) { if (array_key_exists('id', $inputs['transactions'][$key])) { $inputs['transactions'][$key]['id'] = $this->decodePrimaryKey($input['id']); @@ -71,20 +69,8 @@ class MatchBankTransactionRequest extends Request } } - if (array_key_exists('expense_id', $inputs['transactions'][$key]) && strlen($inputs['transactions'][$key]['expense_id']) >= 1) { - // $inputs['transactions'][$key]['expense_id'] = $this->decodePrimaryKey($inputs['transactions'][$key]['expense_id']); - - // $e = Expense::withTrashed()->where('company_id', auth()->user()->company()->id)->where('id', $inputs['transactions'][$key]['expense_id'])->first(); - - /*Ensure we don't relink an existing expense*/ - // if (!$e || is_numeric($e->transaction_id)) { - // unset($inputs['transactions'][$key]['expense_id']); - // } - } } - nlog($inputs); - $this->replace($inputs); } } diff --git a/app/Jobs/Bank/MatchBankTransactions.php b/app/Jobs/Bank/MatchBankTransactions.php index 5839ecf16c..31c1e15380 100644 --- a/app/Jobs/Bank/MatchBankTransactions.php +++ b/app/Jobs/Bank/MatchBankTransactions.php @@ -226,8 +226,6 @@ class MatchBankTransactions implements ShouldQueue return $this; } - nlog($this->getInvoices($input['invoice_ids'])); - $_invoices = Invoice::query() ->withTrashed() ->where('company_id', $this->bt->company_id)