import{S as H,ar as ve,q as Q,_ as N,as as fe,t as ye,j as K,F as be}from"./billing-356772f3.js";import{f as xe,G as E,r as h,d as ge,aj as j,h as l,k as d,x as e,ag as r,u as n,B as z,F as y,ak as A,D as c,A as b,y as I,j as G,s as x,i as M,p as we,e as ke,al as Ce,_ as Be}from"./_plugin-vue_export-helper-3f67fb71.js";import{A as Te,a as Ae}from"./billing.mutations-59bfac39.js";import{c as Ie,a as O,d as Ve,u as Se,b as R}from"./array-a5aedee5.js";import{b as q,a as g,d as Pe,v as $}from"./runtime-dom.esm-bundler-6e07ef74.js";function Ue(){const{withClientQuery:u}=Q();return{downloadInvoice:async S=>{try{await H.fire({title:"Are you sure?",text:"You want to download this invoice",icon:"warning",showCancelButton:!0,confirmButtonColor:"#3085d6",cancelButtonColor:"#d33",confirmButtonText:"Yes, download now!",cancelButtonText:"No, do not download!"}).then(async p=>{p.isConfirmed&&(u(ve,{billUid:S},"billInvoiceCreate","network-only").then(w=>{const m=document.createElement("a");m.href=`data:application/pdf;base64,${w}`,m.setAttribute("download","invoice-report.pdf"),m.click()}),await H.fire("Its Happening!","Downloading .....","success").then(w=>{}))})}catch{}}}}const o=u=>(we("data-v-afb0e1b5"),u=u(),ke(),u),De={class:"mt-4"},Fe=o(()=>e("h4",{class:"text-sm text-gray-800 font-bold"},"Patient's Order Bills",-1)),Le=o(()=>e("hr",null,null,-1)),Ne={class:"grid grid-cols-12 gap-4 mt-2"},Ee={initial:{opacity:0,y:100},enter:{opacity:1,y:0,scale:1},variants:{custom:{scale:2}},delay:400,class:"col-span-3 overflow-y-scroll overscroll-contain billing-scroll"},je={key:0,class:"py-4 text-center bg-white w-full mb-1 rounded-sm shadow border"},Me={key:1},Oe=["onClick"],Re={class:"flex-grow p-1"},qe={class:"font-semibold text-gray-800"},$e={class:"text-sm text-gray-400"},Ye={initial:{opacity:0,y:-100},enter:{opacity:1,y:0,scale:1},variants:{custom:{scale:2}},delay:400,class:"col-span-9"},We={class:"bg-white rounded-sm shadow-sm hover:shadow-xs duration-500 px-4 sm:px-6 md:px-2 py-4"},He={class:"flex justify-between items-center"},Ke={class:"text-gray-800 text-l font-bold"},ze=o(()=>e("hr",null,null,-1)),Ge={class:"grid grid-cols-3 gap-x-8"},Qe={class:"col-span-1"},Je={class:"flex justify-between items-center mt-2"},Xe=o(()=>e("span",{class:"text-gray-800 text-sm font-semibold"},"Active:",-1)),Ze={class:"text-gray-600 text-sm md:text-md"},et={class:"flex justify-between items-center mt-2"},tt=o(()=>e("span",{class:"text-gray-800 text-sm font-semibold"},"Confirmed:",-1)),st={class:"text-gray-600 text-sm md:text-md"},ot={class:"col-span-1"},nt={class:"flex justify-between items-center mt-2"},at=o(()=>e("span",{class:"text-gray-800 text-sm font-semibold"},"Total Charged:",-1)),lt={class:"text-gray-600 text-sm md:text-md"},it={class:"flex justify-between items-center mt-2"},dt=o(()=>e("span",{class:"text-gray-800 text-sm font-semibold"},"Total Paid:",-1)),ct={class:"text-gray-600 text-sm md:text-md"},rt={class:"col-span-1"},ut={class:"flex justify-between items-center mt-2"},mt=o(()=>e("span",{class:"text-gray-800 text-sm font-semibold"},"Partial:",-1)),_t={class:"text-gray-600 text-sm md:text-md"},ht={class:"mt-4"},pt={class:"flex justify-between items-center"},vt=o(()=>e("h4",{class:"text-gray-800 text-l font-semibold"},"Order Items",-1)),ft=o(()=>e("hr",null,null,-1)),yt={class:"mt-4 bg-white rounded-sm shadow-sm hover:shadow-xs duration-500 px-4 sm:px-6 md:px-2 py-4"},bt={class:"text-gray-400"},xt={class:"ml-2 text-md leading-5 text-sky-600"},gt={class:"mt-4"},wt={class:"flex justify-between items-center"},kt=o(()=>e("h4",{class:"text-gray-800 text-l font-semibold"},"Transactions",-1)),Ct=["onClick"],Bt=["onClick"],Tt=o(()=>e("hr",null,null,-1)),At={class:"mt-4 bg-white rounded-sm shadow-sm hover:shadow-xs duration-500 px-4 sm:px-6 md:px-2 py-4"},It=o(()=>e("h3",null,"Transaction Form",-1)),Vt={class:"grid grid-cols-2 gap-x-4 mb-4"},St={class:"whitespace-nowrap mb-2 w-full"},Pt=o(()=>e("span",{class:"text-gray-700 w-4/12"},"Kind of payment",-1)),Ut={class:"w-full"},Dt=o(()=>e("option",null,null,-1)),Ft=["value"],Lt={class:"text-orange-600 w-4/12"},Nt={class:"block col-span-1 mb-2"},Et=o(()=>e("span",{class:"text-gray-700"},"Amount",-1)),jt={class:"grid grid-cols-4 gap-x-4 mb-4"},Mt={class:"block col-span-4 mb-2"},Ot=o(()=>e("span",{class:"text-gray-700"},"Notes",-1)),Rt=o(()=>e("hr",null,null,-1)),qt=o(()=>e("h3",null,"Apply Voucher Code Form",-1)),$t={class:"grid grid-cols-2 gap-x-4 mb-4"},Yt={class:"block col-span-2 mb-2"},Wt=o(()=>e("span",{class:"text-gray-700"},"Voucher Code:",-1)),Ht=o(()=>e("hr",null,null,-1)),Kt=["onClick"],zt=xe({__name:"PatientBill",props:{patientUid:String},setup(u){const V=u,S=E(()=>N(()=>import("./LoadingMessage-83976fce.js"),["assets/LoadingMessage-83976fce.js","assets/_plugin-vue_export-helper-3f67fb71.js"])),p=E(()=>N(()=>import("./SimpleModal-1f91868a.js"),["assets/SimpleModal-1f91868a.js","assets/_plugin-vue_export-helper-3f67fb71.js","assets/runtime-dom.esm-bundler-6e07ef74.js","assets/SimpleModal-f645a074.css"])),w=E(()=>N(()=>import("./DataTable-6e858f1d.js"),["assets/DataTable-6e858f1d.js","assets/_plugin-vue_export-helper-3f67fb71.js","assets/runtime-dom.esm-bundler-6e07ef74.js"])),{withClientMutation:m}=Q(),k=fe(),J=ye(),{bills:Y,fetchingBills:X,transactions:Z,fetchingTransactions:ee}=K(k),{analysisRequests:te}=K(J);k.fetchBillsForPatient(V?.patientUid);const se=h(["cash","medical-aid","e-payment"]),P=h(!1),a=h({}),oe=i=>{a.value={...i},k.fetchBillTransactions(i.uid)},ne=ge(()=>{const i=a?.value?.orders?.map(s=>s.uid)??[];return te?.value?.filter(s=>i.includes(s.uid))});function ae(i,s){let _=[];return i.forEach(v=>_.push(v.name)),s.forEach(v=>_.push(v.name)),_.join(", ")}const le=Ie({testBillUid:O().required(),kind:O().required(),amount:Ve().required(),notes:O().nullable()}),{handleSubmit:ie,errors:C,setFieldValue:B}=Se({validationSchema:le,initialValues:{testBillUid:a.value?.uid}}),{value:U}=R("kind"),{value:D}=R("amount"),{value:F}=R("notes"),W=ie(i=>ce(i)),de=()=>{B("testBillUid",a.value?.uid),B("kind","cash"),B("amount",+a?.value?.totalCharged-+a?.value?.totalPaid),B("notes",""),P.value=!0},ce=i=>{m(Te,{payload:i},"createTestBillTransaction").then(s=>k.addTransaction(s))},re=h([{name:"Kind",value:"kind",sortable:!0,sortBy:"asc",defaultSort:!0,showInToggler:!1,hidden:!1},{name:"Amount",value:"amount",sortable:!1,sortBy:"asc",hidden:!1},{name:"Success",value:"isSuccess",sortable:!1,sortBy:"asc",hidden:!1},{name:"Notes",value:"notes",sortable:!1,sortBy:"asc",hidden:!1},{name:"Message",value:"message",sortable:!1,sortBy:"asc",hidden:!1},{name:"Processed",value:"processed",sortable:!1,sortBy:"asc",hidden:!1}]),L=h(!1),T=h({code:""}),ue=()=>{L.value=!0},me=()=>{m(Ae,{payload:{voucherCode:T.value?.code,testBillUid:a.value?.uid,customerUid:V.patientUid}},"applyVoucher").then(i=>{})},{downloadInvoice:_e}=Ue(),he=async i=>await _e(i.uid);return(i,s)=>{const _=j("motion"),v=j("motion-slide-top"),pe=j("motion-slide-right");return l(),d(y,null,[e("div",De,[Fe,Le,e("div",Ne,[r((l(),d("section",Ee,[n(X)?(l(),d("div",je,[z(n(S),{message:"Fetching bills ..."})])):(l(),d("div",Me,[e("ul",null,[(l(!0),d(y,null,A(n(Y),t=>(l(),d("li",{key:t.uid,class:x(["bg-white w-full flex items-center p-1 mb-1 rounded-sm shadow border",{"border-sky-800 bg-emerald-200":t.uid===a.value.uid}]),onClick:f=>oe(t)},[e("div",Re,[e("div",qe,[e("div",null,c(t.billId?.toLocaleUpperCase()),1),e("div",$e,c(n(be)(t.createdAt)),1)])])],10,Oe))),128))])]))])),[[_]]),r((l(),d("section",Ye,[r((l(),d("div",We,[e("div",He,[e("h4",Ke,c(a.value.billId?.toLocaleUpperCase()),1)]),ze,e("section",Ge,[e("div",Qe,[e("div",Je,[Xe,e("span",Ze,c(a.value.isActive?"Yes":"No"),1)]),e("div",et,[tt,e("span",st,c(a.value?.toConfirm?"No":"Yes"),1)])]),e("div",ot,[e("div",nt,[at,e("span",lt,c(a.value?.totalCharged),1)]),e("div",it,[dt,e("span",ct,c(a.value?.totalPaid),1)])]),e("div",rt,[e("div",ut,[mt,e("span",_t,c(a.value?.totalPaidhe(a.value),["prevent"]))}," Invoice ")]),ft,e("ul",yt,[(l(!0),d(y,null,A(n(ne),t=>(l(),d("li",{class:"font-semibold",key:t.uid},[e("div",null,c(t?.requestId)+" ("+c(t?.clientRequestId)+")",1),(l(!0),d(y,null,A(t.samples,f=>r((l(),d("div",{class:"ml-4 text-sm",key:f.uid},[e("span",bt,c(f.sampleId),1),Ce(" ⇒ "),e("span",xt,c(ae(f.profiles??[],f.analyses??[])),1)])),[[pe]])),128))]))),128))])]),e("div",gt,[e("div",wt,[kt,e("div",null,[r(e("button",{class:"px-2 py-1 mr-2 border-sky-800 border text-sky-800 rounded-sm transition duration-300 hover:bg-sky-800 hover:text-white focus:outline-none",onClick:g(de,["prevent"])}," Add Transaction ",8,Ct),[[q,a.value.isActive]]),r(e("button",{class:"ml-4 px-2 py-1 mr-2 border-sky-800 border text-sky-800 rounded-sm transition duration-300 hover:bg-sky-800 hover:text-white focus:outline-none",onClick:g(ue,["prevent"])}," Apply Voucher ",8,Bt),[[q,a.value.isActive]])])]),Tt,e("div",At,[z(n(w),{columns:re.value,data:n(Z),toggleColumns:!1,loading:n(ee),paginable:!1,searchable:!1,filterable:!1,selectable:!1},{footer:b(()=>[]),_:1},8,["columns","data","loading"])])])])),[[q,n(Y)?.length>0&&a.value.uid],[_]])])]),I(" Transaction Form Modal "),P.value?(l(),G(n(p),{key:0,onClose:s[5]||(s[5]=t=>P.value=!1),contentWidth:"w-3/6"},{header:b(()=>[It]),body:b(()=>[e("form",null,[e("div",Vt,[e("label",St,[Pt,e("div",Ut,[r(e("select",{class:x(["form-select mt-1 w-full",{"border-red-500 animate-pulse":n(C).kind}]),"onUpdate:modelValue":s[1]||(s[1]=t=>M(U)?U.value=t:null)},[Dt,(l(!0),d(y,null,A(se.value,t=>(l(),d("option",{key:t,value:t},c(t),9,Ft))),128))],2),[[Pe,n(U)]]),e("div",Lt,c(n(C).gender),1)])]),e("label",Nt,[Et,r(e("input",{class:x(["form-input mt-1 block w-full",{"border-red-500 animate-pulse":n(C).amount}]),type:"number","onUpdate:modelValue":s[2]||(s[2]=t=>M(D)?D.value=t:null)},null,2),[[$,n(D)]])])]),e("div",jt,[e("label",Mt,[Ot,r(e("input",{class:x(["form-input mt-1 block w-full",{"border-red-500 animate-pulse":n(C).notes}]),type:"number",min:"1","onUpdate:modelValue":s[3]||(s[3]=t=>M(F)?F.value=t:null)},null,2),[[$,n(F)]])])]),Rt,e("button",{type:"submit",class:"-mb-4 border border-sky-800 bg-sky-800 text-white rounded-sm px-2 py-1 mt-2 transition-colors duration-500 ease select-none hover:bg-sky-800 focus:outline-none focus:shadow-outline",onClick:s[4]||(s[4]=g((...t)=>n(W)&&n(W)(...t),["prevent"]))}," Save Transaction ")])]),_:1})):I("v-if",!0),I(" Voucher Code Form Modal "),L.value?(l(),G(n(p),{key:1,onClose:s[7]||(s[7]=t=>L.value=!1),contentWidth:"w-1/5"},{header:b(()=>[qt]),body:b(()=>[e("form",null,[e("div",$t,[e("label",Yt,[Wt,r(e("input",{class:x(["form-input mt-1 block w-full",{"border-red-500 animate-pulse":!T.value.code}]),type:"text","onUpdate:modelValue":s[6]||(s[6]=t=>T.value.code=t)},null,2),[[$,T.value.code]])])]),Ht,e("button",{type:"submit",class:"-mb-4 border border-sky-800 bg-sky-800 text-white rounded-sm px-2 py-1 mt-2 transition-colors duration-500 ease select-none hover:bg-sky-800 focus:outline-none focus:shadow-outline",onClick:g(me,["prevent"])}," Apply Voucher ",8,Kt)])]),_:1})):I("v-if",!0)],64)}}});const es=Be(zt,[["__scopeId","data-v-afb0e1b5"],["__file","/home/aurthurm/Development/felicity-lims/webapp/views/patient/_id/PatientBill.vue"]]);export{es as default};