/ app / Http / Livewire / Jsons / Validation / View.php
View.php
 1  <?php
 2  
 3  namespace App\Http\Livewire\Jsons\Validation;
 4  
 5  
 6  use App\Http\Services\JsonImporterService;
 7  use App\Models\DocumentType;
 8  use App\Models\JsonDraft;
 9  use App\Models\ValidationType;
10  use App\Enums\InboxFileTypeEnum;
11  use App\Enums\ValidationStatusEnum;
12  use App\Helpers\DocGen\INFReportTemplateDocGen;
13  use Illuminate\Support\Facades\Auth;
14  use App\Http\Services\DocumentService;
15  use App\Http\Services\InboxFileService;
16  use Illuminate\Support\Facades\Storage;
17  
18  class View extends \App\Http\Livewire\InboxFiles\View
19  {
20  
21      public jsonDraft $jsonDraft;
22  
23      public function mount()
24      {
25          $this->inboxFile = $this->jsonDraft;
26          if ($this->inboxFile->completed)
27              abort(403);
28          /** @var ValidationType $validationType */
29          $validationType = $this->inboxFile->dossier->norm->validationTypes()
30              ->where('name', InboxFileTypeEnum::id2name(4))->firstOrFail();
31          $this->validationType = $validationType;
32          $this->requirements = $this->inboxFile->validation->requirements;
33      }
34  
35      public function confirm()
36      {
37          try {
38              InboxFileService::finishValidation($this->inboxFile);
39  
40              $doc = $this->generateInform();
41  
42              $this->inboxFile->validation->validated_report_id = $doc->id;
43              $this->inboxFile->validation->save();
44              if ($this->inboxFile->validation->status->id === ValidationStatusEnum::pass()->value) {
45  
46                  $this->addDocument(Auth()->id());
47                  $this->notificateSuccess();
48              } else {
49                  //file denied
50                  $this->notificateSuccess();
51                 /* return response()->streamDownload(function () use ($doc) {
52                      echo $this->getDeniedEml($doc);
53                  }, 'document.eml');*/
54              }
55  
56  
57              return redirect()->to(route('jsons.index'));
58          } catch (\Exception $e) {
59              log_exception($e);
60              $this->notification()->error('Error', $e->getMessage());
61              throw $e;
62          }
63      }
64  
65  
66      protected function addDocument(int $userId): void
67      {
68          $json = JsonImporterService::acceptDraft($this->jsonDraft);
69  
70      }
71  
72      public function render()
73      {
74          return view('livewire.inbox-files.view')
75              ->layoutData([
76                  'title' => __('inbox-files.title'),
77                  'entity' => $this->inboxFile,
78                  'breadcrumb' => 'validations.inbox-files.view',
79              ]);
80      }
81  }