ruạṛ
import{u as f,p as x,z as B,j as h,H as E,c as n,ax as r,ay as d,ac as I,ad as T,J as j,aa as N,ae as O,bh as $,a1 as G,av as H,a5 as J,aE as q,aG as k,aJ as z,dl as F,bc as y,aP as Q,G as V,bi as K}from"./bundle.9abe88c8.js";import{u as L}from"./useDownloadPdfs-4d13e7c1.js";import{b as _}from"./hooks-10493af2.js";import{a as C}from"./CreditStatus-ef9aafcc.js";import{u as R}from"./payments-0a3eee62.js";import{p as U}from"./atoms-f5ce5583.js";const W=s=>{const[a]=f(),[m,l]=x.useState(!1),{selectedIds:i,setSelected:c}=s,p=_(),u=B();return h(E,{children:[n(r,{onClick:()=>l(!0),icon:n(d,{element:I}),children:a("send_email")}),h(T,{title:a("bulk_email_credits"),visible:m,onClose:()=>l(!1),children:[n("span",{className:"text-lg",style:{backgroundColor:u.$2,color:u.$3,colorScheme:u.$0},children:a("are_you_sure")}),n("div",{className:"flex justify-end space-x-4 mt-5",children:n(j,{behavior:"button",onClick:()=>{p(i,"email"),c([]),l(!1)},children:a("yes")})})]})]})};/** * 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 */const X=()=>{const s=N(),a=O(U),{data:m}=R();return l=>{m&&(a({...m.data.data,invoices:[],credits:[],client_id:l[0].client_id}),l.forEach(i=>{a(c=>c&&{...c,credits:[...c.credits,{_id:$(),credit_id:i.id,amount:i.balance>0?i.balance:i.amount}]})}),s("/payments/create?action=apply&type=1"))}},oe=()=>{const[s]=f(),a=_(),m=G(),l=K(),i=X(),c=H({entity:"credit"}),p=L({entity:"credit"}),u=e=>!e.some(({status_id:t,is_deleted:o})=>t!==C.Draft||o),b=e=>e.some(({documents:t})=>t.length),g=e=>e.flatMap(({documents:t})=>t.map(({id:o})=>o)),A=(e,t)=>{const o=g(e);l(o,"download"),t([])},M=e=>{if(e.length){if(V(e).pluck("client_id").unique().toArray().length>1)return y.error("multiple_client_error");i(e)}},P=e=>e.every(({client_id:t,amount:o,status_id:S})=>t&&o>0&&S!==C.Applied),{setChangeTemplateVisible:v,setChangeTemplateResources:w,setChangeTemplateEntityContext:D}=J();return[({selectedIds:e,setSelected:t})=>n(W,{selectedIds:e,setSelected:t}),({selectedIds:e,setSelected:t})=>n(r,{onClick:()=>{c(e),t([])},icon:n(d,{element:q}),children:s("print_pdf")}),({selectedIds:e,setSelected:t})=>n(r,{onClick:()=>{p(e),t([])},icon:n(d,{element:k}),children:s("download_pdf")}),({selectedIds:e,selectedResources:t,setSelected:o})=>u(t)&&n(r,{onClick:()=>{a(e,"mark_sent"),o([])},icon:n(d,{element:z}),children:s("mark_sent")}),({selectedResources:e,setSelected:t})=>P(e)&&m("create_payment")&&n(r,{onClick:()=>{M(e),t([])},icon:n(d,{element:F}),children:s("apply_credit")}),({selectedResources:e,setSelected:t})=>n(r,{onClick:()=>b(e)?A(e,t):y.error("no_documents_to_download"),icon:n(d,{element:k}),children:s("documents")}),({selectedResources:e})=>n(r,{onClick:()=>{v(!0),w(e),D({endpoint:"/api/v1/credits/bulk",entity:"credit"})},icon:n(d,{element:Q}),children:s("run_template")})]};export{oe as u};
cải xoăn