mirror of
				https://github.com/crater-invoice/crater.git
				synced 2025-10-28 04:01:10 -04:00 
			
		
		
		
	fixed uploaded attachment not removed
This commit is contained in:
		
				
					committed by
					
						 Mohit Panjwani
						Mohit Panjwani
					
				
			
			
				
	
			
			
			
						parent
						
							f34dac9d3f
						
					
				
				
					commit
					8ba84f68c7
				
			| @ -71,6 +71,9 @@ class CompanyController extends Controller | ||||
|  | ||||
|         $data = json_decode($request->company_logo); | ||||
|  | ||||
|         if (isset($request->is_company_logo_removed) && (bool) $request->is_company_logo_removed) { | ||||
|             $company->clearMediaCollection('logo'); | ||||
|         } | ||||
|         if ($data) { | ||||
|             $company = Company::find($request->header('company')); | ||||
|  | ||||
| @ -98,6 +101,9 @@ class CompanyController extends Controller | ||||
|     { | ||||
|         $user = auth()->user(); | ||||
|  | ||||
|         if (isset($request->is_admin_avatar_removed) && (bool) $request->is_admin_avatar_removed) { | ||||
|             $user->clearMediaCollection('admin_avatar'); | ||||
|         } | ||||
|         if ($user && $request->hasFile('admin_avatar')) { | ||||
|             $user->clearMediaCollection('admin_avatar'); | ||||
|  | ||||
|  | ||||
| @ -17,6 +17,9 @@ class ProfileController extends Controller | ||||
|  | ||||
|         $customer->update($request->validated()); | ||||
|  | ||||
|         if (isset($request->is_customer_avatar_removed) && (bool) $request->is_customer_avatar_removed) { | ||||
|             $customer->clearMediaCollection('customer_avatar'); | ||||
|         } | ||||
|         if ($customer && $request->hasFile('customer_avatar')) { | ||||
|             $customer->clearMediaCollection('customer_avatar'); | ||||
|  | ||||
|  | ||||
| @ -126,14 +126,14 @@ class Expense extends Model implements HasMedia | ||||
|     { | ||||
|         foreach (explode(' ', $search) as $term) { | ||||
|             $query->whereHas('category', function ($query) use ($term) { | ||||
|                 $query->where('name', 'LIKE', '%'.$term.'%'); | ||||
|                 $query->where('name', 'LIKE', '%' . $term . '%'); | ||||
|             }); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public function scopeWhereNotes($query, $search) | ||||
|     { | ||||
|         $query->where('notes', 'LIKE', '%'.$search.'%'); | ||||
|         $query->where('notes', 'LIKE', '%' . $search . '%'); | ||||
|     } | ||||
|  | ||||
|     public function scopeWhereCategory($query, $categoryId) | ||||
| @ -188,9 +188,9 @@ class Expense extends Model implements HasMedia | ||||
|     { | ||||
|         foreach (explode(' ', $search) as $term) { | ||||
|             $query->whereHas('category', function ($query) use ($term) { | ||||
|                 $query->where('name', 'LIKE', '%'.$term.'%'); | ||||
|                 $query->where('name', 'LIKE', '%' . $term . '%'); | ||||
|             }) | ||||
|                 ->orWhere('notes', 'LIKE', '%'.$term.'%'); | ||||
|                 ->orWhere('notes', 'LIKE', '%' . $term . '%'); | ||||
|         } | ||||
|     } | ||||
|  | ||||
| @ -262,6 +262,9 @@ class Expense extends Model implements HasMedia | ||||
|             ExchangeRateLog::addExchangeRateLog($this); | ||||
|         } | ||||
|  | ||||
|         if (isset($request->is_attachment_receipt_removed) && (bool) $request->is_attachment_receipt_removed) { | ||||
|             $this->clearMediaCollection('receipts'); | ||||
|         } | ||||
|         if ($request->hasFile('attachment_receipt')) { | ||||
|             $this->clearMediaCollection('receipts'); | ||||
|             $this->addMediaFromRequest('attachment_receipt')->toMediaCollection('receipts'); | ||||
|  | ||||
| @ -61,15 +61,15 @@ export const useExpenseStore = (useWindow = false) => { | ||||
|                 Object.assign(this.currentExpense, response.data.data) | ||||
|                 this.currentExpense.selectedCurrency = | ||||
|                   response.data.data.currency | ||||
|  | ||||
|                 if (response.data.data.attachment_receipt) { | ||||
|                 this.currentExpense.attachment_receipt = null | ||||
|                 if (response.data.data.attachment_receipt_url) { | ||||
|                   if ( | ||||
|                     utils.isImageFile( | ||||
|                       response.data.data.attachment_receipt_meta.mime_type | ||||
|                     ) | ||||
|                   ) { | ||||
|                     this.currentExpense.receiptFiles = [ | ||||
|                       { image: `/expenses/${id}/receipt` }, | ||||
|                       { image: `/reports/expenses/${id}/receipt?${response.data.data.attachment_receipt_meta.uuid}` }, | ||||
|                     ] | ||||
|                   } else { | ||||
|                     this.currentExpense.receiptFiles = [ | ||||
| @ -118,12 +118,13 @@ export const useExpenseStore = (useWindow = false) => { | ||||
|         }) | ||||
|       }, | ||||
|  | ||||
|       updateExpense({ id, data }) { | ||||
|       updateExpense({ id, data, isAttachmentReceiptRemoved }) { | ||||
|         const notificationStore = useNotificationStore() | ||||
|  | ||||
|         const formData = utils.toFormData(data) | ||||
|  | ||||
|         formData.append('_method', 'PUT') | ||||
|         formData.append('is_attachment_receipt_removed', isAttachmentReceiptRemoved) | ||||
|  | ||||
|         return new Promise((resolve) => { | ||||
|           axios.post(`/api/v1/expenses/${id}`, formData).then((response) => { | ||||
|  | ||||
| @ -21,7 +21,7 @@ | ||||
|  | ||||
|         <template #actions> | ||||
|           <BaseButton | ||||
|             v-if="isEdit && expenseStore.currentExpense.attachment_receipt" | ||||
|             v-if="isEdit && expenseStore.currentExpense.attachment_receipt_url" | ||||
|             :href="receiptDownloadUrl" | ||||
|             tag="a" | ||||
|             variant="primary-outline" | ||||
| @ -317,6 +317,7 @@ const globalStore = useGlobalStore() | ||||
| let isSaving = ref(false) | ||||
| let isFetchingInitialData = ref(false) | ||||
| const expenseValidationScope = 'newExpense' | ||||
| const isAttachmentReceiptRemoved = ref(false) | ||||
|  | ||||
| const rules = computed(() => { | ||||
|   return { | ||||
| @ -381,7 +382,7 @@ const pageTitle = computed(() => | ||||
| ) | ||||
|  | ||||
| const receiptDownloadUrl = computed(() => | ||||
|   isEdit.value ? `/expenses/${route.params.id}/download-receipt` : '' | ||||
|   isEdit.value ? `/reports/expenses/${route.params.id}/download-receipt` : '' | ||||
| ) | ||||
|  | ||||
| expenseStore.resetCurrentExpenseData() | ||||
| @ -395,6 +396,7 @@ function onFileInputChange(fileName, file) { | ||||
|  | ||||
| function onFileInputRemove() { | ||||
|   expenseStore.currentExpense.attachment_receipt = null | ||||
|   isAttachmentReceiptRemoved.value = true | ||||
| } | ||||
|  | ||||
| function openCategoryModal() { | ||||
| @ -460,11 +462,14 @@ async function submitForm() { | ||||
|       await expenseStore.updateExpense({ | ||||
|         id: route.params.id, | ||||
|         data: formData, | ||||
|         isAttachmentReceiptRemoved: isAttachmentReceiptRemoved.value | ||||
|       }) | ||||
|     } else { | ||||
|       await expenseStore.addExpense(formData) | ||||
|     } | ||||
|     isSaving.value = false | ||||
|     expenseStore.currentExpense.attachment_receipt = null | ||||
|     isAttachmentReceiptRemoved.value = false | ||||
|     router.push('/admin/expenses') | ||||
|   } catch (err) { | ||||
|     console.error(err) | ||||
|  | ||||
| @ -118,6 +118,7 @@ const { t } = useI18n() | ||||
| let isSaving = ref(false) | ||||
| let avatarFileBlob = ref(null) | ||||
| let imgFiles = ref([]) | ||||
| const isAdminAvatarRemoved = ref(false) | ||||
|  | ||||
| if (userStore.currentUser.avatar) { | ||||
|   imgFiles.value.push({ | ||||
| @ -170,6 +171,7 @@ function onFileInputChange(fileName, file) { | ||||
|  | ||||
| function onFileInputRemove() { | ||||
|   avatarFileBlob.value = null | ||||
|   isAdminAvatarRemoved.value = true | ||||
| } | ||||
|  | ||||
| async function updateUserData() { | ||||
| @ -209,12 +211,17 @@ async function updateUserData() { | ||||
|     if (response.data.data) { | ||||
|       isSaving.value = false | ||||
|  | ||||
|       if (avatarFileBlob.value) { | ||||
|       if (avatarFileBlob.value || isAdminAvatarRemoved.value) { | ||||
|         let avatarData = new FormData() | ||||
|  | ||||
|         if (avatarFileBlob.value) { | ||||
|           avatarData.append('admin_avatar', avatarFileBlob.value) | ||||
|         } | ||||
|         avatarData.append('is_admin_avatar_removed', isAdminAvatarRemoved.value) | ||||
|  | ||||
|         await userStore.uploadAvatar(avatarData) | ||||
|         avatarFileBlob.value = null | ||||
|         isAdminAvatarRemoved.value = false | ||||
|       } | ||||
|  | ||||
|       userForm.password = '' | ||||
|  | ||||
| @ -180,6 +180,7 @@ utils.mergeSettings(companyForm, { | ||||
| let previewLogo = ref([]) | ||||
| let logoFileBlob = ref(null) | ||||
| let logoFileName = ref(null) | ||||
| const isCompanyLogoRemoved = ref(false) | ||||
|  | ||||
| if (companyForm.logo) { | ||||
|   previewLogo.value.push({ | ||||
| @ -218,6 +219,7 @@ function onFileInputChange(fileName, file, fileCount, fileList) { | ||||
|  | ||||
| function onFileInputRemove() { | ||||
|   logoFileBlob.value = null | ||||
|   isCompanyLogoRemoved.value = true | ||||
| } | ||||
|  | ||||
| async function updateCompanyData() { | ||||
| @ -232,9 +234,10 @@ async function updateCompanyData() { | ||||
|   const res = await companyStore.updateCompany(companyForm) | ||||
|  | ||||
|   if (res.data.data) { | ||||
|     if (logoFileBlob.value) { | ||||
|     if (logoFileBlob.value || isCompanyLogoRemoved.value) { | ||||
|       let logoData = new FormData() | ||||
|  | ||||
|       if (logoFileBlob.value) { | ||||
|         logoData.append( | ||||
|           'company_logo', | ||||
|           JSON.stringify({ | ||||
| @ -242,8 +245,12 @@ async function updateCompanyData() { | ||||
|             data: logoFileBlob.value, | ||||
|           }) | ||||
|         ) | ||||
|       } | ||||
|       logoData.append('is_company_logo_removed', isCompanyLogoRemoved.value) | ||||
|  | ||||
|       await companyStore.updateCompanyLogo(logoData) | ||||
|       logoFileBlob.value = null | ||||
|       isCompanyLogoRemoved.value = false | ||||
|     } | ||||
|  | ||||
|     isSaving.value = false | ||||
|  | ||||
| @ -33,6 +33,7 @@ | ||||
|       :name="inputFieldName" | ||||
|       :accept="accept" | ||||
|       class="absolute z-10 w-full h-full opacity-0 cursor-pointer" | ||||
|       @click="$event.target.value=null" | ||||
|       @change=" | ||||
|         onChange( | ||||
|           $event.target.name, | ||||
| @ -557,6 +558,7 @@ function onAvatarRemove(image) { | ||||
|  | ||||
| function onFileRemove(index) { | ||||
|   localFiles.value.splice(index, 1) | ||||
|   emit('remove', index) | ||||
| } | ||||
|  | ||||
| function getDefaultAvatar() { | ||||
|  | ||||
| @ -153,6 +153,7 @@ let isSaving = ref(false) | ||||
| let avatarFileBlob = ref(null) | ||||
| let isShowPassword = ref(false) | ||||
| let isShowConfirmPassword = ref(false) | ||||
| const isCustomerAvatarRemoved = ref(false) | ||||
|  | ||||
| if (userStore.userForm.avatar) { | ||||
|   imgFiles.value.push({ | ||||
| @ -206,6 +207,7 @@ function onFileInputChange(fileName, file) { | ||||
|  | ||||
| function onFileInputRemove() { | ||||
|   avatarFileBlob.value = null | ||||
|   isCustomerAvatarRemoved.value = true | ||||
| } | ||||
|  | ||||
| function updateCustomerData() { | ||||
| @ -230,6 +232,7 @@ function updateCustomerData() { | ||||
|   if (avatarFileBlob.value) { | ||||
|     data.append('customer_avatar', avatarFileBlob.value) | ||||
|   } | ||||
|   data.append('is_customer_avatar_removed', isCustomerAvatarRemoved.value) | ||||
|  | ||||
|   userStore | ||||
|     .updateCurrentUser({ | ||||
| @ -243,6 +246,8 @@ function updateCustomerData() { | ||||
|           state.userForm.password = '' | ||||
|           state.userForm.confirm_password = '' | ||||
|         }) | ||||
|         avatarFileBlob.value = null | ||||
|         isCustomerAvatarRemoved.value = false | ||||
|       } | ||||
|     }) | ||||
|     .catch((error) => { | ||||
|  | ||||
		Reference in New Issue
	
	Block a user