Files
.github
app
Abstracts
Builders
BulkActions
Classifiers
Console
Events
Exceptions
Exports
Http
Controllers
Api
Auth
Banking
Common
Install
Modals
Accounts.php
Categories.php
Companies.php
Currencies.php
Customers.php
DocumentItemColumns.php
DocumentTransactions.php
InvoiceEmails.php
InvoiceShare.php
InvoiceTemplates.php
Items.php
Taxes.php
TransactionEmails.php
TransactionShare.php
TransferTemplates.php
Vendors.php
Modules
Portal
Purchases
Sales
Settings
Wizard
Livewire
Middleware
Requests
Resources
Responses
ViewComposers
Kernel.php
Imports
Interfaces
Jobs
Listeners
Models
Notifications
Observers
Providers
Relations
Reports
Scopes
Traits
Utilities
View
Widgets
bootstrap
config
database
modules
overrides
public
resources
routes
storage
tests
.editorconfig
.env.example
.env.testing
.gitattributes
.gitignore
.htaccess
LICENSE.txt
README.md
SECURITY.md
artisan
composer.json
composer.lock
index.php
manifest.json
nginx.example.com.conf
package-lock.json
package.json
phpunit.xml
presets.js
safelist.txt
serviceworker.js
tailwind.config.js
web.config
webpack.mix.js
akaunting/app/Http/Controllers/Modals/Customers.php
2022-06-01 10:15:55 +03:00

115 lines
3.1 KiB
PHP

<?php
namespace App\Http\Controllers\Modals;
use App\Abstracts\Http\Controller;
use App\Http\Requests\Common\Contact as Request;
use App\Models\Common\Contact;
use App\Jobs\Common\CreateContact;
use App\Jobs\Common\UpdateContact;
class Customers extends Controller
{
/**
* Instantiate a new controller instance.
*/
public function __construct()
{
// Add CRUD permission check
$this->middleware('permission:create-sales-customers')->only('create', 'store', 'duplicate', 'import');
$this->middleware('permission:read-sales-customers')->only('index', 'show', 'edit', 'export');
$this->middleware('permission:update-sales-customers')->only('update', 'enable', 'disable');
$this->middleware('permission:delete-sales-customers')->only('destroy');
}
/**
* Show the form for creating a new resource.
*
* @return Response
*/
public function create()
{
$contact_selector = false;
if (request()->has('contact_selector')) {
$contact_selector = request()->get('contact_selector');
}
$html = view('modals.customers.create', compact('contact_selector'))->render();
return response()->json([
'success' => true,
'error' => false,
'message' => 'null',
'html' => $html,
]);
}
/**
* Store a newly created resource in storage.
*
* @param Request $request
*
* @return Response
*/
public function store(Request $request)
{
$request['enabled'] = 1;
$response = $this->ajaxDispatch(new CreateContact($request));
$this->ajaxDispatch(new UpdateContact($customer, $request));
if ($response['success']) {
$response['message'] = trans('messages.success.added', ['type' => trans_choice('general.customers', 1)]);
}
return response()->json($response);
}
/**
* Show the form for editing the specified resource.
*
* @param Contact $customer
*
* @return Response
*/
public function edit(Contact $customer)
{
$contact_selector = false;
if (request()->has('contact_selector')) {
$contact_selector = request()->get('contact_selector');
}
$html = view('modals.customers.edit', compact('customer', 'contact_selector'))->render();
return response()->json([
'success' => true,
'error' => false,
'message' => 'null',
'html' => $html,
]);
}
/**
* Update the specified resource in storage.
*
* @param Contact $customer
* @param Request $request
*
* @return Response
*/
public function update(Contact $customer, Request $request)
{
$request['enabled'] = 1;
$response = $this->ajaxDispatch(new UpdateContact($customer, $request));
if ($response['success']) {
$response['message'] = trans('messages.success.updated', ['type' => trans_choice('general.customers', 1)]);
}
return response()->json($response);
}
}