@openmrs/esm-billing-app 1.3.2-pre.2041 → 1.3.2-pre.2046
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/.turbo/cache/b0d19e990e22d393-meta.json +1 -0
- package/.turbo/cache/b0d19e990e22d393.tar.zst +0 -0
- package/.turbo/turbo-build.log +2 -2
- package/dist/1578.js +1 -1
- package/dist/1578.js.map +1 -1
- package/dist/1899.js +1 -1
- package/dist/196.js +1 -1
- package/dist/2322.js +1 -1
- package/dist/2450.js +10 -10
- package/dist/2450.js.map +1 -1
- package/dist/3517.js +1 -0
- package/dist/3517.js.map +1 -0
- package/dist/5898.js +1 -1
- package/dist/5898.js.map +1 -1
- package/dist/6029.js +1 -0
- package/dist/6029.js.map +1 -0
- package/dist/6362.js +1 -1
- package/dist/6362.js.map +1 -1
- package/dist/7977.js +1 -0
- package/dist/7977.js.map +1 -0
- package/dist/8410.js +1 -0
- package/dist/8410.js.map +1 -0
- package/dist/9197.js +1 -0
- package/dist/9197.js.map +1 -0
- package/dist/990.js +1 -1
- package/dist/openmrs-esm-billing-app.js +2 -2
- package/dist/openmrs-esm-billing-app.js.buildmanifest.json +168 -102
- package/dist/openmrs-esm-billing-app.js.map +1 -1
- package/dist/routes.json +1 -1
- package/package.json +2 -2
- package/.turbo/cache/8a5f534e063b7d0a-meta.json +0 -1
- package/.turbo/cache/8a5f534e063b7d0a.tar.zst +0 -0
- package/dist/5789.js +0 -1
- package/dist/5789.js.map +0 -1
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:()=>o,OS:()=>d,WJ:()=>c,bb:()=>m,cW:()=>_,j2:()=>u,ly:()=>s,vv:()=>b});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"}})},b=(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:()=>b,FR:()=>f,LM:()=>N,N7:()=>S,TS:()=>p,Vs:()=>g,Xn:()=>h,Z5:()=>T,eC:()=>E,fu:()=>d,ly:()=>y,mi:()=>C,u1:()=>_,yj:()=>v});var l=a(2914),n=a.n(l),i=a(6734),r=a.n(i),s=a(3139),o=a(3137),c=a(7003),m=a(5084);let u=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)}},d=(e,t,a,l,n)=>{let i=`${c.B}bill?v=custom:(id,uuid,dateCreated,status,receiptNumber,patient:(uuid,display),lineItems:(uuid,item,billableService,voided))&pageSize=${e}`;t&&(i+=`&status=${t}`),a&&(i+=`&patientName=${encodeURIComponent(a)}`),l&&(i+=`&startDate=${encodeURIComponent(r()(l).startOf("day").format(c.U))}`),n&&(i+=`&endDate=${encodeURIComponent(r()(n).endOf("day").format(c.U))}`);let s=!l||!n||l<=n,{data:m,error:d,isLoading:_,isValidating:b,mutate:p,currentPage:E,totalCount:g,goTo:y}=(0,o.useOpenmrsPagination)(s?i:null,e);return{bills:m?.map(e=>u(e))??[],error:d,isLoading:_,isValidating:b,mutate:p,currentPage:E,totalCount:g,goTo:y}},_=(e,t,a)=>{let l=`${c.B}bill?v=full`;e&&(l+=`&patientUuid=${e}`),t&&(l+=`&status=${t}`),a&&(l+=`&visitUuid=${a}`);let{data:n,error:i,isLoading:r,isValidating:m,mutate:d}=(0,o.useOpenmrsFetchAll)(l),_=(0,s.A)(n??[],["dateCreated"]).reverse();return{bills:_?.map(e=>u(e)),error:i,isLoading:r,isValidating:m,mutate:d}};function b(e,t=!0){let a=`${c.B}bill/${e}`,{data:l,error:i,isLoading:r,isValidating:s,mutate:m}=n()(e?a:null,o.openmrsFetch),d=null;return l?.data&&(d=t?u(l.data):l.data),{bill:d,error:i,isLoading:r,isValidating:s,mutate:m}}let p=(e,t)=>{let a=`${c.B}bill/${t}/payment`;return(0,o.openmrsFetch)(a,{method:"POST",body:e,headers:{"Content-Type":"application/json"}})};function E(){let{sessionLocation:e}=(0,o.useSession)();return{data:e}}let g=e=>{let{currentVisit:t}=(0,o.useVisit)(e);return(t?.attributes??[]).map(e=>({name:e.attributeType.name,value:e.value})).filter(({name:e})=>"Insurance scheme"===e||"Policy Number"===e)};function y(){let e=`${c.B}billableService?v=custom:(uuid,name,shortName,serviceStatus,serviceType:(display),servicePrices:(uuid,name,price,paymentMode))`;return(0,o.useOpenmrsFetchAll)(e)}let h=e=>{let t=`${c.B}bill`;return(0,o.openmrsFetch)(t,{method:"POST",body:e,headers:{"Content-Type":"application/json"}})},f=e=>{let t=`${c.B}bill/${e.uuid}`;return(0,o.openmrsFetch)(t,{method:"POST",body:e,headers:{"Content-Type":"application/json"}})},v=e=>{let t=`${c.B}bill/${e}`;return(0,o.openmrsFetch)(t,{method:"POST",body:{status:m.ih.POSTED},headers:{"Content-Type":"application/json"}})},C=(e,t)=>{let a=`${c.B}billLineItem/${e}?reason=${encodeURIComponent(t)}`;return(0,o.openmrsFetch)(a,{method:"DELETE"})},N=(e,t)=>{let a=`${c.B}bill/${e}?reason=${encodeURIComponent(t)}`;return(0,o.openmrsFetch)(a,{method:"DELETE"})},T=e=>`${c.B}patientPaymentStatus/${e}`,S=e=>{let t=T(e),{data:a,error:l,isLoading:i,isValidating:r,mutate:s}=n()(e?t:null,o.openmrsFetch);return{paymentStatus:a?.data,error:l,isLoading:i,isValidating:r,mutate:s}}},7003(e,t,a){"use strict";a.d(t,{B:()=>n,U:()=>i});var l=a(3137);let n=`${l.restBaseUrl}/billing/`,i="YYYY-MM-DDTHH:mm:ss.SSSZZ"},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:()=>tb,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:()=>tp});var o=a(2383),c=a(4499),m=a(3989),u=a(771),d=a(3137),_=a(5275),b=a.n(_),p=a(7767),E=a(4976),g=a(8395);function y({config:e}){let{t}=(0,g.useTranslation)(),{name:a,title:l}=e,n=(0,p.zy)(),i=window.getOpenmrsSpaBase()+"home",r=(0,_.useMemo)(()=>n.pathname.split("/").map(e=>decodeURIComponent(e)).includes(a),[n.pathname,a]);return b().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,p.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=b().createElement(h.VxE,{onClick:()=>{(0,d.navigate)({to:`${s}/${a}`})},renderIcon:l,isActive:o},i(t));return n?b().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=b().createElement(h.whj,{defaultExpanded:!0,title:i(t),renderIcon:a},l.map(e=>b().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?b().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,p.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 b().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,p.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 b().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 b().createElement(b().Fragment,null,b().createElement("div",{className:"-esm-billing__billable-services__headerContainer___Jom5Q"},b().createElement("div",{className:k()({"-esm-billing__billable-services__tabletHeading___DjbOL":!(0,d.isDesktop)(e),"-esm-billing__billable-services__desktopHeading___JApyg":(0,d.isDesktop)(e)})},b().createElement("h4",null,i("servicesList","Services list"))),b().createElement("div",{className:"-esm-billing__billable-services__backgroundDataFetchingIndicator___Icc-9"},b().createElement("span",null,a?b().createElement(h.OuH,null):null))),b().createElement("div",{className:"-esm-billing__billable-services__actionsContainer___gjC3h"},b().createElement(h.vji,{labelText:"",placeholder:i("filterTable","Filter table"),onChange:t,size:n}),b().createElement(h.$nd,{size:n,kind:"primary",renderIcon:e=>b().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,p]=(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?b().createElement(h.OuH,{status:"active",iconDescription:(0,d.getCoreTranslation)("loading"),description:e("loading","Loading data")+"..."}):n?b().createElement(d.ErrorState,{headerTitle:e("billableService","Billable service"),error:n}):0===t.length?b().createElement(d.EmptyCard,{displayText:e("billableServices__lower","billable services"),headerTitle:e("billableService","Billable service"),launchForm:y}):b().createElement("div",{className:"-esm-billing__billable-services__serviceContainer___x-Geg"},b().createElement(P,{handleSearch:k,isValidating:l,launchBillableServiceForm:y,layout:r,responsiveSize:m,t:e}),b().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})=>b().createElement(h.K3K,null,b().createElement(h.XIK,{...i(),"aria-label":e("serviceList","Service list")},b().createElement(h.ndF,null,b().createElement(h.Hjg,null,a.map(e=>b().createElement(h.A0N,{...l({header:e}),key:e.key},e.header)),b().createElement(h.A0N,{"aria-label":(0,d.getCoreTranslation)("actions")}))),b().createElement(h.BFY,null,t.map(t=>b().createElement(h.Hjg,{key:t.id,...n({row:t})},t.cells.map(e=>b().createElement(h.nA6,{key:e.id},e.value)),b().createElement(h.nA6,{className:"cds--table-column-menu"},b().createElement(h.obU,{size:"lg",flipped:!0},b().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&&b().createElement("div",{className:"-esm-billing__billable-services__filterEmptyState___Gklg-"},b().createElement(h.Wdr,{level:0},b().createElement(h.FAs,{className:"-esm-billing__billable-services__filterEmptyStateTile___DHTbi"},b().createElement("p",{className:"-esm-billing__billable-services__filterEmptyStateContent___n3TI3"},e("noMatchingServicesToDisplay","No matching services to display")),b().createElement("p",{className:"-esm-billing__billable-services__filterEmptyStateHelper___pVBoH"},e("checkFilters","Check the filters above"))))),v&&b().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&&p(e),t!==T&&C(t)}}))};function I(){return b().createElement("main",{className:"-esm-billing__dashboard__container___PDlGf"},b().createElement("main",{className:"-esm-billing__dashboard__servicesTableContainer___m7wfM"},b().createElement(w,null)))}let L=()=>b().createElement("svg",{width:"64",height:"64",viewBox:"10 10 60 60.02"},b().createElement("title",null,"Billing module illustration"),b().createElement("g",{fill:"none",fillRule:"evenodd"},b().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"}),b().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"}),b().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"}),b().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 b().createElement("div",{className:"-esm-billing__billing-header__header___P+PIw","data-testid":"billing-header"},b().createElement("div",{className:"-esm-billing__billing-header__left-justified-items___0FINv"},b().createElement(L,null),b().createElement("div",{className:"-esm-billing__billing-header__page-labels___Z52tc"},b().createElement("p",null,t("billing","Billing")),b().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 b().createElement("div",{className:"-esm-billing__cash-point-configuration__container___-hvwr"},b().createElement("div",{className:"-esm-billing__cash-point-configuration__card___ytTem"},b().createElement(d.CardHeader,{title:e("cashPointHistory","Cash point history")},b().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"))),b().createElement("div",null,b().createElement(h.bQt,{rows:n,headers:i,isSortable:!0,size:"lg"},({rows:e,headers:t,getTableProps:a,getHeaderProps:l,getRowProps:n})=>b().createElement(h.K3K,null,b().createElement(h.XIK,{className:"-esm-billing__cash-point-configuration__table___x+kW9",...a()},b().createElement(h.ndF,null,b().createElement(h.Hjg,null,t.map(e=>b().createElement(h.A0N,{key:e.key,...l({header:e})},e.header)))),b().createElement(h.BFY,null,e.map(e=>b().createElement(h.Hjg,{key:e.id,...n({row:e})},e.cells.map(e=>b().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?b().createElement(h.OuH,{status:"active",iconDescription:(0,d.getCoreTranslation)("loading"),description:e("loading","Loading data")+"..."}):a?b().createElement(d.ErrorState,{headerTitle:e("paymentMode","Payment mode"),error:a}):b().createElement("div",{className:"-esm-billing__payment-modes-config__container___hB7Cc"},b().createElement("div",{className:"-esm-billing__payment-modes-config__card___FGL9q"},b().createElement(d.CardHeader,{title:e("paymentModeHistory","Payment mode history")},b().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"))),b().createElement(h.bQt,{rows:n,headers:i,isSortable:!0,size:"lg"},({rows:e,headers:a,getTableProps:l,getHeaderProps:n,getRowProps:i})=>b().createElement(h.K3K,null,b().createElement(h.XIK,{className:"-esm-billing__payment-modes-config__table___Zs7R+",...l()},b().createElement(h.ndF,null,b().createElement(h.Hjg,null,a.map(e=>b().createElement(h.A0N,{key:e.key,...n({header:e})},e.header)))),b().createElement(h.BFY,null,e.map(e=>b().createElement(h.Hjg,{key:e.id,...i({row:e})},e.cells.map(a=>"actions"!==a.info.header?b().createElement(h.nA6,{key:a.id},a.value):b().createElement(h.nA6,{key:a.id},b().createElement(h.obU,null,b().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()}))}}),b().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),U=a.n(x),$=a(7003);let j=`${$.B}billDiscount`,O=`${$.B}bill`;async function H(e){return(await (0,d.openmrsFetch)(j,{method:"POST",headers:{"Content-Type":"application/json"},body:e})).data}async function z(e,t,a){return(await (0,d.openmrsFetch)(`${j}/${e}`,{method:"POST",headers:{"Content-Type":"application/json"},body:{status:t,approver:a}})).data}async function V(e,t){await (0,d.openmrsFetch)(`${j}/${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 b().createElement(b().Fragment,null,b().createElement("div",{className:W.headerContainer},b().createElement("div",{className:k()({[W.tabletHeading]:!(0,d.isDesktop)(e),[W.desktopHeading]:(0,d.isDesktop)(e)})},b().createElement("h4",null,i("discountRequests","Discount requests"))),a&&b().createElement("div",{className:W.backgroundDataFetchingIndicator},b().createElement("span",null,b().createElement(h.OuH,null)))),b().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,p]=(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=`${O}?${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?b().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=>{p(e.target.value),S(1)},[S]);return b().createElement("main",{className:W.container},b().createElement("main",{className:W.servicesTableContainer},b().createElement("div",{className:W.filterContainer},b().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"})),b().createElement("div",{className:W.billListContainer},b().createElement(G,{handleSearch:L,isValidating:C,layout:n,responsiveSize:i,searchString:u,t:t}),y&&!E?.length?b().createElement("div",{className:W.loaderContainer,role:"progressbar","aria-label":t("loadingDescription","Loading")},b().createElement(h.OOb,{rowCount:c,showHeader:!1,showToolbar:!1,zebra:!0,columnCount:P.length})):f?b().createElement("div",{className:W.errorContainer},b().createElement(h.Wdr,null,b().createElement(d.ErrorState,{error:f,headerTitle:t("discountRequests","Discount requests")}))):I.length>0?b().createElement(b().Fragment,null,b().createElement(h.bQt,{isSortable:!0,rows:I,headers:P,size:i,useZebraStyles:I.length>1},({rows:e,headers:a,getRowProps:l,getTableProps:n})=>b().createElement(h.K3K,null,b().createElement(h.XIK,{...n(),"aria-label":t("discountRequests","Discount requests")},b().createElement(h.ndF,null,b().createElement(h.Hjg,null,a.map(e=>b().createElement(h.A0N,{key:e.key},e.header)))),b().createElement(h.BFY,null,e.map(e=>b().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=>b().createElement(h.nA6,{key:e.id},e.value)))))))),T&&b().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)}})):b().createElement(h.Wdr,{className:W.emptyStateContainer},b().createElement(h.FAs,{className:W.tile},b().createElement("div",{className:W.illo},b().createElement(d.EmptyCardIllustration,null)),b().createElement("p",{className:W.content},t("noDiscountRequestsToDisplay","There are no discount requests to display.")))))))};var J=a(8683);let Y={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 b().createElement(b().Fragment,null,b().createElement("div",{className:Y.headerContainer},b().createElement("div",{className:k()({[Y.tabletHeading]:!(0,d.isDesktop)(e),[Y.desktopHeading]:(0,d.isDesktop)(e)})},b().createElement("h4",null,i("refundRequests","Refund requests"))),a&&b().createElement("span",null,b().createElement(h.OuH,null))),b().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 X=()=>{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),[p,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=p.trim().toLowerCase();return e?y.filter(t=>t.patient?.display?.toLowerCase().includes(e)||t.receiptNumber?.toLowerCase().includes(e)):y},[y,p]),{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?b().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?b().createElement("div",{className:Y.loaderContainer,"aria-busy":"true","aria-label":a("loading","Loading")},b().createElement(h.OOb,{rowCount:m,showHeader:!1,showToolbar:!1,zebra:!0,columnCount:w.length})):v?b().createElement("div",{className:Y.errorContainer},b().createElement(h.Wdr,null,b().createElement(d.ErrorState,{error:v,headerTitle:a("refundRequests","Refund requests")}))):L.length>0?b().createElement(b().Fragment,null,b().createElement(h.bQt,{isSortable:!0,rows:L,headers:w,size:r,useZebraStyles:L.length>1},({rows:e,headers:t,getRowProps:l,getTableProps:n})=>b().createElement(h.K3K,null,b().createElement(h.XIK,{...n(),"aria-label":a("refundRequests","Refund requests")},b().createElement(h.ndF,null,b().createElement(h.Hjg,null,t.map(e=>b().createElement(h.A0N,{key:e.key},e.header)))),b().createElement(h.BFY,null,e.map(e=>b().createElement(h.Hjg,{key:e.id,...l({row:e}),className:Y.row,onClick:()=>B(e.id)},e.cells.map(e=>b().createElement(h.nA6,{key:e.id},e.value)))))))),S&&b().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)}})):b().createElement(h.Wdr,{className:Y.emptyStateContainer},b().createElement(h.FAs,{className:Y.tile},b().createElement("div",{className:Y.illo},b().createElement(d.EmptyCardIllustration,null)),b().createElement("p",{className:Y.content},a("noRefundRequestsToDisplay","There are no refund requests to display.")))),b().createElement("main",{className:Y.container},b().createElement("div",{className:Y.servicesTableContainer},b().createElement("div",{className:Y.filterContainer},b().createElement(h.msM,{className:Y.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"})),b().createElement("div",{className:Y.billListContainer},b().createElement(Z,{handleSearch:M,isValidating:N,layout:i,responsiveSize:r,searchString:p,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 b().createElement(h.Wdr,null,b().createElement(h.obU,{align:"left",flipped:!0,size:(0,d.isDesktop)(n)?"sm":"lg","data-testid":`action-menu-${e.uuid}`},b().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&&b().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,p,E]=o(["paymentDetails","paymentMethods","insuranceScheme","policyNumber","patientCategory"]),{paymentModes:y,isLoading:f}=(()=>{let e=`${$.B}paymentMode`,{data:t,isLoading:a,error:l}=U()(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,p,E,e,C]),f)?b().createElement(h.OuH,{status:"active",iconDescription:a("loadingDescription","Loading"),description:a("loading","Loading data")+"..."}):b().createElement(h.BJc,{className:eo.stack,gap:5},b().createElement(er.xI,{name:"paymentDetails",control:r,render:({field:e})=>b().createElement(h.zWQ,{className:eo.radioButtonGroup,legendText:b().createElement("div",{className:eo.paymentDetailsLegend},a("paymentDetails","Payment details"),b().createElement(h.Gff,{autoAlign:!0,align:"bottom"},b().createElement(h.yvu,{label:a("showInformation","Show information")},b().createElement(es.$$,null)),b().createElement(h.pNg,null,b().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"},b().createElement(h.aaP,{labelText:a("paying","Paying"),value:n.payingDetails,id:"payment-details-paying"}),b().createElement(h.aaP,{labelText:a("nonPaying","Non paying"),value:n.nonPayingDetails,id:"payment-details-non-paying"}))}),c===n.payingDetails&&b().createElement(er.xI,{control:r,name:"paymentMethods",render:({field:e})=>b().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&&b().createElement(b().Fragment,null,b().createElement(er.xI,{control:r,name:"insuranceScheme",render:({field:e})=>b().createElement(h.ksK,{id:"insurance-scheme",labelText:a("insuranceScheme","Insurance scheme"),onChange:t=>e.onChange(t.target.value),type:"text"})}),b().createElement(er.xI,{control:r,name:"policyNumber",render:({field:e})=>b().createElement(h.ksK,{...e,id:"policy-number",labelText:a("policyNumber","Policy number"),onChange:t=>e.onChange(t.target.value),type:"text"})})),c===n.nonPayingDetails&&b().createElement(er.xI,{control:r,name:"patientCategory",render:({field:e})=>b().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=b().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}=U()(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}=U()(e,d.openmrsFetch);return{isLoading:a,error:l,cashPoints:t?.data?.results??[]}})(),{lineItems:u,isLoading:p,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}=U()(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 p||c?b().createElement(h.OuH,{status:"active",iconDescription:(0,d.getCoreTranslation)("loading"),description:`${a("loadingBillingServices","Loading billing services")}...`}):m||E?b().createElement(h.jeF,{kind:"error",lowContrast:!0,title:a("billErrorService","Billing service error"),subtitle:a("errorLoadingBillServices","Error loading bill services")}):b().createElement("section",{className:"-esm-billing__billing-checkin-form__sectionContainer___TLb4u"},b().createElement("h1",{className:"-esm-billing__billing-checkin-form__sectionLabel___1H1hH"},a("billingDetails","Billing details")),b().createElement("div",{className:"-esm-billing__billing-checkin-form__sectionField___AUKom"},!r&&!s&&i&&b().createElement("div",{className:"-esm-billing__billing-checkin-form__lastVisitBanner___Bh8FX"},b().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})),b().createElement(em,{setAttributes:f,setPaymentMethod:C}),D.length>0&&b().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"},eb="-esm-billing__request-discount-modal__summaryLabel___VaWqh",ep="-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 b().createElement("section",{className:"-esm-billing__bill-line-items-table__ledger___qbKwi"},b().createElement("h3",{className:"-esm-billing__bill-line-items-table__ledgerHeading___M7DcA"},t("lineItems","Line items")),b().createElement("table",{className:"-esm-billing__bill-line-items-table__ledgerTable___Lw3pG"},b().createElement("thead",null,b().createElement("tr",null,b().createElement("th",null,t("item","Item")),b().createElement("th",null,t("qty","Qty")),b().createElement("th",{className:eE},t("price","Price")))),b().createElement("tbody",null,e.map((e,t)=>b().createElement("tr",{key:e.uuid??t},b().createElement("td",{className:"-esm-billing__bill-line-items-table__itemName___dKItf"},e.item||e.billableService||"--"),b().createElement("td",null,e.quantity),b().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:b().createElement("section",{className:"-esm-billing__bill-payments-table__ledger___Qc+ke"},b().createElement("h3",{className:"-esm-billing__bill-payments-table__ledgerHeading___ilV8F"},t("payments","Payments")),b().createElement("table",{className:"-esm-billing__bill-payments-table__ledgerTable___lHxsT"},b().createElement("thead",null,b().createElement("tr",null,b().createElement("th",null,t("method","Method")),b().createElement("th",null,t("date","Date")),b().createElement("th",{className:ey},t("tendered","Tendered")))),b().createElement("tbody",null,e.map(e=>b().createElement("tr",{key:e.uuid},b().createElement("td",null,b().createElement("span",{className:"-esm-billing__bill-payments-table__paymentKind___TglOe"},e.instanceType?.name??"--")),b().createElement("td",null,b().createElement("span",{className:"-esm-billing__bill-payments-table__paymentDate___9NyEF"},e.dateCreated?(0,d.formatDate)(new Date(e.dateCreated),{mode:"wide"}):"--")),b().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 b().createElement("section",{className:"-esm-billing__bill-totals-summary__totals___6iaM7"},b().createElement("div",{className:k()(ef,"-esm-billing__bill-totals-summary__totalsSubtotal___8mWZP")},b().createElement("span",null,r("subtotal","Subtotal")),b().createElement("span",null,(0,F.aL)(e,s))),n.map(e=>b().createElement("div",{key:e.uuid,className:k()(ef,ev)},b().createElement("span",null,"− ",r("discount","Discount")),b().createElement("span",null,(0,F.aL)(e.discountAmount,s)))),b().createElement("hr",{className:"-esm-billing__bill-totals-summary__totalsRule___LldMI"}),b().createElement("div",{className:k()(ef,"-esm-billing__bill-totals-summary__totalsNet___0Bb1l")},b().createElement("span",null,r("currentNet","Current net")),b().createElement("span",{className:"-esm-billing__bill-totals-summary__totalsNetAmount___xvxJT"},(0,F.aL)(t,s))),l>0&&b().createElement("div",{className:k()(ef,"-esm-billing__bill-totals-summary__totalsRowAdd___sbxAx")},b().createElement("span",null,"− ",r("paymentsReceived","Payments received")),b().createElement("span",null,(0,F.aL)(l,s))),b().createElement("hr",{className:"-esm-billing__bill-totals-summary__totalsRuleStrong___Kidyj"}),b().createElement("div",{className:k()(ef,"-esm-billing__bill-totals-summary__totalsOutstanding___fP1bD")},b().createElement("span",null,r("outstanding","Outstanding")),b().createElement("span",{className:"-esm-billing__bill-totals-summary__totalsOutstandingAmount___qQXu3"},(0,F.aL)(a,s))),i.length>0&&b().createElement("div",{className:"-esm-billing__bill-totals-summary__preview___rPSsf"},b().createElement("p",{className:"-esm-billing__bill-totals-summary__previewLabel___mjNu2"},r("ifPendingApproved","If pending discounts approved")),i.map(e=>b().createElement("div",{key:e.uuid,className:k()(ef,ev)},b().createElement("span",null,"− ",r("discount","Discount")," (",e.discountType===K.Bp.PERCENTAGE?`${e.discountValue}%`:(0,F.aL)(e.discountValue,s),")"),b().createElement("span",null,(0,F.aL)(e.discountAmount,s)))),b().createElement("div",{className:k()(ef,"-esm-billing__bill-totals-summary__previewProjected___bUPgY")},b().createElement("span",null,r("projectedNet","Projected net")),b().createElement("span",{className:"-esm-billing__bill-totals-summary__previewProjectedAmount___7yhBk"},(0,F.aL)(t-i.reduce((e,t)=>e+t.discountAmount,0),s)))))},eN=b().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 b().createElement("aside",{className:"-esm-billing__bill-receipt-rail__receipt___b5het"},b().createElement("div",{className:"-esm-billing__bill-receipt-rail__patient___gB6Df"},b().createElement("div",null,b().createElement("p",{className:"-esm-billing__bill-receipt-rail__patientName___dNAHq"},e.patient?.display),b().createElement("p",{className:"-esm-billing__bill-receipt-rail__patientId___2KJ7G"},c("receiptNumber","Receipt #"),": ",e.receiptNumber)),e.status&&b().createElement(h.vwO,{type:"blue",size:"sm"},c(String(e.status).toLowerCase(),String(e.status)))),b().createElement("dl",{className:"-esm-billing__bill-receipt-rail__meta___F8p9R"},b().createElement("dt",null,c("issued","Issued")),b().createElement("dd",null,e.dateCreated?(0,d.formatDate)((0,d.parseDate)(e.dateCreated),{mode:"wide"}):"--"),b().createElement("dt",null,c("cashier","Cashier")),b().createElement("dd",null,e.cashier?.display??"--")),b().createElement(eg,{lineItems:t}),b().createElement(eh,{payments:a}),b().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:p}=(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||"--":p("wholeBill","Whole bill");return b().createElement("article",{className:C},b().createElement("header",{className:"-esm-billing__discount-card__cardTop___2KfsR"},b().createElement("div",{className:"-esm-billing__discount-card__cardScope___DFbYt"},b().createElement("span",{className:"-esm-billing__discount-card__cardScopeName___e0Gom"},T),b().createElement("span",{className:"-esm-billing__discount-card__cardScopeKind___YgWB0"},e.discountType===K.Bp.PERCENTAGE?p("percentage","Percentage"):p("fixedAmount","Fixed amount"))),e.status!==K.nT.PENDING&&b().createElement(h.vwO,{type:eS[e.status],size:"sm"},p(e.status.toLowerCase(),e.status))),b().createElement("div",{className:"-esm-billing__discount-card__cardFigure___2fn-w"},b().createElement("span",{className:k()("-esm-billing__discount-card__cardAmount___IsWoS",{"-esm-billing__discount-card__cardAmountVoided___VNogb":e.status===K.nT.REJECTED})},b().createElement("span",{className:"-esm-billing__discount-card__cardAmountMinus___eSUgX"},"−"),(0,F.aL)(e.discountAmount,E)),e.discountType===K.Bp.PERCENTAGE&&b().createElement("span",{className:"-esm-billing__discount-card__cardValue___pIy2C"},N)),b().createElement("div",null,p("reasonForDiscount","Reason for discount"),": ",b().createElement("p",{className:"-esm-billing__discount-card__cardJustification___ZbW6e"},e.justification)),b().createElement("footer",{className:"-esm-billing__discount-card__cardFooter___AlFbq"},b().createElement("div",{className:"-esm-billing__discount-card__cardByline___r8xcx"},p("requestedBy","Requested by")," ",b().createElement("strong",null,e.initiator?.display),b().createElement("span",{className:"-esm-billing__discount-card__cardBylineSep___VM4YL"},"\xb7"),(0,d.formatDate)((0,d.parseDate)(e.dateCreated),{mode:"wide"})),b().createElement("div",{className:"-esm-billing__discount-card__cardActions___bvhbQ"},v&&e.status===K.nT.PENDING&&b().createElement(b().Fragment,null,b().createElement(h.$nd,{kind:"danger--tertiary",size:"sm",disabled:!!a||!i,onClick:()=>s(e.uuid)},p("reject","Reject")),b().createElement(h.$nd,{kind:"primary",size:"sm",disabled:!!a||!i,onClick:()=>r(e)},p("approve","Approve"))),v&&b().createElement(h.$nd,{kind:"danger",size:"sm",disabled:!!a,onClick:()=>m(e.uuid)},p("delete","Delete")),y&&b().createElement(b().Fragment,null,b().createElement("span",{className:eT},p("rejectConfirm","Reject this discount?")),b().createElement(h.$nd,{kind:"ghost",size:"sm",onClick:o},(0,d.getCoreTranslation)("cancel")),b().createElement(h.$nd,{kind:"danger",size:"sm",disabled:!!a,onClick:()=>c(e)},p("confirmReject","Confirm reject"))),f&&b().createElement(b().Fragment,null,b().createElement("span",{className:eT},p("deleteConfirm","Delete this discount?")),b().createElement(h.$nd,{kind:"ghost",size:"sm",onClick:u},(0,d.getCoreTranslation)("cancel")),b().createElement(h.$nd,{kind:"danger",size:"sm",disabled:!!a,onClick:()=>_(e)},p("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=b().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:p}=(0,g.useTranslation)(),E=e=>b().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 b().createElement("section",{className:"-esm-billing__discount-review-stack__review___7I6RE"},e.length>0&&b().createElement("div",null,b().createElement("div",{className:eD},b().createElement("h3",{className:eA},p("pendingDiscounts","Pending discounts")),b().createElement("span",{className:eP},e.length)),b().createElement("div",{className:ew},e.map(E))),t.length>0&&b().createElement("div",null,b().createElement("div",{className:eD},b().createElement("h3",{className:eA},p("confirmedDiscounts","Confirmed discounts")),b().createElement("span",{className:eP},t.length)),b().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",datePickerContainer:"-esm-billing__bills-table__datePickerContainer___Ss4P3",clearDatesButton:"-esm-billing__bills-table__clearDatesButton___ZS5e8",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 b().createElement(b().Fragment,null,b().createElement("div",{className:eM.headerContainer},b().createElement("div",{className:k()({[eM.tabletHeading]:!(0,d.isDesktop)(e),[eM.desktopHeading]:(0,d.isDesktop)(e)})},b().createElement("h4",null,i("billList","Bill list"))),a&&b().createElement("div",{className:eM.backgroundDataFetchingIndicator},b().createElement("span",null,b().createElement(h.OuH,null)))),b().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),[p,E]=(0,_.useState)(null),[y,f]=(0,_.useState)(null),{bills:v,error:C,currentPage:N,isLoading:T,isValidating:S,totalCount:k,goTo:D}=(0,ee.fu)(l,s.status,u||void 0,p,y),A=[{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"}],P=(0,_.useMemo)(()=>v?.map(e=>({...e,id:String(e.id),dateCreated:e.dateCreated?(0,d.formatDate)((0,d.parseDate)(e.dateCreated),{mode:"wide"}):"--",receiptNumberDisplay:b().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(" & ")})),[v]),w=""!==c.trim()||""!==s.id||null!==p||null!==y,I=(0,_.useCallback)(e=>{D(1),m(e.target.value)},[D,m]),L=(0,_.useCallback)(({selectedItem:e})=>{o(e),D(1)},[D]),M=(0,_.useCallback)(e=>{E(e??null),D(1)},[D]),B=(0,_.useCallback)(e=>{f(e??null),D(1)},[D]),R=(0,_.useCallback)(()=>{E(null),f(null),D(1)},[D]);return b().createElement(b().Fragment,null,b().createElement("div",{className:eM.filterContainer},b().createElement(h.msM,{className:eM.filterDropdown,direction:"bottom",id:"bill-payment-status-filter",selectedItem:s,items:r,itemToString:e=>e?e.text:"",label:"",onChange:L,size:i,titleText:e("filterBy","Filter by:"),type:"inline"}),b().createElement("div",{className:eM.datePickerContainer},b().createElement(d.OpenmrsDatePicker,{id:"bill-start-date-filter",labelText:e("from","From"),maxDate:y,value:p,onChange:M,size:i}),b().createElement(d.OpenmrsDatePicker,{id:"bill-end-date-filter",labelText:e("to","To"),minDate:p,value:y,onChange:B,size:i,invalidText:e("endDateBeforeStartDate","End date must be after the start date")}),p||y?b().createElement(h.$nd,{className:eM.clearDatesButton,kind:"ghost",onClick:R,size:i},e("clearDates","Clear dates")):null)),T&&!v?.length?b().createElement("div",{className:eM.loaderContainer,"data-testid":"bills-table-skeleton"},b().createElement(h.OOb,{rowCount:l,showHeader:!1,showToolbar:!1,zebra:!0,columnCount:A?.length})):C?b().createElement("div",{className:eM.errorContainer},b().createElement(h.Wdr,null,b().createElement(d.ErrorState,{error:C,headerTitle:e("billList","Bill list")}))):P?.length>0||w?b().createElement("div",{className:eM.billListContainer},b().createElement(eB,{handleSearch:I,isValidating:S,layout:t,responsiveSize:i,searchString:c,t:e}),b().createElement(h.bQt,{isSortable:!0,rows:P,headers:A,size:i,useZebraStyles:P?.length>1},({rows:t,headers:a,getRowProps:l,getTableProps:n})=>b().createElement(h.K3K,null,b().createElement(h.XIK,{...n(),"aria-label":e("billList","Bill list")},b().createElement(h.ndF,null,b().createElement(h.Hjg,null,a.map(e=>b().createElement(h.A0N,{key:e.key},e.header)))),b().createElement(h.BFY,null,t.map(e=>b().createElement(h.Hjg,{key:e.id,...l({row:e})},e.cells.map(e=>b().createElement(h.nA6,{key:e.id},e.value)))))))),P?.length===0&&b().createElement("div",{className:eM.filterEmptyState},b().createElement(h.Wdr,{level:0},b().createElement(h.FAs,{className:eM.filterEmptyStateTile},b().createElement("p",{className:eM.filterEmptyStateContent},e("noMatchingBillsToDisplay","No matching bills to display")),b().createElement("p",{className:eM.filterEmptyStateHelper},e("checkFilters","Check the filters above"))))),k>0&&b().createElement(h.dKS,{forwardText:e("nextPage","Next page"),backwardText:e("previousPage","Previous page"),page:N,pageSize:l,pageSizes:[10,20,30,40,50],totalItems:k,onChange:({pageSize:e,page:t})=>{e!==l?(n(e),D(1)):t!==N&&D(t)}})):b().createElement(h.Wdr,{className:eM.emptyStateContainer},b().createElement(h.FAs,{className:eM.tile},b().createElement("div",{className:eM.illo},b().createElement(d.EmptyCardIllustration,null)),b().createElement("p",{className:eM.content},e("noBillsToDisplay","There are no bills to display.")))))};function eq(){let{t:e}=(0,g.useTranslation)();return b().createElement(b().Fragment,null,b().createElement(M,{title:e("home","Home")}),b().createElement("section",{className:"-esm-billing__billing-dashboard__billsTableContainer___XBT2N"},b().createElement(eR,null)))}var eF=a(7240);let ex=({label:e,value:t,hasBalance:a})=>b().createElement("div",{className:"-esm-billing__invoice-breakdown__invoiceBreakdown___IGWfb"},b().createElement("span",{className:a?"-esm-billing__invoice-breakdown__extendedLabel___fJ78V":"-esm-billing__invoice-breakdown__label___WpAJx"},e,": "),b().createElement("span",{className:"-esm-billing__invoice-breakdown__value___L3Y8v"},t)),eU={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"})},ej=({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}=U()(e,d.openmrsFetch,eU);return{paymentModes:t?.data?.results??[],isLoading:a,mutate:n,error:l}})();return i?b().createElement(h.Rzj,null):r?b().createElement("div",{className:"-esm-billing__payment-form__errorPaymentContainer___Ft9DN"},b().createElement(d.ErrorState,{headerTitle:t("errorLoadingPaymentModes","Error loading payment modes"),error:r})):e?null:b().createElement("div",{className:"-esm-billing__payment-form__container___P4SMq"},b().createElement("div",{className:"-esm-billing__payment-form__paymentMethodContainer___fZiwB"},b().createElement(er.xI,{control:a,name:"payment.method",render:({field:e})=>b().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})}),b().createElement(er.xI,{control:a,name:"payment.amount",render:({field:e})=>b().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??""})}),b().createElement(er.xI,{name:"payment.referenceCode",control:a,render:({field:e})=>b().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??""})})))},eO=({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 b().createElement(h.bQt,{size:"sm",rows:n,headers:l},({rows:e,headers:t,getTableProps:a,getHeaderProps:l,getRowProps:n})=>b().createElement(h.XIK,a(),b().createElement(h.ndF,null,b().createElement(h.Hjg,null,t.map(e=>b().createElement(h.A0N,l({header:e}),e.header)))),b().createElement(h.BFY,null,e.map(e=>b().createElement(h.Hjg,n({row:e}),e.cells.map(e=>b().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.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),p=(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 b().createElement(er.Op,m,b().createElement("div",{className:"-esm-billing__payments__wrapper___V4WiR"},b().createElement("div",{className:"-esm-billing__payments__paymentContainer___1SfXU"},b().createElement(d.CardHeader,{title:l("payments","Payments")},b().createElement("span",null)),b().createElement("div",null,E?b().createElement("div",{className:"-esm-billing__payments__pendingEmptyState___jUFD7"},b().createElement(h.Wdr,null,b().createElement(h.FAs,{className:"-esm-billing__payments__pendingEmptyStateTile___q+iuz"},b().createElement("p",{className:"-esm-billing__payments__pendingEmptyStateContent___B8pVF"},l("billNotFinalized","Bill not finalized")),b().createElement("p",{className:"-esm-billing__payments__pendingEmptyStateHelper___amDGw"},l("finalizeBillToRecordPayment","Finalize this bill before recording a payment.")),b().createElement(h.$nd,{className:"-esm-billing__payments__finalizeButton___nCnCg",kind:"primary",size:"sm",onClick:a},l("finalizeBill","Finalize bill"))))):b().createElement(b().Fragment,null,b().createElement(eO,{bill:e}),b().createElement(ej,{disablePayment:p<=0})))),b().createElement("div",{className:"-esm-billing__payments__divider___C6sdr"}),b().createElement("div",{className:"-esm-billing__payments__paymentTotals___-3A2t"},b().createElement(ex,{label:l("totalAmount","Total amount"),value:(0,F.aL)(e.totalAmount??0,o)}),b().createElement(ex,{label:l("totalTendered","Total tendered"),value:(0,F.aL)(e.tenderedAmount??0,o)}),b().createElement(ex,{label:l("discount","Discount"),value:`- ${(0,F.aL)((e.totalAmount??0)-(e.netAmount??0),o)}`}),b().createElement(ex,{label:l("refunds","Refunds"),value:`- ${(0,F.aL)(_,o)}`}),b().createElement(ex,{hasBalance:p<0,label:l("amountDue","Amount due"),value:(0,F.aL)(p,o)}),b().createElement("div",{className:"-esm-billing__payments__processPayments___RG8aV"},b().createElement(h.$nd,{onClick:()=>(0,d.navigate)({to:window.getOpenmrsSpaBase()+"home/billing"}),kind:"secondary"},l("discard","Discard")),!E&&b().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 b().createElement(h.$nd,{kind:"secondary",className:"-esm-billing__print-receipt__button___QnAQS",renderIcon:e=>b().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?b().createElement("div",{className:"-esm-billing__printable-footer__container___mTh7B"},b().createElement("p",{className:"-esm-billing__printable-footer__itemFooter___Y5pkL"},e?.display)):b().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",eY=({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 b().createElement("div",{className:"-esm-billing__printable-invoice-header__container___1u0nI"},b().createElement("div",{className:"-esm-billing__printable-invoice-header__printableHeader___Jl02J"},b().createElement("div",{className:"-esm-billing__printable-invoice-header__logo___ZpVka"},n?.src&&!eW()(n.src)?b().createElement("img",{className:eG,src:(0,d.interpolateUrl)(n.src),alt:n.alt}):n?.alt&&!eW()(n.alt)?n.alt:b().createElement("svg",{className:eG,role:"img",width:110,height:40,viewBox:"0 0 380 119",xmlns:"http://www.w3.org/2000/svg"},b().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"}))),b().createElement("div",{className:"-esm-billing__printable-invoice-header__facilityDetails___uJPtI"},b().createElement("p",{className:"-esm-billing__printable-invoice-header__facilityName___81nN9"},t?.display),b().createElement("p",{className:eJ},i))),b().createElement("h1",{className:"-esm-billing__printable-invoice-header__invoiceHeading___9Xftg"},l("invoice","Invoice")),b().createElement("div",{className:"-esm-billing__printable-invoice-header__printableBody___cMhfI"},b().createElement("div",{className:"-esm-billing__printable-invoice-header__detailsContainer___rJn9A"},b().createElement("div",null,b().createElement("h2",{className:eQ},l("patientInformation","Patient information")),Object.entries(o).map(([e,t])=>b().createElement("p",{className:eJ,key:e},b().createElement("strong",null,e),b().createElement("span",null,": ",t)))),b().createElement("div",null,b().createElement("h2",{className:eQ},l("invoiceSummary","Invoice summary")),Object.entries(s).map(([e,t])=>b().createElement("p",{className:eJ,key:e},b().createElement("strong",null,e),b().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"},eX=({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]),p=(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 b().createElement("div",{className:eZ.container,ref:a},b().createElement(eY,{patientDetails:p,defaultFacility:l,bill:e}),b().createElement("div",{className:eZ.itemsContainer},b().createElement("div",{className:eZ.tableContainer},b().createElement(h.bQt,{rows:c,headers:o,size:s,useZebraStyles:!1},({rows:e,headers:t,getRowProps:a,getTableProps:l})=>b().createElement(h.K3K,null,b().createElement(h.XIK,{...l(),"aria-label":n("invoiceLineItems","Invoice line items")},b().createElement(h.ndF,null,b().createElement(h.Hjg,null,t.map(e=>b().createElement(h.A0N,{key:e.key},e.header)))),b().createElement(h.BFY,null,e.map(e=>b().createElement(h.Hjg,{key:e.id,...a({row:e})},e.cells.map(e=>b().createElement(h.nA6,{key:e.id},e.value)))))))),e?.netAmount!=null&&e.totalAmount!==e.netAmount?b().createElement(b().Fragment,null,b().createElement("div",{className:eZ.balanceContainer},b().createElement("span",{className:eZ.itemHeading},n("subtotal","Subtotal"),":")," ",b().createElement("span",{className:eZ.itemLabel},b().createElement("strong",null,r," ",e?.totalAmount))),b().createElement("div",{className:eZ.balanceContainer},b().createElement("span",{className:eZ.itemHeading},n("discount","Discount"),":")," ",b().createElement("span",{className:eZ.itemLabel},b().createElement("strong",null,"- ",r," ",(e?.totalAmount??0)-(e?.netAmount??0)))),b().createElement("div",{className:eZ.balanceContainer},b().createElement("span",{className:eZ.itemHeading},n("totalAmount","Total amount"),":")," ",b().createElement("span",{className:eZ.itemLabel},b().createElement("strong",null,r," ",e?.netAmount)))):b().createElement("div",{className:eZ.balanceContainer},b().createElement("span",{className:eZ.itemHeading},n("totalAmount","Total amount"),":")," ",b().createElement("span",{className:eZ.itemLabel},b().createElement("strong",null,r," ",e?.totalAmount))),e?.payments?.length>0&&b().createElement("div",{className:eZ.paymentHistoryContainer},b().createElement(h.bQt,{rows:u,headers:m,size:s},({rows:e,headers:t,getRowProps:a,getTableProps:l})=>b().createElement(h.K3K,null,b().createElement(h.XIK,{...l(),"aria-label":n("paymentHistory","Payment History")},b().createElement(h.ndF,null,b().createElement(h.Hjg,null,t.map(e=>b().createElement(h.A0N,{key:e.key},e.header)))),b().createElement(h.BFY,null,e.map(e=>b().createElement(h.Hjg,{key:e.id,...a({row:e})},e.cells.map(e=>b().createElement(h.nA6,{key:e.id},e.value))))))))),b().createElement("div",{className:eZ.balanceContainer},b().createElement("span",{className:eZ.itemHeading},n("totalTendered","Total tendered"),":"),b().createElement("span",{className:eZ.itemLabel},b().createElement("strong",null,r," ",e?.tenderedAmount))),b().createElement("div",{className:eZ.balanceContainer},b().createElement("span",{className:eZ.itemHeading},n("balance","Balance"),":"),b().createElement("span",{className:eZ.itemLabel},b().createElement("strong",null,r," ",e?.netAmount-e?.tenderedAmount))))),b().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?b().createElement("div",{className:"-esm-billing__discounts-table__discountsWrapper___nAknV"},b().createElement(h.bQt,{headers:r,rows:s,size:n,useZebraStyles:!0,overflowMenuOnHover:(0,d.isDesktop)(l)},({rows:e,headers:a,getRowProps:l,getTableProps:n})=>b().createElement(h.K3K,{description:b().createElement("span",{className:"-esm-billing__discounts-table__tableDescription___dsPxA"},b().createElement("span",null,t("discountsAppliedToBill","Discounts applied to this bill"))),title:t("discounts","Discounts")},b().createElement(h.XIK,{...n(),"aria-label":t("billDiscounts","Bill discounts"),className:k()("-esm-billing__discounts-table__discountsTable___Wd5vG","billingTable")},b().createElement(h.ndF,null,b().createElement(h.Hjg,null,a.map(e=>b().createElement(h.A0N,{key:e.key},e.header)))),b().createElement(h.BFY,null,e.map(e=>b().createElement(h.Hjg,{key:e.id,...l({row:e})},e.cells.map(e=>b().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]),p=(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:b().createElement(h.$nd,{kind:"primary",size:"sm",disabled:s===t.uuid||t.status!==K.fH.APPROVED,onClick:()=>u(t)},s===t.uuid?b().createElement(h.OuH,{description:a("processing","Processing")+"..."}):a("processRefund","Process refund"))})),[m,e,l,s,a,u]);return m&&0!==m.length?b().createElement("div",{className:"-esm-billing__refunds-table__refundsWrapper___ZvDhw"},b().createElement(h.bQt,{headers:c,rows:p,size:r,useZebraStyles:!0},({rows:e,headers:t,getRowProps:l,getTableProps:n})=>b().createElement(h.K3K,{description:b().createElement("span",{className:"-esm-billing__refunds-table__tableDescription___hGPCT"},b().createElement("span",null,a("refundsOnBill","Refunds on this bill"))),title:a("refunds","Refunds")},b().createElement(h.XIK,{...n(),"aria-label":a("billRefunds","Bill refunds"),className:k()("-esm-billing__refunds-table__refundsTable___B5xVc","billingTable")},b().createElement(h.ndF,null,b().createElement(h.Hjg,null,t.map(e=>b().createElement(h.A0N,{key:e.key},e.header)))),b().createElement(h.BFY,null,e.map(e=>b().createElement(h.Hjg,{key:e.id,...l({row:e})},e.cells.map(e=>b().createElement(h.nA6,{key:e.id},e.value))))))))):null},e3="-esm-billing__invoice__invoiceContainer___6Vmk0",e6=`
|
|
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:()=>b});var l=a(6335),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"}})},b=(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:()=>b,FR:()=>f,LM:()=>N,N7:()=>S,TS:()=>p,Vs:()=>g,Xn:()=>h,Z5:()=>T,eC:()=>E,fu:()=>d,ly:()=>y,mi:()=>C,u1:()=>_,yj:()=>v});var l=a(6335),n=a.n(l),i=a(6734),r=a.n(i),s=a(3139),o=a(3137),c=a(7003),m=a(5084);let u=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)}},d=(e,t,a,l,n)=>{let i=`${c.B}bill?v=custom:(id,uuid,dateCreated,status,receiptNumber,patient:(uuid,display),lineItems:(uuid,item,billableService,voided))&pageSize=${e}`;t&&(i+=`&status=${t}`),a&&(i+=`&patientName=${encodeURIComponent(a)}`),l&&(i+=`&startDate=${encodeURIComponent(r()(l).startOf("day").format(c.U))}`),n&&(i+=`&endDate=${encodeURIComponent(r()(n).endOf("day").format(c.U))}`);let s=!l||!n||l<=n,{data:m,error:d,isLoading:_,isValidating:b,mutate:p,currentPage:E,totalCount:g,goTo:y}=(0,o.useOpenmrsPagination)(s?i:null,e);return{bills:m?.map(e=>u(e))??[],error:d,isLoading:_,isValidating:b,mutate:p,currentPage:E,totalCount:g,goTo:y}},_=(e,t,a)=>{let l=`${c.B}bill?v=full`;e&&(l+=`&patientUuid=${e}`),t&&(l+=`&status=${t}`),a&&(l+=`&visitUuid=${a}`);let{data:n,error:i,isLoading:r,isValidating:m,mutate:d}=(0,o.useOpenmrsFetchAll)(l),_=(0,s.A)(n??[],["dateCreated"]).reverse();return{bills:_?.map(e=>u(e)),error:i,isLoading:r,isValidating:m,mutate:d}};function b(e,t=!0){let a=`${c.B}bill/${e}`,{data:l,error:i,isLoading:r,isValidating:s,mutate:m}=n()(e?a:null,o.openmrsFetch),d=null;return l?.data&&(d=t?u(l.data):l.data),{bill:d,error:i,isLoading:r,isValidating:s,mutate:m}}let p=(e,t)=>{let a=`${c.B}bill/${t}/payment`;return(0,o.openmrsFetch)(a,{method:"POST",body:e,headers:{"Content-Type":"application/json"}})};function E(){let{sessionLocation:e}=(0,o.useSession)();return{data:e}}let g=e=>{let{currentVisit:t}=(0,o.useVisit)(e);return(t?.attributes??[]).map(e=>({name:e.attributeType.name,value:e.value})).filter(({name:e})=>"Insurance scheme"===e||"Policy Number"===e)};function y(){let e=`${c.B}billableService?v=custom:(uuid,name,shortName,serviceStatus,serviceType:(display),servicePrices:(uuid,name,price,paymentMode))`;return(0,o.useOpenmrsFetchAll)(e)}let h=e=>{let t=`${c.B}bill`;return(0,o.openmrsFetch)(t,{method:"POST",body:e,headers:{"Content-Type":"application/json"}})},f=e=>{let t=`${c.B}bill/${e.uuid}`;return(0,o.openmrsFetch)(t,{method:"POST",body:e,headers:{"Content-Type":"application/json"}})},v=e=>{let t=`${c.B}bill/${e}`;return(0,o.openmrsFetch)(t,{method:"POST",body:{status:m.ih.POSTED},headers:{"Content-Type":"application/json"}})},C=(e,t)=>{let a=`${c.B}billLineItem/${e}?reason=${encodeURIComponent(t)}`;return(0,o.openmrsFetch)(a,{method:"DELETE"})},N=(e,t)=>{let a=`${c.B}bill/${e}?reason=${encodeURIComponent(t)}`;return(0,o.openmrsFetch)(a,{method:"DELETE"})},T=e=>`${c.B}patientPaymentStatus/${e}`,S=e=>{let t=T(e),{data:a,error:l,isLoading:i,isValidating:r,mutate:s}=n()(e?t:null,o.openmrsFetch);return{paymentStatus:a?.data,error:l,isLoading:i,isValidating:r,mutate:s}}},7003(e,t,a){"use strict";a.d(t,{B:()=>n,U:()=>i});var l=a(3137);let n=`${l.restBaseUrl}/billing/`,i="YYYY-MM-DDTHH:mm:ss.SSSZZ"},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:()=>tb,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:()=>tp});var o=a(2383),c=a(4499),m=a(3989),u=a(771),d=a(3137),_=a(5275),b=a.n(_),p=a(7767),E=a(4976),g=a(8395);function y({config:e}){let{t}=(0,g.useTranslation)(),{name:a,title:l}=e,n=(0,p.zy)(),i=window.getOpenmrsSpaBase()+"home",r=(0,_.useMemo)(()=>n.pathname.split("/").map(e=>decodeURIComponent(e)).includes(a),[n.pathname,a]);return b().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,p.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=b().createElement(h.VxE,{onClick:()=>{(0,d.navigate)({to:`${s}/${a}`})},renderIcon:l,isActive:o},i(t));return n?b().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=b().createElement(h.whj,{defaultExpanded:!0,title:i(t),renderIcon:a},l.map(e=>b().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?b().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,p.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 b().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,p.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 b().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 b().createElement(b().Fragment,null,b().createElement("div",{className:"-esm-billing__billable-services__headerContainer___Jom5Q"},b().createElement("div",{className:k()({"-esm-billing__billable-services__tabletHeading___DjbOL":!(0,d.isDesktop)(e),"-esm-billing__billable-services__desktopHeading___JApyg":(0,d.isDesktop)(e)})},b().createElement("h4",null,i("servicesList","Services list"))),b().createElement("div",{className:"-esm-billing__billable-services__backgroundDataFetchingIndicator___Icc-9"},b().createElement("span",null,a?b().createElement(h.OuH,null):null))),b().createElement("div",{className:"-esm-billing__billable-services__actionsContainer___gjC3h"},b().createElement(h.vji,{labelText:"",placeholder:i("filterTable","Filter table"),onChange:t,size:n}),b().createElement(h.$nd,{size:n,kind:"primary",renderIcon:e=>b().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,p]=(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?b().createElement(h.OuH,{status:"active",iconDescription:(0,d.getCoreTranslation)("loading"),description:e("loading","Loading data")+"..."}):n?b().createElement(d.ErrorState,{headerTitle:e("billableService","Billable service"),error:n}):0===t.length?b().createElement(d.EmptyCard,{displayText:e("billableServices__lower","billable services"),headerTitle:e("billableService","Billable service"),launchForm:y}):b().createElement("div",{className:"-esm-billing__billable-services__serviceContainer___x-Geg"},b().createElement(P,{handleSearch:k,isValidating:l,launchBillableServiceForm:y,layout:r,responsiveSize:m,t:e}),b().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})=>b().createElement(h.K3K,null,b().createElement(h.XIK,{...i(),"aria-label":e("serviceList","Service list")},b().createElement(h.ndF,null,b().createElement(h.Hjg,null,a.map(e=>b().createElement(h.A0N,{...l({header:e}),key:e.key},e.header)),b().createElement(h.A0N,{"aria-label":(0,d.getCoreTranslation)("actions")}))),b().createElement(h.BFY,null,t.map(t=>b().createElement(h.Hjg,{key:t.id,...n({row:t})},t.cells.map(e=>b().createElement(h.nA6,{key:e.id},e.value)),b().createElement(h.nA6,{className:"cds--table-column-menu"},b().createElement(h.obU,{size:"lg",flipped:!0},b().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&&b().createElement("div",{className:"-esm-billing__billable-services__filterEmptyState___Gklg-"},b().createElement(h.Wdr,{level:0},b().createElement(h.FAs,{className:"-esm-billing__billable-services__filterEmptyStateTile___DHTbi"},b().createElement("p",{className:"-esm-billing__billable-services__filterEmptyStateContent___n3TI3"},e("noMatchingServicesToDisplay","No matching services to display")),b().createElement("p",{className:"-esm-billing__billable-services__filterEmptyStateHelper___pVBoH"},e("checkFilters","Check the filters above"))))),v&&b().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&&p(e),t!==T&&C(t)}}))};function I(){return b().createElement("main",{className:"-esm-billing__dashboard__container___PDlGf"},b().createElement("main",{className:"-esm-billing__dashboard__servicesTableContainer___m7wfM"},b().createElement(w,null)))}let L=()=>b().createElement("svg",{width:"64",height:"64",viewBox:"10 10 60 60.02"},b().createElement("title",null,"Billing module illustration"),b().createElement("g",{fill:"none",fillRule:"evenodd"},b().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"}),b().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"}),b().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"}),b().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 b().createElement("div",{className:"-esm-billing__billing-header__header___P+PIw","data-testid":"billing-header"},b().createElement("div",{className:"-esm-billing__billing-header__left-justified-items___0FINv"},b().createElement(L,null),b().createElement("div",{className:"-esm-billing__billing-header__page-labels___Z52tc"},b().createElement("p",null,t("billing","Billing")),b().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 b().createElement("div",{className:"-esm-billing__cash-point-configuration__container___-hvwr"},b().createElement("div",{className:"-esm-billing__cash-point-configuration__card___ytTem"},b().createElement(d.CardHeader,{title:e("cashPointHistory","Cash point history")},b().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"))),b().createElement("div",null,b().createElement(h.bQt,{rows:n,headers:i,isSortable:!0,size:"lg"},({rows:e,headers:t,getTableProps:a,getHeaderProps:l,getRowProps:n})=>b().createElement(h.K3K,null,b().createElement(h.XIK,{className:"-esm-billing__cash-point-configuration__table___x+kW9",...a()},b().createElement(h.ndF,null,b().createElement(h.Hjg,null,t.map(e=>b().createElement(h.A0N,{key:e.key,...l({header:e})},e.header)))),b().createElement(h.BFY,null,e.map(e=>b().createElement(h.Hjg,{key:e.id,...n({row:e})},e.cells.map(e=>b().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?b().createElement(h.OuH,{status:"active",iconDescription:(0,d.getCoreTranslation)("loading"),description:e("loading","Loading data")+"..."}):a?b().createElement(d.ErrorState,{headerTitle:e("paymentMode","Payment mode"),error:a}):b().createElement("div",{className:"-esm-billing__payment-modes-config__container___hB7Cc"},b().createElement("div",{className:"-esm-billing__payment-modes-config__card___FGL9q"},b().createElement(d.CardHeader,{title:e("paymentModeHistory","Payment mode history")},b().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"))),b().createElement(h.bQt,{rows:n,headers:i,isSortable:!0,size:"lg"},({rows:e,headers:a,getTableProps:l,getHeaderProps:n,getRowProps:i})=>b().createElement(h.K3K,null,b().createElement(h.XIK,{className:"-esm-billing__payment-modes-config__table___Zs7R+",...l()},b().createElement(h.ndF,null,b().createElement(h.Hjg,null,a.map(e=>b().createElement(h.A0N,{key:e.key,...n({header:e})},e.header)))),b().createElement(h.BFY,null,e.map(e=>b().createElement(h.Hjg,{key:e.id,...i({row:e})},e.cells.map(a=>"actions"!==a.info.header?b().createElement(h.nA6,{key:a.id},a.value):b().createElement(h.nA6,{key:a.id},b().createElement(h.obU,null,b().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()}))}}),b().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(6335),U=a.n(x),$=a(7003);let j=`${$.B}billDiscount`,O=`${$.B}bill`;async function H(e){return(await (0,d.openmrsFetch)(j,{method:"POST",headers:{"Content-Type":"application/json"},body:e})).data}async function z(e,t,a){return(await (0,d.openmrsFetch)(`${j}/${e}`,{method:"POST",headers:{"Content-Type":"application/json"},body:{status:t,approver:a}})).data}async function V(e,t){await (0,d.openmrsFetch)(`${j}/${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 b().createElement(b().Fragment,null,b().createElement("div",{className:W.headerContainer},b().createElement("div",{className:k()({[W.tabletHeading]:!(0,d.isDesktop)(e),[W.desktopHeading]:(0,d.isDesktop)(e)})},b().createElement("h4",null,i("discountRequests","Discount requests"))),a&&b().createElement("div",{className:W.backgroundDataFetchingIndicator},b().createElement("span",null,b().createElement(h.OuH,null)))),b().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,p]=(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=`${O}?${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?b().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=>{p(e.target.value),S(1)},[S]);return b().createElement("main",{className:W.container},b().createElement("main",{className:W.servicesTableContainer},b().createElement("div",{className:W.filterContainer},b().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"})),b().createElement("div",{className:W.billListContainer},b().createElement(G,{handleSearch:L,isValidating:C,layout:n,responsiveSize:i,searchString:u,t:t}),y&&!E?.length?b().createElement("div",{className:W.loaderContainer,role:"progressbar","aria-label":t("loadingDescription","Loading")},b().createElement(h.OOb,{rowCount:c,showHeader:!1,showToolbar:!1,zebra:!0,columnCount:P.length})):f?b().createElement("div",{className:W.errorContainer},b().createElement(h.Wdr,null,b().createElement(d.ErrorState,{error:f,headerTitle:t("discountRequests","Discount requests")}))):I.length>0?b().createElement(b().Fragment,null,b().createElement(h.bQt,{isSortable:!0,rows:I,headers:P,size:i,useZebraStyles:I.length>1},({rows:e,headers:a,getRowProps:l,getTableProps:n})=>b().createElement(h.K3K,null,b().createElement(h.XIK,{...n(),"aria-label":t("discountRequests","Discount requests")},b().createElement(h.ndF,null,b().createElement(h.Hjg,null,a.map(e=>b().createElement(h.A0N,{key:e.key},e.header)))),b().createElement(h.BFY,null,e.map(e=>b().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=>b().createElement(h.nA6,{key:e.id},e.value)))))))),T&&b().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)}})):b().createElement(h.Wdr,{className:W.emptyStateContainer},b().createElement(h.FAs,{className:W.tile},b().createElement("div",{className:W.illo},b().createElement(d.EmptyCardIllustration,null)),b().createElement("p",{className:W.content},t("noDiscountRequestsToDisplay","There are no discount requests to display.")))))))};var J=a(8683);let Y={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 b().createElement(b().Fragment,null,b().createElement("div",{className:Y.headerContainer},b().createElement("div",{className:k()({[Y.tabletHeading]:!(0,d.isDesktop)(e),[Y.desktopHeading]:(0,d.isDesktop)(e)})},b().createElement("h4",null,i("refundRequests","Refund requests"))),a&&b().createElement("span",null,b().createElement(h.OuH,null))),b().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 X=()=>{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),[p,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=p.trim().toLowerCase();return e?y.filter(t=>t.patient?.display?.toLowerCase().includes(e)||t.receiptNumber?.toLowerCase().includes(e)):y},[y,p]),{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?b().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?b().createElement("div",{className:Y.loaderContainer,"aria-busy":"true","aria-label":a("loading","Loading")},b().createElement(h.OOb,{rowCount:m,showHeader:!1,showToolbar:!1,zebra:!0,columnCount:w.length})):v?b().createElement("div",{className:Y.errorContainer},b().createElement(h.Wdr,null,b().createElement(d.ErrorState,{error:v,headerTitle:a("refundRequests","Refund requests")}))):L.length>0?b().createElement(b().Fragment,null,b().createElement(h.bQt,{isSortable:!0,rows:L,headers:w,size:r,useZebraStyles:L.length>1},({rows:e,headers:t,getRowProps:l,getTableProps:n})=>b().createElement(h.K3K,null,b().createElement(h.XIK,{...n(),"aria-label":a("refundRequests","Refund requests")},b().createElement(h.ndF,null,b().createElement(h.Hjg,null,t.map(e=>b().createElement(h.A0N,{key:e.key},e.header)))),b().createElement(h.BFY,null,e.map(e=>b().createElement(h.Hjg,{key:e.id,...l({row:e}),className:Y.row,onClick:()=>B(e.id)},e.cells.map(e=>b().createElement(h.nA6,{key:e.id},e.value)))))))),S&&b().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)}})):b().createElement(h.Wdr,{className:Y.emptyStateContainer},b().createElement(h.FAs,{className:Y.tile},b().createElement("div",{className:Y.illo},b().createElement(d.EmptyCardIllustration,null)),b().createElement("p",{className:Y.content},a("noRefundRequestsToDisplay","There are no refund requests to display.")))),b().createElement("main",{className:Y.container},b().createElement("div",{className:Y.servicesTableContainer},b().createElement("div",{className:Y.filterContainer},b().createElement(h.msM,{className:Y.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"})),b().createElement("div",{className:Y.billListContainer},b().createElement(Z,{handleSearch:M,isValidating:N,layout:i,responsiveSize:r,searchString:p,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 b().createElement(h.Wdr,null,b().createElement(h.obU,{align:"left",flipped:!0,size:(0,d.isDesktop)(n)?"sm":"lg","data-testid":`action-menu-${e.uuid}`},b().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&&b().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,p,E]=o(["paymentDetails","paymentMethods","insuranceScheme","policyNumber","patientCategory"]),{paymentModes:y,isLoading:f}=(()=>{let e=`${$.B}paymentMode`,{data:t,isLoading:a,error:l}=U()(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,p,E,e,C]),f)?b().createElement(h.OuH,{status:"active",iconDescription:a("loadingDescription","Loading"),description:a("loading","Loading data")+"..."}):b().createElement(h.BJc,{className:eo.stack,gap:5},b().createElement(er.xI,{name:"paymentDetails",control:r,render:({field:e})=>b().createElement(h.zWQ,{className:eo.radioButtonGroup,legendText:b().createElement("div",{className:eo.paymentDetailsLegend},a("paymentDetails","Payment details"),b().createElement(h.Gff,{autoAlign:!0,align:"bottom"},b().createElement(h.yvu,{label:a("showInformation","Show information")},b().createElement(es.$$,null)),b().createElement(h.pNg,null,b().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"},b().createElement(h.aaP,{labelText:a("paying","Paying"),value:n.payingDetails,id:"payment-details-paying"}),b().createElement(h.aaP,{labelText:a("nonPaying","Non paying"),value:n.nonPayingDetails,id:"payment-details-non-paying"}))}),c===n.payingDetails&&b().createElement(er.xI,{control:r,name:"paymentMethods",render:({field:e})=>b().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&&b().createElement(b().Fragment,null,b().createElement(er.xI,{control:r,name:"insuranceScheme",render:({field:e})=>b().createElement(h.ksK,{id:"insurance-scheme",labelText:a("insuranceScheme","Insurance scheme"),onChange:t=>e.onChange(t.target.value),type:"text"})}),b().createElement(er.xI,{control:r,name:"policyNumber",render:({field:e})=>b().createElement(h.ksK,{...e,id:"policy-number",labelText:a("policyNumber","Policy number"),onChange:t=>e.onChange(t.target.value),type:"text"})})),c===n.nonPayingDetails&&b().createElement(er.xI,{control:r,name:"patientCategory",render:({field:e})=>b().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=b().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}=U()(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}=U()(e,d.openmrsFetch);return{isLoading:a,error:l,cashPoints:t?.data?.results??[]}})(),{lineItems:u,isLoading:p,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}=U()(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 p||c?b().createElement(h.OuH,{status:"active",iconDescription:(0,d.getCoreTranslation)("loading"),description:`${a("loadingBillingServices","Loading billing services")}...`}):m||E?b().createElement(h.jeF,{kind:"error",lowContrast:!0,title:a("billErrorService","Billing service error"),subtitle:a("errorLoadingBillServices","Error loading bill services")}):b().createElement("section",{className:"-esm-billing__billing-checkin-form__sectionContainer___TLb4u"},b().createElement("h1",{className:"-esm-billing__billing-checkin-form__sectionLabel___1H1hH"},a("billingDetails","Billing details")),b().createElement("div",{className:"-esm-billing__billing-checkin-form__sectionField___AUKom"},!r&&!s&&i&&b().createElement("div",{className:"-esm-billing__billing-checkin-form__lastVisitBanner___Bh8FX"},b().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})),b().createElement(em,{setAttributes:f,setPaymentMethod:C}),D.length>0&&b().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"},eb="-esm-billing__request-discount-modal__summaryLabel___VaWqh",ep="-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 b().createElement("section",{className:"-esm-billing__bill-line-items-table__ledger___qbKwi"},b().createElement("h3",{className:"-esm-billing__bill-line-items-table__ledgerHeading___M7DcA"},t("lineItems","Line items")),b().createElement("table",{className:"-esm-billing__bill-line-items-table__ledgerTable___Lw3pG"},b().createElement("thead",null,b().createElement("tr",null,b().createElement("th",null,t("item","Item")),b().createElement("th",null,t("qty","Qty")),b().createElement("th",{className:eE},t("price","Price")))),b().createElement("tbody",null,e.map((e,t)=>b().createElement("tr",{key:e.uuid??t},b().createElement("td",{className:"-esm-billing__bill-line-items-table__itemName___dKItf"},e.item||e.billableService||"--"),b().createElement("td",null,e.quantity),b().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:b().createElement("section",{className:"-esm-billing__bill-payments-table__ledger___Qc+ke"},b().createElement("h3",{className:"-esm-billing__bill-payments-table__ledgerHeading___ilV8F"},t("payments","Payments")),b().createElement("table",{className:"-esm-billing__bill-payments-table__ledgerTable___lHxsT"},b().createElement("thead",null,b().createElement("tr",null,b().createElement("th",null,t("method","Method")),b().createElement("th",null,t("date","Date")),b().createElement("th",{className:ey},t("tendered","Tendered")))),b().createElement("tbody",null,e.map(e=>b().createElement("tr",{key:e.uuid},b().createElement("td",null,b().createElement("span",{className:"-esm-billing__bill-payments-table__paymentKind___TglOe"},e.instanceType?.name??"--")),b().createElement("td",null,b().createElement("span",{className:"-esm-billing__bill-payments-table__paymentDate___9NyEF"},e.dateCreated?(0,d.formatDate)(new Date(e.dateCreated),{mode:"wide"}):"--")),b().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 b().createElement("section",{className:"-esm-billing__bill-totals-summary__totals___6iaM7"},b().createElement("div",{className:k()(ef,"-esm-billing__bill-totals-summary__totalsSubtotal___8mWZP")},b().createElement("span",null,r("subtotal","Subtotal")),b().createElement("span",null,(0,F.aL)(e,s))),n.map(e=>b().createElement("div",{key:e.uuid,className:k()(ef,ev)},b().createElement("span",null,"− ",r("discount","Discount")),b().createElement("span",null,(0,F.aL)(e.discountAmount,s)))),b().createElement("hr",{className:"-esm-billing__bill-totals-summary__totalsRule___LldMI"}),b().createElement("div",{className:k()(ef,"-esm-billing__bill-totals-summary__totalsNet___0Bb1l")},b().createElement("span",null,r("currentNet","Current net")),b().createElement("span",{className:"-esm-billing__bill-totals-summary__totalsNetAmount___xvxJT"},(0,F.aL)(t,s))),l>0&&b().createElement("div",{className:k()(ef,"-esm-billing__bill-totals-summary__totalsRowAdd___sbxAx")},b().createElement("span",null,"− ",r("paymentsReceived","Payments received")),b().createElement("span",null,(0,F.aL)(l,s))),b().createElement("hr",{className:"-esm-billing__bill-totals-summary__totalsRuleStrong___Kidyj"}),b().createElement("div",{className:k()(ef,"-esm-billing__bill-totals-summary__totalsOutstanding___fP1bD")},b().createElement("span",null,r("outstanding","Outstanding")),b().createElement("span",{className:"-esm-billing__bill-totals-summary__totalsOutstandingAmount___qQXu3"},(0,F.aL)(a,s))),i.length>0&&b().createElement("div",{className:"-esm-billing__bill-totals-summary__preview___rPSsf"},b().createElement("p",{className:"-esm-billing__bill-totals-summary__previewLabel___mjNu2"},r("ifPendingApproved","If pending discounts approved")),i.map(e=>b().createElement("div",{key:e.uuid,className:k()(ef,ev)},b().createElement("span",null,"− ",r("discount","Discount")," (",e.discountType===K.Bp.PERCENTAGE?`${e.discountValue}%`:(0,F.aL)(e.discountValue,s),")"),b().createElement("span",null,(0,F.aL)(e.discountAmount,s)))),b().createElement("div",{className:k()(ef,"-esm-billing__bill-totals-summary__previewProjected___bUPgY")},b().createElement("span",null,r("projectedNet","Projected net")),b().createElement("span",{className:"-esm-billing__bill-totals-summary__previewProjectedAmount___7yhBk"},(0,F.aL)(t-i.reduce((e,t)=>e+t.discountAmount,0),s)))))},eN=b().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 b().createElement("aside",{className:"-esm-billing__bill-receipt-rail__receipt___b5het"},b().createElement("div",{className:"-esm-billing__bill-receipt-rail__patient___gB6Df"},b().createElement("div",null,b().createElement("p",{className:"-esm-billing__bill-receipt-rail__patientName___dNAHq"},e.patient?.display),b().createElement("p",{className:"-esm-billing__bill-receipt-rail__patientId___2KJ7G"},c("receiptNumber","Receipt #"),": ",e.receiptNumber)),e.status&&b().createElement(h.vwO,{type:"blue",size:"sm"},c(String(e.status).toLowerCase(),String(e.status)))),b().createElement("dl",{className:"-esm-billing__bill-receipt-rail__meta___F8p9R"},b().createElement("dt",null,c("issued","Issued")),b().createElement("dd",null,e.dateCreated?(0,d.formatDate)((0,d.parseDate)(e.dateCreated),{mode:"wide"}):"--"),b().createElement("dt",null,c("cashier","Cashier")),b().createElement("dd",null,e.cashier?.display??"--")),b().createElement(eg,{lineItems:t}),b().createElement(eh,{payments:a}),b().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:p}=(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||"--":p("wholeBill","Whole bill");return b().createElement("article",{className:C},b().createElement("header",{className:"-esm-billing__discount-card__cardTop___2KfsR"},b().createElement("div",{className:"-esm-billing__discount-card__cardScope___DFbYt"},b().createElement("span",{className:"-esm-billing__discount-card__cardScopeName___e0Gom"},T),b().createElement("span",{className:"-esm-billing__discount-card__cardScopeKind___YgWB0"},e.discountType===K.Bp.PERCENTAGE?p("percentage","Percentage"):p("fixedAmount","Fixed amount"))),e.status!==K.nT.PENDING&&b().createElement(h.vwO,{type:eS[e.status],size:"sm"},p(e.status.toLowerCase(),e.status))),b().createElement("div",{className:"-esm-billing__discount-card__cardFigure___2fn-w"},b().createElement("span",{className:k()("-esm-billing__discount-card__cardAmount___IsWoS",{"-esm-billing__discount-card__cardAmountVoided___VNogb":e.status===K.nT.REJECTED})},b().createElement("span",{className:"-esm-billing__discount-card__cardAmountMinus___eSUgX"},"−"),(0,F.aL)(e.discountAmount,E)),e.discountType===K.Bp.PERCENTAGE&&b().createElement("span",{className:"-esm-billing__discount-card__cardValue___pIy2C"},N)),b().createElement("div",null,p("reasonForDiscount","Reason for discount"),": ",b().createElement("p",{className:"-esm-billing__discount-card__cardJustification___ZbW6e"},e.justification)),b().createElement("footer",{className:"-esm-billing__discount-card__cardFooter___AlFbq"},b().createElement("div",{className:"-esm-billing__discount-card__cardByline___r8xcx"},p("requestedBy","Requested by")," ",b().createElement("strong",null,e.initiator?.display),b().createElement("span",{className:"-esm-billing__discount-card__cardBylineSep___VM4YL"},"\xb7"),(0,d.formatDate)((0,d.parseDate)(e.dateCreated),{mode:"wide"})),b().createElement("div",{className:"-esm-billing__discount-card__cardActions___bvhbQ"},v&&e.status===K.nT.PENDING&&b().createElement(b().Fragment,null,b().createElement(h.$nd,{kind:"danger--tertiary",size:"sm",disabled:!!a||!i,onClick:()=>s(e.uuid)},p("reject","Reject")),b().createElement(h.$nd,{kind:"primary",size:"sm",disabled:!!a||!i,onClick:()=>r(e)},p("approve","Approve"))),v&&b().createElement(h.$nd,{kind:"danger",size:"sm",disabled:!!a,onClick:()=>m(e.uuid)},p("delete","Delete")),y&&b().createElement(b().Fragment,null,b().createElement("span",{className:eT},p("rejectConfirm","Reject this discount?")),b().createElement(h.$nd,{kind:"ghost",size:"sm",onClick:o},(0,d.getCoreTranslation)("cancel")),b().createElement(h.$nd,{kind:"danger",size:"sm",disabled:!!a,onClick:()=>c(e)},p("confirmReject","Confirm reject"))),f&&b().createElement(b().Fragment,null,b().createElement("span",{className:eT},p("deleteConfirm","Delete this discount?")),b().createElement(h.$nd,{kind:"ghost",size:"sm",onClick:u},(0,d.getCoreTranslation)("cancel")),b().createElement(h.$nd,{kind:"danger",size:"sm",disabled:!!a,onClick:()=>_(e)},p("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=b().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:p}=(0,g.useTranslation)(),E=e=>b().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 b().createElement("section",{className:"-esm-billing__discount-review-stack__review___7I6RE"},e.length>0&&b().createElement("div",null,b().createElement("div",{className:eD},b().createElement("h3",{className:eA},p("pendingDiscounts","Pending discounts")),b().createElement("span",{className:eP},e.length)),b().createElement("div",{className:ew},e.map(E))),t.length>0&&b().createElement("div",null,b().createElement("div",{className:eD},b().createElement("h3",{className:eA},p("confirmedDiscounts","Confirmed discounts")),b().createElement("span",{className:eP},t.length)),b().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",datePickerContainer:"-esm-billing__bills-table__datePickerContainer___Ss4P3",clearDatesButton:"-esm-billing__bills-table__clearDatesButton___ZS5e8",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 b().createElement(b().Fragment,null,b().createElement("div",{className:eM.headerContainer},b().createElement("div",{className:k()({[eM.tabletHeading]:!(0,d.isDesktop)(e),[eM.desktopHeading]:(0,d.isDesktop)(e)})},b().createElement("h4",null,i("billList","Bill list"))),a&&b().createElement("div",{className:eM.backgroundDataFetchingIndicator},b().createElement("span",null,b().createElement(h.OuH,null)))),b().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),[p,E]=(0,_.useState)(null),[y,f]=(0,_.useState)(null),{bills:v,error:C,currentPage:N,isLoading:T,isValidating:S,totalCount:k,goTo:D}=(0,ee.fu)(l,s.status,u||void 0,p,y),A=[{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"}],P=(0,_.useMemo)(()=>v?.map(e=>({...e,id:String(e.id),dateCreated:e.dateCreated?(0,d.formatDate)((0,d.parseDate)(e.dateCreated),{mode:"wide"}):"--",receiptNumberDisplay:b().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(" & ")})),[v]),w=""!==c.trim()||""!==s.id||null!==p||null!==y,I=(0,_.useCallback)(e=>{D(1),m(e.target.value)},[D,m]),L=(0,_.useCallback)(({selectedItem:e})=>{o(e),D(1)},[D]),M=(0,_.useCallback)(e=>{E(e??null),D(1)},[D]),B=(0,_.useCallback)(e=>{f(e??null),D(1)},[D]),R=(0,_.useCallback)(()=>{E(null),f(null),D(1)},[D]);return b().createElement(b().Fragment,null,b().createElement("div",{className:eM.filterContainer},b().createElement(h.msM,{className:eM.filterDropdown,direction:"bottom",id:"bill-payment-status-filter",selectedItem:s,items:r,itemToString:e=>e?e.text:"",label:"",onChange:L,size:i,titleText:e("filterBy","Filter by:"),type:"inline"}),b().createElement("div",{className:eM.datePickerContainer},b().createElement(d.OpenmrsDatePicker,{id:"bill-start-date-filter",labelText:e("from","From"),maxDate:y,value:p,onChange:M,size:i}),b().createElement(d.OpenmrsDatePicker,{id:"bill-end-date-filter",labelText:e("to","To"),minDate:p,value:y,onChange:B,size:i,invalidText:e("endDateBeforeStartDate","End date must be after the start date")}),p||y?b().createElement(h.$nd,{className:eM.clearDatesButton,kind:"ghost",onClick:R,size:i},e("clearDates","Clear dates")):null)),T&&!v?.length?b().createElement("div",{className:eM.loaderContainer,"data-testid":"bills-table-skeleton"},b().createElement(h.OOb,{rowCount:l,showHeader:!1,showToolbar:!1,zebra:!0,columnCount:A?.length})):C?b().createElement("div",{className:eM.errorContainer},b().createElement(h.Wdr,null,b().createElement(d.ErrorState,{error:C,headerTitle:e("billList","Bill list")}))):P?.length>0||w?b().createElement("div",{className:eM.billListContainer},b().createElement(eB,{handleSearch:I,isValidating:S,layout:t,responsiveSize:i,searchString:c,t:e}),b().createElement(h.bQt,{isSortable:!0,rows:P,headers:A,size:i,useZebraStyles:P?.length>1},({rows:t,headers:a,getRowProps:l,getTableProps:n})=>b().createElement(h.K3K,null,b().createElement(h.XIK,{...n(),"aria-label":e("billList","Bill list")},b().createElement(h.ndF,null,b().createElement(h.Hjg,null,a.map(e=>b().createElement(h.A0N,{key:e.key},e.header)))),b().createElement(h.BFY,null,t.map(e=>b().createElement(h.Hjg,{key:e.id,...l({row:e})},e.cells.map(e=>b().createElement(h.nA6,{key:e.id},e.value)))))))),P?.length===0&&b().createElement("div",{className:eM.filterEmptyState},b().createElement(h.Wdr,{level:0},b().createElement(h.FAs,{className:eM.filterEmptyStateTile},b().createElement("p",{className:eM.filterEmptyStateContent},e("noMatchingBillsToDisplay","No matching bills to display")),b().createElement("p",{className:eM.filterEmptyStateHelper},e("checkFilters","Check the filters above"))))),k>0&&b().createElement(h.dKS,{forwardText:e("nextPage","Next page"),backwardText:e("previousPage","Previous page"),page:N,pageSize:l,pageSizes:[10,20,30,40,50],totalItems:k,onChange:({pageSize:e,page:t})=>{e!==l?(n(e),D(1)):t!==N&&D(t)}})):b().createElement(h.Wdr,{className:eM.emptyStateContainer},b().createElement(h.FAs,{className:eM.tile},b().createElement("div",{className:eM.illo},b().createElement(d.EmptyCardIllustration,null)),b().createElement("p",{className:eM.content},e("noBillsToDisplay","There are no bills to display.")))))};function eq(){let{t:e}=(0,g.useTranslation)();return b().createElement(b().Fragment,null,b().createElement(M,{title:e("home","Home")}),b().createElement("section",{className:"-esm-billing__billing-dashboard__billsTableContainer___XBT2N"},b().createElement(eR,null)))}var eF=a(7240);let ex=({label:e,value:t,hasBalance:a})=>b().createElement("div",{className:"-esm-billing__invoice-breakdown__invoiceBreakdown___IGWfb"},b().createElement("span",{className:a?"-esm-billing__invoice-breakdown__extendedLabel___fJ78V":"-esm-billing__invoice-breakdown__label___WpAJx"},e,": "),b().createElement("span",{className:"-esm-billing__invoice-breakdown__value___L3Y8v"},t)),eU={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"})},ej=({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}=U()(e,d.openmrsFetch,eU);return{paymentModes:t?.data?.results??[],isLoading:a,mutate:n,error:l}})();return i?b().createElement(h.Rzj,null):r?b().createElement("div",{className:"-esm-billing__payment-form__errorPaymentContainer___Ft9DN"},b().createElement(d.ErrorState,{headerTitle:t("errorLoadingPaymentModes","Error loading payment modes"),error:r})):e?null:b().createElement("div",{className:"-esm-billing__payment-form__container___P4SMq"},b().createElement("div",{className:"-esm-billing__payment-form__paymentMethodContainer___fZiwB"},b().createElement(er.xI,{control:a,name:"payment.method",render:({field:e})=>b().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})}),b().createElement(er.xI,{control:a,name:"payment.amount",render:({field:e})=>b().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??""})}),b().createElement(er.xI,{name:"payment.referenceCode",control:a,render:({field:e})=>b().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??""})})))},eO=({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 b().createElement(h.bQt,{size:"sm",rows:n,headers:l},({rows:e,headers:t,getTableProps:a,getHeaderProps:l,getRowProps:n})=>b().createElement(h.XIK,a(),b().createElement(h.ndF,null,b().createElement(h.Hjg,null,t.map(e=>b().createElement(h.A0N,l({header:e}),e.header)))),b().createElement(h.BFY,null,e.map(e=>b().createElement(h.Hjg,n({row:e}),e.cells.map(e=>b().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.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),p=(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 b().createElement(er.Op,m,b().createElement("div",{className:"-esm-billing__payments__wrapper___V4WiR"},b().createElement("div",{className:"-esm-billing__payments__paymentContainer___1SfXU"},b().createElement(d.CardHeader,{title:l("payments","Payments")},b().createElement("span",null)),b().createElement("div",null,E?b().createElement("div",{className:"-esm-billing__payments__pendingEmptyState___jUFD7"},b().createElement(h.Wdr,null,b().createElement(h.FAs,{className:"-esm-billing__payments__pendingEmptyStateTile___q+iuz"},b().createElement("p",{className:"-esm-billing__payments__pendingEmptyStateContent___B8pVF"},l("billNotFinalized","Bill not finalized")),b().createElement("p",{className:"-esm-billing__payments__pendingEmptyStateHelper___amDGw"},l("finalizeBillToRecordPayment","Finalize this bill before recording a payment.")),b().createElement(h.$nd,{className:"-esm-billing__payments__finalizeButton___nCnCg",kind:"primary",size:"sm",onClick:a},l("finalizeBill","Finalize bill"))))):b().createElement(b().Fragment,null,b().createElement(eO,{bill:e}),b().createElement(ej,{disablePayment:p<=0})))),b().createElement("div",{className:"-esm-billing__payments__divider___C6sdr"}),b().createElement("div",{className:"-esm-billing__payments__paymentTotals___-3A2t"},b().createElement(ex,{label:l("totalAmount","Total amount"),value:(0,F.aL)(e.totalAmount??0,o)}),b().createElement(ex,{label:l("totalTendered","Total tendered"),value:(0,F.aL)(e.tenderedAmount??0,o)}),b().createElement(ex,{label:l("discount","Discount"),value:`- ${(0,F.aL)((e.totalAmount??0)-(e.netAmount??0),o)}`}),b().createElement(ex,{label:l("refunds","Refunds"),value:`- ${(0,F.aL)(_,o)}`}),b().createElement(ex,{hasBalance:p<0,label:l("amountDue","Amount due"),value:(0,F.aL)(p,o)}),b().createElement("div",{className:"-esm-billing__payments__processPayments___RG8aV"},b().createElement(h.$nd,{onClick:()=>(0,d.navigate)({to:window.getOpenmrsSpaBase()+"home/billing"}),kind:"secondary"},l("discard","Discard")),!E&&b().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 b().createElement(h.$nd,{kind:"secondary",className:"-esm-billing__print-receipt__button___QnAQS",renderIcon:e=>b().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?b().createElement("div",{className:"-esm-billing__printable-footer__container___mTh7B"},b().createElement("p",{className:"-esm-billing__printable-footer__itemFooter___Y5pkL"},e?.display)):b().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",eY=({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 b().createElement("div",{className:"-esm-billing__printable-invoice-header__container___1u0nI"},b().createElement("div",{className:"-esm-billing__printable-invoice-header__printableHeader___Jl02J"},b().createElement("div",{className:"-esm-billing__printable-invoice-header__logo___ZpVka"},n?.src&&!eW()(n.src)?b().createElement("img",{className:eG,src:(0,d.interpolateUrl)(n.src),alt:n.alt}):n?.alt&&!eW()(n.alt)?n.alt:b().createElement("svg",{className:eG,role:"img",width:110,height:40,viewBox:"0 0 380 119",xmlns:"http://www.w3.org/2000/svg"},b().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"}))),b().createElement("div",{className:"-esm-billing__printable-invoice-header__facilityDetails___uJPtI"},b().createElement("p",{className:"-esm-billing__printable-invoice-header__facilityName___81nN9"},t?.display),b().createElement("p",{className:eJ},i))),b().createElement("h1",{className:"-esm-billing__printable-invoice-header__invoiceHeading___9Xftg"},l("invoice","Invoice")),b().createElement("div",{className:"-esm-billing__printable-invoice-header__printableBody___cMhfI"},b().createElement("div",{className:"-esm-billing__printable-invoice-header__detailsContainer___rJn9A"},b().createElement("div",null,b().createElement("h2",{className:eQ},l("patientInformation","Patient information")),Object.entries(o).map(([e,t])=>b().createElement("p",{className:eJ,key:e},b().createElement("strong",null,e),b().createElement("span",null,": ",t)))),b().createElement("div",null,b().createElement("h2",{className:eQ},l("invoiceSummary","Invoice summary")),Object.entries(s).map(([e,t])=>b().createElement("p",{className:eJ,key:e},b().createElement("strong",null,e),b().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"},eX=({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]),p=(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 b().createElement("div",{className:eZ.container,ref:a},b().createElement(eY,{patientDetails:p,defaultFacility:l,bill:e}),b().createElement("div",{className:eZ.itemsContainer},b().createElement("div",{className:eZ.tableContainer},b().createElement(h.bQt,{rows:c,headers:o,size:s,useZebraStyles:!1},({rows:e,headers:t,getRowProps:a,getTableProps:l})=>b().createElement(h.K3K,null,b().createElement(h.XIK,{...l(),"aria-label":n("invoiceLineItems","Invoice line items")},b().createElement(h.ndF,null,b().createElement(h.Hjg,null,t.map(e=>b().createElement(h.A0N,{key:e.key},e.header)))),b().createElement(h.BFY,null,e.map(e=>b().createElement(h.Hjg,{key:e.id,...a({row:e})},e.cells.map(e=>b().createElement(h.nA6,{key:e.id},e.value)))))))),e?.netAmount!=null&&e.totalAmount!==e.netAmount?b().createElement(b().Fragment,null,b().createElement("div",{className:eZ.balanceContainer},b().createElement("span",{className:eZ.itemHeading},n("subtotal","Subtotal"),":")," ",b().createElement("span",{className:eZ.itemLabel},b().createElement("strong",null,r," ",e?.totalAmount))),b().createElement("div",{className:eZ.balanceContainer},b().createElement("span",{className:eZ.itemHeading},n("discount","Discount"),":")," ",b().createElement("span",{className:eZ.itemLabel},b().createElement("strong",null,"- ",r," ",(e?.totalAmount??0)-(e?.netAmount??0)))),b().createElement("div",{className:eZ.balanceContainer},b().createElement("span",{className:eZ.itemHeading},n("totalAmount","Total amount"),":")," ",b().createElement("span",{className:eZ.itemLabel},b().createElement("strong",null,r," ",e?.netAmount)))):b().createElement("div",{className:eZ.balanceContainer},b().createElement("span",{className:eZ.itemHeading},n("totalAmount","Total amount"),":")," ",b().createElement("span",{className:eZ.itemLabel},b().createElement("strong",null,r," ",e?.totalAmount))),e?.payments?.length>0&&b().createElement("div",{className:eZ.paymentHistoryContainer},b().createElement(h.bQt,{rows:u,headers:m,size:s},({rows:e,headers:t,getRowProps:a,getTableProps:l})=>b().createElement(h.K3K,null,b().createElement(h.XIK,{...l(),"aria-label":n("paymentHistory","Payment History")},b().createElement(h.ndF,null,b().createElement(h.Hjg,null,t.map(e=>b().createElement(h.A0N,{key:e.key},e.header)))),b().createElement(h.BFY,null,e.map(e=>b().createElement(h.Hjg,{key:e.id,...a({row:e})},e.cells.map(e=>b().createElement(h.nA6,{key:e.id},e.value))))))))),b().createElement("div",{className:eZ.balanceContainer},b().createElement("span",{className:eZ.itemHeading},n("totalTendered","Total tendered"),":"),b().createElement("span",{className:eZ.itemLabel},b().createElement("strong",null,r," ",e?.tenderedAmount))),b().createElement("div",{className:eZ.balanceContainer},b().createElement("span",{className:eZ.itemHeading},n("balance","Balance"),":"),b().createElement("span",{className:eZ.itemLabel},b().createElement("strong",null,r," ",e?.netAmount-e?.tenderedAmount))))),b().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?b().createElement("div",{className:"-esm-billing__discounts-table__discountsWrapper___nAknV"},b().createElement(h.bQt,{headers:r,rows:s,size:n,useZebraStyles:!0,overflowMenuOnHover:(0,d.isDesktop)(l)},({rows:e,headers:a,getRowProps:l,getTableProps:n})=>b().createElement(h.K3K,{description:b().createElement("span",{className:"-esm-billing__discounts-table__tableDescription___dsPxA"},b().createElement("span",null,t("discountsAppliedToBill","Discounts applied to this bill"))),title:t("discounts","Discounts")},b().createElement(h.XIK,{...n(),"aria-label":t("billDiscounts","Bill discounts"),className:k()("-esm-billing__discounts-table__discountsTable___Wd5vG","billingTable")},b().createElement(h.ndF,null,b().createElement(h.Hjg,null,a.map(e=>b().createElement(h.A0N,{key:e.key},e.header)))),b().createElement(h.BFY,null,e.map(e=>b().createElement(h.Hjg,{key:e.id,...l({row:e})},e.cells.map(e=>b().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]),p=(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:b().createElement(h.$nd,{kind:"primary",size:"sm",disabled:s===t.uuid||t.status!==K.fH.APPROVED,onClick:()=>u(t)},s===t.uuid?b().createElement(h.OuH,{description:a("processing","Processing")+"..."}):a("processRefund","Process refund"))})),[m,e,l,s,a,u]);return m&&0!==m.length?b().createElement("div",{className:"-esm-billing__refunds-table__refundsWrapper___ZvDhw"},b().createElement(h.bQt,{headers:c,rows:p,size:r,useZebraStyles:!0},({rows:e,headers:t,getRowProps:l,getTableProps:n})=>b().createElement(h.K3K,{description:b().createElement("span",{className:"-esm-billing__refunds-table__tableDescription___hGPCT"},b().createElement("span",null,a("refundsOnBill","Refunds on this bill"))),title:a("refunds","Refunds")},b().createElement(h.XIK,{...n(),"aria-label":a("billRefunds","Bill refunds"),className:k()("-esm-billing__refunds-table__refundsTable___B5xVc","billingTable")},b().createElement(h.ndF,null,b().createElement(h.Hjg,null,t.map(e=>b().createElement(h.A0N,{key:e.key},e.header)))),b().createElement(h.BFY,null,e.map(e=>b().createElement(h.Hjg,{key:e.id,...l({row:e})},e.cells.map(e=>b().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;
|