Files
crater/public/build/assets/Create.1d6bd807.js
Mohit Panjwani 18507ddb6f new build 606
2022-03-06 12:39:21 +05:30

2 lines
10 KiB
JavaScript

var ce=Object.defineProperty;var R=Object.getOwnPropertySymbols;var de=Object.prototype.hasOwnProperty,ye=Object.prototype.propertyIsEnumerable;var L=(_,s,c)=>s in _?ce(_,s,{enumerable:!0,configurable:!0,writable:!0,value:c}):_[s]=c,T=(_,s)=>{for(var c in s||(s={}))de.call(s,c)&&L(_,c,s[c]);if(R)for(var c of R(s))ye.call(s,c)&&L(_,c,s[c]);return _};import{G as pe,aN as _e,ah as ve,J as fe,B as w,a0 as Pe,k as S,L as C,M as q,aX as ge,O as be,aP as Be,T as $e,a7 as he,b1 as Ce,r as m,o as k,e as Ie,f as r,w as l,h as I,u as e,l as j,m as z,j as U,i as N,t as b,x as Se,U as Ve,F as Me}from"./vendor.d12b5734.js";import{_ as we}from"./ExchangeRateConverter.d865db6a.js";import{u as qe,l as ke,m as Ne,b as je,c as Ue,i as xe,d as De}from"./main.465728e1.js";import{u as Ae}from"./payment.93619753.js";import{_ as Ee}from"./SelectNotePopup.2e678c03.js";import{_ as Fe}from"./CreateCustomFields.c1c460e4.js";import{_ as Ge}from"./PaymentModeModal.a0b58785.js";import"./exchange-rate.85b564e2.js";import"./NoteModal.ebe10cf0.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 V=ke();Ne(),je();const H=Ue(),x=xe();De();const D=ve("utils"),{t:p}=fe();let B=w(!1),M=w(!1),v=w([]);const f=w(null),A="newEstimate",J=Pe(["customer","company","customerCustom","payment","paymentCustom"]),$=S({get:()=>t.currentPayment.amount/100,set:a=>{t.currentPayment.amount=Math.round(a*100)}}),u=S(()=>t.isFetchingInitialData),d=S(()=>s.name==="payments.edit"),E=S(()=>d.value?p("payments.edit_payment"):p("payments.new_payment")),O=S(()=>({currentPayment:{customer_id:{required:C.withMessage(p("validation.required"),q)},payment_date:{required:C.withMessage(p("validation.required"),q)},amount:{required:C.withMessage(p("validation.required"),q),between:C.withMessage(p("validation.payment_greater_than_due_amount"),ge(0,t.currentPayment.maxPayableAmount))},exchange_rate:{required:be(function(){return C.withMessage(p("validation.required"),q),t.showExchangeRate}),decimal:C.withMessage(p("validation.valid_exchange_rate"),Be)}}})),i=$e(O,t,{$scope:A});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 x.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=""),M.value=!0,Promise.all([x.fetchInvoices(n),V.fetchCustomer(a)]).then(async([y,P])=>{y&&(v.value=[...y.data.data]),P&&P.data&&(t.currentPayment.selectedCustomer=P.data.data,t.currentPayment.customer=P.data.data,t.currentPayment.currency=P.data.data.currency,d.value&&!V.editCustomer&&t.currentPayment.customer_id&&(V.editCustomer=P.data.data)),t.currentPayment.invoice_id&&(f.value=v.value.find(g=>g.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(g=>g.due_amount>0||g.id==t.currentPayment.invoice_id)),M.value=!1}).catch(y=>{M.value=!1,console.error(y,"error")})}}Ce(()=>{t.resetCurrentPayment(),v.value=[],V.editCustomer=null});async function Z(){if(i.value.$touch(),i.value.$invalid)return!1;B.value=!0;let a=T({},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"),P=m("BaseBreadcrumb"),g=m("BaseIcon"),F=m("BaseButton"),te=m("BasePageHeader"),ae=m("BaseDatePicker"),h=m("BaseInputGroup"),ne=m("BaseInput"),oe=m("BaseCustomerSelectInput"),G=m("BaseMultiselect"),re=m("BaseMoney"),se=m("BaseSelectAction"),le=m("BaseInputGrid"),ue=m("BaseCustomInput"),me=m("BaseCard"),ie=m("BasePage");return k(),Ie(Me,null,[r(Ge),r(ie,{class:"relative payment-create"},{default:l(()=>[I("form",{action:"",onSubmit:Ve(Z,["prevent"])},[r(te,{title:e(E),class:"mb-5"},{actions:l(()=>[r(F,{loading:e(B),disabled:e(B),variant:"primary",type:"submit",class:"hidden sm:flex"},{left:l(o=>[e(B)?U("",!0):(k(),j(g,{key:0,name:"SaveIcon",class:z(o.class)},null,8,["class"]))]),default:l(()=>[N(" "+b(e(d)?a.$t("payments.update_payment"):a.$t("payments.save_payment")),1)]),_:1},8,["loading","disabled"])]),default:l(()=>[r(P,null,{default:l(()=>[r(y,{title:a.$t("general.home"),to:"/admin/dashboard"},null,8,["title"]),r(y,{title:a.$tc("payments.payment",2),to:"/admin/payments"},null,8,["title"]),r(y,{title:e(E),to:"#",active:""},null,8,["title"])]),_:1})]),_:1},8,["title"]),r(me,null,{default:l(()=>[r(le,null,{default:l(()=>[r(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(()=>[r(ae,{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(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"]),r(h,{label:a.$t("payments.payment_number"),"content-loading":e(u),required:""},{default:l(()=>[r(ne,{modelValue:e(t).currentPayment.payment_number,"onUpdate:modelValue":n[2]||(n[2]=o=>e(t).currentPayment.payment_number=o),"content-loading":e(u)},null,8,["modelValue","content-loading"])]),_:1},8,["label","content-loading"]),r(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(()=>[e(u)?U("",!0):(k(),j(oe,{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=>ee(e(t).currentPayment.customer_id))],"content-loading":e(u),invalid:e(i).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(h,{"content-loading":e(u),label:a.$t("payments.invoice"),"help-text":f.value?`Due Amount: ${e(t).currentPayment.maxPayableAmount/100}`:""},{default:l(()=>[r(G,{modelValue:e(t).currentPayment.invoice_id,"onUpdate:modelValue":n[5]||(n[5]=o=>e(t).currentPayment.invoice_id=o),"content-loading":e(u),"value-prop":"id","track-by":"invoice_number",label:"invoice_number",options:e(v),loading:e(M),placeholder:a.$t("invoices.select_invoice"),onSelect:W},{singlelabel:l(({value:o})=>[I("div",Le,b(o.invoice_number)+" ("+b(e(D).formatMoney(o.total,o.customer.currency))+") ",1)]),option:l(({option:o})=>[N(b(o.invoice_number)+" ("+b(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(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(()=>[I("div",Te,[r(re,{key:e(t).currentPayment.currency,modelValue:e($),"onUpdate:modelValue":[n[6]||(n[6]=o=>Se($)?$.value=o:null),n[7]||(n[7]=o=>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"]),r(h,{"content-loading":e(u),label:a.$t("payments.payment_mode")},{default:l(()=>[r(G,{modelValue:e(t).currentPayment.payment_method_id,"onUpdate:modelValue":n[8]||(n[8]=o=>e(t).currentPayment.payment_method_id=o),"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(()=>[r(se,{onClick:X},{default:l(()=>[r(g,{name:"PlusIcon",class:"h-4 mr-2 -ml-2 text-center text-primary-400"}),N(" "+b(a.$t("settings.payment_modes.add_payment_mode")),1)]),_:1})]),_:1},8,["modelValue","content-loading","options","placeholder"])]),_:1},8,["content-loading","label"]),r(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}),r(Fe,{type:"Payment","is-edit":e(d),"is-loading":e(u),store:e(t),"store-prop":"currentPayment","custom-field-scope":A,class:"mt-6"},null,8,["is-edit","is-loading","store"]),I("div",ze,[I("div",He,[r(Ee,{type:"Payment",onSelect:K})]),I("label",Je,b(a.$t("estimates.notes")),1),r(ue,{modelValue:e(t).currentPayment.notes,"onUpdate:modelValue":n[9]||(n[9]=o=>e(t).currentPayment.notes=o),"content-loading":e(u),fields:e(J),class:"mt-1"},null,8,["modelValue","content-loading","fields"])]),r(F,{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(o=>[e(B)?U("",!0):(k(),j(g,{key:0,name:"SaveIcon",class:z(o.class)},null,8,["class"]))]),default:l(()=>[N(" "+b(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};