|
7 | 7 | use Admin\Classes\BaseFormWidget; |
8 | 8 | use Admin\Classes\FormField; |
9 | 9 | use Admin\Facades\AdminAuth; |
| 10 | +use Admin\Facades\AdminLocation; |
10 | 11 | use Admin\Models\Orders_model; |
11 | 12 | use Admin\Models\Staff_groups_model; |
12 | 13 | use Admin\Models\Staffs_model; |
@@ -162,15 +163,13 @@ public function onSaveRecord() |
162 | 163 | throw new ApplicationException(sprintf(lang('admin::lang.statuses.alert_already_added'), $context, $context)); |
163 | 164 |
|
164 | 165 | $this->validateFormWidget($form, $saveData); |
165 | | - } |
166 | | - catch (ValidationException $ex) { |
| 166 | + } catch (ValidationException $ex) { |
167 | 167 | throw new ApplicationException($ex->getMessage()); |
168 | 168 | } |
169 | 169 |
|
170 | 170 | if ($this->saveRecord($saveData, $keyFrom)) { |
171 | 171 | flash()->success(sprintf(lang('admin::lang.alert_success'), lang($this->getModeConfig('formName')).' '.'updated'))->now(); |
172 | | - } |
173 | | - else { |
| 172 | + } else { |
174 | 173 | flash()->error(lang('admin::lang.alert_error_try_again'))->now(); |
175 | 174 | } |
176 | 175 |
|
@@ -207,7 +206,7 @@ public function onLoadAssigneeList() |
207 | 206 | $formField = $form->getField($this->assigneeKeyFrom); |
208 | 207 |
|
209 | 208 | return [ |
210 | | - '#'.$formField->getId() => $form->renderField($formField, [ |
| 209 | + '#'.$formField->getId('group') => $form->renderField($formField, [ |
211 | 210 | 'useContainer' => false, |
212 | 211 | ]), |
213 | 212 | ]; |
@@ -236,9 +235,15 @@ public static function getAssigneeOptions($form, $field) |
236 | 235 | if (!strlen($groupId = post('groupId', $form->getField('assignee_group_id')->value))) |
237 | 236 | return []; |
238 | 237 |
|
239 | | - return Staffs_model::whereHas('groups', function ($query) use ($groupId) { |
| 238 | + $query = Staffs_model::whereHas('groups', function ($query) use ($groupId) { |
240 | 239 | $query->where('staff_groups.staff_group_id', $groupId); |
241 | | - })->isEnabled()->dropdown('staff_name'); |
| 240 | + }); |
| 241 | + |
| 242 | + if ($locationId = AdminLocation::getId()) { |
| 243 | + $query->whereHasLocation($locationId); |
| 244 | + } |
| 245 | + |
| 246 | + return $query->isEnabled()->dropdown('staff_name'); |
242 | 247 | } |
243 | 248 |
|
244 | 249 | public static function getAssigneeGroupOptions() |
@@ -335,8 +340,7 @@ protected function saveRecord(array $saveData, string $keyFrom) |
335 | 340 | $staff = Staffs_model::find(array_get($saveData, $keyFrom)); |
336 | 341 | if ($record = $this->model->updateAssignTo($group, $staff)) |
337 | 342 | AssigneeUpdated::log($record, $this->getController()->getUser()); |
338 | | - } |
339 | | - else { |
| 343 | + } else { |
340 | 344 | $status = Statuses_model::find(array_get($saveData, $keyFrom)); |
341 | 345 | if ($record = $this->model->addStatusHistory($status, $saveData)) |
342 | 346 | StatusUpdated::log($record, $this->getController()->getUser()); |
|
0 commit comments