Merge Invoice and Bill into Document
This commit is contained in:
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Sales;
|
||||
|
||||
use App\Http\Requests\Banking\Transaction as Request;
|
||||
use App\Jobs\Banking\CreateBankingDocumentTransaction;
|
||||
use App\Jobs\Banking\DeleteTransaction;
|
||||
use App\Models\Banking\Transaction;
|
||||
use App\Models\Document\Document;
|
||||
use App\Transformers\Banking\Transaction as Transformer;
|
||||
use Dingo\Api\Routing\Helpers;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
|
||||
class InvoiceTransactions extends BaseController
|
||||
{
|
||||
use Helpers, AuthorizesRequests, DispatchesJobs, ValidatesRequests;
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @param $invoice_id
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function index($invoice_id)
|
||||
{
|
||||
$transactions = Transaction::document($invoice_id)->get();
|
||||
|
||||
return $this->response->collection($transactions, new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param $invoice_id
|
||||
* @param $id
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function show($invoice_id, $id)
|
||||
{
|
||||
$transaction = Transaction::document($invoice_id)->find($id);
|
||||
|
||||
return $this->response->item($transaction, new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param $invoice_id
|
||||
* @param $request
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function store($invoice_id, Request $request)
|
||||
{
|
||||
$invoice = Document::find($invoice_id);
|
||||
|
||||
$transaction = $this->dispatch(new CreateBankingDocumentTransaction($invoice, $request));
|
||||
|
||||
return $this->response->created(url('api/invoices/' . $invoice_id . '/transactions/' . $transaction->id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param $invoice_id
|
||||
* @param $id
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function destroy($invoice_id, $id)
|
||||
{
|
||||
$transaction = Transaction::document($invoice_id)->find($id);
|
||||
|
||||
$this->dispatch(new DeleteTransaction($transaction));
|
||||
|
||||
return $this->response->noContent();
|
||||
}
|
||||
}
|
91
modules/BC21/Http/Controllers/Api/Sales/Invoices.php
Normal file
91
modules/BC21/Http/Controllers/Api/Sales/Invoices.php
Normal file
@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Sales;
|
||||
|
||||
use App\Abstracts\Http\ApiController;
|
||||
use App\Http\Requests\Document\Document as Request;
|
||||
use App\Jobs\Document\CreateDocument;
|
||||
use App\Jobs\Document\DeleteDocument;
|
||||
use App\Jobs\Document\UpdateDocument;
|
||||
use App\Models\Document\Document;
|
||||
use App\Transformers\Sale\Invoice as Transformer;
|
||||
|
||||
class Invoices extends ApiController
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$invoices = Document::invoice()->with('contact', 'histories', 'items', 'transactions')->collect(['issued_at'=> 'desc']);
|
||||
|
||||
return $this->response->paginator($invoices, new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param $id
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
// Check if we're querying by id or number
|
||||
if (is_numeric($id)) {
|
||||
$invoice = Document::find($id);
|
||||
} else {
|
||||
$invoice = Document::where('document_number', $id)->first();
|
||||
}
|
||||
|
||||
return $this->response->item($invoice, new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param $request
|
||||
*
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$invoice = $this->dispatch(new CreateDocument($request));
|
||||
|
||||
return $this->response->created(route('api.invoices.show', $invoice->id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param $document
|
||||
* @param $request
|
||||
*
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function update(Document $document, Request $request)
|
||||
{
|
||||
$document = $this->dispatch(new UpdateDocument($document, $request));
|
||||
|
||||
return $this->response->item($document->fresh(), new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param Document $document
|
||||
*
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function destroy(Document $document)
|
||||
{
|
||||
try {
|
||||
$this->dispatch(new DeleteDocument($document));
|
||||
|
||||
return $this->response->noContent();
|
||||
} catch(\Exception $e) {
|
||||
$this->response->errorUnauthorized($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user