Files
crater/public/build/assets/Create.8a84f9c5.js
2022-01-28 07:11:54 +00:00

2 lines
9.9 KiB
JavaScript

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