10 lines
3.0 KiB
JavaScript
10 lines
3.0 KiB
JavaScript
import{u as C,p as B,z as x,j as h,H as I,c as n,af as r,ae as d,ag as E,ah as T,J as j,a8 as N,a9 as O,bh as $,Z as F,aw as H,a1 as q,aD as z,aF as k,aI as G,db as J,bc as f,aP as Q,G as V,bi as Z}from"./bundle.4a8685ac.js";import{u as K}from"./bundle.9528b41d.js";import{b as _}from"./bundle.d8ed156c.js";import{a as y}from"./bundle.ffc7495e.js";import{u as L}from"./bundle.46fb46a7.js";import{p as R}from"./bundle.d41b5e83.js";const U=s=>{const[o]=C(),[m,l]=B.useState(!1),{selectedIds:i,setSelected:c}=s,p=_(),u=x();return h(I,{children:[n(r,{onClick:()=>l(!0),icon:n(d,{element:E}),children:o("send_email")}),h(T,{title:o("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:o("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:o("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 W=()=>{const s=N(),o=O(R),{data:m}=L();return l=>{m&&(o({...m.data.data,invoices:[],credits:[],client_id:l[0].client_id}),l.forEach(i=>{o(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"))}},ae=()=>{const[s]=C(),o=_(),m=F(),l=Z(),i=W(),c=H({entity:"credit"}),p=K({entity:"credit"}),u=e=>!e.some(({status_id:t,is_deleted:a})=>t!==y.Draft||a),b=e=>e.some(({documents:t})=>t.length),g=e=>e.flatMap(({documents:t})=>t.map(({id:a})=>a)),w=(e,t)=>{const a=g(e);l(a,"download"),t([])},A=e=>{if(e.length){if(V(e).pluck("client_id").unique().toArray().length>1)return f.error("multiple_client_error");i(e)}},D=e=>e.every(({client_id:t,amount:a,status_id:S})=>t&&a>0&&S!==y.Applied),{setChangeTemplateVisible:M,setChangeTemplateResources:P,setChangeTemplateEntityContext:v}=q();return[({selectedIds:e,setSelected:t})=>n(U,{selectedIds:e,setSelected:t}),({selectedIds:e,setSelected:t})=>n(r,{onClick:()=>{c(e),t([])},icon:n(d,{element:z}),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:a})=>u(t)&&n(r,{onClick:()=>{o(e,"mark_sent"),a([])},icon:n(d,{element:G}),children:s("mark_sent")}),({selectedResources:e,setSelected:t})=>D(e)&&m("create_payment")&&n(r,{onClick:()=>{A(e),t([])},icon:n(d,{element:J}),children:s("apply_credit")}),({selectedResources:e,setSelected:t})=>n(r,{onClick:()=>b(e)?w(e,t):f.error("no_documents_to_download"),icon:n(d,{element:k}),children:s("documents")}),({selectedResources:e})=>n(r,{onClick:()=>{M(!0),P(e),v({endpoint:"/api/v1/credits/bulk",entity:"credit"})},icon:n(d,{element:Q}),children:s("run_template")})]};export{ae as u};
|