From 23a191d1f76d418856d34ff2042cbd5e37049db2 Mon Sep 17 00:00:00 2001 From: omair saleh Date: Tue, 30 Mar 2021 02:10:14 +0800 Subject: [PATCH] fixing bugs --- .../CalculatesBookingFloatingAmount.php | 18 +++++++++++++----- .../Services/GeneratesBookingQuotation.php | 8 +++++++- .../forms/ConfirmQuotationFormComponent.vue | 2 +- .../forms/PurchaseOrderFormComponent.vue | 4 ++-- .../general/forms/FileUploadComponent.vue | 13 +++++++------ 5 files changed, 30 insertions(+), 15 deletions(-) diff --git a/app/Classes/Modules/Bookings/Services/CalculatesBookingFloatingAmount.php b/app/Classes/Modules/Bookings/Services/CalculatesBookingFloatingAmount.php index cc5acc1d..2f28c704 100644 --- a/app/Classes/Modules/Bookings/Services/CalculatesBookingFloatingAmount.php +++ b/app/Classes/Modules/Bookings/Services/CalculatesBookingFloatingAmount.php @@ -15,11 +15,19 @@ class CalculatesBookingFloatingAmount return $type === 1 ? $booking->transactions()->selectRaw('sum(amount - service_charge - tax) as sub_total') ->where('type', TransactionType::PAYMENT) - ->whereIn('status', [ApprovalStatus::PENDING_SUBMISSION, ApprovalStatus::PENDING_VERIFICATION]) - ->whereDate('expires_on', '>', Carbon::now())->get()->sum('sub_total') : - $booking->transactions()->where('type', TransactionType::PAYMENT) - ->whereIn('status', [ApprovalStatus::PENDING_SUBMISSION, ApprovalStatus::PENDING_VERIFICATION]) - ->whereDate('expires_on', '>', Carbon::now())->sum('original_amount'); + ->where(function($query){ + $query->whereIn('status', [ApprovalStatus::PENDING_SUBMISSION]) + ->whereDate('expires_on', '>=', Carbon::now()); + })->orWhere(function($query){ + $query->whereIn('status', [ApprovalStatus::PENDING_VERIFICATION]); + })->get()->sum('sub_total') + : $booking->transactions()->where('type', TransactionType::PAYMENT) + ->where(function($query){ + $query->whereIn('status', [ApprovalStatus::PENDING_SUBMISSION]) + ->whereDate('expires_on', '>=', Carbon::now()); + })->orWhere(function($query){ + $query->whereIn('status', [ApprovalStatus::PENDING_VERIFICATION]); + })->get()->sum('original_amount'); } } \ No newline at end of file diff --git a/app/Classes/Modules/Bookings/Services/GeneratesBookingQuotation.php b/app/Classes/Modules/Bookings/Services/GeneratesBookingQuotation.php index 0b631b54..8f40187b 100644 --- a/app/Classes/Modules/Bookings/Services/GeneratesBookingQuotation.php +++ b/app/Classes/Modules/Bookings/Services/GeneratesBookingQuotation.php @@ -7,11 +7,17 @@ use App\Classes\Modules\Bookings\DataTransferObjects\CalculationObject; use App\Http\Resources\BankResource; use App\Models\Bank; use Carbon\Carbon; +use Carbon\CarbonInterval; class GeneratesBookingQuotation { public function execute(CalculationObject $calculationObject, ?int $paymentAttemptLimit = 0){ + $date = Carbon::now(); + $days = $date->diffInDays($date->copy()->addMinutes($paymentAttemptLimit)); + $hours = $date->diffInHours($date->copy()->addMinutes($paymentAttemptLimit)->subDays($days)) ; + $minutes = $date->diffInMinutes($date->copy()->addMinutes($paymentAttemptLimit)->subDays($days)->subHours($hours)); + return [ 'bank' => new BankResource(Bank::find($calculationObject->getConfigurations()->getBankId())), 'rate' => $calculationObject->getConfigurations()->getRate(), @@ -24,7 +30,7 @@ class GeneratesBookingQuotation 'sub_total' => $calculationObject->getSubTotal(), 'total' => $calculationObject->getTotal(), 'date' => Carbon::now()->timezone('Asia/Singapore')->format('h:i a, jS M, Y \G\M\T T'), - 'payment_attempt_limit' => $paymentAttemptLimit + 'payment_attempt_limit' => CarbonInterval::days($days)->hours($hours)->minutes($minutes)->forHumans() ]; } } \ No newline at end of file diff --git a/resources/assets/vue/components/bookings/forms/ConfirmQuotationFormComponent.vue b/resources/assets/vue/components/bookings/forms/ConfirmQuotationFormComponent.vue index 0cf9cdfb..86be8e1a 100644 --- a/resources/assets/vue/components/bookings/forms/ConfirmQuotationFormComponent.vue +++ b/resources/assets/vue/components/bookings/forms/ConfirmQuotationFormComponent.vue @@ -42,7 +42,7 @@
-
Please upload your payment proof before the booking expires within 12 hours 30 minutes.
+
Please upload your payment proof before the booking expires within {{calculation.payment_attempt_limit}}.
diff --git a/resources/assets/vue/components/bookings/forms/PurchaseOrderFormComponent.vue b/resources/assets/vue/components/bookings/forms/PurchaseOrderFormComponent.vue index 90faea0e..5baf548f 100644 --- a/resources/assets/vue/components/bookings/forms/PurchaseOrderFormComponent.vue +++ b/resources/assets/vue/components/bookings/forms/PurchaseOrderFormComponent.vue @@ -176,8 +176,8 @@ } }, created() { - this.products = this.data.purchase_order.details; - this.submitted = this.data.purchase_order.status === 1 || this.data.purchase_order.status === 2; + this.products = this.data.purchase_order ? this.data.purchase_order.details : []; + this.submitted = this.data.purchase_order ? this.data.purchase_order.status === 1 || this.data.purchase_order.status === 2: false; }, computed: { productTotal(){ diff --git a/resources/assets/vue/components/general/forms/FileUploadComponent.vue b/resources/assets/vue/components/general/forms/FileUploadComponent.vue index 0a940557..3028586d 100644 --- a/resources/assets/vue/components/general/forms/FileUploadComponent.vue +++ b/resources/assets/vue/components/general/forms/FileUploadComponent.vue @@ -76,7 +76,6 @@ }, mounted(){ let vm = this; - Dropzone.autoDiscover = false; var dropzone = new Dropzone(this.$el, { url: '#', @@ -88,6 +87,8 @@ previewTemplate: '
' }); + dropzone.autoDiscover = false; + dropzone.on("removedfile", function() { vm.updateFiles(dropzone.files); }); @@ -97,10 +98,10 @@ vm.isLoading = true; if(file.name.split('.').pop() === 'pdf'){ - $(file.previewElement).find("img[data-dz-thumbnail]").attr("src", "/images/icons/pdf.png"); + $(file.previewElement).closest("img[data-dz-thumbnail]").attr("src", "/images/icons/pdf.png"); } if(file.name.split('.').pop().indexOf("xls") !== -1){ - $(file.previewElement).find("img[data-dz-thumbnail]").attr("src", "/images/icons/xlsx.png"); + $(file.previewElement).closest("img[data-dz-thumbnail]").attr("src", "/images/icons/xlsx.png"); } Promise.all(dropzone.files.map(function(file){ @@ -115,15 +116,15 @@ }); dropzone.on("dragover", function() { - $(vm.$el).find('.dragzone').css('opacity', 0.5) + $(vm.$el).closest('.dragzone').css('opacity', 0.5) }); dropzone.on("dragleave", function() { - $(vm.$el).find('.dragzone').css('opacity', 1) + $(vm.$el).closest('.dragzone').css('opacity', 1) }); dropzone.on("drop", function() { - $(vm.$el).find('.dragzone').css('opacity', 1) + $(vm.$el).closest('.dragzone').css('opacity', 1) }); }, methods: {