2019-11-16 07:21:14 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\BulkActions\Common;
|
|
|
|
|
|
2023-10-03 08:06:08 +00:00
|
|
|
use Akaunting\Money\Currency as MoneyCurrency;
|
2019-11-16 07:21:14 +00:00
|
|
|
use App\Abstracts\BulkAction;
|
2019-12-23 09:46:00 +00:00
|
|
|
use App\Jobs\Common\DeleteCompany;
|
|
|
|
|
use App\Jobs\Common\UpdateCompany;
|
2019-11-16 07:21:14 +00:00
|
|
|
use App\Models\Common\Company;
|
2023-10-03 08:06:08 +00:00
|
|
|
use App\Traits\Users;
|
2019-11-16 07:21:14 +00:00
|
|
|
|
|
|
|
|
class Companies extends BulkAction
|
|
|
|
|
{
|
2023-10-03 08:06:08 +00:00
|
|
|
use Users;
|
|
|
|
|
|
2019-11-16 07:21:14 +00:00
|
|
|
public $model = Company::class;
|
|
|
|
|
|
2022-06-01 07:15:55 +00:00
|
|
|
public $text = 'general.companies';
|
|
|
|
|
|
|
|
|
|
public $path = [
|
|
|
|
|
'group' => 'common',
|
|
|
|
|
'type' => 'companies',
|
|
|
|
|
];
|
|
|
|
|
|
2019-11-16 07:21:14 +00:00
|
|
|
public $actions = [
|
2023-10-03 08:06:08 +00:00
|
|
|
'edit' => [
|
|
|
|
|
'icon' => 'edit',
|
|
|
|
|
'name' => 'general.edit',
|
|
|
|
|
'message' => '',
|
|
|
|
|
'permission' => 'update-common-companies',
|
|
|
|
|
'type' => 'modal',
|
|
|
|
|
'handle' => 'update',
|
|
|
|
|
],
|
2022-06-01 07:15:55 +00:00
|
|
|
'enable' => [
|
|
|
|
|
'icon' => 'check_circle',
|
|
|
|
|
'name' => 'general.enable',
|
|
|
|
|
'message' => 'bulk_actions.message.enable',
|
|
|
|
|
'permission' => 'update-common-companies',
|
2019-11-16 07:21:14 +00:00
|
|
|
],
|
2022-06-01 07:15:55 +00:00
|
|
|
'disable' => [
|
|
|
|
|
'icon' => 'hide_source',
|
|
|
|
|
'name' => 'general.disable',
|
|
|
|
|
'message' => 'bulk_actions.message.disable',
|
|
|
|
|
'permission' => 'update-common-companies',
|
2019-11-16 07:21:14 +00:00
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
|
2023-10-03 08:06:08 +00:00
|
|
|
public function edit($request)
|
|
|
|
|
{
|
|
|
|
|
$selected = $this->getSelectedInput($request);
|
|
|
|
|
|
|
|
|
|
$money_currencies = MoneyCurrency::getCurrencies();
|
|
|
|
|
|
|
|
|
|
$currencies = [];
|
|
|
|
|
|
|
|
|
|
foreach ($money_currencies as $key => $item) {
|
|
|
|
|
$currencies[$key] = $key . ' - ' . $item['name'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->response('bulk-actions.common.companies.edit', compact('selected', 'currencies'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function update($request)
|
|
|
|
|
{
|
|
|
|
|
$companies = $this->getSelectedRecords($request);
|
|
|
|
|
|
|
|
|
|
foreach ($companies as $company) {
|
|
|
|
|
try {
|
|
|
|
|
if ($this->isNotUserCompany($company->id)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$request->merge([
|
|
|
|
|
'enabled' => $company->enabled,
|
|
|
|
|
]); // for update job authorize..
|
|
|
|
|
|
|
|
|
|
$this->dispatch(new UpdateCompany($company, $this->getUpdateRequest($request), company_id()));
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
flash($e->getMessage())->error()->important();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-16 07:21:14 +00:00
|
|
|
public function enable($request)
|
|
|
|
|
{
|
2019-12-23 09:46:00 +00:00
|
|
|
$companies = $this->getSelectedRecords($request);
|
2019-11-16 07:21:14 +00:00
|
|
|
|
2019-12-23 09:46:00 +00:00
|
|
|
foreach ($companies as $company) {
|
|
|
|
|
try {
|
2021-04-15 21:59:43 +00:00
|
|
|
$this->dispatch(new UpdateCompany($company, $request->merge(['enabled' => 1])));
|
2019-12-23 09:46:00 +00:00
|
|
|
} catch (\Exception $e) {
|
2021-02-12 16:26:38 +00:00
|
|
|
flash($e->getMessage())->error()->important();
|
2019-11-16 07:21:14 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function disable($request)
|
|
|
|
|
{
|
2019-12-23 09:46:00 +00:00
|
|
|
$companies = $this->getSelectedRecords($request);
|
2019-11-16 07:21:14 +00:00
|
|
|
|
2019-12-23 09:46:00 +00:00
|
|
|
foreach ($companies as $company) {
|
|
|
|
|
try {
|
2021-04-15 21:59:43 +00:00
|
|
|
$this->dispatch(new UpdateCompany($company, $request->merge(['enabled' => 0])));
|
2019-12-23 09:46:00 +00:00
|
|
|
} catch (\Exception $e) {
|
2021-02-12 16:26:38 +00:00
|
|
|
flash($e->getMessage())->error()->important();
|
2019-11-16 07:21:14 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function destroy($request)
|
|
|
|
|
{
|
2019-12-23 09:46:00 +00:00
|
|
|
$companies = $this->getSelectedRecords($request);
|
2019-11-16 07:21:14 +00:00
|
|
|
|
|
|
|
|
foreach ($companies as $company) {
|
|
|
|
|
try {
|
2021-04-15 21:59:43 +00:00
|
|
|
$this->dispatch(new DeleteCompany($company));
|
2019-12-23 09:46:00 +00:00
|
|
|
} catch (\Exception $e) {
|
2021-02-12 16:26:38 +00:00
|
|
|
flash($e->getMessage())->error()->important();
|
2019-11-16 07:21:14 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|