diff --git a/app/Classes/General/Eloquent/Filters/WithOwner.php b/app/Classes/General/Eloquent/Filters/WithOwner.php new file mode 100644 index 00000000..7d31691e --- /dev/null +++ b/app/Classes/General/Eloquent/Filters/WithOwner.php @@ -0,0 +1,20 @@ +with('owner'); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Bookings/ControllersLogic/DownloadBookingDocumentLogic.php b/app/Classes/Modules/Bookings/ControllersLogic/DownloadBookingDocumentLogic.php index 3c3459e2..cb37d36a 100644 --- a/app/Classes/Modules/Bookings/ControllersLogic/DownloadBookingDocumentLogic.php +++ b/app/Classes/Modules/Bookings/ControllersLogic/DownloadBookingDocumentLogic.php @@ -17,7 +17,7 @@ use App\Classes\ValueObjects\Constants\ApprovalStatus; use App\Classes\ValueObjects\Constants\TransactionType; use App\Classes\General\Abstracts\AbstractControllerLogic; -class DownloadBookingDocumentLogic extends AbstractControllerLogic +class DownloadBookingDocumentLogic { /** @@ -42,25 +42,21 @@ class DownloadBookingDocumentLogic extends AbstractControllerLogic /** * @param Request $request * @return JsonResponse - * @throws \App\Classes\Exceptions\AccessForbiddenException - * @throws \App\Classes\Exceptions\RequestValidationException + * @throws MalformedRequestException */ - public function logic(Request $request): JsonResponse + public function execute(Request $request): JsonResponse { Auth::login(User::findOrFail(1)); - $zip_file = 'do_' . Carbon::yesterday()->format('Y_m_d') . '.zip'; - $attachment = storage_path() . '/' . $zip_file; + $zip_file = $request->input('type').'.zip'; + $attachment = Storage::disk('documents')->path('zip/'.$zip_file); $zip = new ZipArchive(); if ($zip->open($attachment, ZIPARCHIVE::CREATE | ZipArchive::OVERWRITE)) { - $bookings = Booking::where('status', ApprovalStatus::COMPLETED)->whereDate('updated_at', '>=', $request->input('startDate'))->whereDate('updated_at', '<=', $request->input('endDate')) - ->whereHas('transactions', function ($query) { - return $query->where('type', TransactionType::PAYMENT)->whereHas('transactions', function ($query) { - return $query->where('issuer', 2); - }); - })->get(); + $bookings = Booking::where('status', ApprovalStatus::COMPLETED) + ->whereDate('updated_at', '>=', Carbon::parse($request->input('startDate'))) + ->whereDate('updated_at', '<=', Carbon::parse($request->input('endDate')))->get(); if (!count($bookings)) throw new MalformedRequestException('No available file to download'); @@ -71,23 +67,7 @@ class DownloadBookingDocumentLogic extends AbstractControllerLogic $zip->close(); - while (ob_get_level()) { - ob_end_clean(); - } - ob_start(); - header($_SERVER['SERVER_PROTOCOL'] . ' 200 OK'); - header("Content-Type: application/zip"); - header("Content-Transfer-Encoding: Binary"); - header("Content-Length: " . filesize($attachment)); - header('Pragma: no-cache'); - header("Content-Disposition: attachment; filename=\"" . basename($attachment) . "\""); - ob_flush(); - ob_clean(); - - readfile($attachment); - File::delete($attachment); - - exit; + return Storage::download($attachment); } } diff --git a/app/Http/Resources/DocumentResource.php b/app/Http/Resources/DocumentResource.php index 2595ed55..59933a67 100644 --- a/app/Http/Resources/DocumentResource.php +++ b/app/Http/Resources/DocumentResource.php @@ -2,6 +2,7 @@ namespace App\Http\Resources; +use App\Models\Booking; use App\Models\Company; use App\Models\Document; use Carbon\Carbon; @@ -23,7 +24,7 @@ class DocumentResource extends JsonResource 'reference' => $this->reference, 'status' => (int) $this->status, 'document_type' => $this->document_type, - 'owner' => new CompanyResource($this->whenLoaded('owner')), + 'owner' => $this->relationLoaded('owner') ? ($this->owner instanceof Booking ? new BookingResource($this->owner) : new CompanyResource($this->owner)) : null, 'files' => FileResource::collection($this->files), 'created_at' => Carbon::parse($this->created_at)->format('d-m-Y h:i:s A') ]; diff --git a/resources/assets/vue/components/bookings/elements/BillingComponent.vue b/resources/assets/vue/components/bookings/elements/BillingComponent.vue index 0e9263c9..bfa8b2d9 100644 --- a/resources/assets/vue/components/bookings/elements/BillingComponent.vue +++ b/resources/assets/vue/components/bookings/elements/BillingComponent.vue @@ -3,8 +3,7 @@