Files
docker-invoiceninja/docker/app/public/bundle.e36ca010.js
2024-10-19 18:17:42 +00:00

10 lines
2.5 KiB
JavaScript

import{bJ as w,ba as y,r as V,e as x,bb as E,u as h,aq as O,Z as g,bo as v,bO as P,h as c,c as u,bP as R,p as b,a1 as j,j as f,T as k,bq as D,ds as q,bQ as $,bR as B,a5 as H}from"./bundle.293347bb.js";import{b as N}from"./bundle.07494dea.js";import{u as Q}from"./bundle.eaf58755.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 U(a){const t=w();return async r=>{a(void 0),y.processing(),await t(!0);const i={...r};delete i.invoices,delete i.credits,await t(!0),V("PUT",x("/api/v1/payments/:id",{id:r.id}),i).then(()=>{y.success("updated_payment")}).catch(n=>{var s;((s=n.response)==null?void 0:s.status)===422&&(y.dismiss(),a(n.response.data))}).finally(()=>E(["payments"]))}}function F(a){const[t]=h(),{isAdmin:r,isOwner:i}=O(),n=g(),s=v(),{id:o}=P(),{payment:e}=a,p=n("edit_payment")||s(e),l=n("view_payment")||n("edit_payment")||s(e);let d=[{name:t("edit"),href:c("/payments/:id/edit",{id:o})},{name:t("apply"),href:c("/payments/:id/apply",{id:o}),enabled:p},{name:t("refund"),href:c("/payments/:id/refund",{id:o}),enabled:p},{name:t("documents"),href:c("/payments/:id/documents",{id:o}),enabled:l,formatName:()=>{var m;return u(R,{numberOfDocuments:(m=e==null?void 0:e.documents)==null?void 0:m.length})}},{name:t("custom_fields"),href:c("/payments/:id/payment_fields",{id:o}),enabled:r||i}];return e&&(e.amount-e.applied>0&&!e.is_deleted||(d=d.filter(({name:m})=>m!==t("apply"))),e.amount!==e.refunded&&!e.is_deleted||(d=d.filter(({name:m})=>m!==t("refund")))),d}function Z(){const[a]=h(),t=g(),r=v(),{id:i}=P(),{data:n}=N({id:i}),[s,o]=b.useState(),[e,p]=b.useState(),l=[{name:a("payments"),href:"/payments"},{name:a("edit_payment"),href:c("/payments/:id/edit",{id:i})}],d=F({payment:s}),m=U(p),T=Q();b.useEffect(()=>{n&&o(n)},[n]);const{changeTemplateVisible:_,setChangeTemplateVisible:A,changeTemplateResources:C}=j();return f(k,{title:a("payment"),breadcrumbs:l,...(t("edit_payment")||r(s))&&s&&{onSaveClick:()=>m(s),navigationTopRight:u(D,{label:a("more_actions"),resource:s,actions:T,cypressRef:"paymentActionDropdown"}),disableSaveButton:!s},children:[f(q,{breadcrumbs:[],children:[u($,{tabs:d,disableBackupNavigation:!0}),u(B,{context:{errors:e,payment:s,setPayment:o}})]}),u(H,{entity:"payment",entities:C,visible:_,setVisible:A,labelFn:S=>`${a("number")}: ${S.number}`,bulkUrl:"/api/v1/payments/bulk"})]})}export{Z as default};