From 07d1bbd92181987aa1aeaf0cc2797fd59d053f96 Mon Sep 17 00:00:00 2001 From: omair saleh Date: Wed, 2 Mar 2022 02:24:54 +0800 Subject: [PATCH] fix billing page --- .../General/Eloquent/Filters/WithOwner.php | 20 ++++++ .../DownloadBookingDocumentLogic.php | 38 +++-------- app/Http/Resources/DocumentResource.php | 3 +- .../bookings/elements/BillingComponent.vue | 47 +++++++------- .../elements/BillingDocumentComponent.vue | 64 +++++++++++++++++++ resources/views/pages/billings.blade.php | 16 ++--- routes/booking.php | 2 - routes/web.php | 2 + 8 files changed, 130 insertions(+), 62 deletions(-) create mode 100644 app/Classes/General/Eloquent/Filters/WithOwner.php create mode 100644 resources/assets/vue/components/bookings/elements/BillingDocumentComponent.vue 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 @@
- -
+
@@ -44,13 +43,13 @@
- +
- + @@ -73,32 +72,36 @@ import {VMoney} from 'v-money' export default { data(){ return { - section: 'customerSectionComponent', - isLoading: false, - search: false, parameters: { - startDate: '2021-01-01', - endDate: '2022-01-01', + startDate: '', + endDate: '', type: 'INVOICE', }, - selectedDocumentStatus: false, documents: ['INVOICE', 'PURCHASE_ORDER', 'DELIVERY_ORDER', 'SUPPLIER_DELIVERY_ORDER'], - } - }, - methods: { - submitSearch(){ - this.submit(this.route('api.booking.download'), 'post', this.section, false, false) - }, - updateDocumentType(documentType) { - this.parameters.type = documentType; - this.selectedDocumentStatus = !this.selectedDocumentStatus + selectedDocumentStatus: false } }, validations: { parameters: { - recency: {}, - frequency: {}, - monetary: {}, + startDate: { + required + }, + endDate: { + required + }, + type: { + required + }, + } + }, + methods: { + submitSearch(){ + if(!this.validate()){ return; } + window.open(route('documents.download')+'?type='+this.parameters.type+'&startDate='+this.parameters.startDate+'&endDate='+this.parameters.endDate, '_blank'); + }, + updateDocumentType(documentType) { + this.parameters.type = documentType; + this.selectedDocumentStatus = !this.selectedDocumentStatus } }, mixins: [componentHandler] diff --git a/resources/assets/vue/components/bookings/elements/BillingDocumentComponent.vue b/resources/assets/vue/components/bookings/elements/BillingDocumentComponent.vue new file mode 100644 index 00000000..64f96d0e --- /dev/null +++ b/resources/assets/vue/components/bookings/elements/BillingDocumentComponent.vue @@ -0,0 +1,64 @@ + + + \ No newline at end of file diff --git a/resources/views/pages/billings.blade.php b/resources/views/pages/billings.blade.php index 2dd8f312..4bc012d5 100644 --- a/resources/views/pages/billings.blade.php +++ b/resources/views/pages/billings.blade.php @@ -95,30 +95,30 @@
- +
- +
- +
- +
diff --git a/routes/booking.php b/routes/booking.php index 2087d0fa..d83bb4af 100644 --- a/routes/booking.php +++ b/routes/booking.php @@ -32,6 +32,4 @@ Route::group(['prefix' => 'booking', 'as' => 'booking.', 'namespace' => 'Booking Route::post('{id}/proforma/create', 'CreateProformaInvoiceTransaction@create')->name('proforma.create'); - Route::get('/document/download', 'DownloadBookingDocumentController@download')->name('download'); - }); \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index 4fe7fdf2..d258ba05 100644 --- a/routes/web.php +++ b/routes/web.php @@ -132,6 +132,8 @@ Route::get('/bookings/billplz', function () { return view('pages.billplz_redirect'); })->name('bookings.billplz'); +Route::get('/document/download', 'Bookings\DownloadBookingDocumentController@download')->name('documents.download'); + Route::get('billplz/bills/{bill_no}', function($bill_no){ return redirect(env('BILLPLZ_BASE_URL').'/bills/'.$bill_no); })->name('billplz.bill');