ruạṛ
import{a as Se,r as H,e as q,u as O,x as ce,A as xe,f as ee,d as te,g as ke,fE as re,c as a,D as pe,h as A,m as G,a$ as Te,s as le,b0 as ye,b1 as Ie,bk as R,z as U,j as C,cs as J,p as y,H as F,fp as _e,cO as ge,bg as Ne,ay as Y,fF as we,aM as De,cq as $e,dg as be,fo as Pe,fG as Me,fH as Ke,fI as Ee,G as Be,bq as Ae,bH as Fe,bI as Oe,bu as Qe,J as oe,fJ as je,fK as Ve,bc as M,$ as X,fL as Re,fM as Le,f1 as ze,fN as He,bv as D,bC as qe,fO as Ge,ad as Ue,ax as ie,eM as We,fP as Je,by as Xe,T as Ye,a1 as Ze,bs as et,W as tt,k as at,a6 as nt,a7 as st,a8 as se}from"./bundle.9abe88c8.js";import{E as lt,A as ae,T as Z,u as ot,a as Ce,b as it}from"./transactions-cc5537db.js";import{u as ct,a as rt}from"./useActions-7d783617.js";import{I as dt}from"./ImportButton-83a39628.js";import{c as ut,b as mt}from"./payments-0a3eee62.js";import{I as B}from"./invoice-status-756326ba.js";import{P as V}from"./payment-status-51e1486d.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 de(e){return Se(["/api/v1/invoices",e],()=>H("GET",q("/api/v1/invoices?client_status=:client_status&filter=:filter&client_id=:client_id&filter_deleted_clients=:without_deleted_clients&per_page=:per_page&page=:page&include=:include",{per_page:e.perPage??"100",page:e.currentPage??"1",client_status:e.clientStatus??"all",client_id:e.clientId??"",filter:e.filter??"",without_deleted_clients:e.withoutDeletedClients||!0,include:e.include||""})).then(s=>s.data.data),{enabled:e.enabled??!0,staleTime:1/0})}function ht(){const{t:e}=O(),s=ce(),n=xe(),{dateFormat:l}=ee(),i=te(),t=ke(),c=ct(),{data:$}=de({perPage:1e3}),{data:k}=re({perPage:1e3}),b=h=>{var o;return((o=$==null?void 0:$.find(g=>g.id===h))==null?void 0:o.number)||""},v=h=>{var o;return((o=k==null?void 0:k.find(g=>g.id===h))==null?void 0:o.number)||""};return[{id:"status",label:e("status"),format:(h,o)=>a(pe,{to:A("/transactions/:id/edit",{id:o.id}),renderSpan:t("bank_transaction",o),children:a(lt,{transaction:o})})},{id:"deposit",label:e("deposit"),format:(h,o)=>{var g;if(o.base_type===ae.Credit)return i(o.amount,(g=s==null?void 0:s.settings)==null?void 0:g.country_id,o.currency_id)}},{id:"withdrawal",label:e("withdrawal"),format:(h,o)=>{var g;if(o.base_type===ae.Debit)return i(o.amount,(g=s==null?void 0:s.settings)==null?void 0:g.country_id,o.currency_id)}},{id:"date",label:e("date"),format:h=>G(h,l)},{id:"description",label:e("description"),format:h=>a(Te,{width:"auto",tooltipElement:a("div",{className:"w-full max-h-48 overflow-auto whitespace-normal break-all",children:a("article",{className:le("prose prose-sm",{"prose-invert":n.dark_mode}),dangerouslySetInnerHTML:{__html:ye(c(h))}})}),children:a("span",{children:Ie(ye(c(h))).slice(0,50)})})},{id:"invoice_ids",label:e("invoices"),format:h=>h&&a("div",{className:"flex space-x-2",children:h.toString().split(",").map(o=>a(R,{to:A("/invoices/:id/edit",{id:o}),children:b(o)},o))})},{id:"expense_id",label:e("expense"),format:h=>h&&a("div",{className:"flex space-x-2",children:h.toString().split(",").map(o=>a(R,{to:A("/expenses/:id/edit",{id:o}),children:v(o)},o))})}]}function ft(e){const[s]=O(),n=U(),l=(i,t)=>{e.setSearchParams(c=>({...c,[i]:t}))};return a("div",{className:"absolute w-full top-full left-0 mt-1 text-center z-10",style:{color:n.$3,colorScheme:n.$0,backgroundColor:n.$1,borderColor:n.$4},children:C("div",{className:"flex flex-col items-center pt-3 pb-6 space-y-3",style:{color:n.$3,colorScheme:n.$0,backgroundColor:n.$1,borderBottom:`1px solid ${n.$5}`},children:[C("div",{className:"flex justify-evenly w-full",style:{color:n.$3,colorScheme:n.$0,backgroundColor:n.$1,borderColor:n.$4},children:[a(J,{changeOverride:!0,style:{color:n.$3,colorScheme:n.$0,backgroundColor:n.$1,borderColor:n.$4},width:"12rem",label:`${s("min")} ${s("amount")}`,value:e.searchParams.minAmount,onValueChange:i=>l("minAmount",isNaN(Number(i))?0:Number(i))}),a(J,{changeOverride:!0,style:{color:n.$3,colorScheme:n.$0,backgroundColor:n.$1,borderColor:n.$4},width:"12rem",label:`${s("max")} ${s("amount")}`,value:e.searchParams.maxAmount,onValueChange:i=>l("maxAmount",isNaN(Number(i))?0:Number(i))})]}),C("div",{className:"flex justify-evenly w-full",children:[a(J,{style:{color:n.$3,colorScheme:n.$0,backgroundColor:n.$1,borderColor:n.$4},className:"w-full",width:"12rem",label:s("start"),type:"date",value:e.searchParams.startDate,onValueChange:i=>l("startDate",i||"")}),a(J,{changeOverride:!0,style:{color:n.$3,colorScheme:n.$0,backgroundColor:n.$1,borderColor:n.$4},className:"w-full",width:"12rem",label:s("end"),type:"date",value:e.searchParams.endDate,onValueChange:i=>l("endDate",i||"")})]})]})})}function yt(e){const s=e.dataKey==="invoices",n=e.dataKey==="payments",l=e.dataKey==="expenses",[i,t]=y.useState(!1),[c,$]=y.useState(!1),k=(v,_)=>{e.setSearchParams(h=>({...h,[v]:_}))},b=U();return C(F,{children:[a(_e,{initiallyVisible:i,setVisible:t,setSelectedIds:e.setSelectedIds,onChange:()=>{}}),a(ge,{initiallyVisibleModal:c,setVisible:$,setSelectedIds:e.setSelectedIds,onChange:()=>{}}),C("div",{className:"flex items-center pr-3",children:[a(J,{changeOverride:!0,style:{color:b.$3,colorScheme:b.$0,backgroundColor:b.$1,borderColor:b.$4},placeholder:Ne(`search_${e.dataKey}`,{count:""}),value:e.searchParams.searchTerm,onValueChange:v=>k("searchTerm",v)}),s||n||l?a(F,{children:a(Y,{element:we,className:"ml-3 cursor-pointer",size:28,onClick:()=>e.setIsFilterModalOpened(v=>!v)})}):a(F,{children:a(Y,{element:De,className:"ml-3 cursor-pointer",size:28,onClick:()=>e.dataKey==="vendors"?$(!0):t(!0)})}),e.isFilterModalOpened&&a(ft,{searchParams:e.searchParams,setSearchParams:e.setSearchParams})]})]})}/** * Invoice Ninja (https://invoiceninja.com). * * @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com) * * @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com) * * @license https://www.elastic.co/licensing/elastic-license */const bt={[B.Cancelled]:"cancelled",[B.Unpaid]:"unpaid",[B.PastDue]:"past_due",[B.Draft]:"draft",[B.Sent]:"sent",[B.Partial]:"partial",[B.Paid]:"paid",[B.Cancelled]:"cancelled",[B.Reversed]:"reversed"};/** * Invoice Ninja (https://invoiceninja.com). * * @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com) * * @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com) * * @license https://www.elastic.co/licensing/elastic-license */const Ct={[V.PartiallyUnapplied]:"partially_unapplied",[V.Unapplied]:"unapplied",[V.Pending]:"pending",[V.Cancelled]:"cancelled",[V.Failed]:"failed",[V.Completed]:"completed",[V.PartiallyRefunded]:"partially_refunded",[V.Refunded]:"refunded"};function _t(e){const s=te(),{dateFormat:n}=ee(),l=U();return C("li",{style:{color:l.$3,colorScheme:l.$0,backgroundColor:l.$1,borderColor:l.$4},className:"flex justify-between w-full cursor-pointer p-4 border-b last:border-b-0",onClick:()=>e.selectItem(e.resourceItem.id,e.resourceItem.clientId),children:[C("div",{className:"flex items-center",children:[a($e,{style:{color:l.$3,colorScheme:l.$0,backgroundColor:l.$1,borderColor:l.$4},checked:e.isItemChecked,onClick:()=>e.selectItem(e.resourceItem.id)}),C("div",{className:"flex flex-col items-start",style:{color:l.$3,colorScheme:l.$0,backgroundColor:l.$1,borderColor:l.$4},children:[a("span",{className:"text-sm",children:e.resourceItem.name}),a("span",{className:"text-sm",children:e.resourceItem.number})]})]}),C("div",{className:"flex items-center flex-grow pr-3",style:{color:l.$3,colorScheme:l.$0,backgroundColor:l.$1,borderColor:l.$4},children:[C("div",{className:"flex flex-col flex-grow pl-8 pr-3",style:{color:l.$3,colorScheme:l.$0,backgroundColor:l.$1,borderColor:l.$4},children:[a("span",{className:"text-sm",style:{color:l.$3,colorScheme:l.$0,backgroundColor:l.$1,borderColor:l.$4},children:e.resourceItem.clientName}),a("span",{className:"text-sm",style:{color:l.$3,colorScheme:l.$0,backgroundColor:l.$1,borderColor:l.$4},children:G(e.resourceItem.date||"",n)})]}),typeof e.resourceItem.amount=="number"&&a("span",{className:"text-sm",style:{color:l.$3,colorScheme:l.$0,backgroundColor:l.$1,borderColor:l.$4},children:s(e.resourceItem.amount||0,e.resourceItem.country_id,e.resourceItem.currency_id)})]}),a("div",{className:"flex items-center",style:{color:l.$3,colorScheme:l.$0,backgroundColor:l.$1,borderColor:l.$4},children:e.resourceItem.statusId?C(F,{children:[e.dataKey==="invoices"&&a(be,{for:bt,code:e.resourceItem.statusId}),e.dataKey==="payments"&&a(be,{for:Ct,code:e.resourceItem.statusId})]}):a(F,{children:e.dataKey==="expenses"&&a(Pe,{entity:e.resourceItem})})})]},e.resourceItem.id)}function W(e){var ue,me;const[s]=O(),n=U(),l=te(),[i,t]=y.useState({searchTerm:"",minAmount:0,maxAmount:0,startDate:"",endDate:""}),c=e.dataKey==="vendors",$=e.dataKey==="expenses",k=e.dataKey==="payments",b=e.dataKey==="invoices",v=e.dataKey==="categories",[_,h]=y.useState(),{data:o}=Me({enabled:b}),{data:g}=de({include:"client",clientStatus:"unpaid",filter:i.searchTerm,clientId:_,enabled:b}),{data:p}=Ke({filter:i.searchTerm,enabled:c}),{data:K}=Ee({filter:i.searchTerm,enabled:v}),{data:S}=ut({include:"client",filter:i.searchTerm,enabled:k,matchTransactions:!0}),{data:x}=re({include:"client",filter:i.searchTerm,enabled:$,matchTransactions:!0}),[d,N]=y.useState(),[Q,P]=y.useState(),[j,m]=y.useState(!1),r=f=>{var u,T;return!!((T=(u=e.selectedIds)==null?void 0:u.find(E=>E===f))!=null&&T.length)},I=(f,u)=>{var he,fe;h(u);const T=(he=e.selectedIds)==null?void 0:he.find(ne=>f===ne);let E;T!=null&&T.length?(E=(fe=e.selectedIds)==null?void 0:fe.filter(ne=>ne!==f),e.setSelectedIds(E)):(E=[...e.selectedIds||[],f],e.setSelectedIds(E))},L=f=>{var u;return(u=Q==null?void 0:Q.find(({id:T})=>T===f))==null?void 0:u.display_name},w=f=>f==null?void 0:f.map(u=>{var T,E;return{id:u.id,number:u.number,name:u.name,clientName:L(u.client_id),statusId:u.status_id,amount:u.amount,date:u.date,clientId:u.client_id,should_be_invoiced:u.should_be_invoiced,invoice_id:u.invoice_id,payment_date:u.payment_date,transaction_reference:u.transaction_reference,payment_type_id:u.payment_type_id,country_id:u.country_id||((T=u.client)==null?void 0:T.country_id),currency_id:u.currency_id||((E=u.client)==null?void 0:E.settings.currency_id)}}),z=f=>((d==null?void 0:d.filter(u=>r(u.id)&&u.currency_id===f))||[]).reduce((u,T)=>u+T.amount,0)??0,ve=()=>Be((d==null?void 0:d.filter(f=>r(f.id)))||[]).pluck("currency_id").unique().toArray();return y.useEffect(()=>{P(o),N(w(b?g:c?p:v?K:k?S:x))},[e.dataKey,g,p,K,o,S,x]),y.useEffect(()=>{var f;b&&!((f=e.selectedIds)!=null&&f.length)&&h("")},[e.selectedIds]),C("div",{className:le("flex flex-col flex-1 w-full relative",{"pb-7":e.calculateTotal}),style:{color:n.$3,colorScheme:n.$0,backgroundColor:n.$1,borderColor:n.$4},children:[C("div",{style:{color:n.$3,colorScheme:n.$0,backgroundColor:n.$1,borderColor:n.$4},className:le("flex justify-center px-5 py-3 relative border-b border-t",e.className,{relative:e.addSelectAllButton}),children:[e.addSelectAllButton&&a("div",{className:"absolute top-5 left-4",children:a($e,{checked:(ue=e.selectedIds)!=null&&ue.length?((me=e.selectedIds)==null?void 0:me.length)===(d==null?void 0:d.length):!1,onValueChange:(f,u)=>e.setSelectedIds(u?(d==null?void 0:d.map(T=>T.id))||[]:[])})}),a(yt,{dataKey:e.dataKey,searchParams:i,setIsFilterModalOpened:m,isFilterModalOpened:j,setSearchParams:t,setSelectedIds:e.setSelectedIds})]}),a("ul",{style:{height:b?400:200,color:n.$3,colorScheme:n.$0,backgroundColor:n.$1,borderColor:n.$4},className:"flex flex-col grow justify-start overflow-y-auto",children:d==null?void 0:d.map(f=>{var u;return(r(f.id)||!((u=e.selectedIds)!=null&&u.length)||b||$)&&a(_t,{isItemChecked:r(f.id),resourceItem:f,selectItem:I,dataKey:e.dataKey},f.id)})}),e.calculateTotal&&!!(d!=null&&d.filter(f=>r(f.id)).length)&&a("div",{className:"absolute flex w-full bottom-2 text-sm",children:C("div",{className:"flex flex-1 justify-center items-center space-x-1",children:[a("span",{children:d==null?void 0:d.filter(f=>r(f.id)).length}),a("span",{children:s("selected")}),a("span",{children:"·"}),a("span",{children:ve().map((f,u)=>l(z(f),d==null?void 0:d[u].country_id,f)).join(" | ")})]})})]})}function gt(e){const[s]=O(),n=Ae(),{transactionRule:l}=e,i=Fe(Oe),[t,c]=y.useState(!1),[$,k]=y.useState(!0),[b,v]=y.useState([]),[_,h]=y.useState([]),[o,g]=y.useState([]),[p,K]=y.useState([]),[S,x]=y.useState([]),d=[e.isCreditTransactionType?s("create_payment"):s("create_expense"),e.isCreditTransactionType?s("link_payment"):s("link_expense")],N=r=>{r.preventDefault(),!(!b.length||t)&&(c(!0),M.processing(),H("POST",q("/api/v1/bank_transactions/match"),{transactions:[{id:e.transactionDetails.transaction_id,invoice_ids:b.join(",")}]}).then(()=>{n.invalidateQueries([i]),X(["invoices","bank_transactions"]),M.success("converted_transaction")}).finally(()=>c(!1)))},Q=r=>{r.preventDefault(),!(!p.length||t)&&(c(!0),M.processing(),H("POST",q("/api/v1/bank_transactions/match"),{transactions:[{id:e.transactionDetails.transaction_id,payment_id:p.join(",")}]}).then(()=>{n.invalidateQueries([i]),X(["invoices","payments","bank_transactions"]),M.success("linked_transaction")}).finally(()=>c(!1)))},P=r=>{r.preventDefault(),!(!_.length&&!o.length||t)&&(c(!0),M.processing(),H("POST",q("/api/v1/bank_transactions/match"),{transactions:[{id:e.transactionDetails.transaction_id,vendor_id:_.join(","),ninja_category_id:o.join(",")}]}).then(()=>{n.invalidateQueries([i]),X(["bank_transactions","expenses"]),M.success("converted_transaction")}).finally(()=>c(!1)))},j=r=>{r.preventDefault(),!(!S.length||t)&&(c(!0),M.processing(),H("POST",q("/api/v1/bank_transactions/match"),{transactions:[{id:e.transactionDetails.transaction_id,expense_id:S.join(",")}]}).then(()=>{n.invalidateQueries([i]),X(["expenses","bank_transactions"]),M.success("linked_transaction")}).finally(()=>c(!1)))};y.useEffect(()=>{k(e.transactionDetails.status_id===Z.Converted)},[e.transactionDetails.status_id,e.isCreditTransactionType,_,b,o,p,S]),y.useEffect(()=>()=>{k(!0)},[]),y.useEffect(()=>{if(l){const{category_id:r,vendor_id:I}=l;r&&g([r]),I&&h([I])}},[l]);const m=U();return a("div",{className:"flex flex-col flex-1",children:a("div",{className:"flex flex-col flex-1",children:!$&&C(Qe,{className:"flex flex-col flex-1 border-t border-gray-200",tabs:d,height:"full",width:"full",children:[C("div",{children:[e.isCreditTransactionType?a(W,{style:{color:m.$3,colorScheme:m.$0,backgroundColor:m.$1,borderColor:m.$4},transactionDetails:e.transactionDetails,dataKey:"invoices",setSelectedIds:v,selectedIds:b,calculateTotal:!0}):C(F,{children:[a(W,{style:{color:m.$3,colorScheme:m.$0,backgroundColor:m.$1,borderColor:m.$4},transactionDetails:e.transactionDetails,dataKey:"vendors",setSelectedIds:h,selectedIds:_}),a(W,{style:{color:m.$3,colorScheme:m.$0,backgroundColor:m.$1,borderColor:m.$4},transactionDetails:e.transactionDetails,dataKey:"categories",setSelectedIds:g,selectedIds:o})]}),a("div",{className:"px-3 py-3 w-full border-t border-gray-200",children:C(oe,{style:{color:m.$3,colorScheme:m.$0,backgroundColor:m.$1,borderColor:m.$4},className:"w-full",onClick:e.isCreditTransactionType?N:P,disableWithoutIcon:!0,disabled:t||e.isCreditTransactionType&&!b.length&&!p.length||!e.isCreditTransactionType&&!_.length&&!o.length&&!S.length,children:[a(je,{fontSize:22}),a("span",{children:e.isCreditTransactionType?s("create_payment"):s("create_expense")})]})})]}),C("div",{children:[e.isCreditTransactionType?a(W,{style:{color:m.$3,colorScheme:m.$0,backgroundColor:m.$1,borderColor:m.$4},transactionDetails:e.transactionDetails,dataKey:"payments",setSelectedIds:K,selectedIds:p,calculateTotal:!0}):a(W,{style:{color:m.$3,colorScheme:m.$0,backgroundColor:m.$1,borderColor:m.$4},transactionDetails:e.transactionDetails,dataKey:"expenses",setSelectedIds:x,selectedIds:S,calculateTotal:!0,addSelectAllButton:!0}),a("div",{className:"px-3 py-3 w-full border-t border-gray-200",children:C(oe,{style:{color:m.$3,colorScheme:m.$0,backgroundColor:m.$1,borderColor:m.$4},className:"w-full",onClick:e.isCreditTransactionType?Q:j,disableWithoutIcon:!0,disabled:t||e.isCreditTransactionType&&!b.length&&!p.length||!e.isCreditTransactionType&&!_.length&&!o.length&&!S.length,children:[a(Ve,{fontSize:22}),a("span",{children:e.isCreditTransactionType?s("link_payment"):s("link_expense")})]})})]})]})})})}function $t(e){const[s]=O(),n=ce(),l=te(),{dateFormat:i}=ee(),{data:t}=ot({id:e.transactionId,enabled:!!e.transactionId}),{data:c}=Re({id:(t==null?void 0:t.bank_integration_id)||"",enabled:!!t}),$=Z.Matched===(t==null?void 0:t.status_id),{data:k}=Le({id:(t==null?void 0:t.bank_transaction_rule_id)||"",enabled:!!t&&$}),[b,v]=y.useState(),[_,h]=y.useState(),[o,g]=y.useState(),[p,K]=y.useState(),S=(t==null?void 0:t.base_type)===ae.Credit,x=Z.Converted!==(t==null?void 0:t.status_id),d=t&&!x&&!!e.transactionId,{data:N}=de({enabled:S&&d}),{data:Q}=mt({id:(t==null?void 0:t.payment_id)||"",enabled:S&&d}),{data:P}=ze({id:(t==null?void 0:t.vendor_id)||"",enabled:!S&&d}),{data:j}=re({enabled:!S&&d}),{data:m}=He({id:(t==null?void 0:t.ninja_category_id)||"",enabled:!S&&d});y.useEffect(()=>{if(t){const I=N==null?void 0:N.filter(({id:w})=>{var z;return(z=t.invoice_ids)==null?void 0:z.includes(w)});v(I);const L=j==null?void 0:j.filter(({id:w})=>{var z;return(z=t.expense_id)==null?void 0:z.includes(w)});K(L),g(m==null?void 0:m.data.data),h(Q)}},[t,m,Q,e.transactionId,j]);const r=U();return C("div",{className:"flex flex-col flex-1 border-b",style:{color:r.$3,colorScheme:r.$0,backgroundColor:r.$1,borderColor:r.$4},children:[C("div",{children:[a(D,{leftSide:s("type"),children:s(S?Ce.Deposit:Ce.Withdrawal)}),a(D,{leftSide:s("amount"),children:l((t==null?void 0:t.amount)||0,n==null?void 0:n.settings.country_id,t==null?void 0:t.currency_id)}),a(D,{leftSide:s("date"),children:G((t==null?void 0:t.date)||"",i)}),a(D,{leftSide:s("bank_account"),className:"cursor-pointer",children:a(R,{style:{color:r.$3,colorScheme:r.$0,backgroundColor:r.$1,borderColor:r.$4},to:A("/settings/bank_accounts/:id/details",{id:c==null?void 0:c.id}),children:c==null?void 0:c.bank_account_name})}),(t==null?void 0:t.participant)&&a(D,{leftSide:s("participant"),children:t.participant}),(t==null?void 0:t.participant_name)&&a(D,{leftSide:s("participant_name"),children:t.participant_name})]}),x?a(gt,{transactionDetails:{base_type:(t==null?void 0:t.base_type)||"",transaction_id:(t==null?void 0:t.id)||"",status_id:(t==null?void 0:t.status_id)||""},isCreditTransactionType:S,transactionRule:k}):C(F,{children:[b==null?void 0:b.map(({id:I,number:L})=>a(D,{leftSide:s("invoice"),className:"cursor-pointer",children:a(R,{style:{color:r.$3,colorScheme:r.$0,backgroundColor:r.$1,borderColor:r.$4},to:A("/invoices/:id/edit",{id:I}),children:L})},I)),(t==null?void 0:t.payment_id)&&a(D,{leftSide:s("payment"),className:"cursor-pointer",children:a(R,{style:{color:r.$3,colorScheme:r.$0},to:A("/payments/:id/edit",{id:_==null?void 0:_.id}),children:_==null?void 0:_.number})}),(t==null?void 0:t.vendor_id)&&a(D,{leftSide:s("vendor"),className:"cursor-pointer",children:a(R,{style:{color:r.$3,colorScheme:r.$0,backgroundColor:r.$1,borderColor:r.$4},to:A("/vendors/:id",{id:P==null?void 0:P.id}),children:P==null?void 0:P.name})}),(t==null?void 0:t.ninja_category_id)&&a(D,{leftSide:s("category"),className:"cursor-pointer",children:a(R,{style:{color:r.$3,colorScheme:r.$0},to:A("/settings/expense_categories/:id/edit",{id:o==null?void 0:o.id}),children:o==null?void 0:o.name})}),p==null?void 0:p.map(({id:I,number:L,date:w})=>a(D,{leftSide:s("expense"),className:"cursor-pointer",children:a(R,{style:{color:r.$3,colorScheme:r.$0},to:A("/expenses/:id/edit",{id:I}),children:L||G(w,i)})},I))]})]})}/** * 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 vt(){const[e]=O(),s=qe(),{data:n}=Ge({perPage:1e3}),l=[{label:e("unmatched"),value:"unmatched",color:"white",backgroundColor:s.$1||"#6B7280",dropdownKey:"0"},{label:e("matched"),value:"matched",color:"white",backgroundColor:s.$2||"#1D4ED8",dropdownKey:"0"},{label:e("converted"),value:"converted",color:"white",backgroundColor:s.$3||"#22C55E",dropdownKey:"0"},{label:e("deposits"),value:"deposits",color:"white",backgroundColor:s.$4||"#e6b05c",dropdownKey:"0"},{label:e("withdrawals"),value:"withdrawals",color:"white",backgroundColor:s.$5||"#93C5FD",dropdownKey:"0"}];return n==null||n.forEach(i=>{l.push({label:i.bank_account_name,value:i.id,color:"white",backgroundColor:"#6B7280",queryKey:"bank_integration_ids",dropdownKey:"1",placeHolder:"bank_account"})}),l}function St(e){const[s]=O(),{transactions:n,setSelected:l}=e,i=ce(),t=te(),{dateFormat:c}=ee(),[$,k]=y.useState(!1),[b,v]=y.useState(!1),[_,h]=y.useState(""),[o,g]=y.useState(""),p=()=>n.every(({base_type:x,status_id:d})=>x===ae.Debit&&d!==Z.Converted),K=()=>{h(""),l([]),k(!1),g("")},S=()=>{M.processing(),v(!0);const x=n.map(d=>({id:d.id,vendor_id:_,ninja_category_id:o}));H("POST",q("/api/v1/bank_transactions/match"),{transactions:x}).then(()=>{X(["bank_transactions","expenses"]),M.success("converted_transaction"),K()}).finally(()=>v(!1))};return p()?C(F,{children:[C(Ue,{title:s("create_expense"),visible:$,onClose:K,overflowVisible:!0,children:[C("div",{className:"flex flex-col space-y-3",children:[C("span",{className:"text-base font-medium",children:[s("transactions"),":"]}),a("div",{className:"flex flex-col px-10",children:n.map((x,d)=>C("div",{className:"flex justify-evenly",children:[a("span",{className:"flex-1",children:G(x.date,c)}),a("span",{className:"ml-16 flex-1",children:t(x.amount,i==null?void 0:i.settings.country_id,x.currency_id)})]},d))})]}),a(ge,{inputLabel:s("vendor"),value:_,onChange:x=>h(x.id),onClearButtonClick:()=>h("")}),a(_e,{inputLabel:s("expense_category"),value:o,onChange:x=>g(x.id),onClearButtonClick:()=>g("")}),a(oe,{behavior:"button",onClick:S,disableWithoutIcon:!0,disabled:!_&&!o||b,children:s("create_expense")})]}),a(ie,{onClick:()=>k(!0),icon:a(Y,{element:We}),children:s("create_expense")})]}):null}const xt=()=>{const[e]=O(),s=it(),n=t=>t.every(({status_id:c})=>Z.Matched===c),l=t=>t.every(({payment_id:c})=>c);return[({selectedIds:t,selectedResources:c,setSelected:$})=>c&&l(c)&&a(ie,{onClick:()=>{s(t,"unlink"),$([])},icon:a(Y,{element:Je}),children:e("unlink")}),({selectedResources:t,setSelected:c})=>t&&a(St,{setSelected:c,transactions:t}),({selectedIds:t,selectedResources:c,setSelected:$})=>c&&n(c)&&a(ie,{onClick:()=>{s(t,"convert_matched"),$([])},icon:a(Y,{element:Xe}),children:e("convert")})]};function Pt(){Ye("transactions");const[e]=O(),s=Ze(),n=[{name:e("transactions"),href:"/transactions"}],l=rt(),i=vt(),t=ht(),c=xt(),{dateFormat:$}=ee(),[k,b]=y.useState(),[v,_]=y.useState(""),h=o=>{if(_(o.id),o.description){let g=o.description;o.description.length>35&&(g=g.slice(0,35).concat("...")),b(g)}else b(G(o.date,$))};return C(F,{children:[a(et,{title:k,visible:!!v,onClose:()=>_(""),size:"large",children:a($t,{transactionId:v,setTransactionId:_})}),a(tt,{title:e("transactions"),breadcrumbs:n,docsLink:"en/transactions/",children:a(at,{resource:"transaction",endpoint:"/api/v1/bank_transactions?sort=id|desc",bulkRoute:"/api/v1/bank_transactions/bulk",columns:t,linkToCreate:"/transactions/create",linkToEdit:"/transactions/:id/edit",onTableRowClick:h,customActions:l,customFilters:i,customBulkActions:c,customFilterPlaceholder:"status",rightSide:a(nt,{type:"component",guards:[st(se("create_bank_transaction"),se("edit_bank_transaction"))],component:a(dt,{route:"/transactions/import"})}),withResourcefulActions:!0,linkToCreateGuards:[se("create_bank_transaction")],hideEditableOptions:!s("edit_bank_transaction"),enableSavingFilterPreference:!0})})]})}export{Pt as default};
cải xoăn