PageSourceSearch

https://martic-insight-stream.lovable.app/assets/Proposals-DvZoybLx.js

js martic-insight-stream.lovable.app collected 2026-10-03 03:34:43 UTC 13,153 bytes, 1 lines download raw bytes

1import{r as P,j as e,u as W}from"./vendor-react-IuE1BHLN.js";import{H as Z}from"./HubEmptyState-D5ioipHk.js";import{u as J}from"./BusinessHubContext-DzG9KGxS.js";import{useQueryClient as X,useQuery as F,useMutation as z}from"./vendor-query-tvLceJaY.js";import{K as Y,b as G,D as ee,a1 as ae,Z as se,at as te,u as oe,s as p,p as re,aJ as ne,ae as ie,af as le,ag as ce,ah as de,ai as I,am as T,P as ue,L as me,aQ as k,ao as pe,E as xe,o as he,Y as fe,bd as be,c_ as ge}from"./index-DXNQ1pJm.js";import{T as je,a as ve,b as M,c as u,d as _e,e as m}from"./table-Cp1A1aKk.js";import{M as O}from"./ModuleSettingsButton-D_eNNC-m.js";import{A as ye,a as Ne,b as we,O as Ce}from"./ActionBar-CoM-M2Pc.js";import{R as x}from"./ReportCard--r9C18f3.js";import{S as $}from"./send-Bllr-FyW.js";import{C as Se}from"./circle-x-DSTX-Zec.js";import{R as Te}from"./repeat-DfGVXM31.js";import{u as Re}from"./vendor-i18n-D-M1SmLz.js";import"./vendor-ui-CAzyx7hV.js";import"./lightbulb-YcXdWOjQ.js";import"./arrow-up-CoF4ROUW.js";import"./arrow-down-C7jj8SQO.js";const R=h=>new Intl.NumberFormat("pt-BR",{style:"currency",currency:"BRL",maximumFractionDigits:0}).format(h||0);function Pe({proposals:h,itemsByProposal:_={}}){const l=P.useMemo(()=>{let o=0,y=0,b=0,g=0,j=0,N=0,v=0,w=0;return h.forEach(c=>{const f=_[c.id];["rascunho","enviada","visualizada"].includes(c.status)&&o++,c.status==="enviada"&&y++,c.status==="aceita"&&(b++,j+=c.total||0,f&&(N+=f.recurring)),["recusada","expirada"].includes(c.status)&&g++,!["recusada","expirada","aceita"].includes(c.status)&&f&&(v+=f.oneTime,w+=f.recurring)}),{open:o,sent:y,approved:b,lost:g,totalWon:j,mrrWon:N,pipelineOneTime:v,pipelineRecurring:w}},[h,_]);return e.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 2xl:grid-cols-8 gap-3 sm:gap-4 mb-6",children:[e.jsx(x,{label:"Em aberto",value:l.open,icon:e.jsx(Y,{className:"h-4 w-4"}),tooltip:"Propostas em rascunho, enviadas ou visualizadas."}),e.jsx(x,{label:"Enviadas",value:l.sent,icon:e.jsx($,{className:"h-4 w-4"}),tooltip:"Propostas com status enviada."}),e.jsx(x,{label:"Aprovadas",value:l.approved,icon:e.jsx(G,{className:"h-4 w-4"}),tooltip:"Propostas aceitas pelo cliente."}),e.jsx(x,{label:"Perdidas",value:l.lost,icon:e.jsx(Se,{className:"h-4 w-4"}),tooltip:"Propostas recusadas ou expiradas."}),e.jsx(x,{label:"Total ganho",value:R(l.totalWon),icon:e.jsx(ee,{className:"h-4 w-4"}),tooltip:"Soma dos valores das propostas aprovadas."}),e.jsx(x,{label:"MRR ganho",value:R(l.mrrWon),icon:e.jsx(ae,{className:"h-4 w-4"}),tooltip:"Receita recorrente mensal das propostas aprovadas."}),e.jsx(x,{label:"Pipeline único",value:R(l.pipelineOneTime),icon:e.jsx(se,{className:"h-4 w-4"}),tooltip:"Valor de itens avulsos em propostas ativas."}),e.jsx(x,{label:"Pipeline mensal",value:R(l.pipelineRecurring),icon:e.jsx(Te,{className:"h-4 w-4"}),tooltip:"Valor mensal recorrente em propostas ativas."})]})}const D={rascunho:"Rascunho",enviada:"Enviada",visualizada:"Visualizada",aceita:"Aceita",recusada:"Recusada",expirada:"Expirada"},ke={rascunho:"bg-muted text-muted-foreground",enviada:"bg-blue-500/10 text-blue-600 border-blue-200",visualizada:"bg-amber-500/10 text-amber-600 border-amber-200",aceita:"bg-emerald-500/10 text-emerald-600 border-emerald-200",recusada:"bg-red-500/10 text-red-600 border-red-200",expirada:"bg-muted text-muted-foreground"},Le={rascunho:"Ainda não enviada ao cliente. Use 'Enviar' ou copie o link público para mudar para Enviada.",enviada:"Link enviado ao cliente, aguardando abertura.",visualizada:"O cliente já abriu o link público da proposta.",aceita:"Aceita e assinada digitalmente pelo cliente.",recusada:"O cliente recusou a proposta.",expirada:"A data de validade passou sem resposta."},Ze=()=>{const h=J(),{t:_}=Re(),l=W(),{profile:o,getProfileName:y}=te(),{toast:b}=oe(),g=X(),[j,N]=P.useState(""),[v,w]=P.useState("all"),{data:c=[],isLoading:f}=F({queryKey:["proposals",o==null?void 0:o.company_id],queryFn:async()=>{const{data:a}=await p.from("proposals").select("*, customers(name), leads(name, company_name)").eq("company_id",o.company_id).order("created_at",{ascending:!1});return a||[]},enabled:!!(o!=null&&o.company_id)}),L=a=>{var r;const s=(r=a.customers)==null?void 0:r.name;if(s)return{name:s,source:"cliente"};const t=a.leads,d=(t==null?void 0:t.company_name)||(t==null?void 0:t.name);return d?{name:d,source:"lead"}:{name:null,source:null}},{data:q=[]}=F({queryKey:["proposal-items-breakdown",o==null?void 0:o.company_id],queryFn:async()=>{const{data:a}=await p.from("proposal_items").select("proposal_id, subtotal, product_id, products(type, is_recurring)").eq("company_id",o.company_id);return a||[]},enabled:!!(o!=null&&o.company_id)}),B=P.useMemo(()=>{const a={};return q.forEach(s=>{const t=s.proposal_id;a[t]||(a[t]={oneTime:0,recurring:0,products:0,services:0,contracts:0});const d=s.subtotal||0,r=s.products,n=r==null?void 0:r.type,C=r==null?void 0:r.is_recurring;n==="recorrente"||C?(a[t].recurring+=d,a[t].contracts++):n==="produto"?(a[t].oneTime+=d,a[t].products++):(a[t].oneTime+=d,a[t].services++)}),a},[q]),H=z({mutationFn:async a=>{await p.from("proposal_items").delete().eq("proposal_id",a);const{error:s}=await p.from("proposals").delete().eq("id",a);if(s)throw s},onSuccess:()=>{g.invalidateQueries({queryKey:["proposals"]}),g.invalidateQueries({queryKey:["proposal-items-breakdown"]}),b({title:"Proposta excluída"})}}),U=z({mutationFn:async a=>{const{data:s}=await p.from("proposal_settings").select("*").eq("company_id",o.company_id).maybeSingle(),t=(s==null?void 0:s.next_number)||1,r=`${(s==null?void 0:s.prefix)||"PROP"}-${String(t).padStart(4,"0")}`,{data:n,error:C}=await p.from("proposals").insert({company_id:o.company_id,customer_id:a.customer_id,title:`${a.title} (cópia)`,proposal_number:r,status:"rascunho",responsible_id:a.responsible_id,about_company_text:a.about_company_text,commercial_conditions:a.commercial_conditions,validity_date:null,subtotal:a.subtotal,discount_type:a.discount_type,discount_value:a.discount_value,tax_total:a.tax_total,total:a.total}).select("id").single();if(C)throw C;const{data:S}=await p.from("proposal_items").select("*").eq("proposal_id",a.id);return S!=null&&S.length&&await p.from("proposal_items").insert(S.map(i=>({company_id:o.company_id,proposal_id:n.id,product_id:i.product_id,name:i.name,description:i.description,quantity:i.quantity,unit_price:i.unit_price,discount_percent:i.discount_percent,discount_value:i.discount_value,tax_rate:i.tax_rate,subtotal:i.subtotal,sort_order:i.sort_order,is_package:i.is_package,is_recurring:i.is_recurring,frequency:i.frequency}))),s!=null&&s.id&&await p.from("proposal_settings").update({next_number:t+1}).eq("id",s.id),n.id},onSuccess:a=>{g.invalidateQueries({queryKey:["proposals"]}),l(`/proposals/${a}`),b({title:"Proposta duplicada"})}}),K=a=>new Intl.NumberFormat("pt-BR",{style:"currency",currency:"BRL"}).format(a||0),E=a=>a?new Intl.NumberFormat("pt-BR",{style:"currency",currency:"BRL",minimumFractionDigits:0,maximumFractionDigits:0}).format(a):"—",A=c.filter(a=>{var s;if(j){const t=j.toLowerCase(),d=((s=L(a).name)==null?void 0:s.toLowerCase())||"";if(!a.title.toLowerCase().includes(t)&&!a.proposal_number.toLowerCase().includes(t)&&!d.includes(t))return!1}return!(v!=="all"&&a.status!==v)}),Q=ge(),V=a=>{const s=a!=null&&a.public_token?`?t=${encodeURIComponent(a.public_token)}`:"";return`${Q}/p/${a.proposal_number}${s}`};return e.jsxs("div",{className:"animate-fade-in",children:[h?null:e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx("h1",{className:"font-display text-xl font-bold tracking-tight",children:_("proposals.title")}),e.jsx(O,{to:"/settings/proposals"})]}),e.jsxs(ye,{children:[e.jsxs(Ne,{className:"gap-2 sm:gap-3",children:[e.jsxs("div",{className:"relative flex-1 min-w-0 sm:min-w-[240px]",children:[e.jsx(re,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(ne,{placeholder:"Buscar por título ou número...",value:j,onChange:a=>N(a.target.value),className:"pl-9"})]}),e.jsxs(ie,{value:v,onValueChange:w,children:[e.jsx(le,{className:"w-[180px]",children:e.jsx(ce,{})}),e.jsxs(de,{children:[e.jsx(I,{value:"all",children:"Todos os status"}),Object.entries(D).map(([a,s])=>e.jsx(I,{value:a,children:s},a))]})]})]}),e.jsxs(we,{children:[h&&e.jsx(O,{to:"/settings/proposals"}),e.jsxs(T,{size:"sm",onClick:()=>l("/proposals/new"),className:"gap-2",children:[e.jsx(ue,{className:"h-4 w-4"}),_("proposals.newProposal")]})]})]}),e.jsx(Ce,{id:"proposals-public-link",strong:"Envie pelo link público",text:"Cada proposta gera um link exclusivo, o cliente visualiza, aceita e assina sem login.",when:c.length===0,icon:e.jsx($,{className:"h-3.5 w-3.5"})}),e.jsx(Pe,{proposals:c,itemsByProposal:B}),f?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(me,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):A.length===0?e.jsx(Z,{illustration:"deals",title:"Crie sua primeira proposta comercial",description:"Envie propostas profissionais com link público, acompanhe visualizações e aceites digitais.",actionLabel:"Criar Proposta",actionPath:"/proposals/new",secondaryLabel:"Ir para Configurações",secondaryPath:"/settings/proposals",children:e.jsx("div",{className:"w-full max-w-sm space-y-3 text-left mt-2",children:[{step:1,text:"Configure a numeração e dados da empresa em Configurações > Comercial"},{step:2,text:"Cadastre seus produtos e serviços no catálogo"},{step:3,text:"Crie sua primeira proposta e envie ao cliente"}].map(({step:a,text:s})=>e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"flex items-center justify-center h-6 w-6 rounded-full bg-primary/10 text-primary text-xs font-bold shrink-0 mt-0.5",children:a}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s})]},a))})}):e.jsx("div",{className:"bg-card rounded-xl border border-border overflow-x-auto",children:e.jsxs(je,{children:[e.jsx(ve,{children:e.jsxs(M,{children:[e.jsx(u,{children:"Número"}),e.jsx(u,{children:"Título"}),e.jsx(u,{children:"Cliente"}),e.jsx(u,{children:"Status"}),e.jsx(u,{children:"Itens"}),e.jsx(u,{className:"text-right",children:"Único"}),e.jsx(u,{className:"text-right",children:"Mensal"}),e.jsx(u,{className:"text-right",children:"Total"}),e.jsx(u,{children:"Responsável"}),e.jsx(u,{children:"Data"}),e.jsx(u,{className:"w-24",children:"Ações"})]})}),e.jsx(_e,{children:A.map(a=>{const s=B[a.id],t=s&&s.oneTime>0,d=s&&s.recurring>0,r=[];return s!=null&&s.products&&r.push({label:"Prod",count:s.products}),s!=null&&s.services&&r.push({label:"Serv",count:s.services}),s!=null&&s.contracts&&r.push({label:"Rec",count:s.contracts}),e.jsxs(M,{className:"cursor-pointer hover:bg-muted/30",onClick:()=>l(`/proposals/${a.id}`),children:[e.jsxs(m,{className:"font-mono text-xs",children:[a.proposal_number,e.jsxs(k,{variant:"outline",className:"ml-1.5 text-[10px] px-1.5 py-0 font-mono",children:["v",
1String(a.version||1).padStart(2,"0")]})]}),e.jsx(m,{className:"font-medium max-w-[180px] truncate",children:a.title}),e.jsx(m,{className:"text-sm max-w-[200px]",children:(()=>{const n=L(a);return n.name?e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx("span",{className:"truncate text-foreground",children:n.name}),n.source==="lead"&&e.jsx(k,{variant:"outline",className:"text-[9px] px-1 py-0 shrink-0",children:"Lead"})]}):e.jsx("span",{className:"text-muted-foreground",children:"Sem vínculo"})})()}),e.jsx(m,{children:e.jsx("span",{title:Le[a.status],children:e.jsx(k,{className:ke[a.status],children:D[a.status]})})}),e.jsx(m,{children:e.jsx("div",{className:"flex items-center gap-1",children:r.length>0?r.map(n=>e.jsxs("span",{className:"inline-flex items-center text-[10px] font-medium px-1.5 py-0.5 rounded bg-muted text-muted-foreground",children:[n.count,"×",n.label]},n.label)):e.jsx("span",{className:"text-muted-foreground text-xs",children:"—"})})}),e.jsx(m,{className:"text-right font-mono text-sm",children:t?E(s.oneTime):"—"}),e.jsx(m,{className:"text-right font-mono text-sm",children:d?e.jsxs("span",{className:"text-blue-500",children:[E(s.recurring),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:"/mês"})]}):"—"}),e.jsx(m,{className:"text-right font-mono font-semibold",children:K(a.total)}),e.jsx(m,{className:"text-muted-foreground text-sm",children:y(a.responsible_id)}),e.jsx(m,{className:"text-muted-foreground text-sm",children:pe(new Date(a.created_at),"dd/MM/yy",{locale:be})}),e.jsx(m,{children:e.jsxs("div",{className:"flex items-center gap-1",onClick:n=>n.stopPropagation(),children:[e.jsx(T,{variant:"ghost",size:"icon",className:"h-8 w-8",title:"Link público",onClick:()=>{navigator.clipboard.writeText(V(a)),b({title:"Link copiado!"})},children:e.jsx(xe,{className:"h-4 w-4"})}),e.jsx(T,{variant:"ghost",size:"icon",className:"h-8 w-8",title:"Duplicar",onClick:()=>U.mutate(a),children:e.jsx(he,{className:"h-4 w-4"})}),e.jsx(T,{variant:"ghost",size:"icon",className:"h-8 w-8 text-destructive",title:"Excluir",onClick:()=>H.mutate(a.id),children:e.jsx(fe,{className:"h-4 w-4"})})]})})]},a.id)})})]})})]})};export{Ze 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.