diff --git a/app/Http/Controllers/BankTransactionController.php b/app/Http/Controllers/BankTransactionController.php new file mode 100644 index 000000000000..8f7e744e7208 --- /dev/null +++ b/app/Http/Controllers/BankTransactionController.php @@ -0,0 +1,448 @@ +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-Secret"), + * @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 Request $request + * @return Response|mixed + */ + public function index(Request $request) + { + + $bank_transactions = BankTransaction::query()->company(); + + 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-Secret"), + * @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-Secret"), + * @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-Secret"), + * @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 + $bank_transaction = $this->bank_transaction_repo->save($request->all(), $bank_transaction); + + 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-Secret"), + * @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); + + 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-Secret"), + * @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 + $bank_transaction = $this->bank_transaction_repo->save($request->all(), BankTransactionFactory::create(auth()->user()->company()->id, auth()->user()->id, auth()->user()->account_id)); + + 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-Secret"), + * @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); + + return $this->itemResponse($bank_transaction->fresh()); + } + + public function getTransactions(AdminBankTransactionRequest $request) + { + + $bank_account_id = auth()->user()->account->bank_transaction_account_id; + + $bank_account_id = 'sbMem62e1e69547bfb1'; + + if(!$bank_account_id) + return response()->json(['message' => 'Not yet authenticated with Bank Integration service'], 400); + + $yodlee = new Yodlee($bank_account_id); + $yodlee->setTestMode(); + + $data = [ + 'CONTAINER' => 'bank', + 'categoryType' => 'INCOME, UNCATEGORIZE', + 'top' => 500, + 'fromDate' => '2000-10-10', /// YYYY-MM-DD + ]; + + $transactions = $yodlee->getTransactions($data); + + $transactions = (new BankService(auth()->user()->company()))->match(); + + return response()->json($transactions, 200, [], JSON_PRETTY_PRINT); + + } +} \ No newline at end of file diff --git a/app/Http/Controllers/ClientController.php b/app/Http/Controllers/ClientController.php index b99917040a0e..22647928799a 100644 --- a/app/Http/Controllers/ClientController.php +++ b/app/Http/Controllers/ClientController.php @@ -662,7 +662,7 @@ class ClientController extends BaseController * * * @OA\Post( - * path="/api/v1/clients/{id}/{mergaeble_client_hashed_id}/merge", + * path="/api/v1/clients/{id}/{mergeable_client_hashed_id}/merge", * operationId="mergeClient", * tags={"clients"}, * summary="Merges two clients", @@ -683,7 +683,7 @@ class ClientController extends BaseController * ), * ), * @OA\Parameter( - * name="mergeable_client_hashedid", + * name="mergeable_client_hashed_id", * in="path", * description="The Mergeable Client Hashed ID", * example="D2J234DFA", diff --git a/app/Http/Controllers/OpenAPI/BankTransaction.php b/app/Http/Controllers/OpenAPI/BankTransaction.php new file mode 100644 index 000000000000..0895e9ef617f --- /dev/null +++ b/app/Http/Controllers/OpenAPI/BankTransaction.php @@ -0,0 +1,20 @@ +belongsTo(Company::class); + } + + public function invoice() + { + return $this->belongsTo(Invoice::class); + } + + public function expense() + { + return $this->belongsTo(Expense::class); + } + + public function user() + { + return $this->belongsTo(User::class)->withTrashed(); + } + + public function bank_integration() + { + return $this->belongsTo(BankIntegration::class)->withTrashed(); + } + + public function account() + { + return $this->belongsTo(Account::class)->withTrashed(); + } + +} \ No newline at end of file diff --git a/app/Repositories/BankTransactionRepository.php b/app/Repositories/BankTransactionRepository.php new file mode 100644 index 000000000000..c74b5abefbad --- /dev/null +++ b/app/Repositories/BankTransactionRepository.php @@ -0,0 +1,33 @@ +save(); + + } + +} diff --git a/app/Transformers/BankTransactionTransformer.php b/app/Transformers/BankTransactionTransformer.php new file mode 100644 index 000000000000..7729e1b8ff52 --- /dev/null +++ b/app/Transformers/BankTransactionTransformer.php @@ -0,0 +1,97 @@ + (string) $this->encodePrimaryKey($bank_transaction->id), + 'transaction_id' => (int)$bank_transaction->transaction_id, + 'amount' => (float)$bank_transaction->amount ?: 0, + 'currency_code' => (string)$bank_transaction->currency_code ?: '', + 'account_type' => (string)$bank_transaction->account_type ?: '', + 'category_id' => (int) $bank_transaction->category_id, + 'category_type' => (string)$bank_transaction->category_type ?: '', + 'date' => (string)$bank_transaction->date ?: '', + 'bank_account_id' => (int)$bank_transaction->bank_account_id, + 'description' => (string)$bank_transaction->description ?: '', + 'invoice_id' => (string)$this->encodePrimaryKey($bank_transaction->invoice_id) ?: '', + 'expense_id'=> (string)$this->encodePrimaryKey($bank_transaction->expense_id) ?: '', + 'is_matched'=> (bool)$bank_transaction->is_matched ?: '', + ]; + } + + public function includeAccount(BankTransaction $bank_transaction) + { + $transformer = new AccountTransformer($this->serializer); + + return $this->includeItem($bank_transaction->account, $transformer, Account::class); + } + + public function includeCompany(BankTransaction $bank_transaction) + { + $transformer = new CompanyTransformer($this->serializer); + + return $this->includeItem($bank_transaction->company, $transformer, Company::class); + } + + public function includeInvoice(BankTransaction $bank_transaction) + { + $transformer = new InvoiceTransformer($this->serializer); + + return $this->includeItem($bank_transaction->invoice, $transformer, Invoice::class); + } + + public function includeExpense(BankTransaction $bank_transaction) + { + $transformer = new ExpenseTransformer($this->serializer); + + return $this->includeItem($bank_transaction->expense, $transformer, Expense::class); + } + +}