Skip to content

Commit 7bb2e53

Browse files
fix: lead issue and other issues
1 parent e15e6fb commit 7bb2e53

File tree

31 files changed

+503
-259
lines changed

31 files changed

+503
-259
lines changed

packages/Webkul/Admin/src/Http/Controllers/Contact/Persons/PersonController.php

+2-21
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function store(AttributeForm $request): RedirectResponse|JsonResponse
5454
{
5555
Event::dispatch('contacts.person.create.before');
5656

57-
$person = $this->personRepository->create($this->sanitizeRequestedPersonData($request->all()));
57+
$person = $this->personRepository->create($request->all());
5858

5959
Event::dispatch('contacts.person.create.after', $person);
6060

@@ -97,7 +97,7 @@ public function update(AttributeForm $request, int $id): RedirectResponse|JsonRe
9797
{
9898
Event::dispatch('contacts.person.update.before', $id);
9999

100-
$person = $this->personRepository->update($this->sanitizeRequestedPersonData($request->all()), $id);
100+
$person = $this->personRepository->update($request->all(), $id);
101101

102102
Event::dispatch('contacts.person.update.after', $person);
103103

@@ -174,23 +174,4 @@ public function massDestroy(MassDestroyRequest $massDestroyRequest): JsonRespons
174174
'message' => trans('admin::app.contacts.persons.index.delete-success'),
175175
]);
176176
}
177-
178-
/**
179-
* Sanitize requested person data and return the clean array.
180-
*/
181-
private function sanitizeRequestedPersonData(array $data): array
182-
{
183-
if (
184-
array_key_exists('organization_id', $data)
185-
&& empty($data['organization_id'])
186-
) {
187-
$data['organization_id'] = null;
188-
}
189-
190-
if (isset($data['contact_numbers'])) {
191-
$data['contact_numbers'] = collect($data['contact_numbers'])->filter(fn ($number) => ! is_null($number['value']))->toArray();
192-
}
193-
194-
return $data;
195-
}
196177
}

packages/Webkul/Admin/src/Http/Controllers/Lead/LeadController.php

+8-36
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use Webkul\Admin\Http\Resources\StageResource;
1919
use Webkul\Attribute\Repositories\AttributeRepository;
2020
use Webkul\Contact\Repositories\PersonRepository;
21-
use Webkul\DataGrid\Enums\DateRangeOptionEnum;
2221
use Webkul\Lead\Repositories\LeadRepository;
2322
use Webkul\Lead\Repositories\PipelineRepository;
2423
use Webkul\Lead\Repositories\ProductRepository;
@@ -153,7 +152,7 @@ public function store(LeadForm $request): RedirectResponse
153152

154153
$data['status'] = 1;
155154

156-
if (request()->input('lead_pipeline_stage_id')) {
155+
if (isset($data['lead_pipeline_stage_id'])) {
157156
$stage = $this->stageRepository->findOrFail($data['lead_pipeline_stage_id']);
158157

159158
$data['lead_pipeline_id'] = $stage->lead_pipeline_id;
@@ -171,8 +170,6 @@ public function store(LeadForm $request): RedirectResponse
171170
$data['closed_at'] = Carbon::now();
172171
}
173172

174-
$data['person']['organization_id'] = empty($data['person']['organization_id']) ? null : $data['person']['organization_id'];
175-
176173
$lead = $this->leadRepository->create($data);
177174

178175
Event::dispatch('lead.create.after', $lead);
@@ -195,12 +192,14 @@ public function edit(int $id): View
195192
/**
196193
* Display a resource.
197194
*/
198-
public function view(int $id): View
195+
public function view(int $id)
199196
{
200197
$lead = $this->leadRepository->findOrFail($id);
201198

199+
$userIds = bouncer()->getAuthorizedUserIds();
200+
202201
if (
203-
$userIds = bouncer()->getAuthorizedUserIds()
202+
$userIds
204203
&& ! in_array($lead->user_id, $userIds)
205204
) {
206205
return redirect()->route('admin.leads.index');
@@ -232,8 +231,6 @@ public function update(LeadForm $request, int $id): RedirectResponse|JsonRespons
232231
$data['lead_pipeline_stage_id'] = $stage->id;
233232
}
234233

235-
$data['person']['organization_id'] = empty($data['person']['organization_id']) ? null : $data['person']['organization_id'];
236-
237234
$lead = $this->leadRepository->update($data, $id);
238235

239236
Event::dispatch('lead.update.after', $lead);
@@ -343,7 +340,7 @@ public function destroy(int $id): JsonResponse
343340

344341
return response()->json([
345342
'message' => trans('admin::app.leads.destroy-success'),
346-
], 200);
343+
]);
347344
} catch (\Exception $exception) {
348345
return response()->json([
349346
'message' => trans('admin::app.leads.destroy-failed'),
@@ -352,7 +349,7 @@ public function destroy(int $id): JsonResponse
352349
}
353350

354351
/**
355-
* Mass Update the specified resources.
352+
* Mass update the specified resources.
356353
*/
357354
public function massUpdate(MassUpdateRequest $massUpdateRequest): JsonResponse
358355
{
@@ -380,7 +377,7 @@ public function massUpdate(MassUpdateRequest $massUpdateRequest): JsonResponse
380377
}
381378

382379
/**
383-
* Mass Delete the specified resources.
380+
* Mass delete the specified resources.
384381
*/
385382
public function massDestroy(MassDestroyRequest $massDestroyRequest): JsonResponse
386383
{
@@ -578,7 +575,6 @@ private function getKanbanColumns(): array
578575
'sortable' => true,
579576
'visibility' => true,
580577
],
581-
582578
[
583579
'index' => 'tags.name',
584580
'label' => trans('admin::app.leads.index.kanban.columns.tags'),
@@ -599,30 +595,6 @@ private function getKanbanColumns(): array
599595
],
600596
],
601597
],
602-
603-
[
604-
'index' => 'expected_close_date',
605-
'label' => trans('admin::app.leads.index.kanban.columns.expected-close-date'),
606-
'type' => 'date',
607-
'searchable' => false,
608-
'searchable' => false,
609-
'sortable' => true,
610-
'filterable' => true,
611-
'filterable_type' => 'date_range',
612-
'filterable_options' => DateRangeOptionEnum::options(),
613-
],
614-
615-
[
616-
'index' => 'created_at',
617-
'label' => trans('admin::app.leads.index.kanban.columns.created-at'),
618-
'type' => 'date',
619-
'searchable' => false,
620-
'searchable' => false,
621-
'sortable' => true,
622-
'filterable' => true,
623-
'filterable_type' => 'date_range',
624-
'filterable_options' => DateRangeOptionEnum::options(),
625-
],
626598
];
627599
}
628600
}

packages/Webkul/Admin/src/Http/Controllers/Settings/AttributeController.php

+26-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Webkul\Admin\Http\Controllers\Controller;
1212
use Webkul\Admin\Http\Requests\MassDestroyRequest;
1313
use Webkul\Attribute\Repositories\AttributeRepository;
14+
use Webkul\Attribute\Repositories\AttributeValueRepository;
1415
use Webkul\Core\Contracts\Validations\Code;
1516

1617
class AttributeController extends Controller
@@ -20,7 +21,10 @@ class AttributeController extends Controller
2021
*
2122
* @return void
2223
*/
23-
public function __construct(protected AttributeRepository $attributeRepository) {}
24+
public function __construct(
25+
protected AttributeRepository $attributeRepository,
26+
protected AttributeValueRepository $attributeValueRepository
27+
) {}
2428

2529
/**
2630
* Display a listing of the resource.
@@ -129,6 +133,27 @@ public function destroy(int $id): JsonResponse
129133
}
130134
}
131135

136+
/**
137+
* Check unique validation.
138+
*
139+
* @return void
140+
*/
141+
public function checkUniqueValidation()
142+
{
143+
$attribute = $this->attributeRepository->findOneWhere([
144+
'code' => request('attribute_code'),
145+
]);
146+
147+
return response()->json([
148+
'validated' => $this->attributeValueRepository->isValueUnique(
149+
request('entity_id'),
150+
request('entity_type'),
151+
$attribute,
152+
request('attribute_value'),
153+
),
154+
]);
155+
}
156+
132157
/**
133158
* Search attribute lookup results
134159
*/

packages/Webkul/Admin/src/Http/Requests/LeadForm.php

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Webkul\Admin\Http\Requests;
44

5+
use Carbon\Carbon;
56
use Illuminate\Foundation\Http\FormRequest;
67
use Webkul\Attribute\Repositories\AttributeRepository;
78
use Webkul\Attribute\Repositories\AttributeValueRepository;
@@ -127,6 +128,11 @@ public function rules()
127128
}
128129
}
129130

131+
$this->rules['expected_close_date'] = [
132+
'date_format:Y-m-d',
133+
'after:'.Carbon::yesterday()->format('Y-m-d'),
134+
];
135+
130136
return [
131137
...$this->rules,
132138
'products' => 'array',

0 commit comments

Comments
 (0)