first commit
This commit is contained in:
77
app/Http/Controllers/Api/Incomes/Customers.php
Normal file
77
app/Http/Controllers/Api/Incomes/Customers.php
Normal file
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Incomes;
|
||||
|
||||
use App\Http\Controllers\ApiController;
|
||||
use App\Http\Requests\Income\Customer as Request;
|
||||
use App\Http\Transformers\Income\Customer as Transformer;
|
||||
use App\Models\Income\Customer;
|
||||
use Dingo\Api\Routing\Helpers;
|
||||
|
||||
class Customers extends ApiController
|
||||
{
|
||||
use Helpers;
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$customers = Customer::collect();
|
||||
|
||||
return $this->response->paginator($customers, new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param Customer $customer
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function show(Customer $customer)
|
||||
{
|
||||
return $this->response->item($customer, new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param $request
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$customer = Customer::create($request->all());
|
||||
|
||||
return $this->response->created(url('api/customers/'.$customer->id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param $customer
|
||||
* @param $request
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function update(Customer $customer, Request $request)
|
||||
{
|
||||
$customer->update($request->all());
|
||||
|
||||
return $this->response->item($customer->fresh(), new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param Customer $customer
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function destroy(Customer $customer)
|
||||
{
|
||||
$customer->delete();
|
||||
|
||||
return $this->response->noContent();
|
||||
}
|
||||
}
|
184
app/Http/Controllers/Api/Incomes/Invoices.php
Normal file
184
app/Http/Controllers/Api/Incomes/Invoices.php
Normal file
@ -0,0 +1,184 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Incomes;
|
||||
|
||||
use App\Events\InvoiceCreated;
|
||||
use App\Events\InvoiceUpdated;
|
||||
use App\Http\Controllers\ApiController;
|
||||
use App\Http\Requests\Income\Invoice as Request;
|
||||
use App\Http\Transformers\Income\Invoice as Transformer;
|
||||
use App\Models\Income\Invoice;
|
||||
use App\Models\Income\InvoiceHistory;
|
||||
use App\Models\Income\InvoiceItem;
|
||||
use App\Models\Income\InvoicePayment;
|
||||
use App\Models\Income\InvoiceStatus;
|
||||
use App\Models\Item\Item;
|
||||
use App\Models\Setting\Tax;
|
||||
use Dingo\Api\Routing\Helpers;
|
||||
|
||||
class Invoices extends ApiController
|
||||
{
|
||||
use Helpers;
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$invoices = Invoice::with('invoice_statuses')->collect();
|
||||
|
||||
return $this->response->paginator($invoices, new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param Invoice $invoice
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function show(Invoice $invoice)
|
||||
{
|
||||
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 = Invoice::create($request->all());
|
||||
|
||||
$invoice_item = array();
|
||||
$invoice_item['company_id'] = $request['company_id'];
|
||||
$invoice_item['invoice_id'] = $invoice->id;
|
||||
|
||||
if ($request['item']) {
|
||||
foreach ($request['item'] as $item) {
|
||||
$item_sku = '';
|
||||
|
||||
if (!empty($item['item_id'])) {
|
||||
$data = Item::where('id', $item['item_id'])->first();
|
||||
|
||||
$item_sku = $data['sku'];
|
||||
}
|
||||
|
||||
$tax_id = 0;
|
||||
$tax_rate = 0;
|
||||
|
||||
if (!empty($item['tax'])) {
|
||||
$tax = Tax::where('id', $item['tax'])->first();
|
||||
|
||||
$tax_rate = $tax->rate;
|
||||
$tax_id = $item['tax'];
|
||||
}
|
||||
|
||||
$invoice_item['item_id'] = $item['item_id'];
|
||||
$invoice_item['name'] = $item['name'];
|
||||
$invoice_item['sku'] = $item_sku;
|
||||
$invoice_item['quantity'] = $item['quantity'];
|
||||
$invoice_item['price'] = $item['price'];
|
||||
$invoice_item['tax'] = (($item['price'] * $item['quantity']) / 100) * $tax_rate;
|
||||
$invoice_item['tax_id'] = $tax_id;
|
||||
$invoice_item['total'] = ($item['price'] + $invoice_item['tax']) * $item['quantity'];
|
||||
|
||||
$request['amount'] += $invoice_item['total'];
|
||||
|
||||
InvoiceItem::create($invoice_item);
|
||||
}
|
||||
}
|
||||
|
||||
$invoice->update($request->input());
|
||||
|
||||
$request['invoice_id'] = $invoice->id;
|
||||
$request['status_code'] = 'draft';
|
||||
$request['notify'] = 0;
|
||||
$request['description'] = trans('messages.success.added', ['type' => $request['invoice_number']]);
|
||||
|
||||
InvoiceHistory::create($request->input());
|
||||
|
||||
// Fire the event to make it extendible
|
||||
event(new InvoiceCreated($invoice));
|
||||
|
||||
return $this->response->created(url('api/invoices/'.$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_item = array();
|
||||
$invoice_item['company_id'] = $request['company_id'];
|
||||
$invoice_item['invoice_id'] = $invoice->id;
|
||||
|
||||
if ($request['item']) {
|
||||
InvoiceItem::where('invoice_id', $invoice->id)->delete();
|
||||
|
||||
foreach ($request['item'] as $item) {
|
||||
$item_sku = '';
|
||||
|
||||
if (!empty($item['item_id'])) {
|
||||
$data = Item::where('id', $item['item_id'])->first();
|
||||
|
||||
$item_sku = $data['sku'];
|
||||
}
|
||||
|
||||
$tax_id = 0;
|
||||
$tax_rate = 0;
|
||||
|
||||
if (!empty($item['tax'])) {
|
||||
$tax = Tax::where('id', $item['tax'])->first();
|
||||
|
||||
$tax_rate = $tax->rate;
|
||||
$tax_id = $item['tax'];
|
||||
}
|
||||
|
||||
$invoice_item['item_id'] = $item['item_id'];
|
||||
$invoice_item['name'] = $item['name'];
|
||||
$invoice_item['sku'] = $item_sku;
|
||||
$invoice_item['quantity'] = $item['quantity'];
|
||||
$invoice_item['price'] = $item['price'];
|
||||
$invoice_item['tax'] = (($item['price'] * $item['quantity']) / 100 * $tax_rate);
|
||||
$invoice_item['tax_id'] = $tax_id;
|
||||
$invoice_item['total'] = ($item['price'] + $invoice_item['tax']) * $item['quantity'];
|
||||
|
||||
$request['amount'] += $invoice_item['total'];
|
||||
|
||||
InvoiceItem::create($invoice_item);
|
||||
}
|
||||
}
|
||||
|
||||
$invoice->update($request->input());
|
||||
|
||||
// Fire the event to make it extendible
|
||||
event(new InvoiceUpdated($invoice));
|
||||
|
||||
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)
|
||||
{
|
||||
$invoice->delete();
|
||||
|
||||
InvoiceItem::where('invoice_id', $invoice->id)->delete();
|
||||
InvoicePayment::where('invoice_id', $invoice->id)->delete();
|
||||
InvoiceHistory::where('invoice_id', $invoice->id)->delete();
|
||||
|
||||
return $this->response->noContent();
|
||||
}
|
||||
}
|
77
app/Http/Controllers/Api/Incomes/Revenues.php
Normal file
77
app/Http/Controllers/Api/Incomes/Revenues.php
Normal file
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Incomes;
|
||||
|
||||
use App\Http\Controllers\ApiController;
|
||||
use App\Http\Requests\Income\Revenue as Request;
|
||||
use App\Http\Transformers\Income\Revenue as Transformer;
|
||||
use App\Models\Income\Revenue;
|
||||
use Dingo\Api\Routing\Helpers;
|
||||
|
||||
class Revenues extends ApiController
|
||||
{
|
||||
use Helpers;
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$revenues = Revenue::with('account', 'customer', 'category')->collect();
|
||||
|
||||
return $this->response->paginator($revenues, new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param Revenue $revenue
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function show(Revenue $revenue)
|
||||
{
|
||||
return $this->response->item($revenue, new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param $request
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$revenue = Revenue::create($request->all());
|
||||
|
||||
return $this->response->created(url('api/revenues/'.$revenue->id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param $revenue
|
||||
* @param $request
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function update(Revenue $revenue, Request $request)
|
||||
{
|
||||
$revenue->update($request->all());
|
||||
|
||||
return $this->response->item($revenue->fresh(), new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param Revenue $revenue
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function destroy(Revenue $revenue)
|
||||
{
|
||||
$revenue->delete();
|
||||
|
||||
return $this->response->noContent();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user