mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-21 04:04:07 +00:00
2 lines
2.7 KiB
JavaScript
2 lines
2.7 KiB
JavaScript
import{G as V,E as D,f as v,k as i,z as l,aD as F,r as d,aM as G,o as x,m as N,w as h,c as A,ac as j,a as p,J as z,l as s,K as C,b as E,t as B}from"./main-WMXHPsTs.js";import{u as L}from"./exchange-rate-dmwjabGR.js";const O={key:0},U={class:"text-gray-500 sm:text-sm"},q={class:"text-gray-400 text-xs mt-2 font-light"},M={__name:"ExchangeRateConverter",props:{v:{type:Object,default:null},isLoading:{type:Boolean,default:!1},store:{type:Object,default:null},storeProp:{type:String,default:""},isEdit:{type:Boolean,default:!1},customerCurrency:{type:[String,Number],default:null}},setup(r){const e=r,g=V(),P=D(),m=L(),f=v(!1);let n=v(!1);g.fetchCurrencies();const o=i(()=>P.selectedCompanyCurrency),c=i(()=>g.currencies.find(t=>t.id===e.store[e.storeProp].currency_id)),b=i(()=>o.value.id!==e.customerCurrency);l(()=>e.store[e.storeProp].customer,t=>{w(t)},{deep:!0}),l(()=>e.store[e.storeProp].currency_id,t=>{$(t)},{immediate:!0}),l(()=>e.customerCurrency,t=>{t&&e.isEdit&&R()},{immediate:!0});function R(){b.value&&m.checkForActiveProvider(e.customerCurrency).then(t=>{t.data.success&&(f.value=!0)})}function w(t){t?e.store[e.storeProp].currency_id=t.currency.id:e.store[e.storeProp].currency_id=o.value.id}async function $(t){t!==o.value.id?(!e.isEdit&&t&&await y(t),e.store.showExchangeRate=!0):e.store.showExchangeRate=!1}function y(t){n.value=!0,m.getCurrentExchangeRate(t).then(a=>{a.data&&!a.data.error?e.store[e.storeProp].exchange_rate=a.data.exchangeRate[0]:e.store[e.storeProp].exchange_rate="",n.value=!1}).catch(a=>{n.value=!1})}return F(()=>{e.store.showExchangeRate=!1}),(t,a)=>{const k=d("BaseIcon"),S=d("BaseInput"),I=d("BaseInputGroup"),_=G("tooltip");return r.store.showExchangeRate&&c.value?(x(),N(I,{key:0,"content-loading":s(n)&&!r.isEdit,label:t.$t("settings.exchange_rate.exchange_rate"),error:r.v.exchange_rate.$error&&r.v.exchange_rate.$errors[0].$message,required:""},{labelRight:h(()=>[f.value&&r.isEdit?(x(),A("div",O,[j(p(k,{name:"RefreshIcon",class:z(`h-4 w-4 text-primary-500 cursor-pointer outline-none ${s(n)?" animate-spin rotate-180 cursor-not-allowed pointer-events-none ":""}`),onClick:a[0]||(a[0]=u=>y(r.customerCurrency))},null,8,["class"]),[[_,{content:"Fetch Latest Exchange rate"}]])])):C("",!0)]),default:h(()=>[p(S,{modelValue:r.store[r.storeProp].exchange_rate,"onUpdate:modelValue":a[1]||(a[1]=u=>r.store[r.storeProp].exchange_rate=u),"content-loading":s(n)&&!r.isEdit,addon:`1 ${c.value.code} =`,disabled:s(n),onInput:a[2]||(a[2]=u=>r.v.exchange_rate.$touch())},{right:h(()=>[E("span",U,B(o.value.code),1)]),_:1},8,["modelValue","content-loading","addon","disabled"]),E("span",q,B(t.$t("settings.exchange_rate.exchange_help_text",{currency:c.value.code,baseCurrency:o.value.code})),1)]),_:1},8,["content-loading","label","error"])):C("",!0)}}};export{M as _};
|