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