|
|
@@ -2,9 +2,184 @@
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
+use App\Http\Requests\CreateReclamationRequest;
|
|
|
+use App\Http\Requests\StoreReclamationRequest;
|
|
|
+use App\Models\File;
|
|
|
+use App\Models\Order;
|
|
|
+use App\Models\Reclamation;
|
|
|
+use App\Models\ReclamationStatus;
|
|
|
+use App\Models\Role;
|
|
|
+use App\Models\User;
|
|
|
+use App\Services\FileService;
|
|
|
use Illuminate\Http\Request;
|
|
|
+use Illuminate\Support\Carbon;
|
|
|
+use Illuminate\Support\Facades\Storage;
|
|
|
|
|
|
class ReclamationController extends Controller
|
|
|
{
|
|
|
- //
|
|
|
+ protected array $data = [
|
|
|
+ 'active' => 'reclamations',
|
|
|
+ 'title' => 'Рекламации',
|
|
|
+ 'id' => 'reclamations',
|
|
|
+ 'header' => [
|
|
|
+ 'id' => 'ID',
|
|
|
+ 'user_id' => 'Менеджер',
|
|
|
+ 'status_id' => 'Статус',
|
|
|
+ 'order-district_id' => 'Округ',
|
|
|
+ 'order-area_id' => 'Район',
|
|
|
+ 'order-object_address' => 'Адрес объекта',
|
|
|
+ 'create_date' => 'Дата создания',
|
|
|
+ 'finish_date' => 'Дата завершения',
|
|
|
+ 'reason' => 'Причина',
|
|
|
+ 'guarantee' => 'Гарантии',
|
|
|
+ 'whats_done' => 'Что сделано',
|
|
|
+ ],
|
|
|
+ 'searchFields' => [
|
|
|
+ 'reason',
|
|
|
+ 'guarantee',
|
|
|
+ 'whats_done',
|
|
|
+ ],
|
|
|
+ 'ranges' => [],
|
|
|
+ ];
|
|
|
+
|
|
|
+ public function __construct()
|
|
|
+ {
|
|
|
+ $this->data['users'] = User::query()->whereIn('role', [Role::MANAGER, Role::ADMIN])->get()->pluck('name', 'id');
|
|
|
+ $this->data['statuses'] = ReclamationStatus::query()->get()->pluck('name', 'id');
|
|
|
+ }
|
|
|
+
|
|
|
+ public function index(Request $request)
|
|
|
+ {
|
|
|
+ $model = new Reclamation();
|
|
|
+ // fill filters
|
|
|
+ $this->createFilters($model, 'user_id', 'status_id');
|
|
|
+ $this->createDateFilters($model, 'create_date', 'finish_date');
|
|
|
+
|
|
|
+ $q = $model::query();
|
|
|
+
|
|
|
+ $this->acceptFilters($q, $request);
|
|
|
+ $this->acceptSearch($q, $request);
|
|
|
+ $this->setSortAndOrderBy($model, $request);
|
|
|
+
|
|
|
+ $q->orderBy($this->data['sortBy'], $this->data['orderBy']);
|
|
|
+ $this->data['reclamations'] = $q->paginate(session('per_page', config('pagination.per_page')))->withQueryString();
|
|
|
+
|
|
|
+ return view('reclamations.index', $this->data);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function create(CreateReclamationRequest $request, Order $order)
|
|
|
+ {
|
|
|
+ $reclamation = Reclamation::query()->create([
|
|
|
+ 'order_id' => $order->id,
|
|
|
+ 'user_id' => $request->user()->id,
|
|
|
+ 'status_id' => Reclamation::STATUS_NEW,
|
|
|
+ 'create_date' => Carbon::now(),
|
|
|
+ 'finish_date' => Carbon::now()->addDays(30),
|
|
|
+ ]);
|
|
|
+ $skus = $request->validated('skus');
|
|
|
+ $reclamation->skus()->attach($skus);
|
|
|
+ return redirect()->route('reclamations.show', $reclamation);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function show(Reclamation $reclamation)
|
|
|
+ {
|
|
|
+ $this->data['reclamation'] = $reclamation;
|
|
|
+ return view('reclamations.edit', $this->data);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function update(StoreReclamationRequest $request, Reclamation $reclamation)
|
|
|
+ {
|
|
|
+ $data = $request->validated();
|
|
|
+ $reclamation->update($data);
|
|
|
+ return redirect()->route('reclamations.show', $reclamation);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function uploadPhotoBefore(Request $request, Reclamation $reclamation, FileService $fileService)
|
|
|
+ {
|
|
|
+ $data = $request->validate([
|
|
|
+ 'photo.*' => 'mimes:jpeg,jpg,png|max:8192',
|
|
|
+ ]);
|
|
|
+ $f = [];
|
|
|
+ foreach ($data['photo'] as $photo) {
|
|
|
+ $f[] = $fileService->saveUploadedFile( 'reclamations/' . $reclamation->id . '/photo_before', $photo);
|
|
|
+ }
|
|
|
+ $reclamation->photos_before()->syncWithoutDetaching($f);
|
|
|
+
|
|
|
+ return redirect()->route('reclamations.show', $reclamation);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function uploadPhotoAfter(Request $request, Reclamation $reclamation, FileService $fileService)
|
|
|
+ {
|
|
|
+ $data = $request->validate([
|
|
|
+ 'photo.*' => 'mimes:jpeg,jpg,png|max:8192',
|
|
|
+ ]);
|
|
|
+ $f = [];
|
|
|
+ foreach ($data['photo'] as $photo) {
|
|
|
+ $f[] = $fileService->saveUploadedFile( 'reclamations/' . $reclamation->id . '/photo_after', $photo);
|
|
|
+ }
|
|
|
+ $reclamation->photos_after()->syncWithoutDetaching($f);
|
|
|
+
|
|
|
+ return redirect()->route('reclamations.show', $reclamation);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function deletePhotoBefore(Reclamation $reclamation, File $file, FileService $fileService)
|
|
|
+ {
|
|
|
+ $reclamation->photos_before()->detach($file);
|
|
|
+ Storage::disk('public')->delete($file->path);
|
|
|
+ $file->delete();
|
|
|
+ return redirect()->route('reclamations.show', $reclamation);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function deletePhotoAfter(Reclamation $reclamation, File $file, FileService $fileService)
|
|
|
+ {
|
|
|
+ $reclamation->photos_after()->detach($file);
|
|
|
+ Storage::disk('public')->delete($file->path);
|
|
|
+ $file->delete();
|
|
|
+ return redirect()->route('reclamations.show', $reclamation);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function uploadDocument(Request $request, Reclamation $reclamation, FileService $fileService)
|
|
|
+ {
|
|
|
+ $data = $request->validate([
|
|
|
+ 'document.*' => 'file',
|
|
|
+ ]);
|
|
|
+ $f = [];
|
|
|
+ foreach ($data['document'] as $document) {
|
|
|
+ $f[] = $fileService->saveUploadedFile( 'reclamations/' . $reclamation->id . '/document', $document);
|
|
|
+ }
|
|
|
+ $reclamation->documents()->syncWithoutDetaching($f);
|
|
|
+
|
|
|
+ return redirect()->route('reclamations.show', $reclamation);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function deleteDocument(Reclamation $reclamation, File $file)
|
|
|
+ {
|
|
|
+ $reclamation->documents()->detach($file);
|
|
|
+ Storage::disk('public')->delete($file->path);
|
|
|
+ $file->delete();
|
|
|
+ return redirect()->route('reclamations.show', $reclamation);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function uploadAct(Request $request, Reclamation $reclamation, FileService $fileService)
|
|
|
+ {
|
|
|
+ $data = $request->validate([
|
|
|
+ 'acts.*' => 'file',
|
|
|
+ ]);
|
|
|
+ $f = [];
|
|
|
+ foreach ($data['acts'] as $document) {
|
|
|
+ $f[] = $fileService->saveUploadedFile( 'reclamations/' . $reclamation->id . '/act', $document);
|
|
|
+ }
|
|
|
+ $reclamation->acts()->syncWithoutDetaching($f);
|
|
|
+
|
|
|
+ return redirect()->route('reclamations.show', $reclamation);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function deleteAct(Reclamation $reclamation, File $file)
|
|
|
+ {
|
|
|
+ $reclamation->acts()->detach($file);
|
|
|
+ Storage::disk('public')->delete($file->path);
|
|
|
+ $file->delete();
|
|
|
+ return redirect()->route('reclamations.show', $reclamation);
|
|
|
+ }
|
|
|
+
|
|
|
}
|