1import{r as m,j as e}from"./index-DY445dpH.js";import{u as $,aj as E,s as Q,ax as V,c as I,d as U,B as u,A as G,cL as H,o as K}from"./App-KLoqlvE_.js";import{C as N}from"./checkbox-DKlnVkyT.js";import{c as J}from"./usePharmaQuoteRequests-Cb-ewxf6.js";import{u as W}from"./usePharmaBranches-BW5QdtJR.js";import{q as P}from"./number-CQ8_qA1Y.js";import{P as X}from"./calculator-B-Ji9MGa.js";import{P as Y}from"./printer-B5WLQFVy.js";import{F as Z}from"./file-down-CX6qtKb8.js";function ee(){const{profile:n,isLoading:c}=$();return E({queryKey:["organization-settings",n==null?void 0:n.organization_id],queryFn:async()=>{if(!(n!=null&&n.organization_id))return null;const{data:i,error:s}=await Q.from("organizations").select("id, name, whatsapp_dms_enabled").eq("id",n.organization_id).single();if(s)throw s;return i},enabled:!!(n!=null&&n.organization_id)&&!c})}const d=n=>n==null?"â":(n/100).toLocaleString("pt-BR",{style:"currency",currency:"BRL"}),v=(n,c=!1)=>{if(!n)return"â";const i=new Date(n.length===10?`${n}T12:00:00`:n);return isNaN(i.getTime())?"â":c?i.toLocaleString("pt-BR"):i.toLocaleDateString("pt-BR")},se=n=>{var c;return((c=X.find(i=>i.value===n))==null?void 0:c.label)??n??"â"};function xe(){const{quoteId:n}=V(),c=I(),[i]=U(),{data:s,isLoading:z}=J(n),{data:y}=ee(),{data:F=[]}=W(),[q,C]=m.useState(i.get("modelo")??"detalhado"),[x,L]=m.useState(i.get("valores")!=="0"),[S,O]=m.useState(i.get("composicao")!=="0"),[A,R]=m.useState(i.get("assinatura")==="1"),[h,D]=m.useState(null),p=m.useMemo(()=>s?Array.isArray(s.formulations)&&s.formulations.length>0?s.formulations:Array.isArray(s.quote_items)&&s.quote_items.length>0?[{name:"Formulação 1",pharmaceutical_form:s.pharmaceutical_form,n_doses:s.n_doses,capsule_size:s.capsule_size,items:s.quote_items,price_cents:s.price_cents??s.quote_amount_cents}]:[]:[],[s]),j=p.filter((t,r)=>!h||h.includes(r)),g=j.reduce((t,r)=>t+Number((r==null?void 0:r.price_cents)??0),0)||((s==null?void 0:s.price_cents)??(s==null?void 0:s.quote_amount_cents)??0),w=j.length===p.length?Math.max(0,((s==null?void 0:s.price_cents)??g)-g):0,k=(s==null?void 0:s.discount_cents)??0,B=Math.max(0,g+w-k),l=q==="detalhado",b=t=>{var r;return((r=F.find(o=>o.id===t))==null?void 0:r.name)??null},M=j.some(t=>((t==null?void 0:t.items)??[]).some(r=>(r==null?void 0:r.is_controlled)||(r==null?void 0:r.controlled)));if(z)return e.jsx("div",{className:"p-8 text-sm text-muted-foreground",children:"Carregando orçamentoâ¦"});if(!s)return e.jsx("div",{className:"p-8 text-sm text-muted-foreground",children:"Orçamento não encontrado."});const T=(t,r)=>{const o=h??p.map((a,f)=>f),_=r?[...new Set([...o,t])]:o.filter(a=>a!==t);D(_)};return e.jsxs("div",{className:"min-h-screen bg-muted/40 print:bg-white",children:[e.jsx("style",{children:` 2 @page { size: A4 portrait; margin: 14mm 12mm; } 3 @media print { 4 .no-print { display: none !important; } 5 .print-sheet { box-shadow: none !important; margin: 0 !important; padding: 0 !important; width: auto !important; } 6 thead { display: table-header-group; } 7 tr, .avoid-break { break-inside: avoid; } 8 .print-footer { position: fixed; bottom: 0; left: 0; right: 0; } 9 } 10 `}),e.jsxs("div",{className:"no-print sticky top-0 z-10 border-b bg-background/95 backdrop-blur px-4 py-3 flex flex-wrap items-center gap-3",children:[e.jsx(u,{variant:"ghost",size:"icon",onClick:()=>c(-1),"aria-label":"Voltar",children:e.jsx(G,{className:"h-5 w-5"})}),e.jsxs("div",{className:"font-semibold",children:["Orçamento ",P(s.sequence_number)]}),e.jsxs("div",{className:"flex items-center gap-1 rounded-md border p-1",children:[e.jsx(u,{size:"sm",variant:l?"default":"ghost",onClick:()=>C("detalhado"),children:"Detalhado"}),e.jsx(u,{size:"sm",variant:l?"ghost":"default",onClick:()=>C("cliente"),children:"Cliente"})]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx(N,{checked:x,onCheckedChange:t=>L(!!t)})," Valores"]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx(N,{checked:S,onCheckedChange:t=>O(!!t)})," Composição"]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx(N,{checked:A,onCheckedChange:t=>R(!!t)})," Assinatura"]}),p.length>1&&e.jsxs("div",{className:"flex items-center gap-3 text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:"Formulações:"}),p.map((t,r)=>e.jsxs("label",{className:"flex items-center gap-1",children:[e.jsx(N,{checked:!h||h.includes(r),onCheckedChange:o=>T(r,!!o)}),(t==null?void 0:t.name)||`#${r+1}`]},r))]}),e.jsxs("div",{className:"ml-auto flex gap-2",children:[e.jsxs(u,{onClick:()=>window.print(),children:[e.jsx(Y,{className:"h-4 w-4 mr-2"})," Imprimir"]}),e.jsxs(u,{variant:"outline",onClick:()=>window.print(),children:[e.jsx(Z,{className:"h-4 w-4 mr-2"})," Gerar PDF"]})]})]}),e.jsxs("div",{className:"print-sheet mx-auto my-6 w-[210mm] max-w-full bg-white text-black shadow-lg p-10 print:p-0",children:[e.jsxs("header",{className:"flex items-start justify-between border-b-2 border-black/80 pb-3",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-bold",children:(y==null?void 0:y.name)??"Farmácia de Manipulação"}),e.jsxs("p",{className:"text-xs",children:["Filial: ",b(s.filial_destino_id)??b(s.filial_origem_id)??"â"]}
10),e.jsx("p",{className:"text-xs",children:s.title??"Orçamento de manipulados"})]}),e.jsxs("div",{className:"text-right text-xs",children:[e.jsxs("div",{className:"text-lg font-bold",children:["Orçamento ",P(s.sequence_number)]}),e.jsxs("div",{children:["Emissão: ",v(s.data_entrada??s.created_at,!0)]}),e.jsxs("div",{children:["Prescrição: ",v(s.data_prescricao)]}),e.jsxs("div",{children:["Validade: ",v(s.quote_valid_until)]})]})]}),e.jsxs("section",{className:"grid grid-cols-2 gap-x-6 gap-y-1 py-3 text-xs border-b",children:[e.jsxs("div",{children:[e.jsx("strong",{children:"Cliente:"})," ",s.contact_name??"â"]}),e.jsxs("div",{children:[e.jsx("strong",{children:"Paciente:"})," ",s.patient_name??s.contact_name??"â"]}),e.jsxs("div",{children:[e.jsx("strong",{children:"Prescritor:"})," ",s.prescriber_name??"â"," ",s.prescriber_crm?`(${s.prescriber_crm})`:""]}),e.jsxs("div",{children:[e.jsx("strong",{children:"Canal de captação:"})," ",s.capture_channel??"â"]}),e.jsxs("div",{children:[e.jsx("strong",{children:"Grupo terapêutico:"})," ",s.therapeutic_group??"â"]}),e.jsxs("div",{children:[e.jsx("strong",{children:"Qtd. prescrita:"})," ",s.prescribed_quantity??"â"]}),l&&e.jsxs("div",{children:[e.jsx("strong",{children:"Filial origem:"})," ",b(s.filial_origem_id)??"â"]}),l&&e.jsxs("div",{children:[e.jsx("strong",{children:"Filial destino:"})," ",b(s.filial_destino_id)??"â"]}
10)]}),M&&e.jsxs("div",{className:"mt-3 border border-black px-3 py-2 text-xs font-semibold flex items-center gap-2 avoid-break",children:[e.jsx(H,{className:"h-4 w-4"})," CONTÃM PRODUTO CONTROLADO â sujeito a receita e retenção conforme legislação."]}),j.map((t,r)=>{const o=Array.isArray(t==null?void 0:t.items)?t.items:[],_=l?o:o.filter(a=>!(a!=null&&a.hide_on_label));return e.jsxs("section",{className:"mt-4 avoid-break",children:[e.jsxs("div",{className:"flex items-baseline justify-between border-b border-black/40 pb-1",children:[e.jsxs("h2",{className:"font-bold text-sm",children:[(t==null?void 0:t.name)||`Formulação ${r+1}`,e.jsxs("span",{className:"ml-2 font-normal text-xs",children:[se(t==null?void 0:t.pharmaceutical_form)," · ",(t==null?void 0:t.n_doses)??"â"," doses",t!=null&&t.capsule_size?` · cáps. ${t.capsule_size}`:""]})]}),x&&e.jsx("div",{className:"font-semibold text-sm",children:d((t==null?void 0:t.price_cents)??null)})]}),S&&_.length>0&&e.jsxs("table",{className:"w-full text-xs mt-2 border-collapse",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-black/30 text-left",children:[e.jsx("th",{className:"py-1",children:"Componente"}),e.jsx("th",{className:"py-1 w-24 text-right",children:"Dose"}),e.jsx("th",{className:"py-1 w-16",children:"Unid."}),l&&e.jsx("th",{className:"py-1 w-24 text-right",children:"Qtd. total"}),l&&x&&e.jsx("th",{className:"py-1 w-24 text-right",children:"Custo"})]})}),e.jsx("tbody",{children:_.map((a,f)=>e.jsxs("tr",{className:"border-b border-black/10",children:[e.jsxs("td",{className:"py-1",children:[(a==null?void 0:a.label_override)||(a==null?void 0:a.raw_name)||"â",a!=null&&a.is_qsp?" (QSP)":""]}),e.jsx("td",{className:"py-1 text-right",children:Number((a==null?void 0:a.dose_per_unit)??0).toLocaleString("pt-BR")}),e.jsx("td",{className:"py-1",children:(a==null?void 0:a.dose_unit)??"â"}),l&&e.jsx("td",{className:"py-1 text-right",children:(a==null?void 0:a.total_quantity_grams)!=null?`${Number(a.total_quantity_grams).toLocaleString("pt-BR",{maximumFractionDigits:4})} g`:"â"}),l&&x&&e.jsx("td",{className:"py-1 text-right",children:(a==null?void 0:a.cost_cents)!=null?d(a.cost_cents):"â"})]},f))})]}),e.jsxs("div",{className:"text-xs mt-1 space-y-0.5",children:[(t==null?void 0:t.posology)&&e.jsxs("div",{children:[e.jsx("strong",{children:"Posologia:"})," ",t.posology]}),s.packaging_description&&e.jsxs("div",{children:[e.jsx("strong",{children:"Embalagem:"})," ",s.packaging_description]}),l&&s.excipient&&e.jsxs("div",{children:[e.jsx("strong",{children:"Excipiente/veÃculo:"})," ",s.excipient]})]})]},r)}),x&&e.jsxs("section",{className:"mt-6 ml-auto w-64 text-sm avoid-break",children:[e.jsxs("div",{className:"flex justify-between border-b py-1",children:[e.jsx("span",{children:"Subtotal"}),e.jsx("span",{children:d(g)})]}),w>0&&e.jsxs("div",{className:"flex justify-between border-b py-1",children:[e.jsx("span",{children:"Acréscimo"}),e.jsxs("span",{children:["+ ",d(w)]})]}),e.jsxs("div",{className:"flex justify-between border-b py-1",children:[e.jsx("span",{children:"Desconto"}),e.jsx("span",{children:k?`- ${d(k)}`:d(0)})]}),e.jsxs("div",{className:"flex justify-between py-1 font-bold text-base",children:[e.jsx("span",{children:"Total"}),e.jsx("span",{children:d(B)})]})]}),e.jsxs("section",{className:"mt-6 text-xs space-y-2",children:[s.quote_notes&&e.jsxs("div",{children:[e.jsx("strong",{children:"Observações:"}),e.jsx("div",{className:"whitespace-pre-wrap",children:s.quote_notes})]}),s.commercial_terms&&e.jsxs("div",{children:[e.jsx("strong",{children:"Condições comerciais:"}),e.jsx("div",{className:"whitespace-pre-wrap",children:s.commercial_terms})]}),e.jsxs("div",{className:"text-[10px] text-black/60",children:["Orçamento válido até ",v(s.quote_valid_until),". Valores sujeitos a alteração conforme disponibilidade de insumos."]})]}),A&&e.jsxs("section",{className:"mt-16 grid grid-cols-2 gap-10 text-xs avoid-break",children:[e.jsx("div",{className:"border-t border-black pt-1 text-center",children:"Assinatura do cliente"}),e.jsx("div",{className:"border-t border-black pt-1 text-center",children:"Farmacêutico responsável"})]})]}),e.jsx("div",{className:"no-print pb-10 text-center text-xs text-muted-foreground",children:e.jsx(K,{variant:"outline",children:l?"Modelo detalhado (interno)":"Modelo cliente (comercial)"})})]})}export{xe as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.