Merge Invoice and Bill into Document

This commit is contained in:
Burak Çakırel
2020-12-24 01:28:38 +03:00
parent 830cc05957
commit 0c1424db47
436 changed files with 31655 additions and 37350 deletions

View File

@ -1,12 +1,12 @@
<?php
namespace App\Http\Controllers\Api\Sales;
namespace App\Http\Controllers\Api\Document;
use App\Http\Requests\Banking\Transaction as Request;
use App\Jobs\Banking\CreateDocumentTransaction;
use App\Jobs\Banking\CreateBankingDocumentTransaction;
use App\Jobs\Banking\DeleteTransaction;
use App\Models\Banking\Transaction;
use App\Models\Sale\Invoice;
use App\Models\Document\Document;
use App\Transformers\Banking\Transaction as Transformer;
use Dingo\Api\Routing\Helpers;
use Illuminate\Foundation\Bus\DispatchesJobs;
@ -14,19 +14,19 @@ use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
class InvoiceTransactions extends BaseController
class DocumentTransactions extends BaseController
{
use Helpers, AuthorizesRequests, DispatchesJobs, ValidatesRequests;
/**
* Display a listing of the resource.
*
* @param $invoice_id
* @param $document_id
* @return \Dingo\Api\Http\Response
*/
public function index($invoice_id)
public function index($document_id)
{
$transactions = Transaction::document($invoice_id)->get();
$transactions = Transaction::document($document_id)->get();
return $this->response->collection($transactions, new Transformer());
}
@ -34,13 +34,13 @@ class InvoiceTransactions extends BaseController
/**
* Display the specified resource.
*
* @param $invoice_id
* @param $document_id
* @param $id
* @return \Dingo\Api\Http\Response
*/
public function show($invoice_id, $id)
public function show($document_id, $id)
{
$transaction = Transaction::document($invoice_id)->find($id);
$transaction = Transaction::document($document_id)->find($id);
return $this->response->item($transaction, new Transformer());
}
@ -48,29 +48,29 @@ class InvoiceTransactions extends BaseController
/**
* Store a newly created resource in storage.
*
* @param $invoice_id
* @param $document_id
* @param $request
* @return \Dingo\Api\Http\Response
*/
public function store($invoice_id, Request $request)
public function store($document_id, Request $request)
{
$invoice = Invoice::find($invoice_id);
$document = Document::find($document_id);
$transaction = $this->dispatch(new CreateDocumentTransaction($invoice, $request));
$transaction = $this->dispatch(new CreateBankingDocumentTransaction($document, $request));
return $this->response->created(url('api/invoices/' . $invoice_id . '/transactions/' . $transaction->id));
return $this->response->created(route('documents.transactions.show', [$document_id, $transaction->id]));
}
/**
* Remove the specified resource from storage.
*
* @param $invoice_id
* @param $document_id
* @param $id
* @return \Dingo\Api\Http\Response
*/
public function destroy($invoice_id, $id)
public function destroy($document_id, $id)
{
$transaction = Transaction::document($invoice_id)->find($id);
$transaction = Transaction::document($document_id)->find($id);
$this->dispatch(new DeleteTransaction($transaction));

View File

@ -0,0 +1,91 @@
<?php
namespace App\Http\Controllers\Api\Document;
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\Document\Document as Transformer;
class Documents extends ApiController
{
/**
* Display a listing of the resource.
*
* @return \Dingo\Api\Http\Response
*/
public function index()
{
$documents = Document::with('contact', 'histories', 'items', 'transactions')->collect(['issued_at'=> 'desc']);
return $this->response->paginator($documents, 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)) {
$document = Document::find($id);
} else {
$document = Document::where('document_number', $id)->first();
}
return $this->response->item($document, new Transformer());
}
/**
* Store a newly created resource in storage.
*
* @param $request
*
* @return \Dingo\Api\Http\Response
*/
public function store(Request $request)
{
$document = $this->dispatch(new CreateDocument($request));
return $this->response->created(route('api.documents.show', $document->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());
}
}
}

View File

@ -1,81 +0,0 @@
<?php
namespace App\Http\Controllers\Api\Purchases;
use App\Abstracts\Http\ApiController;
use App\Http\Requests\Purchase\Bill as Request;
use App\Jobs\Purchase\CreateBill;
use App\Jobs\Purchase\DeleteBill;
use App\Jobs\Purchase\UpdateBill;
use App\Models\Purchase\Bill;
use App\Transformers\Purchase\Bill as Transformer;
class Bills extends ApiController
{
/**
* Display a listing of the resource.
*
* @return \Dingo\Api\Http\Response
*/
public function index()
{
$bills = Bill::with('contact', 'histories', 'items', 'transactions')->collect(['billed_at'=> 'desc']);
return $this->response->paginator($bills, new Transformer());
}
/**
* Display the specified resource.
*
* @param Bill $bill
* @return \Dingo\Api\Http\Response
*/
public function show(Bill $bill)
{
return $this->response->item($bill, new Transformer());
}
/**
* Store a newly created resource in storage.
*
* @param $request
* @return \Dingo\Api\Http\Response
*/
public function store(Request $request)
{
$bill = $this->dispatch(new CreateBill($request));
return $this->response->created(route('api.bills.show', $bill->id));
}
/**
* Update the specified resource in storage.
*
* @param $bill
* @param $request
* @return \Dingo\Api\Http\Response
*/
public function update(Bill $bill, Request $request)
{
$bill = $this->dispatch(new UpdateBill($bill, $request));
return $this->item($bill->fresh(), new Transformer());
}
/**
* Remove the specified resource from storage.
*
* @param Bill $bill
* @return \Dingo\Api\Http\Response
*/
public function destroy(Bill $bill)
{
try {
$this->dispatch(new DeleteBill($bill));
return $this->response->noContent();
} catch(\Exception $e) {
$this->response->errorUnauthorized($e->getMessage());
}
}
}

View File

@ -1,88 +0,0 @@
<?php
namespace App\Http\Controllers\Api\Sales;
use App\Abstracts\Http\ApiController;
use App\Http\Requests\Sale\Invoice as Request;
use App\Jobs\Sale\CreateInvoice;
use App\Jobs\Sale\DeleteInvoice;
use App\Jobs\Sale\UpdateInvoice;
use App\Models\Sale\Invoice;
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 = Invoice::with('contact', 'histories', 'items', 'transactions')->collect(['invoiced_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 = Invoice::find($id);
} else {
$invoice = Invoice::where('invoice_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 CreateInvoice($request));
return $this->response->created(route('api.invoices.show', $invoice->id));
}
/**
* Update the specified resource in storage.
*
* @param $invoice
* @param $request
* @return \Dingo\Api\Http\Response
*/
public function update(Invoice $invoice, Request $request)
{
$invoice = $this->dispatch(new UpdateInvoice($invoice, $request));
return $this->response->item($invoice->fresh(), new Transformer());
}
/**
* Remove the specified resource from storage.
*
* @param Invoice $invoice
* @return \Dingo\Api\Http\Response
*/
public function destroy(Invoice $invoice)
{
try {
$this->dispatch(new DeleteInvoice($invoice));
return $this->response->noContent();
} catch(\Exception $e) {
$this->response->errorUnauthorized($e->getMessage());
}
}
}