ruạṛ
import{bq as oe,r as re,e as T,bh as j,ea as ue,o as fe,aa as xe,bc as te,h as _e,$ as pe,T as Fe,u as be,bJ as ve,z as me,x as ye,d as ge,a2 as Ce,p as K,c as u,W as Se,bP as Ae,dM as we,j as L,C as Be,bv as E,cp as Ne,ct as ie,aA as ae,c1 as Z,G as q,J as se,eb as ce,c2 as U,cs as ne,I as Ee,cu as ee,bA as le}from"./bundle.9abe88c8.js";import{u as $e}from"./payments-0a3eee62.js";import{u as Oe,C as Ie}from"./usePaymentTypes-db32e981.js";import{p as Ve}from"./atoms-f5ce5583.js";/** * Invoice Ninja (https://invoiceninja.com). * * @link https://github.com/invoiceninja/invoiceninja source repository * * @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com) * * @license https://www.elastic.co/licensing/elastic-license */function Re(){const A=oe();return{find:F=>A.fetchQuery(["/api/v1/credits",F],()=>re("GET",T("/api/v1/credits/:id?include=client&sort=id|asc",{id:F})).then(x=>x.data.data),{staleTime:1/0})}}/** * Invoice Ninja (https://invoiceninja.com). * * @link https://github.com/invoiceninja/invoiceninja source repository * * @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com) * * @license https://www.elastic.co/licensing/elastic-license */function Me(){const A=oe();return{find:F=>A.fetchQuery(["/api/v1/invoices",F],()=>re("GET",T("/api/v1/invoices/:id?include=client.group_settings&sort=id|asc",{id:F})).then(x=>x.data.data),{staleTime:1/0})}}/** * Invoice Ninja (https://invoiceninja.com). * * @link https://github.com/invoiceninja/invoiceninja source repository * * @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com) * * @license https://www.elastic.co/licensing/elastic-license */function He(A){const{payment:f,setPayment:F}=A;return{handleCreditChange:x=>{F(y=>y&&{...y,credits:[...y.credits,{_id:j(),amount:x.balance>0?x.balance:x.amount,credit_id:x.id}]})},handleExistingCreditChange:(x,y)=>{const h={...f};h.credits[y]={_id:j(),amount:x.balance>0?x.balance:x.amount,credit_id:x.id},F({...h})},handleCreditInputChange:(x,y)=>{const h={...f};h.credits[x].amount=y,F({...h})},handleDeletingCredit:x=>{F(y=>y&&{...y,credits:y.credits.filter(h=>h._id!==x)})}}}/** * Invoice Ninja (https://invoiceninja.com). * * @link https://github.com/invoiceninja/invoiceninja source repository * * @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com) * * @license https://www.elastic.co/licensing/elastic-license */function Te(A){const{payment:f,setPayment:F}=A;return{handleInvoiceChange:x=>{F(y=>y&&{...y,invoices:[...y.invoices,{_id:j(),amount:x.balance>0?x.balance:x.amount,invoice_id:x.id}]})},handleExistingInvoiceChange:(x,y)=>{const h={...f};h.invoices[y]={_id:j(),amount:x.balance>0?x.balance:x.amount,invoice_id:x.id},F({...h})},handleInvoiceInputChange:(x,y)=>{const h={...f};h.invoices[x].amount=y,F({...h})},handleDeletingInvoice:x=>{F(y=>y&&{...y,invoices:y.invoices.filter(h=>h._id!==x)})}}}var de={exports:{}};const ke={},Pe=Object.freeze(Object.defineProperty({__proto__:null,default:ke},Symbol.toStringTag,{value:"Module"})),he=ue(Pe);/** * [js-sha256]{@link https://github.com/emn178/js-sha256} * * @version 0.11.0 * @author Chen, Yi-Cyuan [emn178@gmail.com] * @copyright Chen, Yi-Cyuan 2014-2024 * @license MIT */(function(A){(function(){var f="input is invalid type",F=typeof window=="object",x=F?window:{};x.JS_SHA256_NO_WINDOW&&(F=!1);var y=!F&&typeof self=="object",h=!x.JS_SHA256_NO_NODE_JS&&typeof process=="object"&&process.versions&&process.versions.node;h?x=fe:y&&(x=self);var J=!x.JS_SHA256_NO_COMMON_JS&&!0&&A.exports,R=!x.JS_SHA256_NO_ARRAY_BUFFER&&typeof ArrayBuffer<"u",r="0123456789abcdef".split(""),k=[-2147483648,8388608,32768,128],i=[24,16,8,0],N=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],l=["hex","array","digest","arrayBuffer"],C=[];(x.JS_SHA256_NO_NODE_JS||!Array.isArray)&&(Array.isArray=function(e){return Object.prototype.toString.call(e)==="[object Array]"}),R&&(x.JS_SHA256_NO_ARRAY_BUFFER_IS_VIEW||!ArrayBuffer.isView)&&(ArrayBuffer.isView=function(e){return typeof e=="object"&&e.buffer&&e.buffer.constructor===ArrayBuffer});var z=function(e,c){return function(o){return new S(c,!0).update(o)[e]()}},G=function(e){var c=z("hex",e);h&&(c=Q(c,e)),c.create=function(){return new S(e)},c.update=function(d){return c.create().update(d)};for(var o=0;o<l.length;++o){var s=l[o];c[s]=z(s,e)}return c},Q=function(e,c){var o=he,s=he.Buffer,d=c?"sha224":"sha256",n;s.from&&!x.JS_SHA256_NO_BUFFER_FROM?n=s.from:n=function(t){return new s(t)};var b=function(t){if(typeof t=="string")return o.createHash(d).update(t,"utf8").digest("hex");if(t==null)throw new Error(f);return t.constructor===ArrayBuffer&&(t=new Uint8Array(t)),Array.isArray(t)||ArrayBuffer.isView(t)||t.constructor===s?o.createHash(d).update(n(t)).digest("hex"):e(t)};return b},Y=function(e,c){return function(o,s){return new M(o,c,!0).update(s)[e]()}},X=function(e){var c=Y("hex",e);c.create=function(d){return new M(d,e)},c.update=function(d,n){return c.create(d).update(n)};for(var o=0;o<l.length;++o){var s=l[o];c[s]=Y(s,e)}return c};function S(e,c){c?(C[0]=C[16]=C[1]=C[2]=C[3]=C[4]=C[5]=C[6]=C[7]=C[8]=C[9]=C[10]=C[11]=C[12]=C[13]=C[14]=C[15]=0,this.blocks=C):this.blocks=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],e?(this.h0=3238371032,this.h1=914150663,this.h2=812702999,this.h3=4144912697,this.h4=4290775857,this.h5=1750603025,this.h6=1694076839,this.h7=3204075428):(this.h0=1779033703,this.h1=3144134277,this.h2=1013904242,this.h3=2773480762,this.h4=1359893119,this.h5=2600822924,this.h6=528734635,this.h7=1541459225),this.block=this.start=this.bytes=this.hBytes=0,this.finalized=this.hashed=!1,this.first=!0,this.is224=e}S.prototype.update=function(e){if(!this.finalized){var c,o=typeof e;if(o!=="string"){if(o==="object"){if(e===null)throw new Error(f);if(R&&e.constructor===ArrayBuffer)e=new Uint8Array(e);else if(!Array.isArray(e)&&(!R||!ArrayBuffer.isView(e)))throw new Error(f)}else throw new Error(f);c=!0}for(var s,d=0,n,b=e.length,t=this.blocks;d<b;){if(this.hashed&&(this.hashed=!1,t[0]=this.block,this.block=t[16]=t[1]=t[2]=t[3]=t[4]=t[5]=t[6]=t[7]=t[8]=t[9]=t[10]=t[11]=t[12]=t[13]=t[14]=t[15]=0),c)for(n=this.start;d<b&&n<64;++d)t[n>>>2]|=e[d]<<i[n++&3];else for(n=this.start;d<b&&n<64;++d)s=e.charCodeAt(d),s<128?t[n>>>2]|=s<<i[n++&3]:s<2048?(t[n>>>2]|=(192|s>>>6)<<i[n++&3],t[n>>>2]|=(128|s&63)<<i[n++&3]):s<55296||s>=57344?(t[n>>>2]|=(224|s>>>12)<<i[n++&3],t[n>>>2]|=(128|s>>>6&63)<<i[n++&3],t[n>>>2]|=(128|s&63)<<i[n++&3]):(s=65536+((s&1023)<<10|e.charCodeAt(++d)&1023),t[n>>>2]|=(240|s>>>18)<<i[n++&3],t[n>>>2]|=(128|s>>>12&63)<<i[n++&3],t[n>>>2]|=(128|s>>>6&63)<<i[n++&3],t[n>>>2]|=(128|s&63)<<i[n++&3]);this.lastByteIndex=n,this.bytes+=n-this.start,n>=64?(this.block=t[16],this.start=n-64,this.hash(),this.hashed=!0):this.start=n}return this.bytes>4294967295&&(this.hBytes+=this.bytes/4294967296<<0,this.bytes=this.bytes%4294967296),this}},S.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var e=this.blocks,c=this.lastByteIndex;e[16]=this.block,e[c>>>2]|=k[c&3],this.block=e[16],c>=56&&(this.hashed||this.hash(),e[0]=this.block,e[16]=e[1]=e[2]=e[3]=e[4]=e[5]=e[6]=e[7]=e[8]=e[9]=e[10]=e[11]=e[12]=e[13]=e[14]=e[15]=0),e[14]=this.hBytes<<3|this.bytes>>>29,e[15]=this.bytes<<3,this.hash()}},S.prototype.hash=function(){var e=this.h0,c=this.h1,o=this.h2,s=this.h3,d=this.h4,n=this.h5,b=this.h6,t=this.h7,v=this.blocks,g,w,B,$,m,O,I,H,P,a,_;for(g=16;g<64;++g)m=v[g-15],w=(m>>>7|m<<25)^(m>>>18|m<<14)^m>>>3,m=v[g-2],B=(m>>>17|m<<15)^(m>>>19|m<<13)^m>>>10,v[g]=v[g-16]+w+v[g-7]+B<<0;for(_=c&o,g=0;g<64;g+=4)this.first?(this.is224?(H=300032,m=v[0]-1413257819,t=m-150054599<<0,s=m+24177077<<0):(H=704751109,m=v[0]-210244248,t=m-1521486534<<0,s=m+143694565<<0),this.first=!1):(w=(e>>>2|e<<30)^(e>>>13|e<<19)^(e>>>22|e<<10),B=(d>>>6|d<<26)^(d>>>11|d<<21)^(d>>>25|d<<7),H=e&c,$=H^e&o^_,I=d&n^~d&b,m=t+B+I+N[g]+v[g],O=w+$,t=s+m<<0,s=m+O<<0),w=(s>>>2|s<<30)^(s>>>13|s<<19)^(s>>>22|s<<10),B=(t>>>6|t<<26)^(t>>>11|t<<21)^(t>>>25|t<<7),P=s&e,$=P^s&c^H,I=t&d^~t&n,m=b+B+I+N[g+1]+v[g+1],O=w+$,b=o+m<<0,o=m+O<<0,w=(o>>>2|o<<30)^(o>>>13|o<<19)^(o>>>22|o<<10),B=(b>>>6|b<<26)^(b>>>11|b<<21)^(b>>>25|b<<7),a=o&s,$=a^o&e^P,I=b&t^~b&d,m=n+B+I+N[g+2]+v[g+2],O=w+$,n=c+m<<0,c=m+O<<0,w=(c>>>2|c<<30)^(c>>>13|c<<19)^(c>>>22|c<<10),B=(n>>>6|n<<26)^(n>>>11|n<<21)^(n>>>25|n<<7),_=c&o,$=_^c&s^a,I=n&b^~n&t,m=d+B+I+N[g+3]+v[g+3],O=w+$,d=e+m<<0,e=m+O<<0,this.chromeBugWorkAround=!0;this.h0=this.h0+e<<0,this.h1=this.h1+c<<0,this.h2=this.h2+o<<0,this.h3=this.h3+s<<0,this.h4=this.h4+d<<0,this.h5=this.h5+n<<0,this.h6=this.h6+b<<0,this.h7=this.h7+t<<0},S.prototype.hex=function(){this.finalize();var e=this.h0,c=this.h1,o=this.h2,s=this.h3,d=this.h4,n=this.h5,b=this.h6,t=this.h7,v=r[e>>>28&15]+r[e>>>24&15]+r[e>>>20&15]+r[e>>>16&15]+r[e>>>12&15]+r[e>>>8&15]+r[e>>>4&15]+r[e&15]+r[c>>>28&15]+r[c>>>24&15]+r[c>>>20&15]+r[c>>>16&15]+r[c>>>12&15]+r[c>>>8&15]+r[c>>>4&15]+r[c&15]+r[o>>>28&15]+r[o>>>24&15]+r[o>>>20&15]+r[o>>>16&15]+r[o>>>12&15]+r[o>>>8&15]+r[o>>>4&15]+r[o&15]+r[s>>>28&15]+r[s>>>24&15]+r[s>>>20&15]+r[s>>>16&15]+r[s>>>12&15]+r[s>>>8&15]+r[s>>>4&15]+r[s&15]+r[d>>>28&15]+r[d>>>24&15]+r[d>>>20&15]+r[d>>>16&15]+r[d>>>12&15]+r[d>>>8&15]+r[d>>>4&15]+r[d&15]+r[n>>>28&15]+r[n>>>24&15]+r[n>>>20&15]+r[n>>>16&15]+r[n>>>12&15]+r[n>>>8&15]+r[n>>>4&15]+r[n&15]+r[b>>>28&15]+r[b>>>24&15]+r[b>>>20&15]+r[b>>>16&15]+r[b>>>12&15]+r[b>>>8&15]+r[b>>>4&15]+r[b&15];return this.is224||(v+=r[t>>>28&15]+r[t>>>24&15]+r[t>>>20&15]+r[t>>>16&15]+r[t>>>12&15]+r[t>>>8&15]+r[t>>>4&15]+r[t&15]),v},S.prototype.toString=S.prototype.hex,S.prototype.digest=function(){this.finalize();var e=this.h0,c=this.h1,o=this.h2,s=this.h3,d=this.h4,n=this.h5,b=this.h6,t=this.h7,v=[e>>>24&255,e>>>16&255,e>>>8&255,e&255,c>>>24&255,c>>>16&255,c>>>8&255,c&255,o>>>24&255,o>>>16&255,o>>>8&255,o&255,s>>>24&255,s>>>16&255,s>>>8&255,s&255,d>>>24&255,d>>>16&255,d>>>8&255,d&255,n>>>24&255,n>>>16&255,n>>>8&255,n&255,b>>>24&255,b>>>16&255,b>>>8&255,b&255];return this.is224||v.push(t>>>24&255,t>>>16&255,t>>>8&255,t&255),v},S.prototype.array=S.prototype.digest,S.prototype.arrayBuffer=function(){this.finalize();var e=new ArrayBuffer(this.is224?28:32),c=new DataView(e);return c.setUint32(0,this.h0),c.setUint32(4,this.h1),c.setUint32(8,this.h2),c.setUint32(12,this.h3),c.setUint32(16,this.h4),c.setUint32(20,this.h5),c.setUint32(24,this.h6),this.is224||c.setUint32(28,this.h7),e};function M(e,c,o){var s,d=typeof e;if(d==="string"){var n=[],b=e.length,t=0,v;for(s=0;s<b;++s)v=e.charCodeAt(s),v<128?n[t++]=v:v<2048?(n[t++]=192|v>>>6,n[t++]=128|v&63):v<55296||v>=57344?(n[t++]=224|v>>>12,n[t++]=128|v>>>6&63,n[t++]=128|v&63):(v=65536+((v&1023)<<10|e.charCodeAt(++s)&1023),n[t++]=240|v>>>18,n[t++]=128|v>>>12&63,n[t++]=128|v>>>6&63,n[t++]=128|v&63);e=n}else if(d==="object"){if(e===null)throw new Error(f);if(R&&e.constructor===ArrayBuffer)e=new Uint8Array(e);else if(!Array.isArray(e)&&(!R||!ArrayBuffer.isView(e)))throw new Error(f)}else throw new Error(f);e.length>64&&(e=new S(c,!0).update(e).array());var g=[],w=[];for(s=0;s<64;++s){var B=e[s]||0;g[s]=92^B,w[s]=54^B}S.call(this,c,o),this.update(w),this.oKeyPad=g,this.inner=!0,this.sharedMemory=o}M.prototype=new S,M.prototype.finalize=function(){if(S.prototype.finalize.call(this),this.inner){this.inner=!1;var e=this.array();S.call(this,this.is224,this.sharedMemory),this.update(this.oKeyPad),this.update(e),S.prototype.finalize.call(this)}};var V=G();V.sha256=V,V.sha224=G(!0),V.sha256.hmac=X(),V.sha224.hmac=X(!0),J?A.exports=V:(x.sha256=V.sha256,x.sha224=V.sha224)})()})(de);var Ue=de.exports;/** * Invoice Ninja (https://invoiceninja.com). * * @link https://github.com/invoiceninja/invoiceninja source repository * * @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com) * * @license https://www.elastic.co/licensing/elastic-license */function je(){const A=Ue.sha256.create();return A.update(`${Date.now().toString()}${Math.random().toString()}`),A.hex()}/** * Invoice Ninja (https://invoiceninja.com). * * @link https://github.com/invoiceninja/invoiceninja source repository * * @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com) * * @license https://www.elastic.co/licensing/elastic-license */function Je(A){const{setErrors:f,setIsFormBusy:F,isFormBusy:x}=A,y=xe();return(h,J)=>{if(!x){te.processing(),f(void 0),F(!0);const R=je();re("POST",T("/api/v1/payments?email_receipt=:email",{email:J}),{...h,idempotency_key:R}).then(r=>{te.success("created_payment"),y(_e("/payments/:id/edit",{id:r.data.data.id}))}).catch(r=>{var k;((k=r.response)==null?void 0:k.status)===422&&(te.dismiss(),f(r.response.data))}).finally(()=>{F(!1),pe(["payments","credits","invoices","clients"])})}}}function Le(){var g,w,B,$,m,O,I,H,P;const{documentTitle:A}=Fe("create_payment"),[f]=be(),[F]=ve(),x=[{name:f("payments"),href:"/payments"},{name:f("new_payment"),href:"/payments/create"}],y=me(),h=ye(),J=Re(),R=Me(),r=ge(),k=Oe(),[i,N]=Ce(Ve),[l,C]=K.useState(),[z,G]=K.useState(!1),[Q,Y]=K.useState((g=h==null?void 0:h.settings)==null?void 0:g.client_manual_payment_notification),[X,S]=K.useState(!1),{data:M}=$e();K.useEffect(()=>{N(a=>{var p;let _=a;return F.get("action")!=="enter"&&F.get("action")!=="apply"&&(_=void 0),typeof M<"u"&&typeof _>"u"&&(_={...M.data.data,invoices:[],credits:[],client_id:"",type_id:((p=h==null?void 0:h.settings)==null?void 0:p.payment_type_id)??""}),_}),F.has("client")&&N(a=>a&&{...a,client_id:F.get("client")}),F.has("client")&&F.has("invoice")&&R.find(F.get("invoice")).then(a=>N(_=>_&&{..._,invoices:[{_id:j(),invoice_id:a.id,amount:a.balance>0?a.balance:a.amount}]})),F.has("client")&&F.has("credit")&&J.find(F.get("credit")).then(a=>N(_=>_&&{..._,credits:[{_id:j(),credit_id:a.id,amount:a.balance>0?a.balance:a.amount}]})),F.has("type")&&N(a=>a&&{...a,type_id:F.get("type")??""})},[M]);const{handleInvoiceChange:V,handleExistingInvoiceChange:e,handleInvoiceInputChange:c,handleDeletingInvoice:o}=Te({payment:i,setPayment:N}),{handleCreditChange:s,handleExistingCreditChange:d,handleCreditInputChange:n,handleDeletingCredit:b}=He({payment:i,setPayment:N}),t=(a,_)=>{N(p=>p&&{...p,[a]:_})},v=Je({setErrors:C,setIsFormBusy:G,isFormBusy:z});return u(Se,{title:A,breadcrumbs:x,onSaveClick:()=>v(i,Q),disableSaveButton:!i||z,aboveMainContainer:!!(i&&i.amount<0)&&u(Ae,{variant:"orange",style:{borderColor:y.$5},children:f("negative_payment_warning")}),children:u(we,{breadcrumbs:[],children:L(Be,{title:f("enter_payment"),children:[u(E,{leftSide:f("client"),children:u(Ne,{onChange:a=>{t("client_id",a==null?void 0:a.id),t("currency_id",(a==null?void 0:a.settings.currency_id)||"1"),t("invoices",[]),t("credits",[])},onClearButtonClick:()=>{t("client_id",""),t("currency_id",""),t("invoices",[]),t("credits",[])},errorMessage:l==null?void 0:l.errors.client_id,defaultValue:i==null?void 0:i.client_id,value:i==null?void 0:i.client_id,readonly:F.has("invoice")||F.get("action")==="enter"||F.get("action")==="apply",initiallyVisible:!(i!=null&&i.client_id)})}),u(E,{leftSide:f("amount_received"),leftSideHelp:f("amount_received_help"),children:u(ie,{value:(i==null?void 0:i.amount)||"",onValueChange:a=>t("amount",isNaN(parseFloat(a))?0:parseFloat(a)),errorMessage:l==null?void 0:l.errors.amount,changeOverride:!0})}),(i==null?void 0:i.client_id)&&u(ae,{}),i&&i.invoices.length>0&&i.invoices.map((a,_)=>u(E,{children:L("div",{className:"flex flex-col",children:[L("div",{className:"flex items-end space-x-2",children:[u(Z,{inputOptions:{value:a.invoice_id,label:f("invoice")??""},endpoint:T(`/api/v1/invoices?payable=${i.client_id}&per_page=100`),entryOptions:{label:"number",id:"id",value:"id",searchable:"number",dropdownLabelFn:p=>{var D,W;return`${f("invoice_number_short")}${p.number} - ${f("balance")} ${r(p.balance,(D=i.client)==null?void 0:D.country_id,(W=i.client)==null?void 0:W.settings.currency_id)}`},inputLabelFn:p=>p?`${f("invoice_number_short")}${p==null?void 0:p.number}`:""},onChange:p=>p.resource?e(p.resource,_):null,exclude:q(i.invoices.filter(({invoice_id:p})=>p!==a.invoice_id)).pluck("invoice_id").toArray()}),u(ie,{label:f("amount_received"),value:a.amount||"",onValueChange:p=>c(_,isNaN(parseFloat(p))?0:parseFloat(p)),className:"w-full",withoutLabelWrapping:!0}),u(se,{behavior:"button",type:"minimal",className:"self-center mt-6",onClick:()=>o(a._id),children:u(ce,{})})]}),(l==null?void 0:l.errors[`invoices.${_}.amount`])&&u(U,{className:"mt-2",type:"danger",children:l==null?void 0:l.errors[`invoices.${_}.amount`]}),(l==null?void 0:l.errors[`invoices.${_}.invoice_id`])&&u(U,{className:"mt-2",type:"danger",children:l==null?void 0:l.errors[`invoices.${_}.invoice_id`]})]})},_)),(i==null?void 0:i.client_id)&&u(E,{leftSide:f("invoices"),children:u(Z,{endpoint:T(`/api/v1/invoices?payable=${i==null?void 0:i.client_id}&per_page=100`),inputOptions:{value:"id"},entryOptions:{id:"id",value:"id",label:"number",searchable:"number",dropdownLabelFn:a=>{var _,p;return`${f("invoice_number_short")}${a.number} - ${f("balance")} ${r(a.balance,(_=i.client)==null?void 0:_.country_id,(p=i.client)==null?void 0:p.settings.currency_id)}`}},onChange:({resource:a})=>a?V(a):null,exclude:q(i.invoices).pluck("invoice_id").toArray(),clearInputAfterSelection:!0})}),(l==null?void 0:l.errors.invoices)&&u("div",{className:"px-6",children:u(U,{className:"mt-2",type:"danger",children:l==null?void 0:l.errors.invoices})}),(i==null?void 0:i.client_id)&&u(ae,{}),i&&i.credits.length>0&&i.credits.map((a,_)=>u(E,{children:L("div",{className:"flex flex-col",children:[L("div",{className:"flex items-end space-x-2",children:[u(Z,{inputOptions:{value:a.credit_id,label:f("credit")??""},endpoint:T(`/api/v1/credits?client_id=${i.client_id}&per_page=100&applicable=true`),entryOptions:{id:"id",value:"id",label:"number",searchable:"number",dropdownLabelFn:p=>{var D,W;return`${f("credit")} #${p.number} - ${f("balance")} ${r(p.balance,(D=i.client)==null?void 0:D.country_id,(W=i.client)==null?void 0:W.settings.currency_id)}`}},onChange:p=>p.resource?d(p.resource,_):null,exclude:q(i.credits.filter(({credit_id:p})=>p!==a.credit_id)).pluck("credit_id").toArray()}),u(ie,{label:f("amount"),onValueChange:p=>n(_,isNaN(parseFloat(p))?0:parseFloat(p)),className:"w-full",value:a.amount||"",withoutLabelWrapping:!0}),u(se,{behavior:"button",type:"minimal",className:"self-center mt-6",onClick:()=>b(a._id),children:u(ce,{})})]}),(l==null?void 0:l.errors[`credits.${_}.amount`])&&u(U,{className:"mt-2",type:"danger",children:l==null?void 0:l.errors[`credits.${_}.amount`]}),(l==null?void 0:l.errors[`credits.${_}.credit_id`])&&u(U,{className:"mt-2",type:"danger",children:l==null?void 0:l.errors[`credits.${_}.credit_id`]})]})},_)),(i==null?void 0:i.client_id)&&u(E,{leftSide:f("credits"),children:u(Z,{endpoint:T(`/api/v1/credits?client_id=${i.client_id}&applicable=true`),inputOptions:{value:null},entryOptions:{id:"id",label:"number",value:"id",searchable:"number",dropdownLabelFn:a=>{var _,p;return`${f("credit")} #${a.number} - ${f("balance")} ${r(a.balance,(_=i.client)==null?void 0:_.country_id,(p=i.client)==null?void 0:p.settings.currency_id)}`}},onChange:a=>a.resource?s(a.resource):null,exclude:q(i.credits).pluck("credit_id").toArray(),clearInputAfterSelection:!0})}),(l==null?void 0:l.errors.credits)&&u("div",{className:"px-6",children:u(U,{className:"mt-2",type:"danger",children:l==null?void 0:l.errors.credits})}),(i==null?void 0:i.client_id)&&u(ae,{}),u(E,{leftSide:f("payment_date"),children:u(ne,{type:"date",id:"date",value:i==null?void 0:i.date,onValueChange:a=>t("date",a),errorMessage:l==null?void 0:l.errors.date})}),u(E,{leftSide:f("payment_type"),children:u(Ee,{value:i==null?void 0:i.type_id,onValueChange:a=>t("type_id",a),errorMessage:l==null?void 0:l.errors.type_id,withBlank:!0,customSelector:!0,children:k.map(([a,_],p)=>u("option",{value:a,children:_},p))})}),u(E,{leftSide:f("transaction_reference"),children:u(ne,{id:"transaction_reference",onValueChange:a=>t("transaction_reference",a),errorMessage:l==null?void 0:l.errors.transaction_reference})}),u(E,{leftSide:f("private_notes"),children:u(ne,{element:"textarea",id:"private_notes",onValueChange:a=>t("private_notes",a),errorMessage:l==null?void 0:l.errors.private_notes})}),((w=h==null?void 0:h.custom_fields)==null?void 0:w.payment1)&&u(ee,{field:"payment1",defaultValue:i==null?void 0:i.custom_value1,value:(B=h==null?void 0:h.custom_fields)==null?void 0:B.payment1,onValueChange:a=>t("custom_value1",a.toString())}),(($=h==null?void 0:h.custom_fields)==null?void 0:$.payment2)&&u(ee,{field:"payment2",defaultValue:i==null?void 0:i.custom_value2,value:(m=h==null?void 0:h.custom_fields)==null?void 0:m.payment2,onValueChange:a=>t("custom_value2",a.toString())}),((O=h==null?void 0:h.custom_fields)==null?void 0:O.payment3)&&u(ee,{field:"payment3",defaultValue:i==null?void 0:i.custom_value3,value:(I=h==null?void 0:h.custom_fields)==null?void 0:I.payment3,onValueChange:a=>t("custom_value3",a.toString())}),((H=h==null?void 0:h.custom_fields)==null?void 0:H.payment4)&&u(ee,{field:"payment4",defaultValue:i==null?void 0:i.custom_value4,value:(P=h==null?void 0:h.custom_fields)==null?void 0:P.payment4,onValueChange:a=>t("custom_value4",a.toString())}),u(E,{leftSide:f("send_email"),children:u(le,{checked:Q,onChange:Y})}),u(E,{leftSide:f("convert_currency"),children:u(le,{checked:!!(i!=null&&i.exchange_currency_id),onChange:a=>{S(a),a?t("exchange_currency_id","1"):t("exchange_currency_id",""),t("exchange_rate",1)}})}),X&&i&&u(Ie,{exchangeRate:i.exchange_rate.toString()||"1",exchangeCurrencyId:i.exchange_currency_id,currencyId:i.currency_id||"1",amount:q(i==null?void 0:i.invoices).sum("amount")+((i==null?void 0:i.amount)??0),onChange:(a,_)=>{t("exchange_rate",a),t("exchange_currency_id",_)},onExchangeRateChange:a=>t("exchange_rate",a)})]})})})}export{Le as default};
cải xoăn