2 lines
9.7 KiB
JavaScript
2 lines
9.7 KiB
JavaScript
import{J as le,f as ue,u as me,a6 as ie,ac as ce,C as de,D as ye,ao as pe,E as _e,a3 as ve,e as fe,g as S,F as Pe,l as I,h as $,i as w,aI as ge,ad as be,V as Be,k as $e,al as he,aB as Ie,r as u,o as M,c as Ce,a as r,w as s,b as h,m as e,n as k,H as G,I as N,q,t as P,p as Ve,s as Se,L as we}from"./main-vzIkKseS.js";import{_ as Me}from"./ExchangeRateConverter-ZwwFqeKM.js";import{u as qe}from"./payment-ALr-TD5m.js";import{_ as ke}from"./SelectNotePopup-DKlwyGyu.js";import{_ as Ne}from"./CreateCustomFields-hHeYNhLY.js";import{_ as Ue}from"./PaymentModeModal-OW7LJo93.js";import"./exchange-rate--sifpuzz.js";import"./NoteModal-rdu-Hccj.js";import"./dynamic-import-helper-0gtGTknh.js";const De=["onSubmit"],Ae={class:"absolute left-3.5"},Ee={class:"relative w-full"},Fe={class:"relative mt-6"},xe={class:"z-20 float-right text-sm font-semibold leading-5 text-primary-400"},Ge={class:"mb-4 text-sm font-medium text-gray-800"},We={setup(Le){const i=le(),L=ue(),t=qe();me();const C=ie();ce(),de();const R=ye(),U=pe();_e();const D=ve("utils"),{t:y}=fe();let g=S(!1),V=S(!1),p=S([]);const _=S(null),A="newEstimate",H=Pe(["customer","company","customerCustom","payment","paymentCustom"]),b=I({get:()=>t.currentPayment.amount/100,set:a=>{t.currentPayment.amount=Math.round(a*100)}}),l=I(()=>t.isFetchingInitialData),c=I(()=>i.name==="payments.edit"),E=I(()=>c.value?y("payments.edit_payment"):y("payments.new_payment")),j=I(()=>({currentPayment:{customer_id:{required:$.withMessage(y("validation.required"),w)},payment_date:{required:$.withMessage(y("validation.required"),w)},amount:{required:$.withMessage(y("validation.required"),w),between:$.withMessage(y("validation.payment_greater_than_due_amount"),ge(0,t.currentPayment.maxPayableAmount))},exchange_rate:{required:be(function(){return $.withMessage(y("validation.required"),w),t.showExchangeRate}),decimal:$.withMessage(y("validation.valid_exchange_rate"),Be)}}})),m=$e(j,t,{$scope:A});he(()=>{t.currentPayment.customer_id&&O(t.currentPayment.customer_id),i.query.customer&&(t.currentPayment.customer_id=i.query.customer)}),t.resetCurrentPayment(),i.query.customer&&(t.currentPayment.customer_id=i.query.customer),t.fetchPaymentInitialData(c.value),i.params.id&&!c.value&&J();async function z(){R.openModal({title:y("settings.payment_modes.add_payment_mode"),componentName:"PaymentModeModal"})}function T(a){t.currentPayment.notes=""+a.notes}async function J(){var n;let a=await U.fetchInvoice((n=i==null?void 0:i.params)==null?void 0:n.id);t.currentPayment.customer_id=a.data.data.customer.id,t.currentPayment.invoice_id=a.data.data.id}async function K(a){a&&(_.value=p.value.find(n=>n.id===a),b.value=_.value.due_amount/100,t.currentPayment.maxPayableAmount=_.value.due_amount)}function O(a){if(a){let n={customer_id:a,status:"DUE",limit:"all"};c.value&&(n.status=""),V.value=!0,Promise.all([U.fetchInvoices(n),C.fetchCustomer(a)]).then(async([d,v])=>{d&&(p.value=[...d.data.data]),v&&v.data&&(t.currentPayment.selectedCustomer=v.data.data,t.currentPayment.customer=v.data.data,t.currentPayment.currency=v.data.data.currency,c.value&&!C.editCustomer&&t.currentPayment.customer_id&&(C.editCustomer=v.data.data)),t.currentPayment.invoice_id&&(_.value=p.value.find(f=>f.id===t.currentPayment.invoice_id),t.currentPayment.maxPayableAmount=_.value.due_amount+t.currentPayment.amount,b.value===0&&(b.value=_.value.due_amount/100)),c.value&&(p.value=p.value.filter(f=>f.due_amount>0||f.id==t.currentPayment.invoice_id)),V.value=!1}).catch(d=>{V.value=!1,console.error(d,"error")})}}Ie(()=>{t.resetCurrentPayment(),p.value=[],C.editCustomer=null});async function Q(){if(m.value.$touch(),m.value.$invalid)return!1;g.value=!0;let a={...t.currentPayment},n=null;try{n=await(c.value?t.updatePayment:t.addPayment)(a),L.push(`/admin/payments/${n.data.data.id}/view`)}catch{g.value=!1}}function W(a){let n={userId:a};i.params.id&&(n.model_id=i.params.id),t.currentPayment.invoice_id=_.value=null,t.currentPayment.amount=0,p.value=[],t.getNextNumber(n,!0)}return(a,n)=>{const d=u("BaseBreadcrumbItem"),v=u("BaseBreadcrumb"),f=u("BaseIcon"),F=u("BaseButton"),X=u("BasePageHeader"),Y=u("BaseDatePicker"),B=u("BaseInputGroup"),Z=u("BaseInput"),ee=u("BaseCustomerSelectInput"),x=u("BaseMultiselect"),te=u("BaseMoney"),ae=u("BaseSelectAction"),ne=u("BaseInputGrid"),oe=u("BaseCustomInput"),re=u("BaseCard"),se=u("BasePage");return M(),Ce(we,null,[r(Ue),r(se,{class:"relative payment-create"},{default:s(()=>[h("form",{action:"",onSubmit:Se(Q,["prevent"])},[r(X,{title:e(E),class:"mb-5"},{actions:s(()=>[r(F,{loading:e(g),disabled:e(g),variant:"primary",type:"submit",class:"hidden sm:flex"},{left:s(o=>[e(g)?N("",!0):(M(),k(f,{key:0,name:"SaveIcon",class:G(o.class)},null,8,["class"]))]),default:s(()=>[q(" "+P(e(c)?a.$t("payments.update_payment"):a.$t("payments.save_payment")),1)]),_:1},8,["loading","disabled"])]),default:s(()=>[r(v,null,{default:s(()=>[r(d,{title:a.$t("general.home"),to:"/admin/dashboard"},null,8,["title"]),r(d,{title:a.$tc("payments.payment",2),to:"/admin/payments"},null,8,["title"]),r(d,{title:e(E),to:"#",active:""},null,8,["title"])]),_:1})]),_:1},8,["title"]),r(re,null,{default:s(()=>[r(ne,null,{default:s(()=>[r(B,{label:a.$t("payments.date"),"content-loading":e(l),required:"",error:e(m).currentPayment.payment_date.$error&&e(m).currentPayment.payment_date.$errors[0].$message},{default:s(()=>[r(Y,{modelValue:e(t).currentPayment.payment_date,"onUpdate:modelValue":[n[0]||(n[0]=o=>e(t).currentPayment.payment_date=o),n[1]||(n[1]=o=>e(m).currentPayment.payment_date.$touch())],"content-loading":e(l),"calendar-button":!0,"calendar-button-icon":"calendar",invalid:e(m).currentPayment.payment_date.$error},null,8,["modelValue","content-loading","invalid"])]),_:1},8,["label","content-loading","error"]),r(B,{label:a.$t("payments.payment_number"),"content-loading":e(l),required:""},{default:s(()=>[r(Z,{modelValue:e(t).currentPayment.payment_number,"onUpdate:modelValue":n[2]||(n[2]=o=>e(t).currentPayment.payment_number=o),"content-loading":e(l)},null,8,["modelValue","content-loading"])]),_:1},8,["label","content-loading"]),r(B,{label:a.$t("payments.customer"),error:e(m).currentPayment.customer_id.$error&&e(m).currentPayment.customer_id.$errors[0].$message,"content-loading":e(l),required:""},{default:s(()=>[e(l)?N("",!0):(M(),k(ee,{key:0,modelValue:e(t).currentPayment.customer_id,"onUpdate:modelValue":[n[3]||(n[3]=o=>e(t).currentPayment.customer_id=o),n[4]||(n[4]=o=>W(e(t).currentPayment.customer_id))],"content-loading":e(l),invalid:e(m).currentPayment.customer_id.$error,placeholder:a.$t("customers.select_a_customer"),"show-action":""},null,8,["modelValue","content-loading","invalid","placeholder"]))]),_:1},8,["label","error","content-loading"]),r(B,{"content-loading":e(l),label:a.$t("payments.invoice"),"help-text":_.value?`Due Amount: ${e(t).currentPayment.maxPayableAmount/100}`:""},{default:s(()=>[r(x,{modelValue:e(t).currentPayment.invoice_id,"onUpdate:modelValue":n[5]||(n[5]=o=>e(t).currentPayment.invoice_id=o),"content-loading":e(l),"value-prop":"id","track-by":"invoice_number",label:"invoice_number",options:e(p),loading:e(V),placeholder:a.$t("invoices.select_invoice"),onSelect:K},{singlelabel:s(({value:o})=>[h("div",Ae,P(o.invoice_number)+" ("+P(e(D).formatMoney(o.total,o.customer.currency))+") ",1)]),option:s(({option:o})=>[q(P(o.invoice_number)+" ("+P(e(D).formatMoney(o.total,o.customer.currency))+") ",1)]),_:1},8,["modelValue","content-loading","options","loading","placeholder"])]),_:1},8,["content-loading","label","help-text"]),r(B,{label:a.$t("payments.amount"),"content-loading":e(l),error:e(m).currentPayment.amount.$error&&e(m).currentPayment.amount.$errors[0].$message,required:""},{default:s(()=>[h("div",Ee,[r(te,{key:e(t).currentPayment.currency,modelValue:e(b),"onUpdate:modelValue":[n[6]||(n[6]=o=>Ve(b)?b.value=o:null),n[7]||(n[7]=o=>e(m).currentPayment.amount.$touch())],currency:e(t).currentPayment.currency,"content-loading":e(l),invalid:e(m).currentPayment.amount.$error},null,8,["modelValue","currency","content-loading","invalid"])])]),_:1},8,["label","content-loading","error"]),r(B,{"content-loading":e(l),label:a.$t("payments.payment_mode")},{default:s(()=>[r(x,{modelValue:e(t).currentPayment.payment_method_id,"onUpdate:modelValue":n[8]||(n[8]=o=>e(t).currentPayment.payment_method_id=o),"content-loading":e(l),label:"name","value-prop":"id","track-by":"name",options:e(t).paymentModes,placeholder:a.$t("payments.select_payment_mode"),searchable:""},{action:s(()=>[r(ae,{onClick:z},{default:s(()=>[r(f,{name:"PlusIcon",class:"h-4 mr-2 -ml-2 text-center text-primary-400"}),q(" "+P(a.$t("settings.payment_modes.add_payment_mode")),1)]),_:1})]),_:1},8,["modelValue","content-loading","options","placeholder"])]),_:1},8,["content-loading","label"]),r(Me,{store:e(t),"store-prop":"currentPayment",v:e(m).currentPayment,"is-loading":e(l),"is-edit":e(c),"customer-currency":e(t).currentPayment.currency_id},null,8,["store","v","is-loading","is-edit","customer-currency"])]),_:1}),r(Ne,{type:"Payment","is-edit":e(c),"is-loading":e(l),store:e(t),"store-prop":"currentPayment","custom-field-scope":A,class:"mt-6"},null,8,["is-edit","is-loading","store"]),h("div",Fe,[h("div",xe,[r(ke,{type:"Payment",onSelect:T})]),h("label",Ge,P(a.$t("estimates.notes")),1),r(oe,{modelValue:e(t).currentPayment.notes,"onUpdate:modelValue":n[9]||(n[9]=o=>e(t).currentPayment.notes=o),"content-loading":e(l),fields:e(H),class:"mt-1"},null,8,["modelValue","content-loading","fields"])]),r(F,{loading:e(g),"content-loading":e(l),variant:"primary",type:"submit",class:"flex justify-center w-full mt-4 sm:hidden md:hidden"},{left:s(o=>[e(g)?N("",!0):(M(),k(f,{key:0,name:"SaveIcon",class:G(o.class)},null,8,["class"]))]),default:s(()=>[q(" "+P(e(c)?a.$t("payments.update_payment"):a.$t("payments.save_payment")),1)]),_:1},8,["loading","content-loading"])]),_:1})],40,De)]),_:1})],64)}}};export{We as default};
|