v2 first commit
This commit is contained in:
@ -2,16 +2,16 @@
|
||||
|
||||
namespace App\Http\Controllers\Api\Auth;
|
||||
|
||||
use App\Http\Controllers\ApiController;
|
||||
use App\Abstracts\Http\ApiController;
|
||||
use App\Http\Requests\Auth\Permission as Request;
|
||||
use App\Models\Auth\Permission;
|
||||
use App\Jobs\Auth\CreatePermission;
|
||||
use App\Jobs\Auth\DeletePermission;
|
||||
use App\Jobs\Auth\UpdatePermission;
|
||||
use App\Transformers\Auth\Permission as Transformer;
|
||||
use Dingo\Api\Routing\Helpers;
|
||||
|
||||
class Permissions extends ApiController
|
||||
{
|
||||
use Helpers;
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
@ -43,9 +43,9 @@ class Permissions extends ApiController
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$permission = Permission::create($request->all());
|
||||
$permission = $this->dispatch(new CreatePermission($request));
|
||||
|
||||
return $this->response->created(url('api/permissions/'.$permission->id));
|
||||
return $this->response->created(url('api/permissions/' . $permission->id));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -57,9 +57,9 @@ class Permissions extends ApiController
|
||||
*/
|
||||
public function update(Permission $permission, Request $request)
|
||||
{
|
||||
$permission->update($request->all());
|
||||
$permission = $this->dispatch(new UpdatePermission($permission, $request));
|
||||
|
||||
return $this->response->item($permission->fresh(), new Transformer());
|
||||
return $this->item($permission->fresh(), new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -70,8 +70,12 @@ class Permissions extends ApiController
|
||||
*/
|
||||
public function destroy(Permission $permission)
|
||||
{
|
||||
$permission->delete();
|
||||
try {
|
||||
$this->dispatch(new DeletePermission($permission));
|
||||
|
||||
return $this->response->noContent();
|
||||
return $this->response->noContent();
|
||||
} catch(\Exception $e) {
|
||||
$this->response->errorUnauthorized($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,16 +2,16 @@
|
||||
|
||||
namespace App\Http\Controllers\Api\Auth;
|
||||
|
||||
use App\Http\Controllers\ApiController;
|
||||
use App\Abstracts\Http\ApiController;
|
||||
use App\Http\Requests\Auth\Role as Request;
|
||||
use App\Models\Auth\Role;
|
||||
use App\Jobs\Auth\CreateRole;
|
||||
use App\Jobs\Auth\DeleteRole;
|
||||
use App\Jobs\Auth\UpdateRole;
|
||||
use App\Transformers\Auth\Role as Transformer;
|
||||
use Dingo\Api\Routing\Helpers;
|
||||
|
||||
class Roles extends ApiController
|
||||
{
|
||||
use Helpers;
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
@ -43,13 +43,9 @@ class Roles extends ApiController
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$role = Role::create($request->input());
|
||||
$role = $this->dispatch(new CreateRole($request));
|
||||
|
||||
if ($request->has('permissions')) {
|
||||
$role->permissions()->attach($request->get('permissions'));
|
||||
}
|
||||
|
||||
return $this->response->created(url('api/roles/'.$role->id));
|
||||
return $this->response->created(url('api/roles/' . $role->id));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -61,13 +57,9 @@ class Roles extends ApiController
|
||||
*/
|
||||
public function update(Role $role, Request $request)
|
||||
{
|
||||
$role->update($request->all());
|
||||
$role = $this->dispatch(new UpdateRole($role, $request));
|
||||
|
||||
if ($request->has('permissions')) {
|
||||
$role->permissions()->attach($request->get('permissions'));
|
||||
}
|
||||
|
||||
return $this->response->item($role->fresh(), new Transformer());
|
||||
return $this->item($role->fresh(), new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -78,8 +70,12 @@ class Roles extends ApiController
|
||||
*/
|
||||
public function destroy(Role $role)
|
||||
{
|
||||
$role->delete();
|
||||
try {
|
||||
$this->dispatch(new DeleteRole($role));
|
||||
|
||||
return $this->response->noContent();
|
||||
return $this->response->noContent();
|
||||
} catch(\Exception $e) {
|
||||
$this->response->errorUnauthorized($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,16 +2,16 @@
|
||||
|
||||
namespace App\Http\Controllers\Api\Auth;
|
||||
|
||||
use App\Http\Controllers\ApiController;
|
||||
use App\Abstracts\Http\ApiController;
|
||||
use App\Http\Requests\Auth\User as Request;
|
||||
use App\Jobs\Auth\CreateUser;
|
||||
use App\Jobs\Auth\DeleteUser;
|
||||
use App\Jobs\Auth\UpdateUser;
|
||||
use App\Models\Auth\User;
|
||||
use App\Transformers\Auth\User as Transformer;
|
||||
use Dingo\Api\Routing\Helpers;
|
||||
|
||||
class Users extends ApiController
|
||||
{
|
||||
use Helpers;
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
@ -50,15 +50,9 @@ class Users extends ApiController
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$user = User::create($request->input());
|
||||
$user = $this->dispatch(new CreateUser($request));
|
||||
|
||||
// Attach roles
|
||||
$user->roles()->attach($request->get('roles'));
|
||||
|
||||
// Attach companies
|
||||
$user->companies()->attach($request->get('companies'));
|
||||
|
||||
return $this->response->created(url('api/users/'.$user->id));
|
||||
return $this->response->created(url('api/users/' . $user->id));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -70,16 +64,35 @@ class Users extends ApiController
|
||||
*/
|
||||
public function update(User $user, Request $request)
|
||||
{
|
||||
// Except password as we don't want to let the users change a password from this endpoint
|
||||
$user->update($request->except('password'));
|
||||
$user = $this->dispatch(new UpdateUser($user, $request));
|
||||
|
||||
// Sync roles
|
||||
$user->roles()->sync($request->get('roles'));
|
||||
return $this->item($user->fresh(), new Transformer());
|
||||
}
|
||||
|
||||
// Sync companies
|
||||
$user->companies()->sync($request->get('companies'));
|
||||
/**
|
||||
* Enable the specified resource in storage.
|
||||
*
|
||||
* @param User $user
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function enable(User $user)
|
||||
{
|
||||
$user = $this->dispatch(new UpdateUser($user, request()->merge(['enabled' => 1])));
|
||||
|
||||
return $this->response->item($user->fresh(), new Transformer());
|
||||
return $this->item($user->fresh(), new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable the specified resource in storage.
|
||||
*
|
||||
* @param User $user
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function disable(User $user)
|
||||
{
|
||||
$user = $this->dispatch(new UpdateUser($user, request()->merge(['enabled' => 0])));
|
||||
|
||||
return $this->item($user->fresh(), new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -90,8 +103,12 @@ class Users extends ApiController
|
||||
*/
|
||||
public function destroy(User $user)
|
||||
{
|
||||
$user->delete();
|
||||
try {
|
||||
$this->dispatch(new DeleteUser($user));
|
||||
|
||||
return $this->response->noContent();
|
||||
return $this->response->noContent();
|
||||
} catch(\Exception $e) {
|
||||
$this->response->errorUnauthorized($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,16 +2,16 @@
|
||||
|
||||
namespace App\Http\Controllers\Api\Banking;
|
||||
|
||||
use App\Http\Controllers\ApiController;
|
||||
use App\Abstracts\Http\ApiController;
|
||||
use App\Http\Requests\Banking\Account as Request;
|
||||
use App\Jobs\Banking\CreateAccount;
|
||||
use App\Jobs\Banking\DeleteAccount;
|
||||
use App\Jobs\Banking\UpdateAccount;
|
||||
use App\Models\Banking\Account;
|
||||
use App\Transformers\Banking\Account as Transformer;
|
||||
use Dingo\Api\Routing\Helpers;
|
||||
|
||||
class Accounts extends ApiController
|
||||
{
|
||||
use Helpers;
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
@ -27,11 +27,18 @@ class Accounts extends ApiController
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param Account $account
|
||||
* @param $id
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function show(Account $account)
|
||||
public function show($id)
|
||||
{
|
||||
// Check if we're querying by id or number
|
||||
if (is_numeric($id)) {
|
||||
$account = Account::find($id);
|
||||
} else {
|
||||
$account = Account::where('number', $id)->first();
|
||||
}
|
||||
|
||||
return $this->response->item($account, new Transformer());
|
||||
}
|
||||
|
||||
@ -43,9 +50,9 @@ class Accounts extends ApiController
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$account = Account::create($request->all());
|
||||
$account = $this->dispatch(new CreateAccount($request));
|
||||
|
||||
return $this->response->created(url('api/accounts/'.$account->id));
|
||||
return $this->response->created(url('api/accounts/' . $account->id));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -57,9 +64,43 @@ class Accounts extends ApiController
|
||||
*/
|
||||
public function update(Account $account, Request $request)
|
||||
{
|
||||
$account->update($request->all());
|
||||
try {
|
||||
$account = $this->dispatch(new UpdateAccount($account, $request));
|
||||
|
||||
return $this->response->item($account->fresh(), new Transformer());
|
||||
return $this->item($account->fresh(), new Transformer());
|
||||
} catch(\Exception $e) {
|
||||
$this->response->errorUnauthorized($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable the specified resource in storage.
|
||||
*
|
||||
* @param Account $account
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function enable(Account $account)
|
||||
{
|
||||
$account = $this->dispatch(new UpdateAccount($account, request()->merge(['enabled' => 1])));
|
||||
|
||||
return $this->item($account->fresh(), new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable the specified resource in storage.
|
||||
*
|
||||
* @param Account $account
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function disable(Account $account)
|
||||
{
|
||||
try {
|
||||
$account = $this->dispatch(new UpdateAccount($account, request()->merge(['enabled' => 0])));
|
||||
|
||||
return $this->item($account->fresh(), new Transformer());
|
||||
} catch(\Exception $e) {
|
||||
$this->response->errorUnauthorized($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -70,8 +111,12 @@ class Accounts extends ApiController
|
||||
*/
|
||||
public function destroy(Account $account)
|
||||
{
|
||||
$account->delete();
|
||||
try {
|
||||
$this->dispatch(new DeleteAccount($account));
|
||||
|
||||
return $this->response->noContent();
|
||||
return $this->response->noContent();
|
||||
} catch(\Exception $e) {
|
||||
$this->response->errorUnauthorized($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
81
app/Http/Controllers/Api/Banking/Reconciliations.php
Normal file
81
app/Http/Controllers/Api/Banking/Reconciliations.php
Normal file
@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Banking;
|
||||
|
||||
use App\Abstracts\Http\ApiController;
|
||||
use App\Http\Requests\Banking\Reconciliation as Request;
|
||||
use App\Jobs\Banking\CreateReconciliation;
|
||||
use App\Jobs\Banking\DeleteReconciliation;
|
||||
use App\Jobs\Banking\UpdateReconciliation;
|
||||
use App\Models\Banking\Reconciliation;
|
||||
use App\Transformers\Banking\Reconciliation as Transformer;
|
||||
|
||||
class Reconciliations extends ApiController
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$items = Reconciliation::with(['account'])->collect();
|
||||
|
||||
return $this->response->paginator($items, new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param $reconciliation
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function show(Reconciliation $reconciliation)
|
||||
{
|
||||
return $this->response->item($reconciliation, new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param $request
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$reconciliation = $this->dispatch(new CreateReconciliation($request));
|
||||
|
||||
return $this->response->created(url('api/reconciliations/' . $reconciliation->id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param $reconciliation
|
||||
* @param $request
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function update(Reconciliation $reconciliation, Request $request)
|
||||
{
|
||||
$reconciliation = $this->dispatch(new UpdateReconciliation($reconciliation, $request));
|
||||
|
||||
return $this->item($reconciliation->fresh(), new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param Reconciliation $reconciliation
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function destroy(Reconciliation $reconciliation)
|
||||
{
|
||||
try {
|
||||
$this->dispatch(new DeleteReconciliation($reconciliation));
|
||||
|
||||
return $this->response->noContent();
|
||||
} catch(\Exception $e) {
|
||||
$this->response->errorUnauthorized($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
81
app/Http/Controllers/Api/Banking/Transactions.php
Normal file
81
app/Http/Controllers/Api/Banking/Transactions.php
Normal file
@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Banking;
|
||||
|
||||
use App\Abstracts\Http\ApiController;
|
||||
use App\Http\Requests\Banking\Transaction as Request;
|
||||
use App\Jobs\Banking\CreateTransaction;
|
||||
use App\Jobs\Banking\DeleteTransaction;
|
||||
use App\Jobs\Banking\UpdateTransaction;
|
||||
use App\Models\Banking\Transaction;
|
||||
use App\Transformers\Banking\Transaction as Transformer;
|
||||
|
||||
class Transactions extends ApiController
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$transactions = Transaction::with(['account', 'category', 'contact'])->collect(['paid_at'=> 'desc']);
|
||||
|
||||
return $this->response->paginator($transactions, new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param Transaction $transaction
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function show(Transaction $transaction)
|
||||
{
|
||||
return $this->response->item($transaction, new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param $request
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$transaction = $this->dispatch(new CreateTransaction($request));
|
||||
|
||||
return $this->response->created(url('api/transactions/' . $transaction->id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param $transaction
|
||||
* @param $request
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function update(Transaction $transaction, Request $request)
|
||||
{
|
||||
$transaction = $this->dispatch(new UpdateTransaction($transaction, $request));
|
||||
|
||||
return $this->item($transaction->fresh(), new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param Transaction $transaction
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function destroy(Transaction $transaction)
|
||||
{
|
||||
try {
|
||||
$this->dispatch(new DeleteTransaction($transaction));
|
||||
|
||||
return $this->response->noContent();
|
||||
} catch(\Exception $e) {
|
||||
$this->response->errorUnauthorized($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
@ -2,18 +2,16 @@
|
||||
|
||||
namespace App\Http\Controllers\Api\Banking;
|
||||
|
||||
use App\Http\Controllers\ApiController;
|
||||
use App\Abstracts\Http\ApiController;
|
||||
use App\Http\Requests\Banking\Transfer as Request;
|
||||
use App\Jobs\Banking\CreateTransfer;
|
||||
use App\Jobs\Banking\UpdateTransfer;
|
||||
use App\Jobs\Banking\DeleteTransfer;
|
||||
use App\Models\Banking\Transfer;
|
||||
use App\Models\Expense\Payment;
|
||||
use App\Models\Income\Revenue;
|
||||
use App\Transformers\Banking\Transfer as Transformer;
|
||||
use Dingo\Api\Routing\Helpers;
|
||||
|
||||
class Transfers extends ApiController
|
||||
{
|
||||
use Helpers;
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
@ -21,7 +19,37 @@ class Transfers extends ApiController
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$transfers = Transfer::with(['payment', 'revenue'])->collect('payment.paid_at');
|
||||
$transfers = Transfer::with([
|
||||
'expense_transaction', 'expense_transaction.account', 'income_transaction', 'income_transaction.account'
|
||||
])->collect('expense_transaction.paid_at');
|
||||
|
||||
$special_key = [
|
||||
'expense_transaction.name' => 'from_account',
|
||||
'income_transaction.name' => 'to_account',
|
||||
];
|
||||
|
||||
$request = request();
|
||||
if (isset($request['sort']) && array_key_exists($request['sort'], $special_key)) {
|
||||
$items = $transfers->items();
|
||||
|
||||
$sort_order = [];
|
||||
|
||||
foreach ($items as $key => $value) {
|
||||
$sort = $request['sort'];
|
||||
|
||||
if (array_key_exists($request['sort'], $special_key)) {
|
||||
$sort = $special_key[$request['sort']];
|
||||
}
|
||||
|
||||
$sort_order[$key] = $value->{$sort};
|
||||
}
|
||||
|
||||
$sort_type = (isset($request['order']) && $request['order'] == 'asc') ? SORT_ASC : SORT_DESC;
|
||||
|
||||
array_multisort($sort_order, $sort_type, $items);
|
||||
|
||||
$transfers->setCollection(collect($items));
|
||||
}
|
||||
|
||||
return $this->response->paginator($transfers, new Transformer());
|
||||
}
|
||||
@ -45,9 +73,9 @@ class Transfers extends ApiController
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$transfer = Transfer::create($request->all());
|
||||
$transfer = $this->dispatch(new CreateTransfer($request));
|
||||
|
||||
return $this->response->created(url('api/transfers/'.$transfer->id));
|
||||
return $this->response->created(url('api/transfers/' . $transfer->id));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -59,9 +87,9 @@ class Transfers extends ApiController
|
||||
*/
|
||||
public function update(Transfer $transfer, Request $request)
|
||||
{
|
||||
$transfer->update($request->all());
|
||||
$transfer = $this->dispatch(new UpdateTransfer($transfer, $request));
|
||||
|
||||
return $this->response->item($transfer->fresh(), new Transformer());
|
||||
return $this->item($transfer->fresh(), new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -72,13 +100,12 @@ class Transfers extends ApiController
|
||||
*/
|
||||
public function destroy(Transfer $transfer)
|
||||
{
|
||||
$payment = Payment::findOrFail($transfer['payment_id']);
|
||||
$revenue = Revenue::findOrFail($transfer['revenue_id']);
|
||||
try {
|
||||
$this->dispatch(new DeleteTransfer($transfer));
|
||||
|
||||
$transfer->delete();
|
||||
$payment->delete();
|
||||
$revenue->delete();
|
||||
|
||||
return $this->response->noContent();
|
||||
return $this->response->noContent();
|
||||
} catch(\Exception $e) {
|
||||
$this->response->errorUnauthorized($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,15 +2,19 @@
|
||||
|
||||
namespace App\Http\Controllers\Api\Common;
|
||||
|
||||
use App\Http\Controllers\ApiController;
|
||||
use App\Abstracts\Http\ApiController;
|
||||
use App\Http\Requests\Common\Company as Request;
|
||||
use App\Jobs\Common\CreateCompany;
|
||||
use App\Jobs\Common\DeleteCompany;
|
||||
use App\Jobs\Common\UpdateCompany;
|
||||
use App\Models\Common\Company;
|
||||
use App\Transformers\Common\Company as Transformer;
|
||||
use Dingo\Api\Routing\Helpers;
|
||||
use App\Traits\Users;
|
||||
use Dingo\Api\Http\Response;
|
||||
|
||||
class Companies extends ApiController
|
||||
{
|
||||
use Helpers;
|
||||
use Users;
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
@ -19,13 +23,9 @@ class Companies extends ApiController
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$companies = app('Dingo\Api\Auth\Auth')->user()->companies()->get()->sortBy('name');
|
||||
$companies = user()->companies()->collect();
|
||||
|
||||
foreach ($companies as $company) {
|
||||
$company->setSettings();
|
||||
}
|
||||
|
||||
return $this->response->collection($companies, new Transformer());
|
||||
return $this->response->paginator($companies, new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -36,15 +36,14 @@ class Companies extends ApiController
|
||||
*/
|
||||
public function show(Company $company)
|
||||
{
|
||||
// Check if user can access company
|
||||
$companies = app('Dingo\Api\Auth\Auth')->user()->companies()->pluck('id')->toArray();
|
||||
if (!in_array($company->id, $companies)) {
|
||||
$this->response->errorUnauthorized();
|
||||
try {
|
||||
// Check if user can access company
|
||||
$this->owner($company);
|
||||
|
||||
return $this->response->item($company, new Transformer());
|
||||
} catch (\HttpException $e) {
|
||||
$this->response->errorUnauthorized($e->getMessage());
|
||||
}
|
||||
|
||||
$company->setSettings();
|
||||
|
||||
return $this->response->item($company, new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -55,22 +54,7 @@ class Companies extends ApiController
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$company = Company::create($request->all());
|
||||
|
||||
// Clear settings
|
||||
setting()->forgetAll();
|
||||
setting()->setExtraColumns(['company_id' => $company->id]);
|
||||
|
||||
// Create settings
|
||||
setting()->set([
|
||||
'general.company_name' => $request->get('company_name'),
|
||||
'general.company_email' => $request->get('company_email'),
|
||||
'general.company_address' => $request->get('company_address'),
|
||||
'general.default_currency' => $request->get('default_currency'),
|
||||
'general.default_locale' => $request->get('default_locale', 'en-GB'),
|
||||
]);
|
||||
|
||||
setting()->save();
|
||||
$company = $this->dispatch(new CreateCompany($request));
|
||||
|
||||
return $this->response->created(url('api/companies/' . $company->id));
|
||||
}
|
||||
@ -84,31 +68,47 @@ class Companies extends ApiController
|
||||
*/
|
||||
public function update(Company $company, Request $request)
|
||||
{
|
||||
// Check if user can access company
|
||||
$companies = app('Dingo\Api\Auth\Auth')->user()->companies()->pluck('id')->toArray();
|
||||
if (!in_array($company->id, $companies)) {
|
||||
$this->response->errorUnauthorized();
|
||||
try {
|
||||
$company = $this->dispatch(new UpdateCompany($company, $request));
|
||||
|
||||
return $this->item($company->fresh(), new Transformer());
|
||||
} catch (\Exception $e) {
|
||||
$this->response->errorUnauthorized($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// Update company
|
||||
$company->update(['domain' => $request->get('domain')]);
|
||||
/**
|
||||
* Enable the specified resource in storage.
|
||||
*
|
||||
* @param Company $company
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function enable(Company $company)
|
||||
{
|
||||
try {
|
||||
$company = $this->dispatch(new UpdateCompany($company, request()->merge(['enabled' => 1])));
|
||||
|
||||
// Update settings
|
||||
setting()->forgetAll();
|
||||
setting()->setExtraColumns(['company_id' => $company->id]);
|
||||
setting()->load(true);
|
||||
return $this->item($company->fresh(), new Transformer());
|
||||
} catch (\Exception $e) {
|
||||
$this->response->errorUnauthorized($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
setting()->set([
|
||||
'general.company_name' => $request->get('company_name'),
|
||||
'general.company_email' => $request->get('company_email'),
|
||||
'general.company_address' => $request->get('company_address'),
|
||||
'general.default_currency' => $request->get('default_currency'),
|
||||
'general.default_locale' => $request->get('default_locale', 'en-GB'),
|
||||
]);
|
||||
/**
|
||||
* Disable the specified resource in storage.
|
||||
*
|
||||
* @param Company $company
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function disable(Company $company)
|
||||
{
|
||||
try {
|
||||
$company = $this->dispatch(new UpdateCompany($company, request()->merge(['enabled' => 0])));
|
||||
|
||||
setting()->save();
|
||||
|
||||
return $this->response->item($company->fresh(), new Transformer());
|
||||
return $this->item($company->fresh(), new Transformer());
|
||||
} catch (\Exception $e) {
|
||||
$this->response->errorUnauthorized($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -119,14 +119,30 @@ class Companies extends ApiController
|
||||
*/
|
||||
public function destroy(Company $company)
|
||||
{
|
||||
// Check if user can access company
|
||||
$companies = app('Dingo\Api\Auth\Auth')->user()->companies()->pluck('id')->toArray();
|
||||
if (!in_array($company->id, $companies)) {
|
||||
$this->response->errorUnauthorized();
|
||||
try {
|
||||
$this->dispatch(new DeleteCompany($company));
|
||||
|
||||
return $this->response->noContent();
|
||||
} catch (\Exception $e) {
|
||||
$this->response->errorUnauthorized($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check user company assignment
|
||||
*
|
||||
* @param Company $company
|
||||
*
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function owner(Company $company)
|
||||
{
|
||||
if ($this->isUserCompany($company->id)) {
|
||||
return new Response('');
|
||||
}
|
||||
|
||||
$company->delete();
|
||||
$message = trans('companies.error.not_user_company');
|
||||
|
||||
return $this->response->noContent();
|
||||
$this->response->errorUnauthorized($message);
|
||||
}
|
||||
}
|
||||
|
133
app/Http/Controllers/Api/Common/Contacts.php
Normal file
133
app/Http/Controllers/Api/Common/Contacts.php
Normal file
@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Common;
|
||||
|
||||
use App\Abstracts\Http\ApiController;
|
||||
use App\Http\Requests\Common\Contact as Request;
|
||||
use App\Jobs\Common\CreateContact;
|
||||
use App\Jobs\Common\DeleteContact;
|
||||
use App\Jobs\Common\UpdateContact;
|
||||
use App\Models\Common\Contact;
|
||||
use App\Traits\Uploads;
|
||||
use App\Transformers\Common\Contact as Transformer;
|
||||
|
||||
class Contacts extends ApiController
|
||||
{
|
||||
use Uploads;
|
||||
|
||||
/**
|
||||
* Instantiate a new controller instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// Add CRUD permission check
|
||||
$this->middleware('permission:create-incomes-customers')->only(['create', 'store', 'duplicate', 'import']);
|
||||
$this->middleware('permission:read-incomes-customers')->only(['index', 'show', 'edit', 'export']);
|
||||
$this->middleware('permission:update-incomes-customers')->only(['update', 'enable', 'disable']);
|
||||
$this->middleware('permission:delete-incomes-customers')->only('destroy');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$contacts = Contact::collect();
|
||||
|
||||
return $this->response->paginator($contacts, new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int|string $id
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
// Check if we're querying by id or email
|
||||
if (is_numeric($id)) {
|
||||
$contact = Contact::find($id);
|
||||
} else {
|
||||
$contact = Contact::where('email', $id)->first();
|
||||
}
|
||||
|
||||
return $this->response->item($contact, new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param $request
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$contact = $this->dispatch(new CreateContact($request));
|
||||
|
||||
return $this->response->created(url('api/contacts/' . $contact->id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param $contact
|
||||
* @param $request
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function update(Contact $contact, Request $request)
|
||||
{
|
||||
$contact = $this->dispatch(new UpdateContact($contact, $request));
|
||||
|
||||
return $this->item($contact->fresh(), new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable the specified resource in storage.
|
||||
*
|
||||
* @param Contact $contact
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function enable(Contact $contact)
|
||||
{
|
||||
$contact = $this->dispatch(new UpdateContact($contact, request()->merge(['enabled' => 1])));
|
||||
|
||||
return $this->item($contact->fresh(), new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable the specified resource in storage.
|
||||
*
|
||||
* @param Contact $contact
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function disable(Contact $contact)
|
||||
{
|
||||
try {
|
||||
$contact = $this->dispatch(new UpdateContact($contact, request()->merge(['enabled' => 0])));
|
||||
|
||||
return $this->item($contact->fresh(), new Transformer());
|
||||
} catch(\Exception $e) {
|
||||
$this->response->errorUnauthorized($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param Contact $contact
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function destroy(Contact $contact)
|
||||
{
|
||||
try {
|
||||
$this->dispatch(new DeleteContact($contact));
|
||||
|
||||
return $this->response->noContent();
|
||||
} catch(\Exception $e) {
|
||||
$this->response->errorUnauthorized($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
@ -2,15 +2,18 @@
|
||||
|
||||
namespace App\Http\Controllers\Api\Common;
|
||||
|
||||
use App\Http\Controllers\ApiController;
|
||||
use App\Abstracts\Http\ApiController;
|
||||
use App\Http\Requests\Common\Item as Request;
|
||||
use App\Jobs\Common\CreateItem;
|
||||
use App\Jobs\Common\DeleteItem;
|
||||
use App\Jobs\Common\UpdateItem;
|
||||
use App\Models\Common\Item;
|
||||
use App\Transformers\Common\Item as Transformer;
|
||||
use Dingo\Api\Routing\Helpers;
|
||||
use App\Traits\Uploads;
|
||||
|
||||
class Items extends ApiController
|
||||
{
|
||||
use Helpers;
|
||||
use Uploads;
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
@ -32,12 +35,7 @@ class Items extends ApiController
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
// Check if we're querying by id or sku
|
||||
if (is_numeric($id)) {
|
||||
$item = Item::with(['category', 'tax'])->find($id);
|
||||
} else {
|
||||
$item = Item::with(['category', 'tax'])->where('sku', $id)->first();
|
||||
}
|
||||
$item = Item::with(['category', 'tax'])->find($id);
|
||||
|
||||
return $this->response->item($item, new Transformer());
|
||||
}
|
||||
@ -50,9 +48,9 @@ class Items extends ApiController
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$item = Item::create($request->all());
|
||||
$item = $this->dispatch(new CreateItem($request));
|
||||
|
||||
return $this->response->created(url('api/items/'.$item->id));
|
||||
return $this->response->created(url('api/items/' . $item->id));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -64,9 +62,35 @@ class Items extends ApiController
|
||||
*/
|
||||
public function update(Item $item, Request $request)
|
||||
{
|
||||
$item->update($request->all());
|
||||
$item = $this->dispatch(new UpdateItem($item, $request));
|
||||
|
||||
return $this->response->item($item->fresh(), new Transformer());
|
||||
return $this->item($item->fresh(), new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable the specified resource in storage.
|
||||
*
|
||||
* @param Item $item
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function enable(Item $item)
|
||||
{
|
||||
$item = $this->dispatch(new UpdateItem($item, request()->merge(['enabled' => 1])));
|
||||
|
||||
return $this->item($item->fresh(), new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable the specified resource in storage.
|
||||
*
|
||||
* @param Item $item
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function disable(Item $item)
|
||||
{
|
||||
$item = $this->dispatch(new UpdateItem($item, request()->merge(['enabled' => 0])));
|
||||
|
||||
return $this->item($item->fresh(), new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -77,8 +101,12 @@ class Items extends ApiController
|
||||
*/
|
||||
public function destroy(Item $item)
|
||||
{
|
||||
$item->delete();
|
||||
try {
|
||||
$this->dispatch(new DeleteItem($item));
|
||||
|
||||
return $this->response->noContent();
|
||||
return $this->response->noContent();
|
||||
} catch(\Exception $e) {
|
||||
$this->response->errorUnauthorized($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\Api\Common;
|
||||
|
||||
use App\Http\Controllers\ApiController;
|
||||
use App\Abstracts\Http\ApiController;
|
||||
use Date;
|
||||
use Dingo\Api\Routing\Helpers;
|
||||
|
||||
|
107
app/Http/Controllers/Api/Common/Reports.php
Normal file
107
app/Http/Controllers/Api/Common/Reports.php
Normal file
@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Common;
|
||||
|
||||
use App\Abstracts\Http\ApiController;
|
||||
use App\Http\Requests\Common\Report as Request;
|
||||
use App\Jobs\Common\CreateReport;
|
||||
use App\Jobs\Common\DeleteReport;
|
||||
use App\Jobs\Common\UpdateReport;
|
||||
use App\Models\Common\Report;
|
||||
use App\Transformers\Common\Report as Transformer;
|
||||
|
||||
class Reports extends ApiController
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$reports = Report::collect();
|
||||
|
||||
return $this->response->paginator($reports, new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param Report $report
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function show(Report $report)
|
||||
{
|
||||
return $this->response->item($report, new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param $request
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$report = $this->dispatch(new CreateReport($request));
|
||||
|
||||
return $this->response->created(url('api/reports/' . $report->id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param $report
|
||||
* @param $request
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function update(Report $report, Request $request)
|
||||
{
|
||||
$report = $this->dispatch(new UpdateReport($report, $request));
|
||||
|
||||
return $this->item($report->fresh(), new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable the specified resource in storage.
|
||||
*
|
||||
* @param Report $report
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function enable(Report $report)
|
||||
{
|
||||
$report = $this->dispatch(new UpdateReport($report, request()->merge(['enabled' => 1])));
|
||||
|
||||
return $this->item($report->fresh(), new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable the specified resource in storage.
|
||||
*
|
||||
* @param Report $report
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function disable(Report $report)
|
||||
{
|
||||
$report = $this->dispatch(new UpdateReport($report, request()->merge(['enabled' => 0])));
|
||||
|
||||
return $this->item($report->fresh(), new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param Report $report
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function destroy(Report $report)
|
||||
{
|
||||
try {
|
||||
$this->dispatch(new DeleteReport($report));
|
||||
|
||||
return $this->response->noContent();
|
||||
} catch(\Exception $e) {
|
||||
$this->response->errorUnauthorized($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
@ -2,24 +2,16 @@
|
||||
|
||||
namespace App\Http\Controllers\Api\Expenses;
|
||||
|
||||
use App\Events\BillCreated;
|
||||
use App\Events\BillUpdated;
|
||||
use App\Http\Controllers\ApiController;
|
||||
use App\Abstracts\Http\ApiController;
|
||||
use App\Http\Requests\Expense\Bill as Request;
|
||||
use App\Jobs\Expense\CreateBill;
|
||||
use App\Jobs\Expense\DeleteBill;
|
||||
use App\Jobs\Expense\UpdateBill;
|
||||
use App\Models\Expense\Bill;
|
||||
use App\Models\Expense\BillHistory;
|
||||
use App\Models\Expense\BillItem;
|
||||
use App\Models\Expense\BillPayment;
|
||||
use App\Models\Expense\BillStatus;
|
||||
use App\Models\Common\Item;
|
||||
use App\Models\Setting\Tax;
|
||||
use App\Transformers\Expense\Bill as Transformer;
|
||||
use Dingo\Api\Routing\Helpers;
|
||||
|
||||
class Bills extends ApiController
|
||||
{
|
||||
use Helpers;
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
@ -27,7 +19,7 @@ class Bills extends ApiController
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$bills = Bill::with(['vendor', 'status', 'items', 'payments', 'histories'])->collect();
|
||||
$bills = Bill::with(['contact', 'status', 'items', 'transactions', 'histories'])->collect(['billed_at'=> 'desc']);
|
||||
|
||||
return $this->response->paginator($bills, new Transformer());
|
||||
}
|
||||
@ -51,72 +43,9 @@ class Bills extends ApiController
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$bill = Bill::create($request->all());
|
||||
$bill = $this->dispatch(new CreateBill($request));
|
||||
|
||||
$bill_item = array();
|
||||
$bill_item['company_id'] = $request['company_id'];
|
||||
$bill_item['bill_id'] = $bill->id;
|
||||
|
||||
if ($request['item']) {
|
||||
foreach ($request['item'] as $item) {
|
||||
$item_id = 0;
|
||||
$item_sku = '';
|
||||
|
||||
if (!empty($item['item_id'])) {
|
||||
$item_object = Item::find($item['item_id']);
|
||||
|
||||
$item_id = $item['item_id'];
|
||||
|
||||
$item['name'] = $item_object->name;
|
||||
$item_sku = $item_object->sku;
|
||||
|
||||
// Increase stock (item bought)
|
||||
$item_object->quantity += $item['quantity'];
|
||||
$item_object->save();
|
||||
} elseif (!empty($item['sku'])) {
|
||||
$item_sku = $item['sku'];
|
||||
}
|
||||
|
||||
$tax = $tax_id = 0;
|
||||
|
||||
if (!empty($item['tax_id'])) {
|
||||
$tax_object = Tax::find($item['tax_id']);
|
||||
|
||||
$tax_id = $item['tax_id'];
|
||||
|
||||
$tax = (($item['price'] * $item['quantity']) / 100) * $tax_object->rate;
|
||||
} elseif (!empty($item['tax'])) {
|
||||
$tax = $item['tax'];
|
||||
}
|
||||
|
||||
$bill_item['item_id'] = $item_id;
|
||||
$bill_item['name'] = str_limit($item['name'], 180, '');
|
||||
$bill_item['sku'] = $item_sku;
|
||||
$bill_item['quantity'] = $item['quantity'];
|
||||
$bill_item['price'] = $item['price'];
|
||||
$bill_item['tax'] = $tax;
|
||||
$bill_item['tax_id'] = $tax_id;
|
||||
$bill_item['total'] = ($item['price'] + $bill_item['tax']) * $item['quantity'];
|
||||
|
||||
$request['amount'] += $bill_item['total'];
|
||||
|
||||
BillItem::create($bill_item);
|
||||
}
|
||||
}
|
||||
|
||||
$bill->update($request->input());
|
||||
|
||||
$request['bill_id'] = $bill->id;
|
||||
$request['status_code'] = $request['bill_status_code'];
|
||||
$request['notify'] = 0;
|
||||
$request['description'] = trans('messages.success.added', ['type' => $request['bill_number']]);
|
||||
|
||||
BillHistory::create($request->input());
|
||||
|
||||
// Fire the event to make it extendible
|
||||
event(new BillCreated($bill));
|
||||
|
||||
return $this->response->created(url('api/bills/'.$bill->id));
|
||||
return $this->response->created(url('api/bills/' . $bill->id));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -128,61 +57,9 @@ class Bills extends ApiController
|
||||
*/
|
||||
public function update(Bill $bill, Request $request)
|
||||
{
|
||||
$bill_item = array();
|
||||
$bill_item['company_id'] = $request['company_id'];
|
||||
$bill_item['bill_id'] = $bill->id;
|
||||
$bill = $this->dispatch(new UpdateBill($bill, $request));
|
||||
|
||||
if ($request['item']) {
|
||||
BillItem::where('bill_id', $bill->id)->delete();
|
||||
|
||||
foreach ($request['item'] as $item) {
|
||||
$item_id = 0;
|
||||
$item_sku = '';
|
||||
|
||||
if (!empty($item['item_id'])) {
|
||||
$item_object = Item::find($item['item_id']);
|
||||
|
||||
$item_id = $item['item_id'];
|
||||
|
||||
$item['name'] = $item_object->name;
|
||||
$item_sku = $item_object->sku;
|
||||
} elseif (!empty($item['sku'])) {
|
||||
$item_sku = $item['sku'];
|
||||
}
|
||||
|
||||
$tax = $tax_id = 0;
|
||||
|
||||
if (!empty($item['tax_id'])) {
|
||||
$tax_object = Tax::find($item['tax_id']);
|
||||
|
||||
$tax_id = $item['tax_id'];
|
||||
|
||||
$tax = (($item['price'] * $item['quantity']) / 100) * $tax_object->rate;
|
||||
} elseif (!empty($item['tax'])) {
|
||||
$tax = $item['tax'];
|
||||
}
|
||||
|
||||
$bill_item['item_id'] = $item_id;
|
||||
$bill_item['name'] = str_limit($item['name'], 180, '');
|
||||
$bill_item['sku'] = $item_sku;
|
||||
$bill_item['quantity'] = $item['quantity'];
|
||||
$bill_item['price'] = $item['price'];
|
||||
$bill_item['tax'] = $tax;
|
||||
$bill_item['tax_id'] = $tax_id;
|
||||
$bill_item['total'] = ($item['price'] + $bill_item['tax']) * $item['quantity'];
|
||||
|
||||
$request['amount'] += $bill_item['total'];
|
||||
|
||||
BillItem::create($bill_item);
|
||||
}
|
||||
}
|
||||
|
||||
$bill->update($request->input());
|
||||
|
||||
// Fire the event to make it extendible
|
||||
event(new BillUpdated($bill));
|
||||
|
||||
return $this->response->item($bill->fresh(), new Transformer());
|
||||
return $this->item($bill->fresh(), new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -193,12 +70,12 @@ class Bills extends ApiController
|
||||
*/
|
||||
public function destroy(Bill $bill)
|
||||
{
|
||||
$bill->delete();
|
||||
try {
|
||||
$this->dispatch(new DeleteBill($bill));
|
||||
|
||||
BillItem::where('bill_id', $bill->id)->delete();
|
||||
BillPayment::where('bill_id', $bill->id)->delete();
|
||||
BillHistory::where('bill_id', $bill->id)->delete();
|
||||
|
||||
return $this->response->noContent();
|
||||
return $this->response->noContent();
|
||||
} catch(\Exception $e) {
|
||||
$this->response->errorUnauthorized($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,77 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Expenses;
|
||||
|
||||
use App\Http\Controllers\ApiController;
|
||||
use App\Http\Requests\Expense\Payment as Request;
|
||||
use App\Models\Expense\Payment;
|
||||
use App\Transformers\Expense\Payment as Transformer;
|
||||
use Dingo\Api\Routing\Helpers;
|
||||
|
||||
class Payments extends ApiController
|
||||
{
|
||||
use Helpers;
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$payments = Payment::with(['account', 'vendor', 'category'])->collect();
|
||||
|
||||
return $this->response->paginator($payments, new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param Payment $payment
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function show(Payment $payment)
|
||||
{
|
||||
return $this->response->item($payment, new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param $request
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$payment = Payment::create($request->all());
|
||||
|
||||
return $this->response->created(url('api/payments/'.$payment->id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param $payment
|
||||
* @param $request
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function update(Payment $payment, Request $request)
|
||||
{
|
||||
$payment->update($request->all());
|
||||
|
||||
return $this->response->item($payment->fresh(), new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param Payment $payment
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function destroy(Payment $payment)
|
||||
{
|
||||
$payment->delete();
|
||||
|
||||
return $this->response->noContent();
|
||||
}
|
||||
}
|
@ -1,84 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Expenses;
|
||||
|
||||
use App\Http\Controllers\ApiController;
|
||||
use App\Http\Requests\Expense\Vendor as Request;
|
||||
use App\Models\Expense\Vendor;
|
||||
use App\Transformers\Expense\Vendor as Transformer;
|
||||
use Dingo\Api\Routing\Helpers;
|
||||
|
||||
class Vendors extends ApiController
|
||||
{
|
||||
use Helpers;
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$vendors = Vendor::collect();
|
||||
|
||||
return $this->response->paginator($vendors, new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int|string $id
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
// Check if we're querying by id or email
|
||||
if (is_numeric($id)) {
|
||||
$vendor = Vendor::find($id);
|
||||
} else {
|
||||
$vendor = Vendor::where('email', $id)->first();
|
||||
}
|
||||
|
||||
return $this->response->item($vendor, new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param $request
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$vendor = Vendor::create($request->all());
|
||||
|
||||
return $this->response->created(url('api/vendors/'.$vendor->id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param $vendor
|
||||
* @param $request
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function update(Vendor $vendor, Request $request)
|
||||
{
|
||||
$vendor->update($request->all());
|
||||
|
||||
return $this->response->item($vendor->fresh(), new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param Vendor $vendor
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function destroy(Vendor $vendor)
|
||||
{
|
||||
$vendor->delete();
|
||||
|
||||
return $this->response->noContent();
|
||||
}
|
||||
}
|
@ -1,84 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Incomes;
|
||||
|
||||
use App\Http\Controllers\ApiController;
|
||||
use App\Http\Requests\Income\Customer as Request;
|
||||
use App\Models\Income\Customer;
|
||||
use App\Transformers\Income\Customer as Transformer;
|
||||
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 int|string $id
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
// Check if we're querying by id or email
|
||||
if (is_numeric($id)) {
|
||||
$customer = Customer::find($id);
|
||||
} else {
|
||||
$customer = Customer::where('email', $id)->first();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
@ -1,126 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Incomes;
|
||||
|
||||
use App\Http\Requests\Income\InvoicePayment as Request;
|
||||
use App\Models\Income\Invoice;
|
||||
use App\Models\Income\InvoiceHistory;
|
||||
use App\Models\Income\InvoicePayment;
|
||||
use App\Models\Setting\Currency;
|
||||
use App\Traits\DateTime;
|
||||
use App\Transformers\Income\InvoicePayments as Transformer;
|
||||
use Date;
|
||||
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 InvoicePayments extends BaseController
|
||||
{
|
||||
use DateTime, Helpers, AuthorizesRequests, DispatchesJobs, ValidatesRequests;
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @param $invoice_id
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function index($invoice_id)
|
||||
{
|
||||
$invoice_payments = InvoicePayment::where('invoice_id', $invoice_id)->get();
|
||||
|
||||
return $this->response->collection($invoice_payments, new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param $invoice_id
|
||||
* @param $id
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function show($invoice_id, $id)
|
||||
{
|
||||
$invoice_payment = InvoicePayment::find($id);
|
||||
|
||||
return $this->response->item($invoice_payment, 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)
|
||||
{
|
||||
// Get currency object
|
||||
$currency = Currency::where('code', $request['currency_code'])->first();
|
||||
|
||||
$request['currency_code'] = $currency->code;
|
||||
$request['currency_rate'] = $currency->rate;
|
||||
|
||||
$request['invoice_id'] = $invoice_id;
|
||||
|
||||
$invoice = Invoice::find($invoice_id);
|
||||
|
||||
if ($request['currency_code'] == $invoice->currency_code) {
|
||||
if ($request['amount'] > $invoice->amount) {
|
||||
return $this->response->noContent();
|
||||
} elseif ($request['amount'] == $invoice->amount) {
|
||||
$invoice->invoice_status_code = 'paid';
|
||||
} else {
|
||||
$invoice->invoice_status_code = 'partial';
|
||||
}
|
||||
} else {
|
||||
$request_invoice = new Invoice();
|
||||
|
||||
$request_invoice->amount = (float) $request['amount'];
|
||||
$request_invoice->currency_code = $currency->code;
|
||||
$request_invoice->currency_rate = $currency->rate;
|
||||
|
||||
$amount = $request_invoice->getConvertedAmount();
|
||||
|
||||
if ($amount > $invoice->amount) {
|
||||
return $this->response->noContent();
|
||||
} elseif ($amount == $invoice->amount) {
|
||||
$invoice->invoice_status_code = 'paid';
|
||||
} else {
|
||||
$invoice->invoice_status_code = 'partial';
|
||||
}
|
||||
}
|
||||
|
||||
$invoice->save();
|
||||
|
||||
$invoice_payment = InvoicePayment::create($request->input());
|
||||
|
||||
$request['status_code'] = $invoice->invoice_status_code;
|
||||
$request['notify'] = 0;
|
||||
|
||||
$desc_date = Date::parse($request['paid_at'])->format($this->getCompanyDateFormat());
|
||||
$desc_amount = money((float) $request['amount'], $request['currency_code'], true)->format();
|
||||
$request['description'] = $desc_date . ' ' . $desc_amount;
|
||||
|
||||
InvoiceHistory::create($request->input());
|
||||
|
||||
return $this->response->created(url('api/invoices/' . $invoice_id . '/payments' . $invoice_payment->id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param $invoice_id
|
||||
* @param $id
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function destroy($invoice_id, $id)
|
||||
{
|
||||
$invoice_payment = InvoicePayment::find($id);
|
||||
|
||||
$invoice_payment->delete();
|
||||
|
||||
return $this->response->noContent();
|
||||
}
|
||||
}
|
79
app/Http/Controllers/Api/Incomes/InvoiceTransactions.php
Normal file
79
app/Http/Controllers/Api/Incomes/InvoiceTransactions.php
Normal file
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Incomes;
|
||||
|
||||
use App\Http\Requests\Banking\Transaction as Request;
|
||||
use App\Jobs\Banking\CreateDocumentTransaction;
|
||||
use App\Jobs\Banking\DeleteTransaction;
|
||||
use App\Models\Banking\Transaction;
|
||||
use App\Models\Income\Invoice;
|
||||
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 = Invoice::find($invoice_id);
|
||||
|
||||
$transaction = $this->dispatch(new CreateDocumentTransaction($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();
|
||||
}
|
||||
}
|
@ -2,25 +2,16 @@
|
||||
|
||||
namespace App\Http\Controllers\Api\Incomes;
|
||||
|
||||
use App\Events\InvoiceUpdated;
|
||||
use App\Http\Controllers\ApiController;
|
||||
use App\Abstracts\Http\ApiController;
|
||||
use App\Http\Requests\Income\Invoice as Request;
|
||||
use App\Jobs\Income\CreateInvoice;
|
||||
use App\Jobs\Income\DeleteInvoice;
|
||||
use App\Jobs\Income\UpdateInvoice;
|
||||
use App\Models\Income\Invoice;
|
||||
use App\Models\Income\InvoiceHistory;
|
||||
use App\Models\Income\InvoiceItem;
|
||||
use App\Models\Income\InvoicePayment;
|
||||
use App\Models\Income\InvoiceTotal;
|
||||
use App\Models\Common\Item;
|
||||
use App\Models\Setting\Tax;
|
||||
use App\Traits\Incomes;
|
||||
use App\Transformers\Income\Invoice as Transformer;
|
||||
use Dingo\Api\Routing\Helpers;
|
||||
|
||||
class Invoices extends ApiController
|
||||
{
|
||||
use Helpers, Incomes;
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
@ -28,7 +19,7 @@ class Invoices extends ApiController
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$invoices = Invoice::with(['customer', 'status', 'items', 'payments', 'histories'])->collect();
|
||||
$invoices = Invoice::with(['contact', 'status', 'items', 'transactions', 'histories'])->collect(['invoiced_at'=> 'desc']);
|
||||
|
||||
return $this->response->paginator($invoices, new Transformer());
|
||||
}
|
||||
@ -59,11 +50,7 @@ class Invoices extends ApiController
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
if (empty($request['amount'])) {
|
||||
$request['amount'] = 0;
|
||||
}
|
||||
|
||||
$invoice = dispatch(new CreateInvoice($request));
|
||||
$invoice = $this->dispatch(new CreateInvoice($request));
|
||||
|
||||
return $this->response->created(url('api/invoices/' . $invoice->id));
|
||||
}
|
||||
@ -77,89 +64,7 @@ class Invoices extends ApiController
|
||||
*/
|
||||
public function update(Invoice $invoice, Request $request)
|
||||
{
|
||||
$taxes = [];
|
||||
$tax_total = 0;
|
||||
$sub_total = 0;
|
||||
|
||||
$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_id = 0;
|
||||
$item_sku = '';
|
||||
|
||||
if (!empty($item['item_id'])) {
|
||||
$item_object = Item::find($item['item_id']);
|
||||
|
||||
$item_id = $item['item_id'];
|
||||
|
||||
$item['name'] = $item_object->name;
|
||||
$item_sku = $item_object->sku;
|
||||
} elseif (!empty($item['sku'])) {
|
||||
$item_sku = $item['sku'];
|
||||
}
|
||||
|
||||
$tax = $tax_id = 0;
|
||||
|
||||
if (!empty($item['tax_id'])) {
|
||||
$tax_object = Tax::find($item['tax_id']);
|
||||
|
||||
$tax_id = $item['tax_id'];
|
||||
|
||||
$tax = (($item['price'] * $item['quantity']) / 100) * $tax_object->rate;
|
||||
} elseif (!empty($item['tax'])) {
|
||||
$tax = $item['tax'];
|
||||
}
|
||||
|
||||
$invoice_item['item_id'] = $item_id;
|
||||
$invoice_item['name'] = str_limit($item['name'], 180, '');
|
||||
$invoice_item['sku'] = $item_sku;
|
||||
$invoice_item['quantity'] = $item['quantity'];
|
||||
$invoice_item['price'] = $item['price'];
|
||||
$invoice_item['tax'] = $tax;
|
||||
$invoice_item['tax_id'] = $tax_id;
|
||||
$invoice_item['total'] = $item['price'] * $item['quantity'];
|
||||
|
||||
$request['amount'] += $invoice_item['total'];
|
||||
|
||||
InvoiceItem::create($invoice_item);
|
||||
|
||||
if (isset($tax_object)) {
|
||||
if (array_key_exists($tax_object->id, $taxes)) {
|
||||
$taxes[$tax_object->id]['amount'] += $tax;
|
||||
} else {
|
||||
$taxes[$tax_object->id] = [
|
||||
'name' => $tax_object->name,
|
||||
'amount' => $tax
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$tax_total += $tax;
|
||||
$sub_total += $invoice_item['total'];
|
||||
|
||||
unset($item_object);
|
||||
unset($tax_object);
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($request['amount'])) {
|
||||
$request['amount'] = $sub_total + $tax_total;
|
||||
}
|
||||
|
||||
$invoice->update($request->input());
|
||||
|
||||
// Delete previous invoice totals
|
||||
InvoiceTotal::where('invoice_id', $invoice->id)->delete();
|
||||
|
||||
$this->addTotals($invoice, $request, $taxes, $sub_total, $tax_total);
|
||||
|
||||
// Fire the event to make it extendible
|
||||
event(new InvoiceUpdated($invoice));
|
||||
$invoice = $this->dispatch(new UpdateInvoice($invoice, $request));
|
||||
|
||||
return $this->response->item($invoice->fresh(), new Transformer());
|
||||
}
|
||||
@ -172,81 +77,12 @@ class Invoices extends ApiController
|
||||
*/
|
||||
public function destroy(Invoice $invoice)
|
||||
{
|
||||
$this->deleteRelationships($invoice, ['items', 'histories', 'payments', 'recurring', 'totals']);
|
||||
$invoice->delete();
|
||||
try {
|
||||
$this->dispatch(new DeleteInvoice($invoice));
|
||||
|
||||
return $this->response->noContent();
|
||||
}
|
||||
|
||||
protected function addTotals($invoice, $request, $taxes, $sub_total, $tax_total) {
|
||||
// Add invoice total taxes
|
||||
if ($request['totals']) {
|
||||
$sort_order = 1;
|
||||
|
||||
foreach ($request['totals'] as $total) {
|
||||
if (!empty($total['sort_order'])) {
|
||||
$sort_order = $total['sort_order'];
|
||||
}
|
||||
|
||||
$invoice_total = [
|
||||
'company_id' => $request['company_id'],
|
||||
'invoice_id' => $invoice->id,
|
||||
'code' => $total['code'],
|
||||
'name' => $total['name'],
|
||||
'amount' => $total['amount'],
|
||||
'sort_order' => $sort_order,
|
||||
];
|
||||
|
||||
InvoiceTotal::create($invoice_total);
|
||||
|
||||
if (empty($total['sort_order'])) {
|
||||
$sort_order++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Added invoice total sub total
|
||||
$invoice_sub_total = [
|
||||
'company_id' => $request['company_id'],
|
||||
'invoice_id' => $invoice->id,
|
||||
'code' => 'sub_total',
|
||||
'name' => 'invoices.sub_total',
|
||||
'amount' => $sub_total,
|
||||
'sort_order' => 1,
|
||||
];
|
||||
|
||||
InvoiceTotal::create($invoice_sub_total);
|
||||
|
||||
$sort_order = 2;
|
||||
|
||||
// Added invoice total taxes
|
||||
if ($taxes) {
|
||||
foreach ($taxes as $tax) {
|
||||
$invoice_tax_total = [
|
||||
'company_id' => $request['company_id'],
|
||||
'invoice_id' => $invoice->id,
|
||||
'code' => 'tax',
|
||||
'name' => $tax['name'],
|
||||
'amount' => $tax['amount'],
|
||||
'sort_order' => $sort_order,
|
||||
];
|
||||
|
||||
InvoiceTotal::create($invoice_tax_total);
|
||||
|
||||
$sort_order++;
|
||||
}
|
||||
}
|
||||
|
||||
// Added invoice total total
|
||||
$invoice_total = [
|
||||
'company_id' => $request['company_id'],
|
||||
'invoice_id' => $invoice->id,
|
||||
'code' => 'total',
|
||||
'name' => 'invoices.total',
|
||||
'amount' => $sub_total + $tax_total,
|
||||
'sort_order' => $sort_order,
|
||||
];
|
||||
|
||||
InvoiceTotal::create($invoice_total);
|
||||
return $this->response->noContent();
|
||||
} catch(\Exception $e) {
|
||||
$this->response->errorUnauthorized($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,77 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Incomes;
|
||||
|
||||
use App\Http\Controllers\ApiController;
|
||||
use App\Http\Requests\Income\Revenue as Request;
|
||||
use App\Models\Income\Revenue;
|
||||
use App\Transformers\Income\Revenue as Transformer;
|
||||
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();
|
||||
}
|
||||
}
|
@ -2,16 +2,16 @@
|
||||
|
||||
namespace App\Http\Controllers\Api\Settings;
|
||||
|
||||
use App\Http\Controllers\ApiController;
|
||||
use App\Abstracts\Http\ApiController;
|
||||
use App\Http\Requests\Setting\Category as Request;
|
||||
use App\Jobs\Setting\CreateCategory;
|
||||
use App\Jobs\Setting\DeleteCategory;
|
||||
use App\Jobs\Setting\UpdateCategory;
|
||||
use App\Models\Setting\Category;
|
||||
use App\Transformers\Setting\Category as Transformer;
|
||||
use Dingo\Api\Routing\Helpers;
|
||||
|
||||
class Categories extends ApiController
|
||||
{
|
||||
use Helpers;
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
@ -43,9 +43,9 @@ class Categories extends ApiController
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$category = Category::create($request->all());
|
||||
$category = $this->dispatch(new CreateCategory($request));
|
||||
|
||||
return $this->response->created(url('api/categories/'.$category->id));
|
||||
return $this->response->created(url('api/categories/' . $category->id));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -57,9 +57,43 @@ class Categories extends ApiController
|
||||
*/
|
||||
public function update(Category $category, Request $request)
|
||||
{
|
||||
$category->update($request->all());
|
||||
try {
|
||||
$category = $this->dispatch(new UpdateCategory($category, $request));
|
||||
|
||||
return $this->response->item($category->fresh(), new Transformer());
|
||||
return $this->item($category->fresh(), new Transformer());
|
||||
} catch(\Exception $e) {
|
||||
$this->response->errorUnauthorized($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable the specified resource in storage.
|
||||
*
|
||||
* @param Category $category
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function enable(Category $category)
|
||||
{
|
||||
$category = $this->dispatch(new UpdateCategory($category, request()->merge(['enabled' => 1])));
|
||||
|
||||
return $this->item($category->fresh(), new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable the specified resource in storage.
|
||||
*
|
||||
* @param Category $category
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function disable(Category $category)
|
||||
{
|
||||
try {
|
||||
$category = $this->dispatch(new UpdateCategory($category, request()->merge(['enabled' => 0])));
|
||||
|
||||
return $this->item($category->fresh(), new Transformer());
|
||||
} catch(\Exception $e) {
|
||||
$this->response->errorUnauthorized($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -70,8 +104,12 @@ class Categories extends ApiController
|
||||
*/
|
||||
public function destroy(Category $category)
|
||||
{
|
||||
$category->delete();
|
||||
try {
|
||||
$this->dispatch(new DeleteCategory($category));
|
||||
|
||||
return $this->response->noContent();
|
||||
return $this->response->noContent();
|
||||
} catch(\Exception $e) {
|
||||
$this->response->errorUnauthorized($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,16 +2,16 @@
|
||||
|
||||
namespace App\Http\Controllers\Api\Settings;
|
||||
|
||||
use App\Http\Controllers\ApiController;
|
||||
use App\Abstracts\Http\ApiController;
|
||||
use App\Http\Requests\Setting\Currency as Request;
|
||||
use App\Jobs\Setting\CreateCurrency;
|
||||
use App\Jobs\Setting\DeleteCurrency;
|
||||
use App\Jobs\Setting\UpdateCurrency;
|
||||
use App\Models\Setting\Currency;
|
||||
use App\Transformers\Setting\Currency as Transformer;
|
||||
use Dingo\Api\Routing\Helpers;
|
||||
|
||||
class Currencies extends ApiController
|
||||
{
|
||||
use Helpers;
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
@ -27,11 +27,18 @@ class Currencies extends ApiController
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param Currency $currency
|
||||
* @param int|string $id
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function show(Currency $currency)
|
||||
public function show($id)
|
||||
{
|
||||
// Check if we're querying by id or code
|
||||
if (is_numeric($id)) {
|
||||
$currency = Currency::find($id);
|
||||
} else {
|
||||
$currency = Currency::where('code', $id)->first();
|
||||
}
|
||||
|
||||
return $this->response->item($currency, new Transformer());
|
||||
}
|
||||
|
||||
@ -43,9 +50,9 @@ class Currencies extends ApiController
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$currency = Currency::create($request->all());
|
||||
$currency = $this->dispatch(new CreateCurrency($request));
|
||||
|
||||
return $this->response->created(url('api/currencies/'.$currency->id));
|
||||
return $this->response->created(url('api/currencies/' . $currency->id));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -57,9 +64,43 @@ class Currencies extends ApiController
|
||||
*/
|
||||
public function update(Currency $currency, Request $request)
|
||||
{
|
||||
$currency->update($request->all());
|
||||
try {
|
||||
$currency = $this->dispatch(new UpdateCurrency($currency, $request));
|
||||
|
||||
return $this->response->item($currency->fresh(), new Transformer());
|
||||
return $this->item($currency->fresh(), new Transformer());
|
||||
} catch(\Exception $e) {
|
||||
$this->response->errorUnauthorized($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable the specified resource in storage.
|
||||
*
|
||||
* @param Currency $currency
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function enable(Currency $currency)
|
||||
{
|
||||
$currency = $this->dispatch(new UpdateCurrency($currency, request()->merge(['enabled' => 1])));
|
||||
|
||||
return $this->item($currency->fresh(), new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable the specified resource in storage.
|
||||
*
|
||||
* @param Currency $currency
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function disable(Currency $currency)
|
||||
{
|
||||
try {
|
||||
$currency = $this->dispatch(new UpdateCurrency($currency, request()->merge(['enabled' => 0])));
|
||||
|
||||
return $this->item($currency->fresh(), new Transformer());
|
||||
} catch(\Exception $e) {
|
||||
$this->response->errorUnauthorized($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -70,8 +111,12 @@ class Currencies extends ApiController
|
||||
*/
|
||||
public function destroy(Currency $currency)
|
||||
{
|
||||
$currency->delete();
|
||||
try {
|
||||
$this->dispatch(new DeleteCurrency($currency));
|
||||
|
||||
return $this->response->noContent();
|
||||
return $this->response->noContent();
|
||||
} catch(\Exception $e) {
|
||||
$this->response->errorUnauthorized($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\Api\Settings;
|
||||
|
||||
use App\Http\Controllers\ApiController;
|
||||
use App\Abstracts\Http\ApiController;
|
||||
use App\Http\Requests\Setting\Setting as Request;
|
||||
use App\Models\Setting\Setting;
|
||||
use App\Transformers\Setting\Setting as Transformer;
|
||||
|
@ -2,16 +2,16 @@
|
||||
|
||||
namespace App\Http\Controllers\Api\Settings;
|
||||
|
||||
use App\Http\Controllers\ApiController;
|
||||
use App\Abstracts\Http\ApiController;
|
||||
use App\Http\Requests\Setting\Tax as Request;
|
||||
use App\Jobs\Setting\CreateTax;
|
||||
use App\Jobs\Setting\DeleteTax;
|
||||
use App\Jobs\Setting\UpdateTax;
|
||||
use App\Models\Setting\Tax;
|
||||
use App\Transformers\Setting\Tax as Transformer;
|
||||
use Dingo\Api\Routing\Helpers;
|
||||
|
||||
class Taxes extends ApiController
|
||||
{
|
||||
use Helpers;
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
@ -43,9 +43,9 @@ class Taxes extends ApiController
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$tax = Tax::create($request->all());
|
||||
$tax = $this->dispatch(new CreateTax($request));
|
||||
|
||||
return $this->response->created(url('api/taxes/'.$tax->id));
|
||||
return $this->response->created(url('api/taxes/' . $tax->id));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -57,9 +57,43 @@ class Taxes extends ApiController
|
||||
*/
|
||||
public function update(Tax $tax, Request $request)
|
||||
{
|
||||
$tax->update($request->all());
|
||||
try {
|
||||
$tax = $this->dispatch(new UpdateTax($tax, $request));
|
||||
|
||||
return $this->response->item($tax->fresh(), new Transformer());
|
||||
return $this->item($tax->fresh(), new Transformer());
|
||||
} catch(\Exception $e) {
|
||||
$this->response->errorUnauthorized($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable the specified resource in storage.
|
||||
*
|
||||
* @param Tax $tax
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function enable(Tax $tax)
|
||||
{
|
||||
$tax = $this->dispatch(new UpdateTax($tax, request()->merge(['enabled' => 1])));
|
||||
|
||||
return $this->item($tax->fresh(), new Transformer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable the specified resource in storage.
|
||||
*
|
||||
* @param Tax $tax
|
||||
* @return \Dingo\Api\Http\Response
|
||||
*/
|
||||
public function disable(Tax $tax)
|
||||
{
|
||||
try {
|
||||
$tax = $this->dispatch(new UpdateTax($tax, request()->merge(['enabled' => 0])));
|
||||
|
||||
return $this->item($tax->fresh(), new Transformer());
|
||||
} catch(\Exception $e) {
|
||||
$this->response->errorUnauthorized($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -70,8 +104,12 @@ class Taxes extends ApiController
|
||||
*/
|
||||
public function destroy(Tax $tax)
|
||||
{
|
||||
$tax->delete();
|
||||
try {
|
||||
$this->dispatch(new DeleteTax($tax));
|
||||
|
||||
return $this->response->noContent();
|
||||
return $this->response->noContent();
|
||||
} catch(\Exception $e) {
|
||||
$this->response->errorUnauthorized($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user