parent
48ae7a5a8a
commit
774f64a051
|
|
@ -43,6 +43,10 @@ class Transactions extends ApiController
|
|||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
if ($request->has('document_id')) {
|
||||
return $this->errorBadRequest(trans('transactions.messages.create_document_transaction_error'));
|
||||
}
|
||||
|
||||
$transaction = $this->dispatch(new CreateTransaction($request));
|
||||
|
||||
return $this->created(route('api.transactions.show', $transaction->id), new Resource($transaction));
|
||||
|
|
@ -57,6 +61,10 @@ class Transactions extends ApiController
|
|||
*/
|
||||
public function update(Transaction $transaction, Request $request)
|
||||
{
|
||||
if ($request->has('document_id')) {
|
||||
return $this->errorBadRequest(trans('transactions.messages.update_document_transaction_error'));
|
||||
}
|
||||
|
||||
$transaction = $this->dispatch(new UpdateTransaction($transaction, $request));
|
||||
|
||||
return new Resource($transaction->fresh());
|
||||
|
|
@ -70,6 +78,10 @@ class Transactions extends ApiController
|
|||
*/
|
||||
public function destroy(Transaction $transaction)
|
||||
{
|
||||
if ($transaction->document_id) {
|
||||
return $this->errorBadRequest(trans('transactions.messages.delete_document_transaction_error'));
|
||||
}
|
||||
|
||||
try {
|
||||
$this->dispatch(new DeleteTransaction($transaction));
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ use App\Abstracts\Http\ApiController;
|
|||
use App\Http\Requests\Banking\Transaction as Request;
|
||||
use App\Http\Resources\Banking\Transaction as Resource;
|
||||
use App\Jobs\Banking\CreateBankingDocumentTransaction;
|
||||
use App\Jobs\Banking\UpdateBankingDocumentTransaction;
|
||||
use App\Jobs\Banking\DeleteTransaction;
|
||||
use App\Models\Banking\Transaction;
|
||||
use App\Models\Document\Document;
|
||||
|
|
@ -32,7 +33,7 @@ class DocumentTransactions extends ApiController
|
|||
*/
|
||||
public function index($document_id)
|
||||
{
|
||||
$transactions = Transaction::documentId($document_id)->get();
|
||||
$transactions = Transaction::with(['document', 'taxes'])->documentId($document_id)->get();
|
||||
|
||||
return Resource::collection($transactions);
|
||||
}
|
||||
|
|
@ -46,7 +47,7 @@ class DocumentTransactions extends ApiController
|
|||
*/
|
||||
public function show($document_id, $id)
|
||||
{
|
||||
$transaction = Transaction::documentId($document_id)->find($id);
|
||||
$transaction = Transaction::with(['document', 'taxes'])->documentId($document_id)->find($id);
|
||||
|
||||
if (! $transaction instanceof Transaction) {
|
||||
return $this->errorInternal('No query results for model [' . Transaction::class . '] ' . $id);
|
||||
|
|
@ -71,6 +72,25 @@ class DocumentTransactions extends ApiController
|
|||
return $this->created(route('api.documents.transactions.show', [$document_id, $transaction->id]), new Resource($transaction));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param $document_id
|
||||
* @param $id
|
||||
* @param $request
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function update($document_id, $id, Request $request)
|
||||
{
|
||||
$document = Document::find($document_id);
|
||||
|
||||
$transaction = Transaction::documentId($document_id)->find($id);
|
||||
|
||||
$transaction = $this->dispatch(new UpdateBankingDocumentTransaction($document, $transaction, $request));
|
||||
|
||||
return $this->created(route('api.documents.transactions.show', [$document_id, $transaction->id]), new Resource($transaction));
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ class Documents extends ApiController
|
|||
*/
|
||||
public function index()
|
||||
{
|
||||
$documents = Document::with('contact', 'histories', 'items', 'transactions')->collect(['issued_at'=> 'desc']);
|
||||
$documents = Document::with('contact', 'histories', 'items', 'item_taxes', 'totals', 'transactions')->collect(['issued_at'=> 'desc']);
|
||||
|
||||
return Resource::collection($documents);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,4 +48,10 @@ return [
|
|||
'description' => 'You are previewing how your customer will see the web version of your payment.',
|
||||
],
|
||||
|
||||
'messages' => [
|
||||
'create_document_transaction_error' => 'This endpoint cannot be added to a document. Use {{akaunting_url}}/documents/{{akaunting_document_id}}/transactions',
|
||||
'update_document_transaction_error' => 'This endpoint cannot be updated to a document. Use {{akaunting_url}}/documents/{{akaunting_document_id}}/transactions/{akaunting_transaction_id}',
|
||||
'delete_document_transaction_error' => 'This endpoint cannot be deleted to a document. Use {{akaunting_url}}/documents/{{akaunting_document_id}}/transactions/{akaunting_transaction_id}',
|
||||
]
|
||||
|
||||
];
|
||||
|
|
|
|||
Loading…
Reference in New Issue