1import{r as p,i as b,j as e}from"./index-Bo63WaDo.js";import{S as m,f as h}from"./packsazulFinanzasUi-ujDV7R9n.js";import{c as I}from"./packsazulFeed-BKi4xE_3.js";const v=(s,a)=>`${Number(s).toLocaleString("es-MX",{minimumFractionDigits:2})} ${a}`;function $(){const[s,a]=p.useState({loading:!0,error:null});if(p.useEffect(()=>{let n=!0;return b("packsazul-catalog",{action:"sales_summary"}).then(r=>{n&&(r.error?a({loading:!1,error:r.error}):a({loading:!1,error:null,...r.data}))}),()=>{n=!1}},[]),s.loading)return e.jsx("div",{className:"card",children:e.jsx("p",{style:{fontSize:12,color:"var(--text2)"},children:"Cargando ventasâ¦"})});if(s.error)return e.jsx("div",{className:"card",children:e.jsx("p",{style:{color:"var(--danger)"},children:s.error})});const x=Object.fromEntries((s.por_estado||[]).map(n=>[n.status,n.orders]));return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"card",style:{marginBottom:12,display:"flex",gap:24,flexWrap:"wrap"},children:[(s.totales||[]).map(n=>e.jsxs("div",{children:[e.jsxs("div",{style:{fontSize:11,textTransform:"uppercase",letterSpacing:".5px",color:"var(--text2)"},children:["Total ",n.currency]}),e.jsx("div",{style:{fontSize:22,fontWeight:700},children:v(n.amount,n.currency)}),e.jsxs("div",{style:{fontSize:12,color:"var(--text2)"},children:[n.orders," órdenes"]})]},n.currency)),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:11,textTransform:"uppercase",letterSpacing:".5px",color:"var(--text2)"},children:"Por estado"}),e.jsx("div",{style:{fontSize:13,marginTop:4},children:["active","expired","revoked"].map(n=>e.jsxs("span",{style:{marginRight:12},children:[n,": ",e.jsx("strong",{children:x[n]??0})]},n))})]})]}),e.jsxs("div",{className:"card",style:{marginBottom:12},children:[e.jsx("div",{style:{fontSize:11,textTransform:"uppercase",letterSpacing:".5px",color:"var(--text2)",marginBottom:8},children:"Por tipo"}),e.jsxs("table",{className:"products-table",style:{fontSize:12,width:"100%",minWidth:0},children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Tipo"}),e.jsx("th",{children:"Moneda"}),e.jsx("th",{children:"Ãrdenes"}),e.jsx("th",{children:"Monto"})]})}),e.jsx("tbody",{children:(s.por_tipo||[]).map((n,r)=>e.jsxs("tr",{children:[e.jsx("td",{children:n.order_type}),e.jsx("td",{children:n.currency}),e.jsx("td",{children:n.orders}),e.jsx("td",{children:v(n.amount,n.currency)})]},r))})]})]}),e.jsxs("div",{className:"card",style:{marginBottom:12},children:[e.jsx("div",{style:{fontSize:11,textTransform:"uppercase",letterSpacing:".5px",color:"var(--text2)",marginBottom:8},children:"Por modelo"}),e.jsxs("table",{className:"products-table",style:{fontSize:12,width:"100%",minWidth:0},children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Modelo"}),e.jsx("th",{children:"Moneda"}),e.jsx("th",{children:"Ãrdenes"}),e.jsx("th",{children:"Monto"}),e.jsx("th",{children:"Ãltima venta"})]})}),e.jsx("tbody",{children:(s.por_modelo||[]).map((n,r)=>e.jsxs("tr",{children:[e.jsx("td",{children:n.title}),e.jsx("td",{children:n.currency}),e.jsx("td",{children:n.orders}),e.jsx("td",{children:v(n.amount,n.currency)}),e.jsx("td",{children:n.last_paid?String(n.last_paid).slice(0,10):"â"})]},r))})]})]}),e.jsxs("div",{className:"card",children:[e.jsx("div",{style:{fontSize:11,textTransform:"uppercase",letterSpacing:".5px",color:"var(--text2)",marginBottom:8},children:"Serie mensual"}),e.jsxs("table",{className:"products-table",style:{fontSize:12,width:"100%",minWidth:0},children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Mes"}),e.jsx("th",{children:"Moneda"}),e.jsx("th",{children:"Ãrdenes"}),e.jsx("th",{children:"Monto"})]})}),e.jsx("tbody",{children:(s.mensual||[]).map((n,r)=>e.jsxs("tr",{children:[e.jsx("td",{children:n.month}),e.jsx("td",{children:n.currency}),e.jsx("td",{children:n.orders}),e.jsx("td",{children:v(n.amount,n.currency)})]},r))})]}),e.jsx("p",{style:{fontSize:11,color:"var(--text2)",marginTop:8},children:"Lectura directa de las órdenes de la web (sin comisiones â pendiente de regla comercial)."})]})]})}const A=()=>new Date().toISOString().slice(0,10),E={rojo:0,verde:1,gris:2};function O({s}){const a=m[s]||m.gris,x=s==="rojo"?"Cuesta más de lo que rinde":s==="verde"?"Deja margen":"Pausada / sin config";return e.jsx("span",{title:x,style:{display:"inline-block",width:12,height:12,borderRadius:99,background:a,verticalAlign:"middle"}})}function z({text:s,color:a}){return e.jsx("span",{style:{fontSize:10,fontWeight:600,padding:"1px 6px",borderRadius:99,background:`${a}22`,color:a,border:`1px solid ${a}55`,whiteSpace:"nowrap"},children:s})}function L({showToast:s}){const[a,x]=p.useState({loading:!0,error:null,rows:[],resumen:null,margenEsNeto:!0,comisionRate:null}),[n,r]=p.useState(null),[i,g]=p.useState(null),[l,j]=p.useState(null),N=async()=>{var C,M,P,W,B;x(d=>({...d,loading:!0}));
1const[t,o]=await Promise.all([b("packsazul-finanzas",{action:"get_finanzas"}),b("packsazul-catalog",{})]);if(t.error){x({loading:!1,error:t.error,rows:[],resumen:null,margenEsNeto:!0,comisionRate:null});return}const f=o.error?[]:((C=o.data)==null?void 0:C.modelos)||[],y=new Map(f.map(d=>[d.id,d])),k=(((M=t.data)==null?void 0:M.rows)||[]).map(d=>{const c=y.get(d.wp_modelo_id);return{...d,title:(c==null?void 0:c.title)||`#${d.wp_modelo_id}`,last_feed:(c==null?void 0:c.last_feed)??null}});k.sort((d,c)=>(E[d.semaforo]??3)-(E[c.semaforo]??3)||(c.ingreso_neto??c.ingreso_bruto)-(d.ingreso_neto??d.ingreso_bruto)),x({loading:!1,error:null,rows:k,resumen:((P=t.data)==null?void 0:P.resumen)??null,margenEsNeto:!!((W=t.data)!=null&&W.margen_es_neto),comisionRate:((B=t.data)==null?void 0:B.comision_rate)??null})};p.useEffect(()=>{N()},[]);const _=async(t,o)=>{const f=t.wp_modelo_id;r(f);try{const y=await b("packsazul-finanzas",t);return y.error?(s==null||s(y.error,"error"),!1):(s==null||s(o,"success"),await N(),!0)}finally{r(null)}},F=async()=>{if(!i)return;const t=Number(i.monto);if(!Number.isFinite(t)||t<0){s==null||s("Monto inválido","error");return}const o=Number(i.dia);if(!Number.isInteger(o)||o<1||o>31){s==null||s("DÃa de pago inválido","error");return}await _({action:"set_config",wp_modelo_id:i.id,monto_mensual:t,dia_pago:o},"Config guardada")&&g(null)},R=async()=>{if(!l)return;const t=Number(l.monto);if(!Number.isFinite(t)){s==null||s("Monto inválido","error");return}await _({action:"mark_paid",wp_modelo_id:l.id,monto:t,fecha_pagada:l.fecha,nota:l.nota||""},"Pago registrado + próximo agendado")&&j(null)},D=t=>_({action:t.estado==="pausado"?"resume":"pause",wp_modelo_id:t.wp_modelo_id},t.estado==="pausado"?"Reanudada":"Pausada");if(a.loading)return e.jsx("div",{className:"card",children:e.jsx("p",{style:{fontSize:12,color:"var(--text2)"},children:"Cargando finanzasâ¦"})});if(a.error)return e.jsx("div",{className:"card",children:e.jsx("p",{style:{color:"var(--danger)"},children:a.error})});const u=a.resumen,S=a.margenEsNeto?"Ingreso neto":"Ingreso bruto";return e.jsxs(e.Fragment,{children:[u&&e.jsxs("div",{className:"card",style:{marginBottom:12,display:"flex",gap:24,flexWrap:"wrap",alignItems:"baseline"},children:[e.jsxs("div",{children:[e.jsxs("div",{style:{fontSize:11,textTransform:"uppercase",letterSpacing:".5px",color:"var(--text2)"},children:["Margen del cliente · ",u.ym]}),e.jsx("div",{style:{fontSize:22,fontWeight:700,color:u.margen<0?m.rojo:m.verde},children:h(u.margen)}),e.jsx("div",{style:{fontSize:11,color:"var(--text2)"},children:"este mes"})]}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:11,color:"var(--text2)"},children:S}),e.jsx("div",{style:{fontSize:16,fontWeight:600},children:h(u.ingresado_neto??u.ingresado_bruto)})]}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:11,color:"var(--text2)"},children:"Pagado a modelos"}),e.jsx("div",{style:{fontSize:16,fontWeight:600},children:h(u.pagado)})]})]}),i&&e.jsxs("div",{className:"card",style:{marginBottom:12},children:[e.jsxs("div",{style:{fontWeight:600,marginBottom:8},children:["Config de pago â ",i.title]}),e.jsxs("div",{style:{display:"flex",gap:12,flexWrap:"wrap",alignItems:"flex-end"},children:[e.jsxs("label",{style:{fontSize:12},children:["Monto mensual (MXN)",e.jsx("br",{}),e.jsx("input",{type:"number",min:"0",value:i.monto,onChange:t=>g({...i,monto:t.target.value}),style:{width:120}})]}),e.jsxs("label",{style:{fontSize:12},children:["DÃa de pago",e.jsx("br",{}),e.jsx("input",{type:"number",min:"1",max:"31",value:i.dia||"",onChange:t=>g({...i,dia:t.target.value}),style:{width:70}})]}),e.jsx("button",{onClick:F,disabled:n===i.id,children:"Guardar"}),e.jsx("button",{onClick:()=>g(null),className:"ghost",children:"Cancelar"})]})]}),l&&e.jsxs("div",{className:"card",style:{marginBottom:12},children:[e.jsxs("div",{style:{fontWeight:600,marginBottom:8},children:["Marcar pagado â ",l.title]}),e.jsxs("div",{style:{display:"flex",gap:12,flexWrap:"wrap",alignItems:"flex-end"},children:[e.jsxs("label",{style:{fontSize:12},children:["Monto (MXN)",e.jsx("br",{}),e.jsx("input",{type:"number",value:l.monto,onChange:t=>j({...l,monto:t.target.value}),style:{width:120}})]}),e.jsxs("label",{style:{fontSize:12},children:["Fecha",e.jsx("br",{}),e.jsx("input",{type:"date",value:l.fecha,onChange:t=>j({...l,fecha:t.target.value})})]}),e.jsxs("label",{style:{fontSize:12,flex:1,minWidth:160}
1,children:["Nota (opcional)",e.jsx("br",{}),e.jsx("input",{type:"text",value:l.nota,onChange:t=>j({...l,nota:t.target.value}),style:{width:"100%"},placeholder:"bono, ajusteâ¦"})]}),e.jsx("button",{onClick:R,disabled:n===l.id,children:"Registrar pago"}),e.jsx("button",{onClick:()=>j(null),className:"ghost",children:"Cancelar"})]}),e.jsx("p",{style:{fontSize:11,color:"var(--text2)",marginTop:6},children:"El monto es editable (bono/ajuste). Al registrar, se agenda solo el aviso del mes siguiente."})]}),e.jsxs("div",{className:"card products-table-container",children:[e.jsxs("div",{style:{fontSize:11,textTransform:"uppercase",letterSpacing:".5px",color:"var(--text2)",marginBottom:8},children:["Por modelo · ",e.jsx("strong",{children:"acumulado histórico"})," (no del mes en curso) â margen = ",S.toLowerCase()," â pagado"]}),e.jsxs("table",{className:"products-table",style:{fontSize:12,width:"100%",minWidth:0},children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{}),e.jsx("th",{children:"Modelo"}),e.jsx("th",{children:"Monto/mes"}),e.jsx("th",{children:"Próximo pago"}),e.jsx("th",{children:S}),e.jsx("th",{children:"Gasto"}),e.jsx("th",{children:"Margen"}),e.jsx("th",{children:"Señales"}),e.jsx("th",{})]})}),e.jsx("tbody",{children:a.rows.map(t=>{const o=t.last_feed!==void 0?I(t.last_feed):null;return e.jsxs("tr",{style:{opacity:t.estado==="pausado"?.55:1},children:[e.jsx("td",{children:e.jsx(O,{s:t.semaforo})}),e.jsx("td",{children:t.title}),e.jsx("td",{children:t.monto_mensual!=null?h(t.monto_mensual):e.jsx("span",{style:{color:"var(--text3,#999)"},children:"â"})}),e.jsxs("td",{children:[t.proximo_pago||"â",t.estado==="pausado"&&e.jsx("span",{style:{fontSize:10,color:"var(--text2)"},children:" (pausada)"})]}),e.jsx("td",{children:h(t.ingreso_neto??t.ingreso_bruto)}),e.jsx("td",{children:h(t.gasto)}),e.jsx("td",{style:{fontWeight:600,color:t.margen<0?m.rojo:m.verde},children:h(t.margen)}),e.jsx("td",{children:e.jsxs("span",{style:{display:"inline-flex",gap:4},children:[o&&e.jsx(z,{text:o.label,color:o.color}),t.vende?e.jsx(z,{text:"Vende",color:m.verde}):e.jsx(z,{text:t.dias_ultima_venta==null?"Sin ventas":`Sin vender +${t.dias_ultima_venta}d`,color:m.rojo})]})}),e.jsxs("td",{style:{whiteSpace:"nowrap"},children:[e.jsx("button",{className:"ghost",style:{fontSize:11},disabled:n===t.wp_modelo_id,onClick:()=>g({id:t.wp_modelo_id,title:t.title,monto:t.monto_mensual??"",dia:t.dia_pago??""}),children:"Config"})," ",e.jsx("button",{className:"ghost",style:{fontSize:11},disabled:n===t.wp_modelo_id||t.monto_mensual==null,onClick:()=>j({id:t.wp_modelo_id,title:t.title,monto:t.monto_mensual??"",fecha:A(),nota:""}),children:"Pagar"})," ",t.estado&&e.jsx("button",{className:"ghost",style:{fontSize:11},disabled:n===t.wp_modelo_id,onClick:()=>D(t),children:t.estado==="pausado"?"Reanudar":"Pausar"})]})]},t.wp_modelo_id)})})]}),e.jsxs("p",{style:{fontSize:11,color:"var(--text2)",marginTop:8},children:["ð´ cuesta más de lo que rinde · ð¢ deja margen · ⪠pausada. Dos señales: ",e.jsx("b",{children:"publica"})," (última publicación) y ",e.jsx("b",{children:"vende"})," (última venta) â una modelo puede vender packs viejos sin publicar, o publicar sin vender.",!a.margenEsNeto&&" Margen en bruto: falta confirmar comisión de pasarela."]})]})]})}function G({page:s,onNavigate:a,showToast:x}){const n=s==="pa-finanzas"?"finanzas":"ventas",r=i=>{typeof a=="function"&&i!==s&&a(i)};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{role:"tablist","aria-label":"Ventas o Finanzas",style:{display:"flex",gap:6,marginBottom:14},children:[e.jsx("button",{type:"button",role:"tab","aria-selected":n==="ventas",className:`btn btn-sm ${n==="ventas"?"btn-primary":""}`,onClick:()=>r("pa-ventas"),children:"Ventas"}),e.jsx("button",{type:"button",role:"tab","aria-selected":n==="finanzas",className:`btn btn-sm ${n==="finanzas"?"btn-primary":""}`,onClick:()=>r("pa-finanzas"),children:"Finanzas"})]}),n==="ventas"?e.jsx($,{}):e.jsx(L,{showToast:x})]})}export{G 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.