@openmrs/esm-billing-app 1.3.2-pre.2017 → 1.3.2-pre.2030

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/990.js CHANGED
@@ -1,4 +1,4 @@
1
- (globalThis.webpackChunk_openmrs_esm_billing_app=globalThis.webpackChunk_openmrs_esm_billing_app||[]).push([["990"],{4767(e,t,a){var l={"./uk.json":["723","9072"],"./ar.json":["4132","7045"],"./ru_RU.json":["986","8359"],"./uz_UZ.json":["890","7175"],"./fr.json":["4055","6508"],"./sw_KE.json":["8618","903"],"./uz.json":["3584","6377"],"./en.json":["4300","5117"],"./ky.json":["8163","2416"],"./pl.json":["1119","6724"],"./sq.json":["8371","4928"],"./ka.json":["795","1480"],"./si.json":["6859","6904"],"./zh_TW.json":["439","556"],"./de.json":["4944","5145"],"./lg.json":["4618","8695"],"./vi.json":["9214","6371"],"./tr.json":["5241","434"],"./es_MX.json":["8349","1646"],"./tr_TR.json":["9900","1869"],"./zh_CN.json":["9879","5644"],"./en_US.json":["9569","4106"],"./he.json":["4652","2317"],"./id.json":["2690","6047"],"./ku.json":["9895","4348"],"./es.json":["3099","7912"],"./ne.json":["2146","5503"],"./ar_SY.json":["7617","282"],"./uz@Latn.json":["7097","4658"],"./bn.json":["7159","6444"],"./cs.json":["6589","7182"],"./zh.json":["5661","7742"],"./hi_IN.json":["5442","4383"],"./pt_BR.json":["6468","1877"],"./qu.json":["5173","8358"],"./ro_RO.json":["6022","3963"],"./sw.json":["9913","3378"],"./am.json":["1197","9806"],"./pt.json":["6679","5132"],"./it.json":["9538","4111"],"./km.json":["6716","5940"],"./hi.json":["6840","2881"]};function n(e){if(!a.o(l,e))return Promise.resolve().then(function(){var t=Error("Cannot find module '"+e+"'");throw t.code="MODULE_NOT_FOUND",t});var t=l[e],n=t[0];return a.e(t[1]).then(function(){return a(n)})}n.keys=()=>Object.keys(l),n.id=4767,e.exports=n},6994(e,t,a){"use strict";a.d(t,{MH:()=>s,OS:()=>u,WJ:()=>o,bb:()=>c,cW:()=>d,j2:()=>m,ly:()=>r,vv:()=>_});var l=a(9324),n=a(3137),i=a(7003);let r=()=>{let e=`${i.B}billableService?v=custom:(uuid,name,shortName,serviceStatus,concept:(uuid,display,name:(name)),serviceType:(display,uuid),servicePrices:(uuid,name,price,paymentMode:(uuid,name)))`,{data:t,isLoading:a,isValidating:l,error:r,mutate:s}=(0,n.useOpenmrsFetchAll)(e);return{billableServices:t??[],isLoading:a,isValidating:l,error:r,mutate:s}};function s(){let{serviceTypes:e}=(0,n.useConfig)(),t=e.billableService,a=`${n.restBaseUrl}/concept/${t}?v=custom:(setMembers:(uuid,display))`,{data:i,error:r,isLoading:s}=(0,l.Ay)(a,n.openmrsFetch);return{serviceTypes:i?.data.setMembers?[...i.data.setMembers].sort((e,t)=>e.display.localeCompare(t.display)):[],error:r,isLoadingServiceTypes:s}}let o=()=>{let e=`${i.B}paymentMode`,{data:t,error:a,isLoading:r,mutate:s}=(0,l.Ay)(e,n.openmrsFetch);return{paymentModes:t?.data.results?[...t.data.results].sort((e,t)=>e.name.localeCompare(t.name)):[],error:a,isLoadingPaymentModes:r,mutate:s}};function c(e){let t=`${n.restBaseUrl}/conceptsearch?q=${e}`,{data:a,error:i,isLoading:r}=(0,l.Ay)(e?t:null,n.openmrsFetch);return{searchResults:a?.data?.results??[],error:i,isSearching:r}}let m=async e=>{let t=`${i.B}api/billable-service`;return await (0,n.openmrsFetch)(t,{method:"POST",body:e,headers:{"Content-Type":"application/json"}})},u=async(e,t)=>{let a=`${i.B}billableService/${e}`;return await (0,n.openmrsFetch)(a,{method:"POST",body:t,headers:{"Content-Type":"application/json"}})},d=e=>{let t=`${n.restBaseUrl}/billing/paymentMode`;return(0,n.openmrsFetch)(t,{method:"POST",body:e,headers:{"Content-Type":"application/json"}})},_=(e,t)=>{let a=`${n.restBaseUrl}/billing/paymentMode/${e}`;return(0,n.openmrsFetch)(a,{method:"POST",body:t,headers:{"Content-Type":"application/json"}})}},6199(e,t,a){"use strict";a.d(t,{DX:()=>u,FR:()=>g,LM:()=>v,N7:()=>C,TS:()=>d,Vs:()=>p,Xn:()=>E,Z5:()=>f,eC:()=>_,fu:()=>c,ly:()=>b,mi:()=>h,u1:()=>m,yj:()=>y});var l=a(9324),n=a(3139),i=a(3137),r=a(7003),s=a(5084);let o=e=>{let t=e?.lineItems?.filter(e=>!e.voided)??[],{identifier:a,name:l}=(e=>{if(!e)return{identifier:"",name:""};let t=e.indexOf(" - ");return -1===t?{identifier:"",name:e.trim()}:{identifier:e.substring(0,t).trim(),name:e.substring(t+3).trim()}})(e?.patient?.display);return{...e,patientName:l,identifier:a,patientUuid:e?.patient?.uuid,visitUuid:e?.visit?.uuid,cashPointUuid:e?.cashPoint?.uuid,cashPointName:e?.cashPoint?.name,cashPointLocation:e?.cashPoint?.location?.display,status:e.status,lineItems:t,billingService:t.map(e=>e?.item||e?.billableService||"--").join(" "),totalAmount:e.total,netAmount:e.amountAfterDiscount,tenderedAmount:(e?.payments??[]).map(e=>e.amountTendered??0).reduce((e,t)=>e+t,0)}},c=(e,t,a)=>{let l=`${r.B}bill?v=custom:(id,uuid,dateCreated,status,receiptNumber,patient:(uuid,display),lineItems:(uuid,item,billableService,voided))&pageSize=${e}`;t&&(l+=`&status=${t}`),a&&(l+=`&patientName=${encodeURIComponent(a)}`);let{data:n,error:s,isLoading:c,isValidating:m,mutate:u,currentPage:d,totalCount:_,goTo:p}=(0,i.useOpenmrsPagination)(l,e);return{bills:n?.map(e=>o(e)),error:s,isLoading:c,isValidating:m,mutate:u,currentPage:d,totalCount:_,goTo:p}},m=(e,t,a)=>{let l=`${r.B}bill?v=full`;e&&(l+=`&patientUuid=${e}`),t&&(l+=`&status=${t}`),a&&(l+=`&visitUuid=${a}`);let{data:s,error:c,isLoading:m,isValidating:u,mutate:d}=(0,i.useOpenmrsFetchAll)(l),_=(0,n.A)(s??[],["dateCreated"]).reverse();return{bills:_?.map(e=>o(e)),error:c,isLoading:m,isValidating:u,mutate:d}};function u(e,t=!0){let a=`${r.B}bill/${e}`,{data:n,error:s,isLoading:c,isValidating:m,mutate:d}=(0,l.Ay)(e?a:null,i.openmrsFetch),_=null;return n?.data&&(_=t?o(n.data):n.data),{bill:_,error:s,isLoading:c,isValidating:m,mutate:d}}let d=(e,t)=>{let a=`${r.B}bill/${t}/payment`;return(0,i.openmrsFetch)(a,{method:"POST",body:e,headers:{"Content-Type":"application/json"}})};function _(){let{sessionLocation:e}=(0,i.useSession)();return{data:e}}let p=e=>{let{currentVisit:t}=(0,i.useVisit)(e);return(t?.attributes??[]).map(e=>({name:e.attributeType.name,value:e.value})).filter(({name:e})=>"Insurance scheme"===e||"Policy Number"===e)};function b(){let e=`${r.B}billableService?v=custom:(uuid,name,shortName,serviceStatus,serviceType:(display),servicePrices:(uuid,name,price,paymentMode))`;return(0,i.useOpenmrsFetchAll)(e)}let E=e=>{let t=`${r.B}bill`;return(0,i.openmrsFetch)(t,{method:"POST",body:e,headers:{"Content-Type":"application/json"}})},g=e=>{let t=`${r.B}bill/${e.uuid}`;return(0,i.openmrsFetch)(t,{method:"POST",body:e,headers:{"Content-Type":"application/json"}})},y=e=>{let t=`${r.B}bill/${e}`;return(0,i.openmrsFetch)(t,{method:"POST",body:{status:s.ih.POSTED},headers:{"Content-Type":"application/json"}})},h=(e,t)=>{let a=`${r.B}billLineItem/${e}?reason=${encodeURIComponent(t)}`;return(0,i.openmrsFetch)(a,{method:"DELETE"})},v=(e,t)=>{let a=`${r.B}bill/${e}?reason=${encodeURIComponent(t)}`;return(0,i.openmrsFetch)(a,{method:"DELETE"})},f=e=>`${r.B}patientPaymentStatus/${e}`,C=e=>{let t=f(e),{data:a,error:n,isLoading:r,isValidating:s,mutate:o}=(0,l.Ay)(e?t:null,i.openmrsFetch);return{paymentStatus:a?.data,error:n,isLoading:r,isValidating:s,mutate:o}}},7003(e,t,a){"use strict";a.d(t,{B:()=>n});var l=a(3137);let n=`${l.restBaseUrl}/billing/`},2373(e,t,a){"use strict";a.d(t,{Zz:()=>n,aL:()=>i,o_:()=>r});var l=a(3137);function n(e){return Array.isArray(e)?e.reduce((e,t)=>"number"==typeof t.price&&"number"==typeof t.quantity&&!0!==t.voided?e+t.price*t.quantity:e,0):0}let i=(e,t)=>{let a=window.i18next?.language?.substring(0,2)??"",l=new Intl.NumberFormat(a,{style:"currency",currency:t,minimumFractionDigits:2}).format(Math.abs(e));return e<0&&(l=`(${l})`),l},r=(e,t)=>{switch(e){case"male":return(0,l.getCoreTranslation)("male");case"female":return(0,l.getCoreTranslation)("female");case"other":return(0,l.getCoreTranslation)("other");case"unknown":return(0,l.getCoreTranslation)("unknown");default:return e}}},1772(e,t,a){"use strict";a.d(t,{aL:()=>l.aL,o_:()=>l.o_});var l=a(2373)},7149(e,t,a){"use strict";let l,n,i,r,s;a.r(t),a.d(t,{refundRequestsLeftPanelLink:()=>tP,deletePaymentModeModal:()=>tu,billingDashboardLink:()=>te,billingFormWorkspace:()=>tg,discountRequestsLeftPanelLink:()=>tk,importTranslation:()=>e9,billingSettingsLeftPanelMenu:()=>tv,billingCheckInForm:()=>tr,billableServicesAppMenuItem:()=>tl,billableServicesCardLink:()=>tn,deleteBillConfirmationModal:()=>tN,billingSummaryDashboardLink:()=>ta,editBillLineItemModal:()=>t_,patientPaymentStatusTag:()=>tE,finalizeBillConfirmationModal:()=>tC,requestDiscountModal:()=>tT,requestRefundModal:()=>tD,visitBillsPanel:()=>to,billingPatientSummary:()=>ts,billableServicesLeftPanelLink:()=>th,startupApp:()=>tt,paymentModeFormModal:()=>tm,reviewBillRefundsModal:()=>tA,billableServicesHome:()=>ti,addCashPointModal:()=>td,deleteLineItemConfirmationModal:()=>tf,reviewBillDiscountsModal:()=>tS,visitAttributeTags:()=>tb,requirePaymentModal:()=>tc,billableServiceFormWorkspace:()=>ty,root:()=>tp});var o=a(2383),c=a(4499),m=a(3989),u=a(771),d=a(3137),_=a(5275),p=a.n(_),b=a(7767),E=a(4976),g=a(8395);function y({config:e}){let{t}=(0,g.useTranslation)(),{name:a,title:l}=e,n=(0,b.zy)(),i=window.getOpenmrsSpaBase()+"home",r=(0,_.useMemo)(()=>n.pathname.split("/").map(e=>decodeURIComponent(e)).includes(a),[n.pathname,a]);return p().createElement(d.ConfigurableLink,{to:i+"/"+a,className:`cds--side-nav__link ${r&&"active-left-nav-link"}`},t(l))}var h=a(6800);function v({config:e}){let{title:t,path:a,icon:l,privilege:n}=e,{t:i}=(0,g.useTranslation)(),r=(0,b.zy)(),s=`${window.spaBase}/billable-services`,o=(0,_.useMemo)(()=>{let e=r.pathname.replace(s,"");return""===a||"/"===a?""===e||"/"===e:e.startsWith(`/${a}`)},[r.pathname,a,s]),c=p().createElement(h.VxE,{onClick:()=>{(0,d.navigate)({to:`${s}/${a}`})},renderIcon:l,isActive:o},i(t));return n?p().createElement(d.UserHasAccess,{privilege:n},c):c}function f({config:e}){let{title:t,icon:a,items:l,privilege:n}=e,{t:i}=(0,g.useTranslation)(),r=`${window.spaBase}/billable-services`,s=p().createElement(h.whj,{defaultExpanded:!0,title:i(t),renderIcon:a},l.map(e=>p().createElement(h.ldn,{key:e.name,onClick:()=>{var t;return t=e.path,void(0,d.navigate)({to:`${r}/${t}`})}},i(e.title))));return n?p().createElement(d.UserHasAccess,{privilege:n},s):s}function C({config:e}){let{title:t,path:a,icon:l}=e,{t:n}=(0,g.useTranslation)(),i=(0,b.zy)(),r=`${window.spaBase}/billable-services`,s=(0,_.useMemo)(()=>{let e=i.pathname.replace(r,"");return""===a||"/"===a?""===e||"/"===e:e.startsWith(`/${a}`)},[i.pathname,a,r]);return p().createElement(h.VxE,{onClick:()=>{(0,d.navigate)({to:`${r}/${a}`})},renderIcon:l,isActive:s},n(t))}function N({config:e}){let{title:t,path:a,icon:l}=e,{t:n}=(0,g.useTranslation)(),i=(0,b.zy)(),r=`${globalThis.spaBase}/billable-services`,s=(0,_.useMemo)(()=>{let e=i.pathname.replace(r,"");return""===a||"/"===a?""===e||"/"===e:e.startsWith(`/${a}`)},[i.pathname,a,r]);return p().createElement(h.VxE,{onClick:()=>{(0,d.navigate)({to:`${r}/${a}`})},renderIcon:l,isActive:s},n(t))}var T=a(9564),S=a(6942),k=a.n(S),D=a(2137),A=a(6994);function P({layout:e,handleSearch:t,isValidating:a,launchBillableServiceForm:l,responsiveSize:n,t:i}){return p().createElement(p().Fragment,null,p().createElement("div",{className:"-esm-billing__billable-services__headerContainer___Jom5Q"},p().createElement("div",{className:k()({"-esm-billing__billable-services__tabletHeading___DjbOL":!(0,d.isDesktop)(e),"-esm-billing__billable-services__desktopHeading___JApyg":(0,d.isDesktop)(e)})},p().createElement("h4",null,i("servicesList","Services list"))),p().createElement("div",{className:"-esm-billing__billable-services__backgroundDataFetchingIndicator___Icc-9"},p().createElement("span",null,a?p().createElement(h.OuH,null):null))),p().createElement("div",{className:"-esm-billing__billable-services__actionsContainer___gjC3h"},p().createElement(h.vji,{labelText:"",placeholder:i("filterTable","Filter table"),onChange:t,size:n}),p().createElement(h.$nd,{size:n,kind:"primary",renderIcon:e=>p().createElement(D.Qp,{size:16,...e}),onClick:l,iconDescription:i("addNewBillableService","Add new billable service")},i("addNewService","Add new service"))))}let w=()=>{let{t:e}=(0,g.useTranslation)(),{billableServices:t,isLoading:a,isValidating:l,error:n,mutate:i}=(0,A.ly)(),r=(0,d.useLayoutType)(),{pageSize:s}=(0,d.useConfig)(),[o,c]=(0,_.useState)(""),m=(0,d.isDesktop)(r)?"lg":"sm",[u,b]=(0,_.useState)(s??10),E=[{header:e("serviceName","Service name"),key:"serviceName"},{header:e("shortName","Short name"),key:"shortName"},{header:e("serviceType","Service type"),key:"serviceType"},{header:e("serviceStatus","Service status"),key:"status"},{header:e("prices","Prices"),key:"prices"}],y=(0,_.useCallback)(()=>{(0,d.launchWorkspace2)("billable-service-form",{onWorkspaceClose:i})},[i]),v=(0,_.useMemo)(()=>{let e=Array.isArray(t)?t.flat():t;if(void 0!==e&&e.length>0){let t=o.trim();if(t){let a=t.toLowerCase();return e.filter(e=>Object.entries(e).some(([e,t])=>"uuid"!==e&&`${t}`.toLowerCase().includes(a)))}}return e},[o,t]),{paginated:f,goTo:C,results:N,currentPage:T}=(0,d.usePagination)(v,u),S=[];N&&N.forEach(e=>{let t={id:e.uuid,uuid:e.uuid,serviceName:e.name,shortName:e.shortName,serviceType:e?.serviceType?.display,status:e.serviceStatus,prices:e.servicePrices.map(e=>`${e.name} (${e.price})`).join(", ")||"--"};S.push(t)});let k=(0,_.useCallback)(e=>{C(1),c(e.target.value)},[C,c]),D=(0,_.useCallback)(e=>{(0,d.launchWorkspace2)("billable-service-form",{serviceToEdit:e,onWorkspaceClose:i})},[i]);return a?p().createElement(h.OuH,{status:"active",iconDescription:(0,d.getCoreTranslation)("loading"),description:e("loading","Loading data")+"..."}):n?p().createElement(d.ErrorState,{headerTitle:e("billableService","Billable service"),error:n}):0===t.length?p().createElement(d.EmptyCard,{displayText:e("billableServices__lower","billable services"),headerTitle:e("billableService","Billable service"),launchForm:y}):p().createElement("div",{className:"-esm-billing__billable-services__serviceContainer___x-Geg"},p().createElement(P,{handleSearch:k,isValidating:l,launchBillableServiceForm:y,layout:r,responsiveSize:m,t:e}),p().createElement(h.bQt,{isSortable:!0,rows:S,headers:E,overflowMenuOnHover:(0,d.isDesktop)(r),size:m,useZebraStyles:S?.length>1},({rows:t,headers:a,getHeaderProps:l,getRowProps:n,getTableProps:i})=>p().createElement(h.K3K,null,p().createElement(h.XIK,{...i(),"aria-label":e("serviceList","Service list")},p().createElement(h.ndF,null,p().createElement(h.Hjg,null,a.map(e=>p().createElement(h.A0N,{...l({header:e}),key:e.key},e.header)),p().createElement(h.A0N,{"aria-label":(0,d.getCoreTranslation)("actions")}))),p().createElement(h.BFY,null,t.map(t=>p().createElement(h.Hjg,{key:t.id,...n({row:t})},t.cells.map(e=>p().createElement(h.nA6,{key:e.id},e.value)),p().createElement(h.nA6,{className:"cds--table-column-menu"},p().createElement(h.obU,{size:"lg",flipped:!0},p().createElement(h.XSD,{className:"-esm-billing__billable-services__menuItem___yk74T",itemText:e("editBillableService","Edit billable service"),onClick:()=>D(N.find(e=>e.uuid===t.id))}))))))))),v?.length===0&&p().createElement("div",{className:"-esm-billing__billable-services__filterEmptyState___Gklg-"},p().createElement(h.Wdr,{level:0},p().createElement(h.FAs,{className:"-esm-billing__billable-services__filterEmptyStateTile___DHTbi"},p().createElement("p",{className:"-esm-billing__billable-services__filterEmptyStateContent___n3TI3"},e("noMatchingServicesToDisplay","No matching services to display")),p().createElement("p",{className:"-esm-billing__billable-services__filterEmptyStateHelper___pVBoH"},e("checkFilters","Check the filters above"))))),f&&p().createElement(h.dKS,{forwardText:e("nextPage","Next page"),backwardText:e("previousPage","Previous page"),page:T,pageSize:u,pageSizes:[10,20,30,40,50],totalItems:v?.length,className:"-esm-billing__billable-services__pagination___UwJIA",size:m,onChange:({pageSize:e,page:t})=>{e!==u&&b(e),t!==T&&C(t)}}))};function I(){return p().createElement("main",{className:"-esm-billing__dashboard__container___PDlGf"},p().createElement("main",{className:"-esm-billing__dashboard__servicesTableContainer___m7wfM"},p().createElement(w,null)))}let L=()=>p().createElement("svg",{width:"64",height:"64",viewBox:"10 10 60 60.02"},p().createElement("title",null,"Billing module illustration"),p().createElement("g",{fill:"none",fillRule:"evenodd"},p().createElement("path",{opacity:"0.5",d:"M58.75 68.639C60.8886 66.8242 64.1114 66.8242 66.25 68.639C67.703 69.8719 70 68.8873 70 67.0314V12.9686C70 11.1128 67.703 10.1281 66.25 11.3611C64.1114 13.1758 60.8886 13.1758 58.75 11.3611C56.6114 9.54632 53.3886 9.54632 51.25 11.3611C49.1114 13.1758 45.8886 13.1758 43.75 11.3611C41.6114 9.54632 38.3886 9.54632 36.25 11.3611C34.1114 13.1758 30.8886 13.1758 28.75 11.3611C26.6114 9.54632 23.3886 9.54632 21.25 11.3611C19.1114 13.1758 15.8886 13.1758 13.75 11.3611C12.297 10.1281 10 11.1128 10 12.9686V67.0314C10 68.8873 12.297 69.8719 13.75 68.639C15.8886 66.8242 19.1114 66.8242 21.25 68.639C23.3886 70.4537 26.6114 70.4537 28.75 68.639C30.8886 66.8242 34.1114 66.8242 36.25 68.639C38.3886 70.4537 41.6114 70.4537 43.75 68.639C45.8886 66.8242 49.1114 66.8242 51.25 68.639C53.3886 70.4537 56.6114 70.4537 58.75 68.639Z",fill:"#CEE6E5"}),p().createElement("path",{d:"M22.5 51.6666C22.5 50.2859 23.6193 49.1666 25 49.1666H55C56.3807 49.1666 57.5 50.2859 57.5 51.6666C57.5 53.0474 56.3807 54.1666 55 54.1666H25C23.6193 54.1666 22.5 53.0474 22.5 51.6666Z",fill:"#7BBCB9"}),p().createElement("path",{d:"M22.5 40C22.5 38.6193 23.6193 37.5 25 37.5H55C56.3807 37.5 57.5 38.6193 57.5 40C57.5 41.3807 56.3807 42.5 55 42.5H25C23.6193 42.5 22.5 41.3807 22.5 40Z",fill:"#7BBCB9"}),p().createElement("path",{d:"M22.5 28.3333C22.5 26.9526 23.6193 25.8333 25 25.8333H55C56.3807 25.8333 57.5 26.9526 57.5 28.3333C57.5 29.714 56.3807 30.8333 55 30.8333H25C23.6193 30.8333 22.5 29.714 22.5 28.3333Z",fill:"#7BBCB9"}))),M=({title:e})=>{let{t}=(0,g.useTranslation)();return p().createElement("div",{className:"-esm-billing__billing-header__header___P+PIw","data-testid":"billing-header"},p().createElement("div",{className:"-esm-billing__billing-header__left-justified-items___0FINv"},p().createElement(L,null),p().createElement("div",{className:"-esm-billing__billing-header__page-labels___Z52tc"},p().createElement("p",null,t("billing","Billing")),p().createElement("p",{className:"-esm-billing__billing-header__page-name___uiEHw"},e))))},B=()=>{let{t:e}=(0,g.useTranslation)(),[t,a]=(0,_.useState)([]),l=(0,_.useCallback)(async()=>{try{let e=await (0,d.openmrsFetch)(`${d.restBaseUrl}/billing/cashPoint?v=full`);a(e.data.results||[])}catch(t){(0,d.showSnackbar)({title:(0,d.getCoreTranslation)("error"),subtitle:e("errorFetchingCashPoints","An error occurred while fetching cash points."),kind:"error",isLowContrast:!1})}},[e]);(0,_.useEffect)(()=>{l()},[l]);let n=t.map(e=>({id:e.uuid,name:e.name,uuid:e.uuid,location:e.location?e.location.display:"None"})),i=[{key:"name",header:e("name","Name")},{key:"uuid",header:e("uuid","UUID")},{key:"location",header:e("location","Location")}];return p().createElement("div",{className:"-esm-billing__cash-point-configuration__container___-hvwr"},p().createElement("div",{className:"-esm-billing__cash-point-configuration__card___ytTem"},p().createElement(d.CardHeader,{title:e("cashPointHistory","Cash point history")},p().createElement(h.$nd,{renderIcon:D.OM,onClick:()=>{let e=(0,d.showModal)("add-cash-point-modal",{onCashPointAdded:l,closeModal:()=>e()})},kind:"ghost"},e("addNewCashPoint","Add new cash point"))),p().createElement("div",null,p().createElement(h.bQt,{rows:n,headers:i,isSortable:!0,size:"lg"},({rows:e,headers:t,getTableProps:a,getHeaderProps:l,getRowProps:n})=>p().createElement(h.K3K,null,p().createElement(h.XIK,{className:"-esm-billing__cash-point-configuration__table___x+kW9",...a()},p().createElement(h.ndF,null,p().createElement(h.Hjg,null,t.map(e=>p().createElement(h.A0N,{key:e.key,...l({header:e})},e.header)))),p().createElement(h.BFY,null,e.map(e=>p().createElement(h.Hjg,{key:e.id,...n({row:e})},e.cells.map(e=>p().createElement(h.nA6,{key:e.id},e.value)))))))))))},R="-esm-billing__payment-modes-config__menuItem___7qBhO",q=()=>{let{t:e}=(0,g.useTranslation)(),{paymentModes:t,error:a,isLoadingPaymentModes:l}=(0,A.WJ)(),n=t.map(e=>({id:e.uuid,name:e.name,description:e.description||"--"})),i=[{key:"name",header:e("name","Name")},{key:"description",header:e("description","Description")},{key:"actions",header:(0,d.getCoreTranslation)("actions")}];return l?p().createElement(h.OuH,{status:"active",iconDescription:(0,d.getCoreTranslation)("loading"),description:e("loading","Loading data")+"..."}):a?p().createElement(d.ErrorState,{headerTitle:e("paymentMode","Payment mode"),error:a}):p().createElement("div",{className:"-esm-billing__payment-modes-config__container___hB7Cc"},p().createElement("div",{className:"-esm-billing__payment-modes-config__card___FGL9q"},p().createElement(d.CardHeader,{title:e("paymentModeHistory","Payment mode history")},p().createElement(h.$nd,{renderIcon:D.OM,onClick:()=>{let e=(0,d.showModal)("payment-mode-form-modal",{closeModal:()=>e()})},kind:"ghost"},e("addNewPaymentMode","Add new payment mode"))),p().createElement(h.bQt,{rows:n,headers:i,isSortable:!0,size:"lg"},({rows:e,headers:a,getTableProps:l,getHeaderProps:n,getRowProps:i})=>p().createElement(h.K3K,null,p().createElement(h.XIK,{className:"-esm-billing__payment-modes-config__table___Zs7R+",...l()},p().createElement(h.ndF,null,p().createElement(h.Hjg,null,a.map(e=>p().createElement(h.A0N,{key:e.key,...n({header:e})},e.header)))),p().createElement(h.BFY,null,e.map(e=>p().createElement(h.Hjg,{key:e.id,...i({row:e})},e.cells.map(a=>"actions"!==a.info.header?p().createElement(h.nA6,{key:a.id},a.value):p().createElement(h.nA6,{key:a.id},p().createElement(h.obU,null,p().createElement(h.XSD,{className:R,itemText:(0,d.getCoreTranslation)("edit"),onClick:()=>{let a,l=t.find(t=>t.uuid===e.id);l&&(a=(0,d.showModal)("payment-mode-form-modal",{editPaymentMode:l,closeModal:()=>a()}))}}),p().createElement(h.XSD,{className:R,itemText:(0,d.getCoreTranslation)("delete"),onClick:()=>{let a,l=t.find(t=>t.uuid===e.id);l&&(a=(0,d.showModal)("delete-payment-mode-modal",{paymentModeUuid:l.uuid,paymentModeName:l.name,closeModal:()=>a()}))}}))))))))))))};var F=a(1772),x=a(9324),j=a(7003);let $=`${j.B}billDiscount`,U=`${j.B}bill`;async function H(e){return(await (0,d.openmrsFetch)($,{method:"POST",headers:{"Content-Type":"application/json"},body:e})).data}async function O(e,t,a){return(await (0,d.openmrsFetch)(`${$}/${e}`,{method:"POST",headers:{"Content-Type":"application/json"},body:{status:t,approver:a}})).data}async function z(e,t){await (0,d.openmrsFetch)(`${$}/${e}?reason=${encodeURIComponent(t)}`,{method:"DELETE"})}var V=a(5084);let K={container:"-esm-billing__discount-requests__container___Oz7Sy",servicesTableContainer:"-esm-billing__discount-requests__servicesTableContainer___LRvfc",sectionMargin:"-esm-billing__discount-requests__sectionMargin___xsMap",emptyStateContainer:"-esm-billing__discount-requests__emptyStateContainer___5+u6v",loaderContainer:"-esm-billing__discount-requests__loaderContainer___UxUmn",errorContainer:"-esm-billing__discount-requests__errorContainer___lTCUs",billListContainer:"-esm-billing__discount-requests__billListContainer___Iy16I",filterEmptyState:"-esm-billing__discount-requests__filterEmptyState___OqM0-",filterContainer:"-esm-billing__discount-requests__filterContainer___4mog+",headerContainer:"-esm-billing__discount-requests__headerContainer___OQEp3",row:"-esm-billing__discount-requests__row___yW0Qk",statusTags:"-esm-billing__discount-requests__statusTags___lGmnm",illo:"-esm-billing__discount-requests__illo___f7Xua",content:"-esm-billing__discount-requests__content___FlVLI",desktopHeading:"-esm-billing__discount-requests__desktopHeading___jySob",tabletHeading:"-esm-billing__discount-requests__tabletHeading___LE23P",tile:"-esm-billing__discount-requests__tile___pM5j8",filterEmptyStateTile:"-esm-billing__discount-requests__filterEmptyStateTile___0XhKz",filterEmptyStateContent:"-esm-billing__discount-requests__filterEmptyStateContent___8LzTm",filterEmptyStateHelper:"-esm-billing__discount-requests__filterEmptyStateHelper___G-NDy"};function W({layout:e,handleSearch:t,isValidating:a,responsiveSize:l,searchString:n,t:i}){return p().createElement(p().Fragment,null,p().createElement("div",{className:K.headerContainer},p().createElement("div",{className:k()({[K.tabletHeading]:!(0,d.isDesktop)(e),[K.desktopHeading]:(0,d.isDesktop)(e)})},p().createElement("h4",null,i("discountRequests","Discount requests"))),a&&p().createElement("div",{className:K.backgroundDataFetchingIndicator},p().createElement("span",null,p().createElement(h.OuH,null)))),p().createElement(h.vji,{closeButtonLabelText:i("clearSearch","Clear"),"data-testid":"discountRequestsSearchBar",labelText:i("searchDiscountRequests","Search discount requests"),placeholder:i("searchByPatientOrBill","Search by patient name or bill #"),value:n,onChange:t,size:l}))}let G=()=>{var e;let{t}=(0,g.useTranslation)(),{defaultCurrency:a,pageSize:l}=(0,d.useConfig)(),n=(0,d.useLayoutType)(),i=(0,d.isDesktop)(n)?"sm":"lg",r=(0,_.useMemo)(()=>[{id:"PENDING",text:t("pending","Pending")},{id:"APPROVED",text:t("approved","Approved")},{id:"REJECTED",text:t("rejected","Rejected")},{id:"ALL",text:t("all","All")}],[t]),[s,o]=(0,_.useState)(r[0]),[c,m]=(0,_.useState)(l??10),[u,b]=(0,_.useState)(""),{bills:E,isLoading:y,error:v,mutate:f,isValidating:C}=function({statuses:e}){let t=new URLSearchParams({discountStatus:e.join(","),v:"default"}),a=`${U}?${t.toString()}`,{data:l,isLoading:n,error:i,mutate:r,isValidating:s}=(0,d.useOpenmrsFetchAll)(a);return{bills:l??[],isLoading:n,error:i,mutate:r,isValidating:s}}({statuses:"ALL"===(e=s.id)?[V.nT.PENDING,V.nT.APPROVED,V.nT.REJECTED]:[e]}),N=(0,_.useMemo)(()=>{let e=u.trim().toLowerCase();return e?E.filter(t=>t.patient?.display?.toLowerCase().includes(e)||t.receiptNumber?.toLowerCase().includes(e)):E},[E,u]),{paginated:T,goTo:S,results:k,currentPage:D}=(0,d.usePagination)(N,c),{pageSizes:A}=(0,d.usePaginationInfo)(c,N.length,D,k.length),P=(0,_.useMemo)(()=>[{key:"dateCreated",header:t("date","Date")},{key:"receiptNumber",header:t("invoiceNo","Invoice #")},{key:"patient",header:t("patient","Patient")},{key:"billAmount",header:t("billAmount","Bill amount")},{key:"cashier",header:t("cashier","Cashier")}],[t]),w=(0,_.useCallback)(e=>{let t=(0,d.showModal)("review-bill-discounts-modal",{bill:e,onMutate:f,closeModal:()=>t()})},[f]),I=(0,_.useMemo)(()=>k.map(e=>({id:e.uuid,dateCreated:e.dateCreated?(0,d.formatDate)((0,d.parseDate)(e.dateCreated),{mode:"wide"}):"--",patient:e.patient?.display??"--",receiptNumber:e.receiptNumber?p().createElement(h.N_E,{href:"#",onClick:t=>{t.preventDefault(),t.stopPropagation(),w(e)}},e.receiptNumber):"--",billAmount:(0,F.aL)(e.total??0,a),cashier:e.cashier?.display??"--",_raw:e})),[k,a,w]),L=(0,_.useCallback)(e=>{b(e.target.value),S(1)},[S]);return p().createElement("main",{className:K.container},p().createElement("main",{className:K.servicesTableContainer},p().createElement("div",{className:K.filterContainer},p().createElement(h.msM,{className:K.filterDropdown,direction:"bottom",id:"discount-status-filter",selectedItem:s,items:r,itemToString:e=>e?e.text:"",label:"",onChange:({selectedItem:e})=>{o(e),S(1)},size:i,titleText:t("filterBy","Filter by:"),type:"inline"})),p().createElement("div",{className:K.billListContainer},p().createElement(W,{handleSearch:L,isValidating:C,layout:n,responsiveSize:i,searchString:u,t:t}),y&&!E?.length?p().createElement("div",{className:K.loaderContainer,role:"progressbar","aria-label":t("loadingDescription","Loading")},p().createElement(h.OOb,{rowCount:c,showHeader:!1,showToolbar:!1,zebra:!0,columnCount:P.length})):v?p().createElement("div",{className:K.errorContainer},p().createElement(h.Wdr,null,p().createElement(d.ErrorState,{error:v,headerTitle:t("discountRequests","Discount requests")}))):I.length>0?p().createElement(p().Fragment,null,p().createElement(h.bQt,{isSortable:!0,rows:I,headers:P,size:i,useZebraStyles:I.length>1},({rows:e,headers:a,getRowProps:l,getTableProps:n})=>p().createElement(h.K3K,null,p().createElement(h.XIK,{...n(),"aria-label":t("discountRequests","Discount requests")},p().createElement(h.ndF,null,p().createElement(h.Hjg,null,a.map(e=>p().createElement(h.A0N,{key:e.key},e.header)))),p().createElement(h.BFY,null,e.map(e=>p().createElement(h.Hjg,{key:e.id,...l({row:e}),className:K.row,onClick:()=>{let t=I.find(t=>t.id===e.id);t&&w(t._raw)}},e.cells.map(e=>p().createElement(h.nA6,{key:e.id},e.value)))))))),T&&p().createElement(h.dKS,{forwardText:t("nextPage","Next page"),backwardText:t("previousPage","Previous page"),page:D,pageSize:c,pageSizes:A,totalItems:N.length,size:i,onChange:({pageSize:e,page:t})=>{e!==c&&m(e),t!==D&&S(t)}})):p().createElement(h.Wdr,{className:K.emptyStateContainer},p().createElement(h.FAs,{className:K.tile},p().createElement("div",{className:K.illo},p().createElement(d.EmptyCardIllustration,null)),p().createElement("p",{className:K.content},t("noDiscountRequestsToDisplay","There are no discount requests to display.")))))))};var Q=a(8683);let J={container:"-esm-billing__refund-requests__container___Wt9xd",servicesTableContainer:"-esm-billing__refund-requests__servicesTableContainer___IChqx",sectionMargin:"-esm-billing__refund-requests__sectionMargin___aL-4-",emptyStateContainer:"-esm-billing__refund-requests__emptyStateContainer___UcXAt",loaderContainer:"-esm-billing__refund-requests__loaderContainer___ImaKM",errorContainer:"-esm-billing__refund-requests__errorContainer___WvLOw",billListContainer:"-esm-billing__refund-requests__billListContainer___fs+ZV",filterEmptyState:"-esm-billing__refund-requests__filterEmptyState___KAwFs",filterContainer:"-esm-billing__refund-requests__filterContainer___hP1MN",headerContainer:"-esm-billing__refund-requests__headerContainer___ooxMR",row:"-esm-billing__refund-requests__row___yKZOb",statusTags:"-esm-billing__refund-requests__statusTags___J2Aq7",illo:"-esm-billing__refund-requests__illo___CafiD",content:"-esm-billing__refund-requests__content___H+jeh",desktopHeading:"-esm-billing__refund-requests__desktopHeading___brWKR",tabletHeading:"-esm-billing__refund-requests__tabletHeading___GlO5d",tile:"-esm-billing__refund-requests__tile___gu7cO",filterEmptyStateTile:"-esm-billing__refund-requests__filterEmptyStateTile___5HpOu",filterEmptyStateContent:"-esm-billing__refund-requests__filterEmptyStateContent___wE5s3",filterEmptyStateHelper:"-esm-billing__refund-requests__filterEmptyStateHelper___m2t8f"};function X({layout:e,handleSearch:t,isValidating:a,responsiveSize:l,searchString:n,t:i}){return p().createElement(p().Fragment,null,p().createElement("div",{className:J.headerContainer},p().createElement("div",{className:k()({[J.tabletHeading]:!(0,d.isDesktop)(e),[J.desktopHeading]:(0,d.isDesktop)(e)})},p().createElement("h4",null,i("refundRequests","Refund requests"))),a&&p().createElement("span",null,p().createElement(h.OuH,null))),p().createElement(h.vji,{closeButtonLabelText:i("clearSearch","Clear"),"data-testid":"refundRequestsSearchBar",labelText:i("searchRefundRequests","Search refund requests"),placeholder:i("searchByPatientOrBill","Search by patient name or bill #"),value:n,onChange:t,size:l}))}let Z=()=>{var e;let t,{t:a}=(0,g.useTranslation)(),{defaultCurrency:l,pageSize:n}=(0,d.useConfig)(),i=(0,d.useLayoutType)(),r=(0,d.isDesktop)(i)?"sm":"lg",s=(0,_.useMemo)(()=>[{id:"REQUESTED",text:a("requested","Requested")},{id:"APPROVED",text:a("approved","Approved")},{id:"REJECTED",text:a("rejected","Rejected")},{id:"COMPLETED",text:a("completed","Completed")},{id:"ALL",text:a("all","All")}],[a]),[o,c]=(0,_.useState)(s[0]),[m,u]=(0,_.useState)(n??10),[b,E]=(0,_.useState)(""),{bills:y,isLoading:v,error:f,mutate:C,isValidating:N}=(0,Q.KY)({statuses:"ALL"===(e=o.id)?[V.fH.REQUESTED,V.fH.APPROVED,V.fH.REJECTED,V.fH.COMPLETED]:[e]}),T=(0,_.useMemo)(()=>{let e=b.trim().toLowerCase();return e?y.filter(t=>t.patient?.display?.toLowerCase().includes(e)||t.receiptNumber?.toLowerCase().includes(e)):y},[y,b]),{paginated:S,goTo:k,results:D,currentPage:A}=(0,d.usePagination)(T,m),{pageSizes:P}=(0,d.usePaginationInfo)(m,T.length,A,D.length),w=(0,_.useMemo)(()=>[{key:"dateCreated",header:a("date","Date")},{key:"receiptNumber",header:a("invoiceNo","Invoice #")},{key:"patient",header:a("patient","Patient")},{key:"billAmount",header:a("billAmount","Bill amount")},{key:"cashier",header:a("cashier","Cashier")}],[a]),I=(0,_.useCallback)(e=>{let t=(0,d.showModal)("review-bill-refunds-modal",{bill:e,onMutate:C,closeModal:()=>t()})},[C]),L=(0,_.useMemo)(()=>D.map(e=>({id:e.uuid,dateCreated:e.dateCreated?(0,d.formatDate)((0,d.parseDate)(e.dateCreated),{mode:"wide"}):"--",patient:e.patient?.display??"--",receiptNumber:e.receiptNumber?p().createElement(h.N_E,{href:"#",onClick:t=>{t.preventDefault(),t.stopPropagation(),I(e)}},e.receiptNumber):"--",billAmount:(0,F.aL)(e.total??0,l),cashier:e.cashier?.display??"--",_raw:e})),[D,l,I]),M=(0,_.useCallback)(e=>{E(e.target.value),k(1)},[k]),B=(0,_.useCallback)(e=>{let t=L.find(t=>t.id===e);t&&I(t._raw)},[L,I]);return t=v&&!y?.length?p().createElement("div",{className:J.loaderContainer,"aria-busy":"true","aria-label":a("loading","Loading")},p().createElement(h.OOb,{rowCount:m,showHeader:!1,showToolbar:!1,zebra:!0,columnCount:w.length})):f?p().createElement("div",{className:J.errorContainer},p().createElement(h.Wdr,null,p().createElement(d.ErrorState,{error:f,headerTitle:a("refundRequests","Refund requests")}))):L.length>0?p().createElement(p().Fragment,null,p().createElement(h.bQt,{isSortable:!0,rows:L,headers:w,size:r,useZebraStyles:L.length>1},({rows:e,headers:t,getRowProps:l,getTableProps:n})=>p().createElement(h.K3K,null,p().createElement(h.XIK,{...n(),"aria-label":a("refundRequests","Refund requests")},p().createElement(h.ndF,null,p().createElement(h.Hjg,null,t.map(e=>p().createElement(h.A0N,{key:e.key},e.header)))),p().createElement(h.BFY,null,e.map(e=>p().createElement(h.Hjg,{key:e.id,...l({row:e}),className:J.row,onClick:()=>B(e.id)},e.cells.map(e=>p().createElement(h.nA6,{key:e.id},e.value)))))))),S&&p().createElement(h.dKS,{forwardText:a("nextPage","Next page"),backwardText:a("previousPage","Previous page"),page:A,pageSize:m,pageSizes:P,totalItems:T.length,size:r,onChange:({pageSize:e,page:t})=>{e!==m&&u(e),t!==A&&k(t)}})):p().createElement(h.Wdr,{className:J.emptyStateContainer},p().createElement(h.FAs,{className:J.tile},p().createElement("div",{className:J.illo},p().createElement(d.EmptyCardIllustration,null)),p().createElement("p",{className:J.content},a("noRefundRequestsToDisplay","There are no refund requests to display.")))),p().createElement("main",{className:J.container},p().createElement("div",{className:J.servicesTableContainer},p().createElement("div",{className:J.filterContainer},p().createElement(h.msM,{className:J.filterDropdown,direction:"bottom",id:"refund-status-filter",selectedItem:o,items:s,itemToString:e=>e?e.text:"",label:"",onChange:({selectedItem:e})=>{c(e),k(1)},size:r,titleText:a("filterBy","Filter by:"),type:"inline"})),p().createElement("div",{className:J.billListContainer},p().createElement(X,{handleSearch:M,isValidating:N,layout:i,responsiveSize:r,searchString:b,t:a}),t)))};var Y=a(6199);let ee="-esm-billing__bill-action-menu__menuItem___IEXNy",et=({bill:e,patientUuid:t,onMutate:a})=>{let{t:l}=(0,g.useTranslation)(),n=(0,d.useLayoutType)(),i=e?.status===V.ih.PENDING;return p().createElement(h.Wdr,null,p().createElement(h.obU,{align:"left",flipped:!0,size:(0,d.isDesktop)(n)?"sm":"lg","data-testid":`action-menu-${e.uuid}`},p().createElement(h.XSD,{className:ee,itemText:l("addItemsToBill","Add items to bill"),onClick:()=>(0,d.launchWorkspace2)("patient-chart-billing-form-workspace",{patientUuid:t,billUuid:e.uuid,onMutate:a})}),i&&p().createElement(h.XSD,{className:ee,hasDivider:!0,isDelete:!0,itemText:l("deleteBill","Delete bill"),onClick:()=>{let t=(0,d.showModal)("delete-bill-confirmation-modal",{bill:e,onSuccess:a,closeModal:()=>t()})}})))};var ea=a(6762),el=a(4476),en=a(3285),ei=a(9785),er=a(1362);let es={sectionContainer:"-esm-billing__visit-attributes-form__sectionContainer___aj98I",sectionTitle:"-esm-billing__visit-attributes-form__sectionTitle___kol0c",visitAttributesContainer:"-esm-billing__visit-attributes-form__visitAttributesContainer___ArSYD",radioButtonGroup:"-esm-billing__visit-attributes-form__radioButtonGroup___mSIc2",stack:"-esm-billing__visit-attributes-form__stack___HU1se",paymentDetailsLegend:"-esm-billing__visit-attributes-form__paymentDetailsLegend___uTIXR"},eo=el.z.object({paymentDetails:el.z.string(),paymentMethods:el.z.string(),insuranceSchema:el.z.string(),policyNumber:el.z.string(),patientCategory:el.z.string()}),ec=({setAttributes:e,setPaymentMethod:t})=>{let{t:a}=(0,g.useTranslation)(),{patientCategory:l,categoryConcepts:n,nonPayingPatientCategories:i}=(0,d.useConfig)(),{control:r,getValues:s,watch:o}=(0,ei.mN)({mode:"all",defaultValues:{},resolver:(0,en.u)(eo)}),[c,m,u,b,E]=o(["paymentDetails","paymentMethods","insuranceScheme","policyNumber","patientCategory"]),{paymentModes:y,isLoading:v}=(()=>{let e=`${j.B}paymentMode`,{data:t,isLoading:a,error:l}=(0,x.Ay)(e,d.openmrsFetch);return{isLoading:a,error:l,paymentModes:t?.data?.results??[]}})(),f=(0,_.useMemo)(()=>Object.entries(i??{}).map(([e,t])=>({text:a(e),uuid:t})),[i,a]),C=(0,_.useCallback)(()=>{let{paymentDetails:e,paymentMethods:a,insuranceScheme:n,policyNumber:i,patientCategory:r}=s();return t?.(a),Object.entries([{uuid:l.paymentDetails,value:e},{uuid:l.paymentMethods,value:a},{uuid:l.insuranceScheme,value:n},{uuid:l.policyNumber,value:i},{uuid:l.patientCategory,value:r}].filter(e=>void 0!==e.value&&null!==e.value&&""!==e.value)).map(([e,t])=>({attributeType:t.uuid,value:t.value}))},[s,l.insuranceScheme,l.patientCategory,l.paymentDetails,l.paymentMethods,l.policyNumber,t]);return((0,_.useEffect)(()=>{e(C())},[c,m,u,b,E,e,C]),v)?p().createElement(h.OuH,{status:"active",iconDescription:a("loadingDescription","Loading"),description:a("loading","Loading data")+"..."}):p().createElement(h.BJc,{className:es.stack,gap:5},p().createElement(ei.xI,{name:"paymentDetails",control:r,render:({field:e})=>p().createElement(h.zWQ,{className:es.radioButtonGroup,legendText:p().createElement("div",{className:es.paymentDetailsLegend},a("paymentDetails","Payment details"),p().createElement(h.Gff,{autoAlign:!0,align:"bottom"},p().createElement(h.yvu,{label:a("showInformation","Show information")},p().createElement(er.$$,null)),p().createElement(h.pNg,null,p().createElement("p",null,a("nonPayingInfo","Any services rendered to non-paying patients will not be billed"))))),name:"payment-details",onChange:t=>e.onChange(t),orientation:"vertical"},p().createElement(h.aaP,{labelText:a("paying","Paying"),value:n.payingDetails,id:"payment-details-paying"}),p().createElement(h.aaP,{labelText:a("nonPaying","Non paying"),value:n.nonPayingDetails,id:"payment-details-non-paying"}))}),c===n.payingDetails&&p().createElement(ei.xI,{control:r,name:"paymentMethods",render:({field:e})=>p().createElement(h.a32,{id:"paymentMethods",items:y,itemToString:e=>e?e.name:"",onChange:({selectedItem:t})=>e.onChange(t?.uuid),placeholder:a("selectPaymentMethod","Select payment method"),titleText:a("paymentMethod","Payment method")})}),m===n.insuranceDetails&&c===n.payingDetails&&p().createElement(p().Fragment,null,p().createElement(ei.xI,{control:r,name:"insuranceScheme",render:({field:e})=>p().createElement(h.ksK,{id:"insurance-scheme",labelText:a("insuranceScheme","Insurance scheme"),onChange:t=>e.onChange(t.target.value),type:"text"})}),p().createElement(ei.xI,{control:r,name:"policyNumber",render:({field:e})=>p().createElement(h.ksK,{...e,id:"policy-number",labelText:a("policyNumber","Policy number"),onChange:t=>e.onChange(t.target.value),type:"text"})})),c===n.nonPayingDetails&&p().createElement(ei.xI,{control:r,name:"patientCategory",render:({field:e})=>p().createElement(h.a32,{className:es.sectionField,onChange:({selectedItem:t})=>e.onChange(t?.uuid),id:"patientCategory",items:f,itemToString:e=>e?e.text:"",titleText:a("patientCategory","Patient category"),placeholder:a("selectPatientCategory","Select patient category")})}))},em=p().memo(({patientUuid:e,setExtraVisitInfo:t})=>{let{t:a}=(0,g.useTranslation)(),{mutate:l}=(0,x.iX)(),{categoryConcepts:n}=(0,d.useConfig)(),{lastVisitInfo:i,isLoading:r,error:s}=(e=>{let t=`${d.restBaseUrl}/visit?patient=${e}&v=default&limit=1&sort=desc:startDatetime`,{data:a,isLoading:l,error:n}=(0,x.Ay)(e?t:null,d.openmrsFetch);return{lastVisitInfo:(0,_.useMemo)(()=>{let e=a?.data?.results;if(!e?.length)return null;let t=e[0],l=new Date(t.startDatetime);return isNaN(l.getTime())?null:{diffDays:Math.floor(Math.abs(Date.now()-l.getTime())/864e5),type:t.visitType?.display??"",location:t.location?.display??""}},[a]),isLoading:l,error:n}})(e);(0,_.useEffect)(()=>{s&&(0,d.showSnackbar)({title:a("lastVisitError","Last visit error"),subtitle:a("errorLoadingLastVisit","An error occurred while loading the last visit"),kind:"error"})},[s,a]);let{cashPoints:o,isLoading:c,error:m}=(()=>{let e=`${j.B}cashPoint`,{data:t,isLoading:a,error:l}=(0,x.Ay)(e,d.openmrsFetch);return{isLoading:a,error:l,cashPoints:t?.data?.results??[]}})(),{lineItems:u,isLoading:b,error:E}=(()=>{let e=`${j.B}billableService?v=custom:(uuid,name,shortName,serviceStatus,serviceType:(display),servicePrices:(uuid,name,price,paymentMode))`,{data:t,isLoading:a,error:l}=(0,x.Ay)(e,d.openmrsFetch);return{lineItems:t?.data?.results??[],isLoading:a,error:l}})(),[y,v]=(0,_.useState)([]),[f,C]=(0,_.useState)(null),[N,T]=(0,_.useState)(null),S=(0,_.useRef)(y);(0,_.useEffect)(()=>{S.current=y},[y]);let k=(0,_.useMemo)(()=>!!n?.nonPayingDetails&&!!y?.length&&y.some(e=>e.value===n.nonPayingDetails),[y,n]),D=(0,_.useMemo)(()=>!k&&f&&u?.length?u.filter(e=>e.servicePrices.some(e=>e.paymentMode?.uuid===f)):[],[u,f,k]);(0,_.useEffect)(()=>{t({createBillPayload:null,handleCreateExtraVisitInfo:null,attributes:S.current}),T(null)},[f,k,t]);let A=(0,_.useCallback)(async t=>{try{let n;await (n=`${j.B}bill`,(0,d.openmrsFetch)(n,{method:"POST",headers:{"Content-Type":"application/json"},body:t})),l((0,Y.Z5)(e)),(0,d.showSnackbar)({title:a("patientBill","Patient bill"),subtitle:a("billCreatedSuccessfully","Bill created successfully"),kind:"success"})}catch(e){(0,d.showSnackbar)({title:a("billCreationError","Bill creation error"),subtitle:a("errorCreatingBill","An error occurred while creating the bill"),kind:"error"})}},[l,a,e]),P=(0,_.useCallback)(({selectedItem:a})=>{T(a);let l=o?.[0]?.uuid??"",n=a?.uuid??"",i=a.servicePrices.find(e=>e.paymentMode?.uuid===f)||a?.servicePrices[0],r={lineItems:[{billableService:n,quantity:1,price:i?i.price:"0.000",priceName:"Default",priceUuid:i?i.uuid:"",lineItemOrder:0,status:V.zk.PENDING}],cashPoint:l,patient:e,status:V.ih.PENDING,payments:[]};t({createBillPayload:r,handleCreateExtraVisitInfo:()=>A(r),attributes:y})},[y,o,A,f,e,t]);return b||c?p().createElement(h.OuH,{status:"active",iconDescription:(0,d.getCoreTranslation)("loading"),description:`${a("loadingBillingServices","Loading billing services")}...`}):m||E?p().createElement(h.jeF,{kind:"error",lowContrast:!0,title:a("billErrorService","Billing service error"),subtitle:a("errorLoadingBillServices","Error loading bill services")}):p().createElement("section",{className:"-esm-billing__billing-checkin-form__sectionContainer___TLb4u"},p().createElement("h1",{className:"-esm-billing__billing-checkin-form__sectionLabel___1H1hH"},a("billingDetails","Billing details")),p().createElement("div",{className:"-esm-billing__billing-checkin-form__sectionField___AUKom"},!r&&!s&&i&&p().createElement("div",{className:"-esm-billing__billing-checkin-form__lastVisitBanner___Bh8FX"},p().createElement(h.jeF,{hideCloseButton:!0,kind:"info",title:a("lastVisitInfo","Last Visit Information"),subtitle:a("lastVisitMsg","The last visit was a {{type}} {{count}} days ago at {{location}}",{count:i.diffDays,type:i.type,location:i.location}),lowContrast:!0})),p().createElement(ec,{setAttributes:v,setPaymentMethod:C}),D.length>0&&p().createElement(h.msM,{key:`billable-${f}`,id:"billable-items",items:D,itemToString:e=>{let t;return e?`${e.name} ${(t=e.servicePrices.find(e=>e.paymentMode?.uuid===f))?`(${t.name}: ${t.price})`:""}`:""},label:a("selectBillableService","Select a billable service"),onChange:P,selectedItem:N,titleText:a("billableService","Billable service")})))});var eu=a(7661);let ed={sectionTitle:"-esm-billing__bill-item-actions__sectionTitle___VJZLU",modalBody:"-esm-billing__bill-item-actions__modalBody___FImqs",billInfo:"-esm-billing__bill-item-actions__billInfo___grzHg",separator:"-esm-billing__bill-item-actions__separator___CKXsJ",label:"-esm-billing__bill-item-actions__label___FwJ2Z",controlField:"-esm-billing__bill-item-actions__controlField___vJUpf",loader:"-esm-billing__bill-item-actions__loader___UfgTz"},e_="-esm-billing__request-discount-modal__summaryLabel___VaWqh",ep="-esm-billing__request-discount-modal__summaryValue___d6IJk",eb="-esm-billing__bill-line-items-table__right___TBXRJ",eE=({lineItems:e})=>{let{t}=(0,g.useTranslation)(),{defaultCurrency:a}=(0,d.useConfig)();return p().createElement("section",{className:"-esm-billing__bill-line-items-table__ledger___qbKwi"},p().createElement("h3",{className:"-esm-billing__bill-line-items-table__ledgerHeading___M7DcA"},t("lineItems","Line items")),p().createElement("table",{className:"-esm-billing__bill-line-items-table__ledgerTable___Lw3pG"},p().createElement("thead",null,p().createElement("tr",null,p().createElement("th",null,t("item","Item")),p().createElement("th",null,t("qty","Qty")),p().createElement("th",{className:eb},t("price","Price")))),p().createElement("tbody",null,e.map((e,t)=>p().createElement("tr",{key:e.uuid??t},p().createElement("td",{className:"-esm-billing__bill-line-items-table__itemName___dKItf"},e.item||e.billableService||"--"),p().createElement("td",null,e.quantity),p().createElement("td",{className:eb},(0,F.aL)(e.price??0,a)))))))},eg="-esm-billing__bill-payments-table__right___qD-5O",ey=({payments:e})=>{let{t}=(0,g.useTranslation)(),{defaultCurrency:a}=(0,d.useConfig)();return 0===e.length?null:p().createElement("section",{className:"-esm-billing__bill-payments-table__ledger___Qc+ke"},p().createElement("h3",{className:"-esm-billing__bill-payments-table__ledgerHeading___ilV8F"},t("payments","Payments")),p().createElement("table",{className:"-esm-billing__bill-payments-table__ledgerTable___lHxsT"},p().createElement("thead",null,p().createElement("tr",null,p().createElement("th",null,t("method","Method")),p().createElement("th",null,t("date","Date")),p().createElement("th",{className:eg},t("tendered","Tendered")))),p().createElement("tbody",null,e.map(e=>p().createElement("tr",{key:e.uuid},p().createElement("td",null,p().createElement("span",{className:"-esm-billing__bill-payments-table__paymentKind___TglOe"},e.instanceType?.name??"--")),p().createElement("td",null,p().createElement("span",{className:"-esm-billing__bill-payments-table__paymentDate___9NyEF"},e.dateCreated?(0,d.formatDate)(new Date(e.dateCreated),{mode:"wide"}):"--")),p().createElement("td",{className:eg},(0,F.aL)(e.amountTendered??0,a)))))))},eh="-esm-billing__bill-totals-summary__totalsRow___r3Lew",ev="-esm-billing__bill-totals-summary__totalsRowMinus___2n1W4",ef=({subtotal:e,currentNet:t,outstanding:a,paymentsTotal:l,approvedDiscounts:n,pendingDiscounts:i})=>{let{t:r}=(0,g.useTranslation)(),{defaultCurrency:s}=(0,d.useConfig)();return p().createElement("section",{className:"-esm-billing__bill-totals-summary__totals___6iaM7"},p().createElement("div",{className:k()(eh,"-esm-billing__bill-totals-summary__totalsSubtotal___8mWZP")},p().createElement("span",null,r("subtotal","Subtotal")),p().createElement("span",null,(0,F.aL)(e,s))),n.map(e=>p().createElement("div",{key:e.uuid,className:k()(eh,ev)},p().createElement("span",null,"− ",r("discount","Discount")),p().createElement("span",null,(0,F.aL)(e.discountAmount,s)))),p().createElement("hr",{className:"-esm-billing__bill-totals-summary__totalsRule___LldMI"}),p().createElement("div",{className:k()(eh,"-esm-billing__bill-totals-summary__totalsNet___0Bb1l")},p().createElement("span",null,r("currentNet","Current net")),p().createElement("span",{className:"-esm-billing__bill-totals-summary__totalsNetAmount___xvxJT"},(0,F.aL)(t,s))),l>0&&p().createElement("div",{className:k()(eh,"-esm-billing__bill-totals-summary__totalsRowAdd___sbxAx")},p().createElement("span",null,"− ",r("paymentsReceived","Payments received")),p().createElement("span",null,(0,F.aL)(l,s))),p().createElement("hr",{className:"-esm-billing__bill-totals-summary__totalsRuleStrong___Kidyj"}),p().createElement("div",{className:k()(eh,"-esm-billing__bill-totals-summary__totalsOutstanding___fP1bD")},p().createElement("span",null,r("outstanding","Outstanding")),p().createElement("span",{className:"-esm-billing__bill-totals-summary__totalsOutstandingAmount___qQXu3"},(0,F.aL)(a,s))),i.length>0&&p().createElement("div",{className:"-esm-billing__bill-totals-summary__preview___rPSsf"},p().createElement("p",{className:"-esm-billing__bill-totals-summary__previewLabel___mjNu2"},r("ifPendingApproved","If pending discounts approved")),i.map(e=>p().createElement("div",{key:e.uuid,className:k()(eh,ev)},p().createElement("span",null,"− ",r("discount","Discount")," (",e.discountType===V.Bp.PERCENTAGE?`${e.discountValue}%`:(0,F.aL)(e.discountValue,s),")"),p().createElement("span",null,(0,F.aL)(e.discountAmount,s)))),p().createElement("div",{className:k()(eh,"-esm-billing__bill-totals-summary__previewProjected___bUPgY")},p().createElement("span",null,r("projectedNet","Projected net")),p().createElement("span",{className:"-esm-billing__bill-totals-summary__previewProjectedAmount___7yhBk"},(0,F.aL)(t-i.reduce((e,t)=>e+t.discountAmount,0),s)))))},eC=p().memo(({bill:e,lineItems:t,payments:a,paymentsTotal:l,subtotal:n,currentNet:i,outstanding:r,approvedDiscounts:s,pendingDiscounts:o})=>{let{t:c}=(0,g.useTranslation)();return p().createElement("aside",{className:"-esm-billing__bill-receipt-rail__receipt___b5het"},p().createElement("div",{className:"-esm-billing__bill-receipt-rail__patient___gB6Df"},p().createElement("div",null,p().createElement("p",{className:"-esm-billing__bill-receipt-rail__patientName___dNAHq"},e.patient?.display),p().createElement("p",{className:"-esm-billing__bill-receipt-rail__patientId___2KJ7G"},c("receiptNumber","Receipt #"),": ",e.receiptNumber)),e.status&&p().createElement(h.vwO,{type:"blue",size:"sm"},c(String(e.status).toLowerCase(),String(e.status)))),p().createElement("dl",{className:"-esm-billing__bill-receipt-rail__meta___F8p9R"},p().createElement("dt",null,c("issued","Issued")),p().createElement("dd",null,e.dateCreated?(0,d.formatDate)((0,d.parseDate)(e.dateCreated),{mode:"wide"}):"--"),p().createElement("dt",null,c("cashier","Cashier")),p().createElement("dd",null,e.cashier?.display??"--")),p().createElement(eE,{lineItems:t}),p().createElement(ey,{payments:a}),p().createElement(ef,{subtotal:n,currentNet:i,outstanding:r,paymentsTotal:l,approvedDiscounts:s,pendingDiscounts:o}))}),eN="-esm-billing__discount-card__confirmCopy___tkMH1",eT={PENDING:"gray",APPROVED:"green",REJECTED:"red"},eS=({discount:e,lineItems:t,busy:a,rejectingId:l,deletingId:n,canDecide:i,onApprove:r,onStartReject:s,onCancelReject:o,onConfirmReject:c,onStartDelete:m,onCancelDelete:u,onConfirmDelete:_})=>{let{t:b}=(0,g.useTranslation)(),{defaultCurrency:E}=(0,d.useConfig)(),y=l===e.uuid,v=n===e.uuid,f=!y&&!v,C=k()("-esm-billing__discount-card__card___LKhCs",{"-esm-billing__discount-card__cardPending___kkfK0":e.status===V.nT.PENDING,"-esm-billing__discount-card__cardApproved___e22b2":e.status===V.nT.APPROVED,"-esm-billing__discount-card__cardRejected___RSYBZ":e.status===V.nT.REJECTED}),N=e.discountType===V.Bp.PERCENTAGE?`${e.discountValue}%`:(0,F.aL)(e.discountValue,E),T=e.lineItemUuid?t.find(t=>t.uuid===e.lineItemUuid)?.item||t.find(t=>t.uuid===e.lineItemUuid)?.billableService||"--":b("wholeBill","Whole bill");return p().createElement("article",{className:C},p().createElement("header",{className:"-esm-billing__discount-card__cardTop___2KfsR"},p().createElement("div",{className:"-esm-billing__discount-card__cardScope___DFbYt"},p().createElement("span",{className:"-esm-billing__discount-card__cardScopeName___e0Gom"},T),p().createElement("span",{className:"-esm-billing__discount-card__cardScopeKind___YgWB0"},e.discountType===V.Bp.PERCENTAGE?b("percentage","Percentage"):b("fixedAmount","Fixed amount"))),e.status!==V.nT.PENDING&&p().createElement(h.vwO,{type:eT[e.status],size:"sm"},b(e.status.toLowerCase(),e.status))),p().createElement("div",{className:"-esm-billing__discount-card__cardFigure___2fn-w"},p().createElement("span",{className:k()("-esm-billing__discount-card__cardAmount___IsWoS",{"-esm-billing__discount-card__cardAmountVoided___VNogb":e.status===V.nT.REJECTED})},p().createElement("span",{className:"-esm-billing__discount-card__cardAmountMinus___eSUgX"},"−"),(0,F.aL)(e.discountAmount,E)),e.discountType===V.Bp.PERCENTAGE&&p().createElement("span",{className:"-esm-billing__discount-card__cardValue___pIy2C"},N)),p().createElement("div",null,b("reasonForDiscount","Reason for discount"),": ",p().createElement("p",{className:"-esm-billing__discount-card__cardJustification___ZbW6e"},e.justification)),p().createElement("footer",{className:"-esm-billing__discount-card__cardFooter___AlFbq"},p().createElement("div",{className:"-esm-billing__discount-card__cardByline___r8xcx"},b("requestedBy","Requested by")," ",p().createElement("strong",null,e.initiator?.display),p().createElement("span",{className:"-esm-billing__discount-card__cardBylineSep___VM4YL"},"\xb7"),(0,d.formatDate)((0,d.parseDate)(e.dateCreated),{mode:"wide"})),p().createElement("div",{className:"-esm-billing__discount-card__cardActions___bvhbQ"},f&&e.status===V.nT.PENDING&&p().createElement(p().Fragment,null,p().createElement(h.$nd,{kind:"danger--tertiary",size:"sm",disabled:!!a||!i,onClick:()=>s(e.uuid)},b("reject","Reject")),p().createElement(h.$nd,{kind:"primary",size:"sm",disabled:!!a||!i,onClick:()=>r(e)},b("approve","Approve"))),f&&p().createElement(h.$nd,{kind:"danger",size:"sm",disabled:!!a,onClick:()=>m(e.uuid)},b("delete","Delete")),y&&p().createElement(p().Fragment,null,p().createElement("span",{className:eN},b("rejectConfirm","Reject this discount?")),p().createElement(h.$nd,{kind:"ghost",size:"sm",onClick:o},(0,d.getCoreTranslation)("cancel")),p().createElement(h.$nd,{kind:"danger",size:"sm",disabled:!!a,onClick:()=>c(e)},b("confirmReject","Confirm reject"))),v&&p().createElement(p().Fragment,null,p().createElement("span",{className:eN},b("deleteConfirm","Delete this discount?")),p().createElement(h.$nd,{kind:"ghost",size:"sm",onClick:u},(0,d.getCoreTranslation)("cancel")),p().createElement(h.$nd,{kind:"danger",size:"sm",disabled:!!a,onClick:()=>_(e)},b("confirmDelete","Confirm delete"))))))},ek="-esm-billing__discount-review-stack__groupHeader___Ie7oM",eD="-esm-billing__discount-review-stack__groupTitle___e80de",eA="-esm-billing__discount-review-stack__groupCount___zrgwP",eP="-esm-billing__discount-review-stack__stack___YgUv1",ew=p().memo(({pendingDiscounts:e,confirmedDiscounts:t,lineItems:a,busy:l,rejectingId:n,deletingId:i,canDecide:r,onApprove:s,onStartReject:o,onCancelReject:c,onConfirmReject:m,onStartDelete:u,onCancelDelete:d,onConfirmDelete:_})=>{let{t:b}=(0,g.useTranslation)(),E=e=>p().createElement(eS,{key:e.uuid,discount:e,lineItems:a,busy:l,rejectingId:n,deletingId:i,canDecide:r,onApprove:s,onStartReject:o,onCancelReject:c,onConfirmReject:m,onStartDelete:u,onCancelDelete:d,onConfirmDelete:_});return p().createElement("section",{className:"-esm-billing__discount-review-stack__review___7I6RE"},e.length>0&&p().createElement("div",null,p().createElement("div",{className:ek},p().createElement("h3",{className:eD},b("pendingDiscounts","Pending discounts")),p().createElement("span",{className:eA},e.length)),p().createElement("div",{className:eP},e.map(E))),t.length>0&&p().createElement("div",null,p().createElement("div",{className:ek},p().createElement("h3",{className:eD},b("confirmedDiscounts","Confirmed discounts")),p().createElement("span",{className:eA},t.length)),p().createElement("div",{className:eP},t.map(E))))}),eI=e=>e?.responseBody?.error?.message??(e instanceof Error?e.message:String(e)),eL={container:"-esm-billing__bills-table__container___PDs67",emptyStateContainer:"-esm-billing__bills-table__emptyStateContainer___+sc4M",loaderContainer:"-esm-billing__bills-table__loaderContainer___9+3cP",billListContainer:"-esm-billing__bills-table__billListContainer___z5Mjt",filterEmptyState:"-esm-billing__bills-table__filterEmptyState___hV8Kp",filterContainer:"-esm-billing__bills-table__filterContainer___HlgpD",menu:"-esm-billing__bills-table__menu___F7TXn",headerContainer:"-esm-billing__bills-table__headerContainer___FouPn",backgroundDataFetchingIndicator:"-esm-billing__bills-table__backgroundDataFetchingIndicator___-WVf2",tableContainer:"-esm-billing__bills-table__tableContainer___-rFXM",hiddenRow:"-esm-billing__bills-table__hiddenRow___UsKb7",emptyRow:"-esm-billing__bills-table__emptyRow___kJSR-",visitSummaryContainer:"-esm-billing__bills-table__visitSummaryContainer___TzYie",expandedActiveVisitRow:"-esm-billing__bills-table__expandedActiveVisitRow___-imGs",action:"-esm-billing__bills-table__action___T5jNA",illo:"-esm-billing__bills-table__illo___zE0Ny",content:"-esm-billing__bills-table__content___XIyTL",desktopHeading:"-esm-billing__bills-table__desktopHeading___qYmFK",tabletHeading:"-esm-billing__bills-table__tabletHeading___JVDgu",tile:"-esm-billing__bills-table__tile___Zxkhk",menuitem:"-esm-billing__bills-table__menuitem___owZSX",filterEmptyStateTile:"-esm-billing__bills-table__filterEmptyStateTile___qWUMb",filterEmptyStateContent:"-esm-billing__bills-table__filterEmptyStateContent___W3mdv",filterEmptyStateHelper:"-esm-billing__bills-table__filterEmptyStateHelper___nvBYb"};function eM({layout:e,handleSearch:t,isValidating:a,responsiveSize:l,searchString:n,t:i}){return p().createElement(p().Fragment,null,p().createElement("div",{className:eL.headerContainer},p().createElement("div",{className:k()({[eL.tabletHeading]:!(0,d.isDesktop)(e),[eL.desktopHeading]:(0,d.isDesktop)(e)})},p().createElement("h4",null,i("billList","Bill list"))),a&&p().createElement("div",{className:eL.backgroundDataFetchingIndicator},p().createElement("span",null,p().createElement(h.OuH,null)))),p().createElement(h.vji,{autoFocus:!0,closeButtonLabelText:i("clearSearch","Clear"),"data-testid":"billsTableSearchBar",labelText:i("searchForPatient","Search for a patient"),placeholder:i("filterBillsByPatient","Filter bills by patient name or identifier"),value:n,onChange:t,size:l}))}let eB=()=>{let{t:e}=(0,g.useTranslation)(),t=(0,d.useLayoutType)(),{pageSize:a}=(0,d.useConfig)(),[l,n]=(0,_.useState)(a??10),i=(0,d.isDesktop)(t)?"sm":"lg",r=(0,_.useMemo)(()=>[{id:"",text:e("allBills","All bills"),status:""},{id:V.ih.PENDING,text:e("pendingConfirmationBills","Pending confirmation"),status:V.ih.PENDING},{id:V.ih.POSTED,text:e("pendingPaymentBills","Pending payment"),status:V.ih.POSTED},{id:V.ih.PAID,text:e("paidBills","Paid bills"),status:V.ih.PAID},{id:V.ih.REFUNDED,text:e("refundedBills","Refunded bills"),status:`${V.ih.REFUNDED},${V.ih.PARTIALLY_REFUNDED}`},{id:V.ih.REFUND_REQUESTED,text:e("pendingRefundBills","Pending refunds"),status:V.ih.REFUND_REQUESTED}],[e]),[s,o]=(0,_.useState)(()=>r.find(e=>e.id===V.ih.PENDING)??r[0]),[c,m]=(0,_.useState)(""),u=(0,d.useDebounce)(c,500),{bills:b,error:E,currentPage:y,isLoading:v,isValidating:f,totalCount:C,goTo:N}=(0,Y.fu)(l,s.status,u||void 0),T=[{header:e("billDate","Bill date"),key:"dateCreated"},{header:e("invoiceNumber","Invoice number"),key:"receiptNumberDisplay"},{header:e("patientIdentifier","Patient identifier"),key:"identifier"},{header:e("patientName","Patient name"),key:"patientName"},{header:e("billedItems","Billed items"),key:"billedItems"}],S=(0,_.useMemo)(()=>b?.map(e=>({...e,id:String(e.id),dateCreated:e.dateCreated?(0,d.formatDate)((0,d.parseDate)(e.dateCreated),{mode:"wide"}):"--",receiptNumberDisplay:p().createElement(d.ConfigurableLink,{style:{textDecoration:"none"},to:"${openmrsSpaBase}/home/billing/patient/${patientUuid}/${uuid}",templateParams:{patientUuid:e.patientUuid,uuid:e.uuid}},e.receiptNumber),billedItems:e?.lineItems?.map(e=>e.billableService||e.item).filter(Boolean).join(" & ")})),[b]),k=""!==c.trim()||""!==s.id,D=(0,_.useCallback)(e=>{N(1),m(e.target.value)},[N,m]),A=(0,_.useCallback)(({selectedItem:e})=>{o(e),N(1)},[N]);return p().createElement(p().Fragment,null,p().createElement("div",{className:eL.filterContainer},p().createElement(h.msM,{className:eL.filterDropdown,direction:"bottom",id:"bill-payment-status-filter",selectedItem:s,items:r,itemToString:e=>e?e.text:"",label:"",onChange:A,size:i,titleText:e("filterBy","Filter by:"),type:"inline"})),v&&!b?.length?p().createElement("div",{className:eL.loaderContainer,"data-testid":"bills-table-skeleton"},p().createElement(h.OOb,{rowCount:l,showHeader:!1,showToolbar:!1,zebra:!0,columnCount:T?.length})):E?p().createElement("div",{className:eL.errorContainer},p().createElement(h.Wdr,null,p().createElement(d.ErrorState,{error:E,headerTitle:e("billList","Bill list")}))):S?.length>0||k?p().createElement("div",{className:eL.billListContainer},p().createElement(eM,{handleSearch:D,isValidating:f,layout:t,responsiveSize:i,searchString:c,t:e}),p().createElement(h.bQt,{isSortable:!0,rows:S,headers:T,size:i,useZebraStyles:S?.length>1},({rows:t,headers:a,getRowProps:l,getTableProps:n})=>p().createElement(h.K3K,null,p().createElement(h.XIK,{...n(),"aria-label":e("billList","Bill list")},p().createElement(h.ndF,null,p().createElement(h.Hjg,null,a.map(e=>p().createElement(h.A0N,{key:e.key},e.header)))),p().createElement(h.BFY,null,t.map(e=>p().createElement(h.Hjg,{key:e.id,...l({row:e})},e.cells.map(e=>p().createElement(h.nA6,{key:e.id},e.value)))))))),S?.length===0&&p().createElement("div",{className:eL.filterEmptyState},p().createElement(h.Wdr,{level:0},p().createElement(h.FAs,{className:eL.filterEmptyStateTile},p().createElement("p",{className:eL.filterEmptyStateContent},e("noMatchingBillsToDisplay","No matching bills to display")),p().createElement("p",{className:eL.filterEmptyStateHelper},e("checkFilters","Check the filters above"))))),C>0&&p().createElement(h.dKS,{forwardText:e("nextPage","Next page"),backwardText:e("previousPage","Previous page"),page:y,pageSize:l,pageSizes:[10,20,30,40,50],totalItems:C,onChange:({pageSize:e,page:t})=>{e!==l?(n(e),N(1)):t!==y&&N(t)}})):p().createElement(h.Wdr,{className:eL.emptyStateContainer},p().createElement(h.FAs,{className:eL.tile},p().createElement("div",{className:eL.illo},p().createElement(d.EmptyCardIllustration,null)),p().createElement("p",{className:eL.content},e("noBillsToDisplay","There are no bills to display.")))))};function eR(){let{t:e}=(0,g.useTranslation)();return p().createElement(p().Fragment,null,p().createElement(M,{title:e("home","Home")}),p().createElement("section",{className:"-esm-billing__billing-dashboard__billsTableContainer___XBT2N"},p().createElement(eB,null)))}var eq=a(7240);let eF=({label:e,value:t,hasBalance:a})=>p().createElement("div",{className:"-esm-billing__invoice-breakdown__invoiceBreakdown___IGWfb"},p().createElement("span",{className:a?"-esm-billing__invoice-breakdown__extendedLabel___fJ78V":"-esm-billing__invoice-breakdown__label___WpAJx"},e,": "),p().createElement("span",{className:"-esm-billing__invoice-breakdown__value___L3Y8v"},t)),ex={errorRetryCount:2},ej=async e=>{let{uuid:t,attributes:a}=e,l=a?.find(e=>"919b51c9-8e2e-468f-8354-181bf3e55786"===e.attributeType.uuid)?.uuid;return(0,d.openmrsFetch)(`${d.restBaseUrl}/visit/${t}/attribute/${l}`,{body:{value:!1},headers:{"Content-Type":"application/json"},method:"POST"})},e$=({disablePayment:e})=>{let{t}=(0,g.useTranslation)(),{control:a,formState:{errors:l}}=(0,ei.xW)(),{paymentModes:n,isLoading:i,error:r}=(()=>{let e=`${j.B}paymentMode`,{data:t,isLoading:a,error:l,mutate:n}=(0,x.Ay)(e,d.openmrsFetch,ex);return{paymentModes:t?.data?.results??[],isLoading:a,mutate:n,error:l}})();return i?p().createElement(h.Rzj,null):r?p().createElement("div",{className:"-esm-billing__payment-form__errorPaymentContainer___Ft9DN"},p().createElement(d.ErrorState,{headerTitle:t("errorLoadingPaymentModes","Error loading payment modes"),error:r})):e?null:p().createElement("div",{className:"-esm-billing__payment-form__container___P4SMq"},p().createElement("div",{className:"-esm-billing__payment-form__paymentMethodContainer___fZiwB"},p().createElement(ei.xI,{control:a,name:"payment.method",render:({field:e})=>p().createElement(h.msM,{id:"paymentMethod",selectedItem:n?.find(t=>t.uuid===e.value)??null,onChange:({selectedItem:t})=>e.onChange(t?.uuid??""),titleText:t("paymentMethod","Payment method"),label:t("selectPaymentMethod","Select payment method"),items:n,itemToString:e=>e?e.name:"",invalid:!!l?.payment?.method,invalidText:l?.payment?.method?.message})}),p().createElement(ei.xI,{control:a,name:"payment.amount",render:({field:e})=>p().createElement(h.Q7x,{allowEmpty:!0,disableWheel:!0,hideSteppers:!0,id:"paymentAmount",invalid:!!l?.payment?.amount,invalidText:l?.payment?.amount?.message,label:t("amount","Amount"),onChange:(t,{value:a})=>{let l=""===a||void 0===a?void 0:Number(a);e.onChange(l)},placeholder:t("enterAmount","Enter amount"),value:e.value??""})}),p().createElement(ei.xI,{name:"payment.referenceCode",control:a,render:({field:e})=>p().createElement(h.ksK,{id:"paymentReferenceCode",labelText:t("referenceNumber","Reference number"),name:e.name,onBlur:e.onBlur,onChange:e.onChange,placeholder:t("enterReferenceNumber","Enter reference number"),type:"text",value:e.value??""})})))},eU=({bill:e})=>{let{t}=(0,g.useTranslation)(),{defaultCurrency:a}=(0,d.useConfig)(),l=[{key:"dateCreated",header:t("dateOfPayment","Date of payment")},{key:"amount",header:t("billAmount","Bill amount")},{key:"amountTendered",header:t("amountTendered","Amount tendered")},{key:"paymentMethod",header:t("paymentMethod","Payment method")}],n=(e?.payments??[]).map((e,t)=>{let l=new Date(e.dateCreated);return{id:`${e.uuid}-${t}`,dateCreated:(0,d.formatDate)(l),amountTendered:(0,F.aL)(e.amountTendered,a),amount:(0,F.aL)(e.amount,a),paymentMethod:e.instanceType.name,sortKey:l.getTime()}});if(n.sort((e,t)=>t.sortKey-e.sortKey),0!==Object.values(e?.payments??{}).length)return p().createElement(h.bQt,{size:"sm",rows:n,headers:l},({rows:e,headers:t,getTableProps:a,getHeaderProps:l,getRowProps:n})=>p().createElement(h.XIK,a(),p().createElement(h.ndF,null,p().createElement(h.Hjg,null,t.map(e=>p().createElement(h.A0N,l({header:e}),e.header)))),p().createElement(h.BFY,null,e.map(e=>p().createElement(h.Hjg,n({row:e}),e.cells.map(e=>p().createElement(h.nA6,{key:e.id},e.value)))))))},eH=({bill:e,mutate:t,onFinalizeBill:a})=>{let{t:l}=(0,g.useTranslation)(),{mutate:n}=(0,x.iX)(),i=el.z.object({method:el.z.string().refine(e=>!!e,"Payment method is required"),amount:el.z.number({required_error:l("amountRequired","Amount is required"),invalid_type_error:l("amountRequired","Amount is required")}).positive({message:l("amountMustBePositive","Amount must be greater than 0")}).max((e?.netAmount??0)-(e?.tenderedAmount??0),{message:l("paymentAmountCannotExceedAmountDue","Payment amount cannot exceed amount due")}),referenceCode:el.z.union([el.z.number(),el.z.string()]).optional()}),r=el.z.object({payment:i}),{currentVisit:s}=(0,d.useVisit)(e?.patientUuid),{defaultCurrency:o}=(0,d.useConfig)(),c={payment:{method:"",amount:void 0,referenceCode:""}},m=(0,ei.mN)({mode:"all",defaultValues:c,resolver:(0,en.u)(r)}),u=(0,ei.FH)({name:"payment",control:m.control,defaultValue:c.payment});if(!e)return null;let _=(e.refunds??[]).filter(e=>e.status===V.fH.COMPLETED).reduce((e,t)=>e+t.refundAmount,0),b=(e.netAmount??0)-(e.tenderedAmount??0),E=e.status===V.ih.PENDING,y=async()=>{if(u?.method&&null!=u.amount)try{await (0,Y.TS)({instanceType:u.method,amountTendered:Number(u.amount),amount:e.totalAmount??0},e.uuid),(0,d.showSnackbar)({title:l("billPayment","Bill payment"),subtitle:l("paymentProcessedSuccessfully","Payment processed successfully"),kind:"success"}),s&&ej(s),m.reset(c),t(),n((0,Y.Z5)(e.patientUuid))}catch(e){(0,d.showSnackbar)({title:l("errorProcessingPayment","Error processing payment"),kind:"error",subtitle:e?.message})}};return p().createElement(ei.Op,m,p().createElement("div",{className:"-esm-billing__payments__wrapper___V4WiR"},p().createElement("div",{className:"-esm-billing__payments__paymentContainer___1SfXU"},p().createElement(d.CardHeader,{title:l("payments","Payments")},p().createElement("span",null)),p().createElement("div",null,E?p().createElement("div",{className:"-esm-billing__payments__pendingEmptyState___jUFD7"},p().createElement(h.Wdr,null,p().createElement(h.FAs,{className:"-esm-billing__payments__pendingEmptyStateTile___q+iuz"},p().createElement("p",{className:"-esm-billing__payments__pendingEmptyStateContent___B8pVF"},l("billNotFinalized","Bill not finalized")),p().createElement("p",{className:"-esm-billing__payments__pendingEmptyStateHelper___amDGw"},l("finalizeBillToRecordPayment","Finalize this bill before recording a payment.")),p().createElement(h.$nd,{className:"-esm-billing__payments__finalizeButton___nCnCg",kind:"primary",size:"sm",onClick:a},l("finalizeBill","Finalize bill"))))):p().createElement(p().Fragment,null,p().createElement(eU,{bill:e}),p().createElement(e$,{disablePayment:b<=0})))),p().createElement("div",{className:"-esm-billing__payments__divider___C6sdr"}),p().createElement("div",{className:"-esm-billing__payments__paymentTotals___-3A2t"},p().createElement(eF,{label:l("totalAmount","Total amount"),value:(0,F.aL)(e.totalAmount??0,o)}),p().createElement(eF,{label:l("totalTendered","Total tendered"),value:(0,F.aL)(e.tenderedAmount??0,o)}),p().createElement(eF,{label:l("discount","Discount"),value:`- ${(0,F.aL)((e.totalAmount??0)-(e.netAmount??0),o)}`}),p().createElement(eF,{label:l("refunds","Refunds"),value:`- ${(0,F.aL)(_,o)}`}),p().createElement(eF,{hasBalance:b<0,label:l("amountDue","Amount due"),value:(0,F.aL)(b,o)}),p().createElement("div",{className:"-esm-billing__payments__processPayments___RG8aV"},p().createElement(h.$nd,{onClick:()=>(0,d.navigate)({to:window.getOpenmrsSpaBase()+"home/billing"}),kind:"secondary"},l("discard","Discard")),!E&&p().createElement(h.$nd,{onClick:y,disabled:!u?.method||null==u.amount||!m.formState.isValid},l("processPayment","Process Payment"))))))},eO=({billUuid:e})=>{let{t}=(0,g.useTranslation)(),[a,l]=(0,_.useState)(!1),n=new URL(window.location.href);return p().createElement(h.$nd,{kind:"secondary",className:"-esm-billing__print-receipt__button___QnAQS",renderIcon:e=>p().createElement(T.xj,{size:24,...e}),onClick:()=>{l(!0),setTimeout(()=>{let t=`${n.origin}/openmrs${j.B}receipt?billUuid=${e}`,a=document.createElement("a");a.href=t,a.download=`receipt_${e}.pdf`,document.body.appendChild(a),a.click(),document.body.removeChild(a),l(!1)},1e3)},disabled:a},a?(0,d.getCoreTranslation)("loading"):t("printReceipt","Print receipt"))},ez=()=>{let{data:e}=(0,Y.eC)();return e?p().createElement("div",{className:"-esm-billing__printable-footer__container___mTh7B"},p().createElement("p",{className:"-esm-billing__printable-footer__itemFooter___Y5pkL"},e?.display)):p().createElement("div",null,"--")};var eV=a(2193),eK=a.n(eV);let eW="-esm-billing__printable-invoice-header__img___rSlvX",eG="-esm-billing__printable-invoice-header__sectionHeading___tOV2s",eQ="-esm-billing__printable-invoice-header__itemLabel___+hACh",eJ=({patientDetails:e,defaultFacility:t,bill:a})=>{let{t:l}=(0,g.useTranslation)(),{logo:n,country:i,defaultCurrency:r}=(0,d.useConfig)(),s={[l("invoiceNo","Invoice #")]:a?.receiptNumber,[l("invoiceDate","Invoice date")]:a?.dateCreated?(0,d.formatDate)((0,d.parseDate)(a.dateCreated),{mode:"wide",noToday:!0,time:!1}):"--",[l("totalAmount","Total amount")]:`${r} ${a?.totalAmount}`,[l("totalPaid","Total paid")]:`${r} ${a?.tenderedAmount}`,[l("amountBalance","Amount balance")]:`${r} ${a?.netAmount-a?.tenderedAmount}`,...a?.status&&{[l("invoiceStatus","Invoice status")]:a.status}},o={[l("name","Name")]:e?.name,...e.gender&&{[l("gender","Gender")]:e.gender},...e.birthDate&&{[l("birthDate","Date of birth")]:(0,d.formatDate)((0,d.parseDate)(e.birthDate),{time:!1})},...e.address&&{[l("address","Address")]:e.address}};return p().createElement("div",{className:"-esm-billing__printable-invoice-header__container___1u0nI"},p().createElement("div",{className:"-esm-billing__printable-invoice-header__printableHeader___Jl02J"},p().createElement("div",{className:"-esm-billing__printable-invoice-header__logo___ZpVka"},n?.src&&!eK()(n.src)?p().createElement("img",{className:eW,src:(0,d.interpolateUrl)(n.src),alt:n.alt}):n?.alt&&!eK()(n.alt)?n.alt:p().createElement("svg",{className:eW,role:"img",width:110,height:40,viewBox:"0 0 380 119",xmlns:"http://www.w3.org/2000/svg"},p().createElement("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M40.29 40.328a27.755 27.755 0 0 1 19.688-8.154c7.669 0 14.613 3.102 19.647 8.116l.02-18.54A42.835 42.835 0 0 0 59.978 17c-7.089 0-13.813 1.93-19.709 4.968l.021 18.36ZM79.645 79.671a27.744 27.744 0 0 1-19.684 8.154c-7.67 0-14.614-3.101-19.651-8.116l-.02 18.54A42.857 42.857 0 0 0 59.96 103a42.833 42.833 0 0 0 19.672-4.751l.013-18.578ZM40.328 79.696c-5.038-5.037-8.154-11.995-8.154-19.685 0-7.669 3.102-14.612 8.116-19.65l-18.54-.02A42.85 42.85 0 0 0 17 60.012a42.819 42.819 0 0 0 4.752 19.672l18.576.013ZM79.634 40.289a27.753 27.753 0 0 1 8.154 19.688 27.744 27.744 0 0 1-8.117 19.646l18.542.02a42.842 42.842 0 0 0 4.749-19.666c0-7.09-1.714-13.779-4.751-19.675l-18.577-.013ZM156.184 60.002c0-8.748-6.118-15.776-15.025-15.776-8.909 0-15.025 7.028-15.025 15.776 0 8.749 6.116 15.78 15.025 15.78 8.907 0 15.025-7.031 15.025-15.78Zm-34.881 0c0-11.482 8.318-19.958 19.856-19.958 11.536 0 19.855 8.477 19.855 19.959 0 11.484-8.319 19.964-19.855 19.964-11.538 0-19.856-8.48-19.856-19.965ZM179.514 75.54c5.507 0 9.05-4.14 9.05-9.482 0-5.341-3.543-9.483-9.05-9.483-5.505 0-9.046 4.142-9.046 9.483 0 5.342 3.541 9.482 9.046 9.482ZM166.22 53.306h4.248v3.704h.11c2.344-2.725 5.449-4.36 9.154-4.36 8.014 0 13.408 5.67 13.408 13.408 0 7.63-5.613 13.406-12.752 13.406-4.58 0-8.231-2.29-9.81-5.178h-.11V90.87h-4.248V53.306ZM217.773 63.768c-.163-4.305-3-7.193-7.686-7.193-4.685 0-7.79 2.888-8.335 7.193h16.021Zm3.653 10.412c-3.001 3.868-6.596 5.284-11.339 5.284-8.01 0-12.914-5.993-12.914-13.406 0-7.901 5.559-13.407 13.08-13.407 7.196 0 12.096 4.906 12.096 13.354v1.362h-20.597c.325 4.413 3.704 8.173 8.335 8.173 3.65 0 6.105-1.307 8.12-3.868l3.219 2.508ZM227.854 59.356c0-2.346-.216-4.36-.216-6.05h4.031c0 1.363.11 2.777.11 4.195h.11c1.144-2.505 4.306-4.85 8.5-4.85 6.705 0 9.699 4.252 9.699 10.41v15.748h-4.248v-15.31c0-4.253-1.856-6.924-5.833-6.924-5.503 0-7.903 3.979-7.903 9.811V78.81h-4.25V59.356ZM259.211 41.008h6.708L278.8 70.791h.107l12.982-29.782h6.549v37.99h-4.506V47.124h-.106L280.192 79h-2.738l-13.629-31.875h-.107V79h-4.507V41.01ZM312.392 57.752h4.023c4.992 0 11.487 0 11.487-6.282 0-5.47-4.776-6.276-9.177-6.276h-6.333v12.558Zm-4.506-16.744h9.711c7.352 0 15.132 1.072 15.132 10.462 0 5.527-3.594 9.125-9.495 10.037L334.018 79h-5.525l-10.304-17.063h-5.797V79h-4.506V41.01ZM358.123 47.712c-1.506-2.413-4.187-3.486-6.926-3.486-3.973 0-8.1 1.88-8.1 6.385 0 3.49 1.931 5.047 7.994 6.98 5.903 1.878 11.377 3.809 11.377 11.267 0 7.567-6.495 11.11-13.36 11.11-4.402 0-9.125-1.45-11.7-5.262l3.862-3.165c1.61 2.794 4.83 4.24 8.105 4.24 3.862 0 8.263-2.253 8.263-6.601 0-4.669-3.165-5.474-9.928-7.728-5.366-1.771-9.442-4.134-9.442-10.463 0-7.298 6.277-10.945 12.929-10.945 4.241 0 7.836 1.178 10.625 4.45l-3.699 3.218Z"}))),p().createElement("div",{className:"-esm-billing__printable-invoice-header__facilityDetails___uJPtI"},p().createElement("p",{className:"-esm-billing__printable-invoice-header__facilityName___81nN9"},t?.display),p().createElement("p",{className:eQ},i))),p().createElement("h1",{className:"-esm-billing__printable-invoice-header__invoiceHeading___9Xftg"},l("invoice","Invoice")),p().createElement("div",{className:"-esm-billing__printable-invoice-header__printableBody___cMhfI"},p().createElement("div",{className:"-esm-billing__printable-invoice-header__detailsContainer___rJn9A"},p().createElement("div",null,p().createElement("h2",{className:eG},l("patientInformation","Patient information")),Object.entries(o).map(([e,t])=>p().createElement("p",{className:eQ,key:e},p().createElement("strong",null,e),p().createElement("span",null,": ",t)))),p().createElement("div",null,p().createElement("h2",{className:eG},l("invoiceSummary","Invoice summary")),Object.entries(s).map(([e,t])=>p().createElement("p",{className:eQ,key:e},p().createElement("strong",null,e),p().createElement("span",null,": ",t)))))))},eX={itemsContainer:"-esm-billing__printable-invoice__itemsContainer___EA1KS",tableContainer:"-esm-billing__printable-invoice__tableContainer___CeBjk",totalContainer:"-esm-billing__printable-invoice__totalContainer___+8XbC",item:"-esm-billing__printable-invoice__item___U-0e6",itemHeading:"-esm-billing__printable-invoice__itemHeading___mHy3a",itemTotal:"-esm-billing__printable-invoice__itemTotal___pOXNY",itemLabel:"-esm-billing__printable-invoice__itemLabel___i+Nva",summaryContainer:"-esm-billing__printable-invoice__summaryContainer___A5A-s",paymentHistoryContainer:"-esm-billing__printable-invoice__paymentHistoryContainer___Z+0Pi",balanceContainer:"-esm-billing__printable-invoice__balanceContainer___oekII"},eZ=({bill:e,patient:t,componentRef:a,defaultFacility:l})=>{let{t:n}=(0,g.useTranslation)(),i=(0,d.useLayoutType)(),{defaultCurrency:r}=(0,d.useConfig)(),s=(0,d.isDesktop)(i)?"sm":"lg",o=[{header:n("inventoryItem","Inventory item"),key:"billItem"},{header:n("quantity","Quantity"),key:"quantity"},{header:n("unitPrice","Unit price"),key:"price"},{header:n("total","Total"),key:"total"}],c=e?.lineItems?.map(e=>({id:`${e.uuid}`,billItem:e.billableService?e.billableService:e.item,quantity:e.quantity,price:`${r} ${e.price}`,total:`${r} ${e.price*e.quantity}`}))??[],m=[{key:"no",header:n("no","No")},{key:"paymentMethod",header:n("paymentMethod","Payment method")},{key:"amountPaid",header:n("amountPaid","Amount paid")},{key:"dateCreated",header:n("dateOfPayment","Date of payment")}],u=(0,_.useMemo)(()=>e?e.payments?.map((e,t)=>({no:t+1,id:`${e.uuid}-${t}`,paymentMethod:e.instanceType.name,amountPaid:`${r} ${e.amountTendered.toFixed(2)}`,dateCreated:(0,d.formatDate)(new Date(e.dateCreated))})):[],[e,r]),b=(0,_.useMemo)(()=>{let e=t?.address?.[0],a=[e?.line?.join(" "),e?.city,e?.district,e?.state].filter(Boolean).join(", ");return{name:`${t?.name?.[0]?.given?.join(" ")} ${t?.name?.[0].family}`,birthDate:t?.birthDate,gender:(0,F.o_)(t?.gender,n),address:a}},[t,n]);return p().createElement("div",{className:eX.container,ref:a},p().createElement(eJ,{patientDetails:b,defaultFacility:l,bill:e}),p().createElement("div",{className:eX.itemsContainer},p().createElement("div",{className:eX.tableContainer},p().createElement(h.bQt,{rows:c,headers:o,size:s,useZebraStyles:!1},({rows:e,headers:t,getRowProps:a,getTableProps:l})=>p().createElement(h.K3K,null,p().createElement(h.XIK,{...l(),"aria-label":n("invoiceLineItems","Invoice line items")},p().createElement(h.ndF,null,p().createElement(h.Hjg,null,t.map(e=>p().createElement(h.A0N,{key:e.key},e.header)))),p().createElement(h.BFY,null,e.map(e=>p().createElement(h.Hjg,{key:e.id,...a({row:e})},e.cells.map(e=>p().createElement(h.nA6,{key:e.id},e.value)))))))),e?.netAmount!=null&&e.totalAmount!==e.netAmount?p().createElement(p().Fragment,null,p().createElement("div",{className:eX.balanceContainer},p().createElement("span",{className:eX.itemHeading},n("subtotal","Subtotal"),":")," ",p().createElement("span",{className:eX.itemLabel},p().createElement("strong",null,r," ",e?.totalAmount))),p().createElement("div",{className:eX.balanceContainer},p().createElement("span",{className:eX.itemHeading},n("discount","Discount"),":")," ",p().createElement("span",{className:eX.itemLabel},p().createElement("strong",null,"- ",r," ",(e?.totalAmount??0)-(e?.netAmount??0)))),p().createElement("div",{className:eX.balanceContainer},p().createElement("span",{className:eX.itemHeading},n("totalAmount","Total amount"),":")," ",p().createElement("span",{className:eX.itemLabel},p().createElement("strong",null,r," ",e?.netAmount)))):p().createElement("div",{className:eX.balanceContainer},p().createElement("span",{className:eX.itemHeading},n("totalAmount","Total amount"),":")," ",p().createElement("span",{className:eX.itemLabel},p().createElement("strong",null,r," ",e?.totalAmount))),e?.payments?.length>0&&p().createElement("div",{className:eX.paymentHistoryContainer},p().createElement(h.bQt,{rows:u,headers:m,size:s},({rows:e,headers:t,getRowProps:a,getTableProps:l})=>p().createElement(h.K3K,null,p().createElement(h.XIK,{...l(),"aria-label":n("paymentHistory","Payment History")},p().createElement(h.ndF,null,p().createElement(h.Hjg,null,t.map(e=>p().createElement(h.A0N,{key:e.key},e.header)))),p().createElement(h.BFY,null,e.map(e=>p().createElement(h.Hjg,{key:e.id,...a({row:e})},e.cells.map(e=>p().createElement(h.nA6,{key:e.id},e.value))))))))),p().createElement("div",{className:eX.balanceContainer},p().createElement("span",{className:eX.itemHeading},n("totalTendered","Total tendered"),":"),p().createElement("span",{className:eX.itemLabel},p().createElement("strong",null,r," ",e?.tenderedAmount))),p().createElement("div",{className:eX.balanceContainer},p().createElement("span",{className:eX.itemHeading},n("balance","Balance"),":"),p().createElement("span",{className:eX.itemLabel},p().createElement("strong",null,r," ",e?.netAmount-e?.tenderedAmount))))),p().createElement(ez,null))},eY=({bill:e})=>{let{t}=(0,g.useTranslation)(),{defaultCurrency:a}=(0,d.useConfig)(),l=(0,d.useLayoutType)(),n=(0,d.isDesktop)(l)?"sm":"lg",i=(0,_.useMemo)(()=>(e.discounts??[]).filter(e=>!e.voided),[e.discounts]),r=[{header:t("discountItem","Item"),key:"item",width:25},{header:t("discountType","Type"),key:"type",width:15},{header:t("discountAmount","Amount"),key:"amount",width:15},{header:t("justification","Justification"),key:"justification",width:30},{header:t("status","Status"),key:"status",width:15}],s=(0,_.useMemo)(()=>(i??[]).map(l=>({id:l.uuid,item:function(e,t,a){if(!e.lineItemUuid)return a;let l=t.lineItems?.find(t=>t.uuid===e.lineItemUuid);return l?.item||l?.billableService||a}(l,e,t("wholeBill","Whole bill")),type:l.discountType===V.Bp.PERCENTAGE?t("percentage","Percentage"):t("fixedAmount","Fixed amount"),amount:(0,F.aL)(l.discountAmount,a),justification:l.justification,status:t(l.status.toLowerCase(),l.status)})),[i,e,a,t]);return i&&0!==i.length?p().createElement("div",{className:"-esm-billing__discounts-table__discountsWrapper___nAknV"},p().createElement(h.bQt,{headers:r,rows:s,size:n,useZebraStyles:!0,overflowMenuOnHover:(0,d.isDesktop)(l)},({rows:e,headers:a,getRowProps:l,getTableProps:n})=>p().createElement(h.K3K,{description:p().createElement("span",{className:"-esm-billing__discounts-table__tableDescription___dsPxA"},p().createElement("span",null,t("discountsAppliedToBill","Discounts applied to this bill"))),title:t("discounts","Discounts")},p().createElement(h.XIK,{...n(),"aria-label":t("billDiscounts","Bill discounts"),className:k()("-esm-billing__discounts-table__discountsTable___Wd5vG","billingTable")},p().createElement(h.ndF,null,p().createElement(h.Hjg,null,a.map(e=>p().createElement(h.A0N,{key:e.key},e.header)))),p().createElement(h.BFY,null,e.map(e=>p().createElement(h.Hjg,{key:e.id,...l({row:e})},e.cells.map(e=>p().createElement(h.nA6,{key:e.id},e.value))))))))):null},e0=({bill:e,onMutate:t})=>{let{t:a}=(0,g.useTranslation)(),{defaultCurrency:l}=(0,d.useConfig)(),n=(0,d.useSession)(),i=(0,d.useLayoutType)(),r=(0,d.isDesktop)(i)?"sm":"lg",[s,o]=(0,_.useState)(null),c=[{header:a("refundItem","Item"),key:"item"},{header:a("refundAmount","Refund amount"),key:"amount"},{header:a("reason","Reason"),key:"reason"},{header:a("status","Status"),key:"status"},{header:a("action","Action"),key:"action"}],m=(0,_.useMemo)(()=>(e.refunds??[]).filter(e=>!e.voided),[e.refunds]),u=(0,_.useCallback)(async e=>{o(e.uuid);try{await (0,Q.eK)(e.uuid,{status:V.fH.COMPLETED,completer:n.user?.uuid}),(0,d.showSnackbar)({title:a("refundProcessed","Refund processed"),kind:"success"}),t?.()}catch(t){let e=t?.responseBody?.error?.message??(t instanceof Error?t.message:void 0);(0,d.showSnackbar)({title:a("refundProcessFailed","Could not process refund"),subtitle:e,kind:"error"})}finally{o(null)}},[t,n.user?.uuid,a]),b=(0,_.useMemo)(()=>(m??[]).map(t=>({id:t.uuid,item:function(e,t,a){if(!e.lineItemUuid)return a;let l=t.lineItems?.find(t=>t.uuid===e.lineItemUuid);return l?.item||l?.billableService||a}(t,e,a("wholeBill","Whole bill")),amount:(0,F.aL)(t.refundAmount,l),reason:t.reason,status:a(t.status.toLowerCase(),t.status),action:p().createElement(h.$nd,{kind:"primary",size:"sm",disabled:s===t.uuid||t.status!==V.fH.APPROVED,onClick:()=>u(t)},s===t.uuid?p().createElement(h.OuH,{description:a("processing","Processing")+"..."}):a("processRefund","Process refund"))})),[m,e,l,s,a,u]);return m&&0!==m.length?p().createElement("div",{className:"-esm-billing__refunds-table__refundsWrapper___ZvDhw"},p().createElement(h.bQt,{headers:c,rows:b,size:r,useZebraStyles:!0},({rows:e,headers:t,getRowProps:l,getTableProps:n})=>p().createElement(h.K3K,{description:p().createElement("span",{className:"-esm-billing__refunds-table__tableDescription___hGPCT"},p().createElement("span",null,a("refundsOnBill","Refunds on this bill"))),title:a("refunds","Refunds")},p().createElement(h.XIK,{...n(),"aria-label":a("billRefunds","Bill refunds"),className:k()("-esm-billing__refunds-table__refundsTable___B5xVc","billingTable")},p().createElement(h.ndF,null,p().createElement(h.Hjg,null,t.map(e=>p().createElement(h.A0N,{key:e.key},e.header)))),p().createElement(h.BFY,null,e.map(e=>p().createElement(h.Hjg,{key:e.id,...l({row:e})},e.cells.map(e=>p().createElement(h.nA6,{key:e.id},e.value))))))))):null},e1="-esm-billing__invoice__invoiceContainer___6Vmk0",e3=`
1
+ (globalThis.webpackChunk_openmrs_esm_billing_app=globalThis.webpackChunk_openmrs_esm_billing_app||[]).push([["990"],{4767(e,t,a){var l={"./uk.json":["723","9072"],"./ar.json":["4132","7045"],"./ru_RU.json":["986","8359"],"./uz_UZ.json":["890","7175"],"./fr.json":["4055","6508"],"./sw_KE.json":["8618","903"],"./uz.json":["3584","6377"],"./en.json":["4300","5117"],"./ky.json":["8163","2416"],"./pl.json":["1119","6724"],"./sq.json":["8371","4928"],"./ka.json":["795","1480"],"./si.json":["6859","6904"],"./zh_TW.json":["439","556"],"./de.json":["4944","5145"],"./lg.json":["4618","8695"],"./vi.json":["9214","6371"],"./tr.json":["5241","434"],"./es_MX.json":["8349","1646"],"./tr_TR.json":["9900","1869"],"./zh_CN.json":["9879","5644"],"./en_US.json":["9569","4106"],"./he.json":["4652","2317"],"./id.json":["2690","6047"],"./ku.json":["9895","4348"],"./es.json":["3099","7912"],"./ne.json":["2146","5503"],"./ar_SY.json":["7617","282"],"./uz@Latn.json":["7097","4658"],"./bn.json":["7159","6444"],"./cs.json":["6589","7182"],"./zh.json":["5661","7742"],"./hi_IN.json":["5442","4383"],"./pt_BR.json":["6468","1877"],"./qu.json":["5173","8358"],"./ro_RO.json":["6022","3963"],"./sw.json":["9913","3378"],"./am.json":["1197","9806"],"./pt.json":["6679","5132"],"./it.json":["9538","4111"],"./km.json":["6716","5940"],"./hi.json":["6840","2881"]};function n(e){if(!a.o(l,e))return Promise.resolve().then(function(){var t=Error("Cannot find module '"+e+"'");throw t.code="MODULE_NOT_FOUND",t});var t=l[e],n=t[0];return a.e(t[1]).then(function(){return a(n)})}n.keys=()=>Object.keys(l),n.id=4767,e.exports=n},6994(e,t,a){"use strict";a.d(t,{MH:()=>o,OS:()=>d,WJ:()=>c,bb:()=>m,cW:()=>_,j2:()=>u,ly:()=>s,vv:()=>p});var l=a(2914),n=a.n(l),i=a(3137),r=a(7003);let s=()=>{let e=`${r.B}billableService?v=custom:(uuid,name,shortName,serviceStatus,concept:(uuid,display,name:(name)),serviceType:(display,uuid),servicePrices:(uuid,name,price,paymentMode:(uuid,name)))`,{data:t,isLoading:a,isValidating:l,error:n,mutate:s}=(0,i.useOpenmrsFetchAll)(e);return{billableServices:t??[],isLoading:a,isValidating:l,error:n,mutate:s}};function o(){let{serviceTypes:e}=(0,i.useConfig)(),t=e.billableService,a=`${i.restBaseUrl}/concept/${t}?v=custom:(setMembers:(uuid,display))`,{data:l,error:r,isLoading:s}=n()(a,i.openmrsFetch);return{serviceTypes:l?.data.setMembers?[...l.data.setMembers].sort((e,t)=>e.display.localeCompare(t.display)):[],error:r,isLoadingServiceTypes:s}}let c=()=>{let e=`${r.B}paymentMode`,{data:t,error:a,isLoading:l,mutate:s}=n()(e,i.openmrsFetch);return{paymentModes:t?.data.results?[...t.data.results].sort((e,t)=>e.name.localeCompare(t.name)):[],error:a,isLoadingPaymentModes:l,mutate:s}};function m(e){let t=`${i.restBaseUrl}/conceptsearch?q=${e}`,{data:a,error:l,isLoading:r}=n()(e?t:null,i.openmrsFetch);return{searchResults:a?.data?.results??[],error:l,isSearching:r}}let u=async e=>{let t=`${r.B}api/billable-service`;return await (0,i.openmrsFetch)(t,{method:"POST",body:e,headers:{"Content-Type":"application/json"}})},d=async(e,t)=>{let a=`${r.B}billableService/${e}`;return await (0,i.openmrsFetch)(a,{method:"POST",body:t,headers:{"Content-Type":"application/json"}})},_=e=>{let t=`${i.restBaseUrl}/billing/paymentMode`;return(0,i.openmrsFetch)(t,{method:"POST",body:e,headers:{"Content-Type":"application/json"}})},p=(e,t)=>{let a=`${i.restBaseUrl}/billing/paymentMode/${e}`;return(0,i.openmrsFetch)(a,{method:"POST",body:t,headers:{"Content-Type":"application/json"}})}},6199(e,t,a){"use strict";a.d(t,{DX:()=>d,FR:()=>y,LM:()=>v,N7:()=>N,TS:()=>_,Vs:()=>b,Xn:()=>g,Z5:()=>C,eC:()=>p,fu:()=>m,ly:()=>E,mi:()=>f,u1:()=>u,yj:()=>h});var l=a(2914),n=a.n(l),i=a(3139),r=a(3137),s=a(7003),o=a(5084);let c=e=>{let t=e?.lineItems?.filter(e=>!e.voided)??[],{identifier:a,name:l}=(e=>{if(!e)return{identifier:"",name:""};let t=e.indexOf(" - ");return -1===t?{identifier:"",name:e.trim()}:{identifier:e.substring(0,t).trim(),name:e.substring(t+3).trim()}})(e?.patient?.display);return{...e,patientName:l,identifier:a,patientUuid:e?.patient?.uuid,visitUuid:e?.visit?.uuid,cashPointUuid:e?.cashPoint?.uuid,cashPointName:e?.cashPoint?.name,cashPointLocation:e?.cashPoint?.location?.display,status:e.status,lineItems:t,billingService:t.map(e=>e?.item||e?.billableService||"--").join(" "),totalAmount:e.total,netAmount:e.amountAfterDiscount,tenderedAmount:(e?.payments??[]).map(e=>e.amountTendered??0).reduce((e,t)=>e+t,0)}},m=(e,t,a)=>{let l=`${s.B}bill?v=custom:(id,uuid,dateCreated,status,receiptNumber,patient:(uuid,display),lineItems:(uuid,item,billableService,voided))&pageSize=${e}`;t&&(l+=`&status=${t}`),a&&(l+=`&patientName=${encodeURIComponent(a)}`);let{data:n,error:i,isLoading:o,isValidating:m,mutate:u,currentPage:d,totalCount:_,goTo:p}=(0,r.useOpenmrsPagination)(l,e);return{bills:n?.map(e=>c(e)),error:i,isLoading:o,isValidating:m,mutate:u,currentPage:d,totalCount:_,goTo:p}},u=(e,t,a)=>{let l=`${s.B}bill?v=full`;e&&(l+=`&patientUuid=${e}`),t&&(l+=`&status=${t}`),a&&(l+=`&visitUuid=${a}`);let{data:n,error:o,isLoading:m,isValidating:u,mutate:d}=(0,r.useOpenmrsFetchAll)(l),_=(0,i.A)(n??[],["dateCreated"]).reverse();return{bills:_?.map(e=>c(e)),error:o,isLoading:m,isValidating:u,mutate:d}};function d(e,t=!0){let a=`${s.B}bill/${e}`,{data:l,error:i,isLoading:o,isValidating:m,mutate:u}=n()(e?a:null,r.openmrsFetch),_=null;return l?.data&&(_=t?c(l.data):l.data),{bill:_,error:i,isLoading:o,isValidating:m,mutate:u}}let _=(e,t)=>{let a=`${s.B}bill/${t}/payment`;return(0,r.openmrsFetch)(a,{method:"POST",body:e,headers:{"Content-Type":"application/json"}})};function p(){let{sessionLocation:e}=(0,r.useSession)();return{data:e}}let b=e=>{let{currentVisit:t}=(0,r.useVisit)(e);return(t?.attributes??[]).map(e=>({name:e.attributeType.name,value:e.value})).filter(({name:e})=>"Insurance scheme"===e||"Policy Number"===e)};function E(){let e=`${s.B}billableService?v=custom:(uuid,name,shortName,serviceStatus,serviceType:(display),servicePrices:(uuid,name,price,paymentMode))`;return(0,r.useOpenmrsFetchAll)(e)}let g=e=>{let t=`${s.B}bill`;return(0,r.openmrsFetch)(t,{method:"POST",body:e,headers:{"Content-Type":"application/json"}})},y=e=>{let t=`${s.B}bill/${e.uuid}`;return(0,r.openmrsFetch)(t,{method:"POST",body:e,headers:{"Content-Type":"application/json"}})},h=e=>{let t=`${s.B}bill/${e}`;return(0,r.openmrsFetch)(t,{method:"POST",body:{status:o.ih.POSTED},headers:{"Content-Type":"application/json"}})},f=(e,t)=>{let a=`${s.B}billLineItem/${e}?reason=${encodeURIComponent(t)}`;return(0,r.openmrsFetch)(a,{method:"DELETE"})},v=(e,t)=>{let a=`${s.B}bill/${e}?reason=${encodeURIComponent(t)}`;return(0,r.openmrsFetch)(a,{method:"DELETE"})},C=e=>`${s.B}patientPaymentStatus/${e}`,N=e=>{let t=C(e),{data:a,error:l,isLoading:i,isValidating:s,mutate:o}=n()(e?t:null,r.openmrsFetch);return{paymentStatus:a?.data,error:l,isLoading:i,isValidating:s,mutate:o}}},7003(e,t,a){"use strict";a.d(t,{B:()=>n});var l=a(3137);let n=`${l.restBaseUrl}/billing/`},2373(e,t,a){"use strict";a.d(t,{Zz:()=>n,aL:()=>i,o_:()=>r});var l=a(3137);function n(e){return Array.isArray(e)?e.reduce((e,t)=>"number"==typeof t.price&&"number"==typeof t.quantity&&!0!==t.voided?e+t.price*t.quantity:e,0):0}let i=(e,t)=>{let a=window.i18next?.language?.substring(0,2)??"",l=new Intl.NumberFormat(a,{style:"currency",currency:t,minimumFractionDigits:2}).format(Math.abs(e));return e<0&&(l=`(${l})`),l},r=(e,t)=>{switch(e){case"male":return(0,l.getCoreTranslation)("male");case"female":return(0,l.getCoreTranslation)("female");case"other":return(0,l.getCoreTranslation)("other");case"unknown":return(0,l.getCoreTranslation)("unknown");default:return e}}},1772(e,t,a){"use strict";a.d(t,{aL:()=>l.aL,o_:()=>l.o_});var l=a(2373)},7149(e,t,a){"use strict";let l,n,i,r,s;a.r(t),a.d(t,{refundRequestsLeftPanelLink:()=>tw,deletePaymentModeModal:()=>td,billingDashboardLink:()=>tt,billingFormWorkspace:()=>ty,discountRequestsLeftPanelLink:()=>tD,importTranslation:()=>te,billingSettingsLeftPanelMenu:()=>tv,billingCheckInForm:()=>ts,billableServicesAppMenuItem:()=>tn,billableServicesCardLink:()=>ti,deleteBillConfirmationModal:()=>tT,billingSummaryDashboardLink:()=>tl,editBillLineItemModal:()=>tp,patientPaymentStatusTag:()=>tg,finalizeBillConfirmationModal:()=>tN,requestDiscountModal:()=>tS,requestRefundModal:()=>tA,visitBillsPanel:()=>tc,billingPatientSummary:()=>to,billableServicesLeftPanelLink:()=>tf,startupApp:()=>ta,paymentModeFormModal:()=>tu,reviewBillRefundsModal:()=>tP,billableServicesHome:()=>tr,addCashPointModal:()=>t_,deleteLineItemConfirmationModal:()=>tC,reviewBillDiscountsModal:()=>tk,visitAttributeTags:()=>tE,requirePaymentModal:()=>tm,billableServiceFormWorkspace:()=>th,root:()=>tb});var o=a(2383),c=a(4499),m=a(3989),u=a(771),d=a(3137),_=a(5275),p=a.n(_),b=a(7767),E=a(4976),g=a(8395);function y({config:e}){let{t}=(0,g.useTranslation)(),{name:a,title:l}=e,n=(0,b.zy)(),i=window.getOpenmrsSpaBase()+"home",r=(0,_.useMemo)(()=>n.pathname.split("/").map(e=>decodeURIComponent(e)).includes(a),[n.pathname,a]);return p().createElement(d.ConfigurableLink,{to:i+"/"+a,className:`cds--side-nav__link ${r&&"active-left-nav-link"}`},t(l))}var h=a(6800);function f({config:e}){let{title:t,path:a,icon:l,privilege:n}=e,{t:i}=(0,g.useTranslation)(),r=(0,b.zy)(),s=`${window.spaBase}/billable-services`,o=(0,_.useMemo)(()=>{let e=r.pathname.replace(s,"");return""===a||"/"===a?""===e||"/"===e:e.startsWith(`/${a}`)},[r.pathname,a,s]),c=p().createElement(h.VxE,{onClick:()=>{(0,d.navigate)({to:`${s}/${a}`})},renderIcon:l,isActive:o},i(t));return n?p().createElement(d.UserHasAccess,{privilege:n},c):c}function v({config:e}){let{title:t,icon:a,items:l,privilege:n}=e,{t:i}=(0,g.useTranslation)(),r=`${window.spaBase}/billable-services`,s=p().createElement(h.whj,{defaultExpanded:!0,title:i(t),renderIcon:a},l.map(e=>p().createElement(h.ldn,{key:e.name,onClick:()=>{var t;return t=e.path,void(0,d.navigate)({to:`${r}/${t}`})}},i(e.title))));return n?p().createElement(d.UserHasAccess,{privilege:n},s):s}function C({config:e}){let{title:t,path:a,icon:l}=e,{t:n}=(0,g.useTranslation)(),i=(0,b.zy)(),r=`${window.spaBase}/billable-services`,s=(0,_.useMemo)(()=>{let e=i.pathname.replace(r,"");return""===a||"/"===a?""===e||"/"===e:e.startsWith(`/${a}`)},[i.pathname,a,r]);return p().createElement(h.VxE,{onClick:()=>{(0,d.navigate)({to:`${r}/${a}`})},renderIcon:l,isActive:s},n(t))}function N({config:e}){let{title:t,path:a,icon:l}=e,{t:n}=(0,g.useTranslation)(),i=(0,b.zy)(),r=`${globalThis.spaBase}/billable-services`,s=(0,_.useMemo)(()=>{let e=i.pathname.replace(r,"");return""===a||"/"===a?""===e||"/"===e:e.startsWith(`/${a}`)},[i.pathname,a,r]);return p().createElement(h.VxE,{onClick:()=>{(0,d.navigate)({to:`${r}/${a}`})},renderIcon:l,isActive:s},n(t))}var T=a(9564),S=a(6942),k=a.n(S),D=a(2137),A=a(6994);function P({layout:e,handleSearch:t,isValidating:a,launchBillableServiceForm:l,responsiveSize:n,t:i}){return p().createElement(p().Fragment,null,p().createElement("div",{className:"-esm-billing__billable-services__headerContainer___Jom5Q"},p().createElement("div",{className:k()({"-esm-billing__billable-services__tabletHeading___DjbOL":!(0,d.isDesktop)(e),"-esm-billing__billable-services__desktopHeading___JApyg":(0,d.isDesktop)(e)})},p().createElement("h4",null,i("servicesList","Services list"))),p().createElement("div",{className:"-esm-billing__billable-services__backgroundDataFetchingIndicator___Icc-9"},p().createElement("span",null,a?p().createElement(h.OuH,null):null))),p().createElement("div",{className:"-esm-billing__billable-services__actionsContainer___gjC3h"},p().createElement(h.vji,{labelText:"",placeholder:i("filterTable","Filter table"),onChange:t,size:n}),p().createElement(h.$nd,{size:n,kind:"primary",renderIcon:e=>p().createElement(D.Qp,{size:16,...e}),onClick:l,iconDescription:i("addNewBillableService","Add new billable service")},i("addNewService","Add new service"))))}let w=()=>{let{t:e}=(0,g.useTranslation)(),{billableServices:t,isLoading:a,isValidating:l,error:n,mutate:i}=(0,A.ly)(),r=(0,d.useLayoutType)(),{pageSize:s}=(0,d.useConfig)(),[o,c]=(0,_.useState)(""),m=(0,d.isDesktop)(r)?"lg":"sm",[u,b]=(0,_.useState)(s??10),E=[{header:e("serviceName","Service name"),key:"serviceName"},{header:e("shortName","Short name"),key:"shortName"},{header:e("serviceType","Service type"),key:"serviceType"},{header:e("serviceStatus","Service status"),key:"status"},{header:e("prices","Prices"),key:"prices"}],y=(0,_.useCallback)(()=>{(0,d.launchWorkspace2)("billable-service-form",{onWorkspaceClose:i})},[i]),f=(0,_.useMemo)(()=>{let e=Array.isArray(t)?t.flat():t;if(void 0!==e&&e.length>0){let t=o.trim();if(t){let a=t.toLowerCase();return e.filter(e=>Object.entries(e).some(([e,t])=>"uuid"!==e&&`${t}`.toLowerCase().includes(a)))}}return e},[o,t]),{paginated:v,goTo:C,results:N,currentPage:T}=(0,d.usePagination)(f,u),S=[];N&&N.forEach(e=>{let t={id:e.uuid,uuid:e.uuid,serviceName:e.name,shortName:e.shortName,serviceType:e?.serviceType?.display,status:e.serviceStatus,prices:e.servicePrices.map(e=>`${e.name} (${e.price})`).join(", ")||"--"};S.push(t)});let k=(0,_.useCallback)(e=>{C(1),c(e.target.value)},[C,c]),D=(0,_.useCallback)(e=>{(0,d.launchWorkspace2)("billable-service-form",{serviceToEdit:e,onWorkspaceClose:i})},[i]);return a?p().createElement(h.OuH,{status:"active",iconDescription:(0,d.getCoreTranslation)("loading"),description:e("loading","Loading data")+"..."}):n?p().createElement(d.ErrorState,{headerTitle:e("billableService","Billable service"),error:n}):0===t.length?p().createElement(d.EmptyCard,{displayText:e("billableServices__lower","billable services"),headerTitle:e("billableService","Billable service"),launchForm:y}):p().createElement("div",{className:"-esm-billing__billable-services__serviceContainer___x-Geg"},p().createElement(P,{handleSearch:k,isValidating:l,launchBillableServiceForm:y,layout:r,responsiveSize:m,t:e}),p().createElement(h.bQt,{isSortable:!0,rows:S,headers:E,overflowMenuOnHover:(0,d.isDesktop)(r),size:m,useZebraStyles:S?.length>1},({rows:t,headers:a,getHeaderProps:l,getRowProps:n,getTableProps:i})=>p().createElement(h.K3K,null,p().createElement(h.XIK,{...i(),"aria-label":e("serviceList","Service list")},p().createElement(h.ndF,null,p().createElement(h.Hjg,null,a.map(e=>p().createElement(h.A0N,{...l({header:e}),key:e.key},e.header)),p().createElement(h.A0N,{"aria-label":(0,d.getCoreTranslation)("actions")}))),p().createElement(h.BFY,null,t.map(t=>p().createElement(h.Hjg,{key:t.id,...n({row:t})},t.cells.map(e=>p().createElement(h.nA6,{key:e.id},e.value)),p().createElement(h.nA6,{className:"cds--table-column-menu"},p().createElement(h.obU,{size:"lg",flipped:!0},p().createElement(h.XSD,{className:"-esm-billing__billable-services__menuItem___yk74T",itemText:e("editBillableService","Edit billable service"),onClick:()=>D(N.find(e=>e.uuid===t.id))}))))))))),f?.length===0&&p().createElement("div",{className:"-esm-billing__billable-services__filterEmptyState___Gklg-"},p().createElement(h.Wdr,{level:0},p().createElement(h.FAs,{className:"-esm-billing__billable-services__filterEmptyStateTile___DHTbi"},p().createElement("p",{className:"-esm-billing__billable-services__filterEmptyStateContent___n3TI3"},e("noMatchingServicesToDisplay","No matching services to display")),p().createElement("p",{className:"-esm-billing__billable-services__filterEmptyStateHelper___pVBoH"},e("checkFilters","Check the filters above"))))),v&&p().createElement(h.dKS,{forwardText:e("nextPage","Next page"),backwardText:e("previousPage","Previous page"),page:T,pageSize:u,pageSizes:[10,20,30,40,50],totalItems:f?.length,className:"-esm-billing__billable-services__pagination___UwJIA",size:m,onChange:({pageSize:e,page:t})=>{e!==u&&b(e),t!==T&&C(t)}}))};function I(){return p().createElement("main",{className:"-esm-billing__dashboard__container___PDlGf"},p().createElement("main",{className:"-esm-billing__dashboard__servicesTableContainer___m7wfM"},p().createElement(w,null)))}let L=()=>p().createElement("svg",{width:"64",height:"64",viewBox:"10 10 60 60.02"},p().createElement("title",null,"Billing module illustration"),p().createElement("g",{fill:"none",fillRule:"evenodd"},p().createElement("path",{opacity:"0.5",d:"M58.75 68.639C60.8886 66.8242 64.1114 66.8242 66.25 68.639C67.703 69.8719 70 68.8873 70 67.0314V12.9686C70 11.1128 67.703 10.1281 66.25 11.3611C64.1114 13.1758 60.8886 13.1758 58.75 11.3611C56.6114 9.54632 53.3886 9.54632 51.25 11.3611C49.1114 13.1758 45.8886 13.1758 43.75 11.3611C41.6114 9.54632 38.3886 9.54632 36.25 11.3611C34.1114 13.1758 30.8886 13.1758 28.75 11.3611C26.6114 9.54632 23.3886 9.54632 21.25 11.3611C19.1114 13.1758 15.8886 13.1758 13.75 11.3611C12.297 10.1281 10 11.1128 10 12.9686V67.0314C10 68.8873 12.297 69.8719 13.75 68.639C15.8886 66.8242 19.1114 66.8242 21.25 68.639C23.3886 70.4537 26.6114 70.4537 28.75 68.639C30.8886 66.8242 34.1114 66.8242 36.25 68.639C38.3886 70.4537 41.6114 70.4537 43.75 68.639C45.8886 66.8242 49.1114 66.8242 51.25 68.639C53.3886 70.4537 56.6114 70.4537 58.75 68.639Z",fill:"#CEE6E5"}),p().createElement("path",{d:"M22.5 51.6666C22.5 50.2859 23.6193 49.1666 25 49.1666H55C56.3807 49.1666 57.5 50.2859 57.5 51.6666C57.5 53.0474 56.3807 54.1666 55 54.1666H25C23.6193 54.1666 22.5 53.0474 22.5 51.6666Z",fill:"#7BBCB9"}),p().createElement("path",{d:"M22.5 40C22.5 38.6193 23.6193 37.5 25 37.5H55C56.3807 37.5 57.5 38.6193 57.5 40C57.5 41.3807 56.3807 42.5 55 42.5H25C23.6193 42.5 22.5 41.3807 22.5 40Z",fill:"#7BBCB9"}),p().createElement("path",{d:"M22.5 28.3333C22.5 26.9526 23.6193 25.8333 25 25.8333H55C56.3807 25.8333 57.5 26.9526 57.5 28.3333C57.5 29.714 56.3807 30.8333 55 30.8333H25C23.6193 30.8333 22.5 29.714 22.5 28.3333Z",fill:"#7BBCB9"}))),M=({title:e})=>{let{t}=(0,g.useTranslation)();return p().createElement("div",{className:"-esm-billing__billing-header__header___P+PIw","data-testid":"billing-header"},p().createElement("div",{className:"-esm-billing__billing-header__left-justified-items___0FINv"},p().createElement(L,null),p().createElement("div",{className:"-esm-billing__billing-header__page-labels___Z52tc"},p().createElement("p",null,t("billing","Billing")),p().createElement("p",{className:"-esm-billing__billing-header__page-name___uiEHw"},e))))},B=()=>{let{t:e}=(0,g.useTranslation)(),[t,a]=(0,_.useState)([]),l=(0,_.useCallback)(async()=>{try{let e=await (0,d.openmrsFetch)(`${d.restBaseUrl}/billing/cashPoint?v=full`);a(e.data.results||[])}catch(t){(0,d.showSnackbar)({title:(0,d.getCoreTranslation)("error"),subtitle:e("errorFetchingCashPoints","An error occurred while fetching cash points."),kind:"error",isLowContrast:!1})}},[e]);(0,_.useEffect)(()=>{l()},[l]);let n=t.map(e=>({id:e.uuid,name:e.name,uuid:e.uuid,location:e.location?e.location.display:"None"})),i=[{key:"name",header:e("name","Name")},{key:"uuid",header:e("uuid","UUID")},{key:"location",header:e("location","Location")}];return p().createElement("div",{className:"-esm-billing__cash-point-configuration__container___-hvwr"},p().createElement("div",{className:"-esm-billing__cash-point-configuration__card___ytTem"},p().createElement(d.CardHeader,{title:e("cashPointHistory","Cash point history")},p().createElement(h.$nd,{renderIcon:D.OM,onClick:()=>{let e=(0,d.showModal)("add-cash-point-modal",{onCashPointAdded:l,closeModal:()=>e()})},kind:"ghost"},e("addNewCashPoint","Add new cash point"))),p().createElement("div",null,p().createElement(h.bQt,{rows:n,headers:i,isSortable:!0,size:"lg"},({rows:e,headers:t,getTableProps:a,getHeaderProps:l,getRowProps:n})=>p().createElement(h.K3K,null,p().createElement(h.XIK,{className:"-esm-billing__cash-point-configuration__table___x+kW9",...a()},p().createElement(h.ndF,null,p().createElement(h.Hjg,null,t.map(e=>p().createElement(h.A0N,{key:e.key,...l({header:e})},e.header)))),p().createElement(h.BFY,null,e.map(e=>p().createElement(h.Hjg,{key:e.id,...n({row:e})},e.cells.map(e=>p().createElement(h.nA6,{key:e.id},e.value)))))))))))},R="-esm-billing__payment-modes-config__menuItem___7qBhO",q=()=>{let{t:e}=(0,g.useTranslation)(),{paymentModes:t,error:a,isLoadingPaymentModes:l}=(0,A.WJ)(),n=t.map(e=>({id:e.uuid,name:e.name,description:e.description||"--"})),i=[{key:"name",header:e("name","Name")},{key:"description",header:e("description","Description")},{key:"actions",header:(0,d.getCoreTranslation)("actions")}];return l?p().createElement(h.OuH,{status:"active",iconDescription:(0,d.getCoreTranslation)("loading"),description:e("loading","Loading data")+"..."}):a?p().createElement(d.ErrorState,{headerTitle:e("paymentMode","Payment mode"),error:a}):p().createElement("div",{className:"-esm-billing__payment-modes-config__container___hB7Cc"},p().createElement("div",{className:"-esm-billing__payment-modes-config__card___FGL9q"},p().createElement(d.CardHeader,{title:e("paymentModeHistory","Payment mode history")},p().createElement(h.$nd,{renderIcon:D.OM,onClick:()=>{let e=(0,d.showModal)("payment-mode-form-modal",{closeModal:()=>e()})},kind:"ghost"},e("addNewPaymentMode","Add new payment mode"))),p().createElement(h.bQt,{rows:n,headers:i,isSortable:!0,size:"lg"},({rows:e,headers:a,getTableProps:l,getHeaderProps:n,getRowProps:i})=>p().createElement(h.K3K,null,p().createElement(h.XIK,{className:"-esm-billing__payment-modes-config__table___Zs7R+",...l()},p().createElement(h.ndF,null,p().createElement(h.Hjg,null,a.map(e=>p().createElement(h.A0N,{key:e.key,...n({header:e})},e.header)))),p().createElement(h.BFY,null,e.map(e=>p().createElement(h.Hjg,{key:e.id,...i({row:e})},e.cells.map(a=>"actions"!==a.info.header?p().createElement(h.nA6,{key:a.id},a.value):p().createElement(h.nA6,{key:a.id},p().createElement(h.obU,null,p().createElement(h.XSD,{className:R,itemText:(0,d.getCoreTranslation)("edit"),onClick:()=>{let a,l=t.find(t=>t.uuid===e.id);l&&(a=(0,d.showModal)("payment-mode-form-modal",{editPaymentMode:l,closeModal:()=>a()}))}}),p().createElement(h.XSD,{className:R,itemText:(0,d.getCoreTranslation)("delete"),onClick:()=>{let a,l=t.find(t=>t.uuid===e.id);l&&(a=(0,d.showModal)("delete-payment-mode-modal",{paymentModeUuid:l.uuid,paymentModeName:l.name,closeModal:()=>a()}))}}))))))))))))};var F=a(1772),x=a(2914),j=a.n(x),$=a(7003);let U=`${$.B}billDiscount`,H=`${$.B}bill`;async function O(e){return(await (0,d.openmrsFetch)(U,{method:"POST",headers:{"Content-Type":"application/json"},body:e})).data}async function z(e,t,a){return(await (0,d.openmrsFetch)(`${U}/${e}`,{method:"POST",headers:{"Content-Type":"application/json"},body:{status:t,approver:a}})).data}async function V(e,t){await (0,d.openmrsFetch)(`${U}/${e}?reason=${encodeURIComponent(t)}`,{method:"DELETE"})}var K=a(5084);let W={container:"-esm-billing__discount-requests__container___Oz7Sy",servicesTableContainer:"-esm-billing__discount-requests__servicesTableContainer___LRvfc",sectionMargin:"-esm-billing__discount-requests__sectionMargin___xsMap",emptyStateContainer:"-esm-billing__discount-requests__emptyStateContainer___5+u6v",loaderContainer:"-esm-billing__discount-requests__loaderContainer___UxUmn",errorContainer:"-esm-billing__discount-requests__errorContainer___lTCUs",billListContainer:"-esm-billing__discount-requests__billListContainer___Iy16I",filterEmptyState:"-esm-billing__discount-requests__filterEmptyState___OqM0-",filterContainer:"-esm-billing__discount-requests__filterContainer___4mog+",headerContainer:"-esm-billing__discount-requests__headerContainer___OQEp3",row:"-esm-billing__discount-requests__row___yW0Qk",statusTags:"-esm-billing__discount-requests__statusTags___lGmnm",illo:"-esm-billing__discount-requests__illo___f7Xua",content:"-esm-billing__discount-requests__content___FlVLI",desktopHeading:"-esm-billing__discount-requests__desktopHeading___jySob",tabletHeading:"-esm-billing__discount-requests__tabletHeading___LE23P",tile:"-esm-billing__discount-requests__tile___pM5j8",filterEmptyStateTile:"-esm-billing__discount-requests__filterEmptyStateTile___0XhKz",filterEmptyStateContent:"-esm-billing__discount-requests__filterEmptyStateContent___8LzTm",filterEmptyStateHelper:"-esm-billing__discount-requests__filterEmptyStateHelper___G-NDy"};function G({layout:e,handleSearch:t,isValidating:a,responsiveSize:l,searchString:n,t:i}){return p().createElement(p().Fragment,null,p().createElement("div",{className:W.headerContainer},p().createElement("div",{className:k()({[W.tabletHeading]:!(0,d.isDesktop)(e),[W.desktopHeading]:(0,d.isDesktop)(e)})},p().createElement("h4",null,i("discountRequests","Discount requests"))),a&&p().createElement("div",{className:W.backgroundDataFetchingIndicator},p().createElement("span",null,p().createElement(h.OuH,null)))),p().createElement(h.vji,{closeButtonLabelText:i("clearSearch","Clear"),"data-testid":"discountRequestsSearchBar",labelText:i("searchDiscountRequests","Search discount requests"),placeholder:i("searchByPatientOrBill","Search by patient name or bill #"),value:n,onChange:t,size:l}))}let Q=()=>{var e;let{t}=(0,g.useTranslation)(),{defaultCurrency:a,pageSize:l}=(0,d.useConfig)(),n=(0,d.useLayoutType)(),i=(0,d.isDesktop)(n)?"sm":"lg",r=(0,_.useMemo)(()=>[{id:"PENDING",text:t("pending","Pending")},{id:"APPROVED",text:t("approved","Approved")},{id:"REJECTED",text:t("rejected","Rejected")},{id:"ALL",text:t("all","All")}],[t]),[s,o]=(0,_.useState)(r[0]),[c,m]=(0,_.useState)(l??10),[u,b]=(0,_.useState)(""),{bills:E,isLoading:y,error:f,mutate:v,isValidating:C}=function({statuses:e}){let t=new URLSearchParams({discountStatus:e.join(","),v:"default"}),a=`${H}?${t.toString()}`,{data:l,isLoading:n,error:i,mutate:r,isValidating:s}=(0,d.useOpenmrsFetchAll)(a);return{bills:l??[],isLoading:n,error:i,mutate:r,isValidating:s}}({statuses:"ALL"===(e=s.id)?[K.nT.PENDING,K.nT.APPROVED,K.nT.REJECTED]:[e]}),N=(0,_.useMemo)(()=>{let e=u.trim().toLowerCase();return e?E.filter(t=>t.patient?.display?.toLowerCase().includes(e)||t.receiptNumber?.toLowerCase().includes(e)):E},[E,u]),{paginated:T,goTo:S,results:k,currentPage:D}=(0,d.usePagination)(N,c),{pageSizes:A}=(0,d.usePaginationInfo)(c,N.length,D,k.length),P=(0,_.useMemo)(()=>[{key:"dateCreated",header:t("date","Date")},{key:"receiptNumber",header:t("invoiceNo","Invoice #")},{key:"patient",header:t("patient","Patient")},{key:"billAmount",header:t("billAmount","Bill amount")},{key:"cashier",header:t("cashier","Cashier")}],[t]),w=(0,_.useCallback)(e=>{let t=(0,d.showModal)("review-bill-discounts-modal",{bill:e,onMutate:v,closeModal:()=>t()})},[v]),I=(0,_.useMemo)(()=>k.map(e=>({id:e.uuid,dateCreated:e.dateCreated?(0,d.formatDate)((0,d.parseDate)(e.dateCreated),{mode:"wide"}):"--",patient:e.patient?.display??"--",receiptNumber:e.receiptNumber?p().createElement(h.N_E,{href:"#",onClick:t=>{t.preventDefault(),t.stopPropagation(),w(e)}},e.receiptNumber):"--",billAmount:(0,F.aL)(e.total??0,a),cashier:e.cashier?.display??"--",_raw:e})),[k,a,w]),L=(0,_.useCallback)(e=>{b(e.target.value),S(1)},[S]);return p().createElement("main",{className:W.container},p().createElement("main",{className:W.servicesTableContainer},p().createElement("div",{className:W.filterContainer},p().createElement(h.msM,{className:W.filterDropdown,direction:"bottom",id:"discount-status-filter",selectedItem:s,items:r,itemToString:e=>e?e.text:"",label:"",onChange:({selectedItem:e})=>{o(e),S(1)},size:i,titleText:t("filterBy","Filter by:"),type:"inline"})),p().createElement("div",{className:W.billListContainer},p().createElement(G,{handleSearch:L,isValidating:C,layout:n,responsiveSize:i,searchString:u,t:t}),y&&!E?.length?p().createElement("div",{className:W.loaderContainer,role:"progressbar","aria-label":t("loadingDescription","Loading")},p().createElement(h.OOb,{rowCount:c,showHeader:!1,showToolbar:!1,zebra:!0,columnCount:P.length})):f?p().createElement("div",{className:W.errorContainer},p().createElement(h.Wdr,null,p().createElement(d.ErrorState,{error:f,headerTitle:t("discountRequests","Discount requests")}))):I.length>0?p().createElement(p().Fragment,null,p().createElement(h.bQt,{isSortable:!0,rows:I,headers:P,size:i,useZebraStyles:I.length>1},({rows:e,headers:a,getRowProps:l,getTableProps:n})=>p().createElement(h.K3K,null,p().createElement(h.XIK,{...n(),"aria-label":t("discountRequests","Discount requests")},p().createElement(h.ndF,null,p().createElement(h.Hjg,null,a.map(e=>p().createElement(h.A0N,{key:e.key},e.header)))),p().createElement(h.BFY,null,e.map(e=>p().createElement(h.Hjg,{key:e.id,...l({row:e}),className:W.row,onClick:()=>{let t=I.find(t=>t.id===e.id);t&&w(t._raw)}},e.cells.map(e=>p().createElement(h.nA6,{key:e.id},e.value)))))))),T&&p().createElement(h.dKS,{forwardText:t("nextPage","Next page"),backwardText:t("previousPage","Previous page"),page:D,pageSize:c,pageSizes:A,totalItems:N.length,size:i,onChange:({pageSize:e,page:t})=>{e!==c&&m(e),t!==D&&S(t)}})):p().createElement(h.Wdr,{className:W.emptyStateContainer},p().createElement(h.FAs,{className:W.tile},p().createElement("div",{className:W.illo},p().createElement(d.EmptyCardIllustration,null)),p().createElement("p",{className:W.content},t("noDiscountRequestsToDisplay","There are no discount requests to display.")))))))};var J=a(8683);let X={container:"-esm-billing__refund-requests__container___Wt9xd",servicesTableContainer:"-esm-billing__refund-requests__servicesTableContainer___IChqx",sectionMargin:"-esm-billing__refund-requests__sectionMargin___aL-4-",emptyStateContainer:"-esm-billing__refund-requests__emptyStateContainer___UcXAt",loaderContainer:"-esm-billing__refund-requests__loaderContainer___ImaKM",errorContainer:"-esm-billing__refund-requests__errorContainer___WvLOw",billListContainer:"-esm-billing__refund-requests__billListContainer___fs+ZV",filterEmptyState:"-esm-billing__refund-requests__filterEmptyState___KAwFs",filterContainer:"-esm-billing__refund-requests__filterContainer___hP1MN",headerContainer:"-esm-billing__refund-requests__headerContainer___ooxMR",row:"-esm-billing__refund-requests__row___yKZOb",statusTags:"-esm-billing__refund-requests__statusTags___J2Aq7",illo:"-esm-billing__refund-requests__illo___CafiD",content:"-esm-billing__refund-requests__content___H+jeh",desktopHeading:"-esm-billing__refund-requests__desktopHeading___brWKR",tabletHeading:"-esm-billing__refund-requests__tabletHeading___GlO5d",tile:"-esm-billing__refund-requests__tile___gu7cO",filterEmptyStateTile:"-esm-billing__refund-requests__filterEmptyStateTile___5HpOu",filterEmptyStateContent:"-esm-billing__refund-requests__filterEmptyStateContent___wE5s3",filterEmptyStateHelper:"-esm-billing__refund-requests__filterEmptyStateHelper___m2t8f"};function Z({layout:e,handleSearch:t,isValidating:a,responsiveSize:l,searchString:n,t:i}){return p().createElement(p().Fragment,null,p().createElement("div",{className:X.headerContainer},p().createElement("div",{className:k()({[X.tabletHeading]:!(0,d.isDesktop)(e),[X.desktopHeading]:(0,d.isDesktop)(e)})},p().createElement("h4",null,i("refundRequests","Refund requests"))),a&&p().createElement("span",null,p().createElement(h.OuH,null))),p().createElement(h.vji,{closeButtonLabelText:i("clearSearch","Clear"),"data-testid":"refundRequestsSearchBar",labelText:i("searchRefundRequests","Search refund requests"),placeholder:i("searchByPatientOrBill","Search by patient name or bill #"),value:n,onChange:t,size:l}))}let Y=()=>{var e;let t,{t:a}=(0,g.useTranslation)(),{defaultCurrency:l,pageSize:n}=(0,d.useConfig)(),i=(0,d.useLayoutType)(),r=(0,d.isDesktop)(i)?"sm":"lg",s=(0,_.useMemo)(()=>[{id:"REQUESTED",text:a("requested","Requested")},{id:"APPROVED",text:a("approved","Approved")},{id:"REJECTED",text:a("rejected","Rejected")},{id:"COMPLETED",text:a("completed","Completed")},{id:"ALL",text:a("all","All")}],[a]),[o,c]=(0,_.useState)(s[0]),[m,u]=(0,_.useState)(n??10),[b,E]=(0,_.useState)(""),{bills:y,isLoading:f,error:v,mutate:C,isValidating:N}=(0,J.KY)({statuses:"ALL"===(e=o.id)?[K.fH.REQUESTED,K.fH.APPROVED,K.fH.REJECTED,K.fH.COMPLETED]:[e]}),T=(0,_.useMemo)(()=>{let e=b.trim().toLowerCase();return e?y.filter(t=>t.patient?.display?.toLowerCase().includes(e)||t.receiptNumber?.toLowerCase().includes(e)):y},[y,b]),{paginated:S,goTo:k,results:D,currentPage:A}=(0,d.usePagination)(T,m),{pageSizes:P}=(0,d.usePaginationInfo)(m,T.length,A,D.length),w=(0,_.useMemo)(()=>[{key:"dateCreated",header:a("date","Date")},{key:"receiptNumber",header:a("invoiceNo","Invoice #")},{key:"patient",header:a("patient","Patient")},{key:"billAmount",header:a("billAmount","Bill amount")},{key:"cashier",header:a("cashier","Cashier")}],[a]),I=(0,_.useCallback)(e=>{let t=(0,d.showModal)("review-bill-refunds-modal",{bill:e,onMutate:C,closeModal:()=>t()})},[C]),L=(0,_.useMemo)(()=>D.map(e=>({id:e.uuid,dateCreated:e.dateCreated?(0,d.formatDate)((0,d.parseDate)(e.dateCreated),{mode:"wide"}):"--",patient:e.patient?.display??"--",receiptNumber:e.receiptNumber?p().createElement(h.N_E,{href:"#",onClick:t=>{t.preventDefault(),t.stopPropagation(),I(e)}},e.receiptNumber):"--",billAmount:(0,F.aL)(e.total??0,l),cashier:e.cashier?.display??"--",_raw:e})),[D,l,I]),M=(0,_.useCallback)(e=>{E(e.target.value),k(1)},[k]),B=(0,_.useCallback)(e=>{let t=L.find(t=>t.id===e);t&&I(t._raw)},[L,I]);return t=f&&!y?.length?p().createElement("div",{className:X.loaderContainer,"aria-busy":"true","aria-label":a("loading","Loading")},p().createElement(h.OOb,{rowCount:m,showHeader:!1,showToolbar:!1,zebra:!0,columnCount:w.length})):v?p().createElement("div",{className:X.errorContainer},p().createElement(h.Wdr,null,p().createElement(d.ErrorState,{error:v,headerTitle:a("refundRequests","Refund requests")}))):L.length>0?p().createElement(p().Fragment,null,p().createElement(h.bQt,{isSortable:!0,rows:L,headers:w,size:r,useZebraStyles:L.length>1},({rows:e,headers:t,getRowProps:l,getTableProps:n})=>p().createElement(h.K3K,null,p().createElement(h.XIK,{...n(),"aria-label":a("refundRequests","Refund requests")},p().createElement(h.ndF,null,p().createElement(h.Hjg,null,t.map(e=>p().createElement(h.A0N,{key:e.key},e.header)))),p().createElement(h.BFY,null,e.map(e=>p().createElement(h.Hjg,{key:e.id,...l({row:e}),className:X.row,onClick:()=>B(e.id)},e.cells.map(e=>p().createElement(h.nA6,{key:e.id},e.value)))))))),S&&p().createElement(h.dKS,{forwardText:a("nextPage","Next page"),backwardText:a("previousPage","Previous page"),page:A,pageSize:m,pageSizes:P,totalItems:T.length,size:r,onChange:({pageSize:e,page:t})=>{e!==m&&u(e),t!==A&&k(t)}})):p().createElement(h.Wdr,{className:X.emptyStateContainer},p().createElement(h.FAs,{className:X.tile},p().createElement("div",{className:X.illo},p().createElement(d.EmptyCardIllustration,null)),p().createElement("p",{className:X.content},a("noRefundRequestsToDisplay","There are no refund requests to display.")))),p().createElement("main",{className:X.container},p().createElement("div",{className:X.servicesTableContainer},p().createElement("div",{className:X.filterContainer},p().createElement(h.msM,{className:X.filterDropdown,direction:"bottom",id:"refund-status-filter",selectedItem:o,items:s,itemToString:e=>e?e.text:"",label:"",onChange:({selectedItem:e})=>{c(e),k(1)},size:r,titleText:a("filterBy","Filter by:"),type:"inline"})),p().createElement("div",{className:X.billListContainer},p().createElement(Z,{handleSearch:M,isValidating:N,layout:i,responsiveSize:r,searchString:b,t:a}),t)))};var ee=a(6199);let et="-esm-billing__bill-action-menu__menuItem___IEXNy",ea=({bill:e,patientUuid:t,onMutate:a})=>{let{t:l}=(0,g.useTranslation)(),n=(0,d.useLayoutType)(),i=e?.status===K.ih.PENDING;return p().createElement(h.Wdr,null,p().createElement(h.obU,{align:"left",flipped:!0,size:(0,d.isDesktop)(n)?"sm":"lg","data-testid":`action-menu-${e.uuid}`},p().createElement(h.XSD,{className:et,itemText:l("addItemsToBill","Add items to bill"),onClick:()=>(0,d.launchWorkspace2)("patient-chart-billing-form-workspace",{patientUuid:t,billUuid:e.uuid,onMutate:a})}),i&&p().createElement(h.XSD,{className:et,hasDivider:!0,isDelete:!0,itemText:l("deleteBill","Delete bill"),onClick:()=>{let t=(0,d.showModal)("delete-bill-confirmation-modal",{bill:e,onSuccess:a,closeModal:()=>t()})}})))};var el=a(6762),en=a(4476),ei=a(3285),er=a(9785),es=a(1362);let eo={sectionContainer:"-esm-billing__visit-attributes-form__sectionContainer___aj98I",sectionTitle:"-esm-billing__visit-attributes-form__sectionTitle___kol0c",visitAttributesContainer:"-esm-billing__visit-attributes-form__visitAttributesContainer___ArSYD",radioButtonGroup:"-esm-billing__visit-attributes-form__radioButtonGroup___mSIc2",stack:"-esm-billing__visit-attributes-form__stack___HU1se",paymentDetailsLegend:"-esm-billing__visit-attributes-form__paymentDetailsLegend___uTIXR"},ec=en.z.object({paymentDetails:en.z.string(),paymentMethods:en.z.string(),insuranceSchema:en.z.string(),policyNumber:en.z.string(),patientCategory:en.z.string()}),em=({setAttributes:e,setPaymentMethod:t})=>{let{t:a}=(0,g.useTranslation)(),{patientCategory:l,categoryConcepts:n,nonPayingPatientCategories:i}=(0,d.useConfig)(),{control:r,getValues:s,watch:o}=(0,er.mN)({mode:"all",defaultValues:{},resolver:(0,ei.u)(ec)}),[c,m,u,b,E]=o(["paymentDetails","paymentMethods","insuranceScheme","policyNumber","patientCategory"]),{paymentModes:y,isLoading:f}=(()=>{let e=`${$.B}paymentMode`,{data:t,isLoading:a,error:l}=j()(e,d.openmrsFetch);return{isLoading:a,error:l,paymentModes:t?.data?.results??[]}})(),v=(0,_.useMemo)(()=>Object.entries(i??{}).map(([e,t])=>({text:a(e),uuid:t})),[i,a]),C=(0,_.useCallback)(()=>{let{paymentDetails:e,paymentMethods:a,insuranceScheme:n,policyNumber:i,patientCategory:r}=s();return t?.(a),Object.entries([{uuid:l.paymentDetails,value:e},{uuid:l.paymentMethods,value:a},{uuid:l.insuranceScheme,value:n},{uuid:l.policyNumber,value:i},{uuid:l.patientCategory,value:r}].filter(e=>void 0!==e.value&&null!==e.value&&""!==e.value)).map(([e,t])=>({attributeType:t.uuid,value:t.value}))},[s,l.insuranceScheme,l.patientCategory,l.paymentDetails,l.paymentMethods,l.policyNumber,t]);return((0,_.useEffect)(()=>{e(C())},[c,m,u,b,E,e,C]),f)?p().createElement(h.OuH,{status:"active",iconDescription:a("loadingDescription","Loading"),description:a("loading","Loading data")+"..."}):p().createElement(h.BJc,{className:eo.stack,gap:5},p().createElement(er.xI,{name:"paymentDetails",control:r,render:({field:e})=>p().createElement(h.zWQ,{className:eo.radioButtonGroup,legendText:p().createElement("div",{className:eo.paymentDetailsLegend},a("paymentDetails","Payment details"),p().createElement(h.Gff,{autoAlign:!0,align:"bottom"},p().createElement(h.yvu,{label:a("showInformation","Show information")},p().createElement(es.$$,null)),p().createElement(h.pNg,null,p().createElement("p",null,a("nonPayingInfo","Any services rendered to non-paying patients will not be billed"))))),name:"payment-details",onChange:t=>e.onChange(t),orientation:"vertical"},p().createElement(h.aaP,{labelText:a("paying","Paying"),value:n.payingDetails,id:"payment-details-paying"}),p().createElement(h.aaP,{labelText:a("nonPaying","Non paying"),value:n.nonPayingDetails,id:"payment-details-non-paying"}))}),c===n.payingDetails&&p().createElement(er.xI,{control:r,name:"paymentMethods",render:({field:e})=>p().createElement(h.a32,{id:"paymentMethods",items:y,itemToString:e=>e?e.name:"",onChange:({selectedItem:t})=>e.onChange(t?.uuid),placeholder:a("selectPaymentMethod","Select payment method"),titleText:a("paymentMethod","Payment method")})}),m===n.insuranceDetails&&c===n.payingDetails&&p().createElement(p().Fragment,null,p().createElement(er.xI,{control:r,name:"insuranceScheme",render:({field:e})=>p().createElement(h.ksK,{id:"insurance-scheme",labelText:a("insuranceScheme","Insurance scheme"),onChange:t=>e.onChange(t.target.value),type:"text"})}),p().createElement(er.xI,{control:r,name:"policyNumber",render:({field:e})=>p().createElement(h.ksK,{...e,id:"policy-number",labelText:a("policyNumber","Policy number"),onChange:t=>e.onChange(t.target.value),type:"text"})})),c===n.nonPayingDetails&&p().createElement(er.xI,{control:r,name:"patientCategory",render:({field:e})=>p().createElement(h.a32,{className:eo.sectionField,onChange:({selectedItem:t})=>e.onChange(t?.uuid),id:"patientCategory",items:v,itemToString:e=>e?e.text:"",titleText:a("patientCategory","Patient category"),placeholder:a("selectPatientCategory","Select patient category")})}))},eu=p().memo(({patientUuid:e,setExtraVisitInfo:t})=>{let{t:a}=(0,g.useTranslation)(),{mutate:l}=(0,x.useSWRConfig)(),{categoryConcepts:n}=(0,d.useConfig)(),{lastVisitInfo:i,isLoading:r,error:s}=(e=>{let t=`${d.restBaseUrl}/visit?patient=${e}&v=default&limit=1&sort=desc:startDatetime`,{data:a,isLoading:l,error:n}=j()(e?t:null,d.openmrsFetch);return{lastVisitInfo:(0,_.useMemo)(()=>{let e=a?.data?.results;if(!e?.length)return null;let t=e[0],l=new Date(t.startDatetime);return isNaN(l.getTime())?null:{diffDays:Math.floor(Math.abs(Date.now()-l.getTime())/864e5),type:t.visitType?.display??"",location:t.location?.display??""}},[a]),isLoading:l,error:n}})(e);(0,_.useEffect)(()=>{s&&(0,d.showSnackbar)({title:a("lastVisitError","Last visit error"),subtitle:a("errorLoadingLastVisit","An error occurred while loading the last visit"),kind:"error"})},[s,a]);let{cashPoints:o,isLoading:c,error:m}=(()=>{let e=`${$.B}cashPoint`,{data:t,isLoading:a,error:l}=j()(e,d.openmrsFetch);return{isLoading:a,error:l,cashPoints:t?.data?.results??[]}})(),{lineItems:u,isLoading:b,error:E}=(()=>{let e=`${$.B}billableService?v=custom:(uuid,name,shortName,serviceStatus,serviceType:(display),servicePrices:(uuid,name,price,paymentMode))`,{data:t,isLoading:a,error:l}=j()(e,d.openmrsFetch);return{lineItems:t?.data?.results??[],isLoading:a,error:l}})(),[y,f]=(0,_.useState)([]),[v,C]=(0,_.useState)(null),[N,T]=(0,_.useState)(null),S=(0,_.useRef)(y);(0,_.useEffect)(()=>{S.current=y},[y]);let k=(0,_.useMemo)(()=>!!n?.nonPayingDetails&&!!y?.length&&y.some(e=>e.value===n.nonPayingDetails),[y,n]),D=(0,_.useMemo)(()=>!k&&v&&u?.length?u.filter(e=>e.servicePrices.some(e=>e.paymentMode?.uuid===v)):[],[u,v,k]);(0,_.useEffect)(()=>{t({createBillPayload:null,handleCreateExtraVisitInfo:null,attributes:S.current}),T(null)},[v,k,t]);let A=(0,_.useCallback)(async t=>{try{let n;await (n=`${$.B}bill`,(0,d.openmrsFetch)(n,{method:"POST",headers:{"Content-Type":"application/json"},body:t})),l((0,ee.Z5)(e)),(0,d.showSnackbar)({title:a("patientBill","Patient bill"),subtitle:a("billCreatedSuccessfully","Bill created successfully"),kind:"success"})}catch(e){(0,d.showSnackbar)({title:a("billCreationError","Bill creation error"),subtitle:a("errorCreatingBill","An error occurred while creating the bill"),kind:"error"})}},[l,a,e]),P=(0,_.useCallback)(({selectedItem:a})=>{T(a);let l=o?.[0]?.uuid??"",n=a?.uuid??"",i=a.servicePrices.find(e=>e.paymentMode?.uuid===v)||a?.servicePrices[0],r={lineItems:[{billableService:n,quantity:1,price:i?i.price:"0.000",priceName:"Default",priceUuid:i?i.uuid:"",lineItemOrder:0,status:K.zk.PENDING}],cashPoint:l,patient:e,status:K.ih.PENDING,payments:[]};t({createBillPayload:r,handleCreateExtraVisitInfo:()=>A(r),attributes:y})},[y,o,A,v,e,t]);return b||c?p().createElement(h.OuH,{status:"active",iconDescription:(0,d.getCoreTranslation)("loading"),description:`${a("loadingBillingServices","Loading billing services")}...`}):m||E?p().createElement(h.jeF,{kind:"error",lowContrast:!0,title:a("billErrorService","Billing service error"),subtitle:a("errorLoadingBillServices","Error loading bill services")}):p().createElement("section",{className:"-esm-billing__billing-checkin-form__sectionContainer___TLb4u"},p().createElement("h1",{className:"-esm-billing__billing-checkin-form__sectionLabel___1H1hH"},a("billingDetails","Billing details")),p().createElement("div",{className:"-esm-billing__billing-checkin-form__sectionField___AUKom"},!r&&!s&&i&&p().createElement("div",{className:"-esm-billing__billing-checkin-form__lastVisitBanner___Bh8FX"},p().createElement(h.jeF,{hideCloseButton:!0,kind:"info",title:a("lastVisitInfo","Last Visit Information"),subtitle:a("lastVisitMsg","The last visit was a {{type}} {{count}} days ago at {{location}}",{count:i.diffDays,type:i.type,location:i.location}),lowContrast:!0})),p().createElement(em,{setAttributes:f,setPaymentMethod:C}),D.length>0&&p().createElement(h.msM,{key:`billable-${v}`,id:"billable-items",items:D,itemToString:e=>{let t;return e?`${e.name} ${(t=e.servicePrices.find(e=>e.paymentMode?.uuid===v))?`(${t.name}: ${t.price})`:""}`:""},label:a("selectBillableService","Select a billable service"),onChange:P,selectedItem:N,titleText:a("billableService","Billable service")})))});var ed=a(7661);let e_={sectionTitle:"-esm-billing__bill-item-actions__sectionTitle___VJZLU",modalBody:"-esm-billing__bill-item-actions__modalBody___FImqs",billInfo:"-esm-billing__bill-item-actions__billInfo___grzHg",separator:"-esm-billing__bill-item-actions__separator___CKXsJ",label:"-esm-billing__bill-item-actions__label___FwJ2Z",controlField:"-esm-billing__bill-item-actions__controlField___vJUpf",loader:"-esm-billing__bill-item-actions__loader___UfgTz"},ep="-esm-billing__request-discount-modal__summaryLabel___VaWqh",eb="-esm-billing__request-discount-modal__summaryValue___d6IJk",eE="-esm-billing__bill-line-items-table__right___TBXRJ",eg=({lineItems:e})=>{let{t}=(0,g.useTranslation)(),{defaultCurrency:a}=(0,d.useConfig)();return p().createElement("section",{className:"-esm-billing__bill-line-items-table__ledger___qbKwi"},p().createElement("h3",{className:"-esm-billing__bill-line-items-table__ledgerHeading___M7DcA"},t("lineItems","Line items")),p().createElement("table",{className:"-esm-billing__bill-line-items-table__ledgerTable___Lw3pG"},p().createElement("thead",null,p().createElement("tr",null,p().createElement("th",null,t("item","Item")),p().createElement("th",null,t("qty","Qty")),p().createElement("th",{className:eE},t("price","Price")))),p().createElement("tbody",null,e.map((e,t)=>p().createElement("tr",{key:e.uuid??t},p().createElement("td",{className:"-esm-billing__bill-line-items-table__itemName___dKItf"},e.item||e.billableService||"--"),p().createElement("td",null,e.quantity),p().createElement("td",{className:eE},(0,F.aL)(e.price??0,a)))))))},ey="-esm-billing__bill-payments-table__right___qD-5O",eh=({payments:e})=>{let{t}=(0,g.useTranslation)(),{defaultCurrency:a}=(0,d.useConfig)();return 0===e.length?null:p().createElement("section",{className:"-esm-billing__bill-payments-table__ledger___Qc+ke"},p().createElement("h3",{className:"-esm-billing__bill-payments-table__ledgerHeading___ilV8F"},t("payments","Payments")),p().createElement("table",{className:"-esm-billing__bill-payments-table__ledgerTable___lHxsT"},p().createElement("thead",null,p().createElement("tr",null,p().createElement("th",null,t("method","Method")),p().createElement("th",null,t("date","Date")),p().createElement("th",{className:ey},t("tendered","Tendered")))),p().createElement("tbody",null,e.map(e=>p().createElement("tr",{key:e.uuid},p().createElement("td",null,p().createElement("span",{className:"-esm-billing__bill-payments-table__paymentKind___TglOe"},e.instanceType?.name??"--")),p().createElement("td",null,p().createElement("span",{className:"-esm-billing__bill-payments-table__paymentDate___9NyEF"},e.dateCreated?(0,d.formatDate)(new Date(e.dateCreated),{mode:"wide"}):"--")),p().createElement("td",{className:ey},(0,F.aL)(e.amountTendered??0,a)))))))},ef="-esm-billing__bill-totals-summary__totalsRow___r3Lew",ev="-esm-billing__bill-totals-summary__totalsRowMinus___2n1W4",eC=({subtotal:e,currentNet:t,outstanding:a,paymentsTotal:l,approvedDiscounts:n,pendingDiscounts:i})=>{let{t:r}=(0,g.useTranslation)(),{defaultCurrency:s}=(0,d.useConfig)();return p().createElement("section",{className:"-esm-billing__bill-totals-summary__totals___6iaM7"},p().createElement("div",{className:k()(ef,"-esm-billing__bill-totals-summary__totalsSubtotal___8mWZP")},p().createElement("span",null,r("subtotal","Subtotal")),p().createElement("span",null,(0,F.aL)(e,s))),n.map(e=>p().createElement("div",{key:e.uuid,className:k()(ef,ev)},p().createElement("span",null,"− ",r("discount","Discount")),p().createElement("span",null,(0,F.aL)(e.discountAmount,s)))),p().createElement("hr",{className:"-esm-billing__bill-totals-summary__totalsRule___LldMI"}),p().createElement("div",{className:k()(ef,"-esm-billing__bill-totals-summary__totalsNet___0Bb1l")},p().createElement("span",null,r("currentNet","Current net")),p().createElement("span",{className:"-esm-billing__bill-totals-summary__totalsNetAmount___xvxJT"},(0,F.aL)(t,s))),l>0&&p().createElement("div",{className:k()(ef,"-esm-billing__bill-totals-summary__totalsRowAdd___sbxAx")},p().createElement("span",null,"− ",r("paymentsReceived","Payments received")),p().createElement("span",null,(0,F.aL)(l,s))),p().createElement("hr",{className:"-esm-billing__bill-totals-summary__totalsRuleStrong___Kidyj"}),p().createElement("div",{className:k()(ef,"-esm-billing__bill-totals-summary__totalsOutstanding___fP1bD")},p().createElement("span",null,r("outstanding","Outstanding")),p().createElement("span",{className:"-esm-billing__bill-totals-summary__totalsOutstandingAmount___qQXu3"},(0,F.aL)(a,s))),i.length>0&&p().createElement("div",{className:"-esm-billing__bill-totals-summary__preview___rPSsf"},p().createElement("p",{className:"-esm-billing__bill-totals-summary__previewLabel___mjNu2"},r("ifPendingApproved","If pending discounts approved")),i.map(e=>p().createElement("div",{key:e.uuid,className:k()(ef,ev)},p().createElement("span",null,"− ",r("discount","Discount")," (",e.discountType===K.Bp.PERCENTAGE?`${e.discountValue}%`:(0,F.aL)(e.discountValue,s),")"),p().createElement("span",null,(0,F.aL)(e.discountAmount,s)))),p().createElement("div",{className:k()(ef,"-esm-billing__bill-totals-summary__previewProjected___bUPgY")},p().createElement("span",null,r("projectedNet","Projected net")),p().createElement("span",{className:"-esm-billing__bill-totals-summary__previewProjectedAmount___7yhBk"},(0,F.aL)(t-i.reduce((e,t)=>e+t.discountAmount,0),s)))))},eN=p().memo(({bill:e,lineItems:t,payments:a,paymentsTotal:l,subtotal:n,currentNet:i,outstanding:r,approvedDiscounts:s,pendingDiscounts:o})=>{let{t:c}=(0,g.useTranslation)();return p().createElement("aside",{className:"-esm-billing__bill-receipt-rail__receipt___b5het"},p().createElement("div",{className:"-esm-billing__bill-receipt-rail__patient___gB6Df"},p().createElement("div",null,p().createElement("p",{className:"-esm-billing__bill-receipt-rail__patientName___dNAHq"},e.patient?.display),p().createElement("p",{className:"-esm-billing__bill-receipt-rail__patientId___2KJ7G"},c("receiptNumber","Receipt #"),": ",e.receiptNumber)),e.status&&p().createElement(h.vwO,{type:"blue",size:"sm"},c(String(e.status).toLowerCase(),String(e.status)))),p().createElement("dl",{className:"-esm-billing__bill-receipt-rail__meta___F8p9R"},p().createElement("dt",null,c("issued","Issued")),p().createElement("dd",null,e.dateCreated?(0,d.formatDate)((0,d.parseDate)(e.dateCreated),{mode:"wide"}):"--"),p().createElement("dt",null,c("cashier","Cashier")),p().createElement("dd",null,e.cashier?.display??"--")),p().createElement(eg,{lineItems:t}),p().createElement(eh,{payments:a}),p().createElement(eC,{subtotal:n,currentNet:i,outstanding:r,paymentsTotal:l,approvedDiscounts:s,pendingDiscounts:o}))}),eT="-esm-billing__discount-card__confirmCopy___tkMH1",eS={PENDING:"gray",APPROVED:"green",REJECTED:"red"},ek=({discount:e,lineItems:t,busy:a,rejectingId:l,deletingId:n,canDecide:i,onApprove:r,onStartReject:s,onCancelReject:o,onConfirmReject:c,onStartDelete:m,onCancelDelete:u,onConfirmDelete:_})=>{let{t:b}=(0,g.useTranslation)(),{defaultCurrency:E}=(0,d.useConfig)(),y=l===e.uuid,f=n===e.uuid,v=!y&&!f,C=k()("-esm-billing__discount-card__card___LKhCs",{"-esm-billing__discount-card__cardPending___kkfK0":e.status===K.nT.PENDING,"-esm-billing__discount-card__cardApproved___e22b2":e.status===K.nT.APPROVED,"-esm-billing__discount-card__cardRejected___RSYBZ":e.status===K.nT.REJECTED}),N=e.discountType===K.Bp.PERCENTAGE?`${e.discountValue}%`:(0,F.aL)(e.discountValue,E),T=e.lineItemUuid?t.find(t=>t.uuid===e.lineItemUuid)?.item||t.find(t=>t.uuid===e.lineItemUuid)?.billableService||"--":b("wholeBill","Whole bill");return p().createElement("article",{className:C},p().createElement("header",{className:"-esm-billing__discount-card__cardTop___2KfsR"},p().createElement("div",{className:"-esm-billing__discount-card__cardScope___DFbYt"},p().createElement("span",{className:"-esm-billing__discount-card__cardScopeName___e0Gom"},T),p().createElement("span",{className:"-esm-billing__discount-card__cardScopeKind___YgWB0"},e.discountType===K.Bp.PERCENTAGE?b("percentage","Percentage"):b("fixedAmount","Fixed amount"))),e.status!==K.nT.PENDING&&p().createElement(h.vwO,{type:eS[e.status],size:"sm"},b(e.status.toLowerCase(),e.status))),p().createElement("div",{className:"-esm-billing__discount-card__cardFigure___2fn-w"},p().createElement("span",{className:k()("-esm-billing__discount-card__cardAmount___IsWoS",{"-esm-billing__discount-card__cardAmountVoided___VNogb":e.status===K.nT.REJECTED})},p().createElement("span",{className:"-esm-billing__discount-card__cardAmountMinus___eSUgX"},"−"),(0,F.aL)(e.discountAmount,E)),e.discountType===K.Bp.PERCENTAGE&&p().createElement("span",{className:"-esm-billing__discount-card__cardValue___pIy2C"},N)),p().createElement("div",null,b("reasonForDiscount","Reason for discount"),": ",p().createElement("p",{className:"-esm-billing__discount-card__cardJustification___ZbW6e"},e.justification)),p().createElement("footer",{className:"-esm-billing__discount-card__cardFooter___AlFbq"},p().createElement("div",{className:"-esm-billing__discount-card__cardByline___r8xcx"},b("requestedBy","Requested by")," ",p().createElement("strong",null,e.initiator?.display),p().createElement("span",{className:"-esm-billing__discount-card__cardBylineSep___VM4YL"},"\xb7"),(0,d.formatDate)((0,d.parseDate)(e.dateCreated),{mode:"wide"})),p().createElement("div",{className:"-esm-billing__discount-card__cardActions___bvhbQ"},v&&e.status===K.nT.PENDING&&p().createElement(p().Fragment,null,p().createElement(h.$nd,{kind:"danger--tertiary",size:"sm",disabled:!!a||!i,onClick:()=>s(e.uuid)},b("reject","Reject")),p().createElement(h.$nd,{kind:"primary",size:"sm",disabled:!!a||!i,onClick:()=>r(e)},b("approve","Approve"))),v&&p().createElement(h.$nd,{kind:"danger",size:"sm",disabled:!!a,onClick:()=>m(e.uuid)},b("delete","Delete")),y&&p().createElement(p().Fragment,null,p().createElement("span",{className:eT},b("rejectConfirm","Reject this discount?")),p().createElement(h.$nd,{kind:"ghost",size:"sm",onClick:o},(0,d.getCoreTranslation)("cancel")),p().createElement(h.$nd,{kind:"danger",size:"sm",disabled:!!a,onClick:()=>c(e)},b("confirmReject","Confirm reject"))),f&&p().createElement(p().Fragment,null,p().createElement("span",{className:eT},b("deleteConfirm","Delete this discount?")),p().createElement(h.$nd,{kind:"ghost",size:"sm",onClick:u},(0,d.getCoreTranslation)("cancel")),p().createElement(h.$nd,{kind:"danger",size:"sm",disabled:!!a,onClick:()=>_(e)},b("confirmDelete","Confirm delete"))))))},eD="-esm-billing__discount-review-stack__groupHeader___Ie7oM",eA="-esm-billing__discount-review-stack__groupTitle___e80de",eP="-esm-billing__discount-review-stack__groupCount___zrgwP",ew="-esm-billing__discount-review-stack__stack___YgUv1",eI=p().memo(({pendingDiscounts:e,confirmedDiscounts:t,lineItems:a,busy:l,rejectingId:n,deletingId:i,canDecide:r,onApprove:s,onStartReject:o,onCancelReject:c,onConfirmReject:m,onStartDelete:u,onCancelDelete:d,onConfirmDelete:_})=>{let{t:b}=(0,g.useTranslation)(),E=e=>p().createElement(ek,{key:e.uuid,discount:e,lineItems:a,busy:l,rejectingId:n,deletingId:i,canDecide:r,onApprove:s,onStartReject:o,onCancelReject:c,onConfirmReject:m,onStartDelete:u,onCancelDelete:d,onConfirmDelete:_});return p().createElement("section",{className:"-esm-billing__discount-review-stack__review___7I6RE"},e.length>0&&p().createElement("div",null,p().createElement("div",{className:eD},p().createElement("h3",{className:eA},b("pendingDiscounts","Pending discounts")),p().createElement("span",{className:eP},e.length)),p().createElement("div",{className:ew},e.map(E))),t.length>0&&p().createElement("div",null,p().createElement("div",{className:eD},p().createElement("h3",{className:eA},b("confirmedDiscounts","Confirmed discounts")),p().createElement("span",{className:eP},t.length)),p().createElement("div",{className:ew},t.map(E))))}),eL=e=>e?.responseBody?.error?.message??(e instanceof Error?e.message:String(e)),eM={container:"-esm-billing__bills-table__container___PDs67",emptyStateContainer:"-esm-billing__bills-table__emptyStateContainer___+sc4M",loaderContainer:"-esm-billing__bills-table__loaderContainer___9+3cP",billListContainer:"-esm-billing__bills-table__billListContainer___z5Mjt",filterEmptyState:"-esm-billing__bills-table__filterEmptyState___hV8Kp",filterContainer:"-esm-billing__bills-table__filterContainer___HlgpD",menu:"-esm-billing__bills-table__menu___F7TXn",headerContainer:"-esm-billing__bills-table__headerContainer___FouPn",backgroundDataFetchingIndicator:"-esm-billing__bills-table__backgroundDataFetchingIndicator___-WVf2",tableContainer:"-esm-billing__bills-table__tableContainer___-rFXM",hiddenRow:"-esm-billing__bills-table__hiddenRow___UsKb7",emptyRow:"-esm-billing__bills-table__emptyRow___kJSR-",visitSummaryContainer:"-esm-billing__bills-table__visitSummaryContainer___TzYie",expandedActiveVisitRow:"-esm-billing__bills-table__expandedActiveVisitRow___-imGs",action:"-esm-billing__bills-table__action___T5jNA",illo:"-esm-billing__bills-table__illo___zE0Ny",content:"-esm-billing__bills-table__content___XIyTL",desktopHeading:"-esm-billing__bills-table__desktopHeading___qYmFK",tabletHeading:"-esm-billing__bills-table__tabletHeading___JVDgu",tile:"-esm-billing__bills-table__tile___Zxkhk",menuitem:"-esm-billing__bills-table__menuitem___owZSX",filterEmptyStateTile:"-esm-billing__bills-table__filterEmptyStateTile___qWUMb",filterEmptyStateContent:"-esm-billing__bills-table__filterEmptyStateContent___W3mdv",filterEmptyStateHelper:"-esm-billing__bills-table__filterEmptyStateHelper___nvBYb"};function eB({layout:e,handleSearch:t,isValidating:a,responsiveSize:l,searchString:n,t:i}){return p().createElement(p().Fragment,null,p().createElement("div",{className:eM.headerContainer},p().createElement("div",{className:k()({[eM.tabletHeading]:!(0,d.isDesktop)(e),[eM.desktopHeading]:(0,d.isDesktop)(e)})},p().createElement("h4",null,i("billList","Bill list"))),a&&p().createElement("div",{className:eM.backgroundDataFetchingIndicator},p().createElement("span",null,p().createElement(h.OuH,null)))),p().createElement(h.vji,{autoFocus:!0,closeButtonLabelText:i("clearSearch","Clear"),"data-testid":"billsTableSearchBar",labelText:i("searchForPatient","Search for a patient"),placeholder:i("filterBillsByPatient","Filter bills by patient name or identifier"),value:n,onChange:t,size:l}))}let eR=()=>{let{t:e}=(0,g.useTranslation)(),t=(0,d.useLayoutType)(),{pageSize:a}=(0,d.useConfig)(),[l,n]=(0,_.useState)(a??10),i=(0,d.isDesktop)(t)?"sm":"lg",r=(0,_.useMemo)(()=>[{id:"",text:e("allBills","All bills"),status:""},{id:K.ih.PENDING,text:e("pendingConfirmationBills","Pending confirmation"),status:K.ih.PENDING},{id:K.ih.POSTED,text:e("pendingPaymentBills","Pending payment"),status:K.ih.POSTED},{id:K.ih.PAID,text:e("paidBills","Paid bills"),status:K.ih.PAID},{id:K.ih.REFUNDED,text:e("refundedBills","Refunded bills"),status:`${K.ih.REFUNDED},${K.ih.PARTIALLY_REFUNDED}`},{id:K.ih.REFUND_REQUESTED,text:e("pendingRefundBills","Pending refunds"),status:K.ih.REFUND_REQUESTED}],[e]),[s,o]=(0,_.useState)(()=>r.find(e=>e.id===K.ih.PENDING)??r[0]),[c,m]=(0,_.useState)(""),u=(0,d.useDebounce)(c,500),{bills:b,error:E,currentPage:y,isLoading:f,isValidating:v,totalCount:C,goTo:N}=(0,ee.fu)(l,s.status,u||void 0),T=[{header:e("billDate","Bill date"),key:"dateCreated"},{header:e("invoiceNumber","Invoice number"),key:"receiptNumberDisplay"},{header:e("patientIdentifier","Patient identifier"),key:"identifier"},{header:e("patientName","Patient name"),key:"patientName"},{header:e("billedItems","Billed items"),key:"billedItems"}],S=(0,_.useMemo)(()=>b?.map(e=>({...e,id:String(e.id),dateCreated:e.dateCreated?(0,d.formatDate)((0,d.parseDate)(e.dateCreated),{mode:"wide"}):"--",receiptNumberDisplay:p().createElement(d.ConfigurableLink,{style:{textDecoration:"none"},to:"${openmrsSpaBase}/home/billing/patient/${patientUuid}/${uuid}",templateParams:{patientUuid:e.patientUuid,uuid:e.uuid}},e.receiptNumber),billedItems:e?.lineItems?.map(e=>e.billableService||e.item).filter(Boolean).join(" & ")})),[b]),k=""!==c.trim()||""!==s.id,D=(0,_.useCallback)(e=>{N(1),m(e.target.value)},[N,m]),A=(0,_.useCallback)(({selectedItem:e})=>{o(e),N(1)},[N]);return p().createElement(p().Fragment,null,p().createElement("div",{className:eM.filterContainer},p().createElement(h.msM,{className:eM.filterDropdown,direction:"bottom",id:"bill-payment-status-filter",selectedItem:s,items:r,itemToString:e=>e?e.text:"",label:"",onChange:A,size:i,titleText:e("filterBy","Filter by:"),type:"inline"})),f&&!b?.length?p().createElement("div",{className:eM.loaderContainer,"data-testid":"bills-table-skeleton"},p().createElement(h.OOb,{rowCount:l,showHeader:!1,showToolbar:!1,zebra:!0,columnCount:T?.length})):E?p().createElement("div",{className:eM.errorContainer},p().createElement(h.Wdr,null,p().createElement(d.ErrorState,{error:E,headerTitle:e("billList","Bill list")}))):S?.length>0||k?p().createElement("div",{className:eM.billListContainer},p().createElement(eB,{handleSearch:D,isValidating:v,layout:t,responsiveSize:i,searchString:c,t:e}),p().createElement(h.bQt,{isSortable:!0,rows:S,headers:T,size:i,useZebraStyles:S?.length>1},({rows:t,headers:a,getRowProps:l,getTableProps:n})=>p().createElement(h.K3K,null,p().createElement(h.XIK,{...n(),"aria-label":e("billList","Bill list")},p().createElement(h.ndF,null,p().createElement(h.Hjg,null,a.map(e=>p().createElement(h.A0N,{key:e.key},e.header)))),p().createElement(h.BFY,null,t.map(e=>p().createElement(h.Hjg,{key:e.id,...l({row:e})},e.cells.map(e=>p().createElement(h.nA6,{key:e.id},e.value)))))))),S?.length===0&&p().createElement("div",{className:eM.filterEmptyState},p().createElement(h.Wdr,{level:0},p().createElement(h.FAs,{className:eM.filterEmptyStateTile},p().createElement("p",{className:eM.filterEmptyStateContent},e("noMatchingBillsToDisplay","No matching bills to display")),p().createElement("p",{className:eM.filterEmptyStateHelper},e("checkFilters","Check the filters above"))))),C>0&&p().createElement(h.dKS,{forwardText:e("nextPage","Next page"),backwardText:e("previousPage","Previous page"),page:y,pageSize:l,pageSizes:[10,20,30,40,50],totalItems:C,onChange:({pageSize:e,page:t})=>{e!==l?(n(e),N(1)):t!==y&&N(t)}})):p().createElement(h.Wdr,{className:eM.emptyStateContainer},p().createElement(h.FAs,{className:eM.tile},p().createElement("div",{className:eM.illo},p().createElement(d.EmptyCardIllustration,null)),p().createElement("p",{className:eM.content},e("noBillsToDisplay","There are no bills to display.")))))};function eq(){let{t:e}=(0,g.useTranslation)();return p().createElement(p().Fragment,null,p().createElement(M,{title:e("home","Home")}),p().createElement("section",{className:"-esm-billing__billing-dashboard__billsTableContainer___XBT2N"},p().createElement(eR,null)))}var eF=a(7240);let ex=({label:e,value:t,hasBalance:a})=>p().createElement("div",{className:"-esm-billing__invoice-breakdown__invoiceBreakdown___IGWfb"},p().createElement("span",{className:a?"-esm-billing__invoice-breakdown__extendedLabel___fJ78V":"-esm-billing__invoice-breakdown__label___WpAJx"},e,": "),p().createElement("span",{className:"-esm-billing__invoice-breakdown__value___L3Y8v"},t)),ej={errorRetryCount:2},e$=async e=>{let{uuid:t,attributes:a}=e,l=a?.find(e=>"919b51c9-8e2e-468f-8354-181bf3e55786"===e.attributeType.uuid)?.uuid;return(0,d.openmrsFetch)(`${d.restBaseUrl}/visit/${t}/attribute/${l}`,{body:{value:!1},headers:{"Content-Type":"application/json"},method:"POST"})},eU=({disablePayment:e})=>{let{t}=(0,g.useTranslation)(),{control:a,formState:{errors:l}}=(0,er.xW)(),{paymentModes:n,isLoading:i,error:r}=(()=>{let e=`${$.B}paymentMode`,{data:t,isLoading:a,error:l,mutate:n}=j()(e,d.openmrsFetch,ej);return{paymentModes:t?.data?.results??[],isLoading:a,mutate:n,error:l}})();return i?p().createElement(h.Rzj,null):r?p().createElement("div",{className:"-esm-billing__payment-form__errorPaymentContainer___Ft9DN"},p().createElement(d.ErrorState,{headerTitle:t("errorLoadingPaymentModes","Error loading payment modes"),error:r})):e?null:p().createElement("div",{className:"-esm-billing__payment-form__container___P4SMq"},p().createElement("div",{className:"-esm-billing__payment-form__paymentMethodContainer___fZiwB"},p().createElement(er.xI,{control:a,name:"payment.method",render:({field:e})=>p().createElement(h.msM,{id:"paymentMethod",selectedItem:n?.find(t=>t.uuid===e.value)??null,onChange:({selectedItem:t})=>e.onChange(t?.uuid??""),titleText:t("paymentMethod","Payment method"),label:t("selectPaymentMethod","Select payment method"),items:n,itemToString:e=>e?e.name:"",invalid:!!l?.payment?.method,invalidText:l?.payment?.method?.message})}),p().createElement(er.xI,{control:a,name:"payment.amount",render:({field:e})=>p().createElement(h.Q7x,{allowEmpty:!0,disableWheel:!0,hideSteppers:!0,id:"paymentAmount",invalid:!!l?.payment?.amount,invalidText:l?.payment?.amount?.message,label:t("amount","Amount"),onChange:(t,{value:a})=>{let l=""===a||void 0===a?void 0:Number(a);e.onChange(l)},placeholder:t("enterAmount","Enter amount"),value:e.value??""})}),p().createElement(er.xI,{name:"payment.referenceCode",control:a,render:({field:e})=>p().createElement(h.ksK,{id:"paymentReferenceCode",labelText:t("referenceNumber","Reference number"),name:e.name,onBlur:e.onBlur,onChange:e.onChange,placeholder:t("enterReferenceNumber","Enter reference number"),type:"text",value:e.value??""})})))},eH=({bill:e})=>{let{t}=(0,g.useTranslation)(),{defaultCurrency:a}=(0,d.useConfig)(),l=[{key:"dateCreated",header:t("dateOfPayment","Date of payment")},{key:"amount",header:t("billAmount","Bill amount")},{key:"amountTendered",header:t("amountTendered","Amount tendered")},{key:"paymentMethod",header:t("paymentMethod","Payment method")}],n=(e?.payments??[]).map((e,t)=>{let l=new Date(e.dateCreated);return{id:`${e.uuid}-${t}`,dateCreated:(0,d.formatDate)(l),amountTendered:(0,F.aL)(e.amountTendered,a),amount:(0,F.aL)(e.amount,a),paymentMethod:e.instanceType.name,sortKey:l.getTime()}});if(n.sort((e,t)=>t.sortKey-e.sortKey),0!==Object.values(e?.payments??{}).length)return p().createElement(h.bQt,{size:"sm",rows:n,headers:l},({rows:e,headers:t,getTableProps:a,getHeaderProps:l,getRowProps:n})=>p().createElement(h.XIK,a(),p().createElement(h.ndF,null,p().createElement(h.Hjg,null,t.map(e=>p().createElement(h.A0N,l({header:e}),e.header)))),p().createElement(h.BFY,null,e.map(e=>p().createElement(h.Hjg,n({row:e}),e.cells.map(e=>p().createElement(h.nA6,{key:e.id},e.value)))))))},eO=({bill:e,mutate:t,onFinalizeBill:a})=>{let{t:l}=(0,g.useTranslation)(),{mutate:n}=(0,x.useSWRConfig)(),i=en.z.object({method:en.z.string().refine(e=>!!e,"Payment method is required"),amount:en.z.number({required_error:l("amountRequired","Amount is required"),invalid_type_error:l("amountRequired","Amount is required")}).positive({message:l("amountMustBePositive","Amount must be greater than 0")}).max((e?.netAmount??0)-(e?.tenderedAmount??0),{message:l("paymentAmountCannotExceedAmountDue","Payment amount cannot exceed amount due")}),referenceCode:en.z.union([en.z.number(),en.z.string()]).optional()}),r=en.z.object({payment:i}),{currentVisit:s}=(0,d.useVisit)(e?.patientUuid),{defaultCurrency:o}=(0,d.useConfig)(),c={payment:{method:"",amount:void 0,referenceCode:""}},m=(0,er.mN)({mode:"all",defaultValues:c,resolver:(0,ei.u)(r)}),u=(0,er.FH)({name:"payment",control:m.control,defaultValue:c.payment});if(!e)return null;let _=(e.refunds??[]).filter(e=>e.status===K.fH.COMPLETED).reduce((e,t)=>e+t.refundAmount,0),b=(e.netAmount??0)-(e.tenderedAmount??0),E=e.status===K.ih.PENDING,y=async()=>{if(u?.method&&null!=u.amount)try{await (0,ee.TS)({instanceType:u.method,amountTendered:Number(u.amount),amount:e.totalAmount??0},e.uuid),(0,d.showSnackbar)({title:l("billPayment","Bill payment"),subtitle:l("paymentProcessedSuccessfully","Payment processed successfully"),kind:"success"}),s&&e$(s),m.reset(c),t(),n((0,ee.Z5)(e.patientUuid))}catch(e){(0,d.showSnackbar)({title:l("errorProcessingPayment","Error processing payment"),kind:"error",subtitle:e?.message})}};return p().createElement(er.Op,m,p().createElement("div",{className:"-esm-billing__payments__wrapper___V4WiR"},p().createElement("div",{className:"-esm-billing__payments__paymentContainer___1SfXU"},p().createElement(d.CardHeader,{title:l("payments","Payments")},p().createElement("span",null)),p().createElement("div",null,E?p().createElement("div",{className:"-esm-billing__payments__pendingEmptyState___jUFD7"},p().createElement(h.Wdr,null,p().createElement(h.FAs,{className:"-esm-billing__payments__pendingEmptyStateTile___q+iuz"},p().createElement("p",{className:"-esm-billing__payments__pendingEmptyStateContent___B8pVF"},l("billNotFinalized","Bill not finalized")),p().createElement("p",{className:"-esm-billing__payments__pendingEmptyStateHelper___amDGw"},l("finalizeBillToRecordPayment","Finalize this bill before recording a payment.")),p().createElement(h.$nd,{className:"-esm-billing__payments__finalizeButton___nCnCg",kind:"primary",size:"sm",onClick:a},l("finalizeBill","Finalize bill"))))):p().createElement(p().Fragment,null,p().createElement(eH,{bill:e}),p().createElement(eU,{disablePayment:b<=0})))),p().createElement("div",{className:"-esm-billing__payments__divider___C6sdr"}),p().createElement("div",{className:"-esm-billing__payments__paymentTotals___-3A2t"},p().createElement(ex,{label:l("totalAmount","Total amount"),value:(0,F.aL)(e.totalAmount??0,o)}),p().createElement(ex,{label:l("totalTendered","Total tendered"),value:(0,F.aL)(e.tenderedAmount??0,o)}),p().createElement(ex,{label:l("discount","Discount"),value:`- ${(0,F.aL)((e.totalAmount??0)-(e.netAmount??0),o)}`}),p().createElement(ex,{label:l("refunds","Refunds"),value:`- ${(0,F.aL)(_,o)}`}),p().createElement(ex,{hasBalance:b<0,label:l("amountDue","Amount due"),value:(0,F.aL)(b,o)}),p().createElement("div",{className:"-esm-billing__payments__processPayments___RG8aV"},p().createElement(h.$nd,{onClick:()=>(0,d.navigate)({to:window.getOpenmrsSpaBase()+"home/billing"}),kind:"secondary"},l("discard","Discard")),!E&&p().createElement(h.$nd,{onClick:y,disabled:!u?.method||null==u.amount||!m.formState.isValid},l("processPayment","Process Payment"))))))},ez=({billUuid:e})=>{let{t}=(0,g.useTranslation)(),[a,l]=(0,_.useState)(!1),n=new URL(window.location.href);return p().createElement(h.$nd,{kind:"secondary",className:"-esm-billing__print-receipt__button___QnAQS",renderIcon:e=>p().createElement(T.xj,{size:24,...e}),onClick:()=>{l(!0),setTimeout(()=>{let t=`${n.origin}/openmrs${$.B}receipt?billUuid=${e}`,a=document.createElement("a");a.href=t,a.download=`receipt_${e}.pdf`,document.body.appendChild(a),a.click(),document.body.removeChild(a),l(!1)},1e3)},disabled:a},a?(0,d.getCoreTranslation)("loading"):t("printReceipt","Print receipt"))},eV=()=>{let{data:e}=(0,ee.eC)();return e?p().createElement("div",{className:"-esm-billing__printable-footer__container___mTh7B"},p().createElement("p",{className:"-esm-billing__printable-footer__itemFooter___Y5pkL"},e?.display)):p().createElement("div",null,"--")};var eK=a(2193),eW=a.n(eK);let eG="-esm-billing__printable-invoice-header__img___rSlvX",eQ="-esm-billing__printable-invoice-header__sectionHeading___tOV2s",eJ="-esm-billing__printable-invoice-header__itemLabel___+hACh",eX=({patientDetails:e,defaultFacility:t,bill:a})=>{let{t:l}=(0,g.useTranslation)(),{logo:n,country:i,defaultCurrency:r}=(0,d.useConfig)(),s={[l("invoiceNo","Invoice #")]:a?.receiptNumber,[l("invoiceDate","Invoice date")]:a?.dateCreated?(0,d.formatDate)((0,d.parseDate)(a.dateCreated),{mode:"wide",noToday:!0,time:!1}):"--",[l("totalAmount","Total amount")]:`${r} ${a?.totalAmount}`,[l("totalPaid","Total paid")]:`${r} ${a?.tenderedAmount}`,[l("amountBalance","Amount balance")]:`${r} ${a?.netAmount-a?.tenderedAmount}`,...a?.status&&{[l("invoiceStatus","Invoice status")]:a.status}},o={[l("name","Name")]:e?.name,...e.gender&&{[l("gender","Gender")]:e.gender},...e.birthDate&&{[l("birthDate","Date of birth")]:(0,d.formatDate)((0,d.parseDate)(e.birthDate),{time:!1})},...e.address&&{[l("address","Address")]:e.address}};return p().createElement("div",{className:"-esm-billing__printable-invoice-header__container___1u0nI"},p().createElement("div",{className:"-esm-billing__printable-invoice-header__printableHeader___Jl02J"},p().createElement("div",{className:"-esm-billing__printable-invoice-header__logo___ZpVka"},n?.src&&!eW()(n.src)?p().createElement("img",{className:eG,src:(0,d.interpolateUrl)(n.src),alt:n.alt}):n?.alt&&!eW()(n.alt)?n.alt:p().createElement("svg",{className:eG,role:"img",width:110,height:40,viewBox:"0 0 380 119",xmlns:"http://www.w3.org/2000/svg"},p().createElement("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M40.29 40.328a27.755 27.755 0 0 1 19.688-8.154c7.669 0 14.613 3.102 19.647 8.116l.02-18.54A42.835 42.835 0 0 0 59.978 17c-7.089 0-13.813 1.93-19.709 4.968l.021 18.36ZM79.645 79.671a27.744 27.744 0 0 1-19.684 8.154c-7.67 0-14.614-3.101-19.651-8.116l-.02 18.54A42.857 42.857 0 0 0 59.96 103a42.833 42.833 0 0 0 19.672-4.751l.013-18.578ZM40.328 79.696c-5.038-5.037-8.154-11.995-8.154-19.685 0-7.669 3.102-14.612 8.116-19.65l-18.54-.02A42.85 42.85 0 0 0 17 60.012a42.819 42.819 0 0 0 4.752 19.672l18.576.013ZM79.634 40.289a27.753 27.753 0 0 1 8.154 19.688 27.744 27.744 0 0 1-8.117 19.646l18.542.02a42.842 42.842 0 0 0 4.749-19.666c0-7.09-1.714-13.779-4.751-19.675l-18.577-.013ZM156.184 60.002c0-8.748-6.118-15.776-15.025-15.776-8.909 0-15.025 7.028-15.025 15.776 0 8.749 6.116 15.78 15.025 15.78 8.907 0 15.025-7.031 15.025-15.78Zm-34.881 0c0-11.482 8.318-19.958 19.856-19.958 11.536 0 19.855 8.477 19.855 19.959 0 11.484-8.319 19.964-19.855 19.964-11.538 0-19.856-8.48-19.856-19.965ZM179.514 75.54c5.507 0 9.05-4.14 9.05-9.482 0-5.341-3.543-9.483-9.05-9.483-5.505 0-9.046 4.142-9.046 9.483 0 5.342 3.541 9.482 9.046 9.482ZM166.22 53.306h4.248v3.704h.11c2.344-2.725 5.449-4.36 9.154-4.36 8.014 0 13.408 5.67 13.408 13.408 0 7.63-5.613 13.406-12.752 13.406-4.58 0-8.231-2.29-9.81-5.178h-.11V90.87h-4.248V53.306ZM217.773 63.768c-.163-4.305-3-7.193-7.686-7.193-4.685 0-7.79 2.888-8.335 7.193h16.021Zm3.653 10.412c-3.001 3.868-6.596 5.284-11.339 5.284-8.01 0-12.914-5.993-12.914-13.406 0-7.901 5.559-13.407 13.08-13.407 7.196 0 12.096 4.906 12.096 13.354v1.362h-20.597c.325 4.413 3.704 8.173 8.335 8.173 3.65 0 6.105-1.307 8.12-3.868l3.219 2.508ZM227.854 59.356c0-2.346-.216-4.36-.216-6.05h4.031c0 1.363.11 2.777.11 4.195h.11c1.144-2.505 4.306-4.85 8.5-4.85 6.705 0 9.699 4.252 9.699 10.41v15.748h-4.248v-15.31c0-4.253-1.856-6.924-5.833-6.924-5.503 0-7.903 3.979-7.903 9.811V78.81h-4.25V59.356ZM259.211 41.008h6.708L278.8 70.791h.107l12.982-29.782h6.549v37.99h-4.506V47.124h-.106L280.192 79h-2.738l-13.629-31.875h-.107V79h-4.507V41.01ZM312.392 57.752h4.023c4.992 0 11.487 0 11.487-6.282 0-5.47-4.776-6.276-9.177-6.276h-6.333v12.558Zm-4.506-16.744h9.711c7.352 0 15.132 1.072 15.132 10.462 0 5.527-3.594 9.125-9.495 10.037L334.018 79h-5.525l-10.304-17.063h-5.797V79h-4.506V41.01ZM358.123 47.712c-1.506-2.413-4.187-3.486-6.926-3.486-3.973 0-8.1 1.88-8.1 6.385 0 3.49 1.931 5.047 7.994 6.98 5.903 1.878 11.377 3.809 11.377 11.267 0 7.567-6.495 11.11-13.36 11.11-4.402 0-9.125-1.45-11.7-5.262l3.862-3.165c1.61 2.794 4.83 4.24 8.105 4.24 3.862 0 8.263-2.253 8.263-6.601 0-4.669-3.165-5.474-9.928-7.728-5.366-1.771-9.442-4.134-9.442-10.463 0-7.298 6.277-10.945 12.929-10.945 4.241 0 7.836 1.178 10.625 4.45l-3.699 3.218Z"}))),p().createElement("div",{className:"-esm-billing__printable-invoice-header__facilityDetails___uJPtI"},p().createElement("p",{className:"-esm-billing__printable-invoice-header__facilityName___81nN9"},t?.display),p().createElement("p",{className:eJ},i))),p().createElement("h1",{className:"-esm-billing__printable-invoice-header__invoiceHeading___9Xftg"},l("invoice","Invoice")),p().createElement("div",{className:"-esm-billing__printable-invoice-header__printableBody___cMhfI"},p().createElement("div",{className:"-esm-billing__printable-invoice-header__detailsContainer___rJn9A"},p().createElement("div",null,p().createElement("h2",{className:eQ},l("patientInformation","Patient information")),Object.entries(o).map(([e,t])=>p().createElement("p",{className:eJ,key:e},p().createElement("strong",null,e),p().createElement("span",null,": ",t)))),p().createElement("div",null,p().createElement("h2",{className:eQ},l("invoiceSummary","Invoice summary")),Object.entries(s).map(([e,t])=>p().createElement("p",{className:eJ,key:e},p().createElement("strong",null,e),p().createElement("span",null,": ",t)))))))},eZ={itemsContainer:"-esm-billing__printable-invoice__itemsContainer___EA1KS",tableContainer:"-esm-billing__printable-invoice__tableContainer___CeBjk",totalContainer:"-esm-billing__printable-invoice__totalContainer___+8XbC",item:"-esm-billing__printable-invoice__item___U-0e6",itemHeading:"-esm-billing__printable-invoice__itemHeading___mHy3a",itemTotal:"-esm-billing__printable-invoice__itemTotal___pOXNY",itemLabel:"-esm-billing__printable-invoice__itemLabel___i+Nva",summaryContainer:"-esm-billing__printable-invoice__summaryContainer___A5A-s",paymentHistoryContainer:"-esm-billing__printable-invoice__paymentHistoryContainer___Z+0Pi",balanceContainer:"-esm-billing__printable-invoice__balanceContainer___oekII"},eY=({bill:e,patient:t,componentRef:a,defaultFacility:l})=>{let{t:n}=(0,g.useTranslation)(),i=(0,d.useLayoutType)(),{defaultCurrency:r}=(0,d.useConfig)(),s=(0,d.isDesktop)(i)?"sm":"lg",o=[{header:n("inventoryItem","Inventory item"),key:"billItem"},{header:n("quantity","Quantity"),key:"quantity"},{header:n("unitPrice","Unit price"),key:"price"},{header:n("total","Total"),key:"total"}],c=e?.lineItems?.map(e=>({id:`${e.uuid}`,billItem:e.billableService?e.billableService:e.item,quantity:e.quantity,price:`${r} ${e.price}`,total:`${r} ${e.price*e.quantity}`}))??[],m=[{key:"no",header:n("no","No")},{key:"paymentMethod",header:n("paymentMethod","Payment method")},{key:"amountPaid",header:n("amountPaid","Amount paid")},{key:"dateCreated",header:n("dateOfPayment","Date of payment")}],u=(0,_.useMemo)(()=>e?e.payments?.map((e,t)=>({no:t+1,id:`${e.uuid}-${t}`,paymentMethod:e.instanceType.name,amountPaid:`${r} ${e.amountTendered.toFixed(2)}`,dateCreated:(0,d.formatDate)(new Date(e.dateCreated))})):[],[e,r]),b=(0,_.useMemo)(()=>{let e=t?.address?.[0],a=[e?.line?.join(" "),e?.city,e?.district,e?.state].filter(Boolean).join(", ");return{name:`${t?.name?.[0]?.given?.join(" ")} ${t?.name?.[0].family}`,birthDate:t?.birthDate,gender:(0,F.o_)(t?.gender,n),address:a}},[t,n]);return p().createElement("div",{className:eZ.container,ref:a},p().createElement(eX,{patientDetails:b,defaultFacility:l,bill:e}),p().createElement("div",{className:eZ.itemsContainer},p().createElement("div",{className:eZ.tableContainer},p().createElement(h.bQt,{rows:c,headers:o,size:s,useZebraStyles:!1},({rows:e,headers:t,getRowProps:a,getTableProps:l})=>p().createElement(h.K3K,null,p().createElement(h.XIK,{...l(),"aria-label":n("invoiceLineItems","Invoice line items")},p().createElement(h.ndF,null,p().createElement(h.Hjg,null,t.map(e=>p().createElement(h.A0N,{key:e.key},e.header)))),p().createElement(h.BFY,null,e.map(e=>p().createElement(h.Hjg,{key:e.id,...a({row:e})},e.cells.map(e=>p().createElement(h.nA6,{key:e.id},e.value)))))))),e?.netAmount!=null&&e.totalAmount!==e.netAmount?p().createElement(p().Fragment,null,p().createElement("div",{className:eZ.balanceContainer},p().createElement("span",{className:eZ.itemHeading},n("subtotal","Subtotal"),":")," ",p().createElement("span",{className:eZ.itemLabel},p().createElement("strong",null,r," ",e?.totalAmount))),p().createElement("div",{className:eZ.balanceContainer},p().createElement("span",{className:eZ.itemHeading},n("discount","Discount"),":")," ",p().createElement("span",{className:eZ.itemLabel},p().createElement("strong",null,"- ",r," ",(e?.totalAmount??0)-(e?.netAmount??0)))),p().createElement("div",{className:eZ.balanceContainer},p().createElement("span",{className:eZ.itemHeading},n("totalAmount","Total amount"),":")," ",p().createElement("span",{className:eZ.itemLabel},p().createElement("strong",null,r," ",e?.netAmount)))):p().createElement("div",{className:eZ.balanceContainer},p().createElement("span",{className:eZ.itemHeading},n("totalAmount","Total amount"),":")," ",p().createElement("span",{className:eZ.itemLabel},p().createElement("strong",null,r," ",e?.totalAmount))),e?.payments?.length>0&&p().createElement("div",{className:eZ.paymentHistoryContainer},p().createElement(h.bQt,{rows:u,headers:m,size:s},({rows:e,headers:t,getRowProps:a,getTableProps:l})=>p().createElement(h.K3K,null,p().createElement(h.XIK,{...l(),"aria-label":n("paymentHistory","Payment History")},p().createElement(h.ndF,null,p().createElement(h.Hjg,null,t.map(e=>p().createElement(h.A0N,{key:e.key},e.header)))),p().createElement(h.BFY,null,e.map(e=>p().createElement(h.Hjg,{key:e.id,...a({row:e})},e.cells.map(e=>p().createElement(h.nA6,{key:e.id},e.value))))))))),p().createElement("div",{className:eZ.balanceContainer},p().createElement("span",{className:eZ.itemHeading},n("totalTendered","Total tendered"),":"),p().createElement("span",{className:eZ.itemLabel},p().createElement("strong",null,r," ",e?.tenderedAmount))),p().createElement("div",{className:eZ.balanceContainer},p().createElement("span",{className:eZ.itemHeading},n("balance","Balance"),":"),p().createElement("span",{className:eZ.itemLabel},p().createElement("strong",null,r," ",e?.netAmount-e?.tenderedAmount))))),p().createElement(eV,null))},e0=({bill:e})=>{let{t}=(0,g.useTranslation)(),{defaultCurrency:a}=(0,d.useConfig)(),l=(0,d.useLayoutType)(),n=(0,d.isDesktop)(l)?"sm":"lg",i=(0,_.useMemo)(()=>(e.discounts??[]).filter(e=>!e.voided),[e.discounts]),r=[{header:t("discountItem","Item"),key:"item",width:25},{header:t("discountType","Type"),key:"type",width:15},{header:t("discountAmount","Amount"),key:"amount",width:15},{header:t("justification","Justification"),key:"justification",width:30},{header:t("status","Status"),key:"status",width:15}],s=(0,_.useMemo)(()=>(i??[]).map(l=>({id:l.uuid,item:function(e,t,a){if(!e.lineItemUuid)return a;let l=t.lineItems?.find(t=>t.uuid===e.lineItemUuid);return l?.item||l?.billableService||a}(l,e,t("wholeBill","Whole bill")),type:l.discountType===K.Bp.PERCENTAGE?t("percentage","Percentage"):t("fixedAmount","Fixed amount"),amount:(0,F.aL)(l.discountAmount,a),justification:l.justification,status:t(l.status.toLowerCase(),l.status)})),[i,e,a,t]);return i&&0!==i.length?p().createElement("div",{className:"-esm-billing__discounts-table__discountsWrapper___nAknV"},p().createElement(h.bQt,{headers:r,rows:s,size:n,useZebraStyles:!0,overflowMenuOnHover:(0,d.isDesktop)(l)},({rows:e,headers:a,getRowProps:l,getTableProps:n})=>p().createElement(h.K3K,{description:p().createElement("span",{className:"-esm-billing__discounts-table__tableDescription___dsPxA"},p().createElement("span",null,t("discountsAppliedToBill","Discounts applied to this bill"))),title:t("discounts","Discounts")},p().createElement(h.XIK,{...n(),"aria-label":t("billDiscounts","Bill discounts"),className:k()("-esm-billing__discounts-table__discountsTable___Wd5vG","billingTable")},p().createElement(h.ndF,null,p().createElement(h.Hjg,null,a.map(e=>p().createElement(h.A0N,{key:e.key},e.header)))),p().createElement(h.BFY,null,e.map(e=>p().createElement(h.Hjg,{key:e.id,...l({row:e})},e.cells.map(e=>p().createElement(h.nA6,{key:e.id},e.value))))))))):null},e1=({bill:e,onMutate:t})=>{let{t:a}=(0,g.useTranslation)(),{defaultCurrency:l}=(0,d.useConfig)(),n=(0,d.useSession)(),i=(0,d.useLayoutType)(),r=(0,d.isDesktop)(i)?"sm":"lg",[s,o]=(0,_.useState)(null),c=[{header:a("refundItem","Item"),key:"item"},{header:a("refundAmount","Refund amount"),key:"amount"},{header:a("reason","Reason"),key:"reason"},{header:a("status","Status"),key:"status"},{header:a("action","Action"),key:"action"}],m=(0,_.useMemo)(()=>(e.refunds??[]).filter(e=>!e.voided),[e.refunds]),u=(0,_.useCallback)(async e=>{o(e.uuid);try{await (0,J.eK)(e.uuid,{status:K.fH.COMPLETED,completer:n.user?.uuid}),(0,d.showSnackbar)({title:a("refundProcessed","Refund processed"),kind:"success"}),t?.()}catch(t){let e=t?.responseBody?.error?.message??(t instanceof Error?t.message:void 0);(0,d.showSnackbar)({title:a("refundProcessFailed","Could not process refund"),subtitle:e,kind:"error"})}finally{o(null)}},[t,n.user?.uuid,a]),b=(0,_.useMemo)(()=>(m??[]).map(t=>({id:t.uuid,item:function(e,t,a){if(!e.lineItemUuid)return a;let l=t.lineItems?.find(t=>t.uuid===e.lineItemUuid);return l?.item||l?.billableService||a}(t,e,a("wholeBill","Whole bill")),amount:(0,F.aL)(t.refundAmount,l),reason:t.reason,status:a(t.status.toLowerCase(),t.status),action:p().createElement(h.$nd,{kind:"primary",size:"sm",disabled:s===t.uuid||t.status!==K.fH.APPROVED,onClick:()=>u(t)},s===t.uuid?p().createElement(h.OuH,{description:a("processing","Processing")+"..."}):a("processRefund","Process refund"))})),[m,e,l,s,a,u]);return m&&0!==m.length?p().createElement("div",{className:"-esm-billing__refunds-table__refundsWrapper___ZvDhw"},p().createElement(h.bQt,{headers:c,rows:b,size:r,useZebraStyles:!0},({rows:e,headers:t,getRowProps:l,getTableProps:n})=>p().createElement(h.K3K,{description:p().createElement("span",{className:"-esm-billing__refunds-table__tableDescription___hGPCT"},p().createElement("span",null,a("refundsOnBill","Refunds on this bill"))),title:a("refunds","Refunds")},p().createElement(h.XIK,{...n(),"aria-label":a("billRefunds","Bill refunds"),className:k()("-esm-billing__refunds-table__refundsTable___B5xVc","billingTable")},p().createElement(h.ndF,null,p().createElement(h.Hjg,null,t.map(e=>p().createElement(h.A0N,{key:e.key},e.header)))),p().createElement(h.BFY,null,e.map(e=>p().createElement(h.Hjg,{key:e.id,...l({row:e})},e.cells.map(e=>p().createElement(h.nA6,{key:e.id},e.value))))))))):null},e3="-esm-billing__invoice__invoiceContainer___6Vmk0",e6=`
2
2
  @page {
3
3
  /* Remove the browser's default header (title) and footer (url) */
4
4
  margin: 0;
@@ -15,4 +15,4 @@
15
15
  -webkit-print-color-adjust: exact;
16
16
  }
17
17
  }
18
- `;function e6({label:e,value:t}){let{t:a}=(0,g.useTranslation)();return p().createElement("div",null,p().createElement("h1",{className:"-esm-billing__invoice__label___Ecjiu"},a(e)),p().createElement("span",{className:"-esm-billing__invoice__value___1rJZi"},t))}let e5=()=>{let{t:e}=(0,g.useTranslation)(),{data:t}=(0,Y.eC)(),{billUuid:a,patientUuid:l}=(0,b.g)(),{patient:n,isLoading:i}=(0,d.usePatient)(l),{bill:r,isLoading:s,error:o,isValidating:c,mutate:m}=(0,Y.DX)(a),[u,E]=(0,_.useState)(!1),y=(0,_.useRef)(null),v=(0,_.useRef)(null),{defaultCurrency:f}=(0,d.useConfig)(),C=(r?.discounts??[]).filter(e=>!e.voided),N=C.some(e=>!e.lineItemUuid),S=C.some(e=>!!e.lineItemUuid),k=r?.status===V.ih.PENDING||r?.status===V.ih.POSTED,A=!!r&&k&&!N,P=C.some(e=>e.status===V.nT.APPROVED),w=(r?.refunds??[]).filter(e=>!e.voided),I=r?.status===V.ih.PAID||r?.status===V.ih.PARTIALLY_REFUNDED,L=w.filter(e=>e.status===V.fH.REQUESTED||e.status===V.fH.APPROVED),M=L.some(e=>!e.lineItemUuid),B=new Set(L.flatMap(e=>e.lineItemUuid?[e.lineItemUuid]:[])),R=!!r&&I&&!M,q=()=>{if(!r)return;if(null==r.netAmount)return void(0,d.showSnackbar)({title:e("refundUnavailable","Refund unavailable"),subtitle:e("refundUnavailableSubtitle","Bill amount could not be determined. Please reload and try again."),kind:"error"});let t=w.filter(e=>e.status===V.fH.APPROVED||e.status===V.fH.COMPLETED).reduce((e,t)=>e+t.refundAmount,0),a=r.netAmount-t,l=(0,d.showModal)("request-refund-modal",{bill:{uuid:r.uuid,total:r.totalAmount??0,amountAfterDiscount:r.netAmount,receiptNumber:r.receiptNumber,lineItemCount:r.lineItems?.length??0},remainingRefundable:Math.max(0,a),onMutate:()=>m(),closeModal:()=>l()})},x=(0,_.useCallback)(()=>{v.current=null,E(!1)},[]),j=(0,_.useCallback)(()=>new Promise(e=>{n&&r&&(E(!0),v.current=e)}),[r,n]),$=()=>{let e=(0,d.showModal)("finalize-bill-confirmation-modal",{bill:r,onMutate:m,closeModal:()=>e()})},U=(0,eq.useReactToPrint)({contentRef:y,documentTitle:`Invoice ${r?.receiptNumber} - ${n?.name?.[0]?.given?.join(" ")} ${n?.name?.[0].family}`,pageStyle:e3,onBeforePrint:j,onAfterPrint:x,preserveAfterPrint:!1,onPrintError:(t,a)=>(0,d.showSnackbar)({title:e("errorPrintingInvoice","Error printing invoice"),kind:"error",subtitle:a.message})});(0,_.useEffect)(()=>{u&&v.current&&v.current()},[u]);let H={[e("dateBillCreated","Date bill created")]:r?.dateCreated?(0,d.formatDate)((0,d.parseDate)(r.dateCreated),{mode:"wide"}):"--",[e("totalAmount","Total amount")]:(0,F.aL)(r?.totalAmount,f),...P?{[e("discount","Discount")]:`- ${(0,F.aL)((r?.totalAmount??0)-(r?.netAmount??0),f)}`,[e("netAmount","Net amount")]:(0,F.aL)(r?.netAmount,f)}:{},[e("amountTendered","Amount tendered")]:(0,F.aL)(r?.tenderedAmount,f),[e("amountDue","Amount due")]:(0,F.aL)(r?(r.netAmount??0)-(r.tenderedAmount??0):void 0,f),[e("invoiceNumber","Invoice number")]:r?.receiptNumber,[e("invoiceStatus","Invoice status")]:r?.status};return i||s?p().createElement("div",{className:e1},p().createElement(h.OuH,{className:"-esm-billing__invoice__loader___YjE+7",description:`${e("loadingBillInfo","Loading bill information")}...`})):o?p().createElement("div",{className:"-esm-billing__invoice__errorContainer___b+MxG"},p().createElement(d.ErrorState,{headerTitle:e("invoiceError","Invoice error"),error:o})):p().createElement("div",{className:e1},n&&l&&p().createElement(d.ExtensionSlot,{name:"patient-header-slot",state:{patient:n,patientUuid:l}}),p().createElement("div",{className:"-esm-billing__invoice__actionsContainer___CSsXH"},c&&p().createElement("span",null,p().createElement(h.OuH,{status:"active"})),A&&p().createElement(h.$nd,{kind:"tertiary",onClick:()=>{let e=(0,d.showModal)("request-discount-modal",{bill:{uuid:r.uuid,total:r.totalAmount??0,amountDue:Math.max(0,(r.netAmount??r.totalAmount??0)-(r.tenderedAmount??0)),receiptNumber:r.receiptNumber,lineItemCount:r.lineItems?.length??0},onMutate:()=>m(),closeModal:()=>e()})},disabled:S},e("requestDiscount","Request discount")),R&&(B.size>0?p().createElement(h.m_M,{align:"bottom",label:e("refundInProgress","A refund is already in progress for one or more line items")},p().createElement(h.$nd,{kind:"tertiary",onClick:q,disabled:!0},e("requestRefund","Request refund"))):p().createElement(h.$nd,{kind:"tertiary",onClick:q},e("requestRefund","Request refund"))),r?.status===V.ih.PENDING&&p().createElement(p().Fragment,null,p().createElement(h.$nd,{kind:"ghost",renderIcon:D.OM,onClick:()=>(0,d.launchWorkspace2)("billing-form-workspace",{patientUuid:l,billUuid:r.uuid,onMutate:m})},e("addItemsToBill","Add items to bill")),p().createElement(h.$nd,{kind:"danger--ghost",onClick:()=>{let e=(0,d.showModal)("delete-bill-confirmation-modal",{bill:r,onSuccess:()=>(0,d.navigate)({to:window.getOpenmrsSpaBase()+"home/billing"}),closeModal:()=>e()})}},e("deleteBill","Delete bill")),p().createElement(h.$nd,{kind:"primary",onClick:$},e("finalizeBill","Finalize bill"))),p().createElement(h.$nd,{disabled:u||i||s,onClick:U,renderIcon:e=>p().createElement(T.xj,{size:24,...e}),iconDescription:e("printBill","Print bill")},e("printBill","Print bill")),r&&(r.status===V.ih.PAID||r.tenderedAmount>0)&&p().createElement(eO,{billUuid:r.uuid})),p().createElement("div",{className:"-esm-billing__invoice__detailsContainer___93jPh"},p().createElement("section",{className:"-esm-billing__invoice__details___zIHv7"},Object.entries(H).map(([e,t])=>p().createElement(e6,{key:e,label:e,value:t})))),p().createElement("div",{className:"-esm-billing__invoice__invoiceContent___Yd6Pt"},p().createElement(ea.A,{bill:r,isLoadingBill:s,onMutate:m}),r&&p().createElement(eY,{bill:r}),r&&p().createElement(e0,{bill:r,onMutate:m}),p().createElement(eH,{bill:r,mutate:m,onFinalizeBill:$})),r&&n&&p().createElement("div",{className:"-esm-billing__invoice__printContainer___9D3HY"},p().createElement(eZ,{bill:r,patient:n,defaultFacility:t,componentRef:y})))},e2=({patientUuid:e})=>{let{t}=(0,g.useTranslation)(),{paymentStatus:a,isLoading:l,error:n}=(0,Y.N7)(e);return l||n||!a||"UNKNOWN"===a.status?null:p().createElement(h.Gff,{className:"-esm-billing__payment-status-tag__tag___Sfz+y"},p().createElement(h.yvu,{label:t(a.status,a.status)},p().createElement(h.vwO,{type:"PAID"===a.status?"green":"red"},t(a.status,a.status))),p().createElement(h.pNg,null,p().createElement("div",{role:"tooltip"},p().createElement("p",null,a.reason))))},e4={logo:{src:{_type:d.Type.String,_default:"",_description:"The path or URL to the logo image. If set to an empty string, the alt text will be used.",_validators:[d.validators.isUrl]},alt:{_type:d.Type.String,_default:"",_description:"The alternative text for the logo image, displayed when the image cannot be loaded or on hover. If not provided and src is empty, the default OpenMRS SVG sprite will be used."}},country:{_type:d.Type.String,_description:"The text that gets printed on the top right of the invoice, typically the name of the country",_default:"Kenya"},patientCategory:{_type:d.Type.Object,_description:"Visit Attribute Type UUIDs - These are custom attribute types that can be attached to patient visits. Each UUID represents a Visit Attribute Type in OpenMRS that stores payment-related information for the visit.",_default:{paymentDetails:"fbc0702d-b4c9-4968-be63-af8ad3ad6239",paymentMethods:"8553afa0-bdb9-4d3c-8a98-05fa9350aa85",policyNumber:"aac48226-d143-4274-80e0-264db4e368ee",insuranceScheme:"3a988e33-a6c0-4b76-b924-01abb998944b",patientCategory:"3b9dfac8-9e4d-11ee-8c90-0242ac120002",formPayloadPending:"919b51c9-8e2e-468f-8354-181bf3e55786"}},categoryConcepts:{_type:d.Type.Object,_description:"Concept UUIDs - These are OpenMRS Concept UUIDs that represent the actual values/options for payment categories. These concepts are stored as values in the visit attributes defined in patientCategory.",_default:{payingDetails:"44b34972-6630-4e5a-a9f6-a6eb0f109650",nonPayingDetails:"f3fb2d88-cccd-422c-8766-be101ba7bd2e",insuranceDetails:"beac329b-f1dc-4a33-9e7c-d95821a137a6"}},nonPayingPatientCategories:{_type:d.Type.Object,_description:"Concept UUIDs for non-paying patient categories - These are OpenMRS Concept UUIDs that identify specific patient categories eligible for non-paying status (e.g., children under 5, students). These are used as values when a patient is categorized as non-paying.",_default:{childUnder5:"1528AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",student:"159465AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"}},postBilledItems:{_type:d.Type.Object,_description:"Default UUIDs used when creating bills - These UUIDs identify default resources (cash points, cashier providers) that are used when submitting a bill if not explicitly provided.",_default:{cashPoint:"54065383-b4d4-42d2-af4d-d250a1fd2590",cashier:"f9badd80-ab76-11e2-9e96-0800200c9a66",priceUuid:"7b9171ac-d3c1-49b4-beff-c9902aee5245"}},serviceTypes:{_type:d.Type.Object,_description:"Service Type Concept Set UUID - This is an OpenMRS Concept Set UUID. The set members of this concept represent the different types of services that can be billed (e.g., Consultation, Lab Test, Procedure).",_default:{billableService:"21b8cf43-9f9f-4d02-9f4a-d710ece54261"}},defaultCurrency:{_type:d.Type.String,_description:"The default currency for the application. Specify the currency code (e.g., KES, UGX, GBP).",_default:"KES"},pageSize:{_type:d.Type.Number,_description:"The default page size",_default:10}},e8="@openmrs/esm-billing-app",e7={featureName:"billing",moduleName:e8},e9=a(4767),te=(0,d.getSyncLifecycle)((l={name:"billing",title:"billing"},()=>p().createElement(E.Kd,null,p().createElement(y,{config:l}))),e7);function tt(){(0,d.defineConfigSchema)(e8,e4)}let ta=(0,d.getSyncLifecycle)((0,d.createDashboard)({slot:"patient-chart-billing-dashboard-slot",columns:1,title:"billingHistory",hideDashboardTitle:!0,icon:"omrs-icon-money",path:"billing-history"}),e7),tl=(0,d.getSyncLifecycle)(()=>{let{t:e}=(0,g.useTranslation)(),t=window.getOpenmrsSpaBase();return p().createElement(h.t3h,{className:"-esm-billing__item__customTile___Z3Rn6",id:"menu-item",href:`${t}billable-services`},p().createElement("div",{className:"customTileTitle"},p().createElement(T.TA,{size:24})),p().createElement("div",null,e("billableServices","Billable services")))},e7),tn=(0,d.getSyncLifecycle)(()=>{let{t:e}=(0,g.useTranslation)(),t=e("manageBilling","Manage billing");return p().createElement(h.Wdr,null,p().createElement(h.t3h,{href:`${window.spaBase}/billable-services`},p().createElement("div",null,p().createElement("div",{className:"heading"},t),p().createElement("div",{className:"content"},e("billingAdministration","Billing administration"))),p().createElement("div",{className:"iconWrapper"},p().createElement(D.Qp,{size:16}))))},e7),ti=(0,d.getSyncLifecycle)(()=>{let{t:e}=(0,g.useTranslation)(),t=(0,d.useLayoutType)(),a=`${window.spaBase}/billable-services`;return(0,d.useLeftNav)({name:"billable-services-left-panel-slot",basePath:a}),p().createElement(E.Kd,{basename:a},p().createElement("div",{className:"-esm-billing__billable-services__pageWrapper___jBBH1"},p().createElement("main",{className:k()("-esm-billing__billable-services__pageContent___bnbzA",{"-esm-billing__billable-services__hasLeftNav___3svGW":(0,d.isDesktop)(t)})},p().createElement(M,{title:e("billingAdministration","Billing administration")}),p().createElement(b.BV,null,p().createElement(b.qh,{path:"/",element:p().createElement(I,null)}),p().createElement(b.qh,{path:"/cash-point-config",element:p().createElement(B,null)}),p().createElement(b.qh,{path:"/payment-modes-config",element:p().createElement(q,null)}),p().createElement(b.qh,{path:"/discount-requests",element:p().createElement(G,null)}),p().createElement(b.qh,{path:"/refund-requests",element:p().createElement(Z,null)})))),p().createElement(d.WorkspaceContainer,{contextKey:"billable-services"}))},e7),tr=(0,d.getSyncLifecycle)(em,e7),ts=(0,d.getSyncLifecycle)(({patientUuid:e})=>{let{t}=(0,g.useTranslation)(),{bills:a,error:l,isLoading:n,isValidating:i,mutate:r}=(0,Y.u1)(e),{paginated:s,goTo:o,results:c,currentPage:m}=(0,d.usePagination)(a),{pageSize:u,defaultCurrency:b}=(0,d.useConfig)(),[E,y]=(0,_.useState)(u),{pageSizes:v}=(0,d.usePaginationInfo)(u,a?.length,m,c?.length),f=(0,_.useMemo)(()=>new Map(a?.map(e=>[e.uuid,e])),[a]),C=[{header:t("billDate","Bill date"),key:"billDate"},{header:t("invoiceNumber","Invoice number"),key:"invoiceNumber"},{header:t("billedItems","Billed items"),key:"billedItems"},{header:t("billTotal","Bill total"),key:"billTotal"}],N=c?.map(e=>({id:e.uuid,uuid:e.uuid,billTotal:(0,F.aL)(e?.totalAmount,b),billDate:(0,d.formatDate)((0,d.parseDate)(e.dateCreated),{mode:"wide"}),invoiceNumber:e.receiptNumber,billedItems:e?.lineItems?.map(e=>e?.billableService||e?.item).filter(Boolean).join(" & ")}));return n?p().createElement("div",{className:"-esm-billing__bill-history__loaderContainer___KePhb"},p().createElement(h.OOb,{showHeader:!1,showToolbar:!1,zebra:!0})):l?p().createElement("div",{className:"-esm-billing__bill-history__errorContainer___j-G7W"},p().createElement(h.Wdr,null,p().createElement(d.ErrorState,{error:l,headerTitle:t("billList","Bill list")}))):0===a.length?p().createElement(h.Wdr,{className:"-esm-billing__bill-history__emptyStateContainer___udoC8"},p().createElement(h.FAs,{className:"-esm-billing__bill-history__tile___hj7H+"},p().createElement("div",{className:"-esm-billing__bill-history__illo___SEucs"},p().createElement(d.EmptyCardIllustration,null)),p().createElement("p",{className:"-esm-billing__bill-history__content___YJZdv"},t("noBillsToDisplay","There are no bills to display.")),p().createElement(h.$nd,{onClick:()=>(0,d.launchWorkspace2)("patient-chart-billing-form-workspace",{patientUuid:e,onMutate:r}),kind:"ghost"},t("createBill","Create bill")))):p().createElement("div",null,p().createElement(d.CardHeader,{title:t("billingHistory","Billing History")},i&&p().createElement("span",null,p().createElement(h.OuH,{status:"active"})),p().createElement(h.$nd,{kind:"ghost",onClick:()=>(0,d.launchWorkspace2)("patient-chart-billing-form-workspace",{patientUuid:e,onMutate:r}),renderIcon:D.OM},t("createBill","Create bill"))),p().createElement("div",{className:"-esm-billing__bill-history__billHistoryContainer___yTHIn"},p().createElement(h.bQt,{isSortable:!0,rows:N,headers:C,size:"md",useZebraStyles:!0},({getExpandHeaderProps:a,getHeaderProps:l,getRowProps:n,getTableContainerProps:s,getTableProps:o,headers:c,rows:m})=>p().createElement(h.K3K,s,p().createElement(h.XIK,{className:"-esm-billing__bill-history__table___TYYPG",...o(),"aria-label":t("billList","Bill list")},p().createElement(h.ndF,null,p().createElement(h.Hjg,null,p().createElement(h.Uwq,{enableToggle:!0,...a()}),c.map((e,t)=>p().createElement(h.A0N,{key:t,...l({header:e})},e.header)),p().createElement(h.A0N,{"aria-label":(0,d.getCoreTranslation)("actions")}))),p().createElement(h.BFY,null,m.map((t,a)=>{let l=f.get(t.id);return p().createElement(p().Fragment,{key:t.id},p().createElement(h.fZD,n({row:t}),t.cells.map(e=>p().createElement(h.nA6,{key:e.id,className:"-esm-billing__bill-history__tableCells___ySiYL"},e.value)),p().createElement(h.nA6,{className:"cds--table-column-menu"},l?.status===V.ih.PENDING&&p().createElement(et,{bill:l,patientUuid:e,onMutate:r}))),t.isExpanded?p().createElement(h.cwJ,{colSpan:c.length+2},p().createElement("div",{className:"-esm-billing__bill-history__container___6+v1E",key:a},p().createElement(ea.A,{bill:l,onMutate:r,isLoadingBill:i}))):p().createElement(h.cwJ,{className:"-esm-billing__bill-history__hiddenRow___p94zi",colSpan:c.length+2}))}))))),s&&p().createElement(h.dKS,{forwardText:t("nextPage","Next page"),backwardText:t("previousPage","Previous page"),page:m,pageSize:E,pageSizes:v,totalItems:a.length,className:"-esm-billing__bill-history__pagination___Tosqe",size:"md",onChange:({page:e,pageSize:t})=>{e!==m&&o(e),y(t)}})))},e7),to=(0,d.getAsyncLifecycle)(()=>a.e("9414").then(a.bind(a,501)),e7),tc=(0,d.getSyncLifecycle)(({closeModal:e,patientUuid:t})=>{let{t:a}=(0,g.useTranslation)(),{defaultCurrency:l}=(0,d.useConfig)(),{bills:n,isLoading:i}=(0,Y.u1)(t),r=n.filter(e=>e?.status!==V.ih.PAID).flatMap(e=>e?.lineItems);return p().createElement(p().Fragment,null,p().createElement(h.rQ0,{closeModal:e,title:a("patientBillingAlert","Patient Billing Alert")}),p().createElement(h.cwr,null,p().createElement("p",{className:"-esm-billing__require-payment__bodyShort02___JC8LG"},a("billPaymentRequiredMessage","The current patient has a pending bill. Advise the patient to settle the bill before receiving services")),i&&p().createElement(h.OuH,{status:"active",iconDescription:(0,d.getCoreTranslation)("loading"),description:a("loadingBillItems","Loading bill items")+"..."}),p().createElement(h.r9c,{isCondensed:!0},p().createElement(h.AVA,null,p().createElement(h.Cvq,{head:!0},p().createElement(h.Um2,{head:!0},a("item","Item")),p().createElement(h.Um2,{head:!0},a("quantity","Quantity")),p().createElement(h.Um2,{head:!0},a("unitPrice","Unit price")),p().createElement(h.Um2,{head:!0},a("total","Total")))),p().createElement(h.GRJ,null,r.map(e=>p().createElement(h.Cvq,{key:e.uuid},p().createElement(h.Um2,null,e.billableService||e.item),p().createElement(h.Um2,null,e.quantity),p().createElement(h.Um2,null,(0,F.aL)(e.price,l)),p().createElement(h.Um2,null,(0,F.aL)(e.quantity*e.price,l))))))),p().createElement(h.jlY,null,p().createElement(h.$nd,{kind:"secondary",onClick:e},(0,d.getCoreTranslation)("cancel")),p().createElement(h.$nd,{kind:"primary",onClick:e},a("ok","OK"))))},e7),tm=(0,d.getSyncLifecycle)(({closeModal:e,editPaymentMode:t})=>{let{t:a}=(0,g.useTranslation)(),{mutate:l}=(0,x.iX)(),n=el.z.object({name:el.z.string().min(1,a("paymentModeNameRequired","Payment mode name is required")),description:el.z.string().optional()}),{control:i,handleSubmit:r,reset:s,formState:{errors:o,isSubmitting:c}}=(0,ei.mN)({resolver:(0,en.u)(n),defaultValues:{name:t?.name??"",description:t?.description??""}}),m=async n=>{let i=`${j.B}paymentMode`;try{let r={name:n.name,description:n.description};t?.uuid?await (0,A.vv)(t.uuid,r):await (0,A.cW)(r),l(e=>"string"==typeof e&&e.startsWith(i),void 0,{revalidate:!0}),(0,d.showSnackbar)({title:a("success","Success"),subtitle:a("paymentModeSaved","Payment mode was successfully saved."),kind:"success"}),e(),s({name:"",description:""})}catch(e){(0,d.showSnackbar)({title:(0,d.getCoreTranslation)("error"),subtitle:e?.message||a("errorSavingPaymentMode","An error occurred while saving the payment mode."),kind:"error",isLowContrast:!1})}};return p().createElement(p().Fragment,null,p().createElement(h.rQ0,{closeModal:e,title:t?a("editPaymentMode","Edit payment mode"):a("addPaymentMode","Add payment mode")}),p().createElement(h.lVW,{onSubmit:r(m)},p().createElement(h.cwr,null,p().createElement(h.BJc,{gap:5},p().createElement(ei.xI,{name:"name",control:i,render:({field:e})=>p().createElement(h.ksK,{id:"payment-mode-name",labelText:a("paymentModeNameLabel","Payment mode name"),placeholder:a("paymentModeNamePlaceholder","For example, Cash, Credit Card"),invalid:!!o.name,invalidText:o.name?.message,...e})}),p().createElement(ei.xI,{name:"description",control:i,render:({field:e})=>p().createElement(h.ksK,{id:"payment-mode-description",labelText:a("description","Description"),placeholder:a("descriptionPlaceholder","For example, Used for all cash transactions"),invalid:!!o.description,invalidText:o.description?.message,...e})}))),p().createElement(h.jlY,null,p().createElement(h.$nd,{kind:"secondary",onClick:e},(0,d.getCoreTranslation)("cancel")),p().createElement(h.$nd,{type:"submit",disabled:c},c?a("saving","Saving")+"...":(0,d.getCoreTranslation)("save")))))},e7),tu=(0,d.getSyncLifecycle)(({closeModal:e,paymentModeUuid:t,paymentModeName:a})=>{let{t:l}=(0,g.useTranslation)(),{mutate:n}=(0,x.iX)(),[i,r]=(0,_.useState)(!1),s=async()=>{r(!0);let a=`${j.B}paymentMode`;try{await (0,d.openmrsFetch)(`${d.restBaseUrl}/billing/paymentMode/${t}`,{method:"DELETE"}),n(e=>"string"==typeof e&&e.startsWith(a),void 0,{revalidate:!0}),(0,d.showSnackbar)({title:l("success","Success"),subtitle:l("paymentModeDeleted","Payment mode was successfully deleted."),kind:"success"}),e()}catch(e){(0,d.showSnackbar)({title:(0,d.getCoreTranslation)("error"),subtitle:e?.message||l("errorDeletingPaymentMode","An error occurred while deleting the payment mode."),kind:"error",isLowContrast:!1})}finally{r(!1)}};return p().createElement(p().Fragment,null,p().createElement(h.rQ0,{closeModal:e,title:l("deletePaymentMode","Delete Payment Mode")}),p().createElement(h.cwr,null,p().createElement("p",null,l("confirmDeleteMessage","Are you sure you want to delete this payment mode? Proceed cautiously.")),a&&p().createElement("p",null,p().createElement("strong",null,l("paymentModeNameToDelete","Payment Mode Name: {{paymentModeName}}",{paymentModeName:a})))),p().createElement(h.jlY,null,p().createElement(h.$nd,{kind:"secondary",onClick:e},(0,d.getCoreTranslation)("cancel")),p().createElement(h.$nd,{kind:"danger",onClick:s,disabled:i},i?l("deleting","Deleting")+"...":(0,d.getCoreTranslation)("delete"))))},e7),td=(0,d.getSyncLifecycle)(({closeModal:e,onCashPointAdded:t})=>{let{t:a}=(0,g.useTranslation)(),[l,n]=(0,_.useState)([]),i=el.z.object({name:el.z.string().min(1,a("cashPointNameRequired","Cash Point Name is required")),uuid:el.z.string().min(1,a("uuidRequired","UUID is required")).regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,a("invalidUuidFormat","Invalid UUID format")),location:el.z.string().min(1,a("locationRequired","Location is required"))}),{control:r,handleSubmit:s,reset:o,formState:{errors:c,isSubmitting:m}}=(0,ei.mN)({resolver:(0,en.u)(i),defaultValues:{name:"",uuid:"",location:""}}),u=(0,_.useCallback)(async()=>{try{let e=(await (0,d.openmrsFetch)(`${d.restBaseUrl}/location?v=default`)).data.results.map(e=>({id:e.uuid,label:e.display}));n(e)}catch(e){(0,d.showSnackbar)({title:(0,d.getCoreTranslation)("error"),subtitle:a("errorFetchingLocations","An error occurred while fetching locations."),kind:"error",isLowContrast:!1})}},[a]);(0,_.useEffect)(()=>{u()},[u]);let b=async l=>{try{await (0,d.openmrsFetch)(`${d.restBaseUrl}/billing/cashPoint`,{method:"POST",headers:{"Content-Type":"application/json"},body:{name:l.name,uuid:l.uuid,location:{uuid:l.location}}}),(0,d.showSnackbar)({title:a("success","Success"),subtitle:a("cashPointSaved","Cash point was successfully saved."),kind:"success"}),e(),o({name:"",uuid:"",location:""}),t()}catch(e){(0,d.showSnackbar)({title:(0,d.getCoreTranslation)("error"),subtitle:e?.message||a("errorSavingCashPoint","An error occurred while saving the cash point."),kind:"error",isLowContrast:!1})}};return p().createElement(p().Fragment,null,p().createElement(h.rQ0,{closeModal:e,title:a("addCashPoint","Add Cash Point")}),p().createElement(h.lVW,{onSubmit:s(b)},p().createElement(h.cwr,null,p().createElement(h.BJc,{gap:5},p().createElement(ei.xI,{name:"name",control:r,render:({field:e})=>p().createElement(h.ksK,{id:"cash-point-name",labelText:a("cashPointName","Cash Point Name"),placeholder:a("cashPointNamePlaceholder","For example, Pharmacy Cash Point"),invalid:!!c.name,invalidText:c.name?.message,...e})}),p().createElement(ei.xI,{name:"uuid",control:r,render:({field:e})=>p().createElement(h.ksK,{id:"cash-point-uuid",labelText:a("cashPointUuid","Cash Point UUID"),placeholder:a("cashPointUuidPlaceholder","Enter UUID"),invalid:!!c.uuid,invalidText:c.uuid?.message,...e})}),p().createElement(ei.xI,{name:"location",control:r,render:({field:e})=>p().createElement(h.msM,{id:"cash-point-location",label:a("selectLocation","Select Location"),titleText:a("cashPointLocation","Cash Point Location"),items:l,selectedItem:l.find(t=>t.id===e.value),onChange:({selectedItem:t})=>e.onChange(t?.id),invalid:!!c.location,invalidText:c.location?.message})}))),p().createElement(h.jlY,null,p().createElement(h.$nd,{kind:"secondary",onClick:e},(0,d.getCoreTranslation)("cancel")),p().createElement(h.$nd,{type:"submit",disabled:m},m?a("saving","Saving")+"...":(0,d.getCoreTranslation)("save")))))},e7),t_=(0,d.getSyncLifecycle)(({bill:e,closeModal:t,item:a,onMutate:l})=>{let{t:n}=(0,g.useTranslation)(),{defaultCurrency:i}=(0,d.useConfig)(),{billableServices:r}=(0,A.ly)(),[s,o]=(0,_.useState)(0),c=(0,_.useMemo)(()=>el.z.object({quantity:el.z.coerce.number({required_error:n("quantityRequired","Quantity is required"),invalid_type_error:n("quantityMustBeNumber","Quantity must be a valid number")}).int(n("quantityMustBeInteger","Quantity must be a whole number")).min(1,n("quantityMustBeAtLeastOne","Quantity must be at least 1")).max(100,n("quantityCannotExceed100","Quantity cannot exceed 100")),price:el.z.coerce.number({required_error:n("priceIsRequired","Price is required"),invalid_type_error:n("priceMustBeNumber","Price must be a valid number")}).min(0,n("priceMustBeNonNegative","Price must be 0 or greater"))}),[n]),{control:m,handleSubmit:u,formState:{isSubmitting:b,errors:E},watch:y}=(0,ei.mN)({defaultValues:{quantity:a.quantity,price:a.price},resolver:(0,en.u)(c)}),v=y("quantity"),f=y("price");(0,_.useEffect)(()=>{let e=("number"==typeof v?v:parseFloat(v)||0)*("number"==typeof f?f:parseFloat(f)||0);o(isNaN(e)?0:e)},[v,f]);let C=async i=>{let s={...a,quantity:i.quantity,price:i.price,billableService:(0,eu.e)(r,a.billableService),item:a?.item},o=(e?.lineItems.filter(e=>e.uuid!==a?.uuid).map(e=>({...e,billableService:(0,eu.e)(r,e.billableService)}))).concat(s),c={cashPoint:e.cashPointUuid,cashier:e.cashier.uuid,lineItems:o,patient:e.patientUuid,status:e.status,uuid:e.uuid};try{await (0,Y.FR)(c),l?.(),(0,d.showSnackbar)({title:n("lineItemUpdated","Line item updated"),subtitle:n("lineItemUpdateSuccess","The bill line item has been updated successfully"),kind:"success"}),t()}catch(e){(0,d.showSnackbar)({title:n("lineItemUpdateFailed","Failed to update line item"),subtitle:e?.message||n("lineItemUpdateErrorDefault","Unable to update the bill line item. Please try again."),kind:"error"})}};return Object.keys(e)?.length===0?p().createElement(h.rQ0,{closeModal:t,title:n("billLineItemEmpty","This bill has no line items")}):p().createElement(p().Fragment,null,p().createElement(h.rQ0,{closeModal:t,title:n("editBillLineItem","Edit bill line item")}),p().createElement(h.lVW,{onSubmit:u(C)},p().createElement(h.cwr,null,p().createElement(h.BJc,{gap:5},p().createElement("div",{className:ed.modalBody},p().createElement("div",{className:ed.billInfo},e?.patientName,p().createElement("span",{className:ed.separator},"\xb7"),e?.cashPointName,p().createElement("span",{className:ed.separator},"\xb7"),e?.receiptNumber)),p().createElement("section",null,p().createElement("p",{className:ed.label},n("item","Item"),": ",a?.billableService?a?.billableService:a?.item),p().createElement("p",{className:ed.label},n("currentPrice","Current price"),": ",(0,F.aL)(a?.price,i)),p().createElement("p",{className:ed.label},n("serviceStatus","Service status"),": ",a?.status),p().createElement(ei.xI,{name:"quantity",control:m,render:({field:{onChange:e,value:t}})=>p().createElement(h.Q7x,{allowEmpty:!0,disableWheel:!0,className:ed.controlField,hideSteppers:!0,id:"quantityInput",invalid:!!E.quantity,invalidText:E.quantity?.message,label:n("quantity","Quantity"),onChange:(t,a)=>{e(a.value)},value:t})}),p().createElement(ei.xI,{name:"price",control:m,render:({field:{value:e}})=>p().createElement(h.ksK,{className:ed.controlField,helperText:n("unitPriceHelperText","This is the unit price for this item"),id:"priceInput",labelText:n("unitPrice","Unit price"),readOnly:!0,value:e})}),p().createElement("p",{className:ed.label,"aria-live":"polite"},n("total","Total"),": ",(0,F.aL)(s,i))))),p().createElement(h.jlY,null,p().createElement(h.$nd,{kind:"secondary",onClick:t},(0,d.getCoreTranslation)("cancel")),p().createElement(h.$nd,{type:"submit",disabled:b},b?p().createElement("div",{className:ed.inline},p().createElement(h.OuH,{className:ed.loader,description:`${n("submitting","Submitting")}...`})):(0,d.getCoreTranslation)("save")))))},e7),tp=(0,d.getSyncLifecycle)(()=>{let e=window.getOpenmrsSpaBase()+"home/billing";return p().createElement(E.Kd,{basename:e},p().createElement(b.BV,null,p().createElement(b.qh,{path:"/",element:p().createElement(eR,null)}),p().createElement(b.qh,{path:"/patient/:patientUuid/:billUuid",element:p().createElement(e5,null)})))},e7),tb=(0,d.getSyncLifecycle)(({patientUuid:e})=>{let t=(0,Y.Vs)(e);return p().createElement("div",null,t?.map(e=>p().createElement(p().Fragment,{key:e.name},p().createElement(h.vwO,{type:"gray"},e.name),p().createElement(h.vwO,{type:"cool-gray"},e.value))))},e7),tE=(0,d.getSyncLifecycle)(({patientUuid:e,renderedFrom:t})=>"patient-chart"!==t?null:p().createElement(e2,{patientUuid:e}),e7),tg=(0,d.getAsyncLifecycle)(()=>a.e("1899").then(a.bind(a,662)),e7),ty=(0,d.getAsyncLifecycle)(()=>a.e("3784").then(a.bind(a,8843)),e7),th=(0,d.getSyncLifecycle)((n={name:"billable-services",title:"billableServices",path:"",icon:o.uW},()=>p().createElement(E.Kd,null,p().createElement(v,{config:n}))),e7),tv=(0,d.getSyncLifecycle)((i={title:"billingSettings",icon:c.wB,privilege:"coreapps.systemAdministration",items:[{name:"cash-point-config",title:"cashPointConfig",path:"cash-point-config"},{name:"payment-modes-config",title:"paymentModesConfig",path:"payment-modes-config"}]},()=>p().createElement(E.Kd,null,p().createElement(f,{config:i}))),e7),tf=(0,d.getAsyncLifecycle)(()=>a.e("1564").then(a.bind(a,6903)),e7),tC=(0,d.getAsyncLifecycle)(()=>a.e("5390").then(a.bind(a,4829)),e7),tN=(0,d.getAsyncLifecycle)(()=>a.e("7247").then(a.bind(a,8402)),e7),tT=(0,d.getSyncLifecycle)(({closeModal:e,bill:t,lineItem:a,onMutate:l})=>{let{t:n}=(0,g.useTranslation)(),{defaultCurrency:i}=(0,d.useConfig)(),[r,s]=(0,_.useState)(V.Bp.PERCENTAGE),[o,c]=(0,_.useState)(null),[m,u]=(0,_.useState)(""),[b,E]=(0,_.useState)(!1),y=!!a,v=a?.total??t.total,f=m.trim(),C=null!=o&&!Number.isNaN(o)&&o>0?r===V.Bp.PERCENTAGE?v*o/100:o:null,N=y?n("lineItemJustificationPlaceholder","e.g., damaged item, wrong quantity billed, expired stock"):n("billJustificationPlaceholder","e.g., hardship assistance, charity case, write-off"),T=m.length>1e3?n("justificationTooLong","Justification cannot exceed 1000 characters"):null,S=null==o||Number.isNaN(o)?null:o<=0?n("valueMustBePositive","Value must be greater than 0"):r===V.Bp.PERCENTAGE&&o>100?n("percentageTooHigh","Percentage cannot exceed 100"):null==C?null:C>t.amountDue?n("discountExceedsAmountDue","Discount cannot exceed the amount due"):a&&C>a.total?n("discountExceedsLineTotal","Discount cannot exceed the line item total"):null,k=!b&&null!=o&&f.length>0&&!T&&!S,D=async()=>{if(k&&null!=o){E(!0);try{await H({bill:t.uuid,lineItem:a?.uuid,discountType:r,discountValue:o,justification:f}),l?.(),(0,d.showSnackbar)({title:n("discountRequested","Discount request submitted"),subtitle:n("discountPendingReview","An admin will review your request"),kind:"success"}),e()}catch(t){let e=t?.responseBody?.error?.message??(t instanceof Error?t.message:void 0);(0,d.showSnackbar)({title:n("discountRequestFailed","Could not submit discount request"),subtitle:e,kind:"error"})}finally{E(!1)}}};return p().createElement(p().Fragment,null,p().createElement(h.rQ0,{closeModal:e,title:n("requestDiscount","Request discount")}),p().createElement(h.cwr,{className:"-esm-billing__request-discount-modal__modalBody___GBnye"},p().createElement(h.BJc,{gap:5},p().createElement("section",{className:"-esm-billing__request-discount-modal__scopePanel___3guqY","aria-label":n("discountScope","Discount scope")},p().createElement("div",{className:"-esm-billing__request-discount-modal__scopePrimary___Y71Gc"},y?a.display:n("wholeBillScope","Whole bill")),p().createElement("ul",{className:"-esm-billing__request-discount-modal__scopeMeta___xrhxy"},t.receiptNumber&&p().createElement("li",null,n("invoiceLabel","Invoice {{number}}",{number:t.receiptNumber})),y&&null!=a.quantity&&null!=a.price&&p().createElement("li",null,n("qtyTimesPrice","Qty {{quantity}} \xd7 {{price}}",{quantity:a.quantity,price:(0,F.aL)(a.price,i)})),!y&&null!=t.lineItemCount&&p().createElement("li",null,n("lineItemCount","{{count}} line items",{count:t.lineItemCount})),p().createElement("li",{className:"-esm-billing__request-discount-modal__scopeTotal___2e1eb"},y?n("lineTotalLabel","Line total {{total}}",{total:(0,F.aL)(v,i)}):n("billTotalLabel","Bill total {{total}}",{total:(0,F.aL)(v,i)})))),p().createElement(h.gE_,{legendText:n("discount","Discount"),className:"-esm-billing__request-discount-modal__discountGroup___qyLxM"},p().createElement(h.BJc,{gap:4},p().createElement(h.zWQ,{legendText:"",name:"discount-type",valueSelected:r,onChange:e=>s(e)},p().createElement(h.aaP,{labelText:n("percentage","Percentage"),value:V.Bp.PERCENTAGE}),p().createElement(h.aaP,{labelText:n("fixedAmount","Fixed amount"),value:V.Bp.FIXED_AMOUNT})),p().createElement(h.Q7x,{id:"discount-value",label:r===V.Bp.PERCENTAGE?n("valuePercentLabel","Value (%)"):n("valueAmountLabel","Value ({{currency}})",{currency:i}),allowEmpty:!0,min:0,value:o??"",invalid:!!S,invalidText:S??"",onChange:(e,{value:t})=>{if(""===t||null==t)return void c(null);let a="string"==typeof t?parseFloat(t):t;c(Number.isNaN(a)?null:a)}}))),null!=C&&p().createElement("section",{className:"-esm-billing__request-discount-modal__summaryCard___BjITg","aria-label":n("discountSummary","Discount summary")},p().createElement("span",{className:e_},y?n("lineTotal","Line total"):n("billTotal","Bill total")),p().createElement("span",{className:ep},(0,F.aL)(v,i)),p().createElement("span",{className:e_},r===V.Bp.PERCENTAGE&&null!=o?n("discountWithPercent","Discount ({{percent}}%)",{percent:o}):n("discountLabel","Discount")),p().createElement("span",{className:`${ep} -esm-billing__request-discount-modal__summaryDiscount___REJ5I`},"−",(0,F.aL)(C,i)),y&&p().createElement(p().Fragment,null,p().createElement("span",{className:e_},n("lineAfterDiscount","Line after discount")),p().createElement("span",{className:ep},(0,F.aL)(v-C,i))),p().createElement("span",{className:"-esm-billing__request-discount-modal__summaryDivider___2nBbX","aria-hidden":"true"}),p().createElement("span",{className:e_},n("outstanding","Outstanding")),p().createElement("span",{className:ep},(0,F.aL)(t.amountDue,i)),p().createElement("span",{className:"-esm-billing__request-discount-modal__summaryTotalLabel___9ESne"},n("amountDueOnBillAfterDiscount","Amount due on bill after discount")),p().createElement("span",{className:"-esm-billing__request-discount-modal__summaryTotalValue___Cwkmg"},(0,F.aL)(t.amountDue-C,i))),p().createElement(h.fs1,{id:"discount-justification",labelText:n("justification","Justification"),placeholder:N,maxCount:1e3,enableCounter:!0,required:!0,rows:3,value:m,invalid:!!T,invalidText:T??"",onChange:e=>u(e.target.value)}))),p().createElement(h.jlY,null,p().createElement(h.$nd,{kind:"secondary",onClick:e},(0,d.getCoreTranslation)("cancel")),p().createElement(h.$nd,{kind:"primary",onClick:D,disabled:!k},b?p().createElement(h.OuH,{description:n("submitting","Submitting")+"..."}):p().createElement("span",null,n("submitRequest","Submit request")))))},e7),tS=(0,d.getSyncLifecycle)(({closeModal:e,bill:t,onMutate:a})=>{let l,n,i,r,s,o,c,m,u,{t:b}=(0,g.useTranslation)(),E=(0,d.useSession)(),{bill:y,mutate:v,isLoading:f,isValidating:C}=(0,Y.DX)(t.uuid,!1),N=y??t,[T,S]=(0,_.useState)(null),[k,D]=(0,_.useState)(null),[A,P]=(0,_.useState)(null),w=N.status===V.ih.PENDING||N.status===V.ih.POSTED,{pendingDiscounts:I,confirmedDiscounts:L,approvedDiscounts:M,lineItems:B,payments:R,paymentsTotal:q,subtotal:F,currentNet:x,outstanding:j}=(n=(l=(0,_.useMemo)(()=>(N.discounts??[]).filter(e=>!e.voided),[N.discounts])).filter(e=>e.status===V.nT.PENDING),i=l.filter(e=>e.status!==V.nT.PENDING),r=l.filter(e=>e.status===V.nT.APPROVED),s=(N.lineItems??[]).filter(e=>!e.voided),c=(o=(N.payments??[]).filter(e=>!e.voided)).reduce((e,t)=>e+(t.amountTendered??0),0),m=N.total,{activeDiscounts:l,pendingDiscounts:n,confirmedDiscounts:i,approvedDiscounts:r,lineItems:s,payments:o,paymentsTotal:c,subtotal:m,currentNet:u=N.amountAfterDiscount,outstanding:u-c}),$=(0,_.useCallback)(async e=>{if(w){if(j-e.discountAmount<0)return void(0,d.showSnackbar)({title:b("approveBlocked","Cannot approve discount"),subtitle:b("approveBlockedNegativeDue","Approving this discount would push the amount due below zero."),kind:"error"});S(e.uuid);try{await O(e.uuid,V.nT.APPROVED,E.user.uuid),(0,d.showSnackbar)({title:b("discountApproved","Discount approved"),kind:"success"}),await v(),a()}catch(e){(0,d.showSnackbar)({title:b("approveFailed","Approve failed"),subtitle:eI(e),kind:"error"})}finally{S(null)}}},[w,j,b,E.user.uuid,v,a]),U=(0,_.useCallback)(async e=>{if(w){S(e.uuid);try{await O(e.uuid,V.nT.REJECTED,E.user.uuid),(0,d.showSnackbar)({title:b("discountRejected","Discount rejected"),kind:"success"}),await v(),a()}catch(e){(0,d.showSnackbar)({title:b("rejectFailed","Reject failed"),subtitle:eI(e),kind:"error"})}finally{S(null),D(null)}}},[w,b,E.user.uuid,v,a]),H=(0,_.useCallback)(async e=>{if(e.status===V.nT.APPROVED&&j<=0){(0,d.showSnackbar)({title:b("deleteBlocked","Cannot delete discount"),subtitle:b("deleteBlockedFullyPaid","An approved discount cannot be removed once the bill is fully paid."),kind:"error"}),P(null);return}S(e.uuid);try{await z(e.uuid,"Deleted by admin"),(0,d.showSnackbar)({title:b("discountDeleted","Discount deleted"),kind:"success"}),await v(),a()}catch(e){(0,d.showSnackbar)({title:b("deleteFailed","Delete failed"),subtitle:eI(e),kind:"error"})}finally{S(null),P(null)}},[j,b,v,a]),K=(0,_.useCallback)(()=>D(null),[]),W=(0,_.useCallback)(()=>P(null),[]),G=!!T||f||C;return p().createElement(p().Fragment,null,p().createElement(h.rQ0,{closeModal:e,title:b("reviewDiscounts","Review discounts")}),p().createElement(h.cwr,null,G?p().createElement(h.z21,{label:"",hideLabel:!0}):p().createElement("div",{className:"-esm-billing__review-bill-discounts-modal__layout___gF7VM"},p().createElement(eC,{bill:N,lineItems:B,payments:R,paymentsTotal:q,subtotal:F,currentNet:x,outstanding:j,approvedDiscounts:M,pendingDiscounts:I}),p().createElement(ew,{pendingDiscounts:I,confirmedDiscounts:L,lineItems:B,busy:T,rejectingId:k,deletingId:A,canDecide:w,onApprove:$,onStartReject:D,onCancelReject:K,onConfirmReject:U,onStartDelete:P,onCancelDelete:W,onConfirmDelete:H}))))},e7),tk=(0,d.getSyncLifecycle)((r={name:"discount-requests",title:"discountRequests",path:"discount-requests",icon:m.CR},()=>p().createElement(E.Kd,null,p().createElement(C,{config:r}))),e7),tD=(0,d.getAsyncLifecycle)(()=>a.e("6594").then(a.bind(a,3785)),e7),tA=(0,d.getAsyncLifecycle)(()=>a.e("2269").then(a.bind(a,2220)),e7),tP=(0,d.getSyncLifecycle)((s={name:"refund-requests",title:"refundRequests",path:"refund-requests",icon:u.ds},()=>p().createElement(E.Kd,null,p().createElement(N,{config:s}))),e7)},6762(e,t,a){"use strict";a.d(t,{A:()=>g});var l=a(5275),n=a.n(l),i=a(6942),r=a.n(i),s=a(8395),o=a(4751),c=a.n(o),m=a(6800),u=a(3137),d=a(5084);let _="-esm-billing__line-item-action-menu__menuitem___lOuJD",p=({bill:e,item:t,onMutate:a,showDiscountRequest:i,onDiscountRequest:r,showRefundRequest:o,onRefundRequest:c})=>{let{t:p}=(0,s.useTranslation)(),b=(0,u.useLayoutType)(),E=(0,l.useCallback)(()=>{let l=(0,u.showModal)("edit-bill-line-item-modal",{bill:e,item:t,closeModal:()=>l(),onMutate:a})},[e,t,a]),g=(0,l.useCallback)(()=>{let e=(0,u.showModal)("delete-line-item-confirmation-modal",{item:t,closeModal:()=>e(),onMutate:a})},[t,a]),y=e?.status===d.ih.PENDING;return n().createElement(m.Wdr,null,n().createElement(m.obU,{align:"left",flipped:!0,size:(0,u.isDesktop)(b)?"sm":"lg","data-testid":`action-menu-${t.uuid}`},n().createElement(m.XSD,{className:_,"data-testid":`edit-button-${t.uuid}`,disabled:!y,itemText:(0,u.getCoreTranslation)("edit"),onClick:E}),n().createElement(m.XSD,{className:_,"data-testid":`delete-button-${t.uuid}`,disabled:!y,isDelete:!0,itemText:(0,u.getCoreTranslation)("delete"),onClick:g}),i&&n().createElement(m.XSD,{className:_,"data-testid":`request-discount-button-${t.uuid}`,itemText:p("requestDiscount","Request discount"),onClick:r}),o&&n().createElement(m.XSD,{className:_,"data-testid":`request-refund-button-${t.uuid}`,itemText:p("requestRefund","Request refund"),onClick:c})))};var b=a(1772);let E=e=>(e.price??0)*(e.quantity??0),g=({bill:e,isLoadingBill:t,onMutate:a,viewOnly:i})=>{let{t:o}=(0,s.useTranslation)(),{defaultCurrency:_}=(0,u.useConfig)(),g=(0,u.useLayoutType)(),y=(0,l.useMemo)(()=>e?.lineItems??[],[e?.lineItems]),h=(0,u.isDesktop)(g)?"sm":"lg",[v,f]=(0,l.useState)(""),C=(0,u.useDebounce)(v),N=(0,l.useMemo)(()=>(e?.discounts??[]).filter(e=>!e.voided),[e?.discounts]),T=e?.status===d.ih.PENDING||e?.status===d.ih.POSTED,S=N.some(e=>!e.lineItemUuid),k=(0,l.useMemo)(()=>(e?.refunds??[]).filter(e=>!e.voided),[e?.refunds]),D=e?.status===d.ih.PAID||e?.status===d.ih.PARTIALLY_REFUNDED||e?.status===d.ih.REFUND_REQUESTED,A=k.filter(e=>e.status===d.fH.REQUESTED||e.status===d.fH.APPROVED),P=A.some(e=>!e.lineItemUuid),w=(0,l.useMemo)(()=>C?c().filter(C,y,{extract:e=>`${e.billableService} ${e.item}`}).sort((e,t)=>e.score-t.score).map(e=>e.original):y,[C,y]),I=(0,l.useMemo)(()=>new Map(y.map(e=>[e.uuid,e])),[y]),L=[{header:o("number","Number"),key:"no",width:7},{header:o("billItem","Bill item"),key:"billItem",width:25},{header:o("status","Status"),key:"status",width:25},{header:o("quantity","Quantity"),key:"quantity",width:15},{header:o("price","Price"),key:"price",width:24},{header:o("total","Total"),key:"total",width:15}],M=(0,l.useMemo)(()=>w?.map((e,t)=>({no:`${t+1}`,id:`${e.uuid}`,billItem:e.billableService?e.billableService:e?.item,status:e.status,quantity:e.quantity,price:(0,b.aL)(e.price,_),total:(0,b.aL)(E(e),_)}))??[],[w,_]);return t?n().createElement(m.OOb,{"data-testid":"loader",columnCount:L.length,showHeader:!1,showToolbar:!1,zebra:!0}):n().createElement("div",{className:"-esm-billing__invoice-table__lineItemsWrapper___ABU3I"},n().createElement(m.bQt,{headers:L,rows:M,size:h,useZebraStyles:!0,overflowMenuOnHover:(0,u.isDesktop)(g)},({rows:t,headers:l,getRowProps:s,getTableProps:c})=>n().createElement(m.K3K,{description:n().createElement("span",{className:"-esm-billing__invoice-table__tableDescription___JKz3j"},n().createElement("span",null,o("itemsToBeBilled","Items to be billed"))),title:o("lineItems","Line items")},!i&&n().createElement(m.w6V,{className:"-esm-billing__invoice-table__searchbox___oxEnj",expanded:!0,onChange:e=>f(e.target.value),placeholder:o("searchThisTable","Search this table"),size:h}),n().createElement(m.XIK,{...c(),"aria-label":o("invoiceLineItems","Invoice line items"),className:r()("-esm-billing__invoice-table__invoiceTable___2hd71","billingTable")},n().createElement(m.ndF,null,n().createElement(m.Hjg,null,l.map(e=>n().createElement(m.A0N,{key:e.key},e.header)),!i&&n().createElement(m.A0N,{"aria-label":(0,u.getCoreTranslation)("actions")}))),n().createElement(m.BFY,null,t.map(t=>{let l,r,o=I.get(t.id);return n().createElement(m.Hjg,{key:t.id,...s({row:t})},t.cells.map(e=>n().createElement(m.nA6,{key:e.id},e.value)),!i&&n().createElement(m.nA6,{className:"cds--table-column-menu"},o&&n().createElement(p,{bill:e,item:o,onMutate:a,showDiscountRequest:T&&!S&&(l=o.uuid,!N.some(e=>e.lineItemUuid===l)),onDiscountRequest:()=>{let t;t=(0,u.showModal)("request-discount-modal",{bill:{uuid:e.uuid,total:e.totalAmount??0,amountDue:Math.max(0,(e.netAmount??e.totalAmount??0)-(e.tenderedAmount??0)),receiptNumber:e.receiptNumber,lineItemCount:y.length},lineItem:{uuid:o.uuid,display:o.item||o.billableService||"--",total:E(o),quantity:o.quantity,price:o.price},onMutate:()=>a?.(),closeModal:()=>t()})},showRefundRequest:D&&!P&&(r=o.uuid??"",!A.some(e=>e.lineItemUuid===r))&&!!o.uuid,onRefundRequest:()=>(t=>{if(!t.uuid)return;let l=E(t),n=l-k.filter(e=>e.lineItemUuid===t.uuid&&(e.status===d.fH.APPROVED||e.status===d.fH.COMPLETED)).reduce((e,t)=>e+t.refundAmount,0),i=(0,u.showModal)("request-refund-modal",{bill:{uuid:e.uuid,total:e.totalAmount??0,amountAfterDiscount:e.netAmount??e.totalAmount??0},lineItem:{uuid:t.uuid,display:t.item||t.billableService||"--",total:l,quantity:t.quantity,price:t.price},remainingRefundable:Math.max(0,n),onMutate:()=>a?.(),closeModal:()=>i()})})(o)})))}))))),w?.length===0&&n().createElement("div",{className:"-esm-billing__invoice-table__filterEmptyState___ZtVBH"},n().createElement(m.Wdr,null,n().createElement(m.FAs,{className:"-esm-billing__invoice-table__filterEmptyStateTile___j92yY"},n().createElement("p",{className:"-esm-billing__invoice-table__filterEmptyStateContent___41NoP"},o("noMatchingItemsToDisplay","No matching items to display")),!i&&n().createElement("p",{className:"-esm-billing__invoice-table__filterEmptyStateHelper___+DQR2"},o("checkFilters","Check the filters above"))))))}},7661(e,t,a){"use strict";a.d(t,{e:()=>l});let l=(e,t)=>{if(!e.length)return null;let a=e.find(e=>e.name===t);return a?.uuid??null}},8683(e,t,a){"use strict";a.d(t,{KY:()=>s,eK:()=>c,qC:()=>o,zb:()=>m});var l=a(3137),n=a(7003);let i=`${n.B}billRefund`,r=`${n.B}bill`;function s({statuses:e}){let t=new URLSearchParams({refundStatus:e.join(","),v:"default"}),a=`${r}?${t.toString()}`,{data:n,isLoading:i,error:o,mutate:c,isValidating:m}=(0,l.useOpenmrsFetchAll)(a);return{bills:n??[],isLoading:i,error:o,mutate:c,isValidating:m}}async function o(e){return(await (0,l.openmrsFetch)(i,{method:"POST",headers:{"Content-Type":"application/json"},body:e})).data}async function c(e,t){return(await (0,l.openmrsFetch)(`${i}/${e}`,{method:"POST",headers:{"Content-Type":"application/json"},body:t})).data}async function m(e,t){await (0,l.openmrsFetch)(`${i}/${e}?reason=${encodeURIComponent(t)}`,{method:"DELETE"})}},5084(e,t,a){"use strict";a.d(t,{Bp:()=>r,fH:()=>s,ih:()=>l,nT:()=>i,zk:()=>n});let l={PENDING:"PENDING",POSTED:"POSTED",PAID:"PAID",ADJUSTED:"ADJUSTED",PARTIALLY_REFUNDED:"PARTIALLY_REFUNDED",REFUNDED:"REFUNDED",REFUND_REQUESTED:"REFUND_REQUESTED"},n={PENDING:"PENDING",PAID:"PAID",CANCELLED:"CANCELLED",ADJUSTED:"ADJUSTED",EXEMPTED:"EXEMPTED",REFUND_REQUESTED:"REFUND_REQUESTED",REFUNDED:"REFUNDED",PARTIALLY_REFUNDED:"PARTIALLY_REFUNDED"},i={PENDING:"PENDING",APPROVED:"APPROVED",REJECTED:"REJECTED"},r={PERCENTAGE:"PERCENTAGE",FIXED_AMOUNT:"FIXED_AMOUNT"},s={REQUESTED:"REQUESTED",APPROVED:"APPROVED",REJECTED:"REJECTED",COMPLETED:"COMPLETED"}}}]);
18
+ `;function e5({label:e,value:t}){let{t:a}=(0,g.useTranslation)();return p().createElement("div",null,p().createElement("h1",{className:"-esm-billing__invoice__label___Ecjiu"},a(e)),p().createElement("span",{className:"-esm-billing__invoice__value___1rJZi"},t))}let e2=()=>{let{t:e}=(0,g.useTranslation)(),{data:t}=(0,ee.eC)(),{billUuid:a,patientUuid:l}=(0,b.g)(),{patient:n,isLoading:i}=(0,d.usePatient)(l),{bill:r,isLoading:s,error:o,isValidating:c,mutate:m}=(0,ee.DX)(a),[u,E]=(0,_.useState)(!1),y=(0,_.useRef)(null),f=(0,_.useRef)(null),{defaultCurrency:v}=(0,d.useConfig)(),C=(r?.discounts??[]).filter(e=>!e.voided),N=C.some(e=>!e.lineItemUuid),S=C.some(e=>!!e.lineItemUuid),k=r?.status===K.ih.PENDING||r?.status===K.ih.POSTED,A=!!r&&k&&!N,P=C.some(e=>e.status===K.nT.APPROVED),w=(r?.refunds??[]).filter(e=>!e.voided),I=r?.status===K.ih.PAID||r?.status===K.ih.PARTIALLY_REFUNDED,L=w.filter(e=>e.status===K.fH.REQUESTED||e.status===K.fH.APPROVED),M=L.some(e=>!e.lineItemUuid),B=new Set(L.flatMap(e=>e.lineItemUuid?[e.lineItemUuid]:[])),R=!!r&&I&&!M,q=()=>{if(!r)return;if(null==r.netAmount)return void(0,d.showSnackbar)({title:e("refundUnavailable","Refund unavailable"),subtitle:e("refundUnavailableSubtitle","Bill amount could not be determined. Please reload and try again."),kind:"error"});let t=w.filter(e=>e.status===K.fH.APPROVED||e.status===K.fH.COMPLETED).reduce((e,t)=>e+t.refundAmount,0),a=r.netAmount-t,l=(0,d.showModal)("request-refund-modal",{bill:{uuid:r.uuid,total:r.totalAmount??0,amountAfterDiscount:r.netAmount,receiptNumber:r.receiptNumber,lineItemCount:r.lineItems?.length??0},remainingRefundable:Math.max(0,a),onMutate:()=>m(),closeModal:()=>l()})},x=(0,_.useCallback)(()=>{f.current=null,E(!1)},[]),j=(0,_.useCallback)(()=>new Promise(e=>{n&&r&&(E(!0),f.current=e)}),[r,n]),$=()=>{let e=(0,d.showModal)("finalize-bill-confirmation-modal",{bill:r,onMutate:m,closeModal:()=>e()})},U=(0,eF.useReactToPrint)({contentRef:y,documentTitle:`Invoice ${r?.receiptNumber} - ${n?.name?.[0]?.given?.join(" ")} ${n?.name?.[0].family}`,pageStyle:e6,onBeforePrint:j,onAfterPrint:x,preserveAfterPrint:!1,onPrintError:(t,a)=>(0,d.showSnackbar)({title:e("errorPrintingInvoice","Error printing invoice"),kind:"error",subtitle:a.message})});(0,_.useEffect)(()=>{u&&f.current&&f.current()},[u]);let H={[e("dateBillCreated","Date bill created")]:r?.dateCreated?(0,d.formatDate)((0,d.parseDate)(r.dateCreated),{mode:"wide"}):"--",[e("totalAmount","Total amount")]:(0,F.aL)(r?.totalAmount,v),...P?{[e("discount","Discount")]:`- ${(0,F.aL)((r?.totalAmount??0)-(r?.netAmount??0),v)}`,[e("netAmount","Net amount")]:(0,F.aL)(r?.netAmount,v)}:{},[e("amountTendered","Amount tendered")]:(0,F.aL)(r?.tenderedAmount,v),[e("amountDue","Amount due")]:(0,F.aL)(r?(r.netAmount??0)-(r.tenderedAmount??0):void 0,v),[e("invoiceNumber","Invoice number")]:r?.receiptNumber,[e("invoiceStatus","Invoice status")]:r?.status};return i||s?p().createElement("div",{className:e3},p().createElement(h.OuH,{className:"-esm-billing__invoice__loader___YjE+7",description:`${e("loadingBillInfo","Loading bill information")}...`})):o?p().createElement("div",{className:"-esm-billing__invoice__errorContainer___b+MxG"},p().createElement(d.ErrorState,{headerTitle:e("invoiceError","Invoice error"),error:o})):p().createElement("div",{className:e3},n&&l&&p().createElement(d.ExtensionSlot,{name:"patient-header-slot",state:{patient:n,patientUuid:l}}),p().createElement("div",{className:"-esm-billing__invoice__actionsContainer___CSsXH"},c&&p().createElement("span",null,p().createElement(h.OuH,{status:"active"})),A&&p().createElement(h.$nd,{kind:"tertiary",onClick:()=>{let e=(0,d.showModal)("request-discount-modal",{bill:{uuid:r.uuid,total:r.totalAmount??0,amountDue:Math.max(0,(r.netAmount??r.totalAmount??0)-(r.tenderedAmount??0)),receiptNumber:r.receiptNumber,lineItemCount:r.lineItems?.length??0},onMutate:()=>m(),closeModal:()=>e()})},disabled:S},e("requestDiscount","Request discount")),R&&(B.size>0?p().createElement(h.m_M,{align:"bottom",label:e("refundInProgress","A refund is already in progress for one or more line items")},p().createElement(h.$nd,{kind:"tertiary",onClick:q,disabled:!0},e("requestRefund","Request refund"))):p().createElement(h.$nd,{kind:"tertiary",onClick:q},e("requestRefund","Request refund"))),r?.status===K.ih.PENDING&&p().createElement(p().Fragment,null,p().createElement(h.$nd,{kind:"ghost",renderIcon:D.OM,onClick:()=>(0,d.launchWorkspace2)("billing-form-workspace",{patientUuid:l,billUuid:r.uuid,onMutate:m})},e("addItemsToBill","Add items to bill")),p().createElement(h.$nd,{kind:"danger--ghost",onClick:()=>{let e=(0,d.showModal)("delete-bill-confirmation-modal",{bill:r,onSuccess:()=>(0,d.navigate)({to:window.getOpenmrsSpaBase()+"home/billing"}),closeModal:()=>e()})}},e("deleteBill","Delete bill")),p().createElement(h.$nd,{kind:"primary",onClick:$},e("finalizeBill","Finalize bill"))),p().createElement(h.$nd,{disabled:u||i||s,onClick:U,renderIcon:e=>p().createElement(T.xj,{size:24,...e}),iconDescription:e("printBill","Print bill")},e("printBill","Print bill")),r&&(r.status===K.ih.PAID||r.tenderedAmount>0)&&p().createElement(ez,{billUuid:r.uuid})),p().createElement("div",{className:"-esm-billing__invoice__detailsContainer___93jPh"},p().createElement("section",{className:"-esm-billing__invoice__details___zIHv7"},Object.entries(H).map(([e,t])=>p().createElement(e5,{key:e,label:e,value:t})))),p().createElement("div",{className:"-esm-billing__invoice__invoiceContent___Yd6Pt"},p().createElement(el.A,{bill:r,isLoadingBill:s,onMutate:m}),r&&p().createElement(e0,{bill:r}),r&&p().createElement(e1,{bill:r,onMutate:m}),p().createElement(eO,{bill:r,mutate:m,onFinalizeBill:$})),r&&n&&p().createElement("div",{className:"-esm-billing__invoice__printContainer___9D3HY"},p().createElement(eY,{bill:r,patient:n,defaultFacility:t,componentRef:y})))},e4=({patientUuid:e})=>{let{t}=(0,g.useTranslation)(),{paymentStatus:a,isLoading:l,error:n}=(0,ee.N7)(e);return l||n||!a||"UNKNOWN"===a.status?null:p().createElement(h.Gff,{className:"-esm-billing__payment-status-tag__tag___Sfz+y"},p().createElement(h.yvu,{label:t(a.status,a.status)},p().createElement(h.vwO,{type:"PAID"===a.status?"green":"red"},t(a.status,a.status))),p().createElement(h.pNg,null,p().createElement("div",{role:"tooltip"},p().createElement("p",null,a.reason))))},e8={logo:{src:{_type:d.Type.String,_default:"",_description:"The path or URL to the logo image. If set to an empty string, the alt text will be used.",_validators:[d.validators.isUrl]},alt:{_type:d.Type.String,_default:"",_description:"The alternative text for the logo image, displayed when the image cannot be loaded or on hover. If not provided and src is empty, the default OpenMRS SVG sprite will be used."}},country:{_type:d.Type.String,_description:"The text that gets printed on the top right of the invoice, typically the name of the country",_default:"Kenya"},patientCategory:{_type:d.Type.Object,_description:"Visit Attribute Type UUIDs - These are custom attribute types that can be attached to patient visits. Each UUID represents a Visit Attribute Type in OpenMRS that stores payment-related information for the visit.",_default:{paymentDetails:"fbc0702d-b4c9-4968-be63-af8ad3ad6239",paymentMethods:"8553afa0-bdb9-4d3c-8a98-05fa9350aa85",policyNumber:"aac48226-d143-4274-80e0-264db4e368ee",insuranceScheme:"3a988e33-a6c0-4b76-b924-01abb998944b",patientCategory:"3b9dfac8-9e4d-11ee-8c90-0242ac120002",formPayloadPending:"919b51c9-8e2e-468f-8354-181bf3e55786"}},categoryConcepts:{_type:d.Type.Object,_description:"Concept UUIDs - These are OpenMRS Concept UUIDs that represent the actual values/options for payment categories. These concepts are stored as values in the visit attributes defined in patientCategory.",_default:{payingDetails:"44b34972-6630-4e5a-a9f6-a6eb0f109650",nonPayingDetails:"f3fb2d88-cccd-422c-8766-be101ba7bd2e",insuranceDetails:"beac329b-f1dc-4a33-9e7c-d95821a137a6"}},nonPayingPatientCategories:{_type:d.Type.Object,_description:"Concept UUIDs for non-paying patient categories - These are OpenMRS Concept UUIDs that identify specific patient categories eligible for non-paying status (e.g., children under 5, students). These are used as values when a patient is categorized as non-paying.",_default:{childUnder5:"1528AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",student:"159465AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"}},postBilledItems:{_type:d.Type.Object,_description:"Default UUIDs used when creating bills - These UUIDs identify default resources (cash points, cashier providers) that are used when submitting a bill if not explicitly provided.",_default:{cashPoint:"54065383-b4d4-42d2-af4d-d250a1fd2590",cashier:"f9badd80-ab76-11e2-9e96-0800200c9a66",priceUuid:"7b9171ac-d3c1-49b4-beff-c9902aee5245"}},serviceTypes:{_type:d.Type.Object,_description:"Service Type Concept Set UUID - This is an OpenMRS Concept Set UUID. The set members of this concept represent the different types of services that can be billed (e.g., Consultation, Lab Test, Procedure).",_default:{billableService:"21b8cf43-9f9f-4d02-9f4a-d710ece54261"}},defaultCurrency:{_type:d.Type.String,_description:"The default currency for the application. Specify the currency code (e.g., KES, UGX, GBP).",_default:"KES"},pageSize:{_type:d.Type.Number,_description:"The default page size",_default:10}},e7="@openmrs/esm-billing-app",e9={featureName:"billing",moduleName:e7},te=a(4767),tt=(0,d.getSyncLifecycle)((l={name:"billing",title:"billing"},()=>p().createElement(E.Kd,null,p().createElement(y,{config:l}))),e9);function ta(){(0,d.defineConfigSchema)(e7,e8)}let tl=(0,d.getSyncLifecycle)((0,d.createDashboard)({slot:"patient-chart-billing-dashboard-slot",columns:1,title:"billingHistory",hideDashboardTitle:!0,icon:"omrs-icon-money",path:"billing-history"}),e9),tn=(0,d.getSyncLifecycle)(()=>{let{t:e}=(0,g.useTranslation)(),t=window.getOpenmrsSpaBase();return p().createElement(h.t3h,{className:"-esm-billing__item__customTile___Z3Rn6",id:"menu-item",href:`${t}billable-services`},p().createElement("div",{className:"customTileTitle"},p().createElement(T.TA,{size:24})),p().createElement("div",null,e("billableServices","Billable services")))},e9),ti=(0,d.getSyncLifecycle)(()=>{let{t:e}=(0,g.useTranslation)(),t=e("manageBilling","Manage billing");return p().createElement(h.Wdr,null,p().createElement(h.t3h,{href:`${window.spaBase}/billable-services`},p().createElement("div",null,p().createElement("div",{className:"heading"},t),p().createElement("div",{className:"content"},e("billingAdministration","Billing administration"))),p().createElement("div",{className:"iconWrapper"},p().createElement(D.Qp,{size:16}))))},e9),tr=(0,d.getSyncLifecycle)(()=>{let{t:e}=(0,g.useTranslation)(),t=(0,d.useLayoutType)(),a=`${window.spaBase}/billable-services`;return(0,d.useLeftNav)({name:"billable-services-left-panel-slot",basePath:a}),p().createElement(E.Kd,{basename:a},p().createElement("div",{className:"-esm-billing__billable-services__pageWrapper___jBBH1"},p().createElement("main",{className:k()("-esm-billing__billable-services__pageContent___bnbzA",{"-esm-billing__billable-services__hasLeftNav___3svGW":(0,d.isDesktop)(t)})},p().createElement(M,{title:e("billingAdministration","Billing administration")}),p().createElement(b.BV,null,p().createElement(b.qh,{path:"/",element:p().createElement(I,null)}),p().createElement(b.qh,{path:"/cash-point-config",element:p().createElement(B,null)}),p().createElement(b.qh,{path:"/payment-modes-config",element:p().createElement(q,null)}),p().createElement(b.qh,{path:"/discount-requests",element:p().createElement(Q,null)}),p().createElement(b.qh,{path:"/refund-requests",element:p().createElement(Y,null)})))),p().createElement(d.WorkspaceContainer,{contextKey:"billable-services"}))},e9),ts=(0,d.getSyncLifecycle)(eu,e9),to=(0,d.getSyncLifecycle)(({patientUuid:e})=>{let{t}=(0,g.useTranslation)(),{bills:a,error:l,isLoading:n,isValidating:i,mutate:r}=(0,ee.u1)(e),{paginated:s,goTo:o,results:c,currentPage:m}=(0,d.usePagination)(a),{pageSize:u,defaultCurrency:b}=(0,d.useConfig)(),[E,y]=(0,_.useState)(u),{pageSizes:f}=(0,d.usePaginationInfo)(u,a?.length,m,c?.length),v=(0,_.useMemo)(()=>new Map(a?.map(e=>[e.uuid,e])),[a]),C=[{header:t("billDate","Bill date"),key:"billDate"},{header:t("invoiceNumber","Invoice number"),key:"invoiceNumber"},{header:t("billedItems","Billed items"),key:"billedItems"},{header:t("billTotal","Bill total"),key:"billTotal"}],N=c?.map(e=>({id:e.uuid,uuid:e.uuid,billTotal:(0,F.aL)(e?.totalAmount,b),billDate:(0,d.formatDate)((0,d.parseDate)(e.dateCreated),{mode:"wide"}),invoiceNumber:e.receiptNumber,billedItems:e?.lineItems?.map(e=>e?.billableService||e?.item).filter(Boolean).join(" & ")}));return n?p().createElement("div",{className:"-esm-billing__bill-history__loaderContainer___KePhb"},p().createElement(h.OOb,{showHeader:!1,showToolbar:!1,zebra:!0})):l?p().createElement("div",{className:"-esm-billing__bill-history__errorContainer___j-G7W"},p().createElement(h.Wdr,null,p().createElement(d.ErrorState,{error:l,headerTitle:t("billList","Bill list")}))):0===a.length?p().createElement(h.Wdr,{className:"-esm-billing__bill-history__emptyStateContainer___udoC8"},p().createElement(h.FAs,{className:"-esm-billing__bill-history__tile___hj7H+"},p().createElement("div",{className:"-esm-billing__bill-history__illo___SEucs"},p().createElement(d.EmptyCardIllustration,null)),p().createElement("p",{className:"-esm-billing__bill-history__content___YJZdv"},t("noBillsToDisplay","There are no bills to display.")),p().createElement(h.$nd,{onClick:()=>(0,d.launchWorkspace2)("patient-chart-billing-form-workspace",{patientUuid:e,onMutate:r}),kind:"ghost"},t("createBill","Create bill")))):p().createElement("div",null,p().createElement(d.CardHeader,{title:t("billingHistory","Billing History")},i&&p().createElement("span",null,p().createElement(h.OuH,{status:"active"})),p().createElement(h.$nd,{kind:"ghost",onClick:()=>(0,d.launchWorkspace2)("patient-chart-billing-form-workspace",{patientUuid:e,onMutate:r}),renderIcon:D.OM},t("createBill","Create bill"))),p().createElement("div",{className:"-esm-billing__bill-history__billHistoryContainer___yTHIn"},p().createElement(h.bQt,{isSortable:!0,rows:N,headers:C,size:"md",useZebraStyles:!0},({getExpandHeaderProps:a,getHeaderProps:l,getRowProps:n,getTableContainerProps:s,getTableProps:o,headers:c,rows:m})=>p().createElement(h.K3K,s,p().createElement(h.XIK,{className:"-esm-billing__bill-history__table___TYYPG",...o(),"aria-label":t("billList","Bill list")},p().createElement(h.ndF,null,p().createElement(h.Hjg,null,p().createElement(h.Uwq,{enableToggle:!0,...a()}),c.map((e,t)=>p().createElement(h.A0N,{key:t,...l({header:e})},e.header)),p().createElement(h.A0N,{"aria-label":(0,d.getCoreTranslation)("actions")}))),p().createElement(h.BFY,null,m.map((t,a)=>{let l=v.get(t.id);return p().createElement(p().Fragment,{key:t.id},p().createElement(h.fZD,n({row:t}),t.cells.map(e=>p().createElement(h.nA6,{key:e.id,className:"-esm-billing__bill-history__tableCells___ySiYL"},e.value)),p().createElement(h.nA6,{className:"cds--table-column-menu"},l?.status===K.ih.PENDING&&p().createElement(ea,{bill:l,patientUuid:e,onMutate:r}))),t.isExpanded?p().createElement(h.cwJ,{colSpan:c.length+2},p().createElement("div",{className:"-esm-billing__bill-history__container___6+v1E",key:a},p().createElement(el.A,{bill:l,onMutate:r,isLoadingBill:i}))):p().createElement(h.cwJ,{className:"-esm-billing__bill-history__hiddenRow___p94zi",colSpan:c.length+2}))}))))),s&&p().createElement(h.dKS,{forwardText:t("nextPage","Next page"),backwardText:t("previousPage","Previous page"),page:m,pageSize:E,pageSizes:f,totalItems:a.length,className:"-esm-billing__bill-history__pagination___Tosqe",size:"md",onChange:({page:e,pageSize:t})=>{e!==m&&o(e),y(t)}})))},e9),tc=(0,d.getAsyncLifecycle)(()=>a.e("9414").then(a.bind(a,501)),e9),tm=(0,d.getSyncLifecycle)(({closeModal:e,patientUuid:t})=>{let{t:a}=(0,g.useTranslation)(),{defaultCurrency:l}=(0,d.useConfig)(),{bills:n,isLoading:i}=(0,ee.u1)(t),r=n.filter(e=>e?.status!==K.ih.PAID).flatMap(e=>e?.lineItems);return p().createElement(p().Fragment,null,p().createElement(h.rQ0,{closeModal:e,title:a("patientBillingAlert","Patient Billing Alert")}),p().createElement(h.cwr,null,p().createElement("p",{className:"-esm-billing__require-payment__bodyShort02___JC8LG"},a("billPaymentRequiredMessage","The current patient has a pending bill. Advise the patient to settle the bill before receiving services")),i&&p().createElement(h.OuH,{status:"active",iconDescription:(0,d.getCoreTranslation)("loading"),description:a("loadingBillItems","Loading bill items")+"..."}),p().createElement(h.r9c,{isCondensed:!0},p().createElement(h.AVA,null,p().createElement(h.Cvq,{head:!0},p().createElement(h.Um2,{head:!0},a("item","Item")),p().createElement(h.Um2,{head:!0},a("quantity","Quantity")),p().createElement(h.Um2,{head:!0},a("unitPrice","Unit price")),p().createElement(h.Um2,{head:!0},a("total","Total")))),p().createElement(h.GRJ,null,r.map(e=>p().createElement(h.Cvq,{key:e.uuid},p().createElement(h.Um2,null,e.billableService||e.item),p().createElement(h.Um2,null,e.quantity),p().createElement(h.Um2,null,(0,F.aL)(e.price,l)),p().createElement(h.Um2,null,(0,F.aL)(e.quantity*e.price,l))))))),p().createElement(h.jlY,null,p().createElement(h.$nd,{kind:"secondary",onClick:e},(0,d.getCoreTranslation)("cancel")),p().createElement(h.$nd,{kind:"primary",onClick:e},a("ok","OK"))))},e9),tu=(0,d.getSyncLifecycle)(({closeModal:e,editPaymentMode:t})=>{let{t:a}=(0,g.useTranslation)(),{mutate:l}=(0,x.useSWRConfig)(),n=en.z.object({name:en.z.string().min(1,a("paymentModeNameRequired","Payment mode name is required")),description:en.z.string().optional()}),{control:i,handleSubmit:r,reset:s,formState:{errors:o,isSubmitting:c}}=(0,er.mN)({resolver:(0,ei.u)(n),defaultValues:{name:t?.name??"",description:t?.description??""}}),m=async n=>{let i=`${$.B}paymentMode`;try{let r={name:n.name,description:n.description};t?.uuid?await (0,A.vv)(t.uuid,r):await (0,A.cW)(r),l(e=>"string"==typeof e&&e.startsWith(i),void 0,{revalidate:!0}),(0,d.showSnackbar)({title:a("success","Success"),subtitle:a("paymentModeSaved","Payment mode was successfully saved."),kind:"success"}),e(),s({name:"",description:""})}catch(e){(0,d.showSnackbar)({title:(0,d.getCoreTranslation)("error"),subtitle:e?.message||a("errorSavingPaymentMode","An error occurred while saving the payment mode."),kind:"error",isLowContrast:!1})}};return p().createElement(p().Fragment,null,p().createElement(h.rQ0,{closeModal:e,title:t?a("editPaymentMode","Edit payment mode"):a("addPaymentMode","Add payment mode")}),p().createElement(h.lVW,{onSubmit:r(m)},p().createElement(h.cwr,null,p().createElement(h.BJc,{gap:5},p().createElement(er.xI,{name:"name",control:i,render:({field:e})=>p().createElement(h.ksK,{id:"payment-mode-name",labelText:a("paymentModeNameLabel","Payment mode name"),placeholder:a("paymentModeNamePlaceholder","For example, Cash, Credit Card"),invalid:!!o.name,invalidText:o.name?.message,...e})}),p().createElement(er.xI,{name:"description",control:i,render:({field:e})=>p().createElement(h.ksK,{id:"payment-mode-description",labelText:a("description","Description"),placeholder:a("descriptionPlaceholder","For example, Used for all cash transactions"),invalid:!!o.description,invalidText:o.description?.message,...e})}))),p().createElement(h.jlY,null,p().createElement(h.$nd,{kind:"secondary",onClick:e},(0,d.getCoreTranslation)("cancel")),p().createElement(h.$nd,{type:"submit",disabled:c},c?a("saving","Saving")+"...":(0,d.getCoreTranslation)("save")))))},e9),td=(0,d.getSyncLifecycle)(({closeModal:e,paymentModeUuid:t,paymentModeName:a})=>{let{t:l}=(0,g.useTranslation)(),{mutate:n}=(0,x.useSWRConfig)(),[i,r]=(0,_.useState)(!1),s=async()=>{r(!0);let a=`${$.B}paymentMode`;try{await (0,d.openmrsFetch)(`${d.restBaseUrl}/billing/paymentMode/${t}`,{method:"DELETE"}),n(e=>"string"==typeof e&&e.startsWith(a),void 0,{revalidate:!0}),(0,d.showSnackbar)({title:l("success","Success"),subtitle:l("paymentModeDeleted","Payment mode was successfully deleted."),kind:"success"}),e()}catch(e){(0,d.showSnackbar)({title:(0,d.getCoreTranslation)("error"),subtitle:e?.message||l("errorDeletingPaymentMode","An error occurred while deleting the payment mode."),kind:"error",isLowContrast:!1})}finally{r(!1)}};return p().createElement(p().Fragment,null,p().createElement(h.rQ0,{closeModal:e,title:l("deletePaymentMode","Delete Payment Mode")}),p().createElement(h.cwr,null,p().createElement("p",null,l("confirmDeleteMessage","Are you sure you want to delete this payment mode? Proceed cautiously.")),a&&p().createElement("p",null,p().createElement("strong",null,l("paymentModeNameToDelete","Payment Mode Name: {{paymentModeName}}",{paymentModeName:a})))),p().createElement(h.jlY,null,p().createElement(h.$nd,{kind:"secondary",onClick:e},(0,d.getCoreTranslation)("cancel")),p().createElement(h.$nd,{kind:"danger",onClick:s,disabled:i},i?l("deleting","Deleting")+"...":(0,d.getCoreTranslation)("delete"))))},e9),t_=(0,d.getSyncLifecycle)(({closeModal:e,onCashPointAdded:t})=>{let{t:a}=(0,g.useTranslation)(),[l,n]=(0,_.useState)([]),i=en.z.object({name:en.z.string().min(1,a("cashPointNameRequired","Cash Point Name is required")),uuid:en.z.string().min(1,a("uuidRequired","UUID is required")).regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,a("invalidUuidFormat","Invalid UUID format")),location:en.z.string().min(1,a("locationRequired","Location is required"))}),{control:r,handleSubmit:s,reset:o,formState:{errors:c,isSubmitting:m}}=(0,er.mN)({resolver:(0,ei.u)(i),defaultValues:{name:"",uuid:"",location:""}}),u=(0,_.useCallback)(async()=>{try{let e=(await (0,d.openmrsFetch)(`${d.restBaseUrl}/location?v=default`)).data.results.map(e=>({id:e.uuid,label:e.display}));n(e)}catch(e){(0,d.showSnackbar)({title:(0,d.getCoreTranslation)("error"),subtitle:a("errorFetchingLocations","An error occurred while fetching locations."),kind:"error",isLowContrast:!1})}},[a]);(0,_.useEffect)(()=>{u()},[u]);let b=async l=>{try{await (0,d.openmrsFetch)(`${d.restBaseUrl}/billing/cashPoint`,{method:"POST",headers:{"Content-Type":"application/json"},body:{name:l.name,uuid:l.uuid,location:{uuid:l.location}}}),(0,d.showSnackbar)({title:a("success","Success"),subtitle:a("cashPointSaved","Cash point was successfully saved."),kind:"success"}),e(),o({name:"",uuid:"",location:""}),t()}catch(e){(0,d.showSnackbar)({title:(0,d.getCoreTranslation)("error"),subtitle:e?.message||a("errorSavingCashPoint","An error occurred while saving the cash point."),kind:"error",isLowContrast:!1})}};return p().createElement(p().Fragment,null,p().createElement(h.rQ0,{closeModal:e,title:a("addCashPoint","Add Cash Point")}),p().createElement(h.lVW,{onSubmit:s(b)},p().createElement(h.cwr,null,p().createElement(h.BJc,{gap:5},p().createElement(er.xI,{name:"name",control:r,render:({field:e})=>p().createElement(h.ksK,{id:"cash-point-name",labelText:a("cashPointName","Cash Point Name"),placeholder:a("cashPointNamePlaceholder","For example, Pharmacy Cash Point"),invalid:!!c.name,invalidText:c.name?.message,...e})}),p().createElement(er.xI,{name:"uuid",control:r,render:({field:e})=>p().createElement(h.ksK,{id:"cash-point-uuid",labelText:a("cashPointUuid","Cash Point UUID"),placeholder:a("cashPointUuidPlaceholder","Enter UUID"),invalid:!!c.uuid,invalidText:c.uuid?.message,...e})}),p().createElement(er.xI,{name:"location",control:r,render:({field:e})=>p().createElement(h.msM,{id:"cash-point-location",label:a("selectLocation","Select Location"),titleText:a("cashPointLocation","Cash Point Location"),items:l,selectedItem:l.find(t=>t.id===e.value),onChange:({selectedItem:t})=>e.onChange(t?.id),invalid:!!c.location,invalidText:c.location?.message})}))),p().createElement(h.jlY,null,p().createElement(h.$nd,{kind:"secondary",onClick:e},(0,d.getCoreTranslation)("cancel")),p().createElement(h.$nd,{type:"submit",disabled:m},m?a("saving","Saving")+"...":(0,d.getCoreTranslation)("save")))))},e9),tp=(0,d.getSyncLifecycle)(({bill:e,closeModal:t,item:a,onMutate:l})=>{let{t:n}=(0,g.useTranslation)(),{defaultCurrency:i}=(0,d.useConfig)(),{billableServices:r}=(0,A.ly)(),[s,o]=(0,_.useState)(0),c=(0,_.useMemo)(()=>en.z.object({quantity:en.z.coerce.number({required_error:n("quantityRequired","Quantity is required"),invalid_type_error:n("quantityMustBeNumber","Quantity must be a valid number")}).int(n("quantityMustBeInteger","Quantity must be a whole number")).min(1,n("quantityMustBeAtLeastOne","Quantity must be at least 1")).max(100,n("quantityCannotExceed100","Quantity cannot exceed 100")),price:en.z.coerce.number({required_error:n("priceIsRequired","Price is required"),invalid_type_error:n("priceMustBeNumber","Price must be a valid number")}).min(0,n("priceMustBeNonNegative","Price must be 0 or greater"))}),[n]),{control:m,handleSubmit:u,formState:{isSubmitting:b,errors:E},watch:y}=(0,er.mN)({defaultValues:{quantity:a.quantity,price:a.price},resolver:(0,ei.u)(c)}),f=y("quantity"),v=y("price");(0,_.useEffect)(()=>{let e=("number"==typeof f?f:parseFloat(f)||0)*("number"==typeof v?v:parseFloat(v)||0);o(isNaN(e)?0:e)},[f,v]);let C=async i=>{let s={...a,quantity:i.quantity,price:i.price,billableService:(0,ed.e)(r,a.billableService),item:a?.item},o=(e?.lineItems.filter(e=>e.uuid!==a?.uuid).map(e=>({...e,billableService:(0,ed.e)(r,e.billableService)}))).concat(s),c={cashPoint:e.cashPointUuid,cashier:e.cashier.uuid,lineItems:o,patient:e.patientUuid,status:e.status,uuid:e.uuid};try{await (0,ee.FR)(c),l?.(),(0,d.showSnackbar)({title:n("lineItemUpdated","Line item updated"),subtitle:n("lineItemUpdateSuccess","The bill line item has been updated successfully"),kind:"success"}),t()}catch(e){(0,d.showSnackbar)({title:n("lineItemUpdateFailed","Failed to update line item"),subtitle:e?.message||n("lineItemUpdateErrorDefault","Unable to update the bill line item. Please try again."),kind:"error"})}};return Object.keys(e)?.length===0?p().createElement(h.rQ0,{closeModal:t,title:n("billLineItemEmpty","This bill has no line items")}):p().createElement(p().Fragment,null,p().createElement(h.rQ0,{closeModal:t,title:n("editBillLineItem","Edit bill line item")}),p().createElement(h.lVW,{onSubmit:u(C)},p().createElement(h.cwr,null,p().createElement(h.BJc,{gap:5},p().createElement("div",{className:e_.modalBody},p().createElement("div",{className:e_.billInfo},e?.patientName,p().createElement("span",{className:e_.separator},"\xb7"),e?.cashPointName,p().createElement("span",{className:e_.separator},"\xb7"),e?.receiptNumber)),p().createElement("section",null,p().createElement("p",{className:e_.label},n("item","Item"),": ",a?.billableService?a?.billableService:a?.item),p().createElement("p",{className:e_.label},n("currentPrice","Current price"),": ",(0,F.aL)(a?.price,i)),p().createElement("p",{className:e_.label},n("serviceStatus","Service status"),": ",a?.status),p().createElement(er.xI,{name:"quantity",control:m,render:({field:{onChange:e,value:t}})=>p().createElement(h.Q7x,{allowEmpty:!0,disableWheel:!0,className:e_.controlField,hideSteppers:!0,id:"quantityInput",invalid:!!E.quantity,invalidText:E.quantity?.message,label:n("quantity","Quantity"),onChange:(t,a)=>{e(a.value)},value:t})}),p().createElement(er.xI,{name:"price",control:m,render:({field:{value:e}})=>p().createElement(h.ksK,{className:e_.controlField,helperText:n("unitPriceHelperText","This is the unit price for this item"),id:"priceInput",labelText:n("unitPrice","Unit price"),readOnly:!0,value:e})}),p().createElement("p",{className:e_.label,"aria-live":"polite"},n("total","Total"),": ",(0,F.aL)(s,i))))),p().createElement(h.jlY,null,p().createElement(h.$nd,{kind:"secondary",onClick:t},(0,d.getCoreTranslation)("cancel")),p().createElement(h.$nd,{type:"submit",disabled:b},b?p().createElement("div",{className:e_.inline},p().createElement(h.OuH,{className:e_.loader,description:`${n("submitting","Submitting")}...`})):(0,d.getCoreTranslation)("save")))))},e9),tb=(0,d.getSyncLifecycle)(()=>{let e=window.getOpenmrsSpaBase()+"home/billing";return p().createElement(E.Kd,{basename:e},p().createElement(b.BV,null,p().createElement(b.qh,{path:"/",element:p().createElement(eq,null)}),p().createElement(b.qh,{path:"/patient/:patientUuid/:billUuid",element:p().createElement(e2,null)})))},e9),tE=(0,d.getSyncLifecycle)(({patientUuid:e})=>{let t=(0,ee.Vs)(e);return p().createElement("div",null,t?.map(e=>p().createElement(p().Fragment,{key:e.name},p().createElement(h.vwO,{type:"gray"},e.name),p().createElement(h.vwO,{type:"cool-gray"},e.value))))},e9),tg=(0,d.getSyncLifecycle)(({patientUuid:e,renderedFrom:t})=>"patient-chart"!==t?null:p().createElement(e4,{patientUuid:e}),e9),ty=(0,d.getAsyncLifecycle)(()=>a.e("1899").then(a.bind(a,662)),e9),th=(0,d.getAsyncLifecycle)(()=>a.e("3784").then(a.bind(a,8843)),e9),tf=(0,d.getSyncLifecycle)((n={name:"billable-services",title:"billableServices",path:"",icon:o.uW},()=>p().createElement(E.Kd,null,p().createElement(f,{config:n}))),e9),tv=(0,d.getSyncLifecycle)((i={title:"billingSettings",icon:c.wB,privilege:"coreapps.systemAdministration",items:[{name:"cash-point-config",title:"cashPointConfig",path:"cash-point-config"},{name:"payment-modes-config",title:"paymentModesConfig",path:"payment-modes-config"}]},()=>p().createElement(E.Kd,null,p().createElement(v,{config:i}))),e9),tC=(0,d.getAsyncLifecycle)(()=>a.e("1564").then(a.bind(a,6903)),e9),tN=(0,d.getAsyncLifecycle)(()=>a.e("5390").then(a.bind(a,4829)),e9),tT=(0,d.getAsyncLifecycle)(()=>a.e("7247").then(a.bind(a,8402)),e9),tS=(0,d.getSyncLifecycle)(({closeModal:e,bill:t,lineItem:a,onMutate:l})=>{let{t:n}=(0,g.useTranslation)(),{defaultCurrency:i}=(0,d.useConfig)(),[r,s]=(0,_.useState)(K.Bp.PERCENTAGE),[o,c]=(0,_.useState)(null),[m,u]=(0,_.useState)(""),[b,E]=(0,_.useState)(!1),y=!!a,f=a?.total??t.total,v=m.trim(),C=null!=o&&!Number.isNaN(o)&&o>0?r===K.Bp.PERCENTAGE?f*o/100:o:null,N=y?n("lineItemJustificationPlaceholder","e.g., damaged item, wrong quantity billed, expired stock"):n("billJustificationPlaceholder","e.g., hardship assistance, charity case, write-off"),T=m.length>1e3?n("justificationTooLong","Justification cannot exceed 1000 characters"):null,S=null==o||Number.isNaN(o)?null:o<=0?n("valueMustBePositive","Value must be greater than 0"):r===K.Bp.PERCENTAGE&&o>100?n("percentageTooHigh","Percentage cannot exceed 100"):null==C?null:C>t.amountDue?n("discountExceedsAmountDue","Discount cannot exceed the amount due"):a&&C>a.total?n("discountExceedsLineTotal","Discount cannot exceed the line item total"):null,k=!b&&null!=o&&v.length>0&&!T&&!S,D=async()=>{if(k&&null!=o){E(!0);try{await O({bill:t.uuid,lineItem:a?.uuid,discountType:r,discountValue:o,justification:v}),l?.(),(0,d.showSnackbar)({title:n("discountRequested","Discount request submitted"),subtitle:n("discountPendingReview","An admin will review your request"),kind:"success"}),e()}catch(t){let e=t?.responseBody?.error?.message??(t instanceof Error?t.message:void 0);(0,d.showSnackbar)({title:n("discountRequestFailed","Could not submit discount request"),subtitle:e,kind:"error"})}finally{E(!1)}}};return p().createElement(p().Fragment,null,p().createElement(h.rQ0,{closeModal:e,title:n("requestDiscount","Request discount")}),p().createElement(h.cwr,{className:"-esm-billing__request-discount-modal__modalBody___GBnye"},p().createElement(h.BJc,{gap:5},p().createElement("section",{className:"-esm-billing__request-discount-modal__scopePanel___3guqY","aria-label":n("discountScope","Discount scope")},p().createElement("div",{className:"-esm-billing__request-discount-modal__scopePrimary___Y71Gc"},y?a.display:n("wholeBillScope","Whole bill")),p().createElement("ul",{className:"-esm-billing__request-discount-modal__scopeMeta___xrhxy"},t.receiptNumber&&p().createElement("li",null,n("invoiceLabel","Invoice {{number}}",{number:t.receiptNumber})),y&&null!=a.quantity&&null!=a.price&&p().createElement("li",null,n("qtyTimesPrice","Qty {{quantity}} \xd7 {{price}}",{quantity:a.quantity,price:(0,F.aL)(a.price,i)})),!y&&null!=t.lineItemCount&&p().createElement("li",null,n("lineItemCount","{{count}} line items",{count:t.lineItemCount})),p().createElement("li",{className:"-esm-billing__request-discount-modal__scopeTotal___2e1eb"},y?n("lineTotalLabel","Line total {{total}}",{total:(0,F.aL)(f,i)}):n("billTotalLabel","Bill total {{total}}",{total:(0,F.aL)(f,i)})))),p().createElement(h.gE_,{legendText:n("discount","Discount"),className:"-esm-billing__request-discount-modal__discountGroup___qyLxM"},p().createElement(h.BJc,{gap:4},p().createElement(h.zWQ,{legendText:"",name:"discount-type",valueSelected:r,onChange:e=>s(e)},p().createElement(h.aaP,{labelText:n("percentage","Percentage"),value:K.Bp.PERCENTAGE}),p().createElement(h.aaP,{labelText:n("fixedAmount","Fixed amount"),value:K.Bp.FIXED_AMOUNT})),p().createElement(h.Q7x,{id:"discount-value",label:r===K.Bp.PERCENTAGE?n("valuePercentLabel","Value (%)"):n("valueAmountLabel","Value ({{currency}})",{currency:i}),allowEmpty:!0,min:0,value:o??"",invalid:!!S,invalidText:S??"",onChange:(e,{value:t})=>{if(""===t||null==t)return void c(null);let a="string"==typeof t?parseFloat(t):t;c(Number.isNaN(a)?null:a)}}))),null!=C&&p().createElement("section",{className:"-esm-billing__request-discount-modal__summaryCard___BjITg","aria-label":n("discountSummary","Discount summary")},p().createElement("span",{className:ep},y?n("lineTotal","Line total"):n("billTotal","Bill total")),p().createElement("span",{className:eb},(0,F.aL)(f,i)),p().createElement("span",{className:ep},r===K.Bp.PERCENTAGE&&null!=o?n("discountWithPercent","Discount ({{percent}}%)",{percent:o}):n("discountLabel","Discount")),p().createElement("span",{className:`${eb} -esm-billing__request-discount-modal__summaryDiscount___REJ5I`},"−",(0,F.aL)(C,i)),y&&p().createElement(p().Fragment,null,p().createElement("span",{className:ep},n("lineAfterDiscount","Line after discount")),p().createElement("span",{className:eb},(0,F.aL)(f-C,i))),p().createElement("span",{className:"-esm-billing__request-discount-modal__summaryDivider___2nBbX","aria-hidden":"true"}),p().createElement("span",{className:ep},n("outstanding","Outstanding")),p().createElement("span",{className:eb},(0,F.aL)(t.amountDue,i)),p().createElement("span",{className:"-esm-billing__request-discount-modal__summaryTotalLabel___9ESne"},n("amountDueOnBillAfterDiscount","Amount due on bill after discount")),p().createElement("span",{className:"-esm-billing__request-discount-modal__summaryTotalValue___Cwkmg"},(0,F.aL)(t.amountDue-C,i))),p().createElement(h.fs1,{id:"discount-justification",labelText:n("justification","Justification"),placeholder:N,maxCount:1e3,enableCounter:!0,required:!0,rows:3,value:m,invalid:!!T,invalidText:T??"",onChange:e=>u(e.target.value)}))),p().createElement(h.jlY,null,p().createElement(h.$nd,{kind:"secondary",onClick:e},(0,d.getCoreTranslation)("cancel")),p().createElement(h.$nd,{kind:"primary",onClick:D,disabled:!k},b?p().createElement(h.OuH,{description:n("submitting","Submitting")+"..."}):p().createElement("span",null,n("submitRequest","Submit request")))))},e9),tk=(0,d.getSyncLifecycle)(({closeModal:e,bill:t,onMutate:a})=>{let l,n,i,r,s,o,c,m,u,{t:b}=(0,g.useTranslation)(),E=(0,d.useSession)(),{bill:y,mutate:f,isLoading:v,isValidating:C}=(0,ee.DX)(t.uuid,!1),N=y??t,[T,S]=(0,_.useState)(null),[k,D]=(0,_.useState)(null),[A,P]=(0,_.useState)(null),w=N.status===K.ih.PENDING||N.status===K.ih.POSTED,{pendingDiscounts:I,confirmedDiscounts:L,approvedDiscounts:M,lineItems:B,payments:R,paymentsTotal:q,subtotal:F,currentNet:x,outstanding:j}=(n=(l=(0,_.useMemo)(()=>(N.discounts??[]).filter(e=>!e.voided),[N.discounts])).filter(e=>e.status===K.nT.PENDING),i=l.filter(e=>e.status!==K.nT.PENDING),r=l.filter(e=>e.status===K.nT.APPROVED),s=(N.lineItems??[]).filter(e=>!e.voided),c=(o=(N.payments??[]).filter(e=>!e.voided)).reduce((e,t)=>e+(t.amountTendered??0),0),m=N.total,{activeDiscounts:l,pendingDiscounts:n,confirmedDiscounts:i,approvedDiscounts:r,lineItems:s,payments:o,paymentsTotal:c,subtotal:m,currentNet:u=N.amountAfterDiscount,outstanding:u-c}),$=(0,_.useCallback)(async e=>{if(w){if(j-e.discountAmount<0)return void(0,d.showSnackbar)({title:b("approveBlocked","Cannot approve discount"),subtitle:b("approveBlockedNegativeDue","Approving this discount would push the amount due below zero."),kind:"error"});S(e.uuid);try{await z(e.uuid,K.nT.APPROVED,E.user.uuid),(0,d.showSnackbar)({title:b("discountApproved","Discount approved"),kind:"success"}),await f(),a()}catch(e){(0,d.showSnackbar)({title:b("approveFailed","Approve failed"),subtitle:eL(e),kind:"error"})}finally{S(null)}}},[w,j,b,E.user.uuid,f,a]),U=(0,_.useCallback)(async e=>{if(w){S(e.uuid);try{await z(e.uuid,K.nT.REJECTED,E.user.uuid),(0,d.showSnackbar)({title:b("discountRejected","Discount rejected"),kind:"success"}),await f(),a()}catch(e){(0,d.showSnackbar)({title:b("rejectFailed","Reject failed"),subtitle:eL(e),kind:"error"})}finally{S(null),D(null)}}},[w,b,E.user.uuid,f,a]),H=(0,_.useCallback)(async e=>{if(e.status===K.nT.APPROVED&&j<=0){(0,d.showSnackbar)({title:b("deleteBlocked","Cannot delete discount"),subtitle:b("deleteBlockedFullyPaid","An approved discount cannot be removed once the bill is fully paid."),kind:"error"}),P(null);return}S(e.uuid);try{await V(e.uuid,"Deleted by admin"),(0,d.showSnackbar)({title:b("discountDeleted","Discount deleted"),kind:"success"}),await f(),a()}catch(e){(0,d.showSnackbar)({title:b("deleteFailed","Delete failed"),subtitle:eL(e),kind:"error"})}finally{S(null),P(null)}},[j,b,f,a]),O=(0,_.useCallback)(()=>D(null),[]),W=(0,_.useCallback)(()=>P(null),[]),G=!!T||v||C;return p().createElement(p().Fragment,null,p().createElement(h.rQ0,{closeModal:e,title:b("reviewDiscounts","Review discounts")}),p().createElement(h.cwr,null,G?p().createElement(h.z21,{label:"",hideLabel:!0}):p().createElement("div",{className:"-esm-billing__review-bill-discounts-modal__layout___gF7VM"},p().createElement(eN,{bill:N,lineItems:B,payments:R,paymentsTotal:q,subtotal:F,currentNet:x,outstanding:j,approvedDiscounts:M,pendingDiscounts:I}),p().createElement(eI,{pendingDiscounts:I,confirmedDiscounts:L,lineItems:B,busy:T,rejectingId:k,deletingId:A,canDecide:w,onApprove:$,onStartReject:D,onCancelReject:O,onConfirmReject:U,onStartDelete:P,onCancelDelete:W,onConfirmDelete:H}))))},e9),tD=(0,d.getSyncLifecycle)((r={name:"discount-requests",title:"discountRequests",path:"discount-requests",icon:m.CR},()=>p().createElement(E.Kd,null,p().createElement(C,{config:r}))),e9),tA=(0,d.getAsyncLifecycle)(()=>a.e("6594").then(a.bind(a,3785)),e9),tP=(0,d.getAsyncLifecycle)(()=>a.e("2269").then(a.bind(a,2220)),e9),tw=(0,d.getSyncLifecycle)((s={name:"refund-requests",title:"refundRequests",path:"refund-requests",icon:u.ds},()=>p().createElement(E.Kd,null,p().createElement(N,{config:s}))),e9)},6762(e,t,a){"use strict";a.d(t,{A:()=>g});var l=a(5275),n=a.n(l),i=a(6942),r=a.n(i),s=a(8395),o=a(4751),c=a.n(o),m=a(6800),u=a(3137),d=a(5084);let _="-esm-billing__line-item-action-menu__menuitem___lOuJD",p=({bill:e,item:t,onMutate:a,showDiscountRequest:i,onDiscountRequest:r,showRefundRequest:o,onRefundRequest:c})=>{let{t:p}=(0,s.useTranslation)(),b=(0,u.useLayoutType)(),E=(0,l.useCallback)(()=>{let l=(0,u.showModal)("edit-bill-line-item-modal",{bill:e,item:t,closeModal:()=>l(),onMutate:a})},[e,t,a]),g=(0,l.useCallback)(()=>{let e=(0,u.showModal)("delete-line-item-confirmation-modal",{item:t,closeModal:()=>e(),onMutate:a})},[t,a]),y=e?.status===d.ih.PENDING;return n().createElement(m.Wdr,null,n().createElement(m.obU,{align:"left",flipped:!0,size:(0,u.isDesktop)(b)?"sm":"lg","data-testid":`action-menu-${t.uuid}`},n().createElement(m.XSD,{className:_,"data-testid":`edit-button-${t.uuid}`,disabled:!y,itemText:(0,u.getCoreTranslation)("edit"),onClick:E}),n().createElement(m.XSD,{className:_,"data-testid":`delete-button-${t.uuid}`,disabled:!y,isDelete:!0,itemText:(0,u.getCoreTranslation)("delete"),onClick:g}),i&&n().createElement(m.XSD,{className:_,"data-testid":`request-discount-button-${t.uuid}`,itemText:p("requestDiscount","Request discount"),onClick:r}),o&&n().createElement(m.XSD,{className:_,"data-testid":`request-refund-button-${t.uuid}`,itemText:p("requestRefund","Request refund"),onClick:c})))};var b=a(1772);let E=e=>(e.price??0)*(e.quantity??0),g=({bill:e,isLoadingBill:t,onMutate:a,viewOnly:i})=>{let{t:o}=(0,s.useTranslation)(),{defaultCurrency:_}=(0,u.useConfig)(),g=(0,u.useLayoutType)(),y=(0,l.useMemo)(()=>e?.lineItems??[],[e?.lineItems]),h=(0,u.isDesktop)(g)?"sm":"lg",[f,v]=(0,l.useState)(""),C=(0,u.useDebounce)(f),N=(0,l.useMemo)(()=>(e?.discounts??[]).filter(e=>!e.voided),[e?.discounts]),T=e?.status===d.ih.PENDING||e?.status===d.ih.POSTED,S=N.some(e=>!e.lineItemUuid),k=(0,l.useMemo)(()=>(e?.refunds??[]).filter(e=>!e.voided),[e?.refunds]),D=e?.status===d.ih.PAID||e?.status===d.ih.PARTIALLY_REFUNDED||e?.status===d.ih.REFUND_REQUESTED,A=k.filter(e=>e.status===d.fH.REQUESTED||e.status===d.fH.APPROVED),P=A.some(e=>!e.lineItemUuid),w=(0,l.useMemo)(()=>C?c().filter(C,y,{extract:e=>`${e.billableService} ${e.item}`}).sort((e,t)=>e.score-t.score).map(e=>e.original):y,[C,y]),I=(0,l.useMemo)(()=>new Map(y.map(e=>[e.uuid,e])),[y]),L=[{header:o("number","Number"),key:"no",width:7},{header:o("billItem","Bill item"),key:"billItem",width:25},{header:o("status","Status"),key:"status",width:25},{header:o("quantity","Quantity"),key:"quantity",width:15},{header:o("price","Price"),key:"price",width:24},{header:o("total","Total"),key:"total",width:15}],M=(0,l.useMemo)(()=>w?.map((e,t)=>({no:`${t+1}`,id:`${e.uuid}`,billItem:e.billableService?e.billableService:e?.item,status:e.status,quantity:e.quantity,price:(0,b.aL)(e.price,_),total:(0,b.aL)(E(e),_)}))??[],[w,_]);return t?n().createElement(m.OOb,{"data-testid":"loader",columnCount:L.length,showHeader:!1,showToolbar:!1,zebra:!0}):n().createElement("div",{className:"-esm-billing__invoice-table__lineItemsWrapper___ABU3I"},n().createElement(m.bQt,{headers:L,rows:M,size:h,useZebraStyles:!0,overflowMenuOnHover:(0,u.isDesktop)(g)},({rows:t,headers:l,getRowProps:s,getTableProps:c})=>n().createElement(m.K3K,{description:n().createElement("span",{className:"-esm-billing__invoice-table__tableDescription___JKz3j"},n().createElement("span",null,o("itemsToBeBilled","Items to be billed"))),title:o("lineItems","Line items")},!i&&n().createElement(m.w6V,{className:"-esm-billing__invoice-table__searchbox___oxEnj",expanded:!0,onChange:e=>v(e.target.value),placeholder:o("searchThisTable","Search this table"),size:h}),n().createElement(m.XIK,{...c(),"aria-label":o("invoiceLineItems","Invoice line items"),className:r()("-esm-billing__invoice-table__invoiceTable___2hd71","billingTable")},n().createElement(m.ndF,null,n().createElement(m.Hjg,null,l.map(e=>n().createElement(m.A0N,{key:e.key},e.header)),!i&&n().createElement(m.A0N,{"aria-label":(0,u.getCoreTranslation)("actions")}))),n().createElement(m.BFY,null,t.map(t=>{let l,r,o=I.get(t.id);return n().createElement(m.Hjg,{key:t.id,...s({row:t})},t.cells.map(e=>n().createElement(m.nA6,{key:e.id},e.value)),!i&&n().createElement(m.nA6,{className:"cds--table-column-menu"},o&&n().createElement(p,{bill:e,item:o,onMutate:a,showDiscountRequest:T&&!S&&(l=o.uuid,!N.some(e=>e.lineItemUuid===l)),onDiscountRequest:()=>{let t;t=(0,u.showModal)("request-discount-modal",{bill:{uuid:e.uuid,total:e.totalAmount??0,amountDue:Math.max(0,(e.netAmount??e.totalAmount??0)-(e.tenderedAmount??0)),receiptNumber:e.receiptNumber,lineItemCount:y.length},lineItem:{uuid:o.uuid,display:o.item||o.billableService||"--",total:E(o),quantity:o.quantity,price:o.price},onMutate:()=>a?.(),closeModal:()=>t()})},showRefundRequest:D&&!P&&(r=o.uuid??"",!A.some(e=>e.lineItemUuid===r))&&!!o.uuid,onRefundRequest:()=>(t=>{if(!t.uuid)return;let l=E(t),n=l-k.filter(e=>e.lineItemUuid===t.uuid&&(e.status===d.fH.APPROVED||e.status===d.fH.COMPLETED)).reduce((e,t)=>e+t.refundAmount,0),i=(0,u.showModal)("request-refund-modal",{bill:{uuid:e.uuid,total:e.totalAmount??0,amountAfterDiscount:e.netAmount??e.totalAmount??0},lineItem:{uuid:t.uuid,display:t.item||t.billableService||"--",total:l,quantity:t.quantity,price:t.price},remainingRefundable:Math.max(0,n),onMutate:()=>a?.(),closeModal:()=>i()})})(o)})))}))))),w?.length===0&&n().createElement("div",{className:"-esm-billing__invoice-table__filterEmptyState___ZtVBH"},n().createElement(m.Wdr,null,n().createElement(m.FAs,{className:"-esm-billing__invoice-table__filterEmptyStateTile___j92yY"},n().createElement("p",{className:"-esm-billing__invoice-table__filterEmptyStateContent___41NoP"},o("noMatchingItemsToDisplay","No matching items to display")),!i&&n().createElement("p",{className:"-esm-billing__invoice-table__filterEmptyStateHelper___+DQR2"},o("checkFilters","Check the filters above"))))))}},7661(e,t,a){"use strict";a.d(t,{e:()=>l});let l=(e,t)=>{if(!e.length)return null;let a=e.find(e=>e.name===t);return a?.uuid??null}},8683(e,t,a){"use strict";a.d(t,{KY:()=>s,eK:()=>c,qC:()=>o,zb:()=>m});var l=a(3137),n=a(7003);let i=`${n.B}billRefund`,r=`${n.B}bill`;function s({statuses:e}){let t=new URLSearchParams({refundStatus:e.join(","),v:"default"}),a=`${r}?${t.toString()}`,{data:n,isLoading:i,error:o,mutate:c,isValidating:m}=(0,l.useOpenmrsFetchAll)(a);return{bills:n??[],isLoading:i,error:o,mutate:c,isValidating:m}}async function o(e){return(await (0,l.openmrsFetch)(i,{method:"POST",headers:{"Content-Type":"application/json"},body:e})).data}async function c(e,t){return(await (0,l.openmrsFetch)(`${i}/${e}`,{method:"POST",headers:{"Content-Type":"application/json"},body:t})).data}async function m(e,t){await (0,l.openmrsFetch)(`${i}/${e}?reason=${encodeURIComponent(t)}`,{method:"DELETE"})}},5084(e,t,a){"use strict";a.d(t,{Bp:()=>r,fH:()=>s,ih:()=>l,nT:()=>i,zk:()=>n});let l={PENDING:"PENDING",POSTED:"POSTED",PAID:"PAID",ADJUSTED:"ADJUSTED",PARTIALLY_REFUNDED:"PARTIALLY_REFUNDED",REFUNDED:"REFUNDED",REFUND_REQUESTED:"REFUND_REQUESTED"},n={PENDING:"PENDING",PAID:"PAID",CANCELLED:"CANCELLED",ADJUSTED:"ADJUSTED",EXEMPTED:"EXEMPTED",REFUND_REQUESTED:"REFUND_REQUESTED",REFUNDED:"REFUNDED",PARTIALLY_REFUNDED:"PARTIALLY_REFUNDED"},i={PENDING:"PENDING",APPROVED:"APPROVED",REJECTED:"REJECTED"},r={PERCENTAGE:"PERCENTAGE",FIXED_AMOUNT:"FIXED_AMOUNT"},s={REQUESTED:"REQUESTED",APPROVED:"APPROVED",REJECTED:"REJECTED",COMPLETED:"COMPLETED"}}}]);