akaunting/app/Http/Controllers/Api/Document/DocumentTransactions.php

86 lines
2.6 KiB
PHP
Raw Normal View History

2019-11-16 10:21:14 +03:00
<?php
2020-12-24 01:28:38 +03:00
namespace App\Http\Controllers\Api\Document;
2019-11-16 10:21:14 +03:00
2021-01-02 13:06:02 +03:00
use App\Abstracts\Http\ApiController;
2019-11-16 10:21:14 +03:00
use App\Http\Requests\Banking\Transaction as Request;
2020-12-24 01:28:38 +03:00
use App\Jobs\Banking\CreateBankingDocumentTransaction;
2019-11-16 10:21:14 +03:00
use App\Jobs\Banking\DeleteTransaction;
use App\Models\Banking\Transaction;
2020-12-24 01:28:38 +03:00
use App\Models\Document\Document;
2019-11-16 10:21:14 +03:00
use App\Transformers\Banking\Transaction as Transformer;
2021-01-02 13:06:02 +03:00
class DocumentTransactions extends ApiController
2019-11-16 10:21:14 +03:00
{
2021-01-02 13:06:02 +03:00
/**
* Instantiate a new controller instance.
*/
public function __construct()
{
// Add CRUD permission check
$this->middleware('permission:create-banking-transactions')->only('create', 'store', 'duplicate', 'import');
$this->middleware('permission:read-banking-transactions')->only('index', 'show', 'edit', 'export');
$this->middleware('permission:update-banking-transactions')->only('update', 'enable', 'disable');
$this->middleware('permission:delete-banking-transactions')->only('destroy');
}
2019-11-16 10:21:14 +03:00
/**
* Display a listing of the resource.
*
2020-12-24 01:28:38 +03:00
* @param $document_id
2019-11-16 10:21:14 +03:00
* @return \Dingo\Api\Http\Response
*/
2020-12-24 01:28:38 +03:00
public function index($document_id)
2019-11-16 10:21:14 +03:00
{
2021-01-02 13:06:02 +03:00
$transactions = Transaction::documentId($document_id)->get();
2019-11-16 10:21:14 +03:00
return $this->response->collection($transactions, new Transformer());
}
/**
* Display the specified resource.
*
2020-12-24 01:28:38 +03:00
* @param $document_id
2019-11-16 10:21:14 +03:00
* @param $id
* @return \Dingo\Api\Http\Response
*/
2020-12-24 01:28:38 +03:00
public function show($document_id, $id)
2019-11-16 10:21:14 +03:00
{
2021-01-02 13:06:02 +03:00
$transaction = Transaction::documentId($document_id)->find($id);
2019-11-16 10:21:14 +03:00
2021-05-30 02:43:12 +03:00
return $this->item($transaction, new Transformer());
2019-11-16 10:21:14 +03:00
}
/**
* Store a newly created resource in storage.
*
2020-12-24 01:28:38 +03:00
* @param $document_id
2019-11-16 10:21:14 +03:00
* @param $request
* @return \Dingo\Api\Http\Response
*/
2020-12-24 01:28:38 +03:00
public function store($document_id, Request $request)
2019-11-16 10:21:14 +03:00
{
2020-12-24 01:28:38 +03:00
$document = Document::find($document_id);
2019-11-16 10:21:14 +03:00
2020-12-24 01:28:38 +03:00
$transaction = $this->dispatch(new CreateBankingDocumentTransaction($document, $request));
2019-11-16 10:21:14 +03:00
2021-05-30 02:43:12 +03:00
return $this->response->created(route('api.documents.transactions.show', [$document_id, $transaction->id]), $this->item($transaction, new Transformer()));
2019-11-16 10:21:14 +03:00
}
/**
* Remove the specified resource from storage.
*
2020-12-24 01:28:38 +03:00
* @param $document_id
2019-11-16 10:21:14 +03:00
* @param $id
* @return \Dingo\Api\Http\Response
*/
2020-12-24 01:28:38 +03:00
public function destroy($document_id, $id)
2019-11-16 10:21:14 +03:00
{
2021-01-02 13:06:02 +03:00
$transaction = Transaction::documentId($document_id)->find($id);
2019-11-16 10:21:14 +03:00
$this->dispatch(new DeleteTransaction($transaction));
return $this->response->noContent();
}
}