2019-11-16 10:21:14 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\BulkActions\Common;
|
|
|
|
|
|
|
|
use App\Abstracts\BulkAction;
|
2019-12-23 12:46:00 +03:00
|
|
|
use App\Jobs\Common\DeleteCompany;
|
|
|
|
use App\Jobs\Common\UpdateCompany;
|
2019-11-16 10:21:14 +03:00
|
|
|
use App\Models\Common\Company;
|
|
|
|
|
|
|
|
class Companies extends BulkAction
|
|
|
|
{
|
|
|
|
public $model = Company::class;
|
|
|
|
|
2022-06-01 10:15:55 +03:00
|
|
|
public $text = 'general.companies';
|
|
|
|
|
|
|
|
public $path = [
|
|
|
|
'group' => 'common',
|
|
|
|
'type' => 'companies',
|
|
|
|
];
|
|
|
|
|
2019-11-16 10:21:14 +03:00
|
|
|
public $actions = [
|
2022-06-01 10:15:55 +03:00
|
|
|
'enable' => [
|
|
|
|
'icon' => 'check_circle',
|
|
|
|
'name' => 'general.enable',
|
|
|
|
'message' => 'bulk_actions.message.enable',
|
|
|
|
'permission' => 'update-common-companies',
|
2019-11-16 10:21:14 +03:00
|
|
|
],
|
2022-06-01 10:15:55 +03:00
|
|
|
'disable' => [
|
|
|
|
'icon' => 'hide_source',
|
|
|
|
'name' => 'general.disable',
|
|
|
|
'message' => 'bulk_actions.message.disable',
|
|
|
|
'permission' => 'update-common-companies',
|
2019-11-16 10:21:14 +03:00
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
public function enable($request)
|
|
|
|
{
|
2019-12-23 12:46:00 +03:00
|
|
|
$companies = $this->getSelectedRecords($request);
|
2019-11-16 10:21:14 +03:00
|
|
|
|
2019-12-23 12:46:00 +03:00
|
|
|
foreach ($companies as $company) {
|
|
|
|
try {
|
2021-04-16 00:59:43 +03:00
|
|
|
$this->dispatch(new UpdateCompany($company, $request->merge(['enabled' => 1])));
|
2019-12-23 12:46:00 +03:00
|
|
|
} catch (\Exception $e) {
|
2021-02-12 19:26:38 +03:00
|
|
|
flash($e->getMessage())->error()->important();
|
2019-11-16 10:21:14 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function disable($request)
|
|
|
|
{
|
2019-12-23 12:46:00 +03:00
|
|
|
$companies = $this->getSelectedRecords($request);
|
2019-11-16 10:21:14 +03:00
|
|
|
|
2019-12-23 12:46:00 +03:00
|
|
|
foreach ($companies as $company) {
|
|
|
|
try {
|
2021-04-16 00:59:43 +03:00
|
|
|
$this->dispatch(new UpdateCompany($company, $request->merge(['enabled' => 0])));
|
2019-12-23 12:46:00 +03:00
|
|
|
} catch (\Exception $e) {
|
2021-02-12 19:26:38 +03:00
|
|
|
flash($e->getMessage())->error()->important();
|
2019-11-16 10:21:14 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function destroy($request)
|
|
|
|
{
|
2019-12-23 12:46:00 +03:00
|
|
|
$companies = $this->getSelectedRecords($request);
|
2019-11-16 10:21:14 +03:00
|
|
|
|
|
|
|
foreach ($companies as $company) {
|
|
|
|
try {
|
2021-04-16 00:59:43 +03:00
|
|
|
$this->dispatch(new DeleteCompany($company));
|
2019-12-23 12:46:00 +03:00
|
|
|
} catch (\Exception $e) {
|
2021-02-12 19:26:38 +03:00
|
|
|
flash($e->getMessage())->error()->important();
|
2019-11-16 10:21:14 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|